public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables
@ 2021-12-15 14:58 Adrian Ratiu
  2021-12-15 21:36 ` James Beddek
  2021-12-16  0:32 ` Andrew Savchenko
  0 siblings, 2 replies; 8+ messages in thread
From: Adrian Ratiu @ 2021-12-15 14:58 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Manoj Gupta

Starting with kernel>=v5.7 the build system can override the
tools vars by setting LLVM=1 [1], but older kernels still use
the default GNU tools, so to be able to use a full LLVM/Clang
build, CC should be set together with AR to the portage set
values.

Doing this avoids situations like building the kernel with
clang (using the set HOSTCC) but using gcc/gnu-ar for headers.

[1] a0d1c951ef08 kbuild: support LLVM=1 to switch the default tools to Clang/LLVM

Co-authored-by: Manoj Gupta <manojgupta@chromium.org>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 eclass/kernel-2.eclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
index adc1425bc2e..caeec86ff59 100644
--- a/eclass/kernel-2.eclass
+++ b/eclass/kernel-2.eclass
@@ -692,7 +692,7 @@ env_setup_xmakeopts() {
 	elif type -p ${CHOST}-ar >/dev/null; then
 		xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
 	fi
-	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)"
+	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC) CC=$(tc-getCC) AR=$(tc-getAR)"
 	export xmakeopts
 }
 
-- 
2.34.1



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

* Re: [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables
  2021-12-15 14:58 [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables Adrian Ratiu
@ 2021-12-15 21:36 ` James Beddek
  2021-12-15 21:44   ` Manoj Gupta
  2021-12-16 19:25   ` Adrian Ratiu
  2021-12-16  0:32 ` Andrew Savchenko
  1 sibling, 2 replies; 8+ messages in thread
From: James Beddek @ 2021-12-15 21:36 UTC (permalink / raw)
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1508 bytes --]

On Thursday, 16 December 2021 3:58:26 AM NZDT Adrian Ratiu wrote:
> Starting with kernel>=v5.7 the build system can override the
> tools vars by setting LLVM=1 [1], but older kernels still use
> the default GNU tools, so to be able to use a full LLVM/Clang
> build, CC should be set together with AR to the portage set
> values.
> 
> Doing this avoids situations like building the kernel with
> clang (using the set HOSTCC) but using gcc/gnu-ar for headers.
> 
> [1] a0d1c951ef08 kbuild: support LLVM=1 to switch the default tools to
> Clang/LLVM
> 
> Co-authored-by: Manoj Gupta <manojgupta@chromium.org>
> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
> ---
>  eclass/kernel-2.eclass | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
> index adc1425bc2e..caeec86ff59 100644
> --- a/eclass/kernel-2.eclass
> +++ b/eclass/kernel-2.eclass
> @@ -692,7 +692,7 @@ env_setup_xmakeopts() {
>  	elif type -p ${CHOST}-ar >/dev/null; then
>  		xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
>  	fi
> -	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)"
> +	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC) CC=$(tc-getCC)
> AR=$(tc-getAR)" export xmakeopts
>  }

What's the reason for not using $LLVM here? To preserve building with clang 
for kernels < 5.7 ?

I might be missing the point, but wouldn't something along the lines of
"LLVM=$(! [[ $(tc-getCC) =~ clang ]]; echo $?)" work to preserve the correct 
compiler tools?

Cheers

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables
  2021-12-15 21:36 ` James Beddek
@ 2021-12-15 21:44   ` Manoj Gupta
  2021-12-16 19:25   ` Adrian Ratiu
  1 sibling, 0 replies; 8+ messages in thread
From: Manoj Gupta @ 2021-12-15 21:44 UTC (permalink / raw)
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 2013 bytes --]

On Wed, Dec 15, 2021 at 1:37 PM James Beddek <telans@posteo.de> wrote:

> On Thursday, 16 December 2021 3:58:26 AM NZDT Adrian Ratiu wrote:
> > Starting with kernel>=v5.7 the build system can override the
> > tools vars by setting LLVM=1 [1], but older kernels still use
> > the default GNU tools, so to be able to use a full LLVM/Clang
> > build, CC should be set together with AR to the portage set
> > values.
> >
> > Doing this avoids situations like building the kernel with
> > clang (using the set HOSTCC) but using gcc/gnu-ar for headers.
> >
> > [1] a0d1c951ef08 kbuild: support LLVM=1 to switch the default tools to
> > Clang/LLVM
> >
> > Co-authored-by: Manoj Gupta <manojgupta@chromium.org>
> > Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
> > ---
> >  eclass/kernel-2.eclass | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
> > index adc1425bc2e..caeec86ff59 100644
> > --- a/eclass/kernel-2.eclass
> > +++ b/eclass/kernel-2.eclass
> > @@ -692,7 +692,7 @@ env_setup_xmakeopts() {
> >       elif type -p ${CHOST}-ar >/dev/null; then
> >               xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
> >       fi
> > -     xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)"
> > +     xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC) CC=$(tc-getCC)
> > AR=$(tc-getAR)" export xmakeopts
> >  }
>
> What's the reason for not using $LLVM here? To preserve building with
> clang
> for kernels < 5.7 ?
>
> I might be missing the point, but wouldn't something along the lines of
> "LLVM=$(! [[ $(tc-getCC) =~ clang ]]; echo $?)" work to preserve the
> correct
> compiler tools?
>
> This patch is about respecting the current CC value in portage. It could
be clang, icc, or something else
What should be the value of CC should be up to the user's portage config.

In Chrome OS e.g., we have multiple possible CC's with variants like
<abi>-clang. So hardcoding clang
also does not look correct.

Thanks,
Manoj


> Cheers

[-- Attachment #2: Type: text/html, Size: 2993 bytes --]

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

* Re: [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables
  2021-12-15 14:58 [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables Adrian Ratiu
  2021-12-15 21:36 ` James Beddek
@ 2021-12-16  0:32 ` Andrew Savchenko
  2021-12-16  0:37   ` Andrew Savchenko
  1 sibling, 1 reply; 8+ messages in thread
From: Andrew Savchenko @ 2021-12-16  0:32 UTC (permalink / raw)
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]

On Wed, 15 Dec 2021 16:58:26 +0200 Adrian Ratiu wrote:
> Starting with kernel>=v5.7 the build system can override the
> tools vars by setting LLVM=1 [1], but older kernels still use
> the default GNU tools, so to be able to use a full LLVM/Clang
> build, CC should be set together with AR to the portage set
> values.
> 
> Doing this avoids situations like building the kernel with
> clang (using the set HOSTCC) but using gcc/gnu-ar for headers.
> 
> [1] a0d1c951ef08 kbuild: support LLVM=1 to switch the default tools to Clang/LLVM
> 
> Co-authored-by: Manoj Gupta <manojgupta@chromium.org>
> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
> ---
>  eclass/kernel-2.eclass | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
> index adc1425bc2e..caeec86ff59 100644
> --- a/eclass/kernel-2.eclass
> +++ b/eclass/kernel-2.eclass
> @@ -692,7 +692,7 @@ env_setup_xmakeopts() {
>  	elif type -p ${CHOST}-ar >/dev/null; then
>  		xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
>  	fi
> -	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)"
> +	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC) CC=$(tc-getCC) AR=$(tc-getAR)"

OBJDUMP should be exported as well
(e.g. used by scripts/Makefile.build)

>  	export xmakeopts
>  }
>  


Best regards,
Andrew Savchenko

