diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7dbed637970a..5db11a576db7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2005-01-15 Marc Espie + + * config.gcc (*-*-openbsd*): Set HAS_LIBC_R for OpenBSD <= 3.2. + (i[34567]86-*-openbsd*): Switch to ELF for OpenBSD >= 3.4. + * config/openbsd.h: Fix C++ includes for native configurations. + Add proper OS_CPP_BUILTINS. Fix libspec for recent OpenBSD. + Add trampoline support. + * config/i386/openbsdelf.h: New. + 2005-01-15 Marc Espie * collect2.c (main): Explicitly parse -dynamic-linker option. diff --git a/gcc/config.gcc b/gcc/config.gcc index 397be8da8217..a295059127a9 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -493,6 +493,10 @@ case ${target} in tmake_file="${tmake_file} t-openbsd-thread" ;; esac + case ${target} in + *-*-openbsd2.*|*-*-openbsd3.[012]) + tm_defines="${tm_defines} HAS_LIBC_R=1" ;; + esac ;; *-*-rtems*) case ${enable_threads} in @@ -930,13 +934,20 @@ i[34567]86-*-netbsd*) x86_64-*-netbsd*) tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/x86-64.h i386/netbsd64.h" ;; -i[34567]86-*-openbsd*) +i[34567]86-*-openbsd2.*|i[34567]86-*openbsd3.[0123]) tm_file="i386/i386.h i386/unix.h i386/bsd.h i386/gas.h i386/gstabs.h openbsd-oldgas.h openbsd.h i386/openbsd.h" # needed to unconfuse gdb tmake_file="t-libc-ok t-openbsd i386/t-openbsd" # we need collect2 until our bug is fixed... use_collect2=yes ;; +i[34567]86-*-openbsd*) + tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h i386/i386elf.h" + tm_file="${tm_file} openbsd.h i386/openbsdelf.h" + gas=yes + gnu_ld=yes + stabs=yes + ;; i[34567]86-*-coff*) tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h i386/i386-coff.h" use_fixproto=yes diff --git a/gcc/config/i386/openbsdelf.h b/gcc/config/i386/openbsdelf.h new file mode 100644 index 000000000000..3088e849a350 --- /dev/null +++ b/gcc/config/i386/openbsdelf.h @@ -0,0 +1,130 @@ +/* Configuration for an OpenBSD i386 target. + + Copyright (C) 2005 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. */ + +/* This gets defined in tm.h->linux.h->svr4.h, and keeps us from using + libraries compiled with the native cc, so undef it. */ +#undef NO_DOLLAR_IN_LABEL + +/* Override the default comment-starter of "/". */ +#undef ASM_COMMENT_START +#define ASM_COMMENT_START "#" + + +/* This goes away when the math-emulator is fixed */ +#undef TARGET_DEFAULT +#define TARGET_DEFAULT \ + (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_NO_FANCY_MATH_387) + +/* Run-time target specifications */ + +#define TARGET_OS_CPP_BUILTINS() \ + do \ + { \ + OPENBSD_OS_CPP_BUILTINS_ELF(); \ + } \ + while (0) + +/* As an elf system, we need crtbegin/crtend stuff. */ +#undef STARTFILE_SPEC +#define STARTFILE_SPEC "\ + %{!shared: %{pg:gcrt0%O%s} %{!pg:%{p:gcrt0%O%s} %{!p:crt0%O%s}} \ + crtbegin%O%s} %{shared:crtbeginS%O%s}" +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}" + +/* Layout of source language data types. */ + +/* This must agree with */ +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "int" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_WORD + +/* Assembler format: overall framework. */ + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +#undef SET_ASM_OP +#define SET_ASM_OP "\t.set\t" + +/* The following macros were originally stolen from i386v4.h. + These have to be defined to get PIC code correct. */ + +/* Assembler format: dispatch tables. */ + +/* Assembler format: sections. */ + +/* Stack & calling: aggregate returns. */ + +/* Don't default to pcc-struct-return, because gcc is the only compiler, and + we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 + +/* Assembler format: alignment output. */ + +#ifdef HAVE_GAS_MAX_SKIP_P2ALIGN +#define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE,LOG,MAX_SKIP) \ + if ((LOG) != 0) {\ + if ((MAX_SKIP) == 0) fprintf ((FILE), "\t.p2align %d\n", (LOG)); \ + else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP)); \ + } +#endif + +/* Stack & calling: profiling. */ + +/* OpenBSD's profiler recovers all information from the stack pointer. + The icky part is not here, but in machine/profile.h. */ +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ + fputs (flag_pic ? "\tcall __mcount@PLT\n": "\tcall __mcount\n", FILE); + +/* Assembler format: exception region output. */ + +/* our configuration still doesn't handle dwarf2 correctly */ +#define DWARF2_UNWIND_INFO 0 + +/* Assembler format: alignment output. */ + +/* Note that we pick up ASM_OUTPUT_MAX_SKIP_ALIGN from i386/gas.h */ + +/* Note that we pick up ASM_OUTPUT_MI_THUNK from unix.h. */ + +#undef LINK_SPEC +#define LINK_SPEC \ + "%{!shared:%{!nostdlib:%{!r*:%{!e*:-e __start}}}} \ + %{shared:-shared} %{R*} \ + %{static:-Bstatic} \ + %{!static:-Bdynamic} \ + %{assert*} \ + %{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}" + +#define OBSD_HAS_CORRECT_SPECS diff --git a/gcc/config/openbsd.h b/gcc/config/openbsd.h index bf1349bfbd34..f836cf9b4afa 100644 --- a/gcc/config/openbsd.h +++ b/gcc/config/openbsd.h @@ -1,5 +1,5 @@ /* Base configuration file for all OpenBSD targets. - Copyright (C) 1999, 2000, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2004, 2005 Free Software Foundation, Inc. This file is part of GCC. @@ -52,29 +52,41 @@ Boston, MA 02111-1307, USA. */ #ifdef OPENBSD_NATIVE -#undef GCC_INCLUDE_DIR -#define GCC_INCLUDE_DIR "/usr/include" - /* The compiler is configured with ONLY the gcc/g++ standard headers. */ #undef INCLUDE_DEFAULTS #define INCLUDE_DEFAULTS \ { \ { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 }, \ - { GCC_INCLUDE_DIR, "GCC", 0, 0 }, \ + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1 }, \ + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1 }, \ + { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 }, \ { 0, 0, 0, 0 } \ } /* Under OpenBSD, the normal location of the various *crt*.o files is the /usr/lib directory. */ -#define STANDARD_STARTFILE_PREFIX "/usr/lib/" +#undef STANDARD_STARTFILE_PREFIX +#define STANDARD_STARTFILE_PREFIX "/usr/local/lib/" #endif /* Controlling the compilation driver. */ +/* TARGET_OS_CPP_BUILTINS() common to all OpenBSD targets. */ +#define OPENBSD_OS_CPP_BUILTINS() \ + do \ + { \ + builtin_define ("__OpenBSD__"); \ + builtin_define ("__unix__"); \ + builtin_define ("__ANSI_COMPAT"); \ + builtin_assert ("system=unix"); \ + builtin_assert ("system=bsd"); \ + builtin_assert ("system=OpenBSD"); \ + } \ + while (0) /* CPP_SPEC appropriate for OpenBSD. We deal with -posix and -pthread. - XXX the way threads are handling currently is not very satisfying, + XXX the way threads are handled currently is not very satisfying, since all code must be compiled with -pthread to work. This two-stage defines makes it easy to pick that for targets that have subspecs. */ @@ -84,10 +96,15 @@ Boston, MA 02111-1307, USA. */ #define OBSD_CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}" #endif -/* LIB_SPEC appropriate for OpenBSD. Select the appropriate libc, - depending on profiling and threads. Basically, - -lc(_r)?(_p)?, select _r for threads, and _p for p or pg. */ -#define OBSD_LIB_SPEC "%{!shared:-lc%{pthread:_r}%{p:_p}%{!p:%{pg:_p}}}" +/* LIB_SPEC appropriate for OpenBSD. */ +#ifdef HAS_LIBC_R +/* -lc(_r)?(_p)?, select _r for threads, and _p for p or pg. */ +# define OBSD_LIB_SPEC "%{!shared:-lc%{pthread:_r}%{p:_p}%{!p:%{pg:_p}}}" +#else +/* Include -lpthread if -pthread is specified on the command line. */ +# define OBSD_LIB_SPEC "%{!shared:%{pthread:-lpthread%{p:_p}%{!p:%{pg:_p}}}} %{!shared:-lc%{p:_p}%{!p:%{pg:_p}}}" +#endif + #ifndef OBSD_HAS_CORRECT_SPECS @@ -275,3 +292,20 @@ do { \ as this depends on a few other details as well... */ #define HANDLE_SYSV_PRAGMA 1 +/* Stack is explicitly denied execution rights on OpenBSD platforms. */ +#define ENABLE_EXECUTE_STACK \ +extern void __enable_execute_stack (void *); \ +void \ +__enable_execute_stack (void *addr) \ +{ \ + long size = getpagesize (); \ + long mask = ~(size-1); \ + char *page = (char *) (((long) addr) & mask); \ + char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \ + \ + if (mprotect (page, end - page, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) \ + perror ("mprotect of trampoline code"); \ +} + +#include +#include