aboutsummaryrefslogtreecommitdiff
path: root/src/link.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-07-22 14:44:06 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-22 19:51:32 -0700
commita5fb28070f37c2cad92ac8805bcc704e872fc538 (patch)
tree05e8432688cd83fcb4989a13087c01c74df172c5 /src/link.zig
parent36295d712fbd561c3de9b3eb46e776d63e646e9a (diff)
downloadzig-a5fb28070f37c2cad92ac8805bcc704e872fc538.tar.gz
zig-a5fb28070f37c2cad92ac8805bcc704e872fc538.zip
add -femit-llvm-bc CLI option and implement it
* Added doc comments for `std.Target.ObjectFormat` enum * `std.Target.oFileExt` is removed because it is incorrect for Plan-9 targets. Instead, use `std.Target.ObjectFormat.fileExt` and pass a CPU architecture. * Added `Compilation.Directory.joinZ` for when a null byte is desired. * Improvements to `Compilation.create` logic for computing `use_llvm` and reporting errors in contradictory flags. `-femit-llvm-ir` and `-femit-llvm-bc` will now imply `-fLLVM`. * Fix compilation when passing `.bc` files on the command line. * Improvements to the stage2 LLVM backend: - cleaned up error messages and error reporting. Properly bubble up some errors rather than dumping to stderr; others turn into panics. - properly call ZigLLVMCreateTargetMachine and ZigLLVMTargetMachineEmitToFile and implement calculation of the respective parameters (cpu features, code model, abi name, lto, tsan, etc). - LLVM module verification only runs in debug builds of the compiler - use LLVMDumpModule rather than printToString because in the case that we incorrectly pass a null pointer to LLVM it may crash during dumping the module and having it partially printed is helpful in this case. - support -femit-asm, -fno-emit-bin, -femit-llvm-ir, -femit-llvm-bc - Support LLVM backend when used with Mach-O and WASM linkers.
Diffstat (limited to 'src/link.zig')
-rw-r--r--src/link.zig10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/link.zig b/src/link.zig
index 562896d14c..85ff2ca603 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -206,7 +206,8 @@ pub const File = struct {
const use_lld = build_options.have_llvm and options.use_lld; // comptime known false when !have_llvm
const sub_path = if (use_lld) blk: {
if (options.module == null) {
- // No point in opening a file, we would not write anything to it. Initialize with empty.
+ // No point in opening a file, we would not write anything to it.
+ // Initialize with empty.
return switch (options.object_format) {
.coff => &(try Coff.createEmpty(allocator, options)).base,
.elf => &(try Elf.createEmpty(allocator, options)).base,
@@ -219,8 +220,11 @@ pub const File = struct {
.raw => return error.RawObjectFormatUnimplemented,
};
}
- // Open a temporary object file, not the final output file because we want to link with LLD.
- break :blk try std.fmt.allocPrint(allocator, "{s}{s}", .{ emit.sub_path, options.target.oFileExt() });
+ // Open a temporary object file, not the final output file because we
+ // want to link with LLD.
+ break :blk try std.fmt.allocPrint(allocator, "{s}{s}", .{
+ emit.sub_path, options.object_format.fileExt(options.target.cpu.arch),
+ });
} else emit.sub_path;
errdefer if (use_lld) allocator.free(sub_path);