mirror of https://github.com/ncroxon/gnu-efi
4f8b339fac
This makes setup and teardown functions defined with __attribute__((__constructor__) and __attribute__((__destructor__)) work in normal circumstances in EFI binaries. A couple of notes: - it implements both the old-style .ctors/.dtors methods and the newer style .init_array/.fini_array ELF constructor and destructor arrays, processed in the order: .init_array[] .ctors[] efi_main() .dtors[] .fini_array[] - Destructors will only be called if efi_main() exits using "return"; any call to Exit() will still longjmp() past them. - InitializeLib() has already been called before constructors run, so they don't need to call it (and neither does anything else.) For compatibility, it has been altered so calling it more than once is safe. - No attempt is made to handle any constructor or destructor with a prototype other than "void func(void);", but note that InitializeLib has been called, so LibImageHandle, ST, BS, and RT are set. - The init_array/ctor/dtor/fini_array lists aren't the using the GNU "CONSTRUCTOR" output section command, so they don't start with a size. - The lists are individually sorted during the link stage via SORT_BY_NAME() in the linker script. - The default (empty) init_array/ctor/dtor/fini_array lists are padded out to 8-byte alignment with ".p2align 3, 0", and each list always has at least one ".long 0" at the end of it (even if it's completely empty). As a result, they can have NULLs that need to be skipped. The sections they're in are mergeable, so the NULLs don't have to be exclusively at the end. - The ia64 and mips64el arches have not been tested. Signed-off-by: Peter Jones <pjones@redhat.com> |
||
---|---|---|
.. | ||
Makefile | ||
crt0-efi-aarch64.S | ||
crt0-efi-arm.S | ||
crt0-efi-ia32.S | ||
crt0-efi-ia64.S | ||
crt0-efi-loongarch64.S | ||
crt0-efi-mips64el.S | ||
crt0-efi-riscv64.S | ||
crt0-efi-x86_64.S | ||
elf_aarch64_efi.lds | ||
elf_arm_efi.lds | ||
elf_ia32_efi.lds | ||
elf_ia32_fbsd_efi.lds | ||
elf_ia64_efi.lds | ||
elf_loongarch64_efi.lds | ||
elf_mips64el_efi.lds | ||
elf_riscv64_efi.lds | ||
elf_x86_64_efi.lds | ||
elf_x86_64_fbsd_efi.lds | ||
reloc_aarch64.c | ||
reloc_arm.c | ||
reloc_ia32.c | ||
reloc_ia64.S | ||
reloc_loongarch64.c | ||
reloc_mips64el.c | ||
reloc_riscv64.c | ||
reloc_x86_64.c |