Bug 3132 - Incorrect 16-bit relocations in ELF
Summary: Incorrect 16-bit relocations in ELF
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-25 15:28 UTC by Markus Gyger
Modified: 2022-08-24 13:59 UTC (History)
1 user (show)

See Also:
Host: i386-pc-solaris2.10
Target: h8300-elf
Build: i386-pc-solaris2.10
Last reconfirmed:


Attachments
Assembler example to show incorrect 16-bit ELF relocation (91 bytes, text/plain)
2006-08-25 15:30 UTC, Markus Gyger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Gyger 2006-08-25 15:28:16 UTC
ELF on ld 2.17 incorrectly calculates 8- and 16-bit relocations that worked with
COFF on ld 2.16.2.

  h8300-coff-as -oreloc.o reloc.s
  h8300-coff-ld -mh8300s --oformat binary reloc.o
  od -tx1 a.out
correctly yields:
  0000000 6a 08 e0 02 00 02

while

  h8300-elf-as -oreloc.o reloc.s
  h8300-elf-ld -mh8300self --oformat binary reloc.o
yields:
  reloc.o:(.text+0x2): relocation truncated to fit: R_H8_DIR16A8 against `addr'

and

  h8300-elf-as -oreloc.o reloc.s
  h8300-elf-ld -mh8300self reloc.o
  h8300-elf-objdump -d a.out
  h8300-elf-objcopy -Obinary a.out
  od -tx1 a.out
yields:
  0000000 6a 08 e0 02 01 06


Content of reloc.s:
.h8300s
_start = 0
.global _start

mov @addr + 2 :16, r0l
addr = 0xffe000

.word label - .
label:
Comment 1 Markus Gyger 2006-08-25 15:30:47 UTC
Created attachment 1250 [details]
Assembler example to show incorrect 16-bit ELF relocation
Comment 2 Alan Modra 2022-08-24 13:59:57 UTC
This is a gas problem.  gas is generating R_H8_DIR16 for the .word expression, which is wrong.  The expression needs a 16 bit pc-relative reloc instead, or gas should be resolving the "label-." expression itself.  It doesn't resolve the expression because h8300 sets linkrelax and there is no logic to detect that the expression is pc-relative and does not cross a region that could change size.