From afe2fed34dd960afb44f88cfe6ce088e1817cb5b Mon Sep 17 00:00:00 2001 From: Alex Rønne Petersen Date: Mon, 16 Dec 2024 06:07:02 +0100 Subject: 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). --- src/link/Elf.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/link/Elf.zig') diff --git a/src/link/Elf.zig b/src/link/Elf.zig index ea2fa56a5d..edd45f65ee 100644 --- 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 => {}, -- cgit v1.2.3