diff options
author | Dmitriy Ivanov <dimitry@google.com> | 2015-04-27 18:53:27 -0700 |
---|---|---|
committer | Dmitriy Ivanov <dimitry@google.com> | 2015-04-27 20:45:04 -0700 |
commit | 7936fa6536934b67b5f9bd836c205f962bd0cea3 (patch) | |
tree | 7e51449f51714987afaff01ea5effc6dbe3b0d16 /tools/relocation_packer | |
parent | 9e22d0ff3c12e51c20a72e148112bcbb207f816f (diff) | |
download | bionic-7936fa6536934b67b5f9bd836c205f962bd0cea3.zip bionic-7936fa6536934b67b5f9bd836c205f962bd0cea3.tar.gz bionic-7936fa6536934b67b5f9bd836c205f962bd0cea3.tar.bz2 |
Reduce p_align for program header to page size.
Having p_align > page_size leads to the situation when striping
packed executables results in unnecessary p_vaddr adjustments.
And it also may result (with probability 1 - 1/sizeof(uintptr_t)) in
misaligned segments following .dynstr
Bug: http://b/20629834
Bug: http://b/18051137
(cherry picked from commit b293969c6d4acede62ac7b035dcb598e63574ca0)
Change-Id: I2fb15cf5cb52fada6511d5af93df099fc2cbf7ba
Diffstat (limited to 'tools/relocation_packer')
-rw-r--r-- | tools/relocation_packer/src/elf_file.cc | 10 | ||||
-rwxr-xr-x | tools/relocation_packer/test_data/elf_file_unittest_relocs_arm64_packed.so | bin | 113651 -> 113651 bytes |
2 files changed, 8 insertions, 2 deletions
diff --git a/tools/relocation_packer/src/elf_file.cc b/tools/relocation_packer/src/elf_file.cc index c8ddde6..6ac9deb 100644 --- a/tools/relocation_packer/src/elf_file.cc +++ b/tools/relocation_packer/src/elf_file.cc @@ -37,11 +37,13 @@ static constexpr int32_t DT_ANDROID_RELASZ = DT_LOOS + 5; static constexpr uint32_t SHT_ANDROID_REL = SHT_LOOS + 1; static constexpr uint32_t SHT_ANDROID_RELA = SHT_LOOS + 2; +static const size_t kPageSize = 4096; + // Alignment to preserve, in bytes. This must be at least as large as the // largest d_align and sh_addralign values found in the loaded file. // Out of caution for RELRO page alignment, we preserve to a complete target // page. See http://www.airs.com/blog/archives/189. -static constexpr size_t kPreserveAlignment = 4096; +static const size_t kPreserveAlignment = kPageSize; // Get section data. Checks that the section has exactly one data entry, // so that the section size and the data size are the same. True in @@ -318,9 +320,13 @@ static void AdjustProgramHeaderOffsets(typename ELF::Phdr* program_headers, } else { program_header->p_vaddr -= hole_size; program_header->p_paddr -= hole_size; + if (program_header->p_align > kPageSize) { + program_header->p_align = kPageSize; + } VLOG(1) << "phdr[" << i << "] p_vaddr adjusted to "<< program_header->p_vaddr - << "; p_paddr adjusted to "<< program_header->p_paddr; + << "; p_paddr adjusted to "<< program_header->p_paddr + << "; p_align adjusted to "<< program_header->p_align; } } } diff --git a/tools/relocation_packer/test_data/elf_file_unittest_relocs_arm64_packed.so b/tools/relocation_packer/test_data/elf_file_unittest_relocs_arm64_packed.so Binary files differindex a2b0039..ed85ce1 100755 --- a/tools/relocation_packer/test_data/elf_file_unittest_relocs_arm64_packed.so +++ b/tools/relocation_packer/test_data/elf_file_unittest_relocs_arm64_packed.so |