summaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-loongarch-elf/relax.exp
blob: 77323d8d7a3a0bbd28144178657ce8af225bd88a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# 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 .exe 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 .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"
      }
    }

    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.
    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" \
	    ] \
	]
  }

  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" \
	  ] \
      ]
}