Files
Matthias Krüger 99abbd6a01 Rollup merge of #155817 - folkertdev:link-name-null-empty, r=mejrs
validate `#[link_name = "..."]` & `#[link(name = "...")]` parameters

fixes https://github.com/rust-lang/rust/issues/155776
fixes https://github.com/rust-lang/rust/issues/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
2026-05-10 03:17:02 +02:00
..
2025-07-13 15:01:48 -07:00
2024-01-13 12:46:58 -05:00