Repository: rust
Issue: Errors compiling `libc` using rust 1.73.0 on `riscv64/ubuntu:focal` docker image - works with 1.72.1
Labels: A-linkage,P-high,T-compiler,regression-from-stable-to-stable,C-bug,O-riscv,regression-untriaged

h/w device: Starfive VisionFive2 SoC board
docker image : `riscv64/ubuntu:focal` - (LTS Ubuntu 20)
Docker version 20.10.21

The issue also appears using QEMU.
The issue also appears using `rust 1.75.0-nightly`
The issue also appears compiling `libc 0.2.148`

Note - the issue **DOES NOT** appear
- using image `riscv64/ubuntu:jammy` - (LTS Ubuntu 22)
- using `rust 1.72.1`

Target = `stable-riscv64gc-unknown-linux-gnu` 

empty project with `libc` dependency:

```
[package]
name = "test_crate"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "0.2.149"
```

```
root@000f3594006f:/ws# cargo clean && cargo build --verbose --verbose
   Compiling libc v0.2.149
     Running `CARGO=/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.149 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_README=README.md CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.2.149 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=149 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/ws/target/debug/deps:/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib:/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib' /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/rustc --crate-name build_script_build /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.149/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=204 --crate-type bin --emit=dep-info,link -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=96e5e627a3abf8c8 -C extra-filename=-96e5e627a3abf8c8 --out-dir /ws/target/debug/build/libc-96e5e627a3abf8c8 -L dependency=/ws/target/debug/deps --cap-lints warn`
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "cc" "/tmp/rustcCVctF1/symbols.o" "/ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.build_script_build.78bae1900acaa159-cgu.0.rcgu.o" "/ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.build_script_build.78bae1900acaa159-cgu.1.rcgu.o" "/ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.build_script_build.78bae1900acaa159-cgu.2.rcgu.o" "/ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.build_script_build.78bae1900acaa159-cgu.3.rcgu.o" "/ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.2gwogyquwaava3wi.rcgu.o" "-Wl,--as-needed" "-L" "/ws/target/debug/deps" "-L" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libstd-7c20a79be40626d5.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libpanic_unwind-0828025c99efa306.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libobject-cad77585ea5b2597.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libmemchr-819221be8f9a39ca.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libaddr2line-27305f678c78b7e8.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libgimli-d6dc5edd95c10e8b.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/librustc_demangle-0d40f94f5bf49047.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libstd_detect-400d9ad6f69566ef.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libhashbrown-efe127239291790f.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/librustc_std_workspace_alloc-b2b1393aaa45cbdc.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libminiz_oxide-3f8d7ae12780bb8a.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libadler-9fd99aca5a91830a.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libunwind-130742698a3dada1.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcfg_if-61c4490aa3cd5617.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/liblibc-11b24d104e4a6819.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/liballoc-edf623dacc1b8376.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/librustc_std_workspace_core-f7351a9898cc3f1f.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcore-8c347cbe3d348ef5.rlib" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcompiler_builtins-83534430d5ebaab4.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib" "-o" "/ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.build_script_build.78bae1900acaa159-cgu.1.rcgu.o
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.build_script_build.78bae1900acaa159-cgu.2.rcgu.o
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.build_script_build.78bae1900acaa159-cgu.3.rcgu.o
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /ws/target/debug/build/libc-96e5e627a3abf8c8/build_script_build-96e5e627a3abf8c8.2gwogyquwaava3wi.rcgu.o
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libstd-7c20a79be40626d5.rlib(std-7c20a79be40626d5.std.bf3dc212422480e-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libpanic_unwind-0828025c99efa306.rlib(panic_unwind-0828025c99efa306.panic_unwind.7653168454a35d11-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libobject-cad77585ea5b2597.rlib(object-cad77585ea5b2597.object.df09169ba80752fc-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libmemchr-819221be8f9a39ca.rlib(memchr-819221be8f9a39ca.memchr.9319e8ba93f7c543-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libaddr2line-27305f678c78b7e8.rlib(addr2line-27305f678c78b7e8.addr2line.1dbb935f6e696ff5-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libgimli-d6dc5edd95c10e8b.rlib(gimli-d6dc5edd95c10e8b.gimli.c09175a2afb04107-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/librustc_demangle-0d40f94f5bf49047.rlib(rustc_demangle-0d40f94f5bf49047.rustc_demangle.63400a85a5bf63f4-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libminiz_oxide-3f8d7ae12780bb8a.rlib(miniz_oxide-3f8d7ae12780bb8a.miniz_oxide.9d43bb9f04dbfc00-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libadler-9fd99aca5a91830a.rlib(adler-9fd99aca5a91830a.adler.84d4be1594b06e2c-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/liblibc-11b24d104e4a6819.rlib(libc-11b24d104e4a6819.libc.3c82556467890d0-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/liballoc-edf623dacc1b8376.rlib(alloc-edf623dacc1b8376.alloc.d475226557833bf6-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcore-8c347cbe3d348ef5.rlib(core-8c347cbe3d348ef5.core.2983b1ded1f05c41-cgu.0.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcompiler_builtins-83534430d5ebaab4.rlib(compiler_builtins-83534430d5ebaab4.compiler_builtins.d269826ba1c73e2b-cgu.044.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcompiler_builtins-83534430d5ebaab4.rlib(compiler_builtins-83534430d5ebaab4.compiler_builtins.d269826ba1c73e2b-cgu.090.rcgu.o)
          /usr/bin/ld: -march=rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0: unsupported ISA subset `z'
          /usr/bin/ld: failed to merge target specific data of file /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcompiler_builtins-83534430d5ebaab4.rlib(compiler_builtins-83534430d5ebaab4.compiler_builtins.d269826ba1c73e2b-cgu.006.rcgu.o)
          collect2: error: ld returned 1 exit status
          

error: could not compile `libc` (build script) due to previous error

Caused by:
  process didn't exit successfully: `CARGO=/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.149 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
  ' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_README=README.md CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.2.149 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=149 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/ws/target/debug/deps:/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib:/root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/lib' /root/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/rustc --crate-name build_script_build /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.149/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=204 --crate-type bin --emit=dep-info,link -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=96e5e627a3abf8c8 -C extra-filename=-96e5e627a3abf8c8 --out-dir /ws/target/debug/build/libc-96e5e627a3abf8c8 -L dependency=/ws/target/debug/deps --cap-lints warn` (exit status: 1)
```