Skip to content

gcc-LTO support for the kernel

Jiri Slaby (SUSE) bpf linux-kbuild linux-mm live-patching lkml xen-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest46 patches 40 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/46x86/boot: robustify calling startup_{32,64}() from the decompressor codearch/x86/boot/compressed/head_32.S arch/x86/boot/compressed/head_64.S arch/x86/boot/compressed/misc.c+12 -80 replies
2/46kbuild: pass jobserver to cmd_ld_vmlinux.oscripts/Makefile.vmlinux_o+1 -12 replies
3/46kbuild: lto: preserve MAKEFLAGS for module linkingscripts/Makefile.build+2 -21 reply
4/46compiler.h: introduce __visible_on_ltoinclude/linux/compiler.h+6 -00 replies
5/46compiler.h: introduce __global_on_ltoinclude/linux/compiler.h+2 -00 replies
6/46Compiler Attributes, lto: introduce __noreorderinclude/linux/compiler_attributes.h+10 -00 replies
7/46tracepoint, lto: Mark static call functions as __visibleinclude/linux/tracepoint.h+2 -20 replies
8/46static_call, lto: Mark static keys as __visibleinclude/linux/static_call.h+6 -65 replies
9/46static_call, lto: Mark static_call_return0() as __visiblekernel/static_call.c+1 -10 replies
10/46static_call, lto: Mark func_a() as __visible_on_ltokernel/static_call_inline.c+3 -32 replies
11/46x86/alternative, lto: Mark int3_*() as global and __visiblearch/x86/kernel/alternative.c+3 -20 replies
12/46x86/paravirt, lto: Mark native_steal_clock() as __visible_on_ltoarch/x86/kernel/paravirt.c+1 -11 reply
13/46x86/preempt, lto: Mark preempt_schedule_*thunk() as __visiblearch/x86/include/asm/preempt.h+2 -20 replies
14/46x86/sev, lto: Mark cpuid_table_copy as __visible_on_ltoarch/x86/kernel/sev-shared.c+1 -11 reply
15/46x86/xen, lto: Mark xen_vcpu_stolen() as __visibledrivers/xen/time.c+1 -10 replies
16/46x86, lto: Mark gdt_page and native_sched_clock() as __visiblearch/x86/kernel/cpu/common.c arch/x86/kernel/tsc.c+2 -20 replies
17/46amd, lto: Mark amd pmu and pstate functions as __visible_on_ltoarch/x86/events/amd/core.c drivers/cpufreq/amd-pstate.c+9 -80 replies
18/46entry, lto: Mark raw_irqentry_exit_cond_resched() as __visiblekernel/entry/common.c+1 -17 replies
19/46export, lto: Mark __kstrtab* in EXPORT_SYMBOL() as global and __visibleinclude/linux/export.h+4 -20 replies
20/46softirq, lto: Mark irq_enter/exit_rcu() as __visiblekernel/softirq.c+2 -20 replies
21/46btf, lto: pass scope as stringsinclude/linux/btf_ids.h+11 -110 replies
22/46btf, lto: Make all BTF IDs global on LTOinclude/linux/btf_ids.h+6 -60 replies
23/46init.h, lto: mark initcalls as __noreorderinclude/linux/init.h+1 -10 replies
24/46bpf, lto: mark interpreter jump table as __noreorderkernel/bpf/core.c+1 -10 replies
25/46sched, lto: mark sched classes as __noreorderkernel/sched/sched.h+1 -00 replies
26/46x86/apic, lto: Mark apic_driver*() as __noreorderarch/x86/include/asm/apic.h+2 -20 replies
27/46linkage, lto: use C version for SYSCALL_ALIAS() / cond_syscall()include/linux/linkage.h kernel/time/posix-stubs.c+25 -100 replies
28/46scripts, lto: re-add gcc-ldscripts/gcc-ld+40 -00 replies
29/46scripts, lto: use CONFIG_LTO for many LTO specific actionsMakefile include/asm-generic/vmlinux.lds.h kernel/kallsyms.c +4 more+7 -70 replies
30/46Kbuild, lto: Add Link Time Optimization supportDocumentation/kbuild/index.rst Documentation/kbuild/lto-build.rst Makefile +7 more+190 -122 replies
31/46x86/purgatory, lto: Disable gcc LTO for purgatoryarch/x86/purgatory/Makefile+2 -00 replies
32/46x86/realmode, lto: Disable gcc LTO for real mode codearch/x86/realmode/Makefile+1 -00 replies
33/46x86/vdso, lto: Disable gcc LTO for the vdsoarch/x86/entry/vdso/Makefile+2 -00 replies
34/46scripts, lto: disable gcc LTO for some mod sourcesscripts/mod/Makefile+3 -00 replies
35/46Kbuild, lto: disable gcc LTO for bounds+asm-offsetsKbuild+3 -00 replies
36/46lib/string, lto: disable gcc LTO for string.olib/Makefile+2 -00 replies
37/46Compiler attributes, lto: disable __flatten with LTOinclude/linux/compiler_attributes.h+5 -01 reply
38/46Kbuild, lto: don't include weak source file symbols in System.mapscripts/mksysmap+2 -00 replies
39/46x86, lto: Disable relative init pointers with gcc LTOarch/x86/Kconfig+3 -10 replies
40/46x86/livepatch, lto: Disable live patching with gcc LTOkernel/livepatch/Kconfig+1 -05 replies
41/46x86/lib, lto: Mark 32bit mem{cpy,move,set} as __usedarch/x86/lib/memcpy_32.c+3 -30 replies
42/46mm/kasan, lto: Mark kasan mem{cpy,move,set} as __usedmm/kasan/shadow.c+3 -30 replies
43/46scripts, lto: check C symbols for modversionsscripts/Makefile.build+1 -10 replies
44/46scripts/bloat-o-meter, lto: handle gcc LTOscripts/bloat-o-meter+1 -10 replies
45/46kasan, lto: remove extra BUILD_BUG() in memory_is_poisonedmm/kasan/generic.c+1 -11 reply
46/46x86, lto: Finally enable gcc LTO for x86arch/x86/Kconfig+1 -00 replies

