2020-04-02 08:20:20

by Kees Cook

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Kees Cook <[email protected]>
---
init/Makefile | 2 +-
scripts/mkcompile_h | 8 ++++++--
2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/init/Makefile b/init/Makefile
index 6246a06364d0..82c15bdb42d7 100644
--- a/init/Makefile
+++ b/init/Makefile
@@ -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)"
diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
index 3a5a4b210c86..f98c07709370 100755
--- a/scripts/mkcompile_h
+++ b/scripts/mkcompile_h
@@ -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


2020-04-02 14:25:12

by Sedat Dilek

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Thu, Apr 2, 2020 at 10:18 AM Kees Cook <[email protected]> wrote:
>
> 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 -

> ---
> init/Makefile | 2 +-
> scripts/mkcompile_h | 8 ++++++--
> 2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/init/Makefile b/init/Makefile
> index 6246a06364d0..82c15bdb42d7 100644
> --- a/init/Makefile
> +++ b/init/Makefile
> @@ -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)"
> diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
> index 3a5a4b210c86..f98c07709370 100755
> --- a/scripts/mkcompile_h
> +++ b/scripts/mkcompile_h
> @@ -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.

2020-04-02 17:11:02

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

Hi Kees,

On Thu, Apr 2, 2020 at 5:18 PM Kees Cook <[email protected]> wrote:
>
> 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(-)
>
> diff --git a/init/Makefile b/init/Makefile
> index 6246a06364d0..82c15bdb42d7 100644
> --- a/init/Makefile
> +++ b/init/Makefile
> @@ -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)"
> diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
> index 3a5a4b210c86..f98c07709370 100755
> --- a/scripts/mkcompile_h
> +++ b/scripts/mkcompile_h
> @@ -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.




--- a/init/Makefile
+++ b/init/Makefile
@@ -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)"
diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
index 8b38a96163e2..5b80a4699740 100755
--- a/scripts/mkcompile_h
+++ b/scripts/mkcompile_h
@@ -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

2020-04-02 18:19:07

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Fri, Apr 03, 2020 at 02:00:52AM +0900, Masahiro Yamada wrote:
> Hi Kees,
>
> On Thu, Apr 2, 2020 at 5:18 PM Kees Cook <[email protected]> wrote:
> >
> > 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(-)
> >
> > diff --git a/init/Makefile b/init/Makefile
> > index 6246a06364d0..82c15bdb42d7 100644
> > --- a/init/Makefile
> > +++ b/init/Makefile
> > @@ -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)"
> > diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
> > index 3a5a4b210c86..f98c07709370 100755
> > --- a/scripts/mkcompile_h
> > +++ b/scripts/mkcompile_h
> > @@ -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.

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.

> If you do not mind, I will fold the following
> on top of your patch.

Yes, that would be great; thanks!

-Kees

>
>
>
>
> --- a/init/Makefile
> +++ b/init/Makefile
> @@ -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)"
> diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
> index 8b38a96163e2..5b80a4699740 100755
> --- a/scripts/mkcompile_h
> +++ b/scripts/mkcompile_h
> @@ -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

--
Kees Cook

2020-04-02 18:39:21

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Thu, Apr 2, 2020 at 10:02 AM Masahiro Yamada <[email protected]> wrote:
>
> Hi Kees,
>
> On Thu, Apr 2, 2020 at 5:18 PM Kees Cook <[email protected]> wrote:
> >
> > 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(-)
> >
> > diff --git a/init/Makefile b/init/Makefile
> > index 6246a06364d0..82c15bdb42d7 100644
> > --- a/init/Makefile
> > +++ b/init/Makefile
> > @@ -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)"
> > diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
> > index 3a5a4b210c86..f98c07709370 100755
> > --- a/scripts/mkcompile_h
> > +++ b/scripts/mkcompile_h
> > @@ -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.

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

Reviewed-by: Nick Desaulniers <[email protected]>
Tested-by: Nick Desaulniers <[email protected]>

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.


> --- a/init/Makefile
> +++ b/init/Makefile
> @@ -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)"
> diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
> index 8b38a96163e2..5b80a4699740 100755
> --- a/scripts/mkcompile_h
> +++ b/scripts/mkcompile_h
> @@ -6,8 +6,8 @@ ARCH=$2
> SMP=$3
> PREEMPT=$4
> PREEMPT_RT=$5
> -LD=$6
> -CC=$7
> +CC=$6
> +LD=$7


