[lld] r249963 - ELF2: Manage BumpPtrAllocator ownership better.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 10 18:53:08 PDT 2015


Author: ruiu
Date: Sat Oct 10 20:53:07 2015
New Revision: 249963

URL: http://llvm.org/viewvc/llvm-project?rev=249963&view=rev
Log:
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.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Driver.h
    lld/trunk/ELF/DriverUtils.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=249963&r1=249962&r2=249963&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Oct 10 20:53:07 2015
@@ -166,7 +166,7 @@ getString(opt::InputArgList &Args, unsig
 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) {

Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=249963&r1=249962&r2=249963&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Sat Oct 10 20:53:07 2015
@@ -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;

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=249963&r1=249962&r2=249963&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Sat Oct 10 20:53:07 2015
@@ -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(Array
 
   // 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.




More information about the llvm-commits mailing list