Skip to content

Commit 566f086

Browse files
Maqrkkyuri91
authored andcommitted
Implement get_thread_pointer in PreExecuter
The PreExecuter would fail when trying to execute the intrinsic llvm.cheerp.get.thread.pointer. And since this would occur in the global constructor with priority 101, no other global constructors would run. This commit introduces a simple fix: we return 0. The code that actually calls this intrinsic in musl then will use __dummy_thread as the thread pointer.
1 parent e7dc431 commit 566f086

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

llvm/lib/ExecutionEngine/Interpreter/Execution.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,15 @@ void Interpreter::visitIntrinsicInst(IntrinsicInst &I) {
11841184

11851185
if (ForPreExecute && strncmp(I.getCalledFunction()->getName().str().c_str(), "llvm.cheerp", strlen("llvm.cheerp")) == 0)
11861186
{
1187+
if (I.getCalledFunction()->getName() == "llvm.cheerp.get.thread.pointer")
1188+
{
1189+
// We return a value of zero. The code in musl will instead assign it the address of the __dummy_thread variable.
1190+
IntegerType* Ty = cast<IntegerType>(I.getType());
1191+
GenericValue Result;
1192+
Result.IntVal = APInt(Ty->getBitWidth(), 0);
1193+
SetValue(&I, Result, SF);
1194+
return;
1195+
}
11871196
errs() << "Tried to execute cheerp intrinsic: " << I.getCalledFunction()->getName() << "\n";
11881197
printCallTrace();
11891198
CleanAbort = true;

0 commit comments

Comments
 (0)