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