This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
MIPS patch to fix explicit reloc abort
- From: Richard Sandiford <rsandifo at redhat dot com>
- To: binutils at sources dot redhat dot com
- Cc: echristo at redhat dot com
- Date: 20 Feb 2003 23:02:18 +0000
- Subject: MIPS patch to fix explicit reloc abort
In my previous patch, I overlooked a case in which tc_gen_reloc()
could get confused by explicit relocs. Hopefully the comment
explains the problem.
Tested on:
mips64-elf mips64el-linux-gnu mips64-linux-gnu mips64vrel-elf
mips-ecoff mips-elf mipsel-linux-gnu mips-linux-gnu mips-sgi-irix6.5
OK to install?
Richard
gas/
* config/tc-mips.c (prev_reloc_op_frag): New variable.
(macro): Check it to decide whether a new frag is needed.
(my_getSmallExpression): Set it.
gas/testsuite/
* gas/mips/elf-rel14.[sd]: New test.
* gas/mips/mips.exp: Run it.
Index: config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.192
diff -c -d -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.192 tc-mips.c
*** config/tc-mips.c 8 Feb 2003 17:05:54 -0000 1.192
--- config/tc-mips.c 20 Feb 2003 21:49:20 -0000
*************** struct mips_hi_fixup
*** 555,560 ****
--- 555,565 ----
static struct mips_hi_fixup *mips_hi_fixup_list;
+ /* The frag in which the last explicit relocation operator was generated.
+ Null if explicit relocations have not been used. */
+
+ static fragS *prev_reloc_op_frag;
+
/* Map normal MIPS register numbers to mips16 register numbers. */
#define X ILLEGAL_REG
*************** macro (ip)
*** 4106,4115 ****
#2. This would confuse tc_gen_reloc, which expects the relocations
for #2 to be the last for that frag.
! If it looks like this situation could happen, put the macro
! in a new frag. */
! if (mips_hi_fixup_list != 0
! && mips_hi_fixup_list->fixp->fx_frag == frag_now)
{
frag_wane (frag_now);
frag_new (0);
--- 4111,4123 ----
#2. This would confuse tc_gen_reloc, which expects the relocations
for #2 to be the last for that frag.
! Also, if tc_gen_reloc sees certain relocations in a variant frag,
! it assumes that they belong to a relaxable macro. We mustn't put
! other uses of such relocations into a variant frag.
!
! To avoid both problems, finish the current frag it contains a
! %reloc() operator. The macro then goes into a new frag. */
! if (prev_reloc_op_frag == frag_now)
{
frag_wane (frag_now);
frag_new (0);
*************** my_getSmallExpression (ep, reloc, str)
*** 10103,10111 ****
expr_end = str;
! reloc[0] = BFD_RELOC_LO16;
! for (i = 0; i < reloc_index; i++)
! reloc[i] = reversed_reloc[reloc_index - 1 - i];
return reloc_index;
}
--- 10111,10124 ----
expr_end = str;
! if (reloc_index == 0)
! reloc[0] = BFD_RELOC_LO16;
! else
! {
! prev_reloc_op_frag = frag_now;
! for (i = 0; i < reloc_index; i++)
! reloc[i] = reversed_reloc[reloc_index - 1 - i];
! }
return reloc_index;
}
Index: testsuite/gas/mips/mips.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/mips.exp,v
retrieving revision 1.61
diff -c -d -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.61 mips.exp
*** testsuite/gas/mips/mips.exp 8 Feb 2003 17:05:55 -0000 1.61
--- testsuite/gas/mips/mips.exp 20 Feb 2003 21:49:20 -0000
*************** if { [istarget mips*-*-*] } then {
*** 610,615 ****
--- 610,616 ----
}
run_dump_test "elf-rel12"
run_dump_test "elf-rel13"
+ run_dump_test "elf-rel14"
run_dump_test "${tmips}${el}empic"
run_dump_test "empic2"
run_dump_test "empic3_e"
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gas/mips/elf-rel14.d Thu Feb 20 21:18:03 2003
***************
*** 0 ****
--- 1,18 ----
+ #as: -march=mips1 -mabi=32 -KPIC
+ #objdump: -M gpr-names=numeric -dr
+ #name: MIPS ELF reloc 14
+
+ .*: file format .*
+
+ Disassembly of section \.text:
+
+ 0+00 <foo>:
+ 0: 8f840000 lw \$4,0\(\$28\)
+ 0: R_MIPS_CALL16 bar
+ 4: 8f850000 lw \$5,0\(\$28\)
+ 4: R_MIPS_GOT16 \.text
+ 8: 00000000 nop
+ c: 24a50014 addiu \$5,\$5,20
+ c: R_MIPS_LO16 \.text
+ 10: 24c60001 addiu \$6,\$6,1
+ \.\.\.
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gas/mips/elf-rel14.s Thu Feb 20 21:21:27 2003
***************
*** 0 ****
--- 1,10 ----
+ .ent foo
+ foo:
+ lw $4,%call16(bar)($28)
+ la $5,.L1
+ # Insert an instruction that doesn't use $5 to avoid a spurious
+ # nop after the previous load macro.
+ addiu $6,$6,1
+ .L1:
+ .space 32
+ .end foo