bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH kbuild] kbuild: add -grecord-gcc-switches to clang build
@ 2021-03-28  6:41 Yonghong Song
  2021-03-29 22:52 ` Nick Desaulniers
  0 siblings, 1 reply; 11+ messages in thread
From: Yonghong Song @ 2021-03-28  6:41 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Alexei Starovoitov, Arnaldo Carvalho de Melo, bpf, kernel-team,
	Masahiro Yamada, Michal Marek

Putting compilation flags in dwarf is helpful in that
it tells what potential transformations may have
happened to generate the final binary. Furthermore,
we have a particular usecase in [1] where pahole wants
to detect whether vmlinux is compiled with clang lto
or not, and if vmlinux is compiled with clang lto,
pahole will merge all debuginfo cu's into one pahole cu.

Currently gcc seems put compilation flags into
dwarf DW_AT_producer tag if -g is specified, while
clang needs explicit flag -grecord-gcc-switches.
For example,
 build with gcc 8.4.1 (make -j60):
   ...
   DW_AT_producer    ("GNU C89 8.4.1 20200928 (Red Hat 8.4.1-1) -mno-sse -mno-mmx -mno-sse2 ...")
   DW_AT_language    (DW_LANG_C89)
   DW_AT_name        ("/home/yhs/work/bpf-next/arch/x86/kernel/ebda.c")

 build with clang 13 trunk (make -j60 LLVM=1):
   ...
   DW_AT_producer    ("clang version 13.0.0 (https://github.com/llvm/llvm-project.git
                       11bf268864afbe35ad317e6354c51440d5184911)")
   DW_AT_language    (DW_LANG_C89)
   DW_AT_name        ("/home/yhs/work/bpf-next/arch/x86/kernel/ebda.c")

 With this patch, build with clang 13 trunk:
   ...
   DW_AT_producer    ("clang version 13.0.0 (https://github.com/llvm/llvm-project.git
                       11bf268864afbe35ad317e6354c51440d5184911)
                       /home/yhs/work/llvm-project/llvm/build.cur/install/bin/clang-13 -MMD
                       -MF arch/x86/kernel/.ebda.o.d -nostdinc ...")
   DW_AT_language    (DW_LANG_C89)
   DW_AT_name        ("/home/yhs/work/bpf-next/arch/x86/kernel/ebda.c")

 With detailed compilation flags information, in [1], pahole is able to quickly
 decide whether merging cu's is a right choice or not.

 [1] https://lore.kernel.org/bpf/20210328061646.1955678-1-yhs@fb.com/T

I tested with latest bpf-next, but the patch is also applied cleanly on
top of latest linus tree.

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Makefile b/Makefile
index d4784d181123..ab0119beb42d 100644
--- a/Makefile
+++ b/Makefile
@@ -839,6 +839,12 @@ dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5
 DEBUG_CFLAGS	+= -gdwarf-$(dwarf-version-y)
 endif
 
+# gcc emits compilation flags in dwarf DW_AT_producer by default
+# while clang needs explicit flag. Add this flag explicitly.
+ifdef CONFIG_CC_IS_CLANG
+DEBUG_CFLAGS	+= -grecord-gcc-switches
+endif
+
 ifdef CONFIG_DEBUG_INFO_REDUCED
 DEBUG_CFLAGS	+= $(call cc-option, -femit-struct-debug-baseonly) \
 		   $(call cc-option,-fno-var-tracking)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-03-31  3:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-28  6:41 [PATCH kbuild] kbuild: add -grecord-gcc-switches to clang build Yonghong Song
2021-03-29 22:52 ` Nick Desaulniers
2021-03-30 23:54   ` Yonghong Song
2021-03-31  0:25     ` Fangrui Song
2021-03-31  1:47       ` Yonghong Song
2021-03-31  2:39         ` Fāng-ruì Sòng
2021-03-31  2:51           ` David Blaikie
2021-03-31  3:13             ` Yonghong Song
2021-03-31  3:16               ` David Blaikie
2021-03-31  3:26                 ` Yonghong Song
2021-03-31  3:28                   ` David Blaikie

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).