diff options
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r-- | llvm/tools/llvm-objcopy/llvm-objcopy.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
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)) |