Relax restrictions on NOBITS sections
authornorly <ny-git@enpas.org>
Thu, 27 Jun 2013 01:06:41 +0000 (02:06 +0100)
committernorly <ny-git@enpas.org>
Thu, 27 Jun 2013 01:06:41 +0000 (02:06 +0100)
include/libelfu/generic.h
src/libelfu/elfops/check.c
src/libelfu/modelops/fromFile.c

index 340719cc562c3386d8f5905a7ac9ae63421f988e..4e3239db2e33d618e2f62e2a68d4e7942fb24a14 100644 (file)
@@ -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))
 
 
index 108964aca136934f0dce75c9a7da7c490ef6984c..a5aeef366145f4b3789b51d0024bcbb18933cbe2 100644 (file)
@@ -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;
index 2b47be029fcce1099bc2f637ec1990340ab0ebd9..ef7add9a17ab7fcbd6152437b6748f53c7038b48 100644 (file)
@@ -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);