You are not logged in.

#1 2021-10-23 15:45:22

ihitmani
Member
Registered: 2021-05-03
Posts: 63

[SOLVED] How to compile custom kernel with specific CFLAGS ?

hi, where to set flags in order to compile custom kernel, previously I thought I should modify /etc/makepkg.conf, but as https://bbs.archlinux.org/viewtopic.php … 6#p1998356 said, it is wrong. Just wondering why is it no logical that package get compiled with different flags then here : etc/makepkg.conf. It is wrong, linux is just a package, as described here : https://wiki.archlinux.org/title/Kernel … ild_System.

Last edited by ihitmani (2021-10-24 20:11:42)

Offline

#2 2021-10-23 15:56:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] How to compile custom kernel with specific CFLAGS ?

ihitmani wrote:

hi, where to set flags in order to compile custom kernel, previously I thought I should modify /etc/makepkg.conf, but as https://bbs.archlinux.org/viewtopic.php … 6#p1998356 said, it is wrong.

Nothing in that thread indicates this.  If you are building a kernel package with makepkg, then makepkg.conf ig is a good place for this setting - especially if this is a general CFLAGS you want to use for all packages you build.  You could, of course, also export it from the build function of the PKGBUILD.

If you are not using makepkg, then obviously makepkg.conf is not relevant, and you'd just export the flags from the build environment.

But what CFLAGS do you want to add to build a kernel?  And why?

EDIT: and that is your thread?  Why are you abandoning it just to start a new thread for what seems to be the same question?

Last edited by Trilby (2021-10-23 15:58:58)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2021-10-23 16:07:40

ihitmani
Member
Registered: 2021-05-03
Posts: 63

Re: [SOLVED] How to compile custom kernel with specific CFLAGS ?

Trilby wrote:
ihitmani wrote:

hi, where to set flags in order to compile custom kernel, previously I thought I should modify /etc/makepkg.conf, but as https://bbs.archlinux.org/viewtopic.php … 6#p1998356 said, it is wrong.

Nothing in that thread indicates this.  If you are building a kernel package with makepkg, then makepkg.conf ig is a good place for this setting - especially if this is a general CFLAGS you want to use for all packages you build.  You could, of course, also export it from the build function of the PKGBUILD.

If you are not using makepkg, then obviously makepkg.conf is not relevant, and you'd just export the flags from the build environment.

But what CFLAGS do you want to add to build a kernel?  And why?

EDIT: and that is your thread?  Why are you abandoning it just to start a new thread for what seems to be the same question?

First of all it is different question, thats why I started new thread. Second I am confused, because person from mentioned thread says:"The compiler flags will not be used for the kernel build,  only for building host tooling." that makepkg will not use flags from  /etc/makepkg.conf because this is kernel. I am confused, please provide more details why that person says that ?

I want to add next flags :

CFLAGS="-march=native -O2 -pipe -fno-plt -fomit-frame-pointer"

CXXFLAGS="-march=native -O2 -pipe -fno-plt -fomit-frame-pointer"

Last edited by ihitmani (2021-10-23 16:09:57)

Offline

#4 2021-10-23 16:50:34

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: [SOLVED] How to compile custom kernel with specific CFLAGS ?

The kernel uses its own flags.  You need to patch the kernel source.  https://github.com/graysky2/kernel_compiler_patch


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2021-10-23 20:16:17

loqs
Member
Registered: 2014-03-06
Posts: 17,192

Re: [SOLVED] How to compile custom kernel with specific CFLAGS ?

march is controlled by the choice in arch/x86/Kconfig.cpu
optimization level is controlled by CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE/CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3/CONFIG_CC_OPTIMIZE_FOR_SIZE
frame pointer use is controlled by CONFIG_FRAME_POINTER
stack protector is controlled by CONFIG_STACK_PROTECTOR CONFIG_STACKPROTECTOR_STRONG
fcf-protection is disabled in the kernel as the kernel does not support its use either in kernel space or user space.

Does PLT apply to the kernel?  That is a property of ELF binaries not sure if the kernel uses it.

Last edited by loqs (2021-10-23 23:12:24)

Offline

#6 2021-10-24 01:37:39

Sinistar
Member
Registered: 2021-01-02
Posts: 11

Re: [SOLVED] How to compile custom kernel with specific CFLAGS ?

CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 has a "depends on ARC", so you will have to patch "init/Kconfig" to have the option work.
The Kernel defaults to O2.

Last edited by Sinistar (2021-10-24 01:41:59)

Offline

Board footer

Powered by FluxBB