Skip to contentSkip to conversation

error: 'const_pcpu_hot' causes a section type conflict with 'pcpu_hot' when compiling with -flto

DISCUSSION Bagas Sanjaya 3 participants 3 messages Aug 3, 2024 – Aug 7, 2024

lore
Share & tools
lore
#0 lore raw

Hi,

mrwizardwizard <[email protected]> reported kernel FTBFS on bugzilla
(https://bugzilla.kernel.org/show_bug.cgi?id=219099) when the kernel is built with LTO:

Quoted 8 lines

Hello,

when compiling linux kernel 6.9-6.10 with -flto

compiler outputs:

./arch/x86/include/asm/current.h:42:25: error: 'const_pcpu_hot' causes a section type conflict with 'pcpu_hot' const_pcpu_hot);

He could reproduce the build error on mainline:

Quoted 71 lines
Quoted 1 line

Can you reproduce above on current mainline (v6.11-rc1)?

same messages

mkdir -p /home/mrwizardwizard/Documents/Kernel/linux-6.11-rc1/tools/objtool && make O=/home/mrwizardwizard/Documents/Kernel/linux-6.11-rc1 subdir=tools/objtool --no-print-directory -C objtool
INSTALL libsubcmd_headers

  CALL    scripts/checksyscalls.sh
  CC      init/main.o
  AS      arch/x86/entry/entry.o
  AS      arch/x86/entry/entry_64.o
arch/x86/entry/entry_64.o: warning: objtool: __switch_to_asm+0x18: stack layout conflict in alternatives: .altinstr_replacement+0x1d
  CC      arch/x86/entry/syscall_64.o
In file included from ./include/asm-generic/percpu.h:7,
                 from ./arch/x86/include/asm/percpu.h:616,
                 from ./arch/x86/include/asm/current.h:11,
                 from ./arch/x86/include/asm/processor.h:17,
                 from ./arch/x86/include/asm/timex.h:5,
                 from ./include/linux/timex.h:67,
                 from ./include/linux/time32.h:13,
                 from ./include/linux/time.h:60,
                 from ./include/linux/stat.h:19,
                 from ./include/linux/module.h:13,
                 from init/main.c:17:
./arch/x86/include/asm/current.h:42:25: error: 'const_pcpu_hot' causes a section type conflict with 'pcpu_hot'
   42 |                         const_pcpu_hot);
      |                         ^~~~~~~~~~~~~~

./arch/x86/include/asm/current.h:38:42: note: 'pcpu_hot' was declared here
38 | DECLARE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot);
| ^~~~~~~~
make[3]: *** [scripts/Makefile.build:244: init/main.o] Error 1 make[2]: *** [scripts/Makefile.build:485: init] Error 2 make[2]: *** Waiting for unfinished jobs....

  CC      arch/x86/entry/common.o
  CC      arch/x86/events/core.o
  CC      arch/x86/entry/vdso/vma.o
In file included from ./include/asm-generic/percpu.h:7,
                 from ./arch/x86/include/asm/percpu.h:616,
                 from ./arch/x86/include/asm/current.h:11,
                 from ./include/linux/sched.h:12,
                 from ./include/linux/ptrace.h:6,
                 from ./include/uapi/asm-generic/bpf_perf_event.h:4,
                 from ./arch/x86/include/generated/uapi/asm/bpf_perf_event.h:1,
                 from ./include/uapi/linux/bpf_perf_event.h:11,
                 from ./include/linux/perf_event.h:18,
                 from arch/x86/events/core.c:15:
./arch/x86/include/asm/current.h:42:25: error: 'const_pcpu_hot' causes a section type conflict with 'pcpu_hot'
   42 |                         const_pcpu_hot);
      |                         ^~~~~~~~~~~~~~

./arch/x86/include/asm/current.h:38:42: note: 'pcpu_hot' was declared here
38 | DECLARE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot);
| ^~~~~~~~
make[4]: *** [scripts/Makefile.build:244: arch/x86/events/core.o] Error 1 make[3]: *** [scripts/Makefile.build:485: arch/x86/events] Error 2 make[3]: *** Waiting for unfinished jobs....

  AR      arch/x86/entry/vsyscall/built-in.a
  CC      arch/x86/entry/vdso/extable.o
  LDS     arch/x86/entry/vdso/vdso.lds
  AS      arch/x86/entry/vdso/vdso-note.o
  CC      arch/x86/entry/vdso/vclock_gettime.o
  CC      arch/x86/entry/vdso/vgetcpu.o
  CC      arch/x86/entry/vdso/vgetrandom.o
  AS      arch/x86/entry/vdso/vgetrandom-chacha.o
  HOSTCC  arch/x86/entry/vdso/vdso2c
  VDSO    arch/x86/entry/vdso/vdso64.so.dbg
  OBJCOPY arch/x86/entry/vdso/vdso64.so
  VDSO2C  arch/x86/entry/vdso/vdso-image-64.c
  CC      arch/x86/entry/vdso/vdso-image-64.o
  AR      arch/x86/entry/vdso/built-in.a
  AS      arch/x86/entry/thunk.o
  AR      arch/x86/entry/built-in.a
Quoted 3 lines

make[2]: *** [scripts/Makefile.build:485: arch/x86] Error 2
make[1]: *** [/home/mrwizardwizard/Documents/Kernel/linux-6.11-rc1/Makefile:1927: .] Error 2
make: *** [Makefile:224: __sub-make] Error

For the full build log, see Bugzilla link.

Thanks.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#1 lore raw
Quoted 7 lines · Bagas Sanjaya
Quoted 5 lines

when compiling linux kernel 6.9-6.10 with -flto

compiler outputs:

./arch/x86/include/asm/current.h:42:25: error: 'const_pcpu_hot' causes a section type conflict with 'pcpu_hot' const_pcpu_hot);

He could reproduce the build error on mainline:

That's caused by:

ed2f752e0e0a ("x86/percpu: Introduce const-qualified const_pcpu_hot to micro-optimize code generation")

Uros?

Thanks,

tglx

#2 lore raw
Quoted 8 lines · Thomas Gleixner
Quoted 6 lines · Bagas Sanjaya
Quoted 5 lines

when compiling linux kernel 6.9-6.10 with -flto

compiler outputs:

./arch/x86/include/asm/current.h:42:25: error: 'const_pcpu_hot' causes a section type conflict with 'pcpu_hot' const_pcpu_hot);

Quoted 7 lines
Quoted 1 line

He could reproduce the build error on mainline:

That's caused by:

ed2f752e0e0a ("x86/percpu: Introduce const-qualified const_pcpu_hot to micro-optimize code generation")

Uros?

I have taken the discussion to the bugreport, where the potential patch is also posted.

For reference, my answer is as follows:

--cut here--
(In reply to mrwizardwizard from comment #0)

Quoted 1 line

when compiling linux kernel 6.9-6.10 with -flto

You need a whole lot more patches to successfully compile kernel with GCC LTO. The last revision can be found at:

https://lore.kernel.org/lkml/[email protected]/

The patchset defines CONFIG_LTO, which can be used to disable offending optimization, something like the to-be attached patch.

Ideally, a LTO-compatible "const __seg_gs" qualified alias to struct pcpu_hot should be declared, so LTO can retain the disabled optimization, but ...

... the LTO patchset was rejected mainly due to:
- the performance is the same
- the resulting image is bigger
- we need a whole lot of ugly hacks to placate the linker. --cut here--

Thanks,
Uros.