LoongArch: Record pc instead of offset in la_abs relocation
authorWANG Rui <wangrui@loongson.cn>
Tue, 21 Nov 2023 07:03:25 +0000 (15:03 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Tue, 21 Nov 2023 07:03:25 +0000 (15:03 +0800)
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.

Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: WANG Rui <wangrui@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/include/asm/asmmacro.h
arch/loongarch/include/asm/setup.h
arch/loongarch/kernel/relocate.c

index c9544f358c33991b46b67edec578af1df44939b7..655db7d7a42796d947e857b6c546023d82c13fba 100644 (file)
        lu32i.d \reg, 0
        lu52i.d \reg, \reg, 0
        .pushsection ".la_abs", "aw", %progbits
-       768:
-       .dword  768b-766b
+       .dword  766b
        .dword  \sym
        .popsection
 #endif
index a0bc159ce8bdc0348defe27953c07d973dd58b5f..ee52fb1e99631653e3e40d6998afd159a7e5986d 100644 (file)
@@ -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;
 };
 
index 6c3eff9af9fb1ed4cc4af8ffa9b9ea5490591ee3..288b739ca88dda7891cd675def4a79b3eddd3be3 100644 (file)
@@ -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;