| author | |
| committer | |
| log | b7c3ebcb9e3aefbdd82a43c7ab122931787c7805 |
| tree | 4136470a9950065a63e77f5ef61d93e2b3b0f93f |
| parent | e0e3ceac19c0de0f8b3e408f9d3728496bc051f7 |
9 files changed, 74 insertions(+), 122 deletions(-)
CMakeLists.txt+7-18| ... | ... | @@ -505,24 +505,13 @@ add_dependencies(zig zig_build_zig1) |
| 505 | 505 | |
| 506 | 506 | install(TARGETS zig DESTINATION bin) |
| 507 | 507 | |
| 508 | if(NOT SYSTEM_LINKER_HACK) | |
| 509 | set(ZIG_INSTALL_ARGS "build" | |
| 510 | --override-lib-dir "${CMAKE_SOURCE_DIR}/lib" | |
| 511 | "-Dlib-files-only" | |
| 512 | --prefix "${CMAKE_INSTALL_PREFIX}" | |
| 513 | "-Dconfig_h=${ZIG_CONFIG_H_OUT}" | |
| 514 | install | |
| 515 | ) | |
| 516 | else() | |
| 517 | set(ZIG_INSTALL_ARGS "build" | |
| 518 | --override-lib-dir "${CMAKE_SOURCE_DIR}/lib" | |
| 519 | "-Dlib-files-only" | |
| 520 | --prefix "${CMAKE_INSTALL_PREFIX}" | |
| 521 | "-Dconfig_h=${ZIG_CONFIG_H_OUT}" | |
| 522 | --system-linker-hack | |
| 523 | install | |
| 524 | ) | |
| 525 | endif() | |
| 508 | set(ZIG_INSTALL_ARGS "build" | |
| 509 | --override-lib-dir "${CMAKE_SOURCE_DIR}/lib" | |
| 510 | "-Dlib-files-only" | |
| 511 | --prefix "${CMAKE_INSTALL_PREFIX}" | |
| 512 | "-Dconfig_h=${ZIG_CONFIG_H_OUT}" | |
| 513 | install | |
| 514 | ) | |
| 526 | 515 | |
| 527 | 516 | # CODE has no effect with Visual Studio build system generator, therefore |
| 528 | 517 | # when using Visual Studio build system generator we resort to running |
build.zig+1-1| ... | ... | @@ -396,8 +396,8 @@ fn configureStage2(b: *Builder, exe: anytype, ctx: Context, need_cpp_includes: b |
| 396 | 396 | try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null, need_cpp_includes); |
| 397 | 397 | exe.linkSystemLibrary("pthread"); |
| 398 | 398 | // TODO LLD cannot perform this link. |
| 399 | // Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead. | |
| 399 | 400 | // See https://github.com/ziglang/zig/issues/1535 |
| 400 | exe.enableSystemLinkerHack(); | |
| 401 | 401 | } else |err| switch (err) { |
| 402 | 402 | error.RequiredLibraryNotFound => { |
| 403 | 403 | // System compiler, not gcc. |
lib/std/build.zig-8| ... | ... | @@ -67,7 +67,6 @@ pub const Builder = struct { |
| 67 | 67 | vcpkg_root: VcpkgRoot, |
| 68 | 68 | pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null, |
| 69 | 69 | args: ?[][]const u8 = null, |
| 70 | system_linker_hack: bool, | |
| 71 | 70 | |
| 72 | 71 | const PkgConfigError = error{ |
| 73 | 72 | PkgConfigCrashed, |
| ... | ... | @@ -174,7 +173,6 @@ pub const Builder = struct { |
| 174 | 173 | .install_path = undefined, |
| 175 | 174 | .vcpkg_root = VcpkgRoot{ .Unattempted = {} }, |
| 176 | 175 | .args = null, |
| 177 | .system_linker_hack = false, | |
| 178 | 176 | }; |
| 179 | 177 | try self.top_level_steps.append(&self.install_tls); |
| 180 | 178 | try self.top_level_steps.append(&self.uninstall_tls); |
| ... | ... | @@ -1239,7 +1237,6 @@ pub const LibExeObjStep = struct { |
| 1239 | 1237 | packages: ArrayList(Pkg), |
| 1240 | 1238 | build_options_contents: std.ArrayList(u8), |
| 1241 | 1239 | build_options_artifact_args: std.ArrayList(BuildOptionArtifactArg), |
| 1242 | system_linker_hack: bool = false, | |
| 1243 | 1240 | |
| 1244 | 1241 | object_src: []const u8, |
| 1245 | 1242 | |
| ... | ... | @@ -1900,10 +1897,6 @@ pub const LibExeObjStep = struct { |
| 1900 | 1897 | self.exec_cmd_args = args; |
| 1901 | 1898 | } |
| 1902 | 1899 | |
| 1903 | pub fn enableSystemLinkerHack(self: *LibExeObjStep) void { | |
| 1904 | self.system_linker_hack = true; | |
| 1905 | } | |
| 1906 | ||
| 1907 | 1900 | fn linkLibraryOrObject(self: *LibExeObjStep, other: *LibExeObjStep) void { |
| 1908 | 1901 | self.step.dependOn(&other.step); |
| 1909 | 1902 | self.link_objects.append(LinkObject{ .OtherStep = other }) catch unreachable; |
| ... | ... | @@ -2076,7 +2069,6 @@ pub const LibExeObjStep = struct { |
| 2076 | 2069 | if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable; |
| 2077 | 2070 | if (builder.verbose_cc or self.verbose_cc) zig_args.append("--verbose-cc") catch unreachable; |
| 2078 | 2071 | if (builder.verbose_llvm_cpu_features) zig_args.append("--verbose-llvm-cpu-features") catch unreachable; |
| 2079 | if (builder.system_linker_hack or self.system_linker_hack) zig_args.append("--system-linker-hack") catch unreachable; | |
| 2080 | 2072 | |
| 2081 | 2073 | if (self.emit_llvm_ir) try zig_args.append("-femit-llvm-ir"); |
| 2082 | 2074 | if (self.emit_asm) try zig_args.append("-femit-asm"); |
lib/std/special/build_runner.zig-3| ... | ... | @@ -112,8 +112,6 @@ pub fn main() !void { |
| 112 | 112 | builder.verbose_cc = true; |
| 113 | 113 | } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) { |
| 114 | 114 | builder.verbose_llvm_cpu_features = true; |
| 115 | } else if (mem.eql(u8, arg, "--system-linker-hack")) { | |
| 116 | builder.system_linker_hack = true; | |
| 117 | 115 | } else if (mem.eql(u8, arg, "--")) { |
| 118 | 116 | builder.args = argsRest(args, arg_idx); |
| 119 | 117 | break; |
| ... | ... | @@ -215,7 +213,6 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void |
| 215 | 213 | \\ --verbose-cimport Enable compiler debug output for C imports |
| 216 | 214 | \\ --verbose-cc Enable compiler debug output for C compilation |
| 217 | 215 | \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features |
| 218 | \\ --system-linker-hack Use system linker LD instead of LLD (requires LLVM enabled) | |
| 219 | 216 | \\ |
| 220 | 217 | ); |
| 221 | 218 | } |
src/Compilation.zig+18-11| ... | ... | @@ -348,8 +348,6 @@ pub const InitOptions = struct { |
| 348 | 348 | want_valgrind: ?bool = null, |
| 349 | 349 | use_llvm: ?bool = null, |
| 350 | 350 | use_lld: ?bool = null, |
| 351 | /// When set, this option will overwrite LLD with the system linker LD. | |
| 352 | system_linker_hack: bool = false, | |
| 353 | 351 | use_clang: ?bool = null, |
| 354 | 352 | rdynamic: bool = false, |
| 355 | 353 | strip: bool = false, |
| ... | ... | @@ -474,13 +472,22 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 474 | 472 | break :blk false; |
| 475 | 473 | }; |
| 476 | 474 | |
| 477 | const syslibroot = if (build_options.have_llvm and comptime std.Target.current.isDarwin()) outer: { | |
| 478 | const path = if (use_lld and options.is_native_os and options.target.isDarwin()) inner: { | |
| 479 | const syslibroot_path = try std.zig.system.getSDKPath(arena); | |
| 480 | break :inner syslibroot_path; | |
| 481 | } else null; | |
| 482 | break :outer path; | |
| 483 | } else null; | |
| 475 | const DarwinOptions = struct { | |
| 476 | syslibroot: ?[]const u8 = null, | |
| 477 | system_linker_hack: bool = false, | |
| 478 | }; | |
| 479 | ||
| 480 | const darwin_options: DarwinOptions = if (build_options.have_llvm and comptime std.Target.current.isDarwin()) outer: { | |
| 481 | const opts: DarwinOptions = if (use_lld and options.is_native_os and options.target.isDarwin()) inner: { | |
| 482 | const syslibroot = try std.zig.system.getSDKPath(arena); | |
| 483 | const system_linker_hack = if (std.os.getenv("ZIG_SYSTEM_LINKER_HACK")) |_| true else false; | |
| 484 | break :inner .{ | |
| 485 | .syslibroot = syslibroot, | |
| 486 | .system_linker_hack = system_linker_hack, | |
| 487 | }; | |
| 488 | } else .{}; | |
| 489 | break :outer opts; | |
| 490 | } else .{}; | |
| 484 | 491 | |
| 485 | 492 | const link_libc = options.link_libc or target_util.osRequiresLibC(options.target); |
| 486 | 493 | |
| ... | ... | @@ -777,14 +784,14 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 777 | 784 | .optimize_mode = options.optimize_mode, |
| 778 | 785 | .use_lld = use_lld, |
| 779 | 786 | .use_llvm = use_llvm, |
| 780 | .system_linker_hack = options.system_linker_hack, | |
| 787 | .system_linker_hack = darwin_options.system_linker_hack, | |
| 781 | 788 | .link_libc = link_libc, |
| 782 | 789 | .link_libcpp = options.link_libcpp, |
| 783 | 790 | .objects = options.link_objects, |
| 784 | 791 | .frameworks = options.frameworks, |
| 785 | 792 | .framework_dirs = options.framework_dirs, |
| 786 | 793 | .system_libs = system_libs, |
| 787 | .syslibroot = syslibroot, | |
| 794 | .syslibroot = darwin_options.syslibroot, | |
| 788 | 795 | .lib_dirs = options.lib_dirs, |
| 789 | 796 | .rpath_list = options.rpath_list, |
| 790 | 797 | .strip = strip, |
src/link.zig+2-2| ... | ... | @@ -57,8 +57,8 @@ pub const Options = struct { |
| 57 | 57 | /// other objects. |
| 58 | 58 | /// Otherwise (depending on `use_lld`) this link code directly outputs and updates the final binary. |
| 59 | 59 | use_llvm: bool, |
| 60 | /// If this is true and `use_llvm` is true, this link code will use system linker `ld` instead of | |
| 61 | /// the LLD. | |
| 60 | /// Darwin-only. If this is true, `use_llvm` is true, and `is_native_os` is true, this link code will | |
| 61 | /// use system linker `ld` instead of the LLD. | |
| 62 | 62 | system_linker_hack: bool, |
| 63 | 63 | link_libc: bool, |
| 64 | 64 | link_libcpp: bool, |
src/link/Elf.zig+40-66| ... | ... | @@ -1353,20 +1353,14 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1353 | 1353 | // Create an LLD command line and invoke it. |
| 1354 | 1354 | var argv = std.ArrayList([]const u8).init(self.base.allocator); |
| 1355 | 1355 | defer argv.deinit(); |
| 1356 | ||
| 1357 | if (self.base.options.is_native_os and self.base.options.system_linker_hack) { | |
| 1358 | try argv.append("ld"); | |
| 1359 | } else { | |
| 1360 | // Even though we're calling LLD as a library it thinks the first argument is its own exe name. | |
| 1361 | try argv.append("lld"); | |
| 1362 | ||
| 1363 | try argv.append("-error-limit=0"); | |
| 1364 | } | |
| 1365 | ||
| 1356 | // Even though we're calling LLD as a library it thinks the first argument is its own exe name. | |
| 1357 | try argv.append("lld"); | |
| 1366 | 1358 | if (is_obj) { |
| 1367 | 1359 | try argv.append("-r"); |
| 1368 | 1360 | } |
| 1369 | 1361 | |
| 1362 | try argv.append("-error-limit=0"); | |
| 1363 | ||
| 1370 | 1364 | if (self.base.options.output_mode == .Exe) { |
| 1371 | 1365 | try argv.append("-z"); |
| 1372 | 1366 | try argv.append(try std.fmt.allocPrint(arena, "stack-size={}", .{stack_size})); |
| ... | ... | @@ -1622,63 +1616,43 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1622 | 1616 | Compilation.dump_argv(argv.items); |
| 1623 | 1617 | } |
| 1624 | 1618 | |
| 1625 | if (self.base.options.is_native_os and self.base.options.system_linker_hack) { | |
| 1626 | const result = try std.ChildProcess.exec(.{ .allocator = self.base.allocator, .argv = argv.items }); | |
| 1627 | defer { | |
| 1628 | self.base.allocator.free(result.stdout); | |
| 1629 | self.base.allocator.free(result.stderr); | |
| 1630 | } | |
| 1631 | if (result.stdout.len != 0) { | |
| 1632 | std.log.warn("unexpected LD stdout: {}", .{result.stdout}); | |
| 1633 | } | |
| 1634 | if (result.stderr.len != 0) { | |
| 1635 | std.log.warn("unexpected LD stderr: {}", .{result.stderr}); | |
| 1636 | } | |
| 1637 | if (result.term.Exited != 0) { | |
| 1638 | // TODO parse this output and surface with the Compilation API rather than | |
| 1639 | // directly outputting to stderr here. | |
| 1640 | std.debug.print("{}", .{result.stderr}); | |
| 1641 | return error.LDReportedFailure; | |
| 1642 | } | |
| 1643 | } else { | |
| 1644 | // Oh, snapplesauce! We need null terminated argv. | |
| 1645 | const new_argv = try arena.allocSentinel(?[*:0]const u8, argv.items.len, null); | |
| 1646 | for (argv.items) |arg, i| { | |
| 1647 | new_argv[i] = try arena.dupeZ(u8, arg); | |
| 1648 | } | |
| 1619 | // Oh, snapplesauce! We need null terminated argv. | |
| 1620 | const new_argv = try arena.allocSentinel(?[*:0]const u8, argv.items.len, null); | |
| 1621 | for (argv.items) |arg, i| { | |
| 1622 | new_argv[i] = try arena.dupeZ(u8, arg); | |
| 1623 | } | |
| 1649 | 1624 | |
| 1650 | var stderr_context: LLDContext = .{ | |
| 1651 | .elf = self, | |
| 1652 | .data = std.ArrayList(u8).init(self.base.allocator), | |
| 1653 | }; | |
| 1654 | defer stderr_context.data.deinit(); | |
| 1655 | var stdout_context: LLDContext = .{ | |
| 1656 | .elf = self, | |
| 1657 | .data = std.ArrayList(u8).init(self.base.allocator), | |
| 1658 | }; | |
| 1659 | defer stdout_context.data.deinit(); | |
| 1660 | const llvm = @import("../llvm.zig"); | |
| 1661 | const ok = llvm.Link( | |
| 1662 | .ELF, | |
| 1663 | new_argv.ptr, | |
| 1664 | new_argv.len, | |
| 1665 | append_diagnostic, | |
| 1666 | @ptrToInt(&stdout_context), | |
| 1667 | @ptrToInt(&stderr_context), | |
| 1668 | ); | |
| 1669 | if (stderr_context.oom or stdout_context.oom) return error.OutOfMemory; | |
| 1670 | if (stdout_context.data.items.len != 0) { | |
| 1671 | std.log.warn("unexpected LLD stdout: {}", .{stdout_context.data.items}); | |
| 1672 | } | |
| 1673 | if (!ok) { | |
| 1674 | // TODO parse this output and surface with the Compilation API rather than | |
| 1675 | // directly outputting to stderr here. | |
| 1676 | std.debug.print("{}", .{stderr_context.data.items}); | |
| 1677 | return error.LLDReportedFailure; | |
| 1678 | } | |
| 1679 | if (stderr_context.data.items.len != 0) { | |
| 1680 | std.log.warn("unexpected LLD stderr: {}", .{stderr_context.data.items}); | |
| 1681 | } | |
| 1625 | var stderr_context: LLDContext = .{ | |
| 1626 | .elf = self, | |
| 1627 | .data = std.ArrayList(u8).init(self.base.allocator), | |
| 1628 | }; | |
| 1629 | defer stderr_context.data.deinit(); | |
| 1630 | var stdout_context: LLDContext = .{ | |
| 1631 | .elf = self, | |
| 1632 | .data = std.ArrayList(u8).init(self.base.allocator), | |
| 1633 | }; | |
| 1634 | defer stdout_context.data.deinit(); | |
| 1635 | const llvm = @import("../llvm.zig"); | |
| 1636 | const ok = llvm.Link( | |
| 1637 | .ELF, | |
| 1638 | new_argv.ptr, | |
| 1639 | new_argv.len, | |
| 1640 | append_diagnostic, | |
| 1641 | @ptrToInt(&stdout_context), | |
| 1642 | @ptrToInt(&stderr_context), | |
| 1643 | ); | |
| 1644 | if (stderr_context.oom or stdout_context.oom) return error.OutOfMemory; | |
| 1645 | if (stdout_context.data.items.len != 0) { | |
| 1646 | std.log.warn("unexpected LLD stdout: {}", .{stdout_context.data.items}); | |
| 1647 | } | |
| 1648 | if (!ok) { | |
| 1649 | // TODO parse this output and surface with the Compilation API rather than | |
| 1650 | // directly outputting to stderr here. | |
| 1651 | std.debug.print("{}", .{stderr_context.data.items}); | |
| 1652 | return error.LLDReportedFailure; | |
| 1653 | } | |
| 1654 | if (stderr_context.data.items.len != 0) { | |
| 1655 | std.log.warn("unexpected LLD stderr: {}", .{stderr_context.data.items}); | |
| 1682 | 1656 | } |
| 1683 | 1657 | |
| 1684 | 1658 | if (!self.base.options.disable_lld_caching) { |
src/link/MachO.zig+6-2| ... | ... | @@ -534,7 +534,9 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 534 | 534 | defer argv.deinit(); |
| 535 | 535 | |
| 536 | 536 | // TODO https://github.com/ziglang/zig/issues/6971 |
| 537 | if (self.base.options.is_native_os and self.base.options.system_linker_hack) { | |
| 537 | // Note that there is no need to check if running natively since we do that already | |
| 538 | // when setting `system_linker_hack` in Compilation struct. | |
| 539 | if (self.base.options.system_linker_hack) { | |
| 538 | 540 | try argv.append("ld"); |
| 539 | 541 | } else { |
| 540 | 542 | // Even though we're calling LLD as a library it thinks the first argument is its own exe name. |
| ... | ... | @@ -710,7 +712,9 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 710 | 712 | } |
| 711 | 713 | |
| 712 | 714 | // TODO https://github.com/ziglang/zig/issues/6971 |
| 713 | if (self.base.options.is_native_os and self.base.options.system_linker_hack) { | |
| 715 | // Note that there is no need to check if running natively since we do that already | |
| 716 | // when setting `system_linker_hack` in Compilation struct. | |
| 717 | if (self.base.options.system_linker_hack) { | |
| 714 | 718 | const result = try std.ChildProcess.exec(.{ .allocator = self.base.allocator, .argv = argv.items }); |
| 715 | 719 | defer { |
| 716 | 720 | self.base.allocator.free(result.stdout); |
src/main.zig-11| ... | ... | @@ -317,7 +317,6 @@ const usage_build_generic = |
| 317 | 317 | \\ --image-base [addr] Set base address for executable image |
| 318 | 318 | \\ -framework [name] (darwin) link against framework |
| 319 | 319 | \\ -F[dir] (darwin) add search path for frameworks |
| 320 | \\ --system-linker-hack Use system linker LD instead of LLD (requires LLVM enabled) | |
| 321 | 320 | \\ |
| 322 | 321 | \\Test Options: |
| 323 | 322 | \\ --test-filter [text] Skip tests that do not match filter |
| ... | ... | @@ -475,7 +474,6 @@ fn buildOutputType( |
| 475 | 474 | var image_base_override: ?u64 = null; |
| 476 | 475 | var use_llvm: ?bool = null; |
| 477 | 476 | var use_lld: ?bool = null; |
| 478 | var system_linker_hack = false; | |
| 479 | 477 | var use_clang: ?bool = null; |
| 480 | 478 | var link_eh_frame_hdr = false; |
| 481 | 479 | var link_emit_relocs = false; |
| ... | ... | @@ -917,8 +915,6 @@ fn buildOutputType( |
| 917 | 915 | mem.startsWith(u8, arg, "-I")) |
| 918 | 916 | { |
| 919 | 917 | try clang_argv.append(arg); |
| 920 | } else if (mem.startsWith(u8, arg, "--system-linker-hack")) { | |
| 921 | system_linker_hack = true; | |
| 922 | 918 | } else { |
| 923 | 919 | fatal("unrecognized parameter: '{}'", .{arg}); |
| 924 | 920 | } |
| ... | ... | @@ -1643,7 +1639,6 @@ fn buildOutputType( |
| 1643 | 1639 | .want_valgrind = want_valgrind, |
| 1644 | 1640 | .use_llvm = use_llvm, |
| 1645 | 1641 | .use_lld = use_lld, |
| 1646 | .system_linker_hack = system_linker_hack, | |
| 1647 | 1642 | .use_clang = use_clang, |
| 1648 | 1643 | .rdynamic = rdynamic, |
| 1649 | 1644 | .linker_script = linker_script, |
| ... | ... | @@ -2165,7 +2160,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 2165 | 2160 | var override_global_cache_dir: ?[]const u8 = null; |
| 2166 | 2161 | var override_local_cache_dir: ?[]const u8 = null; |
| 2167 | 2162 | var child_argv = std.ArrayList([]const u8).init(arena); |
| 2168 | var system_linker_hack = false; | |
| 2169 | 2163 | |
| 2170 | 2164 | const argv_index_exe = child_argv.items.len; |
| 2171 | 2165 | _ = try child_argv.addOne(); |
| ... | ... | @@ -2206,10 +2200,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 2206 | 2200 | override_global_cache_dir = args[i]; |
| 2207 | 2201 | try child_argv.appendSlice(&[_][]const u8{ arg, args[i] }); |
| 2208 | 2202 | continue; |
| 2209 | } else if (mem.eql(u8, arg, "--system-linker-hack")) { | |
| 2210 | system_linker_hack = true; | |
| 2211 | try child_argv.append(arg); | |
| 2212 | continue; | |
| 2213 | 2203 | } |
| 2214 | 2204 | } |
| 2215 | 2205 | try child_argv.append(arg); |
| ... | ... | @@ -2345,7 +2335,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 2345 | 2335 | .optimize_mode = .Debug, |
| 2346 | 2336 | .self_exe_path = self_exe_path, |
| 2347 | 2337 | .rand = &default_prng.random, |
| 2348 | .system_linker_hack = system_linker_hack, | |
| 2349 | 2338 | }) catch |err| { |
| 2350 | 2339 | fatal("unable to create compilation: {}", .{@errorName(err)}); |
| 2351 | 2340 | }; |