OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [lib/] [lto.exp] - Blame information for rev 318

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

Line No. Rev Author Line
1 306 jeremybenn
# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
2
 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with GCC; see the file COPYING3.  If not see
15
# .
16
 
17
# Contributed by Diego Novillo 
18
 
19
# Prune messages that aren't useful.
20
 
21
proc lto_prune_warns { text } {
22
 
23
    verbose "lto_prune_warns: entry: $text" 2
24
 
25
    # Many tests that use visibility will still pass on platforms that don't support it.
26
    regsub -all "(^|\n)\[^\n\]*: warning: visibility attribute not supported in this configuration; ignored\[^\n\]*" $text "" text
27
 
28
    # And any stray location lines.
29
    regsub -all "(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
30
    regsub -all "(^|\n)In file included from \[^\n\]*" $text "" text
31
    regsub -all "(^|\n)\[ \t\]*from \[^\n\]*" $text "" text
32
 
33
    # Sun ld warns about common symbols with differing sizes.  Unlike GNU ld
34
    # --warn-common (off by default), they cannot be disabled.
35
    regsub -all "(^|\n)ld: warning: symbol \[`'\]\[^\n\]*' has differing sizes:" $text "" text
36
    regsub -all "(^|\n)\[ \t\]*\[\(\]file \[^\n\]* value=\[^\n\]*; file \[^\n\]* value=\[^\n\]*\[)\];" $text "" text
37
    regsub -all "(^|\n)\[ \t\]*\[^\n\]* definition taken" $text "" text
38
 
39
    verbose "lto_prune_warns: exit: $text" 2
40
 
41
    return $text
42
}
43
 
44
# lto_init -- called at the start of each subdir of tests
45
 
46
proc lto_init { args } {
47
    global LTO_OPTIONS
48
 
49
    if {[info exists args] && $args == "no-mathlib"} {
50
        global board_info
51
        global saved_mathlib
52
 
53
        set dest [target_info name]
54
        if [board_info $dest exists mathlib] {
55
            set saved_mathlib [board_info $dest mathlib]
56
        }
57
        set board_info($dest,mathlib) " "
58
    }
59
 
60
    # Each test is run with the compiler options from this list.
61
    # The default option lists can be overridden by LTO_OPTIONS="[list
62
    # {opts_1} {opts_2}... {opts_n}]" where opts_i are lists of options.
63
    # You can put this in the environment before site.exp is written or
64
    # add it to site.exp directly.
65
    if ![info exists LTO_OPTIONS] {
66
        set LTO_OPTIONS [list   \
67
            {-O0 -fwhopr}       \
68
            {-O2 -fwhopr}       \
69
            {-O0 -flto}         \
70
            {-O2 -flto}         \
71
        ]
72
    }
73
}
74
 
75
#
76
# lto_finish -- called at the end of each subdir of tests if mathlib is
77
#               changed.
78
#
79
 
80
proc lto_finish { } {
81
    global board_info
82
    global saved_mathlib
83
 
84
    set dest [target_info name]
85
    if [info exists saved_mathlib] {
86
        set board_info($dest,mathlib) $saved_mathlib
87
    } elseif [board_info $dest exists mathlib] {
88
        unset board_info($dest,mathlib)
89
    }
90
}
91
 
92
# Subsets of tests can be selectively disabled by members of this list:
93
#  - ATTRIBUTE: disable all tests using the __attribute__ extension,
94
#  - COMPLEX: disable all tests using the complex types feature,
95
#  - COMPLEX_INT: disable all tests using the complex integral types extension,
96
#  - VA: disable all tests using the variable number of arguments feature,
97
#  - VLA_IN_STRUCT: disable all tests using the variable-length arrays as
98
#    structure members extension,
99
#  - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
100
# The default skip lists can be overriden by
101
# LTO_SKIPS="[list {skip_1}...{skip_n}]"
102
# where skip_i are skip identifiers.  You can put this in the environment
103
# before site.exp is written or add it to site.exp directly.
104
if ![info exists LTO_SKIPS] {
105
    set LTO_SKIPS [list {}]
106
}
107
 
108
global lto_skip_list
109
set lto_skip_list $LTO_SKIPS
110
 
111
load_lib dg.exp
112
load_lib gcc-dg.exp
113
 
114
# lto-obj -- compile to an object file
115
#
116
# SOURCE is the source file
117
# DEST is the object file
118
# OPTALL is the list of compiler options to use with all tests
119
# OPTFILE is the list of compiler options to use with this file
120
# OPTSTR is the options to print with test messages
121
# XFAILDATA is the xfail data to be passed to the compiler
122
proc lto-obj { source dest optall optfile optstr xfaildata } {
123
    global testcase
124
    global tool
125
    global compiler_conditional_xfail_data
126
    global lto_skip_list
127
 
128
    # Add the skip specifiers.
129
    foreach skip $lto_skip_list {
130
        if { ![string match $skip ""] } {
131
            lappend optall "-DSKIP_$skip"
132
        }
133
    }
134
 
135
    # Set up the options for compiling this file.
136
    set options ""
137
    lappend options "additional_flags=$optall $optfile"
138
 
139
    set compiler_conditional_xfail_data $xfaildata
140
    set comp_output [${tool}_target_compile "$source" "$dest" object $options]
141
    # Prune unimportant visibility warnings before checking output.
142
    set comp_output [lto_prune_warns $comp_output]
143
    ${tool}_check_compile "$testcase $dest assemble" $optstr $dest $comp_output
144
}
145
 
146
# lto-link-and-maybe-run -- link the object files and run the executable
147
# if compile_type is set to "run"
148
#
149
# TESTNAME is the mixture of object files to link
150
# OBJLIST is the list of object files to link
151
# DEST is the name of the executable
152
# OPTALL is a list of compiler and linker options to use for all tests
153
# OPTFILE is a list of compiler and linker options to use for this test
154
# OPTSTR is the list of options to list in messages
155
proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
156
    global testcase
157
    global tool
158
    global compile_type
159
 
160
    # Check that all of the objects were built successfully.
161
    foreach obj [split $objlist] {
162
        if ![file_on_host exists $obj] then {
163
            unresolved "$testcase $testname link $optstr"
164
            unresolved "$testcase $testname execute $optstr"
165
            return
166
        }
167
    }
168
 
169
    # Set up the options for linking this test.
170
    set options ""
171
    lappend options "additional_flags=$optall $optfile"
172
 
173
    # Link the objects into an executable.
174
    set comp_output [${tool}_target_compile "$objlist" $dest executable \
175
                     "$options"]
176
 
177
    # Prune unimportant visibility warnings before checking output.
178
    set comp_output [lto_prune_warns $comp_output]
179
 
180
    if ![${tool}_check_compile "$testcase $testname link" "" \
181
         $dest $comp_output] then {
182
        unresolved "$testcase $testname execute $optstr"
183
        return
184
    }
185
 
186
    # Return if we only needed to link.
187
    if { ![string compare "link" $compile_type] } {
188
        return
189
    }
190
 
191
    # Run the self-checking executable.
192
    if ![string match "*/*" $dest] then {
193
        set dest "./$dest"
194
    }
195
    set result [${tool}_load $dest "" ""]
196
    set status [lindex $result 0]
197
    if { $status == "pass" } then {
198
        file_on_host delete $dest
199
    }
200
    $status "$testcase $testname execute $optstr"
201
}
202
 
