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

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