Repository: rust
Issue: Linking with `rust-lld` causes SIGSEGV in FFI code
Labels: A-linkage,I-crash,T-compiler,A-proc-macros,C-external-bug

 I just hit the following ICE on nightly-2024-07-21:

```
2024-07-27T18:47:51.0486374Z error: rustc interrupted by SIGSEGV, printing backtrace
2024-07-27T18:47:51.0486993Z 
2024-07-27T18:47:51.0490075Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x34567d3)[0x7f6d158567d3]
2024-07-27T18:47:51.0491772Z /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f6d12042520]
2024-07-27T18:47:51.0492829Z /lib/x86_64-linux-gnu/libc.so.6(pthread_mutex_lock+0x4)[0x7f6d12097ef4]
2024-07-27T18:47:51.0495708Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xe8d19c)[0x7f6cfce8d19c]
2024-07-27T18:47:51.0497646Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xc9a5e9)[0x7f6cfcc9a5e9]
2024-07-27T18:47:51.0499530Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xc8a98e)[0x7f6cfcc8a98e]
2024-07-27T18:47:51.0501447Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xb735d8)[0x7f6cfcb735d8]
2024-07-27T18:47:51.0503367Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xa83cc5)[0x7f6cfca83cc5]
2024-07-27T18:47:51.0505238Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xa81caa)[0x7f6cfca81caa]
2024-07-27T18:47:51.0507168Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xa7d8bc)[0x7f6cfca7d8bc]
2024-07-27T18:47:51.0509002Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xaf5d96)[0x7f6cfcaf5d96]
2024-07-27T18:47:51.0511037Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xa76266)[0x7f6cfca76266]
2024-07-27T18:47:51.0513133Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xacc6ac)[0x7f6cfcacc6ac]
2024-07-27T18:47:51.0515169Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xaa99cb)[0x7f6cfcaa99cb]
2024-07-27T18:47:51.0517088Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xaa97a9)[0x7f6cfcaa97a9]
2024-07-27T18:47:51.0519085Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xb774f9)[0x7f6cfcb774f9]
2024-07-27T18:47:51.0521107Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xb7b768)[0x7f6cfcb7b768]
2024-07-27T18:47:51.0523111Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xbc373e)[0x7f6cfcbc373e]
2024-07-27T18:47:51.0525433Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xc3ebee)[0x7f6cfcc3ebee]
2024-07-27T18:47:51.0527860Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xc3eaa6)[0x7f6cfcc3eaa6]
2024-07-27T18:47:51.0530004Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xa899c6)[0x7f6cfca899c6]
2024-07-27T18:47:51.0532386Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xc3e4d1)[0x7f6cfcc3e4d1]
2024-07-27T18:47:51.0534648Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xa762b0)[0x7f6cfca762b0]
2024-07-27T18:47:51.0537232Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xacc4fc)[0x7f6cfcacc4fc]
2024-07-27T18:47:51.0539355Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xc3ed4b)[0x7f6cfcc3ed4b]
2024-07-27T18:47:51.0541438Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xc3cad3)[0x7f6cfcc3cad3]
2024-07-27T18:47:51.0543516Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xc3eb5e)[0x7f6cfcc3eb5e]
2024-07-27T18:47:51.0545634Z /home/runner/work/rust-cuda/rust-cuda/target/debug/deps/librust_cuda_kernel-f8e68a2959435f1e.so(+0xa7b282)[0x7f6cfca7b282]
2024-07-27T18:47:51.0547948Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x53c5645)[0x7f6d177c5645]
2024-07-27T18:47:51.0550481Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x53c537f)[0x7f6d177c537f]
2024-07-27T18:47:51.0554034Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(_RNvXs_NtCs5bDVmVmSdCw_12rustc_expand10proc_macroNtB4_13BangProcMacroNtNtB6_4base13BangProcMacro6expand+0x89)[0x7f6d1802b4c9]
2024-07-27T18:47:51.0557909Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(_RNvMs1_NtCs5bDVmVmSdCw_12rustc_expand6expandNtB5_13MacroExpander21fully_expand_fragment+0x31b37)[0x7f6d1348dfd7]
2024-07-27T18:47:51.0561615Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(_RNvMs1_NtCs5bDVmVmSdCw_12rustc_expand6expandNtB5_13MacroExpander12expand_crate+0x298)[0x7f6d17c7b0d8]
2024-07-27T18:47:51.0565145Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(_RNvNtCshR7PlEWAGD5_15rustc_interface6passes25resolver_for_lowering_raw+0xa33)[0x7f6d171fe333]
2024-07-27T18:47:51.0568106Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x4dfd8eb)[0x7f6d171fd8eb]
2024-07-27T18:47:51.0570558Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x4dfd8d9)[0x7f6d171fd8d9]
2024-07-27T18:47:51.0572964Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x5b81a40)[0x7f6d17f81a40]
2024-07-27T18:47:51.0576204Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x5b814ca)[0x7f6d17f814ca]
2024-07-27T18:47:51.0579062Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x582aa63)[0x7f6d17c2aa63]
2024-07-27T18:47:51.0581710Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x57cc689)[0x7f6d17bcc689]
2024-07-27T18:47:51.0585015Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/librustc_driver-9194d071d74e8e5f.so(+0x57cc43a)[0x7f6d17bcc43a]
2024-07-27T18:47:51.0588209Z /home/runner/.rustup/toolchains/nightly-2024-07-21-x86_64-unknown-linux-gnu/lib/libstd-c6c045f3358c0b22.so(rust_metadata_std_6ba14169a40c6134+0xc75bb)[0x7f6d123995bb]
2024-07-27T18:47:51.0589958Z /lib/x86_64-linux-gnu/libc.so.6(+0x94ac3)[0x7f6d12094ac3]
2024-07-27T18:47:51.0590814Z /lib/x86_64-linux-gnu/libc.so.6(+0x126850)[0x7f6d12126850]
```

The full log is from a CI run (https://github.com/juntyr/rust-cuda/actions/runs/10125660318/job/28001392785) of this repo (https://github.com/juntyr/rust-cuda/tree/670bee6f2d4550c1c6b721bf2f4d6e1863791886)

_Originally posted by @juntyr in https://github.com/rust-lang/rust/issues/127330#issuecomment-2254227215_