zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit afe2fed34dd960afb44f88cfe6ce088e1817cb5b (tree)
parent cd8c92fc40993d307e891be27bfd86574c2ce85d
Author: Alex Rønne Petersen <alex@alexrp.com>
Date:   Mon, 16 Dec 2024 06:07:02 +0100

link: Set machine and float ABI when invoking ld.lld and lld-link.

If this isn't done, LTO can completely miscompile the input bitcode modules for
certain targets where we need to explicitly set these ABIs (because LLVM's
defaults are bad).

Diffstat:
Msrc/link/Coff.zig | 7+++++++
Msrc/link/Elf.zig | 12++++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/link/Coff.zig b/src/link/Coff.zig @@ -1876,6 +1876,13 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: if (comp.version) |version| { try argv.append(try allocPrint(arena, "-VERSION:{}.{}", .{ version.major, version.minor })); } + + if (target_util.llvmMachineAbi(target)) |mabi| { + try argv.append(try allocPrint(arena, "-MLLVM:-target-abi={s}", .{mabi})); + } + + try argv.append(try allocPrint(arena, "-MLLVM:-float-abi={s}", .{if (target.abi.floatAbi() == .hard) "hard" else "soft"})); + if (comp.config.lto != .none) { switch (optimize_mode) { .Debug => {}, diff --git a/src/link/Elf.zig b/src/link/Elf.zig @@ -1700,6 +1700,18 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s try argv.append(try std.fmt.allocPrint(arena, "--sysroot={s}", .{sysroot})); } + if (target_util.llvmMachineAbi(target)) |mabi| { + try argv.appendSlice(&.{ + "-mllvm", + try std.fmt.allocPrint(arena, "-target-abi={s}", .{mabi}), + }); + } + + try argv.appendSlice(&.{ + "-mllvm", + try std.fmt.allocPrint(arena, "-float-abi={s}", .{if (target.abi.floatAbi() == .hard) "hard" else "soft"}), + }); + if (comp.config.lto != .none) { switch (comp.root_mod.optimize_mode) { .Debug => {},