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]

[PATCH, MIPS] SDE -fpic means -mabicalls


This is a patch originally from MIPS that I am submitting on their
behalf.

The intent of this patch is to fix a historical error, which is that the
MIPS toolchain is the only one where you can't use -fpic to get PIC
code.  Instead, you have to use -mabicalls.  So this patch makes -fpic
imply -mabicalls.  To avoid some code duplication, I borrowed the
SUBSUBTARGET trick from the rs6000 port.  This patch only affects the
sde targets.

While looking at the -fpic support, I noticed that I also needed to
change the gcc.target/mips/mips.exp file.  This file assumes that -fpic
implies -mshared, but this is only true for the linux targets which do
this in a spec in the linux.h file.  So I made this conditional on the
linux targets, and added a line that make -fpic imply -mabicalls for the
sde targets.  There are no tests in this directory that currently use
-fpic, so this does not have any actual affect.

This was manually tested by building sde and sdemtk toolchains and
verify that -fpic did what I expected.

This patch was also tested on the gdb simulator, using the
mipsisa32-sde-elf configuration, and runnning tests with -mabicalls and
-fpic to verify that I got reasonably consistent results.  The results
are a little different with -fpic because that affects symbol resolution
and hence some optimizations, but they are within reason.

I did notice that I got a few too many ICEs; I will be looking at that
separately.

This patch follows the intent of the original MIPS patch which is to
only change the sde targets.  It might be worth doing this for other
MIPS targets too.  I think this is a generally good idea, but haven't
tried to do that at this time.  I noticed that the vxworks target has
some -fpic support, so that one might need a little work.  The linux
target already has -mabicalls hard wired on, so this change would not
affect the linux targets.  And the other targets apparently don't use
-fpic currently.

Jim

testsuite/ChangeLog
2010-04-12  James E. Wilson  <wilson@codesourcery.com>

	* gcc.target/mips/mips.exp: Test istarget for -fpic dependencies.

gcc/ChangeLog

2010-04-12  James E. Wilson  <wilson@codesourcery.com>
	    Thiemo Seufer  <ths@mips.com>

	* config/mips/sde.h (SUBSUBTARGET_OVERRIDE_OPTIONS): New.
	(SUBTARGET_OVERRIDE_OPTIONS): New.
	* config/mips/sdemtk.h (SUBSUBTARGET_OVERRIDE_OPTIONS): Renamed from
	SUBTARGET_OVERRIDE_OPTIONS.

Index: testsuite/gcc.target/mips/mips.exp
===================================================================
--- testsuite/gcc.target/mips/mips.exp	(revision 157804)
+++ testsuite/gcc.target/mips/mips.exp	(working copy)
@@ -1,4 +1,4 @@
-# Copyright (C) 1997, 2007, 2008, 2009 Free Software Foundation, Inc.
+# Copyright (C) 1997, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -840,7 +840,11 @@ proc mips-dg-options { args } {
     mips_option_dependency options "-mrelax-pic-calls" "-mno-plt"
     mips_option_dependency options "-mrelax-pic-calls" "-mabicalls"
     mips_option_dependency options "-mrelax-pic-calls" "-mexplicit-relocs"
-    mips_option_dependency options "-fpic" "-mshared"
+    if { [istarget *-*-linux*] } {
+        mips_option_dependency options "-fpic" "-mshared"
+    } elseif { [istarget *-sde*-*] } {
+	mips_option_dependency options "-fpic" "-mabicalls"
+    }
     mips_option_dependency options "-mshared" "-mno-plt"
     mips_option_dependency options "-mno-plt" "addressing=unknown"
     mips_option_dependency options "-mabicalls" "-G0"
Index: config/mips/sde.h
===================================================================
--- config/mips/sde.h	(revision 157804)
+++ config/mips/sde.h	(working copy)
@@ -1,6 +1,6 @@
 /* Definitions of target machine for GNU compiler.
    MIPS SDE version.
-   Copyright (C) 2003, 2004, 2007, 2008, 2009
+   Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -144,3 +144,22 @@ along with GCC; see the file COPYING3.  
 	jal " USER_LABEL_PREFIX #FUNC "\n\
 	.set pop\n\
 	" TEXT_SECTION_ASM_OP);
+
+/* This is redefined by the sdemtk.h file if it is included.  */
+#define SUBSUBTARGET_OVERRIDE_OPTIONS
+
+#undef SUBTARGET_OVERRIDE_OPTIONS
+#define SUBTARGET_OVERRIDE_OPTIONS			\
+  do							\
+    {							\
+      /* Switch on ABICALLS mode if -fpic or -fpie were \
+	 used, and the user hasn't explicitly disabled	\
+	 these modes.  */				\
+      if ((flag_pic || flag_pie) && !TARGET_ABICALLS	\
+	  && !(target_flags_explicit & MASK_ABICALLS)	\
+	  && mips_abi != ABI_EABI)			\
+	target_flags |= MASK_ABICALLS;			\
+							\
+      SUBSUBTARGET_OVERRIDE_OPTIONS;			\
+    }							\
+while (0)
Index: config/mips/sdemtk.h
===================================================================
--- config/mips/sdemtk.h	(revision 157804)
+++ config/mips/sdemtk.h	(working copy)
@@ -1,6 +1,6 @@
 /* Definitions of target machine for GNU compiler.
    MIPS SDE version, for use with the SDE C library rather than newlib.
-   Copyright (C) 2007, 2008, 2009
+   Copyright (C) 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -57,8 +57,8 @@ along with GCC; see the file COPYING3.  
     }							\
   while (0)
 
-#undef SUBTARGET_OVERRIDE_OPTIONS
-#define SUBTARGET_OVERRIDE_OPTIONS			\
+#undef SUBSUBTARGET_OVERRIDE_OPTIONS
+#define SUBSUBTARGET_OVERRIDE_OPTIONS			\
   do							\
     {							\
       if (TARGET_NO_FLOAT)				\

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