This is an archive of the discontinued LLVM Phabricator instance.

[llvm-xray] Support for PIE
ClosedPublic

Authored by phosek on Dec 10 2018, 7:30 PM.

Details

Summary

When the instrumented binary is linked as PIE, we need to apply the
relative relocations to sleds. This is handled by the dynamic linker
at runtime, but when processing the file we have to do it ourselves.

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Dec 10 2018, 7:30 PM
dberris accepted this revision.Dec 10 2018, 8:22 PM

LGTM -- Thanks @phosek!

This revision is now accepted and ready to land.Dec 10 2018, 8:22 PM
MaskRay added inline comments.Dec 11 2018, 9:38 AM
llvm/lib/XRay/InstrumentationMap.cpp
90 ↗(On Diff #177648)

Section.relocations() applies on either SHT_REL or SHT_RELA. I think the code can be applied on just SHT_RELA.

if (Section.isBSS() || Section.isVirtual()) is not necessary.

MaskRay added inline comments.Dec 11 2018, 9:40 AM
llvm/lib/XRay/InstrumentationMap.cpp
97 ↗(On Diff #177648)

The code only works on x86_64 and ppc64le. So the relative relocations can just be enumerated here.

joerg added a subscriber: joerg.Dec 11 2018, 12:55 PM
joerg added inline comments.
llvm/lib/XRay/InstrumentationMap.cpp
97 ↗(On Diff #177648)

Please explicitly check for the relocation types you care about. They are not the only relocations you can find in a PIE binary, even with static linking.

phosek updated this revision to Diff 178162.Dec 13 2018, 5:02 PM
phosek marked 3 inline comments as done.
dberris accepted this revision.Dec 13 2018, 5:19 PM

LGTM still, thanks @phosek!

MaskRay accepted this revision.Dec 13 2018, 5:22 PM
MaskRay added inline comments.
llvm/lib/XRay/InstrumentationMap.cpp
105 ↗(On Diff #178162)

It can be simplified with
if (auto AddendOrErr = object::ELFRelocationRef(Reloc).getAddend())

phosek updated this revision to Diff 178164.Dec 13 2018, 5:39 PM
phosek marked an inline comment as done.
This revision was automatically updated to reflect the committed changes.