Skip to content

Commit c62a786

Browse files
committed
[MachO] Apply the correct calling convention for objc_retain_xN / objc_release_xN
The type library for the Objective-C runtime does not apply the custom calling conventions these functions use. Detect these functions when creating symbols for imported functions and apply the custom calling convention to them. Fixes #8031.
1 parent 896f4b9 commit c62a786

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

view/macho/machoview.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,17 @@ Ref<Symbol> MachoView::DefineMachoSymbol(
27122712
}
27132713
}
27142714

2715+
if ((type == ExternalSymbol || type == ImportAddressSymbol)
2716+
&& (name.find("_objc_retain_x") != std::string::npos || name.find("_objc_release_x") != std::string::npos))
2717+
{
2718+
auto x = name.rfind('x');
2719+
auto num = name.substr(x + 1);
2720+
2721+
auto cc = GetDefaultArchitecture()->GetCallingConventionByName("apple-arm64-objc-fast-arc-" + num);
2722+
if (auto idType = GetTypeByName({"id"}); cc && idType)
2723+
typeRef = Type::FunctionType(idType, cc, {{"obj", idType}});
2724+
}
2725+
27152726
return std::pair<Ref<Symbol>, Ref<Type>>(
27162727
new Symbol(type, shortName, fullName, rawName, addr, binding, nameSpace), typeRef);
27172728
};

0 commit comments

Comments
 (0)