aboutsummaryrefslogtreecommitdiff
path: root/gas/testsuite
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@imgtec.com>2016-05-20 13:32:19 +0100
committerMaciej W. Rozycki <macro@imgtec.com>2016-05-20 13:38:48 +0100
commit17c6c9d9f3e71459edb4b6af5ec75125f0d06f87 (patch)
tree8ea38eb69685fd05cbeb181263dbd87556da3919 /gas/testsuite
parent134c0c8bf4a258ba10e72b724eadf40f731bb7ec (diff)
downloadgdb-17c6c9d9f3e71459edb4b6af5ec75125f0d06f87.zip
gdb-17c6c9d9f3e71459edb4b6af5ec75125f0d06f87.tar.gz
gdb-17c6c9d9f3e71459edb4b6af5ec75125f0d06f87.tar.bz2
MIPS: Fix the encoding of immediates with microMIPS JALX
The microMIPS JALX instruction shares the R_MICROMIPS_26_S1 relocation with microMIPS J/JAL/JALS instructions, however unlike the latters its encoded immediate argument is unusually shifted left by 2 rather than 1 in calculating the value used for the operation requested. We already handle this exception in `mips_elf_calculate_relocation' in LD, in a scenario where JALX is produced as a result of relaxing JAL for the purpose of making a cross-mode jump. We also get it right in the disassembler in `decode_micromips_operand'. What we don't correctly do however is processing microMIPS JALX produced by GAS from an assembly source, where a non-zero constant argument or a symbol reference with a non-zero in-place addend has been used. In this case the same calculation is made as for microMIPS J/JAL/JALS, causing the wrong encoding to be produced by GAS on making an object file, and then again by LD in the final link. The latter in particular causes the calculation, where the addend fits in the relocatable field, to produce different final addresses for the same source code depending on whether REL or RELA relocations are used. Correct these issues by special-casing microMIPS JALX in the places that have been previously missed. bfd/ * elfxx-mips.c (mips_elf_read_rel_addend): Adjust the addend for microMIPS JALX. gas/ * config/tc-mips.c (append_insn): Correct the encoding of a constant argument for microMIPS JALX. (tc_gen_reloc): Correct the encoding of an in-place addend for microMIPS JALX. * testsuite/gas/mips/jalx-addend.d: New test. * testsuite/gas/mips/jalx-addend-n32.d: New test. * testsuite/gas/mips/jalx-addend-n64.d: New test. * testsuite/gas/mips/jalx-imm.d: New test. * testsuite/gas/mips/jalx-imm-n32.d: New test. * testsuite/gas/mips/jalx-imm-n64.d: New test. * testsuite/gas/mips/jalx-addend.s: New test source. * testsuite/gas/mips/jalx-imm.s: New test source. * testsuite/gas/mips/mips.exp: Run the new tests. ld/ * testsuite/ld-mips-elf/jalx-addend.d: New test. * testsuite/ld-mips-elf/jalx-addend-n32.d: New test. * testsuite/ld-mips-elf/jalx-addend-n64.d: New test. * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
Diffstat (limited to 'gas/testsuite')
-rw-r--r--gas/testsuite/gas/mips/jalx-addend-n32.d29
-rw-r--r--gas/testsuite/gas/mips/jalx-addend-n64.d37
-rw-r--r--gas/testsuite/gas/mips/jalx-addend.d28
-rw-r--r--gas/testsuite/gas/mips/jalx-addend.s35
-rw-r--r--gas/testsuite/gas/mips/jalx-imm-n32.d5
-rw-r--r--gas/testsuite/gas/mips/jalx-imm-n64.d5
-rw-r--r--gas/testsuite/gas/mips/jalx-imm.d24
-rw-r--r--gas/testsuite/gas/mips/jalx-imm.s35
-rw-r--r--gas/testsuite/gas/mips/mips.exp8
9 files changed, 206 insertions, 0 deletions
diff --git a/gas/testsuite/gas/mips/jalx-addend-n32.d b/gas/testsuite/gas/mips/jalx-addend-n32.d
new file mode 100644
index 0000000..1abb246
--- /dev/null
+++ b/gas/testsuite/gas/mips/jalx-addend-n32.d
@@ -0,0 +1,29 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JAL/JALX addend encoding (n32)
+#as: -n32 -march=from-abi
+#source: jalx-addend.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+ \.\.\.
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> f400 0000 jal 00000000 <foo-0x1000>
+[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 foo-0x3fffffe
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> f000 0000 jalx 00000000 <foo-0x1000>
+[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 bar-0x7fffffc
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c jr ra
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> 0000 0000 nop
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 74000000 jalx 00000000 <foo-0x1000>
+[ ]*[0-9a-f]+: R_MIPS_26 foo-0x7fffffc
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 0c000000 jal 00000000 <foo-0x1000>
+[ ]*[0-9a-f]+: R_MIPS_26 bar-0x7fffffc
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+ \.\.\.
diff --git a/gas/testsuite/gas/mips/jalx-addend-n64.d b/gas/testsuite/gas/mips/jalx-addend-n64.d
new file mode 100644
index 0000000..469261f
--- /dev/null
+++ b/gas/testsuite/gas/mips/jalx-addend-n64.d
@@ -0,0 +1,37 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JAL/JALX addend encoding (n64)
+#as: -64 -march=from-abi
+#source: jalx-addend.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+ \.\.\.
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> f400 0000 jal 0000000000000000 <foo-0x1000>
+[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 foo-0x3fffffe
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*-0x3fffffe
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*-0x3fffffe
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> f000 0000 jalx 0000000000000000 <foo-0x1000>
+[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 bar-0x7fffffc
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*-0x7fffffc
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*-0x7fffffc
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c jr ra
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> 0000 0000 nop
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 74000000 jalx 0000000000000000 <foo-0x1000>
+[ ]*[0-9a-f]+: R_MIPS_26 foo-0x7fffffc
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*-0x7fffffc
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*-0x7fffffc
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 0c000000 jal 0000000000000000 <foo-0x1000>
+[ ]*[0-9a-f]+: R_MIPS_26 bar-0x7fffffc
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*-0x7fffffc
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*-0x7fffffc
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+ \.\.\.
diff --git a/gas/testsuite/gas/mips/jalx-addend.d b/gas/testsuite/gas/mips/jalx-addend.d
new file mode 100644
index 0000000..442bc69
--- /dev/null
+++ b/gas/testsuite/gas/mips/jalx-addend.d
@@ -0,0 +1,28 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JAL/JALX addend encoding
+#as: -32
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+ \.\.\.
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> f600 0001 jal 04000002 <bar\+0x3ffefe2>
+[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 foo
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> f200 0001 jalx 08000004 <bar\+0x7ffefe4>
+[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 bar
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c jr ra
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> 0000 0000 nop
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 76000001 jalx 08000004 <bar\+0x7ffefe4>
+[ ]*[0-9a-f]+: R_MIPS_26 foo
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 0e000001 jal 08000004 <bar\+0x7ffefe4>
+[ ]*[0-9a-f]+: R_MIPS_26 bar
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+ \.\.\.
diff --git a/gas/testsuite/gas/mips/jalx-addend.s b/gas/testsuite/gas/mips/jalx-addend.s
new file mode 100644
index 0000000..b9b0db3
--- /dev/null
+++ b/gas/testsuite/gas/mips/jalx-addend.s
@@ -0,0 +1,35 @@
+ .text
+ .set noreorder
+ .space 0x1000
+
+ .align 4
+ .set micromips
+ .globl foo
+ .ent foo
+foo:
+ nor $0, $0
+ jal foo - 0x3fffffe
+ nor $0, $0
+ jalx bar - 0x7fffffc
+ nor $0, $0
+ jalr $0, $ra
+ nor $0, $0
+ .end foo
+
+ .align 4
+ .set nomicromips
+ .globl bar
+ .ent bar
+bar:
+ nor $0, $0
+ jalx foo - 0x7fffffc
+ nor $0, $0
+ jal bar - 0x7fffffc
+ nor $0, $0
+ jalr $0, $ra
+ nor $0, $0
+ .end bar
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 4, 0
+ .space 16
diff --git a/gas/testsuite/gas/mips/jalx-imm-n32.d b/gas/testsuite/gas/mips/jalx-imm-n32.d
new file mode 100644
index 0000000..188bb49
--- /dev/null
+++ b/gas/testsuite/gas/mips/jalx-imm-n32.d
@@ -0,0 +1,5 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JAL/JALX immediate operand encoding (n32)
+#as: -n32 -march=from-abi
+#source: jalx-imm.s
+#dump: jalx-imm.d
diff --git a/gas/testsuite/gas/mips/jalx-imm-n64.d b/gas/testsuite/gas/mips/jalx-imm-n64.d
new file mode 100644
index 0000000..7b0c23e
--- /dev/null
+++ b/gas/testsuite/gas/mips/jalx-imm-n64.d
@@ -0,0 +1,5 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JAL/JALX immediate operand encoding (n64)
+#as: -64 -march=from-abi
+#source: jalx-imm.s
+#dump: jalx-imm.d
diff --git a/gas/testsuite/gas/mips/jalx-imm.d b/gas/testsuite/gas/mips/jalx-imm.d
new file mode 100644
index 0000000..aa487ff
--- /dev/null
+++ b/gas/testsuite/gas/mips/jalx-imm.d
@@ -0,0 +1,24 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JAL/JALX immediate operand encoding
+#as: -32
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+ \.\.\.
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> f600 0001 jal 0+4000002 <bar\+0x3ffefe2>
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> f200 0001 jalx 0+8000004 <bar\+0x7ffefe4>
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c jr ra
+[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
+[0-9a-f]+ <[^>]*> 0000 0000 nop
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 76000001 jalx 0+8000004 <bar\+0x7ffefe4>
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 0e000001 jal 0+8000004 <bar\+0x7ffefe4>
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra
+[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
+ \.\.\.
diff --git a/gas/testsuite/gas/mips/jalx-imm.s b/gas/testsuite/gas/mips/jalx-imm.s
new file mode 100644
index 0000000..eef8717
--- /dev/null
+++ b/gas/testsuite/gas/mips/jalx-imm.s
@@ -0,0 +1,35 @@
+ .text
+ .set noreorder
+ .space 0x1000
+
+ .align 4
+ .set micromips
+ .globl foo
+ .ent foo
+foo:
+ nor $0, $0
+ jal 0x4000002
+ nor $0, $0
+ jalx 0x8000004
+ nor $0, $0
+ jalr $0, $ra
+ nor $0, $0
+ .end foo
+
+ .align 4
+ .set nomicromips
+ .globl bar
+ .ent bar
+bar:
+ nor $0, $0
+ jalx 0x8000004
+ nor $0, $0
+ jal 0x8000004
+ nor $0, $0
+ jalr $0, $ra
+ nor $0, $0
+ .end bar
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 4, 0
+ .space 16
diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp
index 88d15c8..1b1ac02 100644
--- a/gas/testsuite/gas/mips/mips.exp
+++ b/gas/testsuite/gas/mips/mips.exp
@@ -794,6 +794,14 @@ if { [istarget mips*-*-vxworks*] } {
run_dump_test "mips16-jalx"
run_dump_test "mips-jalx"
run_dump_test "mips-jalx-2"
+ run_dump_test "jalx-imm"
+ run_dump_test "jalx-addend"
+ if $has_newabi {
+ run_dump_test "jalx-imm-n32"
+ run_dump_test "jalx-addend-n32"
+ run_dump_test "jalx-imm-n64"
+ run_dump_test "jalx-addend-n64"
+ }
# Check MIPS16 HI16/LO16 relocations
run_dump_test "mips16-hilo"
if $has_newabi {