diff options
author | Fangrui Song <maskray@google.com> | 2019-09-10 09:16:34 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-09-10 09:16:34 +0000 |
commit | 1da4f47195c2e5e4faaaca265ae2f9d9149b85df (patch) | |
tree | cef5384c45484dda05acf3b8469f653287c218df /llvm/lib | |
parent | 3565c6b15c5466d6945fe82eae3e2d8df29d6622 (diff) | |
download | bcm5719-llvm-1da4f47195c2e5e4faaaca265ae2f9d9149b85df.tar.gz bcm5719-llvm-1da4f47195c2e5e4faaaca265ae2f9d9149b85df.zip |
[yaml2obj] Set p_align to the maximum sh_addralign of contained sections
The address difference between two sections in a PT_LOAD is a constant.
Consider a hypothetical case (pagesize can be very small, say, 4).
```
.text sh_addralign=4
.text.hot sh_addralign=16
```
If we set p_align to 4, the PT_LOAD will be loaded at an address which
is a multiple of 4. The address of .text.hot is guaranteed to be a
multiple of 4, but not necessarily a multiple of 16.
This patch deletes the constraint
if (SHeader->sh_offset == PHeader.p_offset)
Reviewed By: grimar, jhenderson
Differential Revision: https://reviews.llvm.org/D67260
llvm-svn: 371501
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/ObjectYAML/ELFEmitter.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index 531f0d4f1d8..72063a5dafd 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -645,16 +645,15 @@ void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders, PHeader.p_memsz = YamlPhdr.MemSize ? uint64_t(*YamlPhdr.MemSize) : MemOffset - PHeader.p_offset; - // Set the alignment of the segment to be the same as the maximum alignment - // of the sections with the same offset so that by default the segment - // has a valid and sensible alignment. if (YamlPhdr.Align) { PHeader.p_align = *YamlPhdr.Align; } else { + // Set the alignment of the segment to be the maximum alignment of the + // sections so that by default the segment has a valid and sensible + // alignment. PHeader.p_align = 1; for (Elf_Shdr *SHeader : Sections) - if (SHeader->sh_offset == PHeader.p_offset) - PHeader.p_align = std::max(PHeader.p_align, SHeader->sh_addralign); + PHeader.p_align = std::max(PHeader.p_align, SHeader->sh_addralign); } } } |