[PATCH] D57617: [llvm-objcopy][NFC] Use StringSaver for --keep-global-symbols

Jordan Rupprecht via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 4 10:39:16 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL353068: [llvm-objcopy][NFC] Use StringSaver for --keep-global-symbols (authored by rupprecht, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D57617?vs=184836&id=185089#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57617/new/

https://reviews.llvm.org/D57617

Files:
  llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
  llvm/trunk/tools/llvm-objcopy/CopyConfig.h


Index: llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
+++ llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
@@ -19,8 +19,8 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/StringSaver.h"
 #include <memory>
-#include <string>
 
 namespace llvm {
 namespace objcopy {
@@ -225,8 +225,10 @@
   return Iter->getValue();
 }
 
-static void addGlobalSymbolsFromFile(std::vector<std::string> &Symbols,
+static void addGlobalSymbolsFromFile(std::vector<StringRef> &Symbols,
+                                     BumpPtrAllocator &Alloc,
                                      StringRef Filename) {
+  StringSaver Saver(Alloc);
   SmallVector<StringRef, 16> Lines;
   auto BufOrErr = MemoryBuffer::getFile(Filename);
   if (!BufOrErr)
@@ -238,7 +240,7 @@
     // it's not empty.
     auto TrimmedLine = Line.split('#').first.trim();
     if (!TrimmedLine.empty())
-      Symbols.push_back(TrimmedLine.str());
+      Symbols.push_back(Saver.save(TrimmedLine));
   }
 }
 
@@ -246,6 +248,7 @@
 // help flag is set then ParseObjcopyOptions will print the help messege and
 // exit.
 DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
+  DriverConfig DC;
   ObjcopyOptTable T;
   unsigned MissingArgumentIndex, MissingArgumentCount;
   llvm::opt::InputArgList InputArgs =
@@ -401,7 +404,8 @@
   for (auto Arg : InputArgs.filtered(OBJCOPY_keep_global_symbol))
     Config.SymbolsToKeepGlobal.push_back(Arg->getValue());
   for (auto Arg : InputArgs.filtered(OBJCOPY_keep_global_symbols))
-    addGlobalSymbolsFromFile(Config.SymbolsToKeepGlobal, Arg->getValue());
+    addGlobalSymbolsFromFile(Config.SymbolsToKeepGlobal, DC.Alloc,
+                             Arg->getValue());
   for (auto Arg : InputArgs.filtered(OBJCOPY_globalize_symbol))
     Config.SymbolsToGlobalize.push_back(Arg->getValue());
   for (auto Arg : InputArgs.filtered(OBJCOPY_weaken_symbol))
@@ -426,7 +430,6 @@
   if (Config.DecompressDebugSections && !zlib::isAvailable())
     error("LLVM was not compiled with LLVM_ENABLE_ZLIB: cannot decompress.");
 
-  DriverConfig DC;
   DC.CopyConfigs.push_back(std::move(Config));
   return DC;
 }
Index: llvm/trunk/tools/llvm-objcopy/CopyConfig.h
===================================================================
--- llvm/trunk/tools/llvm-objcopy/CopyConfig.h
+++ llvm/trunk/tools/llvm-objcopy/CopyConfig.h
@@ -14,9 +14,9 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
 // Necessary for llvm::DebugCompressionType::None
 #include "llvm/Target/TargetOptions.h"
-#include <string>
 #include <vector>
 
 namespace llvm {
@@ -81,7 +81,7 @@
   std::vector<StringRef> SymbolsToRemove;
   std::vector<StringRef> SymbolsToWeaken;
   std::vector<StringRef> ToRemove;
-  std::vector<std::string> SymbolsToKeepGlobal;
+  std::vector<StringRef> SymbolsToKeepGlobal;
 
   // Map options
   StringMap<SectionRename> SectionsToRename;
@@ -112,6 +112,7 @@
 // will contain one or more CopyConfigs.
 struct DriverConfig {
   SmallVector<CopyConfig, 1> CopyConfigs;
+  BumpPtrAllocator Alloc;
 };
 
 // ParseObjcopyOptions returns the config and sets the input arguments. If a


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57617.185089.patch
Type: text/x-patch
Size: 3377 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190204/ae4d3a47/attachment.bin>


More information about the llvm-commits mailing list