Index: gcc/config/sparc/openbsd64.h
--- gcc/config/sparc/openbsd64.h.orig
+++ gcc/config/sparc/openbsd64.h
@@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 /* XXX - do we really want HARD_QUAD? */
 #undef TARGET_DEFAULT
 #define TARGET_DEFAULT \
-(MASK_V9 + MASK_PTR64 + MASK_64BIT + MASK_HARD_QUAD \
+(MASK_V9 + MASK_PTR64 + MASK_64BIT + /* MASK_HARD_QUAD */ \
  + MASK_APP_REGS + MASK_FPU + MASK_STACK_BIAS + MASK_LONG_DOUBLE_128)
 
 #undef SPARC_DEFAULT_CMODEL
@@ -30,10 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #define TARGET_OS_CPP_BUILTINS()		\
   do						\
     {						\
-	builtin_define ("__unix__");		\
-	builtin_define ("__OpenBSD__");		\
-	builtin_assert ("system=unix");		\
-	builtin_assert ("system=OpenBSD");	\
+	OPENBSD_OS_CPP_BUILTINS();		\
 	builtin_define ("__sparc64__");		\
 	builtin_define ("__sparcv9__");		\
 	builtin_define ("__sparc_v9__");	\
@@ -42,10 +39,17 @@ along with GCC; see the file COPYING3.  If not see
   while (0)
 
 #undef ASM_SPEC
+#ifdef PIE_DEFAULT
 #define ASM_SPEC "\
+-s %{fpic|fPIC:-K PIC} %{!fno-pie: %{!p: %{!pg: -K PIC}}} \
+%(asm_cpu) %(asm_arch) \
+"
+#else
+#define ASM_SPEC "\
 -s %{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %(asm_cpu) %(asm_arch) \
 "
+#endif
 
 /* Layout of source language data types.  */
 #undef WCHAR_TYPE
@@ -54,6 +58,15 @@ along with GCC; see the file COPYING3.  If not see
 #undef WCHAR_TYPE_SIZE
 #define WCHAR_TYPE_SIZE 32
 
+#undef WINT_TYPE
+#define WINT_TYPE "int"
+
+#undef INTMAX_TYPE
+#define INTMAX_TYPE "long long int"
+
+#undef UINTMAX_TYPE
+#define UINTMAX_TYPE "long long unsigned int"
+
 #undef SPARC_LONG_DOUBLE_TYPE_SIZE
 #define SPARC_LONG_DOUBLE_TYPE_SIZE 128
 
@@ -63,13 +76,15 @@ along with GCC; see the file COPYING3.  If not see
    %{shared:-shared} %{R*} \
    %{static:-Bstatic} \
    %{!static:-Bdynamic} \
+   %{rdynamic:-export-dynamic} \
    %{assert*} \
-   -dynamic-linker /usr/libexec/ld.so"
+   %{!static:-dynamic-linker /usr/libexec/ld.so}"
 
 /* As an elf system, we need crtbegin/crtend stuff.  */
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC "\
-        %{!shared: %{pg:gcrt0%O%s} %{!pg:%{p:gcrt0%O%s} %{!p:crt0%O%s}} \
-        crtbegin%O%s} %{shared:crtbeginS%O%s}"
+	%{!shared: %{pg:gcrt0%O%s} %{!pg:%{p:gcrt0%O%s} \
+	%{!p:%{!static:crt0%O%s} %{static:%{nopie:crt0%O%s} \
+	%{!nopie:rcrt0%O%s}}}} crtbegin%O%s} %{shared:crtbeginS%O%s}"
 #undef ENDFILE_SPEC
 #define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}"
