authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-18 23:57:26-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-23 16:27:38-07:00
logd1ecb742ec5cb80e29178fddefe6663bed40daa8
tree7460432fc857653400b4eb884c982f4120755242
parentde0f7fcf526312088e4b373c6ed7436427080087

don't create unused musl crt objects


2 files changed, 20 insertions(+), 16 deletions(-)

src/Compilation.zig+7-9
......@@ -1815,15 +1815,13 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18151815 .{ .musl_crt_file = .crtn_o },
18161816 });
18171817 }
1818 try comp.queueJobs(&[_]Job{
1819 .{ .musl_crt_file = .crt1_o },
1820 .{ .musl_crt_file = .scrt1_o },
1821 .{ .musl_crt_file = .rcrt1_o },
1822 switch (comp.config.link_mode) {
1823 .static => .{ .musl_crt_file = .libc_a },
1824 .dynamic => .{ .musl_crt_file = .libc_so },
1825 },
1826 });
1818 if (musl.needsCrt0(comp.config.output_mode, comp.config.link_mode, comp.config.pie)) |f| {
1819 try comp.queueJobs(&.{.{ .musl_crt_file = f }});
1820 }
1821 try comp.queueJobs(&.{.{ .musl_crt_file = switch (comp.config.link_mode) {
1822 .static => .libc_a,
1823 .dynamic => .libc_so,
1824 } }});
18271825 } else if (target.isGnuLibC()) {
18281826 if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;
18291827
src/musl.zig+13-7
......@@ -292,18 +292,24 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
292292 }
293293}
294294
295// Return true if musl has arch-specific crti/crtn sources.
296// See lib/libc/musl/crt/ARCH/crt?.s .
295/// Return true if musl has arch-specific crti/crtn sources.
296/// See lib/libc/musl/crt/ARCH/crt?.s .
297297pub fn needsCrtiCrtn(target: std.Target) bool {
298 // zig fmt: off
299298 return switch (target.cpu.arch) {
300 .riscv32,
301 .riscv64,
302 .wasm32, .wasm64 => false,
299 .riscv32, .riscv64, .wasm32, .wasm64 => false,
303300 .loongarch64 => false,
304301 else => true,
305302 };
306 // zig fmt: on
303}
304
305pub fn needsCrt0(output_mode: std.builtin.OutputMode, link_mode: std.builtin.LinkMode, pie: bool) ?CrtFile {
306 return switch (output_mode) {
307 .Obj, .Lib => null,
308 .Exe => switch (link_mode) {
309 .dynamic => if (pie) .scrt1_o else .crt1_o,
310 .static => if (pie) .rcrt1_o else .crt1_o,
311 },
312 };
307313}
308314
309315fn isMuslArchName(name: []const u8) bool {