Skip to content

Conversation

@mysterymath
Copy link
Contributor

A crummy draft patch to demonstrate how LTO can be altered to treat builtin libfuncs with more respect after LTO symbol resolution

@github-actions
Copy link

github-actions bot commented Oct 24, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions h,cpp -- lld/ELF/Driver.cpp lld/ELF/LTO.cpp lld/ELF/LTO.h llvm/include/llvm/LTO/LTO.h llvm/include/llvm/LTO/LTOBackend.h llvm/lib/LTO/LTO.cpp llvm/lib/LTO/LTOBackend.cpp llvm/lib/LTO/LTOCodeGenerator.cpp llvm/lib/Object/IRSymtab.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index d0a447df6..f128193f9 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -402,7 +402,8 @@ public:
   LLVM_ABI Error add(std::unique_ptr<InputFile> Obj,
                      ArrayRef<SymbolResolution> Res);
 
-  LLVM_ABI void setBitcodeLibFuncs(const SmallVector<const char *> &BitcodeLibFuncs);
+  LLVM_ABI void
+  setBitcodeLibFuncs(const SmallVector<const char *> &BitcodeLibFuncs);
 
   /// Returns an upper bound on the number of tasks that the client may expect.
   /// This may only be called after all IR object files have been added. For a
diff --git a/llvm/include/llvm/LTO/LTOBackend.h b/llvm/include/llvm/LTO/LTOBackend.h
index 26bff2281..2e5334740 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ b/llvm/include/llvm/LTO/LTOBackend.h
@@ -40,7 +40,7 @@ LLVM_ABI bool opt(const Config &Conf, TargetMachine *TM, unsigned Task,
                   ModuleSummaryIndex *ExportSummary,
                   const ModuleSummaryIndex *ImportSummary,
                   const std::vector<uint8_t> &CmdArgs,
-                  const SmallVector<const char*>& BitcodeLibFuncs);
+                  const SmallVector<const char *> &BitcodeLibFuncs);
 
 /// Runs a regular LTO backend. The regular LTO backend can also act as the
 /// regular LTO phase of ThinLTO, which may need to access the combined index.
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 95f061036..fe1550324 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1503,7 +1503,7 @@ public:
 class InProcessThinBackend : public CGThinBackend {
 protected:
   FileCache Cache;
-  const SmallVector<const char*> &BitcodeLibFuncs;
+  const SmallVector<const char *> &BitcodeLibFuncs;
 
 public:
   InProcessThinBackend(

mysterymath and others added 6 commits November 13, 2025 14:52
- Preserve all libc symbols in LTO
- Disable libfuncs that aren't present in the module

This is overly-disably:
- Libfuncs not in bitcode are disabled too 
- Libfuncs defined in other ThinLTO modules are disabled unless they are
  imported into the module. Not sure when importing happens; maybe that
  means this disables all libfuncs for ThinLTO entirely?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant