public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, MIPS] diagnose -fpic/-fpie incompatibility with -mno-abicalls
@ 2012-08-03 17:41 Sandra Loosemore
  2012-08-04 14:09 ` Richard Sandiford
  0 siblings, 1 reply; 3+ messages in thread
From: Sandra Loosemore @ 2012-08-03 17:41 UTC (permalink / raw)
  To: gcc-patches

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

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.)

This patch adds a diagnostic to catch the bad option combination, and 
fixes a couple test cases that triggered the new error.  OK for mainline?

-Sandra


2012-08-03  Sandra Loosemore  <sandra@codesourcery.com>

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

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


[-- Attachment #2: abicalls.patch --]
[-- Type: text/x-patch, Size: 2048 bytes --]

Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c	(revision 190052)
+++ gcc/config/mips/mips.c	(working copy)
@@ -15872,6 +15872,8 @@ static void
 mips_option_override (void)
 {
   int i, start, regno, mode;
+  static const char * const mips_abi_name[] =
+    {"-mabi=32", "-mabi=n32", "-mabi=64", "-mabi=eabi", "-mabi=o64"};
 
   if (global_options_set.x_mips_isa_option)
     mips_isa_option_info = &mips_cpu_info_table[mips_isa_option];
@@ -16053,6 +16055,12 @@ mips_option_override (void)
       target_flags &= ~MASK_ABICALLS;
     }
 
+  /* On non-EABI targets, -fpic and -fpie require -mabicalls.  */
+  if (mips_abi != ABI_EABI && (flag_pic || flag_pie) && !TARGET_ABICALLS)
+    error ("the combination of %qs and %qs is incompatible with %qs",
+	   (flag_pic ? "-fpic" : "-fpie"),
+	   "-mno-abicalls", mips_abi_name[mips_abi]);
+
   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 190052)
+++ 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 190052)
+++ 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} }  */

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

* Re: [PATCH, MIPS] diagnose -fpic/-fpie incompatibility with -mno-abicalls
  2012-08-03 17:41 [PATCH, MIPS] diagnose -fpic/-fpie incompatibility with -mno-abicalls Sandra Loosemore
@ 2012-08-04 14:09 ` Richard Sandiford
  2012-08-05  0:39   ` Sandra Loosemore
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2012-08-04 14:09 UTC (permalink / raw)
  To: Sandra Loosemore; +Cc: gcc-patches

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:

> Index: gcc/config/mips/mips.c
> ===================================================================
> --- gcc/config/mips/mips.c	(revision 190052)
> +++ gcc/config/mips/mips.c	(working copy)
> @@ -15872,6 +15872,8 @@ static void
>  mips_option_override (void)
>  {
>    int i, start, regno, mode;
> +  static const char * const mips_abi_name[] =
> +    {"-mabi=32", "-mabi=n32", "-mabi=64", "-mabi=eabi", "-mabi=o64"};
>  
>    if (global_options_set.x_mips_isa_option)
>      mips_isa_option_info = &mips_cpu_info_table[mips_isa_option];
> @@ -16053,6 +16055,12 @@ mips_option_override (void)
>        target_flags &= ~MASK_ABICALLS;
>      }
>  
> +  /* On non-EABI targets, -fpic and -fpie require -mabicalls.  */
> +  if (mips_abi != ABI_EABI && (flag_pic || flag_pie) && !TARGET_ABICALLS)
> +    error ("the combination of %qs and %qs is incompatible with %qs",
> +	   (flag_pic ? "-fpic" : "-fpie"),
> +	   "-mno-abicalls", mips_abi_name[mips_abi]);

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.

Richard

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

* Re: [PATCH, MIPS] diagnose -fpic/-fpie incompatibility with -mno-abicalls
  2012-08-04 14:09 ` Richard Sandiford
@ 2012-08-05  0:39   ` Sandra Loosemore
  0 siblings, 0 replies; 3+ messages in thread
From: Sandra Loosemore @ 2012-08-05  0:39 UTC (permalink / raw)
  To: gcc-patches, rdsandiford

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

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.



[-- Attachment #2: abicalls.patch --]
[-- Type: text/x-patch, Size: 1705 bytes --]

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} }  */

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

end of thread, other threads:[~2012-08-05  0:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-03 17:41 [PATCH, MIPS] diagnose -fpic/-fpie incompatibility with -mno-abicalls Sandra Loosemore
2012-08-04 14:09 ` Richard Sandiford
2012-08-05  0:39   ` Sandra Loosemore

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).