* [PATCH] LoongArch: Apply dynamic relocations for LLD
@ 2023-11-24 3:55 WANG Rui
2023-11-26 14:20 ` Huacai Chen
0 siblings, 1 reply; 2+ messages in thread
From: WANG Rui @ 2023-11-24 3:55 UTC (permalink / raw)
To: Huacai Chen
Cc: WANG Xuerui, Xi Ruoyao, linux-kernel, loongarch, linux-kbuild,
llvm, loongson-kernel, WANG Rui
For the following assembly code:
.text
.global func
func:
nop
.data
var:
.dword func
When linked with `-pie`, GNU LD populates the `var` variable with the
pre-relocated value of `func`. However, LLVM LLD does not exhibit the
same behavior. This issue also arises with the `kernel_entry` in
arch/loongarch/kernel/head.S:
_head:
.word MZ_MAGIC /* "MZ", MS-DOS header */
.org 0x8
.dword kernel_entry /* Kernel entry point */
The correct kernel entry from the MS-DOS header is crucial for jumping
to vmlinux from zboot. This necessity is why the compressed kernel
compiled by Clang encounters difficulties in booting.
To address this problem, it is proposed to apply dynamic relocations to
place with `--apply-dynamic-relocs`.
Link: https://github.com/ClangBuiltLinux/linux/issues/1962
Signed-off-by: WANG Rui <wangrui@loongson.cn>
---
arch/loongarch/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index 1f0d74403419..05ab85118212 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -83,7 +83,7 @@ endif
ifeq ($(CONFIG_RELOCATABLE),y)
KBUILD_CFLAGS_KERNEL += -fPIE
-LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext
+LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext $(call ld-option, --apply-dynamic-relocs)
endif
cflags-y += $(call cc-option, -mno-check-zero-division)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] LoongArch: Apply dynamic relocations for LLD
2023-11-24 3:55 [PATCH] LoongArch: Apply dynamic relocations for LLD WANG Rui
@ 2023-11-26 14:20 ` Huacai Chen
0 siblings, 0 replies; 2+ messages in thread
From: Huacai Chen @ 2023-11-26 14:20 UTC (permalink / raw)
To: WANG Rui
Cc: WANG Xuerui, Xi Ruoyao, linux-kernel, loongarch, linux-kbuild,
llvm, loongson-kernel
Queued for loongarch-fixes, thanks.
Huacai
On Fri, Nov 24, 2023 at 11:56 AM WANG Rui <wangrui@loongson.cn> wrote:
>
> For the following assembly code:
>
> .text
> .global func
> func:
> nop
>
> .data
> var:
> .dword func
>
> When linked with `-pie`, GNU LD populates the `var` variable with the
> pre-relocated value of `func`. However, LLVM LLD does not exhibit the
> same behavior. This issue also arises with the `kernel_entry` in
> arch/loongarch/kernel/head.S:
>
> _head:
> .word MZ_MAGIC /* "MZ", MS-DOS header */
> .org 0x8
> .dword kernel_entry /* Kernel entry point */
>
> The correct kernel entry from the MS-DOS header is crucial for jumping
> to vmlinux from zboot. This necessity is why the compressed kernel
> compiled by Clang encounters difficulties in booting.
>
> To address this problem, it is proposed to apply dynamic relocations to
> place with `--apply-dynamic-relocs`.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1962
> Signed-off-by: WANG Rui <wangrui@loongson.cn>
> ---
> arch/loongarch/Makefile | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
> index 1f0d74403419..05ab85118212 100644
> --- a/arch/loongarch/Makefile
> +++ b/arch/loongarch/Makefile
> @@ -83,7 +83,7 @@ endif
>
> ifeq ($(CONFIG_RELOCATABLE),y)
> KBUILD_CFLAGS_KERNEL += -fPIE
> -LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext
> +LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext $(call ld-option, --apply-dynamic-relocs)
> endif
>
> cflags-y += $(call cc-option, -mno-check-zero-division)
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-26 14:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-24 3:55 [PATCH] LoongArch: Apply dynamic relocations for LLD WANG Rui
2023-11-26 14:20 ` Huacai Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).