diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index eed0251c82e37..f38d9fab4500f 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -377,9 +377,18 @@ bool elf::computeIsPreemptible(const Symbol &sym) { void elf::reportBackrefs() { for (auto &it : backwardReferences) { const Symbol &sym = *it.first; - warn("backward reference detected: " + sym.getName() + " in " + - toString(it.second.first) + " refers to " + - toString(it.second.second)); + std::string to = toString(it.second.second); + // Some libraries have known problems and can cause noise. Filter them out + // with --warn-backrefs-exclude=. to may look like *.o or *.a(*.o). + bool exclude = false; + for (const llvm::GlobPattern &pat : config->warnBackrefsExclude) + if (pat.match(to)) { + exclude = true; + break; + } + if (!exclude) + warn("backward reference detected: " + sym.getName() + " in " + + toString(it.second.first) + " refers to " + to); } } @@ -515,17 +524,6 @@ void Symbol::resolveUndefined(const Undefined &other) { // group assignment rule simulates the traditional linker's semantics. bool backref = config->warnBackrefs && other.file && file->groupId < other.file->groupId; - if (backref) { - // Some libraries have known problems and can cause noise. Filter them out - // with --warn-backrefs-exclude=. - StringRef name = - !file->archiveName.empty() ? file->archiveName : file->getName(); - for (const llvm::GlobPattern &pat : config->warnBackrefsExclude) - if (pat.match(name)) { - backref = false; - break; - } - } fetch(); // We don't report backward references to weak symbols as they can be diff --git a/lld/test/ELF/warn-backrefs.s b/lld/test/ELF/warn-backrefs.s index a1b186fc98b1c..6912955700f93 100644 --- a/lld/test/ELF/warn-backrefs.s +++ b/lld/test/ELF/warn-backrefs.s @@ -20,8 +20,8 @@ # RUN: ld.lld --warn-backrefs %t2.a %t1.o -o /dev/null 2>&1 | FileCheck %s # RUN: ld.lld --warn-backrefs %t2.a '-(' %t1.o '-)' -o /dev/null 2>&1 | FileCheck %s # RUN: ld.lld --warn-backrefs --warn-backrefs-exclude='*3.a' %t2.a %t1.o -o /dev/null 2>&1 | FileCheck %s -# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude='*2.a' %t2.a %t1.o -o /dev/null -# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude '*2.a' \ +# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude='*2.a(*2.o)' %t2.a %t1.o -o /dev/null +# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude '*2.a(*2.o)' \ # RUN: --warn-backrefs-exclude not_exist %t2.a %t1.o -o /dev/null ## Without --warn-backrefs, --warn-backrefs-exclude is ignored. # RUN: ld.lld --fatal-warnings --warn-backrefs-exclude=not_exist %t2.a %t1.o -o /dev/null @@ -35,7 +35,7 @@ # RUN: echo 'GROUP("%t2.a")' > %t3.lds # RUN: ld.lld --warn-backrefs %t3.lds %t1.o -o /dev/null 2>&1 | FileCheck %s # RUN: ld.lld --fatal-warnings --warn-backrefs '-(' %t3.lds %t1.o '-)' -o /dev/null -# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude='*2.a' -o /dev/null %t3.lds %t1.o +# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude='*2.a(*2.o)' -o /dev/null %t3.lds %t1.o ## If a lazy definition appears after the backward reference, don't warn. # RUN: ld.lld --fatal-warnings --warn-backrefs %t3.lds %t1.o %t3.lds -o /dev/null