Commit | Line | Data |
---|---|---|
ac69cbc6 | 1 | # Expect script for ld-gc tests |
5a68afcf | 2 | # Copyright 2008, 2009, 2010, 2012 |
ac69cbc6 TG |
3 | # Free Software Foundation, Inc. |
4 | # | |
5 | # This file is part of the GNU Binutils. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 3 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program; if not, write to the Free Software | |
19 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
20 | # MA 02110-1301, USA. | |
21 | ||
22 | # These tests require --gc-sections | |
23 | if ![check_gc_sections_available] { | |
24 | return | |
25 | } | |
26 | ||
27 | set cflags "-ffunction-sections -fdata-sections" | |
28 | set objfile "tmpdir/gc.o" | |
29 | ||
2893311c AM |
30 | if [istarget powerpc64*-*-*] { |
31 | # otherwise with -mcmodel=medium gcc we get XPASSes. | |
32 | set cflags "$cflags -mminimal-toc" | |
33 | } | |
34 | ||
6927f982 NC |
35 | if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] } { |
36 | # Otherwise tests FAIL due to _.frame | |
37 | set cflags "$cflags -fomit-frame-pointer -mshort" | |
38 | } | |
39 | ||
d053948a | 40 | if { [is_remote host] || [which $CC] != 0 } { |
3becfab9 HPN |
41 | ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/gc.c $objfile |
42 | } | |
ac69cbc6 TG |
43 | |
44 | proc test_gc { testname filename linker ldflags} { | |
45 | global nm | |
46 | global srcdir | |
47 | global subdir | |
48 | global nm_output | |
49 | global objfile | |
50 | ||
3becfab9 HPN |
51 | if ![file readable $objfile ] { |
52 | untested $testname | |
53 | return | |
54 | } | |
55 | ||
ac69cbc6 | 56 | set outfile "tmpdir/$filename" |
1b662205 AM |
57 | set options "-L$srcdir/$subdir" |
58 | append options " " $ldflags " " [ld_simple_link_defsyms] " " $objfile | |
ac69cbc6 | 59 | |
22fe6da0 KK |
60 | # SH64 targets needs an extra ld option for this test. |
61 | if [istarget sh64*-*-*] { | |
62 | if [istarget sh64*l*-*-*] { | |
63 | set options "-mshlelf32 $options" | |
64 | } else { | |
65 | set options "-mshelf32 $options" | |
66 | } | |
67 | } | |
68 | ||
69 | if ![ld_simple_link $linker $outfile $options] { | |
0d600a79 | 70 | fail $testname |
ac69cbc6 TG |
71 | return |
72 | } | |
73 | if ![ld_nm $nm "" $outfile] { | |
74 | unresolved $testname | |
75 | return | |
76 | } | |
77 | if {![info exists nm_output(used_func)] \ | |
78 | || ![info exists nm_output(used_var)]} { | |
79 | send_log "used sections do not exist\n" | |
80 | verbose "used sections do not exist" | |
81 | fail $testname | |
82 | return | |
83 | } | |
0d600a79 AM |
84 | #ppc64_elf_gc_mark_hook needs to be taught how to look through |
85 | #the .toc section to properly mark variable sections for gc. | |
86 | setup_xfail "powerpc64*-*-*" | |
ac69cbc6 TG |
87 | if {[info exists nm_output(unused_func)] \ |
88 | || [info exists nm_output(unused_var)]} { | |
89 | send_log "unused section still here\n" | |
90 | verbose "unused section still here" | |
91 | fail $testname | |
92 | return | |
93 | } | |
94 | pass $testname | |
95 | } | |
96 | ||
97 | test_gc "Check --gc-section" "gcexe" $ld "--gc-sections -e main" | |
98 | test_gc "Check --gc-section/-q" "gcrexe" $ld "--gc-sections -q -e main" | |
99 | test_gc "Check --gc-section/-r/-e" "gcrel" $ld "-r --gc-sections -e main" | |
100 | test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func" | |
101 | ||
102 | run_dump_test "noent" | |
16583161 | 103 | run_dump_test "abi-note" |
bde6f3eb | 104 | run_dump_test "start" |
1d5316ab AM |
105 | |
106 | if { [is_elf_format] && [check_shared_lib_support] } then { | |
107 | set gasopt "" | |
108 | if { [istarget tic6x-*] } then { | |
109 | set gasopt "-mpic -mpid=near" | |
110 | } | |
111 | if {![ld_assemble_flags $as $gasopt $srcdir/$subdir/libpersonality.s tmpdir/libpersonality.o] | |
112 | || ![ld_simple_link $ld tmpdir/libpersonality.so "-shared tmpdir/libpersonality.o"] } then { | |
113 | fail libpersonality | |
114 | } else { | |
115 | run_dump_test "personality" | |
116 | } | |
117 | } | |
118 | ||
98da7939 | 119 | if { [is_remote host] || [which $CC] != 0 } { |
5940a93c | 120 | if { [istarget "*-*-linux*"] |
5a68afcf | 121 | || [istarget "*-*-nacl*"] |
5940a93c | 122 | || [istarget "*-*-gnu*"] } { |
98da7939 L |
123 | ld_compile "$CC -fPIC $CFLAGS $cflags" $srcdir/$subdir/pr11218-1.c tmpdir/pr11218-1.o |
124 | ld_simple_link $ld tmpdir/pr11218-1.so "-shared tmpdir/pr11218-1.o" | |
125 | ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/pr11218-2.c tmpdir/pr11218-2.o | |
126 | run_dump_test "pr11218" | |
127 | } | |
128 | } | |
2aa9aad9 NC |
129 | |
130 | if { [is_remote host] || [which $CC] != 0 } { | |
131 | ld_compile "$CC $CFLAGS $cflags" $srcdir/$subdir/pr13683.c tmpdir/pr13683.o | |
132 | run_dump_test "pr13683" | |
133 | } |