[llvm] [AArch64] Make IFUNC opt-in rather than opt-out. (PR #171648)

Harald van Dijk via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 10 20:05:43 PST 2025


https://github.com/hvdijk updated https://github.com/llvm/llvm-project/pull/171648

>From 94587933cba1b5bc246283d374ae4bb41185ad28 Mon Sep 17 00:00:00 2001
From: Harald van Dijk <hdijk at accesssoftek.com>
Date: Thu, 11 Dec 2025 04:04:30 +0000
Subject: [PATCH] [AArch64] Make IFUNC opt-in rather than opt-out.

IFUNCs require loader support, so for arbitrary environments, the safe
assumption is to assume that they are not supported.

In particular, aarch64-linux-pauthtest may be used with musl, and was
wrongly detected as supporting IFUNCs.
---
 llvm/include/llvm/TargetParser/Triple.h       |  2 +-
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 28 ++++---------------
 llvm/test/CodeGen/AArch64/ptrauth-reloc.ll    | 16 +++++------
 3 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 9480e7b36dc2c..b9fbe2b02e22c 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -769,7 +769,7 @@ class Triple {
   bool isOSGlibc() const {
     return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD ||
             getOS() == Triple::Hurd) &&
-           !isAndroid() && !isMusl();
+           !isAndroid() && !isMusl() && getEnvironment() != Triple::PAuthTest;
   }
 
   /// Tests whether the OS is AIX.
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 87256352faccd..114bece6bddc2 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -2419,30 +2419,14 @@ void AArch64AsmPrinter::emitAddress(MCRegister Reg, const MCExpr *Expr,
   }
 }
 
-static bool targetSupportsPAuthRelocation(const Triple &TT,
-                                          const MCExpr *Target,
-                                          const MCExpr *DSExpr) {
-  // No released version of glibc supports PAuth relocations.
-  if (TT.isOSGlibc() || TT.isMusl())
-    return false;
-
-  // We emit PAuth constants as IRELATIVE relocations in cases where the
-  // constant cannot be represented as a PAuth relocation:
-  // 1) There is a deactivation symbol.
-  // 2) The signed value is not a symbol.
-  return !DSExpr && !isa<MCConstantExpr>(Target);
-}
-
 static bool targetSupportsIRelativeRelocation(const Triple &TT) {
   // IFUNCs are ELF-only.
   if (!TT.isOSBinFormatELF())
     return false;
 
-  // musl doesn't support IFUNCs.
-  if (TT.isMusl())
-    return false;
-
-  return true;
+  // IFUNCs are supported on glibc, bionic, and some but not all of the BSDs.
+  return TT.isOSGlibc() || TT.isAndroid() || TT.isOSFreeBSD() ||
+         TT.isOSDragonFly() || TT.isOSNetBSD();
 }
 
 // Emit an ifunc resolver that returns a signed pointer to the specified target,
@@ -2501,10 +2485,8 @@ const MCExpr *AArch64AsmPrinter::emitPAuthRelocationAsIRelative(
     bool HasAddressDiversity, bool IsDSOLocal, const MCExpr *DSExpr) {
   const Triple &TT = TM.getTargetTriple();
 
-  // We only emit an IRELATIVE relocation if the target supports IRELATIVE and
-  // does not support the kind of PAuth relocation that we are trying to emit.
-  if (targetSupportsPAuthRelocation(TT, Target, DSExpr) ||
-      !targetSupportsIRelativeRelocation(TT))
+  // We only emit an IRELATIVE relocation if the target supports that.
+  if (!targetSupportsIRelativeRelocation(TT))
     return nullptr;
 
   // For now, only the DA key is supported.
diff --git a/llvm/test/CodeGen/AArch64/ptrauth-reloc.ll b/llvm/test/CodeGen/AArch64/ptrauth-reloc.ll
index f2d080644e93e..b546fe4ed8279 100644
--- a/llvm/test/CodeGen/AArch64/ptrauth-reloc.ll
+++ b/llvm/test/CodeGen/AArch64/ptrauth-reloc.ll
@@ -4,13 +4,13 @@
 
 ; RUN: llc < ok.ll -mtriple arm64e-apple-darwin \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-MACHO
-; RUN: llc < ok.ll -mtriple aarch64-elf -mattr=+pauth \
+; RUN: llc < ok.ll -mtriple aarch64-android -mattr=+pauth \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ELF
 
 ; RUN: llc < ok.ll -mtriple arm64e-apple-darwin \
 ; RUN:   -global-isel -verify-machineinstrs -global-isel-abort=1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-MACHO
-; RUN: llc < ok.ll -mtriple aarch64-elf -mattr=+pauth \
+; RUN: llc < ok.ll -mtriple aarch64-android -mattr=+pauth \
 ; RUN:   -global-isel -verify-machineinstrs -global-isel-abort=1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ELF
 
@@ -141,13 +141,13 @@
 
 ; RUN: not llc < err-key.ll -mtriple arm64e-apple-darwin 2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-KEY
-; RUN: not llc < err-key.ll -mtriple aarch64-elf -mattr=+pauth 2>&1 \
+; RUN: not llc < err-key.ll -mtriple aarch64-android -mattr=+pauth 2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-KEY
 
 ; RUN: not llc < err-key.ll -mtriple arm64e-apple-darwin \
 ; RUN:   -global-isel -verify-machineinstrs -global-isel-abort=1  2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-KEY
-; RUN: not llc < err-key.ll -mtriple aarch64-elf -mattr=+pauth \
+; RUN: not llc < err-key.ll -mtriple aarch64-android -mattr=+pauth \
 ; RUN:   -global-isel -verify-machineinstrs -global-isel-abort=1 2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-KEY
 
@@ -161,13 +161,13 @@
 
 ; RUN: not llc < err-disc.ll -mtriple arm64e-apple-darwin 2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-DISC
-; RUN: not llc < err-disc.ll -mtriple aarch64-elf -mattr=+pauth 2>&1 \
+; RUN: not llc < err-disc.ll -mtriple aarch64-android -mattr=+pauth 2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-DISC
 
 ; RUN: not llc < err-disc.ll -mtriple arm64e-apple-darwin \
 ; RUN:   -global-isel -verify-machineinstrs -global-isel-abort=1  2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-DISC
-; RUN: not llc < err-disc.ll -mtriple aarch64-elf -mattr=+pauth \
+; RUN: not llc < err-disc.ll -mtriple aarch64-android -mattr=+pauth \
 ; RUN:   -global-isel -verify-machineinstrs -global-isel-abort=1 2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-DISC
 
@@ -178,9 +178,9 @@
 
 ;--- err-disc-elf.ll
 
-; RUN: not llc < err-disc-elf.ll -mtriple aarch64-elf -mattr=+pauth 2>&1 \
+; RUN: not llc < err-disc-elf.ll -mtriple aarch64-android -mattr=+pauth 2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-DISC-ELF
-; RUN: not llc < err-disc-elf.ll -mtriple aarch64-elf -mattr=+pauth \
+; RUN: not llc < err-disc-elf.ll -mtriple aarch64-android -mattr=+pauth \
 ; RUN:   -global-isel -verify-machineinstrs -global-isel-abort=1 2>&1 \
 ; RUN:   | FileCheck %s --check-prefix=CHECK-ERR-DISC-ELF
 



More information about the llvm-commits mailing list