]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/dwarf2asm.c
alias.c: Reorder #include statements and remove duplicates.
[thirdparty/gcc.git] / gcc / dwarf2asm.c
1 /* Dwarf2 assembler output helper routines.
2 Copyright (C) 2001-2015 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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.
10
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.
15
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/>. */
19
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "target.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "tm_p.h"
28 #include "stringpool.h"
29 #include "flags.h"
30 #include "alias.h"
31 #include "varasm.h"
32 #include "output.h"
33 #include "dwarf2asm.h"
34 #include "dwarf2.h"
35
36 #ifndef XCOFF_DEBUGGING_INFO
37 #define XCOFF_DEBUGGING_INFO 0
38 #endif
39
40 \f
41 /* Output an unaligned integer with the given value and size. Prefer not
42 to print a newline, since the caller may want to add a comment. */
43
44 void
45 dw2_assemble_integer (int size, rtx x)
46 {
47 const char *op = integer_asm_op (size, FALSE);
48
49 if (op)
50 {
51 fputs (op, asm_out_file);
52 if (CONST_INT_P (x))
53 fprint_whex (asm_out_file, (unsigned HOST_WIDE_INT) INTVAL (x));
54 else
55 output_addr_const (asm_out_file, x);
56 }
57 else
58 assemble_integer (x, size, BITS_PER_UNIT, 1);
59 }
60
61
62 /* Output a value of a given size in target byte order. */
63
64 void
65 dw2_asm_output_data_raw (int size, unsigned HOST_WIDE_INT value)
66 {
67 unsigned char bytes[8];
68 int i;
69
70 for (i = 0; i < 8; ++i)
71 {
72 bytes[i] = value & 0xff;
73 value >>= 8;
74 }
75
76 if (BYTES_BIG_ENDIAN)
77 {
78 for (i = size - 1; i > 0; --i)
79 fprintf (asm_out_file, "%#x,", bytes[i]);
80 fprintf (asm_out_file, "%#x", bytes[0]);
81 }
82 else
83 {
84 for (i = 0; i < size - 1; ++i)
85 fprintf (asm_out_file, "%#x,", bytes[i]);
86 fprintf (asm_out_file, "%#x", bytes[i]);
87 }
88 }
89
90 /* Output an immediate constant in a given SIZE in bytes. */
91
92 void
93 dw2_asm_output_data (int size, unsigned HOST_WIDE_INT value,
94 const char *comment, ...)
95 {
96 va_list ap;
97 const char *op = integer_asm_op (size, FALSE);
98
99 va_start (ap, comment);
100
101 if (size * 8 < HOST_BITS_PER_WIDE_INT)
102 value &= ~(~(unsigned HOST_WIDE_INT) 0 << (size * 8));
103
104 if (op)
105 {
106 fputs (op, asm_out_file);
107 fprint_whex (asm_out_file, value);
108 }
109 else
110 assemble_integer (GEN_INT (value), size, BITS_PER_UNIT, 1);
111
112 if (flag_debug_asm && comment)
113 {
114 fputs ("\t" ASM_COMMENT_START " ", asm_out_file);
115 vfprintf (asm_out_file, comment, ap);
116 }
117 putc ('\n', asm_out_file);
118
119 va_end (ap);
120 }
121
122 /* Output the difference between two symbols in a given size. */
123 /* ??? There appear to be assemblers that do not like such
124 subtraction, but do support ASM_SET_OP. It's unfortunately
125 impossible to do here, since the ASM_SET_OP for the difference
126 symbol must appear after both symbols are defined. */
127
128 void
129 dw2_asm_output_delta (int size, const char *lab1, const char *lab2,
130 const char *comment, ...)
131 {
132 va_list ap;
133
134 va_start (ap, comment);
135
136 #ifdef ASM_OUTPUT_DWARF_DELTA
137 ASM_OUTPUT_DWARF_DELTA (asm_out_file, size, lab1, lab2);
138 #else
139 dw2_assemble_integer (size,
140 gen_rtx_MINUS (Pmode,
141 gen_rtx_SYMBOL_REF (Pmode, lab1),
142 gen_rtx_SYMBOL_REF (Pmode, lab2)));
143 #endif
144 if (flag_debug_asm && comment)
145 {
146 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
147 vfprintf (asm_out_file, comment, ap);
148 }
149 fputc ('\n', asm_out_file);
150
151 va_end (ap);
152 }
153
154 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
155 /* Output the difference between two symbols in instruction units
156 in a given size. */
157
158 void
159 dw2_asm_output_vms_delta (int size ATTRIBUTE_UNUSED,
160 const char *lab1, const char *lab2,
161 const char *comment, ...)
162 {
163 va_list ap;
164
165 va_start (ap, comment);
166
167 ASM_OUTPUT_DWARF_VMS_DELTA (asm_out_file, size, lab1, lab2);
168 if (flag_debug_asm && comment)
169 {
170 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
171 vfprintf (asm_out_file, comment, ap);
172 }
173 fputc ('\n', asm_out_file);
174
175 va_end (ap);
176 }
177 #endif
178
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. */
185
186 void
187 dw2_asm_output_offset (int size, const char *label,
188 section *base ATTRIBUTE_UNUSED,
189 const char *comment, ...)
190 {
191 va_list ap;
192
193 va_start (ap, comment);
194
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
200
201 if (flag_debug_asm && comment)
202 {
203 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
204 vfprintf (asm_out_file, comment, ap);
205 }
206 fputc ('\n', asm_out_file);
207
208 va_end (ap);
209 }
210
211 #if 0
212
213 /* Output a self-relative reference to a label, possibly in a
214 different section or object file. */
215
216 void
217 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED,
218 const char *label ATTRIBUTE_UNUSED,
219 const char *comment, ...)
220 {
221 va_list ap;
222
223 va_start (ap, comment);
224
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
233
234 if (flag_debug_asm && comment)
235 {
236 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
237 vfprintf (asm_out_file, comment, ap);
238 }
239 fputc ('\n', asm_out_file);
240
241 va_end (ap);
242 }
243 #endif /* 0 */
244
245 /* Output an absolute reference to a label. */
246
247 void
248 dw2_asm_output_addr (int size, const char *label,
249 const char *comment, ...)
250 {
251 va_list ap;
252
253 va_start (ap, comment);
254
255 dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
256
257 if (flag_debug_asm && comment)
258 {
259 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
260 vfprintf (asm_out_file, comment, ap);
261 }
262 fputc ('\n', asm_out_file);
263
264 va_end (ap);
265 }
266
267 /* Similar, but use an RTX expression instead of a text label. */
268
269 void
270 dw2_asm_output_addr_rtx (int size, rtx addr,
271 const char *comment, ...)
272 {
273 va_list ap;
274
275 va_start (ap, comment);
276
277 dw2_assemble_integer (size, addr);
278
279 if (flag_debug_asm && comment)
280 {
281 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
282 vfprintf (asm_out_file, comment, ap);
283 }
284 fputc ('\n', asm_out_file);
285
286 va_end (ap);
287 }
288
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. */
295
296 void
297 dw2_asm_output_nstring (const char *str, size_t orig_len,
298 const char *comment, ...)
299 {
300 size_t i, len;
301 va_list ap;
302
303 va_start (ap, comment);
304
305 len = orig_len;
306
307 if (len == (size_t) -1)
308 len = strlen (str);
309
310 if (flag_debug_asm && comment)
311 {
312 if (XCOFF_DEBUGGING_INFO)
313 fputs ("\t.byte \"", asm_out_file);
314 else
315 fputs ("\t.ascii \"", asm_out_file);
316
317 for (i = 0; i < len; i++)
318 {
319 int c = str[i];
320 if (c == '\"' || c == '\\')
321 fputc ('\\', asm_out_file);
322 if (ISPRINT (c))
323 fputc (c, asm_out_file);
324 else
325 fprintf (asm_out_file, "\\%o", c);
326 }
327 fprintf (asm_out_file, "\\0\"\t%s ", ASM_COMMENT_START);
328 vfprintf (asm_out_file, comment, ap);
329 fputc ('\n', asm_out_file);
330 }
331 else
332 {
333 /* If an explicit length was given, we can't assume there
334 is a null termination in the string buffer. */
335 if (orig_len == (size_t) -1)
336 len += 1;
337 ASM_OUTPUT_ASCII (asm_out_file, str, len);
338 if (orig_len != (size_t) -1)
339 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
340 }
341
342 va_end (ap);
343 }
344 \f
345
346 /* Return the size of an unsigned LEB128 quantity. */
347
348 int
349 size_of_uleb128 (unsigned HOST_WIDE_INT value)
350 {
351 int size = 0;
352
353 do
354 {
355 value >>= 7;
356 size += 1;
357 }
358 while (value != 0);
359
360 return size;
361 }
362
363 /* Return the size of a signed LEB128 quantity. */
364
365 int
366 size_of_sleb128 (HOST_WIDE_INT value)
367 {
368 int size = 0, byte;
369
370 do
371 {
372 byte = (value & 0x7f);
373 value >>= 7;
374 size += 1;
375 }
376 while (!((value == 0 && (byte & 0x40) == 0)
377 || (value == -1 && (byte & 0x40) != 0)));
378
379 return size;
380 }
381
382 /* Given an encoding, return the number of bytes the format occupies.
383 This is only defined for fixed-size encodings, and so does not
384 include leb128. */
385
386 int
387 size_of_encoded_value (int encoding)
388 {
389 if (encoding == DW_EH_PE_omit)
390 return 0;
391
392 switch (encoding & 0x07)
393 {
394 case DW_EH_PE_absptr:
395 return POINTER_SIZE_UNITS;
396 case DW_EH_PE_udata2:
397 return 2;
398 case DW_EH_PE_udata4:
399 return 4;
400 case DW_EH_PE_udata8:
401 return 8;
402 default:
403 gcc_unreachable ();
404 }
405 }
406
407 /* Yield a name for a given pointer encoding. */
408
409 const char *
410 eh_data_format_name (int format)
411 {
412 #if HAVE_DESIGNATED_INITIALIZERS
413 #define S(p, v) [p] = v,
414 #else
415 #define S(p, v) case p: return v;
416 #endif
417
418 #if HAVE_DESIGNATED_INITIALIZERS
419 __extension__ static const char * const format_names[256] = {
420 #else
421 switch (format) {
422 #endif
423
424 S(DW_EH_PE_absptr, "absolute")
425 S(DW_EH_PE_omit, "omit")
426 S(DW_EH_PE_aligned, "aligned absolute")
427
428 S(DW_EH_PE_uleb128, "uleb128")
429 S(DW_EH_PE_udata2, "udata2")
430 S(DW_EH_PE_udata4, "udata4")
431 S(DW_EH_PE_udata8, "udata8")
432 S(DW_EH_PE_sleb128, "sleb128")
433 S(DW_EH_PE_sdata2, "sdata2")
434 S(DW_EH_PE_sdata4, "sdata4")
435 S(DW_EH_PE_sdata8, "sdata8")
436
437 S(DW_EH_PE_absptr | DW_EH_PE_pcrel, "pcrel")
438 S(DW_EH_PE_uleb128 | DW_EH_PE_pcrel, "pcrel uleb128")
439 S(DW_EH_PE_udata2 | DW_EH_PE_pcrel, "pcrel udata2")
440 S(DW_EH_PE_udata4 | DW_EH_PE_pcrel, "pcrel udata4")
441 S(DW_EH_PE_udata8 | DW_EH_PE_pcrel, "pcrel udata8")
442 S(DW_EH_PE_sleb128 | DW_EH_PE_pcrel, "pcrel sleb128")
443 S(DW_EH_PE_sdata2 | DW_EH_PE_pcrel, "pcrel sdata2")
444 S(DW_EH_PE_sdata4 | DW_EH_PE_pcrel, "pcrel sdata4")
445 S(DW_EH_PE_sdata8 | DW_EH_PE_pcrel, "pcrel sdata8")
446
447 S(DW_EH_PE_absptr | DW_EH_PE_textrel, "textrel")
448 S(DW_EH_PE_uleb128 | DW_EH_PE_textrel, "textrel uleb128")
449 S(DW_EH_PE_udata2 | DW_EH_PE_textrel, "textrel udata2")
450 S(DW_EH_PE_udata4 | DW_EH_PE_textrel, "textrel udata4")
451 S(DW_EH_PE_udata8 | DW_EH_PE_textrel, "textrel udata8")
452 S(DW_EH_PE_sleb128 | DW_EH_PE_textrel, "textrel sleb128")
453 S(DW_EH_PE_sdata2 | DW_EH_PE_textrel, "textrel sdata2")
454 S(DW_EH_PE_sdata4 | DW_EH_PE_textrel, "textrel sdata4")
455 S(DW_EH_PE_sdata8 | DW_EH_PE_textrel, "textrel sdata8")
456
457 S(DW_EH_PE_absptr | DW_EH_PE_datarel, "datarel")
458 S(DW_EH_PE_uleb128 | DW_EH_PE_datarel, "datarel uleb128")
459 S(DW_EH_PE_udata2 | DW_EH_PE_datarel, "datarel udata2")
460 S(DW_EH_PE_udata4 | DW_EH_PE_datarel, "datarel udata4")
461 S(DW_EH_PE_udata8 | DW_EH_PE_datarel, "datarel udata8")
462 S(DW_EH_PE_sleb128 | DW_EH_PE_datarel, "datarel sleb128")
463 S(DW_EH_PE_sdata2 | DW_EH_PE_datarel, "datarel sdata2")
464 S(DW_EH_PE_sdata4 | DW_EH_PE_datarel, "datarel sdata4")
465 S(DW_EH_PE_sdata8 | DW_EH_PE_datarel, "datarel sdata8")
466
467 S(DW_EH_PE_absptr | DW_EH_PE_funcrel, "funcrel")
468 S(DW_EH_PE_uleb128 | DW_EH_PE_funcrel, "funcrel uleb128")
469 S(DW_EH_PE_udata2 | DW_EH_PE_funcrel, "funcrel udata2")
470 S(DW_EH_PE_udata4 | DW_EH_PE_funcrel, "funcrel udata4")
471 S(DW_EH_PE_udata8 | DW_EH_PE_funcrel, "funcrel udata8")
472 S(DW_EH_PE_sleb128 | DW_EH_PE_funcrel, "funcrel sleb128")
473 S(DW_EH_PE_sdata2 | DW_EH_PE_funcrel, "funcrel sdata2")
474 S(DW_EH_PE_sdata4 | DW_EH_PE_funcrel, "funcrel sdata4")
475 S(DW_EH_PE_sdata8 | DW_EH_PE_funcrel, "funcrel sdata8")
476
477 S(DW_EH_PE_indirect | DW_EH_PE_absptr, "indirect absolute")
478
479 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_pcrel,
480 "indirect pcrel")
481 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_pcrel,
482 "indirect pcrel uleb128")
483 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_pcrel,
484 "indirect pcrel udata2")
485 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_pcrel,
486 "indirect pcrel udata4")
487 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_pcrel,
488 "indirect pcrel udata8")
489 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_pcrel,
490 "indirect pcrel sleb128")
491 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_pcrel,
492 "indirect pcrel sdata2")
493 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_pcrel,
494 "indirect pcrel sdata4")
495 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_pcrel,
496 "indirect pcrel sdata8")
497
498 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_textrel,
499 "indirect textrel")
500 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_textrel,
501 "indirect textrel uleb128")
502 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_textrel,
503 "indirect textrel udata2")
504 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_textrel,
505 "indirect textrel udata4")
506 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_textrel,
507 "indirect textrel udata8")
508 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_textrel,
509 "indirect textrel sleb128")
510 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_textrel,
511 "indirect textrel sdata2")
512 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_textrel,
513 "indirect textrel sdata4")
514 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_textrel,
515 "indirect textrel sdata8")
516
517 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_datarel,
518 "indirect datarel")
519 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_datarel,
520 "indirect datarel uleb128")
521 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_datarel,
522 "indirect datarel udata2")
523 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_datarel,
524 "indirect datarel udata4")
525 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_datarel,
526 "indirect datarel udata8")
527 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_datarel,
528 "indirect datarel sleb128")
529 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_datarel,
530 "indirect datarel sdata2")
531 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_datarel,
532 "indirect datarel sdata4")
533 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_datarel,
534 "indirect datarel sdata8")
535
536 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_funcrel,
537 "indirect funcrel")
538 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_funcrel,
539 "indirect funcrel uleb128")
540 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_funcrel,
541 "indirect funcrel udata2")
542 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_funcrel,
543 "indirect funcrel udata4")
544 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_funcrel,
545 "indirect funcrel udata8")
546 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_funcrel,
547 "indirect funcrel sleb128")
548 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_funcrel,
549 "indirect funcrel sdata2")
550 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_funcrel,
551 "indirect funcrel sdata4")
552 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_funcrel,
553 "indirect funcrel sdata8")
554
555 #if HAVE_DESIGNATED_INITIALIZERS
556 };
557
558 gcc_assert (format >= 0 && format < 0x100 && format_names[format]);
559
560 return format_names[format];
561 #else
562 }
563 gcc_unreachable ();
564 #endif
565 }
566
567 /* Output an unsigned LEB128 quantity, but only the byte values. */
568
569 void
570 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value)
571 {
572 while (1)
573 {
574 int byte = (value & 0x7f);
575 value >>= 7;
576 if (value != 0)
577 /* More bytes to follow. */
578 byte |= 0x80;
579
580 fprintf (asm_out_file, "%#x", byte);
581 if (value == 0)
582 break;
583 fputc (',', asm_out_file);
584 }
585 }
586
587 /* Output an unsigned LEB128 quantity. */
588
589 void
590 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value,
591 const char *comment, ...)
592 {
593 va_list ap;
594
595 va_start (ap, comment);
596
597 #ifdef HAVE_AS_LEB128
598 fputs ("\t.uleb128 ", asm_out_file);
599 fprint_whex (asm_out_file, value);
600
601 if (flag_debug_asm && comment)
602 {
603 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
604 vfprintf (asm_out_file, comment, ap);
605 }
606 #else
607 {
608 unsigned HOST_WIDE_INT work = value;
609 const char *byte_op = targetm.asm_out.byte_op;
610
611 if (byte_op)
612 fputs (byte_op, asm_out_file);
613 do
614 {
615 int byte = (work & 0x7f);
616 work >>= 7;
617 if (work != 0)
618 /* More bytes to follow. */
619 byte |= 0x80;
620
621 if (byte_op)
622 {
623 fprintf (asm_out_file, "%#x", byte);
624 if (work != 0)
625 fputc (',', asm_out_file);
626 }
627 else
628 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
629 }
630 while (work != 0);
631
632 if (flag_debug_asm)
633 {
634 fprintf (asm_out_file, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX,
635 ASM_COMMENT_START, value);
636 if (comment)
637 {
638 fputs ("; ", asm_out_file);
639 vfprintf (asm_out_file, comment, ap);
640 }
641 }
642 }
643 #endif
644 putc ('\n', asm_out_file);
645
646 va_end (ap);
647 }
648
649 /* Output an signed LEB128 quantity, but only the byte values. */
650
651 void
652 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value)
653 {
654 int byte, more;
655
656 while (1)
657 {
658 byte = (value & 0x7f);
659 value >>= 7;
660 more = !((value == 0 && (byte & 0x40) == 0)
661 || (value == -1 && (byte & 0x40) != 0));
662 if (more)
663 byte |= 0x80;
664
665 fprintf (asm_out_file, "%#x", byte);
666 if (!more)
667 break;
668 fputc (',', asm_out_file);
669 }
670 }
671
672 /* Output a signed LEB128 quantity. */
673
674 void
675 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value,
676 const char *comment, ...)
677 {
678 va_list ap;
679
680 va_start (ap, comment);
681
682 #ifdef HAVE_AS_LEB128
683 fprintf (asm_out_file, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC, value);
684
685 if (flag_debug_asm && comment)
686 {
687 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
688 vfprintf (asm_out_file, comment, ap);
689 }
690 #else
691 {
692 HOST_WIDE_INT work = value;
693 int more, byte;
694 const char *byte_op = targetm.asm_out.byte_op;
695
696 if (byte_op)
697 fputs (byte_op, asm_out_file);
698 do
699 {
700 byte = (work & 0x7f);
701 /* arithmetic shift */
702 work >>= 7;
703 more = !((work == 0 && (byte & 0x40) == 0)
704 || (work == -1 && (byte & 0x40) != 0));
705 if (more)
706 byte |= 0x80;
707
708 if (byte_op)
709 {
710 fprintf (asm_out_file, "%#x", byte);
711 if (more)
712 fputc (',', asm_out_file);
713 }
714 else
715 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
716 }
717 while (more);
718
719 if (flag_debug_asm)
720 {
721 fprintf (asm_out_file, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC,
722 ASM_COMMENT_START, value);
723 if (comment)
724 {
725 fputs ("; ", asm_out_file);
726 vfprintf (asm_out_file, comment, ap);
727 }
728 }
729 }
730 #endif
731 fputc ('\n', asm_out_file);
732
733 va_end (ap);
734 }
735
736 void
737 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED,
738 const char *lab2 ATTRIBUTE_UNUSED,
739 const char *comment, ...)
740 {
741 va_list ap;
742
743 va_start (ap, comment);
744
745 #ifdef HAVE_AS_LEB128
746 fputs ("\t.uleb128 ", asm_out_file);
747 assemble_name (asm_out_file, lab1);
748 putc ('-', asm_out_file);
749 assemble_name (asm_out_file, lab2);
750 #else
751 gcc_unreachable ();
752 #endif
753
754 if (flag_debug_asm && comment)
755 {
756 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
757 vfprintf (asm_out_file, comment, ap);
758 }
759 fputc ('\n', asm_out_file);
760
761 va_end (ap);
762 }
763
764 #if 0
765
766 void
767 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED,
768 const char *lab2 ATTRIBUTE_UNUSED,
769 const char *comment, ...)
770 {
771 va_list ap;
772
773 va_start (ap, comment);
774
775 #ifdef HAVE_AS_LEB128
776 fputs ("\t.sleb128 ", asm_out_file);
777 assemble_name (asm_out_file, lab1);
778 putc ('-', asm_out_file);
779 assemble_name (asm_out_file, lab2);
780 #else
781 gcc_unreachable ();
782 #endif
783
784 if (flag_debug_asm && comment)
785 {
786 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
787 vfprintf (asm_out_file, comment, ap);
788 }
789 fputc ('\n', asm_out_file);
790
791 va_end (ap);
792 }
793 #endif /* 0 */
794 \f
795 static GTY(()) hash_map<const char *, tree> *indirect_pool;
796
797 static GTY(()) int dw2_const_labelno;
798
799 #if defined(HAVE_GAS_HIDDEN)
800 # define USE_LINKONCE_INDIRECT (SUPPORTS_ONE_ONLY)
801 #else
802 # define USE_LINKONCE_INDIRECT 0
803 #endif
804
805 /* Compare two std::pair<const char *, tree> by their first element.
806 Returns <0, 0, or
807 >0 to indicate whether K1 is less than, equal to, or greater than
808 K2, respectively. */
809
810 static int
811 compare_strings (const void *a, const void *b)
812 {
813 const char *s1 = ((const std::pair<const char *, tree> *) a)->first;
814 const char *s2 = ((const std::pair<const char *, tree> *) b)->first;
815 int ret;
816
817 if (s1 == s2)
818 return 0;
819
820 ret = strcmp (s1, s2);
821
822 /* The strings are always those from IDENTIFIER_NODEs, and,
823 therefore, we should never have two copies of the same
824 string. */
825 gcc_assert (ret);
826
827 return ret;
828 }
829
830 /* Put X, a SYMBOL_REF, in memory. Return a SYMBOL_REF to the allocated
831 memory. Differs from force_const_mem in that a single pool is used for
832 the entire unit of translation, and the memory is not guaranteed to be
833 "near" the function in any interesting sense. IS_PUBLIC controls whether
834 the symbol can be shared across the entire application (or DSO). */
835
836 rtx
837 dw2_force_const_mem (rtx x, bool is_public)
838 {
839 const char *key;
840 tree decl_id;
841
842 if (! indirect_pool)
843 indirect_pool = hash_map<const char *, tree>::create_ggc (64);
844
845 gcc_assert (GET_CODE (x) == SYMBOL_REF);
846
847 key = XSTR (x, 0);
848 tree *slot = indirect_pool->get (key);
849 if (slot)
850 decl_id = *slot;
851 else
852 {
853 tree id;
854 const char *str = targetm.strip_name_encoding (key);
855
856 if (is_public && USE_LINKONCE_INDIRECT)
857 {
858 char *ref_name = XALLOCAVEC (char, strlen (str) + sizeof "DW.ref.");
859
860 sprintf (ref_name, "DW.ref.%s", str);
861 gcc_assert (!maybe_get_identifier (ref_name));
862 decl_id = get_identifier (ref_name);
863 TREE_PUBLIC (decl_id) = 1;
864 }
865 else
866 {
867 char label[32];
868
869 ASM_GENERATE_INTERNAL_LABEL (label, "LDFCM", dw2_const_labelno);
870 ++dw2_const_labelno;
871 gcc_assert (!maybe_get_identifier (label));
872 decl_id = get_identifier (label);
873 }
874
875 id = maybe_get_identifier (str);
876 if (id)
877 TREE_SYMBOL_REFERENCED (id) = 1;
878
879 indirect_pool->put (key, decl_id);
880 }
881
882 return gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (decl_id));
883 }
884
885 /* A helper function for dw2_output_indirect_constants. Emit one queued
886 constant to memory. */
887
888 static int
889 dw2_output_indirect_constant_1 (const char *sym, tree id)
890 {
891 rtx sym_ref;
892 tree decl;
893
894 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, ptr_type_node);
895 SET_DECL_ASSEMBLER_NAME (decl, id);
896 DECL_ARTIFICIAL (decl) = 1;
897 DECL_IGNORED_P (decl) = 1;
898 DECL_INITIAL (decl) = decl;
899 TREE_READONLY (decl) = 1;
900 TREE_STATIC (decl) = 1;
901
902 if (TREE_PUBLIC (id))
903 {
904 TREE_PUBLIC (decl) = 1;
905 make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
906 if (USE_LINKONCE_INDIRECT)
907 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
908 }
909
910 sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
911 assemble_variable (decl, 1, 1, 1);
912 assemble_integer (sym_ref, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
913
914 return 0;
915 }
916
917 /* Emit the constants queued through dw2_force_const_mem. */
918
919 void
920 dw2_output_indirect_constants (void)
921 {
922 if (!indirect_pool)
923 return;
924
925 auto_vec<std::pair<const char *, tree> > temp (indirect_pool->elements ());
926 for (hash_map<const char *, tree>::iterator iter = indirect_pool->begin ();
927 iter != indirect_pool->end (); ++iter)
928 temp.quick_push (*iter);
929
930 temp.qsort (compare_strings);
931
932 for (unsigned int i = 0; i < temp.length (); i++)
933 dw2_output_indirect_constant_1 (temp[i].first, temp[i].second);
934 }
935
936 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
937 If PUBLIC is set and the encoding is DW_EH_PE_indirect, the indirect
938 reference is shared across the entire application (or DSO). */
939
940 void
941 dw2_asm_output_encoded_addr_rtx (int encoding, rtx addr, bool is_public,
942 const char *comment, ...)
943 {
944 int size;
945 va_list ap;
946
947 va_start (ap, comment);
948
949 size = size_of_encoded_value (encoding);
950
951 if (encoding == DW_EH_PE_aligned)
952 {
953 assemble_align (POINTER_SIZE);
954 assemble_integer (addr, size, POINTER_SIZE, 1);
955 va_end (ap);
956 return;
957 }
958
959 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
960 "all others". */
961 if (addr == const0_rtx || addr == const1_rtx)
962 assemble_integer (addr, size, BITS_PER_UNIT, 1);
963 else
964 {
965 restart:
966 /* Allow the target first crack at emitting this. Some of the
967 special relocations require special directives instead of
968 just ".4byte" or whatever. */
969 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
970 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file, encoding, size,
971 addr, done);
972 #endif
973
974 /* Indirection is used to get dynamic relocations out of a
975 read-only section. */
976 if (encoding & DW_EH_PE_indirect)
977 {
978 /* It is very tempting to use force_const_mem so that we share data
979 with the normal constant pool. However, we've already emitted
980 the constant pool for this function. Moreover, we'd like to
981 share these constants across the entire unit of translation and
982 even, if possible, across the entire application (or DSO). */
983 addr = dw2_force_const_mem (addr, is_public);
984 encoding &= ~DW_EH_PE_indirect;
985 goto restart;
986 }
987
988 switch (encoding & 0xF0)
989 {
990 case DW_EH_PE_absptr:
991 dw2_assemble_integer (size, addr);
992 break;
993
994 #ifdef ASM_OUTPUT_DWARF_DATAREL
995 case DW_EH_PE_datarel:
996 gcc_assert (GET_CODE (addr) == SYMBOL_REF);
997 ASM_OUTPUT_DWARF_DATAREL (asm_out_file, size, XSTR (addr, 0));
998 break;
999 #endif
1000
1001 case DW_EH_PE_pcrel:
1002 gcc_assert (GET_CODE (addr) == SYMBOL_REF);
1003 #ifdef ASM_OUTPUT_DWARF_PCREL
1004 ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, XSTR (addr, 0));
1005 #else
1006 dw2_assemble_integer (size, gen_rtx_MINUS (Pmode, addr, pc_rtx));
1007 #endif
1008 break;
1009
1010 default:
1011 /* Other encodings should have been handled by
1012 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
1013 gcc_unreachable ();
1014 }
1015
1016 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
1017 done:;
1018 #endif
1019 }
1020
1021 if (flag_debug_asm && comment)
1022 {
1023 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1024 vfprintf (asm_out_file, comment, ap);
1025 }
1026 fputc ('\n', asm_out_file);
1027
1028 va_end (ap);
1029 }
1030
1031 #include "gt-dwarf2asm.h"