This is an archive of the discontinued LLVM Phabricator instance.

[llvm-symbolizer] Add switch to adjust addresses by fixed offset
ClosedPublic

Authored by jhenderson on Jan 24 2019, 5:36 AM.

Details

Summary

If a stack trace or similar has a list of addresses from a program or DSO loaded at a variable address (e.g. due to ASLR), the addresses will not directly correspond to the addresses stored in the object file. If a user wishes to use llvm-symbolizer, they have to subtract the load address from every address. This is somewhat inconvenient, especially as the output of --print-address will result in the adjusted address being listed, rather than the address coming from the stack trace, making it harder to map results between the two.

This change adds a new switch to llvm-symbolizer --adjust-vma which takes an offset, which is then used to automatically do this calculation. The printed address remains the input address (allowing for easy mapping), whilst the specified offset is applied to the addresses when performing the lookup.

The switch is conceptually similar to llvm-objdump's new switch of the same name (see D57051), which in turn mirrors a GNU switch. There is no equivalent switch in addr2line.

Diff Detail

Repository
rL LLVM

Event Timeline

jhenderson created this revision.Jan 24 2019, 5:36 AM

Add documentation.

I think this is a good one. Interesting what others think.

test/tools/llvm-symbolizer/adjust-vma.s
18

I would probably suggest to do:
llvm-symbolizer 0xa 0xb --print-address --adjust-vma 0x100

That way it would be easy to match this invocation with one used in the first test and see a difference in result.

I have no strong preference, just was a bit confused with 0xb at first, because it was already used as
an address in the previous test and my brain tried to match it with it :)

jhenderson marked an inline comment as done.Jan 24 2019, 6:23 AM
jhenderson added inline comments.
test/tools/llvm-symbolizer/adjust-vma.s
18

I can understand the confusion. That's what I did originally, but a colleague suggested that I change the offset to 0xa to test the case where the calculation only just overflows. How about the following:

llvm-symbolizer 0xa 0xb --print-address --adjust-vma 0xc

grimar added inline comments.Jan 24 2019, 6:25 AM
test/tools/llvm-symbolizer/adjust-vma.s
18

Yeah, that will also work, thanks!

Tweak test to reduce risk of confusion.

grimar accepted this revision.Jan 25 2019, 1:32 AM

LGTM

This revision is now accepted and ready to land.Jan 25 2019, 1:32 AM
This revision was automatically updated to reflect the committed changes.