]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
build: clarify linker script generation
authorChris Kay <chris.kay@arm.com>
Mon, 16 Jan 2023 16:53:45 +0000 (16:53 +0000)
committerChris Kay <chris.kay@arm.com>
Fri, 10 Feb 2023 17:01:46 +0000 (17:01 +0000)
The following build system variables have been renamed:

- `LINKERFILE` -> `DEFAULT_LINKER_SCRIPT`
- `BL_LINKERFILE` -> `DEFAULT_LINKER_SCRIPT_SOURCE`
- `<IMAGE>_LINKERFILE` -> `<IMAGE>_DEFAULT_LINKER_SCRIPT_SOURCE`

These new names better reflect how each variable is used:

1. the default linker script is passed via `-dT` instead of `-T`
2. linker script source files are first preprocessed

Additionally, linker scripts are now placed in the build directory
relative to where they exist in the source directory. For example,
the `bl32/sp_min/sp_min.ld.S` would now preprocess to
`sp_min/sp_min.ld` instead of just `bl32.ld`

BREAKING-CHANGE: The `LINKERFILE`, `BL_LINKERFILE` and
 `<IMAGE_LINKERFILE>` build system variables have been renamed. See the
 commit message for more information.

Change-Id: If8cef65dcb8820e8993736702c8741e97a66e6cc
Signed-off-by: Chris Kay <chris.kay@arm.com>
bl1/bl1.mk
bl2/bl2.mk
bl2u/bl2u.mk
bl31/bl31.mk
bl32/sp_min/sp_min.mk
bl32/tsp/tsp.mk
make_helpers/build_macros.mk
plat/marvell/armada/a8k/common/ble/ble.mk
services/std_svc/rmmd/trp/linker.ld.S [new file with mode: 0644]
services/std_svc/rmmd/trp/linker.lds [deleted file]
services/std_svc/rmmd/trp/trp.mk

index 9f63fd50fab0986464086e2fd0349decaea84509..0c43f13d0c11a5129223219dcbde19e2bdca1a76 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2013-2021, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -29,4 +29,4 @@ ifeq (${TRUSTED_BOARD_BOOT},1)
 BL1_SOURCES            +=      bl1/bl1_fwu.c
 endif
 
-BL1_LINKERFILE         :=      bl1/bl1.ld.S
+BL1_DEFAULT_LINKER_SCRIPT_SOURCE := bl1/bl1.ld.S
index 7a973e5120bfbda1d7663bc3fa0a6ba113c86c97..a18abab1392a3e7f9acc9798210ba24c73b5d6db 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2013-2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -23,12 +23,12 @@ BL2_SOURCES         +=      bl2/${ARCH}/bl2_rme_entrypoint.S        \
                                bl2/${ARCH}/bl2_el3_exceptions.S        \
                                bl2/${ARCH}/bl2_run_next_image.S        \
                                ${GPT_LIB_SRCS}
-BL2_LINKERFILE         :=      bl2/bl2.ld.S
+BL2_DEFAULT_LINKER_SCRIPT_SOURCE := bl2/bl2.ld.S
 
 else ifeq (${BL2_AT_EL3},0)
 # Normal operation, no RME, no BL2 at EL3
 BL2_SOURCES            +=      bl2/${ARCH}/bl2_entrypoint.S
-BL2_LINKERFILE         :=      bl2/bl2.ld.S
+BL2_DEFAULT_LINKER_SCRIPT_SOURCE := bl2/bl2.ld.S
 
 else
 # BL2 at EL3, no RME
@@ -46,5 +46,5 @@ ifeq (${ARCH},aarch64)
 BL2_SOURCES            +=      lib/cpus/aarch64/dsu_helpers.S
 endif
 
-BL2_LINKERFILE         :=      bl2/bl2_el3.ld.S
+BL2_DEFAULT_LINKER_SCRIPT_SOURCE := bl2/bl2_el3.ld.S
 endif
index b4d763433963edc90508aec0499c93f52621db77..9f29bdee14e76caaf2b94fc1495849eee6a01bdb 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -12,4 +12,4 @@ ifeq (${ARCH},aarch64)
 BL2U_SOURCES           +=      common/aarch64/early_exceptions.S
 endif
 
