-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Support 'raw mangles' via leading "\1" in pragma(mangle) strings #3854
Conversation
This is a prerequisite for #3850 and enables getting hold of section start/end addresses on Mac (at least with their pragma(mangle, "\1section$start$__DATA$.minfo")
immutable ModuleInfo* __start___minfo;
pragma(mangle, "\1section$end$__DATA$.minfo")
immutable ModuleInfo* __stop___minfo; |
6b4fbc6
to
4fba4a8
Compare
What prevents this from being upstream ? |
A DMD backend/glue layer implementation and an agreed prefix/notion, as the "\1" is AFAIK just an LLVM convention. |
gen/mangling.cpp
Outdated
@@ -125,11 +125,15 @@ std::string getIRMangledName(VarDeclaration *vd) { | |||
} | |||
|
|||
std::string getIRMangledFuncName(std::string baseMangle, LINK link) { | |||
return gABI->mangleFunctionForLLVM(std::move(baseMangle), link); | |||
return baseMangle[0] == '\1' | |||
? baseMangle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that be a std::move
? I only use C++ for LDC development at the moment, some rust creeping in… ;)
Such mangled names aren't affected by a target-specific default (C) prefix, such as `_` on Mac.
@@ -125,11 +125,15 @@ std::string getIRMangledName(VarDeclaration *vd) { | |||
} | |||
|
|||
std::string getIRMangledFuncName(std::string baseMangle, LINK link) { | |||
return gABI->mangleFunctionForLLVM(std::move(baseMangle), link); | |||
return baseMangle[0] == '\1' | |||
? std::move(baseMangle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::move is not needed here (you are returning a func param), but (I think) are needed when passing to mangleFunctionForLLVM
. Yes the c++ rules are tough and I had to look it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was worried about the ternary expression. Seems like std::move
is indeed needed to avoid a full copy: https://cpp.godbolt.org/z/1e6cPzqzW
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah interesting, good thinking.
tests/codegen/mangling_raw.d
Outdated
// RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll | ||
|
||
// CHECK: @"\01myGlobal" = global i32 | ||
pragma(mangle, "\1myGlobal") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: make the variable name different from the mangle (less chance for it to be accidentally correct)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, good point, haven't thought about that possibility.
Such mangled names aren't affected by a target-specific default (C) prefix, such as
_
on Mac.