From 62635c74b9771c0866301b8035a9559be904403d Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sat, 14 Dec 2013 05:14:43 -0800 Subject: [PATCH] ARM: Define custom ELF headers for ARM. At least when building with the gnu toolchain, the headers the linker automatically generate save space for the actual ELF headers in one of the loadable segments. This creates two problems. First, the data you intended to be at the start of the image doesn't actually show up there, it's actually the ELF headers. Second, the ELF headers are essentially useless for firmware since there's currently nothing to tell you where they are, and even if there was, there isn't much of a reason to look at them. They're useful in userspace for, for instance, the dynamic linker, but not really in firmware. This change adds a PHDRS construct to each of the linker scripts used on ARM which define a single segment called to_load which does not have the flag set which would tell the linker to put headers in it. The first section defined in the script has ": to_load" to tell the linker which segment to put it in, and from that point on the other sections go in there by default. BUG=None TEST=Built and booted on nyan. Verified that the ROM stage was less than 18KB. Reverted the change which forced ROM stage alignment and saw that the ROM stage stayed the same size. BRANCH=None Change-Id: Ie2670f33f0421b16b2d4663fbfa99358890c77e4 Signed-off-by: Gabe Black Reviewed-on: https://chromium-review.googlesource.com/180163 Reviewed-by: Hung-Te Lin Reviewed-by: Tom Warren Reviewed-by: Stefan Reinauer Commit-Queue: Gabe Black Tested-by: Gabe Black --- src/arch/arm/bootblock.ld | 7 ++++++- src/arch/arm/coreboot_ram.ld | 7 ++++++- src/arch/arm/romstage.ld | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/arch/arm/bootblock.ld b/src/arch/arm/bootblock.ld index 9fc330b716..624665d60a 100644 --- a/src/arch/arm/bootblock.ld +++ b/src/arch/arm/bootblock.ld @@ -23,6 +23,11 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm) INCLUDE ldoptions +PHDRS +{ + to_load PT_LOAD; +} + ENTRY(_start) TARGET(binary) SECTIONS @@ -42,7 +47,7 @@ SECTIONS *(.bss.*); *(.sbss); *(.sbss.*); - } = 0xff + } : to_load = 0xff /DISCARD/ : { *(.comment) diff --git a/src/arch/arm/coreboot_ram.ld b/src/arch/arm/coreboot_ram.ld index d7a6269f6a..ba5200aa08 100644 --- a/src/arch/arm/coreboot_ram.ld +++ b/src/arch/arm/coreboot_ram.ld @@ -22,6 +22,11 @@ /* We use ELF as output format. So that we can debug the code in some form. */ INCLUDE ldoptions +PHDRS +{ + to_load PT_LOAD; +} + ENTRY(stage_entry) SECTIONS @@ -38,7 +43,7 @@ SECTIONS *(.text.*); . = ALIGN(16); _etext = .; - } + } : to_load .ctors : { . = ALIGN(0x100); diff --git a/src/arch/arm/romstage.ld b/src/arch/arm/romstage.ld index e1b09c032e..a723fe6008 100644 --- a/src/arch/arm/romstage.ld +++ b/src/arch/arm/romstage.ld @@ -29,6 +29,11 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm) INCLUDE ldoptions +PHDRS +{ + to_load PT_LOAD; +} + ENTRY(stage_entry) SECTIONS @@ -41,7 +46,7 @@ SECTIONS *(.text.startup); *(.text); *(.text.*); - } + } : to_load .romdata . : { *(.rodata);