-BL2U_LINKERFILE                :=      bl2u/bl2u.ld.S
+BL2U_DEFAULT_LINKER_SCRIPT_SOURCE := bl2u/bl2u.ld.S
index ac15f9f58878dced292ddc210a1a5a0878152ad7..e6609fe863a10dbbda7da197f67f6bbce79b05df 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2013-2022, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -157,7 +157,7 @@ BL31_SOURCES                +=      services/std_svc/drtm/drtm_main.c               \
                                ${MBEDTLS_SOURCES}
 endif
 
-BL31_LINKERFILE                :=      bl31/bl31.ld.S
+BL31_DEFAULT_LINKER_SCRIPT_SOURCE := bl31/bl31.ld.S
 
 # Flag used to indicate if Crash reporting via console should be included
 # in BL31. This defaults to being present in DEBUG builds only
index ab1287dc0f917f306a3a107c56b26279d2a95d71..b2f4e4c09573869782463aa65b5d57ad5b1e8ee8 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2016-2022, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2016-2023, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -54,7 +54,7 @@ ifeq (${ENABLE_TRF_FOR_NS},1)
 BL32_SOURCES           +=      lib/extensions/trf/aarch32/trf.c
 endif
 
-BL32_LINKERFILE        :=      bl32/sp_min/sp_min.ld.S
+BL32_DEFAULT_LINKER_SCRIPT_SOURCE := bl32/sp_min/sp_min.ld.S
 
 # Include the platform-specific SP_MIN Makefile
 # If no platform-specific SP_MIN Makefile exists, it means SP_MIN is not supported
index c31b9b54304ec302c93c7d0457f1b29c7021da5e..cfffbdbed9138e52195ea31af695ae56ebd0fcf7 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2013-2022, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -22,7 +22,7 @@ BL32_SOURCES          +=      bl32/tsp/aarch64/tsp_entrypoint.S       \
                                common/aarch64/early_exceptions.S       \
                                lib/locks/exclusive/aarch64/spinlock.S
 
-BL32_LINKERFILE                :=      bl32/tsp/tsp.ld.S
+BL32_DEFAULT_LINKER_SCRIPT_SOURCE := bl32/tsp/tsp.ld.S
 
 # This flag determines if the TSPD initializes BL32 in tspd_init() (synchronous
 # method) or configures BL31 to pass control to BL32 instead of BL33
index 426e344941d996c2d3f3638779a8eac5ccba3676..d86720e61d1b42f46e18df93b8b7c0cab1f478a5 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -97,12 +97,6 @@ $(if $(word $(2), $($(1))),\
 )
 endef
 
-# IMG_LINKERFILE defines the linker script corresponding to a BL stage
-#   $(1) = BL stage
-define IMG_LINKERFILE
-    ${BUILD_DIR}/$(1).ld
-endef
-
 # IMG_MAPFILE defines the output file describing the memory map corresponding
 # to a BL stage
 #   $(1) = BL stage
@@ -457,6 +451,15 @@ ${LIB_DIR}/lib$(1).a: $(OBJS)
        $$(Q)$$(AR) cr $$@ $$?
 endef
 
+# Generate the path to one or more preprocessed linker scripts given the paths
+# of their sources.
+#
+# Arguments:
+#   $(1) = path to one or more linker script sources
+define linker_script_path
+        $(patsubst %.S,$(BUILD_DIR)/%,$(1))
+endef
+
 # MAKE_BL macro defines the targets and options to build each BL image.
 # Arguments:
 #   $(1) = BL stage
@@ -468,17 +471,19 @@ define MAKE_BL
         $(eval BL_SOURCES := $($(call uppercase,$(1))_SOURCES))
         $(eval SOURCES    := $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))
         $(eval OBJS       := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
-        $(eval LINKERFILE := $(call IMG_LINKERFILE,$(1)))
         $(eval MAPFILE    := $(call IMG_MAPFILE,$(1)))
         $(eval ELF        := $(call IMG_ELF,$(1)))
         $(eval DUMP       := $(call IMG_DUMP,$(1)))
         $(eval BIN        := $(call IMG_BIN,$(1)))
         $(eval ENC_BIN    := $(call IMG_ENC_BIN,$(1)))
-        $(eval BL_LINKERFILE := $($(call uppercase,$(1))_LINKERFILE))
         $(eval BL_LIBS    := $($(call uppercase,$(1))_LIBS))
+
+        $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(call uppercase,$(1))_DEFAULT_LINKER_SCRIPT_SOURCE))
+        $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE)))
+
         # We use sort only to get a list of unique object directory names.
         # ordering is not relevant but sort removes duplicates.
-        $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${LINKERFILE})))
+        $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${DEFAULT_LINKER_SCRIPT})))
         # The $(dir ) function leaves a trailing / on the directory names
         # Rip off the / to match directory names with make rule targets.
         $(eval OBJ_DIRS   := $(patsubst %/,%,$(TEMP_OBJ_DIRS)))
@@ -487,7 +492,8 @@ define MAKE_BL
 
 $(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
 
-$(eval $(foreach objd,${OBJ_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
+$(eval $(foreach objd,${OBJ_DIRS},
+        $(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
 
 .PHONY : ${1}_dirs
 
@@ -496,7 +502,7 @@ $(eval $(foreach objd,${OBJ_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
 ${1}_dirs: | ${OBJ_DIRS}
 
 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
-$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1)))
+$(eval $(call MAKE_LD,$(DEFAULT_LINKER_SCRIPT),$(DEFAULT_LINKER_SCRIPT_SOURCE),$(1)))
 $(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS))
 
 ifeq ($(USE_ROMLIB),1)
@@ -507,7 +513,7 @@ endif
 # object file path, and prebuilt object file path.
 $(eval OBJS += $(MODULE_OBJS))
 
-$(ELF): $(OBJS) $(LINKERFILE) | $(1)_dirs libraries $(BL_LIBS)
+$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) | $(1)_dirs libraries $(BL_LIBS)
        $$(ECHO) "  LD      $$@"
 ifdef MAKE_BUILD_STRINGS
        $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o)
@@ -526,11 +532,11 @@ ifneq ($(findstring armlink,$(notdir $(LD))),)
                $(BUILD_DIR)/build_message.o $(OBJS)
 else ifneq ($(findstring gcc,$(notdir $(LD))),)
        $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Wl,-Map=$(MAPFILE) \
-               -Wl,-dT $(LINKERFILE) $(EXTRA_LINKERFILE) $(BUILD_DIR)/build_message.o \
+               $(EXTRA_LINKERFILE) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) $(BUILD_DIR)/build_message.o \
                $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
 else
        $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
-               --script $(LINKERFILE) $(BUILD_DIR)/build_message.o \
+               --script $(DEFAULT_LINKER_SCRIPT) $(BUILD_DIR)/build_message.o \
                $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
 endif
 ifeq ($(DISABLE_BIN_GENERATION),1)
index 160e98f12a0f7c074ac337771cdc5d6e837bb20b..752ab419d2e8d3cecfa4c902d48cb63bbb91c244 100644 (file)
@@ -21,7 +21,7 @@ MV_DDR_INCLUDES               :=      -I$(CURDIR)/include                             \
                                -I$(CURDIR)/include/lib/libc                    \
                                -I$(CURDIR)/include/lib/libc/aarch64
 
-BLE_LINKERFILE         :=      $(BLE_PATH)/ble.ld.S
+BLE_DEFAULT_LINKER_SCRIPT_SOURCE := $(BLE_PATH)/ble.ld.S
 
 BLE_OBJS := $(addprefix $(BUILD_PLAT)/ble/,$(call SOURCES_TO_OBJS,$(BLE_SOURCES)))
 $(BLE_OBJS): PLAT_INCLUDES += -I$(MV_DDR_PATH)
diff --git a/services/std_svc/rmmd/trp/linker.ld.S b/services/std_svc/rmmd/trp/linker.ld.S
new file mode 100644 (file)
index 0000000..9895cf9
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <common/bl_common.ld.h>
+#include <lib/xlat_tables/xlat_tables_defs.h>
+
+/* Mapped using 4K pages, requires us to align different sections with
+ * different property at the same granularity. */
+PAGE_SIZE_4K = 4096;
+
+OUTPUT_FORMAT("elf64-littleaarch64")
+OUTPUT_ARCH(aarch64)
+ENTRY(trp_head)
+
+MEMORY {
+       RAM (rwx): ORIGIN = RMM_BASE, LENGTH = RMM_LIMIT - RMM_BASE
+}
+
+
+SECTIONS
+{
+       . = RMM_BASE;
+
+       .text : {
+               *(.head.text)
+               . = ALIGN(8);
+               *(.text*)
+       } >RAM
+
+       . = ALIGN(PAGE_SIZE_4K);
+
+       .rodata : {
+               *(.rodata*)
+       } >RAM
+
+       . = ALIGN(PAGE_SIZE_4K);
+
+        __RW_START__ = . ;
+
+       .data : {
+               *(.data*)
+       } >RAM
+
+       .bss (NOLOAD) : {
+               __BSS_START__ = .;
+               *(.bss*)
+               __BSS_END__ = .;
+       } >RAM
+       __BSS_SIZE__ = SIZEOF(.bss);
+
+
+       STACK_SECTION >RAM
+
+
+       /*
+       * Define a linker symbol to mark the end of the RW memory area for this
+       * image.
+       */
+       __RW_END__ = .;
+       __RMM_END__ = .;
+
+
+       /DISCARD/ : { *(.dynstr*) }
+       /DISCARD/ : { *(.dynamic*) }
+       /DISCARD/ : { *(.plt*) }
+       /DISCARD/ : { *(.interp*) }
+       /DISCARD/ : { *(.gnu*) }
+       /DISCARD/ : { *(.note*) }
+}
diff --git a/services/std_svc/rmmd/trp/linker.lds b/services/std_svc/rmmd/trp/linker.lds
deleted file mode 100644 (file)
index 2b7f383..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * (C) COPYRIGHT 2021 Arm Limited or its affiliates.
- * ALL RIGHTS RESERVED
- */
-
-#include <common/bl_common.ld.h>
-#include <lib/xlat_tables/xlat_tables_defs.h>
-
-/* Mapped using 4K pages, requires us to align different sections with
- * different property at the same granularity. */
-PAGE_SIZE_4K = 4096;
-
-OUTPUT_FORMAT("elf64-littleaarch64")
-OUTPUT_ARCH(aarch64)
-ENTRY(trp_head)
-
-MEMORY {
-       RAM (rwx): ORIGIN = RMM_BASE, LENGTH = RMM_LIMIT - RMM_BASE
-}
-
-
-SECTIONS
-{
-       . = RMM_BASE;
-
-       .text : {
-               *(.head.text)
-               . = ALIGN(8);
-               *(.text*)
-       } >RAM
-
-       . = ALIGN(PAGE_SIZE_4K);
-
-       .rodata : {
-               *(.rodata*)
-       } >RAM
-
-       . = ALIGN(PAGE_SIZE_4K);
-
-        __RW_START__ = . ;
-
-       .data : {
-               *(.data*)
-       } >RAM
-
-       .bss (NOLOAD) : {
-               __BSS_START__ = .;
-               *(.bss*)
-               __BSS_END__ = .;
-       } >RAM
-       __BSS_SIZE__ = SIZEOF(.bss);
-
-
-       STACK_SECTION >RAM
-
-
-       /*
-       * Define a linker symbol to mark the end of the RW memory area for this
-       * image.
-       */
-       __RW_END__ = .;
-       __RMM_END__ = .;
-
-
-       /DISCARD/ : { *(.dynstr*) }
-       /DISCARD/ : { *(.dynamic*) }
-       /DISCARD/ : { *(.plt*) }
-       /DISCARD/ : { *(.interp*) }
-       /DISCARD/ : { *(.gnu*) }
-       /DISCARD/ : { *(.note*) }
-}
index 44bbf226fa7c3a67325c1735985ef406071dca38..e511bf5d147e7e51cd0fbc4bbe6e38b62d811477 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2021-2022 Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2021-2023 Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -8,7 +8,7 @@ RMM_SOURCES             +=      services/std_svc/rmmd/trp/trp_entry.S \
                                services/std_svc/rmmd/trp/trp_main.c  \
                                services/std_svc/rmmd/trp/trp_helpers.c
 
-RMM_LINKERFILE         :=      services/std_svc/rmmd/trp/linker.lds
+RMM_DEFAULT_LINKER_SCRIPT_SOURCE := services/std_svc/rmmd/trp/linker.ld.S
 
 # Include the platform-specific TRP Makefile
 # If no platform-specific TRP Makefile exists, it means TRP is not supported