[-- Attachment #2: Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables
  2021-12-16  0:32 ` Andrew Savchenko
@ 2021-12-16  0:37   ` Andrew Savchenko
  2021-12-16 19:29     ` Adrian Ratiu
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Savchenko @ 2021-12-16  0:37 UTC (permalink / raw)
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1569 bytes --]

On Thu, 16 Dec 2021 03:32:10 +0300 Andrew Savchenko wrote:
> On Wed, 15 Dec 2021 16:58:26 +0200 Adrian Ratiu wrote:
> > Starting with kernel>=v5.7 the build system can override the
> > tools vars by setting LLVM=1 [1], but older kernels still use
> > the default GNU tools, so to be able to use a full LLVM/Clang
> > build, CC should be set together with AR to the portage set
> > values.
> > 
> > Doing this avoids situations like building the kernel with
> > clang (using the set HOSTCC) but using gcc/gnu-ar for headers.
> > 
> > [1] a0d1c951ef08 kbuild: support LLVM=1 to switch the default tools to Clang/LLVM
> > 
> > Co-authored-by: Manoj Gupta <manojgupta@chromium.org>
> > Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
> > ---
> >  eclass/kernel-2.eclass | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
> > index adc1425bc2e..caeec86ff59 100644
> > --- a/eclass/kernel-2.eclass
> > +++ b/eclass/kernel-2.eclass
> > @@ -692,7 +692,7 @@ env_setup_xmakeopts() {
> >  	elif type -p ${CHOST}-ar >/dev/null; then
> >  		xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
> >  	fi
> > -	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)"
> > +	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC) CC=$(tc-getCC) AR=$(tc-getAR)"
> 
> OBJDUMP should be exported as well
> (e.g. used by scripts/Makefile.build)

And LD as well.
 
> >  	export xmakeopts
> >  }
> >  
> 
> 
> Best regards,
> Andrew Savchenko


Best regards,
Andrew Savchenko

[-- Attachment #2: Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables
  2021-12-15 21:36 ` James Beddek
  2021-12-15 21:44   ` Manoj Gupta
@ 2021-12-16 19:25   ` Adrian Ratiu
  1 sibling, 0 replies; 8+ messages in thread
From: Adrian Ratiu @ 2021-12-16 19:25 UTC (permalink / raw)
  To: James Beddek, gentoo-dev; +Cc: Manoj Gupta

Hi James, thank you very much for your feedback!

On Wed, 15 Dec 2021, James Beddek <telans@posteo.de> wrote:
> On Thursday, 16 December 2021 3:58:26 AM NZDT Adrian Ratiu 
> wrote: 
>> Starting with kernel>=v5.7 the build system can override the 
>> tools vars by setting LLVM=1 [1], but older kernels still use 
>> the default GNU tools, so to be able to use a full LLVM/Clang 
>> build, CC should be set together with AR to the portage set 
>> values.   Doing this avoids situations like building the kernel 
>> with clang (using the set HOSTCC) but using gcc/gnu-ar for 
>> headers.   [1] a0d1c951ef08 kbuild: support LLVM=1 to switch 
>> the default tools to Clang/LLVM  Co-authored-by: Manoj Gupta 
>> <manojgupta@chromium.org> Signed-off-by: Adrian Ratiu 
>> <adrian.ratiu@collabora.com> --- 
>>  eclass/kernel-2.eclass | 2 +- 1 file changed, 1 insertion(+), 
>>  1 deletion(-) 
>>  diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass 
>> index adc1425bc2e..caeec86ff59 100644 --- 
>> a/eclass/kernel-2.eclass +++ b/eclass/kernel-2.eclass @@ -692,7 
>> +692,7 @@ env_setup_xmakeopts() { 
>>  	elif type -p ${CHOST}-ar >/dev/null; then 
>>  xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-" fi 
>> -	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)" + 
>> xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC) CC=$(tc-getCC) 
>> AR=$(tc-getAR)" export xmakeopts 
>>  } 
> 
> What's the reason for not using $LLVM here? To preserve building 
> with clang  for kernels < 5.7 ? 

