Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Does genkernel compile with make.conf CFLAGS?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
EliasJonsson
n00b
n00b


Joined: 18 Oct 2017
Posts: 53

PostPosted: Mon Apr 03, 2023 4:29 am    Post subject: Does genkernel compile with make.conf CFLAGS? Reply with quote

Hello Gentoo Community,
when using genkernel, is the kernel compiled using the custom cflags in the /etc/portage/make.conf when the
Code:
genkernel all
is executed?

Last edited by EliasJonsson on Mon Apr 03, 2023 3:16 pm; edited 2 times in total
Back to top
View user's profile Send private message
EliasJonsson
n00b
n00b


Joined: 18 Oct 2017
Posts: 53

PostPosted: Mon Apr 03, 2023 5:40 am    Post subject: Reply with quote

found the solution elsewhere:
Code:
nano /etc/genkernel.conf

And add the line:
Code:

KERNEL_CFLAGS="-O2 -march=native -pipe -fomit-frame-pointer"

Then go to linux source folder and issue the command:
Code:

genkernel all


Verify CFLAGS using
Code:

nano /var/log/genkernel.log


look for the entry
genkernel.log wrote:
* KERNEL_CFLAGS

My entry was:
genkernel.log wrote:

* KERNEL_CFLAGS set in config file to "-O2 -march=native -pipe -fomit-frame-pointer"


Last edited by EliasJonsson on Mon Apr 03, 2023 2:58 pm; edited 4 times in total
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2699

PostPosted: Mon Apr 03, 2023 6:04 am    Post subject: Reply with quote

I think it depends on your kernel config.

Best Regards,
Georgi
Back to top
View user's profile Send private message
Gladdle
Guru
Guru


Joined: 27 Jul 2008
Posts: 313
Location: Cleebronn, Germany

PostPosted: Mon Apr 03, 2023 8:13 am    Post subject: Reply with quote

May i quote from the file /etc/genkernel.conf:
Code:
# Genkernel uses an independent configuration for MAKEOPTS, and does not source
# /etc/portage/make.conf . You can override the default setting by uncommenting
# and tweaking the following line. Default setting is set up by
# ${GK_SHARE}/${ARCH_OVERRIDE}/config.sh . The recommended value for -j
# argument is: <number of processors>*<number of cores per processor>+1
#MAKEOPTS="$(portageq envvar MAKEOPTS)"
Back to top
View user's profile Send private message
EliasJonsson
n00b
n00b


Joined: 18 Oct 2017
Posts: 53

PostPosted: Mon Apr 03, 2023 3:21 pm    Post subject: Reply with quote

Gladdle wrote:
May i quote from the file /etc/genkernel.conf:
Code:
# Genkernel uses an independent configuration for MAKEOPTS, and does not source
# /etc/portage/make.conf . You can override the default setting by uncommenting
# and tweaking the following line. Default setting is set up by
# ${GK_SHARE}/${ARCH_OVERRIDE}/config.sh . The recommended value for -j
# argument is: <number of processors>*<number of cores per processor>+1
#MAKEOPTS="$(portageq envvar MAKEOPTS)"


Does that mean that CFLAGS can be gotten from make.conf?

I followed my own steps on how to make the kernel take custom CFLAGS, but the resulting binary was exactly the same as the un-optimized. What do you think, were the CFLAGS not applied to the kernel compilation process properly since the resulting binary size were exactly the same as the old one?
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23100

PostPosted: Mon Apr 03, 2023 4:56 pm    Post subject: Reply with quote

Assuming that the shown commented example means that shell indirections are legal here, then yes, I expect you could make it look up the CFLAGS configured for Portage.

Matching size is suspicious, but not definitive. What command line did make use to run gcc on the kernel source? What did you do that you expected to influence the kernel's build?
Back to top
View user's profile Send private message
EliasJonsson
n00b
n00b


Joined: 18 Oct 2017
Posts: 53

PostPosted: Tue Apr 04, 2023 2:07 am    Post subject: Reply with quote

Hu wrote:

Matching size is suspicious, but not definitive. What command line did make use to run gcc on the kernel source? What did you do that you expected to influence the kernel's build?


See post #2 in this thread, I think that post answer your questions.

To get to the bottom with the similarities of the old, unoptimized kernel, I calculated the md5sum of the contents of the two kernels.
Code:
lee /boot # md5sum vmlinuz-6.1.19-gentoo-x86_64
eb33224e0a715b8fb78a25047f0572ed  vmlinuz-6.1.19-gentoo-x86_64
lee /boot # md5sum vmlinuz-6.1.19-gentoo-x86_64.old
54e162e35f0e8772be3c013f454e67cb  vmlinuz-6.1.19-gentoo-x86_64.old
lee /boot # du -b vmlinuz-6.1.19-gentoo-x86_64
10238784   vmlinuz-6.1.19-gentoo-x86_64
lee /boot # du -b vmlinuz-6.1.19-gentoo-x86_64.old
10238784   vmlinuz-6.1.19-gentoo-x86_64.old
lee /boot #


