<div dir="ltr">Ooh, yes. I'll revert it now. I thought I was working in a different branch.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 9, 2014 at 9:46 AM, Joey Gouly <span dir="ltr"><<a href="mailto:joey.gouly@gmail.com" target="_blank">joey.gouly@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Was this accidental?</p><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On 9 May 2014 17:43, "Rui Ueyama" <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Author: ruiu<br>
Date: Fri May  9 11:35:23 2014<br>
New Revision: 208427<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=208427&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=208427&view=rev</a><br>
Log:<br>
temporary commit.<br>
<br>
Modified:<br>
    lld/trunk/include/lld/Core/ArchiveLibraryFile.h<br>
    lld/trunk/include/lld/Core/InputGraph.h<br>
    lld/trunk/lib/Core/InputGraph.cpp<br>
    lld/trunk/lib/Driver/WinLinkDriver.cpp<br>
    lld/trunk/lib/ReaderWriter/FileArchive.cpp<br>
    lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h<br>
<br>
Modified: lld/trunk/include/lld/Core/ArchiveLibraryFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/ArchiveLibraryFile.h?rev=208427&r1=208426&r2=208427&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/ArchiveLibraryFile.h?rev=208427&r1=208426&r2=208427&view=diff</a><br>



==============================================================================<br>
--- lld/trunk/include/lld/Core/ArchiveLibraryFile.h (original)<br>
+++ lld/trunk/include/lld/Core/ArchiveLibraryFile.h Fri May  9 11:35:23 2014<br>
@@ -12,6 +12,8 @@<br>
<br>
 #include "lld/Core/File.h"<br>
