From 0235e7610c6cfdf698cded967a88bfe5963f09fb Mon Sep 17 00:00:00 2001 From: Pavel Durov Date: Wed, 17 Dec 2025 18:11:10 +0000 Subject: [PATCH] Address taken functions as opt. When a function's address is taken, it is now marked as yk_outline to prevent tracing calls from being added, ensuring function pointer identity is maintained. --- llvm/lib/Transforms/Yk/ModuleClone.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Yk/ModuleClone.cpp b/llvm/lib/Transforms/Yk/ModuleClone.cpp index 3d2ee08d886f5..5ad9de668a06b 100644 --- a/llvm/lib/Transforms/Yk/ModuleClone.cpp +++ b/llvm/lib/Transforms/Yk/ModuleClone.cpp @@ -13,7 +13,8 @@ // // Sometimes we are unable to clone a function. For example when a function has // its address taken. Cloning such a function would break "function pointer -// identity", which the program may be relying on. +// identity", which the program may be relying on. In this case, we mark the +// original function as yk_outline to prevent tracing calls from being added. //===----------------------------------------------------------------------===// #include "llvm/Transforms/Yk/ModuleClone.h" @@ -28,6 +29,7 @@ #include "llvm/IR/Verifier.h" #include "llvm/Linker/Linker.h" #include "llvm/Pass.h" +#include "llvm/Support/Debug.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Yk/ControlPoint.h" #include "llvm/YkIR/YkIRWriter.h" @@ -56,11 +58,7 @@ bool ModuleClonePass::shouldClone(Function &F) { if (F.isDeclaration()) { return false; } - // If the address of a function is taken, then cloning it would break - // function pointer identity, which the program may rely on. - if (F.hasAddressTaken()) { - return false; - } + // Note: address-taken functions are handled separately in cloneFunctionsInModule. // For now we don't clone functions that contain a call to the control // point. if (containsControlPoint(F)) { @@ -85,6 +83,18 @@ ModuleClonePass::cloneFunctionsInModule(Module &M) { for (Function *F : Funcs) { auto OrigName = F->getName().str(); + // If the address of a function is taken, then cloning it would break + // function pointer identity, which the program may rely on. We mark the + // original as yk_outline to prevent tracing calls from being added. + if (F->hasAddressTaken()) { + // Debug print + // errs() << "yk-module-clone: address-taken function: " << F->getName() << "\n"; + F->addFnAttr(YK_OUTLINE_FNATTR); + F->setMetadata(YK_SWT_OPT_MD, OptMD); + CloneMap[F] = nullptr; + continue; + } + // Maybe clone the function. Function *ClonedOptFunc = nullptr; if (shouldClone(*F)) {