1 /* Definitions of target machine for GNU compiler. MIPS R3000 version with
2 GOFAST floating point library.
3 Copyright (C) 1994, 1997, 1999 Free Software Foundation, Inc.
5 This file is part of GNU CC.
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)
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.
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. */
23 #define OBJECT_FORMAT_ELF
25 /* Until we figure out what MIPS ELF targets normally use, just do
27 #ifndef PREFERRED_DEBUGGING_TYPE
28 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
31 /* Mostly like ECOFF. */
33 #include "mips/ecoff.h"
35 /* We need to use .esize and .etype instead of .size and .type to
36 avoid conflicting with ELF directives. */
38 #define PUT_SDB_SIZE(a) \
40 extern FILE *asm_out_text_file; \
41 fprintf (asm_out_text_file, "\t.esize\t%d;", (a)); \
45 #define PUT_SDB_TYPE(a) \
47 extern FILE *asm_out_text_file; \
48 fprintf (asm_out_text_file, "\t.etype\t0x%x;", (a)); \
51 /* Biggest alignment supported by the object file format of this
52 machine. Use this macro to limit the alignment which can be
53 specified using the `__attribute__ ((aligned (N)))' construct. If
54 not defined, the default value is `BIGGEST_ALIGNMENT'. */
56 #define MAX_OFILE_ALIGNMENT (32768*8)
58 /* A C statement to output something to the assembler file to switch to section
59 NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
60 NULL_TREE. Some target formats do not support arbitrary sections. Do not
61 define this macro in such cases. */
63 #define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME, RELOC) \
65 extern FILE *asm_out_text_file; \
66 if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL) \
67 fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \
68 else if ((DECL) && DECL_READONLY_SECTION (DECL, RELOC)) \
69 fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME)); \
71 fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME)); \
74 /* The following macro defines the format used to output the second
75 operand of the .type assembler directive. Different svr4 assemblers
76 expect various different forms for this operand. The one given here
77 is just a default. You may need to override it in your machine-
78 specific tm.h file (depending upon the particulars of your assembler). */
80 #define TYPE_OPERAND_FMT "@%s"
82 /* Define the strings used for the special svr4 .type and .size directives.
83 These strings generally do not vary from one system running svr4 to
84 another, but if a given system (e.g. m88k running svr) needs to use
85 different pseudo-op names for these, they may be overridden in the
86 file which includes this one. */
90 #define TYPE_ASM_OP ".type"
91 #define SIZE_ASM_OP ".size"
93 /* If defined, a C expression whose value is a string containing the
94 assembler operation to identify the following data as
95 uninitialized global data. If not defined, and neither
96 `ASM_OUTPUT_BSS' nor `ASM_OUTPUT_ALIGNED_BSS' are defined,
97 uninitialized global data will be output in the data section if
98 `-fno-common' is passed, otherwise `ASM_OUTPUT_COMMON' will be
100 #ifndef BSS_SECTION_ASM_OP
101 #define BSS_SECTION_ASM_OP ".section\t.bss"
104 /* Like `ASM_OUTPUT_BSS' except takes the required alignment as a
105 separate, explicit argument. If you define this macro, it is used
106 in place of `ASM_OUTPUT_BSS', and gives you more flexibility in
107 handling the required alignment of the variable. The alignment is
108 specified as the number of bits.
110 Try to use function `asm_output_aligned_bss' defined in file
111 `varasm.c' when defining this macro. */
112 #ifndef ASM_OUTPUT_ALIGNED_BSS
113 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
114 asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
117 /* These macros generate the special .type and .size directives which
118 are used to set the corresponding fields of the linker symbol table
119 entries in an ELF object file under SVR4. These macros also output
120 the starting labels for the relevant functions/objects. */
122 /* Write the extra assembler code needed to declare an object properly. */
124 #undef ASM_DECLARE_OBJECT_NAME
125 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
127 fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \
128 assemble_name (FILE, NAME); \
130 fprintf (FILE, TYPE_OPERAND_FMT, "object"); \
132 size_directive_output = 0; \
133 if (!flag_inhibit_size_directive && DECL_SIZE (DECL)) \
135 size_directive_output = 1; \
136 fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \
137 assemble_name (FILE, NAME); \
138 fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \
140 mips_declare_object (FILE, NAME, "", ":\n", 0); \
143 /* Output the size directive for a decl in rest_of_decl_compilation
144 in the case where we did not do so before the initializer.
145 Once we find the error_mark_node, we know that the value of
146 size_directive_output was set
147 by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */
149 #undef ASM_FINISH_DECLARE_OBJECT
150 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \
152 char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \
153 if (!flag_inhibit_size_directive && DECL_SIZE (DECL) \
154 && ! AT_END && TOP_LEVEL \
155 && DECL_INITIAL (DECL) == error_mark_node \
156 && !size_directive_output) \
158 size_directive_output = 1; \
159 fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \
160 assemble_name (FILE, name); \
161 fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \
165 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
166 do { fputc ( '\t', FILE); \
167 assemble_name (FILE, LABEL1); \
168 fputs ( " = ", FILE); \
169 assemble_name (FILE, LABEL2); \
170 fputc ( '\n', FILE); \
173 /* Note about .weak vs. .weakext
174 The mips native assemblers support .weakext, but not .weak.
175 mips-elf gas supports .weak, but not .weakext.
176 mips-elf gas has been changed to support both .weak and .weakext,
177 but until that support is generally available, the 'if' below
180 #define ASM_WEAKEN_LABEL(FILE,NAME) ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,0)
181 #define ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,VALUE) \
184 fputs ("\t.weak\t", FILE); \
186 fputs ("\t.weakext\t", FILE); \
187 assemble_name (FILE, NAME); \
191 assemble_name (FILE, VALUE); \
193 fputc ('\n', FILE); \
196 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
197 #undef UNIQUE_SECTION_P
198 #define UNIQUE_SECTION_P(DECL) (DECL_ONE_ONLY (DECL))
199 #define UNIQUE_SECTION(DECL,RELOC) \
201 int len, size, sec; \
202 char *name, *string, *prefix; \
203 static char *prefixes[4][2] = { \
204 { ".text.", ".gnu.linkonce.t." }, \
205 { ".rodata.", ".gnu.linkonce.r." }, \
206 { ".data.", ".gnu.linkonce.d." }, \
207 { ".sdata.", ".gnu.linkonce.s." } \
210 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
211 size = int_size_in_bytes (TREE_TYPE (decl)); \
213 /* Determine the base section we are interested in: \
214 0=text, 1=rodata, 2=data, 3=sdata. */ \
215 if (TREE_CODE (DECL) == FUNCTION_DECL) \
217 else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16) \
218 && TREE_CODE (decl) == STRING_CST \
219 && !flag_writable_strings) \
221 /* For embedded position independent code, put constant strings \
222 in the text section, because the data section is limited to \
223 64K in size. For mips16 code, put strings in the text \
224 section so that a PC relative load instruction can be used to \
225 get their address. */ \
228 else if (TARGET_EMBEDDED_DATA) \
230 /* For embedded applications, always put an object in read-only data \
231 if possible, in order to reduce RAM usage. */ \
233 if (DECL_READONLY_SECTION (DECL, RELOC)) \
235 else if (size > 0 && size <= mips_section_threshold) \
242 /* For hosted applications, always put an object in small data if \
243 possible, as this gives the best performance. */ \
245 if (size > 0 && size <= mips_section_threshold) \
247 else if (DECL_READONLY_SECTION (DECL, RELOC)) \
253 prefix = prefixes[sec][DECL_ONE_ONLY (DECL)]; \
254 len = strlen (name) + strlen (prefix); \
255 string = alloca (len + 1); \
256 sprintf (string, "%s%s", prefix, name); \
258 DECL_SECTION_NAME (DECL) = build_string (len, string); \
261 /* Support the ctors/dtors and other sections. */
263 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
265 Note that we want to give these sections the SHF_WRITE attribute
266 because these sections will actually contain data (i.e. tables of
267 addresses of functions in the current root executable or shared library
268 file) and, in the case of a shared library, the relocatable addresses
269 will have to be properly resolved/relocated (and then written into) by
270 the dynamic linker when it actually attaches the given shared library
271 to the executing process. (Note that on SVR4, you may wish to use the
272 `-z text' option to the ELF linker, when building a shared library, as
273 an additional check that you are doing everything right. But if you do
274 use the `-z text' option when building a shared library, you will get
275 errors unless the .ctors and .dtors sections are marked as writable
276 via the SHF_WRITE attribute.) */
278 #define CTORS_SECTION_ASM_OP "\t.section\t.ctors,\"aw\""
279 #define DTORS_SECTION_ASM_OP "\t.section\t.dtors,\"aw\""
281 /* A list of other sections which the compiler might be "in" at any
283 #undef EXTRA_SECTIONS
284 #define EXTRA_SECTIONS in_sdata, in_rdata, in_ctors, in_dtors
287 #define NAME__MAIN "__gccmain"
288 #define SYMBOL__MAIN __gccmain
290 #undef EXTRA_SECTION_FUNCTIONS
291 #define EXTRA_SECTION_FUNCTIONS \
292 SECTION_FUNCTION_TEMPLATE(sdata_section, in_sdata, SDATA_SECTION_ASM_OP) \
293 SECTION_FUNCTION_TEMPLATE(rdata_section, in_rdata, RDATA_SECTION_ASM_OP) \
294 SECTION_FUNCTION_TEMPLATE(ctors_section, in_ctors, CTORS_SECTION_ASM_OP) \
295 SECTION_FUNCTION_TEMPLATE(dtors_section, in_dtors, DTORS_SECTION_ASM_OP)
297 #define SECTION_FUNCTION_TEMPLATE(FN, ENUM, OP) \
300 if (in_section != ENUM) \
302 fprintf (asm_out_file, "%s\n", OP); \
308 /* A C statement (sans semicolon) to output an element in the table of
309 global constructors. */
310 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \
313 fprintf (FILE, "\t%s\t", TARGET_LONG64 ? ".dword" : ".word"); \
314 assemble_name (FILE, NAME); \
315 fprintf (FILE, "\n"); \
319 /* A C statement (sans semicolon) to output an element in the table of
320 global destructors. */
321 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \
324 fprintf (FILE, "\t%s\t", TARGET_LONG64 ? ".dword" : ".word"); \
325 assemble_name (FILE, NAME); \
326 fprintf (FILE, "\n"); \
329 #define CTOR_LIST_BEGIN \
330 asm (CTORS_SECTION_ASM_OP); \
331 func_ptr __CTOR_LIST__[1] = { (func_ptr) (-1) }
333 #define CTOR_LIST_END \
334 asm (CTORS_SECTION_ASM_OP); \
335 func_ptr __CTOR_END__[1] = { (func_ptr) 0 };
337 #define DTOR_LIST_BEGIN \
338 asm (DTORS_SECTION_ASM_OP); \
339 func_ptr __DTOR_LIST__[1] = { (func_ptr) (-1) }
341 #define DTOR_LIST_END \
342 asm (DTORS_SECTION_ASM_OP); \
343 func_ptr __DTOR_END__[1] = { (func_ptr) 0 };
345 /* Don't set the target flags, this is done by the linker script */
349 #undef STARTFILE_SPEC
350 #define STARTFILE_SPEC "crtbegin%O%s crt0%O%s"
353 #define ENDFILE_SPEC "crtend%O%s"