[NetBSD] Add support for the Arm EABI.
authorMatt Thomas <matt@3am-software.com>
Fri, 14 Jun 2019 14:04:20 +0000 (14:04 +0000)
committerRichard Earnshaw <rearnsha@gcc.gnu.org>
Fri, 14 Jun 2019 14:04:20 +0000 (14:04 +0000)
This is a roll-up of a set of changes needed to support the Arm EABI on NetBSD.

2019-06-14  Matt Thomas  <matt@3am-software.com>
    Matthew Green  <mrg@eterna.com.au>
    Nick Hudson  <skrll@netbsd.org>
    Maya Rashish  <coypu@sdf.org>
    Richard Earnshaw  <rearnsha@arm.com>

gcc:

* config.gcc (arm*-*-netbsdelf*) Add support for EABI configuration.
* config.host (arm*-*-netbsd*): Use driver-arm.o on native NetBSD.
* config/arm/netbsd-eabi.h: New file.
* config/arm/netbsd-elf.h (TARGET_OS_CPP_BUILTINS): Undefine before
redefining.
(SUBTARGET_EXTRA_ASM_SPEC): Don't pass -matpcs to the assembler.
* config/netbsd-elf.h (NETBSD_LINK_LD_ELF_SO_SPEC): New define.
(NETBSD_SUBTARGET_EXTRA_SPECS): New define.
(SUBTARGET_EXTRA_SPECS): Define to NETBSD_SUBTARGET_EXTRA_SPECS.

libatomic:
* configure.tgt (arm*): Handle NetBSD in the same way as FreeBSD.

libgcc:
* config.host (arm*-*-netbsdelf*): Add support for EABI configurations.
* config/arm/t-netbsd (LIB1ASMFUNCS): Add some additional assembler
functions to build.
* config/arm/t-netbsd-eabi: New file.

Co-Authored-By: Matthew Green <mrg@eterna.com.au>
Co-Authored-By: Maya Rashish <coypu@sdf.org>
Co-Authored-By: Nick Hudson <skrll@netbsd.org>
Co-Authored-By: Richard Earnshaw <rearnsha@arm.com>
From-SVN: r272290

12 files changed:
gcc/ChangeLog
gcc/config.gcc
gcc/config.host
gcc/config/arm/netbsd-eabi.h [new file with mode: 0644]
gcc/config/arm/netbsd-elf.h
gcc/config/netbsd-elf.h
libatomic/ChangeLog
libatomic/configure.tgt
libgcc/ChangeLog
libgcc/config.host
libgcc/config/arm/t-netbsd
libgcc/config/arm/t-netbsd-eabi [new file with mode: 0644]

index 00c252e0b71aa162daceb10d66ebfa43ca29a664..f98290188c9c4140e32ff066b6353f4ae31858e9 100644 (file)
@@ -1,3 +1,19 @@
+2019-06-14  Matt Thomas  <matt@3am-software.com>
+           Matthew Green  <mrg@eterna.com.au>
+           Nick Hudson  <skrll@netbsd.org>
+           Maya Rashish  <coypu@sdf.org>
+           Richard Earnshaw  <rearnsha@arm.com>
+
+       * config.gcc (arm*-*-netbsdelf*) Add support for EABI configuration.
+       * config.host (arm*-*-netbsd*): Use driver-arm.o on native NetBSD.
+       * config/arm/netbsd-eabi.h: New file.
+       * config/arm/netbsd-elf.h (TARGET_OS_CPP_BUILTINS): Undefine before
+       redefining.
+       (SUBTARGET_EXTRA_ASM_SPEC): Don't pass -matpcs to the assembler.
+       * config/netbsd-elf.h (NETBSD_LINK_LD_ELF_SO_SPEC): New define.
+       (NETBSD_SUBTARGET_EXTRA_SPECS): New define.
+       (SUBTARGET_EXTRA_SPECS): Define to NETBSD_SUBTARGET_EXTRA_SPECS.
+
 2019-06-14  Richard Biener  <rguenther@suse.de>
 
        * tree-loop-distribution.c (classify_partition): Return
index 48e6bb70e40ca0542718be21d6059b06b680104e..8f864c8e1f5f21029e512e40fafcbedf475182e2 100644 (file)
@@ -1162,10 +1162,35 @@ arm*-*-freebsd*)                # ARM FreeBSD EABI
        with_tls=${with_tls:-gnu}
        ;;
 arm*-*-netbsdelf*)
-       tm_file="dbxelf.h elfos.h ${nbsd_tm_file} arm/elf.h arm/aout.h ${tm_file} arm/netbsd-elf.h"
-       extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
-       tmake_file="${tmake_file} arm/t-arm"
        target_cpu_cname="strongarm"
+       tmake_file="${tmake_file} arm/t-arm"
+       tm_file="dbxelf.h elfos.h ${nbsd_tm_file} arm/elf.h"
+       extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+       case ${target} in
+       arm*eb-*) tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1" ;;
+       esac
+       case ${target} in
+       arm*-*-netbsdelf-*eabi*)
+           tm_file="$tm_file arm/bpabi.h arm/netbsd-elf.h arm/netbsd-eabi.h"
+           tmake_file="$tmake_file arm/t-bpabi arm/t-netbsdeabi"
+           ;;
+       *)
+           tm_file="$tm_file arm/netbsd-elf.h"
+           tmake_file="$tmake_file arm/t-netbsd"
+           ;;
+       esac
+       tm_file="${tm_file} arm/aout.h arm/arm.h"
+       case ${target} in
+       arm*-*-netbsdelf-*eabihf*)
+           # Hard-float requires at least Arm v5te
+           target_cpu_cname="arm10e"
+           tm_defines="${tm_defines} TARGET_DEFAULT_FLOAT_ABI=ARM_FLOAT_ABI_HARD"
+           ;;
+       esac
+       case ${target} in
+       armv6*) target_cpu_cname="arm1176jzf-s";;
+       armv7*) target_cpu_cname="generic-armv7-a";;
+       esac
        ;;
 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"
index 2213404dd0ec56a6945927daea1dca2a67d437fa..82409e32f9601226fbbb62a57206575c13a6e9c9 100644 (file)
@@ -107,7 +107,7 @@ case ${host} in
        ;;
     esac
     ;;
-  arm*-*-freebsd* | arm*-*-linux* | arm*-*-fuchsia*)
+  arm*-*-freebsd* | arm*-*-netbsd* | arm*-*-linux* | arm*-*-fuchsia*)
     case ${target} in
       arm*-*-*)
        host_extra_gcc_objs="driver-arm.o"
