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

riscv64gc-unknown-none-elf target generates soft-float ABI #60012

Closed
laanwj opened this issue Apr 16, 2019 · 4 comments
Closed

riscv64gc-unknown-none-elf target generates soft-float ABI #60012

laanwj opened this issue Apr 16, 2019 · 4 comments
Labels
O-riscv Target: RISC-V architecture T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@laanwj
Copy link

laanwj commented Apr 16, 2019

tl;dr: confusion about float ABI in rust-generated RV64 object files

To do a little testing with Rust on Kendryte K210 (RV64GC) without having to write a full BSP, I'm trying to link the output of rust into an existing bare-metal project,

With the following source:

#![no_std]

use core::panic::PanicInfo;

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

#[allow(non_camel_case_types)]
type size_t = usize;

extern {
    fn callback_to_c(input: *const u8, input_length: size_t, val: f32);
}

#[no_mangle]
pub extern fn rust_main() {
    let x: f32 = 3.0;
    let test = "string";
    unsafe {
        callback_to_c(test.as_ptr(), test.len(), x);
    }
}

However, it looks like the output (see flags is marked as soft-float ABI):

$ rustc +nightly --version
rustc 1.35.0-nightly (2975a3c4b 2019-04-15)
$ rustc +nightly --target riscv64gc-unknown-none-elf --crate-type staticlib --release src/lib.rs
$ readelf -a liblib.a |head -n 20

File: liblib.a(lib.lib.3a1fbbbh-cgu.0.rcgu.o)
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           RISC-V
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          296 (bytes into file)
--->  Flags:                             0x1, RVC, soft-float ABI  <----
  Size of this header:               64 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           64 (bytes)

This causes the following error during link:

/opt/kendryte-toolchain/lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: /home/user/maixgo/rust-test/target/riscv64gc-unknown-none-elf/release/librust_test.a(rust_test-235c1d6ff76f1afc.rust_test.412mpu3z-cgu.0.rcgu.o):
can't link hard-float modules with soft-float modules

The expected value for flags would be, in this specific case:

   Flags:                             0x3, RVC, single-float ABI

To be honest I don't know if this is expected or not! For gcc it seems to have to do with the -mabi flag—I'm not sure what ABI we'd be expecting Rust to generate here:

$ riscv64-unknown-elf-gcc -mabi=lp64d -march=rv64gc test.c -c -o test.o && readelf -h test.o|grep Flags
  Flags:                             0x5, RVC, double-float ABI
$ riscv64-unknown-elf-gcc -mabi=lp64f -march=rv64gc test.c -c -o test.o && readelf -h test.o|grep Flags
  Flags:                             0x3, RVC, single-float ABI
$ riscv64-unknown-elf-gcc -mabi=lp64 -march=rv64gc test.c -c -o test.o && readelf -h test.o|grep Flags
  Flags:                             0x1, RVC, soft-float ABI
@jonas-schievink jonas-schievink added O-riscv Target: RISC-V architecture T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 16, 2019
@mati865
Copy link
Contributor

mati865 commented Apr 17, 2019

I think LLVM doesn't support hard-float for RISC-V yet.

@hanna-kruppe
Copy link
Contributor

LLVM supports it since https://llvm.org/D59357, though I think our LLVM version needs bumping to bring that in. Clang support is still under review (https://reviews.llvm.org/D60456) but we couldn't use/cherry-pick that code anyway. It may still be prudent to wait for the Clang patch being polished and committed, to unearth any issues with the ABI spec, but in principle someone could implement the same logic in rustc today.

@laanwj
Copy link
Author

laanwj commented Apr 17, 2019

Good to know, thanks!

@laanwj
Copy link
Author

laanwj commented May 11, 2019

Closing, this specific issue is no longer relevant to me, sufficiently has now been implemented in rust to no longer need this unholy linkage with the Kendryte SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-riscv Target: RISC-V architecture T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants