summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorJake Ehrlich <jakehehrlich@google.com>2017-11-13 22:13:08 +0000
committerJake Ehrlich <jakehehrlich@google.com>2017-11-13 22:13:08 +0000
commit1bfefc1c725792108a37f4e2678eb23fb06bb92f (patch)
tree85a06980489f70a7b82eef196f4548598669f8fd /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parent33f83995a8cb8071255b7b923c94c243e4bd2ebb (diff)
downloadbcm5719-llvm-1bfefc1c725792108a37f4e2678eb23fb06bb92f.tar.gz
bcm5719-llvm-1bfefc1c725792108a37f4e2678eb23fb06bb92f.zip
[llvm-objcopy] Add --strip-debug
Many projects use this option. There are two ways to use it. You can either a) Just use --strip-debug and keep the old file with debug content or b) you can use --strip-debug, --only-keep-debug, and --add-gnu-debuglink all in conjunction to create two separate files, the stripped file and the debug file. --only-keep-debug is more complicated than --strip-debug because it keeps the section headers without keeping section contents. That's not really supported by llvm-objcopy at the moment but I plan on adding it. So this change just supports a) and options to support b) will come soon. Differential Revision: https://reviews.llvm.org/D39919 llvm-svn: 318094
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 12d6205722f..b520a1415c2 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -83,6 +83,8 @@ static cl::alias ToRemoveA("R", cl::desc("Alias for remove-section"),
cl::aliasopt(ToRemove));
static cl::opt<bool> StripAll("strip-all",
cl::desc("Removes symbol, relocation, and debug information"));
+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>
@@ -197,6 +199,12 @@ void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) {
Obj->WriteSectionHeaders = false;
}
+ if (StripDebug) {
+ RemovePred = [RemovePred](const SectionBase &Sec) {
+ return RemovePred(Sec) || Sec.Name.startswith(".debug");
+ };
+ }
+
Obj->removeSections(RemovePred);
Obj->finalize();
WriteObjectFile(*Obj, OutputFilename.getValue());
OpenPOWER on IntegriCloud