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 08/05/2019 10:41, Alan Modra wrote:
On Tue, May 07, 2019 at 10:30:40AM +0200, Sebastian Huber wrote:
powerpc-rtems4.9-ld --version
GNU ld (GNU Binutils) 2.19.1

With this LD version I can boot the application. The LD output is a binary
file. I had to remove the OUTPUT_ARCH(powerpc) from ppcboot.lds.

Since at least Binutils 2.28, it no longer works:

powerpc-rtems5-ld -o ticker.ralf
/build/git-build/b-any/powerpc-rtems5/mvme2100/lib/bootloader.o
--just-symbols=ticker.exe -b binary rtems.gz -T
~/git-rtems-5/./bsps/powerpc/motorola_powerpc/bootloader/ppcboot.lds
/build/git-build/b-any/powerpc-rtems5/mvme2100/lib/bootloader.o: in function
`start':
/home/EB/sebastian_h/git-rtems-5/c/src/lib/libbsp/powerpc/motorola_powerpc/bootloader/../../../../../../../bsps/powerpc/motorola_powerpc/bootloader/head.S:140:(.text+0x8a):
dangerous relocation: generic linker can't handle R_PPC_SECTOFF_HA
/home/EB/sebastian_h/git-rtems-5/c/src/lib/libbsp/powerpc/motorola_powerpc/bootloader/../../../../../../../bsps/powerpc/motorola_powerpc/bootloader/head.S:141:(.text+0x8e):
The truth is that linking to binary with 2.19 did not handle any of
the R_PPC_SECTOFF relocations correctly.  They were handled just like
the corresponding R_PPC_ADDR16 reloc, a fact that you can verify by
comparing the reloc howtos.  (Reloc howtos are used by the generic
linker to apply relocations.  When linking to powerpc ELF you'll be
using the code in ppc_elf_relocate_section instead.)  So the values
applied by 2.19 were symbol values rather than symbol values relative
to their output section.

I think that means your assembly code has compensated for the 2.19
linker behaviour by some means or other, and therefore crashes with a
fixed linker.

You'll probably find that using 2.19 to link to ELF then objcopy to
binary will also give you a "bad" output.

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:

Breakpoint 1 at 0x44c590: file /home/EB/sebastian_h/archive/binutils-git/bfd/reloc.c, line 1340.
(gdb) r
Starting program: /opt/rtems/5/bin/powerpc-rtems5-ld -o ticker.ralf bootloader.o --just-symbols=ticker.exe -b binary rtems.gz -T ppcboot.lds -no-warn-mismatch

Breakpoint 1, _bfd_final_link_relocate (howto=howto@entry=0x647340 <ppc_elf_howto_raw+1440>, input_bfd=input_bfd@entry=0x8a9c50, input_section=input_section@entry=0x8aae30, contents=contents@entry=0x99b5e0 "H", address=138, value=value@entry=155668, addend=18446744073709433152) at /home/EB/sebastian_h/archive/binutils-git/bfd/reloc.c:1340
1340                              bfd_vma value,
(gdb) bt
#0  _bfd_final_link_relocate (howto=howto@entry=0x647340 <ppc_elf_howto_raw+1440>, input_bfd=input_bfd@entry=0x8a9c50, input_section=input_section@entry=0x8aae30, contents=contents@entry=0x99b5e0 "H", address=138, value=value@entry=155668, addend=18446744073709433152) at /home/EB/sebastian_h/archive/binutils-git/bfd/reloc.c:1340 #1  0x000000000045e54d in ppc_elf_relocate_section (output_bfd=output_bfd@entry=0x89d220, info=0x88c820 <link_info>, input_bfd=input_bfd@entry=0x8a9c50, input_section=input_section@entry=0x8aae30, contents=0x99b5e0 "H", relocs=relocs@entry=0x8d11d8, local_syms=0x9c5890, local_sections=0x9cdec0) at /home/EB/sebastian_h/archive/binutils-git/bfd/elf32-ppc.c:9039 #2  0x0000000000487029 in elf_link_input_bfd (flinfo=flinfo@entry=0x7fffffffd540, input_bfd=input_bfd@entry=0x8a9c50) at /home/EB/sebastian_h/archive/binutils-git/bfd/elflink.c:10887 #3  0x0000000000488897 in bfd_elf_final_link (abfd=<optimized out>, info=<optimized out>) at /home/EB/sebastian_h/archive/binutils-git/bfd/elflink.c:12214 #4  0x000000000041874d in ldwrite () at /home/EB/sebastian_h/archive/binutils-git/ld/ldwrite.c:581 #5  0x0000000000402f20 in main (argc=<optimized out>, argv=<optimized out>) at /home/EB/sebastian_h/archive/binutils-git/ld/ldmain.c:457
(gdb) frame 1
#1  0x000000000045e54d in ppc_elf_relocate_section (output_bfd=output_bfd@entry=0x89d220, info=0x88c820 <link_info>, input_bfd=input_bfd@entry=0x8a9c50, input_section=input_section@entry=0x8aae30, contents=0x99b5e0 "H", relocs=relocs@entry=0x8d11d8, local_syms=0x9c5890, local_sections=0x9cdec0) at /home/EB/sebastian_h/archive/binutils-git/bfd/elf32-ppc.c:9039 9039            r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
(gdb) p sym_name
$1 = 0x8d4231 "__size"
(gdb) p sec->output_section ->name
$2 = 0x89cc60 ".bss"
(gdb) p input_section->name
$3 = 0x8b2c50 ".text"

Why is the output section .bss for __size and not *ABS*?

If I do this with the latest Binutils 2.19 branch. I get:

(gdb) b _bfd_final_link_relocate
Breakpoint 1 at 0x427b40: file /home/EB/sebastian_h/archive/binutils-git/bfd/reloc.c, line 1346.
(gdb) r
Starting program: /opt/rtems/4.9/bin/powerpc-rtems4.9-ld -o ticker.ralf bootloader.o --just-symbols=ticker.exe -b binary rtems.gz -T ppcboot.lds -no-warn-mismatch

Breakpoint 1, _bfd_final_link_relocate (howto=howto@entry=0x4dcfe0 <ppc_elf_howto_raw+2880>, input_bfd=input_bfd@entry=0x7298e0, input_section=input_section@entry=0x72cdc8, contents=contents@entry=0x822e90 "H", address=138, value=value@entry=155668, addend=32768) at /home/EB/sebastian_h/archive/binutils-git/bfd/reloc.c:1346
1346      if (address > bfd_get_section_limit (input_bfd, input_section))
(gdb) bt
#0  _bfd_final_link_relocate (howto=howto@entry=0x4dcfe0 <ppc_elf_howto_raw+2880>, input_bfd=input_bfd@entry=0x7298e0, input_section=input_section@entry=0x72cdc8, contents=contents@entry=0x822e90 "H", address=138, value=value@entry=155668, addend=32768) at /home/EB/sebastian_h/archive/binutils-git/bfd/reloc.c:1346 #1  0x000000000043a1ba in ppc_elf_relocate_section (output_bfd=output_bfd@entry=0x71d2c0, info=0x70f900 <link_info>, input_bfd=input_bfd@entry=0x7298e0, input_section=input_section@entry=0x72cdc8, contents=contents@entry=0x822e90 "H", relocs=relocs@entry=0x757d88, local_syms=0x84d140, local_sections=0x855770) at /home/EB/sebastian_h/archive/binutils-git/bfd/elf32-ppc.c:7318 #2  0x000000000045c359 in elf_link_input_bfd (finfo=finfo@entry=0x7fffffffd520, input_bfd=input_bfd@entry=0x7298e0) at /home/EB/sebastian_h/archive/binutils-git/bfd/elflink.c:9308 #3  0x000000000045df3e in bfd_elf_final_link (abfd=0x71d2c0, info=0x70f900 <link_info>) at /home/EB/sebastian_h/archive/binutils-git/bfd/elflink.c:10448 #4  0x000000000041534d in ldwrite () at /home/EB/sebastian_h/archive/binutils-git/ld/ldwrite.c:567 #5  0x000000000040283e in main (argc=<optimized out>, argv=<optimized out>) at /home/EB/sebastian_h/archive/binutils-git/ld/ldmain.c:462
(gdb) frame 1
#1  0x000000000043a1ba in ppc_elf_relocate_section (output_bfd=output_bfd@entry=0x71d2c0, info=0x70f900 <link_info>, input_bfd=input_bfd@entry=0x7298e0, input_section=input_section@entry=0x72cdc8, contents=contents@entry=0x822e90 "H", relocs=relocs@entry=0x757d88, local_syms=0x84d140, local_sections=0x855770) at /home/EB/sebastian_h/archive/binutils-git/bfd/elf32-ppc.c:7318
7318          r = _bfd_final_link_relocate (howto,
(gdb) p sym_name
$1 = 0x75aaa1 "__size"
(gdb) p sec->output_section ->name
$2 = 0x4acd54 "*ABS*"
(gdb) p input_section ->name
$3 = 0x73b770 ".text"

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.


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