summaryrefslogtreecommitdiff
path: root/BaseTools
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2015-07-02 06:36:00 +0000
committerabiesheuvel <abiesheuvel@Edk2>2015-07-02 06:36:00 +0000
commitf0dbe9fa0a437fe27210718c2f1d575b99e26583 (patch)
treefc0547c335024339a80e6edd0e81db2caa745a75 /BaseTools
parentd77cc2063de7be8a1b28ef2efb5770df4578975a (diff)
downloadedk2-platforms-f0dbe9fa0a437fe27210718c2f1d575b99e26583.tar.xz
BaseTools: AArch64: use explicit linker scripts
Instead of relying on the builtin linker script of GNU ld, which may vary based on binutils version (which is not tightly coupled to the GCC version) and linker command line options, introduce a linker script for AArch64 to be used by all GCC/binutils versions. The script is laid out such that two ELF sections .text and .data are created that map onto the PE/COFF with the same names. By aligning .data to the minimum alignment of .text, and by not adding any additional padding -which is what LD's builtin linker script does- the relative offset between .text and .data is retained after the PE/COFF conversion. This should prevent problems with debuggers and other tooling that are ELF based. Also provided is an overlay linker script that increases the alignment of .text and .data to 64 KB. This is intended for DXE_RUNTIME_DRIVER modules, to make them compatible with the newly introduced Properties Table feature. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17802 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools')
-rw-r--r--BaseTools/Conf/tools_def.template23
-rw-r--r--BaseTools/Scripts/gcc-aarch64-64K-align-ld-script4
-rw-r--r--BaseTools/Scripts/gcc-aarch64-ld-script39
3 files changed, 56 insertions, 10 deletions
diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 88ec2e138d..7edd759095 100644
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -3821,9 +3821,12 @@ DEFINE GCC_ARM_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mword-relocations -m
DEFINE GCC_AARCH64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mcmodel=large -mlittle-endian -fno-short-enums -save-temps -fverbose-asm -fsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-builtin -Wno-address
DEFINE GCC_DLINK_FLAGS_COMMON = -nostdlib --pie
DEFINE GCC_IA32_X64_DLINK_COMMON = DEF(GCC_DLINK_FLAGS_COMMON) --gc-sections
-DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Ttext=0x0 --emit-relocs -nostdlib --gc-sections -u $(IMAGE_ENTRY_POINT) -e $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
+DEFINE GCC_ARM_AARCH64_DLINK_COMMON= --emit-relocs -nostdlib --gc-sections -u $(IMAGE_ENTRY_POINT) -e $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
+DEFINE GCC_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -Ttext=0x0
+DEFINE GCC_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) --script=$(EDK_TOOLS_PATH)/Scripts/gcc-aarch64-ld-script
DEFINE GCC_IA32_X64_ASLDLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
-DEFINE GCC_ARM_AARCH64_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) --entry ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
+DEFINE GCC_ARM_ASLDLINK_FLAGS = DEF(GCC_ARM_DLINK_FLAGS) --entry ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
+DEFINE GCC_AARCH64_ASLDLINK_FLAGS = DEF(GCC_AARCH64_DLINK_FLAGS) --entry ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
DEFINE GCC_IA32_X64_DLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _$(IMAGE_ENTRY_POINT) --file-alignment 0x20 --section-alignment 0x20 -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_IPF_DLINK_FLAGS = -nostdlib -O2 --gc-sections --dll -static --entry $(IMAGE_ENTRY_POINT) --undefined $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_IPF_OBJCOPY_FLAGS = -I elf64-ia64-little -O efi-bsdrv-ia64
@@ -3866,8 +3869,8 @@ DEFINE GCC46_X64_DLINK_FLAGS = DEF(GCC45_X64_DLINK_FLAGS)
DEFINE GCC46_ASM_FLAGS = DEF(GCC45_ASM_FLAGS)
DEFINE GCC46_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ASM_FLAGS) -mlittle-endian
DEFINE GCC46_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC44_ALL_CC_FLAGS) DEF(GCC_ARM_CC_FLAGS) -fstack-protector
-DEFINE GCC46_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) --oformat=elf32-littlearm
-DEFINE GCC46_ARM_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS) --oformat=elf32-littlearm
+DEFINE GCC46_ARM_DLINK_FLAGS = DEF(GCC_ARM_DLINK_FLAGS) --oformat=elf32-littlearm
+DEFINE GCC46_ARM_ASLDLINK_FLAGS = DEF(GCC_ARM_ASLDLINK_FLAGS) --oformat=elf32-littlearm
DEFINE GCC47_IA32_CC_FLAGS = DEF(GCC46_IA32_CC_FLAGS)
DEFINE GCC47_X64_CC_FLAGS = DEF(GCC46_X64_CC_FLAGS)
@@ -3881,9 +3884,9 @@ DEFINE GCC47_AARCH64_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) DEF(GC
DEFINE GCC47_ARM_CC_FLAGS = DEF(GCC46_ARM_CC_FLAGS) -mno-unaligned-access
DEFINE GCC47_AARCH64_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC44_ALL_CC_FLAGS) DEF(GCC_AARCH64_CC_FLAGS)
DEFINE GCC47_ARM_DLINK_FLAGS = DEF(GCC46_ARM_DLINK_FLAGS)
-DEFINE GCC47_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON)
+DEFINE GCC47_AARCH64_DLINK_FLAGS = DEF(GCC_AARCH64_DLINK_FLAGS)
DEFINE GCC47_ARM_ASLDLINK_FLAGS = DEF(GCC46_ARM_ASLDLINK_FLAGS)
-DEFINE GCC47_AARCH64_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS)
+DEFINE GCC47_AARCH64_ASLDLINK_FLAGS = DEF(GCC_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC47_IA32_CC_FLAGS)
DEFINE GCC48_X64_CC_FLAGS = DEF(GCC47_X64_CC_FLAGS)
@@ -3897,9 +3900,9 @@ DEFINE GCC48_AARCH64_ASM_FLAGS = DEF(GCC47_AARCH64_ASM_FLAGS)
DEFINE GCC48_ARM_CC_FLAGS = DEF(GCC47_ARM_CC_FLAGS)
DEFINE GCC48_AARCH64_CC_FLAGS = DEF(GCC47_AARCH64_CC_FLAGS)
DEFINE GCC48_ARM_DLINK_FLAGS = DEF(GCC47_ARM_DLINK_FLAGS)
-DEFINE GCC48_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON)
+DEFINE GCC48_AARCH64_DLINK_FLAGS = DEF(GCC47_AARCH64_DLINK_FLAGS)
DEFINE GCC48_ARM_ASLDLINK_FLAGS = DEF(GCC47_ARM_ASLDLINK_FLAGS)
-DEFINE GCC48_AARCH64_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS)
+DEFINE GCC48_AARCH64_ASLDLINK_FLAGS = DEF(GCC47_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC49_IA32_CC_FLAGS = DEF(GCC48_IA32_CC_FLAGS)
DEFINE GCC49_X64_CC_FLAGS = DEF(GCC48_X64_CC_FLAGS)
@@ -3913,9 +3916,9 @@ DEFINE GCC49_AARCH64_ASM_FLAGS = DEF(GCC48_AARCH64_ASM_FLAGS)
DEFINE GCC49_ARM_CC_FLAGS = DEF(GCC48_ARM_CC_FLAGS)
DEFINE GCC49_AARCH64_CC_FLAGS = DEF(GCC48_AARCH64_CC_FLAGS)
DEFINE GCC49_ARM_DLINK_FLAGS = DEF(GCC48_ARM_DLINK_FLAGS)
-DEFINE GCC49_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON)
+DEFINE GCC49_AARCH64_DLINK_FLAGS = DEF(GCC48_AARCH64_DLINK_FLAGS)
DEFINE GCC49_ARM_ASLDLINK_FLAGS = DEF(GCC48_ARM_ASLDLINK_FLAGS)
-DEFINE GCC49_AARCH64_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS)
+DEFINE GCC49_AARCH64_ASLDLINK_FLAGS = DEF(GCC48_AARCH64_ASLDLINK_FLAGS)
####################################################################################
#
diff --git a/BaseTools/Scripts/gcc-aarch64-64K-align-ld-script b/BaseTools/Scripts/gcc-aarch64-64K-align-ld-script
new file mode 100644
index 0000000000..8aa4c5f08c
--- /dev/null
+++ b/BaseTools/Scripts/gcc-aarch64-64K-align-ld-script
@@ -0,0 +1,4 @@
+SECTIONS {
+ .text : ALIGN(0x10000) { }
+ .data : ALIGN(0x10000) { }
+}
diff --git a/BaseTools/Scripts/gcc-aarch64-ld-script b/BaseTools/Scripts/gcc-aarch64-ld-script
new file mode 100644
index 0000000000..29095c268e
--- /dev/null
+++ b/BaseTools/Scripts/gcc-aarch64-ld-script
@@ -0,0 +1,39 @@
+SECTIONS {
+ /*
+ * Put the .text section at 0x0 explicitly. While we know it will minimally
+ * end up at 0x280, (the size of the PE/COFF headers being 0x250 bytes and the
+ * minimum alignment 0x40), choosing 0x280 as the offset causes problems when
+ * linking objects with a greater .text alignment, since the section's base
+ * must adhere to its own alignment.
+ * Using 0x0 will result in the PE/COFF binary's memory layout to be shifted
+ * with respect to the ELF version, but this shouldn't be a problem as long as
+ * the .data's offset relative to .text is kept the same.
+ */
+ .text 0x0 : ALIGN(0x40) {
+ *(.text .text.* .rodata .rodata.*)
+ }
+
+ /*
+ * The alignment of the .data section needs to be less than or equal to the
+ * alignment of the .text section. This ensures that the relative offset
+ * between these sections is the same in the ELF and the PE/COFF version of
+ * this binary.
+ */
+ .data : ALIGN(0x40) {
+ *(.data .data.*)
+ *(.bss .bss.* *COM*)
+ }
+ .rela ALIGN(0x20) : {
+ *(.rela .rela.*)
+ }
+
+ /DISCARD/ : {
+ *(.note.GNU-stack)
+ *(.interp)
+ *(.dynsym)
+ *(.dynstr)
+ *(.dynamic)
+ *(.hash)
+ *(.comment)
+ }
+}