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

can't compile std for riscv64gc-unknown-linux-musl #93975

Closed
blackdragon2447 opened this issue Feb 13, 2022 · 7 comments
Closed

can't compile std for riscv64gc-unknown-linux-musl #93975

blackdragon2447 opened this issue Feb 13, 2022 · 7 comments
Labels
C-bug Category: This is a bug.

Comments

@blackdragon2447
Copy link

blackdragon2447 commented Feb 13, 2022

trying to compile a project for riscv64gc-unknown-linux-musl using cargo build --target riscv64gc-unknown-linux-musl -Zbuild-std=core,std,panic_abort will result in cargo reporting not being able to find value SYS_clone3 while building the std:

error[E0425]: cannot find value `SYS_clone3` in this scope
   --> /home/blackdragon2447/.rustup/toolchains/nightly-2022-02-13-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/weak.rs:202:17
    |
202 |                   concat_idents!(SYS_, $name),
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `SYS_clone`
    |
   ::: /home/blackdragon2447/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.116/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs:239:1
    |
239 |   pub const SYS_clone: ::c_long = 220;
    |   ------------------------------------ similarly named constant `SYS_clone` defined here
    |
   ::: /home/blackdragon2447/.rustup/toolchains/nightly-2022-02-13-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/process/process_unix.rs:165:9
    |
165 | /         raw_syscall! {
166 | |             fn clone3(cl_args: *mut clone_args, len: libc::size_t) -> libc::c_long
167 | |         }
    | |_________- in this macro invocation
    |
    = note: this error originates in the macro `concat_idents` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0425`.
error: could not compile `std` due to previous error

i do have rustflags setup specifying the correct c toolchain for the target in ~/.cargo/config.toml:

[target.riscv64gc-unknown-linux-musl]
rustflags = [
"-L/home/blackdragon2447/x-tools/riscv64-unknown-linux-musl/riscv64-unknown-linux-musl/sysroot/lib",
"-L/home/blackdragon2447/x-tools/riscv64-unknown-linux-musl/lib/gcc/riscv64-unknown-linux-musl/11.2.0/",
"-L/home/blackdragon2447/x-tools/riscv64-unknown-linux-musl/riscv64-unknown-linux-musl/sysroot/usr/lib",
"-C", "link-args=-lc",
"-C", "prefer-dynamic",
"-C", "target-feature=-crt-static"
]
ar = "riscv64-unknown-linux-musl-ar"
linker = "riscv64-unknown-linux-musl-gcc"

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (5d8767cb2 2022-02-12)
binary: rustc
commit-hash: 5d8767cb229b097fedb1dd4bd9420d463c37774f
commit-date: 2022-02-12
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0

rustup show

Default host: x86_64-unknown-linux-gnu
rustup home:  /home/blackdragon2447/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain
--------------------------------------

riscv64gc-unknown-linux-gnu
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.60.0-nightly (5d8767cb2 2022-02-12)
@blackdragon2447 blackdragon2447 added the C-bug Category: This is a bug. label Feb 13, 2022
@12101111
Copy link
Contributor

rust-lang/libc#2664
Should fix by #94052

@blackdragon2447
Copy link
Author

blackdragon2447 commented Feb 26, 2022

Cool I'll wait for that to merge then.

@SaadiSave
Copy link

SaadiSave commented Apr 6, 2022

rust-lang/libc#2664 Should fix by #94052

@12101111, does that pave the way for full std availability on riscv musl?

@nmeum
Copy link

nmeum commented May 9, 2022

rust-lang/libc#2664 Should fix by #94052

@12101111, does that pave the way for full std availability on riscv musl?

Just #94052 is actually not sufficient. rust-lang/libc#2784 is also needed. Furthermore, to have the latest Rust release (1.6.0 at the time of writing) compile on riscv64 musl it is also necessary to update the vendored libc creates accordingly. Furthermore, I ran into the following issue when attempting to bootstrap a stage2 rustc on Alpine Linux (which uses musl libc):

error: unknown directive
  --> /home/buildozer/aports/community/rust/src/rustc-1.60.0-src/library/core/src/../../stdarch/crates/core_arch/src/riscv_shared/mod.rs:11:20
   |
11 |     unsafe { asm!(".insn i 0x0F, 0, x0, x0, 0x010", options(nomem, nostack)) }
   |                    ^
   |
note: instantiated into assembly here
  --> <inline asm>:1:2
   |
1  |     .insn i 0x0F, 0, x0, x0, 0x010
   |     ^

   Compiling aho-corasick v0.7.18
error: could not compile `log` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
Build completed unsuccessfully in 0:17:42

Not sure what this is about as my binutils does seem to support .insn. I temporarily worked around that by replacing the pause() function implementation with a NOP instruction.

With those outlined changes I was able to compile a stage2 rustc 1.6.0 for riscv64 on Alpine Linux. While compiling simple programs with this rustc works, compiling rust itself sadly seems to trigger compiler bugs.

@catamorphism
Copy link
Contributor

I tried to reproduce this bug, and eventually succeeded in cross-compiling code, building rustc from source yesterday (commit 2eaeb1e ). I picked a random project ( https://github.com/rust-lang/regex ) and did:

$ cargo build --target riscv64gc-unknown-linux-musl -Zbuild-std=core,std,panic_abort

and this command succeeded. (I used a config.toml similar to what @blackdragon2447 posted, except with lib/gcc/riscv64-unknown-linux-musl/12.2.0/.)

So either the issue has been fixed, or it's specific to the project @blackdragon2447 was trying to build.

$ rustc --version --verbose
rustc 1.70.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.70.0-dev
LLVM version: 16.0.0

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/tjc/.rustup

installed toolchains
--------------------

nightly-x86_64-unknown-linux-gnu
stage1 (default)

active toolchain
----------------

stage1 (default)
rustc 1.70.0-dev

(I'm a little confused about the rustup show output not showing riscv64gc-unknown-linux-musl as an installed target, but I guess that's because stage1 is my target built from source and I built it with x.py build --target x86_64-unknown-linux-gnu --target riscv64gc-unknown-linux-musl. Although I would still expect to see the installed targets listed. I followed the instructions at https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html?highlight=target#building-targets-for-cross-compilation , including the "Creating a rustup toolchain" section.)

Unless the OP provides more information, I think it would be safe to close this bug. @nmeum 's comment seems to point to different issues from the original bug, which may still exist.

@catamorphism
Copy link
Contributor

Actually @nmeum, could you clarify what you mean by "With those outlined changes I was able to compile a stage2 rustc 1.6.0 for riscv64 on Alpine Linux. While compiling simple programs with this rustc works, compiling rust itself sadly seems to trigger compiler bugs"? Do you mean that compiling stage3 doesn't work?

@blackdragon2447
Copy link
Author

I seem to be able to compile my project now, so I guess the issue on rusts side is gone. This issue should be safe to close then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants