This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Second version Re: [RFA:] testsuite/target-supports.exp: check_effective_target_fpic
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: drow at false dot org
- Date: Wed, 6 Apr 2005 03:22:41 +0200
- Subject: Second version Re: [RFA:] testsuite/target-supports.exp: check_effective_target_fpic
> Date: Tue, 5 Apr 2005 21:04:29 -0400
> From: Daniel Jacobowitz <drow@false.org>
> > > There can be multilibs incompatible with position-independent
> > > code.
> >
> > In theory, yes. Do you know of any in practice?
>
> We implemented one several weeks ago (not contributed yet, but it will
> be) - defined for ARM but not Thumb.
>
> M68K has one:
> /* -fPIC uses 32-bit pc-relative displacements, which don't exist
> until the 68020. */
> if (!TARGET_68020 && !TARGET_COLDFIRE && (flag_pic == 2))
> error("-fPIC is not currently supported on the 68000 or 68010\n");
Perhaps I should clarify why I did it like that: It's trivial to
add code to handle that (using other procs as template), but I
can't really test it.
Blah, I see you killed another assumption (-fPIC always
supported where -fpic is). Oh well, changes tested on host as
before, I really wouldn't mind if you test on your target:
* lib/target-supports.exp (get_compiler_messages): Support
optional arguments, the fourth being compiler options.
(check_effective_target_fpic): New proc.
Index: target-supports.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/target-supports.exp,v
retrieving revision 1.46
diff -p -c -r1.46 target-supports.exp
*** target-supports.exp 25 Mar 2005 02:21:01 -0000 1.46
--- target-supports.exp 6 Apr 2005 01:13:46 -0000
***************
*** 24,32 ****
# 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.
! proc get_compiler_messages {basename type contents} {
global tool
set src ${basename}[pid].c
switch $type {
assembly { set output ${basename}[pid].s }
--- 24,40 ----
# 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 }
*************** proc get_compiler_messages {basename typ
*** 35,41 ****
set f [open $src "w"]
puts $f $contents
close $f
! set lines [${tool}_target_compile $src $output $type ""]
file delete $src
remote_file build delete $output
--- 43,49 ----
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
*************** proc check_profiling_available { test_wh
*** 295,300 ****
--- 303,356 ----
return $profiling_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
+
+ 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 true if iconv is supported on the target. In particular IBM1047.
proc check_iconv_available { test_what } {
brgds, H-P