From d27473e7c54891df2bf6e637e60f1910c57e058e Mon Sep 17 00:00:00 2001 From: Lulu Cai Date: Wed, 13 Dec 2023 11:34:56 +0800 Subject: LoongArch: Add testsuit for DESC and tls transition and tls relaxation. --- ld/testsuite/ld-loongarch-elf/desc-ie.d | 16 ++++++ ld/testsuite/ld-loongarch-elf/desc-ie.s | 18 ++++++ ld/testsuite/ld-loongarch-elf/desc-le.d | 15 +++++ ld/testsuite/ld-loongarch-elf/desc-le.s | 14 +++++ ld/testsuite/ld-loongarch-elf/desc-norelax.d | 16 ++++++ ld/testsuite/ld-loongarch-elf/desc-norelax.s | 5 ++ ld/testsuite/ld-loongarch-elf/desc-relax.d | 15 +++++ ld/testsuite/ld-loongarch-elf/desc-relax.s | 5 ++ ld/testsuite/ld-loongarch-elf/ie-le.d | 13 +++++ ld/testsuite/ld-loongarch-elf/ie-le.s | 11 ++++ ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp | 9 +++ ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d | 56 +++++++++++++++++++ ld/testsuite/ld-loongarch-elf/tlsdesc-dso.s | 65 ++++++++++++++++++++++ 13 files changed, 258 insertions(+) create mode 100644 ld/testsuite/ld-loongarch-elf/desc-ie.d create mode 100644 ld/testsuite/ld-loongarch-elf/desc-ie.s create mode 100644 ld/testsuite/ld-loongarch-elf/desc-le.d create mode 100644 ld/testsuite/ld-loongarch-elf/desc-le.s create mode 100644 ld/testsuite/ld-loongarch-elf/desc-norelax.d create mode 100644 ld/testsuite/ld-loongarch-elf/desc-norelax.s create mode 100644 ld/testsuite/ld-loongarch-elf/desc-relax.d create mode 100644 ld/testsuite/ld-loongarch-elf/desc-relax.s create mode 100644 ld/testsuite/ld-loongarch-elf/ie-le.d create mode 100644 ld/testsuite/ld-loongarch-elf/ie-le.s create mode 100644 ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d create mode 100644 ld/testsuite/ld-loongarch-elf/tlsdesc-dso.s (limited to 'ld') diff --git a/ld/testsuite/ld-loongarch-elf/desc-ie.d b/ld/testsuite/ld-loongarch-elf/desc-ie.d new file mode 100644 index 0000000..d1acbfc --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-ie.d @@ -0,0 +1,16 @@ +#as: +#ld: -shared -z norelro -e 0x0 +#objdump: -dr +#skip: loongarch32-*-* + +.*: file format .* + +Disassembly of section .text: + +0+230 : + 230: 1a000084 pcalau12i \$a0, 4 + 234: 28cd6084 ld.d \$a0, \$a0, 856 + 238: 03400000 nop.* + 23c: 03400000 nop.* + 240: 1a000084 pcalau12i \$a0, 4 + 244: 28cd6081 ld.d \$ra, \$a0, 856 diff --git a/ld/testsuite/ld-loongarch-elf/desc-ie.s b/ld/testsuite/ld-loongarch-elf/desc-ie.s new file mode 100644 index 0000000..7f5772b --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-ie.s @@ -0,0 +1,18 @@ + .global v1 + .section .tdata,"awT",@progbits +v1: + .word 1 + .text + .global fn1 + .type fn1,@function +fn1: + + # Use DESC and IE to access the same symbol, + # DESC will relax to IE. + pcalau12i $a0,%desc_pc_hi20(var) + addi.d $a0,$a0,%desc_pc_lo12(var) + ld.d $ra,$a0,%desc_ld(var) + jirl $ra,$ra,%desc_call(var) + + pcalau12i $a0,%ie_pc_hi20(var) + ld.d $ra,$a0,%ie_pc_lo12(var) diff --git a/ld/testsuite/ld-loongarch-elf/desc-le.d b/ld/testsuite/ld-loongarch-elf/desc-le.d new file mode 100644 index 0000000..b4ca9f8 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-le.d @@ -0,0 +1,15 @@ +#as: +#ld: -z norelro -e 0x0 +#objdump: -dr +#skip: loongarch32-*-* + +.*: file format .* + + +Disassembly of section .text: + +0+1200000e8 : + 1200000e8: 14000004 lu12i.w \$a0, 0 + 1200000ec: 03800084 ori \$a0, \$a0, 0x0 + 1200000f0: 03400000 nop.* + 1200000f4: 03400000 nop.* diff --git a/ld/testsuite/ld-loongarch-elf/desc-le.s b/ld/testsuite/ld-loongarch-elf/desc-le.s new file mode 100644 index 0000000..9ffaa2d --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-le.s @@ -0,0 +1,14 @@ + .global var + .section .tdata,"awT",@progbits +var: + .word 1 + .text + .global fn1 + .type fn1,@function +fn1: + + # DESC will relax to LE. + pcalau12i $a0,%desc_pc_hi20(var) + addi.d $a0,$a0,%desc_pc_lo12(var) + ld.d $ra,$a0,%desc_ld(var) + jirl $ra,$ra,%desc_call(var) diff --git a/ld/testsuite/ld-loongarch-elf/desc-norelax.d b/ld/testsuite/ld-loongarch-elf/desc-norelax.d new file mode 100644 index 0000000..32ce3e5 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-norelax.d @@ -0,0 +1,16 @@ +#as: +#ld: -z norelro -shared --section-start=.got=0x1ff000 +#objdump: -dr +#skip: loongarch32-*-* + +.*: file format .* + + +Disassembly of section .text: + +0+1c0 <.*>: + 1c0: 1a003fe4 pcalau12i \$a0, 511 + 1c4: 02c02084 addi.d \$a0, \$a0, 8 + 1c8: 28c00081 ld.d \$ra, \$a0, 0 + 1cc: 4c000021 jirl \$ra, \$ra, 0 + 1d0: 0010888c add.d \$t0, \$a0, \$tp diff --git a/ld/testsuite/ld-loongarch-elf/desc-norelax.s b/ld/testsuite/ld-loongarch-elf/desc-norelax.s new file mode 100644 index 0000000..9aa7f55 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-norelax.s @@ -0,0 +1,5 @@ +.L1: +# The got address of the symbol exceeds the +# range of pcaddi, do not relax. +la.tls.desc $a0,var +add.d $t0,$a0,$tp diff --git a/ld/testsuite/ld-loongarch-elf/desc-relax.d b/ld/testsuite/ld-loongarch-elf/desc-relax.d new file mode 100644 index 0000000..ce53d31 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-relax.d @@ -0,0 +1,15 @@ +#as: +#ld: -z norelro -shared +#objdump: -dr +#skip: loongarch32-*-* + +.*: file format .* + + +Disassembly of section .text: + +0+188 <.*>: + 188: 18020844 pcaddi \$a0, 4162 + 18c: 28c00081 ld.d \$ra, \$a0, 0 + 190: 4c000021 jirl \$ra, \$ra, 0 + 194: 0010888c add.d \$t0, \$a0, \$tp diff --git a/ld/testsuite/ld-loongarch-elf/desc-relax.s b/ld/testsuite/ld-loongarch-elf/desc-relax.s new file mode 100644 index 0000000..4a993a5 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-relax.s @@ -0,0 +1,5 @@ +.L1: +# A UND symbol but no more than the range of pcaddi, +# do pcalau12i + addi => pcaddi +la.tls.desc $a0,var +add.d $t0,$a0,$tp diff --git a/ld/testsuite/ld-loongarch-elf/ie-le.d b/ld/testsuite/ld-loongarch-elf/ie-le.d new file mode 100644 index 0000000..42694d7 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/ie-le.d @@ -0,0 +1,13 @@ +#as: +#ld: -z norelro -e 0x0 +#objdump: -dr +#skip: loongarch32-*-* + +.*: file format .* + + +Disassembly of section .text: + +0+1200000e8 : + 1200000e8: 14000004 lu12i.w \$a0, 0 + 1200000ec: 03800084 ori \$a0, \$a0, 0x0 diff --git a/ld/testsuite/ld-loongarch-elf/ie-le.s b/ld/testsuite/ld-loongarch-elf/ie-le.s new file mode 100644 index 0000000..795c7ce --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/ie-le.s @@ -0,0 +1,11 @@ + .data + .section .tdata,"awT",@progbits +var: + .word 1 + .text + .global fn1 + .type gn1,@function +fn1: + # expect IE to relax LE. + pcalau12i $a0,%ie_pc_hi20(var) + ld.d $a0,$a0,%ie_pc_lo12(var) diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp index b43a518..2a5709a 100644 --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp @@ -69,3 +69,12 @@ if [istarget "loongarch64-*-*"] { ] \ ] } + +if [istarget "loongarch64-*-*"] { + run_dump_test "desc-ie" + run_dump_test "desc-le" + run_dump_test "ie-le" + run_dump_test "tlsdesc-dso" + run_dump_test "desc-norelax" + run_dump_test "desc-relax" +} diff --git a/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d b/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d new file mode 100644 index 0000000..667ad74 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d @@ -0,0 +1,56 @@ +#as: +#ld: -shared -z norelro +#objdump: -dr +#skip: loongarch32-*-* + +.*: file format .* + + +Disassembly of section .text: + +0+418 : + 418: 180214c4 pcaddi \$a0, 4262 + 41c: 1a000084 pcalau12i \$a0, 4 + 420: 28db0084 ld.d \$a0, \$a0, 1728 + 424: 180212a4 pcaddi \$a0, 4245 + 428: 18021304 pcaddi \$a0, 4248 + 42c: 28c00081 ld.d \$ra, \$a0, 0 + 430: 4c000021 jirl \$ra, \$ra, 0 + 434: 1a000084 pcalau12i \$a0, 4 + 438: 28d9c084 ld.d \$a0, \$a0, 1648 + 43c: 03400000 nop.* + 440: 03400000 nop.* + 444: 1a000084 pcalau12i \$a0, 4 + 448: 28d9c084 ld.d \$a0, \$a0, 1648 + 44c: 18021264 pcaddi \$a0, 4243 + 450: 18021244 pcaddi \$a0, 4242 + 454: 28c00081 ld.d \$ra, \$a0, 0 + 458: 4c000021 jirl \$ra, \$ra, 0 + 45c: 1a000084 pcalau12i \$a0, 4 + 460: 28daa084 ld.d \$a0, \$a0, 1704 + +0+464 : + 464: 1a000084 pcalau12i \$a0, 4 + 468: 28d86084 ld.d \$a0, \$a0, 1560 + 46c: 18020ce4 pcaddi \$a0, 4199 + 470: 18020e04 pcaddi \$a0, 4208 + 474: 28c00081 ld.d \$ra, \$a0, 0 + 478: 4c000021 jirl \$ra, \$ra, 0 + 47c: 18020d24 pcaddi \$a0, 4201 + 480: 1a000084 pcalau12i \$a0, 4 + 484: 28d90084 ld.d \$a0, \$a0, 1600 + 488: 03400000 nop.* + 48c: 03400000 nop.* + 490: 1a000084 pcalau12i \$a0, 4 + 494: 28d90084 ld.d \$a0, \$a0, 1600 + 498: 18020d84 pcaddi \$a0, 4204 + 49c: 28c00081 ld.d \$ra, \$a0, 0 + 4a0: 4c000021 jirl \$ra, \$ra, 0 + 4a4: 18020d24 pcaddi \$a0, 4201 + 4a8: 1a000084 pcalau12i \$a0, 4 + 4ac: 28d96084 ld.d \$a0, \$a0, 1624 + +0+4b0 : + 4b0: 18020d84 pcaddi \$a0, 4204 + 4b4: 28c00081 ld.d \$ra, \$a0, 0 + 4b8: 4c000021 jirl \$ra, \$ra, 0 diff --git a/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.s b/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.s new file mode 100644 index 0000000..936bbce --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.s @@ -0,0 +1,65 @@ + .data + .section .tdata,"awT",@progbits + .global gl1, gl2, gl3, gl4 +gl1: .dword 1 +gl2: .dword 2 +gl3: .dword 3 +gl4: .dword 4 +lo1: .dword 10 +lo2: .dword 20 +lo3: .dword 30 +lo4: .dword 40 + .text +# Access global symbol +fun_gl1: + # GD + IE + # GD: pcaddi + addi.d => pcaddi + la.tls.gd $a0, gl1 + la.tls.ie $a0, gl1 + + # GD + DESC + # GD: pcaddi + addi.d => pcaddi + la.tls.gd $a0, gl2 + # DESC: pcaddi + addi.d => pcaddi + la.tls.desc $a0, gl2 + + # DESC + IE + # DESC -> IE + la.tls.desc $a0, gl3 + la.tls.ie $a0, gl3 + + # GD + DESC + IE + # GD: pcaddi + addi.d => pcaddi + la.tls.gd $a0, gl4 + # DESC: pcaddi + addi.d => pcaddi + la.tls.desc $a0, gl4 + la.tls.ie $a0, gl4 + +# Access local symbol +fun_lo: + # IE + GD + la.tls.ie $a0, lo1 + # GD: pcaddi + addi.d => pcaddi + la.tls.gd $a0, lo1 + + # DESC + GD + # DESC: pcaddi + addi.d => pcaddi + la.tls.desc $a0, lo2 + # GD: pcaddi + addi.d => pcaddi + la.tls.gd $a0, lo2 + + # DESC + IE + # DESC: DESC -> IE + la.tls.desc $a0, lo3 + la.tls.ie $a0, lo3 + + # DESC + GD + IE + # DESC: pcaddi + addi.d => pcaddi + la.tls.desc $a0, lo4 + # GD: pcaddi + addi.d => pcaddi + la.tls.gd $a0, lo4 + la.tls.ie $a0, lo4 + +# Access external undef symbol +fun_external: + la.tls.desc $a0, sH1 -- cgit v1.1