Skip to content

Commit 87d33d9

Browse files
author
Georgii Rymar
committed
[yaml2obj] - Change how p_offset is calculated when creating segments. NFCI.
This depends on D78361 and simplifies the computation of the `p_offset`. Differential revision: https://reviews.llvm.org/D78363
1 parent 317c491 commit 87d33d9

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

llvm/lib/ObjectYAML/ELFEmitter.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -759,18 +759,12 @@ void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
759759
reportError("sections in the program header with index " +
760760
Twine(PhdrIdx) + " are not sorted by their file offset");
761761

762-
if (YamlPhdr.Offset) {
762+
if (YamlPhdr.Offset)
763763
PHeader.p_offset = *YamlPhdr.Offset;
764-
} else {
765-
if (YamlPhdr.Sections.size())
766-
PHeader.p_offset = UINT32_MAX;
767-
else
768-
PHeader.p_offset = 0;
769-
770-
// Find the minimum offset for the program header.
771-
for (const Fragment &F : Fragments)
772-
PHeader.p_offset = std::min((uint64_t)PHeader.p_offset, F.Offset);
773-
}
764+
else if (!Fragments.empty())
765+
PHeader.p_offset = Fragments.front().Offset;
766+
else
767+
PHeader.p_offset = 0;
774768

775769
// Find the maximum offset of the end of a section in order to set p_filesz
776770
// and p_memsz. When setting p_filesz, trailing SHT_NOBITS sections are not

0 commit comments

Comments
 (0)