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