# genkernel-next with clang and gold

## Marlo

Hello!

I changed my system to clang and gold. It works well.

For the kernel I use genkernel-next and would like to use just as well. But Genkernel is used by default the gcc compiler.

In /etc/genkernel.conf there are  the options:

 *http://docs.huihoo.com/gentoo/resources/document-listing/genkernel.html wrote:*   

> 
> 
> Genkernel supports the following flags which are assigned to the relevant applications when your kernel is assembled:
> 
>     --kernel-as = someAssembler: This specifies to assembler which would be used for compiling your kernel.
> ...

 

But, what are the "specifies" flags? I could not find anything for clang and gold.

Thanks in advance for any help!

ma

-----

edit:  Bug 632227

----------

## duby2291

Last I heard clang is not yet capable of compiling the linux kernel. I'm not sure if that is still the case though. You might want to cd into /usr/src/linux and manually try building the kernel with it to see if it works now. I don't think it will.

----------

## Marlo

 *tux /usr/src/linux # make  && make modules_install wrote:*   

> 
> 
>  ......
> 
>   DATAREL arch/x86/boot/compressed/vmlinux
> ...

 

 make  && make modules_install works very well. But I can not see whether make uses the gcc or clang.

This is not important in principle either. I just wanted to know it.

Thanks for your reply.

Ma

----------

## duby2291

 *Marlo wrote:*   

>  *tux /usr/src/linux # make  && make modules_install wrote:*   
> 
>  ......
> 
>   DATAREL arch/x86/boot/compressed/vmlinux
> ...

 

I think you have to use the CC=clang environment variable set before make

https://wiki.gentoo.org/wiki/Clang#Clang_environments

----------

## Hu

 *duby2291 wrote:*   

> Last I heard clang is not yet capable of compiling the linux kernel. I'm not sure if that is still the case though.

 Very timely LWN piece: Building the kernel with clang.  In short, it can be done now for some useful configurations, but it's not possible for every configuration that gcc can handle.

----------

## Marlo

 *duby2291 wrote:*   

> 
> 
> I think you have to use the CC=clang environment variable set before make
> 
> https://wiki.gentoo.org/wiki/Clang#Clang_environments

 

I have set the system to use the global configuration via make.conf.

https://wiki.gentoo.org/wiki/Clang#Global_configuration_via_make.conf.

And if I set the variable CC = "clang" in addition, that works synonymous.

```

  CHK     include/config/kernel.release

  CHK     include/generated/uapi/linux/version.h

  CHK     include/generated/utsrelease.h

  CHK     include/generated/bounds.h

  CHK     include/generated/timeconst.h

  CHK     include/generated/asm-offsets.h

  CALL    scripts/checksyscalls.sh

  CHK     scripts/mod/devicetable-offsets.h

  CHK     include/generated/compile.h

  CHK     kernel/config_data.h

  LD      arch/x86/boot/compressed/vmlinux

  ZOFFSET arch/x86/boot/zoffset.h

  AS      arch/x86/boot/header.o

  LD      arch/x86/boot/setup.elf

  OBJCOPY arch/x86/boot/setup.bin

  OBJCOPY arch/x86/boot/vmlinux.bin

  BUILD   arch/x86/boot/bzImage

Setup is 15868 bytes (padded to 15872 bytes).

System is 12051 kB

CRC d9c40890

Kernel: arch/x86/boot/bzImage is ready  (#1)

  Building modules, stage 2.

  MODPOST 80 modules

```

 *Hu wrote:*   

> 
> 
> Very timely LWN piece: Building the kernel with clang. In short, it can be done now for some useful configurations, but it's not possible for every configuration that gcc can handle.
> 
> 

 

Thanks for this interesting link.

 *https://lwn.net/Articles/734071/ wrote:*   

> 
> 
> Hackmann related the state of the upstream kernel: "we are very close to having a kernel that can be built with Clang". It does require using a recent Clang that has some fixes, but the x86_64 and ARM64 kernels can be built, though each architecture has one out-of-tree patch that needs to be applied to do so.

 

I use the gentoo kernel 4.12.12 and I do not think that is already patched.

It seems that my configuration with clang works (maybe). But "make" and "genkernel-next" still switch to gcc.

Ma

----------

## duby2291

 *Marlo wrote:*   

>  *duby2291 wrote:*   
> 
> I think you have to use the CC=clang environment variable set before make
> 
> https://wiki.gentoo.org/wiki/Clang#Clang_environments 
> ...

 

Somebody can correct me if I'm wrong, but I don't think make actually reads portages make.conf. For years I've believed it is actually a mis-named configuration file. You have to actually set the environment variable on the command line before your make command. something like "CC=clang make bzImage modules && make modules_install install"

----------

## Hu

You are correct, and Marlo did show that, although the way it is presented as a code tag label can be missed if you do not look closely.  For make, but not for most programs, you can also set the variable as a program argument: make CC=clang targets.  This has slightly different semantics for processing a Makefile.  When a Makefile assigns a variable using the classic syntax VARIABLE = value, that overrides environment variables, but not command line arguments.  When it assigns using ?=, the environment variable takes precedence.

----------

## Marlo

Yes, thank you duby2291 and Hu.

You recorded the correct syntax.

It is not possible to compile the gentoo kernel with clang.

```

CC=clang
```

Sample: 

```
 

  CHK     include/config/kernel.release

  CHK     include/generated/uapi/linux/version.h

  CHK     include/generated/utsrelease.h

  CC      kernel/bounds.s

error: unable to load plugin './scripts/gcc-plugins/structleak_plugin.so': './scripts/gcc-plugins/structleak_plugin.so: undefined symbol: cfun'

make[1]: *** [Kbuild:21: kernel/bounds.s] Fehler 1

make: *** [Makefile:1064: prepare0] Fehler 2

```

Crosscheck:

```

 CHK     include/config/kernel.release

  CHK     include/generated/uapi/linux/version.h

  CHK     include/generated/utsrelease.h

  CC      kernel/bounds.s

  CHK     include/generated/bounds.h

  CHK     include/generated/timeconst.h

  CHK     include/generated/asm-offsets.h

  CALL    scripts/checksyscalls.sh

  CHK     scripts/mod/devicetable-offsets.h

  CHK     include/generated/compile.h

  CHK     kernel/config_data.h

  LD      arch/x86/boot/compressed/vmlinux

  ZOFFSET arch/x86/boot/zoffset.h

  AS      arch/x86/boot/header.o

  LD      arch/x86/boot/setup.elf

  OBJCOPY arch/x86/boot/setup.bin

  OBJCOPY arch/x86/boot/vmlinux.bin

  BUILD   arch/x86/boot/bzImage

Setup is 15868 bytes (padded to 15872 bytes).

System is 12051 kB

CRC d9c40890
```

Thank you very much for your comments and help.

Ma

[Moderator edit: changed [quote] tags to [code] tags to preserve output layout. -Hu]

----------

