From: Jordan Rupprecht Date: Mon, 4 Feb 2019 18:38:00 +0000 (+0000) Subject: [llvm-objcopy][NFC] Use StringSaver for --keep-global-symbols X-Git-Tag: llvmorg-10-init~12872 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5745c5f54f459bdd9de36df031e697c59f2d4717;p=platform%2Fupstream%2Fllvm.git [llvm-objcopy][NFC] Use StringSaver for --keep-global-symbols Summary: Use StringSaver/BumpPtrAlloc when parsing lines from --keep-global-symbols files. This allows us to consistently use StringRef for driver options, which avoids copying the full strings for each object copied, as well as simplifies part of D57517. Reviewers: jhenderson, evgeny777, alexshap Subscribers: jakehehrlich Tags: #llvm Differential Revision: https://reviews.llvm.org/D57617 llvm-svn: 353068 --- diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp index 053f908..9172196 100644 --- a/llvm/tools/llvm-objcopy/CopyConfig.cpp +++ b/llvm/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 -#include namespace llvm { namespace objcopy { @@ -225,8 +225,10 @@ static const MachineInfo &getOutputFormatMachineInfo(StringRef Format) { return Iter->getValue(); } -static void addGlobalSymbolsFromFile(std::vector &Symbols, +static void addGlobalSymbolsFromFile(std::vector &Symbols, + BumpPtrAllocator &Alloc, StringRef Filename) { + StringSaver Saver(Alloc); SmallVector Lines; auto BufOrErr = MemoryBuffer::getFile(Filename); if (!BufOrErr) @@ -238,7 +240,7 @@ static void addGlobalSymbolsFromFile(std::vector &Symbols, // 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 @@ static void addGlobalSymbolsFromFile(std::vector &Symbols, // help flag is set then ParseObjcopyOptions will print the help messege and // exit. DriverConfig parseObjcopyOptions(ArrayRef ArgsArr) { + DriverConfig DC; ObjcopyOptTable T; unsigned MissingArgumentIndex, MissingArgumentCount; llvm::opt::InputArgList InputArgs = @@ -401,7 +404,8 @@ DriverConfig parseObjcopyOptions(ArrayRef ArgsArr) { 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 @@ DriverConfig parseObjcopyOptions(ArrayRef ArgsArr) { 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; } diff --git a/llvm/tools/llvm-objcopy/CopyConfig.h b/llvm/tools/llvm-objcopy/CopyConfig.h index 9a9a098..9d16c7b 100644 --- a/llvm/tools/llvm-objcopy/CopyConfig.h +++ b/llvm/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 #include namespace llvm { @@ -81,7 +81,7 @@ struct CopyConfig { std::vector SymbolsToRemove; std::vector SymbolsToWeaken; std::vector ToRemove; - std::vector SymbolsToKeepGlobal; + std::vector SymbolsToKeepGlobal; // Map options StringMap SectionsToRename; @@ -112,6 +112,7 @@ struct CopyConfig { // will contain one or more CopyConfigs. struct DriverConfig { SmallVector CopyConfigs; + BumpPtrAllocator Alloc; }; // ParseObjcopyOptions returns the config and sets the input arguments. If a