Skip to content

Commit 6181752

Browse files
committed
Support mangling *const ptr and slices like *const [T]
The legacy mangling scheme needs to convert the canonical path containing * for pointers and the [] brackets representing slices into: * = $BP$ [ = $u5b$ ] = $u5d$ These symbols are not allowed in asm symbols. Addresses #849
1 parent 0f4f9ab commit 6181752

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

gcc/rust/backend/rust-mangle.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ static const std::string kMangledSubstBegin = "$LT$";
1111
static const std::string kMangledSubstEnd = "$GT$";
1212
static const std::string kMangledSpace = "$u20$";
1313
static const std::string kMangledRef = "$RF$";
14+
static const std::string kMangledPtr = "$BP$";
15+
static const std::string kMangledLeftSqParen = "$u5b$"; // [
16+
static const std::string kMangledRightSqParen = "$u5d$"; // ]
1417
static const std::string kQualPathBegin = "_" + kMangledSubstBegin;
1518

1619
namespace Rust {
@@ -29,8 +32,15 @@ legacy_mangle_name (const std::string &name)
2932
// <example::Bar as example::A>::fooA:
3033
// _ZN43_$LT$example..Bar$u20$as$u20$example..A$GT$4fooA17hfc615fa76c7db7a0E:
3134
//
35+
// core::ptr::const_ptr::<impl *const T>::cast:
36+
// _ZN4core3ptr9const_ptr33_$LT$impl$u20$$BP$const$u20$T$GT$4cast17hb79f4617226f1d55E:
37+
//
38+
// core::ptr::const_ptr::<impl *const [T]>::as_ptr:
39+
// _ZN4core3ptr9const_ptr43_$LT$impl$u20$$BP$const$u20$$u5b$T$u5d$$GT$6as_ptr17he16e0dcd9473b04fE:
40+
//
3241
// example::Foo<T>::new:
3342
// _ZN7example12Foo$LT$T$GT$3new17h9a2aacb7fd783515E:
43+
3444
std::string buffer;
3545
for (size_t i = 0; i < name.size (); i++)
3646
{
@@ -47,6 +57,12 @@ legacy_mangle_name (const std::string &name)
4757
m = kMangledSubstBegin;
4858
else if (c == '>')
4959
m = kMangledSubstEnd;
60+
else if (c == '*')
61+
m = kMangledPtr;
62+
else if (c == '[')
63+
m = kMangledLeftSqParen;
64+
else if (c == ']')
65+
m = kMangledRightSqParen;
5066
else if (c == ':')
5167
{
5268
rust_assert (i + 1 < name.size ());

0 commit comments

Comments
 (0)