[llvm] [ThinLTO] Don't convert functions to declarations if `force-import-all` is enabled (PR #134541)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 8 10:26:31 PDT 2025


================
@@ -1701,13 +1701,16 @@ void llvm::thinLTOFinalizeInModule(Module &TheModule,
     if (NewLinkage == GV.getLinkage())
       return;
 
+    bool ForceImportFunction = isa<Function>(GV) && ForceImportAll;
+
     // Check for a non-prevailing def that has interposable linkage
     // (e.g. non-odr weak or linkonce). In that case we can't simply
     // convert to available_externally, since it would lose the
     // interposable property and possibly get inlined. Simply drop
     // the definition in that case.
     if (GlobalValue::isAvailableExternallyLinkage(NewLinkage) &&
-        GlobalValue::isInterposableLinkage(GV.getLinkage())) {
+        GlobalValue::isInterposableLinkage(GV.getLinkage()) &&
+        !ForceImportFunction) {
----------------
shiltian wrote:

> All `cl::opt` in the passes are all considered not officially supported user facing options. You need change that to an updated the actual `lto::Config` to has an option for that to be an official function.

Sure, this will be done in a separate PR.

> The comment explains that for an `interposable linkage`, it is invalid to be inlined according to language ref. It is not about if object linking is allowed or not. You might use a wrong linkage type here? Maybe something `linkonce_odr` is better if inlining should be allowed (of course I don't know your use case)

The global is set to `available_externally` if it is not prevailing nor an alias in `thinLTOResolvePrevailingGUID`. This might need to be updated to consider the force-import-all case.

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


More information about the llvm-commits mailing list