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