forked from OSchip/llvm-project
COFF: Use a string saver in Memory.h in Driver.
llvm-svn: 289104
This commit is contained in:
parent
bcc6cea748
commit
8d433d71f5
|
@ -150,11 +150,11 @@ StringRef LinkerDriver::doFindFile(StringRef Filename) {
|
|||
SmallString<128> Path = Dir;
|
||||
sys::path::append(Path, Filename);
|
||||
if (sys::fs::exists(Path.str()))
|
||||
return Alloc.save(Path.str());
|
||||
return Saver.save(Path.str());
|
||||
if (!HasExt) {
|
||||
Path.append(".obj");
|
||||
if (sys::fs::exists(Path.str()))
|
||||
return Alloc.save(Path.str());
|
||||
return Saver.save(Path.str());
|
||||
}
|
||||
}
|
||||
return Filename;
|
||||
|
@ -175,7 +175,7 @@ StringRef LinkerDriver::doFindLib(StringRef Filename) {
|
|||
// Add ".lib" to Filename if that has no file extension.
|
||||
bool HasExt = (Filename.find('.') != StringRef::npos);
|
||||
if (!HasExt)
|
||||
Filename = Alloc.save(Filename + ".lib");
|
||||
Filename = Saver.save(Filename + ".lib");
|
||||
return doFindFile(Filename);
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ void LinkerDriver::addLibSearchPaths() {
|
|||
Optional<std::string> EnvOpt = Process::GetEnv("LIB");
|
||||
if (!EnvOpt.hasValue())
|
||||
return;
|
||||
StringRef Env = Alloc.save(*EnvOpt);
|
||||
StringRef Env = Saver.save(*EnvOpt);
|
||||
while (!Env.empty()) {
|
||||
StringRef Path;
|
||||
std::tie(Path, Env) = Env.split(';');
|
||||
|
@ -217,7 +217,7 @@ Undefined *LinkerDriver::addUndefined(StringRef Name) {
|
|||
StringRef LinkerDriver::mangle(StringRef Sym) {
|
||||
assert(Config->Machine != IMAGE_FILE_MACHINE_UNKNOWN);
|
||||
if (Config->Machine == I386)
|
||||
return Alloc.save("_" + Sym);
|
||||
return Saver.save("_" + Sym);
|
||||
return Sym;
|
||||
}
|
||||
|
||||
|
@ -633,9 +633,9 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
|||
Export E = parseExport(Arg->getValue());
|
||||
if (Config->Machine == I386) {
|
||||
if (!isDecorated(E.Name))
|
||||
E.Name = Alloc.save("_" + E.Name);
|
||||
E.Name = Saver.save("_" + E.Name);
|
||||
if (!E.ExtName.empty() && !isDecorated(E.ExtName))
|
||||
E.ExtName = Alloc.save("_" + E.ExtName);
|
||||
E.ExtName = Saver.save("_" + E.ExtName);
|
||||
}
|
||||
Config->Exports.push_back(E);
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
|||
if (auto *Arg = Args.getLastArg(OPT_deffile)) {
|
||||
MemoryBufferRef MB = openFile(Arg->getValue());
|
||||
// parseModuleDefs mutates Config object.
|
||||
parseModuleDefs(MB, &Alloc);
|
||||
parseModuleDefs(MB);
|
||||
}
|
||||
|
||||
// Handle /delayload
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#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 <vector>
|
||||
|
@ -43,7 +42,6 @@ void doICF(const std::vector<Chunk *> &Chunks);
|
|||
|
||||
class ArgParser {
|
||||
public:
|
||||
ArgParser() : Alloc(AllocAux) {}
|
||||
// Parses command line options.
|
||||
llvm::opt::InputArgList parse(llvm::ArrayRef<const char *> Args);
|
||||
|
||||
|
@ -57,14 +55,10 @@ private:
|
|||
std::vector<const char *> tokenize(StringRef S);
|
||||
|
||||
std::vector<const char *> replaceResponseFiles(std::vector<const char *>);
|
||||
|
||||
llvm::BumpPtrAllocator AllocAux;
|
||||
llvm::StringSaver Alloc;
|
||||
};
|
||||
|
||||
class LinkerDriver {
|
||||
public:
|
||||
LinkerDriver() : Alloc(AllocAux) {}
|
||||
void link(llvm::ArrayRef<const char *> Args);
|
||||
|
||||
// Used by the resolver to parse .drectve section contents.
|
||||
|
@ -73,8 +67,6 @@ public:
|
|||
std::unique_ptr<CpioFile> Cpio; // for /linkrepro
|
||||
|
||||
private:
|
||||
llvm::BumpPtrAllocator AllocAux;
|
||||
llvm::StringSaver Alloc;
|
||||
ArgParser Parser;
|
||||
SymbolTable Symtab;
|
||||
|
||||
|
@ -112,7 +104,7 @@ private:
|
|||
std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
|
||||
};
|
||||
|
||||
void parseModuleDefs(MemoryBufferRef MB, llvm::StringSaver *Alloc);
|
||||
void parseModuleDefs(MemoryBufferRef MB);
|
||||
void writeImportLibrary();
|
||||
|
||||
// Functions below this line are defined in DriverUtils.cpp.
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "Driver.h"
|
||||
#include "Error.h"
|
||||
#include "Symbols.h"
|
||||
#include "lld/Support/Memory.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Object/COFF.h"
|
||||
|
@ -678,7 +679,6 @@ opt::InputArgList ArgParser::parseLINK(ArrayRef<const char *> Args) {
|
|||
|
||||
std::vector<const char *> ArgParser::tokenize(StringRef S) {
|
||||
SmallVector<const char *, 16> Tokens;
|
||||
StringSaver Saver(AllocAux);
|
||||
cl::TokenizeWindowsCommandLine(S, Saver, Tokens);
|
||||
return std::vector<const char *>(Tokens.begin(), Tokens.end());
|
||||
}
|
||||
|
@ -688,7 +688,6 @@ std::vector<const char *> ArgParser::tokenize(StringRef S) {
|
|||
std::vector<const char *>
|
||||
ArgParser::replaceResponseFiles(std::vector<const char *> Argv) {
|
||||
SmallVector<const char *, 256> Tokens(Argv.data(), Argv.data() + Argv.size());
|
||||
StringSaver Saver(AllocAux);
|
||||
ExpandResponseFiles(Saver, TokenizeWindowsCommandLine, Tokens);
|
||||
return std::vector<const char *>(Tokens.begin(), Tokens.end());
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "Config.h"
|
||||
#include "Error.h"
|
||||
#include "lld/Support/Memory.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Support/StringSaver.h"
|
||||
|
@ -113,7 +114,7 @@ private:
|
|||
|
||||
class Parser {
|
||||
public:
|
||||
explicit Parser(StringRef S, StringSaver *A) : Lex(S), Alloc(A) {}
|
||||
explicit Parser(StringRef S) : Lex(S) {}
|
||||
|
||||
void parse() {
|
||||
do {
|
||||
|
@ -197,9 +198,9 @@ private:
|
|||
|
||||
if (Config->Machine == I386) {
|
||||
if (!isDecorated(E.Name))
|
||||
E.Name = Alloc->save("_" + E.Name);
|
||||
E.Name = Saver.save("_" + E.Name);
|
||||
if (!E.ExtName.empty() && !isDecorated(E.ExtName))
|
||||
E.ExtName = Alloc->save("_" + E.ExtName);
|
||||
E.ExtName = Saver.save("_" + E.ExtName);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
|
@ -283,9 +284,7 @@ private:
|
|||
|
||||
} // anonymous namespace
|
||||
|
||||
void parseModuleDefs(MemoryBufferRef MB, StringSaver *Alloc) {
|
||||
Parser(MB.getBuffer(), Alloc).parse();
|
||||
}
|
||||
void parseModuleDefs(MemoryBufferRef MB) { Parser(MB.getBuffer()).parse(); }
|
||||
|
||||
} // namespace coff
|
||||
} // namespace lld
|
||||
|
|
Loading…
Reference in New Issue