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