public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch] ld testsuite: Fix some FAILs caused by missing -fpic.
@ 2011-12-05 23:52 David Daney
  2011-12-06 10:33 ` nick clifton
  0 siblings, 1 reply; 5+ messages in thread
From: David Daney @ 2011-12-05 23:52 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]

Since the beginning of time (or at least CVS), there has been special 
code in the ld testsuite to  omit -fpic from the flags used for building 
shared libraries on MIPS.  This worked for very old versions of GCC 
where the generated code was always PIC by default.

Since GCC-4.3, -fpic has been mandatory for creation of shared objects, 
and the testsuite's lack of this flag has caused many test cases to fail.

I propose that we remove this special handling and pass -fpic, just as 
we do for almost all other targets.  Doing this fixes about twenty FAILs.

Tested on mips64-linux-gnu and x86_64-linux-gnu with no regressions.

OK to commit?

2011-12-05  David Daney  <david.daney@cavium.com>

	* ld-elfvers/vers.exp (picflag): Remove special handling for mips*-*-*.
	(pic): Set to "yes" for mips*-*-linux*.
	* ld-elfvsb/elfvsb.exp: Don't test non-PIC shared libraried on
	mips*-*-linux*.
	( picflag): Remove special handling for mips*-*-*.
	* ld-elfweak/elfweak.exp (picflag): Remove special handling
	for mips*-*-*.
	* ld-shared/shared.exp (picflag): Same.

[-- Attachment #2: dd-1.patch --]
[-- Type: text/plain, Size: 7771 bytes --]

Index: ld/testsuite/ld-elfvers/vers.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfvers/vers.exp,v
retrieving revision 1.53
diff -u -p -r1.53 vers.exp
--- ld/testsuite/ld-elfvers/vers.exp	15 Mar 2011 23:34:30 -0000	1.53
+++ ld/testsuite/ld-elfvers/vers.exp	5 Dec 2011 20:15:51 -0000
@@ -72,26 +72,22 @@ set SOBJDUMP_FLAGS --syms
 set shared "--shared --no-undefined-version"
 set script --version-script
 
-if [istarget mips*-*-*] {
-    set picflag ""
-} else {
-    # Unfortunately, the gcc argument is -fpic and the cc argument is
-    # -KPIC.  We have to try both.
-    set picflag "-fpic"
-    send_log "$CC $picflag\n"
-    verbose "$CC $picflag"
-    catch "exec $CC $picflag" exec_output
-    send_log "$exec_output\n"
-    verbose "--" "$exec_output"
-    if { [string match "*illegal option*" $exec_output]
-	 || [string match "*option ignored*" $exec_output]
-	 || [string match "*unrecognized option*" $exec_output]
-	 || [string match "*passed to ld*" $exec_output] } {
-	if [istarget *-*-sunos4*] {
-	    set picflag "-pic"
-	} else {
-	    set picflag "-KPIC"
-	}
+# Unfortunately, the gcc argument is -fpic and the cc argument is
+# -KPIC.  We have to try both.
+set picflag "-fpic"
+send_log "$CC $picflag\n"
+verbose "$CC $picflag"
+catch "exec $CC $picflag" exec_output
+send_log "$exec_output\n"
+verbose "--" "$exec_output"
+if { [string match "*illegal option*" $exec_output]
+     || [string match "*option ignored*" $exec_output]
+     || [string match "*unrecognized option*" $exec_output]
+     || [string match "*passed to ld*" $exec_output] } {
+    if [istarget *-*-sunos4*] {
+	set picflag "-pic"
+    } else {
+	set picflag "-KPIC"
     }
 }
 
@@ -768,8 +764,8 @@ proc build_exec { test source execname f
     pass $test
 }
 
-if [istarget x86_64-*-linux*] {
-    # x86_64 doesn't like non-pic shared libraries
+if { [istarget x86_64-*-linux*] || [istarget mips*-*-linux*] } {
+    # x86_64 and MIPS don't like non-pic shared libraries
     set pic "yes"
 } else {
     set pic "no"
Index: ld/testsuite/ld-elfvsb/elfvsb.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfvsb/elfvsb.exp,v
retrieving revision 1.36
diff -u -p -r1.36 elfvsb.exp
--- ld/testsuite/ld-elfvsb/elfvsb.exp	19 Jun 2011 21:22:13 -0000	1.36
+++ ld/testsuite/ld-elfvsb/elfvsb.exp	5 Dec 2011 20:15:51 -0000
@@ -249,7 +249,7 @@ proc visibility_run {visibility} {
 	set VSBCFLAG ""
     }}}}}}}}}
 
-    if { [istarget powerpc*-*-linux*] } {
+    if { [istarget powerpc*-*-linux*] || [istarget mips*-*-linux*] } {
 	# Testing non-PIC libraries is a waste of effort on any target.
 	# If you don't pass -fpic or -fPIC to gcc, gcc will assume quite
 	# reasonably that you are not compiling for a shared library.
@@ -453,26 +453,22 @@ proc visibility_run {visibility} {
     }}
 }
 
-if [istarget mips*-*-*] {
-    set picflag ""
-} else {
-    # Unfortunately, the gcc argument is -fpic and the cc argument is
-    # -KPIC.  We have to try both.
-    set picflag "-fpic"
-    send_log "$CC $picflag\n"
-    verbose "$CC $picflag"
-    catch "exec $CC $picflag" exec_output
-    send_log "$exec_output\n"
-    verbose "--" "$exec_output"
-    if { [string match "*illegal option*" $exec_output] \
-	 || [string match "*option ignored*" $exec_output] \
-	 || [string match "*unrecognized option*" $exec_output] \
-	 || [string match "*passed to ld*" $exec_output] } {
-	if [istarget *-*-sunos4*] {
-	    set picflag "-pic"
-	} else {
-	    set picflag "-KPIC"
-	}
+# Unfortunately, the gcc argument is -fpic and the cc argument is
+# -KPIC.  We have to try both.
+set picflag "-fpic"
+send_log "$CC $picflag\n"
+verbose "$CC $picflag"
+catch "exec $CC $picflag" exec_output
+send_log "$exec_output\n"
+verbose "--" "$exec_output"
+if { [string match "*illegal option*" $exec_output] \
+     || [string match "*option ignored*" $exec_output] \
+     || [string match "*unrecognized option*" $exec_output] \
+     || [string match "*passed to ld*" $exec_output] } {
+    if [istarget *-*-sunos4*] {
+	set picflag "-pic"
+    } else {
+	set picflag "-KPIC"
     }
 }
 verbose "Using $picflag to compile PIC code"
Index: ld/testsuite/ld-elfweak/elfweak.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfweak/elfweak.exp,v
retrieving revision 1.18
diff -u -p -r1.18 elfweak.exp
--- ld/testsuite/ld-elfweak/elfweak.exp	21 Dec 2010 11:00:48 -0000	1.18
+++ ld/testsuite/ld-elfweak/elfweak.exp	5 Dec 2011 20:15:51 -0000
@@ -370,26 +370,22 @@ proc build_exec { test execname objs fla
     pass $test
 }
 
-if [istarget mips*-*-*] {
-    set picflag ""
-} else {
-    # Unfortunately, the gcc argument is -fpic and the cc argument is
-    # -KPIC.  We have to try both.
-    set picflag "-fpic"
-    send_log "$CC $picflag\n"
-    verbose "$CC $picflag"
-    catch "exec $CC $picflag" exec_output
-    send_log "$exec_output\n"
-    verbose "--" "$exec_output"
-    if { [string match "*illegal option*" $exec_output]
-	 || [string match "*option ignored*" $exec_output]
-	 || [string match "*unrecognized option*" $exec_output]
-	 || [string match "*passed to ld*" $exec_output] } {
-	if [istarget *-*-sunos4*] {
-	    set picflag "-pic"
-	} else {
-	    set picflag "-KPIC"
-	}
+# Unfortunately, the gcc argument is -fpic and the cc argument is
+# -KPIC.  We have to try both.
+set picflag "-fpic"
+send_log "$CC $picflag\n"
+verbose "$CC $picflag"
+catch "exec $CC $picflag" exec_output
+send_log "$exec_output\n"
+verbose "--" "$exec_output"
+if { [string match "*illegal option*" $exec_output]
+     || [string match "*option ignored*" $exec_output]
+     || [string match "*unrecognized option*" $exec_output]
+     || [string match "*passed to ld*" $exec_output] } {
+    if [istarget *-*-sunos4*] {
+	set picflag "-pic"
+    } else {
+	set picflag "-KPIC"
     }
 }
 verbose "Using $picflag to compile PIC code"
Index: ld/testsuite/ld-shared/shared.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-shared/shared.exp,v
retrieving revision 1.27
diff -u -p -r1.27 shared.exp
--- ld/testsuite/ld-shared/shared.exp	19 Jun 2011 21:22:13 -0000	1.27
+++ ld/testsuite/ld-shared/shared.exp	5 Dec 2011 20:15:51 -0000
@@ -181,26 +181,22 @@ proc shared_test { progname testname mai
     pass "$testname"
 }
 
-if [istarget mips*-*-*] {
-    set picflag ""
-} else {
-    # Unfortunately, the gcc argument is -fpic and the cc argument is
-    # -KPIC.  We have to try both.
-    set picflag "-fpic"
-    send_log "$CC $picflag\n"
-    verbose "$CC $picflag"
-    catch "exec $CC $picflag" exec_output
-    send_log "$exec_output\n"
-    verbose "--" "$exec_output"
-    if { [string match "*illegal option*" $exec_output] \
-	 || [string match "*option ignored*" $exec_output] \
-	 || [string match "*unrecognized option*" $exec_output] \
-	 || [string match "*passed to ld*" $exec_output] } {
-	if [istarget *-*-sunos4*] {
-	    set picflag "-pic"
-	} else {
-	    set picflag "-KPIC"
-	}
+# Unfortunately, the gcc argument is -fpic and the cc argument is
+# -KPIC.  We have to try both.
+set picflag "-fpic"
+send_log "$CC $picflag\n"
+verbose "$CC $picflag"
+catch "exec $CC $picflag" exec_output
+send_log "$exec_output\n"
+verbose "--" "$exec_output"
+if { [string match "*illegal option*" $exec_output] \
+     || [string match "*option ignored*" $exec_output] \
+     || [string match "*unrecognized option*" $exec_output] \
+     || [string match "*passed to ld*" $exec_output] } {
+    if [istarget *-*-sunos4*] {
+	set picflag "-pic"
+    } else {
+	set picflag "-KPIC"
     }
 }
 verbose "Using $picflag to compile PIC code"

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] ld testsuite: Fix some FAILs caused by missing -fpic.
  2011-12-05 23:52 [Patch] ld testsuite: Fix some FAILs caused by missing -fpic David Daney
@ 2011-12-06 10:33 ` nick clifton
  2011-12-06 17:12   ` David Daney
  0 siblings, 1 reply; 5+ messages in thread
From: nick clifton @ 2011-12-06 10:33 UTC (permalink / raw)
  To: David Daney; +Cc: binutils

Hi David,

> Since the beginning of time (or at least CVS), there has been special
> code in the ld testsuite to omit -fpic from the flags used for building
> shared libraries on MIPS. This worked for very old versions of GCC where
> the generated code was always PIC by default.

How old is "very old" ?

> I propose that we remove this special handling and pass -fpic, just as
> we do for almost all other targets. Doing this fixes about twenty FAILs.

If "very old" actually includes any of the 4.x versions of gcc then I 
would be inclined to say that a better fix would be to check the gcc 
version number and only omit "-fpic" if it is not needed.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] ld testsuite: Fix some FAILs caused by missing -fpic.
  2011-12-06 10:33 ` nick clifton
