* [PATCH] Fix handling of R_MIPS_PC16 relocations
@ 2001-08-26 14:30 Thiemo Seufer
2001-09-06 16:00 ` Thiemo Seufer
0 siblings, 1 reply; 5+ messages in thread
From: Thiemo Seufer @ 2001-08-26 14:30 UTC (permalink / raw)
To: binutils
Hi All,
when I compared the MIPS ELF64 spec with the actual code in binutils,
I found the R_MIPS_PC16 relocation to be wrongly implemented. I found
also a R_MIPS_GNU_REL16_S2 relocation which behaves exactly as
R_MIPS_PC16 should do, which was seemingly invented to support
embedded PIC.
The AFAICS only way to get such a reloc (except by embedded PIC)
is via a branch to an external label. There is no such test in
binutils, and gcc doesn't seem to use it also, so this feature
was possibly never used. The native SGI assembler handles this
even simpler: branches to external labels are illegal there.
I haven't found a way to get a R_MIPS_PC16 reloc with the
native tools on IRIX.
The potential problem with this patch: There is no good way to
distinguish R_MIPS_PC16 from R_MIPS_GNU_REL16_S2 because both
are mapped to BFD_RELOC_16_PCREL_S2. This means new embedded
PIC objects will use R_MIPS_PC16 instead of the GNU extension.
Old embedded PIC objects can be read, though.
I extended the branch testcases accordingly and tested it for
mips-elf, mips64el-elf and mips64-linux.
Thiemo
2001-08-21 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
/bfd/ChangeLog (elf_mips_howto_table): Fix rightshift for R_MIPS_PC16.
(mips_reloc_map): Map R_MIPS_PC16 to the BFD_RELOC_16_PCREL_S2.
(mips_elf_calculate_relocation): Fix handling of R_MIPS_PC16.
(_bfd_mips_elf_relocate_section): Likewise.
/gas/ChangeLog
* config/tc-mips.c (tc_gen_reloc): Allow BFD_RELOC_16_PCREL_S2.
/gas/testsuite/ChangeLog
* gas/mips/beq.d: Check branches to external labels.
* gas/mips/beq.s: Likewise.
* gas/mips/bge.d: Likewise.
* gas/mips/bge.s: Likewise.
* gas/mips/bgeu.d: Likewise.
* gas/mips/bgeu.s: Likewise.
* gas/mips/blt.d: Likewise.
* gas/mips/blt.s: Likewise.
* gas/mips/bltu.d: Likewise.
* gas/mips/bltu.s: Likewise.
* gas/mips/elempic.d: Switch from R_MIPS_GNU_REL16_S2 to R_MIPS_PC16.
* gas/mips/empic.d: Likewise.
* gas/mips/empic.s: Likewise.
* gas/mips/telempic.d: Likewise.
* gas/mips/tempic.d: Likewise.
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/bfd/elf32-mips.c src/bfd/elf32-mips.c
--- src-orig/bfd/elf32-mips.c Wed Jul 4 13:55:24 2001
+++ src/bfd/elf32-mips.c Tue Aug 21 18:15:03 2001
@@ -638,7 +639,7 @@ static reloc_howto_type elf_mips_howto_t
/* 16 bit PC relative reference. */
HOWTO (R_MIPS_PC16, /* type */
- 0, /* rightshift */
+ 2, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
true, /* pc_relative */
@@ -1970,7 +1971,7 @@ static CONST struct elf_reloc_map mips_r
{ BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
{ BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
{ BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
- { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
+ { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
{ BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
{ BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 },
{ BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
@@ -6357,6 +6358,7 @@ mips_elf_calculate_relocation (abfd,
break;
case R_MIPS_GNU_REL16_S2:
+ case R_MIPS_PC16:
value = symbol + mips_elf_sign_extend (addend << 2, 18) - p;
overflowed_p = mips_elf_overflow_p (value, 18);
value = (value >> 2) & howto->dst_mask;
@@ -6473,12 +6475,6 @@ mips_elf_calculate_relocation (abfd,
value = (addend + symbol + gp0 - gp) & howto->dst_mask;
break;
- case R_MIPS_PC16:
- value = mips_elf_sign_extend (addend, 16) + symbol - p;
- value = (bfd_vma) ((bfd_signed_vma) value / 4);
- overflowed_p = mips_elf_overflow_p (value, 16);
- break;
-
case R_MIPS_GOT_HI16:
case R_MIPS_CALL_HI16:
/* We're allowed to handle these two relocations identically.
@@ -6932,7 +6928,7 @@ _bfd_mips_elf_relocate_section (output_b
addend -= (_bfd_get_gp_value (output_bfd)
- _bfd_get_gp_value (input_bfd));
else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
- || r_type == R_MIPS_GNU_REL16_S2)
+ || r_type == R_MIPS_GNU_REL16_S2 || r_type == R_MIPS_PC16)
/* The addend is stored without its two least
significant bits (which are always zero.) In a
non-relocateable link, calculate_relocation will do
@@ -6955,7 +6951,7 @@ _bfd_mips_elf_relocate_section (output_b
the two low-order bits are not stored in the object file;
they are implicitly zero. */
else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26
- || r_type == R_MIPS_GNU_REL16_S2)
+ || r_type == R_MIPS_GNU_REL16_S2 || r_type == R_MIPS_PC16)
addend >>= 2;
if (rela_relocation_p)
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/config/tc-mips.c src/gas/config/tc-mips.c
--- src-orig/gas/config/tc-mips.c Tue Aug 21 19:13:58 2001
+++ src/gas/config/tc-mips.c Fri Aug 24 22:30:21 2001
@@ -11369,17 +11662,7 @@ tc_gen_reloc (section, fixp)
}
}
- /* To support a PC relative reloc when generating embedded PIC code
- for ECOFF, we use a Cygnus extension. We check for that here to
- make sure that we don't let such a reloc escape normally. */
- if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
- || OUTPUT_FLAVOR == bfd_target_elf_flavour)
- && code == BFD_RELOC_16_PCREL_S2
- && mips_pic != EMBEDDED_PIC)
- reloc->howto = NULL;
- else
- reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
-
+ reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
if (reloc->howto == NULL)
{
as_bad_where (fixp->fx_file, fixp->fx_line,
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/beq.d src/gas/testsuite/gas/mips/beq.d
--- src-orig/gas/testsuite/gas/mips/beq.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/beq.d Tue Aug 21 17:25:46 2001
@@ -37,4 +37,10 @@ Disassembly of section .text:
0+2006c <[^>]*> nop
0+20070 <[^>]*> jal 0+0000 <text_label>
[ ]*20070: (MIPS_JMP|JMPADDR|R_MIPS_26) .text
+0+20074 <[^>]*> nop
+0+20078 <[^>]*> b 0+20078 <text_label\+0x20078>
+[ ]*20078: R_MIPS_PC16 external_label
+0+2007c <[^>]*> nop
+0+20080 <[^>]*> bal 0+20080 <text_label\+0x20080>
+[ ]*20080: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/beq.s src/gas/testsuite/gas/mips/beq.s
--- src-orig/gas/testsuite/gas/mips/beq.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/beq.s Tue Aug 21 17:49:33 2001
@@ -22,6 +22,10 @@ text_label:
b text_label
bal text_label
+# Branch to an external label.
+ b external_label
+ bal external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bge.d src/gas/testsuite/gas/mips/bge.d
--- src-orig/gas/testsuite/gas/mips/bge.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/bge.d Tue Aug 21 17:41:59 2001
@@ -50,4 +50,20 @@ Disassembly of section .text:
0+00a4 <[^>]*> nop
0+00a8 <[^>]*> slt at,a1,a0
0+00ac <[^>]*> bnezl at,0+0000 <text_label>
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> slt at,a0,a1
+0+00b8 <[^>]*> beqz at,000000b8 <text_label\+0xb8>
+[ ]*b8: R_MIPS_PC16 external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> slt at,a1,a0
+0+00c4 <[^>]*> bnez at,000000c4 <text_label\+0xc4>
+[ ]*c4: R_MIPS_PC16 external_label
+0+00c8 <[^>]*> nop
+0+00cc <[^>]*> slt at,a0,a1
+0+00d0 <[^>]*> beqzl at,000000d0 <text_label\+0xd0>
+[ ]*d0: R_MIPS_PC16 external_label
+0+00d4 <[^>]*> nop
+0+00d8 <[^>]*> slt at,a1,a0
+0+00dc <[^>]*> bnezl at,000000dc <text_label\+0xdc>
+[ ]*dc: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bge.s src/gas/testsuite/gas/mips/bge.s
--- src-orig/gas/testsuite/gas/mips/bge.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/bge.s Tue Aug 21 17:48:35 2001
@@ -24,6 +24,12 @@ text_label:
bgel $4,$5,text_label
bgtl $4,$5,text_label
+# Branch to an external label.
+ bge $4,$5,external_label
+ bgt $4,$5,external_label
+ bgel $4,$5,external_label
+ bgtl $4,$5,external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bgeu.d src/gas/testsuite/gas/mips/bgeu.d
--- src-orig/gas/testsuite/gas/mips/bgeu.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/bgeu.d Tue Aug 21 18:12:13 2001
@@ -44,4 +44,20 @@ Disassembly of section .text:
0+008c <[^>]*> nop
0+0090 <[^>]*> sltu at,a1,a0
0+0094 <[^>]*> bnezl at,0+0000 <text_label>
+0+0098 <[^>]*> nop
+0+009c <[^>]*> sltu at,a0,a1
+0+00a0 <[^>]*> beqz at,000000a0 <text_label\+0xa0>
+[ ]*a0: R_MIPS_PC16 external_label
+0+00a4 <[^>]*> nop
+0+00a8 <[^>]*> sltu at,a1,a0
+0+00ac <[^>]*> bnez at,000000ac <text_label\+0xac>
+[ ]*ac: R_MIPS_PC16 external_label
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> sltu at,a0,a1
+0+00b8 <[^>]*> beqzl at,000000b8 <text_label\+0xb8>
+[ ]*b8: R_MIPS_PC16 external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> sltu at,a1,a0
+0+00c4 <[^>]*> bnezl at,000000c4 <text_label\+0xc4>
+[ ]*c4: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bgeu.s src/gas/testsuite/gas/mips/bgeu.s
--- src-orig/gas/testsuite/gas/mips/bgeu.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/bgeu.s Tue Aug 21 17:57:36 2001
@@ -22,6 +22,12 @@ text_label:
bgeul $4,$5,text_label
bgtul $4,$5,text_label
+# Branch to an external label.
+ bgeu $4,$5,external_label
+ bgtu $4,$5,external_label
+ bgeul $4,$5,external_label
+ bgtul $4,$5,external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/blt.d src/gas/testsuite/gas/mips/blt.d
--- src-orig/gas/testsuite/gas/mips/blt.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/blt.d Tue Aug 21 17:52:50 2001
@@ -50,4 +50,20 @@ Disassembly of section .text:
0+00a4 <[^>]*> nop
0+00a8 <[^>]*> slt at,a1,a0
0+00ac <[^>]*> beqzl at,0+0000 <text_label>
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> slt at,a0,a1
+0+00b8 <[^>]*> bnez at,000000b8 <text_label\+0xb8>
+[ ]*b8: R_MIPS_PC16 external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> slt at,a1,a0
+0+00c4 <[^>]*> beqz at,000000c4 <text_label\+0xc4>
+[ ]*c4: R_MIPS_PC16 external_label
+0+00c8 <[^>]*> nop
+0+00cc <[^>]*> slt at,a0,a1
+0+00d0 <[^>]*> bnezl at,000000d0 <text_label\+0xd0>
+[ ]*d0: R_MIPS_PC16 external_label
+0+00d4 <[^>]*> nop
+0+00d8 <[^>]*> slt at,a1,a0
+0+00dc <[^>]*> beqzl at,000000dc <text_label\+0xdc>
+[ ]*dc: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/blt.s src/gas/testsuite/gas/mips/blt.s
--- src-orig/gas/testsuite/gas/mips/blt.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/blt.s Tue Aug 21 17:49:12 2001
@@ -24,6 +24,12 @@ text_label:
bltl $4,$5,text_label
blel $4,$5,text_label
+# Branch to an external label.
+ blt $4,$5,external_label
+ ble $4,$5,external_label
+ bltl $4,$5,external_label
+ blel $4,$5,external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bltu.d src/gas/testsuite/gas/mips/bltu.d
--- src-orig/gas/testsuite/gas/mips/bltu.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/bltu.d Tue Aug 21 18:05:47 2001
@@ -44,4 +44,20 @@ Disassembly of section .text:
0+008c <[^>]*> nop
0+0090 <[^>]*> sltu at,a1,a0
0+0094 <[^>]*> beqzl at,0+0000 <text_label>
+0+0098 <[^>]*> nop
+0+009c <[^>]*> sltu at,a0,a1
+0+00a0 <[^>]*> bnez at,000000a0 <text_label\+0xa0>
+[ ]*a0: R_MIPS_PC16 external_label
+0+00a4 <[^>]*> nop
+0+00a8 <[^>]*> sltu at,a1,a0
+0+00ac <[^>]*> beqz at,000000ac <text_label\+0xac>
+[ ]*ac: R_MIPS_PC16 external_label
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> sltu at,a0,a1
+0+00b8 <[^>]*> bnezl at,000000b8 <text_label\+0xb8>
+[ ]*b8: R_MIPS_PC16 external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> sltu at,a1,a0
+0+00c4 <[^>]*> beqzl at,000000c4 <text_label\+0xc4>
+[ ]*c4: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bltu.s src/gas/testsuite/gas/mips/bltu.s
--- src-orig/gas/testsuite/gas/mips/bltu.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/bltu.s Tue Aug 21 18:03:14 2001
@@ -22,6 +22,12 @@ text_label:
bltul $4,$5,text_label
bleul $4,$5,text_label
+# Branch to an external label.
+ bltu $4,$5,external_label
+ bleu $4,$5,external_label
+ bltul $4,$5,external_label
+ bleul $4,$5,external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/elempic.d src/gas/testsuite/gas/mips/elempic.d
--- src-orig/gas/testsuite/gas/mips/elempic.d Sat Aug 25 02:48:49 2001
+++ src/gas/testsuite/gas/mips/elempic.d Sat Aug 25 05:31:22 2001
@@ -25,13 +25,13 @@
RELOCATION RECORDS FOR \[\.text\]:
OFFSET [ ]+ TYPE VALUE
-0+0000004 R_MIPS_GNU_REL16_S2 g1
-0+000000c R_MIPS_GNU_REL16_S2 g2
-0+0000014 R_MIPS_GNU_REL16_S2 g2
-0+000001c R_MIPS_GNU_REL16_S2 \.foo
-0+0000024 R_MIPS_GNU_REL16_S2 \.text
-0+000002c R_MIPS_GNU_REL16_S2 \.foo
-0+0000034 R_MIPS_GNU_REL16_S2 \.text
+0+0000004 R_MIPS_PC16 g1
+0+000000c R_MIPS_PC16 g2
+0+0000014 R_MIPS_PC16 g2
+0+000001c R_MIPS_PC16 \.foo
+0+0000024 R_MIPS_PC16 \.text
+0+000002c R_MIPS_PC16 \.foo
+0+0000034 R_MIPS_PC16 \.text
0+000003c R_MIPS_GNU_REL_HI16 g1
0+0000040 R_MIPS_GNU_REL_LO16 g1
0+0000044 R_MIPS_GNU_REL_HI16 \.foo
@@ -46,16 +46,16 @@
0+0000078 R_MIPS_64 \.text
0+0000080 R_MIPS_PC64 g1
0+0000088 R_MIPS_PC64 \.foo
-0+0000098 R_MIPS_GNU_REL16_S2 \.text
-0+000009c R_MIPS_GNU_REL16_S2 \.text
+0+0000098 R_MIPS_PC16 \.text
+0+000009c R_MIPS_PC16 \.text
0+00000a0 R_MIPS_GNU_REL_HI16 \.text
0+00000a4 R_MIPS_GNU_REL_LO16 \.text
0+00000a8 R_MIPS_GNU_REL_HI16 \.text
0+00000ac R_MIPS_GNU_REL_LO16 \.text
0+00000b0 R_MIPS_32 \.text
0+00000b8 R_MIPS_64 \.text
-0+00000cc R_MIPS_GNU_REL16_S2 \.text
-0+00000d0 R_MIPS_GNU_REL16_S2 \.text
+0+00000cc R_MIPS_PC16 \.text
+0+00000d0 R_MIPS_PC16 \.text
0+00000dc R_MIPS_32 \.text
0+00000e8 R_MIPS_64 \.text
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/empic.d src/gas/testsuite/gas/mips/empic.d
--- src-orig/gas/testsuite/gas/mips/empic.d Sun Aug 12 13:34:58 2001
+++ src/gas/testsuite/gas/mips/empic.d Mon Aug 20 05:41:20 2001
@@ -24,13 +24,13 @@ SYMBOL TABLE:
RELOCATION RECORDS FOR \[\.text\]:
OFFSET [ ]+ TYPE VALUE
-0+0000004 R_MIPS_GNU_REL16_S2 g1
-0+000000c R_MIPS_GNU_REL16_S2 g2
-0+0000014 R_MIPS_GNU_REL16_S2 g2
-0+000001c R_MIPS_GNU_REL16_S2 \.foo
-0+0000024 R_MIPS_GNU_REL16_S2 \.text
-0+000002c R_MIPS_GNU_REL16_S2 \.foo
-0+0000034 R_MIPS_GNU_REL16_S2 \.text
+0+0000004 R_MIPS_PC16 g1
+0+000000c R_MIPS_PC16 g2
+0+0000014 R_MIPS_PC16 g2
+0+000001c R_MIPS_PC16 \.foo
+0+0000024 R_MIPS_PC16 \.text
+0+000002c R_MIPS_PC16 \.foo
+0+0000034 R_MIPS_PC16 \.text
0+000003c R_MIPS_GNU_REL_HI16 g1
0+0000040 R_MIPS_GNU_REL_LO16 g1
0+0000044 R_MIPS_GNU_REL_HI16 \.foo
@@ -45,16 +45,16 @@ OFFSET [ ]+ TYPE VALUE
0+0000078 R_MIPS_64 \.text
0+0000080 R_MIPS_PC64 g1
0+0000088 R_MIPS_PC64 \.foo
-0+0000098 R_MIPS_GNU_REL16_S2 \.text
-0+000009c R_MIPS_GNU_REL16_S2 \.text
+0+0000098 R_MIPS_PC16 \.text
+0+000009c R_MIPS_PC16 \.text
0+00000a0 R_MIPS_GNU_REL_HI16 \.text
0+00000a4 R_MIPS_GNU_REL_LO16 \.text
0+00000a8 R_MIPS_GNU_REL_HI16 \.text
0+00000ac R_MIPS_GNU_REL_LO16 \.text
0+00000b0 R_MIPS_32 \.text
0+00000b8 R_MIPS_64 \.text
-0+00000cc R_MIPS_GNU_REL16_S2 \.text
-0+00000d0 R_MIPS_GNU_REL16_S2 \.text
+0+00000cc R_MIPS_PC16 \.text
+0+00000d0 R_MIPS_PC16 \.text
0+00000dc R_MIPS_32 \.text
0+00000e8 R_MIPS_64 \.text
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/empic.s src/gas/testsuite/gas/mips/empic.s
--- src-orig/gas/testsuite/gas/mips/empic.s Wed Dec 13 02:59:48 2000
+++ src/gas/testsuite/gas/mips/empic.s Mon Aug 20 05:51:44 2001
@@ -3,20 +3,20 @@
.text
.set noreorder
nop
-l2: jal g1 # R_MIPS_GNU_REL16_S2 g1 -1
+l2: jal g1 # R_MIPS_PC16 g1 -1
nop
- b g2 # R_MIPS_GNU_REL16_S2 g2 -1
+ b g2 # R_MIPS_PC16 g2 -1
nop
- b g2 # R_MIPS_GNU_REL16_S2 g2 -1
+ b g2 # R_MIPS_PC16 g2 -1
nop
- jal l1 # R_MIPS_GNU_REL16_S2 .foo 3F
+ jal l1 # R_MIPS_PC16 .foo 3F
nop
- jal l2 # R_MIPS_GNU_REL16_S2 .text 0 or -9
+ jal l2 # R_MIPS_PC16 .text 0 or -9
nop
- b l1+8 # R_MIPS_GNU_REL16_S2 .foo 41
+ b l1+8 # R_MIPS_PC16 .foo 41
nop
l3:
- b l2 # R_MIPS_GNU_REL16_S2 .text 0 or -D
+ b l2 # R_MIPS_PC16 .text 0 or -D
nop
la $3,g1-l3 # R_MIPS_GNU_REL_HI16 g1 0
# R_MIPS_GNU_REL_LO16 g1 C
@@ -37,8 +37,8 @@ l3:
.dword l1-l3 # R_MIPS_PC64 .foo 154
.dword l2-l3 # -30
l5:
- b 2f # R_MIPS_GNU_REL16_S2 .text 32
- b 2f+4 # R_MIPS_GNU_REL16_S2 .text 33
+ b 2f # R_MIPS_PC16 .text 32
+ b 2f+4 # R_MIPS_PC16 .text 33
la $3,2f-l5 # R_MIPS_GNU_REL_HI16 .text 0
# R_MIPS_GNU_REL_LO16 .text D8
la $3,2f+8-l5 # R_MIPS_GNU_REL_HI16 .text 0
@@ -51,8 +51,8 @@ l5:
.dword 2f-l5 # R_MIPS_PC64 .text F8 or 34
nop
2: # at address 0xCC.
- b 2b # R_MIPS_GNU_REL16_S2 .text 32
- b 2b+4 # R_MIPS_GNU_REL16_S2 .text 33
+ b 2b # R_MIPS_PC16 .text 32
+ b 2b+4 # R_MIPS_PC16 .text 33
la $3,2b-l5 # 34
la $3,2b+8-l5 # 3C
.word 2b # R_MIPS_32 .text CC
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/telempic.d src/gas/testsuite/gas/mips/telempic.d
--- src-orig/gas/testsuite/gas/mips/telempic.d Sun Aug 12 13:35:04 2001
+++ src/gas/testsuite/gas/mips/telempic.d Mon Aug 20 05:48:02 2001
@@ -25,13 +25,13 @@ SYMBOL TABLE:
RELOCATION RECORDS FOR \[\.text\]:
OFFSET [ ]+ TYPE VALUE
-0+0000004 R_MIPS_GNU_REL16_S2 g1
-0+000000c R_MIPS_GNU_REL16_S2 g2
-0+0000014 R_MIPS_GNU_REL16_S2 g2
-0+000001c R_MIPS_GNU_REL16_S2 \.foo
-0+0000024 R_MIPS_GNU_REL16_S2 \.text
-0+000002c R_MIPS_GNU_REL16_S2 \.foo
-0+0000034 R_MIPS_GNU_REL16_S2 \.text
+0+0000004 R_MIPS_PC16 g1
+0+000000c R_MIPS_PC16 g2
+0+0000014 R_MIPS_PC16 g2
+0+000001c R_MIPS_PC16 \.foo
+0+0000024 R_MIPS_PC16 \.text
+0+000002c R_MIPS_PC16 \.foo
+0+0000034 R_MIPS_PC16 \.text
0+000003c R_MIPS_GNU_REL_HI16 g1
0+0000040 R_MIPS_GNU_REL_LO16 g1
0+0000044 R_MIPS_GNU_REL_HI16 \.foo
@@ -46,16 +46,16 @@ OFFSET [ ]+ TYPE VALUE
0+0000078 R_MIPS_64 \.text
0+0000080 R_MIPS_PC64 g1
0+0000088 R_MIPS_PC64 \.foo
-0+0000098 R_MIPS_GNU_REL16_S2 \.text
-0+000009c R_MIPS_GNU_REL16_S2 \.text
+0+0000098 R_MIPS_PC16 \.text
+0+000009c R_MIPS_PC16 \.text
0+00000a0 R_MIPS_GNU_REL_HI16 \.text
0+00000a4 R_MIPS_GNU_REL_LO16 \.text
0+00000a8 R_MIPS_GNU_REL_HI16 \.text
0+00000ac R_MIPS_GNU_REL_LO16 \.text
0+00000b0 R_MIPS_32 \.text
0+00000b8 R_MIPS_64 \.text
-0+00000cc R_MIPS_GNU_REL16_S2 \.text
-0+00000d0 R_MIPS_GNU_REL16_S2 \.text
+0+00000cc R_MIPS_PC16 \.text
+0+00000d0 R_MIPS_PC16 \.text
0+00000dc R_MIPS_32 \.text
0+00000e8 R_MIPS_64 \.text
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/tempic.d src/gas/testsuite/gas/mips/tempic.d
--- src-orig/gas/testsuite/gas/mips/tempic.d Sun Aug 12 13:35:04 2001
+++ src/gas/testsuite/gas/mips/tempic.d Mon Aug 20 05:55:37 2001
@@ -25,13 +25,13 @@ SYMBOL TABLE:
RELOCATION RECORDS FOR \[\.text\]:
OFFSET [ ]+ TYPE VALUE
-0+0000004 R_MIPS_GNU_REL16_S2 g1
-0+000000c R_MIPS_GNU_REL16_S2 g2
-0+0000014 R_MIPS_GNU_REL16_S2 g2
-0+000001c R_MIPS_GNU_REL16_S2 \.foo
-0+0000024 R_MIPS_GNU_REL16_S2 \.text
-0+000002c R_MIPS_GNU_REL16_S2 \.foo
-0+0000034 R_MIPS_GNU_REL16_S2 \.text
+0+0000004 R_MIPS_PC16 g1
+0+000000c R_MIPS_PC16 g2
+0+0000014 R_MIPS_PC16 g2
+0+000001c R_MIPS_PC16 \.foo
+0+0000024 R_MIPS_PC16 \.text
+0+000002c R_MIPS_PC16 \.foo
+0+0000034 R_MIPS_PC16 \.text
0+000003c R_MIPS_GNU_REL_HI16 g1
0+0000040 R_MIPS_GNU_REL_LO16 g1
0+0000044 R_MIPS_GNU_REL_HI16 \.foo
@@ -46,16 +46,16 @@ OFFSET [ ]+ TYPE VALUE
0+0000078 R_MIPS_64 \.text
0+0000080 R_MIPS_PC64 g1
0+0000088 R_MIPS_PC64 \.foo
-0+0000098 R_MIPS_GNU_REL16_S2 \.text
-0+000009c R_MIPS_GNU_REL16_S2 \.text
+0+0000098 R_MIPS_PC16 \.text
+0+000009c R_MIPS_PC16 \.text
0+00000a0 R_MIPS_GNU_REL_HI16 \.text
0+00000a4 R_MIPS_GNU_REL_LO16 \.text
0+00000a8 R_MIPS_GNU_REL_HI16 \.text
0+00000ac R_MIPS_GNU_REL_LO16 \.text
0+00000b0 R_MIPS_32 \.text
0+00000b8 R_MIPS_64 \.text
-0+00000cc R_MIPS_GNU_REL16_S2 \.text
-0+00000d0 R_MIPS_GNU_REL16_S2 \.text
+0+00000cc R_MIPS_PC16 \.text
+0+00000d0 R_MIPS_PC16 \.text
0+00000dc R_MIPS_32 \.text
0+00000e8 R_MIPS_64 \.text
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix handling of R_MIPS_PC16 relocations
2001-08-26 14:30 [PATCH] Fix handling of R_MIPS_PC16 relocations Thiemo Seufer
@ 2001-09-06 16:00 ` Thiemo Seufer
2001-09-06 21:45 ` Eric Christopher
2001-09-12 8:40 ` Maciej W. Rozycki
0 siblings, 2 replies; 5+ messages in thread
From: Thiemo Seufer @ 2001-09-06 16:00 UTC (permalink / raw)
To: binutils
Thiemo Seufer wrote:
[snip]
> /bfd/ChangeLog (elf_mips_howto_table): Fix rightshift for R_MIPS_PC16.
> (mips_reloc_map): Map R_MIPS_PC16 to the BFD_RELOC_16_PCREL_S2.
> (mips_elf_calculate_relocation): Fix handling of R_MIPS_PC16.
> (_bfd_mips_elf_relocate_section): Likewise.
This patch was wrong. The R_MIPS_PC16 relocation actually spans an
offset of only 16 bit while the hardware (and internal branches
without a reloc) can do 18 bit. I have no explanation why this was
defined this way. The appended patch adds handling for R_MIPS_PC16
to gas and bfd. Tested for mips64-linux and mips-elf.
Thiemo
2001-09-07 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
/bfd/ChangeLog
* elf32-mips.c (mips_elf_calculate_relocation): Fix overflow handling
of R_MIPS_PC16.
/gas/ChangeLog
* config/tc-mips.c (append_insn): Handle BFD_RELOC_16_PCREL.
(macro_build): Use BFD_RELOC_16_PCREL_S2 only for embedded
PIC, BFD_RELOC_16_PCREL for the rest.
(mips_ip): Likewise.
(md_pcrel_from): return the right offset for the differently shifted
pcrel relocs.
(md_apply_fix): Handle BFD_RELOC_16_PCREL.
/gas/testsuite/ChangeLog
* gas/mips/beq.d: Check branches to external labels.
* gas/mips/beq.s: Likewise.
* gas/mips/bge.d: Likewise.
* gas/mips/bge.s: Likewise.
* gas/mips/bgeu.d: Likewise.
* gas/mips/bgeu.s: Likewise.
* gas/mips/blt.d: Likewise.
* gas/mips/blt.s: Likewise.
* gas/mips/bltu.d: Likewise.
* gas/mips/bltu.s: Likewise.
* gas/mips/elempic.d: Switch from R_MIPS_GNU_REL16_S2 to R_MIPS_PC16.
* gas/mips/empic.d: Likewise.
* gas/mips/empic.s: Likewise.
* gas/mips/telempic.d: Likewise.
* gas/mips/tempic.d: Likewise.
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/bfd/elf32-mips.c src/bfd/elf32-mips.c
--- src-orig/bfd/elf32-mips.c Fri Aug 31 21:59:55 2001
+++ src/bfd/elf32-mips.c Thu Sep 6 21:11:29 2001
@@ -6488,8 +6488,8 @@ mips_elf_calculate_relocation (abfd,
case R_MIPS_PC16:
value = mips_elf_sign_extend (addend, 16) + symbol - p;
- value = (bfd_vma) ((bfd_signed_vma) value / 4);
overflowed_p = mips_elf_overflow_p (value, 16);
+ value = (bfd_vma) ((bfd_signed_vma) value / 4);
break;
case R_MIPS_GOT_HI16:
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/config/tc-mips.c src/gas/config/tc-mips.c
--- src-orig/gas/config/tc-mips.c Fri Aug 31 22:00:08 2001
+++ src/gas/config/tc-mips.c Thu Sep 6 21:58:05 2001
@@ -1898,6 +1978,10 @@ append_insn (place, ip, address_expr, re
| ((address_expr->X_add_number & 0x3fffc) >> 2));
break;
+ case BFD_RELOC_16_PCREL:
+ ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0xffff;
+ break;
+
case BFD_RELOC_16_PCREL_S2:
goto need_reloc;
@@ -1914,7 +1998,8 @@ append_insn (place, ip, address_expr, re
{
fixp = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
address_expr,
- reloc_type == BFD_RELOC_16_PCREL_S2,
+ (reloc_type == BFD_RELOC_16_PCREL
+ || reloc_type == BFD_RELOC_16_PCREL_S2),
reloc_type);
if (unmatched_hi)
{
@@ -2699,7 +2804,10 @@ macro_build (place, counter, ep, name, f
ep = NULL;
}
else
- r = BFD_RELOC_16_PCREL_S2;
+ if (mips_pic == EMBEDDED_PIC)
+ r = BFD_RELOC_16_PCREL_S2;
+ else
+ r = BFD_RELOC_16_PCREL;
continue;
case 'a':
@@ -7791,7 +8131,10 @@ mips_ip (str, ip)
continue;
case 'p': /* pc relative offset */
- offset_reloc = BFD_RELOC_16_PCREL_S2;
+ if (mips_pic == EMBEDDED_PIC)
+ offset_reloc = BFD_RELOC_16_PCREL_S2;
+ else
+ offset_reloc = BFD_RELOC_16_PCREL;
my_getExpression (&offset_expr, s);
s = expr_end;
continue;
@@ -9427,9 +9836,16 @@ md_pcrel_from (fixP)
&& fixP->fx_addsy != (symbolS *) NULL
&& ! S_IS_DEFINED (fixP->fx_addsy))
{
- /* This makes a branch to an undefined symbol be a branch to the
- current location. */
- return 4;
+ if (mips_pic == EMBEDDED_PIC)
+ {
+ /* This makes a branch to an undefined symbol be a branch to the
+ current location. */
+ return 4;
+ }
+ else
+ {
+ return 1;
+ }
}
/* return the address of the delay slot */
@@ -9666,7 +10102,8 @@ md_apply_fix (fixP, valueP)
/* BFD's REL handling, for MIPS, is _very_ weird.
This gives the right results, but it can't possibly
be the way things are supposed to work. */
- if (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
+ if ((fixP->fx_r_type != BFD_RELOC_16_PCREL
+ && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
|| S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
value += fixP->fx_frag->fr_address + fixP->fx_where;
}
@@ -9812,15 +10268,18 @@ md_apply_fix (fixP, valueP)
break;
case BFD_RELOC_16_PCREL_S2:
+ if ((value & 0x3) != 0)
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("Branch to odd address (%lx)"), (long) value);
+
+ /* Fall through. */
+
+ case BFD_RELOC_16_PCREL:
/*
* We need to save the bits in the instruction since fixup_segment()
* might be deleting the relocation entry (i.e., a branch within
* the current segment).
*/
- if ((value & 0x3) != 0)
- as_bad_where (fixP->fx_file, fixP->fx_line,
- _("Branch to odd address (%lx)"), (long) value);
-
if (!fixP->fx_done && value != 0)
break;
/* If 'value' is zero, the remaining reloc code won't actually
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/beq.d src/gas/testsuite/gas/mips/beq.d
--- src-orig/gas/testsuite/gas/mips/beq.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/beq.d Fri Aug 31 23:01:41 2001
@@ -37,4 +37,10 @@ Disassembly of section .text:
0+2006c <[^>]*> nop
0+20070 <[^>]*> jal 0+0000 <text_label>
[ ]*20070: (MIPS_JMP|JMPADDR|R_MIPS_26) .text
+0+20074 <[^>]*> nop
+0+20078 <[^>]*> b 0+20078 <text_label\+0x20078>
+[ ]*20078: R_MIPS_PC16 external_label
+0+2007c <[^>]*> nop
+0+20080 <[^>]*> bal 0+20080 <text_label\+0x20080>
+[ ]*20080: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/beq.s src/gas/testsuite/gas/mips/beq.s
--- src-orig/gas/testsuite/gas/mips/beq.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/beq.s Fri Aug 31 23:01:41 2001
@@ -22,7 +22,9 @@ text_label:
b text_label
bal text_label
+# Branch to an external label.
+ b external_label
+ bal external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
- nop
- nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bge.d src/gas/testsuite/gas/mips/bge.d
--- src-orig/gas/testsuite/gas/mips/bge.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/bge.d Fri Aug 31 23:01:41 2001
@@ -50,4 +50,20 @@ Disassembly of section .text:
0+00a4 <[^>]*> nop
0+00a8 <[^>]*> slt at,a1,a0
0+00ac <[^>]*> bnezl at,0+0000 <text_label>
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> slt at,a0,a1
+0+00b8 <[^>]*> beqz at,000000b8 <text_label\+0xb8>
+[ ]*b8: R_MIPS_PC16 external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> slt at,a1,a0
+0+00c4 <[^>]*> bnez at,000000c4 <text_label\+0xc4>
+[ ]*c4: R_MIPS_PC16 external_label
+0+00c8 <[^>]*> nop
+0+00cc <[^>]*> slt at,a0,a1
+0+00d0 <[^>]*> beqzl at,000000d0 <text_label\+0xd0>
+[ ]*d0: R_MIPS_PC16 external_label
+0+00d4 <[^>]*> nop
+0+00d8 <[^>]*> slt at,a1,a0
+0+00dc <[^>]*> bnezl at,000000dc <text_label\+0xdc>
+[ ]*dc: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bge.s src/gas/testsuite/gas/mips/bge.s
--- src-orig/gas/testsuite/gas/mips/bge.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/bge.s Fri Aug 31 23:01:41 2001
@@ -24,6 +24,12 @@ text_label:
bgel $4,$5,text_label
bgtl $4,$5,text_label
+# Branch to an external label.
+ bge $4,$5,external_label
+ bgt $4,$5,external_label
+ bgel $4,$5,external_label
+ bgtl $4,$5,external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bgeu.d src/gas/testsuite/gas/mips/bgeu.d
--- src-orig/gas/testsuite/gas/mips/bgeu.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/bgeu.d Fri Aug 31 23:01:41 2001
@@ -44,4 +44,20 @@ Disassembly of section .text:
0+008c <[^>]*> nop
0+0090 <[^>]*> sltu at,a1,a0
0+0094 <[^>]*> bnezl at,0+0000 <text_label>
+0+0098 <[^>]*> nop
+0+009c <[^>]*> sltu at,a0,a1
+0+00a0 <[^>]*> beqz at,000000a0 <text_label\+0xa0>
+[ ]*a0: R_MIPS_PC16 external_label
+0+00a4 <[^>]*> nop
+0+00a8 <[^>]*> sltu at,a1,a0
+0+00ac <[^>]*> bnez at,000000ac <text_label\+0xac>
+[ ]*ac: R_MIPS_PC16 external_label
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> sltu at,a0,a1
+0+00b8 <[^>]*> beqzl at,000000b8 <text_label\+0xb8>
+[ ]*b8: R_MIPS_PC16 external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> sltu at,a1,a0
+0+00c4 <[^>]*> bnezl at,000000c4 <text_label\+0xc4>
+[ ]*c4: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bgeu.s src/gas/testsuite/gas/mips/bgeu.s
--- src-orig/gas/testsuite/gas/mips/bgeu.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/bgeu.s Fri Aug 31 23:01:41 2001
@@ -22,6 +22,12 @@ text_label:
bgeul $4,$5,text_label
bgtul $4,$5,text_label
+# Branch to an external label.
+ bgeu $4,$5,external_label
+ bgtu $4,$5,external_label
+ bgeul $4,$5,external_label
+ bgtul $4,$5,external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/blt.d src/gas/testsuite/gas/mips/blt.d
--- src-orig/gas/testsuite/gas/mips/blt.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/blt.d Fri Aug 31 23:01:41 2001
@@ -50,4 +50,20 @@ Disassembly of section .text:
0+00a4 <[^>]*> nop
0+00a8 <[^>]*> slt at,a1,a0
0+00ac <[^>]*> beqzl at,0+0000 <text_label>
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> slt at,a0,a1
+0+00b8 <[^>]*> bnez at,000000b8 <text_label\+0xb8>
+[ ]*b8: R_MIPS_PC16 external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> slt at,a1,a0
+0+00c4 <[^>]*> beqz at,000000c4 <text_label\+0xc4>
+[ ]*c4: R_MIPS_PC16 external_label
+0+00c8 <[^>]*> nop
+0+00cc <[^>]*> slt at,a0,a1
+0+00d0 <[^>]*> bnezl at,000000d0 <text_label\+0xd0>
+[ ]*d0: R_MIPS_PC16 external_label
+0+00d4 <[^>]*> nop
+0+00d8 <[^>]*> slt at,a1,a0
+0+00dc <[^>]*> beqzl at,000000dc <text_label\+0xdc>
+[ ]*dc: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/blt.s src/gas/testsuite/gas/mips/blt.s
--- src-orig/gas/testsuite/gas/mips/blt.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/blt.s Fri Aug 31 23:01:41 2001
@@ -24,6 +24,12 @@ text_label:
bltl $4,$5,text_label
blel $4,$5,text_label
+# Branch to an external label.
+ blt $4,$5,external_label
+ ble $4,$5,external_label
+ bltl $4,$5,external_label
+ blel $4,$5,external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bltu.d src/gas/testsuite/gas/mips/bltu.d
--- src-orig/gas/testsuite/gas/mips/bltu.d Tue May 15 16:33:52 2001
+++ src/gas/testsuite/gas/mips/bltu.d Fri Aug 31 23:01:41 2001
@@ -44,4 +44,20 @@ Disassembly of section .text:
0+008c <[^>]*> nop
0+0090 <[^>]*> sltu at,a1,a0
0+0094 <[^>]*> beqzl at,0+0000 <text_label>
+0+0098 <[^>]*> nop
+0+009c <[^>]*> sltu at,a0,a1
+0+00a0 <[^>]*> bnez at,000000a0 <text_label\+0xa0>
+[ ]*a0: R_MIPS_PC16 external_label
+0+00a4 <[^>]*> nop
+0+00a8 <[^>]*> sltu at,a1,a0
+0+00ac <[^>]*> beqz at,000000ac <text_label\+0xac>
+[ ]*ac: R_MIPS_PC16 external_label
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> sltu at,a0,a1
+0+00b8 <[^>]*> bnezl at,000000b8 <text_label\+0xb8>
+[ ]*b8: R_MIPS_PC16 external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> sltu at,a1,a0
+0+00c4 <[^>]*> beqzl at,000000c4 <text_label\+0xc4>
+[ ]*c4: R_MIPS_PC16 external_label
...
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/testsuite/gas/mips/bltu.s src/gas/testsuite/gas/mips/bltu.s
--- src-orig/gas/testsuite/gas/mips/bltu.s Mon May 3 09:28:50 1999
+++ src/gas/testsuite/gas/mips/bltu.s Fri Aug 31 23:01:41 2001
@@ -22,6 +22,12 @@ text_label:
bltul $4,$5,text_label
bleul $4,$5,text_label
+# Branch to an external label.
+ bltu $4,$5,external_label
+ bleu $4,$5,external_label
+ bltul $4,$5,external_label
+ bleul $4,$5,external_label
+
# Round to a 16 byte boundary, for ease in testing multiple targets.
nop
nop
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix handling of R_MIPS_PC16 relocations
2001-09-06 16:00 ` Thiemo Seufer
@ 2001-09-06 21:45 ` Eric Christopher
2001-09-12 8:40 ` Maciej W. Rozycki
1 sibling, 0 replies; 5+ messages in thread
From: Eric Christopher @ 2001-09-06 21:45 UTC (permalink / raw)
To: Thiemo Seufer; +Cc: binutils
>
>
> 2001-09-07 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
>
> /bfd/ChangeLog
> * elf32-mips.c (mips_elf_calculate_relocation): Fix overflow handling
> of R_MIPS_PC16.
>
> /gas/ChangeLog
> * config/tc-mips.c (append_insn): Handle BFD_RELOC_16_PCREL.
> (macro_build): Use BFD_RELOC_16_PCREL_S2 only for embedded
> PIC, BFD_RELOC_16_PCREL for the rest.
> (mips_ip): Likewise.
> (md_pcrel_from): return the right offset for the differently shifted
> pcrel relocs.
> (md_apply_fix): Handle BFD_RELOC_16_PCREL.
>
> /gas/testsuite/ChangeLog
> * gas/mips/beq.d: Check branches to external labels.
> * gas/mips/beq.s: Likewise.
> * gas/mips/bge.d: Likewise.
> * gas/mips/bge.s: Likewise.
> * gas/mips/bgeu.d: Likewise.
> * gas/mips/bgeu.s: Likewise.
> * gas/mips/blt.d: Likewise.
> * gas/mips/blt.s: Likewise.
> * gas/mips/bltu.d: Likewise.
> * gas/mips/bltu.s: Likewise.
> * gas/mips/elempic.d: Switch from R_MIPS_GNU_REL16_S2 to R_MIPS_PC16.
> * gas/mips/empic.d: Likewise.
> * gas/mips/empic.s: Likewise.
> * gas/mips/telempic.d: Likewise.
> * gas/mips/tempic.d: Likewise.
>
Looks right. Go ahead.
-eric
--
Look out behind you!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix handling of R_MIPS_PC16 relocations
2001-09-06 16:00 ` Thiemo Seufer
2001-09-06 21:45 ` Eric Christopher
@ 2001-09-12 8:40 ` Maciej W. Rozycki
2001-09-12 11:31 ` Thiemo Seufer
1 sibling, 1 reply; 5+ messages in thread
From: Maciej W. Rozycki @ 2001-09-12 8:40 UTC (permalink / raw)
To: Thiemo Seufer; +Cc: binutils
On Fri, 7 Sep 2001, Thiemo Seufer wrote:
> This patch was wrong. The R_MIPS_PC16 relocation actually spans an
> offset of only 16 bit while the hardware (and internal branches
> without a reloc) can do 18 bit. I have no explanation why this was
> defined this way. The appended patch adds handling for R_MIPS_PC16
> to gas and bfd. Tested for mips64-linux and mips-elf.
It's simply the R_MIPS_PC16 relocation does not shift the address and as
such it is basically useless. The ABI is broken but I think we should
either stick to it as is or fix it first.
I don't think the following bit is OK -- you've just defined
BFD_RELOC_16_PCREL to behave just like BFD_RELOC_16_PCREL_S2 would:
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/config/tc-mips.c src/gas/config/tc-mips.c
--- src-orig/gas/config/tc-mips.c Fri Aug 31 22:00:08 2001
+++ src/gas/config/tc-mips.c Thu Sep 6 21:58:05 2001
@@ -1898,6 +1978,10 @@ append_insn (place, ip, address_expr, re
| ((address_expr->X_add_number & 0x3fffc) >> 2));
break;
+ case BFD_RELOC_16_PCREL:
+ ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0xffff;
+ break;
+
case BFD_RELOC_16_PCREL_S2:
goto need_reloc;
You'd do something like "ip->insn_opcode |= address_expr->X_add_number &
0xffff" for a BFD_RELOC_16_PCREL reloc.
Maciej
--
+ Maciej W. Rozycki, Technical University of Gdansk, Poland +
+--------------------------------------------------------------+
+ e-mail: macro@ds2.pg.gda.pl, PGP key available +
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix handling of R_MIPS_PC16 relocations
2001-09-12 8:40 ` Maciej W. Rozycki
@ 2001-09-12 11:31 ` Thiemo Seufer
0 siblings, 0 replies; 5+ messages in thread
From: Thiemo Seufer @ 2001-09-12 11:31 UTC (permalink / raw)
To: binutils
Maciej W. Rozycki wrote:
[snip]
> I don't think the following bit is OK -- you've just defined
> BFD_RELOC_16_PCREL to behave just like BFD_RELOC_16_PCREL_S2 would:
>
> diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/config/tc-mips.c src/gas/config/tc-mips.c
> --- src-orig/gas/config/tc-mips.c Fri Aug 31 22:00:08 2001
> +++ src/gas/config/tc-mips.c Thu Sep 6 21:58:05 2001
> @@ -1898,6 +1978,10 @@ append_insn (place, ip, address_expr, re
> | ((address_expr->X_add_number & 0x3fffc) >> 2));
> break;
>
> + case BFD_RELOC_16_PCREL:
> + ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0xffff;
> + break;
> +
> case BFD_RELOC_16_PCREL_S2:
> goto need_reloc;
>
>
> You'd do something like "ip->insn_opcode |= address_expr->X_add_number &
> 0xffff" for a BFD_RELOC_16_PCREL reloc.
I've overlooked this reminiscent from my earlier patch, thanks
for reviewing. I'll check in the following patch under the obvious
rule.
Thiemo
2001-09-12 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
/gas/ChangeLog
* config/tc-mips.c (append_insn): Don't rightshift BFD_RELOC_16_PCREL.
diff -BurpNX /bigdisk/src/binutils-exclude src-orig/gas/config/tc-mips.c src/gas/config/tc-mips.c
--- src-orig/gas/config/tc-mips.c Fri Sep 7 08:11:31 2001
+++ src/gas/config/tc-mips.c Wed Sep 12 19:55:09 2001
@@ -1899,7 +1978,7 @@ append_insn (place, ip, address_expr, re
break;
case BFD_RELOC_16_PCREL:
- ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0xffff;
+ ip->insn_opcode |= address_expr->X_add_number & 0xffff;
break;
case BFD_RELOC_16_PCREL_S2:
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-09-12 11:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-26 14:30 [PATCH] Fix handling of R_MIPS_PC16 relocations Thiemo Seufer
2001-09-06 16:00 ` Thiemo Seufer
2001-09-06 21:45 ` Eric Christopher
2001-09-12 8:40 ` Maciej W. Rozycki
2001-09-12 11:31 ` Thiemo Seufer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).