authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-25 13:17:25-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-01-25 13:17:25-08:00
log8fa47bb904c888dadf20af5eb72b9643eed2bfea
tree47fcc20146a7358b4216668d91c78d3bb712511d
parent015a5e198246f782415586235e0da7085867eb22
parentb60e39fe8f50783509e3cfe7a3888e1611b063c1
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22230 from alexrp/lto-stuff

Disable LTO by default + some LTO fixes

19 files changed, 129 insertions(+), 124 deletions(-)

lib/compiler_rt/arm.zig+24-12
......@@ -15,11 +15,11 @@ comptime {
1515 @export(&__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = common.linkage, .visibility = common.visibility });
1616 @export(&__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = common.linkage, .visibility = common.visibility });
1717
18 @export(&__aeabi_ldivmod, .{ .name = if (target.isMinGW()) "__rt_sdiv64" else "__aeabi_ldivmod", .linkage = common.linkage, .visibility = common.visibility });
19 @export(&__aeabi_uldivmod, .{ .name = if (target.isMinGW()) "__rt_udiv64" else "__aeabi_uldivmod", .linkage = common.linkage, .visibility = common.visibility });
18 @export(&__aeabi_ldivmod, .{ .name = if (common.want_windows_arm_abi) "__rt_sdiv64" else "__aeabi_ldivmod", .linkage = common.linkage, .visibility = common.visibility });
19 @export(&__aeabi_uldivmod, .{ .name = if (common.want_windows_arm_abi) "__rt_udiv64" else "__aeabi_uldivmod", .linkage = common.linkage, .visibility = common.visibility });
2020
21 @export(&__aeabi_idivmod, .{ .name = if (target.isMinGW()) "__rt_sdiv" else "__aeabi_idivmod", .linkage = common.linkage, .visibility = common.visibility });
22 @export(&__aeabi_uidivmod, .{ .name = if (target.isMinGW()) "__rt_udiv" else "__aeabi_uidivmod", .linkage = common.linkage, .visibility = common.visibility });
21 @export(&__aeabi_idivmod, .{ .name = if (common.want_windows_arm_abi) "__rt_sdiv" else "__aeabi_idivmod", .linkage = common.linkage, .visibility = common.visibility });
22 @export(&__aeabi_uidivmod, .{ .name = if (common.want_windows_arm_abi) "__rt_udiv" else "__aeabi_uidivmod", .linkage = common.linkage, .visibility = common.visibility });
2323
2424 @export(&__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = common.linkage, .visibility = common.visibility });
2525 @export(&__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = common.linkage, .visibility = common.visibility });
......@@ -136,11 +136,14 @@ pub fn __aeabi_uidivmod() callconv(.Naked) void {
136136 \\ push {lr}
137137 \\ sub sp, #4
138138 \\ mov r2, sp
139 \\ bl __udivmodsi4
139 \\ bl %[__udivmodsi4]
140140 \\ ldr r1, [sp]
141141 \\ add sp, #4
142142 \\ pop {pc}
143 ::: "memory");
143 :
144 : [__udivmodsi4] "X" (&__udivmodsi4),
145 : "memory"
146 );
144147 unreachable;
145148}
146149
......@@ -152,12 +155,15 @@ pub fn __aeabi_uldivmod() callconv(.Naked) void {
152155 \\ sub sp, #16
153156 \\ add r4, sp, #8
154157 \\ str r4, [sp]
155 \\ bl __udivmoddi4
158 \\ bl %[__udivmoddi4]
156159 \\ ldr r2, [sp, #8]
157160 \\ ldr r3, [sp, #12]
158161 \\ add sp, #16
159162 \\ pop {r4, pc}
160 ::: "memory");
163 :
164 : [__udivmoddi4] "X" (&__udivmoddi4),
165 : "memory"
166 );
161167 unreachable;
162168}
163169
......@@ -168,11 +174,14 @@ pub fn __aeabi_idivmod() callconv(.Naked) void {
168174 \\ push {lr}
169175 \\ sub sp, #4
170176 \\ mov r2, sp
171 \\ bl __divmodsi4
177 \\ bl %[__divmodsi4]
172178 \\ ldr r1, [sp]
173179 \\ add sp, #4
174180 \\ pop {pc}
175 ::: "memory");
181 :
182 : [__divmodsi4] "X" (&__divmodsi4),
183 : "memory"
184 );
176185 unreachable;
177186}
178187
......@@ -184,12 +193,15 @@ pub fn __aeabi_ldivmod() callconv(.Naked) void {
184193 \\ sub sp, #16
185194 \\ add r4, sp, #8
186195 \\ str r4, [sp]
187 \\ bl __divmoddi4
196 \\ bl %[__divmoddi4]
188197 \\ ldr r2, [sp, #8]
189198 \\ ldr r3, [sp, #12]
190199 \\ add sp, #16
191200 \\ pop {r4, pc}
192 ::: "memory");
201 :
202 : [__divmoddi4] "X" (&__divmoddi4),
203 : "memory"
204 );
193205 unreachable;
194206}
195207
lib/compiler_rt/aulldiv.zig+1-1
......@@ -8,7 +8,7 @@ const common = @import("common.zig");
88pub const panic = common.panic;
99
1010comptime {
11 if (arch == .x86 and os == .windows and (abi == .msvc or abi == .itanium) and builtin.zig_backend != .stage2_c) {
11 if (arch == .x86 and os == .windows and (abi == .msvc or abi == .itanium) and !builtin.link_libc) {
1212 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
1313 @export(&_alldiv, .{ .name = "\x01__alldiv", .linkage = common.linkage, .visibility = common.visibility });
1414 @export(&_aulldiv, .{ .name = "\x01__aulldiv", .linkage = common.linkage, .visibility = common.visibility });
lib/compiler_rt/aullrem.zig+1-1
......@@ -8,7 +8,7 @@ const common = @import("common.zig");
88pub const panic = common.panic;
99
1010comptime {
11 if (arch == .x86 and os == .windows and (abi == .msvc or abi == .itanium) and builtin.zig_backend != .stage2_c) {
11 if (arch == .x86 and os == .windows and (abi == .msvc or abi == .itanium) and !builtin.link_libc) {
1212 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
1313 @export(&_allrem, .{ .name = "\x01__allrem", .linkage = common.linkage, .visibility = common.visibility });
1414 @export(&_aullrem, .{ .name = "\x01__aullrem", .linkage = common.linkage, .visibility = common.visibility });
lib/compiler_rt/common.zig+5-1
......@@ -9,11 +9,13 @@ else if (ofmt_c)
99 .strong
1010else
1111 .weak;
12
1213/// Determines the symbol's visibility to other objects.
1314/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
1415/// export it to the host runtime.
1516pub const visibility: std.builtin.SymbolVisibility =
1617 if (builtin.target.isWasm() and linkage != .internal) .hidden else .default;
18
1719pub const want_aeabi = switch (builtin.abi) {
1820 .eabi,
1921 .eabihf,
......@@ -29,7 +31,9 @@ pub const want_aeabi = switch (builtin.abi) {
2931 },
3032 else => false,
3133};
32pub const want_mingw_arm_abi = builtin.cpu.arch.isArm() and builtin.target.isMinGW();
34
35/// These functions are provided by libc when targeting MSVC, but not MinGW.
36pub const want_windows_arm_abi = builtin.cpu.arch.isArm() and builtin.os.tag == .windows and (builtin.abi.isGnu() or !builtin.link_libc);
3337
3438pub const want_ppc_abi = builtin.cpu.arch.isPowerPC();
3539
lib/compiler_rt/fixdfdi.zig+1-5
......@@ -8,11 +8,7 @@ comptime {
88 if (common.want_aeabi) {
99 @export(&__aeabi_d2lz, .{ .name = "__aeabi_d2lz", .linkage = common.linkage, .visibility = common.visibility });
1010 } else {
11 @export(&__fixdfdi, .{ .name = "__fixdfdi", .linkage = common.linkage, .visibility = common.visibility });
12
13 if (common.want_mingw_arm_abi) {
14 @export(&__fixdfdi, .{ .name = "__dtoi64", .linkage = common.linkage, .visibility = common.visibility });
15 }
11 @export(&__fixdfdi, .{ .name = if (common.want_windows_arm_abi) "__dtoi64" else "__fixdfdi", .linkage = common.linkage, .visibility = common.visibility });
1612 }
1713}
1814
lib/compiler_rt/fixsfdi.zig+1-5
......@@ -8,11 +8,7 @@ comptime {
88 if (common.want_aeabi) {
99 @export(&__aeabi_f2lz, .{ .name = "__aeabi_f2lz", .linkage = common.linkage, .visibility = common.visibility });
1010 } else {
11 @export(&__fixsfdi, .{ .name = "__fixsfdi", .linkage = common.linkage, .visibility = common.visibility });
12
13 if (common.want_mingw_arm_abi) {
14 @export(&__fixsfdi, .{ .name = "__stoi64", .linkage = common.linkage, .visibility = common.visibility });
15 }
11 @export(&__fixsfdi, .{ .name = if (common.want_windows_arm_abi) "__stoi64" else "__fixsfdi", .linkage = common.linkage, .visibility = common.visibility });
1612 }
1713}
1814
lib/compiler_rt/fixunsdfdi.zig+1-5
......@@ -8,11 +8,7 @@ comptime {
88 if (common.want_aeabi) {
99 @export(&__aeabi_d2ulz, .{ .name = "__aeabi_d2ulz", .linkage = common.linkage, .visibility = common.visibility });
1010 } else {
11 @export(&__fixunsdfdi, .{ .name = "__fixunsdfdi", .linkage = common.linkage, .visibility = common.visibility });
12
13 if (common.want_mingw_arm_abi) {
14 @export(&__fixunsdfdi, .{ .name = "__dtou64", .linkage = common.linkage, .visibility = common.visibility });
15 }
11 @export(&__fixunsdfdi, .{ .name = if (common.want_windows_arm_abi) "__dtou64" else "__fixunsdfdi", .linkage = common.linkage, .visibility = common.visibility });
1612 }
1713}
1814
lib/compiler_rt/fixunssfdi.zig+1-5
......@@ -8,11 +8,7 @@ comptime {
88 if (common.want_aeabi) {
99 @export(&__aeabi_f2ulz, .{ .name = "__aeabi_f2ulz", .linkage = common.linkage, .visibility = common.visibility });
1010 } else {
11 @export(&__fixunssfdi, .{ .name = "__fixunssfdi", .linkage = common.linkage, .visibility = common.visibility });
12
13 if (common.want_mingw_arm_abi) {
14 @export(&__fixunssfdi, .{ .name = "__stou64", .linkage = common.linkage, .visibility = common.visibility });
15 }
11 @export(&__fixunssfdi, .{ .name = if (common.want_windows_arm_abi) "__stou64" else "__fixunssfdi", .linkage = common.linkage, .visibility = common.visibility });
1612 }
1713}
1814
lib/compiler_rt/floatdidf.zig+1-5
......@@ -8,11 +8,7 @@ comptime {
88 if (common.want_aeabi) {
99 @export(&__aeabi_l2d, .{ .name = "__aeabi_l2d", .linkage = common.linkage, .visibility = common.visibility });
1010 } else {
11 @export(&__floatdidf, .{ .name = "__floatdidf", .linkage = common.linkage, .visibility = common.visibility });
12
13 if (common.want_mingw_arm_abi) {
14 @export(&__floatdidf, .{ .name = "__i64tod", .linkage = common.linkage, .visibility = common.visibility });
15 }
11 @export(&__floatdidf, .{ .name = if (common.want_windows_arm_abi) "__i64tod" else "__floatdidf", .linkage = common.linkage, .visibility = common.visibility });
1612 }
1713}
1814
lib/compiler_rt/floatdisf.zig+1-5
......@@ -8,11 +8,7 @@ comptime {
88 if (common.want_aeabi) {
99 @export(&__aeabi_l2f, .{ .name = "__aeabi_l2f", .linkage = common.linkage, .visibility = common.visibility });
1010 } else {
11 @export(&__floatdisf, .{ .name = "__floatdisf", .linkage = common.linkage, .visibility = common.visibility });
12
13 if (common.want_mingw_arm_abi) {
14 @export(&__floatdisf, .{ .name = "__i64tos", .linkage = common.linkage, .visibility = common.visibility });
15 }
11 @export(&__floatdisf, .{ .name = if (common.want_windows_arm_abi) "__i64tos" else "__floatdisf", .linkage = common.linkage, .visibility = common.visibility });
1612 }
1713}
1814
lib/compiler_rt/floatundidf.zig+1-5
......@@ -8,11 +8,7 @@ comptime {
88 if (common.want_aeabi) {
99 @export(&__aeabi_ul2d, .{ .name = "__aeabi_ul2d", .linkage = common.linkage, .visibility = common.visibility });
1010 } else {
11 @export(&__floatundidf, .{ .name = "__floatundidf", .linkage = common.linkage, .visibility = common.visibility });
12
13 if (common.want_mingw_arm_abi) {
14 @export(&__floatundidf, .{ .name = "__u64tod", .linkage = common.linkage, .visibility = common.visibility });
15 }
11 @export(&__floatundidf, .{ .name = if (common.want_windows_arm_abi) "__u64tod" else "__floatundidf", .linkage = common.linkage, .visibility = common.visibility });
1612 }
1713}
1814
lib/compiler_rt/floatundisf.zig+1-5
......@@ -8,11 +8,7 @@ comptime {
88 if (common.want_aeabi) {
99 @export(&__aeabi_ul2f, .{ .name = "__aeabi_ul2f", .linkage = common.linkage, .visibility = common.visibility });
1010 } else {
11 @export(&__floatundisf, .{ .name = "__floatundisf", .linkage = common.linkage, .visibility = common.visibility });
12
13 if (common.want_mingw_arm_abi) {
14 @export(&__floatundisf, .{ .name = "__u64tos", .linkage = common.linkage, .visibility = common.visibility });
15 }
11 @export(&__floatundisf, .{ .name = if (common.want_windows_arm_abi) "__u64tos" else "__floatundisf", .linkage = common.linkage, .visibility = common.visibility });
1612 }
1713}
1814
src/Compilation.zig+15-16
......@@ -1881,18 +1881,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18811881 comp.remaining_prelink_tasks += 1;
18821882 }
18831883
1884 if (target.isMinGW() and comp.config.any_non_single_threaded) {
1885 // LLD might drop some symbols as unused during LTO and GCing, therefore,
1886 // we force mark them for resolution here.
1887
1888 const tls_index_sym = switch (target.cpu.arch) {
1889 .x86 => "__tls_index",
1890 else => "_tls_index",
1891 };
1892
1893 try comp.force_undefined_symbols.put(comp.gpa, tls_index_sym, {});
1894 }
1895
18961884 if (comp.include_compiler_rt and capable_of_building_compiler_rt) {
18971885 if (is_exe_or_dyn_lib) {
18981886 log.debug("queuing a job to build compiler_rt_lib", .{});
......@@ -3695,15 +3683,19 @@ fn performAllTheWorkInner(
36953683 // In case it failed last time, try again. `clearMiscFailures` was already
36963684 // called at the start of `update`.
36973685 if (comp.queued_jobs.compiler_rt_lib and comp.compiler_rt_lib == null) {
3698 comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Lib, &comp.compiler_rt_lib, main_progress_node });
3686 // LLVM disables LTO for its compiler-rt and we've had various issues with LTO of our
3687 // compiler-rt due to LLD bugs as well, e.g.:
3688 //
3689 // https://github.com/llvm/llvm-project/issues/43698#issuecomment-2542660611
3690 comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Lib, false, &comp.compiler_rt_lib, main_progress_node });
36993691 }
37003692
37013693 if (comp.queued_jobs.compiler_rt_obj and comp.compiler_rt_obj == null) {
3702 comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Obj, &comp.compiler_rt_obj, main_progress_node });
3694 comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Obj, false, &comp.compiler_rt_obj, main_progress_node });
37033695 }
37043696
37053697 if (comp.queued_jobs.fuzzer_lib and comp.fuzzer_lib == null) {
3706 comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", .libfuzzer, .Lib, &comp.fuzzer_lib, main_progress_node });
3698 comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", .libfuzzer, .Lib, true, &comp.fuzzer_lib, main_progress_node });
37073699 }
37083700
37093701 if (comp.queued_jobs.glibc_shared_objects) {
......@@ -4635,12 +4627,14 @@ fn buildRt(
46354627 root_source_name: []const u8,
46364628 misc_task: MiscTask,
46374629 output_mode: std.builtin.OutputMode,
4630 allow_lto: bool,
46384631 out: *?CrtFile,
46394632 prog_node: std.Progress.Node,
46404633) void {
46414634 comp.buildOutputFromZig(
46424635 root_source_name,
46434636 output_mode,
4637 allow_lto,
46444638 out,
46454639 misc_task,
46464640 prog_node,
......@@ -4748,6 +4742,7 @@ fn buildZigLibc(comp: *Compilation, prog_node: std.Progress.Node) void {
47484742 comp.buildOutputFromZig(
47494743 "c.zig",
47504744 .Lib,
4745 true,
47514746 &comp.libc_static_lib,
47524747 .zig_libc,
47534748 prog_node,
......@@ -6453,6 +6448,7 @@ fn buildOutputFromZig(
64536448 comp: *Compilation,
64546449 src_basename: []const u8,
64556450 output_mode: std.builtin.OutputMode,
6451 allow_lto: bool,
64566452 out: *?CrtFile,
64576453 misc_task_tag: MiscTask,
64586454 prog_node: std.Progress.Node,
......@@ -6481,6 +6477,7 @@ fn buildOutputFromZig(
64816477 .root_strip = strip,
64826478 .link_libc = comp.config.link_libc,
64836479 .any_unwind_tables = comp.root_mod.unwind_tables != .none,
6480 .lto = if (allow_lto) comp.config.lto else .none,
64846481 });
64856482
64866483 const root_mod = try Package.Module.create(arena, .{
......@@ -6581,6 +6578,8 @@ pub const CrtFileOptions = struct {
65816578 unwind_tables: ?std.builtin.UnwindTables = null,
65826579 pic: ?bool = null,
65836580 no_builtin: ?bool = null,
6581
6582 allow_lto: bool = true,
65846583};
65856584
65866585pub fn build_crt_file(
......@@ -6619,7 +6618,7 @@ pub fn build_crt_file(
66196618 .link_libc = false,
66206619 .any_unwind_tables = options.unwind_tables != .none,
66216620 .lto = switch (output_mode) {
6622 .Lib => comp.config.lto,
6621 .Lib => if (options.allow_lto) comp.config.lto else .none,
66236622 .Obj, .Exe => .none,
66246623 },
66256624 });
src/Compilation/Config.zig+1-20
......@@ -295,27 +295,8 @@ pub fn resolve(options: Options) ResolveError!Config {
295295 }
296296
297297 if (options.lto) |x| break :b x;
298 if (!options.any_c_source_files) break :b .none;
299
300 // https://github.com/llvm/llvm-project/pull/116537
301 switch (target.abi) {
302 .gnuabin32,
303 .gnuilp32,
304 .gnux32,
305 .ilp32,
306 .muslabin32,
307 .muslx32,
308 => break :b .none,
309 else => {},
310 }
311298
312 break :b switch (options.output_mode) {
313 .Lib, .Obj => .none,
314 .Exe => switch (root_optimize_mode) {
315 .Debug => .none,
316 .ReleaseSafe, .ReleaseFast, .ReleaseSmall => .full,
317 },
318 };
299 break :b .none;
319300 };
320301
321302 const link_libcpp = b: {
src/libtsan.zig+6
......@@ -53,6 +53,8 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
5353 const optimize_mode = comp.compilerRtOptMode();
5454 const strip = comp.compilerRtStrip();
5555 const link_libcpp = target.isDarwin();
56 const unwind_tables: std.builtin.UnwindTables =
57 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .@"async";
5658
5759 const config = Compilation.Config.resolve(.{
5860 .output_mode = output_mode,
......@@ -65,6 +67,9 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
6567 .root_strip = strip,
6668 .link_libc = true,
6769 .link_libcpp = link_libcpp,
70 .any_unwind_tables = unwind_tables != .none,
71 // LLVM disables LTO for its libtsan.
72 .lto = .none,
6873 }) catch |err| {
6974 comp.setMiscFailure(
7075 .libtsan,
......@@ -95,6 +100,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
95100 .red_zone = comp.root_mod.red_zone,
96101 .omit_frame_pointer = optimize_mode != .Debug and !target.os.tag.isDarwin(),
97102 .valgrind = false,
103 .unwind_tables = unwind_tables,
98104 .optimize_mode = optimize_mode,
99105 .structured_cfg = comp.root_mod.structured_cfg,
100106 .pic = true,
src/link/Coff.zig+7
......@@ -1876,6 +1876,13 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
18761876 if (comp.version) |version| {
18771877 try argv.append(try allocPrint(arena, "-VERSION:{}.{}", .{ version.major, version.minor }));
18781878 }
1879
1880 if (target_util.llvmMachineAbi(target)) |mabi| {
1881 try argv.append(try allocPrint(arena, "-MLLVM:-target-abi={s}", .{mabi}));
1882 }
1883
1884 try argv.append(try allocPrint(arena, "-MLLVM:-float-abi={s}", .{if (target.abi.floatAbi() == .hard) "hard" else "soft"}));
1885
18791886 if (comp.config.lto != .none) {
18801887 switch (optimize_mode) {
18811888 .Debug => {},
src/link/Elf.zig+12
......@@ -1700,6 +1700,18 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
17001700 try argv.append(try std.fmt.allocPrint(arena, "--sysroot={s}", .{sysroot}));
17011701 }
17021702
1703 if (target_util.llvmMachineAbi(target)) |mabi| {
1704 try argv.appendSlice(&.{
1705 "-mllvm",
1706 try std.fmt.allocPrint(arena, "-target-abi={s}", .{mabi}),
1707 });
1708 }
1709
1710 try argv.appendSlice(&.{
1711 "-mllvm",
1712 try std.fmt.allocPrint(arena, "-float-abi={s}", .{if (target.abi.floatAbi() == .hard) "hard" else "soft"}),
1713 });
1714
17031715 if (comp.config.lto != .none) {
17041716 switch (comp.root_mod.optimize_mode) {
17051717 .Debug => {},
src/mingw.zig+2
......@@ -175,6 +175,8 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
175175
176176 return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{
177177 .unwind_tables = unwind_tables,
178 // https://github.com/llvm/llvm-project/issues/43698#issuecomment-2542660611
179 .allow_lto = false,
178180 });
179181 },
180182 }
src/target.zig+47-33
......@@ -482,16 +482,6 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {
482482}
483483
484484pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
485 // This special-casing should be removed with LLVM 20.
486 switch (target.cpu.arch) {
487 .mips, .mipsel => return "o32",
488 .mips64, .mips64el => return switch (target.abi) {
489 .gnuabin32, .muslabin32 => "n32",
490 else => "n64",
491 },
492 else => {},
493 }
494
495485 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it
496486 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc
497487 // is linked as glibc only supports ELFv2 for little endian, but there's nothing we can do about
......@@ -500,33 +490,57 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
500490 // Once our self-hosted linker can handle both ABIs, this hack should go away.
501491 if (target.cpu.arch == .powerpc64) return "elfv2";
502492
503 switch (target.cpu.arch) {
504 .riscv64 => {
493 return switch (target.cpu.arch) {
494 .arm, .armeb, .thumb, .thumbeb => "aapcs",
495 // TODO: `muslsf` and `muslf32` in LLVM 20.
496 .loongarch64 => switch (target.abi) {
497 .gnusf => "lp64s",
498 .gnuf32 => "lp64f",
499 else => "lp64d",
500 },
501 .loongarch32 => switch (target.abi) {
502 .gnusf => "ilp32s",
503 .gnuf32 => "ilp32f",
504 else => "ilp32d",
505 },
506 .mips, .mipsel => "o32",
507 .mips64, .mips64el => switch (target.abi) {
508 .gnuabin32, .muslabin32 => "n32",
509 else => "n64",
510 },
511 .powerpc64 => switch (target.os.tag) {
512 .freebsd => if (target.os.version_range.semver.isAtLeast(.{ .major = 13, .minor = 0, .patch = 0 }) orelse false)
513 "elfv2"
514 else
515 "elfv1",
516 .openbsd => "elfv2",
517 else => if (target.abi.isMusl()) "elfv2" else "elfv1",
518 },
519 .powerpc64le => "elfv2",
520 .riscv64 => b: {
505521 const featureSetHas = std.Target.riscv.featureSetHas;
506 if (featureSetHas(target.cpu.features, .e)) {
507 return "lp64e";
508 } else if (featureSetHas(target.cpu.features, .d)) {
509 return "lp64d";
510 } else if (featureSetHas(target.cpu.features, .f)) {
511 return "lp64f";
512 } else {
513 return "lp64";
514 }
522 break :b if (featureSetHas(target.cpu.features, .e))
523 "lp64e"
524 else if (featureSetHas(target.cpu.features, .d))
525 "lp64d"
526 else if (featureSetHas(target.cpu.features, .f))
527 "lp64f"
528 else
529 "lp64";
515530 },
516 .riscv32 => {
531 .riscv32 => b: {
517532 const featureSetHas = std.Target.riscv.featureSetHas;
518 if (featureSetHas(target.cpu.features, .e)) {
519 return "ilp32e";
520 } else if (featureSetHas(target.cpu.features, .d)) {
521 return "ilp32d";
522 } else if (featureSetHas(target.cpu.features, .f)) {
523 return "ilp32f";
524 } else {
525 return "ilp32";
526 }
533 break :b if (featureSetHas(target.cpu.features, .e))
534 "ilp32e"
535 else if (featureSetHas(target.cpu.features, .d))
536 "ilp32d"
537 else if (featureSetHas(target.cpu.features, .f))
538 "ilp32f"
539 else
540 "ilp32";
527541 },
528 else => return null,
529 }
542 else => null,
543 };
530544}
531545
532546/// This function returns 1 if function alignment is not observable or settable. Note that this