From 9b1e06cd0cc7937ae291a34f1bb5ec1b4568faee Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Wed, 26 Apr 2023 18:36:56 +0100 Subject: [PATCH 01/14] Use -std instead of --std --std isn't standardised. lol. Signed-off-by: Callum Farmer --- Make.defaults | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Make.defaults b/Make.defaults index 1277d14..53360a8 100755 --- a/Make.defaults +++ b/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 From 97499a0cf265bf2d515bfcab99349ce00ecf2662 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Wed, 26 Apr 2023 19:18:28 +0100 Subject: [PATCH 02/14] ctors.S: Use LSB defined section perms Seems to not be correct at the moment, causes errors. error: expected the entry size .section .fini_array, "aM", @fini_array Change per https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/specialsections.html Signed-off-by: Callum Farmer --- lib/ctors.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ctors.S b/lib/ctors.S index 4a0c6ab..fe0f23a 100644 --- a/lib/ctors.S +++ b/lib/ctors.S @@ -8,7 +8,7 @@ * 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: @@ -16,7 +16,7 @@ _init_array: .globl _init_array_end _init_array_end: .long 0 - .section .ctors, "aM", @init_array + .section .ctors, "aw", @progbits .p2align 3, 0 .globl __CTOR_LIST__ __CTOR_LIST__: @@ -24,7 +24,7 @@ __CTOR_LIST__: .globl __CTOR_END__ __CTOR_END__: .long 0 - .section .dtors, "aM", @fini_array + .section .dtors, "aw", @progbits .p2align 3, 0 .globl __DTOR_LIST__ __DTOR_LIST__: @@ -32,7 +32,7 @@ __DTOR_LIST__: .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: From 486b1c20c139c04439a6518d5ac68c0d9bd8c730 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Fri, 28 Apr 2023 14:52:08 +0100 Subject: [PATCH 03/14] Enforce nocombreloc It is needed to avoid ELF reloc (rela) issues and to find un-merged reloc sections Signed-off-by: Callum Farmer --- Make.defaults | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Make.defaults b/Make.defaults index 53360a8..a4ecac0 100755 --- a/Make.defaults +++ b/Make.defaults @@ -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) From 4c938fac30954a54456300bcdad2fdd0b34b6210 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Fri, 28 Apr 2023 15:13:58 +0100 Subject: [PATCH 04/14] Merge ctors/dtors rela sections Signed-off-by: Callum Farmer --- gnuefi/elf_aarch64_efi.lds | 5 +++++ gnuefi/elf_arm_efi.lds | 5 +++++ gnuefi/elf_ia32_efi.lds | 4 ++++ gnuefi/elf_ia32_fbsd_efi.lds | 4 ++++ gnuefi/elf_ia64_efi.lds | 3 +++ gnuefi/elf_mips64el_efi.lds | 4 ++++ gnuefi/elf_riscv64_efi.lds | 4 ++++ gnuefi/elf_x86_64_efi.lds | 4 ++++ gnuefi/elf_x86_64_fbsd_efi.lds | 4 ++++ 9 files changed, 37 insertions(+) diff --git a/gnuefi/elf_aarch64_efi.lds b/gnuefi/elf_aarch64_efi.lds index 563e22d..343956c 100644 --- a/gnuefi/elf_aarch64_efi.lds +++ b/gnuefi/elf_aarch64_efi.lds @@ -84,6 +84,11 @@ SECTIONS *(.rela.got) *(.rela.dyn) *(.rela.stab) + *(.rela.init_array) + *(.rela.fini_array) + *(.rela.ctors) + *(.rela.dtors) + } . = ALIGN(4096); .rela.plt : { *(.rela.plt) } diff --git a/gnuefi/elf_arm_efi.lds b/gnuefi/elf_arm_efi.lds index 3023ebc..4b0f032 100644 --- a/gnuefi/elf_arm_efi.lds +++ b/gnuefi/elf_arm_efi.lds @@ -70,6 +70,11 @@ SECTIONS *(.rel.got) *(.rel.dyn) *(.rel.stab) + *(.rel.init_array) + *(.rel.fini_array) + *(.rel.ctors) + *(.rel.dtors) + } . = ALIGN(4096); .rel.plt : { *(.rel.plt) } diff --git a/gnuefi/elf_ia32_efi.lds b/gnuefi/elf_ia32_efi.lds index 5eec529..8694d82 100644 --- a/gnuefi/elf_ia32_efi.lds +++ b/gnuefi/elf_ia32_efi.lds @@ -70,6 +70,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) diff --git a/gnuefi/elf_ia32_fbsd_efi.lds b/gnuefi/elf_ia32_fbsd_efi.lds index 9e9baec..3ecdc62 100644 --- a/gnuefi/elf_ia32_fbsd_efi.lds +++ b/gnuefi/elf_ia32_fbsd_efi.lds @@ -80,6 +80,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) diff --git a/gnuefi/elf_ia64_efi.lds b/gnuefi/elf_ia64_efi.lds index e45799c..de51acf 100644 --- a/gnuefi/elf_ia64_efi.lds +++ b/gnuefi/elf_ia64_efi.lds @@ -82,7 +82,10 @@ SECTIONS *(.rela.dyn) *(.rela.gnu.linkonce.d*) *(.rela.stab) + *(.rela.init_array) + *(.rela.fini_array) *(.rela.ctors) + *(.rela.dtors) } . = ALIGN(4096); .rela.plt : { *(.rela.plt) } diff --git a/gnuefi/elf_mips64el_efi.lds b/gnuefi/elf_mips64el_efi.lds index bf96841..b522bbc 100644 --- a/gnuefi/elf_mips64el_efi.lds +++ b/gnuefi/elf_mips64el_efi.lds @@ -70,6 +70,10 @@ SECTIONS *(.rel.got) *(.rel.dyn) *(.rel.stab) + *(.rel.init_array) + *(.rel.fini_array) + *(.rel.ctors) + *(.rel.dtors) } . = ALIGN(4096); .rel.plt : { *(.rel.plt) } diff --git a/gnuefi/elf_riscv64_efi.lds b/gnuefi/elf_riscv64_efi.lds index 3b47247..d5153e9 100644 --- a/gnuefi/elf_riscv64_efi.lds +++ b/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) } diff --git a/gnuefi/elf_x86_64_efi.lds b/gnuefi/elf_x86_64_efi.lds index 2e0e0cb..4aea2da 100644 --- a/gnuefi/elf_x86_64_efi.lds +++ b/gnuefi/elf_x86_64_efi.lds @@ -82,6 +82,10 @@ SECTIONS *(.rela.got) *(.rela.dyn) *(.rela.stab) + *(.rela.init_array) + *(.rela.fini_array) + *(.rela.ctors) + *(.rela.dtors) } . = ALIGN(4096); .rela.plt : { *(.rela.plt) } diff --git a/gnuefi/elf_x86_64_fbsd_efi.lds b/gnuefi/elf_x86_64_fbsd_efi.lds index 721ce9a..0eb7299 100644 --- a/gnuefi/elf_x86_64_fbsd_efi.lds +++ b/gnuefi/elf_x86_64_fbsd_efi.lds @@ -76,6 +76,10 @@ SECTIONS *(.rela.data*) *(.rela.got) *(.rela.stab) + *(.rela.init_array) + *(.rela.fini_array) + *(.rela.ctors) + *(.rela.dtors) } _edata = .; _data_size = . - _etext; From e2aa099738e1bd527929b5fb6fe7312962b6b4e4 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Fri, 28 Apr 2023 17:46:24 +0100 Subject: [PATCH 05/14] lds: Support ctors/dtors with a priority Signed-off-by: Callum Farmer --- gnuefi/elf_aarch64_efi.lds | 20 ++++++++++++-------- gnuefi/elf_arm_efi.lds | 20 ++++++++++++-------- gnuefi/elf_ia32_efi.lds | 20 ++++++++++++-------- gnuefi/elf_ia32_fbsd_efi.lds | 20 ++++++++++++-------- gnuefi/elf_ia64_efi.lds | 20 ++++++++++++-------- gnuefi/elf_mips64el_efi.lds | 20 ++++++++++++-------- gnuefi/elf_x86_64_efi.lds | 20 ++++++++++++-------- gnuefi/elf_x86_64_fbsd_efi.lds | 20 ++++++++++++-------- 8 files changed, 96 insertions(+), 64 deletions(-) diff --git a/gnuefi/elf_aarch64_efi.lds b/gnuefi/elf_aarch64_efi.lds index 343956c..7657bb3 100644 --- a/gnuefi/elf_aarch64_efi.lds +++ b/gnuefi/elf_aarch64_efi.lds @@ -49,16 +49,20 @@ SECTIONS */ . = ALIGN(16); _init_array = .; - *(SORT_BY_NAME(.init_array)) + *(SORT(.init_array.*)) + *(.init_array) _init_array_end = .; __CTOR_LIST__ = .; - *(SORT_BY_NAME(.ctors)) + *(SORT(.ctors.*)) + *(.ctors) __CTOR_END__ = .; __DTOR_LIST__ = .; - *(SORT_BY_NAME(.dtors)) + *(SORT(.dtors.*)) + *(.dtors) __DTOR_END__ = .; _fini_array = .; - *(SORT_BY_NAME(.fini_array)) + *(SORT(.fini_array.*)) + *(.fini_array) _fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick @@ -84,10 +88,10 @@ SECTIONS *(.rela.got) *(.rela.dyn) *(.rela.stab) - *(.rela.init_array) - *(.rela.fini_array) - *(.rela.ctors) - *(.rela.dtors) + *(.rela.init_array*) + *(.rela.fini_array*) + *(.rela.ctors*) + *(.rela.dtors*) } . = ALIGN(4096); diff --git a/gnuefi/elf_arm_efi.lds b/gnuefi/elf_arm_efi.lds index 4b0f032..3c9f919 100644 --- a/gnuefi/elf_arm_efi.lds +++ b/gnuefi/elf_arm_efi.lds @@ -36,16 +36,20 @@ SECTIONS */ . = ALIGN(16); _init_array = .; - *(SORT_BY_NAME(.init_array)) + *(SORT(.init_array.*)) + *(.init_array) _init_array_end = .; __CTOR_LIST__ = .; - *(SORT_BY_NAME(.ctors)) + *(SORT(.ctors.*)) + *(.ctors) __CTOR_END__ = .; __DTOR_LIST__ = .; - *(SORT_BY_NAME(.dtors)) + *(SORT(.dtors.*)) + *(.dtors) __DTOR_END__ = .; _fini_array = .; - *(SORT_BY_NAME(.fini_array)) + *(SORT(.fini_array.*)) + *(.fini_array) _fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick @@ -70,10 +74,10 @@ SECTIONS *(.rel.got) *(.rel.dyn) *(.rel.stab) - *(.rel.init_array) - *(.rel.fini_array) - *(.rel.ctors) - *(.rel.dtors) + *(.rel.init_array*) + *(.rel.fini_array*) + *(.rel.ctors*) + *(.rel.dtors*) } . = ALIGN(4096); diff --git a/gnuefi/elf_ia32_efi.lds b/gnuefi/elf_ia32_efi.lds index 8694d82..964530c 100644 --- a/gnuefi/elf_ia32_efi.lds +++ b/gnuefi/elf_ia32_efi.lds @@ -40,16 +40,20 @@ SECTIONS */ . = ALIGN(16); _init_array = .; - *(SORT_BY_NAME(.init_array)) + *(SORT(.init_array.*)) + *(.init_array) _init_array_end = .; __CTOR_LIST__ = .; - *(SORT_BY_NAME(.ctors)) + *(SORT(.ctors.*)) + *(.ctors) __CTOR_END__ = .; __DTOR_LIST__ = .; - *(SORT_BY_NAME(.dtors)) + *(SORT(.dtors.*)) + *(.dtors) __DTOR_END__ = .; _fini_array = .; - *(SORT_BY_NAME(.fini_array)) + *(SORT(.fini_array.*)) + *(.fini_array) _fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick @@ -70,10 +74,10 @@ SECTIONS *(.rel.got) *(.rel.dyn) *(.rel.stab) - *(.rel.init_array) - *(.rel.fini_array) - *(.rel.ctors) - *(.rel.dtors) + *(.rel.init_array*) + *(.rel.fini_array*) + *(.rel.ctors*) + *(.rel.dtors*) *(.data.rel.ro.local) *(.data.rel.local) *(.data.rel.ro) diff --git a/gnuefi/elf_ia32_fbsd_efi.lds b/gnuefi/elf_ia32_fbsd_efi.lds index 3ecdc62..c5c5dae 100644 --- a/gnuefi/elf_ia32_fbsd_efi.lds +++ b/gnuefi/elf_ia32_fbsd_efi.lds @@ -49,16 +49,20 @@ SECTIONS */ . = ALIGN(16); _init_array = .; - *(SORT_BY_NAME(.init_array)) + *(SORT(.init_array.*)) + *(.init_array) _init_array_end = .; __CTOR_LIST__ = .; - *(SORT_BY_NAME(.ctors)) + *(SORT(.ctors.*)) + *(.ctors) __CTOR_END__ = .; __DTOR_LIST__ = .; - *(SORT_BY_NAME(.dtors)) + *(SORT(.dtors.*)) + *(.dtors) __DTOR_END__ = .; _fini_array = .; - *(SORT_BY_NAME(.fini_array)) + *(SORT(.fini_array.*)) + *(.fini_array) _fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick @@ -80,10 +84,10 @@ SECTIONS *(.rel.data.*) *(.rel.got) *(.rel.stab) - *(.rel.init_array) - *(.rel.fini_array) - *(.rel.ctors) - *(.rel.dtors) + *(.rel.init_array*) + *(.rel.fini_array*) + *(.rel.ctors*) + *(.rel.dtors*) *(.data.rel.ro.local) *(.data.rel.local) *(.data.rel.ro) diff --git a/gnuefi/elf_ia64_efi.lds b/gnuefi/elf_ia64_efi.lds index de51acf..f85cb91 100644 --- a/gnuefi/elf_ia64_efi.lds +++ b/gnuefi/elf_ia64_efi.lds @@ -50,16 +50,20 @@ SECTIONS */ . = ALIGN(16); _init_array = .; - *(SORT_BY_NAME(.init_array)) + *(SORT(.init_array.*)) + *(.init_array) _init_array_end = .; __CTOR_LIST__ = .; - *(SORT_BY_NAME(.ctors)) + *(SORT(.ctors.*)) + *(.ctors) __CTOR_END__ = .; __DTOR_LIST__ = .; - *(SORT_BY_NAME(.dtors)) + *(SORT(.dtors.*)) + *(.dtors) __DTOR_END__ = .; _fini_array = .; - *(SORT_BY_NAME(.fini_array)) + *(SORT(.fini_array.*)) + *(.fini_array) _fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick @@ -82,10 +86,10 @@ SECTIONS *(.rela.dyn) *(.rela.gnu.linkonce.d*) *(.rela.stab) - *(.rela.init_array) - *(.rela.fini_array) - *(.rela.ctors) - *(.rela.dtors) + *(.rela.init_array*) + *(.rela.fini_array*) + *(.rela.ctors*) + *(.rela.dtors*) } . = ALIGN(4096); .rela.plt : { *(.rela.plt) } diff --git a/gnuefi/elf_mips64el_efi.lds b/gnuefi/elf_mips64el_efi.lds index b522bbc..80312bf 100644 --- a/gnuefi/elf_mips64el_efi.lds +++ b/gnuefi/elf_mips64el_efi.lds @@ -37,16 +37,20 @@ SECTIONS */ . = ALIGN(16); _init_array = .; - *(SORT_BY_NAME(.init_array)) + *(SORT(.init_array.*)) + *(.init_array) _init_array_end = .; __CTOR_LIST__ = .; - *(SORT_BY_NAME(.ctors)) + *(SORT(.ctors.*)) + *(.ctors) __CTOR_END__ = .; __DTOR_LIST__ = .; - *(SORT_BY_NAME(.dtors)) + *(SORT(.dtors.*)) + *(.dtors) __DTOR_END__ = .; _fini_array = .; - *(SORT_BY_NAME(.fini_array)) + *(SORT(.fini_array.*)) + *(.fini_array) _fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick @@ -70,10 +74,10 @@ SECTIONS *(.rel.got) *(.rel.dyn) *(.rel.stab) - *(.rel.init_array) - *(.rel.fini_array) - *(.rel.ctors) - *(.rel.dtors) + *(.rel.init_array*) + *(.rel.fini_array*) + *(.rel.ctors*) + *(.rel.dtors*) } . = ALIGN(4096); .rel.plt : { *(.rel.plt) } diff --git a/gnuefi/elf_x86_64_efi.lds b/gnuefi/elf_x86_64_efi.lds index 4aea2da..c9564a2 100644 --- a/gnuefi/elf_x86_64_efi.lds +++ b/gnuefi/elf_x86_64_efi.lds @@ -47,16 +47,20 @@ SECTIONS */ . = ALIGN(16); _init_array = .; - *(SORT_BY_NAME(.init_array)) + *(SORT(.init_array.*)) + *(.init_array) _init_array_end = .; __CTOR_LIST__ = .; - *(SORT_BY_NAME(.ctors)) + *(SORT(.ctors.*)) + *(.ctors) __CTOR_END__ = .; __DTOR_LIST__ = .; - *(SORT_BY_NAME(.dtors)) + *(SORT(.dtors.*)) + *(.dtors) __DTOR_END__ = .; _fini_array = .; - *(SORT_BY_NAME(.fini_array)) + *(SORT(.fini_array.*)) + *(.fini_array) _fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick @@ -82,10 +86,10 @@ SECTIONS *(.rela.got) *(.rela.dyn) *(.rela.stab) - *(.rela.init_array) - *(.rela.fini_array) - *(.rela.ctors) - *(.rela.dtors) + *(.rela.init_array*) + *(.rela.fini_array*) + *(.rela.ctors*) + *(.rela.dtors*) } . = ALIGN(4096); .rela.plt : { *(.rela.plt) } diff --git a/gnuefi/elf_x86_64_fbsd_efi.lds b/gnuefi/elf_x86_64_fbsd_efi.lds index 0eb7299..e8a6825 100644 --- a/gnuefi/elf_x86_64_fbsd_efi.lds +++ b/gnuefi/elf_x86_64_fbsd_efi.lds @@ -45,16 +45,20 @@ SECTIONS */ . = ALIGN(16); _init_array = .; - *(SORT_BY_NAME(.init_array)) + *(SORT(.init_array.*)) + *(.init_array) _init_array_end = .; __CTOR_LIST__ = .; - *(SORT_BY_NAME(.ctors)) + *(SORT(.ctors.*)) + *(.ctors) __CTOR_END__ = .; __DTOR_LIST__ = .; - *(SORT_BY_NAME(.dtors)) + *(SORT(.dtors.*)) + *(.dtors) __DTOR_END__ = .; _fini_array = .; - *(SORT_BY_NAME(.fini_array)) + *(SORT(.fini_array.*)) + *(.fini_array) _fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick @@ -76,10 +80,10 @@ SECTIONS *(.rela.data*) *(.rela.got) *(.rela.stab) - *(.rela.init_array) - *(.rela.fini_array) - *(.rela.ctors) - *(.rela.dtors) + *(.rela.init_array*) + *(.rela.fini_array*) + *(.rela.ctors*) + *(.rela.dtors*) } _edata = .; _data_size = . - _etext; From b3cc412aadc6448c62224013ce122b5449e67ec3 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Fri, 28 Apr 2023 20:22:05 +0100 Subject: [PATCH 06/14] entry.c: .ctors is run backwards Store forwards, run backwards (65535 to 0) Ref: https://github.com/bminor/binutils-gdb/blob/5a8e7e1332c35d4d5bed67adccd9d66f5cf62c4e/ld/scripttempl/elf.sc#L310 Ref: https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html Signed-off-by: Callum Farmer --- lib/entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/entry.c b/lib/entry.c index d852608..21bf0e6 100644 --- a/lib/entry.c +++ b/lib/entry.c @@ -28,7 +28,7 @@ static void ctors(void) func(); } - for (funcp *location = (void *)&__CTOR_LIST__; location < (funcp *)&__CTOR_END__; location++) { + for (funcp *location = (void *)&__CTOR_END__; location > (funcp *)&__CTOR_LIST__; location--) { funcp func = *location; if (location != NULL) func(); From 9c5403e1e6269bd47a4c383cfeaf1a4f29db121f Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Sun, 30 Apr 2023 13:51:32 +0100 Subject: [PATCH 07/14] Copy marker names from binutils for init/fini Signed-off-by: Callum Farmer --- gnuefi/elf_aarch64_efi.lds | 8 ++++---- gnuefi/elf_arm_efi.lds | 8 ++++---- gnuefi/elf_ia32_efi.lds | 8 ++++---- gnuefi/elf_ia32_fbsd_efi.lds | 8 ++++---- gnuefi/elf_ia64_efi.lds | 8 ++++---- gnuefi/elf_mips64el_efi.lds | 8 ++++---- gnuefi/elf_x86_64_efi.lds | 8 ++++---- gnuefi/elf_x86_64_fbsd_efi.lds | 8 ++++---- lib/ctors.S | 16 ++++++++-------- lib/entry.c | 8 ++++---- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/gnuefi/elf_aarch64_efi.lds b/gnuefi/elf_aarch64_efi.lds index 7657bb3..48d5106 100644 --- a/gnuefi/elf_aarch64_efi.lds +++ b/gnuefi/elf_aarch64_efi.lds @@ -48,10 +48,10 @@ SECTIONS * have NULLs which aren't guaranteed to be at the end. */ . = ALIGN(16); - _init_array = .; + __init_array_start = .; *(SORT(.init_array.*)) *(.init_array) - _init_array_end = .; + __init_array_end = .; __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) @@ -60,10 +60,10 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; - _fini_array = .; + __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) - _fini_array_end = .; + __fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ diff --git a/gnuefi/elf_arm_efi.lds b/gnuefi/elf_arm_efi.lds index 3c9f919..0964d35 100644 --- a/gnuefi/elf_arm_efi.lds +++ b/gnuefi/elf_arm_efi.lds @@ -35,10 +35,10 @@ SECTIONS * have NULLs which aren't guaranteed to be at the end. */ . = ALIGN(16); - _init_array = .; + __init_array_start = .; *(SORT(.init_array.*)) *(.init_array) - _init_array_end = .; + __init_array_end = .; __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) @@ -47,10 +47,10 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; - _fini_array = .; + __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) - _fini_array_end = .; + __fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ diff --git a/gnuefi/elf_ia32_efi.lds b/gnuefi/elf_ia32_efi.lds index 964530c..0c1f2a7 100644 --- a/gnuefi/elf_ia32_efi.lds +++ b/gnuefi/elf_ia32_efi.lds @@ -39,10 +39,10 @@ SECTIONS * have NULLs which aren't guaranteed to be at the end. */ . = ALIGN(16); - _init_array = .; + __init_array_start = .; *(SORT(.init_array.*)) *(.init_array) - _init_array_end = .; + __init_array_end = .; __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) @@ -51,10 +51,10 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; - _fini_array = .; + __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) - _fini_array_end = .; + __fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ diff --git a/gnuefi/elf_ia32_fbsd_efi.lds b/gnuefi/elf_ia32_fbsd_efi.lds index c5c5dae..0377d4f 100644 --- a/gnuefi/elf_ia32_fbsd_efi.lds +++ b/gnuefi/elf_ia32_fbsd_efi.lds @@ -48,10 +48,10 @@ SECTIONS * have NULLs which aren't guaranteed to be at the end. */ . = ALIGN(16); - _init_array = .; + __init_array_start = .; *(SORT(.init_array.*)) *(.init_array) - _init_array_end = .; + __init_array_end = .; __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) @@ -60,10 +60,10 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; - _fini_array = .; + __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) - _fini_array_end = .; + __fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ diff --git a/gnuefi/elf_ia64_efi.lds b/gnuefi/elf_ia64_efi.lds index f85cb91..46aee72 100644 --- a/gnuefi/elf_ia64_efi.lds +++ b/gnuefi/elf_ia64_efi.lds @@ -49,10 +49,10 @@ SECTIONS * have NULLs which aren't guaranteed to be at the end. */ . = ALIGN(16); - _init_array = .; + __init_array_start = .; *(SORT(.init_array.*)) *(.init_array) - _init_array_end = .; + __init_array_end = .; __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) @@ -61,10 +61,10 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; - _fini_array = .; + __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) - _fini_array_end = .; + __fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ diff --git a/gnuefi/elf_mips64el_efi.lds b/gnuefi/elf_mips64el_efi.lds index 80312bf..3721c56 100644 --- a/gnuefi/elf_mips64el_efi.lds +++ b/gnuefi/elf_mips64el_efi.lds @@ -36,10 +36,10 @@ SECTIONS * have NULLs which aren't guaranteed to be at the end. */ . = ALIGN(16); - _init_array = .; + __init_array_start = .; *(SORT(.init_array.*)) *(.init_array) - _init_array_end = .; + __init_array_end = .; __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) @@ -48,10 +48,10 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; - _fini_array = .; + __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) - _fini_array_end = .; + __fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ diff --git a/gnuefi/elf_x86_64_efi.lds b/gnuefi/elf_x86_64_efi.lds index c9564a2..22409de 100644 --- a/gnuefi/elf_x86_64_efi.lds +++ b/gnuefi/elf_x86_64_efi.lds @@ -46,10 +46,10 @@ SECTIONS * have NULLs which aren't guaranteed to be at the end. */ . = ALIGN(16); - _init_array = .; + __init_array_start = .; *(SORT(.init_array.*)) *(.init_array) - _init_array_end = .; + __init_array_end = .; __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) @@ -58,10 +58,10 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; - _fini_array = .; + __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) - _fini_array_end = .; + __fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ diff --git a/gnuefi/elf_x86_64_fbsd_efi.lds b/gnuefi/elf_x86_64_fbsd_efi.lds index e8a6825..55bed4a 100644 --- a/gnuefi/elf_x86_64_fbsd_efi.lds +++ b/gnuefi/elf_x86_64_fbsd_efi.lds @@ -44,10 +44,10 @@ SECTIONS * have NULLs which aren't guaranteed to be at the end. */ . = ALIGN(16); - _init_array = .; + __init_array_start = .; *(SORT(.init_array.*)) *(.init_array) - _init_array_end = .; + __init_array_end = .; __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) @@ -56,10 +56,10 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; - _fini_array = .; + __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) - _fini_array_end = .; + __fini_array_end = .; /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ diff --git a/lib/ctors.S b/lib/ctors.S index fe0f23a..cdd4629 100644 --- a/lib/ctors.S +++ b/lib/ctors.S @@ -10,11 +10,11 @@ */ .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: + .globl __init_array_end +__init_array_end: .long 0 .section .ctors, "aw", @progbits .p2align 3, 0 @@ -34,11 +34,11 @@ __DTOR_END__: .long 0 .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: + .globl __fini_array_end +__fini_array_end: .long 0 #if defined(__ELF__) && defined(__linux__) diff --git a/lib/entry.c b/lib/entry.c index 21bf0e6..5032f81 100644 --- a/lib/entry.c +++ b/lib/entry.c @@ -13,16 +13,16 @@ * 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 __init_array_start, __init_array_end; extern UINTN __CTOR_LIST__, __CTOR_END__; -extern UINTN _fini_array, _fini_array_end; +extern UINTN __fini_array_start, __fini_array_end; extern UINTN __DTOR_LIST__, __DTOR_END__; typedef void (*funcp)(void); static void ctors(void) { - for (funcp *location = (void *)&_init_array; location < (funcp *)&_init_array_end; location++) { + for (funcp *location = (void *)&__init_array_start; location < (funcp *)&__init_array_end; location++) { funcp func = *location; if (location != NULL) func(); @@ -43,7 +43,7 @@ static void dtors(void) func(); } - for (funcp *location = (void *)&_fini_array; location < (funcp *)&_fini_array_end; location++) { + for (funcp *location = (void *)&__fini_array_start; location < (funcp *)&__fini_array_end; location++) { funcp func = *location; if (location != NULL) func(); From 74b7b5e92c7ac329af95f66c6b2906a7ac3bf1d7 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Wed, 3 May 2023 11:19:41 +0100 Subject: [PATCH 08/14] entry.c: Fix null pointer exception Signed-off-by: Callum Farmer --- lib/entry.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/entry.c b/lib/entry.c index 5032f81..1aac667 100644 --- a/lib/entry.c +++ b/lib/entry.c @@ -24,13 +24,13 @@ static void ctors(void) { for (funcp *location = (void *)&__init_array_start; location < (funcp *)&__init_array_end; location++) { funcp func = *location; - if (location != NULL) + if (*location != NULL) func(); } for (funcp *location = (void *)&__CTOR_END__; location > (funcp *)&__CTOR_LIST__; location--) { funcp func = *location; - if (location != NULL) + if (*location != NULL) func(); } } @@ -39,13 +39,13 @@ static void dtors(void) { for (funcp *location = (void *)&__DTOR_LIST__; location < (funcp *)&__DTOR_END__; location++) { funcp func = *location; - if (location != NULL) + if (*location != NULL) func(); } for (funcp *location = (void *)&__fini_array_start; location < (funcp *)&__fini_array_end; location++) { funcp func = *location; - if (location != NULL) + if (*location != NULL) func(); } } From 9dbfe1c36558fdbc2574cea7e47e6a473955051d Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Wed, 3 May 2023 16:02:32 +0100 Subject: [PATCH 09/14] Align all ctors/dtors start to 16 Signed-off-by: Callum Farmer --- gnuefi/elf_aarch64_efi.lds | 3 +++ gnuefi/elf_arm_efi.lds | 3 +++ gnuefi/elf_ia32_efi.lds | 3 +++ gnuefi/elf_ia32_fbsd_efi.lds | 3 +++ gnuefi/elf_ia64_efi.lds | 3 +++ gnuefi/elf_mips64el_efi.lds | 3 +++ gnuefi/elf_x86_64_efi.lds | 3 +++ gnuefi/elf_x86_64_fbsd_efi.lds | 3 +++ 8 files changed, 24 insertions(+) diff --git a/gnuefi/elf_aarch64_efi.lds b/gnuefi/elf_aarch64_efi.lds index 48d5106..c487d8d 100644 --- a/gnuefi/elf_aarch64_efi.lds +++ b/gnuefi/elf_aarch64_efi.lds @@ -52,14 +52,17 @@ SECTIONS *(SORT(.init_array.*)) *(.init_array) __init_array_end = .; + . = ALIGN(16); __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) __CTOR_END__ = .; + . = ALIGN(16); __DTOR_LIST__ = .; *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; + . = ALIGN(16); __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) diff --git a/gnuefi/elf_arm_efi.lds b/gnuefi/elf_arm_efi.lds index 0964d35..b656440 100644 --- a/gnuefi/elf_arm_efi.lds +++ b/gnuefi/elf_arm_efi.lds @@ -39,14 +39,17 @@ SECTIONS *(SORT(.init_array.*)) *(.init_array) __init_array_end = .; + . = ALIGN(16); __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) __CTOR_END__ = .; + . = ALIGN(16); __DTOR_LIST__ = .; *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; + . = ALIGN(16); __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) diff --git a/gnuefi/elf_ia32_efi.lds b/gnuefi/elf_ia32_efi.lds index 0c1f2a7..a84c673 100644 --- a/gnuefi/elf_ia32_efi.lds +++ b/gnuefi/elf_ia32_efi.lds @@ -43,14 +43,17 @@ SECTIONS *(SORT(.init_array.*)) *(.init_array) __init_array_end = .; + . = ALIGN(16); __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) __CTOR_END__ = .; + . = ALIGN(16); __DTOR_LIST__ = .; *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; + . = ALIGN(16); __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) diff --git a/gnuefi/elf_ia32_fbsd_efi.lds b/gnuefi/elf_ia32_fbsd_efi.lds index 0377d4f..61ae5c5 100644 --- a/gnuefi/elf_ia32_fbsd_efi.lds +++ b/gnuefi/elf_ia32_fbsd_efi.lds @@ -52,14 +52,17 @@ SECTIONS *(SORT(.init_array.*)) *(.init_array) __init_array_end = .; + . = ALIGN(16); __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) __CTOR_END__ = .; + . = ALIGN(16); __DTOR_LIST__ = .; *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; + . = ALIGN(16); __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) diff --git a/gnuefi/elf_ia64_efi.lds b/gnuefi/elf_ia64_efi.lds index 46aee72..74014ce 100644 --- a/gnuefi/elf_ia64_efi.lds +++ b/gnuefi/elf_ia64_efi.lds @@ -53,14 +53,17 @@ SECTIONS *(SORT(.init_array.*)) *(.init_array) __init_array_end = .; + . = ALIGN(16); __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) __CTOR_END__ = .; + . = ALIGN(16); __DTOR_LIST__ = .; *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; + . = ALIGN(16); __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) diff --git a/gnuefi/elf_mips64el_efi.lds b/gnuefi/elf_mips64el_efi.lds index 3721c56..a9fe787 100644 --- a/gnuefi/elf_mips64el_efi.lds +++ b/gnuefi/elf_mips64el_efi.lds @@ -40,14 +40,17 @@ SECTIONS *(SORT(.init_array.*)) *(.init_array) __init_array_end = .; + . = ALIGN(16); __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) __CTOR_END__ = .; + . = ALIGN(16); __DTOR_LIST__ = .; *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; + . = ALIGN(16); __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) diff --git a/gnuefi/elf_x86_64_efi.lds b/gnuefi/elf_x86_64_efi.lds index 22409de..0f4b63b 100644 --- a/gnuefi/elf_x86_64_efi.lds +++ b/gnuefi/elf_x86_64_efi.lds @@ -50,14 +50,17 @@ SECTIONS *(SORT(.init_array.*)) *(.init_array) __init_array_end = .; + . = ALIGN(16); __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) __CTOR_END__ = .; + . = ALIGN(16); __DTOR_LIST__ = .; *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; + . = ALIGN(16); __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) diff --git a/gnuefi/elf_x86_64_fbsd_efi.lds b/gnuefi/elf_x86_64_fbsd_efi.lds index 55bed4a..dd10d88 100644 --- a/gnuefi/elf_x86_64_fbsd_efi.lds +++ b/gnuefi/elf_x86_64_fbsd_efi.lds @@ -48,14 +48,17 @@ SECTIONS *(SORT(.init_array.*)) *(.init_array) __init_array_end = .; + . = ALIGN(16); __CTOR_LIST__ = .; *(SORT(.ctors.*)) *(.ctors) __CTOR_END__ = .; + . = ALIGN(16); __DTOR_LIST__ = .; *(SORT(.dtors.*)) *(.dtors) __DTOR_END__ = .; + . = ALIGN(16); __fini_array_start = .; *(SORT(.fini_array.*)) *(.fini_array) From 4c6962457f4ce3f4c18774ce6accd8d20ee29f22 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Thu, 4 May 2023 14:11:37 +0100 Subject: [PATCH 10/14] entry.c: fini_array is run backwards fini_array is 65535 to 0 but stored 0 to 65535 Signed-off-by: Callum Farmer --- lib/entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/entry.c b/lib/entry.c index 1aac667..0ff63fe 100644 --- a/lib/entry.c +++ b/lib/entry.c @@ -43,7 +43,7 @@ static void dtors(void) func(); } - for (funcp *location = (void *)&__fini_array_start; location < (funcp *)&__fini_array_end; location++) { + for (funcp *location = (void *)&__fini_array_end; location > (funcp *)&__fini_array_start; location--) { funcp func = *location; if (*location != NULL) func(); From 7dac18443fdce2cb99ca5f423104c2c22d415a38 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Sat, 6 May 2023 10:42:27 +0100 Subject: [PATCH 11/14] Re-write entry.c/ctors.S to work better * Make entry.c work correctly in reverse order * Remove incorrectly sized (on non-32bit) NULLs from ctors.S Signed-off-by: Callum Farmer --- lib/ctors.S | 5 +---- lib/entry.c | 42 ++++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/ctors.S b/lib/ctors.S index cdd4629..de3f231 100644 --- a/lib/ctors.S +++ b/lib/ctors.S @@ -15,7 +15,6 @@ __init_array_start: .p2align 3, 0 .globl __init_array_end __init_array_end: - .long 0 .section .ctors, "aw", @progbits .p2align 3, 0 .globl __CTOR_LIST__ @@ -23,7 +22,6 @@ __CTOR_LIST__: .p2align 3, 0 .globl __CTOR_END__ __CTOR_END__: - .long 0 .section .dtors, "aw", @progbits .p2align 3, 0 .globl __DTOR_LIST__ @@ -31,7 +29,6 @@ __DTOR_LIST__: .p2align 3, 0 .globl __DTOR_END__ __DTOR_END__: - .long 0 .section .fini_array, "aw", @fini_array .p2align 3, 0 .globl __fini_array_start @@ -39,7 +36,7 @@ __fini_array_start: .p2align 3, 0 .globl __fini_array_end __fini_array_end: - .long 0 + .p2align 3, 0 #if defined(__ELF__) && defined(__linux__) .section .note.GNU-stack,"",%progbits diff --git a/lib/entry.c b/lib/entry.c index 0ff63fe..3baa91d 100644 --- a/lib/entry.c +++ b/lib/entry.c @@ -7,45 +7,51 @@ #include #include +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_start, __init_array_end; -extern UINTN __CTOR_LIST__, __CTOR_END__; -extern UINTN __fini_array_start, __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_start; 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_END__; location > (funcp *)&__CTOR_LIST__; 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_end; location > (funcp *)&__fini_array_start; 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(); } } From e1efa4d70aa17627ee7f2e74e52d09163c9e2d8a Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Wed, 3 May 2023 19:36:41 +0100 Subject: [PATCH 12/14] No clean Signed-off-by: Callum Farmer --- Make.rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Make.rules b/Make.rules index 8cb93b0..b270781 100644 --- a/Make.rules +++ b/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* \ From ba150f34d68e8ddea000bbe4cf64300aec5b80bf Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Sun, 7 May 2023 16:31:32 +0100 Subject: [PATCH 13/14] Add test for ctors & dtors with a priority Signed-off-by: Callum Farmer --- apps/Makefile | 2 +- apps/ctors_dtors_priority_test.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 apps/ctors_dtors_priority_test.c diff --git a/apps/Makefile b/apps/Makefile index 6ebd438..424ee9d 100644 --- a/apps/Makefile +++ b/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 = diff --git a/apps/ctors_dtors_priority_test.c b/apps/ctors_dtors_priority_test.c new file mode 100644 index 0000000..0458c08 --- /dev/null +++ b/apps/ctors_dtors_priority_test.c @@ -0,0 +1,29 @@ +#include +#include + +// 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; +} \ No newline at end of file From 99730f29b2f8874bc7bfad383ea8eb52679e8897 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Thu, 11 May 2023 15:12:36 +0100 Subject: [PATCH 14/14] Structs with no linkage Signed-off-by: Callum Farmer --- lib/dpath.c | 5 +++-- lib/error.c | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/dpath.c b/lib/dpath.c index 5e079d6..63e4e70 100644 --- a/lib/dpath.c +++ b/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}, diff --git a/lib/error.c b/lib/error.c index 2399a06..9f3b230 100644 --- a/lib/error.c +++ b/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"},