[PATCH] D78627: [obj2yaml] - Zero initialize program headers. NFCI.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 02:41:19 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG34b3d5b66c40: [obj2yaml] - Zero initialize program headers. NFCI. (authored by grimar).
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78627/new/

https://reviews.llvm.org/D78627

Files:
  llvm/lib/ObjectYAML/ELFEmitter.cpp


Index: llvm/lib/ObjectYAML/ELFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -318,6 +318,7 @@
 void ELFState<ELFT>::initProgramHeaders(std::vector<Elf_Phdr> &PHeaders) {
   for (const auto &YamlPhdr : Doc.ProgramHeaders) {
     Elf_Phdr Phdr;
+    zero(Phdr);
     Phdr.p_type = YamlPhdr.Type;
     Phdr.p_flags = YamlPhdr.Flags;
     Phdr.p_vaddr = YamlPhdr.VAddr;
@@ -759,16 +760,16 @@
       reportError("sections in the program header with index " +
                   Twine(PhdrIdx) + " are not sorted by their file offset");
 
-    uint64_t PhdrFileOffset = Fragments.empty() ? 0 : Fragments.front().Offset;
     if (YamlPhdr.Offset) {
-      if (!Fragments.empty() && *YamlPhdr.Offset > PhdrFileOffset)
+      if (!Fragments.empty() && *YamlPhdr.Offset > Fragments.front().Offset)
         reportError("'Offset' for segment with index " + Twine(PhdrIdx) +
                     " must be less than or equal to the minimum file offset of "
                     "all included sections (0x" +
-                    Twine::utohexstr(PhdrFileOffset) + ")");
-      PhdrFileOffset = *YamlPhdr.Offset;
+                    Twine::utohexstr(Fragments.front().Offset) + ")");
+      PHeader.p_offset = *YamlPhdr.Offset;
+    } else if (!Fragments.empty()) {
+      PHeader.p_offset = Fragments.front().Offset;
     }
-    PHeader.p_offset = PhdrFileOffset;
 
     // Find the maximum offset of the end of a section in order to set p_filesz
     // and p_memsz. When setting p_filesz, trailing SHT_NOBITS sections are not


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78627.259501.patch
Type: text/x-patch
Size: 1631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200423/4c0db8ba/attachment.bin>


More information about the llvm-commits mailing list