diff --git a/gcc/config/arm/netbsd-eabi.h b/gcc/config/arm/netbsd-eabi.h
new file mode 100644 (file)
index 0000000..5524b37
--- /dev/null
@@ -0,0 +1,105 @@
+/* Definitions of target machine for GNU compiler, NetBSD/arm ELF version.
+   Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+   Contributed by Wasabi Systems, 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/>.  */
+
+/* Run-time Target Specification.  */
+#undef MULTILIB_DEFAULTS
+#define MULTILIB_DEFAULTS { "mabi=aapcs-linux" }
+
+#define TARGET_LINKER_EABI_SUFFIX_SOFT \
+  "%{!mabi=apcs-gnu:%{!mabi=atpcs:%{mfloat-abi=hard:_eabihf;:_eabi}}}"
+#define TARGET_LINKER_EABI_SUFFIX_HARD \
+  "%{!mabi=apcs-gnu:%{!mabi=atpcs:%{mfloat-abi=soft:_eabi;:_eabihf}}}"
+
+#define TARGET_LINKER_EABI_SUFFIX                      \
+  (TARGET_DEFAULT_FLOAT_ABI == ARM_FLOAT_ABI_SOFT      \
+   ? TARGET_LINKER_EABI_SUFFIX_SOFT                    \
+   : TARGET_LINKER_EABI_SUFFIX_HARD)
+
+#define TARGET_LINKER_BIG_EMULATION "armelfb_nbsd%(linker_eabi_suffix)"
+#define TARGET_LINKER_LITTLE_EMULATION "armelf_nbsd%(linker_eabi_suffix)"
+
+/* TARGET_BIG_ENDIAN_DEFAULT is set in
+   config.gcc for big endian configurations.  */
+#undef  TARGET_LINKER_EMULATION
+#if TARGET_BIG_ENDIAN_DEFAULT
+#define TARGET_LINKER_EMULATION TARGET_LINKER_BIG_EMULATION
+#else
+#define TARGET_LINKER_EMULATION TARGET_LINKER_LITTLE_EMULATION
+#endif
+
+#undef ARM_DEFAULT_ABI
+#define ARM_DEFAULT_ABI ARM_ABI_AAPCS_LINUX
+
+#undef ARM_UNWIND_INFO
+#define ARM_UNWIND_INFO 0
+#undef DWARF2_UNWIND_INFO
+#define DWARF2_UNWIND_INFO 1
+
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS()               \
+  do                                           \
+    {                                          \
+      if (TARGET_AAPCS_BASED)                  \
+       TARGET_BPABI_CPP_BUILTINS();            \
+      NETBSD_OS_CPP_BUILTINS_ELF();            \
+      if (DWARF2_UNWIND_INFO)                  \
+       builtin_define ("__ARM_DWARF_EH__");    \
+    }                                          \
+  while (0)
+
+#undef SUBTARGET_CPP_SPEC
+#define SUBTARGET_CPP_SPEC NETBSD_CPP_SPEC
+
+/*
+ * Override AAPCS types to remain compatible the existing NetBSD types.
+ */
+#undef WCHAR_TYPE
+#define WCHAR_TYPE "int"
+
+#undef SIZE_TYPE
+#define SIZE_TYPE "long unsigned int"
+
+#undef PTRDIFF_TYPE
+#define PTRDIFF_TYPE "long int"
+
+#undef SUBTARGET_EXTRA_ASM_SPEC
+#define SUBTARGET_EXTRA_ASM_SPEC               \
+  "%{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu} "    \
+  "%{fpic|fpie:-k} "                           \
+  "%{fPIC|fPIE:-k}"
+
+#undef SUBTARGET_EXTRA_SPECS
+#define SUBTARGET_EXTRA_SPECS                                          \
+  { "subtarget_extra_asm_spec",        SUBTARGET_EXTRA_ASM_SPEC },             \
+  { "linker_eabi_suffix",      TARGET_LINKER_EABI_SUFFIX },            \
+  { "linker_emulation",                TARGET_LINKER_EMULATION },              \
+  { "linker_big_emulation",    TARGET_LINKER_BIG_EMULATION },          \
+  { "linker_little_emulation", TARGET_LINKER_LITTLE_EMULATION },       \
+  { "target_fix_v4bx_spec",    TARGET_FIX_V4BX_SPEC },                 \
+  NETBSD_SUBTARGET_EXTRA_SPECS
+
+#define NETBSD_ENTRY_POINT "__start"
+
+#undef LINK_SPEC
+#define LINK_SPEC                                              \
+  "-X %{mbig-endian:-EB -m %(linker_big_emulation)} "          \
+  "%{mlittle-endian:-EL -m %(linker_liitle_emulation)} "       \
+  "%{!mbig-endian:%{!mlittle-endian:-m %(linker_emulation)}} " \
+  "%(target_fix_v4bx_spec) %(netbsd_link_spec)"
index 5fcb543ed5fbf76fa87daba6ace7598a5b61ed45..ec68d3fd10f27527379c6057d6a6d8e067a69bea 100644 (file)
@@ -43,6 +43,7 @@
 #undef ARM_DEFAULT_ABI
 #define ARM_DEFAULT_ABI ARM_ABI_ATPCS
 
