OSDN Git Service

2002-01-16 H.J. Lu <hjl@gnu.org>
[pf3gnuchains/gcc-fork.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 /* This should change to n32 when it is supported in gas.  */
29 #define MIPS_ABI_DEFAULT ABI_O64
30
31 /* Until we figure out what MIPS ELF targets normally use, just do
32    stabs in ELF.  */
33 #ifndef PREFERRED_DEBUGGING_TYPE
34 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
35 #endif
36
37 /* US Software GOFAST library support.  */
38 #include "gofast.h"
39 #define INIT_SUBTARGET_OPTABS INIT_GOFAST_OPTABS
40
41 #include "mips/mips.h"
42
43 #undef CPP_PREDEFINES
44 #define CPP_PREDEFINES "-Dmips -DMIPSEB -DR4000 -D_mips -D_MIPSEB -D_R4000"
45
46 /* I would rather put this in CPP_PREDEFINES, but the gcc driver
47    doesn't handle -U options in CPP_PREDEFINES.  */
48 #undef SUBTARGET_CPP_SPEC
49 #define SUBTARGET_CPP_SPEC "\
50 %{!mips1:%{!mips2:-U__mips -D__mips=3 -D__mips64}}"
51
52 /* Use memcpy, et. al., rather than bcopy.  */
53 #define TARGET_MEM_FUNCTIONS
54
55 /* Biggest alignment supported by the object file format of this
56    machine.  Use this macro to limit the alignment which can be
57    specified using the `__attribute__ ((aligned (N)))' construct.  If
58    not defined, the default value is `BIGGEST_ALIGNMENT'.  */
59
60 #undef MAX_OFILE_ALIGNMENT
61 #define MAX_OFILE_ALIGNMENT (32768*8)
62
63 /* We need to use .esize and .etype instead of .size and .type to
64    avoid conflicting with ELF directives.  */
65 #undef PUT_SDB_SIZE
66 #define PUT_SDB_SIZE(a)                                 \
67 do {                                                    \
68   extern FILE *asm_out_text_file;                       \
69   fprintf (asm_out_text_file, "\t.esize\t");            \
70   fprintf (asm_out_text_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) (a)); \
71   fprintf (asm_out_text_file, ";");                     \
72 } while (0)
73
74 #undef PUT_SDB_TYPE
75 #define PUT_SDB_TYPE(a)                                 \
76 do {                                                    \
77   extern FILE *asm_out_text_file;                       \
78   fprintf (asm_out_text_file, "\t.etype\t0x%x;", (a));  \
79 } while (0)
80
81 /* Switch into a generic section.  */
82 #undef TARGET_ASM_NAMED_SECTION
83 #define TARGET_ASM_NAMED_SECTION  default_elf_asm_named_section
84
85 /* Given that Irix has it's own headers, not having TARGET_GAS here
86    seems a mistake.  If we actually need to be prepared for file
87    switching, then we need a custom TARGET_ASM_NAMED_SECTION too.  */
88
89 #undef TEXT_SECTION
90 #define TEXT_SECTION()                          \
91 do {                                            \
92   if (TARGET_FILE_SWITCHING)                    \
93     abort ();                                   \
94   fputs (TEXT_SECTION_ASM_OP, asm_out_file);    \
95   fputc ('\n', asm_out_file);                   \
96 } while (0)
97
98 /* The following macro defines the format used to output the second
99    operand of the .type assembler directive.  Different svr4 assemblers
100    expect various different forms for this operand.  The one given here
101    is just a default.  You may need to override it in your machine-
102    specific tm.h file (depending upon the particulars of your assembler).  */
103
104 #define TYPE_OPERAND_FMT        "@%s"
105
106 /* Define the strings used for the special svr4 .type and .size directives.
107    These strings generally do not vary from one system running svr4 to
108    another, but if a given system (e.g. m88k running svr) needs to use
109    different pseudo-op names for these, they may be overridden in the
110    file which includes this one.  */
111
112 #undef TYPE_ASM_OP
113 #undef SIZE_ASM_OP
114 #define TYPE_ASM_OP     "\t.type\t"
115 #define SIZE_ASM_OP     "\t.size\t"
116
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.  */
121
122 /* Write the extra assembler code needed to declare an object properly.  */
123
124 #undef ASM_DECLARE_OBJECT_NAME
125 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)                       \
126   do {                                                                  \
127     fprintf (FILE, "%s", TYPE_ASM_OP);                                  \
128     assemble_name (FILE, NAME);                                         \
129     putc (',', FILE);                                                   \
130     fprintf (FILE, TYPE_OPERAND_FMT, "object");                         \
131     putc ('\n', FILE);                                                  \
132     size_directive_output = 0;                                          \
133     if (!flag_inhibit_size_directive && DECL_SIZE (DECL))               \
134       {                                                                 \
135         size_directive_output = 1;                                      \
136         fprintf (FILE, "%s", SIZE_ASM_OP);                              \
137         assemble_name (FILE, NAME);                                     \
138         fprintf (FILE, ",");                                            \
139         fprintf (FILE, HOST_WIDE_INT_PRINT_DEC,                         \
140           int_size_in_bytes (TREE_TYPE (DECL)));                        \
141         fprintf (FILE, "\n");                                           \
142       }                                                                 \
143     mips_declare_object (FILE, NAME, "", ":\n", 0);                     \
144   } while (0)
145
146 /* Output the size directive for a decl in rest_of_decl_compilation
147    in the case where we did not do so before the initializer.
148    Once we find the error_mark_node, we know that the value of
149    size_directive_output was set
150    by ASM_DECLARE_OBJECT_NAME when it was run for the same decl.  */
151
152 #undef ASM_FINISH_DECLARE_OBJECT
153 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)         \
154 do {                                                                     \
155      const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);             \
156      if (!flag_inhibit_size_directive && DECL_SIZE (DECL)                \
157          && ! AT_END && TOP_LEVEL                                        \
158          && DECL_INITIAL (DECL) == error_mark_node                       \
159          && !size_directive_output)                                      \
160        {                                                                 \
161          size_directive_output = 1;                                      \
162          fprintf (FILE, "%s", SIZE_ASM_OP);                              \
163          assemble_name (FILE, name);                                     \
164          fprintf (FILE, ",");                                            \
165          fprintf (FILE, HOST_WIDE_INT_PRINT_DEC,                         \
166                   int_size_in_bytes (TREE_TYPE (DECL)));                 \
167          fprintf (FILE, "\n");                                           \
168        }                                                                 \
169    } while (0)
170
171 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                            \
172  do { fputc ( '\t', FILE);                                            \
173       assemble_name (FILE, LABEL1);                                   \
174       fputs ( " = ", FILE);                                           \
175       assemble_name (FILE, LABEL2);                                   \
176       fputc ( '\n', FILE);                                            \
177  } while (0)
178
179 /* Note about .weak vs. .weakext
180    The mips native assemblers support .weakext, but not .weak.
181    mips-elf gas supports .weak, but not .weakext.
182    mips-elf gas has been changed to support both .weak and .weakext,
183    but until that support is generally available, the 'if' below
184    should serve.  */
185
186 #undef ASM_WEAKEN_LABEL
187 #define ASM_WEAKEN_LABEL(FILE,NAME) ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,0)
188 #define ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,VALUE)  \
189  do {                                           \
190   if (TARGET_GAS)                               \
191       fputs ("\t.weak\t", FILE);                \
192   else                                          \
193       fputs ("\t.weakext\t", FILE);             \
194   assemble_name (FILE, NAME);                   \
195   if (VALUE)                                    \
196     {                                           \
197       fputc (' ', FILE);                        \
198       assemble_name (FILE, VALUE);              \
199     }                                           \
200   fputc ('\n', FILE);                           \
201  } while (0)
202
203 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
204 #undef UNIQUE_SECTION
205 #define UNIQUE_SECTION(DECL,RELOC)                                         \
206 do {                                                                       \
207   int len, size, sec;                                                      \
208   const char *name, *prefix;                                               \
209   char *string;                                                            \
210   static const char *const prefixes[4][2] = {                              \
211     { ".text.", ".gnu.linkonce.t." },                                      \
212     { ".rodata.", ".gnu.linkonce.r." },                                    \
213     { ".data.", ".gnu.linkonce.d." },                                      \
214     { ".sdata.", ".gnu.linkonce.s." }                                      \
215   };                                                                       \
216                                                                            \
217   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL));                  \
218   size = int_size_in_bytes (TREE_TYPE (decl));                             \
219                                                                            \
220   /* Determine the base section we are interested in:                      \
221      0=text, 1=rodata, 2=data, 3=sdata, [4=bss].  */                       \
222   if (TREE_CODE (DECL) == FUNCTION_DECL)                                   \
223     sec = 0;                                                               \
224   else if (DECL_INITIAL (DECL) == 0                                        \
225            || DECL_INITIAL (DECL) == error_mark_node)                      \
226     sec = 2;                                                               \
227   else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16)                          \
228       && TREE_CODE (decl) == STRING_CST                                    \
229       && !flag_writable_strings)                                           \
230     {                                                                      \
231       /* For embedded position independent code, put constant strings      \
232          in the text section, because the data section is limited to       \
233          64K in size.  For mips16 code, put strings in the text            \
234          section so that a PC relative load instruction can be used to     \
235          get their address.  */                                            \
236       sec = 0;                                                             \
237     }                                                                      \
238   else if (TARGET_EMBEDDED_DATA)                                           \
239     {                                                                      \
240       /* For embedded applications, always put an object in read-only data \
241          if possible, in order to reduce RAM usage.  */                    \
242                                                                            \
243       if (DECL_READONLY_SECTION (DECL, RELOC))                             \
244         sec = 1;                                                           \
245       else if (size > 0 && size <= mips_section_threshold)                 \
246         sec = 3;                                                           \
247       else                                                                 \
248         sec = 2;                                                           \
249     }                                                                      \
250   else                                                                     \
251     {                                                                      \
252       /* For hosted applications, always put an object in small data if    \
253          possible, as this gives the best performance.  */                 \
254                                                                            \
255       if (size > 0 && size <= mips_section_threshold)                      \
256         sec = 3;                                                           \
257       else if (DECL_READONLY_SECTION (DECL, RELOC))                        \
258         sec = 1;                                                           \
259       else                                                                 \
260         sec = 2;                                                           \
261     }                                                                      \
262                                                                            \
263   prefix = prefixes[sec][DECL_ONE_ONLY (DECL)];                            \
264   len = strlen (name) + strlen (prefix);                                   \
265   string = alloca (len + 1);                                               \
266   sprintf (string, "%s%s", prefix, name);                                  \
267                                                                            \
268   DECL_SECTION_NAME (DECL) = build_string (len, string);                   \
269 } while (0)
270
271 /* A list of other sections which the compiler might be "in" at any
272    given time.  */
273 #undef EXTRA_SECTIONS
274 #define EXTRA_SECTIONS in_sdata, in_rdata
275
276 #undef EXTRA_SECTION_FUNCTIONS
277 #define EXTRA_SECTION_FUNCTIONS                                         \
278   SECTION_FUNCTION_TEMPLATE(sdata_section, in_sdata, SDATA_SECTION_ASM_OP) \
279   SECTION_FUNCTION_TEMPLATE(rdata_section, in_rdata, RDATA_SECTION_ASM_OP)
280
281 #define SECTION_FUNCTION_TEMPLATE(FN, ENUM, OP)                               \
282 void FN ()                                                            \
283 {                                                                     \
284   if (in_section != ENUM)                                             \
285     {                                                                 \
286       fprintf (asm_out_file, "%s\n", OP);                             \
287       in_section = ENUM;                                              \
288     }                                                                 \
289 }
290
291 /* On elf, we *do* have support for the .init and .fini sections, and we
292    can put stuff in there to be executed before and after `main'.  We let
293    crtstuff.c and other files know this by defining the following symbols.
294    The definitions say how to change sections to the .init and .fini
295    sections.  This is the same for all known elf assemblers.  */
296
297 #undef  INIT_SECTION_ASM_OP
298 #define INIT_SECTION_ASM_OP     "\t.section\t.init"
299 #undef  FINI_SECTION_ASM_OP
300 #define FINI_SECTION_ASM_OP     "\t.section\t.fini"
301
302 /* Don't set the target flags, this is done by the linker script */
303 #undef LIB_SPEC
304 #define LIB_SPEC ""
305
306 #undef  STARTFILE_SPEC
307 #define STARTFILE_SPEC "crti%O%s crtbegin%O%s %{!mno-crt0:crt0%O%s}"
308
309 #undef  ENDFILE_SPEC
310 #define ENDFILE_SPEC "crtend%O%s crtn%O%s"