summaryrefslogtreecommitdiffstats
path: root/llvm/tools/yaml2obj/yaml2elf.cpp
diff options
context:
space:
mode:
authorJake Ehrlich <jakehehrlich@google.com>2017-11-01 23:14:48 +0000
committerJake Ehrlich <jakehehrlich@google.com>2017-11-01 23:14:48 +0000
commit03aeeb09c53923072d561d004b6f682664a2eb8c (patch)
treeb6efdbb165c16a2fe809b522652d598707626e4c /llvm/tools/yaml2obj/yaml2elf.cpp
parentbfa77c4c85dbe28c8b651b6e692b7673c8cfb349 (diff)
downloadbcm5719-llvm-03aeeb09c53923072d561d004b6f682664a2eb8c.tar.gz
bcm5719-llvm-03aeeb09c53923072d561d004b6f682664a2eb8c.zip
[yaml2obj][ELF] Add support for setting alignment in program headers
Sometimes program headers have larger alignments than any of the sections they contain. Currently yaml2obj can't produce such files. A bug recently appeared in llvm-objcopy that failed in such a case. I'd like to be able to add tests to llvm-objcopy for such cases. This change adds an optional alignment parameter to program headers that will be used instead of calculating the alignment. Differential Revision: https://reviews.llvm.org/D39130 llvm-svn: 317139
Diffstat (limited to 'llvm/tools/yaml2obj/yaml2elf.cpp')
-rw-r--r--llvm/tools/yaml2obj/yaml2elf.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index 9328048c425..913f19050dc 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -378,15 +378,19 @@ void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
}
// Set the alignment of the segment to be the same as the maximum alignment
- // of the the sections with the same offset so that by default the segment
+ // of the sections with the same offset so that by default the segment
// has a valid and sensible alignment.
- PHeader.p_align = 1;
- for (auto SecName : YamlPhdr.Sections) {
- uint32_t Index = 0;
- SN2I.lookup(SecName.Section, Index);
- const auto &SHeader = SHeaders[Index];
- if (SHeader.sh_offset == PHeader.p_offset)
- PHeader.p_align = std::max(PHeader.p_align, SHeader.sh_addralign);
+ if (YamlPhdr.Align) {
+ PHeader.p_align = *YamlPhdr.Align;
+ } else {
+ PHeader.p_align = 1;
+ for (auto SecName : YamlPhdr.Sections) {
+ uint32_t Index = 0;
+ SN2I.lookup(SecName.Section, Index);
+ const auto &SHeader = SHeaders[Index];
+ if (SHeader.sh_offset == PHeader.p_offset)
+ PHeader.p_align = std::max(PHeader.p_align, SHeader.sh_addralign);
+ }
}
}
}
OpenPOWER on IntegriCloud