summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-07-30 15:35:20 +0200
committerMitya Selivanov <automainint@guattari.tech>2024-07-30 15:35:20 +0200
commit41b51baf9b14bae073aff088e624c139e47a1d62 (patch)
treea67e45431e76adc0c24f4a7739a29829355a797f
parentcd19e4b8d2fe164661a7cbcf6e28ec87f05d91c5 (diff)
downloadbxgen-41b51baf9b14bae073aff088e624c139e47a1d62.zip
Do not rewrite symbols in place
-rwxr-xr-xbxgen.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/bxgen.c b/bxgen.c
index 65e4903..f56107e 100755
--- a/bxgen.c
+++ b/bxgen.c
@@ -2502,8 +2502,6 @@ i64 unit_write_in_memory(
if (end > buf.end)
end = buf.end;
-
- write_i64(LE, sym_address, begin + 8, end);
}
}
@@ -2576,7 +2574,6 @@ i64 unit_write_in_memory(
i64 dst_index = elf_find_related_section_index(buf, sec_index);
i64 dst_index_global = sec_index_global + dst_index - 1;
-
BX_CHECK(dst_index_global >= 0 && dst_index_global < linker->max_num_sections, "Buffer overflow",);
for (i64 entry_index = 0; entry_index < src_sec.num_entries; ++entry_index) {
@@ -2610,12 +2607,15 @@ i64 unit_write_in_memory(
bx_mem_cpy(linker->not_found_buffer + not_found_size, sym_name, relx.symbol.name.size);
not_found_size += relx.symbol.name.size + 1;
}
- } else
+ } else {
+ i64 src_index_global = sec_index_global + relx.symbol.section - 1;
+
symbol = (Symbol_Entry) {
- .section = sec_index_global,
- .address = relx.symbol.value.offset,
+ .section = src_index_global,
+ .address = relx.symbol.value.offset + linker->section_addresses[src_index_global],
.size = relx.symbol.value.size,
};
+ }
u8 *dst = buf.begin + elf_section(buf, dst_index).data.offset + relx.offset;
@@ -3424,7 +3424,7 @@ int main(int argc, char **argv) {
// Add the `main` procedure.
i64 mainproc = p_new_entry(u, "main");
- // Call printf
+ // Call puts
n_call_by_name(
mainproc,
CONV_CDECL, // calling convention