| author | |
| committer | |
| log | b97a68c529b5db15705f4d542d8ead616d27c880 |
| tree | 4a88814249684640687fbde316fe0ad0bf9256d6 |
| parent | 0471eea0e2cac49946449efe4698d5ac18c0dc0d |
- add support for passing through .def files to the linker,
required for building libLTO.dll in LLVM
- fixup libcpp linking conditionals
- add option to skip linking zstd for use in bootstrapping (when
building against an LLVM with LLVM_ENABLE_ZSTD=OFF)5 files changed, 32 insertions(+), 8 deletions(-)
build.zig+8-6| ... | ... | @@ -99,6 +99,7 @@ pub fn build(b: *Builder) !void { |
| 99 | 99 | const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse false; |
| 100 | 100 | const enable_symlinks_windows = b.option(bool, "enable-symlinks-windows", "Run tests requiring presence of symlinks on Windows") orelse false; |
| 101 | 101 | const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h"); |
| 102 | const disable_zstd = b.option(bool, "disable-zstd", "Skip linking zstd") orelse false; | |
| 102 | 103 | |
| 103 | 104 | if (!skip_install_lib_files) { |
| 104 | 105 | b.installDirectory(InstallDirectoryOptions{ |
| ... | ... | @@ -277,8 +278,8 @@ pub fn build(b: *Builder) !void { |
| 277 | 278 | try addCmakeCfgOptionsToExe(b, cfg, test_cases, use_zig_libcxx); |
| 278 | 279 | } else { |
| 279 | 280 | // Here we are -Denable-llvm but no cmake integration. |
| 280 | try addStaticLlvmOptionsToExe(exe); | |
| 281 | try addStaticLlvmOptionsToExe(test_cases); | |
| 281 | try addStaticLlvmOptionsToExe(exe, !disable_zstd); | |
| 282 | try addStaticLlvmOptionsToExe(test_cases, !disable_zstd); | |
| 282 | 283 | } |
| 283 | 284 | if (target.isWindows()) { |
| 284 | 285 | inline for (.{ exe, test_cases }) |artifact| { |
| ... | ... | @@ -606,7 +607,7 @@ fn addCmakeCfgOptionsToExe( |
| 606 | 607 | } |
| 607 | 608 | } |
| 608 | 609 | |
| 609 | fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void { | |
| 610 | fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep, link_zstd: bool) !void { | |
| 610 | 611 | // Adds the Zig C++ sources which both stage1 and stage2 need. |
| 611 | 612 | // |
| 612 | 613 | // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling |
| ... | ... | @@ -629,10 +630,11 @@ fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void { |
| 629 | 630 | |
| 630 | 631 | exe.linkSystemLibrary("z"); |
| 631 | 632 | |
| 632 | if (exe.target.getOs().tag != .windows and exe.target.getAbi() != .msvc) { | |
| 633 | // TODO: Support this on msvc | |
| 633 | if (link_zstd) { | |
| 634 | 634 | exe.linkSystemLibrary("zstd"); |
| 635 | } | |
| 635 | 636 | |
| 637 | if (exe.target.getOs().tag != .windows or exe.target.getAbi() != .msvc) { | |
| 636 | 638 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. |
| 637 | 639 | exe.linkSystemLibrary("c++"); |
| 638 | 640 | } |
| ... | ... | @@ -704,7 +706,7 @@ fn addCMakeSystemLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) vo |
| 704 | 706 | end_offset = ".lib".len; |
| 705 | 707 | } |
| 706 | 708 | |
| 707 | exe.linkSystemLibrary(lib[start_offset..lib.len - end_offset]); | |
| 709 | exe.linkSystemLibrary(lib[start_offset .. lib.len - end_offset]); | |
| 708 | 710 | } |
| 709 | 711 | } |
| 710 | 712 |
src/Compilation.zig+7-1| ... | ... | @@ -984,6 +984,7 @@ pub const InitOptions = struct { |
| 984 | 984 | linker_dynamicbase: bool = false, |
| 985 | 985 | linker_optimization: ?u8 = null, |
| 986 | 986 | linker_compress_debug_sections: ?link.CompressDebugSections = null, |
| 987 | linker_module_definition_file: ?[]const u8 = null, | |
| 987 | 988 | major_subsystem_version: ?u32 = null, |
| 988 | 989 | minor_subsystem_version: ?u32 = null, |
| 989 | 990 | clang_passthrough_mode: bool = false, |
| ... | ... | @@ -1815,6 +1816,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1815 | 1816 | .allow_shlib_undefined = options.linker_allow_shlib_undefined, |
| 1816 | 1817 | .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false, |
| 1817 | 1818 | .compress_debug_sections = options.linker_compress_debug_sections orelse .none, |
| 1819 | .module_definition_file = options.linker_module_definition_file, | |
| 1818 | 1820 | .import_memory = options.linker_import_memory orelse false, |
| 1819 | 1821 | .import_symbols = options.linker_import_symbols, |
| 1820 | 1822 | .import_table = options.linker_import_table, |
| ... | ... | @@ -4379,7 +4381,7 @@ pub fn addCCArgs( |
| 4379 | 4381 | try argv.append("-fno-unwind-tables"); |
| 4380 | 4382 | } |
| 4381 | 4383 | }, |
| 4382 | .shared_library, .ll, .bc, .unknown, .static_library, .object, .zig => {}, | |
| 4384 | .shared_library, .ll, .bc, .unknown, .static_library, .object, .def, .zig => {}, | |
| 4383 | 4385 | .assembly => { |
| 4384 | 4386 | // The Clang assembler does not accept the list of CPU features like the |
| 4385 | 4387 | // compiler frontend does. Therefore we must hard-code the -m flags for |
| ... | ... | @@ -4524,6 +4526,7 @@ pub const FileExt = enum { |
| 4524 | 4526 | object, |
| 4525 | 4527 | static_library, |
| 4526 | 4528 | zig, |
| 4529 | def, | |
| 4527 | 4530 | unknown, |
| 4528 | 4531 | |
| 4529 | 4532 | pub fn clangSupportsDepFile(ext: FileExt) bool { |
| ... | ... | @@ -4537,6 +4540,7 @@ pub const FileExt = enum { |
| 4537 | 4540 | .object, |
| 4538 | 4541 | .static_library, |
| 4539 | 4542 | .zig, |
| 4543 | .def, | |
| 4540 | 4544 | .unknown, |
| 4541 | 4545 | => false, |
| 4542 | 4546 | }; |
| ... | ... | @@ -4629,6 +4633,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt { |
| 4629 | 4633 | return .object; |
| 4630 | 4634 | } else if (mem.endsWith(u8, filename, ".cu")) { |
| 4631 | 4635 | return .cu; |
| 4636 | } else if (mem.endsWith(u8, filename, ".def")) { | |
| 4637 | return .def; | |
| 4632 | 4638 | } else { |
| 4633 | 4639 | return .unknown; |
| 4634 | 4640 | } |
src/link.zig+7| ... | ... | @@ -219,6 +219,13 @@ pub const Options = struct { |
| 219 | 219 | /// (Darwin) remove dylibs that are unreachable by the entry point or exported symbols |
| 220 | 220 | dead_strip_dylibs: bool = false, |
| 221 | 221 | |
| 222 | /// (Windows) PDB source path prefix to instruct the linker how to resolve relative | |
| 223 | /// paths when consolidating CodeView streams into a single PDB file. | |
| 224 | pdb_source_path: ?[]const u8 = null, | |
| 225 | ||
| 226 | /// (Windows) .def file to specify when linking | |
| 227 | module_definition_file: ?[] const u8 = null, | |
| 228 | ||
| 222 | 229 | pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode { |
| 223 | 230 | return if (options.use_lld) .Obj else options.output_mode; |
| 224 | 231 | } |
src/link/Coff/lld.zig+4| ... | ... | @@ -260,6 +260,10 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 260 | 260 | try argv.append(p); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | if (self.base.options.module_definition_file) |def| { | |
| 264 | try argv.append(try allocPrint(arena, "-DEF:{s}", .{ def })); | |
| 265 | } | |
| 266 | ||
| 263 | 267 | const resolved_subsystem: ?std.Target.SubSystem = blk: { |
| 264 | 268 | if (self.base.options.subsystem) |explicit| break :blk explicit; |
| 265 | 269 | switch (target.os.tag) { |
src/main.zig+6-1| ... | ... | @@ -742,6 +742,7 @@ fn buildOutputType( |
| 742 | 742 | var linker_nxcompat = false; |
| 743 | 743 | var linker_dynamicbase = false; |
| 744 | 744 | var linker_optimization: ?u8 = null; |
| 745 | var linker_module_definition_file: ?[]const u8 = null; | |
| 745 | 746 | var test_evented_io = false; |
| 746 | 747 | var test_no_exec = false; |
| 747 | 748 | var entry: ?[]const u8 = null; |
| ... | ... | @@ -1404,7 +1405,7 @@ fn buildOutputType( |
| 1404 | 1405 | root_src_file = arg; |
| 1405 | 1406 | } |
| 1406 | 1407 | }, |
| 1407 | .unknown => { | |
| 1408 | .def, .unknown => { | |
| 1408 | 1409 | fatal("unrecognized file extension of parameter '{s}'", .{arg}); |
| 1409 | 1410 | }, |
| 1410 | 1411 | } |
| ... | ... | @@ -1478,6 +1479,9 @@ fn buildOutputType( |
| 1478 | 1479 | .must_link = must_link, |
| 1479 | 1480 | }); |
| 1480 | 1481 | }, |
| 1482 | .def => { | |
| 1483 | linker_module_definition_file = it.only_arg; | |
| 1484 | }, | |
| 1481 | 1485 | .zig => { |
| 1482 | 1486 | if (root_src_file) |other| { |
| 1483 | 1487 | fatal("found another zig file '{s}' after root source file '{s}'", .{ it.only_arg, other }); |
| ... | ... | @@ -3015,6 +3019,7 @@ fn buildOutputType( |
| 3015 | 3019 | .linker_dynamicbase = linker_dynamicbase, |
| 3016 | 3020 | .linker_optimization = linker_optimization, |
| 3017 | 3021 | .linker_compress_debug_sections = linker_compress_debug_sections, |
| 3022 | .linker_module_definition_file = linker_module_definition_file, | |
| 3018 | 3023 | .major_subsystem_version = major_subsystem_version, |
| 3019 | 3024 | .minor_subsystem_version = minor_subsystem_version, |
| 3020 | 3025 | .link_eh_frame_hdr = link_eh_frame_hdr, |