[lld] r197998 - [PECOFF] Use the first definition of an export if specified multiple times.

Rui Ueyama ruiu at google.com
Tue Dec 24 22:46:46 PST 2013


Author: ruiu
Date: Wed Dec 25 00:46:45 2013
New Revision: 197998

URL: http://llvm.org/viewvc/llvm-project?rev=197998&view=rev
Log:
[PECOFF] Use the first definition of an export if specified multiple times.

If the same symbol is specified multiple times as arguments of /export, the
first definition should be used.

Modified:
    lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
    lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=197998&r1=197997&r2=197998&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Wed Dec 25 00:46:45 2013
@@ -217,7 +217,7 @@ public:
   void setDosStub(ArrayRef<uint8_t> data) { _dosStub = data; }
   ArrayRef<uint8_t> getDosStub() const { return _dosStub; }
 
-  void addDllExport(ExportDesc &desc) { _dllExports.push_back(desc); }
+  void addDllExport(ExportDesc &desc);
   std::vector<ExportDesc> &getDllExports() { return _dllExports; }
   const std::vector<ExportDesc> &getDllExports() const { return _dllExports; }
 
@@ -300,6 +300,7 @@ private:
 
   // DLLExport'ed symbols.
   std::vector<ExportDesc> _dllExports;
+  std::set<StringRef> _dllExportSet;
 
   // List of files that will be removed on destruction.
   std::vector<std::unique_ptr<llvm::FileRemover> > _tempFiles;

Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=197998&r1=197997&r2=197998&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Wed Dec 25 00:46:45 2013
@@ -257,6 +257,16 @@ uint32_t PECOFFLinkingContext::getSectio
   return (flags | setMask) & ~clearMask;
 }
 
+void PECOFFLinkingContext::addDllExport(ExportDesc &desc) {
+  if (_dllExportSet.count(desc.name)) {
+    llvm::errs() << "Export symbol '" << desc.name
+                 << "' specified more than once.";
+    return;
+  }
+  _dllExports.push_back(desc);
+  _dllExportSet.insert(desc.name);
+}
+
 void PECOFFLinkingContext::addPasses(PassManager &pm) {
   pm.add(std::unique_ptr<Pass>(new pecoff::SetSubsystemPass(*this)));
   pm.add(std::unique_ptr<Pass>(new pecoff::EdataPass(*this)));

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=197998&r1=197997&r2=197998&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Wed Dec 25 00:46:45 2013
@@ -183,7 +183,17 @@ TEST_F(WinLinkParserTest, ExportWithOpti
   EXPECT_TRUE(exports[1].isData);
 }
 
-TEST_F(WinLinkParserTest, ExportDuplicates) {
+TEST_F(WinLinkParserTest, ExportDuplicateExports) {
+  EXPECT_TRUE(
+      parse("link.exe", "/export:foo, at 1", "/export:foo, at 2", "a.out", nullptr));
+  const std::vector<PECOFFLinkingContext::ExportDesc> &exports =
+      _context.getDllExports();
+  EXPECT_EQ(1U, exports.size());
+  EXPECT_EQ("_foo", exports[0].name);
+  EXPECT_EQ(1, exports[0].ordinal);
+}
+
+TEST_F(WinLinkParserTest, ExportDuplicateOrdinals) {
   EXPECT_FALSE(
       parse("link.exe", "/export:foo, at 1", "/export:bar, at 1", "a.out", nullptr));
 }





More information about the llvm-commits mailing list