gnu-efi/lib
Peter Jones 4f8b339fac Make ELF constructors and destructors work
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>
2023-03-28 08:59:41 -04:00
..
aarch64 */*.S: add non-executable GNU stack marking on ELF-linux 2022-08-08 11:35:10 -04:00
arm */*.S: add non-executable GNU stack marking on ELF-linux 2022-08-08 11:35:10 -04:00
ia32 */*.S: add non-executable GNU stack marking on ELF-linux 2022-08-08 11:35:10 -04:00
ia64 */*.S: add non-executable GNU stack marking on ELF-linux 2022-08-08 11:35:10 -04:00
loongarch64 use jr instead of jirl 2022-07-07 15:16:10 +08:00
mips64el */*.S: add non-executable GNU stack marking on ELF-linux 2022-08-08 11:35:10 -04:00
riscv64 riscv: Update SPDX license identifiers 2023-03-08 10:32:49 -05:00
runtime Fix CopyMem() not handling overlaps 2021-03-08 14:58:21 -05:00
x86_64 */*.S: add non-executable GNU stack marking on ELF-linux 2022-08-08 11:35:10 -04:00
boxdraw.c The gnu-efi-3.0 toplevel subdirectory is really annoying. Kill it. 2014-11-25 10:09:50 -05:00
cmdline.c Move EFI_SHELL_PARAMETERS_PROTOCOL related definitions to efishell.h 2020-11-15 15:15:18 +08:00
console.c The gnu-efi-3.0 toplevel subdirectory is really annoying. Kill it. 2014-11-25 10:09:50 -05:00
crc.c The gnu-efi-3.0 toplevel subdirectory is really annoying. Kill it. 2014-11-25 10:09:50 -05:00
ctors.S Make ELF constructors and destructors work 2023-03-28 08:59:41 -04:00
data.c Add definitions for the EFI device tree table 2021-07-16 16:36:46 +02:00
debug.c GCC 4.8 (and others) const warnings 2017-01-08 06:52:33 -05:00
dpath.c * Fixed typeo lib/error.c EFI_WARN_UNKNOWN_GLYPH definition. 2019-01-09 07:03:46 -05:00
entry.c Make ELF constructors and destructors work 2023-03-28 08:59:41 -04:00
error.c Define UnicodeSPrint/UnicodeVSPrint as our main SPrint/VSPrint calls 2021-03-08 15:00:14 -05:00
event.c When copying structs, some compilers (e.g. MSVC for ARM) will use an 2016-04-04 10:09:51 -04:00
exit.c add-Exit - Add Exit() library function which calls BS->Exit() 2017-02-17 16:30:28 -05:00
guid.c Define UnicodeSPrint/UnicodeVSPrint as our main SPrint/VSPrint calls 2021-03-08 15:00:14 -05:00
hand.c lib/hand: missing va_end() in LibReinstallProtocolInterfaces() 2021-06-22 00:17:00 +02:00
hw.c Commit 3dd05c and subsequent ones introduced the use of the GNU 2016-03-25 13:32:54 -04:00
init.c Make ELF constructors and destructors work 2023-03-28 08:59:41 -04:00
lock.c The gnu-efi-3.0 toplevel subdirectory is really annoying. Kill it. 2014-11-25 10:09:50 -05:00
Makefile Make ELF constructors and destructors work 2023-03-28 08:59:41 -04:00
misc.c lib/misc: avoid NULL dereference in LibInsertToTailOfBootOrder 2021-06-22 00:17:00 +02:00
pause.c Replace Pause() macro with new library function 2020-07-22 17:49:07 +08:00
print.c Semi-asciibetize _Print()'s formatters. 2023-03-28 08:39:09 -04:00
smbios.c Fix VS2019 Code Analysis warnings 2021-07-16 12:43:24 -04:00
sread.c The gnu-efi-3.0 toplevel subdirectory is really annoying. Kill it. 2014-11-25 10:09:50 -05:00
str.c Fix VS2019 Code Analysis warnings 2021-07-16 12:43:24 -04:00