1 /* coff object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 Free Software Foundation, Inc.
6 This file is part of GAS.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define OBJ_HEADER "obj-coff.h"
29 /* I think this is probably always correct. */
30 #ifndef KEEP_RELOC_INFO
31 #define KEEP_RELOC_INFO
34 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
35 a new section's attributes when a directive has no valid flags or the
36 "w" flag is used. This default should be appropriate for most. */
37 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
38 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
41 static void obj_coff_bss PARAMS ((int));
42 const char *s_get_name PARAMS ((symbolS * s));
43 static void obj_coff_ln PARAMS ((int));
44 static void obj_coff_def PARAMS ((int));
45 static void obj_coff_endef PARAMS ((int));
46 static void obj_coff_dim PARAMS ((int));
47 static void obj_coff_line PARAMS ((int));
48 static void obj_coff_size PARAMS ((int));
49 static void obj_coff_scl PARAMS ((int));
50 static void obj_coff_tag PARAMS ((int));
51 static void obj_coff_val PARAMS ((int));
52 static void obj_coff_type PARAMS ((int));
53 static void obj_coff_ident PARAMS ((int));
55 static void obj_coff_loc PARAMS((int));
58 /* This is used to hold the symbol built by a sequence of pseudo-ops
59 from .def and .endef. */
60 static symbolS *def_symbol_in_progress;
65 unsigned long chunk_size;
66 unsigned long element_size;
69 unsigned long pointer;
74 stack_init (chunk_size, element_size)
75 unsigned long chunk_size;
76 unsigned long element_size;
80 st = (stack *) malloc (sizeof (stack));
83 st->data = malloc (chunk_size);
90 st->size = chunk_size;
91 st->chunk_size = chunk_size;
92 st->element_size = element_size;
97 /* Not currently used. */
108 stack_push (st, element)
112 if (st->pointer + st->element_size >= st->size)
114 st->size += st->chunk_size;
115 if ((st->data = xrealloc (st->data, st->size)) == (char *) 0)
118 memcpy (st->data + st->pointer, element, st->element_size);
119 st->pointer += st->element_size;
120 return st->data + st->pointer;
127 if (st->pointer < st->element_size)
132 st->pointer -= st->element_size;
133 return st->data + st->pointer;
137 * Maintain a list of the tagnames of the structres.
140 static struct hash_control *tag_hash;
145 tag_hash = hash_new ();
149 tag_insert (name, symbolP)
153 const char *error_string;
155 if ((error_string = hash_jam (tag_hash, name, (char *) symbolP)))
157 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
166 #ifdef STRIP_UNDERSCORE
169 #endif /* STRIP_UNDERSCORE */
170 return (symbolS *) hash_find (tag_hash, name);
174 tag_find_or_make (name)
179 if ((symbolP = tag_find (name)) == NULL)
181 symbolP = symbol_new (name, undefined_section,
182 0, &zero_address_frag);
184 tag_insert (S_GET_NAME (symbolP), symbolP);
186 symbol_table_insert (symbolP);
193 /* We accept the .bss directive to set the section for backward
194 compatibility with earlier versions of gas. */
197 obj_coff_bss (ignore)
198 int ignore ATTRIBUTE_UNUSED;
200 if (*input_line_pointer == '\n')
201 subseg_new (".bss", get_absolute_expression ());
206 /* Handle .weak. This is a GNU extension. */
209 obj_coff_weak (ignore)
210 int ignore ATTRIBUTE_UNUSED;
218 name = input_line_pointer;
219 c = get_symbol_end ();
220 symbolP = symbol_find_or_make (name);
221 *input_line_pointer = c;
224 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
225 S_SET_WEAK (symbolP);
229 S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
231 S_SET_STORAGE_CLASS (symbolP, C_WEAKEXT);
236 input_line_pointer++;
238 if (*input_line_pointer == '\n')
244 demand_empty_rest_of_line ();
249 static void SA_SET_SYM_TAGNDX PARAMS ((symbolS *, symbolS *));
251 #define GET_FILENAME_STRING(X) \
252 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
256 fetch_coff_debug_section ()
258 static segT debug_section;
262 s = bfd_make_debug_symbol (stdoutput, (char *) 0, 0);
264 debug_section = s->section;
266 return debug_section;
270 SA_SET_SYM_ENDNDX (sym, val)
274 combined_entry_type *entry, *p;
276 entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
277 p = coffsymbol (symbol_get_bfdsym (val))->native;
278 entry->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p = p;
283 SA_SET_SYM_TAGNDX (sym, val)
287 combined_entry_type *entry, *p;
289 entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
290 p = coffsymbol (symbol_get_bfdsym (val))->native;
291 entry->u.auxent.x_sym.x_tagndx.p = p;
296 S_GET_DATA_TYPE (sym)
299 return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type;
303 S_SET_DATA_TYPE (sym, val)
307 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type = val;
312 S_GET_STORAGE_CLASS (sym)
315 return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass;
319 S_SET_STORAGE_CLASS (sym, val)
323 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass = val;
327 /* Merge a debug symbol containing debug information into a normal symbol. */
330 c_symbol_merge (debug, normal)
334 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
335 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
337 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
339 /* take the most we have */
340 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
343 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
345 /* Move all the auxiliary information. */
346 memcpy (SYM_AUXINFO (normal), SYM_AUXINFO (debug),
347 (S_GET_NUMBER_AUXILIARY (debug)
348 * sizeof (*SYM_AUXINFO (debug))));
351 /* Move the debug flags. */
352 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
356 c_dot_file_symbol (filename)
357 const char *filename;
361 /* BFD converts filename to a .file symbol with an aux entry. It
362 also handles chaining. */
363 symbolP = symbol_new (filename, bfd_abs_section_ptr, 0, &zero_address_frag);
365 S_SET_STORAGE_CLASS (symbolP, C_FILE);
366 S_SET_NUMBER_AUXILIARY (symbolP, 1);
368 symbol_get_bfdsym (symbolP)->flags = BSF_DEBUGGING;
375 listing_source_file (filename);
380 /* Make sure that the symbol is first on the symbol chain */
381 if (symbol_rootP != symbolP)
383 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
384 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
385 } /* if not first on the list */
388 /* Line number handling */
391 struct line_no *next;
398 /* Symbol of last function, which we should hang line#s off of. */
399 static symbolS *line_fsym;
401 #define in_function() (line_fsym != 0)
402 #define clear_function() (line_fsym = 0)
403 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
407 coff_obj_symbol_new_hook (symbolP)
410 long sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type);
411 char * s = (char *) xmalloc (sz);
414 coffsymbol (symbol_get_bfdsym (symbolP))->native = (combined_entry_type *) s;
416 S_SET_DATA_TYPE (symbolP, T_NULL);
417 S_SET_STORAGE_CLASS (symbolP, 0);
418 S_SET_NUMBER_AUXILIARY (symbolP, 0);
420 if (S_IS_STRING (symbolP))
421 SF_SET_STRING (symbolP);
423 if (S_IS_LOCAL (symbolP))
424 SF_SET_LOCAL (symbolP);
429 * Handle .ln directives.
432 static symbolS *current_lineno_sym;
433 static struct line_no *line_nos;
434 /* @@ Blindly assume all .ln directives will be in the .text section... */
438 add_lineno (frag, offset, num)
443 struct line_no *new_line =
444 (struct line_no *) xmalloc (sizeof (struct line_no));
445 if (!current_lineno_sym)
451 /* The native aix assembler accepts negative line number */
455 /* Zero is used as an end marker in the file. */
456 as_warn (_("Line numbers must be positive integers\n"));
459 #endif /* OBJ_XCOFF */
460 new_line->next = line_nos;
461 new_line->frag = frag;
462 new_line->l.line_number = num;
463 new_line->l.u.offset = offset;
469 coff_add_linesym (sym)
474 coffsymbol (symbol_get_bfdsym (current_lineno_sym))->lineno =
479 current_lineno_sym = sym;
483 obj_coff_ln (appline)
488 if (! appline && def_symbol_in_progress != NULL)
490 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
491 demand_empty_rest_of_line ();
495 l = get_absolute_expression ();
497 /* If there is no lineno symbol, treat a .ln
498 directive as if it were a .appline directive. */
499 if (appline || current_lineno_sym == NULL)
500 new_logical_line ((char *) NULL, l - 1);
502 add_lineno (frag_now, frag_now_fix (), l);
511 l += coff_line_base - 1;
512 listing_source_line (l);
517 demand_empty_rest_of_line ();
520 /* .loc is essentially the same as .ln; parse it for assembler
524 obj_coff_loc (ignore)
525 int ignore ATTRIBUTE_UNUSED;
529 /* FIXME: Why do we need this check? We need it for ECOFF, but why
530 do we need it for COFF? */
531 if (now_seg != text_section)
533 as_warn (_(".loc outside of .text"));
534 demand_empty_rest_of_line ();
538 if (def_symbol_in_progress != NULL)
540 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
541 demand_empty_rest_of_line ();
545 /* Skip the file number. */
547 get_absolute_expression ();
550 lineno = get_absolute_expression ();
558 lineno += coff_line_base - 1;
559 listing_source_line (lineno);
564 demand_empty_rest_of_line ();
566 add_lineno (frag_now, frag_now_fix (), lineno);
569 /* Handle the .ident pseudo-op. */
572 obj_coff_ident (ignore)
573 int ignore ATTRIBUTE_UNUSED;
575 segT current_seg = now_seg;
576 subsegT current_subseg = now_subseg;
582 /* We could put it in .comment, but that creates an extra section
583 that shouldn't be loaded into memory, which requires linker
584 changes... For now, until proven otherwise, use .rdata. */
585 sec = subseg_new (".rdata$zzz", 0);
586 bfd_set_section_flags (stdoutput, sec,
587 ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA)
588 & bfd_applicable_section_flags (stdoutput)));
591 subseg_new (".comment", 0);
595 subseg_set (current_seg, current_subseg);
601 * Handle .def directives.
603 * One might ask : why can't we symbol_new if the symbol does not
604 * already exist and fill it with debug information. Because of
605 * the C_EFCN special symbol. It would clobber the value of the
606 * function symbol before we have a chance to notice that it is
607 * a C_EFCN. And a second reason is that the code is more clear this
608 * way. (at least I think it is :-).
612 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
613 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
614 *input_line_pointer == '\t') \
615 input_line_pointer++;
619 int what ATTRIBUTE_UNUSED;
621 char name_end; /* Char after the end of name */
622 char *symbol_name; /* Name of the debug symbol */
623 char *symbol_name_copy; /* Temporary copy of the name */
624 unsigned int symbol_name_length;
626 if (def_symbol_in_progress != NULL)
628 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
629 demand_empty_rest_of_line ();
631 } /* if not inside .def/.endef */
635 symbol_name = input_line_pointer;
636 #ifdef STRIP_UNDERSCORE
637 if (symbol_name[0] == '_' && symbol_name[1] != 0)
639 #endif /* STRIP_UNDERSCORE */
641 name_end = get_symbol_end ();
642 symbol_name_length = strlen (symbol_name);
643 symbol_name_copy = xmalloc (symbol_name_length + 1);
644 strcpy (symbol_name_copy, symbol_name);
645 #ifdef tc_canonicalize_symbol_name
646 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
649 /* Initialize the new symbol */
650 def_symbol_in_progress = symbol_make (symbol_name_copy);
651 symbol_set_frag (def_symbol_in_progress, &zero_address_frag);
652 S_SET_VALUE (def_symbol_in_progress, 0);
654 if (S_IS_STRING (def_symbol_in_progress))
655 SF_SET_STRING (def_symbol_in_progress);
657 *input_line_pointer = name_end;
659 demand_empty_rest_of_line ();
662 unsigned int dim_index;
665 obj_coff_endef (ignore)
666 int ignore ATTRIBUTE_UNUSED;
668 symbolS *symbolP = NULL;
670 /* DIM BUG FIX sac@cygnus.com */
672 if (def_symbol_in_progress == NULL)
674 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
675 demand_empty_rest_of_line ();
677 } /* if not inside .def/.endef */
679 /* Set the section number according to storage class. */
680 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
685 SF_SET_TAG (def_symbol_in_progress);
686 /* intentional fallthrough */
689 SF_SET_DEBUG (def_symbol_in_progress);
690 S_SET_SEGMENT (def_symbol_in_progress, fetch_coff_debug_section ());
694 SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */
695 /* intentional fallthrough */
697 SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */
698 /* intentional fallthrough */
702 S_SET_SEGMENT (def_symbol_in_progress, text_section);
704 name = S_GET_NAME (def_symbol_in_progress);
705 if (name[0] == '.' && name[2] == 'f' && name[3] == '\0')
711 if (! in_function ())
712 as_warn (_("`%s' symbol without preceding function"), name);
713 /* Will need relocating. */
714 SF_SET_PROCESS (def_symbol_in_progress);
720 /* The MS compilers output the actual endline, not the
721 function-relative one... we want to match without
722 changing the assembler input. */
723 SA_SET_SYM_LNNO (def_symbol_in_progress,
724 (SA_GET_SYM_LNNO (def_symbol_in_progress)
735 #endif /* C_AUTOARG */
742 /* According to the COFF documentation:
744 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
746 A special section number (-2) marks symbolic debugging symbols,
747 including structure/union/enumeration tag names, typedefs, and
748 the name of the file. A section number of -1 indicates that the
749 symbol has a value but is not relocatable. Examples of
750 absolute-valued symbols include automatic and register variables,
751 function arguments, and .eos symbols.
753 But from Ian Lance Taylor:
755 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
757 the actual tools all marked them as section -1. So the GNU COFF
758 assembler follows historical COFF assemblers.
760 However, it causes problems for djgpp
762 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
764 By defining STRICTCOFF, a COFF port can make the assembler to
765 follow the documented behavior. */
772 SF_SET_DEBUG (def_symbol_in_progress);
773 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
781 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
792 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
799 as_warn (_("unexpected storage class %d"),
800 S_GET_STORAGE_CLASS (def_symbol_in_progress));
802 } /* switch on storage class */
804 /* Now that we have built a debug symbol, try to find if we should
805 merge with an existing symbol or not. If a symbol is C_EFCN or
806 absolute_section or untagged SEG_DEBUG it never merges. We also
807 don't merge labels, which are in a different namespace, nor
808 symbols which have not yet been defined since they are typically
809 unique, nor do we merge tags with non-tags. */
811 /* Two cases for functions. Either debug followed by definition or
812 definition followed by debug. For definition first, we will
813 merge the debug symbol into the definition. For debug first, the
814 lineno entry MUST point to the definition function or else it
815 will point off into space when obj_crawl_symbol_chain() merges
816 the debug symbol into the real symbol. Therefor, let's presume
817 the debug symbol is a real function reference. */
819 /* FIXME-SOON If for some reason the definition label/symbol is
820 never seen, this will probably leave an undefined symbol at link
823 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
824 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
825 || (!strcmp (bfd_get_section_name (stdoutput,
826 S_GET_SEGMENT (def_symbol_in_progress)),
828 && !SF_GET_TAG (def_symbol_in_progress))
829 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
830 || ! symbol_constant_p (def_symbol_in_progress)
831 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
832 DO_NOT_STRIP)) == NULL
833 || SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP))
835 /* If it already is at the end of the symbol list, do nothing */
836 if (def_symbol_in_progress != symbol_lastP)
838 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
839 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
845 /* This symbol already exists, merge the newly created symbol
846 into the old one. This is not mandatory. The linker can
847 handle duplicate symbols correctly. But I guess that it save
848 a *lot* of space if the assembly file defines a lot of
851 /* The debug entry (def_symbol_in_progress) is merged into the
852 previous definition. */
854 c_symbol_merge (def_symbol_in_progress, symbolP);
855 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
857 def_symbol_in_progress = symbolP;
859 if (SF_GET_FUNCTION (def_symbol_in_progress)
860 || SF_GET_TAG (def_symbol_in_progress)
861 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
863 /* For functions, and tags, and static symbols, the symbol
864 *must* be where the debug symbol appears. Move the
865 existing symbol to the current place. */
866 /* If it already is at the end of the symbol list, do nothing */
867 if (def_symbol_in_progress != symbol_lastP)
869 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
870 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, &symbol_lastP);
875 if (SF_GET_TAG (def_symbol_in_progress))
879 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
881 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
882 tag_insert (S_GET_NAME (def_symbol_in_progress),
883 def_symbol_in_progress);
886 if (SF_GET_FUNCTION (def_symbol_in_progress))
888 know (sizeof (def_symbol_in_progress) <= sizeof (long));
889 set_function (def_symbol_in_progress);
890 SF_SET_PROCESS (def_symbol_in_progress);
894 /* That is, if this is the first time we've seen the
896 symbol_table_insert (def_symbol_in_progress);
897 } /* definition follows debug */
898 } /* Create the line number entry pointing to the function being defined */
900 def_symbol_in_progress = NULL;
901 demand_empty_rest_of_line ();
905 obj_coff_dim (ignore)
906 int ignore ATTRIBUTE_UNUSED;
910 if (def_symbol_in_progress == NULL)
912 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
913 demand_empty_rest_of_line ();
915 } /* if not inside .def/.endef */
917 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
919 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
922 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
923 get_absolute_expression ());
925 switch (*input_line_pointer)
928 input_line_pointer++;
932 as_warn (_("badly formed .dim directive ignored"));
933 /* intentional fallthrough */
941 demand_empty_rest_of_line ();
945 obj_coff_line (ignore)
946 int ignore ATTRIBUTE_UNUSED;
950 if (def_symbol_in_progress == NULL)
952 /* Probably stabs-style line? */
957 this_base = get_absolute_expression ();
958 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress)))
959 coff_line_base = this_base;
961 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
962 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
964 demand_empty_rest_of_line ();
967 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress)) == 0)
972 listing_source_line ((unsigned int) this_base);
978 obj_coff_size (ignore)
979 int ignore ATTRIBUTE_UNUSED;
981 if (def_symbol_in_progress == NULL)
983 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
984 demand_empty_rest_of_line ();
986 } /* if not inside .def/.endef */
988 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
989 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
990 demand_empty_rest_of_line ();
994 obj_coff_scl (ignore)
995 int ignore ATTRIBUTE_UNUSED;
997 if (def_symbol_in_progress == NULL)
999 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
1000 demand_empty_rest_of_line ();
1002 } /* if not inside .def/.endef */
1004 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
1005 demand_empty_rest_of_line ();
1009 obj_coff_tag (ignore)
1010 int ignore ATTRIBUTE_UNUSED;
1015 if (def_symbol_in_progress == NULL)
1017 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
1018 demand_empty_rest_of_line ();
1022 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
1023 symbol_name = input_line_pointer;
1024 name_end = get_symbol_end ();
1026 #ifdef tc_canonicalize_symbol_name
1027 symbol_name = tc_canonicalize_symbol_name (symbol_name);
1030 /* Assume that the symbol referred to by .tag is always defined.
1031 This was a bad assumption. I've added find_or_make. xoxorich. */
1032 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
1033 tag_find_or_make (symbol_name));
1034 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
1036 as_warn (_("tag not found for .tag %s"), symbol_name);
1039 SF_SET_TAGGED (def_symbol_in_progress);
1040 *input_line_pointer = name_end;
1042 demand_empty_rest_of_line ();
1046 obj_coff_type (ignore)
1047 int ignore ATTRIBUTE_UNUSED;
1049 if (def_symbol_in_progress == NULL)
1051 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1052 demand_empty_rest_of_line ();
1054 } /* if not inside .def/.endef */
1056 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
1058 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
1059 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
1061 SF_SET_FUNCTION (def_symbol_in_progress);
1062 } /* is a function */
1064 demand_empty_rest_of_line ();
1068 obj_coff_val (ignore)
1069 int ignore ATTRIBUTE_UNUSED;
1071 if (def_symbol_in_progress == NULL)
1073 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1074 demand_empty_rest_of_line ();
1076 } /* if not inside .def/.endef */
1078 if (is_name_beginner (*input_line_pointer))
1080 char *symbol_name = input_line_pointer;
1081 char name_end = get_symbol_end ();
1083 #ifdef tc_canonicalize_symbol_name
1084 symbol_name = tc_canonicalize_symbol_name (symbol_name);
1086 if (!strcmp (symbol_name, "."))
1088 symbol_set_frag (def_symbol_in_progress, frag_now);
1089 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
1090 /* If the .val is != from the .def (e.g. statics) */
1092 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
1096 exp.X_op = O_symbol;
1097 exp.X_add_symbol = symbol_find_or_make (symbol_name);
1098 exp.X_op_symbol = NULL;
1099 exp.X_add_number = 0;
1100 symbol_set_value_expression (def_symbol_in_progress, &exp);
1102 /* If the segment is undefined when the forward reference is
1103 resolved, then copy the segment id from the forward
1105 SF_SET_GET_SEGMENT (def_symbol_in_progress);
1107 /* FIXME: gcc can generate address expressions here in
1108 unusual cases (search for "obscure" in sdbout.c). We
1109 just ignore the offset here, thus generating incorrect
1110 debugging information. We ignore the rest of the line
1113 /* Otherwise, it is the name of a non debug symbol and its value
1114 will be calculated later. */
1115 *input_line_pointer = name_end;
1119 S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ());
1120 } /* if symbol based */
1122 demand_empty_rest_of_line ();
1126 coff_obj_read_begin_hook ()
1128 /* These had better be the same. Usually 18 bytes. */
1130 know (sizeof (SYMENT) == sizeof (AUXENT));
1131 know (SYMESZ == AUXESZ);
1136 symbolS *coff_last_function;
1137 static symbolS *coff_last_bf;
1140 coff_frob_symbol (symp, punt)
1144 static symbolS *last_tagP;
1145 static stack *block_stack;
1146 static symbolS *set_end;
1147 symbolS *next_set_end = NULL;
1149 if (symp == &abs_symbol)
1155 if (current_lineno_sym)
1156 coff_add_linesym ((symbolS *) 0);
1159 block_stack = stack_init (512, sizeof (symbolS*));
1161 if (S_IS_WEAK (symp))
1164 S_SET_STORAGE_CLASS (symp, C_NT_WEAK);
1166 S_SET_STORAGE_CLASS (symp, C_WEAKEXT);
1170 if (!S_IS_DEFINED (symp)
1171 && !S_IS_WEAK (symp)
1172 && S_GET_STORAGE_CLASS (symp) != C_STAT)
1173 S_SET_STORAGE_CLASS (symp, C_EXT);
1175 if (!SF_GET_DEBUG (symp))
1179 if (!SF_GET_LOCAL (symp)
1180 && !SF_GET_STATICS (symp)
1181 && S_GET_STORAGE_CLASS (symp) != C_LABEL
1182 && symbol_constant_p(symp)
1183 && (real = symbol_find_base (S_GET_NAME (symp), DO_NOT_STRIP))
1184 && S_GET_STORAGE_CLASS (real) == C_NULL
1187 c_symbol_merge (symp, real);
1192 if (!S_IS_DEFINED (symp) && !SF_GET_LOCAL (symp))
1194 assert (S_GET_VALUE (symp) == 0);
1195 S_SET_EXTERNAL (symp);
1197 else if (S_GET_STORAGE_CLASS (symp) == C_NULL)
1199 if (S_GET_SEGMENT (symp) == text_section
1200 && symp != seg_info (text_section)->sym)
1201 S_SET_STORAGE_CLASS (symp, C_LABEL);
1203 S_SET_STORAGE_CLASS (symp, C_STAT);
1206 if (SF_GET_PROCESS (symp))
1208 if (S_GET_STORAGE_CLASS (symp) == C_BLOCK)
1210 if (!strcmp (S_GET_NAME (symp), ".bb"))
1211 stack_push (block_stack, (char *) &symp);
1216 begin = *(symbolS **) stack_pop (block_stack);
1218 as_warn (_("mismatched .eb"));
1220 next_set_end = begin;
1224 if (coff_last_function == 0 && SF_GET_FUNCTION (symp))
1226 union internal_auxent *auxp;
1228 coff_last_function = symp;
1229 if (S_GET_NUMBER_AUXILIARY (symp) < 1)
1230 S_SET_NUMBER_AUXILIARY (symp, 1);
1231 auxp = SYM_AUXENT (symp);
1232 memset (auxp->x_sym.x_fcnary.x_ary.x_dimen, 0,
1233 sizeof (auxp->x_sym.x_fcnary.x_ary.x_dimen));
1236 if (S_GET_STORAGE_CLASS (symp) == C_EFCN)
1238 if (coff_last_function == 0)
1239 as_fatal (_("C_EFCN symbol out of scope"));
1240 SA_SET_SYM_FSIZE (coff_last_function,
1241 (long) (S_GET_VALUE (symp)
1242 - S_GET_VALUE (coff_last_function)));
1243 next_set_end = coff_last_function;
1244 coff_last_function = 0;
1248 if (S_IS_EXTERNAL (symp))
1249 S_SET_STORAGE_CLASS (symp, C_EXT);
1250 else if (SF_GET_LOCAL (symp))
1253 if (SF_GET_FUNCTION (symp))
1254 symbol_get_bfdsym (symp)->flags |= BSF_FUNCTION;
1259 /* Double check weak symbols. */
1260 if (S_IS_WEAK (symp) && S_IS_COMMON (symp))
1261 as_bad (_("Symbol `%s' can not be both weak and common"),
1264 if (SF_GET_TAG (symp))
1266 else if (S_GET_STORAGE_CLASS (symp) == C_EOS)
1267 next_set_end = last_tagP;
1270 /* This is pretty horrible, but we have to set *punt correctly in
1271 order to call SA_SET_SYM_ENDNDX correctly. */
1272 if (! symbol_used_in_reloc_p (symp)
1273 && ((symbol_get_bfdsym (symp)->flags & BSF_SECTION_SYM) != 0
1274 || (! S_IS_EXTERNAL (symp)
1275 && ! symbol_get_tc (symp)->output
1276 && S_GET_STORAGE_CLASS (symp) != C_FILE)))
1280 if (set_end != (symbolS *) NULL
1282 && ((symbol_get_bfdsym (symp)->flags & BSF_NOT_AT_END) != 0
1283 || (S_IS_DEFINED (symp)
1284 && ! S_IS_COMMON (symp)
1285 && (! S_IS_EXTERNAL (symp) || SF_GET_FUNCTION (symp)))))
1287 SA_SET_SYM_ENDNDX (set_end, symp);
1291 if (next_set_end != NULL)
1293 if (set_end != NULL)
1294 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1295 S_GET_NAME (set_end));
1296 set_end = next_set_end;
1300 && S_GET_STORAGE_CLASS (symp) == C_FCN
1301 && strcmp (S_GET_NAME (symp), ".bf") == 0)
1303 if (coff_last_bf != NULL)
1304 SA_SET_SYM_ENDNDX (coff_last_bf, symp);
1305 coff_last_bf = symp;
1308 if (coffsymbol (symbol_get_bfdsym (symp))->lineno)
1311 struct line_no *lptr;
1314 lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
1315 for (i = 0; lptr; lptr = lptr->next)
1317 lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
1319 /* We need i entries for line numbers, plus 1 for the first
1320 entry which BFD will override, plus 1 for the last zero
1321 entry (a marker for BFD). */
1322 l = (alent *) xmalloc ((i + 2) * sizeof (alent));
1323 coffsymbol (symbol_get_bfdsym (symp))->lineno = l;
1324 l[i + 1].line_number = 0;
1325 l[i + 1].u.sym = NULL;
1329 lptr->l.u.offset += lptr->frag->fr_address / OCTETS_PER_BYTE;
1337 coff_adjust_section_syms (abfd, sec, x)
1338 bfd *abfd ATTRIBUTE_UNUSED;
1340 PTR x ATTRIBUTE_UNUSED;
1343 segment_info_type *seginfo = seg_info (sec);
1344 int nlnno, nrelocs = 0;
1346 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1347 tc-ppc.c. Do not get confused by it. */
1348 if (seginfo == NULL)
1351 if (!strcmp (sec->name, ".text"))
1352 nlnno = coff_n_line_nos;
1356 /* @@ Hope that none of the fixups expand to more than one reloc
1358 fixS *fixp = seginfo->fix_root;
1361 if (! fixp->fx_done)
1363 fixp = fixp->fx_next;
1366 if (bfd_get_section_size_before_reloc (sec) == 0
1369 && sec != text_section
1370 && sec != data_section
1371 && sec != bss_section)
1373 secsym = section_symbol (sec);
1374 /* This is an estimate; we'll plug in the real value using
1375 SET_SECTION_RELOCS later */
1376 SA_SET_SCN_NRELOC (secsym, nrelocs);
1377 SA_SET_SCN_NLINNO (secsym, nlnno);
1381 coff_frob_file_after_relocs ()
1383 bfd_map_over_sections (stdoutput, coff_adjust_section_syms, (char*) 0);
1387 * implement the .section pseudo op:
1388 * .section name {, "flags"}
1390 * | +--- optional flags: 'b' for bss
1392 * +-- section name 'l' for lib
1396 * 'd' (apparently m88k for data)
1398 * 'r' for read-only data
1399 * 's' for shared data (PE)
1400 * But if the argument is not a quoted string, treat it as a
1401 * subsegment number.
1405 obj_coff_section (ignore)
1406 int ignore ATTRIBUTE_UNUSED;
1408 /* Strip out the section name */
1413 flagword flags, oldflags;
1424 section_name = input_line_pointer;
1425 c = get_symbol_end ();
1427 name = xmalloc (input_line_pointer - section_name + 1);
1428 strcpy (name, section_name);
1430 *input_line_pointer = c;
1435 flags = SEC_NO_FLAGS;
1437 if (*input_line_pointer == ',')
1439 ++input_line_pointer;
1441 if (*input_line_pointer != '"')
1442 exp = get_absolute_expression ();
1445 ++input_line_pointer;
1446 while (*input_line_pointer != '"'
1447 && ! is_end_of_line[(unsigned char) *input_line_pointer])
1449 switch (*input_line_pointer)
1451 case 'b': flags |= SEC_ALLOC; flags &=~ SEC_LOAD; break;
1452 case 'n': flags &=~ SEC_LOAD; flags |= SEC_NEVER_LOAD; break;
1453 case 'd': flags |= SEC_DATA | SEC_LOAD; /* fall through */
1454 case 'w': flags &=~ SEC_READONLY; break;
1455 case 'x': flags |= SEC_CODE | SEC_LOAD; break;
1456 case 'r': flags |= SEC_READONLY; break;
1457 case 's': flags |= SEC_SHARED; break;
1459 case 'i': /* STYP_INFO */
1460 case 'l': /* STYP_LIB */
1461 case 'o': /* STYP_OVER */
1462 as_warn (_("unsupported section attribute '%c'"),
1463 *input_line_pointer);
1467 as_warn(_("unknown section attribute '%c'"),
1468 *input_line_pointer);
1471 ++input_line_pointer;
1473 if (*input_line_pointer == '"')
1474 ++input_line_pointer;
1478 sec = subseg_new (name, (subsegT) exp);
1480 oldflags = bfd_get_section_flags (stdoutput, sec);
1481 if (oldflags == SEC_NO_FLAGS)
1483 /* Set section flags for a new section just created by subseg_new.
1484 Provide a default if no flags were parsed. */
1485 if (flags == SEC_NO_FLAGS)
1486 flags = TC_COFF_SECTION_DEFAULT_ATTRIBUTES;
1488 #ifdef COFF_LONG_SECTION_NAMES
1489 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1490 sections so adjust_reloc_syms in write.c will correctly handle
1491 relocs which refer to non-local symbols in these sections. */
1492 if (strncmp (name, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1493 flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1496 if (! bfd_set_section_flags (stdoutput, sec, flags))
1497 as_warn (_("error setting flags for \"%s\": %s"),
1498 bfd_section_name (stdoutput, sec),
1499 bfd_errmsg (bfd_get_error ()));
1501 else if (flags != SEC_NO_FLAGS)
1503 /* This section's attributes have already been set. Warn if the
1504 attributes don't match. */
1505 flagword matchflags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
1506 | SEC_DATA | SEC_SHARED | SEC_NEVER_LOAD);
1507 if ((flags ^ oldflags) & matchflags)
1508 as_warn (_("Ignoring changed section attributes for %s"), name);
1511 demand_empty_rest_of_line ();
1515 coff_adjust_symtab ()
1517 if (symbol_rootP == NULL
1518 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
1519 c_dot_file_symbol ("fake");
1523 coff_frob_section (sec)
1529 bfd_vma size, n_entries, mask;
1530 bfd_vma align_power = (bfd_vma)sec->alignment_power + OCTETS_PER_BYTE_POWER;
1532 /* The COFF back end in BFD requires that all section sizes be
1533 rounded up to multiples of the corresponding section alignments,
1534 supposedly because standard COFF has no other way of encoding alignment
1535 for sections. If your COFF flavor has a different way of encoding
1536 section alignment, then skip this step, as TICOFF does. */
1537 size = bfd_get_section_size_before_reloc (sec);
1538 mask = ((bfd_vma) 1 << align_power) - 1;
1539 #if !defined(TICOFF)
1545 new_size = (size + mask) & ~mask;
1546 bfd_set_section_size (stdoutput, sec, new_size);
1548 /* If the size had to be rounded up, add some padding in
1549 the last non-empty frag. */
1550 fragp = seg_info (sec)->frchainP->frch_root;
1551 last = seg_info (sec)->frchainP->frch_last;
1552 while (fragp->fr_next != last)
1553 fragp = fragp->fr_next;
1554 last->fr_address = size;
1555 fragp->fr_offset += new_size - size;
1559 /* If the section size is non-zero, the section symbol needs an aux
1560 entry associated with it, indicating the size. We don't know
1561 all the values yet; coff_frob_symbol will fill them in later. */
1564 || sec == text_section
1565 || sec == data_section
1566 || sec == bss_section)
1569 symbolS *secsym = section_symbol (sec);
1571 S_SET_STORAGE_CLASS (secsym, C_STAT);
1572 S_SET_NUMBER_AUXILIARY (secsym, 1);
1573 SF_SET_STATICS (secsym);
1574 SA_SET_SCN_SCNLEN (secsym, size);
1577 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1578 #ifndef STAB_SECTION_NAME
1579 #define STAB_SECTION_NAME ".stab"
1581 #ifndef STAB_STRING_SECTION_NAME
1582 #define STAB_STRING_SECTION_NAME ".stabstr"
1584 if (strcmp (STAB_STRING_SECTION_NAME, sec->name))
1588 sec = subseg_get (STAB_SECTION_NAME, 0);
1589 /* size is already rounded up, since other section will be listed first */
1590 size = bfd_get_section_size_before_reloc (strsec);
1592 n_entries = bfd_get_section_size_before_reloc (sec) / 12 - 1;
1594 /* Find first non-empty frag. It should be large enough. */
1595 fragp = seg_info (sec)->frchainP->frch_root;
1596 while (fragp && fragp->fr_fix == 0)
1597 fragp = fragp->fr_next;
1598 assert (fragp != 0 && fragp->fr_fix >= 12);
1600 /* Store the values. */
1601 p = fragp->fr_literal;
1602 bfd_h_put_16 (stdoutput, n_entries, (bfd_byte *) p + 6);
1603 bfd_h_put_32 (stdoutput, size, (bfd_byte *) p + 8);
1607 obj_coff_init_stab_section (seg)
1613 unsigned int stroff;
1615 /* Make space for this first symbol. */
1619 as_where (&file, (unsigned int *) NULL);
1620 stabstr_name = (char *) alloca (strlen (seg->name) + 4);
1621 strcpy (stabstr_name, seg->name);
1622 strcat (stabstr_name, "str");
1623 stroff = get_stab_string_offset (file, stabstr_name);
1625 md_number_to_chars (p, stroff, 4);
1634 return ((s == NULL) ? "(NULL)" : S_GET_NAME (s));
1642 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
1644 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1645 (unsigned long) symbolP,
1646 S_GET_NAME(symbolP),
1647 (long) S_GET_DATA_TYPE(symbolP),
1648 S_GET_STORAGE_CLASS(symbolP),
1649 (int) S_GET_SEGMENT(symbolP));
1655 #else /* not BFD_ASSEMBLER */
1658 /* This is needed because we include internal bfd things. */
1662 #include "libcoff.h"
1665 #include "coff/pe.h"
1668 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1669 that we can stick sections together without causing trouble. */
1671 #define NOP_OPCODE 0x00
1674 /* The zeroes if symbol name is longer than 8 chars */
1675 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1677 #define MIN(a,b) ((a) < (b)? (a) : (b))
1679 /* This vector is used to turn a gas internal segment number into a
1680 section number suitable for insertion into a coff symbol table.
1681 This must correspond to seg_info_off_by_4. */
1683 const short seg_N_TYPE[] =
1684 { /* in: segT out: N_TYPE bits */
1686 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1687 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1688 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1689 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1690 C_UNDEF_SECTION, /* SEG_UNKNOWN */
1691 C_UNDEF_SECTION, /* SEG_GOOF */
1692 C_UNDEF_SECTION, /* SEG_EXPR */
1693 C_DEBUG_SECTION, /* SEG_DEBUG */
1694 C_NTV_SECTION, /* SEG_NTV */
1695 C_PTV_SECTION, /* SEG_PTV */
1696 C_REGISTER_SECTION, /* SEG_REGISTER */
1699 int function_lineoff = -1; /* Offset in line#s where the last function
1700 started (the odd entry for line #0) */
1702 /* structure used to keep the filenames which
1703 are too long around so that we can stick them
1704 into the string table */
1705 struct filename_list
1708 struct filename_list *next;
1711 static struct filename_list *filename_list_head;
1712 static struct filename_list *filename_list_tail;
1714 static symbolS *last_line_symbol;
1716 /* Add 4 to the real value to get the index and compensate the
1717 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1718 section number into a segment number
1720 static symbolS *previous_file_symbol;
1721 void c_symbol_merge ();
1722 static int line_base;
1724 symbolS *c_section_symbol ();
1727 static void fixup_segment PARAMS ((segment_info_type *segP,
1728 segT this_segment_type));
1730 static void fixup_mdeps PARAMS ((fragS *,
1734 static void fill_section PARAMS ((bfd * abfd,
1738 static int c_line_new PARAMS ((symbolS * symbol, long paddr,
1742 static void w_symbols PARAMS ((bfd * abfd, char *where,
1743 symbolS * symbol_rootP));
1745 static void adjust_stab_section PARAMS ((bfd *abfd, segT seg));
1747 static void obj_coff_lcomm PARAMS ((int));
1748 static void obj_coff_text PARAMS ((int));
1749 static void obj_coff_data PARAMS ((int));
1750 void obj_coff_section PARAMS ((int));
1752 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1754 This array maps a COFF section number into a gas section number.
1755 Because COFF uses negative section numbers, you must add 4 to the
1756 COFF section number when indexing into this array; this is done via
1757 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1760 static const segT seg_info_off_by_4[] =
1767 SEG_E0, SEG_E1, SEG_E2, SEG_E3, SEG_E4,
1768 SEG_E5, SEG_E6, SEG_E7, SEG_E8, SEG_E9,
1769 SEG_E10, SEG_E11, SEG_E12, SEG_E13, SEG_E14,
1770 SEG_E15, SEG_E16, SEG_E17, SEG_E18, SEG_E19,
1771 SEG_E20, SEG_E21, SEG_E22, SEG_E23, SEG_E24,
1772 SEG_E25, SEG_E26, SEG_E27, SEG_E28, SEG_E29,
1773 SEG_E30, SEG_E31, SEG_E32, SEG_E33, SEG_E34,
1774 SEG_E35, SEG_E36, SEG_E37, SEG_E38, SEG_E39,
1787 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1789 static relax_addressT
1790 relax_align (address, alignment)
1791 relax_addressT address;
1794 relax_addressT mask;
1795 relax_addressT new_address;
1797 mask = ~((~0) << alignment);
1798 new_address = (address + mask) & (~mask);
1799 return (new_address - address);
1806 return SEG_INFO_FROM_SECTION_NUMBER (x->sy_symbol.ost_entry.n_scnum);
1809 /* calculate the size of the frag chain and fill in the section header
1810 to contain all of it, also fill in the addr of the sections */
1812 size_section (abfd, idx)
1813 bfd *abfd ATTRIBUTE_UNUSED;
1817 unsigned int size = 0;
1818 fragS *frag = segment_info[idx].frchainP->frch_root;
1821 size = frag->fr_address;
1822 if (frag->fr_address != size)
1824 fprintf (stderr, _("Out of step\n"));
1825 size = frag->fr_address;
1828 switch (frag->fr_type)
1830 #ifdef TC_COFF_SIZEMACHDEP
1831 case rs_machine_dependent:
1832 size += TC_COFF_SIZEMACHDEP (frag);
1838 size += frag->fr_fix;
1839 size += frag->fr_offset * frag->fr_var;
1847 size += frag->fr_fix;
1848 off = relax_align (size, frag->fr_offset);
1849 if (frag->fr_subtype != 0 && off > frag->fr_subtype)
1855 BAD_CASE (frag->fr_type);
1858 frag = frag->fr_next;
1860 segment_info[idx].scnhdr.s_size = size;
1865 count_entries_in_chain (idx)
1868 unsigned int nrelocs;
1871 /* Count the relocations */
1872 fixup_ptr = segment_info[idx].fix_root;
1874 while (fixup_ptr != (fixS *) NULL)
1876 if (fixup_ptr->fx_done == 0 && TC_COUNT_RELOC (fixup_ptr))
1879 if (fixup_ptr->fx_r_type == RELOC_CONSTH)
1888 fixup_ptr = fixup_ptr->fx_next;
1895 static int compare_external_relocs PARAMS ((const PTR, const PTR));
1897 /* AUX's ld expects relocations to be sorted */
1899 compare_external_relocs (x, y)
1903 struct external_reloc *a = (struct external_reloc *) x;
1904 struct external_reloc *b = (struct external_reloc *) y;
1905 bfd_vma aadr = bfd_getb32 (a->r_vaddr);
1906 bfd_vma badr = bfd_getb32 (b->r_vaddr);
1907 return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
1912 /* output all the relocations for a section */
1914 do_relocs_for (abfd, h, file_cursor)
1917 unsigned long *file_cursor;
1919 unsigned int nrelocs;
1921 unsigned long reloc_start = *file_cursor;
1923 for (idx = SEG_E0; idx < SEG_LAST; idx++)
1925 if (segment_info[idx].scnhdr.s_name[0])
1927 struct external_reloc *ext_ptr;
1928 struct external_reloc *external_reloc_vec;
1929 unsigned int external_reloc_size;
1930 unsigned int base = segment_info[idx].scnhdr.s_paddr;
1931 fixS *fix_ptr = segment_info[idx].fix_root;
1932 nrelocs = count_entries_in_chain (idx);
1935 /* Bypass this stuff if no relocs. This also incidentally
1936 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1938 external_reloc_size = nrelocs * RELSZ;
1939 external_reloc_vec =
1940 (struct external_reloc *) malloc (external_reloc_size);
1942 ext_ptr = external_reloc_vec;
1944 /* Fill in the internal coff style reloc struct from the
1945 internal fix list. */
1948 struct internal_reloc intr;
1950 /* Only output some of the relocations */
1951 if (fix_ptr->fx_done == 0 && TC_COUNT_RELOC (fix_ptr))
1953 #ifdef TC_RELOC_MANGLE
1954 TC_RELOC_MANGLE (&segment_info[idx], fix_ptr, &intr,
1959 symbolS *symbol_ptr = fix_ptr->fx_addsy;
1961 intr.r_type = TC_COFF_FIX2RTYPE (fix_ptr);
1963 base + fix_ptr->fx_frag->fr_address + fix_ptr->fx_where;
1965 #ifdef TC_KEEP_FX_OFFSET
1966 intr.r_offset = fix_ptr->fx_offset;
1971 while (symbol_ptr->sy_value.X_op == O_symbol
1972 && (! S_IS_DEFINED (symbol_ptr)
1973 || S_IS_COMMON (symbol_ptr)))
1977 /* We must avoid looping, as that can occur
1978 with a badly written program. */
1979 n = symbol_ptr->sy_value.X_add_symbol;
1980 if (n == symbol_ptr)
1985 /* Turn the segment of the symbol into an offset. */
1988 resolve_symbol_value (symbol_ptr);
1989 if (! symbol_ptr->sy_resolved)
1994 if (expr_symbol_where (symbol_ptr, &file, &line))
1995 as_bad_where (file, line,
1996 _("unresolved relocation"));
1998 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1999 S_GET_NAME (symbol_ptr));
2001 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
2004 intr.r_symndx = dot->sy_number;
2008 intr.r_symndx = symbol_ptr->sy_number;
2018 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
2021 #if defined(TC_A29K)
2023 /* The 29k has a special kludge for the high 16 bit
2024 reloc. Two relocations are emited, R_IHIHALF,
2025 and R_IHCONST. The second one doesn't contain a
2026 symbol, but uses the value for offset. */
2028 if (intr.r_type == R_IHIHALF)
2030 /* now emit the second bit */
2031 intr.r_type = R_IHCONST;
2032 intr.r_symndx = fix_ptr->fx_addnumber;
2033 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
2039 fix_ptr = fix_ptr->fx_next;
2043 /* Sort the reloc table */
2044 qsort ((PTR) external_reloc_vec, nrelocs,
2045 sizeof (struct external_reloc), compare_external_relocs);
2048 /* Write out the reloc table */
2049 bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size,
2051 free (external_reloc_vec);
2053 /* Fill in section header info. */
2054 segment_info[idx].scnhdr.s_relptr = *file_cursor;
2055 *file_cursor += external_reloc_size;
2056 segment_info[idx].scnhdr.s_nreloc = nrelocs;
2061 segment_info[idx].scnhdr.s_relptr = 0;
2065 /* Set relocation_size field in file headers */
2066 H_SET_RELOCATION_SIZE (h, *file_cursor - reloc_start, 0);
2069 /* run through a frag chain and write out the data to go with it, fill
2070 in the scnhdrs with the info on the file postions
2073 fill_section (abfd, h, file_cursor)
2075 object_headers *h ATTRIBUTE_UNUSED;
2076 unsigned long *file_cursor;
2080 unsigned int paddr = 0;
2082 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
2084 unsigned int offset = 0;
2085 struct internal_scnhdr *s = &(segment_info[i].scnhdr);
2091 fragS *frag = segment_info[i].frchainP->frch_root;
2092 char *buffer = NULL;
2098 buffer = xmalloc (s->s_size);
2099 s->s_scnptr = *file_cursor;
2101 know (s->s_paddr == paddr);
2103 if (strcmp (s->s_name, ".text") == 0)
2104 s->s_flags |= STYP_TEXT;
2105 else if (strcmp (s->s_name, ".data") == 0)
2106 s->s_flags |= STYP_DATA;
2107 else if (strcmp (s->s_name, ".bss") == 0)
2110 s->s_flags |= STYP_BSS;
2112 /* @@ Should make the i386 and a29k coff targets define
2113 COFF_NOLOAD_PROBLEM, and have only one test here. */
2116 #ifndef COFF_NOLOAD_PROBLEM
2117 /* Apparently the SVR3 linker (and exec syscall) and UDI
2118 mondfe progrem are confused by noload sections. */
2119 s->s_flags |= STYP_NOLOAD;
2124 else if (strcmp (s->s_name, ".lit") == 0)
2125 s->s_flags = STYP_LIT | STYP_TEXT;
2126 else if (strcmp (s->s_name, ".init") == 0)
2127 s->s_flags |= STYP_TEXT;
2128 else if (strcmp (s->s_name, ".fini") == 0)
2129 s->s_flags |= STYP_TEXT;
2130 else if (strncmp (s->s_name, ".comment", 8) == 0)
2131 s->s_flags |= STYP_INFO;
2135 unsigned int fill_size;
2136 switch (frag->fr_type)
2138 case rs_machine_dependent:
2141 memcpy (buffer + frag->fr_address,
2143 (unsigned int) frag->fr_fix);
2144 offset += frag->fr_fix;
2156 memcpy (buffer + frag->fr_address,
2158 (unsigned int) frag->fr_fix);
2159 offset += frag->fr_fix;
2162 fill_size = frag->fr_var;
2163 if (fill_size && frag->fr_offset > 0)
2166 unsigned int off = frag->fr_fix;
2167 for (count = frag->fr_offset; count; count--)
2169 if (fill_size + frag->fr_address + off <= s->s_size)
2171 memcpy (buffer + frag->fr_address + off,
2172 frag->fr_literal + frag->fr_fix,
2175 offset += fill_size;
2180 case rs_broken_word:
2185 frag = frag->fr_next;
2190 if (s->s_scnptr != 0)
2192 bfd_write (buffer, s->s_size, 1, abfd);
2193 *file_cursor += s->s_size;
2202 /* Coff file generation & utilities */
2205 coff_header_append (abfd, h)
2212 #ifdef COFF_LONG_SECTION_NAMES
2213 unsigned long string_size = 4;
2216 bfd_seek (abfd, 0, 0);
2218 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2219 H_SET_MAGIC_NUMBER (h, COFF_MAGIC);
2220 H_SET_VERSION_STAMP (h, 0);
2221 H_SET_ENTRY_POINT (h, 0);
2222 H_SET_TEXT_START (h, segment_info[SEG_E0].frchainP->frch_root->fr_address);
2223 H_SET_DATA_START (h, segment_info[SEG_E1].frchainP->frch_root->fr_address);
2224 H_SET_SIZEOF_OPTIONAL_HEADER (h, bfd_coff_swap_aouthdr_out(abfd, &h->aouthdr,
2226 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2227 H_SET_SIZEOF_OPTIONAL_HEADER (h, 0);
2228 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2230 i = bfd_coff_swap_filehdr_out (abfd, &h->filehdr, buffer);
2232 bfd_write (buffer, i, 1, abfd);
2233 bfd_write (buffero, H_GET_SIZEOF_OPTIONAL_HEADER (h), 1, abfd);
2235 for (i = SEG_E0; i < SEG_LAST; i++)
2237 if (segment_info[i].scnhdr.s_name[0])
2241 #ifdef COFF_LONG_SECTION_NAMES
2242 /* Support long section names as found in PE. This code
2243 must coordinate with that in write_object_file and
2245 if (strlen (segment_info[i].name) > SCNNMLEN)
2247 memset (segment_info[i].scnhdr.s_name, 0, SCNNMLEN);
2248 sprintf (segment_info[i].scnhdr.s_name, "/%lu", string_size);
2249 string_size += strlen (segment_info[i].name) + 1;
2253 size = bfd_coff_swap_scnhdr_out (abfd,
2254 &(segment_info[i].scnhdr),
2257 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2258 bfd_write (buffer, size, 1, abfd);
2264 symbol_to_chars (abfd, where, symbolP)
2269 unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux;
2273 /* Turn any symbols with register attributes into abs symbols */
2274 if (S_GET_SEGMENT (symbolP) == reg_section)
2276 S_SET_SEGMENT (symbolP, absolute_section);
2278 /* At the same time, relocate all symbols to their output value */
2281 val = (segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_paddr
2282 + S_GET_VALUE (symbolP));
2284 val = S_GET_VALUE (symbolP);
2287 S_SET_VALUE (symbolP, val);
2289 symbolP->sy_symbol.ost_entry.n_value = val;
2291 where += bfd_coff_swap_sym_out (abfd, &symbolP->sy_symbol.ost_entry,
2294 for (i = 0; i < numaux; i++)
2296 where += bfd_coff_swap_aux_out (abfd,
2297 &symbolP->sy_symbol.ost_auxent[i],
2298 S_GET_DATA_TYPE (symbolP),
2299 S_GET_STORAGE_CLASS (symbolP),
2307 coff_obj_symbol_new_hook (symbolP)
2310 char underscore = 0; /* Symbol has leading _ */
2312 /* Effective symbol */
2313 /* Store the pointer in the offset. */
2314 S_SET_ZEROES (symbolP, 0L);
2315 S_SET_DATA_TYPE (symbolP, T_NULL);
2316 S_SET_STORAGE_CLASS (symbolP, 0);
2317 S_SET_NUMBER_AUXILIARY (symbolP, 0);
2318 /* Additional information */
2319 symbolP->sy_symbol.ost_flags = 0;
2320 /* Auxiliary entries */
2321 memset ((char *) &symbolP->sy_symbol.ost_auxent[0], 0, AUXESZ);
2323 if (S_IS_STRING (symbolP))
2324 SF_SET_STRING (symbolP);
2325 if (!underscore && S_IS_LOCAL (symbolP))
2326 SF_SET_LOCAL (symbolP);
2330 * Handle .ln directives.
2334 obj_coff_ln (appline)
2339 if (! appline && def_symbol_in_progress != NULL)
2341 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2342 demand_empty_rest_of_line ();
2344 } /* wrong context */
2346 l = get_absolute_expression ();
2347 c_line_new (0, frag_now_fix (), l, frag_now);
2350 new_logical_line ((char *) NULL, l - 1);
2360 listing_source_line ((unsigned int) l);
2365 demand_empty_rest_of_line ();
2371 * Handle .def directives.
2373 * One might ask : why can't we symbol_new if the symbol does not
2374 * already exist and fill it with debug information. Because of
2375 * the C_EFCN special symbol. It would clobber the value of the
2376 * function symbol before we have a chance to notice that it is
2377 * a C_EFCN. And a second reason is that the code is more clear this
2378 * way. (at least I think it is :-).
2382 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2383 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2384 *input_line_pointer == '\t') \
2385 input_line_pointer++;
2389 int what ATTRIBUTE_UNUSED;
2391 char name_end; /* Char after the end of name */
2392 char *symbol_name; /* Name of the debug symbol */
2393 char *symbol_name_copy; /* Temporary copy of the name */
2394 unsigned int symbol_name_length;
2396 if (def_symbol_in_progress != NULL)
2398 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2399 demand_empty_rest_of_line ();
2401 } /* if not inside .def/.endef */
2403 SKIP_WHITESPACES ();
2405 def_symbol_in_progress = (symbolS *) obstack_alloc (¬es, sizeof (*def_symbol_in_progress));
2406 memset (def_symbol_in_progress, 0, sizeof (*def_symbol_in_progress));
2408 symbol_name = input_line_pointer;
2409 name_end = get_symbol_end ();
2410 symbol_name_length = strlen (symbol_name);
2411 symbol_name_copy = xmalloc (symbol_name_length + 1);
2412 strcpy (symbol_name_copy, symbol_name);
2413 #ifdef tc_canonicalize_symbol_name
2414 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
2417 /* Initialize the new symbol */
2418 #ifdef STRIP_UNDERSCORE
2419 S_SET_NAME (def_symbol_in_progress, (*symbol_name_copy == '_'
2420 ? symbol_name_copy + 1
2421 : symbol_name_copy));
2422 #else /* STRIP_UNDERSCORE */
2423 S_SET_NAME (def_symbol_in_progress, symbol_name_copy);
2424 #endif /* STRIP_UNDERSCORE */
2425 /* free(symbol_name_copy); */
2426 def_symbol_in_progress->sy_name_offset = (unsigned long) ~0;
2427 def_symbol_in_progress->sy_number = ~0;
2428 def_symbol_in_progress->sy_frag = &zero_address_frag;
2429 S_SET_VALUE (def_symbol_in_progress, 0);
2431 if (S_IS_STRING (def_symbol_in_progress))
2432 SF_SET_STRING (def_symbol_in_progress);
2434 *input_line_pointer = name_end;
2436 demand_empty_rest_of_line ();
2439 unsigned int dim_index;
2442 obj_coff_endef (ignore)
2443 int ignore ATTRIBUTE_UNUSED;
2445 symbolS *symbolP = 0;
2446 /* DIM BUG FIX sac@cygnus.com */
2448 if (def_symbol_in_progress == NULL)
2450 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2451 demand_empty_rest_of_line ();
2453 } /* if not inside .def/.endef */
2455 /* Set the section number according to storage class. */
2456 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
2461 SF_SET_TAG (def_symbol_in_progress);
2462 /* intentional fallthrough */
2465 SF_SET_DEBUG (def_symbol_in_progress);
2466 S_SET_SEGMENT (def_symbol_in_progress, SEG_DEBUG);
2470 SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */
2471 /* intentional fallthrough */
2473 SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */
2474 /* intentional fallthrough */
2476 S_SET_SEGMENT (def_symbol_in_progress, SEG_E0);
2478 if (strcmp (S_GET_NAME (def_symbol_in_progress), ".bf") == 0)
2480 if (function_lineoff < 0)
2482 fprintf (stderr, _("`.bf' symbol without preceding function\n"));
2483 } /* missing function symbol */
2484 SA_GET_SYM_LNNOPTR (last_line_symbol) = function_lineoff;
2486 SF_SET_PROCESS (last_line_symbol);
2487 SF_SET_ADJ_LNNOPTR (last_line_symbol);
2488 SF_SET_PROCESS (def_symbol_in_progress);
2489 function_lineoff = -1;
2491 /* Value is always set to . */
2492 def_symbol_in_progress->sy_frag = frag_now;
2493 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2498 #endif /* C_AUTOARG */
2508 SF_SET_DEBUG (def_symbol_in_progress);
2509 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
2519 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2525 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress));
2527 } /* switch on storage class */
2529 /* Now that we have built a debug symbol, try to find if we should
2530 merge with an existing symbol or not. If a symbol is C_EFCN or
2531 absolute_section or untagged SEG_DEBUG it never merges. We also
2532 don't merge labels, which are in a different namespace, nor
2533 symbols which have not yet been defined since they are typically
2534 unique, nor do we merge tags with non-tags. */
2536 /* Two cases for functions. Either debug followed by definition or
2537 definition followed by debug. For definition first, we will
2538 merge the debug symbol into the definition. For debug first, the
2539 lineno entry MUST point to the definition function or else it
2540 will point off into space when crawl_symbols() merges the debug
2541 symbol into the real symbol. Therefor, let's presume the debug
2542 symbol is a real function reference. */
2544 /* FIXME-SOON If for some reason the definition label/symbol is
2545 never seen, this will probably leave an undefined symbol at link
2548 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
2549 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
2550 || (S_GET_SEGMENT (def_symbol_in_progress) == SEG_DEBUG
2551 && !SF_GET_TAG (def_symbol_in_progress))
2552 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
2553 || def_symbol_in_progress->sy_value.X_op != O_constant
2554 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL
2555 || (SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP)))
2557 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
2562 /* This symbol already exists, merge the newly created symbol
2563 into the old one. This is not mandatory. The linker can
2564 handle duplicate symbols correctly. But I guess that it save
2565 a *lot* of space if the assembly file defines a lot of
2568 /* The debug entry (def_symbol_in_progress) is merged into the
2569 previous definition. */
2571 c_symbol_merge (def_symbol_in_progress, symbolP);
2572 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2573 def_symbol_in_progress = symbolP;
2575 if (SF_GET_FUNCTION (def_symbol_in_progress)
2576 || SF_GET_TAG (def_symbol_in_progress)
2577 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
2579 /* For functions, and tags, and static symbols, the symbol
2580 *must* be where the debug symbol appears. Move the
2581 existing symbol to the current place. */
2582 /* If it already is at the end of the symbol list, do nothing */
2583 if (def_symbol_in_progress != symbol_lastP)
2585 symbol_remove (def_symbol_in_progress, &symbol_rootP,
2587 symbol_append (def_symbol_in_progress, symbol_lastP,
2588 &symbol_rootP, &symbol_lastP);
2589 } /* if not already in place */
2591 } /* normal or mergable */
2593 if (SF_GET_TAG (def_symbol_in_progress))
2597 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
2599 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
2600 tag_insert (S_GET_NAME (def_symbol_in_progress),
2601 def_symbol_in_progress);
2604 if (SF_GET_FUNCTION (def_symbol_in_progress))
2606 know (sizeof (def_symbol_in_progress) <= sizeof (long));
2608 = c_line_new (def_symbol_in_progress, 0, 0, &zero_address_frag);
2610 SF_SET_PROCESS (def_symbol_in_progress);
2612 if (symbolP == NULL)
2614 /* That is, if this is the first time we've seen the
2616 symbol_table_insert (def_symbol_in_progress);
2617 } /* definition follows debug */
2618 } /* Create the line number entry pointing to the function being defined */
2620 def_symbol_in_progress = NULL;
2621 demand_empty_rest_of_line ();
2625 obj_coff_dim (ignore)
2626 int ignore ATTRIBUTE_UNUSED;
2630 if (def_symbol_in_progress == NULL)
2632 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2633 demand_empty_rest_of_line ();
2635 } /* if not inside .def/.endef */
2637 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2639 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
2641 SKIP_WHITESPACES ();
2642 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
2643 get_absolute_expression ());
2645 switch (*input_line_pointer)
2648 input_line_pointer++;
2652 as_warn (_("badly formed .dim directive ignored"));
2653 /* intentional fallthrough */
2661 demand_empty_rest_of_line ();
2665 obj_coff_line (ignore)
2666 int ignore ATTRIBUTE_UNUSED;
2671 if (def_symbol_in_progress == NULL)
2677 name = S_GET_NAME (def_symbol_in_progress);
2678 this_base = get_absolute_expression ();
2680 /* Only .bf symbols indicate the use of a new base line number; the
2681 line numbers associated with .ef, .bb, .eb are relative to the
2682 start of the containing function. */
2683 if (!strcmp (".bf", name))
2685 #if 0 /* XXX Can we ever have line numbers going backwards? */
2686 if (this_base > line_base)
2689 line_base = this_base;
2697 listing_source_line ((unsigned int) line_base);
2703 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2704 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
2706 demand_empty_rest_of_line ();
2710 obj_coff_size (ignore)
2711 int ignore ATTRIBUTE_UNUSED;
2713 if (def_symbol_in_progress == NULL)
2715 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2716 demand_empty_rest_of_line ();
2718 } /* if not inside .def/.endef */
2720 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2721 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
2722 demand_empty_rest_of_line ();
2726 obj_coff_scl (ignore)
2727 int ignore ATTRIBUTE_UNUSED;
2729 if (def_symbol_in_progress == NULL)
2731 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2732 demand_empty_rest_of_line ();
2734 } /* if not inside .def/.endef */
2736 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
2737 demand_empty_rest_of_line ();
2741 obj_coff_tag (ignore)
2742 int ignore ATTRIBUTE_UNUSED;
2747 if (def_symbol_in_progress == NULL)
2749 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2750 demand_empty_rest_of_line ();
2754 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2755 symbol_name = input_line_pointer;
2756 name_end = get_symbol_end ();
2757 #ifdef tc_canonicalize_symbol_name
2758 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2761 /* Assume that the symbol referred to by .tag is always defined.
2762 This was a bad assumption. I've added find_or_make. xoxorich. */
2763 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
2764 (long) tag_find_or_make (symbol_name));
2765 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
2767 as_warn (_("tag not found for .tag %s"), symbol_name);
2770 SF_SET_TAGGED (def_symbol_in_progress);
2771 *input_line_pointer = name_end;
2773 demand_empty_rest_of_line ();
2777 obj_coff_type (ignore)
2778 int ignore ATTRIBUTE_UNUSED;
2780 if (def_symbol_in_progress == NULL)
2782 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2783 demand_empty_rest_of_line ();
2785 } /* if not inside .def/.endef */
2787 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
2789 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
2790 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
2792 SF_SET_FUNCTION (def_symbol_in_progress);
2793 } /* is a function */
2795 demand_empty_rest_of_line ();
2799 obj_coff_val (ignore)
2800 int ignore ATTRIBUTE_UNUSED;
2802 if (def_symbol_in_progress == NULL)
2804 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2805 demand_empty_rest_of_line ();
2807 } /* if not inside .def/.endef */
2809 if (is_name_beginner (*input_line_pointer))
2811 char *symbol_name = input_line_pointer;
2812 char name_end = get_symbol_end ();
2814 #ifdef tc_canonicalize_symbol_name
2815 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2818 if (!strcmp (symbol_name, "."))
2820 def_symbol_in_progress->sy_frag = frag_now;
2821 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2822 /* If the .val is != from the .def (e.g. statics) */
2824 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
2826 def_symbol_in_progress->sy_value.X_op = O_symbol;
2827 def_symbol_in_progress->sy_value.X_add_symbol =
2828 symbol_find_or_make (symbol_name);
2829 def_symbol_in_progress->sy_value.X_op_symbol = NULL;
2830 def_symbol_in_progress->sy_value.X_add_number = 0;
2832 /* If the segment is undefined when the forward reference is
2833 resolved, then copy the segment id from the forward
2835 SF_SET_GET_SEGMENT (def_symbol_in_progress);
2837 /* FIXME: gcc can generate address expressions here in
2838 unusual cases (search for "obscure" in sdbout.c). We
2839 just ignore the offset here, thus generating incorrect
2840 debugging information. We ignore the rest of the line
2843 /* Otherwise, it is the name of a non debug symbol and
2844 its value will be calculated later. */
2845 *input_line_pointer = name_end;
2847 /* FIXME: this is to avoid an error message in the
2848 FIXME case mentioned just above. */
2849 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2850 ++input_line_pointer;
2854 S_SET_VALUE (def_symbol_in_progress,
2855 (valueT) get_absolute_expression ());
2856 } /* if symbol based */
2858 demand_empty_rest_of_line ();
2863 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2864 read.c, which then calls this object file format specific routine. */
2867 obj_coff_pe_handle_link_once (type)
2868 enum linkonce_type type;
2870 seg_info (now_seg)->scnhdr.s_flags |= IMAGE_SCN_LNK_COMDAT;
2872 /* We store the type in the seg_info structure, and use it to set up
2873 the auxiliary entry for the section symbol in c_section_symbol. */
2874 seg_info (now_seg)->linkonce = type;
2880 coff_obj_read_begin_hook ()
2882 /* These had better be the same. Usually 18 bytes. */
2884 know (sizeof (SYMENT) == sizeof (AUXENT));
2885 know (SYMESZ == AUXESZ);
2890 /* This function runs through the symbol table and puts all the
2891 externals onto another chain */
2893 /* The chain of globals. */
2894 symbolS *symbol_globalP;
2895 symbolS *symbol_global_lastP;
2897 /* The chain of externals */
2898 symbolS *symbol_externP;
2899 symbolS *symbol_extern_lastP;
2902 symbolS *last_functionP;
2903 static symbolS *last_bfP;
2910 unsigned int symbol_number = 0;
2911 unsigned int last_file_symno = 0;
2913 struct filename_list *filename_list_scan = filename_list_head;
2915 for (symbolP = symbol_rootP;
2917 symbolP = symbolP ? symbol_next (symbolP) : symbol_rootP)
2919 if (symbolP->sy_mri_common)
2921 if (S_GET_STORAGE_CLASS (symbolP) == C_EXT
2923 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
2925 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT)
2926 as_bad (_("%s: global symbols not supported in common sections"),
2927 S_GET_NAME (symbolP));
2928 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2932 if (!SF_GET_DEBUG (symbolP))
2934 /* Debug symbols do not need all this rubbish */
2935 symbolS *real_symbolP;
2937 /* L* and C_EFCN symbols never merge. */
2938 if (!SF_GET_LOCAL (symbolP)
2939 && !SF_GET_STATICS (symbolP)
2940 && S_GET_STORAGE_CLASS (symbolP) != C_LABEL
2941 && symbolP->sy_value.X_op == O_constant
2942 && (real_symbolP = symbol_find_base (S_GET_NAME (symbolP), DO_NOT_STRIP))
2943 && real_symbolP != symbolP)
2945 /* FIXME-SOON: where do dups come from?
2946 Maybe tag references before definitions? xoxorich. */
2947 /* Move the debug data from the debug symbol to the
2948 real symbol. Do NOT do the oposite (i.e. move from
2949 real symbol to debug symbol and remove real symbol from the
2950 list.) Because some pointers refer to the real symbol
2951 whereas no pointers refer to the debug symbol. */
2952 c_symbol_merge (symbolP, real_symbolP);
2953 /* Replace the current symbol by the real one */
2954 /* The symbols will never be the last or the first
2955 because : 1st symbol is .file and 3 last symbols are
2956 .text, .data, .bss */
2957 symbol_remove (real_symbolP, &symbol_rootP, &symbol_lastP);
2958 symbol_insert (real_symbolP, symbolP, &symbol_rootP, &symbol_lastP);
2959 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2960 symbolP = real_symbolP;
2961 } /* if not local but dup'd */
2963 if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_E1))
2965 S_SET_SEGMENT (symbolP, SEG_E0);
2966 } /* push data into text */
2968 resolve_symbol_value (symbolP);
2970 if (S_GET_STORAGE_CLASS (symbolP) == C_NULL)
2972 if (!S_IS_DEFINED (symbolP) && !SF_GET_LOCAL (symbolP))
2974 S_SET_EXTERNAL (symbolP);
2976 else if (S_GET_SEGMENT (symbolP) == SEG_E0)
2978 S_SET_STORAGE_CLASS (symbolP, C_LABEL);
2982 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2986 /* Mainly to speed up if not -g */
2987 if (SF_GET_PROCESS (symbolP))
2989 /* Handle the nested blocks auxiliary info. */
2990 if (S_GET_STORAGE_CLASS (symbolP) == C_BLOCK)
2992 if (!strcmp (S_GET_NAME (symbolP), ".bb"))
2993 stack_push (block_stack, (char *) &symbolP);
2996 register symbolS *begin_symbolP;
2997 begin_symbolP = *(symbolS **) stack_pop (block_stack);
2998 if (begin_symbolP == (symbolS *) 0)
2999 as_warn (_("mismatched .eb"));
3001 SA_SET_SYM_ENDNDX (begin_symbolP, symbol_number + 2);
3004 /* If we are able to identify the type of a function, and we
3005 are out of a function (last_functionP == 0) then, the
3006 function symbol will be associated with an auxiliary
3008 if (last_functionP == (symbolS *) 0 &&
3009 SF_GET_FUNCTION (symbolP))
3011 last_functionP = symbolP;
3013 if (S_GET_NUMBER_AUXILIARY (symbolP) < 1)
3015 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3016 } /* make it at least 1 */
3018 /* Clobber possible stale .dim information. */
3020 /* Iffed out by steve - this fries the lnnoptr info too */
3021 bzero (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen,
3022 sizeof (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen));
3025 if (S_GET_STORAGE_CLASS (symbolP) == C_FCN)
3027 if (strcmp (S_GET_NAME (symbolP), ".bf") == 0)
3029 if (last_bfP != NULL)
3030 SA_SET_SYM_ENDNDX (last_bfP, symbol_number);
3034 else if (S_GET_STORAGE_CLASS (symbolP) == C_EFCN)
3036 /* I don't even know if this is needed for sdb. But
3037 the standard assembler generates it, so... */
3038 if (last_functionP == (symbolS *) 0)
3039 as_fatal (_("C_EFCN symbol out of scope"));
3040 SA_SET_SYM_FSIZE (last_functionP,
3041 (long) (S_GET_VALUE (symbolP) -
3042 S_GET_VALUE (last_functionP)));
3043 SA_SET_SYM_ENDNDX (last_functionP, symbol_number);
3044 last_functionP = (symbolS *) 0;
3048 else if (SF_GET_TAG (symbolP))
3050 /* First descriptor of a structure must point to
3051 the first slot after the structure description. */
3052 last_tagP = symbolP;
3055 else if (S_GET_STORAGE_CLASS (symbolP) == C_EOS)
3057 /* +2 take in account the current symbol */
3058 SA_SET_SYM_ENDNDX (last_tagP, symbol_number + 2);
3060 else if (S_GET_STORAGE_CLASS (symbolP) == C_FILE)
3062 /* If the filename was too long to fit in the
3063 auxent, put it in the string table */
3064 if (SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3065 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3067 SA_SET_FILE_FNAME_OFFSET (symbolP, string_byte_count);
3068 string_byte_count += strlen (filename_list_scan->filename) + 1;
3069 filename_list_scan = filename_list_scan->next;
3071 if (S_GET_VALUE (symbolP))
3073 S_SET_VALUE (symbolP, last_file_symno);
3074 last_file_symno = symbol_number;
3075 } /* no one points at the first .file symbol */
3076 } /* if debug or tag or eos or file */
3078 #ifdef tc_frob_coff_symbol
3079 tc_frob_coff_symbol (symbolP);
3082 /* We must put the external symbols apart. The loader
3083 does not bomb if we do not. But the references in
3084 the endndx field for a .bb symbol are not corrected
3085 if an external symbol is removed between .bb and .be.
3086 I.e in the following case :
3087 [20] .bb endndx = 22
3090 ld will move the symbol 21 to the end of the list but
3091 endndx will still be 22 instead of 21. */
3093 if (SF_GET_LOCAL (symbolP))
3095 /* remove C_EFCN and LOCAL (L...) symbols */
3096 /* next pointer remains valid */
3097 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3100 else if (symbolP->sy_value.X_op == O_symbol
3101 && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)))
3103 /* Skip symbols which were equated to undefined or common
3105 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3107 else if (!S_IS_DEFINED (symbolP)
3108 && !S_IS_DEBUG (symbolP)
3109 && !SF_GET_STATICS (symbolP)
3110 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3112 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3114 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT))
3116 /* if external, Remove from the list */
3117 symbolS *hold = symbol_previous (symbolP);
3119 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3120 symbol_clear_list_pointers (symbolP);
3121 symbol_append (symbolP, symbol_extern_lastP, &symbol_externP, &symbol_extern_lastP);
3124 else if (! S_IS_DEBUG (symbolP)
3125 && ! SF_GET_STATICS (symbolP)
3126 && ! SF_GET_FUNCTION (symbolP)
3127 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3129 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3131 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK))
3133 symbolS *hold = symbol_previous (symbolP);
3135 /* The O'Reilly COFF book says that defined global symbols
3136 come at the end of the symbol table, just before
3137 undefined global symbols. */
3139 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3140 symbol_clear_list_pointers (symbolP);
3141 symbol_append (symbolP, symbol_global_lastP, &symbol_globalP,
3142 &symbol_global_lastP);
3147 if (SF_GET_STRING (symbolP))
3149 symbolP->sy_name_offset = string_byte_count;
3150 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
3154 symbolP->sy_name_offset = 0;
3155 } /* fix "long" names */
3157 symbolP->sy_number = symbol_number;
3158 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
3159 } /* if local symbol */
3160 } /* traverse the symbol list */
3161 return symbol_number;
3166 glue_symbols (head, tail)
3170 unsigned int symbol_number = 0;
3172 while (*head != NULL)
3174 symbolS *tmp = *head;
3177 symbol_remove (tmp, head, tail);
3178 symbol_append (tmp, symbol_lastP, &symbol_rootP, &symbol_lastP);
3181 if (SF_GET_STRING (tmp))
3183 tmp->sy_name_offset = string_byte_count;
3184 string_byte_count += strlen (S_GET_NAME (tmp)) + 1;
3188 tmp->sy_name_offset = 0;
3189 } /* fix "long" names */
3191 tmp->sy_number = symbol_number;
3192 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (tmp);
3193 } /* append the entire extern chain */
3195 return symbol_number;
3201 unsigned int symbol_number = 0;
3204 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
3206 symbolP->sy_number = symbol_number;
3208 if (SF_GET_TAGGED (symbolP))
3212 ((symbolS *) SA_GET_SYM_TAGNDX (symbolP))->sy_number);
3215 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
3218 return symbol_number;
3222 crawl_symbols (h, abfd)
3224 bfd *abfd ATTRIBUTE_UNUSED;
3228 /* Initialize the stack used to keep track of the matching .bb .be */
3230 block_stack = stack_init (512, sizeof (symbolS *));
3232 /* The symbol list should be ordered according to the following sequence
3235 * . debug entries for functions
3236 * . fake symbols for the sections, including .text .data and .bss
3238 * . undefined symbols
3239 * But this is not mandatory. The only important point is to put the
3240 * undefined symbols at the end of the list.
3243 /* Is there a .file symbol ? If not insert one at the beginning. */
3244 if (symbol_rootP == NULL
3245 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
3247 c_dot_file_symbol ("fake");
3251 * Build up static symbols for the sections, they are filled in later
3254 for (i = SEG_E0; i < SEG_LAST; i++)
3255 if (segment_info[i].scnhdr.s_name[0])
3256 segment_info[i].dot = c_section_symbol (segment_info[i].name,
3259 /* Take all the externals out and put them into another chain */
3260 H_SET_SYMBOL_TABLE_SIZE (h, yank_symbols ());
3261 /* Take the externals and glue them onto the end.*/
3262 H_SET_SYMBOL_TABLE_SIZE (h,
3263 (H_GET_SYMBOL_COUNT (h)
3264 + glue_symbols (&symbol_globalP,
3265 &symbol_global_lastP)
3266 + glue_symbols (&symbol_externP,
3267 &symbol_extern_lastP)));
3269 H_SET_SYMBOL_TABLE_SIZE (h, tie_tags ());
3270 know (symbol_globalP == NULL);
3271 know (symbol_global_lastP == NULL);
3272 know (symbol_externP == NULL);
3273 know (symbol_extern_lastP == NULL);
3277 * Find strings by crawling along symbol table chain.
3285 struct filename_list *filename_list_scan = filename_list_head;
3287 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3288 md_number_to_chars (where, (valueT) string_byte_count, 4);
3291 #ifdef COFF_LONG_SECTION_NAMES
3292 /* Support long section names as found in PE. This code must
3293 coordinate with that in coff_header_append and write_object_file. */
3297 for (i = SEG_E0; i < SEG_LAST; i++)
3299 if (segment_info[i].scnhdr.s_name[0]
3300 && strlen (segment_info[i].name) > SCNNMLEN)
3304 size = strlen (segment_info[i].name) + 1;
3305 memcpy (where, segment_info[i].name, size);
3310 #endif /* COFF_LONG_SECTION_NAMES */
3312 for (symbolP = symbol_rootP;
3314 symbolP = symbol_next (symbolP))
3318 if (SF_GET_STRING (symbolP))
3320 size = strlen (S_GET_NAME (symbolP)) + 1;
3321 memcpy (where, S_GET_NAME (symbolP), size);
3324 if (S_GET_STORAGE_CLASS (symbolP) == C_FILE
3325 && SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3326 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3328 size = strlen (filename_list_scan->filename) + 1;
3329 memcpy (where, filename_list_scan->filename, size);
3330 filename_list_scan = filename_list_scan ->next;
3337 do_linenos_for (abfd, h, file_cursor)
3340 unsigned long *file_cursor;
3343 unsigned long start = *file_cursor;
3345 for (idx = SEG_E0; idx < SEG_LAST; idx++)
3347 segment_info_type *s = segment_info + idx;
3349 if (s->scnhdr.s_nlnno != 0)
3351 struct lineno_list *line_ptr;
3353 struct external_lineno *buffer =
3354 (struct external_lineno *) xmalloc (s->scnhdr.s_nlnno * LINESZ);
3356 struct external_lineno *dst = buffer;
3358 /* Run through the table we've built and turn it into its external
3359 form, take this chance to remove duplicates */
3361 for (line_ptr = s->lineno_list_head;
3362 line_ptr != (struct lineno_list *) NULL;
3363 line_ptr = line_ptr->next)
3365 if (line_ptr->line.l_lnno == 0)
3367 /* Turn a pointer to a symbol into the symbols' index,
3368 provided that it has been initialised. */
3369 if (line_ptr->line.l_addr.l_symndx)
3370 line_ptr->line.l_addr.l_symndx =
3371 ((symbolS *) line_ptr->line.l_addr.l_symndx)->sy_number;
3375 line_ptr->line.l_addr.l_paddr += ((struct frag *) (line_ptr->frag))->fr_address;
3378 (void) bfd_coff_swap_lineno_out (abfd, &(line_ptr->line), dst);
3383 s->scnhdr.s_lnnoptr = *file_cursor;
3385 bfd_write (buffer, 1, s->scnhdr.s_nlnno * LINESZ, abfd);
3388 *file_cursor += s->scnhdr.s_nlnno * LINESZ;
3391 H_SET_LINENO_SIZE (h, *file_cursor - start);
3394 /* Now we run through the list of frag chains in a segment and
3395 make all the subsegment frags appear at the end of the
3396 list, as if the seg 0 was extra long */
3403 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3405 frchainS *head = segment_info[i].frchainP;
3407 fragS *prev_frag = &dummy;
3409 while (head && head->frch_seg == i)
3411 prev_frag->fr_next = head->frch_root;
3412 prev_frag = head->frch_last;
3413 head = head->frch_next;
3415 prev_frag->fr_next = 0;
3419 unsigned long machine;
3422 write_object_file ()
3426 struct frchain *frchain_ptr;
3428 object_headers headers;
3429 unsigned long file_cursor;
3432 abfd = bfd_openw (out_file_name, TARGET_FORMAT);
3436 as_perror (_("FATAL: Can't create %s"), out_file_name);
3437 exit (EXIT_FAILURE);
3439 bfd_set_format (abfd, bfd_object);
3440 bfd_set_arch_mach (abfd, BFD_ARCH, machine);
3442 string_byte_count = 4;
3444 for (frchain_ptr = frchain_root;
3445 frchain_ptr != (struct frchain *) NULL;
3446 frchain_ptr = frchain_ptr->frch_next)
3448 /* Run through all the sub-segments and align them up. Also
3449 close any open frags. We tack a .fill onto the end of the
3450 frag chain so that any .align's size can be worked by looking
3451 at the next frag. */
3453 subseg_set (frchain_ptr->frch_seg, frchain_ptr->frch_subseg);
3455 #ifndef SUB_SEGMENT_ALIGN
3456 #define SUB_SEGMENT_ALIGN(SEG) 1
3459 md_do_align (SUB_SEGMENT_ALIGN (now_seg), (char *) NULL, 0, 0,
3462 if (subseg_text_p (now_seg))
3463 frag_align_code (SUB_SEGMENT_ALIGN (now_seg), 0);
3465 frag_align (SUB_SEGMENT_ALIGN (now_seg), 0, 0);
3471 frag_wane (frag_now);
3472 frag_now->fr_fix = 0;
3473 know (frag_now->fr_next == NULL);
3478 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3480 relax_segment (segment_info[i].frchainP->frch_root, i);
3483 /* Relaxation has completed. Freeze all syms. */
3486 H_SET_NUMBER_OF_SECTIONS (&headers, 0);
3488 /* Find out how big the sections are, and set the addresses. */
3490 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3494 segment_info[i].scnhdr.s_paddr = addr;
3495 segment_info[i].scnhdr.s_vaddr = addr;
3497 if (segment_info[i].scnhdr.s_name[0])
3499 H_SET_NUMBER_OF_SECTIONS (&headers,
3500 H_GET_NUMBER_OF_SECTIONS (&headers) + 1);
3502 #ifdef COFF_LONG_SECTION_NAMES
3503 /* Support long section names as found in PE. This code
3504 must coordinate with that in coff_header_append and
3509 len = strlen (segment_info[i].name);
3511 string_byte_count += len + 1;
3513 #endif /* COFF_LONG_SECTION_NAMES */
3516 size = size_section (abfd, (unsigned int) i);
3519 /* I think the section alignment is only used on the i960; the
3520 i960 needs it, and it should do no harm on other targets. */
3521 #ifdef ALIGNMENT_IN_S_FLAGS
3522 segment_info[i].scnhdr.s_flags |= (section_alignment[i] & 0xF) << 8;
3524 segment_info[i].scnhdr.s_align = 1 << section_alignment[i];
3528 H_SET_TEXT_SIZE (&headers, size);
3529 else if (i == SEG_E1)
3530 H_SET_DATA_SIZE (&headers, size);
3531 else if (i == SEG_E2)
3532 H_SET_BSS_SIZE (&headers, size);
3535 /* Turn the gas native symbol table shape into a coff symbol table */
3536 crawl_symbols (&headers, abfd);
3538 if (string_byte_count == 4)
3539 string_byte_count = 0;
3541 H_SET_STRING_SIZE (&headers, string_byte_count);
3547 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3549 fixup_mdeps (segment_info[i].frchainP->frch_root, &headers, i);
3550 fixup_segment (&segment_info[i], i);
3553 /* Look for ".stab" segments and fill in their initial symbols
3555 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3557 name = segment_info[i].name;
3560 && strncmp (".stab", name, 5) == 0
3561 && strncmp (".stabstr", name, 8) != 0)
3562 adjust_stab_section (abfd, i);
3565 file_cursor = H_GET_TEXT_FILE_OFFSET (&headers);
3567 bfd_seek (abfd, (file_ptr) file_cursor, 0);
3569 /* Plant the data */
3571 fill_section (abfd, &headers, &file_cursor);
3573 do_relocs_for (abfd, &headers, &file_cursor);
3575 do_linenos_for (abfd, &headers, &file_cursor);
3577 H_SET_FILE_MAGIC_NUMBER (&headers, COFF_MAGIC);
3578 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3579 H_SET_TIME_STAMP (&headers, (long)time((time_t *)0));
3581 H_SET_TIME_STAMP (&headers, 0);
3583 #ifdef TC_COFF_SET_MACHINE
3584 TC_COFF_SET_MACHINE (&headers);
3588 #define COFF_FLAGS 0
3591 #ifdef KEEP_RELOC_INFO
3592 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3593 COFF_FLAGS | coff_flags));
3595 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3596 (H_GET_RELOCATION_SIZE(&headers) ? 0 : F_RELFLG) |
3597 COFF_FLAGS | coff_flags));
3601 unsigned int symtable_size = H_GET_SYMBOL_TABLE_SIZE (&headers);
3602 char *buffer1 = xmalloc (symtable_size + string_byte_count + 1);
3604 H_SET_SYMBOL_TABLE_POINTER (&headers, bfd_tell (abfd));
3605 w_symbols (abfd, buffer1, symbol_rootP);
3606 if (string_byte_count > 0)
3607 w_strings (buffer1 + symtable_size);
3608 bfd_write (buffer1, 1, symtable_size + string_byte_count, abfd);
3612 coff_header_append (abfd, &headers);
3614 /* Recent changes to write need this, but where it should
3615 go is up to Ken.. */
3616 if (bfd_close_all_done (abfd) == false)
3617 as_fatal (_("Can't close %s: %s"), out_file_name,
3618 bfd_errmsg (bfd_get_error ()));
3621 extern bfd *stdoutput;
3628 /* Add a new segment. This is called from subseg_new via the
3629 obj_new_segment macro. */
3632 obj_coff_add_segment (name)
3637 #ifndef COFF_LONG_SECTION_NAMES
3638 char buf[SCNNMLEN + 1];
3640 strncpy (buf, name, SCNNMLEN);
3641 buf[SCNNMLEN] = '\0';
3645 for (i = SEG_E0; i < SEG_LAST && segment_info[i].scnhdr.s_name[0]; i++)
3646 if (strcmp (name, segment_info[i].name) == 0)
3651 as_bad (_("Too many new sections; can't add \"%s\""), name);
3655 /* Add a new section. */
3656 strncpy (segment_info[i].scnhdr.s_name, name,
3657 sizeof (segment_info[i].scnhdr.s_name));
3658 segment_info[i].scnhdr.s_flags = STYP_REG;
3659 segment_info[i].name = xstrdup (name);
3665 * implement the .section pseudo op:
3666 * .section name {, "flags"}
3668 * | +--- optional flags: 'b' for bss
3670 * +-- section name 'l' for lib
3674 * 'd' (apparently m88k for data)
3676 * 'r' for read-only data
3677 * But if the argument is not a quoted string, treat it as a
3678 * subsegment number.
3682 obj_coff_section (ignore)
3683 int ignore ATTRIBUTE_UNUSED;
3685 /* Strip out the section name */
3686 char *section_name, *name;
3699 else if (type == 'D')
3701 segment_info[now_seg].scnhdr.s_flags |= flags;
3706 section_name = input_line_pointer;
3707 c = get_symbol_end ();
3709 name = xmalloc (input_line_pointer - section_name + 1);
3710 strcpy (name, section_name);
3712 *input_line_pointer = c;
3718 if (*input_line_pointer == ',')
3720 ++input_line_pointer;
3723 if (*input_line_pointer != '"')
3724 exp = get_absolute_expression ();
3727 ++input_line_pointer;
3728 while (*input_line_pointer != '"'
3729 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3731 switch (*input_line_pointer)
3733 case 'b': flags |= STYP_BSS; break;
3734 case 'i': flags |= STYP_INFO; break;
3735 case 'l': flags |= STYP_LIB; break;
3736 case 'n': flags |= STYP_NOLOAD; break;
3737 case 'o': flags |= STYP_OVER; break;
3739 case 'w': flags |= STYP_DATA; break;
3740 case 'x': flags |= STYP_TEXT; break;
3741 case 'r': flags |= STYP_LIT; break;
3743 as_warn(_("unknown section attribute '%c'"),
3744 *input_line_pointer);
3747 ++input_line_pointer;
3749 if (*input_line_pointer == '"')
3750 ++input_line_pointer;
3754 subseg_new (name, (subsegT) exp);
3756 segment_info[now_seg].scnhdr.s_flags |= flags;
3758 demand_empty_rest_of_line ();
3762 obj_coff_text (ignore)
3763 int ignore ATTRIBUTE_UNUSED;
3765 subseg_new (".text", get_absolute_expression ());
3769 obj_coff_data (ignore)
3770 int ignore ATTRIBUTE_UNUSED;
3772 if (flag_readonly_data_in_text)
3773 subseg_new (".text", get_absolute_expression () + 1000);
3775 subseg_new (".data", get_absolute_expression ());
3779 obj_coff_ident (ignore)
3780 int ignore ATTRIBUTE_UNUSED;
3782 segT current_seg = now_seg; /* save current seg */
3783 subsegT current_subseg = now_subseg;
3784 subseg_new (".comment", 0); /* .comment seg */
3785 stringer (1); /* read string */
3786 subseg_set (current_seg, current_subseg); /* restore current seg */
3790 c_symbol_merge (debug, normal)
3794 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
3795 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
3797 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
3799 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
3800 } /* take the most we have */
3802 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
3804 memcpy ((char *) &normal->sy_symbol.ost_auxent[0],
3805 (char *) &debug->sy_symbol.ost_auxent[0],
3806 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug) * AUXESZ));
3807 } /* Move all the auxiliary information */
3809 /* Move the debug flags. */
3810 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
3811 } /* c_symbol_merge() */
3814 c_line_new (symbol, paddr, line_number, frag)
3820 struct lineno_list *new_line =
3821 (struct lineno_list *) xmalloc (sizeof (struct lineno_list));
3823 segment_info_type *s = segment_info + now_seg;
3824 new_line->line.l_lnno = line_number;
3826 if (line_number == 0)
3828 last_line_symbol = symbol;
3829 new_line->line.l_addr.l_symndx = (long) symbol;
3833 new_line->line.l_addr.l_paddr = paddr;
3836 new_line->frag = (char *) frag;
3837 new_line->next = (struct lineno_list *) NULL;
3839 if (s->lineno_list_head == (struct lineno_list *) NULL)
3841 s->lineno_list_head = new_line;
3845 s->lineno_list_tail->next = new_line;
3847 s->lineno_list_tail = new_line;
3848 return LINESZ * s->scnhdr.s_nlnno++;
3852 c_dot_file_symbol (filename)
3857 symbolP = symbol_new (".file",
3860 &zero_address_frag);
3862 S_SET_STORAGE_CLASS (symbolP, C_FILE);
3863 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3865 if (strlen (filename) > FILNMLEN)
3867 /* Filename is too long to fit into an auxent,
3868 we stick it into the string table instead. We keep
3869 a linked list of the filenames we find so we can emit
3871 struct filename_list *f = ((struct filename_list *)
3872 xmalloc (sizeof (struct filename_list)));
3874 f->filename = filename;
3877 SA_SET_FILE_FNAME_ZEROS (symbolP, 0);
3878 SA_SET_FILE_FNAME_OFFSET (symbolP, 1);
3880 if (filename_list_tail)
3881 filename_list_tail->next = f;
3883 filename_list_head = f;
3884 filename_list_tail = f;
3888 SA_SET_FILE_FNAME (symbolP, filename);
3895 listing_source_file (filename);
3901 SF_SET_DEBUG (symbolP);
3902 S_SET_VALUE (symbolP, (valueT) previous_file_symbol);
3904 previous_file_symbol = symbolP;
3906 /* Make sure that the symbol is first on the symbol chain */
3907 if (symbol_rootP != symbolP)
3909 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3910 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
3912 } /* c_dot_file_symbol() */
3915 * Build a 'section static' symbol.
3919 c_section_symbol (name, idx)
3925 symbolP = symbol_find_base (name, DO_NOT_STRIP);
3926 if (symbolP == NULL)
3927 symbolP = symbol_new (name, idx, 0, &zero_address_frag);
3930 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3931 S_SET_SEGMENT (symbolP, idx);
3932 symbolP->sy_frag = &zero_address_frag;
3935 S_SET_STORAGE_CLASS (symbolP, C_STAT);
3936 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3938 SF_SET_STATICS (symbolP);
3941 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3942 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3943 SF_CLEAR_LOCAL (symbolP);
3946 /* If the .linkonce pseudo-op was used for this section, we must
3947 store the information in the auxiliary entry for the section
3949 if (segment_info[idx].linkonce != LINKONCE_UNSET)
3953 switch (segment_info[idx].linkonce)
3957 case LINKONCE_DISCARD:
3958 type = IMAGE_COMDAT_SELECT_ANY;
3960 case LINKONCE_ONE_ONLY:
3961 type = IMAGE_COMDAT_SELECT_NODUPLICATES;
3963 case LINKONCE_SAME_SIZE:
3964 type = IMAGE_COMDAT_SELECT_SAME_SIZE;
3966 case LINKONCE_SAME_CONTENTS:
3967 type = IMAGE_COMDAT_SELECT_EXACT_MATCH;
3971 SYM_AUXENT (symbolP)->x_scn.x_comdat = type;
3976 } /* c_section_symbol() */
3979 w_symbols (abfd, where, symbol_rootP)
3982 symbolS * symbol_rootP;
3987 /* First fill in those values we have only just worked out */
3988 for (i = SEG_E0; i < SEG_LAST; i++)
3990 symbolP = segment_info[i].dot;
3993 SA_SET_SCN_SCNLEN (symbolP, segment_info[i].scnhdr.s_size);
3994 SA_SET_SCN_NRELOC (symbolP, segment_info[i].scnhdr.s_nreloc);
3995 SA_SET_SCN_NLINNO (symbolP, segment_info[i].scnhdr.s_nlnno);
4000 * Emit all symbols left in the symbol chain.
4002 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
4004 /* Used to save the offset of the name. It is used to point
4005 to the string in memory but must be a file offset. */
4006 register char *temp;
4008 /* We can't fix the lnnoptr field in yank_symbols with the other
4009 adjustments, because we have to wait until we know where they
4011 if (SF_GET_ADJ_LNNOPTR (symbolP))
4013 SA_GET_SYM_LNNOPTR (symbolP) +=
4014 segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_lnnoptr;
4017 tc_coff_symbol_emit_hook (symbolP);
4019 temp = S_GET_NAME (symbolP);
4020 if (SF_GET_STRING (symbolP))
4022 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
4023 S_SET_ZEROES (symbolP, 0);
4027 memset (symbolP->sy_symbol.ost_entry.n_name, 0, SYMNMLEN);
4028 strncpy (symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN);
4030 where = symbol_to_chars (abfd, where, symbolP);
4031 S_SET_NAME (symbolP, temp);
4037 obj_coff_lcomm (ignore)
4038 int ignore ATTRIBUTE_UNUSED;
4050 name = input_line_pointer;
4052 c = get_symbol_end ();
4053 p = input_line_pointer;
4056 if (*input_line_pointer != ',')
4058 as_bad (_("Expected comma after name"));
4059 ignore_rest_of_line ();
4062 if (*input_line_pointer == '\n')
4064 as_bad (_("Missing size expression"));
4067 input_line_pointer++;
4068 if ((temp = get_absolute_expression ()) < 0)
4070 as_warn (_("lcomm length (%d.) <0! Ignored."), temp);
4071 ignore_rest_of_line ();
4076 symbolP = symbol_find_or_make (name);
4078 if (S_GET_SEGMENT (symbolP) == SEG_UNKNOWN &&
4079 S_GET_VALUE (symbolP) == 0)
4084 segT current_seg = now_seg; /* save current seg */
4085 subsegT current_subseg = now_subseg;
4087 subseg_set (SEG_E2, 1);
4088 symbolP->sy_frag = frag_now;
4089 p = frag_var(rs_org, 1, 1, (relax_substateT)0, symbolP,
4090 (offsetT) temp, (char *) 0);
4092 subseg_set (current_seg, current_subseg); /* restore current seg */
4093 S_SET_SEGMENT (symbolP, SEG_E2);
4094 S_SET_STORAGE_CLASS (symbolP, C_STAT);
4098 as_bad (_("Symbol %s already defined"), name);
4100 demand_empty_rest_of_line ();
4105 fixup_mdeps (frags, h, this_segment)
4110 subseg_change (this_segment, 0);
4113 switch (frags->fr_type)
4120 HANDLE_ALIGN (frags);
4122 frags->fr_type = rs_fill;
4124 ((frags->fr_next->fr_address - frags->fr_address - frags->fr_fix)
4127 case rs_machine_dependent:
4128 md_convert_frag (h, this_segment, frags);
4134 frags = frags->fr_next;
4140 #ifndef TC_FORCE_RELOCATION
4141 #define TC_FORCE_RELOCATION(fix) 0
4145 fixup_segment (segP, this_segment_type)
4146 segment_info_type * segP;
4147 segT this_segment_type;
4149 register fixS * fixP;
4150 register symbolS *add_symbolP;
4151 register symbolS *sub_symbolP;
4154 register char *place;
4155 register long where;
4156 register char pcrel;
4157 register fragS *fragP;
4158 register segT add_symbol_segment = absolute_section;
4160 for (fixP = segP->fix_root; fixP; fixP = fixP->fx_next)
4162 fragP = fixP->fx_frag;
4164 where = fixP->fx_where;
4165 place = fragP->fr_literal + where;
4166 size = fixP->fx_size;
4167 add_symbolP = fixP->fx_addsy;
4168 sub_symbolP = fixP->fx_subsy;
4169 add_number = fixP->fx_offset;
4170 pcrel = fixP->fx_pcrel;
4172 /* We want function-relative stabs to work on systems which
4173 may use a relaxing linker; thus we must handle the sym1-sym2
4174 fixups function-relative stabs generates.
4176 Of course, if you actually enable relaxing in the linker, the
4177 line and block scoping information is going to be incorrect
4178 in some cases. The only way to really fix this is to support
4179 a reloc involving the difference of two symbols. */
4181 && (!sub_symbolP || pcrel))
4185 if (fixP->fx_tcbit && SF_GET_CALLNAME (add_symbolP))
4187 /* Relocation should be done via the associated 'bal' entry
4190 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP)))
4192 as_bad_where (fixP->fx_file, fixP->fx_line,
4193 _("No 'bal' entry point for leafproc %s"),
4194 S_GET_NAME (add_symbolP));
4197 fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP);
4201 /* Make sure the symbols have been resolved; this may not have
4202 happened if these are expression symbols. */
4203 if (add_symbolP != NULL && ! add_symbolP->sy_resolved)
4204 resolve_symbol_value (add_symbolP);
4206 if (add_symbolP != NULL)
4208 /* If this fixup is against a symbol which has been equated
4209 to another symbol, convert it to the other symbol. */
4210 if (add_symbolP->sy_value.X_op == O_symbol
4211 && (! S_IS_DEFINED (add_symbolP)
4212 || S_IS_COMMON (add_symbolP)))
4214 while (add_symbolP->sy_value.X_op == O_symbol
4215 && (! S_IS_DEFINED (add_symbolP)
4216 || S_IS_COMMON (add_symbolP)))
4220 /* We must avoid looping, as that can occur with a
4221 badly written program. */
4222 n = add_symbolP->sy_value.X_add_symbol;
4223 if (n == add_symbolP)
4225 add_number += add_symbolP->sy_value.X_add_number;
4228 fixP->fx_addsy = add_symbolP;
4229 fixP->fx_offset = add_number;
4233 if (sub_symbolP != NULL && ! sub_symbolP->sy_resolved)
4234 resolve_symbol_value (sub_symbolP);
4236 if (add_symbolP != NULL
4237 && add_symbolP->sy_mri_common)
4239 know (add_symbolP->sy_value.X_op == O_symbol);
4240 add_number += S_GET_VALUE (add_symbolP);
4241 fixP->fx_offset = add_number;
4242 add_symbolP = fixP->fx_addsy = add_symbolP->sy_value.X_add_symbol;
4247 add_symbol_segment = S_GET_SEGMENT (add_symbolP);
4248 } /* if there is an addend */
4252 if (add_symbolP == NULL || add_symbol_segment == absolute_section)
4254 if (add_symbolP != NULL)
4256 add_number += S_GET_VALUE (add_symbolP);
4258 fixP->fx_addsy = NULL;
4261 /* It's just -sym. */
4262 if (S_GET_SEGMENT (sub_symbolP) == absolute_section)
4264 add_number -= S_GET_VALUE (sub_symbolP);
4271 as_bad_where (fixP->fx_file, fixP->fx_line,
4272 _("Negative of non-absolute symbol %s"),
4273 S_GET_NAME (sub_symbolP));
4275 add_number -= S_GET_VALUE (sub_symbolP);
4276 } /* not absolute */
4278 /* if sub_symbol is in the same segment that add_symbol
4279 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4281 else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
4282 && SEG_NORMAL (add_symbol_segment))
4284 /* Difference of 2 symbols from same segment. Can't
4285 make difference of 2 undefineds: 'value' means
4286 something different for N_UNDF. */
4288 /* Makes no sense to use the difference of 2 arbitrary symbols
4289 as the target of a call instruction. */
4292 as_bad_where (fixP->fx_file, fixP->fx_line,
4293 _("callj to difference of 2 symbols"));
4295 #endif /* TC_I960 */
4296 add_number += S_GET_VALUE (add_symbolP) -
4297 S_GET_VALUE (sub_symbolP);
4300 if (!TC_FORCE_RELOCATION (fixP))
4302 fixP->fx_addsy = NULL;
4303 fixP->fx_subsy = NULL;
4305 #ifdef TC_M68K /* is this right? */
4313 /* Different segments in subtraction. */
4314 know (!(S_IS_EXTERNAL (sub_symbolP) && (S_GET_SEGMENT (sub_symbolP) == absolute_section)));
4316 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section))
4318 add_number -= S_GET_VALUE (sub_symbolP);
4321 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type
4322 #if 0 /* Okay for 68k, at least... */
4327 /* Make it pc-relative. */
4328 add_number += (md_pcrel_from (fixP)
4329 - S_GET_VALUE (sub_symbolP));
4338 as_bad_where (fixP->fx_file, fixP->fx_line,
4339 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4340 segment_name (S_GET_SEGMENT (sub_symbolP)),
4341 S_GET_NAME (sub_symbolP),
4342 (long) (fragP->fr_address + where));
4345 } /* if sub_symbolP */
4349 if (add_symbol_segment == this_segment_type && pcrel)
4352 * This fixup was made when the symbol's segment was
4353 * SEG_UNKNOWN, but it is now in the local segment.
4354 * So we know how to do the address without relocation.
4357 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4358 * in which cases it modifies *fixP as appropriate. In the case
4359 * of a 'calls', no further work is required, and *fixP has been
4360 * set up to make the rest of the code below a no-op.
4363 #endif /* TC_I960 */
4365 add_number += S_GET_VALUE (add_symbolP);
4366 add_number -= md_pcrel_from (fixP);
4369 add_number -= segP->scnhdr.s_vaddr;
4370 if defined (TC_I386) || defined (TE_LYNX). I now
4371 think that was an error propagated from the case when
4372 we are going to emit the relocation. If we are not
4373 going to emit the relocation, then we just want to
4374 set add_number to the difference between the symbols.
4375 This is a case that would only arise when there is a
4376 PC relative reference from a section other than .text
4377 to a symbol defined in the same section, and the
4378 reference is not relaxed. Since jump instructions on
4379 the i386 are relaxed, this could only arise with a
4380 call instruction. */
4382 pcrel = 0; /* Lie. Don't want further pcrel processing. */
4383 if (!TC_FORCE_RELOCATION (fixP))
4385 fixP->fx_addsy = NULL;
4391 switch (add_symbol_segment)
4393 case absolute_section:
4395 reloc_callj (fixP); /* See comment about reloc_callj() above*/
4396 #endif /* TC_I960 */
4397 add_number += S_GET_VALUE (add_symbolP);
4400 if (!TC_FORCE_RELOCATION (fixP))
4402 fixP->fx_addsy = NULL;
4408 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4409 /* This really should be handled in the linker, but
4410 backward compatibility forbids. */
4411 add_number += S_GET_VALUE (add_symbolP);
4413 add_number += S_GET_VALUE (add_symbolP) +
4414 segment_info[S_GET_SEGMENT (add_symbolP)].scnhdr.s_paddr;
4420 if ((int) fixP->fx_bit_fixP == 13)
4422 /* This is a COBR instruction. They have only a
4423 * 13-bit displacement and are only to be used
4424 * for local branches: flag as error, don't generate
4427 as_bad_where (fixP->fx_file, fixP->fx_line,
4428 _("can't use COBR format with external label"));
4429 fixP->fx_addsy = NULL;
4433 #endif /* TC_I960 */
4434 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4435 /* 386 COFF uses a peculiar format in which the
4436 value of a common symbol is stored in the .text
4437 segment (I've checked this on SVR3.2 and SCO
4438 3.2.2) Ian Taylor <ian@cygnus.com>. */
4439 /* This is also true for 68k COFF on sysv machines
4440 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4441 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4442 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4443 if (S_IS_COMMON (add_symbolP))
4444 add_number += S_GET_VALUE (add_symbolP);
4448 } /* switch on symbol seg */
4449 } /* if not in local seg */
4450 } /* if there was a + symbol */
4454 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4455 /* This adjustment is not correct on the m88k, for which the
4456 linker does all the computation. */
4457 add_number -= md_pcrel_from (fixP);
4459 if (add_symbolP == 0)
4461 fixP->fx_addsy = &abs_symbol;
4462 } /* if there's an add_symbol */
4463 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4464 /* On the 386 we must adjust by the segment vaddr as well.
4467 I changed the i960 to work this way as well. This is
4468 compatible with the current GNU linker behaviour. I do
4469 not know what other i960 COFF assemblers do. This is not
4470 a common case: normally, only assembler code will contain
4471 a PC relative reloc, and only branches which do not
4472 originate in the .text section will have a non-zero
4475 I changed the m68k to work this way as well. This will
4476 break existing PC relative relocs from sections which do
4477 not start at address 0, but it will make ld -r work.
4478 Ian Taylor, 4 Oct 96. */
4480 add_number -= segP->scnhdr.s_vaddr;
4484 #ifdef MD_APPLY_FIX3
4485 md_apply_fix3 (fixP, (valueT *) &add_number, this_segment_type);
4487 md_apply_fix (fixP, add_number);
4490 if (!fixP->fx_bit_fixP && ! fixP->fx_no_overflow)
4493 /* The m88k uses the offset field of the reloc to get around
4496 && ((add_number & ~0xFF)
4497 || (fixP->fx_signed && (add_number & 0x80)))
4498 && ((add_number & ~0xFF) != (-1 & ~0xFF)
4499 || (add_number & 0x80) == 0))
4501 && ((add_number & ~0xFFFF)
4502 || (fixP->fx_signed && (add_number & 0x8000)))
4503 && ((add_number & ~0xFFFF) != (-1 & ~0xFFFF)
4504 || (add_number & 0x8000) == 0)))
4506 as_bad_where (fixP->fx_file, fixP->fx_line,
4507 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4508 (long) add_number, size,
4509 (unsigned long) (fragP->fr_address + where));
4512 #ifdef WARN_SIGNED_OVERFLOW_WORD
4513 /* Warn if a .word value is too large when treated as a
4514 signed number. We already know it is not too negative.
4515 This is to catch over-large switches generated by gcc on
4517 if (!flag_signed_overflow_ok
4519 && add_number > 0x7fff)
4520 as_bad_where (fixP->fx_file, fixP->fx_line,
4521 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4523 (unsigned long) (fragP->fr_address + where));
4525 } /* not a bit fix */
4526 } /* For each fixS in this segment. */
4527 } /* fixup_segment() */
4531 /* The first entry in a .stab section is special. */
4534 obj_coff_init_stab_section (seg)
4540 unsigned int stroff;
4542 /* Make space for this first symbol. */
4546 as_where (&file, (unsigned int *) NULL);
4547 stabstr_name = (char *) alloca (strlen (segment_info[seg].name) + 4);
4548 strcpy (stabstr_name, segment_info[seg].name);
4549 strcat (stabstr_name, "str");
4550 stroff = get_stab_string_offset (file, stabstr_name);
4552 md_number_to_chars (p, stroff, 4);
4555 /* Fill in the counts in the first entry in a .stab section. */
4558 adjust_stab_section(abfd, seg)
4562 segT stabstrseg = SEG_UNKNOWN;
4563 const char *secname, *name2;
4566 int i, strsz = 0, nsyms;
4567 fragS *frag = segment_info[seg].frchainP->frch_root;
4569 /* Look for the associated string table section. */
4571 secname = segment_info[seg].name;
4572 name = (char *) alloca (strlen (secname) + 4);
4573 strcpy (name, secname);
4574 strcat (name, "str");
4576 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
4578 name2 = segment_info[i].name;
4579 if (name2 != NULL && strncmp(name2, name, 8) == 0)
4586 /* If we found the section, get its size. */
4587 if (stabstrseg != SEG_UNKNOWN)
4588 strsz = size_section (abfd, stabstrseg);
4590 nsyms = size_section (abfd, seg) / 12 - 1;
4592 /* Look for the first frag of sufficient size for the initial stab
4593 symbol, and collect a pointer to it. */
4594 while (frag && frag->fr_fix < 12)
4595 frag = frag->fr_next;
4597 p = frag->fr_literal;
4600 /* Write in the number of stab symbols and the size of the string
4602 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
4603 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
4606 #endif /* not BFD_ASSEMBLER */
4608 const pseudo_typeS coff_pseudo_table[] =
4610 {"def", obj_coff_def, 0},
4611 {"dim", obj_coff_dim, 0},
4612 {"endef", obj_coff_endef, 0},
4613 {"line", obj_coff_line, 0},
4614 {"ln", obj_coff_ln, 0},
4615 #ifdef BFD_ASSEMBLER
4616 {"loc", obj_coff_loc, 0},
4618 {"appline", obj_coff_ln, 1},
4619 {"scl", obj_coff_scl, 0},
4620 {"size", obj_coff_size, 0},
4621 {"tag", obj_coff_tag, 0},
4622 {"type", obj_coff_type, 0},
4623 {"val", obj_coff_val, 0},
4624 {"section", obj_coff_section, 0},
4625 {"sect", obj_coff_section, 0},
4626 /* FIXME: We ignore the MRI short attribute. */
4627 {"section.s", obj_coff_section, 0},
4628 {"sect.s", obj_coff_section, 0},
4629 /* We accept the .bss directive for backward compatibility with
4630 earlier versions of gas. */
4631 {"bss", obj_coff_bss, 0},
4632 {"weak", obj_coff_weak, 0},
4633 {"ident", obj_coff_ident, 0},
4634 #ifndef BFD_ASSEMBLER
4635 {"use", obj_coff_section, 0},
4636 {"text", obj_coff_text, 0},
4637 {"data", obj_coff_data, 0},
4638 {"lcomm", obj_coff_lcomm, 0},
4640 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
4642 {"version", s_ignore, 0},
4643 {"ABORT", s_abort, 0},
4645 /* The m88k uses sdef instead of def. */
4646 {"sdef", obj_coff_def, 0},
4648 {NULL, NULL, 0} /* end sentinel */
4649 }; /* coff_pseudo_table */
4651 #ifdef BFD_ASSEMBLER
4653 /* Support for a COFF emulation. */
4655 static void coff_pop_insert PARAMS ((void));
4656 static int coff_separate_stab_sections PARAMS ((void));
4661 pop_insert (coff_pseudo_table);
4665 coff_separate_stab_sections ()
4670 const struct format_ops coff_format_ops =
4672 bfd_target_coff_flavour,
4673 0, /* dfl_leading_underscore */
4674 1, /* emit_section_symbols */
4679 0, /* frob_file_before_adjust */
4680 coff_frob_file_after_relocs,
4683 0, /* s_get_align */
4684 0, /* s_set_align */
4685 0, /* s_get_other */
4686 0, /* s_set_other */
4691 0, /* copy_symbol_attributes */
4692 0, /* generate_asm_lineno */
4693 0, /* process_stab */
4694 coff_separate_stab_sections,
4695 obj_coff_init_stab_section,
4696 0, /* sec_sym_ok_for_reloc */
4698 0, /* ecoff_set_ext */
4699 coff_obj_read_begin_hook,
4700 coff_obj_symbol_new_hook