$OpenBSD: patch-gcc_config_gcc,v 1.1.1.1 2021/08/03 10:04:14 pascal Exp $

Index: gcc/config.gcc
--- gcc/config.gcc.orig
+++ gcc/config.gcc
@@ -830,6 +830,14 @@ case ${target} in
       default_use_cxa_atexit=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
   ;;
 *-*-phoenix*)
   gas=yes
@@ -980,6 +988,13 @@ aarch64*-*-freebsd*)
 	tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-freebsd.h"
 	tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-freebsd"
 	;;
+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-linux.h"
@@ -1026,7 +1041,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"
@@ -1131,6 +1146,14 @@ arm*-*-netbsdelf*)
 	tmake_file="${tmake_file} arm/t-arm"
 	target_cpu_cname="arm6"
 	;;
+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 GNU/Linux with ELF
 	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"
@@ -1353,6 +1376,7 @@ 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"
@@ -1541,6 +1565,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"
@@ -1548,12 +1573,25 @@ i[34567]86-*-openbsd*)
 	gnu_ld=yes
 	;;
 x86_64-*-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/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
@@ -2394,6 +2432,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 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 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
@@ -2994,10 +3044,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"
@@ -3226,6 +3276,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
