Skip to content

Commit 16f1c4b

Browse files
authored
[Symbol Names] Add Global Prefix if set (#177)
- Prepend `_` before looking for symbols by default - Use compat::getExecutionEngine for data layout and then get Global Prefix Signed-off-by: Shreyas Atre <[email protected]>
1 parent 0023d86 commit 16f1c4b

File tree

7 files changed

+18
-47
lines changed

7 files changed

+18
-47
lines changed

Diff for: lib/Interpreter/Compatibility.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,16 @@ getSymbolAddress(clang::Interpreter& I, clang::GlobalDecl GD) {
216216
}
217217

218218
inline llvm::Expected<llvm::JITTargetAddress>
219-
getSymbolAddressFromLinkerName(const clang::Interpreter& I,
219+
getSymbolAddressFromLinkerName(clang::Interpreter& I,
220220
llvm::StringRef LinkerName) {
221221
#if CLANG_VERSION_MAJOR >= 14
222-
auto AddrOrErr = I.getSymbolAddressFromLinkerName(LinkerName);
222+
const auto& DL = getExecutionEngine(I)->getDataLayout();
223+
char GlobalPrefix = DL.getGlobalPrefix();
224+
std::string LinkerNameTmp(LinkerName);
225+
if (GlobalPrefix != '\0') {
226+
LinkerNameTmp = std::string(1, GlobalPrefix) + LinkerNameTmp;
227+
}
228+
auto AddrOrErr = I.getSymbolAddressFromLinkerName(LinkerNameTmp);
223229
if (llvm::Error Err = AddrOrErr.takeError())
224230
return std::move(Err);
225231
return AddrOrErr->getValue();

Diff for: lib/Interpreter/CppInterOp.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -2661,7 +2661,13 @@ namespace Cpp {
26612661
// Let's inject it.
26622662
SymbolMap::iterator It;
26632663
llvm::orc::SymbolMap InjectedSymbols;
2664-
auto Name = ES.intern(linker_mangled_name);
2664+
auto& DL = compat::getExecutionEngine(I)->getDataLayout();
2665+
char GlobalPrefix = DL.getGlobalPrefix();
2666+
std::string tmp(linker_mangled_name);
2667+
if (GlobalPrefix != '\0') {
2668+
tmp = std::string(1, GlobalPrefix) + tmp;
2669+
}
2670+
auto Name = ES.intern(tmp);
26652671
InjectedSymbols[Name] =
26662672
#if CLANG_VERSION_MAJOR < 17
26672673
JITEvaluatedSymbol(address,

Diff for: unittests/CppInterOp/FunctionReflectionTest.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,7 @@ TEST(FunctionReflectionTest, IsVirtualMethod) {
592592
EXPECT_FALSE(Cpp::IsVirtualMethod(Decls[0]));
593593
}
594594

595-
#ifdef __APPLE__
596-
TEST(FunctionReflectionTest, DISABLED_JitCallAdvanced) {
597-
#else
598595
TEST(FunctionReflectionTest, JitCallAdvanced) {
599-
#endif
600596
std::vector<Decl*> Decls;
601597
std::string code = R"(
602598
typedef struct _name {
@@ -617,11 +613,8 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
617613
Cpp::Destruct(object, Decls[1]);
618614
}
619615

620-
#ifdef __APPLE__
621-
TEST(FunctionReflectionTest, DISABLED_GetFunctionCallWrapper) {
622-
#else
616+
623617
TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
624-
#endif
625618
std::vector<Decl*> Decls;
626619
std::string code = R"(
627620
int f1(int i) { return i * i; }
@@ -784,11 +777,7 @@ TEST(FunctionReflectionTest, GetFunctionArgDefault) {
784777
EXPECT_EQ(Cpp::GetFunctionArgDefault(Decls[1], 2), "34126");
785778
}
786779

787-
#ifdef __APPLE__
788-
TEST(FunctionReflectionTest, DISABLED_Construct) {
789-
#else
790780
TEST(FunctionReflectionTest, Construct) {
791-
#endif
792781
Cpp::CreateInterpreter();
793782

794783
Interp->declare(R"(
@@ -822,11 +811,7 @@ TEST(FunctionReflectionTest, Construct) {
822811
EXPECT_EQ(output, "Constructor Executed");
823812
}
824813

825-
#ifdef __APPLE__
826-
TEST(FunctionReflectionTest, DISABLED_Destruct) {
827-
#else
828814
TEST(FunctionReflectionTest, Destruct) {
829-
#endif
830815
Cpp::CreateInterpreter();
831816

832817
Interp->declare(R"(

Diff for: unittests/CppInterOp/InterpreterTest.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ TEST(InterpreterTest, Evaluate) {
4949
EXPECT_FALSE(HadError) ;
5050
}
5151

52-
#ifdef __APPLE__ //Fails for Cling Tests
53-
TEST(InterpreterTest, DISABLED_Process) {
54-
#else
5552
TEST(InterpreterTest, Process) {
56-
#endif
5753
Cpp::CreateInterpreter();
5854
EXPECT_TRUE(Cpp::Process("") == 0);
5955
EXPECT_TRUE(Cpp::Process("int a = 12;") == 0);

Diff for: unittests/CppInterOp/JitTest.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ static int printf_jit(const char* format, ...) {
1111
return 0;
1212
}
1313

14-
#ifdef __APPLE__
15-
TEST(JitTest, DISABLED_InsertOrReplaceJitSymbol) {
16-
#else
1714
TEST(JitTest, InsertOrReplaceJitSymbol) {
18-
#endif
1915
std::vector<Decl*> Decls;
2016
std::string code = R"(
2117
extern "C" int printf(const char*,...);

Diff for: unittests/CppInterOp/ScopeReflectionTest.cpp

+2-16
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,8 @@ TEST(ScopeReflectionTest, SizeOf) {
9999
EXPECT_EQ(Cpp::SizeOf(Decls[7]), (size_t)16);
100100
}
101101

102-
#ifdef __APPLE__
103-
TEST(ScopeReflectionTest, DISABLED_IsBuiltin) {
104-
#else
102+
105103
TEST(ScopeReflectionTest, IsBuiltin) {
106-
#endif
107104
// static std::set<std::string> g_builtins =
108105
// {"bool", "char", "signed char", "unsigned char", "wchar_t", "short", "unsigned short",
109106
// "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long",
@@ -433,11 +430,7 @@ TEST(ScopeReflectionTest, GetScopefromCompleteName) {
433430
EXPECT_EQ(Cpp::GetQualifiedName(Cpp::GetScopeFromCompleteName("N1::N2::C::S")), "N1::N2::C::S");
434431
}
435432

436-
#ifdef __APPLE__
437-
TEST(ScopeReflectionTest, DISABLED_GetNamed) {
438-
#else
439433
TEST(ScopeReflectionTest, GetNamed) {
440-
#endif
441434
std::string code = R"(namespace N1 {
442435
namespace N2 {
443436
class C {
@@ -761,11 +754,7 @@ TEST(ScopeReflectionTest, InstantiateNNTPClassTemplate) {
761754
/*type_size*/ args1.size()));
762755
}
763756

764-
#ifdef __APPLE__
765-
TEST(ScopeReflectionTest, DISABLED_InstantiateTemplateFunctionFromString) {
766-
#else
767757
TEST(ScopeReflectionTest, InstantiateTemplateFunctionFromString) {
768-
#endif
769758
Cpp::CreateInterpreter();
770759
std::string code = R"(#include <memory>)";
771760
Interp->process(code);
@@ -905,11 +894,8 @@ TEST(ScopeReflectionTest, GetClassTemplateInstantiationArgs) {
905894
EXPECT_TRUE(instance_types.size() == 0);
906895
}
907896

908-
#ifdef __APPLE__
909-
TEST(ScopeReflectionTest, DISABLED_IncludeVector) {
910-
#else
897+
911898
TEST(ScopeReflectionTest, IncludeVector) {
912-
#endif
913899
std::string code = R"(
914900
#include <vector>
915901
#include <iostream>

Diff for: unittests/CppInterOp/TypeReflectionTest.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,7 @@ TEST(TypeReflectionTest, IsPODType) {
522522
EXPECT_FALSE(Cpp::IsPODType(0));
523523
}
524524

525-
#ifdef __APPLE__
526-
TEST(TypeReflectionTest, DISABLED_IsSmartPtrType) {
527-
#else
528525
TEST(TypeReflectionTest, IsSmartPtrType) {
529-
#endif
530526
Cpp::CreateInterpreter();
531527

532528
Interp->declare(R"(

0 commit comments

Comments
 (0)