Bug 10378

Summary: SH: jump table for switch/case got invalid adjustment during relaxing.
Product: binutils Reporter: Takashi YOSHII <yoshii.takashi>
Component: ldAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: bug-binutils, kkojima, olegendo
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target: sh
Build: Last reconfirmed:
Attachments: test program
patch to fix

Description Takashi YOSHII 2009-07-08 05:56:49 UTC
R_SH_SWITCH8(.byte Label2-Label1) can be alterd if codes between two labels got
shorter by relaxing. But currently the adjustment value seems to be bad.
Comment 1 Takashi YOSHII 2009-07-08 06:03:22 UTC
Created attachment 4044 [details]
test program

as -relax adjsw8.s -o adjsw8.o; ld -relax adjsw8.o; objdump -t; objdump -s
and see if first 3 bytes are L1-L0,L2-L0,L3-L0 (should be 04 08 0c).
HEAD of CVS produces 04 06 0a.
Comment 2 Takashi YOSHII 2009-07-08 06:38:45 UTC
Created attachment 4045 [details]
patch to fix

I added small code to gas as bfd/elf-sh.c expects r_addend holds the different
between reloc address and label1. I can't find any official documents(ELF-ps or
so), though.
Tested for target=sh4-unknown-linux-gnu host=build=x86_64-pc-linux-gnu with 
$ make check-bfd check-gas check-ld RUNTESTFLAGS="--target_board=sh-sim
SIM=$PWD/sim/sh/run"
New test case and even old sh.exp:"SH relaxing execution" can detect this
issue.
Comment 3 Oleg Endo 2014-06-20 22:48:55 UTC
I believe this is a (partial) dup of PR 3298.
Comment 4 Oleg Endo 2014-08-02 15:21:52 UTC
The issue has been fixed on trunk and should be available in the next release that follows binutils 2.24.