| author | |
| committer | |
| log | 2c41c453b634b3d1f378f6f1b335314f0a4be2de |
| tree | 82ee4addc7157c67a314ff123aa36ab294e2c4af |
| parent | e1e151df0d948be7464b448c61033d4c1d80d86b |
The goal is to minimize as much as possible how much logic is inside
flush(). So let's start by moving out obvious stuff. This data can be
preformatted before flush().10 files changed, 20 insertions(+), 35 deletions(-)
src/link.zig-1| ... | @@ -67,7 +67,6 @@ pub const File = struct { | ... | @@ -67,7 +67,6 @@ pub const File = struct { |
| 67 | gc_sections: bool, | 67 | gc_sections: bool, |
| 68 | print_gc_sections: bool, | 68 | print_gc_sections: bool, |
| 69 | build_id: std.zig.BuildId, | 69 | build_id: std.zig.BuildId, |
| 70 | rpath_list: []const []const u8, | ||
| 71 | allow_shlib_undefined: bool, | 70 | allow_shlib_undefined: bool, |
| 72 | stack_size: u64, | 71 | stack_size: u64, |
| 73 | 72 |
src/link/C.zig-1| ... | @@ -148,7 +148,6 @@ pub fn createEmpty( | ... | @@ -148,7 +148,6 @@ pub fn createEmpty( |
| 148 | .file = file, | 148 | .file = file, |
| 149 | .disable_lld_caching = options.disable_lld_caching, | 149 | .disable_lld_caching = options.disable_lld_caching, |
| 150 | .build_id = options.build_id, | 150 | .build_id = options.build_id, |
| 151 | .rpath_list = options.rpath_list, | ||
| 152 | }, | 151 | }, |
| 153 | }; | 152 | }; |
| 154 | 153 |
src/link/Coff.zig-1| ... | @@ -263,7 +263,6 @@ pub fn createEmpty( | ... | @@ -263,7 +263,6 @@ pub fn createEmpty( |
| 263 | .file = null, | 263 | .file = null, |
| 264 | .disable_lld_caching = options.disable_lld_caching, | 264 | .disable_lld_caching = options.disable_lld_caching, |
| 265 | .build_id = options.build_id, | 265 | .build_id = options.build_id, |
| 266 | .rpath_list = options.rpath_list, | ||
| 267 | }, | 266 | }, |
| 268 | .ptr_width = ptr_width, | 267 | .ptr_width = ptr_width, |
| 269 | .page_size = page_size, | 268 | .page_size = page_size, |
src/link/Elf.zig+13-22| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | base: link.File, | 1 | base: link.File, |
| 2 | rpath_table: std.StringArrayHashMapUnmanaged(void), | ||
| 2 | image_base: u64, | 3 | image_base: u64, |
| 3 | emit_relocs: bool, | 4 | emit_relocs: bool, |
| 4 | z_nodelete: bool, | 5 | z_nodelete: bool, |
| ... | @@ -239,6 +240,11 @@ pub fn createEmpty( | ... | @@ -239,6 +240,11 @@ pub fn createEmpty( |
| 239 | else | 240 | else |
| 240 | try std.fmt.allocPrint(arena, "{s}.o", .{emit.sub_path}); | 241 | try std.fmt.allocPrint(arena, "{s}.o", .{emit.sub_path}); |
| 241 | 242 | ||
| 243 | var rpath_table: std.StringArrayHashMapUnmanaged(void) = .empty; | ||
| 244 | try rpath_table.entries.resize(arena, options.rpath_list.len); | ||
| 245 | @memcpy(rpath_table.entries.items(.key), options.rpath_list); | ||
| 246 | try rpath_table.reIndex(arena); | ||
| 247 | |||
| 242 | const self = try arena.create(Elf); | 248 | const self = try arena.create(Elf); |
| 243 | self.* = .{ | 249 | self.* = .{ |
| 244 | .base = .{ | 250 | .base = .{ |
| ... | @@ -253,8 +259,8 @@ pub fn createEmpty( | ... | @@ -253,8 +259,8 @@ pub fn createEmpty( |
| 253 | .file = null, | 259 | .file = null, |
| 254 | .disable_lld_caching = options.disable_lld_caching, | 260 | .disable_lld_caching = options.disable_lld_caching, |
| 255 | .build_id = options.build_id, | 261 | .build_id = options.build_id, |
| 256 | .rpath_list = options.rpath_list, | ||
| 257 | }, | 262 | }, |
| 263 | .rpath_table = rpath_table, | ||
| 258 | .ptr_width = ptr_width, | 264 | .ptr_width = ptr_width, |
| 259 | .page_size = page_size, | 265 | .page_size = page_size, |
| 260 | .default_sym_version = default_sym_version, | 266 | .default_sym_version = default_sym_version, |
| ... | @@ -829,14 +835,6 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod | ... | @@ -829,14 +835,6 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod |
| 829 | 835 | ||
| 830 | if (module_obj_path) |path| try positionals.append(.{ .path = path }); | 836 | if (module_obj_path) |path| try positionals.append(.{ .path = path }); |
| 831 | 837 | ||
| 832 | // rpaths | ||
| 833 | var rpath_table = std.StringArrayHashMap(void).init(gpa); | ||
| 834 | defer rpath_table.deinit(); | ||
| 835 | |||
| 836 | for (self.base.rpath_list) |rpath| { | ||
| 837 | _ = try rpath_table.put(rpath, {}); | ||
| 838 | } | ||
| 839 | |||
| 840 | if (comp.config.any_sanitize_thread) { | 838 | if (comp.config.any_sanitize_thread) { |
| 841 | try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path }); | 839 | try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path }); |
| 842 | } | 840 | } |
| ... | @@ -1056,7 +1054,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod | ... | @@ -1056,7 +1054,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod |
| 1056 | try self.initSpecialPhdrs(); | 1054 | try self.initSpecialPhdrs(); |
| 1057 | try self.sortShdrs(); | 1055 | try self.sortShdrs(); |
| 1058 | 1056 | ||
| 1059 | try self.setDynamicSection(rpath_table.keys()); | 1057 | try self.setDynamicSection(self.rpath_table.keys()); |
| 1060 | self.sortDynamicSymtab(); | 1058 | self.sortDynamicSymtab(); |
| 1061 | try self.setHashSections(); | 1059 | try self.setHashSections(); |
| 1062 | try self.setVersionSymtab(); | 1060 | try self.setVersionSymtab(); |
| ... | @@ -1207,9 +1205,8 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { | ... | @@ -1207,9 +1205,8 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { |
| 1207 | try argv.appendSlice(&.{ "--entry", name }); | 1205 | try argv.appendSlice(&.{ "--entry", name }); |
| 1208 | } | 1206 | } |
| 1209 | 1207 | ||
| 1210 | for (self.base.rpath_list) |rpath| { | 1208 | for (self.rpath_table.keys()) |rpath| { |
| 1211 | try argv.append("-rpath"); | 1209 | try argv.appendSlice(&.{ "-rpath", rpath }); |
| 1212 | try argv.append(rpath); | ||
| 1213 | } | 1210 | } |
| 1214 | 1211 | ||
| 1215 | try argv.appendSlice(&.{ | 1212 | try argv.appendSlice(&.{ |
| ... | @@ -1978,7 +1975,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s | ... | @@ -1978,7 +1975,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s |
| 1978 | man.hash.add(self.emit_relocs); | 1975 | man.hash.add(self.emit_relocs); |
| 1979 | man.hash.add(comp.config.rdynamic); | 1976 | man.hash.add(comp.config.rdynamic); |
| 1980 | man.hash.addListOfBytes(self.lib_dirs); | 1977 | man.hash.addListOfBytes(self.lib_dirs); |
| 1981 | man.hash.addListOfBytes(self.base.rpath_list); | 1978 | man.hash.addListOfBytes(self.rpath_table.keys()); |
| 1982 | if (output_mode == .Exe) { | 1979 | if (output_mode == .Exe) { |
| 1983 | man.hash.add(self.base.stack_size); | 1980 | man.hash.add(self.base.stack_size); |
| 1984 | man.hash.add(self.base.build_id); | 1981 | man.hash.add(self.base.build_id); |
| ... | @@ -2263,14 +2260,8 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s | ... | @@ -2263,14 +2260,8 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s |
| 2263 | if (csu.crti) |v| try argv.append(v); | 2260 | if (csu.crti) |v| try argv.append(v); |
| 2264 | if (csu.crtbegin) |v| try argv.append(v); | 2261 | if (csu.crtbegin) |v| try argv.append(v); |
| 2265 | 2262 | ||
| 2266 | // rpaths | 2263 | for (self.rpath_table.keys()) |rpath| { |
| 2267 | var rpath_table = std.StringHashMap(void).init(gpa); | 2264 | try argv.appendSlice(&.{ "-rpath", rpath }); |
| 2268 | defer rpath_table.deinit(); | ||
| 2269 | for (self.base.rpath_list) |rpath| { | ||
| 2270 | if ((try rpath_table.fetchPut(rpath, {})) == null) { | ||
| 2271 | try argv.append("-rpath"); | ||
| 2272 | try argv.append(rpath); | ||
| 2273 | } | ||
| 2274 | } | 2265 | } |
| 2275 | 2266 | ||
| 2276 | for (self.symbol_wrap_set.keys()) |symbol_name| { | 2267 | for (self.symbol_wrap_set.keys()) |symbol_name| { |
src/link/MachO.zig+6-5| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | base: link.File, | 1 | base: link.File, |
| 2 | 2 | ||
| 3 | rpath_list: []const []const u8, | ||
| 4 | |||
| 3 | /// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path. | 5 | /// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path. |
| 4 | llvm_object: ?LlvmObject.Ptr = null, | 6 | llvm_object: ?LlvmObject.Ptr = null, |
| 5 | 7 | ||
| ... | @@ -192,8 +194,8 @@ pub fn createEmpty( | ... | @@ -192,8 +194,8 @@ pub fn createEmpty( |
| 192 | .file = null, | 194 | .file = null, |
| 193 | .disable_lld_caching = options.disable_lld_caching, | 195 | .disable_lld_caching = options.disable_lld_caching, |
| 194 | .build_id = options.build_id, | 196 | .build_id = options.build_id, |
| 195 | .rpath_list = options.rpath_list, | ||
| 196 | }, | 197 | }, |
| 198 | .rpath_list = options.rpath_list, | ||
| 197 | .pagezero_size = options.pagezero_size, | 199 | .pagezero_size = options.pagezero_size, |
| 198 | .headerpad_size = options.headerpad_size, | 200 | .headerpad_size = options.headerpad_size, |
| 199 | .headerpad_max_install_names = options.headerpad_max_install_names, | 201 | .headerpad_max_install_names = options.headerpad_max_install_names, |
| ... | @@ -662,9 +664,8 @@ fn dumpArgv(self: *MachO, comp: *Compilation) !void { | ... | @@ -662,9 +664,8 @@ fn dumpArgv(self: *MachO, comp: *Compilation) !void { |
| 662 | try argv.append(syslibroot); | 664 | try argv.append(syslibroot); |
| 663 | } | 665 | } |
| 664 | 666 | ||
| 665 | for (self.base.rpath_list) |rpath| { | 667 | for (self.rpath_list) |rpath| { |
| 666 | try argv.append("-rpath"); | 668 | try argv.appendSlice(&.{ "-rpath", rpath }); |
| 667 | try argv.append(rpath); | ||
| 668 | } | 669 | } |
| 669 | 670 | ||
| 670 | if (self.pagezero_size) |size| { | 671 | if (self.pagezero_size) |size| { |
| ... | @@ -2842,7 +2843,7 @@ fn writeLoadCommands(self: *MachO) !struct { usize, usize, u64 } { | ... | @@ -2842,7 +2843,7 @@ fn writeLoadCommands(self: *MachO) !struct { usize, usize, u64 } { |
| 2842 | ncmds += 1; | 2843 | ncmds += 1; |
| 2843 | } | 2844 | } |
| 2844 | 2845 | ||
| 2845 | for (self.base.rpath_list) |rpath| { | 2846 | for (self.rpath_list) |rpath| { |
| 2846 | try load_commands.writeRpathLC(rpath, writer); | 2847 | try load_commands.writeRpathLC(rpath, writer); |
| 2847 | ncmds += 1; | 2848 | ncmds += 1; |
| 2848 | } | 2849 | } |
src/link/MachO/load_commands.zig+1-1| ... | @@ -63,7 +63,7 @@ pub fn calcLoadCommandsSize(macho_file: *MachO, assume_max_path_len: bool) !u32 | ... | @@ -63,7 +63,7 @@ pub fn calcLoadCommandsSize(macho_file: *MachO, assume_max_path_len: bool) !u32 |
| 63 | } | 63 | } |
| 64 | // LC_RPATH | 64 | // LC_RPATH |
| 65 | { | 65 | { |
| 66 | for (macho_file.base.rpath_list) |rpath| { | 66 | for (macho_file.rpath_list) |rpath| { |
| 67 | sizeofcmds += calcInstallNameLen( | 67 | sizeofcmds += calcInstallNameLen( |
| 68 | @sizeOf(macho.rpath_command), | 68 | @sizeOf(macho.rpath_command), |
| 69 | rpath, | 69 | rpath, |
src/link/NvPtx.zig-1| ... | @@ -60,7 +60,6 @@ pub fn createEmpty( | ... | @@ -60,7 +60,6 @@ pub fn createEmpty( |
| 60 | .file = null, | 60 | .file = null, |
| 61 | .disable_lld_caching = options.disable_lld_caching, | 61 | .disable_lld_caching = options.disable_lld_caching, |
| 62 | .build_id = options.build_id, | 62 | .build_id = options.build_id, |
| 63 | .rpath_list = options.rpath_list, | ||
| 64 | }, | 63 | }, |
| 65 | .llvm_object = llvm_object, | 64 | .llvm_object = llvm_object, |
| 66 | }; | 65 | }; |
src/link/Plan9.zig-1| ... | @@ -304,7 +304,6 @@ pub fn createEmpty( | ... | @@ -304,7 +304,6 @@ pub fn createEmpty( |
| 304 | .file = null, | 304 | .file = null, |
| 305 | .disable_lld_caching = options.disable_lld_caching, | 305 | .disable_lld_caching = options.disable_lld_caching, |
| 306 | .build_id = options.build_id, | 306 | .build_id = options.build_id, |
| 307 | .rpath_list = options.rpath_list, | ||
| 308 | }, | 307 | }, |
| 309 | .sixtyfour_bit = sixtyfour_bit, | 308 | .sixtyfour_bit = sixtyfour_bit, |
| 310 | .bases = undefined, | 309 | .bases = undefined, |
src/link/SpirV.zig-1| ... | @@ -74,7 +74,6 @@ pub fn createEmpty( | ... | @@ -74,7 +74,6 @@ pub fn createEmpty( |
| 74 | .file = null, | 74 | .file = null, |
| 75 | .disable_lld_caching = options.disable_lld_caching, | 75 | .disable_lld_caching = options.disable_lld_caching, |
| 76 | .build_id = options.build_id, | 76 | .build_id = options.build_id, |
| 77 | .rpath_list = options.rpath_list, | ||
| 78 | }, | 77 | }, |
| 79 | .object = codegen.Object.init(gpa), | 78 | .object = codegen.Object.init(gpa), |
| 80 | }; | 79 | }; |
src/link/Wasm.zig-1| ... | @@ -398,7 +398,6 @@ pub fn createEmpty( | ... | @@ -398,7 +398,6 @@ pub fn createEmpty( |
| 398 | .file = null, | 398 | .file = null, |
| 399 | .disable_lld_caching = options.disable_lld_caching, | 399 | .disable_lld_caching = options.disable_lld_caching, |
| 400 | .build_id = options.build_id, | 400 | .build_id = options.build_id, |
| 401 | .rpath_list = options.rpath_list, | ||
| 402 | }, | 401 | }, |
| 403 | .name = undefined, | 402 | .name = undefined, |
| 404 | .import_table = options.import_table, | 403 | .import_table = options.import_table, |