This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, MIPS] diagnose -fpic/-fpie incompatibility with -mno-abicalls


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]