mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
17c6c9d9f3
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.
27 lines
938 B
Makefile
27 lines
938 B
Makefile
#name: MIPS JAL/JALX addend calculation
|
|
#source: ../../../gas/testsuite/gas/mips/jalx-addend.s
|
|
#as: -EB -32
|
|
#ld: -EB -Ttext 0x1c000000 -e 0x1c000000
|
|
#objdump: -dr --prefix-addresses --show-raw-insn
|
|
|
|
.*: +file format .*mips.*
|
|
|
|
Disassembly of section \.text:
|
|
\.\.\.
|
|
[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
|
|
[0-9a-f]+ <[^>]*> f400 0801 jal 0*18001002 <.*>
|
|
[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero
|
|
[0-9a-f]+ <[^>]*> f100 0409 jalx 0*14001024 <.*>
|
|
[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]+ <[^>]*> 75000401 jalx 0*14001004 <.*>
|
|
[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
|
|
[0-9a-f]+ <[^>]*> 0d000409 jal 0*14001024 <.*>
|
|
[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
|
|
[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra
|
|
[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero
|
|
\.\.\.
|