summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2018-07-20 19:54:24 +0000
committerJordan Rupprecht <rupprecht@google.com>2018-07-20 19:54:24 +0000
commitdb2036e1f5b74876c5574ec526a44d042101fb3b (patch)
tree0a5687598d05942a3356eb60e65b29a36a7481bb /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parent0cb55919eca72a89d2fcb29dd958631ee07a32fb (diff)
downloadbcm5719-llvm-db2036e1f5b74876c5574ec526a44d042101fb3b.tar.gz
bcm5719-llvm-db2036e1f5b74876c5574ec526a44d042101fb3b.zip
[llvm-objcopy] Add basic support for --rename-section
Summary: Add basic support for --rename-section=old=new to llvm-objcopy. A full replacement for GNU objcopy requires also modifying flags (i.e. --rename-section=old=new,flag1,flag2); I'd like to keep that in a separate change to keep this simple. Reviewers: jakehehrlich, alexshap Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D49576 llvm-svn: 337604
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp17
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))
OpenPOWER on IntegriCloud