aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chambers <[email protected]>2021-10-02 19:52:16 +1300
committerAndrew Chambers <[email protected]>2021-10-02 19:52:16 +1300
commite12b5b927f5960d0583432e1aa07035295a6b660 (patch)
treedc4f03e1a550028706af1f7af2c186d631d4aa5a
parentc716461f43559bd257bb79bc4175763109dab47d (diff)
Fix offset calculation.
-rw-r--r--main.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/main.c b/main.c
index d2571f0..e0bc8b7 100644
--- a/main.c
+++ b/main.c
@@ -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 *)&sections[i].hdr, sizeof(Elf64_Shdr));