coolaj86 / rust-hello-cross-zig

Rust "Hello World", cross-compiled with Zig
Mozilla Public License 2.0
4 stars 0 forks source link

ld.lld: error: undefined symbol: _Unwind_Resume #2

Open coolaj86 opened 2 years ago

coolaj86 commented 2 years ago
rm -rf ./target
rm -rf ~/.cache/zig
CC="zig-cc-x86_64-linux-gnu" cargo build --target x86_64-unknown-linux-gnu
   Compiling hello v0.1.0 (/private/tmp/hello)
error: linking with `zig-cc-x86_64-linux-gnu` failed: exit status: 1
  |
  = note: "zig-cc-x86_64-linux-gnu" "-m64" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.2u831i91a5n7aje3.rcgu.o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.36jenterk0cheql4.rcgu.o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.38sl65aenayrr897.rcgu.o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.3s6c6jdlsatokf5i.rcgu.o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.3z1fzgr59ex6b2g0.rcgu.o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.429lwwkg4fwk0jq9.rcgu.o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.bg5kpokqtr31443.rcgu.o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.zxcpql81lczk6mh.rcgu.o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.34ohcojr4n220jbu.rcgu.o" "-Wl,--as-needed" "-L" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps" "-L" "/private/tmp/hello/target/debug/deps" "-L" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f2400674c7513725.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-605c3a7d1a5d300d.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-3d4fb4efa907e4e8.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-65207f030ab23308.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-76ca199cb0186109.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-1e3e01ed4f561dc1.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-dd8dddcba7c13fee.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-00b13d31c3420656.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e4c8460b81557bd5.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-600d46e5f0005455.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-e4a08a2585b62d37.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fbc21ec567cb9dc7.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-10b3fa8e49bd978f.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-64625b73694ffce7.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-fb6b78ac543a58ee.rlib" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-1d1f2d1bec6f51b8.rlib" "-Wl,--end-group" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-acf5ff6e9595d982.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: warning: unsupported linker arg: -znoexecstack
          warning: unsupported linker arg: -zrelro
          warning: unsupported linker arg: -znow
          warning: ignoring superfluous library 'gcc_s': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides
          ld.lld: error: undefined symbol: _Unwind_Resume
          >>> referenced by function.rs:227 (/rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/ops/function.rs:227)
          >>>               /private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.2u831i91a5n7aje3.rcgu.o:(core::ops::function::FnOnce::call_once::hecfef0d049c564a6)
          >>> referenced by backtrace.rs:118 (/rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/sys_common/backtrace.rs:118)
          >>>               /private/tmp/hello/target/x86_64-unknown-linux-gnu/debug/deps/hello-ba716e8c717f55e4.36jenterk0cheql4.rcgu.o:(std::sys_common::backtrace::__rust_begin_short_backtrace::hcb14acc25b27f756)
          >>> referenced by alloc.rs:0 (/rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/alloc/src/alloc.rs:0)
          >>>               std-8d61b92a0a02f53a.std.28dff6de-cgu.0.rcgu.o:(core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::hf35af5048e4bd27c) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib
          >>> referenced 72 more times

          ld.lld: error: undefined symbol: _Unwind_Backtrace
          >>> referenced by libunwind.rs:93 (library/std/src/../../backtrace/src/backtrace/libunwind.rs:93)
          >>>               std-8d61b92a0a02f53a.std.28dff6de-cgu.0.rcgu.o:(_$LT$std..sys_common..backtrace.._print..DisplayBacktrace$u20$as$u20$core..fmt..Display$GT$::fmt::h606862f787600875) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib

          ld.lld: error: undefined symbol: _Unwind_GetIP
          >>> referenced by libunwind.rs:43 (library/std/src/../../backtrace/src/backtrace/libunwind.rs:43)
          >>>               std-8d61b92a0a02f53a.std.28dff6de-cgu.0.rcgu.o:(std::sys_common::backtrace::_print_fmt::_$u7b$$u7b$closure$u7d$$u7d$::h7e96097cf8725d68) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib
          >>> referenced by libunwind.rs:43 (library/std/src/../../backtrace/src/backtrace/libunwind.rs:43)
          >>>               std-8d61b92a0a02f53a.std.28dff6de-cgu.0.rcgu.o:(std::sys_common::backtrace::_print_fmt::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h6a12823434bbeeef) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib
          >>> referenced by libunwind.rs:43 (library/std/src/../../backtrace/src/backtrace/libunwind.rs:43)
          >>>               std-8d61b92a0a02f53a.std.28dff6de-cgu.0.rcgu.o:(std::backtrace_rs::symbolize::gimli::resolve::h377c1d10cdfd7d94) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib

          ld.lld: error: undefined symbol: _Unwind_GetDataRelBase
          >>> referenced by gcc.rs:312 (library/panic_unwind/src/gcc.rs:312)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h5082f9683150112b) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib
          >>> referenced by gcc.rs:312 (library/panic_unwind/src/gcc.rs:312)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(panic_unwind::real_imp::find_eh_action::_$u7b$$u7b$closure$u7d$$u7d$::hd993293e11870c1b) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

          ld.lld: error: undefined symbol: _Unwind_GetTextRelBase
          >>> referenced by gcc.rs:311 (library/panic_unwind/src/gcc.rs:311)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::hbaead8c0cc2f640b) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib
          >>> referenced by gcc.rs:311 (library/panic_unwind/src/gcc.rs:311)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(panic_unwind::real_imp::find_eh_action::_$u7b$$u7b$closure$u7d$$u7d$::hedef531a78879bae) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

          ld.lld: error: undefined symbol: _Unwind_DeleteException
          >>> referenced by gcc.rs:78 (library/panic_unwind/src/gcc.rs:78)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(__rust_panic_cleanup) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

          ld.lld: error: undefined symbol: _Unwind_RaiseException
          >>> referenced by gcc.rs:62 (library/panic_unwind/src/gcc.rs:62)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(__rust_start_panic) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

          ld.lld: error: undefined symbol: _Unwind_GetLanguageSpecificData
          >>> referenced by gcc.rs:303 (library/panic_unwind/src/gcc.rs:303)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(rust_eh_personality) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

          ld.lld: error: undefined symbol: _Unwind_GetIPInfo
          >>> referenced by gcc.rs:305 (library/panic_unwind/src/gcc.rs:305)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(rust_eh_personality) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

          ld.lld: error: undefined symbol: _Unwind_GetRegionStart
          >>> referenced by gcc.rs:310 (library/panic_unwind/src/gcc.rs:310)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(rust_eh_personality) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

          ld.lld: error: undefined symbol: _Unwind_SetGR
          >>> referenced by gcc.rs:254 (library/panic_unwind/src/gcc.rs:254)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(rust_eh_personality) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

          ld.lld: error: undefined symbol: _Unwind_SetIP
          >>> referenced by gcc.rs:257 (library/panic_unwind/src/gcc.rs:257)
          >>>               panic_unwind-fc45202bb435016b.panic_unwind.58b25625-cgu.0.rcgu.o:(rust_eh_personality) in archive /Users/aj/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib

error: could not compile `hello` due to previous error
qris commented 1 year ago

Note this line:

      warning: ignoring superfluous library 'gcc_s': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides

The LLVM compiler-rt runtime (--rtlib=compiler-rt) does not provide an unwinder unless it's compiled with support for it enabled. I'm guessing your LLVM is not, thus the missing symbols:

      ld.lld: error: undefined symbol: _Unwind_Resume

The unwind library provides a family of _Unwind_* functions implementing the language-neutral stack unwinding portion of the Itanium C++ ABI (Level I). It is a dependency of the C++ ABI library, and sometimes is a dependency of other runtimes.

libunwind (LLVM) LLVM’s unwinder library is part of the llvm-project git repository. To build it, pass -DLLVM_ENABLE_RUNTIMES=libunwind to the cmake invocation.

https://clang.llvm.org/docs/Toolchain.html#unwind-library

You may need to rebuild your llvm/clang with this option (and the matching libunwind package downloaded and installed in the correct location, next to llvm itself).

It may also be related to ignoring the request to link with libgcc_s. From the same page:

libgcc_s (GNU) libgcc_s has an integrated unwinder, and does not need an external unwind library to be provided.

So if libgcc_s had been used, this error would not have happened.