From 6004cb3888eaac4995025fdba5f71b7fd861d81a Mon Sep 17 00:00:00 2001 From: norly Date: Thu, 27 Jun 2013 02:06:41 +0100 Subject: [PATCH] Relax restrictions on NOBITS sections --- include/libelfu/generic.h | 1 + src/libelfu/elfops/check.c | 2 +- src/libelfu/modelops/fromFile.c | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/libelfu/generic.h b/include/libelfu/generic.h index 340719c..4e3239d 100644 --- a/include/libelfu/generic.h +++ b/include/libelfu/generic.h @@ -5,6 +5,7 @@ #define MIN(x, y) ((x) < (y) ? (x) : (y)) +#define MAX(x, y) ((x) > (y) ? (x) : (y)) #define ROUNDUP(x, align) ((x) + ((align) - ((x) % (align))) % (align)) diff --git a/src/libelfu/elfops/check.c b/src/libelfu/elfops/check.c index 108964a..a5aeef3 100644 --- a/src/libelfu/elfops/check.c +++ b/src/libelfu/elfops/check.c @@ -182,7 +182,7 @@ int elfu_eCheck(Elf *e) if (PHDR_CONTAINS_SCN_IN_MEMORY(&phdrs[j], &shdrs[i])) { GElf_Off shoff = phdrs[j].p_offset + (shdrs[i].sh_addr - phdrs[j].p_vaddr); - if (shdrs[i].sh_offset != shoff + if ((shdrs[i].sh_offset != shoff && shdrs[i].sh_type != SHT_NOBITS) || !PHDR_CONTAINS_SCN_IN_FILE(&phdrs[j], &shdrs[i])) { ELFU_WARN("elfu_eCheck: SHDR %d and PHDR %d report conflicting file/memory regions.\n", i, j); goto ERROR; diff --git a/src/libelfu/modelops/fromFile.c b/src/libelfu/modelops/fromFile.c index 2b47be0..ef7add9 100644 --- a/src/libelfu/modelops/fromFile.c +++ b/src/libelfu/modelops/fromFile.c @@ -445,7 +445,12 @@ ElfuElf* elfu_mFromElf(Elf *e) if (ms->shdr.sh_addr == 0) { ms->shdr.sh_addr = shaddr; } else { - assert(ms->shdr.sh_addr == shaddr); + if (ms->shdr.sh_type != SHT_NOBITS) { + assert(ms->shdr.sh_addr == shaddr); + } else if (ms->shdr.sh_addr > shaddr) { + parent->phdr.p_filesz = MAX(parent->phdr.p_filesz, + ms->shdr.sh_addr - parent->phdr.p_vaddr); + } } CIRCLEQ_INSERT_TAIL(&parent->childScnList, ms, elemChildScn); -- 2.30.2