This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] Construct relocation-aware DWARFDataExtractor to decode .eh_frame addresses correctly
ClosedPublic

Authored by MaskRay on Jul 18 2020, 10:05 AM.

Details

Summary

In an object file, a "PC Begin" field in a FDE is usually relocated by a
PC-relative relocation. Use a relocation-aware DWARFDataExtractor overload (with
DWARFContext and a reference to its internal .eh_frame representation) to decode
addresses correctly. In an object file, most sections have addresses of zero. So
the displayed addresses are almost always offsets relative to the start of the
associated text section.

DWARFContext::create handles .eh_frame and .rela.eh_frame by itself, so if there
are more than one .eh_frame (technically possible, but almost always erronerous
in practice), this will only handle the first one. Supporting multiple
.eh_frame is beyond the scope of this patch.

Diff Detail

Event Timeline

MaskRay created this revision.Jul 18 2020, 10:05 AM
MaskRay edited the summary of this revision. (Show Details)Jul 18 2020, 10:05 AM
MaskRay updated this revision to Diff 279013.Jul 18 2020, 10:07 AM

Add a comment

grimar accepted this revision.Jul 20 2020, 5:13 AM

The description seems to be confusing, it says: "Use a relocation-aware DWARFDataExtractor instead of plain DataExtractor",
though both the code on the left and on the right use DWARFDataExtractor type and the difference is in the internal logic.

The rest looks fine to me (with a nit about headers order), I'd like somebody else to look at this too though.

llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
26

I think you could just add "DWARFContext.h", no need to sort the headers in this patch.

This revision is now accepted and ready to land.Jul 20 2020, 5:13 AM

I agree with @grimar as it looks like the change is from a DWARFDataExtractor without relocations to one with relocations.
Regarding header order, in cases like this it's usual to do an NFC commit to sort the headers that are there, and then the functional patch just adds the new one in the right place.

MaskRay updated this revision to Diff 279304.Jul 20 2020, 10:28 AM
MaskRay edited the summary of this revision. (Show Details)

Fix description (Use a relocation-aware DWARFDataExtractor constructor)

MaskRay marked an inline comment as done.Jul 20 2020, 10:28 AM

@probinson Looks good now? :)

This revision was automatically updated to reflect the committed changes.