This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Exclude zero size section for RELRO segment match
On Fri, Feb 16, 2018 at 3:44 PM, Alan Modra <amodra@gmail.com> wrote:
> On Fri, Feb 16, 2018 at 04:13:04AM -0800, H.J. Lu wrote:
>> On Fri, Feb 16, 2018 at 4:08 AM, Alan Modra <amodra@gmail.com> wrote:
>> > On Thu, Feb 15, 2018 at 03:58:16AM -0800, H.J. Lu wrote:
>> >> When seaching a LOAD segment which overlaps with the RELRO segment, we
>> >> need to check the size of the last non-zero size section in the LOAD
>> >> segment.
>> >
>> > Why? Do you have a case where the current algorithm goes wrong?
>> >
>>
>> Yes, apply this patch and I get assert in
>> assign_file_positions_for_non_load_sections
>> on x86-64:
>
> On looking at the tbss1 fail, I see a PT_LOAD with a single
> zero length .eh_frame section. So we have a degenerate PT_LOAD.
> I think the following simpler patch is sufficient.
>
> Your testsuite change is OK, but please check a large set of targets
> before committing in case some targets won't support -z separate-code.
>
> PR 22845
> * elf.c (assign_file_positions_for_non_load_sections): Ignore
> degenerate zero size PT_LOAD segments when finding one overlapping
> the PT_GNU_RELRO segment.
>
> diff --git a/bfd/elf.c b/bfd/elf.c
> index 397fa62..b069b59 100644
> --- 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.
--
H.J.
From 04a1a6e280aeada4031b1f89c2c4c35ade8f3679 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.
PR ld/22845
* testsuite/ld-elf/frame.exp: Add tests for "-z noseparate-code"
and "-z separate-code".
---
ld/testsuite/ld-elf/frame.exp | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/ld/testsuite/ld-elf/frame.exp b/ld/testsuite/ld-elf/frame.exp
index 6cce42deb3..55e6cba529 100644
--- a/ld/testsuite/ld-elf/frame.exp
+++ b/ld/testsuite/ld-elf/frame.exp
@@ -64,13 +64,23 @@ 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 {
+ if [string match "*shared not supported*" $link_output] {
+ unsupported "-shared is not supported by this target"
+ } else {
+ fail "$test1 -z separate-code"
}
}
@@ -79,12 +89,22 @@ 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 {
+ if [string match "*shared not supported*" $link_output] {
+ unsupported "-shared is not supported by this target"
+ } 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