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

linux arm64? #64

Open
pfgithub opened this issue Feb 9, 2022 · 9 comments
Open

linux arm64? #64

pfgithub opened this issue Feb 9, 2022 · 9 comments

Comments

@pfgithub
Copy link

pfgithub commented Feb 9, 2022

I tried to build with zig build but got an error

zig build
Compile C Objects [50/172] local_single_store_elim_pass.cpp... date
ld.lld: error: undefined symbol: __aarch64_ldadd8_acq_rel
>>> referenced by cxa_exception.cpp
>>>               /home/pfg/.cache/zig/o/3e01ab056524dcb1c1244d2f3c5eeec2/cxa_exception.o:(__cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a
>>> referenced by cxa_exception.cpp
>>>               /home/pfg/.cache/zig/o/3e01ab056524dcb1c1244d2f3c5eeec2/cxa_exception.o:(__cxa_end_catch) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a
>>> referenced by cxa_exception.cpp
>>>               /home/pfg/.cache/zig/o/3e01ab056524dcb1c1244d2f3c5eeec2/cxa_exception.o:(__cxa_decrement_exception_refcount) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a
>>> referenced 8 more times

ld.lld: error: undefined symbol: __aarch64_swp8_acq_rel
>>> referenced by cxa_handlers.cpp
>>>               /home/pfg/.cache/zig/o/64d3b96e34db44070d0984d092a6f424/cxa_handlers.o:(std::set_new_handler(void (*)())) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a
>>> referenced by cxa_default_handlers.cpp
>>>               /home/pfg/.cache/zig/o/2d5c3ec7a28dc673c0e03f9b1d27a829/cxa_default_handlers.o:(std::set_unexpected(void (*)())) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a
>>> referenced by cxa_default_handlers.cpp
>>>               /home/pfg/.cache/zig/o/2d5c3ec7a28dc673c0e03f9b1d27a829/cxa_default_handlers.o:(std::set_terminate(void (*)())) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a

ld.lld: error: undefined symbol: __aarch64_ldadd4_acq_rel
>>> referenced by stdlib_stdexcept.cpp
>>>               /home/pfg/.cache/zig/o/17ae5122d3f0d1e8b8d861f9a310eabe/stdlib_stdexcept.o:(std::logic_error::~logic_error()) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a
>>> referenced by stdlib_stdexcept.cpp
>>>               /home/pfg/.cache/zig/o/17ae5122d3f0d1e8b8d861f9a310eabe/stdlib_stdexcept.o:(std::logic_error::~logic_error()) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a
>>> referenced by stdlib_stdexcept.cpp
>>>               /home/pfg/.cache/zig/o/17ae5122d3f0d1e8b8d861f9a310eabe/stdlib_stdexcept.o:(std::runtime_error::~runtime_error()) in archive /home/pfg/.cache/zig/o/37c162f54d45cb72666e68725c71c99e/libc++abi.a
>>> referenced 16 more times

ld.lld: error: undefined symbol: __aarch64_ldadd8_relax
>>> referenced by memory.cpp
>>>               /home/pfg/.cache/zig/o/6884c501b9002ad0afef125b115e2078/memory.o:(std::__1::__shared_count::__add_shared()) in archive /home/pfg/.cache/zig/o/1bd721408ecc5a60cfd7119395c1d264/libc++.a
>>> referenced by memory.cpp
>>>               /home/pfg/.cache/zig/o/6884c501b9002ad0afef125b115e2078/memory.o:(std::__1::__shared_weak_count::__add_shared()) in archive /home/pfg/.cache/zig/o/1bd721408ecc5a60cfd7119395c1d264/libc++.a
>>> referenced by memory.cpp
>>>               /home/pfg/.cache/zig/o/6884c501b9002ad0afef125b115e2078/memory.o:(std::__1::__shared_weak_count::__add_weak()) in archive /home/pfg/.cache/zig/o/1bd721408ecc5a60cfd7119395c1d264/libc++.a

ld.lld: error: undefined symbol: __aarch64_cas8_acq_rel
>>> referenced by memory.cpp
>>>               /home/pfg/.cache/zig/o/6884c501b9002ad0afef125b115e2078/memory.o:(std::__1::__shared_weak_count::lock()) in archive /home/pfg/.cache/zig/o/1bd721408ecc5a60cfd7119395c1d264/libc++.a
error: LLDReportedFailure
sokol-shdc...The following command exited with error code 1:
/home/pfg/Apps/zig/zig-linux-aarch64-0.10.0-dev.599+0a7801236/zig build-exe -lc -lc++ /home/pfg/Dev/sokol-tools/zig-cache/o/1df3121054c32d2d6c7ee908274c9bb7/libfmt.a /home/pfg/Dev/sokol-tools/zig-cache/o/0100a4a7c292e49c66ed48a98869d910/libgetopt.a /home/pfg/Dev/sokol-tools/zig-cache/o/98a3fc31ee374912e41745516394082a/libpystring.a /home/pfg/Dev/sokol-tools/zig-cache/o/64847f0758baa65e2f17390d5eafad01/libspirvcross.a /home/pfg/Dev/sokol-tools/zig-cache/o/b1bdb7eb7a7354e1b2626268f6355fee/libspirvtools.a /home/pfg/Dev/sokol-tools/zig-cache/o/78f9a763e75e6b4833a0ec556a85c85b/libglslang.a -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/args.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/bare.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/bytecode.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/input.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/main.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/sokol.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/sokolzig.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/spirv.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/spirvcross.cc -cflags -fstrict-aliasing -fno-rtti -fno-exceptions -DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS -- /home/pfg/Dev/sokol-tools/src/shdc/util.cc --cache-dir /home/pfg/Dev/sokol-tools/zig-cache --global-cache-dir /home/pfg/.cache/zig --name sokol-shdc -I /home/pfg/Dev/sokol-tools/ext/fmt/include -I /home/pfg/Dev/sokol-tools/ext/SPIRV-Cross -I /home/pfg/Dev/sokol-tools/ext/pystring -I /home/pfg/Dev/sokol-tools/ext/getopt/include -I /home/pfg/Dev/sokol-tools/ext/glslang -I /home/pfg/Dev/sokol-tools/ext/glslang/glslang/Public -I /home/pfg/Dev/sokol-tools/ext/glslang/glslang/Include -I /home/pfg/Dev/sokol-tools/ext/glslang/SPIRV -I /home/pfg/Dev/sokol-tools/ext/SPIRV-Tools/include --enable-cache 
error: the following build command failed with exit code 1:
/home/pfg/Dev/sokol-tools/zig-cache/o/0074cf5de30fa61b428f800b825544f0/build /home/pfg/Apps/zig/zig-linux-aarch64-0.10.0-dev.599+0a7801236/zig /home/pfg/Dev/sokol-tools /home/pfg/Dev/sokol-tools/zig-cache /home/pfg/.cache/zig
@floooh
Copy link
Owner

floooh commented Feb 20, 2022

No idea what's up with that, sorry. The zig build is currently more like an experiment, and not really "actively maintained". One problem I saw was that the executable size is a lot bigger than going through the cmake build, at least on macOS. This might have improved in the meantime with recent linker updates though.

@DctrNoob
Copy link

DctrNoob commented May 21, 2022

I came across the same situation where I needed the sokol-shdc tool for arm64 linux. I did not encounter the problems by @pfgithub and got an executable via zig build without problems. However, the executable is indeed pretty big (201MB compared to the 5-7MB using cmake). Still, it worked for me.

@floooh
Copy link
Owner

floooh commented May 30, 2022

@DctrNoob you could try zig build -Drelease-small, on my ARM Mac this gives me a 12 MB executable, this is still twice the size of a Clang build (I think the Zig linker doesn't have similar output size optimizations yet), but still much smaller than 201 MB :)

@DctrNoob
Copy link

DctrNoob commented May 31, 2022

@floooh Thanks for the tip. Under Linux this still leads to an executable of 124 MB for me. Better but still pretty awful. =)
Edit: could maybe also be a difference between gcc and clang.

@floooh
Copy link
Owner

floooh commented May 31, 2022

Hmm ok, I guess I should add a "native" linux-arm64 executable (should be much easier now with the GH Actions based compilation (e.g. https://github.com/floooh/sokol-tools/actions/runs/2282914956).

I "just" need to figure out how to cross-compile an arm64 executable with cmake (on macOS this is a special cmake variable CMAKE_OSX_ARCHITECTURES = arm64, but on Linux it doesn't seem quite so trivial: https://discourse.cmake.org/t/linux-cross-compile-x64-to-aarch64/1752/6

@floooh
Copy link
Owner

floooh commented May 31, 2022

PS: did you try stripping the executable? Maybe it still has some sort of symbols embedded despite compiling with -Drelease-small?

@DctrNoob
Copy link

@floooh I would but I am a zig noob and the --strip option is only available when using zig build-exe it seems.

@DctrNoob
Copy link

DctrNoob commented Jun 1, 2022

@floooh So I figured it out. I simply had to add exe.strip = true to build.zig at an appropriate location. Now I've got a 5.4 MB executable for Linux arm64. And it works, too. =)

I could raise a PR if you like.

@floooh
Copy link
Owner

floooh commented Jun 2, 2022

@DctrNoob nice! I just added this fix (exe.strip will be set to true in any of the release modes).

2cd64a0

On macOS it doesn't seem to make much of a difference though (I still get a 12 MByte executable), but this could be because the new Zig linker doesn't implement the same tricks yet as the Apple linker.

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

3 participants