bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/14902] New: h8300-elf linker relaxations: symbols skipped


From: achille.fouilleul+binutils at gadz dot org
Subject: [Bug binutils/14902] New: h8300-elf linker relaxations: symbols skipped
Date: Fri, 30 Nov 2012 23:36:12 +0000

http://sourceware.org/bugzilla/show_bug.cgi?id=14902

             Bug #: 14902
           Summary: h8300-elf linker relaxations: symbols skipped
           Product: binutils
           Version: 2.23
            Status: NEW
          Severity: normal
          Priority: P2
         Component: binutils
        AssignedTo: address@hidden
        ReportedBy: address@hidden
    Classification: Unclassified


Created attachment 6767
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6767
proposed fix (don't forget to remove the fprintfs)

With binutils 2.23.1, configured with --target=h8300-elf

When relaxations are applied, symbols located after the last instruction of a
.text section do not get updated as they should.

$ cat a.s 
    .h8300s
    .text
    .globl _start
    .globl _a
    .globl _a_end
_start:
_a:
    sub r0,r0
    jmp @_a
    sub r1,r1
    jmp @_b
    sub r2,r2
_a_end:

$ cat b.s 
    .h8300s
    .text
    .globl _b
_b:
    sub r0,r0
    jmp @_a
    sub r1,r1
    jmp @_b
    sub r2,r2
    jmp @_a_end
_b_end:

$ cat Makefile 
AS = h8300-elf-as
LD = h8300-elf-ld

result.elf: a.o b.o
    $(LD) --relax -mh8300self $^ -o $@

.PHONY: clean

clean:
    -rm -f *.o *.elf

.s.o:
    $(AS) $< -o $@


Assemble and link the files above (Makefile provided for convenience), then run
h8300-elf-objdump -dr result.elf:

result.elf:     file format elf32-h8300


Disassembly of section .text:

00000100 <_a>:
 100:    19 00           sub.w    r0,r0
 102:    40 fc           bra    .-4 (0x100)
 104:    19 11           sub.w    r1,r1
 106:    40 02           bra    .+2 (0x10a)
 108:    19 22           sub.w    r2,r2

0000010a <_b>:
 10a:    19 00           sub.w    r0,r0
 10c:    40 f2           bra    .-14 (0x100)

0000010e <_a_end>:
 10e:    19 11           sub.w    r1,r1
 110:    40 f8           bra    .-8 (0x10a)
 112:    19 22           sub.w    r2,r2
 114:    40 f8           bra    .-8 (0x10e)

The _a_end symbol has not been adjusted. One problem with this bug is that gcc
often places labels at the end of .text sections; with midly complex programs
and linker scripts, this has led to incorrect code being generated.

I think the problem is in the elf32_h8_relax_delete_bytes() function
(elf32-h8300.c); symbol values are always compared strictly with toaddr. I
think the <= operator should be used instead. The attached patch seems to fix
the issue:

result.elf:     file format elf32-h8300


Disassembly of section .text:

00000100 <_a>:
 100:    19 00           sub.w    r0,r0
 102:    40 fc           bra    .-4 (0x100)
 104:    19 11           sub.w    r1,r1
 106:    40 02           bra    .+2 (0x10a)
 108:    19 22           sub.w    r2,r2

0000010a <_a_end>:
 10a:    19 00           sub.w    r0,r0
 10c:    40 f2           bra    .-14 (0x100)
 10e:    19 11           sub.w    r1,r1
 110:    40 f8           bra    .-8 (0x10a)
 112:    19 22           sub.w    r2,r2
 114:    40 f4           bra    .-12 (0x10a)

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]