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