Empty distributed slices causes LLD error on Windows
- Dominant language
- Rust
- Stars
- 890
- Forks
- 46
- PR merge metrics
- No merged PRs in 30d
Description
Creating a lib crate with an empty distributed slice:
```rust
#[linkme::distributed_slice]
pub static SYSTEMS_SLICE: [fn()];
```
...and linking to that crate from a bin crate without adding any entries to the distributed slice causes lld-link (LLD 18.1.3) to exit with code `0xC0000005`:
```
= note: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.␍
Stack dump:␍
0. Program arguments: rust-lld -flavor link @C:\\Users\\lucien\\AppData\\Local\\Temp\\rustcPGJUjr\\linker-arguments␍
Exception Code: 0xC0000005␍
#0 0x00007ff7ea401646 (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0x501646)␍
#1 0x00007ff7ea0821f7 (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0x1821f7)␍
#2 0x00007ff7ea075521 (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0x175521)␍
#3 0x00007ff7e9fb6ba2 (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0xb6ba2)␍
#4 0x00007ff7e9fabd7c (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0xabd7c)␍
#5 0x00007ff7e9fab30e (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0xab30e)␍
#6 0x00007ff7e9f9e589 (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0x9e589)␍
#7 0x00007ff7e9f9eb57 (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0x9eb57)␍
#8 0x00007ff7ec1e3458 (C:\Users\lucien\.rustup\toolchains\1.88-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\bin\rust-lld.exe+0x22e3458)␍
#9 0x00007ffb18d2e8d7 (C:\WINDOWS\System32\KERNEL32.DLL+0x2e8d7)␍
#10 0x00007ffb18f3c34c (C:\WINDOWS\SYSTEM32\ntdll.dll+0x3c34c)␍
```
Adding a dummy entry to the slice within the crate defining the slice stops the error from happening:
```rust
#[linkme::distributed_slice(SYSTEMS_SLICE)]
static DUMMY_SYSTEM: fn() = || {};
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the minimal lib-and-bin setup on Windows with rust-lld: define an empty linkme distributed slice, link the binary without entries, then compare it with the dummy-entry case. Investigate the linker interaction reported with LLD 18.1.3; done when the empty slice links without rust-lld crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100