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

Explicitly define used NIF symbols #792

Merged
merged 1 commit into from
Sep 15, 2022
Merged

Conversation

tombruijn
Copy link
Member

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

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 jeffkreeftmeijer merged commit 910ad1d into main Sep 15, 2022
tombruijn added a commit that referenced this pull request Sep 15, 2022
We made a mistake in PR #792. We split up the very long line in the
Makefile to specify a symbol per line. This accidentally broke how the
linker interprets these options.

Specify the symbols per line, but on each line also include the `-Wl,`
prefix to specify the liker option. Somehow the multi line option value
for `-Wl,` didn't work.
tombruijn added a commit that referenced this pull request Sep 15, 2022
We made a mistake in PR #792. We split up the very long line in the
Makefile to specify a symbol per line. This accidentally broke how the
linker interprets these options.

Specify the symbols per line, but on each line also include the `-Wl,`
prefix to specify the liker option. Somehow the multi line option value
for `-Wl,` didn't work.
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 this pull request may close these issues.

Extension linking doesn't work with Xcode 14 (macOS 12.6)
4 participants