osf.h: Standarize copyright statement.
[platform/upstream/gcc.git] / gcc / config / arm / elf.h
1 /* Definitions of target machine for GNU compiler.
2    For ARM with ELF obj format.
3    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
4    Free Software Foundation, Inc.
5    Contributed by Philip Blundell <philb@gnu.org> and
6    Catherine Moore <clm@cygnus.com>
7    
8 This file is part of GNU CC.
9
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING.  If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.  */
24
25
26 #define OBJECT_FORMAT_ELF
27
28 #ifndef LOCAL_LABEL_PREFIX
29 #define LOCAL_LABEL_PREFIX "."
30 #endif
31
32 #ifndef USER_LABEL_PREFIX
33 #define USER_LABEL_PREFIX ""
34 #endif
35
36 #ifndef SUBTARGET_CPP_SPEC
37 #define SUBTARGET_CPP_SPEC  "-D__ELF__"
38 #endif
39
40 #ifndef SUBTARGET_EXTRA_ASM_SPEC
41 #define SUBTARGET_EXTRA_ASM_SPEC
42 #endif
43
44 #ifndef ASM_SPEC
45 #define ASM_SPEC "\
46 %{mbig-endian:-EB} \
47 %{mcpu=*:-m%*} \
48 %{march=*:-m%*} \
49 %{mapcs-*:-mapcs-%*} \
50 %{mapcs-float:-mfloat} \
51 %{msoft-float:-mno-fpu} \
52 %{mthumb-interwork:-mthumb-interwork} \
53 " SUBTARGET_EXTRA_ASM_SPEC
54 #endif
55
56 /* The following macro defines the format used to output the second
57    operand of the .type assembler directive.  Different svr4 assemblers
58    expect various different forms for this operand.  The one given here
59    is just a default.  You may need to override it in your machine-
60    specific tm.h file (depending upon the particulars of your assembler).  */
61 #define TYPE_OPERAND_FMT        "%s"
62
63 /* Write the extra assembler code needed to declare a function's result.
64    Most svr4 assemblers don't require any special declaration of the
65    result value, but there are exceptions.  */
66 #ifndef ASM_DECLARE_RESULT
67 #define ASM_DECLARE_RESULT(FILE, RESULT)
68 #endif
69
70 /* These macros generate the special .type and .size directives which
71    are used to set the corresponding fields of the linker symbol table
72    entries in an ELF object file under SVR4.  These macros also output
73    the starting labels for the relevant functions/objects.  */
74 #define TYPE_ASM_OP     "\t.type\t"
75 #define SIZE_ASM_OP     "\t.size\t"
76
77 /* Write the extra assembler code needed to declare a function properly.
78    Some svr4 assemblers need to also have something extra said about the
79    function's return value.  We allow for that here.  */
80 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)     \
81   do                                                    \
82     {                                                   \
83       ARM_DECLARE_FUNCTION_NAME (FILE, NAME, DECL);     \
84       fprintf (FILE, "%s", TYPE_ASM_OP);                \
85       assemble_name (FILE, NAME);                       \
86       putc (',', FILE);                                 \
87       fprintf (FILE, TYPE_OPERAND_FMT, "function");     \
88       putc ('\n', FILE);                                \
89       ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));    \
90       ASM_OUTPUT_LABEL(FILE, NAME);                     \
91     }                                                   \
92   while (0)
93
94 /* Write the extra assembler code needed to declare an object properly.  */
95 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)               \
96   do                                                            \
97     {                                                           \
98       fprintf (FILE, "%s", TYPE_ASM_OP);                        \
99       assemble_name (FILE, NAME);                               \
100       putc (',', FILE);                                         \
101       fprintf (FILE, TYPE_OPERAND_FMT, "object");               \
102       putc ('\n', FILE);                                        \
103       size_directive_output = 0;                                \
104       if (!flag_inhibit_size_directive && DECL_SIZE (DECL))     \
105         {                                                       \
106           size_directive_output = 1;                            \
107           fprintf (FILE, "%s", SIZE_ASM_OP);                    \
108           assemble_name (FILE, NAME);                           \
109           putc (',', FILE);                                     \
110           fprintf (FILE, HOST_WIDE_INT_PRINT_DEC,               \
111                    int_size_in_bytes (TREE_TYPE (DECL)));       \
112           fputc ('\n', FILE);                                   \
113         }                                                       \
114       ASM_OUTPUT_LABEL(FILE, NAME);                             \
115     }                                                           \
116   while (0)
117
118 /* Output the size directive for a decl in rest_of_decl_compilation
119    in the case where we did not do so before the initializer.
120    Once we find the error_mark_node, we know that the value of
121    size_directive_output was set
122    by ASM_DECLARE_OBJECT_NAME when it was run for the same decl.  */
123 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)        \
124   do                                                                    \
125     {                                                                   \
126       const char * name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);          \
127       if (!flag_inhibit_size_directive && DECL_SIZE (DECL)              \
128           && ! AT_END && TOP_LEVEL                                      \
129           && DECL_INITIAL (DECL) == error_mark_node                     \
130           && !size_directive_output)                                    \
131         {                                                               \
132           size_directive_output = 1;                                    \
133           fprintf (FILE, "%s", SIZE_ASM_OP);                            \
134           assemble_name (FILE, name);                                   \
135           putc (',', FILE);                                             \
136           fprintf (FILE, HOST_WIDE_INT_PRINT_DEC,                       \
137                   int_size_in_bytes (TREE_TYPE (DECL)));                \
138          fputc ('\n', FILE);                                            \
139         }                                                               \
140     }                                                                   \
141   while (0)
142
143 /* This is how to declare the size of a function.  */
144 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)            \
145   do                                                            \
146     {                                                           \
147       ARM_DECLARE_FUNCTION_SIZE (FILE, FNAME, DECL);            \
148       if (!flag_inhibit_size_directive)                         \
149         {                                                       \
150           char label[256];                                      \
151           static int labelno;                                   \
152           labelno ++;                                           \
153           ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);  \
154           ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);     \
155           fprintf (FILE, "%s", SIZE_ASM_OP);                    \
156           assemble_name (FILE, (FNAME));                        \
157           fprintf (FILE, ",");                                  \
158           assemble_name (FILE, label);                          \
159           fprintf (FILE, "-");                                  \
160           assemble_name (FILE, (FNAME));                        \
161           putc ('\n', FILE);                                    \
162         }                                                       \
163     }                                                           \
164   while (0)
165
166 /* Define this macro if jump tables (for `tablejump' insns) should be
167    output in the text section, along with the assembler instructions.
168    Otherwise, the readonly data section is used.  */
169 #define JUMP_TABLES_IN_TEXT_SECTION 1
170
171 #ifndef LINK_SPEC
172 #define LINK_SPEC "%{mbig-endian:-EB} -X"
173 #endif
174   
175 /* Run-time Target Specification.  */
176 #ifndef TARGET_VERSION
177 #define TARGET_VERSION fputs (" (ARM/elf)", stderr)
178 #endif
179
180 #ifndef TARGET_DEFAULT
181 #define TARGET_DEFAULT (ARM_FLAG_SOFT_FLOAT | ARM_FLAG_APCS_32 | ARM_FLAG_APCS_FRAME)
182 #endif
183
184 #ifndef MULTILIB_DEFAULTS
185 #define MULTILIB_DEFAULTS \
186   { "marm", "mlittle-endian", "msoft-float", "mapcs-32", "mno-thumb-interwork", "fno-leading-underscore" }
187 #endif
188
189 /* A C expression whose value is nonzero if IDENTIFIER with arguments ARGS
190    is a valid machine specific attribute for DECL.
191    The attributes in ATTRIBUTES have previously been assigned to DECL.  */
192 #define VALID_MACHINE_DECL_ATTRIBUTE(DECL, ATTRIBUTES, IDENTIFIER, ARGS) \
193   arm_valid_machine_decl_attribute (DECL, IDENTIFIER, ARGS)
194 \f
195
196 /* A C statement to output assembler commands which will identify the
197    object file as having been compiled with GNU CC (or another GNU
198    compiler).  */
199 /* Define this to NULL so we don't get anything.
200    We have ASM_IDENTIFY_LANGUAGE.
201    Also, when using stabs, gcc2_compiled must be a stabs entry, not an
202    ordinary symbol, or gdb won't see it.  The stabs entry must be
203    before the N_SO in order for gdb to find it.  */
204 #ifndef ASM_IDENTIFY_GCC
205 #define ASM_IDENTIFY_GCC(STREAM)                                \
206   fprintf (STREAM, "%sgcc2_compiled.:\n", LOCAL_LABEL_PREFIX )
207 #endif
208
209 /* This outputs a lot of .req's to define alias for various registers.
210    Let's try to avoid this.  */
211 #ifndef ASM_FILE_START
212 #define ASM_FILE_START(STREAM)                                  \
213   do                                                            \
214     {                                                           \
215       fprintf (STREAM, "%s Generated by gcc %s for ARM/elf\n",  \
216                ASM_COMMENT_START, version_string);              \
217       output_file_directive (STREAM, main_input_filename);      \
218       fprintf (STREAM, ASM_APP_OFF);                            \
219     }                                                           \
220   while (0)
221 #endif
222
223 /* Output an internal label definition.  */
224 #ifndef ASM_OUTPUT_INTERNAL_LABEL
225 #define ASM_OUTPUT_INTERNAL_LABEL(STREAM, PREFIX, NUM)          \
226   do                                                            \
227     {                                                           \
228       char * s = (char *) alloca (40 + strlen (PREFIX));        \
229       extern int arm_target_label, arm_ccfsm_state;             \
230       extern rtx arm_target_insn;                               \
231                                                                 \
232       if (arm_ccfsm_state == 3 && arm_target_label == (NUM)     \
233         && !strcmp (PREFIX, "L"))                               \
234         {                                                       \
235           arm_ccfsm_state = 0;                                  \
236           arm_target_insn = NULL;                               \
237         }                                                       \
238         ASM_GENERATE_INTERNAL_LABEL (s, (PREFIX), (NUM));       \
239         ASM_OUTPUT_LABEL (STREAM, s);                           \
240     }                                                           \
241   while (0)
242 #endif
243 \f
244 /* Support the ctors/dtors and other sections.  */
245
246 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
247
248    Note that we want to give these sections the SHF_WRITE attribute
249    because these sections will actually contain data (i.e. tables of
250    addresses of functions in the current root executable or shared library
251    file) and, in the case of a shared library, the relocatable addresses
252    will have to be properly resolved/relocated (and then written into) by
253    the dynamic linker when it actually attaches the given shared library
254    to the executing process.  (Note that on SVR4, you may wish to use the
255    `-z text' option to the ELF linker, when building a shared library, as
256    an additional check that you are doing everything right.  But if you do
257    use the `-z text' option when building a shared library, you will get
258    errors unless the .ctors and .dtors sections are marked as writable
259    via the SHF_WRITE attribute.)  */
260 #ifndef CTORS_SECTION_ASM_OP
261 #define CTORS_SECTION_ASM_OP    "\t.section\t.ctors,\"aw\""
262 #endif
263      
264 #ifndef DTORS_SECTION_ASM_OP
265 #define DTORS_SECTION_ASM_OP    "\t.section\t.dtors,\"aw\""
266 #endif
267
268 /* A list of other sections which the compiler might be "in" at any
269    given time.  */
270 #ifndef SUBTARGET_EXTRA_SECTIONS
271 #define SUBTARGET_EXTRA_SECTIONS
272 #endif
273
274 #ifndef EXTRA_SECTIONS
275 #define EXTRA_SECTIONS SUBTARGET_EXTRA_SECTIONS in_ctors, in_dtors
276 #endif
277
278 /* A list of extra section function definitions.  */
279 #ifndef SUBTARGET_EXTRA_SECTION_FUNCTIONS
280 #define SUBTARGET_EXTRA_SECTION_FUNCTIONS
281 #endif
282
283 #ifndef EXTRA_SECTION_FUNCTIONS
284 #define EXTRA_SECTION_FUNCTIONS                 \
285   SUBTARGET_EXTRA_SECTION_FUNCTIONS             \
286   CTORS_SECTION_FUNCTION                        \
287   DTORS_SECTION_FUNCTION                        
288 #endif
289
290 #ifndef CTORS_SECTION_FUNCTION
291 #define CTORS_SECTION_FUNCTION                                  \
292 void                                                            \
293 ctors_section ()                                                \
294 {                                                               \
295   if (in_section != in_ctors)                                   \
296     {                                                           \
297       fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP);     \
298       in_section = in_ctors;                                    \
299     }                                                           \
300 }
301 #endif
302
303 #ifndef DTORS_SECTION_FUNCTION
304 #define DTORS_SECTION_FUNCTION                                  \
305 void                                                            \
306 dtors_section ()                                                \
307 {                                                               \
308   if (in_section != in_dtors)                                   \
309     {                                                           \
310       fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP);     \
311       in_section = in_dtors;                                    \
312     }                                                           \
313 }
314 #endif
315
316 /* A C statement to output something to the assembler file to switch to
317    section NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL
318    or NULL_TREE.  */
319 #undef  ASM_OUTPUT_SECTION_NAME
320 #define ASM_OUTPUT_SECTION_NAME(STREAM, DECL, NAME, RELOC)              \
321   do                                                                    \
322     {                                                                   \
323       if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL)                  \
324         fprintf (STREAM, "\t.section %s,\"ax\",%%progbits\n", NAME);    \
325       else if ((DECL) && DECL_READONLY_SECTION (DECL, RELOC))           \
326         fprintf (STREAM, "\t.section %s,\"a\"\n", NAME);                \
327       else if (! strncmp (NAME, ".bss", 4))                             \
328         fprintf (STREAM, "\t.section %s,\"aw\",%%nobits\n", NAME);      \
329       else                                                              \
330         fprintf (STREAM, "\t.section %s,\"aw\"\n", NAME);               \
331     }                                                                   \
332   while (0)
333 \f
334 /* Support the ctors/dtors sections for g++.  */
335 #ifndef INT_ASM_OP
336 #define INT_ASM_OP      "\t.word\t"
337 #endif
338
339 /* A C statement (sans semicolon) to output an element in the table of
340    global constructors.  */
341 #ifndef ASM_OUTPUT_CONSTRUCTOR
342 #define ASM_OUTPUT_CONSTRUCTOR(STREAM, NAME)    \
343   do                                            \
344     {                                           \
345       ctors_section ();                         \
346       fprintf (STREAM, "%s", INT_ASM_OP);       \
347       assemble_name (STREAM, NAME);             \
348       fprintf (STREAM, "\n");                   \
349     }                                           \
350   while (0)
351 #endif
352      
353 /* A C statement (sans semicolon) to output an element in the table of
354    global destructors.  */
355 #ifndef ASM_OUTPUT_DESTRUCTOR
356 #define ASM_OUTPUT_DESTRUCTOR(STREAM, NAME)     \
357   do                                            \
358     {                                           \
359       dtors_section ();                         \
360       fprintf (STREAM, "%s", INT_ASM_OP);       \
361       assemble_name (STREAM, NAME);             \
362       fprintf (STREAM, "\n");                   \
363     }                                           \
364   while (0)
365 #endif
366
367 /* This is how we tell the assembler that a symbol is weak.  */
368
369 #define ASM_WEAKEN_LABEL(FILE, NAME)            \
370   do                                            \
371     {                                           \
372       fputs ("\t.weak\t", FILE);                \
373       assemble_name (FILE, NAME);               \
374       fputc ('\n', FILE);                       \
375     }                                           \
376   while (0)
377
378 /* For PIC code we need to explicitly specify (PLT) and (GOT) relocs.  */
379 #define NEED_PLT_RELOC  flag_pic
380 #define NEED_GOT_RELOC  flag_pic
381
382 /* The ELF assembler handles GOT addressing differently to NetBSD.  */
383 #define GOT_PCREL       0
384
385 /* Biggest alignment supported by the object file format of this
386    machine.  Use this macro to limit the alignment which can be
387    specified using the `__attribute__ ((aligned (N)))' construct.  If
388    not defined, the default value is `BIGGEST_ALIGNMENT'.  */
389 #define MAX_OFILE_ALIGNMENT (32768 * 8)
390
391 /* Align output to a power of two.  Note ".align 0" is redundant,
392    and also GAS will treat it as ".align 2" which we do not want.  */
393 #define ASM_OUTPUT_ALIGN(STREAM, POWER)                 \
394   do                                                    \
395     {                                                   \
396       if ((POWER) > 0)                                  \
397         fprintf (STREAM, "\t.align\t%d\n", POWER);      \
398     }                                                   \
399   while (0)
400
401 #include "aout.h"