summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorJake Ehrlich <jakehehrlich@google.com>2017-11-14 18:50:24 +0000
committerJake Ehrlich <jakehehrlich@google.com>2017-11-14 18:50:24 +0000
commitd56725a042871238ed0a4ad4576497b55db2c960 (patch)
treee9407a7a2db7a08e86cbd25d3f2c5c992ffe95ab /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parent0b2f73fd84ca59735efdec4b230941634b59e485 (diff)
downloadbcm5719-llvm-d56725a042871238ed0a4ad4576497b55db2c960.tar.gz
bcm5719-llvm-d56725a042871238ed0a4ad4576497b55db2c960.zip
[llvm-objcopy] Add -strip-non-alloc option to remove all non-allocated sections
This change adds a new flag not present in GNU objcopy that we call --strip-non-alloc. Differential Revision: https://reviews.llvm.org/D39926 llvm-svn: 318168
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index f7a94f5f891..812d27b403f 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -87,6 +87,8 @@ static cl::opt<bool> StripDebug("strip-debug",
cl::desc("Removes all debug information"));
static cl::opt<bool> StripSections("strip-sections",
cl::desc("Remove all section headers"));
+static cl::opt<bool> StripNonAlloc("strip-non-alloc",
+ cl::desc("Remove all non-allocated sections"));
static cl::opt<bool>
StripDWO("strip-dwo", cl::desc("remove all DWARF .dwo sections from file"));
static cl::opt<bool> ExtractDWO(
@@ -206,6 +208,15 @@ void CopyBinary(const ELFObjectFile<ELFT> &ObjFile) {
};
}
+ if (StripNonAlloc)
+ RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
+ if (RemovePred(Sec))
+ return true;
+ if (&Sec == Obj->getSectionHeaderStrTab())
+ return false;
+ return (Sec.Flags & SHF_ALLOC) == 0;
+ };
+
Obj->removeSections(RemovePred);
Obj->finalize();
WriteObjectFile(*Obj, OutputFilename.getValue());
OpenPOWER on IntegriCloud