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