This is an archive of the discontinued LLVM Phabricator instance.

[DWARF] Do not pass Version to DWARFExpression.
ClosedPublic

Authored by ikudrin on Jan 23 2020, 4:09 AM.

Details

Summary

The Version was used only to determine the size of an operand of DW_OP_call_ref. The size was 4 for all versions apart from 2, but the DW_OP_call_ref operation was introduced only in DWARF3. Thus, the code may be simplified and using of Version may be eliminated.

Diff Detail

Event Timeline

ikudrin created this revision.Jan 23 2020, 4:09 AM
ikudrin retitled this revision from [DWARF] Do not pass Version to DWARFExtract. NFCI. to [DWARF] Do not pass Version to DWARFExpression. NFCI..Jan 23 2020, 4:10 AM

Reviewing the DWARF spec for DW_OP_call_ref:
This operator does not exist in DWARF v2. In v3 and onward, its operand is specified as 4- or 8-byte depending on the DWARF-32/64 format. There is non-normative commentary that says this is the same interpretation as DW_FORM_ref_addr, which is true for v3 and onward.
While the interpretation of DW_FORM_ref_addr did change from v2 to v3, I think that's not relevant to DW_OP_call_ref, because the normative text for its operand has always explicitly specified that it is format-dependent.
So, I think it is correct to remove getRefAddrSize() from DWARFExpression, and have the SizeRefAddr case be strictly format-dependent.

Removing the Version field also seems appropriate, even though it's a bit of churn. Version would be most helpful for something like strict verification; on the other hand, all the operator descriptions carry the version-when-first-defined, and the verify() call takes a DWARFUnit* which will specify the version to verify against.

One thing is missing: There should be a test to verify we are handling DW_OP_call_ref in a V2 unit according to the format rather than the address size.

ikudrin updated this revision to Diff 240137.Jan 24 2020, 2:45 AM
ikudrin retitled this revision from [DWARF] Do not pass Version to DWARFExpression. NFCI. to [DWARF] Do not pass Version to DWARFExpression..
  • Rebase, Update;
  • Add a test.

@probinson, did you mean a test like this? I am a bit in doubt because it checks an unrealistic case.

dblaikie added inline comments.Jan 24 2020, 11:52 AM
llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
158–161

Looks like the old code handled 64 and 32 - so is this not a regression? (unlikely we'd want to regress functionality) or was this dead code previously? Or some other explanation?

probinson accepted this revision.Jan 24 2020, 12:58 PM

LGTM but give @dblaikie a chance to say whether he accepts my explanation.

llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
158–161

The old code would use getU64() only if you had Version == 2 and AddressSize == 64. For Version > 2 it was hard-coded to return size 4, i.e. it did not correctly look at the 32/64 *format*. Doing that correctly will, I expect, be a follow-up (because @ikudrin has been doing DWARF-64 stuff in general).

IMO this is not a regression. Pedantically you should never see a SizeRefAddr op in DWARF v2, it was introduced in v3.

llvm/test/DebugInfo/X86/DW_OP_call_ref_ver2.s
5

Please add a comment saying what this is for.

This revision is now accepted and ready to land.Jan 24 2020, 12:58 PM
ikudrin updated this revision to Diff 240338.Jan 24 2020, 5:39 PM
  • Add an explanatory comment to the test.
dblaikie accepted this revision.Jan 24 2020, 7:46 PM
dblaikie added inline comments.
llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
158–161

Pedantically you should never see a SizeRefAddr op in DWARF v2, it was introduced in v3.

That suggests this was dead code, then? That this code path wasn't reachable (no SizeRefAddr op in DWARFv2) with anything other than a ref addr size of 4, so the other two code paths here were dead?

Or that they are reachable (one could craft an input that would execute the code), but the behavior isn't important/meaningful to change?

It looks like it's literally unreachable/dead code (the only SizeRefAddr in Descriptions table is for DWARFv3 and above), so I'm fine with that.

This revision was automatically updated to reflect the committed changes.
ikudrin marked an inline comment as done.