This is an archive of the discontinued LLVM Phabricator instance.

Handle the new "selector-specific stub" ObjC Method dispatch method
ClosedPublic

Authored by jingham on Apr 8 2022, 12:53 PM.

Details

Reviewers
JDevlieghere
Summary

Clang is adding a feature to ObjC code generation, where instead of calling
objc_msgSend directly with an object & selector, it generates a stub that
gets passed only the object and the stub figures out the selector.

This patch adds support for following that dispatch method into the implementation
function.

Diff Detail

Event Timeline

jingham created this revision.Apr 8 2022, 12:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2022, 12:53 PM
jingham requested review of this revision.Apr 8 2022, 12:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2022, 12:53 PM
jingham updated this revision to Diff 421638.Apr 8 2022, 2:35 PM

-U9999 on the patch.

JDevlieghere added inline comments.Apr 8 2022, 2:55 PM
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
52–53

Nit: Seems like the formatting is a bit off. I would copy/paste this code in a separate file, run clang-format over it, and paste it back.

642–649

I don't understand why we need to have two versions of the code. IIUC, if there's a "stret return lookup function", then if we pass is_stret == true we'll use it. Otherwise we'll unconditionally use the straight lookup. Why do we need two variants of the code at all? Can't we pass false to is_stret and achieve the same result with the g_lookup_implementation_with_stret_function_code variant?

821–823

Nit: for consistency with the line below

1017–1020

The if (log) check is redundant. It's the purpose of the macro to expand to that that. Same below.

1075

redundant

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h
55–65

Nit: I think these should be doxygen comments, so ///. You can group them like this:

lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
82

redundant

lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
404–407
return class_addr == rhs.class_addr && sel_name == rhs.sel_name;
411–417
if (class_addr < rhs.class_addr)
  return true;
if (class_addr > rhs.class_addr)
  return false;
return ConstString::Compare(sel_name, rhs.sel_name);
jingham updated this revision to Diff 421651.Apr 8 2022, 5:00 PM

Address review comments

I also made one functional change. Some code was checking !m_lookup_implementation_function_code.empty() to see if we had found an implementation function. That won't work if I put the common prefix into this ivar in the constructor, so I change that to leave the member empty till we actually figure out that we want one or the other of the prefixes. This is an error path that you have to intentionally mess things up to get to, but still it's worth preserving this signal.

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
642–649

On the systems that don't use stret returns, class_getMethodImplementation_stret doesn't exist. So we would either have to have two versions of that part of the code, or passing function pointers to the two functions (making them the same in the no _stret case) or do some dlsym type ugliness.

This solution is straightforward, and reducing complexity in these Utility functions is a virtue. Having two copies of all the code was a bit bogus, but this solution is straightforward and easy to debug.

jingham marked 6 inline comments as done.Apr 8 2022, 5:05 PM
jingham added inline comments.
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
1017–1020

Old habits die hard...

JDevlieghere accepted this revision.Apr 8 2022, 5:33 PM

Thanks Jim. This LGTM.

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
642–649

Thanks. I saw the m_impl_stret_fn_addr and figured we were passing in the function pointer ourselves. Makes sense.

This revision is now accepted and ready to land.Apr 8 2022, 5:33 PM