Repository: rust
Issue: Fails to link verbatim libary in 1.82 on macOS
Labels: A-linkage,O-macos,T-compiler,C-bug,regression-untriaged

<!--
Thank you for filing a regression report! 🐛 A regression is something that changed between versions of Rust but was not supposed to.

Please provide a short summary of the regression, along with any information you feel is relevant to replicate it.
-->

### Code

Full project to reproduce this bug is at https://github.com/anatawa12/rust-1.82-linker-regression

I tried to link .a file at `$OUT_DIR/testlib.a` with the following `build.rs` code.

```rust

fn main() {
    let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
    std::fs::create_dir_all(&out_dir).unwrap();
    let object = out_dir.join("testlib.o");
    let archive = out_dir.join("testlib.a");

    // buiid code here

    println!(
        "cargo:rustc-link-search=native={path}",
        path = out_dir.display()
    );
    println!("cargo:rustc-link-lib=static:+verbatim=testlib.a");
}
```

I ran `cargo +stable test`, linker reported `ld: library 'testlib.a' not found`, but with rust 1.81.0 (`cargo +1.81.0 test`) no linker error was reported.

Rust 1.82.0 on linux works well AFAIK (not tested with this code above, but works with real-world case I found this regression)

<details>
<summary>full build log with verbose</summary>

```
$ cargo +stable test --verbose
   Compiling rust-1-82-linker-regression v0.1.0 (/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression)
     Running `/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name build_script_build --edition=2021 build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=192 --crate-type bin --emit=dep-info,link -C embed-bitcode=no --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=d7bb1aa767972a7a -C extra-filename=-d7bb1aa767972a7a --out-dir /Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/build/rust-1-82-linker-regression-d7bb1aa767972a7a -C incremental=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/incremental -L dependency=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps`
     Running `/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/build/rust-1-82-linker-regression-d7bb1aa767972a7a/build-script-build`
     Running `/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name rust_1_82_linker_regression --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=192 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=add4a5facfd2f7ab -C extra-filename=-add4a5facfd2f7ab --out-dir /Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps -C incremental=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/incremental -L dependency=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps -L native=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/build/rust-1-82-linker-regression-a47462767d058db3/out -l 'static:+verbatim=testlib.a'`
     Running `/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name rust_1_82_linker_regression --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=192 --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --test --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=963aac10ba26161b -C extra-filename=-963aac10ba26161b --out-dir /Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps -C incremental=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/incremental -L dependency=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps -L native=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/build/rust-1-82-linker-regression-a47462767d058db3/out -l 'static:+verbatim=testlib.a'`
error: linking with `cc` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/anatawa12/.cargo/bin:/Users/anatawa12/.opam/default/bin:/opt/homebrew/opt/coreutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/Users/anatawa12/.pyenv/shims:/Users/anatawa12/.rbenv/bin:/Users/anatawa12/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/anatawa12/.cargo/bin:/opt/n/bin:/Users/anatawa12/bin:/Users/anatawa12/.dotnet/tools:/Users/anatawa12/go/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/kw/yhxddc7x2_b9f__07m789msm0000gn/T/rustcxMuggb/symbols.o" "/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps/rust_1_82_linker_regression-963aac10ba26161b.230w3ltx1tyin48jyz9gg62ve.rcgu.o" "/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps/rust_1_82_linker_regression-963aac10ba26161b.2kpsu0kkm1iu0u33iw506w5qe.rcgu.o" "/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps/rust_1_82_linker_regression-963aac10ba26161b.2rra8qibc8xluhhphpeac63l6.rcgu.o" "/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps/rust_1_82_linker_regression-963aac10ba26161b.63fa677y8o4kupyjrhw2e06nv.rcgu.o" "/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps/rust_1_82_linker_regression-963aac10ba26161b.dozsgtx5r5kuvil9ikjcppamh.rcgu.o" "/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps/rust_1_82_linker_regression-963aac10ba26161b.4mrr65f7zswfitye8l3bs5h4p.rcgu.o" "-ltestlib.a" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libtest-85a9da6da381f636.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgetopts-78018899fd21502d.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunicode_width-869d479eca56b68b.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_std-4410c8ee795fd46e.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-0b4a354a5d882f18.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-00e89274fccf37d9.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-16cb3fa9562569e5.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-726032628236814d.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-3a2050392888e443.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-22481e5f0a7ce87c.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-99efda3e7d60c7d0.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-97279fd1ed4043e6.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-14aec4517faeb95b.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-ce8f05ca22908841.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-45050aa8ac83ac5c.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-3a0b6babb2efec9c.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-41b79f23e35577db.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-7831295d10c91204.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-f86e480d5dcc309d.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-a7504b44dda8a2a3.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-589a9d977c5a484f.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-a17e2a568e77fc15.rlib" "/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-791901bf82ad4f12.rlib" "-lSystem" "-lc" "-lm" "-L" "/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/build/rust-1-82-linker-regression-a47462767d058db3/out" "-o" "/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps/rust_1_82_linker_regression-963aac10ba26161b" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: library 'testlib.a' not found
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `rust-1-82-linker-regression` (lib test) due to 1 previous error

Caused by:
  process didn't exit successfully: `/Users/anatawa12/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name rust_1_82_linker_regression --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=192 --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --test --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=963aac10ba26161b -C extra-filename=-963aac10ba26161b --out-dir /Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps -C incremental=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/incremental -L dependency=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/deps -L native=/Users/anatawa12/RustroverProjects/rust-1-82-linker-regression/target/debug/build/rust-1-82-linker-regression-a47462767d058db3/out -l 'static:+verbatim=testlib.a'` (exit status: 1)
```

</details>

### Version it worked on

<!--
Provide the most recent version this worked on, for example:

It most recently worked on: Rust 1.47
-->

It most recently worked on: Rust 1.80 or 1.81 beta, and 1.81 stable on github actions<!-- version -->

### Version with regression

<!--
Provide the version you are using that has the regression.
-->

`rustc --version --verbose`:
```
rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: aarch64-apple-darwin
release: 1.82.0
LLVM version: 19.1.1
```

<!--
Did the compiler crash? If so, please provide a backtrace.
-->

### Backtrace

No Compiler Crashes

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
<backtrace>
```

</p>
</details>

<!--
If you know when this regression occurred, please add a line like below, replacing `{channel}` with one of stable, beta, or nightly.

@rustbot modify labels: +regression-from-stable-to-{channel} -regression-untriaged
-->