[PATCH] D49979: [llvm-objcopy] Add --dump-section

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 30 11:36:59 PDT 2018


jakehehrlich added a comment.

Thanks! I've been meaning to implement this forever. For instance this is the only way to dump non-allocated sections. I've run into cases debugging things where that was useful and had to use objcopy.



================
Comment at: tools/llvm-objcopy/Object.h:622
+  explicit Reader(Binary *B) : Bin(B){};
+  Binary *Bin;
 };
----------------
If you use ELFSectionWriter you don't need to keep track of this information.


================
Comment at: tools/llvm-objcopy/llvm-objcopy.cpp:241
 
+static Expected<SectionRef> getSectionByName(ObjectFile *Obj,
+                                             StringRef SecName) {
----------------
It probably makes more sense to use llvm::objcopy::Object and to use an ELFSectionWriter to dump the contents.


================
Comment at: tools/llvm-objcopy/llvm-objcopy.cpp:475
+  if (!Config.DumpSection.empty()) {
+    for (const auto &Flag : Config.DumpSection) {
+      auto SecPair = Flag.split("=");
----------------
You can just iterate over these instead of checking.


================
Comment at: tools/llvm-objcopy/llvm-objcopy.cpp:476-494
+      auto SecPair = Flag.split("=");
+      auto SecName = SecPair.first;
+      auto File = SecPair.second;
+      if (ObjectFile *O = dyn_cast<ObjectFile>(Reader.Bin)) {
+        Expected<SectionRef> SecRefOrError = getSectionByName(O, SecName);
+        if (!SecRefOrError)
+          reportError(Config.InputFilename, SecRefOrError.takeError());
----------------
Could you wrap this in a function somehow?


Repository:
  rL LLVM

https://reviews.llvm.org/D49979





More information about the llvm-commits mailing list