This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR ld/14215: ld creates bad GNU_RELRO segment
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Sun, 10 Jun 2012 06:52:42 -0700
- Subject: Re: PATCH: PR ld/14215: ld creates bad GNU_RELRO segment
- References: <20120609210614.GA9654@intel.com>
On Sat, Jun 9, 2012 at 2:06 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Hi,
>
> We should check if .got.plt section exists before putting the first N
> bytes in PT_GNU_RELRO segment. ?OK to install?
>
> Thanks.
>
>
> H.J.
> --
> ld/
>
> 2012-06-09 ?H.J. Lu ?<hongjiu.lu@intel.com>
>
> ? ? ? ?PR ld/14215
> ? ? ? ?* ldexp.c (fold_binary): Check if .got.plt section exists
> ? ? ? ?before putting the first N bytes in PT_GNU_RELRO segment.
>
Here is the updated patch to check .got.plt section only if
expld.result.value isn't 0. OK to install.
--
H.J.
---
ld/
2012-06-10 H.J. Lu <hongjiu.lu@intel.com>
PR ld/14215
* ldexp.c (fold_binary): Check if .got.plt section exists
before putting the first N bytes of .got.plt section in
PT_GNU_RELRO segment.
ld/testsuite/
2012-06-10 H.J. Lu <hongjiu.lu@intel.com>
PR ld/14215
* ld-i386/i386.exp: Run pr14215.
* ld-x86-64/x86-64.exp: Likewise.
* ld-i386/pr14215.d: New file.
* ld-i386/pr14215.s: Likewise.
* ld-x86-64/pr14215.d: Likewise.
* ld-x86-64/pr14215.s: Likewise.
diff --git a/ld/ldexp.c b/ld/ldexp.c
index 3bddc81..c1ec92c 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -487,9 +487,23 @@ fold_binary (etree_type *tree)
|| expld.dataseg.phase == exp_dataseg_relro_adjust
|| expld.dataseg.phase == exp_dataseg_done)
{
+ bfd_vma value = expld.result.value;
+ if (value != 0)
+ {
+ /* Check if .got.plt section exists before putting the
+ first VALUE bytes of .got.plt section in PT_GNU_RELRO
+ segment. */
+ asection *gotplt;
+ gotplt = bfd_get_section_by_name (link_info.output_bfd,
+ ".got.plt");
+ if (gotplt == NULL
+ || (gotplt->rawsize == 0
+ && (gotplt->flags & SEC_KEEP) == 0))
+ value = 0;
+ }
if (expld.dataseg.phase == exp_dataseg_align_seen
|| expld.dataseg.phase == exp_dataseg_relro_adjust)
- expld.dataseg.relro_end = lhs.value + expld.result.value;
+ expld.dataseg.relro_end = lhs.value + value;
if (expld.dataseg.phase == exp_dataseg_relro_adjust
&& (expld.dataseg.relro_end
@@ -497,8 +511,7 @@ fold_binary (etree_type *tree)
{
expld.dataseg.relro_end += expld.dataseg.pagesize - 1;
expld.dataseg.relro_end &= ~(expld.dataseg.pagesize - 1);
- expld.result.value = (expld.dataseg.relro_end
- - expld.result.value);
+ expld.result.value = expld.dataseg.relro_end - value;
}
else
expld.result.value = lhs.value;
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 47f918f..03367ca 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -245,3 +245,4 @@ if { !([istarget "i?86-*-linux*"]
run_dump_test "compressed1"
run_dump_test "pr12627"
run_dump_test "pr13302"
+run_dump_test "pr14215"
diff --git a/ld/testsuite/ld-i386/pr14215.d b/ld/testsuite/ld-i386/pr14215.d
new file mode 100644
index 0000000..78ec994
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr14215.d
@@ -0,0 +1,9 @@
+#name: PR ld/14215
+#as: --32
+#ld: -melf_i386 -shared -z relro
+#readelf: -l --wide
+
+#failif
+#...
+ 03 .dynamic .got .data
+#...
diff --git a/ld/testsuite/ld-i386/pr14215.s b/ld/testsuite/ld-i386/pr14215.s
new file mode 100644
index 0000000..df0cbc2
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr14215.s
@@ -0,0 +1,4 @@
+ .section .got
+ .space 0x2a8, 4
+ .data
+ .zero 12
diff --git a/ld/testsuite/ld-x86-64/pr14215.d b/ld/testsuite/ld-x86-64/pr14215.d
new file mode 100644
index 0000000..7d8e90d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr14215.d
@@ -0,0 +1,9 @@
+#name: PR ld/14215
+#as: --64
+#ld: -melf_x86_64 -shared -z relro
+#readelf: -l --wide
+
+#failif
+#...
+ 03 .dynamic .got .data
+#...
diff --git a/ld/testsuite/ld-x86-64/pr14215.s b/ld/testsuite/ld-x86-64/pr14215.s
new file mode 100644
index 0000000..281b638
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr14215.s
@@ -0,0 +1,4 @@
+ .section .got
+ .space 0x2a8, 4
+ .data
+ .zero 24
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp
b/ld/testsuite/ld-x86-64/x86-64.exp
index 7d2934f..b9af8de 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -208,6 +208,7 @@ run_dump_test "pr12921"
run_dump_test "pr13947"
run_dump_test "pr12570a"
run_dump_test "pr12570b"
+run_dump_test "pr14215"
if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
return