This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf/obj] - Stop printing wrong addresses for arm32 unwind info for non-relocatable objects.
ClosedPublic

Authored by grimar on Sep 22 2020, 1:43 AM.

Details

Summary

This is the first patch for https://bugs.llvm.org/show_bug.cgi?id=47581.

Currently -u does not compute function addresses correctly and
dumps broken addresses for non-relocatable objects.

ARM spec says:
"An index table entry consists of 2 words.
The first word contains a prel31 offset (see Relocations) to the start of a function, with bit 31 clear."
...
"The relocated 31 bits form a place-relative signed offset to the referenced entity.
For brevity, this document will refer to the results of these relocations as "prel31 offsets"."

(https://developer.arm.com/documentation/ihi0038/c/?lang=en#index-table-entries)
(https://developer.arm.com/documentation/ihi0038/c/?lang=en#relocations)

Currently we use an address of the SHT_ARM_EXIDX section instead of an address of an entry
in computations. As a result we compute an offset that is not really "place-relative",
but section relative, what is wrong.

The patch fixes this issue.

Diff Detail

Event Timeline

grimar created this revision.Sep 22 2020, 1:43 AM
grimar requested review of this revision.Sep 22 2020, 1:43 AM
grimar updated this revision to Diff 293378.Sep 22 2020, 1:47 AM
  • Fix a mistype in comment.

I think there may still be problems in a non-relocatable ELF file when there is more than one executable output section as there is only one .ARM.exidx output section and only one sh_link.

llvm/test/tools/llvm-readobj/ELF/ARM/unwind-non-relocatable.test
70

entry offset should be (0) for the first entry

llvm/tools/llvm-readobj/ARMEHABIPrinter.h
543–567

For a non-relocatable ELF file the sh_link field is not reliable as there can be more than one OutputSection, but there will only be one .ARM.exidx OutputSection and the sh_link can only point to one OutputSection. I think that FunctionAtAddress will need changing so that it doesn't require a matching section when there is non-relocatable objects.

554

Offset is a bit confusing in this context. As I understand it, it is an offset for relocatable objects but an absolute address for non-relocatable objects.

556

You may want to replace the IT->sh_addr with 0 rather than using the 0 from the relocatable object sh_addr, not a strong opinion though.

grimar updated this revision to Diff 293698.Sep 23 2020, 5:11 AM
grimar marked 4 inline comments as done.

Thanks, Peter! I've addressed all review comments.

llvm/test/tools/llvm-readobj/ELF/ARM/unwind-non-relocatable.test
70

Done. I've also updated comments to mention that 31 bit is used in offsets.

llvm/tools/llvm-readobj/ARMEHABIPrinter.h
543–567

Thanks! I've did this change and updated the test case to drop sh_link field of the SHT_ARM_EXIDX section.

554

I think we probably can use Address for both? We pass it to the FunctionAtAddress below.

556

Yes, I also found we probably should do it, but I haven't changed it in this patch because it is a possible behavior change for relocatable objects.

If I change this to 0, no our tests fail, but it probably means that the behavior is not well documented by tests. I think changing this for relocatable objects probably belongs to a different patch that should also add a correspondent test.

psmith accepted this revision.Sep 23 2020, 10:29 AM

Thanks for the update. LGTM. Happy to see other parts done in follow up commits

This revision is now accepted and ready to land.Sep 23 2020, 10:29 AM