[PATCH] Exclude zero size section for RELRO segment match

H.J. Lu hjl.tools@gmail.com
Mon Feb 19 13:06:00 GMT 2018


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.
-------------- 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: 2541 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20180219/1fecebad/attachment.bin>


More information about the Binutils mailing list