From e068a7ca860f35a171f608d55fb8a2a00ebd7561 Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Mon, 15 Jan 2024 16:16:07 +0000 Subject: [PATCH 1/6] fix(rcar): fix implicit rule invocations in tools The `rzg_layout_create` and `rcar_layout_create` tools have a rule to build object files from C files, but it depends on object files in the parent directory when it should depend on object files in the current directory. Consequently, the rule is not triggering and the implicit C compilation rule is executed instead. This rule works, so I have replaced the broken rule with exactly the same command as what the implicit rule is executing and fixed the dependency. Change-Id: Ib8d640361adff8c4d660738dda230e5536bec629 Signed-off-by: Chris Kay --- tools/renesas/rcar_layout_create/makefile | 4 ++-- tools/renesas/rzg_layout_create/makefile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/renesas/rcar_layout_create/makefile b/tools/renesas/rcar_layout_create/makefile index d5857549b..01b3d62f4 100644 --- a/tools/renesas/rcar_layout_create/makefile +++ b/tools/renesas/rcar_layout_create/makefile @@ -113,8 +113,8 @@ $(OUTPUT_FILE_SA6) : $(MEMORY_DEF_SA6) $(OBJ_FILE_SA6) # Compile ################################################### -%.o:../%.c - $(CC) -c -I $< -o $@ +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< .PHONY: clean clean: diff --git a/tools/renesas/rzg_layout_create/makefile b/tools/renesas/rzg_layout_create/makefile index 2d438b923..92a0557c0 100644 --- a/tools/renesas/rzg_layout_create/makefile +++ b/tools/renesas/rzg_layout_create/makefile @@ -110,8 +110,8 @@ $(OUTPUT_FILE_SA6) : $(MEMORY_DEF_SA6) $(OBJ_FILE_SA6) # Compile ################################################### -%.o:../%.c - $(CC) -c -I $< -o $@ +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< .PHONY: clean clean: From 781cb31439f9b02e2f0befc4bee651ff5f945cf7 Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Mon, 15 Jan 2024 18:45:07 +0000 Subject: [PATCH 2/6] build: always use the C compiler to preprocess We're a bit inconsistent about which tool we use to preprocess source files; in some places we use `$(CC) -E` whilst in others we use `cpp`. This change forces all invocations of the C preprocessor to use the first scheme, which ensures that the preprocessor behaves the same way as the C compiler used when compiling C source files. Change-Id: Iede2f25ff86ea8b43d7a523e32648058d5023832 Signed-off-by: Chris Kay --- Makefile | 6 ++---- lib/romlib/Makefile | 4 ++-- make_helpers/build_macros.mk | 4 ++-- plat/rockchip/rk3399/drivers/m0/Makefile | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index f8b230d6a..8e90a753b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved. +# Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -100,14 +100,13 @@ HOSTCC := gcc export HOSTCC CC := ${CROSS_COMPILE}gcc -CPP := ${CROSS_COMPILE}cpp +CPP := ${CROSS_COMPILE}gcc -E AS := ${CROSS_COMPILE}gcc AR := ${CROSS_COMPILE}ar LINKER := ${CROSS_COMPILE}ld OC := ${CROSS_COMPILE}objcopy OD := ${CROSS_COMPILE}objdump NM := ${CROSS_COMPILE}nm -PP := ${CROSS_COMPILE}gcc -E DTC := dtc # Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH). @@ -187,7 +186,6 @@ ifneq ($(findstring clang,$(notdir $(CC))),) endif CPP := $(CC) -E $(TF_CFLAGS_$(ARCH)) - PP := $(CC) -E $(TF_CFLAGS_$(ARCH)) AS := $(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH)) else ifneq ($(findstring gcc,$(notdir $(CC))),) ifeq ($(ENABLE_LTO),1) diff --git a/lib/romlib/Makefile b/lib/romlib/Makefile index c3ddc5afb..5359f8fbb 100644 --- a/lib/romlib/Makefile +++ b/lib/romlib/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved. +# Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -8,7 +8,7 @@ AS = $(CROSS_COMPILE)as AR = $(CROSS_COMPILE)ar LD = $(CROSS_COMPILE)ld OC = $(CROSS_COMPILE)objcopy -CPP = $(CROSS_COMPILE)cpp +CPP = $(CROSS_COMPILE)gcc -E ROMLIB_GEN = ./romlib_generator.py BUILD_DIR = $(BUILD_PLAT)/romlib LIB_DIR = $(BUILD_PLAT)/lib diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index 08a604625..a0d71c51b 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved. +# Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -658,7 +658,7 @@ $(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ))) $(DOBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs $${ECHO} " CPP $$<" $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) - $$(Q)$$(PP) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$< + $$(Q)$$(CPP) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$< $${ECHO} " DTC $$<" $$(Q)$$(DTC) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $(DPRE) diff --git a/plat/rockchip/rk3399/drivers/m0/Makefile b/plat/rockchip/rk3399/drivers/m0/Makefile index 79e09f0ef..17632460d 100644 --- a/plat/rockchip/rk3399/drivers/m0/Makefile +++ b/plat/rockchip/rk3399/drivers/m0/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -40,7 +40,7 @@ LDFLAGS := -Wl,--gc-sections -Wl,--build-id=none # Cross tool CC := ${M0_CROSS_COMPILE}gcc -CPP := ${M0_CROSS_COMPILE}cpp +CPP := ${M0_CROSS_COMPILE}gcc -E AR := ${M0_CROSS_COMPILE}ar OC := ${M0_CROSS_COMPILE}objcopy OD := ${M0_CROSS_COMPILE}objdump From 7fc4d77808a1009c8cfe17e361db388507c8d2c7 Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Mon, 15 Jan 2024 18:45:07 +0000 Subject: [PATCH 3/6] build: always use the C compiler to assemble The ROM library is the only component in the repository that compiles assembly files using the assembler directly. This change migrates it to the C compiler instead, like the rest of the project. Change-Id: I6c50660eeb9be2ca8dcb0e626c37c197466b0fa1 Signed-off-by: Chris Kay --- changelog.yaml | 5 ++++- lib/romlib/Makefile | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/changelog.yaml b/changelog.yaml index c5e157d9b..326308208 100644 --- a/changelog.yaml +++ b/changelog.yaml @@ -1,5 +1,5 @@ # -# Copyright (c) 2021-2023, Arm Limited. All rights reserved. +# Copyright (c) 2021-2024, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -774,6 +774,9 @@ subsections: - title: PSCI scope: psci + - title: ROMlib + scope: romlib + - title: GPT scope: gpt diff --git a/lib/romlib/Makefile b/lib/romlib/Makefile index 5359f8fbb..8a437440c 100644 --- a/lib/romlib/Makefile +++ b/lib/romlib/Makefile @@ -4,7 +4,7 @@ # SPDX-License-Identifier: BSD-3-Clause # -AS = $(CROSS_COMPILE)as +AS = $(CROSS_COMPILE)gcc AR = $(CROSS_COMPILE)ar LD = $(CROSS_COMPILE)ld OC = $(CROSS_COMPILE)objcopy @@ -48,11 +48,11 @@ all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a %.o: %.s @echo " AS $@" - $(Q)$(AS) $(ASFLAGS) -o $@ $< + $(Q)$(AS) -c $(ASFLAGS) -o $@ $< $(BUILD_DIR)/%.o: %.s @echo " AS $@" - $(Q)$(AS) $(ASFLAGS) -o $@ $< + $(Q)$(AS) -c $(ASFLAGS) -o $@ $< $(BUILD_DIR)/romlib.ld: romlib.ld.S @echo " PP $@" From 86e489c1903c72b76c6ff3b3ff6b75774c132e59 Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Tue, 16 Jan 2024 11:53:35 +0000 Subject: [PATCH 4/6] build: add `--no-warn-rwx-segments` when linking with GCC This flag is currently not included when linking with BFD via GCC. Without it, builds can fail when linking via GCC. Change-Id: Id37e05f6fb4eea4620861eb1bc8668c41f21ba20 Signed-off-by: Chris Kay --- Makefile | 1 + make_helpers/build_macros.mk | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8e90a753b..2dc2956c9 100644 --- a/Makefile +++ b/Makefile @@ -354,6 +354,7 @@ ifneq ($(findstring armlink,$(notdir $(LD))),) # LD = gcc (used when GCC LTO is enabled) else ifneq ($(findstring gcc,$(notdir $(LD))),) # Pass ld options with Wl or Xlinker switches + TF_LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments) TF_LDFLAGS += -Wl,--fatal-warnings -O1 TF_LDFLAGS += -Wl,--gc-sections diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index a0d71c51b..2d2f14116 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -101,9 +101,7 @@ endef # Convenience function to check for a given linker option. An call to # $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker -define ld_option - $(shell if $(LD) $(1) -v >/dev/null 2>&1; then echo $(1); fi ) -endef +ld_option = $(shell $(LD) $(1) -Wl,--version >/dev/null 2>&1 || $(LD) $(1) -v >/dev/null 2>&1 && echo $(1)) # Convenience function to check for a given compiler option. A call to # $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler From 7e38758925f0eff899b16648293abbc9dd732c3d Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Mon, 15 Jan 2024 19:55:11 +0000 Subject: [PATCH 5/6] build: prefer `gcc-ar` over `ar` The `gcc-ar` wrapper exists to make it easier to support LTO on some versions of GCC. The two commands are compatible, accepting exactly the same arguments, so this change moves us to `gcc-ar` to ensure that we are configuring LTO correctly. Change-Id: I24a4cfaad29d35b09f847299081f83ca9b41aa8a Signed-off-by: Chris Kay --- Makefile | 2 +- lib/romlib/Makefile | 2 +- plat/rockchip/rk3399/drivers/m0/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 2dc2956c9..326766022 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ export HOSTCC CC := ${CROSS_COMPILE}gcc CPP := ${CROSS_COMPILE}gcc -E AS := ${CROSS_COMPILE}gcc -AR := ${CROSS_COMPILE}ar +AR := ${CROSS_COMPILE}gcc-ar LINKER := ${CROSS_COMPILE}ld OC := ${CROSS_COMPILE}objcopy OD := ${CROSS_COMPILE}objdump diff --git a/lib/romlib/Makefile b/lib/romlib/Makefile index 8a437440c..3b62aaa15 100644 --- a/lib/romlib/Makefile +++ b/lib/romlib/Makefile @@ -5,7 +5,7 @@ # AS = $(CROSS_COMPILE)gcc -AR = $(CROSS_COMPILE)ar +AR = $(CROSS_COMPILE)gcc-ar LD = $(CROSS_COMPILE)ld OC = $(CROSS_COMPILE)objcopy CPP = $(CROSS_COMPILE)gcc -E diff --git a/plat/rockchip/rk3399/drivers/m0/Makefile b/plat/rockchip/rk3399/drivers/m0/Makefile index 17632460d..8783269da 100644 --- a/plat/rockchip/rk3399/drivers/m0/Makefile +++ b/plat/rockchip/rk3399/drivers/m0/Makefile @@ -41,7 +41,7 @@ LDFLAGS := -Wl,--gc-sections -Wl,--build-id=none # Cross tool CC := ${M0_CROSS_COMPILE}gcc CPP := ${M0_CROSS_COMPILE}gcc -E -AR := ${M0_CROSS_COMPILE}ar +AR := ${M0_CROSS_COMPILE}gcc-ar OC := ${M0_CROSS_COMPILE}objcopy OD := ${M0_CROSS_COMPILE}objdump NM := ${M0_CROSS_COMPILE}nm From 1685b420658b262e4ffffec8dfdb9e45c88edb03 Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Mon, 15 Jan 2024 19:40:55 +0000 Subject: [PATCH 6/6] build: remove the `NM` variable No part of the build system uses the `NM` variable, which is usually used to dump symbol tables from compiled images. This change removes all declarations of it. Change-Id: I796ff365e6a7f97d21678f1c8cf8b59bfbb1ae9c Signed-off-by: Chris Kay --- Makefile | 1 - plat/rockchip/rk3399/drivers/m0/Makefile | 1 - 2 files changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 326766022..792ad1cf8 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,6 @@ AR := ${CROSS_COMPILE}gcc-ar LINKER := ${CROSS_COMPILE}ld OC := ${CROSS_COMPILE}objcopy OD := ${CROSS_COMPILE}objdump -NM := ${CROSS_COMPILE}nm DTC := dtc # Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH). diff --git a/plat/rockchip/rk3399/drivers/m0/Makefile b/plat/rockchip/rk3399/drivers/m0/Makefile index 8783269da..71548ba81 100644 --- a/plat/rockchip/rk3399/drivers/m0/Makefile +++ b/plat/rockchip/rk3399/drivers/m0/Makefile @@ -44,7 +44,6 @@ CPP := ${M0_CROSS_COMPILE}gcc -E AR := ${M0_CROSS_COMPILE}gcc-ar OC := ${M0_CROSS_COMPILE}objcopy OD := ${M0_CROSS_COMPILE}objdump -NM := ${M0_CROSS_COMPILE}nm # NOTE: The line continuation '\' is required in the next define otherwise we # end up with a line-feed characer at the end of the last c filename.