Index: gcc/config.gcc
--- gcc/config.gcc.orig
+++ gcc/config.gcc
@@ -904,6 +904,14 @@ case ${target} in
       default_gnu_indirect_function=yes
       ;;
   esac
+  case ${target} in
+    *-*-openbsd[0-3].*|*-*-openbsd4.[012])
+      # keep default of no cxa_atexit support for these older releases
+      ;;
+    *)
+      default_use_cxa_atexit=yes
+      ;;
+  esac
   ;;
 *-*-openbsd*)
   tmake_file="t-openbsd"
@@ -1133,6 +1141,13 @@ aarch64*-*-netbsd*)
 	tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-netbsd"
 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
 	;;
+aarch64-*-openbsd*)
+	tm_file="${tm_file} dbxelf.h elfos.h"
+	tm_file="${tm_file} aarch64/aarch64-elf.h openbsd-stdint.h"
+	tm_file="${tm_file} openbsd.h aarch64/openbsd.h openbsd-libpthread.h"
+	tmake_file="${tmake_file} aarch64/t-aarch64"
+	extra_options="${extra_options} openbsd.opt"
+	;;
 aarch64*-*-linux*)
 	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h"
 	tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-linux.h"
@@ -1179,7 +1194,7 @@ alpha*-*-netbsd*)
 		       alpha/elf.opt"
 	;;
 alpha*-*-openbsd*)
-	tm_defines="${tm_defines} OBSD_HAS_DECLARE_FUNCTION_NAME OBSD_HAS_DECLARE_FUNCTION_SIZE OBSD_HAS_DECLARE_OBJECT"
+	tm_defines="${tm_defines} OBSD_HAS_DECLARE_FUNCTION_NAME OBSD_HAS_DECLARE_FUNCTION_SIZE OBSD_HAS_DECLARE_OBJECT DEFAULT_FLAG_PIE=2"
 	tm_file="elfos.h alpha/alpha.h alpha/elf.h openbsd.h openbsd-stdint.h alpha/openbsd.h openbsd-libpthread.h"
 	tmake_file="${tmake_file} alpha/t-alpha"
 	extra_options="${extra_options} openbsd.opt alpha/elf.opt"
@@ -1303,10 +1318,18 @@ arm*-*-netbsdelf*)
 	armv7*) target_cpu_cname="generic-armv7-a";;
 	esac
 	;;
-arm*-*-linux-* | arm*-*-uclinuxfdpiceabi)
-	tm_file="dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h arm/elf.h arm/linux-gas.h arm/linux-elf.h"
-	extra_options="${extra_options} linux-android.opt"
-	case $target in
+arm-*-openbsd*)
+	tm_defines="${tm_defines} DEFAULT_FLAG_PIE=1"
+	tm_file="dbxelf.h elfos.h arm/elf.h arm/aout.h arm/openbsd1.h arm/arm.h openbsd.h openbsd-stdint.h openbsd-libpthread.h arm/openbsd.h"
+	extra_options="${extra_options} openbsd.opt"
+	tmake_file="${tmake_file} arm/t-arm arm/t-bpabi"
+	target_cpu_cname="generic-armv7-a"
+	set
+	;;
+arm*-*-linux-*	| arm*-*-uclinuxfdpiceabi)
+	tm_file="dbxelf.h	elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h arm/elf.h arm/linux-gas.h arm/linux-elf.h"
+	extra_options="${extra_options}	linux-android.opt"
+	case	$target in
 	arm*b-*-linux*)
 	    tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
 	    ;;
@@ -1731,10 +1754,11 @@ hppa*-*-linux*)
 	;;
 hppa*-*-openbsd*)
 	target_cpu_default="MASK_PA_11"
+	tm_defines="${tm_defines} DEFAULT_FLAG_PIE=1"
 	tm_file="${tm_file} dbxelf.h elfos.h openbsd.h openbsd-stdint.h openbsd-libpthread.h \
 		 pa/pa-openbsd.h pa/pa32-regs.h pa/pa32-openbsd.h"
 	extra_options="${extra_options} openbsd.opt"
-	tmake_file="pa/t-pa"
+	tmake_file="${tmake_file} pa/t-pa"
 	d_target_objs="${d_target_objs} pa-d.o"
 	gas=yes
 	gnu_ld=yes
@@ -1932,6 +1956,7 @@ x86_64-*-netbsd*)
 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
 	;;
 i[34567]86-*-openbsd*)
+	tm_defines="${tm_defines} DEFAULT_FLAG_PIE=1"
 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h"
 	tm_file="${tm_file} openbsd.h openbsd-stdint.h openbsd-libpthread.h i386/openbsdelf.h"
 	extra_options="${extra_options} openbsd.opt"
@@ -1939,12 +1964,25 @@ i[34567]86-*-openbsd*)
 	gnu_ld=yes
 	;;
 x86_64-*-openbsd*)
