| ... | ... | @@ -1983,13 +1983,21 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options |
| 1983 | 1983 | if (options.skip_linker_dependencies) break :s .none; |
| 1984 | 1984 | const want = options.want_compiler_rt orelse is_exe_or_dyn_lib; |
| 1985 | 1985 | if (!want) break :s .none; |
| 1986 | | if (have_zcu and target_util.canBuildLibCompilerRt(target, use_llvm, build_options.have_llvm and use_llvm)) { |
| 1986 | const need_llvm = switch (target_util.canBuildLibCompilerRt(target)) { |
| 1987 | .no => break :s .none, // impossible to build |
| 1988 | .yes => false, |
| 1989 | .llvm_only => true, |
| 1990 | }; |
| 1991 | if (have_zcu and (!need_llvm or use_llvm)) { |
| 1987 | 1992 | if (output_mode == .Obj) break :s .zcu; |
| 1988 | | if (switch (target_util.zigBackend(target, use_llvm)) { |
| 1989 | | else => false, |
| 1990 | | .stage2_aarch64, .stage2_x86_64 => target.ofmt == .coff, |
| 1991 | | }) break :s if (is_exe_or_dyn_lib) .dyn_lib else .zcu; |
| 1993 | switch (target_util.zigBackend(target, use_llvm)) { |
| 1994 | else => {}, |
| 1995 | .stage2_aarch64, .stage2_x86_64 => if (target.ofmt == .coff) { |
| 1996 | break :s if (is_exe_or_dyn_lib) .dyn_lib else .zcu; |
| 1997 | }, |
| 1998 | } |
| 1992 | 1999 | } |
| 2000 | if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm |
| 1993 | 2001 | if (is_exe_or_dyn_lib) break :s .lib; |
| 1994 | 2002 | break :s .obj; |
| 1995 | 2003 | }; |
| ... | ... | @@ -2031,14 +2039,22 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options |
| 2031 | 2039 | } |
| 2032 | 2040 | |
| 2033 | 2041 | // unlike compiler_rt, we always want to go through the `_ = @import("ubsan-rt")` |
| 2034 | | // approach, since the ubsan runtime uses quite a lot of the standard library |
| 2035 | | // and this reduces unnecessary bloat. |
| 2042 | // approach if possible, since the ubsan runtime uses quite a lot of the standard |
| 2043 | // library and this reduces unnecessary bloat. |
| 2036 | 2044 | const ubsan_rt_strat: RtStrat = s: { |
| 2037 | | const can_build_ubsan_rt = target_util.canBuildLibUbsanRt(target, use_llvm, build_options.have_llvm); |
| 2038 | | const want_ubsan_rt = options.want_ubsan_rt orelse (can_build_ubsan_rt and any_sanitize_c == .full and is_exe_or_dyn_lib); |
| 2039 | | if (!want_ubsan_rt) break :s .none; |
| 2040 | 2045 | if (options.skip_linker_dependencies) break :s .none; |
| 2041 | | if (have_zcu and target_util.canBuildLibUbsanRt(target, use_llvm, build_options.have_llvm and use_llvm)) break :s .zcu; |
| 2046 | const want = options.want_ubsan_rt orelse (any_sanitize_c == .full and is_exe_or_dyn_lib); |
| 2047 | if (!want) break :s .none; |
| 2048 | const need_llvm = switch (target_util.canBuildLibUbsanRt(target)) { |
| 2049 | .no => break :s .none, // impossible to build |
| 2050 | .yes => false, |
| 2051 | .llvm_only => true, |
| 2052 | .llvm_lld_only => if (!options.config.use_lld) { |
| 2053 | break :s .none; // only LLD can handle ubsan-rt for this target |
| 2054 | } else true, |
| 2055 | }; |
| 2056 | if (have_zcu and (!need_llvm or use_llvm)) break :s .zcu; |
| 2057 | if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm |
| 2042 | 2058 | if (is_exe_or_dyn_lib) break :s .lib; |
| 2043 | 2059 | break :s .obj; |
| 2044 | 2060 | }; |
| ... | ... | @@ -2476,8 +2492,6 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options |
| 2476 | 2492 | }; |
| 2477 | 2493 | errdefer comp.destroy(); |
| 2478 | 2494 | |
| 2479 | | const can_build_compiler_rt = target_util.canBuildLibCompilerRt(target, use_llvm, build_options.have_llvm); |
| 2480 | | |
| 2481 | 2495 | // Add a `CObject` for each `c_source_files`. |
| 2482 | 2496 | try comp.c_object_table.ensureTotalCapacity(gpa, options.c_source_files.len); |
| 2483 | 2497 | for (options.c_source_files) |c_source_file| { |
| ... | ... | @@ -2637,33 +2651,39 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options |
| 2637 | 2651 | comp.queued_jobs.libtsan = true; |
| 2638 | 2652 | } |
| 2639 | 2653 | |
| 2640 | | if (can_build_compiler_rt) { |
| 2641 | | if (comp.compiler_rt_strat == .lib) { |
| 2654 | switch (comp.compiler_rt_strat) { |
| 2655 | .none, .zcu => {}, |
| 2656 | .lib => { |
| 2642 | 2657 | log.debug("queuing a job to build compiler_rt_lib", .{}); |
| 2643 | 2658 | comp.queued_jobs.compiler_rt_lib = true; |
| 2644 | | } else if (comp.compiler_rt_strat == .obj) { |
| 2659 | }, |
| 2660 | .obj => { |
| 2645 | 2661 | log.debug("queuing a job to build compiler_rt_obj", .{}); |
| 2646 | | // In this case we are making a static library, so we ask |
| 2647 | | // for a compiler-rt object to put in it. |
| 2648 | 2662 | comp.queued_jobs.compiler_rt_obj = true; |
| 2649 | | } else if (comp.compiler_rt_strat == .dyn_lib) { |
| 2663 | }, |
| 2664 | .dyn_lib => { |
| 2650 | 2665 | // hack for stage2_x86_64 + coff |
| 2651 | 2666 | log.debug("queuing a job to build compiler_rt_dyn_lib", .{}); |
| 2652 | 2667 | comp.queued_jobs.compiler_rt_dyn_lib = true; |
| 2653 | | } |
| 2668 | }, |
| 2669 | } |
| 2654 | 2670 | |
| 2655 | | if (comp.ubsan_rt_strat == .lib) { |
| 2671 | switch (comp.ubsan_rt_strat) { |
| 2672 | .none, .zcu => {}, |
| 2673 | .lib => { |
| 2656 | 2674 | log.debug("queuing a job to build ubsan_rt_lib", .{}); |
| 2657 | 2675 | comp.queued_jobs.ubsan_rt_lib = true; |
| 2658 | | } else if (comp.ubsan_rt_strat == .obj) { |
| 2676 | }, |
| 2677 | .obj => { |
| 2659 | 2678 | log.debug("queuing a job to build ubsan_rt_obj", .{}); |
| 2660 | 2679 | comp.queued_jobs.ubsan_rt_obj = true; |
| 2661 | | } |
| 2680 | }, |
| 2681 | .dyn_lib => unreachable, // hack for compiler_rt only |
| 2682 | } |
| 2662 | 2683 | |
| 2663 | | if (is_exe_or_dyn_lib and comp.config.any_fuzz) { |
| 2664 | | log.debug("queuing a job to build libfuzzer", .{}); |
| 2665 | | comp.queued_jobs.fuzzer_lib = true; |
| 2666 | | } |
| 2684 | if (is_exe_or_dyn_lib and comp.config.any_fuzz) { |
| 2685 | log.debug("queuing a job to build libfuzzer", .{}); |
| 2686 | comp.queued_jobs.fuzzer_lib = true; |
| 2667 | 2687 | } |
| 2668 | 2688 | } |
| 2669 | 2689 | |
| ... | ... | @@ -7638,11 +7658,11 @@ pub fn dump_argv(argv: []const []const u8) void { |
| 7638 | 7658 | const stderr = std.debug.lockStderrWriter(&buffer); |
| 7639 | 7659 | defer std.debug.unlockStderrWriter(); |
| 7640 | 7660 | nosuspend { |
| 7641 | | for (argv) |arg| { |
| 7661 | for (argv, 0..) |arg, i| { |
| 7662 | if (i != 0) stderr.writeByte(' ') catch return; |
| 7642 | 7663 | stderr.writeAll(arg) catch return; |
| 7643 | | (stderr.writableArray(1) catch return)[0] = ' '; |
| 7644 | 7664 | } |
| 7645 | | stderr.buffer[stderr.end - 1] = '\n'; |
| 7665 | stderr.writeByte('\n') catch return; |
| 7646 | 7666 | } |
| 7647 | 7667 | } |
| 7648 | 7668 | |