diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-10-18 23:57:26 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-10-23 16:27:38 -0700 |
| commit | d1ecb742ec5cb80e29178fddefe6663bed40daa8 (patch) | |
| tree | 7460432fc857653400b4eb884c982f4120755242 /src | |
| parent | de0f7fcf526312088e4b373c6ed7436427080087 (diff) | |
| download | zig-d1ecb742ec5cb80e29178fddefe6663bed40daa8.tar.gz zig-d1ecb742ec5cb80e29178fddefe6663bed40daa8.zip | |
don't create unused musl crt objects
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 16 | ||||
| -rw-r--r-- | src/musl.zig | 20 |
2 files changed, 20 insertions, 16 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 0b058b99a4..870d5faf8f 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1815,15 +1815,13 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil .{ .musl_crt_file = .crtn_o }, }); } - try comp.queueJobs(&[_]Job{ - .{ .musl_crt_file = .crt1_o }, - .{ .musl_crt_file = .scrt1_o }, - .{ .musl_crt_file = .rcrt1_o }, - switch (comp.config.link_mode) { - .static => .{ .musl_crt_file = .libc_a }, - .dynamic => .{ .musl_crt_file = .libc_so }, - }, - }); + if (musl.needsCrt0(comp.config.output_mode, comp.config.link_mode, comp.config.pie)) |f| { + try comp.queueJobs(&.{.{ .musl_crt_file = f }}); + } + try comp.queueJobs(&.{.{ .musl_crt_file = switch (comp.config.link_mode) { + .static => .libc_a, + .dynamic => .libc_so, + } }}); } else if (target.isGnuLibC()) { if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; diff --git a/src/musl.zig b/src/musl.zig index 41a9c89143..975929a59d 100644 --- a/src/musl.zig +++ b/src/musl.zig @@ -292,18 +292,24 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro } } -// Return true if musl has arch-specific crti/crtn sources. -// See lib/libc/musl/crt/ARCH/crt?.s . +/// Return true if musl has arch-specific crti/crtn sources. +/// See lib/libc/musl/crt/ARCH/crt?.s . pub fn needsCrtiCrtn(target: std.Target) bool { - // zig fmt: off return switch (target.cpu.arch) { - .riscv32, - .riscv64, - .wasm32, .wasm64 => false, + .riscv32, .riscv64, .wasm32, .wasm64 => false, .loongarch64 => false, else => true, }; - // zig fmt: on +} + +pub fn needsCrt0(output_mode: std.builtin.OutputMode, link_mode: std.builtin.LinkMode, pie: bool) ?CrtFile { + return switch (output_mode) { + .Obj, .Lib => null, + .Exe => switch (link_mode) { + .dynamic => if (pie) .scrt1_o else .crt1_o, + .static => if (pie) .rcrt1_o else .crt1_o, + }, + }; } fn isMuslArchName(name: []const u8) bool { |
