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...@@ -1815,15 +1815,13 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1815 .{ .musl_crt_file = .crtn_o },1815 .{ .musl_crt_file = .crtn_o },
1816 });1816 });
1817 }1817 }
1818 try comp.queueJobs(&[_]Job{1818 if (musl.needsCrt0(comp.config.output_mode, comp.config.link_mode, comp.config.pie)) |f| {
1819 .{ .musl_crt_file = .crt1_o },1819 try comp.queueJobs(&.{.{ .musl_crt_file = f }});
1820 .{ .musl_crt_file = .scrt1_o },1820 }
1821 .{ .musl_crt_file = .rcrt1_o },1821 try comp.queueJobs(&.{.{ .musl_crt_file = switch (comp.config.link_mode) {
1822 switch (comp.config.link_mode) {1822 .static => .libc_a,
1823 .static => .{ .musl_crt_file = .libc_a },1823 .dynamic => .libc_so,
1824 .dynamic => .{ .musl_crt_file = .libc_so },1824 } }});
1825 },
1826 });
1827 } else if (target.isGnuLibC()) {1825 } else if (target.isGnuLibC()) {
1828 if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;1826 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...@@ -292,18 +292,24 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
292 }292 }
293}293}
294294
295// Return true if musl has arch-specific crti/crtn sources.295/// Return true if musl has arch-specific crti/crtn sources.
296// See lib/libc/musl/crt/ARCH/crt?.s .296/// See lib/libc/musl/crt/ARCH/crt?.s .
297pub fn needsCrtiCrtn(target: std.Target) bool {297pub fn needsCrtiCrtn(target: std.Target) bool {
298 // zig fmt: off
299 return switch (target.cpu.arch) {298 return switch (target.cpu.arch) {
300 .riscv32,299 .riscv32, .riscv64, .wasm32, .wasm64 => false,
301 .riscv64,
302 .wasm32, .wasm64 => false,
303 .loongarch64 => false,300 .loongarch64 => false,
304 else => true,301 else => true,
305 };302 };
306 // zig fmt: on303}
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 };
307}313}
308314
309fn isMuslArchName(name: []const u8) bool {315fn isMuslArchName(name: []const u8) bool {