Skip to content

llvm error: export_name #155495

Closed
Closed

Description

@matthiaskrgr

I tried this code:

#[unsafe(export_name = "\
")]
pub fn main() {}

This can cause a segfault within LLVM.

Meta

rustc --version --verbose:

rustc 1.97.0-nightly (e9e32aca5 2026-04-17)
binary: rustc
commit-hash: e9e32aca5a4ffd08cbc29547b039d64b92a2c03b
commit-date: 2026-04-17
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

with debug assertions:

rust -Cprofile-generate=. a.rs

rustc: /checkout/src/llvm-project/llvm/include/llvm/ADT/StringRef.h:236: char llvm::StringRef::operator[](size_t) const: Assertion `Index < size() && "Invalid index!"' failed.

rustc -Cinstrument-coverage

rustc: /checkout/src/llvm-project/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From *) [To = llvm::ConstantDataArray, From = llvm::Constant]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

Activity

  1. added
    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    C-bugCategory: This is a bug.
    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)
    A-PGOArea: Profile-guided optimizations (PGO)
    on Apr 18, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 18, 2026
  3. folkertdev commented on Apr 19, 2026

    @folkertdev
    Contributor

    The issue reproduces just with #[unsafe(export_name = "")], no need for the newline.

    An empty argument to export_name has some interesting behavior: it circumvents rust name mangling and instead has LLVM make up a symbol:

    https://godbolt.org/z/555eKdjWe

    I wonder if that has any practical uses, or whether we should just disallow the empty string as an argument.

  4. bjorn3 commented on Apr 19, 2026

    @bjorn3
    Member

    We should disallow that. If the item is defined in a different crate than it is used, LLVM would make up entirely different symbols and you did get a linker error. Even within a crate there is no guarantee that the definition and the user end up in the same codegen unit. Basically the use case I can think of where it would not be UB is a #[used] static that is not referenced anywhere.

  5. folkertdev commented on Apr 19, 2026

    @folkertdev
    Contributor

    Basically the use case I can think of where it would not be UB is a #[used] static that is not referenced anywhere.

    But even in this case, is there an advantage to LLVM generating that name? You could just use #[used] without export_name or no_mangle for the same effect right?

  6. bjorn3 commented on Apr 19, 2026

    @bjorn3
    Member

    I don't think there is an advantage to having LLVM generate the name. It is just the only case I can think of where it would not be UB.

  7. self-assigned this
    on Apr 19, 2026
  8. added a commit that references this issue on May 9, 2026
  9. added 2 commits that reference this issue on May 9, 2026
  10. added a commit that references this issue on May 10, 2026
  11. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-PGOArea: Profile-guided optimizations (PGO)A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions