[PATCH helios 1/2] boot/+aarch64: Include .dynamic and .rel.reloc in PE data
Export this patch
---
boot/+aarch64/link.ld | 11 ++++++ -----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/boot/+aarch64/link.ld b/boot/+aarch64/link.ld
index b0b9b06..e85c02c 100644
--- a/boot/+aarch64/link.ld
@@ -3,7 +3,6 @@ OUTPUT_FORMAT(elf64-littleaarch64)
SECTIONS {
/DISCARD/ : {
- *(.rel.reloc)
*(.eh_frame)
*(.note.GNU-stack)
*(.interp)
@@ -28,10 +27,6 @@ SECTIONS {
. = ALIGN(64K);
_etext = .;
- .dynamic : {
- *(.dynamic)
- }
-
.data : ALIGN(64K) {
_data = .;
KEEP(*(.data))
@@ -53,6 +48,9 @@ SECTIONS {
. += 512 * 8;
}
+ .dynamic : {
+ *(.dynamic)
+ }
.rela.text : {
*(.rela.text)
*(.rela.text*)
@@ -70,6 +68,9 @@ SECTIONS {
*(.rela.data)
*(.rela.data*)
}
+ .rel.reloc : {
+ *(.rel.reloc)
+ }
.pecoff_edata_padding : {
BYTE(0);
--
2.42.0
[PATCH helios 2/2] boot/+aarch64: Apply R_AARCH64_RELATIVE relocations
Export this patch
This fixes string literals after harec@219d934 (generate string constants using
gen_data_item)
---
boot/+aarch64/Makefile | 7 +++++++
boot/+aarch64/reloc.ha | 26 +++++++++++++++++++++ -----
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/boot/+aarch64/Makefile b/boot/+aarch64/Makefile
index 21963a8..836f841 100644
--- a/boot/+aarch64/Makefile
@@ -19,6 +19,7 @@ BOOT_OBJS=\
$(BOOT)/header.o \
$(BOOT)/boot.o \
$(BOOT)/lib_efi.o \
+ $(BOOT)/lib_elf.o \
$(BOOT)/lib_endian.o \
$(BOOT)/lib_cons.o \
$(BOOT)/lib_types.o \
@@ -94,6 +95,12 @@ BYTES_SRC=\
$(BOOT)/lib_bytes.o: $(BYTES_SRC)
HAREPATH=. $(HARE) build $(HARECONFIG) -to -N bytes -o $@ bytes
+ ELF_SRC=\
+ elf/types.ha
+
+ $(BOOT)/lib_elf.o: $(ELF_SRC)
+ HAREPATH=. $(HARE) build $(HARECONFIG) -to -N elf -o $@ elf
+
ENDIAN_SRC=\
endian/big.ha \
endian/endian.ha \
diff --git a/boot/+aarch64/reloc.ha b/boot/+aarch64/reloc.ha
index 8499935..5fdb5d9 100644
--- a/boot/+aarch64/reloc.ha
@@ -1,8 +1,13 @@
use elf;
use efi;
- export fn relocate(base: uintptr, dynamic: *opaque) efi::STATUS = {
- let dynamic = dynamic: *[*]elf::dyn64;
+ // https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#5712dynamic-relocations
+ def R_AARCH64_RELATIVE: u64 = 1027;
+
+ // See boot/+aarch64/link.ld
+ def BINARY_BASE = 0xffff800000000000: uintptr;
+
+ export fn relocate(base: uintptr, dynamic: *[*]elf::dyn64) efi::STATUS = {
let rela: nullable *[*]elf::rela64 = null,
relasz = 0z,
relaent = 0z;
@@ -11,7 +16,7 @@ export fn relocate(base: uintptr, dynamic: *opaque) efi::STATUS = {
switch (dynamic[i].d_tag) {
case elf::dt::RELA =>
if (dynamic[i].d_ptr != 0) {
- rela = (base + dynamic[i].d_ptr: uintptr): *[*]elf::rela64;
+ rela = (base + (dynamic[i].d_ptr: uintptr - BINARY_BASE)): *[*]elf::rela64;
};
case elf::dt::RELASZ =>
relasz = dynamic[i].d_val: size;
@@ -30,9 +35,20 @@ export fn relocate(base: uintptr, dynamic: *opaque) efi::STATUS = {
return efi::STATUS::LOAD_ERROR;
};
- const rela = rela: *[*]elf::rela64; // We're sure this is not null
+ if (relaent != size(elf::rela64)) {
+ return efi::STATUS::LOAD_ERROR;
+ };
+
+ const rela = rela: *[*]elf::rela64;
for (let i = 0z; i * relaent < relasz; i += 1) {
- abort(); // XXX: TODO
+ const ent = rela[i];
+ switch (elf::r64_type(ent.r_info)) {
+ case R_AARCH64_RELATIVE =>
+ const dest = (base + (ent.r_offset: uintptr - BINARY_BASE)): *u64;
+ *dest = (base: i64 + (ent.r_addend - BINARY_BASE: i64)): u64;
+ case =>
+ return efi::STATUS::LOAD_ERROR;
+ };
};
return efi::STATUS::SUCCESS;
--
2.42.0
helios/patches/.build.yml: FAILED in 39s
[boot/+aarch64: Include .dynamic and .rel.reloc in PE data][0] from [Alexey Yerin][1]
[0]: https://lists.sr.ht/~sircmpwn/helios-devel/patches/44826
[1]: mailto:yyp@disroot.org
✗ #1059140 FAILED helios/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/1059140