]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-gc/gc.exp
ld: Pass -fno-sanitize=all to tests with linker
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-gc / gc.exp
CommitLineData
ac69cbc6 1# Expect script for ld-gc tests
b3adc24a 2# Copyright (C) 2008-2020 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
1949ad04
L
26global NOSANTIZE_CFLAGS
27
28set cflags "-ffunction-sections -fdata-sections $NOSANTIZE_CFLAGS"
ac69cbc6
TG
29set objfile "tmpdir/gc.o"
30
9d1c54ed
L
31# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
32global NOPIE_CFLAGS NOPIE_LDFLAGS
33
2893311c
AM
34if [istarget powerpc64*-*-*] {
35 # otherwise with -mcmodel=medium gcc we get XPASSes.
36 set cflags "$cflags -mminimal-toc"
37}
38
6927f982
NC
39if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] } {
40 # Otherwise tests FAIL due to _.frame
41 set cflags "$cflags -fomit-frame-pointer -mshort"
42}
43
44ed8092 44if { [check_compiler_available] } {
3becfab9
HPN
45 ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/gc.c $objfile
46}
ac69cbc6
TG
47
48proc test_gc { testname filename linker ldflags} {
49 global nm
50 global srcdir
51 global subdir
52 global nm_output
53 global objfile
54
3becfab9
HPN
55 if ![file readable $objfile ] {
56 untested $testname
57 return
58 }
59
ac69cbc6 60 set outfile "tmpdir/$filename"
1b662205 61 set options "-L$srcdir/$subdir"
d9816402 62 append options " " $ldflags " " [ld_link_defsyms] " " $objfile
ac69cbc6 63
d9816402 64 if ![ld_link $linker $outfile $options] {
0d600a79 65 fail $testname
ac69cbc6
TG
66 return
67 }
68 if ![ld_nm $nm "" $outfile] {
69 unresolved $testname
70 return
71 }
72 if {![info exists nm_output(used_func)] \
73 || ![info exists nm_output(used_var)]} {
74 send_log "used sections do not exist\n"
75 verbose "used sections do not exist"
76 fail $testname
77 return
78 }
0d600a79
AM
79 #ppc64_elf_gc_mark_hook needs to be taught how to look through
80 #the .toc section to properly mark variable sections for gc.
81 setup_xfail "powerpc64*-*-*"
ac69cbc6
TG
82 if {[info exists nm_output(unused_func)] \
83 || [info exists nm_output(unused_var)]} {
84 send_log "unused section still here\n"
85 verbose "unused section still here"
86 fail $testname
87 return
88 }
89 pass $testname
90}
91
92test_gc "Check --gc-section" "gcexe" $ld "--gc-sections -e main"
93test_gc "Check --gc-section/-q" "gcrexe" $ld "--gc-sections -q -e main"
94test_gc "Check --gc-section/-r/-e" "gcrel" $ld "-r --gc-sections -e main"
95test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func"
96
97run_dump_test "noent"
16583161 98run_dump_test "abi-note"
bde6f3eb 99run_dump_test "start"
040b4a9e 100run_dump_test "stop"
be83aa76 101run_dump_test "pr19167"
d422d1c4
SKS
102if { [is_elf_format] } then {
103 run_dump_test "all-debug-sections"
b7c871ed 104 run_dump_test "pr20882"
d422d1c4 105}
1d5316ab
AM
106
107if { [is_elf_format] && [check_shared_lib_support] } then {
108 set gasopt ""
109 if { [istarget tic6x-*] } then {
110 set gasopt "-mpic -mpid=near"
111 }
8988502d
MR
112 # These targets do not default to linking with shared libraries.
113 set old_ldflags $LDFLAGS
114 if { [istarget "mips*vr4100*-*-elf*"] \
115 || [istarget "mips*vr4300*-*-elf*"] \
116 || [istarget "mips*vr5000*-*-elf*"] } {
117 append LDFLAGS " -call_shared"
118 }
1d5316ab 119 if {![ld_assemble_flags $as $gasopt $srcdir/$subdir/libpersonality.s tmpdir/libpersonality.o]
d9816402 120 || ![ld_link $ld tmpdir/libpersonality.so "-shared tmpdir/libpersonality.o"] } then {
1d5316ab
AM
121 fail libpersonality
122 } else {
ed381877 123 run_dump_test "personality"
1d5316ab 124 }
11e6e4c7 125 run_dump_test "pr18223"
cbd0eecf
L
126 if {![ld_assemble_flags $as $gasopt $srcdir/$subdir/pr20022a.s tmpdir/pr20022a.o]
127 || ![ld_link $ld tmpdir/pr20022.so "-shared --gc-sections tmpdir/pr20022a.o"] } then {
128 fail pr20022
129 } else {
130 run_dump_test "pr20022"
131 }
8988502d 132 set LDFLAGS $old_ldflags
1d5316ab
AM
133}
134
44ed8092 135if { [check_compiler_available] } {
5940a93c 136 if { [istarget "*-*-linux*"]
5a68afcf 137 || [istarget "*-*-nacl*"]
5940a93c 138 || [istarget "*-*-gnu*"] } {
98da7939 139 ld_compile "$CC -fPIC $CFLAGS $cflags" $srcdir/$subdir/pr11218-1.c tmpdir/pr11218-1.o
d9816402 140 ld_link $ld tmpdir/pr11218-1.so "-shared tmpdir/pr11218-1.o"
98da7939
L
141 ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/pr11218-2.c tmpdir/pr11218-2.o
142 run_dump_test "pr11218"
143 }
144}
2aa9aad9 145
44ed8092 146if { [check_compiler_available] } {
2aa9aad9
NC
147 ld_compile "$CC $CFLAGS $cflags" $srcdir/$subdir/pr13683.c tmpdir/pr13683.o
148 run_dump_test "pr13683"
149}
b9b2ae8b 150
44ed8092 151if { [check_compiler_available] } {
9d1c54ed 152 ld_compile "$CC $CFLAGS $cflags $NOPIE_CFLAGS" $srcdir/$subdir/pr14265.c tmpdir/pr14265.o
b9b2ae8b
NC
153 run_dump_test "pr14265"
154}
bba037e0 155
44ed8092 156if { [check_compiler_available] } {
bba037e0
L
157 ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-1.c tmpdir/pr19161-1.o
158 ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-2.c tmpdir/pr19161-2.o
1c1a69dc
JDA
159 set saved_LDFLAGS "$LDFLAGS"
160 if [istarget hppa*-*-linux*] {
161 set LDFLAGS "$LDFLAGS --defsym '\$\$dyncall=0'"
162 }
bba037e0 163 run_dump_test "pr19161"
1c1a69dc 164 set LDFLAGS "$saved_LDFLAGS"
bba037e0 165}
f4ab0e2d
L
166
167if { [is_elf_format] && [check_shared_lib_support] \
44ed8092 168 && [check_compiler_available] } {
f4ab0e2d
L
169 run_cc_link_tests [list \
170 [list \
171 "Build libpr20306.so" \
172 "-shared" \
173 "-fPIC" \
174 {pr20306.c} \
175 {} \
176 "libpr20306.so" \
177 ] \
178 ]
179 run_dump_test "pr20306"
180}
035801ce 181
86333705
FS
182if { [is_elf_format] } then {
183 run_dump_test "skip-map-discarded"
184}