efi_loader: Rename sections to allow for implicit data

Some times gcc may generate data that is then used within code that may
be part of an efi runtime section. That data could be jump tables,
constants or strings.

In order to make sure we catch these, we need to ensure that gcc emits
them into a section that we can relocate together with all the other
efi runtime bits. This only works if the -ffunction-sections and
-fdata-sections flags are passed and the efi runtime functions are
in a section that starts with ".text".

Up to now we had all efi runtime bits in sections that did not
interfere with the normal section naming scheme, but this forces
us to do so. Hence we need to move the efi_loader text/data/rodata
sections before the global *(.text*) catch-all section.

With this patch in place, we should hopefully have an easier time
to extend the efi runtime functionality in the future.

Signed-off-by: Alexander Graf <agraf@suse.de>
[agraf: Fix x86_64 breakage]
lime2-spi
Alexander Graf 7 years ago
parent 416e07e2cf
commit 7e21fbca26
  1. 4
      arch/arm/config.mk
  2. 24
      arch/arm/cpu/armv8/u-boot.lds
  3. 36
      arch/arm/cpu/u-boot.lds
  4. 36
      arch/arm/mach-zynq/u-boot.lds
  5. 26
      arch/riscv/cpu/ax25/u-boot.lds
  6. 3
      arch/sandbox/config.mk
  7. 9
      arch/sandbox/cpu/u-boot.lds
  8. 2
      arch/x86/config.mk
  9. 2
      arch/x86/cpu/start.S
  10. 2
      arch/x86/cpu/start64.S
  11. 3
      arch/x86/cpu/u-boot-64.lds
  12. 34
      arch/x86/cpu/u-boot.lds
  13. 17
      board/qualcomm/dragonboard410c/u-boot.lds
  14. 24
      board/qualcomm/dragonboard820c/u-boot.lds
  15. 36
      board/ti/am335x/u-boot.lds
  16. 4
      include/efi_loader.h

@ -134,11 +134,11 @@ endif
ifdef CONFIG_ARM64 ifdef CONFIG_ARM64
OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .data \ OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .data \
-j .u_boot_list -j .rela.dyn -j .got -j .got.plt \ -j .u_boot_list -j .rela.dyn -j .got -j .got.plt \
-j .binman_sym_table -j .binman_sym_table -j .text_rest
else else
OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \ OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \
-j .data -j .got -j .got.plt -j .u_boot_list -j .rel.dyn \ -j .data -j .got -j .got.plt -j .u_boot_list -j .rel.dyn \
-j .binman_sym_table -j .binman_sym_table -j .text_rest
endif endif
# if a dtb section exists we always have to include it # if a dtb section exists we always have to include it

@ -25,6 +25,19 @@ SECTIONS
{ {
*(.__image_copy_start) *(.__image_copy_start)
CPUDIR/start.o (.text*) CPUDIR/start.o (.text*)
}
/* This needs to come before *(.text*) */
.efi_runtime : {
__efi_runtime_start = .;
*(.text.efi_runtime*)
*(.rodata.efi_runtime*)
*(.data.efi_runtime*)
__efi_runtime_stop = .;
}
.text_rest :
{
*(.text*) *(.text*)
} }
@ -98,17 +111,10 @@ SECTIONS
. = ALIGN(8); . = ALIGN(8);
.efi_runtime : {
__efi_runtime_start = .;
*(efi_runtime_text)
*(efi_runtime_data)
__efi_runtime_stop = .;
}
.efi_runtime_rel : { .efi_runtime_rel : {
__efi_runtime_rel_start = .; __efi_runtime_rel_start = .;
*(.relaefi_runtime_text) *(.rel*.efi_runtime)
*(.relaefi_runtime_data) *(.rel*.efi_runtime.*)
__efi_runtime_rel_stop = .; __efi_runtime_rel_stop = .;
} }

@ -43,6 +43,25 @@ SECTIONS
*(.__image_copy_start) *(.__image_copy_start)
*(.vectors) *(.vectors)
CPUDIR/start.o (.text*) CPUDIR/start.o (.text*)
}
/* This needs to come before *(.text*) */
.__efi_runtime_start : {
*(.__efi_runtime_start)
}
.efi_runtime : {
*(.text.efi_runtime*)
*(.rodata.efi_runtime*)
*(.data.efi_runtime*)
}
.__efi_runtime_stop : {
*(.__efi_runtime_stop)
}
.text_rest :
{
*(.text*) *(.text*)
} }
@ -136,27 +155,14 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
.__efi_runtime_start : {
*(.__efi_runtime_start)
}
.efi_runtime : {
*(efi_runtime_text)
*(efi_runtime_data)
}
.__efi_runtime_stop : {
*(.__efi_runtime_stop)
}
.efi_runtime_rel_start : .efi_runtime_rel_start :
{ {
*(.__efi_runtime_rel_start) *(.__efi_runtime_rel_start)
} }
.efi_runtime_rel : { .efi_runtime_rel : {
*(.relefi_runtime_text) *(.rel*.efi_runtime)
*(.relefi_runtime_data) *(.rel*.efi_runtime.*)
} }
.efi_runtime_rel_stop : .efi_runtime_rel_stop :

@ -19,6 +19,25 @@ SECTIONS
*(.__image_copy_start) *(.__image_copy_start)
*(.vectors) *(.vectors)
CPUDIR/start.o (.text*) CPUDIR/start.o (.text*)
}
/* This needs to come before *(.text*) */
.__efi_runtime_start : {
*(.__efi_runtime_start)
}
.efi_runtime : {
*(.text.efi_runtime*)
*(.rodata.efi_runtime*)
*(.data.efi_runtime*)
}
.__efi_runtime_stop : {
*(.__efi_runtime_stop)
}
.text_rest :
{
*(.text*) *(.text*)
} }
@ -41,27 +60,14 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
.__efi_runtime_start : {
*(.__efi_runtime_start)
}
.efi_runtime : {
*(efi_runtime_text)
*(efi_runtime_data)
}
.__efi_runtime_stop : {
*(.__efi_runtime_stop)
}
.efi_runtime_rel_start : .efi_runtime_rel_start :
{ {
*(.__efi_runtime_rel_start) *(.__efi_runtime_rel_start)
} }
.efi_runtime_rel : { .efi_runtime_rel : {
*(.relefi_runtime_text) *(.rel*.efi_runtime)
*(.relefi_runtime_data) *(.rel*.efi_runtime.*)
} }
.efi_runtime_rel_stop : .efi_runtime_rel_stop :

@ -12,7 +12,20 @@ SECTIONS
.text : .text :
{ {
arch/riscv/cpu/ax25/start.o (.text) arch/riscv/cpu/ax25/start.o (.text)
*(.text) }
/* This needs to come before *(.text*) */
.efi_runtime : {
__efi_runtime_start = .;
*(.text.efi_runtime*)
*(.rodata.efi_runtime*)
*(.data.efi_runtime*)
__efi_runtime_stop = .;
}
.text_rest :
{
*(.text*)
} }
. = ALIGN(4); . = ALIGN(4);
@ -39,17 +52,10 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
.efi_runtime : {
__efi_runtime_start = .;
*(efi_runtime_text)
*(efi_runtime_data)
__efi_runtime_stop = .;
}
.efi_runtime_rel : { .efi_runtime_rel : {
__efi_runtime_rel_start = .; __efi_runtime_rel_start = .;
*(.relaefi_runtime_text) *(.rel*.efi_runtime)
*(.relaefi_runtime_data) *(.rel*.efi_runtime.*)
__efi_runtime_rel_stop = .; __efi_runtime_rel_stop = .;
} }

@ -5,6 +5,9 @@ PLATFORM_CPPFLAGS += -D__SANDBOX__ -U_FORTIFY_SOURCE
PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM
PLATFORM_LIBS += -lrt PLATFORM_LIBS += -lrt
LDFLAGS_FINAL += --gc-sections
PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
# Define this to avoid linking with SDL, which requires SDL libraries # Define this to avoid linking with SDL, which requires SDL libraries
# This can solve 'sdl-config: Command not found' errors # This can solve 'sdl-config: Command not found' errors
ifneq ($(NO_SDL),) ifneq ($(NO_SDL),)

