1 # Expect script
for common symbol tests
2 # Copyright
(C
) 2003-2019 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 # hpux assembly is weird
32 if [istarget
"hppa*-*-hpux*"] {
36 proc test_sort_common
{} {
44 set test
"--sort-common (descending)"
46 verbose
"Check to see that --sort-common sorts in descending alignment"
48 # We
do not run the
sort common tests
for the DLX target because we know that the linker
49 # will seg
-fault. The built
-in DLX linker script requires that there be something in the
50 # .
text section and our
sort-common.s file does not provide anything.
51 if [istarget dlx
-*-*] {
56 if { ![ld_assemble $as $srcdir
/$subdir
/sort-common.s tmpdir
/sort-common.o
] } {
61 if { ![ld_link $
ld tmpdir
/sort-common.dx
"--sort-common=descending tmpdir/sort-common.o"] } {
62 fail
"$test (could not link)"
66 send_log
"$objdump --syms tmpdir/sort-common.dx | grep var | sort\n"
67 set exec_output
[run_host_cmd
"$objdump" "--syms tmpdir/sort-common.dx | grep var | sort"]
69 # Don
't know why, but the CR ports fail this test.
70 setup_xfail "cr16-*-*" "crx-*-*"
72 # Note: The second regexp is for targets which put small commons in a .sbss
73 # section and large commons in a .bss section.
74 if { ![regexp ".*var_16.*var_8.*var_4.*var_2.*var_1.*" $exec_output]
75 && ![regexp ".*sbss.*var_8.*var_4.*var_2.*var_1.*bss.*var_16.*" $exec_output] } {
76 fail "$test (variables in wrong order)"
81 set test "--sort-common (ascending)"
83 verbose "Check to see that --sort-common=ascending sorts in ascending alignment"
85 if { ![ld_link $ld tmpdir/sort-common.ax "--sort-common=ascending tmpdir/sort-common.o"] } {
86 fail "$test (could not link)"
90 send_log "$objdump --syms tmpdir/sort-common.ax | grep var | sort\n"
91 set exec_output [run_host_cmd "$objdump" "--syms tmpdir/sort-common.ax | grep var | sort"]
93 if {![regexp ".*var_1.*var_2.*var_4.*var_8.*var_16.*" $exec_output]} {
94 fail "$test (variables in wrong order)"
104 set test1 "size/alignment change of common symbols"
105 set test1w1 "$test1 (warning 1)"
106 set test1w2 "$test1 (warning 2)"
107 set test1c1 "$test1 (change 1)"
108 set test1c2 "$test1 (change 2)"
110 if { ![check_compiler_available] } {
117 if { [istarget score-*-*] } {
125 proc dump_common1 { testname } {
129 send_log "$READELF --syms tmpdir/common1.o | grep foo\n"
130 set exec_output [run_host_cmd "$READELF" "--syms tmpdir/common1.o | grep foo"]
132 if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+)4(\[ \]+)(COMMON|OBJECT)(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output]
133 || ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)21(\[ \]+)OBJECT(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo1" $exec_output] } {
142 proc stt_common_test { options testname } {
147 set options "$options tmpdir/common1c.o"
149 if { ! [ld_link $ld tmpdir/common.exe $options] } {
154 send_log "$READELF --syms tmpdir/common.exe | grep foo\n"
155 set exec_output [run_host_cmd "$READELF" "--syms tmpdir/common.exe | grep foo"]
157 if {![regexp { +[0-9a-f]+. +[0-9a-f]+ OBJECT + GLOBAL +DEFAULT +[0-9]+ _?foo2} $exec_output] } {
166 if [istarget nios2*-*-*] {
167 set CFLAGS "$CFLAGS -G0"
170 # Explicitly use "-fcommon" so that even if $CFLAGS includes
171 # "-fno-common", these tests are compiled as expected.
172 if { ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
173 || ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1b.c tmpdir/common1b.o]
174 || ![ld_compile "$CC $CFLAGS -Wa,--elf-stt-common=yes -fcommon" $srcdir/$subdir/common1b.c tmpdir/common1c.o] } {
183 set options "-r tmpdir/common1a.o tmpdir/common1b.o"
185 if { [ld_link $ld tmpdir/common1.o $options] } {
190 # This test fails on MIPS because the backend sets type_change_ok.
191 # The size change warning is suppressed. Same on hppa64.
192 if {[istarget mips*-*-*] || [istarget hppa*64*-*-*]} {
193 if { ![regexp "warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
199 if { ![regexp "warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output]
200 || ![regexp "warning: size of symbol \`_?foo1\' changed from 2 in tmpdir/common1a.o to 21 in tmpdir/common1b.o" $link_output] } {
207 if { [dump_common1 $test1c1] } {
211 set options "-r tmpdir/common1b.o tmpdir/common1a.o"
213 if { [ld_link $ld tmpdir/common1.o $options] } {
218 if { ![regexp "warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
224 if { [dump_common1 $test1c2] } {
229 # The following tests are for when we are generating STT_COMMON symbols only.
231 # Handling of -z common and -z nocommon flags is enabled only if
232 # $GENERATE_SHLIB_SCRIPT is turned on in emulparams i.e. shared
233 # libraries are supported.
235 if ![check_shared_lib_support] {
239 stt_common_test "-static -e 0" "static link of common symbols"
240 stt_common_test "-shared" "shared link of common symbols"
241 stt_common_test "-pie" "position independent link of common symbols"
243 run_ld_link_tests [list \
245 "Build common-3x.o" \
246 "-r" "" "--elf-stt-common=no" \
247 {common-1.s} {} "common-3x.o" \
250 "Build common-3y.o" \
251 "-r" "" "--elf-stt-common=yes" \
252 {common-1.s} {} "common-3y.o" \
255 "Build common-3a.o" \
256 "-r tmpdir/common-3x.o tmpdir/common-3y.o" "" "" \
257 {dummy.s} {{readelf {-s -W} common-3a.rd}} "common-3a.o" \
260 "Build common-3b.o" \
261 "-r tmpdir/common-3y.o tmpdir/common-3x.o" "" "" \
262 {dummy.s} {{readelf {-s -W} common-3b.rd}} "common-3b.o" \
265 "Build common-3c.o" \
266 "-r -z nocommon tmpdir/common-3x.o tmpdir/common-3y.o" "" "" \
267 {dummy.s} {{readelf {-s -W} common-3a.rd}} "common-3c.o" \
270 "Build common-3d.o" \
271 "-r -z common tmpdir/common-3x.o tmpdir/common-3y.o" "" "" \
272 {dummy.s} {{readelf {-s -W} common-3b.rd}} "common-3b.o" \
275 "Build common-3e.o" \
276 "-r -z common tmpdir/common-3y.o tmpdir/common-3x.o" "" "" \
277 {dummy.s} {{readelf {-s -W} common-3b.rd}} "common-3e.o" \
280 "Build common-3f.o" \
281 "-r -z nocommon tmpdir/common-3y.o tmpdir/common-3x.o" "" "" \
282 {dummy.s} {{readelf {-s -W} common-3a.rd}} "common-3f.o" \
286 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
287 foreach t $test_list {
288 # We need to strip the ".d", but can leave the dirname.
289 verbose [file rootname $t]
290 run_dump_test [file rootname $t]