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