1 /* elfos.h -- operating system specific defines to be used when
2 targeting GCC for some generic ELF system
3 Copyright (C) 1991, 1994, 1995, 1999, 2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
5 Based on svr4.h contributed by Ron Guilmette (rfg@netcom.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)
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. */
24 #define TARGET_OBJFMT_CPP_BUILTINS() \
27 builtin_define ("__ELF__"); \
31 /* Define a symbol indicating that we are using elfos.h.
32 Some CPU specific configuration files use this. */
35 /* The prefix to add to user-visible assembler symbols.
37 For ELF systems the convention is *not* to prepend a leading
38 underscore onto user-level symbol names. */
40 #undef USER_LABEL_PREFIX
41 #define USER_LABEL_PREFIX ""
43 /* Biggest alignment supported by the object file format of this
44 machine. Use this macro to limit the alignment which can be
45 specified using the `__attribute__ ((aligned (N)))' construct. If
46 not defined, the default value is `BIGGEST_ALIGNMENT'. */
47 #ifndef MAX_OFILE_ALIGNMENT
48 #define MAX_OFILE_ALIGNMENT (32768 * 8)
51 /* Use periods rather than dollar signs in special g++ assembler names. */
53 #define NO_DOLLAR_IN_LABEL
55 /* Writing `int' for a bit-field forces int alignment for the structure. */
57 #ifndef PCC_BITFIELD_TYPE_MATTERS
58 #define PCC_BITFIELD_TYPE_MATTERS 1
61 /* Implicit library calls should use memcpy, not bcopy, etc. */
63 #define TARGET_MEM_FUNCTIONS
65 /* Handle #pragma weak and #pragma pack. */
67 #define HANDLE_SYSV_PRAGMA 1
69 /* System V Release 4 uses DWARF debugging info. */
71 #define DWARF_DEBUGGING_INFO 1
73 /* All ELF targets can support DWARF-2. */
75 #define DWARF2_DEBUGGING_INFO 1
77 /* The GNU tools operate better with dwarf2, and it is required by some
78 psABI's. Since we don't have any native tools to be compatible with,
81 #ifndef PREFERRED_DEBUGGING_TYPE
82 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
85 /* All SVR4 targets use the ELF object file format. */
86 #define OBJECT_FORMAT_ELF
89 /* Output #ident as a .ident. */
91 #define ASM_OUTPUT_IDENT(FILE, NAME) \
92 fprintf (FILE, "%s\"%s\"\n", IDENT_ASM_OP, NAME);
94 #define IDENT_ASM_OP "\t.ident\t"
97 #define SET_ASM_OP "\t.set\t"
99 /* This is how to begin an assembly language file. Most svr4 assemblers want
100 at least a .file directive to come first, and some want to see a .version
101 directive come right after that. Here we just establish a default
102 which generates only the .file directive. If you need a .version
103 directive for any specific target, you should override this definition
104 in the target-specific file which includes this one. */
106 #undef ASM_FILE_START
107 #define ASM_FILE_START(FILE) \
108 output_file_directive ((FILE), main_input_filename)
110 /* This is how to allocate empty space in some section. The .zero
111 pseudo-op is used for this on most svr4 assemblers. */
113 #define SKIP_ASM_OP "\t.zero\t"
115 #undef ASM_OUTPUT_SKIP
116 #define ASM_OUTPUT_SKIP(FILE, SIZE) \
117 fprintf ((FILE), "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n",\
120 /* This is how to store into the string LABEL
121 the symbol_ref name of an internal numbered label where
122 PREFIX is the class of label and NUM is the number within the class.
123 This is suitable for output with `assemble_name'.
125 For most svr4 systems, the convention is that any symbol which begins
126 with a period is not put into the linker symbol table by the assembler. */
128 #undef ASM_GENERATE_INTERNAL_LABEL
129 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
132 sprintf (LABEL, "*.%s%u", PREFIX, (unsigned) (NUM)); \
136 /* Output the label which precedes a jumptable. Note that for all svr4
137 systems where we actually generate jumptables (which is to say every
138 svr4 target except i386, where we use casesi instead) we put the jump-
139 tables into the .rodata section and since other stuff could have been
140 put into the .rodata section prior to any given jumptable, we have to
141 make sure that the location counter for the .rodata section gets pro-
142 perly re-aligned prior to the actual beginning of the jump table. */
145 #define ALIGN_ASM_OP "\t.align\t"
147 #ifndef ASM_OUTPUT_BEFORE_CASE_LABEL
148 #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE, PREFIX, NUM, TABLE) \
149 ASM_OUTPUT_ALIGN ((FILE), 2);
152 #undef ASM_OUTPUT_CASE_LABEL
153 #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE) \
156 ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE) \
157 (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); \
161 /* The standard SVR4 assembler seems to require that certain builtin
162 library routines (e.g. .udiv) be explicitly declared as .globl
163 in each assembly file where they are referenced. */
165 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
166 (*targetm.asm_out.globalize_label) (FILE, XSTR (FUN, 0))
168 /* This says how to output assembler code to declare an
169 uninitialized external linkage data object. Under SVR4,
170 the linker seems to want the alignment of data objects
171 to depend on their types. We do exactly that here. */
173 #define COMMON_ASM_OP "\t.comm\t"
175 #undef ASM_OUTPUT_ALIGNED_COMMON
176 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
179 fprintf ((FILE), "%s", COMMON_ASM_OP); \
180 assemble_name ((FILE), (NAME)); \
181 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", \
182 (SIZE), (ALIGN) / BITS_PER_UNIT); \
186 /* This says how to output assembler code to declare an
187 uninitialized internal linkage data object. Under SVR4,
188 the linker seems to want the alignment of data objects
189 to depend on their types. We do exactly that here. */
191 #define LOCAL_ASM_OP "\t.local\t"
193 #undef ASM_OUTPUT_ALIGNED_LOCAL
194 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
197 fprintf ((FILE), "%s", LOCAL_ASM_OP); \
198 assemble_name ((FILE), (NAME)); \
199 fprintf ((FILE), "\n"); \
200 ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN); \
204 /* This is the pseudo-op used to generate a contiguous sequence of byte
205 values from a double-quoted string WITHOUT HAVING A TERMINATING NUL
206 AUTOMATICALLY APPENDED. This is the same for most svr4 assemblers. */
208 #undef ASCII_DATA_ASM_OP
209 #define ASCII_DATA_ASM_OP "\t.ascii\t"
211 /* Support a read-only data section. */
212 #define READONLY_DATA_SECTION_ASM_OP "\t.section\t.rodata"
214 /* On svr4, we *do* have support for the .init and .fini sections, and we
215 can put stuff in there to be executed before and after `main'. We let
216 crtstuff.c and other files know this by defining the following symbols.
217 The definitions say how to change sections to the .init and .fini
218 sections. This is the same for all known svr4 assemblers. */
220 #define INIT_SECTION_ASM_OP "\t.section\t.init"
221 #define FINI_SECTION_ASM_OP "\t.section\t.fini"
223 /* Output assembly directive to move to the beginning of current section. */
224 #ifdef HAVE_GAS_SUBSECTION_ORDERING
225 # define ASM_SECTION_START_OP "\t.subsection\t-1"
226 # define ASM_OUTPUT_SECTION_START(FILE) \
227 fprintf ((FILE), "%s\n", ASM_SECTION_START_OP)
230 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
232 /* Switch into a generic section. */
233 #define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section
235 #undef TARGET_ASM_SELECT_RTX_SECTION
236 #define TARGET_ASM_SELECT_RTX_SECTION default_elf_select_rtx_section
237 #undef TARGET_ASM_SELECT_SECTION
238 #define TARGET_ASM_SELECT_SECTION default_elf_select_section
240 /* Define the strings used for the special svr4 .type and .size directives.
241 These strings generally do not vary from one system running svr4 to
242 another, but if a given system (e.g. m88k running svr) needs to use
243 different pseudo-op names for these, they may be overridden in the
244 file which includes this one. */
246 #define TYPE_ASM_OP "\t.type\t"
247 #define SIZE_ASM_OP "\t.size\t"
249 /* This is how we tell the assembler that a symbol is weak. */
251 #define ASM_WEAKEN_LABEL(FILE, NAME) \
254 fputs ("\t.weak\t", (FILE)); \
255 assemble_name ((FILE), (NAME)); \
256 fputc ('\n', (FILE)); \
260 /* The following macro defines the format used to output the second
261 operand of the .type assembler directive. Different svr4 assemblers
262 expect various different forms for this operand. The one given here
263 is just a default. You may need to override it in your machine-
264 specific tm.h file (depending upon the particulars of your assembler). */
266 #define TYPE_OPERAND_FMT "@%s"
268 /* Write the extra assembler code needed to declare a function's result.
269 Most svr4 assemblers don't require any special declaration of the
270 result value, but there are exceptions. */
272 #ifndef ASM_DECLARE_RESULT
273 #define ASM_DECLARE_RESULT(FILE, RESULT)
276 /* These macros generate the special .type and .size directives which
277 are used to set the corresponding fields of the linker symbol table
278 entries in an ELF object file under SVR4. These macros also output
279 the starting labels for the relevant functions/objects. */
281 /* Write the extra assembler code needed to declare a function properly.
282 Some svr4 assemblers need to also have something extra said about the
283 function's return value. We allow for that here. */
285 #ifndef ASM_DECLARE_FUNCTION_NAME
286 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
289 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
290 ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \
291 ASM_OUTPUT_LABEL (FILE, NAME); \
296 /* Write the extra assembler code needed to declare an object properly. */
298 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
301 HOST_WIDE_INT size; \
303 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
305 size_directive_output = 0; \
306 if (!flag_inhibit_size_directive \
307 && (DECL) && DECL_SIZE (DECL)) \
309 size_directive_output = 1; \
310 size = int_size_in_bytes (TREE_TYPE (DECL)); \
311 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size); \
314 ASM_OUTPUT_LABEL (FILE, NAME); \
318 /* Output the size directive for a decl in rest_of_decl_compilation
319 in the case where we did not do so before the initializer.
320 Once we find the error_mark_node, we know that the value of
321 size_directive_output was set
322 by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */
324 #undef ASM_FINISH_DECLARE_OBJECT
325 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)\
328 const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \
329 HOST_WIDE_INT size; \
331 if (!flag_inhibit_size_directive \
332 && DECL_SIZE (DECL) \
333 && ! AT_END && TOP_LEVEL \
334 && DECL_INITIAL (DECL) == error_mark_node \
335 && !size_directive_output) \
337 size_directive_output = 1; \
338 size = int_size_in_bytes (TREE_TYPE (DECL)); \
339 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size); \
344 /* This is how to declare the size of a function. */
345 #ifndef ASM_DECLARE_FUNCTION_SIZE
346 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \
349 if (!flag_inhibit_size_directive) \
350 ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME); \
355 /* A table of bytes codes used by the ASM_OUTPUT_ASCII and
356 ASM_OUTPUT_LIMITED_STRING macros. Each byte in the table
357 corresponds to a particular byte value [0..255]. For any
358 given byte value, if the value in the corresponding table
359 position is zero, the given character can be output directly.
360 If the table value is 1, the byte must be output as a \ooo
361 octal escape. If the tables value is anything else, then the
362 byte value should be output as a \ followed by the value
363 in the table. Note that we can use standard UN*X escape
364 sequences for many control characters, but we don't use
365 \a to represent BEL because some svr4 assemblers (e.g. on
366 the i386) don't know about that. Also, we don't use \v
367 since some versions of gas, such as 2.2 did not accept it. */
370 "\1\1\1\1\1\1\1\1btn\1fr\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
371 \0\0\"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
372 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\0\0\0\
373 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\
374 \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
375 \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
376 \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
377 \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"
379 /* Some svr4 assemblers have a limit on the number of characters which
380 can appear in the operand of a .string directive. If your assembler
381 has such a limitation, you should define STRING_LIMIT to reflect that
382 limit. Note that at least some svr4 assemblers have a limit on the
383 actual number of bytes in the double-quoted string, and that they
384 count each character in an escape sequence as one byte. Thus, an
385 escape sequence like \377 would count as four bytes.
387 If your target assembler doesn't support the .string directive, you
388 should define this to zero.
391 #define STRING_LIMIT ((unsigned) 256)
393 #define STRING_ASM_OP "\t.string\t"
395 /* The routine used to output NUL terminated strings. We use a special
396 version of this for most svr4 targets because doing so makes the
397 generated assembly code more compact (and thus faster to assemble)
398 as well as more readable, especially for targets like the i386
399 (where the only alternative is to output character sequences as
400 comma separated lists of numbers). */
402 #define ASM_OUTPUT_LIMITED_STRING(FILE, STR) \
405 register const unsigned char *_limited_str = \
406 (const unsigned char *) (STR); \
407 register unsigned ch; \
409 fprintf ((FILE), "%s\"", STRING_ASM_OP); \
411 for (; (ch = *_limited_str); _limited_str++) \
413 register int escape; \
415 switch (escape = ESCAPES[ch]) \
421 fprintf ((FILE), "\\%03o", ch); \
424 putc ('\\', (FILE)); \
425 putc (escape, (FILE)); \
430 fprintf ((FILE), "\"\n"); \
434 /* The routine used to output sequences of byte values. We use a special
435 version of this for most svr4 targets because doing so makes the
436 generated assembly code more compact (and thus faster to assemble)
437 as well as more readable. Note that if we find subparts of the
438 character sequence which end with NUL (and which are shorter than
439 STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING. */
441 #undef ASM_OUTPUT_ASCII
442 #define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \
445 register const unsigned char *_ascii_bytes = \
446 (const unsigned char *) (STR); \
447 register const unsigned char *limit = _ascii_bytes + (LENGTH); \
448 register unsigned bytes_in_chunk = 0; \
450 for (; _ascii_bytes < limit; _ascii_bytes++) \
452 register const unsigned char *p; \
454 if (bytes_in_chunk >= 60) \
456 fprintf ((FILE), "\"\n"); \
457 bytes_in_chunk = 0; \
460 for (p = _ascii_bytes; p < limit && *p != '\0'; p++) \
463 if (p < limit && (p - _ascii_bytes) <= (long)STRING_LIMIT) \
465 if (bytes_in_chunk > 0) \
467 fprintf ((FILE), "\"\n"); \
468 bytes_in_chunk = 0; \
471 ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes); \
476 register int escape; \
477 register unsigned ch; \
479 if (bytes_in_chunk == 0) \
480 fprintf ((FILE), "%s\"", ASCII_DATA_ASM_OP); \
482 switch (escape = ESCAPES[ch = *_ascii_bytes]) \
489 fprintf ((FILE), "\\%03o", ch); \
490 bytes_in_chunk += 4; \
493 putc ('\\', (FILE)); \
494 putc (escape, (FILE)); \
495 bytes_in_chunk += 2; \
501 if (bytes_in_chunk > 0) \
502 fprintf ((FILE), "\"\n"); \