diff options
Diffstat (limited to 'llvm/tools/llvm-objcopy')
-rw-r--r-- | llvm/tools/llvm-objcopy/ObjcopyOpts.td | 3 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/llvm-objcopy.cpp | 17 |
2 files changed, 20 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td index 4e337e6db9e..2af2108d98d 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -27,6 +27,9 @@ defm add_gnu_debuglink : Eq<"add-gnu-debuglink">, defm remove_section : Eq<"remove-section">, MetaVarName<"section">, HelpText<"Remove <section>">; +defm rename_section : Eq<"rename-section">, + MetaVarName<"old=new">, + HelpText<"Renames a section from old to new">; defm redefine_symbol : Eq<"redefine-sym">, MetaVarName<"old=new">, HelpText<"Change the name of a symbol old to new">; diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp index 12e9ca17e19..3a25e3f690b 100644 --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp @@ -133,6 +133,7 @@ struct CopyConfig { std::vector<StringRef> SymbolsToWeaken; std::vector<StringRef> SymbolsToRemove; std::vector<StringRef> SymbolsToKeep; + StringMap<StringRef> SectionsToRename; StringMap<StringRef> SymbolsToRename; bool StripAll = false; bool StripAllGNU = false; @@ -430,6 +431,14 @@ static void HandleArgs(const CopyConfig &Config, Object &Obj, Obj.removeSections(RemovePred); + if (!Config.SectionsToRename.empty()) { + for (auto &Sec : Obj.sections()) { + const auto Iter = Config.SectionsToRename.find(Sec.Name); + if (Iter != Config.SectionsToRename.end()) + Sec.Name = Iter->second; + } + } + if (!Config.AddSection.empty()) { for (const auto &Flag : Config.AddSection) { auto SecPair = Flag.split("="); @@ -587,6 +596,14 @@ static CopyConfig ParseObjcopyOptions(ArrayRef<const char *> ArgsArr) { error("Multiple redefinition of symbol " + Old2New.first); } + for (auto Arg : InputArgs.filtered(OBJCOPY_rename_section)) { + if (!StringRef(Arg->getValue()).contains('=')) + error("Bad format for --rename-section"); + auto Old2New = StringRef(Arg->getValue()).split('='); + if (!Config.SectionsToRename.insert(Old2New).second) + error("Already have a section rename for " + Old2New.first); + } + for (auto Arg : InputArgs.filtered(OBJCOPY_remove_section)) Config.ToRemove.push_back(Arg->getValue()); for (auto Arg : InputArgs.filtered(OBJCOPY_keep)) |