2000-05-02 Jeff Sturm <jsturm@one-point.com>
[official-gcc.git] / gcc / config / elfos.h
blobe7b9b811121307383d73fa21d36f300847132c1b
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
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)
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. */
24 /* The prefix to add to user-visible assembler symbols.
26 For ELF systems the convention is *not* to prepend a leading
27 underscore onto user-level symbol names. */
29 #undef USER_LABEL_PREFIX
30 #define USER_LABEL_PREFIX ""
32 /* Biggest alignment supported by the object file format of this
33 machine. Use this macro to limit the alignment which can be
34 specified using the `__attribute__ ((aligned (N)))' construct. If
35 not defined, the default value is `BIGGEST_ALIGNMENT'. */
36 #ifndef MAX_OFILE_ALIGNMENT
37 #define MAX_OFILE_ALIGNMENT (32768 * 8)
38 #endif
40 #undef ENDFILE_SPEC
41 #define ENDFILE_SPEC "crtend.o%s"
43 #undef STARTFILE_SPEC
44 #define STARTFILE_SPEC "%{!shared: \
45 %{!symbolic: \
46 %{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}}}\
47 crtbegin.o%s"
49 /* Use periods rather than dollar signs in special g++ assembler names. */
51 #define NO_DOLLAR_IN_LABEL
53 /* Writing `int' for a bitfield forces int alignment for the structure. */
55 #define PCC_BITFIELD_TYPE_MATTERS 1
57 /* Implicit library calls should use memcpy, not bcopy, etc. */
59 #define TARGET_MEM_FUNCTIONS
61 /* Handle #pragma weak and #pragma pack. */
63 #define HANDLE_SYSV_PRAGMA
65 /* System V Release 4 uses DWARF debugging info. */
67 #ifndef DWARF_DEBUGGING_INFO
68 #define DWARF_DEBUGGING_INFO 1
69 #endif
71 /* All ELF targets can support DWARF-2. */
73 #ifndef DWARF2_DEBUGGING_INFO
74 #define DWARF2_DEBUGGING_INFO 1
75 #endif
77 /* Also allow them to support STABS debugging. */
79 #include "dbxelf.h"
81 /* The GNU tools operate better with stabs. Since we don't have
82 any native tools to be compatible with, default to stabs. */
84 #ifndef PREFERRED_DEBUGGING_TYPE
85 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
86 #endif
88 /* All SVR4 targets use the ELF object file format. */
89 #define OBJECT_FORMAT_ELF
92 /* Output #ident as a .ident. */
94 #define ASM_OUTPUT_IDENT(FILE, NAME) \
95 fprintf (FILE, "%s\"%s\"\n", IDENT_ASM_OP, NAME);
97 #define IDENT_ASM_OP "\t.ident\t"
99 #undef ASM_BYTE_OP
100 #define ASM_BYTE_OP "\t.byte\t"
102 #undef SET_ASM_OP
103 #define SET_ASM_OP "\t.set\t"
105 /* This is how to begin an assembly language file. Most svr4 assemblers want
106 at least a .file directive to come first, and some want to see a .version
107 directive come right after that. Here we just establish a default
108 which generates only the .file directive. If you need a .version
109 directive for any specific target, you should override this definition
110 in the target-specific file which includes this one. */
112 #undef ASM_FILE_START
113 #define ASM_FILE_START(FILE) \
114 output_file_directive ((FILE), main_input_filename)
116 /* This is how to allocate empty space in some section. The .zero
117 pseudo-op is used for this on most svr4 assemblers. */
119 #define SKIP_ASM_OP "\t.zero\t"
121 #undef ASM_OUTPUT_SKIP
122 #define ASM_OUTPUT_SKIP(FILE, SIZE) \
123 fprintf (FILE, "%s%u\n", SKIP_ASM_OP, (SIZE))
125 /* This is how to output an internal numbered label where
126 PREFIX is the class of label and NUM is the number within the class.
128 For most svr4 systems, the convention is that any symbol which begins
129 with a period is not put into the linker symbol table by the assembler. */
131 #undef ASM_OUTPUT_INTERNAL_LABEL
132 #define ASM_OUTPUT_INTERNAL_LABEL(FILE, PREFIX, NUM) \
133 do \
135 fprintf (FILE, ".%s%d:\n", PREFIX, NUM); \
137 while (0)
139 /* This is how to store into the string LABEL
140 the symbol_ref name of an internal numbered label where
141 PREFIX is the class of label and NUM is the number within the class.
142 This is suitable for output with `assemble_name'.
144 For most svr4 systems, the convention is that any symbol which begins
145 with a period is not put into the linker symbol table by the assembler. */
147 #undef ASM_GENERATE_INTERNAL_LABEL
148 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
149 do \
151 sprintf (LABEL, "*.%s%u", PREFIX, (unsigned) (NUM)); \
153 while (0)
155 /* Output the label which precedes a jumptable. Note that for all svr4
156 systems where we actually generate jumptables (which is to say every
157 svr4 target except i386, where we use casesi instead) we put the jump-
158 tables into the .rodata section and since other stuff could have been
159 put into the .rodata section prior to any given jumptable, we have to
160 make sure that the location counter for the .rodata section gets pro-
161 perly re-aligned prior to the actual beginning of the jump table. */
163 #define ALIGN_ASM_OP "\t.align\t"
165 #ifndef ASM_OUTPUT_BEFORE_CASE_LABEL
166 #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE, PREFIX, NUM, TABLE) \
167 ASM_OUTPUT_ALIGN ((FILE), 2);
168 #endif
170 #undef ASM_OUTPUT_CASE_LABEL
171 #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE) \
172 do \
174 ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE) \
175 ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); \
177 while (0)
179 /* The standard SVR4 assembler seems to require that certain builtin
180 library routines (e.g. .udiv) be explicitly declared as .globl
181 in each assembly file where they are referenced. */
183 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
184 ASM_GLOBALIZE_LABEL (FILE, XSTR (FUN, 0))
186 /* This says how to output assembler code to declare an
187 uninitialized external 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 COMMON_ASM_OP "\t.comm\t"
193 #undef ASM_OUTPUT_ALIGNED_COMMON
194 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
195 do \
197 fprintf ((FILE), "%s", COMMON_ASM_OP); \
198 assemble_name ((FILE), (NAME)); \
199 fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT); \
201 while (0)
203 /* This says how to output assembler code to declare an
204 uninitialized internal linkage data object. Under SVR4,
205 the linker seems to want the alignment of data objects
206 to depend on their types. We do exactly that here. */
208 #define LOCAL_ASM_OP "\t.local\t"
210 #undef ASM_OUTPUT_ALIGNED_LOCAL
211 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
212 do \
214 fprintf ((FILE), "%s", LOCAL_ASM_OP); \
215 assemble_name ((FILE), (NAME)); \
216 fprintf ((FILE), "\n"); \
217 ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN); \
219 while (0)
221 /* This is the pseudo-op used to generate a reference to a specific
222 symbol in some section. It is only used in machine-specific
223 configuration files, typically only in ASM_OUTPUT_CONSTRUCTOR and
224 ASM_OUTPUT_DESTRUCTOR. This is the same for all known svr4
225 assemblers, except those in targets that don't use 32-bit pointers.
226 Those should override INT_ASM_OP. Yes, the name of the macro is
227 misleading. */
229 #ifndef INT_ASM_OP
230 #define INT_ASM_OP "\t.long\t"
231 #endif
233 /* This is the pseudo-op used to generate a contiguous sequence of byte
234 values from a double-quoted string WITHOUT HAVING A TERMINATING NUL
235 AUTOMATICALLY APPENDED. This is the same for most svr4 assemblers. */
237 #undef ASCII_DATA_ASM_OP
238 #define ASCII_DATA_ASM_OP "\t.ascii\t"
240 /* Support const sections and the ctors and dtors sections for g++.
241 Note that there appears to be two different ways to support const
242 sections at the moment. You can either #define the symbol
243 READONLY_DATA_SECTION (giving it some code which switches to the
244 readonly data section) or else you can #define the symbols
245 EXTRA_SECTIONS, EXTRA_SECTION_FUNCTIONS, SELECT_SECTION, and
246 SELECT_RTX_SECTION. We do both here just to be on the safe side. */
248 #define USE_CONST_SECTION 1
250 #define CONST_SECTION_ASM_OP "\t.section\t.rodata"
252 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
254 Note that we want to give these sections the SHF_WRITE attribute
255 because these sections will actually contain data (i.e. tables of
256 addresses of functions in the current root executable or shared library
257 file) and, in the case of a shared library, the relocatable addresses
258 will have to be properly resolved/relocated (and then written into) by
259 the dynamic linker when it actually attaches the given shared library
260 to the executing process. (Note that on SVR4, you may wish to use the
261 `-z text' option to the ELF linker, when building a shared library, as
262 an additional check that you are doing everything right. But if you do
263 use the `-z text' option when building a shared library, you will get
264 errors unless the .ctors and .dtors sections are marked as writable
265 via the SHF_WRITE attribute.) */
267 #define CTORS_SECTION_ASM_OP "\t.section\t.ctors,\"aw\""
268 #define DTORS_SECTION_ASM_OP "\t.section\t.dtors,\"aw\""
270 /* On svr4, we *do* have support for the .init and .fini sections, and we
271 can put stuff in there to be executed before and after `main'. We let
272 crtstuff.c and other files know this by defining the following symbols.
273 The definitions say how to change sections to the .init and .fini
274 sections. This is the same for all known svr4 assemblers. */
276 #define INIT_SECTION_ASM_OP "\t.section\t.init"
277 #define FINI_SECTION_ASM_OP "\t.section\t.fini"
279 /* A default list of other sections which we might be "in" at any given
280 time. For targets that use additional sections (e.g. .tdesc) you
281 should override this definition in the target-specific file which
282 includes this file. */
284 #undef EXTRA_SECTIONS
285 #define EXTRA_SECTIONS in_const, in_ctors, in_dtors
287 /* A default list of extra section function definitions. For targets
288 that use additional sections (e.g. .tdesc) you should override this
289 definition in the target-specific file which includes this file. */
291 #undef EXTRA_SECTION_FUNCTIONS
292 #define EXTRA_SECTION_FUNCTIONS \
293 CONST_SECTION_FUNCTION \
294 CTORS_SECTION_FUNCTION \
295 DTORS_SECTION_FUNCTION
297 #define READONLY_DATA_SECTION() const_section ()
299 #define CONST_SECTION_FUNCTION \
300 void \
301 const_section () \
303 if (!USE_CONST_SECTION) \
304 text_section (); \
305 else if (in_section != in_const) \
307 fprintf (asm_out_file, "%s\n", CONST_SECTION_ASM_OP); \
308 in_section = in_const; \
312 #define CTORS_SECTION_FUNCTION \
313 void \
314 ctors_section () \
316 if (in_section != in_ctors) \
318 fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP); \
319 in_section = in_ctors; \
323 #define DTORS_SECTION_FUNCTION \
324 void \
325 dtors_section () \
327 if (in_section != in_dtors) \
329 fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP); \
330 in_section = in_dtors; \
334 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
336 #define UNIQUE_SECTION_P(DECL) (DECL_ONE_ONLY (DECL))
338 #define UNIQUE_SECTION(DECL, RELOC) \
339 do \
341 int len; \
342 int sec; \
343 const char *name; \
344 char *string; \
345 const char *prefix; \
346 static const char *prefixes[/*4*/3][2] = \
348 { ".text.", ".gnu.linkonce.t." }, \
349 { ".rodata.", ".gnu.linkonce.r." }, \
350 { ".data.", ".gnu.linkonce.d." } \
351 /* Do not generate unique sections for uninitialised \
352 data since we do not have support for this in the \
353 linker scripts yet... \
354 ,{ ".bss.", ".gnu.linkonce.b." } */ \
355 }; \
357 if (TREE_CODE (DECL) == FUNCTION_DECL) \
358 sec = 0; \
359 /* else if (DECL_INITIAL (DECL) == 0 \
360 || DECL_INITIAL (DECL) == error_mark_node) \
361 sec = 3; */ \
362 else if (DECL_READONLY_SECTION (DECL, RELOC)) \
363 sec = 1; \
364 else \
365 sec = 2; \
367 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
368 /* Strip off any encoding in name. */ \
369 STRIP_NAME_ENCODING (name, name); \
370 prefix = prefixes[sec][DECL_ONE_ONLY(DECL)]; \
371 len = strlen (name) + strlen (prefix); \
372 string = alloca (len + 1); \
374 sprintf (string, "%s%s", prefix, name); \
376 DECL_SECTION_NAME (DECL) = build_string (len, string); \
378 while (0)
380 /* A C statement (sans semicolon) to output an
381 element in the table of global constructors. */
382 #define ASM_OUTPUT_CONSTRUCTOR(FILE, NAME) \
383 do \
385 ctors_section (); \
386 fprintf (FILE, "%s", INT_ASM_OP); \
387 assemble_name (FILE, NAME); \
388 fprintf (FILE, "\n"); \
390 while (0)
392 /* A C statement (sans semicolon) to output an
393 element in the table of global destructors. */
394 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \
395 do \
397 dtors_section (); \
398 fprintf (FILE, "%s", INT_ASM_OP); \
399 assemble_name (FILE, NAME); \
400 fprintf (FILE, "\n"); \
402 while (0)
404 /* Switch into a generic section.
406 We make the section read-only and executable for a function decl,
407 read-only for a const data decl, and writable for a non-const data decl.
409 If the section has already been defined, we must not
410 emit the attributes here. The SVR4 assembler does not
411 recognize section redefinitions.
412 If DECL is NULL, no attributes are emitted. */
414 #define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME, RELOC) \
415 do \
417 static htab_t htab; \
419 struct section_info \
421 enum sect_enum {SECT_RW, SECT_RO, SECT_EXEC} type; \
422 }; \
424 struct section_info *s; \
425 const char *mode; \
426 enum sect_enum type; \
427 PTR* slot; \
429 /* The names we put in the hashtable will always be the unique \
430 versions gived to us by the stringtable, so we can just use \
431 their addresses as the keys. */ \
432 if (!htab) \
433 htab = htab_create (31, \
434 htab_hash_pointer, \
435 htab_eq_pointer, \
436 NULL); \
438 if (DECL && TREE_CODE (DECL) == FUNCTION_DECL) \
439 type = SECT_EXEC, mode = "ax"; \
440 else if (DECL && DECL_READONLY_SECTION (DECL, RELOC)) \
441 type = SECT_RO, mode = "a"; \
442 else \
443 type = SECT_RW, mode = "aw"; \
446 /* See if we already have an entry for this section. */ \
447 slot = htab_find_slot (htab, NAME, INSERT); \
448 if (!*slot) \
450 s = (struct section_info *) xmalloc (sizeof (* s)); \
451 s->type = type; \
452 *slot = s; \
453 fprintf (FILE, "\t.section\t%s,\"%s\",@progbits\n", \
454 NAME, mode); \
456 else \
458 s = (struct section_info *) *slot; \
459 if (DECL && s->type != type) \
460 error_with_decl (DECL, \
461 "%s causes a section type conflict"); \
463 fprintf (FILE, "\t.section\t%s\n", NAME); \
466 while (0)
468 /* A C statement or statements to switch to the appropriate
469 section for output of RTX in mode MODE. RTX is some kind
470 of constant in RTL. The argument MODE is redundant except
471 in the case of a `const_int' rtx. Currently, these always
472 go into the const section. */
474 #undef SELECT_RTX_SECTION
475 #define SELECT_RTX_SECTION(MODE, RTX) const_section ()
477 /* A C statement or statements to switch to the appropriate
478 section for output of DECL. DECL is either a `VAR_DECL' node
479 or a constant of some sort. RELOC indicates whether forming
480 the initial value of DECL requires link-time relocations. */
482 #undef SELECT_SECTION
483 #define SELECT_SECTION(DECL, RELOC) \
485 if (TREE_CODE (DECL) == STRING_CST) \
487 if (! flag_writable_strings) \
488 const_section (); \
489 else \
490 data_section (); \
492 else if (TREE_CODE (DECL) == VAR_DECL) \
494 if ((flag_pic && RELOC) \
495 || !TREE_READONLY (DECL) || TREE_SIDE_EFFECTS (DECL) \
496 || !DECL_INITIAL (DECL) \
497 || (DECL_INITIAL (DECL) != error_mark_node \
498 && !TREE_CONSTANT (DECL_INITIAL (DECL)))) \
499 data_section (); \
500 else \
501 const_section (); \
503 else if (TREE_CODE (DECL) == CONSTRUCTOR) \
505 if ((flag_pic && RELOC) \
506 || !TREE_READONLY (DECL) || TREE_SIDE_EFFECTS (DECL) \
507 || ! TREE_CONSTANT (DECL)) \
508 data_section (); \
509 else \
510 const_section (); \
512 else \
513 const_section (); \
516 /* Define the strings used for the special svr4 .type and .size directives.
517 These strings generally do not vary from one system running svr4 to
518 another, but if a given system (e.g. m88k running svr) needs to use
519 different pseudo-op names for these, they may be overridden in the
520 file which includes this one. */
522 #define TYPE_ASM_OP "\t.type\t"
523 #define SIZE_ASM_OP "\t.size\t"
525 /* This is how we tell the assembler that a symbol is weak. */
527 #define ASM_WEAKEN_LABEL(FILE, NAME) \
528 do \
530 fputs ("\t.weak\t", (FILE)); \
531 assemble_name ((FILE), (NAME)); \
532 fputc ('\n', (FILE)); \
534 while (0)
536 /* The following macro defines the format used to output the second
537 operand of the .type assembler directive. Different svr4 assemblers
538 expect various different forms for this operand. The one given here
539 is just a default. You may need to override it in your machine-
540 specific tm.h file (depending upon the particulars of your assembler). */
542 #define TYPE_OPERAND_FMT "@%s"
544 /* Write the extra assembler code needed to declare a function's result.
545 Most svr4 assemblers don't require any special declaration of the
546 result value, but there are exceptions. */
548 #ifndef ASM_DECLARE_RESULT
549 #define ASM_DECLARE_RESULT(FILE, RESULT)
550 #endif
552 /* These macros generate the special .type and .size directives which
553 are used to set the corresponding fields of the linker symbol table
554 entries in an ELF object file under SVR4. These macros also output
555 the starting labels for the relevant functions/objects. */
557 /* Write the extra assembler code needed to declare a function properly.
558 Some svr4 assemblers need to also have something extra said about the
559 function's return value. We allow for that here. */
561 #ifndef ASM_DECLARE_FUNCTION_NAME
562 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
563 do \
565 fprintf (FILE, "%s", TYPE_ASM_OP); \
566 assemble_name (FILE, NAME); \
567 putc (',', FILE); \
568 fprintf (FILE, TYPE_OPERAND_FMT, "function"); \
569 putc ('\n', FILE); \
571 ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \
572 ASM_OUTPUT_LABEL(FILE, NAME); \
574 while (0)
575 #endif
577 /* Write the extra assembler code needed to declare an object properly. */
579 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
580 do \
582 fprintf (FILE, "%s", TYPE_ASM_OP); \
583 assemble_name (FILE, NAME); \
584 putc (',', FILE); \
585 fprintf (FILE, TYPE_OPERAND_FMT, "object"); \
586 putc ('\n', FILE); \
588 size_directive_output = 0; \
590 if (!flag_inhibit_size_directive \
591 && (DECL) && DECL_SIZE (DECL)) \
593 size_directive_output = 1; \
594 fprintf (FILE, "%s", SIZE_ASM_OP); \
595 assemble_name (FILE, NAME); \
596 putc (',', FILE); \
597 fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, \
598 int_size_in_bytes (TREE_TYPE (DECL))); \
599 fputc ('\n', FILE); \
602 ASM_OUTPUT_LABEL (FILE, NAME); \
604 while (0)
606 /* Output the size directive for a decl in rest_of_decl_compilation
607 in the case where we did not do so before the initializer.
608 Once we find the error_mark_node, we know that the value of
609 size_directive_output was set
610 by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */
612 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)\
613 do \
615 const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \
617 if (!flag_inhibit_size_directive \
618 && DECL_SIZE (DECL) \
619 && ! AT_END && TOP_LEVEL \
620 && DECL_INITIAL (DECL) == error_mark_node \
621 && !size_directive_output) \
623 size_directive_output = 1; \
624 fprintf (FILE, "%s", SIZE_ASM_OP); \
625 assemble_name (FILE, name); \
626 putc (',', FILE); \
627 fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, \
628 int_size_in_bytes (TREE_TYPE (DECL))); \
629 fputc ('\n', FILE); \
632 while (0)
634 /* This is how to declare the size of a function. */
635 #ifndef ASM_DECLARE_FUNCTION_SIZE
636 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \
637 do \
639 if (!flag_inhibit_size_directive) \
641 char label[256]; \
642 static int labelno; \
644 labelno++; \
646 ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno); \
647 ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno); \
649 fprintf (FILE, "%s", SIZE_ASM_OP); \
650 assemble_name (FILE, (FNAME)); \
651 fprintf (FILE, ","); \
652 assemble_name (FILE, label); \
653 fprintf (FILE, "-"); \
654 assemble_name (FILE, (FNAME)); \
655 putc ('\n', FILE); \
658 while (0)
659 #endif
661 /* A table of bytes codes used by the ASM_OUTPUT_ASCII and
662 ASM_OUTPUT_LIMITED_STRING macros. Each byte in the table
663 corresponds to a particular byte value [0..255]. For any
664 given byte value, if the value in the corresponding table
665 position is zero, the given character can be output directly.
666 If the table value is 1, the byte must be output as a \ooo
667 octal escape. If the tables value is anything else, then the
668 byte value should be output as a \ followed by the value
669 in the table. Note that we can use standard UN*X escape
670 sequences for many control characters, but we don't use
671 \a to represent BEL because some svr4 assemblers (e.g. on
672 the i386) don't know about that. Also, we don't use \v
673 since some versions of gas, such as 2.2 did not accept it. */
675 #define ESCAPES \
676 "\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\
677 \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\
678 \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\
679 \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\
680 \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\
681 \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\
682 \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\
683 \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"
685 /* Some svr4 assemblers have a limit on the number of characters which
686 can appear in the operand of a .string directive. If your assembler
687 has such a limitation, you should define STRING_LIMIT to reflect that
688 limit. Note that at least some svr4 assemblers have a limit on the
689 actual number of bytes in the double-quoted string, and that they
690 count each character in an escape sequence as one byte. Thus, an
691 escape sequence like \377 would count as four bytes.
693 If your target assembler doesn't support the .string directive, you
694 should define this to zero.
697 #define STRING_LIMIT ((unsigned) 256)
699 #define STRING_ASM_OP "\t.string\t"
701 /* The routine used to output NUL terminated strings. We use a special
702 version of this for most svr4 targets because doing so makes the
703 generated assembly code more compact (and thus faster to assemble)
704 as well as more readable, especially for targets like the i386
705 (where the only alternative is to output character sequences as
706 comma separated lists of numbers). */
708 #define ASM_OUTPUT_LIMITED_STRING(FILE, STR) \
709 do \
711 register const unsigned char *_limited_str = \
712 (const unsigned char *) (STR); \
713 register unsigned ch; \
715 fprintf ((FILE), "%s\"", STRING_ASM_OP); \
717 for (; (ch = *_limited_str); _limited_str++) \
719 register int escape; \
721 switch (escape = ESCAPES[ch]) \
723 case 0: \
724 putc (ch, (FILE)); \
725 break; \
726 case 1: \
727 fprintf ((FILE), "\\%03o", ch); \
728 break; \
729 default: \
730 putc ('\\', (FILE)); \
731 putc (escape, (FILE)); \
732 break; \
736 fprintf ((FILE), "\"\n"); \
738 while (0)
740 /* The routine used to output sequences of byte values. We use a special
741 version of this for most svr4 targets because doing so makes the
742 generated assembly code more compact (and thus faster to assemble)
743 as well as more readable. Note that if we find subparts of the
744 character sequence which end with NUL (and which are shorter than
745 STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING. */
747 #undef ASM_OUTPUT_ASCII
748 #define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \
749 do \
751 register const unsigned char *_ascii_bytes = \
752 (const unsigned char *) (STR); \
753 register const unsigned char *limit = _ascii_bytes + (LENGTH); \
754 register unsigned bytes_in_chunk = 0; \
756 for (; _ascii_bytes < limit; _ascii_bytes++) \
758 register const unsigned char *p; \
760 if (bytes_in_chunk >= 60) \
762 fprintf ((FILE), "\"\n"); \
763 bytes_in_chunk = 0; \
766 for (p = _ascii_bytes; p < limit && *p != '\0'; p++) \
767 continue; \
769 if (p < limit && (p - _ascii_bytes) <= (long)STRING_LIMIT) \
771 if (bytes_in_chunk > 0) \
773 fprintf ((FILE), "\"\n"); \
774 bytes_in_chunk = 0; \
777 ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes); \
778 _ascii_bytes = p; \
780 else \
782 register int escape; \
783 register unsigned ch; \
785 if (bytes_in_chunk == 0) \
786 fprintf ((FILE), "%s\"", ASCII_DATA_ASM_OP); \
788 switch (escape = ESCAPES[ch = *_ascii_bytes]) \
790 case 0: \
791 putc (ch, (FILE)); \
792 bytes_in_chunk++; \
793 break; \
794 case 1: \
795 fprintf ((FILE), "\\%03o", ch); \
796 bytes_in_chunk += 4; \
797 break; \
798 default: \
799 putc ('\\', (FILE)); \
800 putc (escape, (FILE)); \
801 bytes_in_chunk += 2; \
802 break; \
807 if (bytes_in_chunk > 0) \
808 fprintf ((FILE), "\"\n"); \
810 while (0)