I am trying to compile phone_numbers library (Elixir wrapper for Google's libphonenumber) on M1 mac running Ventura 13.4.1.
It fails during linking phase with an error I find difficult to interpret.
Here's the linking command and its output
$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld \
-demangle \
-lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib \
-dynamic \
-dylib \
-arch arm64 \
-flat_namespace \
-platform_version macos 13.0.0 13.3 \
-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
-undefined suppress \
-undefined suppress \
-o /Users/michals/code/phone_numbers/priv/phone_number_util_nif.so \
-L/opt/homebrew/Cellar/libphonenumber/8.13.17/lib \
-L/Users/michals/.asdf/installs/erlang/25.0.2/lib/erl_interface-5.3/lib \
-L/opt/homebrew/lib \
-L. \
-L/opt/homebrew/lib \
-L. \
-L/usr/local/lib \
-lc++ \
-lei \
-lphonenumber \
-lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.3/lib/darwin/libclang_rt.osx.a \
/Users/michals/code/phone_numbers/c_src/phone_number_util_nif.o \
-v
@(#)PROGRAM:ld PROJECT:ld64-857.1
BUILD 23:13:29 May 7 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
/opt/homebrew/Cellar/libphonenumber/8.13.17/lib
/Users/michals/.asdf/installs/erlang/25.0.2/lib/erl_interface-5.3/lib
/opt/homebrew/lib
.
/opt/homebrew/lib
.
/usr/local/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
Framework search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/
0 0x102c3c71c __assert_rtn + 140
1 0x102af4ed4 ld::tool::InputFiles::findDylib(char const*, ld::dylib::File const*, bool) + 1080
2 0x102bc99f0 generic::dylib::File::processIndirectLibraries(ld::dylib::File::DylibHandler*, bool) + 88
3 0x102af657c ld::tool::InputFiles::createIndirectDylibs() + 496
4 0x102af7398 ld::tool::InputFiles::forEachInitialAtom(ld::File::AtomHandler&, ld::Internal&) + 972
5 0x102b0b184 ld::tool::Resolver::resolve() + 124
6 0x102a78ea4 main + 592
A linker snapshot was created at:
/tmp/phone_number_util_nif.so-2023-07-25-020335.ld-snapshot
ld: Assertion failed: (counter() < 0xffff), function nextCounter, file ld.hpp, line 466.
To give some context, /Users/michals/code/phone_numbers/c_src/phone_number_util_nif.o is only 60kb in size, but ld process peaks at ~150mb of memory usage.
I tried reinstalling XCode, libphonenumber (with homebrew, brew test libphonenumber succeeds) and Erlang. I also tried different versions of Erlang.
Turns out this is a bug in the linker shipped with Xcode 14.
Suggested workaround is to downgrade to Xcode 13, but in my case it was not possible, because this version cannot be installed on a newer system - Ventura 13.4.1.
However the bug got fixed in Xcode 15, which is currently in beta. It can be downloaded from apple servers[1].
So:
/Applicationsfolder[1] https://developer.apple.com/download/all