2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / dwarf2asm.c
blob3a30fe443a8638baca807d5d4c44f59a56ecd9d5
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 "alias.h"
27 #include "tree.h"
28 #include "stringpool.h"
29 #include "varasm.h"
30 #include "rtl.h"
31 #include "output.h"
32 #include "target.h"
33 #include "dwarf2asm.h"
34 #include "dwarf2.h"
35 #include "tm_p.h"
38 /* Output an unaligned integer with the given value and size. Prefer not
39 to print a newline, since the caller may want to add a comment. */
41 void
42 dw2_assemble_integer (int size, rtx x)
44 const char *op = integer_asm_op (size, FALSE);
46 if (op)
48 fputs (op, asm_out_file);
49 if (CONST_INT_P (x))
50 fprint_whex (asm_out_file, (unsigned HOST_WIDE_INT) INTVAL (x));
51 else
52 output_addr_const (asm_out_file, x);
54 else
55 assemble_integer (x, size, BITS_PER_UNIT, 1);
59 /* Output a value of a given size in target byte order. */
61 void
62 dw2_asm_output_data_raw (int size, unsigned HOST_WIDE_INT value)
64 unsigned char bytes[8];
65 int i;
67 for (i = 0; i < 8; ++i)
69 bytes[i] = value & 0xff;
70 value >>= 8;
73 if (BYTES_BIG_ENDIAN)
75 for (i = size - 1; i > 0; --i)
76 fprintf (asm_out_file, "%#x,", bytes[i]);
77 fprintf (asm_out_file, "%#x", bytes[0]);
79 else
81 for (i = 0; i < size - 1; ++i)
82 fprintf (asm_out_file, "%#x,", bytes[i]);
83 fprintf (asm_out_file, "%#x", bytes[i]);
87 /* Output an immediate constant in a given SIZE in bytes. */
89 void
90 dw2_asm_output_data (int size, unsigned HOST_WIDE_INT value,
91 const char *comment, ...)
93 va_list ap;
94 const char *op = integer_asm_op (size, FALSE);
96 va_start (ap, comment);
98 if (size * 8 < HOST_BITS_PER_WIDE_INT)
99 value &= ~(~(unsigned HOST_WIDE_INT) 0 << (size * 8));
101 if (op)
103 fputs (op, asm_out_file);
104 fprint_whex (asm_out_file, value);
106 else
107 assemble_integer (GEN_INT (value), size, BITS_PER_UNIT, 1);
109 if (flag_debug_asm && comment)
111 fputs ("\t" ASM_COMMENT_START " ", asm_out_file);
112 vfprintf (asm_out_file, comment, ap);
114 putc ('\n', asm_out_file);
116 va_end (ap);
119 /* Output the difference between two symbols in a given size. */
120 /* ??? There appear to be assemblers that do not like such
121 subtraction, but do support ASM_SET_OP. It's unfortunately
122 impossible to do here, since the ASM_SET_OP for the difference
123 symbol must appear after both symbols are defined. */
125 void
126 dw2_asm_output_delta (int size, const char *lab1, const char *lab2,
127 const char *comment, ...)
129 va_list ap;
131 va_start (ap, comment);
133 #ifdef ASM_OUTPUT_DWARF_DELTA
134 ASM_OUTPUT_DWARF_DELTA (asm_out_file, size, lab1, lab2);
135 #else
136 dw2_assemble_integer (size,
137 gen_rtx_MINUS (Pmode,
138 gen_rtx_SYMBOL_REF (Pmode, lab1),
139 gen_rtx_SYMBOL_REF (Pmode, lab2)));
140 #endif
141 if (flag_debug_asm && comment)
143 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
144 vfprintf (asm_out_file, comment, ap);
146 fputc ('\n', asm_out_file);
148 va_end (ap);
151 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
152 /* Output the difference between two symbols in instruction units
153 in a given size. */
155 void
156 dw2_asm_output_vms_delta (int size ATTRIBUTE_UNUSED,
157 const char *lab1, const char *lab2,
158 const char *comment, ...)
160 va_list ap;
162 va_start (ap, comment);
164 ASM_OUTPUT_DWARF_VMS_DELTA (asm_out_file, size, lab1, lab2);
165 if (flag_debug_asm && comment)
167 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
168 vfprintf (asm_out_file, comment, ap);
170 fputc ('\n', asm_out_file);
172 va_end (ap);
174 #endif
176 /* Output a section-relative reference to a LABEL, which was placed in
177 BASE. In general this can only be done for debugging symbols.
178 E.g. on most targets with the GNU linker, this is accomplished with
179 a direct reference and the knowledge that the debugging section
180 will be placed at VMA 0. Some targets have special relocations for
181 this that we must use. */
183 void
184 dw2_asm_output_offset (int size, const char *label,
185 section *base ATTRIBUTE_UNUSED,
186 const char *comment, ...)
188 va_list ap;
190 va_start (ap, comment);
192 #ifdef ASM_OUTPUT_DWARF_OFFSET
193 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label, base);
194 #else
195 dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
196 #endif
198 if (flag_debug_asm && comment)
200 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
201 vfprintf (asm_out_file, comment, ap);
203 fputc ('\n', asm_out_file);
205 va_end (ap);
208 #if 0
210 /* Output a self-relative reference to a label, possibly in a
211 different section or object file. */
213 void
214 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED,
215 const char *label ATTRIBUTE_UNUSED,
216 const char *comment, ...)
218 va_list ap;
220 va_start (ap, comment);
222 #ifdef ASM_OUTPUT_DWARF_PCREL
223 ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, label);
224 #else
225 dw2_assemble_integer (size,
226 gen_rtx_MINUS (Pmode,
227 gen_rtx_SYMBOL_REF (Pmode, label),
228 pc_rtx));
229 #endif
231 if (flag_debug_asm && comment)
233 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
234 vfprintf (asm_out_file, comment, ap);
236 fputc ('\n', asm_out_file);
238 va_end (ap);
240 #endif /* 0 */
242 /* Output an absolute reference to a label. */
244 void
245 dw2_asm_output_addr (int size, const char *label,
246 const char *comment, ...)
248 va_list ap;
250 va_start (ap, comment);
252 dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
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 /* Similar, but use an RTX expression instead of a text label. */
266 void
267 dw2_asm_output_addr_rtx (int size, rtx addr,
268 const char *comment, ...)
270 va_list ap;
272 va_start (ap, comment);
274 dw2_assemble_integer (size, addr);
276 if (flag_debug_asm && comment)
278 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
279 vfprintf (asm_out_file, comment, ap);
281 fputc ('\n', asm_out_file);
283 va_end (ap);
286 /* Output the first ORIG_LEN characters of STR as a string.
287 If ORIG_LEN is equal to -1, ignore this parameter and output
288 the entire STR instead.
289 If COMMENT is not NULL and comments in the debug information
290 have been requested by the user, append the given COMMENT
291 to the generated output. */
293 void
294 dw2_asm_output_nstring (const char *str, size_t orig_len,
295 const char *comment, ...)
297 size_t i, len;
298 va_list ap;
300 va_start (ap, comment);
302 len = orig_len;
304 if (len == (size_t) -1)
305 len = strlen (str);
307 if (flag_debug_asm && comment)
309 fputs ("\t.ascii \"", asm_out_file);
310 for (i = 0; i < len; i++)
312 int c = str[i];
313 if (c == '\"' || c == '\\')
314 fputc ('\\', asm_out_file);
315 if (ISPRINT (c))
316 fputc (c, asm_out_file);
317 else
318 fprintf (asm_out_file, "\\%o", c);
320 fprintf (asm_out_file, "\\0\"\t%s ", ASM_COMMENT_START);
321 vfprintf (asm_out_file, comment, ap);
322 fputc ('\n', asm_out_file);
324 else
326 /* If an explicit length was given, we can't assume there
327 is a null termination in the string buffer. */
328 if (orig_len == (size_t) -1)
329 len += 1;
330 ASM_OUTPUT_ASCII (asm_out_file, str, len);
331 if (orig_len != (size_t) -1)
332 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
335 va_end (ap);
339 /* Return the size of an unsigned LEB128 quantity. */
342 size_of_uleb128 (unsigned HOST_WIDE_INT value)
344 int size = 0;
348 value >>= 7;
349 size += 1;
351 while (value != 0);
353 return size;
356 /* Return the size of a signed LEB128 quantity. */
359 size_of_sleb128 (HOST_WIDE_INT value)
361 int size = 0, byte;
365 byte = (value & 0x7f);
366 value >>= 7;
367 size += 1;
369 while (!((value == 0 && (byte & 0x40) == 0)
370 || (value == -1 && (byte & 0x40) != 0)));
372 return size;
375 /* Given an encoding, return the number of bytes the format occupies.
376 This is only defined for fixed-size encodings, and so does not
377 include leb128. */
380 size_of_encoded_value (int encoding)
382 if (encoding == DW_EH_PE_omit)
383 return 0;
385 switch (encoding & 0x07)
387 case DW_EH_PE_absptr:
388 return POINTER_SIZE_UNITS;
389 case DW_EH_PE_udata2:
390 return 2;
391 case DW_EH_PE_udata4:
392 return 4;
393 case DW_EH_PE_udata8:
394 return 8;
395 default:
396 gcc_unreachable ();
400 /* Yield a name for a given pointer encoding. */
402 const char *
403 eh_data_format_name (int format)
405 #if HAVE_DESIGNATED_INITIALIZERS
406 #define S(p, v) [p] = v,
407 #else
408 #define S(p, v) case p: return v;
409 #endif
411 #if HAVE_DESIGNATED_INITIALIZERS
412 __extension__ static const char * const format_names[256] = {
413 #else
414 switch (format) {
415 #endif
417 S(DW_EH_PE_absptr, "absolute")
418 S(DW_EH_PE_omit, "omit")
419 S(DW_EH_PE_aligned, "aligned absolute")
421 S(DW_EH_PE_uleb128, "uleb128")
422 S(DW_EH_PE_udata2, "udata2")
423 S(DW_EH_PE_udata4, "udata4")
424 S(DW_EH_PE_udata8, "udata8")
425 S(DW_EH_PE_sleb128, "sleb128")
426 S(DW_EH_PE_sdata2, "sdata2")
427 S(DW_EH_PE_sdata4, "sdata4")
428 S(DW_EH_PE_sdata8, "sdata8")
430 S(DW_EH_PE_absptr | DW_EH_PE_pcrel, "pcrel")
431 S(DW_EH_PE_uleb128 | DW_EH_PE_pcrel, "pcrel uleb128")
432 S(DW_EH_PE_udata2 | DW_EH_PE_pcrel, "pcrel udata2")
433 S(DW_EH_PE_udata4 | DW_EH_PE_pcrel, "pcrel udata4")
434 S(DW_EH_PE_udata8 | DW_EH_PE_pcrel, "pcrel udata8")
435 S(DW_EH_PE_sleb128 | DW_EH_PE_pcrel, "pcrel sleb128")
436 S(DW_EH_PE_sdata2 | DW_EH_PE_pcrel, "pcrel sdata2")
437 S(DW_EH_PE_sdata4 | DW_EH_PE_pcrel, "pcrel sdata4")
438 S(DW_EH_PE_sdata8 | DW_EH_PE_pcrel, "pcrel sdata8")
440 S(DW_EH_PE_absptr | DW_EH_PE_textrel, "textrel")
441 S(DW_EH_PE_uleb128 | DW_EH_PE_textrel, "textrel uleb128")
442 S(DW_EH_PE_udata2 | DW_EH_PE_textrel, "textrel udata2")
443 S(DW_EH_PE_udata4 | DW_EH_PE_textrel, "textrel udata4")
444 S(DW_EH_PE_udata8 | DW_EH_PE_textrel, "textrel udata8")
445 S(DW_EH_PE_sleb128 | DW_EH_PE_textrel, "textrel sleb128")
446 S(DW_EH_PE_sdata2 | DW_EH_PE_textrel, "textrel sdata2")
447 S(DW_EH_PE_sdata4 | DW_EH_PE_textrel, "textrel sdata4")
448 S(DW_EH_PE_sdata8 | DW_EH_PE_textrel, "textrel sdata8")
450 S(DW_EH_PE_absptr | DW_EH_PE_datarel, "datarel")
451 S(DW_EH_PE_uleb128 | DW_EH_PE_datarel, "datarel uleb128")
452 S(DW_EH_PE_udata2 | DW_EH_PE_datarel, "datarel udata2")
453 S(DW_EH_PE_udata4 | DW_EH_PE_datarel, "datarel udata4")
454 S(DW_EH_PE_udata8 | DW_EH_PE_datarel, "datarel udata8")
455 S(DW_EH_PE_sleb128 | DW_EH_PE_datarel, "datarel sleb128")
456 S(DW_EH_PE_sdata2 | DW_EH_PE_datarel, "datarel sdata2")
457 S(DW_EH_PE_sdata4 | DW_EH_PE_datarel, "datarel sdata4")
458 S(DW_EH_PE_sdata8 | DW_EH_PE_datarel, "datarel sdata8")
460 S(DW_EH_PE_absptr | DW_EH_PE_funcrel, "funcrel")
461 S(DW_EH_PE_uleb128 | DW_EH_PE_funcrel, "funcrel uleb128")
462 S(DW_EH_PE_udata2 | DW_EH_PE_funcrel, "funcrel udata2")
463 S(DW_EH_PE_udata4 | DW_EH_PE_funcrel, "funcrel udata4")
464 S(DW_EH_PE_udata8 | DW_EH_PE_funcrel, "funcrel udata8")
465 S(DW_EH_PE_sleb128 | DW_EH_PE_funcrel, "funcrel sleb128")
466 S(DW_EH_PE_sdata2 | DW_EH_PE_funcrel, "funcrel sdata2")
467 S(DW_EH_PE_sdata4 | DW_EH_PE_funcrel, "funcrel sdata4")
468 S(DW_EH_PE_sdata8 | DW_EH_PE_funcrel, "funcrel sdata8")
470 S(DW_EH_PE_indirect | DW_EH_PE_absptr, "indirect absolute")
472 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_pcrel,
473 "indirect pcrel")
474 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_pcrel,
475 "indirect pcrel uleb128")
476 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_pcrel,
477 "indirect pcrel udata2")
478 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_pcrel,
479 "indirect pcrel udata4")
480 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_pcrel,
481 "indirect pcrel udata8")
482 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_pcrel,
483 "indirect pcrel sleb128")
484 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_pcrel,
485 "indirect pcrel sdata2")
486 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_pcrel,
487 "indirect pcrel sdata4")
488 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_pcrel,
489 "indirect pcrel sdata8")
491 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_textrel,
492 "indirect textrel")
493 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_textrel,
494 "indirect textrel uleb128")
495 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_textrel,
496 "indirect textrel udata2")
497 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_textrel,
498 "indirect textrel udata4")
499 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_textrel,
500 "indirect textrel udata8")
501 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_textrel,
502 "indirect textrel sleb128")
503 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_textrel,
504 "indirect textrel sdata2")
505 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_textrel,
506 "indirect textrel sdata4")
507 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_textrel,
508 "indirect textrel sdata8")
510 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_datarel,
511 "indirect datarel")
512 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_datarel,
513 "indirect datarel uleb128")
514 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_datarel,
515 "indirect datarel udata2")
516 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_datarel,
517 "indirect datarel udata4")
518 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_datarel,
519 "indirect datarel udata8")
520 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_datarel,
521 "indirect datarel sleb128")
522 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_datarel,
523 "indirect datarel sdata2")
524 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_datarel,
525 "indirect datarel sdata4")
526 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_datarel,
527 "indirect datarel sdata8")
529 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_funcrel,
530 "indirect funcrel")
531 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_funcrel,
532 "indirect funcrel uleb128")
533 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_funcrel,
534 "indirect funcrel udata2")
535 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_funcrel,
536 "indirect funcrel udata4")
537 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_funcrel,
538 "indirect funcrel udata8")
539 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_funcrel,
540 "indirect funcrel sleb128")
541 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_funcrel,
542 "indirect funcrel sdata2")
543 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_funcrel,
544 "indirect funcrel sdata4")
545 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_funcrel,
546 "indirect funcrel sdata8")
548 #if HAVE_DESIGNATED_INITIALIZERS
551 gcc_assert (format >= 0 && format < 0x100 && format_names[format]);
553 return format_names[format];
554 #else
556 gcc_unreachable ();
557 #endif
560 /* Output an unsigned LEB128 quantity, but only the byte values. */
562 void
563 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value)
565 while (1)
567 int byte = (value & 0x7f);
568 value >>= 7;
569 if (value != 0)
570 /* More bytes to follow. */
571 byte |= 0x80;
573 fprintf (asm_out_file, "%#x", byte);
574 if (value == 0)
575 break;
576 fputc (',', asm_out_file);
580 /* Output an unsigned LEB128 quantity. */
582 void
583 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value,
584 const char *comment, ...)
586 va_list ap;
588 va_start (ap, comment);
590 #ifdef HAVE_AS_LEB128
591 fputs ("\t.uleb128 ", asm_out_file);
592 fprint_whex (asm_out_file, value);
594 if (flag_debug_asm && comment)
596 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
597 vfprintf (asm_out_file, comment, ap);
599 #else
601 unsigned HOST_WIDE_INT work = value;
602 const char *byte_op = targetm.asm_out.byte_op;
604 if (byte_op)
605 fputs (byte_op, asm_out_file);
608 int byte = (work & 0x7f);
609 work >>= 7;
610 if (work != 0)
611 /* More bytes to follow. */
612 byte |= 0x80;
614 if (byte_op)
616 fprintf (asm_out_file, "%#x", byte);
617 if (work != 0)
618 fputc (',', asm_out_file);
620 else
621 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
623 while (work != 0);
625 if (flag_debug_asm)
627 fprintf (asm_out_file, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX,
628 ASM_COMMENT_START, value);
629 if (comment)
631 fputs ("; ", asm_out_file);
632 vfprintf (asm_out_file, comment, ap);
636 #endif
637 putc ('\n', asm_out_file);
639 va_end (ap);
642 /* Output an signed LEB128 quantity, but only the byte values. */
644 void
645 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value)
647 int byte, more;
649 while (1)
651 byte = (value & 0x7f);
652 value >>= 7;
653 more = !((value == 0 && (byte & 0x40) == 0)
654 || (value == -1 && (byte & 0x40) != 0));
655 if (more)
656 byte |= 0x80;
658 fprintf (asm_out_file, "%#x", byte);
659 if (!more)
660 break;
661 fputc (',', asm_out_file);
665 /* Output a signed LEB128 quantity. */
667 void
668 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value,
669 const char *comment, ...)
671 va_list ap;
673 va_start (ap, comment);
675 #ifdef HAVE_AS_LEB128
676 fprintf (asm_out_file, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC, value);
678 if (flag_debug_asm && comment)
680 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
681 vfprintf (asm_out_file, comment, ap);
683 #else
685 HOST_WIDE_INT work = value;
686 int more, byte;
687 const char *byte_op = targetm.asm_out.byte_op;
689 if (byte_op)
690 fputs (byte_op, asm_out_file);
693 byte = (work & 0x7f);
694 /* arithmetic shift */
695 work >>= 7;
696 more = !((work == 0 && (byte & 0x40) == 0)
697 || (work == -1 && (byte & 0x40) != 0));
698 if (more)
699 byte |= 0x80;
701 if (byte_op)
703 fprintf (asm_out_file, "%#x", byte);
704 if (more)
705 fputc (',', asm_out_file);
707 else
708 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
710 while (more);
712 if (flag_debug_asm)
714 fprintf (asm_out_file, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC,
715 ASM_COMMENT_START, value);
716 if (comment)
718 fputs ("; ", asm_out_file);
719 vfprintf (asm_out_file, comment, ap);
723 #endif
724 fputc ('\n', asm_out_file);
726 va_end (ap);
729 void
730 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED,
731 const char *lab2 ATTRIBUTE_UNUSED,
732 const char *comment, ...)
734 va_list ap;
736 va_start (ap, comment);
738 #ifdef HAVE_AS_LEB128
739 fputs ("\t.uleb128 ", asm_out_file);
740 assemble_name (asm_out_file, lab1);
741 putc ('-', asm_out_file);
742 assemble_name (asm_out_file, lab2);
743 #else
744 gcc_unreachable ();
745 #endif
747 if (flag_debug_asm && comment)
749 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
750 vfprintf (asm_out_file, comment, ap);
752 fputc ('\n', asm_out_file);
754 va_end (ap);
757 #if 0
759 void
760 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED,
761 const char *lab2 ATTRIBUTE_UNUSED,
762 const char *comment, ...)
764 va_list ap;
766 va_start (ap, comment);
768 #ifdef HAVE_AS_LEB128
769 fputs ("\t.sleb128 ", asm_out_file);
770 assemble_name (asm_out_file, lab1);
771 putc ('-', asm_out_file);
772 assemble_name (asm_out_file, lab2);
773 #else
774 gcc_unreachable ();
775 #endif
777 if (flag_debug_asm && comment)
779 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
780 vfprintf (asm_out_file, comment, ap);
782 fputc ('\n', asm_out_file);
784 va_end (ap);
786 #endif /* 0 */
788 static GTY(()) hash_map<const char *, tree> *indirect_pool;
790 static GTY(()) int dw2_const_labelno;
792 #if defined(HAVE_GAS_HIDDEN)
793 # define USE_LINKONCE_INDIRECT (SUPPORTS_ONE_ONLY)
794 #else
795 # define USE_LINKONCE_INDIRECT 0
796 #endif
798 /* Compare two std::pair<const char *, tree> by their first element.
799 Returns <0, 0, or
800 >0 to indicate whether K1 is less than, equal to, or greater than
801 K2, respectively. */
803 static int
804 compare_strings (const void *a, const void *b)
806 const char *s1 = ((const std::pair<const char *, tree> *) a)->first;
807 const char *s2 = ((const std::pair<const char *, tree> *) b)->first;
808 int ret;
810 if (s1 == s2)
811 return 0;
813 ret = strcmp (s1, s2);
815 /* The strings are always those from IDENTIFIER_NODEs, and,
816 therefore, we should never have two copies of the same
817 string. */
818 gcc_assert (ret);
820 return ret;
823 /* Put X, a SYMBOL_REF, in memory. Return a SYMBOL_REF to the allocated
824 memory. Differs from force_const_mem in that a single pool is used for
825 the entire unit of translation, and the memory is not guaranteed to be
826 "near" the function in any interesting sense. IS_PUBLIC controls whether
827 the symbol can be shared across the entire application (or DSO). */
830 dw2_force_const_mem (rtx x, bool is_public)
832 const char *key;
833 tree decl_id;
835 if (! indirect_pool)
836 indirect_pool = hash_map<const char *, tree>::create_ggc (64);
838 gcc_assert (GET_CODE (x) == SYMBOL_REF);
840 key = XSTR (x, 0);
841 tree *slot = indirect_pool->get (key);
842 if (slot)
843 decl_id = *slot;
844 else
846 tree id;
847 const char *str = targetm.strip_name_encoding (key);
849 if (is_public && USE_LINKONCE_INDIRECT)
851 char *ref_name = XALLOCAVEC (char, strlen (str) + sizeof "DW.ref.");
853 sprintf (ref_name, "DW.ref.%s", str);
854 gcc_assert (!maybe_get_identifier (ref_name));
855 decl_id = get_identifier (ref_name);
856 TREE_PUBLIC (decl_id) = 1;
858 else
860 char label[32];
862 ASM_GENERATE_INTERNAL_LABEL (label, "LDFCM", dw2_const_labelno);
863 ++dw2_const_labelno;
864 gcc_assert (!maybe_get_identifier (label));
865 decl_id = get_identifier (label);
868 id = maybe_get_identifier (str);
869 if (id)
870 TREE_SYMBOL_REFERENCED (id) = 1;
872 indirect_pool->put (key, decl_id);
875 return gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (decl_id));
878 /* A helper function for dw2_output_indirect_constants. Emit one queued
879 constant to memory. */
881 static int
882 dw2_output_indirect_constant_1 (const char *sym, tree id)
884 rtx sym_ref;
885 tree decl;
887 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, ptr_type_node);
888 SET_DECL_ASSEMBLER_NAME (decl, id);
889 DECL_ARTIFICIAL (decl) = 1;
890 DECL_IGNORED_P (decl) = 1;
891 DECL_INITIAL (decl) = decl;
892 TREE_READONLY (decl) = 1;
893 TREE_STATIC (decl) = 1;
895 if (TREE_PUBLIC (id))
897 TREE_PUBLIC (decl) = 1;
898 make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
899 if (USE_LINKONCE_INDIRECT)
900 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
903 sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
904 assemble_variable (decl, 1, 1, 1);
905 assemble_integer (sym_ref, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
907 return 0;
910 /* Emit the constants queued through dw2_force_const_mem. */
912 void
913 dw2_output_indirect_constants (void)
915 if (!indirect_pool)
916 return;
918 auto_vec<std::pair<const char *, tree> > temp (indirect_pool->elements ());
919 for (hash_map<const char *, tree>::iterator iter = indirect_pool->begin ();
920 iter != indirect_pool->end (); ++iter)
921 temp.quick_push (*iter);
923 temp.qsort (compare_strings);
925 for (unsigned int i = 0; i < temp.length (); i++)
926 dw2_output_indirect_constant_1 (temp[i].first, temp[i].second);
929 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
930 If PUBLIC is set and the encoding is DW_EH_PE_indirect, the indirect
931 reference is shared across the entire application (or DSO). */
933 void
934 dw2_asm_output_encoded_addr_rtx (int encoding, rtx addr, bool is_public,
935 const char *comment, ...)
937 int size;
938 va_list ap;
940 va_start (ap, comment);
942 size = size_of_encoded_value (encoding);
944 if (encoding == DW_EH_PE_aligned)
946 assemble_align (POINTER_SIZE);
947 assemble_integer (addr, size, POINTER_SIZE, 1);
948 va_end (ap);
949 return;
952 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
953 "all others". */
954 if (addr == const0_rtx || addr == const1_rtx)
955 assemble_integer (addr, size, BITS_PER_UNIT, 1);
956 else
958 restart:
959 /* Allow the target first crack at emitting this. Some of the
960 special relocations require special directives instead of
961 just ".4byte" or whatever. */
962 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
963 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file, encoding, size,
964 addr, done);
965 #endif
967 /* Indirection is used to get dynamic relocations out of a
968 read-only section. */
969 if (encoding & DW_EH_PE_indirect)
971 /* It is very tempting to use force_const_mem so that we share data
972 with the normal constant pool. However, we've already emitted
973 the constant pool for this function. Moreover, we'd like to
974 share these constants across the entire unit of translation and
975 even, if possible, across the entire application (or DSO). */
976 addr = dw2_force_const_mem (addr, is_public);
977 encoding &= ~DW_EH_PE_indirect;
978 goto restart;
981 switch (encoding & 0xF0)
983 case DW_EH_PE_absptr:
984 dw2_assemble_integer (size, addr);
985 break;
987 #ifdef ASM_OUTPUT_DWARF_DATAREL
988 case DW_EH_PE_datarel:
989 gcc_assert (GET_CODE (addr) == SYMBOL_REF);
990 ASM_OUTPUT_DWARF_DATAREL (asm_out_file, size, XSTR (addr, 0));
991 break;
992 #endif
994 case DW_EH_PE_pcrel:
995 gcc_assert (GET_CODE (addr) == SYMBOL_REF);
996 #ifdef ASM_OUTPUT_DWARF_PCREL
997 ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, XSTR (addr, 0));
998 #else
999 dw2_assemble_integer (size, gen_rtx_MINUS (Pmode, addr, pc_rtx));
1000 #endif
1001 break;
1003 default:
1004 /* Other encodings should have been handled by
1005 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
1006 gcc_unreachable ();
1009 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
1010 done:;
1011 #endif
1014 if (flag_debug_asm && comment)
1016 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1017 vfprintf (asm_out_file, comment, ap);
1019 fputc ('\n', asm_out_file);
1021 va_end (ap);
1024 #include "gt-dwarf2asm.h"