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 <san...@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.
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} } */