From f8200b2a38c440a0a4260ad629e1a08dda809b22 Mon Sep 17 00:00:00 2001 From: rsandifo Date: Thu, 18 Jan 2007 19:09:59 +0000 Subject: [PATCH] gcc/ * config.gcc (m68k-*-uclinux*): Add flat.h to $tm_file. * config/flat.h: New file. * crtstuff.c (USE_PT_GNU_EH_FRAME): Don't define if OBJECT_FORMAT_FLAT. * config/m68k/m68k.h (ASM_PREFERRED_EH_DATA_FORMAT): Do not use indirect references for -msep-data or -mid-shared-library. Do not use PC-relative code addresses either. * config/m68k/m68k.c (override_options): Restrict -fPIC error to -mpcrel. * config/m68k/uclinux.h (STARTFILE_SPEC): Define. Use Scrt1.o for shared libraries and crt1.o for executables. Use crti.o and crtbegin.o. (ENDFILE_SPEC): Use crtend.o and crtn.o. (LIB_SPEC): Suppress -Rlibc.gdb if -static-libc is given. Do not add -elf2flt or -shared-lib-id options here. (LINK_SPEC): Define. Pass -elf2flt if no -elf2flt option is given. Pass -shared-lib-id if -mid-shared-library, taking the library identifier from -mshared-library-id if given, otherwise defaulting to 0. (EH_FRAME_IN_DATA_SECTION): Do not undefine. (INIT_SECTION_ASM_OP, FINI_SECTION_ASM_OP): Likewise. (TARGET_OS_CPP_BUILTINS): Define __GXX_MERGED_TYPEINFO_NAMES=0 and __GXX_TYPEINFO_EQUALITY_INLINE=0 if -mid-shared-library. (DRIVER_SELF_SPECS): Map unadorned PIC options to -msep-data. * config/m68k/t-uclinux (EXTRA_MULTILIB_PARTS): Add crtbegin.o and crtend.o. * config/m68k/lb1sf68.asm (PICCALL): Use an lea and pc-relative jump sequence for ISA A and ISA A+. (PICJUMP): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120912 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 32 ++++++++++++++++++++++++++++++ gcc/config.gcc | 2 +- gcc/config/flat.h | 23 ++++++++++++++++++++++ gcc/config/m68k/lb1sf68.asm | 10 ++++++++++ gcc/config/m68k/m68k.c | 8 ++++---- gcc/config/m68k/m68k.h | 27 +++++++++++++++++++++++++- gcc/config/m68k/t-uclinux | 6 +++--- gcc/config/m68k/uclinux.h | 47 ++++++++++++++++++++++++++------------------- gcc/crtstuff.c | 4 +++- 9 files changed, 129 insertions(+), 30 deletions(-) create mode 100644 gcc/config/flat.h diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 98ec52bb1ef..3643673af4a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,37 @@ 2007-01-18 Richard Sandiford + * config.gcc (m68k-*-uclinux*): Add flat.h to $tm_file. + * config/flat.h: New file. + * crtstuff.c (USE_PT_GNU_EH_FRAME): Don't define if + OBJECT_FORMAT_FLAT. + * config/m68k/m68k.h (ASM_PREFERRED_EH_DATA_FORMAT): Do not use + indirect references for -msep-data or -mid-shared-library. + Do not use PC-relative code addresses either. + * config/m68k/m68k.c (override_options): Restrict -fPIC error + to -mpcrel. + * config/m68k/uclinux.h (STARTFILE_SPEC): Define. Use Scrt1.o + for shared libraries and crt1.o for executables. Use crti.o and + crtbegin.o. + (ENDFILE_SPEC): Use crtend.o and crtn.o. + (LIB_SPEC): Suppress -Rlibc.gdb if -static-libc is given. + Do not add -elf2flt or -shared-lib-id options here. + (LINK_SPEC): Define. Pass -elf2flt if no -elf2flt option is given. + Pass -shared-lib-id if -mid-shared-library, taking the library + identifier from -mshared-library-id if given, otherwise + defaulting to 0. + (EH_FRAME_IN_DATA_SECTION): Do not undefine. + (INIT_SECTION_ASM_OP, FINI_SECTION_ASM_OP): Likewise. + (TARGET_OS_CPP_BUILTINS): Define __GXX_MERGED_TYPEINFO_NAMES=0 + and __GXX_TYPEINFO_EQUALITY_INLINE=0 if -mid-shared-library. + (DRIVER_SELF_SPECS): Map unadorned PIC options to -msep-data. + * config/m68k/t-uclinux (EXTRA_MULTILIB_PARTS): Add crtbegin.o + and crtend.o. + * config/m68k/lb1sf68.asm (PICCALL): Use an lea and pc-relative + jump sequence for ISA A and ISA A+. + (PICJUMP): Likewise. + +2007-01-18 Richard Sandiford + * config.gcc (m68k-*-uclinux*): Base the port on the common and m68k GNU/Linux files rather than on the generic ELF ones. * config/m68k/uclinux.h (TARGET_VERSION): Override. diff --git a/gcc/config.gcc b/gcc/config.gcc index 6acecd38f76..ecb7fe60b21 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -1523,7 +1523,7 @@ m68k-*-uclinux*) # Motorola m68k/ColdFire running uClinux # with uClibc, using the new GNU/Linux-style # ABI. default_m68k_cpu=68020 - tm_file="m68k/m68k.h dbxelf.h elfos.h svr4.h linux.h m68k/linux.h m68k/uclinux.h" + tm_file="m68k/m68k.h dbxelf.h elfos.h svr4.h linux.h flat.h m68k/linux.h m68k/uclinux.h" tm_defines="${tm_defines} MOTOROLA USE_GAS UCLIBC_DEFAULT=1" extra_options="${extra_options} linux.opt" tmake_file=m68k/t-uclinux diff --git a/gcc/config/flat.h b/gcc/config/flat.h new file mode 100644 index 00000000000..48cffbc872c --- /dev/null +++ b/gcc/config/flat.h @@ -0,0 +1,23 @@ +/* Defines to be used for targets that support flat executables. + Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. */ + +/* This macro applies on top of OBJECT_FORMAT_ELF and indicates that + we want to support both flat and ELF output. */ +#define OBJECT_FORMAT_FLAT diff --git a/gcc/config/m68k/lb1sf68.asm b/gcc/config/m68k/lb1sf68.asm index 716ff059d25..edb907c9356 100644 --- a/gcc/config/m68k/lb1sf68.asm +++ b/gcc/config/m68k/lb1sf68.asm @@ -120,11 +120,21 @@ Boston, MA 02110-1301, USA. */ /* Common for -mid-shared-libary and -msep-data */ .macro PICCALL addr +#if defined (__mcoldfire__) && !defined (__mcfisab__) + lea \addr-.-8,a0 + jsr pc@(a0) +#else bsr \addr +#endif .endm .macro PICJUMP addr +#if defined (__mcoldfire__) && !defined (__mcfisab__) + lea \addr-.-8,a0 + jmp pc@(a0) +#else bra \addr +#endif .endm # if defined(__ID_SHARED_LIBRARY__) diff --git a/gcc/config/m68k/m68k.c b/gcc/config/m68k/m68k.c index edf8a7e204c..057b3256a8d 100644 --- a/gcc/config/m68k/m68k.c +++ b/gcc/config/m68k/m68k.c @@ -519,10 +519,10 @@ override_options (void) if (TARGET_SEP_DATA || TARGET_ID_SHARED_LIBRARY) flag_pic = 2; - /* -fPIC uses 32-bit pc-relative displacements, which don't exist - until the 68020. */ - if (!TARGET_68020 && !TARGET_COLDFIRE && (flag_pic == 2)) - error ("-fPIC is not currently supported on the 68000 or 68010"); + /* -mpcrel -fPIC uses 32-bit pc-relative displacements. Raise an + error if the target does not support them. */ + if (TARGET_PCREL && !TARGET_68020 && flag_pic == 2) + error ("-mpcrel -fPIC is not currently supported on selected cpu"); /* ??? A historic way of turning on pic, or is this intended to be an embedded thing that doesn't have the same name binding diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h index 772943af8d8..7b3a74c4ba3 100644 --- a/gcc/config/m68k/m68k.h +++ b/gcc/config/m68k/m68k.h @@ -1090,9 +1090,34 @@ do { if (cc_prev_status.flags & CC_IN_68881) \ /* Select a format to encode pointers in exception handling data. CODE is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is - true if the symbol may be affected by dynamic relocations. */ + true if the symbol may be affected by dynamic relocations. + + TARGET_ID_SHARED_LIBRARY and TARGET_SEP_DATA are designed to support + a read-only text segment without imposing a fixed gap between the + text and data segments. As a result, the text segment cannot refer + to anything in the data segment, even in PC-relative form. Because + .eh_frame refers to both code and data, it follows that .eh_frame + must be in the data segment itself, and that the offset between + .eh_frame and code will not be a link-time constant. + + In theory, we could create a read-only .eh_frame by using DW_EH_PE_pcrel + | DW_EH_PE_indirect for all code references. However, gcc currently + handles indirect references using a per-TU constant pool. This means + that if a function and its eh_frame are removed by the linker, the + eh_frame's indirect references to the removed function will not be + removed, leading to an unresolved symbol error. + + It isn't clear that any -msep-data or -mid-shared-library target + would benefit from a read-only .eh_frame anyway. In particular, + no known target that supports these options has a feature like + PT_GNU_RELRO. Without any such feature to motivate them, indirect + references would be unnecessary bloat, so we simply use an absolute + pointer for code and global references. We still use pc-relative + references to data, as this avoids a relocation. */ #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ (flag_pic \ + && !((TARGET_ID_SHARED_LIBRARY || TARGET_SEP_DATA) \ + && ((GLOBAL) || (CODE))) \ ? ((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4 \ : DW_EH_PE_absptr) diff --git a/gcc/config/m68k/t-uclinux b/gcc/config/m68k/t-uclinux index 1fb7a42e598..49080429f98 100644 --- a/gcc/config/m68k/t-uclinux +++ b/gcc/config/m68k/t-uclinux @@ -1,3 +1,6 @@ +# crti and crtn are provided by uClibc. +EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o + LIB1ASMSRC = m68k/lb1sf68.asm LIB1ASMFUNCS = _mulsi3 _udivsi3 _divsi3 _umodsi3 _modsi3 \ _double _float _floatex \ @@ -19,6 +22,3 @@ MULTILIB_EXCEPTIONS = m68000/msep-data* m68000/mid-shared-library* msep-data* mi LIBGCC = stmp-multilib INSTALL_LIBGCC = install-multilib - -# We don't use crtbegin.o and crtend.o -EXTRA_MULTILIB_PARTS= diff --git a/gcc/config/m68k/uclinux.h b/gcc/config/m68k/uclinux.h index 2cf0d0761b7..992c465ce10 100644 --- a/gcc/config/m68k/uclinux.h +++ b/gcc/config/m68k/uclinux.h @@ -24,29 +24,27 @@ Boston, MA 02110-1301, USA. */ #undef TARGET_VERSION #define TARGET_VERSION fprintf (stderr, " (68k uClinux)"); -/* Undo the definition of STARTFILE_SPEC from m68kelf.h so we'll - pick the default from gcc.c (just link crt0.o from multilib dir). */ -#undef STARTFILE_SPEC +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ +"%{mshared-library-id=0|!mshared-library-id=*: crt1.o%s ;: Scrt1.o%s} \ + crti.o%s crtbegin.o%s" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "crtend.o%s crtn.o%s" /* Override the default LIB_SPEC from gcc.c. We don't currently support profiling, or libg.a. */ #undef LIB_SPEC -#define LIB_SPEC "\ -%{mid-shared-library:-R libc.gdb%s -elf2flt -shared-lib-id 0} -lc \ -" - -/* we don't want a .eh_frame section. */ -#define EH_FRAME_IN_DATA_SECTION - -/* ??? Quick hack to get constructors working. Make this look more like a - COFF target, so the existing dejagnu/libgloss support works. A better - solution would be to make the necessary dejagnu and libgloss changes so - that we can use normal the ELF constructor mechanism. */ -#undef INIT_SECTION_ASM_OP -#undef FINI_SECTION_ASM_OP -#undef ENDFILE_SPEC -#define ENDFILE_SPEC "" - +#define LIB_SPEC \ +"%{mid-shared-library:%{!static-libc:-R libc.gdb%s}} -lc" + +/* Default to using -elf2flt with no options. */ +#undef LINK_SPEC +#define LINK_SPEC \ +"%{!elf2flt*:-elf2flt} \ + %{mid-shared-library: \ + %{mshared-library-id=*:-shared-lib-id %*;:-shared-lib-id 0}}" + #undef TARGET_OS_CPP_BUILTINS #define TARGET_OS_CPP_BUILTINS() \ do \ @@ -54,7 +52,16 @@ Boston, MA 02110-1301, USA. */ LINUX_TARGET_OS_CPP_BUILTINS (); \ builtin_define ("__uClinux__"); \ if (TARGET_ID_SHARED_LIBRARY) \ - builtin_define ("__ID_SHARED_LIBRARY__"); \ + { \ + builtin_define ("__ID_SHARED_LIBRARY__"); \ + /* Shared libraries and executables do not share \ + typeinfo names. */ \ + builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0"); \ + builtin_define ("__GXX_TYPEINFO_EQUALITY_INLINE=0"); \ + } \ } \ while (0) +/* -msep-data is the default PIC mode on this target. */ +#define DRIVER_SELF_SPECS \ + "%{fpie|fPIE|fpic|fPIC:%{!msep-data:%{!mid-shared-library: -msep-data}}}" diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c index 8fdc021d019..e847ad04760 100644 --- a/gcc/crtstuff.c +++ b/gcc/crtstuff.c @@ -86,7 +86,9 @@ call_ ## FUNC (void) \ } #endif -#if defined(OBJECT_FORMAT_ELF) && defined(HAVE_LD_EH_FRAME_HDR) \ +#if defined(OBJECT_FORMAT_ELF) \ + && !defined(OBJECT_FORMAT_FLAT) \ + && defined(HAVE_LD_EH_FRAME_HDR) \ && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \ && defined(__GLIBC__) && __GLIBC__ >= 2 #include -- 2.11.0