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