Commit Graph

473 Commits

Author SHA1 Message Date
Callum Farmer
74b7b5e92c entry.c: Fix null pointer exception
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-07 16:43:09 +01:00
Callum Farmer
9c5403e1e6 Copy marker names from binutils for init/fini
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 14:29:47 +01:00
Callum Farmer
b3cc412aad entry.c: .ctors is run backwards
Store forwards, run backwards (65535 to 0)
Ref: 5a8e7e1332/ld/scripttempl/elf.sc (L310)
Ref: https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 14:29:47 +01:00
Callum Farmer
e2aa099738 lds: Support ctors/dtors with a priority
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 14:29:36 +01:00
Callum Farmer
4c938fac30 Merge ctors/dtors rela sections
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 13:59:02 +01:00
Callum Farmer
486b1c20c1 Enforce nocombreloc
It is needed to avoid ELF reloc (rela) issues and
to find un-merged reloc sections

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 13:59:02 +01:00
Callum Farmer
97499a0cf2 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 <gmbr3@opensuse.org>
2023-05-04 13:59:02 +01:00
Callum Farmer
9b1e06cd0c Use -std instead of --std
--std isn't standardised. lol.

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 13:59:02 +01:00
Nigel Croxon
24c80efc1a Bump revision to VERSION = 3.0.17 2023-05-02 07:51:45 -04:00
Callum Farmer
bf6fd0405d ia32: No sdata section
There is no small data section on ia32,
this ends up being created as ld puts .got/.got.plt
here due to first declaration

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-21 13:38:17 +01:00
Callum Farmer
fd3d975161 ia32 GNUC: Use __asm__ instead of asm
Causes an error when using strict ISO modes as
then asm isn't defined

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-21 13:30:00 +01:00
Nigel Croxon
ebd55c4a66 Bump revision to VERSION = 3.0.16 2023-04-17 07:43:00 -04:00
b'Nigel Croxon
bc46fbdc84 Merge /u/gmbr3/gnu-efi/ branch TRUEFALSE into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/49/
2023-04-17 11:39:01 +00:00
b'Nigel Croxon
dcced03469 Merge /u/gmbr3/gnu-efi/ branch CHAR16 into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/48/
2023-04-17 11:38:41 +00:00
b'Nigel Croxon
d9275e2a70 Merge /u/gmbr3/gnu-efi/ branch unsigned-char into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/47/
2023-04-17 11:38:06 +00:00
b'Nigel Croxon
362ef3db04 Merge /u/gmbr3/gnu-efi/ branch nullptr into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/46/
2023-04-17 11:37:07 +00:00
b'Nigel Croxon
e0e1f53ce2 Merge /u/gmbr3/gnu-efi/ branch pkgconf2 into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/45/
2023-04-17 11:36:22 +00:00
b'Nigel Croxon
7219aba42c Merge /u/yetist/gnu-efi/ branch dev-master into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/33/
2023-04-17 11:35:08 +00:00
Callum Farmer
2a599ea133 Make TRUE/FALSE compatible with C23/C++
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-15 14:45:19 +01:00
Callum Farmer
056bdaa53e Make VOID a typedef
'void' is a type so VOID can be typedef instead of
 a '#define' to improve compiler output

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-13 14:32:37 +01:00
Callum Farmer
189200d0b0 Make WCHAR and CHAR16 identical
And actually use wchar_t
gnu-efi already uses L string literals which are of type
wchar_t

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-08 20:07:13 +01:00
Callum Farmer
e398748032 ISO-Latin-1 requires unsigned char
It has characters from 0 to 256 so this requires
an unsigned 8 bit value

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-08 19:16:26 +01:00
Callum Farmer
d0900861c2 Make NULL compatible with C23/C++
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-07 14:13:43 +01:00
Callum Farmer
63a9a4d4c0 Add pkgconfig file
Also add EXEC_PREFIX and INCLUDEDIR variables

This was requested by fwupd-efi, to be able
to retrieve the version number of gnu-efi
so we can detect features

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-07 13:51:28 +01:00
b'Nigel Croxon
b6a6472874 Merge /u/gmbr3/gnu-efi/ branch boolean into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/43/
2023-04-04 13:32:29 +00:00
Richard Hughes
7c89273dbe make: Fix shell exit status handling
Right now whenever we have shell commands with loops, errors in the
middle are accidentally ignored, and make continues to process commands.

