[lld] [LLD][COFF] Detect weak reference cycles. (PR #104463)
Noel Grandin via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 13:16:51 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);
----------------
grandinj wrote:
driveby comment: Normally it is faster to do something like
if (!weakChain.insert(a).second)
break; // we have a cycle
i.e. do the lookup&insert in one operation
https://github.com/llvm/llvm-project/pull/104463
More information about the llvm-commits
mailing list