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