-//===- MCJITTest.cpp - Unit tests for the MCJIT ---------------------------===//
+//===- MCJITTest.cpp - Unit tests for the MCJIT -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
//===----------------------------------------------------------------------===//
#include "llvm/ExecutionEngine/MCJIT.h"
+#include "llvm/Support/DynamicLibrary.h"
#include "MCJITTestBase.h"
#include "gtest/gtest.h"
EXPECT_TRUE(0 != ptr)
<< "Unable to get pointer to main() from JIT";
- int (*FuncPtr)(void) = (int(*)(void))ptr;
+ int (*FuncPtr)() = (int(*)())ptr;
int returnCode = FuncPtr();
EXPECT_EQ(returnCode, rc);
}
uint64_t rgvPtr = TheJIT->getFunctionAddress(ReturnGlobal->getName().str());
EXPECT_TRUE(0 != rgvPtr);
- int32_t(*FuncPtr)(void) = (int32_t(*)(void))rgvPtr;
+ int32_t(*FuncPtr)() = (int32_t(*)())rgvPtr;
EXPECT_EQ(initialNum, FuncPtr())
<< "Invalid value for global returned from JITted function";
}
EXPECT_TRUE(0 != ptr)
<< "Unable to get pointer to outer function from JIT";
- int32_t(*FuncPtr)(void) = (int32_t(*)(void))ptr;
+ int32_t(*FuncPtr)() = (int32_t(*)())ptr;
EXPECT_EQ(innerRetVal, FuncPtr())
<< "Incorrect result returned from function";
}
void *A = TheJIT->getPointerToFunction(Foo);
void *B = TheJIT->getPointerToFunction(Foo);
- EXPECT_TRUE(A != 0) << "Failed lookup - test not correctly configured.";
+ EXPECT_TRUE(A != nullptr) << "Failed lookup - test not correctly configured.";
EXPECT_EQ(A, B) << "Repeat calls to getPointerToFunction fail.";
}
Function *Foo = insertExternalReferenceToFunction<int32_t(void)>(M.get(),
"\1Foo");
- Function *Parent = startFunction<int32_t(void)>(M.get(), "Parent");
+ startFunction<int32_t(void)>(M.get(), "Parent");
CallInst *Call = Builder.CreateCall(Foo, {});
Builder.CreateRet(Call);
// prevents us from capturing local variables, which is why this is static.
static std::string UnresolvedExternal;
FunctionHandlerPtr UnresolvedHandler = [] (const std::string &str) {
+ // Try to resolve the function in the current process before marking it as
+ // unresolved. This solves an issue on ARM where '__aeabi_*' function names
+ // are passed to this handler.
+ void *symbol =
+ llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(str.c_str());
+ if (symbol) {
+ return symbol;
+ }
+
UnresolvedExternal = str;
return (void *)(uintptr_t)-1;
};
"\1Foo1");
Function *Foo2 = insertExternalReferenceToFunction<int32_t(void)>(M.get(),
"\1Foo2");
- Function *Parent = startFunction<int32_t(void)>(M.get(), "Parent");
+ startFunction<int32_t(void)>(M.get(), "Parent");
CallInst *Call1 = Builder.CreateCall(Foo1, {});
CallInst *Call2 = Builder.CreateCall(Foo2, {});
Value *Result = Builder.CreateAdd(Call1, Call2);
// external functions in the module.
std::vector<std::string> UnresolvedExternals;
auto UnresolvedHandler = [&UnresolvedExternals] (const std::string &str) {
- llvm:dbgs() << "str is '" << str << "'\n";
+ // Try to resolve the function in the current process before marking it as
+ // unresolved. This solves an issue on ARM where '__aeabi_*' function names
+ // are passed to this handler.
+ void *symbol =
+ llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(str.c_str());
+ if (symbol) {
+ return symbol;
+ }
UnresolvedExternals.push_back(str);
return (void *)(uintptr_t)-1;
};
// Verify that our handler was called for each unresolved function.
auto I = UnresolvedExternals.begin(), E = UnresolvedExternals.end();
- EXPECT_EQ(UnresolvedExternals.size(), 2);
+ EXPECT_EQ(UnresolvedExternals.size(), 2u);
EXPECT_FALSE(std::find(I, E, "Foo1") == E);
EXPECT_FALSE(std::find(I, E, "Foo2") == E);
}
-}
+} // end anonymous namespace