From 0da7c4b0c8a2a2fe0862f7757bc5976342d51dc8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 29 Sep 2020 14:46:40 -0700 Subject: improve stage2 COFF LLD linking * change some {} to be {s} to gain type safety * fix libraries being libfoo.lib instead of foo.lib for COFF * when linking mingw-w64, add the "always link" libs so that we generate DLL import .lib files for them as the linker code relies on. * COFF LLD linker does not support -r so we do a file copy as an alternative to the -r thing that ELF linking does. I will file an issue for the corresponding TODO upon merging this branch, to look into an optimization that possibly elides this copy when the source and destination are both cache directories. * add a CLI error message when trying to link multiple objects into one and using COFF object format. --- src/main.zig | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index de2f38bffb..822e777d68 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1314,8 +1314,8 @@ fn buildOutputType( } } - const object_format: ?std.Target.ObjectFormat = blk: { - const ofmt = target_ofmt orelse break :blk null; + const object_format: std.Target.ObjectFormat = blk: { + const ofmt = target_ofmt orelse break :blk target_info.target.getObjectFormat(); if (mem.eql(u8, ofmt, "elf")) { break :blk .elf; } else if (mem.eql(u8, ofmt, "c")) { @@ -1337,6 +1337,15 @@ fn buildOutputType( } }; + if (output_mode == .Obj and object_format == .coff) { + const total_obj_count = c_source_files.items.len + + @boolToInt(root_src_file != null) + + link_objects.items.len; + if (total_obj_count > 1) { + fatal("COFF does not support linking multiple objects into one", .{}); + } + } + var cleanup_emit_bin_dir: ?fs.Dir = null; defer if (cleanup_emit_bin_dir) |*dir| dir.close(); -- cgit v1.2.3