This is an archive of the discontinued LLVM Phabricator instance.

RuntimeDyldELF: do not create thunk when jump target is in the same object file and is reachable with R_AARCH64_CALL26.
ClosedPublic

Authored by evgeny777 on Dec 25 2016, 9:14 AM.

Details

Summary

I'm porting LLVM jit to a custom kernel where mmap is disabled and the only way to inject executable code in the running process is to generate and load DSO. This makes it problematic to have absolute jumps with source and target in the same object file, because ASLR is being used and I only know DSO load address after call to dlopen.

To my understanding there is no need to use absolute jumps, when relative can do the job. Also they are faster and require less number of relocs to be resolved.

All LLVM tests pass. I didn't create extra unit tests, because I'd like to know if this is correct way of doing things first.

Diff Detail

Event Timeline

evgeny777 updated this revision to Diff 82477.Dec 25 2016, 9:14 AM
evgeny777 retitled this revision from to RuntimeDyldELF: do not create thunk when jump target is in the same object file and is reachable with R_AARCH64_CALL26..
evgeny777 updated this object.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
evgeny777 added subscribers: ikudrin, grimar.
davide edited edge metadata.Dec 25 2016, 9:40 AM

Can you please add a testcase? That would help me understand better the patch.
Also, probably Lang should take a look (cc:ed).

lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
952–954

please add a comment explaining what this function does.

964–966

prefer C++-style casts to C-style casts, thanks.

968

ditto.

973–975

28 is a little bit a magic'ish number, I'm aware where it comes from but it's non-obvious why it's there. can you please elaborate in the previous comment?

lhames edited edge metadata.Dec 25 2016, 12:35 PM

As davide mentioned, there should be a test case for this.

Out of interest, where does it currently use absolute jumps (I don't follow RuntimeDyldELF closely)? Can we / should we change it to uniformly use relative jumps?

evgeny777 updated this revision to Diff 82494.Dec 26 2016, 4:35 AM
evgeny777 edited edge metadata.
evgeny777 removed rL LLVM as the repository for this revision.

Thanks for looking at it. I've added test case and addressed review comments from Davide.

Currently RuntimeDyldELF emits absolute jump for every relocation in object file. This works for most targets, though being slightly inefficient. Unfortunately this is completely broken for me (see summary for this patch).

I have no additional comments but Lang should sign-off before this goes in.

Lang, do you have any comments on this?

lhames accepted this revision.Jan 7 2017, 9:48 PM
lhames edited edge metadata.

Apologies for the delayed reply. This looks good to me.

This revision is now accepted and ready to land.Jan 7 2017, 9:48 PM
This revision was automatically updated to reflect the committed changes.