Index: llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-keep.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-keep.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-keep.test @@ -1,23 +0,0 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy -only-keep=.test %t %t2 -# RUN: llvm-objcopy -j .test %t %t3 -# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s -# RUN: diff %t2 %t3 - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .test - Type: SHT_PROGBITS - Flags: [ ] - -# CHECK: SectionHeaderCount: 5 - -# CHECK: Name: .test -# CHECK: Name: .symtab -# CHECK: Name: .strtab -# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-section.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-section.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-section.test @@ -0,0 +1,23 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy -only-section=.test %t %t2 +# RUN: llvm-objcopy -j .test %t %t3 +# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s +# RUN: diff %t2 %t3 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .test + Type: SHT_PROGBITS + Flags: [ ] + +# CHECK: SectionHeaderCount: 5 + +# CHECK: Name: .test +# CHECK: Name: .symtab +# CHECK: Name: .strtab +# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/dump-section.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/dump-section.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/dump-section.test @@ -1,6 +1,6 @@ # RUN: yaml2obj %s > %t # RUN: llvm-objcopy -O binary -j .text %t %t2 -# RUN: llvm-objcopy -O binary -only-keep .text %t %t3 +# RUN: llvm-objcopy -O binary -only-section .text %t %t3 # RUN: llvm-objcopy --dump-section .text=%t4 %t %t5 # RUN: llvm-objcopy --dump-section .foo=%t6 %t %t7 # RUN: not llvm-objcopy --dump-section .bar=%t8 %t %t9 2>&1 | FileCheck %s --check-prefix=NOBITS Index: llvm/trunk/test/tools/llvm-objcopy/ELF/explicit-only-keep-remove.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/explicit-only-keep-remove.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/explicit-only-keep-remove.test @@ -1,21 +0,0 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy -R=.test -only-keep=.test %t %t2 -# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .test - Type: SHT_PROGBITS - Flags: [ ] - -# CHECK: SectionHeaderCount: 5 - -# CHECK: Name: .test -# CHECK: Name: .symtab -# CHECK: Name: .strtab -# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/explicit-only-section-remove.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/explicit-only-section-remove.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/explicit-only-section-remove.test @@ -0,0 +1,21 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy -R=.test -only-section=.test %t %t2 +# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .test + Type: SHT_PROGBITS + Flags: [ ] + +# CHECK: SectionHeaderCount: 5 + +# CHECK: Name: .test +# CHECK: Name: .symtab +# CHECK: Name: .strtab +# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/keep-only-keep.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/keep-only-keep.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/keep-only-keep.test @@ -1,27 +0,0 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy -keep-section=.test2 -only-keep=.test %t %t2 -# RUN: llvm-objcopy -j .test -keep-section=.test2 %t %t3 -# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s -# RUN: diff %t2 %t3 - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .test - Type: SHT_PROGBITS - - Name: .test2 - Type: SHT_PROGBITS - - Name: .test3 - Type: SHT_PROGBITS - -# CHECK: SectionHeaderCount: 6 - -# CHECK: Name: .test -# CHECK: Name: .test2 -# CHECK: Name: .symtab -# CHECK: Name: .strtab -# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/keep-only-section.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/keep-only-section.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/keep-only-section.test @@ -0,0 +1,27 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy -keep-section=.test2 -only-section=.test %t %t2 +# RUN: llvm-objcopy -j .test -keep-section=.test2 %t %t3 +# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s +# RUN: diff %t2 %t3 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .test + Type: SHT_PROGBITS + - Name: .test2 + Type: SHT_PROGBITS + - Name: .test3 + Type: SHT_PROGBITS + +# CHECK: SectionHeaderCount: 6 + +# CHECK: Name: .test +# CHECK: Name: .test2 +# CHECK: Name: .symtab +# CHECK: Name: .strtab +# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-many.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-many.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-many.test @@ -1,28 +0,0 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy -j .test1 -j .test2 %t %t2 -# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .test1 - Type: SHT_PROGBITS - Flags: [ ] - - Name: .test2 - Type: SHT_PROGBITS - Flags: [ ] - - Name: .test3 - Type: SHT_PROGBITS - Flags: [ ] - -# CHECK: SectionHeaderCount: 6 - -# CHECK: Name: .test1 -# CHECK: Name: .test2 -# CHECK: Name: .symtab -# CHECK: Name: .strtab -# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-remove-strtab.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-remove-strtab.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-remove-strtab.test @@ -1,21 +0,0 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy -R .symtab -R .strtab -only-keep=.test %t %t2 -# RUN: llvm-objcopy -j .test -R .strtab -R .symtab %t %t3 -# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s -# RUN: diff %t2 %t3 - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .test - Type: SHT_PROGBITS - Flags: [ ] - -# CHECK: SectionHeaderCount: 3 - -# CHECK: Name: .test -# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-strip-non-alloc.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-strip-non-alloc.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/only-keep-strip-non-alloc.test @@ -1,19 +0,0 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy -strip-non-alloc -only-keep=.test %t %t2 -# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .test - Type: SHT_PROGBITS - Flags: [ ] - -# CHECK: SectionHeaderCount: 3 - -# CHECK: Name: .test -# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-many.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-many.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-many.test @@ -0,0 +1,28 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy -j .test1 -j .test2 %t %t2 +# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .test1 + Type: SHT_PROGBITS + Flags: [ ] + - Name: .test2 + Type: SHT_PROGBITS + Flags: [ ] + - Name: .test3 + Type: SHT_PROGBITS + Flags: [ ] + +# CHECK: SectionHeaderCount: 6 + +# CHECK: Name: .test1 +# CHECK: Name: .test2 +# CHECK: Name: .symtab +# CHECK: Name: .strtab +# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-remove-strtab.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-remove-strtab.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-remove-strtab.test @@ -0,0 +1,21 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy -R .symtab -R .strtab -only-section=.test %t %t2 +# RUN: llvm-objcopy -j .test -R .strtab -R .symtab %t %t3 +# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s +# RUN: diff %t2 %t3 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .test + Type: SHT_PROGBITS + Flags: [ ] + +# CHECK: SectionHeaderCount: 3 + +# CHECK: Name: .test +# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-strip-non-alloc.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-strip-non-alloc.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/only-section-strip-non-alloc.test @@ -0,0 +1,19 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy -strip-non-alloc -only-section=.test %t %t2 +# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .test + Type: SHT_PROGBITS + Flags: [ ] + +# CHECK: SectionHeaderCount: 3 + +# CHECK: Name: .test +# CHECK: Name: .shstrtab Index: llvm/trunk/test/tools/llvm-objcopy/ELF/strip-sections-only-keep.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/strip-sections-only-keep.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/strip-sections-only-keep.test @@ -1,20 +0,0 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy -strip-sections -only-keep=.test %t %t2 -# RUN: od -Ax -t x1 %t2 | FileCheck %s -# RUN: od -Ax -t c %t2 | FileCheck %s -check-prefix=TEXT - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .test - Type: SHT_PROGBITS - Flags: [ ] - Content: "DEADBEEF" - -# CHECK: de ad be ef - -# TEXT-NOT: t e s t Index: llvm/trunk/test/tools/llvm-objcopy/ELF/strip-sections-only-section.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/strip-sections-only-section.test +++ llvm/trunk/test/tools/llvm-objcopy/ELF/strip-sections-only-section.test @@ -0,0 +1,20 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy -strip-sections -only-section=.test %t %t2 +# RUN: od -Ax -t x1 %t2 | FileCheck %s +# RUN: od -Ax -t c %t2 | FileCheck %s -check-prefix=TEXT + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .test + Type: SHT_PROGBITS + Flags: [ ] + Content: "DEADBEEF" + +# CHECK: de ad be ef + +# TEXT-NOT: t e s t Index: llvm/trunk/tools/llvm-objcopy/CopyConfig.h =================================================================== --- llvm/trunk/tools/llvm-objcopy/CopyConfig.h +++ llvm/trunk/tools/llvm-objcopy/CopyConfig.h @@ -61,7 +61,7 @@ std::vector AddSection; std::vector DumpSection; std::vector KeepSection; - std::vector OnlyKeep; + std::vector OnlySection; std::vector SymbolsToGlobalize; std::vector SymbolsToKeep; std::vector SymbolsToLocalize; Index: llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp =================================================================== --- llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp +++ llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp @@ -315,8 +315,8 @@ Config.ToRemove.push_back(Arg->getValue()); for (auto Arg : InputArgs.filtered(OBJCOPY_keep_section)) Config.KeepSection.push_back(Arg->getValue()); - for (auto Arg : InputArgs.filtered(OBJCOPY_only_keep)) - Config.OnlyKeep.push_back(Arg->getValue()); + for (auto Arg : InputArgs.filtered(OBJCOPY_only_section)) + Config.OnlySection.push_back(Arg->getValue()); for (auto Arg : InputArgs.filtered(OBJCOPY_add_section)) Config.AddSection.push_back(Arg->getValue()); for (auto Arg : InputArgs.filtered(OBJCOPY_dump_section)) Index: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp =================================================================== --- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -415,10 +415,10 @@ }; // Explicit copies: - if (!Config.OnlyKeep.empty()) { + if (!Config.OnlySection.empty()) { RemovePred = [&Config, RemovePred, &Obj](const SectionBase &Sec) { // Explicitly keep these sections regardless of previous removes. - if (is_contained(Config.OnlyKeep, Sec.Name)) + if (is_contained(Config.OnlySection, Sec.Name)) return false; // Allow all implicit removes. Index: llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td =================================================================== --- llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td +++ llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td @@ -78,9 +78,9 @@ MetaVarName<"old=new">; defm keep_section : Eq<"keep-section", "Keep
">, MetaVarName<"section">; -defm only_keep : Eq<"only-keep", "Remove all but
">, - MetaVarName<"section">; -def j : JoinedOrSeparate<["-"], "j">, Alias; +defm only_section : Eq<"only-section", "Remove all but
">, + MetaVarName<"section">; +def j : JoinedOrSeparate<["-"], "j">, Alias; defm add_section : Eq<"add-section", "Make a section named
with the contents of .">,