diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 66 | ||||
| -rw-r--r-- | src/libtsan.zig | 18 | ||||
| -rw-r--r-- | src/link/Coff.zig | 11 | ||||
| -rw-r--r-- | src/link/Elf.zig | 14 | ||||
| -rw-r--r-- | src/link/MachO.zig | 12 | ||||
| -rw-r--r-- | src/link/Wasm.zig | 37 | ||||
| -rw-r--r-- | src/musl.zig | 3 | ||||
| -rw-r--r-- | src/wasi_libc.zig | 3 |
8 files changed, 76 insertions, 88 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index e245feb9bf..c1d6ef70c8 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -235,7 +235,7 @@ ubsan_rt_lib: ?CrtFile = null, ubsan_rt_obj: ?CrtFile = null, /// Populated when we build the libc static library. A Job to build this is placed in the queue /// and resolved before calling linker.flush(). -libc_static_lib: ?CrtFile = null, +zigc_static_lib: ?CrtFile = null, /// Populated when we build the libcompiler_rt static library. A Job to build this is indicated /// by setting `queued_jobs.compiler_rt_lib` and resolved before calling linker.flush(). compiler_rt_lib: ?CrtFile = null, @@ -307,7 +307,7 @@ const QueuedJobs = struct { libcxx: bool = false, libcxxabi: bool = false, libtsan: bool = false, - zig_libc: bool = false, + zigc_lib: bool = false, }; pub const default_stack_protector_buffer_size = target_util.default_stack_protector_buffer_size; @@ -801,7 +801,7 @@ pub const MiscTask = enum { libfuzzer, wasi_libc_crt_file, compiler_rt, - zig_libc, + libzigc, analyze_mod, docs_copy, docs_wasm, @@ -1759,7 +1759,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil const target = comp.root_mod.resolved_target.result; const capable_of_building_compiler_rt = canBuildLibCompilerRt(target, comp.config.use_llvm); - const capable_of_building_zig_libc = canBuildZigLibC(target, comp.config.use_llvm); // Add a `CObject` for each `c_source_files`. try comp.c_object_table.ensureTotalCapacity(gpa, options.c_source_files.len); @@ -1891,12 +1890,17 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil // When linking mingw-w64 there are some import libs we always need. try comp.windows_libs.ensureUnusedCapacity(gpa, mingw.always_link_libs.len); for (mingw.always_link_libs) |name| comp.windows_libs.putAssumeCapacity(name, {}); - } else if (target.os.tag == .freestanding and capable_of_building_zig_libc) { - comp.queued_jobs.zig_libc = true; - comp.remaining_prelink_tasks += 1; } else { return error.LibCUnavailable; } + + if ((target.isMuslLibC() and comp.config.link_mode == .static) or + target.isWasiLibC() or + target.isMinGW()) + { + comp.queued_jobs.zigc_lib = true; + comp.remaining_prelink_tasks += 1; + } } // Generate Windows import libs. @@ -2010,7 +2014,7 @@ pub fn destroy(comp: *Compilation) void { crt_file.deinit(gpa); } - if (comp.libc_static_lib) |*crt_file| { + if (comp.zigc_static_lib) |*crt_file| { crt_file.deinit(gpa); } @@ -3761,23 +3765,23 @@ fn performAllTheWorkInner( // compiler-rt due to LLD bugs as well, e.g.: // // https://github.com/llvm/llvm-project/issues/43698#issuecomment-2542660611 - comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Lib, false, &comp.compiler_rt_lib, main_progress_node }); + comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", "compiler_rt", .compiler_rt, .Lib, false, &comp.compiler_rt_lib, main_progress_node }); } if (comp.queued_jobs.compiler_rt_obj and comp.compiler_rt_obj == null) { - comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Obj, false, &comp.compiler_rt_obj, main_progress_node }); + comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", "compiler_rt", .compiler_rt, .Obj, false, &comp.compiler_rt_obj, main_progress_node }); } if (comp.queued_jobs.fuzzer_lib and comp.fuzzer_lib == null) { - comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", .libfuzzer, .Lib, true, &comp.fuzzer_lib, main_progress_node }); + comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", "fuzzer", .libfuzzer, .Lib, true, &comp.fuzzer_lib, main_progress_node }); } if (comp.queued_jobs.ubsan_rt_lib and comp.ubsan_rt_lib == null) { - comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "ubsan_rt.zig", .libubsan, .Lib, false, &comp.ubsan_rt_lib, main_progress_node }); + comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "ubsan_rt.zig", "ubsan_rt", .libubsan, .Lib, false, &comp.ubsan_rt_lib, main_progress_node }); } if (comp.queued_jobs.ubsan_rt_obj and comp.ubsan_rt_obj == null) { - comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "ubsan_rt.zig", .libubsan, .Obj, false, &comp.ubsan_rt_obj, main_progress_node }); + comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "ubsan_rt.zig", "ubsan_rt", .libubsan, .Obj, false, &comp.ubsan_rt_obj, main_progress_node }); } if (comp.queued_jobs.glibc_shared_objects) { @@ -3800,8 +3804,8 @@ fn performAllTheWorkInner( comp.link_task_wait_group.spawnManager(buildLibTsan, .{ comp, main_progress_node }); } - if (comp.queued_jobs.zig_libc and comp.libc_static_lib == null) { - comp.link_task_wait_group.spawnManager(buildZigLibc, .{ comp, main_progress_node }); + if (comp.queued_jobs.zigc_lib and comp.zigc_static_lib == null) { + comp.link_task_wait_group.spawnManager(buildLibZigC, .{ comp, main_progress_node }); } for (0..@typeInfo(musl.CrtFile).@"enum".fields.len) |i| { @@ -4764,6 +4768,7 @@ fn workerUpdateWin32Resource( fn buildRt( comp: *Compilation, root_source_name: []const u8, + root_name: []const u8, misc_task: MiscTask, output_mode: std.builtin.OutputMode, allow_lto: bool, @@ -4772,6 +4777,7 @@ fn buildRt( ) void { comp.buildOutputFromZig( root_source_name, + root_name, output_mode, allow_lto, out, @@ -4877,17 +4883,18 @@ fn buildLibTsan(comp: *Compilation, prog_node: std.Progress.Node) void { } } -fn buildZigLibc(comp: *Compilation, prog_node: std.Progress.Node) void { +fn buildLibZigC(comp: *Compilation, prog_node: std.Progress.Node) void { comp.buildOutputFromZig( "c.zig", + "zigc", .Lib, true, - &comp.libc_static_lib, - .zig_libc, + &comp.zigc_static_lib, + .libzigc, prog_node, ) catch |err| switch (err) { error.SubCompilationFailed => return, // error reported already - else => comp.lockAndSetMiscFailure(.zig_libc, "unable to build zig's multitarget libc: {s}", .{@errorName(err)}), + else => comp.lockAndSetMiscFailure(.libzigc, "unable to build libzigc: {s}", .{@errorName(err)}), }; } @@ -6511,25 +6518,6 @@ fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool) bool { }; } -/// Not to be confused with canBuildLibC, which builds musl, glibc, and similar. -/// This one builds lib/c.zig. -fn canBuildZigLibC(target: std.Target, use_llvm: bool) bool { - switch (target.os.tag) { - .plan9 => return false, - else => {}, - } - switch (target.cpu.arch) { - .spirv, .spirv32, .spirv64 => return false, - else => {}, - } - return switch (target_util.zigBackend(target, use_llvm)) { - .stage2_llvm => true, - .stage2_riscv64 => true, - .stage2_x86_64 => if (target.ofmt == .elf or target.ofmt == .macho) true else build_options.have_llvm, - else => build_options.have_llvm, - }; -} - pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend { const target = comp.root_mod.resolved_target.result; return target_util.zigBackend(target, comp.config.use_llvm); @@ -6570,6 +6558,7 @@ pub fn updateSubCompilation( fn buildOutputFromZig( comp: *Compilation, src_basename: []const u8, + root_name: []const u8, output_mode: std.builtin.OutputMode, allow_lto: bool, out: *?CrtFile, @@ -6633,7 +6622,6 @@ fn buildOutputFromZig( .builtin_mod = null, .builtin_modules = null, // there is only one module in this compilation }); - const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len]; const target = comp.getTarget(); const bin_basename = try std.zig.binNameAlloc(arena, .{ .root_name = root_name, diff --git a/src/libtsan.zig b/src/libtsan.zig index 22c425582b..6f36fb5c8d 100644 --- a/src/libtsan.zig +++ b/src/libtsan.zig @@ -124,7 +124,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); try c_source_files.ensureUnusedCapacity(tsan_sources.len); - const tsan_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"tsan"}); + const tsan_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"libtsan"}); for (tsan_sources) |tsan_src| { var cflags = std.ArrayList([]const u8).init(arena); @@ -134,7 +134,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &.{ "tsan", tsan_src }), + .src_path = try comp.zig_lib_directory.join(arena, &.{ "libtsan", tsan_src }), .extra_flags = cflags.items, .owner = root_mod, }); @@ -155,7 +155,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", tsan_src }), + .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libtsan", tsan_src }), .extra_flags = cflags.items, .owner = root_mod, }); @@ -179,7 +179,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try cflags.append("-DNDEBUG"); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", asm_source }), + .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libtsan", asm_source }), .extra_flags = cflags.items, .owner = root_mod, }); @@ -187,7 +187,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try c_source_files.ensureUnusedCapacity(sanitizer_common_sources.len); const sanitizer_common_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "tsan", "sanitizer_common", + "libtsan", "sanitizer_common", }); for (sanitizer_common_sources) |common_src| { var cflags = std.ArrayList([]const u8).init(arena); @@ -201,7 +201,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "tsan", "sanitizer_common", common_src, + "libtsan", "sanitizer_common", common_src, }), .extra_flags = cflags.items, .owner = root_mod, @@ -225,7 +225,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "tsan", "sanitizer_common", c_src, + "libtsan", "sanitizer_common", c_src, }), .extra_flags = cflags.items, .owner = root_mod, @@ -243,7 +243,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "tsan", "sanitizer_common", c_src, + "libtsan", "sanitizer_common", c_src, }), .extra_flags = cflags.items, .owner = root_mod, @@ -269,7 +269,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ - "tsan", "interception", c_src, + "libtsan", "interception", c_src, }), .extra_flags = cflags.items, .owner = root_mod, diff --git a/src/link/Coff.zig b/src/link/Coff.zig index da27c5c076..4b20ba99dd 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -2147,6 +2147,12 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: }, } + if (comp.config.link_libc and link_in_crt) { + if (comp.zigc_static_lib) |zigc| { + try argv.append(try zigc.full_object_path.toString(arena)); + } + } + // libc++ dep if (comp.config.link_libcpp) { try argv.append(try comp.libcxxabi_static_lib.?.full_object_path.toString(arena)); @@ -2172,11 +2178,6 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: } if (is_exe_or_dyn_lib and !comp.skip_linker_dependencies) { - if (!comp.config.link_libc) { - if (comp.libc_static_lib) |lib| { - try argv.append(try lib.full_object_path.toString(arena)); - } - } // MSVC compiler_rt is missing some stuff, so we build it unconditionally but // and rely on weak linkage to allow MSVC compiler_rt functions to override ours. if (comp.compiler_rt_obj) |obj| try argv.append(try obj.full_object_path.toString(arena)); diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 53f88101b1..00bd940500 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1984,16 +1984,6 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s try argv.append(try p.toString(arena)); } - // libc - if (is_exe_or_dyn_lib and - !comp.skip_linker_dependencies and - !comp.config.link_libc) - { - if (comp.libc_static_lib) |lib| { - try argv.append(try lib.full_object_path.toString(arena)); - } - } - // Shared libraries. if (is_exe_or_dyn_lib) { // Worst-case, we need an --as-needed argument for every lib, as well @@ -2071,6 +2061,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s } else { diags.flags.missing_libc = true; } + + if (comp.zigc_static_lib) |zigc| { + try argv.append(try zigc.full_object_path.toString(arena)); + } } } diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 2b4bc3e557..2043be3e7b 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -454,6 +454,17 @@ pub fn flushModule( system_libs.appendAssumeCapacity(.{ .path = comp.libcxx_static_lib.?.full_object_path }); } + const is_exe_or_dyn_lib = comp.config.output_mode == .Exe or + (comp.config.output_mode == .Lib and comp.config.link_mode == .dynamic); + + if (comp.config.link_libc and is_exe_or_dyn_lib) { + if (comp.zigc_static_lib) |zigc| { + const path = zigc.full_object_path; + self.classifyInputFile(try link.openArchiveInput(diags, path, false, false)) catch |err| + diags.addParseError(path, "failed to parse archive: {s}", .{@errorName(err)}); + } + } + // libc/libSystem dep self.resolveLibSystem(arena, comp, &system_libs) catch |err| switch (err) { error.MissingLibSystem => {}, // already reported @@ -831,6 +842,7 @@ fn dumpArgv(self: *MachO, comp: *Compilation) !void { try argv.append("-lSystem"); + if (comp.zigc_static_lib) |lib| try argv.append(try lib.full_object_path.toString(arena)); if (comp.compiler_rt_lib) |lib| try argv.append(try lib.full_object_path.toString(arena)); if (comp.compiler_rt_obj) |obj| try argv.append(try obj.full_object_path.toString(arena)); if (comp.ubsan_rt_lib) |lib| try argv.append(try lib.full_object_path.toString(arena)); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 0d996aff15..466d4aa6bb 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -4100,10 +4100,11 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: try argv.append("-mwasm64"); } - if (target.os.tag == .wasi) { - const is_exe_or_dyn_lib = comp.config.output_mode == .Exe or - (comp.config.output_mode == .Lib and comp.config.link_mode == .dynamic); - if (is_exe_or_dyn_lib) { + const is_exe_or_dyn_lib = comp.config.output_mode == .Exe or + (comp.config.output_mode == .Lib and comp.config.link_mode == .dynamic); + + if (comp.config.link_libc and is_exe_or_dyn_lib) { + if (target.os.tag == .wasi) { for (comp.wasi_emulated_libs) |crt_file| { try argv.append(try comp.crtFileAsString( arena, @@ -4111,18 +4112,20 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: )); } - if (comp.config.link_libc) { - try argv.append(try comp.crtFileAsString( - arena, - wasi_libc.execModelCrtFileFullName(comp.config.wasi_exec_model), - )); - try argv.append(try comp.crtFileAsString(arena, "libc.a")); - } + try argv.append(try comp.crtFileAsString( + arena, + wasi_libc.execModelCrtFileFullName(comp.config.wasi_exec_model), + )); + try argv.append(try comp.crtFileAsString(arena, "libc.a")); + } - if (comp.config.link_libcpp) { - try argv.append(try comp.libcxx_static_lib.?.full_object_path.toString(arena)); - try argv.append(try comp.libcxxabi_static_lib.?.full_object_path.toString(arena)); - } + if (comp.zigc_static_lib) |zigc| { + try argv.append(try zigc.full_object_path.toString(arena)); + } + + if (comp.config.link_libcpp) { + try argv.append(try comp.libcxx_static_lib.?.full_object_path.toString(arena)); + try argv.append(try comp.libcxxabi_static_lib.?.full_object_path.toString(arena)); } } @@ -4157,10 +4160,6 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: try argv.append(p); } - if (comp.libc_static_lib) |crt_file| { - try argv.append(try crt_file.full_object_path.toString(arena)); - } - if (compiler_rt_path) |p| { try argv.append(try p.toString(arena)); } diff --git a/src/musl.zig b/src/musl.zig index 12159e8cd2..93e5cc74f0 100644 --- a/src/musl.zig +++ b/src/musl.zig @@ -1859,17 +1859,14 @@ const src_files = [_][]const u8{ "musl/src/string/strcat.c", "musl/src/string/strchr.c", "musl/src/string/strchrnul.c", - "musl/src/string/strcmp.c", "musl/src/string/strcpy.c", "musl/src/string/strcspn.c", "musl/src/string/strdup.c", "musl/src/string/strerror_r.c", "musl/src/string/strlcat.c", "musl/src/string/strlcpy.c", - "musl/src/string/strlen.c", "musl/src/string/strncasecmp.c", "musl/src/string/strncat.c", - "musl/src/string/strncmp.c", "musl/src/string/strncpy.c", "musl/src/string/strndup.c", "musl/src/string/strnlen.c", diff --git a/src/wasi_libc.zig b/src/wasi_libc.zig index 7f1094c81e..33c03e8068 100644 --- a/src/wasi_libc.zig +++ b/src/wasi_libc.zig @@ -1061,17 +1061,14 @@ const libc_top_half_src_files = [_][]const u8{ "musl/src/string/strcat.c", "musl/src/string/strchr.c", "musl/src/string/strchrnul.c", - "musl/src/string/strcmp.c", "musl/src/string/strcpy.c", "musl/src/string/strcspn.c", "musl/src/string/strdup.c", "musl/src/string/strerror_r.c", "musl/src/string/strlcat.c", "musl/src/string/strlcpy.c", - "musl/src/string/strlen.c", "musl/src/string/strncasecmp.c", "musl/src/string/strncat.c", - "musl/src/string/strncmp.c", "musl/src/string/strncpy.c", "musl/src/string/strndup.c", "musl/src/string/strnlen.c", |