@ 2011-12-06 17:12   ` David Daney
  2011-12-07 11:25     ` nick clifton
  0 siblings, 1 reply; 5+ messages in thread
From: David Daney @ 2011-12-06 17:12 UTC (permalink / raw)
  To: nick clifton; +Cc: binutils, Richard Sandiford

On 12/06/2011 02:33 AM, nick clifton wrote:
> Hi David,
>
>> Since the beginning of time (or at least CVS), there has been special
>> code in the ld testsuite to omit -fpic from the flags used for building
>> shared libraries on MIPS. This worked for very old versions of GCC where
>> the generated code was always PIC by default.
>
> How old is "very old" ?

GCC-4.2 and earlier.

>
>> I propose that we remove this special handling and pass -fpic, just as
>> we do for almost all other targets. Doing this fixes about twenty FAILs.
>
> If "very old" actually includes any of the 4.x versions of gcc then I
> would be inclined to say that a better fix would be to check the gcc
> version number and only omit "-fpic" if it is not needed.

That is too much work.  Although I haven't tested it, supplying -fpic 
will not break anything in any GCC version I know about.  I think 
GCC-2.95 and later should be fine with this, certainly any GCC-4.x and 
later compiler can handle -fpic.

David Daney


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] ld testsuite: Fix some FAILs caused by missing -fpic.
  2011-12-06 17:12   ` David Daney
@ 2011-12-07 11:25     ` nick clifton
  2011-12-07 17:25       ` David Daney
  0 siblings, 1 reply; 5+ messages in thread
From: nick clifton @ 2011-12-07 11:25 UTC (permalink / raw)
  To: David Daney; +Cc: binutils, Richard Sandiford

[-- Attachment #1: Type: text/plain, Size: 774 bytes --]

Hi David, Daney

>> How old is "very old" ?
>
> GCC-4.2 and earlier.

>> If "very old" actually includes any of the 4.x versions of gcc then I
>> would be inclined to say that a better fix would be to check the gcc
>> version number and only omit "-fpic" if it is not needed.
>
> That is too much work.

No it's not.  See the attached patch for a suggestion of how to do this.

> Although I haven't tested it, supplying -fpic
> will not break anything in any GCC version I know about. I think
> GCC-2.95 and later should be fine with this, certainly any GCC-4.x and
> later compiler can handle -fpic.

If passing -fpic to gcc was not a problem for the mips compiler then why 
were these special tests added to the linker test harness in the first 
place ?

Cheers
   Nick



[-- Attachment #2: mips-pic.patch --]
[-- Type: text/plain, Size: 5103 bytes --]

Index: ld/testsuite/ld-elfvers/vers.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfvers/vers.exp,v
retrieving revision 1.53
diff -u -3 -p -r1.53 vers.exp
--- ld/testsuite/ld-elfvers/vers.exp	15 Mar 2011 23:34:30 -0000	1.53
+++ ld/testsuite/ld-elfvers/vers.exp	7 Dec 2011 11:21:36 -0000
@@ -72,7 +72,9 @@ set SOBJDUMP_FLAGS --syms
 set shared "--shared --no-undefined-version"
 set script --version-script
 
-if [istarget mips*-*-*] {
+# Old version of GCC for MIPS default to enabling -fpic
+# and get confused if it is used on the command line.
+if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
     set picflag ""
 } else {
     # Unfortunately, the gcc argument is -fpic and the cc argument is
@@ -768,8 +770,9 @@ proc build_exec { test source execname f
     pass $test
 }
 
-if [istarget x86_64-*-linux*] {
-    # x86_64 doesn't like non-pic shared libraries
+if { [istarget x86_64-*-linux*] \
+     || ( [istarget mips*-*-linux*] && [at_least_gcc_version 4 3] ) } {
+    # x86_64 and newer MIPS toolchains do not like non-pic shared libraries
     set pic "yes"
 } else {
     set pic "no"
Index: ld/testsuite/ld-elfvsb/elfvsb.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfvsb/elfvsb.exp,v
retrieving revision 1.36
diff -u -3 -p -r1.36 elfvsb.exp
--- ld/testsuite/ld-elfvsb/elfvsb.exp	19 Jun 2011 21:22:13 -0000	1.36
+++ ld/testsuite/ld-elfvsb/elfvsb.exp	7 Dec 2011 11:21:36 -0000
@@ -249,7 +249,8 @@ proc visibility_run {visibility} {
 	set VSBCFLAG ""
     }}}}}}}}}
 
-    if { [istarget powerpc*-*-linux*] } {
+    if { [istarget powerpc*-*-linux*] \
+	 || ( [istarget mips*-*-linux*] && [at_least_gcc_version 4 3] )} {
 	# Testing non-PIC libraries is a waste of effort on any target.
 	# If you don't pass -fpic or -fPIC to gcc, gcc will assume quite
 	# reasonably that you are not compiling for a shared library.
@@ -453,7 +454,9 @@ proc visibility_run {visibility} {
     }}
 }
 
-if [istarget mips*-*-*] {
+# Old version of GCC for MIPS default to enabling -fpic
+# and get confused if it is used on the command line.
+if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
     set picflag ""
 } else {
     # Unfortunately, the gcc argument is -fpic and the cc argument is
Index: ld/testsuite/ld-elfweak/elfweak.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elfweak/elfweak.exp,v
retrieving revision 1.18
diff -u -3 -p -r1.18 elfweak.exp
--- ld/testsuite/ld-elfweak/elfweak.exp	21 Dec 2010 11:00:48 -0000	1.18
+++ ld/testsuite/ld-elfweak/elfweak.exp	7 Dec 2011 11:21:36 -0000
@@ -370,7 +370,9 @@ proc build_exec { test execname objs fla
     pass $test
 }
 
-if [istarget mips*-*-*] {
+# Old version of GCC for MIPS default to enabling -fpic
+# and get confused if it is used on the command line.
+if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
     set picflag ""
 } else {
     # Unfortunately, the gcc argument is -fpic and the cc argument is
Index: ld/testsuite/ld-shared/shared.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-shared/shared.exp,v
retrieving revision 1.27
diff -u -3 -p -r1.27 shared.exp
--- ld/testsuite/ld-shared/shared.exp	19 Jun 2011 21:22:13 -0000	1.27
+++ ld/testsuite/ld-shared/shared.exp	7 Dec 2011 11:21:36 -0000
@@ -181,7 +181,9 @@ proc shared_test { progname testname mai
     pass "$testname"
 }
 
-if [istarget mips*-*-*] {
+# Old version of GCC for MIPS default to enabling -fpic
+# and get confused if it is used on the command line.
+if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
     set picflag ""
 } else {
     # Unfortunately, the gcc argument is -fpic and the cc argument is
Index: ld/testsuite/lib/ld-lib.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v
retrieving revision 1.88
diff -u -3 -p -r1.88 ld-lib.exp
--- ld/testsuite/lib/ld-lib.exp	29 Nov 2011 12:42:10 -0000	1.88
+++ ld/testsuite/lib/ld-lib.exp	7 Dec 2011 11:21:36 -0000
@@ -27,6 +27,31 @@ proc load_common_lib { name } {
 
 load_common_lib binutils-common.exp
 
+# Returns 1 if the gcc for the target is at least version MAJOR.MINOR
+# Returns 0 otherwise.
+#
+proc at_least_gcc_version { major minor } {
+    
+    if {![info exists CC]} {
+	set CC [find_gcc]
+    }
+    if { $CC == "" } {
+      return 0
+    }
+    set state [remote_exec host $CC --version]
+    set tmp "[lindex $state 1]\n"
+    # Look for (eg) 4.6.1 in the version output.
+    regexp " .* (\[1-9\])\\.(\[0-9\])\\.\[0-9\]* .*" "$tmp" fred maj min
+    verbose "gcc version: $tmp"
+    verbose "major gcc version is $maj, want at least $major"
+    if { $maj == $major } then {
+	verbose "minor gcc version is $min, want at least $minor"
+	return $min >= $minor
+    } else {
+	return $maj > $major
+    }
+}
+
 # Extract and print the version number of ld.
 #
 proc default_ld_version { ld } {

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] ld testsuite: Fix some FAILs caused by missing -fpic.
  2011-12-07 11:25     ` nick clifton
