[compiler-rt] [UBSan][Offload] Guard musttail for PowerPC in dlsym interceptor (PR #224273)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 04:41:44 PDT 2026


https://github.com/midhuncodes7 created https://github.com/llvm/llvm-project/pull/224273

`[[clang::musttail]]` in the offload `dlsym` interceptor fails to build on PowerPC — indirect/external tail calls aren't supported on PPC (Linux or AIX). Guard it behind `#if defined(__powerpc__)`, falling back to a normal call there. No behavior change on x86_64/aarch64; no existing tests cover this file.

>From 40ab68eafe048f5c6d64827e461e71dae55be261 Mon Sep 17 00:00:00 2001
From: Midhunesh <midhunesh.p at ibm.com>
Date: Thu, 17 Sep 2026 14:30:34 +0530
Subject: [PATCH] Handle musttail for powerpc

(cherry picked from commit bdccdbc458af13d498dca2590260a7d08f142bd3)
---
 .../ubsan/offload/ubsan_offload_hsa_interceptors.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/ubsan/offload/ubsan_offload_hsa_interceptors.cpp b/compiler-rt/lib/ubsan/offload/ubsan_offload_hsa_interceptors.cpp
index 5f251c2fc2a3a..b186350143d2f 100644
--- a/compiler-rt/lib/ubsan/offload/ubsan_offload_hsa_interceptors.cpp
+++ b/compiler-rt/lib/ubsan/offload/ubsan_offload_hsa_interceptors.cpp
@@ -93,6 +93,15 @@ static bool FromHsa(void *P) {
 
 static void BindRealDlsym();
 
+// Guaranteed tail calls to external/indirect functions are not supported by
+// the PowerPC backend (both AIX and Linux), so 'musttail' cannot be used
+// there. Fall back to an ordinary call on that target.
+#if defined(__powerpc__)
+#define UBSAN_DLSYM_MUSTTAIL
+#else
+#define UBSAN_DLSYM_MUSTTAIL [[clang::musttail]]
+#endif
+
 // OpenMP and sometimes HIP access HSA through 'dlsym' so we need to intercept
 // it here if we want to reliably override its definitions.
 INTERCEPTOR(void *, dlsym, void *Handle, const char *Name) {
@@ -101,7 +110,7 @@ INTERCEPTOR(void *, dlsym, void *Handle, const char *Name) {
 
   // This interceptor interferes with the order of 'RTLD_NEXT'. Force a tail
   // call to bypass this process in the stack.
-  if (Handle == RTLD_NEXT) [[clang::musttail]]
+  if (Handle == RTLD_NEXT) UBSAN_DLSYM_MUSTTAIL
     return REAL(dlsym)(Handle, Name);
 
   void *Sym = REAL(dlsym)(Handle, Name);
@@ -113,6 +122,7 @@ INTERCEPTOR(void *, dlsym, void *Handle, const char *Name) {
     return Sym;
   return Wrapper;
 }
+#undef UBSAN_DLSYM_MUSTTAIL
 
 static void BindRealDlsym() {
   if (LIKELY(REAL(dlsym)))



More information about the llvm-commits mailing list