[PATCH] D41141: [llvm-objcopy] Add -S option to llvm-objcopy and llvm-strip

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 12 16:24:45 PST 2017


jakehehrlich created this revision.
jakehehrlich added reviewers: phosek, jhenderson.

-S means something different in GNU strip and GNU objcopy. We'd like to have the respective llvm versions maintain command line compatibility. In strip it means --strip-debug and in objcopy it means --strip-all. This change adds support for -S to both.


Repository:
  rL LLVM

https://reviews.llvm.org/D41141

Files:
  test/tools/llvm-objcopy/big-S.test
  tools/llvm-objcopy/llvm-objcopy.cpp


Index: tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- tools/llvm-objcopy/llvm-objcopy.cpp
+++ tools/llvm-objcopy/llvm-objcopy.cpp
@@ -290,6 +290,7 @@
     "strip-all",
     cl::desc(
         "Removes non-allocated sections other than .gnu.warning* sections"));
+static cl::opt<bool> BigS("S", cl::Hidden);
 static cl::opt<bool>
     StripAllGNU("strip-all-gnu",
                 cl::desc("Removes symbol, relocation, and debug information"));
@@ -348,17 +349,18 @@
 void Strip(const ELFObjectFile<ELFT>& ObjFile) {
   CopyConfig<ELFT> Config(ObjFile);
   CommonConfig(Config);
+  Config.StripDebug = Config.StripDebug || BigS;
   Config.StripAll = StripAll ||
-                    !(StripAllGNU || StripDebug || StripDWO || StripNonAlloc ||
+                    !(StripAllGNU || Config.StripDebug || StripDWO || StripNonAlloc ||
                       StripSections);
   Config.copyBinary();
 }
 
 template <class ELFT>
 void Objcopy(const ELFObjectFile<ELFT>& ObjFile) {
   CopyConfig<ELFT> Config(ObjFile);
   CommonConfig(Config);
-  Config.StripAll = StripAll;
+  Config.StripAll = StripAll || BigS;
   Config.copyBinary();
 }
 
Index: test/tools/llvm-objcopy/big-S.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objcopy/big-S.test
@@ -0,0 +1,46 @@
+UN: yaml2obj %s > %t
+# RUN: llvm-strip -S %t -o %t2
+# RUN: llvm-readobj -file-headers -sections -symbols %t2 | FileCheck --check-prefix=STRIP %s
+# RUN: llvm-objcopy -S %t %t2
+# RUN: llvm-readobj -file-headers -sections -symbols %t2 | FileCheck --check-prefix=OBJCOPY %s
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .bss
+    Type:            SHT_NOBITS
+    Flags:           [ SHF_ALLOC ]
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    Content:         "c3c3c3c3"
+  - Name:            .blarg
+    Type:            SHT_PROGBITS
+    Flags:           [ ]
+    Content:         "00000000"
+  - Name:            .debugfoo
+    Type:            SHT_PROGBITS
+    Content:         "00000000"
+  - Name:            .gnu.warning.foo
+    Type:            SHT_PROGBITS
+
+# STRIP: SectionHeaderCount: 8
+
+# STRIP: Name: .bss
+# STRIP: Name: .text
+# STRIP: Name: .blarg
+# STRIP: Name: .gnu.warning.foo
+# STRIP: Name: .symtab
+# STRIP: Name: .strtab
+# STRIP: Name: .shstrtab
+
+# OBJCOPY: SectionHeaderCount: 5
+
+# OBJCOPY: Name: .bss
+# OBJCOPY: Name: .text
+# OBJCOPY: Name: .gnu.warning.foo
+# OBJCOPY: Name: .shstrtab


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41141.126646.patch
Type: text/x-patch
Size: 2699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171213/50d1816b/attachment-0001.bin>


More information about the llvm-commits mailing list