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 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 BigS("S", cl::Hidden); static cl::opt StripAllGNU("strip-all-gnu", cl::desc("Removes symbol, relocation, and debug information")); @@ -348,8 +349,9 @@ void Strip(const ELFObjectFile& ObjFile) { CopyConfig Config(ObjFile); CommonConfig(Config); + Config.StripDebug = Config.StripDebug || BigS; Config.StripAll = StripAll || - !(StripAllGNU || StripDebug || StripDWO || StripNonAlloc || + !(StripAllGNU || Config.StripDebug || StripDWO || StripNonAlloc || StripSections); Config.copyBinary(); } @@ -358,7 +360,7 @@ void Objcopy(const ELFObjectFile& ObjFile) { CopyConfig Config(ObjFile); CommonConfig(Config); - Config.StripAll = StripAll; + Config.StripAll = StripAll || BigS; Config.copyBinary(); }