This is an archive of the discontinued LLVM Phabricator instance.

[DWARFVerifier] Fix verification of nameless variables.
AbandonedPublic

Authored by fdeazeve on Jun 22 2023, 7:05 AM.

Details

Reviewers
JDevlieghere
aprantl
Group Reviewers
debug-info
Summary

The verifier builds a list of all "possible" names of a variable and then
verifies that the name inside __debug_names is one of those possible names.
For a nameless variable, the list is empty, but its name in the accelerator
table is "", so that logic fails.

One could also question whether accelerator table entries with an empty name
should be valid to begin with. The specification says that:

  • All other debugging information entries without a DW_AT_name attribute are
  • excluded.

But it also says that:

  • DW_TAG_variable debugging information entries with a DW_AT_location attribute
  • that includes a DW_OP_addr or DW_OP_form_tls_address operator are included;
  • otherwise, they are excluded.

So it's not clear which rules takes precedence. Changing the logic to skip
generating entries in this case is likely more complex and probably deserves its
own discussion, as such this commit proposes making the verifier "clean" first:
its logic is arguably buggy and if we want to forbid empty names the verifier
implementation should check for that explicitly, not in this very implicit way.

Diff Detail

Event Timeline

fdeazeve created this revision.Jun 22 2023, 7:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 7:05 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fdeazeve requested review of this revision.Jun 22 2023, 7:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 7:05 AM

You can repro the issue with:

echo 'auto x = "hello!";' | clang++ -x c++ - -c -gdwarf-5 -o - | llvm-dwarfdump --debug-names - --verify
JDevlieghere accepted this revision.Jun 22 2023, 9:37 AM

I can't speak for the committee, but my person interpretation of the standard is that these variables should not be included. I get that from both the order in which those points are define as well as the general spirit behind the accelerated access (i.e. looking things up by name).

It's fine to patch the verifier like this, but let's start a thread on the dwarf-discuss mailing list about the generation side.

This revision is now accepted and ready to land.Jun 22 2023, 9:37 AM

But maybe the deeper question: Why are we creating DW_AT_variables for string literals? They aren't variables as far as a user would be concerned. GCC doesn't do this...

But maybe the deeper question: Why are we creating DW_AT_variables for string literals? They aren't variables as far as a user would be concerned. GCC doesn't do this...

This is either an accident or some obscure historical reason, I'll try to do some git archeology to figure out

But maybe the deeper question: Why are we creating DW_AT_variables for string literals? They aren't variables as far as a user would be concerned. GCC doesn't do this...

@dblaikie apparently this was done last year: https://reviews.llvm.org/D123534

But maybe the deeper question: Why are we creating DW_AT_variables for string literals? They aren't variables as far as a user would be concerned. GCC doesn't do this...

@dblaikie apparently this was done last year: https://reviews.llvm.org/D123534

ah, right... - thanks for the reference! & then, yeah, just not putting these things in the index seems good. (even if we did revisit the original decision to include this debug info unconditionally - adding it under a flag, etc, we'd still want to fix the index issue)

fdeazeve abandoned this revision.Jun 26 2023, 1:15 PM

Abandoning in favor of D153550

Abandoning in favor of D153550

For posterity, I think this is a copy-paste typo, and meant to link to D153809 (?)

Abandoning in favor of D153550

For posterity, I think this is a copy-paste typo, and meant to link to D153809 (?)

Oooops, thank you for catching this, it was indeed a copy-paste mistake.