This is an archive of the discontinued LLVM Phabricator instance.

[dwarfdump] Fix spurious verification errors for DW_AT_location attributes
ClosedPublic

Authored by JDevlieghere on Nov 17 2017, 2:39 PM.

Details

Summary

Verifying any DWARF file that is optimized and contains at least one tag
with a DW_AT_location with a location list offset as a
DW_AT_form_dataXXX results in dwarfdump spuriously claiming that the
location list is invalid.

Diff Detail

Repository
rL LLVM

Event Timeline

clayborg created this revision.Nov 17 2017, 2:39 PM
probinson added inline comments.Nov 17 2017, 3:15 PM
lib/DebugInfo/DWARF/DWARFVerifier.cpp
431 ↗(On Diff #123425)

Looks like this path is missing a couple of opportunities to detect invalid references.

probinson edited edge metadata.Nov 17 2017, 3:36 PM

The FORM that's appropriate for DW_AT_location to use as a reference varies with the DWARF version. In v2 and v3, it's FORM_data4 or FORM_data8, in v4 it's FORM_sec_offset. I haven't looked at the verifier much but it seems like using the correct FORM is something that ought to be verifiable.

In v5 things get way more complicated, but that's not anything you have to deal with now.

aprantl edited edge metadata.Nov 17 2017, 3:36 PM

Do you happen to have a minimal reproducer that we could check in as an assembler testcase?

dblaikie added inline comments.Jan 29 2018, 11:22 AM
lib/DebugInfo/DWARF/DWARFVerifier.cpp
413 ↗(On Diff #123425)

Probably move this down into the "if (Expr)" condition below

if (Optional<ArrayRef<uint8_t>> Expr = AttrValue.Value.getAsBlock()) {
  VerifyLocation(...);
426–435 ↗(On Diff #123425)

Alternatively/slightly different to all this, could use early breaks:

auto X = ...;
if (!X)
  break;

etc...

429–431 ↗(On Diff #123425)

Could roll this into else-if:

} else if (auto LocOffset = ... ) {
432–435 ↗(On Diff #123425)

Could roll these variables into the conditions:

if (auto DebugLoc = DCtx.getDebugLoc())
  if (auto LocList = ...
JDevlieghere commandeered this revision.Feb 9 2018, 7:31 AM
JDevlieghere added a reviewer: clayborg.

This is blocking re-enabling llvm-dwarfdump --verify for Swift.

  • Address review comments
  • Add test case
aprantl added inline comments.Feb 9 2018, 8:44 AM
llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
413 ↗(On Diff #133616)

Why doesn't this just take a StringRef? It looks like all call sites convert StringRefs, too.

429 ↗(On Diff #133616)

Full sentences in the comments?

431 ↗(On Diff #133616)

redundant braces

JDevlieghere marked 3 inline comments as done.
JDevlieghere retitled this revision from llvm-dwarfdump --verify is incorrectly saying all DW_AT_location attributes with locations lists are invalid. to [dwarfdump] Fix spurious verification errors for DW_AT_location attributes.
JDevlieghere edited the summary of this revision. (Show Details)

Fixed Adrian's comments.

I also discovered that I was using this false positive to test the dsymutil -verify feature, so I had to fixing that test as well.

llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
413 ↗(On Diff #133616)

No. The call sites have respectively ArrayRef<uint8t_t> and SmallVector<char, 4> as argument.

I'd have though invalid.s should be a text file from the name, but it shows up as binary here?

I'd have though invalid.s should be a text file from the name, but it shows up as binary here?

Not sure why Phabricator didn't pick it up. Here's its content: https://reviews.llvm.org/P8063

  • Have VerifyLocation lambda take a StringRef as Adrian suggested.
aprantl added inline comments.Feb 16 2018, 2:20 PM
llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
427 ↗(On Diff #134721)

-> llvm::toStringRef(ArrayRef<uint8_t> Input)

JDevlieghere marked 2 inline comments as done.Feb 16 2018, 2:40 PM
aprantl accepted this revision.Feb 16 2018, 2:43 PM

That's a lot cleaner!

This revision is now accepted and ready to land.Feb 16 2018, 2:43 PM

I look forward to this being checked in

This revision was automatically updated to reflect the committed changes.