Remove ELFU_BOOL
[centaur.git] / src / lookup / last-section-in-segment.c
index 964e854a678cf8db2be52b8f30eef6f46508c229..53323f66e6da9d3de64ce565c9f1e2007c6e5cd5 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include <stdlib.h>
 
 #include <libelf.h>
@@ -21,22 +22,24 @@ Elf_Scn* elfu_lastSectionInSegment(Elf *e, GElf_Phdr *phdr)
 
   scn = elf_getscn(e, 1);
   while (scn) {
-    if (elfu_segmentContainsSection(phdr, scn) == ELFU_TRUE) {
+    GElf_Shdr shdr;
+
+    if (gelf_getshdr(scn, &shdr) != &shdr) {
+      fprintf(stderr, "gelf_getshdr() failed: %s\n", elf_errmsg(-1));
+      continue;
+    }
+
+    if (elfu_segmentContainsSection(phdr, &shdr)) {
       if (!last) {
         last = scn;
       } else {
         GElf_Shdr shdrOld;
-        GElf_Shdr shdrNew;
 
         if (gelf_getshdr(last, &shdrOld) != &shdrOld) {
           continue;
         }
 
-        if (gelf_getshdr(scn, &shdrNew) != &shdrNew) {
-          continue;
-        }
-
-        if (shdrNew.sh_offset + shdrNew.sh_size
+        if (shdr.sh_offset + shdr.sh_size
             > shdrOld.sh_offset + shdrOld.sh_size) {
           // TODO: Check (leftover space in memory image) < (p_align)
           last = scn;