From 5a9ceba8fd21973118f1866686aca5622cc60ba2 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Sun, 10 Jan 2021 16:14:26 +0000 Subject: Mark DECL_PUBLIC for main fn or functions with visibility. This change will need more thought later when it comes to traits and generics etc. Fixes #136 --- gcc/rust/backend/rust-compile-item.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index e042ccb..c5fe9a2 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -138,10 +138,24 @@ public: // convert to the actual function type auto compiled_fn_type = TyTyCompile::compile (ctx->get_backend (), fnType); + unsigned int flags = 0; + bool is_main_fn = function.function_name.compare ("main") == 0; + + // if its the main fn or pub visibility mark its as DECL_PUBLIC + // please see https://github.com/Rust-GCC/gccrs/pull/137 + if (is_main_fn || function.has_visibility ()) + flags |= Backend::function_is_visible; + + std::string asm_name = function.function_name; + if (!is_main_fn) + { + // FIXME need name mangling + asm_name = "__" + function.function_name; + } + Bfunction *fndecl = ctx->get_backend ()->function (compiled_fn_type, function.function_name, - "" /* asm_name */, 0 /* flags */, - function.get_locus ()); + asm_name, flags, function.get_locus ()); ctx->insert_function_decl (function.get_mappings ().get_hirid (), fndecl); // setup the params -- cgit v1.1