Commit Graph

90 Commits

Author SHA1 Message Date
Callum Farmer be2888790f
Align CRT0 exit function naming
Align it to .L_exit
Also more useful as a local symbol than a non descriptive local label

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-11-03 15:41:33 +00:00
Callum Farmer aa58dc8ff1
Remove label1
No longer needed

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-10-30 11:13:49 +00:00
Callum Farmer 03bfe2f5ce
Push .reloc after .data
Seems GNU ld is a bit stupid in this regard
Apply to all archs incase this is repeated so far
only seen on ARM64

Fixes ncroxon/gnu-efi#47

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-10-28 15:52:57 +00:00
Callum Farmer 882df4e732
ia32 local: Remove accidental rela
REL not RELA

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-10-24 12:33:00 +01:00
Callum Farmer 40b0203116
ia32 local: Rename reloc to areloc
* Similar to ARM32, this triggers a GNU AS section parameters warning if called reloc
* This breaks IA32 objcopy due to .reloc lookup

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-10-24 12:33:00 +01:00
Callum Farmer ae94e383a3
Make our dummy .reloc sections not depend on section order.
Currently on x64 we manually build a dummy .reloc table entry by using a
symbol in .text and subtracting its address from another symbol that's
inside the .reloc section.  On ia32 we just use its location.  In either
case, if the linker puts either section in a location we're not
expecting, the .reloc table winds up having invalid values, and the PE
loader will fail to load the binary.

This changes it to be two symbols that are both in .text, making the
result unrelated to the section order or location.

It's not clear to me that these .reloc entries are actually necessary at
all, but I'm going to leave them in place for now, in case they are.

Ref: rhboot/gnu-efi@9fb55dee2b
Co-authored-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-10-24 12:33:00 +01:00
Callum Farmer aa2ad0329b
Fix calling of gnuefi install with local lds
* Local lds wasn't being installed on RISC-V

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-09-24 14:24:03 +01:00
Callum Farmer 21ea877a01
IA32 local: Fix up crt0 symbols
* This should use a fully split version of the CRT0 not the old ARM un-split version

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-09-24 13:28:41 +01:00
Callum Farmer e9b6ac7126
ARM64 local: Remove NR_SECTIONS
* NR_SECTIONS is part of the crt0 generator for fwupd-efi
* This isn't implemented here

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-09-24 13:28:41 +01:00
Callum Farmer 24a4cd0e56
ARM32: Split headers and code
* Force code to be at known dest of 4096
* Move _start into .text
* Load the _start symbol address and then minus 4096 to get the load
  address

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-09-24 13:28:41 +01:00
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