That is correct - if Gentoo were to support only kernels >= 5.7 
then we could try to use $LLVM directly, but older long-term 
releases are still supported, the upstream kernel will backport 
patches to v4.14 until Jan 2024 and we would really like to build 
these with Clang too.

> 
> I might be missing the point, but wouldn't something along the 
> lines of "LLVM=$(! [[ $(tc-getCC) =~ clang ]]; echo $?)" work to 
> preserve the correct  compiler tools?

In theory Manoj's argument is correct: this is about respecting CC 
and the tools configuration in general so we should try to avoid 
hardcoding for clang if possible, but...

In practice I'm not aware of people building the kernel with 
something other than GNU or LLVM variants. At least these are the 
only two which receive "first class" support by the upstream 
kernel community.

In addition, hardcoding $LLVM does not fix the problem of older 
kernels.
 
I thought about backporting $LLVM support to long-term releases 
but I don't think it would be acceptable for inclusion in older 
kernels which should receive only bug fixes.

This is why I think the best solution is to just set the variables 
in this eclass to the values set by portage.

Thanks,
Adrian

>
> Cheers


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

* Re: [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables
  2021-12-16  0:37   ` Andrew Savchenko
@ 2021-12-16 19:29     ` Adrian Ratiu
  2021-12-16 23:13       ` James Beddek
  0 siblings, 1 reply; 8+ messages in thread
From: Adrian Ratiu @ 2021-12-16 19:29 UTC (permalink / raw)
  To: Andrew Savchenko, gentoo-dev

Hi Andrew,

On Thu, 16 Dec 2021, Andrew Savchenko <bircoph@gentoo.org> wrote:
> On Thu, 16 Dec 2021 03:32:10 +0300 Andrew Savchenko wrote: 
>> On Wed, 15 Dec 2021 16:58:26 +0200 Adrian Ratiu wrote: 
>> > Starting with kernel>=v5.7 the build system can override the 
>> > tools vars by setting LLVM=1 [1], but older kernels still use 
>> > the default GNU tools, so to be able to use a full LLVM/Clang 
>> > build, CC should be set together with AR to the portage set 
>> > values.   Doing this avoids situations like building the 
>> > kernel with clang (using the set HOSTCC) but using gcc/gnu-ar 
>> > for headers.   [1] a0d1c951ef08 kbuild: support LLVM=1 to 
>> > switch the default tools to Clang/LLVM  Co-authored-by: Manoj 
>> > Gupta <manojgupta@chromium.org> Signed-off-by: Adrian Ratiu 
>> > <adrian.ratiu@collabora.com> --- 
>> >  eclass/kernel-2.eclass | 2 +- 1 file changed, 1 
>> >  insertion(+), 1 deletion(-) 
>> >  diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass 
>> > index adc1425bc2e..caeec86ff59 100644 --- 
>> > a/eclass/kernel-2.eclass +++ b/eclass/kernel-2.eclass @@ 
>> > -692,7 +692,7 @@ env_setup_xmakeopts() { 
>> >  	elif type -p ${CHOST}-ar >/dev/null; then 
>> >  xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-" fi 
>> > -	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)" + 
>> > xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC) 
>> > CC=$(tc-getCC) AR=$(tc-getAR)" 
>>  OBJDUMP should be exported as well (e.g. used by 
>> scripts/Makefile.build) 
> 
> And LD as well. 
>   

Thank you very much for the suggestions!

I only set CC and AR because there were the two which failed in my 
testing, but yes, it is a good idea to be prudent and set them all 
if nobody is oopposed to it.

I will leave this patch on the ML a bit in case there is more 
feedback (it is also EoY season so people might be busy), then I 
will send a v3 with the new variables included.

Thanks again,
Adrian

>> >  	export xmakeopts
>> >  }
>> >  
>> 
>> 
>> Best regards,
>> Andrew Savchenko
>
>
> Best regards,
> Andrew Savchenko


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

* Re: [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables
  2021-12-16 19:29     ` Adrian Ratiu
@ 2021-12-16 23:13       ` James Beddek
  0 siblings, 0 replies; 8+ messages in thread
From: James Beddek @ 2021-12-16 23:13 UTC (permalink / raw)
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 2475 bytes --]

On Friday, 17 December 2021 8:29:18 AM NZDT Adrian Ratiu wrote:
> Hi Andrew,
> 
> On Thu, 16 Dec 2021, Andrew Savchenko <bircoph@gentoo.org> wrote:
> > On Thu, 16 Dec 2021 03:32:10 +0300 Andrew Savchenko wrote:
> >> On Wed, 15 Dec 2021 16:58:26 +0200 Adrian Ratiu wrote:
> >> > Starting with kernel>=v5.7 the build system can override the
> >> > tools vars by setting LLVM=1 [1], but older kernels still use
> >> > the default GNU tools, so to be able to use a full LLVM/Clang
> >> > build, CC should be set together with AR to the portage set
> >> > values.   Doing this avoids situations like building the
> >> > kernel with clang (using the set HOSTCC) but using gcc/gnu-ar
> >> > for headers.   [1] a0d1c951ef08 kbuild: support LLVM=1 to
> >> > switch the default tools to Clang/LLVM  Co-authored-by: Manoj
> >> > Gupta <manojgupta@chromium.org> Signed-off-by: Adrian Ratiu
> >> > <adrian.ratiu@collabora.com> ---
> >> > 
> >> >  eclass/kernel-2.eclass | 2 +- 1 file changed, 1
> >> >  insertion(+), 1 deletion(-)
> >> >  diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
> >> > 
> >> > index adc1425bc2e..caeec86ff59 100644 ---
> >> > a/eclass/kernel-2.eclass +++ b/eclass/kernel-2.eclass @@
> >> > -692,7 +692,7 @@ env_setup_xmakeopts() {
> >> > 
> >> >  	elif type -p ${CHOST}-ar >/dev/null; then
> >> >  
> >> >  xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-" fi
> >> > 
> >> > -	xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)" +
> >> > xmakeopts="${xmakeopts} HOSTCC=$(tc-getBUILD_CC)
> >> > CC=$(tc-getCC) AR=$(tc-getAR)"
> >>  
> >>  OBJDUMP should be exported as well (e.g. used by
> >> 
> >> scripts/Makefile.build)
> > 
> > And LD as well.
> 
> Thank you very much for the suggestions!
> 
> I only set CC and AR because there were the two which failed in my
> testing, but yes, it is a good idea to be prudent and set them all
> if nobody is oopposed to it.
> 

I assume by set them all you're referring to what the kernel makefile uses? I 
think CC, LD, AR, NM, OBJCOPY, OBJDUMP, READELF, and STRIP is the exhaustive 
list for the kernel. (would match the new clang profile feature too)

Thanks

> I will leave this patch on the ML a bit in case there is more
> feedback (it is also EoY season so people might be busy), then I
> will send a v3 with the new variables included.
> 
> Thanks again,
> Adrian
> 
> >> >  	export xmakeopts
> >> >  
> >> >  }
> >> 
> >> Best regards,
> >> Andrew Savchenko
> > 
> > Best regards,
> > Andrew Savchenko


[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2021-12-16 23:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15 14:58 [gentoo-dev] [PATCH v2] kernel-2.eclass: Respect portage CC & AR variables Adrian Ratiu
2021-12-15 21:36 ` James Beddek
2021-12-15 21:44   ` Manoj Gupta
2021-12-16 19:25   ` Adrian Ratiu
2021-12-16  0:32 ` Andrew Savchenko
2021-12-16  0:37   ` Andrew Savchenko
2021-12-16 19:29     ` Adrian Ratiu
2021-12-16 23:13       ` James Beddek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox