[clang] [lld] [llvm] [LTO][LLD] Prevent invalid LTO libfunc transforms (PR #164916)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 15:59:58 PST 2025


================
@@ -279,9 +279,31 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   RegisterPassPlugins(Conf.PassPlugins, PB);
 
   std::unique_ptr<TargetLibraryInfoImpl> TLII(
-      new TargetLibraryInfoImpl(TM->getTargetTriple(), TM->Options.VecLib));
+      new TargetLibraryInfoImpl(TM->getTargetTriple()));
   if (Conf.Freestanding)
     TLII->disableAllFunctions();
+
+  TargetLibraryInfo TLI(*TLII);
+  for (unsigned I = 0, E = static_cast<unsigned>(LibFunc::NumLibFuncs); I != E;
+       ++I) {
+    LibFunc F = static_cast<LibFunc>(I);
+    StringRef Name = TLI.getName(F);
+    GlobalValue *Val = Mod.getNamedValue(Name);
+
+    // LibFuncs present in the current TU can always be referenced.
+    if (Val && !Val->isDeclaration())
+      continue;
+
+    // LibFuncs not implemented in bitcode can always be referenced.
+    if (!BitcodeLibFuncs.contains(Name))
+      continue;
+
+    // FIXME: Functions that are somewhere in a ThinLTO link (just not imported
+    // in this module) should not be disabled, as they have already been
+    // extracted.
----------------
ilovepi wrote:

maybe this is something we should think about filling in as part of the symbol resolution step? I wonder if we could make it work by just setting some bits in the symtab? 

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


More information about the llvm-commits mailing list