Binutils 2.28 on PowerPC: dangerous relocation: generic linker can't handle R_PPC_SECTOFF_HA
Alan Modra
amodra@gmail.com
Wed May 15 04:10:00 GMT 2019
On Tue, May 14, 2019 at 02:42:36PM +0200, Sebastian Huber wrote:
> Lets look at the following assembler code in the .text input section:
>
> https://git.rtems.org/rtems/tree/bsps/powerpc/motorola_powerpc/bootloader/head.S
>
> /* Call the routine to fill boot_data structure from residual data.
> Â * And to find where the code has to be moved.
> Â */
>    lis   r3,__size@sectoff@ha
>    addi   r3,r3,__size@sectoff@l
>
> This symbol is defined by the linker script:
>
> https://git.rtems.org/rtems/tree/bsps/powerpc/motorola_powerpc/bootloader/ppcboot.lds
>
> |.bss : { *(.sbss) *(.bss) . = ALIGN(4); } __bss_words = SIZEOF(.bss)>>2;
> __size = . ; /DISCARD/ : { *(.comment) } }|
>
>
> I built the latest Binutils and invoked ld in GDB. I set a break point to
> _bfd_final_link_relocate(). Here I get this:
[snip]
> (gdb) p sec->output_section ->name
> $2 = 0x89cc60 ".bss"
>
> Why is the output section .bss for __size and not *ABS*?
See ldexp.c set_sym_sections and ldlang.c section_for_dot. The linker
ties assignments to their nearest output section statement because
that works out best in most real-world usage. For example, symbols
like "_end" should not be SHN_ABS due to their use in position
independent code invariably wanting the value relocated by the base
address of the shared library or PIE.
We do have a way of forcing SHN_ABS symbols in scripts:
__size = ABSOLUTE (.);
> If I do this with the latest Binutils 2.19 branch. I get:
[snip]
> (gdb) p sec->output_section ->name
> $2 = 0x4acd54 "*ABS*"
Yes, well, this is why many ld.so implementations must relocate
SHN_ABS symbols. Weird but necessary given older linker behaviour.
The source you show is slightly crazy too. Why use @sectoff when
expecting a SHN_ABS symbol?
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list