diff mbox series

Add NetBSD/hppa target

Message ID 20190614154446.GB20055@SDF.ORG
State New
Headers show
Series Add NetBSD/hppa target | expand

Commit Message

Maya Rashish June 14, 2019, 3:44 p.m. UTC
This adds netbsd/hppa support. I tested it on the shiny new QEMU-git
which can now boot NetBSD too :-)

Files are very similar to the linux code.

Please let me know if any changes need to be made.

Matt Thomas <matt@3am-software.com>
Nick Hudson <nick@nthcliff.demon.co.uk>
Matthew Green <mrg@eterna.com.au>
Maya Rashish <coypu@sdf.org>

gcc/ChangeLog:
	config.gcc (hppa*-*-netbsd*): New target.
	config/pa/pa-netbsd.h: New file.
	config/pa/pa32-netbsd.h: New file.

libgcc/ChangeLog:
	config.host (hppa*-*-netbsd*): New case.
	config/pa/t-netbsd: New file.

---
 gcc/config.gcc              |   8 +++
 gcc/config/pa/pa-netbsd.h   | 137 ++++++++++++++++++++++++++++++++++++
 gcc/config/pa/pa32-netbsd.h |  37 ++++++++++
 libgcc/config.host          |   3 +
 libgcc/config/pa/t-netbsd   |   9 +++
 5 files changed, 194 insertions(+)
 create mode 100644 gcc/config/pa/pa-netbsd.h
 create mode 100644 gcc/config/pa/pa32-netbsd.h
 create mode 100644 libgcc/config/pa/t-netbsd

Comments

Jeff Law June 14, 2019, 4:02 p.m. UTC | #1
On 6/14/19 9:44 AM, coypu@sdf.org wrote:
> This adds netbsd/hppa support. I tested it on the shiny new QEMU-git
> which can now boot NetBSD too :-)
> 
> Files are very similar to the linux code.
> 
> Please let me know if any changes need to be made.
> 
> Matt Thomas <matt@3am-software.com>
> Nick Hudson <nick@nthcliff.demon.co.uk>
> Matthew Green <mrg@eterna.com.au>
> Maya Rashish <coypu@sdf.org>
> 
> gcc/ChangeLog:
> 	config.gcc (hppa*-*-netbsd*): New target.
> 	config/pa/pa-netbsd.h: New file.
> 	config/pa/pa32-netbsd.h: New file.
> 
> libgcc/ChangeLog:
> 	config.host (hppa*-*-netbsd*): New case.
> 	config/pa/t-netbsd: New file.
> 
> ---
>  gcc/config.gcc              |   8 +++
>  gcc/config/pa/pa-netbsd.h   | 137 ++++++++++++++++++++++++++++++++++++
>  gcc/config/pa/pa32-netbsd.h |  37 ++++++++++
>  libgcc/config.host          |   3 +
>  libgcc/config/pa/t-netbsd   |   9 +++
>  5 files changed, 194 insertions(+)
>  create mode 100644 gcc/config/pa/pa-netbsd.h
>  create mode 100644 gcc/config/pa/pa32-netbsd.h
>  create mode 100644 libgcc/config/pa/t-netbsd
> 
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index 76bb316942d..ba93bb41ec8 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -1481,6 +1481,14 @@ hppa*-*-openbsd*)
>  	gas=yes
>  	gnu_ld=yes
>  	;;
> +hppa*-*-netbsd*)
> +	target_cpu_default="MASK_PA_11|MASK_NO_SPACE_REGS"
Any reason to not use the PA 2.0 ISA?   I'm virtually certain we
supported the 32bit ABI running on PA 2.0 hardware in hpbsd (which is
where the netbsd PA code is ultimately derived from).   I'd be really
surprised if there's any PA1.1 hardware running anywhere, though there's
certainly some PA2.0 hardware out in the wild.




> +	tm_file="${tm_file} dbxelf.h elfos.h ${nbsd_tm_file} \
You probably don't need dbxelf.h.  Embedded stabs should be avoided when
it can be.

Jeff
John David Anglin June 14, 2019, 5:32 p.m. UTC | #2
On 2019-06-14 12:02 p.m., Jeff Law wrote:
>> diff --git a/gcc/config.gcc b/gcc/config.gcc
>> index 76bb316942d..ba93bb41ec8 100644
>> --- a/gcc/config.gcc
>> +++ b/gcc/config.gcc
>> @@ -1481,6 +1481,14 @@ hppa*-*-openbsd*)
>>  	gas=yes
>>  	gnu_ld=yes
>>  	;;
>> +hppa*-*-netbsd*)
>> +	target_cpu_default="MASK_PA_11|MASK_NO_SPACE_REGS"
> Any reason to not use the PA 2.0 ISA?   I'm virtually certain we
> supported the 32bit ABI running on PA 2.0 hardware in hpbsd (which is
> where the netbsd PA code is ultimately derived from).   I'd be really
> surprised if there's any PA1.1 hardware running anywhere, though there's
> certainly some PA2.0 hardware out in the wild.
You might also consider adding MASK_CALLER_COPIES as libgomp is broken for callee
copies.  This is an ABI choice so ideally you should do it now or not at all.

Dave
Maya Rashish June 25, 2019, 7:57 a.m. UTC | #3
On Fri, Jun 14, 2019 at 01:32:11PM -0400, John David Anglin wrote:
> >> +hppa*-*-netbsd*)
> >> +	target_cpu_default="MASK_PA_11|MASK_NO_SPACE_REGS"
> > Any reason to not use the PA 2.0 ISA?   I'm virtually certain we
> > supported the 32bit ABI running on PA 2.0 hardware in hpbsd (which is
> > where the netbsd PA code is ultimately derived from).   I'd be really
> > surprised if there's any PA1.1 hardware running anywhere, though there's
> > certainly some PA2.0 hardware out in the wild.
> You might also consider adding MASK_CALLER_COPIES as libgomp is broken for callee
> copies.  This is an ABI choice so ideally you should do it now or not at all.


Hi Jeff, Dave,

I've spoken to the authority of NetBSD/hppa (that's Nick Hudson), and he
said he'd rather keep the ABI as it is for the purpose of upstreaming.
He might switch ABIs eventually, but would rather do it with the local
copy of GCC first.
(And he has several PA1.1 machines :))

Thanks.
Jeff Law June 25, 2019, 2:45 p.m. UTC | #4
On 6/25/19 1:57 AM, coypu@sdf.org wrote:
> On Fri, Jun 14, 2019 at 01:32:11PM -0400, John David Anglin wrote:
>>>> +hppa*-*-netbsd*)
>>>> +	target_cpu_default="MASK_PA_11|MASK_NO_SPACE_REGS"
>>> Any reason to not use the PA 2.0 ISA?   I'm virtually certain we
>>> supported the 32bit ABI running on PA 2.0 hardware in hpbsd (which is
>>> where the netbsd PA code is ultimately derived from).   I'd be really
>>> surprised if there's any PA1.1 hardware running anywhere, though there's
>>> certainly some PA2.0 hardware out in the wild.
>> You might also consider adding MASK_CALLER_COPIES as libgomp is broken for callee
>> copies.  This is an ABI choice so ideally you should do it now or not at all.
> 
> 
> Hi Jeff, Dave,
> 
> I've spoken to the authority of NetBSD/hppa (that's Nick Hudson), and he
> said he'd rather keep the ABI as it is for the purpose of upstreaming.
> He might switch ABIs eventually, but would rather do it with the local
> copy of GCC first.
> (And he has several PA1.1 machines :))
WRT PA1.1 vs PA2.0, as long as it's an informed decision (sounds like it
is), I'm not going to object.

WRT MASK_CALLER_COPIES, I concur with John, it's a now or never choice.
 Flipping it after the fact has far more impacts than libgomp --
essentially it changes who is responsible for copying structures that
are passed by invisible reference -- which happens in far more places
than libgomp.

Jeff
John David Anglin July 31, 2019, 2:15 p.m. UTC | #5
Committed as revision 273933.

Dave

On 2019-06-14 11:44 a.m., coypu@sdf.org wrote:
> This adds netbsd/hppa support. I tested it on the shiny new QEMU-git
> which can now boot NetBSD too :-)
>
> Files are very similar to the linux code.
>
> Please let me know if any changes need to be made.
>
> Matt Thomas <matt@3am-software.com>
> Nick Hudson <nick@nthcliff.demon.co.uk>
> Matthew Green <mrg@eterna.com.au>
> Maya Rashish <coypu@sdf.org>
>
> gcc/ChangeLog:
> 	config.gcc (hppa*-*-netbsd*): New target.
> 	config/pa/pa-netbsd.h: New file.
> 	config/pa/pa32-netbsd.h: New file.
>
> libgcc/ChangeLog:
> 	config.host (hppa*-*-netbsd*): New case.
> 	config/pa/t-netbsd: New file.
>
> ---
>  gcc/config.gcc              |   8 +++
>  gcc/config/pa/pa-netbsd.h   | 137 ++++++++++++++++++++++++++++++++++++
>  gcc/config/pa/pa32-netbsd.h |  37 ++++++++++
>  libgcc/config.host          |   3 +
>  libgcc/config/pa/t-netbsd   |   9 +++
>  5 files changed, 194 insertions(+)
>  create mode 100644 gcc/config/pa/pa-netbsd.h
>  create mode 100644 gcc/config/pa/pa32-netbsd.h
>  create mode 100644 libgcc/config/pa/t-netbsd
>
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index 76bb316942d..ba93bb41ec8 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -1481,6 +1481,14 @@ hppa*-*-openbsd*)
>  	gas=yes
>  	gnu_ld=yes
>  	;;
> +hppa*-*-netbsd*)
> +	target_cpu_default="MASK_PA_11|MASK_NO_SPACE_REGS"
> +	tm_file="${tm_file} dbxelf.h elfos.h ${nbsd_tm_file} \
> +		 pa/pa-netbsd.h pa/pa32-regs.h pa/pa32-netbsd.h"
> +	tmake_file="${tmake_file}"
> +	tm_defines="${tm_defines} CHAR_FAST8=1 SHORT_FAST16=1"
> +	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
> +	;;
>  hppa[12]*-*-hpux10*)
>  	case ${target} in
>  	hppa1.1-*-* | hppa2*-*-*)
> diff --git a/gcc/config/pa/pa-netbsd.h b/gcc/config/pa/pa-netbsd.h
> new file mode 100644
> index 00000000000..88790987561
> --- /dev/null
> +++ b/gcc/config/pa/pa-netbsd.h
> @@ -0,0 +1,137 @@
> +/* Definitions for PA_RISC with ELF format
> +   Copyright (C) 1999-2019 Free Software Foundation, Inc.
> +
> +This file is part of GCC.
> +
> +GCC 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 3, or (at your option)
> +any later version.
> +
> +GCC 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 GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +
> +#undef TARGET_OS_CPP_BUILTINS
> +#define TARGET_OS_CPP_BUILTINS()		\
> +  do						\
> +    {						\
> +	NETBSD_OS_CPP_BUILTINS_ELF();	\
> +	builtin_assert ("machine=bigendian");	\
> +    }						\
> +  while (0)
> +
> +#undef CPP_SPEC
> +#define CPP_SPEC NETBSD_CPP_SPEC
> +
> +#undef ASM_SPEC
> +#define ASM_SPEC \
> +  "%{v:-V} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*}"
> +
> +#undef EXTRA_SPECS
> +#define EXTRA_SPECS NETBSD_SUBTARGET_EXTRA_SPECS
> +#undef SUBTARGET_EXTRA_SPECS
> +
> +#define NETBSD_ENTRY_POINT "__start"
> +
> +#undef LINK_SPEC
> +#define LINK_SPEC NETBSD_LINK_SPEC_ELF
> +
> +/* NetBSD profiling functions don't need gcc to allocate counters.  */
> +#define NO_DEFERRED_PROFILE_COUNTERS 1
> +
> +/* Define the strings used for the special svr4 .type and .size directives.
> +   These strings generally do not vary from one system running svr4 to
> +   another, but if a given system (e.g. m88k running svr) needs to use
> +   different pseudo-op names for these, they may be overridden in the
> +   file which includes this one.  */
> +
> +#undef STRING_ASM_OP
> +#define STRING_ASM_OP   "\t.stringz\t"
> +
> +#define TEXT_SECTION_ASM_OP "\t.text"
> +#define DATA_SECTION_ASM_OP "\t.data"
> +#define BSS_SECTION_ASM_OP "\t.section\t.bss"
> +
> +#define TARGET_ASM_FILE_START pa_linux_file_start
> +
> +/* We want local labels to start with period if made with asm_fprintf.  */
> +#undef LOCAL_LABEL_PREFIX
> +#define LOCAL_LABEL_PREFIX "."
> +
> +/* Define these to generate the Linux/ELF/SysV style of internal
> +   labels all the time - i.e. to be compatible with
> +   ASM_GENERATE_INTERNAL_LABEL in <elfos.h>.  Compare these with the
> +   ones in pa.h and note the lack of dollar signs in these.  FIXME:
> +   shouldn't we fix pa.h to use ASM_GENERATE_INTERNAL_LABEL instead? */
> +
> +#undef ASM_OUTPUT_ADDR_VEC_ELT
> +#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
> +  fprintf (FILE, "\t.word .L%d\n", VALUE)
> +
> +#undef ASM_OUTPUT_ADDR_DIFF_ELT
> +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
> +  fprintf (FILE, "\t.word .L%d-.L%d\n", VALUE, REL)
> +
> +/* Use the default.  */
> +#undef ASM_OUTPUT_LABEL
> +
> +/* NOTE: (*targetm.asm_out.internal_label)() is defined for us by elfos.h, and
> +   does what we want (i.e. uses colons).  It must be compatible with
> +   ASM_GENERATE_INTERNAL_LABEL(), so do not define it here.  */
> +
> +/* Use the default.  */
> +#undef ASM_OUTPUT_INTERNAL_LABEL
> +
> +/* Use the default.  */
> +#undef TARGET_ASM_GLOBALIZE_LABEL
> +/* Globalizing directive for a label.  */
> +#define GLOBAL_ASM_OP ".globl "
> +
> +/* FIXME: Hacked from the <elfos.h> one so that we avoid multiple
> +   labels in a function declaration (since pa.c seems determined to do
> +   it differently)  */
> +
> +#undef ASM_DECLARE_FUNCTION_NAME
> +#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)		\
> +  do								\
> +    {								\
> +      ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");	\
> +      ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));		\
> +    }								\
> +  while (0)
> +
> +/* As well as globalizing the label, we need to encode the label
> +   to ensure a plabel is generated in an indirect call.  */
> +
> +#undef ASM_OUTPUT_EXTERNAL_LIBCALL
> +#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN)  		\
> +  do								\
> +    {								\
> +      if (!FUNCTION_NAME_P (XSTR (FUN, 0)))			\
> +	pa_encode_label (FUN);					\
> +      (*targetm.asm_out.globalize_label) (FILE, XSTR (FUN, 0));	\
> +    }								\
> +  while (0)
> +
> +/* NetBSD always uses gas.  */
> +#undef TARGET_GAS
> +#define TARGET_GAS 1
> +
> +/* Use long int for these type to make hppa64 compatibility easier.  */
> +#undef SIZE_TYPE
> +#define SIZE_TYPE "long unsigned int"
> +
> +#undef PTRDIFF_TYPE
> +#define PTRDIFF_TYPE "long int"
> +
> +#if 0
> +#undef TARGET_SYNC_LIBCALL
> +#define TARGET_SYNC_LIBCALL 1
> +#endif
> diff --git a/gcc/config/pa/pa32-netbsd.h b/gcc/config/pa/pa32-netbsd.h
> new file mode 100644
> index 00000000000..29837ce6f12
> --- /dev/null
> +++ b/gcc/config/pa/pa32-netbsd.h
> @@ -0,0 +1,37 @@
> +/* Definitions for PA_RISC with ELF-32 format
> +   Copyright (C) 2000-2019 Free Software Foundation, Inc.
> +
> +This file is part of GCC.
> +
> +GCC 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.
> +
> +GCC 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 GCC; see the file COPYING.  If not, write to
> +the Free Software Foundation, 59 Temple Place - Suite 330,
> +Boston, MA 02111-1307, USA.  */
> +
> +/* Turn off various SOM crap we don't want.  */
> +#undef TARGET_ELF32
> +#define TARGET_ELF32 1
> +
> +/* The libcall __canonicalize_funcptr_for_compare is referenced in
> +   crtend.o and the reference isn't resolved in objects that don't
> +   compare function pointers.  Thus, we need to play games to provide
> +   a reference in crtbegin.o.  The rest of the define is the same
> +   as that in crtstuff.c  */
> +#define CTOR_LIST_BEGIN \
> +  asm (".type __canonicalize_funcptr_for_compare,@function\n"		\
> +"	.text\n"							\
> +"	.word __canonicalize_funcptr_for_compare-$PIC_pcrel$0");	\
> +  STATIC func_ptr __CTOR_LIST__[1]					\
> +    __attribute__ ((__used__, section(".ctors"),			\
> +		    aligned(sizeof(func_ptr))))				\
> +    = { (func_ptr) (-1) }
> diff --git a/libgcc/config.host b/libgcc/config.host
> index 91fed5fa473..602fc97a321 100644
> --- a/libgcc/config.host
> +++ b/libgcc/config.host
> @@ -616,6 +616,9 @@ hppa[12]*-*-hpux11*)
>  hppa*-*-openbsd*)
>  	tmake_file="$tmake_file pa/t-openbsd"
>  	;;
> +hppa*-*-netbsd*)
> +	tmake_file="$tmake_file pa/t-netbsd"
> +	;;
>  i[34567]86-*-darwin*)
>  	tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi"
>  	tm_file="$tm_file i386/darwin-lib.h"
> diff --git a/libgcc/config/pa/t-netbsd b/libgcc/config/pa/t-netbsd
> new file mode 100644
> index 00000000000..8b99068ce42
> --- /dev/null
> +++ b/libgcc/config/pa/t-netbsd
> @@ -0,0 +1,9 @@
> +#Plug millicode routines into libgcc.a  We want these on both native and
> +#cross compiles.  We use the "64-bit" routines because the "32-bit" code
> +#is broken for certain corner cases.
> +LIB1ASMSRC = pa/milli64.S
> +LIB1ASMFUNCS = _divI _divU _remI _remU _div_const _mulI _dyncall
> +
> +HOST_LIBGCC2_CFLAGS += -DELF=1 -DLINUX=1
> +
> +LIB2ADD = $(srcdir)/config/pa/fptr.c
diff mbox series

Patch

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 76bb316942d..ba93bb41ec8 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1481,6 +1481,14 @@  hppa*-*-openbsd*)
 	gas=yes
 	gnu_ld=yes
 	;;
+hppa*-*-netbsd*)
+	target_cpu_default="MASK_PA_11|MASK_NO_SPACE_REGS"
+	tm_file="${tm_file} dbxelf.h elfos.h ${nbsd_tm_file} \
+		 pa/pa-netbsd.h pa/pa32-regs.h pa/pa32-netbsd.h"
+	tmake_file="${tmake_file}"
+	tm_defines="${tm_defines} CHAR_FAST8=1 SHORT_FAST16=1"
+	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+	;;
 hppa[12]*-*-hpux10*)
 	case ${target} in
 	hppa1.1-*-* | hppa2*-*-*)
diff --git a/gcc/config/pa/pa-netbsd.h b/gcc/config/pa/pa-netbsd.h
new file mode 100644
index 00000000000..88790987561
--- /dev/null
+++ b/gcc/config/pa/pa-netbsd.h
@@ -0,0 +1,137 @@ 
+/* Definitions for PA_RISC with ELF format
+   Copyright (C) 1999-2019 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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 3, or (at your option)
+any later version.
+
+GCC 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 GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS()		\
+  do						\
+    {						\
+	NETBSD_OS_CPP_BUILTINS_ELF();	\
+	builtin_assert ("machine=bigendian");	\
+    }						\
+  while (0)
+
+#undef CPP_SPEC
+#define CPP_SPEC NETBSD_CPP_SPEC
+
+#undef ASM_SPEC
+#define ASM_SPEC \
+  "%{v:-V} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*}"
+
+#undef EXTRA_SPECS
+#define EXTRA_SPECS NETBSD_SUBTARGET_EXTRA_SPECS
+#undef SUBTARGET_EXTRA_SPECS
+
+#define NETBSD_ENTRY_POINT "__start"
+
+#undef LINK_SPEC
+#define LINK_SPEC NETBSD_LINK_SPEC_ELF
+
+/* NetBSD profiling functions don't need gcc to allocate counters.  */
+#define NO_DEFERRED_PROFILE_COUNTERS 1
+
+/* Define the strings used for the special svr4 .type and .size directives.
+   These strings generally do not vary from one system running svr4 to
+   another, but if a given system (e.g. m88k running svr) needs to use
+   different pseudo-op names for these, they may be overridden in the
+   file which includes this one.  */
+
+#undef STRING_ASM_OP
+#define STRING_ASM_OP   "\t.stringz\t"
+
+#define TEXT_SECTION_ASM_OP "\t.text"
+#define DATA_SECTION_ASM_OP "\t.data"
+#define BSS_SECTION_ASM_OP "\t.section\t.bss"
+
+#define TARGET_ASM_FILE_START pa_linux_file_start
+
+/* We want local labels to start with period if made with asm_fprintf.  */
+#undef LOCAL_LABEL_PREFIX
+#define LOCAL_LABEL_PREFIX "."
+
+/* Define these to generate the Linux/ELF/SysV style of internal
+   labels all the time - i.e. to be compatible with
+   ASM_GENERATE_INTERNAL_LABEL in <elfos.h>.  Compare these with the
+   ones in pa.h and note the lack of dollar signs in these.  FIXME:
+   shouldn't we fix pa.h to use ASM_GENERATE_INTERNAL_LABEL instead? */
+
+#undef ASM_OUTPUT_ADDR_VEC_ELT
+#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
+  fprintf (FILE, "\t.word .L%d\n", VALUE)
+
+#undef ASM_OUTPUT_ADDR_DIFF_ELT
+#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
+  fprintf (FILE, "\t.word .L%d-.L%d\n", VALUE, REL)
+
+/* Use the default.  */
+#undef ASM_OUTPUT_LABEL
+
+/* NOTE: (*targetm.asm_out.internal_label)() is defined for us by elfos.h, and
+   does what we want (i.e. uses colons).  It must be compatible with
+   ASM_GENERATE_INTERNAL_LABEL(), so do not define it here.  */
+
+/* Use the default.  */
+#undef ASM_OUTPUT_INTERNAL_LABEL
+
+/* Use the default.  */
+#undef TARGET_ASM_GLOBALIZE_LABEL
+/* Globalizing directive for a label.  */
+#define GLOBAL_ASM_OP ".globl "
+
+/* FIXME: Hacked from the <elfos.h> one so that we avoid multiple
+   labels in a function declaration (since pa.c seems determined to do
+   it differently)  */
+
+#undef ASM_DECLARE_FUNCTION_NAME
+#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)		\
+  do								\
+    {								\
+      ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");	\
+      ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));		\
+    }								\
+  while (0)
+
+/* As well as globalizing the label, we need to encode the label
+   to ensure a plabel is generated in an indirect call.  */
+
+#undef ASM_OUTPUT_EXTERNAL_LIBCALL
+#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN)  		\
+  do								\
+    {								\
+      if (!FUNCTION_NAME_P (XSTR (FUN, 0)))			\
+	pa_encode_label (FUN);					\
+      (*targetm.asm_out.globalize_label) (FILE, XSTR (FUN, 0));	\
+    }								\
+  while (0)
+
+/* NetBSD always uses gas.  */
+#undef TARGET_GAS
+#define TARGET_GAS 1
+
+/* Use long int for these type to make hppa64 compatibility easier.  */
+#undef SIZE_TYPE
+#define SIZE_TYPE "long unsigned int"
+
+#undef PTRDIFF_TYPE
+#define PTRDIFF_TYPE "long int"
+
+#if 0
+#undef TARGET_SYNC_LIBCALL
+#define TARGET_SYNC_LIBCALL 1
+#endif
diff --git a/gcc/config/pa/pa32-netbsd.h b/gcc/config/pa/pa32-netbsd.h
new file mode 100644
index 00000000000..29837ce6f12
--- /dev/null
+++ b/gcc/config/pa/pa32-netbsd.h
@@ -0,0 +1,37 @@ 
+/* Definitions for PA_RISC with ELF-32 format
+   Copyright (C) 2000-2019 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC 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 GCC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* Turn off various SOM crap we don't want.  */
+#undef TARGET_ELF32
+#define TARGET_ELF32 1
+
+/* The libcall __canonicalize_funcptr_for_compare is referenced in
+   crtend.o and the reference isn't resolved in objects that don't
+   compare function pointers.  Thus, we need to play games to provide
+   a reference in crtbegin.o.  The rest of the define is the same
+   as that in crtstuff.c  */
+#define CTOR_LIST_BEGIN \
+  asm (".type __canonicalize_funcptr_for_compare,@function\n"		\
+"	.text\n"							\
+"	.word __canonicalize_funcptr_for_compare-$PIC_pcrel$0");	\
+  STATIC func_ptr __CTOR_LIST__[1]					\
+    __attribute__ ((__used__, section(".ctors"),			\
+		    aligned(sizeof(func_ptr))))				\
+    = { (func_ptr) (-1) }
diff --git a/libgcc/config.host b/libgcc/config.host
index 91fed5fa473..602fc97a321 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -616,6 +616,9 @@  hppa[12]*-*-hpux11*)
 hppa*-*-openbsd*)
 	tmake_file="$tmake_file pa/t-openbsd"
 	;;
+hppa*-*-netbsd*)
+	tmake_file="$tmake_file pa/t-netbsd"
+	;;
 i[34567]86-*-darwin*)
 	tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi"
 	tm_file="$tm_file i386/darwin-lib.h"
diff --git a/libgcc/config/pa/t-netbsd b/libgcc/config/pa/t-netbsd
new file mode 100644
index 00000000000..8b99068ce42
--- /dev/null
+++ b/libgcc/config/pa/t-netbsd
@@ -0,0 +1,9 @@ 
+#Plug millicode routines into libgcc.a  We want these on both native and
+#cross compiles.  We use the "64-bit" routines because the "32-bit" code
+#is broken for certain corner cases.
+LIB1ASMSRC = pa/milli64.S
+LIB1ASMFUNCS = _divI _divU _remI _remU _div_const _mulI _dyncall
+
+HOST_LIBGCC2_CFLAGS += -DELF=1 -DLINUX=1
+
+LIB2ADD = $(srcdir)/config/pa/fptr.c