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