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

Failed to compile libunwind #281

Open
iulianR opened this issue Mar 6, 2020 · 13 comments
Open

Failed to compile libunwind #281

iulianR opened this issue Mar 6, 2020 · 13 comments

Comments

@iulianR
Copy link

iulianR commented Mar 6, 2020

Hello!

With the following config:

$ cat .cargo/config
[target.aarch64-unknown-linux-musl]
linker = "aarch64-openwrt-linux-musl-gcc"
rustflags = [
    "-C", "target-feature=-crt-static",
    "-C", "prefer-dynamic",
    "-C", "link_arg=-lgcc",
    "-C", "link_arg=-s",
    "-L/opt/toolchain/sdk-aarch64-gcc7-musl/staging_dir/toolchain-aarch64_cortex-a72_gcc-7.3.0_musl/lib64/",
    "-L/opt/toolchain/sdk-aarch64-gcc7-musl/staging_dir/target-aarch64_cortex-a72_musl/usr/lib",
]

This in $PATH:

$ echo $PATH
/opt/toolchain/sdk-aarch64-gcc7-musl/staging_dir/toolchain-aarch64_cortex-a72_gcc-7.3.0_musl/bin:<...>

With the directory containing:

$ ls /opt/toolchain/sdk-aarch64-gcc7-musl/staging_dir/toolchain-aarch64_cortex-a72_gcc-7.3.0_musl/bin | grep aarch64-openwrt-linux-musl-gcc
aarch64-openwrt-linux-musl-gcc
aarch64-openwrt-linux-musl-gcc-7.3.0
aarch64-openwrt-linux-musl-gcc-ar
aarch64-openwrt-linux-musl-gcc-nm
aarch64-openwrt-linux-musl-gcc-ranlib

Cargo.toml:

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

Xargo.toml:

[dependencies]
std = {}

This command fails:

$ xargo build --release --target aarch64-unknown-linux-musl
   Compiling unwind v0.0.0 (/home/master/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libunwind)
error: failed to run custom build command for `unwind v0.0.0 (/home/master/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libunwind)`

Caused by:
  process didn't exit successfully: `/tmp/xargo.Q543O70KJ1oj/target/release/build/unwind-080da0be54a1605a/build-script-build` (exit code: 1)
--- stdout
cargo:rerun-if-changed=build.rs
cargo:rustc-link-search=native=/tmp/xargo.Q543O70KJ1oj/target/aarch64-unknown-linux-musl/release/build/unwind-a98e36b91a645d82/out
running: "aarch64-linux-musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "../llvm-project/libunwind/include" "-std=c99" "-std=c++11" "-nostdinc++" "-fno-exceptions" "-fno-rtti" "-fstrict-aliasing" "-funwind-tables" "-D__LITTLE_ENDIAN__=1" "-o" "/tmp/xargo.Q543O70KJ1oj/target/aarch64-unknown-linux-musl/release/build/unwind-a98e36b91a645d82/out/../llvm-project/libunwind/src/Unwind-EHABI.o" "-c" "../llvm-project/libunwind/src/Unwind-EHABI.cpp"

--- stderr


error occurred: Failed to find tool. Is `aarch64-linux-musl-gcc` installed?

Anyone has any idea? I can't figure it out where the problem comes from.

@RalfJung
Copy link
Collaborator

RalfJung commented Mar 6, 2020

libstd has an unconditional dependency on libunwind. But building libunwind seems to fail because you don't have aarch64-linux-musl-gcc which it requires for cross-building. You seem to have aarch64-openwrt-linux-musl-gcc, but well, that's not the same thing.

I'm afraid I have no experience cross-building for such platforms, so that is about all I can tell you...

@iulianR
Copy link
Author

iulianR commented Mar 9, 2020

Oops, I ended up pasting the wrong error (one where the linker was not in PATH) while trying to prepare a minimal setup. Here is the error that I'm getting:

error: failed to run custom build command for `unwind v0.0.0 (/home/master/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libunwind)`
Caused by:
  process didn't exit successfully: `/tmp/xargo.C5ty0ZI1mUUm/target/release/build/unwind-080da0be54a1605a/build-script-build` (exit code: 1)
--- stdout
cargo:rerun-if-changed=build.rs
cargo:rustc-link-search=native=/tmp/xargo.C5ty0ZI1mUUm/target/aarch64-unknown-linux-musl/release/build/unwind-a98e36b91a645d82/out
running: "aarch64-openwrt-linux-musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "../llvm-project/libunwind/include" "-std=c99" "-std=c++11" "-nostdinc++" "-fno-exceptions" "-fno-rtti" "-fstrict-aliasing" "-funwind-tables" "-D__LITTLE_ENDIAN__=1" "-o" "/tmp/xargo.C5ty0ZI1mUUm/target/aarch64-unknown-linux-musl/release/build/unwind-a98e36b91a645d82/out/../llvm-project/libunwind/src/Unwind-EHABI.o" "-c" "../llvm-project/libunwind/src/Unwind-EHABI.cpp"
cargo:warning=aarch64-openwrt-linux-musl-gcc: error: ../llvm-project/libunwind/src/Unwind-EHABI.cpp: No such file or directory
cargo:warning=aarch64-openwrt-linux-musl-gcc: fatal error: no input files
cargo:warning=compilation terminated.
exit code: 1
--- stderr
error occurred: Command "aarch64-openwrt-linux-musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "../llvm-project/libunwind/include" "-std=c99" "-std=c++11" "-nostdinc++" "-fno-exceptions" "-fno-rtti" "-fstrict-aliasing" "-funwind-tables" "-D__LITTLE_ENDIAN__=1" "-o" "/tmp/xargo.C5ty0ZI1mUUm/target/aarch64-unknown-linux-musl/release/build/unwind-a98e36b91a645d82/out/../llvm-project/libunwind/src/Unwind-EHABI.o" "-c" "../llvm-project/libunwind/src/Unwind-EHABI.cpp" with args "aarch64-openwrt-linux-musl-gcc" did not execute successfully (status code exit code: 1).

It seems that path ../llvm-project/libunwind/src/Unwind-EHABI.cpp does not exist. I replaced the compiler path with a bash script that does ls .. and the llvm-project directory does not seem to exist:

total 52
drwxr-xr-x.  2 master master 4096 Mar  9 12:06 build_helper
drwxr-xr-x. 10 master master 4096 Mar  9 12:06 liballoc
drwxr-xr-x. 22 master master 4096 Mar  9 12:06 libcore
drwxr-xr-x.  2 master master 4096 Mar  9 12:06 libpanic_abort
drwxr-xr-x.  3 master master 4096 Mar  9 12:06 libpanic_unwind
drwxr-xr-x.  3 master master 4096 Mar  9 12:06 libproc_macro
drwxr-xr-x.  2 master master 4096 Mar  9 12:06 libprofiler_builtins
drwxr-xr-x. 14 master master 4096 Mar  9 12:06 libstd
drwxr-xr-x.  3 master master 4096 Mar  9 12:06 libterm
drwxr-xr-x.  5 master master 4096 Mar  9 12:06 libtest
drwxr-xr-x.  2 master master 4096 Mar  9 12:06 libunwind
drwxr-xr-x.  6 master master 4096 Mar  9 12:06 stdarch
drwxr-xr-x.  5 master master 4096 Mar  9 12:06 tools

This is what led me to believe that it's not a problem related to the compiler. rust-src and rustc seem up to date.

$ rustup component add rust-src                            
info: component 'rust-src' is up to date
$ rustc -V                     
rustc 1.43.0-nightly (564758c4c 2020-03-08)

Any idea what I should investigate next? I did manage to compile in the same manner some months ago, so it might be something that changed in Rust or Xargo since then.

@RalfJung
Copy link
Collaborator

RalfJung commented Mar 9, 2020

The rustc src directory contains llvm-project... so it looks like some change in rustc's libunwind made that depend on the LLVM checkout, and therefore rust-src is not self-contained any more.

Looking at the libunwind build script, LLVM libunwind is always used for Linux musl targets. That behavior got introduced by rust-lang/rust#63173, so I would guess that PR broke xargo for such targets.

@RalfJung
Copy link
Collaborator

RalfJung commented Mar 9, 2020

That said, it looks like before it relied on libunwind.a being available somehow, and it is not clear how you got that file either.

@iulianR
Copy link
Author

iulianR commented Mar 9, 2020

That said, it looks like before it relied on libunwind.a being available somehow, and it is not clear how you got that file either.

It probably comes from -L/opt/toolchain/sdk-aarch64-gcc7-musl/staging_dir/target-aarch64_cortex-a72_musl/usr/lib as my toolchain contains libunwind.a compiled for aarch64 musl.

@iulianR
Copy link
Author

iulianR commented Mar 9, 2020

The rustc src directory contains llvm-project... so it looks like some change in rustc's libunwind made that depend on the LLVM checkout, and therefore rust-src is not self-contained any more.

Then this is mostly a problem of the rust-src component in rustup?

@RalfJung
Copy link
Collaborator

RalfJung commented Mar 9, 2020

Well... either rust-src should contain llvm-project/libunwind, or else the libunwind build.rs should be smart enough to pick up the libunwind.a that is present on your system.

@iulianR
Copy link
Author

iulianR commented Mar 9, 2020

For now I was able to progress by cloning llvm-project in the rust/src directory, but this not ideal. If I have time, I will try to see if this issue is already reported somewhere in rustup or in rust.

@RalfJung
Copy link
Collaborator

RalfJung commented Mar 9, 2020

rustup just installs archives created by rust, so that would be the right repo to report in. Probably the solution is to add src/llvm-project/libunwind in this list, but I am not sure.

@iulianR
Copy link
Author

iulianR commented Mar 9, 2020

Ok, unless you want to (as you have more experience with the process), I will report this issue in rustup. Thanks for help!

@RalfJung
Copy link
Collaborator

RalfJung commented Mar 9, 2020

The issue should go to rust, not rustup. :)

You know all the actual details of what you want to do so it is probably better if you report it. Feel free to reference the discussion here.

EDIT: Ah, you already did.

@iulianR
Copy link
Author

iulianR commented Mar 9, 2020

The issue should go to rust, not rustup. :)

Right, I was under the impression that the list is actually maintained by rustup and I didn't pay attention. I assume you talked with someone to move the issue, so thanks for that.

@RalfJung
Copy link
Collaborator

RalfJung commented Mar 9, 2020

They moved the issue without my intervention, but anyway it is in the right place now. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants