On Fri, Sep 09 2022, Pascal Stumpf <pas...@stumpf.co> wrote: > OK as soon as the lld patch is in. Great work!
This involved a fair amount of headdesks, thanks for your kind words. :) It might be doable to work around the lld problem within the gcc ports. Thay may be sufficient given that not many C++ ports will be built with ports-gcc on riscv64. I'm gonna work on this next. Meanwhile, I fixed the lang/gcc/11 build with what I learnt from lang/gcc/8, diff below. > On Fri, 09 Sep 2022 00:34:21 +0200, Jeremie Courreges-Anglas wrote: >> >> With the diff below I can build ports-gcc on riscv64. PIE is disabled >> by default because I hit crashes at build time. Since not many ports >> require ports-gcc for for C or C++ code I believe that's okay for now. >> Trying to forcefully disable PIE led to some dubious patches, I'm not >> sure yet why they are actually needed (see the comments). The rest of >> the patches are as riscv64-specific as possible. >> >> One patch which isn't included here is for ld.lld in base, which I have >> yet to submit. >> >> With this I can build blas, lapack, numpy with fortran support... more >> to come. >> >> Thoughts? oks? >> >> PS: I have yet to backport my recent fixes to lang/gcc/11, crossing >> fingers... >> >> PPS: the ONLY_FOR_ARCHS and GCC49_ARCHS changes aren't included for now >> but they're trivial (This time with riscv64 added to ONLY_FOR_ARCHS.) Index: 8/Makefile =================================================================== RCS file: /cvs/ports/lang/gcc/8/Makefile,v retrieving revision 1.56 diff -u -p -r1.56 Makefile --- 8/Makefile 24 Jul 2022 09:52:45 -0000 1.56 +++ 8/Makefile 9 Sep 2022 00:14:41 -0000 @@ -1,5 +1,5 @@ ONLY_FOR_ARCHS = aarch64 alpha amd64 arm hppa i386 mips64 mips64el \ - powerpc powerpc64 sparc64 + powerpc powerpc64 riscv64 sparc64 # XXX: sparc64 ONLY_FOR_ARCHS-ada = amd64 hppa i386 mips64 powerpc @@ -64,7 +64,7 @@ EXTRACT_ONLY = ${DISTNAME}.tar.xz BUILD_DEPENDS += devel/bison .if ${MACHINE_ARCH} == "aarch64" || ${MACHINE_ARCH} == "arm" || \ - ${MACHINE_ARCH} == "powerpc64" + ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "riscv64" # would be helpful on i386/amd64 too, but some ports also need the old # ld.bfd in base which can't cope with new gas. BUILD_DEPENDS += devel/gas @@ -133,9 +133,15 @@ CONFIGURE_ARGS += \ --with-gmp="${LOCALBASE}" \ --enable-languages=${LANGS} \ --disable-libstdcxx-pch \ - --enable-default-ssp \ - --enable-default-pie \ --without-isl + +.if ${MACHINE_ARCH} != "riscv64" +CONFIGURE_ARGS += \ + --enable-default-ssp \ + --enable-default-pie +.else +EXTRA_ENV += PORTS_FORCE_DISABLE_PIE="-nopie" +.endif # This is needed, as internal cpp is no longer compatible with the # visible beast Index: 8/patches/patch-fixincludes_Makefile_in =================================================================== RCS file: 8/patches/patch-fixincludes_Makefile_in diff -N 8/patches/patch-fixincludes_Makefile_in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 8/patches/patch-fixincludes_Makefile_in 8 Sep 2022 21:58:03 -0000 @@ -0,0 +1,25 @@ +Add a knob to force-disable PIE to unbreak compilation where PIE isn't +properly supported. + +Index: fixincludes/Makefile.in +--- fixincludes/Makefile.in.orig ++++ fixincludes/Makefile.in +@@ -107,15 +107,15 @@ oneprocess : full-stamp + twoprocess : test-stamp $(AF) + + full-stamp : $(ALLOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $(FI) $(ALLOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PORTS_FORCE_DISABLE_PIE) $(LDFLAGS) -o $(FI) $(ALLOBJ) $(LIBIBERTY) + $(STAMP) $@ + + test-stamp : $(TESTOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $(FI) $(TESTOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PORTS_FORCE_DISABLE_PIE) $(LDFLAGS) -o $(FI) $(TESTOBJ) $(LIBIBERTY) + $(STAMP) $@ + + $(AF): $(FIXOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(FIXOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PORTS_FORCE_DISABLE_PIE) $(LDFLAGS) -o $@ $(FIXOBJ) $(LIBIBERTY) + + $(ALLOBJ) : $(HDR) + fixincl.o : fixincl.c $(srcdir)/fixincl.x Index: 8/patches/patch-gcc_config_gcc =================================================================== RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_gcc,v retrieving revision 1.6 diff -u -p -r1.6 patch-gcc_config_gcc --- 8/patches/patch-gcc_config_gcc 11 Mar 2022 19:28:59 -0000 1.6 +++ 8/patches/patch-gcc_config_gcc 5 Apr 2022 14:38:47 -0000 @@ -96,7 +96,28 @@ Index: gcc/config.gcc 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-*-*) +@@ -2113,6 +2151,20 @@ riscv*-*-freebsd*) + # automatically detect that GAS supports it, yet we require it. + gcc_cv_initfini_array=yes + ;; ++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, can't hurt... ++ cpu_is_64bit=yes ++ gnu_ld=yes ++ gas=yes ++ ;; + mips*-*-netbsd*) # NetBSD/mips, either endian. + target_cpu_default="MASK_ABICALLS" + tm_file="elfos.h ${tm_file} mips/elf.h ${nbsd_tm_file} mips/netbsd.h" +@@ -2394,6 +2446,18 @@ pdp11-*-*) # tmake_file="${tmake_file} rs6000/t-fprules" # extra_headers= # ;; @@ -115,7 +136,7 @@ Index: gcc/config.gcc powerpc-*-darwin*) extra_options="${extra_options} ${cpu_type}/darwin.opt" case ${target} in -@@ -2994,10 +3044,10 @@ sparc64-*-netbsd*) +@@ -2994,10 +3058,10 @@ sparc64-*-netbsd*) tmake_file="${tmake_file} sparc/t-sparc sparc/t-netbsd64" ;; sparc64-*-openbsd*) @@ -127,7 +148,7 @@ Index: gcc/config.gcc gas=yes gnu_ld=yes with_cpu=ultrasparc tmake_file="${tmake_file} sparc/t-sparc" -@@ -3226,6 +3276,12 @@ case ${target} in +@@ -3226,6 +3290,12 @@ case ${target} in else arch=i386 fi Index: 8/patches/patch-gcc_config_riscv_openbsd_h =================================================================== RCS file: 8/patches/patch-gcc_config_riscv_openbsd_h diff -N 8/patches/patch-gcc_config_riscv_openbsd_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 8/patches/patch-gcc_config_riscv_openbsd_h 8 Sep 2022 23:36:00 -0000 @@ -0,0 +1,125 @@ +Index: gcc/config/riscv/openbsd.h +--- gcc/config/riscv/openbsd.h.orig ++++ gcc/config/riscv/openbsd.h +@@ -0,0 +1,121 @@ ++/* Definitions of target machine for GNU compiler, OpenBSD/riscv64 ELF version. ++ Copyright (C) 2002 Free Software Foundation, Inc. ++ ++This file is part of GNU CC. ++ ++GNU CC is free software; you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation; either version 2, or (at your option) ++any later version. ++ ++GNU CC is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GNU CC; see the file COPYING. If not, write to ++the Free Software Foundation, 59 Temple Place - Suite 330, ++Boston, MA 02111-1307, USA. */ ++ ++/* This defaults us to little-endian. */ ++#ifndef TARGET_ENDIAN_DEFAULT ++#define TARGET_ENDIAN_DEFAULT 0 ++#endif ++ ++#undef MULTILIB_DEFAULTS ++/* The default STARTFILE_PREFIX_SPEC for riscv adds some multilib-aware ++ paths that we don't provide, instead of /usr/local/lib which is ++ needed to get at various files shipped by this port (libatomic.so, ++ libgfortran.spec, etc). ++*/ ++#undef STARTFILE_PREFIX_SPEC ++ ++/* ++ * Without linker relaxation in lld(1) we have to use the most generic ++ * code model. XXX check lld 15.0 support for relaxation. ++ */ ++#undef TARGET_DEFAULT_CMODEL ++#define TARGET_DEFAULT_CMODEL CM_MEDANY ++ ++#define TARGET_OS_CPP_BUILTINS() \ ++ do \ ++ { \ ++ builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0"); \ ++ OPENBSD_OS_CPP_BUILTINS_ELF(); \ ++ } \ ++ while (0) ++ ++#undef SUBTARGET_CPP_SPEC ++#define SUBTARGET_CPP_SPEC OBSD_CPP_SPEC ++ ++#define LINK_SPEC \ ++ "%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}} \ ++ %{shared:-shared} %{R*} \ ++ %{static:-Bstatic} \ ++ %{!static:-Bdynamic} \ ++ %{rdynamic:-export-dynamic} \ ++ %{assert*} \ ++ %{!static:-dynamic-linker /usr/libexec/ld.so} \ ++ %{!nostdlib:-L/usr/lib}" ++ ++#define OPENBSD_ENTRY_POINT "__start" ++ ++/* Make GCC agree with <machine/_types.h>. */ ++ ++#undef SIZE_TYPE ++#define SIZE_TYPE "long unsigned int" ++ ++#undef PTRDIFF_TYPE ++#define PTRDIFF_TYPE "long int" ++ ++#undef INTMAX_TYPE ++#define INTMAX_TYPE "long long int" ++ ++#undef UINTMAX_TYPE ++#define UINTMAX_TYPE "long long unsigned int" ++ ++#undef WCHAR_TYPE ++#define WCHAR_TYPE "int" ++ ++#undef WCHAR_TYPE_SIZE ++#define WCHAR_TYPE_SIZE 32 ++ ++/* Provide a STARTFILE_SPEC appropriate for OpenBSD ELF. Here we ++ provide support for the special GCC option -static. On ELF ++ targets, we also add the crtbegin.o file, which provides part ++ of the support for getting C++ file-scope static objects ++ constructed before entering "main". */ ++ ++#define OPENBSD_STARTFILE_SPEC \ ++ "%{!shared: \ ++ %{pg:gcrt0%O%s} \ ++ %{!pg: \ ++ %{p:gcrt0%O%s} \ ++ %{!p:%{!static:crt0%O%s} %{static:%{nopie|no-pie:crt0%O%s} \ ++ %{!nopie:%{!no-pie:rcrt0%O%s}}}}}} \ ++ %:if-exists(crti%O%s) \ ++ %{static:%:if-exists-else(crtbeginT%O%s crtbegin%O%s)} \ ++ %{!static: \ ++ %{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}" ++ ++#undef STARTFILE_SPEC ++#define STARTFILE_SPEC OPENBSD_STARTFILE_SPEC ++ ++/* Provide an ENDFILE_SPEC appropriate for OpenBSD ELF. Here we ++add crtend.o, which provides part of the support for getting ++C++ file-scope static objects deconstructed after exiting "main". */ ++ ++#define OPENBSD_ENDFILE_SPEC \ ++ "%{!shared:crtend%O%s} %{shared:crtendS%O%s} \ ++ %:if-exists(crtn%O%s)" ++ ++#undef ENDFILE_SPEC ++#define ENDFILE_SPEC OPENBSD_ENDFILE_SPEC ++ ++/* Remove -mcpu=native handling which is Linux specific */ ++#undef DRIVER_SELF_SPECS ++#define DRIVER_SELF_SPECS "" ++ ++/* dito */ ++#undef EXTRA_SPEC_FUNCTIONS Index: 8/patches/patch-gcc_configure =================================================================== RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_configure,v retrieving revision 1.5 diff -u -p -r1.5 patch-gcc_configure --- 8/patches/patch-gcc_configure 11 Mar 2022 19:28:59 -0000 1.5 +++ 8/patches/patch-gcc_configure 8 Sep 2022 22:03:48 -0000 @@ -1,3 +1,7 @@ + +Last hunk: use -nopie instead of -no-pie which apparently isn't properly +recognized by egcc (maybe because of our LINK_SPEC?) + Index: gcc/configure --- gcc/configure.orig +++ gcc/configure @@ -55,3 +59,12 @@ Index: gcc/configure *) enable_default_ssp=$enableval ;; esac else +@@ -30156,7 +30162,7 @@ fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5 + $as_echo "$gcc_cv_no_pie" >&6; } + if test "$gcc_cv_no_pie" = "yes"; then +- NO_PIE_FLAG="-no-pie" ++ NO_PIE_FLAG="-nopie" + fi + + Index: 8/patches/patch-libgcc_config_host =================================================================== RCS file: /cvs/ports/lang/gcc/8/patches/patch-libgcc_config_host,v retrieving revision 1.4 diff -u -p -r1.4 patch-libgcc_config_host --- 8/patches/patch-libgcc_config_host 11 Mar 2022 19:28:59 -0000 1.4 +++ 8/patches/patch-libgcc_config_host 9 Sep 2022 01:15:35 -0000 @@ -38,13 +38,23 @@ Index: libgcc/config.host mips*-*-linux*) # Linux MIPS, either endian. extra_parts="$extra_parts crtfastmath.o" tmake_file="${tmake_file} t-crtfm" -@@ -1037,6 +1053,9 @@ powerpc*-*-freebsd*) - ;; +@@ -1038,6 +1054,9 @@ powerpc*-*-freebsd*) powerpc-*-netbsd*) tmake_file="$tmake_file rs6000/t-netbsd rs6000/t-crtstuff" -+ ;; + ;; +powerpc*-*-openbsd*) + tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-crtstuff rs6000/t-openbsd" - ;; ++ ;; powerpc-*-eabispe*) tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-savresfgpr rs6000/t-crtstuff t-crtstuff-pic t-fdpbit" + extra_parts="$extra_parts crtbegin.o crtend.o crtbeginS.o crtendS.o crtbeginT.o ecrti.o ecrtn.o ncrti.o ncrtn.o" +@@ -1131,6 +1150,9 @@ riscv*-*-linux*) + riscv*-*-freebsd*) + tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}" + extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o" ++ ;; ++riscv64-*-openbsd*) ++ tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}" + ;; + riscv*-*-*) + tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}" Index: 11/Makefile =================================================================== RCS file: /cvs/ports/lang/gcc/11/Makefile,v retrieving revision 1.14 diff -u -p -r1.14 Makefile --- 11/Makefile 24 Jul 2022 09:52:45 -0000 1.14 +++ 11/Makefile 9 Sep 2022 00:13:52 -0000 @@ -6,7 +6,7 @@ BROKEN-sparc64 = ICE during selftests # tested: aarch64 amd64 arm hppa i386 powerpc ONLY_FOR_ARCHS = aarch64 alpha amd64 arm hppa i386 mips64 mips64el \ - powerpc powerpc64 sparc64 + powerpc powerpc64 riscv64 sparc64 ONLY_FOR_ARCHS-ada = amd64 i386 mips64 powerpc ONLY_FOR_ARCHS-dlang = aarch64 amd64 arm i386 powerpc powerpc64 @@ -68,7 +68,8 @@ EXTRACT_ONLY = ${DISTNAME}.tar.xz BUILD_DEPENDS += devel/bison .if ${MACHINE_ARCH} == "aarch64" || ${MACHINE_ARCH} == "arm" || \ - ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" + ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || \ + ${MACHINE_ARCH} == "riscv64" # would be helpful on i386/amd64 too, but some ports also need the old # ld.bfd in base which can't cope with new gas. BUILD_DEPENDS += devel/gas @@ -153,9 +154,15 @@ CONFIGURE_ARGS += \ --with-gmp="${LOCALBASE}" \ --enable-languages=${LANGS} \ --disable-libstdcxx-pch \ - --enable-default-ssp \ - --enable-default-pie \ --without-isl + +.if ${MACHINE_ARCH} != "riscv64" +CONFIGURE_ARGS += \ + --enable-default-ssp \ + --enable-default-pie +.else +EXTRA_ENV += PORTS_FORCE_DISABLE_PIE="-nopie" +.endif # This is needed, as internal cpp is no longer compatible with the # visible beast Index: 11/patches/patch-c++tools_Makefile_in =================================================================== RCS file: 11/patches/patch-c++tools_Makefile_in diff -N 11/patches/patch-c++tools_Makefile_in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 11/patches/patch-c++tools_Makefile_in 10 Sep 2022 22:39:56 -0000 @@ -0,0 +1,15 @@ +Add a knob to force-disable PIE to unbreak compilation where PIE isn't +properly supported. + +Index: c++tools/Makefile.in +--- c++tools/Makefile.in.orig ++++ c++tools/Makefile.in +@@ -91,7 +91,7 @@ MAPPER.O := server.o resolver.o + CODYLIB = ../libcody/libcody.a + CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I. + g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB) +- +$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS) ++ +$(CXX) $(LDFLAGS) $(PIEFLAG) $(PORTS_FORCE_DISABLE_PIE) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS) + + # copy to gcc dir so tests there can run + all::../gcc/g++-mapper-server$(exeext) Index: 11/patches/patch-fixincludes_Makefile_in =================================================================== RCS file: 11/patches/patch-fixincludes_Makefile_in diff -N 11/patches/patch-fixincludes_Makefile_in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 11/patches/patch-fixincludes_Makefile_in 9 Sep 2022 06:28:04 -0000 @@ -0,0 +1,25 @@ +Add a knob to force-disable PIE to unbreak compilation where PIE isn't +properly supported. + +Index: fixincludes/Makefile.in +--- fixincludes/Makefile.in.orig ++++ fixincludes/Makefile.in +@@ -107,15 +107,15 @@ oneprocess : full-stamp + twoprocess : test-stamp $(AF) + + full-stamp : $(ALLOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $(FI) $(ALLOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PORTS_FORCE_DISABLE_PIE) $(LDFLAGS) -o $(FI) $(ALLOBJ) $(LIBIBERTY) + $(STAMP) $@ + + test-stamp : $(TESTOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $(FI) $(TESTOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PORTS_FORCE_DISABLE_PIE) $(LDFLAGS) -o $(FI) $(TESTOBJ) $(LIBIBERTY) + $(STAMP) $@ + + $(AF): $(FIXOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(FIXOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PORTS_FORCE_DISABLE_PIE) $(LDFLAGS) -o $@ $(FIXOBJ) $(LIBIBERTY) + + $(ALLOBJ) : $(HDR) + fixincl.o : fixincl.c $(srcdir)/fixincl.x Index: 11/patches/patch-gcc_config_gcc =================================================================== RCS file: /cvs/ports/lang/gcc/11/patches/patch-gcc_config_gcc,v retrieving revision 1.3 diff -u -p -r1.3 patch-gcc_config_gcc --- 11/patches/patch-gcc_config_gcc 11 Mar 2022 19:28:58 -0000 1.3 +++ 11/patches/patch-gcc_config_gcc 9 Sep 2022 01:07:27 -0000 @@ -109,7 +109,27 @@ Index: gcc/config.gcc 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 -@@ -2891,6 +2929,18 @@ pdp11-*-*) +@@ -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= # ;; @@ -128,7 +148,7 @@ Index: gcc/config.gcc powerpc-*-darwin*) extra_options="${extra_options} ${cpu_type}/darwin.opt" case ${target} in -@@ -3452,10 +3502,10 @@ sparc64-*-netbsd*) +@@ -3452,10 +3515,10 @@ sparc64-*-netbsd*) tmake_file="${tmake_file} sparc/t-sparc sparc/t-netbsd64" ;; sparc64-*-openbsd*) @@ -140,7 +160,7 @@ Index: gcc/config.gcc gas=yes gnu_ld=yes with_cpu=ultrasparc tmake_file="${tmake_file} sparc/t-sparc" -@@ -3682,6 +3732,12 @@ case ${target} in +@@ -3682,6 +3745,12 @@ case ${target} in else arch=i386 fi Index: 11/patches/patch-gcc_config_riscv_openbsd_h =================================================================== RCS file: 11/patches/patch-gcc_config_riscv_openbsd_h diff -N 11/patches/patch-gcc_config_riscv_openbsd_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 11/patches/patch-gcc_config_riscv_openbsd_h 8 Sep 2022 23:36:53 -0000 @@ -0,0 +1,125 @@ +Index: gcc/config/riscv/openbsd.h +--- gcc/config/riscv/openbsd.h.orig ++++ gcc/config/riscv/openbsd.h +@@ -0,0 +1,121 @@ ++/* Definitions of target machine for GNU compiler, OpenBSD/riscv64 ELF version. ++ Copyright (C) 2002 Free Software Foundation, Inc. ++ ++This file is part of GNU CC. ++ ++GNU CC is free software; you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation; either version 2, or (at your option) ++any later version. ++ ++GNU CC is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GNU CC; see the file COPYING. If not, write to ++the Free Software Foundation, 59 Temple Place - Suite 330, ++Boston, MA 02111-1307, USA. */ ++ ++/* This defaults us to little-endian. */ ++#ifndef TARGET_ENDIAN_DEFAULT ++#define TARGET_ENDIAN_DEFAULT 0 ++#endif ++ ++#undef MULTILIB_DEFAULTS ++/* The default STARTFILE_PREFIX_SPEC for riscv adds some multilib-aware ++ paths that we don't provide, instead of /usr/local/lib which is ++ needed to get at various files shipped by this port (libatomic.so, ++ libgfortran.spec, etc). ++*/ ++#undef STARTFILE_PREFIX_SPEC ++ ++/* ++ * Without linker relaxation in lld(1) we have to use the most generic ++ * code model. XXX check lld 15.0 support for relaxation. ++ */ ++#undef TARGET_DEFAULT_CMODEL ++#define TARGET_DEFAULT_CMODEL CM_MEDANY ++ ++#define TARGET_OS_CPP_BUILTINS() \ ++ do \ ++ { \ ++ builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0"); \ ++ OPENBSD_OS_CPP_BUILTINS_ELF(); \ ++ } \ ++ while (0) ++ ++#undef SUBTARGET_CPP_SPEC ++#define SUBTARGET_CPP_SPEC OBSD_CPP_SPEC ++ ++#define LINK_SPEC \ ++ "%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}} \ ++ %{shared:-shared} %{R*} \ ++ %{static:-Bstatic} \ ++ %{!static:-Bdynamic} \ ++ %{rdynamic:-export-dynamic} \ ++ %{assert*} \ ++ %{!static:-dynamic-linker /usr/libexec/ld.so} \ ++ %{!nostdlib:-L/usr/lib}" ++ ++#define OPENBSD_ENTRY_POINT "__start" ++ ++/* Make GCC agree with <machine/_types.h>. */ ++ ++#undef SIZE_TYPE ++#define SIZE_TYPE "long unsigned int" ++ ++#undef PTRDIFF_TYPE ++#define PTRDIFF_TYPE "long int" ++ ++#undef INTMAX_TYPE ++#define INTMAX_TYPE "long long int" ++ ++#undef UINTMAX_TYPE ++#define UINTMAX_TYPE "long long unsigned int" ++ ++#undef WCHAR_TYPE ++#define WCHAR_TYPE "int" ++ ++#undef WCHAR_TYPE_SIZE ++#define WCHAR_TYPE_SIZE 32 ++ ++/* Provide a STARTFILE_SPEC appropriate for OpenBSD ELF. Here we ++ provide support for the special GCC option -static. On ELF ++ targets, we also add the crtbegin.o file, which provides part ++ of the support for getting C++ file-scope static objects ++ constructed before entering "main". */ ++ ++#define OPENBSD_STARTFILE_SPEC \ ++ "%{!shared: \ ++ %{pg:gcrt0%O%s} \ ++ %{!pg: \ ++ %{p:gcrt0%O%s} \ ++ %{!p:%{!static:crt0%O%s} %{static:%{nopie|no-pie:crt0%O%s} \ ++ %{!nopie:%{!no-pie:rcrt0%O%s}}}}}} \ ++ %:if-exists(crti%O%s) \ ++ %{static:%:if-exists-else(crtbeginT%O%s crtbegin%O%s)} \ ++ %{!static: \ ++ %{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}" ++ ++#undef STARTFILE_SPEC ++#define STARTFILE_SPEC OPENBSD_STARTFILE_SPEC ++ ++/* Provide an ENDFILE_SPEC appropriate for OpenBSD ELF. Here we ++add crtend.o, which provides part of the support for getting ++C++ file-scope static objects deconstructed after exiting "main". */ ++ ++#define OPENBSD_ENDFILE_SPEC \ ++ "%{!shared:crtend%O%s} %{shared:crtendS%O%s} \ ++ %:if-exists(crtn%O%s)" ++ ++#undef ENDFILE_SPEC ++#define ENDFILE_SPEC OPENBSD_ENDFILE_SPEC ++ ++/* Remove -mcpu=native handling which is Linux specific */ ++#undef DRIVER_SELF_SPECS ++#define DRIVER_SELF_SPECS "" ++ ++/* dito */ ++#undef EXTRA_SPEC_FUNCTIONS Index: 11/patches/patch-gcc_config_riscv_riscv_opt =================================================================== RCS file: 11/patches/patch-gcc_config_riscv_riscv_opt diff -N 11/patches/patch-gcc_config_riscv_riscv_opt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 11/patches/patch-gcc_config_riscv_riscv_opt 9 Sep 2022 01:02:45 -0000 @@ -0,0 +1,15 @@ +lld doesn't support -mrelax. +XXX check lld 15 + +Index: gcc/config/riscv/riscv.opt +--- gcc/config/riscv/riscv.opt.orig ++++ gcc/config/riscv/riscv.opt +@@ -128,7 +128,7 @@ Target Mask(EXPLICIT_RELOCS) + Use %reloc() operators, rather than assembly macros, to load addresses. + + mrelax +-Target Bool Var(riscv_mrelax) Init(1) ++Target Bool Var(riscv_mrelax) Init(0) + Take advantage of linker relaxations to reduce the number of instructions + required to materialize symbol addresses. + Index: 11/patches/patch-gcc_configure =================================================================== RCS file: /cvs/ports/lang/gcc/11/patches/patch-gcc_configure,v retrieving revision 1.2 diff -u -p -r1.2 patch-gcc_configure --- 11/patches/patch-gcc_configure 11 Mar 2022 19:28:58 -0000 1.2 +++ 11/patches/patch-gcc_configure 11 Sep 2022 00:32:25 -0000 @@ -1,3 +1,6 @@ +Last hunk: use -nopie instead of -no-pie which apparently isn't properly +recognized by egcc (maybe because of our LINK_SPEC?) + Index: gcc/configure --- gcc/configure.orig +++ gcc/configure @@ -55,3 +58,12 @@ Index: gcc/configure *) enable_default_ssp=$enableval ;; esac else +@@ -31846,7 +31852,7 @@ fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5 + $as_echo "$gcc_cv_no_pie" >&6; } + if test "$gcc_cv_no_pie" = "yes"; then +- NO_PIE_FLAG="-no-pie" ++ NO_PIE_FLAG="-nopie" + fi + + Index: 11/patches/patch-libgcc_config_host =================================================================== RCS file: /cvs/ports/lang/gcc/11/patches/patch-libgcc_config_host,v retrieving revision 1.2 diff -u -p -r1.2 patch-libgcc_config_host --- 11/patches/patch-libgcc_config_host 11 Mar 2022 19:28:58 -0000 1.2 +++ 11/patches/patch-libgcc_config_host 10 Sep 2022 00:38:17 -0000 @@ -44,13 +44,23 @@ Index: libgcc/config.host mips*-*-linux*) # Linux MIPS, either endian. extra_parts="$extra_parts crtfastmath.o" tmake_file="${tmake_file} t-crtfm" -@@ -1159,6 +1177,9 @@ powerpc*-*-freebsd*) - ;; +@@ -1160,6 +1178,9 @@ powerpc*-*-freebsd*) powerpc-*-netbsd*) tmake_file="$tmake_file rs6000/t-netbsd rs6000/t-crtstuff" -+ ;; + ;; +powerpc*-*-openbsd*) + tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-crtstuff rs6000/t-openbsd" - ;; ++ ;; powerpc-*-eabispe*) tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-savresfgpr rs6000/t-crtstuff t-crtstuff-pic t-fdpbit" + extra_parts="$extra_parts crtbegin.o crtend.o crtbeginS.o crtendS.o crtbeginT.o ecrti.o ecrtn.o ncrti.o ncrtn.o" +@@ -1279,6 +1300,9 @@ riscv*-*-linux*) + riscv*-*-freebsd*) + tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address} t-slibgcc-libgcc" + extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o" ++ ;; ++riscv64-*-openbsd*) ++ tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}" + ;; + riscv*-*-*) + tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}" -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE