Skip to content

Commit 34cd03c

Browse files
ahmedbougachadtapuska
authored andcommitted
[OrcJIT] Support arm64e/ptrauth.
1 parent cb43ce6 commit 34cd03c

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

llvm/include/llvm/ExecutionEngine/JITSymbol.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,26 @@ template <typename T> T jitTargetAddressToFunction(JITTargetAddress Addr) {
6262
static_assert(std::is_pointer<T>::value &&
6363
std::is_function<std::remove_pointer_t<T>>::value,
6464
"T must be a function pointer type");
65-
return jitTargetAddressToPointer<T>(Addr);
65+
auto VoidPtrResult = jitTargetAddressToPointer<void*>(Addr);
66+
67+
// If this process uses ptrauth then sign the pointer.
68+
#if __has_feature(ptrauth_calls)
69+
VoidPtrResult =
70+
__builtin_ptrauth_sign_unauthenticated(VoidPtrResult, 0, 0);
71+
#endif
72+
73+
return reinterpret_cast<T>(VoidPtrResult);
6674
}
6775

6876
/// Convert a pointer to a JITTargetAddress.
6977
template <typename T> JITTargetAddress pointerToJITTargetAddress(T *Ptr) {
70-
return static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(Ptr));
78+
// If this process uses ptrauth then sign the pointer.
79+
const void *Tmp = reinterpret_cast<const void*>(Ptr);
80+
#if __has_feature(ptrauth_calls)
81+
Tmp = __builtin_ptrauth_strip(Tmp, 0);
82+
#endif
83+
84+
return static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(Tmp));
7185
}
7286

7387
/// Flags for symbols in the JIT.

llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ struct CompactUnwindTraits_MachO_arm64
651651

652652
void link_MachO_arm64(std::unique_ptr<LinkGraph> G,
653653
std::unique_ptr<JITLinkContext> Ctx) {
654-
655654
PassConfiguration Config;
656655

657656
if (Ctx->shouldAddDefaultTargetPasses(G->getTargetTriple())) {

llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,13 @@ Error DynamicLibrarySearchGenerator::tryToGenerate(
262262

263263
std::string Tmp((*Name).data() + HasGlobalPrefix,
264264
(*Name).size() - HasGlobalPrefix);
265-
if (void *P = Dylib.getAddressOfSymbol(Tmp.c_str()))
265+
if (void *P = Dylib.getAddressOfSymbol(Tmp.c_str())) {
266+
// If this process uses ptrauth then strip the pointer.
267+
#if __has_feature(ptrauth_calls)
268+
P = __builtin_ptrauth_strip(P, 0);
269+
#endif
266270
NewSymbols[Name] = {ExecutorAddr::fromPtr(P), JITSymbolFlags::Exported};
271+
}
267272
}
268273

269274
if (NewSymbols.empty())

llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES,
116116

117117
case Triple::aarch64:
118118
case Triple::aarch64_32:
119+
// arm64e doesn't support lazy call.
120+
if (T.isArm64e())
121+
return make_error<StringError>(
122+
std::string("No callback manager available for ") + T.str(),
123+
inconvertibleErrorCode());
119124
return LocalLazyCallThroughManager::Create<OrcAArch64>(ES,
120125
ErrorHandlerAddr);
121126

0 commit comments

Comments
 (0)