<br>
+#include <set><br>
+<br>
 namespace lld {<br>
<br>
 ///<br>
@@ -36,6 +38,10 @@ public:<br>
   virtual error_code<br>
   parseAllMembers(std::vector<std::unique_ptr<File>> &result) const = 0;<br>
<br>
+  virtual std::set<StringRef> getDefinedSymbols() const {<br>
+    return std::set<StringRef>();<br>
+  }<br>
+<br>
 protected:<br>
   /// only subclasses of ArchiveLibraryFile can be instantiated<br>
   ArchiveLibraryFile(StringRef path) : File(path, kindArchiveLibrary) {}<br>
<br>
Modified: lld/trunk/include/lld/Core/InputGraph.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=208427&r1=208426&r2=208427&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=208427&r1=208426&r2=208427&view=diff</a><br>



==============================================================================<br>
--- lld/trunk/include/lld/Core/InputGraph.h (original)<br>
+++ lld/trunk/include/lld/Core/InputGraph.h Fri May  9 11:35:23 2014<br>
@@ -23,6 +23,7 @@<br>
 #include "llvm/Support/MemoryBuffer.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
<br>
+#include <functional><br>
 #include <memory><br>
 #include <stack><br>
 #include <vector><br>
@@ -67,6 +68,11 @@ public:<br>
   /// whether it should iterate over again or terminate or not.<br>
   void notifyProgress();<br>
<br>
+  /// Adds an observer of getNextFile(). Each time a new file is about to be<br>
+  /// returned from getNextFile(), registered observers are called with the file<br>
+  /// being returned.<br>
+  void registerObserver(std::function<void(File*)> &fn);<br>
+<br>
   /// \brief Adds a node into the InputGraph<br>
   void addInputElement(std::unique_ptr<InputElement>);<br>
<br>
@@ -93,6 +99,7 @@ protected:<br>
   // Index of the next element to be processed<br>
   uint32_t _nextElementIndex;<br>
   InputElement *_currentInputElement;<br>
+  std::vector<std::function<void(File *)>> _observers;<br>
<br>
 private:<br>
   ErrorOr<InputElement *> getNextInputElement();<br>
<br>
Modified: lld/trunk/lib/Core/InputGraph.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=208427&r1=208426&r2=208427&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=208427&r1=208426&r2=208427&view=diff</a><br>



==============================================================================<br>
--- lld/trunk/lib/Core/InputGraph.cpp (original)<br>
+++ lld/trunk/lib/Core/InputGraph.cpp Fri May  9 11:35:23 2014<br>
@@ -21,9 +21,12 @@ ErrorOr<File &> InputGraph::getNextFile(<br>
   // it will succeed. If not, try to get the next file in the input graph.<br>
   for (;;) {<br>
     if (_currentInputElement) {<br>
-      ErrorOr<File &> nextFile = _currentInputElement->getNextFile();<br>
-      if (nextFile.getError() != InputGraphError::no_more_files)<br>
-        return std::move(nextFile);<br>
+      ErrorOr<File &> next = _currentInputElement->getNextFile();<br>
+      if (next.getError() != InputGraphError::no_more_files) {<br>
+        for (std::function<void(File*)> &observer : _observers)<br>
+          observer(&next.get());<br>
+        return std::move(next);<br>
+      }<br>
     }<br>
<br>
     ErrorOr<InputElement *> elt = getNextInputElement();<br>
@@ -35,6 +38,10 @@ ErrorOr<File &> InputGraph::getNextFile(<br>
<br>
 void InputGraph::notifyProgress() { _currentInputElement->notifyProgress(); }<br>
<br>
+void InputGraph::registerObserver(std::function<void(File*)> &fn) {<br>
+  _observers.push_back(fn);<br>
+}<br>
+<br>
 void InputGraph::addInputElement(std::unique_ptr<InputElement> ie) {<br>
   _inputArgs.push_back(std::move(ie));<br>
 }<br>
<br>
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=208427&r1=208426&r2=208427&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=208427&r1=208426&r2=208427&view=diff</a><br>



==============================================================================<br>
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)<br>
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Fri May  9 11:35:23 2014<br>
@@ -13,10 +13,12 @@<br>
 ///<br>
 //===----------------------------------------------------------------------===//<br>
<br>
+#include "lld/Core/ArchiveLibraryFile.h"<br>
 #include "lld/Driver/Driver.h"<br>
 #include "lld/Driver/WinLinkInputGraph.h"<br>
 #include "lld/Driver/WinLinkModuleDef.h"<br>
 #include "lld/ReaderWriter/PECOFFLinkingContext.h"<br>
+#include "../ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h"<br>
<br>
 #include "llvm/ADT/ArrayRef.h"<br>
 #include "llvm/ADT/Optional.h"<br>
@@ -34,6 +36,7 @@<br>
<br>
 #include <algorithm><br>
 #include <cctype><br>
+#include <functional><br>
 #include <map><br>
 #include <memory><br>
 #include <sstream><br>
@@ -1293,6 +1296,19 @@ bool WinLinkDriver::parse(int argc, cons<br>
     }<br>
   }<br>
<br>
+  if (!isReadingDirectiveSection) {<br>
+    std::unique_ptr<SimpleFileNode> node(new SimpleFileNode("<export>"));<br>
+    pecoff::ExportedSymbolRenameFile *renameFile =<br>
+        new pecoff::ExportedSymbolRenameFile(ctx);<br>
+    node->appendInputFile(std::unique_ptr<File>(renameFile));<br>
+    ctx.getLibraryGroup()->addFile(std::move(node));<br>
+    std::function<void(File *)> observer = [=](File *file) {<br>
+      if (auto *archive = dyn_cast<ArchiveLibraryFile>(file))<br>
+        renameFile->addResolvableSymbols(archive);<br>
+    };<br>
+    ctx.getInputGraph().registerObserver(observer);<br>
+  }<br>
+<br>
   // Validate the combination of options used.<br>
   return ctx.validate(diag);<br>
 }<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/FileArchive.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/FileArchive.cpp?rev=208427&r1=208426&r2=208427&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/FileArchive.cpp?rev=208427&r1=208426&r2=208427&view=diff</a><br>



==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/FileArchive.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/FileArchive.cpp Fri May  9 11:35:23 2014<br>
@@ -97,6 +97,16 @@ public:<br>
     return _absoluteAtoms;<br>
   }<br>
