]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - scripts/Makefile.lto
Merge remote-tracking branch 'omap_dss2/for-next'
[karo-tx-linux.git] / scripts / Makefile.lto
1 #
2 # Support for gcc link time optimization
3 #
4
5 DISABLE_LTO :=
6 LTO_CFLAGS :=
7
8 export DISABLE_LTO
9 export LTO_CFLAGS
10
11 ifdef CONFIG_LTO
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
25
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
29
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
38
39         # requires plugin ar passed and very recent HJ binutils
40         LTO_CFLAGS += -fno-fat-lto-objects
41
42 # Used to disable LTO for specific files (e.g. vdso)
43         DISABLE_LTO := -fno-lto
44
45         LTO_FINAL_CFLAGS += ${LTO_CFLAGS} -fwhole-program
46
47 ifdef CONFIG_LTO_DEBUG
48         LTO_FINAL_CFLAGS += -dH -fdump-ipa-cgraph -fdump-ipa-inline-details
49         # -Wl,-plugin-save-temps -save-temps
50         LTO_CFLAGS +=
51 endif
52 ifdef CONFIG_LTO_CP_CLONE
53         LTO_FINAL_CFLAGS += -fipa-cp-clone
54         LTO_CFLAGS += -fipa-cp-clone
55 endif
56
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})
69
70         KBUILD_CFLAGS += ${LTO_CFLAGS}
71
72         LDFINAL := ${CONFIG_SHELL} ${srctree}/scripts/gcc-ld \
73                   ${LTO_FINAL_CFLAGS}
74
75 else
76         $(warning "WARNING: Too old linker version $(call ld-version) for kernel LTO. You need Linux binutils. CONFIG_LTO disabled.")
77 endif
78 else
79         $(warning "WARNING: Compiler/Linker does not support LTO/WHOPR with linker plugin. CONFIG_LTO disabled.")
80 endif
81 else
82         $(warning "WARNING: GCC $(call cc-version) too old for LTO/WHOPR. CONFIG_LTO disabled")
83 endif
84 endif