diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-11-25 14:35:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 14:35:50 +0000 |
commit | bdfe6abe2b11e2ddad0b8c8a92b57297fdd73f6b (patch) | |
tree | aea425fae0eecb695216a4481d9553a59fbfd576 /gcc | |
parent | 717b6da459b26ace9a3c303cfa5e485ff8935709 (diff) | |
parent | 67f4a371e5a928839f8d8cb016e69e428aeb874f (diff) | |
download | gcc-bdfe6abe2b11e2ddad0b8c8a92b57297fdd73f6b.zip gcc-bdfe6abe2b11e2ddad0b8c8a92b57297fdd73f6b.tar.gz gcc-bdfe6abe2b11e2ddad0b8c8a92b57297fdd73f6b.tar.bz2 |
Merge #819
819: Update legacy mangling of names r=philberty a=philberty
In rust the mangling of names needs to handle cases such as qualified paths
<&mut T as Deref>::deref. Assemblers cannot handle '&' and whitespace
otherwise we will fail to assemble the functions, the legacy mangling
scheme turns all reference's '&' into 'RF' and all whitespace into '$'
this means we can mangle more complex canonical paths. Which are needed
in order to support the deref operator overloading.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-mangle.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc index 15ac3b1..d0fec0d 100644 --- a/gcc/rust/backend/rust-mangle.cc +++ b/gcc/rust/backend/rust-mangle.cc @@ -18,7 +18,26 @@ Mangler::MangleVersion Mangler::version = MangleVersion::LEGACY; static std::string legacy_mangle_name (const std::string &name) { - return std::to_string (name.size ()) + name; + // example + // <&T as core::fmt::Debug>::fmt: + // _ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h6dac924c0051eef7E + // replace all white space with $ and & with RF + + std::string buffer; + for (const auto &c : name) + { + std::string m; + if (c == ' ') + m = "$"; + else if (c == '&') + m = "RF"; + else + m.push_back (c); + + buffer += m; + } + + return std::to_string (buffer.size ()) + buffer; } static std::string |