1117395Skan/* Base configuration file for all NetBSD targets.
2169689Skan   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3117395Skan   Free Software Foundation, Inc.
4117395Skan
5132718SkanThis file is part of GCC.
6117395Skan
7132718SkanGCC is free software; you can redistribute it and/or modify
8117395Skanit under the terms of the GNU General Public License as published by
9117395Skanthe Free Software Foundation; either version 2, or (at your option)
10117395Skanany later version.
11117395Skan
12132718SkanGCC is distributed in the hope that it will be useful,
13117395Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
14117395SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15117395SkanGNU General Public License for more details.
16117395Skan
17117395SkanYou should have received a copy of the GNU General Public License
18132718Skanalong with GCC; see the file COPYING.  If not, write to
19169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
20169689SkanBoston, MA 02110-1301, USA.  */
21117395Skan
22117395Skan/* TARGET_OS_CPP_BUILTINS() common to all NetBSD targets.  */
23117395Skan#define NETBSD_OS_CPP_BUILTINS_COMMON()		\
24117395Skan  do						\
25117395Skan    {						\
26117395Skan      builtin_define ("__NetBSD__");		\
27169689Skan      builtin_define ("__unix__");		\
28169689Skan      builtin_assert ("system=bsd");		\
29117395Skan      builtin_assert ("system=unix");		\
30117395Skan      builtin_assert ("system=NetBSD");		\
31117395Skan    }						\
32117395Skan  while (0)
33117395Skan
34117395Skan/* CPP_SPEC parts common to all NetBSD targets.  */
35117395Skan#define NETBSD_CPP_SPEC				\
36117395Skan  "%{posix:-D_POSIX_SOURCE} \
37117395Skan   %{pthread:-D_REENTRANT -D_PTHREADS}"
38117395Skan
3918334Speter/* NETBSD_NATIVE is defined when gcc is integrated into the NetBSD
4018334Speter   source tree so it can be configured appropriately without using
41117395Skan   the GNU configure/build mechanism.  */
4218334Speter
4318334Speter#ifdef NETBSD_NATIVE
4418334Speter
4518334Speter/* Look for the include files in the system-defined places.  */
4618334Speter
4718334Speter#undef GPLUSPLUS_INCLUDE_DIR
4818334Speter#define GPLUSPLUS_INCLUDE_DIR "/usr/include/g++"
4918334Speter
5018334Speter#undef GCC_INCLUDE_DIR
5118334Speter#define GCC_INCLUDE_DIR "/usr/include"
5218334Speter
5318334Speter#undef INCLUDE_DEFAULTS
5450397Sobrien#define INCLUDE_DEFAULTS			\
5550397Sobrien  {						\
5650397Sobrien    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },	\
5750397Sobrien    { GCC_INCLUDE_DIR, "GCC", 0, 0 },		\
5850397Sobrien    { 0, 0, 0, 0 }				\
5918334Speter  }
6018334Speter
6118334Speter/* Under NetBSD, the normal location of the compiler back ends is the
6218334Speter   /usr/libexec directory.  */
6318334Speter
6418334Speter#undef STANDARD_EXEC_PREFIX
6518334Speter#define STANDARD_EXEC_PREFIX		"/usr/libexec/"
6618334Speter
6718334Speter/* Under NetBSD, the normal location of the various *crt*.o files is the
6818334Speter   /usr/lib directory.  */
6918334Speter
7018334Speter#undef STANDARD_STARTFILE_PREFIX
7118334Speter#define STANDARD_STARTFILE_PREFIX	"/usr/lib/"
7218334Speter
7390075Sobrien#endif /* NETBSD_NATIVE */
7418334Speter
7518334Speter
76117395Skan/* Provide a LIB_SPEC appropriate for NetBSD.  Here we:
7718334Speter
78117395Skan   1. Select the appropriate set of libs, depending on whether we're
79117395Skan      profiling.
8018334Speter
81117395Skan   2. Include the pthread library if -pthread is specified (only
82117395Skan      if threads are enabled).
8318334Speter
84117395Skan   3. Include the posix library if -posix is specified.
8518334Speter
86117395Skan   FIXME: Could eliminate the duplication here if we were allowed to
87117395Skan   use string concatenation.  */
88117395Skan
89117395Skan#ifdef NETBSD_ENABLE_PTHREADS
90117395Skan#define NETBSD_LIB_SPEC		\
91117395Skan  "%{pthread:			\
92117395Skan     %{!p:			\
93117395Skan       %{!pg:-lpthread}}	\
94117395Skan     %{p:-lpthread_p}		\
95117395Skan     %{pg:-lpthread_p}}		\
96117395Skan   %{posix:			\
97117395Skan     %{!p:			\
98117395Skan       %{!pg:-lposix}}		\
99117395Skan     %{p:-lposix_p}		\
100117395Skan     %{pg:-lposix_p}}		\
101117395Skan   %{!shared:			\
102117395Skan     %{!symbolic:		\
103117395Skan       %{!p:			\
104117395Skan	 %{!pg:-lc}}		\
105117395Skan       %{p:-lc_p}		\
106117395Skan       %{pg:-lc_p}}}"
107117395Skan#else
108117395Skan#define NETBSD_LIB_SPEC		\
10990075Sobrien  "%{posix:			\
11090075Sobrien     %{!p:			\
11190075Sobrien       %{!pg:-lposix}}		\
11290075Sobrien     %{p:-lposix_p}		\
11390075Sobrien     %{pg:-lposix_p}}		\
11490075Sobrien   %{!shared:			\
11590075Sobrien     %{!symbolic:		\
11690075Sobrien       %{!p:			\
11790075Sobrien	 %{!pg:-lc}}		\
11890075Sobrien       %{p:-lc_p}		\
11990075Sobrien       %{pg:-lc_p}}}"
120117395Skan#endif
12118334Speter
122117395Skan#undef LIB_SPEC
123117395Skan#define LIB_SPEC NETBSD_LIB_SPEC
124117395Skan
12590075Sobrien/* Provide a LIBGCC_SPEC appropriate for NetBSD.  We also want to exclude
12690075Sobrien   libgcc with -symbolic.  */
12718334Speter
12890075Sobrien#ifdef NETBSD_NATIVE
129117395Skan#define NETBSD_LIBGCC_SPEC	\
13090075Sobrien  "%{!symbolic:			\
13190075Sobrien     %{!shared:			\
13290075Sobrien       %{!p:			\
133117395Skan	 %{!pg: -lgcc}}}	\
13490075Sobrien     %{shared: -lgcc_pic}	\
13590075Sobrien     %{p: -lgcc_p}		\
13690075Sobrien     %{pg: -lgcc_p}}"
13790075Sobrien#else
138117395Skan#define NETBSD_LIBGCC_SPEC "%{!shared:%{!symbolic: -lgcc}}"
13918334Speter#endif
14018334Speter
141117395Skan#undef LIBGCC_SPEC
142117395Skan#define LIBGCC_SPEC NETBSD_LIBGCC_SPEC
143117395Skan
14490075Sobrien/* When building shared libraries, the initialization and finalization
14590075Sobrien   functions for the library are .init and .fini respectively.  */
14618334Speter
14790075Sobrien#define COLLECT_SHARED_INIT_FUNC(STREAM,FUNC)				\
14818334Speter  do {									\
14990075Sobrien    fprintf ((STREAM), "void __init() __asm__ (\".init\");");		\
15090075Sobrien    fprintf ((STREAM), "void __init() {\n\t%s();\n}\n", (FUNC));	\
15118334Speter  } while (0)
15218334Speter
15390075Sobrien#define COLLECT_SHARED_FINI_FUNC(STREAM,FUNC)				\
15418334Speter  do {									\
15590075Sobrien    fprintf ((STREAM), "void __fini() __asm__ (\".fini\");");		\
15690075Sobrien    fprintf ((STREAM), "void __fini() {\n\t%s();\n}\n", (FUNC));	\
15718334Speter  } while (0)
15818334Speter
159169689Skan#undef TARGET_POSIX_IO
160169689Skan#define TARGET_POSIX_IO
16118334Speter
16290075Sobrien/* Handle #pragma weak and #pragma pack.  */
16390075Sobrien
164117395Skan#define HANDLE_SYSV_PRAGMA 1
16596263Sobrien
166169689Skan/* Don't assume anything about the header files.  */
167169689Skan#undef  NO_IMPLICIT_EXTERN_C
168169689Skan#define NO_IMPLICIT_EXTERN_C    1
16996263Sobrien
17096263Sobrien/* Define some types that are the same on all NetBSD platforms,
17196263Sobrien   making them agree with <machine/ansi.h>.  */
17296263Sobrien
17396263Sobrien#undef WCHAR_TYPE
17496263Sobrien#define WCHAR_TYPE "int"
17596263Sobrien
17696263Sobrien#undef WCHAR_TYPE_SIZE
17796263Sobrien#define WCHAR_TYPE_SIZE 32
17896263Sobrien
17996263Sobrien#undef WINT_TYPE
18096263Sobrien#define WINT_TYPE "int"
181117395Skan
182117395Skan
183117395Skan/* Attempt to turn on execute permission for the stack.  This may be
184132718Skan   used by INITIALIZE_TRAMPOLINE of the target needs it (that is,
185117395Skan   if the target machine can change execute permissions on a page).
186117395Skan
187117395Skan   There is no way to query the execute permission of the stack, so
188117395Skan   we always issue the mprotect() call.
189117395Skan
190117395Skan   Note that we go out of our way to use namespace-non-invasive calls
191117395Skan   here.  Unfortunately, there is no libc-internal name for mprotect().
192117395Skan
193117395Skan   Also note that no errors should be emitted by this code; it is considered
194117395Skan   dangerous for library calls to send messages to stdout/stderr.  */
195117395Skan
196117395Skan#define NETBSD_ENABLE_EXECUTE_STACK					\
197117395Skanextern void __enable_execute_stack (void *);				\
198117395Skanvoid									\
199132718Skan__enable_execute_stack (void *addr)					\
200117395Skan{									\
201117395Skan  extern int mprotect (void *, size_t, int);				\
202117395Skan  extern int __sysctl (int *, unsigned int, void *, size_t *,		\
203117395Skan		       void *, size_t);					\
204117395Skan									\
205117395Skan  static int size;							\
206117395Skan  static long mask;							\
207117395Skan									\
208117395Skan  char *page, *end;							\
209117395Skan									\
210117395Skan  if (size == 0)							\
211117395Skan    {									\
212117395Skan      int mib[2];							\
213117395Skan      size_t len;							\
214117395Skan									\
215117395Skan      mib[0] = 6; /* CTL_HW */						\
216117395Skan      mib[1] = 7; /* HW_PAGESIZE */					\
217117395Skan      len = sizeof (size);						\
218117395Skan      (void) __sysctl (mib, 2, &size, &len, NULL, 0);			\
219117395Skan      mask = ~((long) size - 1);					\
220117395Skan    }									\
221117395Skan									\
222117395Skan  page = (char *) (((long) addr) & mask);				\
223117395Skan  end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size);	\
224117395Skan									\
225117395Skan  /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */				\
226117395Skan  (void) mprotect (page, end - page, 7);				\
227117395Skan}
228