kbuild: mkcompile_h: Include $LD version in /proc/version
PATCH 1/1 kbuild: mkcompile_h: Include $LD version in /proc/version
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to /proc/version.
--- init/Makefile | 2 +- scripts/mkcompile_h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)
init/Makefile +1 -1
@@ -35,4 +35,4 @@ include/generated/compile.h: FORCE @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ - "$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)" + "$(CONFIG_PREEMPT_RT)" "$(LD)" "$(CC) $(KBUILD_CFLAGS)"
scripts/mkcompile_h +6 -2
@@ -6,7 +6,8 @@ ARCH=$2 SMP=$3 PREEMPT=$4 PREEMPT_RT=$5 -CC=$6 +LD=$6 +CC=$7 vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
@@ -72,7 +73,10 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)" printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY" echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\" - echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\" + CC_VERSION=$($CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//') + LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \ + | sed 's/[[:space:]]*$//') + printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION" } > .tmpcompile # Only replace the real compile.h if the new one is different,
Signature · 5 lines
2.20.1 -- Kees Cook
Quoted 7 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.Signed-off-by Kees Cook <[email protected]>
Hi Kees,
this patch is really really a good one!
I use Clang and LLD to build my Linux-kernels.
For archiving important informations of my latest build I did:
cd linux
readelf -p .comment vmlinux > ../archives/readelf-p-comment_vmlinux.txt ...or...
readelf -p .comment arch/x86/boot/compressed/vmlinux > ../archives/readelf-p-comment_vmlinux-compressed.txt
The output looks like:
String dump of section '.comment':
[ 0] Linker: LLD 10.0.0
[ 14] clang version 10.0.0-1
With my next linux-kernel build I will include this one.
Feel free to add any appropriate credits.
Thanks.
Regards,
- Sedat -
Quoted 52 lines
--- init/Makefile | 2 +- scripts/mkcompile_h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)init/Makefile +1
-1@@ -35,4 +35,4 @@ include/generated/compile.h: FORCE @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ - "$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)" + "$(CONFIG_PREEMPT_RT)" "$(LD)" "$(CC) $(KBUILD_CFLAGS)"scripts/mkcompile_h +6
-3@@ -6,7 +6,8 @@ ARCH=$2 SMP=$3 PREEMPT=$4 PREEMPT_RT=$5 -CC=$6 +LD=$6 +CC=$7 vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }@@ -72,7 +73,10 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)" printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY" echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\" - echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\" + CC_VERSION=$($CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//') + LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \ + | sed 's/[[:space:]]*$//') + printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION" } > .tmpcompile # Only replace the real compile.h if the new one is different, --2.20.1
--
Kees Cook--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/202004020117.6E434C035%40keescook.
Hi Kees,
Quoted 27 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.Signed-off-by Kees Cook <[email protected]>--- init/Makefile | 2 +- scripts/mkcompile_h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)init/Makefile +1
-1@@ -35,4 +35,4 @@ include/generated/compile.h: FORCE @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ - "$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)" + "$(CONFIG_PREEMPT_RT)" "$(LD)" "$(CC) $(KBUILD_CFLAGS)"scripts/mkcompile_h +0
-0
scripts/mkcompile_h ARCH=$2 · line 10
Quoted 6 lines
scripts/mkcompile_h +2
-1@@ -6,7 +6,8 @@ ARCH=$2 SMP=$3 PREEMPT=$4 PREEMPT_RT=$5 -CC=$6 +LD=$6 +CC=$7
Just a nit.
If you just append 'LD',
you do not need to touch the 'CC=$6' line.
If you do not mind, I will fold the following
on top of your patch.
init/Makefile +1 -1
@@ -35,4 +35,4 @@ include/generated/compile.h: FORCE @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ - "$(CONFIG_PREEMPT_RT)" "$(LD)" "$(CC) $(KBUILD_CFLAGS)" + "$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)" "$(LD)"
scripts/mkcompile_h +2 -2
@@ -6,8 +6,8 @@ ARCH=$2 SMP=$3 PREEMPT=$4 PREEMPT_RT=$5 -LD=$6 -CC=$7 +CC=$6 +LD=$7
--
Best Regards
Masahiro Yamada
Quoted 40 lines · Masahiro Yamada
Hi Kees,
Quoted 27 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.Signed-off-by Kees Cook <[email protected]>--- init/Makefile | 2 +- scripts/mkcompile_h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)init/Makefile +1
-1@@ -35,4 +35,4 @@ include/generated/compile.h: FORCE @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ - "$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)" + "$(CONFIG_PREEMPT_RT)" "$(LD)" "$(CC) $(KBUILD_CFLAGS)"scripts/mkcompile_h +0
-0scripts/mkcompile_h ARCH=$2 · line 10
Quoted 6 lines
scripts/mkcompile_h +2
-1@@ -6,7 +6,8 @@ ARCH=$2 SMP=$3 PREEMPT=$4 PREEMPT_RT=$5 -CC=$6 +LD=$6 +CC=$7Just a nit.
Quoted 2 lines
If you just append 'LD',
you do not need to touch the 'CC=$6' line.
Oh! Yes, good point. I had convinced myself that the "CC=$6" was dropping all the passed-in KBUILD_CFLAGS, but I failed to notice the double quotes.
Quoted 2 lines
If you do not mind, I will fold the following
on top of your patch.
Yes, that would be great; thanks!
-Kees
Quoted 33 lines
init/Makefile +1
-1@@ -35,4 +35,4 @@ include/generated/compile.h: FORCE @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ - "$(CONFIG_PREEMPT_RT)" "$(LD)" "$(CC) $(KBUILD_CFLAGS)" + "$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)" "$(LD)"scripts/mkcompile_h +2
-3@@ -6,8 +6,8 @@ ARCH=$2 SMP=$3 PREEMPT=$4 PREEMPT_RT=$5 -LD=$6 -CC=$7 +CC=$6 +LD=$7 --Best Regards
Masahiro Yamada
Signature · 1 line
Kees Cook
Quoted 41 lines · Masahiro Yamada
Hi Kees,
Quoted 27 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.Signed-off-by Kees Cook <[email protected]>--- init/Makefile | 2 +- scripts/mkcompile_h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)init/Makefile +1
-1@@ -35,4 +35,4 @@ include/generated/compile.h: FORCE @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ - "$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)" + "$(CONFIG_PREEMPT_RT)" "$(LD)" "$(CC) $(KBUILD_CFLAGS)"scripts/mkcompile_h +0
-0scripts/mkcompile_h ARCH=$2 · line 10
Quoted 6 lines
scripts/mkcompile_h +2
-1@@ -6,7 +6,8 @@ ARCH=$2 SMP=$3 PREEMPT=$4 PREEMPT_RT=$5 -CC=$6 +LD=$6 +CC=$7Just a nit.
Quoted 6 lines
If you just append 'LD',
you do not need to touch the 'CC=$6' line.If you do not mind, I will fold the following
on top of your patch.
With Kees patch + Masahiro's diff applied:
$ cat /proc/version Linux version 5.6.0-rc7-next-20200330+ (ndesaulniers@<hostname scrubbed>) (clang version 11.0.0 ([email protected]:llvm/llvm-project.git 6d71daed03ced011cd25f4e4f4122a368fdc757d), LLD 11.0.0 ([email protected]:llvm/llvm-project.git 6d71daed03ced011cd25f4e4f4122a368fdc757d)) #167 SMP Thu Apr 2 11:17:36 PDT 2020
We could actually use this in Android for a VTS test I've, uh, been meaning to write. Also, LOL at scrubbing the "compatible with" part, reminds me of user agent strings in the browser, which are god awful.
Quoted 20 lines
init/Makefile +1
-1@@ -35,4 +35,4 @@ include/generated/compile.h: FORCE @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ - "$(CONFIG_PREEMPT_RT)" "$(LD)" "$(CC) $(KBUILD_CFLAGS)" + "$(CONFIG_PREEMPT_RT)" "$(CC) $(KBUILD_CFLAGS)" "$(LD)"scripts/mkcompile_h +2
-2@@ -6,8 +6,8 @@ ARCH=$2 SMP=$3 PREEMPT=$4 PREEMPT_RT=$5 -LD=$6 -CC=$7 +CC=$6 +LD=$7
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 11 lines · Nick Desaulniers
With Kees patch + Masahiro's diff applied:
$ cat /proc/version Linux version 5.6.0-rc7-next-20200330+ (ndesaulniers@<hostname scrubbed>) (clang version 11.0.0 ([email protected]:llvm/llvm-project.git 6d71daed03ced011cd25f4e4f4122a368fdc757d), LLD 11.0.0 ([email protected]:llvm/llvm-project.git 6d71daed03ced011cd25f4e4f4122a368fdc757d)) #167 SMP Thu Apr 2 11:17:36 PDT 2020Reviewed-by Nick Desaulniers <[email protected]>Tested-by Nick Desaulniers <[email protected]>
Awesome! Thanks for testing. :)
Quoted 3 lines
We could actually use this in Android for a VTS test I've, uh, been meaning to write. Also, LOL at scrubbing the "compatible with" part, reminds me of user agent strings in the browser, which are god awful.
Heh, yeah. That's there because (actually, I think _you_ told me this when I asked during the ClangBuiltLinux summit) other tools scanned the LD version string for the binutils-specific bits. For this, since it's newly added to the kernel /proc/version, nothing is already expecting to find an LD string, and it looked super weird in there if I left it as-is. Hence, scrub!
-Kees
Signature · 1 line
Kees Cook
Quoted 6 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.Signed-off-by Kees Cook <[email protected]>
With this patch + Masahiro's fold in:
Fangrui Song
Reviewed-byQuoted 19 lines · Kees Cook
Quoted 11 lines · Nick Desaulniers
With Kees patch + Masahiro's diff applied:
$ cat /proc/version Linux version 5.6.0-rc7-next-20200330+ (ndesaulniers@<hostname scrubbed>) (clang version 11.0.0 ([email protected]:llvm/llvm-project.git 6d71daed03ced011cd25f4e4f4122a368fdc757d), LLD 11.0.0 ([email protected]:llvm/llvm-project.git 6d71daed03ced011cd25f4e4f4122a368fdc757d)) #167 SMP Thu Apr 2 11:17:36 PDT 2020Reviewed-by Nick Desaulniers <[email protected]>Tested-by Nick Desaulniers <[email protected]>Awesome! Thanks for testing. :)
Quoted 3 lines
We could actually use this in Android for a VTS test I've, uh, been meaning to write. Also, LOL at scrubbing the "compatible with" part, reminds me of user agent strings in the browser, which are god awful.
Quoted 8 lines
Heh, yeah. That's there because (actually, I think _you_ told me this when I asked during the ClangBuiltLinux summit) other tools scanned the LD version string for the binutils-specific bits. For this, since it's newly added to the kernel
/proc/version, nothing is already expecting to find an LD string, and it looked super weird in there if I left it as-is. Hence, scrub!-Kees
Thanks for the patch! This is a great idea. The linker version may be more useful if link-time optimizations or future post link-time optimizations are enabled. The linker will do code generation just like the compiler and there will be lots of variety. The LD version can become more useful in the future.
Quoted 1 line
+ LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
This User-Agent style hack reminds me of https://reviews.llvm.org/D31199
... Looks like nobody had posted patch to teach libtool about LLD yet! So, I just posted a patch. It should appear on
https://lists.gnu.org/archive/html/libtool-patches/2020-04/index.html in less than 15 minutes.
As what Nathan has just said
Quoted 1 line
With this patch + Masahiro's fold in:
Quoted 10 lines · Sedat Dilek
Quoted 7 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.Signed-off-by Kees Cook <[email protected]>
Please feel free and add:
When I looked at the original patch of Kees I wondered why $(KBUILD_CFLAGS) is passed, but Masahiro has a patch for that...
"[PATCH] kbuild: do not pass $(KBUILD_CFLAGS) to scripts/mkcompile_h"
...see [1].
I have tested with both patches in linux-kbuild.git#kbuild against Linux v5.6.
- Sedat -
Quoted 10 lines · Sedat Dilek
Quoted 8 lines · Sedat Dilek
Quoted 6 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
Signed-off-by Kees Cook <[email protected]>Please feel free and add:
Reviewed-by Sedat Dilek <[email protected]>Tested-by Sedat Dilek <[email protected]>
Thanks.
I collected all Reviewed-by and Tested-by.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 17 lines · Masahiro Yamada
Quoted 15 lines · Sedat Dilek
Quoted 10 lines · Sedat Dilek
Quoted 7 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.Signed-off-by Kees Cook <[email protected]>Please feel free and add:
Quoted 8 lines
Quoted 2 lines
Reviewed-by Sedat Dilek <[email protected]>Tested-by Sedat Dilek <[email protected]>Thanks.
I collected all Reviewed-by and Tested-by.
How to test scripts/mkcompile_h?
I did:
$ cd /path/to/linux
$ head -10 scripts/mkcompile_h #!/bin/sh # SPDX-License-Identifier: GPL-2.0
TARGET=$1
ARCH=$2
SMP=$3
PREEMPT=$4
PREEMPT_RT=$5
CC=$6
LD=$7
$ scripts/mkcompile_h include/generated/compile.h x86_64 SMP "" "" clang-10 ld.lld-10 UPD include/generated/compile.h
$ cat include/generated/compile.h /* This file is auto generated, version 1 */ /* SMP */ #define UTS_MACHINE "x86_64" #define UTS_VERSION "#1 SMP Mon Apr 6 12:29:53 CEST 2020" #define LINUX_COMPILE_BY "dileks" #define LINUX_COMPILE_HOST "iniza" #define LINUX_COMPILER "clang version 10.0.0-2, LLD 10.0.0"
This is with clang-10 and ld.lld-10 from Debian/unstable:
$ clang-10 -v clang version 10.0.0-2 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64
$ ld.lld-10 -v LLD 10.0.0 (compatible with GNU linkers)
Thanks.
- sed@ -
Quoted 22 lines · Sedat Dilek
Quoted 21 lines · Masahiro Yamada
Quoted 17 lines · Sedat Dilek
Quoted 10 lines · Sedat Dilek
Quoted 7 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.Signed-off-by Kees Cook <[email protected]>Please feel free and add:
Reviewed-by Sedat Dilek <[email protected]>Tested-by Sedat Dilek <[email protected]>
Quoted 6 lines
Quoted 4 lines
Thanks.
I collected all Reviewed-by and Tested-by.
How to test
scripts/mkcompile_h?
There's probably a better way, but I do:
$ rm include/generated/compile.h init/version.o $ make init/version.o $ cat include/generated/compile.h
-Kees
Quoted 55 lines
I did:
$ cd /path/to/linux$ head -10 scripts/mkcompile_h #!/bin/sh # SPDX-License-Identifier: GPL-2.0TARGET=$1
ARCH=$2
SMP=$3
PREEMPT=$4
PREEMPT_RT=$5
CC=$6
LD=$7$ scripts/mkcompile_h include/generated/compile.h x86_64 SMP "" "" clang-10 ld.lld-10 UPD include/generated/compile.h$ cat include/generated/compile.h /* This file is auto generated, version 1 */ /* SMP */ #define UTS_MACHINE "x86_64" #define UTS_VERSION "#1 SMP Mon Apr 6 12:29:53 CEST 2020" #define LINUX_COMPILE_BY "dileks" #define LINUX_COMPILE_HOST "iniza" #define LINUX_COMPILER "clang version 10.0.0-2, LLD 10.0.0"This is with clang-10 and ld.lld-10 from Debian/unstable:
$ clang-10 -v clang version 10.0.0-2 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64$ ld.lld-10 -v LLD 10.0.0 (compatible with GNU linkers)Thanks.
- sed@ -
Signature · 1 line
Kees Cook
On Mon, Apr 6, 2020 at 5:53 PM Kees Cook <[email protected]> wrote:
[ ... ]
Quoted 8 lines
Quoted 1 line
How to test
scripts/mkcompile_h?There's probably a better way, but I do:
$ rm include/generated/compile.h init/version.o $ make init/version.o $ cat include/generated/compile.h
Thanks Kees.
# Clean-up
make distclean
# Prereq: Generate include/generated/autoconf.h file
cp -v /boot/config-5.6.0-2-amd64-clang .config
MAKE="make V=1" ; COMPILER="mycompiler" ; LINKER="mylinker" ; MAKE_OPTS="CC=$COMPILER HOSTCC=$COMPILER LD=$LINKER HOSTLD=$LINKER" yes "" | $MAKE $MAKE_OPTS oldconfig && $MAKE $MAKE_OPTS syncconfig < /dev/null
# Generate include/generated/compile.h file
$MAKE $MAKE_OPTS init/version.o
cat include/generated/compile.h
/* This file is auto generated, version 1 */
/* SMP */
#define UTS_MACHINE "x86_64"
#define UTS_VERSION "#1 SMP Mon Apr 6 19:05:53 CEST 2020" #define LINUX_COMPILE_BY "dileks"
#define LINUX_COMPILE_HOST "iniza"
#define LINUX_COMPILER "clang version 10.0.0-2, LLD 10.0.0"
- sed@ -
Quoted 6 lines · Kees Cook
When doing Clang builds of the kernel, it is possible to link with either ld.bfd (binutils) or ld.lld (LLVM), but it is not possible to discover this from a running kernel. Add the "$LD -v" output to
/proc/version.
What about also having the linker and its version in the generated linux-config file?
$ git diff
Kconfig +1 -1
@@ -5,7 +5,7 @@ # mainmenu "Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration" -comment "Compiler: $(CC_VERSION_TEXT)" +comment "Compiler: $(CC_VERSION_TEXT) Linker: $(LD_VERSION_TEXT)" source "scripts/Kconfig.include"
Makefile +4 -1
@@ -553,6 +553,9 @@ endif # and from include/config/auto.conf.cmd to detect the compiler upgrade. CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1) +# LD_VERSION_TEXT is referenced from Kconfig (so it needs export). +LD_VERSION_TEXT = $(shell $(LD) --version 2>/dev/null | head -n 1) + ifdef config-build # =========================================================================== # *config targets only - make sure prerequisites are updated, and descend
@@ -562,7 +565,7 @@ ifdef config-build # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' include arch/$(SRCARCH)/Makefile -export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT +export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT LD_VERSION_TEXT config: outputmakefile scripts_basic FORCE $(Q)$(MAKE) $(build)=scripts/kconfig $@
This generates here:
.config 2020-04-08 12:16:43.477674201 +0200 renamed from boot/config-5.6.0-3-amd64-clang 2020-04-01 13:18:13.000000000 +0200 +2 -2
@@ -1,10 +1,10 @@ # # Automatically generated file; DO NOT EDIT. -# Linux/x86 5.6.0 Kernel Configuration +# Linux/x86 5.6.3 Kernel Configuration # # -# Compiler: clang version 10.0.0-1 +# Compiler: clang version 10.0.0-2 Linker: LLD 10.0.0 (compatible
with GNU linkers)
- Sedat -