~sircmpwn/helios-devel

helios: boot/+aarch64: Include .dynamic and .rel.reloc in PE data v2 PROPOSED

Alexey Yerin: 3
 boot/+aarch64: Include .dynamic and .rel.reloc in PE data
 boot/+aarch64: Set base address to 0
 boot/+aarch64: Apply R_AARCH64_RELATIVE relocations

 4 files changed, 31 insertions(+), 10 deletions(-)
#1059258 .build.yml failed
helios/patches/.build.yml: FAILED in 1m23s

[boot/+aarch64: Include .dynamic and .rel.reloc in PE data][0] v2 from [Alexey Yerin][1]

[0]: https://lists.sr.ht/~sircmpwn/helios-devel/patches/44836
[1]: mailto:yyp@disroot.org

✗ #1059258 FAILED helios/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/1059258
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/helios-devel/patches/44836/mbox | git am -3
Learn more about email & git

[PATCH helios v2 1/3] 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 v2 2/3] boot/+aarch64: Set base address to 0 Export this patch

---
 boot/+aarch64/link.ld | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/boot/+aarch64/link.ld b/boot/+aarch64/link.ld
index e85c02c..eeaac4e 100644
--- a/boot/+aarch64/link.ld
@@ -9,7 +9,7 @@ SECTIONS {
		*(.dynsym .dynstr .hash .gnu.hash)
	}

	. = 0xffff800000000000;
	. = 0x0;

	.text.head : {
		_head = .;
-- 
2.42.0

[PATCH helios v2 3/3] 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 | 21 +++++++++++++++++----
 2 files changed, 24 insertions(+), 4 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..3045f6b 100644
--- a/boot/+aarch64/reloc.ha
@@ -1,8 +1,10 @@
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;

export fn relocate(base: uintptr, dynamic: *[*]elf::dyn64) efi::STATUS = {
	let rela: nullable *[*]elf::rela64 = null,
	    relasz = 0z,
	    relaent = 0z;
@@ -30,9 +32,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): *u64;
			*dest = (base: i64 + ent.r_addend): u64;
		case =>
			return efi::STATUS::LOAD_ERROR;
		};
	};

	return efi::STATUS::SUCCESS;
-- 
2.42.0
helios/patches/.build.yml: FAILED in 1m23s

[boot/+aarch64: Include .dynamic and .rel.reloc in PE data][0] v2 from [Alexey Yerin][1]

[0]: https://lists.sr.ht/~sircmpwn/helios-devel/patches/44836
[1]: mailto:yyp@disroot.org

✗ #1059258 FAILED helios/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/1059258