From: Jonathan Lebon Date: Mon, 11 May 2015 19:38:13 +0000 (-0400) Subject: dwarf_begin_elf: decouple section searching from reading X-Git-Tag: elfutils-0.162~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=90659075adc29213ec0f86fd08f39c7e571fb061;p=thirdparty%2Felfutils.git dwarf_begin_elf: decouple section searching from reading 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 Signed-off-by: Mark Wielaard --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 034db1175..604a9abbb 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2015-05-11 Jonathan Lebon + + * 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 * dwarf_getsrclines.c (read_srclines): Use an int64_t to store and diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c index 4c49ce213..09ea5b11c 100644 --- a/libdw/dwarf_begin_elf.c +++ b/libdw/dwarf_begin_elf.c @@ -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 , 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;