Message ID | 20231116130331.241395-1-wangrui@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp3194282vqg; Thu, 16 Nov 2023 05:05:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9JXyQ7Q/+PKowtJOppNNeMjolWNHDOzEbAxazow/Qzkx8hUF7RyPwnlkzH5/D4dAi7yw5 X-Received: by 2002:a9d:6f82:0:b0:6c0:ef3c:5ab4 with SMTP id h2-20020a9d6f82000000b006c0ef3c5ab4mr9069385otq.0.1700139919833; Thu, 16 Nov 2023 05:05:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700139919; cv=none; d=google.com; s=arc-20160816; b=Q60omW7meX71VEcajWF1FqI9We6wqq+PDIxwW5x1PRmhX6bbc5QrAucD3rQ3edHLUX i3anawy/S+t4rGiREykAvYthAP4GeIKT9QYKUEBKJ0ycFXVrQbD1Pf00kSLfh45BMBDN pyy9ebUxFnWkCKUOrYrqhqPpt5d2aDT7gD3qZfNi/9zhTNECQr2kB6ojfwa+viXo+Ktt XtTfUQntp15aogiwOmPq4tsoaNTs6XCTgPhthONJtDg8kD3JyJz7iAYssoogd/QCfWSJ P4lCrga0isJ7goC9Inw7LVbLegCKP3dTZJ3Z+I7dU/9OkdncctqcCf/Ujk9jSTOF44F/ C+OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=cPr6M8QS7OfMbIWAW52f+o9AE91rbwP4jSd4BqnqW7Y=; fh=VHH9w6045DoD1W0AfBV3WelTzopgJ8dK0fkNeJKCBUo=; b=byfB+X58P/9MmXJtjrZu0QRZ/f0YvDqqCyNDHHMDtb1riCaE9WwLw+Il+83SAI8tK7 aFZho2RrFVgMsdMzRT+hSbahyeu9f1SmdVjaqSU/5BoQpFvC4y/beuYfAKTUr+lxXSZi 1vt4y6lSbREajCKXrWkOXbQBprgsHGBY0sEErZea1BHcRE4i2t04l5jLdfy1EeEHBOME FXz/SkoE5dAk7TzlPCdJOiJi49szMDLReHA0WYYgmENEszIDdP2stOh8p0LDPM6OccKG n3YLK9kDMjiebmknm9nqpFZr+nmoR+VtkF736KfyDi3x0IX/1PfnsjYy1ojtjqBF0pMm GjtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id p25-20020a9d6959000000b006ce2dc92612si4466695oto.48.2023.11.16.05.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 05:05:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3BE8780FF28D; Thu, 16 Nov 2023 05:05:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230385AbjKPNFF (ORCPT <rfc822;jaysivo@gmail.com> + 29 others); Thu, 16 Nov 2023 08:05:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230182AbjKPNFD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 16 Nov 2023 08:05:03 -0500 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 071A811D; Thu, 16 Nov 2023 05:04:58 -0800 (PST) Received: from loongson.cn (unknown [112.22.233.25]) by gateway (Coremail) with SMTP id _____8CxLOt5E1Zl8Is6AA--.44338S3; Thu, 16 Nov 2023 21:04:57 +0800 (CST) Received: from localhost.localdomain (unknown [112.22.233.25]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxP912E1ZlOydEAA--.20248S2; Thu, 16 Nov 2023 21:04:56 +0800 (CST) From: WANG Rui <wangrui@loongson.cn> To: Huacai Chen <chenhuacai@kernel.org> Cc: WANG Xuerui <kernel@xen0n.name>, Jinyang He <hejinyang@loongson.cn>, Xi Ruoyao <xry111@xry111.site>, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-kbuild@vger.kernel.org, llvm@lists.linux.dev, loongson-kernel@lists.loongnix.cn, WANG Rui <wangrui@loongson.cn> Subject: [PATCH] LoongArch: Record pc instead of offset in la-abs relocation Date: Thu, 16 Nov 2023 21:03:31 +0800 Message-ID: <20231116130331.241395-1-wangrui@loongson.cn> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxP912E1ZlOydEAA--.20248S2 X-CM-SenderInfo: pzdqw2txl6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7CFyxuF43Zw47Aw4Uur4kuFX_yoW8Zry8pF 9rZr1ktF4rWr1fKF1Dtas8urn8JanrWr1aganxKa48Aa1aqF1DXr1vg3sFvFyUta1FqrWI ga4rKwnaqa1UAwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j1WlkUUUUU= X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 16 Nov 2023 05:05:17 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782725916476469684 X-GMAIL-MSGID: 1782725916476469684 |
Series |
LoongArch: Record pc instead of offset in la-abs relocation
|
|
Commit Message
WANG Rui
Nov. 16, 2023, 1:03 p.m. UTC
To clarify, the previous version functioned flawlessly. However, it's
worth noting that the LLVM's LoongArch backend currently lacks support
for cross-section label calculations. With this patch, we enable the use
of clang to compile relocatable kernels.
Signed-off-by: WANG Rui <wangrui@loongson.cn>
---
arch/loongarch/include/asm/asmmacro.h | 3 +--
arch/loongarch/include/asm/setup.h | 2 +-
arch/loongarch/kernel/relocate.c | 2 +-
3 files changed, 3 insertions(+), 4 deletions(-)
Comments
Hi Rui, On Thu, Nov 16, 2023 at 09:03:31PM +0800, WANG Rui wrote: > To clarify, the previous version functioned flawlessly. However, it's > worth noting that the LLVM's LoongArch backend currently lacks support > for cross-section label calculations. With this patch, we enable the use > of clang to compile relocatable kernels. > > Signed-off-by: WANG Rui <wangrui@loongson.cn> Thanks a lot for the patch! This fixes the CONFIG_RELOCATABLE build for me as well. Tested-by: Nathan Chancellor <nathan@kernel.org> Something I noticed while testing is that a kernel linked with ld.lld does not boot while one linked with ld.bfd did. I think this might be the same issue that Xuerui filed on our issue tracker but I figured I would mention it in case not: https://github.com/ClangBuiltLinux/linux/issues/1883 Cheers, Nathan > --- > arch/loongarch/include/asm/asmmacro.h | 3 +-- > arch/loongarch/include/asm/setup.h | 2 +- > arch/loongarch/kernel/relocate.c | 2 +- > 3 files changed, 3 insertions(+), 4 deletions(-) > > diff --git a/arch/loongarch/include/asm/asmmacro.h b/arch/loongarch/include/asm/asmmacro.h > index c9544f358c33..655db7d7a427 100644 > --- a/arch/loongarch/include/asm/asmmacro.h > +++ b/arch/loongarch/include/asm/asmmacro.h > @@ -609,8 +609,7 @@ > lu32i.d \reg, 0 > lu52i.d \reg, \reg, 0 > .pushsection ".la_abs", "aw", %progbits > - 768: > - .dword 768b-766b > + .dword 766b > .dword \sym > .popsection > #endif > diff --git a/arch/loongarch/include/asm/setup.h b/arch/loongarch/include/asm/setup.h > index a0bc159ce8bd..ee52fb1e9963 100644 > --- a/arch/loongarch/include/asm/setup.h > +++ b/arch/loongarch/include/asm/setup.h > @@ -25,7 +25,7 @@ extern void set_merr_handler(unsigned long offset, void *addr, unsigned long len > #ifdef CONFIG_RELOCATABLE > > struct rela_la_abs { > - long offset; > + long pc; > long symvalue; > }; > > diff --git a/arch/loongarch/kernel/relocate.c b/arch/loongarch/kernel/relocate.c > index 6c3eff9af9fb..288b739ca88d 100644 > --- a/arch/loongarch/kernel/relocate.c > +++ b/arch/loongarch/kernel/relocate.c > @@ -52,7 +52,7 @@ static inline void __init relocate_absolute(long random_offset) > for (p = begin; (void *)p < end; p++) { > long v = p->symvalue; > uint32_t lu12iw, ori, lu32id, lu52id; > - union loongarch_instruction *insn = (void *)p - p->offset; > + union loongarch_instruction *insn = (void *)p->pc; > > lu12iw = (v >> 12) & 0xfffff; > ori = v & 0xfff; > -- > 2.42.1 > >
Applied to loongarch-fixes, thanks. Huacai On Tue, Nov 21, 2023 at 7:08 AM Nathan Chancellor <nathan@kernel.org> wrote: > > Hi Rui, > > On Thu, Nov 16, 2023 at 09:03:31PM +0800, WANG Rui wrote: > > To clarify, the previous version functioned flawlessly. However, it's > > worth noting that the LLVM's LoongArch backend currently lacks support > > for cross-section label calculations. With this patch, we enable the use > > of clang to compile relocatable kernels. > > > > Signed-off-by: WANG Rui <wangrui@loongson.cn> > > Thanks a lot for the patch! This fixes the CONFIG_RELOCATABLE build for > me as well. > > Tested-by: Nathan Chancellor <nathan@kernel.org> > > Something I noticed while testing is that a kernel linked with ld.lld > does not boot while one linked with ld.bfd did. I think this might be > the same issue that Xuerui filed on our issue tracker but I figured I > would mention it in case not: > https://github.com/ClangBuiltLinux/linux/issues/1883 > > Cheers, > Nathan > > > --- > > arch/loongarch/include/asm/asmmacro.h | 3 +-- > > arch/loongarch/include/asm/setup.h | 2 +- > > arch/loongarch/kernel/relocate.c | 2 +- > > 3 files changed, 3 insertions(+), 4 deletions(-) > > > > diff --git a/arch/loongarch/include/asm/asmmacro.h b/arch/loongarch/include/asm/asmmacro.h > > index c9544f358c33..655db7d7a427 100644 > > --- a/arch/loongarch/include/asm/asmmacro.h > > +++ b/arch/loongarch/include/asm/asmmacro.h > > @@ -609,8 +609,7 @@ > > lu32i.d \reg, 0 > > lu52i.d \reg, \reg, 0 > > .pushsection ".la_abs", "aw", %progbits > > - 768: > > - .dword 768b-766b > > + .dword 766b > > .dword \sym > > .popsection > > #endif > > diff --git a/arch/loongarch/include/asm/setup.h b/arch/loongarch/include/asm/setup.h > > index a0bc159ce8bd..ee52fb1e9963 100644 > > --- a/arch/loongarch/include/asm/setup.h > > +++ b/arch/loongarch/include/asm/setup.h > > @@ -25,7 +25,7 @@ extern void set_merr_handler(unsigned long offset, void *addr, unsigned long len > > #ifdef CONFIG_RELOCATABLE > > > > struct rela_la_abs { > > - long offset; > > + long pc; > > long symvalue; > > }; > > > > diff --git a/arch/loongarch/kernel/relocate.c b/arch/loongarch/kernel/relocate.c > > index 6c3eff9af9fb..288b739ca88d 100644 > > --- a/arch/loongarch/kernel/relocate.c > > +++ b/arch/loongarch/kernel/relocate.c > > @@ -52,7 +52,7 @@ static inline void __init relocate_absolute(long random_offset) > > for (p = begin; (void *)p < end; p++) { > > long v = p->symvalue; > > uint32_t lu12iw, ori, lu32id, lu52id; > > - union loongarch_instruction *insn = (void *)p - p->offset; > > + union loongarch_instruction *insn = (void *)p->pc; > > > > lu12iw = (v >> 12) & 0xfffff; > > ori = v & 0xfff; > > -- > > 2.42.1 > > > >
diff --git a/arch/loongarch/include/asm/asmmacro.h b/arch/loongarch/include/asm/asmmacro.h index c9544f358c33..655db7d7a427 100644 --- a/arch/loongarch/include/asm/asmmacro.h +++ b/arch/loongarch/include/asm/asmmacro.h @@ -609,8 +609,7 @@ lu32i.d \reg, 0 lu52i.d \reg, \reg, 0 .pushsection ".la_abs", "aw", %progbits - 768: - .dword 768b-766b + .dword 766b .dword \sym .popsection #endif diff --git a/arch/loongarch/include/asm/setup.h b/arch/loongarch/include/asm/setup.h index a0bc159ce8bd..ee52fb1e9963 100644 --- a/arch/loongarch/include/asm/setup.h +++ b/arch/loongarch/include/asm/setup.h @@ -25,7 +25,7 @@ extern void set_merr_handler(unsigned long offset, void *addr, unsigned long len #ifdef CONFIG_RELOCATABLE struct rela_la_abs { - long offset; + long pc; long symvalue; }; diff --git a/arch/loongarch/kernel/relocate.c b/arch/loongarch/kernel/relocate.c index 6c3eff9af9fb..288b739ca88d 100644 --- a/arch/loongarch/kernel/relocate.c +++ b/arch/loongarch/kernel/relocate.c @@ -52,7 +52,7 @@ static inline void __init relocate_absolute(long random_offset) for (p = begin; (void *)p < end; p++) { long v = p->symvalue; uint32_t lu12iw, ori, lu32id, lu52id; - union loongarch_instruction *insn = (void *)p - p->offset; + union loongarch_instruction *insn = (void *)p->pc; lu12iw = (v >> 12) & 0xfffff; ori = v & 0xfff;