(ASM_OUTPUT_SECTION_NAME): emit @nobits
[gcc.git] / gcc / config / mips / elf64.h
1 /* Definitions of target machine for GNU compiler. MIPS R4000 version with
2 GOFAST floating point library.
3 Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #define OBJECT_FORMAT_ELF
23
24 /* Default to -mips3. */
25 #define TARGET_DEFAULT MASK_FLOAT64|MASK_64BIT
26 #define MIPS_ISA_DEFAULT 3
27
28 /* Until we figure out what MIPS ELF targets normally use, just do
29 stabs in ELF. */
30 #ifndef PREFERRED_DEBUGGING_TYPE
31 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
32 #endif
33
34 /* US Software GOFAST library support. */
35 #include "gofast.h"
36 #define INIT_SUBTARGET_OPTABS INIT_GOFAST_OPTABS
37
38 #include "mips/mips.h"
39
40 #undef CPP_PREDEFINES
41 #define CPP_PREDEFINES "-Dmips -DMIPSEB -DR4000 -D_mips -D_MIPSEB -D_R4000"
42
43 /* I would rather put this in CPP_PREDEFINES, but the gcc driver
44 doesn't handle -U options in CPP_PREDEFINES. */
45 #undef SUBTARGET_CPP_SPEC
46 #define SUBTARGET_CPP_SPEC "\
47 %{!mips1:%{!mips2:-U__mips -D__mips=3 -D__mips64}}"
48
49 /* Use memcpy, et. al., rather than bcopy. */
50 #define TARGET_MEM_FUNCTIONS
51
52 /* Biggest alignment supported by the object file format of this
53 machine. Use this macro to limit the alignment which can be
54 specified using the `__attribute__ ((aligned (N)))' construct. If
55 not defined, the default value is `BIGGEST_ALIGNMENT'. */
56
57 #define MAX_OFILE_ALIGNMENT (32768*8)
58
59 /* We need to use .esize and .etype instead of .size and .type to
60 avoid conflicting with ELF directives. */
61 #undef PUT_SDB_SIZE
62 #define PUT_SDB_SIZE(a) \
63 do { \
64 extern FILE *asm_out_text_file; \
65 fprintf (asm_out_text_file, "\t.esize\t%d;", (a)); \
66 } while (0)
67
68 #undef PUT_SDB_TYPE
69 #define PUT_SDB_TYPE(a) \
70 do { \
71 extern FILE *asm_out_text_file; \
72 fprintf (asm_out_text_file, "\t.etype\t0x%x;", (a)); \
73 } while (0)
74
75 /* A C statement to output something to the assembler file to switch to section
76 NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
77 NULL_TREE. Some target formats do not support arbitrary sections. Do not
78 define this macro in such cases. */
79
80 #define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME, RELOC) \
81 do { \
82 extern FILE *asm_out_text_file; \
83 if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL) \
84 fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \
85 else if ((DECL) && DECL_READONLY_SECTION (DECL, RELOC)) \
86 fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME)); \
87 else if (! strcmp (NAME, ".bss")) \
88 fprintf (F, "\t.section %s,\"aw\",@nobits\n", (NAME)); \
89 else \
90 fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME)); \
91 } while (0)
92
93 /* The following macro defines the format used to output the second
94 operand of the .type assembler directive. Different svr4 assemblers
95 expect various different forms for this operand. The one given here
96 is just a default. You may need to override it in your machine-
97 specific tm.h file (depending upon the particulars of your assembler). */
98
99 #define TYPE_OPERAND_FMT "@%s"
100
101 /* Define the strings used for the special svr4 .type and .size directives.
102 These strings generally do not vary from one system running svr4 to
103 another, but if a given system (e.g. m88k running svr) needs to use
104 different pseudo-op names for these, they may be overridden in the
105 file which includes this one. */
106
107 #undef TYPE_ASM_OP
108 #undef SIZE_ASM_OP
109 #define TYPE_ASM_OP "\t.type\t"
110 #define SIZE_ASM_OP "\t.size\t"
111
112 /* These macros generate the special .type and .size directives which
113 are used to set the corresponding fields of the linker symbol table
114 entries in an ELF object file under SVR4. These macros also output
115 the starting labels for the relevant functions/objects. */
116
117 /* Write the extra assembler code needed to declare an object properly. */
118
119 #undef ASM_DECLARE_OBJECT_NAME
120 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
121 do { \
122 fprintf (FILE, "%s", TYPE_ASM_OP); \
123 assemble_name (FILE, NAME); \
124 putc (',', FILE); \
125 fprintf (FILE, TYPE_OPERAND_FMT, "object"); \
126 putc ('\n', FILE); \
127 size_directive_output = 0; \
128 if (!flag_inhibit_size_directive && DECL_SIZE (DECL)) \
129 { \
130 size_directive_output = 1; \
131 fprintf (FILE, "%s", SIZE_ASM_OP); \
132 assemble_name (FILE, NAME); \
133 fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \
134 } \
135 mips_declare_object (FILE, NAME, "", ":\n", 0); \
136 } while (0)
137
138 /* Output the size directive for a decl in rest_of_decl_compilation
139 in the case where we did not do so before the initializer.
140 Once we find the error_mark_node, we know that the value of
141 size_directive_output was set
142 by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */
143
144 #undef ASM_FINISH_DECLARE_OBJECT
145 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \
146 do { \
147 const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \
148 if (!flag_inhibit_size_directive && DECL_SIZE (DECL) \
149 && ! AT_END && TOP_LEVEL \
150 && DECL_INITIAL (DECL) == error_mark_node \
151 && !size_directive_output) \
152 { \
153 size_directive_output = 1; \
154 fprintf (FILE, "%s", SIZE_ASM_OP); \
155 assemble_name (FILE, name); \
156 fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \
157 } \
158 } while (0)
159
160 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
161 do { fputc ( '\t', FILE); \
162 assemble_name (FILE, LABEL1); \
163 fputs ( " = ", FILE); \
164 assemble_name (FILE, LABEL2); \
165 fputc ( '\n', FILE); \
166 } while (0)
167
168 /* Note about .weak vs. .weakext
169 The mips native assemblers support .weakext, but not .weak.
170 mips-elf gas supports .weak, but not .weakext.
171 mips-elf gas has been changed to support both .weak and .weakext,
172 but until that support is generally available, the 'if' below
173 should serve. */
174
175 #define ASM_WEAKEN_LABEL(FILE,NAME) ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,0)
176 #define ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,VALUE) \
177 do { \
178 if (TARGET_GAS) \
179 fputs ("\t.weak\t", FILE); \
180 else \
181 fputs ("\t.weakext\t", FILE); \
182 assemble_name (FILE, NAME); \
183 if (VALUE) \
184 { \
185 fputc (' ', FILE); \
186 assemble_name (FILE, VALUE); \
187 } \
188 fputc ('\n', FILE); \
189 } while (0)
190
191 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
192 #undef UNIQUE_SECTION_P
193 #define UNIQUE_SECTION_P(DECL) (DECL_ONE_ONLY (DECL))
194 #define UNIQUE_SECTION(DECL,RELOC) \
195 do { \
196 int len, size, sec; \
197 char *name, *string, *prefix; \
198 static char *prefixes[4][2] = { \
199 { ".text.", ".gnu.linkonce.t." }, \
200 { ".rodata.", ".gnu.linkonce.r." }, \
201 { ".data.", ".gnu.linkonce.d." }, \
202 { ".sdata.", ".gnu.linkonce.s." } \
203 }; \
204 \
205 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
206 size = int_size_in_bytes (TREE_TYPE (decl)); \
207 \
208 /* Determine the base section we are interested in: \
209 0=text, 1=rodata, 2=data, 3=sdata, [4=bss]. */ \
210 if (TREE_CODE (DECL) == FUNCTION_DECL) \
211 sec = 0; \
212 else if (DECL_INITIAL (DECL) == 0 \
213 || DECL_INITIAL (DECL) == error_mark_node) \
214 sec = 2; \
215 else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16) \
216 && TREE_CODE (decl) == STRING_CST \
217 && !flag_writable_strings) \
218 { \
219 /* For embedded position independent code, put constant strings \
220 in the text section, because the data section is limited to \
221 64K in size. For mips16 code, put strings in the text \
222 section so that a PC relative load instruction can be used to \
223 get their address. */ \
224 sec = 0; \
225 } \
226 else if (TARGET_EMBEDDED_DATA) \
227 { \
228 /* For embedded applications, always put an object in read-only data \
229 if possible, in order to reduce RAM usage. */ \
230 \
231 if (DECL_READONLY_SECTION (DECL, RELOC)) \
232 sec = 1; \
233 else if (size > 0 && size <= mips_section_threshold) \
234 sec = 3; \
235 else \
236 sec = 2; \
237 } \
238 else \
239 { \
240 /* For hosted applications, always put an object in small data if \
241 possible, as this gives the best performance. */ \
242 \
243 if (size > 0 && size <= mips_section_threshold) \
244 sec = 3; \
245 else if (DECL_READONLY_SECTION (DECL, RELOC)) \
246 sec = 1; \
247 else \
248 sec = 2; \
249 } \
250 \
251 prefix = prefixes[sec][DECL_ONE_ONLY (DECL)]; \
252 len = strlen (name) + strlen (prefix); \
253 string = alloca (len + 1); \
254 sprintf (string, "%s%s", prefix, name); \
255 \
256 DECL_SECTION_NAME (DECL) = build_string (len, string); \
257 } while (0)
258
259 /* Support the ctors/dtors and other sections. */
260
261 /* Define the names of and pseudo-ops used to switch to the .ctors and
262 .dtors sections.
263
264 Note that we want to give these sections the SHF_WRITE attribute
265 because these sections will actually contain data (i.e. tables of
266 addresses of functions in the current root executable or shared library
267 file) and, in the case of a shared library, the relocatable addresses
268 will have to be properly resolved/relocated (and then written into) by
269 the dynamic linker when it actually attaches the given shared library
270 to the executing process. (Note that on SVR4, you may wish to use the
271 `-z text' option to the ELF linker, when building a shared library, as
272 an additional check that you are doing everything right. But if you do
273 use the `-z text' option when building a shared library, you will get
274 errors unless the .ctors and .dtors sections are marked as writable
275 via the SHF_WRITE attribute.) */
276
277 #define CTORS_SECTION_NAME ".ctors"
278 #define CTORS_SECTION_ASM_OP "\t.section\t.ctors,\"aw\""
279 #define DTORS_SECTION_NAME ".dtors"
280 #define DTORS_SECTION_ASM_OP "\t.section\t.dtors,\"aw\""
281
282 /* There's no point providing a default definition of __CTOR_LIST__
283 since people are expected either to use crtbegin.o, or an equivalent,
284 or provide their own definition. */
285 #define CTOR_LISTS_DEFINED_EXTERNALLY
286
287 /* A list of other sections which the compiler might be "in" at any
288 given time. */
289 #undef EXTRA_SECTIONS
290 #define EXTRA_SECTIONS in_sdata, in_rdata, in_ctors, in_dtors
291
292 #define INVOKE__main
293
294 #undef EXTRA_SECTION_FUNCTIONS
295 #define EXTRA_SECTION_FUNCTIONS \
296 SECTION_FUNCTION_TEMPLATE(sdata_section, in_sdata, SDATA_SECTION_ASM_OP) \
297 SECTION_FUNCTION_TEMPLATE(rdata_section, in_rdata, RDATA_SECTION_ASM_OP) \
298 SECTION_FUNCTION_TEMPLATE(ctors_section, in_ctors, CTORS_SECTION_ASM_OP) \
299 SECTION_FUNCTION_TEMPLATE(dtors_section, in_dtors, DTORS_SECTION_ASM_OP)
300
301 #define SECTION_FUNCTION_TEMPLATE(FN, ENUM, OP) \
302 void FN () \
303 { \
304 if (in_section != ENUM) \
305 { \
306 fprintf (asm_out_file, "%s\n", OP); \
307 in_section = ENUM; \
308 } \
309 }
310
311
312 /* A C statement (sans semicolon) to output an element in the table of
313 global constructors. */
314 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \
315 do { \
316 ctors_section (); \
317 fprintf (FILE, "\t%s\t", (Pmode == SImode) ? ".word" : ".dword"); \
318 assemble_name (FILE, NAME); \
319 fprintf (FILE, "\n"); \
320 } while (0)
321
322
323 /* A C statement (sans semicolon) to output an element in the table of
324 global destructors. */
325 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \
326 do { \
327 dtors_section (); \
328 fprintf (FILE, "\t%s\t", (Pmode == SImode) ? ".word" : ".dword"); \
329 assemble_name (FILE, NAME); \
330 fprintf (FILE, "\n"); \
331 } while (0)
332
333 #define CTOR_LIST_BEGIN \
334 func_ptr __CTOR_LIST__ __attribute__((section(CTORS_SECTION_NAME))) = \
335 (func_ptr) (-1)
336
337 #define CTOR_LIST_END \
338 func_ptr __CTOR_END__ __attribute__((section(CTORS_SECTION_NAME))) = \
339 (func_ptr) 0
340
341 #define DTOR_LIST_BEGIN \
342 func_ptr __DTOR_LIST__ __attribute__((section(DTORS_SECTION_NAME))) = \
343 (func_ptr) (-1)
344
345 #define DTOR_LIST_END \
346 func_ptr __DTOR_END__ __attribute__((section(DTORS_SECTION_NAME))) = \
347 (func_ptr) 0
348
349 /* Don't set the target flags, this is done by the linker script */
350 #undef LIB_SPEC
351 #define LIB_SPEC ""
352
353 #undef STARTFILE_SPEC
354 #define STARTFILE_SPEC "crtbegin%O%s %{!mno-crt0:crt0%O%s}"
355
356 #undef ENDFILE_SPEC
357 #define ENDFILE_SPEC "crtend%O%s"