From 6c1aca3e2d408ef4874bd882a7f0e2cd944bbf09 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 1 Apr 2015 19:19:27 +1030 Subject: Start of relro segment adjustment Adjusting the start of the relro segment in order to make it end exactly on a page boundary runs into difficulties when sections in the relro segment are aligned; Adjusting the start by (next_page - end) sometimes results in more than that adjustment occurring at the end, overrunning the page boundary. So when that occurs we try a new lower start position by masking the adjusted start with the maximum section alignment. However, we didn't consider that this masked start address may in fact be before the initial relro base, which is silly since that can only increase padding at the relro end. I've also moved some calculations closer to where they are used, and comments closer to the relevant statements. * ldlang.c (lang_size_sections): When alignment of sections results in relro base adjustment being too large, don't go lower than the initial value. * ldexp.c (fold_binary ): Comment. * scripttempl/elf.sc (DATA_SEGMENT_ALIGN): Omit SEGMENT_SIZE alignment when SEGMENT_SIZE is the same as MAXPAGESIZE. --- ld/scripttempl/elf.sc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ld/scripttempl') diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index c9c80b0..b4f52eb 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -128,7 +128,11 @@ DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))" DATA_SEGMENT_RELRO_END="" DATA_SEGMENT_END="" if test -n "${COMMONPAGESIZE}"; then - DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})" + if test "${SEGMENT_SIZE}" != "${MAXPAGESIZE}"; then + DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})" + else + DATA_SEGMENT_ALIGN="DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})" + fi DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);" DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);" fi -- cgit v1.1