binutils/
[deliverable/binutils-gdb.git] / gas / dwarf2dbg.c
CommitLineData
fac0d250 1/* dwarf2dbg.c - DWARF2 debug support
aa820537 2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
2da5c037 3 Free Software Foundation, Inc.
fac0d250
RH
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5
6 This file is part of GAS, the GNU Assembler.
7
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
ec2655a6 10 the Free Software Foundation; either version 3, or (at your option)
fac0d250
RH
11 any later version.
12
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
4b4da160
NC
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
fac0d250 22
89b66cde 23/* Logical line numbers can be controlled by the compiler via the
bd0eb99b 24 following directives:
fac0d250
RH
25
26 .file FILENO "file.c"
ecea7679 27 .loc FILENO LINENO [COLUMN] [basic_block] [prologue_end] \
92846e72
CC
28 [epilogue_begin] [is_stmt VALUE] [isa VALUE] \
29 [discriminator VALUE]
bd0eb99b 30*/
fac0d250 31
fac0d250 32#include "as.h"
bd0eb99b 33#include "safe-ctype.h"
92eb7b32 34
42dbf88c
NC
35#ifdef HAVE_LIMITS_H
36#include <limits.h>
92625c16 37#else
6717891c
NC
38#ifdef HAVE_SYS_PARAM_H
39#include <sys/param.h>
40#endif
6256f9dd 41#ifndef INT_MAX
ee515fb7 42#define INT_MAX (int) (((unsigned) (-1)) >> 1)
42dbf88c 43#endif
b8f080d6 44#endif
42dbf88c 45
70658493 46#include "dwarf2dbg.h"
a7ed1ca2 47#include <filenames.h>
70658493 48
56487c55
NC
49#ifdef HAVE_DOS_BASED_FILE_SYSTEM
50/* We need to decide which character to use as a directory separator.
51 Just because HAVE_DOS_BASED_FILE_SYSTEM is defined, it does not
52 necessarily mean that the backslash character is the one to use.
53 Some environments, eg Cygwin, can support both naming conventions.
54 So we use the heuristic that we only need to use the backslash if
55 the path is an absolute path starting with a DOS style drive
56 selector. eg C: or D: */
57# define INSERT_DIR_SEPARATOR(string, offset) \
58 do \
59 { \
60 if (offset > 1 \
7fd3924a
AM
61 && string[0] != 0 \
62 && string[1] == ':') \
56487c55
NC
63 string [offset] = '\\'; \
64 else \
65 string [offset] = '/'; \
66 } \
67 while (0)
68#else
69# define INSERT_DIR_SEPARATOR(string, offset) string[offset] = '/'
70#endif
71
14e777e0 72#ifndef DWARF2_FORMAT
413a266c 73# define DWARF2_FORMAT(SEC) dwarf2_format_32bit
14e777e0
KB
74#endif
75
9605f328 76#ifndef DWARF2_ADDR_SIZE
e4475e39 77# define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
9605f328
AO
78#endif
79
01e1a5bc
NC
80#ifndef DWARF2_FILE_NAME
81#define DWARF2_FILE_NAME(FILENAME, DIRNAME) FILENAME
82#endif
83
84#ifndef DWARF2_FILE_TIME_NAME
85#define DWARF2_FILE_TIME_NAME(FILENAME,DIRNAME) 0
86#endif
87
88#ifndef DWARF2_FILE_SIZE_NAME
89#define DWARF2_FILE_SIZE_NAME(FILENAME,DIRNAME) 0
90#endif
91
fac0d250
RH
92#include "subsegs.h"
93
fa8f86ff 94#include "dwarf2.h"
fac0d250 95
fac0d250
RH
96/* Since we can't generate the prolog until the body is complete, we
97 use three different subsegments for .debug_line: one holding the
98 prolog, one for the directory and filename info, and one for the
99 body ("statement program"). */
100#define DL_PROLOG 0
101#define DL_FILES 1
102#define DL_BODY 2
103
1737851b
BW
104/* If linker relaxation might change offsets in the code, the DWARF special
105 opcodes and variable-length operands cannot be used. If this macro is
106 nonzero, use the DW_LNS_fixed_advance_pc opcode instead. */
107#ifndef DWARF2_USE_FIXED_ADVANCE_PC
108# define DWARF2_USE_FIXED_ADVANCE_PC 0
109#endif
110
fac0d250
RH
111/* First special line opcde - leave room for the standard opcodes.
112 Note: If you want to change this, you'll have to update the
113 "standard_opcode_lengths" table that is emitted below in
bd0eb99b
RH
114 out_debug_line(). */
115#define DWARF2_LINE_OPCODE_BASE 13
fac0d250
RH
116
117#ifndef DWARF2_LINE_BASE
118 /* Minimum line offset in a special line info. opcode. This value
119 was chosen to give a reasonable range of values. */
120# define DWARF2_LINE_BASE -5
121#endif
122
123/* Range of line offsets in a special line info. opcode. */
124#ifndef DWARF2_LINE_RANGE
125# define DWARF2_LINE_RANGE 14
126#endif
127
128#ifndef DWARF2_LINE_MIN_INSN_LENGTH
129 /* Define the architecture-dependent minimum instruction length (in
130 bytes). This value should be rather too small than too big. */
4dc7ead9 131# define DWARF2_LINE_MIN_INSN_LENGTH 1
fac0d250
RH
132#endif
133
bd0eb99b 134/* Flag that indicates the initial value of the is_stmt_start flag. */
fac0d250
RH
135#define DWARF2_LINE_DEFAULT_IS_STMT 1
136
cb30237e 137/* Given a special op, return the line skip amount. */
fac0d250
RH
138#define SPECIAL_LINE(op) \
139 (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE)
140
141/* Given a special op, return the address skip amount (in units of
142 DWARF2_LINE_MIN_INSN_LENGTH. */
143#define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
144
cb30237e 145/* The maximum address skip amount that can be encoded with a special op. */
fac0d250
RH
146#define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
147
ee515fb7 148struct line_entry {
220e750f 149 struct line_entry *next;
07a53e5c 150 symbolS *label;
220e750f 151 struct dwarf2_line_info loc;
e6c774b4 152};
fac0d250 153
ee515fb7 154struct line_subseg {
220e750f
RH
155 struct line_subseg *next;
156 subsegT subseg;
157 struct line_entry *head;
158 struct line_entry **ptail;
159};
353e2c69 160
ee515fb7 161struct line_seg {
220e750f
RH
162 struct line_seg *next;
163 segT seg;
164 struct line_subseg *head;
165 symbolS *text_start;
166 symbolS *text_end;
167};
168
169/* Collects data for all line table entries during assembly. */
170static struct line_seg *all_segs;
1e9cc1c2
NC
171/* Hash used to quickly lookup a segment by name, avoiding the need to search
172 through the all_segs list. */
173static struct hash_control *all_segs_hash;
174static struct line_seg **last_seg_ptr;
220e750f 175
ee515fb7 176struct file_entry {
a7ed1ca2 177 const char *filename;
220e750f
RH
178 unsigned int dir;
179};
180
181/* Table of files used by .debug_line. */
182static struct file_entry *files;
183static unsigned int files_in_use;
184static unsigned int files_allocated;
185
a7ed1ca2
NC
186/* Table of directories used by .debug_line. */
187static char **dirs;
188static unsigned int dirs_in_use;
189static unsigned int dirs_allocated;
190
b34976b6 191/* TRUE when we've seen a .loc directive recently. Used to avoid
220e750f 192 doing work when there's nothing to do. */
1eee4adc 193bfd_boolean dwarf2_loc_directive_seen;
220e750f 194
07a53e5c
RH
195/* TRUE when we're supposed to set the basic block mark whenever a
196 label is seen. */
197bfd_boolean dwarf2_loc_mark_labels;
198
220e750f 199/* Current location as indicated by the most recent .loc directive. */
bd0eb99b
RH
200static struct dwarf2_line_info current = {
201 1, 1, 0, 0,
92846e72
CC
202 DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0,
203 0
bd0eb99b 204};
220e750f 205
220e750f
RH
206/* The size of an address on the target. */
207static unsigned int sizeof_address;
208\f
a2e22468 209static unsigned int get_filenum (const char *, unsigned int);
413a266c 210
c5c0a210 211#ifndef TC_DWARF2_EMIT_OFFSET
802f5d9e 212#define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
c5c0a210 213
6174d9c8
RH
214/* Create an offset to .dwarf2_*. */
215
216static void
a2e22468 217generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
6174d9c8 218{
91d6fa6a 219 expressionS exp;
6174d9c8 220
91d6fa6a
NC
221 exp.X_op = O_symbol;
222 exp.X_add_symbol = symbol;
223 exp.X_add_number = 0;
224 emit_expr (&exp, size);
6174d9c8 225}
c5c0a210 226#endif
6174d9c8 227
220e750f
RH
228/* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
229
230static struct line_subseg *
a2e22468 231get_line_subseg (segT seg, subsegT subseg)
220e750f
RH
232{
233 static segT last_seg;
234 static subsegT last_subseg;
235 static struct line_subseg *last_line_subseg;
236
1e9cc1c2 237 struct line_seg *s;
91d6fa6a 238 struct line_subseg **pss, *lss;
fac0d250 239
220e750f
RH
240 if (seg == last_seg && subseg == last_subseg)
241 return last_line_subseg;
242
1e9cc1c2
NC
243 s = (struct line_seg *) hash_find (all_segs_hash, seg->name);
244 if (s == NULL)
245 {
246 s = (struct line_seg *) xmalloc (sizeof (*s));
247 s->next = NULL;
248 s->seg = seg;
249 s->head = NULL;
250 *last_seg_ptr = s;
251 last_seg_ptr = &s->next;
252 hash_insert (all_segs_hash, seg->name, s);
253 }
254 gas_assert (seg == s->seg);
220e750f 255
91d6fa6a 256 for (pss = &s->head; (lss = *pss) != NULL ; pss = &lss->next)
fac0d250 257 {
91d6fa6a 258 if (lss->subseg == subseg)
ee515fb7 259 goto found_subseg;
91d6fa6a 260 if (lss->subseg > subseg)
220e750f 261 break;
fac0d250 262 }
220e750f 263
91d6fa6a
NC
264 lss = (struct line_subseg *) xmalloc (sizeof (*lss));
265 lss->next = *pss;
266 lss->subseg = subseg;
267 lss->head = NULL;
268 lss->ptail = &lss->head;
269 *pss = lss;
220e750f
RH
270
271 found_subseg:
272 last_seg = seg;
273 last_subseg = subseg;
91d6fa6a 274 last_line_subseg = lss;
220e750f 275
91d6fa6a 276 return lss;
fac0d250
RH
277}
278
07a53e5c
RH
279/* Record an entry for LOC occurring at LABEL. */
280
281static void
282dwarf2_gen_line_info_1 (symbolS *label, struct dwarf2_line_info *loc)
283{
91d6fa6a 284 struct line_subseg *lss;
07a53e5c
RH
285 struct line_entry *e;
286
287 e = (struct line_entry *) xmalloc (sizeof (*e));
288 e->next = NULL;
289 e->label = label;
290 e->loc = *loc;
291
91d6fa6a
NC
292 lss = get_line_subseg (now_seg, now_subseg);
293 *lss->ptail = e;
294 lss->ptail = &e->next;
07a53e5c
RH
295}
296
436d9e46 297/* Record an entry for LOC occurring at OFS within the current fragment. */
353e2c69 298
220e750f 299void
a2e22468 300dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
fac0d250 301{
1ea5c325
MS
302 static unsigned int line = -1;
303 static unsigned int filenum = -1;
220e750f 304
07a53e5c
RH
305 symbolS *sym;
306
220e750f
RH
307 /* Early out for as-yet incomplete location information. */
308 if (loc->filenum == 0 || loc->line == 0)
309 return;
310
ffa554ed
GK
311 /* Don't emit sequences of line symbols for the same line when the
312 symbols apply to assembler code. It is necessary to emit
313 duplicate line symbols when a compiler asks for them, because GDB
314 uses them to determine the end of the prologue. */
d1a6c242 315 if (debug_type == DEBUG_DWARF2
ffa554ed 316 && line == loc->line && filenum == loc->filenum)
1ea5c325
MS
317 return;
318
319 line = loc->line;
320 filenum = loc->filenum;
321
07a53e5c
RH
322 sym = symbol_temp_new (now_seg, ofs, frag_now);
323 dwarf2_gen_line_info_1 (sym, loc);
220e750f 324}
fac0d250 325
ecea7679
RH
326/* Returns the current source information. If .file directives have
327 been encountered, the info for the corresponding source file is
328 returned. Otherwise, the info for the assembly source file is
329 returned. */
330
220e750f 331void
a2e22468 332dwarf2_where (struct dwarf2_line_info *line)
220e750f
RH
333{
334 if (debug_type == DEBUG_DWARF2)
fac0d250 335 {
220e750f
RH
336 char *filename;
337 as_where (&filename, &line->line);
a7ed1ca2 338 line->filenum = get_filenum (filename, 0);
220e750f 339 line->column = 0;
bd0eb99b 340 line->flags = DWARF2_FLAG_IS_STMT;
ecea7679 341 line->isa = current.isa;
92846e72 342 line->discriminator = current.discriminator;
fac0d250 343 }
220e750f
RH
344 else
345 *line = current;
fac0d250
RH
346}
347
7fd3924a 348/* A hook to allow the target backend to inform the line number state
ecea7679
RH
349 machine of isa changes when assembler debug info is enabled. */
350
351void
352dwarf2_set_isa (unsigned int isa)
353{
354 current.isa = isa;
355}
356
220e750f
RH
357/* Called for each machine instruction, or relatively atomic group of
358 machine instructions (ie built-in macro). The instruction or group
359 is SIZE bytes in length. If dwarf2 line number generation is called
360 for, emit a line statement appropriately. */
353e2c69 361
220e750f 362void
a2e22468 363dwarf2_emit_insn (int size)
fac0d250 364{
220e750f 365 struct dwarf2_line_info loc;
fac0d250 366
7fd3924a 367 if (!dwarf2_loc_directive_seen && debug_type != DEBUG_DWARF2)
220e750f 368 return;
7fd3924a
AM
369
370 dwarf2_where (&loc);
b6675117 371
220e750f 372 dwarf2_gen_line_info (frag_now_fix () - size, &loc);
661ba50f
BW
373 dwarf2_consume_line_info ();
374}
375
376/* Called after the current line information has been either used with
377 dwarf2_gen_line_info or saved with a machine instruction for later use.
378 This resets the state of the line number information to reflect that
379 it has been used. */
380
381void
382dwarf2_consume_line_info (void)
383{
384 /* Unless we generate DWARF2 debugging information for each
385 assembler line, we only emit one line symbol for one LOC. */
7fd3924a 386 dwarf2_loc_directive_seen = FALSE;
bd0eb99b
RH
387
388 current.flags &= ~(DWARF2_FLAG_BASIC_BLOCK
389 | DWARF2_FLAG_PROLOGUE_END
390 | DWARF2_FLAG_EPILOGUE_BEGIN);
92846e72 391 current.discriminator = 0;
220e750f 392}
fac0d250 393
07a53e5c
RH
394/* Called for each (preferably code) label. If dwarf2_loc_mark_labels
395 is enabled, emit a basic block marker. */
396
397void
398dwarf2_emit_label (symbolS *label)
399{
400 struct dwarf2_line_info loc;
401
402 if (!dwarf2_loc_mark_labels)
403 return;
404 if (S_GET_SEGMENT (label) != now_seg)
405 return;
406 if (!(bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE))
407 return;
7fd3924a
AM
408 if (files_in_use == 0 && debug_type != DEBUG_DWARF2)
409 return;
410
411 dwarf2_where (&loc);
07a53e5c
RH
412
413 loc.flags |= DWARF2_FLAG_BASIC_BLOCK;
414
07a53e5c 415 dwarf2_gen_line_info_1 (label, &loc);
7fd3924a 416 dwarf2_consume_line_info ();
07a53e5c
RH
417}
418
a7ed1ca2
NC
419/* Get a .debug_line file number for FILENAME. If NUM is nonzero,
420 allocate it on that file table slot, otherwise return the first
421 empty one. */
220e750f
RH
422
423static unsigned int
a2e22468 424get_filenum (const char *filename, unsigned int num)
220e750f 425{
a7ed1ca2
NC
426 static unsigned int last_used, last_used_dir_len;
427 const char *file;
428 size_t dir_len;
429 unsigned int i, dir;
220e750f 430
a7ed1ca2
NC
431 if (num == 0 && last_used)
432 {
433 if (! files[last_used].dir
8b6efd89 434 && filename_cmp (filename, files[last_used].filename) == 0)
a7ed1ca2
NC
435 return last_used;
436 if (files[last_used].dir
8b6efd89
KT
437 && filename_ncmp (filename, dirs[files[last_used].dir],
438 last_used_dir_len) == 0
a7ed1ca2 439 && IS_DIR_SEPARATOR (filename [last_used_dir_len])
8b6efd89
KT
440 && filename_cmp (filename + last_used_dir_len + 1,
441 files[last_used].filename) == 0)
a7ed1ca2
NC
442 return last_used;
443 }
220e750f 444
a7ed1ca2
NC
445 file = lbasename (filename);
446 /* Don't make empty string from / or A: from A:/ . */
447#ifdef HAVE_DOS_BASED_FILE_SYSTEM
448 if (file <= filename + 3)
449 file = filename;
450#else
451 if (file == filename + 1)
452 file = filename;
453#endif
454 dir_len = file - filename;
455
456 dir = 0;
457 if (dir_len)
458 {
01e1a5bc 459#ifndef DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
a7ed1ca2 460 --dir_len;
01e1a5bc 461#endif
a7ed1ca2 462 for (dir = 1; dir < dirs_in_use; ++dir)
8b6efd89 463 if (filename_ncmp (filename, dirs[dir], dir_len) == 0
a7ed1ca2
NC
464 && dirs[dir][dir_len] == '\0')
465 break;
466
467 if (dir >= dirs_in_use)
468 {
469 if (dir >= dirs_allocated)
470 {
471 dirs_allocated = dir + 32;
472 dirs = (char **)
473 xrealloc (dirs, (dir + 32) * sizeof (const char *));
474 }
475
1e9cc1c2 476 dirs[dir] = (char *) xmalloc (dir_len + 1);
a7ed1ca2
NC
477 memcpy (dirs[dir], filename, dir_len);
478 dirs[dir][dir_len] = '\0';
479 dirs_in_use = dir + 1;
480 }
481 }
482
483 if (num == 0)
484 {
485 for (i = 1; i < files_in_use; ++i)
486 if (files[i].dir == dir
88b4ca40 487 && files[i].filename
8b6efd89 488 && filename_cmp (file, files[i].filename) == 0)
a7ed1ca2
NC
489 {
490 last_used = i;
491 last_used_dir_len = dir_len;
492 return i;
493 }
494 }
495 else
496 i = num;
220e750f
RH
497
498 if (i >= files_allocated)
fac0d250 499 {
249e3833
RH
500 unsigned int old = files_allocated;
501
220e750f
RH
502 files_allocated = i + 32;
503 files = (struct file_entry *)
ee515fb7 504 xrealloc (files, (i + 32) * sizeof (struct file_entry));
249e3833
RH
505
506 memset (files + old, 0, (i + 32 - old) * sizeof (struct file_entry));
fac0d250
RH
507 }
508
a7ed1ca2
NC
509 files[i].filename = num ? file : xstrdup (file);
510 files[i].dir = dir;
10cd14b4
AM
511 if (files_in_use < i + 1)
512 files_in_use = i + 1;
220e750f 513 last_used = i;
a7ed1ca2 514 last_used_dir_len = dir_len;
220e750f
RH
515
516 return i;
517}
fac0d250 518
ecb4347a
DJ
519/* Handle two forms of .file directive:
520 - Pass .file "source.c" to s_app_file
521 - Handle .file 1 "source.c" by adding an entry to the DWARF-2 file table
220e750f 522
ecb4347a
DJ
523 If an entry is added to the file table, return a pointer to the filename. */
524
525char *
a2e22468 526dwarf2_directive_file (int dummy ATTRIBUTE_UNUSED)
220e750f
RH
527{
528 offsetT num;
e46d99eb 529 char *filename;
220e750f
RH
530 int filename_len;
531
532 /* Continue to accept a bare string and pass it off. */
533 SKIP_WHITESPACE ();
534 if (*input_line_pointer == '"')
fac0d250 535 {
220e750f 536 s_app_file (0);
ecb4347a 537 return NULL;
fac0d250
RH
538 }
539
220e750f
RH
540 num = get_absolute_expression ();
541 filename = demand_copy_C_string (&filename_len);
bd0eb99b
RH
542 if (filename == NULL)
543 return NULL;
220e750f
RH
544 demand_empty_rest_of_line ();
545
249e3833 546 if (num < 1)
fac0d250 547 {
0e389e77 548 as_bad (_("file number less than one"));
ecb4347a 549 return NULL;
fac0d250
RH
550 }
551
7cadeb2c
AM
552 /* A .file directive implies compiler generated debug information is
553 being supplied. Turn off gas generated debug info. */
554 debug_type = DEBUG_NONE;
555
0e1a166b 556 if (num < (int) files_in_use && files[num].filename != 0)
220e750f 557 {
0e389e77 558 as_bad (_("file number %ld already allocated"), (long) num);
ecb4347a 559 return NULL;
249e3833 560 }
220e750f 561
a7ed1ca2 562 get_filenum (filename, num);
ecb4347a
DJ
563
564 return filename;
fac0d250
RH
565}
566
220e750f 567void
a2e22468 568dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
220e750f 569{
ecea7679
RH
570 offsetT filenum, line;
571
851feff8
DJ
572 /* If we see two .loc directives in a row, force the first one to be
573 output now. */
7cadeb2c 574 if (dwarf2_loc_directive_seen)
851feff8
DJ
575 dwarf2_emit_insn (0);
576
ecea7679
RH
577 filenum = get_absolute_expression ();
578 SKIP_WHITESPACE ();
579 line = get_absolute_expression ();
580
581 if (filenum < 1)
582 {
583 as_bad (_("file number less than one"));
584 return;
585 }
586 if (filenum >= (int) files_in_use || files[filenum].filename == 0)
587 {
588 as_bad (_("unassigned file number %ld"), (long) filenum);
589 return;
590 }
591
592 current.filenum = filenum;
593 current.line = line;
92846e72 594 current.discriminator = 0;
ecea7679
RH
595
596#ifndef NO_LISTING
597 if (listing)
598 {
599 if (files[filenum].dir)
600 {
601 size_t dir_len = strlen (dirs[files[filenum].dir]);
602 size_t file_len = strlen (files[filenum].filename);
603 char *cp = (char *) alloca (dir_len + 1 + file_len + 1);
604
605 memcpy (cp, dirs[files[filenum].dir], dir_len);
56487c55 606 INSERT_DIR_SEPARATOR (cp, dir_len);
ecea7679
RH
607 memcpy (cp + dir_len + 1, files[filenum].filename, file_len);
608 cp[dir_len + file_len + 1] = '\0';
609 listing_source_file (cp);
610 }
611 else
612 listing_source_file (files[filenum].filename);
613 listing_source_line (line);
614 }
615#endif
616
220e750f 617 SKIP_WHITESPACE ();
ecea7679
RH
618 if (ISDIGIT (*input_line_pointer))
619 {
620 current.column = get_absolute_expression ();
621 SKIP_WHITESPACE ();
622 }
623
624 while (ISALPHA (*input_line_pointer))
220e750f 625 {
bd0eb99b
RH
626 char *p, c;
627 offsetT value;
628
629 p = input_line_pointer;
630 c = get_symbol_end ();
631
632 if (strcmp (p, "basic_block") == 0)
633 {
634 current.flags |= DWARF2_FLAG_BASIC_BLOCK;
635 *input_line_pointer = c;
636 }
637 else if (strcmp (p, "prologue_end") == 0)
638 {
639 current.flags |= DWARF2_FLAG_PROLOGUE_END;
640 *input_line_pointer = c;
641 }
642 else if (strcmp (p, "epilogue_begin") == 0)
643 {
644 current.flags |= DWARF2_FLAG_EPILOGUE_BEGIN;
645 *input_line_pointer = c;
646 }
647 else if (strcmp (p, "is_stmt") == 0)
648 {
649 *input_line_pointer = c;
650 value = get_absolute_expression ();
651 if (value == 0)
652 current.flags &= ~DWARF2_FLAG_IS_STMT;
653 else if (value == 1)
654 current.flags |= DWARF2_FLAG_IS_STMT;
655 else
ecea7679
RH
656 {
657 as_bad (_("is_stmt value not 0 or 1"));
658 return;
659 }
bd0eb99b
RH
660 }
661 else if (strcmp (p, "isa") == 0)
662 {
7fd3924a 663 *input_line_pointer = c;
bd0eb99b 664 value = get_absolute_expression ();
ecea7679 665 if (value >= 0)
bd0eb99b 666 current.isa = value;
ecea7679
RH
667 else
668 {
669 as_bad (_("isa number less than zero"));
670 return;
671 }
bd0eb99b 672 }
92846e72
CC
673 else if (strcmp (p, "discriminator") == 0)
674 {
675 *input_line_pointer = c;
676 value = get_absolute_expression ();
677 if (value >= 0)
678 current.discriminator = value;
679 else
680 {
681 as_bad (_("discriminator less than zero"));
682 return;
683 }
684 }
bd0eb99b
RH
685 else
686 {
ecea7679 687 as_bad (_("unknown .loc sub-directive `%s'"), p);
7fd3924a 688 *input_line_pointer = c;
bd0eb99b
RH
689 return;
690 }
691
ecea7679 692 SKIP_WHITESPACE ();
bd0eb99b
RH
693 }
694
695 demand_empty_rest_of_line ();
1eee4adc 696 dwarf2_loc_directive_seen = TRUE;
7cadeb2c 697 debug_type = DEBUG_NONE;
220e750f 698}
07a53e5c
RH
699
700void
701dwarf2_directive_loc_mark_labels (int dummy ATTRIBUTE_UNUSED)
702{
703 offsetT value = get_absolute_expression ();
704
705 if (value != 0 && value != 1)
706 {
707 as_bad (_("expected 0 or 1"));
708 ignore_rest_of_line ();
709 }
710 else
711 {
712 dwarf2_loc_mark_labels = value != 0;
713 demand_empty_rest_of_line ();
714 }
715}
220e750f
RH
716\f
717static struct frag *
a2e22468 718first_frag_for_seg (segT seg)
220e750f 719{
c9049d30 720 return seg_info (seg)->frchainP->frch_root;
220e750f
RH
721}
722
723static struct frag *
a2e22468 724last_frag_for_seg (segT seg)
220e750f 725{
c9049d30 726 frchainS *f = seg_info (seg)->frchainP;
220e750f 727
c9049d30
AM
728 while (f->frch_next != NULL)
729 f = f->frch_next;
220e750f 730
c9049d30 731 return f->frch_last;
220e750f
RH
732}
733\f
734/* Emit a single byte into the current segment. */
735
736static inline void
a2e22468 737out_byte (int byte)
220e750f
RH
738{
739 FRAG_APPEND_1_CHAR (byte);
740}
741
742/* Emit a statement program opcode into the current segment. */
743
744static inline void
a2e22468 745out_opcode (int opc)
220e750f
RH
746{
747 out_byte (opc);
748}
749
750/* Emit a two-byte word into the current segment. */
751
752static inline void
a2e22468 753out_two (int data)
220e750f
RH
754{
755 md_number_to_chars (frag_more (2), data, 2);
756}
757
758/* Emit a four byte word into the current segment. */
759
760static inline void
a2e22468 761out_four (int data)
220e750f
RH
762{
763 md_number_to_chars (frag_more (4), data, 4);
764}
765
766/* Emit an unsigned "little-endian base 128" number. */
767
fac0d250 768static void
a2e22468 769out_uleb128 (addressT value)
220e750f
RH
770{
771 output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
772}
773
92846e72
CC
774/* Emit a signed "little-endian base 128" number. */
775
776static void
777out_leb128 (addressT value)
778{
779 output_leb128 (frag_more (sizeof_leb128 (value, 1)), value, 1);
780}
781
220e750f
RH
782/* Emit a tuple for .debug_abbrev. */
783
784static inline void
a2e22468 785out_abbrev (int name, int form)
fac0d250 786{
220e750f
RH
787 out_uleb128 (name);
788 out_uleb128 (form);
789}
fac0d250 790
220e750f 791/* Get the size of a fragment. */
fac0d250 792
220e750f 793static offsetT
c9049d30 794get_frag_fix (fragS *frag, segT seg)
220e750f
RH
795{
796 frchainS *fr;
797
798 if (frag->fr_next)
799 return frag->fr_fix;
800
801 /* If a fragment is the last in the chain, special measures must be
802 taken to find its size before relaxation, since it may be pending
803 on some subsegment chain. */
c9049d30 804 for (fr = seg_info (seg)->frchainP; fr; fr = fr->frch_next)
220e750f 805 if (fr->frch_last == frag)
c5c0a210 806 return (char *) obstack_next_free (&fr->frch_obstack) - frag->fr_literal;
220e750f
RH
807
808 abort ();
809}
fac0d250 810
220e750f 811/* Set an absolute address (may result in a relocation entry). */
fac0d250 812
220e750f 813static void
07a53e5c 814out_set_addr (symbolS *sym)
220e750f 815{
91d6fa6a 816 expressionS exp;
9e3af0e7 817
fac0d250 818 out_opcode (DW_LNS_extended_op);
220e750f 819 out_uleb128 (sizeof_address + 1);
fac0d250
RH
820
821 out_opcode (DW_LNE_set_address);
91d6fa6a
NC
822 exp.X_op = O_symbol;
823 exp.X_add_symbol = sym;
824 exp.X_add_number = 0;
825 emit_expr (&exp, sizeof_address);
fac0d250
RH
826}
827
a3b75434 828#if DWARF2_LINE_MIN_INSN_LENGTH > 1
a2e22468 829static void scale_addr_delta (addressT *);
c8970b4b 830
a3b75434 831static void
d7342424 832scale_addr_delta (addressT *addr_delta)
a3b75434
DD
833{
834 static int printed_this = 0;
835 if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0)
836 {
837 if (!printed_this)
838 as_bad("unaligned opcodes detected in executable segment");
839 printed_this = 1;
840 }
841 *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH;
842}
843#else
844#define scale_addr_delta(A)
845#endif
846
220e750f
RH
847/* Encode a pair of line and address skips as efficiently as possible.
848 Note that the line skip is signed, whereas the address skip is unsigned.
353e2c69 849
220e750f
RH
850 The following two routines *must* be kept in sync. This is
851 enforced by making emit_inc_line_addr abort if we do not emit
852 exactly the expected number of bytes. */
853
854static int
a2e22468 855size_inc_line_addr (int line_delta, addressT addr_delta)
fac0d250 856{
220e750f
RH
857 unsigned int tmp, opcode;
858 int len = 0;
fac0d250 859
220e750f 860 /* Scale the address delta by the minimum instruction length. */
a3b75434 861 scale_addr_delta (&addr_delta);
220e750f
RH
862
863 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
864 We cannot use special opcodes here, since we want the end_sequence
865 to emit the matrix entry. */
866 if (line_delta == INT_MAX)
fac0d250 867 {
220e750f
RH
868 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
869 len = 1;
fac0d250 870 else
220e750f
RH
871 len = 1 + sizeof_leb128 (addr_delta, 0);
872 return len + 3;
fac0d250 873 }
fac0d250 874
220e750f
RH
875 /* Bias the line delta by the base. */
876 tmp = line_delta - DWARF2_LINE_BASE;
fac0d250 877
220e750f
RH
878 /* If the line increment is out of range of a special opcode, we
879 must encode it with DW_LNS_advance_line. */
880 if (tmp >= DWARF2_LINE_RANGE)
881 {
882 len = 1 + sizeof_leb128 (line_delta, 1);
883 line_delta = 0;
884 tmp = 0 - DWARF2_LINE_BASE;
885 }
fac0d250 886
220e750f
RH
887 /* Bias the opcode by the special opcode base. */
888 tmp += DWARF2_LINE_OPCODE_BASE;
353e2c69 889
220e750f
RH
890 /* Avoid overflow when addr_delta is large. */
891 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
892 {
893 /* Try using a special opcode. */
894 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
895 if (opcode <= 255)
896 return len + 1;
897
898 /* Try using DW_LNS_const_add_pc followed by special op. */
899 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
900 if (opcode <= 255)
901 return len + 2;
902 }
903
904 /* Otherwise use DW_LNS_advance_pc. */
905 len += 1 + sizeof_leb128 (addr_delta, 0);
906
907 /* DW_LNS_copy or special opcode. */
908 len += 1;
909
910 return len;
911}
fac0d250 912
220e750f 913static void
a2e22468 914emit_inc_line_addr (int line_delta, addressT addr_delta, char *p, int len)
220e750f
RH
915{
916 unsigned int tmp, opcode;
917 int need_copy = 0;
918 char *end = p + len;
fac0d250 919
07a53e5c
RH
920 /* Line number sequences cannot go backward in addresses. This means
921 we've incorrectly ordered the statements in the sequence. */
9c2799c2 922 gas_assert ((offsetT) addr_delta >= 0);
07a53e5c 923
220e750f 924 /* Scale the address delta by the minimum instruction length. */
a3b75434
DD
925 scale_addr_delta (&addr_delta);
926
220e750f
RH
927 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
928 We cannot use special opcodes here, since we want the end_sequence
929 to emit the matrix entry. */
930 if (line_delta == INT_MAX)
fac0d250 931 {
220e750f
RH
932 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
933 *p++ = DW_LNS_const_add_pc;
934 else
fac0d250 935 {
220e750f
RH
936 *p++ = DW_LNS_advance_pc;
937 p += output_leb128 (p, addr_delta, 0);
fac0d250 938 }
220e750f
RH
939
940 *p++ = DW_LNS_extended_op;
941 *p++ = 1;
942 *p++ = DW_LNE_end_sequence;
943 goto done;
fac0d250
RH
944 }
945
220e750f
RH
946 /* Bias the line delta by the base. */
947 tmp = line_delta - DWARF2_LINE_BASE;
948
949 /* If the line increment is out of range of a special opcode, we
950 must encode it with DW_LNS_advance_line. */
951 if (tmp >= DWARF2_LINE_RANGE)
fac0d250 952 {
220e750f
RH
953 *p++ = DW_LNS_advance_line;
954 p += output_leb128 (p, line_delta, 1);
fac0d250 955
220e750f
RH
956 line_delta = 0;
957 tmp = 0 - DWARF2_LINE_BASE;
958 need_copy = 1;
959 }
fac0d250 960
bd0eb99b
RH
961 /* Prettier, I think, to use DW_LNS_copy instead of a "line +0, addr +0"
962 special opcode. */
963 if (line_delta == 0 && addr_delta == 0)
964 {
965 *p++ = DW_LNS_copy;
966 goto done;
967 }
968
220e750f
RH
969 /* Bias the opcode by the special opcode base. */
970 tmp += DWARF2_LINE_OPCODE_BASE;
fac0d250 971
220e750f
RH
972 /* Avoid overflow when addr_delta is large. */
973 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
fac0d250 974 {
220e750f
RH
975 /* Try using a special opcode. */
976 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
977 if (opcode <= 255)
978 {
979 *p++ = opcode;
980 goto done;
981 }
982
983 /* Try using DW_LNS_const_add_pc followed by special op. */
984 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
985 if (opcode <= 255)
fac0d250 986 {
220e750f
RH
987 *p++ = DW_LNS_const_add_pc;
988 *p++ = opcode;
989 goto done;
fac0d250
RH
990 }
991 }
220e750f
RH
992
993 /* Otherwise use DW_LNS_advance_pc. */
994 *p++ = DW_LNS_advance_pc;
995 p += output_leb128 (p, addr_delta, 0);
996
997 if (need_copy)
998 *p++ = DW_LNS_copy;
fac0d250 999 else
220e750f 1000 *p++ = tmp;
fac0d250 1001
220e750f 1002 done:
9c2799c2 1003 gas_assert (p == end);
220e750f 1004}
a8316fe2 1005
220e750f 1006/* Handy routine to combine calls to the above two routines. */
e1c05f12 1007
220e750f 1008static void
a2e22468 1009out_inc_line_addr (int line_delta, addressT addr_delta)
220e750f
RH
1010{
1011 int len = size_inc_line_addr (line_delta, addr_delta);
1012 emit_inc_line_addr (line_delta, addr_delta, frag_more (len), len);
1013}
9de8d8f1 1014
1737851b
BW
1015/* Write out an alternative form of line and address skips using
1016 DW_LNS_fixed_advance_pc opcodes. This uses more space than the default
7ddd14de
BW
1017 line and address information, but it is required if linker relaxation
1018 could change the code offsets. The following two routines *must* be
1019 kept in sync. */
1737851b 1020
7ddd14de
BW
1021static int
1022size_fixed_inc_line_addr (int line_delta, addressT addr_delta)
1737851b 1023{
7ddd14de 1024 int len = 0;
1737851b
BW
1025
1026 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. */
7ddd14de
BW
1027 if (line_delta != INT_MAX)
1028 len = 1 + sizeof_leb128 (line_delta, 1);
1029
1030 if (addr_delta > 50000)
1031 {
1032 /* DW_LNS_extended_op */
1033 len += 1 + sizeof_leb128 (sizeof_address + 1, 0);
1034 /* DW_LNE_set_address */
1035 len += 1 + sizeof_address;
1036 }
1037 else
1038 /* DW_LNS_fixed_advance_pc */
1039 len += 3;
1040
1737851b 1041 if (line_delta == INT_MAX)
7ddd14de
BW
1042 /* DW_LNS_extended_op + DW_LNE_end_sequence */
1043 len += 3;
1044 else
1045 /* DW_LNS_copy */
1046 len += 1;
1047
1048 return len;
1049}
1050
1051static void
1052emit_fixed_inc_line_addr (int line_delta, addressT addr_delta, fragS *frag,
1053 char *p, int len)
1054{
91d6fa6a 1055 expressionS *pexp;
7ddd14de
BW
1056 segT line_seg;
1057 char *end = p + len;
1058
1059 /* Line number sequences cannot go backward in addresses. This means
1060 we've incorrectly ordered the statements in the sequence. */
9c2799c2 1061 gas_assert ((offsetT) addr_delta >= 0);
7ddd14de
BW
1062
1063 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. */
1064 if (line_delta != INT_MAX)
1065 {
1066 *p++ = DW_LNS_advance_line;
1067 p += output_leb128 (p, line_delta, 1);
1068 }
1069
91d6fa6a 1070 pexp = symbol_get_value_expression (frag->fr_symbol);
7ddd14de
BW
1071 line_seg = subseg_get (".debug_line", 0);
1072
1073 /* The DW_LNS_fixed_advance_pc opcode has a 2-byte operand so it can
1074 advance the address by at most 64K. Linker relaxation (without
1075 which this function would not be used) could change the operand by
1076 an unknown amount. If the address increment is getting close to
1077 the limit, just reset the address. */
1078 if (addr_delta > 50000)
1737851b 1079 {
7ddd14de 1080 symbolS *to_sym;
91d6fa6a 1081 expressionS exp;
7ddd14de 1082
9f6db0d3 1083 gas_assert (pexp->X_op == O_subtract);
91d6fa6a 1084 to_sym = pexp->X_add_symbol;
7ddd14de
BW
1085
1086 *p++ = DW_LNS_extended_op;
1087 p += output_leb128 (p, sizeof_address + 1, 0);
1088 *p++ = DW_LNE_set_address;
91d6fa6a
NC
1089 exp.X_op = O_symbol;
1090 exp.X_add_symbol = to_sym;
1091 exp.X_add_number = 0;
7ddd14de 1092 subseg_change (line_seg, 0);
91d6fa6a 1093 emit_expr_fix (&exp, sizeof_address, frag, p);
7ddd14de
BW
1094 p += sizeof_address;
1095 }
1096 else
1097 {
1098 *p++ = DW_LNS_fixed_advance_pc;
1099 subseg_change (line_seg, 0);
91d6fa6a 1100 emit_expr_fix (pexp, 2, frag, p);
7ddd14de 1101 p += 2;
1737851b
BW
1102 }
1103
7ddd14de
BW
1104 if (line_delta == INT_MAX)
1105 {
1106 *p++ = DW_LNS_extended_op;
1107 *p++ = 1;
1108 *p++ = DW_LNE_end_sequence;
1109 }
1110 else
1111 *p++ = DW_LNS_copy;
1737851b 1112
9c2799c2 1113 gas_assert (p == end);
1737851b
BW
1114}
1115
220e750f
RH
1116/* Generate a variant frag that we can use to relax address/line
1117 increments between fragments of the target segment. */
9e3af0e7 1118
220e750f 1119static void
07a53e5c 1120relax_inc_line_addr (int line_delta, symbolS *to_sym, symbolS *from_sym)
220e750f 1121{
91d6fa6a 1122 expressionS exp;
220e750f 1123 int max_chars;
6576f0b5 1124
91d6fa6a
NC
1125 exp.X_op = O_subtract;
1126 exp.X_add_symbol = to_sym;
1127 exp.X_op_symbol = from_sym;
1128 exp.X_add_number = 0;
fac0d250 1129
220e750f
RH
1130 /* The maximum size of the frag is the line delta with a maximum
1131 sized address delta. */
7ddd14de
BW
1132 if (DWARF2_USE_FIXED_ADVANCE_PC)
1133 max_chars = size_fixed_inc_line_addr (line_delta,
1134 -DWARF2_LINE_MIN_INSN_LENGTH);
1135 else
1136 max_chars = size_inc_line_addr (line_delta, -DWARF2_LINE_MIN_INSN_LENGTH);
fac0d250 1137
220e750f 1138 frag_var (rs_dwarf2dbg, max_chars, max_chars, 1,
91d6fa6a 1139 make_expr_symbol (&exp), line_delta, NULL);
220e750f 1140}
fac0d250 1141
220e750f
RH
1142/* The function estimates the size of a rs_dwarf2dbg variant frag
1143 based on the current values of the symbols. It is called before
1144 the relaxation loop. We set fr_subtype to the expected length. */
fac0d250 1145
220e750f 1146int
a2e22468 1147dwarf2dbg_estimate_size_before_relax (fragS *frag)
220e750f
RH
1148{
1149 offsetT addr_delta;
1150 int size;
fac0d250 1151
6386f3a7 1152 addr_delta = resolve_symbol_value (frag->fr_symbol);
7ddd14de
BW
1153 if (DWARF2_USE_FIXED_ADVANCE_PC)
1154 size = size_fixed_inc_line_addr (frag->fr_offset, addr_delta);
1155 else
1156 size = size_inc_line_addr (frag->fr_offset, addr_delta);
fac0d250 1157
220e750f 1158 frag->fr_subtype = size;
fac0d250 1159
220e750f
RH
1160 return size;
1161}
1162
1163/* This function relaxes a rs_dwarf2dbg variant frag based on the
1164 current values of the symbols. fr_subtype is the current length
1165 of the frag. This returns the change in frag length. */
1166
1167int
a2e22468 1168dwarf2dbg_relax_frag (fragS *frag)
220e750f
RH
1169{
1170 int old_size, new_size;
fac0d250 1171
220e750f
RH
1172 old_size = frag->fr_subtype;
1173 new_size = dwarf2dbg_estimate_size_before_relax (frag);
ee515fb7 1174
220e750f 1175 return new_size - old_size;
fac0d250
RH
1176}
1177
220e750f
RH
1178/* This function converts a rs_dwarf2dbg variant frag into a normal
1179 fill frag. This is called after all relaxation has been done.
1180 fr_subtype will be the desired length of the frag. */
1181
1182void
a2e22468 1183dwarf2dbg_convert_frag (fragS *frag)
fac0d250 1184{
220e750f
RH
1185 offsetT addr_diff;
1186
6386f3a7 1187 addr_diff = resolve_symbol_value (frag->fr_symbol);
fac0d250 1188
220e750f
RH
1189 /* fr_var carries the max_chars that we created the fragment with.
1190 fr_subtype carries the current expected length. We must, of
1191 course, have allocated enough memory earlier. */
9c2799c2 1192 gas_assert (frag->fr_var >= (int) frag->fr_subtype);
fac0d250 1193
7ddd14de
BW
1194 if (DWARF2_USE_FIXED_ADVANCE_PC)
1195 emit_fixed_inc_line_addr (frag->fr_offset, addr_diff, frag,
1196 frag->fr_literal + frag->fr_fix,
1197 frag->fr_subtype);
1198 else
1199 emit_inc_line_addr (frag->fr_offset, addr_diff,
1200 frag->fr_literal + frag->fr_fix, frag->fr_subtype);
220e750f
RH
1201
1202 frag->fr_fix += frag->fr_subtype;
1203 frag->fr_type = rs_fill;
1204 frag->fr_var = 0;
1205 frag->fr_offset = 0;
1206}
1207
1208/* Generate .debug_line content for the chain of line number entries
1209 beginning at E, for segment SEG. */
1210
1211static void
a2e22468 1212process_entries (segT seg, struct line_entry *e)
220e750f
RH
1213{
1214 unsigned filenum = 1;
1215 unsigned line = 1;
1216 unsigned column = 0;
bd0eb99b
RH
1217 unsigned isa = 0;
1218 unsigned flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;
07a53e5c
RH
1219 fragS *last_frag = NULL, *frag;
1220 addressT last_frag_ofs = 0, frag_ofs;
fead5cd9 1221 symbolS *last_lab = NULL, *lab;
220e750f
RH
1222 struct line_entry *next;
1223
fead5cd9 1224 do
fac0d250 1225 {
07a53e5c 1226 int line_delta;
220e750f
RH
1227
1228 if (filenum != e->loc.filenum)
fac0d250 1229 {
220e750f
RH
1230 filenum = e->loc.filenum;
1231 out_opcode (DW_LNS_set_file);
1232 out_uleb128 (filenum);
220e750f
RH
1233 }
1234
1235 if (column != e->loc.column)
1236 {
1237 column = e->loc.column;
1238 out_opcode (DW_LNS_set_column);
1239 out_uleb128 (column);
220e750f
RH
1240 }
1241
92846e72
CC
1242 if (e->loc.discriminator != 0)
1243 {
1244 out_opcode (DW_LNS_extended_op);
1245 out_leb128 (1 + sizeof_leb128 (e->loc.discriminator, 0));
1246 out_opcode (DW_LNE_set_discriminator);
1247 out_uleb128 (e->loc.discriminator);
1248 }
1249
bd0eb99b
RH
1250 if (isa != e->loc.isa)
1251 {
1252 isa = e->loc.isa;
1253 out_opcode (DW_LNS_set_isa);
1254 out_uleb128 (isa);
bd0eb99b
RH
1255 }
1256
1257 if ((e->loc.flags ^ flags) & DWARF2_FLAG_IS_STMT)
220e750f
RH
1258 {
1259 flags = e->loc.flags;
1260 out_opcode (DW_LNS_negate_stmt);
220e750f
RH
1261 }
1262
bd0eb99b 1263 if (e->loc.flags & DWARF2_FLAG_BASIC_BLOCK)
07a53e5c 1264 out_opcode (DW_LNS_set_basic_block);
220e750f 1265
bd0eb99b 1266 if (e->loc.flags & DWARF2_FLAG_PROLOGUE_END)
07a53e5c 1267 out_opcode (DW_LNS_set_prologue_end);
bd0eb99b
RH
1268
1269 if (e->loc.flags & DWARF2_FLAG_EPILOGUE_BEGIN)
07a53e5c 1270 out_opcode (DW_LNS_set_epilogue_begin);
bd0eb99b 1271
fb81275c
JM
1272 /* Don't try to optimize away redundant entries; gdb wants two
1273 entries for a function where the code starts on the same line as
1274 the {, and there's no way to identify that case here. Trust gcc
1275 to optimize appropriately. */
07a53e5c
RH
1276 line_delta = e->loc.line - line;
1277 lab = e->label;
1278 frag = symbol_get_frag (lab);
1279 frag_ofs = S_GET_VALUE (lab);
220e750f 1280
07a53e5c 1281 if (last_frag == NULL)
220e750f 1282 {
07a53e5c
RH
1283 out_set_addr (lab);
1284 out_inc_line_addr (line_delta, 0);
220e750f 1285 }
7ddd14de 1286 else if (frag == last_frag && ! DWARF2_USE_FIXED_ADVANCE_PC)
07a53e5c
RH
1287 out_inc_line_addr (line_delta, frag_ofs - last_frag_ofs);
1288 else
1289 relax_inc_line_addr (line_delta, lab, last_lab);
1290
1291 line = e->loc.line;
1292 last_lab = lab;
1293 last_frag = frag;
1294 last_frag_ofs = frag_ofs;
220e750f
RH
1295
1296 next = e->next;
1297 free (e);
1298 e = next;
fac0d250 1299 }
fead5cd9 1300 while (e);
353e2c69 1301
220e750f 1302 /* Emit a DW_LNE_end_sequence for the end of the section. */
07a53e5c 1303 frag = last_frag_for_seg (seg);
c9049d30 1304 frag_ofs = get_frag_fix (frag, seg);
7ddd14de 1305 if (frag == last_frag && ! DWARF2_USE_FIXED_ADVANCE_PC)
07a53e5c 1306 out_inc_line_addr (INT_MAX, frag_ofs - last_frag_ofs);
220e750f 1307 else
07a53e5c
RH
1308 {
1309 lab = symbol_temp_new (seg, frag_ofs, frag);
1310 relax_inc_line_addr (INT_MAX, lab, last_lab);
1311 }
fac0d250
RH
1312}
1313
220e750f
RH
1314/* Emit the directory and file tables for .debug_line. */
1315
fac0d250 1316static void
a2e22468 1317out_file_list (void)
fac0d250
RH
1318{
1319 size_t size;
3d6b762c 1320 const char *dir;
fac0d250 1321 char *cp;
220e750f
RH
1322 unsigned int i;
1323
a7ed1ca2
NC
1324 /* Emit directory list. */
1325 for (i = 1; i < dirs_in_use; ++i)
1326 {
3d6b762c
JM
1327 dir = remap_debug_filename (dirs[i]);
1328 size = strlen (dir) + 1;
a7ed1ca2 1329 cp = frag_more (size);
3d6b762c 1330 memcpy (cp, dir, size);
a7ed1ca2
NC
1331 }
1332 /* Terminate it. */
220e750f 1333 out_byte ('\0');
fac0d250 1334
220e750f 1335 for (i = 1; i < files_in_use; ++i)
fac0d250 1336 {
01e1a5bc
NC
1337 const char *fullfilename;
1338
249e3833
RH
1339 if (files[i].filename == NULL)
1340 {
0e389e77 1341 as_bad (_("unassigned file number %ld"), (long) i);
88b4ca40
RH
1342 /* Prevent a crash later, particularly for file 1. */
1343 files[i].filename = "";
249e3833
RH
1344 continue;
1345 }
1346
01e1a5bc
NC
1347 fullfilename = DWARF2_FILE_NAME (files[i].filename,
1348 files[i].dir ? dirs [files [i].dir] : "");
1349 size = strlen (fullfilename) + 1;
fac0d250 1350 cp = frag_more (size);
01e1a5bc 1351 memcpy (cp, fullfilename, size);
fac0d250 1352
220e750f 1353 out_uleb128 (files[i].dir); /* directory number */
01e1a5bc
NC
1354 /* Output the last modification timestamp. */
1355 out_uleb128 (DWARF2_FILE_TIME_NAME (files[i].filename,
1356 files[i].dir ? dirs [files [i].dir] : ""));
1357 /* Output the filesize. */
1358 out_uleb128 (DWARF2_FILE_SIZE_NAME (files[i].filename,
1359 files[i].dir ? dirs [files [i].dir] : ""));
fac0d250 1360 }
353e2c69
KH
1361
1362 /* Terminate filename list. */
1363 out_byte (0);
fac0d250
RH
1364}
1365
413a266c
AM
1366/* Switch to SEC and output a header length field. Return the size of
1367 offsets used in SEC. The caller must set EXPR->X_add_symbol value
1368 to the end of the section. */
1369
1370static int
91d6fa6a 1371out_header (asection *sec, expressionS *exp)
413a266c
AM
1372{
1373 symbolS *start_sym;
1374 symbolS *end_sym;
1375
1376 subseg_set (sec, 0);
1377 start_sym = symbol_temp_new_now ();;
1378 end_sym = symbol_temp_make ();
1379
1380 /* Total length of the information. */
91d6fa6a
NC
1381 exp->X_op = O_subtract;
1382 exp->X_add_symbol = end_sym;
1383 exp->X_op_symbol = start_sym;
413a266c
AM
1384
1385 switch (DWARF2_FORMAT (sec))
1386 {
1387 case dwarf2_format_32bit:
91d6fa6a
NC
1388 exp->X_add_number = -4;
1389 emit_expr (exp, 4);
413a266c
AM
1390 return 4;
1391
1392 case dwarf2_format_64bit:
91d6fa6a 1393 exp->X_add_number = -12;
413a266c 1394 out_four (-1);
91d6fa6a 1395 emit_expr (exp, 8);
413a266c
AM
1396 return 8;
1397
1398 case dwarf2_format_64bit_irix:
91d6fa6a
NC
1399 exp->X_add_number = -8;
1400 emit_expr (exp, 8);
413a266c
AM
1401 return 8;
1402 }
1403
1404 as_fatal (_("internal error: unknown dwarf2 format"));
1405 return 0;
1406}
1407
220e750f
RH
1408/* Emit the collected .debug_line data. */
1409
1410static void
a2e22468 1411out_debug_line (segT line_seg)
220e750f 1412{
91d6fa6a 1413 expressionS exp;
220e750f
RH
1414 symbolS *prologue_end;
1415 symbolS *line_end;
1416 struct line_seg *s;
14e777e0 1417 int sizeof_offset;
220e750f 1418
91d6fa6a
NC
1419 sizeof_offset = out_header (line_seg, &exp);
1420 line_end = exp.X_add_symbol;
220e750f
RH
1421
1422 /* Version. */
1423 out_two (2);
1424
1425 /* Length of the prologue following this length. */
413a266c 1426 prologue_end = symbol_temp_make ();
91d6fa6a
NC
1427 exp.X_add_symbol = prologue_end;
1428 exp.X_add_number = - (4 + 2 + 4);
1429 emit_expr (&exp, sizeof_offset);
220e750f
RH
1430
1431 /* Parameters of the state machine. */
1432 out_byte (DWARF2_LINE_MIN_INSN_LENGTH);
1433 out_byte (DWARF2_LINE_DEFAULT_IS_STMT);
1434 out_byte (DWARF2_LINE_BASE);
1435 out_byte (DWARF2_LINE_RANGE);
1436 out_byte (DWARF2_LINE_OPCODE_BASE);
1437
1438 /* Standard opcode lengths. */
1439 out_byte (0); /* DW_LNS_copy */
1440 out_byte (1); /* DW_LNS_advance_pc */
1441 out_byte (1); /* DW_LNS_advance_line */
1442 out_byte (1); /* DW_LNS_set_file */
1443 out_byte (1); /* DW_LNS_set_column */
1444 out_byte (0); /* DW_LNS_negate_stmt */
1445 out_byte (0); /* DW_LNS_set_basic_block */
1446 out_byte (0); /* DW_LNS_const_add_pc */
1447 out_byte (1); /* DW_LNS_fixed_advance_pc */
bd0eb99b
RH
1448 out_byte (0); /* DW_LNS_set_prologue_end */
1449 out_byte (0); /* DW_LNS_set_epilogue_begin */
1450 out_byte (1); /* DW_LNS_set_isa */
220e750f
RH
1451
1452 out_file_list ();
1453
b7d6ed97 1454 symbol_set_value_now (prologue_end);
220e750f
RH
1455
1456 /* For each section, emit a statement program. */
ee515fb7 1457 for (s = all_segs; s; s = s->next)
220e750f
RH
1458 process_entries (s->seg, s->head->head);
1459
b7d6ed97 1460 symbol_set_value_now (line_end);
220e750f
RH
1461}
1462
802f5d9e
NC
1463static void
1464out_debug_ranges (segT ranges_seg)
1465{
1466 unsigned int addr_size = sizeof_address;
1467 struct line_seg *s;
91d6fa6a 1468 expressionS exp;
802f5d9e
NC
1469 unsigned int i;
1470
1471 subseg_set (ranges_seg, 0);
1472
1473 /* Base Address Entry. */
7fd3924a 1474 for (i = 0; i < addr_size; i++)
802f5d9e 1475 out_byte (0xff);
7fd3924a 1476 for (i = 0; i < addr_size; i++)
802f5d9e
NC
1477 out_byte (0);
1478
1479 /* Range List Entry. */
1480 for (s = all_segs; s; s = s->next)
1481 {
1482 fragS *frag;
1483 symbolS *beg, *end;
1484
1485 frag = first_frag_for_seg (s->seg);
1486 beg = symbol_temp_new (s->seg, 0, frag);
1487 s->text_start = beg;
1488
1489 frag = last_frag_for_seg (s->seg);
1490 end = symbol_temp_new (s->seg, get_frag_fix (frag, s->seg), frag);
1491 s->text_end = end;
1492
91d6fa6a
NC
1493 exp.X_op = O_symbol;
1494 exp.X_add_symbol = beg;
1495 exp.X_add_number = 0;
1496 emit_expr (&exp, addr_size);
802f5d9e 1497
91d6fa6a
NC
1498 exp.X_op = O_symbol;
1499 exp.X_add_symbol = end;
1500 exp.X_add_number = 0;
1501 emit_expr (&exp, addr_size);
802f5d9e
NC
1502 }
1503
1504 /* End of Range Entry. */
7fd3924a 1505 for (i = 0; i < addr_size; i++)
802f5d9e 1506 out_byte (0);
7fd3924a 1507 for (i = 0; i < addr_size; i++)
802f5d9e
NC
1508 out_byte (0);
1509}
1510
220e750f
RH
1511/* Emit data for .debug_aranges. */
1512
58b5739a 1513static void
a2e22468 1514out_debug_aranges (segT aranges_seg, segT info_seg)
fac0d250 1515{
220e750f 1516 unsigned int addr_size = sizeof_address;
220e750f 1517 struct line_seg *s;
91d6fa6a 1518 expressionS exp;
413a266c 1519 symbolS *aranges_end;
220e750f 1520 char *p;
413a266c 1521 int sizeof_offset;
fac0d250 1522
91d6fa6a
NC
1523 sizeof_offset = out_header (aranges_seg, &exp);
1524 aranges_end = exp.X_add_symbol;
fac0d250 1525
220e750f
RH
1526 /* Version. */
1527 out_two (2);
4dc7ead9 1528
220e750f 1529 /* Offset to .debug_info. */
413a266c 1530 TC_DWARF2_EMIT_OFFSET (section_symbol (info_seg), sizeof_offset);
220e750f
RH
1531
1532 /* Size of an address (offset portion). */
1533 out_byte (addr_size);
1534
1535 /* Size of a segment descriptor. */
1536 out_byte (0);
1537
1538 /* Align the header. */
413a266c 1539 frag_align (ffs (2 * addr_size) - 1, 0, 0);
4dc7ead9 1540
ee515fb7 1541 for (s = all_segs; s; s = s->next)
220e750f
RH
1542 {
1543 fragS *frag;
1544 symbolS *beg, *end;
1545
1546 frag = first_frag_for_seg (s->seg);
b7d6ed97 1547 beg = symbol_temp_new (s->seg, 0, frag);
220e750f
RH
1548 s->text_start = beg;
1549
1550 frag = last_frag_for_seg (s->seg);
c9049d30 1551 end = symbol_temp_new (s->seg, get_frag_fix (frag, s->seg), frag);
220e750f
RH
1552 s->text_end = end;
1553
91d6fa6a
NC
1554 exp.X_op = O_symbol;
1555 exp.X_add_symbol = beg;
1556 exp.X_add_number = 0;
1557 emit_expr (&exp, addr_size);
220e750f 1558
91d6fa6a
NC
1559 exp.X_op = O_subtract;
1560 exp.X_add_symbol = end;
1561 exp.X_op_symbol = beg;
1562 exp.X_add_number = 0;
1563 emit_expr (&exp, addr_size);
220e750f 1564 }
4dc7ead9 1565
220e750f
RH
1566 p = frag_more (2 * addr_size);
1567 md_number_to_chars (p, 0, addr_size);
1568 md_number_to_chars (p + addr_size, 0, addr_size);
413a266c
AM
1569
1570 symbol_set_value_now (aranges_end);
4dc7ead9
RH
1571}
1572
220e750f
RH
1573/* Emit data for .debug_abbrev. Note that this must be kept in
1574 sync with out_debug_info below. */
fac0d250 1575
220e750f 1576static void
413a266c
AM
1577out_debug_abbrev (segT abbrev_seg,
1578 segT info_seg ATTRIBUTE_UNUSED,
1579 segT line_seg ATTRIBUTE_UNUSED)
220e750f
RH
1580{
1581 subseg_set (abbrev_seg, 0);
fac0d250 1582
220e750f
RH
1583 out_uleb128 (1);
1584 out_uleb128 (DW_TAG_compile_unit);
1585 out_byte (DW_CHILDREN_no);
413a266c
AM
1586 if (DWARF2_FORMAT (line_seg) == dwarf2_format_32bit)
1587 out_abbrev (DW_AT_stmt_list, DW_FORM_data4);
1588 else
1589 out_abbrev (DW_AT_stmt_list, DW_FORM_data8);
220e750f 1590 if (all_segs->next == NULL)
4dc7ead9 1591 {
220e750f
RH
1592 out_abbrev (DW_AT_low_pc, DW_FORM_addr);
1593 out_abbrev (DW_AT_high_pc, DW_FORM_addr);
1594 }
802f5d9e
NC
1595 else
1596 {
413a266c 1597 if (DWARF2_FORMAT (info_seg) == dwarf2_format_32bit)
802f5d9e
NC
1598 out_abbrev (DW_AT_ranges, DW_FORM_data4);
1599 else
1600 out_abbrev (DW_AT_ranges, DW_FORM_data8);
1601 }
48b91938 1602 out_abbrev (DW_AT_name, DW_FORM_string);
220e750f
RH
1603 out_abbrev (DW_AT_comp_dir, DW_FORM_string);
1604 out_abbrev (DW_AT_producer, DW_FORM_string);
1605 out_abbrev (DW_AT_language, DW_FORM_data2);
1606 out_abbrev (0, 0);
a987bfc9
RH
1607
1608 /* Terminate the abbreviations for this compilation unit. */
1609 out_byte (0);
220e750f 1610}
4dc7ead9 1611
220e750f 1612/* Emit a description of this compilation unit for .debug_info. */
4dc7ead9 1613
220e750f 1614static void
802f5d9e 1615out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg)
220e750f
RH
1616{
1617 char producer[128];
3d6b762c
JM
1618 const char *comp_dir;
1619 const char *dirname;
91d6fa6a 1620 expressionS exp;
220e750f
RH
1621 symbolS *info_end;
1622 char *p;
1623 int len;
14e777e0 1624 int sizeof_offset;
4dc7ead9 1625
91d6fa6a
NC
1626 sizeof_offset = out_header (info_seg, &exp);
1627 info_end = exp.X_add_symbol;
4dc7ead9 1628
220e750f
RH
1629 /* DWARF version. */
1630 out_two (2);
4dc7ead9 1631
220e750f 1632 /* .debug_abbrev offset */
6174d9c8 1633 TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset);
4dc7ead9 1634
220e750f
RH
1635 /* Target address size. */
1636 out_byte (sizeof_address);
fac0d250 1637
220e750f
RH
1638 /* DW_TAG_compile_unit DIE abbrev */
1639 out_uleb128 (1);
fac0d250 1640
220e750f 1641 /* DW_AT_stmt_list */
413a266c
AM
1642 TC_DWARF2_EMIT_OFFSET (section_symbol (line_seg),
1643 (DWARF2_FORMAT (line_seg) == dwarf2_format_32bit
1644 ? 4 : 8));
fac0d250 1645
802f5d9e 1646 /* These two attributes are emitted if all of the code is contiguous. */
220e750f 1647 if (all_segs->next == NULL)
58b5739a 1648 {
220e750f 1649 /* DW_AT_low_pc */
91d6fa6a
NC
1650 exp.X_op = O_symbol;
1651 exp.X_add_symbol = all_segs->text_start;
1652 exp.X_add_number = 0;
1653 emit_expr (&exp, sizeof_address);
220e750f
RH
1654
1655 /* DW_AT_high_pc */
91d6fa6a
NC
1656 exp.X_op = O_symbol;
1657 exp.X_add_symbol = all_segs->text_end;
1658 exp.X_add_number = 0;
1659 emit_expr (&exp, sizeof_address);
58b5739a 1660 }
802f5d9e
NC
1661 else
1662 {
eb1fe072
NC
1663 /* This attribute is emitted if the code is disjoint. */
1664 /* DW_AT_ranges. */
1665 TC_DWARF2_EMIT_OFFSET (section_symbol (ranges_seg), sizeof_offset);
802f5d9e 1666 }
58b5739a 1667
48b91938
RH
1668 /* DW_AT_name. We don't have the actual file name that was present
1669 on the command line, so assume files[1] is the main input file.
1670 We're not supposed to get called unless at least one line number
1671 entry was emitted, so this should always be defined. */
7fd3924a 1672 if (files_in_use == 0)
48b91938 1673 abort ();
a7ed1ca2
NC
1674 if (files[1].dir)
1675 {
3d6b762c
JM
1676 dirname = remap_debug_filename (dirs[files[1].dir]);
1677 len = strlen (dirname);
198f1251
TG
1678#ifdef TE_VMS
1679 /* Already has trailing slash. */
1680 p = frag_more (len);
1681 memcpy (p, dirname, len);
1682#else
a7ed1ca2 1683 p = frag_more (len + 1);
3d6b762c 1684 memcpy (p, dirname, len);
56487c55 1685 INSERT_DIR_SEPARATOR (p, len);
198f1251 1686#endif
a7ed1ca2 1687 }
48b91938
RH
1688 len = strlen (files[1].filename) + 1;
1689 p = frag_more (len);
1690 memcpy (p, files[1].filename, len);
1691
220e750f 1692 /* DW_AT_comp_dir */
3d6b762c 1693 comp_dir = remap_debug_filename (getpwd ());
220e750f
RH
1694 len = strlen (comp_dir) + 1;
1695 p = frag_more (len);
1696 memcpy (p, comp_dir, len);
fac0d250 1697
220e750f
RH
1698 /* DW_AT_producer */
1699 sprintf (producer, "GNU AS %s", VERSION);
1700 len = strlen (producer) + 1;
1701 p = frag_more (len);
1702 memcpy (p, producer, len);
fac0d250 1703
220e750f
RH
1704 /* DW_AT_language. Yes, this is probably not really MIPS, but the
1705 dwarf2 draft has no standard code for assembler. */
1706 out_two (DW_LANG_Mips_Assembler);
1707
b7d6ed97 1708 symbol_set_value_now (info_end);
fac0d250
RH
1709}
1710
1e9cc1c2
NC
1711void
1712dwarf2_init (void)
1713{
1714 all_segs_hash = hash_new ();
1715 last_seg_ptr = &all_segs;
1716}
1717
1718
c6cb92c5
NS
1719/* Finish the dwarf2 debug sections. We emit .debug.line if there
1720 were any .file/.loc directives, or --gdwarf2 was given, or if the
df1c40a7
L
1721 file has a non-empty .debug_info section and an empty .debug_line
1722 section. If we emit .debug_line, and the .debug_info section is
1723 empty, we also emit .debug_info, .debug_aranges and .debug_abbrev.
1724 ALL_SEGS will be non-null if there were any .file/.loc directives,
1725 or --gdwarf2 was given and there were any located instructions
1726 emitted. */
c6cb92c5 1727
fac0d250 1728void
a2e22468 1729dwarf2_finish (void)
fac0d250 1730{
220e750f
RH
1731 segT line_seg;
1732 struct line_seg *s;
c6cb92c5
NS
1733 segT info_seg;
1734 int emit_other_sections = 0;
df1c40a7 1735 int empty_debug_line = 0;
c6cb92c5
NS
1736
1737 info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
1738 emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
fac0d250 1739
df1c40a7
L
1740 line_seg = bfd_get_section_by_name (stdoutput, ".debug_line");
1741 empty_debug_line = line_seg == NULL || !seg_not_empty_p (line_seg);
1742
1743 /* We can't construct a new debug_line section if we already have one.
1744 Give an error. */
1745 if (all_segs && !empty_debug_line)
1746 as_fatal ("duplicate .debug_line sections");
1747
1748 if ((!all_segs && emit_other_sections)
1749 || (!emit_other_sections && !empty_debug_line))
1750 /* If there is no line information and no non-empty .debug_info
1751 section, or if there is both a non-empty .debug_info and a non-empty
1752 .debug_line, then we do nothing. */
220e750f 1753 return;
fac0d250 1754
220e750f 1755 /* Calculate the size of an address for the target machine. */
9605f328 1756 sizeof_address = DWARF2_ADDR_SIZE (stdoutput);
fac0d250 1757
220e750f
RH
1758 /* Create and switch to the line number section. */
1759 line_seg = subseg_new (".debug_line", 0);
8a7140c3 1760 bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY | SEC_DEBUGGING);
fac0d250 1761
220e750f 1762 /* For each subsection, chain the debug entries together. */
ee515fb7 1763 for (s = all_segs; s; s = s->next)
fac0d250 1764 {
91d6fa6a
NC
1765 struct line_subseg *lss = s->head;
1766 struct line_entry **ptail = lss->ptail;
220e750f 1767
91d6fa6a 1768 while ((lss = lss->next) != NULL)
220e750f 1769 {
91d6fa6a
NC
1770 *ptail = lss->head;
1771 ptail = lss->ptail;
220e750f 1772 }
fac0d250 1773 }
85a39694 1774
220e750f 1775 out_debug_line (line_seg);
85a39694 1776
c6cb92c5
NS
1777 /* If this is assembler generated line info, and there is no
1778 debug_info already, we need .debug_info and .debug_abbrev
1779 sections as well. */
1780 if (emit_other_sections)
220e750f
RH
1781 {
1782 segT abbrev_seg;
220e750f 1783 segT aranges_seg;
802f5d9e 1784 segT ranges_seg;
4dc7ead9 1785
9c2799c2 1786 gas_assert (all_segs);
7fd3924a 1787
220e750f
RH
1788 info_seg = subseg_new (".debug_info", 0);
1789 abbrev_seg = subseg_new (".debug_abbrev", 0);
1790 aranges_seg = subseg_new (".debug_aranges", 0);
ef99799a 1791
8a7140c3
NC
1792 bfd_set_section_flags (stdoutput, info_seg,
1793 SEC_READONLY | SEC_DEBUGGING);
1794 bfd_set_section_flags (stdoutput, abbrev_seg,
1795 SEC_READONLY | SEC_DEBUGGING);
1796 bfd_set_section_flags (stdoutput, aranges_seg,
1797 SEC_READONLY | SEC_DEBUGGING);
ef99799a 1798
ee515fb7 1799 record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
ef99799a 1800
802f5d9e
NC
1801 if (all_segs->next == NULL)
1802 ranges_seg = NULL;
1803 else
1804 {
1805 ranges_seg = subseg_new (".debug_ranges", 0);
7fd3924a 1806 bfd_set_section_flags (stdoutput, ranges_seg,
802f5d9e
NC
1807 SEC_READONLY | SEC_DEBUGGING);
1808 record_alignment (ranges_seg, ffs (2 * sizeof_address) - 1);
1809 out_debug_ranges (ranges_seg);
1810 }
1811
220e750f 1812 out_debug_aranges (aranges_seg, info_seg);
413a266c 1813 out_debug_abbrev (abbrev_seg, info_seg, line_seg);
802f5d9e 1814 out_debug_info (info_seg, abbrev_seg, line_seg, ranges_seg);
220e750f 1815 }
85a39694 1816}
This page took 0.621823 seconds and 4 git commands to generate.