| 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 | 67 | gc_sections: bool, |
| 68 | 68 | print_gc_sections: bool, |
| 69 | 69 | build_id: std.zig.BuildId, |
| 70 | rpath_list: []const []const u8, | |
| 71 | 70 | allow_shlib_undefined: bool, |
| 72 | 71 | stack_size: u64, |
| 73 | 72 |
src/link/C.zig-1| ... | ... | @@ -148,7 +148,6 @@ pub fn createEmpty( |
| 148 | 148 | .file = file, |
| 149 | 149 | .disable_lld_caching = options.disable_lld_caching, |
| 150 | 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 | 263 | .file = null, |
| 264 | 264 | .disable_lld_caching = options.disable_lld_caching, |
| 265 | 265 | .build_id = options.build_id, |
| 266 | .rpath_list = options.rpath_list, | |
| 267 | 266 | }, |
| 268 | 267 | .ptr_width = ptr_width, |
| 269 | 268 | .page_size = page_size, |
src/link/Elf.zig+13-22| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | base: link.File, |
| 2 | rpath_table: std.StringArrayHashMapUnmanaged(void), | |
| 2 | 3 | image_base: u64, |
| 3 | 4 | emit_relocs: bool, |
| 4 | 5 | z_nodelete: bool, |
| ... | ... | @@ -239,6 +240,11 @@ pub fn createEmpty( |
| 239 | 240 | else |
| 240 | 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 | 248 | const self = try arena.create(Elf); |
| 243 | 249 | self.* = .{ |
| 244 | 250 | .base = .{ |
| ... | ... | @@ -253,8 +259,8 @@ pub fn createEmpty( |
| 253 | 259 | .file = null, |
| 254 | 260 | .disable_lld_caching = options.disable_lld_caching, |
| 255 | 261 | .build_id = options.build_id, |
| 256 | .rpath_list = options.rpath_list, | |
| 257 | 262 | }, |
| 263 | .rpath_table = rpath_table, | |
| 258 | 264 | .ptr_width = ptr_width, |
| 259 | 265 | .page_size = page_size, |
| 260 | 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 | 835 | |
| 830 | 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 | 838 | if (comp.config.any_sanitize_thread) { |
| 841 | 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 | 1054 | try self.initSpecialPhdrs(); |
| 1057 | 1055 | try self.sortShdrs(); |
| 1058 | 1056 | |
| 1059 | try self.setDynamicSection(rpath_table.keys()); | |
| 1057 | try self.setDynamicSection(self.rpath_table.keys()); | |
| 1060 | 1058 | self.sortDynamicSymtab(); |
| 1061 | 1059 | try self.setHashSections(); |
| 1062 | 1060 | try self.setVersionSymtab(); |
| ... | ... | @@ -1207,9 +1205,8 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { |
| 1207 | 1205 | try argv.appendSlice(&.{ "--entry", name }); |
| 1208 | 1206 | } |
| 1209 | 1207 | |
| 1210 | for (self.base.rpath_list) |rpath| { | |
| 1211 | try argv.append("-rpath"); | |
| 1212 | try argv.append(rpath); | |
| 1208 | for (self.rpath_table.keys()) |rpath| { | |
| 1209 | try argv.appendSlice(&.{ "-rpath", rpath }); | |
| 1213 | 1210 | } |
| 1214 | 1211 | |
| 1215 | 1212 | try argv.appendSlice(&.{ |
| ... | ... | @@ -1978,7 +1975,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s |
| 1978 | 1975 | man.hash.add(self.emit_relocs); |
| 1979 | 1976 | man.hash.add(comp.config.rdynamic); |
| 1980 | 1977 | man.hash.addListOfBytes(self.lib_dirs); |
| 1981 | man.hash.addListOfBytes(self.base.rpath_list); | |
| 1978 | man.hash.addListOfBytes(self.rpath_table.keys()); | |
| 1982 | 1979 | if (output_mode == .Exe) { |
| 1983 | 1980 | man.hash.add(self.base.stack_size); |
| 1984 | 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 | 2260 | if (csu.crti) |v| try argv.append(v); |
| 2264 | 2261 | if (csu.crtbegin) |v| try argv.append(v); |
| 2265 | 2262 | |
| 2266 | // rpaths | |
| 2267 | var rpath_table = std.StringHashMap(void).init(gpa); | |
| 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 | } | |
| 2263 | for (self.rpath_table.keys()) |rpath| { | |
| 2264 | try argv.appendSlice(&.{ "-rpath", rpath }); | |
| 2274 | 2265 | } |
| 2275 | 2266 | |
| 2276 | 2267 | for (self.symbol_wrap_set.keys()) |symbol_name| { |
src/link/MachO.zig+6-5| ... | ... | @@ -1,5 +1,7 @@ |
| 1 | 1 | base: link.File, |
| 2 | 2 | |
| 3 | rpath_list: []const []const u8, | |
| 4 | ||
| 3 | 5 | /// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path. |
| 4 | 6 | llvm_object: ?LlvmObject.Ptr = null, |
| 5 | 7 | |
| ... | ... | @@ -192,8 +194,8 @@ pub fn createEmpty( |
| 192 | 194 | .file = null, |
| 193 | 195 | .disable_lld_caching = options.disable_lld_caching, |
| 194 | 196 | .build_id = options.build_id, |
| 195 | .rpath_list = options.rpath_list, | |
| 196 | 197 | }, |
| 198 | .rpath_list = options.rpath_list, | |
| 197 | 199 | .pagezero_size = options.pagezero_size, |
| 198 | 200 | .headerpad_size = options.headerpad_size, |
| 199 | 201 | .headerpad_max_install_names = options.headerpad_max_install_names, |
| ... | ... | @@ -662,9 +664,8 @@ fn dumpArgv(self: *MachO, comp: *Compilation) !void { |
| 662 | 664 | try argv.append(syslibroot); |
| 663 | 665 | } |
| 664 | 666 | |
| 665 | for (self.base.rpath_list) |rpath| { | |
| 666 | try argv.append("-rpath"); | |
| 667 | try argv.append(rpath); | |
| 667 | for (self.rpath_list) |rpath| { | |
| 668 | try argv.appendSlice(&.{ "-rpath", rpath }); | |
| 668 | 669 | } |
| 669 | 670 | |
| 670 | 671 | if (self.pagezero_size) |size| { |
| ... | ... | @@ -2842,7 +2843,7 @@ fn writeLoadCommands(self: *MachO) !struct { usize, usize, u64 } { |
| 2842 | 2843 | ncmds += 1; |
| 2843 | 2844 | } |
| 2844 | 2845 | |
| 2845 | for (self.base.rpath_list) |rpath| { | |
| 2846 | for (self.rpath_list) |rpath| { | |
| 2846 | 2847 | try load_commands.writeRpathLC(rpath, writer); |
| 2847 | 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 | 63 | } |
| 64 | 64 | // LC_RPATH |
| 65 | 65 | { |
| 66 | for (macho_file.base.rpath_list) |rpath| { | |
| 66 | for (macho_file.rpath_list) |rpath| { | |
| 67 | 67 | sizeofcmds += calcInstallNameLen( |
| 68 | 68 | @sizeOf(macho.rpath_command), |
| 69 | 69 | rpath, |
src/link/NvPtx.zig-1| ... | ... | @@ -60,7 +60,6 @@ pub fn createEmpty( |
| 60 | 60 | .file = null, |
| 61 | 61 | .disable_lld_caching = options.disable_lld_caching, |
| 62 | 62 | .build_id = options.build_id, |
| 63 | .rpath_list = options.rpath_list, | |
| 64 | 63 | }, |
| 65 | 64 | .llvm_object = llvm_object, |
| 66 | 65 | }; |
src/link/Plan9.zig-1| ... | ... | @@ -304,7 +304,6 @@ pub fn createEmpty( |
| 304 | 304 | .file = null, |
| 305 | 305 | .disable_lld_caching = options.disable_lld_caching, |
| 306 | 306 | .build_id = options.build_id, |
| 307 | .rpath_list = options.rpath_list, | |
| 308 | 307 | }, |
| 309 | 308 | .sixtyfour_bit = sixtyfour_bit, |
| 310 | 309 | .bases = undefined, |
src/link/SpirV.zig-1| ... | ... | @@ -74,7 +74,6 @@ pub fn createEmpty( |
| 74 | 74 | .file = null, |
| 75 | 75 | .disable_lld_caching = options.disable_lld_caching, |
| 76 | 76 | .build_id = options.build_id, |
| 77 | .rpath_list = options.rpath_list, | |
| 78 | 77 | }, |
| 79 | 78 | .object = codegen.Object.init(gpa), |
| 80 | 79 | }; |
src/link/Wasm.zig-1| ... | ... | @@ -398,7 +398,6 @@ pub fn createEmpty( |
| 398 | 398 | .file = null, |
| 399 | 399 | .disable_lld_caching = options.disable_lld_caching, |
| 400 | 400 | .build_id = options.build_id, |
| 401 | .rpath_list = options.rpath_list, | |
| 402 | 401 | }, |
| 403 | 402 | .name = undefined, |
| 404 | 403 | .import_table = options.import_table, |