[llvm] [X86][KCFI] Do not require linux triple for kcfi-arity (PR #148207)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 11 03:53:45 PDT 2025


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/148207

This code doesn't assume the Linux ABI, but the standard x86-64 SysV ABI, which is used (with minor variations) by all non-Windows targets.

Requiring "linux" as the OS here is problematic, because the actual OS (as opposed to users of the OS) is generally compiled against the "none" target.

>From f160218b0c8cd0040a4d40ef88b967d58b8220c1 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Fri, 11 Jul 2025 12:47:46 +0200
Subject: [PATCH] [X86][KCFI] Do not require linux triple for kcfi-arity

This code doesn't assume the Linux ABI, but the standard x86-64
SysV ABI, which is used (with minor variations) by all non-Windows
targets.

Requiring "linux" as the OS here is problematic, because the actual
OS (as opposed to users of the OS) is generally compiled against the
"none" target.
---
 llvm/lib/Target/X86/X86AsmPrinter.cpp | 4 ++--
 llvm/test/CodeGen/X86/kcfi-arity.ll   | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 50c20fcde49ce..d406277e440bb 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -192,9 +192,9 @@ void X86AsmPrinter::emitKCFITypeId(const MachineFunction &MF) {
   unsigned DestReg = X86::EAX;
 
   if (F.getParent()->getModuleFlag("kcfi-arity")) {
-    // The ArityToRegMap assumes the 64-bit Linux kernel ABI
+    // The ArityToRegMap assumes the 64-bit SysV ABI.
     [[maybe_unused]] const auto &Triple = MF.getTarget().getTargetTriple();
-    assert(Triple.isArch64Bit() && Triple.isOSLinux());
+    assert(Triple.isArch64Bit() && !Triple.isOSWindows());
 
     // Determine the function's arity (i.e., the number of arguments) at the ABI
     // level by counting the number of parameters that are passed
diff --git a/llvm/test/CodeGen/X86/kcfi-arity.ll b/llvm/test/CodeGen/X86/kcfi-arity.ll
index 009fa7d2dc0a4..5a19bcd7835ea 100644
--- a/llvm/test/CodeGen/X86/kcfi-arity.ll
+++ b/llvm/test/CodeGen/X86/kcfi-arity.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc -mtriple=x86_64-unknown-none -verify-machineinstrs < %s | FileCheck %s --check-prefix=ASM
 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs -stop-after=finalize-isel < %s | FileCheck %s --check-prefixes=MIR,ISEL
 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs -stop-after=kcfi < %s | FileCheck %s --check-prefixes=MIR,KCFI
 



More information about the llvm-commits mailing list