OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [ld/] [testsuite/] [ld-elfcomm/] [elfcomm.exp] - Blame information for rev 79

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 khays
# Expect script for common symbol tests
2
#   Copyright 2003, 2005, 2006, 2007, 2008, 2009
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
# Written by H.J. Lu (hjl@gnu.org)
23
#
24
 
25
# Make sure that ld correctly handles common symbols in ELF.
26
 
27
# This test can only be run on ELF platforms.
28
if ![is_elf_format] {
29
    return
30
}
31
 
32
# hpux assembly is weird
33
if [istarget "hppa*-*-hpux*"] {
34
    return
35
}
36
 
37
proc test_sort_common {} {
38
    global exec_output
39
    global objdump
40
    global srcdir
41
    global subdir
42
    global as
43
    global ld
44
 
45
    set test "--sort-common (descending)"
46
 
47
    verbose "Check to see that --sort-common sorts in descending alignment"
48
 
49
    # We do not run the sort common tests for the DLX target because we know that the linker
50
    # will seg-fault.  The built-in DLX linker script requires that there be something in the
51
    # .text section and our sort-common.s file does not provide anything.
52
    if [istarget dlx-*-*] {
53
        untested "$test"
54
        return 0
55
    }
56
 
57
    if { ![ld_assemble $as $srcdir/$subdir/sort-common.s tmpdir/sort-common.o] } {
58
        unresolved "$test"
59
        return 0
60
    }
61
 
62
    if { ![ld_simple_link $ld tmpdir/sort-common.dx "--sort-common=descending tmpdir/sort-common.o"] } {
63
        fail "$test"
64
        return 0
65
    }
66
 
67
    send_log "$objdump --syms tmpdir/sort-common.dx | grep var | sort\n"
68
    set exec_output [run_host_cmd "$objdump" "--syms tmpdir/sort-common.dx | grep var | sort"]
69
 
70
    # Don't know why, but the CR ports fail this test.
71
    setup_xfail "cr16-*-*" "crx-*-*"
72
 
73
    # Note: The second regexp is for targets which put small commons in a .sbss
74
    #  section and large commons in a .bss section.
75
    if {   ![regexp ".*var_16.*var_8.*var_4.*var_2.*var_1.*" $exec_output]
76
        && ![regexp ".*sbss.*var_8.*var_4.*var_2.*var_1.*bss.*var_16.*" $exec_output] } {
77
        fail $test
78
    } else {
79
        pass $test
80
    }
81
 
82
    set test "--sort-common (ascending)"
83
 
84
    verbose "Check to see that --sort-common=ascending sorts in ascending alignment"
85
 
86
    if { ![ld_simple_link $ld tmpdir/sort-common.ax "--sort-common=ascending tmpdir/sort-common.o"] } {
87
        fail "$test"
88
        return 0
89
    }
90
 
91
    send_log "$objdump --syms tmpdir/sort-common.ax | grep var | sort\n"
92
    set exec_output [run_host_cmd "$objdump" "--syms tmpdir/sort-common.ax | grep var | sort"]
93
 
94
    if {![regexp ".*var_1.*var_2.*var_4.*var_8.*var_16.*" $exec_output]} {
95
        fail $test
96
        return 0
97
    }
98
 
99
    pass $test
100
    return 1
101
}
102
 
103
test_sort_common
104
 
105
set test1       "size/aligment change of common symbols"
106
set test1w1     "$test1 (warning 1)"
107
set test1w2     "$test1 (warning 2)"
108
set test1c1     "$test1 (change 1)"
109
set test1c2     "$test1 (change 2)"
110
 
111
if { ![is_remote host] && [which $CC] == 0 } {
112
    untested $test1w1
113
    untested $test1w2
114
    untested $test1c1
115
    untested $test1c2
116
    return
117
}
118
if { [istarget score-*-*] } {
119
    untested $test1w1
120
    untested $test1w2
121
    untested $test1c1
122
    untested $test1c2
123
    return
124
}
125
 
126
proc dump_common1 { testname } {
127
    global exec_output
128
    global READELF
129
 
130
    send_log "$READELF --syms tmpdir/common1.o | grep foo\n"
131
    set exec_output [run_host_cmd "$READELF" "--syms tmpdir/common1.o | grep foo"]
132
 
133
    if {   ![regexp "(\[        \]*)(\[0-9\]+):(\[      \]*)(\[0\]*)80(\[       \]+)4(\[        \]+)(COMMON|OBJECT)(\[  \]+)GLOBAL(\[   \]+)DEFAULT(\[  \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[     \]+)_?foo2" $exec_output]
134
        || ![regexp "(\[        \]*)(\[0-9\]+):(\[      \]*)(\[0-9\]+)(\[       \]+)21(\[       \]+)OBJECT(\[   \]+)GLOBAL(\[   \]+)DEFAULT(\[  \]+)(\[0-9\]+)(\[       \]+)_?foo1" $exec_output] } {
135
        verbose $exec_output
136
        fail $testname
137
        return 0
138
    }
139
 
140
    return 1
141
}
142
 
