Skip to content

validate #[link_name = "..."] & #[link(name = "...")] parameters#155817

Open
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:link-name-null-empty
Open

validate #[link_name = "..."] & #[link(name = "...")] parameters#155817
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:link-name-null-empty

Conversation

@folkertdev
Copy link
Copy Markdown
Contributor

fixes #155776
fixes #155484

specifically, do not allow NULL bytes and the empty string in #[link_name = "..."] and #[link(name = "...")].

Like some of the others I think this formally needs to be looked at by T-lang because these errors would not show up if not linking.

The LLVM erorr on #[linke_name = "\0"] is emitted here, it is not e.g. target-specific.

https://github.com/llvm/llvm-project/blob/d593279c0b2891f0b0c8af3f70a1a0383b4ad1b5/llvm/lib/IR/Value.cpp#L336-L342

On #[link(name = "")] we already error today. A NULL byte in #[link(name = "\0")] is caught by the linker (https://godbolt.org/z/vnz9sYbPs), using #[link_name = ""] makes LLVM generate a name (https://godbolt.org/z/1hWEo4cxf) which is not useful and likely to cause linker errors.

r? jdonszelmann

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 26, 2026
@folkertdev folkertdev changed the title validate #[link_name = "..."] parameter validate #[link_name = "..."] & #[link(name = "...")] parameters Apr 26, 2026
Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

r? me

r=me on the implementation, pending lang approval

View changes since this review

Comment thread compiler/rustc_attr_parsing/src/attributes/link_attrs.rs Outdated
@rustbot rustbot assigned mejrs and unassigned jdonszelmann Apr 26, 2026
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev added I-lang-nominated Nominated for discussion during a lang team meeting. S-waiting-on-t-lang Status: Awaiting decision from T-lang labels Apr 26, 2026
@folkertdev folkertdev force-pushed the link-name-null-empty branch from b94ed3f to 2ffa233 Compare April 26, 2026 11:45
Comment on lines 12 to 13
#[link_name = "@GLIBC_2.2.5"]
pub safe fn exit_1(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib`
Copy link
Copy Markdown
Contributor Author

@folkertdev folkertdev Apr 26, 2026

Choose a reason for hiding this comment

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

I think we should move these errors to rustc_attr_parsing too, for consistency and so that the ranges can actually point to the attribute instead of the item.

That's not something T-lang needs to worry about though, so probably best done separately.

cc @usamoi (this test was added by #144221)

View changes since the review

@folkertdev folkertdev force-pushed the link-name-null-empty branch from 2ffa233 to 4338dfc Compare April 26, 2026 17:17
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the link-name-null-empty branch from 4338dfc to 5a5ae4c Compare April 26, 2026 17:26
@rust-log-analyzer

This comment has been minimized.

specifically, do not allow NULL bytes and the empty string
@folkertdev folkertdev force-pushed the link-name-null-empty branch from 5a5ae4c to c08b9ab Compare April 26, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) I-lang-nominated Nominated for discussion during a lang team meeting. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-t-lang Status: Awaiting decision from T-lang T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

special link_name confuses LLVM [ICE]: Result::unwrap() on an Err value: NulError(0, [0])

5 participants