aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-base.cc31
-rw-r--r--gcc/rust/backend/rust-compile-base.h4
-rw-r--r--gcc/rust/util/rust-attributes.cc1
-rw-r--r--gcc/testsuite/rust/debug/custom_link_section.rs13
4 files changed, 49 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index f138cb1..84afa1e 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -56,6 +56,8 @@ HIRCompileBase::setup_attributes_on_fndecl (
bool is_must_use
= attr.get_path ().as_string ().compare ("must_use") == 0;
bool is_cold = attr.get_path ().as_string ().compare ("cold") == 0;
+ bool is_link_section
+ = attr.get_path ().as_string ().compare ("link_section") == 0;
if (is_inline)
{
handle_inline_attribute_on_fndecl (fndecl, attr);
@@ -68,6 +70,10 @@ HIRCompileBase::setup_attributes_on_fndecl (
{
handle_cold_attribute_on_fndecl (fndecl, attr);
}
+ else if (is_link_section)
+ {
+ handle_link_section_attribute_on_fndecl (fndecl, attr);
+ }
}
}
@@ -90,6 +96,31 @@ HIRCompileBase::handle_cold_attribute_on_fndecl (tree fndecl,
}
void
+HIRCompileBase::handle_link_section_attribute_on_fndecl (
+ tree fndecl, const AST::Attribute &attr)
+{
+ if (!attr.has_attr_input ())
+ {
+ rust_error_at (attr.get_locus (),
+ "%<link_section%> expects exactly one argment");
+ return;
+ }
+
+ rust_assert (attr.get_attr_input ().get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL);
+
+ auto &literal = static_cast<AST::AttrInputLiteral &> (attr.get_attr_input ());
+ const auto &msg_str = literal.get_literal ().as_string ();
+
+ if (decl_section_name (fndecl))
+ {
+ rust_warning_at (attr.get_locus (), 0, "section name redefined");
+ }
+
+ set_decl_section_name (fndecl, msg_str.c_str ());
+}
+
+void
HIRCompileBase::handle_inline_attribute_on_fndecl (tree fndecl,
const AST::Attribute &attr)
{
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 68a3994..70506c2 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -88,6 +88,10 @@ protected:
static void handle_must_use_attribute_on_fndecl (tree fndecl,
const AST::Attribute &attr);
+ static void
+ handle_link_section_attribute_on_fndecl (tree fndecl,
+ const AST::Attribute &attr);
+
static void setup_abi_options (tree fndecl, ABI abi);
static tree address_expression (tree, Location);
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 106500d..c9112eb 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -31,6 +31,7 @@ static const BuiltinAttrDefinition __definitions[] = {
{"doc", HIR_LOWERING},
{"must_use", STATIC_ANALYSIS},
{"lang", HIR_LOWERING},
+ {"link_section", CODE_GENERATION},
};
BuiltinAttributeMappings *
diff --git a/gcc/testsuite/rust/debug/custom_link_section.rs b/gcc/testsuite/rust/debug/custom_link_section.rs
new file mode 100644
index 0000000..142f351
--- /dev/null
+++ b/gcc/testsuite/rust/debug/custom_link_section.rs
@@ -0,0 +1,13 @@
+#[link_section = ".universe"]
+fn not_in_text() -> i32 {
+ 42
+}
+
+fn main() -> i32 {
+// { dg-do compile }
+// { dg-options "-gdwarf-5 -dA -w" }
+ not_in_text();
+// { dg-final { scan-assembler ".universe" } } */
+
+ 0
+}