* var-tracking.c (insn_stack_adjust_offset_pre_post): If insn has a
[official-gcc.git] / gcc / dwarf2asm.c
blobe490b34a10a055906c1708b3a880c6c415876598
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
9 version.
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
14 for more details.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "flags.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "output.h"
29 #include "target.h"
30 #include "dwarf2asm.h"
31 #include "dwarf2.h"
32 #include "splay-tree.h"
33 #include "ggc.h"
34 #include "tm_p.h"
37 /* How to start an assembler comment. */
38 #ifndef ASM_COMMENT_START
39 #define ASM_COMMENT_START ";#"
40 #endif
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. */
46 void
47 dw2_assemble_integer (int size, rtx x)
49 const char *op = integer_asm_op (size, FALSE);
51 if (op)
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));
57 else
58 output_addr_const (asm_out_file, x);
60 else
61 assemble_integer (x, size, BITS_PER_UNIT, 1);
65 /* Output a value of a given size in target byte order. */
67 void
68 dw2_asm_output_data_raw (int size, unsigned HOST_WIDE_INT value)
70 unsigned char bytes[8];
71 int i;
73 for (i = 0; i < 8; ++i)
75 bytes[i] = value & 0xff;
76 value >>= 8;
79 if (BYTES_BIG_ENDIAN)
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]);
85 else
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. */
95 void
96 dw2_asm_output_data (int size, unsigned HOST_WIDE_INT value,
97 const char *comment, ...)
99 va_list ap;
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));
107 if (op)
108 fprintf (asm_out_file, "%s" HOST_WIDE_INT_PRINT_HEX, op, value);
109 else
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);
119 va_end (ap);
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. */
128 void
129 dw2_asm_output_delta (int size, const char *lab1, const char *lab2,
130 const char *comment, ...)
132 va_list ap;
134 va_start (ap, comment);
136 #ifdef ASM_OUTPUT_DWARF_DELTA
137 ASM_OUTPUT_DWARF_DELTA (asm_out_file, size, lab1, lab2);
138 #else
139 dw2_assemble_integer (size,
140 gen_rtx_MINUS (Pmode,
141 gen_rtx_SYMBOL_REF (Pmode, lab1),
142 gen_rtx_SYMBOL_REF (Pmode, lab2)));
143 #endif
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);
151 va_end (ap);
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. */
161 void
162 dw2_asm_output_offset (int size, const char *label,
163 section *base ATTRIBUTE_UNUSED,
164 const char *comment, ...)
166 va_list ap;
168 va_start (ap, comment);
170 #ifdef ASM_OUTPUT_DWARF_OFFSET
171 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label, base);
172 #else
173 dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
174 #endif
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);
183 va_end (ap);
186 #if 0
188 /* Output a self-relative reference to a label, possibly in a
189 different section or object file. */
191 void
192 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED,
193 const char *label ATTRIBUTE_UNUSED,
194 const char *comment, ...)
196 va_list ap;
198 va_start (ap, comment);
200 #ifdef ASM_OUTPUT_DWARF_PCREL
201 ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, label);
202 #else
203 dw2_assemble_integer (size,
204 gen_rtx_MINUS (Pmode,
205 gen_rtx_SYMBOL_REF (Pmode, label),
206 pc_rtx));
207 #endif
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);
216 va_end (ap);
218 #endif /* 0 */
220 /* Output an absolute reference to a label. */
222 void
223 dw2_asm_output_addr (int size, const char *label,
224 const char *comment, ...)
226 va_list ap;
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);
239 va_end (ap);
242 /* Similar, but use an RTX expression instead of a text label. */
244 void
245 dw2_asm_output_addr_rtx (int size, rtx addr,
246 const char *comment, ...)
248 va_list ap;
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);
261 va_end (ap);
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. */
271 void
272 dw2_asm_output_nstring (const char *str, size_t orig_len,
273 const char *comment, ...)
275 size_t i, len;
276 va_list ap;
278 va_start (ap, comment);
280 len = orig_len;
282 if (len == (size_t) -1)
283 len = strlen (str);
285 if (flag_debug_asm && comment)
287 fputs ("\t.ascii \"", asm_out_file);
288 for (i = 0; i < len; i++)
290 int c = str[i];
291 if (c == '\"' || c == '\\')
292 fputc ('\\', asm_out_file);
293 if (ISPRINT(c))
294 fputc (c, asm_out_file);
295 else
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);
302 else
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)
307 len += 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);
313 va_end (ap);
317 /* Return the size of an unsigned LEB128 quantity. */
320 size_of_uleb128 (unsigned HOST_WIDE_INT value)
322 int size = 0;
326 value >>= 7;
327 size += 1;
329 while (value != 0);
331 return size;
334 /* Return the size of a signed LEB128 quantity. */
337 size_of_sleb128 (HOST_WIDE_INT value)
339 int size = 0, byte;
343 byte = (value & 0x7f);
344 value >>= 7;
345 size += 1;
347 while (!((value == 0 && (byte & 0x40) == 0)
348 || (value == -1 && (byte & 0x40) != 0)));
350 return size;
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
355 include leb128. */
358 size_of_encoded_value (int encoding)
360 if (encoding == DW_EH_PE_omit)
361 return 0;
363 switch (encoding & 0x07)
365 case DW_EH_PE_absptr:
366 return POINTER_SIZE / BITS_PER_UNIT;
367 case DW_EH_PE_udata2:
368 return 2;
369 case DW_EH_PE_udata4:
370 return 4;
371 case DW_EH_PE_udata8:
372 return 8;
373 default:
374 gcc_unreachable ();
378 /* Yield a name for a given pointer encoding. */
380 const char *
381 eh_data_format_name (int format)
383 #if HAVE_DESIGNATED_INITIALIZERS
384 #define S(p, v) [p] = v,
385 #else
386 #define S(p, v) case p: return v;
387 #endif
389 #if HAVE_DESIGNATED_INITIALIZERS
390 __extension__ static const char * const format_names[256] = {
391 #else
392 switch (format) {
393 #endif
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,
449 "indirect 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,
468 "indirect 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,
487 "indirect 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,
506 "indirect 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];
530 #else
532 gcc_unreachable ();
533 #endif
536 /* Output an unsigned LEB128 quantity, but only the byte values. */
538 void
539 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value)
541 while (1)
543 int byte = (value & 0x7f);
544 value >>= 7;
545 if (value != 0)
546 /* More bytes to follow. */
547 byte |= 0x80;
549 fprintf (asm_out_file, "0x%x", byte);
550 if (value == 0)
551 break;
552 fputc (',', asm_out_file);
556 /* Output an unsigned LEB128 quantity. */
558 void
559 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value,
560 const char *comment, ...)
562 va_list ap;
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);
574 #else
576 unsigned HOST_WIDE_INT work = value;
577 const char *byte_op = targetm.asm_out.byte_op;
579 if (byte_op)
580 fputs (byte_op, asm_out_file);
583 int byte = (work & 0x7f);
584 work >>= 7;
585 if (work != 0)
586 /* More bytes to follow. */
587 byte |= 0x80;
589 if (byte_op)
591 fprintf (asm_out_file, "0x%x", byte);
592 if (work != 0)
593 fputc (',', asm_out_file);
595 else
596 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
598 while (work != 0);
600 if (flag_debug_asm)
602 fprintf (asm_out_file, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX,
603 ASM_COMMENT_START, value);
604 if (comment)
606 fputs ("; ", asm_out_file);
607 vfprintf (asm_out_file, comment, ap);
611 #endif
612 fputc ('\n', asm_out_file);
614 va_end (ap);
617 /* Output an signed LEB128 quantity, but only the byte values. */
619 void
620 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value)
622 int byte, more;
624 while (1)
626 byte = (value & 0x7f);
627 value >>= 7;
628 more = !((value == 0 && (byte & 0x40) == 0)
629 || (value == -1 && (byte & 0x40) != 0));
630 if (more)
631 byte |= 0x80;
633 fprintf (asm_out_file, "0x%x", byte);
634 if (!more)
635 break;
636 fputc (',', asm_out_file);
640 /* Output a signed LEB128 quantity. */
642 void
643 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value,
644 const char *comment, ...)
646 va_list ap;
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);
658 #else
660 HOST_WIDE_INT work = value;
661 int more, byte;
662 const char *byte_op = targetm.asm_out.byte_op;
664 if (byte_op)
665 fputs (byte_op, asm_out_file);
668 byte = (work & 0x7f);
669 /* arithmetic shift */
670 work >>= 7;
671 more = !((work == 0 && (byte & 0x40) == 0)
672 || (work == -1 && (byte & 0x40) != 0));
673 if (more)
674 byte |= 0x80;
676 if (byte_op)
678 fprintf (asm_out_file, "0x%x", byte);
679 if (more)
680 fputc (',', asm_out_file);
682 else
683 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
685 while (more);
687 if (flag_debug_asm)
689 fprintf (asm_out_file, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC,
690 ASM_COMMENT_START, value);
691 if (comment)
693 fputs ("; ", asm_out_file);
694 vfprintf (asm_out_file, comment, ap);
698 #endif
699 fputc ('\n', asm_out_file);
701 va_end (ap);
704 void
705 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED,
706 const char *lab2 ATTRIBUTE_UNUSED,
707 const char *comment, ...)
709 va_list ap;
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);
718 #else
719 gcc_unreachable ();
720 #endif
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);
729 va_end (ap);
732 #if 0
734 void
735 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED,
736 const char *lab2 ATTRIBUTE_UNUSED,
737 const char *comment, ...)
739 va_list ap;
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);
748 #else
749 gcc_unreachable ();
750 #endif
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);
759 va_end (ap);
761 #endif /* 0 */
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
771 #else
772 # define USE_LINKONCE_INDIRECT 0
773 #endif
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
778 K2, respectively. */
780 static int
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;
785 int ret;
787 if (s1 == s2)
788 return 0;
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
794 string. */
795 gcc_assert (ret);
797 return ret;
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;
810 const char *key;
811 tree decl;
813 if (! indirect_pool)
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);
820 key = XSTR (x, 0);
821 node = splay_tree_lookup (indirect_pool, (splay_tree_key) key);
822 if (node)
823 decl = (tree) node->value;
824 else
826 tree id;
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);
842 else
844 char label[32];
846 ASM_GENERATE_INTERNAL_LABEL (label, "LDFCM", dw2_const_labelno);
847 ++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);
857 if (id)
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. */
870 static int
871 dw2_output_indirect_constant_1 (splay_tree_node node,
872 void *data ATTRIBUTE_UNUSED)
874 const char *sym;
875 rtx sym_ref;
876 tree decl;
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);
887 return 0;
890 /* Emit the constants queued through dw2_force_const_mem. */
892 void
893 dw2_output_indirect_constants (void)
895 if (indirect_pool)
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). */
903 void
904 dw2_asm_output_encoded_addr_rtx (int encoding, rtx addr, bool is_public,
905 const char *comment, ...)
907 int size;
908 va_list ap;
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);
918 return;
921 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
922 "all others". */
923 if (addr == const0_rtx || addr == const1_rtx)
924 assemble_integer (addr, size, BITS_PER_UNIT, 1);
925 else
927 restart:
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,
933 addr, done);
934 #endif
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;
947 goto restart;
950 switch (encoding & 0xF0)
952 case DW_EH_PE_absptr:
953 dw2_assemble_integer (size, addr);
954 break;
956 case DW_EH_PE_pcrel:
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));
960 #else
961 dw2_assemble_integer (size, gen_rtx_MINUS (Pmode, addr, pc_rtx));
962 #endif
963 break;
965 default:
966 /* Other encodings should have been handled by
967 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
968 gcc_unreachable ();
971 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
972 done:;
973 #endif
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);
983 va_end (ap);
986 #include "gt-dwarf2asm.h"