Skip to content

Commit

Permalink
[llvm-objcopy] Change --only-keep to --only-section
Browse files Browse the repository at this point in the history
I just hard core goofed when I wrote this and created a different name
for no good reason. I'm failry aware of most "fresh" users of llvm-objcopy
(that is, users which are not using it as a drop in replacement for GNU
objcopy) and can say that only "-j" is being used by such people so this
patch should strictly increase compatibility and not remove it.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348446 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
jakehehrlich committed Dec 6, 2018
1 parent 2941d47 commit beec7d4
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t
# RUN: llvm-objcopy -only-keep=.test %t %t2
# 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
Expand Down
2 changes: 1 addition & 1 deletion test/tools/llvm-objcopy/ELF/dump-section.test
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t
# RUN: llvm-objcopy -R=.test -only-keep=.test %t %t2
# RUN: llvm-objcopy -R=.test -only-section=.test %t %t2
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s

!ELF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t
# RUN: llvm-objcopy -keep-section=.test2 -only-keep=.test %t %t2
# 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t
# RUN: llvm-objcopy -R .symtab -R .strtab -only-keep=.test %t %t2
# 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t
# RUN: llvm-objcopy -strip-non-alloc -only-keep=.test %t %t2
# RUN: llvm-objcopy -strip-non-alloc -only-section=.test %t %t2
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s

!ELF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t
# RUN: llvm-objcopy -strip-sections -only-keep=.test %t %t2
# 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

Expand Down
4 changes: 2 additions & 2 deletions tools/llvm-objcopy/CopyConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
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))
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm-objcopy/CopyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct CopyConfig {
std::vector<StringRef> AddSection;
std::vector<StringRef> DumpSection;
std::vector<StringRef> KeepSection;
std::vector<StringRef> OnlyKeep;
std::vector<StringRef> OnlySection;
std::vector<StringRef> SymbolsToGlobalize;
std::vector<StringRef> SymbolsToKeep;
std::vector<StringRef> SymbolsToLocalize;
Expand Down
4 changes: 2 additions & 2 deletions tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ static void handleArgs(const CopyConfig &Config, Object &Obj,
};

// 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.
Expand Down
6 changes: 3 additions & 3 deletions tools/llvm-objcopy/ObjcopyOpts.td
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ defm redefine_symbol
MetaVarName<"old=new">;
defm keep_section : Eq<"keep-section", "Keep <section>">,
MetaVarName<"section">;
defm only_keep : Eq<"only-keep", "Remove all but <section>">,
MetaVarName<"section">;
def j : JoinedOrSeparate<["-"], "j">, Alias<only_keep>;
defm only_section : Eq<"only-section", "Remove all but <section>">,
MetaVarName<"section">;
def j : JoinedOrSeparate<["-"], "j">, Alias<only_section>;
defm add_section
: Eq<"add-section",
"Make a section named <section> with the contents of <file>.">,
Expand Down

0 comments on commit beec7d4

Please sign in to comment.