| ... | ... | @@ -678,8 +678,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 678 | 678 | zld.stack_size = stack_size; |
| 679 | 679 | |
| 680 | 680 | // Positional arguments to the linker such as object files and static archives. |
| 681 | | var positionals = std.ArrayList([]const u8).init(self.base.allocator); |
| 682 | | defer positionals.deinit(); |
| 681 | var positionals = std.ArrayList([]const u8).init(arena); |
| 683 | 682 | |
| 684 | 683 | try positionals.appendSlice(self.base.options.objects); |
| 685 | 684 | for (comp.c_object_table.items()) |entry| { |
| ... | ... | @@ -696,19 +695,9 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 696 | 695 | try positionals.append(comp.libcxx_static_lib.?.full_object_path); |
| 697 | 696 | } |
| 698 | 697 | |
| 699 | | if (self.base.options.is_native_os) {} |
| 700 | | |
| 701 | 698 | // Shared libraries. |
| 702 | | var shared_libs = std.ArrayList([]const u8).init(self.base.allocator); |
| 703 | | defer { |
| 704 | | for (shared_libs.items) |sh| { |
| 705 | | self.base.allocator.free(sh); |
| 706 | | } |
| 707 | | shared_libs.deinit(); |
| 708 | | } |
| 709 | | |
| 710 | | var search_lib_names = std.ArrayList([]const u8).init(self.base.allocator); |
| 711 | | defer search_lib_names.deinit(); |
| 699 | var shared_libs = std.ArrayList([]const u8).init(arena); |
| 700 | var search_lib_names = std.ArrayList([]const u8).init(arena); |
| 712 | 701 | |
| 713 | 702 | const system_libs = self.base.options.system_libs.items(); |
| 714 | 703 | for (system_libs) |entry| { |
| ... | ... | @@ -717,56 +706,43 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 717 | 706 | // (the check for that needs to be earlier), but they could be full paths to .dylib files, in which |
| 718 | 707 | // case we want to avoid prepending "-l". |
| 719 | 708 | if (Compilation.classifyFileExt(link_lib) == .shared_library) { |
| 720 | | const path = try self.base.allocator.dupe(u8, link_lib); |
| 721 | | try shared_libs.append(path); |
| 709 | try shared_libs.append(link_lib); |
| 722 | 710 | continue; |
| 723 | 711 | } |
| 724 | 712 | |
| 725 | 713 | try search_lib_names.append(link_lib); |
| 726 | 714 | } |
| 727 | 715 | |
| 728 | | for (search_lib_names.items) |l_name| { |
| 729 | | // TODO text-based API, or .tbd files. |
| 730 | | const l_name_ext = try std.fmt.allocPrint(self.base.allocator, "lib{s}.dylib", .{l_name}); |
| 731 | | defer self.base.allocator.free(l_name_ext); |
| 716 | var search_lib_dirs = std.ArrayList([]const u8).init(arena); |
| 717 | try search_lib_dirs.ensureCapacity(self.base.options.lib_dirs.len * 2 + 1); |
| 732 | 718 | |
| 733 | | var found = false; |
| 734 | | if (self.base.options.syslibroot) |syslibroot| { |
| 735 | | for (self.base.options.lib_dirs) |lib_dir| { |
| 736 | | const path = try fs.path.join(self.base.allocator, &[_][]const u8{ |
| 737 | | syslibroot, |
| 738 | | lib_dir, |
| 739 | | l_name_ext, |
| 740 | | }); |
| 741 | | |
| 742 | | const tmp = fs.cwd().openFile(path, .{}) catch |err| switch (err) { |
| 743 | | error.FileNotFound => { |
| 744 | | self.base.allocator.free(path); |
| 745 | | continue; |
| 746 | | }, |
| 747 | | else => |e| return e, |
| 748 | | }; |
| 749 | | defer tmp.close(); |
| 750 | | |
| 751 | | try shared_libs.append(path); |
| 752 | | found = true; |
| 753 | | break; |
| 754 | | } |
| 755 | | } |
| 719 | search_lib_dirs.appendAssumeCapacity("."); // We will always start the search in cwd |
| 756 | 720 | |
| 721 | for (self.base.options.lib_dirs) |lib_dir| { |
| 722 | search_lib_dirs.appendAssumeCapacity(lib_dir); |
| 723 | } |
| 724 | |
| 725 | if (self.base.options.syslibroot) |syslibroot| { |
| 757 | 726 | for (self.base.options.lib_dirs) |lib_dir| { |
| 758 | | const path = try fs.path.join(self.base.allocator, &[_][]const u8{ lib_dir, l_name_ext }); |
| 727 | const path = try fs.path.join(arena, &[_][]const u8{ syslibroot, lib_dir }); |
| 728 | search_lib_dirs.appendAssumeCapacity(path); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | for (search_lib_names.items) |l_name| { |
| 733 | // TODO text-based API, or .tbd files. |
| 734 | const l_name_ext = try std.fmt.allocPrint(arena, "lib{s}.dylib", .{l_name}); |
| 759 | 735 | |
| 760 | | const tmp = fs.cwd().openFile(path, .{}) catch |err| switch (err) { |
| 761 | | error.FileNotFound => { |
| 762 | | self.base.allocator.free(path); |
| 763 | | continue; |
| 764 | | }, |
| 736 | var found = false; |
| 737 | for (search_lib_dirs.items) |lib_dir| { |
| 738 | const full_path = try fs.path.join(arena, &[_][]const u8{ lib_dir, l_name_ext }); |
| 739 | const tmp = fs.cwd().openFile(full_path, .{}) catch |err| switch (err) { |
| 740 | error.FileNotFound => continue, |
| 765 | 741 | else => |e| return e, |
| 766 | 742 | }; |
| 767 | 743 | defer tmp.close(); |
| 768 | 744 | |
| 769 | | try shared_libs.append(path); |
| 745 | try shared_libs.append(full_path); |
| 770 | 746 | found = true; |
| 771 | 747 | break; |
| 772 | 748 | } |
| ... | ... | @@ -774,20 +750,14 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 774 | 750 | if (!found) { |
| 775 | 751 | log.warn("library '-l{s}' not found", .{l_name}); |
| 776 | 752 | log.warn("searched paths:", .{}); |
| 777 | | if (self.base.options.syslibroot) |syslibroot| { |
| 778 | | for (self.base.options.lib_dirs) |lib_dir| { |
| 779 | | log.warn(" {s}/{s}", .{ syslibroot, lib_dir }); |
| 780 | | } |
| 781 | | } |
| 782 | | for (self.base.options.lib_dirs) |lib_dir| { |
| 783 | | log.warn(" {s}/", .{lib_dir}); |
| 753 | for (search_lib_dirs.items) |lib_dir| { |
| 754 | log.warn(" {s}", .{lib_dir}); |
| 784 | 755 | } |
| 785 | 756 | } |
| 786 | 757 | } |
| 787 | 758 | |
| 788 | 759 | if (self.base.options.verbose_link) { |
| 789 | | var argv = std.ArrayList([]const u8).init(self.base.allocator); |
| 790 | | defer argv.deinit(); |
| 760 | var argv = std.ArrayList([]const u8).init(arena); |
| 791 | 761 | |
| 792 | 762 | try argv.append("zig"); |
| 793 | 763 | try argv.append("ld"); |
| ... | ... | @@ -803,11 +773,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 803 | 773 | try argv.append(full_out_path); |
| 804 | 774 | |
| 805 | 775 | for (search_lib_names.items) |l_name| { |
| 806 | | try argv.append(try std.fmt.allocPrint(self.base.allocator, "-l{s}", .{l_name})); |
| 776 | try argv.append(try std.fmt.allocPrint(arena, "-l{s}", .{l_name})); |
| 807 | 777 | } |
| 808 | 778 | |
| 809 | 779 | for (self.base.options.lib_dirs) |lib_dir| { |
| 810 | | try argv.append(try std.fmt.allocPrint(self.base.allocator, "-L{s}", .{lib_dir})); |
| 780 | try argv.append(try std.fmt.allocPrint(arena, "-L{s}", .{lib_dir})); |
| 811 | 781 | } |
| 812 | 782 | |
| 813 | 783 | Compilation.dump_argv(argv.items); |