public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] External Items with Rust ABI need to mangle the full path
@ 2022-07-15 11:37 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-07-15 11:37 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6bf6241f29e73678b8c7d3508cdb39b55ae9d1ab

commit 6bf6241f29e73678b8c7d3508cdb39b55ae9d1ab
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Fri Jul 8 15:13:57 2022 +0100

    External Items with Rust ABI need to mangle the full path
    
    When compiling external rust abi item requires the fully qualified
    canonical path to be mangled in order to link correctly.

Diff:
---
 gcc/rust/backend/rust-compile-extern.h    | 11 +++++++++++
 gcc/rust/resolve/rust-ast-resolve-item.cc |  6 ++++++
 2 files changed, 17 insertions(+)

diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h
index c24437deb2f..ddad350eaa9 100644
--- a/gcc/rust/backend/rust-compile-extern.h
+++ b/gcc/rust/backend/rust-compile-extern.h
@@ -130,6 +130,17 @@ public:
     tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
     std::string ir_symbol_name = function.get_item_name ();
     std::string asm_name = function.get_item_name ();
+    if (fntype->get_abi () == ABI::RUST)
+      {
+	// then we need to get the canonical path of it and mangle it
+	const Resolver::CanonicalPath *canonical_path = nullptr;
+	bool ok = ctx->get_mappings ()->lookup_canonical_path (
+	  function.get_mappings ().get_nodeid (), &canonical_path);
+	rust_assert (ok);
+
+	ir_symbol_name = canonical_path->get () + fntype->subst_as_string ();
+	asm_name = ctx->mangle_item (fntype, *canonical_path);
+      }
 
     const unsigned int flags = Backend::function_is_declaration;
     tree fndecl
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 244bf64d148..75bd2e10b1c 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -1027,6 +1027,12 @@ void
 ResolveExternItem::visit (AST::ExternalFunctionItem &function)
 {
   NodeId scope_node_id = function.get_node_id ();
+  auto decl = CanonicalPath::new_seg (function.get_node_id (),
+				      function.get_identifier ());
+  auto path = prefix.append (decl);
+  auto cpath = canonical_prefix.append (decl);
+
+  mappings->insert_canonical_path (function.get_node_id (), cpath);
 
   resolve_visibility (function.get_visibility ());


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-15 11:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 11:37 [gcc/devel/rust/master] External Items with Rust ABI need to mangle the full path Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).