always define DYNAMIC_CHAIN_ADDRESS
[official-gcc.git] / gcc / dwarf2asm.c
blob53140253f8dc4a9f7262d9b72cc40fcad5b8593f
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"
37 #ifndef XCOFF_DEBUGGING_INFO
38 #define XCOFF_DEBUGGING_INFO 0
39 #endif
42 /* Output an unaligned integer with the given value and size. Prefer not
43 to print a newline, since the caller may want to add a comment. */
45 void
46 dw2_assemble_integer (int size, rtx x)
48 const char *op = integer_asm_op (size, FALSE);
50 if (op)
52 fputs (op, asm_out_file);
53 if (CONST_INT_P (x))
54 fprint_whex (asm_out_file, (unsigned HOST_WIDE_INT) INTVAL (x));
55 else
56 output_addr_const (asm_out_file, x);
58 else
59 assemble_integer (x, size, BITS_PER_UNIT, 1);
63 /* Output a value of a given size in target byte order. */
65 void
66 dw2_asm_output_data_raw (int size, unsigned HOST_WIDE_INT value)
68 unsigned char bytes[8];
69 int i;
71 for (i = 0; i < 8; ++i)
73 bytes[i] = value & 0xff;
74 value >>= 8;
77 if (BYTES_BIG_ENDIAN)
79 for (i = size - 1; i > 0; --i)
80 fprintf (asm_out_file, "%#x,", bytes[i]);
81 fprintf (asm_out_file, "%#x", bytes[0]);
83 else
85 for (i = 0; i < size - 1; ++i)
86 fprintf (asm_out_file, "%#x,", bytes[i]);
87 fprintf (asm_out_file, "%#x", bytes[i]);
91 /* Output an immediate constant in a given SIZE in bytes. */
93 void
94 dw2_asm_output_data (int size, unsigned HOST_WIDE_INT value,
95 const char *comment, ...)
97 va_list ap;
98 const char *op = integer_asm_op (size, FALSE);
100 va_start (ap, comment);
102 if (size * 8 < HOST_BITS_PER_WIDE_INT)
103 value &= ~(~(unsigned HOST_WIDE_INT) 0 << (size * 8));
105 if (op)
107 fputs (op, asm_out_file);
108 fprint_whex (asm_out_file, value);
110 else
111 assemble_integer (GEN_INT (value), size, BITS_PER_UNIT, 1);
113 if (flag_debug_asm && comment)
115 fputs ("\t" ASM_COMMENT_START " ", asm_out_file);
116 vfprintf (asm_out_file, comment, ap);
118 putc ('\n', asm_out_file);
120 va_end (ap);
123 /* Output the difference between two symbols in a given size. */
124 /* ??? There appear to be assemblers that do not like such
125 subtraction, but do support ASM_SET_OP. It's unfortunately
126 impossible to do here, since the ASM_SET_OP for the difference
127 symbol must appear after both symbols are defined. */
129 void
130 dw2_asm_output_delta (int size, const char *lab1, const char *lab2,
131 const char *comment, ...)
133 va_list ap;
135 va_start (ap, comment);
137 #ifdef ASM_OUTPUT_DWARF_DELTA
138 ASM_OUTPUT_DWARF_DELTA (asm_out_file, size, lab1, lab2);
139 #else
140 dw2_assemble_integer (size,
141 gen_rtx_MINUS (Pmode,
142 gen_rtx_SYMBOL_REF (Pmode, lab1),
143 gen_rtx_SYMBOL_REF (Pmode, lab2)));
144 #endif
145 if (flag_debug_asm && comment)
147 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
148 vfprintf (asm_out_file, comment, ap);
150 fputc ('\n', asm_out_file);
152 va_end (ap);
155 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
156 /* Output the difference between two symbols in instruction units
157 in a given size. */
159 void
160 dw2_asm_output_vms_delta (int size ATTRIBUTE_UNUSED,
161 const char *lab1, const char *lab2,
162 const char *comment, ...)
164 va_list ap;
166 va_start (ap, comment);
168 ASM_OUTPUT_DWARF_VMS_DELTA (asm_out_file, size, lab1, lab2);
169 if (flag_debug_asm && comment)
171 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
172 vfprintf (asm_out_file, comment, ap);
174 fputc ('\n', asm_out_file);
176 va_end (ap);
178 #endif
180 /* Output a section-relative reference to a LABEL, which was placed in
181 BASE. In general this can only be done for debugging symbols.
182 E.g. on most targets with the GNU linker, this is accomplished with
183 a direct reference and the knowledge that the debugging section
184 will be placed at VMA 0. Some targets have special relocations for
185 this that we must use. */
187 void
188 dw2_asm_output_offset (int size, const char *label,
189 section *base ATTRIBUTE_UNUSED,
190 const char *comment, ...)
192 va_list ap;
194 va_start (ap, comment);
196 #ifdef ASM_OUTPUT_DWARF_OFFSET
197 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label, base);
198 #else
199 dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
200 #endif
202 if (flag_debug_asm && comment)
204 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
205 vfprintf (asm_out_file, comment, ap);
207 fputc ('\n', asm_out_file);
209 va_end (ap);
212 #if 0
214 /* Output a self-relative reference to a label, possibly in a
215 different section or object file. */
217 void
218 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED,
219 const char *label ATTRIBUTE_UNUSED,
220 const char *comment, ...)
222 va_list ap;
224 va_start (ap, comment);
226 #ifdef ASM_OUTPUT_DWARF_PCREL
227 ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, label);
228 #else
229 dw2_assemble_integer (size,
230 gen_rtx_MINUS (Pmode,
231 gen_rtx_SYMBOL_REF (Pmode, label),
232 pc_rtx));
233 #endif
235 if (flag_debug_asm && comment)
237 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
238 vfprintf (asm_out_file, comment, ap);
240 fputc ('\n', asm_out_file);
242 va_end (ap);
244 #endif /* 0 */
246 /* Output an absolute reference to a label. */
248 void
249 dw2_asm_output_addr (int size, const char *label,
250 const char *comment, ...)
252 va_list ap;
254 va_start (ap, comment);
256 dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
258 if (flag_debug_asm && comment)
260 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
261 vfprintf (asm_out_file, comment, ap);
263 fputc ('\n', asm_out_file);
265 va_end (ap);
268 /* Similar, but use an RTX expression instead of a text label. */
270 void
271 dw2_asm_output_addr_rtx (int size, rtx addr,
272 const char *comment, ...)
274 va_list ap;
276 va_start (ap, comment);
278 dw2_assemble_integer (size, addr);
280 if (flag_debug_asm && comment)
282 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
283 vfprintf (asm_out_file, comment, ap);
285 fputc ('\n', asm_out_file);
287 va_end (ap);
290 /* Output the first ORIG_LEN characters of STR as a string.
291 If ORIG_LEN is equal to -1, ignore this parameter and output
292 the entire STR instead.
293 If COMMENT is not NULL and comments in the debug information
294 have been requested by the user, append the given COMMENT
295 to the generated output. */
297 void
298 dw2_asm_output_nstring (const char *str, size_t orig_len,
299 const char *comment, ...)
301 size_t i, len;
302 va_list ap;
304 va_start (ap, comment);
306 len = orig_len;
308 if (len == (size_t) -1)
309 len = strlen (str);
311 if (flag_debug_asm && comment)
313 if (XCOFF_DEBUGGING_INFO)
314 fputs ("\t.byte \"", asm_out_file);
315 else
316 fputs ("\t.ascii \"", asm_out_file);
318 for (i = 0; i < len; i++)
320 int c = str[i];
321 if (c == '\"' || c == '\\')
322 fputc ('\\', asm_out_file);
323 if (ISPRINT (c))
324 fputc (c, asm_out_file);
325 else
326 fprintf (asm_out_file, "\\%o", c);
328 fprintf (asm_out_file, "\\0\"\t%s ", ASM_COMMENT_START);
329 vfprintf (asm_out_file, comment, ap);
330 fputc ('\n', asm_out_file);
332 else
334 /* If an explicit length was given, we can't assume there
335 is a null termination in the string buffer. */
336 if (orig_len == (size_t) -1)
337 len += 1;
338 ASM_OUTPUT_ASCII (asm_out_file, str, len);
339 if (orig_len != (size_t) -1)
340 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
343 va_end (ap);
347 /* Return the size of an unsigned LEB128 quantity. */
350 size_of_uleb128 (unsigned HOST_WIDE_INT value)
352 int size = 0;
356 value >>= 7;
357 size += 1;
359 while (value != 0);
361 return size;
364 /* Return the size of a signed LEB128 quantity. */
367 size_of_sleb128 (HOST_WIDE_INT value)
369 int size = 0, byte;
373 byte = (value & 0x7f);
374 value >>= 7;
375 size += 1;
377 while (!((value == 0 && (byte & 0x40) == 0)
378 || (value == -1 && (byte & 0x40) != 0)));
380 return size;
383 /* Given an encoding, return the number of bytes the format occupies.
384 This is only defined for fixed-size encodings, and so does not
385 include leb128. */
388 size_of_encoded_value (int encoding)
390 if (encoding == DW_EH_PE_omit)
391 return 0;
393 switch (encoding & 0x07)
395 case DW_EH_PE_absptr:
396 return POINTER_SIZE_UNITS;
397 case DW_EH_PE_udata2:
398 return 2;
399 case DW_EH_PE_udata4:
400 return 4;
401 case DW_EH_PE_udata8:
402 return 8;
403 default:
404 gcc_unreachable ();
408 /* Yield a name for a given pointer encoding. */
410 const char *
411 eh_data_format_name (int format)
413 #if HAVE_DESIGNATED_INITIALIZERS
414 #define S(p, v) [p] = v,
415 #else
416 #define S(p, v) case p: return v;
417 #endif
419 #if HAVE_DESIGNATED_INITIALIZERS
420 __extension__ static const char * const format_names[256] = {
421 #else
422 switch (format) {
423 #endif
425 S(DW_EH_PE_absptr, "absolute")
426 S(DW_EH_PE_omit, "omit")
427 S(DW_EH_PE_aligned, "aligned absolute")
429 S(DW_EH_PE_uleb128, "uleb128")
430 S(DW_EH_PE_udata2, "udata2")
431 S(DW_EH_PE_udata4, "udata4")
432 S(DW_EH_PE_udata8, "udata8")
433 S(DW_EH_PE_sleb128, "sleb128")
434 S(DW_EH_PE_sdata2, "sdata2")
435 S(DW_EH_PE_sdata4, "sdata4")
436 S(DW_EH_PE_sdata8, "sdata8")
438 S(DW_EH_PE_absptr | DW_EH_PE_pcrel, "pcrel")
439 S(DW_EH_PE_uleb128 | DW_EH_PE_pcrel, "pcrel uleb128")
440 S(DW_EH_PE_udata2 | DW_EH_PE_pcrel, "pcrel udata2")
441 S(DW_EH_PE_udata4 | DW_EH_PE_pcrel, "pcrel udata4")
442 S(DW_EH_PE_udata8 | DW_EH_PE_pcrel, "pcrel udata8")
443 S(DW_EH_PE_sleb128 | DW_EH_PE_pcrel, "pcrel sleb128")
444 S(DW_EH_PE_sdata2 | DW_EH_PE_pcrel, "pcrel sdata2")
445 S(DW_EH_PE_sdata4 | DW_EH_PE_pcrel, "pcrel sdata4")
446 S(DW_EH_PE_sdata8 | DW_EH_PE_pcrel, "pcrel sdata8")
448 S(DW_EH_PE_absptr | DW_EH_PE_textrel, "textrel")
449 S(DW_EH_PE_uleb128 | DW_EH_PE_textrel, "textrel uleb128")
450 S(DW_EH_PE_udata2 | DW_EH_PE_textrel, "textrel udata2")
451 S(DW_EH_PE_udata4 | DW_EH_PE_textrel, "textrel udata4")
452 S(DW_EH_PE_udata8 | DW_EH_PE_textrel, "textrel udata8")
453 S(DW_EH_PE_sleb128 | DW_EH_PE_textrel, "textrel sleb128")
454 S(DW_EH_PE_sdata2 | DW_EH_PE_textrel, "textrel sdata2")
455 S(DW_EH_PE_sdata4 | DW_EH_PE_textrel, "textrel sdata4")
456 S(DW_EH_PE_sdata8 | DW_EH_PE_textrel, "textrel sdata8")
458 S(DW_EH_PE_absptr | DW_EH_PE_datarel, "datarel")
459 S(DW_EH_PE_uleb128 | DW_EH_PE_datarel, "datarel uleb128")
460 S(DW_EH_PE_udata2 | DW_EH_PE_datarel, "datarel udata2")
461 S(DW_EH_PE_udata4 | DW_EH_PE_datarel, "datarel udata4")
462 S(DW_EH_PE_udata8 | DW_EH_PE_datarel, "datarel udata8")
463 S(DW_EH_PE_sleb128 | DW_EH_PE_datarel, "datarel sleb128")
464 S(DW_EH_PE_sdata2 | DW_EH_PE_datarel, "datarel sdata2")
465 S(DW_EH_PE_sdata4 | DW_EH_PE_datarel, "datarel sdata4")
466 S(DW_EH_PE_sdata8 | DW_EH_PE_datarel, "datarel sdata8")
468 S(DW_EH_PE_absptr | DW_EH_PE_funcrel, "funcrel")
469 S(DW_EH_PE_uleb128 | DW_EH_PE_funcrel, "funcrel uleb128")
470 S(DW_EH_PE_udata2 | DW_EH_PE_funcrel, "funcrel udata2")
471 S(DW_EH_PE_udata4 | DW_EH_PE_funcrel, "funcrel udata4")
472 S(DW_EH_PE_udata8 | DW_EH_PE_funcrel, "funcrel udata8")
473 S(DW_EH_PE_sleb128 | DW_EH_PE_funcrel, "funcrel sleb128")
474 S(DW_EH_PE_sdata2 | DW_EH_PE_funcrel, "funcrel sdata2")
475 S(DW_EH_PE_sdata4 | DW_EH_PE_funcrel, "funcrel sdata4")
476 S(DW_EH_PE_sdata8 | DW_EH_PE_funcrel, "funcrel sdata8")
478 S(DW_EH_PE_indirect | DW_EH_PE_absptr, "indirect absolute")
480 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_pcrel,
481 "indirect pcrel")
482 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_pcrel,
483 "indirect pcrel uleb128")
484 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_pcrel,
485 "indirect pcrel udata2")
486 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_pcrel,
487 "indirect pcrel udata4")
488 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_pcrel,
489 "indirect pcrel udata8")
490 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_pcrel,
491 "indirect pcrel sleb128")
492 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_pcrel,
493 "indirect pcrel sdata2")
494 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_pcrel,
495 "indirect pcrel sdata4")
496 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_pcrel,
497 "indirect pcrel sdata8")
499 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_textrel,
500 "indirect textrel")
501 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_textrel,
502 "indirect textrel uleb128")
503 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_textrel,
504 "indirect textrel udata2")
505 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_textrel,
506 "indirect textrel udata4")
507 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_textrel,
508 "indirect textrel udata8")
509 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_textrel,
510 "indirect textrel sleb128")
511 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_textrel,
512 "indirect textrel sdata2")
513 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_textrel,
514 "indirect textrel sdata4")
515 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_textrel,
516 "indirect textrel sdata8")
518 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_datarel,
519 "indirect datarel")
520 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_datarel,
521 "indirect datarel uleb128")
522 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_datarel,
523 "indirect datarel udata2")
524 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_datarel,
525 "indirect datarel udata4")
526 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_datarel,
527 "indirect datarel udata8")
528 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_datarel,
529 "indirect datarel sleb128")
530 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_datarel,
531 "indirect datarel sdata2")
532 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_datarel,
533 "indirect datarel sdata4")
534 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_datarel,
535 "indirect datarel sdata8")
537 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_funcrel,
538 "indirect funcrel")
539 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_funcrel,
540 "indirect funcrel uleb128")
541 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_funcrel,
542 "indirect funcrel udata2")
543 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_funcrel,
544 "indirect funcrel udata4")
545 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_funcrel,
546 "indirect funcrel udata8")
547 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_funcrel,
548 "indirect funcrel sleb128")
549 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_funcrel,
550 "indirect funcrel sdata2")
551 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_funcrel,
552 "indirect funcrel sdata4")
553 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_funcrel,
554 "indirect funcrel sdata8")
556 #if HAVE_DESIGNATED_INITIALIZERS
559 gcc_assert (format >= 0 && format < 0x100 && format_names[format]);
561 return format_names[format];
562 #else
564 gcc_unreachable ();
565 #endif
568 /* Output an unsigned LEB128 quantity, but only the byte values. */
570 void
571 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value)
573 while (1)
575 int byte = (value & 0x7f);
576 value >>= 7;
577 if (value != 0)
578 /* More bytes to follow. */
579 byte |= 0x80;
581 fprintf (asm_out_file, "%#x", byte);
582 if (value == 0)
583 break;
584 fputc (',', asm_out_file);
588 /* Output an unsigned LEB128 quantity. */
590 void
591 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value,
592 const char *comment, ...)
594 va_list ap;
596 va_start (ap, comment);
598 #ifdef HAVE_AS_LEB128
599 fputs ("\t.uleb128 ", asm_out_file);
600 fprint_whex (asm_out_file, value);
602 if (flag_debug_asm && comment)
604 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
605 vfprintf (asm_out_file, comment, ap);
607 #else
609 unsigned HOST_WIDE_INT work = value;
610 const char *byte_op = targetm.asm_out.byte_op;
612 if (byte_op)
613 fputs (byte_op, asm_out_file);
616 int byte = (work & 0x7f);
617 work >>= 7;
618 if (work != 0)
619 /* More bytes to follow. */
620 byte |= 0x80;
622 if (byte_op)
624 fprintf (asm_out_file, "%#x", byte);
625 if (work != 0)
626 fputc (',', asm_out_file);
628 else
629 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
631 while (work != 0);
633 if (flag_debug_asm)
635 fprintf (asm_out_file, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX,
636 ASM_COMMENT_START, value);
637 if (comment)
639 fputs ("; ", asm_out_file);
640 vfprintf (asm_out_file, comment, ap);
644 #endif
645 putc ('\n', asm_out_file);
647 va_end (ap);
650 /* Output an signed LEB128 quantity, but only the byte values. */
652 void
653 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value)
655 int byte, more;
657 while (1)
659 byte = (value & 0x7f);
660 value >>= 7;
661 more = !((value == 0 && (byte & 0x40) == 0)
662 || (value == -1 && (byte & 0x40) != 0));
663 if (more)
664 byte |= 0x80;
666 fprintf (asm_out_file, "%#x", byte);
667 if (!more)
668 break;
669 fputc (',', asm_out_file);
673 /* Output a signed LEB128 quantity. */
675 void
676 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value,
677 const char *comment, ...)
679 va_list ap;
681 va_start (ap, comment);
683 #ifdef HAVE_AS_LEB128
684 fprintf (asm_out_file, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC, value);
686 if (flag_debug_asm && comment)
688 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
689 vfprintf (asm_out_file, comment, ap);
691 #else
693 HOST_WIDE_INT work = value;
694 int more, byte;
695 const char *byte_op = targetm.asm_out.byte_op;
697 if (byte_op)
698 fputs (byte_op, asm_out_file);
701 byte = (work & 0x7f);
702 /* arithmetic shift */
703 work >>= 7;
704 more = !((work == 0 && (byte & 0x40) == 0)
705 || (work == -1 && (byte & 0x40) != 0));
706 if (more)
707 byte |= 0x80;
709 if (byte_op)
711 fprintf (asm_out_file, "%#x", byte);
712 if (more)
713 fputc (',', asm_out_file);
715 else
716 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
718 while (more);
720 if (flag_debug_asm)
722 fprintf (asm_out_file, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC,
723 ASM_COMMENT_START, value);
724 if (comment)
726 fputs ("; ", asm_out_file);
727 vfprintf (asm_out_file, comment, ap);
731 #endif
732 fputc ('\n', asm_out_file);
734 va_end (ap);
737 void
738 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED,
739 const char *lab2 ATTRIBUTE_UNUSED,
740 const char *comment, ...)
742 va_list ap;
744 va_start (ap, comment);
746 #ifdef HAVE_AS_LEB128
747 fputs ("\t.uleb128 ", asm_out_file);
748 assemble_name (asm_out_file, lab1);
749 putc ('-', asm_out_file);
750 assemble_name (asm_out_file, lab2);
751 #else
752 gcc_unreachable ();
753 #endif
755 if (flag_debug_asm && comment)
757 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
758 vfprintf (asm_out_file, comment, ap);
760 fputc ('\n', asm_out_file);
762 va_end (ap);
765 #if 0
767 void
768 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED,
769 const char *lab2 ATTRIBUTE_UNUSED,
770 const char *comment, ...)
772 va_list ap;
774 va_start (ap, comment);
776 #ifdef HAVE_AS_LEB128
777 fputs ("\t.sleb128 ", asm_out_file);
778 assemble_name (asm_out_file, lab1);
779 putc ('-', asm_out_file);
780 assemble_name (asm_out_file, lab2);
781 #else
782 gcc_unreachable ();
783 #endif
785 if (flag_debug_asm && comment)
787 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
788 vfprintf (asm_out_file, comment, ap);
790 fputc ('\n', asm_out_file);
792 va_end (ap);
794 #endif /* 0 */
796 static GTY(()) hash_map<const char *, tree> *indirect_pool;
798 static GTY(()) int dw2_const_labelno;
800 #if defined(HAVE_GAS_HIDDEN)
801 # define USE_LINKONCE_INDIRECT (SUPPORTS_ONE_ONLY)
802 #else
803 # define USE_LINKONCE_INDIRECT 0
804 #endif
806 /* Compare two std::pair<const char *, tree> by their first element.
807 Returns <0, 0, or
808 >0 to indicate whether K1 is less than, equal to, or greater than
809 K2, respectively. */
811 static int
812 compare_strings (const void *a, const void *b)
814 const char *s1 = ((const std::pair<const char *, tree> *) a)->first;
815 const char *s2 = ((const std::pair<const char *, tree> *) b)->first;
816 int ret;
818 if (s1 == s2)
819 return 0;
821 ret = strcmp (s1, s2);
823 /* The strings are always those from IDENTIFIER_NODEs, and,
824 therefore, we should never have two copies of the same
825 string. */
826 gcc_assert (ret);
828 return ret;
831 /* Put X, a SYMBOL_REF, in memory. Return a SYMBOL_REF to the allocated
832 memory. Differs from force_const_mem in that a single pool is used for
833 the entire unit of translation, and the memory is not guaranteed to be
834 "near" the function in any interesting sense. IS_PUBLIC controls whether
835 the symbol can be shared across the entire application (or DSO). */
838 dw2_force_const_mem (rtx x, bool is_public)
840 const char *key;
841 tree decl_id;
843 if (! indirect_pool)
844 indirect_pool = hash_map<const char *, tree>::create_ggc (64);
846 gcc_assert (GET_CODE (x) == SYMBOL_REF);
848 key = XSTR (x, 0);
849 tree *slot = indirect_pool->get (key);
850 if (slot)
851 decl_id = *slot;
852 else
854 tree id;
855 const char *str = targetm.strip_name_encoding (key);
857 if (is_public && USE_LINKONCE_INDIRECT)
859 char *ref_name = XALLOCAVEC (char, strlen (str) + sizeof "DW.ref.");
861 sprintf (ref_name, "DW.ref.%s", str);
862 gcc_assert (!maybe_get_identifier (ref_name));
863 decl_id = get_identifier (ref_name);
864 TREE_PUBLIC (decl_id) = 1;
866 else
868 char label[32];
870 ASM_GENERATE_INTERNAL_LABEL (label, "LDFCM", dw2_const_labelno);
871 ++dw2_const_labelno;
872 gcc_assert (!maybe_get_identifier (label));
873 decl_id = get_identifier (label);
876 id = maybe_get_identifier (str);
877 if (id)
878 TREE_SYMBOL_REFERENCED (id) = 1;
880 indirect_pool->put (key, decl_id);
883 return gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (decl_id));
886 /* A helper function for dw2_output_indirect_constants. Emit one queued
887 constant to memory. */
889 static int
890 dw2_output_indirect_constant_1 (const char *sym, tree id)
892 rtx sym_ref;
893 tree decl;
895 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, ptr_type_node);
896 SET_DECL_ASSEMBLER_NAME (decl, id);
897 DECL_ARTIFICIAL (decl) = 1;
898 DECL_IGNORED_P (decl) = 1;
899 DECL_INITIAL (decl) = decl;
900 TREE_READONLY (decl) = 1;
901 TREE_STATIC (decl) = 1;
903 if (TREE_PUBLIC (id))
905 TREE_PUBLIC (decl) = 1;
906 make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
907 if (USE_LINKONCE_INDIRECT)
908 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
911 sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
912 assemble_variable (decl, 1, 1, 1);
913 assemble_integer (sym_ref, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
915 return 0;
918 /* Emit the constants queued through dw2_force_const_mem. */
920 void
921 dw2_output_indirect_constants (void)
923 if (!indirect_pool)
924 return;
926 auto_vec<std::pair<const char *, tree> > temp (indirect_pool->elements ());
927 for (hash_map<const char *, tree>::iterator iter = indirect_pool->begin ();
928 iter != indirect_pool->end (); ++iter)
929 temp.quick_push (*iter);
931 temp.qsort (compare_strings);
933 for (unsigned int i = 0; i < temp.length (); i++)
934 dw2_output_indirect_constant_1 (temp[i].first, temp[i].second);
937 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
938 If PUBLIC is set and the encoding is DW_EH_PE_indirect, the indirect
939 reference is shared across the entire application (or DSO). */
941 void
942 dw2_asm_output_encoded_addr_rtx (int encoding, rtx addr, bool is_public,
943 const char *comment, ...)
945 int size;
946 va_list ap;
948 va_start (ap, comment);
950 size = size_of_encoded_value (encoding);
952 if (encoding == DW_EH_PE_aligned)
954 assemble_align (POINTER_SIZE);
955 assemble_integer (addr, size, POINTER_SIZE, 1);
956 va_end (ap);
957 return;
960 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
961 "all others". */
962 if (addr == const0_rtx || addr == const1_rtx)
963 assemble_integer (addr, size, BITS_PER_UNIT, 1);
964 else
966 restart:
967 /* Allow the target first crack at emitting this. Some of the
968 special relocations require special directives instead of
969 just ".4byte" or whatever. */
970 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
971 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file, encoding, size,
972 addr, done);
973 #endif
975 /* Indirection is used to get dynamic relocations out of a
976 read-only section. */
977 if (encoding & DW_EH_PE_indirect)
979 /* It is very tempting to use force_const_mem so that we share data
980 with the normal constant pool. However, we've already emitted
981 the constant pool for this function. Moreover, we'd like to
982 share these constants across the entire unit of translation and
983 even, if possible, across the entire application (or DSO). */
984 addr = dw2_force_const_mem (addr, is_public);
985 encoding &= ~DW_EH_PE_indirect;
986 goto restart;
989 switch (encoding & 0xF0)
991 case DW_EH_PE_absptr:
992 dw2_assemble_integer (size, addr);
993 break;
995 #ifdef ASM_OUTPUT_DWARF_DATAREL
996 case DW_EH_PE_datarel:
997 gcc_assert (GET_CODE (addr) == SYMBOL_REF);
998 ASM_OUTPUT_DWARF_DATAREL (asm_out_file, size, XSTR (addr, 0));
999 break;
1000 #endif
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"