* lto-symtab.c (lto_varpool_replace_node): Merge TLS models.
[official-gcc.git] / gcc / dwarf2asm.c
blobc5942b902748719d2ed01e1cb13f4993ac420b4b
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
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 "hash-set.h"
27 #include "machmode.h"
28 #include "vec.h"
29 #include "double-int.h"
30 #include "input.h"
31 #include "alias.h"
32 #include "symtab.h"
33 #include "wide-int.h"
34 #include "inchash.h"
35 #include "real.h"
36 #include "tree.h"
37 #include "stringpool.h"
38 #include "varasm.h"
39 #include "rtl.h"
40 #include "output.h"
41 #include "target.h"
42 #include "dwarf2asm.h"
43 #include "dwarf2.h"
44 #include "hash-map.h"
45 #include "ggc.h"
46 #include "tm_p.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. */
52 void
53 dw2_assemble_integer (int size, rtx x)
55 const char *op = integer_asm_op (size, FALSE);
57 if (op)
59 fputs (op, asm_out_file);
60 if (CONST_INT_P (x))
61 fprint_whex (asm_out_file, (unsigned HOST_WIDE_INT) INTVAL (x));
62 else
63 output_addr_const (asm_out_file, x);
65 else
66 assemble_integer (x, size, BITS_PER_UNIT, 1);
70 /* Output a value of a given size in target byte order. */
72 void
73 dw2_asm_output_data_raw (int size, unsigned HOST_WIDE_INT value)
75 unsigned char bytes[8];
76 int i;
78 for (i = 0; i < 8; ++i)
80 bytes[i] = value & 0xff;
81 value >>= 8;
84 if (BYTES_BIG_ENDIAN)
86 for (i = size - 1; i > 0; --i)
87 fprintf (asm_out_file, "%#x,", bytes[i]);
88 fprintf (asm_out_file, "%#x", bytes[0]);
90 else
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. */
100 void
101 dw2_asm_output_data (int size, unsigned HOST_WIDE_INT value,
102 const char *comment, ...)
104 va_list ap;
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));
112 if (op)
114 fputs (op, asm_out_file);
115 fprint_whex (asm_out_file, value);
117 else
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);
127 va_end (ap);
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. */
136 void
137 dw2_asm_output_delta (int size, const char *lab1, const char *lab2,
138 const char *comment, ...)
140 va_list ap;
142 va_start (ap, comment);
144 #ifdef ASM_OUTPUT_DWARF_DELTA
145 ASM_OUTPUT_DWARF_DELTA (asm_out_file, size, lab1, lab2);
146 #else
147 dw2_assemble_integer (size,
148 gen_rtx_MINUS (Pmode,
149 gen_rtx_SYMBOL_REF (Pmode, lab1),
150 gen_rtx_SYMBOL_REF (Pmode, lab2)));
151 #endif
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);
159 va_end (ap);
162 /* Output the difference between two symbols in instruction units
163 in a given size. */
165 void
166 dw2_asm_output_vms_delta (int size ATTRIBUTE_UNUSED,
167 const char *lab1, const char *lab2,
168 const char *comment, ...)
170 va_list ap;
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);
178 #else
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);
186 #endif
188 va_end (ap);
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. */
198 void
199 dw2_asm_output_offset (int size, const char *label,
200 section *base ATTRIBUTE_UNUSED,
201 const char *comment, ...)
203 va_list ap;
205 va_start (ap, comment);
207 #ifdef ASM_OUTPUT_DWARF_OFFSET
208 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label, base);
209 #else
210 dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
211 #endif
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);
220 va_end (ap);
223 #if 0
225 /* Output a self-relative reference to a label, possibly in a
226 different section or object file. */
228 void
229 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED,
230 const char *label ATTRIBUTE_UNUSED,
231 const char *comment, ...)
233 va_list ap;
235 va_start (ap, comment);
237 #ifdef ASM_OUTPUT_DWARF_PCREL
238 ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, label);
239 #else
240 dw2_assemble_integer (size,
241 gen_rtx_MINUS (Pmode,
242 gen_rtx_SYMBOL_REF (Pmode, label),
243 pc_rtx));
244 #endif
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);
253 va_end (ap);
255 #endif /* 0 */
257 /* Output an absolute reference to a label. */
259 void
260 dw2_asm_output_addr (int size, const char *label,
261 const char *comment, ...)
263 va_list ap;
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);
276 va_end (ap);
279 /* Similar, but use an RTX expression instead of a text label. */
281 void
282 dw2_asm_output_addr_rtx (int size, rtx addr,
283 const char *comment, ...)
285 va_list ap;
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);
298 va_end (ap);
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. */
308 void
309 dw2_asm_output_nstring (const char *str, size_t orig_len,
310 const char *comment, ...)
312 size_t i, len;
313 va_list ap;
315 va_start (ap, comment);
317 len = orig_len;
319 if (len == (size_t) -1)
320 len = strlen (str);
322 if (flag_debug_asm && comment)
324 fputs ("\t.ascii \"", asm_out_file);
325 for (i = 0; i < len; i++)
327 int c = str[i];
328 if (c == '\"' || c == '\\')
329 fputc ('\\', asm_out_file);
330 if (ISPRINT (c))
331 fputc (c, asm_out_file);
332 else
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);
339 else
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)
344 len += 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);
350 va_end (ap);
354 /* Return the size of an unsigned LEB128 quantity. */
357 size_of_uleb128 (unsigned HOST_WIDE_INT value)
359 int size = 0;
363 value >>= 7;
364 size += 1;
366 while (value != 0);
368 return size;
371 /* Return the size of a signed LEB128 quantity. */
374 size_of_sleb128 (HOST_WIDE_INT value)
376 int size = 0, byte;
380 byte = (value & 0x7f);
381 value >>= 7;
382 size += 1;
384 while (!((value == 0 && (byte & 0x40) == 0)
385 || (value == -1 && (byte & 0x40) != 0)));
387 return size;
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
392 include leb128. */
395 size_of_encoded_value (int encoding)
397 if (encoding == DW_EH_PE_omit)
398 return 0;
400 switch (encoding & 0x07)
402 case DW_EH_PE_absptr:
403 return POINTER_SIZE_UNITS;
404 case DW_EH_PE_udata2:
405 return 2;
406 case DW_EH_PE_udata4:
407 return 4;
408 case DW_EH_PE_udata8:
409 return 8;
410 default:
411 gcc_unreachable ();
415 /* Yield a name for a given pointer encoding. */
417 const char *
418 eh_data_format_name (int format)
420 #if HAVE_DESIGNATED_INITIALIZERS
421 #define S(p, v) [p] = v,
422 #else
423 #define S(p, v) case p: return v;
424 #endif
426 #if HAVE_DESIGNATED_INITIALIZERS
427 __extension__ static const char * const format_names[256] = {
428 #else
429 switch (format) {
430 #endif
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,
488 "indirect 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,
507 "indirect 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,
526 "indirect 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,
545 "indirect 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];
569 #else
571 gcc_unreachable ();
572 #endif
575 /* Output an unsigned LEB128 quantity, but only the byte values. */
577 void
578 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value)
580 while (1)
582 int byte = (value & 0x7f);
583 value >>= 7;
584 if (value != 0)
585 /* More bytes to follow. */
586 byte |= 0x80;
588 fprintf (asm_out_file, "%#x", byte);
589 if (value == 0)
590 break;
591 fputc (',', asm_out_file);
595 /* Output an unsigned LEB128 quantity. */
597 void
598 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value,
599 const char *comment, ...)
601 va_list ap;
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);
614 #else
616 unsigned HOST_WIDE_INT work = value;
617 const char *byte_op = targetm.asm_out.byte_op;
619 if (byte_op)
620 fputs (byte_op, asm_out_file);
623 int byte = (work & 0x7f);
624 work >>= 7;
625 if (work != 0)
626 /* More bytes to follow. */
627 byte |= 0x80;
629 if (byte_op)
631 fprintf (asm_out_file, "%#x", byte);
632 if (work != 0)
633 fputc (',', asm_out_file);
635 else
636 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
638 while (work != 0);
640 if (flag_debug_asm)
642 fprintf (asm_out_file, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX,
643 ASM_COMMENT_START, value);
644 if (comment)
646 fputs ("; ", asm_out_file);
647 vfprintf (asm_out_file, comment, ap);
651 #endif
652 putc ('\n', asm_out_file);
654 va_end (ap);
657 /* Output an signed LEB128 quantity, but only the byte values. */
659 void
660 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value)
662 int byte, more;
664 while (1)
666 byte = (value & 0x7f);
667 value >>= 7;
668 more = !((value == 0 && (byte & 0x40) == 0)
669 || (value == -1 && (byte & 0x40) != 0));
670 if (more)
671 byte |= 0x80;
673 fprintf (asm_out_file, "%#x", byte);
674 if (!more)
675 break;
676 fputc (',', asm_out_file);
680 /* Output a signed LEB128 quantity. */
682 void
683 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value,
684 const char *comment, ...)
686 va_list ap;
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);
698 #else
700 HOST_WIDE_INT work = value;
701 int more, byte;
702 const char *byte_op = targetm.asm_out.byte_op;
704 if (byte_op)
705 fputs (byte_op, asm_out_file);
708 byte = (work & 0x7f);
709 /* arithmetic shift */
710 work >>= 7;
711 more = !((work == 0 && (byte & 0x40) == 0)
712 || (work == -1 && (byte & 0x40) != 0));
713 if (more)
714 byte |= 0x80;
716 if (byte_op)
718 fprintf (asm_out_file, "%#x", byte);
719 if (more)
720 fputc (',', asm_out_file);
722 else
723 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
725 while (more);
727 if (flag_debug_asm)
729 fprintf (asm_out_file, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC,
730 ASM_COMMENT_START, value);
731 if (comment)
733 fputs ("; ", asm_out_file);
734 vfprintf (asm_out_file, comment, ap);
738 #endif
739 fputc ('\n', asm_out_file);
741 va_end (ap);
744 void
745 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED,
746 const char *lab2 ATTRIBUTE_UNUSED,
747 const char *comment, ...)
749 va_list ap;
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);
758 #else
759 gcc_unreachable ();
760 #endif
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);
769 va_end (ap);
772 #if 0
774 void
775 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED,
776 const char *lab2 ATTRIBUTE_UNUSED,
777 const char *comment, ...)
779 va_list ap;
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);
788 #else
789 gcc_unreachable ();
790 #endif
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);
799 va_end (ap);
801 #endif /* 0 */
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)
809 #else
810 # define USE_LINKONCE_INDIRECT 0
811 #endif
813 /* Compare two std::pair<const char *, tree> by their first element.
814 Returns <0, 0, or
815 >0 to indicate whether K1 is less than, equal to, or greater than
816 K2, respectively. */
818 static int
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;
823 int ret;
825 if (s1 == s2)
826 return 0;
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
832 string. */
833 gcc_assert (ret);
835 return ret;
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)
847 const char *key;
848 tree decl_id;
850 if (! indirect_pool)
851 indirect_pool = hash_map<const char *, tree>::create_ggc (64);
853 gcc_assert (GET_CODE (x) == SYMBOL_REF);
855 key = XSTR (x, 0);
856 tree *slot = indirect_pool->get (key);
857 if (slot)
858 decl_id = *slot;
859 else
861 tree id;
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;
873 else
875 char label[32];
877 ASM_GENERATE_INTERNAL_LABEL (label, "LDFCM", dw2_const_labelno);
878 ++dw2_const_labelno;
879 gcc_assert (!maybe_get_identifier (label));
880 decl_id = get_identifier (label);
883 id = maybe_get_identifier (str);
884 if (id)
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. */
896 static int
897 dw2_output_indirect_constant_1 (const char *sym, tree id)
899 rtx sym_ref;
900 tree decl;
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);
922 return 0;
925 /* Emit the constants queued through dw2_force_const_mem. */
927 void
928 dw2_output_indirect_constants (void)
930 if (!indirect_pool)
931 return;
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). */
948 void
949 dw2_asm_output_encoded_addr_rtx (int encoding, rtx addr, bool is_public,
950 const char *comment, ...)
952 int size;
953 va_list ap;
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);
963 va_end (ap);
964 return;
967 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
968 "all others". */
969 if (addr == const0_rtx || addr == const1_rtx)
970 assemble_integer (addr, size, BITS_PER_UNIT, 1);
971 else
973 restart:
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,
979 addr, done);
980 #endif
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;
993 goto restart;
996 switch (encoding & 0xF0)
998 case DW_EH_PE_absptr:
999 dw2_assemble_integer (size, addr);
1000 break;
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));
1006 #else
1007 dw2_assemble_integer (size, gen_rtx_MINUS (Pmode, addr, pc_rtx));
1008 #endif
1009 break;
1011 default:
1012 /* Other encodings should have been handled by
1013 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
1014 gcc_unreachable ();
1017 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
1018 done:;
1019 #endif
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);
1029 va_end (ap);
1032 #include "gt-dwarf2asm.h"