xref: /openbsd-src/gnu/usr.bin/gcc/gcc/config/elfos.h (revision c87b03e512fc05ed6e0222f6fb0ae86264b1d05b)
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
4    Free Software Foundation, Inc.
5    Based on svr4.h contributed by Ron Guilmette (rfg@netcom.com).
6 
7 This file is part of GNU CC.
8 
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.
13 
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.
18 
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.  */
23 
24 
25 /* Define a symbol indicating that we are using elfos.h.
26    Some CPU specific configuration files use this.  */
27 #define USING_ELFOS_H
28 
29 /* The prefix to add to user-visible assembler symbols.
30 
31    For ELF systems the convention is *not* to prepend a leading
32    underscore onto user-level symbol names.  */
33 
34 #undef  USER_LABEL_PREFIX
35 #define USER_LABEL_PREFIX ""
36 
37 /* Biggest alignment supported by the object file format of this
38    machine.  Use this macro to limit the alignment which can be
39    specified using the `__attribute__ ((aligned (N)))' construct.  If
40    not defined, the default value is `BIGGEST_ALIGNMENT'.  */
41 #ifndef MAX_OFILE_ALIGNMENT
42 #define MAX_OFILE_ALIGNMENT (32768 * 8)
43 #endif
44 
45 /* Use periods rather than dollar signs in special g++ assembler names.  */
46 
47 #define NO_DOLLAR_IN_LABEL
48 
49 /* Writing `int' for a bit-field forces int alignment for the structure.  */
50 
51 #ifndef PCC_BITFIELD_TYPE_MATTERS
52 #define PCC_BITFIELD_TYPE_MATTERS 1
53 #endif
54 
55 /* Implicit library calls should use memcpy, not bcopy, etc.  */
56 
57 #define TARGET_MEM_FUNCTIONS
58 
59 /* Handle #pragma weak and #pragma pack.  */
60 
61 #define HANDLE_SYSV_PRAGMA 1
62 
63 /* System V Release 4 uses DWARF debugging info.  */
64 
65 #define DWARF_DEBUGGING_INFO 1
66 
67 /* All ELF targets can support DWARF-2.  */
68 
69 #define DWARF2_DEBUGGING_INFO 1
70 
71 /* The GNU tools operate better with dwarf2, and it is required by some
72    psABI's.  Since we don't have any native tools to be compatible with,
73    default to dwarf2.  */
74 
75 #ifndef PREFERRED_DEBUGGING_TYPE
76 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
77 #endif
78 
79 /* All SVR4 targets use the ELF object file format.  */
80 #define OBJECT_FORMAT_ELF
81 
82 
83 /* Output #ident as a .ident.  */
84 
85 #define ASM_OUTPUT_IDENT(FILE, NAME) \
86   fprintf (FILE, "%s\"%s\"\n", IDENT_ASM_OP, NAME);
87 
88 #define IDENT_ASM_OP "\t.ident\t"
89 
90 #undef  SET_ASM_OP
91 #define SET_ASM_OP	"\t.set\t"
92 
93 /* This is how to begin an assembly language file.  Most svr4 assemblers want
94    at least a .file directive to come first, and some want to see a .version
95    directive come right after that.  Here we just establish a default
96    which generates only the .file directive.  If you need a .version
97    directive for any specific target, you should override this definition
98    in the target-specific file which includes this one.  */
99 
100 #undef ASM_FILE_START
101 #define ASM_FILE_START(FILE)                            \
102   output_file_directive ((FILE), main_input_filename)
103 
104 /* This is how to allocate empty space in some section.  The .zero
105    pseudo-op is used for this on most svr4 assemblers.  */
106 
107 #define SKIP_ASM_OP	"\t.zero\t"
108 
109 #undef  ASM_OUTPUT_SKIP
110 #define ASM_OUTPUT_SKIP(FILE, SIZE) \
111   fprintf (FILE, "%s%u\n", SKIP_ASM_OP, (SIZE))
112 
113 /* This is how to output an internal numbered label where
114    PREFIX is the class of label and NUM is the number within the class.
115 
116    For most svr4 systems, the convention is that any symbol which begins
117    with a period is not put into the linker symbol table by the assembler.  */
118 
119 #undef  ASM_OUTPUT_INTERNAL_LABEL
120 #define ASM_OUTPUT_INTERNAL_LABEL(FILE, PREFIX, NUM)		\
121   do								\
122     {								\
123       fprintf (FILE, ".%s%u:\n", PREFIX, (unsigned) (NUM));	\
124     }								\
125   while (0)
126 
127 /* This is how to store into the string LABEL
128    the symbol_ref name of an internal numbered label where
129    PREFIX is the class of label and NUM is the number within the class.
130    This is suitable for output with `assemble_name'.
131 
132    For most svr4 systems, the convention is that any symbol which begins
133    with a period is not put into the linker symbol table by the assembler.  */
134 
135 #undef  ASM_GENERATE_INTERNAL_LABEL
136 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM)		\
137   do								\
138     {								\
139       sprintf (LABEL, "*.%s%u", PREFIX, (unsigned) (NUM));	\
140     }								\
141   while (0)
142 
143 /* Output the label which precedes a jumptable.  Note that for all svr4
144    systems where we actually generate jumptables (which is to say every
145    svr4 target except i386, where we use casesi instead) we put the jump-
146    tables into the .rodata section and since other stuff could have been
147    put into the .rodata section prior to any given jumptable, we have to
148    make sure that the location counter for the .rodata section gets pro-
149    perly re-aligned prior to the actual beginning of the jump table.  */
150 
151 #undef ALIGN_ASM_OP
152 #define ALIGN_ASM_OP "\t.align\t"
153 
154 #ifndef ASM_OUTPUT_BEFORE_CASE_LABEL
155 #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE, PREFIX, NUM, TABLE) \
156   ASM_OUTPUT_ALIGN ((FILE), 2);
157 #endif
158 
159 #undef  ASM_OUTPUT_CASE_LABEL
160 #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE)		\
161   do									\
162     {									\
163       ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE)	\
164 	ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM);			\
165     }									\
166   while (0)
167 
168 /* The standard SVR4 assembler seems to require that certain builtin
169    library routines (e.g. .udiv) be explicitly declared as .globl
170    in each assembly file where they are referenced.  */
171 
172 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN)	\
173   (*targetm.asm_out.globalize_label) (FILE, XSTR (FUN, 0))
174 
175 /* This says how to output assembler code to declare an
176    uninitialized external linkage data object.  Under SVR4,
177    the linker seems to want the alignment of data objects
178    to depend on their types.  We do exactly that here.  */
179 
180 #define COMMON_ASM_OP	"\t.comm\t"
181 
182 #undef  ASM_OUTPUT_ALIGNED_COMMON
183 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)		\
184   do									\
185     {									\
186       fprintf ((FILE), "%s", COMMON_ASM_OP);				\
187       assemble_name ((FILE), (NAME));					\
188       fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT);	\
189     }									\
190   while (0)
191 
192 /* This says how to output assembler code to declare an
193    uninitialized internal linkage data object.  Under SVR4,
194    the linker seems to want the alignment of data objects
195    to depend on their types.  We do exactly that here.  */
196 
197 #define LOCAL_ASM_OP	"\t.local\t"
198 
199 #undef  ASM_OUTPUT_ALIGNED_LOCAL
200 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)	\
201   do								\
202     {								\
203       fprintf ((FILE), "%s", LOCAL_ASM_OP);			\
204       assemble_name ((FILE), (NAME));				\
205       fprintf ((FILE), "\n");					\
206       ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN);	\
207     }								\
208   while (0)
209 
210 /* This is the pseudo-op used to generate a contiguous sequence of byte
211    values from a double-quoted string WITHOUT HAVING A TERMINATING NUL
212    AUTOMATICALLY APPENDED.  This is the same for most svr4 assemblers.  */
213 
214 #undef  ASCII_DATA_ASM_OP
215 #define ASCII_DATA_ASM_OP	"\t.ascii\t"
216 
217 /* Support a read-only data section.  */
218 #define READONLY_DATA_SECTION_ASM_OP	"\t.section\t.rodata"
219 
220 /* On svr4, we *do* have support for the .init and .fini sections, and we
221    can put stuff in there to be executed before and after `main'.  We let
222    crtstuff.c and other files know this by defining the following symbols.
223    The definitions say how to change sections to the .init and .fini
224    sections.  This is the same for all known svr4 assemblers.  */
225 
226 #define INIT_SECTION_ASM_OP	"\t.section\t.init"
227 #define FINI_SECTION_ASM_OP	"\t.section\t.fini"
228 
229 /* Output assembly directive to move to the beginning of current section.  */
230 #ifdef HAVE_GAS_SUBSECTION_ORDERING
231 # define ASM_SECTION_START_OP	"\t.subsection\t-1"
232 # define ASM_OUTPUT_SECTION_START(FILE)	\
233   fprintf ((FILE), "%s\n", ASM_SECTION_START_OP)
234 #endif
235 
236 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
237 
238 /* Switch into a generic section.  */
239 #define TARGET_ASM_NAMED_SECTION  default_elf_asm_named_section
240 
241 #undef  TARGET_ASM_SELECT_RTX_SECTION
242 #define TARGET_ASM_SELECT_RTX_SECTION default_elf_select_rtx_section
243 #undef	TARGET_ASM_SELECT_SECTION
244 #define TARGET_ASM_SELECT_SECTION default_elf_select_section
245 
246 /* Define the strings used for the special svr4 .type and .size directives.
247    These strings generally do not vary from one system running svr4 to
248    another, but if a given system (e.g. m88k running svr) needs to use
249    different pseudo-op names for these, they may be overridden in the
250    file which includes this one.  */
251 
252 #define TYPE_ASM_OP	"\t.type\t"
253 #define SIZE_ASM_OP	"\t.size\t"
254 
255 /* This is how we tell the assembler that a symbol is weak.  */
256 
257 #define ASM_WEAKEN_LABEL(FILE, NAME) 	\
258   do					\
259     {					\
260       fputs ("\t.weak\t", (FILE));	\
261       assemble_name ((FILE), (NAME)); 	\
262       fputc ('\n', (FILE));		\
263     }					\
264   while (0)
265 
266 /* The following macro defines the format used to output the second
267    operand of the .type assembler directive.  Different svr4 assemblers
268    expect various different forms for this operand.  The one given here
269    is just a default.  You may need to override it in your machine-
270    specific tm.h file (depending upon the particulars of your assembler).  */
271 
272 #define TYPE_OPERAND_FMT	"@%s"
273 
274 /* Write the extra assembler code needed to declare a function's result.
275    Most svr4 assemblers don't require any special declaration of the
276    result value, but there are exceptions.  */
277 
278 #ifndef ASM_DECLARE_RESULT
279 #define ASM_DECLARE_RESULT(FILE, RESULT)
280 #endif
281 
282 /* These macros generate the special .type and .size directives which
283    are used to set the corresponding fields of the linker symbol table
284    entries in an ELF object file under SVR4.  These macros also output
285    the starting labels for the relevant functions/objects.  */
286 
287 /* Write the extra assembler code needed to declare a function properly.
288    Some svr4 assemblers need to also have something extra said about the
289    function's return value.  We allow for that here.  */
290 
291 #ifndef ASM_DECLARE_FUNCTION_NAME
292 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)		\
293   do								\
294     {								\
295       ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");	\
296       ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));		\
297       ASM_OUTPUT_LABEL (FILE, NAME);				\
298     }								\
299   while (0)
300 #endif
301 
302 /* Write the extra assembler code needed to declare an object properly.  */
303 
304 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)		\
305   do								\
306     {								\
307       HOST_WIDE_INT size;					\
308 								\
309       ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");		\
310 								\
311       size_directive_output = 0;				\
312       if (!flag_inhibit_size_directive				\
313 	  && (DECL) && DECL_SIZE (DECL))			\
314 	{							\
315 	  size_directive_output = 1;				\
316 	  size = int_size_in_bytes (TREE_TYPE (DECL));		\
317 	  ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size);		\
318 	}							\
319 								\
320       ASM_OUTPUT_LABEL (FILE, NAME);				\
321     }								\
322   while (0)
323 
324 /* Output the size directive for a decl in rest_of_decl_compilation
325    in the case where we did not do so before the initializer.
326    Once we find the error_mark_node, we know that the value of
327    size_directive_output was set
328    by ASM_DECLARE_OBJECT_NAME when it was run for the same decl.  */
329 
330 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)\
331   do								\
332     {								\
333       const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);	\
334       HOST_WIDE_INT size;					\
335       								\
336       if (!flag_inhibit_size_directive				\
337 	  && DECL_SIZE (DECL)					\
338 	  && ! AT_END && TOP_LEVEL				\
339 	  && DECL_INITIAL (DECL) == error_mark_node		\
340 	  && !size_directive_output)				\
341 	{							\
342 	  size_directive_output = 1;				\
343 	  size = int_size_in_bytes (TREE_TYPE (DECL));		\
344 	  ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size);		\
345 	}							\
346     }								\
347   while (0)
348 
349 /* This is how to declare the size of a function.  */
350 #ifndef ASM_DECLARE_FUNCTION_SIZE
351 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
352   do								\
353     {								\
354       if (!flag_inhibit_size_directive)				\
355 	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
356     }								\
357   while (0)
358 #endif
359 
360 /* A table of bytes codes used by the ASM_OUTPUT_ASCII and
361    ASM_OUTPUT_LIMITED_STRING macros.  Each byte in the table
362    corresponds to a particular byte value [0..255].  For any
363    given byte value, if the value in the corresponding table
364    position is zero, the given character can be output directly.
365    If the table value is 1, the byte must be output as a \ooo
366    octal escape.  If the tables value is anything else, then the
367    byte value should be output as a \ followed by the value
368    in the table.  Note that we can use standard UN*X escape
369    sequences for many control characters, but we don't use
370    \a to represent BEL because some svr4 assemblers (e.g. on
371    the i386) don't know about that.  Also, we don't use \v
372    since some versions of gas, such as 2.2 did not accept it.  */
373 
374 #define ESCAPES \
375 "\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\
376 \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\
377 \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\
378 \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\
379 \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\
380 \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\
381 \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\
382 \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"
383 
384 /* Some svr4 assemblers have a limit on the number of characters which
385    can appear in the operand of a .string directive.  If your assembler
386    has such a limitation, you should define STRING_LIMIT to reflect that
387    limit.  Note that at least some svr4 assemblers have a limit on the
388    actual number of bytes in the double-quoted string, and that they
389    count each character in an escape sequence as one byte.  Thus, an
390    escape sequence like \377 would count as four bytes.
391 
392    If your target assembler doesn't support the .string directive, you
393    should define this to zero.
394 */
395 
396 #define STRING_LIMIT	((unsigned) 256)
397 
398 #define STRING_ASM_OP	"\t.string\t"
399 
400 /* The routine used to output NUL terminated strings.  We use a special
401    version of this for most svr4 targets because doing so makes the
402    generated assembly code more compact (and thus faster to assemble)
403    as well as more readable, especially for targets like the i386
404    (where the only alternative is to output character sequences as
405    comma separated lists of numbers).  */
406 
407 #define ASM_OUTPUT_LIMITED_STRING(FILE, STR)		\
408   do							\
409     {							\
410       register const unsigned char *_limited_str =	\
411 	(const unsigned char *) (STR);			\
412       register unsigned ch;				\
413       							\
414       fprintf ((FILE), "%s\"", STRING_ASM_OP);		\
415       							\
416       for (; (ch = *_limited_str); _limited_str++)	\
417         {						\
418 	  register int escape;				\
419 	  						\
420 	  switch (escape = ESCAPES[ch])			\
421 	    {						\
422 	    case 0:					\
423 	      putc (ch, (FILE));			\
424 	      break;					\
425 	    case 1:					\
426 	      fprintf ((FILE), "\\%03o", ch);		\
427 	      break;					\
428 	    default:					\
429 	      putc ('\\', (FILE));			\
430 	      putc (escape, (FILE));			\
431 	      break;					\
432 	    }						\
433         }						\
434       							\
435       fprintf ((FILE), "\"\n");				\
436     }							\
437   while (0)
438 
439 /* The routine used to output sequences of byte values.  We use a special
440    version of this for most svr4 targets because doing so makes the
441    generated assembly code more compact (and thus faster to assemble)
442    as well as more readable.  Note that if we find subparts of the
443    character sequence which end with NUL (and which are shorter than
444    STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING.  */
445 
446 #undef  ASM_OUTPUT_ASCII
447 #define ASM_OUTPUT_ASCII(FILE, STR, LENGTH)				\
448   do									\
449     {									\
450       register const unsigned char *_ascii_bytes =			\
451 	(const unsigned char *) (STR);					\
452       register const unsigned char *limit = _ascii_bytes + (LENGTH);	\
453       register unsigned bytes_in_chunk = 0;				\
454 									\
455       for (; _ascii_bytes < limit; _ascii_bytes++)			\
456         {								\
457 	  register const unsigned char *p;				\
458       									\
459 	  if (bytes_in_chunk >= 60)					\
460 	    {								\
461 	      fprintf ((FILE), "\"\n");					\
462 	      bytes_in_chunk = 0;					\
463 	    }								\
464       									\
465 	  for (p = _ascii_bytes; p < limit && *p != '\0'; p++)		\
466 	    continue;							\
467       									\
468 	  if (p < limit && (p - _ascii_bytes) <= (long)STRING_LIMIT)	\
469 	    {								\
470 	      if (bytes_in_chunk > 0)					\
471 		{							\
472 		  fprintf ((FILE), "\"\n");				\
473 		  bytes_in_chunk = 0;					\
474 		}							\
475       									\
476 	      ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes);		\
477 	      _ascii_bytes = p;						\
478 	    }								\
479 	  else								\
480 	    {								\
481 	      register int escape;					\
482 	      register unsigned ch;					\
483       									\
484 	      if (bytes_in_chunk == 0)					\
485 		fprintf ((FILE), "%s\"", ASCII_DATA_ASM_OP);		\
486       									\
487 	      switch (escape = ESCAPES[ch = *_ascii_bytes])		\
488 		{							\
489 		case 0:							\
490 		  putc (ch, (FILE));					\
491 		  bytes_in_chunk++;					\
492 		  break;						\
493 		case 1:							\
494 		  fprintf ((FILE), "\\%03o", ch);			\
495 		  bytes_in_chunk += 4;					\
496 		  break;						\
497 		default:						\
498 		  putc ('\\', (FILE));					\
499 		  putc (escape, (FILE));				\
500 		  bytes_in_chunk += 2;					\
501 		  break;						\
502 		}							\
503 	    }								\
504 	}								\
505       									\
506       if (bytes_in_chunk > 0)						\
507         fprintf ((FILE), "\"\n");					\
508     }									\
509   while (0)
510