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