From fa0afdce72be67a8ebecde249a8d07cc9b5395d9 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Sun, 30 Aug 2015 10:46:39 +0200 Subject: [PATCH] ppc: initial powerpc-apple-macos target --- binutils/bfd/config.bfd | 1 + binutils/bfd/targets.c | 2 +- binutils/gas/configure.tgt | 2 +- binutils/ld/configure.tgt | 1 + gcc/gcc/config.gcc | 9 + gcc/gcc/config/rs6000/macos.h | 220 +++++++++++++++++++++++ gcc/gcc/config/rs6000/t-macos | 35 ++++ gcc/gcc/expr.c | 2 + gcc/libgcc/config.host | 3 + gcc/libgcc/config/rs6000/cxa_finalize.c | 2 +- gcc/newlib/libc/machine/powerpc/setjmp.S | 25 ++- 11 files changed, 292 insertions(+), 10 deletions(-) create mode 100644 gcc/gcc/config/rs6000/macos.h create mode 100644 gcc/gcc/config/rs6000/t-macos diff --git a/binutils/bfd/config.bfd b/binutils/bfd/config.bfd index c3b9664e7a..c3a7564154 100644 --- a/binutils/bfd/config.bfd +++ b/binutils/bfd/config.bfd @@ -1280,6 +1280,7 @@ case "${targ}" in targ_archs="$targ_archs bfd_i386_arch" ;; powerpc-*-macos*) + targ_selvecs=powerpc_xcoff_vec targ_defvec=powerpc_xcoff_vec ;; powerpc-*-lynxos*) diff --git a/binutils/bfd/targets.c b/binutils/bfd/targets.c index 8323e9256a..4b002fea2e 100644 --- a/binutils/bfd/targets.c +++ b/binutils/bfd/targets.c @@ -1273,7 +1273,7 @@ static const bfd_target * const _bfd_target_vector[] = &powerpc_pe_le_vec, &powerpc_pei_vec, &powerpc_pei_le_vec, -#if 0 +#if 1 /* This has the same magic number as RS/6000. */ &powerpc_xcoff_vec, #endif diff --git a/binutils/gas/configure.tgt b/binutils/gas/configure.tgt index e06fa8ce1d..a76772f507 100644 --- a/binutils/gas/configure.tgt +++ b/binutils/gas/configure.tgt @@ -375,7 +375,7 @@ case ${generic_target} in ppc-*-aix5.[01]) fmt=coff em=aix5 ;; ppc-*-aix[5-9].*) fmt=coff em=aix5 ;; ppc-*-aix*) fmt=coff em=aix ;; - ppc-*-beos*) fmt=coff ;; + ppc-*-beos*) fmt=coff ;; ppc-*-*n*bsd* | ppc-*-elf*) fmt=elf ;; ppc-*-eabi* | ppc-*-sysv4*) fmt=elf ;; ppc-*-linux-*) fmt=elf em=linux ;; diff --git a/binutils/ld/configure.tgt b/binutils/ld/configure.tgt index 0f3e448c13..4da255efce 100644 --- a/binutils/ld/configure.tgt +++ b/binutils/ld/configure.tgt @@ -603,6 +603,7 @@ powerpcle-*-pe | powerpcle-*-winnt* | powerpcle-*-cygwin*) powerpc-*-aix[5-9]*) targ_emul=aix5ppc ;; powerpc-*-aix*) targ_emul=aixppc ;; powerpc-*-beos*) targ_emul=aixppc ;; +powerpc-*-macos*) targ_emul=aixppc ;; powerpc-*-windiss*) targ_emul=elf32ppcwindiss ;; powerpc-*-lynxos*) targ_emul=ppclynx ;; rs6000-*-aix[5-9]*) targ_emul=aix5rs6 ;; diff --git a/gcc/gcc/config.gcc b/gcc/gcc/config.gcc index 7b5bebd0be..ad35e8b117 100644 --- a/gcc/gcc/config.gcc +++ b/gcc/gcc/config.gcc @@ -2466,6 +2466,15 @@ powerpcle-*-eabi*) extra_options="${extra_options} rs6000/sysv4.opt" use_gcc_stdint=wrap ;; +powerpc-apple-macos*) + tm_file="${tm_file} rs6000/xcoff.h rs6000/aix-stdint.h rs6000/macos.h" + tmake_file="rs6000/t-macos" + extra_options="${extra_options} rs6000/aix64.opt" + use_collect2=yes + thread_file='aix' + use_gcc_stdint=provide + extra_headers= + ;; rs6000-ibm-aix4.[3456789]* | powerpc-ibm-aix4.[3456789]*) tm_file="rs6000/biarch64.h ${tm_file} rs6000/aix.h rs6000/aix43.h rs6000/xcoff.h rs6000/aix-stdint.h" tmake_file="rs6000/t-aix43 t-slibgcc" diff --git a/gcc/gcc/config/rs6000/macos.h b/gcc/gcc/config/rs6000/macos.h new file mode 100644 index 0000000000..89c3749905 --- /dev/null +++ b/gcc/gcc/config/rs6000/macos.h @@ -0,0 +1,220 @@ +/* Definitions of target machine for GNU compiler, + for IBM RS/6000 POWER running AIX. + Copyright (C) 2000-2015 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 + . */ + +/* Yes! We are AIX! */ +#define DEFAULT_ABI ABI_AIX +#undef TARGET_AIX +#define TARGET_AIX 1 + +/* Linux64.h wants to redefine TARGET_AIX based on -m64, but it can't be used + in the #if conditional in options-default.h, so provide another macro. */ +#undef TARGET_AIX_OS +#define TARGET_AIX_OS 1 + +/* AIX always has a TOC. */ +#define TARGET_NO_TOC 0 +#define TARGET_TOC 1 +#define FIXED_R2 1 + +/* AIX allows r13 to be used in 32-bit mode. */ +#define FIXED_R13 0 + +/* 32-bit and 64-bit AIX stack boundary is 128. */ +#undef STACK_BOUNDARY +#define STACK_BOUNDARY 128 + +#undef TARGET_IEEEQUAD +#define TARGET_IEEEQUAD 0 + + +#if HAVE_AS_REF +/* Issue assembly directives that create a reference to the given DWARF table + identifier label from the current function section. This is defined to + ensure we drag frame frame tables associated with needed function bodies in + a link with garbage collection activated. */ +#define ASM_OUTPUT_DWARF_TABLE_REF rs6000_aix_asm_output_dwarf_table_ref +#endif + +/* This is the only version of nm that collect2 can work with. */ +//#define REAL_NM_FILE_NAME "/usr/ucb/nm" + +#define USER_LABEL_PREFIX "" + +/* Don't turn -B into -L if the argument specifies a relative file name. */ +#define RELATIVE_PREFIX_NOT_LINKDIR + +/* Because of the above, we must have gcc search itself to find libgcc.a. */ +#define LINK_LIBGCC_SPECIAL_1 + +#undef ASM_DEFAULT_SPEC +#define ASM_DEFAULT_SPEC "" + +/* Profiled library versions are used by linking with special directories. */ +#define LIB_SPEC "-lc" + +/* Static linking with shared libstdc++ requires libsupc++ as well. */ +#define LIBSTDCXX_STATIC "supc++" + +/* This now supports a natural alignment mode. */ +/* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints. */ +#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ + ((TARGET_ALIGN_NATURAL == 0 \ + && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ + ? MIN ((COMPUTED), 32) \ + : (COMPUTED)) + +/* AIX increases natural record alignment to doubleword if the first + field is an FP double while the FP fields remain word aligned. */ +#define ROUND_TYPE_ALIGN(STRUCT, COMPUTED, SPECIFIED) \ + ((TREE_CODE (STRUCT) == RECORD_TYPE \ + || TREE_CODE (STRUCT) == UNION_TYPE \ + || TREE_CODE (STRUCT) == QUAL_UNION_TYPE) \ + && TARGET_ALIGN_NATURAL == 0 \ + ? rs6000_special_round_type_align (STRUCT, COMPUTED, SPECIFIED) \ + : MAX ((COMPUTED), (SPECIFIED))) + +/* The AIX ABI isn't explicit on whether aggregates smaller than a + word/doubleword should be padded upward or downward. One could + reasonably assume that they follow the normal rules for structure + layout treating the parameter area as any other block of memory, + then map the reg param area to registers, i.e., pad upward, which + is the way IBM Compilers for AIX behave. + Setting both of the following defines results in this behavior. */ +#define AGGREGATE_PADDING_FIXED 1 +#define AGGREGATES_PAD_UPWARD_ALWAYS 1 + +/* Specify padding for the last element of a block move between + registers and memory. FIRST is nonzero if this is the only + element. */ +#define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \ + (!(FIRST) ? upward : FUNCTION_ARG_PADDING (MODE, TYPE)) + +/* Indicate that jump tables go in the text section. */ + +#define JUMP_TABLES_IN_TEXT_SECTION 1 + + +#define PROFILE_HOOK(LABEL) output_profile_hook (LABEL) + +/* No version of AIX fully supports AltiVec or 64-bit instructions in + 32-bit mode. */ +#define OS_MISSING_POWERPC64 1 +#define OS_MISSING_ALTIVEC 1 + +/* WINT_TYPE */ +#define WINT_TYPE "int" + +/* Static stack checking is supported by means of probes. */ +#define STACK_CHECK_STATIC_BUILTIN 1 + +/* Use standard DWARF numbering for DWARF debugging information. */ +#define RS6000_USE_DWARF_NUMBERING + + + +/* MacOS does support Altivec. */ +#/*undef TARGET_ALTIVEC +#define TARGET_ALTIVEC 1 +#undef TARGET_ALTIVEC_ABI +#define TARGET_ALTIVEC_ABI 1 +#undef TARGET_ALTIVEC_VRSAVE +#define TARGET_ALTIVEC_VRSAVE 1*/ + +#undef TARGET_OS_CPP_BUILTINS +/* __POWERPC__ must be defined for some header files */ +#define TARGET_OS_CPP_BUILTINS() \ + do \ + { \ + builtin_define ("__ppc__"); \ + builtin_define ("__POWERPC__"); \ + builtin_define ("__NATURAL_ALIGNMENT__"); \ + builtin_define ("__APPLE__"); \ + builtin_assert ("system=macos"); \ + builtin_assert ("cpu=powerpc"); \ + builtin_assert ("machine=powerpc"); \ + builtin_define("__IEEE_BIG_ENDIAN"); \ + } \ + while (0) + +/* --no-check-sections : sections overlap on purpose! + --bnogc : something's going wrong when csects are gc'ed +*/ + +#define LINK_SPEC "%{!r:-btextro} -bhalt:4 -bnodelcsect \ +--no-check-sections -bnogc \ +%{shared:-bM:SRE}" + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC "" + +#undef TARGET_DEFAULT +#define TARGET_DEFAULT 0 +// (MASK_POWERPC | MASK_MULTIPLE | MASK_NEW_MNEMONICS) + +#undef PROCESSOR_DEFAULT +#define PROCESSOR_DEFAULT PROCESSOR_PPC603 + +#undef OS_MISSING_ALTIVEC +#define OS_MISSING_ALTIVEC 0 + +#undef VECTOR_SAVE_INLINE +#define VECTOR_SAVE_INLINE(FIRST_REG) 1 + + +#define TARGET_USES_AIX64_OPT + +#undef TARGET_POINTERS_TO_NESTED_FUNCTIONS +#define TARGET_POINTERS_TO_NESTED_FUNCTIONS 0 + +#if 0 +/* The AIX linker will discard static constructors in object files before + collect has a chance to see them, so scan the object files directly. */ +#define COLLECT_EXPORT_LIST + +/* On AIX, initialisers specified with -binitfini are called in breadth-first + order. + e.g. if a.out depends on lib1.so, the init function for a.out is called before + the init function for lib1.so. + + To ensure global C++ constructors in linked libraries are run before global + C++ constructors from the current module, there is additional symbol scanning + logic in collect2. + + The global initialiser/finaliser functions are named __GLOBAL_AIXI_{libname} + and __GLOBAL_AIXD_{libname} and are exported from each shared library. + + collect2 will detect these symbols when they exist in shared libraries that + the current program is being linked against. All such initiliser functions + will be called prior to the constructors of the current program, and + finaliser functions called after destructors. + + Reference counting generated by collect2 will ensure that constructors are + only invoked once in the case of multiple dependencies on a library. + + -binitfini is still used in parallel to this solution. + This handles the case where a library is loaded through dlopen(), and also + handles the option -blazy. +*/ +#define COLLECT_SHARED_INIT_FUNC(STREAM, FUNC) \ + fprintf ((STREAM), "void %s() {\n\t%s();\n}\n", aix_shared_initname, (FUNC)) +#define COLLECT_SHARED_FINI_FUNC(STREAM, FUNC) \ + fprintf ((STREAM), "void %s() {\n\t%s();\n}\n", aix_shared_fininame, (FUNC)) + +#endif \ No newline at end of file diff --git a/gcc/gcc/config/rs6000/t-macos b/gcc/gcc/config/rs6000/t-macos new file mode 100644 index 0000000000..534dd94a42 --- /dev/null +++ b/gcc/gcc/config/rs6000/t-macos @@ -0,0 +1,35 @@ +# Copyright (C) 1998-2015 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 +# . + +# Build the libraries for pthread and all of the +# different processor models + +#MULTILIB_OPTIONS = +# mcpu=powerpc + +#MULTILIB_DIRNAMES = +#powerpc + +#MULTILIB_MATCHES = +# mcpu?powerpc=mcpu?powerpc \ +# mcpu?powerpc=mcpu?601 \ +# mcpu?powerpc=mcpu?602 \ +# mcpu?powerpc=mcpu?603 \ +# mcpu?powerpc=mcpu?603e \ +# mcpu?powerpc=mcpu?604 \ +# mcpu?powerpc=mcpu?604e diff --git a/gcc/gcc/expr.c b/gcc/gcc/expr.c index f4b6cb798c..451f516e72 100644 --- a/gcc/gcc/expr.c +++ b/gcc/gcc/expr.c @@ -3949,12 +3949,14 @@ find_args_size_adjust (rtx_insn *insn) addr = XEXP (mem, 0); switch (GET_CODE (addr)) { +#ifdef PUSH_ROUNDING case PRE_INC: case POST_INC: return PUSH_ROUNDING( GET_MODE_SIZE (GET_MODE (mem)) ); case PRE_DEC: case POST_DEC: return -PUSH_ROUNDING( GET_MODE_SIZE (GET_MODE (mem)) ); +#endif case PRE_MODIFY: case POST_MODIFY: addr = XEXP (addr, 1); diff --git a/gcc/libgcc/config.host b/gcc/libgcc/config.host index 1a7c26588b..9341a85db7 100644 --- a/gcc/libgcc/config.host +++ b/gcc/libgcc/config.host @@ -1076,6 +1076,9 @@ rs6000-ibm-aix[56789].* | powerpc-ibm-aix[56789].*) tmake_file="t-fdpbit rs6000/t-ppc64-fp rs6000/t-slibgcc-aix rs6000/t-ibm-ldouble rs6000/t-aix-cxa" extra_parts="crtcxa.o crtcxa_s.o" ;; +powerpc-*-macos) + tmake_file="t-fdpbit rs6000/t-ibm-ldouble rs6000/t-aix-cxa" + ;; rl78-*-elf) tmake_file="$tm_file t-fdpbit rl78/t-rl78" ;; diff --git a/gcc/libgcc/config/rs6000/cxa_finalize.c b/gcc/libgcc/config/rs6000/cxa_finalize.c index 71f8579248..8631019f7a 100644 --- a/gcc/libgcc/config/rs6000/cxa_finalize.c +++ b/gcc/libgcc/config/rs6000/cxa_finalize.c @@ -29,7 +29,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "exit.h" -static boolean_t +static int catomic_compare_and_exchange_bool_acq (long *mem, long newval, long oldval) { return __atomic_compare_exchange (mem, &oldval, &newval, 0, diff --git a/gcc/newlib/libc/machine/powerpc/setjmp.S b/gcc/newlib/libc/machine/powerpc/setjmp.S index f327f31dae..463ba1fb99 100644 --- a/gcc/newlib/libc/machine/powerpc/setjmp.S +++ b/gcc/newlib/libc/machine/powerpc/setjmp.S @@ -2,9 +2,15 @@ Ian Lance Taylor, Cygnus Support, 9 Feb 1994. Modified by Jeff Johnston, Red Hat Inc. 2 Oct 2001. */ -#include "ppc-asm.h" - -FUNC_START(setjmp) + .csect .text[PR] + .align 2 + .globl setjmp + .globl .setjmp + .csect setjmp[DS] +setjmp: + .long .setjmp, TOC[tc0], 0 + .csect .text[PR] +.setjmp: #ifdef __ALTIVEC__ addi 3,3,15 # align Altivec to 16 byte boundary rlwinm 3,3,0,0,27 @@ -134,10 +140,16 @@ FUNC_START(setjmp) #endif li 3,0 blr -FUNC_END(setjmp) - -FUNC_START(longjmp) + .csect .text[PR] + .align 2 + .globl longjmp + .globl .longjmp + .csect longjmp[DS] +longjmp: + .long .longjmp, TOC[tc0], 0 + .csect .text[PR] +.longjmp: #ifdef __ALTIVEC__ addi 3,3,15 # align Altivec to 16 byte boundary rlwinm 3,3,0,0,27 @@ -265,4 +277,3 @@ FUNC_START(longjmp) bclr+ 4,2 li 3,1 blr -FUNC_END(longjmp)