/src/binutils-gdb/gas/dwarf2dbg.c
Line | Count | Source |
1 | | /* dwarf2dbg.c - DWARF2 debug support |
2 | | Copyright (C) 1999-2026 Free Software Foundation, Inc. |
3 | | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
4 | | |
5 | | This file is part of GAS, the GNU Assembler. |
6 | | |
7 | | GAS is free software; you can redistribute it and/or modify |
8 | | it under the terms of the GNU General Public License as published by |
9 | | the Free Software Foundation; either version 3, or (at your option) |
10 | | any later version. |
11 | | |
12 | | GAS is distributed in the hope that it will be useful, |
13 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | GNU General Public License for more details. |
16 | | |
17 | | You should have received a copy of the GNU General Public License |
18 | | along with GAS; see the file COPYING. If not, write to the Free |
19 | | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
20 | | 02110-1301, USA. */ |
21 | | |
22 | | /* Logical line numbers can be controlled by the compiler via the |
23 | | following directives: |
24 | | |
25 | | .file FILENO "file.c" |
26 | | .loc FILENO LINENO [COLUMN] [basic_block] [prologue_end] \ |
27 | | [epilogue_begin] [is_stmt VALUE] [isa VALUE] \ |
28 | | [discriminator VALUE] [view VALUE] |
29 | | */ |
30 | | |
31 | | #include "as.h" |
32 | | #include "safe-ctype.h" |
33 | | #include <limits.h> |
34 | | #include "dwarf2dbg.h" |
35 | | #include <filenames.h> |
36 | | |
37 | | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
38 | | /* We need to decide which character to use as a directory separator. |
39 | | Just because HAVE_DOS_BASED_FILE_SYSTEM is defined, it does not |
40 | | necessarily mean that the backslash character is the one to use. |
41 | | Some environments, eg Cygwin, can support both naming conventions. |
42 | | So we use the heuristic that we only need to use the backslash if |
43 | | the path is an absolute path starting with a DOS style drive |
44 | | selector. eg C: or D: */ |
45 | | # define INSERT_DIR_SEPARATOR(string, offset) \ |
46 | | do \ |
47 | | { \ |
48 | | if (offset > 1 \ |
49 | | && string[0] != 0 \ |
50 | | && string[1] == ':') \ |
51 | | string [offset] = '\\'; \ |
52 | | else \ |
53 | | string [offset] = '/'; \ |
54 | | } \ |
55 | | while (0) |
56 | | #else |
57 | 3 | # define INSERT_DIR_SEPARATOR(string, offset) string[offset] = '/' |
58 | | #endif |
59 | | |
60 | | #ifndef DWARF2_FORMAT |
61 | 107 | # define DWARF2_FORMAT(SEC) dwarf2_format_32bit |
62 | | #endif |
63 | | |
64 | | #ifndef DWARF2_ADDR_SIZE |
65 | | # define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8) |
66 | | #endif |
67 | | |
68 | | #ifndef DWARF2_FILE_NAME |
69 | 36 | #define DWARF2_FILE_NAME(FILENAME, DIRNAME) FILENAME |
70 | | #endif |
71 | | |
72 | | #ifndef DWARF2_FILE_TIME_NAME |
73 | 28 | #define DWARF2_FILE_TIME_NAME(FILENAME,DIRNAME) -1 |
74 | | #endif |
75 | | |
76 | | #ifndef DWARF2_FILE_SIZE_NAME |
77 | 28 | #define DWARF2_FILE_SIZE_NAME(FILENAME,DIRNAME) -1 |
78 | | #endif |
79 | | |
80 | | #ifndef DWARF2_VERSION |
81 | 154k | #define DWARF2_VERSION dwarf_level |
82 | | #endif |
83 | | |
84 | | /* The .debug_aranges version has been 2 in DWARF version 2, 3 and 4. */ |
85 | | #ifndef DWARF2_ARANGES_VERSION |
86 | 26 | #define DWARF2_ARANGES_VERSION 2 |
87 | | #endif |
88 | | |
89 | | /* The .debug_line version is the same as the .debug_info version. */ |
90 | | #ifndef DWARF2_LINE_VERSION |
91 | 154k | #define DWARF2_LINE_VERSION DWARF2_VERSION |
92 | | #endif |
93 | | |
94 | | /* The .debug_rnglists has only been in DWARF version 5. */ |
95 | | #ifndef DWARF2_RNGLISTS_VERSION |
96 | 1 | #define DWARF2_RNGLISTS_VERSION 5 |
97 | | #endif |
98 | | |
99 | | #include "subsegs.h" |
100 | | |
101 | | #include "dwarf2.h" |
102 | | |
103 | | /* Since we can't generate the prolog until the body is complete, we |
104 | | use three different subsegments for .debug_line: one holding the |
105 | | prolog, one for the directory and filename info, and one for the |
106 | | body ("statement program"). */ |
107 | | #define DL_PROLOG 0 |
108 | | #define DL_FILES 1 |
109 | | #define DL_BODY 2 |
110 | | |
111 | | /* If linker relaxation might change offsets in the code, the DWARF special |
112 | | opcodes and variable-length operands cannot be used. If this macro is |
113 | | nonzero, use the DW_LNS_fixed_advance_pc opcode instead. */ |
114 | | #ifndef DWARF2_USE_FIXED_ADVANCE_PC |
115 | 13.4k | # define DWARF2_USE_FIXED_ADVANCE_PC(FROM, TO) linkrelax |
116 | | #endif |
117 | | |
118 | | /* Similar to DWARF2_USE_FIXED_ADVANCE_PC, used for frag. */ |
119 | | #ifndef DWARF2_USE_FIXED_ADVANCE_PC_FRAG |
120 | | # define DWARF2_USE_FIXED_ADVANCE_PC_FRAG(FRAG) \ |
121 | 0 | DWARF2_USE_FIXED_ADVANCE_PC (0, 0) |
122 | | #endif |
123 | | |
124 | | /* First special line opcode - leave room for the standard opcodes. |
125 | | Note: If you want to change this, you'll have to update the |
126 | | "standard_opcode_lengths" table that is emitted below in |
127 | | out_debug_line(). */ |
128 | 52.8k | #define DWARF2_LINE_OPCODE_BASE (DWARF2_LINE_VERSION == 2 ? 10 : 13) |
129 | | |
130 | | #ifndef DWARF2_LINE_BASE |
131 | | /* Minimum line offset in a special line info. opcode. This value |
132 | | was chosen to give a reasonable range of values. */ |
133 | 27.0k | # define DWARF2_LINE_BASE -5 |
134 | | #endif |
135 | | |
136 | | /* Range of line offsets in a special line info. opcode. */ |
137 | | #ifndef DWARF2_LINE_RANGE |
138 | 79.5k | # define DWARF2_LINE_RANGE 14 |
139 | | #endif |
140 | | |
141 | | #ifndef DWARF2_LINE_MIN_INSN_LENGTH |
142 | | /* Define the architecture-dependent minimum instruction length (in |
143 | | bytes). This value should be rather too small than too big. */ |
144 | 27.2k | # define DWARF2_LINE_MIN_INSN_LENGTH 1 |
145 | | #endif |
146 | | |
147 | | /* Flag that indicates the initial value of the is_stmt_start flag. */ |
148 | 411 | #define DWARF2_LINE_DEFAULT_IS_STMT 1 |
149 | | |
150 | | #ifndef DWARF2_LINE_MAX_OPS_PER_INSN |
151 | 28 | #define DWARF2_LINE_MAX_OPS_PER_INSN 1 |
152 | | #endif |
153 | | |
154 | | /* Given a special op, return the line skip amount. */ |
155 | | #define SPECIAL_LINE(op) \ |
156 | | (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE) |
157 | | |
158 | | /* Given a special op, return the address skip amount (in units of |
159 | | DWARF2_LINE_MIN_INSN_LENGTH. */ |
160 | 26.4k | #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE) |
161 | | |
162 | | /* The maximum address skip amount that can be encoded with a special op. */ |
163 | 26.4k | #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255) |
164 | | |
165 | | #ifndef TC_PARSE_CONS_RETURN_NONE |
166 | | #define TC_PARSE_CONS_RETURN_NONE BFD_RELOC_NONE |
167 | | #endif |
168 | | |
169 | 52 | #define GAS_ABBREV_COMP_UNIT 1 |
170 | 2 | #define GAS_ABBREV_SUBPROG 2 |
171 | 2 | #define GAS_ABBREV_NO_TYPE 3 |
172 | | |
173 | | struct line_entry |
174 | | { |
175 | | struct line_entry *next; |
176 | | symbolS *label; |
177 | | struct dwarf2_line_info loc; |
178 | | }; |
179 | | |
180 | | /* Given line_entry list HEAD and PTAIL pointers, return a pointer to |
181 | | the last line_entry on the list. */ |
182 | | static inline struct line_entry * |
183 | | line_entry_at_tail (void *head, struct line_entry **ptail) |
184 | 12.9k | { |
185 | | /* If the list is empty ptail points at head. */ |
186 | 12.9k | if (head == NULL) |
187 | 0 | return NULL; |
188 | | /* Otherwise ptail points to line_entry.next of the last entry. */ |
189 | 12.9k | void *p = (char *) ptail - offsetof (struct line_entry, next); |
190 | 12.9k | return p; |
191 | 12.9k | } |
192 | | |
193 | | struct line_subseg |
194 | | { |
195 | | struct line_subseg *next; |
196 | | subsegT subseg; |
197 | | struct line_entry *head; |
198 | | struct line_entry **ptail; |
199 | | struct line_entry **pmove_tail; |
200 | | }; |
201 | | |
202 | | struct line_seg |
203 | | { |
204 | | struct line_seg *next; |
205 | | segT seg; |
206 | | struct line_subseg *head; |
207 | | symbolS *text_start; |
208 | | symbolS *text_end; |
209 | | }; |
210 | | |
211 | | /* Collects data for all line table entries during assembly. */ |
212 | | static struct line_seg *all_segs; |
213 | | static struct line_seg **last_seg_ptr; |
214 | | |
215 | 108 | #define NUM_MD5_BYTES 16 |
216 | | |
217 | | struct file_entry |
218 | | { |
219 | | const char * filename; |
220 | | unsigned int dir; |
221 | | unsigned char md5[NUM_MD5_BYTES]; |
222 | | }; |
223 | | |
224 | | /* Table of files used by .debug_line. */ |
225 | | static struct file_entry *files; |
226 | | static unsigned int files_in_use; |
227 | | static unsigned int files_allocated; |
228 | | |
229 | | /* Table of directories used by .debug_line. */ |
230 | | static char ** dirs; |
231 | | static unsigned int dirs_in_use; |
232 | | static unsigned int dirs_allocated; |
233 | | |
234 | | /* TRUE when we've seen a .loc directive recently. Used to avoid |
235 | | doing work when there's nothing to do. Will be reset by |
236 | | dwarf2_consume_line_info. */ |
237 | | bool dwarf2_loc_directive_seen; |
238 | | |
239 | | /* TRUE when we've seen any .loc directive at any time during parsing. |
240 | | Indicates the user wants us to generate a .debug_line section. |
241 | | Used in dwarf2_finish as sanity check. */ |
242 | | static bool dwarf2_any_loc_directive_seen; |
243 | | |
244 | | /* TRUE when we're supposed to set the basic block mark whenever a |
245 | | label is seen. */ |
246 | | bool dwarf2_loc_mark_labels; |
247 | | |
248 | | /* Current location as indicated by the most recent .loc directive. */ |
249 | | static struct dwarf2_line_info current; |
250 | | |
251 | | /* This symbol is used to recognize view number forced resets in loc |
252 | | lists. */ |
253 | | static symbolS *force_reset_view; |
254 | | |
255 | | /* This symbol evaluates to an expression that, if nonzero, indicates |
256 | | some view assert check failed. */ |
257 | | static symbolS *view_assert_failed; |
258 | | |
259 | | /* The size of an address on the target. */ |
260 | | static unsigned int sizeof_address; |
261 | | |
262 | | #ifndef TC_DWARF2_EMIT_OFFSET |
263 | 231 | #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset |
264 | | |
265 | | /* Create an offset to .dwarf2_*. */ |
266 | | |
267 | | static void |
268 | | generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
269 | 231 | { |
270 | 231 | expressionS exp; |
271 | | |
272 | 231 | memset (&exp, 0, sizeof exp); |
273 | 231 | exp.X_op = O_symbol; |
274 | 231 | exp.X_add_symbol = symbol; |
275 | 231 | exp.X_add_number = 0; |
276 | 231 | emit_expr (&exp, size); |
277 | 231 | } |
278 | | #endif |
279 | | |
280 | | /* Find or create (if CREATE_P) an entry for SEG+SUBSEG in ALL_SEGS. */ |
281 | | |
282 | | static struct line_subseg * |
283 | | get_line_subseg (segT seg, subsegT subseg, bool create_p) |
284 | 13.5k | { |
285 | 13.5k | struct line_seg *s = seg_info (seg)->dwarf2_line_seg; |
286 | 13.5k | struct line_subseg **pss, *lss; |
287 | | |
288 | 13.5k | if (s == NULL) |
289 | 44 | { |
290 | 44 | if (!create_p) |
291 | 0 | return NULL; |
292 | | |
293 | 44 | s = XNEW (struct line_seg); |
294 | 44 | s->next = NULL; |
295 | 44 | s->seg = seg; |
296 | 44 | s->head = NULL; |
297 | 44 | *last_seg_ptr = s; |
298 | 44 | last_seg_ptr = &s->next; |
299 | 44 | seg_info (seg)->dwarf2_line_seg = s; |
300 | 44 | } |
301 | | |
302 | 13.5k | gas_assert (seg == s->seg); |
303 | | |
304 | 13.6k | for (pss = &s->head; (lss = *pss) != NULL ; pss = &lss->next) |
305 | 13.6k | { |
306 | 13.6k | if (lss->subseg == subseg) |
307 | 13.5k | goto found_subseg; |
308 | 133 | if (lss->subseg > subseg) |
309 | 2 | break; |
310 | 133 | } |
311 | | |
312 | 48 | lss = XNEW (struct line_subseg); |
313 | 48 | lss->next = *pss; |
314 | 48 | lss->subseg = subseg; |
315 | 48 | lss->head = NULL; |
316 | 48 | lss->ptail = &lss->head; |
317 | 48 | lss->pmove_tail = &lss->head; |
318 | 48 | *pss = lss; |
319 | | |
320 | 13.5k | found_subseg: |
321 | 13.5k | return lss; |
322 | 48 | } |
323 | | |
324 | | /* (Un)reverse the line_entry list starting from H. */ |
325 | | |
326 | | static struct line_entry * |
327 | | reverse_line_entry_list (struct line_entry *h) |
328 | 22 | { |
329 | 22 | struct line_entry *p = NULL, *e, *n; |
330 | | |
331 | 104 | for (e = h; e; e = n) |
332 | 82 | { |
333 | 82 | n = e->next; |
334 | 82 | e->next = p; |
335 | 82 | p = e; |
336 | 82 | } |
337 | 22 | return p; |
338 | 22 | } |
339 | | |
340 | | /* Compute the view for E based on the previous entry P. If we |
341 | | introduce an (undefined) view symbol for P, and H is given (P must |
342 | | be the tail in this case), introduce view symbols for earlier list |
343 | | entries as well, until one of them is constant. */ |
344 | | |
345 | | static void |
346 | | set_or_check_view (struct line_entry *e, struct line_entry *p, |
347 | | struct line_entry *h) |
348 | 12.9k | { |
349 | 12.9k | expressionS viewx; |
350 | | |
351 | 12.9k | memset (&viewx, 0, sizeof (viewx)); |
352 | 12.9k | viewx.X_unsigned = 1; |
353 | | |
354 | | /* First, compute !(E->label > P->label), to tell whether or not |
355 | | we're to reset the view number. If we can't resolve it to a |
356 | | constant, keep it symbolic. */ |
357 | 12.9k | if (!p || (e->loc.u.view == force_reset_view && force_reset_view)) |
358 | 150 | { |
359 | 150 | viewx.X_op = O_constant; |
360 | 150 | viewx.X_add_number = 0; |
361 | 150 | viewx.X_add_symbol = NULL; |
362 | 150 | viewx.X_op_symbol = NULL; |
363 | 150 | } |
364 | 12.8k | else |
365 | 12.8k | { |
366 | 12.8k | viewx.X_op = O_gt; |
367 | 12.8k | viewx.X_add_number = 0; |
368 | 12.8k | viewx.X_add_symbol = e->label; |
369 | 12.8k | viewx.X_op_symbol = p->label; |
370 | 12.8k | resolve_expression (&viewx); |
371 | 12.8k | if (viewx.X_op == O_constant) |
372 | 12.8k | viewx.X_add_number = !viewx.X_add_number; |
373 | 0 | else |
374 | 0 | { |
375 | 0 | viewx.X_add_symbol = make_expr_symbol (&viewx); |
376 | 0 | viewx.X_add_number = 0; |
377 | 0 | viewx.X_op_symbol = NULL; |
378 | 0 | viewx.X_op = O_logical_not; |
379 | 0 | } |
380 | 12.8k | } |
381 | | |
382 | 12.9k | if (S_IS_DEFINED (e->loc.u.view) && symbol_constant_p (e->loc.u.view)) |
383 | 12.9k | { |
384 | 12.9k | expressionS *value = symbol_get_value_expression (e->loc.u.view); |
385 | | /* We can't compare the view numbers at this point, because in |
386 | | VIEWX we've only determined whether we're to reset it so |
387 | | far. */ |
388 | 12.9k | if (viewx.X_op == O_constant) |
389 | 12.9k | { |
390 | 12.9k | if (!value->X_add_number != !viewx.X_add_number) |
391 | 7 | as_bad (_("view number mismatch")); |
392 | 12.9k | } |
393 | | /* Record the expression to check it later. It is the result of |
394 | | a logical not, thus 0 or 1. We just add up all such deferred |
395 | | expressions, and resolve it at the end. */ |
396 | 0 | else if (!value->X_add_number) |
397 | 0 | { |
398 | 0 | symbolS *deferred = make_expr_symbol (&viewx); |
399 | 0 | if (view_assert_failed) |
400 | 0 | { |
401 | 0 | expressionS chk; |
402 | |
|
403 | 0 | memset (&chk, 0, sizeof (chk)); |
404 | 0 | chk.X_unsigned = 1; |
405 | 0 | chk.X_op = O_add; |
406 | 0 | chk.X_add_number = 0; |
407 | 0 | chk.X_add_symbol = view_assert_failed; |
408 | 0 | chk.X_op_symbol = deferred; |
409 | 0 | deferred = make_expr_symbol (&chk); |
410 | 0 | } |
411 | 0 | view_assert_failed = deferred; |
412 | 0 | } |
413 | 12.9k | } |
414 | | |
415 | 12.9k | if (viewx.X_op != O_constant || viewx.X_add_number) |
416 | 19 | { |
417 | 19 | expressionS incv; |
418 | 19 | expressionS *p_view; |
419 | | |
420 | 19 | if (!p->loc.u.view) |
421 | 6 | p->loc.u.view = symbol_temp_make (); |
422 | | |
423 | 19 | memset (&incv, 0, sizeof (incv)); |
424 | 19 | incv.X_unsigned = 1; |
425 | 19 | incv.X_op = O_symbol; |
426 | 19 | incv.X_add_symbol = p->loc.u.view; |
427 | 19 | incv.X_add_number = 1; |
428 | 19 | p_view = symbol_get_value_expression (p->loc.u.view); |
429 | 19 | if (p_view->X_op == O_constant || p_view->X_op == O_symbol) |
430 | 19 | { |
431 | | /* If we can, constant fold increments so that a chain of |
432 | | expressions v + 1 + 1 ... + 1 is not created. |
433 | | resolve_expression isn't ideal for this purpose. The |
434 | | base v might not be resolvable until later. */ |
435 | 19 | incv.X_op = p_view->X_op; |
436 | 19 | incv.X_add_symbol = p_view->X_add_symbol; |
437 | 19 | incv.X_add_number = p_view->X_add_number + 1; |
438 | 19 | } |
439 | | |
440 | 19 | if (viewx.X_op == O_constant) |
441 | 19 | { |
442 | 19 | gas_assert (viewx.X_add_number == 1); |
443 | 19 | viewx = incv; |
444 | 19 | } |
445 | 0 | else |
446 | 0 | { |
447 | 0 | viewx.X_add_symbol = make_expr_symbol (&viewx); |
448 | 0 | viewx.X_add_number = 0; |
449 | 0 | viewx.X_op_symbol = make_expr_symbol (&incv); |
450 | 0 | viewx.X_op = O_multiply; |
451 | 0 | } |
452 | 19 | } |
453 | | |
454 | 12.9k | if (!S_IS_DEFINED (e->loc.u.view)) |
455 | 24 | { |
456 | 24 | symbol_set_value_expression (e->loc.u.view, &viewx); |
457 | 24 | S_SET_SEGMENT (e->loc.u.view, expr_section); |
458 | 24 | symbol_set_frag (e->loc.u.view, &zero_address_frag); |
459 | 24 | } |
460 | | |
461 | | /* Define and attempt to simplify any earlier views needed to |
462 | | compute E's. */ |
463 | 12.9k | if (h && p && p->loc.u.view && !S_IS_DEFINED (p->loc.u.view)) |
464 | 11 | { |
465 | 11 | struct line_entry *h2; |
466 | | /* Reverse the list to avoid quadratic behavior going backwards |
467 | | in a single-linked list. */ |
468 | 11 | struct line_entry *r = reverse_line_entry_list (h); |
469 | | |
470 | 11 | gas_assert (r == p); |
471 | | /* Set or check views until we find a defined or absent view. */ |
472 | 11 | do |
473 | 11 | { |
474 | | /* Do not define the head of a (sub?)segment view while |
475 | | handling others. It would be defined too early, without |
476 | | regard to the last view of other subsegments. |
477 | | set_or_check_view will be called for every head segment |
478 | | that needs it. */ |
479 | 11 | if (r == h) |
480 | 5 | break; |
481 | 6 | set_or_check_view (r, r->next, NULL); |
482 | 6 | } |
483 | 11 | while (r->next |
484 | 6 | && r->next->loc.u.view |
485 | 0 | && !S_IS_DEFINED (r->next->loc.u.view) |
486 | 0 | && (r = r->next)); |
487 | | |
488 | | /* Unreverse the list, so that we can go forward again. */ |
489 | 11 | h2 = reverse_line_entry_list (p); |
490 | 11 | gas_assert (h2 == h); |
491 | | |
492 | | /* Starting from the last view we just defined, attempt to |
493 | | simplify the view expressions, until we do so to P. */ |
494 | 11 | do |
495 | 11 | { |
496 | | /* The head view of a subsegment may remain undefined while |
497 | | handling other elements, before it is linked to the last |
498 | | view of the previous subsegment. */ |
499 | 11 | if (r == h) |
500 | 5 | continue; |
501 | 6 | gas_assert (S_IS_DEFINED (r->loc.u.view)); |
502 | 6 | resolve_expression (symbol_get_value_expression (r->loc.u.view)); |
503 | 6 | } |
504 | 11 | while (r != p && (r = r->next)); |
505 | | |
506 | | /* Now that we've defined and computed all earlier views that might |
507 | | be needed to compute E's, attempt to simplify it. */ |
508 | 11 | resolve_expression (symbol_get_value_expression (e->loc.u.view)); |
509 | 11 | } |
510 | 12.9k | } |
511 | | |
512 | | /* Record an entry for LOC occurring at LABEL. */ |
513 | | |
514 | | static void |
515 | | dwarf2_gen_line_info_1 (symbolS *label, struct dwarf2_line_info *loc) |
516 | 13.5k | { |
517 | 13.5k | struct line_subseg *lss; |
518 | 13.5k | struct line_entry *e; |
519 | 13.5k | flagword need_flags = SEC_LOAD | SEC_CODE; |
520 | | |
521 | | /* PR 26850: Do not record LOCs in non-executable or non-loaded |
522 | | sections. SEC_ALLOC isn't tested for non-ELF because obj-coff.c |
523 | | obj_coff_section is careless in setting SEC_ALLOC. */ |
524 | 13.5k | if (IS_ELF) |
525 | 13.5k | need_flags |= SEC_ALLOC; |
526 | 13.5k | if ((now_seg->flags & need_flags) != need_flags) |
527 | 9 | { |
528 | | /* FIXME: Add code to suppress multiple warnings ? */ |
529 | 9 | if (debug_type != DEBUG_DWARF2) |
530 | 9 | as_warn ("dwarf line number information for %s ignored", |
531 | 9 | segment_name (now_seg)); |
532 | 9 | return; |
533 | 9 | } |
534 | | |
535 | 13.5k | e = XNEW (struct line_entry); |
536 | 13.5k | e->next = NULL; |
537 | 13.5k | e->label = label; |
538 | 13.5k | e->loc = *loc; |
539 | | |
540 | 13.5k | lss = get_line_subseg (now_seg, now_subseg, true); |
541 | | |
542 | | /* Subseg heads are chained to previous subsegs in |
543 | | dwarf2_finish. */ |
544 | 13.5k | if (loc->filenum != -1u && loc->u.view && lss->head) |
545 | 12.9k | set_or_check_view (e, line_entry_at_tail (lss->head, lss->ptail), |
546 | 12.9k | lss->head); |
547 | | |
548 | 13.5k | *lss->ptail = e; |
549 | 13.5k | lss->ptail = &e->next; |
550 | 13.5k | } |
551 | | |
552 | | /* Record an entry for LOC occurring at OFS within the current fragment. */ |
553 | | |
554 | | static unsigned int dw2_line; |
555 | | static const char *dw2_filename; |
556 | | static int label_num; |
557 | | |
558 | | void |
559 | | dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc) |
560 | 26.1k | { |
561 | 26.1k | symbolS *sym; |
562 | | |
563 | | /* Early out for as-yet incomplete location information. */ |
564 | 26.1k | if (loc->line == 0) |
565 | 12.8k | return; |
566 | 13.2k | if (loc->filenum == 0) |
567 | 13.2k | { |
568 | 13.2k | if (dwarf_level < 5) |
569 | 0 | dwarf_level = 5; |
570 | 13.2k | if (DWARF2_LINE_VERSION < 5) |
571 | 0 | return; |
572 | 13.2k | } |
573 | | |
574 | | /* Don't emit sequences of line symbols for the same line when the |
575 | | symbols apply to assembler code. It is necessary to emit |
576 | | duplicate line symbols when a compiler asks for them, because GDB |
577 | | uses them to determine the end of the prologue. */ |
578 | 13.2k | if (debug_type == DEBUG_DWARF2) |
579 | 0 | { |
580 | 0 | if (dw2_line == loc->line) |
581 | 0 | { |
582 | 0 | if (dw2_filename == loc->u.filename) |
583 | 0 | return; |
584 | 0 | if (filename_cmp (dw2_filename, loc->u.filename) == 0) |
585 | 0 | { |
586 | 0 | dw2_filename = loc->u.filename; |
587 | 0 | return; |
588 | 0 | } |
589 | 0 | } |
590 | | |
591 | 0 | dw2_line = loc->line; |
592 | 0 | dw2_filename = loc->u.filename; |
593 | 0 | } |
594 | | |
595 | 13.2k | if (linkrelax) |
596 | 0 | { |
597 | 0 | char name[32]; |
598 | | |
599 | | /* Use a non-fake name for the line number location, |
600 | | so that it can be referred to by relocations. */ |
601 | 0 | sprintf (name, ".Loc.%u", label_num); |
602 | 0 | label_num++; |
603 | 0 | sym = symbol_new (name, now_seg, frag_now, ofs); |
604 | 0 | } |
605 | 13.2k | else |
606 | 13.2k | sym = symbol_temp_new (now_seg, frag_now, ofs); |
607 | 13.2k | dwarf2_gen_line_info_1 (sym, loc); |
608 | 13.2k | } |
609 | | |
610 | | static const char * |
611 | | get_basename (const char * pathname) |
612 | 25.7k | { |
613 | 25.7k | const char * file; |
614 | | |
615 | 25.7k | file = lbasename (pathname); |
616 | | /* Don't make empty string from / or A: from A:/ . */ |
617 | | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
618 | | if (file <= pathname + 3) |
619 | | file = pathname; |
620 | | #else |
621 | 25.7k | if (file == pathname + 1) |
622 | 1 | file = pathname; |
623 | 25.7k | #endif |
624 | 25.7k | return file; |
625 | 25.7k | } |
626 | | |
627 | | static unsigned int |
628 | | get_directory_table_entry (const char *dirname, |
629 | | const char *file0_dirname, |
630 | | size_t dirlen, |
631 | | bool can_use_zero) |
632 | 73 | { |
633 | 73 | unsigned int d; |
634 | | |
635 | 73 | if (dirlen == 0) |
636 | 37 | return 0; |
637 | | |
638 | 36 | #ifndef DWARF2_DIR_SHOULD_END_WITH_SEPARATOR |
639 | 36 | if (IS_DIR_SEPARATOR (dirname[dirlen - 1])) |
640 | 18 | { |
641 | 18 | -- dirlen; |
642 | 18 | if (dirlen == 0) |
643 | 0 | return 0; |
644 | 18 | } |
645 | 36 | #endif |
646 | | |
647 | 91 | for (d = 0; d < dirs_in_use; ++d) |
648 | 55 | { |
649 | 55 | if (dirs[d] != NULL |
650 | 47 | && filename_ncmp (dirname, dirs[d], dirlen) == 0 |
651 | 0 | && dirs[d][dirlen] == '\0') |
652 | 0 | return d; |
653 | 55 | } |
654 | | |
655 | 36 | if (can_use_zero) |
656 | 23 | { |
657 | 23 | if (dirs == NULL || dirs[0] == NULL) |
658 | 23 | { |
659 | 23 | const char * pwd = file0_dirname ? file0_dirname : getpwd (); |
660 | | |
661 | 23 | if (dwarf_level >= 5 && filename_cmp (dirname, pwd) != 0) |
662 | 7 | { |
663 | | /* In DWARF-5 the 0 entry in the directory table is |
664 | | expected to be the same as the DW_AT_comp_dir (which |
665 | | is set to the current build directory). Since we are |
666 | | about to create a directory entry that is not the |
667 | | same, allocate the current directory first. */ |
668 | 7 | (void) get_directory_table_entry (pwd, pwd, strlen (pwd), true); |
669 | 7 | d = dirs_in_use; |
670 | 7 | } |
671 | 16 | else |
672 | 16 | d = 0; |
673 | 23 | } |
674 | 23 | } |
675 | 13 | else if (d == 0) |
676 | 4 | d = 1; |
677 | | |
678 | 36 | if (d >= dirs_allocated) |
679 | 19 | { |
680 | 19 | unsigned int old = dirs_allocated; |
681 | 19 | #define DIR_TABLE_INCREMENT 32 |
682 | 19 | dirs_allocated = d + DIR_TABLE_INCREMENT; |
683 | 19 | dirs = XRESIZEVEC (char *, dirs, dirs_allocated); |
684 | 19 | memset (dirs + old, 0, (dirs_allocated - old) * sizeof (char *)); |
685 | 19 | } |
686 | | |
687 | 36 | dirs[d] = xmemdup0 (dirname, dirlen); |
688 | 36 | if (dirs_in_use <= d) |
689 | 35 | dirs_in_use = d + 1; |
690 | | |
691 | 36 | return d; |
692 | 36 | } |
693 | | |
694 | | static bool |
695 | | assign_file_to_slot (valueT i, const char *file, unsigned int dir) |
696 | 66 | { |
697 | 66 | if (i >= files_allocated) |
698 | 60 | { |
699 | 60 | unsigned int want = i + 32; |
700 | | |
701 | | /* If this array is taking 1G or more, someone is using silly |
702 | | file numbers. */ |
703 | 60 | if (want < i || want > UINT_MAX / 4 / sizeof (struct file_entry)) |
704 | 12 | { |
705 | 12 | as_bad (_("file number %" PRIu64 " is too big"), (uint64_t) i); |
706 | 12 | return false; |
707 | 12 | } |
708 | | |
709 | 48 | files = XRESIZEVEC (struct file_entry, files, want); |
710 | 48 | memset (files + files_allocated, 0, |
711 | 48 | (want - files_allocated) * sizeof (struct file_entry)); |
712 | 48 | files_allocated = want; |
713 | 48 | } |
714 | | |
715 | 54 | files[i].filename = file; |
716 | 54 | files[i].dir = dir; |
717 | 54 | memset (files[i].md5, 0, NUM_MD5_BYTES); |
718 | | |
719 | 54 | if (files_in_use < i + 1) |
720 | 48 | files_in_use = i + 1; |
721 | | |
722 | 54 | return true; |
723 | 66 | } |
724 | | |
725 | | /* Get a .debug_line file number for PATHNAME. If there is a |
726 | | directory component to PATHNAME, then this will be stored |
727 | | in the directory table, if it is not already present. |
728 | | Returns the slot number allocated to that filename or -1 |
729 | | if there was a problem. */ |
730 | | |
731 | | static int last_used; |
732 | | static int last_used_dir_len; |
733 | | |
734 | | static signed int |
735 | | allocate_filenum (const char * pathname) |
736 | 0 | { |
737 | 0 | const char *file; |
738 | 0 | size_t dir_len; |
739 | 0 | unsigned int i, dir; |
740 | | |
741 | | /* Short circuit the common case of adding the same pathname |
742 | | as last time. */ |
743 | 0 | if (last_used != -1) |
744 | 0 | { |
745 | 0 | const char * dirname = NULL; |
746 | |
|
747 | 0 | if (dirs != NULL) |
748 | 0 | dirname = dirs[files[last_used].dir]; |
749 | |
|
750 | 0 | if (dirname == NULL) |
751 | 0 | { |
752 | 0 | if (filename_cmp (pathname, files[last_used].filename) == 0) |
753 | 0 | return last_used; |
754 | 0 | } |
755 | 0 | else |
756 | 0 | { |
757 | 0 | if (filename_ncmp (pathname, dirname, last_used_dir_len - 1) == 0 |
758 | 0 | && IS_DIR_SEPARATOR (pathname [last_used_dir_len - 1]) |
759 | 0 | && filename_cmp (pathname + last_used_dir_len, |
760 | 0 | files[last_used].filename) == 0) |
761 | 0 | return last_used; |
762 | 0 | } |
763 | 0 | } |
764 | | |
765 | 0 | file = get_basename (pathname); |
766 | 0 | dir_len = file - pathname; |
767 | |
|
768 | 0 | dir = get_directory_table_entry (pathname, NULL, dir_len, false); |
769 | | |
770 | | /* Do not use slot-0. That is specifically reserved for use by |
771 | | the '.file 0 "name"' directive. */ |
772 | 0 | for (i = 1; i < files_in_use; ++i) |
773 | 0 | if (files[i].dir == dir |
774 | 0 | && files[i].filename |
775 | 0 | && filename_cmp (file, files[i].filename) == 0) |
776 | 0 | { |
777 | 0 | last_used = i; |
778 | 0 | last_used_dir_len = dir_len; |
779 | 0 | return i; |
780 | 0 | } |
781 | | |
782 | 0 | if (!assign_file_to_slot (i, file, dir)) |
783 | 0 | return -1; |
784 | | |
785 | 0 | last_used = i; |
786 | 0 | last_used_dir_len = dir_len; |
787 | |
|
788 | 0 | return i; |
789 | 0 | } |
790 | | |
791 | | /* Run through the list of line entries starting at E, allocating |
792 | | file entries for gas generated debug. */ |
793 | | |
794 | | static void |
795 | | do_allocate_filenum (struct line_entry *e) |
796 | 48 | { |
797 | 48 | do |
798 | 13.5k | { |
799 | 13.5k | if (e->loc.filenum == -1u) |
800 | 0 | { |
801 | 0 | e->loc.filenum = allocate_filenum (e->loc.u.filename); |
802 | 0 | e->loc.u.view = NULL; |
803 | 0 | } |
804 | 13.5k | e = e->next; |
805 | 13.5k | } |
806 | 13.5k | while (e); |
807 | 48 | } |
808 | | |
809 | | /* Remove any generated line entries. These don't live comfortably |
810 | | with compiler generated line info. If THELOT then remove |
811 | | everything, freeing all list entries we have created. */ |
812 | | |
813 | | static void |
814 | | purge_generated_debug (bool thelot) |
815 | 339 | { |
816 | 339 | struct line_seg *s, *nexts; |
817 | | |
818 | 383 | for (s = all_segs; s; s = nexts) |
819 | 44 | { |
820 | 44 | struct line_subseg *lss, *nextlss; |
821 | | |
822 | 92 | for (lss = s->head; lss; lss = nextlss) |
823 | 48 | { |
824 | 48 | struct line_entry *e, *next; |
825 | | |
826 | 13.5k | for (e = lss->head; e; e = next) |
827 | 13.5k | { |
828 | 13.5k | if (!thelot) |
829 | 13.5k | know (e->loc.filenum == -1u); |
830 | 13.5k | next = e->next; |
831 | 13.5k | free (e); |
832 | 13.5k | } |
833 | | |
834 | 48 | lss->head = NULL; |
835 | 48 | lss->ptail = &lss->head; |
836 | 48 | lss->pmove_tail = &lss->head; |
837 | 48 | nextlss = lss->next; |
838 | 48 | if (thelot) |
839 | 48 | free (lss); |
840 | 48 | } |
841 | 44 | nexts = s->next; |
842 | 44 | if (thelot) |
843 | 44 | { |
844 | 44 | seg_info (s->seg)->dwarf2_line_seg = NULL; |
845 | 44 | free (s); |
846 | 44 | } |
847 | 44 | } |
848 | 339 | } |
849 | | |
850 | | /* Allocate slot NUM in the .debug_line file table to FILENAME. |
851 | | If DIRNAME is not NULL or there is a directory component to FILENAME |
852 | | then this will be stored in the directory table, if not already present. |
853 | | if WITH_MD5 is TRUE then there is a md5 value in generic_bignum. |
854 | | Returns TRUE if allocation succeeded, FALSE otherwise. */ |
855 | | |
856 | | static bool |
857 | | allocate_filename_to_slot (const char *dirname, |
858 | | const char *filename, |
859 | | valueT num, |
860 | | bool with_md5) |
861 | 26.1k | { |
862 | 26.1k | const char *file; |
863 | 26.1k | size_t dirlen; |
864 | 26.1k | unsigned int i, d; |
865 | 26.1k | const char *file0_dirname; |
866 | | |
867 | | /* Short circuit the common case of adding the same pathname |
868 | | as last time. */ |
869 | 26.1k | if (num < files_allocated && files[num].filename != NULL) |
870 | 26.1k | { |
871 | 26.1k | const char * dir = NULL; |
872 | | |
873 | 26.1k | if (dirs != NULL) |
874 | 467 | dir = dirs[files[num].dir]; |
875 | | |
876 | 26.1k | if (with_md5 |
877 | 0 | && memcmp (generic_bignum, files[num].md5, NUM_MD5_BYTES) != 0) |
878 | 0 | goto fail; |
879 | | |
880 | 26.1k | if (dirname != NULL) |
881 | 261 | { |
882 | 261 | if (dir != NULL && filename_cmp (dir, dirname) != 0) |
883 | 193 | goto fail; |
884 | | |
885 | 68 | if (filename_cmp (filename, files[num].filename) != 0) |
886 | 3 | goto fail; |
887 | | |
888 | | /* If the filenames match, but the directory table entry was |
889 | | empty, then fill it with the provided directory name. */ |
890 | 65 | if (dir == NULL) |
891 | 0 | { |
892 | 0 | if (dirs == NULL) |
893 | 0 | { |
894 | 0 | dirs_allocated = files[num].dir + DIR_TABLE_INCREMENT; |
895 | 0 | dirs = XCNEWVEC (char *, dirs_allocated); |
896 | 0 | } |
897 | | |
898 | 0 | dirs[files[num].dir] = xmemdup0 (dirname, strlen (dirname)); |
899 | 0 | if (dirs_in_use <= files[num].dir) |
900 | 0 | dirs_in_use = files[num].dir + 1; |
901 | 0 | } |
902 | | |
903 | 65 | return true; |
904 | 68 | } |
905 | 25.8k | else if (dir != NULL) |
906 | 206 | { |
907 | 206 | dirlen = strlen (dir); |
908 | 206 | if (filename_ncmp (filename, dir, dirlen) == 0 |
909 | 206 | && IS_DIR_SEPARATOR (filename [dirlen]) |
910 | 206 | && filename_cmp (filename + dirlen + 1, files[num].filename) == 0) |
911 | 203 | return true; |
912 | 206 | } |
913 | 25.6k | else /* dir == NULL */ |
914 | 25.6k | { |
915 | 25.6k | file = get_basename (filename); |
916 | 25.6k | if (filename_cmp (file, files[num].filename) == 0) |
917 | 12.8k | { |
918 | | /* The filenames match, but the directory table entry is empty. |
919 | | Fill it with the provided directory name. */ |
920 | 12.8k | if (file > filename) |
921 | 0 | { |
922 | 0 | if (dirs == NULL) |
923 | 0 | { |
924 | 0 | dirs_allocated = files[num].dir + DIR_TABLE_INCREMENT; |
925 | 0 | dirs = XCNEWVEC (char *, dirs_allocated); |
926 | 0 | } |
927 | |
|
928 | 0 | dirs[files[num].dir] = xmemdup0 (filename, file - filename); |
929 | 0 | if (dirs_in_use <= files[num].dir) |
930 | 0 | dirs_in_use = files[num].dir + 1; |
931 | 0 | } |
932 | 12.8k | return true; |
933 | 12.8k | } |
934 | 25.6k | } |
935 | | |
936 | 13.0k | fail: |
937 | 13.0k | as_bad (_("file table slot %u is already occupied by a different file" |
938 | 13.0k | " (%s%s%s vs %s%s%s)"), |
939 | 13.0k | (unsigned int) num, |
940 | 13.0k | dir == NULL ? "" : dir, |
941 | 13.0k | dir == NULL ? "" : "/", |
942 | 13.0k | files[num].filename, |
943 | 13.0k | dirname == NULL ? "" : dirname, |
944 | 13.0k | dirname == NULL ? "" : "/", |
945 | 13.0k | filename); |
946 | 13.0k | return false; |
947 | 26.1k | } |
948 | | |
949 | | /* For file .0, the directory name is the current directory and the file |
950 | | may be in another directory contained in the file name. */ |
951 | 66 | if (num == 0) |
952 | 41 | { |
953 | 41 | file0_dirname = dirname; |
954 | | |
955 | 41 | file = get_basename (filename); |
956 | | |
957 | 41 | if (dirname && file == filename) |
958 | 10 | dirlen = strlen (dirname); |
959 | 31 | else |
960 | 31 | { |
961 | 31 | dirname = filename; |
962 | 31 | dirlen = file - filename; |
963 | 31 | } |
964 | 41 | } |
965 | 25 | else |
966 | 25 | { |
967 | 25 | file0_dirname = NULL; |
968 | | |
969 | 25 | if (dirname == NULL) |
970 | 23 | { |
971 | 23 | dirname = filename; |
972 | 23 | file = get_basename (filename); |
973 | 23 | dirlen = file - filename; |
974 | 23 | } |
975 | 2 | else |
976 | 2 | { |
977 | 2 | dirlen = strlen (dirname); |
978 | 2 | file = filename; |
979 | 2 | } |
980 | 25 | } |
981 | | |
982 | 66 | d = get_directory_table_entry (dirname, file0_dirname, dirlen, num == 0); |
983 | 66 | i = num; |
984 | | |
985 | 66 | if (!assign_file_to_slot (num, file, d)) |
986 | 12 | return false; |
987 | | |
988 | 54 | if (with_md5) |
989 | 0 | { |
990 | 0 | if (target_big_endian) |
991 | 0 | { |
992 | | /* md5's are stored in litte endian format. */ |
993 | 0 | unsigned int bits_remaining = NUM_MD5_BYTES * BITS_PER_CHAR; |
994 | 0 | unsigned int byte = NUM_MD5_BYTES; |
995 | 0 | unsigned int bignum_index = 0; |
996 | |
|
997 | 0 | while (bits_remaining) |
998 | 0 | { |
999 | 0 | unsigned int bignum_bits_remaining = LITTLENUM_NUMBER_OF_BITS; |
1000 | 0 | valueT bignum_value = generic_bignum [bignum_index]; |
1001 | 0 | bignum_index ++; |
1002 | |
|
1003 | 0 | while (bignum_bits_remaining) |
1004 | 0 | { |
1005 | 0 | files[i].md5[--byte] = bignum_value & 0xff; |
1006 | 0 | bignum_value >>= 8; |
1007 | 0 | bignum_bits_remaining -= 8; |
1008 | 0 | bits_remaining -= 8; |
1009 | 0 | } |
1010 | 0 | } |
1011 | 0 | } |
1012 | 0 | else |
1013 | 0 | { |
1014 | 0 | unsigned int bits_remaining = NUM_MD5_BYTES * BITS_PER_CHAR; |
1015 | 0 | unsigned int byte = 0; |
1016 | 0 | unsigned int bignum_index = 0; |
1017 | |
|
1018 | 0 | while (bits_remaining) |
1019 | 0 | { |
1020 | 0 | unsigned int bignum_bits_remaining = LITTLENUM_NUMBER_OF_BITS; |
1021 | 0 | valueT bignum_value = generic_bignum [bignum_index]; |
1022 | |
|
1023 | 0 | bignum_index ++; |
1024 | |
|
1025 | 0 | while (bignum_bits_remaining) |
1026 | 0 | { |
1027 | 0 | files[i].md5[byte++] = bignum_value & 0xff; |
1028 | 0 | bignum_value >>= 8; |
1029 | 0 | bignum_bits_remaining -= 8; |
1030 | 0 | bits_remaining -= 8; |
1031 | 0 | } |
1032 | 0 | } |
1033 | 0 | } |
1034 | 0 | } |
1035 | 54 | else |
1036 | 54 | memset (files[i].md5, 0, NUM_MD5_BYTES); |
1037 | | |
1038 | 54 | return true; |
1039 | 66 | } |
1040 | | |
1041 | | /* Returns the current source information. If .file directives have |
1042 | | been encountered, the info for the corresponding source file is |
1043 | | returned. Otherwise, the info for the assembly source file is |
1044 | | returned. */ |
1045 | | |
1046 | | void |
1047 | | dwarf2_where (struct dwarf2_line_info *line) |
1048 | 26.3k | { |
1049 | 26.3k | if (debug_type == DEBUG_DWARF2) |
1050 | 0 | { |
1051 | 0 | line->u.filename = as_where (&line->line); |
1052 | 0 | line->filenum = -1u; |
1053 | 0 | line->column = 0; |
1054 | 0 | line->flags = DWARF2_FLAG_IS_STMT; |
1055 | 0 | line->isa = current.isa; |
1056 | 0 | line->discriminator = current.discriminator; |
1057 | 0 | } |
1058 | 26.3k | else |
1059 | 26.3k | *line = current; |
1060 | 26.3k | } |
1061 | | |
1062 | | /* A hook to allow the target backend to inform the line number state |
1063 | | machine of isa changes when assembler debug info is enabled. */ |
1064 | | |
1065 | | void |
1066 | | dwarf2_set_isa (unsigned int isa) |
1067 | 0 | { |
1068 | 0 | current.isa = isa; |
1069 | 0 | } |
1070 | | |
1071 | | /* Called for each machine instruction, or relatively atomic group of |
1072 | | machine instructions (ie built-in macro). The instruction or group |
1073 | | is SIZE bytes in length. If dwarf2 line number generation is called |
1074 | | for, emit a line statement appropriately. */ |
1075 | | |
1076 | | void |
1077 | | dwarf2_emit_insn (int size) |
1078 | 51.6k | { |
1079 | 51.6k | struct dwarf2_line_info loc; |
1080 | | |
1081 | 51.6k | seg_info (now_seg)->insn_seen = 1; |
1082 | | |
1083 | 51.6k | if (debug_type != DEBUG_DWARF2 |
1084 | 51.6k | ? !dwarf2_loc_directive_seen |
1085 | 51.6k | : !seen_at_least_1_file ()) |
1086 | 25.5k | return; |
1087 | | |
1088 | 26.1k | dwarf2_where (&loc); |
1089 | | |
1090 | 26.1k | dwarf2_gen_line_info ((frag_now_fix_octets () - size) / OCTETS_PER_BYTE, &loc); |
1091 | 26.1k | dwarf2_consume_line_info (); |
1092 | 26.1k | } |
1093 | | |
1094 | | /* Move all previously-emitted line entries for the current position by |
1095 | | DELTA bytes. This function cannot be used to move the same entries |
1096 | | twice. */ |
1097 | | |
1098 | | void |
1099 | | dwarf2_move_insn (int delta) |
1100 | 0 | { |
1101 | 0 | struct line_subseg *lss; |
1102 | 0 | struct line_entry *e; |
1103 | 0 | valueT now; |
1104 | |
|
1105 | 0 | if (delta == 0) |
1106 | 0 | return; |
1107 | | |
1108 | 0 | lss = get_line_subseg (now_seg, now_subseg, false); |
1109 | 0 | if (!lss) |
1110 | 0 | return; |
1111 | | |
1112 | 0 | now = frag_now_fix (); |
1113 | 0 | while ((e = *lss->pmove_tail)) |
1114 | 0 | { |
1115 | 0 | if (S_GET_VALUE (e->label) == now) |
1116 | 0 | S_SET_VALUE (e->label, now + delta); |
1117 | 0 | lss->pmove_tail = &e->next; |
1118 | 0 | } |
1119 | 0 | } |
1120 | | |
1121 | | /* Called after the current line information has been either used with |
1122 | | dwarf2_gen_line_info or saved with a machine instruction for later use. |
1123 | | This resets the state of the line number information to reflect that |
1124 | | it has been used. */ |
1125 | | |
1126 | | void |
1127 | | dwarf2_consume_line_info (void) |
1128 | 26.3k | { |
1129 | | /* Unless we generate DWARF2 debugging information for each |
1130 | | assembler line, we only emit one line symbol for one LOC. */ |
1131 | 26.3k | dwarf2_loc_directive_seen = false; |
1132 | | |
1133 | 26.3k | current.flags &= ~(DWARF2_FLAG_BASIC_BLOCK |
1134 | 26.3k | | DWARF2_FLAG_PROLOGUE_END |
1135 | 26.3k | | DWARF2_FLAG_EPILOGUE_BEGIN); |
1136 | 26.3k | current.discriminator = 0; |
1137 | 26.3k | current.u.view = NULL; |
1138 | 26.3k | } |
1139 | | |
1140 | | /* Called for each (preferably code) label. If dwarf2_loc_mark_labels |
1141 | | is enabled, emit a basic block marker. */ |
1142 | | |
1143 | | void |
1144 | | dwarf2_emit_label (symbolS *label) |
1145 | 9.90k | { |
1146 | 9.90k | struct dwarf2_line_info loc; |
1147 | | |
1148 | 9.90k | if (!dwarf2_loc_mark_labels) |
1149 | 9.60k | return; |
1150 | 293 | if (S_GET_SEGMENT (label) != now_seg) |
1151 | 7 | return; |
1152 | 286 | if (!(bfd_section_flags (now_seg) & SEC_CODE)) |
1153 | 0 | return; |
1154 | 286 | if (files_in_use == 0 && debug_type != DEBUG_DWARF2) |
1155 | 0 | return; |
1156 | | |
1157 | 286 | dwarf2_where (&loc); |
1158 | | |
1159 | 286 | loc.flags |= DWARF2_FLAG_BASIC_BLOCK; |
1160 | | |
1161 | 286 | dwarf2_gen_line_info_1 (label, &loc); |
1162 | 286 | dwarf2_consume_line_info (); |
1163 | 286 | } |
1164 | | |
1165 | | /* Handle two forms of .file directive: |
1166 | | - Pass .file "source.c" to s_file |
1167 | | - Handle .file 1 "source.c" by adding an entry to the DWARF-2 file table |
1168 | | |
1169 | | If an entry is added to the file table, return a pointer to the filename. */ |
1170 | | |
1171 | | char * |
1172 | | dwarf2_directive_filename (void) |
1173 | 27.4k | { |
1174 | 27.4k | bool with_md5 = false; |
1175 | 27.4k | valueT num; |
1176 | 27.4k | char *filename; |
1177 | 27.4k | const char * dirname = NULL; |
1178 | 27.4k | int filename_len; |
1179 | | |
1180 | | /* Continue to accept a bare string and pass it off. */ |
1181 | 27.4k | SKIP_WHITESPACE (); |
1182 | 27.4k | if (*input_line_pointer == '"') |
1183 | 33 | { |
1184 | 33 | s_file (0); |
1185 | 33 | return NULL; |
1186 | 33 | } |
1187 | | |
1188 | 27.4k | num = get_absolute_expression (); |
1189 | | |
1190 | 27.4k | if ((offsetT) num < 1) |
1191 | 27.4k | { |
1192 | 27.4k | if (num == 0 && dwarf_level < 5) |
1193 | 1 | dwarf_level = 5; |
1194 | 27.4k | if ((offsetT) num < 0 || DWARF2_LINE_VERSION < 5) |
1195 | 0 | { |
1196 | 0 | as_bad (_("file number less than one")); |
1197 | 0 | ignore_rest_of_line (); |
1198 | 0 | return NULL; |
1199 | 0 | } |
1200 | 27.4k | } |
1201 | | |
1202 | | /* FIXME: Should we allow ".file <N>\n" as an expression meaning |
1203 | | "switch back to the already allocated file <N> as the current |
1204 | | file" ? */ |
1205 | | |
1206 | 27.4k | filename = demand_copy_C_string (&filename_len); |
1207 | 27.4k | if (filename == NULL) |
1208 | 1.25k | { |
1209 | | /* demand_copy_C_string will have already generated an error. */ |
1210 | 1.25k | ignore_rest_of_line (); |
1211 | 1.25k | return NULL; |
1212 | 1.25k | } |
1213 | | |
1214 | | /* For DWARF-5 support we also accept: |
1215 | | .file <NUM> ["<dir>"] "<file>" [md5 <NUM>] */ |
1216 | 26.1k | if (DWARF2_LINE_VERSION > 4) |
1217 | 26.1k | { |
1218 | 26.1k | SKIP_WHITESPACE (); |
1219 | 26.1k | if (*input_line_pointer == '"') |
1220 | 273 | { |
1221 | 273 | dirname = filename; |
1222 | 273 | filename = demand_copy_C_string (&filename_len); |
1223 | 273 | if (filename == NULL) |
1224 | 0 | { |
1225 | 0 | ignore_rest_of_line (); |
1226 | 0 | return NULL; |
1227 | 0 | } |
1228 | 273 | SKIP_WHITESPACE (); |
1229 | 273 | } |
1230 | | |
1231 | 26.1k | if (startswith (input_line_pointer, "md5")) |
1232 | 0 | { |
1233 | 0 | input_line_pointer += 3; |
1234 | 0 | SKIP_WHITESPACE (); |
1235 | |
|
1236 | 0 | expressionS exp; |
1237 | 0 | expression_and_evaluate (& exp); |
1238 | 0 | if (exp.X_op != O_big) |
1239 | 0 | as_bad (_("md5 value too small or not a constant")); |
1240 | 0 | else |
1241 | 0 | with_md5 = true; |
1242 | 0 | } |
1243 | 26.1k | } |
1244 | | |
1245 | 26.1k | demand_empty_rest_of_line (); |
1246 | | |
1247 | | /* A .file directive implies compiler generated debug information is |
1248 | | being supplied. Turn off gas generated debug info. */ |
1249 | 26.1k | if (debug_type == DEBUG_DWARF2) |
1250 | 0 | purge_generated_debug (false); |
1251 | 26.1k | debug_type = DEBUG_NONE; |
1252 | | |
1253 | 26.1k | if (!allocate_filename_to_slot (dirname, filename, num, with_md5)) |
1254 | 13.0k | return NULL; |
1255 | | |
1256 | 13.1k | return filename; |
1257 | 26.1k | } |
1258 | | |
1259 | | /* Calls dwarf2_directive_filename, but discards its result. |
1260 | | Used in pseudo-op tables where the function result is ignored. */ |
1261 | | |
1262 | | void |
1263 | | dwarf2_directive_file (int dummy ATTRIBUTE_UNUSED) |
1264 | 27.4k | { |
1265 | 27.4k | (void) dwarf2_directive_filename (); |
1266 | 27.4k | } |
1267 | | |
1268 | | void |
1269 | | dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED) |
1270 | 33.7k | { |
1271 | 33.7k | offsetT filenum, line; |
1272 | | |
1273 | | /* If we see two .loc directives in a row, force the first one to be |
1274 | | output now. */ |
1275 | 33.7k | if (dwarf2_loc_directive_seen) |
1276 | 13.1k | dwarf2_emit_insn (0); |
1277 | | |
1278 | 33.7k | filenum = get_absolute_expression (); |
1279 | 33.7k | SKIP_WHITESPACE (); |
1280 | 33.7k | line = get_absolute_expression (); |
1281 | | |
1282 | 33.7k | if (filenum < 1) |
1283 | 33.7k | { |
1284 | 33.7k | if (filenum == 0 && dwarf_level < 5) |
1285 | 0 | dwarf_level = 5; |
1286 | 33.7k | if (filenum < 0 || DWARF2_LINE_VERSION < 5) |
1287 | 0 | { |
1288 | 0 | as_bad (_("file number less than one")); |
1289 | 0 | return; |
1290 | 0 | } |
1291 | 33.7k | } |
1292 | | |
1293 | 33.7k | if ((valueT) filenum >= files_in_use || files[filenum].filename == NULL) |
1294 | 7.52k | { |
1295 | 7.52k | as_bad (_("unassigned file number %ld"), (long) filenum); |
1296 | 7.52k | return; |
1297 | 7.52k | } |
1298 | | |
1299 | | /* debug_type will be turned off by dwarf2_directive_filename, and |
1300 | | if we don't have a dwarf style .file then files_in_use will be |
1301 | | zero and the above error will trigger. */ |
1302 | 26.2k | gas_assert (debug_type == DEBUG_NONE); |
1303 | | |
1304 | 26.2k | current.filenum = filenum; |
1305 | 26.2k | current.line = line; |
1306 | 26.2k | current.discriminator = 0; |
1307 | | |
1308 | 26.2k | #ifndef NO_LISTING |
1309 | 26.2k | if (listing) |
1310 | 0 | { |
1311 | 0 | if (files[filenum].dir) |
1312 | 0 | { |
1313 | 0 | size_t dir_len = strlen (dirs[files[filenum].dir]); |
1314 | 0 | size_t file_len = strlen (files[filenum].filename); |
1315 | 0 | char *cp = XNEWVEC (char, dir_len + 1 + file_len + 1); |
1316 | |
|
1317 | 0 | memcpy (cp, dirs[files[filenum].dir], dir_len); |
1318 | 0 | INSERT_DIR_SEPARATOR (cp, dir_len); |
1319 | 0 | memcpy (cp + dir_len + 1, files[filenum].filename, file_len); |
1320 | 0 | cp[dir_len + file_len + 1] = '\0'; |
1321 | 0 | listing_source_file (cp); |
1322 | 0 | free (cp); |
1323 | 0 | } |
1324 | 0 | else |
1325 | 0 | listing_source_file (files[filenum].filename); |
1326 | 0 | listing_source_line (line); |
1327 | 0 | } |
1328 | 26.2k | #endif |
1329 | | |
1330 | 26.2k | SKIP_WHITESPACE (); |
1331 | 26.2k | if (ISDIGIT (*input_line_pointer)) |
1332 | 12.8k | { |
1333 | 12.8k | current.column = get_absolute_expression (); |
1334 | 12.8k | SKIP_WHITESPACE (); |
1335 | 12.8k | } |
1336 | | |
1337 | 26.2k | while (ISALPHA (*input_line_pointer)) |
1338 | 13.1k | { |
1339 | 13.1k | char *p, c; |
1340 | 13.1k | offsetT value; |
1341 | | |
1342 | 13.1k | c = get_symbol_name (& p); |
1343 | | |
1344 | 13.1k | if (strcmp (p, "basic_block") == 0) |
1345 | 0 | { |
1346 | 0 | current.flags |= DWARF2_FLAG_BASIC_BLOCK; |
1347 | 0 | restore_line_pointer (c); |
1348 | 0 | } |
1349 | 13.1k | else if (strcmp (p, "prologue_end") == 0) |
1350 | 0 | { |
1351 | 0 | if (dwarf_level < 3) |
1352 | 0 | dwarf_level = 3; |
1353 | 0 | current.flags |= DWARF2_FLAG_PROLOGUE_END; |
1354 | 0 | restore_line_pointer (c); |
1355 | 0 | } |
1356 | 13.1k | else if (strcmp (p, "epilogue_begin") == 0) |
1357 | 0 | { |
1358 | 0 | if (dwarf_level < 3) |
1359 | 0 | dwarf_level = 3; |
1360 | 0 | current.flags |= DWARF2_FLAG_EPILOGUE_BEGIN; |
1361 | 0 | restore_line_pointer (c); |
1362 | 0 | } |
1363 | 13.1k | else if (strcmp (p, "is_stmt") == 0) |
1364 | 24 | { |
1365 | 24 | (void) restore_line_pointer (c); |
1366 | 24 | value = get_absolute_expression (); |
1367 | 24 | if (value == 0) |
1368 | 18 | current.flags &= ~DWARF2_FLAG_IS_STMT; |
1369 | 6 | else if (value == 1) |
1370 | 6 | current.flags |= DWARF2_FLAG_IS_STMT; |
1371 | 0 | else |
1372 | 0 | { |
1373 | 0 | as_bad (_("is_stmt value not 0 or 1")); |
1374 | 0 | return; |
1375 | 0 | } |
1376 | 24 | } |
1377 | 13.1k | else if (strcmp (p, "isa") == 0) |
1378 | 73 | { |
1379 | 73 | if (dwarf_level < 3) |
1380 | 0 | dwarf_level = 3; |
1381 | 73 | (void) restore_line_pointer (c); |
1382 | 73 | value = get_absolute_expression (); |
1383 | 73 | if (value >= 0) |
1384 | 0 | current.isa = value; |
1385 | 73 | else |
1386 | 73 | { |
1387 | 73 | as_bad (_("isa number less than zero")); |
1388 | 73 | return; |
1389 | 73 | } |
1390 | 73 | } |
1391 | 13.0k | else if (strcmp (p, "discriminator") == 0) |
1392 | 6 | { |
1393 | 6 | (void) restore_line_pointer (c); |
1394 | 6 | value = get_absolute_expression (); |
1395 | 6 | if (value >= 0) |
1396 | 2 | current.discriminator = value; |
1397 | 4 | else |
1398 | 4 | { |
1399 | 4 | as_bad (_("discriminator less than zero")); |
1400 | 4 | return; |
1401 | 4 | } |
1402 | 6 | } |
1403 | 13.0k | else if (strcmp (p, "view") == 0) |
1404 | 12.9k | { |
1405 | 12.9k | symbolS *sym; |
1406 | | |
1407 | 12.9k | (void) restore_line_pointer (c); |
1408 | 12.9k | SKIP_WHITESPACE (); |
1409 | | |
1410 | 12.9k | if (ISDIGIT (*input_line_pointer) |
1411 | 163 | || *input_line_pointer == '-') |
1412 | 12.9k | { |
1413 | 12.9k | bool force_reset = *input_line_pointer == '-'; |
1414 | | |
1415 | 12.9k | value = get_absolute_expression (); |
1416 | 12.9k | if (value != 0) |
1417 | 2 | { |
1418 | 2 | as_bad (_("numeric view can only be asserted to zero")); |
1419 | 2 | return; |
1420 | 2 | } |
1421 | 12.9k | if (force_reset && force_reset_view) |
1422 | 135 | sym = force_reset_view; |
1423 | 12.8k | else |
1424 | 12.8k | { |
1425 | 12.8k | sym = symbol_temp_new (absolute_section, &zero_address_frag, |
1426 | 12.8k | value); |
1427 | 12.8k | if (force_reset) |
1428 | 8 | force_reset_view = sym; |
1429 | 12.8k | } |
1430 | 12.9k | } |
1431 | 20 | else |
1432 | 20 | { |
1433 | 20 | char *name = read_symbol_name (); |
1434 | | |
1435 | 20 | if (!name) |
1436 | 0 | return; |
1437 | 20 | sym = symbol_find_or_make (name); |
1438 | 20 | free (name); |
1439 | 20 | if (S_IS_DEFINED (sym) || symbol_equated_p (sym)) |
1440 | 5 | { |
1441 | 5 | if (S_IS_VOLATILE (sym)) |
1442 | 4 | sym = symbol_clone (sym, 1); |
1443 | 1 | else if (!S_CAN_BE_REDEFINED (sym)) |
1444 | 1 | { |
1445 | 1 | as_bad (_("symbol `%s' is already defined"), |
1446 | 1 | S_GET_NAME (sym)); |
1447 | 1 | return; |
1448 | 1 | } |
1449 | 5 | } |
1450 | 19 | S_SET_SEGMENT (sym, undefined_section); |
1451 | 19 | S_SET_VALUE (sym, 0); |
1452 | 19 | symbol_set_frag (sym, &zero_address_frag); |
1453 | 19 | } |
1454 | 12.9k | current.u.view = sym; |
1455 | 12.9k | } |
1456 | 49 | else |
1457 | 49 | { |
1458 | 49 | as_bad (_("unknown .loc sub-directive `%s'"), p); |
1459 | 49 | (void) restore_line_pointer (c); |
1460 | 49 | return; |
1461 | 49 | } |
1462 | | |
1463 | 13.0k | SKIP_WHITESPACE (); |
1464 | 13.0k | } |
1465 | | |
1466 | 26.1k | demand_empty_rest_of_line (); |
1467 | 26.1k | dwarf2_any_loc_directive_seen = dwarf2_loc_directive_seen = true; |
1468 | | |
1469 | | /* If we were given a view id, emit the row right away. */ |
1470 | 26.1k | if (current.u.view) |
1471 | 12.9k | dwarf2_emit_insn (0); |
1472 | 26.1k | } |
1473 | | |
1474 | | void |
1475 | | dwarf2_directive_loc_mark_labels (int dummy ATTRIBUTE_UNUSED) |
1476 | 5 | { |
1477 | 5 | offsetT value = get_absolute_expression (); |
1478 | | |
1479 | 5 | if (value != 0 && value != 1) |
1480 | 0 | { |
1481 | 0 | as_bad (_("expected 0 or 1")); |
1482 | 0 | ignore_rest_of_line (); |
1483 | 0 | } |
1484 | 5 | else |
1485 | 5 | { |
1486 | 5 | dwarf2_loc_mark_labels = value != 0; |
1487 | 5 | demand_empty_rest_of_line (); |
1488 | 5 | } |
1489 | 5 | } |
1490 | | |
1491 | | static struct frag * |
1492 | | first_frag_for_seg (segT seg) |
1493 | 63 | { |
1494 | 63 | return seg_info (seg)->frchainP->frch_root; |
1495 | 63 | } |
1496 | | |
1497 | | static struct frag * |
1498 | | last_frag_for_seg (segT seg) |
1499 | 107 | { |
1500 | 107 | frchainS *f = seg_info (seg)->frchainP; |
1501 | | |
1502 | 131 | while (f->frch_next != NULL) |
1503 | 24 | f = f->frch_next; |
1504 | | |
1505 | 107 | return f->frch_last; |
1506 | 107 | } |
1507 | | |
1508 | | /* Emit a single byte into the current segment. */ |
1509 | | |
1510 | | static inline void |
1511 | | out_byte (int byte) |
1512 | 1.58k | { |
1513 | 1.58k | FRAG_APPEND_1_CHAR (byte); |
1514 | 1.58k | } |
1515 | | |
1516 | | /* Emit a statement program opcode into the current segment. */ |
1517 | | |
1518 | | static inline void |
1519 | | out_opcode (int opc) |
1520 | 686 | { |
1521 | 686 | out_byte (opc); |
1522 | 686 | } |
1523 | | |
1524 | | /* Emit a two-byte word into the current segment. */ |
1525 | | |
1526 | | static inline void |
1527 | | out_two (int data) |
1528 | 107 | { |
1529 | 107 | md_number_to_chars (frag_more (2), data, 2); |
1530 | 107 | } |
1531 | | |
1532 | | /* Emit a four byte word into the current segment. */ |
1533 | | |
1534 | | static inline void |
1535 | | out_four (int data) |
1536 | 1 | { |
1537 | 1 | md_number_to_chars (frag_more (4), data, 4); |
1538 | 1 | } |
1539 | | |
1540 | | /* Emit an unsigned "little-endian base 128" number. */ |
1541 | | |
1542 | | static void |
1543 | | out_uleb128 (addressT value) |
1544 | 991 | { |
1545 | 991 | output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0); |
1546 | 991 | } |
1547 | | |
1548 | | /* Emit a signed "little-endian base 128" number. */ |
1549 | | |
1550 | | static void |
1551 | | out_leb128 (addressT value) |
1552 | 1 | { |
1553 | 1 | output_leb128 (frag_more (sizeof_leb128 (value, 1)), value, 1); |
1554 | 1 | } |
1555 | | |
1556 | | /* Emit a tuple for .debug_abbrev. */ |
1557 | | |
1558 | | static inline void |
1559 | | out_abbrev (int name, int form) |
1560 | 214 | { |
1561 | 214 | out_uleb128 (name); |
1562 | 214 | out_uleb128 (form); |
1563 | 214 | } |
1564 | | |
1565 | | /* Get the size of a fragment. */ |
1566 | | |
1567 | | static offsetT |
1568 | | get_frag_fix (fragS *frag, segT seg) |
1569 | 242 | { |
1570 | 242 | frchainS *fr; |
1571 | | |
1572 | 242 | if (frag->fr_next) |
1573 | 131 | return frag->fr_fix; |
1574 | | |
1575 | | /* If a fragment is the last in the chain, special measures must be |
1576 | | taken to find its size before relaxation, since it may be pending |
1577 | | on some subsegment chain. */ |
1578 | 143 | for (fr = seg_info (seg)->frchainP; fr; fr = fr->frch_next) |
1579 | 143 | if (fr->frch_last == frag) |
1580 | 111 | return (char *) obstack_next_free (&fr->frch_obstack) - frag->fr_literal; |
1581 | | |
1582 | 111 | abort (); |
1583 | 111 | } |
1584 | | |
1585 | | /* Set an absolute address (may result in a relocation entry). */ |
1586 | | |
1587 | | static void |
1588 | | out_set_addr (symbolS *sym) |
1589 | 178 | { |
1590 | 178 | expressionS exp; |
1591 | | |
1592 | 178 | memset (&exp, 0, sizeof exp); |
1593 | 178 | out_opcode (DW_LNS_extended_op); |
1594 | 178 | out_uleb128 (sizeof_address + 1); |
1595 | | |
1596 | 178 | out_opcode (DW_LNE_set_address); |
1597 | 178 | exp.X_op = O_symbol; |
1598 | 178 | exp.X_add_symbol = sym; |
1599 | 178 | exp.X_add_number = 0; |
1600 | 178 | emit_expr (&exp, sizeof_address); |
1601 | 178 | } |
1602 | | |
1603 | | static void |
1604 | | scale_addr_delta (int line_delta, addressT *addr_delta) |
1605 | 27.0k | { |
1606 | 27.0k | static int printed_this = 0; |
1607 | 27.0k | if (DWARF2_LINE_MIN_INSN_LENGTH > 1) |
1608 | 0 | { |
1609 | | /* Don't error on non-instruction bytes at end of section. */ |
1610 | 0 | if (line_delta != INT_MAX |
1611 | 0 | && *addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0 && !printed_this) |
1612 | 0 | { |
1613 | 0 | as_bad("unaligned opcodes detected in executable segment"); |
1614 | 0 | printed_this = 1; |
1615 | 0 | } |
1616 | 0 | *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH; |
1617 | 0 | } |
1618 | 27.0k | } |
1619 | | |
1620 | | /* Encode a pair of line and address skips as efficiently as possible. |
1621 | | Note that the line skip is signed, whereas the address skip is unsigned. |
1622 | | |
1623 | | The following two routines *must* be kept in sync. This is |
1624 | | enforced by making emit_inc_line_addr abort if we do not emit |
1625 | | exactly the expected number of bytes. */ |
1626 | | |
1627 | | static int |
1628 | | size_inc_line_addr (int line_delta, addressT addr_delta) |
1629 | 13.5k | { |
1630 | 13.5k | unsigned int tmp, opcode; |
1631 | 13.5k | int len = 0; |
1632 | | |
1633 | | /* Scale the address delta by the minimum instruction length. */ |
1634 | 13.5k | scale_addr_delta (line_delta, &addr_delta); |
1635 | | |
1636 | | /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. |
1637 | | We cannot use special opcodes here, since we want the end_sequence |
1638 | | to emit the matrix entry. */ |
1639 | 13.5k | if (line_delta == INT_MAX) |
1640 | 44 | { |
1641 | 44 | if (addr_delta == MAX_SPECIAL_ADDR_DELTA) |
1642 | 0 | len = 1; |
1643 | 44 | else if (addr_delta) |
1644 | 30 | len = 1 + sizeof_leb128 (addr_delta, 0); |
1645 | 44 | return len + 3; |
1646 | 44 | } |
1647 | | |
1648 | | /* Bias the line delta by the base. */ |
1649 | 13.5k | tmp = (unsigned) line_delta - DWARF2_LINE_BASE; |
1650 | | |
1651 | | /* If the line increment is out of range of a special opcode, we |
1652 | | must encode it with DW_LNS_advance_line. */ |
1653 | 13.5k | if (tmp >= DWARF2_LINE_RANGE) |
1654 | 77 | { |
1655 | 77 | len = 1 + sizeof_leb128 (line_delta, 1); |
1656 | 77 | line_delta = 0; |
1657 | 77 | tmp = 0 - DWARF2_LINE_BASE; |
1658 | 77 | } |
1659 | | |
1660 | | /* Bias the opcode by the special opcode base. */ |
1661 | 13.5k | tmp += DWARF2_LINE_OPCODE_BASE; |
1662 | | |
1663 | | /* Avoid overflow when addr_delta is large. */ |
1664 | 13.5k | if (addr_delta < 256U + MAX_SPECIAL_ADDR_DELTA) |
1665 | 13.3k | { |
1666 | | /* Try using a special opcode. */ |
1667 | 13.3k | opcode = tmp + addr_delta * DWARF2_LINE_RANGE; |
1668 | 13.3k | if (opcode <= 255) |
1669 | 13.3k | return len + 1; |
1670 | | |
1671 | | /* Try using DW_LNS_const_add_pc followed by special op. */ |
1672 | 3 | opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE; |
1673 | 3 | if (opcode <= 255) |
1674 | 0 | return len + 2; |
1675 | 3 | } |
1676 | | |
1677 | | /* Otherwise use DW_LNS_advance_pc. */ |
1678 | 181 | len += 1 + sizeof_leb128 (addr_delta, 0); |
1679 | | |
1680 | | /* DW_LNS_copy or special opcode. */ |
1681 | 181 | len += 1; |
1682 | | |
1683 | 181 | return len; |
1684 | 13.5k | } |
1685 | | |
1686 | | static void |
1687 | | emit_inc_line_addr (int line_delta, addressT addr_delta, char *p, int len) |
1688 | 13.4k | { |
1689 | 13.4k | unsigned int tmp, opcode; |
1690 | 13.4k | int need_copy = 0; |
1691 | 13.4k | char *end = p + len; |
1692 | | |
1693 | | /* Line number sequences cannot go backward in addresses. This means |
1694 | | we've incorrectly ordered the statements in the sequence. */ |
1695 | 13.4k | gas_assert ((offsetT) addr_delta >= 0); |
1696 | | |
1697 | | /* Scale the address delta by the minimum instruction length. */ |
1698 | 13.4k | scale_addr_delta (line_delta, &addr_delta); |
1699 | | |
1700 | | /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. |
1701 | | We cannot use special opcodes here, since we want the end_sequence |
1702 | | to emit the matrix entry. */ |
1703 | 13.4k | if (line_delta == INT_MAX) |
1704 | 41 | { |
1705 | 41 | if (addr_delta == MAX_SPECIAL_ADDR_DELTA) |
1706 | 0 | *p++ = DW_LNS_const_add_pc; |
1707 | 41 | else if (addr_delta) |
1708 | 27 | { |
1709 | 27 | *p++ = DW_LNS_advance_pc; |
1710 | 27 | p += output_leb128 (p, addr_delta, 0); |
1711 | 27 | } |
1712 | | |
1713 | 41 | *p++ = DW_LNS_extended_op; |
1714 | 41 | *p++ = 1; |
1715 | 41 | *p++ = DW_LNE_end_sequence; |
1716 | 41 | goto done; |
1717 | 41 | } |
1718 | | |
1719 | | /* Bias the line delta by the base. */ |
1720 | 13.3k | tmp = (unsigned) line_delta - DWARF2_LINE_BASE; |
1721 | | |
1722 | | /* If the line increment is out of range of a special opcode, we |
1723 | | must encode it with DW_LNS_advance_line. */ |
1724 | 13.3k | if (tmp >= DWARF2_LINE_RANGE) |
1725 | 73 | { |
1726 | 73 | *p++ = DW_LNS_advance_line; |
1727 | 73 | p += output_leb128 (p, line_delta, 1); |
1728 | | |
1729 | 73 | line_delta = 0; |
1730 | 73 | tmp = 0 - DWARF2_LINE_BASE; |
1731 | 73 | need_copy = 1; |
1732 | 73 | } |
1733 | | |
1734 | | /* Prettier, I think, to use DW_LNS_copy instead of a "line +0, addr +0" |
1735 | | special opcode. */ |
1736 | 13.3k | if (line_delta == 0 && addr_delta == 0) |
1737 | 562 | { |
1738 | 562 | *p++ = DW_LNS_copy; |
1739 | 562 | goto done; |
1740 | 562 | } |
1741 | | |
1742 | | /* Bias the opcode by the special opcode base. */ |
1743 | 12.8k | tmp += DWARF2_LINE_OPCODE_BASE; |
1744 | | |
1745 | | /* Avoid overflow when addr_delta is large. */ |
1746 | 12.8k | if (addr_delta < 256U + MAX_SPECIAL_ADDR_DELTA) |
1747 | 12.8k | { |
1748 | | /* Try using a special opcode. */ |
1749 | 12.8k | opcode = tmp + addr_delta * DWARF2_LINE_RANGE; |
1750 | 12.8k | if (opcode <= 255) |
1751 | 12.8k | { |
1752 | 12.8k | *p++ = opcode; |
1753 | 12.8k | goto done; |
1754 | 12.8k | } |
1755 | | |
1756 | | /* Try using DW_LNS_const_add_pc followed by special op. */ |
1757 | 3 | opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE; |
1758 | 3 | if (opcode <= 255) |
1759 | 0 | { |
1760 | 0 | *p++ = DW_LNS_const_add_pc; |
1761 | 0 | *p++ = opcode; |
1762 | 0 | goto done; |
1763 | 0 | } |
1764 | 3 | } |
1765 | | |
1766 | | /* Otherwise use DW_LNS_advance_pc. */ |
1767 | 3 | *p++ = DW_LNS_advance_pc; |
1768 | 3 | p += output_leb128 (p, addr_delta, 0); |
1769 | | |
1770 | 3 | if (need_copy) |
1771 | 3 | *p++ = DW_LNS_copy; |
1772 | 0 | else |
1773 | 0 | *p++ = tmp; |
1774 | | |
1775 | 13.4k | done: |
1776 | 13.4k | gas_assert (p == end); |
1777 | 13.4k | } |
1778 | | |
1779 | | /* Handy routine to combine calls to the above two routines. */ |
1780 | | |
1781 | | static void |
1782 | | out_inc_line_addr (int line_delta, addressT addr_delta) |
1783 | 13.4k | { |
1784 | 13.4k | int len = size_inc_line_addr (line_delta, addr_delta); |
1785 | 13.4k | emit_inc_line_addr (line_delta, addr_delta, frag_more (len), len); |
1786 | 13.4k | } |
1787 | | |
1788 | | /* Write out an alternative form of line and address skips using |
1789 | | DW_LNS_fixed_advance_pc opcodes. This uses more space than the default |
1790 | | line and address information, but it is required if linker relaxation |
1791 | | could change the code offsets. The following two routines *must* be |
1792 | | kept in sync. */ |
1793 | 0 | #define ADDR_DELTA_LIMIT 50000 |
1794 | | |
1795 | | static int |
1796 | | size_fixed_inc_line_addr (int line_delta, addressT addr_delta) |
1797 | 0 | { |
1798 | 0 | int len = 0; |
1799 | | |
1800 | | /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. */ |
1801 | 0 | if (line_delta != INT_MAX) |
1802 | 0 | len = 1 + sizeof_leb128 (line_delta, 1); |
1803 | |
|
1804 | 0 | if (addr_delta > ADDR_DELTA_LIMIT) |
1805 | 0 | { |
1806 | | /* DW_LNS_extended_op */ |
1807 | 0 | len += 1 + sizeof_leb128 (sizeof_address + 1, 0); |
1808 | | /* DW_LNE_set_address */ |
1809 | 0 | len += 1 + sizeof_address; |
1810 | 0 | } |
1811 | 0 | else |
1812 | | /* DW_LNS_fixed_advance_pc */ |
1813 | 0 | len += 3; |
1814 | |
|
1815 | 0 | if (line_delta == INT_MAX) |
1816 | | /* DW_LNS_extended_op + DW_LNE_end_sequence */ |
1817 | 0 | len += 3; |
1818 | 0 | else |
1819 | | /* DW_LNS_copy */ |
1820 | 0 | len += 1; |
1821 | |
|
1822 | 0 | return len; |
1823 | 0 | } |
1824 | | |
1825 | | static void |
1826 | | emit_fixed_inc_line_addr (int line_delta, addressT addr_delta, fragS *frag, |
1827 | | char *p, int len) |
1828 | 0 | { |
1829 | 0 | expressionS *pexp; |
1830 | 0 | char *end = p + len; |
1831 | | |
1832 | | /* Line number sequences cannot go backward in addresses. This means |
1833 | | we've incorrectly ordered the statements in the sequence. */ |
1834 | 0 | gas_assert ((offsetT) addr_delta >= 0); |
1835 | | |
1836 | | /* Verify that we have kept in sync with size_fixed_inc_line_addr. */ |
1837 | 0 | gas_assert (len == size_fixed_inc_line_addr (line_delta, addr_delta)); |
1838 | | |
1839 | | /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. */ |
1840 | 0 | if (line_delta != INT_MAX) |
1841 | 0 | { |
1842 | 0 | *p++ = DW_LNS_advance_line; |
1843 | 0 | p += output_leb128 (p, line_delta, 1); |
1844 | 0 | } |
1845 | |
|
1846 | 0 | pexp = symbol_get_value_expression (frag->fr_symbol); |
1847 | | |
1848 | | /* The DW_LNS_fixed_advance_pc opcode has a 2-byte operand so it can |
1849 | | advance the address by at most 64K. Linker relaxation (without |
1850 | | which this function would not be used) could change the operand by |
1851 | | an unknown amount. If the address increment is getting close to |
1852 | | the limit, just reset the address. */ |
1853 | 0 | if (addr_delta > ADDR_DELTA_LIMIT) |
1854 | 0 | { |
1855 | 0 | symbolS *to_sym; |
1856 | 0 | expressionS exp; |
1857 | |
|
1858 | 0 | memset (&exp, 0, sizeof exp); |
1859 | 0 | gas_assert (pexp->X_op == O_subtract); |
1860 | 0 | to_sym = pexp->X_add_symbol; |
1861 | |
|
1862 | 0 | *p++ = DW_LNS_extended_op; |
1863 | 0 | p += output_leb128 (p, sizeof_address + 1, 0); |
1864 | 0 | *p++ = DW_LNE_set_address; |
1865 | 0 | exp.X_op = O_symbol; |
1866 | 0 | exp.X_add_symbol = to_sym; |
1867 | 0 | exp.X_add_number = 0; |
1868 | 0 | emit_expr_fix (&exp, sizeof_address, frag, p, TC_PARSE_CONS_RETURN_NONE); |
1869 | 0 | p += sizeof_address; |
1870 | 0 | } |
1871 | 0 | else |
1872 | 0 | { |
1873 | 0 | *p++ = DW_LNS_fixed_advance_pc; |
1874 | 0 | emit_expr_fix (pexp, 2, frag, p, TC_PARSE_CONS_RETURN_NONE); |
1875 | 0 | p += 2; |
1876 | 0 | } |
1877 | | |
1878 | 0 | if (line_delta == INT_MAX) |
1879 | 0 | { |
1880 | 0 | *p++ = DW_LNS_extended_op; |
1881 | 0 | *p++ = 1; |
1882 | 0 | *p++ = DW_LNE_end_sequence; |
1883 | 0 | } |
1884 | 0 | else |
1885 | 0 | *p++ = DW_LNS_copy; |
1886 | |
|
1887 | 0 | gas_assert (p == end); |
1888 | 0 | } |
1889 | | |
1890 | | /* Generate a variant frag that we can use to relax address/line |
1891 | | increments between fragments of the target segment. */ |
1892 | | |
1893 | | static void |
1894 | | relax_inc_line_addr (int line_delta, symbolS *to_sym, symbolS *from_sym) |
1895 | 181 | { |
1896 | 181 | expressionS exp; |
1897 | 181 | int max_chars; |
1898 | | |
1899 | 181 | memset (&exp, 0, sizeof exp); |
1900 | 181 | exp.X_op = O_subtract; |
1901 | 181 | exp.X_add_symbol = to_sym; |
1902 | 181 | exp.X_op_symbol = from_sym; |
1903 | 181 | exp.X_add_number = 0; |
1904 | | |
1905 | | /* The maximum size of the frag is the line delta with a maximum |
1906 | | sized address delta. */ |
1907 | 181 | if (DWARF2_USE_FIXED_ADVANCE_PC (from_sym, to_sym)) |
1908 | 0 | max_chars = size_fixed_inc_line_addr (line_delta, |
1909 | 0 | -DWARF2_LINE_MIN_INSN_LENGTH); |
1910 | 181 | else |
1911 | 181 | max_chars = size_inc_line_addr (line_delta, -DWARF2_LINE_MIN_INSN_LENGTH); |
1912 | | |
1913 | 181 | frag_var (rs_dwarf2dbg, max_chars, max_chars, 1, |
1914 | 181 | make_expr_symbol (&exp), line_delta, NULL); |
1915 | 181 | } |
1916 | | |
1917 | | /* The function estimates the size of a rs_dwarf2dbg variant frag |
1918 | | based on the current values of the symbols. It is called before |
1919 | | the relaxation loop. We set fr_subtype to the expected length. */ |
1920 | | |
1921 | | int |
1922 | | dwarf2dbg_estimate_size_before_relax (fragS *frag) |
1923 | 0 | { |
1924 | 0 | offsetT addr_delta; |
1925 | 0 | int size; |
1926 | |
|
1927 | 0 | addr_delta = resolve_symbol_value (frag->fr_symbol); |
1928 | 0 | if (DWARF2_USE_FIXED_ADVANCE_PC_FRAG (frag)) |
1929 | 0 | size = size_fixed_inc_line_addr (frag->fr_offset, addr_delta); |
1930 | 0 | else |
1931 | 0 | size = size_inc_line_addr (frag->fr_offset, addr_delta); |
1932 | |
|
1933 | 0 | frag->fr_subtype = size; |
1934 | |
|
1935 | 0 | return size; |
1936 | 0 | } |
1937 | | |
1938 | | /* This function relaxes a rs_dwarf2dbg variant frag based on the |
1939 | | current values of the symbols. fr_subtype is the current length |
1940 | | of the frag. This returns the change in frag length. */ |
1941 | | |
1942 | | int |
1943 | | dwarf2dbg_relax_frag (fragS *frag) |
1944 | 0 | { |
1945 | 0 | int old_size, new_size; |
1946 | |
|
1947 | 0 | old_size = frag->fr_subtype; |
1948 | 0 | new_size = dwarf2dbg_estimate_size_before_relax (frag); |
1949 | |
|
1950 | 0 | return new_size - old_size; |
1951 | 0 | } |
1952 | | |
1953 | | /* This function converts a rs_dwarf2dbg variant frag into a normal |
1954 | | fill frag. This is called after all relaxation has been done. |
1955 | | fr_subtype will be the desired length of the frag. */ |
1956 | | |
1957 | | void |
1958 | | dwarf2dbg_convert_frag (fragS *frag) |
1959 | 0 | { |
1960 | 0 | offsetT addr_diff; |
1961 | | |
1962 | | /* If linker relaxation is enabled then the distance between the two |
1963 | | symbols in the frag->fr_symbol expression might change. Hence we |
1964 | | cannot rely upon the value computed by resolve_symbol_value. |
1965 | | Instead we leave the expression unfinalized and allow |
1966 | | emit_fixed_inc_line_addr to create a fixup (which later becomes a |
1967 | | relocation) that will allow the linker to correctly compute the |
1968 | | actual address difference. We have to use a fixed line advance for |
1969 | | this as we cannot (easily) relocate leb128 encoded values. */ |
1970 | 0 | int saved_finalize_syms = finalize_syms; |
1971 | 0 | finalize_syms = 0; |
1972 | 0 | addr_diff = resolve_symbol_value (frag->fr_symbol); |
1973 | 0 | finalize_syms = saved_finalize_syms; |
1974 | | |
1975 | | /* fr_var carries the max_chars that we created the fragment with. |
1976 | | fr_subtype carries the current expected length. We must, of |
1977 | | course, have allocated enough memory earlier. */ |
1978 | 0 | gas_assert (frag->fr_var >= (int) frag->fr_subtype); |
1979 | | |
1980 | 0 | if (DWARF2_USE_FIXED_ADVANCE_PC_FRAG (frag)) |
1981 | 0 | emit_fixed_inc_line_addr (frag->fr_offset, addr_diff, frag, |
1982 | 0 | frag->fr_literal + frag->fr_fix, |
1983 | 0 | frag->fr_subtype); |
1984 | 0 | else |
1985 | 0 | emit_inc_line_addr (frag->fr_offset, addr_diff, |
1986 | 0 | frag->fr_literal + frag->fr_fix, frag->fr_subtype); |
1987 | |
|
1988 | 0 | frag->fr_fix += frag->fr_subtype; |
1989 | 0 | frag->fr_type = rs_fill; |
1990 | 0 | frag->fr_var = 0; |
1991 | 0 | frag->fr_offset = 0; |
1992 | 0 | } |
1993 | | |
1994 | | /* Generate .debug_line content for the chain of line number entries |
1995 | | beginning at E, for segment SEG. */ |
1996 | | |
1997 | | static void |
1998 | | process_entries (segT seg, struct line_entry *e) |
1999 | 44 | { |
2000 | 44 | unsigned filenum = 1; |
2001 | 44 | unsigned line = 1; |
2002 | 44 | unsigned column = 0; |
2003 | 44 | unsigned isa = 0; |
2004 | 44 | unsigned flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0; |
2005 | 44 | fragS *last_frag = NULL, *frag; |
2006 | 44 | addressT last_frag_ofs = 0, frag_ofs; |
2007 | 44 | symbolS *last_lab = NULL, *lab; |
2008 | | |
2009 | 44 | if (flag_dwarf_sections) |
2010 | 0 | { |
2011 | 0 | char * name; |
2012 | 0 | const char * sec_name; |
2013 | | |
2014 | | /* Switch to the relevant sub-section before we start to emit |
2015 | | the line number table. |
2016 | | |
2017 | | FIXME: These sub-sections do not have a normal Line Number |
2018 | | Program Header, thus strictly speaking they are not valid |
2019 | | DWARF sections. Unfortunately the DWARF standard assumes |
2020 | | a one-to-one relationship between compilation units and |
2021 | | line number tables. Thus we have to have a .debug_line |
2022 | | section, as well as our sub-sections, and we have to ensure |
2023 | | that all of the sub-sections are merged into a proper |
2024 | | .debug_line section before a debugger sees them. */ |
2025 | |
|
2026 | 0 | sec_name = bfd_section_name (seg); |
2027 | 0 | if (strcmp (sec_name, ".text") != 0) |
2028 | 0 | { |
2029 | 0 | name = concat (".debug_line", sec_name, (char *) NULL); |
2030 | 0 | subseg_set (subseg_get (name, false), 0); |
2031 | 0 | } |
2032 | 0 | else |
2033 | | /* Don't create a .debug_line.text section - |
2034 | | that is redundant. Instead just switch back to the |
2035 | | normal .debug_line section. */ |
2036 | 0 | subseg_set (subseg_get (".debug_line", false), 0); |
2037 | 0 | } |
2038 | | |
2039 | 44 | do |
2040 | 13.5k | { |
2041 | 13.5k | int line_delta; |
2042 | | |
2043 | 13.5k | if (filenum != e->loc.filenum) |
2044 | 38 | { |
2045 | 38 | filenum = e->loc.filenum; |
2046 | 38 | out_opcode (DW_LNS_set_file); |
2047 | 38 | out_uleb128 (filenum); |
2048 | 38 | } |
2049 | | |
2050 | 13.5k | if (column != e->loc.column) |
2051 | 2 | { |
2052 | 2 | column = e->loc.column; |
2053 | 2 | out_opcode (DW_LNS_set_column); |
2054 | 2 | out_uleb128 (column); |
2055 | 2 | } |
2056 | | |
2057 | 13.5k | if (e->loc.discriminator != 0) |
2058 | 0 | { |
2059 | 0 | out_opcode (DW_LNS_extended_op); |
2060 | 0 | out_leb128 (1 + sizeof_leb128 (e->loc.discriminator, 0)); |
2061 | 0 | out_opcode (DW_LNE_set_discriminator); |
2062 | 0 | out_uleb128 (e->loc.discriminator); |
2063 | 0 | } |
2064 | | |
2065 | 13.5k | if (isa != e->loc.isa) |
2066 | 0 | { |
2067 | 0 | isa = e->loc.isa; |
2068 | 0 | out_opcode (DW_LNS_set_isa); |
2069 | 0 | out_uleb128 (isa); |
2070 | 0 | } |
2071 | | |
2072 | 13.5k | if ((e->loc.flags ^ flags) & DWARF2_FLAG_IS_STMT) |
2073 | 4 | { |
2074 | 4 | flags = e->loc.flags; |
2075 | 4 | out_opcode (DW_LNS_negate_stmt); |
2076 | 4 | } |
2077 | | |
2078 | 13.5k | if (e->loc.flags & DWARF2_FLAG_BASIC_BLOCK) |
2079 | 286 | out_opcode (DW_LNS_set_basic_block); |
2080 | | |
2081 | 13.5k | if (e->loc.flags & DWARF2_FLAG_PROLOGUE_END) |
2082 | 0 | out_opcode (DW_LNS_set_prologue_end); |
2083 | | |
2084 | 13.5k | if (e->loc.flags & DWARF2_FLAG_EPILOGUE_BEGIN) |
2085 | 0 | out_opcode (DW_LNS_set_epilogue_begin); |
2086 | | |
2087 | | /* Don't try to optimize away redundant entries; gdb wants two |
2088 | | entries for a function where the code starts on the same line as |
2089 | | the {, and there's no way to identify that case here. Trust gcc |
2090 | | to optimize appropriately. */ |
2091 | 13.5k | line_delta = e->loc.line - line; |
2092 | 13.5k | lab = e->label; |
2093 | 13.5k | frag = symbol_get_frag (lab); |
2094 | 13.5k | frag_ofs = S_GET_VALUE (lab); |
2095 | | |
2096 | 13.5k | if (last_frag == NULL |
2097 | 13.5k | || (e->loc.u.view == force_reset_view && force_reset_view |
2098 | | /* If we're going to reset the view, but we know we're |
2099 | | advancing the PC, we don't have to force with |
2100 | | set_address. We know we do when we're at the same |
2101 | | address of the same frag, and we know we might when |
2102 | | we're in the beginning of a frag, and we were at the |
2103 | | end of the previous frag. */ |
2104 | 140 | && (frag == last_frag |
2105 | 140 | ? (last_frag_ofs == frag_ofs) |
2106 | 140 | : (frag_ofs == 0 |
2107 | 135 | && ((offsetT)last_frag_ofs |
2108 | 135 | >= get_frag_fix (last_frag, seg)))))) |
2109 | 178 | { |
2110 | 178 | out_set_addr (lab); |
2111 | 178 | out_inc_line_addr (line_delta, 0); |
2112 | 178 | } |
2113 | 13.3k | else if (frag == last_frag |
2114 | 13.1k | && ! DWARF2_USE_FIXED_ADVANCE_PC (last_lab, lab)) |
2115 | 13.1k | out_inc_line_addr (line_delta, frag_ofs - last_frag_ofs); |
2116 | 178 | else |
2117 | 178 | relax_inc_line_addr (line_delta, lab, last_lab); |
2118 | | |
2119 | 13.5k | line = e->loc.line; |
2120 | 13.5k | last_lab = lab; |
2121 | 13.5k | last_frag = frag; |
2122 | 13.5k | last_frag_ofs = frag_ofs; |
2123 | | |
2124 | 13.5k | e = e->next; |
2125 | 13.5k | } |
2126 | 13.5k | while (e); |
2127 | | |
2128 | | /* Emit a DW_LNE_end_sequence for the end of the section. */ |
2129 | 44 | frag = last_frag_for_seg (seg); |
2130 | 44 | frag_ofs = get_frag_fix (frag, seg); |
2131 | 44 | if (frag == last_frag && ! DWARF2_USE_FIXED_ADVANCE_PC (last_lab, lab)) |
2132 | 41 | out_inc_line_addr (INT_MAX, frag_ofs - last_frag_ofs); |
2133 | 3 | else |
2134 | 3 | { |
2135 | 3 | lab = symbol_temp_new (seg, frag, frag_ofs); |
2136 | 3 | relax_inc_line_addr (INT_MAX, lab, last_lab); |
2137 | 3 | } |
2138 | 44 | } |
2139 | | |
2140 | | /* Switch to LINE_STR_SEG and output the given STR. Return the |
2141 | | symbol pointing to the new string in the section. */ |
2142 | | |
2143 | | static symbolS * |
2144 | | add_line_strp (segT line_str_seg, const char *str) |
2145 | 70 | { |
2146 | 70 | char *cp; |
2147 | 70 | size_t size; |
2148 | 70 | symbolS *sym; |
2149 | | |
2150 | 70 | subseg_set (line_str_seg, 0); |
2151 | | |
2152 | 70 | sym = symbol_temp_new_now_octets (); |
2153 | | |
2154 | 70 | size = strlen (str) + 1; |
2155 | 70 | cp = frag_more (size); |
2156 | 70 | memcpy (cp, str, size); |
2157 | | |
2158 | 70 | return sym; |
2159 | 70 | } |
2160 | | |
2161 | | |
2162 | | /* Emit the directory and file tables for .debug_line. */ |
2163 | | |
2164 | | static void |
2165 | | out_dir_and_file_list (segT line_seg, int sizeof_offset) |
2166 | 28 | { |
2167 | 28 | size_t size; |
2168 | 28 | char *dir; |
2169 | 28 | char *cp; |
2170 | 28 | unsigned int i, j; |
2171 | 28 | bool emit_md5 = false; |
2172 | 28 | bool emit_timestamps = true; |
2173 | 28 | bool emit_filesize = true; |
2174 | 28 | segT line_str_seg = NULL; |
2175 | 28 | symbolS *line_strp, *file0_strp = NULL; |
2176 | | |
2177 | | /* Output the Directory Table. */ |
2178 | 28 | if (DWARF2_LINE_VERSION >= 5) |
2179 | 28 | { |
2180 | | /* We only have one column in the directory table. */ |
2181 | 28 | out_byte (1); |
2182 | | |
2183 | | /* Describe the purpose and format of the column. */ |
2184 | 28 | out_uleb128 (DW_LNCT_path); |
2185 | | /* Store these strings in the .debug_line_str section so they |
2186 | | can be shared. */ |
2187 | 28 | out_uleb128 (DW_FORM_line_strp); |
2188 | | |
2189 | | /* Now state how many rows there are in the table. We need at |
2190 | | least 1 if there is one or more file names to store the |
2191 | | "working directory". */ |
2192 | 28 | if (dirs_in_use == 0 && files_in_use > 0) |
2193 | 19 | out_uleb128 (1); |
2194 | 9 | else |
2195 | 9 | out_uleb128 (dirs_in_use); |
2196 | 28 | } |
2197 | | |
2198 | | /* Emit directory list. */ |
2199 | 28 | if (DWARF2_LINE_VERSION >= 5 && (dirs_in_use > 0 || files_in_use > 0)) |
2200 | 26 | { |
2201 | 26 | line_str_seg = subseg_new (".debug_line_str", 0); |
2202 | 26 | bfd_set_section_flags (line_str_seg, |
2203 | 26 | SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS |
2204 | 26 | | SEC_MERGE | SEC_STRINGS); |
2205 | 26 | line_str_seg->entsize = 1; |
2206 | | |
2207 | | /* DWARF5 uses slot zero, but that is only set explicitly |
2208 | | using a .file 0 directive. Otherwise use pwd as main file |
2209 | | directory. */ |
2210 | 26 | if (dirs_in_use > 0 && dirs[0] != NULL) |
2211 | 7 | dir = remap_debug_filename (dirs[0]); |
2212 | 19 | else |
2213 | 19 | dir = remap_debug_filename (getpwd ()); |
2214 | | |
2215 | 26 | line_strp = add_line_strp (line_str_seg, dir); |
2216 | 26 | free (dir); |
2217 | 26 | subseg_set (line_seg, 0); |
2218 | 26 | TC_DWARF2_EMIT_OFFSET (line_strp, sizeof_offset); |
2219 | 26 | } |
2220 | 39 | for (i = 1; i < dirs_in_use; ++i) |
2221 | 11 | { |
2222 | 11 | dir = remap_debug_filename (dirs[i]); |
2223 | 11 | if (DWARF2_LINE_VERSION < 5) |
2224 | 0 | { |
2225 | 0 | size = strlen (dir) + 1; |
2226 | 0 | cp = frag_more (size); |
2227 | 0 | memcpy (cp, dir, size); |
2228 | 0 | } |
2229 | 11 | else |
2230 | 11 | { |
2231 | 11 | line_strp = add_line_strp (line_str_seg, dir); |
2232 | 11 | subseg_set (line_seg, 0); |
2233 | 11 | TC_DWARF2_EMIT_OFFSET (line_strp, sizeof_offset); |
2234 | 11 | } |
2235 | 11 | free (dir); |
2236 | 11 | } |
2237 | | |
2238 | 28 | if (DWARF2_LINE_VERSION < 5) |
2239 | | /* Terminate it. */ |
2240 | 0 | out_byte ('\0'); |
2241 | | |
2242 | | /* Output the File Name Table. */ |
2243 | 28 | if (DWARF2_LINE_VERSION >= 5) |
2244 | 28 | { |
2245 | 28 | unsigned int columns = 4; |
2246 | | |
2247 | 28 | if (((unsigned long) DWARF2_FILE_TIME_NAME ("", "")) == -1UL) |
2248 | 28 | { |
2249 | 28 | emit_timestamps = false; |
2250 | 28 | -- columns; |
2251 | 28 | } |
2252 | | |
2253 | 28 | if (DWARF2_FILE_SIZE_NAME ("", "") == -1) |
2254 | 28 | { |
2255 | 28 | emit_filesize = false; |
2256 | 28 | -- columns; |
2257 | 28 | } |
2258 | | |
2259 | 1.04k | for (i = 0; i < files_in_use; ++i) |
2260 | 1.01k | if (files[i].md5[0] != 0) |
2261 | 0 | break; |
2262 | 28 | if (i < files_in_use) |
2263 | 0 | { |
2264 | 0 | emit_md5 = true; |
2265 | 0 | ++ columns; |
2266 | 0 | } |
2267 | | |
2268 | | /* The number of format entries to follow. */ |
2269 | 28 | out_byte (columns); |
2270 | | /* The format of the file name. */ |
2271 | 28 | out_uleb128 (DW_LNCT_path); |
2272 | | /* Store these strings in the .debug_line_str section so they |
2273 | | can be shared. */ |
2274 | 28 | out_uleb128 (DW_FORM_line_strp); |
2275 | | |
2276 | | /* The format of the directory index. */ |
2277 | 28 | out_uleb128 (DW_LNCT_directory_index); |
2278 | 28 | out_uleb128 (DW_FORM_udata); |
2279 | | |
2280 | 28 | if (emit_timestamps) |
2281 | 0 | { |
2282 | | /* The format of the timestamp. */ |
2283 | 0 | out_uleb128 (DW_LNCT_timestamp); |
2284 | 0 | out_uleb128 (DW_FORM_udata); |
2285 | 0 | } |
2286 | | |
2287 | 28 | if (emit_filesize) |
2288 | 0 | { |
2289 | | /* The format of the file size. */ |
2290 | 0 | out_uleb128 (DW_LNCT_size); |
2291 | 0 | out_uleb128 (DW_FORM_udata); |
2292 | 0 | } |
2293 | | |
2294 | 28 | if (emit_md5) |
2295 | 0 | { |
2296 | | /* The format of the MD5 sum. */ |
2297 | 0 | out_uleb128 (DW_LNCT_MD5); |
2298 | 0 | out_uleb128 (DW_FORM_data16); |
2299 | 0 | } |
2300 | | |
2301 | | /* The number of entries in the table. */ |
2302 | 28 | out_uleb128 (files_in_use); |
2303 | 28 | } |
2304 | | |
2305 | 1.04k | for (i = DWARF2_LINE_VERSION > 4 ? 0 : 1; i < files_in_use; ++i) |
2306 | 1.01k | { |
2307 | 1.01k | const char *fullfilename; |
2308 | | |
2309 | 1.01k | if (files[i].filename == NULL) |
2310 | 980 | { |
2311 | 980 | if (DWARF2_LINE_VERSION < 5 || i != 0) |
2312 | 977 | { |
2313 | 977 | as_bad (_("unassigned file number %ld"), (long) i); |
2314 | 977 | continue; |
2315 | 977 | } |
2316 | | /* DWARF5 uses slot zero, but that is only set explicitly using |
2317 | | a .file 0 directive. If that isn't used, but file 1 is, then |
2318 | | use that as main file name. */ |
2319 | 3 | if (files_in_use > 1 && files[1].filename != NULL) |
2320 | 3 | { |
2321 | 3 | files[0].filename = files[1].filename; |
2322 | 3 | files[0].dir = files[1].dir; |
2323 | 3 | if (emit_md5) |
2324 | 0 | for (j = 0; j < NUM_MD5_BYTES; ++j) |
2325 | 0 | files[0].md5[j] = files[1].md5[j]; |
2326 | 3 | } |
2327 | 0 | else |
2328 | 0 | files[0].filename = ""; |
2329 | 3 | } |
2330 | | |
2331 | 36 | fullfilename = DWARF2_FILE_NAME (files[i].filename, |
2332 | 36 | files[i].dir ? dirs [files [i].dir] : ""); |
2333 | 36 | if (DWARF2_LINE_VERSION < 5) |
2334 | 0 | { |
2335 | 0 | size = strlen (fullfilename) + 1; |
2336 | 0 | cp = frag_more (size); |
2337 | 0 | memcpy (cp, fullfilename, size); |
2338 | 0 | } |
2339 | 36 | else |
2340 | 36 | { |
2341 | 36 | if (!file0_strp) |
2342 | 33 | line_strp = add_line_strp (line_str_seg, fullfilename); |
2343 | 3 | else |
2344 | 3 | line_strp = file0_strp; |
2345 | 36 | subseg_set (line_seg, 0); |
2346 | 36 | TC_DWARF2_EMIT_OFFSET (line_strp, sizeof_offset); |
2347 | 36 | if (i == 0 && files_in_use > 1 |
2348 | 4 | && files[0].filename == files[1].filename) |
2349 | 3 | file0_strp = line_strp; |
2350 | 33 | else |
2351 | 33 | file0_strp = NULL; |
2352 | 36 | } |
2353 | | |
2354 | | /* Directory number. */ |
2355 | 36 | out_uleb128 (files[i].dir); |
2356 | | |
2357 | | /* Output the last modification timestamp. */ |
2358 | 36 | if (emit_timestamps) |
2359 | 0 | { |
2360 | 0 | offsetT timestamp; |
2361 | |
|
2362 | 0 | timestamp = DWARF2_FILE_TIME_NAME (files[i].filename, |
2363 | 0 | files[i].dir ? dirs [files [i].dir] : ""); |
2364 | 0 | if (timestamp == -1) |
2365 | 0 | timestamp = 0; |
2366 | 0 | out_uleb128 (timestamp); |
2367 | 0 | } |
2368 | | |
2369 | | /* Output the filesize. */ |
2370 | 36 | if (emit_filesize) |
2371 | 0 | { |
2372 | 0 | offsetT filesize; |
2373 | 0 | filesize = DWARF2_FILE_SIZE_NAME (files[i].filename, |
2374 | 0 | files[i].dir ? dirs [files [i].dir] : ""); |
2375 | 0 | if (filesize == -1) |
2376 | 0 | filesize = 0; |
2377 | 0 | out_uleb128 (filesize); |
2378 | 0 | } |
2379 | | |
2380 | | /* Output the md5 sum. */ |
2381 | 36 | if (emit_md5) |
2382 | 0 | { |
2383 | 0 | int b; |
2384 | |
|
2385 | 0 | for (b = 0; b < NUM_MD5_BYTES; b++) |
2386 | 0 | out_byte (files[i].md5[b]); |
2387 | 0 | } |
2388 | 36 | } |
2389 | | |
2390 | 28 | if (DWARF2_LINE_VERSION < 5) |
2391 | | /* Terminate filename list. */ |
2392 | 0 | out_byte (0); |
2393 | 28 | } |
2394 | | |
2395 | | /* Switch to SEC and output a header length field. Return the size of |
2396 | | offsets used in SEC. The caller must set EXPR->X_add_symbol value |
2397 | | to the end of the section. EXPR->X_add_number will be set to the |
2398 | | negative size of the header. */ |
2399 | | |
2400 | | static int |
2401 | | out_header (asection *sec, expressionS *exp) |
2402 | 81 | { |
2403 | 81 | symbolS *start_sym; |
2404 | 81 | symbolS *end_sym; |
2405 | | |
2406 | 81 | subseg_set (sec, 0); |
2407 | | |
2408 | 81 | if (flag_dwarf_sections) |
2409 | 0 | { |
2410 | | /* If we are going to put the start and end symbols in different |
2411 | | sections, then we need real symbols, not just fake, local ones. */ |
2412 | 0 | frag_now_fix (); |
2413 | 0 | start_sym = symbol_make (".Ldebug_line_start"); |
2414 | 0 | end_sym = symbol_make (".Ldebug_line_end"); |
2415 | 0 | symbol_set_value_now (start_sym); |
2416 | 0 | } |
2417 | 81 | else |
2418 | 81 | { |
2419 | 81 | start_sym = symbol_temp_new_now_octets (); |
2420 | 81 | end_sym = symbol_temp_make (); |
2421 | 81 | } |
2422 | | |
2423 | | /* Total length of the information. */ |
2424 | 81 | exp->X_op = O_subtract; |
2425 | 81 | exp->X_add_symbol = end_sym; |
2426 | 81 | exp->X_op_symbol = start_sym; |
2427 | | |
2428 | 81 | switch (DWARF2_FORMAT (sec)) |
2429 | 81 | { |
2430 | 81 | case dwarf2_format_32bit: |
2431 | 81 | exp->X_add_number = -4; |
2432 | 81 | emit_expr (exp, 4); |
2433 | 81 | return 4; |
2434 | | |
2435 | 0 | case dwarf2_format_64bit: |
2436 | 0 | exp->X_add_number = -12; |
2437 | 0 | out_four (-1); |
2438 | 0 | emit_expr (exp, 8); |
2439 | 0 | return 8; |
2440 | | |
2441 | 0 | case dwarf2_format_64bit_irix: |
2442 | 0 | exp->X_add_number = -8; |
2443 | 0 | emit_expr (exp, 8); |
2444 | 0 | return 8; |
2445 | 81 | } |
2446 | | |
2447 | 0 | as_fatal (_("internal error: unknown dwarf2 format")); |
2448 | 0 | return 0; |
2449 | 81 | } |
2450 | | |
2451 | | /* Emit the collected .debug_line data. */ |
2452 | | |
2453 | | static void |
2454 | | out_debug_line (segT line_seg) |
2455 | 28 | { |
2456 | 28 | expressionS exp; |
2457 | 28 | symbolS *prologue_start, *prologue_end; |
2458 | 28 | symbolS *line_end; |
2459 | 28 | struct line_seg *s; |
2460 | 28 | int sizeof_offset; |
2461 | | |
2462 | 28 | memset (&exp, 0, sizeof exp); |
2463 | 28 | sizeof_offset = out_header (line_seg, &exp); |
2464 | 28 | line_end = exp.X_add_symbol; |
2465 | | |
2466 | | /* Version. */ |
2467 | 28 | out_two (DWARF2_LINE_VERSION); |
2468 | | |
2469 | 28 | if (DWARF2_LINE_VERSION >= 5) |
2470 | 28 | { |
2471 | 28 | out_byte (sizeof_address); |
2472 | 28 | out_byte (0); /* Segment Selector size. */ |
2473 | 28 | } |
2474 | | /* Length of the prologue following this length. */ |
2475 | 28 | prologue_start = symbol_temp_make (); |
2476 | 28 | prologue_end = symbol_temp_make (); |
2477 | 28 | exp.X_op = O_subtract; |
2478 | 28 | exp.X_add_symbol = prologue_end; |
2479 | 28 | exp.X_op_symbol = prologue_start; |
2480 | 28 | exp.X_add_number = 0; |
2481 | 28 | emit_expr (&exp, sizeof_offset); |
2482 | 28 | symbol_set_value_now (prologue_start); |
2483 | | |
2484 | | /* Parameters of the state machine. */ |
2485 | 28 | out_byte (DWARF2_LINE_MIN_INSN_LENGTH); |
2486 | 28 | if (DWARF2_LINE_VERSION >= 4) |
2487 | 28 | out_byte (DWARF2_LINE_MAX_OPS_PER_INSN); |
2488 | 28 | out_byte (DWARF2_LINE_DEFAULT_IS_STMT); |
2489 | 28 | out_byte (DWARF2_LINE_BASE); |
2490 | 28 | out_byte (DWARF2_LINE_RANGE); |
2491 | 28 | out_byte (DWARF2_LINE_OPCODE_BASE); |
2492 | | |
2493 | | /* Standard opcode lengths. */ |
2494 | 28 | out_byte (0); /* DW_LNS_copy */ |
2495 | 28 | out_byte (1); /* DW_LNS_advance_pc */ |
2496 | 28 | out_byte (1); /* DW_LNS_advance_line */ |
2497 | 28 | out_byte (1); /* DW_LNS_set_file */ |
2498 | 28 | out_byte (1); /* DW_LNS_set_column */ |
2499 | 28 | out_byte (0); /* DW_LNS_negate_stmt */ |
2500 | 28 | out_byte (0); /* DW_LNS_set_basic_block */ |
2501 | 28 | out_byte (0); /* DW_LNS_const_add_pc */ |
2502 | 28 | out_byte (1); /* DW_LNS_fixed_advance_pc */ |
2503 | 28 | if (DWARF2_LINE_VERSION >= 3) |
2504 | 28 | { |
2505 | 28 | out_byte (0); /* DW_LNS_set_prologue_end */ |
2506 | 28 | out_byte (0); /* DW_LNS_set_epilogue_begin */ |
2507 | 28 | out_byte (1); /* DW_LNS_set_isa */ |
2508 | | /* We have emitted 12 opcode lengths, so make that this |
2509 | | matches up to the opcode base value we have been using. */ |
2510 | 28 | gas_assert (DWARF2_LINE_OPCODE_BASE == 13); |
2511 | 28 | } |
2512 | 0 | else |
2513 | 0 | gas_assert (DWARF2_LINE_OPCODE_BASE == 10); |
2514 | | |
2515 | 28 | out_dir_and_file_list (line_seg, sizeof_offset); |
2516 | | |
2517 | 28 | symbol_set_value_now (prologue_end); |
2518 | | |
2519 | | /* For each section, emit a statement program. */ |
2520 | 72 | for (s = all_segs; s; s = s->next) |
2521 | | /* Paranoia - this check should have already have |
2522 | | been handled in dwarf2_gen_line_info_1(). */ |
2523 | 44 | if (s->head->head && SEG_NORMAL (s->seg)) |
2524 | 44 | process_entries (s->seg, s->head->head); |
2525 | | |
2526 | 28 | if (flag_dwarf_sections) |
2527 | | /* We have to switch to the special .debug_line_end section |
2528 | | before emitting the end-of-debug_line symbol. The linker |
2529 | | script arranges for this section to be placed after all the |
2530 | | (potentially garbage collected) .debug_line.<foo> sections. |
2531 | | This section contains the line_end symbol which is used to |
2532 | | compute the size of the linked .debug_line section, as seen |
2533 | | in the DWARF Line Number header. */ |
2534 | 0 | subseg_set (subseg_get (".debug_line_end", false), 0); |
2535 | | |
2536 | 28 | symbol_set_value_now (line_end); |
2537 | 28 | } |
2538 | | |
2539 | | static void |
2540 | | out_debug_ranges (segT ranges_seg, symbolS **ranges_sym) |
2541 | 0 | { |
2542 | 0 | unsigned int addr_size = sizeof_address; |
2543 | 0 | struct line_seg *s; |
2544 | 0 | expressionS exp; |
2545 | 0 | unsigned int i; |
2546 | |
|
2547 | 0 | memset (&exp, 0, sizeof exp); |
2548 | 0 | subseg_set (ranges_seg, 0); |
2549 | | |
2550 | | /* For DW_AT_ranges to point at (there is no header, so really start |
2551 | | of section, but see out_debug_rnglists). */ |
2552 | 0 | *ranges_sym = symbol_temp_new_now_octets (); |
2553 | | |
2554 | | /* Base Address Entry. */ |
2555 | 0 | for (i = 0; i < addr_size; i++) |
2556 | 0 | out_byte (0xff); |
2557 | 0 | for (i = 0; i < addr_size; i++) |
2558 | 0 | out_byte (0); |
2559 | | |
2560 | | /* Range List Entry. */ |
2561 | 0 | for (s = all_segs; s; s = s->next) |
2562 | 0 | { |
2563 | 0 | fragS *frag; |
2564 | 0 | symbolS *beg, *end; |
2565 | |
|
2566 | 0 | frag = first_frag_for_seg (s->seg); |
2567 | 0 | beg = symbol_temp_new (s->seg, frag, 0); |
2568 | 0 | s->text_start = beg; |
2569 | |
|
2570 | 0 | frag = last_frag_for_seg (s->seg); |
2571 | 0 | end = symbol_temp_new (s->seg, frag, get_frag_fix (frag, s->seg)); |
2572 | 0 | s->text_end = end; |
2573 | |
|
2574 | 0 | exp.X_op = O_symbol; |
2575 | 0 | exp.X_add_symbol = beg; |
2576 | 0 | exp.X_add_number = 0; |
2577 | 0 | emit_expr (&exp, addr_size); |
2578 | |
|
2579 | 0 | exp.X_op = O_symbol; |
2580 | 0 | exp.X_add_symbol = end; |
2581 | 0 | exp.X_add_number = 0; |
2582 | 0 | emit_expr (&exp, addr_size); |
2583 | 0 | } |
2584 | | |
2585 | | /* End of Range Entry. */ |
2586 | 0 | for (i = 0; i < addr_size; i++) |
2587 | 0 | out_byte (0); |
2588 | 0 | for (i = 0; i < addr_size; i++) |
2589 | 0 | out_byte (0); |
2590 | 0 | } |
2591 | | |
2592 | | static void |
2593 | | out_debug_rnglists (segT ranges_seg, symbolS **ranges_sym) |
2594 | 1 | { |
2595 | 1 | expressionS exp; |
2596 | 1 | symbolS *ranges_end; |
2597 | 1 | struct line_seg *s; |
2598 | | |
2599 | | /* Unit length. */ |
2600 | 1 | memset (&exp, 0, sizeof exp); |
2601 | 1 | out_header (ranges_seg, &exp); |
2602 | 1 | ranges_end = exp.X_add_symbol; |
2603 | | |
2604 | 1 | out_two (DWARF2_RNGLISTS_VERSION); |
2605 | 1 | out_byte (sizeof_address); |
2606 | 1 | out_byte (0); /* Segment Selector size. */ |
2607 | 1 | out_four (0); /* Offset entry count. */ |
2608 | | |
2609 | | /* For DW_AT_ranges to point at (must be after the header). */ |
2610 | 1 | *ranges_sym = symbol_temp_new_now_octets (); |
2611 | | |
2612 | 20 | for (s = all_segs; s; s = s->next) |
2613 | 19 | { |
2614 | 19 | fragS *frag; |
2615 | 19 | symbolS *beg, *end; |
2616 | | |
2617 | 19 | out_byte (DW_RLE_start_length); |
2618 | | |
2619 | 19 | frag = first_frag_for_seg (s->seg); |
2620 | 19 | beg = symbol_temp_new (s->seg, frag, 0); |
2621 | 19 | s->text_start = beg; |
2622 | | |
2623 | 19 | frag = last_frag_for_seg (s->seg); |
2624 | 19 | end = symbol_temp_new (s->seg, frag, get_frag_fix (frag, s->seg)); |
2625 | 19 | s->text_end = end; |
2626 | | |
2627 | 19 | exp.X_op = O_symbol; |
2628 | 19 | exp.X_add_symbol = beg; |
2629 | 19 | exp.X_add_number = 0; |
2630 | 19 | emit_expr (&exp, sizeof_address); |
2631 | | |
2632 | 19 | exp.X_op = O_symbol; |
2633 | 19 | exp.X_add_symbol = end; |
2634 | 19 | exp.X_add_number = 0; |
2635 | 19 | emit_leb128_expr (&exp, 0); |
2636 | 19 | } |
2637 | | |
2638 | 1 | out_byte (DW_RLE_end_of_list); |
2639 | | |
2640 | 1 | symbol_set_value_now (ranges_end); |
2641 | 1 | } |
2642 | | |
2643 | | /* Emit data for .debug_aranges. */ |
2644 | | |
2645 | | static void |
2646 | | out_debug_aranges (segT aranges_seg, segT info_seg) |
2647 | 26 | { |
2648 | 26 | unsigned int addr_size = sizeof_address; |
2649 | 26 | offsetT size; |
2650 | 26 | struct line_seg *s; |
2651 | 26 | expressionS exp; |
2652 | 26 | symbolS *aranges_end; |
2653 | 26 | char *p; |
2654 | 26 | int sizeof_offset; |
2655 | | |
2656 | 26 | memset (&exp, 0, sizeof exp); |
2657 | 26 | sizeof_offset = out_header (aranges_seg, &exp); |
2658 | 26 | aranges_end = exp.X_add_symbol; |
2659 | 26 | size = -exp.X_add_number; |
2660 | | |
2661 | | /* Version. */ |
2662 | 26 | out_two (DWARF2_ARANGES_VERSION); |
2663 | 26 | size += 2; |
2664 | | |
2665 | | /* Offset to .debug_info. */ |
2666 | 26 | TC_DWARF2_EMIT_OFFSET (section_symbol (info_seg), sizeof_offset); |
2667 | 26 | size += sizeof_offset; |
2668 | | |
2669 | | /* Size of an address (offset portion). */ |
2670 | 26 | out_byte (addr_size); |
2671 | 26 | size++; |
2672 | | |
2673 | | /* Size of a segment descriptor. */ |
2674 | 26 | out_byte (0); |
2675 | 26 | size++; |
2676 | | |
2677 | | /* Align the header. */ |
2678 | 130 | while ((size++ % (2 * addr_size)) > 0) |
2679 | 104 | out_byte (0); |
2680 | | |
2681 | 70 | for (s = all_segs; s; s = s->next) |
2682 | 44 | { |
2683 | 44 | fragS *frag; |
2684 | 44 | symbolS *beg, *end; |
2685 | | |
2686 | 44 | frag = first_frag_for_seg (s->seg); |
2687 | 44 | beg = symbol_temp_new (s->seg, frag, 0); |
2688 | 44 | s->text_start = beg; |
2689 | | |
2690 | 44 | frag = last_frag_for_seg (s->seg); |
2691 | 44 | end = symbol_temp_new (s->seg, frag, get_frag_fix (frag, s->seg)); |
2692 | 44 | s->text_end = end; |
2693 | | |
2694 | 44 | exp.X_op = O_symbol; |
2695 | 44 | exp.X_add_symbol = beg; |
2696 | 44 | exp.X_add_number = 0; |
2697 | 44 | emit_expr (&exp, addr_size); |
2698 | | |
2699 | 44 | exp.X_op = O_subtract; |
2700 | 44 | exp.X_add_symbol = end; |
2701 | 44 | exp.X_op_symbol = beg; |
2702 | 44 | exp.X_add_number = 0; |
2703 | 44 | emit_expr (&exp, addr_size); |
2704 | 44 | } |
2705 | | |
2706 | 26 | p = frag_more (2 * addr_size); |
2707 | 26 | md_number_to_chars (p, 0, addr_size); |
2708 | 26 | md_number_to_chars (p + addr_size, 0, addr_size); |
2709 | | |
2710 | 26 | symbol_set_value_now (aranges_end); |
2711 | 26 | } |
2712 | | |
2713 | | /* Emit data for .debug_abbrev. Note that this must be kept in |
2714 | | sync with out_debug_info below. */ |
2715 | | |
2716 | | static void |
2717 | | out_debug_abbrev (segT abbrev_seg, |
2718 | | segT info_seg ATTRIBUTE_UNUSED, |
2719 | | segT line_seg ATTRIBUTE_UNUSED, |
2720 | | unsigned char *func_formP) |
2721 | 26 | { |
2722 | 26 | int secoff_form; |
2723 | 26 | bool have_efunc = false, have_lfunc = false; |
2724 | | |
2725 | | /* Check the symbol table for function symbols which also have their size |
2726 | | specified. */ |
2727 | 26 | if (symbol_rootP) |
2728 | 26 | { |
2729 | 26 | symbolS *symp; |
2730 | | |
2731 | 26.7k | for (symp = symbol_rootP; symp; symp = symbol_next (symp)) |
2732 | 26.7k | { |
2733 | | /* A warning construct is a warning symbol followed by the |
2734 | | symbol warned about. Skip this and the following symbol. */ |
2735 | 26.7k | if (symbol_get_bfdsym (symp)->flags & BSF_WARNING) |
2736 | 0 | { |
2737 | 0 | symp = symbol_next (symp); |
2738 | 0 | if (!symp) |
2739 | 0 | break; |
2740 | 0 | continue; |
2741 | 0 | } |
2742 | | |
2743 | 26.7k | if (!S_IS_DEFINED (symp) || !S_IS_FUNCTION (symp)) |
2744 | 26.7k | continue; |
2745 | | |
2746 | 2 | #if defined (OBJ_ELF) /* || defined (OBJ_MAYBE_ELF) */ |
2747 | 2 | if (S_GET_SIZE (symp) == 0) |
2748 | 1 | { |
2749 | 1 | if (!IS_ELF || symbol_get_obj (symp)->size == NULL) |
2750 | 1 | continue; |
2751 | 1 | } |
2752 | | #else |
2753 | | continue; |
2754 | | #endif |
2755 | | |
2756 | 1 | if (S_IS_EXTERNAL (symp)) |
2757 | 1 | have_efunc = true; |
2758 | 0 | else |
2759 | 0 | have_lfunc = true; |
2760 | 1 | } |
2761 | 26 | } |
2762 | | |
2763 | 26 | subseg_set (abbrev_seg, 0); |
2764 | | |
2765 | 26 | out_uleb128 (GAS_ABBREV_COMP_UNIT); |
2766 | 26 | out_uleb128 (DW_TAG_compile_unit); |
2767 | 26 | out_byte (have_efunc || have_lfunc ? DW_CHILDREN_yes : DW_CHILDREN_no); |
2768 | 26 | if (DWARF2_VERSION < 4) |
2769 | 0 | { |
2770 | 0 | if (DWARF2_FORMAT (line_seg) == dwarf2_format_32bit) |
2771 | 0 | secoff_form = DW_FORM_data4; |
2772 | 0 | else |
2773 | 0 | secoff_form = DW_FORM_data8; |
2774 | 0 | } |
2775 | 26 | else |
2776 | 26 | secoff_form = DW_FORM_sec_offset; |
2777 | 26 | out_abbrev (DW_AT_stmt_list, secoff_form); |
2778 | 26 | if (all_segs->next == NULL) |
2779 | 25 | { |
2780 | 25 | out_abbrev (DW_AT_low_pc, DW_FORM_addr); |
2781 | 25 | if (DWARF2_VERSION < 4) |
2782 | 0 | out_abbrev (DW_AT_high_pc, DW_FORM_addr); |
2783 | 25 | else |
2784 | 25 | out_abbrev (DW_AT_high_pc, DW_FORM_udata); |
2785 | 25 | } |
2786 | 1 | else |
2787 | 1 | out_abbrev (DW_AT_ranges, secoff_form); |
2788 | 26 | out_abbrev (DW_AT_name, DW_FORM_strp); |
2789 | 26 | out_abbrev (DW_AT_comp_dir, DW_FORM_strp); |
2790 | 26 | out_abbrev (DW_AT_producer, DW_FORM_strp); |
2791 | 26 | out_abbrev (DW_AT_language, DW_FORM_data2); |
2792 | 26 | out_abbrev (0, 0); |
2793 | | |
2794 | 26 | if (have_efunc || have_lfunc) |
2795 | 1 | { |
2796 | 1 | out_uleb128 (GAS_ABBREV_SUBPROG); |
2797 | 1 | out_uleb128 (DW_TAG_subprogram); |
2798 | 1 | out_byte (DW_CHILDREN_no); |
2799 | 1 | out_abbrev (DW_AT_name, DW_FORM_strp); |
2800 | 1 | if (have_efunc) |
2801 | 1 | { |
2802 | 1 | if (have_lfunc || DWARF2_VERSION < 4) |
2803 | 0 | *func_formP = DW_FORM_flag; |
2804 | 1 | else |
2805 | 1 | *func_formP = DW_FORM_flag_present; |
2806 | 1 | out_abbrev (DW_AT_external, *func_formP); |
2807 | 1 | } |
2808 | 0 | else |
2809 | | /* Any non-zero value other than DW_FORM_flag will do. */ |
2810 | 0 | *func_formP = DW_FORM_block; |
2811 | | |
2812 | | /* PR 29517: Provide a return type for the function. */ |
2813 | 1 | if (DWARF2_VERSION > 2) |
2814 | 1 | out_abbrev (DW_AT_type, DW_FORM_ref_udata); |
2815 | | |
2816 | 1 | out_abbrev (DW_AT_low_pc, DW_FORM_addr); |
2817 | 1 | out_abbrev (DW_AT_high_pc, |
2818 | 1 | DWARF2_VERSION < 4 ? DW_FORM_addr : DW_FORM_udata); |
2819 | 1 | out_abbrev (0, 0); |
2820 | | |
2821 | 1 | if (DWARF2_VERSION > 2) |
2822 | 1 | { |
2823 | | /* PR 29517: We do not actually know the return type of these |
2824 | | functions, so provide an abbrev that uses DWARF's unspecified |
2825 | | type. */ |
2826 | 1 | out_uleb128 (GAS_ABBREV_NO_TYPE); |
2827 | 1 | out_uleb128 (DW_TAG_unspecified_type); |
2828 | 1 | out_byte (DW_CHILDREN_no); |
2829 | 1 | out_abbrev (0, 0); |
2830 | 1 | } |
2831 | 1 | } |
2832 | | |
2833 | | /* Terminate the abbreviations for this compilation unit. */ |
2834 | 26 | out_byte (0); |
2835 | 26 | } |
2836 | | |
2837 | | /* Emit a description of this compilation unit for .debug_info. */ |
2838 | | |
2839 | | static void |
2840 | | out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT str_seg, |
2841 | | symbolS *ranges_sym, symbolS *name_sym, |
2842 | | symbolS *comp_dir_sym, symbolS *producer_sym, |
2843 | | unsigned char func_form) |
2844 | 26 | { |
2845 | 26 | expressionS exp; |
2846 | 26 | symbolS *info_end; |
2847 | 26 | int sizeof_offset; |
2848 | | |
2849 | 26 | memset (&exp, 0, sizeof exp); |
2850 | 26 | sizeof_offset = out_header (info_seg, &exp); |
2851 | 26 | info_end = exp.X_add_symbol; |
2852 | | |
2853 | | /* DWARF version. */ |
2854 | 26 | out_two (DWARF2_VERSION); |
2855 | | |
2856 | 26 | if (DWARF2_VERSION < 5) |
2857 | 0 | { |
2858 | | /* .debug_abbrev offset */ |
2859 | 0 | TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset); |
2860 | 0 | } |
2861 | 26 | else |
2862 | 26 | { |
2863 | | /* unit (header) type */ |
2864 | 26 | out_byte (DW_UT_compile); |
2865 | 26 | } |
2866 | | |
2867 | | /* Target address size. */ |
2868 | 26 | out_byte (sizeof_address); |
2869 | | |
2870 | 26 | if (DWARF2_VERSION >= 5) |
2871 | 26 | { |
2872 | | /* .debug_abbrev offset */ |
2873 | 26 | TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset); |
2874 | 26 | } |
2875 | | |
2876 | | /* DW_TAG_compile_unit DIE abbrev */ |
2877 | 26 | out_uleb128 (GAS_ABBREV_COMP_UNIT); |
2878 | | |
2879 | | /* DW_AT_stmt_list */ |
2880 | 26 | TC_DWARF2_EMIT_OFFSET (section_symbol (line_seg), |
2881 | 26 | (DWARF2_FORMAT (line_seg) == dwarf2_format_32bit |
2882 | 26 | ? 4 : 8)); |
2883 | | |
2884 | | /* These two attributes are emitted if all of the code is contiguous. */ |
2885 | 26 | if (all_segs->next == NULL) |
2886 | 25 | { |
2887 | | /* DW_AT_low_pc */ |
2888 | 25 | exp.X_op = O_symbol; |
2889 | 25 | exp.X_add_symbol = all_segs->text_start; |
2890 | 25 | exp.X_add_number = 0; |
2891 | 25 | emit_expr (&exp, sizeof_address); |
2892 | | |
2893 | | /* DW_AT_high_pc */ |
2894 | 25 | if (DWARF2_VERSION < 4) |
2895 | 0 | exp.X_op = O_symbol; |
2896 | 25 | else |
2897 | 25 | { |
2898 | 25 | exp.X_op = O_subtract; |
2899 | 25 | exp.X_op_symbol = all_segs->text_start; |
2900 | 25 | } |
2901 | 25 | exp.X_add_symbol = all_segs->text_end; |
2902 | 25 | exp.X_add_number = 0; |
2903 | 25 | if (DWARF2_VERSION < 4) |
2904 | 0 | emit_expr (&exp, sizeof_address); |
2905 | 25 | else |
2906 | 25 | emit_leb128_expr (&exp, 0); |
2907 | 25 | } |
2908 | 1 | else |
2909 | 1 | { |
2910 | | /* This attribute is emitted if the code is disjoint. */ |
2911 | | /* DW_AT_ranges. */ |
2912 | 1 | TC_DWARF2_EMIT_OFFSET (ranges_sym, sizeof_offset); |
2913 | 1 | } |
2914 | | |
2915 | | /* DW_AT_name, DW_AT_comp_dir and DW_AT_producer. Symbols in .debug_str |
2916 | | setup in out_debug_str below. */ |
2917 | 26 | TC_DWARF2_EMIT_OFFSET (name_sym, sizeof_offset); |
2918 | 26 | TC_DWARF2_EMIT_OFFSET (comp_dir_sym, sizeof_offset); |
2919 | 26 | TC_DWARF2_EMIT_OFFSET (producer_sym, sizeof_offset); |
2920 | | |
2921 | | /* DW_AT_language. Yes, this is probably not really MIPS, but the |
2922 | | dwarf2 draft has no standard code for assembler. */ |
2923 | 26 | out_two (DW_LANG_Mips_Assembler); |
2924 | | |
2925 | 26 | if (func_form) |
2926 | 1 | { |
2927 | 1 | symbolS *symp; |
2928 | 1 | symbolS *no_type_tag; |
2929 | | |
2930 | 1 | if (DWARF2_VERSION > 2) |
2931 | 1 | no_type_tag = symbol_make (".Ldebug_no_type_tag"); |
2932 | 0 | else |
2933 | 0 | no_type_tag = NULL; |
2934 | | |
2935 | 37 | for (symp = symbol_rootP; symp; symp = symbol_next (symp)) |
2936 | 36 | { |
2937 | 36 | const char *name; |
2938 | 36 | size_t len; |
2939 | 36 | expressionS size = { .X_op = O_constant }; |
2940 | | |
2941 | | /* Skip warning constructs (see above). */ |
2942 | 36 | if (symbol_get_bfdsym (symp)->flags & BSF_WARNING) |
2943 | 0 | { |
2944 | 0 | symp = symbol_next (symp); |
2945 | 0 | if (!symp) |
2946 | 0 | break; |
2947 | 0 | continue; |
2948 | 0 | } |
2949 | | |
2950 | 36 | if (!S_IS_DEFINED (symp) || !S_IS_FUNCTION (symp)) |
2951 | 35 | continue; |
2952 | | |
2953 | 1 | #if defined (OBJ_ELF) /* || defined (OBJ_MAYBE_ELF) */ |
2954 | 1 | size.X_add_number = S_GET_SIZE (symp); |
2955 | 1 | if (size.X_add_number == 0 && IS_ELF |
2956 | 0 | && symbol_get_obj (symp)->size != NULL) |
2957 | 0 | { |
2958 | 0 | size.X_op = O_add; |
2959 | 0 | size.X_op_symbol = make_expr_symbol (symbol_get_obj (symp)->size); |
2960 | 0 | } |
2961 | 1 | #endif |
2962 | 1 | if (size.X_op == O_constant && size.X_add_number == 0) |
2963 | 0 | continue; |
2964 | | |
2965 | 1 | subseg_set (str_seg, 0); |
2966 | 1 | name_sym = symbol_temp_new_now_octets (); |
2967 | 1 | name = S_GET_NAME (symp); |
2968 | 1 | len = strlen (name) + 1; |
2969 | 1 | memcpy (frag_more (len), name, len); |
2970 | | |
2971 | 1 | subseg_set (info_seg, 0); |
2972 | | |
2973 | | /* DW_TAG_subprogram DIE abbrev */ |
2974 | 1 | out_uleb128 (GAS_ABBREV_SUBPROG); |
2975 | | |
2976 | | /* DW_AT_name */ |
2977 | 1 | TC_DWARF2_EMIT_OFFSET (name_sym, sizeof_offset); |
2978 | | |
2979 | | /* DW_AT_external. */ |
2980 | 1 | if (func_form == DW_FORM_flag) |
2981 | 0 | out_byte (S_IS_EXTERNAL (symp)); |
2982 | | |
2983 | | /* PR 29517: Let consumers know that we do not have |
2984 | | return type information for this function. */ |
2985 | 1 | if (DWARF2_VERSION > 2) |
2986 | 1 | { |
2987 | 1 | exp.X_op = O_symbol; |
2988 | 1 | exp.X_add_symbol = no_type_tag; |
2989 | 1 | exp.X_add_number = 0; |
2990 | 1 | emit_leb128_expr (&exp, 0); |
2991 | 1 | } |
2992 | | |
2993 | | /* DW_AT_low_pc */ |
2994 | 1 | exp.X_op = O_symbol; |
2995 | 1 | exp.X_add_symbol = symp; |
2996 | 1 | exp.X_add_number = 0; |
2997 | 1 | emit_expr (&exp, sizeof_address); |
2998 | | |
2999 | | /* DW_AT_high_pc */ |
3000 | 1 | if (DWARF2_VERSION < 4) |
3001 | 0 | { |
3002 | 0 | if (size.X_op == O_constant) |
3003 | 0 | size.X_op = O_symbol; |
3004 | 0 | size.X_add_symbol = symp; |
3005 | 0 | emit_expr (&size, sizeof_address); |
3006 | 0 | } |
3007 | 1 | else if (size.X_op == O_constant) |
3008 | 1 | out_uleb128 (size.X_add_number); |
3009 | 0 | else |
3010 | 0 | emit_leb128_expr (symbol_get_value_expression (size.X_op_symbol), 0); |
3011 | 1 | } |
3012 | | |
3013 | 1 | if (DWARF2_VERSION > 2) |
3014 | 1 | { |
3015 | | /* PR 29517: Generate a DIE for the unspecified type abbrev. |
3016 | | We do it here because it cannot be part of the top level DIE. */ |
3017 | 1 | subseg_set (info_seg, 0); |
3018 | 1 | symbol_set_value_now (no_type_tag); |
3019 | 1 | out_uleb128 (GAS_ABBREV_NO_TYPE); |
3020 | 1 | } |
3021 | | |
3022 | | /* End of children. */ |
3023 | 1 | out_leb128 (0); |
3024 | 1 | } |
3025 | | |
3026 | 26 | symbol_set_value_now (info_end); |
3027 | 26 | } |
3028 | | |
3029 | | /* Emit the three debug strings needed in .debug_str and setup symbols |
3030 | | to them for use in out_debug_info. */ |
3031 | | static void |
3032 | | out_debug_str (segT str_seg, symbolS **name_sym, symbolS **comp_dir_sym, |
3033 | | symbolS **producer_sym) |
3034 | 26 | { |
3035 | 26 | char producer[128]; |
3036 | 26 | char *p; |
3037 | 26 | int len; |
3038 | 26 | int first_file = DWARF2_LINE_VERSION > 4 ? 0 : 1; |
3039 | | |
3040 | 26 | if (files_in_use == 0) |
3041 | 0 | abort (); |
3042 | 26 | if (first_file == 0 && files[first_file].filename == NULL) |
3043 | 0 | first_file = 1; |
3044 | | |
3045 | 26 | subseg_set (str_seg, 0); |
3046 | | |
3047 | | /* DW_AT_name. We don't have the actual file name that was present |
3048 | | on the command line, so assume files[first_file] is the main input file. |
3049 | | We're not supposed to get called unless at least one line number |
3050 | | entry was emitted, so this should always be defined. */ |
3051 | 26 | *name_sym = symbol_temp_new_now_octets (); |
3052 | | |
3053 | 26 | if (files[first_file].dir) |
3054 | 3 | { |
3055 | 3 | char *dirname = remap_debug_filename (dirs[files[first_file].dir]); |
3056 | 3 | len = strlen (dirname); |
3057 | | #ifdef TE_VMS |
3058 | | /* Already has trailing slash. */ |
3059 | | p = frag_more (len); |
3060 | | memcpy (p, dirname, len); |
3061 | | #else |
3062 | 3 | p = frag_more (len + 1); |
3063 | 3 | memcpy (p, dirname, len); |
3064 | 3 | INSERT_DIR_SEPARATOR (p, len); |
3065 | 3 | #endif |
3066 | 3 | free (dirname); |
3067 | 3 | } |
3068 | 26 | if (files[first_file].filename) |
3069 | 26 | { |
3070 | 26 | len = strlen (files[first_file].filename) + 1; |
3071 | 26 | p = frag_more (len); |
3072 | 26 | memcpy (p, files[first_file].filename, len); |
3073 | 26 | } |
3074 | 0 | else |
3075 | 0 | frag_append_1_char (0); |
3076 | | |
3077 | | /* DW_AT_comp_dir */ |
3078 | 26 | *comp_dir_sym = symbol_temp_new_now_octets (); |
3079 | 26 | char *comp_dir = remap_debug_filename (getpwd ()); |
3080 | 26 | len = strlen (comp_dir) + 1; |
3081 | 26 | p = frag_more (len); |
3082 | 26 | memcpy (p, comp_dir, len); |
3083 | 26 | free (comp_dir); |
3084 | | |
3085 | | /* DW_AT_producer */ |
3086 | 26 | *producer_sym = symbol_temp_new_now_octets (); |
3087 | 26 | sprintf (producer, "GNU AS %s", VERSION); |
3088 | 26 | len = strlen (producer) + 1; |
3089 | 26 | p = frag_more (len); |
3090 | 26 | memcpy (p, producer, len); |
3091 | 26 | } |
3092 | | |
3093 | | void |
3094 | | dwarf2_init (void) |
3095 | 339 | { |
3096 | 339 | all_segs = NULL; |
3097 | 339 | last_seg_ptr = &all_segs; |
3098 | 339 | files = NULL; |
3099 | 339 | files_in_use = 0; |
3100 | 339 | files_allocated = 0; |
3101 | 339 | dirs = NULL; |
3102 | 339 | dirs_in_use = 0; |
3103 | 339 | dirs_allocated = 0; |
3104 | 339 | dwarf2_loc_directive_seen = false; |
3105 | 339 | dwarf2_any_loc_directive_seen = false; |
3106 | 339 | dwarf2_loc_mark_labels = false; |
3107 | 339 | current.filenum = 1; |
3108 | 339 | current.line = 1; |
3109 | 339 | current.column = 0; |
3110 | 339 | current.isa = 0; |
3111 | 339 | current.flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0; |
3112 | 339 | current.discriminator = 0; |
3113 | 339 | current.u.view = NULL; |
3114 | 339 | force_reset_view = NULL; |
3115 | 339 | view_assert_failed = NULL; |
3116 | 339 | dw2_line = -1; |
3117 | 339 | dw2_filename = NULL; |
3118 | 339 | label_num = 0; |
3119 | 339 | last_used = -1; |
3120 | | |
3121 | | /* Select the default CIE version to produce here. The global |
3122 | | starts with a value of -1 and will be modified to a valid value |
3123 | | either by the user providing a command line option, or some |
3124 | | targets will select their own default in md_after_parse_args. If |
3125 | | we get here and the global still contains -1 then it is up to us |
3126 | | to pick a sane default. The default we choose is 1, this is the |
3127 | | CIE version gas has produced for a long time, and there seems no |
3128 | | reason to change it yet. */ |
3129 | 339 | if (flag_dwarf_cie_version == -1) |
3130 | 1 | flag_dwarf_cie_version = 1; |
3131 | 339 | } |
3132 | | |
3133 | | static void |
3134 | | dwarf2_cleanup (void) |
3135 | 339 | { |
3136 | 339 | purge_generated_debug (true); |
3137 | 339 | free (files); |
3138 | 378 | for (unsigned int i = 0; i < dirs_in_use; i++) |
3139 | 39 | free (dirs[i]); |
3140 | 339 | free (dirs); |
3141 | 339 | } |
3142 | | |
3143 | | /* Finish the dwarf2 debug sections. We emit .debug.line if there |
3144 | | were any .file/.loc directives, or --gdwarf2 was given, and if the |
3145 | | file has a non-empty .debug_info section and an empty .debug_line |
3146 | | section. If we emit .debug_line, and the .debug_info section is |
3147 | | empty, we also emit .debug_info, .debug_aranges and .debug_abbrev. |
3148 | | ALL_SEGS will be non-null if there were any .file/.loc directives, |
3149 | | or --gdwarf2 was given and there were any located instructions |
3150 | | emitted. */ |
3151 | | |
3152 | | void |
3153 | | dwarf2_finish (void) |
3154 | 339 | { |
3155 | 339 | segT line_seg; |
3156 | 339 | struct line_seg *s; |
3157 | 339 | segT info_seg; |
3158 | 339 | int emit_other_sections = 0; |
3159 | 339 | int empty_debug_line = 0; |
3160 | | |
3161 | 339 | info_seg = bfd_get_section_by_name (stdoutput, ".debug_info"); |
3162 | 339 | emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg); |
3163 | | |
3164 | 339 | line_seg = bfd_get_section_by_name (stdoutput, ".debug_line"); |
3165 | 339 | empty_debug_line = line_seg == NULL || !seg_not_empty_p (line_seg); |
3166 | | |
3167 | | /* We can't construct a new debug_line section if we already have one. |
3168 | | Give an error if we have seen any .loc, otherwise trust the user |
3169 | | knows what they are doing and want to generate the .debug_line |
3170 | | (and all other debug sections) themselves. */ |
3171 | 339 | if (all_segs && !empty_debug_line && dwarf2_any_loc_directive_seen) |
3172 | 0 | as_fatal ("duplicate .debug_line sections"); |
3173 | | |
3174 | 339 | if ((!all_segs && emit_other_sections) |
3175 | 28 | || (!emit_other_sections && !empty_debug_line)) |
3176 | | /* If there is no line information and no non-empty .debug_info |
3177 | | section, or if there is both a non-empty .debug_info and a non-empty |
3178 | | .debug_line, then we do nothing. */ |
3179 | 311 | { |
3180 | 311 | dwarf2_cleanup (); |
3181 | 311 | return; |
3182 | 311 | } |
3183 | | |
3184 | | /* Calculate the size of an address for the target machine. */ |
3185 | 28 | sizeof_address = DWARF2_ADDR_SIZE (stdoutput); |
3186 | | |
3187 | | /* Create and switch to the line number section. */ |
3188 | 28 | if (empty_debug_line) |
3189 | 28 | { |
3190 | 28 | line_seg = subseg_new (".debug_line", 0); |
3191 | 28 | bfd_set_section_flags (line_seg, |
3192 | 28 | SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS); |
3193 | 28 | } |
3194 | | |
3195 | 72 | for (s = all_segs; s; s = s->next) |
3196 | 44 | { |
3197 | 44 | struct line_subseg *lss; |
3198 | | |
3199 | 92 | for (lss = s->head; lss; lss = lss->next) |
3200 | 48 | if (lss->head) |
3201 | 48 | do_allocate_filenum (lss->head); |
3202 | 44 | } |
3203 | | |
3204 | | /* For each subsection, chain the debug entries together. */ |
3205 | 72 | for (s = all_segs; s; s = s->next) |
3206 | 44 | { |
3207 | 44 | struct line_subseg *lss = s->head; |
3208 | 44 | struct line_entry **ptail = lss->ptail; |
3209 | | |
3210 | | /* Reset the initial view of the first subsection of the |
3211 | | section. */ |
3212 | 44 | if (lss->head && lss->head->loc.u.view) |
3213 | 10 | set_or_check_view (lss->head, NULL, NULL); |
3214 | | |
3215 | 48 | while ((lss = lss->next) != NULL) |
3216 | 4 | { |
3217 | | /* Link the first view of subsequent subsections to the |
3218 | | previous view. */ |
3219 | 4 | if (lss->head && lss->head->loc.u.view) |
3220 | 4 | set_or_check_view (lss->head, line_entry_at_tail (s->head, ptail), |
3221 | 4 | s->head ? s->head->head : NULL); |
3222 | 4 | *ptail = lss->head; |
3223 | 4 | lss->head = NULL; |
3224 | 4 | ptail = lss->ptail; |
3225 | 4 | } |
3226 | 44 | } |
3227 | | |
3228 | 28 | if (empty_debug_line) |
3229 | 28 | out_debug_line (line_seg); |
3230 | | |
3231 | | /* If this is assembler generated line info, and there is no |
3232 | | debug_info already, we need .debug_info, .debug_abbrev and |
3233 | | .debug_str sections as well. */ |
3234 | 28 | if (emit_other_sections) |
3235 | 26 | { |
3236 | 26 | segT abbrev_seg; |
3237 | 26 | segT aranges_seg; |
3238 | 26 | segT str_seg; |
3239 | 26 | symbolS *name_sym, *comp_dir_sym, *producer_sym, *ranges_sym; |
3240 | 26 | unsigned char func_form = 0; |
3241 | | |
3242 | 26 | gas_assert (all_segs); |
3243 | | |
3244 | 26 | info_seg = subseg_new (".debug_info", 0); |
3245 | 26 | abbrev_seg = subseg_new (".debug_abbrev", 0); |
3246 | 26 | aranges_seg = subseg_new (".debug_aranges", 0); |
3247 | 26 | str_seg = subseg_new (".debug_str", 0); |
3248 | | |
3249 | 26 | bfd_set_section_flags (info_seg, |
3250 | 26 | SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS); |
3251 | 26 | bfd_set_section_flags (abbrev_seg, |
3252 | 26 | SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS); |
3253 | 26 | bfd_set_section_flags (aranges_seg, |
3254 | 26 | SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS); |
3255 | 26 | bfd_set_section_flags (str_seg, |
3256 | 26 | SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS |
3257 | 26 | | SEC_MERGE | SEC_STRINGS); |
3258 | 26 | str_seg->entsize = 1; |
3259 | | |
3260 | 26 | record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1); |
3261 | | |
3262 | 26 | if (all_segs->next == NULL) |
3263 | 25 | ranges_sym = NULL; |
3264 | 1 | else |
3265 | 1 | { |
3266 | 1 | if (DWARF2_VERSION < 5) |
3267 | 0 | { |
3268 | 0 | segT ranges_seg = subseg_new (".debug_ranges", 0); |
3269 | 0 | bfd_set_section_flags (ranges_seg, (SEC_READONLY |
3270 | 0 | | SEC_DEBUGGING |
3271 | 0 | | SEC_OCTETS)); |
3272 | 0 | record_alignment (ranges_seg, ffs (2 * sizeof_address) - 1); |
3273 | 0 | out_debug_ranges (ranges_seg, &ranges_sym); |
3274 | 0 | } |
3275 | 1 | else |
3276 | 1 | { |
3277 | 1 | segT rnglists_seg = subseg_new (".debug_rnglists", 0); |
3278 | 1 | bfd_set_section_flags (rnglists_seg, (SEC_READONLY |
3279 | 1 | | SEC_DEBUGGING |
3280 | 1 | | SEC_OCTETS)); |
3281 | 1 | out_debug_rnglists (rnglists_seg, &ranges_sym); |
3282 | 1 | } |
3283 | 1 | } |
3284 | | |
3285 | 26 | out_debug_aranges (aranges_seg, info_seg); |
3286 | 26 | out_debug_abbrev (abbrev_seg, info_seg, line_seg, &func_form); |
3287 | 26 | out_debug_str (str_seg, &name_sym, &comp_dir_sym, &producer_sym); |
3288 | 26 | out_debug_info (info_seg, abbrev_seg, line_seg, str_seg, |
3289 | 26 | ranges_sym, name_sym, comp_dir_sym, producer_sym, |
3290 | 26 | func_form); |
3291 | 26 | } |
3292 | 28 | dwarf2_cleanup (); |
3293 | 28 | } |
3294 | | |
3295 | | /* Perform any deferred checks pertaining to debug information. */ |
3296 | | |
3297 | | void |
3298 | | dwarf2dbg_final_check (void) |
3299 | 0 | { |
3300 | | /* Perform reset-view checks. Don't evaluate view_assert_failed |
3301 | | recursively: it could be very deep. It's a chain of adds, with |
3302 | | each chain element pointing to the next in X_add_symbol, and |
3303 | | holding the check value in X_op_symbol. */ |
3304 | 0 | while (view_assert_failed) |
3305 | 0 | { |
3306 | 0 | expressionS *exp; |
3307 | 0 | symbolS *sym; |
3308 | 0 | offsetT failed; |
3309 | |
|
3310 | 0 | gas_assert (!symbol_resolved_p (view_assert_failed)); |
3311 | | |
3312 | 0 | exp = symbol_get_value_expression (view_assert_failed); |
3313 | 0 | sym = view_assert_failed; |
3314 | | |
3315 | | /* If view_assert_failed looks like a compound check in the |
3316 | | chain, break it up. */ |
3317 | 0 | if (exp->X_op == O_add && exp->X_add_number == 0 && exp->X_unsigned) |
3318 | 0 | { |
3319 | 0 | view_assert_failed = exp->X_add_symbol; |
3320 | 0 | sym = exp->X_op_symbol; |
3321 | 0 | } |
3322 | 0 | else |
3323 | 0 | view_assert_failed = NULL; |
3324 | |
|
3325 | 0 | failed = resolve_symbol_value (sym); |
3326 | 0 | if (!symbol_resolved_p (sym) || failed) |
3327 | 0 | { |
3328 | | as_bad (_("view number mismatch")); |
3329 | 0 | break; |
3330 | 0 | } |
3331 | 0 | } |
3332 | 0 | } |