Support the use of the STT_COMMON type. (In source and object files only at the...
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elfcomm / elfcomm.exp
CommitLineData
09bf9720 1# Expect script for common symbol tests
f96b4a7b 2# Copyright 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
ca4fa240 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
ca4fa240 7# it under the terms of the GNU General Public License as published by
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
ca4fa240 9# (at your option) any later version.
f96b4a7b 10#
ca4fa240
NC
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.
f96b4a7b 15#
ca4fa240
NC
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
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
ca4fa240
NC
20#
21# Written by H.J. Lu (hjl@gnu.org)
22#
23
24# Make sure that ld correctly handles common symbols in ELF.
25
26# This test can only be run on ELF platforms.
43f9d75b 27if ![is_elf_format] {
ca4fa240
NC
28 return
29}
30
b814bbcb
L
31set test1 "size/aligment change of common symbols"
32set test1w1 "$test1 (warning 1)"
33set test1w2 "$test1 (warning 2)"
34set test1c1 "$test1 (change 1)"
35set test1c2 "$test1 (change 2)"
36
7f6a71ff 37if { ![is_remote host] && [which $CC] == 0 } {
b814bbcb
L
38 untested $test1w1
39 untested $test1w2
40 untested $test1c1
41 untested $test1c2
42 return
43}
1c0d3aa6
NC
44if { [istarget score-*-*] } {
45 untested $test1w1
46 untested $test1w2
47 untested $test1c1
48 untested $test1c2
49 return
50}
b814bbcb 51
ca4fa240
NC
52proc dump_common1 { testname } {
53 global exec_output
a42ec05b 54 global READELF
ca4fa240 55
504b7d20
NC
56 send_log "$READELF --syms tmpdir/common1.o | grep foo\n"
57 set exec_output [run_host_cmd "readelf" "--syms tmpdir/common1.o | grep foo"]
7f6a71ff 58
504b7d20
NC
59 if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+)4(\[ \]+)(COMMON|OBJECT)(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output]
60 || ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)21(\[ \]+)OBJECT(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo1" $exec_output] } {
ca4fa240
NC
61 verbose $exec_output
62 fail $testname
63 return 0
64 }
65
66 return 1
67}
68
504b7d20
NC
69proc stt_common_test { options testname } {
70 global exec_output
71 global READELF
72 global ld
73
74 set options "$options tmpdir/common1a.o"
75
76 if { ! [ld_simple_link $ld tmpdir/common.exe $options] } {
77 unresolved $testname
78 return 0
79 }
80
81 send_log "$READELF --syms tmpdir/common.exe | grep foo\n"
82 set exec_output [run_host_cmd "readelf" "--syms tmpdir/common.exe | grep foo"]
83
84 if {![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)(\[0-9\]+)(\[ \]+)COMMON(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo2" $exec_output] } {
85 fail $testname
86 return 0
87 }
88
89 pass $testname
90 return 1
91}
92
93# Check to see if the assembler is generating symbols with the STT_COMMON type.
94proc assembler_generates_commons {} {
95 global exec_output
96 global READELF
97
98 verbose "Check to see if STT_COMMON symbols are being generated:"
99 set exec_output [run_host_cmd "readelf" "--syms tmpdir/common1a.o | grep foo"]
100
101 if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+).(\[ \]+)COMMON(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output] } {
102 verbose "STT_COMMON not generated"
103 return 0
104 }
105
106 verbose "STT_COMMON's are generated"
107 return 1
108}
109
110
111if { ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
ca4fa240
NC
112 || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } {
113 unresolved $test1
114 return
115}
116
117global ld
118global link_output
119
120if { [ld_simple_link $ld tmpdir/common1.o "-r tmpdir/common1a.o tmpdir/common1b.o"] } {
b814bbcb 121 unresolved $test1w1
ca4fa240
NC
122 return
123}
124
674e82fc
TS
125# This test fails on MIPS because the backend sets type_change_ok.
126# The size change warning is suppressed.
127if {[istarget mips*-*-*]} {
128 if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
129 fail $test1w1
a5e0d269 130 } else {
674e82fc 131 pass $test1w1
a5e0d269 132 }
ca4fa240 133} else {
674e82fc
TS
134 if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output]
135 || ![regexp "Warning: size of symbol \`_?foo1\' changed from 2 in tmpdir/common1a.o to 21 in tmpdir/common1b.o" $link_output] } {
136 fail $test1w1
137 } else {
138 pass $test1w1
139 }
ca4fa240
NC
140}
141
b814bbcb
L
142if { [dump_common1 $test1c1] } {
143 pass $test1c1
ca4fa240
NC
144}
145
146if { [ld_simple_link $ld tmpdir/common1.o "-r tmpdir/common1b.o tmpdir/common1a.o"] } {
b814bbcb 147 unresolved $test1w2
ca4fa240
NC
148 return
149}
150
09bf9720 151if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
b814bbcb 152 fail $test1w2
ca4fa240 153} else {
b814bbcb 154 pass $test1w2
ca4fa240
NC
155}
156
b814bbcb
L
157if { [dump_common1 $test1c2] } {
158 pass $test1c2
ca4fa240 159}
504b7d20
NC
160
161#
162# The following tests are for when we are generating STT_COMMON symbols only.
163#
164
165if { ![assembler_generates_commons] } {
166 return
167}
168
169stt_common_test "-static -e 0" "static link of common symbols"
170stt_common_test "-shared" "shared link of common symbols"
171stt_common_test "-pie" "position independent link of common symbols"
172
This page took 0.20322 seconds and 4 git commands to generate.