xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/sparc/netbsd-elf.h (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
1 /* Definitions of target machine for GCC, for ELF on NetBSD/sparc
2    and NetBSD/sparc64.
3    Copyright (C) 2002-2020 Free Software Foundation, Inc.
4    Contributed by Matthew Green (mrg@eterna.com.au).
5 
6 This file is part of GCC.
7 
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12 
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21 
22 #define TARGET_OS_CPP_BUILTINS()			\
23   do							\
24     {							\
25       NETBSD_OS_CPP_BUILTINS_ELF();			\
26       if (TARGET_ARCH64)				\
27 	{						\
28 	  builtin_define ("__sparc64__");		\
29 	  builtin_define ("__sparc_v9__");		\
30 	  builtin_define ("__sparcv9");			\
31 	}						\
32       else						\
33 	builtin_define ("__sparc");			\
34       builtin_define ("__sparc__");			\
35     }							\
36   while (0)
37 
38 /* CPP defines used by all NetBSD targets.  */
39 #undef CPP_SUBTARGET_SPEC
40 #define CPP_SUBTARGET_SPEC "%(netbsd_cpp_spec)"
41 
42 /* SIZE_TYPE and PTRDIFF_TYPE are wrong from sparc/sparc.h.  */
43 #undef SIZE_TYPE
44 #define SIZE_TYPE "long unsigned int"
45 
46 #undef PTRDIFF_TYPE
47 #define PTRDIFF_TYPE "long int"
48 
49 /* we keep these "long" on both 32bit and 64bit targets */
50 #undef INTPTR_TYPE
51 #define INTPTR_TYPE PTRDIFF_TYPE
52 
53 #undef UINTPTR_TYPE
54 #define UINTPTR_TYPE SIZE_TYPE
55 
56 #undef INT_FAST8_TYPE
57 #define INT_FAST8_TYPE   (LONG_TYPE_SIZE == 64 ? "long int" : "int")
58 
59 #undef UINT_FAST8_TYPE
60 #define UINT_FAST8_TYPE  (LONG_TYPE_SIZE == 64 ? "unsigned char" : "unsigned int")
61 
62 #undef INT_FAST16_TYPE
63 #define INT_FAST16_TYPE  (LONG_TYPE_SIZE == 64 ? "long int" : "int")
64 
65 #undef UINT_FAST16_TYPE
66 #define UINT_FAST16_TYPE (LONG_TYPE_SIZE == 64 ? "short unsigned int" : "unsigned int")
67 
68 #undef INT_FAST32_TYPE
69 #define INT_FAST32_TYPE  (LONG_TYPE_SIZE == 64 ? "long int" : "int")
70 
71 #undef UINT_FAST32_TYPE
72 #define UINT_FAST32_TYPE "unsigned int"
73 
74 #undef INT_FAST64_TYPE
75 #define INT_FAST64_TYPE  (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
76 
77 #undef UINT_FAST64_TYPE
78 #define UINT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
79 
80 /* This is the char to use for continuation (in case we need to turn
81    continuation back on).  */
82 #undef DBX_CONTIN_CHAR
83 #define DBX_CONTIN_CHAR '?'
84 
85 #undef  LOCAL_LABEL_PREFIX
86 #define LOCAL_LABEL_PREFIX  "."
87 
88 /* This is how to store into the string LABEL
89    the symbol_ref name of an internal numbered label where
90    PREFIX is the class of label and NUM is the number within the class.
91    This is suitable for output with `assemble_name'.  */
92 
93 #undef  ASM_GENERATE_INTERNAL_LABEL
94 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)	\
95   sprintf ((LABEL), "*.L%s%ld", (PREFIX), (long)(NUM))
96 
97 #undef USER_LABEL_PREFIX
98 #define USER_LABEL_PREFIX ""
99 
100 #undef ASM_SPEC
101 #define ASM_SPEC "%{" FPIE_OR_FPIC_SPEC ":-K PIC} \
102 %(asm_cpu) %(asm_arch) %(asm_relax)"
103 
104 #undef STDC_0_IN_SYSTEM_HEADERS
105 
106 #define HAVE_ENABLE_EXECUTE_STACK
107 
108 /* Below here exists the merged NetBSD/sparc & NetBSD/sparc64 compiler
109    description, allowing one to build 32-bit or 64-bit applications
110    on either.  We define the sparc & sparc64 versions of things,
111    occasionally a neutral version (should be the same as "netbsd-elf.h")
112    and then based on SPARC_BI_ARCH, DEFAULT_ARCH32_P, and TARGET_CPU_DEFAULT,
113    we choose the correct version.  */
114 
115 /* We use the default NetBSD ELF STARTFILE_SPEC and ENDFILE_SPEC
116    definitions, even for the SPARC_BI_ARCH compiler, because NetBSD does
117    not have a default place to find these libraries..  */
118 
119 /* TARGET_CPU_DEFAULT is set in Makefile.in.  We test for 64-bit default
120    platform here.  */
121 
122 #if TARGET_CPU_DEFAULT == TARGET_CPU_v9 \
123  || TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc
124 /* A 64 bit v9 compiler with stack-bias,
125    in a Medium/Low code model environment.  */
126 
127 #undef TARGET_DEFAULT
128 #define TARGET_DEFAULT \
129   (MASK_V9 + MASK_PTR64 + MASK_64BIT /* + MASK_HARD_QUAD */ \
130    + MASK_STACK_BIAS + MASK_APP_REGS + MASK_FPU + MASK_LONG_DOUBLE_128)
131 
132 #undef SPARC_DEFAULT_CMODEL
133 #define SPARC_DEFAULT_CMODEL CM_MEDMID
134 
135 #endif
136 
137 /* CC1_SPEC for NetBSD/sparc.  */
138 #define CC1_SPEC32 \
139  "%{m32:%{m64:%emay not use both -m32 and -m64}} \
140   %{m64: \
141     -mptr64 -mstack-bias -mno-v8plus -mlong-double-128 \
142     %{!mcpu*:%{!mv8plus:-mcpu=ultrasparc}} \
143     %{!mno-vis:%{!mcpu=v9:-mvis}} \
144     %{p:-mcmodel=medlow} \
145     %{pg:-mcmodel=medlow}} " \
146   NETBSD_CC1_AND_CC1PLUS_SPEC
147 
148 #define CC1_SPEC64 \
149  "%{m32:%{m64:%emay not use both -m32 and -m64}} \
150   %{m32: \
151     -mptr32 -mno-stack-bias \
152     %{!mlong-double-128:-mlong-double-64} \
153     %{!mcpu*:%{!mv8plus:-mcpu=cypress}}} \
154   %{!m32: \
155       %{p:-mcmodel=medlow} \
156       %{pg:-mcmodel=medlow}} " \
157   NETBSD_CC1_AND_CC1PLUS_SPEC
158 
159 #if defined(SPARC_BI_ARCH) || defined(__arch64__)
160 /* add code model specific object to the link line for 64bit */
161 #define	LINK_SPEC_CODE_MODEL64	\
162 	"%{!shared:"	\
163 	    "%{!mcmodel=*:%:if-exists(%R/usr/lib/sparc_mcmedmid.o)}"	\
164 	    "%{mcmodel=medlow:%:if-exists(%R/usr/lib/sparc_mcmedlow.o)}" \
165 	    "%{mcmodel=medmid:%:if-exists(%R/usr/lib/sparc_mcmedmid.o)}" \
166 	    "%{mcmodel=medany:%:if-exists(%R/usr/lib/sparc_mcmedany.o)}" \
167 	"}"
168 
169 #ifdef SPARC_BI_ARCH
170 #define LINK_SPEC_CODE_MODEL	"%{!m32:" LINK_SPEC_CODE_MODEL64 "}"
171 #else
172 #define	LINK_SPEC_CODE_MODEL	LINK_SPEC_CODE_MODEL64
173 #endif
174 #else
175 #define	LINK_SPEC_CODE_MODEL	""
176 #endif
177 
178 /* Make sure we use the right output format.  Pick a default and then
179    make sure -m32/-m64 switch to the right one.  */
180 
181 #define LINK_ARCH32_SPEC "-m elf32_sparc"
182 
183 #define LINK_ARCH64_SPEC "-m elf64_sparc"
184 
185 #define LINK_ARCH_SPEC \
186  "%{m32:%(link_arch32)} \
187   %{m64:%(link_arch64)} \
188   %{!m32:%{!m64:%(link_arch_default)}}"
189 
190 #undef LINK_SPEC
191 #define LINK_SPEC \
192  "%(link_arch) \
193   %{!mno-relax:%{!r:-relax}} \
194   %(netbsd_link_spec) " \
195   LINK_SPEC_CODE_MODEL
196 
197 #define NETBSD_ENTRY_POINT "__start"
198 
199 #if DEFAULT_ARCH32_P
200 #define LINK_ARCH_DEFAULT_SPEC LINK_ARCH32_SPEC
201 #else
202 #define LINK_ARCH_DEFAULT_SPEC LINK_ARCH64_SPEC
203 #endif
204 
205 /* What extra spec entries do we need?  */
206 #undef SUBTARGET_EXTRA_SPECS
207 #define SUBTARGET_EXTRA_SPECS \
208   { "link_arch32",		LINK_ARCH32_SPEC }, \
209   { "link_arch64",		LINK_ARCH64_SPEC }, \
210   { "link_arch_default",	LINK_ARCH_DEFAULT_SPEC }, \
211   { "link_arch",		LINK_ARCH_SPEC }, \
212   NETBSD_SUBTARGET_EXTRA_SPECS
213 
214 
215 /* Build a compiler that supports -m32 and -m64?  */
216 
217 #ifdef SPARC_BI_ARCH
218 
219 #undef LONG_DOUBLE_TYPE_SIZE
220 #define LONG_DOUBLE_TYPE_SIZE (TARGET_LONG_DOUBLE_128 ? 128 : 64)
221 
222 #undef  CC1_SPEC
223 #if DEFAULT_ARCH32_P
224 #define CC1_SPEC CC1_SPEC32
225 #else
226 #define CC1_SPEC CC1_SPEC64
227 #endif
228 
229 #if DEFAULT_ARCH32_P
230 #define MULTILIB_DEFAULTS { "m32" }
231 #else
232 #define MULTILIB_DEFAULTS { "m64" }
233 #endif
234 
235 #else	/* SPARC_BI_ARCH */
236 
237 #if TARGET_CPU_DEFAULT == TARGET_CPU_v9 \
238  || TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc
239 
240 #undef LONG_DOUBLE_TYPE_SIZE
241 #define LONG_DOUBLE_TYPE_SIZE 128
242 
243 #undef  CC1_SPEC
244 #define CC1_SPEC CC1_SPEC64
245 
246 #else	/* TARGET_CPU_DEFAULT == TARGET_CPU_v9 \
247 	|| TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc */
248 
249 /* A 32-bit only compiler.  NetBSD don't support 128 bit `long double'
250    for 32-bit code, unlike Solaris.  */
251 
252 #undef LONG_DOUBLE_TYPE_SIZE
253 #define LONG_DOUBLE_TYPE_SIZE 64
254 
255 #undef  CC1_SPEC
256 #define CC1_SPEC CC1_SPEC32
257 
258 #endif	/* TARGET_CPU_DEFAULT == TARGET_CPU_v9 \
259 	|| TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc */
260 
261 #endif	/* SPARC_BI_ARCH */
262 
263 #ifdef HAVE_AS_TLS
264 #undef TARGET_SUN_TLS
265 #undef TARGET_GNU_TLS
266 #define TARGET_SUN_TLS 0
267 #define TARGET_GNU_TLS 1
268 #endif
269 
270 /* We use GNU ld so undefine this so that attribute((init_priority)) works.  */
271 #undef CTORS_SECTION_ASM_OP
272 #undef DTORS_SECTION_ASM_OP
273