<br>
+  /// Returns a set of all defined symbols in the archive.<br>
+  std::set<StringRef> getDefinedSymbols() const override {<br>
+    std::set<StringRef> ret;<br>
+    for (const auto &e : _symbolMemberMap) {<br>
+      StringRef sym = e.first;<br>
+      ret.insert(sym);<br>
+    }<br>
+    return ret;<br>
+  }<br>
+<br>
 protected:<br>
   error_code<br>
   instantiateMember(Archive::child_iterator member,<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=208427&r1=208426&r2=208427&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=208427&r1=208426&r2=208427&view=diff</a><br>



==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h (original)<br>
+++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h Fri May  9 11:35:23 2014<br>
@@ -13,6 +13,9 @@<br>
 #include "lld/ReaderWriter/PECOFFLinkingContext.h"<br>
 #include "lld/ReaderWriter/Simple.h"<br>
 #include "llvm/Support/Allocator.h"<br>
+#include "llvm/Support/Debug.h"<br>
+<br>
+#include <mutex><br>
<br>
 namespace lld {<br>
 namespace pecoff {<br>
@@ -86,6 +89,18 @@ private:<br>
   atom_collection_vector<AbsoluteAtom> _absoluteAtoms;<br>
 };<br>
<br>
+class SymbolRenameFile : public SimpleFile {<br>
+public:<br>
+  SymbolRenameFile(StringRef from, StringRef to)<br>
+      : SimpleFile("<symbol-rename>"), _to(*this, to), _from(*this, from, &_to) {<br>
+    addAtom(_from);<br>
+  };<br>
+<br>
+private:<br>
+  COFFUndefinedAtom _to;<br>
+  COFFUndefinedAtom _from;<br>
+};<br>
+<br>
 } // anonymous namespace<br>
<br>
 // A virtual file containing absolute symbol __ImageBase. __ImageBase (or<br>
@@ -141,5 +156,51 @@ private:<br>
   mutable llvm::BumpPtrAllocator _alloc;<br>
 };<br>
<br>
+class ExportedSymbolRenameFile : public VirtualArchiveLibraryFile {<br>
+public:<br>
+  ExportedSymbolRenameFile(const PECOFFLinkingContext &ctx)<br>
+      : VirtualArchiveLibraryFile("<export>") {<br>
+    for (const PECOFFLinkingContext::ExportDesc &desc : ctx.getDllExports())<br>
+      _exportedSyms.insert(<a href="http://desc.name" target="_blank">desc.name</a>);<br>
+  }<br>
+<br>
+  void addResolvableSymbols(ArchiveLibraryFile *archive) {<br>
+    std::lock_guard<std::mutex> lock(_mutex);<br>
+    if (_seen.count(archive) > 0)<br>
+      return;<br>
+    _seen.insert(archive);<br>
+    for (const std::string &sym : archive->getDefinedSymbols())<br>
+      _resolvableSyms.insert(sym);<br>
+  }<br>
+<br>
+  const File *find(StringRef sym, bool dataSymbolOnly) const override {<br>
+    if (_exportedSyms.count(sym) == 0)<br>
+      return nullptr;<br>
+    std::string expsym = sym;<br>
+    expsym.append("@");<br>
+    auto it = _resolvableSyms.lower_bound(expsym);<br>
+    for (auto e = _resolvableSyms.end(); it != e; ++it) {<br>
+      if (!StringRef(*it).startswith(expsym))<br>
+        return nullptr;<br>
+      if (it->size() == expsym.size())<br>
+        continue;<br>
+      StringRef suffix = it->substr(expsym.size());<br>
+      bool digitSuffix =<br>
+          suffix.find_first_not_of("0123456789") == StringRef::npos;<br>
+      if (digitSuffix) {<br>
+        return new (_alloc) SymbolRenameFile(sym, *it);<br>
+      }<br>
+    }<br>
+    return nullptr;<br>
+  }<br>
+<br>
+private:<br>
+  std::set<std::string> _exportedSyms;<br>
+  std::set<std::string> _resolvableSyms;<br>
+  std::set<ArchiveLibraryFile *> _seen;<br>
+  mutable std::mutex _mutex;<br>
+  mutable llvm::BumpPtrAllocator _alloc;<br>
+};<br>
+<br>
 } // end namespace pecoff<br>
 } // end namespace lld<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>
</div></div></blockquote></div><br></div>