]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: More thorough checking of Dw4Ch7.5 (toplevel CU DIE)
authorPetr Machata <pmachata@redhat.com>
Mon, 7 Mar 2011 13:21:18 +0000 (14:21 +0100)
committerPetr Machata <pmachata@redhat.com>
Mon, 7 Mar 2011 13:21:18 +0000 (14:21 +0100)
dwarflint/check_debug_info.cc

index c3783bba49a23e43251f778341b89e638eaba354..c65ee832adb25891f565d55db662a924f3b003ea 100644 (file)
@@ -598,9 +598,6 @@ namespace
        if (dump_die_offsets)
          std::cerr << "[" << level << "] "
                    << where << ": abbrev " << abbr_code << std::endl;
-       if (level == 0 && ++die_count > 1)
-         wr_error (where)
-           << "toplevel DIE chain contains more than one DIE." << std::endl;
 
        /* Find the abbrev matching the code.  */
        abbrev = abbrevs->find_abbrev (abbr_code);
@@ -613,6 +610,23 @@ namespace
          }
        abbrev->used = true;
 
+       // DWARF 4 Ch. 7.5: compilation unit header [is] followed by a
+       // single DW_TAG_compile_unit or DW_TAG_partial_unit.
+       bool is_cudie = level == 0
+         && (abbrev->tag == DW_TAG_compile_unit
+             || abbrev->tag == DW_TAG_partial_unit);
+       if (level == 0)
+         {
+           if (++die_count > 1)
+             wr_error (where)
+               << "toplevel DIE chain contains more than one DIE."
+               << std::endl;
+           else if (!is_cudie)
+             wr_error (cu->head->where)
+               << "toplevel DIE must be either compile_unit or partial_unit."
+               << std::endl;
+         }
+
        addr_record_add (&cu->die_addrs, cu->head->offset + die_off);
 
        uint64_t low_pc = (uint64_t)-1, high_pc = (uint64_t)-1;
@@ -869,9 +883,7 @@ namespace
        where.ref = NULL;
 
        /* Check PC coverage.  */
-       if ((abbrev->tag == DW_TAG_compile_unit
-            || abbrev->tag == DW_TAG_partial_unit)
-           && low_pc != (uint64_t)-1)
+       if (is_cudie && low_pc != (uint64_t)-1)
          {
            cu->low_pc = low_pc;