diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp index ee9460f488cb..2be1fe6bdc4c 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp @@ -266,16 +266,12 @@ void PECOFFLinkingContext::addDllExport(ExportDesc &desc) { // Scan the vector to look for existing entry. It's not very fast, // but because the number of exported symbol is usually not that // much, it should be okay. - ExportDesc *existing = nullptr; for (ExportDesc &e : _dllExports) { - if (e.name == desc.name) { - existing = &e; - break; - } - } - if (existing && !sameExportDesc(*existing, desc)) { - llvm::errs() << "Export symbol '" << desc.name - << "' specified more than once.\n"; + if (e.name != desc.name) + continue; + if (!sameExportDesc(e, desc)) + llvm::errs() << "Export symbol '" << desc.name + << "' specified more than once.\n"; return; } _dllExports.push_back(desc); diff --git a/lld/test/pecoff/export.test b/lld/test/pecoff/export.test index bfedb56334de..ef2a1d197242 100644 --- a/lld/test/pecoff/export.test +++ b/lld/test/pecoff/export.test @@ -59,3 +59,13 @@ CHECK6: Export Table: CHECK6: DLL name: export.test.tmp6.dll CHECK6: Ordinal RVA Name CHECK6-NEXT: 1 0x2010 exportfn8 + +# RUN: lld -flavor link /out:%t6.dll /dll /entry:init \ +# RUN: /export:exportfn8 /export:exportfn8 -- %t.obj +# RUN: llvm-objdump -p %t6.dll | FileCheck -check-prefix=DUP %s + +DUP: Export Table: +DUP: DLL name: export.test.tmp6.dll +DUP: Ordinal RVA Name +DUP: 1 0x2010 exportfn8 +DUP-NOT: 1 0x2010 exportfn8