1 /* Dwarf2 assembler output helper routines.
2 Copyright (C) 2001-2015 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 "double-int.h"
37 #include "stringpool.h"
42 #include "dwarf2asm.h"
49 /* Output an unaligned integer with the given value and size. Prefer not
50 to print a newline, since the caller may want to add a comment. */
53 dw2_assemble_integer (int size
, rtx x
)
55 const char *op
= integer_asm_op (size
, FALSE
);
59 fputs (op
, asm_out_file
);
61 fprint_whex (asm_out_file
, (unsigned HOST_WIDE_INT
) INTVAL (x
));
63 output_addr_const (asm_out_file
, x
);
66 assemble_integer (x
, size
, BITS_PER_UNIT
, 1);
70 /* Output a value of a given size in target byte order. */
73 dw2_asm_output_data_raw (int size
, unsigned HOST_WIDE_INT value
)
75 unsigned char bytes
[8];
78 for (i
= 0; i
< 8; ++i
)
80 bytes
[i
] = value
& 0xff;
86 for (i
= size
- 1; i
> 0; --i
)
87 fprintf (asm_out_file
, "%#x,", bytes
[i
]);
88 fprintf (asm_out_file
, "%#x", bytes
[0]);
92 for (i
= 0; i
< size
- 1; ++i
)
93 fprintf (asm_out_file
, "%#x,", bytes
[i
]);
94 fprintf (asm_out_file
, "%#x", bytes
[i
]);
98 /* Output an immediate constant in a given SIZE in bytes. */
101 dw2_asm_output_data (int size
, unsigned HOST_WIDE_INT value
,
102 const char *comment
, ...)
105 const char *op
= integer_asm_op (size
, FALSE
);
107 va_start (ap
, comment
);
109 if (size
* 8 < HOST_BITS_PER_WIDE_INT
)
110 value
&= ~(~(unsigned HOST_WIDE_INT
) 0 << (size
* 8));
114 fputs (op
, asm_out_file
);
115 fprint_whex (asm_out_file
, value
);
118 assemble_integer (GEN_INT (value
), size
, BITS_PER_UNIT
, 1);
120 if (flag_debug_asm
&& comment
)
122 fputs ("\t" ASM_COMMENT_START
" ", asm_out_file
);
123 vfprintf (asm_out_file
, comment
, ap
);
125 putc ('\n', asm_out_file
);
130 /* Output the difference between two symbols in a given size. */
131 /* ??? There appear to be assemblers that do not like such
132 subtraction, but do support ASM_SET_OP. It's unfortunately
133 impossible to do here, since the ASM_SET_OP for the difference
134 symbol must appear after both symbols are defined. */
137 dw2_asm_output_delta (int size
, const char *lab1
, const char *lab2
,
138 const char *comment
, ...)
142 va_start (ap
, comment
);
144 #ifdef ASM_OUTPUT_DWARF_DELTA
145 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, size
, lab1
, lab2
);
147 dw2_assemble_integer (size
,
148 gen_rtx_MINUS (Pmode
,
149 gen_rtx_SYMBOL_REF (Pmode
, lab1
),
150 gen_rtx_SYMBOL_REF (Pmode
, lab2
)));
152 if (flag_debug_asm
&& comment
)
154 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
155 vfprintf (asm_out_file
, comment
, ap
);
157 fputc ('\n', asm_out_file
);
162 /* Output the difference between two symbols in instruction units
166 dw2_asm_output_vms_delta (int size ATTRIBUTE_UNUSED
,
167 const char *lab1
, const char *lab2
,
168 const char *comment
, ...)
172 va_start (ap
, comment
);
174 #ifndef ASM_OUTPUT_DWARF_VMS_DELTA
175 /* VMS Delta is only special on ia64-vms, but this function also gets
176 called on alpha-vms so it has to do something sane. */
177 dw2_asm_output_delta (size
, lab1
, lab2
, comment
);
179 ASM_OUTPUT_DWARF_VMS_DELTA (asm_out_file
, size
, lab1
, lab2
);
180 if (flag_debug_asm
&& comment
)
182 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
183 vfprintf (asm_out_file
, comment
, ap
);
185 fputc ('\n', asm_out_file
);
191 /* Output a section-relative reference to a LABEL, which was placed in
192 BASE. In general this can only be done for debugging symbols.
193 E.g. on most targets with the GNU linker, this is accomplished with
194 a direct reference and the knowledge that the debugging section
195 will be placed at VMA 0. Some targets have special relocations for
196 this that we must use. */
199 dw2_asm_output_offset (int size
, const char *label
,
200 section
*base ATTRIBUTE_UNUSED
,
201 const char *comment
, ...)
205 va_start (ap
, comment
);
207 #ifdef ASM_OUTPUT_DWARF_OFFSET
208 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, size
, label
, base
);
210 dw2_assemble_integer (size
, gen_rtx_SYMBOL_REF (Pmode
, label
));
213 if (flag_debug_asm
&& comment
)
215 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
216 vfprintf (asm_out_file
, comment
, ap
);
218 fputc ('\n', asm_out_file
);
225 /* Output a self-relative reference to a label, possibly in a
226 different section or object file. */
229 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED
,
230 const char *label ATTRIBUTE_UNUSED
,
231 const char *comment
, ...)
235 va_start (ap
, comment
);
237 #ifdef ASM_OUTPUT_DWARF_PCREL
238 ASM_OUTPUT_DWARF_PCREL (asm_out_file
, size
, label
);
240 dw2_assemble_integer (size
,
241 gen_rtx_MINUS (Pmode
,
242 gen_rtx_SYMBOL_REF (Pmode
, label
),
246 if (flag_debug_asm
&& comment
)
248 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
249 vfprintf (asm_out_file
, comment
, ap
);
251 fputc ('\n', asm_out_file
);
257 /* Output an absolute reference to a label. */
260 dw2_asm_output_addr (int size
, const char *label
,
261 const char *comment
, ...)
265 va_start (ap
, comment
);
267 dw2_assemble_integer (size
, gen_rtx_SYMBOL_REF (Pmode
, label
));
269 if (flag_debug_asm
&& comment
)
271 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
272 vfprintf (asm_out_file
, comment
, ap
);
274 fputc ('\n', asm_out_file
);
279 /* Similar, but use an RTX expression instead of a text label. */
282 dw2_asm_output_addr_rtx (int size
, rtx addr
,
283 const char *comment
, ...)
287 va_start (ap
, comment
);
289 dw2_assemble_integer (size
, addr
);
291 if (flag_debug_asm
&& comment
)
293 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
294 vfprintf (asm_out_file
, comment
, ap
);
296 fputc ('\n', asm_out_file
);
301 /* Output the first ORIG_LEN characters of STR as a string.
302 If ORIG_LEN is equal to -1, ignore this parameter and output
303 the entire STR instead.
304 If COMMENT is not NULL and comments in the debug information
305 have been requested by the user, append the given COMMENT
306 to the generated output. */
309 dw2_asm_output_nstring (const char *str
, size_t orig_len
,
310 const char *comment
, ...)
315 va_start (ap
, comment
);
319 if (len
== (size_t) -1)
322 if (flag_debug_asm
&& comment
)
324 fputs ("\t.ascii \"", asm_out_file
);
325 for (i
= 0; i
< len
; i
++)
328 if (c
== '\"' || c
== '\\')
329 fputc ('\\', asm_out_file
);
331 fputc (c
, asm_out_file
);
333 fprintf (asm_out_file
, "\\%o", c
);
335 fprintf (asm_out_file
, "\\0\"\t%s ", ASM_COMMENT_START
);
336 vfprintf (asm_out_file
, comment
, ap
);
337 fputc ('\n', asm_out_file
);
341 /* If an explicit length was given, we can't assume there
342 is a null termination in the string buffer. */
343 if (orig_len
== (size_t) -1)
345 ASM_OUTPUT_ASCII (asm_out_file
, str
, len
);
346 if (orig_len
!= (size_t) -1)
347 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
354 /* Return the size of an unsigned LEB128 quantity. */
357 size_of_uleb128 (unsigned HOST_WIDE_INT value
)
371 /* Return the size of a signed LEB128 quantity. */
374 size_of_sleb128 (HOST_WIDE_INT value
)
380 byte
= (value
& 0x7f);
384 while (!((value
== 0 && (byte
& 0x40) == 0)
385 || (value
== -1 && (byte
& 0x40) != 0)));
390 /* Given an encoding, return the number of bytes the format occupies.
391 This is only defined for fixed-size encodings, and so does not
395 size_of_encoded_value (int encoding
)
397 if (encoding
== DW_EH_PE_omit
)
400 switch (encoding
& 0x07)
402 case DW_EH_PE_absptr
:
403 return POINTER_SIZE_UNITS
;
404 case DW_EH_PE_udata2
:
406 case DW_EH_PE_udata4
:
408 case DW_EH_PE_udata8
:
415 /* Yield a name for a given pointer encoding. */
418 eh_data_format_name (int format
)
420 #if HAVE_DESIGNATED_INITIALIZERS
421 #define S(p, v) [p] = v,
423 #define S(p, v) case p: return v;
426 #if HAVE_DESIGNATED_INITIALIZERS
427 __extension__
static const char * const format_names
[256] = {
432 S(DW_EH_PE_absptr
, "absolute")
433 S(DW_EH_PE_omit
, "omit")
434 S(DW_EH_PE_aligned
, "aligned absolute")
436 S(DW_EH_PE_uleb128
, "uleb128")
437 S(DW_EH_PE_udata2
, "udata2")
438 S(DW_EH_PE_udata4
, "udata4")
439 S(DW_EH_PE_udata8
, "udata8")
440 S(DW_EH_PE_sleb128
, "sleb128")
441 S(DW_EH_PE_sdata2
, "sdata2")
442 S(DW_EH_PE_sdata4
, "sdata4")
443 S(DW_EH_PE_sdata8
, "sdata8")
445 S(DW_EH_PE_absptr
| DW_EH_PE_pcrel
, "pcrel")
446 S(DW_EH_PE_uleb128
| DW_EH_PE_pcrel
, "pcrel uleb128")
447 S(DW_EH_PE_udata2
| DW_EH_PE_pcrel
, "pcrel udata2")
448 S(DW_EH_PE_udata4
| DW_EH_PE_pcrel
, "pcrel udata4")
449 S(DW_EH_PE_udata8
| DW_EH_PE_pcrel
, "pcrel udata8")
450 S(DW_EH_PE_sleb128
| DW_EH_PE_pcrel
, "pcrel sleb128")
451 S(DW_EH_PE_sdata2
| DW_EH_PE_pcrel
, "pcrel sdata2")
452 S(DW_EH_PE_sdata4
| DW_EH_PE_pcrel
, "pcrel sdata4")
453 S(DW_EH_PE_sdata8
| DW_EH_PE_pcrel
, "pcrel sdata8")
455 S(DW_EH_PE_absptr
| DW_EH_PE_textrel
, "textrel")
456 S(DW_EH_PE_uleb128
| DW_EH_PE_textrel
, "textrel uleb128")
457 S(DW_EH_PE_udata2
| DW_EH_PE_textrel
, "textrel udata2")
458 S(DW_EH_PE_udata4
| DW_EH_PE_textrel
, "textrel udata4")
459 S(DW_EH_PE_udata8
| DW_EH_PE_textrel
, "textrel udata8")
460 S(DW_EH_PE_sleb128
| DW_EH_PE_textrel
, "textrel sleb128")
461 S(DW_EH_PE_sdata2
| DW_EH_PE_textrel
, "textrel sdata2")
462 S(DW_EH_PE_sdata4
| DW_EH_PE_textrel
, "textrel sdata4")
463 S(DW_EH_PE_sdata8
| DW_EH_PE_textrel
, "textrel sdata8")
465 S(DW_EH_PE_absptr
| DW_EH_PE_datarel
, "datarel")
466 S(DW_EH_PE_uleb128
| DW_EH_PE_datarel
, "datarel uleb128")
467 S(DW_EH_PE_udata2
| DW_EH_PE_datarel
, "datarel udata2")
468 S(DW_EH_PE_udata4
| DW_EH_PE_datarel
, "datarel udata4")
469 S(DW_EH_PE_udata8
| DW_EH_PE_datarel
, "datarel udata8")
470 S(DW_EH_PE_sleb128
| DW_EH_PE_datarel
, "datarel sleb128")
471 S(DW_EH_PE_sdata2
| DW_EH_PE_datarel
, "datarel sdata2")
472 S(DW_EH_PE_sdata4
| DW_EH_PE_datarel
, "datarel sdata4")
473 S(DW_EH_PE_sdata8
| DW_EH_PE_datarel
, "datarel sdata8")
475 S(DW_EH_PE_absptr
| DW_EH_PE_funcrel
, "funcrel")
476 S(DW_EH_PE_uleb128
| DW_EH_PE_funcrel
, "funcrel uleb128")
477 S(DW_EH_PE_udata2
| DW_EH_PE_funcrel
, "funcrel udata2")
478 S(DW_EH_PE_udata4
| DW_EH_PE_funcrel
, "funcrel udata4")
479 S(DW_EH_PE_udata8
| DW_EH_PE_funcrel
, "funcrel udata8")
480 S(DW_EH_PE_sleb128
| DW_EH_PE_funcrel
, "funcrel sleb128")
481 S(DW_EH_PE_sdata2
| DW_EH_PE_funcrel
, "funcrel sdata2")
482 S(DW_EH_PE_sdata4
| DW_EH_PE_funcrel
, "funcrel sdata4")
483 S(DW_EH_PE_sdata8
| DW_EH_PE_funcrel
, "funcrel sdata8")
485 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
, "indirect absolute")
487 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_pcrel
,
489 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_pcrel
,
490 "indirect pcrel uleb128")
491 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_pcrel
,
492 "indirect pcrel udata2")
493 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_pcrel
,
494 "indirect pcrel udata4")
495 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_pcrel
,
496 "indirect pcrel udata8")
497 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_pcrel
,
498 "indirect pcrel sleb128")
499 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_pcrel
,
500 "indirect pcrel sdata2")
501 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_pcrel
,
502 "indirect pcrel sdata4")
503 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_pcrel
,
504 "indirect pcrel sdata8")
506 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_textrel
,
508 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_textrel
,
509 "indirect textrel uleb128")
510 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_textrel
,
511 "indirect textrel udata2")
512 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_textrel
,
513 "indirect textrel udata4")
514 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_textrel
,
515 "indirect textrel udata8")
516 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_textrel
,
517 "indirect textrel sleb128")
518 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_textrel
,
519 "indirect textrel sdata2")
520 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_textrel
,
521 "indirect textrel sdata4")
522 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_textrel
,
523 "indirect textrel sdata8")
525 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_datarel
,
527 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_datarel
,
528 "indirect datarel uleb128")
529 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_datarel
,
530 "indirect datarel udata2")
531 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_datarel
,
532 "indirect datarel udata4")
533 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_datarel
,
534 "indirect datarel udata8")
535 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_datarel
,
536 "indirect datarel sleb128")
537 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_datarel
,
538 "indirect datarel sdata2")
539 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_datarel
,
540 "indirect datarel sdata4")
541 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_datarel
,
542 "indirect datarel sdata8")
544 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_funcrel
,
546 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_funcrel
,
547 "indirect funcrel uleb128")
548 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_funcrel
,
549 "indirect funcrel udata2")
550 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_funcrel
,
551 "indirect funcrel udata4")
552 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_funcrel
,
553 "indirect funcrel udata8")
554 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_funcrel
,
555 "indirect funcrel sleb128")
556 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_funcrel
,
557 "indirect funcrel sdata2")
558 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_funcrel
,
559 "indirect funcrel sdata4")
560 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_funcrel
,
561 "indirect funcrel sdata8")
563 #if HAVE_DESIGNATED_INITIALIZERS
566 gcc_assert (format
>= 0 && format
< 0x100 && format_names
[format
]);
568 return format_names
[format
];
575 /* Output an unsigned LEB128 quantity, but only the byte values. */
578 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value
)
582 int byte
= (value
& 0x7f);
585 /* More bytes to follow. */
588 fprintf (asm_out_file
, "%#x", byte
);
591 fputc (',', asm_out_file
);
595 /* Output an unsigned LEB128 quantity. */
598 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value
,
599 const char *comment
, ...)
603 va_start (ap
, comment
);
605 #ifdef HAVE_AS_LEB128
606 fputs ("\t.uleb128 ", asm_out_file
);
607 fprint_whex (asm_out_file
, value
);
609 if (flag_debug_asm
&& comment
)
611 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
612 vfprintf (asm_out_file
, comment
, ap
);
616 unsigned HOST_WIDE_INT work
= value
;
617 const char *byte_op
= targetm
.asm_out
.byte_op
;
620 fputs (byte_op
, asm_out_file
);
623 int byte
= (work
& 0x7f);
626 /* More bytes to follow. */
631 fprintf (asm_out_file
, "%#x", byte
);
633 fputc (',', asm_out_file
);
636 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
642 fprintf (asm_out_file
, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX
,
643 ASM_COMMENT_START
, value
);
646 fputs ("; ", asm_out_file
);
647 vfprintf (asm_out_file
, comment
, ap
);
652 putc ('\n', asm_out_file
);
657 /* Output an signed LEB128 quantity, but only the byte values. */
660 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value
)
666 byte
= (value
& 0x7f);
668 more
= !((value
== 0 && (byte
& 0x40) == 0)
669 || (value
== -1 && (byte
& 0x40) != 0));
673 fprintf (asm_out_file
, "%#x", byte
);
676 fputc (',', asm_out_file
);
680 /* Output a signed LEB128 quantity. */
683 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value
,
684 const char *comment
, ...)
688 va_start (ap
, comment
);
690 #ifdef HAVE_AS_LEB128
691 fprintf (asm_out_file
, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC
, value
);
693 if (flag_debug_asm
&& comment
)
695 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
696 vfprintf (asm_out_file
, comment
, ap
);
700 HOST_WIDE_INT work
= value
;
702 const char *byte_op
= targetm
.asm_out
.byte_op
;
705 fputs (byte_op
, asm_out_file
);
708 byte
= (work
& 0x7f);
709 /* arithmetic shift */
711 more
= !((work
== 0 && (byte
& 0x40) == 0)
712 || (work
== -1 && (byte
& 0x40) != 0));
718 fprintf (asm_out_file
, "%#x", byte
);
720 fputc (',', asm_out_file
);
723 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
729 fprintf (asm_out_file
, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC
,
730 ASM_COMMENT_START
, value
);
733 fputs ("; ", asm_out_file
);
734 vfprintf (asm_out_file
, comment
, ap
);
739 fputc ('\n', asm_out_file
);
745 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED
,
746 const char *lab2 ATTRIBUTE_UNUSED
,
747 const char *comment
, ...)
751 va_start (ap
, comment
);
753 #ifdef HAVE_AS_LEB128
754 fputs ("\t.uleb128 ", asm_out_file
);
755 assemble_name (asm_out_file
, lab1
);
756 putc ('-', asm_out_file
);
757 assemble_name (asm_out_file
, lab2
);
762 if (flag_debug_asm
&& comment
)
764 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
765 vfprintf (asm_out_file
, comment
, ap
);
767 fputc ('\n', asm_out_file
);
775 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED
,
776 const char *lab2 ATTRIBUTE_UNUSED
,
777 const char *comment
, ...)
781 va_start (ap
, comment
);
783 #ifdef HAVE_AS_LEB128
784 fputs ("\t.sleb128 ", asm_out_file
);
785 assemble_name (asm_out_file
, lab1
);
786 putc ('-', asm_out_file
);
787 assemble_name (asm_out_file
, lab2
);
792 if (flag_debug_asm
&& comment
)
794 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
795 vfprintf (asm_out_file
, comment
, ap
);
797 fputc ('\n', asm_out_file
);
803 static GTY(()) hash_map
<const char *, tree
> *indirect_pool
;
805 static GTY(()) int dw2_const_labelno
;
807 #if defined(HAVE_GAS_HIDDEN)
808 # define USE_LINKONCE_INDIRECT (SUPPORTS_ONE_ONLY)
810 # define USE_LINKONCE_INDIRECT 0
813 /* Compare two std::pair<const char *, tree> by their first element.
815 >0 to indicate whether K1 is less than, equal to, or greater than
819 compare_strings (const void *a
, const void *b
)
821 const char *s1
= ((const std::pair
<const char *, tree
> *) a
)->first
;
822 const char *s2
= ((const std::pair
<const char *, tree
> *) b
)->first
;
828 ret
= strcmp (s1
, s2
);
830 /* The strings are always those from IDENTIFIER_NODEs, and,
831 therefore, we should never have two copies of the same
838 /* Put X, a SYMBOL_REF, in memory. Return a SYMBOL_REF to the allocated
839 memory. Differs from force_const_mem in that a single pool is used for
840 the entire unit of translation, and the memory is not guaranteed to be
841 "near" the function in any interesting sense. IS_PUBLIC controls whether
842 the symbol can be shared across the entire application (or DSO). */
845 dw2_force_const_mem (rtx x
, bool is_public
)
851 indirect_pool
= hash_map
<const char *, tree
>::create_ggc (64);
853 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
856 tree
*slot
= indirect_pool
->get (key
);
862 const char *str
= targetm
.strip_name_encoding (key
);
864 if (is_public
&& USE_LINKONCE_INDIRECT
)
866 char *ref_name
= XALLOCAVEC (char, strlen (str
) + sizeof "DW.ref.");
868 sprintf (ref_name
, "DW.ref.%s", str
);
869 gcc_assert (!maybe_get_identifier (ref_name
));
870 decl_id
= get_identifier (ref_name
);
871 TREE_PUBLIC (decl_id
) = 1;
877 ASM_GENERATE_INTERNAL_LABEL (label
, "LDFCM", dw2_const_labelno
);
879 gcc_assert (!maybe_get_identifier (label
));
880 decl_id
= get_identifier (label
);
883 id
= maybe_get_identifier (str
);
885 TREE_SYMBOL_REFERENCED (id
) = 1;
887 indirect_pool
->put (key
, decl_id
);
890 return gen_rtx_SYMBOL_REF (Pmode
, IDENTIFIER_POINTER (decl_id
));
893 /* A helper function for dw2_output_indirect_constants. Emit one queued
894 constant to memory. */
897 dw2_output_indirect_constant_1 (const char *sym
, tree id
)
902 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, id
, ptr_type_node
);
903 SET_DECL_ASSEMBLER_NAME (decl
, id
);
904 DECL_ARTIFICIAL (decl
) = 1;
905 DECL_IGNORED_P (decl
) = 1;
906 DECL_INITIAL (decl
) = decl
;
907 TREE_READONLY (decl
) = 1;
908 TREE_STATIC (decl
) = 1;
910 if (TREE_PUBLIC (id
))
912 TREE_PUBLIC (decl
) = 1;
913 make_decl_one_only (decl
, DECL_ASSEMBLER_NAME (decl
));
914 if (USE_LINKONCE_INDIRECT
)
915 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
918 sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, sym
);
919 assemble_variable (decl
, 1, 1, 1);
920 assemble_integer (sym_ref
, POINTER_SIZE_UNITS
, POINTER_SIZE
, 1);
925 /* Emit the constants queued through dw2_force_const_mem. */
928 dw2_output_indirect_constants (void)
933 auto_vec
<std::pair
<const char *, tree
> > temp (indirect_pool
->elements ());
934 for (hash_map
<const char *, tree
>::iterator iter
= indirect_pool
->begin ();
935 iter
!= indirect_pool
->end (); ++iter
)
936 temp
.quick_push (*iter
);
938 temp
.qsort (compare_strings
);
940 for (unsigned int i
= 0; i
< temp
.length (); i
++)
941 dw2_output_indirect_constant_1 (temp
[i
].first
, temp
[i
].second
);
944 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
945 If PUBLIC is set and the encoding is DW_EH_PE_indirect, the indirect
946 reference is shared across the entire application (or DSO). */
949 dw2_asm_output_encoded_addr_rtx (int encoding
, rtx addr
, bool is_public
,
950 const char *comment
, ...)
955 va_start (ap
, comment
);
957 size
= size_of_encoded_value (encoding
);
959 if (encoding
== DW_EH_PE_aligned
)
961 assemble_align (POINTER_SIZE
);
962 assemble_integer (addr
, size
, POINTER_SIZE
, 1);
967 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
969 if (addr
== const0_rtx
|| addr
== const1_rtx
)
970 assemble_integer (addr
, size
, BITS_PER_UNIT
, 1);
974 /* Allow the target first crack at emitting this. Some of the
975 special relocations require special directives instead of
976 just ".4byte" or whatever. */
977 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
978 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file
, encoding
, size
,
982 /* Indirection is used to get dynamic relocations out of a
983 read-only section. */
984 if (encoding
& DW_EH_PE_indirect
)
986 /* It is very tempting to use force_const_mem so that we share data
987 with the normal constant pool. However, we've already emitted
988 the constant pool for this function. Moreover, we'd like to
989 share these constants across the entire unit of translation and
990 even, if possible, across the entire application (or DSO). */
991 addr
= dw2_force_const_mem (addr
, is_public
);
992 encoding
&= ~DW_EH_PE_indirect
;
996 switch (encoding
& 0xF0)
998 case DW_EH_PE_absptr
:
999 dw2_assemble_integer (size
, addr
);
1002 case DW_EH_PE_pcrel
:
1003 gcc_assert (GET_CODE (addr
) == SYMBOL_REF
);
1004 #ifdef ASM_OUTPUT_DWARF_PCREL
1005 ASM_OUTPUT_DWARF_PCREL (asm_out_file
, size
, XSTR (addr
, 0));
1007 dw2_assemble_integer (size
, gen_rtx_MINUS (Pmode
, addr
, pc_rtx
));
1012 /* Other encodings should have been handled by
1013 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
1017 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
1022 if (flag_debug_asm
&& comment
)
1024 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
1025 vfprintf (asm_out_file
, comment
, ap
);
1027 fputc ('\n', asm_out_file
);
1032 #include "gt-dwarf2asm.h"