[PATCH] D66623: [llvm-objcopy] Strip debug sections when running with --strip-unneeded.

Jordan Rupprecht via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 07:29:23 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f323439d897: [llvm-objcopy] Strip debug sections when running with --strip-unneeded. (authored by rupprecht).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66623/new/

https://reviews.llvm.org/D66623

Files:
  llvm/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test
  llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp


Index: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -480,7 +480,7 @@
     };
   }
 
-  if (Config.StripDebug) {
+  if (Config.StripDebug || Config.StripUnneeded) {
     RemovePred = [RemovePred](const SectionBase &Sec) {
       return RemovePred(Sec) || isDebugSection(Sec);
     };
Index: llvm/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test
@@ -0,0 +1,30 @@
+## Verifies that running with --strip-unneeded removes debugging sections but
+## retains the .gnu_debuglink section.
+
+# RUN: yaml2obj %s > %t.o
+# RUN: touch %t.debug
+# RUN: llvm-objcopy --add-gnu-debuglink=%t.debug %t.o %t.2.o
+# RUN: llvm-strip --strip-unneeded %t.2.o -o %t.3.o
+# RUN: llvm-readelf --sections %t.3.o | FileCheck %s
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:            .debugfoo
+    Type:            SHT_PROGBITS
+
+# CHECK: There are 6 section headers
+
+# CHECK:        [ 0]
+# CHECK-NEXT:   [ 1] .text
+# CHECK-NEXT:   [ 2] .symtab
+# CHECK-NEXT:   [ 3] .strtab
+# CHECK-NEXT:   [ 4] .shstrtab
+# CHECK-NEXT:   [ 5] .gnu_debuglink


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66623.216844.patch
Type: text/x-patch
Size: 1602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190823/110cc78e/attachment.bin>


More information about the llvm-commits mailing list