Skip to content

Commit 6b38758

Browse files
ypsvlqandrewrk
authored andcommitted
coff: only store PDB basename
1 parent 6724a52 commit 6b38758

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

lib/std/coff.zig

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ pub const Coff = struct {
11011101
return coff;
11021102
}
11031103

1104-
pub fn getPdbPath(self: *Coff, buffer: []u8) !?usize {
1104+
pub fn getPdbPath(self: *Coff) !?[]const u8 {
11051105
assert(self.is_image);
11061106

11071107
const data_dirs = self.getDataDirectories();
@@ -1145,17 +1145,9 @@ pub const Coff = struct {
11451145
self.age = try reader.readInt(u32, .little);
11461146

11471147
// Finally read the null-terminated string.
1148-
var byte = try reader.readByte();
1149-
i = 0;
1150-
while (byte != 0 and i < buffer.len) : (i += 1) {
1151-
buffer[i] = byte;
1152-
byte = try reader.readByte();
1153-
}
1154-
1155-
if (byte != 0 and i == buffer.len)
1156-
return error.NameTooLong;
1157-
1158-
return @as(usize, i);
1148+
const start = reader.context.pos;
1149+
const len = std.mem.indexOfScalar(u8, self.data[start..], 0) orelse return null;
1150+
return self.data[start .. start + len];
11591151
}
11601152

11611153
pub fn getCoffHeader(self: Coff) CoffHeader {

lib/std/debug.zig

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,12 +1093,17 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu
10931093
di.dwarf = dwarf;
10941094
}
10951095

1096-
var path_buf: [windows.MAX_PATH]u8 = undefined;
1097-
const len = try coff_obj.getPdbPath(path_buf[0..]) orelse return di;
1098-
const raw_path = path_buf[0..len];
1099-
1100-
const path = try fs.path.resolve(allocator, &[_][]const u8{raw_path});
1101-
defer allocator.free(path);
1096+
const raw_path = try coff_obj.getPdbPath() orelse return di;
1097+
const path = blk: {
1098+
if (fs.path.isAbsolute(raw_path)) {
1099+
break :blk raw_path;
1100+
} else {
1101+
const self_dir = try fs.selfExeDirPathAlloc(allocator);
1102+
defer allocator.free(self_dir);
1103+
break :blk try fs.path.join(allocator, &.{ self_dir, raw_path });
1104+
}
1105+
};
1106+
defer if (path.ptr != raw_path.ptr) allocator.free(path);
11021107

11031108
di.pdb = pdb.Pdb.init(allocator, path) catch |err| switch (err) {
11041109
error.FileNotFound, error.IsDir => {

src/link/Coff/lld.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
184184
const out_pdb = self.pdb_out_path orelse try allocPrint(arena, "{s}.pdb", .{
185185
full_out_path[0 .. full_out_path.len - out_ext.len],
186186
});
187+
const out_pdb_basename = std.fs.path.basename(out_pdb);
187188

188189
try argv.append(try allocPrint(arena, "-PDB:{s}", .{out_pdb}));
189-
try argv.append(try allocPrint(arena, "-PDBALTPATH:{s}", .{out_pdb}));
190+
try argv.append(try allocPrint(arena, "-PDBALTPATH:{s}", .{out_pdb_basename}));
190191
}
191192
if (comp.version) |version| {
192193
try argv.append(try allocPrint(arena, "-VERSION:{}.{}", .{ version.major, version.minor }));

0 commit comments

Comments
 (0)