190075Sobrien/* Base configuration file for all FreeBSD targets.
2169706Skan   Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
390075Sobrien
4132737SkanThis file is part of GCC.
590075Sobrien
6132737SkanGCC is free software; you can redistribute it and/or modify
790075Sobrienit under the terms of the GNU General Public License as published by
890075Sobrienthe Free Software Foundation; either version 2, or (at your option)
990075Sobrienany later version.
1090075Sobrien
11132737SkanGCC is distributed in the hope that it will be useful,
1290075Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1390075SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1490075SobrienGNU General Public License for more details.
1590075Sobrien
1690075SobrienYou should have received a copy of the GNU General Public License
17132737Skanalong with GCC; see the file COPYING.  If not, write to
18169706Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
19169706SkanBoston, MA 02110-1301, USA.  */
2090075Sobrien
2196362Sobrien/* $FreeBSD$ */
2296362Sobrien
2390075Sobrien/* Common FreeBSD configuration.
2490075Sobrien   All FreeBSD architectures should include this file, which will specify
2590075Sobrien   their commonalities.
2690075Sobrien   Adapted from gcc/config/freebsd.h by
2790075Sobrien   David O'Brien <obrien@FreeBSD.org>
2890075Sobrien   Loren J. Rittle <ljrittle@acm.org>.  */
2990075Sobrien
3090075Sobrien
3190075Sobrien/* In case we need to know.  */
3290075Sobrien#define USING_CONFIG_FREEBSD_SPEC 1
3390075Sobrien
3490075Sobrien/* This defines which switch letters take arguments.  On FreeBSD, most of
3590075Sobrien   the normal cases (defined in gcc.c) apply, and we also have -h* and
3690075Sobrien   -z* options (for the linker) (coming from SVR4).
3790075Sobrien   We also have -R (alias --rpath), no -z, --soname (-h), --assert etc.  */
3890075Sobrien
3990075Sobrien#define FBSD_SWITCH_TAKES_ARG(CHAR)					\
4090075Sobrien  (DEFAULT_SWITCH_TAKES_ARG (CHAR)					\
4190075Sobrien    || (CHAR) == 'h'							\
4290075Sobrien    || (CHAR) == 'z' /* ignored by ld */				\
4390075Sobrien    || (CHAR) == 'R')
4490075Sobrien
4590075Sobrien/* This defines which multi-letter switches take arguments.  */
4690075Sobrien
4790075Sobrien#define FBSD_WORD_SWITCH_TAKES_ARG(STR)					\
4890075Sobrien  (DEFAULT_WORD_SWITCH_TAKES_ARG (STR)					\
4990075Sobrien   || !strcmp ((STR), "rpath") || !strcmp ((STR), "rpath-link")		\
5090075Sobrien   || !strcmp ((STR), "soname") || !strcmp ((STR), "defsym") 		\
5190075Sobrien   || !strcmp ((STR), "assert") || !strcmp ((STR), "dynamic-linker"))
5290075Sobrien
53117420Skan#define FBSD_TARGET_OS_CPP_BUILTINS()					\
54117420Skan  do									\
55117420Skan    {									\
56151775Srodrigc	builtin_define_with_int_value ("__FreeBSD__", FBSD_MAJOR);	\
57117420Skan	builtin_define_std ("unix");					\
58182644Sobrien	builtin_define_std ("__unix__");				\
59182644Sobrien	builtin_define ("__KPRINTF_ATTRIBUTE__");			\
60117420Skan	builtin_assert ("system=unix");					\
61117420Skan	builtin_assert ("system=bsd");					\
62117420Skan	builtin_assert ("system=FreeBSD");				\
63117420Skan	FBSD_NATIVE_TARGET_OS_CPP_BUILTINS();				\
64117420Skan	FBSD_TARGET_CPU_CPP_BUILTINS();					\
65117420Skan    }									\
66117420Skan  while (0)
6796362Sobrien
68169706Skan/* Define the default FreeBSD-specific per-CPU hook code.  */
69117420Skan#define FBSD_TARGET_CPU_CPP_BUILTINS() do {} while (0)
7096362Sobrien
71117420Skan#ifdef FREEBSD_NATIVE
72117420Skan#define FBSD_NATIVE_TARGET_OS_CPP_BUILTINS()				\
73117420Skan  do {									\
74151887Sobrien	builtin_define_with_int_value ("__FreeBSD_cc_version", FBSD_CC_VER); \
75117420Skan  } while (0)
76117420Skan#else
77117420Skan#define FBSD_NATIVE_TARGET_OS_CPP_BUILTINS()				\
78117420Skan  do {} while (0)
7990075Sobrien#endif
8090075Sobrien
81169706Skan/* Provide a CPP_SPEC appropriate for FreeBSD.  We just deal with the GCC
82103258Sobrien   option `-posix', and PIC issues.  Try to detect support for the
83103258Sobrien   `long long' type.  Unfortunately the GCC spec parser will not allow us
84103258Sobrien   to properly detect the "iso9899:1990" and "iso9899:199409" forms of
85103258Sobrien   -std=c89.  Because of the ':' in the -std argument. :-(  I have left
86103258Sobrien   them in the spec as a place holder in hopes someone knows a way to make
87103258Sobrien   the detection of them work.  */
8890075Sobrien
8990075Sobrien#define FBSD_CPP_SPEC "							\
9090075Sobrien  %(cpp_cpu)								\
91169706Skan  %(cpp_arch)								\
92103258Sobrien  %{!ansi:%{!std=c89:%{!std=iso9899.1990:%{!std=iso9899.199409:-D_LONGLONG}}}} \
9390075Sobrien  %{posix:-D_POSIX_SOURCE}"
9490075Sobrien
95119414Sobrien/* Provide a STARTFILE_SPEC appropriate for FreeBSD.  Here we add the magical
96119414Sobrien   crtbegin.o file (see crtstuff.c) which provides part of the support for
97119414Sobrien   getting C++ file-scope static object constructed before entering `main'.  */
98169706Skan
99119414Sobrien#define FBSD_STARTFILE_SPEC "\
100119414Sobrien  %{!shared: \
101119414Sobrien    %{pg:gcrt1.o%s} \
102119414Sobrien    %{!pg: \
103119414Sobrien      %{p:gcrt1.o%s} \
104119414Sobrien      %{!p: \
105119414Sobrien	%{profile:gcrt1.o%s} \
106200038Skib	%{!profile: \
107200038Skib          %{pie: Scrt1.o%s;:crt1.o%s}}}}} \
108119414Sobrien  crti.o%s \
109200038Skib  %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
11090075Sobrien
111119414Sobrien/* Provide an ENDFILE_SPEC appropriate for FreeBSD/i386.  Here we tack on
112119414Sobrien   our own magical crtend.o file (see crtstuff.c) which provides part of
113119414Sobrien   the support for getting C++ file-scope static object constructed before
114119414Sobrien   entering `main', followed by the normal "finalizer" file, `crtn.o'.  */
11590075Sobrien
116119414Sobrien#define FBSD_ENDFILE_SPEC "\
117200038Skib  %{shared|pie:crtendS.o%s;:crtend.o%s} \
118119414Sobrien  crtn.o%s "
11990075Sobrien
120119642Sdeischen/* Provide a LIB_SPEC appropriate for FreeBSD as configured and as
121119642Sdeischen   required by the user-land thread model.  Before __FreeBSD_version
122119642Sdeischen   500016, select the appropriate libc, depending on whether we're
123119642Sdeischen   doing profiling or need threads support.  At __FreeBSD_version
124146908Skan   500016 and later, when threads support is requested include both
125146908Skan   -lc and the threading lib instead of only -lc_r.  To make matters
126146908Skan   interesting, we can't actually use __FreeBSD_version provided by
127146908Skan   <osreldate.h> directly since it breaks cross-compiling.  As a final
128146908Skan   twist, make it a hard error if -pthread is provided on the command
129146908Skan   line and gcc was configured with --disable-threads (this will help
130146908Skan   avoid bug reports from users complaining about threading when they
131146908Skan   misconfigured the gcc bootstrap but are later consulting FreeBSD
132146908Skan   manual pages that refer to the mythical -pthread option).  */
133119642Sdeischen
13490075Sobrien/* Provide a LIB_SPEC appropriate for FreeBSD.  Just select the appropriate
135119642Sdeischen   libc, depending on whether we're doing profiling or need threads support.
136169706Skan   (similar to the default, except no -lg, and no -p).  */
13790075Sobrien
138119642Sdeischen#ifdef FBSD_NO_THREADS
13990075Sobrien#define FBSD_LIB_SPEC "							\
140119642Sdeischen  %{pthread: %eThe -pthread option is only supported on FreeBSD when gcc \
141119642Sdeischenis built with the --enable-threads configure-time option.}		\
14290075Sobrien  %{!shared:								\
14390075Sobrien    %{!pg: -lc}								\
14490075Sobrien    %{pg:  -lc_p}							\
14590075Sobrien  }"
146119642Sdeischen#else
147119642Sdeischen#include <sys/param.h>
148146908Skan#if __FreeBSD_version < 500016
149119642Sdeischen#define FBSD_LIB_SPEC "							\
150119642Sdeischen  %{!shared:								\
151119642Sdeischen    %{!pg:								\
152119642Sdeischen      %{!pthread:-lc}							\
153119642Sdeischen      %{pthread:-lc_r}}							\
154119642Sdeischen    %{pg:								\
155119642Sdeischen      %{!pthread:-lc_p}							\
156119642Sdeischen      %{pthread:-lc_r_p}}						\
157119642Sdeischen  }"
158169706Skan#elif __FreeBSD_version < 700022
159146908Skan#define FBSD_LIB_SPEC "							\
160146908Skan  %{!shared:								\
161146908Skan    %{!pg: %{pthread:-lpthread} -lc}					\
162146908Skan    %{pg:  %{pthread:-lpthread_p} -lc_p}				\
163146908Skan  }"
164169706Skan#else
165169706Skan#define FBSD_LIB_SPEC "							\
166169706Skan  %{!shared:								\
167169706Skan    %{!pg: %{pthread:-lpthread} -lc}					\
168169706Skan    %{pg:  %{pthread:-lpthread_p} -lc_p}}				\
169169706Skan  %{shared:								\
170169706Skan    %{pthread:-lpthread} -lc}						\
171195697Skan  %{fstack-protector|fstack-protector-all:-lssp_nonshared}		\
172169706Skan  "
173119642Sdeischen#endif
174119642Sdeischen#endif
175132737Skan
176132737Skan#if FBSD_MAJOR < 5
177132737Skan#define FBSD_DYNAMIC_LINKER "/usr/libexec/ld-elf.so.1"
178132737Skan#else
179132737Skan#define FBSD_DYNAMIC_LINKER "/libexec/ld-elf.so.1"
180132737Skan#endif
181169706Skan
182169706Skan#if defined(HAVE_LD_EH_FRAME_HDR)
183169706Skan#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
184169706Skan#endif
185169706Skan
186169706Skan/* Use --as-needed -lgcc_s for eh support.  */
187169706Skan#ifdef HAVE_LD_AS_NEEDED
188169706Skan#define USE_LD_AS_NEEDED 1
189169706Skan#endif
190182627Sobrien
191182627Sobrien#define FBSD_SIZE_TYPE \
192182627Sobrien	(POINTER_SIZE == 64 ? "long unsigned int" : "unsigned int")
193182627Sobrien#define FBSD_PTRDIFF_TYPE \
194182627Sobrien	(POINTER_SIZE == 64 ? "long int" : "int")
195