This is an archive of the discontinued LLVM Phabricator instance.

[DWARFLinker] Refactor cloneAddressAttribute().
ClosedPublic

Authored by avl on Feb 3 2023, 7:13 AM.

Details

Summary

As a preparation for implementing DWARFv5 address ranges generation,
this patch refactors cloneAddressAttribute() method. It has special
handling for addresses which can be relocated in some unrelated value,
for applying relocations twice, for indexed addresses. Instead of
all these special handlings this patch uses general handling:

Read attribute value from InputDIE and apply PCOffset.

Another thing is that current handling of DW_FORM_addrx misses the
fact that relocations might be applied twice in some cases. This
patch fixes this problem also.

Diff Detail

Event Timeline

avl created this revision.Feb 3 2023, 7:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 3 2023, 7:13 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
avl requested review of this revision.Feb 3 2023, 7:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 3 2023, 7:13 AM
friss added a comment.Feb 3 2023, 10:24 AM

This feels like a nice generalization (and I like the shape of the new code better), but I'm wondering if it's not too general. For example a DT_AT_location can be DW_FORM_addr, and applying PCOffset to it would be wrong. I'm not sure what PCOffset is set to in a variable DIE, but it does feel somewhat wrong even if it's 0. I cannot be 100% sure, but I believe that fear of mishandling non-PC addresses was the original thinking that led to spelling out all the supported cases.

avl added a comment.Feb 4 2023, 12:36 AM

This feels like a nice generalization (and I like the shape of the new code better), but I'm wondering if it's not too general. For example a DT_AT_location can be DW_FORM_addr, and applying PCOffset to it would be wrong. I'm not sure what PCOffset is set to in a variable DIE, but it does feel somewhat wrong even if it's 0. I cannot be 100% sure, but I believe that fear of mishandling non-PC addresses was the original thinking that led to spelling out all the supported cases.

It looks like DW_AT_location can not have DW_FORM_addr attribute. DWARF spec says that DW_AT_location has "exprloc, loclistptr" classes, while DW_FORM_addr is used for "address" class. It is also said for DW_FORM_addr:

• Debugging information entries may have attributes with the form
DW_FORM_addr (see Section 7.5.4 on page 207). These attributes represent
locations within the virtual address space of the program, and require
relocation.
• A DWARF expression may contain a DW_OP_addr (see Section 2.5.1.1 on
page 26) which contains a location within the virtual address space of the
program, and require relocation.

Thus, it looks like lt is Ok to always apply PCOffset to attribute of DW_FORM_addr form.

JDevlieghere accepted this revision.Feb 9 2023, 2:24 PM

LGTM

llvm/lib/DWARFLinker/DWARFLinker.cpp
1174
1206–1208
This revision is now accepted and ready to land.Feb 9 2023, 2:24 PM
avl added a comment.Feb 13 2023, 3:00 AM

Thank you for the review!

This revision was automatically updated to reflect the committed changes.