Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp145502imn; Fri, 29 Jul 2022 02:35:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tItRBbjbRg1duZufgjEqf1cMWF03GSOtYKxRUWTnZ7RZM6+o5tHZ/RTGoWX6npImL6/B49 X-Received: by 2002:a63:fc41:0:b0:41b:4714:ac78 with SMTP id r1-20020a63fc41000000b0041b4714ac78mr2306923pgk.319.1659087348247; Fri, 29 Jul 2022 02:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659087348; cv=none; d=google.com; s=arc-20160816; b=AbwPAQNP2Agh1z5G0CWE7/64c+sxEVuFZP1V5uLF6qSIB7wPU6kn3GkenubnE9FyXu tbvnyBW6SvzImzXqFydx5vH/2fd8GqKtKYP+KIOuZ7DQRRtitmtG0qnhtu3y5iUopNl3 fhq9cgbON9tpItdw/D+jil7MpoE5p6htcI0bpvVSCkbrP4vF7NjdhgsVFnpGMH4UmiHc SouYRve1h1l2Y5j5LS7GplQKkHioeEto+HkaX2o5IWOjYUXix0oXEK88Ayz7jX8h7BlR +96qa8NTAK2vzbaqr9RaQJTrDwKlHiYa3Cjird+8z0T2ke3Vwba5aF4VOMdMspPEKE1m rHXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=lR/CyNzvSIHqPfUxWsDX2qw91Y1VIj5HwGHzCfBG6+c=; b=XmwwixwChh8kRPAjuEqNMQl4ShLLQZjFF9xOIs58Jf47OjTRs2n9tFRd7upQYdTFGy gOPqf8tD1NrOoQH9bErEVsGJoz7XAwcvMZwVcAS7OCQExH4/gpwy4khMiDTWlnwVrVVs skHDbGxiMZ6X/5YhjnSwnqk4vvdUw4o07CdDpxlCs8DprLTtlN7x4Mk+V0u9/uGb3JVv vsXeI9YZBrUYa8xWeQjXYhXl5JgN6b+6e4BJqX52dVJSWLwtWrB5UzGa23sdx87IOdWv bvL8FuyFcokONAWHT9vQ+pA4ItILa59mLOvr3h3f2L7fA0W0Z5rFwRm2xuUQIu5wxkSx f/uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=jgTZpdWt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lr15-20020a17090b4b8f00b001f291c80d40si8333982pjb.12.2022.07.29.02.35.34; Fri, 29 Jul 2022 02:35:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=jgTZpdWt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234550AbiG2Iku (ORCPT + 99 others); Fri, 29 Jul 2022 04:40:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235681AbiG2Ik1 (ORCPT ); Fri, 29 Jul 2022 04:40:27 -0400 Received: from xry111.site (xry111.site [89.208.246.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A719E13D7F for ; Fri, 29 Jul 2022 01:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1659084024; bh=qVACV7bz4zGf1t3CnRp5Cj62T95tqtofD76Q2nBE43Y=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=jgTZpdWtfW8n1M2Gzlv596ZaIj/rpX9xDH7iHMommbRh2B7TfB5qYYX4VF0N5Y4Z5 tHTfU+GfuPjEmjvzJsBuqlKLUOS10rMQg6IBNTqVA8FqSip+SN/z4iAboAG/4EPqee ecsYg78ILpJtV19iUPonCBeYangEqODMZSYbdlKk= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384)) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 949C5669EB; Fri, 29 Jul 2022 04:40:22 -0400 (EDT) Message-ID: <88259699f98be6eadf574ad01f2bab32c4818b0d.camel@xry111.site> Subject: [PATCH v4 2/4] LoongArch: Support R_LARCH_SOP_PUSH_GPREL relocation type in kernel module From: Xi Ruoyao To: loongarch@lists.linux.dev Cc: linux-kernel@vger.kernel.org, WANG Xuerui , Huacai Chen , Youling Tang , Jinyang He Date: Fri, 29 Jul 2022 16:40:21 +0800 In-Reply-To: <32a74a218c76611f897fd1df1ad0059068621133.camel@xry111.site> References: <32a74a218c76611f897fd1df1ad0059068621133.camel@xry111.site> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.3 MIME-Version: 1.0 X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD, PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This relocation type pushes the offset of the GOT entry for a symbol from the beginning of GOT into the relocation stack. Our linker script has initialized an empty GOT, so we need to create a new GOT entry if there is no exist one for a symbol. Signed-off-by: Xi Ruoyao --- arch/loongarch/kernel/module.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/loongarch/kernel/module.c b/arch/loongarch/kernel/module.= c index 638427ff0d51..3ac4fbb5f109 100644 --- a/arch/loongarch/kernel/module.c +++ b/arch/loongarch/kernel/module.c @@ -122,6 +122,16 @@ static int apply_r_larch_sop_push_plt_pcrel(struct mod= ule *mod, u32 *location, E return apply_r_larch_sop_push_pcrel(mod, location, v, rela_stack, rela_st= ack_top, type); } =20 +static int apply_r_larch_sop_push_gprel(struct module *mod, u32 *location, + Elf_Addr v, s64 *rela_stack, size_t *rela_stack_top, + unsigned int type) +{ + Elf_Addr got =3D module_emit_got_entry(mod, v); + ptrdiff_t offset =3D (void *)got - (void *)mod->arch.got.shdr->sh_addr; + + return rela_stack_push(offset, rela_stack, rela_stack_top); +} + static int apply_r_larch_sop(struct module *mod, u32 *location, Elf_Addr v= , s64 *rela_stack, size_t *rela_stack_top, unsigned int type) { @@ -306,6 +316,7 @@ static reloc_rela_handler reloc_rela_handlers[] =3D { [R_LARCH_SOP_PUSH_PCREL] =3D apply_r_larch_sop_push_pcrel, [R_LARCH_SOP_PUSH_ABSOLUTE] =3D apply_r_larch_sop_push_absolute, [R_LARCH_SOP_PUSH_DUP] =3D apply_r_larch_sop_push_dup, + [R_LARCH_SOP_PUSH_GPREL] =3D apply_r_larch_sop_push_gprel, [R_LARCH_SOP_PUSH_PLT_PCREL] =3D apply_r_larch_sop_push_plt_pcrel, [R_LARCH_SOP_SUB ... R_LARCH_SOP_IF_ELSE] =3D apply_r_larch_sop, [R_LARCH_SOP_POP_32_S_10_5 ... R_LARCH_SOP_POP_32_U] =3D apply_r_larch_so= p_imm_field, --=20 2.37.0