build: add option to enable LTO
[dpdk.git] / mk / toolchain / gcc / rte.vars.mk
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2010-2014 Intel Corporation
3
4 #
5 # toolchain:
6 #
7 #   - define CC, LD, AR, AS, ... (overridden by cmdline value)
8 #   - define TOOLCHAIN_CFLAGS variable (overridden by cmdline value)
9 #   - define TOOLCHAIN_LDFLAGS variable (overridden by cmdline value)
10 #   - define TOOLCHAIN_ASFLAGS variable (overridden by cmdline value)
11 #
12
13 CC        = $(CROSS)gcc
14 KERNELCC  = $(CROSS)gcc
15 CPP       = $(CROSS)cpp
16 # for now, we don't use as but nasm.
17 # AS      = $(CROSS)as
18 AS        = nasm
19 AR        = $(CROSS)ar
20 LD        = $(CROSS)ld
21 OBJCOPY   = $(CROSS)objcopy
22 OBJDUMP   = $(CROSS)objdump
23 STRIP     = $(CROSS)strip
24 READELF   = $(CROSS)readelf
25 GCOV      = $(CROSS)gcov
26
27 ifeq ("$(origin CC)", "command line")
28 HOSTCC    = $(CC)
29 else
30 HOSTCC    = gcc
31 endif
32 HOSTAS    = as
33
34 TOOLCHAIN_ASFLAGS =
35 TOOLCHAIN_CFLAGS =
36 TOOLCHAIN_LDFLAGS =
37
38 ifeq ($(CONFIG_RTE_LIBRTE_GCOV),y)
39 TOOLCHAIN_CFLAGS += --coverage
40 TOOLCHAIN_LDFLAGS += --coverage
41 ifeq (,$(findstring -O0,$(EXTRA_CFLAGS)))
42   $(warning "EXTRA_CFLAGS doesn't contains -O0, coverage will be inaccurate with optimizations enabled")
43 endif
44 endif
45
46 WERROR_FLAGS := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
47 WERROR_FLAGS += -Wmissing-declarations -Wold-style-definition -Wpointer-arith
48 WERROR_FLAGS += -Wcast-align -Wnested-externs -Wcast-qual
49 WERROR_FLAGS += -Wformat-nonliteral -Wformat-security
50 WERROR_FLAGS += -Wundef -Wwrite-strings -Wdeprecated
51
52 ifeq ($(RTE_DEVEL_BUILD),y)
53 WERROR_FLAGS += -Werror
54 endif
55
56 # There are many issues reported for strict alignment architectures
57 # which are not necessarily fatal. Report as warnings.
58 ifeq ($(CONFIG_RTE_ARCH_STRICT_ALIGN),y)
59 WERROR_FLAGS += -Wno-error=cast-align
60 endif
61
62 # process cpu flags
63 include $(RTE_SDK)/mk/toolchain/$(RTE_TOOLCHAIN)/rte.toolchain-compat.mk
64
65 ifeq ($(CONFIG_RTE_ENABLE_LTO),y)
66 # 'fat-lto' is used since pmdinfogen needs to have 'this_pmd_nameX'
67 # exported in symbol table and without this option only internal
68 # representation is present.
69 TOOLCHAIN_CFLAGS += -flto -ffat-lto-objects
70 TOOLCHAIN_LDFLAGS += -flto
71 # workaround for GCC bug 81440
72 ifeq ($(shell test $(GCC_VERSION) -lt 80 && echo 1), 1)
73 WERROR_FLAGS += -Wno-lto-type-mismatch
74 endif
75 endif
76
77 # workaround GCC bug with warning "missing initializer" for "= {0}"
78 ifeq ($(shell test $(GCC_VERSION) -lt 47 && echo 1), 1)
79 WERROR_FLAGS += -Wno-missing-field-initializers
80 endif
81 # workaround GCC bug with warning "may be used uninitialized"
82 ifeq ($(shell test $(GCC_VERSION) -lt 47 && echo 1), 1)
83 WERROR_FLAGS += -Wno-uninitialized
84 endif
85
86 HOST_WERROR_FLAGS := $(WERROR_FLAGS)
87
88 ifeq ($(shell test $(HOST_GCC_VERSION) -gt 70 && echo 1), 1)
89 # Tell GCC only to error for switch fallthroughs without a suitable comment
90 HOST_WERROR_FLAGS += -Wimplicit-fallthrough=2
91 # Ignore errors for snprintf truncation
92 HOST_WERROR_FLAGS += -Wno-format-truncation
93 endif
94
95 ifeq ($(shell test $(GCC_VERSION) -gt 70 && echo 1), 1)
96 # Tell GCC only to error for switch fallthroughs without a suitable comment
97 WERROR_FLAGS += -Wimplicit-fallthrough=2
98 # Ignore errors for snprintf truncation
99 WERROR_FLAGS += -Wno-format-truncation
100 endif
101
102 # disable packed member unalign warnings
103 WERROR_FLAGS += -Wno-address-of-packed-member
104
105 export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
106 export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS