[llvm] r369761 - [llvm-objcopy] Strip debug sections when running with --strip-unneeded.

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


Author: rupprecht
Date: Fri Aug 23 07:28:58 2019
New Revision: 369761

URL: http://llvm.org/viewvc/llvm-project?rev=369761&view=rev
Log:
[llvm-objcopy] Strip debug sections when running with --strip-unneeded.

Summary:
GNU --strip-unneeded strips debugging sections as well. Do that for llvm-objcopy as well.

Additionally, add a test that verifies we keep the .gnu_debuglink section. This apparently was not always the case, and I'm not sure which commit fixed it, but there doesn't appear to be any test coverage to make sure we continue to do so.

This fixes PR41043.

Reviewers: jhenderson, jakehehrlich, espindola, alexshap

Subscribers: emaste, arichardson, MaskRay, abrachet, seiya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66623

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

Added: llvm/trunk/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test?rev=369761&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test (added)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test Fri Aug 23 07:28:58 2019
@@ -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

Modified: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp?rev=369761&r1=369760&r2=369761&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp Fri Aug 23 07:28:58 2019
@@ -480,7 +480,7 @@ static Error replaceAndRemoveSections(co
     };
   }
 
-  if (Config.StripDebug) {
+  if (Config.StripDebug || Config.StripUnneeded) {
     RemovePred = [RemovePred](const SectionBase &Sec) {
       return RemovePred(Sec) || isDebugSection(Sec);
     };




More information about the llvm-commits mailing list