[lld] r208427 - temporary commit.

Rui Ueyama ruiu at google.com
Fri May 9 09:53:30 PDT 2014


Ooh, yes. I'll revert it now. I thought I was working in a different branch.


On Fri, May 9, 2014 at 9:46 AM, Joey Gouly <joey.gouly at gmail.com> wrote:

> Was this accidental?
> On 9 May 2014 17:43, "Rui Ueyama" <ruiu at google.com> wrote:
>
>> Author: ruiu
>> Date: Fri May  9 11:35:23 2014
>> New Revision: 208427
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=208427&view=rev
>> Log:
>> temporary commit.
>>
>> Modified:
>>     lld/trunk/include/lld/Core/ArchiveLibraryFile.h
>>     lld/trunk/include/lld/Core/InputGraph.h
>>     lld/trunk/lib/Core/InputGraph.cpp
>>     lld/trunk/lib/Driver/WinLinkDriver.cpp
>>     lld/trunk/lib/ReaderWriter/FileArchive.cpp
>>     lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
>>
>> Modified: lld/trunk/include/lld/Core/ArchiveLibraryFile.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/ArchiveLibraryFile.h?rev=208427&r1=208426&r2=208427&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/include/lld/Core/ArchiveLibraryFile.h (original)
>> +++ lld/trunk/include/lld/Core/ArchiveLibraryFile.h Fri May  9 11:35:23
>> 2014
>> @@ -12,6 +12,8 @@
>>
>>  #include "lld/Core/File.h"
>>
>> +#include <set>
>> +
>>  namespace lld {
>>
>>  ///
>> @@ -36,6 +38,10 @@ public:
>>    virtual error_code
>>    parseAllMembers(std::vector<std::unique_ptr<File>> &result) const = 0;
>>
>> +  virtual std::set<StringRef> getDefinedSymbols() const {
>> +    return std::set<StringRef>();
>> +  }
>> +
>>  protected:
>>    /// only subclasses of ArchiveLibraryFile can be instantiated
>>    ArchiveLibraryFile(StringRef path) : File(path, kindArchiveLibrary) {}
>>
>> Modified: lld/trunk/include/lld/Core/InputGraph.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=208427&r1=208426&r2=208427&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/include/lld/Core/InputGraph.h (original)
>> +++ lld/trunk/include/lld/Core/InputGraph.h Fri May  9 11:35:23 2014
>> @@ -23,6 +23,7 @@
>>  #include "llvm/Support/MemoryBuffer.h"
>>  #include "llvm/Support/raw_ostream.h"
>>
>> +#include <functional>
>>  #include <memory>
>>  #include <stack>
>>  #include <vector>
>> @@ -67,6 +68,11 @@ public:
>>    /// whether it should iterate over again or terminate or not.
>>    void notifyProgress();
>>
>> +  /// Adds an observer of getNextFile(). Each time a new file is about
>> to be
>> +  /// returned from getNextFile(), registered observers are called with
>> the file
>> +  /// being returned.
>> +  void registerObserver(std::function<void(File*)> &fn);
>> +
>>    /// \brief Adds a node into the InputGraph
>>    void addInputElement(std::unique_ptr<InputElement>);
>>
>> @@ -93,6 +99,7 @@ protected:
>>    // Index of the next element to be processed
>>    uint32_t _nextElementIndex;
>>    InputElement *_currentInputElement;
>> +  std::vector<std::function<void(File *)>> _observers;
>>
>>  private:
>>    ErrorOr<InputElement *> getNextInputElement();
>>
>> Modified: lld/trunk/lib/Core/InputGraph.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=208427&r1=208426&r2=208427&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/lib/Core/InputGraph.cpp (original)
>> +++ lld/trunk/lib/Core/InputGraph.cpp Fri May  9 11:35:23 2014
>> @@ -21,9 +21,12 @@ ErrorOr<File &> InputGraph::getNextFile(
>>    // it will succeed. If not, try to get the next file in the input
>> graph.
>>    for (;;) {
>>      if (_currentInputElement) {
>> -      ErrorOr<File &> nextFile = _currentInputElement->getNextFile();
>> -      if (nextFile.getError() != InputGraphError::no_more_files)
>> -        return std::move(nextFile);
>> +      ErrorOr<File &> next = _currentInputElement->getNextFile();
>> +      if (next.getError() != InputGraphError::no_more_files) {
>> +        for (std::function<void(File*)> &observer : _observers)
>> +          observer(&next.get());
>> +        return std::move(next);
>> +      }
>>      }
>>
>>      ErrorOr<InputElement *> elt = getNextInputElement();
>> @@ -35,6 +38,10 @@ ErrorOr<File &> InputGraph::getNextFile(
>>
>>  void InputGraph::notifyProgress() {
>> _currentInputElement->notifyProgress(); }
>>
>> +void InputGraph::registerObserver(std::function<void(File*)> &fn) {
>> +  _observers.push_back(fn);
>> +}
>> +
>>  void InputGraph::addInputElement(std::unique_ptr<InputElement> ie) {
>>    _inputArgs.push_back(std::move(ie));
>>  }
>>
>> Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=208427&r1=208426&r2=208427&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
>> +++ lld/trunk/lib/Driver/WinLinkDriver.cpp Fri May  9 11:35:23 2014
>> @@ -13,10 +13,12 @@
>>  ///
>>
>>  //===----------------------------------------------------------------------===//
>>
>> +#include "lld/Core/ArchiveLibraryFile.h"
>>  #include "lld/Driver/Driver.h"
>>  #include "lld/Driver/WinLinkInputGraph.h"
>>  #include "lld/Driver/WinLinkModuleDef.h"
>>  #include "lld/ReaderWriter/PECOFFLinkingContext.h"
>> +#include "../ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h"
>>
>>  #include "llvm/ADT/ArrayRef.h"
>>  #include "llvm/ADT/Optional.h"
>> @@ -34,6 +36,7 @@
>>
>>  #include <algorithm>
>>  #include <cctype>
>> +#include <functional>
>>  #include <map>
>>  #include <memory>
>>  #include <sstream>
>> @@ -1293,6 +1296,19 @@ bool WinLinkDriver::parse(int argc, cons
>>      }
>>    }
>>
>> +  if (!isReadingDirectiveSection) {
>> +    std::unique_ptr<SimpleFileNode> node(new SimpleFileNode("<export>"));
>> +    pecoff::ExportedSymbolRenameFile *renameFile =
>> +        new pecoff::ExportedSymbolRenameFile(ctx);
>> +    node->appendInputFile(std::unique_ptr<File>(renameFile));
>> +    ctx.getLibraryGroup()->addFile(std::move(node));
>> +    std::function<void(File *)> observer = [=](File *file) {
>> +      if (auto *archive = dyn_cast<ArchiveLibraryFile>(file))
>> +        renameFile->addResolvableSymbols(archive);
>> +    };
>> +    ctx.getInputGraph().registerObserver(observer);
>> +  }
>> +
>>    // Validate the combination of options used.
>>    return ctx.validate(diag);
>>  }
>>
>> Modified: lld/trunk/lib/ReaderWriter/FileArchive.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/FileArchive.cpp?rev=208427&r1=208426&r2=208427&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/lib/ReaderWriter/FileArchive.cpp (original)
>> +++ lld/trunk/lib/ReaderWriter/FileArchive.cpp Fri May  9 11:35:23 2014
>> @@ -97,6 +97,16 @@ public:
>>      return _absoluteAtoms;
>>    }
>>
>> +  /// Returns a set of all defined symbols in the archive.
>> +  std::set<StringRef> getDefinedSymbols() const override {
>> +    std::set<StringRef> ret;
>> +    for (const auto &e : _symbolMemberMap) {
>> +      StringRef sym = e.first;
>> +      ret.insert(sym);
>> +    }
>> +    return ret;
>> +  }
>> +
>>  protected:
>>    error_code
>>    instantiateMember(Archive::child_iterator member,
>>
>> Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=208427&r1=208426&r2=208427&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
>> (original)
>> +++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h Fri May
>>  9 11:35:23 2014
>> @@ -13,6 +13,9 @@
>>  #include "lld/ReaderWriter/PECOFFLinkingContext.h"
>>  #include "lld/ReaderWriter/Simple.h"
>>  #include "llvm/Support/Allocator.h"
>> +#include "llvm/Support/Debug.h"
>> +
>> +#include <mutex>
>>
>>  namespace lld {
>>  namespace pecoff {
>> @@ -86,6 +89,18 @@ private:
>>    atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
>>  };
>>
>> +class SymbolRenameFile : public SimpleFile {
>> +public:
>> +  SymbolRenameFile(StringRef from, StringRef to)
>> +      : SimpleFile("<symbol-rename>"), _to(*this, to), _from(*this,
>> from, &_to) {
>> +    addAtom(_from);
>> +  };
>> +
>> +private:
>> +  COFFUndefinedAtom _to;
>> +  COFFUndefinedAtom _from;
>> +};
>> +
>>  } // anonymous namespace
>>
>>  // A virtual file containing absolute symbol __ImageBase. __ImageBase (or
>> @@ -141,5 +156,51 @@ private:
>>    mutable llvm::BumpPtrAllocator _alloc;
>>  };
>>
>> +class ExportedSymbolRenameFile : public VirtualArchiveLibraryFile {
>> +public:
>> +  ExportedSymbolRenameFile(const PECOFFLinkingContext &ctx)
>> +      : VirtualArchiveLibraryFile("<export>") {
>> +    for (const PECOFFLinkingContext::ExportDesc &desc :
>> ctx.getDllExports())
>> +      _exportedSyms.insert(desc.name);
>> +  }
>> +
>> +  void addResolvableSymbols(ArchiveLibraryFile *archive) {
>> +    std::lock_guard<std::mutex> lock(_mutex);
>> +    if (_seen.count(archive) > 0)
>> +      return;
>> +    _seen.insert(archive);
>> +    for (const std::string &sym : archive->getDefinedSymbols())
>> +      _resolvableSyms.insert(sym);
>> +  }
>> +
>> +  const File *find(StringRef sym, bool dataSymbolOnly) const override {
>> +    if (_exportedSyms.count(sym) == 0)
>> +      return nullptr;
>> +    std::string expsym = sym;
>> +    expsym.append("@");
>> +    auto it = _resolvableSyms.lower_bound(expsym);
>> +    for (auto e = _resolvableSyms.end(); it != e; ++it) {
>> +      if (!StringRef(*it).startswith(expsym))
>> +        return nullptr;
>> +      if (it->size() == expsym.size())
>> +        continue;
>> +      StringRef suffix = it->substr(expsym.size());
>> +      bool digitSuffix =
>> +          suffix.find_first_not_of("0123456789") == StringRef::npos;
>> +      if (digitSuffix) {
>> +        return new (_alloc) SymbolRenameFile(sym, *it);
>> +      }
>> +    }
>> +    return nullptr;
>> +  }
>> +
>> +private:
>> +  std::set<std::string> _exportedSyms;
>> +  std::set<std::string> _resolvableSyms;
>> +  std::set<ArchiveLibraryFile *> _seen;
>> +  mutable std::mutex _mutex;
>> +  mutable llvm::BumpPtrAllocator _alloc;
>> +};
>> +
>>  } // end namespace pecoff
>>  } // end namespace lld
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140509/26820f83/attachment.html>


More information about the llvm-commits mailing list