Skip to content

error on empty export_name#155515

Open
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:export-name-not-empty
Open

error on empty export_name#155515
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:export-name-not-empty

Conversation

@folkertdev
Copy link
Copy Markdown
Contributor

fixes #155495

Using an empty string as the name makes LLVM make up a name. However this name can be inconsistent between compilation units, which is UB and can cause linking errors, and some parts of LLVM just crash on the empty name (see the linked issue).

As far as we know there is only one valid pattern that could use this, a #[used] static that is not referenced by the program at all. That is not UB, but the export_name is not required for that to work, just normal rust name mangling would do fine.

Technically this is a breaking change, but it seems unlikely that this actually breaks code in the wild that wasn't already broken. I'll leave it up to T-lang to determine what is required here (crater run, FCW, ...), but my gut feeling is that we could just merge this and nobody would notice.

@folkertdev folkertdev added the I-lang-nominated Nominated for discussion during a lang team meeting. label Apr 19, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 19, 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 19, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 19, 2026

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 72 candidates
  • Random selection from 17 candidates

@Urgau
Copy link
Copy Markdown
Member

Urgau commented Apr 19, 2026

Should we consider a symbol name with only white spaces as empty?

@folkertdev
Copy link
Copy Markdown
Contributor Author

Hmm, I don't know that it's useful at all but it apparently does work https://godbolt.org/z/dMqhK6hbx

" ":
.Lfunc_begin0:
        .cfi_startproc
        .file   1 "/app" "example.rs"
        .loc    1 2 16 prologue_end

//~^ ERROR `export_name` may not contain null characters
fn null_terminated() {}

#[export_name = "\0"]
Copy link
Copy Markdown
Contributor

@jdonszelmann jdonszelmann Apr 20, 2026

Choose a reason for hiding this comment

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

did we not already have a test for these? thanks for making one in that case

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We did test that the error code is emitted in tests/ui/error-codes/E0648.rs, but now that this condition is checked in the parser a parser test seemed appropriate, plus this tests some extra inputs.

@jdonszelmann
Copy link
Copy Markdown
Contributor

r=me on implementation after lang approves this one, technically a breaking change

@jdonszelmann jdonszelmann added S-waiting-on-t-lang Status: Awaiting decision from T-lang and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 20, 2026
@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang T-lang Relevant to the language team labels Apr 22, 2026
@traviscross
Copy link
Copy Markdown
Contributor

Makes sense to me. Thanks @folkertdev.

@rfcbot fcp merge lang

@jdonszelmann
Copy link
Copy Markdown
Contributor

@folkertdev r=me in 10 days when the fcp runs out :)

@folkertdev
Copy link
Copy Markdown
Contributor Author

folkertdev commented Apr 23, 2026

Yeah, the bot seems kind of stuck though. @traviscross maybe just try again?

edit: it's being looked into #t-infra > rfcbot unresponsive

@traviscross
Copy link
Copy Markdown
Contributor

(The bot has been fixed.)

@rfcbot fcp merge lang

@rust-rfcbot
Copy link
Copy Markdown
Collaborator

rust-rfcbot commented Apr 24, 2026

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 24, 2026
@scottmcm
Copy link
Copy Markdown
Member

Usual analysis: this is the kind of place where I wonder about making it a lint or a hard error, but here I think hard error is the right choice since

  • It's a simple check that's easy to describe, rather than something nuanced that would plausibly need to change more later
  • Defining the current behaviour of "generate something random" sounds terrible and isn't explained by other things that we need to document anyway, so it would be more work in the spec if it was a lint

@rfcbot reviewed

@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Apr 29, 2026
@rust-rfcbot
Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@traviscross traviscross removed the I-lang-nominated Nominated for discussion during a lang team meeting. label May 6, 2026
@traviscross traviscross removed the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. 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. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

llvm error: export_name

7 participants