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

Extension linking doesn't work with Xcode 14 (macOS 12.6) #790

Closed
tombruijn opened this issue Sep 15, 2022 · 4 comments · Fixed by #792
Closed

Extension linking doesn't work with Xcode 14 (macOS 12.6) #790

tombruijn opened this issue Sep 15, 2022 · 4 comments · Fixed by #792
Assignees
Labels

Comments

@tombruijn
Copy link
Member

tombruijn commented Sep 15, 2022

The linker shipped with XCode Version 14.0 (14A309) breaks linking for Elixir apps on macOS 12.6.

# In this repo's root:
$ mix run
AppSignal installation failed: Build error was encountered while running `make` (exit code: 2):

ld: warning: -undefined dynamic_lookup may not work with chained fixups
ld: fatal warning(s) induced error (-fatal_warnings)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

Xcode Version 13.4.1 (13F100), from macOS 12.5

$ man ld

     -undefined treatment
             Specifies how undefined symbols are to be treated. Options are: error, warning, suppress, or dynamic_lookup.  The default
             is error.

You can also have this older version of Xcode installed on macOS 12.6.

New Xcode Version 14.0 (14A309), from macOS 12.6

$ man ld

     -undefined treatment
             Specifies how undefined symbols are to be treated. Options are: error, warning, suppress, or dynamic_lookup.  The default is error. Note:
             dynamic_lookup that depends on lazy binding will not work with chained fixups.

See how it says "dynamic_lookup that depends on lazy binding will not work with chained fixups", the thing the new error is about.

Research

This change gives me verbose output on the error:

diff --git Makefile Makefile
index f68951ba..69f55ef2 100644
--- Makefile
+++ Makefile
@@ -20,7 +20,7 @@ ifneq ($(OS),Windows_NT)
 endif

 ifeq ($(shell uname),Darwin)
-       LDFLAGS += -dynamiclib -undefined dynamic_lookup
+       LDFLAGS += -dynamiclib -undefined dynamic_lookup -v
 endif

"Workarounds"

Notes

@tombruijn tombruijn added the bug label Sep 15, 2022
@shairyar
Copy link
Member

@tombruijn tombruijn self-assigned this Sep 15, 2022
@tombruijn tombruijn changed the title Extension linking doesn't work on macOS 12.6 Extension linking doesn't work with Xcode 14 (macOS 12.6) Sep 15, 2022
@jeffkreeftmeijer
Copy link
Member

jeffkreeftmeijer commented Sep 15, 2022

Can confirm the issue is present with the latest command line tools on macOS 12.6. Here’s the output with the added -v flag:

$ xcode-select --version
xcode-select version 2395.
$ make
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name appsignal_extension.c -mrelocation-model pic -pic-level 2 -mframe-pointer=all -mllvm -extra-vectorizer-passes -fno-strict-return -fno-rounding-math -funwind-tables=2 -target-sdk-version=12.3 -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -target-linker-version 819.6 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I /Users/jeffkreeftmeijer/.asdf/installs/erlang/23.2.2/erts-11.1.6/include -I ./priv -I/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -O3 -Wall -Wextra -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -Wno-cast-function-type -Wno-bitwise-instead-of-logical -pedantic -fdebug-compilation-dir=/Users/jeffkreeftmeijer/Appsignal/appsignal-elixir -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcommon -fcolor-diagnostics -vectorize-loops -vectorize-slp -clang-vendor-feature=+messageToSelfInClassMethodIdReturnType -clang-vendor-feature=+disableInferNewAvailabilityFromInit -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -mllvm -disable-aligned-alloc-awareness=1 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/gf/30sxxc2x18j87dnw9x3ndxd00000gn/T/appsignal_extension-f52314.o -x c c_src/appsignal_extension.c
clang -cc1 version 14.0.0 (clang-1400.0.29.102) default target x86_64-apple-darwin21.6.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Users/jeffkreeftmeijer/.asdf/installs/erlang/23.2.2/erts-11.1.6/include
 ./priv
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -dynamic -dylib -arch x86_64 -platform_version macos 12.0.0 12.3 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -undefined dynamic_lookup -undefined dynamic_lookup -o ./priv/appsignal_extension.so -L/usr/local/lib ./priv/libappsignal.a -fatal_warnings /var/folders/gf/30sxxc2x18j87dnw9x3ndxd00000gn/T/appsignal_extension-f52314.o -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.osx.a
ld: warning: -undefined dynamic_lookup may not work with chained fixups
ld: fatal warning(s) induced error (-fatal_warnings)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

tombruijn added a commit that referenced this issue Sep 15, 2022
We ran into an issue with the new Xcode version 14 command line tools,
version 2395.
The linker gave a warning about `dynamic_lookup` not working with
chained fixups, a thing that is now enabled by default on the command
line tools looks like.

```
ld: warning: -undefined dynamic_lookup may not work with chained fixups
```

