]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: Rename sections to allow for implicit data
authorAlexander Graf <agraf@suse.de>
Tue, 12 Jun 2018 05:48:37 +0000 (07:48 +0200)
committerAlexander Graf <agraf@suse.de>
Wed, 25 Jul 2018 12:57:44 +0000 (14:57 +0200)
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]

16 files changed:
arch/arm/config.mk
arch/arm/cpu/armv8/u-boot.lds
arch/arm/cpu/u-boot.lds
arch/arm/mach-zynq/u-boot.lds
arch/riscv/cpu/ax25/u-boot.lds
arch/sandbox/config.mk
arch/sandbox/cpu/u-boot.lds
arch/x86/config.mk
arch/x86/cpu/start.S
arch/x86/cpu/start64.S
arch/x86/cpu/u-boot-64.lds
arch/x86/cpu/u-boot.lds
board/qualcomm/dragonboard410c/u-boot.lds
board/qualcomm/dragonboard820c/u-boot.lds
board/ti/am335x/u-boot.lds
include/efi_loader.h

index efafc69d1b307002c80601ef0e53c9777c88c7ed..f25603109e0081d581ab703d1236a2e5660a8e5a 100644 (file)
@@ -134,11 +134,11 @@ endif
 ifdef CONFIG_ARM64
 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 .binman_sym_table
+               -j .binman_sym_table -j .text_rest
 else
 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 .binman_sym_table
+               -j .binman_sym_table -j .text_rest
 endif
 
 # if a dtb section exists we always have to include it
index eb926b3c148ef041fac6aa17f09949848b6fd7da..53de80f745ecd5e15ba158853ef59b85926d0345 100644 (file)
@@ -25,6 +25,19 @@ SECTIONS
        {
                *(.__image_copy_start)
                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*)
        }
 
@@ -98,17 +111,10 @@ SECTIONS
 
        . = ALIGN(8);
 
-       .efi_runtime : {
-                __efi_runtime_start = .;
-               *(efi_runtime_text)
-               *(efi_runtime_data)
-                __efi_runtime_stop = .;
-       }
-
        .efi_runtime_rel : {
                 __efi_runtime_rel_start = .;
-               *(.relaefi_runtime_text)
-               *(.relaefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
                 __efi_runtime_rel_stop = .;
        }
 
index 4157374d21d68689b2613e135f758a2a5e7948ce..834dc99554c90a1cbcc24432bb4c3d69e1b0e9ce 100644 (file)
@@ -43,6 +43,25 @@ SECTIONS
                *(.__image_copy_start)
                *(.vectors)
                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*)
        }
 
@@ -136,27 +155,14 @@ SECTIONS
 
        . = 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 : {
-               *(.relefi_runtime_text)
-               *(.relefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
        }
 
        .efi_runtime_rel_stop :
index ec9a0a01610497108018d0c30c2f63b8784571a4..91c32e89e8fe1d9cbaaa4663cdd4000efd0fd590 100644 (file)
@@ -19,6 +19,25 @@ SECTIONS
                *(.__image_copy_start)
                *(.vectors)
                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*)
        }
 
@@ -41,27 +60,14 @@ SECTIONS
 
        . = 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 : {
-               *(.relefi_runtime_text)
-               *(.relefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
        }
 
        .efi_runtime_rel_stop :
index 1589babf6c3e8ed45e8b164b7be0b113bd7da5bf..3cc89746b1694d638878ed42942ebe87df14ccdf 100644 (file)
@@ -12,7 +12,20 @@ SECTIONS
        .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);
@@ -39,17 +52,10 @@ SECTIONS
 
     . = ALIGN(4);
 
-       .efi_runtime : {
-                __efi_runtime_start = .;
-               *(efi_runtime_text)
-               *(efi_runtime_data)
-                __efi_runtime_stop = .;
-       }
-
        .efi_runtime_rel : {
                 __efi_runtime_rel_start = .;
-               *(.relaefi_runtime_text)
-               *(.relaefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
                 __efi_runtime_rel_stop = .;
        }
 
index 2babcde8815d3987ea4ea6c50fdb4448a61aeba6..5e7077bfe75da80ecc3f0ee901a8e963c7843789 100644 (file)
@@ -5,6 +5,9 @@ PLATFORM_CPPFLAGS += -D__SANDBOX__ -U_FORTIFY_SOURCE
 PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM
 PLATFORM_LIBS += -lrt
 
+LDFLAGS_FINAL += --gc-sections
+PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
+
 # Define this to avoid linking with SDL, which requires SDL libraries
 # This can solve 'sdl-config: Command not found' errors
 ifneq ($(NO_SDL),)
index 3a6cf55eb99d4bc56a8178b3cd1ee3b1d96c226e..727bcc3598153a94de71caaf30dd76b3746769e7 100644 (file)
@@ -24,8 +24,9 @@ SECTIONS
        }
 
        .efi_runtime : {
-               *(efi_runtime_text)
-               *(efi_runtime_data)
+               *(.text.efi_runtime*)
+               *(.rodata.efi_runtime*)
+               *(.data.efi_runtime*)
        }
 
        .__efi_runtime_stop : {
@@ -38,8 +39,8 @@ SECTIONS
        }
 
        .efi_runtime_rel : {
-               *(.relefi_runtime_text)
-               *(.relefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
        }
 
        .efi_runtime_rel_stop :
index 5f77f98e60a453676058a9726c0e357243b41689..586e11a0dda55a62c3318cdbc036318ee5881f40 100644 (file)
@@ -23,6 +23,8 @@ endif
 
 ifeq ($(IS_32BIT),y)
 PLATFORM_CPPFLAGS += -march=i386 -m32
+# TODO: These break on x86_64; need to debug further
+PLATFORM_RELFLAGS += -fdata-sections
 else
 PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -m64
 endif
index e4e997e3e88990f238e646aa098aef864aee8d0e..e1f634ffcd530c58bde0b534101d0ae82253de5a 100644 (file)
@@ -17,7 +17,7 @@
 #include <generated/generic-asm-offsets.h>
 #include <generated/asm-offsets.h>
 
-.section .text
+.section .text.start
 .code32
 .globl _start
 .type _start, @function
index 234482b793a5a2ebd40fc679b95ae80152c64441..a473fd166d3412c9af49e135034388c4e3104c5a 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <config.h>
 
-.section .text
+.section .text.start
 .code64
 .globl _start
 .type _start, @function
index 3f38681669a16bc9d74502eda95ae5cacb0220b2..9a9d39cef293af564e2306ca46dcde8b8c9cad8b 100644 (file)
@@ -17,6 +17,9 @@ SECTIONS
 
        . = CONFIG_SYS_TEXT_BASE;       /* Location of bootcode in flash */
        __text_start = .;
+
+       .text.start : { *(.text.start); }
+
        .text  : { *(.text*); }
 
        . = ALIGN(4);
index f0719368ba652eee4316c239906dffb175c1d4c7..a1cc19ce4cb950efc3ac1dc11554deac66d37f57 100644 (file)
@@ -17,6 +17,23 @@ SECTIONS
 
        . = CONFIG_SYS_TEXT_BASE;       /* Location of bootcode in flash */
        __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*); }
 
        . = ALIGN(4);
@@ -43,27 +60,14 @@ SECTIONS
 
        . = 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 : {
-               *(.relefi_runtime_text)
-               *(.relefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
        }
 
        .efi_runtime_rel_stop :
index dc3f718b0565714b1762dabca260e194cc0f658f..fc1bba8cf08854b5e2be1ed3e2dc66f7b869bc27 100644 (file)
@@ -20,6 +20,19 @@ SECTIONS
                *(.__image_copy_start)
                board/qualcomm/dragonboard410c/head.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*)
        }
 
@@ -51,8 +64,8 @@ SECTIONS
 
        .efi_runtime_rel : {
                 __efi_runtime_rel_start = .;
-               *(.relaefi_runtime_text)
-               *(.relaefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
                 __efi_runtime_rel_stop = .;
        }
 
index bcf5738d387f1f0b958bf819815b1b2f523cb6bf..dcf8256cec38fb7423afb260a88a756207df735f 100644 (file)
@@ -20,6 +20,19 @@ SECTIONS
                *(.__image_copy_start)
                board/qualcomm/dragonboard820c/head.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*)
        }
 
@@ -42,17 +55,10 @@ SECTIONS
 
        . = ALIGN(8);
 
-       .efi_runtime : {
-                __efi_runtime_start = .;
-               *(efi_runtime_text)
-               *(efi_runtime_data)
-                __efi_runtime_stop = .;
-       }
-
        .efi_runtime_rel : {
                 __efi_runtime_rel_start = .;
-               *(.relaefi_runtime_text)
-               *(.relaefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
                 __efi_runtime_rel_stop = .;
        }
 
index a56cc8216bfcf69f441eb2753789a7a57b08300e..03c1d5f73b3dc81445554ec62e2af69fe03e6446 100644 (file)
@@ -37,6 +37,25 @@ SECTIONS
                *(.vectors)
                CPUDIR/start.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*)
        }
 
@@ -59,27 +78,14 @@ SECTIONS
 
        . = 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 : {
-               *(.relefi_runtime_text)
-               *(.relefi_runtime_data)
+               *(.rel*.efi_runtime)
+               *(.rel*.efi_runtime.*)
        }
 
        .efi_runtime_rel_stop :
index d837e7b157fda8167b1889e9ef9079f9ce2c877d..a0495db2918ab5241b3a34ea03efd1540aa6b1cc 100644 (file)
@@ -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
  * section and thus still be available when the OS is running
  */
-#define __efi_runtime_data __attribute__ ((section ("efi_runtime_data")))
-#define __efi_runtime __attribute__ ((section ("efi_runtime_text")))
+#define __efi_runtime_data __attribute__ ((section (".data.efi_runtime")))
+#define __efi_runtime __attribute__ ((section (".text.efi_runtime")))
 
 /* Call this with mmio_ptr as the _pointer_ to a pointer to an MMIO region
  * to make it available at runtime */