an attempt at function pointers

This commit is contained in:
Folkert 2023-09-17 20:26:25 +02:00
parent 539b98b933
commit 311ae4c7a6
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 125 additions and 19 deletions

View file

@ -1072,12 +1072,34 @@ impl Assembler<AArch64GeneralReg, AArch64FloatReg> for AArch64Assembler {
#[inline(always)]
fn function_pointer(
_buf: &mut Vec<'_, u8>,
_relocs: &mut Vec<'_, Relocation>,
_fn_name: String,
_dst: AArch64GeneralReg,
buf: &mut Vec<'_, u8>,
relocs: &mut Vec<'_, Relocation>,
fn_name: String,
dst: AArch64GeneralReg,
) {
todo!("function pointer for AArch64");
// an `adrp` instruction and an addition to add in the lower bits
buf.extend((0x9000_0000u32 | dst.id() as u32).to_le_bytes());
Self::add_reg64_reg64_imm32(buf, dst, dst, 0);
// with elf
//
// 700: 90000001 adrp x1, 0x0 <std.builtin.default_panic>
// 0000000000000700: R_AARCH64_ADR_PREL_PG_HI21 .rodata+0x650
// 704: 91000021 add x1, x1, #0x0
// 0000000000000704: R_AARCH64_ADD_ABS_LO12_NC .rodata+0x650
//
// with macho
//
// 4dc: 90000001 adrp x1, 0x0 <ltmp0>
// 00000000000004dc: ARM64_RELOC_PAGE21 ___unnamed_6
// 4e0: 91000021 add x1, x1, #0x0
// 00000000000004e0: ARM64_RELOC_PAGEOFF12 ___unnamed_6
// in practice, that just looks a lot like a data relocation
relocs.push(Relocation::LinkedData {
offset: buf.len() as u64 - 8,
name: fn_name,
});
}
#[inline(always)]