203
# lto-get-options-main -- get target requirements for a test and
204
# options for the primary source file and the test as a whole
205
#
206
# SRC is the full pathname of the primary source file.
207
proc lto-get-options-main { src } {
208
    global compile_type
209
    global dg-extra-ld-options
210
    global dg-suppress-ld-options
211
 
212
    set dg-extra-ld-options ""
213
    set dg-suppress-ld-options ""
214
 
215
    # dg-options sets a variable called dg-extra-tool-flags.
216
    set dg-extra-tool-flags ""
217
 
218
    # dg-options sets a variable called tool_flags.
219
    set tool_flags ""
220
 
221
    # dg-require-* sets dg-do-what.
222
    upvar dg-do-what dg-do-what
223
    upvar dg-final-code dg-final-code
224
    set dg-final-code ""
225
 
226
    set tmp [dg-get-options $src]
227
    verbose "getting options for $src: $tmp"
228
    foreach op $tmp {
229
        set cmd [lindex $op 0]
230
        verbose "cmd is $cmd"
231
        if { [string match "dg-skip-if" $cmd] \
232
             || [string match "dg-require-*" $cmd] } {
233
            set status [catch "$op" errmsg]
234
            if { $status != 0 } {
235
                perror "src: $errmsg for \"$op\"\n"
236
                unresolved "$src: $errmsg for \"$op\""
237
                return
238
            }
239
        } elseif { [string match "dg-lto-options" $cmd] } {
240
            set op [lreplace $op 0 0 "dg-options"]
241
            set status [catch "$op" errmsg]
242
            if { $status != 0 } {
243
                perror "src: $errmsg for \"$op\"\n"
244
                unresolved "$src: $errmsg for \"$op\""
245
                return
246
            }
247
        } elseif { ![string compare "dg-xfail-if" $cmd] \
248
                   || ![string compare "dg-options" $cmd] } {
249
            warning "lto.exp does not support $cmd in primary source file"
250
        } elseif { ![string compare "dg-lto-do" $cmd] } {
251
            if { [llength $op] > 3 } {
252
                set kw [lindex [lindex $op 3] 0]
253
                if [string match "target" $kw] {
254
                    perror "$src: dg-lto-do does not support \"target\""
255
                } elseif [string match "xfail" $kw] {
256
                    perror "$src: dg-lto-do does not support \"xfail\""
257
                } else {
258
                    perror "$src: dg-lto-do takes a single argument"
259
                }
260
            }
261
            set dgdo [lindex $op 2]
262
            verbose "dg-lto-do command for \"$op\" is $dgdo"
263
            if { ![string compare "assemble" $dgdo] } {
264
                set compile_type "assemble"
265
            } elseif { ![string compare "run" $dgdo] } {
266
                set compile_type "run"
267
            } elseif { ![string compare "link" $dgdo] } {
268
                set compile_type "link"
269
            } else {
270
                warning "lto.exp does not support dg-lto-do $dgdo"
271
            }
272
        } elseif { ![string compare "dg-extra-ld-options" $cmd] } {
273
            set dg-extra-ld-options [lindex $op 2]
274
            verbose "dg-extra-ld-options for main is ${dg-extra-ld-options}"
275
        } elseif { ![string compare "dg-suppress-ld-options" $cmd] } {
276
            set dg-suppress-ld-options [lindex $op 2]
277
            verbose \
278
              "dg-suppress-ld-options for main is ${dg-suppress-ld-options}"
279
        } elseif { ![string compare "dg-final" $cmd] } {
280
            if { [llength $op] > 3 } {
281
                error "[lindex $op 0]: too many arguments"
282
            } else {
283
                append dg-final-code "[lindex $op 2]\n"
284
            }
285
        } else {
286
            # Ignore unrecognized dg- commands, but warn about them.
287
            warning "lto.exp does not support $cmd"
288
        }
289
    }
290
 
291
    # Return flags to use for compiling the primary source file and for
292
    # linking.
293
    verbose "dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
294
    return ${dg-extra-tool-flags}
295
}
296
 
297
 
298
# lto-get-options -- get special tool flags to use for a secondary
299
# source file
300
#
301
# SRC is the full pathname of the source file.
302
# The result is a list of options to use.
303
#
304
# This code is copied from proc dg-test in dg.exp from DejaGNU.
305
proc lto-get-options { src } {
306
    # dg-options sets a variable called dg-extra-tool-flags.
307
    set dg-extra-tool-flags ""
308
 
309
    # dg-xfail-if sets compiler_conditional_xfail_data.
310
    global compiler_conditional_xfail_data
311
    set compiler_conditional_xfail_data ""
312
 
313
    # dg-xfail-if needs access to dg-do-what.
314
    upvar dg-do-what dg-do-what
315
 
316
    set tmp [dg-get-options $src]
317
    foreach op $tmp {
318
        set cmd [lindex $op 0]
319
        if { ![string compare "dg-options" $cmd] \
320
             || ![string compare "dg-xfail-if" $cmd] } {
321
            set status [catch "$op" errmsg]
322
            if { $status != 0 } {
323
                perror "src: $errmsg for \"$op\"\n"
324
                unresolved "$src: $errmsg for \"$op\""
325
                return
326
            }
327
        } elseif { [string match "dg-require-*" $cmd] } {
328
            warning "lto.exp does not support $cmd in secondary source files"
329
        } else {
330
            # Ignore unrecognized dg- commands, but warn about them.
331
            warning "lto.exp does not support $cmd in secondary source files"
332
        }
333
    }
334
 
335
    return ${dg-extra-tool-flags}
336
}
337
 
338
# lto-execute -- compile multi-file tests
339
#
340
# SRC1 is the full pathname of the main file of the testcase.
341
# SID identifies a test suite in the names of temporary files.
342
proc lto-execute { src1 sid } {
343
    global srcdir tmpdir
344
    global lto_option_list
345
    global tool
346
    global verbose
347
    global testcase
348
    global gluefile
349
    global compiler_conditional_xfail_data
350
    global dg-do-what-default
351
    global compile_type
352
    global dg-extra-ld-options
353
    global dg-suppress-ld-options
354
    global LTO_OPTIONS
355
    global dg-final-code
356
 
357
    # Get extra flags for this test from the primary source file, and
358
    # process other dg-* options that this suite supports.  Warn about
359
    # unsupported flags.
360
    verbose "lto-execute: $src1" 1
361
    set compile_type "run"
362
    set dg-do-what [list ${dg-do-what-default} "" P]
363
    set extra_flags(0) [lto-get-options-main $src1]
364
    set compile_xfail(0) ""
365
 
366
    # If the main file defines dg-options, those flags are used to
367
    # overwrite the default lto_option_list taken from LTO_OPTIONS.
368
    if { [string length $extra_flags(0)] > 0 } {
369
        set lto_option_list $extra_flags(0)
370
        set extra_flags(0) ""
371
    } else {
372
        set lto_option_list $LTO_OPTIONS
373
    }
374
 
375
    # Check whether this test is supported for this target.
376
    if { [lindex ${dg-do-what} 1 ] == "N" } {
377
        unsupported "$src1"
378
        verbose "$src1 not supported on this target, skipping it" 3
379
        return
380
    }
381
 
382
    # Set up the names of the other source files.
383
    set dir [file dirname $src1]
384
    set base [file rootname $src1]
385
    set base [string range $base [string length $dir] end]
386
    regsub "_0" $base "" base
387
    regsub "/" $base "" base
388
    set src_list $src1
389
    set i 1
390
    set done 0
391
    while { !$done } {
392
        set names [glob -nocomplain -types f -- "${dir}/${base}_${i}.*"]
393
        if { [llength ${names}] > 1 } {
394
            warning "lto-execute: more than one file matched ${dir}/${base}_${i}.*"
395
        }
396
        if { [llength ${names}] == 1 } {
397
            lappend src_list [lindex ${names} 0]
398
            incr i
399
        } else {
400
            set num_srcs ${i}
401
            set done 1
402
        }
403
    }
404
 
405
    # Use the dg-options mechanism to specify extra flags for each
406
    # of the secondary files.
407
    # The extra flags in each file are used to compile that file, and the
408
    # extra flags in *_0.* are also used for linking.
409
    verbose "\tsrc_list is: $src_list"
410
    for {set i 1} {$i < $num_srcs} {incr i} {
411
        set extra_flags($i) [lto-get-options [lindex $src_list $i]]
412
        set compile_xfail($i) $compiler_conditional_xfail_data
413
    }
414
 
415
    # Define the names of the object files.
416
    set obj_list ""
417
    for {set i 0} {$i < $num_srcs} {incr i} {
418
        lappend obj_list "${sid}_${base}_${i}.o"
419
    }
420
 
421
    # Get the base name of this test, for use in messages.
422
    set testcase [lindex ${src_list} 0]
423
 
424
    # Remove the $srcdir and $tmpdir prefixes from $src1.  (It would
425
    # be possible to use "regsub" here, if we were careful to escape
426
    # all regular expression characters in $srcdir and $tmpdir, but
427
    # that would be more complicated that this approach.)
428
    if {[string first "$srcdir/" "${testcase}"] == 0} {
429
        set testcase [string range "${testcase}" [string length "$srcdir/"] end]
430
    }
431
    if {[string first "$tmpdir/" "$testcase"] == 0} {
432
        set testcase [string range "$testcase" [string length "$tmpdir/"] end]
433
        set testcase "tmpdir-$testcase"
434
    }
435
    regsub "_0.*" $testcase "" testcase
436
 
437
    # Set up the base name of executable files so they'll be unique.
438
    regsub -all "\[./\]" $testcase "-" execbase
439
 
440
    # If we couldn't rip $srcdir out of `src1' then just do the best we can.
441
    # The point is to reduce the unnecessary noise in the logs.  Don't strip
442
    # out too much because different testcases with the same name can confuse
443
    # `test-tool'.
444
    if [string match "/*" $testcase] then {
445
        set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
446
    }
447
 
448
    # Loop through all of the option lists used for this test.
449
    set count 0
450
    foreach option $lto_option_list {
451
        verbose "Testing $testcase, $option"
452
 
453
        # There's a unique name for each executable we generate.
454
        set execname "${execbase}-${count}1"
455
        incr count
456
 
457
        file_on_host delete $execname
458
 
459
        # Compile pieces with the compiler under test.
460
        set i 0
461
        foreach src $src_list obj $obj_list {
462
            lto-obj $src $obj $option $extra_flags($i) $option \
463
                    $compile_xfail($i)
464
            incr i
465
        }
466
 
467
        # Link (using the compiler under test), run, and clean up tests.
468
        if { ![string compare "run" $compile_type] \
469
             || ![string compare "link" $compile_type] } {
470
 
471
            # Filter out any link options we were asked to suppress.
472
            set reduced {}
473
            foreach x [split $option] {
474
              if {[lsearch ${dg-suppress-ld-options} $x] == -1} {
475
                lappend reduced $x
476
              }
477
            }
478
            set filtered [join $reduced " "]
479
 
480
            lto-link-and-maybe-run \
481
                    "[lindex $obj_list 0]-[lindex $obj_list end]" \
482
                    $obj_list $execname $filtered ${dg-extra-ld-options} \
483
                    $filtered
484
        }
485
 
486
 
487
        # Are there any further tests to perform?
488
        # Note that if the program has special run-time requirements, running
489
        # of the program can be delayed until here.  Ditto for other situations.
490
        # It would be a bit cumbersome though.
491
 
492
        if ![string match ${dg-final-code} ""] {
493
            regsub -all "\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code
494
            # Note that the use of `args' here makes this a varargs proc.
495
            proc dg-final-proc { args } ${dg-final-code}
496
            verbose "Running dg-final tests." 3
497
            verbose "dg-final-proc:\n[info body dg-final-proc]" 4
498
            if [catch "dg-final-proc $src1" errmsg] {
499
                perror "$name: error executing dg-final: $errmsg"
500
                # ??? The call to unresolved here is necessary to clear
501
                # `errcnt'.  What we really need is a proc like perror that
502
                # doesn't set errcnt.  It should also set exit_status to 1.
503
                unresolved "$name: error executing dg-final: $errmsg"
504
            }
505
        }
506
 
507
        # Clean up object files.
508
        set files [glob -nocomplain ${sid}_*.o]
509
        if { $files != "" } {
510
            foreach objfile $files {
511
                if { ![info exists gluefile] || $objfile != $gluefile } {
512
                    eval "file_on_host delete $objfile"
513
                }
514
            }
515
        }
516
 
517
        if { ![string compare "run" $compile_type] \
518
             || ![string compare "link" $compile_type] } {
519
            file_on_host delete $execname
520
        }
521
    }
522
}
523
 