Is there a way of how to test what kernel CFLAGS were actually used to create the kernel binary and its modules?
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23100

PostPosted: Tue Apr 04, 2023 2:52 pm    Post subject: Reply with quote

That post does not show the output of make as it invoked gcc. That post assumes use of genkernel. It's not clear from your most recent posts if you built the kernel by hand or if you let genkernel do it.

Additionally, to your repeated question, the definitive answer for knowing what flags were used is to see the full command that make ran, which will show the flags if they were used. You might be able to derive the answer from the contents of the kernel's generated dependency files (*.cmd files).
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1806
Location: South America

PostPosted: Tue Apr 04, 2023 5:12 pm    Post subject: Reply with quote

For a manual build of the kernel, make V=1 makefile_target will show the full compiler invocations, including compiler options used. I don't know how to do it when Genkernel is used to build the kernel, though.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
sublogic
Guru
Guru


Joined: 21 Mar 2022
Posts: 310
Location: Pennsylvania, USA

PostPosted: Tue Apr 04, 2023 10:19 pm    Post subject: Reply with quote

GDH-gentoo wrote:
For a manual build of the kernel, make V=1 makefile_target will show the full compiler invocations, including compiler options used. I don't know how to do it when Genkernel is used to build the kernel, though.

I would suggest MAKEOPTS="V=1" in /etc/genkernel.conf. Not tested though.
Back to top
View user's profile Send private message
EliasJonsson
n00b
n00b


Joined: 18 Oct 2017
Posts: 53

PostPosted: Wed Apr 05, 2023 3:17 am    Post subject: Reply with quote

sublogic wrote:
GDH-gentoo wrote:
For a manual build of the kernel, make V=1 makefile_target will show the full compiler invocations, including compiler options used. I don't know how to do it when Genkernel is used to build the kernel, though.

I would suggest MAKEOPTS="V=1" in /etc/genkernel.conf. Not tested though.


Added
Code:
KERNEL_CFLAGS="-O2 -march=native -pipe -fomit-frame-pointer"

and
Code:
MAKEOPTS="-j5 V=1"

to /etc/genkernel.conf
went to /usr/src/linux/ and issued the command
Code:
genkernel --zfs all

while I looked at the, now V=1erbose output in
Code:
less +F /var/log/genkernel.log


there was no `-march` in that file except for genkernel telling me that the KERNEL_CLFLAGS had been set. I can only conclude that adding the KERNEL_CFLAGS was ineffective.


Last edited by EliasJonsson on Wed Apr 05, 2023 3:43 am; edited 1 time in total
Back to top
View user's profile Send private message
EliasJonsson
n00b
n00b


Joined: 18 Oct 2017
Posts: 53

PostPosted: Wed Apr 05, 2023 3:20 am    Post subject: Reply with quote

Hu wrote:
That post does not show the output of make as it invoked gcc. That post assumes use of genkernel. It's not clear from your most recent posts if you built the kernel by hand or if you let genkernel do it.

I built the kernel using
Code:
genkernel all

Hu wrote:

You might be able to derive the answer from the contents of the kernel's generated dependency files (*.cmd files).


I would love the learn how to do that :D
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2699

PostPosted: Wed Apr 05, 2023 8:23 am    Post subject: Reply with quote

Once again, I think the kernel CFLAGS are defined by what processor family is selected in your kernel config. If it was for genkernel to determine that you could, well at least attempt to, compile a kernel for one architecture with cflags for another.

Not to mention this optimization is of little to no benefit. Better emerge gentoo-sources with experimental use flag enabled which will apply patches allowing you to select exactly what CPU you have in the kernel config.

Best Regards,
Georgi
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23100

PostPosted: Wed Apr 05, 2023 11:54 am    Post subject: Reply with quote

EliasJonsson wrote:
Hu wrote:
You might be able to derive the answer from the contents of the kernel's generated dependency files (*.cmd files).
I would love the learn how to do that :D
The files are plain text, in a format suitable for inclusion in GNU make, so cat /path/to/.cmd-file should work. You should find these files in your $KBUILD_OUTPUT directory (default for basic kernel build: .; default for genkernel: unknown). find "${KBUILD_OUTPUT:-.}" -name '*.cmd' should work to find them, if run from the kernel build directory.
logrusx wrote:
I think the kernel CFLAGS are defined by what processor family is selected in your kernel config.
That can also pick CFLAGS for you, yes. However, most build systems, including the kernel build system, also allow the user to pass arbitrary additional flags. These flags can help or hurt, but it is the user's choice to use them.

The kernel should automatically enable compiler optimizations and frame pointer omission, so I think the only option that OP is requesting that is not redundant is -march=native.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum