[PATCH RFC 1/2] MIPS/GCC: Factor out LINK_SPEC

Maciej W. Rozycki macro@imgtec.com
Thu Nov 26 14:35:00 GMT 2015


Factor out common linker specs to LINK_SPEC, to be included from 
individual SUBTARGET_LINK_SPEC definitions, along the lines of 
SUBTARGET_ASM_SPEC, SUBTARGET_CC1_SPEC, SUBTARGET_CPP_SPEC, etc.  This 
essentially revives the use of the LINK_SPEC definition from mips.h 
which by now has become overridden by nearly all MIPS subtargets.  The 
only target omitted from this change is VxWorks.

There is no functional change here in principle, however this does 
change the handling of `-mips*' options a bit for some subtargets which 
used different glob patterns or just listed all individual options meant 
to be supported.  I think such a unification of the MIPS target as a 
whole does make sense, especially in the face of `-mips*' options being 
legacy aliases for corresponding `-march=mips*' options which do not 
receive any special per-subtarget treatment.

Also `%{shared}' despite being common needs special treatment because of 
how `%(netbsd_link_spec)' has been defined.

	gcc/
	* gcc/config/mips/mips.h [!LINK_SHARED_SPEC] (LINK_SHARED_SPEC):
	New macro.
	[!SUBTARGET_LINK_SPEC] (SUBTARGET_LINK_SPEC): Likewise.
	(LINK_SPEC): Replace `%{shared}' with LINK_SHARED_SPEC, add 
	`%(subtarget_link_spec)'.
	(EXTRA_SPECS): Add "subtarget_link_spec".
	* config/mips/gnu-user.h (GNU_USER_TARGET_LINK_SPEC): Remove
	`%{G*}', `%{EB}', `%{EL}', `%{mips*}' and `%{shared}'.
	(LINK_SPEC): Rename macro to...
	(SUBTARGET_LINK_SPEC): ... this.
	* gcc/config/mips/linux-common.h (LINK_SPEC): Rename macro to...
	(SUBTARGET_LINK_SPEC): ... this.
	* gcc/config/mips/netbsd.h (LINK_SHARED_SPEC): New macro.
	(LINK_SPEC): Rename macro to...
	(SUBTARGET_LINK_SPEC): ... this.  Remove `%(endian_spec)', 
	`%{G*}' and all individual `%{mips*}' pieces.
	* gcc/config/mips/sde.h (LINK_SPEC): Rename macro to...
	(SUBTARGET_LINK_SPEC): ... this.  Remove `%(endian_spec)',
	`%{G*}', all individual `%{mips*}' pieces and `%{shared}'.
---
gcc-mips-subtarget-link-spec.diff
Index: gcc/gcc/config/mips/gnu-user.h
===================================================================
--- gcc.orig/gcc/config/mips/gnu-user.h	2015-09-18 00:39:02.199086616 +0100
+++ gcc/gcc/config/mips/gnu-user.h	2015-09-18 01:46:22.970510955 +0100
@@ -54,7 +54,6 @@ along with GCC; see the file COPYING3.  
 
 #undef GNU_USER_TARGET_LINK_SPEC
 #define GNU_USER_TARGET_LINK_SPEC "\
-  %{G*} %{EB} %{EL} %{mips*} %{shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
@@ -66,8 +65,8 @@ along with GCC; see the file COPYING3.  
   %{mabi=64:-m" GNU_USER_LINK_EMULATION64 "} \
   %{mabi=32:-m" GNU_USER_LINK_EMULATION32 "}"
 
-#undef LINK_SPEC
-#define LINK_SPEC GNU_USER_TARGET_LINK_SPEC
+#undef SUBTARGET_LINK_SPEC
+#define SUBTARGET_LINK_SPEC GNU_USER_TARGET_LINK_SPEC
 
 #undef SUBTARGET_ASM_SPEC
 #define SUBTARGET_ASM_SPEC \
Index: gcc/gcc/config/mips/linux-common.h
===================================================================
--- gcc.orig/gcc/config/mips/linux-common.h	2015-09-18 00:39:02.206172580 +0100
+++ gcc/gcc/config/mips/linux-common.h	2015-09-18 00:39:19.891178351 +0100
@@ -27,8 +27,8 @@ along with GCC; see the file COPYING3.  
     ANDROID_TARGET_OS_CPP_BUILTINS();				\
   } while (0)
 
-#undef  LINK_SPEC
-#define LINK_SPEC							\
+#undef  SUBTARGET_LINK_SPEC
+#define SUBTARGET_LINK_SPEC						\
   LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LINK_SPEC,			\
 		       GNU_USER_TARGET_LINK_SPEC " " ANDROID_LINK_SPEC)
 
Index: gcc/gcc/config/mips/mips.h
===================================================================
--- gcc.orig/gcc/config/mips/mips.h	2015-09-18 00:39:02.218248501 +0100
+++ gcc/gcc/config/mips/mips.h	2015-09-18 02:04:47.233407839 +0100
@@ -1334,11 +1334,27 @@ FP_ASM_SPEC "\
 
 /* Extra switches sometimes passed to the linker.  */
 
+/* SUBTARGET_LINK_SPEC is always passed to the linker.  It may be
+   overridden by subtargets.  */
+
+#ifndef SUBTARGET_LINK_SPEC
+#define SUBTARGET_LINK_SPEC ""
+#endif
+
+/* LINK_SHARED_SPEC is usually set to `%{shared}', however some
+   subtargets may have other means to include this spec and wish
+   to override this macro.  Notice the leading space.  */
+
+#ifndef LINK_SHARED_SPEC
+#define LINK_SHARED_SPEC " %{shared}"
+#endif
+
 #ifndef LINK_SPEC
 #define LINK_SPEC "\
 %(endian_spec) \
