@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
+ * Copyright (C) 2005, 2007, 2009, 2011 Free Software Foundation, Inc.
*
* This file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -30,6 +30,26 @@
#include "cpuid.h"
#endif
+#if !defined __x86_64 && defined __sun__ && defined __svr4__
+#include <signal.h>
+#include <ucontext.h>
+
+static volatile sig_atomic_t sigill_caught;
+
+static void
+sigill_hdlr (int sig __attribute((unused)),
+ siginfo_t *sip __attribute__((unused)),
+ ucontext_t *ucp)
+{
+ sigill_caught = 1;
+ /* Set PC to the instruction after the faulting one to skip over it,
+ otherwise we enter an infinite loop. 4 is the size of the stmxcsr
+ instruction. */
+ ucp->uc_mcontext.gregs[EIP] += 4;
+ setcontext (ucp);
+}
+#endif
+
static void __attribute__((constructor))
#ifndef __x86_64__
/* The i386 ABI only requires 4-byte stack alignment, so this is necessary
@@ -45,6 +65,32 @@ set_fast_math (void)
if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
return;
+#if defined __sun__ && defined __svr4__
+ /* Solaris 2 before Solaris 9 4/04 cannot execute SSE instructions even
+ if the CPU supports them. Programs receive SIGILL instead, so check
+ for that at runtime. */
+
+ if (edx & bit_SSE)
+ {
+ struct sigaction act, oact;
+
+ act.sa_handler = sigill_hdlr;
+ sigemptyset (&act.sa_mask);
+ /* Need to set SA_SIGINFO so a ucontext_t * is passed to the handler. */
+ act.sa_flags = SA_SIGINFO;
+ sigaction (SIGILL, &act, &oact);
+
+ /* We need a single SSE instruction here so the handler can safely skip
+ over it. */
+ __asm__ volatile ("movss %xmm2,%xmm1");
+
+ sigaction (SIGILL, &oact, NULL);
+
+ if (sigill_caught)
+ return;
+ }
+#endif /* __sun__ && __svr4__ */
+
if (edx & bit_SSE)
{
unsigned int mxcsr = __builtin_ia32_stmxcsr ();
@@ -141,7 +141,9 @@ along with GCC; see the file COPYING3.
%{p|pg:-ldl} -lc}"
#undef ENDFILE_SPEC
-#define ENDFILE_SPEC "crtend.o%s crtn.o%s"
+#define ENDFILE_SPEC \
+ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
+ crtend.o%s crtn.o%s"
/* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us. */
#undef STARTFILE_SPEC
@@ -117,11 +117,6 @@ along with GCC; see the file COPYING3.
#define NO_DBX_BNSYM_ENSYM 1
-#undef ENDFILE_SPEC
-#define ENDFILE_SPEC \
- "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
- crtend.o%s crtn.o%s"
-
/* Select a format to encode pointers in exception handling data. CODE
is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is
true if the symbol may be affected by dynamic relocations.
@@ -338,6 +338,8 @@ i[34567]86-*-rtems*)
tmake_file="${tmake_file} t-crtin i386/t-softfp i386/t-crtstuff t-rtems"
;;
i[34567]86-*-solaris2*)
+ tmake_file="$tmake_file i386/t-crtfm"
+ extra_parts="$extra_parts crtfastmath.o"
;;
i[4567]86-wrs-vxworks|i[4567]86-wrs-vxworksae)
;;