From c652626a37614193b84f0dc0ea3d47af23be9893 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Fri, 20 Oct 2017 16:35:27 -0700 Subject: [PATCH] 32-bit shared libs reduce Phdr[1].p_align to 4096, like 64-bit. This saves space when PAGE_SIZE is larger than 4096: MIPS, etc. modified: p_lx_elf.cpp --- src/p_lx_elf.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 90d3556a..55b191a5 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -375,6 +375,7 @@ off_t PackLinuxElf32::pack3(OutputFile *fo, Filter &ft) for (int j = e_phnum; --j>=0; ++phdr) { unsigned const len = get_te32(&phdr->p_filesz); unsigned const ioff = get_te32(&phdr->p_offset); + unsigned align= get_te32(&phdr->p_align); unsigned const type = get_te32(&phdr->p_type); if (phdr->PT_INTERP==type) { // Rotate to highest position, so it can be lopped @@ -388,11 +389,13 @@ off_t PackLinuxElf32::pack3(OutputFile *fo, Filter &ft) } if (phdr->PT_LOAD32==type) { if (xct_off < ioff) { // Slide up non-first PT_LOAD. - fi->seek(ioff, SEEK_SET); - fi->readx(ibuf, len); - off += ~page_mask & (ioff - off); - fo->seek(off, SEEK_SET); - fo->write(ibuf, len); + if ((1u<<12) < align) { + align = 1u<<12; + set_te32(&phdr->p_align, align); + } + off += (align-1) & (ioff - off); + fi->seek(ioff, SEEK_SET); fi->readx(ibuf, len); + fo->seek( off, SEEK_SET); fo->write(ibuf, len); so_slide = off - ioff; set_te32(&phdr->p_offset, so_slide + ioff); }