Skip to content

Commit b261dd9

Browse files
author
Emery Conrad
committed
fix GetFunctionAddress resolution with explicit name change
1 parent af760d0 commit b261dd9

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

include/CppInterOp/CppInterOp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ CPPINTEROP_API bool IsStaticMethod(TCppConstFunction_t method);
560560
CPPINTEROP_API bool IsExplicit(TCppConstFunction_t method);
561561

562562
///\returns the address of the function given its potentially mangled name.
563-
CPPINTEROP_API TCppFuncAddr_t GetFunctionAddress(const char* mangled_name);
563+
CPPINTEROP_API TCppFuncAddr_t
564+
GetFunctionAddressFromMangledName(const char* mangled_name);
564565

565566
///\returns the address of the function given its function declaration.
566567
CPPINTEROP_API TCppFuncAddr_t GetFunctionAddress(TCppFunction_t method);

include/CppInterOp/Dispatch.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ extern "C" CPPINTEROP_API CppFnPtrTy CppGetProcAddress(const char* procname);
184184
DISPATCH_API(IsExplicit, decltype(&CppImpl::IsExplicit)) \
185185
DISPATCH_API(MakeFunctionCallable, \
186186
CppImpl::JitCall (*)(CppImpl::TCppConstFunction_t)) \
187-
DISPATCH_API(GetFunctionAddress, \
188-
CppImpl::TCppFuncAddr_t (*)(CppImpl::TCppFunction_t)) \
187+
DISPATCH_API(GetFunctionAddress, decltype(&CppImpl::GetFunctionAddress)) \
189188
/*DISPATCH_API(API_name, fnptr_ty)*/
190189

191190
// TODO: implement overload that takes an existing opened DL handle

lib/CppInterOp/CppInterOp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ bool IsExplicit(TCppConstFunction_t method) {
14301430
return false;
14311431
}
14321432

1433-
TCppFuncAddr_t GetFunctionAddress(const char* mangled_name) {
1433+
TCppFuncAddr_t GetFunctionAddressFromMangledName(const char* mangled_name) {
14341434
auto& I = getInterp();
14351435
auto FDAorErr = compat::getSymbolAddress(I, mangled_name);
14361436
if (llvm::Error Err = FDAorErr.takeError())
@@ -1462,7 +1462,7 @@ static TCppFuncAddr_t GetFunctionAddress(const FunctionDecl* FD) {
14621462

14631463
// Constructor and Destructors needs to be handled differently
14641464
if (!llvm::isa<CXXConstructorDecl>(FD) && !llvm::isa<CXXDestructorDecl>(FD))
1465-
return GetFunctionAddress(get_mangled_name(FD).c_str());
1465+
return GetFunctionAddressFromMangledName(get_mangled_name(FD).c_str());
14661466

14671467
return 0;
14681468
}

unittests/CppInterOp/DynamicLibraryManagerTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_Sanity) {
3333
GTEST_SKIP() << "Test fails for OOP JIT builds";
3434

3535
EXPECT_TRUE(TestFixture::CreateInterpreter());
36-
EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero"));
36+
EXPECT_FALSE(Cpp::GetFunctionAddressFromMangledName("ret_zero"));
3737

3838
std::string BinaryPath = GetExecutablePath(/*Argv0=*/nullptr);
3939
llvm::StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
@@ -59,14 +59,14 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_Sanity) {
5959
Cpp::Process("");
6060
// FIXME: Conda returns false to run this code on osx.
6161
#ifndef __APPLE__
62-
EXPECT_TRUE(Cpp::GetFunctionAddress("ret_zero"));
62+
EXPECT_TRUE(Cpp::GetFunctionAddressFromMangledName("ret_zero"));
6363
#endif //__APPLE__
6464

6565
Cpp::UnloadLibrary("TestSharedLib");
6666
// We have no reliable way to check if it was unloaded because posix does not
6767
// require the library to be actually unloaded but just the handle to be
6868
// invalidated...
69-
// EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero"));
69+
// EXPECT_FALSE(Cpp::GetFunctionAddressFromMangledName("ret_zero"));
7070
}
7171

7272
TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_BasicSymbolLookup) {
@@ -81,15 +81,15 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_BasicSymbolLookup) {
8181
GTEST_SKIP() << "Test fails for OOP JIT builds";
8282

8383
ASSERT_TRUE(TestFixture::CreateInterpreter());
84-
EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero"));
84+
EXPECT_FALSE(Cpp::GetFunctionAddressFromMangledName("ret_zero"));
8585

8686
// Load the library manually. Use known preload path (MEMFS path)
8787
const char* wasmLibPath = "libTestSharedLib.so"; // Preloaded path in MEMFS
8888
EXPECT_TRUE(Cpp::LoadLibrary(wasmLibPath, false));
8989

9090
Cpp::Process("");
9191

92-
void* Addr = Cpp::GetFunctionAddress("ret_zero");
92+
void* Addr = Cpp::GetFunctionAddressFromMangledName("ret_zero");
9393
EXPECT_NE(Addr, nullptr) << "Symbol 'ret_zero' not found after dlopen.";
9494

9595
using RetZeroFn = int (*)();

0 commit comments

Comments
 (0)