1 /* Dwarf2 assembler output helper routines.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
30 #include "dwarf2asm.h"
32 #include "splay-tree.h"
37 /* How to start an assembler comment. */
38 #ifndef ASM_COMMENT_START
39 #define ASM_COMMENT_START ";#"
43 /* Output an unaligned integer with the given value and size. Prefer not
44 to print a newline, since the caller may want to add a comment. */
47 dw2_assemble_integer (int size
, rtx x
)
49 const char *op
= integer_asm_op (size
, FALSE
);
53 fputs (op
, asm_out_file
);
54 if (GET_CODE (x
) == CONST_INT
)
55 fprintf (asm_out_file
, HOST_WIDE_INT_PRINT_HEX
,
56 (unsigned HOST_WIDE_INT
) INTVAL (x
));
58 output_addr_const (asm_out_file
, x
);
61 assemble_integer (x
, size
, BITS_PER_UNIT
, 1);
65 /* Output a value of a given size in target byte order. */
68 dw2_asm_output_data_raw (int size
, unsigned HOST_WIDE_INT value
)
70 unsigned char bytes
[8];
73 for (i
= 0; i
< 8; ++i
)
75 bytes
[i
] = value
& 0xff;
81 for (i
= size
- 1; i
> 0; --i
)
82 fprintf (asm_out_file
, "0x%x,", bytes
[i
]);
83 fprintf (asm_out_file
, "0x%x", bytes
[0]);
87 for (i
= 0; i
< size
- 1; ++i
)
88 fprintf (asm_out_file
, "0x%x,", bytes
[i
]);
89 fprintf (asm_out_file
, "0x%x", bytes
[i
]);
93 /* Output an immediate constant in a given SIZE in bytes. */
96 dw2_asm_output_data (int size
, unsigned HOST_WIDE_INT value
,
97 const char *comment
, ...)
100 const char *op
= integer_asm_op (size
, FALSE
);
102 va_start (ap
, comment
);
104 if (size
* 8 < HOST_BITS_PER_WIDE_INT
)
105 value
&= ~(~(unsigned HOST_WIDE_INT
) 0 << (size
* 8));
108 fprintf (asm_out_file
, "%s" HOST_WIDE_INT_PRINT_HEX
, op
, value
);
110 assemble_integer (GEN_INT (value
), size
, BITS_PER_UNIT
, 1);
112 if (flag_debug_asm
&& comment
)
114 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
115 vfprintf (asm_out_file
, comment
, ap
);
117 fputc ('\n', asm_out_file
);
122 /* Output the difference between two symbols in a given size. */
123 /* ??? There appear to be assemblers that do not like such
124 subtraction, but do support ASM_SET_OP. It's unfortunately
125 impossible to do here, since the ASM_SET_OP for the difference
126 symbol must appear after both symbols are defined. */
129 dw2_asm_output_delta (int size
, const char *lab1
, const char *lab2
,
130 const char *comment
, ...)
134 va_start (ap
, comment
);
136 #ifdef ASM_OUTPUT_DWARF_DELTA
137 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, size
, lab1
, lab2
);
139 dw2_assemble_integer (size
,
140 gen_rtx_MINUS (Pmode
,
141 gen_rtx_SYMBOL_REF (Pmode
, lab1
),
142 gen_rtx_SYMBOL_REF (Pmode
, lab2
)));
144 if (flag_debug_asm
&& comment
)
146 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
147 vfprintf (asm_out_file
, comment
, ap
);
149 fputc ('\n', asm_out_file
);
154 /* Output a section-relative reference to a LABEL, which was placed in
155 BASE. In general this can only be done for debugging symbols.
156 E.g. on most targets with the GNU linker, this is accomplished with
157 a direct reference and the knowledge that the debugging section
158 will be placed at VMA 0. Some targets have special relocations for
159 this that we must use. */
162 dw2_asm_output_offset (int size
, const char *label
,
163 section
*base ATTRIBUTE_UNUSED
,
164 const char *comment
, ...)
168 va_start (ap
, comment
);
170 #ifdef ASM_OUTPUT_DWARF_OFFSET
171 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, size
, label
, base
);
173 dw2_assemble_integer (size
, gen_rtx_SYMBOL_REF (Pmode
, label
));
176 if (flag_debug_asm
&& comment
)
178 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
179 vfprintf (asm_out_file
, comment
, ap
);
181 fputc ('\n', asm_out_file
);
188 /* Output a self-relative reference to a label, possibly in a
189 different section or object file. */
192 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED
,
193 const char *label ATTRIBUTE_UNUSED
,
194 const char *comment
, ...)
198 va_start (ap
, comment
);
200 #ifdef ASM_OUTPUT_DWARF_PCREL
201 ASM_OUTPUT_DWARF_PCREL (asm_out_file
, size
, label
);
203 dw2_assemble_integer (size
,
204 gen_rtx_MINUS (Pmode
,
205 gen_rtx_SYMBOL_REF (Pmode
, label
),
209 if (flag_debug_asm
&& comment
)
211 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
212 vfprintf (asm_out_file
, comment
, ap
);
214 fputc ('\n', asm_out_file
);
220 /* Output an absolute reference to a label. */
223 dw2_asm_output_addr (int size
, const char *label
,
224 const char *comment
, ...)
228 va_start (ap
, comment
);
230 dw2_assemble_integer (size
, gen_rtx_SYMBOL_REF (Pmode
, label
));
232 if (flag_debug_asm
&& comment
)
234 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
235 vfprintf (asm_out_file
, comment
, ap
);
237 fputc ('\n', asm_out_file
);
242 /* Similar, but use an RTX expression instead of a text label. */
245 dw2_asm_output_addr_rtx (int size
, rtx addr
,
246 const char *comment
, ...)
250 va_start (ap
, comment
);
252 dw2_assemble_integer (size
, addr
);
254 if (flag_debug_asm
&& comment
)
256 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
257 vfprintf (asm_out_file
, comment
, ap
);
259 fputc ('\n', asm_out_file
);
264 /* Output the first ORIG_LEN characters of STR as a string.
265 If ORIG_LEN is equal to -1, ignore this parameter and output
266 the entire STR instead.
267 If COMMENT is not NULL and comments in the debug information
268 have been requested by the user, append the given COMMENT
269 to the generated output. */
272 dw2_asm_output_nstring (const char *str
, size_t orig_len
,
273 const char *comment
, ...)
278 va_start (ap
, comment
);
282 if (len
== (size_t) -1)
285 if (flag_debug_asm
&& comment
)
287 fputs ("\t.ascii \"", asm_out_file
);
288 for (i
= 0; i
< len
; i
++)
291 if (c
== '\"' || c
== '\\')
292 fputc ('\\', asm_out_file
);
294 fputc (c
, asm_out_file
);
296 fprintf (asm_out_file
, "\\%o", c
);
298 fprintf (asm_out_file
, "\\0\"\t%s ", ASM_COMMENT_START
);
299 vfprintf (asm_out_file
, comment
, ap
);
300 fputc ('\n', asm_out_file
);
304 /* If an explicit length was given, we can't assume there
305 is a null termination in the string buffer. */
306 if (orig_len
== (size_t) -1)
308 ASM_OUTPUT_ASCII (asm_out_file
, str
, len
);
309 if (orig_len
!= (size_t) -1)
310 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
317 /* Return the size of an unsigned LEB128 quantity. */
320 size_of_uleb128 (unsigned HOST_WIDE_INT value
)
334 /* Return the size of a signed LEB128 quantity. */
337 size_of_sleb128 (HOST_WIDE_INT value
)
343 byte
= (value
& 0x7f);
347 while (!((value
== 0 && (byte
& 0x40) == 0)
348 || (value
== -1 && (byte
& 0x40) != 0)));
353 /* Given an encoding, return the number of bytes the format occupies.
354 This is only defined for fixed-size encodings, and so does not
358 size_of_encoded_value (int encoding
)
360 if (encoding
== DW_EH_PE_omit
)
363 switch (encoding
& 0x07)
365 case DW_EH_PE_absptr
:
366 return POINTER_SIZE
/ BITS_PER_UNIT
;
367 case DW_EH_PE_udata2
:
369 case DW_EH_PE_udata4
:
371 case DW_EH_PE_udata8
:
378 /* Yield a name for a given pointer encoding. */
381 eh_data_format_name (int format
)
383 #if HAVE_DESIGNATED_INITIALIZERS
384 #define S(p, v) [p] = v,
386 #define S(p, v) case p: return v;
389 #if HAVE_DESIGNATED_INITIALIZERS
390 __extension__
static const char * const format_names
[256] = {
395 S(DW_EH_PE_absptr
, "absolute")
396 S(DW_EH_PE_omit
, "omit")
397 S(DW_EH_PE_aligned
, "aligned absolute")
399 S(DW_EH_PE_uleb128
, "uleb128")
400 S(DW_EH_PE_udata2
, "udata2")
401 S(DW_EH_PE_udata4
, "udata4")
402 S(DW_EH_PE_udata8
, "udata8")
403 S(DW_EH_PE_sleb128
, "sleb128")
404 S(DW_EH_PE_sdata2
, "sdata2")
405 S(DW_EH_PE_sdata4
, "sdata4")
406 S(DW_EH_PE_sdata8
, "sdata8")
408 S(DW_EH_PE_absptr
| DW_EH_PE_pcrel
, "pcrel")
409 S(DW_EH_PE_uleb128
| DW_EH_PE_pcrel
, "pcrel uleb128")
410 S(DW_EH_PE_udata2
| DW_EH_PE_pcrel
, "pcrel udata2")
411 S(DW_EH_PE_udata4
| DW_EH_PE_pcrel
, "pcrel udata4")
412 S(DW_EH_PE_udata8
| DW_EH_PE_pcrel
, "pcrel udata8")
413 S(DW_EH_PE_sleb128
| DW_EH_PE_pcrel
, "pcrel sleb128")
414 S(DW_EH_PE_sdata2
| DW_EH_PE_pcrel
, "pcrel sdata2")
415 S(DW_EH_PE_sdata4
| DW_EH_PE_pcrel
, "pcrel sdata4")
416 S(DW_EH_PE_sdata8
| DW_EH_PE_pcrel
, "pcrel sdata8")
418 S(DW_EH_PE_absptr
| DW_EH_PE_textrel
, "textrel")
419 S(DW_EH_PE_uleb128
| DW_EH_PE_textrel
, "textrel uleb128")
420 S(DW_EH_PE_udata2
| DW_EH_PE_textrel
, "textrel udata2")
421 S(DW_EH_PE_udata4
| DW_EH_PE_textrel
, "textrel udata4")
422 S(DW_EH_PE_udata8
| DW_EH_PE_textrel
, "textrel udata8")
423 S(DW_EH_PE_sleb128
| DW_EH_PE_textrel
, "textrel sleb128")
424 S(DW_EH_PE_sdata2
| DW_EH_PE_textrel
, "textrel sdata2")
425 S(DW_EH_PE_sdata4
| DW_EH_PE_textrel
, "textrel sdata4")
426 S(DW_EH_PE_sdata8
| DW_EH_PE_textrel
, "textrel sdata8")
428 S(DW_EH_PE_absptr
| DW_EH_PE_datarel
, "datarel")
429 S(DW_EH_PE_uleb128
| DW_EH_PE_datarel
, "datarel uleb128")
430 S(DW_EH_PE_udata2
| DW_EH_PE_datarel
, "datarel udata2")
431 S(DW_EH_PE_udata4
| DW_EH_PE_datarel
, "datarel udata4")
432 S(DW_EH_PE_udata8
| DW_EH_PE_datarel
, "datarel udata8")
433 S(DW_EH_PE_sleb128
| DW_EH_PE_datarel
, "datarel sleb128")
434 S(DW_EH_PE_sdata2
| DW_EH_PE_datarel
, "datarel sdata2")
435 S(DW_EH_PE_sdata4
| DW_EH_PE_datarel
, "datarel sdata4")
436 S(DW_EH_PE_sdata8
| DW_EH_PE_datarel
, "datarel sdata8")
438 S(DW_EH_PE_absptr
| DW_EH_PE_funcrel
, "funcrel")
439 S(DW_EH_PE_uleb128
| DW_EH_PE_funcrel
, "funcrel uleb128")
440 S(DW_EH_PE_udata2
| DW_EH_PE_funcrel
, "funcrel udata2")
441 S(DW_EH_PE_udata4
| DW_EH_PE_funcrel
, "funcrel udata4")
442 S(DW_EH_PE_udata8
| DW_EH_PE_funcrel
, "funcrel udata8")
443 S(DW_EH_PE_sleb128
| DW_EH_PE_funcrel
, "funcrel sleb128")
444 S(DW_EH_PE_sdata2
| DW_EH_PE_funcrel
, "funcrel sdata2")
445 S(DW_EH_PE_sdata4
| DW_EH_PE_funcrel
, "funcrel sdata4")
446 S(DW_EH_PE_sdata8
| DW_EH_PE_funcrel
, "funcrel sdata8")
448 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_pcrel
,
450 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_pcrel
,
451 "indirect pcrel uleb128")
452 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_pcrel
,
453 "indirect pcrel udata2")
454 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_pcrel
,
455 "indirect pcrel udata4")
456 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_pcrel
,
457 "indirect pcrel udata8")
458 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_pcrel
,
459 "indirect pcrel sleb128")
460 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_pcrel
,
461 "indirect pcrel sdata2")
462 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_pcrel
,
463 "indirect pcrel sdata4")
464 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_pcrel
,
465 "indirect pcrel sdata8")
467 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_textrel
,
469 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_textrel
,
470 "indirect textrel uleb128")
471 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_textrel
,
472 "indirect textrel udata2")
473 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_textrel
,
474 "indirect textrel udata4")
475 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_textrel
,
476 "indirect textrel udata8")
477 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_textrel
,
478 "indirect textrel sleb128")
479 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_textrel
,
480 "indirect textrel sdata2")
481 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_textrel
,
482 "indirect textrel sdata4")
483 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_textrel
,
484 "indirect textrel sdata8")
486 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_datarel
,
488 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_datarel
,
489 "indirect datarel uleb128")
490 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_datarel
,
491 "indirect datarel udata2")
492 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_datarel
,
493 "indirect datarel udata4")
494 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_datarel
,
495 "indirect datarel udata8")
496 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_datarel
,
497 "indirect datarel sleb128")
498 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_datarel
,
499 "indirect datarel sdata2")
500 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_datarel
,
501 "indirect datarel sdata4")
502 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_datarel
,
503 "indirect datarel sdata8")
505 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_funcrel
,
507 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_funcrel
,
508 "indirect funcrel uleb128")
509 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_funcrel
,
510 "indirect funcrel udata2")
511 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_funcrel
,
512 "indirect funcrel udata4")
513 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_funcrel
,
514 "indirect funcrel udata8")
515 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_funcrel
,
516 "indirect funcrel sleb128")
517 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_funcrel
,
518 "indirect funcrel sdata2")
519 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_funcrel
,
520 "indirect funcrel sdata4")
521 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_funcrel
,
522 "indirect funcrel sdata8")
524 #if HAVE_DESIGNATED_INITIALIZERS
527 gcc_assert (format
>= 0 && format
< 0x100 && format_names
[format
]);
529 return format_names
[format
];
536 /* Output an unsigned LEB128 quantity, but only the byte values. */
539 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value
)
543 int byte
= (value
& 0x7f);
546 /* More bytes to follow. */
549 fprintf (asm_out_file
, "0x%x", byte
);
552 fputc (',', asm_out_file
);
556 /* Output an unsigned LEB128 quantity. */
559 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value
,
560 const char *comment
, ...)
564 va_start (ap
, comment
);
566 #ifdef HAVE_AS_LEB128
567 fprintf (asm_out_file
, "\t.uleb128 " HOST_WIDE_INT_PRINT_HEX
, value
);
569 if (flag_debug_asm
&& comment
)
571 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
572 vfprintf (asm_out_file
, comment
, ap
);
576 unsigned HOST_WIDE_INT work
= value
;
577 const char *byte_op
= targetm
.asm_out
.byte_op
;
580 fputs (byte_op
, asm_out_file
);
583 int byte
= (work
& 0x7f);
586 /* More bytes to follow. */
591 fprintf (asm_out_file
, "0x%x", byte
);
593 fputc (',', asm_out_file
);
596 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
602 fprintf (asm_out_file
, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX
,
603 ASM_COMMENT_START
, value
);
606 fputs ("; ", asm_out_file
);
607 vfprintf (asm_out_file
, comment
, ap
);
612 fputc ('\n', asm_out_file
);
617 /* Output an signed LEB128 quantity, but only the byte values. */
620 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value
)
626 byte
= (value
& 0x7f);
628 more
= !((value
== 0 && (byte
& 0x40) == 0)
629 || (value
== -1 && (byte
& 0x40) != 0));
633 fprintf (asm_out_file
, "0x%x", byte
);
636 fputc (',', asm_out_file
);
640 /* Output a signed LEB128 quantity. */
643 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value
,
644 const char *comment
, ...)
648 va_start (ap
, comment
);
650 #ifdef HAVE_AS_LEB128
651 fprintf (asm_out_file
, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC
, value
);
653 if (flag_debug_asm
&& comment
)
655 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
656 vfprintf (asm_out_file
, comment
, ap
);
660 HOST_WIDE_INT work
= value
;
662 const char *byte_op
= targetm
.asm_out
.byte_op
;
665 fputs (byte_op
, asm_out_file
);
668 byte
= (work
& 0x7f);
669 /* arithmetic shift */
671 more
= !((work
== 0 && (byte
& 0x40) == 0)
672 || (work
== -1 && (byte
& 0x40) != 0));
678 fprintf (asm_out_file
, "0x%x", byte
);
680 fputc (',', asm_out_file
);
683 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
689 fprintf (asm_out_file
, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC
,
690 ASM_COMMENT_START
, value
);
693 fputs ("; ", asm_out_file
);
694 vfprintf (asm_out_file
, comment
, ap
);
699 fputc ('\n', asm_out_file
);
705 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED
,
706 const char *lab2 ATTRIBUTE_UNUSED
,
707 const char *comment
, ...)
711 va_start (ap
, comment
);
713 #ifdef HAVE_AS_LEB128
714 fputs ("\t.uleb128 ", asm_out_file
);
715 assemble_name (asm_out_file
, lab1
);
716 fputc ('-', asm_out_file
);
717 assemble_name (asm_out_file
, lab2
);
722 if (flag_debug_asm
&& comment
)
724 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
725 vfprintf (asm_out_file
, comment
, ap
);
727 fputc ('\n', asm_out_file
);
735 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED
,
736 const char *lab2 ATTRIBUTE_UNUSED
,
737 const char *comment
, ...)
741 va_start (ap
, comment
);
743 #ifdef HAVE_AS_LEB128
744 fputs ("\t.sleb128 ", asm_out_file
);
745 assemble_name (asm_out_file
, lab1
);
746 fputc ('-', asm_out_file
);
747 assemble_name (asm_out_file
, lab2
);
752 if (flag_debug_asm
&& comment
)
754 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
755 vfprintf (asm_out_file
, comment
, ap
);
757 fputc ('\n', asm_out_file
);
763 static int dw2_output_indirect_constant_1 (splay_tree_node
, void *);
765 static GTY((param1_is (char *), param2_is (tree
))) splay_tree indirect_pool
;
767 static GTY(()) int dw2_const_labelno
;
769 #if defined(HAVE_GAS_HIDDEN) && defined(SUPPORTS_ONE_ONLY)
770 # define USE_LINKONCE_INDIRECT 1
772 # define USE_LINKONCE_INDIRECT 0
775 /* Comparison function for a splay tree in which the keys are strings.
776 K1 and K2 have the dynamic type "const char *". Returns <0, 0, or
777 >0 to indicate whether K1 is less than, equal to, or greater than
781 splay_tree_compare_strings (splay_tree_key k1
, splay_tree_key k2
)
783 const char *s1
= (const char *)k1
;
784 const char *s2
= (const char *)k2
;
790 ret
= strcmp (s1
, s2
);
792 /* The strings are always those from IDENTIFIER_NODEs, and,
793 therefore, we should never have two copies of the same
800 /* Put X, a SYMBOL_REF, in memory. Return a SYMBOL_REF to the allocated
801 memory. Differs from force_const_mem in that a single pool is used for
802 the entire unit of translation, and the memory is not guaranteed to be
803 "near" the function in any interesting sense. IS_PUBLIC controls whether
804 the symbol can be shared across the entire application (or DSO). */
807 dw2_force_const_mem (rtx x
, bool is_public
)
809 splay_tree_node node
;
814 /* We use strcmp, rather than just comparing pointers, so that the
815 sort order will not depend on the host system. */
816 indirect_pool
= splay_tree_new_ggc (splay_tree_compare_strings
);
818 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
821 node
= splay_tree_lookup (indirect_pool
, (splay_tree_key
) key
);
823 decl
= (tree
) node
->value
;
827 const char *str
= targetm
.strip_name_encoding (key
);
829 if (is_public
&& USE_LINKONCE_INDIRECT
)
831 char *ref_name
= XALLOCAVEC (char, strlen (str
) + sizeof "DW.ref.");
833 sprintf (ref_name
, "DW.ref.%s", str
);
834 id
= get_identifier (ref_name
);
835 decl
= build_decl (VAR_DECL
, id
, ptr_type_node
);
836 DECL_ARTIFICIAL (decl
) = 1;
837 DECL_IGNORED_P (decl
) = 1;
838 TREE_PUBLIC (decl
) = 1;
839 DECL_INITIAL (decl
) = decl
;
840 make_decl_one_only (decl
);
846 ASM_GENERATE_INTERNAL_LABEL (label
, "LDFCM", dw2_const_labelno
);
848 id
= get_identifier (label
);
849 decl
= build_decl (VAR_DECL
, id
, ptr_type_node
);
850 DECL_ARTIFICIAL (decl
) = 1;
851 DECL_IGNORED_P (decl
) = 1;
852 TREE_STATIC (decl
) = 1;
853 DECL_INITIAL (decl
) = decl
;
856 id
= maybe_get_identifier (str
);
858 TREE_SYMBOL_REFERENCED (id
) = 1;
860 splay_tree_insert (indirect_pool
, (splay_tree_key
) key
,
861 (splay_tree_value
) decl
);
864 return XEXP (DECL_RTL (decl
), 0);
867 /* A helper function for dw2_output_indirect_constants called through
868 splay_tree_foreach. Emit one queued constant to memory. */
871 dw2_output_indirect_constant_1 (splay_tree_node node
,
872 void *data ATTRIBUTE_UNUSED
)
878 sym
= (const char *) node
->key
;
879 decl
= (tree
) node
->value
;
880 sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, sym
);
881 sym
= targetm
.strip_name_encoding (sym
);
882 if (TREE_PUBLIC (decl
) && USE_LINKONCE_INDIRECT
)
883 fprintf (asm_out_file
, "\t.hidden %sDW.ref.%s\n", user_label_prefix
, sym
);
884 assemble_variable (decl
, 1, 1, 1);
885 assemble_integer (sym_ref
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
890 /* Emit the constants queued through dw2_force_const_mem. */
893 dw2_output_indirect_constants (void)
896 splay_tree_foreach (indirect_pool
, dw2_output_indirect_constant_1
, NULL
);
899 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
900 If PUBLIC is set and the encoding is DW_EH_PE_indirect, the indirect
901 reference is shared across the entire application (or DSO). */
904 dw2_asm_output_encoded_addr_rtx (int encoding
, rtx addr
, bool is_public
,
905 const char *comment
, ...)
910 va_start (ap
, comment
);
912 size
= size_of_encoded_value (encoding
);
914 if (encoding
== DW_EH_PE_aligned
)
916 assemble_align (POINTER_SIZE
);
917 assemble_integer (addr
, size
, POINTER_SIZE
, 1);
921 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
923 if (addr
== const0_rtx
|| addr
== const1_rtx
)
924 assemble_integer (addr
, size
, BITS_PER_UNIT
, 1);
928 /* Allow the target first crack at emitting this. Some of the
929 special relocations require special directives instead of
930 just ".4byte" or whatever. */
931 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
932 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file
, encoding
, size
,
936 /* Indirection is used to get dynamic relocations out of a
937 read-only section. */
938 if (encoding
& DW_EH_PE_indirect
)
940 /* It is very tempting to use force_const_mem so that we share data
941 with the normal constant pool. However, we've already emitted
942 the constant pool for this function. Moreover, we'd like to
943 share these constants across the entire unit of translation and
944 even, if possible, across the entire application (or DSO). */
945 addr
= dw2_force_const_mem (addr
, is_public
);
946 encoding
&= ~DW_EH_PE_indirect
;
950 switch (encoding
& 0xF0)
952 case DW_EH_PE_absptr
:
953 dw2_assemble_integer (size
, addr
);
957 gcc_assert (GET_CODE (addr
) == SYMBOL_REF
);
958 #ifdef ASM_OUTPUT_DWARF_PCREL
959 ASM_OUTPUT_DWARF_PCREL (asm_out_file
, size
, XSTR (addr
, 0));
961 dw2_assemble_integer (size
, gen_rtx_MINUS (Pmode
, addr
, pc_rtx
));
966 /* Other encodings should have been handled by
967 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
971 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
976 if (flag_debug_asm
&& comment
)
978 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
979 vfprintf (asm_out_file
, comment
, ap
);
981 fputc ('\n', asm_out_file
);
986 #include "gt-dwarf2asm.h"