Skip to content

Commit

Permalink
[Symbol Names] Use compat::getExecutionEngine for data layout and the…
Browse files Browse the repository at this point in the history
…n Global Prefix

- Use global prefix by default to retrieve symbols

Signed-off-by: Shreyas Atre <[email protected]>
  • Loading branch information
SAtacker committed Jan 10, 2024
1 parent cfafa48 commit 1e68a2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
23 changes: 11 additions & 12 deletions lib/Interpreter/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,25 +210,24 @@ getSymbolAddress(clang::Interpreter& I, llvm::StringRef IRName) {

inline llvm::Expected<llvm::JITTargetAddress>
getSymbolAddress(clang::Interpreter& I, clang::GlobalDecl GD) {
std::string MangledName;
#if __APPLE__
return getSymbolAddress(I, llvm::StringRef("_" + MangledName));
#else
auto& DL = getExecutionEngine(I)->getDataLayout();
char GlobalPrefix = DL.getGlobalPrefix();
std::string MangledName = std::string(1, GlobalPrefix);
compat::maybeMangleDeclName(GD, MangledName);
return getSymbolAddress(I, llvm::StringRef(MangledName));
#endif
}

inline llvm::Expected<llvm::JITTargetAddress>
getSymbolAddressFromLinkerName(const clang::Interpreter& I,
llvm::StringRef LinkerName) {
getSymbolAddressFromLinkerName(clang::Interpreter& I,
llvm::StringRef LinkerName_) {
#if CLANG_VERSION_MAJOR >= 14
#if __APPLE__
/// https://github.com/llvm/llvm-project/blob/0f8615f4dc568f4d7cbf73580eef3e78f64f3bd0/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp#L252-L259
auto AddrOrErr = I.getSymbolAddressFromLinkerName(("_" + LinkerName).str());
#else
auto& DL = getExecutionEngine(I)->getDataLayout();
char GlobalPrefix = DL.getGlobalPrefix();
std::string LinkerName(LinkerName_);
if (GlobalPrefix != '\0') {
LinkerName = std::string(1, GlobalPrefix) + LinkerName;

Check warning on line 228 in lib/Interpreter/Compatibility.h

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/Compatibility.h#L228

Added line #L228 was not covered by tests
}
auto AddrOrErr = I.getSymbolAddressFromLinkerName(LinkerName);
#endif
if (llvm::Error Err = AddrOrErr.takeError())
return std::move(Err);
return AddrOrErr->getValue();
Expand Down
12 changes: 7 additions & 5 deletions lib/Interpreter/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2661,11 +2661,13 @@ namespace Cpp {
// Let's inject it.
SymbolMap::iterator It;
llvm::orc::SymbolMap InjectedSymbols;
#if __APPLE__
auto Name = ES.intern("_" + std::string(linker_mangled_name));
#else
auto Name = ES.intern(linker_mangled_name);
#endif
auto& DL = compat::getExecutionEngine(I)->getDataLayout();
char GlobalPrefix = DL.getGlobalPrefix();
std::string tmp(linker_mangled_name);
if (GlobalPrefix != '\0') {
tmp = std::string(1, GlobalPrefix) + tmp;

Check warning on line 2668 in lib/Interpreter/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CppInterOp.cpp#L2668

Added line #L2668 was not covered by tests
}
auto Name = ES.intern(tmp);
InjectedSymbols[Name] =
#if CLANG_VERSION_MAJOR < 17
JITEvaluatedSymbol(address,
Expand Down

0 comments on commit 1e68a2a

Please sign in to comment.