This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Binutils 2.28 on PowerPC: dangerous relocation: generic linker can't handle R_PPC_SECTOFF_HA


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]