summaryrefslogtreecommitdiff
path: root/bxgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'bxgen.c')
-rwxr-xr-xbxgen.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/bxgen.c b/bxgen.c
index 24c1f4e..27c37ce 100755
--- a/bxgen.c
+++ b/bxgen.c
@@ -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
//