| ... | ... | @@ -875,18 +875,13 @@ pub fn parseInputFiles(self: *MachO) !void { |
| 875 | 875 | defer tracy.end(); |
| 876 | 876 | |
| 877 | 877 | const diags = &self.base.comp.link_diags; |
| 878 | | const tp = self.base.comp.thread_pool; |
| 879 | | var wg: WaitGroup = .{}; |
| 880 | 878 | |
| 881 | 879 | { |
| 882 | | wg.reset(); |
| 883 | | defer wg.wait(); |
| 884 | | |
| 885 | 880 | for (self.objects.items) |index| { |
| 886 | | tp.spawnWg(&wg, parseInputFileWorker, .{ self, self.getFile(index).? }); |
| 881 | parseInputFileWorker(self, self.getFile(index).?); |
| 887 | 882 | } |
| 888 | 883 | for (self.dylibs.items) |index| { |
| 889 | | tp.spawnWg(&wg, parseInputFileWorker, .{ self, self.getFile(index).? }); |
| 884 | parseInputFileWorker(self, self.getFile(index).?); |
| 890 | 885 | } |
| 891 | 886 | } |
| 892 | 887 | |
| ... | ... | @@ -1269,17 +1264,13 @@ fn markLive(self: *MachO) void { |
| 1269 | 1264 | } |
| 1270 | 1265 | |
| 1271 | 1266 | fn convertTentativeDefsAndResolveSpecialSymbols(self: *MachO) !void { |
| 1272 | | const tp = self.base.comp.thread_pool; |
| 1273 | 1267 | const diags = &self.base.comp.link_diags; |
| 1274 | | var wg: WaitGroup = .{}; |
| 1275 | 1268 | { |
| 1276 | | wg.reset(); |
| 1277 | | defer wg.wait(); |
| 1278 | 1269 | for (self.objects.items) |index| { |
| 1279 | | tp.spawnWg(&wg, convertTentativeDefinitionsWorker, .{ self, self.getFile(index).?.object }); |
| 1270 | convertTentativeDefinitionsWorker(self, self.getFile(index).?.object); |
| 1280 | 1271 | } |
| 1281 | 1272 | if (self.getInternalObject()) |obj| { |
| 1282 | | tp.spawnWg(&wg, resolveSpecialSymbolsWorker, .{ self, obj }); |
| 1273 | resolveSpecialSymbolsWorker(self, obj); |
| 1283 | 1274 | } |
| 1284 | 1275 | } |
| 1285 | 1276 | if (diags.hasErrors()) return error.LinkFailure; |
| ... | ... | @@ -1327,19 +1318,15 @@ pub fn dedupLiterals(self: *MachO) !void { |
| 1327 | 1318 | try object.resolveLiterals(&lp, self); |
| 1328 | 1319 | } |
| 1329 | 1320 | |
| 1330 | | const tp = self.base.comp.thread_pool; |
| 1331 | | var wg: WaitGroup = .{}; |
| 1332 | 1321 | { |
| 1333 | | wg.reset(); |
| 1334 | | defer wg.wait(); |
| 1335 | 1322 | if (self.getZigObject()) |zo| { |
| 1336 | | tp.spawnWg(&wg, File.dedupLiterals, .{ zo.asFile(), lp, self }); |
| 1323 | File.dedupLiterals(zo.asFile(), lp, self); |
| 1337 | 1324 | } |
| 1338 | 1325 | for (self.objects.items) |index| { |
| 1339 | | tp.spawnWg(&wg, File.dedupLiterals, .{ self.getFile(index).?, lp, self }); |
| 1326 | File.dedupLiterals(self.getFile(index).?, lp, self); |
| 1340 | 1327 | } |
| 1341 | 1328 | if (self.getInternalObject()) |object| { |
| 1342 | | tp.spawnWg(&wg, File.dedupLiterals, .{ object.asFile(), lp, self }); |
| 1329 | File.dedupLiterals(object.asFile(), lp, self); |
| 1343 | 1330 | } |
| 1344 | 1331 | } |
| 1345 | 1332 | } |
| ... | ... | @@ -1357,21 +1344,17 @@ fn checkDuplicates(self: *MachO) !void { |
| 1357 | 1344 | const tracy = trace(@src()); |
| 1358 | 1345 | defer tracy.end(); |
| 1359 | 1346 | |
| 1360 | | const tp = self.base.comp.thread_pool; |
| 1361 | 1347 | const diags = &self.base.comp.link_diags; |
| 1362 | 1348 | |
| 1363 | | var wg: WaitGroup = .{}; |
| 1364 | 1349 | { |
| 1365 | | wg.reset(); |
| 1366 | | defer wg.wait(); |
| 1367 | 1350 | if (self.getZigObject()) |zo| { |
| 1368 | | tp.spawnWg(&wg, checkDuplicatesWorker, .{ self, zo.asFile() }); |
| 1351 | checkDuplicatesWorker(self, zo.asFile()); |
| 1369 | 1352 | } |
| 1370 | 1353 | for (self.objects.items) |index| { |
| 1371 | | tp.spawnWg(&wg, checkDuplicatesWorker, .{ self, self.getFile(index).? }); |
| 1354 | checkDuplicatesWorker(self, self.getFile(index).?); |
| 1372 | 1355 | } |
| 1373 | 1356 | if (self.getInternalObject()) |obj| { |
| 1374 | | tp.spawnWg(&wg, checkDuplicatesWorker, .{ self, obj.asFile() }); |
| 1357 | checkDuplicatesWorker(self, obj.asFile()); |
| 1375 | 1358 | } |
| 1376 | 1359 | } |
| 1377 | 1360 | |
| ... | ... | @@ -1428,23 +1411,17 @@ fn scanRelocs(self: *MachO) !void { |
| 1428 | 1411 | const tracy = trace(@src()); |
| 1429 | 1412 | defer tracy.end(); |
| 1430 | 1413 | |
| 1431 | | const tp = self.base.comp.thread_pool; |
| 1432 | 1414 | const diags = &self.base.comp.link_diags; |
| 1433 | 1415 | |
| 1434 | | var wg: WaitGroup = .{}; |
| 1435 | | |
| 1436 | 1416 | { |
| 1437 | | wg.reset(); |
| 1438 | | defer wg.wait(); |
| 1439 | | |
| 1440 | 1417 | if (self.getZigObject()) |zo| { |
| 1441 | | tp.spawnWg(&wg, scanRelocsWorker, .{ self, zo.asFile() }); |
| 1418 | scanRelocsWorker(self, zo.asFile()); |
| 1442 | 1419 | } |
| 1443 | 1420 | for (self.objects.items) |index| { |
| 1444 | | tp.spawnWg(&wg, scanRelocsWorker, .{ self, self.getFile(index).? }); |
| 1421 | scanRelocsWorker(self, self.getFile(index).?); |
| 1445 | 1422 | } |
| 1446 | 1423 | if (self.getInternalObject()) |obj| { |
| 1447 | | tp.spawnWg(&wg, scanRelocsWorker, .{ self, obj.asFile() }); |
| 1424 | scanRelocsWorker(self, obj.asFile()); |
| 1448 | 1425 | } |
| 1449 | 1426 | } |
| 1450 | 1427 | |
| ... | ... | @@ -1888,38 +1865,34 @@ fn calcSectionSizes(self: *MachO) !void { |
| 1888 | 1865 | header.@"align" = 3; |
| 1889 | 1866 | } |
| 1890 | 1867 | |
| 1891 | | const tp = self.base.comp.thread_pool; |
| 1892 | | var wg: WaitGroup = .{}; |
| 1893 | 1868 | { |
| 1894 | | wg.reset(); |
| 1895 | | defer wg.wait(); |
| 1896 | 1869 | const slice = self.sections.slice(); |
| 1897 | 1870 | for (slice.items(.header), slice.items(.atoms), 0..) |header, atoms, i| { |
| 1898 | 1871 | if (atoms.items.len == 0) continue; |
| 1899 | 1872 | if (self.requiresThunks() and header.isCode()) continue; |
| 1900 | | tp.spawnWg(&wg, calcSectionSizeWorker, .{ self, @as(u8, @intCast(i)) }); |
| 1873 | calcSectionSizeWorker(self, @as(u8, @intCast(i))); |
| 1901 | 1874 | } |
| 1902 | 1875 | |
| 1903 | 1876 | if (self.requiresThunks()) { |
| 1904 | 1877 | for (slice.items(.header), slice.items(.atoms), 0..) |header, atoms, i| { |
| 1905 | 1878 | if (!header.isCode()) continue; |
| 1906 | 1879 | if (atoms.items.len == 0) continue; |
| 1907 | | tp.spawnWg(&wg, createThunksWorker, .{ self, @as(u8, @intCast(i)) }); |
| 1880 | createThunksWorker(self, @as(u8, @intCast(i))); |
| 1908 | 1881 | } |
| 1909 | 1882 | } |
| 1910 | 1883 | |
| 1911 | 1884 | // At this point, we can also calculate most of the symtab and data-in-code linkedit section sizes |
| 1912 | 1885 | if (self.getZigObject()) |zo| { |
| 1913 | | tp.spawnWg(&wg, File.calcSymtabSize, .{ zo.asFile(), self }); |
| 1886 | File.calcSymtabSize(zo.asFile(), self); |
| 1914 | 1887 | } |
| 1915 | 1888 | for (self.objects.items) |index| { |
| 1916 | | tp.spawnWg(&wg, File.calcSymtabSize, .{ self.getFile(index).?, self }); |
| 1889 | File.calcSymtabSize(self.getFile(index).?, self); |
| 1917 | 1890 | } |
| 1918 | 1891 | for (self.dylibs.items) |index| { |
| 1919 | | tp.spawnWg(&wg, File.calcSymtabSize, .{ self.getFile(index).?, self }); |
| 1892 | File.calcSymtabSize(self.getFile(index).?, self); |
| 1920 | 1893 | } |
| 1921 | 1894 | if (self.getInternalObject()) |obj| { |
| 1922 | | tp.spawnWg(&wg, File.calcSymtabSize, .{ obj.asFile(), self }); |
| 1895 | File.calcSymtabSize(obj.asFile(), self); |
| 1923 | 1896 | } |
| 1924 | 1897 | } |
| 1925 | 1898 | |
| ... | ... | @@ -2403,23 +2376,18 @@ fn writeSectionsAndUpdateLinkeditSizes(self: *MachO) !void { |
| 2403 | 2376 | try self.strtab.resize(gpa, cmd.strsize); |
| 2404 | 2377 | self.strtab.items[0] = 0; |
| 2405 | 2378 | |
| 2406 | | const tp = self.base.comp.thread_pool; |
| 2407 | | var wg: WaitGroup = .{}; |
| 2408 | 2379 | { |
| 2409 | | wg.reset(); |
| 2410 | | defer wg.wait(); |
| 2411 | | |
| 2412 | 2380 | for (self.objects.items) |index| { |
| 2413 | | tp.spawnWg(&wg, writeAtomsWorker, .{ self, self.getFile(index).? }); |
| 2381 | writeAtomsWorker(self, self.getFile(index).?); |
| 2414 | 2382 | } |
| 2415 | 2383 | if (self.getZigObject()) |zo| { |
| 2416 | | tp.spawnWg(&wg, writeAtomsWorker, .{ self, zo.asFile() }); |
| 2384 | writeAtomsWorker(self, zo.asFile()); |
| 2417 | 2385 | } |
| 2418 | 2386 | if (self.getInternalObject()) |obj| { |
| 2419 | | tp.spawnWg(&wg, writeAtomsWorker, .{ self, obj.asFile() }); |
| 2387 | writeAtomsWorker(self, obj.asFile()); |
| 2420 | 2388 | } |
| 2421 | 2389 | for (self.thunks.items) |thunk| { |
| 2422 | | tp.spawnWg(&wg, writeThunkWorker, .{ self, thunk }); |
| 2390 | writeThunkWorker(self, thunk); |
| 2423 | 2391 | } |
| 2424 | 2392 | |
| 2425 | 2393 | const slice = self.sections.slice(); |
| ... | ... | @@ -2434,34 +2402,34 @@ fn writeSectionsAndUpdateLinkeditSizes(self: *MachO) !void { |
| 2434 | 2402 | }) |maybe_sect_id| { |
| 2435 | 2403 | if (maybe_sect_id) |sect_id| { |
| 2436 | 2404 | const out = slice.items(.out)[sect_id].items; |
| 2437 | | tp.spawnWg(&wg, writeSyntheticSectionWorker, .{ self, sect_id, out }); |
| 2405 | writeSyntheticSectionWorker(self, sect_id, out); |
| 2438 | 2406 | } |
| 2439 | 2407 | } |
| 2440 | 2408 | |
| 2441 | 2409 | if (self.la_symbol_ptr_sect_index) |_| { |
| 2442 | | tp.spawnWg(&wg, updateLazyBindSizeWorker, .{self}); |
| 2410 | updateLazyBindSizeWorker(self); |
| 2443 | 2411 | } |
| 2444 | 2412 | |
| 2445 | | tp.spawnWg(&wg, updateLinkeditSizeWorker, .{ self, .rebase }); |
| 2446 | | tp.spawnWg(&wg, updateLinkeditSizeWorker, .{ self, .bind }); |
| 2447 | | tp.spawnWg(&wg, updateLinkeditSizeWorker, .{ self, .weak_bind }); |
| 2448 | | tp.spawnWg(&wg, updateLinkeditSizeWorker, .{ self, .export_trie }); |
| 2449 | | tp.spawnWg(&wg, updateLinkeditSizeWorker, .{ self, .data_in_code }); |
| 2413 | updateLinkeditSizeWorker(self, .rebase); |
| 2414 | updateLinkeditSizeWorker(self, .bind); |
| 2415 | updateLinkeditSizeWorker(self, .weak_bind); |
| 2416 | updateLinkeditSizeWorker(self, .export_trie); |
| 2417 | updateLinkeditSizeWorker(self, .data_in_code); |
| 2450 | 2418 | |
| 2451 | 2419 | if (self.getZigObject()) |zo| { |
| 2452 | | tp.spawnWg(&wg, File.writeSymtab, .{ zo.asFile(), self, self }); |
| 2420 | File.writeSymtab(zo.asFile(), self, self); |
| 2453 | 2421 | } |
| 2454 | 2422 | for (self.objects.items) |index| { |
| 2455 | | tp.spawnWg(&wg, File.writeSymtab, .{ self.getFile(index).?, self, self }); |
| 2423 | File.writeSymtab(self.getFile(index).?, self, self); |
| 2456 | 2424 | } |
| 2457 | 2425 | for (self.dylibs.items) |index| { |
| 2458 | | tp.spawnWg(&wg, File.writeSymtab, .{ self.getFile(index).?, self, self }); |
| 2426 | File.writeSymtab(self.getFile(index).?, self, self); |
| 2459 | 2427 | } |
| 2460 | 2428 | if (self.getInternalObject()) |obj| { |
| 2461 | | tp.spawnWg(&wg, File.writeSymtab, .{ obj.asFile(), self, self }); |
| 2429 | File.writeSymtab(obj.asFile(), self, self); |
| 2462 | 2430 | } |
| 2463 | 2431 | if (self.requiresThunks()) for (self.thunks.items) |th| { |
| 2464 | | tp.spawnWg(&wg, Thunk.writeSymtab, .{ th, self, self }); |
| 2432 | Thunk.writeSymtab(th, self, self); |
| 2465 | 2433 | }; |
| 2466 | 2434 | } |
| 2467 | 2435 | |
| ... | ... | @@ -5370,7 +5338,6 @@ const Thunk = @import("MachO/Thunk.zig"); |
| 5370 | 5338 | const TlvPtrSection = synthetic.TlvPtrSection; |
| 5371 | 5339 | const Value = @import("../Value.zig"); |
| 5372 | 5340 | const UnwindInfo = @import("MachO/UnwindInfo.zig"); |
| 5373 | | const WaitGroup = std.Thread.WaitGroup; |
| 5374 | 5341 | const WeakBind = bind.WeakBind; |
| 5375 | 5342 | const ZigObject = @import("MachO/ZigObject.zig"); |
| 5376 | 5343 | const dev = @import("../dev.zig"); |