[PECOFF] Fix duplicate /export options

If two or more /export options are given for the same symbol, we should
always print a warning message and use the first one regardless of other
parameters.
Previously there was a case that the first parameter is not used.

llvm-svn: 218342
This commit is contained in:
Rui Ueyama 2014-09-23 23:49:41 +00:00
parent dc1b248ccf
commit 7ea46bab26
3 changed files with 9 additions and 15 deletions

View File

@ -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";
}

View File

@ -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

View File

@ -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<PECOFFLinkingContext::ExportDesc> &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) {