This is an archive of the discontinued LLVM Phabricator instance.

[RuntimeDyld] Added support for relocation of indirect functions
ClosedPublic

Authored by MoritzS on Jul 6 2021, 1:27 AM.

Details

Summary

In ELF, symbols of type STT_GNU_IFUNC need to be resolved by calling the
function at the symbol's address. This is implemented by adding special
stubs for all symbols of that type.

Diff Detail

Event Timeline

MoritzS created this revision.Jul 6 2021, 1:27 AM
MoritzS requested review of this revision.Jul 6 2021, 1:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2021, 1:27 AM

This is really cool.

Does the Indirect flag really need to go onto JITSymbolFlags? My mental model of ifuncs (very limited -- I haven't used them myself) is "self-updating PLT" -- its ifunc-ness is opaque to callers right?

Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2022, 5:38 PM
Herald added a subscriber: StephenFan. · View Herald Transcript

Does the Indirect flag really need to go onto JITSymbolFlags? My mental model of ifuncs (very limited -- I haven't used them myself) is "self-updating PLT" -- its ifunc-ness is opaque to callers right?

Yes, you are right, ifuncs are completely opaque to callers, so we probably shouldn't add that flag. I will change that.

MoritzS updated this revision to Diff 444936.Jul 15 2022, 3:55 AM

Removed Indirect from JITSymbolFlags

MoritzS updated this revision to Diff 445468.Jul 18 2022, 5:53 AM

Fixed typos in comments

MoritzS updated this revision to Diff 452152.Aug 12 2022, 5:33 AM

Rebased onto main

MoritzS updated this revision to Diff 452188.Aug 12 2022, 8:10 AM

Rebased again because of failing tests on main

@lhames do you have any other comments? Can I merge this?

MoritzS updated this revision to Diff 462843.Sep 26 2022, 2:37 AM

Rebased onto main, let tests run again

MoritzS updated this revision to Diff 463143.Sep 27 2022, 1:26 AM

Fixed a failing test: In ELFObjectFile I added a case to set the symbol type to
ST_Function also for ifunc symbols. As far as I know, ifunc symbols can only be
functions, but even objdump from binutils doesn't print those symbols with the
function type. I removed that case again, ifunc symbols now have type ST_Other.

MoritzS updated this revision to Diff 467059.Oct 12 2022, 1:55 AM

Fixed an unchecked Expected<T> which lead to several test failures. All tests should run now, hopefully.

MoritzS updated this revision to Diff 469171.Oct 20 2022, 5:10 AM

Use llvm::cantFail instead of just returning

The only failing "test" is clang-format. Should I reformat the complete files? Because my additions are formatted correctly, but the rest of the file is not.

lhames accepted this revision.Oct 31 2022, 8:34 AM

LGTM, and sorry for the very delayed review!

What are your blockers to moving over to ORC/JITLink these days? This is excellent work -- if there's something that I can do to unblock you so that you can work on the new JIT linker I'd be keen to know. ;)

This revision is now accepted and ready to land.Oct 31 2022, 8:34 AM

The only failing "test" is clang-format. Should I reformat the complete files? Because my additions are formatted correctly, but the rest of the file is not.

Only your additions should be reformatted. Reformatting the rest of the files will obscure the commit history. It's better to let them be updated to the correct format over time as patches come in. (Though my hope is that we can kill RuntimeDyld in the not too distant future and just move everyone over to JITLink)

This revision was landed with ongoing or failed builds.Nov 2 2022, 2:46 AM
This revision was automatically updated to reflect the committed changes.