kbuild: Fix lto build issue for aarch64
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Yonghong Song
Commit
bede169618c6("kbuild: enable objtool for *.mod.o and additional kernel objects") added objtool support for various files like *.mod.o, vmlinux.export.o, etc.
But unfortunately it also breaks lto build for aarch64 where a common source file, e.g.,kernel/bpf/syscall.c, is compiled with command:
clang ... -flto=thin ... -c -okernel/bpf/syscall.o/home/yhs/work/bpf-next/kernel/bpf/syscall.c;ld.lld -EL -maarch64elf -z norelro -mllvm -import-instr-limit=5 -z noexecstack \ -r -o kernel/bpf/.tmp_syscall.o kernel/bpf/syscall.o;
Quoted 7 lines
mv
kernel/bpf/.tmp_syscall.okernel/bpf/syscall.oThe above command line completely destroyed thin-lto since file
kernel/bpf/syscall.ois expected to be a llvm bitcode file and later ld.lld can do cross-file inlining.The issue has been reported in [1] and Masahiro actually provided a suggested fix. But unfortunately that suggested fix does not work.
Thanks for the report, but your patch does not fix the real issue.
I think my original [1] worked, although it was a bit redundant (extra $(LD) is executed where it is unnecessary).
Quoted 2 lines
This patch made improvement on top of [2] and the issue for aarch64 lto is fixed. The
x86_64is also tested without any issue.
You are not fixing the issue.
You are just disabling objtool (i.e. reverting bede169618c6).
Quoted 4 lines
In [1], commit
1b466b29a3bf("kbuild: re-enable KCSAN for autogenerated *.mod.c intermediaries") enabled kcsan for *.mod.c files. This patch actually disabled that.
Should we revert commit1b466b29a3bfas well?
No.
I do not want to revert 1b466b29a3bf.
If 1b466b29a3bf were reverted, there would be no point in applying bede169618c6.
Quoted 29 lines
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/CAK7LNATpu5zYwx7kmaknsPGLXt8n8uCXyFpdi5vZeFZiBxYkGw@mail.gmail.com/Fixes bede169618c6 ("kbuild: enable objtool for *.mod.o and additional kernel objects")Signed-off-by Yonghong Song <[email protected]>--- scripts/Makefile.build | 2 ++ scripts/Makefile.lib | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-)scripts/Makefile.build +2
-0@@ -129,6 +129,8 @@ $(obj)/%.ll: $(obj)/%.c FORCE is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y) +need-ld-single = $(is-single-obj-m) + ifdef CONFIG_MODVERSIONS # When module versioning is enabled the following steps are executed: # o compile a <file>.o from <file>.cscripts/Makefile.lib +0
-0
scripts/Makefile.lib endef · line 306
Quoted 5 lines
scripts/Makefile.lib +0
-2@@ -302,11 +302,9 @@ endef # =========================================================================== # These are shared by some Makefile.* files. -objtool-enabled := y -
This is wrong.
You are simply disabling objtool for *.mod.o
I am pretty sure the problem reported by 54babdc
will come back.
I submitted a proper fix.
Quoted 10 lines
scripts/Makefile.lib +1
-2ifdef CONFIG_LTO_CLANG # objtool cannot process LLVM IR. Make $(LD) covert LLVM IR to ELF here. -cmd_ld_single = $(if $(objtool-enabled), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) +cmd_ld_single = $(if $(need-ld-single), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) endif quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ --2.43.5
--
Best Regards
Masahiro Yamada
Quoted 17 lines · Masahiro Yamada
Quoted 9 lines · Yonghong Song
Commit
bede169618c6("kbuild: enable objtool for *.mod.o and additional kernel objects") added objtool support for various files like *.mod.o, vmlinux.export.o, etc. But unfortunately it also breaks lto build for aarch64 where a common source file, e.g.,kernel/bpf/syscall.c, is compiled with command:clang ... -flto=thin ... -c -o kernel/bpf/syscall.o /home/yhs/work/bpf-next/kernel/bpf/syscall.c ; ld.lld -EL -maarch64elf -z norelro -mllvm -import-instr-limit=5 -z noexecstack \ -r -o kernel/bpf/.tmp_syscall.o kernel/bpf/syscall.o; mv kernel/bpf/.tmp_syscall.o kernel/bpf/syscall.oQuoted 5 lines
The above command line completely destroyed thin-lto since file
kernel/bpf/syscall.ois expected to be a llvm bitcode file and later ld.lld can do cross-file inlining.The issue has been reported in [1] and Masahiro actually provided a suggested fix. But unfortunately that suggested fix does not work.
Thanks for the report, but your patch does not fix the real issue.
Quoted 8 lines
I think my original [1] worked, although it was a bit redundant (extra $(LD) is executed where it is unnecessary).
Quoted 2 lines
This patch made improvement on top of [2] and the issue for aarch64 lto is fixed. The
x86_64is also tested without any issue.You are not fixing the issue.
You are just disabling objtool (i.e. revertingbede169618c6).
You are correct. Essentially my patch just reverted bede169618c6 since I am not familar with Makefile.build and Makefile.lib so won't be able to come up with a proper solution.
Quoted 47 lines
Quoted 5 lines
In [1], commit
1b466b29a3bf("kbuild: re-enable KCSAN for autogenerated *.mod.c intermediaries") enabled kcsan for *.mod.c files. This patch actually disabled that.
Should we revert commit1b466b29a3bfas well?No.
I do not want to revert1b466b29a3bf.If
1b466b29a3bfwere reverted, there would be no point in applyingbede169618c6.Quoted 28 lines
[1] https://lore.kernel.org/lkml/[email protected]/ [2] https://lore.kernel.org/lkml/CAK7LNATpu5zYwx7kmaknsPGLXt8n8uCXyFpdi5vZeFZiBxYkGw@mail.gmail.com/Fixes bede169618c6 ("kbuild: enable objtool for *.mod.o and additional kernel objects")Signed-off-by Yonghong Song <[email protected]>--- scripts/Makefile.build | 2 ++ scripts/Makefile.lib | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-)scripts/Makefile.build +2
-0@@ -129,6 +129,8 @@ $(obj)/%.ll: $(obj)/%.c FORCE is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y) +need-ld-single = $(is-single-obj-m) + ifdef CONFIG_MODVERSIONS # When module versioning is enabled the following steps are executed: # o compile a <file>.o from <file>.cscripts/Makefile.lib +0
-0scripts/Makefile.lib endef · line 306
Quoted 5 lines
scripts/Makefile.lib +0
-2@@ -302,11 +302,9 @@ endef # =========================================================================== # These are shared by some Makefile.* files. -objtool-enabled := y -This is wrong.
Quoted 7 lines
You are simply disabling objtool for *.mod.o
I am pretty sure the problem reported by 54babdc
will come back.I submitted a proper fix.
I tested the patch with arm64/x86_64 + lto/no-lto. Everything works fine. I have replied with my Tested-by tag. Thanks!
Quoted 18 lines
Quoted 11 lines
scripts/Makefile.lib +1
-2ifdef CONFIG_LTO_CLANG # objtool cannot process LLVM IR. Make $(LD) covert LLVM IR to ELF here. -cmd_ld_single = $(if $(objtool-enabled), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) +cmd_ld_single = $(if $(need-ld-single), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) endif quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ --Quoted 2 lines
2.43.5
--
Best RegardsMasahiro Yamada