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

Use -target x86_64-macosx-gnu will run failed on macOS #5828

Closed
waruqi opened this issue Jul 9, 2020 · 3 comments
Closed

Use -target x86_64-macosx-gnu will run failed on macOS #5828

waruqi opened this issue Jul 9, 2020 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior os-macos upstream An issue with a third party project that Zig uses.
Milestone

Comments

@waruqi
Copy link

waruqi commented Jul 9, 2020

I use -target x86_64-macosx-gnu to build static library and executable program, the generated program will run failed on macOS.

[ 37%]: ccache compiling.debug src/test.zig
/usr/local/bin/zig build-obj -target x86_64-macosx-gnu --output-dir build/.objs/testlib/macosx/x86_64/debug/src --name test.zig src/test.zig
checking for the zig compiler (zc) ... zig
[ 50%]: ccache compiling.debug src/main.zig
/usr/local/bin/zig build-obj -target x86_64-macosx-gnu --output-dir build/.objs/test/macosx/x86_64/debug/src --name main.zig src/main.zig
[ 62%]: archiving.debug libtestlib.a
/usr/local/bin/zig build-lib --output-dir build/macosx/x86_64/debug --name testlib --object build/.objs/testlib/macosx/x86_64/debug/src/test.zig.o
[ 87%]: linking.debug test
/usr/local/bin/zig build-exe -Lbuild/macosx/x86_64/debug -ltestlib -target x86_64-macosx-gnu --output-dir build/macosx/x86_64/debug --name test --object build/.objs/test/macosx/x86_64/debug/src/main.zig.o
[100%]: build ok!
ruki-2:static_library ruki$ xmake r
dyld: Symbol not found: __tlv_bootstrap
  Referenced from: /Users/ruki/projects/personal/xmake/tests/projects/zig/static_library/build/macosx/x86_64/debug/test
  Expected in: /Users/ruki/projects/personal/xmake/tests/projects/zig/static_library/build/macosx/x86_64/debug/test
 in /Users/ruki/projects/personal/xmake/tests/projects/zig/static_library/build/macosx/x86_64/debug/test
error: execv(/Users/ruki/projects/personal/xmake/tests/projects/zig/static_library/build/macosx/x86_64/debug/test) failed(-1)

But it works when I remove -target x86_64-macosx-gnu.

/usr/local/bin/zig build-obj --output-dir build/.objs/test/macosx/x86_64/debug/src --name main.zig src/main.zig
checking for the zig compiler (zc) ... zig
[ 50%]: ccache compiling.debug src/test.zig
/usr/local/bin/zig build-obj --output-dir build/.objs/testlib/macosx/x86_64/debug/src --name test.zig src/test.zig
[ 62%]: archiving.debug libtestlib.a
/usr/local/bin/zig build-lib --output-dir build/macosx/x86_64/debug --name testlib --object build/.objs/testlib/macosx/x86_64/debug/src/test.zig.o
[ 87%]: linking.debug test
/usr/local/bin/zig build-exe -Lbuild/macosx/x86_64/debug -ltestlib --output-dir build/macosx/x86_64/debug --name test --object build/.objs/test/macosx/x86_64/debug/src/main.zig.o
[100%]: build ok!
ruki-2:static_library ruki$ xmake r
Hello, world - 2!
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-macos upstream An issue with a third party project that Zig uses. labels Oct 4, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Oct 4, 2020
@andrewrk
Copy link
Member

andrewrk commented Oct 4, 2020

This is due to LLD's MachO linker code being insufficiently maintained for years. Recently, 2 things have changed.

  1. There is a new team of maintainers working on LLD MachO linker code. They have not improved things yet with LLVM 11 release coming up but hopefully with LLVM 12 things will be improved.
  2. @kubkon has become interested in working on zig's self-hosted macho linker code. Depending on how far he gets, it may actually be the thing that solves this issue before (1). That said, Jakub's time is his own, and it would be unfair to set unreasonable expectations on him. This code is written in zig so we may see some other contributors enter this space too, if all goes well.

@kubkon
Copy link
Member

kubkon commented Oct 4, 2020

This is due to LLD's MachO linker code being insufficiently maintained for years. Recently, 2 things have changed.

  1. There is a new team of maintainers working on LLD MachO linker code. They have not improved things yet with LLVM 11 release coming up but hopefully with LLVM 12 things will be improved.
  2. @kubkon has become interested in working on zig's self-hosted macho linker code. Depending on how far he gets, it may actually be the thing that solves this issue before (1). That said, Jakub's time is his own, and it would be unfair to set unreasonable expectations on him. This code is written in zig so we may see some other contributors enter this space too, if all goes well.

Just a note that things have picked up recently as seen in #6476 and we can generate basic functional MachO executables from any target, so if I/we manage to keep the pace up, point 2. is not unreachable (pan not intended).

@andrewrk
Copy link
Member

Duplicate of #3295

@andrewrk andrewrk modified the milestones: 0.9.0, 0.8.0 Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

No branches or pull requests

3 participants