diff --git a/lib/std/coff.zig b/lib/std/coff.zig index e9214cbd79..0b6cd75198 100644 --- a/lib/std/coff.zig +++ b/lib/std/coff.zig @@ -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(); @@ -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 { diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 046adadb46..932fb4a730 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -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 => { diff --git a/src/link/Coff/lld.zig b/src/link/Coff/lld.zig index 405c107628..1543415d0e 100644 --- a/src/link/Coff/lld.zig +++ b/src/link/Coff/lld.zig @@ -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 }));