# Expect script for LoongArch ELF linker tests # Copyright (C) 2022-2024 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 .exe build" set pre_builds [list \ [list \ "$testname" \ "" \ "" \ {relax.s} \ {} \ "relax" \ ] \ ] set tls_relax_builds [list \ [list \ "tls_relax_builds" \ "" \ "" \ {relax-tls-le.s} \ {} \ "relax-tls-le" \ ] \ ] set tls_no_relax_builds [list \ [list \ "tls_no_relax_builds" \ "-Wl,--no-relax" \ "" \ {relax-tls-le.s} \ {} \ "no-relax-tls-le" \ ] \ ] set relax_bound_check [list \ [list \ "relax_bound_check" \ "" \ "" \ {relax-bound-check-tls-le.s} \ {} \ "relax-bound-check-tls-le" \ ] \ ] set no_relax_bound_check [list \ [list \ "no_relax_bound_check" \ "-Wl,--no-relax" \ "" \ {relax-bound-check-tls-le.s} \ {} \ "no-relax-bound-check-tls-le" \ ] \ ] set old_tls_le [list \ [list \ "old_tls_le" \ "" \ "" \ {old-tls-le.s} \ {} \ "old-tls-le" \ ] \ ] set relax_compatible [list \ [list \ "relax_compatible" \ "" \ "" \ {tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \ {} \ "realx-compatible" \ ] \ ] set no_relax_compatible [list \ [list \ "no_relax_compatible" \ "-Wl,--no-relax" \ "" \ {tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \ {} \ "no-realx-compatible" \ ] \ ] run_cc_link_tests $pre_builds run_cc_link_tests $tls_relax_builds run_cc_link_tests $tls_no_relax_builds run_cc_link_tests $relax_bound_check run_cc_link_tests $no_relax_bound_check run_cc_link_tests $old_tls_le run_cc_link_tests $relax_compatible run_cc_link_tests $no_relax_compatible if [file exist "tmpdir/relax"] { set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax"] if { [ regexp ".*pcaddi.*pcaddi.*" $objdump_output] } { pass "loongarch relax .exe" } { fail "loongarch relax .exe" } } set testname "loongarch ld --no-relax build" set pre_builds [list \ [list \ "$testname" \ "-Wl,--no-relax" \ "" \ {relax.s} \ {} \ "norelax" \ ] \ ] run_cc_link_tests $pre_builds if [file exist "tmpdir/norelax"] { set objdump_output [run_host_cmd "objdump" "-d tmpdir/norelax"] if { [ regexp ".*pcaddi.*" $objdump_output] } { fail "loongarch ld --no-relax" } { pass "loongarch ld --no-relax" } } if [check_shared_lib_support] { run_ld_link_tests \ [list \ [list \ "loongarch relax .so build" \ "-shared -e 0x0" "" \ "" \ {relax-so.s} \ {} \ "relax-so" \ ] \ ] } if [file exist "tmpdir/relax-so"] { set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-so"] if { [ regexp ".*pcaddi.*" $objdump_output] } { pass "loongarch relax .so" } { fail "loongarch relax .so" } } # If symbol in data segment, offset need to sub segment align to prevent # overflow. if [check_pie_support] { run_ld_link_tests \ [list \ [list \ "loongarch relax segment alignment min" \ "-e0 -Ttext 0x120004000 -pie -z relro" "" \ "" \ {relax-segment-min.s} \ {} \ "relax-segment-min" \ ] \ ] run_ld_link_tests \ [list \ [list \ "loongarch relax segment alignment max" \ "-e0 -Ttext 0x120004000 -pie -z relro" "" \ "" \ {relax-segment-max.s} \ {} \ "relax-segment-max" \ ] \ ] } if [file exist "tmpdir/relax-tls-le"] { set objdump_output1 [run_host_cmd "objdump" "-d tmpdir/relax-tls-le"] if { [ regexp ".addi.*st.*" $objdump_output1] } { pass "loongarch relax success" } { fail "loongarch relax fail" } } if [file exist "tmpdir/no-relax-tls-le"] { set objdump_output2 [run_host_cmd "objdump" "-d tmpdir/no-relax-tls-le"] if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output2] } { pass "loongarch no-relax success" } { fail "loongarch no-relax fail" } } if [file exist "tmpdir/old-tls-le"] { set objdump_output3 [run_host_cmd "objdump" "-d tmpdir/old-tls-le"] if { [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output3] } { pass "loongarch old tls le success" } { fail "loongarch old tls le fail" } } if [file exist "tmpdir/realx-compatible"] { set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/realx-compatible"] if { [ regexp ".addi.*st.*" $objdump_output4] && \ [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output4] } { pass "loongarch tls le relax compatible check success" } { fail "loongarch tls le relax compatible check fail" } } if [file exist "tmpdir/no-realx-compatible"] { set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/realx-compatible"] if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output4] && \ [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output4] } { pass "loongarch tls le no-relax compatible check success" } { fail "loongarch tls le no-relax compatible check fail" } } if [file exist "tmpdir/relax-bound-check-tls-le"] { set objdump_output5 [run_host_cmd "objdump" "-d tmpdir/relax-bound-check-tls-le"] if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output5] && \ [ regexp ".addi.*st.*" $objdump_output5] } { pass "loongarch no-relax success" } { fail "loongarch no-relax fail" } } if [file exist "tmpdir/no-relax-bound-check-tls-le"] { set objdump_output5 [run_host_cmd "objdump" "-d tmpdir/no-relax-bound-check-tls-le"] if { [ regexp ".*addi.*st.*" $objdump_output5] } { pass "loongarch no-relax success" } { fail "loongarch no-relax fail" } } } if [check_shared_lib_support] { run_ld_link_tests \ [list \ [list \ "loongarch relax-align" \ "-e 0x0 -z relro" "" \ "--no-warn" \ {relax-align.s} \ [list \ [list objdump -d relax-align.dd] \ ] \ "relax-align" \ ] \ ] } set objdump_flags "-s -j .data" run_ld_link_tests \ [list \ [list \ "loongarch uleb128" \ "-e 0x0" "" \ "" \ {uleb128.s} \ [list \ [list objdump $objdump_flags uleb128.dd] \ ] \ "uleb128" \ ] \ ] }