Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* coff object file format |
b985eaa8 | 2 | Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 |
252b5132 RH |
3 | Free Software Foundation, Inc. |
4 | ||
5 | This file is part of GAS. | |
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 2, 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, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
22 | #define OBJ_HEADER "obj-coff.h" | |
23 | ||
24 | #include "as.h" | |
25 | #include "obstack.h" | |
26 | #include "subsegs.h" | |
27 | ||
28 | /* I think this is probably always correct. */ | |
29 | #ifndef KEEP_RELOC_INFO | |
30 | #define KEEP_RELOC_INFO | |
31 | #endif | |
32 | ||
b8a9dcab NC |
33 | /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set |
34 | a new section's attributes when a directive has no valid flags or the | |
35 | "w" flag is used. This default should be appropriate for most. */ | |
36 | #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES | |
37 | #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA) | |
38 | #endif | |
39 | ||
252b5132 RH |
40 | static void obj_coff_bss PARAMS ((int)); |
41 | const char *s_get_name PARAMS ((symbolS * s)); | |
0561a208 ILT |
42 | static void obj_coff_ln PARAMS ((int)); |
43 | static void obj_coff_def PARAMS ((int)); | |
44 | static void obj_coff_endef PARAMS ((int)); | |
45 | static void obj_coff_dim PARAMS ((int)); | |
46 | static void obj_coff_line PARAMS ((int)); | |
47 | static void obj_coff_size PARAMS ((int)); | |
48 | static void obj_coff_scl PARAMS ((int)); | |
49 | static void obj_coff_tag PARAMS ((int)); | |
50 | static void obj_coff_val PARAMS ((int)); | |
51 | static void obj_coff_type PARAMS ((int)); | |
7a6284c4 | 52 | static void obj_coff_ident PARAMS ((int)); |
28428223 ILT |
53 | #ifdef BFD_ASSEMBLER |
54 | static void obj_coff_loc PARAMS((int)); | |
55 | #endif | |
0561a208 ILT |
56 | |
57 | /* This is used to hold the symbol built by a sequence of pseudo-ops | |
58 | from .def and .endef. */ | |
252b5132 | 59 | static symbolS *def_symbol_in_progress; |
252b5132 RH |
60 | \f |
61 | /* stack stuff */ | |
62 | typedef struct | |
63 | { | |
64 | unsigned long chunk_size; | |
65 | unsigned long element_size; | |
66 | unsigned long size; | |
67 | char *data; | |
68 | unsigned long pointer; | |
69 | } | |
70 | stack; | |
71 | ||
72 | static stack * | |
73 | stack_init (chunk_size, element_size) | |
74 | unsigned long chunk_size; | |
75 | unsigned long element_size; | |
76 | { | |
77 | stack *st; | |
78 | ||
79 | st = (stack *) malloc (sizeof (stack)); | |
80 | if (!st) | |
81 | return 0; | |
82 | st->data = malloc (chunk_size); | |
83 | if (!st->data) | |
84 | { | |
85 | free (st); | |
86 | return 0; | |
87 | } | |
88 | st->pointer = 0; | |
89 | st->size = chunk_size; | |
90 | st->chunk_size = chunk_size; | |
91 | st->element_size = element_size; | |
92 | return st; | |
93 | } | |
94 | ||
95 | #if 0 | |
96 | /* Not currently used. */ | |
97 | static void | |
98 | stack_delete (st) | |
99 | stack *st; | |
100 | { | |
101 | free (st->data); | |
102 | free (st); | |
103 | } | |
104 | #endif | |
105 | ||
106 | static char * | |
107 | stack_push (st, element) | |
108 | stack *st; | |
109 | char *element; | |
110 | { | |
111 | if (st->pointer + st->element_size >= st->size) | |
112 | { | |
113 | st->size += st->chunk_size; | |
114 | if ((st->data = xrealloc (st->data, st->size)) == (char *) 0) | |
115 | return (char *) 0; | |
116 | } | |
117 | memcpy (st->data + st->pointer, element, st->element_size); | |
118 | st->pointer += st->element_size; | |
119 | return st->data + st->pointer; | |
120 | } | |
121 | ||
122 | static char * | |
123 | stack_pop (st) | |
124 | stack *st; | |
125 | { | |
126 | if (st->pointer < st->element_size) | |
127 | { | |
128 | st->pointer = 0; | |
129 | return (char *) 0; | |
130 | } | |
131 | st->pointer -= st->element_size; | |
132 | return st->data + st->pointer; | |
133 | } | |
134 | \f | |
135 | /* | |
136 | * Maintain a list of the tagnames of the structres. | |
137 | */ | |
138 | ||
139 | static struct hash_control *tag_hash; | |
140 | ||
141 | static void | |
142 | tag_init () | |
143 | { | |
144 | tag_hash = hash_new (); | |
145 | } | |
146 | ||
147 | static void | |
148 | tag_insert (name, symbolP) | |
149 | const char *name; | |
150 | symbolS *symbolP; | |
151 | { | |
152 | const char *error_string; | |
153 | ||
154 | if ((error_string = hash_jam (tag_hash, name, (char *) symbolP))) | |
155 | { | |
156 | as_fatal (_("Inserting \"%s\" into structure table failed: %s"), | |
157 | name, error_string); | |
158 | } | |
159 | } | |
160 | ||
161 | static symbolS * | |
162 | tag_find (name) | |
163 | char *name; | |
164 | { | |
165 | #ifdef STRIP_UNDERSCORE | |
166 | if (*name == '_') | |
167 | name++; | |
168 | #endif /* STRIP_UNDERSCORE */ | |
169 | return (symbolS *) hash_find (tag_hash, name); | |
170 | } | |
171 | ||
172 | static symbolS * | |
173 | tag_find_or_make (name) | |
174 | char *name; | |
175 | { | |
176 | symbolS *symbolP; | |
177 | ||
178 | if ((symbolP = tag_find (name)) == NULL) | |
179 | { | |
180 | symbolP = symbol_new (name, undefined_section, | |
181 | 0, &zero_address_frag); | |
182 | ||
183 | tag_insert (S_GET_NAME (symbolP), symbolP); | |
184 | #ifdef BFD_ASSEMBLER | |
185 | symbol_table_insert (symbolP); | |
186 | #endif | |
187 | } /* not found */ | |
188 | ||
189 | return symbolP; | |
190 | } | |
191 | ||
192 | /* We accept the .bss directive to set the section for backward | |
193 | compatibility with earlier versions of gas. */ | |
194 | ||
195 | static void | |
196 | obj_coff_bss (ignore) | |
a04b544b | 197 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
198 | { |
199 | if (*input_line_pointer == '\n') | |
200 | subseg_new (".bss", get_absolute_expression ()); | |
201 | else | |
202 | s_lcomm (0); | |
203 | } | |
204 | ||
205 | /* Handle .weak. This is a GNU extension. */ | |
206 | ||
207 | static void | |
208 | obj_coff_weak (ignore) | |
a04b544b | 209 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
210 | { |
211 | char *name; | |
212 | int c; | |
213 | symbolS *symbolP; | |
214 | ||
215 | do | |
216 | { | |
217 | name = input_line_pointer; | |
218 | c = get_symbol_end (); | |
219 | symbolP = symbol_find_or_make (name); | |
220 | *input_line_pointer = c; | |
221 | SKIP_WHITESPACE (); | |
222 | ||
607723e4 | 223 | #ifdef BFD_ASSEMBLER |
252b5132 RH |
224 | S_SET_WEAK (symbolP); |
225 | #endif | |
226 | ||
227 | #ifdef TE_PE | |
228 | S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK); | |
229 | #else | |
230 | S_SET_STORAGE_CLASS (symbolP, C_WEAKEXT); | |
231 | #endif | |
232 | ||
233 | if (c == ',') | |
234 | { | |
235 | input_line_pointer++; | |
236 | SKIP_WHITESPACE (); | |
237 | if (*input_line_pointer == '\n') | |
238 | c = '\n'; | |
239 | } | |
240 | } | |
241 | while (c == ','); | |
242 | ||
243 | demand_empty_rest_of_line (); | |
244 | } | |
245 | ||
246 | #ifdef BFD_ASSEMBLER | |
247 | ||
248 | static void SA_SET_SYM_TAGNDX PARAMS ((symbolS *, symbolS *)); | |
249 | ||
250 | #define GET_FILENAME_STRING(X) \ | |
251 | ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1]) | |
252 | ||
253 | /* @@ Ick. */ | |
254 | static segT | |
255 | fetch_coff_debug_section () | |
256 | { | |
257 | static segT debug_section; | |
258 | if (!debug_section) | |
259 | { | |
260 | CONST asymbol *s; | |
261 | s = bfd_make_debug_symbol (stdoutput, (char *) 0, 0); | |
262 | assert (s != 0); | |
263 | debug_section = s->section; | |
264 | } | |
265 | return debug_section; | |
266 | } | |
267 | ||
268 | void | |
269 | SA_SET_SYM_ENDNDX (sym, val) | |
270 | symbolS *sym; | |
271 | symbolS *val; | |
272 | { | |
273 | combined_entry_type *entry, *p; | |
274 | ||
49309057 ILT |
275 | entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1]; |
276 | p = coffsymbol (symbol_get_bfdsym (val))->native; | |
252b5132 RH |
277 | entry->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p = p; |
278 | entry->fix_end = 1; | |
279 | } | |
280 | ||
281 | static void | |
282 | SA_SET_SYM_TAGNDX (sym, val) | |
283 | symbolS *sym; | |
284 | symbolS *val; | |
285 | { | |
286 | combined_entry_type *entry, *p; | |
287 | ||
49309057 ILT |
288 | entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1]; |
289 | p = coffsymbol (symbol_get_bfdsym (val))->native; | |
252b5132 RH |
290 | entry->u.auxent.x_sym.x_tagndx.p = p; |
291 | entry->fix_tag = 1; | |
292 | } | |
293 | ||
294 | static int | |
295 | S_GET_DATA_TYPE (sym) | |
296 | symbolS *sym; | |
297 | { | |
49309057 | 298 | return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type; |
252b5132 RH |
299 | } |
300 | ||
301 | int | |
302 | S_SET_DATA_TYPE (sym, val) | |
303 | symbolS *sym; | |
304 | int val; | |
305 | { | |
49309057 | 306 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type = val; |
252b5132 RH |
307 | return val; |
308 | } | |
309 | ||
310 | int | |
311 | S_GET_STORAGE_CLASS (sym) | |
312 | symbolS *sym; | |
313 | { | |
49309057 | 314 | return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass; |
252b5132 RH |
315 | } |
316 | ||
317 | int | |
318 | S_SET_STORAGE_CLASS (sym, val) | |
319 | symbolS *sym; | |
320 | int val; | |
321 | { | |
49309057 | 322 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass = val; |
252b5132 RH |
323 | return val; |
324 | } | |
325 | ||
326 | /* Merge a debug symbol containing debug information into a normal symbol. */ | |
327 | ||
328 | void | |
329 | c_symbol_merge (debug, normal) | |
330 | symbolS *debug; | |
331 | symbolS *normal; | |
332 | { | |
333 | S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug)); | |
334 | S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug)); | |
335 | ||
336 | if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal)) | |
337 | { | |
338 | /* take the most we have */ | |
339 | S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug)); | |
340 | } | |
341 | ||
342 | if (S_GET_NUMBER_AUXILIARY (debug) > 0) | |
343 | { | |
344 | /* Move all the auxiliary information. */ | |
345 | memcpy (SYM_AUXINFO (normal), SYM_AUXINFO (debug), | |
346 | (S_GET_NUMBER_AUXILIARY (debug) | |
347 | * sizeof (*SYM_AUXINFO (debug)))); | |
348 | } | |
349 | ||
350 | /* Move the debug flags. */ | |
351 | SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug)); | |
352 | } | |
353 | ||
354 | void | |
355 | c_dot_file_symbol (filename) | |
5110c57e | 356 | const char *filename; |
252b5132 RH |
357 | { |
358 | symbolS *symbolP; | |
359 | ||
0561a208 ILT |
360 | /* BFD converts filename to a .file symbol with an aux entry. It |
361 | also handles chaining. */ | |
252b5132 RH |
362 | symbolP = symbol_new (filename, bfd_abs_section_ptr, 0, &zero_address_frag); |
363 | ||
364 | S_SET_STORAGE_CLASS (symbolP, C_FILE); | |
365 | S_SET_NUMBER_AUXILIARY (symbolP, 1); | |
366 | ||
49309057 | 367 | symbol_get_bfdsym (symbolP)->flags = BSF_DEBUGGING; |
252b5132 RH |
368 | |
369 | #ifndef NO_LISTING | |
370 | { | |
371 | extern int listing; | |
372 | if (listing) | |
373 | { | |
374 | listing_source_file (filename); | |
375 | } | |
376 | } | |
377 | #endif | |
378 | ||
379 | /* Make sure that the symbol is first on the symbol chain */ | |
380 | if (symbol_rootP != symbolP) | |
381 | { | |
382 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
383 | symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP); | |
384 | } /* if not first on the list */ | |
385 | } | |
386 | ||
387 | /* Line number handling */ | |
388 | ||
389 | struct line_no { | |
390 | struct line_no *next; | |
391 | fragS *frag; | |
392 | alent l; | |
393 | }; | |
394 | ||
395 | int coff_line_base; | |
396 | ||
397 | /* Symbol of last function, which we should hang line#s off of. */ | |
398 | static symbolS *line_fsym; | |
399 | ||
400 | #define in_function() (line_fsym != 0) | |
401 | #define clear_function() (line_fsym = 0) | |
402 | #define set_function(F) (line_fsym = (F), coff_add_linesym (F)) | |
403 | ||
404 | \f | |
405 | void | |
406 | coff_obj_symbol_new_hook (symbolP) | |
407 | symbolS *symbolP; | |
408 | { | |
409 | long sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type); | |
410 | char * s = (char *) xmalloc (sz); | |
411 | ||
412 | memset (s, 0, sz); | |
49309057 | 413 | coffsymbol (symbol_get_bfdsym (symbolP))->native = (combined_entry_type *) s; |
252b5132 RH |
414 | |
415 | S_SET_DATA_TYPE (symbolP, T_NULL); | |
416 | S_SET_STORAGE_CLASS (symbolP, 0); | |
417 | S_SET_NUMBER_AUXILIARY (symbolP, 0); | |
418 | ||
419 | if (S_IS_STRING (symbolP)) | |
420 | SF_SET_STRING (symbolP); | |
421 | ||
422 | if (S_IS_LOCAL (symbolP)) | |
423 | SF_SET_LOCAL (symbolP); | |
424 | } | |
425 | ||
426 | \f | |
427 | /* | |
428 | * Handle .ln directives. | |
429 | */ | |
430 | ||
431 | static symbolS *current_lineno_sym; | |
432 | static struct line_no *line_nos; | |
433 | /* @@ Blindly assume all .ln directives will be in the .text section... */ | |
434 | int coff_n_line_nos; | |
435 | ||
436 | static void | |
437 | add_lineno (frag, offset, num) | |
438 | fragS *frag; | |
7f6d05e8 | 439 | addressT offset; |
252b5132 RH |
440 | int num; |
441 | { | |
442 | struct line_no *new_line = | |
443 | (struct line_no *) xmalloc (sizeof (struct line_no)); | |
444 | if (!current_lineno_sym) | |
445 | { | |
446 | abort (); | |
447 | } | |
e8a3ab75 ILT |
448 | if (num <= 0) |
449 | { | |
450 | /* Zero is used as an end marker in the file. */ | |
b985eaa8 ILT |
451 | as_warn (_("Line numbers must be positive integers\n")); |
452 | num = 1; | |
e8a3ab75 | 453 | } |
252b5132 RH |
454 | new_line->next = line_nos; |
455 | new_line->frag = frag; | |
456 | new_line->l.line_number = num; | |
457 | new_line->l.u.offset = offset; | |
458 | line_nos = new_line; | |
459 | coff_n_line_nos++; | |
460 | } | |
461 | ||
462 | void | |
463 | coff_add_linesym (sym) | |
464 | symbolS *sym; | |
465 | { | |
466 | if (line_nos) | |
467 | { | |
49309057 ILT |
468 | coffsymbol (symbol_get_bfdsym (current_lineno_sym))->lineno = |
469 | (alent *) line_nos; | |
252b5132 RH |
470 | coff_n_line_nos++; |
471 | line_nos = 0; | |
472 | } | |
473 | current_lineno_sym = sym; | |
474 | } | |
475 | ||
476 | static void | |
477 | obj_coff_ln (appline) | |
478 | int appline; | |
479 | { | |
480 | int l; | |
481 | ||
482 | if (! appline && def_symbol_in_progress != NULL) | |
483 | { | |
484 | as_warn (_(".ln pseudo-op inside .def/.endef: ignored.")); | |
485 | demand_empty_rest_of_line (); | |
486 | return; | |
487 | } | |
488 | ||
489 | l = get_absolute_expression (); | |
490 | if (!appline) | |
491 | { | |
492 | add_lineno (frag_now, frag_now_fix (), l); | |
493 | } | |
494 | ||
495 | if (appline) | |
496 | new_logical_line ((char *) NULL, l - 1); | |
497 | ||
498 | #ifndef NO_LISTING | |
499 | { | |
500 | extern int listing; | |
501 | ||
502 | if (listing) | |
503 | { | |
504 | if (! appline) | |
505 | l += coff_line_base - 1; | |
506 | listing_source_line (l); | |
507 | } | |
508 | } | |
509 | #endif | |
510 | ||
511 | demand_empty_rest_of_line (); | |
512 | } | |
513 | ||
28428223 ILT |
514 | /* .loc is essentially the same as .ln; parse it for assembler |
515 | compatibility. */ | |
516 | ||
517 | static void | |
518 | obj_coff_loc (ignore) | |
519 | int ignore ATTRIBUTE_UNUSED; | |
520 | { | |
521 | int lineno; | |
522 | ||
523 | /* FIXME: Why do we need this check? We need it for ECOFF, but why | |
524 | do we need it for COFF? */ | |
525 | if (now_seg != text_section) | |
526 | { | |
527 | as_warn (_(".loc outside of .text")); | |
528 | demand_empty_rest_of_line (); | |
529 | return; | |
530 | } | |
531 | ||
532 | if (def_symbol_in_progress != NULL) | |
533 | { | |
534 | as_warn (_(".loc pseudo-op inside .def/.endef: ignored.")); | |
535 | demand_empty_rest_of_line (); | |
536 | return; | |
537 | } | |
538 | ||
539 | /* Skip the file number. */ | |
540 | SKIP_WHITESPACE (); | |
541 | get_absolute_expression (); | |
542 | SKIP_WHITESPACE (); | |
543 | ||
544 | lineno = get_absolute_expression (); | |
545 | ||
546 | #ifndef NO_LISTING | |
547 | { | |
548 | extern int listing; | |
549 | ||
550 | if (listing) | |
551 | { | |
552 | lineno += coff_line_base - 1; | |
553 | listing_source_line (lineno); | |
554 | } | |
555 | } | |
556 | #endif | |
557 | ||
558 | demand_empty_rest_of_line (); | |
559 | ||
560 | add_lineno (frag_now, frag_now_fix (), lineno); | |
561 | } | |
562 | ||
7a6284c4 ILT |
563 | /* Handle the .ident pseudo-op. */ |
564 | ||
565 | static void | |
566 | obj_coff_ident (ignore) | |
567 | int ignore ATTRIBUTE_UNUSED; | |
568 | { | |
569 | segT current_seg = now_seg; | |
570 | subsegT current_subseg = now_subseg; | |
571 | ||
572 | #ifdef TE_PE | |
573 | { | |
574 | segT sec; | |
575 | ||
576 | /* We could put it in .comment, but that creates an extra section | |
577 | that shouldn't be loaded into memory, which requires linker | |
578 | changes... For now, until proven otherwise, use .rdata. */ | |
579 | sec = subseg_new (".rdata$zzz", 0); | |
580 | bfd_set_section_flags (stdoutput, sec, | |
581 | ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA) | |
582 | & bfd_applicable_section_flags (stdoutput))); | |
583 | } | |
584 | #else | |
585 | subseg_new (".comment", 0); | |
586 | #endif | |
587 | ||
588 | stringer (1); | |
589 | subseg_set (current_seg, current_subseg); | |
590 | } | |
591 | ||
252b5132 RH |
592 | /* |
593 | * def() | |
594 | * | |
595 | * Handle .def directives. | |
596 | * | |
597 | * One might ask : why can't we symbol_new if the symbol does not | |
598 | * already exist and fill it with debug information. Because of | |
599 | * the C_EFCN special symbol. It would clobber the value of the | |
600 | * function symbol before we have a chance to notice that it is | |
601 | * a C_EFCN. And a second reason is that the code is more clear this | |
602 | * way. (at least I think it is :-). | |
603 | * | |
604 | */ | |
605 | ||
606 | #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';') | |
607 | #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \ | |
608 | *input_line_pointer == '\t') \ | |
609 | input_line_pointer++; | |
610 | ||
611 | static void | |
612 | obj_coff_def (what) | |
c4bf532f | 613 | int what ATTRIBUTE_UNUSED; |
252b5132 RH |
614 | { |
615 | char name_end; /* Char after the end of name */ | |
616 | char *symbol_name; /* Name of the debug symbol */ | |
617 | char *symbol_name_copy; /* Temporary copy of the name */ | |
618 | unsigned int symbol_name_length; | |
619 | ||
620 | if (def_symbol_in_progress != NULL) | |
621 | { | |
622 | as_warn (_(".def pseudo-op used inside of .def/.endef: ignored.")); | |
623 | demand_empty_rest_of_line (); | |
624 | return; | |
625 | } /* if not inside .def/.endef */ | |
626 | ||
627 | SKIP_WHITESPACES (); | |
628 | ||
629 | symbol_name = input_line_pointer; | |
630 | #ifdef STRIP_UNDERSCORE | |
631 | if (symbol_name[0] == '_' && symbol_name[1] != 0) | |
632 | symbol_name++; | |
633 | #endif /* STRIP_UNDERSCORE */ | |
634 | ||
635 | name_end = get_symbol_end (); | |
636 | symbol_name_length = strlen (symbol_name); | |
637 | symbol_name_copy = xmalloc (symbol_name_length + 1); | |
638 | strcpy (symbol_name_copy, symbol_name); | |
639 | #ifdef tc_canonicalize_symbol_name | |
640 | symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy); | |
641 | #endif | |
642 | ||
643 | /* Initialize the new symbol */ | |
644 | def_symbol_in_progress = symbol_make (symbol_name_copy); | |
49309057 | 645 | symbol_set_frag (def_symbol_in_progress, &zero_address_frag); |
252b5132 RH |
646 | S_SET_VALUE (def_symbol_in_progress, 0); |
647 | ||
648 | if (S_IS_STRING (def_symbol_in_progress)) | |
649 | SF_SET_STRING (def_symbol_in_progress); | |
650 | ||
651 | *input_line_pointer = name_end; | |
652 | ||
653 | demand_empty_rest_of_line (); | |
654 | } | |
655 | ||
656 | unsigned int dim_index; | |
657 | ||
658 | static void | |
659 | obj_coff_endef (ignore) | |
c4bf532f | 660 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 661 | { |
c9900432 | 662 | symbolS *symbolP = NULL; |
252b5132 RH |
663 | |
664 | /* DIM BUG FIX sac@cygnus.com */ | |
665 | dim_index = 0; | |
666 | if (def_symbol_in_progress == NULL) | |
667 | { | |
668 | as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored.")); | |
669 | demand_empty_rest_of_line (); | |
670 | return; | |
671 | } /* if not inside .def/.endef */ | |
672 | ||
673 | /* Set the section number according to storage class. */ | |
674 | switch (S_GET_STORAGE_CLASS (def_symbol_in_progress)) | |
675 | { | |
676 | case C_STRTAG: | |
677 | case C_ENTAG: | |
678 | case C_UNTAG: | |
679 | SF_SET_TAG (def_symbol_in_progress); | |
680 | /* intentional fallthrough */ | |
681 | case C_FILE: | |
682 | case C_TPDEF: | |
683 | SF_SET_DEBUG (def_symbol_in_progress); | |
684 | S_SET_SEGMENT (def_symbol_in_progress, fetch_coff_debug_section ()); | |
685 | break; | |
686 | ||
687 | case C_EFCN: | |
688 | SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */ | |
689 | /* intentional fallthrough */ | |
690 | case C_BLOCK: | |
691 | SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */ | |
692 | /* intentional fallthrough */ | |
693 | case C_FCN: | |
694 | { | |
695 | CONST char *name; | |
696 | S_SET_SEGMENT (def_symbol_in_progress, text_section); | |
697 | ||
49309057 | 698 | name = S_GET_NAME (def_symbol_in_progress); |
23dab925 ILT |
699 | if (name[0] == '.' && name[2] == 'f' && name[3] == '\0') |
700 | { | |
701 | switch (name[1]) | |
702 | { | |
703 | case 'b': | |
704 | /* .bf */ | |
705 | if (! in_function ()) | |
706 | as_warn (_("`%s' symbol without preceding function"), name); | |
707 | /* Will need relocating. */ | |
708 | SF_SET_PROCESS (def_symbol_in_progress); | |
709 | clear_function (); | |
710 | break; | |
711 | #ifdef TE_PE | |
712 | case 'e': | |
713 | /* .ef */ | |
714 | /* The MS compilers output the actual endline, not the | |
715 | function-relative one... we want to match without | |
716 | changing the assembler input. */ | |
717 | SA_SET_SYM_LNNO (def_symbol_in_progress, | |
718 | (SA_GET_SYM_LNNO (def_symbol_in_progress) | |
719 | + coff_line_base)); | |
720 | break; | |
721 | #endif | |
722 | } | |
252b5132 RH |
723 | } |
724 | } | |
725 | break; | |
726 | ||
727 | #ifdef C_AUTOARG | |
728 | case C_AUTOARG: | |
729 | #endif /* C_AUTOARG */ | |
730 | case C_AUTO: | |
731 | case C_REG: | |
732 | case C_ARG: | |
733 | case C_REGPARM: | |
734 | case C_FIELD: | |
252b5132 RH |
735 | case C_MOS: |
736 | case C_MOE: | |
737 | case C_MOU: | |
738 | case C_EOS: | |
d1d8ba22 | 739 | SF_SET_DEBUG (def_symbol_in_progress); |
252b5132 RH |
740 | S_SET_SEGMENT (def_symbol_in_progress, absolute_section); |
741 | break; | |
742 | ||
743 | case C_EXT: | |
744 | case C_WEAKEXT: | |
745 | #ifdef TE_PE | |
746 | case C_NT_WEAK: | |
747 | #endif | |
748 | case C_STAT: | |
749 | case C_LABEL: | |
750 | /* Valid but set somewhere else (s_comm, s_lcomm, colon) */ | |
751 | break; | |
752 | ||
753 | default: | |
754 | case C_USTATIC: | |
755 | case C_EXTDEF: | |
756 | case C_ULABEL: | |
757 | as_warn (_("unexpected storage class %d"), | |
758 | S_GET_STORAGE_CLASS (def_symbol_in_progress)); | |
759 | break; | |
760 | } /* switch on storage class */ | |
761 | ||
762 | /* Now that we have built a debug symbol, try to find if we should | |
763 | merge with an existing symbol or not. If a symbol is C_EFCN or | |
9690c54d ILT |
764 | absolute_section or untagged SEG_DEBUG it never merges. We also |
765 | don't merge labels, which are in a different namespace, nor | |
766 | symbols which have not yet been defined since they are typically | |
767 | unique, nor do we merge tags with non-tags. */ | |
252b5132 RH |
768 | |
769 | /* Two cases for functions. Either debug followed by definition or | |
770 | definition followed by debug. For definition first, we will | |
771 | merge the debug symbol into the definition. For debug first, the | |
772 | lineno entry MUST point to the definition function or else it | |
773 | will point off into space when obj_crawl_symbol_chain() merges | |
774 | the debug symbol into the real symbol. Therefor, let's presume | |
775 | the debug symbol is a real function reference. */ | |
776 | ||
777 | /* FIXME-SOON If for some reason the definition label/symbol is | |
778 | never seen, this will probably leave an undefined symbol at link | |
779 | time. */ | |
780 | ||
781 | if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN | |
9690c54d | 782 | || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL |
252b5132 RH |
783 | || (!strcmp (bfd_get_section_name (stdoutput, |
784 | S_GET_SEGMENT (def_symbol_in_progress)), | |
785 | "*DEBUG*") | |
786 | && !SF_GET_TAG (def_symbol_in_progress)) | |
787 | || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section | |
9690c54d ILT |
788 | || ! symbol_constant_p (def_symbol_in_progress) |
789 | || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), | |
790 | DO_NOT_STRIP)) == NULL | |
791 | || SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP)) | |
252b5132 | 792 | { |
9690c54d | 793 | /* If it already is at the end of the symbol list, do nothing */ |
252b5132 | 794 | if (def_symbol_in_progress != symbol_lastP) |
9690c54d ILT |
795 | { |
796 | symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP); | |
797 | symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, | |
798 | &symbol_lastP); | |
799 | } | |
252b5132 RH |
800 | } |
801 | else | |
802 | { | |
803 | /* This symbol already exists, merge the newly created symbol | |
804 | into the old one. This is not mandatory. The linker can | |
805 | handle duplicate symbols correctly. But I guess that it save | |
806 | a *lot* of space if the assembly file defines a lot of | |
807 | symbols. [loic] */ | |
808 | ||
809 | /* The debug entry (def_symbol_in_progress) is merged into the | |
810 | previous definition. */ | |
811 | ||
812 | c_symbol_merge (def_symbol_in_progress, symbolP); | |
813 | symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP); | |
814 | ||
815 | def_symbol_in_progress = symbolP; | |
816 | ||
817 | if (SF_GET_FUNCTION (def_symbol_in_progress) | |
818 | || SF_GET_TAG (def_symbol_in_progress) | |
819 | || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT) | |
820 | { | |
821 | /* For functions, and tags, and static symbols, the symbol | |
822 | *must* be where the debug symbol appears. Move the | |
823 | existing symbol to the current place. */ | |
824 | /* If it already is at the end of the symbol list, do nothing */ | |
825 | if (def_symbol_in_progress != symbol_lastP) | |
826 | { | |
827 | symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP); | |
828 | symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, &symbol_lastP); | |
829 | } | |
830 | } | |
831 | } | |
832 | ||
833 | if (SF_GET_TAG (def_symbol_in_progress)) | |
834 | { | |
835 | symbolS *oldtag; | |
836 | ||
837 | oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress), | |
838 | DO_NOT_STRIP); | |
839 | if (oldtag == NULL || ! SF_GET_TAG (oldtag)) | |
840 | tag_insert (S_GET_NAME (def_symbol_in_progress), | |
841 | def_symbol_in_progress); | |
842 | } | |
843 | ||
844 | if (SF_GET_FUNCTION (def_symbol_in_progress)) | |
845 | { | |
846 | know (sizeof (def_symbol_in_progress) <= sizeof (long)); | |
847 | set_function (def_symbol_in_progress); | |
848 | SF_SET_PROCESS (def_symbol_in_progress); | |
849 | ||
850 | if (symbolP == NULL) | |
851 | { | |
852 | /* That is, if this is the first time we've seen the | |
853 | function... */ | |
854 | symbol_table_insert (def_symbol_in_progress); | |
855 | } /* definition follows debug */ | |
856 | } /* Create the line number entry pointing to the function being defined */ | |
857 | ||
858 | def_symbol_in_progress = NULL; | |
859 | demand_empty_rest_of_line (); | |
860 | } | |
861 | ||
862 | static void | |
863 | obj_coff_dim (ignore) | |
c4bf532f | 864 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
865 | { |
866 | int dim_index; | |
867 | ||
868 | if (def_symbol_in_progress == NULL) | |
869 | { | |
870 | as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored.")); | |
871 | demand_empty_rest_of_line (); | |
872 | return; | |
873 | } /* if not inside .def/.endef */ | |
874 | ||
875 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
876 | ||
877 | for (dim_index = 0; dim_index < DIMNUM; dim_index++) | |
878 | { | |
879 | SKIP_WHITESPACES (); | |
880 | SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index, | |
881 | get_absolute_expression ()); | |
882 | ||
883 | switch (*input_line_pointer) | |
884 | { | |
885 | case ',': | |
886 | input_line_pointer++; | |
887 | break; | |
888 | ||
889 | default: | |
890 | as_warn (_("badly formed .dim directive ignored")); | |
891 | /* intentional fallthrough */ | |
892 | case '\n': | |
893 | case ';': | |
894 | dim_index = DIMNUM; | |
895 | break; | |
896 | } | |
897 | } | |
898 | ||
899 | demand_empty_rest_of_line (); | |
900 | } | |
901 | ||
902 | static void | |
903 | obj_coff_line (ignore) | |
c4bf532f | 904 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
905 | { |
906 | int this_base; | |
907 | ||
908 | if (def_symbol_in_progress == NULL) | |
909 | { | |
910 | /* Probably stabs-style line? */ | |
911 | obj_coff_ln (0); | |
912 | return; | |
913 | } | |
914 | ||
915 | this_base = get_absolute_expression (); | |
916 | if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress))) | |
917 | coff_line_base = this_base; | |
918 | ||
919 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
23dab925 | 920 | SA_SET_SYM_LNNO (def_symbol_in_progress, this_base); |
252b5132 RH |
921 | |
922 | demand_empty_rest_of_line (); | |
923 | ||
924 | #ifndef NO_LISTING | |
925 | if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress)) == 0) | |
926 | { | |
927 | extern int listing; | |
928 | ||
929 | if (listing) | |
23dab925 | 930 | listing_source_line ((unsigned int) this_base); |
252b5132 RH |
931 | } |
932 | #endif | |
933 | } | |
934 | ||
935 | static void | |
936 | obj_coff_size (ignore) | |
c4bf532f | 937 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
938 | { |
939 | if (def_symbol_in_progress == NULL) | |
940 | { | |
941 | as_warn (_(".size pseudo-op used outside of .def/.endef ignored.")); | |
942 | demand_empty_rest_of_line (); | |
943 | return; | |
944 | } /* if not inside .def/.endef */ | |
945 | ||
946 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
947 | SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ()); | |
948 | demand_empty_rest_of_line (); | |
949 | } | |
950 | ||
951 | static void | |
952 | obj_coff_scl (ignore) | |
c4bf532f | 953 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
954 | { |
955 | if (def_symbol_in_progress == NULL) | |
956 | { | |
957 | as_warn (_(".scl pseudo-op used outside of .def/.endef ignored.")); | |
958 | demand_empty_rest_of_line (); | |
959 | return; | |
960 | } /* if not inside .def/.endef */ | |
961 | ||
962 | S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ()); | |
963 | demand_empty_rest_of_line (); | |
964 | } | |
965 | ||
966 | static void | |
967 | obj_coff_tag (ignore) | |
c4bf532f | 968 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
969 | { |
970 | char *symbol_name; | |
971 | char name_end; | |
972 | ||
973 | if (def_symbol_in_progress == NULL) | |
974 | { | |
975 | as_warn (_(".tag pseudo-op used outside of .def/.endef ignored.")); | |
976 | demand_empty_rest_of_line (); | |
977 | return; | |
978 | } | |
979 | ||
980 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
981 | symbol_name = input_line_pointer; | |
982 | name_end = get_symbol_end (); | |
983 | ||
984 | #ifdef tc_canonicalize_symbol_name | |
985 | symbol_name = tc_canonicalize_symbol_name (symbol_name); | |
986 | #endif | |
987 | ||
988 | /* Assume that the symbol referred to by .tag is always defined. | |
989 | This was a bad assumption. I've added find_or_make. xoxorich. */ | |
990 | SA_SET_SYM_TAGNDX (def_symbol_in_progress, | |
991 | tag_find_or_make (symbol_name)); | |
992 | if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L) | |
993 | { | |
994 | as_warn (_("tag not found for .tag %s"), symbol_name); | |
995 | } /* not defined */ | |
996 | ||
997 | SF_SET_TAGGED (def_symbol_in_progress); | |
998 | *input_line_pointer = name_end; | |
999 | ||
1000 | demand_empty_rest_of_line (); | |
1001 | } | |
1002 | ||
1003 | static void | |
1004 | obj_coff_type (ignore) | |
c4bf532f | 1005 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1006 | { |
1007 | if (def_symbol_in_progress == NULL) | |
1008 | { | |
1009 | as_warn (_(".type pseudo-op used outside of .def/.endef ignored.")); | |
1010 | demand_empty_rest_of_line (); | |
1011 | return; | |
1012 | } /* if not inside .def/.endef */ | |
1013 | ||
1014 | S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ()); | |
1015 | ||
1016 | if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) && | |
1017 | S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF) | |
1018 | { | |
1019 | SF_SET_FUNCTION (def_symbol_in_progress); | |
1020 | } /* is a function */ | |
1021 | ||
1022 | demand_empty_rest_of_line (); | |
1023 | } | |
1024 | ||
1025 | static void | |
1026 | obj_coff_val (ignore) | |
c4bf532f | 1027 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1028 | { |
1029 | if (def_symbol_in_progress == NULL) | |
1030 | { | |
1031 | as_warn (_(".val pseudo-op used outside of .def/.endef ignored.")); | |
1032 | demand_empty_rest_of_line (); | |
1033 | return; | |
1034 | } /* if not inside .def/.endef */ | |
1035 | ||
1036 | if (is_name_beginner (*input_line_pointer)) | |
1037 | { | |
1038 | char *symbol_name = input_line_pointer; | |
1039 | char name_end = get_symbol_end (); | |
1040 | ||
1041 | #ifdef tc_canonicalize_symbol_name | |
1042 | symbol_name = tc_canonicalize_symbol_name (symbol_name); | |
1043 | #endif | |
1044 | if (!strcmp (symbol_name, ".")) | |
1045 | { | |
49309057 | 1046 | symbol_set_frag (def_symbol_in_progress, frag_now); |
252b5132 RH |
1047 | S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ()); |
1048 | /* If the .val is != from the .def (e.g. statics) */ | |
1049 | } | |
1050 | else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name)) | |
1051 | { | |
49309057 ILT |
1052 | expressionS exp; |
1053 | ||
1054 | exp.X_op = O_symbol; | |
1055 | exp.X_add_symbol = symbol_find_or_make (symbol_name); | |
1056 | exp.X_op_symbol = NULL; | |
1057 | exp.X_add_number = 0; | |
1058 | symbol_set_value_expression (def_symbol_in_progress, &exp); | |
252b5132 RH |
1059 | |
1060 | /* If the segment is undefined when the forward reference is | |
1061 | resolved, then copy the segment id from the forward | |
1062 | symbol. */ | |
1063 | SF_SET_GET_SEGMENT (def_symbol_in_progress); | |
0561a208 ILT |
1064 | |
1065 | /* FIXME: gcc can generate address expressions here in | |
1066 | unusual cases (search for "obscure" in sdbout.c). We | |
1067 | just ignore the offset here, thus generating incorrect | |
1068 | debugging information. We ignore the rest of the line | |
1069 | just below. */ | |
252b5132 | 1070 | } |
0561a208 ILT |
1071 | /* Otherwise, it is the name of a non debug symbol and its value |
1072 | will be calculated later. */ | |
252b5132 RH |
1073 | *input_line_pointer = name_end; |
1074 | } | |
1075 | else | |
1076 | { | |
1077 | S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ()); | |
1078 | } /* if symbol based */ | |
1079 | ||
1080 | demand_empty_rest_of_line (); | |
1081 | } | |
1082 | ||
1083 | void | |
1084 | coff_obj_read_begin_hook () | |
1085 | { | |
1086 | /* These had better be the same. Usually 18 bytes. */ | |
1087 | #ifndef BFD_HEADERS | |
1088 | know (sizeof (SYMENT) == sizeof (AUXENT)); | |
1089 | know (SYMESZ == AUXESZ); | |
1090 | #endif | |
1091 | tag_init (); | |
1092 | } | |
1093 | ||
1094 | ||
1095 | symbolS *coff_last_function; | |
1096 | static symbolS *coff_last_bf; | |
1097 | ||
1098 | void | |
1099 | coff_frob_symbol (symp, punt) | |
1100 | symbolS *symp; | |
1101 | int *punt; | |
1102 | { | |
1103 | static symbolS *last_tagP; | |
1104 | static stack *block_stack; | |
1105 | static symbolS *set_end; | |
1106 | symbolS *next_set_end = NULL; | |
1107 | ||
1108 | if (symp == &abs_symbol) | |
1109 | { | |
1110 | *punt = 1; | |
1111 | return; | |
1112 | } | |
1113 | ||
1114 | if (current_lineno_sym) | |
1115 | coff_add_linesym ((symbolS *) 0); | |
1116 | ||
1117 | if (!block_stack) | |
1118 | block_stack = stack_init (512, sizeof (symbolS*)); | |
1119 | ||
1120 | if (S_IS_WEAK (symp)) | |
1121 | { | |
1122 | #ifdef TE_PE | |
1123 | S_SET_STORAGE_CLASS (symp, C_NT_WEAK); | |
1124 | #else | |
1125 | S_SET_STORAGE_CLASS (symp, C_WEAKEXT); | |
1126 | #endif | |
1127 | } | |
1128 | ||
1129 | if (!S_IS_DEFINED (symp) | |
1130 | && !S_IS_WEAK (symp) | |
1131 | && S_GET_STORAGE_CLASS (symp) != C_STAT) | |
1132 | S_SET_STORAGE_CLASS (symp, C_EXT); | |
1133 | ||
1134 | if (!SF_GET_DEBUG (symp)) | |
1135 | { | |
1136 | symbolS *real; | |
1137 | if (!SF_GET_LOCAL (symp) | |
1138 | && !SF_GET_STATICS (symp) | |
39da8128 DD |
1139 | && S_GET_STORAGE_CLASS (symp) != C_LABEL |
1140 | && symbol_constant_p(symp) | |
252b5132 RH |
1141 | && (real = symbol_find_base (S_GET_NAME (symp), DO_NOT_STRIP)) |
1142 | && real != symp) | |
1143 | { | |
1144 | c_symbol_merge (symp, real); | |
1145 | *punt = 1; | |
39da8128 | 1146 | return; |
252b5132 | 1147 | } |
5e0d736c | 1148 | if (!S_IS_DEFINED (symp) && !SF_GET_LOCAL (symp)) |
252b5132 | 1149 | { |
5e0d736c DD |
1150 | assert (S_GET_VALUE (symp) == 0); |
1151 | S_SET_EXTERNAL (symp); | |
1152 | } | |
1153 | else if (S_GET_STORAGE_CLASS (symp) == C_NULL) | |
1154 | { | |
1155 | if (S_GET_SEGMENT (symp) == text_section | |
1156 | && symp != seg_info (text_section)->sym) | |
1157 | S_SET_STORAGE_CLASS (symp, C_LABEL); | |
252b5132 | 1158 | else |
5e0d736c | 1159 | S_SET_STORAGE_CLASS (symp, C_STAT); |
252b5132 RH |
1160 | } |
1161 | if (SF_GET_PROCESS (symp)) | |
1162 | { | |
1163 | if (S_GET_STORAGE_CLASS (symp) == C_BLOCK) | |
1164 | { | |
1165 | if (!strcmp (S_GET_NAME (symp), ".bb")) | |
1166 | stack_push (block_stack, (char *) &symp); | |
1167 | else | |
1168 | { | |
1169 | symbolS *begin; | |
1170 | begin = *(symbolS **) stack_pop (block_stack); | |
1171 | if (begin == 0) | |
1172 | as_warn (_("mismatched .eb")); | |
1173 | else | |
1174 | next_set_end = begin; | |
1175 | } | |
1176 | } | |
1177 | if (coff_last_function == 0 && SF_GET_FUNCTION (symp)) | |
1178 | { | |
1179 | union internal_auxent *auxp; | |
1180 | coff_last_function = symp; | |
1181 | if (S_GET_NUMBER_AUXILIARY (symp) < 1) | |
1182 | S_SET_NUMBER_AUXILIARY (symp, 1); | |
0561a208 | 1183 | auxp = SYM_AUXENT (symp); |
252b5132 RH |
1184 | memset (auxp->x_sym.x_fcnary.x_ary.x_dimen, 0, |
1185 | sizeof (auxp->x_sym.x_fcnary.x_ary.x_dimen)); | |
1186 | } | |
1187 | if (S_GET_STORAGE_CLASS (symp) == C_EFCN) | |
1188 | { | |
1189 | if (coff_last_function == 0) | |
1190 | as_fatal (_("C_EFCN symbol out of scope")); | |
1191 | SA_SET_SYM_FSIZE (coff_last_function, | |
1192 | (long) (S_GET_VALUE (symp) | |
1193 | - S_GET_VALUE (coff_last_function))); | |
1194 | next_set_end = coff_last_function; | |
1195 | coff_last_function = 0; | |
1196 | } | |
1197 | } | |
1198 | if (S_IS_EXTERNAL (symp)) | |
1199 | S_SET_STORAGE_CLASS (symp, C_EXT); | |
1200 | else if (SF_GET_LOCAL (symp)) | |
1201 | *punt = 1; | |
1202 | ||
1203 | if (SF_GET_FUNCTION (symp)) | |
49309057 | 1204 | symbol_get_bfdsym (symp)->flags |= BSF_FUNCTION; |
252b5132 RH |
1205 | |
1206 | /* more ... */ | |
1207 | } | |
1208 | ||
8828d862 ILT |
1209 | /* Double check weak symbols. */ |
1210 | if (S_IS_WEAK (symp) && S_IS_COMMON (symp)) | |
1211 | as_bad (_("Symbol `%s' can not be both weak and common"), | |
1212 | S_GET_NAME (symp)); | |
1213 | ||
252b5132 RH |
1214 | if (SF_GET_TAG (symp)) |
1215 | last_tagP = symp; | |
1216 | else if (S_GET_STORAGE_CLASS (symp) == C_EOS) | |
1217 | next_set_end = last_tagP; | |
1218 | ||
1219 | #ifdef OBJ_XCOFF | |
1220 | /* This is pretty horrible, but we have to set *punt correctly in | |
1221 | order to call SA_SET_SYM_ENDNDX correctly. */ | |
809ffe0d | 1222 | if (! symbol_used_in_reloc_p (symp) |
49309057 | 1223 | && ((symbol_get_bfdsym (symp)->flags & BSF_SECTION_SYM) != 0 |
252b5132 | 1224 | || (! S_IS_EXTERNAL (symp) |
809ffe0d | 1225 | && ! symbol_get_tc (symp)->output |
252b5132 RH |
1226 | && S_GET_STORAGE_CLASS (symp) != C_FILE))) |
1227 | *punt = 1; | |
1228 | #endif | |
1229 | ||
1230 | if (set_end != (symbolS *) NULL | |
1231 | && ! *punt | |
49309057 | 1232 | && ((symbol_get_bfdsym (symp)->flags & BSF_NOT_AT_END) != 0 |
252b5132 RH |
1233 | || (S_IS_DEFINED (symp) |
1234 | && ! S_IS_COMMON (symp) | |
1235 | && (! S_IS_EXTERNAL (symp) || SF_GET_FUNCTION (symp))))) | |
1236 | { | |
1237 | SA_SET_SYM_ENDNDX (set_end, symp); | |
1238 | set_end = NULL; | |
1239 | } | |
1240 | ||
a04b544b ILT |
1241 | if (next_set_end != NULL) |
1242 | { | |
1243 | if (set_end != NULL) | |
1244 | as_warn ("Warning: internal error: forgetting to set endndx of %s", | |
1245 | S_GET_NAME (set_end)); | |
1246 | set_end = next_set_end; | |
1247 | } | |
252b5132 RH |
1248 | |
1249 | if (! *punt | |
1250 | && S_GET_STORAGE_CLASS (symp) == C_FCN | |
1251 | && strcmp (S_GET_NAME (symp), ".bf") == 0) | |
1252 | { | |
1253 | if (coff_last_bf != NULL) | |
1254 | SA_SET_SYM_ENDNDX (coff_last_bf, symp); | |
1255 | coff_last_bf = symp; | |
1256 | } | |
1257 | ||
49309057 | 1258 | if (coffsymbol (symbol_get_bfdsym (symp))->lineno) |
252b5132 RH |
1259 | { |
1260 | int i; | |
1261 | struct line_no *lptr; | |
1262 | alent *l; | |
1263 | ||
49309057 | 1264 | lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno; |
252b5132 RH |
1265 | for (i = 0; lptr; lptr = lptr->next) |
1266 | i++; | |
49309057 | 1267 | lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno; |
252b5132 RH |
1268 | |
1269 | /* We need i entries for line numbers, plus 1 for the first | |
1270 | entry which BFD will override, plus 1 for the last zero | |
1271 | entry (a marker for BFD). */ | |
1272 | l = (alent *) xmalloc ((i + 2) * sizeof (alent)); | |
49309057 | 1273 | coffsymbol (symbol_get_bfdsym (symp))->lineno = l; |
252b5132 RH |
1274 | l[i + 1].line_number = 0; |
1275 | l[i + 1].u.sym = NULL; | |
1276 | for (; i > 0; i--) | |
1277 | { | |
1278 | if (lptr->frag) | |
bea9907b | 1279 | lptr->l.u.offset += lptr->frag->fr_address / OCTETS_PER_BYTE; |
252b5132 RH |
1280 | l[i] = lptr->l; |
1281 | lptr = lptr->next; | |
1282 | } | |
1283 | } | |
1284 | } | |
1285 | ||
1286 | void | |
1287 | coff_adjust_section_syms (abfd, sec, x) | |
c4bf532f | 1288 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 1289 | asection *sec; |
c4bf532f | 1290 | PTR x ATTRIBUTE_UNUSED; |
252b5132 RH |
1291 | { |
1292 | symbolS *secsym; | |
1293 | segment_info_type *seginfo = seg_info (sec); | |
1294 | int nlnno, nrelocs = 0; | |
1295 | ||
1296 | /* RS/6000 gas creates a .debug section manually in ppc_frob_file in | |
1297 | tc-ppc.c. Do not get confused by it. */ | |
1298 | if (seginfo == NULL) | |
1299 | return; | |
1300 | ||
1301 | if (!strcmp (sec->name, ".text")) | |
1302 | nlnno = coff_n_line_nos; | |
1303 | else | |
1304 | nlnno = 0; | |
1305 | { | |
1306 | /* @@ Hope that none of the fixups expand to more than one reloc | |
1307 | entry... */ | |
1308 | fixS *fixp = seginfo->fix_root; | |
1309 | while (fixp) | |
1310 | { | |
1311 | if (! fixp->fx_done) | |
1312 | nrelocs++; | |
1313 | fixp = fixp->fx_next; | |
1314 | } | |
1315 | } | |
1316 | if (bfd_get_section_size_before_reloc (sec) == 0 | |
1317 | && nrelocs == 0 | |
1318 | && nlnno == 0 | |
1319 | && sec != text_section | |
1320 | && sec != data_section | |
1321 | && sec != bss_section) | |
1322 | return; | |
1323 | secsym = section_symbol (sec); | |
945a1a6b ILT |
1324 | /* This is an estimate; we'll plug in the real value using |
1325 | SET_SECTION_RELOCS later */ | |
252b5132 RH |
1326 | SA_SET_SCN_NRELOC (secsym, nrelocs); |
1327 | SA_SET_SCN_NLINNO (secsym, nlnno); | |
1328 | } | |
1329 | ||
1330 | void | |
1331 | coff_frob_file_after_relocs () | |
1332 | { | |
1333 | bfd_map_over_sections (stdoutput, coff_adjust_section_syms, (char*) 0); | |
1334 | } | |
1335 | ||
1336 | /* | |
1337 | * implement the .section pseudo op: | |
1338 | * .section name {, "flags"} | |
1339 | * ^ ^ | |
1340 | * | +--- optional flags: 'b' for bss | |
1341 | * | 'i' for info | |
1342 | * +-- section name 'l' for lib | |
1343 | * 'n' for noload | |
1344 | * 'o' for over | |
1345 | * 'w' for data | |
1346 | * 'd' (apparently m88k for data) | |
1347 | * 'x' for text | |
1348 | * 'r' for read-only data | |
2dcc60be | 1349 | * 's' for shared data (PE) |
252b5132 RH |
1350 | * But if the argument is not a quoted string, treat it as a |
1351 | * subsegment number. | |
1352 | */ | |
1353 | ||
1354 | void | |
1355 | obj_coff_section (ignore) | |
c4bf532f | 1356 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1357 | { |
1358 | /* Strip out the section name */ | |
1359 | char *section_name; | |
1360 | char c; | |
1361 | char *name; | |
1362 | unsigned int exp; | |
c9900432 | 1363 | flagword flags, oldflags; |
252b5132 RH |
1364 | asection *sec; |
1365 | ||
1366 | if (flag_mri) | |
1367 | { | |
1368 | char type; | |
1369 | ||
1370 | s_mri_sect (&type); | |
1371 | return; | |
1372 | } | |
1373 | ||
1374 | section_name = input_line_pointer; | |
1375 | c = get_symbol_end (); | |
1376 | ||
1377 | name = xmalloc (input_line_pointer - section_name + 1); | |
1378 | strcpy (name, section_name); | |
1379 | ||
1380 | *input_line_pointer = c; | |
1381 | ||
1382 | SKIP_WHITESPACE (); | |
1383 | ||
1384 | exp = 0; | |
c9900432 | 1385 | flags = SEC_NO_FLAGS; |
252b5132 RH |
1386 | |
1387 | if (*input_line_pointer == ',') | |
1388 | { | |
1389 | ++input_line_pointer; | |
1390 | SKIP_WHITESPACE (); | |
1391 | if (*input_line_pointer != '"') | |
1392 | exp = get_absolute_expression (); | |
1393 | else | |
1394 | { | |
1395 | ++input_line_pointer; | |
1396 | while (*input_line_pointer != '"' | |
1397 | && ! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1398 | { | |
1399 | switch (*input_line_pointer) | |
1400 | { | |
1401 | case 'b': flags |= SEC_ALLOC; flags &=~ SEC_LOAD; break; | |
1402 | case 'n': flags &=~ SEC_LOAD; break; | |
5881e4aa ILT |
1403 | case 'd': flags |= SEC_DATA | SEC_LOAD; /* fall through */ |
1404 | case 'w': flags &=~ SEC_READONLY; break; | |
1405 | case 'x': flags |= SEC_CODE | SEC_LOAD; break; | |
252b5132 | 1406 | case 'r': flags |= SEC_READONLY; break; |
2dcc60be | 1407 | case 's': flags |= SEC_SHARED; break; |
252b5132 RH |
1408 | |
1409 | case 'i': /* STYP_INFO */ | |
1410 | case 'l': /* STYP_LIB */ | |
1411 | case 'o': /* STYP_OVER */ | |
1412 | as_warn (_("unsupported section attribute '%c'"), | |
1413 | *input_line_pointer); | |
1414 | break; | |
1415 | ||
1416 | default: | |
1417 | as_warn(_("unknown section attribute '%c'"), | |
1418 | *input_line_pointer); | |
1419 | break; | |
1420 | } | |
1421 | ++input_line_pointer; | |
1422 | } | |
1423 | if (*input_line_pointer == '"') | |
1424 | ++input_line_pointer; | |
1425 | } | |
1426 | } | |
1427 | ||
1428 | sec = subseg_new (name, (subsegT) exp); | |
1429 | ||
c9900432 NC |
1430 | oldflags = bfd_get_section_flags (stdoutput, sec); |
1431 | if (oldflags == SEC_NO_FLAGS) | |
252b5132 | 1432 | { |
c9900432 NC |
1433 | /* Set section flags for a new section just created by subseg_new. |
1434 | Provide a default if no flags were parsed. */ | |
1435 | if (flags == SEC_NO_FLAGS) | |
1ad5eac0 | 1436 | flags = TC_COFF_SECTION_DEFAULT_ATTRIBUTES; |
c9900432 NC |
1437 | |
1438 | #ifdef COFF_LONG_SECTION_NAMES | |
1439 | /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce | |
1440 | sections so adjust_reloc_syms in write.c will correctly handle | |
1441 | relocs which refer to non-local symbols in these sections. */ | |
1442 | if (strncmp (name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0) | |
1443 | flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; | |
1444 | #endif | |
252b5132 RH |
1445 | |
1446 | if (! bfd_set_section_flags (stdoutput, sec, flags)) | |
c9900432 NC |
1447 | as_warn (_("error setting flags for \"%s\": %s"), |
1448 | bfd_section_name (stdoutput, sec), | |
1449 | bfd_errmsg (bfd_get_error ())); | |
1450 | } | |
1451 | else if (flags != SEC_NO_FLAGS) | |
1452 | { | |
1453 | /* This section's attributes have already been set. Warn if the | |
1454 | attributes don't match. */ | |
1455 | flagword matchflags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | |
1456 | | SEC_DATA | SEC_SHARED; | |
1457 | if ((flags ^ oldflags) & matchflags) | |
1458 | as_warn (_("Ignoring changed section attributes for %s"), name); | |
252b5132 RH |
1459 | } |
1460 | ||
1461 | demand_empty_rest_of_line (); | |
1462 | } | |
1463 | ||
1464 | void | |
1465 | coff_adjust_symtab () | |
1466 | { | |
1467 | if (symbol_rootP == NULL | |
1468 | || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE) | |
1469 | c_dot_file_symbol ("fake"); | |
1470 | } | |
1471 | ||
1472 | void | |
1473 | coff_frob_section (sec) | |
1474 | segT sec; | |
1475 | { | |
1476 | segT strsec; | |
1477 | char *p; | |
1478 | fragS *fragp; | |
1479 | bfd_vma size, n_entries, mask; | |
bea9907b | 1480 | bfd_vma align_power = (bfd_vma)sec->alignment_power + OCTETS_PER_BYTE_POWER; |
252b5132 RH |
1481 | |
1482 | /* The COFF back end in BFD requires that all section sizes be | |
bea9907b TW |
1483 | rounded up to multiples of the corresponding section alignments, |
1484 | supposedly because standard COFF has no other way of encoding alignment | |
1485 | for sections. If your COFF flavor has a different way of encoding | |
1486 | section alignment, then skip this step, as TICOFF does. */ | |
252b5132 | 1487 | size = bfd_get_section_size_before_reloc (sec); |
bea9907b TW |
1488 | mask = ((bfd_vma) 1 << align_power) - 1; |
1489 | #if !defined(TICOFF) | |
252b5132 RH |
1490 | if (size & mask) |
1491 | { | |
7f788821 NC |
1492 | bfd_vma new_size; |
1493 | fragS *last; | |
1494 | ||
1495 | new_size = (size + mask) & ~mask; | |
1496 | bfd_set_section_size (stdoutput, sec, new_size); | |
1497 | ||
1498 | /* If the size had to be rounded up, add some padding in | |
1499 | the last non-empty frag. */ | |
1500 | fragp = seg_info (sec)->frchainP->frch_root; | |
1501 | last = seg_info (sec)->frchainP->frch_last; | |
1502 | while (fragp->fr_next != last) | |
1503 | fragp = fragp->fr_next; | |
1504 | last->fr_address = size; | |
1505 | fragp->fr_offset += new_size - size; | |
252b5132 | 1506 | } |
bea9907b | 1507 | #endif |
252b5132 RH |
1508 | |
1509 | /* If the section size is non-zero, the section symbol needs an aux | |
1510 | entry associated with it, indicating the size. We don't know | |
1511 | all the values yet; coff_frob_symbol will fill them in later. */ | |
bea9907b | 1512 | #ifndef TICOFF |
252b5132 RH |
1513 | if (size != 0 |
1514 | || sec == text_section | |
1515 | || sec == data_section | |
1516 | || sec == bss_section) | |
bea9907b | 1517 | #endif |
252b5132 RH |
1518 | { |
1519 | symbolS *secsym = section_symbol (sec); | |
1520 | ||
1521 | S_SET_STORAGE_CLASS (secsym, C_STAT); | |
1522 | S_SET_NUMBER_AUXILIARY (secsym, 1); | |
1523 | SF_SET_STATICS (secsym); | |
1524 | SA_SET_SCN_SCNLEN (secsym, size); | |
1525 | } | |
1526 | ||
1527 | /* @@ these should be in a "stabs.h" file, or maybe as.h */ | |
1528 | #ifndef STAB_SECTION_NAME | |
1529 | #define STAB_SECTION_NAME ".stab" | |
1530 | #endif | |
1531 | #ifndef STAB_STRING_SECTION_NAME | |
1532 | #define STAB_STRING_SECTION_NAME ".stabstr" | |
1533 | #endif | |
1534 | if (strcmp (STAB_STRING_SECTION_NAME, sec->name)) | |
1535 | return; | |
1536 | ||
1537 | strsec = sec; | |
1538 | sec = subseg_get (STAB_SECTION_NAME, 0); | |
1539 | /* size is already rounded up, since other section will be listed first */ | |
1540 | size = bfd_get_section_size_before_reloc (strsec); | |
1541 | ||
1542 | n_entries = bfd_get_section_size_before_reloc (sec) / 12 - 1; | |
1543 | ||
1544 | /* Find first non-empty frag. It should be large enough. */ | |
1545 | fragp = seg_info (sec)->frchainP->frch_root; | |
1546 | while (fragp && fragp->fr_fix == 0) | |
1547 | fragp = fragp->fr_next; | |
1548 | assert (fragp != 0 && fragp->fr_fix >= 12); | |
1549 | ||
1550 | /* Store the values. */ | |
1551 | p = fragp->fr_literal; | |
1552 | bfd_h_put_16 (stdoutput, n_entries, (bfd_byte *) p + 6); | |
1553 | bfd_h_put_32 (stdoutput, size, (bfd_byte *) p + 8); | |
1554 | } | |
1555 | ||
1556 | void | |
1557 | obj_coff_init_stab_section (seg) | |
1558 | segT seg; | |
1559 | { | |
1560 | char *file; | |
1561 | char *p; | |
1562 | char *stabstr_name; | |
1563 | unsigned int stroff; | |
1564 | ||
1565 | /* Make space for this first symbol. */ | |
1566 | p = frag_more (12); | |
1567 | /* Zero it out. */ | |
1568 | memset (p, 0, 12); | |
1569 | as_where (&file, (unsigned int *) NULL); | |
1570 | stabstr_name = (char *) alloca (strlen (seg->name) + 4); | |
1571 | strcpy (stabstr_name, seg->name); | |
1572 | strcat (stabstr_name, "str"); | |
1573 | stroff = get_stab_string_offset (file, stabstr_name); | |
1574 | know (stroff == 1); | |
1575 | md_number_to_chars (p, stroff, 4); | |
1576 | } | |
1577 | ||
1578 | #ifdef DEBUG | |
1579 | /* for debugging */ | |
1580 | const char * | |
1581 | s_get_name (s) | |
1582 | symbolS *s; | |
1583 | { | |
1584 | return ((s == NULL) ? "(NULL)" : S_GET_NAME (s)); | |
1585 | } | |
1586 | ||
1587 | void | |
1588 | symbol_dump () | |
1589 | { | |
1590 | symbolS *symbolP; | |
1591 | ||
1592 | for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP)) | |
1593 | { | |
1594 | printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"), | |
1595 | (unsigned long) symbolP, | |
1596 | S_GET_NAME(symbolP), | |
1597 | (long) S_GET_DATA_TYPE(symbolP), | |
1598 | S_GET_STORAGE_CLASS(symbolP), | |
1599 | (int) S_GET_SEGMENT(symbolP)); | |
1600 | } | |
1601 | } | |
1602 | ||
1603 | #endif /* DEBUG */ | |
1604 | ||
1605 | #else /* not BFD_ASSEMBLER */ | |
1606 | ||
1607 | #include "frags.h" | |
1608 | /* This is needed because we include internal bfd things. */ | |
1609 | #include <time.h> | |
1610 | ||
1611 | #include "libbfd.h" | |
1612 | #include "libcoff.h" | |
1613 | ||
1614 | #ifdef TE_PE | |
1615 | #include "coff/pe.h" | |
1616 | #endif | |
1617 | ||
1618 | /* The NOP_OPCODE is for the alignment fill value. Fill with nop so | |
1619 | that we can stick sections together without causing trouble. */ | |
1620 | #ifndef NOP_OPCODE | |
1621 | #define NOP_OPCODE 0x00 | |
1622 | #endif | |
1623 | ||
1624 | /* The zeroes if symbol name is longer than 8 chars */ | |
1625 | #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v)) | |
1626 | ||
1627 | #define MIN(a,b) ((a) < (b)? (a) : (b)) | |
a04b544b ILT |
1628 | |
1629 | /* This vector is used to turn a gas internal segment number into a | |
1630 | section number suitable for insertion into a coff symbol table. | |
1631 | This must correspond to seg_info_off_by_4. */ | |
252b5132 RH |
1632 | |
1633 | const short seg_N_TYPE[] = | |
1634 | { /* in: segT out: N_TYPE bits */ | |
1635 | C_ABS_SECTION, | |
1636 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | |
1637 | 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, | |
1638 | 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, | |
1639 | 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | |
1640 | C_UNDEF_SECTION, /* SEG_UNKNOWN */ | |
1641 | C_UNDEF_SECTION, /* SEG_GOOF */ | |
1642 | C_UNDEF_SECTION, /* SEG_EXPR */ | |
1643 | C_DEBUG_SECTION, /* SEG_DEBUG */ | |
1644 | C_NTV_SECTION, /* SEG_NTV */ | |
1645 | C_PTV_SECTION, /* SEG_PTV */ | |
1646 | C_REGISTER_SECTION, /* SEG_REGISTER */ | |
1647 | }; | |
1648 | ||
1649 | int function_lineoff = -1; /* Offset in line#s where the last function | |
1650 | started (the odd entry for line #0) */ | |
1651 | ||
1652 | /* structure used to keep the filenames which | |
1653 | are too long around so that we can stick them | |
1654 | into the string table */ | |
1655 | struct filename_list | |
1656 | { | |
1657 | char *filename; | |
1658 | struct filename_list *next; | |
1659 | }; | |
1660 | ||
1661 | static struct filename_list *filename_list_head; | |
1662 | static struct filename_list *filename_list_tail; | |
1663 | ||
1664 | static symbolS *last_line_symbol; | |
1665 | ||
1666 | /* Add 4 to the real value to get the index and compensate the | |
1667 | negatives. This vector is used by S_GET_SEGMENT to turn a coff | |
1668 | section number into a segment number | |
1669 | */ | |
1670 | static symbolS *previous_file_symbol; | |
1671 | void c_symbol_merge (); | |
1672 | static int line_base; | |
1673 | ||
1674 | symbolS *c_section_symbol (); | |
1675 | bfd *abfd; | |
1676 | ||
1677 | static void fixup_segment PARAMS ((segment_info_type *segP, | |
1678 | segT this_segment_type)); | |
1679 | ||
1680 | ||
1681 | static void fixup_mdeps PARAMS ((fragS *, | |
1682 | object_headers *, | |
1683 | segT)); | |
1684 | ||
1685 | ||
1686 | static void fill_section PARAMS ((bfd * abfd, | |
1687 | object_headers *, | |
1688 | unsigned long *)); | |
1689 | ||
1690 | ||
1691 | static int c_line_new PARAMS ((symbolS * symbol, long paddr, | |
1692 | int line_number, | |
1693 | fragS * frag)); | |
1694 | ||
1695 | ||
1696 | static void w_symbols PARAMS ((bfd * abfd, char *where, | |
1697 | symbolS * symbol_rootP)); | |
1698 | ||
1699 | static void adjust_stab_section PARAMS ((bfd *abfd, segT seg)); | |
1700 | ||
1701 | static void obj_coff_lcomm PARAMS ((int)); | |
1702 | static void obj_coff_text PARAMS ((int)); | |
1703 | static void obj_coff_data PARAMS ((int)); | |
252b5132 RH |
1704 | void obj_coff_section PARAMS ((int)); |
1705 | ||
a04b544b | 1706 | /* When not using BFD_ASSEMBLER, we permit up to 40 sections. |
252b5132 | 1707 | |
a04b544b ILT |
1708 | This array maps a COFF section number into a gas section number. |
1709 | Because COFF uses negative section numbers, you must add 4 to the | |
1710 | COFF section number when indexing into this array; this is done via | |
1711 | the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to | |
1712 | seg_N_TYPE. */ | |
252b5132 | 1713 | |
a04b544b | 1714 | static const segT seg_info_off_by_4[] = |
252b5132 | 1715 | { |
a04b544b ILT |
1716 | SEG_PTV, |
1717 | SEG_NTV, | |
1718 | SEG_DEBUG, | |
1719 | SEG_ABSOLUTE, | |
1720 | SEG_UNKNOWN, | |
1721 | SEG_E0, SEG_E1, SEG_E2, SEG_E3, SEG_E4, | |
1722 | SEG_E5, SEG_E6, SEG_E7, SEG_E8, SEG_E9, | |
1723 | SEG_E10, SEG_E11, SEG_E12, SEG_E13, SEG_E14, | |
1724 | SEG_E15, SEG_E16, SEG_E17, SEG_E18, SEG_E19, | |
1725 | SEG_E20, SEG_E21, SEG_E22, SEG_E23, SEG_E24, | |
1726 | SEG_E25, SEG_E26, SEG_E27, SEG_E28, SEG_E29, | |
1727 | SEG_E30, SEG_E31, SEG_E32, SEG_E33, SEG_E34, | |
1728 | SEG_E35, SEG_E36, SEG_E37, SEG_E38, SEG_E39, | |
1729 | (segT) 40, | |
1730 | (segT) 41, | |
1731 | (segT) 42, | |
1732 | (segT) 43, | |
1733 | (segT) 44, | |
1734 | (segT) 45, | |
1735 | (segT) 0, | |
1736 | (segT) 0, | |
1737 | (segT) 0, | |
1738 | SEG_REGISTER | |
252b5132 RH |
1739 | }; |
1740 | ||
252b5132 RH |
1741 | #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4]) |
1742 | ||
1743 | static relax_addressT | |
1744 | relax_align (address, alignment) | |
1745 | relax_addressT address; | |
1746 | long alignment; | |
1747 | { | |
1748 | relax_addressT mask; | |
1749 | relax_addressT new_address; | |
1750 | ||
1751 | mask = ~((~0) << alignment); | |
1752 | new_address = (address + mask) & (~mask); | |
1753 | return (new_address - address); | |
1754 | } | |
1755 | ||
1756 | ||
1757 | segT | |
1758 | s_get_segment (x) | |
1759 | symbolS * x; | |
1760 | { | |
a04b544b | 1761 | return SEG_INFO_FROM_SECTION_NUMBER (x->sy_symbol.ost_entry.n_scnum); |
252b5132 RH |
1762 | } |
1763 | ||
1764 | /* calculate the size of the frag chain and fill in the section header | |
1765 | to contain all of it, also fill in the addr of the sections */ | |
1766 | static unsigned int | |
1767 | size_section (abfd, idx) | |
a04b544b | 1768 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1769 | unsigned int idx; |
1770 | { | |
1771 | ||
1772 | unsigned int size = 0; | |
1773 | fragS *frag = segment_info[idx].frchainP->frch_root; | |
1774 | while (frag) | |
1775 | { | |
1776 | size = frag->fr_address; | |
1777 | if (frag->fr_address != size) | |
1778 | { | |
1779 | fprintf (stderr, _("Out of step\n")); | |
1780 | size = frag->fr_address; | |
1781 | } | |
1782 | ||
1783 | switch (frag->fr_type) | |
1784 | { | |
1785 | #ifdef TC_COFF_SIZEMACHDEP | |
1786 | case rs_machine_dependent: | |
1787 | size += TC_COFF_SIZEMACHDEP (frag); | |
1788 | break; | |
1789 | #endif | |
1790 | case rs_space: | |
1791 | assert (frag->fr_symbol == 0); | |
1792 | case rs_fill: | |
1793 | case rs_org: | |
1794 | size += frag->fr_fix; | |
1795 | size += frag->fr_offset * frag->fr_var; | |
1796 | break; | |
1797 | case rs_align: | |
1798 | case rs_align_code: | |
1799 | { | |
1800 | addressT off; | |
1801 | ||
1802 | size += frag->fr_fix; | |
1803 | off = relax_align (size, frag->fr_offset); | |
1804 | if (frag->fr_subtype != 0 && off > frag->fr_subtype) | |
1805 | off = 0; | |
1806 | size += off; | |
1807 | } | |
1808 | break; | |
1809 | default: | |
1810 | BAD_CASE (frag->fr_type); | |
1811 | break; | |
1812 | } | |
1813 | frag = frag->fr_next; | |
1814 | } | |
1815 | segment_info[idx].scnhdr.s_size = size; | |
1816 | return size; | |
1817 | } | |
1818 | ||
1819 | ||
1820 | static unsigned int | |
1821 | count_entries_in_chain (idx) | |
1822 | unsigned int idx; | |
1823 | { | |
1824 | unsigned int nrelocs; | |
1825 | fixS *fixup_ptr; | |
1826 | ||
1827 | /* Count the relocations */ | |
1828 | fixup_ptr = segment_info[idx].fix_root; | |
1829 | nrelocs = 0; | |
1830 | while (fixup_ptr != (fixS *) NULL) | |
1831 | { | |
1832 | if (fixup_ptr->fx_done == 0 && TC_COUNT_RELOC (fixup_ptr)) | |
1833 | { | |
1834 | #ifdef TC_A29K | |
1835 | if (fixup_ptr->fx_r_type == RELOC_CONSTH) | |
1836 | nrelocs += 2; | |
1837 | else | |
1838 | nrelocs++; | |
1839 | #else | |
1840 | nrelocs++; | |
1841 | #endif | |
1842 | } | |
1843 | ||
1844 | fixup_ptr = fixup_ptr->fx_next; | |
1845 | } | |
1846 | return nrelocs; | |
1847 | } | |
1848 | ||
1849 | #ifdef TE_AUX | |
1850 | ||
1851 | static int compare_external_relocs PARAMS ((const PTR, const PTR)); | |
1852 | ||
1853 | /* AUX's ld expects relocations to be sorted */ | |
1854 | static int | |
1855 | compare_external_relocs (x, y) | |
1856 | const PTR x; | |
1857 | const PTR y; | |
1858 | { | |
1859 | struct external_reloc *a = (struct external_reloc *) x; | |
1860 | struct external_reloc *b = (struct external_reloc *) y; | |
1861 | bfd_vma aadr = bfd_getb32 (a->r_vaddr); | |
1862 | bfd_vma badr = bfd_getb32 (b->r_vaddr); | |
1863 | return (aadr < badr ? -1 : badr < aadr ? 1 : 0); | |
1864 | } | |
1865 | ||
1866 | #endif | |
1867 | ||
1868 | /* output all the relocations for a section */ | |
1869 | void | |
1870 | do_relocs_for (abfd, h, file_cursor) | |
1871 | bfd * abfd; | |
1872 | object_headers * h; | |
1873 | unsigned long *file_cursor; | |
1874 | { | |
1875 | unsigned int nrelocs; | |
1876 | unsigned int idx; | |
1877 | unsigned long reloc_start = *file_cursor; | |
1878 | ||
1879 | for (idx = SEG_E0; idx < SEG_LAST; idx++) | |
1880 | { | |
1881 | if (segment_info[idx].scnhdr.s_name[0]) | |
1882 | { | |
1883 | struct external_reloc *ext_ptr; | |
1884 | struct external_reloc *external_reloc_vec; | |
1885 | unsigned int external_reloc_size; | |
1886 | unsigned int base = segment_info[idx].scnhdr.s_paddr; | |
1887 | fixS *fix_ptr = segment_info[idx].fix_root; | |
1888 | nrelocs = count_entries_in_chain (idx); | |
1889 | ||
1890 | if (nrelocs) | |
1891 | /* Bypass this stuff if no relocs. This also incidentally | |
1892 | avoids a SCO bug, where free(malloc(0)) tends to crash. */ | |
1893 | { | |
1894 | external_reloc_size = nrelocs * RELSZ; | |
1895 | external_reloc_vec = | |
1896 | (struct external_reloc *) malloc (external_reloc_size); | |
1897 | ||
1898 | ext_ptr = external_reloc_vec; | |
1899 | ||
1900 | /* Fill in the internal coff style reloc struct from the | |
1901 | internal fix list. */ | |
1902 | while (fix_ptr) | |
1903 | { | |
1904 | struct internal_reloc intr; | |
1905 | ||
1906 | /* Only output some of the relocations */ | |
1907 | if (fix_ptr->fx_done == 0 && TC_COUNT_RELOC (fix_ptr)) | |
1908 | { | |
1909 | #ifdef TC_RELOC_MANGLE | |
1910 | TC_RELOC_MANGLE (&segment_info[idx], fix_ptr, &intr, | |
1911 | base); | |
1912 | ||
1913 | #else | |
1914 | symbolS *dot; | |
1915 | symbolS *symbol_ptr = fix_ptr->fx_addsy; | |
1916 | ||
1917 | intr.r_type = TC_COFF_FIX2RTYPE (fix_ptr); | |
1918 | intr.r_vaddr = | |
1919 | base + fix_ptr->fx_frag->fr_address + fix_ptr->fx_where; | |
1920 | ||
1921 | #ifdef TC_KEEP_FX_OFFSET | |
1922 | intr.r_offset = fix_ptr->fx_offset; | |
1923 | #else | |
1924 | intr.r_offset = 0; | |
1925 | #endif | |
1926 | ||
1927 | while (symbol_ptr->sy_value.X_op == O_symbol | |
1928 | && (! S_IS_DEFINED (symbol_ptr) | |
1929 | || S_IS_COMMON (symbol_ptr))) | |
1930 | { | |
1931 | symbolS *n; | |
1932 | ||
1933 | /* We must avoid looping, as that can occur | |
1934 | with a badly written program. */ | |
1935 | n = symbol_ptr->sy_value.X_add_symbol; | |
1936 | if (n == symbol_ptr) | |
1937 | break; | |
1938 | symbol_ptr = n; | |
1939 | } | |
1940 | ||
1941 | /* Turn the segment of the symbol into an offset. */ | |
1942 | if (symbol_ptr) | |
1943 | { | |
1944 | resolve_symbol_value (symbol_ptr, 1); | |
1945 | if (! symbol_ptr->sy_resolved) | |
1946 | { | |
1947 | char *file; | |
1948 | unsigned int line; | |
1949 | ||
1950 | if (expr_symbol_where (symbol_ptr, &file, &line)) | |
1951 | as_bad_where (file, line, | |
1952 | _("unresolved relocation")); | |
1953 | else | |
1954 | as_bad (_("bad relocation: symbol `%s' not in symbol table"), | |
1955 | S_GET_NAME (symbol_ptr)); | |
1956 | } | |
1957 | dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot; | |
1958 | if (dot) | |
1959 | { | |
1960 | intr.r_symndx = dot->sy_number; | |
1961 | } | |
1962 | else | |
1963 | { | |
1964 | intr.r_symndx = symbol_ptr->sy_number; | |
1965 | } | |
1966 | ||
1967 | } | |
1968 | else | |
1969 | { | |
1970 | intr.r_symndx = -1; | |
1971 | } | |
1972 | #endif | |
1973 | ||
1974 | (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr); | |
1975 | ext_ptr++; | |
1976 | ||
1977 | #if defined(TC_A29K) | |
1978 | ||
1979 | /* The 29k has a special kludge for the high 16 bit | |
1980 | reloc. Two relocations are emited, R_IHIHALF, | |
1981 | and R_IHCONST. The second one doesn't contain a | |
1982 | symbol, but uses the value for offset. */ | |
1983 | ||
1984 | if (intr.r_type == R_IHIHALF) | |
1985 | { | |
1986 | /* now emit the second bit */ | |
1987 | intr.r_type = R_IHCONST; | |
1988 | intr.r_symndx = fix_ptr->fx_addnumber; | |
1989 | (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr); | |
1990 | ext_ptr++; | |
1991 | } | |
1992 | #endif | |
1993 | } | |
1994 | ||
1995 | fix_ptr = fix_ptr->fx_next; | |
1996 | } | |
1997 | ||
1998 | #ifdef TE_AUX | |
1999 | /* Sort the reloc table */ | |
2000 | qsort ((PTR) external_reloc_vec, nrelocs, | |
2001 | sizeof (struct external_reloc), compare_external_relocs); | |
2002 | #endif | |
2003 | ||
2004 | /* Write out the reloc table */ | |
2005 | bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size, | |
2006 | abfd); | |
2007 | free (external_reloc_vec); | |
2008 | ||
2009 | /* Fill in section header info. */ | |
2010 | segment_info[idx].scnhdr.s_relptr = *file_cursor; | |
2011 | *file_cursor += external_reloc_size; | |
2012 | segment_info[idx].scnhdr.s_nreloc = nrelocs; | |
2013 | } | |
2014 | else | |
2015 | { | |
2016 | /* No relocs */ | |
2017 | segment_info[idx].scnhdr.s_relptr = 0; | |
2018 | } | |
2019 | } | |
2020 | } | |
2021 | /* Set relocation_size field in file headers */ | |
2022 | H_SET_RELOCATION_SIZE (h, *file_cursor - reloc_start, 0); | |
2023 | } | |
2024 | ||
2025 | ||
2026 | /* run through a frag chain and write out the data to go with it, fill | |
2027 | in the scnhdrs with the info on the file postions | |
2028 | */ | |
2029 | static void | |
2030 | fill_section (abfd, h, file_cursor) | |
2031 | bfd * abfd; | |
a04b544b | 2032 | object_headers *h ATTRIBUTE_UNUSED; |
252b5132 RH |
2033 | unsigned long *file_cursor; |
2034 | { | |
2035 | ||
2036 | unsigned int i; | |
2037 | unsigned int paddr = 0; | |
2038 | ||
2039 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
2040 | { | |
2041 | unsigned int offset = 0; | |
2042 | struct internal_scnhdr *s = &(segment_info[i].scnhdr); | |
2043 | ||
2044 | PROGRESS (1); | |
2045 | ||
2046 | if (s->s_name[0]) | |
2047 | { | |
2048 | fragS *frag = segment_info[i].frchainP->frch_root; | |
2049 | char *buffer; | |
2050 | ||
2051 | if (s->s_size == 0) | |
2052 | s->s_scnptr = 0; | |
2053 | else | |
2054 | { | |
2055 | buffer = xmalloc (s->s_size); | |
2056 | s->s_scnptr = *file_cursor; | |
2057 | } | |
2058 | know (s->s_paddr == paddr); | |
2059 | ||
2060 | if (strcmp (s->s_name, ".text") == 0) | |
2061 | s->s_flags |= STYP_TEXT; | |
2062 | else if (strcmp (s->s_name, ".data") == 0) | |
2063 | s->s_flags |= STYP_DATA; | |
2064 | else if (strcmp (s->s_name, ".bss") == 0) | |
2065 | { | |
2066 | s->s_scnptr = 0; | |
2067 | s->s_flags |= STYP_BSS; | |
2068 | ||
2069 | /* @@ Should make the i386 and a29k coff targets define | |
2070 | COFF_NOLOAD_PROBLEM, and have only one test here. */ | |
2071 | #ifndef TC_I386 | |
2072 | #ifndef TC_A29K | |
2073 | #ifndef COFF_NOLOAD_PROBLEM | |
2074 | /* Apparently the SVR3 linker (and exec syscall) and UDI | |
2075 | mondfe progrem are confused by noload sections. */ | |
2076 | s->s_flags |= STYP_NOLOAD; | |
2077 | #endif | |
2078 | #endif | |
2079 | #endif | |
2080 | } | |
2081 | else if (strcmp (s->s_name, ".lit") == 0) | |
2082 | s->s_flags = STYP_LIT | STYP_TEXT; | |
2083 | else if (strcmp (s->s_name, ".init") == 0) | |
2084 | s->s_flags |= STYP_TEXT; | |
2085 | else if (strcmp (s->s_name, ".fini") == 0) | |
2086 | s->s_flags |= STYP_TEXT; | |
2087 | else if (strncmp (s->s_name, ".comment", 8) == 0) | |
2088 | s->s_flags |= STYP_INFO; | |
2089 | ||
2090 | while (frag) | |
2091 | { | |
2092 | unsigned int fill_size; | |
2093 | switch (frag->fr_type) | |
2094 | { | |
2095 | case rs_machine_dependent: | |
2096 | if (frag->fr_fix) | |
2097 | { | |
2098 | memcpy (buffer + frag->fr_address, | |
2099 | frag->fr_literal, | |
2100 | (unsigned int) frag->fr_fix); | |
2101 | offset += frag->fr_fix; | |
2102 | } | |
2103 | ||
2104 | break; | |
2105 | case rs_space: | |
2106 | assert (frag->fr_symbol == 0); | |
2107 | case rs_fill: | |
2108 | case rs_align: | |
2109 | case rs_align_code: | |
2110 | case rs_org: | |
2111 | if (frag->fr_fix) | |
2112 | { | |
2113 | memcpy (buffer + frag->fr_address, | |
2114 | frag->fr_literal, | |
2115 | (unsigned int) frag->fr_fix); | |
2116 | offset += frag->fr_fix; | |
2117 | } | |
2118 | ||
2119 | fill_size = frag->fr_var; | |
2120 | if (fill_size && frag->fr_offset > 0) | |
2121 | { | |
2122 | unsigned int count; | |
2123 | unsigned int off = frag->fr_fix; | |
2124 | for (count = frag->fr_offset; count; count--) | |
2125 | { | |
2126 | if (fill_size + frag->fr_address + off <= s->s_size) | |
2127 | { | |
2128 | memcpy (buffer + frag->fr_address + off, | |
2129 | frag->fr_literal + frag->fr_fix, | |
2130 | fill_size); | |
2131 | off += fill_size; | |
2132 | offset += fill_size; | |
2133 | } | |
2134 | } | |
2135 | } | |
2136 | break; | |
2137 | case rs_broken_word: | |
2138 | break; | |
2139 | default: | |
2140 | abort (); | |
2141 | } | |
2142 | frag = frag->fr_next; | |
2143 | } | |
2144 | ||
2145 | if (s->s_size != 0) | |
2146 | { | |
2147 | if (s->s_scnptr != 0) | |
2148 | { | |
2149 | bfd_write (buffer, s->s_size, 1, abfd); | |
2150 | *file_cursor += s->s_size; | |
2151 | } | |
2152 | free (buffer); | |
2153 | } | |
2154 | paddr += s->s_size; | |
2155 | } | |
2156 | } | |
2157 | } | |
2158 | ||
2159 | /* Coff file generation & utilities */ | |
2160 | ||
2161 | static void | |
2162 | coff_header_append (abfd, h) | |
2163 | bfd * abfd; | |
2164 | object_headers * h; | |
2165 | { | |
2166 | unsigned int i; | |
2167 | char buffer[1000]; | |
2168 | char buffero[1000]; | |
2169 | #ifdef COFF_LONG_SECTION_NAMES | |
2170 | unsigned long string_size = 4; | |
2171 | #endif | |
2172 | ||
2173 | bfd_seek (abfd, 0, 0); | |
2174 | ||
2175 | #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER | |
2176 | H_SET_MAGIC_NUMBER (h, COFF_MAGIC); | |
2177 | H_SET_VERSION_STAMP (h, 0); | |
2178 | H_SET_ENTRY_POINT (h, 0); | |
2179 | H_SET_TEXT_START (h, segment_info[SEG_E0].frchainP->frch_root->fr_address); | |
2180 | H_SET_DATA_START (h, segment_info[SEG_E1].frchainP->frch_root->fr_address); | |
2181 | H_SET_SIZEOF_OPTIONAL_HEADER (h, bfd_coff_swap_aouthdr_out(abfd, &h->aouthdr, | |
2182 | buffero)); | |
2183 | #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */ | |
2184 | H_SET_SIZEOF_OPTIONAL_HEADER (h, 0); | |
2185 | #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */ | |
2186 | ||
2187 | i = bfd_coff_swap_filehdr_out (abfd, &h->filehdr, buffer); | |
2188 | ||
2189 | bfd_write (buffer, i, 1, abfd); | |
2190 | bfd_write (buffero, H_GET_SIZEOF_OPTIONAL_HEADER (h), 1, abfd); | |
2191 | ||
2192 | for (i = SEG_E0; i < SEG_LAST; i++) | |
2193 | { | |
2194 | if (segment_info[i].scnhdr.s_name[0]) | |
2195 | { | |
2196 | unsigned int size; | |
2197 | ||
2198 | #ifdef COFF_LONG_SECTION_NAMES | |
2199 | /* Support long section names as found in PE. This code | |
2200 | must coordinate with that in write_object_file and | |
2201 | w_strings. */ | |
2202 | if (strlen (segment_info[i].name) > SCNNMLEN) | |
2203 | { | |
2204 | memset (segment_info[i].scnhdr.s_name, 0, SCNNMLEN); | |
2205 | sprintf (segment_info[i].scnhdr.s_name, "/%lu", string_size); | |
2206 | string_size += strlen (segment_info[i].name) + 1; | |
2207 | } | |
2208 | #endif | |
2209 | ||
2210 | size = bfd_coff_swap_scnhdr_out (abfd, | |
2211 | &(segment_info[i].scnhdr), | |
2212 | buffer); | |
2213 | if (size == 0) | |
2214 | as_bad (_("bfd_coff_swap_scnhdr_out failed")); | |
2215 | bfd_write (buffer, size, 1, abfd); | |
2216 | } | |
2217 | } | |
2218 | } | |
2219 | ||
2220 | ||
2221 | char * | |
2222 | symbol_to_chars (abfd, where, symbolP) | |
2223 | bfd * abfd; | |
2224 | char *where; | |
2225 | symbolS * symbolP; | |
2226 | { | |
2227 | unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux; | |
2228 | unsigned int i; | |
2229 | valueT val; | |
2230 | ||
2231 | /* Turn any symbols with register attributes into abs symbols */ | |
2232 | if (S_GET_SEGMENT (symbolP) == reg_section) | |
2233 | { | |
2234 | S_SET_SEGMENT (symbolP, absolute_section); | |
2235 | } | |
2236 | /* At the same time, relocate all symbols to their output value */ | |
2237 | ||
2238 | #ifndef TE_PE | |
2239 | val = (segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_paddr | |
2240 | + S_GET_VALUE (symbolP)); | |
2241 | #else | |
2242 | val = S_GET_VALUE (symbolP); | |
2243 | #endif | |
2244 | ||
2245 | S_SET_VALUE (symbolP, val); | |
2246 | ||
2247 | symbolP->sy_symbol.ost_entry.n_value = val; | |
2248 | ||
2249 | where += bfd_coff_swap_sym_out (abfd, &symbolP->sy_symbol.ost_entry, | |
2250 | where); | |
2251 | ||
2252 | for (i = 0; i < numaux; i++) | |
2253 | { | |
2254 | where += bfd_coff_swap_aux_out (abfd, | |
2255 | &symbolP->sy_symbol.ost_auxent[i], | |
2256 | S_GET_DATA_TYPE (symbolP), | |
2257 | S_GET_STORAGE_CLASS (symbolP), | |
2258 | i, numaux, where); | |
2259 | } | |
2260 | return where; | |
2261 | ||
2262 | } | |
2263 | ||
2264 | void | |
2265 | coff_obj_symbol_new_hook (symbolP) | |
2266 | symbolS *symbolP; | |
2267 | { | |
2268 | char underscore = 0; /* Symbol has leading _ */ | |
2269 | ||
2270 | /* Effective symbol */ | |
2271 | /* Store the pointer in the offset. */ | |
2272 | S_SET_ZEROES (symbolP, 0L); | |
2273 | S_SET_DATA_TYPE (symbolP, T_NULL); | |
2274 | S_SET_STORAGE_CLASS (symbolP, 0); | |
2275 | S_SET_NUMBER_AUXILIARY (symbolP, 0); | |
2276 | /* Additional information */ | |
2277 | symbolP->sy_symbol.ost_flags = 0; | |
2278 | /* Auxiliary entries */ | |
2279 | memset ((char *) &symbolP->sy_symbol.ost_auxent[0], 0, AUXESZ); | |
2280 | ||
2281 | if (S_IS_STRING (symbolP)) | |
2282 | SF_SET_STRING (symbolP); | |
2283 | if (!underscore && S_IS_LOCAL (symbolP)) | |
2284 | SF_SET_LOCAL (symbolP); | |
2285 | } | |
2286 | ||
2287 | /* | |
2288 | * Handle .ln directives. | |
2289 | */ | |
2290 | ||
2291 | static void | |
2292 | obj_coff_ln (appline) | |
2293 | int appline; | |
2294 | { | |
2295 | int l; | |
2296 | ||
2297 | if (! appline && def_symbol_in_progress != NULL) | |
2298 | { | |
2299 | as_warn (_(".ln pseudo-op inside .def/.endef: ignored.")); | |
2300 | demand_empty_rest_of_line (); | |
2301 | return; | |
2302 | } /* wrong context */ | |
2303 | ||
2304 | l = get_absolute_expression (); | |
2305 | c_line_new (0, frag_now_fix (), l, frag_now); | |
2306 | ||
2307 | if (appline) | |
2308 | new_logical_line ((char *) NULL, l - 1); | |
2309 | ||
2310 | #ifndef NO_LISTING | |
2311 | { | |
2312 | extern int listing; | |
2313 | ||
2314 | if (listing) | |
2315 | { | |
2316 | if (! appline) | |
2317 | l += line_base - 1; | |
2318 | listing_source_line ((unsigned int) l); | |
2319 | } | |
2320 | ||
2321 | } | |
2322 | #endif | |
2323 | demand_empty_rest_of_line (); | |
2324 | } | |
2325 | ||
2326 | /* | |
2327 | * def() | |
2328 | * | |
2329 | * Handle .def directives. | |
2330 | * | |
2331 | * One might ask : why can't we symbol_new if the symbol does not | |
2332 | * already exist and fill it with debug information. Because of | |
2333 | * the C_EFCN special symbol. It would clobber the value of the | |
2334 | * function symbol before we have a chance to notice that it is | |
2335 | * a C_EFCN. And a second reason is that the code is more clear this | |
2336 | * way. (at least I think it is :-). | |
2337 | * | |
2338 | */ | |
2339 | ||
2340 | #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';') | |
2341 | #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \ | |
2342 | *input_line_pointer == '\t') \ | |
2343 | input_line_pointer++; | |
2344 | ||
2345 | static void | |
2346 | obj_coff_def (what) | |
a04b544b | 2347 | int what ATTRIBUTE_UNUSED; |
252b5132 RH |
2348 | { |
2349 | char name_end; /* Char after the end of name */ | |
2350 | char *symbol_name; /* Name of the debug symbol */ | |
2351 | char *symbol_name_copy; /* Temporary copy of the name */ | |
2352 | unsigned int symbol_name_length; | |
2353 | ||
2354 | if (def_symbol_in_progress != NULL) | |
2355 | { | |
2356 | as_warn (_(".def pseudo-op used inside of .def/.endef: ignored.")); | |
2357 | demand_empty_rest_of_line (); | |
2358 | return; | |
2359 | } /* if not inside .def/.endef */ | |
2360 | ||
2361 | SKIP_WHITESPACES (); | |
2362 | ||
2363 | def_symbol_in_progress = (symbolS *) obstack_alloc (¬es, sizeof (*def_symbol_in_progress)); | |
2364 | memset (def_symbol_in_progress, 0, sizeof (*def_symbol_in_progress)); | |
2365 | ||
2366 | symbol_name = input_line_pointer; | |
2367 | name_end = get_symbol_end (); | |
2368 | symbol_name_length = strlen (symbol_name); | |
2369 | symbol_name_copy = xmalloc (symbol_name_length + 1); | |
2370 | strcpy (symbol_name_copy, symbol_name); | |
2371 | #ifdef tc_canonicalize_symbol_name | |
2372 | symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy); | |
2373 | #endif | |
2374 | ||
2375 | /* Initialize the new symbol */ | |
2376 | #ifdef STRIP_UNDERSCORE | |
2377 | S_SET_NAME (def_symbol_in_progress, (*symbol_name_copy == '_' | |
2378 | ? symbol_name_copy + 1 | |
2379 | : symbol_name_copy)); | |
2380 | #else /* STRIP_UNDERSCORE */ | |
2381 | S_SET_NAME (def_symbol_in_progress, symbol_name_copy); | |
2382 | #endif /* STRIP_UNDERSCORE */ | |
2383 | /* free(symbol_name_copy); */ | |
2384 | def_symbol_in_progress->sy_name_offset = (unsigned long) ~0; | |
2385 | def_symbol_in_progress->sy_number = ~0; | |
2386 | def_symbol_in_progress->sy_frag = &zero_address_frag; | |
2387 | S_SET_VALUE (def_symbol_in_progress, 0); | |
2388 | ||
2389 | if (S_IS_STRING (def_symbol_in_progress)) | |
2390 | SF_SET_STRING (def_symbol_in_progress); | |
2391 | ||
2392 | *input_line_pointer = name_end; | |
2393 | ||
2394 | demand_empty_rest_of_line (); | |
2395 | } | |
2396 | ||
2397 | unsigned int dim_index; | |
2398 | ||
2399 | ||
2400 | static void | |
2401 | obj_coff_endef (ignore) | |
a04b544b | 2402 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2403 | { |
2404 | symbolS *symbolP = 0; | |
2405 | /* DIM BUG FIX sac@cygnus.com */ | |
2406 | dim_index = 0; | |
2407 | if (def_symbol_in_progress == NULL) | |
2408 | { | |
2409 | as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored.")); | |
2410 | demand_empty_rest_of_line (); | |
2411 | return; | |
2412 | } /* if not inside .def/.endef */ | |
2413 | ||
2414 | /* Set the section number according to storage class. */ | |
2415 | switch (S_GET_STORAGE_CLASS (def_symbol_in_progress)) | |
2416 | { | |
2417 | case C_STRTAG: | |
2418 | case C_ENTAG: | |
2419 | case C_UNTAG: | |
2420 | SF_SET_TAG (def_symbol_in_progress); | |
2421 | /* intentional fallthrough */ | |
2422 | case C_FILE: | |
2423 | case C_TPDEF: | |
2424 | SF_SET_DEBUG (def_symbol_in_progress); | |
2425 | S_SET_SEGMENT (def_symbol_in_progress, SEG_DEBUG); | |
2426 | break; | |
2427 | ||
2428 | case C_EFCN: | |
2429 | SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */ | |
2430 | /* intentional fallthrough */ | |
2431 | case C_BLOCK: | |
2432 | SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */ | |
2433 | /* intentional fallthrough */ | |
2434 | case C_FCN: | |
2435 | S_SET_SEGMENT (def_symbol_in_progress, SEG_E0); | |
2436 | ||
2437 | if (strcmp (S_GET_NAME (def_symbol_in_progress), ".bf") == 0) | |
2438 | { /* .bf */ | |
2439 | if (function_lineoff < 0) | |
2440 | { | |
2441 | fprintf (stderr, _("`.bf' symbol without preceding function\n")); | |
2442 | } /* missing function symbol */ | |
2443 | SA_GET_SYM_LNNOPTR (last_line_symbol) = function_lineoff; | |
2444 | ||
2445 | SF_SET_PROCESS (last_line_symbol); | |
2446 | SF_SET_ADJ_LNNOPTR (last_line_symbol); | |
2447 | SF_SET_PROCESS (def_symbol_in_progress); | |
2448 | function_lineoff = -1; | |
2449 | } | |
2450 | /* Value is always set to . */ | |
2451 | def_symbol_in_progress->sy_frag = frag_now; | |
2452 | S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ()); | |
2453 | break; | |
2454 | ||
2455 | #ifdef C_AUTOARG | |
2456 | case C_AUTOARG: | |
2457 | #endif /* C_AUTOARG */ | |
2458 | case C_AUTO: | |
2459 | case C_REG: | |
2460 | case C_MOS: | |
2461 | case C_MOE: | |
2462 | case C_MOU: | |
2463 | case C_ARG: | |
2464 | case C_REGPARM: | |
2465 | case C_FIELD: | |
2466 | case C_EOS: | |
2467 | SF_SET_DEBUG (def_symbol_in_progress); | |
2468 | S_SET_SEGMENT (def_symbol_in_progress, absolute_section); | |
2469 | break; | |
2470 | ||
2471 | case C_EXT: | |
2472 | case C_WEAKEXT: | |
2473 | #ifdef TE_PE | |
2474 | case C_NT_WEAK: | |
2475 | #endif | |
2476 | case C_STAT: | |
2477 | case C_LABEL: | |
2478 | /* Valid but set somewhere else (s_comm, s_lcomm, colon) */ | |
2479 | break; | |
2480 | ||
2481 | case C_USTATIC: | |
2482 | case C_EXTDEF: | |
2483 | case C_ULABEL: | |
2484 | as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress)); | |
2485 | break; | |
2486 | } /* switch on storage class */ | |
2487 | ||
2488 | /* Now that we have built a debug symbol, try to find if we should | |
2489 | merge with an existing symbol or not. If a symbol is C_EFCN or | |
2490 | absolute_section or untagged SEG_DEBUG it never merges. We also | |
2491 | don't merge labels, which are in a different namespace, nor | |
2492 | symbols which have not yet been defined since they are typically | |
2493 | unique, nor do we merge tags with non-tags. */ | |
2494 | ||
2495 | /* Two cases for functions. Either debug followed by definition or | |
2496 | definition followed by debug. For definition first, we will | |
2497 | merge the debug symbol into the definition. For debug first, the | |
2498 | lineno entry MUST point to the definition function or else it | |
2499 | will point off into space when crawl_symbols() merges the debug | |
2500 | symbol into the real symbol. Therefor, let's presume the debug | |
2501 | symbol is a real function reference. */ | |
2502 | ||
2503 | /* FIXME-SOON If for some reason the definition label/symbol is | |
2504 | never seen, this will probably leave an undefined symbol at link | |
2505 | time. */ | |
2506 | ||
2507 | if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN | |
2508 | || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL | |
2509 | || (S_GET_SEGMENT (def_symbol_in_progress) == SEG_DEBUG | |
2510 | && !SF_GET_TAG (def_symbol_in_progress)) | |
2511 | || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section | |
2512 | || def_symbol_in_progress->sy_value.X_op != O_constant | |
2513 | || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL | |
2514 | || (SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP))) | |
2515 | { | |
2516 | symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, | |
2517 | &symbol_lastP); | |
2518 | } | |
2519 | else | |
2520 | { | |
2521 | /* This symbol already exists, merge the newly created symbol | |
2522 | into the old one. This is not mandatory. The linker can | |
2523 | handle duplicate symbols correctly. But I guess that it save | |
2524 | a *lot* of space if the assembly file defines a lot of | |
2525 | symbols. [loic] */ | |
2526 | ||
2527 | /* The debug entry (def_symbol_in_progress) is merged into the | |
2528 | previous definition. */ | |
2529 | ||
2530 | c_symbol_merge (def_symbol_in_progress, symbolP); | |
2531 | /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */ | |
2532 | def_symbol_in_progress = symbolP; | |
2533 | ||
2534 | if (SF_GET_FUNCTION (def_symbol_in_progress) | |
2535 | || SF_GET_TAG (def_symbol_in_progress) | |
2536 | || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT) | |
2537 | { | |
2538 | /* For functions, and tags, and static symbols, the symbol | |
2539 | *must* be where the debug symbol appears. Move the | |
2540 | existing symbol to the current place. */ | |
2541 | /* If it already is at the end of the symbol list, do nothing */ | |
2542 | if (def_symbol_in_progress != symbol_lastP) | |
2543 | { | |
2544 | symbol_remove (def_symbol_in_progress, &symbol_rootP, | |
2545 | &symbol_lastP); | |
2546 | symbol_append (def_symbol_in_progress, symbol_lastP, | |
2547 | &symbol_rootP, &symbol_lastP); | |
2548 | } /* if not already in place */ | |
2549 | } /* if function */ | |
2550 | } /* normal or mergable */ | |
2551 | ||
2552 | if (SF_GET_TAG (def_symbol_in_progress)) | |
2553 | { | |
2554 | symbolS *oldtag; | |
2555 | ||
2556 | oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress), | |
2557 | DO_NOT_STRIP); | |
2558 | if (oldtag == NULL || ! SF_GET_TAG (oldtag)) | |
2559 | tag_insert (S_GET_NAME (def_symbol_in_progress), | |
2560 | def_symbol_in_progress); | |
2561 | } | |
2562 | ||
2563 | if (SF_GET_FUNCTION (def_symbol_in_progress)) | |
2564 | { | |
2565 | know (sizeof (def_symbol_in_progress) <= sizeof (long)); | |
2566 | function_lineoff | |
2567 | = c_line_new (def_symbol_in_progress, 0, 0, &zero_address_frag); | |
2568 | ||
2569 | SF_SET_PROCESS (def_symbol_in_progress); | |
2570 | ||
2571 | if (symbolP == NULL) | |
2572 | { | |
2573 | /* That is, if this is the first time we've seen the | |
2574 | function... */ | |
2575 | symbol_table_insert (def_symbol_in_progress); | |
2576 | } /* definition follows debug */ | |
2577 | } /* Create the line number entry pointing to the function being defined */ | |
2578 | ||
2579 | def_symbol_in_progress = NULL; | |
2580 | demand_empty_rest_of_line (); | |
2581 | } | |
2582 | ||
2583 | static void | |
2584 | obj_coff_dim (ignore) | |
a04b544b | 2585 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2586 | { |
2587 | int dim_index; | |
2588 | ||
2589 | if (def_symbol_in_progress == NULL) | |
2590 | { | |
2591 | as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored.")); | |
2592 | demand_empty_rest_of_line (); | |
2593 | return; | |
2594 | } /* if not inside .def/.endef */ | |
2595 | ||
2596 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
2597 | ||
2598 | for (dim_index = 0; dim_index < DIMNUM; dim_index++) | |
2599 | { | |
2600 | SKIP_WHITESPACES (); | |
2601 | SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index, | |
2602 | get_absolute_expression ()); | |
2603 | ||
2604 | switch (*input_line_pointer) | |
2605 | { | |
2606 | case ',': | |
2607 | input_line_pointer++; | |
2608 | break; | |
2609 | ||
2610 | default: | |
2611 | as_warn (_("badly formed .dim directive ignored")); | |
2612 | /* intentional fallthrough */ | |
2613 | case '\n': | |
2614 | case ';': | |
2615 | dim_index = DIMNUM; | |
2616 | break; | |
2617 | } | |
2618 | } | |
2619 | ||
2620 | demand_empty_rest_of_line (); | |
2621 | } | |
2622 | ||
2623 | static void | |
2624 | obj_coff_line (ignore) | |
a04b544b | 2625 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2626 | { |
2627 | int this_base; | |
2628 | const char *name; | |
2629 | ||
2630 | if (def_symbol_in_progress == NULL) | |
2631 | { | |
2632 | obj_coff_ln (0); | |
2633 | return; | |
2634 | } | |
2635 | ||
2636 | name = S_GET_NAME (def_symbol_in_progress); | |
2637 | this_base = get_absolute_expression (); | |
2638 | ||
2639 | /* Only .bf symbols indicate the use of a new base line number; the | |
2640 | line numbers associated with .ef, .bb, .eb are relative to the | |
2641 | start of the containing function. */ | |
2642 | if (!strcmp (".bf", name)) | |
2643 | { | |
2644 | #if 0 /* XXX Can we ever have line numbers going backwards? */ | |
2645 | if (this_base > line_base) | |
2646 | #endif | |
2647 | { | |
2648 | line_base = this_base; | |
2649 | } | |
2650 | ||
2651 | #ifndef NO_LISTING | |
2652 | { | |
2653 | extern int listing; | |
2654 | if (listing) | |
2655 | { | |
2656 | listing_source_line ((unsigned int) line_base); | |
2657 | } | |
2658 | } | |
2659 | #endif | |
2660 | } | |
2661 | ||
2662 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
2663 | SA_SET_SYM_LNNO (def_symbol_in_progress, this_base); | |
2664 | ||
2665 | demand_empty_rest_of_line (); | |
2666 | } | |
2667 | ||
2668 | static void | |
2669 | obj_coff_size (ignore) | |
a04b544b | 2670 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2671 | { |
2672 | if (def_symbol_in_progress == NULL) | |
2673 | { | |
2674 | as_warn (_(".size pseudo-op used outside of .def/.endef ignored.")); | |
2675 | demand_empty_rest_of_line (); | |
2676 | return; | |
2677 | } /* if not inside .def/.endef */ | |
2678 | ||
2679 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
2680 | SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ()); | |
2681 | demand_empty_rest_of_line (); | |
2682 | } | |
2683 | ||
2684 | static void | |
2685 | obj_coff_scl (ignore) | |
a04b544b | 2686 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2687 | { |
2688 | if (def_symbol_in_progress == NULL) | |
2689 | { | |
2690 | as_warn (_(".scl pseudo-op used outside of .def/.endef ignored.")); | |
2691 | demand_empty_rest_of_line (); | |
2692 | return; | |
2693 | } /* if not inside .def/.endef */ | |
2694 | ||
2695 | S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ()); | |
2696 | demand_empty_rest_of_line (); | |
2697 | } | |
2698 | ||
2699 | static void | |
2700 | obj_coff_tag (ignore) | |
a04b544b | 2701 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2702 | { |
2703 | char *symbol_name; | |
2704 | char name_end; | |
2705 | ||
2706 | if (def_symbol_in_progress == NULL) | |
2707 | { | |
2708 | as_warn (_(".tag pseudo-op used outside of .def/.endef ignored.")); | |
2709 | demand_empty_rest_of_line (); | |
2710 | return; | |
2711 | } | |
2712 | ||
2713 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
2714 | symbol_name = input_line_pointer; | |
2715 | name_end = get_symbol_end (); | |
2716 | #ifdef tc_canonicalize_symbol_name | |
2717 | symbol_name = tc_canonicalize_symbol_name (symbol_name); | |
2718 | #endif | |
2719 | ||
2720 | /* Assume that the symbol referred to by .tag is always defined. | |
2721 | This was a bad assumption. I've added find_or_make. xoxorich. */ | |
2722 | SA_SET_SYM_TAGNDX (def_symbol_in_progress, | |
2723 | (long) tag_find_or_make (symbol_name)); | |
2724 | if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L) | |
2725 | { | |
2726 | as_warn (_("tag not found for .tag %s"), symbol_name); | |
2727 | } /* not defined */ | |
2728 | ||
2729 | SF_SET_TAGGED (def_symbol_in_progress); | |
2730 | *input_line_pointer = name_end; | |
2731 | ||
2732 | demand_empty_rest_of_line (); | |
2733 | } | |
2734 | ||
2735 | static void | |
2736 | obj_coff_type (ignore) | |
a04b544b | 2737 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2738 | { |
2739 | if (def_symbol_in_progress == NULL) | |
2740 | { | |
2741 | as_warn (_(".type pseudo-op used outside of .def/.endef ignored.")); | |
2742 | demand_empty_rest_of_line (); | |
2743 | return; | |
2744 | } /* if not inside .def/.endef */ | |
2745 | ||
2746 | S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ()); | |
2747 | ||
2748 | if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) && | |
2749 | S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF) | |
2750 | { | |
2751 | SF_SET_FUNCTION (def_symbol_in_progress); | |
2752 | } /* is a function */ | |
2753 | ||
2754 | demand_empty_rest_of_line (); | |
2755 | } | |
2756 | ||
2757 | static void | |
2758 | obj_coff_val (ignore) | |
a04b544b | 2759 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2760 | { |
2761 | if (def_symbol_in_progress == NULL) | |
2762 | { | |
2763 | as_warn (_(".val pseudo-op used outside of .def/.endef ignored.")); | |
2764 | demand_empty_rest_of_line (); | |
2765 | return; | |
2766 | } /* if not inside .def/.endef */ | |
2767 | ||
2768 | if (is_name_beginner (*input_line_pointer)) | |
2769 | { | |
2770 | char *symbol_name = input_line_pointer; | |
2771 | char name_end = get_symbol_end (); | |
2772 | ||
2773 | #ifdef tc_canonicalize_symbol_name | |
2774 | symbol_name = tc_canonicalize_symbol_name (symbol_name); | |
2775 | #endif | |
2776 | ||
2777 | if (!strcmp (symbol_name, ".")) | |
2778 | { | |
2779 | def_symbol_in_progress->sy_frag = frag_now; | |
2780 | S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ()); | |
2781 | /* If the .val is != from the .def (e.g. statics) */ | |
2782 | } | |
2783 | else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name)) | |
2784 | { | |
2785 | def_symbol_in_progress->sy_value.X_op = O_symbol; | |
2786 | def_symbol_in_progress->sy_value.X_add_symbol = | |
2787 | symbol_find_or_make (symbol_name); | |
2788 | def_symbol_in_progress->sy_value.X_op_symbol = NULL; | |
2789 | def_symbol_in_progress->sy_value.X_add_number = 0; | |
2790 | ||
2791 | /* If the segment is undefined when the forward reference is | |
2792 | resolved, then copy the segment id from the forward | |
2793 | symbol. */ | |
2794 | SF_SET_GET_SEGMENT (def_symbol_in_progress); | |
2795 | ||
0561a208 ILT |
2796 | /* FIXME: gcc can generate address expressions here in |
2797 | unusual cases (search for "obscure" in sdbout.c). We | |
2798 | just ignore the offset here, thus generating incorrect | |
2799 | debugging information. We ignore the rest of the line | |
2800 | just below. */ | |
252b5132 RH |
2801 | } |
2802 | /* Otherwise, it is the name of a non debug symbol and | |
2803 | its value will be calculated later. */ | |
2804 | *input_line_pointer = name_end; | |
2805 | ||
2806 | /* FIXME: this is to avoid an error message in the | |
2807 | FIXME case mentioned just above. */ | |
2808 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
2809 | ++input_line_pointer; | |
2810 | } | |
2811 | else | |
2812 | { | |
2813 | S_SET_VALUE (def_symbol_in_progress, | |
2814 | (valueT) get_absolute_expression ()); | |
2815 | } /* if symbol based */ | |
2816 | ||
2817 | demand_empty_rest_of_line (); | |
2818 | } | |
2819 | ||
2820 | #ifdef TE_PE | |
2821 | ||
2822 | /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in | |
2823 | read.c, which then calls this object file format specific routine. */ | |
2824 | ||
2825 | void | |
2826 | obj_coff_pe_handle_link_once (type) | |
2827 | enum linkonce_type type; | |
2828 | { | |
2829 | seg_info (now_seg)->scnhdr.s_flags |= IMAGE_SCN_LNK_COMDAT; | |
2830 | ||
2831 | /* We store the type in the seg_info structure, and use it to set up | |
2832 | the auxiliary entry for the section symbol in c_section_symbol. */ | |
2833 | seg_info (now_seg)->linkonce = type; | |
2834 | } | |
2835 | ||
2836 | #endif /* TE_PE */ | |
2837 | ||
2838 | void | |
2839 | coff_obj_read_begin_hook () | |
2840 | { | |
2841 | /* These had better be the same. Usually 18 bytes. */ | |
2842 | #ifndef BFD_HEADERS | |
2843 | know (sizeof (SYMENT) == sizeof (AUXENT)); | |
2844 | know (SYMESZ == AUXESZ); | |
2845 | #endif | |
2846 | tag_init (); | |
2847 | } | |
2848 | ||
2849 | /* This function runs through the symbol table and puts all the | |
2850 | externals onto another chain */ | |
2851 | ||
2852 | /* The chain of globals. */ | |
2853 | symbolS *symbol_globalP; | |
2854 | symbolS *symbol_global_lastP; | |
2855 | ||
2856 | /* The chain of externals */ | |
2857 | symbolS *symbol_externP; | |
2858 | symbolS *symbol_extern_lastP; | |
2859 | ||
2860 | stack *block_stack; | |
2861 | symbolS *last_functionP; | |
2862 | static symbolS *last_bfP; | |
2863 | symbolS *last_tagP; | |
2864 | ||
2865 | static unsigned int | |
2866 | yank_symbols () | |
2867 | { | |
2868 | symbolS *symbolP; | |
2869 | unsigned int symbol_number = 0; | |
2870 | unsigned int last_file_symno = 0; | |
2871 | ||
2872 | struct filename_list *filename_list_scan = filename_list_head; | |
2873 | ||
2874 | for (symbolP = symbol_rootP; | |
2875 | symbolP; | |
2876 | symbolP = symbolP ? symbol_next (symbolP) : symbol_rootP) | |
2877 | { | |
2878 | if (symbolP->sy_mri_common) | |
2879 | { | |
2880 | if (S_GET_STORAGE_CLASS (symbolP) == C_EXT | |
2881 | #ifdef TE_PE | |
2882 | || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK | |
2883 | #endif | |
2884 | || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT) | |
2885 | as_bad (_("%s: global symbols not supported in common sections"), | |
2886 | S_GET_NAME (symbolP)); | |
2887 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
2888 | continue; | |
2889 | } | |
2890 | ||
2891 | if (!SF_GET_DEBUG (symbolP)) | |
2892 | { | |
2893 | /* Debug symbols do not need all this rubbish */ | |
2894 | symbolS *real_symbolP; | |
2895 | ||
2896 | /* L* and C_EFCN symbols never merge. */ | |
2897 | if (!SF_GET_LOCAL (symbolP) | |
2898 | && !SF_GET_STATICS (symbolP) | |
2899 | && S_GET_STORAGE_CLASS (symbolP) != C_LABEL | |
2900 | && symbolP->sy_value.X_op == O_constant | |
2901 | && (real_symbolP = symbol_find_base (S_GET_NAME (symbolP), DO_NOT_STRIP)) | |
2902 | && real_symbolP != symbolP) | |
2903 | { | |
2904 | /* FIXME-SOON: where do dups come from? | |
2905 | Maybe tag references before definitions? xoxorich. */ | |
2906 | /* Move the debug data from the debug symbol to the | |
2907 | real symbol. Do NOT do the oposite (i.e. move from | |
2908 | real symbol to debug symbol and remove real symbol from the | |
2909 | list.) Because some pointers refer to the real symbol | |
2910 | whereas no pointers refer to the debug symbol. */ | |
2911 | c_symbol_merge (symbolP, real_symbolP); | |
2912 | /* Replace the current symbol by the real one */ | |
2913 | /* The symbols will never be the last or the first | |
2914 | because : 1st symbol is .file and 3 last symbols are | |
2915 | .text, .data, .bss */ | |
2916 | symbol_remove (real_symbolP, &symbol_rootP, &symbol_lastP); | |
2917 | symbol_insert (real_symbolP, symbolP, &symbol_rootP, &symbol_lastP); | |
2918 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
2919 | symbolP = real_symbolP; | |
2920 | } /* if not local but dup'd */ | |
2921 | ||
2922 | if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_E1)) | |
2923 | { | |
2924 | S_SET_SEGMENT (symbolP, SEG_E0); | |
2925 | } /* push data into text */ | |
2926 | ||
2927 | resolve_symbol_value (symbolP, 1); | |
2928 | ||
2929 | if (S_GET_STORAGE_CLASS (symbolP) == C_NULL) | |
2930 | { | |
2931 | if (!S_IS_DEFINED (symbolP) && !SF_GET_LOCAL (symbolP)) | |
2932 | { | |
2933 | S_SET_EXTERNAL (symbolP); | |
2934 | } | |
2935 | else if (S_GET_SEGMENT (symbolP) == SEG_E0) | |
2936 | { | |
2937 | S_SET_STORAGE_CLASS (symbolP, C_LABEL); | |
2938 | } | |
2939 | else | |
2940 | { | |
2941 | S_SET_STORAGE_CLASS (symbolP, C_STAT); | |
2942 | } | |
2943 | } | |
2944 | ||
2945 | /* Mainly to speed up if not -g */ | |
2946 | if (SF_GET_PROCESS (symbolP)) | |
2947 | { | |
2948 | /* Handle the nested blocks auxiliary info. */ | |
2949 | if (S_GET_STORAGE_CLASS (symbolP) == C_BLOCK) | |
2950 | { | |
2951 | if (!strcmp (S_GET_NAME (symbolP), ".bb")) | |
2952 | stack_push (block_stack, (char *) &symbolP); | |
2953 | else | |
2954 | { /* .eb */ | |
2955 | register symbolS *begin_symbolP; | |
2956 | begin_symbolP = *(symbolS **) stack_pop (block_stack); | |
2957 | if (begin_symbolP == (symbolS *) 0) | |
2958 | as_warn (_("mismatched .eb")); | |
2959 | else | |
2960 | SA_SET_SYM_ENDNDX (begin_symbolP, symbol_number + 2); | |
2961 | } | |
2962 | } | |
2963 | /* If we are able to identify the type of a function, and we | |
2964 | are out of a function (last_functionP == 0) then, the | |
2965 | function symbol will be associated with an auxiliary | |
2966 | entry. */ | |
2967 | if (last_functionP == (symbolS *) 0 && | |
2968 | SF_GET_FUNCTION (symbolP)) | |
2969 | { | |
2970 | last_functionP = symbolP; | |
2971 | ||
2972 | if (S_GET_NUMBER_AUXILIARY (symbolP) < 1) | |
2973 | { | |
2974 | S_SET_NUMBER_AUXILIARY (symbolP, 1); | |
2975 | } /* make it at least 1 */ | |
2976 | ||
2977 | /* Clobber possible stale .dim information. */ | |
2978 | #if 0 | |
2979 | /* Iffed out by steve - this fries the lnnoptr info too */ | |
2980 | bzero (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen, | |
2981 | sizeof (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen)); | |
2982 | #endif | |
2983 | } | |
2984 | if (S_GET_STORAGE_CLASS (symbolP) == C_FCN) | |
2985 | { | |
2986 | if (strcmp (S_GET_NAME (symbolP), ".bf") == 0) | |
2987 | { | |
2988 | if (last_bfP != NULL) | |
2989 | SA_SET_SYM_ENDNDX (last_bfP, symbol_number); | |
2990 | last_bfP = symbolP; | |
2991 | } | |
2992 | } | |
2993 | else if (S_GET_STORAGE_CLASS (symbolP) == C_EFCN) | |
2994 | { | |
2995 | /* I don't even know if this is needed for sdb. But | |
2996 | the standard assembler generates it, so... */ | |
2997 | if (last_functionP == (symbolS *) 0) | |
2998 | as_fatal (_("C_EFCN symbol out of scope")); | |
2999 | SA_SET_SYM_FSIZE (last_functionP, | |
3000 | (long) (S_GET_VALUE (symbolP) - | |
3001 | S_GET_VALUE (last_functionP))); | |
3002 | SA_SET_SYM_ENDNDX (last_functionP, symbol_number); | |
3003 | last_functionP = (symbolS *) 0; | |
3004 | } | |
3005 | } | |
3006 | } | |
3007 | else if (SF_GET_TAG (symbolP)) | |
3008 | { | |
3009 | /* First descriptor of a structure must point to | |
3010 | the first slot after the structure description. */ | |
3011 | last_tagP = symbolP; | |
3012 | ||
3013 | } | |
3014 | else if (S_GET_STORAGE_CLASS (symbolP) == C_EOS) | |
3015 | { | |
3016 | /* +2 take in account the current symbol */ | |
3017 | SA_SET_SYM_ENDNDX (last_tagP, symbol_number + 2); | |
3018 | } | |
3019 | else if (S_GET_STORAGE_CLASS (symbolP) == C_FILE) | |
3020 | { | |
3021 | /* If the filename was too long to fit in the | |
3022 | auxent, put it in the string table */ | |
3023 | if (SA_GET_FILE_FNAME_ZEROS (symbolP) == 0 | |
3024 | && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0) | |
3025 | { | |
3026 | SA_SET_FILE_FNAME_OFFSET (symbolP, string_byte_count); | |
3027 | string_byte_count += strlen (filename_list_scan->filename) + 1; | |
3028 | filename_list_scan = filename_list_scan->next; | |
3029 | } | |
3030 | if (S_GET_VALUE (symbolP)) | |
3031 | { | |
3032 | S_SET_VALUE (symbolP, last_file_symno); | |
3033 | last_file_symno = symbol_number; | |
3034 | } /* no one points at the first .file symbol */ | |
3035 | } /* if debug or tag or eos or file */ | |
3036 | ||
3037 | #ifdef tc_frob_coff_symbol | |
3038 | tc_frob_coff_symbol (symbolP); | |
3039 | #endif | |
3040 | ||
3041 | /* We must put the external symbols apart. The loader | |
3042 | does not bomb if we do not. But the references in | |
3043 | the endndx field for a .bb symbol are not corrected | |
3044 | if an external symbol is removed between .bb and .be. | |
3045 | I.e in the following case : | |
3046 | [20] .bb endndx = 22 | |
3047 | [21] foo external | |
3048 | [22] .be | |
3049 | ld will move the symbol 21 to the end of the list but | |
3050 | endndx will still be 22 instead of 21. */ | |
3051 | ||
3052 | ||
3053 | if (SF_GET_LOCAL (symbolP)) | |
3054 | { | |
3055 | /* remove C_EFCN and LOCAL (L...) symbols */ | |
3056 | /* next pointer remains valid */ | |
3057 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
3058 | ||
3059 | } | |
3060 | else if (symbolP->sy_value.X_op == O_symbol | |
3061 | && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))) | |
3062 | { | |
3063 | /* Skip symbols which were equated to undefined or common | |
3064 | symbols. */ | |
3065 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
3066 | } | |
3067 | else if (!S_IS_DEFINED (symbolP) | |
3068 | && !S_IS_DEBUG (symbolP) | |
3069 | && !SF_GET_STATICS (symbolP) | |
3070 | && (S_GET_STORAGE_CLASS (symbolP) == C_EXT | |
3071 | #ifdef TE_PE | |
3072 | || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK | |
3073 | #endif | |
3074 | || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT)) | |
3075 | { | |
3076 | /* if external, Remove from the list */ | |
3077 | symbolS *hold = symbol_previous (symbolP); | |
3078 | ||
3079 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
3080 | symbol_clear_list_pointers (symbolP); | |
3081 | symbol_append (symbolP, symbol_extern_lastP, &symbol_externP, &symbol_extern_lastP); | |
3082 | symbolP = hold; | |
3083 | } | |
3084 | else if (! S_IS_DEBUG (symbolP) | |
3085 | && ! SF_GET_STATICS (symbolP) | |
3086 | && ! SF_GET_FUNCTION (symbolP) | |
3087 | && (S_GET_STORAGE_CLASS (symbolP) == C_EXT | |
3088 | #ifdef TE_PE | |
3089 | || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK | |
3090 | #endif | |
3091 | || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK)) | |
3092 | { | |
3093 | symbolS *hold = symbol_previous (symbolP); | |
3094 | ||
3095 | /* The O'Reilly COFF book says that defined global symbols | |
3096 | come at the end of the symbol table, just before | |
3097 | undefined global symbols. */ | |
3098 | ||
3099 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
3100 | symbol_clear_list_pointers (symbolP); | |
3101 | symbol_append (symbolP, symbol_global_lastP, &symbol_globalP, | |
3102 | &symbol_global_lastP); | |
3103 | symbolP = hold; | |
3104 | } | |
3105 | else | |
3106 | { | |
3107 | if (SF_GET_STRING (symbolP)) | |
3108 | { | |
3109 | symbolP->sy_name_offset = string_byte_count; | |
3110 | string_byte_count += strlen (S_GET_NAME (symbolP)) + 1; | |
3111 | } | |
3112 | else | |
3113 | { | |
3114 | symbolP->sy_name_offset = 0; | |
3115 | } /* fix "long" names */ | |
3116 | ||
3117 | symbolP->sy_number = symbol_number; | |
3118 | symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP); | |
3119 | } /* if local symbol */ | |
3120 | } /* traverse the symbol list */ | |
3121 | return symbol_number; | |
3122 | ||
3123 | } | |
3124 | ||
3125 | ||
3126 | static unsigned int | |
3127 | glue_symbols (head, tail) | |
3128 | symbolS **head; | |
3129 | symbolS **tail; | |
3130 | { | |
3131 | unsigned int symbol_number = 0; | |
3132 | ||
3133 | while (*head != NULL) | |
3134 | { | |
3135 | symbolS *tmp = *head; | |
3136 | ||
3137 | /* append */ | |
3138 | symbol_remove (tmp, head, tail); | |
3139 | symbol_append (tmp, symbol_lastP, &symbol_rootP, &symbol_lastP); | |
3140 | ||
3141 | /* and process */ | |
3142 | if (SF_GET_STRING (tmp)) | |
3143 | { | |
3144 | tmp->sy_name_offset = string_byte_count; | |
3145 | string_byte_count += strlen (S_GET_NAME (tmp)) + 1; | |
3146 | } | |
3147 | else | |
3148 | { | |
3149 | tmp->sy_name_offset = 0; | |
3150 | } /* fix "long" names */ | |
3151 | ||
3152 | tmp->sy_number = symbol_number; | |
3153 | symbol_number += 1 + S_GET_NUMBER_AUXILIARY (tmp); | |
3154 | } /* append the entire extern chain */ | |
3155 | ||
3156 | return symbol_number; | |
3157 | } | |
3158 | ||
3159 | static unsigned int | |
3160 | tie_tags () | |
3161 | { | |
3162 | unsigned int symbol_number = 0; | |
3163 | symbolS *symbolP; | |
3164 | ||
3165 | for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP)) | |
3166 | { | |
3167 | symbolP->sy_number = symbol_number; | |
3168 | ||
3169 | if (SF_GET_TAGGED (symbolP)) | |
3170 | { | |
3171 | SA_SET_SYM_TAGNDX | |
3172 | (symbolP, | |
3173 | ((symbolS *) SA_GET_SYM_TAGNDX (symbolP))->sy_number); | |
3174 | } | |
3175 | ||
3176 | symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP); | |
3177 | } | |
3178 | ||
3179 | return symbol_number; | |
3180 | } | |
3181 | ||
3182 | static void | |
3183 | crawl_symbols (h, abfd) | |
3184 | object_headers *h; | |
a04b544b | 3185 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
3186 | { |
3187 | unsigned int i; | |
3188 | ||
3189 | /* Initialize the stack used to keep track of the matching .bb .be */ | |
3190 | ||
3191 | block_stack = stack_init (512, sizeof (symbolS *)); | |
3192 | ||
3193 | /* The symbol list should be ordered according to the following sequence | |
3194 | * order : | |
3195 | * . .file symbol | |
3196 | * . debug entries for functions | |
3197 | * . fake symbols for the sections, including .text .data and .bss | |
3198 | * . defined symbols | |
3199 | * . undefined symbols | |
3200 | * But this is not mandatory. The only important point is to put the | |
3201 | * undefined symbols at the end of the list. | |
3202 | */ | |
3203 | ||
3204 | /* Is there a .file symbol ? If not insert one at the beginning. */ | |
3205 | if (symbol_rootP == NULL | |
3206 | || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE) | |
3207 | { | |
3208 | c_dot_file_symbol ("fake"); | |
3209 | } | |
3210 | ||
3211 | /* | |
3212 | * Build up static symbols for the sections, they are filled in later | |
3213 | */ | |
3214 | ||
3215 | ||
3216 | for (i = SEG_E0; i < SEG_LAST; i++) | |
3217 | if (segment_info[i].scnhdr.s_name[0]) | |
3218 | segment_info[i].dot = c_section_symbol (segment_info[i].name, | |
3219 | i - SEG_E0 + 1); | |
3220 | ||
3221 | /* Take all the externals out and put them into another chain */ | |
3222 | H_SET_SYMBOL_TABLE_SIZE (h, yank_symbols ()); | |
3223 | /* Take the externals and glue them onto the end.*/ | |
3224 | H_SET_SYMBOL_TABLE_SIZE (h, | |
3225 | (H_GET_SYMBOL_COUNT (h) | |
3226 | + glue_symbols (&symbol_globalP, | |
3227 | &symbol_global_lastP) | |
3228 | + glue_symbols (&symbol_externP, | |
3229 | &symbol_extern_lastP))); | |
3230 | ||
3231 | H_SET_SYMBOL_TABLE_SIZE (h, tie_tags ()); | |
3232 | know (symbol_globalP == NULL); | |
3233 | know (symbol_global_lastP == NULL); | |
3234 | know (symbol_externP == NULL); | |
3235 | know (symbol_extern_lastP == NULL); | |
3236 | } | |
3237 | ||
3238 | /* | |
3239 | * Find strings by crawling along symbol table chain. | |
3240 | */ | |
3241 | ||
3242 | void | |
3243 | w_strings (where) | |
3244 | char *where; | |
3245 | { | |
3246 | symbolS *symbolP; | |
3247 | struct filename_list *filename_list_scan = filename_list_head; | |
3248 | ||
3249 | /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */ | |
3250 | md_number_to_chars (where, (valueT) string_byte_count, 4); | |
3251 | where += 4; | |
3252 | ||
3253 | #ifdef COFF_LONG_SECTION_NAMES | |
3254 | /* Support long section names as found in PE. This code must | |
3255 | coordinate with that in coff_header_append and write_object_file. */ | |
3256 | { | |
3257 | unsigned int i; | |
3258 | ||
3259 | for (i = SEG_E0; i < SEG_LAST; i++) | |
3260 | { | |
3261 | if (segment_info[i].scnhdr.s_name[0] | |
3262 | && strlen (segment_info[i].name) > SCNNMLEN) | |
3263 | { | |
3264 | unsigned int size; | |
3265 | ||
3266 | size = strlen (segment_info[i].name) + 1; | |
3267 | memcpy (where, segment_info[i].name, size); | |
3268 | where += size; | |
3269 | } | |
3270 | } | |
3271 | } | |
3272 | #endif /* COFF_LONG_SECTION_NAMES */ | |
3273 | ||
3274 | for (symbolP = symbol_rootP; | |
3275 | symbolP; | |
3276 | symbolP = symbol_next (symbolP)) | |
3277 | { | |
3278 | unsigned int size; | |
3279 | ||
3280 | if (SF_GET_STRING (symbolP)) | |
3281 | { | |
3282 | size = strlen (S_GET_NAME (symbolP)) + 1; | |
3283 | memcpy (where, S_GET_NAME (symbolP), size); | |
3284 | where += size; | |
3285 | } | |
3286 | if (S_GET_STORAGE_CLASS (symbolP) == C_FILE | |
3287 | && SA_GET_FILE_FNAME_ZEROS (symbolP) == 0 | |
3288 | && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0) | |
3289 | { | |
3290 | size = strlen (filename_list_scan->filename) + 1; | |
3291 | memcpy (where, filename_list_scan->filename, size); | |
3292 | filename_list_scan = filename_list_scan ->next; | |
3293 | where += size; | |
3294 | } | |
3295 | } | |
3296 | } | |
3297 | ||
3298 | static void | |
3299 | do_linenos_for (abfd, h, file_cursor) | |
3300 | bfd * abfd; | |
3301 | object_headers * h; | |
3302 | unsigned long *file_cursor; | |
3303 | { | |
3304 | unsigned int idx; | |
3305 | unsigned long start = *file_cursor; | |
3306 | ||
3307 | for (idx = SEG_E0; idx < SEG_LAST; idx++) | |
3308 | { | |
3309 | segment_info_type *s = segment_info + idx; | |
3310 | ||
3311 | ||
3312 | if (s->scnhdr.s_nlnno != 0) | |
3313 | { | |
3314 | struct lineno_list *line_ptr; | |
3315 | ||
3316 | struct external_lineno *buffer = | |
3317 | (struct external_lineno *) xmalloc (s->scnhdr.s_nlnno * LINESZ); | |
3318 | ||
3319 | struct external_lineno *dst = buffer; | |
3320 | ||
3321 | /* Run through the table we've built and turn it into its external | |
3322 | form, take this chance to remove duplicates */ | |
3323 | ||
3324 | for (line_ptr = s->lineno_list_head; | |
3325 | line_ptr != (struct lineno_list *) NULL; | |
3326 | line_ptr = line_ptr->next) | |
3327 | { | |
3328 | ||
3329 | if (line_ptr->line.l_lnno == 0) | |
3330 | { | |
3331 | /* Turn a pointer to a symbol into the symbols' index */ | |
3332 | line_ptr->line.l_addr.l_symndx = | |
3333 | ((symbolS *) line_ptr->line.l_addr.l_symndx)->sy_number; | |
3334 | } | |
3335 | else | |
3336 | { | |
3337 | line_ptr->line.l_addr.l_paddr += ((struct frag *) (line_ptr->frag))->fr_address; | |
3338 | } | |
3339 | ||
3340 | ||
3341 | (void) bfd_coff_swap_lineno_out (abfd, &(line_ptr->line), dst); | |
3342 | dst++; | |
3343 | ||
3344 | } | |
3345 | ||
3346 | s->scnhdr.s_lnnoptr = *file_cursor; | |
3347 | ||
3348 | bfd_write (buffer, 1, s->scnhdr.s_nlnno * LINESZ, abfd); | |
3349 | free (buffer); | |
3350 | ||
3351 | *file_cursor += s->scnhdr.s_nlnno * LINESZ; | |
3352 | } | |
3353 | } | |
3354 | H_SET_LINENO_SIZE (h, *file_cursor - start); | |
3355 | } | |
3356 | ||
3357 | ||
3358 | /* Now we run through the list of frag chains in a segment and | |
3359 | make all the subsegment frags appear at the end of the | |
3360 | list, as if the seg 0 was extra long */ | |
3361 | ||
3362 | static void | |
3363 | remove_subsegs () | |
3364 | { | |
3365 | unsigned int i; | |
3366 | ||
3367 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
3368 | { | |
3369 | frchainS *head = segment_info[i].frchainP; | |
3370 | fragS dummy; | |
3371 | fragS *prev_frag = &dummy; | |
3372 | ||
3373 | while (head && head->frch_seg == i) | |
3374 | { | |
3375 | prev_frag->fr_next = head->frch_root; | |
3376 | prev_frag = head->frch_last; | |
3377 | head = head->frch_next; | |
3378 | } | |
3379 | prev_frag->fr_next = 0; | |
3380 | } | |
3381 | } | |
3382 | ||
3383 | unsigned long machine; | |
3384 | int coff_flags; | |
3385 | extern void | |
3386 | write_object_file () | |
3387 | { | |
3388 | int i; | |
3389 | const char *name; | |
3390 | struct frchain *frchain_ptr; | |
3391 | ||
3392 | object_headers headers; | |
3393 | unsigned long file_cursor; | |
3394 | bfd *abfd; | |
3395 | unsigned int addr; | |
3396 | abfd = bfd_openw (out_file_name, TARGET_FORMAT); | |
3397 | ||
3398 | ||
3399 | if (abfd == 0) | |
3400 | { | |
3401 | as_perror (_("FATAL: Can't create %s"), out_file_name); | |
3402 | exit (EXIT_FAILURE); | |
3403 | } | |
3404 | bfd_set_format (abfd, bfd_object); | |
3405 | bfd_set_arch_mach (abfd, BFD_ARCH, machine); | |
3406 | ||
3407 | string_byte_count = 4; | |
3408 | ||
3409 | for (frchain_ptr = frchain_root; | |
3410 | frchain_ptr != (struct frchain *) NULL; | |
3411 | frchain_ptr = frchain_ptr->frch_next) | |
3412 | { | |
3413 | /* Run through all the sub-segments and align them up. Also | |
3414 | close any open frags. We tack a .fill onto the end of the | |
3415 | frag chain so that any .align's size can be worked by looking | |
3416 | at the next frag. */ | |
3417 | ||
3418 | subseg_set (frchain_ptr->frch_seg, frchain_ptr->frch_subseg); | |
b9e57a38 | 3419 | |
252b5132 RH |
3420 | #ifndef SUB_SEGMENT_ALIGN |
3421 | #define SUB_SEGMENT_ALIGN(SEG) 1 | |
3422 | #endif | |
3423 | #ifdef md_do_align | |
3424 | md_do_align (SUB_SEGMENT_ALIGN (now_seg), (char *) NULL, 0, 0, | |
3425 | alignment_done); | |
3426 | #endif | |
b9e57a38 ILT |
3427 | frag_align (SUB_SEGMENT_ALIGN (now_seg), |
3428 | subseg_text_p (now_seg) ? NOP_OPCODE : 0, | |
3429 | 0); | |
252b5132 RH |
3430 | #ifdef md_do_align |
3431 | alignment_done: | |
3432 | #endif | |
3433 | frag_wane (frag_now); | |
3434 | frag_now->fr_fix = 0; | |
3435 | know (frag_now->fr_next == NULL); | |
3436 | } | |
3437 | ||
3438 | ||
3439 | remove_subsegs (); | |
3440 | ||
3441 | ||
3442 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
3443 | { | |
3444 | relax_segment (segment_info[i].frchainP->frch_root, i); | |
3445 | } | |
3446 | ||
3447 | H_SET_NUMBER_OF_SECTIONS (&headers, 0); | |
3448 | ||
3449 | /* Find out how big the sections are, and set the addresses. */ | |
3450 | addr = 0; | |
3451 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
3452 | { | |
3453 | long size; | |
3454 | ||
3455 | segment_info[i].scnhdr.s_paddr = addr; | |
3456 | segment_info[i].scnhdr.s_vaddr = addr; | |
3457 | ||
3458 | if (segment_info[i].scnhdr.s_name[0]) | |
3459 | { | |
3460 | H_SET_NUMBER_OF_SECTIONS (&headers, | |
3461 | H_GET_NUMBER_OF_SECTIONS (&headers) + 1); | |
3462 | ||
3463 | #ifdef COFF_LONG_SECTION_NAMES | |
3464 | /* Support long section names as found in PE. This code | |
3465 | must coordinate with that in coff_header_append and | |
3466 | w_strings. */ | |
3467 | { | |
3468 | unsigned int len; | |
3469 | ||
3470 | len = strlen (segment_info[i].name); | |
3471 | if (len > SCNNMLEN) | |
3472 | string_byte_count += len + 1; | |
3473 | } | |
3474 | #endif /* COFF_LONG_SECTION_NAMES */ | |
3475 | } | |
3476 | ||
3477 | size = size_section (abfd, (unsigned int) i); | |
3478 | addr += size; | |
3479 | ||
3480 | /* I think the section alignment is only used on the i960; the | |
3481 | i960 needs it, and it should do no harm on other targets. */ | |
3482 | #ifdef ALIGNMENT_IN_S_FLAGS | |
3483 | segment_info[i].scnhdr.s_flags |= (section_alignment[i] & 0xF) << 8; | |
3484 | #else | |
3485 | segment_info[i].scnhdr.s_align = 1 << section_alignment[i]; | |
3486 | #endif | |
3487 | ||
3488 | if (i == SEG_E0) | |
3489 | H_SET_TEXT_SIZE (&headers, size); | |
3490 | else if (i == SEG_E1) | |
3491 | H_SET_DATA_SIZE (&headers, size); | |
3492 | else if (i == SEG_E2) | |
3493 | H_SET_BSS_SIZE (&headers, size); | |
3494 | } | |
3495 | ||
3496 | /* Turn the gas native symbol table shape into a coff symbol table */ | |
3497 | crawl_symbols (&headers, abfd); | |
3498 | ||
3499 | if (string_byte_count == 4) | |
3500 | string_byte_count = 0; | |
3501 | ||
3502 | H_SET_STRING_SIZE (&headers, string_byte_count); | |
3503 | ||
3504 | #ifdef tc_frob_file | |
3505 | tc_frob_file (); | |
3506 | #endif | |
3507 | ||
3508 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
3509 | { | |
3510 | fixup_mdeps (segment_info[i].frchainP->frch_root, &headers, i); | |
3511 | fixup_segment (&segment_info[i], i); | |
3512 | } | |
3513 | ||
3514 | /* Look for ".stab" segments and fill in their initial symbols | |
3515 | correctly. */ | |
3516 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
3517 | { | |
3518 | name = segment_info[i].name; | |
3519 | ||
3520 | if (name != NULL | |
3521 | && strncmp (".stab", name, 5) == 0 | |
3522 | && strncmp (".stabstr", name, 8) != 0) | |
3523 | adjust_stab_section (abfd, i); | |
3524 | } | |
3525 | ||
3526 | file_cursor = H_GET_TEXT_FILE_OFFSET (&headers); | |
3527 | ||
3528 | bfd_seek (abfd, (file_ptr) file_cursor, 0); | |
3529 | ||
3530 | /* Plant the data */ | |
3531 | ||
3532 | fill_section (abfd, &headers, &file_cursor); | |
3533 | ||
3534 | do_relocs_for (abfd, &headers, &file_cursor); | |
3535 | ||
3536 | do_linenos_for (abfd, &headers, &file_cursor); | |
3537 | ||
3538 | H_SET_FILE_MAGIC_NUMBER (&headers, COFF_MAGIC); | |
3539 | #ifndef OBJ_COFF_OMIT_TIMESTAMP | |
3540 | H_SET_TIME_STAMP (&headers, (long)time((time_t *)0)); | |
3541 | #else | |
3542 | H_SET_TIME_STAMP (&headers, 0); | |
3543 | #endif | |
3544 | #ifdef TC_COFF_SET_MACHINE | |
3545 | TC_COFF_SET_MACHINE (&headers); | |
3546 | #endif | |
3547 | ||
3548 | #ifndef COFF_FLAGS | |
3549 | #define COFF_FLAGS 0 | |
3550 | #endif | |
3551 | ||
3552 | #ifdef KEEP_RELOC_INFO | |
3553 | H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) | | |
3554 | COFF_FLAGS | coff_flags)); | |
3555 | #else | |
3556 | H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) | | |
3557 | (H_GET_RELOCATION_SIZE(&headers) ? 0 : F_RELFLG) | | |
3558 | COFF_FLAGS | coff_flags)); | |
3559 | #endif | |
3560 | ||
3561 | { | |
3562 | unsigned int symtable_size = H_GET_SYMBOL_TABLE_SIZE (&headers); | |
3563 | char *buffer1 = xmalloc (symtable_size + string_byte_count + 1); | |
3564 | ||
3565 | H_SET_SYMBOL_TABLE_POINTER (&headers, bfd_tell (abfd)); | |
3566 | w_symbols (abfd, buffer1, symbol_rootP); | |
3567 | if (string_byte_count > 0) | |
3568 | w_strings (buffer1 + symtable_size); | |
3569 | bfd_write (buffer1, 1, symtable_size + string_byte_count, abfd); | |
3570 | free (buffer1); | |
3571 | } | |
3572 | ||
3573 | coff_header_append (abfd, &headers); | |
3574 | #if 0 | |
3575 | /* Recent changes to write need this, but where it should | |
3576 | go is up to Ken.. */ | |
3577 | if (bfd_close_all_done (abfd) == false) | |
3578 | as_fatal (_("Can't close %s: %s"), out_file_name, | |
3579 | bfd_errmsg (bfd_get_error ())); | |
3580 | #else | |
3581 | { | |
3582 | extern bfd *stdoutput; | |
3583 | stdoutput = abfd; | |
3584 | } | |
3585 | #endif | |
3586 | ||
3587 | } | |
3588 | ||
3589 | /* Add a new segment. This is called from subseg_new via the | |
3590 | obj_new_segment macro. */ | |
3591 | ||
3592 | segT | |
3593 | obj_coff_add_segment (name) | |
3594 | const char *name; | |
3595 | { | |
3596 | unsigned int i; | |
3597 | ||
3598 | #ifndef COFF_LONG_SECTION_NAMES | |
3599 | char buf[SCNNMLEN + 1]; | |
3600 | ||
3601 | strncpy (buf, name, SCNNMLEN); | |
3602 | buf[SCNNMLEN] = '\0'; | |
3603 | name = buf; | |
3604 | #endif | |
3605 | ||
3606 | for (i = SEG_E0; i < SEG_LAST && segment_info[i].scnhdr.s_name[0]; i++) | |
3607 | if (strcmp (name, segment_info[i].name) == 0) | |
3608 | return (segT) i; | |
3609 | ||
3610 | if (i == SEG_LAST) | |
3611 | { | |
3612 | as_bad (_("Too many new sections; can't add \"%s\""), name); | |
3613 | return now_seg; | |
3614 | } | |
3615 | ||
3616 | /* Add a new section. */ | |
3617 | strncpy (segment_info[i].scnhdr.s_name, name, | |
3618 | sizeof (segment_info[i].scnhdr.s_name)); | |
3619 | segment_info[i].scnhdr.s_flags = STYP_REG; | |
3620 | segment_info[i].name = xstrdup (name); | |
3621 | ||
3622 | return (segT) i; | |
3623 | } | |
3624 | ||
3625 | /* | |
3626 | * implement the .section pseudo op: | |
3627 | * .section name {, "flags"} | |
3628 | * ^ ^ | |
3629 | * | +--- optional flags: 'b' for bss | |
3630 | * | 'i' for info | |
3631 | * +-- section name 'l' for lib | |
3632 | * 'n' for noload | |
3633 | * 'o' for over | |
3634 | * 'w' for data | |
3635 | * 'd' (apparently m88k for data) | |
3636 | * 'x' for text | |
3637 | * 'r' for read-only data | |
3638 | * But if the argument is not a quoted string, treat it as a | |
3639 | * subsegment number. | |
3640 | */ | |
3641 | ||
3642 | void | |
3643 | obj_coff_section (ignore) | |
a04b544b | 3644 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3645 | { |
3646 | /* Strip out the section name */ | |
3647 | char *section_name, *name; | |
3648 | char c; | |
3649 | unsigned int exp; | |
3650 | long flags; | |
3651 | ||
3652 | if (flag_mri) | |
3653 | { | |
3654 | char type; | |
3655 | ||
3656 | s_mri_sect (&type); | |
3657 | flags = 0; | |
3658 | if (type == 'C') | |
3659 | flags = STYP_TEXT; | |
3660 | else if (type == 'D') | |
3661 | flags = STYP_DATA; | |
3662 | segment_info[now_seg].scnhdr.s_flags |= flags; | |
3663 | ||
3664 | return; | |
3665 | } | |
3666 | ||
3667 | section_name = input_line_pointer; | |
3668 | c = get_symbol_end (); | |
3669 | ||
3670 | name = xmalloc (input_line_pointer - section_name + 1); | |
3671 | strcpy (name, section_name); | |
3672 | ||
3673 | *input_line_pointer = c; | |
3674 | ||
3675 | exp = 0; | |
3676 | flags = 0; | |
3677 | ||
3678 | SKIP_WHITESPACE (); | |
3679 | if (*input_line_pointer == ',') | |
3680 | { | |
3681 | ++input_line_pointer; | |
3682 | SKIP_WHITESPACE (); | |
3683 | ||
3684 | if (*input_line_pointer != '"') | |
3685 | exp = get_absolute_expression (); | |
3686 | else | |
3687 | { | |
3688 | ++input_line_pointer; | |
3689 | while (*input_line_pointer != '"' | |
3690 | && ! is_end_of_line[(unsigned char) *input_line_pointer]) | |
3691 | { | |
3692 | switch (*input_line_pointer) | |
3693 | { | |
3694 | case 'b': flags |= STYP_BSS; break; | |
3695 | case 'i': flags |= STYP_INFO; break; | |
3696 | case 'l': flags |= STYP_LIB; break; | |
3697 | case 'n': flags |= STYP_NOLOAD; break; | |
3698 | case 'o': flags |= STYP_OVER; break; | |
3699 | case 'd': | |
3700 | case 'w': flags |= STYP_DATA; break; | |
3701 | case 'x': flags |= STYP_TEXT; break; | |
3702 | case 'r': flags |= STYP_LIT; break; | |
3703 | default: | |
3704 | as_warn(_("unknown section attribute '%c'"), | |
3705 | *input_line_pointer); | |
3706 | break; | |
3707 | } | |
3708 | ++input_line_pointer; | |
3709 | } | |
3710 | if (*input_line_pointer == '"') | |
3711 | ++input_line_pointer; | |
3712 | } | |
3713 | } | |
3714 | ||
3715 | subseg_new (name, (subsegT) exp); | |
3716 | ||
3717 | segment_info[now_seg].scnhdr.s_flags |= flags; | |
3718 | ||
3719 | demand_empty_rest_of_line (); | |
3720 | } | |
3721 | ||
3722 | ||
3723 | static void | |
3724 | obj_coff_text (ignore) | |
a04b544b | 3725 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3726 | { |
3727 | subseg_new (".text", get_absolute_expression ()); | |
3728 | } | |
3729 | ||
3730 | ||
3731 | static void | |
3732 | obj_coff_data (ignore) | |
a04b544b | 3733 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3734 | { |
3735 | if (flag_readonly_data_in_text) | |
3736 | subseg_new (".text", get_absolute_expression () + 1000); | |
3737 | else | |
3738 | subseg_new (".data", get_absolute_expression ()); | |
3739 | } | |
3740 | ||
3741 | static void | |
3742 | obj_coff_ident (ignore) | |
a04b544b | 3743 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3744 | { |
3745 | segT current_seg = now_seg; /* save current seg */ | |
3746 | subsegT current_subseg = now_subseg; | |
3747 | subseg_new (".comment", 0); /* .comment seg */ | |
3748 | stringer (1); /* read string */ | |
3749 | subseg_set (current_seg, current_subseg); /* restore current seg */ | |
3750 | } | |
3751 | ||
3752 | void | |
3753 | c_symbol_merge (debug, normal) | |
3754 | symbolS *debug; | |
3755 | symbolS *normal; | |
3756 | { | |
3757 | S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug)); | |
3758 | S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug)); | |
3759 | ||
3760 | if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal)) | |
3761 | { | |
3762 | S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug)); | |
3763 | } /* take the most we have */ | |
3764 | ||
3765 | if (S_GET_NUMBER_AUXILIARY (debug) > 0) | |
3766 | { | |
3767 | memcpy ((char *) &normal->sy_symbol.ost_auxent[0], | |
3768 | (char *) &debug->sy_symbol.ost_auxent[0], | |
3769 | (unsigned int) (S_GET_NUMBER_AUXILIARY (debug) * AUXESZ)); | |
3770 | } /* Move all the auxiliary information */ | |
3771 | ||
3772 | /* Move the debug flags. */ | |
3773 | SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug)); | |
3774 | } /* c_symbol_merge() */ | |
3775 | ||
3776 | static int | |
3777 | c_line_new (symbol, paddr, line_number, frag) | |
3778 | symbolS * symbol; | |
3779 | long paddr; | |
3780 | int line_number; | |
3781 | fragS * frag; | |
3782 | { | |
3783 | struct lineno_list *new_line = | |
3784 | (struct lineno_list *) xmalloc (sizeof (struct lineno_list)); | |
3785 | ||
3786 | segment_info_type *s = segment_info + now_seg; | |
3787 | new_line->line.l_lnno = line_number; | |
3788 | ||
3789 | if (line_number == 0) | |
3790 | { | |
3791 | last_line_symbol = symbol; | |
3792 | new_line->line.l_addr.l_symndx = (long) symbol; | |
3793 | } | |
3794 | else | |
3795 | { | |
3796 | new_line->line.l_addr.l_paddr = paddr; | |
3797 | } | |
3798 | ||
3799 | new_line->frag = (char *) frag; | |
3800 | new_line->next = (struct lineno_list *) NULL; | |
3801 | ||
3802 | ||
3803 | if (s->lineno_list_head == (struct lineno_list *) NULL) | |
3804 | { | |
3805 | s->lineno_list_head = new_line; | |
3806 | } | |
3807 | else | |
3808 | { | |
3809 | s->lineno_list_tail->next = new_line; | |
3810 | } | |
3811 | s->lineno_list_tail = new_line; | |
3812 | return LINESZ * s->scnhdr.s_nlnno++; | |
3813 | } | |
3814 | ||
3815 | void | |
3816 | c_dot_file_symbol (filename) | |
3817 | char *filename; | |
3818 | { | |
3819 | symbolS *symbolP; | |
3820 | ||
3821 | symbolP = symbol_new (".file", | |
3822 | SEG_DEBUG, | |
3823 | 0, | |
3824 | &zero_address_frag); | |
3825 | ||
3826 | S_SET_STORAGE_CLASS (symbolP, C_FILE); | |
3827 | S_SET_NUMBER_AUXILIARY (symbolP, 1); | |
3828 | ||
3829 | if (strlen (filename) > FILNMLEN) | |
3830 | { | |
3831 | /* Filename is too long to fit into an auxent, | |
3832 | we stick it into the string table instead. We keep | |
3833 | a linked list of the filenames we find so we can emit | |
3834 | them later.*/ | |
3835 | struct filename_list *f = ((struct filename_list *) | |
3836 | xmalloc (sizeof (struct filename_list))); | |
3837 | ||
3838 | f->filename = filename; | |
3839 | f->next = 0; | |
3840 | ||
3841 | SA_SET_FILE_FNAME_ZEROS (symbolP, 0); | |
3842 | SA_SET_FILE_FNAME_OFFSET (symbolP, 1); | |
3843 | ||
3844 | if (filename_list_tail) | |
3845 | filename_list_tail->next = f; | |
3846 | else | |
3847 | filename_list_head = f; | |
3848 | filename_list_tail = f; | |
3849 | } | |
3850 | else | |
3851 | { | |
3852 | SA_SET_FILE_FNAME (symbolP, filename); | |
3853 | } | |
3854 | #ifndef NO_LISTING | |
3855 | { | |
3856 | extern int listing; | |
3857 | if (listing) | |
3858 | { | |
3859 | listing_source_file (filename); | |
3860 | } | |
3861 | ||
3862 | } | |
3863 | ||
3864 | #endif | |
3865 | SF_SET_DEBUG (symbolP); | |
3866 | S_SET_VALUE (symbolP, (valueT) previous_file_symbol); | |
3867 | ||
3868 | previous_file_symbol = symbolP; | |
3869 | ||
3870 | /* Make sure that the symbol is first on the symbol chain */ | |
3871 | if (symbol_rootP != symbolP) | |
3872 | { | |
3873 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
3874 | symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP); | |
3875 | } | |
3876 | } /* c_dot_file_symbol() */ | |
3877 | ||
3878 | /* | |
3879 | * Build a 'section static' symbol. | |
3880 | */ | |
3881 | ||
3882 | symbolS * | |
3883 | c_section_symbol (name, idx) | |
3884 | char *name; | |
3885 | int idx; | |
3886 | { | |
3887 | symbolS *symbolP; | |
3888 | ||
3889 | symbolP = symbol_find_base (name, DO_NOT_STRIP); | |
3890 | if (symbolP == NULL) | |
3891 | symbolP = symbol_new (name, idx, 0, &zero_address_frag); | |
3892 | else | |
3893 | { | |
3894 | /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */ | |
3895 | S_SET_SEGMENT (symbolP, idx); | |
3896 | symbolP->sy_frag = &zero_address_frag; | |
3897 | } | |
3898 | ||
3899 | S_SET_STORAGE_CLASS (symbolP, C_STAT); | |
3900 | S_SET_NUMBER_AUXILIARY (symbolP, 1); | |
3901 | ||
3902 | SF_SET_STATICS (symbolP); | |
3903 | ||
3904 | #ifdef TE_DELTA | |
3905 | /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared, | |
3906 | which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */ | |
3907 | SF_CLEAR_LOCAL (symbolP); | |
3908 | #endif | |
3909 | #ifdef TE_PE | |
3910 | /* If the .linkonce pseudo-op was used for this section, we must | |
3911 | store the information in the auxiliary entry for the section | |
3912 | symbol. */ | |
3913 | if (segment_info[idx].linkonce != LINKONCE_UNSET) | |
3914 | { | |
3915 | int type; | |
3916 | ||
3917 | switch (segment_info[idx].linkonce) | |
3918 | { | |
3919 | default: | |
3920 | abort (); | |
3921 | case LINKONCE_DISCARD: | |
3922 | type = IMAGE_COMDAT_SELECT_ANY; | |
3923 | break; | |
3924 | case LINKONCE_ONE_ONLY: | |
3925 | type = IMAGE_COMDAT_SELECT_NODUPLICATES; | |
3926 | break; | |
3927 | case LINKONCE_SAME_SIZE: | |
3928 | type = IMAGE_COMDAT_SELECT_SAME_SIZE; | |
3929 | break; | |
3930 | case LINKONCE_SAME_CONTENTS: | |
3931 | type = IMAGE_COMDAT_SELECT_EXACT_MATCH; | |
3932 | break; | |
3933 | } | |
3934 | ||
3935 | SYM_AUXENT (symbolP)->x_scn.x_comdat = type; | |
3936 | } | |
3937 | #endif /* TE_PE */ | |
3938 | ||
3939 | return symbolP; | |
3940 | } /* c_section_symbol() */ | |
3941 | ||
3942 | static void | |
3943 | w_symbols (abfd, where, symbol_rootP) | |
3944 | bfd * abfd; | |
3945 | char *where; | |
3946 | symbolS * symbol_rootP; | |
3947 | { | |
3948 | symbolS *symbolP; | |
3949 | unsigned int i; | |
3950 | ||
3951 | /* First fill in those values we have only just worked out */ | |
3952 | for (i = SEG_E0; i < SEG_LAST; i++) | |
3953 | { | |
3954 | symbolP = segment_info[i].dot; | |
3955 | if (symbolP) | |
3956 | { | |
3957 | SA_SET_SCN_SCNLEN (symbolP, segment_info[i].scnhdr.s_size); | |
3958 | SA_SET_SCN_NRELOC (symbolP, segment_info[i].scnhdr.s_nreloc); | |
3959 | SA_SET_SCN_NLINNO (symbolP, segment_info[i].scnhdr.s_nlnno); | |
3960 | } | |
3961 | } | |
3962 | ||
3963 | /* | |
3964 | * Emit all symbols left in the symbol chain. | |
3965 | */ | |
3966 | for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP)) | |
3967 | { | |
3968 | /* Used to save the offset of the name. It is used to point | |
3969 | to the string in memory but must be a file offset. */ | |
3970 | register char *temp; | |
3971 | ||
3972 | /* We can't fix the lnnoptr field in yank_symbols with the other | |
3973 | adjustments, because we have to wait until we know where they | |
3974 | go in the file. */ | |
3975 | if (SF_GET_ADJ_LNNOPTR (symbolP)) | |
3976 | { | |
3977 | SA_GET_SYM_LNNOPTR (symbolP) += | |
3978 | segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_lnnoptr; | |
3979 | } | |
3980 | ||
3981 | tc_coff_symbol_emit_hook (symbolP); | |
3982 | ||
3983 | temp = S_GET_NAME (symbolP); | |
3984 | if (SF_GET_STRING (symbolP)) | |
3985 | { | |
3986 | S_SET_OFFSET (symbolP, symbolP->sy_name_offset); | |
3987 | S_SET_ZEROES (symbolP, 0); | |
3988 | } | |
3989 | else | |
3990 | { | |
3991 | memset (symbolP->sy_symbol.ost_entry.n_name, 0, SYMNMLEN); | |
3992 | strncpy (symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN); | |
3993 | } | |
3994 | where = symbol_to_chars (abfd, where, symbolP); | |
3995 | S_SET_NAME (symbolP, temp); | |
3996 | } | |
3997 | ||
3998 | } /* w_symbols() */ | |
3999 | ||
4000 | static void | |
4001 | obj_coff_lcomm (ignore) | |
a04b544b | 4002 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
4003 | { |
4004 | s_lcomm(0); | |
4005 | return; | |
4006 | #if 0 | |
4007 | char *name; | |
4008 | char c; | |
4009 | int temp; | |
4010 | char *p; | |
4011 | ||
4012 | symbolS *symbolP; | |
4013 | ||
4014 | name = input_line_pointer; | |
4015 | ||
4016 | c = get_symbol_end (); | |
4017 | p = input_line_pointer; | |
4018 | *p = c; | |
4019 | SKIP_WHITESPACE (); | |
4020 | if (*input_line_pointer != ',') | |
4021 | { | |
4022 | as_bad (_("Expected comma after name")); | |
4023 | ignore_rest_of_line (); | |
4024 | return; | |
4025 | } | |
4026 | if (*input_line_pointer == '\n') | |
4027 | { | |
4028 | as_bad (_("Missing size expression")); | |
4029 | return; | |
4030 | } | |
4031 | input_line_pointer++; | |
4032 | if ((temp = get_absolute_expression ()) < 0) | |
4033 | { | |
4034 | as_warn (_("lcomm length (%d.) <0! Ignored."), temp); | |
4035 | ignore_rest_of_line (); | |
4036 | return; | |
4037 | } | |
4038 | *p = 0; | |
4039 | ||
4040 | symbolP = symbol_find_or_make(name); | |
4041 | ||
4042 | if (S_GET_SEGMENT(symbolP) == SEG_UNKNOWN && | |
4043 | S_GET_VALUE(symbolP) == 0) | |
4044 | { | |
4045 | if (! need_pass_2) | |
4046 | { | |
4047 | char *p; | |
4048 | segT current_seg = now_seg; /* save current seg */ | |
4049 | subsegT current_subseg = now_subseg; | |
4050 | ||
4051 | subseg_set (SEG_E2, 1); | |
4052 | symbolP->sy_frag = frag_now; | |
4053 | p = frag_var(rs_org, 1, 1, (relax_substateT)0, symbolP, | |
4054 | (offsetT) temp, (char *) 0); | |
4055 | *p = 0; | |
4056 | subseg_set (current_seg, current_subseg); /* restore current seg */ | |
4057 | S_SET_SEGMENT(symbolP, SEG_E2); | |
4058 | S_SET_STORAGE_CLASS(symbolP, C_STAT); | |
4059 | } | |
4060 | } | |
4061 | else | |
4062 | as_bad(_("Symbol %s already defined"), name); | |
4063 | ||
4064 | demand_empty_rest_of_line(); | |
4065 | #endif | |
4066 | } | |
4067 | ||
4068 | static void | |
4069 | fixup_mdeps (frags, h, this_segment) | |
4070 | fragS * frags; | |
4071 | object_headers * h; | |
4072 | segT this_segment; | |
4073 | { | |
4074 | subseg_change (this_segment, 0); | |
4075 | while (frags) | |
4076 | { | |
4077 | switch (frags->fr_type) | |
4078 | { | |
4079 | case rs_align: | |
4080 | case rs_align_code: | |
4081 | case rs_org: | |
4082 | #ifdef HANDLE_ALIGN | |
4083 | HANDLE_ALIGN (frags); | |
4084 | #endif | |
4085 | frags->fr_type = rs_fill; | |
4086 | frags->fr_offset = | |
4087 | ((frags->fr_next->fr_address - frags->fr_address - frags->fr_fix) | |
4088 | / frags->fr_var); | |
4089 | break; | |
4090 | case rs_machine_dependent: | |
4091 | md_convert_frag (h, this_segment, frags); | |
4092 | frag_wane (frags); | |
4093 | break; | |
4094 | default: | |
4095 | ; | |
4096 | } | |
4097 | frags = frags->fr_next; | |
4098 | } | |
4099 | } | |
4100 | ||
4101 | #if 1 | |
4102 | ||
4103 | #ifndef TC_FORCE_RELOCATION | |
4104 | #define TC_FORCE_RELOCATION(fix) 0 | |
4105 | #endif | |
4106 | ||
4107 | static void | |
4108 | fixup_segment (segP, this_segment_type) | |
4109 | segment_info_type * segP; | |
4110 | segT this_segment_type; | |
4111 | { | |
4112 | register fixS * fixP; | |
4113 | register symbolS *add_symbolP; | |
4114 | register symbolS *sub_symbolP; | |
4115 | long add_number; | |
4116 | register int size; | |
4117 | register char *place; | |
4118 | register long where; | |
4119 | register char pcrel; | |
4120 | register fragS *fragP; | |
4121 | register segT add_symbol_segment = absolute_section; | |
4122 | ||
4123 | for (fixP = segP->fix_root; fixP; fixP = fixP->fx_next) | |
4124 | { | |
4125 | fragP = fixP->fx_frag; | |
4126 | know (fragP); | |
4127 | where = fixP->fx_where; | |
4128 | place = fragP->fr_literal + where; | |
4129 | size = fixP->fx_size; | |
4130 | add_symbolP = fixP->fx_addsy; | |
4131 | sub_symbolP = fixP->fx_subsy; | |
4132 | add_number = fixP->fx_offset; | |
4133 | pcrel = fixP->fx_pcrel; | |
4134 | ||
4135 | /* We want function-relative stabs to work on systems which | |
4136 | may use a relaxing linker; thus we must handle the sym1-sym2 | |
4137 | fixups function-relative stabs generates. | |
4138 | ||
4139 | Of course, if you actually enable relaxing in the linker, the | |
4140 | line and block scoping information is going to be incorrect | |
4141 | in some cases. The only way to really fix this is to support | |
4142 | a reloc involving the difference of two symbols. */ | |
4143 | if (linkrelax | |
4144 | && (!sub_symbolP || pcrel)) | |
4145 | continue; | |
4146 | ||
4147 | #ifdef TC_I960 | |
4148 | if (fixP->fx_tcbit && SF_GET_CALLNAME (add_symbolP)) | |
4149 | { | |
4150 | /* Relocation should be done via the associated 'bal' entry | |
4151 | point symbol. */ | |
4152 | ||
4153 | if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP))) | |
4154 | { | |
4155 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4156 | _("No 'bal' entry point for leafproc %s"), | |
4157 | S_GET_NAME (add_symbolP)); | |
4158 | continue; | |
4159 | } | |
4160 | fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP); | |
4161 | } | |
4162 | #endif | |
4163 | ||
4164 | /* Make sure the symbols have been resolved; this may not have | |
4165 | happened if these are expression symbols. */ | |
4166 | if (add_symbolP != NULL && ! add_symbolP->sy_resolved) | |
4167 | resolve_symbol_value (add_symbolP, 1); | |
4168 | ||
4169 | if (add_symbolP != NULL) | |
4170 | { | |
4171 | /* If this fixup is against a symbol which has been equated | |
4172 | to another symbol, convert it to the other symbol. */ | |
4173 | if (add_symbolP->sy_value.X_op == O_symbol | |
4174 | && (! S_IS_DEFINED (add_symbolP) | |
4175 | || S_IS_COMMON (add_symbolP))) | |
4176 | { | |
4177 | while (add_symbolP->sy_value.X_op == O_symbol | |
4178 | && (! S_IS_DEFINED (add_symbolP) | |
4179 | || S_IS_COMMON (add_symbolP))) | |
4180 | { | |
4181 | symbolS *n; | |
4182 | ||
4183 | /* We must avoid looping, as that can occur with a | |
4184 | badly written program. */ | |
4185 | n = add_symbolP->sy_value.X_add_symbol; | |
4186 | if (n == add_symbolP) | |
4187 | break; | |
4188 | add_number += add_symbolP->sy_value.X_add_number; | |
4189 | add_symbolP = n; | |
4190 | } | |
4191 | fixP->fx_addsy = add_symbolP; | |
4192 | fixP->fx_offset = add_number; | |
4193 | } | |
4194 | } | |
4195 | ||
4196 | if (sub_symbolP != NULL && ! sub_symbolP->sy_resolved) | |
4197 | resolve_symbol_value (sub_symbolP, 1); | |
4198 | ||
4199 | if (add_symbolP != NULL | |
4200 | && add_symbolP->sy_mri_common) | |
4201 | { | |
4202 | know (add_symbolP->sy_value.X_op == O_symbol); | |
4203 | add_number += S_GET_VALUE (add_symbolP); | |
4204 | fixP->fx_offset = add_number; | |
4205 | add_symbolP = fixP->fx_addsy = add_symbolP->sy_value.X_add_symbol; | |
4206 | } | |
4207 | ||
4208 | if (add_symbolP) | |
4209 | { | |
4210 | add_symbol_segment = S_GET_SEGMENT (add_symbolP); | |
4211 | } /* if there is an addend */ | |
4212 | ||
4213 | if (sub_symbolP) | |
4214 | { | |
4215 | if (add_symbolP == NULL || add_symbol_segment == absolute_section) | |
4216 | { | |
4217 | if (add_symbolP != NULL) | |
4218 | { | |
4219 | add_number += S_GET_VALUE (add_symbolP); | |
4220 | add_symbolP = NULL; | |
4221 | fixP->fx_addsy = NULL; | |
4222 | } | |
4223 | ||
4224 | /* It's just -sym. */ | |
4225 | if (S_GET_SEGMENT (sub_symbolP) == absolute_section) | |
4226 | { | |
4227 | add_number -= S_GET_VALUE (sub_symbolP); | |
4228 | fixP->fx_subsy = 0; | |
4229 | fixP->fx_done = 1; | |
4230 | } | |
4231 | else | |
4232 | { | |
4233 | #ifndef TC_M68K | |
4234 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4235 | _("Negative of non-absolute symbol %s"), | |
4236 | S_GET_NAME (sub_symbolP)); | |
4237 | #endif | |
4238 | add_number -= S_GET_VALUE (sub_symbolP); | |
4239 | } /* not absolute */ | |
4240 | ||
4241 | /* if sub_symbol is in the same segment that add_symbol | |
4242 | and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */ | |
4243 | } | |
4244 | else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment | |
4245 | && SEG_NORMAL (add_symbol_segment)) | |
4246 | { | |
4247 | /* Difference of 2 symbols from same segment. Can't | |
4248 | make difference of 2 undefineds: 'value' means | |
4249 | something different for N_UNDF. */ | |
4250 | #ifdef TC_I960 | |
4251 | /* Makes no sense to use the difference of 2 arbitrary symbols | |
4252 | as the target of a call instruction. */ | |
4253 | if (fixP->fx_tcbit) | |
4254 | { | |
4255 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4256 | _("callj to difference of 2 symbols")); | |
4257 | } | |
4258 | #endif /* TC_I960 */ | |
4259 | add_number += S_GET_VALUE (add_symbolP) - | |
4260 | S_GET_VALUE (sub_symbolP); | |
4261 | add_symbolP = NULL; | |
4262 | ||
4263 | if (!TC_FORCE_RELOCATION (fixP)) | |
4264 | { | |
4265 | fixP->fx_addsy = NULL; | |
4266 | fixP->fx_subsy = NULL; | |
4267 | fixP->fx_done = 1; | |
4268 | #ifdef TC_M68K /* is this right? */ | |
4269 | pcrel = 0; | |
4270 | fixP->fx_pcrel = 0; | |
4271 | #endif | |
4272 | } | |
4273 | } | |
4274 | else | |
4275 | { | |
4276 | /* Different segments in subtraction. */ | |
4277 | know (!(S_IS_EXTERNAL (sub_symbolP) && (S_GET_SEGMENT (sub_symbolP) == absolute_section))); | |
4278 | ||
4279 | if ((S_GET_SEGMENT (sub_symbolP) == absolute_section)) | |
4280 | { | |
4281 | add_number -= S_GET_VALUE (sub_symbolP); | |
4282 | } | |
4283 | #ifdef DIFF_EXPR_OK | |
4284 | else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type | |
4285 | #if 0 /* Okay for 68k, at least... */ | |
4286 | && !pcrel | |
4287 | #endif | |
4288 | ) | |
4289 | { | |
4290 | /* Make it pc-relative. */ | |
4291 | add_number += (md_pcrel_from (fixP) | |
4292 | - S_GET_VALUE (sub_symbolP)); | |
4293 | pcrel = 1; | |
4294 | fixP->fx_pcrel = 1; | |
4295 | sub_symbolP = 0; | |
4296 | fixP->fx_subsy = 0; | |
4297 | } | |
4298 | #endif | |
4299 | else | |
4300 | { | |
4301 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4302 | _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."), | |
4303 | segment_name (S_GET_SEGMENT (sub_symbolP)), | |
4304 | S_GET_NAME (sub_symbolP), | |
4305 | (long) (fragP->fr_address + where)); | |
4306 | } /* if absolute */ | |
4307 | } | |
4308 | } /* if sub_symbolP */ | |
4309 | ||
4310 | if (add_symbolP) | |
4311 | { | |
4312 | if (add_symbol_segment == this_segment_type && pcrel) | |
4313 | { | |
4314 | /* | |
4315 | * This fixup was made when the symbol's segment was | |
4316 | * SEG_UNKNOWN, but it is now in the local segment. | |
4317 | * So we know how to do the address without relocation. | |
4318 | */ | |
4319 | #ifdef TC_I960 | |
4320 | /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal', | |
4321 | * in which cases it modifies *fixP as appropriate. In the case | |
4322 | * of a 'calls', no further work is required, and *fixP has been | |
4323 | * set up to make the rest of the code below a no-op. | |
4324 | */ | |
4325 | reloc_callj (fixP); | |
4326 | #endif /* TC_I960 */ | |
4327 | ||
4328 | add_number += S_GET_VALUE (add_symbolP); | |
4329 | add_number -= md_pcrel_from (fixP); | |
4330 | ||
4331 | /* We used to do | |
4332 | add_number -= segP->scnhdr.s_vaddr; | |
4333 | if defined (TC_I386) || defined (TE_LYNX). I now | |
4334 | think that was an error propagated from the case when | |
4335 | we are going to emit the relocation. If we are not | |
4336 | going to emit the relocation, then we just want to | |
4337 | set add_number to the difference between the symbols. | |
4338 | This is a case that would only arise when there is a | |
4339 | PC relative reference from a section other than .text | |
4340 | to a symbol defined in the same section, and the | |
4341 | reference is not relaxed. Since jump instructions on | |
4342 | the i386 are relaxed, this could only arise with a | |
4343 | call instruction. */ | |
4344 | ||
4345 | pcrel = 0; /* Lie. Don't want further pcrel processing. */ | |
4346 | if (!TC_FORCE_RELOCATION (fixP)) | |
4347 | { | |
4348 | fixP->fx_addsy = NULL; | |
4349 | fixP->fx_done = 1; | |
4350 | } | |
4351 | } | |
4352 | else | |
4353 | { | |
4354 | switch (add_symbol_segment) | |
4355 | { | |
4356 | case absolute_section: | |
4357 | #ifdef TC_I960 | |
4358 | reloc_callj (fixP); /* See comment about reloc_callj() above*/ | |
4359 | #endif /* TC_I960 */ | |
4360 | add_number += S_GET_VALUE (add_symbolP); | |
4361 | add_symbolP = NULL; | |
4362 | ||
4363 | if (!TC_FORCE_RELOCATION (fixP)) | |
4364 | { | |
4365 | fixP->fx_addsy = NULL; | |
4366 | fixP->fx_done = 1; | |
4367 | } | |
4368 | break; | |
4369 | default: | |
4370 | ||
4371 | ||
4372 | #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K) | |
4373 | /* This really should be handled in the linker, but | |
4374 | backward compatibility forbids. */ | |
4375 | add_number += S_GET_VALUE (add_symbolP); | |
4376 | #else | |
4377 | add_number += S_GET_VALUE (add_symbolP) + | |
4378 | segment_info[S_GET_SEGMENT (add_symbolP)].scnhdr.s_paddr; | |
4379 | #endif | |
4380 | break; | |
4381 | ||
4382 | case SEG_UNKNOWN: | |
4383 | #ifdef TC_I960 | |
4384 | if ((int) fixP->fx_bit_fixP == 13) | |
4385 | { | |
4386 | /* This is a COBR instruction. They have only a | |
4387 | * 13-bit displacement and are only to be used | |
4388 | * for local branches: flag as error, don't generate | |
4389 | * relocation. | |
4390 | */ | |
4391 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4392 | _("can't use COBR format with external label")); | |
4393 | fixP->fx_addsy = NULL; | |
4394 | fixP->fx_done = 1; | |
4395 | continue; | |
4396 | } /* COBR */ | |
4397 | #endif /* TC_I960 */ | |
4398 | #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND) | |
4399 | /* 386 COFF uses a peculiar format in which the | |
4400 | value of a common symbol is stored in the .text | |
4401 | segment (I've checked this on SVR3.2 and SCO | |
4402 | 3.2.2) Ian Taylor <ian@cygnus.com>. */ | |
4403 | /* This is also true for 68k COFF on sysv machines | |
4404 | (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on | |
4405 | UNIX System V/M68000, Release 1.0 from ATT/Bell Labs) | |
4406 | Philippe De Muyter <phdm@info.ucl.ac.be>. */ | |
4407 | if (S_IS_COMMON (add_symbolP)) | |
4408 | add_number += S_GET_VALUE (add_symbolP); | |
4409 | #endif | |
4410 | break; | |
4411 | ||
4412 | ||
4413 | } /* switch on symbol seg */ | |
4414 | } /* if not in local seg */ | |
4415 | } /* if there was a + symbol */ | |
4416 | ||
4417 | if (pcrel) | |
4418 | { | |
4419 | #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K) | |
4420 | /* This adjustment is not correct on the m88k, for which the | |
4421 | linker does all the computation. */ | |
4422 | add_number -= md_pcrel_from (fixP); | |
4423 | #endif | |
4424 | if (add_symbolP == 0) | |
4425 | { | |
4426 | fixP->fx_addsy = &abs_symbol; | |
4427 | } /* if there's an add_symbol */ | |
4428 | #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K) | |
4429 | /* On the 386 we must adjust by the segment vaddr as well. | |
4430 | Ian Taylor. | |
4431 | ||
4432 | I changed the i960 to work this way as well. This is | |
4433 | compatible with the current GNU linker behaviour. I do | |
4434 | not know what other i960 COFF assemblers do. This is not | |
4435 | a common case: normally, only assembler code will contain | |
4436 | a PC relative reloc, and only branches which do not | |
4437 | originate in the .text section will have a non-zero | |
4438 | address. | |
4439 | ||
4440 | I changed the m68k to work this way as well. This will | |
4441 | break existing PC relative relocs from sections which do | |
4442 | not start at address 0, but it will make ld -r work. | |
4443 | Ian Taylor, 4 Oct 96. */ | |
4444 | ||
4445 | add_number -= segP->scnhdr.s_vaddr; | |
4446 | #endif | |
4447 | } /* if pcrel */ | |
4448 | ||
ec0f0840 AM |
4449 | #ifdef MD_APPLY_FIX3 |
4450 | md_apply_fix3 (fixP, (valueT *) &add_number, this_segment_type); | |
4451 | #else | |
4452 | md_apply_fix (fixP, add_number); | |
4453 | #endif | |
4454 | ||
252b5132 RH |
4455 | if (!fixP->fx_bit_fixP && ! fixP->fx_no_overflow) |
4456 | { | |
4457 | #ifndef TC_M88K | |
4458 | /* The m88k uses the offset field of the reloc to get around | |
4459 | this problem. */ | |
4460 | if ((size == 1 | |
4461 | && ((add_number & ~0xFF) | |
4462 | || (fixP->fx_signed && (add_number & 0x80))) | |
4463 | && ((add_number & ~0xFF) != (-1 & ~0xFF) | |
4464 | || (add_number & 0x80) == 0)) | |
4465 | || (size == 2 | |
4466 | && ((add_number & ~0xFFFF) | |
4467 | || (fixP->fx_signed && (add_number & 0x8000))) | |
4468 | && ((add_number & ~0xFFFF) != (-1 & ~0xFFFF) | |
4469 | || (add_number & 0x8000) == 0))) | |
4470 | { | |
4471 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4472 | _("Value of %ld too large for field of %d bytes at 0x%lx"), | |
4473 | (long) add_number, size, | |
4474 | (unsigned long) (fragP->fr_address + where)); | |
4475 | } | |
4476 | #endif | |
4477 | #ifdef WARN_SIGNED_OVERFLOW_WORD | |
4478 | /* Warn if a .word value is too large when treated as a | |
4479 | signed number. We already know it is not too negative. | |
4480 | This is to catch over-large switches generated by gcc on | |
4481 | the 68k. */ | |
4482 | if (!flag_signed_overflow_ok | |
4483 | && size == 2 | |
4484 | && add_number > 0x7fff) | |
4485 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4486 | _("Signed .word overflow; switch may be too large; %ld at 0x%lx"), | |
4487 | (long) add_number, | |
4488 | (unsigned long) (fragP->fr_address + where)); | |
4489 | #endif | |
4490 | } /* not a bit fix */ | |
252b5132 RH |
4491 | } /* For each fixS in this segment. */ |
4492 | } /* fixup_segment() */ | |
4493 | ||
4494 | #endif | |
4495 | ||
4496 | /* The first entry in a .stab section is special. */ | |
4497 | ||
4498 | void | |
4499 | obj_coff_init_stab_section (seg) | |
4500 | segT seg; | |
4501 | { | |
4502 | char *file; | |
4503 | char *p; | |
4504 | char *stabstr_name; | |
4505 | unsigned int stroff; | |
4506 | ||
4507 | /* Make space for this first symbol. */ | |
4508 | p = frag_more (12); | |
4509 | /* Zero it out. */ | |
4510 | memset (p, 0, 12); | |
4511 | as_where (&file, (unsigned int *) NULL); | |
4512 | stabstr_name = (char *) alloca (strlen (segment_info[seg].name) + 4); | |
4513 | strcpy (stabstr_name, segment_info[seg].name); | |
4514 | strcat (stabstr_name, "str"); | |
4515 | stroff = get_stab_string_offset (file, stabstr_name); | |
4516 | know (stroff == 1); | |
4517 | md_number_to_chars (p, stroff, 4); | |
4518 | } | |
4519 | ||
4520 | /* Fill in the counts in the first entry in a .stab section. */ | |
4521 | ||
4522 | static void | |
4523 | adjust_stab_section(abfd, seg) | |
4524 | bfd *abfd; | |
4525 | segT seg; | |
4526 | { | |
4527 | segT stabstrseg = SEG_UNKNOWN; | |
4528 | const char *secname, *name2; | |
4529 | char *name; | |
4530 | char *p = NULL; | |
4531 | int i, strsz = 0, nsyms; | |
4532 | fragS *frag = segment_info[seg].frchainP->frch_root; | |
4533 | ||
4534 | /* Look for the associated string table section. */ | |
4535 | ||
4536 | secname = segment_info[seg].name; | |
4537 | name = (char *) alloca (strlen (secname) + 4); | |
4538 | strcpy (name, secname); | |
4539 | strcat (name, "str"); | |
4540 | ||
4541 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
4542 | { | |
4543 | name2 = segment_info[i].name; | |
4544 | if (name2 != NULL && strncmp(name2, name, 8) == 0) | |
4545 | { | |
4546 | stabstrseg = i; | |
4547 | break; | |
4548 | } | |
4549 | } | |
4550 | ||
4551 | /* If we found the section, get its size. */ | |
4552 | if (stabstrseg != SEG_UNKNOWN) | |
4553 | strsz = size_section (abfd, stabstrseg); | |
4554 | ||
4555 | nsyms = size_section (abfd, seg) / 12 - 1; | |
4556 | ||
4557 | /* Look for the first frag of sufficient size for the initial stab | |
4558 | symbol, and collect a pointer to it. */ | |
4559 | while (frag && frag->fr_fix < 12) | |
4560 | frag = frag->fr_next; | |
4561 | assert (frag != 0); | |
4562 | p = frag->fr_literal; | |
4563 | assert (p != 0); | |
4564 | ||
4565 | /* Write in the number of stab symbols and the size of the string | |
4566 | table. */ | |
4567 | bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6); | |
4568 | bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8); | |
4569 | } | |
4570 | ||
4571 | #endif /* not BFD_ASSEMBLER */ | |
4572 | ||
4c63da97 | 4573 | const pseudo_typeS coff_pseudo_table[] = |
252b5132 RH |
4574 | { |
4575 | {"def", obj_coff_def, 0}, | |
4576 | {"dim", obj_coff_dim, 0}, | |
4577 | {"endef", obj_coff_endef, 0}, | |
4578 | {"line", obj_coff_line, 0}, | |
4579 | {"ln", obj_coff_ln, 0}, | |
28428223 ILT |
4580 | #ifdef BFD_ASSEMBLER |
4581 | {"loc", obj_coff_loc, 0}, | |
4582 | #endif | |
252b5132 RH |
4583 | {"appline", obj_coff_ln, 1}, |
4584 | {"scl", obj_coff_scl, 0}, | |
4585 | {"size", obj_coff_size, 0}, | |
4586 | {"tag", obj_coff_tag, 0}, | |
4587 | {"type", obj_coff_type, 0}, | |
4588 | {"val", obj_coff_val, 0}, | |
4589 | {"section", obj_coff_section, 0}, | |
4590 | {"sect", obj_coff_section, 0}, | |
4591 | /* FIXME: We ignore the MRI short attribute. */ | |
4592 | {"section.s", obj_coff_section, 0}, | |
4593 | {"sect.s", obj_coff_section, 0}, | |
4594 | /* We accept the .bss directive for backward compatibility with | |
4595 | earlier versions of gas. */ | |
4596 | {"bss", obj_coff_bss, 0}, | |
4597 | {"weak", obj_coff_weak, 0}, | |
7a6284c4 | 4598 | {"ident", obj_coff_ident, 0}, |
252b5132 RH |
4599 | #ifndef BFD_ASSEMBLER |
4600 | {"use", obj_coff_section, 0}, | |
4601 | {"text", obj_coff_text, 0}, | |
4602 | {"data", obj_coff_data, 0}, | |
4603 | {"lcomm", obj_coff_lcomm, 0}, | |
252b5132 RH |
4604 | #else |
4605 | {"optim", s_ignore, 0}, /* For sun386i cc (?) */ | |
252b5132 RH |
4606 | #endif |
4607 | {"version", s_ignore, 0}, | |
4608 | {"ABORT", s_abort, 0}, | |
4609 | #ifdef TC_M88K | |
4610 | /* The m88k uses sdef instead of def. */ | |
4611 | {"sdef", obj_coff_def, 0}, | |
4612 | #endif | |
a04b544b | 4613 | {NULL, NULL, 0} /* end sentinel */ |
4c63da97 | 4614 | }; /* coff_pseudo_table */ |
252b5132 RH |
4615 | \f |
4616 | #ifdef BFD_ASSEMBLER | |
4617 | ||
4618 | /* Support for a COFF emulation. */ | |
4619 | ||
4c63da97 | 4620 | static void coff_pop_insert PARAMS ((void)); |
5110c57e | 4621 | static int coff_separate_stab_sections PARAMS ((void)); |
4c63da97 | 4622 | |
252b5132 RH |
4623 | static void |
4624 | coff_pop_insert () | |
4625 | { | |
4c63da97 | 4626 | pop_insert (coff_pseudo_table); |
252b5132 RH |
4627 | } |
4628 | ||
5110c57e HPN |
4629 | static int |
4630 | coff_separate_stab_sections () | |
4631 | { | |
4632 | return 1; | |
4633 | } | |
4634 | ||
252b5132 RH |
4635 | const struct format_ops coff_format_ops = |
4636 | { | |
4637 | bfd_target_coff_flavour, | |
4c63da97 AM |
4638 | 0, /* dfl_leading_underscore */ |
4639 | 1, /* emit_section_symbols */ | |
5110c57e HPN |
4640 | 0, /* begin */ |
4641 | c_dot_file_symbol, | |
252b5132 | 4642 | coff_frob_symbol, |
4c63da97 | 4643 | 0, /* frob_file */ |
252b5132 | 4644 | coff_frob_file_after_relocs, |
4c63da97 AM |
4645 | 0, /* s_get_size */ |
4646 | 0, /* s_set_size */ | |
4647 | 0, /* s_get_align */ | |
4648 | 0, /* s_set_align */ | |
4649 | 0, /* s_get_other */ | |
5110c57e | 4650 | 0, /* s_set_other */ |
4c63da97 | 4651 | 0, /* s_get_desc */ |
5110c57e HPN |
4652 | 0, /* s_set_desc */ |
4653 | 0, /* s_get_type */ | |
4654 | 0, /* s_set_type */ | |
4c63da97 AM |
4655 | 0, /* copy_symbol_attributes */ |
4656 | 0, /* generate_asm_lineno */ | |
4657 | 0, /* process_stab */ | |
5110c57e HPN |
4658 | coff_separate_stab_sections, |
4659 | obj_coff_init_stab_section, | |
4c63da97 | 4660 | 0, /* sec_sym_ok_for_reloc */ |
252b5132 | 4661 | coff_pop_insert, |
4c63da97 | 4662 | 0, /* ecoff_set_ext */ |
252b5132 | 4663 | coff_obj_read_begin_hook, |
4c63da97 | 4664 | coff_obj_symbol_new_hook |
252b5132 RH |
4665 | }; |
4666 | ||
4667 | #endif |