[llvm] [ThinLTO] Do not duplicate import a function that is actually defined in the current module (PR #110064)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 18:16:18 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lto

Author: William Junda Huang (huangjd)

<details>
<summary>Changes</summary>

Doing so could cause a bug where the linker tries to remap a function "reimported" from the current module when materializing it, causing a lookup assert in the type mappings.

---
Full diff: https://github.com/llvm/llvm-project/pull/110064.diff


1 Files Affected:

- (modified) llvm/lib/Linker/IRMover.cpp (+5-1) 


``````````diff
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 3a6c2678cd157f..5bd05d86a949c3 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -595,11 +595,15 @@ Value *IRLinker::materialize(Value *V, bool ForIndirectSymbol) {
   if (!SGV)
     return nullptr;
 
+  // If SGV is from dest, it is already materialized when dest was loaded.
+  if (SGV->getParent() == &DstM)
+    return nullptr;
+
   // When linking a global from other modules than source & dest, skip
   // materializing it because it would be mapped later when its containing
   // module is linked. Linking it now would potentially pull in many types that
   // may not be mapped properly.
-  if (SGV->getParent() != &DstM && SGV->getParent() != SrcM.get())
+  if (SGV->getParent() != SrcM.get())
     return nullptr;
 
   Expected<Constant *> NewProto = linkGlobalValueProto(SGV, ForIndirectSymbol);

``````````

</details>


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


More information about the llvm-commits mailing list