From f89a887bd04d060bf03a8d9f76da8686dc79d9d1 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Wed, 24 Jul 2024 16:37:32 +0200 Subject: Relocations --- bxgen.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bxgen.c b/bxgen.c index 4234631..be2b5d0 100755 --- a/bxgen.c +++ b/bxgen.c @@ -358,6 +358,7 @@ typedef struct { c8 *name; i64 section; i64 address; + i64 size; } Internal_Symbol_Entry; // Pool, a collection of all entities. @@ -2302,6 +2303,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data .name = sym_name, .section = sym_section, .address = sym_address, + .size = sym.value.size, }; u8 *begin = buf.begin + tab.data.offset + sym_index * ELF_SYMBOL_ENTRY_SIZE; @@ -2421,6 +2423,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data symbol = (Internal_Symbol_Entry) { .section = sec_index_global, .address = relx.symbol.value.offset, + .size = relx.symbol.value.size, }; u8 *dst = buf.begin + elf_section(buf, dst_index).data.offset + relx.offset; @@ -2446,6 +2449,9 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data // Represents the value of the symbol whose index resides in the relocation entry. i64 S = symbol.address; + // The size of the symbol whose index resides in the relocation entry. + i64 Z = symbol.size; + switch (relx.type) { #define ADD_(BITS, OP) \ do { \ @@ -2481,14 +2487,14 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data case R_X86_64_TPOFF32: ADD_(32, S + A - B); break; case R_X86_64_PC64: ADD_(64, S + A - P); break; case R_X86_64_GOTOFF64: TODO_; break; - case R_X86_64_GOTPC32: TODO_; break; + case R_X86_64_GOTPC32: ADD_(32, GOT + A - P); break; case R_X86_64_GOT64: TODO_; break; case R_X86_64_GOTPCREL64: TODO_; break; - case R_X86_64_GOTPC64: TODO_; break; + case R_X86_64_GOTPC64: ADD_(64, GOT + A - P); break; case R_X86_64_GOTPLT64: TODO_; break; case R_X86_64_PLTOFF64: TODO_; break; - case R_X86_64_SIZE32: TODO_; break; - case R_X86_64_SIZE64: TODO_; break; + case R_X86_64_SIZE32: ADD_(32, Z + A); break; + case R_X86_64_SIZE64: ADD_(64, Z + A); break; case R_X86_64_GOTPC32_TLSDESC: TODO_; break; case R_X86_64_TLSDESC_CALL: TODO_; break; case R_X86_64_TLSDESC: TODO_; break; -- cgit v1.2.3