-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[RISCV] Use lld as the default linker; Enable C extension; Add riscv32imc-unknown-none-elf target #53822
Conversation
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
r? @japaric |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm these IMC targets do not even support atomic loads and stores? Or do they support atomic loads and stores but not CAS operations?
target_env: String::new(), | ||
target_vendor: "unknown".to_string(), | ||
arch: "riscv32".to_string(), | ||
linker_flavor: LinkerFlavor::Ld, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be LinkerFlavor::Lld(LldFlavor::Ld)
?
panic_strategy: PanicStrategy::Abort, | ||
relocation_model: "static".to_string(), | ||
emit_debug_gdb_scripts: false, | ||
abi_blacklist: vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is the same list as the one used in the IMAC target could you refactor it into a function? See arm_base::abi_blacklist
.
@@ -25,11 +25,11 @@ pub fn target() -> TargetResult { | |||
linker_flavor: LinkerFlavor::Ld, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be LinkerFlavor::Lld(LldFlavor::Ld)
?
cpu: "generic-rv32".to_string(), | ||
max_atomic_width: Some(32), | ||
atomic_cas: false, // incomplete +a extension | ||
features: "+m,+a".to_string(), // disable +c extension | ||
features: "+m,+a,+c".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
@@ -25,11 +25,11 @@ pub fn target() -> TargetResult { | |||
linker_flavor: LinkerFlavor::Ld, | |||
|
|||
options: TargetOptions { | |||
linker: Some("riscv32-unknown-elf-ld".to_string()), | |||
linker: Some("rust-lld".to_string()), | |||
cpu: "generic-rv32".to_string(), | |||
max_atomic_width: Some(32), | |||
atomic_cas: false, // incomplete +a extension |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking: this hasn't been fixed yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, a few commits have happened but nothing that "interesting".
Ah yes, loads and stores up to pointer width should be atomic. |
LLVM says otherwise: #![no_std]
use core::sync::atomic::{Ordering, AtomicUsize};
#[no_mangle]
pub fn foo(x: &AtomicUsize) -> usize {
x.load(Ordering::SeqCst)
} IMAC $ $(rustc +nightly --print sysroot)/bin/llvm-objdump -d target/riscv32imac-unknown-none-elf/release/libfoo.rlib
target/riscv32imac-unknown-none-elf/release/libfoo.rlib(foo-5c3d4a3cd43899d6.foo.axz7xdhy-cgu.0.rcgu.o): file format ELF32-riscv
Disassembly of section .text.foo:
foo:
0: 0f 00 30 03 fence rw, rw
4: 08 41 lw a0, 0(a0)
6: 0f 00 30 02 fence r, rw
a: 82 80 ret
$ $(rustc +nightly --print sysroot)/bin/llvm-nm target/riscv32imac-unknown-none-elf/release/libfoo.rlib
foo-5c3d4a3cd43899d6.foo.axz7xdhy-cgu.0.rcgu.o:
00000000 T foo IMC $ $(rustc +nightly --print sysroot)/bin/llvm-objdump -d target/riscv32imc-unknown-none-elf/release/libfoo.rlib
target/riscv32imc-unknown-none-elf/release/libfoo.rlib(foo-5c3d4a3cd43899d6.foo.axz7xdhy-cgu.0.rcgu.o): file format ELF32-riscv
Disassembly of section .text.foo:
foo:
0: 41 11 addi sp, sp, -16
2: 06 c6 sw ra, 12(sp)
4: 95 45 addi a1, zero, 5
6: 97 00 00 00 auipc ra, 0
a: e7 80 00 00 jalr ra
e: b2 40 lw ra, 12(sp)
10: 41 01 addi sp, sp, 16
12: 82 80 ret
$(rustc +nightly --print sysroot)/bin/llvm-nm target/riscv32imc-unknown-none-elf/release/libfoo.rlib
foo-5c3d4a3cd43899d6.foo.axz7xdhy-cgu.0.rcgu.o:
U __atomic_load_4
00000000 T foo So the IMC target should have P.S. Could you push new commits rather than rewriting the existing ones? New commits are easier to review. |
Mmh fence is part of the base ISA so I don't know why the above code wouldn't work on imc in this particular case. |
AFAIK only |
@rkruppe It's in the user spec 2.2 section 2.7 memory model as part of the base ISA. |
It is my non-expert opinion that llvm is wrong in this case, so we should leave it as is. Since this target is intended for running on fpga's, they are usually single core anyway... |
Oh, right, this is due to the problem described in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86005 -- tl;dr can't emit fence-based inline sequences for some operations and libcalls for other operations on the same memory location because those two might not synchronize correctly with each other. |
@dvc94ch could you file a bug report in LLVM's bugzilla? Rust targets must not produce binaries with undefined references (i.e. that fail to link) so the IMC target must have |
If depending on |
Then what is the purpose of 173c679#diff-b74c18bf827643ac908307f62d9c1d60R32? |
📌 Commit 173c679 has been approved by |
Oh, good to know! However, as mentioned above there are very good reasons for LLVM to expand atomic loads and stores to libcalls without the A extension, so I don't expect the bug y'all want to file to be resolved easily if at all. |
[RISCV] Use lld as the default linker; Enable C extension; Add riscv32imc-unknown-none-elf target The riscv32imc-unknown-none-elf target is intended for soft cores. The riscv32imc target is supported by the following popular soft cores: picorv32: https://github.com/cliffordwolf/picorv32 vexriscv: https://github.com/SpinalHDL/VexRiscv pulp riscy: https://github.com/pulp-platform/riscv pulp zero-riscy: https://github.com/pulp-platform/zero-riscy
☀️ Test successful - status-appveyor, status-travis |
The riscv32imc-unknown-none-elf target is intended for soft cores.
The riscv32imc target is supported by the following popular soft cores:
picorv32: https://github.com/cliffordwolf/picorv32
vexriscv: https://github.com/SpinalHDL/VexRiscv
pulp riscy: https://github.com/pulp-platform/riscv
pulp zero-riscy: https://github.com/pulp-platform/zero-riscy