summaryrefslogtreecommitdiff
path: root/scripts/Makefile.lto
blob: b8e9e4836f4b559181db6d640f35a13d79e75f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#
# Support for gcc link time optimization
#

DISABLE_LTO :=
LTO_CFLAGS :=

export DISABLE_LTO
export LTO_CFLAGS

ifdef CONFIG_LTO
# 4.7 works mostly, but it sometimes loses symbols on large builds
# This can be worked around by marking those symbols visible,
# but that is fairly ugly and the problem is gone with 4.8
# So only allow it with 4.8 for now.
ifeq ($(call cc-ifversion, -ge, 0408,y),y)
ifneq ($(call cc-option,${LTO_CFLAGS},n),n)
# We need HJ Lu's Linux binutils because mainline binutils does not
# support mixing assembler and LTO code in the same ld -r object.
# XXX check if the gcc plugin ld is the expected one too
# XXX some Fedora binutils should also support it. How to check for that?
ifeq ($(call ld-ifversion,-ge,22710001,y),y)
        LTO_CFLAGS := -flto -fno-toplevel-reorder
	LTO_FINAL_CFLAGS := -fuse-linker-plugin

# the -fno-toplevel-reorder is to preserve the order of initcalls
# everything else should tolerate reordering
        LTO_FINAL_CFLAGS +=-fno-toplevel-reorder

# enable LTO and set the jobs used by the LTO phase
# this should be -flto=jobserver to coordinate with the
# parent make, but work around
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50639
# use as many jobs as processors are online for now
# this actually seems to be a kernel bug with the pipe code
	LTO_FINAL_CFLAGS := -flto=$(shell getconf _NPROCESSORS_ONLN)
	#LTO_FINAL_CFLAGS := -flto=jobserver

	# requires plugin ar passed and very recent HJ binutils
        LTO_CFLAGS += -fno-fat-lto-objects

# Used to disable LTO for specific files (e.g. vdso)
	DISABLE_LTO := -fno-lto

	LTO_FINAL_CFLAGS += ${LTO_CFLAGS} -fwhole-program

ifdef CONFIG_LTO_DEBUG
	LTO_FINAL_CFLAGS += -dH -fdump-ipa-cgraph -fdump-ipa-inline-details
	# -Wl,-plugin-save-temps -save-temps
	LTO_CFLAGS +=
endif
ifdef CONFIG_LTO_CP_CLONE
	LTO_FINAL_CFLAGS += -fipa-cp-clone
	LTO_CFLAGS += -fipa-cp-clone
endif

	# In principle gcc should pass through options in the object files,
	# but it doesn't always work. So do it here manually
	# Note that special options for individual files does not
	# work currently (except for some special cases that only
	# affect the compiler frontend)
	# The main offenders are FTRACE and GCOV -- we exclude
	# those in the config.
	LTO_FINAL_CFLAGS += $(filter -g%,${KBUILD_CFLAGS})
	LTO_FINAL_CFLAGS += $(filter -O%,${KBUILD_CFLAGS})
	LTO_FINAL_CFLAGS += $(filter -f%,${KBUILD_CFLAGS})
	LTO_FINAL_CFLAGS += $(filter -m%,${KBUILD_CFLAGS})
	LTO_FINAL_CFLAGS += $(filter -W%,${KBUILD_CFLAGS})

	KBUILD_CFLAGS += ${LTO_CFLAGS}

	LDFINAL := ${CONFIG_SHELL} ${srctree}/scripts/gcc-ld \
                  ${LTO_FINAL_CFLAGS}

else
        $(warning "WARNING: Too old linker version $(call ld-version) for kernel LTO. You need Linux binutils. CONFIG_LTO disabled.")
endif
else
        $(warning "WARNING: Compiler/Linker does not support LTO/WHOPR with linker plugin. CONFIG_LTO disabled.")
endif
else
        $(warning "WARNING: GCC $(call cc-version) too old for LTO/WHOPR. CONFIG_LTO disabled")
endif
endif