Skip to content

Commit

Permalink
[obj2yaml] - Zero initialize program headers. NFCI.
Browse files Browse the repository at this point in the history
It allows to simplify the current code and also
might help for the code around.

It is also consistent with what we do for another headers,
e.g. section headers, elf file header etc.

Differential revision: https://reviews.llvm.org/D78627
  • Loading branch information
Georgii Rymar committed Apr 23, 2020
1 parent 9488f0d commit 34b3d5b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions llvm/lib/ObjectYAML/ELFEmitter.cpp
Expand Up @@ -318,6 +318,7 @@ template <class ELFT>
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;
Expand Down Expand Up @@ -759,16 +760,16 @@ void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
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
Expand Down

0 comments on commit 34b3d5b

Please sign in to comment.