ELF2: Manage BumpPtrAllocator ownership better.

Previously, each ArgParser owned a BumpPtrAllocator, and arguments parsed
by an ArgParser would refer strings allocated using the BumpPtrAllocator
only when response files were used. This could cause a subtle bug because
such ownership was not obvious.

This patch moves the ownership from ArgParser to Driver and make the
ownership explicit.

llvm-svn: 249963
This commit is contained in:
Rui Ueyama 2015-10-11 01:53:07 +00:00
parent a47ee68d8e
commit b973256683
3 changed files with 7 additions and 5 deletions

View File

@ -166,7 +166,7 @@ getString(opt::InputArgList &Args, unsigned Key, StringRef Default = "") {
void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
initSymbols();
opt::InputArgList Args = Parser.parse(ArgsArr);
opt::InputArgList Args = ArgParser(&Alloc).parse(ArgsArr);
createFiles(Args);
switch (Config->ElfKind) {

View File

@ -14,6 +14,7 @@
#include "lld/Core/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/StringSaver.h"
namespace lld {
namespace elf2 {
@ -25,11 +26,13 @@ void link(ArrayRef<const char *> Args);
class ArgParser {
public:
ArgParser(llvm::BumpPtrAllocator *A);
// Parses command line options.
llvm::opt::InputArgList parse(ArrayRef<const char *> Args);
private:
llvm::BumpPtrAllocator Alloc;
llvm::StringSaver Saver;
};
class LinkerDriver {
@ -45,7 +48,6 @@ private:
std::unique_ptr<ELFFileBase> createELFInputFile(MemoryBufferRef MB);
llvm::BumpPtrAllocator Alloc;
ArgParser Parser;
bool WholeArchive = false;
std::vector<std::unique_ptr<InputFile>> Files;
std::vector<std::unique_ptr<ArchiveFile>> OwningArchives;

View File

@ -17,7 +17,6 @@
#include "Error.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/StringSaver.h"
using namespace llvm;
@ -48,6 +47,8 @@ public:
ELFOptTable() : OptTable(infoTable, array_lengthof(infoTable)) {}
};
ArgParser::ArgParser(BumpPtrAllocator *A) : Saver(*A) {}
// Parses a given list of options.
opt::InputArgList ArgParser::parse(ArrayRef<const char *> Argv) {
// Make InputArgList from string vectors.
@ -57,7 +58,6 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> Argv) {
// Expand response files. '@<filename>' is replaced by the file's contents.
SmallVector<const char *, 256> Vec(Argv.data(), Argv.data() + Argv.size());
StringSaver Saver(Alloc);
llvm::cl::ExpandResponseFiles(Saver, llvm::cl::TokenizeGNUCommandLine, Vec);
// Parse options and then do error checking.