authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-07 18:21:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-07 22:31:32-07:00
logbfc85211bb440efb2fe0c2f693c4e0334939261e
tree48096c3ccac5c9ea28a546cdfde6ec450aaf5832
parent7ca86936caf7d206248ca6862f23ac25e4b1d327

link: windows: look for more DLL import lib path names

When linking with -lfoo syntax, this indicates to Zig that the dependency should either be provided by Zig, or it should be dynamically provided by the system. For windows-gnu targets, the search path was "foo.lib". Now it additionally looks for "libfoo.dll.a". Closes #7799

1 files changed, 28 insertions(+), 3 deletions(-)

src/link/Coff.zig+28-3
...@@ -1221,13 +1221,26 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {...@@ -1221,13 +1221,26 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
1221 try argv.append(comp.compiler_rt_static_lib.?.full_object_path);1221 try argv.append(comp.compiler_rt_static_lib.?.full_object_path);
1222 }1222 }
12231223
1224 try argv.ensureUnusedCapacity(self.base.options.system_libs.count());
1224 for (self.base.options.system_libs.keys()) |key| {1225 for (self.base.options.system_libs.keys()) |key| {
1225 const lib_basename = try allocPrint(arena, "{s}.lib", .{key});1226 const lib_basename = try allocPrint(arena, "{s}.lib", .{key});
1226 if (comp.crt_files.get(lib_basename)) |crt_file| {1227 if (comp.crt_files.get(lib_basename)) |crt_file| {
1227 try argv.append(crt_file.full_object_path);1228 argv.appendAssumeCapacity(crt_file.full_object_path);
1228 } else {1229 continue;
1229 try argv.append(lib_basename);1230 }
1231 if (try self.findLib(arena, lib_basename)) |full_path| {
1232 argv.appendAssumeCapacity(full_path);
1233 continue;
1234 }
1235 if (target.abi.isGnu()) {
1236 const fallback_name = try allocPrint(arena, "lib{s}.dll.a", .{key});
1237 if (try self.findLib(arena, fallback_name)) |full_path| {
1238 argv.appendAssumeCapacity(full_path);
1239 continue;
1240 }
1230 }1241 }
1242 log.err("DLL import library for -l{s} not found", .{key});
1243 return error.DllImportLibraryNotFound;
1231 }1244 }
12321245
1233 if (self.base.options.verbose_link) {1246 if (self.base.options.verbose_link) {
...@@ -1309,6 +1322,18 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {...@@ -1309,6 +1322,18 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
1309 }1322 }
1310}1323}
13111324
1325fn findLib(self: *Coff, arena: *Allocator, name: []const u8) !?[]const u8 {
1326 for (self.base.options.lib_dirs) |lib_dir| {
1327 const full_path = try fs.path.join(arena, &.{ lib_dir, name });
1328 fs.cwd().access(full_path, .{}) catch |err| switch (err) {
1329 error.FileNotFound => continue,
1330 else => |e| return e,
1331 };
1332 return full_path;
1333 }
1334 return null;
1335}
1336
1312pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 {1337pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 {
1313 assert(self.llvm_object == null);1338 assert(self.llvm_object == null);
1314 return self.text_section_virtual_address + decl.link.coff.text_offset;1339 return self.text_section_virtual_address + decl.link.coff.text_offset;