--
Thanks,
~Nick Desaulniers

2020-04-02 18:43:39

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Thu, Apr 02, 2020 at 11:22:02AM -0700, Nick Desaulniers wrote:
> 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
>
> Reviewed-by: Nick Desaulniers <[email protected]>
> Tested-by: Nick Desaulniers <[email protected]>

Awesome! Thanks for testing. :)

> 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

--
Kees Cook

2020-04-04 04:03:22

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Thu, Apr 02, 2020 at 01:18:37AM -0700, Kees Cook wrote:
> 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:

Reviewed-by: Nathan Chancellor <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>

2020-04-04 04:58:06

by Fangrui Song

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On 2020-04-02, Kees Cook wrote:
>On Thu, Apr 02, 2020 at 11:22:02AM -0700, Nick Desaulniers wrote:
>> 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
>>
>> Reviewed-by: Nick Desaulniers <[email protected]>
>> Tested-by: Nick Desaulniers <[email protected]>
>
>Awesome! Thanks for testing. :)
>
>> 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

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.

> + 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

> With this patch + Masahiro's fold in:

Reviewed-by: Fangrui Song <[email protected]>

2020-04-05 11:24:45

by Sedat Dilek

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Thu, Apr 2, 2020 at 4:24 PM Sedat Dilek <[email protected]> wrote:
>
> On Thu, Apr 2, 2020 at 10:18 AM Kees Cook <[email protected]> wrote:
> >
> > 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]>

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 -

[1] https://patchwork.kernel.org/patch/11473667/

2020-04-05 13:58:02

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Sun, Apr 5, 2020 at 8:23 PM Sedat Dilek <[email protected]> wrote:
>
> On Thu, Apr 2, 2020 at 4:24 PM Sedat Dilek <[email protected]> wrote:
> >
> > On Thu, Apr 2, 2020 at 10:18 AM Kees Cook <[email protected]> wrote:
> > >
> > > 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]>


Thanks.

I collected all Reviewed-by and Tested-by.






--
Best Regards
Masahiro Yamada

2020-04-06 10:36:15

by Sedat Dilek

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Sun, Apr 5, 2020 at 3:56 PM Masahiro Yamada <[email protected]> wrote:
>
> On Sun, Apr 5, 2020 at 8:23 PM Sedat Dilek <[email protected]> wrote:
> >
> > On Thu, Apr 2, 2020 at 4:24 PM Sedat Dilek <[email protected]> wrote:
> > >
> > > On Thu, Apr 2, 2020 at 10:18 AM Kees Cook <[email protected]> wrote:
> > > >
> > > > 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]>
>
>
> 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@ -

2020-04-06 15:54:47

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Mon, Apr 06, 2020 at 12:35:35PM +0200, Sedat Dilek wrote:
> On Sun, Apr 5, 2020 at 3:56 PM Masahiro Yamada <[email protected]> wrote:
> >
> > On Sun, Apr 5, 2020 at 8:23 PM Sedat Dilek <[email protected]> wrote:
> > >
> > > On Thu, Apr 2, 2020 at 4:24 PM Sedat Dilek <[email protected]> wrote:
> > > >
> > > > On Thu, Apr 2, 2020 at 10:18 AM Kees Cook <[email protected]> wrote:
> > > > >
> > > > > 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]>
> >
> >
> > 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

>
> 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@ -

--
Kees Cook

2020-04-06 17:45:26

by Sedat Dilek

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Mon, Apr 6, 2020 at 5:53 PM Kees Cook <[email protected]> wrote:
[ ... ]
> > 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@ -

2020-04-08 11:56:20

by Sedat Dilek

[permalink] [raw]
Subject: Re: [PATCH] kbuild: mkcompile_h: Include $LD version in /proc/version

On Thu, Apr 2, 2020 at 10:18 AM Kees Cook <[email protected]> wrote:
>
> 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
diff --git a/Kconfig b/Kconfig
index e10b3ee084d4..98fd210786e5 100644
--- a/Kconfig
+++ b/Kconfig
@@ -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"

diff --git a/Makefile b/Makefile
index 91b90ec1737c..42d6834b2255 100644
--- a/Makefile
+++ b/Makefile
@@ -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:

--- /boot/config-5.6.0-3-amd64-clang 2020-04-01 13:18:13.000000000 +0200
+++ .config 2020-04-08 12:16:43.477674201 +0200
@@ -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 -