1 # Expect script
for common symbol tests
2 # Copyright
2003, 2005, 2006, 2007 Free Software Foundation
, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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
,
21 # Written by H.J. Lu
(hjl@gnu.org
)
24 # Make sure that
ld correctly handles common symbols in ELF.
26 # This test can only be run
on ELF platforms.
31 set test1
"size/aligment change of common symbols"
32 set test1w1
"$test1 (warning 1)"
33 set test1w2
"$test1 (warning 2)"
34 set test1c1
"$test1 (change 1)"
35 set test1c2
"$test1 (change 2)"
37 if { ![is_remote host
] && [which $CC
] == 0 } {
44 if { [istarget score
-*-*] } {
52 proc dump_common1
{ testname
} {
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"]
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] } {
69 proc stt_common_test
{ options testname
} {
74 set options
"$options tmpdir/common1a.o"
76 if { ! [ld_simple_link $
ld tmpdir
/common.exe $options
] } {
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"]
84 if {![regexp
"(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)(\[0-9\]+)(\[ \]+)COMMON(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo2" $exec_output] } {
93 # Check to see
if the assembler is generating symbols with the STT_COMMON type.
94 proc assembler_generates_commons
{} {
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"]
101 if { ![regexp
"(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+).(\[ \]+)COMMON(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output] } {
102 verbose
"STT_COMMON not generated"
106 verbose
"STT_COMMON's are generated"
111 if { ![ld_compile
"$CC $CFLAGS" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
112 ||
![ld_compile
"$CC $CFLAGS" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } {
120 if { [ld_simple_link $
ld tmpdir
/common1.o
"-r tmpdir/common1a.o tmpdir/common1b.o"] } {
125 # This test fails
on MIPS because the backend sets type_change_ok.
126 # The size change warning is suppressed.
127 if {[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] } {
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] } {
142 if { [dump_common1 $test1c1
] } {
146 if { [ld_simple_link $
ld tmpdir
/common1.o
"-r tmpdir/common1b.o tmpdir/common1a.o"] } {
151 if { ![regexp
"Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
157 if { [dump_common1 $test1c2
] } {
162 # The following tests are
for when we are generating STT_COMMON symbols only.
165 if { ![assembler_generates_commons
] } {
169 stt_common_test
"-static -e 0" "static link of common symbols"
170 stt_common_test
"-shared" "shared link of common symbols"
171 stt_common_test
"-pie" "position independent link of common symbols"