This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
MIPS patch for relocs against merged sections
- From: Richard Sandiford <rsandifo at redhat dot com>
- To: binutils at sources dot redhat dot com
- Cc: echristo at redhat dot com
- Date: 16 Oct 2002 16:10:02 +0100
- Subject: MIPS patch for relocs against merged sections
The test case:
------------------------------------------------------------
.section .barsec,"aM",@progbits,8
.word 0,1
bar: .word 2,3
.text
foo: lw $4,bar+4
------------------------------------------------------------
produces:
------------------------------------------------------------
Disassembly of section .text:
00000000 <foo>:
0: 3c040000 lui a0,0x0
0: R_MIPS_HI16 bar
4: 8c840014 lw a0,20(a0)
4: R_MIPS_LO16 bar
------------------------------------------------------------
where the LO16 addend is wrong.
I don't claim to understand md_apply_fix3, but it appears to
assume that relocs against local symbols in a merged section
will always be adjusted to be against the section symbol.
adjust_reloc_syms says:
/* Never adjust a reloc against local symbol in a merge section
with non-zero addend. */
if ((symsec->flags & SEC_MERGE) != 0 && fixp->fx_offset != 0)
continue;
and that's the case which goes haywire.
The short-sighted fix is simply to add this case to
mips_elf_need_addend_fixup(). Would really appreciate
other eyes looking at it, though.
Tested on mips64-elf, fixes test case, no regressions.
I've added a few other tests as well, including for the
dreaded addend = symbol value case.
Richard
PS. Looking forward to Alan's bfd_install_relocation rewrite. ;)
* config/tc-mips.c (mips_need_elf_addend_fixup): Return true
for relocs against symbols in a merged section.
testsuite/
* gas/mips/elf-rel7.[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.173
diff -u -d -p -r1.173 tc-mips.c
--- config/tc-mips.c 13 Oct 2002 21:22:49 -0000 1.173
+++ config/tc-mips.c 16 Oct 2002 14:49:32 -0000
@@ -10967,7 +10967,7 @@ mips_need_elf_addend_fixup (fixP)
if (symbol_used_in_reloc_p (fixP->fx_addsy)
&& (((bfd_get_section_flags (stdoutput,
S_GET_SEGMENT (fixP->fx_addsy))
- & SEC_LINK_ONCE) != 0)
+ & (SEC_LINK_ONCE | SEC_MERGE)) != 0)
|| !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
".gnu.linkonce",
sizeof (".gnu.linkonce") - 1)))
Index: testsuite/gas/mips/mips.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/mips.exp,v
retrieving revision 1.49
diff -u -d -p -r1.49 mips.exp
--- testsuite/gas/mips/mips.exp 12 Oct 2002 05:23:46 -0000 1.49
+++ testsuite/gas/mips/mips.exp 16 Oct 2002 14:49:32 -0000
@@ -220,6 +220,7 @@ if { [istarget mips*-*-*] } then {
}
run_dump_test "elf-rel5"
run_dump_test "elf-rel6"
+ run_dump_test "elf-rel7"
run_dump_test "${tmips}${el}empic"
run_dump_test "empic2"
run_dump_test "empic3_e"
--- /dev/null Tue Nov 14 21:44:43 2000
+++ testsuite/gas/mips/elf-rel7.d Wed Oct 16 15:22:21 2002
@@ -0,0 +1,31 @@
+#objdump: -dr --prefix-addresses
+#name: MIPS ELF reloc 7
+
+.*: +file format elf.*mips.*
+
+Disassembly of section \.text:
+0+00 <.*> lui a0,0x0
+ 0: R_MIPS_HI16 .barsec
+0+04 <.*> lw a0,8\(a0\)
+ 4: R_MIPS_LO16 .barsec
+0+08 <.*> lui a0,0x0
+ 8: R_MIPS_HI16 bar
+0+0c <.*> lw a0,4\(a0\)
+ c: R_MIPS_LO16 bar
+0+10 <.*> lui a0,0x0
+ 10: R_MIPS_HI16 bar
+0+14 <.*> lw a0,8\(a0\)
+ 14: R_MIPS_LO16 bar
+0+18 <.*> lui a0,0x0
+ 18: R_MIPS_HI16 frob
+0+1c <.*> lw a0,0\(a0\)
+ 1c: R_MIPS_LO16 frob
+0+20 <.*> lui a0,0x0
+ 20: R_MIPS_HI16 frob
+0+24 <.*> lw a0,4\(a0\)
+ 24: R_MIPS_LO16 frob
+0+28 <.*> lui a0,0x0
+ 28: R_MIPS_HI16 frob
+0+2c <.*> lw a0,16\(a0\)
+ 2c: R_MIPS_LO16 frob
+#pass
--- /dev/null Tue Nov 14 21:44:43 2000
+++ testsuite/gas/mips/elf-rel7.s Wed Oct 16 15:16:30 2002
@@ -0,0 +1,12 @@
+ .global frob
+ .section .barsec,"aM",@progbits,8
+ .word 0,1
+bar: .word 2,3
+frob: .word 4,5
+ .text
+foo: lw $4,bar
+ lw $4,bar+4
+ lw $4,bar+8
+ lw $4,frob
+ lw $4,frob+4
+ lw $4,frob+16