[lld] r239671 - Update for llvm api change.
Rafael Espindola
rafael.espindola at gmail.com
Sat Jun 13 05:50:14 PDT 2015
Author: rafael
Date: Sat Jun 13 07:50:13 2015
New Revision: 239671
URL: http://llvm.org/viewvc/llvm-project?rev=239671&view=rev
Log:
Update for llvm api change.
Removed:
lld/trunk/COFF/Memory.h
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Driver.h
lld/trunk/COFF/DriverUtils.cpp
lld/trunk/COFF/InputFiles.h
lld/trunk/COFF/SymbolTable.h
lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/trunk/lib/Driver/GnuLdDriver.cpp
lld/trunk/lib/Driver/WinLinkDriver.cpp
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Sat Jun 13 07:50:13 2015
@@ -10,7 +10,6 @@
#include "Config.h"
#include "Driver.h"
#include "InputFiles.h"
-#include "Memory.h"
#include "SymbolTable.h"
#include "Writer.h"
#include "llvm/ADT/Optional.h"
Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Sat Jun 13 07:50:13 2015
@@ -10,12 +10,13 @@
#ifndef LLD_COFF_DRIVER_H
#define LLD_COFF_DRIVER_H
-#include "Memory.h"
+#include "lld/Core/LLVM.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/COFF.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
+#include "llvm/Support/StringSaver.h"
#include <memory>
#include <set>
#include <system_error>
@@ -37,6 +38,7 @@ bool link(int Argc, const char *Argv[]);
class ArgParser {
public:
+ ArgParser() : Alloc(AllocAux) {}
// Parses command line options.
ErrorOr<std::unique_ptr<llvm::opt::InputArgList>> parse(int Argc,
const char *Argv[]);
@@ -55,12 +57,13 @@ private:
ErrorOr<std::vector<const char *>>
replaceResponseFiles(std::vector<const char *>);
- StringAllocator Alloc;
+ llvm::BumpPtrAllocator AllocAux;
+ llvm::BumpPtrStringSaver Alloc;
};
class LinkerDriver {
public:
- LinkerDriver() : SearchPaths(getSearchPaths()) {}
+ LinkerDriver() : Alloc(AllocAux), SearchPaths(getSearchPaths()) {}
bool link(int Argc, const char *Argv[]);
// Used by the resolver to parse .drectve section contents.
@@ -68,7 +71,8 @@ public:
parseDirectives(StringRef S, std::vector<std::unique_ptr<InputFile>> *Res);
private:
- StringAllocator Alloc;
+ llvm::BumpPtrAllocator AllocAux;
+ llvm::BumpPtrStringSaver Alloc;
ArgParser Parser;
// Opens a file. Path has to be resolved already.
Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Sat Jun 13 07:50:13 2015
@@ -16,7 +16,6 @@
#include "Config.h"
#include "Driver.h"
#include "Error.h"
-#include "Memory.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringSwitch.h"
@@ -197,20 +196,9 @@ ArgParser::parse(int Argc, const char *A
return parse(V);
}
-namespace {
-class BumpPtrStringSaver : public llvm::cl::StringSaver {
-public:
- BumpPtrStringSaver(lld::coff::StringAllocator *A) : Alloc(A) {}
- const char *SaveString(const char *S) override {
- return Alloc->save(S).data();
- }
- lld::coff::StringAllocator *Alloc;
-};
-}
-
std::vector<const char *> ArgParser::tokenize(StringRef S) {
SmallVector<const char *, 16> Tokens;
- BumpPtrStringSaver Saver(&Alloc);
+ BumpPtrStringSaver Saver(AllocAux);
llvm::cl::TokenizeWindowsCommandLine(S, Saver, Tokens);
return std::vector<const char *>(Tokens.begin(), Tokens.end());
}
@@ -220,7 +208,7 @@ std::vector<const char *> ArgParser::tok
ErrorOr<std::vector<const char *>>
ArgParser::replaceResponseFiles(std::vector<const char *> Argv) {
SmallVector<const char *, 256> Tokens(&Argv[0], &Argv[0] + Argv.size());
- BumpPtrStringSaver Saver(&Alloc);
+ BumpPtrStringSaver Saver(AllocAux);
ExpandResponseFiles(Saver, TokenizeWindowsCommandLine, Tokens);
return std::vector<const char *>(Tokens.begin(), Tokens.end());
}
Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Sat Jun 13 07:50:13 2015
@@ -11,13 +11,13 @@
#define LLD_COFF_INPUT_FILES_H
#include "Chunks.h"
-#include "Memory.h"
#include "Symbols.h"
#include "lld/Core/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/LTO/LTOModule.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFF.h"
+#include "llvm/Support/StringSaver.h"
#include <memory>
#include <set>
#include <vector>
@@ -144,7 +144,8 @@ private:
// for details about the format.
class ImportFile : public InputFile {
public:
- explicit ImportFile(MemoryBufferRef M) : InputFile(ImportKind, M) {}
+ explicit ImportFile(MemoryBufferRef M)
+ : InputFile(ImportKind, M), StringAlloc(StringAllocAux) {}
static bool classof(const InputFile *F) { return F->kind() == ImportKind; }
std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }
@@ -153,7 +154,8 @@ private:
std::vector<SymbolBody *> SymbolBodies;
llvm::BumpPtrAllocator Alloc;
- StringAllocator StringAlloc;
+ llvm::BumpPtrAllocator StringAllocAux;
+ llvm::BumpPtrStringSaver StringAlloc;
};
// Used for LTO.
Removed: lld/trunk/COFF/Memory.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Memory.h?rev=239670&view=auto
==============================================================================
--- lld/trunk/COFF/Memory.h (original)
+++ lld/trunk/COFF/Memory.h (removed)
@@ -1,43 +0,0 @@
-//===- Memory.h -----------------------------------------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_COFF_MEMORY_H
-#define LLD_COFF_MEMORY_H
-
-#include "lld/Core/LLVM.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
-#include "llvm/Support/Allocator.h"
-#include <memory>
-
-namespace lld {
-namespace coff {
-
-class StringAllocator {
-public:
- // Returns a null-terminated copy of a string.
- StringRef save(StringRef S) {
- char *P = Alloc.Allocate<char>(S.size() + 1);
- memcpy(P, S.data(), S.size());
- P[S.size()] = '\0';
- return StringRef(P, S.size());
- }
-
- StringRef save(Twine S) { return save(StringRef(S.str())); }
- StringRef save(const char *S) { return save(StringRef(S)); }
- StringRef save(std::string &S) { return save(StringRef(S)); }
-
-private:
- llvm::BumpPtrAllocator Alloc;
-};
-
-} // namespace coff
-} // namespace lld
-
-#endif
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Sat Jun 13 07:50:13 2015
@@ -11,7 +11,6 @@
#define LLD_COFF_SYMBOL_TABLE_H
#include "InputFiles.h"
-#include "Memory.h"
#include "llvm/Support/Allocator.h"
#include <unordered_map>
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Sat Jun 13 07:50:13 2015
@@ -277,6 +277,8 @@ public:
return is64Bit() ? "__delayLoadHelper2" : "___delayLoadHelper2 at 8";
}
+ llvm::BumpPtrAllocator &getAllocator() { return _allocator; }
+
StringRef allocate(StringRef ref) const {
_allocMutex.lock();
char *x = _allocator.Allocate<char>(ref.size() + 1);
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Sat Jun 13 07:50:13 2015
@@ -31,6 +31,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include <cstring>
@@ -74,20 +75,6 @@ public:
GnuLdOptTable() : OptTable(infoTable, llvm::array_lengthof(infoTable)){}
};
-class DriverStringSaver : public llvm::cl::StringSaver {
-public:
- DriverStringSaver(BumpPtrAllocator &alloc) : _alloc(alloc) {}
-
- const char *SaveString(const char *s) override {
- char *p = _alloc.Allocate<char>(strlen(s) + 1);
- strcpy(p, s);
- return p;
- }
-
-private:
- BumpPtrAllocator &_alloc;
-};
-
} // anonymous namespace
// If a command line option starts with "@", the driver reads its suffix as a
@@ -101,7 +88,7 @@ maybeExpandResponseFiles(int argc, const
SmallVector<const char *, 256> smallvec;
for (int i = 0; i < argc; ++i)
smallvec.push_back(argv[i]);
- DriverStringSaver saver(alloc);
+ llvm::BumpPtrStringSaver saver(alloc);
llvm::cl::ExpandResponseFiles(saver, llvm::cl::TokenizeGNUCommandLine, smallvec);
// Pack the results to a C-array and return it.
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Sat Jun 13 07:50:13 2015
@@ -29,6 +29,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
+#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cctype>
@@ -694,20 +695,6 @@ static void processLibEnv(PECOFFLinkingC
ctx.appendInputSearchPath(ctx.allocate(path));
}
-namespace {
-class DriverStringSaver : public llvm::cl::StringSaver {
-public:
- DriverStringSaver(PECOFFLinkingContext &ctx) : _ctx(ctx) {}
-
- const char *SaveString(const char *s) override {
- return _ctx.allocate(StringRef(s)).data();
- }
-
-private:
- PECOFFLinkingContext &_ctx;
-};
-}
-
// Tokenize command line options in a given file and add them to result.
static bool readResponseFile(StringRef path, PECOFFLinkingContext &ctx,
std::vector<const char *> &result) {
@@ -716,7 +703,7 @@ static bool readResponseFile(StringRef p
return false;
StringRef contentsStr(reinterpret_cast<const char *>(contents.data()),
contents.size());
- DriverStringSaver saver(ctx);
+ llvm::BumpPtrStringSaver saver(ctx.getAllocator());
SmallVector<const char *, 0> args;
llvm::cl::TokenizeWindowsCommandLine(contentsStr, saver, args);
for (const char *s : args)
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=239671&r1=239670&r2=239671&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Sat Jun 13 07:50:13 2015
@@ -29,6 +29,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
+#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <map>
@@ -54,14 +55,12 @@ using namespace lld;
namespace {
-class BumpPtrStringSaver : public llvm::cl::StringSaver {
+class BumpPtrStringSaver final : public llvm::StringSaver {
public:
- const char *SaveString(const char *str) override {
- size_t len = strlen(str);
+ BumpPtrStringSaver() : llvm::StringSaver(_alloc) {}
+ const char *saveImpl(StringRef Str) override {
std::lock_guard<std::mutex> lock(_allocMutex);
- char *copy = _alloc.Allocate<char>(len + 1);
- memcpy(copy, str, len + 1);
- return copy;
+ return llvm::StringSaver::saveImpl(Str);
}
private:
More information about the llvm-commits
mailing list