2 # Support for gcc link time optimization
12 # 4.7 works mostly, but it sometimes loses symbols on large builds
13 # This can be worked around by marking those symbols visible,
14 # but that is fairly ugly and the problem is gone with 4.8
15 # So only allow it with 4.8 for now.
16 ifeq ($(call cc-ifversion, -ge, 0408,y),y)
17 ifneq ($(call cc-option,${LTO_CFLAGS},n),n)
18 # We need HJ Lu's Linux binutils because mainline binutils does not
19 # support mixing assembler and LTO code in the same ld -r object.
20 # XXX check if the gcc plugin ld is the expected one too
21 # XXX some Fedora binutils should also support it. How to check for that?
22 ifeq ($(call ld-ifversion,-ge,22710001,y),y)
23 LTO_CFLAGS := -flto -fno-toplevel-reorder
24 LTO_FINAL_CFLAGS := -fuse-linker-plugin
26 # the -fno-toplevel-reorder is to preserve the order of initcalls
27 # everything else should tolerate reordering
28 LTO_FINAL_CFLAGS +=-fno-toplevel-reorder
30 # enable LTO and set the jobs used by the LTO phase
31 # this should be -flto=jobserver to coordinate with the
32 # parent make, but work around
33 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50639
34 # use as many jobs as processors are online for now
35 # this actually seems to be a kernel bug with the pipe code
36 LTO_FINAL_CFLAGS := -flto=$(shell getconf _NPROCESSORS_ONLN)
37 #LTO_FINAL_CFLAGS := -flto=jobserver
39 # requires plugin ar passed and very recent HJ binutils
40 LTO_CFLAGS += -fno-fat-lto-objects
42 # Used to disable LTO for specific files (e.g. vdso)
43 DISABLE_LTO := -fno-lto
45 LTO_FINAL_CFLAGS += ${LTO_CFLAGS} -fwhole-program
47 ifdef CONFIG_LTO_DEBUG
48 LTO_FINAL_CFLAGS += -dH -fdump-ipa-cgraph -fdump-ipa-inline-details
49 # -Wl,-plugin-save-temps -save-temps
52 ifdef CONFIG_LTO_CP_CLONE
53 LTO_FINAL_CFLAGS += -fipa-cp-clone
54 LTO_CFLAGS += -fipa-cp-clone
57 # In principle gcc should pass through options in the object files,
58 # but it doesn't always work. So do it here manually
59 # Note that special options for individual files does not
60 # work currently (except for some special cases that only
61 # affect the compiler frontend)
62 # The main offenders are FTRACE and GCOV -- we exclude
63 # those in the config.
64 LTO_FINAL_CFLAGS += $(filter -g%,${KBUILD_CFLAGS})
65 LTO_FINAL_CFLAGS += $(filter -O%,${KBUILD_CFLAGS})
66 LTO_FINAL_CFLAGS += $(filter -f%,${KBUILD_CFLAGS})
67 LTO_FINAL_CFLAGS += $(filter -m%,${KBUILD_CFLAGS})
68 LTO_FINAL_CFLAGS += $(filter -W%,${KBUILD_CFLAGS})
70 KBUILD_CFLAGS += ${LTO_CFLAGS}
72 LDFINAL := ${CONFIG_SHELL} ${srctree}/scripts/gcc-ld \
76 $(warning "WARNING: Too old linker version $(call ld-version) for kernel LTO. You need Linux binutils. CONFIG_LTO disabled.")
79 $(warning "WARNING: Compiler/Linker does not support LTO/WHOPR with linker plugin. CONFIG_LTO disabled.")
82 $(warning "WARNING: GCC $(call cc-version) too old for LTO/WHOPR. CONFIG_LTO disabled")