diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 444ed5e69d36..2c7b59f32cf3 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -619,20 +619,18 @@ void Symbol::resolve(Ctx &ctx, const LazySymbol &other) { return; } - // For common objects, we want to look for global or weak definitions that - // should be extracted as the canonical definition instead. - if (LLVM_UNLIKELY(isCommon()) && ctx.arg.fortranCommon && - other.file->shouldExtractForCommon(getName())) { - ctx.backwardReferences.erase(this); - other.overwrite(*this); - other.extract(ctx); - return; - } - - if (!isUndefined()) { - // See the comment in resolveUndefined(). - if (isDefined()) + if (LLVM_UNLIKELY(!isUndefined())) { + // See the comment in resolve(Ctx &, const Undefined &). + if (isDefined()) { ctx.backwardReferences.erase(this); + } else if (isCommon() && ctx.arg.fortranCommon && + other.file->shouldExtractForCommon(getName())) { + // For common objects, we want to look for global or weak definitions that + // should be extracted as the canonical definition instead. + ctx.backwardReferences.erase(this); + other.overwrite(*this); + other.extract(ctx); + } return; }