This is an archive of the discontinued LLVM Phabricator instance.

[ORC-RT] Hook objc's class_getImageName for JITDylibs
Needs ReviewPublic

Authored by benlangmuir on Jan 12 2022, 4:42 PM.

Details

Reviewers
lhames
Summary

Use the objc runtime's callback to customize the image name for JITDylibs to match their name. This allows some mechanisms that look up files next to binaries to work correctly if the JITDylib name is a path (but not if they use dladdr or dyld_image_path_containing_address for now).

Diff Detail

Event Timeline

benlangmuir created this revision.Jan 12 2022, 4:42 PM
benlangmuir requested review of this revision.Jan 12 2022, 4:42 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 12 2022, 4:42 PM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript
benlangmuir added inline comments.Jan 12 2022, 4:48 PM
compiler-rt/lib/orc/macho_platform.cpp
372

I wasn't 100% sure whether this should be a log message or an error. The other objc functionality uses errors, but in those cases the objc code will fail completely if you're missing the runtime functions. In this case, class_getImageName returning nullptr doesn't seem bad enough to make it a hard error to me -- you might not be using that at all. It's too bad there's no such thing as a runtime warning.

Sorry for the delayed review on this one.

The switch to allocation actions will have broken this -- I'll try to port it to top-of-tree tomorrow.

compiler-rt/lib/orc/executor_address.h
196–206

What about using upper-bound here? It has the advantage that you only need to check one range, though you do have to special-case the empty map.

if (Map.empty())
  return Map.end();
auto I = std::prev(Map.upper_bound({Addr, Addr}));
if (I->first.contains(Addr))
  return I;
return Map.end();
compiler-rt/lib/orc/macho_platform.cpp
372

For now I think we debug-log when we see objc_setHook_getImageName missing, and hard-error in the hook. Especially in early development I'd rather fail loudly wherever we deviate from AOT behavior.

Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 5:27 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
benlangmuir added inline comments.Apr 29 2022, 2:24 PM
compiler-rt/lib/orc/executor_address.h
196–206

I think this would work, although you need to check I != Map.begin() before calling prev I believe.