1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-22 11:17:19 +00:00

lld: do not round up PT_GNU_RELRO p_memsz

The change was made to support glibc and believed to be a no-op on
FreeBSD, but that is not the case for architectures with multiple page
sizes, such as arm64. The relro p_memsz header was rounded up to the
default maximum page size (64K). When 4K pages are in use, multiple
pages beyond the final PT_LOAD segment had their permissions changed to
read-only after application of relocations and copy relocations, which
led to a segfault in certain cases.

This reverts upstream r290986. I have started a discussion about the
upstream fix on the LLVM mailing list.

Reported by:	andrew
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Ed Maste 2017-01-27 16:53:53 +00:00
parent dfccd92cd2
commit 3dd7b92917
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/clang400-import/; revision=312891

View File

@ -1461,13 +1461,8 @@ template <class ELFT> void Writer<ELFT>::setPhdrs() {
}
if (P.p_type == PT_LOAD)
P.p_align = Config->MaxPageSize;
else if (P.p_type == PT_GNU_RELRO) {
else if (P.p_type == PT_GNU_RELRO)
P.p_align = 1;
// The glibc dynamic loader rounds the size down, so we need to round up
// to protect the last page. This is a no-op on FreeBSD which always
// rounds up.
P.p_memsz = alignTo(P.p_memsz, Config->MaxPageSize);
}
// The TLS pointer goes after PT_TLS. At least glibc will align it,
// so round up the size to make sure the offsets are correct.