@ 2011-12-07 17:25       ` David Daney
  0 siblings, 0 replies; 5+ messages in thread
From: David Daney @ 2011-12-07 17:25 UTC (permalink / raw)
  To: nick clifton, Eric Christopher; +Cc: binutils, Richard Sandiford

On 12/07/2011 03:24 AM, nick clifton wrote:
> Hi David, Daney
>
>>> How old is "very old" ?
>>
>> GCC-4.2 and earlier.
>
>>> If "very old" actually includes any of the 4.x versions of gcc then I
>>> would be inclined to say that a better fix would be to check the gcc
>>> version number and only omit "-fpic" if it is not needed.
>>
>> That is too much work.
>
> No it's not.  See the attached patch for a suggestion of how to do this.
>

That patch looks fine to me, and since you are a Maintainer, I would 
encourage you to commit it if you are happy with it.

That said, I think it may be overkill as no sane person would be testing 
a modern mips binutils with a pre-2.95 GCC.


>> Although I haven't tested it, supplying -fpic
>> will not break anything in any GCC version I know about. I think
>> GCC-2.95 and later should be fine with this, certainly any GCC-4.x and
>> later compiler can handle -fpic.
>
> If passing -fpic to gcc was not a problem for the mips compiler then why
> were these special tests added to the linker test harness in the first
> place ?
>

I wasn't around when it was created.

Eric Christopher might know.

If neither you nor Eric know, then I think we have to live with the 
possibility that this information has been lost forever.

David Daney

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-12-07 17:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-05 23:52 [Patch] ld testsuite: Fix some FAILs caused by missing -fpic David Daney
2011-12-06 10:33 ` nick clifton
2011-12-06 17:12   ` David Daney
2011-12-07 11:25     ` nick clifton
2011-12-07 17:25       ` David Daney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).