Page MenuHomeFreeBSD

WIP: lang/rust: Add riscv64gc-unknown-freebsd target
ClosedPublic

Authored by tobik on Nov 7 2021, 3:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 3, 3:56 AM
Unknown Object (File)
Mon, Dec 2, 7:31 AM
Unknown Object (File)
Sun, Dec 1, 10:44 AM
Unknown Object (File)
Sun, Dec 1, 10:44 AM
Unknown Object (File)
Sat, Nov 30, 5:38 PM
Unknown Object (File)
Sat, Nov 30, 5:38 PM
Unknown Object (File)
Fri, Nov 29, 1:11 AM
Unknown Object (File)
Wed, Nov 27, 1:34 PM

Details

Summary

Add riscv64gc-unknown-freebsd target

I have had to patch libc and libstd to target FreeBSD 13.x ABI since riscv64 GENERIC does not enable COMPAT_*.

TODO:

  • Figure out why rustc crashes with SIGBUS while compiling the parse-zoneinfo crate
  • Do a native build of lang/rust on riscv64. There is no cmake in the riscv64 package repository so I haven't tried it yet
  • Try on real hardware (do not have any)
  • Let other people look it over
  • Upstream pull request: https://github.com/rust-lang/rust/pull/91284
Test Plan
  1. Get latest ports tree
  1. Get the bootstraps

Built from lang/rust-bootstrap@riscv64 on 13.0-RELEASE amd64 and tested on 13.0-RELEASE riscv64 in a QEMU VM.

  1. Install the bootstraps:
$ for c in rust-std cargo rustc; do
	tar xf $c-1.56.0-riscv64gc-unknown-freebsd.tar.xz
	(cd $c-1.56.0-riscv64gc-unknown-freebsd; sh install.sh --prefix=~/rust)
done
  1. Try building a hello world program:
$ echo 'fn main() { println!("hello world") }' >hello.rs
$ ~/rust/bin/rustc hello.rs && ./hello
hello world

As an example I have patched sysutils/hexyl for riscv64 (see sysutils/hexyl/files/patch-riscv64). To test it:

$ make -C sysutils/hexyl CARGO_BUILDDEP=no CARGO=~/rust/bin/cargo RUSTC=~/rust/bin/rustc

Diff Detail

Repository
rP FreeBSD ports repository
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 42724
Build 39612: arc lint + arc unit

Event Timeline

tobik held this revision as a draft.
tobik published this revision for review.Nov 7 2021, 3:39 PM
tobik retitled this revision from lang/rust: Add riscv64gc-unknown-freebsd target to WIP: lang/rust: Add riscv64gc-unknown-freebsd target.

This looks incomplete, I hacked this up a while ago building from upstream sources with P522 P523 P524 P525 (doesn't include the target.rs, didn't git add that, but it's the same as yours). But this needs resolving properly upstream by having the FreeBSD version propagated properly as cfg info, not by whack-a-mole patching of places all over that RISC-V is FreeBSD 12 and everything else is 11. One place should have that RISC-V-specific knowledge, everywhere else should just be automatic based on what libc or std say.

this needs resolving properly upstream by having the FreeBSD version propagated properly as cfg info, not by whack-a-mole patching of places all over that RISC-V is FreeBSD 12 and everything else is 11

Hopefully everything will migrate to the 12 (ino64) ABI soon: https://github.com/rust-lang/rust/issues/89058

In D32881#742246, @greg_unrelenting.technology wrote:

this needs resolving properly upstream by having the FreeBSD version propagated properly as cfg info, not by whack-a-mole patching of places all over that RISC-V is FreeBSD 12 and everything else is 11

Hopefully everything will migrate to the 12 (ino64) ABI soon: https://github.com/rust-lang/rust/issues/89058

It solves this specific problem, but the underlying issue is just punted two years down the road... Now is the right time to fix it properly.

This looks incomplete, I hacked this up a while ago building from upstream sources with P522 P523 P524 P525 (doesn't include the target.rs, didn't git add that, but it's the same as yours)

Thanks. Going to add the missing pieces some time this week and rebuild the bootstrap.

But this needs resolving properly upstream by having the FreeBSD version propagated properly as cfg info, not by whack-a-mole patching of places all over that RISC-V is FreeBSD 12 and everything else is 11. One place should have that RISC-V-specific knowledge, everywhere else should just be automatic based on what libc or std say.

Are you working on it?

This looks incomplete, I hacked this up a while ago building from upstream sources with P522 P523 P524 P525 (doesn't include the target.rs, didn't git add that, but it's the same as yours)

Thanks. Going to add the missing pieces some time this week and rebuild the bootstrap.

But this needs resolving properly upstream by having the FreeBSD version propagated properly as cfg info, not by whack-a-mole patching of places all over that RISC-V is FreeBSD 12 and everything else is 11. One place should have that RISC-V-specific knowledge, everywhere else should just be automatic based on what libc or std say.

Are you working on it?

No, I don't have enough time to engage in that kind of discussion with upstream, which is why my work stalled where it did rather than upstreaming any of it.

  • Update riscv64 patches based on @jrtc27's work
  • Disable backtrace on riscv64 (bug in _Unwind_Backtrace that causes the SIGBUS?)
  • Update riscv64 bootstrap checksums
  • Build the riscv64 bootstrap with debug=true for now
  • bootstrap.py: Detect riscv64 cputype properly

A native build was successful too.

Why not just add COMPAT_FREEBSD11 to riscv64 kernel? That's what I did for powerpc64le (support added in 13.0) to have Rust working.

Why not just add COMPAT_FREEBSD11 to riscv64 kernel? That's what I did for powerpc64le (support added in 13.0) to have Rust working.

Yeah, that sounds better than special casing riscv64gc-unknown-freebsd everywhere. Any comments from riscv about that? Is it possible?

Why not just add COMPAT_FREEBSD11 to riscv64 kernel? That's what I did for powerpc64le (support added in 13.0) to have Rust working.

Yeah, that sounds better than special casing riscv64gc-unknown-freebsd everywhere. Any comments from riscv about that? Is it possible?

It's possible, but it's not a solution to the problem, and you shouldn't change the kernel because Rust wants to use syscalls that never existed for the current RISC-V ABI (11.0 had some RISC-V support, but the ISA and toolchain ABI saw breaking changes after that so it's not until 12.0 that you reach the point of compatibility).

So I object to that change on the grounds that Rust is broken and we should not carry baggage in the kernel just so it can continue to ignore syscall ABI issues.

  • Rebase after Rust 1.57.0 update
This revision was not accepted when it landed; it landed in state Needs Review.Dec 23 2021, 10:11 AM
This revision was automatically updated to reflect the committed changes.