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

gcc internal compiler error due to cc1 being dynamically linked against missing libzstd #8

Closed
edmorley opened this issue Feb 12, 2022 · 2 comments

Comments

@edmorley
Copy link
Contributor

edmorley commented Feb 12, 2022

Hi!

Thank you for providing these toolchains! :-)

We're currently transitioning to this project from https://github.com/FiloSottile/homebrew-musl-cross since we need Apple M1 support, and that project does not yet support it.

However we think we've encountered an issue with the brew packages here - in that they have a hidden dependency on libzstd, which causes compile errors if it's not present.

Steps to reproduce

  1. rustup default stable
  2. rustup update
  3. rustup target add x86_64-unknown-linux-musl
  4. brew uninstall x86_64-unknown-linux-musl zstd (if zstd can't be uninstalled due to being depended on by other packages, uninstall those other packages too)
  5. brew install messense/macos-cross-toolchains/x86_64-unknown-linux-musl
  6. cargo new testcase && cd $_
  7. cargo add ring (or add to Cargo.toml manually, if cargo-edit isn't installed)
  8. export CC_x86_64_unknown_linux_musl=x86_64-unknown-linux-musl-gcc CXX_x86_64_unknown_linux_musl=x86_64-unknown-linux-musl-g++ AR_x86_64_unknown_linux_musl=x86_64-unknown-linux-musl-ar CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-unknown-linux-musl-gcc
  9. cargo build --target x86_64-unknown-linux-musl

Expected

Cargo build succeeds.

Actual

Cargo build fails with this error:

$ cargo build --target x86_64-unknown-linux-musl
   Compiling cc v1.0.72
   Compiling libc v0.2.117
   Compiling once_cell v1.9.0
   Compiling untrusted v0.7.1
   Compiling spin v0.5.2
   Compiling ring v0.16.20
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/Users/emorley/src/testcase/target/debug/build/ring-05aa88e857cb018a/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("0")
  TARGET = Some("x86_64-unknown-linux-musl")
  HOST = Some("x86_64-apple-darwin")
  CC_x86_64-unknown-linux-musl = None
  CC_x86_64_unknown_linux_musl = Some("x86_64-unknown-linux-musl-gcc")
  CFLAGS_x86_64-unknown-linux-musl = None
  CFLAGS_x86_64_unknown_linux_musl = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

  --- stderr
  running "x86_64-unknown-linux-musl-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/Users/emorley/src/testcase/target/x86_64-unknown-linux-musl/debug/build/ring-c827af35860feb9e/out/aesni-x86_64-elf.o" "/Users/emorley/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
  dyld[39495]: Library not loaded: /usr/local/opt/zstd/lib/libzstd.1.dylib
    Referenced from: /usr/local/Cellar/x86_64-unknown-linux-musl/10.3.0/toolchain/libexec/gcc/x86_64-unknown-linux-musl/10.3.0/cc1
    Reason: tried: '/usr/local/opt/zstd/lib/libzstd.1.dylib' (no such file), '/Users/emorley/src/testcase/target/debug/deps/libzstd.1.dylib' (no such file), '/Users/emorley/src/testcase/target/debug/libzstd.1.dylib' (no such file), '/Users/emorley/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libzstd.1.dylib' (no such file), '/Users/emorley/.rustup/toolchains/stable-x86_64-apple-darwin/lib/libzstd.1.dylib' (no such file), '/Users/emorley/lib/libzstd.1.dylib' (no such file), '/usr/local/lib/libzstd.1.dylib' (no such file), '/usr/lib/libzstd.1.dylib' (no such file)
  x86_64-unknown-linux-musl-gcc: internal compiler error: Abort trap: 6 signal terminated program cc1

Additional information

Manually installing the zstd package to ensure libzstd is available (eg via brew install zstd) makes the build succeed.

It appears the cc1 binary at /usr/local/Cellar/x86_64-unknown-linux-musl/10.3.0/toolchain/libexec/gcc/x86_64-unknown-linux-musl/10.3.0/cc1 is dynamically linked against libzstd, however the x86_64-unknown-linux-musl package does not ensure it exists.

It seems the solutions would be to either:

  1. Have the x86_64-unknown-linux-musl brew package (and related packages) declare a dependency on the zstd brew package, so brew installs that at the same time.
  2. (If the building of the cc1 binary is something within this project's control) Statically build the cc1 binary so it doesn't have dependencies on external libraries.
  3. Package libzstd some other way inside the x86_64-unknown-linux-musl brew package and ensure the toolchain configuration is such that it can be found at runtime.
@edmorley edmorley changed the title cc1 internal compiler error due to missing libzstd dependency gcc internal compiler error due to cc1 being dynamically linked against missing libzstd Feb 12, 2022
@edmorley
Copy link
Contributor Author

@messense Hi! Thank you for the fast fix :-)

I notice that the change was only applied to the musl toolchains, however it seems the others are also dynamically linked against libzstd?

eg:

$ otool -L /usr/local/Cellar/x86_64-unknown-linux-gnu/10.3.0/toolchain/libexec/gcc/x86_64-unknown-linux-gnu/10.3.0/cc1 | rg zstd
	/usr/local/opt/zstd/lib/libzstd.1.dylib (compatibility version 1.0.0, current version 1.4.9)

...which is the same as for musl:

$ otool -L /usr/local/Cellar/x86_64-unknown-linux-musl/10.3.0/toolchain/libexec/gcc/x86_64-unknown-linux-musl/10.3.0/cc1 | rg zstd
	/usr/local/opt/zstd/lib/libzstd.1.dylib (compatibility version 1.0.0, current version 1.4.9)

...so presumably the others need the depends_on too?

@messense
Copy link
Owner

@edmorley Done in 13b3250

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