diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-07-31 21:14:30 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-07-31 21:14:30 +0200 |
commit | 98d5c2ad147330e7b18d4b2ee36eb26cb7e40a84 (patch) | |
tree | 85db02d28842caac142700d3b132aa4b972abd5d | |
parent | 378e17cdd8d36a08fe65041f96de5a80dabf2ce5 (diff) | |
download | bxgen-98d5c2ad147330e7b18d4b2ee36eb26cb7e40a84.zip |
Fix num program headers
-rwxr-xr-x | bxgen.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -2649,7 +2649,7 @@ i64 unit_write_in_memory( emit_unit(pool, codegen, unit, arch); - u16 num_program_headers = 4; + u16 num_program_headers = 5; i64 program_offset = bx_align(ELF_HEADER_SIZE + ELF_PROGRAM_HEADER_SIZE * num_program_headers, X86_64_ALIGNMENT); i64 base_address = X86_64_BASE_ADDRESS; @@ -3198,9 +3198,9 @@ i64 unit_write_in_memory( write_i64(LE, ELF_HEADER_SIZE, h + 32, o_end); // size in file write_i64(LE, ELF_HEADER_SIZE, h + 40, o_end); // size in memory write_i64(LE, X86_64_ALIGNMENT, h + 48, o_end); + h += ELF_PROGRAM_HEADER_SIZE; // r/x code - h += ELF_PROGRAM_HEADER_SIZE; write_u32(LE, 1, h, o_end); // type (PT_LOAD) write_u32(LE, 5, h + 4, o_end); // flags (PF_X | PF_R) write_i64(LE, rxcode_offset, h + 8, o_end); @@ -3209,9 +3209,9 @@ i64 unit_write_in_memory( write_i64(LE, rxcode_size, h + 32, o_end); // size in file write_i64(LE, rxcode_size, h + 40, o_end); // size in memory write_i64(LE, X86_64_ALIGNMENT, h + 48, o_end); + h += ELF_PROGRAM_HEADER_SIZE; // r/w zero values - h += ELF_PROGRAM_HEADER_SIZE; write_u32(LE, 1, h, o_end); // type (PT_LOAD) write_u32(LE, 6, h + 4, o_end); // flags (PF_R | PF_W) write_i64(LE, rwdata_offset, h + 8, o_end); @@ -3220,9 +3220,9 @@ i64 unit_write_in_memory( write_i64(LE, 0, h + 32, o_end); // size in file write_i64(LE, rwzval_size, h + 40, o_end); // size in memory write_i64(LE, X86_64_ALIGNMENT, h + 48, o_end); + h += ELF_PROGRAM_HEADER_SIZE; // r/w data - h += ELF_PROGRAM_HEADER_SIZE; write_u32(LE, 1, h, o_end); // type (PT_LOAD) write_u32(LE, 6, h + 4, o_end); // flags (PF_R | PF_W) write_i64(LE, rwdata_offset, h + 8, o_end); @@ -3231,9 +3231,9 @@ i64 unit_write_in_memory( write_i64(LE, rwdata_size, h + 32, o_end); // size in file write_i64(LE, rwdata_size, h + 40, o_end); // size in memory write_i64(LE, X86_64_ALIGNMENT, h + 48, o_end); + h += ELF_PROGRAM_HEADER_SIZE; // r/o data - h += ELF_PROGRAM_HEADER_SIZE; write_u32(LE, 1, h, o_end); // type (PT_LOAD) write_u32(LE, 4, h + 4, o_end); // flags (PF_R) write_i64(LE, rodata_offset, h + 8, o_end); @@ -3242,8 +3242,10 @@ i64 unit_write_in_memory( write_i64(LE, rodata_size, h + 32, o_end); // size in file write_i64(LE, rodata_size, h + 40, o_end); // size in memory write_i64(LE, X86_64_ALIGNMENT, h + 48, o_end); + h += ELF_PROGRAM_HEADER_SIZE; - CHECK(rxcode_offset >= 288, "Sanity",); + CHECK(h == o + ELF_HEADER_SIZE + num_program_headers * ELF_PROGRAM_HEADER_SIZE, "Sanity",); + CHECK(rxcode_offset >= h - o, "Sanity",); // Code // |