cross icon indicating copy to clipboard operation
cross copied to clipboard

Segfault when compiling from M1 macbook to x86_64-unknown-linux-gnu

Open thestarmaker opened this issue 2 years ago • 7 comments

Checklist

Describe your issue

Hello, I am trying to cross compile an application on M1 Macbook to x86_64-unknown-linux-gnu but getting segfault.

Command used:

cross build --target x86_64-unknown-linux-gnu --release

Results in

...
...
   Compiling bytecheck_derive v0.6.11
error: linking with `cc` failed: exit status: 4
  |
  = note: LC_ALL="C" PATH="/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin" VSLANG="1033" "cc" "-Wl,--version-script=/tmp/rustcRJoesS/list" "-Wl,--no-undefined-version" "-m64" "/tmp/rustcRJoesS/symbols.o" "/target/release/deps/bytecheck_derive-e232799992011355.bytecheck_derive.93bb9eb7272cdb13-cgu.0.rcgu.o" "/target/release/deps/bytecheck_derive-e232799992011355.bytecheck_derive.93bb9eb7272cdb13-cgu.1.rcgu.o" "/target/release/deps/bytecheck_derive-e232799992011355.bytecheck_derive.93bb9eb7272cdb13-cgu.2.rcgu.o" "/target/release/deps/bytecheck_derive-e232799992011355.bytecheck_derive.93bb9eb7272cdb13-cgu.3.rcgu.o" "/target/release/deps/bytecheck_derive-e232799992011355.bytecheck_derive.93bb9eb7272cdb13-cgu.4.rcgu.o" "/target/release/deps/bytecheck_derive-e232799992011355.tvka76dvd803l2x.rcgu.rmeta" "/target/release/deps/bytecheck_derive-e232799992011355.4oiz2l11tvprwmg3.rcgu.o" "-Wl,--as-needed" "-L" "/target/release/deps" "-L" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/target/release/deps/libsyn-69ec48c693b1b3f6.rlib" "/target/release/deps/libquote-2ad1f6550352b3ef.rlib" "/target/release/deps/libproc_macro2-1aa811561c3ba260.rlib" "/target/release/deps/libunicode_ident-8d5f48593d34662b.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libproc_macro-8ef1d81577e9ba51.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-a60ea580632c66b2.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-0246f9e29468a372.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-979cf952bd1658de.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-03fa28fdeaafd68b.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-03e2c40d9b97f2da.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-b46544d0dee7d770.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-99aa4e25844454d5.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-9150218a70bddb76.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-03e4207e81b1c3a8.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-f6b4bb99c2a0252e.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-2f724c5b2e2ac3bf.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-8cc04b330b04bc1f.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-989658a4668f769d.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-c7e3d38fd607ad46.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-ff4ae84067796be3.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-2aa132acfd312321.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-cd2f2bc505f56f50.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-ec02dd343723da85.rlib" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-00ae71943a8bc9aa.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/Users/retropaladin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/target/release/deps/libbytecheck_derive-e232799992011355.so" "-Wl,--gc-sections" "-shared" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: cc: internal compiler error: Segmentation fault signal terminated program collect2
          Please submit a full bug report,
          with preprocessed source if appropriate.
          See <file:///usr/share/doc/gcc-9/README.Bugs> for instructions.
          

error: could not compile `bytecheck_derive` (lib) due to previous error

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • [X] macOS
  • [ ] Windows
  • [ ] Linux / BSD
  • [ ] other OS (specify in description)

What architecture is the host?

  • [ ] x86_64 / AMD64
  • [ ] arm32
  • [X] arm64 (including Mac M1)

What container engine is cross using?

  • [ ] docker
  • [X] podman
  • [ ] other container engine (specify in description)

cross version

cross 0.2.5 (37c681a 2023-07-17)

Example

sorry, the application is quite large, I can not submit sources. The application is based on leptos-rs.

Additional information / notes

No response

thestarmaker avatar Aug 01 '23 16:08 thestarmaker

This might be a legit segfault, are you sure docker/the container engine is not capping out?

Emilgardis avatar Aug 01 '23 16:08 Emilgardis

Hey, looking at the offending library, it seems to come from rkyv serialisers family.

are you sure docker/the container engine is not capping out

sorry, what do you mean? Everything is possible, I noticed that the build is much slower than native one.

thestarmaker avatar Aug 01 '23 16:08 thestarmaker

What I mean is that podman might not have enough memory to build.

The reason it's slower is because we have to resort to x86_64 emulation to run a x86_64 container on aarch64 hardware. We're planning on solving that.

podman machine inspect should tell you how much memory is allocated for the machine, you can increase that with

podman machine stop
podman machine set --memory 4096 # adding more CPUs wouldn't hurt either with --cpus x
podman machine start

Emilgardis avatar Aug 01 '23 17:08 Emilgardis

observation: the project contains multiple crates, looks like there may be different versions of rkyv present. Younger version seems to compile fine:

   Compiling lock_api v0.4.10
   Compiling rkyv_derive v0.7.42
   Compiling bytecheck_derive v0.7.0
   Compiling encoding_rs v0.8.32

Note how it originally segfaulted on bytecheck_derive v0.6.11. Rerunning the build, will update once done.

thestarmaker avatar Aug 01 '23 17:08 thestarmaker

righty, so the machine is quite thin:

          "Resources": {
               "CPUs": 1,
               "DiskSize": 100,
               "Memory": 2048
          },

The build did run much further this time (does this eliminate segfault suspicion?), and there is a new problem, probbaly not related, but any chance you could advise me on what that could be plese (I am quite new to Rust)?

error[E0786]: found invalid metadata files for crate `hyper`
  --> /Users/retropaladin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/async_impl/decoder.rs:19:5
   |
19 | use hyper::body::HttpBody;
   |     ^^^^^
   |
   = note: failed to mmap rmeta metadata: '/target/x86_64-unknown-linux-gnu/release/deps/libhyper-41d1bf4ffc0ea818.rmeta'

error: could not compile `reqwest` (lib) due to previous error

thestarmaker avatar Aug 01 '23 17:08 thestarmaker

Nice, this new error is unrelated to the segfault.

that error suggests two different toolchains were used to make the meta files, however, I'd first try cleaning the artifacts.

cargo clean --release --target x86_64-unknown-linux-gnu

Emilgardis avatar Aug 01 '23 18:08 Emilgardis

If that doesn't solve it, try reinstalling the toolchain you're using, which would be

rustup toolchain remove stable-x86_64-unknown-linux-gnu and then running the build again (cross automatically will pull it) or similar (note that the toolchain cross uses is x86_64-unknown-linux-gnu, not what you'd use as the host on the mac)

Emilgardis avatar Aug 01 '23 18:08 Emilgardis