From 403973c95daa62b8411f789a8a93ef9e18b7f980 Mon Sep 17 00:00:00 2001 From: Sandrine Bailleux Date: Mon, 11 Apr 2016 13:01:17 +0100 Subject: Give user's compiler flags precedence over default ones The user can provide additional CFLAGS to use when building TF. However, these custom CFLAGS are currently prepended to the standard CFLAGS that are hardcoded in the TF build system. This is an issue because when providing conflicting compiler flags (e.g. different optimisations levels like -O1 and -O0), the last one on the command line usually takes precedence. This means that the user flags get overriden. To address this problem, this patch separates the TF CFLAGS from the user CFLAGS. The former are now stored in the TF_CFLAGS make variable, whereas the CFLAGS make variable is untouched and reserved for the user. The order of the 2 sets of flags is enforced when invoking the compiler. Fixes ARM-Software/tf-issues#350 Change-Id: Ib189f44555b885f1dffbec6015092f381600e560 --- Makefile | 10 +++++----- make_helpers/build_macros.mk | 6 +++--- make_helpers/windows.mk | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index c5ec6d1c..b1560a2b 100644 --- a/Makefile +++ b/Makefile @@ -136,7 +136,7 @@ export Q $(eval $(call add_define,DEBUG)) ifneq (${DEBUG}, 0) BUILD_TYPE := debug - CFLAGS += -g + TF_CFLAGS += -g ASFLAGS += -g -Wa,--gdwarf-2 # Use LOG_LEVEL_INFO by default for debug builds LOG_LEVEL := 40 @@ -179,12 +179,12 @@ ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ -Werror -Wmissing-include-dirs \ -mgeneral-regs-only -D__ASSEMBLY__ \ ${DEFINES} ${INCLUDES} -CFLAGS += -nostdinc -ffreestanding -Wall \ +TF_CFLAGS += -nostdinc -ffreestanding -Wall \ -Werror -Wmissing-include-dirs \ -mgeneral-regs-only -mstrict-align \ -std=c99 -c -Os \ ${DEFINES} ${INCLUDES} -CFLAGS += -ffunction-sections -fdata-sections +TF_CFLAGS += -ffunction-sections -fdata-sections LDFLAGS += --fatal-warnings -O1 LDFLAGS += --gc-sections @@ -331,7 +331,7 @@ endif # Check if -pedantic option should be used ifeq (${DISABLE_PEDANTIC},0) - CFLAGS += -pedantic + TF_CFLAGS += -pedantic endif # Using the ARM Trusted Firmware BL2 implies that a BL33 image also needs to be @@ -487,7 +487,7 @@ msg_start: # Check if deprecated declarations should be treated as error or not. ifeq (${ERROR_DEPRECATED},0) - CFLAGS += -Wno-error=deprecated-declarations + TF_CFLAGS += -Wno-error=deprecated-declarations endif # Expand build macros for the different images diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index 5171ff00..c963b7af 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -208,11 +208,11 @@ $(eval IMAGE := IMAGE_BL$(call uppercase,$(3))) $(OBJ): $(2) @echo " CC $$<" - $$(Q)$$(CC) $$(CFLAGS) -D$(IMAGE) -c $$< -o $$@ + $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -D$(IMAGE) -c $$< -o $$@ $(PREREQUISITES): $(2) | bl$(3)_dirs @echo " DEPS $$@" - $$(Q)$$(CC) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$< + $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$< ifdef IS_ANYTHING_TO_BUILD -include $(PREREQUISITES) @@ -351,7 +351,7 @@ ifdef MAKE_BUILD_STRINGS else @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \ const char version_string[] = "${VERSION_STRING}";' | \ - $$(CC) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o + $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o endif $$(Q)$$(LD) -o $$@ $$(LDFLAGS) -Map=$(MAPFILE) --script $(LINKERFILE) \ $(BUILD_DIR)/build_message.o $(OBJS) diff --git a/make_helpers/windows.mk b/make_helpers/windows.mk index 8ac82460..fe5e8c1f 100644 --- a/make_helpers/windows.mk +++ b/make_helpers/windows.mk @@ -104,6 +104,6 @@ BUILT_TIME_DATE_STRING = const char build_message[] = "Built : "${BUILD_MESSAGE_ VERSION_STRING_MESSAGE = const char version_string[] = "${VERSION_STRING}"; define MAKE_BUILD_STRINGS @echo $$(BUILT_TIME_DATE_STRING) $$(VERSION_STRING_MESSAGE) | \ - $$(CC) $$(CFLAGS) -x c - -o $1 + $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -x c - -o $1 endef -- cgit From 10c252c14b7f446c0b49ef1aafbd5d37804577dd Mon Sep 17 00:00:00 2001 From: Sandrine Bailleux Date: Mon, 11 Apr 2016 13:17:50 +0100 Subject: Fix build error with optimizations disabled (-O0) If Trusted Firmware is built with optimizations disabled (-O0), the linker throws the following error: undefined reference to 'xxx' Where 'xxx' is a raw inline function defined in a header file. The reason is that, with optimizations disabled, GCC may decide to skip the inlining. If that is the case, an external definition to the compilation unit must be provided. Because no external definition is present, the linker throws the error. This patch fixes the problem by declaring the following inline functions static, so the internal definition is used: - cm_set_next_context() - bakery_lock_init() Note that building the TF with optimizations disabled when Trusted Board Boot is enabled is currently unsupported, as this makes the BL2 image too big to fit in memory without any adjustment of its base address. Similarly, disabling optimizations for debug builds on FVP is unsupported at the moment. Change-Id: I284a9f84cc8df96a0c1a52dfe05c9e8544c0cefe --- include/common/context_mgmt.h | 3 +-- include/lib/bakery_lock.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/common/context_mgmt.h b/include/common/context_mgmt.h index 11786a18..a76ecbe3 100644 --- a/include/common/context_mgmt.h +++ b/include/common/context_mgmt.h @@ -55,7 +55,6 @@ void cm_set_context_by_index(unsigned int cpu_idx, unsigned int security_state); void *cm_get_context(uint32_t security_state); void cm_set_context(void *context, uint32_t security_state); -inline void cm_set_next_context(void *context); void cm_init_context(uint64_t mpidr, const struct entry_point_info *ep) __deprecated; void cm_init_my_context(const struct entry_point_info *ep); @@ -80,7 +79,7 @@ uint32_t cm_get_scr_el3(uint32_t security_state); * return. This initializes the SP_EL3 to a pointer to a 'cpu_context' set for * the required security state ******************************************************************************/ -inline void cm_set_next_context(void *context) +static inline void cm_set_next_context(void *context) { #if DEBUG uint64_t sp_mode; diff --git a/include/lib/bakery_lock.h b/include/lib/bakery_lock.h index 8a538917..6b8157e6 100644 --- a/include/lib/bakery_lock.h +++ b/include/lib/bakery_lock.h @@ -96,7 +96,7 @@ typedef bakery_info_t bakery_lock_t; #endif /* __USE_COHERENT_MEM__ */ -inline void bakery_lock_init(bakery_lock_t *bakery) {} +static inline void bakery_lock_init(bakery_lock_t *bakery) {} void bakery_lock_get(bakery_lock_t *bakery); void bakery_lock_release(bakery_lock_t *bakery); -- cgit