diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp index 6ee5b560e446..2e31acea8087 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp @@ -263,24 +263,18 @@ uint32_t PECOFFLinkingContext::getSectionAttributes(StringRef sectionName, return (flags | setMask) & ~clearMask; } -// Returns true if two export descriptors have conflicting contents, -// e.g. different export ordinals. -static bool exportConflicts(const PECOFFLinkingContext::ExportDesc &a, - const PECOFFLinkingContext::ExportDesc &b) { - return (a.ordinal > 0 && b.ordinal > 0 && a.ordinal != b.ordinal) || - a.noname != b.noname || a.isData != b.isData; +// Returns true if two export descriptors are the same. +static bool sameExportDesc(const PECOFFLinkingContext::ExportDesc &a, + const PECOFFLinkingContext::ExportDesc &b) { + return a.ordinal == b.ordinal && a.ordinal == b.ordinal && + a.noname == b.noname && a.isData == b.isData; } void PECOFFLinkingContext::addDllExport(ExportDesc &desc) { addInitialUndefinedSymbol(allocate(desc.name)); auto existing = _dllExports.insert(desc); - if (existing.second) + if (existing.second || sameExportDesc(*existing.first, desc)) return; - if (!exportConflicts(*existing.first, desc)) { - _dllExports.erase(existing.first); - _dllExports.insert(desc); - return; - } llvm::errs() << "Export symbol '" << desc.name << "' specified more than once.\n"; } diff --git a/lld/test/pecoff/export-warning.test b/lld/test/pecoff/export-warning.test index 835a0cdfe6cd..5c7647de00bd 100644 --- a/lld/test/pecoff/export-warning.test +++ b/lld/test/pecoff/export-warning.test @@ -10,7 +10,7 @@ CHECK1-NOT: Export symbol '_exportfn1' specified more than once. # RUN: /export:exportfn1 /export:exportfn1,@5 -- %t.obj 2> %t2.log # RUN: echo >> %t2.log # RUN: FileCheck -check-prefix=CHECK2 %s < %t2.log -CHECK2-NOT: Export symbol '_exportfn1' specified more than once. +CHECK2: Export symbol '_exportfn1' specified more than once. # RUN: lld -flavor link /out:%t3.dll /dll /entry:init \ # RUN: /export:exportfn1,@8 /export:exportfn1,@5 -- %t.obj 2> %t3.log diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp index 783c528e280b..7ce513cc0305 100644 --- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp +++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp @@ -188,13 +188,13 @@ TEST_F(WinLinkParserTest, ExportWithOptions) { TEST_F(WinLinkParserTest, ExportDuplicateExports) { EXPECT_TRUE( - parse("link.exe", "/export:foo,@1", "/export:foo,@2", "a.out", nullptr)); + parse("link.exe", "/export:foo", "/export:foo,@2", "a.out", nullptr)); const std::set &exports = _context.getDllExports(); EXPECT_EQ(1U, exports.size()); auto it = exports.begin(); EXPECT_EQ("_foo", it->name); - EXPECT_EQ(1, it->ordinal); + EXPECT_EQ(-1, it->ordinal); } TEST_F(WinLinkParserTest, ExportDuplicateOrdinals) {