+#undef TARGET_OS_CPP_BUILTINS
 #define TARGET_OS_CPP_BUILTINS()       \
   do                                   \
     {                                  \
@@ -55,7 +56,7 @@
 
 #undef SUBTARGET_EXTRA_ASM_SPEC
 #define SUBTARGET_EXTRA_ASM_SPEC       \
-  "-matpcs %{" FPIE_OR_FPIC_SPEC ":-k}"
+  "%{" FPIE_OR_FPIC_SPEC ":-k}"
 
 /* Default to full VFP if -mfloat-abi=hard is specified.  */
 #undef SUBTARGET_ASM_FLOAT_SPEC
 /* We don't have any limit on the length as out debugger is GDB.  */
 #undef DBX_CONTIN_LENGTH
 
-/* NetBSD does its profiling differently to the Acorn compiler. We      
+/* NetBSD does its profiling differently to the Acorn compiler. We
    don't need a word following the mcount call; and to skip it
-   requires either an assembly stub or use of fomit-frame-pointer when  
+   requires either an assembly stub or use of fomit-frame-pointer when
    compiling the profiling functions.  Since we break Acorn CC
    compatibility below a little more won't hurt.  */
-   
-#undef ARM_FUNCTION_PROFILER                                  
+
+#undef ARM_FUNCTION_PROFILER
 #define ARM_FUNCTION_PROFILER(STREAM,LABELNO)          \
 {                                                      \
   asm_fprintf (STREAM, "\tmov\t%Rip, %Rlr\n");         \
    boundary.  However this causes problems with bugged NetBSD kernel
    code (possibly userland code as well - I have not checked every
    binary).  The nature of this bugged code is to rely on sizeof()
-   returning the correct size of various structures rounded to the  
+   returning the correct size of various structures rounded to the
    nearest byte (SCSI and ether code are two examples, the vm system
    is another).  This code breaks when the structure alignment is 32
-   as sizeof() will report a word=rounded size.  By changing the        
+   as sizeof() will report a word=rounded size.  By changing the
    structure alignment to 8. GCC will conform to what is expected by
    NetBSD.
-   
+
    This has several side effects that should be considered.
    1. Structures will only be aligned to the size of the largest member.
       i.e. structures containing only bytes will be byte aligned.
-           structures containing shorts will be half word aligned.          
-           structures containing ints will be word aligned.                 
-  
+          structures containing shorts will be half word aligned.
+          structures containing ints will be word aligned.
+
       This means structures should be padded to a word boundary if
       alignment of 32 is required for byte structures etc.
-       
+
    2. A potential performance penalty may exist if strings are no longer
       word aligned.  GCC will not be able to use word load/stores to copy
       short strings.
index e35758b9abc13168c9124d17b37b1197233d9385..12ebdd673c62a50f2e28d9caf5e67cbe517fafaa 100644 (file)
@@ -73,6 +73,9 @@ along with GCC; see the file COPYING3.  If not see
 
    Target-specific code must provide the %(netbsd_entry_point) spec.  */
 
+#define NETBSD_LINK_LD_ELF_SO_SPEC \
+  "%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.elf_so}"
+
 #define NETBSD_LINK_SPEC_ELF \
   "%{assert*} %{R*} %{rpath*} \
    %{shared:-shared} \
@@ -87,6 +90,17 @@ along with GCC; see the file COPYING3.  If not see
        -dynamic-linker /usr/libexec/ld.elf_so} \
      %{static:-static}}"
 
+/* Provide the standard list of subtarget extra specs for NetBSD targets.  */
+#define NETBSD_SUBTARGET_EXTRA_SPECS \
+  { "netbsd_link_ld_elf_so",    NETBSD_LINK_LD_ELF_SO_SPEC }, \
+  { "netbsd_cpp_spec",          NETBSD_CPP_SPEC }, \
+  { "netbsd_link_spec",         NETBSD_LINK_SPEC_ELF }, \
+  { "netbsd_entry_point",       NETBSD_ENTRY_POINT }, \
+  { "netbsd_endfile_spec",      NETBSD_ENDFILE_SPEC },
+
+#undef SUBTARGET_EXTRA_SPECS
+#define SUBTARGET_EXTRA_SPECS   NETBSD_SUBTARGET_EXTRA_SPECS
+
 /* Use --as-needed -lgcc_s for eh support.  */
 #ifdef HAVE_LD_AS_NEEDED
 #define USE_LD_AS_NEEDED 1
index 0bdf5af598dfca1212f7a34597bb90470ec23125..40e32c37330c7633bc975fb43fdf3003919fdac7 100644 (file)
@@ -1,3 +1,10 @@
+2019-06-14  Matt Thomas  <matt@3am-software.com>
+           Matthew Green  <mrg@eterna.com.au>
+           Nick Hudson  <skrll@netbsd.org>
+           Maya Rashish  <coypu@sdf.org>
+
+       * configure.tgt (arm*): Handle NetBSD in the same way as FreeBSD.
+
 2019-01-01  Jakub Jelinek  <jakub@redhat.com>
 
        Update copyright years.
