reladd: Work more with sh_addr instead of sh_offset
authornorly <ny-git@enpas.org>
Sat, 22 Jun 2013 00:03:28 +0000 (01:03 +0100)
committernorly <ny-git@enpas.org>
Sat, 22 Jun 2013 00:03:28 +0000 (01:03 +0100)
src/libelfu/modelops/reladd.c

index 82b562b557079d0ce03610d49bebb5853497f120..55438db523eb237552c7f70f41f6cba31eecb444 100644 (file)
@@ -66,7 +66,13 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn)
   GElf_Off injOffset;
   ElfuPhdr *injPhdr;
 
-  if (oldscn->shdr.sh_flags & SHF_ALLOC) {
+  if (!(oldscn->shdr.sh_flags & SHF_ALLOC)) {
+    ELFU_WARN("insertSection: Skipping non-memory section %s (type %d flags %u).\n",
+              elfu_mScnName(mrel, oldscn),
+              oldscn->shdr.sh_type,
+              (unsigned)oldscn->shdr.sh_flags);
+    goto ERROR;
+  } else {
     newscn = cloneScn(oldscn);
     if (!newscn) {
       return NULL;
@@ -105,13 +111,14 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn)
     newscn->shdr.sh_addr = injAddr;
     newscn->shdr.sh_offset = injOffset;
 
+    /* Insert section in child list, ordered by memory address */
     if (CIRCLEQ_EMPTY(&injPhdr->childScnList)
-        || CIRCLEQ_LAST(&injPhdr->childScnList)->shdr.sh_offset < injOffset) {
+        || CIRCLEQ_LAST(&injPhdr->childScnList)->shdr.sh_addr < injAddr) {
       CIRCLEQ_INSERT_TAIL(&injPhdr->childScnList, newscn, elemChildScn);
     } else {
       ElfuScn *ms;
       CIRCLEQ_FOREACH(ms, &injPhdr->childScnList, elemChildScn) {
-        if (injOffset < ms->shdr.sh_offset) {
+        if (injAddr < ms->shdr.sh_addr) {
           CIRCLEQ_INSERT_BEFORE(&injPhdr->childScnList, ms, newscn, elemChildScn);
           break;
         }
@@ -148,12 +155,6 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn)
     }
 
     return newscn;
-  } else {
-      ELFU_WARN("insertSection: Skipping non-memory section %s (type %d flags %u).\n",
-                elfu_mScnName(mrel, oldscn),
-                oldscn->shdr.sh_type,
-                (unsigned)oldscn->shdr.sh_flags);
-      goto ERROR;
   }
 
   ERROR: