This is the mail archive of the binutils@sources.redhat.com 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]

Patch to fix GP-relative MIPS16 relocs


This patch exempts R_MIPS16_GPREL from the MIPS bfd_install_relocation
hacks, just like R_MIPS_GPREL16 is exempted now.

Or the longer version: md_apply_fix3 has a hack to subtract a symbol's
value twice, because generic code in bfd_install_relcoation will
incorrectly add the value back in.  GP-relative relocs are one of the
few not to need this treatment, because their HOWTO hooks handle the
complete calculation, and get it right.  At the moment GAS only checks
for BFD_RELOC_GPREL16, this patch makes it check BFD_RELOC_MIPS16_GPREL
as well.

Patch fixes the attached test case, no regressions on mips-elf or
mipsel-elf.  OK to install?

[gas/]
	* config/tc-mips.c (tc_gen_reloc): Extend GP-relative addend
	handling to BFD_RELOC_MIPS16_GPREL.

[gas/testsuite/]
	* gas/mips/elf-rel6.[sd]: New test.
	* gas/mips/mips.exp: Run it.

Index: gas/config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.151
diff -c -d -p -r1.151 tc-mips.c
*** gas/config/tc-mips.c	25 Jul 2002 11:07:47 -0000	1.151
--- gas/config/tc-mips.c	29 Jul 2002 11:02:23 -0000
*************** tc_gen_reloc (section, fixp)
*** 12685,12691 ****
       stop md_apply_fix3 from subtracting twice in the first place since
       the fake addend is required for variant frags above.  */
    if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
!       && code == BFD_RELOC_GPREL16
        && reloc->addend != 0
        && mips_need_elf_addend_fixup (fixp))
      reloc->addend += S_GET_VALUE (fixp->fx_addsy);
--- 12685,12691 ----
       stop md_apply_fix3 from subtracting twice in the first place since
       the fake addend is required for variant frags above.  */
    if (fixp->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour
!       && (code == BFD_RELOC_GPREL16 || code == BFD_RELOC_MIPS16_GPREL)
        && reloc->addend != 0
        && mips_need_elf_addend_fixup (fixp))
      reloc->addend += S_GET_VALUE (fixp->fx_addsy);
Index: gas/testsuite/gas/mips/mips.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/mips.exp,v
retrieving revision 1.37
diff -c -d -p -r1.37 mips.exp
*** gas/testsuite/gas/mips/mips.exp	14 Jun 2002 14:08:54 -0000	1.37
--- gas/testsuite/gas/mips/mips.exp	29 Jul 2002 11:02:24 -0000
*************** if { [istarget mips*-*-*] } then {
*** 202,207 ****
--- 202,208 ----
  	    run_dump_test "e32-rel4"
  	}
  	run_dump_test "elf-rel5"
+ 	run_dump_test "elf-rel6"
  	run_dump_test "${tmips}${el}empic"
  	run_dump_test "empic2"
  	run_dump_test "empic3_e"
*** /dev/null	Tue Nov 14 21:44:43 2000
--- gas/testsuite/gas/mips/elf-rel6.d	Mon Jul 29 12:01:59 2002
***************
*** 0 ****
--- 1,10 ----
+ #objdump: -dr --prefix-addresses
+ #name: MIPS ELF reloc 6
+ 
+ .*: +file format elf.*mips.*
+ 
+ Disassembly of section \.text:
+ 0+00 <.*> lb	v0,0\(v1\)
+ 			0: R_MIPS16_GPREL	bar
+ 0+04 <.*> lb	v0,1\(v1\)
+ 			4: R_MIPS16_GPREL	bar
*** /dev/null	Tue Nov 14 21:44:43 2000
--- gas/testsuite/gas/mips/elf-rel6.s	Mon Jul 29 12:01:59 2002
***************
*** 0 ****
--- 1,16 ----
+ 	.sdata
+ 	.global	foo
+ 	.globl	bar
+ foo:	.byte	1
+ 	.byte	2
+ bar:	.byte	3
+ 	.byte	4
+ 
+ 	.text
+ 	.set mips16
+ 	.global	f
+ 	.ent	f
+ f:
+ 	lb	$2,%gprel(bar)($3)
+ 	lb	$2,%gprel(bar+1)($3)
+ 	.end	f


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