aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/lib/target-supports.exp
blob: a2dde90e3811b8b6f5dfb4f14439a979a005ba14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#   Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# Please email any bugs, comments, and/or additions to this file to:
# gcc-patches@gcc.gnu.org

# This file defines procs for determining features supported by the target.

# Try to compile some code and return the messages printed by the compiler.
#
# BASENAME is a basename to use for temporary files.
# TYPE is the type of compilation to perform (see target_compile).
# CONTENTS gives the contents of the input file.
# The rest is optional:
# OPTIONS: additional compiler options to use.
proc get_compiler_messages {basename type contents args} {
    global tool

    if { [llength $args] > 0 } {
	set options "additional_flags=[lindex $args 0]"
    } else {
	set options ""
    }

    set src ${basename}[pid].c
    switch $type {
	assembly { set output ${basename}[pid].s }
	object { set output ${basename}[pid].o }
    }
    set f [open $src "w"]
    puts $f $contents
    close $f
    set lines [${tool}_target_compile $src $output $type "$options"]
    file delete $src
    remote_file build delete $output

    return $lines
}

proc current_target_name { } {
    global target_info
    if [info exists target_info(target,name)] {
	set answer $target_info(target,name)
    } else {
	set answer ""
    }
    return $answer
}

###############################
# proc check_weak_available { }
###############################

# weak symbols are only supported in some configs/object formats
# this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure

proc check_weak_available { } {
    global target_triplet
    global target_cpu

    # All mips targets should support it
    
    if { [ string first "mips" $target_cpu ] >= 0 } {
        return 1
    }

    # All solaris2 targets should support it
    
    if { [regexp ".*-solaris2.*" $target_triplet] } {
        return 1
    }

    # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it

    if { [regexp "alpha.*osf.*" $target_triplet] } {
	return 1
    }

    # ELF and ECOFF support it. a.out does with gas/gld but may also with
    # other linkers, so we should try it

    set objformat [gcc_target_object_format]

    switch $objformat {
        elf      { return 1 }
        ecoff    { return 1 }
        a.out    { return 1 }
        unknown  { return -1 }
        default  { return 0 }
    }
}

###############################
# proc check_visibility_available { }
###############################

# The visibility attribute is only support in some object formats
# This proc returns 1 if it is supported, 0 if not, -1 if unsure.

proc check_visibility_available { } {
    global target_triplet
    global target_cpu

    # ELF supports it if the system has recent GNU ld and gas.
    # As a start we return 1 for all ELF systems; we'll let people
    # add exceptions as necessary.

    set objformat [gcc_target_object_format]

    switch $objformat {
        elf      { return 1 }
        unknown  { return -1 }
        default  { return 0 }
    }
}

###############################
# proc check_alias_available { }
###############################

# Determine if the target toolchain supports the alias attribute.

# Returns 2 if the target supports aliases.  Returns 1 if the target
# only supports weak aliased.  Returns 0 if the target does not
# support aliases at all.  Returns -1 if support for aliases could not
# be determined.

proc check_alias_available { } {
    global alias_available_saved
    global tool

    if [info exists alias_available_saved] {
        verbose "check_alias_available  returning saved $alias_available_saved" 2
    } else {
        verbose "check_alias_available  compiling testfile" 2
	set f [open "tmp.c" "w"]
	# Compile a small test program.  The definition of "g" is
	# necessary to keep the Solaris assembler from complaining
	# about the program.
	puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
	puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
	close $f
	set lines [${tool}_target_compile "tmp.c" "tmp.o" object ""]
	file delete "tmp.c"

	if [string match "" $lines] then {
	    # No error messages, everything is OK.
	    set alias_available_saved 2
	} else {
	    if [regexp "alias definitions not supported" $lines] {
		verbose "check_alias_available  target does not support aliases" 2

		set objformat [gcc_target_object_format]

		if { $objformat == "elf" } {
		    verbose "check_alias_available  but target uses ELF format, so it ought to" 2
		    set alias_available_saved -1
		} else {
		    set alias_available_saved 0
		}
	    } else {
		if [regexp "only weak aliases are supported" $lines] {
		verbose "check_alias_available  target supports only weak aliases" 2
		set alias_available_saved 1
		} else {
		    set alias_available_saved -1
		}
	    }
	}
	
	verbose "check_alias_available  returning $alias_available_saved" 2
    }

    return $alias_available_saved
}

# Returns true if --gc-sections is supported on the target.

