Skip to content

coff: only store PDB basename #18704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/std/coff.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ pub const Coff = struct {
return coff;
}

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

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

// Finally read the null-terminated string.
var byte = try reader.readByte();
i = 0;
while (byte != 0 and i < buffer.len) : (i += 1) {
buffer[i] = byte;
byte = try reader.readByte();
}

if (byte != 0 and i == buffer.len)
return error.NameTooLong;

return @as(usize, i);
const start = reader.context.pos;
const len = std.mem.indexOfScalar(u8, self.data[start..], 0) orelse return null;
return self.data[start .. start + len];
}

pub fn getCoffHeader(self: Coff) CoffHeader {
Expand Down
17 changes: 11 additions & 6 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1093,12 +1093,17 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu
di.dwarf = dwarf;
}

var path_buf: [windows.MAX_PATH]u8 = undefined;
const len = try coff_obj.getPdbPath(path_buf[0..]) orelse return di;
const raw_path = path_buf[0..len];

const path = try fs.path.resolve(allocator, &[_][]const u8{raw_path});
defer allocator.free(path);
const raw_path = try coff_obj.getPdbPath() orelse return di;
const path = blk: {
if (fs.path.isAbsolute(raw_path)) {
break :blk raw_path;
} else {
const self_dir = try fs.selfExeDirPathAlloc(allocator);
defer allocator.free(self_dir);
break :blk try fs.path.join(allocator, &.{ self_dir, raw_path });
}
};
defer if (path.ptr != raw_path.ptr) allocator.free(path);

di.pdb = pdb.Pdb.init(allocator, path) catch |err| switch (err) {
error.FileNotFound, error.IsDir => {
Expand Down
3 changes: 2 additions & 1 deletion src/link/Coff/lld.zig
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node)
const out_pdb = self.pdb_out_path orelse try allocPrint(arena, "{s}.pdb", .{
full_out_path[0 .. full_out_path.len - out_ext.len],
});
const out_pdb_basename = std.fs.path.basename(out_pdb);

try argv.append(try allocPrint(arena, "-PDB:{s}", .{out_pdb}));
try argv.append(try allocPrint(arena, "-PDBALTPATH:{s}", .{out_pdb}));
try argv.append(try allocPrint(arena, "-PDBALTPATH:{s}", .{out_pdb_basename}));
}
if (comp.version) |version| {
try argv.append(try allocPrint(arena, "-VERSION:{}.{}", .{ version.major, version.minor }));
Expand Down