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

Build failed on macOS Sonoma with Xcode 15: zig2 duplicate symbol __mh_execute_header #17050

Closed
thelastlin opened this issue Sep 2, 2023 · 9 comments · Fixed by #17180
Closed
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Milestone

Comments

@thelastlin
Copy link

Zig Version

0.11.0

Steps to Reproduce and Observed Behavior

  1. Install required dependencies.
  2. Configure and build with:
    export SDKROOT=$(xcrun --sdk macosx --show-sdk-path); cd builld;
    cmake .. -DCMAKE_PREFIX_PATH=$PATH_TO_LLVM16_INSTALL_PATH
    make -j`nproc`
    which SDKROOT will be set to /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk
  3. Failed at Linking CXX executable zig2, linker output:
     @(#)PROGRAM:ld  PROJECT:dyld-1015.7
     BUILD 19:43:18 Aug 22 2023
     configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
     will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
     LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
     TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.3)
     Library search paths:
         ... 
     Framework search paths:
     ld: warning: ignoring duplicate libraries: '/path/to/llvm-16/lib/libclangAST.a', '/path/to/llvm-16/lib/libclangASTMatchers.a', '/path/to/llvm-16/lib/libclangAnalysis.a', '/path/to/llvm-16/lib/libclangParse.a', '/path/to/llvm-16/lib/libclangSema.a', '/path/to/llvm-16/lib/libclangStaticAnalyzerCheckers.a', '/path/to/llvm-16/lib/libclangStaticAnalyzerCore.a', '/path/to/llvm-16/lib/libclangStaticAnalyzerFrontend.a'
     duplicate symbol '__mh_execute_header' in:
         /path/to/build/CMakeFiles/zig2.dir/zig2.c.o
         boundary-file
     ld: 1 duplicate symbols
    

macOS: 23A5337a
Xcode: 15A5229m
LLVM(llvm-config --version): 16.0.6

Expected Behavior

  1. Succeed in linking zig2.
@thelastlin thelastlin added the bug Observed behavior contradicts documented or intended behavior label Sep 2, 2023
@jedisct1
Copy link
Contributor

jedisct1 commented Sep 4, 2023

As a quick workaround, edit zig2.c and remove the definition:

struct mach_header_64__3906 _mh_execute_header = {UINT32_C(0xaaaaaaaa), ... };

@mikdusan
Copy link
Member

mikdusan commented Sep 14, 2023

Further hint, this is definitely triggered when Xcode 15 (Release Candidate) linker is used, even on Ventura. It looks like the latest system linker is more strict.

@mikdusan
Copy link
Member

another hint

  • zig2.c declares without weak attribution
  • zig (stage3) when build-obj a main.zig file declares with weak attribution

but what's going on here? If we look as to why the symbol is used... it's used when .zig owns (exports) main. It's not needed when .c owns main. And this is further re-enforced by your workaround.

I'm thinking when backend is .c we have 2 choices:

  1. do not define _mh_execute_header
  2. define _mh_execute_header but it must be weak

mikdusan added a commit to mikdusan/zig that referenced this issue Sep 17, 2023
implement codegen for:

- decl weak linkage
- decl aliases
- fn decl weak linkage

closes ziglang#17050
mikdusan added a commit to mikdusan/zig that referenced this issue Sep 23, 2023
implement codegen for:

- decl weak linkage
- decl aliases
- fn decl weak linkage

windows:
- `__declspec(selectany)` is not supported for functions
- skip weak linkage for functions

closes ziglang#17050
mikdusan added a commit to mikdusan/zig that referenced this issue Sep 23, 2023
implement codegen for:

- decl weak linkage
- decl aliases
- fn decl weak linkage

windows:
- `__declspec(selectany)` is not supported for functions
- skip weak linkage for functions

closes ziglang#17050
@jvo203
Copy link

jvo203 commented Sep 24, 2023

This problem is happening on the latest macOS Ventura 13.6 too, M1 Ultra chip, even with the latest zig (after "git pull"). Can't compile / build zig.

mikdusan added a commit to mikdusan/zig that referenced this issue Sep 24, 2023
implement codegen for:

- decl weak linkage
- decl aliases
- fn decl weak linkage

windows msvc:
- `__declspec(selectany)` is not supported for functions
- skip weak linkage for functions

closes ziglang#17050
andrewrk pushed a commit that referenced this issue Sep 24, 2023
implement codegen for:

- decl weak linkage
- decl aliases
- fn decl weak linkage

windows msvc:
- `__declspec(selectany)` is not supported for functions
- skip weak linkage for functions

closes #17050
@andrewrk andrewrk added this to the 0.12.0 milestone Sep 24, 2023
@jvo203
Copy link

jvo203 commented Sep 25, 2023

Are you sure this has been fixed? Am still getting an error in Ventura 13.6 (this time on Intel macOS):

[ 94%] Linking CXX executable zig2
ld: warning: ignoring duplicate libraries: '/usr/local/opt/llvm/lib/libclangAST.a', '/usr/local/opt/llvm/lib/libclangASTMatchers.a', '/usr/local/opt/llvm/lib/libclangAnalysis.a', '/usr/local/opt/llvm/lib/libclangParse.a', '/usr/local/opt/llvm/lib/libclangSema.a', '/usr/local/opt/llvm/lib/libclangStaticAnalyzerCheckers.a', '/usr/local/opt/llvm/lib/libclangStaticAnalyzerCore.a', '/usr/local/opt/llvm/lib/libclangStaticAnalyzerFrontend.a'
duplicate symbol '__mh_execute_header' in:
    /Users/chris/projects/zig/build/CMakeFiles/zig2.dir/zig2.c.o
    boundary-file
ld: 1 duplicate symbols
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [zig2] Error 1
make[1]: *** [CMakeFiles/zig2.dir/all] Error 2
make: *** [all] Error 2

@mikdusan
Copy link
Member

mikdusan commented Sep 25, 2023

Are you sure this has been fixed? Am still getting an error in Ventura 13.6 (this time on Intel macOS):

sorry it's a 2-part fix. The first part has been committed. But we have a bootstrap process where stage1/zig1.wasm has to be updated in another commit and that has been delayed; this comment #17180 (comment) indicates that when #17253 merges to master (it looks like very soon!) it will have the updated zig1.wasm and you should be able to build.

update: zig1.wasm landed in master 6bd54a1

@jvo203
Copy link

jvo203 commented Sep 25, 2023

I see!

@wangzhizhou
Copy link

Xcode 15‘s new linker cause this problem, you can add -ld_classic into OTHER_LDFLAGS
reference: https://developer.apple.com/forums/thread/736590

@jvo203
Copy link

jvo203 commented Oct 13, 2023

Thanks, it's good to know it. Other, non-zig related projects have been affected too so it's great that at least there is a temporary workaround.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants