diff options
Diffstat (limited to 'src/link')
| -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 |
4 files changed, 40 insertions, 34 deletions
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)); } |
