OSDN Git Service

* dwarf2asm.c (dw2_output_indirect_constant_1): Take user_label_prefix
[pf3gnuchains/gcc-fork.git] / gcc / dwarf2asm.c
1 /* Dwarf2 assembler output helper routines.
2    Copyright (C) 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.  */
20
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "flags.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "output.h"
30 #include "target.h"
31 #include "dwarf2asm.h"
32 #include "dwarf2.h"
33 #include "splay-tree.h"
34 #include "ggc.h"
35 #include "tm_p.h"
36
37
38 /* How to start an assembler comment.  */
39 #ifndef ASM_COMMENT_START
40 #define ASM_COMMENT_START ";#"
41 #endif
42
43 \f
44 /* Output an unaligned integer with the given value and size.  Prefer not
45    to print a newline, since the caller may want to add a comment.  */
46
47 void
48 dw2_assemble_integer (int size, rtx x)
49 {
50   const char *op = integer_asm_op (size, FALSE);
51
52   if (op)
53     {
54       fputs (op, asm_out_file);
55       if (GET_CODE (x) == CONST_INT)
56         fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX, INTVAL (x));
57       else
58         output_addr_const (asm_out_file, x);
59     }
60   else
61     assemble_integer (x, size, BITS_PER_UNIT, 1);
62 }
63
64
65 /* Output an immediate constant in a given size.  */
66
67 void
68 dw2_asm_output_data (int size, unsigned HOST_WIDE_INT value,
69                      const char *comment, ...)
70 {
71   va_list ap;
72
73   va_start (ap, comment);
74
75   if (size * 8 < HOST_BITS_PER_WIDE_INT)
76     value &= ~(~(unsigned HOST_WIDE_INT) 0 << (size * 8));
77
78   dw2_assemble_integer (size, GEN_INT (value));
79
80   if (flag_debug_asm && comment)
81     {
82       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
83       vfprintf (asm_out_file, comment, ap);
84     }
85   fputc ('\n', asm_out_file);
86
87   va_end (ap);
88 }
89
90 /* Output the difference between two symbols in a given size.  */
91 /* ??? There appear to be assemblers that do not like such
92    subtraction, but do support ASM_SET_OP.  It's unfortunately
93    impossible to do here, since the ASM_SET_OP for the difference
94    symbol must appear after both symbols are defined.  */
95
96 void
97 dw2_asm_output_delta (int size, const char *lab1, const char *lab2,
98                       const char *comment, ...)
99 {
100   va_list ap;
101
102   va_start (ap, comment);
103
104 #ifdef ASM_OUTPUT_DWARF_DELTA
105   ASM_OUTPUT_DWARF_DELTA (asm_out_file, size, lab1, lab2);
106 #else
107   dw2_assemble_integer (size,
108                         gen_rtx_MINUS (Pmode,
109                                        gen_rtx_SYMBOL_REF (Pmode, lab1),
110                                        gen_rtx_SYMBOL_REF (Pmode, lab2)));
111 #endif
112   if (flag_debug_asm && comment)
113     {
114       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
115       vfprintf (asm_out_file, comment, ap);
116     }
117   fputc ('\n', asm_out_file);
118
119   va_end (ap);
120 }
121
122 /* Output a section-relative reference to a label.  In general this
123    can only be done for debugging symbols.  E.g. on most targets with
124    the GNU linker, this is accomplished with a direct reference and
125    the knowledge that the debugging section will be placed at VMA 0.
126    Some targets have special relocations for this that we must use.  */
127
128 void
129 dw2_asm_output_offset (int size, const char *label,
130                        const char *comment, ...)
131 {
132   va_list ap;
133
134   va_start (ap, comment);
135
136 #ifdef ASM_OUTPUT_DWARF_OFFSET
137   ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label);
138 #else
139   dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
140 #endif
141
142   if (flag_debug_asm && comment)
143     {
144       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
145       vfprintf (asm_out_file, comment, ap);
146     }
147   fputc ('\n', asm_out_file);
148
149   va_end (ap);
150 }
151
152 /* Output a self-relative reference to a label, possibly in a
153    different section or object file.  */
154
155 void
156 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED,
157                       const char *label ATTRIBUTE_UNUSED,
158                       const char *comment, ...)
159 {
160   va_list ap;
161
162   va_start (ap, comment);
163
164 #ifdef ASM_OUTPUT_DWARF_PCREL
165   ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, label);
166 #else
167   dw2_assemble_integer (size,
168                         gen_rtx_MINUS (Pmode,
169                                        gen_rtx_SYMBOL_REF (Pmode, label),
170                                        pc_rtx));
171 #endif
172
173   if (flag_debug_asm && comment)
174     {
175       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
176       vfprintf (asm_out_file, comment, ap);
177     }
178   fputc ('\n', asm_out_file);
179
180   va_end (ap);
181 }
182
183 /* Output an absolute reference to a label.  */
184
185 void
186 dw2_asm_output_addr (int size, const char *label,
187                      const char *comment, ...)
188 {
189   va_list ap;
190
191   va_start (ap, comment);
192
193   dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
194
195   if (flag_debug_asm && comment)
196     {
197       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
198       vfprintf (asm_out_file, comment, ap);
199     }
200   fputc ('\n', asm_out_file);
201
202   va_end (ap);
203 }
204
205 /* Similar, but use an RTX expression instead of a text label.  */
206
207 void
208 dw2_asm_output_addr_rtx (int size, rtx addr,
209                          const char *comment, ...)
210 {
211   va_list ap;
212
213   va_start (ap, comment);
214
215   dw2_assemble_integer (size, addr);
216
217   if (flag_debug_asm && comment)
218     {
219       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
220       vfprintf (asm_out_file, comment, ap);
221     }
222   fputc ('\n', asm_out_file);
223
224   va_end (ap);
225 }
226
227 void
228 dw2_asm_output_nstring (const char *str, size_t orig_len,
229                         const char *comment, ...)
230 {
231   size_t i, len;
232   va_list ap;
233
234   va_start (ap, comment);
235
236   len = orig_len;
237
238   if (len == (size_t) -1)
239     len = strlen (str);
240
241   if (flag_debug_asm && comment)
242     {
243       fputs ("\t.ascii \"", asm_out_file);
244       for (i = 0; i < len; i++)
245         {
246           int c = str[i];
247           if (c == '\"' || c == '\\')
248             fputc ('\\', asm_out_file);
249           if (ISPRINT(c))
250             fputc (c, asm_out_file);
251           else
252             fprintf (asm_out_file, "\\%o", c);
253         }
254       fprintf (asm_out_file, "\\0\"\t%s ", ASM_COMMENT_START);
255       vfprintf (asm_out_file, comment, ap);
256       fputc ('\n', asm_out_file);
257     }
258   else
259     {
260       /* If an explicit length was given, we can't assume there
261          is a null termination in the string buffer.  */
262       if (orig_len == (size_t) -1)
263         len += 1;
264       ASM_OUTPUT_ASCII (asm_out_file, str, len);
265       if (orig_len != (size_t) -1)
266         assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
267     }
268
269   va_end (ap);
270 }
271 \f
272
273 /* Return the size of an unsigned LEB128 quantity.  */
274
275 int
276 size_of_uleb128 (unsigned HOST_WIDE_INT value)
277 {
278   int size = 0;
279
280   do
281     {
282       value >>= 7;
283       size += 1;
284     }
285   while (value != 0);
286
287   return size;
288 }
289
290 /* Return the size of a signed LEB128 quantity.  */
291
292 int
293 size_of_sleb128 (HOST_WIDE_INT value)
294 {
295   int size = 0, byte;
296
297   do
298     {
299       byte = (value & 0x7f);
300       value >>= 7;
301       size += 1;
302     }
303   while (!((value == 0 && (byte & 0x40) == 0)
304            || (value == -1 && (byte & 0x40) != 0)));
305
306   return size;
307 }
308
309 /* Given an encoding, return the number of bytes the format occupies.
310    This is only defined for fixed-size encodings, and so does not
311    include leb128.  */
312
313 int
314 size_of_encoded_value (int encoding)
315 {
316   if (encoding == DW_EH_PE_omit)
317     return 0;
318
319   switch (encoding & 0x07)
320     {
321     case DW_EH_PE_absptr:
322       return POINTER_SIZE / BITS_PER_UNIT;
323     case DW_EH_PE_udata2:
324       return 2;
325     case DW_EH_PE_udata4:
326       return 4;
327     case DW_EH_PE_udata8:
328       return 8;
329     }
330   abort ();
331 }
332
333 /* Yield a name for a given pointer encoding.  */
334
335 const char *
336 eh_data_format_name (int format)
337 {
338 #if HAVE_DESIGNATED_INITIALIZERS
339 #define S(p, v)         [p] = v,
340 #else
341 #define S(p, v)         case p: return v;
342 #endif
343
344 #if HAVE_DESIGNATED_INITIALIZERS
345   __extension__ static const char * const format_names[256] = {
346 #else
347   switch (format) {
348 #endif
349
350   S(DW_EH_PE_absptr, "absolute")
351   S(DW_EH_PE_omit, "omit")
352   S(DW_EH_PE_aligned, "aligned absolute")
353
354   S(DW_EH_PE_uleb128, "uleb128")
355   S(DW_EH_PE_udata2, "udata2")
356   S(DW_EH_PE_udata4, "udata4")
357   S(DW_EH_PE_udata8, "udata8")
358   S(DW_EH_PE_sleb128, "sleb128")
359   S(DW_EH_PE_sdata2, "sdata2")
360   S(DW_EH_PE_sdata4, "sdata4")
361   S(DW_EH_PE_sdata8, "sdata8")
362
363   S(DW_EH_PE_absptr | DW_EH_PE_pcrel, "pcrel")
364   S(DW_EH_PE_uleb128 | DW_EH_PE_pcrel, "pcrel uleb128")
365   S(DW_EH_PE_udata2 | DW_EH_PE_pcrel, "pcrel udata2")
366   S(DW_EH_PE_udata4 | DW_EH_PE_pcrel, "pcrel udata4")
367   S(DW_EH_PE_udata8 | DW_EH_PE_pcrel, "pcrel udata8")
368   S(DW_EH_PE_sleb128 | DW_EH_PE_pcrel, "pcrel sleb128")
369   S(DW_EH_PE_sdata2 | DW_EH_PE_pcrel, "pcrel sdata2")
370   S(DW_EH_PE_sdata4 | DW_EH_PE_pcrel, "pcrel sdata4")
371   S(DW_EH_PE_sdata8 | DW_EH_PE_pcrel, "pcrel sdata8")
372
373   S(DW_EH_PE_absptr | DW_EH_PE_textrel, "textrel")
374   S(DW_EH_PE_uleb128 | DW_EH_PE_textrel, "textrel uleb128")
375   S(DW_EH_PE_udata2 | DW_EH_PE_textrel, "textrel udata2")
376   S(DW_EH_PE_udata4 | DW_EH_PE_textrel, "textrel udata4")
377   S(DW_EH_PE_udata8 | DW_EH_PE_textrel, "textrel udata8")
378   S(DW_EH_PE_sleb128 | DW_EH_PE_textrel, "textrel sleb128")
379   S(DW_EH_PE_sdata2 | DW_EH_PE_textrel, "textrel sdata2")
380   S(DW_EH_PE_sdata4 | DW_EH_PE_textrel, "textrel sdata4")
381   S(DW_EH_PE_sdata8 | DW_EH_PE_textrel, "textrel sdata8")
382
383   S(DW_EH_PE_absptr | DW_EH_PE_datarel, "datarel")
384   S(DW_EH_PE_uleb128 | DW_EH_PE_datarel, "datarel uleb128")
385   S(DW_EH_PE_udata2 | DW_EH_PE_datarel, "datarel udata2")
386   S(DW_EH_PE_udata4 | DW_EH_PE_datarel, "datarel udata4")
387   S(DW_EH_PE_udata8 | DW_EH_PE_datarel, "datarel udata8")
388   S(DW_EH_PE_sleb128 | DW_EH_PE_datarel, "datarel sleb128")
389   S(DW_EH_PE_sdata2 | DW_EH_PE_datarel, "datarel sdata2")
390   S(DW_EH_PE_sdata4 | DW_EH_PE_datarel, "datarel sdata4")
391   S(DW_EH_PE_sdata8 | DW_EH_PE_datarel, "datarel sdata8")
392
393   S(DW_EH_PE_absptr | DW_EH_PE_funcrel, "funcrel")
394   S(DW_EH_PE_uleb128 | DW_EH_PE_funcrel, "funcrel uleb128")
395   S(DW_EH_PE_udata2 | DW_EH_PE_funcrel, "funcrel udata2")
396   S(DW_EH_PE_udata4 | DW_EH_PE_funcrel, "funcrel udata4")
397   S(DW_EH_PE_udata8 | DW_EH_PE_funcrel, "funcrel udata8")
398   S(DW_EH_PE_sleb128 | DW_EH_PE_funcrel, "funcrel sleb128")
399   S(DW_EH_PE_sdata2 | DW_EH_PE_funcrel, "funcrel sdata2")
400   S(DW_EH_PE_sdata4 | DW_EH_PE_funcrel, "funcrel sdata4")
401   S(DW_EH_PE_sdata8 | DW_EH_PE_funcrel, "funcrel sdata8")
402
403   S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_pcrel,
404     "indirect pcrel")
405   S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_pcrel,
406     "indirect pcrel uleb128")
407   S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_pcrel,
408     "indirect pcrel udata2")
409   S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_pcrel,
410     "indirect pcrel udata4")
411   S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_pcrel,
412     "indirect pcrel udata8")
413   S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_pcrel,
414     "indirect pcrel sleb128")
415   S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_pcrel,
416     "indirect pcrel sdata2")
417   S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_pcrel,
418     "indirect pcrel sdata4")
419   S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_pcrel,
420     "indirect pcrel sdata8")
421
422   S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_textrel,
423     "indirect textrel")
424   S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_textrel,
425     "indirect textrel uleb128")
426   S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_textrel,
427     "indirect textrel udata2")
428   S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_textrel,
429     "indirect textrel udata4")
430   S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_textrel,
431     "indirect textrel udata8")
432   S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_textrel,
433     "indirect textrel sleb128")
434   S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_textrel,
435     "indirect textrel sdata2")
436   S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_textrel,
437     "indirect textrel sdata4")
438   S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_textrel,
439     "indirect textrel sdata8")
440
441   S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_datarel,
442     "indirect datarel")
443   S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_datarel,
444     "indirect datarel uleb128")
445   S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_datarel,
446     "indirect datarel udata2")
447   S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_datarel,
448     "indirect datarel udata4")
449   S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_datarel,
450     "indirect datarel udata8")
451   S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_datarel,
452     "indirect datarel sleb128")
453   S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_datarel,
454     "indirect datarel sdata2")
455   S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_datarel,
456     "indirect datarel sdata4")
457   S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_datarel,
458     "indirect datarel sdata8")
459
460   S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_funcrel,
461     "indirect funcrel")
462   S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_funcrel,
463     "indirect funcrel uleb128")
464   S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_funcrel,
465     "indirect funcrel udata2")
466   S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_funcrel,
467     "indirect funcrel udata4")
468   S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_funcrel,
469     "indirect funcrel udata8")
470   S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_funcrel,
471     "indirect funcrel sleb128")
472   S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_funcrel,
473     "indirect funcrel sdata2")
474   S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_funcrel,
475     "indirect funcrel sdata4")
476   S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_funcrel,
477     "indirect funcrel sdata8")
478
479 #if HAVE_DESIGNATED_INITIALIZERS
480   };
481
482   if (format < 0 || format > 0xff || format_names[format] == NULL)
483     abort ();
484   return format_names[format];
485 #else
486   }
487   abort ();
488 #endif
489 }
490
491 /* Output an unsigned LEB128 quantity.  */
492
493 void
494 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value,
495                              const char *comment, ...)
496 {
497   va_list ap;
498
499   va_start (ap, comment);
500
501 #ifdef HAVE_AS_LEB128
502   fprintf (asm_out_file, "\t.uleb128 " HOST_WIDE_INT_PRINT_HEX , value);
503
504   if (flag_debug_asm && comment)
505     {
506       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
507       vfprintf (asm_out_file, comment, ap);
508     }
509 #else
510   {
511     unsigned HOST_WIDE_INT work = value;
512     const char *byte_op = targetm.asm_out.byte_op;
513
514     if (byte_op)
515       fputs (byte_op, asm_out_file);
516     do
517       {
518         int byte = (work & 0x7f);
519         work >>= 7;
520         if (work != 0)
521           /* More bytes to follow.  */
522           byte |= 0x80;
523
524         if (byte_op)
525           {
526             fprintf (asm_out_file, "0x%x", byte);
527             if (work != 0)
528               fputc (',', asm_out_file);
529           }
530         else
531           assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
532       }
533     while (work != 0);
534
535   if (flag_debug_asm)
536     {
537       fprintf (asm_out_file, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX,
538                ASM_COMMENT_START, value);
539       if (comment)
540         {
541           fputs ("; ", asm_out_file);
542           vfprintf (asm_out_file, comment, ap);
543         }
544     }
545   }
546 #endif
547   fputc ('\n', asm_out_file);
548
549   va_end (ap);
550 }
551
552 /* Output a signed LEB128 quantity.  */
553
554 void
555 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value,
556                              const char *comment, ...)
557 {
558   va_list ap;
559
560   va_start (ap, comment);
561
562 #ifdef HAVE_AS_LEB128
563   fprintf (asm_out_file, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC, value);
564
565   if (flag_debug_asm && comment)
566     {
567       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
568       vfprintf (asm_out_file, comment, ap);
569     }
570 #else
571   {
572     HOST_WIDE_INT work = value;
573     int more, byte;
574     const char *byte_op = targetm.asm_out.byte_op;
575
576     if (byte_op)
577       fputs (byte_op, asm_out_file);
578     do
579       {
580         byte = (work & 0x7f);
581         /* arithmetic shift */
582         work >>= 7;
583         more = !((work == 0 && (byte & 0x40) == 0)
584                  || (work == -1 && (byte & 0x40) != 0));
585         if (more)
586           byte |= 0x80;
587
588         if (byte_op)
589           {
590             fprintf (asm_out_file, "0x%x", byte);
591             if (more)
592               fputc (',', asm_out_file);
593           }
594         else
595           assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
596       }
597     while (more);
598
599   if (flag_debug_asm)
600     {
601       fprintf (asm_out_file, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC,
602                ASM_COMMENT_START, value);
603       if (comment)
604         {
605           fputs ("; ", asm_out_file);
606           vfprintf (asm_out_file, comment, ap);
607         }
608     }
609   }
610 #endif
611   fputc ('\n', asm_out_file);
612
613   va_end (ap);
614 }
615
616 void
617 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED,
618                               const char *lab2 ATTRIBUTE_UNUSED,
619                               const char *comment, ...)
620 {
621   va_list ap;
622
623   va_start (ap, comment);
624
625 #ifdef HAVE_AS_LEB128
626   fputs ("\t.uleb128 ", asm_out_file);
627   assemble_name (asm_out_file, lab1);
628   fputc ('-', asm_out_file);
629   assemble_name (asm_out_file, lab2);
630 #else
631   abort ();
632 #endif
633
634   if (flag_debug_asm && comment)
635     {
636       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
637       vfprintf (asm_out_file, comment, ap);
638     }
639   fputc ('\n', asm_out_file);
640
641   va_end (ap);
642 }
643
644 void
645 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED,
646                               const char *lab2 ATTRIBUTE_UNUSED,
647                               const char *comment, ...)
648 {
649   va_list ap;
650
651   va_start (ap, comment);
652
653 #ifdef HAVE_AS_LEB128
654   fputs ("\t.sleb128 ", asm_out_file);
655   assemble_name (asm_out_file, lab1);
656   fputc ('-', asm_out_file);
657   assemble_name (asm_out_file, lab2);
658 #else
659   abort ();
660 #endif
661
662   if (flag_debug_asm && comment)
663     {
664       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
665       vfprintf (asm_out_file, comment, ap);
666     }
667   fputc ('\n', asm_out_file);
668
669   va_end (ap);
670 }
671 \f
672 static rtx dw2_force_const_mem (rtx);
673 static int dw2_output_indirect_constant_1 (splay_tree_node, void *);
674
675 static GTY((param1_is (char *), param2_is (tree))) splay_tree indirect_pool;
676
677 static GTY(()) int dw2_const_labelno;
678
679 #if defined(HAVE_GAS_HIDDEN) && defined(SUPPORTS_ONE_ONLY)
680 # define USE_LINKONCE_INDIRECT 1
681 #else
682 # define USE_LINKONCE_INDIRECT 0
683 #endif
684
685 /* Put X, a SYMBOL_REF, in memory.  Return a SYMBOL_REF to the allocated
686    memory.  Differs from force_const_mem in that a single pool is used for
687    the entire unit of translation, and the memory is not guaranteed to be
688    "near" the function in any interesting sense.  */
689
690 static rtx
691 dw2_force_const_mem (rtx x)
692 {
693   splay_tree_node node;
694   const char *str;
695   tree decl;
696
697   if (! indirect_pool)
698     indirect_pool = splay_tree_new_ggc (splay_tree_compare_pointers);
699
700   if (GET_CODE (x) != SYMBOL_REF)
701     abort ();
702
703   str = (* targetm.strip_name_encoding) (XSTR (x, 0));
704   node = splay_tree_lookup (indirect_pool, (splay_tree_key) str);
705   if (node)
706     decl = (tree) node->value;
707   else
708     {
709       tree id;
710
711       if (USE_LINKONCE_INDIRECT)
712         {
713           char *ref_name = alloca (strlen (str) + sizeof "DW.ref.");
714
715           sprintf (ref_name, "DW.ref.%s", str);
716           id = get_identifier (ref_name);
717           decl = build_decl (VAR_DECL, id, ptr_type_node);
718           DECL_ARTIFICIAL (decl) = 1;
719           TREE_PUBLIC (decl) = 1;
720           DECL_INITIAL (decl) = decl;
721           make_decl_one_only (decl);
722         }
723       else
724         {
725           char label[32];
726
727           ASM_GENERATE_INTERNAL_LABEL (label, "LDFCM", dw2_const_labelno);
728           ++dw2_const_labelno;
729           id = get_identifier (label);
730           decl = build_decl (VAR_DECL, id, ptr_type_node);
731           DECL_ARTIFICIAL (decl) = 1;
732           TREE_STATIC (decl) = 1;
733           DECL_INITIAL (decl) = decl;
734         }
735
736       id = maybe_get_identifier (str);
737       if (id)
738         TREE_SYMBOL_REFERENCED (id) = 1;
739
740       splay_tree_insert (indirect_pool, (splay_tree_key) str,
741                          (splay_tree_value) decl);
742     }
743
744   return XEXP (DECL_RTL (decl), 0);
745 }
746
747 /* A helper function for dw2_output_indirect_constants called through
748    splay_tree_foreach.  Emit one queued constant to memory.  */
749
750 static int
751 dw2_output_indirect_constant_1 (splay_tree_node node,
752                                 void *data ATTRIBUTE_UNUSED)
753 {
754   const char *sym;
755   rtx sym_ref;
756
757   sym = (const char *) node->key;
758   sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
759   if (USE_LINKONCE_INDIRECT)
760     fprintf (asm_out_file, "\t.hidden %sDW.ref.%s\n", user_label_prefix, sym);
761   assemble_variable ((tree) node->value, 1, 1, 1);
762   assemble_integer (sym_ref, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
763
764   return 0;
765 }
766
767 /* Emit the constants queued through dw2_force_const_mem.  */
768
769 void
770 dw2_output_indirect_constants (void)
771 {
772   if (indirect_pool)
773     splay_tree_foreach (indirect_pool, dw2_output_indirect_constant_1, NULL);
774 }
775
776 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.  */
777
778 void
779 dw2_asm_output_encoded_addr_rtx (int encoding, rtx addr,
780                                  const char *comment, ...)
781 {
782   int size;
783   va_list ap;
784
785   va_start (ap, comment);
786
787   size = size_of_encoded_value (encoding);
788
789   if (encoding == DW_EH_PE_aligned)
790     {
791       assemble_align (POINTER_SIZE);
792       assemble_integer (addr, size, POINTER_SIZE, 1);
793       return;
794     }
795
796   /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
797      "all others".  */
798   if (addr == const0_rtx || addr == const1_rtx)
799     assemble_integer (addr, size, BITS_PER_UNIT, 1);
800   else
801     {
802     restart:
803       /* Allow the target first crack at emitting this.  Some of the
804          special relocations require special directives instead of
805          just ".4byte" or whatever.  */
806 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
807       ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file, encoding, size,
808                                          addr, done);
809 #endif
810
811       /* Indirection is used to get dynamic relocations out of a
812          read-only section.  */
813       if (encoding & DW_EH_PE_indirect)
814         {
815           /* It is very tempting to use force_const_mem so that we share data
816              with the normal constant pool.  However, we've already emitted
817              the constant pool for this function.  Moreover, we'd like to
818              share these constants across the entire unit of translation,
819              or better, across the entire application (or DSO).  */
820           addr = dw2_force_const_mem (addr);
821           encoding &= ~DW_EH_PE_indirect;
822           goto restart;
823         }
824
825       switch (encoding & 0xF0)
826         {
827         case DW_EH_PE_absptr:
828           dw2_assemble_integer (size, addr);
829           break;
830
831         case DW_EH_PE_pcrel:
832           if (GET_CODE (addr) != SYMBOL_REF)
833             abort ();
834 #ifdef ASM_OUTPUT_DWARF_PCREL
835           ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, XSTR (addr, 0));
836 #else
837           dw2_assemble_integer (size, gen_rtx_MINUS (Pmode, addr, pc_rtx));
838 #endif
839           break;
840
841         default:
842           /* Other encodings should have been handled by
843              ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX.  */
844           abort ();
845         }
846
847 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
848     done:;
849 #endif
850     }
851
852   if (flag_debug_asm && comment)
853     {
854       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
855       vfprintf (asm_out_file, comment, ap);
856     }
857   fputc ('\n', asm_out_file);
858
859   va_end (ap);
860 }
861
862 #include "gt-dwarf2asm.h"