| ... | ... | @@ -374,6 +374,7 @@ pub const InitOptions = struct { |
| 374 | 374 | is_test: bool = false, |
| 375 | 375 | test_evented_io: bool = false, |
| 376 | 376 | is_compiler_rt_or_libc: bool = false, |
| 377 | parent_compilation_link_libc: bool = false, |
| 377 | 378 | stack_size_override: ?u64 = null, |
| 378 | 379 | self_exe_path: ?[]const u8 = null, |
| 379 | 380 | version: ?std.builtin.Version = null, |
| ... | ... | @@ -614,6 +615,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 614 | 615 | hash.add(options.target.os.getVersionRange()); |
| 615 | 616 | hash.add(dll_export_fns); |
| 616 | 617 | hash.add(options.is_test); |
| 618 | hash.add(options.is_compiler_rt_or_libc); |
| 619 | hash.add(options.parent_compilation_link_libc); |
| 617 | 620 | |
| 618 | 621 | const digest = hash.final(); |
| 619 | 622 | const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest }); |
| ... | ... | @@ -781,6 +784,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 781 | 784 | .error_return_tracing = error_return_tracing, |
| 782 | 785 | .llvm_cpu_features = llvm_cpu_features, |
| 783 | 786 | .is_compiler_rt_or_libc = options.is_compiler_rt_or_libc, |
| 787 | .parent_compilation_link_libc = options.parent_compilation_link_libc, |
| 784 | 788 | .each_lib_rpath = options.each_lib_rpath orelse false, |
| 785 | 789 | .disable_lld_caching = options.disable_lld_caching, |
| 786 | 790 | .subsystem = options.subsystem, |
| ... | ... | @@ -848,7 +852,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 848 | 852 | comp.c_object_table.putAssumeCapacityNoClobber(c_object, {}); |
| 849 | 853 | } |
| 850 | 854 | |
| 851 | | if (comp.bin_file.options.emit != null) { |
| 855 | if (comp.bin_file.options.emit != null and !comp.bin_file.options.is_compiler_rt_or_libc) { |
| 852 | 856 | // If we need to build glibc for the target, add work items for it. |
| 853 | 857 | // We go through the work queue so that building can be done in parallel. |
| 854 | 858 | if (comp.wantBuildGLibCFromSource()) { |
| ... | ... | @@ -903,9 +907,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 903 | 907 | try comp.work_queue.writeItem(.libcxx); |
| 904 | 908 | try comp.work_queue.writeItem(.libcxxabi); |
| 905 | 909 | } |
| 906 | | if (is_exe_or_dyn_lib and !comp.bin_file.options.is_compiler_rt_or_libc and |
| 907 | | build_options.is_stage1) |
| 908 | | { |
| 910 | if (is_exe_or_dyn_lib and build_options.is_stage1) { |
| 909 | 911 | try comp.work_queue.writeItem(.{ .libcompiler_rt = {} }); |
| 910 | 912 | if (!comp.bin_file.options.link_libc) { |
| 911 | 913 | try comp.work_queue.writeItem(.{ .zig_libc = {} }); |
| ... | ... | @@ -2345,6 +2347,15 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 |
| 2345 | 2347 | ), |
| 2346 | 2348 | } |
| 2347 | 2349 | try buffer.appendSlice("};\n"); |
| 2350 | |
| 2351 | // This is so that compiler_rt and libc.zig libraries know whether they |
| 2352 | // will eventually be linked with libc. They make different decisions |
| 2353 | // about what to export depending on whether another libc will be linked |
| 2354 | // in. For example, compiler_rt will not export the __chkstk symbol if it |
| 2355 | // knows libc will provide it, and likewise c.zig will not export memcpy. |
| 2356 | const link_libc = comp.bin_file.options.link_libc or |
| 2357 | (comp.bin_file.options.is_compiler_rt_or_libc and comp.bin_file.options.parent_compilation_link_libc); |
| 2358 | |
| 2348 | 2359 | try buffer.writer().print( |
| 2349 | 2360 | \\pub const object_format = ObjectFormat.{}; |
| 2350 | 2361 | \\pub const mode = Mode.{}; |
| ... | ... | @@ -2359,7 +2370,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 |
| 2359 | 2370 | , .{ |
| 2360 | 2371 | @tagName(comp.bin_file.options.object_format), |
| 2361 | 2372 | @tagName(comp.bin_file.options.optimize_mode), |
| 2362 | | comp.bin_file.options.link_libc, |
| 2373 | link_libc, |
| 2363 | 2374 | comp.bin_file.options.link_libcpp, |
| 2364 | 2375 | comp.bin_file.options.error_return_tracing, |
| 2365 | 2376 | comp.bin_file.options.valgrind, |
| ... | ... | @@ -2481,6 +2492,7 @@ fn buildStaticLibFromZig(comp: *Compilation, src_basename: []const u8, out: *?CR |
| 2481 | 2492 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 2482 | 2493 | .clang_passthrough_mode = comp.clang_passthrough_mode, |
| 2483 | 2494 | .is_compiler_rt_or_libc = true, |
| 2495 | .parent_compilation_link_libc = comp.bin_file.options.link_libc, |
| 2484 | 2496 | }); |
| 2485 | 2497 | defer sub_compilation.destroy(); |
| 2486 | 2498 | |
| ... | ... | @@ -2842,12 +2854,7 @@ pub fn build_crt_file( |
| 2842 | 2854 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 2843 | 2855 | .clang_passthrough_mode = comp.clang_passthrough_mode, |
| 2844 | 2856 | .is_compiler_rt_or_libc = true, |
| 2845 | | // This is so that compiler_rt and libc.zig libraries know whether they |
| 2846 | | // will eventually be linked with libc. They make different decisions |
| 2847 | | // about what to export depending on whether another libc will be linked |
| 2848 | | // in. For example, compiler_rt will not export the __chkstk symbol if it |
| 2849 | | // knows libc will provide it, and likewise c.zig will not export memcpy. |
| 2850 | | .link_libc = comp.bin_file.options.link_libc, |
| 2857 | .parent_compilation_link_libc = comp.bin_file.options.link_libc, |
| 2851 | 2858 | }); |
| 2852 | 2859 | defer sub_compilation.destroy(); |
| 2853 | 2860 | |