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