| ... | ... | @@ -93,6 +93,9 @@ libc_static_lib: ?CRTFile = null, |
| 93 | 93 | /// Populated when we build the libcompiler_rt static library. A Job to build this is placed in the queue |
| 94 | 94 | /// and resolved before calling linker.flush(). |
| 95 | 95 | compiler_rt_static_lib: ?CRTFile = null, |
| 96 | /// Populated when we build the compiler_rt_obj object. A Job to build this is placed in the queue |
| 97 | /// and resolved before calling linker.flush(). |
| 98 | compiler_rt_obj: ?CRTFile = null, |
| 96 | 99 | |
| 97 | 100 | glibc_so_files: ?glibc.BuiltSharedObjects = null, |
| 98 | 101 | |
| ... | ... | @@ -166,6 +169,8 @@ const Job = union(enum) { |
| 166 | 169 | libssp: void, |
| 167 | 170 | /// needed when producing a dynamic library or executable |
| 168 | 171 | libcompiler_rt: void, |
| 172 | /// needed when producing a static library with bundle-compiler-rt |
| 173 | compiler_rt_obj: void, |
| 169 | 174 | /// needed when not linking libc and using LLVM for code generation because it generates |
| 170 | 175 | /// calls to, for example, memcpy and memset. |
| 171 | 176 | zig_libc: void, |
| ... | ... | @@ -387,6 +392,7 @@ pub const InitOptions = struct { |
| 387 | 392 | parent_compilation_link_libc: bool = false, |
| 388 | 393 | stack_size_override: ?u64 = null, |
| 389 | 394 | image_base_override: ?u64 = null, |
| 395 | bundle_compiler_rt: bool = false, |
| 390 | 396 | self_exe_path: ?[]const u8 = null, |
| 391 | 397 | version: ?std.builtin.Version = null, |
| 392 | 398 | libc_installation: ?*const LibCInstallation = null, |
| ... | ... | @@ -404,6 +410,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 404 | 410 | .Obj, .Exe => false, |
| 405 | 411 | .Lib => (options.link_mode orelse .Static) == .Dynamic, |
| 406 | 412 | }; |
| 413 | const is_static_lib = switch (options.output_mode) { |
| 414 | .Obj, .Exe => false, |
| 415 | .Lib => (options.link_mode orelse .Static) == .Static, |
| 416 | }; |
| 407 | 417 | const is_exe_or_dyn_lib = switch (options.output_mode) { |
| 408 | 418 | .Obj => false, |
| 409 | 419 | .Lib => is_dyn_lib, |
| ... | ... | @@ -821,6 +831,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 821 | 831 | .z_defs = options.linker_z_defs, |
| 822 | 832 | .stack_size_override = options.stack_size_override, |
| 823 | 833 | .image_base_override = options.image_base_override, |
| 834 | .bundle_compiler_rt = options.bundle_compiler_rt, |
| 824 | 835 | .linker_script = options.linker_script, |
| 825 | 836 | .version_script = options.version_script, |
| 826 | 837 | .gc_sections = options.linker_gc_sections, |
| ... | ... | @@ -967,10 +978,18 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 967 | 978 | try comp.work_queue.writeItem(.libcxxabi); |
| 968 | 979 | } |
| 969 | 980 | |
| 970 | | const needs_compiler_rt_and_c = is_exe_or_dyn_lib or |
| 981 | const needs_libc = is_exe_or_dyn_lib or |
| 971 | 982 | (comp.getTarget().isWasm() and comp.bin_file.options.output_mode != .Obj); |
| 972 | | if (needs_compiler_rt_and_c and build_options.is_stage1) { |
| 973 | | try comp.work_queue.writeItem(.{ .libcompiler_rt = {} }); |
| 983 | const needs_compiler_rt = options.bundle_compiler_rt or needs_libc; |
| 984 | |
| 985 | if (needs_compiler_rt and build_options.is_stage1) { |
| 986 | if (is_static_lib) { |
| 987 | try comp.work_queue.writeItem(.{ .compiler_rt_obj = {} }); |
| 988 | } else { |
| 989 | try comp.work_queue.writeItem(.{ .libcompiler_rt = {} }); |
| 990 | } |
| 991 | } |
| 992 | if (needs_libc and build_options.is_stage1) { |
| 974 | 993 | // MinGW provides no libssp, use our own implementation. |
| 975 | 994 | if (comp.getTarget().isMinGW()) { |
| 976 | 995 | try comp.work_queue.writeItem(.{ .libssp = {} }); |
| ... | ... | @@ -1380,6 +1399,12 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1380 | 1399 | fatal("unable to build compiler_rt: {}", .{@errorName(err)}); |
| 1381 | 1400 | }; |
| 1382 | 1401 | }, |
| 1402 | .compiler_rt_obj => { |
| 1403 | self.buildOutputFromZig("compiler_rt.zig", .Obj, &self.compiler_rt_obj) catch |err| { |
| 1404 | // TODO Expose this as a normal compile error rather than crashing here. |
| 1405 | fatal("unable to build compiler_rt: {}", .{@errorName(err)}); |
| 1406 | }; |
| 1407 | }, |
| 1383 | 1408 | .libssp => { |
| 1384 | 1409 | self.buildStaticLibFromZig("ssp.zig", &self.libssp_static_lib) catch |err| { |
| 1385 | 1410 | // TODO Expose this as a normal compile error rather than crashing here. |
| ... | ... | @@ -2551,10 +2576,16 @@ pub fn updateSubCompilation(sub_compilation: *Compilation) !void { |
| 2551 | 2576 | } |
| 2552 | 2577 | } |
| 2553 | 2578 | |
| 2554 | | fn buildStaticLibFromZig(comp: *Compilation, src_basename: []const u8, out: *?CRTFile) !void { |
| 2579 | fn buildOutputFromZig( |
| 2580 | comp: *Compilation, |
| 2581 | src_basename: []const u8, |
| 2582 | output_mode: std.builtin.OutputMode, |
| 2583 | out: *?CRTFile, |
| 2584 | ) !void { |
| 2555 | 2585 | const tracy = trace(@src()); |
| 2556 | 2586 | defer tracy.end(); |
| 2557 | 2587 | |
| 2588 | std.debug.assert(output_mode != .Exe); |
| 2558 | 2589 | const special_sub = "std" ++ std.fs.path.sep_str ++ "special"; |
| 2559 | 2590 | const special_path = try comp.zig_lib_directory.join(comp.gpa, &[_][]const u8{special_sub}); |
| 2560 | 2591 | defer comp.gpa.free(special_path); |
| ... | ... | @@ -2571,11 +2602,11 @@ fn buildStaticLibFromZig(comp: *Compilation, src_basename: []const u8, out: *?CR |
| 2571 | 2602 | }; |
| 2572 | 2603 | const root_name = mem.split(src_basename, ".").next().?; |
| 2573 | 2604 | const target = comp.getTarget(); |
| 2574 | | const output_mode: std.builtin.OutputMode = if (target.cpu.arch.isWasm()) .Obj else .Lib; |
| 2605 | const fixed_output_mode = if (target.cpu.arch.isWasm()) .Obj else output_mode; |
| 2575 | 2606 | const bin_basename = try std.zig.binNameAlloc(comp.gpa, .{ |
| 2576 | 2607 | .root_name = root_name, |
| 2577 | 2608 | .target = target, |
| 2578 | | .output_mode = output_mode, |
| 2609 | .output_mode = fixed_output_mode, |
| 2579 | 2610 | }); |
| 2580 | 2611 | defer comp.gpa.free(bin_basename); |
| 2581 | 2612 | |
| ... | ... | @@ -2598,7 +2629,7 @@ fn buildStaticLibFromZig(comp: *Compilation, src_basename: []const u8, out: *?CR |
| 2598 | 2629 | .target = target, |
| 2599 | 2630 | .root_name = root_name, |
| 2600 | 2631 | .root_pkg = &root_pkg, |
| 2601 | | .output_mode = output_mode, |
| 2632 | .output_mode = fixed_output_mode, |
| 2602 | 2633 | .rand = comp.rand, |
| 2603 | 2634 | .libc_installation = comp.bin_file.options.libc_installation, |
| 2604 | 2635 | .emit_bin = emit_bin, |
| ... | ... | @@ -2639,6 +2670,10 @@ fn buildStaticLibFromZig(comp: *Compilation, src_basename: []const u8, out: *?CR |
| 2639 | 2670 | }; |
| 2640 | 2671 | } |
| 2641 | 2672 | |
| 2673 | fn buildStaticLibFromZig(comp: *Compilation, src_basename: []const u8, out: *?CRTFile) !void { |
| 2674 | return buildOutputFromZig(comp, src_basename, .Lib, out); |
| 2675 | } |
| 2676 | |
| 2642 | 2677 | fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node) !void { |
| 2643 | 2678 | const tracy = trace(@src()); |
| 2644 | 2679 | defer tracy.end(); |