This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Let gcc bootstrap again on OpenBSD
- From: Marc Espie <espie at nerim dot net>
- To: gcc-patches at gcc dot gnu dot org
- Cc: gerald at pfeifer dot com, dewar at adacore dot com,gdr at integrable-solutions dot net, mark at codesourcery dot com,pinskia at physics dot uc dot edu
- Date: Sat, 8 Jan 2005 16:58:47 +0100
- Subject: [PATCH] Let gcc bootstrap again on OpenBSD
- Reply-to: espie at nerim dot net
Long-timers know I've had trouble keeping up with GCC development.
Well, I finally found time to sit down and fix the most glaring issues
in -current GCC.
I don't know what's the exact status on 4.0 (branch, devel ?)
In any case, this does:
- allow GCC to boostrap on a recent OpenBSD i386 system.
- take recent changes into account (e.g., work properly before i386
switched to ELF, work properly before libpthread).
- doesn't disturb other architectures (sparc64 still bootstraps).
- restore trampoline functionality (ada runs)
What to do ? Can I commit this, or are there still loops I need to jump
through ?
My goal here is to restore decent support for OpenBSD in GCC...
If this can get in, I can then produce the corresponding patches for 3.3.*
and 3.4.*
Together with Mark Kettenis, we've been working on correct unwind support,
but I've been a lazy bum, and I haven't spent the time to check whether
it works on gcc 4.0 or not.
2005-01-08 Marc Espie <espie@openbsd.org>
* 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.
*** gcc/config.gcc.orig Wed Dec 22 09:41:31 2004
--- gcc/config.gcc Fri Jan 7 14:37:09 2005
*************** case ${target} in
*** 493,498 ****
--- 493,502 ----
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
*************** i[34567]86-*-netbsd*)
*** 930,941 ****
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*)
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-*-coff*)
tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h i386/i386-coff.h"
--- 934,952 ----
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-*-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"
*** gcc/config/openbsd.h.orig Sun Oct 24 03:42:48 2004
--- gcc/config/openbsd.h Fri Jan 7 13:31:19 2005
*************** Boston, MA 02111-1307, USA. */
*** 52,80 ****
#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 }, \
{ 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/"
#endif
/* Controlling the compilation driver. */
/* CPP_SPEC appropriate for OpenBSD. We deal with -posix and -pthread.
! XXX the way threads are handling 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. */
--- 52,111 ----
#ifdef OPENBSD_NATIVE
/* The compiler is configured with ONLY the gcc/g++ standard headers. */
#undef INCLUDE_DEFAULTS
#define INCLUDE_DEFAULTS \
{ \
{ GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 }, \
! { 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. */
! #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_COMMON() \
+ 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)
+ /* TARGET_OS_CPP_BUILTINS() common to all OpenBSD ELF targets. */
+ #define OPENBSD_OS_CPP_BUILTINS_ELF() \
+ do \
+ { \
+ OPENBSD_OS_CPP_BUILTINS_COMMON(); \
+ builtin_define ("__ELF__"); \
+ } \
+ while (0)
+
+ /* TARGET_OS_CPP_BUILTINS() common to all LP64 OpenBSD targets. */
+ #define OPENBSD_OS_CPP_BUILTINS_LP64() \
+ do \
+ { \
+ builtin_define ("_LP64"); \
+ builtin_define ("__LP64__"); \
+ } \
+ while (0)
+
+
/* CPP_SPEC appropriate for OpenBSD. We deal with -posix and -pthread.
! 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. */
*************** Boston, MA 02111-1307, USA. */
*** 84,94 ****
#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}}}"
#ifndef OBSD_HAS_CORRECT_SPECS
#ifndef OBSD_NO_DYNAMIC_LIBRARIES
--- 115,130 ----
#define OBSD_CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}"
#endif
! /* 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
#ifndef OBSD_NO_DYNAMIC_LIBRARIES
*************** do { \
*** 275,277 ****
--- 311,331 ----
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 (addr) \
+ 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 <sys/types.h>
+ #include <sys/mman.h>
*** gcc/config/i386/openbsdelf.h.orig Fri Jan 7 13:31:18 2005
--- gcc/config/i386/openbsdelf.h Fri Jan 7 13:31:18 2005
***************
*** 0 ****
--- 1,131 ----
+
+ /* Configuration for an OpenBSD i386 target.
+
+ Copyright (C) 1999 Free Software Foundation, Inc.
+
+ 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. */
+
+ /* 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 <machine/ansi.h> */
+ #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