diff options
author | liushuyu <liushuyu011@gmail.com> | 2022-04-21 17:19:27 -0600 |
---|---|---|
committer | liushuyu <liushuyu011@gmail.com> | 2022-04-22 16:16:37 -0600 |
commit | af7622f219871cdaf8ae7e124008730b411d7a06 (patch) | |
tree | c0da8f48c2cd78c60c784c52c3381be371d6237e /gcc/rust/backend | |
parent | 1286acc34e826039ebc8f09ad36dddc30f726283 (diff) | |
download | gcc-af7622f219871cdaf8ae7e124008730b411d7a06.zip gcc-af7622f219871cdaf8ae7e124008730b411d7a06.tar.gz gcc-af7622f219871cdaf8ae7e124008730b411d7a06.tar.bz2 |
backend: handle no_mangle attribute
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-base.cc | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 84afa1e..0c28728 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -30,6 +30,24 @@ namespace Rust { namespace Compile { +bool +should_mangle_item (const AST::AttrVec &attrs) +{ + for (const auto &attr : attrs) + { + if (attr.get_path ().as_string ().compare ("no_mangle") == 0) + { + if (attr.has_attr_input ()) + rust_error_at ( + attr.get_locus (), + "attribute %<no_mangle%> does not accept any arguments"); + return false; + } + } + + return true; +} + void HIRCompileBase::setup_attributes_on_fndecl ( tree fndecl, bool is_main_entry_point, HIR::Visibility &visibility, @@ -58,6 +76,7 @@ HIRCompileBase::setup_attributes_on_fndecl ( bool is_cold = attr.get_path ().as_string ().compare ("cold") == 0; bool is_link_section = attr.get_path ().as_string ().compare ("link_section") == 0; + bool no_mangle = attr.get_path ().as_string ().compare ("no_mangle") == 0; if (is_inline) { handle_inline_attribute_on_fndecl (fndecl, attr); @@ -74,6 +93,11 @@ HIRCompileBase::setup_attributes_on_fndecl ( { handle_link_section_attribute_on_fndecl (fndecl, attr); } + else if (no_mangle) + { + // we handled this in `should_mangle_item` + continue; + } } } @@ -396,7 +420,10 @@ HIRCompileBase::compile_function ( // we don't mangle the main fn since we haven't implemented the main shim bool is_main_fn = fn_name.compare ("main") == 0; std::string asm_name = fn_name; - if (!is_main_fn) + // TODO(liushuyu): we should probably move this part to + // `setup_attributes_on_fndecl` if possible + bool should_mangle = should_mangle_item (outer_attrs); + if (!is_main_fn && should_mangle) asm_name = ctx->mangle_item (fntype, *canonical_path); unsigned int flags = 0; |