This is an archive of the discontinued LLVM Phabricator instance.

[DWARF] Added verification check for tags in accelerator tables. This patch verifies that the atom tag is actually the same with the tag of the DIE that we retrieve from the table.
ClosedPublic

Authored by sgravani on Jul 27 2017, 4:23 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

sgravani created this revision.Jul 27 2017, 4:23 PM
aprantl edited edge metadata.Jul 27 2017, 4:50 PM

This needs a testcase.

include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
68 ↗(On Diff #108546)

I would use a std::pair<> or a simple struct here.

lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
102 ↗(On Diff #108546)

A dwarf::Tag is a uint_16 — do we also need to check that the value is within range, or is this impossible because we already verified the FORM?

108 ↗(On Diff #108546)

return {DieOffset, DieTag};

should also work here

lib/DebugInfo/DWARF/DWARFVerifier.cpp
550 ↗(On Diff #108546)

maybe continue; here and get rid of the else? not sure if this will be better :-)

554 ↗(On Diff #108546)

Could we be more specific in the error message?
perhaps: "Tag in accelerator table does not match Tag of DIE"

sgravani updated this revision to Diff 108950.Jul 31 2017, 10:12 AM
sgravani marked 4 inline comments as done.

Addressed reviewer's comments.

lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
102 ↗(On Diff #108546)

I think we will catch such an error when we validate the forms

lib/DebugInfo/DWARF/DWARFVerifier.cpp
550 ↗(On Diff #108546)

.....why do that? I'm not sure if this is better either :P

aprantl added inline comments.Jul 31 2017, 10:27 AM
lib/DebugInfo/DWARF/DWARFVerifier.cpp
534 ↗(On Diff #108950)

I think something like this would be more readable:

unsigned Offset;
unsigned Tag;
std::tie(Offset, Tag) = AccelTable.readAtoms(HashDataOffset);
550 ↗(On Diff #108546)

The LLVM coding style prefers early exits over nested ifs to improve readability. I'll leave this up to you.

test/tools/llvm-dwarfdump/X86/apple_types_verify_tag.s
121 ↗(On Diff #108950)

Where's the CHECK?

aprantl accepted this revision.Jul 31 2017, 10:28 AM

This LGTM once all pending comments are addressed.

This revision is now accepted and ready to land.Jul 31 2017, 10:28 AM
sgravani marked 2 inline comments as done.Jul 31 2017, 11:02 AM
sgravani added inline comments.
lib/DebugInfo/DWARF/DWARFVerifier.cpp
534 ↗(On Diff #108950)

I followed the advice, thanks!

test/tools/llvm-dwarfdump/X86/apple_types_verify_tag.s
121 ↗(On Diff #108950)

beginning of test:

  1. CHECK: Verifying .apple_types...
  2. CHECK-NEXT: error: Tag DW_TAG_ptr_to_member_type in accelerator table does not match Tag DW_TAG_base_type of DIE[0].
This revision was automatically updated to reflect the committed changes.
sgravani marked 2 inline comments as done.