| ... | @@ -236,31 +236,32 @@ pub fn createEmpty( | ... | @@ -236,31 +236,32 @@ pub fn createEmpty( |
| 236 | try self.getZigObject().?.init(self); | 236 | try self.getZigObject().?.init(self); |
| 237 | | 237 | |
| 238 | // TODO init metadata | 238 | // TODO init metadata |
| | 239 | // TODO init dwarf |
| 239 | | 240 | |
| 240 | if (comp.config.debug_format != .strip) { | 241 | // if (comp.config.debug_format != .strip) { |
| 241 | // Create dSYM bundle. | 242 | // // Create dSYM bundle. |
| 242 | log.debug("creating {s}.dSYM bundle", .{emit.sub_path}); | 243 | // log.debug("creating {s}.dSYM bundle", .{emit.sub_path}); |
| 243 | | 244 | |
| 244 | const d_sym_path = try std.fmt.allocPrint( | 245 | // const d_sym_path = try std.fmt.allocPrint( |
| 245 | arena, | 246 | // arena, |
| 246 | "{s}.dSYM" ++ fs.path.sep_str ++ "Contents" ++ fs.path.sep_str ++ "Resources" ++ fs.path.sep_str ++ "DWARF", | 247 | // "{s}.dSYM" ++ fs.path.sep_str ++ "Contents" ++ fs.path.sep_str ++ "Resources" ++ fs.path.sep_str ++ "DWARF", |
| 247 | .{emit.sub_path}, | 248 | // .{emit.sub_path}, |
| 248 | ); | 249 | // ); |
| 249 | | 250 | |
| 250 | var d_sym_bundle = try emit.directory.handle.makeOpenPath(d_sym_path, .{}); | 251 | // var d_sym_bundle = try emit.directory.handle.makeOpenPath(d_sym_path, .{}); |
| 251 | defer d_sym_bundle.close(); | 252 | // defer d_sym_bundle.close(); |
| 252 | | 253 | |
| 253 | const d_sym_file = try d_sym_bundle.createFile(emit.sub_path, .{ | 254 | // const d_sym_file = try d_sym_bundle.createFile(emit.sub_path, .{ |
| 254 | .truncate = false, | 255 | // .truncate = false, |
| 255 | .read = true, | 256 | // .read = true, |
| 256 | }); | 257 | // }); |
| 257 | | 258 | |
| 258 | self.d_sym = .{ | 259 | // self.d_sym = .{ |
| 259 | .allocator = gpa, | 260 | // .allocator = gpa, |
| 260 | .dwarf = link.File.Dwarf.init(&self.base, .dwarf32), | 261 | // .dwarf = link.File.Dwarf.init(&self.base, .dwarf32), |
| 261 | .file = d_sym_file, | 262 | // .file = d_sym_file, |
| 262 | }; | 263 | // }; |
| 263 | } | 264 | // } |
| 264 | } | 265 | } |
| 265 | } | 266 | } |
| 266 | | 267 | |
| ... | @@ -379,6 +380,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node | ... | @@ -379,6 +380,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node |
| 379 | // --verbose-link | 380 | // --verbose-link |
| 380 | if (comp.verbose_link) try self.dumpArgv(comp); | 381 | if (comp.verbose_link) try self.dumpArgv(comp); |
| 381 | | 382 | |
| | 383 | if (self.getZigObject()) |zo| try zo.flushModule(self); |
| 382 | if (self.base.isStaticLib()) return self.flushStaticLib(comp, module_obj_path); | 384 | if (self.base.isStaticLib()) return self.flushStaticLib(comp, module_obj_path); |
| 383 | if (self.base.isObject()) return relocatable.flush(self, comp, module_obj_path); | 385 | if (self.base.isObject()) return relocatable.flush(self, comp, module_obj_path); |
| 384 | | 386 | |
| ... | @@ -1311,6 +1313,8 @@ pub fn resolveSymbols(self: *MachO) !void { | ... | @@ -1311,6 +1313,8 @@ pub fn resolveSymbols(self: *MachO) !void { |
| 1311 | const tracy = trace(@src()); | 1313 | const tracy = trace(@src()); |
| 1312 | defer tracy.end(); | 1314 | defer tracy.end(); |
| 1313 | | 1315 | |
| | 1316 | // Resolve symbols in the ZigObject. For now, we assume that it's always live. |
| | 1317 | if (self.getZigObject()) |zo| zo.asFile().resolveSymbols(self); |
| 1314 | // Resolve symbols on the set of all objects and shared objects (even if some are unneeded). | 1318 | // Resolve symbols on the set of all objects and shared objects (even if some are unneeded). |
| 1315 | for (self.objects.items) |index| self.getFile(index).?.resolveSymbols(self); | 1319 | for (self.objects.items) |index| self.getFile(index).?.resolveSymbols(self); |
| 1316 | for (self.dylibs.items) |index| self.getFile(index).?.resolveSymbols(self); | 1320 | for (self.dylibs.items) |index| self.getFile(index).?.resolveSymbols(self); |
| ... | @@ -1319,6 +1323,7 @@ pub fn resolveSymbols(self: *MachO) !void { | ... | @@ -1319,6 +1323,7 @@ pub fn resolveSymbols(self: *MachO) !void { |
| 1319 | self.markLive(); | 1323 | self.markLive(); |
| 1320 | | 1324 | |
| 1321 | // Reset state of all globals after marking live objects. | 1325 | // Reset state of all globals after marking live objects. |
| | 1326 | if (self.getZigObject()) |zo| zo.asFile().resetGlobals(self); |
| 1322 | for (self.objects.items) |index| self.getFile(index).?.resetGlobals(self); | 1327 | for (self.objects.items) |index| self.getFile(index).?.resetGlobals(self); |
| 1323 | for (self.dylibs.items) |index| self.getFile(index).?.resetGlobals(self); | 1328 | for (self.dylibs.items) |index| self.getFile(index).?.resetGlobals(self); |
| 1324 | | 1329 | |
| ... | @@ -1332,6 +1337,7 @@ pub fn resolveSymbols(self: *MachO) !void { | ... | @@ -1332,6 +1337,7 @@ pub fn resolveSymbols(self: *MachO) !void { |
| 1332 | } | 1337 | } |
| 1333 | | 1338 | |
| 1334 | // Re-resolve the symbols. | 1339 | // Re-resolve the symbols. |
| | 1340 | if (self.getZigObject()) |zo| zo.resolveSymbols(self); |
| 1335 | for (self.objects.items) |index| self.getFile(index).?.resolveSymbols(self); | 1341 | for (self.objects.items) |index| self.getFile(index).?.resolveSymbols(self); |
| 1336 | for (self.dylibs.items) |index| self.getFile(index).?.resolveSymbols(self); | 1342 | for (self.dylibs.items) |index| self.getFile(index).?.resolveSymbols(self); |
| 1337 | } | 1343 | } |
| ... | @@ -1351,6 +1357,7 @@ fn markLive(self: *MachO) void { | ... | @@ -1351,6 +1357,7 @@ fn markLive(self: *MachO) void { |
| 1351 | if (file == .object) file.object.alive = true; | 1357 | if (file == .object) file.object.alive = true; |
| 1352 | } | 1358 | } |
| 1353 | } | 1359 | } |
| | 1360 | if (self.getZigObject()) |zo| zo.markLive(self); |
| 1354 | for (self.objects.items) |index| { | 1361 | for (self.objects.items) |index| { |
| 1355 | const object = self.getFile(index).?.object; | 1362 | const object = self.getFile(index).?.object; |
| 1356 | if (object.alive) object.markLive(self); | 1363 | if (object.alive) object.markLive(self); |
| ... | @@ -1449,12 +1456,23 @@ fn createObjcSections(self: *MachO) !void { | ... | @@ -1449,12 +1456,23 @@ fn createObjcSections(self: *MachO) !void { |
| 1449 | } | 1456 | } |
| 1450 | | 1457 | |
| 1451 | fn claimUnresolved(self: *MachO) error{OutOfMemory}!void { | 1458 | fn claimUnresolved(self: *MachO) error{OutOfMemory}!void { |
| 1452 | for (self.objects.items) |index| { | 1459 | const gpa = self.base.comp.gpa; |
| 1453 | const object = self.getFile(index).?.object; | | |
| 1454 | | 1460 | |
| 1455 | for (object.symbols.items, 0..) |sym_index, i| { | 1461 | var objects = try std.ArrayList(File.Index).initCapacity(gpa, self.objects.items.len + 1); |
| | 1462 | defer objects.deinit(); |
| | 1463 | if (self.getZigObject()) |zo| objects.appendAssumeCapacity(zo.index); |
| | 1464 | objects.appendSliceAssumeCapacity(self.objects.items); |
| | 1465 | |
| | 1466 | for (objects.items) |index| { |
| | 1467 | const file = self.getFile(index).?; |
| | 1468 | |
| | 1469 | for (file.getSymbols(), 0..) |sym_index, i| { |
| 1456 | const nlist_idx = @as(Symbol.Index, @intCast(i)); | 1470 | const nlist_idx = @as(Symbol.Index, @intCast(i)); |
| 1457 | const nlist = object.symtab.items(.nlist)[nlist_idx]; | 1471 | const nlist = switch (file) { |
| | 1472 | .object => |x| x.symtab.items(.nlist)[nlist_idx], |
| | 1473 | .zig_object => |x| x.symtab.items(.nlist)[nlist_idx], |
| | 1474 | else => unreachable, |
| | 1475 | }; |
| 1458 | if (!nlist.ext()) continue; | 1476 | if (!nlist.ext()) continue; |
| 1459 | if (!nlist.undf()) continue; | 1477 | if (!nlist.undf()) continue; |
| 1460 | | 1478 | |