aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-06-25 17:55:26 +0200
committerGitHub <noreply@github.com>2022-06-25 17:55:26 +0200
commit0078d36ff39f2ef35e32f2d58e5d447b62f3a37e (patch)
tree37793e2032189f83915a829dac0bd425264b488e /src/main.zig
parent905a18849f7f2c3f269fbf425170e0c86b12524a (diff)
parent8f00bc9d231c0c686b2ffa3bd0b14181afa7a171 (diff)
downloadzig-0078d36ff39f2ef35e32f2d58e5d447b62f3a37e.tar.gz
zig-0078d36ff39f2ef35e32f2d58e5d447b62f3a37e.zip
Merge pull request #11917 from motiejus/wl-search-paths
macho: implement `-search_paths_first` and `-search_dylibs_first`
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index 6942d0ba49..3d65875975 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -448,6 +448,8 @@ const usage_build_generic =
\\ -install_name=[value] (Darwin) add dylib's install name
\\ --entitlements [path] (Darwin) add path to entitlements file for embedding in code signature
\\ -pagezero_size [value] (Darwin) size of the __PAGEZERO segment in hexadecimal notation
+ \\ -search_paths_first (Darwin) search each dir in library search paths for `libx.dylib` then `libx.a`
+ \\ -search_dylibs_first (Darwin) search `libx.dylib` in each dir in library search paths, then `libx.a`
\\ --import-memory (WebAssembly) import memory from the environment
\\ --import-table (WebAssembly) import function table from the host environment
\\ --export-table (WebAssembly) export function table to the host environment
@@ -696,6 +698,7 @@ fn buildOutputType(
var hash_style: link.HashStyle = .both;
var entitlements: ?[]const u8 = null;
var pagezero_size: ?u64 = null;
+ var search_strategy: ?link.File.MachO.SearchStrategy = null;
// e.g. -m3dnow or -mno-outline-atomics. They correspond to std.Target llvm cpu feature names.
// This array is populated by zig cc frontend and then has to be converted to zig-style
@@ -917,6 +920,10 @@ fn buildOutputType(
pagezero_size = std.fmt.parseUnsigned(u64, eatIntPrefix(next_arg, 16), 16) catch |err| {
fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
};
+ } else if (mem.eql(u8, arg, "-search_paths_first")) {
+ search_strategy = .paths_first;
+ } else if (mem.eql(u8, arg, "-search_dylibs_first")) {
+ search_strategy = .dylibs_first;
} else if (mem.eql(u8, arg, "-T") or mem.eql(u8, arg, "--script")) {
linker_script = args_iter.next() orelse {
fatal("expected parameter after {s}", .{arg});
@@ -1475,6 +1482,10 @@ fn buildOutputType(
mem.eql(u8, linker_arg, "-static"))
{
force_static_libs = true;
+ } else if (mem.eql(u8, linker_arg, "-search_paths_first")) {
+ search_strategy = .paths_first;
+ } else if (mem.eql(u8, linker_arg, "-search_dylibs_first")) {
+ search_strategy = .dylibs_first;
} else {
try linker_args.append(linker_arg);
}
@@ -2141,6 +2152,7 @@ fn buildOutputType(
}
for (lib_dirs.items) |lib_dir_path| {
+ if (cross_target.isDarwin()) break; // Targeting Darwin we let the linker resolve the libraries in the correct order
test_path.clearRetainingCapacity();
try test_path.writer().print("{s}" ++ sep ++ "{s}{s}{s}", .{
lib_dir_path,
@@ -2782,6 +2794,7 @@ fn buildOutputType(
.install_name = install_name,
.entitlements = entitlements,
.pagezero_size = pagezero_size,
+ .search_strategy = search_strategy,
}) catch |err| switch (err) {
error.LibCUnavailable => {
const target = target_info.target;