]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-gc/gc.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-gc / gc.exp
CommitLineData
ac69cbc6 1# Expect script for ld-gc tests
fd67aa11 2# Copyright (C) 2008-2024 Free Software Foundation, Inc.
ac69cbc6
TG
3#
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
20
21# These tests require --gc-sections
22if ![check_gc_sections_available] {
23 return
24}
25
c6d47bff 26set cflags "-ffunction-sections -fdata-sections $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
ac69cbc6
TG
27set objfile "tmpdir/gc.o"
28
c560184e
AM
29if { [istarget powerpc*-*-*] && ![istarget powerpc64*-*-*] } {
30 # Avoid using .got2 for powerpc -m32
31 set cflags "$cflags $NOPIE_CFLAGS"
2893311c
AM
32}
33
6927f982
NC
34if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] } {
35 # Otherwise tests FAIL due to _.frame
36 set cflags "$cflags -fomit-frame-pointer -mshort"
37}
38
44ed8092 39if { [check_compiler_available] } {
669d5115 40 ld_compile "$CC_FOR_TARGET -c $cflags" $srcdir/$subdir/gc.c $objfile
3becfab9 41}
ac69cbc6
TG
42
43proc test_gc { testname filename linker ldflags} {
44 global nm
45 global srcdir
46 global subdir
47 global nm_output
48 global objfile
49
3becfab9
HPN
50 if ![file readable $objfile ] {
51 untested $testname
52 return
53 }
54
ac69cbc6 55 set outfile "tmpdir/$filename"
1b662205 56 set options "-L$srcdir/$subdir"
68cb2183
AM
57 if [is_pecoff_format] {
58 append ldflags " --image-base 0"
59 }
d9816402 60 append options " " $ldflags " " [ld_link_defsyms] " " $objfile
ac69cbc6 61
d9816402 62 if ![ld_link $linker $outfile $options] {
0d600a79 63 fail $testname
ac69cbc6
TG
64 return
65 }
66 if ![ld_nm $nm "" $outfile] {
348fe36b 67 fail $testname
ac69cbc6
TG
68 return
69 }
70 if {![info exists nm_output(used_func)] \
71 || ![info exists nm_output(used_var)]} {
72 send_log "used sections do not exist\n"
73 verbose "used sections do not exist"
74 fail $testname
75 return
76 }
77 if {[info exists nm_output(unused_func)] \
78 || [info exists nm_output(unused_var)]} {
79 send_log "unused section still here\n"
80 verbose "unused section still here"
81 fail $testname
82 return
83 }
84 pass $testname
85}
86
87test_gc "Check --gc-section" "gcexe" $ld "--gc-sections -e main"
88test_gc "Check --gc-section/-q" "gcrexe" $ld "--gc-sections -q -e main"
89test_gc "Check --gc-section/-r/-e" "gcrel" $ld "-r --gc-sections -e main"
90test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func"
91
68cb2183
AM
92set old_ldflags $LDFLAGS
93if [is_pecoff_format] {
94 append LDFLAGS " --image-base 0"
95}
270f32fc
AM
96set old_asflags $ASFLAGS
97if [is_underscore_target] {
68cb2183 98 append ASFLAGS " --defsym UNDERSCORE=1"
270f32fc
AM
99}
100
ac69cbc6 101run_dump_test "noent"
270f32fc 102
d422d1c4 103if { [is_elf_format] } then {
270f32fc 104 run_dump_test "abi-note"
d422d1c4 105 run_dump_test "all-debug-sections"
270f32fc 106 run_dump_test "pr19167"
b7c871ed 107 run_dump_test "pr20882"
270f32fc
AM
108 run_dump_test "stop"
109 run_dump_test "start"
110 run_dump_test "start2"
5789f845
AM
111 run_dump_test "start3"
112 run_dump_test "start4"
d422d1c4 113}
1d5316ab
AM
114
115if { [is_elf_format] && [check_shared_lib_support] } then {
116 set gasopt ""
117 if { [istarget tic6x-*] } then {
118 set gasopt "-mpic -mpid=near"
119 }
8988502d 120 # These targets do not default to linking with shared libraries.
68cb2183 121 set save_ldflags $LDFLAGS
8988502d
MR
122 if { [istarget "mips*vr4100*-*-elf*"] \
123 || [istarget "mips*vr4300*-*-elf*"] \
124 || [istarget "mips*vr5000*-*-elf*"] } {
125 append LDFLAGS " -call_shared"
126 }
1d5316ab 127 if {![ld_assemble_flags $as $gasopt $srcdir/$subdir/libpersonality.s tmpdir/libpersonality.o]
d9816402 128 || ![ld_link $ld tmpdir/libpersonality.so "-shared tmpdir/libpersonality.o"] } then {
1d5316ab
AM
129 fail libpersonality
130 } else {
ed381877 131 run_dump_test "personality"
1d5316ab 132 }
11e6e4c7 133 run_dump_test "pr18223"
cbd0eecf
L
134 if {![ld_assemble_flags $as $gasopt $srcdir/$subdir/pr20022a.s tmpdir/pr20022a.o]
135 || ![ld_link $ld tmpdir/pr20022.so "-shared --gc-sections tmpdir/pr20022a.o"] } then {
136 fail pr20022
137 } else {
138 run_dump_test "pr20022"
139 }
68cb2183 140 set LDFLAGS $save_ldflags
1d5316ab
AM
141}
142
44ed8092 143if { [check_compiler_available] } {
5940a93c 144 if { [istarget "*-*-linux*"]
5a68afcf 145 || [istarget "*-*-nacl*"]
5940a93c 146 || [istarget "*-*-gnu*"] } {
669d5115 147 ld_compile "$CC_FOR_TARGET -fPIC $cflags" $srcdir/$subdir/pr11218-1.c tmpdir/pr11218-1.o
d9816402 148 ld_link $ld tmpdir/pr11218-1.so "-shared tmpdir/pr11218-1.o"
669d5115 149 ld_compile "$CC_FOR_TARGET -c $cflags" $srcdir/$subdir/pr11218-2.c tmpdir/pr11218-2.o
98da7939
L
150 run_dump_test "pr11218"
151 }
152}
2aa9aad9 153
68cb2183
AM
154set symdefs ""
155if [is_pecoff_format] {
156 set symdefs {{ld {--defsym __main=main --defsym ___main=main}}}
157}
158
44ed8092 159if { [check_compiler_available] } {
669d5115 160 ld_compile "$CC_FOR_TARGET $cflags" $srcdir/$subdir/pr13683.c tmpdir/pr13683.o
68cb2183 161 run_dump_test "pr13683" $symdefs
2aa9aad9 162}
b9b2ae8b 163
44ed8092 164if { [check_compiler_available] } {
669d5115 165 ld_compile "$CC_FOR_TARGET $cflags $NOPIE_CFLAGS" $srcdir/$subdir/pr14265.c tmpdir/pr14265.o
68cb2183 166 run_dump_test "pr14265" $symdefs
b9b2ae8b 167}
bba037e0 168
44ed8092 169if { [check_compiler_available] } {
669d5115
AM
170 ld_compile "$CC_FOR_TARGET $cflags -O0" $srcdir/$subdir/pr19161-1.c tmpdir/pr19161-1.o
171 ld_compile "$CC_FOR_TARGET $cflags -O0" $srcdir/$subdir/pr19161-2.c tmpdir/pr19161-2.o
1c1a69dc 172 if [istarget hppa*-*-linux*] {
68cb2183 173 set symdefs {{ld {--defsym '\$\$dyncall=0'}}}
1c1a69dc 174 }
68cb2183 175 run_dump_test "pr19161" $symdefs
bba037e0 176}
f4ab0e2d
L
177
178if { [is_elf_format] && [check_shared_lib_support] \
44ed8092 179 && [check_compiler_available] } {
f4ab0e2d
L
180 run_cc_link_tests [list \
181 [list \
182 "Build libpr20306.so" \
183 "-shared" \
184 "-fPIC" \
185 {pr20306.c} \
186 {} \
187 "libpr20306.so" \
188 ] \
189 ]
190 run_dump_test "pr20306"
191}
035801ce 192
86333705
FS
193if { [is_elf_format] } then {
194 run_dump_test "skip-map-discarded"
195}
270f32fc
AM
196
197set ASFLAGS $old_asflags
68cb2183 198set LDFLAGS $old_ldflags