| ... | ... | @@ -236,6 +236,11 @@ fn parseInputFiles(self: *Zld, files: []const []const u8) !void { |
| 236 | 236 | // First, classify input files as either object or archive. |
| 237 | 237 | for (files) |file_name| { |
| 238 | 238 | const file = try fs.cwd().openFile(file_name, .{}); |
| 239 | const full_path = full_path: { |
| 240 | var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| 241 | const path = try std.fs.realpath(file_name, &buffer); |
| 242 | break :full_path try self.allocator.dupe(u8, path); |
| 243 | }; |
| 239 | 244 | |
| 240 | 245 | try_object: { |
| 241 | 246 | const header = try file.reader().readStruct(macho.mach_header_64); |
| ... | ... | @@ -248,7 +253,7 @@ fn parseInputFiles(self: *Zld, files: []const []const u8) !void { |
| 248 | 253 | try classified.append(.{ |
| 249 | 254 | .kind = .object, |
| 250 | 255 | .file = file, |
| 251 | | .name = file_name, |
| 256 | .name = full_path, |
| 252 | 257 | }); |
| 253 | 258 | continue; |
| 254 | 259 | } |
| ... | ... | @@ -264,7 +269,7 @@ fn parseInputFiles(self: *Zld, files: []const []const u8) !void { |
| 264 | 269 | try classified.append(.{ |
| 265 | 270 | .kind = .archive, |
| 266 | 271 | .file = file, |
| 267 | | .name = file_name, |
| 272 | .name = full_path, |
| 268 | 273 | }); |
| 269 | 274 | continue; |
| 270 | 275 | } |
| ... | ... | @@ -2441,7 +2446,7 @@ fn writeDebugInfo(self: *Zld) !void { |
| 2441 | 2446 | var stabs = std.ArrayList(macho.nlist_64).init(self.allocator); |
| 2442 | 2447 | defer stabs.deinit(); |
| 2443 | 2448 | |
| 2444 | | for (self.objects.items) |object| { |
| 2449 | for (self.objects.items) |object, object_id| { |
| 2445 | 2450 | const tu_path = object.tu_path orelse continue; |
| 2446 | 2451 | const tu_mtime = object.tu_mtime orelse continue; |
| 2447 | 2452 | const dirname = std.fs.path.dirname(tu_path) orelse "./"; |
| ... | ... | @@ -2472,6 +2477,15 @@ fn writeDebugInfo(self: *Zld) !void { |
| 2472 | 2477 | |
| 2473 | 2478 | for (object.stabs.items) |stab| { |
| 2474 | 2479 | const sym = object.symtab.items[stab.symbol]; |
| 2480 | |
| 2481 | // TODO We should clean this up. |
| 2482 | if (self.unhandled_sections.contains(.{ |
| 2483 | .object_id = @intCast(u16, object_id), |
| 2484 | .source_sect_id = stab.source_sect_id, |
| 2485 | })) { |
| 2486 | continue; |
| 2487 | } |
| 2488 | |
| 2475 | 2489 | switch (stab.tag) { |
| 2476 | 2490 | .function => { |
| 2477 | 2491 | try stabs.append(.{ |
| ... | ... | @@ -2549,8 +2563,8 @@ fn populateStringTable(self: *Zld) !void { |
| 2549 | 2563 | for (self.objects.items) |*object| { |
| 2550 | 2564 | for (object.symtab.items) |*sym| { |
| 2551 | 2565 | switch (sym.tag) { |
| 2552 | | .Stab, .Local => {}, |
| 2553 | | else => continue, |
| 2566 | .Undef, .Import => continue, |
| 2567 | else => {}, |
| 2554 | 2568 | } |
| 2555 | 2569 | const sym_name = object.getString(sym.inner.n_strx); |
| 2556 | 2570 | const n_strx = try self.makeString(sym_name); |
| ... | ... | @@ -2559,6 +2573,8 @@ fn populateStringTable(self: *Zld) !void { |
| 2559 | 2573 | } |
| 2560 | 2574 | |
| 2561 | 2575 | for (self.symtab.items()) |*entry| { |
| 2576 | if (entry.value.tag != .Import) continue; |
| 2577 | |
| 2562 | 2578 | const n_strx = try self.makeString(entry.key); |
| 2563 | 2579 | entry.value.inner.n_strx = n_strx; |
| 2564 | 2580 | } |