* read.c (pseudo_set): Set segment of expression syms to expr_section.
[binutils-gdb.git] / gas / dwarf2dbg.c
1 /* dwarf2dbg.c - DWARF2 debug support
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
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
10 the Free Software Foundation; either version 2, or (at your option)
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
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
22
23 /* Logical line numbers can be controlled by the compiler via the
24 following directives:
25
26 .file FILENO "file.c"
27 .loc FILENO LINENO [COLUMN] [basic_block] [prologue_end] \
28 [epilogue_begin] [is_stmt VALUE] [isa VALUE]
29 */
30
31 #include "ansidecl.h"
32 #include "as.h"
33 #include "safe-ctype.h"
34
35 #ifdef HAVE_LIMITS_H
36 #include <limits.h>
37 #else
38 #ifdef HAVE_SYS_PARAM_H
39 #include <sys/param.h>
40 #endif
41 #ifndef INT_MAX
42 #define INT_MAX (int) (((unsigned) (-1)) >> 1)
43 #endif
44 #endif
45
46 #include "dwarf2dbg.h"
47 #include <filenames.h>
48
49 #ifndef DWARF2_FORMAT
50 # define DWARF2_FORMAT() dwarf2_format_32bit
51 #endif
52
53 #ifndef DWARF2_ADDR_SIZE
54 # define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
55 #endif
56
57 #include "subsegs.h"
58
59 #include "elf/dwarf2.h"
60
61 /* Since we can't generate the prolog until the body is complete, we
62 use three different subsegments for .debug_line: one holding the
63 prolog, one for the directory and filename info, and one for the
64 body ("statement program"). */
65 #define DL_PROLOG 0
66 #define DL_FILES 1
67 #define DL_BODY 2
68
69 /* First special line opcde - leave room for the standard opcodes.
70 Note: If you want to change this, you'll have to update the
71 "standard_opcode_lengths" table that is emitted below in
72 out_debug_line(). */
73 #define DWARF2_LINE_OPCODE_BASE 13
74
75 #ifndef DWARF2_LINE_BASE
76 /* Minimum line offset in a special line info. opcode. This value
77 was chosen to give a reasonable range of values. */
78 # define DWARF2_LINE_BASE -5
79 #endif
80
81 /* Range of line offsets in a special line info. opcode. */
82 #ifndef DWARF2_LINE_RANGE
83 # define DWARF2_LINE_RANGE 14
84 #endif
85
86 #ifndef DWARF2_LINE_MIN_INSN_LENGTH
87 /* Define the architecture-dependent minimum instruction length (in
88 bytes). This value should be rather too small than too big. */
89 # define DWARF2_LINE_MIN_INSN_LENGTH 1
90 #endif
91
92 /* Flag that indicates the initial value of the is_stmt_start flag. */
93 #define DWARF2_LINE_DEFAULT_IS_STMT 1
94
95 /* Given a special op, return the line skip amount. */
96 #define SPECIAL_LINE(op) \
97 (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE)
98
99 /* Given a special op, return the address skip amount (in units of
100 DWARF2_LINE_MIN_INSN_LENGTH. */
101 #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
102
103 /* The maximum address skip amount that can be encoded with a special op. */
104 #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
105
106 struct line_entry {
107 struct line_entry *next;
108 fragS *frag;
109 addressT frag_ofs;
110 struct dwarf2_line_info loc;
111 };
112
113 struct line_subseg {
114 struct line_subseg *next;
115 subsegT subseg;
116 struct line_entry *head;
117 struct line_entry **ptail;
118 };
119
120 struct line_seg {
121 struct line_seg *next;
122 segT seg;
123 struct line_subseg *head;
124 symbolS *text_start;
125 symbolS *text_end;
126 };
127
128 /* Collects data for all line table entries during assembly. */
129 static struct line_seg *all_segs;
130
131 struct file_entry {
132 const char *filename;
133 unsigned int dir;
134 };
135
136 /* Table of files used by .debug_line. */
137 static struct file_entry *files;
138 static unsigned int files_in_use;
139 static unsigned int files_allocated;
140
141 /* Table of directories used by .debug_line. */
142 static char **dirs;
143 static unsigned int dirs_in_use;
144 static unsigned int dirs_allocated;
145
146 /* TRUE when we've seen a .loc directive recently. Used to avoid
147 doing work when there's nothing to do. */
148 static bfd_boolean loc_directive_seen;
149
150 /* Current location as indicated by the most recent .loc directive. */
151 static struct dwarf2_line_info current = {
152 1, 1, 0, 0,
153 DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0
154 };
155
156 /* The size of an address on the target. */
157 static unsigned int sizeof_address;
158 \f
159 static struct line_subseg *get_line_subseg (segT, subsegT);
160 static unsigned int get_filenum (const char *, unsigned int);
161 static struct frag *first_frag_for_seg (segT);
162 static struct frag *last_frag_for_seg (segT);
163 static void out_byte (int);
164 static void out_opcode (int);
165 static void out_two (int);
166 static void out_four (int);
167 static void out_abbrev (int, int);
168 static void out_uleb128 (addressT);
169 static offsetT get_frag_fix (fragS *);
170 static void out_set_addr (segT, fragS *, addressT);
171 static int size_inc_line_addr (int, addressT);
172 static void emit_inc_line_addr (int, addressT, char *, int);
173 static void out_inc_line_addr (int, addressT);
174 static void relax_inc_line_addr (int, segT, fragS *, addressT,
175 fragS *, addressT);
176 static void process_entries (segT, struct line_entry *);
177 static void out_file_list (void);
178 static void out_debug_line (segT);
179 static void out_debug_aranges (segT, segT);
180 static void out_debug_abbrev (segT);
181 static void out_debug_info (segT, segT, segT);
182 \f
183 #ifndef TC_DWARF2_EMIT_OFFSET
184 # define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
185 static void generic_dwarf2_emit_offset (symbolS *, unsigned int);
186
187 /* Create an offset to .dwarf2_*. */
188
189 static void
190 generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
191 {
192 expressionS expr;
193
194 expr.X_op = O_symbol;
195 expr.X_add_symbol = symbol;
196 expr.X_add_number = 0;
197 emit_expr (&expr, size);
198 }
199 #endif
200
201 /* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
202
203 static struct line_subseg *
204 get_line_subseg (segT seg, subsegT subseg)
205 {
206 static segT last_seg;
207 static subsegT last_subseg;
208 static struct line_subseg *last_line_subseg;
209
210 struct line_seg *s;
211 struct line_subseg **pss, *ss;
212
213 if (seg == last_seg && subseg == last_subseg)
214 return last_line_subseg;
215
216 for (s = all_segs; s; s = s->next)
217 if (s->seg == seg)
218 goto found_seg;
219
220 s = (struct line_seg *) xmalloc (sizeof (*s));
221 s->next = all_segs;
222 s->seg = seg;
223 s->head = NULL;
224 all_segs = s;
225
226 found_seg:
227 for (pss = &s->head; (ss = *pss) != NULL ; pss = &ss->next)
228 {
229 if (ss->subseg == subseg)
230 goto found_subseg;
231 if (ss->subseg > subseg)
232 break;
233 }
234
235 ss = (struct line_subseg *) xmalloc (sizeof (*ss));
236 ss->next = *pss;
237 ss->subseg = subseg;
238 ss->head = NULL;
239 ss->ptail = &ss->head;
240 *pss = ss;
241
242 found_subseg:
243 last_seg = seg;
244 last_subseg = subseg;
245 last_line_subseg = ss;
246
247 return ss;
248 }
249
250 /* Record an entry for LOC occurring at OFS within the current fragment. */
251
252 void
253 dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
254 {
255 struct line_subseg *ss;
256 struct line_entry *e;
257 static unsigned int line = -1;
258 static unsigned int filenum = -1;
259
260 /* Early out for as-yet incomplete location information. */
261 if (loc->filenum == 0 || loc->line == 0)
262 return;
263
264 /* Don't emit sequences of line symbols for the same line when the
265 symbols apply to assembler code. It is necessary to emit
266 duplicate line symbols when a compiler asks for them, because GDB
267 uses them to determine the end of the prologue. */
268 if (debug_type == DEBUG_DWARF2
269 && line == loc->line && filenum == loc->filenum)
270 return;
271
272 line = loc->line;
273 filenum = loc->filenum;
274
275 e = (struct line_entry *) xmalloc (sizeof (*e));
276 e->next = NULL;
277 e->frag = frag_now;
278 e->frag_ofs = ofs;
279 e->loc = *loc;
280
281 ss = get_line_subseg (now_seg, now_subseg);
282 *ss->ptail = e;
283 ss->ptail = &e->next;
284 }
285
286 /* Returns the current source information. If .file directives have
287 been encountered, the info for the corresponding source file is
288 returned. Otherwise, the info for the assembly source file is
289 returned. */
290
291 void
292 dwarf2_where (struct dwarf2_line_info *line)
293 {
294 if (debug_type == DEBUG_DWARF2)
295 {
296 char *filename;
297 as_where (&filename, &line->line);
298 line->filenum = get_filenum (filename, 0);
299 line->column = 0;
300 line->flags = DWARF2_FLAG_IS_STMT;
301 line->isa = current.isa;
302 }
303 else
304 *line = current;
305 }
306
307 /* A hook to allow the target backend to inform the line number state
308 machine of isa changes when assembler debug info is enabled. */
309
310 void
311 dwarf2_set_isa (unsigned int isa)
312 {
313 current.isa = isa;
314 }
315
316 /* Called for each machine instruction, or relatively atomic group of
317 machine instructions (ie built-in macro). The instruction or group
318 is SIZE bytes in length. If dwarf2 line number generation is called
319 for, emit a line statement appropriately. */
320
321 void
322 dwarf2_emit_insn (int size)
323 {
324 struct dwarf2_line_info loc;
325
326 if (loc_directive_seen)
327 {
328 /* Use the last location established by a .loc directive, not
329 the value returned by dwarf2_where(). That calls as_where()
330 which will return either the logical input file name (foo.c)
331 or the physical input file name (foo.s) and not the file name
332 specified in the most recent .loc directive (eg foo.h). */
333 loc = current;
334
335 /* Unless we generate DWARF2 debugging information for each
336 assembler line, we only emit one line symbol for one LOC. */
337 if (debug_type != DEBUG_DWARF2)
338 loc_directive_seen = FALSE;
339 }
340 else if (debug_type != DEBUG_DWARF2)
341 return;
342 else
343 dwarf2_where (&loc);
344
345 dwarf2_gen_line_info (frag_now_fix () - size, &loc);
346
347 current.flags &= ~(DWARF2_FLAG_BASIC_BLOCK
348 | DWARF2_FLAG_PROLOGUE_END
349 | DWARF2_FLAG_EPILOGUE_BEGIN);
350 }
351
352 /* Get a .debug_line file number for FILENAME. If NUM is nonzero,
353 allocate it on that file table slot, otherwise return the first
354 empty one. */
355
356 static unsigned int
357 get_filenum (const char *filename, unsigned int num)
358 {
359 static unsigned int last_used, last_used_dir_len;
360 const char *file;
361 size_t dir_len;
362 unsigned int i, dir;
363
364 if (num == 0 && last_used)
365 {
366 if (! files[last_used].dir
367 && strcmp (filename, files[last_used].filename) == 0)
368 return last_used;
369 if (files[last_used].dir
370 && strncmp (filename, dirs[files[last_used].dir],
371 last_used_dir_len) == 0
372 && IS_DIR_SEPARATOR (filename [last_used_dir_len])
373 && strcmp (filename + last_used_dir_len + 1,
374 files[last_used].filename) == 0)
375 return last_used;
376 }
377
378 file = lbasename (filename);
379 /* Don't make empty string from / or A: from A:/ . */
380 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
381 if (file <= filename + 3)
382 file = filename;
383 #else
384 if (file == filename + 1)
385 file = filename;
386 #endif
387 dir_len = file - filename;
388
389 dir = 0;
390 if (dir_len)
391 {
392 --dir_len;
393 for (dir = 1; dir < dirs_in_use; ++dir)
394 if (strncmp (filename, dirs[dir], dir_len) == 0
395 && dirs[dir][dir_len] == '\0')
396 break;
397
398 if (dir >= dirs_in_use)
399 {
400 if (dir >= dirs_allocated)
401 {
402 dirs_allocated = dir + 32;
403 dirs = (char **)
404 xrealloc (dirs, (dir + 32) * sizeof (const char *));
405 }
406
407 dirs[dir] = xmalloc (dir_len + 1);
408 memcpy (dirs[dir], filename, dir_len);
409 dirs[dir][dir_len] = '\0';
410 dirs_in_use = dir + 1;
411 }
412 }
413
414 if (num == 0)
415 {
416 for (i = 1; i < files_in_use; ++i)
417 if (files[i].dir == dir
418 && files[i].filename
419 && strcmp (file, files[i].filename) == 0)
420 {
421 last_used = i;
422 last_used_dir_len = dir_len;
423 return i;
424 }
425 }
426 else
427 i = num;
428
429 if (i >= files_allocated)
430 {
431 unsigned int old = files_allocated;
432
433 files_allocated = i + 32;
434 files = (struct file_entry *)
435 xrealloc (files, (i + 32) * sizeof (struct file_entry));
436
437 memset (files + old, 0, (i + 32 - old) * sizeof (struct file_entry));
438 }
439
440 files[i].filename = num ? file : xstrdup (file);
441 files[i].dir = dir;
442 files_in_use = i + 1;
443 last_used = i;
444 last_used_dir_len = dir_len;
445
446 return i;
447 }
448
449 /* Handle two forms of .file directive:
450 - Pass .file "source.c" to s_app_file
451 - Handle .file 1 "source.c" by adding an entry to the DWARF-2 file table
452
453 If an entry is added to the file table, return a pointer to the filename. */
454
455 char *
456 dwarf2_directive_file (int dummy ATTRIBUTE_UNUSED)
457 {
458 offsetT num;
459 char *filename;
460 int filename_len;
461
462 /* Continue to accept a bare string and pass it off. */
463 SKIP_WHITESPACE ();
464 if (*input_line_pointer == '"')
465 {
466 s_app_file (0);
467 return NULL;
468 }
469
470 num = get_absolute_expression ();
471 filename = demand_copy_C_string (&filename_len);
472 if (filename == NULL)
473 return NULL;
474 demand_empty_rest_of_line ();
475
476 if (num < 1)
477 {
478 as_bad (_("file number less than one"));
479 return NULL;
480 }
481
482 if (num < (int) files_in_use && files[num].filename != 0)
483 {
484 as_bad (_("file number %ld already allocated"), (long) num);
485 return NULL;
486 }
487
488 get_filenum (filename, num);
489
490 return filename;
491 }
492
493 void
494 dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
495 {
496 offsetT filenum, line;
497
498 filenum = get_absolute_expression ();
499 SKIP_WHITESPACE ();
500 line = get_absolute_expression ();
501
502 if (filenum < 1)
503 {
504 as_bad (_("file number less than one"));
505 return;
506 }
507 if (filenum >= (int) files_in_use || files[filenum].filename == 0)
508 {
509 as_bad (_("unassigned file number %ld"), (long) filenum);
510 return;
511 }
512
513 current.filenum = filenum;
514 current.line = line;
515
516 #ifndef NO_LISTING
517 if (listing)
518 {
519 if (files[filenum].dir)
520 {
521 size_t dir_len = strlen (dirs[files[filenum].dir]);
522 size_t file_len = strlen (files[filenum].filename);
523 char *cp = (char *) alloca (dir_len + 1 + file_len + 1);
524
525 memcpy (cp, dirs[files[filenum].dir], dir_len);
526 cp[dir_len] = '/';
527 memcpy (cp + dir_len + 1, files[filenum].filename, file_len);
528 cp[dir_len + file_len + 1] = '\0';
529 listing_source_file (cp);
530 }
531 else
532 listing_source_file (files[filenum].filename);
533 listing_source_line (line);
534 }
535 #endif
536
537 SKIP_WHITESPACE ();
538 if (ISDIGIT (*input_line_pointer))
539 {
540 current.column = get_absolute_expression ();
541 SKIP_WHITESPACE ();
542 }
543
544 while (ISALPHA (*input_line_pointer))
545 {
546 char *p, c;
547 offsetT value;
548
549 p = input_line_pointer;
550 c = get_symbol_end ();
551
552 if (strcmp (p, "basic_block") == 0)
553 {
554 current.flags |= DWARF2_FLAG_BASIC_BLOCK;
555 *input_line_pointer = c;
556 }
557 else if (strcmp (p, "prologue_end") == 0)
558 {
559 current.flags |= DWARF2_FLAG_PROLOGUE_END;
560 *input_line_pointer = c;
561 }
562 else if (strcmp (p, "epilogue_begin") == 0)
563 {
564 current.flags |= DWARF2_FLAG_EPILOGUE_BEGIN;
565 *input_line_pointer = c;
566 }
567 else if (strcmp (p, "is_stmt") == 0)
568 {
569 *input_line_pointer = c;
570 value = get_absolute_expression ();
571 if (value == 0)
572 current.flags &= ~DWARF2_FLAG_IS_STMT;
573 else if (value == 1)
574 current.flags |= DWARF2_FLAG_IS_STMT;
575 else
576 {
577 as_bad (_("is_stmt value not 0 or 1"));
578 return;
579 }
580 }
581 else if (strcmp (p, "isa") == 0)
582 {
583 *input_line_pointer = c;
584 value = get_absolute_expression ();
585 if (value >= 0)
586 current.isa = value;
587 else
588 {
589 as_bad (_("isa number less than zero"));
590 return;
591 }
592 }
593 else
594 {
595 as_bad (_("unknown .loc sub-directive `%s'"), p);
596 *input_line_pointer = c;
597 return;
598 }
599
600 SKIP_WHITESPACE ();
601 }
602
603 demand_empty_rest_of_line ();
604 loc_directive_seen = TRUE;
605 }
606 \f
607 static struct frag *
608 first_frag_for_seg (segT seg)
609 {
610 frchainS *f, *first = NULL;
611
612 for (f = frchain_root; f; f = f->frch_next)
613 if (f->frch_seg == seg
614 && (! first || first->frch_subseg > f->frch_subseg))
615 first = f;
616
617 return first ? first->frch_root : NULL;
618 }
619
620 static struct frag *
621 last_frag_for_seg (segT seg)
622 {
623 frchainS *f, *last = NULL;
624
625 for (f = frchain_root; f; f = f->frch_next)
626 if (f->frch_seg == seg
627 && (! last || last->frch_subseg < f->frch_subseg))
628 last= f;
629
630 return last ? last->frch_last : NULL;
631 }
632 \f
633 /* Emit a single byte into the current segment. */
634
635 static inline void
636 out_byte (int byte)
637 {
638 FRAG_APPEND_1_CHAR (byte);
639 }
640
641 /* Emit a statement program opcode into the current segment. */
642
643 static inline void
644 out_opcode (int opc)
645 {
646 out_byte (opc);
647 }
648
649 /* Emit a two-byte word into the current segment. */
650
651 static inline void
652 out_two (int data)
653 {
654 md_number_to_chars (frag_more (2), data, 2);
655 }
656
657 /* Emit a four byte word into the current segment. */
658
659 static inline void
660 out_four (int data)
661 {
662 md_number_to_chars (frag_more (4), data, 4);
663 }
664
665 /* Emit an unsigned "little-endian base 128" number. */
666
667 static void
668 out_uleb128 (addressT value)
669 {
670 output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
671 }
672
673 /* Emit a tuple for .debug_abbrev. */
674
675 static inline void
676 out_abbrev (int name, int form)
677 {
678 out_uleb128 (name);
679 out_uleb128 (form);
680 }
681
682 /* Get the size of a fragment. */
683
684 static offsetT
685 get_frag_fix (fragS *frag)
686 {
687 frchainS *fr;
688
689 if (frag->fr_next)
690 return frag->fr_fix;
691
692 /* If a fragment is the last in the chain, special measures must be
693 taken to find its size before relaxation, since it may be pending
694 on some subsegment chain. */
695 for (fr = frchain_root; fr; fr = fr->frch_next)
696 if (fr->frch_last == frag)
697 return (char *) obstack_next_free (&fr->frch_obstack) - frag->fr_literal;
698
699 abort ();
700 }
701
702 /* Set an absolute address (may result in a relocation entry). */
703
704 static void
705 out_set_addr (segT seg, fragS *frag, addressT ofs)
706 {
707 expressionS expr;
708 symbolS *sym;
709
710 sym = symbol_temp_new (seg, ofs, frag);
711
712 out_opcode (DW_LNS_extended_op);
713 out_uleb128 (sizeof_address + 1);
714
715 out_opcode (DW_LNE_set_address);
716 expr.X_op = O_symbol;
717 expr.X_add_symbol = sym;
718 expr.X_add_number = 0;
719 emit_expr (&expr, sizeof_address);
720 }
721
722 #if DWARF2_LINE_MIN_INSN_LENGTH > 1
723 static void scale_addr_delta (addressT *);
724
725 static void
726 scale_addr_delta (addressT *addr_delta)
727 {
728 static int printed_this = 0;
729 if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0)
730 {
731 if (!printed_this)
732 as_bad("unaligned opcodes detected in executable segment");
733 printed_this = 1;
734 }
735 *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH;
736 }
737 #else
738 #define scale_addr_delta(A)
739 #endif
740
741 /* Encode a pair of line and address skips as efficiently as possible.
742 Note that the line skip is signed, whereas the address skip is unsigned.
743
744 The following two routines *must* be kept in sync. This is
745 enforced by making emit_inc_line_addr abort if we do not emit
746 exactly the expected number of bytes. */
747
748 static int
749 size_inc_line_addr (int line_delta, addressT addr_delta)
750 {
751 unsigned int tmp, opcode;
752 int len = 0;
753
754 /* Scale the address delta by the minimum instruction length. */
755 scale_addr_delta (&addr_delta);
756
757 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
758 We cannot use special opcodes here, since we want the end_sequence
759 to emit the matrix entry. */
760 if (line_delta == INT_MAX)
761 {
762 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
763 len = 1;
764 else
765 len = 1 + sizeof_leb128 (addr_delta, 0);
766 return len + 3;
767 }
768
769 /* Bias the line delta by the base. */
770 tmp = line_delta - DWARF2_LINE_BASE;
771
772 /* If the line increment is out of range of a special opcode, we
773 must encode it with DW_LNS_advance_line. */
774 if (tmp >= DWARF2_LINE_RANGE)
775 {
776 len = 1 + sizeof_leb128 (line_delta, 1);
777 line_delta = 0;
778 tmp = 0 - DWARF2_LINE_BASE;
779 }
780
781 /* Bias the opcode by the special opcode base. */
782 tmp += DWARF2_LINE_OPCODE_BASE;
783
784 /* Avoid overflow when addr_delta is large. */
785 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
786 {
787 /* Try using a special opcode. */
788 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
789 if (opcode <= 255)
790 return len + 1;
791
792 /* Try using DW_LNS_const_add_pc followed by special op. */
793 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
794 if (opcode <= 255)
795 return len + 2;
796 }
797
798 /* Otherwise use DW_LNS_advance_pc. */
799 len += 1 + sizeof_leb128 (addr_delta, 0);
800
801 /* DW_LNS_copy or special opcode. */
802 len += 1;
803
804 return len;
805 }
806
807 static void
808 emit_inc_line_addr (int line_delta, addressT addr_delta, char *p, int len)
809 {
810 unsigned int tmp, opcode;
811 int need_copy = 0;
812 char *end = p + len;
813
814 /* Scale the address delta by the minimum instruction length. */
815 scale_addr_delta (&addr_delta);
816
817 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
818 We cannot use special opcodes here, since we want the end_sequence
819 to emit the matrix entry. */
820 if (line_delta == INT_MAX)
821 {
822 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
823 *p++ = DW_LNS_const_add_pc;
824 else
825 {
826 *p++ = DW_LNS_advance_pc;
827 p += output_leb128 (p, addr_delta, 0);
828 }
829
830 *p++ = DW_LNS_extended_op;
831 *p++ = 1;
832 *p++ = DW_LNE_end_sequence;
833 goto done;
834 }
835
836 /* Bias the line delta by the base. */
837 tmp = line_delta - DWARF2_LINE_BASE;
838
839 /* If the line increment is out of range of a special opcode, we
840 must encode it with DW_LNS_advance_line. */
841 if (tmp >= DWARF2_LINE_RANGE)
842 {
843 *p++ = DW_LNS_advance_line;
844 p += output_leb128 (p, line_delta, 1);
845
846 line_delta = 0;
847 tmp = 0 - DWARF2_LINE_BASE;
848 need_copy = 1;
849 }
850
851 /* Prettier, I think, to use DW_LNS_copy instead of a "line +0, addr +0"
852 special opcode. */
853 if (line_delta == 0 && addr_delta == 0)
854 {
855 *p++ = DW_LNS_copy;
856 goto done;
857 }
858
859 /* Bias the opcode by the special opcode base. */
860 tmp += DWARF2_LINE_OPCODE_BASE;
861
862 /* Avoid overflow when addr_delta is large. */
863 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
864 {
865 /* Try using a special opcode. */
866 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
867 if (opcode <= 255)
868 {
869 *p++ = opcode;
870 goto done;
871 }
872
873 /* Try using DW_LNS_const_add_pc followed by special op. */
874 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
875 if (opcode <= 255)
876 {
877 *p++ = DW_LNS_const_add_pc;
878 *p++ = opcode;
879 goto done;
880 }
881 }
882
883 /* Otherwise use DW_LNS_advance_pc. */
884 *p++ = DW_LNS_advance_pc;
885 p += output_leb128 (p, addr_delta, 0);
886
887 if (need_copy)
888 *p++ = DW_LNS_copy;
889 else
890 *p++ = tmp;
891
892 done:
893 assert (p == end);
894 }
895
896 /* Handy routine to combine calls to the above two routines. */
897
898 static void
899 out_inc_line_addr (int line_delta, addressT addr_delta)
900 {
901 int len = size_inc_line_addr (line_delta, addr_delta);
902 emit_inc_line_addr (line_delta, addr_delta, frag_more (len), len);
903 }
904
905 /* Generate a variant frag that we can use to relax address/line
906 increments between fragments of the target segment. */
907
908 static void
909 relax_inc_line_addr (int line_delta, segT seg,
910 fragS *to_frag, addressT to_ofs,
911 fragS *from_frag, addressT from_ofs)
912 {
913 symbolS *to_sym, *from_sym;
914 expressionS expr;
915 int max_chars;
916
917 to_sym = symbol_temp_new (seg, to_ofs, to_frag);
918 from_sym = symbol_temp_new (seg, from_ofs, from_frag);
919
920 expr.X_op = O_subtract;
921 expr.X_add_symbol = to_sym;
922 expr.X_op_symbol = from_sym;
923 expr.X_add_number = 0;
924
925 /* The maximum size of the frag is the line delta with a maximum
926 sized address delta. */
927 max_chars = size_inc_line_addr (line_delta, -DWARF2_LINE_MIN_INSN_LENGTH);
928
929 frag_var (rs_dwarf2dbg, max_chars, max_chars, 1,
930 make_expr_symbol (&expr), line_delta, NULL);
931 }
932
933 /* The function estimates the size of a rs_dwarf2dbg variant frag
934 based on the current values of the symbols. It is called before
935 the relaxation loop. We set fr_subtype to the expected length. */
936
937 int
938 dwarf2dbg_estimate_size_before_relax (fragS *frag)
939 {
940 offsetT addr_delta;
941 int size;
942
943 addr_delta = resolve_symbol_value (frag->fr_symbol);
944 size = size_inc_line_addr (frag->fr_offset, addr_delta);
945
946 frag->fr_subtype = size;
947
948 return size;
949 }
950
951 /* This function relaxes a rs_dwarf2dbg variant frag based on the
952 current values of the symbols. fr_subtype is the current length
953 of the frag. This returns the change in frag length. */
954
955 int
956 dwarf2dbg_relax_frag (fragS *frag)
957 {
958 int old_size, new_size;
959
960 old_size = frag->fr_subtype;
961 new_size = dwarf2dbg_estimate_size_before_relax (frag);
962
963 return new_size - old_size;
964 }
965
966 /* This function converts a rs_dwarf2dbg variant frag into a normal
967 fill frag. This is called after all relaxation has been done.
968 fr_subtype will be the desired length of the frag. */
969
970 void
971 dwarf2dbg_convert_frag (fragS *frag)
972 {
973 offsetT addr_diff;
974
975 addr_diff = resolve_symbol_value (frag->fr_symbol);
976
977 /* fr_var carries the max_chars that we created the fragment with.
978 fr_subtype carries the current expected length. We must, of
979 course, have allocated enough memory earlier. */
980 assert (frag->fr_var >= (int) frag->fr_subtype);
981
982 emit_inc_line_addr (frag->fr_offset, addr_diff,
983 frag->fr_literal + frag->fr_fix, frag->fr_subtype);
984
985 frag->fr_fix += frag->fr_subtype;
986 frag->fr_type = rs_fill;
987 frag->fr_var = 0;
988 frag->fr_offset = 0;
989 }
990
991 /* Generate .debug_line content for the chain of line number entries
992 beginning at E, for segment SEG. */
993
994 static void
995 process_entries (segT seg, struct line_entry *e)
996 {
997 unsigned filenum = 1;
998 unsigned line = 1;
999 unsigned column = 0;
1000 unsigned isa = 0;
1001 unsigned flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;
1002 fragS *frag = NULL;
1003 fragS *last_frag;
1004 addressT frag_ofs = 0;
1005 addressT last_frag_ofs;
1006 struct line_entry *next;
1007
1008 while (e)
1009 {
1010 int changed = 0;
1011
1012 if (filenum != e->loc.filenum)
1013 {
1014 filenum = e->loc.filenum;
1015 out_opcode (DW_LNS_set_file);
1016 out_uleb128 (filenum);
1017 changed = 1;
1018 }
1019
1020 if (column != e->loc.column)
1021 {
1022 column = e->loc.column;
1023 out_opcode (DW_LNS_set_column);
1024 out_uleb128 (column);
1025 changed = 1;
1026 }
1027
1028 if (isa != e->loc.isa)
1029 {
1030 isa = e->loc.isa;
1031 out_opcode (DW_LNS_set_isa);
1032 out_uleb128 (isa);
1033 changed = 1;
1034 }
1035
1036 if ((e->loc.flags ^ flags) & DWARF2_FLAG_IS_STMT)
1037 {
1038 flags = e->loc.flags;
1039 out_opcode (DW_LNS_negate_stmt);
1040 changed = 1;
1041 }
1042
1043 if (e->loc.flags & DWARF2_FLAG_BASIC_BLOCK)
1044 {
1045 out_opcode (DW_LNS_set_basic_block);
1046 changed = 1;
1047 }
1048
1049 if (e->loc.flags & DWARF2_FLAG_PROLOGUE_END)
1050 {
1051 out_opcode (DW_LNS_set_prologue_end);
1052 changed = 1;
1053 }
1054
1055 if (e->loc.flags & DWARF2_FLAG_EPILOGUE_BEGIN)
1056 {
1057 out_opcode (DW_LNS_set_epilogue_begin);
1058 changed = 1;
1059 }
1060
1061 /* Don't try to optimize away redundant entries; gdb wants two
1062 entries for a function where the code starts on the same line as
1063 the {, and there's no way to identify that case here. Trust gcc
1064 to optimize appropriately. */
1065 if (1 /* line != e->loc.line || changed */)
1066 {
1067 int line_delta = e->loc.line - line;
1068 if (frag == NULL)
1069 {
1070 out_set_addr (seg, e->frag, e->frag_ofs);
1071 out_inc_line_addr (line_delta, 0);
1072 }
1073 else if (frag == e->frag)
1074 out_inc_line_addr (line_delta, e->frag_ofs - frag_ofs);
1075 else
1076 relax_inc_line_addr (line_delta, seg, e->frag, e->frag_ofs,
1077 frag, frag_ofs);
1078
1079 frag = e->frag;
1080 frag_ofs = e->frag_ofs;
1081 line = e->loc.line;
1082 }
1083 else if (frag == NULL)
1084 {
1085 out_set_addr (seg, e->frag, e->frag_ofs);
1086 frag = e->frag;
1087 frag_ofs = e->frag_ofs;
1088 }
1089
1090 next = e->next;
1091 free (e);
1092 e = next;
1093 }
1094
1095 /* Emit a DW_LNE_end_sequence for the end of the section. */
1096 last_frag = last_frag_for_seg (seg);
1097 last_frag_ofs = get_frag_fix (last_frag);
1098 if (frag == last_frag)
1099 out_inc_line_addr (INT_MAX, last_frag_ofs - frag_ofs);
1100 else
1101 relax_inc_line_addr (INT_MAX, seg, last_frag, last_frag_ofs,
1102 frag, frag_ofs);
1103 }
1104
1105 /* Emit the directory and file tables for .debug_line. */
1106
1107 static void
1108 out_file_list (void)
1109 {
1110 size_t size;
1111 char *cp;
1112 unsigned int i;
1113
1114 /* Emit directory list. */
1115 for (i = 1; i < dirs_in_use; ++i)
1116 {
1117 size = strlen (dirs[i]) + 1;
1118 cp = frag_more (size);
1119 memcpy (cp, dirs[i], size);
1120 }
1121 /* Terminate it. */
1122 out_byte ('\0');
1123
1124 for (i = 1; i < files_in_use; ++i)
1125 {
1126 if (files[i].filename == NULL)
1127 {
1128 as_bad (_("unassigned file number %ld"), (long) i);
1129 /* Prevent a crash later, particularly for file 1. */
1130 files[i].filename = "";
1131 continue;
1132 }
1133
1134 size = strlen (files[i].filename) + 1;
1135 cp = frag_more (size);
1136 memcpy (cp, files[i].filename, size);
1137
1138 out_uleb128 (files[i].dir); /* directory number */
1139 out_uleb128 (0); /* last modification timestamp */
1140 out_uleb128 (0); /* filesize */
1141 }
1142
1143 /* Terminate filename list. */
1144 out_byte (0);
1145 }
1146
1147 /* Emit the collected .debug_line data. */
1148
1149 static void
1150 out_debug_line (segT line_seg)
1151 {
1152 expressionS expr;
1153 symbolS *line_start;
1154 symbolS *prologue_end;
1155 symbolS *line_end;
1156 struct line_seg *s;
1157 enum dwarf2_format d2f;
1158 int sizeof_offset;
1159
1160 subseg_set (line_seg, 0);
1161
1162 line_start = symbol_temp_new_now ();
1163 prologue_end = symbol_temp_make ();
1164 line_end = symbol_temp_make ();
1165
1166 /* Total length of the information for this compilation unit. */
1167 expr.X_op = O_subtract;
1168 expr.X_add_symbol = line_end;
1169 expr.X_op_symbol = line_start;
1170
1171 d2f = DWARF2_FORMAT ();
1172 if (d2f == dwarf2_format_32bit)
1173 {
1174 expr.X_add_number = -4;
1175 emit_expr (&expr, 4);
1176 sizeof_offset = 4;
1177 }
1178 else if (d2f == dwarf2_format_64bit)
1179 {
1180 expr.X_add_number = -12;
1181 out_four (-1);
1182 emit_expr (&expr, 8);
1183 sizeof_offset = 8;
1184 }
1185 else if (d2f == dwarf2_format_64bit_irix)
1186 {
1187 expr.X_add_number = -8;
1188 emit_expr (&expr, 8);
1189 sizeof_offset = 8;
1190 }
1191 else
1192 {
1193 as_fatal (_("internal error: unknown dwarf2 format"));
1194 }
1195
1196 /* Version. */
1197 out_two (2);
1198
1199 /* Length of the prologue following this length. */
1200 expr.X_op = O_subtract;
1201 expr.X_add_symbol = prologue_end;
1202 expr.X_op_symbol = line_start;
1203 expr.X_add_number = - (4 + 2 + 4);
1204 emit_expr (&expr, sizeof_offset);
1205
1206 /* Parameters of the state machine. */
1207 out_byte (DWARF2_LINE_MIN_INSN_LENGTH);
1208 out_byte (DWARF2_LINE_DEFAULT_IS_STMT);
1209 out_byte (DWARF2_LINE_BASE);
1210 out_byte (DWARF2_LINE_RANGE);
1211 out_byte (DWARF2_LINE_OPCODE_BASE);
1212
1213 /* Standard opcode lengths. */
1214 out_byte (0); /* DW_LNS_copy */
1215 out_byte (1); /* DW_LNS_advance_pc */
1216 out_byte (1); /* DW_LNS_advance_line */
1217 out_byte (1); /* DW_LNS_set_file */
1218 out_byte (1); /* DW_LNS_set_column */
1219 out_byte (0); /* DW_LNS_negate_stmt */
1220 out_byte (0); /* DW_LNS_set_basic_block */
1221 out_byte (0); /* DW_LNS_const_add_pc */
1222 out_byte (1); /* DW_LNS_fixed_advance_pc */
1223 out_byte (0); /* DW_LNS_set_prologue_end */
1224 out_byte (0); /* DW_LNS_set_epilogue_begin */
1225 out_byte (1); /* DW_LNS_set_isa */
1226
1227 out_file_list ();
1228
1229 symbol_set_value_now (prologue_end);
1230
1231 /* For each section, emit a statement program. */
1232 for (s = all_segs; s; s = s->next)
1233 process_entries (s->seg, s->head->head);
1234
1235 symbol_set_value_now (line_end);
1236 }
1237
1238 /* Emit data for .debug_aranges. */
1239
1240 static void
1241 out_debug_aranges (segT aranges_seg, segT info_seg)
1242 {
1243 unsigned int addr_size = sizeof_address;
1244 addressT size, skip;
1245 struct line_seg *s;
1246 expressionS expr;
1247 char *p;
1248
1249 size = 4 + 2 + 4 + 1 + 1;
1250
1251 skip = 2 * addr_size - (size & (2 * addr_size - 1));
1252 if (skip == 2 * addr_size)
1253 skip = 0;
1254 size += skip;
1255
1256 for (s = all_segs; s; s = s->next)
1257 size += 2 * addr_size;
1258
1259 size += 2 * addr_size;
1260
1261 subseg_set (aranges_seg, 0);
1262
1263 /* Length of the compilation unit. */
1264 out_four (size - 4);
1265
1266 /* Version. */
1267 out_two (2);
1268
1269 /* Offset to .debug_info. */
1270 /* ??? sizeof_offset */
1271 TC_DWARF2_EMIT_OFFSET (section_symbol (info_seg), 4);
1272
1273 /* Size of an address (offset portion). */
1274 out_byte (addr_size);
1275
1276 /* Size of a segment descriptor. */
1277 out_byte (0);
1278
1279 /* Align the header. */
1280 if (skip)
1281 frag_align (ffs (2 * addr_size) - 1, 0, 0);
1282
1283 for (s = all_segs; s; s = s->next)
1284 {
1285 fragS *frag;
1286 symbolS *beg, *end;
1287
1288 frag = first_frag_for_seg (s->seg);
1289 beg = symbol_temp_new (s->seg, 0, frag);
1290 s->text_start = beg;
1291
1292 frag = last_frag_for_seg (s->seg);
1293 end = symbol_temp_new (s->seg, get_frag_fix (frag), frag);
1294 s->text_end = end;
1295
1296 expr.X_op = O_symbol;
1297 expr.X_add_symbol = beg;
1298 expr.X_add_number = 0;
1299 emit_expr (&expr, addr_size);
1300
1301 expr.X_op = O_subtract;
1302 expr.X_add_symbol = end;
1303 expr.X_op_symbol = beg;
1304 expr.X_add_number = 0;
1305 emit_expr (&expr, addr_size);
1306 }
1307
1308 p = frag_more (2 * addr_size);
1309 md_number_to_chars (p, 0, addr_size);
1310 md_number_to_chars (p + addr_size, 0, addr_size);
1311 }
1312
1313 /* Emit data for .debug_abbrev. Note that this must be kept in
1314 sync with out_debug_info below. */
1315
1316 static void
1317 out_debug_abbrev (segT abbrev_seg)
1318 {
1319 subseg_set (abbrev_seg, 0);
1320
1321 out_uleb128 (1);
1322 out_uleb128 (DW_TAG_compile_unit);
1323 out_byte (DW_CHILDREN_no);
1324 out_abbrev (DW_AT_stmt_list, DW_FORM_data4);
1325 if (all_segs->next == NULL)
1326 {
1327 out_abbrev (DW_AT_low_pc, DW_FORM_addr);
1328 out_abbrev (DW_AT_high_pc, DW_FORM_addr);
1329 }
1330 out_abbrev (DW_AT_name, DW_FORM_string);
1331 out_abbrev (DW_AT_comp_dir, DW_FORM_string);
1332 out_abbrev (DW_AT_producer, DW_FORM_string);
1333 out_abbrev (DW_AT_language, DW_FORM_data2);
1334 out_abbrev (0, 0);
1335
1336 /* Terminate the abbreviations for this compilation unit. */
1337 out_byte (0);
1338 }
1339
1340 /* Emit a description of this compilation unit for .debug_info. */
1341
1342 static void
1343 out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg)
1344 {
1345 char producer[128];
1346 char *comp_dir;
1347 expressionS expr;
1348 symbolS *info_start;
1349 symbolS *info_end;
1350 char *p;
1351 int len;
1352 enum dwarf2_format d2f;
1353 int sizeof_offset;
1354
1355 subseg_set (info_seg, 0);
1356
1357 info_start = symbol_temp_new_now ();
1358 info_end = symbol_temp_make ();
1359
1360 /* Compilation Unit length. */
1361 expr.X_op = O_subtract;
1362 expr.X_add_symbol = info_end;
1363 expr.X_op_symbol = info_start;
1364
1365 d2f = DWARF2_FORMAT ();
1366 if (d2f == dwarf2_format_32bit)
1367 {
1368 expr.X_add_number = -4;
1369 emit_expr (&expr, 4);
1370 sizeof_offset = 4;
1371 }
1372 else if (d2f == dwarf2_format_64bit)
1373 {
1374 expr.X_add_number = -12;
1375 out_four (-1);
1376 emit_expr (&expr, 8);
1377 sizeof_offset = 8;
1378 }
1379 else if (d2f == dwarf2_format_64bit_irix)
1380 {
1381 expr.X_add_number = -8;
1382 emit_expr (&expr, 8);
1383 sizeof_offset = 8;
1384 }
1385 else
1386 {
1387 as_fatal (_("internal error: unknown dwarf2 format"));
1388 }
1389
1390 /* DWARF version. */
1391 out_two (2);
1392
1393 /* .debug_abbrev offset */
1394 TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset);
1395
1396 /* Target address size. */
1397 out_byte (sizeof_address);
1398
1399 /* DW_TAG_compile_unit DIE abbrev */
1400 out_uleb128 (1);
1401
1402 /* DW_AT_stmt_list */
1403 /* ??? sizeof_offset */
1404 TC_DWARF2_EMIT_OFFSET (section_symbol (line_seg), 4);
1405
1406 /* These two attributes may only be emitted if all of the code is
1407 contiguous. Multiple sections are not that. */
1408 if (all_segs->next == NULL)
1409 {
1410 /* DW_AT_low_pc */
1411 expr.X_op = O_symbol;
1412 expr.X_add_symbol = all_segs->text_start;
1413 expr.X_add_number = 0;
1414 emit_expr (&expr, sizeof_address);
1415
1416 /* DW_AT_high_pc */
1417 expr.X_op = O_symbol;
1418 expr.X_add_symbol = all_segs->text_end;
1419 expr.X_add_number = 0;
1420 emit_expr (&expr, sizeof_address);
1421 }
1422
1423 /* DW_AT_name. We don't have the actual file name that was present
1424 on the command line, so assume files[1] is the main input file.
1425 We're not supposed to get called unless at least one line number
1426 entry was emitted, so this should always be defined. */
1427 if (!files || files_in_use < 1)
1428 abort ();
1429 if (files[1].dir)
1430 {
1431 len = strlen (dirs[files[1].dir]);
1432 p = frag_more (len + 1);
1433 memcpy (p, dirs[files[1].dir], len);
1434 p[len] = '/';
1435 }
1436 len = strlen (files[1].filename) + 1;
1437 p = frag_more (len);
1438 memcpy (p, files[1].filename, len);
1439
1440 /* DW_AT_comp_dir */
1441 comp_dir = getpwd ();
1442 len = strlen (comp_dir) + 1;
1443 p = frag_more (len);
1444 memcpy (p, comp_dir, len);
1445
1446 /* DW_AT_producer */
1447 sprintf (producer, "GNU AS %s", VERSION);
1448 len = strlen (producer) + 1;
1449 p = frag_more (len);
1450 memcpy (p, producer, len);
1451
1452 /* DW_AT_language. Yes, this is probably not really MIPS, but the
1453 dwarf2 draft has no standard code for assembler. */
1454 out_two (DW_LANG_Mips_Assembler);
1455
1456 symbol_set_value_now (info_end);
1457 }
1458
1459 /* Finish the dwarf2 debug sections. We emit .debug.line if there
1460 were any .file/.loc directives, or --gdwarf2 was given, or if the
1461 file has a non-empty .debug_info section. If we emit .debug_line,
1462 and the .debug_info section is empty, we also emit .debug_info,
1463 .debug_aranges and .debug_abbrev. ALL_SEGS will be non-null if
1464 there were any .file/.loc directives, or --gdwarf2 was given and
1465 there were any located instructions emitted. */
1466
1467 void
1468 dwarf2_finish (void)
1469 {
1470 segT line_seg;
1471 struct line_seg *s;
1472 segT info_seg;
1473 int emit_other_sections = 0;
1474
1475 info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
1476 emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
1477
1478 if (!all_segs && emit_other_sections)
1479 /* There is no line information and no non-empty .debug_info
1480 section. */
1481 return;
1482
1483 /* Calculate the size of an address for the target machine. */
1484 sizeof_address = DWARF2_ADDR_SIZE (stdoutput);
1485
1486 /* Create and switch to the line number section. */
1487 line_seg = subseg_new (".debug_line", 0);
1488 bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY | SEC_DEBUGGING);
1489
1490 /* For each subsection, chain the debug entries together. */
1491 for (s = all_segs; s; s = s->next)
1492 {
1493 struct line_subseg *ss = s->head;
1494 struct line_entry **ptail = ss->ptail;
1495
1496 while ((ss = ss->next) != NULL)
1497 {
1498 *ptail = ss->head;
1499 ptail = ss->ptail;
1500 }
1501 }
1502
1503 out_debug_line (line_seg);
1504
1505 /* If this is assembler generated line info, and there is no
1506 debug_info already, we need .debug_info and .debug_abbrev
1507 sections as well. */
1508 if (emit_other_sections)
1509 {
1510 segT abbrev_seg;
1511 segT aranges_seg;
1512
1513 assert (all_segs);
1514
1515 info_seg = subseg_new (".debug_info", 0);
1516 abbrev_seg = subseg_new (".debug_abbrev", 0);
1517 aranges_seg = subseg_new (".debug_aranges", 0);
1518
1519 bfd_set_section_flags (stdoutput, info_seg,
1520 SEC_READONLY | SEC_DEBUGGING);
1521 bfd_set_section_flags (stdoutput, abbrev_seg,
1522 SEC_READONLY | SEC_DEBUGGING);
1523 bfd_set_section_flags (stdoutput, aranges_seg,
1524 SEC_READONLY | SEC_DEBUGGING);
1525
1526 record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
1527
1528 out_debug_aranges (aranges_seg, info_seg);
1529 out_debug_abbrev (abbrev_seg);
1530 out_debug_info (info_seg, abbrev_seg, line_seg);
1531 }
1532 }