[PATCH] D144009: [obj2yaml] Save offset for segments and size for PHDR

Denis Revunov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 06:33:44 PST 2023


treapster created this revision.
Herald added a project: All.
treapster requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

With current implementation obj2yaml produces files which on conversion back to obj have invalid address-offset value and have half the sections not belonging to any segment(especially after some sections are stripped from YAML). This quick fix improves situation a lot.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144009

Files:
  llvm/tools/obj2yaml/elf2yaml.cpp


Index: llvm/tools/obj2yaml/elf2yaml.cpp
===================================================================
--- llvm/tools/obj2yaml/elf2yaml.cpp
+++ llvm/tools/obj2yaml/elf2yaml.cpp
@@ -10,6 +10,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/Object/ELFObjectFile.h"
 #include "llvm/ObjectYAML/DWARFYAML.h"
@@ -484,6 +485,12 @@
     PH.Flags = Phdr.p_flags;
     PH.VAddr = Phdr.p_vaddr;
     PH.PAddr = Phdr.p_paddr;
+    PH.Offset = Phdr.p_offset;
+
+    if (Phdr.p_type == ELF::PT_PHDR) {
+      PH.MemSize = Phdr.p_memsz;
+      PH.FileSize = Phdr.p_filesz;
+    }
 
     // yaml2obj sets the alignment of a segment to 1 by default.
     // We do not print the default alignment to reduce noise in the output.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144009.497303.patch
Type: text/x-patch
Size: 865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230214/2217c34e/attachment.bin>


More information about the llvm-commits mailing list