@@ -1101,6 +1101,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
size_t nloadcmds = 0;
bool has_holes = false;
bool empty_dynamic = false;
+ ElfW(Addr) p_align_max = 0;
/* The struct is initialized to zero so this is not necessary:
l->l_ld = 0;
@@ -1151,7 +1152,9 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
c->mapend = ALIGN_UP (ph->p_vaddr + ph->p_filesz, GLRO(dl_pagesize));
c->dataend = ph->p_vaddr + ph->p_filesz;
c->allocend = ph->p_vaddr + ph->p_memsz;
- c->mapalign = ph->p_align;
+ /* Remember the maximum p_align. */
+ if (ph->p_align > p_align_max)
+ p_align_max = ph->p_align;
c->mapoff = ALIGN_DOWN (ph->p_offset, GLRO(dl_pagesize));
/* Determine whether there is a gap between the last segment
@@ -1226,6 +1229,10 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
goto lose;
}
+ /* Align all PT_LOAD segments to the maximum p_align. */
+ for (size_t i = 0; i < nloadcmds; i++)
+ loadcmds[i].mapalign = p_align_max;
+
/* dlopen of an executable is not valid because it is not possible
to perform proper relocations, handle static TLS, or run the
ELF constructors. For PIE, the check needs the dynamic
new file mode 100644
@@ -0,0 +1,9 @@
+ifeq ($(subdir),elf)
+tests += tst-p_align1
+
+$(objpfx)tst-p_align1: $(objpfx)tst-p_alignmod1.so
+
+$(objpfx)tst-p_alignmod1.so: $(..)sysdeps/x86_64/64/tst-p_alignmod1.so.xz
+ cp -f $< $(objpfx)
+ unxz -f $(objpfx)tst-p_alignmod1.so.xz
+endif
new file mode 100644
@@ -0,0 +1,27 @@
+/* Check different alignments of PT_LOAD segments in a shared library.
+ Copyright (C) 2021 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+extern int do_load_test (void);
+
+static int
+do_test (void)
+{
+ return do_load_test ();
+}
+
+#include <support/test-driver.c>
new file mode 100755