authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-27 15:33:48+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-27 15:33:48+02:00
logd8d92dafe8763ac18d964bb1a6e88de0b13da152
tree8573e7cdf28d48984f125687b859243bf15da10e
parentae15281c0577694e17a3301fd83d097ed9991bad

zld: search for .a before .dylib by default

Change default behaviour to search for static archives before searching for dynamic libraries if no flag such as `-search_paths_first` is specified. Also, fix a bug with early break from outer loop (label in the wrong place).

1 files changed, 6 insertions(+), 5 deletions(-)

src/link/MachO.zig+6-5
......@@ -759,19 +759,21 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
759759 }
760760 }
761761
762 // Search for static libraries first, then dynamic libraries.
763 // TODO Respect flags such as -search_paths_first to the linker.
762764 // TODO text-based API, or .tbd files.
763 const exts = &[_][]const u8{ "dylib", "a" };
765 const exts = &[_][]const u8{ "a", "dylib" };
764766
765767 for (search_lib_names.items) |l_name| {
766768 var found = false;
767769
768 for (exts) |ext| ext: {
770 ext: for (exts) |ext| {
769771 const l_name_ext = try std.fmt.allocPrint(arena, "lib{s}.{s}", .{ l_name, ext });
770772
771773 for (search_lib_dirs.items) |lib_dir| {
772774 const full_path = try fs.path.join(arena, &[_][]const u8{ lib_dir, l_name_ext });
773775
774 // Check if the dylib file exists.
776 // Check if the lib file exists.
775777 const tmp = fs.cwd().openFile(full_path, .{}) catch |err| switch (err) {
776778 error.FileNotFound => continue,
777779 else => |e| return e,
......@@ -2517,8 +2519,7 @@ fn allocatedSizeLinkedit(self: *MachO, start: u64) u64 {
25172519
25182520 return min_pos - start;
25192521}
2520
2521inline fn checkForCollision(start: u64, end: u64, off: u64, size: u64) ?u64 {
2522fn checkForCollision(start: u64, end: u64, off: u64, size: u64) callconv(.Inline) ?u64 {
25222523 const increased_size = padToIdeal(size);
25232524 const test_end = off + increased_size;
25242525 if (end > off and start < test_end) {