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