blob: e237c514170c0ee09f619998476c9f0787e5e4f0 [file] [log] [blame]
Boyan Karatotev3df79ae2025-04-09 14:26:17 +01001#
2# Copyright (c) 2025, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7GCC_V_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
8PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
9
10################################################################################
11# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
12################################################################################
13ifeq (${ARM_ARCH_MAJOR},7)
14 target32-directive = -target arm-none-eabi
15# Will set march-directive from platform configuration
16else
17 target32-directive = -target armv8a-none-eabi
18endif #(ARM_ARCH_MAJOR)
19
20ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
21 ifeq ($($(ARCH)-cc-id),arm-clang)
22 TF_CFLAGS_aarch32 := -target arm-arm-none-eabi
23 TF_CFLAGS_aarch64 := -target aarch64-arm-none-eabi
24 else
25 TF_CFLAGS_aarch32 = $(target32-directive)
26 TF_CFLAGS_aarch64 := -target aarch64-elf
27 endif
28endif #(clang)
29
30# Process Debug flag
31ifneq (${DEBUG}, 0)
32 TF_CFLAGS += -g -gdwarf-4
Boyan Karatotev3df79ae2025-04-09 14:26:17 +010033endif #(Debug)
34
35ifeq (${AARCH32_INSTRUCTION_SET},A32)
36 TF_CFLAGS_aarch32 += -marm
37else ifeq (${AARCH32_INSTRUCTION_SET},T32)
38 TF_CFLAGS_aarch32 += -mthumb
39endif #(AARCH32_INSTRUCTION_SET)
40
41TF_CFLAGS_aarch32 += -mno-unaligned-access
42TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align
43
44##############################################################################
45# WARNINGS Configuration
46###############################################################################
47# General warnings
48WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
49 -Wdisabled-optimization -Wvla -Wshadow \
50 -Wredundant-decls
51# stricter warnings
52WARNINGS += -Wextra -Wno-trigraphs
53# too verbose for generic build
54WARNINGS += -Wno-missing-field-initializers \
55 -Wno-type-limits -Wno-sign-compare \
56# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
57WARNINGS += -Wno-unused-parameter
58
59# Additional warnings
60# Level 1 - infrequent warnings we should have none of
61# full -Wextra
62WARNING1 += -Wsign-compare
63WARNING1 += -Wtype-limits
64WARNING1 += -Wmissing-field-initializers
65
66# Level 2 - problematic warnings that we want
67# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
68# TODO: disable just for them and move into default build
69WARNING2 += -Wold-style-definition
70WARNING2 += -Wmissing-prototypes
71WARNING2 += -Wmissing-format-attribute
72# TF-A aims to comply with this eventually. Effort too large at present
73WARNING2 += -Wundef
74# currently very involved and many platforms set this off
75WARNING2 += -Wunused-const-variable=2
76
77# Level 3 - very pedantic, frequently ignored
78WARNING3 := -Wbad-function-cast
79WARNING3 += -Waggregate-return
80WARNING3 += -Wnested-externs
81WARNING3 += -Wcast-align
82WARNING3 += -Wcast-qual
83WARNING3 += -Wconversion
84WARNING3 += -Wpacked
85WARNING3 += -Wpointer-arith
86WARNING3 += -Wswitch-default
87
88ifeq (${W},1)
89 WARNINGS += $(WARNING1)
90else ifeq (${W},2)
91 WARNINGS += $(WARNING1) $(WARNING2)
92else ifeq (${W},3)
93 WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
94endif #(W)
95
96ifneq (${E},0)
97 ERRORS := -Werror
98endif #(E)
99
100# Compiler specific warnings
101ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
102# not using clang
103# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
104TF_CFLAGS_MIN_PAGE_SIZE := $(call cc_option, --param=min-pagesize=0)
105TF_CFLAGS += $(TF_CFLAGS_MIN_PAGE_SIZE)
106
107ifeq ($(HARDEN_SLS), 1)
108 TF_CFLAGS_MHARDEN_SLS := $(call cc_option, -mharden-sls=all)
109 TF_CFLAGS_aarch64 += $(TF_CFLAGS_MHARDEN_SLS)
110endif
111
112WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \
113 -Wpacked-bitfield-compat -Wshift-overflow=2 \
114 -Wlogical-op
115
116else
117# using clang
118WARNINGS += -Wshift-overflow -Wshift-sign-overflow \
119 -Wlogical-op-parentheses
120endif #(Clang Warning)
121
122CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \
123 $(ERRORS) $(WARNINGS)
124
125
126TF_CFLAGS += -ffunction-sections -fdata-sections \
127 -ffreestanding -fno-common \
128 -Os -std=gnu99
129
130ifneq (${BP_OPTION},none)
131 TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION}
132endif #(BP_OPTION)
133
134ifeq (${SANITIZE_UB},on)
135 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover
136endif #(${SANITIZE_UB},on)
137
138ifeq (${SANITIZE_UB},trap)
139 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \
140 -fsanitize-undefined-trap-on-error
141endif #(${SANITIZE_UB},trap)
142
143ifeq ($($(ARCH)-cc-id),gnu-gcc)
144 # Enable LTO only for aarch64
145 LTO_CFLAGS = $(if $(filter-out 0,$(ENABLE_LTO)),-flto)
146endif #(gnu-gcc)
147
148ifeq (${ERROR_DEPRECATED},0)
149# Check if deprecated declarations and cpp warnings should be treated as error or not.
150ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
151 CPPFLAGS += -Wno-error=deprecated-declarations
152else
153 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp
154endif
155endif #(!ERROR_DEPRECATED)
156
157################################################################################
158# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
159# up with appropriate march values for compiler.
160################################################################################
161include ${MAKE_HELPERS_DIRECTORY}march.mk
162ifeq (${ARM_ARCH_MAJOR},7)
163include make_helpers/armv7-a-cpus.mk
164endif
165
166TF_CFLAGS += $(march-directive)
Boyan Karatotev3df79ae2025-04-09 14:26:17 +0100167
168ifneq ($(PIE_FOUND),)
169 TF_CFLAGS += -fno-PIE
170endif
171
172TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH))
Boyan Karatotev6bb9f052025-04-25 13:25:50 +0100173TF_CFLAGS += $(CFLAGS)
Boyan Karatotev7416eb22025-04-11 14:47:20 +0100174ASFLAGS += -Wa,--fatal-warnings
Boyan Karatotev3df79ae2025-04-09 14:26:17 +0100175TF_LDFLAGS += -z noexecstack
176
177# LD = armlink
178ifeq ($($(ARCH)-ld-id),arm-link)
179 TF_LDFLAGS += --diag_error=warning --lto_level=O1
180 TF_LDFLAGS += --remove --info=unused,unusedsymbols
181 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH))
182
183# LD = gcc (used when GCC LTO is enabled)
184else ifeq ($($(ARCH)-ld-id),gnu-gcc)
185 # Pass ld options with Wl or Xlinker switches
186 TF_LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments)
187 TF_LDFLAGS += -Wl,--fatal-warnings -O1
188 TF_LDFLAGS += -Wl,--gc-sections
189
190 TF_LDFLAGS += -Wl,-z,common-page-size=4096 #Configure page size constants
191 TF_LDFLAGS += -Wl,-z,max-page-size=4096
192 TF_LDFLAGS += -Wl,--build-id=none
193
194 ifeq ($(ENABLE_LTO),1)
195 TF_LDFLAGS += -flto -fuse-linker-plugin
196 TF_LDFLAGS += -flto-partition=one
197 endif #(ENABLE_LTO)
198
199# GCC automatically adds fix-cortex-a53-843419 flag when used to link
200# which breaks some builds, so disable if errata fix is not explicitly enabled
201 ifeq (${ARCH},aarch64)
202 ifneq (${ERRATA_A53_843419},1)
203 TF_LDFLAGS += -mno-fix-cortex-a53-843419
204 endif
205 endif
206 TF_LDFLAGS += -nostdlib
207 TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
208
209# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
210else
211# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
212# are not loaded by a elf loader.
213 TF_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
214 TF_LDFLAGS += -O1
215 TF_LDFLAGS += --gc-sections
216
217 TF_LDFLAGS += -z common-page-size=4096 # Configure page size constants
218 TF_LDFLAGS += -z max-page-size=4096
219 TF_LDFLAGS += --build-id=none
220
221# ld.lld doesn't recognize the errata flags,
222# therefore don't add those in that case.
223# ld.lld reports section type mismatch warnings,
224# therefore don't add --fatal-warnings to it.
225 ifneq ($($(ARCH)-ld-id),llvm-lld)
226 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) --fatal-warnings
227 endif
228
229endif #(LD = armlink)
230
231ifneq ($(PIE_FOUND),)
232ifeq ($($(ARCH)-ld-id),gnu-gcc)
233 TF_LDFLAGS += -no-pie
234endif
235endif #(PIE_FOUND)
236
237ifeq ($($(ARCH)-ld-id),gnu-gcc)
238 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
239else
240 PIE_LDFLAGS += -pie --no-dynamic-linker
241endif
242
243ifeq ($(ENABLE_PIE),1)
244 ifeq ($(RESET_TO_BL2),1)
245 ifneq ($(BL2_IN_XIP_MEM),1)
246 BL2_CPPFLAGS += -fpie
247 BL2_CFLAGS += -fpie
248 BL2_LDFLAGS += $(PIE_LDFLAGS)
249 endif #(BL2_IN_XIP_MEM)
250 endif #(RESET_TO_BL2)
251 BL31_CPPFLAGS += -fpie
252 BL31_CFLAGS += -fpie
253 BL31_LDFLAGS += $(PIE_LDFLAGS)
254
255 BL32_CPPFLAGS += -fpie
256 BL32_CFLAGS += -fpie
257 BL32_LDFLAGS += $(PIE_LDFLAGS)
258endif #(ENABLE_PIE)
259
260BL1_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
261BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
262BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
263
264BL1_CPPFLAGS += -DIMAGE_AT_EL3
265ifeq ($(RESET_TO_BL2),1)
266 BL2_CPPFLAGS += -DIMAGE_AT_EL3
267else
268 BL2_CPPFLAGS += -DIMAGE_AT_EL1
269endif #(RESET_TO_BL2)
270
271ifeq (${ARCH},aarch64)
272 BL2U_CPPFLAGS += -DIMAGE_AT_EL1
273 BL31_CPPFLAGS += -DIMAGE_AT_EL3
274 BL32_CPPFLAGS += -DIMAGE_AT_EL1
275else
276 BL32_CPPFLAGS += -DIMAGE_AT_EL3
277endif
278
279ifeq (${SPD},spmd)
280 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
281 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG
282 endif
283
284 ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
285 DTC_CPPFLAGS += -DTRUSTY_SP_FW_CONFIG
286 endif
287
288 ifeq ($(TS_SP_FW_CONFIG),1)
289 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG
290 endif
291
292 ifneq ($(ARM_BL2_SP_LIST_DTS),)
293 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
294 endif
295endif
296
297
298DTC_FLAGS += -I dts -O dtb
Boyan Karatotev1e8b5352025-04-29 09:32:12 +0100299DTC_CPPFLAGS += -Ifdts -undef
Boyan Karatotev3df79ae2025-04-09 14:26:17 +0100300