1# Expect script for .tls_common tests
2#   Copyright (C) 2006-2016 Free Software Foundation, Inc.
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# Written by Jakub Jelinek (jakub@redhat.com)
22#
23
24# Make sure that binutils can correctly handle ld output in ELF.
25
26if { ![istarget *-*-linux*]
27     && ![istarget *-*-nacl*]
28     && ![istarget *-*-gnu*] } {
29    return
30}
31
32if { [istarget *-*-linux*aout*]
33     || [istarget *-*-linux*oldld*] } {
34    return
35}
36
37global as
38global ld
39global READELF
40global srcdir
41global subdir
42global link_output
43
44if { ![ld_assemble $as "--elf-stt-common=no $srcdir/$subdir/tls_common.s" tmpdir/tls_commona.o]
45      || ![ld_assemble $as "--elf-stt-common=yes $srcdir/$subdir/tls_common.s" tmpdir/tls_commonb.o] } {
46    unresolved "tls_common"
47    return
48}
49
50if { ![ld_simple_link $ld tmpdir/tls_common1a.o "-r tmpdir/tls_commona.o"]
51     || ![ld_simple_link $ld tmpdir/tls_common1b.o "-r tmpdir/tls_commona.o"] } {
52    fail "tls_common"
53    return
54}
55
56if { ![ld_simple_link $ld tmpdir/tls_commona "tmpdir/tls_common1a.o"] } {
57    if { [string match "*not supported*" $link_output]
58	 || [string match "*unrecognized option*" $link_output] } {
59	unsupported "$ld_options is not supported by this target"
60    } elseif { [string match "*Warning*alignment*of common symbol*" $link_output] } {
61	fail "tls_common"
62    } else {
63	unresolved "tls_common"
64    }
65    return
66}
67
68if { ![ld_simple_link $ld tmpdir/tls_commonb "tmpdir/tls_common1b.o"] } {
69    if { [string match "*not supported*" $link_output]
70	 || [string match "*unrecognized option*" $link_output] } {
71	unsupported "$ld_options is not supported by this target"
72    } elseif { [string match "*Warning*alignment*of common symbol*" $link_output] } {
73	fail "tls_common"
74    } else {
75	unresolved "tls_common"
76    }
77    return
78}
79
80set readelf_output [run_host_cmd "$READELF" "-l --wide tmpdir/tls_commona"]
81if ![regexp ".*TLS.*0x0+ 0x0+4 R .*" $readelf_output] then {
82    send_log "$readelf_output\n"
83    fail "tls_common"
84    return
85}
86
87set readelf_output [run_host_cmd "$READELF" "-l --wide tmpdir/tls_commona"]
88if ![regexp ".*TLS.*0x0+ 0x0+4 R .*" $readelf_output] then {
89    send_log "$readelf_output\n"
90    fail "tls_common"
91    return
92}
93
94pass "tls_common"
95