@ -24,8 +24,9 @@ SECTIONS
} }
.efi_runtime : { .efi_runtime : {
*(efi_runtime_text) *(.text.efi_runtime*)
*(efi_runtime_data) *(.rodata.efi_runtime*)
*(.data.efi_runtime*)
} }
.__efi_runtime_stop : { .__efi_runtime_stop : {
@ -38,8 +39,8 @@ SECTIONS
} }
.efi_runtime_rel : { .efi_runtime_rel : {
*(.relefi_runtime_text) *(.rel*.efi_runtime)
*(.relefi_runtime_data) *(.rel*.efi_runtime.*)
} }
.efi_runtime_rel_stop : .efi_runtime_rel_stop :

@ -23,6 +23,8 @@ endif
ifeq ($(IS_32BIT),y) ifeq ($(IS_32BIT),y)
PLATFORM_CPPFLAGS += -march=i386 -m32 PLATFORM_CPPFLAGS += -march=i386 -m32
# TODO: These break on x86_64; need to debug further
PLATFORM_RELFLAGS += -fdata-sections
else else
PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -m64 PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -m64
endif endif

@ -17,7 +17,7 @@
#include <generated/generic-asm-offsets.h> #include <generated/generic-asm-offsets.h>
#include <generated/asm-offsets.h> #include <generated/asm-offsets.h>
.section .text .section .text.start
.code32 .code32
.globl _start .globl _start
.type _start, @function .type _start, @function

@ -8,7 +8,7 @@
#include <config.h> #include <config.h>
.section .text .section .text.start
.code64 .code64
.globl _start .globl _start
.type _start, @function .type _start, @function

@ -17,6 +17,9 @@ SECTIONS
. = CONFIG_SYS_TEXT_BASE; /* Location of bootcode in flash */ . = CONFIG_SYS_TEXT_BASE; /* Location of bootcode in flash */
__text_start = .; __text_start = .;
.text.start : { *(.text.start); }
.text : { *(.text*); } .text : { *(.text*); }
. = ALIGN(4); . = ALIGN(4);

@ -17,6 +17,23 @@ SECTIONS
. = CONFIG_SYS_TEXT_BASE; /* Location of bootcode in flash */ . = CONFIG_SYS_TEXT_BASE; /* Location of bootcode in flash */
__text_start = .; __text_start = .;
.text.start : { *(.text.start); }
.__efi_runtime_start : {
*(.__efi_runtime_start)
}
.efi_runtime : {
*(.text.efi_runtime*)
*(.rodata.efi_runtime*)
*(.data.efi_runtime*)
}
.__efi_runtime_stop : {
*(.__efi_runtime_stop)
}
.text : { *(.text*); } .text : { *(.text*); }
. = ALIGN(4); . = ALIGN(4);
@ -43,27 +60,14 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
.__efi_runtime_start : {
*(.__efi_runtime_start)
}
.efi_runtime : {
*(efi_runtime_text)
*(efi_runtime_data)
}
.__efi_runtime_stop : {
*(.__efi_runtime_stop)
}
.efi_runtime_rel_start : .efi_runtime_rel_start :
{ {
*(.__efi_runtime_rel_start) *(.__efi_runtime_rel_start)
} }
.efi_runtime_rel : { .efi_runtime_rel : {
*(.relefi_runtime_text) *(.rel*.efi_runtime)
*(.relefi_runtime_data) *(.rel*.efi_runtime.*)
} }
.efi_runtime_rel_stop : .efi_runtime_rel_stop :

@ -20,6 +20,19 @@ SECTIONS
*(.__image_copy_start) *(.__image_copy_start)
board/qualcomm/dragonboard410c/head.o (.text*) board/qualcomm/dragonboard410c/head.o (.text*)
CPUDIR/start.o (.text*) CPUDIR/start.o (.text*)
}
/* This needs to come before *(.text*) */
.efi_runtime : {
__efi_runtime_start = .;
*(.text.efi_runtime*)
*(.rodata.efi_runtime*)
*(.data.efi_runtime*)
__efi_runtime_stop = .;
}
.text_rest :
{
*(.text*) *(.text*)
} }
@ -51,8 +64,8 @@ SECTIONS
.efi_runtime_rel : { .efi_runtime_rel : {
__efi_runtime_rel_start = .; __efi_runtime_rel_start = .;
*(.relaefi_runtime_text) *(.rel*.efi_runtime)
*(.relaefi_runtime_data) *(.rel*.efi_runtime.*)
__efi_runtime_rel_stop = .; __efi_runtime_rel_stop = .;
} }

@ -20,6 +20,19 @@ SECTIONS
*(.__image_copy_start) *(.__image_copy_start)
board/qualcomm/dragonboard820c/head.o (.text*) board/qualcomm/dragonboard820c/head.o (.text*)
CPUDIR/start.o (.text*) CPUDIR/start.o (.text*)
}
/* This needs to come before *(.text*) */
.efi_runtime : {
__efi_runtime_start = .;
*(.text.efi_runtime*)
*(.rodata.efi_runtime*)
*(.data.efi_runtime*)
__efi_runtime_stop = .;
}
.text_rest :
{
*(.text*) *(.text*)
} }
@ -42,17 +55,10 @@ SECTIONS
. = ALIGN(8); . = ALIGN(8);
.efi_runtime : {
__efi_runtime_start = .;
*(efi_runtime_text)
*(efi_runtime_data)
__efi_runtime_stop = .;
}
.efi_runtime_rel : { .efi_runtime_rel : {
__efi_runtime_rel_start = .; __efi_runtime_rel_start = .;
*(.relaefi_runtime_text) *(.rel*.efi_runtime)
*(.relaefi_runtime_data) *(.rel*.efi_runtime.*)
__efi_runtime_rel_stop = .; __efi_runtime_rel_stop = .;
} }

@ -37,6 +37,25 @@ SECTIONS
*(.vectors) *(.vectors)
CPUDIR/start.o (.text*) CPUDIR/start.o (.text*)
board/ti/am335x/built-in.o (.text*) board/ti/am335x/built-in.o (.text*)
}
/* This needs to come before *(.text*) */
.__efi_runtime_start : {
*(.__efi_runtime_start)
}
.efi_runtime : {
*(.text.efi_runtime*)
*(.rodata.efi_runtime*)
*(.data.efi_runtime*)
}
.__efi_runtime_stop : {
*(.__efi_runtime_stop)
}
.text_rest :
{
*(.text*) *(.text*)
} }
@ -59,27 +78,14 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
.__efi_runtime_start : {
*(.__efi_runtime_start)
}
.efi_runtime : {
*(efi_runtime_text)
*(efi_runtime_data)
}
.__efi_runtime_stop : {
*(.__efi_runtime_stop)
}
.efi_runtime_rel_start : .efi_runtime_rel_start :
{ {
*(.__efi_runtime_rel_start) *(.__efi_runtime_rel_start)
} }
.efi_runtime_rel : { .efi_runtime_rel : {
*(.relefi_runtime_text) *(.rel*.efi_runtime)
*(.relefi_runtime_data) *(.rel*.efi_runtime.*)
} }
.efi_runtime_rel_stop : .efi_runtime_rel_stop :

@ -406,8 +406,8 @@ static inline int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
* Use these to indicate that your code / data should go into the EFI runtime * Use these to indicate that your code / data should go into the EFI runtime
* section and thus still be available when the OS is running * section and thus still be available when the OS is running
*/ */
#define __efi_runtime_data __attribute__ ((section ("efi_runtime_data"))) #define __efi_runtime_data __attribute__ ((section (".data.efi_runtime")))
#define __efi_runtime __attribute__ ((section ("efi_runtime_text"))) #define __efi_runtime __attribute__ ((section (".text.efi_runtime")))
/* Call this with mmio_ptr as the _pointer_ to a pointer to an MMIO region /* Call this with mmio_ptr as the _pointer_ to a pointer to an MMIO region
* to make it available at runtime */ * to make it available at runtime */

Loading…
Cancel
Save