Jakub Jelinek <ja...@redhat.com> writes:

> On Fri, Jun 03, 2011 at 09:38:31PM +0200, Rainer Orth wrote:
>> Rainer Orth <r...@cebitec.uni-bielefeld.de> writes:
>> Jakub, any suggestion how to properly test for -fpie/-fPIE support?
>> Otherwise, I'll remove that part of the patch for now and just commit
>> the -fpic/-fPIC one.
>
> You want to compile/link the program with -pie -fpie rather than just -fpie,
> if it links, otherwise you are testing just linking PIC code into normal
> executables.

Ok, thanks.  Unfortunately, this didn't work out of the box since for
targets where the linker doesn't support -pie, gcc silently ignores it
which I think is bad style.

The following patch corrects this by rejecting -pie in this case.  I've
also added a effective-target keyword pie for testsuite use, both below
and in the revised TLS torture tests to be submitted separately.

I didn't introduce a separte fpie keyword since e.g. gcc.dg/tls/pie-1.c
uses fpic for that purpose, but maybe I should?

One other question: gcc.target/i386/pr39013-[12].c is currently
restricted to *-*-linux*.  Any particular reason for that?

Bootstrapped without regressions on i386-pc-solaris2.11 with Sun ld (no
-pie support, pie-link becomes UNSUPPORTED) and with GNU ld 2.21 (-pie
support, 32-bit pie-link works, 64-bit pie-link becomes unsupported:

/vol/gcc/bin/gld-2.21: /usr/lib/amd64/crt1.o: relocation R_X86_64_32S against 
`_DYNAMIC' can not be used when making a shared object; recompile with -fPIC
/usr/lib/amd64/crt1.o: could not read symbols: Bad value

).  Ok for mainline?

Thanks.
        Rainer


2011-06-04  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

        gcc:
        * gcc.c [!HAVE_LD_PIE] (LINK_PIE_SPEC): Reject -pie.
        * doc/sourcebuild.texi (Effective-Target Keywords, pie): Document it.

        gcc/testsuite:
        * lib/target-supports.exp (check_effective_target_pie): New proc.
        * gcc.dg/pie-link.c: Use target pie.
        Add -pie to dg-options.

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1782,6 +1782,9 @@ Target defines @code{PCC_BITFIELD_TYPE_M
 @item pe_aligned_commons
 Target supports @option{-mpe-aligned-commons}.
 
+@item pie
+Target supports @option{-pie}, @option{-fpie} and @option{-fPIE}.
+
 @item section_anchors
 Target supports section anchors.
 
diff --git a/gcc/gcc.c b/gcc/gcc.c
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -612,7 +612,7 @@ proper position among the other output f
 #ifdef HAVE_LD_PIE
 #define LINK_PIE_SPEC "%{pie:-pie} "
 #else
-#define LINK_PIE_SPEC "%{pie:} "
+#define LINK_PIE_SPEC "%{pie:%e-pie is not supported in this configuration} "
 #endif
 #endif
 
diff --git a/gcc/testsuite/gcc.dg/pie-link.c b/gcc/testsuite/gcc.dg/pie-link.c
--- a/gcc/testsuite/gcc.dg/pie-link.c
+++ b/gcc/testsuite/gcc.dg/pie-link.c
@@ -1,5 +1,5 @@
-/* { dg-do link { target *-*-darwin[912]* *-*-linux* } } */
-/* { dg-options "-fpie" } */
+/* { dg-do link { target pie } } */
+/* { dg-options "-pie -fpie" } */
 
 int main(void)
 {
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -788,6 +788,18 @@ proc check_effective_target_fpic { } {
     return 0
 }
 
+# Return 1 if -pie, -fpie and -fPIE are supported, as in no warnings or errors
+# emitted, 0 otherwise.
+
+proc check_effective_target_pie { } {
+    if [check_no_compiler_messages pie executable {
+       int main (void) { return 0; }
+    } "-pie -fpie"] {
+       return 1
+    }
+    return 0
+}
+
 # Return true if the target supports -mpaired-single (as used on MIPS).
 
 proc check_effective_target_mpaired_single { } {


-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

Reply via email to