From c177db4bbe9370c05dbcd18220f4c927aea7c94b Mon Sep 17 00:00:00 2001 From: Timothy Wall Date: Thu, 12 Jul 2001 02:55:24 +0000 Subject: [PATCH] ia64-aix port from Tim Wall ia64-aix port from Tim Wall * config.gcc: Add configuration for AIX5/IA64. * config/ia64/aix.h: New. AIX5/IA64-specific configuration. * config/ia64/crt[in].asm: New. Generic static ctor/dtor support prefix/suffix code. * config/ia64/t-aix: New. Makefile fragment. * config/ia64/unwind-aix.c: New. Unwind table entry lookup. From-SVN: r43958 --- gcc/ChangeLog | 9 ++ gcc/config.gcc | 5 + gcc/config/ia64/aix.h | 262 +++++++++++++++++++++++++++++++++++ gcc/config/ia64/crti.asm | 66 +++++++++ gcc/config/ia64/crtn.asm | 56 ++++++++ gcc/config/ia64/t-aix | 19 +++ gcc/config/ia64/unwind-aix.c | 120 ++++++++++++++++ 7 files changed, 537 insertions(+) create mode 100644 gcc/config/ia64/aix.h create mode 100644 gcc/config/ia64/crti.asm create mode 100644 gcc/config/ia64/crtn.asm create mode 100644 gcc/config/ia64/t-aix create mode 100644 gcc/config/ia64/unwind-aix.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f3eed75a716..fd9857f1b14 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2001-07-11 Timothy Wall + + * config.gcc: Add configuration for AIX5/IA64. + * config/ia64/aix.h: New. AIX5/IA64-specific configuration. + * config/ia64/crt[in].asm: New. Generic static ctor/dtor + support prefix/suffix code. + * config/ia64/t-aix: New. Makefile fragment. + * config/ia64/unwind-aix.c: New. Unwind table entry lookup. + 2001-07-11 Kazu Hirata * recog.c (validate_change): Fix a comment typo. diff --git a/gcc/config.gcc b/gcc/config.gcc index 50eb5473dbb..353086c6832 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -1465,6 +1465,11 @@ i960-*-*) # Default i960 environment. c_target_objs="i960-c.o" cxx_target_objs="i960-c.o" ;; +ia64*-*-aix*) + tm_file="${tm_file} svr4.h ia64/sysv4.h ia64/aix.h" + tmake_file="ia64/t-ia64 ia64/t-aix" + target_cpu_default="MASK_GNU_AS|MASK_GNU_LD" + ;; ia64*-*-elf*) tm_file=ia64/elf.h tmake_file="ia64/t-ia64" diff --git a/gcc/config/ia64/aix.h b/gcc/config/ia64/aix.h new file mode 100644 index 00000000000..36baf103fc7 --- /dev/null +++ b/gcc/config/ia64/aix.h @@ -0,0 +1,262 @@ +/* Definitions of target machine GNU compiler. IA-64/AIX version. + Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + Contributed by Timothy Wall (twall@cygnus.com) + +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. */ + +/* AIX5 (aka Monterey): a mix of AIX and UnixWare. + This file is loosely based on ia64/linux.h. */ + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +#define SET_ASM_OP "\t.set\t" + +/*#undef PREFERRED_DEBUGGING_TYPE*/ +/*#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG*/ + +#undef MD_EXEC_PREFIX +#undef MD_STARTFILE_PREFIX +#define MD_STARTFILE_PREFIX "/usr/lib/ia64l64/" + +/* Output at beginning of assembler file. */ +/* The .file command should always begin the output. */ +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) \ + do { \ + output_file_directive (FILE, main_input_filename); \ + fprintf (FILE, "\t.version\t\"01.01\"\n"); \ + } while (0) + +/* Provide a STARTFILE_SPEC appropriate for AIX. Here we add + the crti C++ startup files file which provide part of the support + for getting C++ file-scope static object constructed before entering + `main'. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ +"%{!shared: \ + %{pg:gcrt1_64.o%s} %{!pg:%{p:mcrt1_64.o%s} \ + %{!p:%{profile:gcrt1_64.o%s} \ + %{!profile:crt1_64.o%s}}}} \ + crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}" + +/* Provide a ENDFILE_SPEC appropriate for AIX. Here we tack on + the crtn file which provides termination of the support for getting C++ + file-scope static object constructed before entering `main'. */ + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" + +#undef DEFAULT_VTABLE_THUNKS +#define DEFAULT_VTABLE_THUNKS 1 + +/* Define this so we can compile MS code for use with WINE. */ +#define HANDLE_PRAGMA_PACK_PUSH_POP + +/* A C string constant that tells the GNU CC driver program options to pass to + CPP. It can also specify how to translate options you give to GNU CC into + options for GNU CC to pass to the CPP. */ + +/* If -ansi, we need to define _ANSI_C_SOURCE to get the right headers. */ +#undef CPP_SPEC +#define CPP_SPEC "\ +%{mcpu=itanium:-D__itanium__} %{mbig-endian:-D__BIG_ENDIAN__} \ +%{ansi:-D_ANSI_C_SOURCE} \ +%{posix:-D_POSIX_SOURCE} \ +%{cpp_cpu} \ +-D__LONG_MAX__=9223372036854775807L" + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "\ +-D__ia64 -D__ia64__ -D_AIX -D_AIX64 -D_LONGLONG -Dunix \ +-D__LP64__ -D__ELF__ -Asystem=unix -Asystem=aix -Acpu=ia64 -Amachine=ia64 \ +-D__64BIT__ -D_LONG_LONG -D_IA64 -D__int128=__size128_t" + +/* The GNU C++ standard library requires that these macros be defined. */ +#undef CPLUSPLUS_CPP_SPEC +#define CPLUSPLUS_CPP_SPEC \ + "-D_XOPEN_SOURCE=500 \ + -D_XOPEN_SOURCE_EXTENDED=1 \ + -D_LARGE_FILE_API \ + -D_ALL_SOURCE \ + -D__LONG_MAX__=9223372036854775807L \ + %{cpp_cpu}" + +/* ia64-specific options for gas */ +#undef ASM_SPEC +#define ASM_SPEC "-x %{mconstant-gp} %{mauto-pic}" + +/* Define this for shared library support. */ + +#undef LINK_SPEC +#define LINK_SPEC "\ +%{shared:-shared} \ +%{!shared: \ + %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!dynamic-linker:-dynamic-linker /usr/lib/ia64l64/libc.so.1}} \ + %{static:-static}}" + +#define DONT_USE_BUILTIN_SETJMP +#define JMP_BUF_SIZE 85 + +/* Output any profiling code before the prologue. */ + +#undef PROFILE_BEFORE_PROLOGUE +#define PROFILE_BEFORE_PROLOGUE 1 + +/* A C statement or compound statement to output to FILE some assembler code to + call the profiling subroutine `mcount'. + + FIXME this is not supported until xlC supports it and can thus tell us + how to do it. +*/ + +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ +do { \ +} while (0) + +/* Tell the linker where to find the crt*.o files. */ + +#ifndef CROSS_COMPILE +#undef STANDARD_STARTFILE_PREFIX +#define STANDARD_STARTFILE_PREFIX "/usr/lib/ia64l64/" +#endif + +/* Override SELECT_SECTION and SELECT_RTX_SECTION from config/ia64/sysv4.h; + these definitions ignore flag_pic as if it were always set; + it is illegal to have relocations in shared segments on AIX. */ + +/* A C statement or statements to switch to the appropriate + section for output of DECL. DECL is either a `VAR_DECL' node + or a constant of some sort. RELOC indicates whether forming + the initial value of DECL requires link-time relocations. */ + +#undef SELECT_SECTION +#define SELECT_SECTION(DECL,RELOC) \ +{ \ + if (TREE_CODE (DECL) == STRING_CST) \ + { \ + if (! flag_writable_strings) \ + const_section (); \ + else \ + data_section (); \ + } \ + else if (TREE_CODE (DECL) == VAR_DECL) \ + { \ + if (XSTR (XEXP (DECL_RTL (DECL), 0), 0)[0] \ + == SDATA_NAME_FLAG_CHAR) \ + sdata_section (); \ + /* ??? We need the extra ! RELOC check, because the default is to \ + only check RELOC if flag_pic is set, and we don't set flag_pic \ + (yet?). */ \ + else if (DECL_READONLY_SECTION (DECL, RELOC) && ! (RELOC)) \ + const_section (); \ + else \ + data_section (); \ + } \ + /* This could be a CONSTRUCTOR containing ADDR_EXPR of a VAR_DECL, \ + in which case we can't put it in a shared library rodata. */ \ + else if (RELOC) \ + data_section (); \ + else \ + const_section (); \ +} + +/* Similarly for constant pool data. */ + +extern unsigned int ia64_section_threshold; +#undef SELECT_RTX_SECTION +#define SELECT_RTX_SECTION(MODE, RTX) \ +{ \ + if (GET_MODE_SIZE (MODE) > 0 \ + && GET_MODE_SIZE (MODE) <= ia64_section_threshold) \ + sdata_section (); \ + else if (symbolic_operand ((RTX), (MODE))) \ + data_section (); \ + else \ + const_section (); \ +} + +#undef UNIQUE_SECTION +#define UNIQUE_SECTION(DECL, RELOC) \ + do \ + { \ + int len; \ + int sec; \ + const char *name; \ + char *string; \ + const char *prefix; \ + static const char *prefixes[/*4*/3][2] = \ + { \ + { ".text.", ".gnu.linkonce.t." }, \ + { ".rodata.", ".gnu.linkonce.r." }, \ + { ".data.", ".gnu.linkonce.d." } \ + /* Do not generate unique sections for uninitialised \ + data since we do not have support for this in the \ + linker scripts yet... \ + ,{ ".bss.", ".gnu.linkonce.b." } */ \ + }; \ + \ + if (TREE_CODE (DECL) == FUNCTION_DECL) \ + sec = 0; \ + /* else if (DECL_INITIAL (DECL) == 0 \ + || DECL_INITIAL (DECL) == error_mark_node) \ + sec = 3; */ \ + else if (DECL_READONLY_SECTION (DECL, RELOC) && ! (RELOC))\ + sec = 1; \ + else \ + sec = 2; \ + \ + name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \ + /* Strip off any encoding in name. */ \ + STRIP_NAME_ENCODING (name, name); \ + prefix = prefixes[sec][DECL_ONE_ONLY(DECL)]; \ + len = strlen (name) + strlen (prefix); \ + string = alloca (len + 1); \ + \ + sprintf (string, "%s%s", prefix, name); \ + \ + DECL_SECTION_NAME (DECL) = build_string (len, string); \ + } \ + while (0) + +/* Override ia64/sysv4.h setting with that used by AIX5. */ +#undef WCHAR_TYPE +#ifdef __64BIT__ +#define WCHAR_TYPE "unsigned int" +#else +#define WCHAR_TYPE "unsigned short" +#endif + +/* Have to get rid of the system's definition so that we can use gcc's + instead. */ +#include +#undef REG_SIZE + +/* Define the `__builtin_va_list' type for AIX. Use char* b/c that's what the + system headers expect. */ +#define BUILD_VA_LIST_TYPE(VALIST) \ + (VALIST) = build_pointer_type(char_type_node) + +/* End of aix.h */ diff --git a/gcc/config/ia64/crti.asm b/gcc/config/ia64/crti.asm new file mode 100644 index 00000000000..4b94b7f6953 --- /dev/null +++ b/gcc/config/ia64/crti.asm @@ -0,0 +1,66 @@ +# Copyright (C) 2000, 2001 Free Software Foundation, Inc. +# Written By Timothy Wall +# +# This file 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. +# +# In addition to the permissions in the GNU General Public License, the +# Free Software Foundation gives you unlimited permission to link the +# compiled version of this file with other programs, and to distribute +# those programs without any restriction coming from the use of this +# file. (The General Public License restrictions do apply in other +# respects; for example, they cover modification of the file, and +# distribution when not linked into another program.) +# +# This file 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 this program; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# +# As a special exception, if you link this library with files +# compiled with GCC to produce an executable, this does not cause +# the resulting executable to be covered by the GNU General Public License. +# This exception does not however invalidate any other reasons why +# the executable file might be covered by the GNU General Public License. +# + +# This file just make a stack frame for the contents of the .fini and +# .init sections. Users may put any desired instructions in those +# sections. + + .file "crti.asm" + + .section ".init" + .align 16 + .global _init# +_init: + .prologue 14, 33 + .save ar.pfs, r34 + alloc r34 = ar.pfs, 0, 4, 0, 0 + .vframe r35 + mov r35 = r12 + .save rp, r33 + mov r33 = b0 + .body + + .section ".fini" + .align 16 + .global _fini# +_fini: + .prologue 14, 33 + .save ar.pfs, r34 + alloc r34 = ar.pfs, 0, 4, 0, 0 + .vframe r35 + mov r35 = r12 + .save rp, r33 + mov r33 = b0 + .body + +# end of crti.asm diff --git a/gcc/config/ia64/crtn.asm b/gcc/config/ia64/crtn.asm new file mode 100644 index 00000000000..0b45d380aad --- /dev/null +++ b/gcc/config/ia64/crtn.asm @@ -0,0 +1,56 @@ +# Copyright (C) 2000, 2001 Free Software Foundation, Inc. +# Written By Timothy Wall +# +# This file 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. +# +# In addition to the permissions in the GNU General Public License, the +# Free Software Foundation gives you unlimited permission to link the +# compiled version of this file with other programs, and to distribute +# those programs without any restriction coming from the use of this +# file. (The General Public License restrictions do apply in other +# respects; for example, they cover modification of the file, and +# distribution when not linked into another program.) +# +# This file 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 this program; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# +# As a special exception, if you link this library with files +# compiled with GCC to produce an executable, this does not cause +# the resulting executable to be covered by the GNU General Public License. +# This exception does not however invalidate any other reasons why +# the executable file might be covered by the GNU General Public License. +# + +# This file just makes sure that the .fini and .init sections do in +# fact return. Users may put any desired instructions in those sections. +# This file is the last thing linked into any executable. + + .file "crtn.asm" + + .section ".init" + ;; + mov ar.pfs = r34 + mov b0 = r33 + .restore sp + mov r12 = r35 + br.ret.sptk.many b0 + + .section ".fini" + ;; + mov ar.pfs = r34 + mov b0 = r33 + .restore sp + mov r12 = r35 + br.ret.sptk.many b0 + +# end of crtn.asm diff --git a/gcc/config/ia64/t-aix b/gcc/config/ia64/t-aix new file mode 100644 index 00000000000..2e738f9b9e1 --- /dev/null +++ b/gcc/config/ia64/t-aix @@ -0,0 +1,19 @@ +# AIX support + +# Compile crtbeginS.o and crtendS.o with pic. +CRTSTUFF_T_CFLAGS_S = -fPIC +# Compile libgcc2.a with pic and defines required by AIX headers +TARGET_LIBGCC2_CFLAGS = -fPIC -D__64BIT__ -D_LONG_LONG -D_IA64 -D__int128=__size128_t +LIB2ADDEH += $(srcdir)/config/ia64/unwind-aix.c + +# Add crt[in].o to the list defined in t-ia64. These files provide +# endpoints for crtbegin/end. + +EXTRA_PARTS=crti.o crtn.o crtbegin.o crtend.o crtbeginS.o crtendS.o + +crti.o: $(srcdir)/config/ia64/crti.asm $(GCC_PASSES) + $(GCC_FOR_TARGET) -c -o crti.o -x assembler $(srcdir)/config/ia64/crti.asm +crtn.o: $(srcdir)/config/ia64/crtn.asm $(GCC_PASSES) + $(GCC_FOR_TARGET) -c -o crtn.o -x assembler $(srcdir)/config/ia64/crtn.asm + +# end t-aix diff --git a/gcc/config/ia64/unwind-aix.c b/gcc/config/ia64/unwind-aix.c new file mode 100644 index 00000000000..b1302a81596 --- /dev/null +++ b/gcc/config/ia64/unwind-aix.c @@ -0,0 +1,120 @@ +/* Implements unwind table entry lookup for AIX (cf. fde-glibc.c). + Copyright (C) 2001 Free Software Foundation, Inc. + Contributed by Timothy Wall + + 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. */ + +#include "tconfig.h" +#include "tsystem.h" +#include "unwind.h" +#include "unwind-ia64.h" + +#include +#include +#include + +static struct unw_table_entry * +find_fde_for_dso (Elf64_Addr pc, rt_link_map *map, + unsigned long* pseg_base, unsigned long* pgp) +{ + rt_segment *seg; + Elf64_Addr seg_base; + struct unw_table_entry *f_base; + size_t lo, hi; + + /* See if PC falls into one of the loaded segments. */ + for (seg = map->l_segments; seg; seg = (rt_segment *)seg->s_next) + { + if (pc >= seg->s_map_addr && pc < seg->s_map_addr + seg->s_mapsz) + break; + } + if (!seg) + return NULL; + + /* Search for the entry within the unwind table. */ + f_base = (struct unw_table_entry *) (map->l_unwind_table); + seg_base = (Elf64_Addr) seg->s_map_addr; + lo = 0; + hi = map->l_unwind_sz / sizeof (struct unw_table_entry); + + while (lo < hi) + { + size_t mid = (lo + hi) / 2; + struct unw_table_entry *f = f_base + mid; + + if (pc < f->start_offset + seg_base) + hi = mid; + else if (pc >= f->end_offset + seg_base) + lo = mid + 1; + else { + /* AIX executables are *always* dynamic. Look up GP for this + object. */ + Elf64_Dyn *dyn = map->l_ld; + *pgp = 0; + for (; dyn->d_tag != DT_NULL ; dyn++) + { + if (dyn->d_tag == DT_PLTGOT) + { + *pgp = dyn->d_un.d_ptr; + break; + } + } + *pseg_base = seg_base; + return f; + } + } + return NULL; +} + +/* Return a pointer to the unwind table entry for the function containing + PC. */ +struct unw_table_entry * +_Unwind_FindTableEntry (void *pc, unsigned long *pseg_base, unsigned long *pgp) +{ + extern rt_r_debug _r_debug; + struct unw_table_entry *ret; + rt_link_map *map = _r_debug.r_map; /* address of link map */ + + /* Check the main application first, hoping that most of the user's + code is there instead of in some library. */ + ret = find_fde_for_dso ((Elf64_Addr)pc, map, pseg_base, pgp); + if (ret) + { + /* If we're in the main application, use the current GP value. */ + register unsigned long gp __asm__("gp"); + *pgp = gp; + return ret; + } + + /* FIXME need a DSO lock mechanism for AIX here, to ensure shared + libraries aren't changed while we're examining them. */ + + for (map = _r_debug.r_map; map; map = map->l_next) + { + /* Skip the main application's entry. */ + if (!map->l_name) + continue; + ret = find_fde_for_dso ((Elf64_Addr)pc, map, pseg_base, pgp); + if (ret) + break; + } + + /* FIXME need a DSO unlock mechanism for AIX here. */ + + return ret; +} -- 2.30.2