1 /* Dwarf2 assembler output helper routines.
2 Copyright (C) 2001-2013 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 /* Output an unaligned integer with the given value and size. Prefer not
38 to print a newline, since the caller may want to add a comment. */
41 dw2_assemble_integer (int size
, rtx x
)
43 const char *op
= integer_asm_op (size
, FALSE
);
47 fputs (op
, asm_out_file
);
49 fprint_whex (asm_out_file
, (unsigned HOST_WIDE_INT
) INTVAL (x
));
51 output_addr_const (asm_out_file
, x
);
54 assemble_integer (x
, size
, BITS_PER_UNIT
, 1);
58 /* Output a value of a given size in target byte order. */
61 dw2_asm_output_data_raw (int size
, unsigned HOST_WIDE_INT value
)
63 unsigned char bytes
[8];
66 for (i
= 0; i
< 8; ++i
)
68 bytes
[i
] = value
& 0xff;
74 for (i
= size
- 1; i
> 0; --i
)
75 fprintf (asm_out_file
, "%#x,", bytes
[i
]);
76 fprintf (asm_out_file
, "%#x", bytes
[0]);
80 for (i
= 0; i
< size
- 1; ++i
)
81 fprintf (asm_out_file
, "%#x,", bytes
[i
]);
82 fprintf (asm_out_file
, "%#x", bytes
[i
]);
86 /* Output an immediate constant in a given SIZE in bytes. */
89 dw2_asm_output_data (int size
, unsigned HOST_WIDE_INT value
,
90 const char *comment
, ...)
93 const char *op
= integer_asm_op (size
, FALSE
);
95 va_start (ap
, comment
);
97 if (size
* 8 < HOST_BITS_PER_WIDE_INT
)
98 value
&= ~(~(unsigned HOST_WIDE_INT
) 0 << (size
* 8));
102 fputs (op
, asm_out_file
);
103 fprint_whex (asm_out_file
, value
);
106 assemble_integer (GEN_INT (value
), size
, BITS_PER_UNIT
, 1);
108 if (flag_debug_asm
&& comment
)
110 fputs ("\t" ASM_COMMENT_START
" ", asm_out_file
);
111 vfprintf (asm_out_file
, comment
, ap
);
113 putc ('\n', asm_out_file
);
118 /* Output the difference between two symbols in a given size. */
119 /* ??? There appear to be assemblers that do not like such
120 subtraction, but do support ASM_SET_OP. It's unfortunately
121 impossible to do here, since the ASM_SET_OP for the difference
122 symbol must appear after both symbols are defined. */
125 dw2_asm_output_delta (int size
, const char *lab1
, const char *lab2
,
126 const char *comment
, ...)
130 va_start (ap
, comment
);
132 #ifdef ASM_OUTPUT_DWARF_DELTA
133 ASM_OUTPUT_DWARF_DELTA (asm_out_file
, size
, lab1
, lab2
);
135 dw2_assemble_integer (size
,
136 gen_rtx_MINUS (Pmode
,
137 gen_rtx_SYMBOL_REF (Pmode
, lab1
),
138 gen_rtx_SYMBOL_REF (Pmode
, lab2
)));
140 if (flag_debug_asm
&& comment
)
142 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
143 vfprintf (asm_out_file
, comment
, ap
);
145 fputc ('\n', asm_out_file
);
150 /* Output the difference between two symbols in instruction units
154 dw2_asm_output_vms_delta (int size ATTRIBUTE_UNUSED
,
155 const char *lab1
, const char *lab2
,
156 const char *comment
, ...)
160 va_start (ap
, comment
);
162 #ifndef ASM_OUTPUT_DWARF_VMS_DELTA
163 /* VMS Delta is only special on ia64-vms, but this function also gets
164 called on alpha-vms so it has to do something sane. */
165 dw2_asm_output_delta (size
, lab1
, lab2
, comment
);
167 ASM_OUTPUT_DWARF_VMS_DELTA (asm_out_file
, size
, lab1
, lab2
);
168 if (flag_debug_asm
&& comment
)
170 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
171 vfprintf (asm_out_file
, comment
, ap
);
173 fputc ('\n', asm_out_file
);
179 /* Output a section-relative reference to a LABEL, which was placed in
180 BASE. In general this can only be done for debugging symbols.
181 E.g. on most targets with the GNU linker, this is accomplished with
182 a direct reference and the knowledge that the debugging section
183 will be placed at VMA 0. Some targets have special relocations for
184 this that we must use. */
187 dw2_asm_output_offset (int size
, const char *label
,
188 section
*base ATTRIBUTE_UNUSED
,
189 const char *comment
, ...)
193 va_start (ap
, comment
);
195 #ifdef ASM_OUTPUT_DWARF_OFFSET
196 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, size
, label
, base
);
198 dw2_assemble_integer (size
, gen_rtx_SYMBOL_REF (Pmode
, label
));
201 if (flag_debug_asm
&& comment
)
203 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
204 vfprintf (asm_out_file
, comment
, ap
);
206 fputc ('\n', asm_out_file
);
213 /* Output a self-relative reference to a label, possibly in a
214 different section or object file. */
217 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED
,
218 const char *label ATTRIBUTE_UNUSED
,
219 const char *comment
, ...)
223 va_start (ap
, comment
);
225 #ifdef ASM_OUTPUT_DWARF_PCREL
226 ASM_OUTPUT_DWARF_PCREL (asm_out_file
, size
, label
);
228 dw2_assemble_integer (size
,
229 gen_rtx_MINUS (Pmode
,
230 gen_rtx_SYMBOL_REF (Pmode
, label
),
234 if (flag_debug_asm
&& comment
)
236 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
237 vfprintf (asm_out_file
, comment
, ap
);
239 fputc ('\n', asm_out_file
);
245 /* Output an absolute reference to a label. */
248 dw2_asm_output_addr (int size
, const char *label
,
249 const char *comment
, ...)
253 va_start (ap
, comment
);
255 dw2_assemble_integer (size
, gen_rtx_SYMBOL_REF (Pmode
, label
));
257 if (flag_debug_asm
&& comment
)
259 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
260 vfprintf (asm_out_file
, comment
, ap
);
262 fputc ('\n', asm_out_file
);
267 /* Similar, but use an RTX expression instead of a text label. */
270 dw2_asm_output_addr_rtx (int size
, rtx addr
,
271 const char *comment
, ...)
275 va_start (ap
, comment
);
277 dw2_assemble_integer (size
, addr
);
279 if (flag_debug_asm
&& comment
)
281 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
282 vfprintf (asm_out_file
, comment
, ap
);
284 fputc ('\n', asm_out_file
);
289 /* Output the first ORIG_LEN characters of STR as a string.
290 If ORIG_LEN is equal to -1, ignore this parameter and output
291 the entire STR instead.
292 If COMMENT is not NULL and comments in the debug information
293 have been requested by the user, append the given COMMENT
294 to the generated output. */
297 dw2_asm_output_nstring (const char *str
, size_t orig_len
,
298 const char *comment
, ...)
303 va_start (ap
, comment
);
307 if (len
== (size_t) -1)
310 if (flag_debug_asm
&& comment
)
312 fputs ("\t.ascii \"", asm_out_file
);
313 for (i
= 0; i
< len
; i
++)
316 if (c
== '\"' || c
== '\\')
317 fputc ('\\', asm_out_file
);
319 fputc (c
, asm_out_file
);
321 fprintf (asm_out_file
, "\\%o", c
);
323 fprintf (asm_out_file
, "\\0\"\t%s ", ASM_COMMENT_START
);
324 vfprintf (asm_out_file
, comment
, ap
);
325 fputc ('\n', asm_out_file
);
329 /* If an explicit length was given, we can't assume there
330 is a null termination in the string buffer. */
331 if (orig_len
== (size_t) -1)
333 ASM_OUTPUT_ASCII (asm_out_file
, str
, len
);
334 if (orig_len
!= (size_t) -1)
335 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
342 /* Return the size of an unsigned LEB128 quantity. */
345 size_of_uleb128 (unsigned HOST_WIDE_INT value
)
359 /* Return the size of a signed LEB128 quantity. */
362 size_of_sleb128 (HOST_WIDE_INT value
)
368 byte
= (value
& 0x7f);
372 while (!((value
== 0 && (byte
& 0x40) == 0)
373 || (value
== -1 && (byte
& 0x40) != 0)));
378 /* Given an encoding, return the number of bytes the format occupies.
379 This is only defined for fixed-size encodings, and so does not
383 size_of_encoded_value (int encoding
)
385 if (encoding
== DW_EH_PE_omit
)
388 switch (encoding
& 0x07)
390 case DW_EH_PE_absptr
:
391 return POINTER_SIZE
/ BITS_PER_UNIT
;
392 case DW_EH_PE_udata2
:
394 case DW_EH_PE_udata4
:
396 case DW_EH_PE_udata8
:
403 /* Yield a name for a given pointer encoding. */
406 eh_data_format_name (int format
)
408 #if HAVE_DESIGNATED_INITIALIZERS
409 #define S(p, v) [p] = v,
411 #define S(p, v) case p: return v;
414 #if HAVE_DESIGNATED_INITIALIZERS
415 __extension__
static const char * const format_names
[256] = {
420 S(DW_EH_PE_absptr
, "absolute")
421 S(DW_EH_PE_omit
, "omit")
422 S(DW_EH_PE_aligned
, "aligned absolute")
424 S(DW_EH_PE_uleb128
, "uleb128")
425 S(DW_EH_PE_udata2
, "udata2")
426 S(DW_EH_PE_udata4
, "udata4")
427 S(DW_EH_PE_udata8
, "udata8")
428 S(DW_EH_PE_sleb128
, "sleb128")
429 S(DW_EH_PE_sdata2
, "sdata2")
430 S(DW_EH_PE_sdata4
, "sdata4")
431 S(DW_EH_PE_sdata8
, "sdata8")
433 S(DW_EH_PE_absptr
| DW_EH_PE_pcrel
, "pcrel")
434 S(DW_EH_PE_uleb128
| DW_EH_PE_pcrel
, "pcrel uleb128")
435 S(DW_EH_PE_udata2
| DW_EH_PE_pcrel
, "pcrel udata2")
436 S(DW_EH_PE_udata4
| DW_EH_PE_pcrel
, "pcrel udata4")
437 S(DW_EH_PE_udata8
| DW_EH_PE_pcrel
, "pcrel udata8")
438 S(DW_EH_PE_sleb128
| DW_EH_PE_pcrel
, "pcrel sleb128")
439 S(DW_EH_PE_sdata2
| DW_EH_PE_pcrel
, "pcrel sdata2")
440 S(DW_EH_PE_sdata4
| DW_EH_PE_pcrel
, "pcrel sdata4")
441 S(DW_EH_PE_sdata8
| DW_EH_PE_pcrel
, "pcrel sdata8")
443 S(DW_EH_PE_absptr
| DW_EH_PE_textrel
, "textrel")
444 S(DW_EH_PE_uleb128
| DW_EH_PE_textrel
, "textrel uleb128")
445 S(DW_EH_PE_udata2
| DW_EH_PE_textrel
, "textrel udata2")
446 S(DW_EH_PE_udata4
| DW_EH_PE_textrel
, "textrel udata4")
447 S(DW_EH_PE_udata8
| DW_EH_PE_textrel
, "textrel udata8")
448 S(DW_EH_PE_sleb128
| DW_EH_PE_textrel
, "textrel sleb128")
449 S(DW_EH_PE_sdata2
| DW_EH_PE_textrel
, "textrel sdata2")
450 S(DW_EH_PE_sdata4
| DW_EH_PE_textrel
, "textrel sdata4")
451 S(DW_EH_PE_sdata8
| DW_EH_PE_textrel
, "textrel sdata8")
453 S(DW_EH_PE_absptr
| DW_EH_PE_datarel
, "datarel")
454 S(DW_EH_PE_uleb128
| DW_EH_PE_datarel
, "datarel uleb128")
455 S(DW_EH_PE_udata2
| DW_EH_PE_datarel
, "datarel udata2")
456 S(DW_EH_PE_udata4
| DW_EH_PE_datarel
, "datarel udata4")
457 S(DW_EH_PE_udata8
| DW_EH_PE_datarel
, "datarel udata8")
458 S(DW_EH_PE_sleb128
| DW_EH_PE_datarel
, "datarel sleb128")
459 S(DW_EH_PE_sdata2
| DW_EH_PE_datarel
, "datarel sdata2")
460 S(DW_EH_PE_sdata4
| DW_EH_PE_datarel
, "datarel sdata4")
461 S(DW_EH_PE_sdata8
| DW_EH_PE_datarel
, "datarel sdata8")
463 S(DW_EH_PE_absptr
| DW_EH_PE_funcrel
, "funcrel")
464 S(DW_EH_PE_uleb128
| DW_EH_PE_funcrel
, "funcrel uleb128")
465 S(DW_EH_PE_udata2
| DW_EH_PE_funcrel
, "funcrel udata2")
466 S(DW_EH_PE_udata4
| DW_EH_PE_funcrel
, "funcrel udata4")
467 S(DW_EH_PE_udata8
| DW_EH_PE_funcrel
, "funcrel udata8")
468 S(DW_EH_PE_sleb128
| DW_EH_PE_funcrel
, "funcrel sleb128")
469 S(DW_EH_PE_sdata2
| DW_EH_PE_funcrel
, "funcrel sdata2")
470 S(DW_EH_PE_sdata4
| DW_EH_PE_funcrel
, "funcrel sdata4")
471 S(DW_EH_PE_sdata8
| DW_EH_PE_funcrel
, "funcrel sdata8")
473 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
, "indirect absolute")
475 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_pcrel
,
477 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_pcrel
,
478 "indirect pcrel uleb128")
479 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_pcrel
,
480 "indirect pcrel udata2")
481 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_pcrel
,
482 "indirect pcrel udata4")
483 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_pcrel
,
484 "indirect pcrel udata8")
485 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_pcrel
,
486 "indirect pcrel sleb128")
487 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_pcrel
,
488 "indirect pcrel sdata2")
489 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_pcrel
,
490 "indirect pcrel sdata4")
491 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_pcrel
,
492 "indirect pcrel sdata8")
494 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_textrel
,
496 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_textrel
,
497 "indirect textrel uleb128")
498 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_textrel
,
499 "indirect textrel udata2")
500 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_textrel
,
501 "indirect textrel udata4")
502 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_textrel
,
503 "indirect textrel udata8")
504 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_textrel
,
505 "indirect textrel sleb128")
506 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_textrel
,
507 "indirect textrel sdata2")
508 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_textrel
,
509 "indirect textrel sdata4")
510 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_textrel
,
511 "indirect textrel sdata8")
513 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_datarel
,
515 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_datarel
,
516 "indirect datarel uleb128")
517 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_datarel
,
518 "indirect datarel udata2")
519 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_datarel
,
520 "indirect datarel udata4")
521 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_datarel
,
522 "indirect datarel udata8")
523 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_datarel
,
524 "indirect datarel sleb128")
525 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_datarel
,
526 "indirect datarel sdata2")
527 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_datarel
,
528 "indirect datarel sdata4")
529 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_datarel
,
530 "indirect datarel sdata8")
532 S(DW_EH_PE_indirect
| DW_EH_PE_absptr
| DW_EH_PE_funcrel
,
534 S(DW_EH_PE_indirect
| DW_EH_PE_uleb128
| DW_EH_PE_funcrel
,
535 "indirect funcrel uleb128")
536 S(DW_EH_PE_indirect
| DW_EH_PE_udata2
| DW_EH_PE_funcrel
,
537 "indirect funcrel udata2")
538 S(DW_EH_PE_indirect
| DW_EH_PE_udata4
| DW_EH_PE_funcrel
,
539 "indirect funcrel udata4")
540 S(DW_EH_PE_indirect
| DW_EH_PE_udata8
| DW_EH_PE_funcrel
,
541 "indirect funcrel udata8")
542 S(DW_EH_PE_indirect
| DW_EH_PE_sleb128
| DW_EH_PE_funcrel
,
543 "indirect funcrel sleb128")
544 S(DW_EH_PE_indirect
| DW_EH_PE_sdata2
| DW_EH_PE_funcrel
,
545 "indirect funcrel sdata2")
546 S(DW_EH_PE_indirect
| DW_EH_PE_sdata4
| DW_EH_PE_funcrel
,
547 "indirect funcrel sdata4")
548 S(DW_EH_PE_indirect
| DW_EH_PE_sdata8
| DW_EH_PE_funcrel
,
549 "indirect funcrel sdata8")
551 #if HAVE_DESIGNATED_INITIALIZERS
554 gcc_assert (format
>= 0 && format
< 0x100 && format_names
[format
]);
556 return format_names
[format
];
563 /* Output an unsigned LEB128 quantity, but only the byte values. */
566 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value
)
570 int byte
= (value
& 0x7f);
573 /* More bytes to follow. */
576 fprintf (asm_out_file
, "%#x", byte
);
579 fputc (',', asm_out_file
);
583 /* Output an unsigned LEB128 quantity. */
586 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value
,
587 const char *comment
, ...)
591 va_start (ap
, comment
);
593 #ifdef HAVE_AS_LEB128
594 fputs ("\t.uleb128 ", asm_out_file
);
595 fprint_whex (asm_out_file
, value
);
597 if (flag_debug_asm
&& comment
)
599 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
600 vfprintf (asm_out_file
, comment
, ap
);
604 unsigned HOST_WIDE_INT work
= value
;
605 const char *byte_op
= targetm
.asm_out
.byte_op
;
608 fputs (byte_op
, asm_out_file
);
611 int byte
= (work
& 0x7f);
614 /* More bytes to follow. */
619 fprintf (asm_out_file
, "%#x", byte
);
621 fputc (',', asm_out_file
);
624 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
630 fprintf (asm_out_file
, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX
,
631 ASM_COMMENT_START
, value
);
634 fputs ("; ", asm_out_file
);
635 vfprintf (asm_out_file
, comment
, ap
);
640 putc ('\n', asm_out_file
);
645 /* Output an signed LEB128 quantity, but only the byte values. */
648 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value
)
654 byte
= (value
& 0x7f);
656 more
= !((value
== 0 && (byte
& 0x40) == 0)
657 || (value
== -1 && (byte
& 0x40) != 0));
661 fprintf (asm_out_file
, "%#x", byte
);
664 fputc (',', asm_out_file
);
668 /* Output a signed LEB128 quantity. */
671 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value
,
672 const char *comment
, ...)
676 va_start (ap
, comment
);
678 #ifdef HAVE_AS_LEB128
679 fprintf (asm_out_file
, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC
, value
);
681 if (flag_debug_asm
&& comment
)
683 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
684 vfprintf (asm_out_file
, comment
, ap
);
688 HOST_WIDE_INT work
= value
;
690 const char *byte_op
= targetm
.asm_out
.byte_op
;
693 fputs (byte_op
, asm_out_file
);
696 byte
= (work
& 0x7f);
697 /* arithmetic shift */
699 more
= !((work
== 0 && (byte
& 0x40) == 0)
700 || (work
== -1 && (byte
& 0x40) != 0));
706 fprintf (asm_out_file
, "%#x", byte
);
708 fputc (',', asm_out_file
);
711 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
717 fprintf (asm_out_file
, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC
,
718 ASM_COMMENT_START
, value
);
721 fputs ("; ", asm_out_file
);
722 vfprintf (asm_out_file
, comment
, ap
);
727 fputc ('\n', asm_out_file
);
733 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED
,
734 const char *lab2 ATTRIBUTE_UNUSED
,
735 const char *comment
, ...)
739 va_start (ap
, comment
);
741 #ifdef HAVE_AS_LEB128
742 fputs ("\t.uleb128 ", asm_out_file
);
743 assemble_name (asm_out_file
, lab1
);
744 putc ('-', asm_out_file
);
745 assemble_name (asm_out_file
, lab2
);
750 if (flag_debug_asm
&& comment
)
752 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
753 vfprintf (asm_out_file
, comment
, ap
);
755 fputc ('\n', asm_out_file
);
763 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED
,
764 const char *lab2 ATTRIBUTE_UNUSED
,
765 const char *comment
, ...)
769 va_start (ap
, comment
);
771 #ifdef HAVE_AS_LEB128
772 fputs ("\t.sleb128 ", asm_out_file
);
773 assemble_name (asm_out_file
, lab1
);
774 putc ('-', asm_out_file
);
775 assemble_name (asm_out_file
, lab2
);
780 if (flag_debug_asm
&& comment
)
782 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
783 vfprintf (asm_out_file
, comment
, ap
);
785 fputc ('\n', asm_out_file
);
791 static int dw2_output_indirect_constant_1 (splay_tree_node
, void *);
793 static GTY((param1_is (char *), param2_is (tree
))) splay_tree indirect_pool
;
795 static GTY(()) int dw2_const_labelno
;
797 #if defined(HAVE_GAS_HIDDEN)
798 # define USE_LINKONCE_INDIRECT (SUPPORTS_ONE_ONLY)
800 # define USE_LINKONCE_INDIRECT 0
803 /* Comparison function for a splay tree in which the keys are strings.
804 K1 and K2 have the dynamic type "const char *". Returns <0, 0, or
805 >0 to indicate whether K1 is less than, equal to, or greater than
809 splay_tree_compare_strings (splay_tree_key k1
, splay_tree_key k2
)
811 const char *s1
= (const char *)k1
;
812 const char *s2
= (const char *)k2
;
818 ret
= strcmp (s1
, s2
);
820 /* The strings are always those from IDENTIFIER_NODEs, and,
821 therefore, we should never have two copies of the same
828 /* Put X, a SYMBOL_REF, in memory. Return a SYMBOL_REF to the allocated
829 memory. Differs from force_const_mem in that a single pool is used for
830 the entire unit of translation, and the memory is not guaranteed to be
831 "near" the function in any interesting sense. IS_PUBLIC controls whether
832 the symbol can be shared across the entire application (or DSO). */
835 dw2_force_const_mem (rtx x
, bool is_public
)
837 splay_tree_node node
;
842 /* We use strcmp, rather than just comparing pointers, so that the
843 sort order will not depend on the host system. */
844 indirect_pool
= splay_tree_new_ggc (splay_tree_compare_strings
,
845 ggc_alloc_splay_tree_str_tree_node_splay_tree_s
,
846 ggc_alloc_splay_tree_str_tree_node_splay_tree_node_s
);
848 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
851 node
= splay_tree_lookup (indirect_pool
, (splay_tree_key
) key
);
853 decl_id
= (tree
) node
->value
;
857 const char *str
= targetm
.strip_name_encoding (key
);
859 if (is_public
&& USE_LINKONCE_INDIRECT
)
861 char *ref_name
= XALLOCAVEC (char, strlen (str
) + sizeof "DW.ref.");
863 sprintf (ref_name
, "DW.ref.%s", str
);
864 gcc_assert (!maybe_get_identifier (ref_name
));
865 decl_id
= get_identifier (ref_name
);
866 TREE_PUBLIC (decl_id
) = 1;
872 ASM_GENERATE_INTERNAL_LABEL (label
, "LDFCM", dw2_const_labelno
);
874 gcc_assert (!maybe_get_identifier (label
));
875 decl_id
= get_identifier (label
);
878 id
= maybe_get_identifier (str
);
880 TREE_SYMBOL_REFERENCED (id
) = 1;
882 splay_tree_insert (indirect_pool
, (splay_tree_key
) key
,
883 (splay_tree_value
) decl_id
);
886 return gen_rtx_SYMBOL_REF (Pmode
, IDENTIFIER_POINTER (decl_id
));
889 /* A helper function for dw2_output_indirect_constants called through
890 splay_tree_foreach. Emit one queued constant to memory. */
893 dw2_output_indirect_constant_1 (splay_tree_node node
,
894 void *data ATTRIBUTE_UNUSED
)
900 sym
= (const char *) node
->key
;
901 id
= (tree
) node
->value
;
903 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, id
, ptr_type_node
);
904 SET_DECL_ASSEMBLER_NAME (decl
, id
);
905 DECL_ARTIFICIAL (decl
) = 1;
906 DECL_IGNORED_P (decl
) = 1;
907 DECL_INITIAL (decl
) = decl
;
908 TREE_READONLY (decl
) = 1;
909 TREE_STATIC (decl
) = 1;
911 if (TREE_PUBLIC (id
))
913 TREE_PUBLIC (decl
) = 1;
914 make_decl_one_only (decl
, DECL_ASSEMBLER_NAME (decl
));
915 if (USE_LINKONCE_INDIRECT
)
916 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
919 sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, sym
);
920 assemble_variable (decl
, 1, 1, 1);
921 assemble_integer (sym_ref
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
926 /* Emit the constants queued through dw2_force_const_mem. */
929 dw2_output_indirect_constants (void)
932 splay_tree_foreach (indirect_pool
, dw2_output_indirect_constant_1
, NULL
);
935 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
936 If PUBLIC is set and the encoding is DW_EH_PE_indirect, the indirect
937 reference is shared across the entire application (or DSO). */
940 dw2_asm_output_encoded_addr_rtx (int encoding
, rtx addr
, bool is_public
,
941 const char *comment
, ...)
946 va_start (ap
, comment
);
948 size
= size_of_encoded_value (encoding
);
950 if (encoding
== DW_EH_PE_aligned
)
952 assemble_align (POINTER_SIZE
);
953 assemble_integer (addr
, size
, POINTER_SIZE
, 1);
958 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
960 if (addr
== const0_rtx
|| addr
== const1_rtx
)
961 assemble_integer (addr
, size
, BITS_PER_UNIT
, 1);
965 /* Allow the target first crack at emitting this. Some of the
966 special relocations require special directives instead of
967 just ".4byte" or whatever. */
968 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
969 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file
, encoding
, size
,
973 /* Indirection is used to get dynamic relocations out of a
974 read-only section. */
975 if (encoding
& DW_EH_PE_indirect
)
977 /* It is very tempting to use force_const_mem so that we share data
978 with the normal constant pool. However, we've already emitted
979 the constant pool for this function. Moreover, we'd like to
980 share these constants across the entire unit of translation and
981 even, if possible, across the entire application (or DSO). */
982 addr
= dw2_force_const_mem (addr
, is_public
);
983 encoding
&= ~DW_EH_PE_indirect
;
987 switch (encoding
& 0xF0)
989 case DW_EH_PE_absptr
:
990 dw2_assemble_integer (size
, addr
);
994 gcc_assert (GET_CODE (addr
) == SYMBOL_REF
);
995 #ifdef ASM_OUTPUT_DWARF_PCREL
996 ASM_OUTPUT_DWARF_PCREL (asm_out_file
, size
, XSTR (addr
, 0));
998 dw2_assemble_integer (size
, gen_rtx_MINUS (Pmode
, addr
, pc_rtx
));
1003 /* Other encodings should have been handled by
1004 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
1008 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
1013 if (flag_debug_asm
&& comment
)
1015 fprintf (asm_out_file
, "\t%s ", ASM_COMMENT_START
);
1016 vfprintf (asm_out_file
, comment
, ap
);
1018 fputc ('\n', asm_out_file
);
1023 #include "gt-dwarf2asm.h"