Forráskód Böngészése

Merge /u/gmbr3/gnu-efi/ branch ia32 into master

https://sourceforge.net/p/gnu-efi/code/merge-requests/51/
b'Nigel Croxon 1 éve
szülő
commit
9835e11ebe

+ 3 - 3
Make.defaults

@@ -125,9 +125,9 @@ ifeq ($(ARCH),x86_64)
                                  && [ $(GCCMINOR) -ge "7" ] ) ) \
                           && echo 1)
   ifeq ($(GCCNEWENOUGH),1)
-    CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args --std=c11
+    CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args -std=c11
   else ifeq ($(USING_CLANG),clang)
-    CPPFLAGS += -DGNU_EFI_USE_MS_ABI --std=c11
+    CPPFLAGS += -DGNU_EFI_USE_MS_ABI -std=c11
   endif
 
   CFLAGS += -mno-red-zone
@@ -197,7 +197,7 @@ endif
 ARFLAGS := rDv
 ASFLAGS += $(ARCH3264)
 LDFLAGS	+= -nostdlib --warn-common --no-undefined --fatal-warnings \
-	   --build-id=sha1
+	   --build-id=sha1 -z nocombreloc
 
 ifneq ($(ARCH),arm)
 export LIBGCC=$(shell $(CC) $(CFLAGS) $(ARCH3264) -print-libgcc-file-name)

+ 2 - 0
Make.rules

@@ -34,6 +34,8 @@
 #    SUCH DAMAGE.
 #
 
+.SECONDARY:
+
 %.efi: %.so
 	$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
 		    -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \

+ 1 - 1
apps/Makefile

@@ -64,7 +64,7 @@ TARGET_APPS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi \
 	      route80h.efi drv0_use.efi AllocPages.efi exit.efi \
 	      FreePages.efi setjmp.efi debughook.efi debughook.efi.debug \
 	      bltgrid.efi lfbgrid.efi setdbg.efi unsetdbg.efi \
-	      ctors_test.efi
+	      ctors_test.efi ctors_dtors_priority_test.efi
 TARGET_BSDRIVERS = drv0.efi
 TARGET_RTDRIVERS =
 

+ 29 - 0
apps/ctors_dtors_priority_test.c

@@ -0,0 +1,29 @@
+#include <efi.h>
+#include <efilib.h>
+
+// 101 in init_array, 65434 in ctors
+static void __attribute__((constructor(101))) ctors101() {
+    Print(L"1) ctor with lower numbered priority \r\n");
+}
+
+// 65434 in init_array, 101 in ctors
+static void __attribute__((constructor(65434))) ctors65434() {
+    Print(L"2) ctor with higher numbered priority \r\n");
+}
+
+// 101 in fini_array, 65434 in dtors
+static void __attribute__((destructor(101))) dtors101() {
+    Print(L"4) dtor with lower numbered priority \r\n");
+}
+
+// 65434 in fini_array, 101 in dtors
+static void __attribute__((destructor(65434))) dtors65434() {
+    Print(L"3) dtor with higher numbered priority \r\n");
+}
+
+EFI_STATUS
+efi_main (EFI_HANDLE image EFI_UNUSED, EFI_SYSTEM_TABLE *systab EFI_UNUSED)
+{
+    Print(L"Main function \r\n");
+    return EFI_SUCCESS;
+}

+ 20 - 8
gnuefi/elf_aarch64_efi.lds

@@ -48,18 +48,25 @@ SECTIONS
     * have NULLs which aren't guaranteed to be at the end.
     */
    . = ALIGN(16);
-   _init_array = .;
-   *(SORT_BY_NAME(.init_array))
-   _init_array_end = .;
+   __init_array_start = .;
+   *(SORT(.init_array.*))
+   *(.init_array)
+   __init_array_end = .;
+  . = ALIGN(16);
    __CTOR_LIST__ = .;
-   *(SORT_BY_NAME(.ctors))
+   *(SORT(.ctors.*))
+   *(.ctors)
    __CTOR_END__ = .;
+  . = ALIGN(16);
    __DTOR_LIST__ = .;
-   *(SORT_BY_NAME(.dtors))
+   *(SORT(.dtors.*))
+   *(.dtors)
    __DTOR_END__ = .;
-   _fini_array = .;
-   *(SORT_BY_NAME(.fini_array))
-   _fini_array_end = .;
+   . = ALIGN(16);
+   __fini_array_start = .;
+   *(SORT(.fini_array.*))
+   *(.fini_array)
+   __fini_array_end = .;
 
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
@@ -84,6 +91,11 @@ SECTIONS
     *(.rela.got)
     *(.rela.dyn)
     *(.rela.stab)
+    *(.rela.init_array*)
+    *(.rela.fini_array*)
+    *(.rela.ctors*)
+    *(.rela.dtors*)
+
   }
   . = ALIGN(4096);
   .rela.plt : { *(.rela.plt) }

+ 20 - 8
gnuefi/elf_arm_efi.lds

@@ -35,18 +35,25 @@ SECTIONS
     * have NULLs which aren't guaranteed to be at the end.
     */
    . = ALIGN(16);
-   _init_array = .;
-   *(SORT_BY_NAME(.init_array))
-   _init_array_end = .;
+   __init_array_start = .;
+   *(SORT(.init_array.*))
+   *(.init_array)
+   __init_array_end = .;
+  . = ALIGN(16);
    __CTOR_LIST__ = .;
-   *(SORT_BY_NAME(.ctors))
+   *(SORT(.ctors.*))
+   *(.ctors)
    __CTOR_END__ = .;
+  . = ALIGN(16);
    __DTOR_LIST__ = .;
-   *(SORT_BY_NAME(.dtors))
+   *(SORT(.dtors.*))
+   *(.dtors)
    __DTOR_END__ = .;
-   _fini_array = .;
-   *(SORT_BY_NAME(.fini_array))
-   _fini_array_end = .;
+   . = ALIGN(16);
+   __fini_array_start = .;
+   *(SORT(.fini_array.*))
+   *(.fini_array)
+   __fini_array_end = .;
 
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
@@ -70,6 +77,11 @@ SECTIONS
     *(.rel.got)
     *(.rel.dyn)
     *(.rel.stab)
+    *(.rel.init_array*)
+    *(.rel.fini_array*)
+    *(.rel.ctors*)
+    *(.rel.dtors*)
+
   }
   . = ALIGN(4096);
   .rel.plt : { *(.rel.plt) }

+ 19 - 8
gnuefi/elf_ia32_efi.lds

@@ -39,18 +39,25 @@ SECTIONS
     * have NULLs which aren't guaranteed to be at the end.
     */
    . = ALIGN(16);
-   _init_array = .;
-   *(SORT_BY_NAME(.init_array))
-   _init_array_end = .;
+   __init_array_start = .;
+   *(SORT(.init_array.*))
+   *(.init_array)
+   __init_array_end = .;
+  . = ALIGN(16);
    __CTOR_LIST__ = .;
-   *(SORT_BY_NAME(.ctors))
+   *(SORT(.ctors.*))
+   *(.ctors)
    __CTOR_END__ = .;
+  . = ALIGN(16);
    __DTOR_LIST__ = .;
-   *(SORT_BY_NAME(.dtors))
+   *(SORT(.dtors.*))
+   *(.dtors)
    __DTOR_END__ = .;
-   _fini_array = .;
-   *(SORT_BY_NAME(.fini_array))
-   _fini_array_end = .;
+   . = ALIGN(16);
+   __fini_array_start = .;
+   *(SORT(.fini_array.*))
+   *(.fini_array)
+   __fini_array_end = .;
 
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
@@ -70,6 +77,10 @@ SECTIONS
     *(.rel.got)
     *(.rel.dyn)
     *(.rel.stab)
+    *(.rel.init_array*)
+    *(.rel.fini_array*)
+    *(.rel.ctors*)
+    *(.rel.dtors*)
     *(.data.rel.ro.local)
     *(.data.rel.local)
     *(.data.rel.ro)

+ 19 - 8
gnuefi/elf_ia32_fbsd_efi.lds

@@ -48,18 +48,25 @@ SECTIONS
     * have NULLs which aren't guaranteed to be at the end.
     */
    . = ALIGN(16);
-   _init_array = .;
-   *(SORT_BY_NAME(.init_array))
-   _init_array_end = .;
+   __init_array_start = .;
+   *(SORT(.init_array.*))
+   *(.init_array)
+   __init_array_end = .;
+  . = ALIGN(16);
    __CTOR_LIST__ = .;
-   *(SORT_BY_NAME(.ctors))
+   *(SORT(.ctors.*))
+   *(.ctors)
    __CTOR_END__ = .;
+  . = ALIGN(16);
    __DTOR_LIST__ = .;
-   *(SORT_BY_NAME(.dtors))
+   *(SORT(.dtors.*))
+   *(.dtors)
    __DTOR_END__ = .;
-   _fini_array = .;
-   *(SORT_BY_NAME(.fini_array))
-   _fini_array_end = .;
+   . = ALIGN(16);
+   __fini_array_start = .;
+   *(SORT(.fini_array.*))
+   *(.fini_array)
+   __fini_array_end = .;
 
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
@@ -80,6 +87,10 @@ SECTIONS
     *(.rel.data.*)
     *(.rel.got)
     *(.rel.stab)
+    *(.rel.init_array*)
+    *(.rel.fini_array*)
+    *(.rel.ctors*)
+    *(.rel.dtors*)
     *(.data.rel.ro.local)
     *(.data.rel.local)
     *(.data.rel.ro)

+ 19 - 9
gnuefi/elf_ia64_efi.lds

@@ -49,18 +49,25 @@ SECTIONS
     * have NULLs which aren't guaranteed to be at the end.
     */
    . = ALIGN(16);
-   _init_array = .;
-   *(SORT_BY_NAME(.init_array))
-   _init_array_end = .;
+   __init_array_start = .;
+   *(SORT(.init_array.*))
+   *(.init_array)
+   __init_array_end = .;
+  . = ALIGN(16);
    __CTOR_LIST__ = .;
-   *(SORT_BY_NAME(.ctors))
+   *(SORT(.ctors.*))
+   *(.ctors)
    __CTOR_END__ = .;
+  . = ALIGN(16);
    __DTOR_LIST__ = .;
-   *(SORT_BY_NAME(.dtors))
+   *(SORT(.dtors.*))
+   *(.dtors)
    __DTOR_END__ = .;
-   _fini_array = .;
-   *(SORT_BY_NAME(.fini_array))
-   _fini_array_end = .;
+   . = ALIGN(16);
+   __fini_array_start = .;
+   *(SORT(.fini_array.*))
+   *(.fini_array)
+   __fini_array_end = .;
 
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
@@ -82,7 +89,10 @@ SECTIONS
     *(.rela.dyn)
     *(.rela.gnu.linkonce.d*)
     *(.rela.stab)
-    *(.rela.ctors)
+    *(.rela.init_array*)
+    *(.rela.fini_array*)
+    *(.rela.ctors*)
+    *(.rela.dtors*)
   }
   . = ALIGN(4096);
   .rela.plt : { *(.rela.plt) }

+ 19 - 8
gnuefi/elf_mips64el_efi.lds

@@ -36,18 +36,25 @@ SECTIONS
     * have NULLs which aren't guaranteed to be at the end.
     */
    . = ALIGN(16);
-   _init_array = .;
-   *(SORT_BY_NAME(.init_array))
-   _init_array_end = .;
+   __init_array_start = .;
+   *(SORT(.init_array.*))
+   *(.init_array)
+   __init_array_end = .;
+  . = ALIGN(16);
    __CTOR_LIST__ = .;
-   *(SORT_BY_NAME(.ctors))
+   *(SORT(.ctors.*))
+   *(.ctors)
    __CTOR_END__ = .;
+  . = ALIGN(16);
    __DTOR_LIST__ = .;
-   *(SORT_BY_NAME(.dtors))
+   *(SORT(.dtors.*))
+   *(.dtors)
    __DTOR_END__ = .;
-   _fini_array = .;
-   *(SORT_BY_NAME(.fini_array))
-   _fini_array_end = .;
+   . = ALIGN(16);
+   __fini_array_start = .;
+   *(SORT(.fini_array.*))
+   *(.fini_array)
+   __fini_array_end = .;
 
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
@@ -70,6 +77,10 @@ SECTIONS
     *(.rel.got)
     *(.rel.dyn)
     *(.rel.stab)
+    *(.rel.init_array*)
+    *(.rel.fini_array*)
+    *(.rel.ctors*)
+    *(.rel.dtors*)
   }
   . = ALIGN(4096);
   .rel.plt : { *(.rel.plt) }

+ 4 - 0
gnuefi/elf_riscv64_efi.lds

@@ -52,6 +52,10 @@ SECTIONS {
     *(.rela.got)
     *(.rela.dyn)
     *(.rela.stab)
+    *(.rela.init_array)
+    *(.rela.fini_array)
+    *(.rela.ctors)
+    *(.rela.dtors)
   }
 . = ALIGN(4096);
 .rela.plt : { *(.rela.plt) }

+ 19 - 8
gnuefi/elf_x86_64_efi.lds

@@ -46,18 +46,25 @@ SECTIONS
     * have NULLs which aren't guaranteed to be at the end.
     */
    . = ALIGN(16);
-   _init_array = .;
-   *(SORT_BY_NAME(.init_array))
-   _init_array_end = .;
+   __init_array_start = .;
+   *(SORT(.init_array.*))
+   *(.init_array)
+   __init_array_end = .;
+  . = ALIGN(16);
    __CTOR_LIST__ = .;
-   *(SORT_BY_NAME(.ctors))
+   *(SORT(.ctors.*))
+   *(.ctors)
    __CTOR_END__ = .;
+  . = ALIGN(16);
    __DTOR_LIST__ = .;
-   *(SORT_BY_NAME(.dtors))
+   *(SORT(.dtors.*))
+   *(.dtors)
    __DTOR_END__ = .;
-   _fini_array = .;
-   *(SORT_BY_NAME(.fini_array))
-   _fini_array_end = .;
+   . = ALIGN(16);
+   __fini_array_start = .;
+   *(SORT(.fini_array.*))
+   *(.fini_array)
+   __fini_array_end = .;
 
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
@@ -82,6 +89,10 @@ SECTIONS
     *(.rela.got)
     *(.rela.dyn)
     *(.rela.stab)
+    *(.rela.init_array*)
+    *(.rela.fini_array*)
+    *(.rela.ctors*)
+    *(.rela.dtors*)
   }
   . = ALIGN(4096);
   .rela.plt : { *(.rela.plt) }

+ 19 - 8
gnuefi/elf_x86_64_fbsd_efi.lds

@@ -44,18 +44,25 @@ SECTIONS
     * have NULLs which aren't guaranteed to be at the end.
     */
    . = ALIGN(16);
-   _init_array = .;
-   *(SORT_BY_NAME(.init_array))
-   _init_array_end = .;
+   __init_array_start = .;
+   *(SORT(.init_array.*))
+   *(.init_array)
+   __init_array_end = .;
+  . = ALIGN(16);
    __CTOR_LIST__ = .;
-   *(SORT_BY_NAME(.ctors))
+   *(SORT(.ctors.*))
+   *(.ctors)
    __CTOR_END__ = .;
+  . = ALIGN(16);
    __DTOR_LIST__ = .;
-   *(SORT_BY_NAME(.dtors))
+   *(SORT(.dtors.*))
+   *(.dtors)
    __DTOR_END__ = .;
-   _fini_array = .;
-   *(SORT_BY_NAME(.fini_array))
-   _fini_array_end = .;
+   . = ALIGN(16);
+   __fini_array_start = .;
+   *(SORT(.fini_array.*))
+   *(.fini_array)
+   __fini_array_end = .;
 
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
@@ -76,6 +83,10 @@ SECTIONS
     *(.rela.data*)
     *(.rela.got)
     *(.rela.stab)
+    *(.rela.init_array*)
+    *(.rela.fini_array*)
+    *(.rela.ctors*)
+    *(.rela.dtors*)
   }
   _edata = .;
   _data_size = . - _etext;

+ 13 - 16
lib/ctors.S

@@ -8,38 +8,35 @@
  * end/END definitions, and the fact that they're mergeable, they can also
  * have NULLs which aren't guaranteed to be at the end.
  */
-	.section .init_array, "aM", @init_array
+	.section .init_array, "aw", @init_array
 	.p2align 3, 0
-	.globl _init_array
-_init_array:
+	.globl __init_array_start
+__init_array_start:
 	.p2align 3, 0
-	.globl _init_array_end
-_init_array_end:
-	.long 0
-	.section .ctors, "aM", @init_array
+	.globl __init_array_end
+__init_array_end:
+	.section .ctors, "aw", @progbits
 	.p2align 3, 0
 	.globl __CTOR_LIST__
 __CTOR_LIST__:
 	.p2align 3, 0
 	.globl __CTOR_END__
 __CTOR_END__:
-	.long 0
-	.section .dtors, "aM", @fini_array
+	.section .dtors, "aw", @progbits
 	.p2align 3, 0
 	.globl __DTOR_LIST__
 __DTOR_LIST__:
 	.p2align 3, 0
 	.globl __DTOR_END__
 __DTOR_END__:
-	.long 0
-	.section .fini_array, "aM", @fini_array
+	.section .fini_array, "aw", @fini_array
 	.p2align 3, 0
-	.globl _fini_array
-_fini_array:
+	.globl __fini_array_start
+__fini_array_start:
+	.p2align 3, 0
+	.globl __fini_array_end
+__fini_array_end:
 	.p2align 3, 0
