From f0025c1ff517c6e041dfdf3b9d1afbd6bf8a9ff1 Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard@codesourcery.com>
Date: Wed, 4 Jul 2007 13:01:33 +0000
Subject: [PATCH] vxworks.h (SUBTARGET_OVERRIDE_OPTIONS): Reject -mrelax unless
 compiling RTP PIC.

gcc/
	* config/sh/vxworks.h (SUBTARGET_OVERRIDE_OPTIONS): Reject -mrelax
	unless compiling RTP PIC.

gcc/testsuite/
	* gcc.dg/sh-relax.c: Skip for VxWorks if non-PIC.
	* gcc.dg/sh-relax-vxworks.c: New test.

From-SVN: r126317
---
 gcc/ChangeLog                           |  5 +++++
 gcc/config/sh/vxworks.h                 | 15 ++++++++++++++-
 gcc/testsuite/ChangeLog                 |  5 +++++
 gcc/testsuite/gcc.dg/sh-relax-vxworks.c |  5 +++++
 gcc/testsuite/gcc.dg/sh-relax.c         |  2 +-
 5 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/sh-relax-vxworks.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a2949209d049..af67cfb0caa6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2007-07-04  Richard Sandiford  <richard@codesourcery.com>
+
+	* config/sh/vxworks.h (SUBTARGET_OVERRIDE_OPTIONS): Reject -mrelax
+	unless compiling RTP PIC.
+
 2007-07-04  Richard Guenther  <rguenther@suse.de>
 
 	PR tree-optimization/32482
diff --git a/gcc/config/sh/vxworks.h b/gcc/config/sh/vxworks.h
index 63f2bbf6969a..82b32f143c6c 100644
--- a/gcc/config/sh/vxworks.h
+++ b/gcc/config/sh/vxworks.h
@@ -30,7 +30,20 @@ Boston, MA 02110-1301, USA.  */
   while (0)
 
 #undef SUBTARGET_OVERRIDE_OPTIONS
-#define SUBTARGET_OVERRIDE_OPTIONS VXWORKS_OVERRIDE_OPTIONS
+#define SUBTARGET_OVERRIDE_OPTIONS				\
+  do								\
+    {								\
+      VXWORKS_OVERRIDE_OPTIONS;					\
+      /* The kernel loader cannot handle the relaxation		\
+	 relocations, so it cannot load kernel modules		\
+	 (which are ET_REL) or RTP executables (which are	\
+	 linked with --emit-relocs).  No relaxation relocations	\
+	 appear in shared libraries, so relaxation is OK	\
+	 for RTP PIC.  */					\
+      if (TARGET_RELAX && !(TARGET_VXWORKS_RTP && flag_pic))	\
+	error ("-mrelax is only supported for RTP PIC");	\
+    }								\
+  while (0)
 
 #undef SUBTARGET_CPP_SPEC
 #define SUBTARGET_CPP_SPEC VXWORKS_ADDITIONAL_CPP_SPEC
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 261286e57c34..30516ad65c14 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-07-04  Richard Sandiford  <richard@codesourcery.com>
+
+	* gcc.dg/sh-relax.c: Skip for VxWorks if non-PIC.
+	* gcc.dg/sh-relax-vxworks.c: New test.
+
 2007-07-04  Richard Guenther  <rguenther@suse.de>
 
 	PR tree-optimization/32500
diff --git a/gcc/testsuite/gcc.dg/sh-relax-vxworks.c b/gcc/testsuite/gcc.dg/sh-relax-vxworks.c
new file mode 100644
index 000000000000..f8c2ffef431a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sh-relax-vxworks.c
@@ -0,0 +1,5 @@
+/* Check that -mrelax produces the correct error message.  */
+/* { dg-do compile { target { sh-*-vxworks* && nonpic } } } */
+/* { dg-error "-mrelax is only supported for RTP PIC" "" { target *-*-* } 0 } */
+/* { dg-options "-O1 -mrelax" } */
+int x;
diff --git a/gcc/testsuite/gcc.dg/sh-relax.c b/gcc/testsuite/gcc.dg/sh-relax.c
index e204f063e840..54422de46d24 100644
--- a/gcc/testsuite/gcc.dg/sh-relax.c
+++ b/gcc/testsuite/gcc.dg/sh-relax.c
@@ -1,5 +1,5 @@
 /* Check that -mrelax works.  */
-/* { dg-do run { target sh-*-* sh?-*-* } } */
+/* { dg-do run { target { { sh-*-* sh?-*-* } && { ! { sh*-*-vxworks* && nonpic } } } } } */
 /* { dg-options "-O1 -mrelax" } */
 
 extern void abort (void);
-- 
GitLab