Commit Graph

404 Commits

Author SHA1 Message Date
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
Nigel Croxon
637b3bdb9b Author: Callum Farmer <gmbr3@opensuse.org>
Date:   Tue Feb 7 21:48:27 2023 +0000

    ARM32/x86_64 lds: Force data segment align to 4KiB

    Some newer versions of binutils can set invalid COMMONPAGESIZE
    and MAXPAGESIZE values on these architectures

    git fetch git.code.sf.net/u/gmbr3/gnu-efi arm-pagesize
    git merge 89d55b364d

    Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-02-08 09:25:01 -05:00
Callum Farmer
89d55b364d ARM32/x86_64 lds: Force data segment align to 4KiB
Some newer versions of binutils can set invalid COMMONPAGESIZE
and MAXPAGESIZE values on these architectures

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-02-07 21:53:29 +00:00
Callum Farmer
04e6df709d Make.defaults: Force 4K page size on ARM64
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-02-07 21:18:41 +00:00
Callum Farmer
1e00550694 aarch64 lds: Force data segment align to 64KiB
Required by UEFI 2.10 AArch64 specification
https://uefi.org/specs/UEFI/2.10/02_Overview.html#aarch64-platforms

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-02-07 21:18:23 +00:00
Callum Farmer
a90c2f16fa Make.defaults: Enable objcopy on aarch64
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-02-07 16:38:05 +00:00
b'Nigel Croxon
f7b2e1ff6d Merge /u/gmbr3/gnu-efi/ branch master into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/34/
2023-01-20 12:41:14 +00:00
Callum Farmer
593e13937c Make aarch64 crt0/lds more like x86_64
Binutils 2.38 now supports efi-app-aarch64 so
to use this we must add a dummy reloc section
and remove the PE header definition from crt0
as this will conflict with the version added
by objcopy

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-01-19 17:22:19 +00:00
Callum Farmer
231c7632c0 *.efi.lds: Use proper data segment placement
Use ld commands DATA_SEGMENT_ALIGN and DATA_SEGMENT_END

Fixes binutils 2.39 warning:
/usr/bin/ld: warning: efi/fwup.so has a LOAD segment with RWX
permissions

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-01-19 17:22:13 +00:00
Xiaotian Wu
1ba13fdfd0 Add PE machine type definitions for the LoongArch
See https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
2023-01-04 10:31:26 +08:00
b'Nigel Croxon
c2102ae059 Merge /u/mingtaoxt/gnu-efi/ branch master into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/29/
2022-11-16 20:56:17 +00:00
b'Nigel Croxon
156d50d2de Merge /u/fantasquex/gnu-efi/ branch makefile-1 into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/30/
2022-11-16 20:54:10 +00:00
Letu Ren
98f1250742 riscv: Fix ld RWX warning
The current ld script places .dynamic section right after .text, which
results in that one LOAD segment contains both data and code. Binutils
2.39 and later will throw a warning if RWX segments exist. Code and
data should be placed in different LOAD segments with different
permissions. This patch adds a gap between data and code sections which
is taken from the default ld script in riscv64.

Co-developed-by: Moody Liu <mooodyhunter@outlook.com>
Signed-off-by: Moody Liu <mooodyhunter@outlook.com>
Signed-off-by: Letu Ren <fantasquex@gmail.com>
2022-10-10 11:03:20 +02:00
Letu Ren
c26275184c Makefile: Change default target to all
According to README.gnuefi,

To build the sample EFI applications provided in subdirectory "apps",
simply invoke "make" in the toplevel directory (the directory
containing this README file).  This should build lib/libefi.a and
gnuefi/libgnuefi.a first and then all the EFI applications such as a
apps/t6.efi.

The default target of top directory Makefile should be all instead of
gnuefi.

Signed-off-by: Letu Ren <fantasquex@gmail.com>
2022-10-09 18:31:38 +02:00
Dwight Engen
4a566dd746 aarch64: fix setjmp overrun
The assembly code uses fixed offsets into the jmp_buf and leaves an 8 byte
gap between the GPRs and the FPRs, but the jmp_buf structure was not laid
out to account for this so the code would overrun the jmp_buf by 8 bytes.

Found-by: Oskar Engen <oskar.engen@gmail.com>
Signed-off-by: Dwight Engen <dwight.engen@gmail.com>
2022-09-28 12:01:29 -04:00
Nigel Croxon
8b018e6721 Bump revision to VERSION = 3.0.15 2022-08-08 11:38:33 -04:00
Sergei Trofimovich
803b49c40b */*.S: add non-executable GNU stack marking on ELF-linux
binutils-2.39 enabed a few warning by default
(https://sourceware.org/pipermail/binutils/2022-August/122246.html):

> The ELF linker will now generate a warning message if the stack is made executable.

Let's suppress the warnings in assembly files by adding non-executables
stack markings. This fixes at least systemd build which uses '-Wl,--fatal-warnings':

    https://github.com/systemd/systemd/issues/24226
2022-08-08 11:35:10 -04:00
Sergei Trofimovich
2ed6486834 lib/Makefile: add .o file dependency on libsubdirs targets
Without the change there is no guarantee that .o files will be built
after directories are created for them and build fails as:

    gcc -I/build/gnu-efi-code//lib ... -c lib/runtime/rtstr.c -o runtime/rtstr.o
    Assembler messages:
    Fatal error: can't create runtime/rtstr.o: No such file or directory
2022-07-25 10:39:43 -04:00
Fabrice Fontaine
6b28563584 Handle __mips64
Handle __mips64 to avoid a build failure since
b1c7a1c5f2

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-07-25 10:36:14 -04:00
zhoumingtao
5849eacdce use jr instead of jirl
jirl -> jr
2022-07-07 15:16:10 +08:00