-%{G*} %{mips1} %{mips2} %{mips3} %{mips4} %{mips32*} %{mips64*} \
-%{shared}"
+%{G*} %{mips1} %{mips2} %{mips3} %{mips4} %{mips32*} %{mips64*}" \
+LINK_SHARED_SPEC " \
+%(subtarget_link_spec)"
 #endif  /* LINK_SPEC defined */
 
 
@@ -1382,6 +1398,7 @@ FP_ASM_SPEC "\
   { "subtarget_cpp_spec", SUBTARGET_CPP_SPEC },				\
   { "subtarget_asm_debugging_spec", SUBTARGET_ASM_DEBUGGING_SPEC },	\
   { "subtarget_asm_spec", SUBTARGET_ASM_SPEC },				\
+  { "subtarget_link_spec", SUBTARGET_LINK_SPEC },			\
   { "asm_abi_default_spec", "-" MULTILIB_ABI_DEFAULT },			\
   { "endian_spec", ENDIAN_SPEC },					\
   SUBTARGET_EXTRA_SPECS
Index: gcc/gcc/config/mips/netbsd.h
===================================================================
--- gcc.orig/gcc/config/mips/netbsd.h	2015-09-18 00:39:02.226377443 +0100
+++ gcc/gcc/config/mips/netbsd.h	2015-09-18 00:46:30.586637575 +0100
@@ -124,17 +124,20 @@ along with GCC; see the file COPYING3.  
 #undef SUBTARGET_CPP_SPEC
 #define SUBTARGET_CPP_SPEC "%(netbsd_cpp_spec)"
 
-/* Provide a LINK_SPEC appropriate for a NetBSD/mips target.
+/* LINK_SHARED_SPEC is usually set to `%{shared}', however we already
+   include this spec in `%(netbsd_link_spec)', so set this macro to nil.  */
+
+#undef LINK_SHARED_SPEC
+#define LINK_SHARED_SPEC ""
+
+/* Provide a SUBTARGET_LINK_SPEC appropriate for a NetBSD/mips target.
    This is a copy of LINK_SPEC from <netbsd-elf.h> tweaked for
    the MIPS target.  */
 
-#undef LINK_SPEC
-#define LINK_SPEC \
+#undef SUBTARGET_LINK_SPEC
+#define SUBTARGET_LINK_SPEC \
   "%{EL:-m elf32lmip} \
    %{EB:-m elf32bmip} \
-   %(endian_spec) \
-   %{G*} %{mips1} %{mips2} %{mips3} %{mips4} %{mips32} %{mips32r2} \
-   %{mips32r6} %{mips64} %{mips64r6} \
    %(netbsd_link_spec)"
 
 #define NETBSD_ENTRY_POINT "__start"
Index: gcc/gcc/config/mips/sde.h
===================================================================
--- gcc.orig/gcc/config/mips/sde.h	2015-09-18 00:39:02.240515372 +0100
+++ gcc/gcc/config/mips/sde.h	2015-09-18 01:48:26.729890822 +0100
@@ -57,11 +57,8 @@ along with GCC; see the file COPYING3.  
 %{!mips1:--trap} \
 %{mips16:-no-mips16}"
 
-#undef LINK_SPEC
-#define LINK_SPEC "\
-%(endian_spec) \
-%{G*} %{mips1} %{mips2} %{mips3} %{mips4} %{mips32*} %{mips64*} \
-%{shared} \
+#undef SUBTARGET_LINK_SPEC
+#define SUBTARGET_LINK_SPEC "\
 %{mabi=n32:-melf32%{EB:b}%{EL:l}tsmipn32} \
 %{mabi=64:-melf64%{EB:b}%{EL:l}tsmip} \
 %{mabi=32:-melf32%{EB:b}%{EL:l}tsmip}"



More information about the Gcc-patches mailing list