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

https://sourceforge.net/p/gnu-efi/code/merge-requests/51/
This commit is contained in:
b'Nigel Croxon 2023-05-16 13:06:32 +00:00
commit 9835e11ebe
17 changed files with 238 additions and 109 deletions

View File

@ -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)

View File

@ -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* \

View File

@ -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 =

View File

@ -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;
}

View File

@ -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) }

View File

@ -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) }

View File

@ -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)

View File

@ -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)

View File

@ -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) }

View File

@ -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) }

View File

@ -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) }

View File

@ -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) }

View File

@ -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;

View File

@ -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

View File

@ -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},

View File

@ -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();
}
}

View File

@ -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"},