diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-07-12 05:00:57 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-07-12 05:00:57 +0200 |
commit | 28f2b93e4b8128cab724e930f8aeae211a7144e5 (patch) | |
tree | 41e6243e205e9257197f70dbff0bde659b0f2d41 | |
parent | 9018ec15f750aa01ff090c9e2d80da6aea2e70dd (diff) | |
download | bxgen-28f2b93e4b8128cab724e930f8aeae211a7144e5.zip |
Decode relocations
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | bxgen.c | 79 | ||||
-rw-r--r-- | libtest.a | bin | 1364 -> 1790 bytes |
3 files changed, 63 insertions, 17 deletions
@@ -1 +1,2 @@ test* +/bxgen @@ -6,8 +6,8 @@ gcc \ -Wno-missing-field-initializers -Wno-missing-braces \ -Wall -Wextra -Werror -pedantic \ -O0 -fsanitize=undefined,address,leak -mshstk \ - -o $BIN.tmp $SRC && \ - ./$BIN.tmp $@ && rm $BIN.tmp + -o $BIN $SRC && \ + ./$BIN $@ exit $? #endif @@ -40,6 +40,7 @@ exit $? // - String table for names and arrays // - Proper error handling // - Proper prefixes for identifiers +// - Correct serialization for endianness // - Effective entity allocation // - Implicit procedure prototypes // - Implicit exit after ret from entry point @@ -716,32 +717,44 @@ void unit_set_entry_point(Pool *pool, i64 unit, i64 entry_point_proc) { #include <stdio.h> // TEMP #include <stdlib.h> // TEMP +// TODO + enum { - MAX_SECTION_SIZE = 1024 * 1024 * 10, - MAX_INPUT_SIZE = 1024 * 1024 * 100, - MAX_RELOCATIONS = 1024 * 10, - MAX_INPUT_SECTIONS = 1024 * 10, + MAX_SECTION_SIZE = 1024 * 1024 * 10, + MAX_SYMBOL_NAME_SIZE = 1024, + MAX_INPUT_SIZE = 1024 * 1024 * 100, + MAX_SYMBOLS = 1024 * 100, + MAX_RELOCATIONS = 1024 * 100, + MAX_INPUT_SECTIONS = 1024 * 10, }; typedef struct { - i64 memory_address; - i64 file_offset; + i64 address_in_memory; + i64 offset_in_file; i64 size; u8 bytes[MAX_SECTION_SIZE]; } Section; typedef struct { i64 src_section; - i64 src_file_offset; + i64 src_offset_in_file; + i64 src_size; + i64 name_size; + c8 name[MAX_SYMBOL_NAME_SIZE]; +} Symbol; + +typedef struct { + i64 src_section; + i64 src_offset_in_file; i64 src_size; i64 dst_section; - i64 dst_memory_address; + i64 dst_address_in_memory; } Relocation; typedef struct { - i64 object_index; - i64 section_index; - i64 file_offset; + i64 object; + i64 section; + i64 offset_in_file; i64 size; } Input_Section_Info; @@ -750,6 +763,8 @@ typedef struct { Section read_only; Section read_write; Section zero_init; + i64 symbols_size; + Symbol symbols[MAX_SYMBOLS]; i64 relocs_size; Relocation relocs[MAX_RELOCATIONS]; i64 input_raw_size; @@ -1405,6 +1420,38 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data // Relocarions with addends case 4: { + BX_ASSERT(entsize == 24); + + i64 prev_offset = current_offset; + i64 prev_byte_count = byte_count; + io_seek(f, begin_offset + offset, IO_SEEK_BEGIN, io_user_data); + current_offset = begin_offset + offset; + + printf("\n"); + + for (byte_count = size; byte_count > 0;) { + u64 rela_offset; + u64 rela_info; + i64 rela_addent; + + READ(rela_offset); BX_ASSERT(n != 0); + READ(rela_info); BX_ASSERT(n != 0); + READ(rela_addent); BX_ASSERT(n != 0); + + u32 rela_sym = (u32) (rela_info >> 32); + u32 rela_type = (u32) (rela_info & 0xffffffff); + + printf(" "); + + printf("%08llx sym %-2d type %-2d add %-2lld", rela_offset, rela_sym, rela_type, rela_addent); + printf("\n"); + } + + printf("\n"); + + io_seek(f, prev_offset, IO_SEEK_BEGIN, io_user_data); + current_offset = prev_offset; + byte_count = prev_byte_count; } break; // ================================================================ @@ -1673,10 +1720,8 @@ int main(int argc, char **argv) { (void) argc; (void) argv; - printf("node - %d bytes\n", (i32) sizeof(Node)); - printf("proc - %d bytes\n", (i32) sizeof(Proc)); - printf("unit - %d bytes\n", (i32) sizeof(Unit)); - printf("entity - %d bytes\n\n", (i32) sizeof(Entity)); + printf("entity - %d bytes\n", (i32) sizeof(Entity)); + printf("binary output buffer - %d MB\n\n", (i32) sizeof(Binary_Output) / (1024 * 1024)); i64 main = p_new("main"); i64 n0 = n_i64(42); Binary files differ |