]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarf_begin_elf: decouple section searching from reading
authorJonathan Lebon <jlebon@redhat.com>
Mon, 11 May 2015 19:38:13 +0000 (15:38 -0400)
committerMark Wielaard <mjw@redhat.com>
Wed, 13 May 2015 15:32:20 +0000 (17:32 +0200)
To help legibility, we separate the section name matching from the
actual section reading. This also allows us to remove duplicate code in
cases of sections appearing twice or empty section data. There are no
changes in functionality. The indentation will be fixed in the next
commit, in the interest of keeping this commit easier to read.

Signed-off-by: Jonathan Lebon <jlebon@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdw/ChangeLog
libdw/dwarf_begin_elf.c

index 034db1175ea024857cbf617bc27f5b12b2db9878..604a9abbba9963baf16cbdcdd2ea10b9d82a2f62 100644 (file)
@@ -1,3 +1,8 @@
+2015-05-11  Jonathan Lebon  <jlebon@redhat.com>
+
+       * dwarf_begin_elf.c (check_section): Add compressed flag. Always
+       check for .zdebug sections. Only wrap decompression in #if USE_ZLIB.
+
 2015-05-06  Mark Wielaard  <mjw@redhat.com>
 
        * dwarf_getsrclines.c (read_srclines): Use an int64_t to store and
index 4c49ce213ee35dcb62b0ca9cfa73724d55c07a08..09ea5b11cfe8c9c12546fcb93b0b2869c33f1c40 100644 (file)
@@ -1,5 +1,5 @@
 /* Create descriptor from ELF descriptor for processing file.
-   Copyright (C) 2002-2011, 2014 Red Hat, Inc.
+   Copyright (C) 2002-2011, 2014, 2015 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -118,42 +118,45 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp)
 
   /* Recognize the various sections.  Most names start with .debug_.  */
   size_t cnt;
+  bool compressed = false;
   for (cnt = 0; cnt < ndwarf_scnnames; ++cnt)
     if (strcmp (scnname, dwarf_scnnames[cnt]) == 0)
-      {
-       /* Found it.  Remember where the data is.  */
-       if (unlikely (result->sectiondata[cnt] != NULL))
-         /* A section appears twice.  That's bad.  We ignore the section.  */
-         break;
-
-       /* Get the section data.  */
-       Elf_Data *data = elf_getdata (scn, NULL);
-       if (data != NULL && data->d_size != 0)
-         /* Yep, there is actually data available.  */
-         result->sectiondata[cnt] = data;
-
-       break;
-      }
-#if USE_ZLIB
+      break;
     else if (scnname[0] == '.' && scnname[1] == 'z'
             && strcmp (&scnname[2], &dwarf_scnnames[cnt][1]) == 0)
       {
-       /* A compressed section.  */
+        compressed = true;
+        break;
+      }
 
-       if (unlikely (result->sectiondata[cnt] != NULL))
-         /* A section appears twice.  That's bad.  We ignore the section.  */
-         break;
+  if (cnt >= ndwarf_scnnames)
+    /* Not a debug section; ignore it. */
+    return result;
+
+  if (unlikely (result->sectiondata[cnt] != NULL))
+    /* A section appears twice.  That's bad.  We ignore the section.  */
+    return result;
+
+  /* Get the section data.  */
+  Elf_Data *data = elf_getdata (scn, NULL);
+  if (data == NULL || data->d_size == 0)
+    /* No data actually available, ignore it. */
+    return result;
+
+  /* We can now read the section data into results. */
+  if (!compressed)
+    result->sectiondata[cnt] = data;
+#if USE_ZLIB
+  else
+    {
+        /* A compressed section. */
 
-       /* Get the section data.  */
-       Elf_Data *data = elf_getdata (scn, NULL);
-       if (data != NULL && data->d_size != 0)
-         {
            /* There is a 12-byte header of "ZLIB" followed by
               an 8-byte big-endian size.  */
 
            if (unlikely (data->d_size < 4 + 8)
                || unlikely (memcmp (data->d_buf, "ZLIB", 4) != 0))
-             break;
+             return result;
 
            uint64_t size;
            memcpy (&size, data->d_buf + 4, sizeof size);
@@ -163,11 +166,11 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp)
               enough memory for both the Elf_Data header and the
               uncompressed section data.  */
            if (unlikely (sizeof (Elf_Data) + size < size))
-             break;
+             return result;
 
            Elf_Data *zdata = malloc (sizeof (Elf_Data) + size);
            if (unlikely (zdata == NULL))
-             break;
+             return result;
 
            zdata->d_buf = &zdata[1];
            zdata->d_type = ELF_T_BYTE;
@@ -205,10 +208,7 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp)
                result->sectiondata[cnt] = zdata;
                result->sectiondata_gzip_mask |= 1U << cnt;
              }
-         }
-
-       break;
-      }
+    }
 #endif
 
   return result;