[lld] r218342 - [PECOFF] Fix duplicate /export options
Rui Ueyama
ruiu at google.com
Tue Sep 23 16:49:41 PDT 2014
Author: ruiu
Date: Tue Sep 23 18:49:41 2014
New Revision: 218342
URL: http://llvm.org/viewvc/llvm-project?rev=218342&view=rev
Log:
[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.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
lld/trunk/test/pecoff/export-warning.test
lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=218342&r1=218341&r2=218342&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Tue Sep 23 18:49:41 2014
@@ -263,24 +263,18 @@ uint32_t PECOFFLinkingContext::getSectio
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";
}
Modified: lld/trunk/test/pecoff/export-warning.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/export-warning.test?rev=218342&r1=218341&r2=218342&view=diff
==============================================================================
--- lld/trunk/test/pecoff/export-warning.test (original)
+++ lld/trunk/test/pecoff/export-warning.test Tue Sep 23 18:49:41 2014
@@ -10,7 +10,7 @@ CHECK1-NOT: Export symbol '_exportfn1' s
# RUN: /export:exportfn1 /export:exportfn1, at 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, at 8 /export:exportfn1, at 5 -- %t.obj 2> %t3.log
Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=218342&r1=218341&r2=218342&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Tue Sep 23 18:49:41 2014
@@ -188,13 +188,13 @@ TEST_F(WinLinkParserTest, ExportWithOpti
TEST_F(WinLinkParserTest, ExportDuplicateExports) {
EXPECT_TRUE(
- parse("link.exe", "/export:foo, at 1", "/export:foo, at 2", "a.out", nullptr));
+ parse("link.exe", "/export:foo", "/export:foo, at 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) {
More information about the llvm-commits
mailing list