143
proc stt_common_test { options testname } {
144
    global exec_output
145
    global READELF
146
    global ld
147
 
148
    set options "$options tmpdir/common1a.o"
149
 
150
    if { ! [ld_simple_link $ld tmpdir/common.exe $options] } {
151
      unresolved $testname
152
      return 0
153
    }
154
 
155
    send_log "$READELF --syms tmpdir/common.exe | grep foo\n"
156
    set exec_output [run_host_cmd "$READELF" "--syms tmpdir/common.exe | grep foo"]
157
 
158
    if {![regexp "(\[   \]*)(\[0-9\]+):(\[      \]*)(\[0-9\]+)(\[       \]+)(\[0-9\]+)(\[       \]+)COMMON(\[   \]+)GLOBAL(\[   \]+)DEFAULT(\[  \]+)(\[0-9\]+)(\[       \]+)_?foo2" $exec_output] } {
159
        fail $testname
160
        return 0
161
    }
162
 
163
    pass $testname
164
    return 1
165
}
166
 
167
# Check to see if the assembler is generating symbols with the STT_COMMON type.
168
proc assembler_generates_commons {} {
169
    global exec_output
170
    global READELF
171
 
172
    verbose "Check to see if STT_COMMON symbols are being generated:"
173
    set exec_output [run_host_cmd "$READELF" "--syms tmpdir/common1a.o | grep foo"]
174
 
175
    if { ![regexp "(\[  \]*)(\[0-9\]+):(\[      \]*)(\[0\]*)80(\[       \]+).(\[        \]+)COMMON(\[   \]+)GLOBAL(\[   \]+)DEFAULT(\[  \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[     \]+)_?foo2" $exec_output] } {
176
        verbose "STT_COMMON not generated"
177
        return 0
178
    }
179
 
180
    verbose "STT_COMMON's are generated"
181
    return 1
182
}
183
 
184
# Explicitly use "-fcommon" so that even if $CFLAGS includes
185
# "-fno-common", these tests are compiled as expected.
186
if {   ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
187
    || ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } {
188
    unresolved $test1
189
    return
190
}
191
 
192
global ld
193
global link_output
194
 
195
set options "-r tmpdir/common1a.o tmpdir/common1b.o"
196
 
197
# SH64 targets needs an extra ld option for this test.
198
if [istarget sh64*-*-*] {
199
    if [istarget sh64*l*-*-*] {
200
        set options "-mshlelf32 $options"
201
    } else {
202
        set options "-mshelf32 $options"
203
    }
204
}
205
 
206
if { [ld_simple_link $ld tmpdir/common1.o $options] } {
207
    unresolved $test1w1
208
    return
209
}
210
 
211
# This test fails on MIPS because the backend sets type_change_ok.
212
# The size change warning is suppressed.  Same on hppa64.
213
if {[istarget mips*-*-*] || [istarget hppa*64*-*-*]} {
214
    if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
215
        fail $test1w1
216
    } else {
217
        pass $test1w1
218
    }
219
} else {
220
    if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output]
221
         || ![regexp "Warning: size of symbol \`_?foo1\' changed from 2 in tmpdir/common1a.o to 21 in tmpdir/common1b.o" $link_output] } {
222
        fail $test1w1
223
    } else {
224
        pass $test1w1
225
    }
226
}
227
 
228
if { [dump_common1 $test1c1] } {
229
    pass $test1c1
230
}
231
 
232
set options "-r tmpdir/common1b.o tmpdir/common1a.o"
233
 
234
# SH64 targets needs an extra ld option for this test.
235
if [istarget sh64*-*-*] {
236
    if [istarget sh64*l*-*-*] {
237
        set options "-mshlelf32 $options"
238
    } else {
239
        set options "-mshelf32 $options"
240
    }
241
}
242
 
243
if { [ld_simple_link $ld tmpdir/common1.o $options] } {
244
    unresolved $test1w2
245
    return
246
}
247
 
248
if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
249
    fail $test1w2
250
} else {
251
    pass $test1w2
252
}
253
 
254
if { [dump_common1 $test1c2] } {
255
    pass $test1c2
256
}
257
 
258
#
259
# The following tests are for when we are generating STT_COMMON symbols only.
260
#
261
 
262
if { ![assembler_generates_commons] } {
263
    return
264
}
265
 
266
stt_common_test "-static -e 0" "static link of common symbols"
267
stt_common_test "-shared"      "shared link of common symbols"
268
stt_common_test "-pie"         "position independent link of common symbols"
269
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.