]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Add explicit section index to struct Dwarf_CU.
authorMark Wielaard <mark@klomp.org>
Wed, 20 Dec 2017 15:50:57 +0000 (16:50 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 20 Dec 2017 16:20:29 +0000 (17:20 +0100)
The DIE (attribute) data might come from either the main .debug_info
section or for DWARFv4 from a separate .debug_types section. Or in
case of the fake_loc_cu from the .debug_loc section and in the case
of macros from the .debug_macinfo or .debug_macro section.

We didn't handle the last two "fake" CU cases correctly when sanity
checking offsets in __libdw_read_address and __libdw_read_offset.

Add an explicit sec_idx field to struct Dwarf_CU that is always set
to the actual section that the data came from.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/dwarf_begin_elf.c
libdw/dwarf_getmacros.c
libdw/libdwP.h
libdw/libdw_findcu.c

index 350230e512b1d5ec7a31b1a0e6d785c4421dead6..22b7bf4dbb944a7f70b108904604f2a5b435c30b 100644 (file)
@@ -1,3 +1,14 @@
+2017-12-20  Mark Wielaard  <mark@klomp.org>
+
+       * libdwP.h (struct Dwarf_CU): Add sec_idx field.
+       (cu_sec_idx): Return cu->sec_idx.
+       * libdw_findcu.c (__libdw_intern_next_unit): Set cu sec_idx to
+       IDX_debug_info or IDX_debug_types.
+       * dwarf_begin_elf.c (valid_p): Set fake_loc_cu->sec_idx to
+       IDX_debug_loc.
+       * dwarf_getmacros.c (read_macros): Set fake_cu->sec_idx to
+       IDX_debug_macro or IDX_debug_macinfo.
+
 2017-12-12  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_aggregate_size.c (dwarf_aggregate_size): Don't peel the
index afa15cef009a3e1389ae8999fc4eebe87711c083..7c3fe103604e20e7f277eda3cc996aacfb81c7b0 100644 (file)
@@ -201,6 +201,7 @@ valid_p (Dwarf *result)
        }
       else
        {
+         result->fake_loc_cu->sec_idx = IDX_debug_loc;
          result->fake_loc_cu->dbg = result;
          result->fake_loc_cu->startp
            = result->sectiondata[IDX_debug_loc]->d_buf;
index db6582b6e36cc12f37f4181170f612c3fbc3ed0b..c456051ca55dee2d37284b11423cb6d21d23906f 100644 (file)
@@ -360,6 +360,7 @@ read_macros (Dwarf *dbg, int sec_index,
         Version 4 for the old GNU extension, version 5 for DWARF5.  */
       Dwarf_CU fake_cu = {
        .dbg = dbg,
+       .sec_idx = sec_index,
        .version = table->version,
        .offset_size = table->is_64bit ? 8 : 4,
        .startp = (void *) startp + offset,
index 78c00132e745c1d978dfe61cfdff84e6a20d758f..f524347c7a87d50102e545fd22ec89fc45724600 100644 (file)
@@ -293,6 +293,8 @@ struct Dwarf_CU
   uint8_t offset_size;
   uint16_t version;
 
+  size_t sec_idx; /* Normally .debug_info, could be .debug_type or "fake". */
+
   /* Zero if this is a normal CU.  Nonzero if it is a type unit.  */
   size_t type_offset;
   uint64_t type_sig8;
@@ -714,7 +716,7 @@ __libdw_read_offset (Dwarf *dbg, Dwarf *dbg_ret,
 static inline size_t
 cu_sec_idx (struct Dwarf_CU *cu)
 {
-  return cu->type_offset == 0 ? IDX_debug_info : IDX_debug_types;
+  return cu->sec_idx;
 }
 
 static inline bool
index 082307b0dc1951f45127ae9e5ae2d85efeab5b07..4e025e26faaf8ebdd7d52a21986d68a91d56ceed 100644 (file)
@@ -93,8 +93,8 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
     }
 
   /* Invalid or truncated debug section data?  */
-  Elf_Data *data = dbg->sectiondata[debug_types
-                                   ? IDX_debug_types : IDX_debug_info];
+  size_t sec_idx = debug_types ? IDX_debug_types : IDX_debug_info;
+  Elf_Data *data = dbg->sectiondata[sec_idx];
   if (unlikely (*offsetp > data->d_size))
     *offsetp = data->d_size;
 
@@ -102,6 +102,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
   struct Dwarf_CU *newp = libdw_typed_alloc (dbg, struct Dwarf_CU);
 
   newp->dbg = dbg;
+  newp->sec_idx = sec_idx;
   newp->start = oldoff;
   newp->end = *offsetp;
   newp->address_size = address_size;