diff options
| author | Andrew Chambers <[email protected]> | 2021-10-02 19:52:16 +1300 |
|---|---|---|
| committer | Andrew Chambers <[email protected]> | 2021-10-02 19:52:16 +1300 |
| commit | e12b5b927f5960d0583432e1aa07035295a6b660 (patch) | |
| tree | dc4f03e1a550028706af1f7af2c186d631d4aa5a | |
| parent | c716461f43559bd257bb79bc4175763109dab47d (diff) | |
Fix offset calculation.
| -rw-r--r-- | main.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -87,7 +87,7 @@ static void out(uint8_t *buf, size_t n) { static void outelf(void) { size_t i; - uint64_t offset = 0; + uint64_t offset; Elf64_Ehdr ehdr = {0}; ehdr.e_ident[0] = 0x7f; @@ -106,9 +106,10 @@ static void outelf(void) { ehdr.e_shentsize = sizeof(Elf64_Shdr); ehdr.e_shnum = nsections; ehdr.e_shstrndx = 1; - offset = sizeof(Elf64_Shdr) * nsections; out((uint8_t *)&ehdr, sizeof(ehdr)); + offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Shdr) * nsections; + for (i = 0; i < nsections; i++) { sections[i].hdr.sh_offset = offset; out((uint8_t *)§ions[i].hdr, sizeof(Elf64_Shdr)); |
