[PATCH] D39919: [llvm-objcopy] Add --strip-debug

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 14:13:15 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL318094: [llvm-objcopy] Add --strip-debug (authored by jakehehrlich).

Changed prior to commit:
  https://reviews.llvm.org/D39919?vs=122506&id=122728#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39919

Files:
  llvm/trunk/test/tools/llvm-objcopy/strip-debug.test
  llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp


Index: llvm/trunk/test/tools/llvm-objcopy/strip-debug.test
===================================================================
--- llvm/trunk/test/tools/llvm-objcopy/strip-debug.test
+++ llvm/trunk/test/tools/llvm-objcopy/strip-debug.test
@@ -0,0 +1,54 @@
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy -strip-debug %t %t2
+# RUN: llvm-readobj -file-headers -sections -symbols %t2 | FileCheck %s
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .debugfoo
+    Type:            SHT_PROGBITS
+    Content:         "00000000"
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000010
+    Content:         "00000000"
+Symbols:
+  Global:
+    - Name: foo
+      Section: .text
+    - Name: debugfoo
+      Section: .debugfoo
+
+# CHECK: SectionHeaderCount: 5
+
+# CHECK: Name: .text
+# CHECK: Name: .symtab
+# CHECK: Name: .strtab
+# CHECK: Name: .shstrtab
+
+# Check that *only* foo is copied and not debugfoo
+# CHECK:      Symbols [
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name:
+# CHECK-NEXT:     Value:
+# CHECK-NEXT:     Size:
+# CHECK-NEXT:     Binding:
+# CHECK-NEXT:     Type:
+# CHECK-NEXT:     Other:
+# CHECK-NEXT:     Section: Undefined
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: foo
+# CHECK-NEXT:     Value:
+# CHECK-NEXT:     Size:
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type:
+# CHECK-NEXT:     Other:
+# CHECK-NEXT:     Section: .text
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
Index: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -83,6 +83,8 @@
                            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 @@
     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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39919.122728.patch
Type: text/x-patch
Size: 2699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171113/9662dae9/attachment.bin>


More information about the llvm-commits mailing list