Skip to content

Add allocator attrs#4556

Open
nsvke wants to merge 2 commits into
Rust-GCC:masterfrom
nsvke:add-allocator-attrs
Open

Add allocator attrs#4556
nsvke wants to merge 2 commits into
Rust-GCC:masterfrom
nsvke:add-allocator-attrs

Conversation

@nsvke
Copy link
Copy Markdown
Contributor

@nsvke nsvke commented May 25, 2026

This PR introduces three new compiler attributes required for alloc crate integration and memory allocation support.

rustc_std_internal_symbol: Prevents name mangling for internal runtime symbols.

rustc_allocator and rustc_allocator_nounwind: Instruct the GCC backend to apply malloc and nothrow.

@nsvke nsvke force-pushed the add-allocator-attrs branch from 19ef3a5 to 4db115d Compare May 25, 2026 16:43
@dkm
Copy link
Copy Markdown
Member

dkm commented May 27, 2026

You could have (_definitions) for the attribute cc file.

* util/rust-attributes.cc (__definitions): Register rustc_std_internal_symbol in
	the BuiltinAttributes list.

@nsvke nsvke force-pushed the add-allocator-attrs branch from 4db115d to b27c318 Compare May 27, 2026 09:54
This patch introduces the `rustc_std_internal_symbol` attribute.
This attribute is required by the Rust standard library to prevent
name mangling for internal runtime symbols.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (should_mangle_item): Bypass
	mangling for rustc_std_internal_symbol.
	(HIRCompileBase::setup_fndecl): Dispatch the new attribute.
	(HIRCompileBase::handle_rustc_std_internal_symbol_attribute_on_fndecl):
	New function.
	* backend/rust-compile-base.h:
	(handle_rustc_std_internal_symbol_attribute_on_fndecl): New declaration.
	* util/rust-attribute-values.h (Attributes): Add
	RUSTC_STD_INTERNAL_SYMBOL constexpr.
	* util/rust-attributes.cc (__definitions): Register
	rustc_std_internal_symbol in the BuiltinAttributes list.
	* checks/errors/rust-builtin-attribute-checker.cc (rustc_std_internal_symbol):
	New function.
	(attribute_checking_handlers): Add rustc_std_internal_symbol function.

gcc/testsuite/ChangeLog:

	* rust/compile/rustc_std_internal_symbol1.rs: New test.
	* rust/compile/rustc_std_internal_symbol2.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
@nsvke nsvke force-pushed the add-allocator-attrs branch from b27c318 to d205919 Compare May 28, 2026 10:44
This patch introduces the `rustc_allocator` and `rustc_allocator_nounwind`
attributes.
These attributes instruct the GCC backend to apply `malloc` and `nothrow`.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl): Dispatch the new
	attributes.
	(HIRCompileBase::handle_rustc_allocator_on_fndecl): New function.
	(HIRCompileBase::handle_rustc_allocator_nounwind_on_fndecl): New function.
	* backend/rust-compile-base.h (handle_rustc_allocator_on_fndecl): New declaration.
	(handle_rustc_allocator_nounwind_on_fndecl): Likewise.
	* util/rust-attribute-values.h (Attributes): Add RUSTC_ALLOCATOR and
	RUSTC_ALLOCATOR_NOUNWIND constexprs.
	* util/rust-attributes.cc (__definitions): Register rustc_allocator and
	rustc_allocator_nounwind in the BuiltinAttributes list.
	* checks/errors/rust-builtin-attribute-checker.cc (rustc_allocator): New function.
	(rustc_allocator_nounwind): New function.
	(attribute_checking_handlers): Add rustc_allocator and rustc_allocator_nounwind
	functions.

gcc/testsuite/ChangeLog:

	* rust/compile/attr-allocator1.rs: New test.
	* rust/compile/attr-allocator2.rs: New test.
	* rust/compile/attr-allocator3.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
@nsvke nsvke force-pushed the add-allocator-attrs branch from d205919 to fc8cddc Compare May 28, 2026 11:55
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.

2 participants