[lld] [LLD][COFF] Detect weak reference cycles. (PR #104463)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 04:18:39 PDT 2024


================
@@ -126,9 +127,14 @@ DefinedImportThunk::DefinedImportThunk(COFFLinkerContext &ctx, StringRef name,
 
 Defined *Undefined::getWeakAlias() {
   // A weak alias may be a weak alias to another symbol, so check recursively.
-  for (Symbol *a = weakAlias; a; a = cast<Undefined>(a)->weakAlias)
+  SmallSet<Symbol *, 4> weakChain;
+  for (Symbol *a = weakAlias; a; a = cast<Undefined>(a)->weakAlias) {
+    if (weakChain.contains(a))
+      break; // We have a cycle.
     if (auto *d = dyn_cast<Defined>(a))
       return d;
+    weakChain.insert(a);
----------------
cjacek wrote:

Good point, I changed that in the new version (used `try_emplace` after changing set type to `DenseMap`).

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


More information about the llvm-commits mailing list