It looks like we can't use `dynamic_lookup`. Instead define a list
ourselves of all the symbols we use in the `c_src/appsignal_extension.c`
file. That way we tell the linker to ignore the undefined symbols, and
have them be looked up at runtime when the Elixir NIF library is loaded.
Every time we call another NIF function defined in `erl_nif.h` we need
to update this list.

## ld documentation changes between Xcode versions that broke

Xcode Version 13.4.1 (13F100), from macOS 12.5:

```
$ man ld

     -undefined treatment
             Specifies how undefined symbols are to be treated. Options
             are: error, warning, suppress, or dynamic_lookup.  The
             default is error.
```

New Xcode Version 14.0 (14A309), from macOS 12.6:

```
$ man ld

     -undefined treatment
             Specifies how undefined symbols are to be treated. Options
             are: error, warning, suppress, or dynamic_lookup.  The
             default is error. Note: dynamic_lookup that depends on lazy
             binding will not work with chained fixups.

     -U symbol_name
             Specified that it is ok for symbol_name to have no
             definition.  With -two_levelnamespace, the resulting symbol
             will be marked dynamic_lookup which means dyld will search
             all loaded images.
```

Closes #790
tombruijn added a commit that referenced this issue Sep 15, 2022
We ran into an issue with the new Xcode version 14 command line tools,
version 2395.
The linker gave a warning about `dynamic_lookup` not working with
chained fixups, a thing that is now enabled by default on the command
line tools looks like.

```
ld: warning: -undefined dynamic_lookup may not work with chained fixups
```

It looks like we can't use `dynamic_lookup`. Instead define a list
ourselves of all the symbols we use in the `c_src/appsignal_extension.c`
file. That way we tell the linker to ignore the undefined symbols, and
have them be looked up at runtime when the Elixir NIF library is loaded.
Every time we call another NIF function defined in `erl_nif.h` we need
to update this list.

## ld documentation changes between Xcode versions that broke

Xcode Version 13.4.1 (13F100), from macOS 12.5:

```
$ man ld

     -undefined treatment
             Specifies how undefined symbols are to be treated. Options
             are: error, warning, suppress, or dynamic_lookup.  The
             default is error.
```

New Xcode Version 14.0 (14A309), from macOS 12.6:

```
$ man ld

     -undefined treatment
             Specifies how undefined symbols are to be treated. Options
             are: error, warning, suppress, or dynamic_lookup.  The
             default is error. Note: dynamic_lookup that depends on lazy
             binding will not work with chained fixups.

     -U symbol_name
             Specified that it is ok for symbol_name to have no
             definition.  With -two_levelnamespace, the resulting symbol
             will be marked dynamic_lookup which means dyld will search
             all loaded images.
```

Closes #790

Co-authored-by: Jeff Kreeftmeijer <jeffkreeftmeijer@gmail.com>
jeffkreeftmeijer added a commit that referenced this issue Sep 15, 2022
We ran into an issue with the new Xcode version 14 command line tools,
version 2395.
The linker gave a warning about `dynamic_lookup` not working with
chained fixups, a thing that is now enabled by default on the command
line tools looks like.

```
ld: warning: -undefined dynamic_lookup may not work with chained fixups
```

It looks like we can't use `dynamic_lookup`. Instead define a list
ourselves of all the symbols we use in the `c_src/appsignal_extension.c`
file. That way we tell the linker to ignore the undefined symbols, and
have them be looked up at runtime when the Elixir NIF library is loaded.
Every time we call another NIF function defined in `erl_nif.h` we need
to update this list.

## ld documentation changes between Xcode versions that broke

Xcode Version 13.4.1 (13F100), from macOS 12.5:

```
$ man ld

     -undefined treatment
             Specifies how undefined symbols are to be treated. Options
             are: error, warning, suppress, or dynamic_lookup.  The
             default is error.
```

New Xcode Version 14.0 (14A309), from macOS 12.6:

```
$ man ld

     -undefined treatment
             Specifies how undefined symbols are to be treated. Options
             are: error, warning, suppress, or dynamic_lookup.  The
             default is error. Note: dynamic_lookup that depends on lazy
             binding will not work with chained fixups.

     -U symbol_name
             Specified that it is ok for symbol_name to have no
             definition.  With -two_levelnamespace, the resulting symbol
             will be marked dynamic_lookup which means dyld will search
             all loaded images.
```

Closes #790

Co-authored-by: Jeff Kreeftmeijer <jeffkreeftmeijer@gmail.com>

Co-authored-by: Jeff Kreeftmeijer <jeffkreeftmeijer@gmail.com>
@tombruijn
Copy link
Member Author

Fixed by PR #792, released in package version 2.2.17.

@tombruijn
Copy link
Member Author

Fixed for real in PR #793. Fix is released in package version 2.2.18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants