[PATCH] Exclude zero size section for RELRO segment match

H.J. Lu hjl.tools@gmail.com
Sat Feb 17 23:19:00 GMT 2018


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ld-Add-z-separate-code-tests-to-frame.exp.patch
Type: text/x-patch
Size: 2455 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20180217/cc38fa5d/attachment.bin>


More information about the Binutils mailing list