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