summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorJake Ehrlich <jakehehrlich@google.com>2017-10-10 23:02:43 +0000
committerJake Ehrlich <jakehehrlich@google.com>2017-10-10 23:02:43 +0000
commitfcc05627d43f3ab272005b7f314689625af03525 (patch)
tree9005f3f0aa0c498734ebf9a0a6f283e414971260 /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parenta1b79dff2af6b739d047d6b43c24e287724cd637 (diff)
downloadbcm5719-llvm-fcc05627d43f3ab272005b7f314689625af03525.tar.gz
bcm5719-llvm-fcc05627d43f3ab272005b7f314689625af03525.zip
[llvm-objcopy] Add ability to remove multiple sections by name
This change adds the ability to use the "-R"/"-remove-section" option multiple times. Differential Revision: https://reviews.llvm.org/D38332 llvm-svn: 315385
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 775c5ae42b6..d76735482d6 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -56,10 +56,11 @@ cl::opt<std::string> OutputFilename(cl::Positional, cl::desc("<output>"),
cl::opt<std::string>
OutputFormat("O", cl::desc("set output format to one of the following:"
"\n\tbinary"));
-// TODO: make this a cl::list to support removing multiple sections
-cl::opt<std::string> ToRemove("remove-section",
- cl::desc("Remove a specific section"));
-cl::alias ToRemoveA("R", cl::desc("Alias for remove-section"), cl::aliasopt(ToRemove));
+
+cl::list<std::string> ToRemove("remove-section",
+ cl::desc("Remove a specific section"));
+cl::alias ToRemoveA("R", cl::desc("Alias for remove-section"),
+ cl::aliasopt(ToRemove));
void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) {
std::unique_ptr<FileOutputBuffer> Buffer;
@@ -71,8 +72,10 @@ void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) {
else
Obj = llvm::make_unique<ELFObject<ELF64LE>>(ObjFile);
if (!ToRemove.empty()) {
- Obj->removeSections(
- [&](const SectionBase &Sec) { return ToRemove == Sec.Name; });
+ Obj->removeSections([&](const SectionBase &Sec) {
+ return std::find(std::begin(ToRemove), std::end(ToRemove), Sec.Name) !=
+ std::end(ToRemove);
+ });
}
Obj->finalize();
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
OpenPOWER on IntegriCloud