524
# Utility for scanning a symbol in the final executable, invoked via dg-final.
525
# Call pass if pattern is present, otherwise fail.
526
#
527
# Argument 0 is the regexp to match.
528
# Argument 1 handles expected failures and the like
529
proc scan-symbol { args } {
530
    global nm
531
    global base_dir
532
    upvar 2 execname execname
533
 
534
    if { [llength $args] >= 2 } {
535
        switch [dg-process-target [lindex $args 1]] {
536
            "S" { }
537
            "N" { return }
538
            "F" { setup_xfail "*-*-*" }
539
            "P" { }
540
        }
541
    }
542
 
543
    # Find nm like we find g++ in g++.exp.
544
    if ![info exists nm]  {
545
        set nm [findfile $base_dir/../../../binutils/nm \
546
                $base_dir/../../../binutils/nm \
547
                [findfile $base_dir/../../nm $base_dir/../../nm \
548
                      [findfile $base_dir/nm $base_dir/nm \
549
                       [transform nm]]]]
550
        verbose -log "nm is $nm"
551
    }
552
 
553
    set output_file "[glob -nocomplain $execname]"
554
    if { $output_file == "" } {
555
        fail "scan-symbol $args: dump file does not exist"
556
        return
557
    }
558
 
559
    set fd [open "| $nm $output_file" r]
560
    set text [read $fd]
561
    close $fd
562
 
563
    if [regexp -- [lindex $args 0] $text] {
564
        pass "scan-symbol $args"
565
    } else {
566
        fail "scan-symbol $args"
567
    }
568
}

powered by: WebSVN 2.1.0

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