-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
macho: allow undefined symbols in dylibs #10314
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.
@@ -1703,6 +1703,16 @@ fn buildOutputType( | |||
} | |||
emit_implib = .{ .yes = linker_args.items[i] }; | |||
emit_implib_arg_provided = true; | |||
} else if (mem.eql(u8, arg, "-undefined")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm, wait, did I make a typo somewhere? It should implement the former, -Wl,"-undefined=dynamic_lookup"
unless I messed something up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍
We now respect both
-fallow-shlib-undefined
and-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-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.You can also check whether the option is on by requesting
--verbose-link
when building a shared object like so:Fixes #3000
cc @jorangreef @ifreund