This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Exclude zero size section for RELRO segment match


On Sun, Feb 18, 2018 at 7:21 PM, Alan Modra <amodra@gmail.com> wrote:
> On Sat, Feb 17, 2018 at 03:19:26PM -0800, H.J. Lu wrote:
>> On Fri, Feb 16, 2018 at 3:44 PM, Alan Modra <amodra@gmail.com> wrote:
>> > --- a/bfd/elf.c
>> > +++ b/bfd/elf.c
>> > @@ -5897,6 +5897,7 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
>> >                    lm = lm->next, lp++)
>> >                 {
>> >                   if (lp->p_type == PT_LOAD
>> > +                     && lp->p_memsz != 0
>> >                       && lm->count != 0
>> >                       && lm->sections[lm->count - 1]->vma >= start
>> >                       && lm->sections[0]->vma < end)
>> >
>>
>> This patch isn't sufficient.  On x86, with this patch, I got
>>
>> [hjl@gnu-tools-1 ld]$  ../gas/as-new
>> -I/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf   -o
>> tmpdir/tbss.o /export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf/tbss.s
>> [hjl@gnu-tools-1 ld]$ ../gas/as-new
>> -I/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf   -o
>> tmpdir/frame.o /export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf/frame.s
>> [hjl@gnu-tools-1 ld]$ ./ld-new   -o tmpdir/frame.so -z separate-code
>> --shared tmpdir/frame.o tmpdir/tbss.o
>> ./ld-new: BFD (GNU Binutils) 2.30.51.20180217 assertion fail
>> /export/gnu/import/git/sources/binutils-gdb/bfd/elf.c:5917
>> [hjl@gnu-tools-1 ld]$
>>
>> My original patch fixes them.
>
> You're correct, but the real underlying problem is that my load
> section end calculation was wrong.  That can be fixed without a loop
> scanning back through sections.
>
> BTW, the testsuite changes will need some tweaks before they can be
> committed, eg.
> /home/alan/build/gas/d30v-elf/ld/ld-new: unrecognized option '-z'

This is the patch I am checking in.   It skips frame tests if -shared isn't
supported.

>         PR 22845
>         * elf.c (IS_TBSS): Define.
>         (_bfd_elf_map_sections_to_segments): Use IS_TBSS.
>         (assign_file_positions_for_non_load_sections): Revert last change.
>         Properly calculate load segment limits to compare against relro limits.
>

Thanks.

-- 
H.J.
From 5231ad1399e8794864891969f7de7cd5383bfe67 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 17 Feb 2018 15:06:32 -0800
Subject: [PATCH] ld: Add -z separate-code tests to frame.exp

On x86, "-z separate-code" leads to assertion fail at bfd/elf.c:5917.
Alsp skip tests if -shared isn't supported.

	PR ld/22845
	* testsuite/ld-elf/frame.exp: Skip if -shared isn't supported.
	Add tests for "-z noseparate-code" and "-z separate-code".
	Remove unsupported -shared check.
---
 ld/testsuite/ld-elf/frame.exp | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/ld/testsuite/ld-elf/frame.exp b/ld/testsuite/ld-elf/frame.exp
index 6cce42deb3..8862ff14a5 100644
--- a/ld/testsuite/ld-elf/frame.exp
+++ b/ld/testsuite/ld-elf/frame.exp
@@ -29,7 +29,7 @@ if ![is_elf_format] {
 }
 
 # No shared lib support on this target.
-if { [istarget "mcore-*-*"] } {
+if ![istarget shared] {
     return
 }
 
@@ -64,14 +64,16 @@ if { ![ld_assemble_flags $as $as_opt $srcdir/$subdir/tbss.s tmpdir/tbss.o ]
     return
 }
 
-if { [ld_link $ld tmpdir/frame.so "--shared tmpdir/frame.o tmpdir/tbss.o"] } {
-    pass "$test1"
+if { [ld_link $ld tmpdir/frame.so "-z noseparate-code --shared tmpdir/frame.o tmpdir/tbss.o"] } {
+    pass "$test1 -z noseparate-code"
 } else {
-    if [string match "*shared not supported*" $link_output] {
-	unsupported "-shared is not supported by this target"
-    } else {
-	fail "$test1"
-    }
+   fail "$test1 -z noseparate-code"
+}
+
+if { [ld_link $ld tmpdir/frame.so "-z separate-code --shared tmpdir/frame.o tmpdir/tbss.o"] } {
+    pass "$test1 -z separate-code"
+} else {
+    fail "$test1 -z separate-code"
 }
 
 if ![ld_assemble_flags $as $as_opt $srcdir/$subdir/table.s tmpdir/table.o ] {
@@ -79,12 +81,14 @@ if ![ld_assemble_flags $as $as_opt $srcdir/$subdir/table.s tmpdir/table.o ] {
     return
 }
 
-if { [ld_link $ld tmpdir/table.so "--shared tmpdir/table.o tmpdir/tbss.o"] } {
-    pass "$test2"
+if { [ld_link $ld tmpdir/table.so "-z noseparate-code --shared tmpdir/table.o tmpdir/tbss.o"] } {
+    pass "$test2 -z noseparate-code"
+} else {
+    fail "$test2 -z noseparate-code"
+}
+
+if { [ld_link $ld tmpdir/table.so "-z separate-code --shared tmpdir/table.o tmpdir/tbss.o"] } {
+    pass "$test2 -z separate-code"
 } else {
-    if [string match "*shared not supported*" $link_output] {
-	unsupported "-shared is not supported by this target"
-    } else {
-	fail "$test2"
-    }
+    fail "$test2 -z separate-code"
 }
-- 
2.14.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]