[PATCH + test RFA] MIPS/LD: Fix crashing with a discarded dynamic relocation section

H.J. Lu hjl.tools@gmail.com
Fri Jul 20 13:09:00 GMT 2018


On Fri, Jul 20, 2018 at 5:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Jul 20, 2018 at 5:40 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Fri, Jul 20, 2018 at 5:30 AM, Maciej W. Rozycki <macro@mips.com> wrote:
>>> Hi Nick,
>>>
>>>> Approved.  Better to have a testcase that fails than a problem that
>>>> no-one knows about...
>>>
>>>  Applied then, thanks for the quick review.  I keep being confused about
>>> our XFAIL policy (and myself I tend to forget about things that have been
>>> XFAILed and never get back to them, so they never get fixed, unless
>>> perhaps by chance if I come across the same problem elsewhere).
>>>
>>>   Maciej
>>
>> On x86-64, I got
>>
>> regexp_diff match failure
>> regexp "^There are no dynamic relocations in this file\.$"
>> line   "'RELA' relocation section at offset 0x70 contains 24 bytes:"
>> extra lines in tmpdir/dump.out starting with "^  Offset          Info
>>          Type           Sym. Value    Sym. Name + Addend$"
>> EOF from /export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf/reloc-discard.d
>> FAIL: Discarded dynamic relocation section
>>
>> [hjl@gnu-cfl-1 ld]$ cat 1
>> /export/build/gnu/binutils-gold/build-x86_64-linux/ld/../gas/as-new
>> --defsym ALIGN=3   -o tmpdir/reloc-discard.o
>> /export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf/reloc-discard.s
>> ./ld-new -z norelro
>> -L/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf
>> -shared -T reloc-discard.ld -o tmpdir/dump tmpdir/reloc-discard.o
>> /export/build/gnu/binutils-gold/build-x86_64-linux/ld/../binutils/readelf
>>  -r --use-dynamic tmpdir/dump
>> [hjl@gnu-cfl-1 ld]$ sh 1
>>
>> 'RELA' relocation section at offset 0x70 contains 24 bytes:
>>   Offset          Info           Type           Sym. Value    Sym. Name + Addend
>> 000000000088  000100000001 R_X86_64_64       0000000000000000 foo + 0
>> [hjl@gnu-cfl-1 ld]$
>>
>>
>> --
>> H.J.
>
> diff --git a/ld/testsuite/ld-elf/reloc-discard.ld
> b/ld/testsuite/ld-elf/reloc-discard.ld
> index b16b80a242..1252bbb832 100644
> --- a/ld/testsuite/ld-elf/reloc-discard.ld
> +++ b/ld/testsuite/ld-elf/reloc-discard.ld
> @@ -2,5 +2,5 @@ SECTIONS
>  {
>    /* .dynamic needs to go first with MIPS IRIX-style emulations.  */
>    .dynamic : { *(.dynamic) }
> -  /DISCARD/ : { *(.rel.dyn) *(.rela.dyn) }
>                                ^^^^^^^^^^^^^^^^^^  This won't work on
> output sections.
>
> On many targets, .rel.dyn and .rela.dyn are output sections.
>
> +  /DISCARD/ : { *(.rel.*) *(.rela.*) }
>                            ^^^^^^^^^^^^^^^ This works.
>  }
>

Some backends will issue a warning:

[hjl@gnu-cfl-1 ld]$
/export/build/gnu/binutils-cross/build-powerpc64-linux/ld/../gas/as-new
 --defsym ALIGN=3   -o tmpdir/reloc-discard.o
/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf/reloc-discard.s
[hjl@gnu-cfl-1 ld]$ ./ld-new -z norelro
-L/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf
-shared -T reloc-discard.ld -o tmpdir/dump tmpdir/reloc-discard.o
./ld-new: warning: discarding dynamic section .rela.data
[hjl@gnu-cfl-1 ld]$


-- 
H.J.



More information about the Binutils mailing list