Reviews trailers per patch

2 of 46 patches have a Reviewed-by or Acked-by.

PatchJiri SlabyAndrey Konovalov
1/46T-b R-b
2/46
3/46
4/46
5/46
6/46
7/46
8/46
9/46
10/46
11/46
12/46
13/46
14/46
15/46
16/46
17/46
18/46
19/46
20/46
21/46
22/46
23/46
24/46
25/46
26/46
27/46
28/46
29/46
30/46
31/46
32/46
33/46
34/46
35/46
36/46
37/46
38/46
39/46
40/46
41/46
42/46
43/46
44/46
45/46R-b
46/46

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 00/46] gcc-LTO support for the kernel

Hi,

this is the first call for comments (and kbuild complaints) for this support of gcc (full) LTO in the kernel. Most of the patches come from Andi. Me and Martin rebased them to new kernels and fixed the to-use known issues. Also I updated most of the commit logs and reordered the patches to groups of patches with similar intent.

The very first patch comes from Alexander and is pending on some x86 queue already (I believe). I am attaching it only for completeness. Without that, the kernel does not boot (LTO reorders a lot).

In our measurements, the performance differences are negligible.

The kernel is bigger with gcc LTO due to more inlining. The next step might be to play with non-static functions as we export everything, so the compiler cannot actually drop anything (esp. inlined and no longer needed functions).

Cc Alexander Potapenko <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Alexey Makhalov <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Andrey Konovalov <[email protected]>
Cc Andrey Ryabinin <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Ben Segall <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Daniel Bristot de Oliveira <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Don Zickus <[email protected]>
Cc Hao Luo <[email protected]>
Cc H.J. Lu <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Huang Rui <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jan Hubicka <[email protected]>
Cc Jason Baron <[email protected]>
Cc Jiri Kosina <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Joe Lawrence <[email protected]>
Cc John Fastabend <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Juri Lelli <[email protected]>
Cc KP Singh <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Martin Liska <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Michal Marek <[email protected]>
Cc Miroslav Benes <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Oleksandr Tyshchenko <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Petr Mladek <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Richard Biener <[email protected]>
Cc Sedat Dilek <[email protected]>
Cc Song Liu <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Vincenzo Frascino <[email protected]>
Cc Viresh Kumar <[email protected]>
Cc VMware PV-Drivers Reviewers <[email protected]>
Cc Yonghong Song <[email protected]>

Alexander Lobakin (1):
x86/boot: robustify calling startup_{32,64}() from the decompressor
code

Andi Kleen (36):
Compiler Attributes, lto: introduce __noreorder tracepoint, lto: Mark static call functions as __visible static_call, lto: Mark static keys as __visible static_call, lto: Mark static_call_return0() as __visible static_call, lto: Mark func_a() as __visible_on_lto x86/alternative, lto: Mark int3_*() as global and __visible x86/paravirt, lto: Mark native_steal_clock() as __visible_on_lto x86/preempt, lto: Mark preempt_schedule_*thunk() as __visible x86/xen, lto: Mark xen_vcpu_stolen() as __visible
x86, lto: Mark gdt_page and native_sched_clock() as __visible amd, lto: Mark amd pmu and pstate functions as __visible_on_lto entry, lto: Mark raw_irqentry_exit_cond_resched() as __visible export, lto: Mark __kstrtab* in EXPORT_SYMBOL() as global and
__visible
softirq, lto: Mark irq_enter/exit_rcu() as __visible btf, lto: Make all BTF IDs global on LTO
init.h, lto: mark initcalls as __noreorder
bpf, lto: mark interpreter jump table as __noreorder sched, lto: mark sched classes as __noreorder
linkage, lto: use C version for SYSCALL_ALIAS() / cond_syscall() scripts, lto: re-add gcc-ld
scripts, lto: use CONFIG_LTO for many LTO specific actions Kbuild, lto: Add Link Time Optimization support x86/purgatory, lto: Disable gcc LTO for purgatory x86/realmode, lto: Disable gcc LTO for real mode code x86/vdso, lto: Disable gcc LTO for the vdso
scripts, lto: disable gcc LTO for some mod sources Kbuild, lto: disable gcc LTO for bounds+asm-offsets lib/string, lto: disable gcc LTO for string.o
Compiler attributes, lto: disable __flatten with LTO Kbuild, lto: don't include weak source file symbols in System.map x86, lto: Disable relative init pointers with gcc LTO x86/livepatch, lto: Disable live patching with gcc LTO x86/lib, lto: Mark 32bit mem{cpy,move,set} as __used scripts, lto: check C symbols for modversions scripts/bloat-o-meter, lto: handle gcc LTO
x86, lto: Finally enable gcc LTO for x86

