From: Yonghong Song <yhs@fb.com>
To: <linux-kbuild@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
<bpf@vger.kernel.org>, <kernel-team@fb.com>,
Masahiro Yamada <masahiroy@kernel.org>,
Michal Marek <michal.lkml@markovi.net>
Subject: [PATCH kbuild] kbuild: add -grecord-gcc-switches to clang build
Date: Sat, 27 Mar 2021 23:41:21 -0700 [thread overview]
Message-ID: <20210328064121.2062927-1-yhs@fb.com> (raw)
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
next reply other threads:[~2021-03-28 6:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-28 6:41 Yonghong Song [this message]
2021-03-29 22:52 ` [PATCH kbuild] kbuild: add -grecord-gcc-switches to clang build 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210328064121.2062927-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=arnaldo.melo@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=michal.lkml@markovi.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).