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