Jiri Slaby (5):
kbuild: pass jobserver to cmd_ld_vmlinux.o compiler.h: introduce __visible_on_lto compiler.h: introduce __global_on_lto btf, lto: pass scope as strings
x86/apic, lto: Mark apic_driver*() as __noreorder

Martin Liska (4):
kbuild: lto: preserve MAKEFLAGS for module linking x86/sev, lto: Mark cpuid_table_copy as __visible_on_lto mm/kasan, lto: Mark kasan mem{cpy,move,set} as __used kasan, lto: remove extra BUILD_BUG() in memory_is_poisoned

 Documentation/kbuild/index.rst      |  2 +
 Documentation/kbuild/lto-build.rst  | 76 +++++++++++++++++++++++++++++
 Kbuild                              |  3 ++
 Makefile                            |  6 ++-
 arch/Kconfig                        | 52 ++++++++++++++++++++
 arch/x86/Kconfig                    |  5 +-
 arch/x86/boot/compressed/head_32.S  |  2 +-
 arch/x86/boot/compressed/head_64.S  |  2 +-
 arch/x86/boot/compressed/misc.c     | 16 +++---
 arch/x86/entry/vdso/Makefile        |  2 +
 arch/x86/events/amd/core.c          |  2 +-
 arch/x86/include/asm/apic.h         |  4 +-
 arch/x86/include/asm/preempt.h      |  4 +-
 arch/x86/kernel/alternative.c       |  5 +-
 arch/x86/kernel/cpu/common.c        |  2 +-
 arch/x86/kernel/paravirt.c          |  2 +-
 arch/x86/kernel/sev-shared.c        |  2 +-
 arch/x86/kernel/tsc.c               |  2 +-
 arch/x86/lib/memcpy_32.c            |  6 +--
 arch/x86/purgatory/Makefile         |  2 +
 arch/x86/realmode/Makefile          |  1 +
 drivers/cpufreq/amd-pstate.c        | 15 +++---
 drivers/xen/time.c                  |  2 +-
 include/asm-generic/vmlinux.lds.h   |  2 +-
 include/linux/btf_ids.h             | 24 ++++-----
 include/linux/compiler.h            |  8 +++
 include/linux/compiler_attributes.h | 15 ++++++
 include/linux/export.h              |  6 ++-
 include/linux/init.h                |  2 +-
 include/linux/linkage.h             | 16 +++---
 include/linux/static_call.h         | 12 ++---
 include/linux/tracepoint.h          |  4 +-
 kernel/bpf/core.c                   |  2 +-
 kernel/entry/common.c               |  2 +-
 kernel/kallsyms.c                   |  2 +-
 kernel/livepatch/Kconfig            |  1 +
 kernel/sched/sched.h                |  1 +
 kernel/softirq.c                    |  4 +-
 kernel/static_call.c                |  2 +-
 kernel/static_call_inline.c         |  6 +--
 kernel/time/posix-stubs.c           | 19 +++++++-
 lib/Makefile                        |  2 +
 mm/kasan/generic.c                  |  2 +-
 mm/kasan/shadow.c                   |  6 +--
 scripts/Makefile.build              | 17 ++++---
 scripts/Makefile.lib                |  2 +-
 scripts/Makefile.lto                | 43 ++++++++++++++++
 scripts/Makefile.modfinal           |  2 +-
 scripts/Makefile.vmlinux            |  3 +-
 scripts/Makefile.vmlinux_o          |  6 +--
 scripts/bloat-o-meter               |  2 +-
 scripts/gcc-ld                      | 40 +++++++++++++++
 scripts/link-vmlinux.sh             |  9 ++--
 scripts/mksysmap                    |  2 +
 scripts/mod/Makefile                |  3 ++
 scripts/module.lds.S                |  2 +-
 56 files changed, 384 insertions(+), 100 deletions(-)
 create mode 100644 Documentation/kbuild/lto-build.rst
 create mode 100644 scripts/Makefile.lto
 create mode 100755 scripts/gcc-ld
Signature · 1 line
2.38.1