From b261dd9d28c0d92eb2034af195b8453488442223 Mon Sep 17 00:00:00 2001 From: Emery Conrad Date: Tue, 3 Feb 2026 03:32:21 -0600 Subject: [PATCH] fix GetFunctionAddress resolution with explicit name change --- include/CppInterOp/CppInterOp.h | 3 ++- include/CppInterOp/Dispatch.h | 3 +-- lib/CppInterOp/CppInterOp.cpp | 4 ++-- unittests/CppInterOp/DynamicLibraryManagerTest.cpp | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/CppInterOp/CppInterOp.h b/include/CppInterOp/CppInterOp.h index b0f7466b0..90cc73355 100644 --- a/include/CppInterOp/CppInterOp.h +++ b/include/CppInterOp/CppInterOp.h @@ -560,7 +560,8 @@ CPPINTEROP_API bool IsStaticMethod(TCppConstFunction_t method); CPPINTEROP_API bool IsExplicit(TCppConstFunction_t method); ///\returns the address of the function given its potentially mangled name. -CPPINTEROP_API TCppFuncAddr_t GetFunctionAddress(const char* mangled_name); +CPPINTEROP_API TCppFuncAddr_t +GetFunctionAddressFromMangledName(const char* mangled_name); ///\returns the address of the function given its function declaration. CPPINTEROP_API TCppFuncAddr_t GetFunctionAddress(TCppFunction_t method); diff --git a/include/CppInterOp/Dispatch.h b/include/CppInterOp/Dispatch.h index d9f0e9dd2..47fa6a863 100644 --- a/include/CppInterOp/Dispatch.h +++ b/include/CppInterOp/Dispatch.h @@ -184,8 +184,7 @@ extern "C" CPPINTEROP_API CppFnPtrTy CppGetProcAddress(const char* procname); DISPATCH_API(IsExplicit, decltype(&CppImpl::IsExplicit)) \ DISPATCH_API(MakeFunctionCallable, \ CppImpl::JitCall (*)(CppImpl::TCppConstFunction_t)) \ - DISPATCH_API(GetFunctionAddress, \ - CppImpl::TCppFuncAddr_t (*)(CppImpl::TCppFunction_t)) \ + DISPATCH_API(GetFunctionAddress, decltype(&CppImpl::GetFunctionAddress)) \ /*DISPATCH_API(API_name, fnptr_ty)*/ // TODO: implement overload that takes an existing opened DL handle diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 17ef3ae9b..28b855aca 100644 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1430,7 +1430,7 @@ bool IsExplicit(TCppConstFunction_t method) { return false; } -TCppFuncAddr_t GetFunctionAddress(const char* mangled_name) { +TCppFuncAddr_t GetFunctionAddressFromMangledName(const char* mangled_name) { auto& I = getInterp(); auto FDAorErr = compat::getSymbolAddress(I, mangled_name); if (llvm::Error Err = FDAorErr.takeError()) @@ -1462,7 +1462,7 @@ static TCppFuncAddr_t GetFunctionAddress(const FunctionDecl* FD) { // Constructor and Destructors needs to be handled differently if (!llvm::isa(FD) && !llvm::isa(FD)) - return GetFunctionAddress(get_mangled_name(FD).c_str()); + return GetFunctionAddressFromMangledName(get_mangled_name(FD).c_str()); return 0; } diff --git a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp index ab3ca8125..91a6fba75 100644 --- a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp +++ b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp @@ -33,7 +33,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_Sanity) { GTEST_SKIP() << "Test fails for OOP JIT builds"; EXPECT_TRUE(TestFixture::CreateInterpreter()); - EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero")); + EXPECT_FALSE(Cpp::GetFunctionAddressFromMangledName("ret_zero")); std::string BinaryPath = GetExecutablePath(/*Argv0=*/nullptr); llvm::StringRef Dir = llvm::sys::path::parent_path(BinaryPath); @@ -59,14 +59,14 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_Sanity) { Cpp::Process(""); // FIXME: Conda returns false to run this code on osx. #ifndef __APPLE__ - EXPECT_TRUE(Cpp::GetFunctionAddress("ret_zero")); + EXPECT_TRUE(Cpp::GetFunctionAddressFromMangledName("ret_zero")); #endif //__APPLE__ Cpp::UnloadLibrary("TestSharedLib"); // We have no reliable way to check if it was unloaded because posix does not // require the library to be actually unloaded but just the handle to be // invalidated... - // EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero")); + // EXPECT_FALSE(Cpp::GetFunctionAddressFromMangledName("ret_zero")); } TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_BasicSymbolLookup) { @@ -81,7 +81,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_BasicSymbolLookup) { GTEST_SKIP() << "Test fails for OOP JIT builds"; ASSERT_TRUE(TestFixture::CreateInterpreter()); - EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero")); + EXPECT_FALSE(Cpp::GetFunctionAddressFromMangledName("ret_zero")); // Load the library manually. Use known preload path (MEMFS path) const char* wasmLibPath = "libTestSharedLib.so"; // Preloaded path in MEMFS @@ -89,7 +89,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, DynamicLibraryManager_BasicSymbolLookup) { Cpp::Process(""); - void* Addr = Cpp::GetFunctionAddress("ret_zero"); + void* Addr = Cpp::GetFunctionAddressFromMangledName("ret_zero"); EXPECT_NE(Addr, nullptr) << "Symbol 'ret_zero' not found after dlopen."; using RetZeroFn = int (*)();