diff options
author | norly <ny-git@enpas.org> | 2013-06-03 02:20:00 +0100 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2013-06-03 02:20:00 +0100 |
commit | 3ab3fa41bb34e51f17190e0cb0cf1b38e72d8b69 (patch) | |
tree | 509f9970fe219496f46c0bf7f6ce8de26433e355 | |
parent | a08653637257ceaef8e61d965ab0d6c52b0c697d (diff) |
Insert NOBITS sections (.bss), ignore empty sections
-rw-r--r-- | src/model/reladd.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/model/reladd.c b/src/model/reladd.c index 80f106f..482804c 100644 --- a/src/model/reladd.c +++ b/src/model/reladd.c @@ -42,6 +42,18 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn) return NULL; } + if (newscn->shdr.sh_type == SHT_NOBITS) { + /* Expand this to SHT_PROGBITS, then insert as such. */ + + assert(!newscn->data.d_buf); + + newscn->data.d_buf = malloc(newscn->shdr.sh_size); + if (!newscn->data.d_buf) { + goto ERROR; + } + newscn->data.d_size = newscn->shdr.sh_size; + newscn->shdr.sh_type = SHT_PROGBITS; + } injAddr = elfu_mLayoutGetSpaceInPhdr(me, newscn->shdr.sh_size, @@ -106,9 +118,6 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn) } } - - // TODO: Relocate - return newscn; } else { ELFU_WARN("insertSection: Skipping non-memory section %s (type %d flags %jd).\n", @@ -135,6 +144,12 @@ static void* subScnAdd1(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2) switch(ms->shdr.sh_type) { case SHT_PROGBITS: /* 1 */ + case SHT_NOBITS: /* 8 */ + /* Ignore empty sections */ + if (ms->shdr.sh_size == 0) { + break; + } + /* Find a place where it belongs and shove it in. */ newscn = insertSection(me, mrel, ms); if (!newscn) { @@ -143,12 +158,6 @@ static void* subScnAdd1(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2) ms->shdr.sh_type); } break; - case SHT_NOBITS: /* 8 */ - /* Expand this to SHT_PROGBITS, then insert as such. */ - - // TODO - - break; } return NULL; @@ -164,6 +173,7 @@ static void* subScnAdd2(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2) switch(ms->shdr.sh_type) { case SHT_NULL: /* 0 */ case SHT_PROGBITS: /* 1 */ + case SHT_NOBITS: /* 8 */ break; |