Compiling linux with `clang -fbasic-block-sections=labels`

Hi,
I’m trying to build the linux kernel with clang -fbasic-block-sections=labels.

I ran into this error:

/tmp/main-81886d.s: Assembler messages:
/tmp/main-81886d.s: Error: .size expression for .BB.set_reset_devices does not evaluate to a constant
/tmp/main-81886d.s: Error: .size expression for .BB.debug_kernel does not evaluate to a constant
/tmp/main-81886d.s: Error: .size expression for .BB.quiet_kernel does not evaluate to a constant
/tmp/main-81886d.s: Error: .size expression for .BB.loglevel does not evaluate to a constant

make kernelversion
5.10.0

clang version 11.1.0 (g...@github.com:llvm/llvm-project.git 1fdec59bffc11ae37eb51a1b9869f0696bfd5312)
Target: x86_64-unknown-linux-gnu

  1. Can someone help me understand what this error means?
  2. Is clang-built-linux a better place to ask this question?
  3. Is there a workaround for this?

Thanks
Akshith

BB sections has only been tested/implemented with a fairly narrow set of flags so far as I know, and is sufficiently novel that various features won’t interact correctly with it without some work to support the combination of bb sections and those features.

I’d /guess/ BPF, for instance, probably doesn’t work with BB sections out of the box & may require some work (like some work was needed to support BB sections with DWARF) - I believe BPF is mandatory/used by default when building the Linux kernel? So maybe that’s what’s being tripped over here. But could something else entirely - that’s just my first guess.

BB sections has only been tested/implemented with a fairly narrow set of flags so far as I know, and is sufficiently novel that various features won’t interact correctly with it without some work to support the combination of bb sections and those features.

I’d /guess/ BPF, for instance, probably doesn’t work with BB sections out of the box & may require some work (like some work was needed to support BB sections with DWARF) - I believe BPF is mandatory/used by default when building the Linux kernel? So maybe that’s what’s being tripped over here. But could something else entirely - that’s just my first guess.

Right, we have not tried to build the linux kernel with these flags but it is something we would like to test and fix.

Hi,
I’m trying to build the linux kernel with clang -fbasic-block-sections=labels.

Labels does not actually generate sections and it must be a simpler step as it only adds metadata to the binary.

I ran into this error:

/tmp/main-81886d.s: Assembler messages:
/tmp/main-81886d.s: Error: .size expression for .BB.set_reset_devices does not evaluate to a constant
/tmp/main-81886d.s: Error: .size expression for .BB.debug_kernel does not evaluate to a constant
/tmp/main-81886d.s: Error: .size expression for .BB.quiet_kernel does not evaluate to a constant
/tmp/main-81886d.s: Error: .size expression for .BB.loglevel does not evaluate to a constant

Would you be able to give us a smaller repro for this, we can take a look. Basic block labels uses size expressions when generating metadata and it looks like we are not doing this right under some circumstances.

Hi,

Here is a public gist with the repro steps: https://gist.github.com/akshithg/e5a58fc7012a65e6ec2e94794d66569f

It should have 1) the config i’m using 2) the toolchain version 3) build steps

Feel free to shoot more questions if you need more details :slight_smile:

Hi,

Here is a public gist with the repro steps: https://gist.github.com/akshithg/e5a58fc7012a65e6ec2e94794d66569f

It should have 1) the config i’m using 2) the toolchain version 3) build steps

Feel free to shoot more questions if you need more details :slight_smile:

Thanks, in the interests of simplifying this further, would it be possible to give me the preprocessed source and the failing command?

Hi,

Here is a public gist with the repro steps: https://gist.github.com/akshithg/e5a58fc7012a65e6ec2e94794d66569f

It should have 1) the config i’m using 2) the toolchain version 3) build steps

Feel free to shoot more questions if you need more details :slight_smile:

Thanks, in the interests of simplifying this further, would it be possible to give me the preprocessed source and the failing command?

Here you go: https://gist.github.com/akshithg/e5a58fc7012a65e6ec2e94794d66569f#gistcomment-3773366
Thanks for your time and effort :slight_smile: