Commit | Line | Data |
---|---|---|
ac69cbc6 | 1 | # Expect script for ld-gc tests |
82704155 | 2 | # Copyright (C) 2008-2019 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 | |
d9816402 | 62 | if ![ld_link $linker $outfile $options] { |
0d600a79 | 63 | fail $testname |
ac69cbc6 TG |
64 | return |
65 | } | |
66 | if ![ld_nm $nm "" $outfile] { | |
67 | unresolved $testname | |
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 | } | |
0d600a79 AM |
77 | #ppc64_elf_gc_mark_hook needs to be taught how to look through |
78 | #the .toc section to properly mark variable sections for gc. | |
79 | setup_xfail "powerpc64*-*-*" | |
ac69cbc6 TG |
80 | if {[info exists nm_output(unused_func)] \ |
81 | || [info exists nm_output(unused_var)]} { | |
82 | send_log "unused section still here\n" | |
83 | verbose "unused section still here" | |
84 | fail $testname | |
85 | return | |
86 | } | |
87 | pass $testname | |
88 | } | |
89 | ||
90 | test_gc "Check --gc-section" "gcexe" $ld "--gc-sections -e main" | |
91 | test_gc "Check --gc-section/-q" "gcrexe" $ld "--gc-sections -q -e main" | |
92 | test_gc "Check --gc-section/-r/-e" "gcrel" $ld "-r --gc-sections -e main" | |
93 | test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func" | |
94 | ||
95 | run_dump_test "noent" | |
16583161 | 96 | run_dump_test "abi-note" |
bde6f3eb | 97 | run_dump_test "start" |
040b4a9e | 98 | run_dump_test "stop" |
be83aa76 | 99 | run_dump_test "pr19167" |
d422d1c4 SKS |
100 | if { [is_elf_format] } then { |
101 | run_dump_test "all-debug-sections" | |
b7c871ed | 102 | run_dump_test "pr20882" |
d422d1c4 | 103 | } |
1d5316ab AM |
104 | |
105 | if { [is_elf_format] && [check_shared_lib_support] } then { | |
106 | set gasopt "" | |
107 | if { [istarget tic6x-*] } then { | |
108 | set gasopt "-mpic -mpid=near" | |
109 | } | |
8988502d MR |
110 | # These targets do not default to linking with shared libraries. |
111 | set old_ldflags $LDFLAGS | |
112 | if { [istarget "mips*vr4100*-*-elf*"] \ | |
113 | || [istarget "mips*vr4300*-*-elf*"] \ | |
114 | || [istarget "mips*vr5000*-*-elf*"] } { | |
115 | append LDFLAGS " -call_shared" | |
116 | } | |
1d5316ab | 117 | if {![ld_assemble_flags $as $gasopt $srcdir/$subdir/libpersonality.s tmpdir/libpersonality.o] |
d9816402 | 118 | || ![ld_link $ld tmpdir/libpersonality.so "-shared tmpdir/libpersonality.o"] } then { |
1d5316ab AM |
119 | fail libpersonality |
120 | } else { | |
ed381877 | 121 | run_dump_test "personality" |
1d5316ab | 122 | } |
11e6e4c7 | 123 | run_dump_test "pr18223" |
cbd0eecf L |
124 | if {![ld_assemble_flags $as $gasopt $srcdir/$subdir/pr20022a.s tmpdir/pr20022a.o] |
125 | || ![ld_link $ld tmpdir/pr20022.so "-shared --gc-sections tmpdir/pr20022a.o"] } then { | |
126 | fail pr20022 | |
127 | } else { | |
128 | run_dump_test "pr20022" | |
129 | } | |
8988502d | 130 | set LDFLAGS $old_ldflags |
1d5316ab AM |
131 | } |
132 | ||
98da7939 | 133 | if { [is_remote host] || [which $CC] != 0 } { |
5940a93c | 134 | if { [istarget "*-*-linux*"] |
5a68afcf | 135 | || [istarget "*-*-nacl*"] |
5940a93c | 136 | || [istarget "*-*-gnu*"] } { |
98da7939 | 137 | ld_compile "$CC -fPIC $CFLAGS $cflags" $srcdir/$subdir/pr11218-1.c tmpdir/pr11218-1.o |
d9816402 | 138 | ld_link $ld tmpdir/pr11218-1.so "-shared tmpdir/pr11218-1.o" |
98da7939 L |
139 | ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/pr11218-2.c tmpdir/pr11218-2.o |
140 | run_dump_test "pr11218" | |
141 | } | |
142 | } | |
2aa9aad9 NC |
143 | |
144 | if { [is_remote host] || [which $CC] != 0 } { | |
145 | ld_compile "$CC $CFLAGS $cflags" $srcdir/$subdir/pr13683.c tmpdir/pr13683.o | |
146 | run_dump_test "pr13683" | |
147 | } | |
b9b2ae8b NC |
148 | |
149 | if { [is_remote host] || [which $CC] != 0 } { | |
9d1c54ed | 150 | ld_compile "$CC $CFLAGS $cflags $NOPIE_CFLAGS" $srcdir/$subdir/pr14265.c tmpdir/pr14265.o |
b9b2ae8b NC |
151 | run_dump_test "pr14265" |
152 | } | |
bba037e0 L |
153 | |
154 | if { [is_remote host] || [which $CC] != 0 } { | |
155 | ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-1.c tmpdir/pr19161-1.o | |
156 | ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-2.c tmpdir/pr19161-2.o | |
157 | run_dump_test "pr19161" | |
158 | } | |
f4ab0e2d L |
159 | |
160 | if { [is_elf_format] && [check_shared_lib_support] \ | |
161 | && ([is_remote host] || [which $CC] != 0) } { | |
162 | run_cc_link_tests [list \ | |
163 | [list \ | |
164 | "Build libpr20306.so" \ | |
165 | "-shared" \ | |
166 | "-fPIC" \ | |
167 | {pr20306.c} \ | |
168 | {} \ | |
169 | "libpr20306.so" \ | |
170 | ] \ | |
171 | ] | |
172 | run_dump_test "pr20306" | |
173 | } | |
035801ce FS |
174 | |
175 | run_dump_test "skip-map-discarded" |