Skip to content

Commit 1c72678

Browse files
committed
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
1 parent 9a3ad29 commit 1c72678

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

gcc/rust/backend/rust-compile-item.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,24 @@ class CompileItem : public HIRCompileBase
138138
// convert to the actual function type
139139
auto compiled_fn_type = TyTyCompile::compile (ctx->get_backend (), fnType);
140140

141+
unsigned int flags = 0;
142+
bool is_main_fn = function.function_name.compare ("main") == 0;
143+
144+
// if its the main fn or pub visibility mark its as DECL_PUBLIC
145+
// please see https://github.com/Rust-GCC/gccrs/pull/137
146+
if (is_main_fn || function.has_visibility ())
147+
flags |= Backend::function_is_visible;
148+
149+
std::string asm_name = function.function_name;
150+
if (!is_main_fn)
151+
{
152+
// FIXME need name mangling
153+
asm_name = "__" + function.function_name;
154+
}
155+
141156
Bfunction *fndecl
142157
= ctx->get_backend ()->function (compiled_fn_type, function.function_name,
143-
"" /* asm_name */, 0 /* flags */,
144-
function.get_locus ());
158+
asm_name, flags, function.get_locus ());
145159
ctx->insert_function_decl (function.get_mappings ().get_hirid (), fndecl);
146160

147161
// setup the params

0 commit comments

Comments
 (0)