From 2bd766d6245bf9db77c42da3537c949ffb814bfc Mon Sep 17 00:00:00 2001 From: mengqinggang Date: Thu, 1 Dec 2022 17:17:09 +0800 Subject: [PATCH] LoongArch: ld: Add support for linker relaxation. Add ld relax support and testsuits. ld/ChangeLog: * emultempl/loongarchelf.em: Regenerated. * testsuite/ld-elf/compressed1d.d: Xfail loongarch*-*. * testsuite/ld-elf/pr26936.d: Likewise. * testsuite/ld-loongarch-elf/disas-jirl.d: Regenerated. * testsuite/ld-loongarch-elf/disas-jirl-32.d: Regenerated. * testsuite/ld-loongarch-elf/jmp_op.d: Likewise. * testsuite/ld-loongarch-elf/macro_op.d: Likewise. * testsuite/ld-loongarch-elf/macro_op_32.d: Likewise. * testsuite/ld-loongarch-elf/relax-align.dd: New test. * testsuite/ld-loongarch-elf/relax-align.s: New test. * testsuite/ld-loongarch-elf/relax.exp: New test. * testsuite/ld-loongarch-elf/relax.s: New test. * testsuite/ld-loongarch-elf/uleb128.dd: New test. * testsuite/ld-loongarch-elf/uleb128.s: New test. --- ld/emultempl/loongarchelf.em | 3 + ld/testsuite/ld-elf/compressed1d.d | 3 + ld/testsuite/ld-elf/pr26936.d | 4 +- ld/testsuite/ld-loongarch-elf/disas-jirl-32.d | 2 + ld/testsuite/ld-loongarch-elf/disas-jirl.d | 4 +- ld/testsuite/ld-loongarch-elf/jmp_op.d | 65 +++++++++----- ld/testsuite/ld-loongarch-elf/macro_op.d | 84 +++++++++++++------ ld/testsuite/ld-loongarch-elf/macro_op_32.d | 24 ++++-- ld/testsuite/ld-loongarch-elf/relax-align.dd | 7 ++ ld/testsuite/ld-loongarch-elf/relax-align.s | 9 ++ ld/testsuite/ld-loongarch-elf/relax.exp | 77 +++++++++++++++++ ld/testsuite/ld-loongarch-elf/relax.s | 16 ++++ ld/testsuite/ld-loongarch-elf/uleb128.dd | 10 +++ ld/testsuite/ld-loongarch-elf/uleb128.s | 21 +++++ 14 files changed, 273 insertions(+), 56 deletions(-) create mode 100644 ld/testsuite/ld-loongarch-elf/relax-align.dd create mode 100644 ld/testsuite/ld-loongarch-elf/relax-align.s create mode 100644 ld/testsuite/ld-loongarch-elf/relax.exp create mode 100644 ld/testsuite/ld-loongarch-elf/relax.s create mode 100644 ld/testsuite/ld-loongarch-elf/uleb128.dd create mode 100644 ld/testsuite/ld-loongarch-elf/uleb128.s diff --git a/ld/emultempl/loongarchelf.em b/ld/emultempl/loongarchelf.em index b790f645c9b..4850feb8767 100644 --- a/ld/emultempl/loongarchelf.em +++ b/ld/emultempl/loongarchelf.em @@ -23,6 +23,7 @@ fragment <: [ ]+0:[ ]+1a000014[ ]+pcalau12i[ ]+\$t8,[ ]+0 [ ]+0:[ ]+R_LARCH_PCALA_HI20[ ]+_start +[ ]+0:[ ]+R_LARCH_RELAX[ ]+\*ABS\* [ ]+4:[ ]+02800294[ ]+addi.w[ ]+\$t8,[ ]+\$t8,[ ]+0 [ ]+4:[ ]+R_LARCH_PCALA_LO12[ ]+_start +[ ]+4:[ ]+R_LARCH_RELAX[ ]+\*ABS\* [ ]+8:[ ]+4c000281[ ]+jirl[ ]+\$ra,[ ]+\$t8,[ ]+0 diff --git a/ld/testsuite/ld-loongarch-elf/disas-jirl.d b/ld/testsuite/ld-loongarch-elf/disas-jirl.d index 595c30c7361..eeb8dd05092 100644 --- a/ld/testsuite/ld-loongarch-elf/disas-jirl.d +++ b/ld/testsuite/ld-loongarch-elf/disas-jirl.d @@ -6,9 +6,11 @@ Disassembly of section .text: -00000000.*: +00000000.* <_start>: [ ]+0:[ ]+1a000014[ ]+pcalau12i[ ]+\$t8,[ ]+0 [ ]+0:[ ]+R_LARCH_PCALA_HI20[ ]+_start +[ ]+0:[ ]+R_LARCH_RELAX[ ]+\*ABS\* [ ]+4:[ ]+02c00294[ ]+addi.d[ ]+\$t8,[ ]+\$t8,[ ]+0 [ ]+4:[ ]+R_LARCH_PCALA_LO12[ ]+_start +[ ]+4:[ ]+R_LARCH_RELAX[ ]+\*ABS\* [ ]+8:[ ]+4c000281[ ]+jirl[ ]+\$ra,[ ]+\$t8,[ ]+0 diff --git a/ld/testsuite/ld-loongarch-elf/jmp_op.d b/ld/testsuite/ld-loongarch-elf/jmp_op.d index 218c13f9398..09f89100195 100644 --- a/ld/testsuite/ld-loongarch-elf/jmp_op.d +++ b/ld/testsuite/ld-loongarch-elf/jmp_op.d @@ -6,26 +6,45 @@ Disassembly of section .text: -00000000.* <.text>: -[ ]+0:[ ]+03400000[ ]+[ ]+andi[ ]+\$zero, \$zero, 0x0 -[ ]+4:[ ]+63fffc04[ ]+[ ]+blt[ ]+\$zero, \$a0, -4\(0x3fffc\)[ ]+# 0x0 -[ ]+8:[ ]+67fff880[ ]+[ ]+bge[ ]+\$a0, \$zero, -8\(0x3fff8\)[ ]+# 0x0 -[ ]+c:[ ]+67fff404[ ]+[ ]+bge[ ]+\$zero, \$a0, -12\(0x3fff4\)[ ]+# 0x0 -[ ]+10:[ ]+43fff09f[ ]+[ ]+beqz[ ]+\$a0, -16\(0x7ffff0\)[ ]+# 0x0 -[ ]+14:[ ]+47ffec9f[ ]+[ ]+bnez[ ]+\$a0, -20\(0x7fffec\)[ ]+# 0x0 -[ ]+18:[ ]+4bffe81f[ ]+[ ]+bceqz[ ]+\$fcc0, -24\(0x7fffe8\)[ ]+# 0x0 -[ ]+1c:[ ]+4bffe51f[ ]+[ ]+bcnez[ ]+\$fcc0, -28\(0x7fffe4\)[ ]+# 0x0 -[ ]+20:[ ]+4c000080[ ]+[ ]+jirl[ ]+\$zero, \$a0, 0 -[ ]+24:[ ]+53ffdfff[ ]+[ ]+b[ ]+-36\(0xfffffdc\)[ ]+# 0x0 -[ ]+28:[ ]+57ffdbff[ ]+[ ]+bl[ ]+-40\(0xfffffd8\)[ ]+# 0x0 -[ ]+2c:[ ]+5bffd485[ ]+[ ]+beq[ ]+\$a0, \$a1, -44\(0x3ffd4\)[ ]+# 0x0 -[ ]+30:[ ]+5fffd085[ ]+[ ]+bne[ ]+\$a0, \$a1, -48\(0x3ffd0\)[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LARCH_RELAX[ ]+\*ABS\* [ ]+128:[ ]+16000005[ ]+lu32i.d[ ]+\$a1,[ ]+0 [ ]+128:[ ]+R_LARCH_GOT64_PC_LO20[ ]+TLS1 [ ]+12c:[ ]+030000a5[ ]+lu52i.d[ ]+\$a1,[ ]+\$a1,[ ]+0 @@ -153,10 +187,12 @@ Disassembly of section .text: [ ]+134:[ ]+R_LARCH_TLS_GD_PC_HI20[ ]+TLS1 [ ]+138:[ ]+02c00084[ ]+addi.d[ ]+\$a0,[ ]+\$a0,[ ]+0 [ ]+138:[ ]+R_LARCH_GOT_PC_LO12[ ]+TLS1 +[ ]+138:[ ]+R_LARCH_RELAX[ ]+\*ABS\* [ ]+13c:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0,[ ]+0 [ ]+13c:[ ]+R_LARCH_TLS_GD_PC_HI20[ ]+TLS1 [ ]+140:[ ]+02c00005[ ]+addi.d[ ]+\$a1,[ ]+\$zero,[ ]+0 [ ]+140:[ ]+R_LARCH_GOT_PC_LO12[ ]+TLS1 +[ ]+140:[ ]+R_LARCH_RELAX[ ]+\*ABS\* [ ]+144:[ ]+16000005[ ]+lu32i.d[ ]+\$a1,[ ]+0 [ ]+144:[ ]+R_LARCH_GOT64_PC_LO20[ ]+TLS1 [ ]+148:[ ]+030000a5[ ]+lu52i.d[ ]+\$a1,[ ]+\$a1,[ ]+0 diff --git a/ld/testsuite/ld-loongarch-elf/macro_op_32.d b/ld/testsuite/ld-loongarch-elf/macro_op_32.d index a78c4579ee9..f5a2b54dd9b 100644 --- a/ld/testsuite/ld-loongarch-elf/macro_op_32.d +++ b/ld/testsuite/ld-loongarch-elf/macro_op_32.d @@ -14,29 +14,39 @@ Disassembly of section .text: [ ]+c:[ ]+02bffc04[ ]+addi.w[ ]+\$a0,[ ]+\$zero,[ ]+-1\(0xfff\) [ ]+10:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0,[ ]+0 [ ]+10:[ ]+R_LARCH_GOT_PC_HI20[ ]+.L1 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+TLS1 +[ ]+5c:[ ]+R_LARCH_RELAX[ ]+\*ABS\* diff --git a/ld/testsuite/ld-loongarch-elf/relax-align.dd b/ld/testsuite/ld-loongarch-elf/relax-align.dd new file mode 100644 index 00000000000..3149738ff71 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-align.dd @@ -0,0 +1,7 @@ +#... +.*pcaddi.* +.*pcaddi.* +.*andi.* +.*andi.* +.*0:.*pcaddi.* +#pass diff --git a/ld/testsuite/ld-loongarch-elf/relax-align.s b/ld/testsuite/ld-loongarch-elf/relax-align.s new file mode 100644 index 00000000000..9617c02d8e5 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-align.s @@ -0,0 +1,9 @@ +# relax-align.o has 3 andi(nop) insns. +# relax-align has 2 andi insns, ld relax delete andi insns. +# the last pcaddi 16 bytes align. + .text +L1: + la.local $a0, L1 + la.local $a0, L1 + .align 4 + la.local $a0, L1 diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp new file mode 100644 index 00000000000..7ff876d7914 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax.exp @@ -0,0 +1,77 @@ +# Expect script for LoongArch ELF linker tests +# Copyright (C) 2022 Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +if [istarget loongarch64-*-*] { + + if [isbuild loongarch64-*-*] { + set testname "loongarch relax build" + set pre_builds [list \ + [list \ + "$testname" \ + "" \ + "" \ + {relax.s} \ + {} \ + "relax" \ + ] \ + ] + + run_cc_link_tests $pre_builds + + if [file exist "tmpdir/relax"] { + set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax"] + if { [ regexp ".*pcaddi.*pcaddi.*" $objdump_output] } { + pass "loongarch relax" + } { + fail "loongarch relax" + } + } + } + + run_ld_link_tests \ + [list \ + [list \ + "relax-align" \ + "-e 0x0 -z relro" "" \ + "" \ + {relax-align.s} \ + [list \ + [list objdump -d relax-align.dd] \ + ] \ + "relax-align" \ + ] \ + ] + + set objdump_flags "-s -j .data" + run_ld_link_tests \ + [list \ + [list \ + "uleb128" \ + "-e 0x0" "" \ + "" \ + {uleb128.s} \ + [list \ + [list objdump $objdump_flags uleb128.dd] \ + ] \ + "uleb128" \ + ] \ + ] +} diff --git a/ld/testsuite/ld-loongarch-elf/relax.s b/ld/testsuite/ld-loongarch-elf/relax.s new file mode 100644 index 00000000000..2979ffa3714 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax.s @@ -0,0 +1,16 @@ + .data + .global a + .type a, @object +a: + .word 123 + + .text + .global main + .type main, @function +main: + la.local $a0, a + ld.w $a1, $a0, 0 + la.global $a0, a + ld.w $a0, $a0, 0 + sub.d $a0, $a0, $a1 + jr $ra diff --git a/ld/testsuite/ld-loongarch-elf/uleb128.dd b/ld/testsuite/ld-loongarch-elf/uleb128.dd new file mode 100644 index 00000000000..c4ad3070ee1 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/uleb128.dd @@ -0,0 +1,10 @@ +.*: .* + +Contents of section .* + [0-9a-f]+ 01020381 01000000 00000000 00000000.* +#... + [0-9a-f]+ 00000004 ffff0500 06078380 01000000.* +#... + [0-9a-f]+ 00000000 00000000 00000008 ffffffff.* + [0-9a-f]+ 09090909 09090909 09090909 09090909.* +#pass diff --git a/ld/testsuite/ld-loongarch-elf/uleb128.s b/ld/testsuite/ld-loongarch-elf/uleb128.s new file mode 100644 index 00000000000..7299fb91a25 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/uleb128.s @@ -0,0 +1,21 @@ +# From gas/all/relax.s, test ld process add_uleb128/sub_uleb128 reloc pair. + .data + .byte 1, 2, 3 + .uleb128 L2 - L1 +L1: + .space 128 - 2 + .byte 4 + .p2align 1, 0xff +L2: + .byte 5 + + .p2align 2 + .byte 6, 7 + .uleb128 L4 - L3 +L3: + .space 128*128 - 2 + .byte 8 + .p2align 2, 0xff +L4: + .byte 9 + .p2align 4, 9 -- 2.30.2