diff mbox

[MIPS] diagnose -fpic/-fpie incompatibility with -mno-abicalls

Message ID 501DC0B9.6060109@codesourcery.com
State New
Headers show

Commit Message

Sandra Loosemore Aug. 5, 2012, 12:39 a.m. UTC
On 08/04/2012 08:09 AM, Richard Sandiford wrote:
> Sandra Loosemore<sandra@codesourcery.com>  writes:
>> For all supported MIPS ABIs other than EABI, compiling with
>> -fpic/-fPIC/-fpie/-fPIE implicitly requires abicalls support.  On Linux
>> targets, -mabicalls is the default, but bare-metal targets like
>> mips-sde-elf default to -mno-abicalls and naively compiling with -fPIC
>> alone doesn't result in working code.  (In fact, even "-fPIC -mabicalls"
>> doesn't work, because -mabicalls then conflicts with the default for -G,
>> and the linker rejects mixing -mabicalls code with -mno-abicalls
>> libraries.)
>
> Yeah.  I was tempted to add a message for this a while back, but I think
> there was resistance from someone who was managing to generate a form of
> PIC with careful use of that combination.  If they did, it was by accident
> rather than design.
>
> However, EABI doesn't support PIC at all.  (There used to be an
> -membedded-pic option, but that's long gone.)  So I think this: [snip]
> should be:
>
>    if (flag_pic)
>      {
>        if (mips_abi == ABI_EABI)
>          error ("cannot generate position-independent code for %qs",
>                 "-mabi=eabi");
>        else if (!TARGET_ABICALLS)
>          error ("position-independent code requires %qs", "-mabicalls");
>      }
>
> (where flag_pie implies flag_pic).  I've removed the -fpic/-fpie thing
> to avoid having to decide between printing "-fpic" and "-fPIC"
> (or "-fpie" and "-fPIE").
>
> OK with that change, if you agree.

Yes indeed -- I was dithering on exactly what the error message should 
say anyway.  I've committed the attached version.

-Sandra

2012-08-04  Sandra Loosemore  <sandra@codesourcery.com>
	    Richard Sandiford  <rdsandiford@googlemail.com>

	gcc/
	* config/mips/mips.c (mips_option_override): Check -fpic
	for compatibility with -mabicalls and ABI.

	gcc/testsuite/
	* g++.dg/opt/enum2.C: Require fpic target.
	* g++.dg/lto/20090303_0.C: Likewise.
diff mbox

Patch

Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c	(revision 190149)
+++ gcc/config/mips/mips.c	(working copy)
@@ -16162,6 +16162,16 @@  mips_option_override (void)
       target_flags &= ~MASK_ABICALLS;
     }
 
+  /* PIC requires -mabicalls.  */
+  if (flag_pic)
+    {
+      if (mips_abi == ABI_EABI)
+	error ("cannot generate position-independent code for %qs",
+	       "-mabi=eabi");
+      else if (!TARGET_ABICALLS)
+	error ("position-independent code requires %qs", "-mabicalls");
+    }
+
   if (TARGET_ABICALLS_PIC2)
     /* We need to set flag_pic for executables as well as DSOs
        because we may reference symbols that are not defined in
Index: gcc/testsuite/g++.dg/opt/enum2.C
===================================================================
--- gcc/testsuite/g++.dg/opt/enum2.C	(revision 190149)
+++ gcc/testsuite/g++.dg/opt/enum2.C	(working copy)
@@ -1,8 +1,8 @@ 
 // PR c++/43680
 // Test that we don't make excessively aggressive assumptions about what
 // values an enum variable can have.
+// { dg-do run { target fpic } }
 // { dg-options "-O2 -fPIC" }
-// { dg-do run }
 
 extern "C" void abort ();
 
Index: gcc/testsuite/g++.dg/lto/20090303_0.C
===================================================================
--- gcc/testsuite/g++.dg/lto/20090303_0.C	(revision 190149)
+++ gcc/testsuite/g++.dg/lto/20090303_0.C	(working copy)
@@ -1,4 +1,5 @@ 
 /* { dg-lto-do run } */
+/* { dg-require-effective-target fpic } */
 /* { dg-lto-options {{-flto -flto-partition=1to1 -fPIC}} } */
 /* { dg-lto-options {{-flto -flto-partition=1to1}} { target sparc*-*-* } } */
 /* { dg-suppress-ld-options {-fPIC} }  */