Commit Graph

80 Commits

Author SHA1 Message Date
Callum Farmer
618037c0cb
Update GPL-2.0 SPDX notation
GPL-2.0+ is now GPL-2.0-or-later

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-09-16 15:37:18 +01:00
Callum Farmer
f505aa71e6
Add missed clean-up for FreeBSD
Missed from ncroxon/gnu-efi@13c46e46a6

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-08-19 14:00:13 +01:00
Callum Farmer
13c46e46a6
Sync FreeBSD
* Always use objcopy -O (--target doesn't make sense)
  and isn't available on freebsd
* No efi-bsdrv target (but has efi-app)(bug in binutils??)
* Sync linker scripts (all features are supported)
* Use clang as HOSTCC (there is no default gcc)

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-08-03 16:21:00 +01:00
Callum Farmer
e092a94869
Add non-objcopy IA32 crt0/lds
* Needed by embedded (MacOS) ELF toolchain

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-07-16 14:49:52 +01:00
Callum Farmer
644e03821e
Tune for new MacOS toolchains
* Doesn't seem to like nocombreloc
* i686 doesn't have the efi-app-ia32 target (bug in binutils??)
* Set float manually on ARM32 due to generic toolchain
* Ensure _DYNAMIC symbol exists

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-07-16 14:49:52 +01:00
Callum Farmer
b6f99c7ac5
Add substitute elf.h for macOS
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-07-14 18:50:39 +01:00
Callum Farmer
2765122e67
X86_64: We use RELA not REL
Weird huh? GNU ld uses RELA but no addends, as soon as
you get an addend from LLD, this code breaks

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-07-04 15:44:02 +01:00
Callum Farmer
0c0b91b9f9
PC file missing from clean
The pkgconfig file was not being removed
by clean, add the missing statement

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-07-04 15:44:01 +01:00
Callum Farmer
353984bb97
Move riscv64 default to objcopy
Fixes ncroxon/gnu-efi#11

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-07-04 15:44:01 +01:00
Callum Farmer
23715d6389
Restore non-objcopy ARM64 crt0/lds
* An up-to-date version of it anyways
* Useful for systems without objcopy 2.38+

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-07-04 15:44:01 +01:00
Pete Batard
eeb0e6a830
Fix RISCV64 not setting the subsystem according to EFI_SUBSYSTEM
The RISCV64 toolchain does not support 16-bit variable relocation from assembly,
and even if it did support relocations, it would not properly set the subsystem
from --defsym. So we add an extra step on RISCV64, post objcopy, to set the field
manually (using dd and /bin/echo to output the relevant byte, as GNU Make's echo
does not support -ne).
Closes ncroxon/gnu-efi#27.

Signed-off-by: Pete Batard <pete@akeo.ie>
2024-05-24 10:29:49 +01:00
Pete Batard
2d6d426b8c
Enable silent rules for compiler output
This is similar to using automake's silent rules and, just as with automake,
can be disabled by invoking 'make V=1'.

Signed-off-by: Pete Batard <pete@akeo.ie>
2024-05-21 11:45:20 +01:00
Callum Farmer
1e8900a92b
Switch everything to Unix line endings
I wondered why a patch didn't apply :(

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-05-19 14:22:26 +01:00
Callum Farmer
8ad6c33424
PC: Add useful variables
* Add efi_machine_type_name and gnu_efi_arch from fwupd-efi

* Add gnu_efi_default_is_objcopy so downstreams know if the crt0 goes objcopy

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-05-19 14:22:11 +01:00
Richard Hughes
8272cd905e
Replace 'Copright' with 'Copyright' in file headers
This was hopefully just a typo that has been cargo-culted around the codebase.

It certainly confuses the Red Hat license checker and makes the code copyright
clear.
2024-05-07 13:03:52 +01:00
Callum Farmer
c7ee41c6c4
lds: Add eh_frame_hdr section
A new section has appeared, move it to the correct place
Copy of fwupd/fwupd-efi#59

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-04-01 16:04:02 +01:00
Peter Jones
31913f8489 Make: make TOPDIR actually work and get rid of unused CDIR
Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
2024-03-22 10:24:28 -04:00
Peter Jones
95dbde278c make: Make "make clean" use @ and rm -v everywhere
This makes our "make clean" commands show what they've /removed/, rather
than what the shell code that will be run is.

Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
2024-03-22 10:24:28 -04:00
Callum Farmer
e2355ed7fb Remove 64k gap on ARM32
While binutils 2.25 incorrectly changed the page size
to 64K, the second part of that fix prevents the bug
anyways

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:24:28 -04:00
Callum Farmer
792715e5e9 arm64 lds: move 64K gap to reloc
The PE32 header means code ends at end of text, unlike
ELF where its mostly dynamic

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:24:28 -04:00
Xiaotian Wu
feedeaa339 Make loongarch64 use efi-app-loongarch64
Binutils 2.41 now supports efi-app-loongarch64, 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: Xiaotian Wu <wuxiaotian@loongson.cn>
2024-03-22 10:24:23 -04:00
Callum Farmer
fb58e92621 ARM32: Only use 4K pages
Turns out some linkers have set page size to 64K on ARM32 aswell
so apply the same fix as ARM64

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:24:19 -04:00
Callum Farmer
fb3b3f4c66 riscv64: ignore unknown relocs
Sometimes ld emits relocs such as R_RISCV_64 for unwind symbols
these don't need to be handled yet so just can be skipped otherwise
the binary will never load

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:08:37 -04:00
Callum Farmer
4cdcf2a37b riscv64: fix image
- Make it actually work
- Split text/data/reloc/rodata sections
- Move hash sections to past end of image
  (un-needed in PE)
- Correct section & file alignment
- Correct image size

Builds correctly but untested

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:08:24 -04:00
Callum Farmer
eadee98bf0 ARM32: fix image
- Make it actually work
- Split text/data/reloc/rodata sections
- Move hash sections to past end of image
  (un-needed in PE)
- Correct section & file alignment
- Correct image size
- rename .reloc to .areloc within ELF
  as only on ARM32 does this name cause
  it to be marked as REL and subsequently
  mistakenly added to RELSZ

Builds correctly & tested working in QEMU

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:07:56 -04:00
Callum Farmer
0bb329b0bf Merge .plt into .text
ld writes .plt immediately after .text
which corrupts the alignment of .reloc

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:07:53 -04:00
Callum Farmer
262c1f4604 Split out rodata
rodata should be split for security

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:07:49 -04:00
Callum Farmer
0209271936 Clean up size symbols
Tells ld to define them after their markers

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:43 -04:00
Callum Farmer
db870d96d6 Mark _start as function
Currently marked as NOTYPE

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:43 -04:00
Callum Farmer
18d53408ff ARM32: _start must be global
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:43 -04:00
Callum Farmer
2dcebec0ce Add full Data Directories table
Microsoft dumpbin doesn't like the binary if
the full table doesn't exist

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:43 -04:00
Callum Farmer
bfa3cead95 ARM32: fix L_DYNAMIC
L_DYNAMIC must be 32bits to be PCREL

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:43 -04:00
Callum Farmer
dd82a45499 riscv: Use new ctors _entry func as entry point
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:43 -04:00
Callum Farmer
6c142a6df4 riscv64 lds: fix ctors/dtors
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:43 -04:00
Callum Farmer
a68997b11e riscv: Avoid TEXTREL
Use expression instead of variable for _data_size

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:38 -04:00
Callum Farmer
6f0648992a Avoid processor dependent sizes in assembly
.word -> .2byte
.short -> .2byte
.long -> .4byte
.quad -> .8byte

Reference: b83f0845b5
Fixes: https://sourceforge.net/p/gnu-efi/bugs/37/

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:05:31 -04:00
Callum Farmer
9dbfe1c365 Align all ctors/dtors start to 16
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-07 16:43:19 +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
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
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
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
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
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
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
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