backend: handle link_section attribute
This commit is contained in:
parent
d541ded485
commit
f6194707a6
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +95,31 @@ HIRCompileBase::handle_cold_attribute_on_fndecl (tree fndecl,
|
|||
"attribute %<cold%> does not accept any arguments");
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -31,6 +31,7 @@ static const BuiltinAttrDefinition __definitions[] = {
|
|||
{"doc", HIR_LOWERING},
|
||||
{"must_use", STATIC_ANALYSIS},
|
||||
{"lang", HIR_LOWERING},
|
||||
{"link_section", CODE_GENERATION},
|
||||
};
|
||||
|
||||
BuiltinAttributeMappings *
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue