Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Symbol Names] Workaround: Mangle names for macOS #177

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

SAtacker
Copy link
Contributor

@SAtacker SAtacker commented Jan 4, 2024

  • Prepend _ before looking for symbols
  • Currently the interface is not unified and solutions like a global prefix would work better.

Copy link

codecov bot commented Jan 4, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (d294b07) 77.55% compared to head (bed72f4) 77.56%.
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #177   +/-   ##
=======================================
  Coverage   77.55%   77.56%           
=======================================
  Files           8        8           
  Lines        2887     2897   +10     
=======================================
+ Hits         2239     2247    +8     
- Misses        648      650    +2     
Files Coverage Δ
lib/Interpreter/Compatibility.h 90.90% <85.71%> (-0.76%) ⬇️
lib/Interpreter/CppInterOp.cpp 85.42% <83.33%> (-0.02%) ⬇️
Files Coverage Δ
lib/Interpreter/Compatibility.h 90.90% <85.71%> (-0.76%) ⬇️
lib/Interpreter/CppInterOp.cpp 85.42% <83.33%> (-0.02%) ⬇️

Copy link
Contributor

github-actions bot commented Jan 4, 2024

clang-tidy review says "All clean, LGTM! 👍"

@SAtacker
Copy link
Contributor Author

SAtacker commented Jan 6, 2024

@vgvassilev would this work?

@@ -211,15 +211,24 @@ getSymbolAddress(clang::Interpreter& I, llvm::StringRef IRName) {
inline llvm::Expected<llvm::JITTargetAddress>
getSymbolAddress(clang::Interpreter& I, clang::GlobalDecl GD) {
std::string MangledName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't rely on __APPLE__ here since we might be running on OSX but using remote execution and the underlying platform to be different.

How about something like:

auto &DL = getExecutionEngine()->getDataLayout();
char GlobalPrefix = DL.getGlobalPrefix();
bool HasGlobalPrefix = (GlobalPrefix != '\0');
if (HasGlobalPrefix && (*Name).front() != GlobalPrefix)
  // Complain?
std::string Tmp((*MangledName).data() + HasGlobalPrefix,
                    (*MangledName).size() - HasGlobalPrefix);
getSymbolAddress(Tmp);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MangledName should be behavior agnostic, if it has the prefix then we cannot guess if it's actually the name of the symbol or if it was intended for prefix i.e. it creates ambiguity. Which is why I propose that we handle the prefix on API's end. Would that be okay?

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

#if CLANG_VERSION_MAJOR >= 14
auto& DL = getExecutionEngine(I)->getDataLayout();
char GlobalPrefix = DL.getGlobalPrefix();
std::string LinkerName = std::string(1, GlobalPrefix) + LinkerName_.str();
auto AddrOrErr = I.getSymbolAddressFromLinkerName(LinkerName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we sink this code in getSymbolAddressFromLinkerName?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have it there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete the new code then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete the new code then?

We need to have it in the upstream version or the above location. Otherwise it fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused then. Why this code cannot go in getSymbolAddressFromLinkerName?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSymbolAddressFromLinkerName

Because it goes to clang-repl's API llvm::Expected<llvm::orc::ExecutorAddr> Interpreter::getSymbolAddressFromLinkerName(llvm::StringRef Name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LibInterOp has compat function inline llvm::Expected<llvm::JITTargetAddress> getSymbolAddressFromLinkerName(clang::Interpreter& I, llvm::StringRef LinkerName)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, you are saying it needs to go in llvm upstream if we want it close to the API... Ok, understood.

@mcbarton
Copy link
Collaborator

Just thought I'd add a comment that I tested this PR on an osx arm machine with Clang-REPL on, with a patched clang 16, and it passes all the tests for CppInterOp.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! This feature is covering OSX and codecoverage cannot detect it being tested but that's ok. Could you squash the commits into one?

- Prepend `_` before looking for symbols by default
- Use compat::getExecutionEngine for data layout and then get Global Prefix

Signed-off-by: Shreyas Atre <shreyasatre16@gmail.com>
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@vgvassilev vgvassilev merged commit 16f1c4b into compiler-research:main Jan 11, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants