MIPS: Add tests for orphan REL HI16 relocation addend processing

Add GAS and LD test cases for orphan REL HI16 relocation processing,
including verification of the addends produced as well as the warning
messages expected.

Due to the ordering used for the list of oustanding cached HI16 reloc
entries warnings for non-ELF links are issued in the reverse order
compared to one for ELF links.  This is not considered a defect as all
the required warnings are produced in both cases, however separate
warning lists are required and included here for ELF and srec output.
This commit is contained in:
Maciej W. Rozycki
2026-01-14 22:28:44 +00:00
parent b710ca0876
commit 42b413786d
27 changed files with 447 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
#objdump: -dr --prefix-addresses --show-raw-insn
#as: -mabi=32 -march=mips1 -mno-pdr --defsym micromips=1
#name: MIPS and microMIPS orphan HI16 REL relocation addends
#warning_output: mips-hi16-orphan-addend.l
#source: mips-hi16-orphan-addend.s
.*: +file format .*mips.*
Disassembly of section \.text:
00000000 <[^>]*> 24025677 li v0,22135
0: R_MIPS_LO16 var1
00000004 <[^>]*> 24045677 li a0,22135
4: R_MIPS_TLS_DTPREL_LO16 var2
00000008 <[^>]*> 03e00008 jr ra
0000000c <[^>]*> 24065677 li a2,22135
c: R_MIPS_TLS_TPREL_LO16 var3
00000010 <[^>]*> 3040 5677 li v0,22135
10: R_MICROMIPS_LO16 var1
00000014 <[^>]*> 3080 5677 li a0,22135
14: R_MICROMIPS_TLS_DTPREL_LO16 var2
00000018 <[^>]*> 459f jr ra
0000001a <[^>]*> 30c0 5677 li a2,22135
1a: R_MICROMIPS_TLS_TPREL_LO16 var3
\.\.\.
00000020 <[^>]*> 2407b1a3 li a3,-20061
20: R_MIPS_TLS_TPREL_HI16 var3
00000024 <[^>]*> 24061234 li a2,4660
24: R_MIPS_TLS_TPREL_HI16 var3
00000028 <[^>]*> 2405b1a3 li a1,-20061
28: R_MIPS_TLS_DTPREL_HI16 var2
0000002c <[^>]*> 24041234 li a0,4660
2c: R_MIPS_TLS_DTPREL_HI16 var2
00000030 <[^>]*> 2403b1a3 li v1,-20061
30: R_MIPS_HI16 var1
00000034 <[^>]*> 03e00008 jr ra
00000038 <[^>]*> 24021234 li v0,4660
38: R_MIPS_HI16 var1
0000003c <[^>]*> 30e0 b1a3 li a3,-20061
3c: R_MICROMIPS_TLS_TPREL_HI16 var3
00000040 <[^>]*> 30c0 1234 li a2,4660
40: R_MICROMIPS_TLS_TPREL_HI16 var3
00000044 <[^>]*> 30a0 b1a3 li a1,-20061
44: R_MICROMIPS_TLS_DTPREL_HI16 var2
00000048 <[^>]*> 3080 1234 li a0,4660
48: R_MICROMIPS_TLS_DTPREL_HI16 var2
0000004c <[^>]*> 3060 b1a3 li v1,-20061
4c: R_MICROMIPS_HI16 var1
00000050 <[^>]*> 459f jr ra
00000052 <[^>]*> 3040 1234 li v0,4660
52: R_MICROMIPS_HI16 var1
\.\.\.

View File

@@ -0,0 +1,13 @@
.*: Assembler messages:
.*:57: Warning: can't find matching low-part relocation for %hi operator
.*:56: Warning: can't find matching low-part relocation for %hi operator
.*:55: Warning: can't find matching low-part relocation for %dtprel_hi operator
.*:54: Warning: can't find matching low-part relocation for %dtprel_hi operator
.*:53: Warning: can't find matching low-part relocation for %tprel_hi operator
.*:52: Warning: can't find matching low-part relocation for %tprel_hi operator
.*:38: Warning: can't find matching low-part relocation for %hi operator
.*:37: Warning: can't find matching low-part relocation for %hi operator
.*:36: Warning: can't find matching low-part relocation for %dtprel_hi operator
.*:35: Warning: can't find matching low-part relocation for %dtprel_hi operator
.*:34: Warning: can't find matching low-part relocation for %tprel_hi operator
.*:33: Warning: can't find matching low-part relocation for %tprel_hi operator

View File

@@ -0,0 +1,66 @@
.text
.globl fun1
.ent fun1
fun1:
li $2, %lo(var1 + 0x12345677)
li $4, %dtprel_lo(var2 + 0x12345677)
li $6, %tprel_lo(var3 + 0x12345677)
jr $31
.end fun1
.set push
.ifdef micromips
.set micromips
.else
.set mips16
.endif
.globl fun2
.ent fun2
fun2:
li $2, %lo(var1 + 0x12345677)
li $4, %dtprel_lo(var2 + 0x12345677)
li $6, %tprel_lo(var3 + 0x12345677)
jr $31
.end fun2
.set pop
.align 2
.globl fun3
.ent fun3
fun3:
li $7, %tprel_hi(var3 + 0xb1a29384)
li $6, %tprel_hi(var3 + 0x12345678)
li $5, %dtprel_hi(var2 + 0xb1a29384)
li $4, %dtprel_hi(var2 + 0x12345678)
li $3, %hi(var1 + 0xb1a29384)
li $2, %hi(var1 + 0x12345678)
jr $31
.end fun3
.set push
.ifdef micromips
.set micromips
.else
.set mips16
.endif
.globl fun4
.ent fun4
fun4:
li $7, %tprel_hi(var3 + 0xb1a29384)
li $6, %tprel_hi(var3 + 0x12345678)
li $5, %dtprel_hi(var2 + 0xb1a29384)
li $4, %dtprel_hi(var2 + 0x12345678)
li $3, %hi(var1 + 0xb1a29384)
li $2, %hi(var1 + 0x12345678)
jr $31
.end fun4
.set pop
.align 2
# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
.space 16
.align 4, 0

View File

@@ -1059,6 +1059,7 @@ if { [istarget mips*-*-vxworks*] } {
run_dump_test "mips16-hilo-match"
run_dump_test "mips16-tls-hilo-match"
run_dump_test "mips16-tls-hilo-addend"
run_dump_test "mips16-hi16-orphan-addend"
run_dump_test "mips16-reloc-error"
run_dump_test "mips16e2-reloc-error"
run_dump_test "mips16-reg-error"
@@ -1678,6 +1679,7 @@ if { [istarget mips*-*-vxworks*] } {
run_dump_test "micromips-hilo-match"
run_dump_test "micromips-tls-hilo-match"
run_dump_test "micromips-tls-hilo-addend"
run_dump_test "micromips-hi16-orphan-addend"
run_dump_test_arches "mcu" [mips_arch_list_matching mips32r2 \
!octeon]

View File

@@ -0,0 +1,52 @@
#objdump: -dr --prefix-addresses --show-raw-insn
#as: -mabi=32 -march=mips1 -mno-pdr
#name: MIPS and MIPS16 orphan HI16 REL relocation addends
#warning_output: mips-hi16-orphan-addend.l
#source: mips-hi16-orphan-addend.s
.*: +file format .*mips.*
Disassembly of section \.text:
00000000 <[^>]*> 24025677 li v0,22135
0: R_MIPS_LO16 var1
00000004 <[^>]*> 24045677 li a0,22135
4: R_MIPS_TLS_DTPREL_LO16 var2
00000008 <[^>]*> 03e00008 jr ra
0000000c <[^>]*> 24065677 li a2,22135
c: R_MIPS_TLS_TPREL_LO16 var3
00000010 <[^>]*> f66a 6a17 li v0,22135
10: R_MIPS16_LO16 var1
00000014 <[^>]*> f66a 6c17 li a0,22135
14: R_MIPS16_TLS_DTPREL_LO16 var2
00000018 <[^>]*> f66a 6e17 li a2,22135
18: R_MIPS16_TLS_TPREL_LO16 var3
0000001c <[^>]*> e820 jr ra
0000001e <[^>]*> 6500 nop
00000020 <[^>]*> 2407b1a3 li a3,-20061
20: R_MIPS_TLS_TPREL_HI16 var3
00000024 <[^>]*> 24061234 li a2,4660
24: R_MIPS_TLS_TPREL_HI16 var3
00000028 <[^>]*> 2405b1a3 li a1,-20061
28: R_MIPS_TLS_DTPREL_HI16 var2
0000002c <[^>]*> 24041234 li a0,4660
2c: R_MIPS_TLS_DTPREL_HI16 var2
00000030 <[^>]*> 2403b1a3 li v1,-20061
30: R_MIPS_HI16 var1
00000034 <[^>]*> 03e00008 jr ra
00000038 <[^>]*> 24021234 li v0,4660
38: R_MIPS_HI16 var1
0000003c <[^>]*> f1b6 6f03 li a3,45475
3c: R_MIPS16_TLS_TPREL_HI16 var3
00000040 <[^>]*> f222 6e14 li a2,4660
40: R_MIPS16_TLS_TPREL_HI16 var3
00000044 <[^>]*> f1b6 6d03 li a1,45475
44: R_MIPS16_TLS_DTPREL_HI16 var2
00000048 <[^>]*> f222 6c14 li a0,4660
48: R_MIPS16_TLS_DTPREL_HI16 var2
0000004c <[^>]*> f1b6 6b03 li v1,45475
4c: R_MIPS16_HI16 var1
00000050 <[^>]*> f222 6a14 li v0,4660
50: R_MIPS16_HI16 var1
00000054 <[^>]*> e820 jr ra
00000056 <[^>]*> 6500 nop
\.\.\.

View File

@@ -0,0 +1,20 @@
#objdump: -dr --prefix-addresses --show-raw-insn
#as: -mabi=32 -mips32r6 -mno-pdr
#name: MIPS orphan PCHI16 REL relocation addends
#warning_output: mips-hi16-orphan-addend.l
.*: +file format .*mips.*
Disassembly of section \.text:
00000000 <[^>]*> 24029384 li v0,-27772
0: R_MIPS_PCLO16 var1
00000004 <[^>]*> 03e00009 jr ra
00000008 <[^>]*> 24035678 li v1,22136
8: R_MIPS_PCLO16 var2
00000010 <[^>]*> ec5eb1a3 auipc v0,0xb1a3
10: R_MIPS_PCHI16 var1
00000014 <[^>]*> ec7e1234 auipc v1,0x1234
14: R_MIPS_PCHI16 var2
00000018 <[^>]*> 03e00009 jr ra
0000001c <[^>]*> 00000000 nop
\.\.\.

View File

@@ -0,0 +1,3 @@
.*: Assembler messages:
.*:14: Warning: can't find matching low-part relocation for %pcrel_hi operator
.*:13: Warning: can't find matching low-part relocation for %pcrel_hi operator

View File

@@ -0,0 +1,20 @@
.text
.globl fun1
.ent fun1
fun1:
li $2, %pcrel_lo(var1 + 0xb1a29384)
li $3, %pcrel_lo(var2 + 0x12345678)
jr $31
.end fun1
.globl fun2
.ent fun2
fun2:
auipc $2, %pcrel_hi(var1 + 0xb1a29384)
auipc $3, %pcrel_hi(var2 + 0x12345678)
jr $31
.end fun2
# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
.align 4, 0
.space 16