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