index ecbb7d33cc11b451f83479009e9d2b43510f3f76..4a1294bc1ffff09396c78811aac39161e55df1bf 100644 (file)
@@ -53,7 +53,7 @@ case "${target_cpu}" in
   arm*)
        ARCH=arm
        case "${target}" in
-            arm*-*-freebsd*)
+            arm*-*-freebsd* | arm*-*-netbsd*)
                 ;;
             *)
                 # ??? Detect when -march=armv7 is already enabled.
index ed6f97eda15431e025293540a52992efa26c1942..959776da959788cf2aedaf77d17b70b20884588d 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-14  Matt Thomas  <matt@3am-software.com>
+           Matthew Green  <mrg@eterna.com.au>
+           Nick Hudson  <skrll@netbsd.org>
+           Maya Rashish  <coypu@sdf.org>
+
+       * config.host (arm*-*-netbsdelf*): Add support for EABI configurations.
+       * config/arm/t-netbsd (LIB1ASMFUNCS): Add some additional assembler
+       functions to build.
+       * config/arm/t-netbsd-eabi: New file.
+
 2019-06-12  Dimitar Dimitrov  <dimitar@dinux.eu>
 
        * config.host: Add PRU target.
index 588fd7c33245c1229250c6256740e901b4480e61..0574b4d7741c05901fc7421e36517cf39946c0a3 100644 (file)
@@ -436,7 +436,16 @@ arm*-*-fuchsia*)
        unwind_header=config/arm/unwind-arm.h
        ;;
 arm*-*-netbsdelf*)
-       tmake_file="$tmake_file arm/t-arm arm/t-netbsd t-slibgcc-gld-nover"
+       tmake_file="$tmake_file arm/t-arm"
+       case ${host} in
+         arm*-*-netbsdelf-*eabi*)
+           tmake_file="${tmake_file} arm/t-netbsd-eabi"
+           unwind_header=config/arm/unwind-arm.h
+           ;;
+         *)
+           tmake_file="${tmake_file} arm/t-netbsd t-slibgcc-gld-nover"
+           ;;
+       esac
        ;;
 arm*-*-linux*)                 # ARM GNU/Linux with ELF
        tmake_file="${tmake_file} arm/t-arm t-fixedpoint-gnu-prefix t-crtfm"
index 95358f931ba3cfe994fe2a93773cffe231c17de4..ea4d5de4e7740c993c2e3486c0b8488dd35b8b81 100644 (file)
@@ -1,3 +1,11 @@
+# This list is from t-elf, but with some things removed.
+LIB1ASMFUNCS += _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_tls _bb_init_func \
+       _call_via_rX _interwork_call_via_rX \
+       _arm_fixunsdfsi _arm_fixunssfsi \
+       _arm_floatdidf _arm_floatdisf _arm_floatundidf _arm_floatundisf \
+       _lshrdi3 _ashrdi3 _ashldi3 \
+       _clzsi2 _clzdi2 _ctzsi2
+
 # Just for these, we omit the frame pointer since it makes such a big
 # difference.  It is then pointless adding debugging.
 HOST_LIBGCC2_CFLAGS += -fomit-frame-pointer
diff --git a/libgcc/config/arm/t-netbsd-eabi b/libgcc/config/arm/t-netbsd-eabi
new file mode 100644 (file)
index 0000000..ae08ea4
--- /dev/null
@@ -0,0 +1,18 @@
+# This list is from t-elf, but with lots removed.
+LIB1ASMFUNCS += _dvmd_tls _bb_init_func _call_via_rX _interwork_call_via_rX \
+        _clzsi2 _clzdi2 _ctzsi2
+
+# Derived from t-bpabi
+# Add the BPABI C functions.
+LIB2ADD +=    $(srcdir)/config/arm/unaligned-funcs.c
+
+# Not using libgcc for EH.
+LIB2ADDEH =
+
+# Add the BPABI names.
+SHLIB_MAPFILES += $(srcdir)/config/arm/libgcc-bpabi.ver
+
+# On ARM, specifying -fnon-call-exceptions will needlessly pull in
+# the unwinder in simple programs which use 64-bit division.  Omitting
+# the option is safe.
+LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions