[clang] [compiler-rt] [llvm] [AIX] Implement the ifunc attribute. (PR #153049)

Wael Yehia via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 18 10:24:10 PDT 2025


================
@@ -3361,6 +3382,194 @@ void PPCAIXAsmPrinter::emitModuleCommandLines(Module &M) {
   OutStreamer->emitXCOFFCInfoSym(".GCC.command.line", RSOS.str());
 }
 
+static bool TOCRestoreNeeded(const GlobalIFunc &GI) {
+  auto IsLocalFunc = [&](const Value *V) {
+    if (!isa<Function>(V))
+      return false;
+    auto *F = cast<Function>(V);
+
+    // static functions are local
+    if (F->getLinkage() == GlobalValue::InternalLinkage)
+      return true;
+    // for now, declarations we treat as potentially non-local
+    if (F->isDeclarationForLinker())
+      return false;
+    // hidden visibility definitions cannot be preempted, so treat as local.
+    if (F->getVisibility() == GlobalValue::HiddenVisibility)
+      return true;
+
+    return false;
+  };
+
+  if (!IFuncLocal.empty()) {
+    ArrayRef<std::string> List = IFuncLocal;
+    // special case of -ifunc-local=1
+    if (List.size() == 1 && List[0].compare("1") == 0)
+      return false;
+    StringRef IFuncName = GI.getName();
+    if (any_of(List, [&](const std::string &Element) {
+          return Element.size() == IFuncName.size() &&
+                 Element.compare(IFuncName.data()) == 0;
+        }))
+      return false;
+  }
+
+  // if one of the return values of the resolver function is not a
+  // local function, then we have to conservatively do a TOC save/restore.
+  auto *Resolver = GI.getResolverFunction();
+  for (auto &BB : *Resolver) {
+    if (auto *Ret = dyn_cast<ReturnInst>(BB.getTerminator())) {
+      Value *RV = Ret->getReturnValue();
+      assert(RV);
+      // return &foo_p9;
+      if (auto *F = dyn_cast<Function>(RV)) {
+        if (!IsLocalFunc(F))
+          return true;
+      } else if (auto *I = dyn_cast<Instruction>(RV)) {
+        // return isP9 ? foo_p9 : foo_default;
+        if (auto *SI = dyn_cast<SelectInst>(I)) {
----------------
w2yehia wrote:

recursively look through the instructions (i.e. a phinode operand might be a selectinst)

https://github.com/llvm/llvm-project/pull/153049


More information about the llvm-commits mailing list