-	.globl _fini_array_end
-_fini_array_end:
-	.long 0
 
 #if defined(__ELF__) && defined(__linux__)
 	.section .note.GNU-stack,"",%progbits

+ 3 - 2
lib/dpath.c

@@ -1083,11 +1083,12 @@ _DevPathNodeUnknown (
  * Entries hold "Type" and "SubType" for know values.
  * Special "SubType" 0 is used as default for known type with unknown subtype.
  */
-struct {
+typedef struct {
     UINT8   Type;
     UINT8   SubType;
     VOID    (*Function)(POOL_PRINT *, VOID *);
-} DevPathTable[] = {
+} DevPathTable_Type;
+DevPathTable_Type DevPathTable[] = {
 	{ HARDWARE_DEVICE_PATH,   HW_PCI_DP,                        _DevPathPci},
 	{ HARDWARE_DEVICE_PATH,   HW_PCCARD_DP,                     _DevPathPccard},
 	{ HARDWARE_DEVICE_PATH,   HW_MEMMAP_DP,                     _DevPathMemMap},

+ 24 - 18
lib/entry.c

@@ -7,45 +7,51 @@
 #include <efi.h>
 #include <efilib.h>
 
+typedef void (*funcp)(void);
+
 /*
  * Note that these aren't the using the GNU "CONSTRUCTOR" output section
  * command, so they don't start with a size.  Because of p2align and the
  * end/END definitions, and the fact that they're mergeable, they can also
  * have NULLs which aren't guaranteed to be at the end.
  */
-extern UINTN _init_array, _init_array_end;
-extern UINTN __CTOR_LIST__, __CTOR_END__;
-extern UINTN _fini_array, _fini_array_end;
-extern UINTN __DTOR_LIST__, __DTOR_END__;
-
-typedef void (*funcp)(void);
+extern funcp __init_array_start[], __init_array_end[];
+extern funcp __CTOR_LIST__[], __CTOR_END__[];
+extern funcp __fini_array_start[], __fini_array_end[];
+extern funcp __DTOR_LIST__[], __DTOR_END__[];
 
 static void ctors(void)
 {
-	for (funcp *location = (void *)&_init_array; location < (funcp *)&_init_array_end; location++) {
-		funcp func = *location;
-		if (location != NULL)
+	size_t __init_array_length = __init_array_end - __init_array_start;
+	for (size_t i = 0; i < __init_array_length; i++) {
+		funcp func = __init_array_start[i];
+		if (func != NULL)
 			func();
 	}
 
-	for (funcp *location = (void *)&__CTOR_LIST__; location < (funcp *)&__CTOR_END__; location++) {
-		funcp func = *location;
-		if (location != NULL)
+	size_t __CTOR_length = __CTOR_END__ - __CTOR_LIST__;
+	for (size_t i = 0; i < __CTOR_length; i++) {
+		size_t current = __CTOR_length - i - 1;
+		funcp func = __CTOR_LIST__[current];
+		if (func != NULL)
 			func();
 	}
 }
 
 static void dtors(void)
 {
-	for (funcp *location = (void *)&__DTOR_LIST__; location < (funcp *)&__DTOR_END__; location++) {
-		funcp func = *location;
-		if (location != NULL)
+	size_t __DTOR_length = __DTOR_END__ - __DTOR_LIST__;
+	for (size_t i = 0; i < __DTOR_length; i++) {
+		funcp func = __DTOR_LIST__[i];
+		if (func != NULL)
 			func();
 	}
 
-	for (funcp *location = (void *)&_fini_array; location < (funcp *)&_fini_array_end; location++) {
-		funcp func = *location;
-		if (location != NULL)
+	size_t __fini_array_length = __fini_array_end - __fini_array_start;
+	for (size_t i = 0; i < __fini_array_length; i++) {
+		size_t current = __fini_array_length - i - 1;
+		funcp func = __fini_array_start[current];
+		if (func != NULL)
 			func();
 	}
 }

+ 5 - 4
lib/error.c

@@ -18,10 +18,11 @@ Revision History
 #include "lib.h"
 
 
-struct {
-    EFI_STATUS      Code;
-    WCHAR	    *Desc;
-} ErrorCodeTable[] = {
+typedef struct {
+    EFI_STATUS	Code;
+    WCHAR		*Desc;
+} ErrorCodeTable_Type;
+ErrorCodeTable_Type ErrorCodeTable[] = {
 	{  EFI_SUCCESS,                L"Success"},
 	{  EFI_LOAD_ERROR,             L"Load Error"},
 	{  EFI_INVALID_PARAMETER,      L"Invalid Parameter"},