Skip to content

Handle link_name attribute #4031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

powerboat9
Copy link
Collaborator

Unless I'm mistaken, we don't need to put no_mangle in DECL_ATTRIBUTES (fndecl), right? Since we do all of the mangling, and gcc doesn't seem to have a no_mangle attribute?

This also makes some tweaks to how we handle the no_mangle attribute.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc: Include "rust-gcc.h".
	(should_mangle_item): Remove function.
	(get_unmangled_item): Add function.
	(HIRCompileBase::setup_fndecl): Remove handling of no_mangle.
	(HIRCompileBase::handle_no_mangle_attribute_on_fndecl): Remove
	function definition.
	(HIRCompileBase::compile_function): Use get_unmangled_name
	instead of should_mangle_name.
	* backend/rust-compile-base.h
	(HIRCompileBase::handle_no_mangle_attribute_on_fndecl): Remove
	function declaration.
	* util/rust-attribute-values.h (Attributes::LINK_NAME): New
	constexpr member variable.
	* util/rust-attributes.cc (__definitions): Add LINK_NAME.

Signed-off-by: Owen Avery <[email protected]>
@powerboat9
Copy link
Collaborator Author

Fixes #3867

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is partly there but there is special handling for the function declarations in: ust-compile-extern.h: void visit (HIR::ExternalFunctionItem &function) override

@philberty
Copy link
Member

Also you should put the Fixes into the commit message too since this is almost it finished


if (input->get_attr_input_type ()
!= AST::AttrInput::AttrInputType::LITERAL)
goto err_link_name;
Copy link
Member

@P-E-P P-E-P Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of this goto. You could have split the code in multiple functions and I don't want newcomers to grep the codebase, find this goto and sprinkle some everywhere nor be confused about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch yeah avoid goto's please

@powerboat9
Copy link
Collaborator Author

Now depends on #4044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants