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.
Details
Diff Detail
Event Timeline
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.
- 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.
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? |
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. |
llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp | ||
---|---|---|
158–161 |
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. |
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?