OSDN Git Service

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