This adds 'set -e' to all of those, so they'll propagate back up.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-04-04 09:28:42 -04:00
Peter Jones
98ef7f9f5f Use CFLAGS with "gcc -print-libgcc-file-name" to get the right one.
This makes us use CFLAGS when trying to find libgcc, so we don't get the
one with the wrong endian or float ABI.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-04-04 09:28:42 -04:00
Peter Jones
4ee8cf5610 Make: make "make DESTDIR=../foo install" work right.
This makes the normal DESTDIR= variable work on the command line, and
makes relative paths always relative to the top-level directory.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-04-04 09:28:42 -04:00
Peter Jones
4b5db35e9d Implement Print(L"%p", ptr);
Signed-off-by: Peter Jones <pjones@redhat.com>
2023-04-04 09:28:42 -04:00
Callum Farmer
8efd8cde75 Use C/C++ boolean when available
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-04 14:20:31 +01:00
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
Peter Jones
14899d899b Make CHAR8 and similar be defined the same way edk2 does it.
Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:39:26 -04:00
Peter Jones
b9c4b23d90 CFLAGS: add -Wno-pointer-sign
Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:39:19 -04:00
Peter Jones
f7bf4302e4 Semi-asciibetize _Print()'s formatters.
This is ascii order but with upper and lower case letters mixed, so
things like 'X' and 'x' that use fallthrough still stay together.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:39:09 -04:00
Peter Jones
368cdf1265 Switch to -fPIE
Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:38:58 -04:00
Peter Jones
cc4ef911ee Remove the accidentally created lib/Makefile.orig
This was added in dae0b4b0b0.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:38:46 -04:00
Peter Jones
1b94cff100 Fix a minor coverity complaint in some apps
Coverity added a new kind of check, and it noticed some minor errors
with some types in two of the apps here, both of the same form:

1. gnu-efi-3.0.6/apps/lfbgrid.c:91: overflow_before_widen: Potentially
overflowing expression "info->VerticalResolution *
info->PixelsPerScanLine" with type "unsigned int" (32 bits, unsigned) is
evaluated using 32-bit arithmetic, and then used in a context that
expects an expression of type "UINTN" (64 bits, unsigned).

1. gnu-efi-3.0.6/apps/bltgrid.c:67: overflow_before_widen: Potentially
overflowing expression "info->VerticalResolution *
info->HorizontalResolution" with type "unsigned int" (32 bits, unsigned)
is evaluated using 32-bit arithmetic, and then used in a context that
expects an expression of type "UINTN" (64 bits, unsigned).

This resolves both issues.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:38:37 -04:00
Peter Jones
3d82853ffe lfbgrid: Make pointer size testing not arch name dependent 2023-03-28 07:58:51 -04:00
b'Nigel Croxon
5e2444d115 Merge /u/gmbr3/gnu-efi/ branch gc-sections into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/42/
2023-03-23 14:17:28 +00:00
Callum Farmer
bc233a7a4b Prevent deletion of .reloc by gc-sections
Add keyword KEEP to prevent .reloc being removed
when using --gc-sections with GNU ld

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-03-22 15:32:24 +00:00
Callum Farmer
7ad75d9162 Ensure objcopy sections are aligned
Ensure the main sections are page aligned:
 - .text
 - .reloc
 - .dynamic
 - .data
 - .rel
 - .rel.plt

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-03-09 19:52:44 +00:00
bmeng@tinylab.org
0f9c15fe4f riscv: Update SPDX license identifiers
The whole gnu-efi project is licensed under BSD license, see [1].
However some of the RISC-V codes have conflict license identifiers:

- Some mention GPL-2.0+ in the SPDX license part, but the long license
  header indicates it's actually BSD and GPL-2.0+ dual-licensed
- Some mention GPL-2.0+ in the SPDX license part only
- Some do not have any license indication

To have a matching license with the whole project, this commit updates
all RISC-V codes to have the correct SPDX license identifiers
(GPL-2.0+ or BSD dual-license).

Link: https://sourceforge.net/p/gnu-efi/ [1]
Signed-off-by: Bin Meng <bmeng@tinylab.org>
Acked-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2023-03-08 10:32:49 -05:00
Callum Farmer
1a10c66182 Un-merge .rel.plt section
Merging this section causes an incorrect RELASZ value
2023-03-07 22:47:37 +00:00
b'Nigel Croxon
75e4ef25ad Merge /u/gmbr3/gnu-efi/ branch fix-apps into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/39/
2023-03-07 13:46:37 +00:00
b'Nigel Croxon
330c88aa0c Merge /u/gmbr3/gnu-efi/ branch function-sections into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/38/
2023-03-07 13:45:45 +00: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
Callum Farmer
02f96e8a26 *.efi.lds: Add .rel.dyn section
LLVM LLD always calls it .rel[a].dyn no matter what
so add this to the .rel[a] section

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-03-04 17:57:39 +00:00
Callum Farmer
15f10734e7 Add some COMDAT sections
When using function/data sections option from
gcc, some additional un-packed sections get created
move these to there correct placement if not already
included

sections seen on x86/x86_64/aarch64:
.gcc_except_table.efi_main
.bss.debugging

.gcc_except_table.* only appears on objcopy archs

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-03-03 21:00:32 +00:00
b'Nigel Croxon
d78b78cb2e Merge /u/gmbr3/gnu-efi/ branch merge-rela2 into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/37/
2023-02-22 13:42:44 +00:00
Callum Farmer
eea6d31a22 *.efi.lds: Merge all rela sections into one
Objcopy sometimes generates .rela.plt and .rela.data
sections for which their names are longer than the 8
characters limit of PE32

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-02-21 11:57:47 +00:00