[lld] [LLD][COFF] Detect weak reference cycles. (PR #104463)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 09:42:58 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.
----------------
aganea wrote:
Instead of returning null then emitting "error: undefined symbol:" wouldn't it be nicer to say something like "can't resolve weak symbol because there's a cycle", and then "here's the cycle chain..." (with corresponding ref. obj files)?
https://github.com/llvm/llvm-project/pull/104463
More information about the llvm-commits
mailing list