From 890e888ebc27c27f14580ac4bacde8a0ff9a5828 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Wed, 24 Jul 2024 08:53:37 +0200 Subject: Relocations (incomplete) --- bxgen.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/bxgen.c b/bxgen.c index d478699..2bc5e6a 100755 --- a/bxgen.c +++ b/bxgen.c @@ -2432,7 +2432,9 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data u8 *begin = buf.begin + tab.data.offset + sym_index * ELF_SYMBOL_ENTRY_SIZE; u8 *end = begin + tab.data.size; - write_i64(LE, pool->section_offsets[sec_index] + sym.value.offset, begin + 8, end); + i64 sym_address = base_address + data_offset + pool->section_offsets[sec_index] + sym.value.offset; + + write_i64(LE, sym_address, begin + 8, end); } } } @@ -2463,8 +2465,6 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data BX_CHECK(dst_index >= 0 && dst_index < pool->max_num_sections, "Buffer overflow",); - i64 dst_address = base_address + data_offset + pool->section_offsets[dst_index]; - switch (src_sec.type) { case SEC_REL: { for (i64 rel_index = 0; rel_index < src_sec.num_entries; ++rel_index) { @@ -2609,16 +2609,25 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data BX_FAIL("Not implemented",); } break; case R_X86_64_64: { + // TODO BX_FAIL("Not implemented",); } break; case R_X86_64_PC32: { - BX_FAIL("Not implemented",); + // TODO + i64 x = + read_i32(LE, buf.begin + dst.offset, buf.end) + + rela.symbol.value.offset + rela.addent; + write_i32(LE, x, buf.begin + dst.offset, buf.end); } break; case R_X86_64_GOT32: { BX_FAIL("Not implemented",); } break; case R_X86_64_PLT32: { - BX_FAIL("Not implemented",); + // TODO + i64 x = + read_i32(LE, buf.begin + dst.offset, buf.end) + + rela.symbol.value.offset + rela.addent; + write_i32(LE, x, buf.begin + dst.offset, buf.end); } break; case R_X86_64_COPY: { BX_FAIL("Not implemented",); @@ -2633,7 +2642,8 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data BX_FAIL("Not implemented",); } break; case R_X86_64_GOTPCREL: { - BX_FAIL("Not implemented",); + // TODO + //BX_FAIL("Not implemented",); } break; case R_X86_64_32: { BX_FAIL("Not implemented",); @@ -2672,7 +2682,8 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data BX_FAIL("Not implemented",); } break; case R_X86_64_GOTTPOFF: { - BX_FAIL("Not implemented",); + // TODO + //BX_FAIL("Not implemented",); } break; case R_X86_64_TPOFF32: { BX_FAIL("Not implemented",); @@ -2726,7 +2737,8 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data BX_FAIL("Not implemented",); } break; case R_X86_64_REX_GOTPCRELX: { - BX_FAIL("Not implemented",); + // TODO + //BX_FAIL("Not implemented",); } break; default: BX_LAX(0, "Unknown relocation type"); -- cgit v1.2.3