diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-08-01 08:32:03 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-08-01 08:32:03 +0200 |
commit | cfa77100929e31771730e964f63ff28b0e6ce387 (patch) | |
tree | 1695931a9a44e423b5bf4cfa9488f69664a6d6f2 /bxgen.c | |
parent | b33fbbc22c895e6553331c29cc6856208ff16dc4 (diff) | |
download | bxgen-cfa77100929e31771730e964f63ff28b0e6ce387.zip |
TLS segments
Diffstat (limited to 'bxgen.c')
-rwxr-xr-x | bxgen.c | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -2575,8 +2575,8 @@ i64 unit_write_in_memory( i64 rw_zval_size = 0; i64 rw_data_size = 0; i64 ro_data_size = codegen->offset_ro_data; - i64 rw_tls_zval_size = 0; i64 rw_tls_data_size = 0; + i64 rw_tls_zval_size = 0; i64 rw_got_size = ELF_GOT_ENTRY_SIZE; i64 rw_dynamic_size = ELF_DYNAMIC_ENTRY_SIZE; @@ -2676,8 +2676,8 @@ i64 unit_write_in_memory( i64 rw_zval_address = align(rx_code_address + rx_code_size, X86_64_PAGE_SIZE); i64 rw_data_address = align(rw_zval_address + rw_zval_size, X86_64_PAGE_SIZE); i64 ro_data_address = align(rw_data_address + rw_data_size, X86_64_PAGE_SIZE); - i64 rw_tls_zval_address = align(ro_data_address + ro_data_size, X86_64_PAGE_SIZE); - i64 rw_tls_data_address = align(rw_tls_zval_address + rw_tls_zval_size, X86_64_PAGE_SIZE); + i64 rw_tls_data_address = align(ro_data_address + ro_data_size, X86_64_PAGE_SIZE); + i64 rw_tls_zval_address = align(rw_tls_data_address + rw_tls_data_size, X86_64_PAGE_SIZE); i64 rx_code_offset = program_offset; i64 rw_data_offset = align(rx_code_offset + rx_code_size, X86_64_PAGE_SIZE); @@ -3242,8 +3242,8 @@ i64 unit_write_in_memory( LOG(VERBOSE, "r/w zval - %7lld bytes", rw_zval_size); LOG(VERBOSE, "r/w data - %7lld bytes", rw_data_size); LOG(VERBOSE, "r/o data - %7lld bytes", ro_data_size); - LOG(VERBOSE, "r/w TLS zval - %7lld bytes", rw_tls_zval_size); LOG(VERBOSE, "r/w TLS data - %7lld bytes", rw_tls_data_size); + LOG(VERBOSE, "r/w TLS zval - %7lld bytes", rw_tls_zval_size); LOG(VERBOSE, "r/w GOT - %7lld bytes", rw_got_size); LOG(VERBOSE, "r/w dynamic - %7lld bytes", rw_dynamic_size); @@ -3343,14 +3343,15 @@ i64 unit_write_in_memory( write_i64(LE, X86_64_ALIGNMENT, h + 48, o_end); h += ELF_PROGRAM_HEADER_SIZE; - // r/w TLS zero values - write_u32(LE, 7, h, o_end); // type (PT_TLS) + // TLS segment + i64 tls_size = rw_tls_zval_size + rw_tls_data_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, rw_tls_data_offset, h + 8, o_end); - write_i64(LE, rw_tls_zval_address, h + 16, o_end); // virtual address - write_i64(LE, rw_tls_zval_address, h + 24, o_end); // phisical address - write_i64(LE, 0, h + 32, o_end); // size in file - write_i64(LE, rw_tls_zval_size, h + 40, o_end); // size in memory + write_i64(LE, rw_tls_data_address, h + 16, o_end); // virtual address + write_i64(LE, rw_tls_data_address, h + 24, o_end); // phisical address + write_i64(LE, rw_tls_data_size, h + 32, o_end); // size in file + write_i64(LE, tls_size, h + 40, o_end); // size in memory write_i64(LE, X86_64_ALIGNMENT, h + 48, o_end); h += ELF_PROGRAM_HEADER_SIZE; @@ -3365,6 +3366,17 @@ i64 unit_write_in_memory( write_i64(LE, X86_64_ALIGNMENT, h + 48, o_end); h += ELF_PROGRAM_HEADER_SIZE; + // r/w TLS zero values + write_u32(LE, 7, h, o_end); // type (PT_TLS) + write_u32(LE, 6, h + 4, o_end); // flags (PF_R | PF_W) + write_i64(LE, rw_got_offset, h + 8, o_end); + write_i64(LE, rw_tls_zval_address, h + 16, o_end); // virtual address + write_i64(LE, rw_tls_zval_address, h + 24, o_end); // phisical address + write_i64(LE, 0, h + 32, o_end); // size in file + write_i64(LE, rw_tls_zval_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 GOT write_u32(LE, 1, h, o_end); // type (PT_LOAD) write_u32(LE, 6, h + 4, o_end); // flags (PF_R | PF_W) |