#include "Config.h"
#include "Driver.h"
#include "InputFiles.h"
-#include "Memory.h"
#include "SymbolTable.h"
#include "Writer.h"
#include "llvm/ADT/Optional.h"
#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>
class ArgParser {
public:
+ ArgParser() : Alloc(AllocAux) {}
// Parses command line options.
ErrorOr<std::unique_ptr<llvm::opt::InputArgList>> parse(int Argc,
const char *Argv[]);
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.
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.
#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"
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());
}
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());
}
#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>
// 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; }
std::vector<SymbolBody *> SymbolBodies;
llvm::BumpPtrAllocator Alloc;
- StringAllocator StringAlloc;
+ llvm::BumpPtrAllocator StringAllocAux;
+ llvm::BumpPtrStringSaver StringAlloc;
};
// Used for LTO.
+++ /dev/null
-//===- 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
#define LLD_COFF_SYMBOL_TABLE_H
#include "InputFiles.h"
-#include "Memory.h"
#include "llvm/Support/Allocator.h"
#include <unordered_map>
return is64Bit() ? "__delayLoadHelper2" : "___delayLoadHelper2@8";
}
+ llvm::BumpPtrAllocator &getAllocator() { return _allocator; }
+
StringRef allocate(StringRef ref) const {
_allocMutex.lock();
char *x = _allocator.Allocate<char>(ref.size() + 1);
#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>
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
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.
#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>
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) {
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)
#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>
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: