Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riscv32gc-* targets produce a synthetic object file (symbols.o) with a mismatching floating-point ABI #104284

Closed
yvt opened this issue Nov 11, 2022 · 6 comments · Fixed by #106797
Assignees
Labels
A-abi Area: Concerning the application binary interface (ABI). A-floating-point Area: Floating point numbers and arithmetic A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-riscv Target: RISC-V architecture

Comments

@yvt
Copy link
Contributor

yvt commented Nov 11, 2022

I tried this code:

cargo new --lib hoge
cd hoge

cat >> Cargo.toml <<EOF
[lib]
crate-type = ["cdylib"]
EOF

cat > src/lib.rs <<EOF
#![no_std]
#[no_mangle]
pub extern "C" fn add(left: usize, right: usize) -> usize {
    left + right
}

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    loop {}
}
EOF

env RUSTFLAGS='-Cpanic=abort -Clinker=rust-lld' cargo build --target riscv32gc-unknown-linux-gnu -Zbuild-std

I expected to see this happen: Successful compilation (because this would succeed for the target riscv64gc-unknown-linux-gnu)

Instead, this happened:

error: linking with `rust-lld` failed: exit status: 1
  |
  = note: "rust-lld" "-flavor" "gnu" "--version-script=/tmp/rustcDiidlE/list" "/tmp/rustcDiidlE/symbols.o" "/tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/hoge.92rzut19pk7sei6.rcgu.o" "--as-needed" "-L" "/tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps" "-L" "/tmp/hoge/target/debug/deps" "-L" "/home/USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/riscv32gc-unknown-linux-gnu/lib" "-Bstatic" "/tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/librustc_std_workspace_core-4ec574d8efc1d5b8.rlib" "/tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib" "/tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcompiler_builtins-c685b409872aa5db.rlib" "-Bdynamic" "--eh-frame-hdr" "-znoexecstack" "-L" "/home/USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/riscv32gc-unknown-linux-gnu/lib" "-o" "/tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libhoge.so" "--gc-sections" "-shared" "-zrelro" "-znow"
  = note: rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/hoge.92rzut19pk7sei6.rcgu.o: cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.3.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.10.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.0.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.2.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.15.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.13.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.11.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.14.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.1.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.12.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.4.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.5.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.6.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.7.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcore-572ea5c6b4d30279.rlib(core-572ea5c6b4d30279.core.efcbc3e8-cgu.9.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcompiler_builtins-c685b409872aa5db.rlib(compiler_builtins-c685b409872aa5db.compiler_builtins.53485fab-cgu.11.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcompiler_builtins-c685b409872aa5db.rlib(compiler_builtins-c685b409872aa5db.compiler_builtins.53485fab-cgu.0.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcompiler_builtins-c685b409872aa5db.rlib(compiler_builtins-c685b409872aa5db.compiler_builtins.53485fab-cgu.12.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/libcompiler_builtins-c685b409872aa5db.rlib(compiler_builtins-c685b409872aa5db.compiler_builtins.53485fab-cgu.15.rcgu.o): cannot link object files with different floating-point ABI
          rust-lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
$ file /tmp/rustcVXpC3S/symbols.o
/tmp/rustcVXpC3S/symbols.o: ELF 32-bit LSB relocatable, UCB RISC-V, soft-float ABI, version 1 (SYSV), not stripped

$ file /tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/hoge.92rzut19pk7sei6.rcgu.o
/tmp/hoge/target/riscv32gc-unknown-linux-gnu/debug/deps/hoge.92rzut19pk7sei6.rcgu.o: ELF 32-bit LSB relocatable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), with debug_info, not stripped

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (a6b7274a4 2022-10-10)
binary: rustc
commit-hash: a6b7274a462829f8ef08a1ddcdcec7ac80dbf3e1
commit-date: 2022-10-10
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
@yvt yvt added the C-bug Category: This is a bug. label Nov 11, 2022
@yvt yvt changed the title riscv32gc-*targets produce a synthetic object file (symbols.o) with a mismatching floating-point ABI riscv32gc-* targets produce a synthetic object file (symbols.o) with a mismatching floating-point ABI Nov 11, 2022
@bjorn3 bjorn3 added A-linkage Area: linking into static, shared libraries and binaries O-riscv Target: RISC-V architecture A-abi Area: Concerning the application binary interface (ABI). A-floating-point Area: Floating point numbers and arithmetic labels Nov 11, 2022
@bjorn3
Copy link
Member

bjorn3 commented Nov 11, 2022

The relevant code is

Architecture::Riscv64 if sess.target.options.features.contains("+d") => {
// copied from `riscv64-linux-gnu-gcc foo.c -c`, note though
// that the `+d` target feature represents whether the double
// float abi is enabled.
let e_flags = elf::EF_RISCV_RVC | elf::EF_RISCV_FLOAT_ABI_DOUBLE;
e_flags
}
It should probably be applied to riscv32 too

@FawazTirmizi
Copy link
Contributor

Doesn't seem like anyone else has picked this up yet, if it's as simple a fix as it seems I would be happy to make the PR.

@FawazTirmizi
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 13, 2023
…bjorn3

riscv: Fix ELF header flags

The previous version added both `EF_RISCV_FLOAT_ABI_DOUBLE` and `EF_RISCV_RVC` if the "D" extension was enabled on riscv64 targets. riscv32 targets were not accounted for. This patch changes this so that:

- Only add `EF_RISCV_RVC` if the "C" extension is enabled
- Add `EF_RISCV_FLOAT_ABI_SINGLE` if the "F" extension is enabled and the "D" extension is not
- Add these ELF flags for riscv32 as well

Fixes rust-lang#104284

r? rust-lang/risc-v
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 13, 2023
…bjorn3

riscv: Fix ELF header flags

The previous version added both `EF_RISCV_FLOAT_ABI_DOUBLE` and `EF_RISCV_RVC` if the "D" extension was enabled on riscv64 targets. riscv32 targets were not accounted for. This patch changes this so that:

- Only add `EF_RISCV_RVC` if the "C" extension is enabled
- Add `EF_RISCV_FLOAT_ABI_SINGLE` if the "F" extension is enabled and the "D" extension is not
- Add these ELF flags for riscv32 as well

Fixes rust-lang#104284

r? rust-lang/risc-v
@bors bors closed this as completed in 278e02a Jan 14, 2023
@yvt
Copy link
Contributor Author

yvt commented Jan 15, 2023

The mismatch still occurs if extra features are specified by -C (e.g., -C target-feature=+f,+d).

@FawazTirmizi
Copy link
Contributor

Sorry about the delayed response. I just tested it, but I'm not seeing the error. Could you test again as well? I was running the following command:
env RUSTFLAGS='-Cpanic=abort -Clinker=rust-lld -C target-feature=+f,+d' cargo build --target riscv32gc-unknown-linux-gnu -Zbuild-std

Here is the version I'm on:

rustc 1.69.0-nightly (f77bfb733 2023-03-01)
binary: rustc
commit-hash: f77bfb7336f21bfe6a5fb5f7358d4406e2597289
commit-date: 2023-03-01
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

@yvt
Copy link
Contributor Author

yvt commented Mar 8, 2023

Hm, I actually encountered the issue in a more complicated setup (CI run) with bare-metal targets and assumed from the symptom that it was caused by a similar underlying problem. I'll look into it again and open a separate issue after getting a better idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-abi Area: Concerning the application binary interface (ABI). A-floating-point Area: Floating point numbers and arithmetic A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-riscv Target: RISC-V architecture
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants