[PATCH] RX: Incorrect output for displacement of subtruct expression

Yoshinori Sato ysato@users.sourceforge.jp
Fri Dec 27 14:11:55 GMT 2024


On Thu, 26 Dec 2024 16:53:59 +0900,
Oleg Endo wrote:
> 
> 
> On Thu, 2024-12-26 at 12:53 +0900, Yoshinori Sato wrote:
> > Assembling the following code results in incorrect displacement values:
> > 1: mov.L 2f-1b[r0],r0
> > 
> > If you write a subtraction formula in the displacement field, the value
> > will simply be the result of the subtraction, which will not be the
> > expected value for word and longword sizes.
> > 
> > gas/
> > 	* config/rx-parse.y (displacement): use BFD_RELOC_RX_GPREL in subtract expression.
> > 	* testsuite/gas/rx/mov.sm: Add subtruct expression displacement.
> > 	* testsuite/gas/rx/mov.d: Likewise.
> > 
> 
> Hi!
> 
> Wow .. how did you find this bug?  I'm curious because I've been using an RX
> system with GCC 8 and older binutils for several years.

I am trying to get FDPIC support in RX.
gcc, which supports this FDPIC, generated the following code for a switch
statement:

1:      mvfc    pc, r3
	shll    #2, r14
        add     r3, r14
        mov.L   .L282 - 1b[r14], r14

1:      bra     r14
        .balign 4
.L282:
        .long .L284 - 1b
        .long .L280 - 1b
        .long .L280 - 1b

I investigated why this code wasn't working as expected and discovered that it
was due to this bug.
This kind of code is not output by the release version of gcc, and even when
written in assembler, it is not written in this way, so I don't think anyone
noticed the bug.

> Thanks for posting the patch!
> 
> Best regards,
> Oleg Endo
> 

-- 
Yoshinori Sato


More information about the Binutils mailing list