1 /* Dwarf2 assembler output helper routines.
2 Copyright (C) 2001-2017 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"
29 #include "stringpool.h"
32 #include "dwarf2asm.h"
37 #ifndef XCOFF_DEBUGGING_INFO
38 #define XCOFF_DEBUGGING_INFO 0
42 /* Output an unaligned integer with the given value and size. Prefer not
43 to print a newline, since the caller may want to add a comment. */
46 dw2_assemble_integer (int size
, rtx x
)
48 const char *op
= integer_asm_op (size
, FALSE
);
52 fputs (op
, asm_out_file
);
54 fprint_whex (asm_out_file
, (unsigned HOST_WIDE_INT
) INTVAL (x
));
56 output_addr_const (asm_out_file
, x
);
59 assemble_integer (x
, size
, BITS_PER_UNIT
, 1);
63 /* Output a value of a given size in target byte order. */
66 dw2_asm_output_data_raw (int size
, unsigned HOST_WIDE_INT value
)
68 unsigned char bytes
[8];
71 for (i
= 0; i
< 8; ++i
)
73 bytes
[i
] = value
& 0xff;
79 for (i
= size
- 1; i
> 0; --i
)
80 fprintf (asm_out_file
, "%#x,", bytes
[i
]);
81 fprintf (asm_out_file
, "%#x", bytes
[0]);
85 for (i
= 0; i
< size
- 1; ++i
)
86 fprintf (asm_out_file
, "%#x,", bytes
[i
]);
87 fprintf (asm_out_file
, "%#x", bytes
[i
]);
91 /* Output an immediate constant in a given SIZE in bytes. */
94 dw2_asm_output_data (int size
, unsigned HOST_WIDE_INT value
,
95 const char *comment
, ...)
98 const char *op
= integer_asm_op (size
, FALSE
);
100 va_start (ap
, comment
);
102 if (size
* 8 < HOST_BITS_PER_WIDE_INT
)
103 value
&= ~(HOST_WIDE_INT_M1U
<< (size
* 8));
107 fputs (op
, asm_out_file
);
108 fprint_whex (asm_out_file
, value
);
111 assemble_integer (GEN_INT (value
), size
, BITS_PER_UNIT
, 1);
113 if (flag_debug_asm
&& comment
)
115 fputs ("\t" ASM_COMMENT_START
" ", asm_out_file
);
116 vfprintf (asm_out_file
, comment
, ap
);
118 putc ('\n', asm_out_file
);
123 /* Output the difference between two symbols in a given size. */
124 /* ??? There appear to be assemblers that do not like such
125 subtraction, but do support ASM_SET_OP. It's unfortunately
126 impossible to do here, since the ASM_SET_OP for the difference
127 symbol must appear after both symbols are defined. */
130 dw2_asm_output_delta (int size
, const char *lab1
, const char *lab2
,
131 const char *comment
, ...)
135 va_start (ap
, comment
);
137 #ifdef ASM_OUTPUT_DWARF_DELTA
138 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, size
, lab1
, lab2
);
140 dw2_assemble_integer (size
,
141 gen_rtx_MINUS (Pmode
,
142 gen_rtx_SYMBOL_REF (Pmode
, lab1
),
143 gen_rtx_SYMBOL_REF (Pmode
, lab2
)));
145 if (flag_debug_asm
&& comment
)
147 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
148 vfprintf (asm_out_file
, comment
, ap
);
150 fputc ('\n', asm_out_file
);
155 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
156 /* Output the difference between two symbols in instruction units
160 dw2_asm_output_vms_delta (int size ATTRIBUTE_UNUSED
,
161 const char *lab1
, const char *lab2
,
162 const char *comment
, ...)
166 va_start (ap
, comment
);
168 ASM_OUTPUT_DWARF_VMS_DELTA (asm_out_file
, size
, lab1
, lab2
);
169 if (flag_debug_asm
&& comment
)
171 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
172 vfprintf (asm_out_file
, comment
, ap
);
174 fputc ('\n', asm_out_file
);
180 /* Output a section-relative reference to a LABEL, which was placed in
181 BASE. In general this can only be done for debugging symbols.
182 E.g. on most targets with the GNU linker, this is accomplished with
183 a direct reference and the knowledge that the debugging section
184 will be placed at VMA 0. Some targets have special relocations for
185 this that we must use. */
188 dw2_asm_output_offset (int size
, const char *label
,
189 section
*base ATTRIBUTE_UNUSED
,
190 const char *comment
, ...)
194 va_start (ap
, comment
);
196 #ifdef ASM_OUTPUT_DWARF_OFFSET
197 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, size
, label
, 0, base
);
199 dw2_assemble_integer (size
, gen_rtx_SYMBOL_REF (Pmode
, label
));
202 if (flag_debug_asm
&& comment
)
204 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
205 vfprintf (asm_out_file
, comment
, ap
);
207 fputc ('\n', asm_out_file
);
213 dw2_asm_output_offset (int size
, const char *label
, HOST_WIDE_INT offset
,
214 section
*base ATTRIBUTE_UNUSED
,
215 const char *comment
, ...)
219 va_start (ap
, comment
);
221 #ifdef ASM_OUTPUT_DWARF_OFFSET
222 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, size
, label
, offset
, base
);
224 dw2_assemble_integer (size
, gen_rtx_PLUS (Pmode
,
225 gen_rtx_SYMBOL_REF (Pmode
, label
),
226 gen_int_mode (offset
, Pmode
)));
229 if (flag_debug_asm
&& comment
)
231 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
232 vfprintf (asm_out_file
, comment
, ap
);
234 fputc ('\n', asm_out_file
);
241 /* Output a self-relative reference to a label, possibly in a
242 different section or object file. */
245 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED
,
246 const char *label ATTRIBUTE_UNUSED
,
247 const char *comment
, ...)
251 va_start (ap
, comment
);
253 #ifdef ASM_OUTPUT_DWARF_PCREL
254 ASM_OUTPUT_DWARF_PCREL (asm_out_file
, size
, label
);
256 dw2_assemble_integer (size
,
257 gen_rtx_MINUS (Pmode
,
258 gen_rtx_SYMBOL_REF (Pmode
, label
),
262 if (flag_debug_asm
&& comment
)
264 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
265 vfprintf (asm_out_file
, comment
, ap
);
267 fputc ('\n', asm_out_file
);
273 /* Output an absolute reference to a label. */
276 dw2_asm_output_addr (int size
, const char *label
,
277 const char *comment
, ...)
281 va_start (ap
, comment
);
283 dw2_assemble_integer (size
, gen_rtx_SYMBOL_REF (Pmode
, label
));
285 if (flag_debug_asm
&& comment
)
287 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
288 vfprintf (asm_out_file
, comment
, ap
);
290 fputc ('\n', asm_out_file
);
295 /* Similar, but use an RTX expression instead of a text label. */
298 dw2_asm_output_addr_rtx (int size
, rtx addr
,
299 const char *comment
, ...)
303 va_start (ap
, comment
);
305 dw2_assemble_integer (size
, addr
);
307 if (flag_debug_asm
&& comment
)
309 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
310 vfprintf (asm_out_file
, comment
, ap
);
312 fputc ('\n', asm_out_file
);
317 /* Output the first ORIG_LEN characters of STR as a string.
318 If ORIG_LEN is equal to -1, ignore this parameter and output
319 the entire STR instead.
320 If COMMENT is not NULL and comments in the debug information
321 have been requested by the user, append the given COMMENT
322 to the generated output. */
325 dw2_asm_output_nstring (const char *str
, size_t orig_len
,
326 const char *comment
, ...)
331 va_start (ap
, comment
);
335 if (len
== (size_t) -1)
338 if (flag_debug_asm
&& comment
)
340 if (XCOFF_DEBUGGING_INFO
)
341 fputs ("\t.byte \"", asm_out_file
);
343 fputs ("\t.ascii \"", asm_out_file
);
345 for (i
= 0; i
< len
; i
++)
348 if (c
== '\"' || c
== '\\')
349 fputc ('\\', asm_out_file
);
351 fputc (c
, asm_out_file
);
353 fprintf (asm_out_file
, "\\%o", c
);
355 fprintf (asm_out_file
, "\\0\"\t%s ", ASM_COMMENT_START
);
356 vfprintf (asm_out_file
, comment
, ap
);
357 fputc ('\n', asm_out_file
);
361 /* If an explicit length was given, we can't assume there
362 is a null termination in the string buffer. */
363 if (orig_len
== (size_t) -1)
365 ASM_OUTPUT_ASCII (asm_out_file
, str
, len
);
366 if (orig_len
!= (size_t) -1)
367 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
374 /* Return the size of an unsigned LEB128 quantity. */
377 size_of_uleb128 (unsigned HOST_WIDE_INT value
)
391 /* Return the size of a signed LEB128 quantity. */
394 size_of_sleb128 (HOST_WIDE_INT value
)
400 byte
= (value
& 0x7f);
404 while (!((value
== 0 && (byte
& 0x40) == 0)
405 || (value
== -1 && (byte
& 0x40) != 0)));
410 /* Given an encoding, return the number of bytes the format occupies.
411 This is only defined for fixed-size encodings, and so does not
415 size_of_encoded_value (int encoding
)
417 if (encoding
== DW_EH_PE_omit
)
420 switch (encoding
& 0x07)
422 case DW_EH_PE_absptr
:
423 return POINTER_SIZE_UNITS
;
424 case DW_EH_PE_udata2
:
426 case DW_EH_PE_udata4
:
428 case DW_EH_PE_udata8
:
435 /* Yield a name for a given pointer encoding. */
438 eh_data_format_name (int format
)
440 #if HAVE_DESIGNATED_INITIALIZERS
441 #define S(p, v) [p] = v,
443 #define S(p, v) case p: return v;
446 #if HAVE_DESIGNATED_INITIALIZERS
447 __extension__
static const char * const format_names
[256] = {
452 S(DW_EH_PE_absptr
, "absolute")
453 S(DW_EH_PE_omit
, "omit")
454 S(DW_EH_PE_aligned
, "aligned absolute")
456 S(DW_EH_PE_uleb128
, "uleb128")
457 S(DW_EH_PE_udata2
, "udata2")
458 S(DW_EH_PE_udata4
, "udata4")
459 S(DW_EH_PE_udata8
, "udata8")
460 S(DW_EH_PE_sleb128
, "sleb128")
461 S(DW_EH_PE_sdata2
, "sdata2")
462 S(DW_EH_PE_sdata4
, "sdata4")
463 S(DW_EH_PE_sdata8
, "sdata8")
465 S(DW_EH_PE_absptr
| DW_EH_PE_pcrel
, "pcrel")
466 S(DW_EH_PE_uleb128
| DW_EH_PE_pcrel
, "pcrel uleb128")
467 S(DW_EH_PE_udata2
| DW_EH_PE_pcrel
, "pcrel udata2")
468 S(DW_EH_PE_udata4
| DW_EH_PE_pcrel
, "pcrel udata4")
469 S(DW_EH_PE_udata8
| DW_EH_PE_pcrel
, "pcrel udata8")
470 S(DW_EH_PE_sleb128
| DW_EH_PE_pcrel
, "pcrel sleb128")
471 S(DW_EH_PE_sdata2
| DW_EH_PE_pcrel
, "pcrel sdata2")
472 S(DW_EH_PE_sdata4
| DW_EH_PE_pcrel
, "pcrel sdata4")
473 S(DW_EH_PE_sdata8
| DW_EH_PE_pcrel
, "pcrel sdata8")
475 S(DW_EH_PE_absptr
| DW_EH_PE_textrel
, "textrel")
476 S(DW_EH_PE_uleb128
| DW_EH_PE_textrel
, "textrel uleb128")
477 S(DW_EH_PE_udata2
| DW_EH_PE_textrel
, "textrel udata2")
478 S(DW_EH_PE_udata4
| DW_EH_PE_textrel
, "textrel udata4")
479 S(DW_EH_PE_udata8
| DW_EH_PE_textrel
, "textrel udata8")
480 S(DW_EH_PE_sleb128
| DW_EH_PE_textrel
, "textrel sleb128")
481 S(DW_EH_PE_sdata2
| DW_EH_PE_textrel
, "textrel sdata2")
482 S(DW_EH_PE_sdata4
| DW_EH_PE_textrel
, "textrel sdata4")
483 S(DW_EH_PE_sdata8
| DW_EH_PE_textrel
, "textrel sdata8")
485 S(DW_EH_PE_absptr
| DW_EH_PE_datarel
, "datarel")
486 S(DW_EH_PE_uleb128
| DW_EH_PE_datarel
, "datarel uleb128")
487 S(DW_EH_PE_udata2
| DW_EH_PE_datarel
, "datarel udata2")
488 S(DW_EH_PE_udata4
| DW_EH_PE_datarel
, "datarel udata4")
489 S(DW_EH_PE_udata8
| DW_EH_PE_datarel
, "datarel udata8")
490 S(DW_EH_PE_sleb128
| DW_EH_PE_datarel
, "datarel sleb128")
491 S(DW_EH_PE_sdata2
| DW_EH_PE_datarel
, "datarel sdata2")
492 S(DW_EH_PE_sdata4
| DW_EH_PE_datarel
, "datarel sdata4")
493 S(DW_EH_PE_sdata8
| DW_EH_PE_datarel
, "datarel sdata8")
495 S(DW_EH_PE_absptr
| DW_EH_PE_funcrel
, "funcrel")
496 S(DW_EH_PE_uleb128
| DW_EH_PE_funcrel
, "funcrel uleb128")
497 S(DW_EH_PE_udata2
| DW_EH_PE_funcrel
, "funcrel udata2")
498 S(DW_EH_PE_udata4
| DW_EH_PE_funcrel
, "funcrel udata4")
499 S(DW_EH_PE_udata8
| DW_EH_PE_funcrel
, "funcrel udata8")
500 S(DW_EH_PE_sleb128
| DW_EH_PE_funcrel
, "funcrel sleb128")
501 S(DW_EH_PE_sdata2
| DW_EH_PE_funcrel
, "funcrel sdata2")
502 S(DW_EH_PE_sdata4
| DW_EH_PE_funcrel
, "funcrel sdata4")
503 S(DW_EH_PE_sdata8
| DW_EH_PE_funcrel
, "funcrel sdata8")
505 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
, "indirect absolute")
507 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_pcrel
,
509 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_pcrel
,
510 "indirect pcrel uleb128")
511 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_pcrel
,
512 "indirect pcrel udata2")
513 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_pcrel
,
514 "indirect pcrel udata4")
515 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_pcrel
,
516 "indirect pcrel udata8")
517 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_pcrel
,
518 "indirect pcrel sleb128")
519 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_pcrel
,
520 "indirect pcrel sdata2")
521 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_pcrel
,
522 "indirect pcrel sdata4")
523 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_pcrel
,
524 "indirect pcrel sdata8")
526 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_textrel
,
528 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_textrel
,
529 "indirect textrel uleb128")
530 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_textrel
,
531 "indirect textrel udata2")
532 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_textrel
,
533 "indirect textrel udata4")
534 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_textrel
,
535 "indirect textrel udata8")
536 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_textrel
,
537 "indirect textrel sleb128")
538 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_textrel
,
539 "indirect textrel sdata2")
540 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_textrel
,
541 "indirect textrel sdata4")
542 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_textrel
,
543 "indirect textrel sdata8")
545 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_datarel
,
547 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_datarel
,
548 "indirect datarel uleb128")
549 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_datarel
,
550 "indirect datarel udata2")
551 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_datarel
,
552 "indirect datarel udata4")
553 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_datarel
,
554 "indirect datarel udata8")
555 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_datarel
,
556 "indirect datarel sleb128")
557 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_datarel
,
558 "indirect datarel sdata2")
559 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_datarel
,
560 "indirect datarel sdata4")
561 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_datarel
,
562 "indirect datarel sdata8")
564 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_funcrel
,
566 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_funcrel
,
567 "indirect funcrel uleb128")
568 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_funcrel
,
569 "indirect funcrel udata2")
570 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_funcrel
,
571 "indirect funcrel udata4")
572 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_funcrel
,
573 "indirect funcrel udata8")
574 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_funcrel
,
575 "indirect funcrel sleb128")
576 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_funcrel
,
577 "indirect funcrel sdata2")
578 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_funcrel
,
579 "indirect funcrel sdata4")
580 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_funcrel
,
581 "indirect funcrel sdata8")
583 #if HAVE_DESIGNATED_INITIALIZERS
586 gcc_assert (format
>= 0 && format
< 0x100 && format_names
[format
]);
588 return format_names
[format
];
595 /* Output an unsigned LEB128 quantity, but only the byte values. */
598 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value
)
602 int byte
= (value
& 0x7f);
605 /* More bytes to follow. */
608 fprintf (asm_out_file
, "%#x", byte
);
611 fputc (',', asm_out_file
);
615 /* Output an unsigned LEB128 quantity. */
618 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value
,
619 const char *comment
, ...)
623 va_start (ap
, comment
);
627 fputs ("\t.uleb128 ", asm_out_file
);
628 fprint_whex (asm_out_file
, value
);
630 if (flag_debug_asm
&& comment
)
632 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
633 vfprintf (asm_out_file
, comment
, ap
);
638 unsigned HOST_WIDE_INT work
= value
;
639 const char *byte_op
= targetm
.asm_out
.byte_op
;
642 fputs (byte_op
, asm_out_file
);
645 int byte
= (work
& 0x7f);
648 /* More bytes to follow. */
653 fprintf (asm_out_file
, "%#x", byte
);
655 fputc (',', asm_out_file
);
658 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
664 fprintf (asm_out_file
, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX
,
665 ASM_COMMENT_START
, value
);
668 fputs ("; ", asm_out_file
);
669 vfprintf (asm_out_file
, comment
, ap
);
674 putc ('\n', asm_out_file
);
679 /* Output an signed LEB128 quantity, but only the byte values. */
682 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value
)
688 byte
= (value
& 0x7f);
690 more
= !((value
== 0 && (byte
& 0x40) == 0)
691 || (value
== -1 && (byte
& 0x40) != 0));
695 fprintf (asm_out_file
, "%#x", byte
);
698 fputc (',', asm_out_file
);
702 /* Output a signed LEB128 quantity. */
705 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value
,
706 const char *comment
, ...)
710 va_start (ap
, comment
);
714 fprintf (asm_out_file
, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC
, value
);
716 if (flag_debug_asm
&& comment
)
718 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
719 vfprintf (asm_out_file
, comment
, ap
);
724 HOST_WIDE_INT work
= value
;
726 const char *byte_op
= targetm
.asm_out
.byte_op
;
729 fputs (byte_op
, asm_out_file
);
732 byte
= (work
& 0x7f);
733 /* arithmetic shift */
735 more
= !((work
== 0 && (byte
& 0x40) == 0)
736 || (work
== -1 && (byte
& 0x40) != 0));
742 fprintf (asm_out_file
, "%#x", byte
);
744 fputc (',', asm_out_file
);
747 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
753 fprintf (asm_out_file
, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC
,
754 ASM_COMMENT_START
, value
);
757 fputs ("; ", asm_out_file
);
758 vfprintf (asm_out_file
, comment
, ap
);
763 fputc ('\n', asm_out_file
);
769 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED
,
770 const char *lab2 ATTRIBUTE_UNUSED
,
771 const char *comment
, ...)
775 va_start (ap
, comment
);
777 gcc_assert (HAVE_AS_LEB128
);
779 fputs ("\t.uleb128 ", asm_out_file
);
780 assemble_name (asm_out_file
, lab1
);
781 putc ('-', asm_out_file
);
782 assemble_name (asm_out_file
, lab2
);
784 if (flag_debug_asm
&& comment
)
786 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
787 vfprintf (asm_out_file
, comment
, ap
);
789 fputc ('\n', asm_out_file
);
797 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED
,
798 const char *lab2 ATTRIBUTE_UNUSED
,
799 const char *comment
, ...)
803 va_start (ap
, comment
);
805 gcc_assert (HAVE_AS_LEB128
);
807 fputs ("\t.sleb128 ", asm_out_file
);
808 assemble_name (asm_out_file
, lab1
);
809 putc ('-', asm_out_file
);
810 assemble_name (asm_out_file
, lab2
);
812 if (flag_debug_asm
&& comment
)
814 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
815 vfprintf (asm_out_file
, comment
, ap
);
817 fputc ('\n', asm_out_file
);
823 static GTY(()) hash_map
<const char *, tree
> *indirect_pool
;
825 static GTY(()) int dw2_const_labelno
;
827 #if defined(HAVE_GAS_HIDDEN)
828 # define USE_LINKONCE_INDIRECT (SUPPORTS_ONE_ONLY && !XCOFF_DEBUGGING_INFO)
830 # define USE_LINKONCE_INDIRECT 0
833 /* Compare two std::pair<const char *, tree> by their first element.
835 >0 to indicate whether K1 is less than, equal to, or greater than
839 compare_strings (const void *a
, const void *b
)
841 const char *s1
= ((const std::pair
<const char *, tree
> *) a
)->first
;
842 const char *s2
= ((const std::pair
<const char *, tree
> *) b
)->first
;
848 ret
= strcmp (s1
, s2
);
850 /* The strings are always those from IDENTIFIER_NODEs, and,
851 therefore, we should never have two copies of the same
858 /* Put X, a SYMBOL_REF, in memory. Return a SYMBOL_REF to the allocated
859 memory. Differs from force_const_mem in that a single pool is used for
860 the entire unit of translation, and the memory is not guaranteed to be
861 "near" the function in any interesting sense. IS_PUBLIC controls whether
862 the symbol can be shared across the entire application (or DSO). */
865 dw2_force_const_mem (rtx x
, bool is_public
)
871 indirect_pool
= hash_map
<const char *, tree
>::create_ggc (64);
873 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
876 tree
*slot
= indirect_pool
->get (key
);
882 const char *str
= targetm
.strip_name_encoding (key
);
884 if (is_public
&& USE_LINKONCE_INDIRECT
)
886 char *ref_name
= XALLOCAVEC (char, strlen (str
) + sizeof "DW.ref.");
888 sprintf (ref_name
, "DW.ref.%s", str
);
889 gcc_assert (!maybe_get_identifier (ref_name
));
890 decl_id
= get_identifier (ref_name
);
891 TREE_PUBLIC (decl_id
) = 1;
897 ASM_GENERATE_INTERNAL_LABEL (label
, "LDFCM", dw2_const_labelno
);
899 gcc_assert (!maybe_get_identifier (label
));
900 decl_id
= get_identifier (label
);
903 id
= maybe_get_identifier (str
);
905 TREE_SYMBOL_REFERENCED (id
) = 1;
907 indirect_pool
->put (key
, decl_id
);
910 return gen_rtx_SYMBOL_REF (Pmode
, IDENTIFIER_POINTER (decl_id
));
913 /* A helper function for dw2_output_indirect_constants. Emit one queued
914 constant to memory. */
917 dw2_output_indirect_constant_1 (const char *sym
, tree id
)
922 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, id
, ptr_type_node
);
923 SET_DECL_ASSEMBLER_NAME (decl
, id
);
924 DECL_ARTIFICIAL (decl
) = 1;
925 DECL_IGNORED_P (decl
) = 1;
926 DECL_INITIAL (decl
) = decl
;
927 TREE_READONLY (decl
) = 1;
928 TREE_STATIC (decl
) = 1;
930 if (TREE_PUBLIC (id
))
932 TREE_PUBLIC (decl
) = 1;
933 make_decl_one_only (decl
, DECL_ASSEMBLER_NAME (decl
));
934 if (USE_LINKONCE_INDIRECT
)
935 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
938 sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, sym
);
939 assemble_variable (decl
, 1, 1, 1);
940 assemble_integer (sym_ref
, POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
945 /* Emit the constants queued through dw2_force_const_mem. */
948 dw2_output_indirect_constants (void)
953 auto_vec
<std::pair
<const char *, tree
> > temp (indirect_pool
->elements ());
954 for (hash_map
<const char *, tree
>::iterator iter
= indirect_pool
->begin ();
955 iter
!= indirect_pool
->end (); ++iter
)
956 temp
.quick_push (*iter
);
958 temp
.qsort (compare_strings
);
960 for (unsigned int i
= 0; i
< temp
.length (); i
++)
961 dw2_output_indirect_constant_1 (temp
[i
].first
, temp
[i
].second
);
964 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
965 If PUBLIC is set and the encoding is DW_EH_PE_indirect, the indirect
966 reference is shared across the entire application (or DSO). */
969 dw2_asm_output_encoded_addr_rtx (int encoding
, rtx addr
, bool is_public
,
970 const char *comment
, ...)
975 va_start (ap
, comment
);
977 size
= size_of_encoded_value (encoding
);
979 if (encoding
== DW_EH_PE_aligned
)
981 assemble_align (POINTER_SIZE
);
982 assemble_integer (addr
, size
, POINTER_SIZE
, 1);
987 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
989 if (addr
== const0_rtx
|| addr
== const1_rtx
)
990 assemble_integer (addr
, size
, BITS_PER_UNIT
, 1);
994 /* Allow the target first crack at emitting this. Some of the
995 special relocations require special directives instead of
996 just ".4byte" or whatever. */
997 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
998 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file
, encoding
, size
,
1002 /* Indirection is used to get dynamic relocations out of a
1003 read-only section. */
1004 if (encoding
& DW_EH_PE_indirect
)
1006 /* It is very tempting to use force_const_mem so that we share data
1007 with the normal constant pool. However, we've already emitted
1008 the constant pool for this function. Moreover, we'd like to
1009 share these constants across the entire unit of translation and
1010 even, if possible, across the entire application (or DSO). */
1011 addr
= dw2_force_const_mem (addr
, is_public
);
1012 encoding
&= ~DW_EH_PE_indirect
;
1016 switch (encoding
& 0xF0)
1018 case DW_EH_PE_absptr
:
1019 dw2_assemble_integer (size
, addr
);
1022 #ifdef ASM_OUTPUT_DWARF_DATAREL
1023 case DW_EH_PE_datarel
:
1024 gcc_assert (GET_CODE (addr
) == SYMBOL_REF
);
1025 ASM_OUTPUT_DWARF_DATAREL (asm_out_file
, size
, XSTR (addr
, 0));
1029 case DW_EH_PE_pcrel
:
1030 gcc_assert (GET_CODE (addr
) == SYMBOL_REF
);
1031 #ifdef ASM_OUTPUT_DWARF_PCREL
1032 ASM_OUTPUT_DWARF_PCREL (asm_out_file
, size
, XSTR (addr
, 0));
1034 dw2_assemble_integer (size
, gen_rtx_MINUS (Pmode
, addr
, pc_rtx
));
1039 /* Other encodings should have been handled by
1040 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
1044 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
1049 if (flag_debug_asm
&& comment
)
1051 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
1052 vfprintf (asm_out_file
, comment
, ap
);
1054 fputc ('\n', asm_out_file
);
1059 #include "gt-dwarf2asm.h"