+	tm_defines="${tm_defines} DEFAULT_FLAG_PIE=1 CF_DEFAULT=CF_BRANCH"
 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h"
 	tm_file="${tm_file} openbsd.h openbsd-stdint.h openbsd-libpthread.h i386/x86-64.h i386/openbsdelf.h"
 	extra_options="${extra_options} openbsd.opt"
 	gas=yes
 	gnu_ld=yes
 	;;
+mips64-*-openbsd*)
+	set
+	tm_file="dbxelf.h elfos.h openbsd.h openbsd-stdint.h mips/mips.h mips/openbsd.h openbsd-libpthread.h"
+	tm_defines="MIPS_ISA_DEFAULT=3 MIPS_ABI_DEFAULT=ABI_64 DEFAULT_FLAG_PIE=1"
+	extra_options="${extra_options} openbsd.opt"
+	;;
+mips64el-*-openbsd*)
+	set
+	tm_file="dbxelf.h elfos.h openbsd.h openbsd-stdint.h mips/mips.h mips/openbsd.h openbsd-libpthread.h"
+	tm_defines="MIPS_ISA_DEFAULT=3 MIPS_ABI_DEFAULT=ABI_64 TARGET_ENDIAN_DEFAULT=0 DEFAULT_FLAG_PIE=1"
+	extra_options="${extra_options} openbsd.opt"
+	;;
 i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
 			# Intel 80386's running GNU/*
 			# with ELF format using glibc 2
@@ -2532,6 +2570,19 @@ mips*-*-netbsd*)			# NetBSD/mips, either endian.
 	tm_file="elfos.h ${tm_file} mips/elf.h ${nbsd_tm_file} mips/netbsd.h"
 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
 	;;
+riscv64-*-openbsd*)
+	tm_file="${tm_file} dbxelf.h elfos.h"
+	tm_file="${tm_file} openbsd-stdint.h"
+	tm_file="${tm_file} openbsd.h riscv/openbsd.h openbsd-libpthread.h"
+	tmake_file="${tmake_file} riscv/t-riscv"
+	extra_options="${extra_options} openbsd.opt"
+	# Force .init_array support.  The configure script cannot always
+	# automatically detect that GAS supports it, yet we require it.
+	gcc_cv_initfini_array=yes
+	# Also force this, shouldn't hurt...
+	gnu_ld=yes
+	gas=yes
+	;;
 mips*-img-linux*)
 	tm_file="dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/linux.h mips/linux-common.h mips/mti-linux.h"
 	extra_options="${extra_options} linux-android.opt"
@@ -2891,6 +2942,18 @@ pdp11-*-*)
 #	tmake_file="${tmake_file} rs6000/t-fprules"
 #	extra_headers=
 #	;;
+powerpc-*-openbsd*)
+	tm_defines="${tm_defines} DEFAULT_FLAG_PIE=2"
+	tm_file="rs6000/secureplt.h ${tm_file} dbxelf.h elfos.h gnu-user.h openbsd.h openbsd-stdint.h openbsd-libpthread.h freebsd-spec.h rs6000/sysv4.h rs6000/openbsd.h"
+	tmake_file="${tmake_file} rs6000/t-openbsd"
+	extra_options="${extra_options} rs6000/sysv4.opt openbsd.opt"
+	;;
+powerpc64*-*-openbsd*)
+	tm_defines="${tm_defines} DEFAULT_FLAG_PIE=2"
+	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h openbsd.h openbsd-stdint.h openbsd-libpthread.h freebsd-spec.h rs6000/sysv4.h rs6000/default64.h rs6000/openbsd64.h"
+	tmake_file="${tmake_file} rs6000/t-openbsd64"
+	extra_options="${extra_options} rs6000/sysv4.opt rs6000/linux64.opt openbsd.opt"
+	;;
 powerpc-*-darwin*)
 	extra_options="${extra_options} ${cpu_type}/darwin.opt"
 	case ${target} in
@@ -3452,10 +3515,10 @@ sparc64-*-netbsd*)
 	tmake_file="${tmake_file} sparc/t-sparc sparc/t-netbsd64"
 	;;
 sparc64-*-openbsd*)
+	tm_defines="${tm_defines} DEFAULT_FLAG_PIE=2"
 	tm_file="sparc/openbsd1-64.h ${tm_file} dbxelf.h elfos.h sparc/sysv4.h sparc/sp64-elf.h"
 	tm_file="${tm_file} openbsd.h openbsd-stdint.h openbsd-libpthread.h sparc/openbsd64.h"
 	extra_options="${extra_options} openbsd.opt"
-	extra_options="${extra_options}"
 	gas=yes gnu_ld=yes
 	with_cpu=ultrasparc
 	tmake_file="${tmake_file} sparc/t-sparc"
@@ -3682,6 +3745,12 @@ case ${target} in
     else
       arch=i386
     fi
+    cpu=generic
+    arch_without_sse2=yes
+    arch_without_64bit=yes
+    ;;
+  i386-*-openbsd*)
+    arch=pentium
     cpu=generic
     arch_without_sse2=yes
     arch_without_64bit=yes
