Commit Graph

8 Commits

Author SHA1 Message Date
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
Callum Farmer
3f9a656929 apps: Fix Makefile install and ordering
Create a new directory called $APPSDIR
which is the default install location of
these examples. apps must be ordered after
gnuefi target.

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-03-06 13:36:27 +00:00
Peter Jones
b030bfce35 Add debug helper applications
Add debug helper applications.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
2018-03-14 14:50:23 -04:00
Peter Jones
5ec879ace7 apps: Add bltgrid and lfbgrid, and add error checks to modelist
This adds bltgrid and lfbgrid, which draw checkerboards using GOP's
Blt() and linear framebuffer, respectively, and adds some error checks
to modelist.efi.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
2018-03-14 14:50:23 -04:00
Nigel Croxon
049a863e14 Fixed build issue with apps/exit.c
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
2017-02-17 16:31:39 -05:00
Nigel Croxon
11a459ba96 This patch makes the following symbols (relatively) consistent between
all of our linker scripts:

_text
_etext
_text_size
_data
_edata
_data_size

There are various things that are slightly different (positions of
.rela*, .dynamic, and similar in relation to .data), but _text and _data
are now always at the beginning of their respective sections with regard
to how a debuger would reference the debug info, and _etext and _edata
are now always extant and guaranteed to be after any of the respective
kind of data the debugger would look for in that section.

This also adds an application example of how it might be used, and a
makefile target for %.efi.debug which will generate a separate debuginfo
file for that example.

This also enables debugging by default (i.e. -g is in CFLAGS) and adds
.note.gnu.build-id sections to our .so files (i.e. --build-id=sha1 is in
LDFLAGS).

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Nigel Croxon <nigel.croxon@hp.com>
2015-07-16 12:31:23 -04:00
Nigel Croxon
dae0b4b0b0 Turns out we actually need setjmp in one of gnu-efi's prominent
users, and it seems to make more sense to put it here than in
the application.

All of these are derived from the Tiano code, but I re-wrote the
x86_64 one because we use the ELF psABI calling conventions instead
of the MS ABI calling conventions.  Which is to say you probably
shouldn't setjmp()/longjmp() between functions with EFIAPI (aka
__attribute__((ms_abi))) and those without.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Nigel Croxon <nigel.croxon@hp.com>
2015-05-14 12:20:51 -04:00
Nigel Croxon
530d68ba19 The gnu-efi-3.0 toplevel subdirectory is really annoying. Kill it.
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Nigel Croxon <nigel.croxon@hp.com>
2014-11-25 10:09:50 -05:00