From 67f4a371e5a928839f8d8cb016e69e428aeb874f Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 24 Nov 2021 19:55:09 +0000 Subject: Update legacy mangling of names 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. --- gcc/rust/backend/rust-mangle.cc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'gcc/rust/backend') 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 -- cgit v1.1