proc check_gc_sections_available { } {
    global gc_sections_available_saved
    global tool

    if {![info exists gc_sections_available_saved]} {
	# Check if the ld used by gcc supports --gc-sections.
	set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=ld" "" "none" ""] 0]
	set ld_output [remote_exec host "$gcc_ld" "--help"]
	if { [ string first "--gc-sections" $ld_output ] >= 0 } {
	    set gc_sections_available_saved 1
	} else {
	    set gc_sections_available_saved 0
	}
    }
    return $gc_sections_available_saved
}

# Return true if profiling is supported on the target.

proc check_profiling_available { test_what } {
    global profiling_available_saved

    verbose "Profiling argument is <$test_what>" 1

    # These conditions depend on the argument so examine them before
    # looking at the cache variable.

    # Support for -p on solaris2 relies on mcrt1.o which comes with the
    # vendor compiler.  We cannot reliably predict the directory where the
    # vendor compiler (and thus mcrt1.o) is installed so we can't
    # necessarily find mcrt1.o even if we have it.
    if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
	return 0
    }

    # Support for -p on irix relies on libprof1.a which doesn't appear to
    # exist on any irix6 system currently posting testsuite results.
    # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
    # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
    if { [istarget mips*-*-irix*] 
    && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
	return 0
    }

    # Now examine the cache variable.
    if {![info exists profiling_available_saved]} {
	# Some targets don't have any implementation of __bb_init_func or are
	# missing other needed machinery.
	if { [istarget mmix-*-*]
	     || [istarget arm*-*-elf]
	     || [istarget strongarm*-*-elf]
	     || [istarget xscale*-*-elf]
	     || [istarget cris-*-*]
	     || [istarget h8300-*-*] 
	     || [istarget *-*-windiss] } {
	    set profiling_available_saved 0
	} else {
	    set profiling_available_saved 1
	}
    }
    
    return $profiling_available_saved
}

# Return true if named sections are supported on this target.
# This proc does not cache results, because the answer may vary
# when cycling over subtarget options (e.g. irix o32/n32/n64) in
# the same test run.
proc check_named_sections_available { } {
    global tool

    verbose "check_named_sections_available  compiling testfile" 2
    set f [open "tmp.c" "w"]
    # Compile a small test program.
    puts $f "int __attribute__ ((section(\"whatever\"))) foo;"
    close $f
    set lines [${tool}_target_compile "tmp.c" "tmp.o" object ""]
    file delete "tmp.c"

    # If we got no error messages, everything is OK.
    set answer [string match "" $lines]
    verbose "check_named_sections_available  returning $answer" 2
    return $answer
}

# Return 1 if the target supports executing AltiVec instructions, 0
# otherwise.  Cache the result.

proc check_vmx_hw_available { } {
    global vmx_hw_available_saved
    global tool

    if [info exists vmx_hw_available_saved] {
	verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
    } else {
	set vmx_hw_available_saved 0

	# Some simulators are known to not support VMX instructions.
	if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
	    verbose "check_hw_available  returning 0" 2
	    return $vmx_hw_available_saved
	}

	# Set up, compile, and execute a test program containing VMX
	# instructions.  Include the current process ID in the file
	# names to prevent conflicts with invocations for multiple
	# testsuites.
	set src vmx[pid].c
	set exe vmx[pid].x

	set f [open $src "w"]
	puts $f "int main() {"
	puts $f "#ifdef __MACH__"
	puts $f "  asm volatile (\"vor v0,v0,v0\");"
	puts $f "#else"
	puts $f "  asm volatile (\"vor 0,0,0\");"
	puts $f "#endif"
	puts $f "  return 0; }"
	close $f

	verbose "check_vmx_hw_available  compiling testfile $src" 2
	set lines [${tool}_target_compile $src $exe executable ""]
	file delete $src

	if [string match "" $lines] then {
	    # No error message, compilation succeeded.
	    set result [${tool}_load "./$exe" "" ""]
	    set status [lindex $result 0]
	    remote_file build delete $exe
	    verbose "check_vmx_hw_available testfile status is <$status>" 2

	    if { $status == "pass" } then {
		set vmx_hw_available_saved 1
	    }
	} else {
	    verbose "check_vmx_hw_availalble testfile compilation failed" 2
	}
    }

    return $vmx_hw_available_saved
}

# Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
# emitted, 0 otherwise.  Whether a shared library can actually be built is
# out of scope for this test.
#
# When the target name changes, replace the cached result.

proc check_effective_target_fpic { } {
    global et_fpic_saved
    global et_fpic_target_name

    if { ![info exists et_fpic_target_name] } {
	set et_fpic_target_name ""
    }

    # If the target has changed since we set the cached value, clear it.
    set current_target [current_target_name]
    if { $current_target != $et_fpic_target_name } {
	verbose "check_effective_target_fpic: `$et_fpic_target_name'" 2
	set et_fpic_target_name $current_target
	if [info exists et_fpic_saved] {
	    verbose "check_effective_target_fpic: removing cached result" 2
	    unset et_fpic_saved
	}
    }

    if [info exists et_fpic_saved] {
	verbose "check_effective_target_fpic: using cached result" 2
    } else {
	verbose "check_effective_target_fpic: compiling source" 2

	# Note that M68K has a multilib that supports -fpic but not
	# -fPIC, so we need to check both.  We test with a program that
	# requires GOT references.
	set et_fpic_saved [string match "" [get_compiler_messages fpic object {
	    extern int foo (void); extern int bar;
	    int baz (void) { return foo () + bar; }
	} "-fpic"]]

	if { $et_fpic_saved != 0 } {
	    set et_fpic_saved [string match "" [get_compiler_messages fpic object {
		extern int foo (void); extern int bar;
		int baz (void) { return foo () + bar; }
	    } "-fPIC"]]
	}
    }
    verbose "check_effective_target_fpic: returning $et_fpic_saved" 2
    return $et_fpic_saved
}

# Return 1 if we're generating 32-bit code using default options, 0
# otherwise.
#
# When the target name changes, replace the cached result.

proc check_effective_target_ilp32 { } {
    global et_ilp32_saved
    global et_ilp32_target_name

    if { ![info exists et_ilp32_target_name] } {
	set et_ilp32_target_name ""
    }

    # If the target has changed since we set the cached value, clear it.
    set current_target [current_target_name]
    if { $current_target != $et_ilp32_target_name } {
	verbose "check_effective_target_ilp32: `$et_ilp32_target_name' `$current_target'" 2
	set et_ilp32_target_name $current_target
	if { [info exists et_ilp32_saved] } {
	    verbose "check_effective_target_ilp32: removing cached result" 2
	    unset et_ilp32_saved
	}
    }

    if [info exists et_ilp32_saved] {
	verbose "check-effective_target_ilp32: using cached result" 2
    } else {
	verbose "check_effective_target_ilp32: compiling source" 2
	set et_ilp32_saved [string match "" [get_compiler_messages ilp32 object {
	    int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
	}]]
    }
    verbose "check_effective_target_ilp32: returning $et_ilp32_saved" 2
    return $et_ilp32_saved
}

# Return 1 if we're generating 64-bit code using default options, 0
# otherwise.
#
# When the target name changes, replace the cached result.

proc check_effective_target_lp64 { } {
    global et_lp64_saved
    global et_lp64_target_name

    if { ![info exists et_lp64_target_name] } {
	set et_lp64_target_name ""
    }

    # If the target has changed since we set the cached value, clear it.
    set current_target [current_target_name]
    if { $current_target != $et_lp64_target_name } {
	verbose "check_effective_target_lp64: `$et_lp64_target_name' `$current_target'" 2
	set et_lp64_target_name $current_target
	if [info exists et_lp64_saved] {
	    verbose "check_effective_target_lp64: removing cached result" 2
	    unset et_lp64_saved
	}
    }

    if [info exists et_lp64_saved] {
	verbose "check_effective_target_lp64: using cached result" 2
    } else {
	verbose "check_effective_target_lp64: compiling source" 2
	set et_lp64_saved [string match "" [get_compiler_messages lp64 object {
	    int dummy[(sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ) ? 1 : -1];
	}]]
    }
    verbose "check_effective_target_lp64: returning $et_lp64_saved" 2
    return $et_lp64_saved
}

# Return 1 if the target matches the effective target 'arg', 0 otherwise.
# This can be used with any check_* proc that takes no argument and
# returns only 1 or 0.  It could be used with check_* procs that take
# arguments with keywords that pass particular arguments.

proc is-effective-target { arg } {
    set selected 0
    if { [info procs check_effective_target_${arg}] != [list] } {
	set selected [check_effective_target_${arg}]
    } else {
	switch $arg {
	  "vmx_hw"         { set selected [check_vmx_hw_available] }
	  "named_sections" { set selected [check_named_sections_available] }
	  "gc_sections"    { set selected [check_gc_sections_available] }
	  default          { error "unknown effective target keyword `$arg'" }
	}
    }
    verbose "is-effective-target: $arg $selected" 2
    return $selected
}

# Return 1 if the argument is an effective-target keyword, 0 otherwise.

proc is-effective-target-keyword { arg } {
    if { [info procs check_effective_target_${arg}] != [list] } {
	return 1
    } else {
	# These have different names for their check_* procs.
	switch $arg {
	  "vmx_hw"         { return 1 }
	  "named_sections" { return 1 }
	  "gc_sections"    { return 1 }
	  default          { return 0 }
	}
    }
}