* [PATCH] LoongArch: Record pc instead of offset in la-abs relocation
@ 2023-11-16 13:03 WANG Rui
2023-11-20 23:08 ` Nathan Chancellor
0 siblings, 1 reply; 3+ messages in thread
From: WANG Rui @ 2023-11-16 13:03 UTC (permalink / raw)
To: Huacai Chen
Cc: WANG Xuerui, Jinyang He, Xi Ruoyao, linux-kernel, loongarch,
linux-kbuild, llvm, loongson-kernel, WANG Rui
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(-)
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] LoongArch: Record pc instead of offset in la-abs relocation
2023-11-16 13:03 [PATCH] LoongArch: Record pc instead of offset in la-abs relocation WANG Rui
@ 2023-11-20 23:08 ` Nathan Chancellor
2023-11-21 1:32 ` Huacai Chen
0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2023-11-20 23:08 UTC (permalink / raw)
To: WANG Rui
Cc: Huacai Chen, WANG Xuerui, Jinyang He, Xi Ruoyao, linux-kernel,
loongarch, linux-kbuild, llvm, loongson-kernel
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
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] LoongArch: Record pc instead of offset in la-abs relocation
2023-11-20 23:08 ` Nathan Chancellor
@ 2023-11-21 1:32 ` Huacai Chen
0 siblings, 0 replies; 3+ messages in thread
From: Huacai Chen @ 2023-11-21 1:32 UTC (permalink / raw)
To: Nathan Chancellor
Cc: WANG Rui, WANG Xuerui, Jinyang He, Xi Ruoyao, linux-kernel,
loongarch, linux-kbuild, llvm, loongson-kernel
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
> >
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-21 1:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-16 13:03 [PATCH] LoongArch: Record pc instead of offset in la-abs relocation WANG Rui
2023-11-20 23:08 ` Nathan Chancellor
2023-11-21 1:32 ` Huacai Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®