Implement orphaned sections
authornorly <ny-git@enpas.org>
Tue, 28 May 2013 22:34:51 +0000 (23:34 +0100)
committernorly <ny-git@enpas.org>
Tue, 28 May 2013 22:34:51 +0000 (23:34 +0100)
Orphaned sections are not (fully) included in any LOAD PHDR and can thus
be moved and stripped at will without changing the memory image of the
program.

include/libelfu/modeltypes.h
src/model/dump.c
src/model/fromFile.c

index e8a9c015ee4f70fc7e3799dbc9771ea26b63c118..bea93222f358088a38696aac2f0f1aa80c456bb1 100644 (file)
@@ -37,6 +37,7 @@ typedef struct {
 
   CIRCLEQ_HEAD(ScnList, ElfuScn) scnList;
   CIRCLEQ_HEAD(PhdrList, ElfuPhdr) phdrList;
+  CIRCLEQ_HEAD(OrphanScnList, ElfuScn) orphanScnList;
 
   ElfuScn *shstrtab;
 } ElfuElf;
index 882ba0af7d3d36bb27c061b8dd1c9d20c7b3aaea..67a498a184e7a2e531cf6b6624e64b21b9f24168 100644 (file)
@@ -209,6 +209,15 @@ void elfu_mDumpElf(ElfuElf *me)
   ELFU_INFO("\n");
 
 
+  ELFU_INFO("Orphaned sections:\n");
+  CIRCLEQ_FOREACH(ms, &me->orphanScnList, elemChildScn) {
+    ELFU_INFO("        * %-17s @ %8jx\n",
+              elfu_mScnName(me, ms),
+              ms->shdr.sh_addr);
+  }
+  ELFU_INFO("\n");
+
+
   ELFU_INFO("Sections:\n");
   ELFU_INFO("     #  Name              sh_type          sh_addr sh_offset  sh_size ES Fl Al sh_link           sh_info          \n");
   ELFU_INFO("       |                 |               |        |         |        |  |  |  |                 |                 \n");
index fd6aba0b83586f8810a5c8c73cbc0515a80d9b4e..cb0935270d355a26f01f369ad348fa2d4ce14c99 100644 (file)
@@ -167,6 +167,7 @@ ElfuElf* elfu_mFromElf(Elf *e)
   /* General stuff */
   CIRCLEQ_INIT(&me->scnList);
   CIRCLEQ_INIT(&me->phdrList);
+  CIRCLEQ_INIT(&me->orphanScnList);
   me->shstrtab = NULL;
 
   me->elfclass = gelf_getclass(e);
@@ -286,6 +287,8 @@ ElfuElf* elfu_mFromElf(Elf *e)
 
       if (parent) {
         CIRCLEQ_INSERT_TAIL(&parent->childScnList, ms, elemChildScn);
+      } else {
+        CIRCLEQ_INSERT_TAIL(&me->orphanScnList, ms, elemChildScn);
       }
     }