macho: allow undefined symbols in dylibs#10314
Merged
Conversation
We now respect both `-fallow-shlib-undefined` and `-Wl,"-undefined=dynamic_lookup"` flags. This is the first step towards solving issues #8180 and #3000. We currently do not expose any other ld64 equivalent flag for `-undefined` flag - we basically throw an error should the user specify a different flag. Support for those is conditional on closing #8180. As a result of this change, it is now possible to generate a valid native Node.js addon with Zig for macOS.
andrewrk
approved these changes
Dec 11, 2021
| } | ||
| emit_implib = .{ .yes = linker_args.items[i] }; | ||
| emit_implib_arg_provided = true; | ||
| } else if (mem.eql(u8, arg, "-undefined")) { |
Member
There was a problem hiding this comment.
Quick question- you mentioned that this supports -Wl,"-undefined=dynamic_lookup", but it looks like this actually implements -Wl,-undefined,dynamic_lookup. Is this intentional?
Member
Author
There was a problem hiding this comment.
Uhm, wait, did I make a typo somewhere? It should implement the former, -Wl,"-undefined=dynamic_lookup" unless I messed something up.
Member
Author
There was a problem hiding this comment.
Hmm, I think that's what I did. Note that there is another if statement after we match -undefined:
5 } else if (mem.eql(u8, arg, "-undefined")) {
4 i += 1;
3 if (i >= linker_args.items.len) {
2 fatal("expected linker arg after '{s}'", .{arg});
1 }
1711 if (mem.eql(u8, "dynamic_lookup", linker_args.items[i])) {
1 linker_allow_shlib_undefined = true;
2 } else {
3 fatal("unsupported -undefined option '{s}'", .{linker_args.items[i]});
4 }
5 } else {
Member
There was a problem hiding this comment.
Never mind- I forgot that we had this code up there:
// Handle nested-joined args like `-Wl,-rpath=foo`.
// Must be prefixed with 1 or 2 dashes.
if (linker_arg.len >= 3 and linker_arg[0] == '-' and linker_arg[2] != '-') {
if (mem.indexOfScalar(u8, linker_arg, '=')) |equals_pos| {
try linker_args.append(linker_arg[0..equals_pos]);
try linker_args.append(linker_arg[equals_pos + 1 ..]);
continue;
}
}all good 👍
Contributor
messense
added a commit
to messense/maturin
that referenced
this pull request
Feb 23, 2022
messense
added a commit
to rust-cross/cargo-zigbuild
that referenced
this pull request
Feb 23, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We now respect both
-fallow-shlib-undefinedand-Wl,"-undefined=dynamic_lookup"flags. This is the first step towards solving issues #8180. We currently do not expose any other ld64 equivalent flag for-undefinedflag - we basically throw an error should the user specify a different flag. Support for those is conditional on closing #8180. As a result of this change, it is now possible to generate a valid native Node.js addon with Zig for macOS.You can also check whether the option is on by requesting
--verbose-linkwhen building a shared object like so:Fixes #3000
cc @jorangreef @ifreund