Turn elfu_gScnSizeFile into a macro
authornorly <ny-git@enpas.org>
Mon, 27 May 2013 02:18:00 +0000 (03:18 +0100)
committernorly <ny-git@enpas.org>
Mon, 27 May 2013 02:18:00 +0000 (03:18 +0100)
include/libelfu/generic.h
src/elfops/check.c
src/generic/scnSize.c [deleted file]
src/model/check.c
src/model/reladd.c
src/model/section-in-segment.c

index 09d2ffc651f0d372815027c5d72896fae5068d6b..c74981aa99eadc91481f1e00b188a64ca040bd7e 100644 (file)
 
 
 
+#define SCNFILESIZE(shdr) ((shdr)->sh_type == SHT_NOBITS ? 0 : (shdr)->sh_size)
+
+
 int elfu_gPhdrContainsScn(GElf_Phdr *phdr, GElf_Shdr *shdr);
 
-size_t elfu_gScnSizeFile(const GElf_Shdr *shdr);
 
 #endif
index c7ebc7d5ebfc92eec645b5b03f91137421aae26a..8aaa7b55291df3fefc2448b6761f77c4a710163e 100644 (file)
@@ -126,14 +126,14 @@ int elfu_eCheck(Elf *e)
       }
 
       /* Section should not overlap with PHDRs. */
-      if (OVERLAPPING(shdrs[i].sh_offset, elfu_gScnSizeFile(&shdrs[i]),
+      if (OVERLAPPING(shdrs[i].sh_offset, SCNFILESIZE(&shdrs[i]),
                       ehdr.e_phoff, numPhdr * ehdr.e_phentsize)) {
         ELFU_WARN("elfu_eCheck: Section %d overlaps with PHDR.\n", i);
         goto ERROR;
       }
 
       /* Section should not overlap with SHDRs. */
-      if (OVERLAPPING(shdrs[i].sh_offset, elfu_gScnSizeFile(&shdrs[i]),
+      if (OVERLAPPING(shdrs[i].sh_offset, SCNFILESIZE(&shdrs[i]),
                       ehdr.e_shoff, numShdr * ehdr.e_shentsize)) {
         ELFU_WARN("elfu_eCheck: Section %d overlaps with SHDRs.\n", i);
         goto ERROR;
@@ -154,8 +154,8 @@ int elfu_eCheck(Elf *e)
         }
 
         /* Sections must not overlap in file. */
-        if (OVERLAPPING(shdrs[i].sh_offset, elfu_gScnSizeFile(&shdrs[i]),
-                        shdrs[j].sh_offset, elfu_gScnSizeFile(&shdrs[j]))) {
+        if (OVERLAPPING(shdrs[i].sh_offset, SCNFILESIZE(&shdrs[i]),
+                        shdrs[j].sh_offset, SCNFILESIZE(&shdrs[j]))) {
           ELFU_WARN("elfu_eCheck: Sections %d and %d overlap in file.\n", i, j);
           goto ERROR;
         }
diff --git a/src/generic/scnSize.c b/src/generic/scnSize.c
deleted file mode 100644 (file)
index 43abb13..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <assert.h>
-#include <sys/types.h>
-#include <libelf/gelf.h>
-#include <libelfu/libelfu.h>
-
-
-
-size_t elfu_gScnSizeFile(const GElf_Shdr *shdr)
-{
-  assert(shdr);
-
-  return shdr->sh_type == SHT_NOBITS ? 0 : shdr->sh_size;
-}
index 2c8c67ebf757ab38060975e8409317c7938cd01d..4fb042ceca5632af7af7fc3e82dfa17ed432d51d 100644 (file)
@@ -68,7 +68,7 @@ int elfu_mCheck(ElfuElf *me)
 
   /* Check for overlapping sections */
   for (i = 0; i < numSecs - 1; i++) {
-    if (sortedSecs[i]->shdr.sh_offset + elfu_gScnSizeFile(&sortedSecs[i]->shdr)
+    if (sortedSecs[i]->shdr.sh_offset + SCNFILESIZE(&sortedSecs[i]->shdr)
         > sortedSecs[i+1]->shdr.sh_offset) {
       ELFU_WARN("elfu_check: Found overlapping sections: %s and %s.\n",
                 elfu_mScnName(me, sortedSecs[i]),
@@ -89,7 +89,7 @@ int elfu_mCheck(ElfuElf *me)
   /* Check for sections overlapping with PHDRs */
   for (i = 0; i < numSecs; i++) {
     if (isOverlapping(sortedSecs[i]->shdr.sh_offset,
-                      elfu_gScnSizeFile(&sortedSecs[i]->shdr),
+                      SCNFILESIZE(&sortedSecs[i]->shdr),
                       me->ehdr.e_phoff,
                       me->ehdr.e_phentsize * me->ehdr.e_phnum)) {
       ELFU_WARN("elfu_check: Found section overlapping with PHDRs: %s.\n",
index 41d7cfba004a4a2bb146fbee058f772db8561dbc..549afcfe46c42013851016f7f46468cffda2dfc4 100644 (file)
@@ -119,7 +119,7 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *ms)
 
             // TODO: Error handling
           } else {
-            injOffset = lastScn->shdr.sh_offset + elfu_gScnSizeFile(&lastScn->shdr);
+            injOffset = lastScn->shdr.sh_offset + SCNFILESIZE(&lastScn->shdr);
 
             ELFU_INFO("Expanding at offset 0x%jx...\n",
                       injOffset);
@@ -129,7 +129,7 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *ms)
 
             /* Recalculate injOffset in case we expanded a NOBITS section */
             lastScn = elfu_mScnLastInSegment(me, injAnchor);
-            injOffset = lastScn->shdr.sh_offset + elfu_gScnSizeFile(&lastScn->shdr);
+            injOffset = lastScn->shdr.sh_offset + SCNFILESIZE(&lastScn->shdr);
 
             ELFU_INFO("Inserting %s at offset 0x%jx...\n",
                       elfu_mScnName(mrel, ms),
index ad7f037f4fd20ea22c9588b2dbec2b03c075dbb6..0e513e23d82409a647afa3a3c3ed8342e6f199f3 100644 (file)
@@ -44,7 +44,7 @@ ElfuScn* elfu_mScnLastInSegment(ElfuElf *me, ElfuPhdr *mp)
 
   CIRCLEQ_FOREACH(ms, &me->scnList, elem) {
     /* Get section size on disk - for NOBITS sections that is 0 bytes. */
-    size_t size = elfu_gScnSizeFile(&ms->shdr);
+    size_t size = SCNFILESIZE(&ms->shdr);
 
     if (((ms->shdr.sh_offset + size >= mp->phdr.p_offset)
          && (ms->shdr.sh_offset + size <= mp->phdr.p_offset + mp->phdr.p_filesz))) {