From: "H.J. Lu" <hjl.tools@gmail.com>
To: Binutils <binutils@sourceware.org>
Subject: Re: Start of relro segment adjustment
Date: Wed, 01 Apr 2015 11:26:00 -0000 [thread overview]
Message-ID: <CAMe9rOrYd3_ne-Mp933kzU1njd7aj-6MAqzQmSCGcA5JSUo3kQ@mail.gmail.com> (raw)
In-Reply-To: <20150401091156.GT26234@bubble.grove.modra.org>
[-- Attachment #1: Type: text/plain, Size: 1246 bytes --]
On Wed, Apr 1, 2015 at 2:11 AM, Alan Modra <amodra@gmail.com> wrote:
> 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 <DATA_SEGMENT_RELRO_END>): Comment.
> * scripttempl/elf.sc (DATA_SEGMENT_ALIGN): Omit SEGMENT_SIZE
> alignment when SEGMENT_SIZE is the same as MAXPAGESIZE.
>
Thanks.
I checked in this testcase.
--
H.J.
[-- Attachment #2: 0001-Add-a-testcase-for-PR-ld-18176.patch --]
[-- Type: text/x-patch, Size: 5466 bytes --]
From 875b5b9d147d37c99a189aa95354f9bebdd64ef5 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 1 Apr 2015 04:24:05 -0700
Subject: [PATCH] Add a testcase for PR ld/18176
PR ld/18176
* ld-x86-64/pr18176.d: New file.
* ld-x86-64/pr18176.s: Likewise.
* ld-x86-64/pr18176.t: Likewise.
* ld-x86-64/x86-64.exp: Run pr18176.
---
ld/ChangeLog | 1 +
ld/testsuite/ChangeLog | 8 ++++++
ld/testsuite/ld-x86-64/pr18176.d | 9 +++++++
ld/testsuite/ld-x86-64/pr18176.s | 52 +++++++++++++++++++++++++++++++++++++++
ld/testsuite/ld-x86-64/pr18176.t | 39 +++++++++++++++++++++++++++++
ld/testsuite/ld-x86-64/x86-64.exp | 1 +
6 files changed, 110 insertions(+)
create mode 100644 ld/testsuite/ld-x86-64/pr18176.d
create mode 100644 ld/testsuite/ld-x86-64/pr18176.s
create mode 100644 ld/testsuite/ld-x86-64/pr18176.t
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 718cdb6..6082e28 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -5,6 +5,7 @@
2015-04-01 Alan Modra <amodra@gmail.com>
+ PR ld/18176
* 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.
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 47bb489..b35ab3f 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2015-04-01 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/18176
+ * ld-x86-64/pr18176.d: New file.
+ * ld-x86-64/pr18176.s: Likewise.
+ * ld-x86-64/pr18176.t: Likewise.
+ * ld-x86-64/x86-64.exp: Run pr18176.
+
2015-03-31 H.J. Lu <hongjiu.lu@intel.com>
* ld-bootstrap/bootstrap.exp (extralibs): Add -lz.
diff --git a/ld/testsuite/ld-x86-64/pr18176.d b/ld/testsuite/ld-x86-64/pr18176.d
new file mode 100644
index 0000000..3a08539
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr18176.d
@@ -0,0 +1,9 @@
+#name: PR ld/18176
+#as: --64
+#ld: -melf_x86_64 -shared -z relro -T pr18176.t -z max-page-size=0x200000 -z common-page-size=0x1000
+#readelf: -l --wide
+#target: x86_64-*-linux*
+
+#...
+ GNU_RELRO 0x04bd07 0x000000000024bd07 0x000000000024bd07 0x0022f9 0x0022f9 R 0x1
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr18176.s b/ld/testsuite/ld-x86-64/pr18176.s
new file mode 100644
index 0000000..405355f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr18176.s
@@ -0,0 +1,52 @@
+ .section .init,"ax",@progbits
+ .p2align 2
+ .space 0x1a
+ .section .text,"ax",@progbits
+ .p2align 4
+ .space 0x3ab96
+ .section .fini,"ax",@progbits
+ .p2align 2
+ .space 0x9
+ .section .foo_hdr,"a",@progbits
+ .p2align 2
+ .space 0xd14
+ .section .foo,"a",@progbits
+ .p2align 3
+ .space 0x4d5c
+ .section .rodata,"a",@progbits
+ .p2align 6
+ .space 0xa54d
+ .section .xxx,"a",@progbits
+ .space 0xf43
+ .section .yyy,"aw",@progbits
+ .space 0x1
+ .section .init_array,"aw",@init_array
+ .p2align 3
+ .space 0x10
+ .section .fini_array,"aw",@fini_array
+ .p2align 3
+ .space 0x8
+ .section .tdata,"awT",%progbits
+ .p2align 3
+ .space 0x4
+ .section .tbss,"awT",%nobits
+ .p2align 3
+ .space 0x40
+ .section .data.rel.ro,"aw",%progbits
+ .p2align 6
+ .space 0x1b60
+ .section .jcr,"aw",@progbits
+ .p2align 3
+ .space 0x8
+ .section .bar,"aw",@progbits
+ .p2align 3
+ .space 0x640
+ .section .data,"aw",%progbits
+ .p2align 5
+ .space 0x70
+ .section .bss,"aw",%nobits
+ .p2align 6
+ .space 0x8a0
+ .section BUS_ERROR_MAP,"aw",%progbits
+ .p2align 3
+ .space 0x230
diff --git a/ld/testsuite/ld-x86-64/pr18176.t b/ld/testsuite/ld-x86-64/pr18176.t
new file mode 100644
index 0000000..480c0cd
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr18176.t
@@ -0,0 +1,39 @@
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ . = SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS;
+ .hash : { *(.hash) }
+ .gnu.hash : { *(.gnu.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .init : { *(.init) }
+ .text : { *(.text) }
+ .fini : { *(.fini) }
+ .rodata : { *(.rodata) }
+ .foo_hdr : { *(.foo_hdr) }
+ .foo : { *(.foo) }
+ .xxx : { *(.xxx) }
+ . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
+ .yyy : { *(.yyy) }
+ .tdata : { *(.tdata) }
+ .tbss : { *(.tbss) }
+ .init_array : { *(.init_array) }
+ .fini_array : { *(.fini_array) }
+ .jcr : { *(.jcr) }
+ .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
+ .dynamic : { *(.dynamic) }
+ .bar : { *(.bar) }
+ . = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
+ .got.plt : { *(.got.plt) }
+ .data : { *(.data) }
+ __bss_start = .;
+ .bss :
+ {
+ *(.bss)
+ . = ALIGN(. != 0 ? 64 / 8 : 1);
+ }
+ . = ALIGN(64 / 8);
+ _end = .; PROVIDE (end = .);
+ . = DATA_SEGMENT_END (.);
+ /DISCARD/ : { *(.*) }
+}
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 7bceb7f..98514ed 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -318,6 +318,7 @@ run_dump_test "mov1d"
run_dump_test "pr17935-1"
run_dump_test "pr17935-2"
run_dump_test "pr18160"
+run_dump_test "pr18176"
# Must be native with the C compiler
if { [isnative] && [which $CC] != 0 } {
--
2.1.0
next prev parent reply other threads:[~2015-04-01 11:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-19 13:02 [PATCH] Reduce file size for PT_GNU_RELRO segment H.J. Lu
2015-03-26 2:22 ` Alan Modra
2015-03-27 20:00 ` H.J. Lu
2015-03-28 4:15 ` Alan Modra
2015-03-28 18:30 ` H.J. Lu
2015-03-28 22:46 ` H.J. Lu
2015-03-29 3:49 ` Alan Modra
2015-03-29 13:58 ` H.J. Lu
2015-03-30 12:39 ` Alan Modra
2015-03-30 13:00 ` H.J. Lu
2015-03-30 14:14 ` Alan Modra
2015-03-30 16:12 ` H.J. Lu
2015-04-01 9:12 ` Start of relro segment adjustment Alan Modra
2015-04-01 11:26 ` H.J. Lu [this message]
2015-03-29 3:19 ` [PATCH] Reduce file size for PT_GNU_RELRO segment H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMe9rOrYd3_ne-Mp933kzU1njd7aj-6MAqzQmSCGcA5JSUo3kQ@mail.gmail.com \
--to=hjl.tools@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).