1 /* coff object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004
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"
33 /* I think this is probably always correct. */
34 #ifndef KEEP_RELOC_INFO
35 #define KEEP_RELOC_INFO
38 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
39 a new section's attributes when a directive has no valid flags or the
40 "w" flag is used. This default should be appropriate for most. */
41 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
42 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
45 /* This is used to hold the symbol built by a sequence of pseudo-ops
46 from .def and .endef. */
47 static symbolS *def_symbol_in_progress;
49 /* PE weak alternate symbols begin with this string. */
50 static const char weak_altprefix[] = ".weak.";
55 unsigned long chunk_size;
56 unsigned long element_size;
59 unsigned long pointer;
63 static stack *stack_init PARAMS ((unsigned long, unsigned long));
64 static char *stack_push PARAMS ((stack *, char *));
65 static char *stack_pop PARAMS ((stack *));
66 static void tag_init PARAMS ((void));
67 static void tag_insert PARAMS ((const char *, symbolS *));
68 static symbolS *tag_find PARAMS ((char *));
69 static symbolS *tag_find_or_make PARAMS ((char *));
70 static void obj_coff_bss PARAMS ((int));
72 static void obj_coff_weak PARAMS ((int));
74 const char *s_get_name PARAMS ((symbolS * s));
75 static void obj_coff_ln PARAMS ((int));
76 static void obj_coff_def PARAMS ((int));
77 static void obj_coff_endef PARAMS ((int));
78 static void obj_coff_dim PARAMS ((int));
79 static void obj_coff_line PARAMS ((int));
80 static void obj_coff_size PARAMS ((int));
81 static void obj_coff_scl PARAMS ((int));
82 static void obj_coff_tag PARAMS ((int));
83 static void obj_coff_val PARAMS ((int));
84 static void obj_coff_type PARAMS ((int));
85 static void obj_coff_ident PARAMS ((int));
87 static void obj_coff_loc PARAMS((int));
93 stack_init (chunk_size, element_size)
94 unsigned long chunk_size;
95 unsigned long element_size;
99 st = (stack *) malloc (sizeof (stack));
102 st->data = malloc (chunk_size);
109 st->size = chunk_size;
110 st->chunk_size = chunk_size;
111 st->element_size = element_size;
116 stack_push (st, element)
120 if (st->pointer + st->element_size >= st->size)
122 st->size += st->chunk_size;
123 if ((st->data = xrealloc (st->data, st->size)) == (char *) 0)
126 memcpy (st->data + st->pointer, element, st->element_size);
127 st->pointer += st->element_size;
128 return st->data + st->pointer;
135 if (st->pointer < st->element_size)
140 st->pointer -= st->element_size;
141 return st->data + st->pointer;
145 * Maintain a list of the tagnames of the structures.
148 static struct hash_control *tag_hash;
153 tag_hash = hash_new ();
157 tag_insert (name, symbolP)
161 const char *error_string;
163 if ((error_string = hash_jam (tag_hash, name, (char *) symbolP)))
165 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
174 #ifdef STRIP_UNDERSCORE
177 #endif /* STRIP_UNDERSCORE */
178 return (symbolS *) hash_find (tag_hash, name);
182 tag_find_or_make (name)
187 if ((symbolP = tag_find (name)) == NULL)
189 symbolP = symbol_new (name, undefined_section,
190 0, &zero_address_frag);
192 tag_insert (S_GET_NAME (symbolP), symbolP);
194 symbol_table_insert (symbolP);
201 /* We accept the .bss directive to set the section for backward
202 compatibility with earlier versions of gas. */
205 obj_coff_bss (ignore)
206 int ignore ATTRIBUTE_UNUSED;
208 if (*input_line_pointer == '\n')
209 subseg_new (".bss", get_absolute_expression ());
216 static segT fetch_coff_debug_section PARAMS ((void));
217 static void SA_SET_SYM_TAGNDX PARAMS ((symbolS *, symbolS *));
218 static int S_GET_DATA_TYPE PARAMS ((symbolS *));
219 void c_symbol_merge PARAMS ((symbolS *, symbolS *));
220 static void add_lineno PARAMS ((fragS *, addressT, int));
222 #define GET_FILENAME_STRING(X) \
223 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
227 fetch_coff_debug_section ()
229 static segT debug_section;
233 s = bfd_make_debug_symbol (stdoutput, (char *) 0, 0);
235 debug_section = s->section;
237 return debug_section;
241 SA_SET_SYM_ENDNDX (sym, val)
245 combined_entry_type *entry, *p;
247 entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
248 p = coffsymbol (symbol_get_bfdsym (val))->native;
249 entry->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p = p;
254 SA_SET_SYM_TAGNDX (sym, val)
258 combined_entry_type *entry, *p;
260 entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
261 p = coffsymbol (symbol_get_bfdsym (val))->native;
262 entry->u.auxent.x_sym.x_tagndx.p = p;
267 S_GET_DATA_TYPE (sym)
270 return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type;
274 S_SET_DATA_TYPE (sym, val)
278 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type = val;
283 S_GET_STORAGE_CLASS (sym)
286 return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass;
290 S_SET_STORAGE_CLASS (sym, val)
294 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass = val;
298 /* Merge a debug symbol containing debug information into a normal symbol. */
301 c_symbol_merge (debug, normal)
305 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
306 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
308 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
310 /* take the most we have */
311 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
314 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
316 /* Move all the auxiliary information. */
317 memcpy (SYM_AUXINFO (normal), SYM_AUXINFO (debug),
318 (S_GET_NUMBER_AUXILIARY (debug)
319 * sizeof (*SYM_AUXINFO (debug))));
322 /* Move the debug flags. */
323 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
327 c_dot_file_symbol (const char *filename, int appfile ATTRIBUTE_UNUSED)
331 /* BFD converts filename to a .file symbol with an aux entry. It
332 also handles chaining. */
333 symbolP = symbol_new (filename, bfd_abs_section_ptr, 0, &zero_address_frag);
335 S_SET_STORAGE_CLASS (symbolP, C_FILE);
336 S_SET_NUMBER_AUXILIARY (symbolP, 1);
338 symbol_get_bfdsym (symbolP)->flags = BSF_DEBUGGING;
345 listing_source_file (filename);
350 /* Make sure that the symbol is first on the symbol chain */
351 if (symbol_rootP != symbolP)
353 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
354 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
355 } /* if not first on the list */
358 /* Line number handling */
361 struct line_no *next;
368 /* Symbol of last function, which we should hang line#s off of. */
369 static symbolS *line_fsym;
371 #define in_function() (line_fsym != 0)
372 #define clear_function() (line_fsym = 0)
373 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
377 coff_obj_symbol_new_hook (symbolP)
380 long sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type);
381 char * s = (char *) xmalloc (sz);
384 coffsymbol (symbol_get_bfdsym (symbolP))->native = (combined_entry_type *) s;
386 S_SET_DATA_TYPE (symbolP, T_NULL);
387 S_SET_STORAGE_CLASS (symbolP, 0);
388 S_SET_NUMBER_AUXILIARY (symbolP, 0);
390 if (S_IS_STRING (symbolP))
391 SF_SET_STRING (symbolP);
393 if (S_IS_LOCAL (symbolP))
394 SF_SET_LOCAL (symbolP);
399 * Handle .ln directives.
402 static symbolS *current_lineno_sym;
403 static struct line_no *line_nos;
404 /* @@ Blindly assume all .ln directives will be in the .text section... */
408 add_lineno (frag, offset, num)
413 struct line_no *new_line =
414 (struct line_no *) xmalloc (sizeof (struct line_no));
415 if (!current_lineno_sym)
421 /* The native aix assembler accepts negative line number */
425 /* Zero is used as an end marker in the file. */
426 as_warn (_("Line numbers must be positive integers\n"));
429 #endif /* OBJ_XCOFF */
430 new_line->next = line_nos;
431 new_line->frag = frag;
432 new_line->l.line_number = num;
433 new_line->l.u.offset = offset;
439 coff_add_linesym (sym)
444 coffsymbol (symbol_get_bfdsym (current_lineno_sym))->lineno =
449 current_lineno_sym = sym;
453 obj_coff_ln (appline)
458 if (! appline && def_symbol_in_progress != NULL)
460 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
461 demand_empty_rest_of_line ();
465 l = get_absolute_expression ();
467 /* If there is no lineno symbol, treat a .ln
468 directive as if it were a .appline directive. */
469 if (appline || current_lineno_sym == NULL)
470 new_logical_line ((char *) NULL, l - 1);
472 add_lineno (frag_now, frag_now_fix (), l);
481 l += coff_line_base - 1;
482 listing_source_line (l);
487 demand_empty_rest_of_line ();
490 /* .loc is essentially the same as .ln; parse it for assembler
494 obj_coff_loc (ignore)
495 int ignore ATTRIBUTE_UNUSED;
499 /* FIXME: Why do we need this check? We need it for ECOFF, but why
500 do we need it for COFF? */
501 if (now_seg != text_section)
503 as_warn (_(".loc outside of .text"));
504 demand_empty_rest_of_line ();
508 if (def_symbol_in_progress != NULL)
510 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
511 demand_empty_rest_of_line ();
515 /* Skip the file number. */
517 get_absolute_expression ();
520 lineno = get_absolute_expression ();
528 lineno += coff_line_base - 1;
529 listing_source_line (lineno);
534 demand_empty_rest_of_line ();
536 add_lineno (frag_now, frag_now_fix (), lineno);
539 /* Handle the .ident pseudo-op. */
542 obj_coff_ident (ignore)
543 int ignore ATTRIBUTE_UNUSED;
545 segT current_seg = now_seg;
546 subsegT current_subseg = now_subseg;
552 /* We could put it in .comment, but that creates an extra section
553 that shouldn't be loaded into memory, which requires linker
554 changes... For now, until proven otherwise, use .rdata. */
555 sec = subseg_new (".rdata$zzz", 0);
556 bfd_set_section_flags (stdoutput, sec,
557 ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA)
558 & bfd_applicable_section_flags (stdoutput)));
561 subseg_new (".comment", 0);
565 subseg_set (current_seg, current_subseg);
571 * Handle .def directives.
573 * One might ask : why can't we symbol_new if the symbol does not
574 * already exist and fill it with debug information. Because of
575 * the C_EFCN special symbol. It would clobber the value of the
576 * function symbol before we have a chance to notice that it is
577 * a C_EFCN. And a second reason is that the code is more clear this
578 * way. (at least I think it is :-).
582 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
583 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
584 *input_line_pointer == '\t') \
585 input_line_pointer++;
589 int what ATTRIBUTE_UNUSED;
591 char name_end; /* Char after the end of name */
592 char *symbol_name; /* Name of the debug symbol */
593 char *symbol_name_copy; /* Temporary copy of the name */
594 unsigned int symbol_name_length;
596 if (def_symbol_in_progress != NULL)
598 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
599 demand_empty_rest_of_line ();
601 } /* if not inside .def/.endef */
605 symbol_name = input_line_pointer;
606 #ifdef STRIP_UNDERSCORE
607 if (symbol_name[0] == '_' && symbol_name[1] != 0)
609 #endif /* STRIP_UNDERSCORE */
611 name_end = get_symbol_end ();
612 symbol_name_length = strlen (symbol_name);
613 symbol_name_copy = xmalloc (symbol_name_length + 1);
614 strcpy (symbol_name_copy, symbol_name);
615 #ifdef tc_canonicalize_symbol_name
616 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
619 /* Initialize the new symbol */
620 def_symbol_in_progress = symbol_make (symbol_name_copy);
621 symbol_set_frag (def_symbol_in_progress, &zero_address_frag);
622 S_SET_VALUE (def_symbol_in_progress, 0);
624 if (S_IS_STRING (def_symbol_in_progress))
625 SF_SET_STRING (def_symbol_in_progress);
627 *input_line_pointer = name_end;
629 demand_empty_rest_of_line ();
632 unsigned int dim_index;
635 obj_coff_endef (ignore)
636 int ignore ATTRIBUTE_UNUSED;
638 symbolS *symbolP = NULL;
640 /* DIM BUG FIX sac@cygnus.com */
642 if (def_symbol_in_progress == NULL)
644 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
645 demand_empty_rest_of_line ();
647 } /* if not inside .def/.endef */
649 /* Set the section number according to storage class. */
650 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
655 SF_SET_TAG (def_symbol_in_progress);
656 /* intentional fallthrough */
659 SF_SET_DEBUG (def_symbol_in_progress);
660 S_SET_SEGMENT (def_symbol_in_progress, fetch_coff_debug_section ());
664 SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */
665 /* intentional fallthrough */
667 SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */
668 /* intentional fallthrough */
672 S_SET_SEGMENT (def_symbol_in_progress, text_section);
674 name = S_GET_NAME (def_symbol_in_progress);
675 if (name[0] == '.' && name[2] == 'f' && name[3] == '\0')
681 if (! in_function ())
682 as_warn (_("`%s' symbol without preceding function"), name);
683 /* Will need relocating. */
684 SF_SET_PROCESS (def_symbol_in_progress);
690 /* The MS compilers output the actual endline, not the
691 function-relative one... we want to match without
692 changing the assembler input. */
693 SA_SET_SYM_LNNO (def_symbol_in_progress,
694 (SA_GET_SYM_LNNO (def_symbol_in_progress)
705 #endif /* C_AUTOARG */
712 /* According to the COFF documentation:
714 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
716 A special section number (-2) marks symbolic debugging symbols,
717 including structure/union/enumeration tag names, typedefs, and
718 the name of the file. A section number of -1 indicates that the
719 symbol has a value but is not relocatable. Examples of
720 absolute-valued symbols include automatic and register variables,
721 function arguments, and .eos symbols.
723 But from Ian Lance Taylor:
725 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
727 the actual tools all marked them as section -1. So the GNU COFF
728 assembler follows historical COFF assemblers.
730 However, it causes problems for djgpp
732 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
734 By defining STRICTCOFF, a COFF port can make the assembler to
735 follow the documented behavior. */
742 SF_SET_DEBUG (def_symbol_in_progress);
743 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
751 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
762 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
769 as_warn (_("unexpected storage class %d"),
770 S_GET_STORAGE_CLASS (def_symbol_in_progress));
772 } /* switch on storage class */
774 /* Now that we have built a debug symbol, try to find if we should
775 merge with an existing symbol or not. If a symbol is C_EFCN or
776 absolute_section or untagged SEG_DEBUG it never merges. We also
777 don't merge labels, which are in a different namespace, nor
778 symbols which have not yet been defined since they are typically
779 unique, nor do we merge tags with non-tags. */
781 /* Two cases for functions. Either debug followed by definition or
782 definition followed by debug. For definition first, we will
783 merge the debug symbol into the definition. For debug first, the
784 lineno entry MUST point to the definition function or else it
785 will point off into space when obj_crawl_symbol_chain() merges
786 the debug symbol into the real symbol. Therefor, let's presume
787 the debug symbol is a real function reference. */
789 /* FIXME-SOON If for some reason the definition label/symbol is
790 never seen, this will probably leave an undefined symbol at link
793 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
794 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
795 || (!strcmp (bfd_get_section_name (stdoutput,
796 S_GET_SEGMENT (def_symbol_in_progress)),
798 && !SF_GET_TAG (def_symbol_in_progress))
799 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
800 || ! symbol_constant_p (def_symbol_in_progress)
801 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
802 DO_NOT_STRIP)) == NULL
803 || SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP))
805 /* If it already is at the end of the symbol list, do nothing */
806 if (def_symbol_in_progress != symbol_lastP)
808 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
809 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
815 /* This symbol already exists, merge the newly created symbol
816 into the old one. This is not mandatory. The linker can
817 handle duplicate symbols correctly. But I guess that it save
818 a *lot* of space if the assembly file defines a lot of
821 /* The debug entry (def_symbol_in_progress) is merged into the
822 previous definition. */
824 c_symbol_merge (def_symbol_in_progress, symbolP);
825 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
827 def_symbol_in_progress = symbolP;
829 if (SF_GET_FUNCTION (def_symbol_in_progress)
830 || SF_GET_TAG (def_symbol_in_progress)
831 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
833 /* For functions, and tags, and static symbols, the symbol
834 *must* be where the debug symbol appears. Move the
835 existing symbol to the current place. */
836 /* If it already is at the end of the symbol list, do nothing */
837 if (def_symbol_in_progress != symbol_lastP)
839 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
840 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, &symbol_lastP);
845 if (SF_GET_TAG (def_symbol_in_progress))
849 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
851 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
852 tag_insert (S_GET_NAME (def_symbol_in_progress),
853 def_symbol_in_progress);
856 if (SF_GET_FUNCTION (def_symbol_in_progress))
858 know (sizeof (def_symbol_in_progress) <= sizeof (long));
859 set_function (def_symbol_in_progress);
860 SF_SET_PROCESS (def_symbol_in_progress);
864 /* That is, if this is the first time we've seen the
866 symbol_table_insert (def_symbol_in_progress);
867 } /* definition follows debug */
868 } /* Create the line number entry pointing to the function being defined */
870 def_symbol_in_progress = NULL;
871 demand_empty_rest_of_line ();
875 obj_coff_dim (ignore)
876 int ignore ATTRIBUTE_UNUSED;
880 if (def_symbol_in_progress == NULL)
882 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
883 demand_empty_rest_of_line ();
885 } /* if not inside .def/.endef */
887 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
889 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
892 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
893 get_absolute_expression ());
895 switch (*input_line_pointer)
898 input_line_pointer++;
902 as_warn (_("badly formed .dim directive ignored"));
903 /* intentional fallthrough */
911 demand_empty_rest_of_line ();
915 obj_coff_line (ignore)
916 int ignore ATTRIBUTE_UNUSED;
920 if (def_symbol_in_progress == NULL)
922 /* Probably stabs-style line? */
927 this_base = get_absolute_expression ();
928 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress)))
929 coff_line_base = this_base;
931 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
932 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
934 demand_empty_rest_of_line ();
937 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress)) == 0)
942 listing_source_line ((unsigned int) this_base);
948 obj_coff_size (ignore)
949 int ignore ATTRIBUTE_UNUSED;
951 if (def_symbol_in_progress == NULL)
953 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
954 demand_empty_rest_of_line ();
956 } /* if not inside .def/.endef */
958 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
959 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
960 demand_empty_rest_of_line ();
964 obj_coff_scl (ignore)
965 int ignore ATTRIBUTE_UNUSED;
967 if (def_symbol_in_progress == NULL)
969 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
970 demand_empty_rest_of_line ();
972 } /* if not inside .def/.endef */
974 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
975 demand_empty_rest_of_line ();
979 obj_coff_tag (ignore)
980 int ignore ATTRIBUTE_UNUSED;
985 if (def_symbol_in_progress == NULL)
987 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
988 demand_empty_rest_of_line ();
992 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
993 symbol_name = input_line_pointer;
994 name_end = get_symbol_end ();
996 #ifdef tc_canonicalize_symbol_name
997 symbol_name = tc_canonicalize_symbol_name (symbol_name);
1000 /* Assume that the symbol referred to by .tag is always defined.
1001 This was a bad assumption. I've added find_or_make. xoxorich. */
1002 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
1003 tag_find_or_make (symbol_name));
1004 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
1006 as_warn (_("tag not found for .tag %s"), symbol_name);
1009 SF_SET_TAGGED (def_symbol_in_progress);
1010 *input_line_pointer = name_end;
1012 demand_empty_rest_of_line ();
1016 obj_coff_type (ignore)
1017 int ignore ATTRIBUTE_UNUSED;
1019 if (def_symbol_in_progress == NULL)
1021 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1022 demand_empty_rest_of_line ();
1024 } /* if not inside .def/.endef */
1026 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
1028 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
1029 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
1031 SF_SET_FUNCTION (def_symbol_in_progress);
1032 } /* is a function */
1034 demand_empty_rest_of_line ();
1038 obj_coff_val (ignore)
1039 int ignore ATTRIBUTE_UNUSED;
1041 if (def_symbol_in_progress == NULL)
1043 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1044 demand_empty_rest_of_line ();
1046 } /* if not inside .def/.endef */
1048 if (is_name_beginner (*input_line_pointer))
1050 char *symbol_name = input_line_pointer;
1051 char name_end = get_symbol_end ();
1053 #ifdef tc_canonicalize_symbol_name
1054 symbol_name = tc_canonicalize_symbol_name (symbol_name);
1056 if (!strcmp (symbol_name, "."))
1058 symbol_set_frag (def_symbol_in_progress, frag_now);
1059 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
1060 /* If the .val is != from the .def (e.g. statics) */
1062 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
1066 exp.X_op = O_symbol;
1067 exp.X_add_symbol = symbol_find_or_make (symbol_name);
1068 exp.X_op_symbol = NULL;
1069 exp.X_add_number = 0;
1070 symbol_set_value_expression (def_symbol_in_progress, &exp);
1072 /* If the segment is undefined when the forward reference is
1073 resolved, then copy the segment id from the forward
1075 SF_SET_GET_SEGMENT (def_symbol_in_progress);
1077 /* FIXME: gcc can generate address expressions here in
1078 unusual cases (search for "obscure" in sdbout.c). We
1079 just ignore the offset here, thus generating incorrect
1080 debugging information. We ignore the rest of the line
1083 /* Otherwise, it is the name of a non debug symbol and its value
1084 will be calculated later. */
1085 *input_line_pointer = name_end;
1089 S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ());
1090 } /* if symbol based */
1092 demand_empty_rest_of_line ();
1097 /* Return nonzero if name begins with weak alternate symbol prefix. */
1100 weak_is_altname (const char * name)
1102 return ! strncmp (name, weak_altprefix, sizeof (weak_altprefix) - 1);
1105 /* Return the name of the alternate symbol
1106 name corresponding to a weak symbol's name. */
1109 weak_name2altname (const char * name)
1113 alt_name = xmalloc (sizeof (weak_altprefix) + strlen (name));
1114 strcpy (alt_name, weak_altprefix);
1115 return strcat (alt_name, name);
1118 /* Return the name of the weak symbol corresponding to an
1122 weak_altname2name (const char * name)
1127 assert (weak_is_altname (name));
1129 weak_name = xstrdup (name + 6);
1130 if ((dot = strchr (weak_name, '.')))
1135 /* Make a weak symbol name unique by
1136 appending the name of an external symbol. */
1139 weak_uniquify (const char * name)
1142 const char * unique = "";
1145 if (an_external_name != NULL)
1146 unique = an_external_name;
1148 assert (weak_is_altname (name));
1150 if (strchr (name + sizeof (weak_altprefix), '.'))
1153 ret = xmalloc (strlen (name) + strlen (unique) + 2);
1156 strcat (ret, unique);
1162 /* Handle .weak. This is a GNU extension in formats other than PE. */
1165 obj_coff_weak (int ignore ATTRIBUTE_UNUSED)
1171 symbolS *alternateP;
1176 name = input_line_pointer;
1177 c = get_symbol_end ();
1180 as_warn (_("badly formed .weak directive ignored"));
1181 ignore_rest_of_line ();
1185 symbolP = symbol_find_or_make (name);
1186 *input_line_pointer = c;
1189 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
1190 S_SET_WEAK (symbolP);
1194 /* See _Microsoft Portable Executable and Common Object
1195 File Format Specification_, section 5.5.3.
1196 Create a symbol representing the alternate value.
1197 coff_frob_symbol will set the value of this symbol from
1198 the value of the weak symbol itself. */
1199 S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
1200 S_SET_NUMBER_AUXILIARY (symbolP, 1);
1201 SA_SET_SYM_FSIZE (symbolP, IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
1203 alternateP = symbol_find_or_make (weak_name2altname (name));
1204 S_SET_EXTERNAL (alternateP);
1205 S_SET_STORAGE_CLASS (alternateP, C_NT_WEAK);
1207 SA_SET_SYM_TAGNDX (symbolP, alternateP);
1212 input_line_pointer++;
1214 if (*input_line_pointer == '\n')
1221 demand_empty_rest_of_line ();
1225 coff_obj_read_begin_hook ()
1227 /* These had better be the same. Usually 18 bytes. */
1229 know (sizeof (SYMENT) == sizeof (AUXENT));
1230 know (SYMESZ == AUXESZ);
1235 symbolS *coff_last_function;
1237 static symbolS *coff_last_bf;
1241 coff_frob_symbol (symp, punt)
1245 static symbolS *last_tagP;
1246 static stack *block_stack;
1247 static symbolS *set_end;
1248 symbolS *next_set_end = NULL;
1250 if (symp == &abs_symbol)
1256 if (current_lineno_sym)
1257 coff_add_linesym ((symbolS *) 0);
1260 block_stack = stack_init (512, sizeof (symbolS*));
1263 if (S_GET_STORAGE_CLASS (symp) == C_NT_WEAK
1264 && ! S_IS_WEAK (symp)
1265 && weak_is_altname (S_GET_NAME (symp)))
1267 /* This is a weak alternate symbol. All processing of
1268 PECOFFweak symbols is done here, through the alternate. */
1269 symbolS *weakp = symbol_find (weak_altname2name (S_GET_NAME (symp)));
1272 assert (S_GET_NUMBER_AUXILIARY (weakp) == 1);
1274 if (symbol_equated_p (weakp))
1276 /* The weak symbol has an alternate specified; symp is unneeded. */
1277 S_SET_STORAGE_CLASS (weakp, C_NT_WEAK);
1278 SA_SET_SYM_TAGNDX (weakp,
1279 symbol_get_value_expression (weakp)->X_add_symbol);
1281 S_CLEAR_EXTERNAL (symp);
1287 /* The weak symbol has been assigned an alternate value.
1288 Copy this value to symp, and set symp as weakp's alternate. */
1289 if (S_GET_STORAGE_CLASS (weakp) != C_NT_WEAK)
1291 S_SET_STORAGE_CLASS (symp, S_GET_STORAGE_CLASS (weakp));
1292 S_SET_STORAGE_CLASS (weakp, C_NT_WEAK);
1295 if (S_IS_DEFINED (weakp))
1297 /* This is a defined weak symbol. Copy value information
1298 from the weak symbol itself to the alternate symbol. */
1299 symbol_set_value_expression (symp,
1300 symbol_get_value_expression (weakp));
1301 symbol_set_frag (symp, symbol_get_frag (weakp));
1302 S_SET_SEGMENT (symp, S_GET_SEGMENT (weakp));
1306 /* This is an undefined weak symbol.
1307 Define the alternate symbol to zero. */
1308 S_SET_VALUE (symp, 0);
1309 S_SET_SEGMENT (symp, absolute_section);
1312 S_SET_NAME (symp, weak_uniquify (S_GET_NAME (symp)));
1313 S_SET_STORAGE_CLASS (symp, C_EXT);
1315 S_SET_VALUE (weakp, 0);
1316 S_SET_SEGMENT (weakp, undefined_section);
1320 if (S_IS_WEAK (symp))
1321 S_SET_STORAGE_CLASS (symp, C_WEAKEXT);
1324 if (!S_IS_DEFINED (symp)
1325 && !S_IS_WEAK (symp)
1326 && S_GET_STORAGE_CLASS (symp) != C_STAT)
1327 S_SET_STORAGE_CLASS (symp, C_EXT);
1329 if (!SF_GET_DEBUG (symp))
1333 if (!SF_GET_LOCAL (symp)
1334 && !SF_GET_STATICS (symp)
1335 && S_GET_STORAGE_CLASS (symp) != C_LABEL
1336 && symbol_constant_p(symp)
1337 && (real = symbol_find_base (S_GET_NAME (symp), DO_NOT_STRIP))
1338 && S_GET_STORAGE_CLASS (real) == C_NULL
1341 c_symbol_merge (symp, real);
1346 if (!S_IS_DEFINED (symp) && !SF_GET_LOCAL (symp))
1348 assert (S_GET_VALUE (symp) == 0);
1349 S_SET_EXTERNAL (symp);
1351 else if (S_GET_STORAGE_CLASS (symp) == C_NULL)
1353 if (S_GET_SEGMENT (symp) == text_section
1354 && symp != seg_info (text_section)->sym)
1355 S_SET_STORAGE_CLASS (symp, C_LABEL);
1357 S_SET_STORAGE_CLASS (symp, C_STAT);
1360 if (SF_GET_PROCESS (symp))
1362 if (S_GET_STORAGE_CLASS (symp) == C_BLOCK)
1364 if (!strcmp (S_GET_NAME (symp), ".bb"))
1365 stack_push (block_stack, (char *) &symp);
1370 begin = *(symbolS **) stack_pop (block_stack);
1372 as_warn (_("mismatched .eb"));
1374 next_set_end = begin;
1378 if (coff_last_function == 0 && SF_GET_FUNCTION (symp))
1380 union internal_auxent *auxp;
1382 coff_last_function = symp;
1383 if (S_GET_NUMBER_AUXILIARY (symp) < 1)
1384 S_SET_NUMBER_AUXILIARY (symp, 1);
1385 auxp = SYM_AUXENT (symp);
1386 memset (auxp->x_sym.x_fcnary.x_ary.x_dimen, 0,
1387 sizeof (auxp->x_sym.x_fcnary.x_ary.x_dimen));
1390 if (S_GET_STORAGE_CLASS (symp) == C_EFCN)
1392 if (coff_last_function == 0)
1393 as_fatal (_("C_EFCN symbol out of scope"));
1394 SA_SET_SYM_FSIZE (coff_last_function,
1395 (long) (S_GET_VALUE (symp)
1396 - S_GET_VALUE (coff_last_function)));
1397 next_set_end = coff_last_function;
1398 coff_last_function = 0;
1402 if (S_IS_EXTERNAL (symp))
1403 S_SET_STORAGE_CLASS (symp, C_EXT);
1404 else if (SF_GET_LOCAL (symp))
1407 if (SF_GET_FUNCTION (symp))
1408 symbol_get_bfdsym (symp)->flags |= BSF_FUNCTION;
1413 /* Double check weak symbols. */
1414 if (S_IS_WEAK (symp) && S_IS_COMMON (symp))
1415 as_bad (_("Symbol `%s' can not be both weak and common"),
1418 if (SF_GET_TAG (symp))
1420 else if (S_GET_STORAGE_CLASS (symp) == C_EOS)
1421 next_set_end = last_tagP;
1424 /* This is pretty horrible, but we have to set *punt correctly in
1425 order to call SA_SET_SYM_ENDNDX correctly. */
1426 if (! symbol_used_in_reloc_p (symp)
1427 && ((symbol_get_bfdsym (symp)->flags & BSF_SECTION_SYM) != 0
1428 || (! (S_IS_EXTERNAL (symp) || S_IS_WEAK (symp))
1429 && ! symbol_get_tc (symp)->output
1430 && S_GET_STORAGE_CLASS (symp) != C_FILE)))
1434 if (set_end != (symbolS *) NULL
1436 && ((symbol_get_bfdsym (symp)->flags & BSF_NOT_AT_END) != 0
1437 || (S_IS_DEFINED (symp)
1438 && ! S_IS_COMMON (symp)
1439 && (! S_IS_EXTERNAL (symp) || SF_GET_FUNCTION (symp)))))
1441 SA_SET_SYM_ENDNDX (set_end, symp);
1445 if (next_set_end != NULL)
1447 if (set_end != NULL)
1448 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1449 S_GET_NAME (set_end));
1450 set_end = next_set_end;
1455 && S_GET_STORAGE_CLASS (symp) == C_FCN
1456 && strcmp (S_GET_NAME (symp), ".bf") == 0)
1458 if (coff_last_bf != NULL)
1459 SA_SET_SYM_ENDNDX (coff_last_bf, symp);
1460 coff_last_bf = symp;
1463 if (coffsymbol (symbol_get_bfdsym (symp))->lineno)
1466 struct line_no *lptr;
1469 lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
1470 for (i = 0; lptr; lptr = lptr->next)
1472 lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
1474 /* We need i entries for line numbers, plus 1 for the first
1475 entry which BFD will override, plus 1 for the last zero
1476 entry (a marker for BFD). */
1477 l = (alent *) xmalloc ((i + 2) * sizeof (alent));
1478 coffsymbol (symbol_get_bfdsym (symp))->lineno = l;
1479 l[i + 1].line_number = 0;
1480 l[i + 1].u.sym = NULL;
1484 lptr->l.u.offset += lptr->frag->fr_address / OCTETS_PER_BYTE;
1492 coff_adjust_section_syms (abfd, sec, x)
1493 bfd *abfd ATTRIBUTE_UNUSED;
1495 PTR x ATTRIBUTE_UNUSED;
1498 segment_info_type *seginfo = seg_info (sec);
1499 int nlnno, nrelocs = 0;
1501 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1502 tc-ppc.c. Do not get confused by it. */
1503 if (seginfo == NULL)
1506 if (!strcmp (sec->name, ".text"))
1507 nlnno = coff_n_line_nos;
1511 /* @@ Hope that none of the fixups expand to more than one reloc
1513 fixS *fixp = seginfo->fix_root;
1516 if (! fixp->fx_done)
1518 fixp = fixp->fx_next;
1521 if (bfd_get_section_size (sec) == 0
1524 && sec != text_section
1525 && sec != data_section
1526 && sec != bss_section)
1528 secsym = section_symbol (sec);
1529 /* This is an estimate; we'll plug in the real value using
1530 SET_SECTION_RELOCS later */
1531 SA_SET_SCN_NRELOC (secsym, nrelocs);
1532 SA_SET_SCN_NLINNO (secsym, nlnno);
1536 coff_frob_file_after_relocs ()
1538 bfd_map_over_sections (stdoutput, coff_adjust_section_syms, (char*) 0);
1541 /* Implement the .section pseudo op:
1542 .section name {, "flags"}
1544 | +--- optional flags: 'b' for bss
1546 +-- section name 'l' for lib
1550 'd' (apparently m88k for data)
1552 'r' for read-only data
1553 's' for shared data (PE)
1554 But if the argument is not a quoted string, treat it as a
1557 Note the 'a' flag is silently ignored. This allows the same
1558 .section directive to be parsed in both ELF and COFF formats. */
1561 obj_coff_section (ignore)
1562 int ignore ATTRIBUTE_UNUSED;
1564 /* Strip out the section name */
1569 flagword flags, oldflags;
1580 section_name = input_line_pointer;
1581 c = get_symbol_end ();
1583 name = xmalloc (input_line_pointer - section_name + 1);
1584 strcpy (name, section_name);
1586 *input_line_pointer = c;
1591 flags = SEC_NO_FLAGS;
1593 if (*input_line_pointer == ',')
1595 ++input_line_pointer;
1597 if (*input_line_pointer != '"')
1598 exp = get_absolute_expression ();
1601 ++input_line_pointer;
1602 while (*input_line_pointer != '"'
1603 && ! is_end_of_line[(unsigned char) *input_line_pointer])
1605 switch (*input_line_pointer)
1607 case 'b': flags |= SEC_ALLOC; flags &=~ SEC_LOAD; break;
1608 case 'n': flags &=~ SEC_LOAD; flags |= SEC_NEVER_LOAD; break;
1610 case 's': flags |= SEC_SHARED; /* fall through */
1611 case 'd': flags |= SEC_DATA | SEC_LOAD; /* fall through */
1612 case 'w': flags &=~ SEC_READONLY; break;
1614 case 'a': break; /* For compatibility with ELF. */
1615 case 'x': flags |= SEC_CODE | SEC_LOAD; break;
1616 case 'r': flags |= SEC_DATA | SEC_LOAD | SEC_READONLY; break;
1618 case 'i': /* STYP_INFO */
1619 case 'l': /* STYP_LIB */
1620 case 'o': /* STYP_OVER */
1621 as_warn (_("unsupported section attribute '%c'"),
1622 *input_line_pointer);
1626 as_warn(_("unknown section attribute '%c'"),
1627 *input_line_pointer);
1630 ++input_line_pointer;
1632 if (*input_line_pointer == '"')
1633 ++input_line_pointer;
1637 sec = subseg_new (name, (subsegT) exp);
1639 oldflags = bfd_get_section_flags (stdoutput, sec);
1640 if (oldflags == SEC_NO_FLAGS)
1642 /* Set section flags for a new section just created by subseg_new.
1643 Provide a default if no flags were parsed. */
1644 if (flags == SEC_NO_FLAGS)
1645 flags = TC_COFF_SECTION_DEFAULT_ATTRIBUTES;
1647 #ifdef COFF_LONG_SECTION_NAMES
1648 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1649 sections so adjust_reloc_syms in write.c will correctly handle
1650 relocs which refer to non-local symbols in these sections. */
1651 if (strncmp (name, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1652 flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1655 if (! bfd_set_section_flags (stdoutput, sec, flags))
1656 as_warn (_("error setting flags for \"%s\": %s"),
1657 bfd_section_name (stdoutput, sec),
1658 bfd_errmsg (bfd_get_error ()));
1660 else if (flags != SEC_NO_FLAGS)
1662 /* This section's attributes have already been set. Warn if the
1663 attributes don't match. */
1664 flagword matchflags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
1665 | SEC_DATA | SEC_SHARED | SEC_NEVER_LOAD);
1666 if ((flags ^ oldflags) & matchflags)
1667 as_warn (_("Ignoring changed section attributes for %s"), name);
1670 demand_empty_rest_of_line ();
1674 coff_adjust_symtab ()
1676 if (symbol_rootP == NULL
1677 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
1678 c_dot_file_symbol ("fake", 0);
1682 coff_frob_section (sec)
1688 bfd_vma size, n_entries, mask;
1689 bfd_vma align_power = (bfd_vma)sec->alignment_power + OCTETS_PER_BYTE_POWER;
1691 /* The COFF back end in BFD requires that all section sizes be
1692 rounded up to multiples of the corresponding section alignments,
1693 supposedly because standard COFF has no other way of encoding alignment
1694 for sections. If your COFF flavor has a different way of encoding
1695 section alignment, then skip this step, as TICOFF does. */
1696 size = bfd_get_section_size (sec);
1697 mask = ((bfd_vma) 1 << align_power) - 1;
1698 #if !defined(TICOFF)
1704 new_size = (size + mask) & ~mask;
1705 bfd_set_section_size (stdoutput, sec, new_size);
1707 /* If the size had to be rounded up, add some padding in
1708 the last non-empty frag. */
1709 fragp = seg_info (sec)->frchainP->frch_root;
1710 last = seg_info (sec)->frchainP->frch_last;
1711 while (fragp->fr_next != last)
1712 fragp = fragp->fr_next;
1713 last->fr_address = size;
1714 fragp->fr_offset += new_size - size;
1718 /* If the section size is non-zero, the section symbol needs an aux
1719 entry associated with it, indicating the size. We don't know
1720 all the values yet; coff_frob_symbol will fill them in later. */
1723 || sec == text_section
1724 || sec == data_section
1725 || sec == bss_section)
1728 symbolS *secsym = section_symbol (sec);
1730 S_SET_STORAGE_CLASS (secsym, C_STAT);
1731 S_SET_NUMBER_AUXILIARY (secsym, 1);
1732 SF_SET_STATICS (secsym);
1733 SA_SET_SCN_SCNLEN (secsym, size);
1736 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1737 #ifndef STAB_SECTION_NAME
1738 #define STAB_SECTION_NAME ".stab"
1740 #ifndef STAB_STRING_SECTION_NAME
1741 #define STAB_STRING_SECTION_NAME ".stabstr"
1743 if (strcmp (STAB_STRING_SECTION_NAME, sec->name))
1747 sec = subseg_get (STAB_SECTION_NAME, 0);
1748 /* size is already rounded up, since other section will be listed first */
1749 size = bfd_get_section_size (strsec);
1751 n_entries = bfd_get_section_size (sec) / 12 - 1;
1753 /* Find first non-empty frag. It should be large enough. */
1754 fragp = seg_info (sec)->frchainP->frch_root;
1755 while (fragp && fragp->fr_fix == 0)
1756 fragp = fragp->fr_next;
1757 assert (fragp != 0 && fragp->fr_fix >= 12);
1759 /* Store the values. */
1760 p = fragp->fr_literal;
1761 bfd_h_put_16 (stdoutput, n_entries, (bfd_byte *) p + 6);
1762 bfd_h_put_32 (stdoutput, size, (bfd_byte *) p + 8);
1766 obj_coff_init_stab_section (seg)
1772 unsigned int stroff;
1774 /* Make space for this first symbol. */
1778 as_where (&file, (unsigned int *) NULL);
1779 stabstr_name = (char *) xmalloc (strlen (seg->name) + 4);
1780 strcpy (stabstr_name, seg->name);
1781 strcat (stabstr_name, "str");
1782 stroff = get_stab_string_offset (file, stabstr_name);
1784 md_number_to_chars (p, stroff, 4);
1793 return ((s == NULL) ? "(NULL)" : S_GET_NAME (s));
1801 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
1803 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1804 (unsigned long) symbolP,
1805 S_GET_NAME(symbolP),
1806 (long) S_GET_DATA_TYPE(symbolP),
1807 S_GET_STORAGE_CLASS(symbolP),
1808 (int) S_GET_SEGMENT(symbolP));
1814 #else /* not BFD_ASSEMBLER */
1817 /* This is needed because we include internal bfd things. */
1821 #include "libcoff.h"
1823 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1824 that we can stick sections together without causing trouble. */
1826 #define NOP_OPCODE 0x00
1829 /* The zeroes if symbol name is longer than 8 chars */
1830 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1832 #define MIN(a,b) ((a) < (b)? (a) : (b))
1834 /* This vector is used to turn a gas internal segment number into a
1835 section number suitable for insertion into a coff symbol table.
1836 This must correspond to seg_info_off_by_4. */
1838 const short seg_N_TYPE[] =
1839 { /* in: segT out: N_TYPE bits */
1841 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1842 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1843 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1844 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1845 C_UNDEF_SECTION, /* SEG_UNKNOWN */
1846 C_UNDEF_SECTION, /* SEG_GOOF */
1847 C_UNDEF_SECTION, /* SEG_EXPR */
1848 C_DEBUG_SECTION, /* SEG_DEBUG */
1849 C_NTV_SECTION, /* SEG_NTV */
1850 C_PTV_SECTION, /* SEG_PTV */
1851 C_REGISTER_SECTION, /* SEG_REGISTER */
1854 int function_lineoff = -1; /* Offset in line#s where the last function
1855 started (the odd entry for line #0) */
1857 /* Structure used to keep the filenames which
1858 are too long around so that we can stick them
1859 into the string table. */
1860 struct filename_list
1863 struct filename_list *next;
1866 static struct filename_list *filename_list_head;
1867 static struct filename_list *filename_list_tail;
1869 static symbolS *last_line_symbol;
1871 /* Add 4 to the real value to get the index and compensate the
1872 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1873 section number into a segment number. */
1876 static symbolS *previous_file_symbol;
1877 static int line_base;
1879 void c_symbol_merge PARAMS ((symbolS *, symbolS *));
1880 symbolS *c_section_symbol PARAMS ((char *, int));
1881 void obj_coff_section PARAMS ((int));
1882 void do_relocs_for PARAMS ((bfd *, object_headers *, unsigned long *));
1883 char * symbol_to_chars PARAMS ((bfd *, char *, symbolS *));
1884 void w_strings PARAMS ((char *));
1886 static void fixup_segment PARAMS ((segment_info_type *, segT));
1887 static void fixup_mdeps PARAMS ((fragS *, object_headers *, segT));
1888 static void fill_section PARAMS ((bfd *, object_headers *, unsigned long *));
1889 static int c_line_new PARAMS ((symbolS *, long, int, fragS *));
1890 static void w_symbols PARAMS ((bfd *, char *, symbolS *));
1891 static void adjust_stab_section PARAMS ((bfd *, segT));
1892 static void obj_coff_lcomm PARAMS ((int));
1893 static void obj_coff_text PARAMS ((int));
1894 static void obj_coff_data PARAMS ((int));
1895 static unsigned int count_entries_in_chain PARAMS ((unsigned int));
1896 static void coff_header_append PARAMS ((bfd *, object_headers *));
1897 static unsigned int yank_symbols PARAMS ((void));
1898 static unsigned int glue_symbols PARAMS ((symbolS **, symbolS **));
1899 static unsigned int tie_tags PARAMS ((void));
1900 static void crawl_symbols PARAMS ((object_headers *, bfd *));
1901 static void do_linenos_for PARAMS ((bfd *, object_headers *, unsigned long *));
1902 static void remove_subsegs PARAMS ((void));
1906 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1908 This array maps a COFF section number into a gas section number.
1909 Because COFF uses negative section numbers, you must add 4 to the
1910 COFF section number when indexing into this array; this is done via
1911 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1914 static const segT seg_info_off_by_4[] =
1921 SEG_E0, SEG_E1, SEG_E2, SEG_E3, SEG_E4,
1922 SEG_E5, SEG_E6, SEG_E7, SEG_E8, SEG_E9,
1923 SEG_E10, SEG_E11, SEG_E12, SEG_E13, SEG_E14,
1924 SEG_E15, SEG_E16, SEG_E17, SEG_E18, SEG_E19,
1925 SEG_E20, SEG_E21, SEG_E22, SEG_E23, SEG_E24,
1926 SEG_E25, SEG_E26, SEG_E27, SEG_E28, SEG_E29,
1927 SEG_E30, SEG_E31, SEG_E32, SEG_E33, SEG_E34,
1928 SEG_E35, SEG_E36, SEG_E37, SEG_E38, SEG_E39,
1941 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1943 static relax_addressT relax_align PARAMS ((relax_addressT, long));
1945 static relax_addressT
1946 relax_align (address, alignment)
1947 relax_addressT address;
1950 relax_addressT mask;
1951 relax_addressT new_address;
1953 mask = ~((~0) << alignment);
1954 new_address = (address + mask) & (~mask);
1955 return (new_address - address);
1962 return SEG_INFO_FROM_SECTION_NUMBER (x->sy_symbol.ost_entry.n_scnum);
1965 static unsigned int size_section PARAMS ((bfd *, unsigned int));
1967 /* Calculate the size of the frag chain and fill in the section header
1968 to contain all of it, also fill in the addr of the sections. */
1971 size_section (abfd, idx)
1972 bfd *abfd ATTRIBUTE_UNUSED;
1975 unsigned int size = 0;
1976 fragS *frag = segment_info[idx].frchainP->frch_root;
1980 size = frag->fr_address;
1981 if (frag->fr_address != size)
1983 fprintf (stderr, _("Out of step\n"));
1984 size = frag->fr_address;
1987 switch (frag->fr_type)
1989 #ifdef TC_COFF_SIZEMACHDEP
1990 case rs_machine_dependent:
1991 size += TC_COFF_SIZEMACHDEP (frag);
1997 size += frag->fr_fix;
1998 size += frag->fr_offset * frag->fr_var;
2006 size += frag->fr_fix;
2007 off = relax_align (size, frag->fr_offset);
2008 if (frag->fr_subtype != 0 && off > frag->fr_subtype)
2014 BAD_CASE (frag->fr_type);
2017 frag = frag->fr_next;
2019 segment_info[idx].scnhdr.s_size = size;
2024 count_entries_in_chain (idx)
2027 unsigned int nrelocs;
2030 /* Count the relocations. */
2031 fixup_ptr = segment_info[idx].fix_root;
2033 while (fixup_ptr != (fixS *) NULL)
2035 if (fixup_ptr->fx_done == 0 && TC_COUNT_RELOC (fixup_ptr))
2037 #if defined(TC_A29K) || defined(TC_OR32)
2038 if (fixup_ptr->fx_r_type == RELOC_CONSTH)
2047 fixup_ptr = fixup_ptr->fx_next;
2054 static int compare_external_relocs PARAMS ((const PTR, const PTR));
2056 /* AUX's ld expects relocations to be sorted. */
2059 compare_external_relocs (x, y)
2063 struct external_reloc *a = (struct external_reloc *) x;
2064 struct external_reloc *b = (struct external_reloc *) y;
2065 bfd_vma aadr = bfd_getb32 (a->r_vaddr);
2066 bfd_vma badr = bfd_getb32 (b->r_vaddr);
2067 return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
2072 /* Output all the relocations for a section. */
2075 do_relocs_for (abfd, h, file_cursor)
2078 unsigned long *file_cursor;
2080 unsigned int nrelocs;
2082 unsigned long reloc_start = *file_cursor;
2084 for (idx = SEG_E0; idx < SEG_LAST; idx++)
2086 if (segment_info[idx].scnhdr.s_name[0])
2088 struct external_reloc *ext_ptr;
2089 struct external_reloc *external_reloc_vec;
2090 unsigned int external_reloc_size;
2091 unsigned int base = segment_info[idx].scnhdr.s_paddr;
2092 fixS *fix_ptr = segment_info[idx].fix_root;
2093 nrelocs = count_entries_in_chain (idx);
2096 /* Bypass this stuff if no relocs. This also incidentally
2097 avoids a SCO bug, where free(malloc(0)) tends to crash. */
2099 external_reloc_size = nrelocs * RELSZ;
2100 external_reloc_vec =
2101 (struct external_reloc *) malloc (external_reloc_size);
2103 ext_ptr = external_reloc_vec;
2105 /* Fill in the internal coff style reloc struct from the
2106 internal fix list. */
2109 struct internal_reloc intr;
2111 /* Only output some of the relocations. */
2112 if (fix_ptr->fx_done == 0 && TC_COUNT_RELOC (fix_ptr))
2114 #ifdef TC_RELOC_MANGLE
2115 TC_RELOC_MANGLE (&segment_info[idx], fix_ptr, &intr,
2119 symbolS *symbol_ptr = fix_ptr->fx_addsy;
2121 intr.r_type = TC_COFF_FIX2RTYPE (fix_ptr);
2123 base + fix_ptr->fx_frag->fr_address + fix_ptr->fx_where;
2125 #ifdef TC_KEEP_FX_OFFSET
2126 intr.r_offset = fix_ptr->fx_offset;
2131 while (symbol_ptr->sy_value.X_op == O_symbol
2132 && (! S_IS_DEFINED (symbol_ptr)
2133 || S_IS_COMMON (symbol_ptr)))
2137 /* We must avoid looping, as that can occur
2138 with a badly written program. */
2139 n = symbol_ptr->sy_value.X_add_symbol;
2140 if (n == symbol_ptr)
2145 /* Turn the segment of the symbol into an offset. */
2148 resolve_symbol_value (symbol_ptr);
2149 if (! symbol_ptr->sy_resolved)
2154 if (expr_symbol_where (symbol_ptr, &file, &line))
2155 as_bad_where (file, line,
2156 _("unresolved relocation"));
2158 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
2159 S_GET_NAME (symbol_ptr));
2162 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
2164 intr.r_symndx = dot->sy_number;
2166 intr.r_symndx = symbol_ptr->sy_number;
2171 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
2173 #if defined(TC_A29K)
2174 /* The 29k has a special kludge for the high 16 bit
2175 reloc. Two relocations are emitted, R_IHIHALF,
2176 and R_IHCONST. The second one doesn't contain a
2177 symbol, but uses the value for offset. */
2178 if (intr.r_type == R_IHIHALF)
2180 /* Now emit the second bit. */
2181 intr.r_type = R_IHCONST;
2182 intr.r_symndx = fix_ptr->fx_addnumber;
2183 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
2187 #if defined(TC_OR32)
2188 /* The or32 has a special kludge for the high 16 bit
2189 reloc. Two relocations are emitted, R_IHIHALF,
2190 and R_IHCONST. The second one doesn't contain a
2191 symbol, but uses the value for offset. */
2192 if (intr.r_type == R_IHIHALF)
2194 /* Now emit the second bit. */
2195 intr.r_type = R_IHCONST;
2196 intr.r_symndx = fix_ptr->fx_addnumber;
2197 (void) bfd_coff_swap_reloc_out (abfd, & intr, ext_ptr);
2203 fix_ptr = fix_ptr->fx_next;
2206 /* Sort the reloc table. */
2207 qsort ((PTR) external_reloc_vec, nrelocs,
2208 sizeof (struct external_reloc), compare_external_relocs);
2210 /* Write out the reloc table. */
2211 bfd_bwrite ((PTR) external_reloc_vec,
2212 (bfd_size_type) external_reloc_size, abfd);
2213 free (external_reloc_vec);
2215 /* Fill in section header info. */
2216 segment_info[idx].scnhdr.s_relptr = *file_cursor;
2217 *file_cursor += external_reloc_size;
2218 segment_info[idx].scnhdr.s_nreloc = nrelocs;
2223 segment_info[idx].scnhdr.s_relptr = 0;
2228 /* Set relocation_size field in file headers. */
2229 H_SET_RELOCATION_SIZE (h, *file_cursor - reloc_start, 0);
2232 /* Run through a frag chain and write out the data to go with it, fill
2233 in the scnhdrs with the info on the file positions. */
2236 fill_section (abfd, h, file_cursor)
2238 object_headers *h ATTRIBUTE_UNUSED;
2239 unsigned long *file_cursor;
2242 unsigned int paddr = 0;
2244 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
2246 unsigned int offset = 0;
2247 struct internal_scnhdr *s = &(segment_info[i].scnhdr);
2253 fragS *frag = segment_info[i].frchainP->frch_root;
2254 char *buffer = NULL;
2260 buffer = xmalloc (s->s_size);
2261 s->s_scnptr = *file_cursor;
2263 know (s->s_paddr == paddr);
2265 if (strcmp (s->s_name, ".text") == 0)
2266 s->s_flags |= STYP_TEXT;
2267 else if (strcmp (s->s_name, ".data") == 0)
2268 s->s_flags |= STYP_DATA;
2269 else if (strcmp (s->s_name, ".bss") == 0)
2272 s->s_flags |= STYP_BSS;
2274 /* @@ Should make the i386 and a29k coff targets define
2275 COFF_NOLOAD_PROBLEM, and have only one test here. */
2279 #ifndef COFF_NOLOAD_PROBLEM
2280 /* Apparently the SVR3 linker (and exec syscall) and UDI
2281 mondfe progrem are confused by noload sections. */
2282 s->s_flags |= STYP_NOLOAD;
2288 else if (strcmp (s->s_name, ".lit") == 0)
2289 s->s_flags = STYP_LIT | STYP_TEXT;
2290 else if (strcmp (s->s_name, ".init") == 0)
2291 s->s_flags |= STYP_TEXT;
2292 else if (strcmp (s->s_name, ".fini") == 0)
2293 s->s_flags |= STYP_TEXT;
2294 else if (strncmp (s->s_name, ".comment", 8) == 0)
2295 s->s_flags |= STYP_INFO;
2299 unsigned int fill_size;
2300 switch (frag->fr_type)
2302 case rs_machine_dependent:
2305 memcpy (buffer + frag->fr_address,
2307 (unsigned int) frag->fr_fix);
2308 offset += frag->fr_fix;
2320 memcpy (buffer + frag->fr_address,
2322 (unsigned int) frag->fr_fix);
2323 offset += frag->fr_fix;
2326 fill_size = frag->fr_var;
2327 if (fill_size && frag->fr_offset > 0)
2330 unsigned int off = frag->fr_fix;
2331 for (count = frag->fr_offset; count; count--)
2333 if (fill_size + frag->fr_address + off <= s->s_size)
2335 memcpy (buffer + frag->fr_address + off,
2336 frag->fr_literal + frag->fr_fix,
2339 offset += fill_size;
2344 case rs_broken_word:
2349 frag = frag->fr_next;
2354 if (s->s_scnptr != 0)
2356 bfd_bwrite (buffer, s->s_size, abfd);
2357 *file_cursor += s->s_size;
2366 /* Coff file generation & utilities. */
2369 coff_header_append (abfd, h)
2376 #ifdef COFF_LONG_SECTION_NAMES
2377 unsigned long string_size = 4;
2380 bfd_seek (abfd, (file_ptr) 0, 0);
2382 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2383 H_SET_MAGIC_NUMBER (h, COFF_MAGIC);
2384 H_SET_VERSION_STAMP (h, 0);
2385 H_SET_ENTRY_POINT (h, 0);
2386 H_SET_TEXT_START (h, segment_info[SEG_E0].frchainP->frch_root->fr_address);
2387 H_SET_DATA_START (h, segment_info[SEG_E1].frchainP->frch_root->fr_address);
2388 H_SET_SIZEOF_OPTIONAL_HEADER (h, bfd_coff_swap_aouthdr_out(abfd, &h->aouthdr,
2390 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2391 H_SET_SIZEOF_OPTIONAL_HEADER (h, 0);
2392 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2394 i = bfd_coff_swap_filehdr_out (abfd, &h->filehdr, buffer);
2396 bfd_bwrite (buffer, (bfd_size_type) i, abfd);
2397 bfd_bwrite (buffero, (bfd_size_type) H_GET_SIZEOF_OPTIONAL_HEADER (h), abfd);
2399 for (i = SEG_E0; i < SEG_LAST; i++)
2401 if (segment_info[i].scnhdr.s_name[0])
2405 #ifdef COFF_LONG_SECTION_NAMES
2406 /* Support long section names as found in PE. This code
2407 must coordinate with that in write_object_file and
2409 if (strlen (segment_info[i].name) > SCNNMLEN)
2411 memset (segment_info[i].scnhdr.s_name, 0, SCNNMLEN);
2412 sprintf (segment_info[i].scnhdr.s_name, "/%lu", string_size);
2413 string_size += strlen (segment_info[i].name) + 1;
2416 size = bfd_coff_swap_scnhdr_out (abfd,
2417 &(segment_info[i].scnhdr),
2420 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2421 bfd_bwrite (buffer, (bfd_size_type) size, abfd);
2427 symbol_to_chars (abfd, where, symbolP)
2432 unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux;
2436 /* Turn any symbols with register attributes into abs symbols. */
2437 if (S_GET_SEGMENT (symbolP) == reg_section)
2438 S_SET_SEGMENT (symbolP, absolute_section);
2440 /* At the same time, relocate all symbols to their output value. */
2442 val = (segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_paddr
2443 + S_GET_VALUE (symbolP));
2445 val = S_GET_VALUE (symbolP);
2448 S_SET_VALUE (symbolP, val);
2450 symbolP->sy_symbol.ost_entry.n_value = val;
2452 where += bfd_coff_swap_sym_out (abfd, &symbolP->sy_symbol.ost_entry,
2455 for (i = 0; i < numaux; i++)
2457 where += bfd_coff_swap_aux_out (abfd,
2458 &symbolP->sy_symbol.ost_auxent[i],
2459 S_GET_DATA_TYPE (symbolP),
2460 S_GET_STORAGE_CLASS (symbolP),
2468 coff_obj_symbol_new_hook (symbolP)
2471 char underscore = 0; /* Symbol has leading _ */
2473 /* Effective symbol. */
2474 /* Store the pointer in the offset. */
2475 S_SET_ZEROES (symbolP, 0L);
2476 S_SET_DATA_TYPE (symbolP, T_NULL);
2477 S_SET_STORAGE_CLASS (symbolP, 0);
2478 S_SET_NUMBER_AUXILIARY (symbolP, 0);
2479 /* Additional information. */
2480 symbolP->sy_symbol.ost_flags = 0;
2481 /* Auxiliary entries. */
2482 memset ((char *) &symbolP->sy_symbol.ost_auxent[0], 0, AUXESZ);
2484 if (S_IS_STRING (symbolP))
2485 SF_SET_STRING (symbolP);
2486 if (!underscore && S_IS_LOCAL (symbolP))
2487 SF_SET_LOCAL (symbolP);
2490 /* Handle .ln directives. */
2493 obj_coff_ln (appline)
2498 if (! appline && def_symbol_in_progress != NULL)
2500 /* Wrong context. */
2501 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2502 demand_empty_rest_of_line ();
2506 l = get_absolute_expression ();
2507 c_line_new (0, frag_now_fix (), l, frag_now);
2510 new_logical_line ((char *) NULL, l - 1);
2520 listing_source_line ((unsigned int) l);
2525 demand_empty_rest_of_line ();
2528 /* Handle .def directives.
2530 One might ask : why can't we symbol_new if the symbol does not
2531 already exist and fill it with debug information. Because of
2532 the C_EFCN special symbol. It would clobber the value of the
2533 function symbol before we have a chance to notice that it is
2534 a C_EFCN. And a second reason is that the code is more clear this
2535 way. (at least I think it is :-). */
2537 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2538 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2539 *input_line_pointer == '\t') \
2540 input_line_pointer++;
2544 int what ATTRIBUTE_UNUSED;
2546 char name_end; /* Char after the end of name. */
2547 char *symbol_name; /* Name of the debug symbol. */
2548 char *symbol_name_copy; /* Temporary copy of the name. */
2549 unsigned int symbol_name_length;
2551 if (def_symbol_in_progress != NULL)
2553 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2554 demand_empty_rest_of_line ();
2558 SKIP_WHITESPACES ();
2560 def_symbol_in_progress = (symbolS *) obstack_alloc (¬es, sizeof (*def_symbol_in_progress));
2561 memset (def_symbol_in_progress, 0, sizeof (*def_symbol_in_progress));
2563 symbol_name = input_line_pointer;
2564 name_end = get_symbol_end ();
2565 symbol_name_length = strlen (symbol_name);
2566 symbol_name_copy = xmalloc (symbol_name_length + 1);
2567 strcpy (symbol_name_copy, symbol_name);
2568 #ifdef tc_canonicalize_symbol_name
2569 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
2572 /* Initialize the new symbol. */
2573 #ifdef STRIP_UNDERSCORE
2574 S_SET_NAME (def_symbol_in_progress, (*symbol_name_copy == '_'
2575 ? symbol_name_copy + 1
2576 : symbol_name_copy));
2577 #else /* STRIP_UNDERSCORE */
2578 S_SET_NAME (def_symbol_in_progress, symbol_name_copy);
2579 #endif /* STRIP_UNDERSCORE */
2580 /* free(symbol_name_copy); */
2581 def_symbol_in_progress->sy_name_offset = (unsigned long) ~0;
2582 def_symbol_in_progress->sy_number = ~0;
2583 def_symbol_in_progress->sy_frag = &zero_address_frag;
2584 S_SET_VALUE (def_symbol_in_progress, 0);
2586 if (S_IS_STRING (def_symbol_in_progress))
2587 SF_SET_STRING (def_symbol_in_progress);
2589 *input_line_pointer = name_end;
2591 demand_empty_rest_of_line ();
2594 unsigned int dim_index;
2597 obj_coff_endef (ignore)
2598 int ignore ATTRIBUTE_UNUSED;
2600 symbolS *symbolP = 0;
2601 /* DIM BUG FIX sac@cygnus.com */
2603 if (def_symbol_in_progress == NULL)
2605 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2606 demand_empty_rest_of_line ();
2610 /* Set the section number according to storage class. */
2611 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
2616 SF_SET_TAG (def_symbol_in_progress);
2617 /* Intentional fallthrough. */
2621 SF_SET_DEBUG (def_symbol_in_progress);
2622 S_SET_SEGMENT (def_symbol_in_progress, SEG_DEBUG);
2626 /* Do not emit this symbol. */
2627 SF_SET_LOCAL (def_symbol_in_progress);
2628 /* Intentional fallthrough. */
2631 /* Will need processing before writing. */
2632 SF_SET_PROCESS (def_symbol_in_progress);
2633 /* Intentional fallthrough. */
2636 S_SET_SEGMENT (def_symbol_in_progress, SEG_E0);
2638 if (strcmp (S_GET_NAME (def_symbol_in_progress), ".bf") == 0)
2640 if (function_lineoff < 0)
2641 fprintf (stderr, _("`.bf' symbol without preceding function\n"));
2643 SA_GET_SYM_LNNOPTR (last_line_symbol) = function_lineoff;
2645 SF_SET_PROCESS (last_line_symbol);
2646 SF_SET_ADJ_LNNOPTR (last_line_symbol);
2647 SF_SET_PROCESS (def_symbol_in_progress);
2648 function_lineoff = -1;
2651 /* Value is always set to . */
2652 def_symbol_in_progress->sy_frag = frag_now;
2653 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2658 #endif /* C_AUTOARG */
2668 SF_SET_DEBUG (def_symbol_in_progress);
2669 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
2679 /* Valid but set somewhere else (s_comm, s_lcomm, colon). */
2685 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress));
2689 /* Now that we have built a debug symbol, try to find if we should
2690 merge with an existing symbol or not. If a symbol is C_EFCN or
2691 absolute_section or untagged SEG_DEBUG it never merges. We also
2692 don't merge labels, which are in a different namespace, nor
2693 symbols which have not yet been defined since they are typically
2694 unique, nor do we merge tags with non-tags. */
2696 /* Two cases for functions. Either debug followed by definition or
2697 definition followed by debug. For definition first, we will
2698 merge the debug symbol into the definition. For debug first, the
2699 lineno entry MUST point to the definition function or else it
2700 will point off into space when crawl_symbols() merges the debug
2701 symbol into the real symbol. Therefor, let's presume the debug
2702 symbol is a real function reference. */
2704 /* FIXME-SOON If for some reason the definition label/symbol is
2705 never seen, this will probably leave an undefined symbol at link
2708 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
2709 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
2710 || (S_GET_SEGMENT (def_symbol_in_progress) == SEG_DEBUG
2711 && !SF_GET_TAG (def_symbol_in_progress))
2712 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
2713 || def_symbol_in_progress->sy_value.X_op != O_constant
2714 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL
2715 || (SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP)))
2717 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
2722 /* This symbol already exists, merge the newly created symbol
2723 into the old one. This is not mandatory. The linker can
2724 handle duplicate symbols correctly. But I guess that it save
2725 a *lot* of space if the assembly file defines a lot of
2728 /* The debug entry (def_symbol_in_progress) is merged into the
2729 previous definition. */
2731 c_symbol_merge (def_symbol_in_progress, symbolP);
2732 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2733 def_symbol_in_progress = symbolP;
2735 if (SF_GET_FUNCTION (def_symbol_in_progress)
2736 || SF_GET_TAG (def_symbol_in_progress)
2737 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
2739 /* For functions, and tags, and static symbols, the symbol
2740 *must* be where the debug symbol appears. Move the
2741 existing symbol to the current place. */
2742 /* If it already is at the end of the symbol list, do nothing. */
2743 if (def_symbol_in_progress != symbol_lastP)
2745 symbol_remove (def_symbol_in_progress, &symbol_rootP,
2747 symbol_append (def_symbol_in_progress, symbol_lastP,
2748 &symbol_rootP, &symbol_lastP);
2753 if (SF_GET_TAG (def_symbol_in_progress))
2757 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
2759 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
2760 tag_insert (S_GET_NAME (def_symbol_in_progress),
2761 def_symbol_in_progress);
2764 if (SF_GET_FUNCTION (def_symbol_in_progress))
2766 know (sizeof (def_symbol_in_progress) <= sizeof (long));
2768 = c_line_new (def_symbol_in_progress, 0, 0, &zero_address_frag);
2770 SF_SET_PROCESS (def_symbol_in_progress);
2772 if (symbolP == NULL)
2774 /* That is, if this is the first time we've seen the
2776 symbol_table_insert (def_symbol_in_progress);
2780 def_symbol_in_progress = NULL;
2781 demand_empty_rest_of_line ();
2785 obj_coff_dim (ignore)
2786 int ignore ATTRIBUTE_UNUSED;
2790 if (def_symbol_in_progress == NULL)
2792 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2793 demand_empty_rest_of_line ();
2797 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2799 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
2801 SKIP_WHITESPACES ();
2802 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
2803 get_absolute_expression ());
2805 switch (*input_line_pointer)
2808 input_line_pointer++;
2812 as_warn (_("badly formed .dim directive ignored"));
2813 /* Intentional fallthrough. */
2822 demand_empty_rest_of_line ();
2826 obj_coff_line (ignore)
2827 int ignore ATTRIBUTE_UNUSED;
2832 if (def_symbol_in_progress == NULL)
2838 name = S_GET_NAME (def_symbol_in_progress);
2839 this_base = get_absolute_expression ();
2841 /* Only .bf symbols indicate the use of a new base line number; the
2842 line numbers associated with .ef, .bb, .eb are relative to the
2843 start of the containing function. */
2844 if (!strcmp (".bf", name))
2846 line_base = this_base;
2852 listing_source_line ((unsigned int) line_base);
2857 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2858 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
2860 demand_empty_rest_of_line ();
2864 obj_coff_size (ignore)
2865 int ignore ATTRIBUTE_UNUSED;
2867 if (def_symbol_in_progress == NULL)
2869 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2870 demand_empty_rest_of_line ();
2874 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2875 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
2876 demand_empty_rest_of_line ();
2880 obj_coff_scl (ignore)
2881 int ignore ATTRIBUTE_UNUSED;
2883 if (def_symbol_in_progress == NULL)
2885 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2886 demand_empty_rest_of_line ();
2890 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
2891 demand_empty_rest_of_line ();
2895 obj_coff_tag (ignore)
2896 int ignore ATTRIBUTE_UNUSED;
2901 if (def_symbol_in_progress == NULL)
2903 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2904 demand_empty_rest_of_line ();
2908 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2909 symbol_name = input_line_pointer;
2910 name_end = get_symbol_end ();
2911 #ifdef tc_canonicalize_symbol_name
2912 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2915 /* Assume that the symbol referred to by .tag is always defined.
2916 This was a bad assumption. I've added find_or_make. xoxorich. */
2917 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
2918 (long) tag_find_or_make (symbol_name));
2919 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
2920 as_warn (_("tag not found for .tag %s"), symbol_name);
2922 SF_SET_TAGGED (def_symbol_in_progress);
2923 *input_line_pointer = name_end;
2925 demand_empty_rest_of_line ();
2929 obj_coff_type (ignore)
2930 int ignore ATTRIBUTE_UNUSED;
2932 if (def_symbol_in_progress == NULL)
2934 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2935 demand_empty_rest_of_line ();
2939 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
2941 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
2942 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
2943 SF_SET_FUNCTION (def_symbol_in_progress);
2945 demand_empty_rest_of_line ();
2949 obj_coff_val (ignore)
2950 int ignore ATTRIBUTE_UNUSED;
2952 if (def_symbol_in_progress == NULL)
2954 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2955 demand_empty_rest_of_line ();
2959 if (is_name_beginner (*input_line_pointer))
2961 char *symbol_name = input_line_pointer;
2962 char name_end = get_symbol_end ();
2964 #ifdef tc_canonicalize_symbol_name
2965 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2968 if (!strcmp (symbol_name, "."))
2970 def_symbol_in_progress->sy_frag = frag_now;
2971 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2972 /* If the .val is != from the .def (e.g. statics). */
2974 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
2976 def_symbol_in_progress->sy_value.X_op = O_symbol;
2977 def_symbol_in_progress->sy_value.X_add_symbol =
2978 symbol_find_or_make (symbol_name);
2979 def_symbol_in_progress->sy_value.X_op_symbol = NULL;
2980 def_symbol_in_progress->sy_value.X_add_number = 0;
2982 /* If the segment is undefined when the forward reference is
2983 resolved, then copy the segment id from the forward
2985 SF_SET_GET_SEGMENT (def_symbol_in_progress);
2987 /* FIXME: gcc can generate address expressions here in
2988 unusual cases (search for "obscure" in sdbout.c). We
2989 just ignore the offset here, thus generating incorrect
2990 debugging information. We ignore the rest of the line
2993 /* Otherwise, it is the name of a non debug symbol and
2994 its value will be calculated later. */
2995 *input_line_pointer = name_end;
2997 /* FIXME: this is to avoid an error message in the
2998 FIXME case mentioned just above. */
2999 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3000 ++input_line_pointer;
3004 S_SET_VALUE (def_symbol_in_progress,
3005 (valueT) get_absolute_expression ());
3006 } /* if symbol based */
3008 demand_empty_rest_of_line ();
3013 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
3014 read.c, which then calls this object file format specific routine. */
3017 obj_coff_pe_handle_link_once (type)
3018 enum linkonce_type type;
3020 seg_info (now_seg)->scnhdr.s_flags |= IMAGE_SCN_LNK_COMDAT;
3022 /* We store the type in the seg_info structure, and use it to set up
3023 the auxiliary entry for the section symbol in c_section_symbol. */
3024 seg_info (now_seg)->linkonce = type;
3030 coff_obj_read_begin_hook ()
3032 /* These had better be the same. Usually 18 bytes. */
3034 know (sizeof (SYMENT) == sizeof (AUXENT));
3035 know (SYMESZ == AUXESZ);
3040 /* This function runs through the symbol table and puts all the
3041 externals onto another chain. */
3043 /* The chain of globals. */
3044 symbolS *symbol_globalP;
3045 symbolS *symbol_global_lastP;
3047 /* The chain of externals. */
3048 symbolS *symbol_externP;
3049 symbolS *symbol_extern_lastP;
3052 symbolS *last_functionP;
3053 static symbolS *last_bfP;
3060 unsigned int symbol_number = 0;
3061 unsigned int last_file_symno = 0;
3063 struct filename_list *filename_list_scan = filename_list_head;
3065 for (symbolP = symbol_rootP;
3067 symbolP = symbolP ? symbol_next (symbolP) : symbol_rootP)
3069 if (symbolP->sy_mri_common)
3071 if (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3073 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3075 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT)
3076 as_bad (_("%s: global symbols not supported in common sections"),
3077 S_GET_NAME (symbolP));
3078 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3082 if (!SF_GET_DEBUG (symbolP))
3084 /* Debug symbols do not need all this rubbish. */
3085 symbolS *real_symbolP;
3087 /* L* and C_EFCN symbols never merge. */
3088 if (!SF_GET_LOCAL (symbolP)
3089 && !SF_GET_STATICS (symbolP)
3090 && S_GET_STORAGE_CLASS (symbolP) != C_LABEL
3091 && symbolP->sy_value.X_op == O_constant
3092 && (real_symbolP = symbol_find_base (S_GET_NAME (symbolP), DO_NOT_STRIP))
3093 && real_symbolP != symbolP)
3095 /* FIXME-SOON: where do dups come from?
3096 Maybe tag references before definitions? xoxorich. */
3097 /* Move the debug data from the debug symbol to the
3098 real symbol. Do NOT do the opposite (i.e. move from
3099 real symbol to debug symbol and remove real symbol from the
3100 list.) Because some pointers refer to the real symbol
3101 whereas no pointers refer to the debug symbol. */
3102 c_symbol_merge (symbolP, real_symbolP);
3103 /* Replace the current symbol by the real one. */
3104 /* The symbols will never be the last or the first
3105 because : 1st symbol is .file and 3 last symbols are
3106 .text, .data, .bss. */
3107 symbol_remove (real_symbolP, &symbol_rootP, &symbol_lastP);
3108 symbol_insert (real_symbolP, symbolP, &symbol_rootP, &symbol_lastP);
3109 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3110 symbolP = real_symbolP;
3113 if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_E1))
3114 S_SET_SEGMENT (symbolP, SEG_E0);
3116 resolve_symbol_value (symbolP);
3118 if (S_GET_STORAGE_CLASS (symbolP) == C_NULL)
3120 if (!S_IS_DEFINED (symbolP) && !SF_GET_LOCAL (symbolP))
3122 S_SET_EXTERNAL (symbolP);
3125 else if (S_GET_SEGMENT (symbolP) == SEG_E0)
3126 S_SET_STORAGE_CLASS (symbolP, C_LABEL);
3129 S_SET_STORAGE_CLASS (symbolP, C_STAT);
3132 /* Mainly to speed up if not -g. */
3133 if (SF_GET_PROCESS (symbolP))
3135 /* Handle the nested blocks auxiliary info. */
3136 if (S_GET_STORAGE_CLASS (symbolP) == C_BLOCK)
3138 if (!strcmp (S_GET_NAME (symbolP), ".bb"))
3139 stack_push (block_stack, (char *) &symbolP);
3143 symbolS *begin_symbolP;
3145 begin_symbolP = *(symbolS **) stack_pop (block_stack);
3146 if (begin_symbolP == (symbolS *) 0)
3147 as_warn (_("mismatched .eb"));
3149 SA_SET_SYM_ENDNDX (begin_symbolP, symbol_number + 2);
3152 /* If we are able to identify the type of a function, and we
3153 are out of a function (last_functionP == 0) then, the
3154 function symbol will be associated with an auxiliary
3156 if (last_functionP == (symbolS *) 0 &&
3157 SF_GET_FUNCTION (symbolP))
3159 last_functionP = symbolP;
3161 if (S_GET_NUMBER_AUXILIARY (symbolP) < 1)
3162 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3164 if (S_GET_STORAGE_CLASS (symbolP) == C_FCN)
3166 if (strcmp (S_GET_NAME (symbolP), ".bf") == 0)
3168 if (last_bfP != NULL)
3169 SA_SET_SYM_ENDNDX (last_bfP, symbol_number);
3173 else if (S_GET_STORAGE_CLASS (symbolP) == C_EFCN)
3175 /* I don't even know if this is needed for sdb. But
3176 the standard assembler generates it, so... */
3177 if (last_functionP == (symbolS *) 0)
3178 as_fatal (_("C_EFCN symbol out of scope"));
3179 SA_SET_SYM_FSIZE (last_functionP,
3180 (long) (S_GET_VALUE (symbolP) -
3181 S_GET_VALUE (last_functionP)));
3182 SA_SET_SYM_ENDNDX (last_functionP, symbol_number);
3183 last_functionP = (symbolS *) 0;
3187 else if (SF_GET_TAG (symbolP))
3189 /* First descriptor of a structure must point to
3190 the first slot after the structure description. */
3191 last_tagP = symbolP;
3194 else if (S_GET_STORAGE_CLASS (symbolP) == C_EOS)
3196 /* +2 take in account the current symbol. */
3197 SA_SET_SYM_ENDNDX (last_tagP, symbol_number + 2);
3199 else if (S_GET_STORAGE_CLASS (symbolP) == C_FILE)
3201 /* If the filename was too long to fit in the
3202 auxent, put it in the string table. */
3203 if (SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3204 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3206 SA_SET_FILE_FNAME_OFFSET (symbolP, string_byte_count);
3207 string_byte_count += strlen (filename_list_scan->filename) + 1;
3208 filename_list_scan = filename_list_scan->next;
3210 if (S_GET_VALUE (symbolP))
3212 S_SET_VALUE (symbolP, last_file_symno);
3213 last_file_symno = symbol_number;
3217 #ifdef tc_frob_coff_symbol
3218 tc_frob_coff_symbol (symbolP);
3221 /* We must put the external symbols apart. The loader
3222 does not bomb if we do not. But the references in
3223 the endndx field for a .bb symbol are not corrected
3224 if an external symbol is removed between .bb and .be.
3225 I.e in the following case :
3226 [20] .bb endndx = 22
3229 ld will move the symbol 21 to the end of the list but
3230 endndx will still be 22 instead of 21. */
3232 if (SF_GET_LOCAL (symbolP))
3234 /* Remove C_EFCN and LOCAL (L...) symbols. */
3235 /* Next pointer remains valid. */
3236 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3239 else if (symbolP->sy_value.X_op == O_symbol
3240 && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)))
3242 /* Skip symbols which were equated to undefined or common
3244 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3246 else if (!S_IS_DEFINED (symbolP)
3247 && !S_IS_DEBUG (symbolP)
3248 && !SF_GET_STATICS (symbolP)
3249 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3251 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3253 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT))
3255 /* If external, Remove from the list. */
3256 symbolS *hold = symbol_previous (symbolP);
3258 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3259 symbol_clear_list_pointers (symbolP);
3260 symbol_append (symbolP, symbol_extern_lastP, &symbol_externP, &symbol_extern_lastP);
3263 else if (! S_IS_DEBUG (symbolP)
3264 && ! SF_GET_STATICS (symbolP)
3265 && ! SF_GET_FUNCTION (symbolP)
3266 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3268 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3270 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK))
3272 symbolS *hold = symbol_previous (symbolP);
3274 /* The O'Reilly COFF book says that defined global symbols
3275 come at the end of the symbol table, just before
3276 undefined global symbols. */
3277 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3278 symbol_clear_list_pointers (symbolP);
3279 symbol_append (symbolP, symbol_global_lastP, &symbol_globalP,
3280 &symbol_global_lastP);
3285 if (SF_GET_STRING (symbolP))
3287 symbolP->sy_name_offset = string_byte_count;
3288 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
3292 symbolP->sy_name_offset = 0;
3295 symbolP->sy_number = symbol_number;
3296 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
3300 return symbol_number;
3304 glue_symbols (head, tail)
3308 unsigned int symbol_number = 0;
3310 while (*head != NULL)
3312 symbolS *tmp = *head;
3315 symbol_remove (tmp, head, tail);
3316 symbol_append (tmp, symbol_lastP, &symbol_rootP, &symbol_lastP);
3319 if (SF_GET_STRING (tmp))
3321 tmp->sy_name_offset = string_byte_count;
3322 string_byte_count += strlen (S_GET_NAME (tmp)) + 1;
3326 /* Fix "long" names. */
3327 tmp->sy_name_offset = 0;
3330 tmp->sy_number = symbol_number;
3331 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (tmp);
3334 return symbol_number;
3340 unsigned int symbol_number = 0;
3343 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
3345 symbolP->sy_number = symbol_number;
3347 if (SF_GET_TAGGED (symbolP))
3351 ((symbolS *) SA_GET_SYM_TAGNDX (symbolP))->sy_number);
3354 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
3357 return symbol_number;
3362 crawl_symbols (h, abfd)
3364 bfd *abfd ATTRIBUTE_UNUSED;
3368 /* Initialize the stack used to keep track of the matching .bb .be. */
3370 block_stack = stack_init (512, sizeof (symbolS *));
3372 /* The symbol list should be ordered according to the following sequence
3375 . debug entries for functions
3376 . fake symbols for the sections, including .text .data and .bss
3379 But this is not mandatory. The only important point is to put the
3380 undefined symbols at the end of the list. */
3382 /* Is there a .file symbol ? If not insert one at the beginning. */
3383 if (symbol_rootP == NULL
3384 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
3385 c_dot_file_symbol ("fake", 0);
3387 /* Build up static symbols for the sections, they are filled in later. */
3389 for (i = SEG_E0; i < SEG_LAST; i++)
3390 if (segment_info[i].scnhdr.s_name[0])
3391 segment_info[i].dot = c_section_symbol ((char *) segment_info[i].name,
3394 /* Take all the externals out and put them into another chain. */
3395 H_SET_SYMBOL_TABLE_SIZE (h, yank_symbols ());
3396 /* Take the externals and glue them onto the end. */
3397 H_SET_SYMBOL_TABLE_SIZE (h,
3398 (H_GET_SYMBOL_COUNT (h)
3399 + glue_symbols (&symbol_globalP,
3400 &symbol_global_lastP)
3401 + glue_symbols (&symbol_externP,
3402 &symbol_extern_lastP)));
3404 H_SET_SYMBOL_TABLE_SIZE (h, tie_tags ());
3405 know (symbol_globalP == NULL);
3406 know (symbol_global_lastP == NULL);
3407 know (symbol_externP == NULL);
3408 know (symbol_extern_lastP == NULL);
3411 /* Find strings by crawling along symbol table chain. */
3418 struct filename_list *filename_list_scan = filename_list_head;
3420 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK. */
3421 md_number_to_chars (where, (valueT) string_byte_count, 4);
3424 #ifdef COFF_LONG_SECTION_NAMES
3425 /* Support long section names as found in PE. This code must
3426 coordinate with that in coff_header_append and write_object_file. */
3430 for (i = SEG_E0; i < SEG_LAST; i++)
3432 if (segment_info[i].scnhdr.s_name[0]
3433 && strlen (segment_info[i].name) > SCNNMLEN)
3437 size = strlen (segment_info[i].name) + 1;
3438 memcpy (where, segment_info[i].name, size);
3443 #endif /* COFF_LONG_SECTION_NAMES */
3445 for (symbolP = symbol_rootP;
3447 symbolP = symbol_next (symbolP))
3451 if (SF_GET_STRING (symbolP))
3453 size = strlen (S_GET_NAME (symbolP)) + 1;
3454 memcpy (where, S_GET_NAME (symbolP), size);
3457 if (S_GET_STORAGE_CLASS (symbolP) == C_FILE
3458 && SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3459 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3461 size = strlen (filename_list_scan->filename) + 1;
3462 memcpy (where, filename_list_scan->filename, size);
3463 filename_list_scan = filename_list_scan ->next;
3470 do_linenos_for (abfd, h, file_cursor)
3473 unsigned long *file_cursor;
3476 unsigned long start = *file_cursor;
3478 for (idx = SEG_E0; idx < SEG_LAST; idx++)
3480 segment_info_type *s = segment_info + idx;
3482 if (s->scnhdr.s_nlnno != 0)
3484 struct lineno_list *line_ptr;
3486 struct external_lineno *buffer =
3487 (struct external_lineno *) xmalloc (s->scnhdr.s_nlnno * LINESZ);
3489 struct external_lineno *dst = buffer;
3491 /* Run through the table we've built and turn it into its external
3492 form, take this chance to remove duplicates. */
3494 for (line_ptr = s->lineno_list_head;
3495 line_ptr != (struct lineno_list *) NULL;
3496 line_ptr = line_ptr->next)
3498 if (line_ptr->line.l_lnno == 0)
3500 /* Turn a pointer to a symbol into the symbols' index,
3501 provided that it has been initialised. */
3502 if (line_ptr->line.l_addr.l_symndx)
3503 line_ptr->line.l_addr.l_symndx =
3504 ((symbolS *) line_ptr->line.l_addr.l_symndx)->sy_number;
3507 line_ptr->line.l_addr.l_paddr += ((struct frag *) (line_ptr->frag))->fr_address;
3509 (void) bfd_coff_swap_lineno_out (abfd, &(line_ptr->line), dst);
3513 s->scnhdr.s_lnnoptr = *file_cursor;
3515 bfd_bwrite (buffer, (bfd_size_type) s->scnhdr.s_nlnno * LINESZ, abfd);
3518 *file_cursor += s->scnhdr.s_nlnno * LINESZ;
3522 H_SET_LINENO_SIZE (h, *file_cursor - start);
3525 /* Now we run through the list of frag chains in a segment and
3526 make all the subsegment frags appear at the end of the
3527 list, as if the seg 0 was extra long. */
3534 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3536 frchainS *head = segment_info[i].frchainP;
3538 fragS *prev_frag = &dummy;
3540 while (head && head->frch_seg == i)
3542 prev_frag->fr_next = head->frch_root;
3543 prev_frag = head->frch_last;
3544 head = head->frch_next;
3546 prev_frag->fr_next = 0;
3550 unsigned long machine;
3553 #ifndef SUB_SEGMENT_ALIGN
3555 /* The last subsegment gets an alignment corresponding to the alignment
3556 of the section. This allows proper nop-filling at the end of
3557 code-bearing sections. */
3558 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \
3559 (!(FRCHAIN)->frch_next || (FRCHAIN)->frch_next->frch_seg != (SEG) \
3560 ? get_recorded_alignment (SEG) : 0)
3562 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 1
3567 write_object_file ()
3571 struct frchain *frchain_ptr;
3573 object_headers headers;
3574 unsigned long file_cursor;
3577 abfd = bfd_openw (out_file_name, TARGET_FORMAT);
3581 as_perror (_("FATAL: Can't create %s"), out_file_name);
3582 exit (EXIT_FAILURE);
3584 bfd_set_format (abfd, bfd_object);
3585 bfd_set_arch_mach (abfd, BFD_ARCH, machine);
3587 string_byte_count = 4;
3589 /* Run through all the sub-segments and align them up. Also
3590 close any open frags. We tack a .fill onto the end of the
3591 frag chain so that any .align's size can be worked by looking
3592 at the next frag. */
3593 for (frchain_ptr = frchain_root;
3594 frchain_ptr != (struct frchain *) NULL;
3595 frchain_ptr = frchain_ptr->frch_next)
3599 subseg_set (frchain_ptr->frch_seg, frchain_ptr->frch_subseg);
3601 alignment = SUB_SEGMENT_ALIGN (now_seg, frchain_ptr);
3604 md_do_align (alignment, (char *) NULL, 0, 0, alignment_done);
3606 if (subseg_text_p (now_seg))
3607 frag_align_code (alignment, 0);
3609 frag_align (alignment, 0, 0);
3615 frag_wane (frag_now);
3616 frag_now->fr_fix = 0;
3617 know (frag_now->fr_next == NULL);
3622 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3623 relax_segment (segment_info[i].frchainP->frch_root, i);
3625 /* Relaxation has completed. Freeze all syms. */
3628 H_SET_NUMBER_OF_SECTIONS (&headers, 0);
3630 /* Find out how big the sections are, and set the addresses. */
3632 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3636 segment_info[i].scnhdr.s_paddr = addr;
3637 segment_info[i].scnhdr.s_vaddr = addr;
3639 if (segment_info[i].scnhdr.s_name[0])
3641 H_SET_NUMBER_OF_SECTIONS (&headers,
3642 H_GET_NUMBER_OF_SECTIONS (&headers) + 1);
3644 #ifdef COFF_LONG_SECTION_NAMES
3645 /* Support long section names as found in PE. This code
3646 must coordinate with that in coff_header_append and
3651 len = strlen (segment_info[i].name);
3653 string_byte_count += len + 1;
3655 #endif /* COFF_LONG_SECTION_NAMES */
3658 size = size_section (abfd, (unsigned int) i);
3661 /* I think the section alignment is only used on the i960; the
3662 i960 needs it, and it should do no harm on other targets. */
3663 #ifdef ALIGNMENT_IN_S_FLAGS
3664 segment_info[i].scnhdr.s_flags |= (section_alignment[i] & 0xF) << 8;
3666 segment_info[i].scnhdr.s_align = 1 << section_alignment[i];
3670 H_SET_TEXT_SIZE (&headers, size);
3671 else if (i == SEG_E1)
3672 H_SET_DATA_SIZE (&headers, size);
3673 else if (i == SEG_E2)
3674 H_SET_BSS_SIZE (&headers, size);
3677 /* Turn the gas native symbol table shape into a coff symbol table. */
3678 crawl_symbols (&headers, abfd);
3680 if (string_byte_count == 4)
3681 string_byte_count = 0;
3683 H_SET_STRING_SIZE (&headers, string_byte_count);
3689 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3691 fixup_mdeps (segment_info[i].frchainP->frch_root, &headers, i);
3692 fixup_segment (&segment_info[i], i);
3695 /* Look for ".stab" segments and fill in their initial symbols
3697 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3699 name = segment_info[i].name;
3702 && strncmp (".stab", name, 5) == 0
3703 && strncmp (".stabstr", name, 8) != 0)
3704 adjust_stab_section (abfd, i);
3707 file_cursor = H_GET_TEXT_FILE_OFFSET (&headers);
3709 bfd_seek (abfd, (file_ptr) file_cursor, 0);
3711 /* Plant the data. */
3712 fill_section (abfd, &headers, &file_cursor);
3714 do_relocs_for (abfd, &headers, &file_cursor);
3716 do_linenos_for (abfd, &headers, &file_cursor);
3718 H_SET_FILE_MAGIC_NUMBER (&headers, COFF_MAGIC);
3719 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3720 H_SET_TIME_STAMP (&headers, (long)time((time_t *)0));
3722 H_SET_TIME_STAMP (&headers, 0);
3724 #ifdef TC_COFF_SET_MACHINE
3725 TC_COFF_SET_MACHINE (&headers);
3729 #define COFF_FLAGS 0
3732 #ifdef KEEP_RELOC_INFO
3733 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3734 COFF_FLAGS | coff_flags));
3736 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3737 (H_GET_RELOCATION_SIZE(&headers) ? 0 : F_RELFLG) |
3738 COFF_FLAGS | coff_flags));
3742 unsigned int symtable_size = H_GET_SYMBOL_TABLE_SIZE (&headers);
3743 char *buffer1 = xmalloc (symtable_size + string_byte_count + 1);
3745 H_SET_SYMBOL_TABLE_POINTER (&headers, bfd_tell (abfd));
3746 w_symbols (abfd, buffer1, symbol_rootP);
3747 if (string_byte_count > 0)
3748 w_strings (buffer1 + symtable_size);
3749 bfd_bwrite (buffer1, (bfd_size_type) symtable_size + string_byte_count,
3754 coff_header_append (abfd, &headers);
3756 extern bfd *stdoutput;
3761 /* Add a new segment. This is called from subseg_new via the
3762 obj_new_segment macro. */
3765 obj_coff_add_segment (name)
3770 #ifndef COFF_LONG_SECTION_NAMES
3771 char buf[SCNNMLEN + 1];
3773 strncpy (buf, name, SCNNMLEN);
3774 buf[SCNNMLEN] = '\0';
3778 for (i = SEG_E0; i < SEG_LAST && segment_info[i].scnhdr.s_name[0]; i++)
3779 if (strcmp (name, segment_info[i].name) == 0)
3784 as_bad (_("Too many new sections; can't add \"%s\""), name);
3788 /* Add a new section. */
3789 strncpy (segment_info[i].scnhdr.s_name, name,
3790 sizeof (segment_info[i].scnhdr.s_name));
3791 segment_info[i].scnhdr.s_flags = STYP_REG;
3792 segment_info[i].name = xstrdup (name);
3797 /* Implement the .section pseudo op:
3798 .section name {, "flags"}
3800 | +--- optional flags: 'b' for bss
3802 +-- section name 'l' for lib
3806 'd' (apparently m88k for data)
3808 'r' for read-only data
3809 But if the argument is not a quoted string, treat it as a
3810 subsegment number. */
3813 obj_coff_section (ignore)
3814 int ignore ATTRIBUTE_UNUSED;
3816 /* Strip out the section name. */
3817 char *section_name, *name;
3830 else if (type == 'D')
3832 segment_info[now_seg].scnhdr.s_flags |= flags;
3837 section_name = input_line_pointer;
3838 c = get_symbol_end ();
3840 name = xmalloc (input_line_pointer - section_name + 1);
3841 strcpy (name, section_name);
3843 *input_line_pointer = c;
3849 if (*input_line_pointer == ',')
3851 ++input_line_pointer;
3854 if (*input_line_pointer != '"')
3855 exp = get_absolute_expression ();
3858 ++input_line_pointer;
3859 while (*input_line_pointer != '"'
3860 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3862 switch (*input_line_pointer)
3864 case 'b': flags |= STYP_BSS; break;
3865 case 'i': flags |= STYP_INFO; break;
3866 case 'l': flags |= STYP_LIB; break;
3867 case 'n': flags |= STYP_NOLOAD; break;
3868 case 'o': flags |= STYP_OVER; break;
3870 case 'w': flags |= STYP_DATA; break;
3871 case 'x': flags |= STYP_TEXT; break;
3872 case 'r': flags |= STYP_LIT; break;
3874 as_warn(_("unknown section attribute '%c'"),
3875 *input_line_pointer);
3878 ++input_line_pointer;
3880 if (*input_line_pointer == '"')
3881 ++input_line_pointer;
3885 subseg_new (name, (subsegT) exp);
3887 segment_info[now_seg].scnhdr.s_flags |= flags;
3889 demand_empty_rest_of_line ();
3893 obj_coff_text (ignore)
3894 int ignore ATTRIBUTE_UNUSED;
3896 subseg_new (".text", get_absolute_expression ());
3900 obj_coff_data (ignore)
3901 int ignore ATTRIBUTE_UNUSED;
3903 if (flag_readonly_data_in_text)
3904 subseg_new (".text", get_absolute_expression () + 1000);
3906 subseg_new (".data", get_absolute_expression ());
3910 obj_coff_ident (ignore)
3911 int ignore ATTRIBUTE_UNUSED;
3913 segT current_seg = now_seg; /* Save current seg. */
3914 subsegT current_subseg = now_subseg;
3916 subseg_new (".comment", 0); /* .comment seg. */
3917 stringer (1); /* Read string. */
3918 subseg_set (current_seg, current_subseg); /* Restore current seg. */
3922 c_symbol_merge (debug, normal)
3926 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
3927 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
3929 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
3930 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
3932 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
3933 memcpy ((char *) &normal->sy_symbol.ost_auxent[0],
3934 (char *) &debug->sy_symbol.ost_auxent[0],
3935 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug) * AUXESZ));
3937 /* Move the debug flags. */
3938 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
3942 c_line_new (symbol, paddr, line_number, frag)
3948 struct lineno_list *new_line =
3949 (struct lineno_list *) xmalloc (sizeof (struct lineno_list));
3951 segment_info_type *s = segment_info + now_seg;
3952 new_line->line.l_lnno = line_number;
3954 if (line_number == 0)
3956 last_line_symbol = symbol;
3957 new_line->line.l_addr.l_symndx = (long) symbol;
3961 new_line->line.l_addr.l_paddr = paddr;
3964 new_line->frag = (char *) frag;
3965 new_line->next = (struct lineno_list *) NULL;
3967 if (s->lineno_list_head == (struct lineno_list *) NULL)
3968 s->lineno_list_head = new_line;
3970 s->lineno_list_tail->next = new_line;
3972 s->lineno_list_tail = new_line;
3973 return LINESZ * s->scnhdr.s_nlnno++;
3977 c_dot_file_symbol (const char *filename, int appfile ATTRIBUTE_UNUSED)
3981 symbolP = symbol_new (".file",
3984 &zero_address_frag);
3986 S_SET_STORAGE_CLASS (symbolP, C_FILE);
3987 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3989 if (strlen (filename) > FILNMLEN)
3991 /* Filename is too long to fit into an auxent,
3992 we stick it into the string table instead. We keep
3993 a linked list of the filenames we find so we can emit
3995 struct filename_list *f = ((struct filename_list *)
3996 xmalloc (sizeof (struct filename_list)));
3998 f->filename = filename;
4001 SA_SET_FILE_FNAME_ZEROS (symbolP, 0);
4002 SA_SET_FILE_FNAME_OFFSET (symbolP, 1);
4004 if (filename_list_tail)
4005 filename_list_tail->next = f;
4007 filename_list_head = f;
4008 filename_list_tail = f;
4012 SA_SET_FILE_FNAME (symbolP, filename);
4018 listing_source_file (filename);
4021 SF_SET_DEBUG (symbolP);
4022 S_SET_VALUE (symbolP, (valueT) previous_file_symbol);
4024 previous_file_symbol = symbolP;
4026 /* Make sure that the symbol is first on the symbol chain. */
4027 if (symbol_rootP != symbolP)
4029 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
4030 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
4034 /* Build a 'section static' symbol. */
4037 c_section_symbol (name, idx)
4043 symbolP = symbol_find_base (name, DO_NOT_STRIP);
4044 if (symbolP == NULL)
4045 symbolP = symbol_new (name, idx, 0, &zero_address_frag);
4048 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
4049 S_SET_SEGMENT (symbolP, idx);
4050 symbolP->sy_frag = &zero_address_frag;
4053 S_SET_STORAGE_CLASS (symbolP, C_STAT);
4054 S_SET_NUMBER_AUXILIARY (symbolP, 1);
4056 SF_SET_STATICS (symbolP);
4059 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
4060 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
4061 SF_CLEAR_LOCAL (symbolP);
4064 /* If the .linkonce pseudo-op was used for this section, we must
4065 store the information in the auxiliary entry for the section
4067 if (segment_info[idx].linkonce != LINKONCE_UNSET)
4071 switch (segment_info[idx].linkonce)
4075 case LINKONCE_DISCARD:
4076 type = IMAGE_COMDAT_SELECT_ANY;
4078 case LINKONCE_ONE_ONLY:
4079 type = IMAGE_COMDAT_SELECT_NODUPLICATES;
4081 case LINKONCE_SAME_SIZE:
4082 type = IMAGE_COMDAT_SELECT_SAME_SIZE;
4084 case LINKONCE_SAME_CONTENTS:
4085 type = IMAGE_COMDAT_SELECT_EXACT_MATCH;
4089 SYM_AUXENT (symbolP)->x_scn.x_comdat = type;
4097 w_symbols (abfd, where, symbol_rootP)
4100 symbolS * symbol_rootP;
4105 /* First fill in those values we have only just worked out. */
4106 for (i = SEG_E0; i < SEG_LAST; i++)
4108 symbolP = segment_info[i].dot;
4111 SA_SET_SCN_SCNLEN (symbolP, segment_info[i].scnhdr.s_size);
4112 SA_SET_SCN_NRELOC (symbolP, segment_info[i].scnhdr.s_nreloc);
4113 SA_SET_SCN_NLINNO (symbolP, segment_info[i].scnhdr.s_nlnno);
4117 /* Emit all symbols left in the symbol chain. */
4118 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
4120 /* Used to save the offset of the name. It is used to point
4121 to the string in memory but must be a file offset. */
4124 /* We can't fix the lnnoptr field in yank_symbols with the other
4125 adjustments, because we have to wait until we know where they
4127 if (SF_GET_ADJ_LNNOPTR (symbolP))
4128 SA_GET_SYM_LNNOPTR (symbolP) +=
4129 segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_lnnoptr;
4131 tc_coff_symbol_emit_hook (symbolP);
4133 temp = S_GET_NAME (symbolP);
4134 if (SF_GET_STRING (symbolP))
4136 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
4137 S_SET_ZEROES (symbolP, 0);
4141 memset (symbolP->sy_symbol.ost_entry.n_name, 0, SYMNMLEN);
4142 strncpy (symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN);
4144 where = symbol_to_chars (abfd, where, symbolP);
4145 S_SET_NAME (symbolP, temp);
4150 obj_coff_lcomm (ignore)
4151 int ignore ATTRIBUTE_UNUSED;
4158 fixup_mdeps (frags, h, this_segment)
4160 object_headers *h ATTRIBUTE_UNUSED;
4163 subseg_change (this_segment, 0);
4167 switch (frags->fr_type)
4174 HANDLE_ALIGN (frags);
4176 frags->fr_type = rs_fill;
4178 ((frags->fr_next->fr_address - frags->fr_address - frags->fr_fix)
4181 case rs_machine_dependent:
4182 md_convert_frag (h, this_segment, frags);
4188 frags = frags->fr_next;
4194 #ifndef TC_FORCE_RELOCATION
4195 #define TC_FORCE_RELOCATION(fix) 0
4199 fixup_segment (segP, this_segment_type)
4200 segment_info_type * segP;
4201 segT this_segment_type;
4204 symbolS *add_symbolP;
4205 symbolS *sub_symbolP;
4212 segT add_symbol_segment = absolute_section;
4214 for (fixP = segP->fix_root; fixP; fixP = fixP->fx_next)
4216 fragP = fixP->fx_frag;
4218 where = fixP->fx_where;
4219 place = fragP->fr_literal + where;
4220 size = fixP->fx_size;
4221 add_symbolP = fixP->fx_addsy;
4222 sub_symbolP = fixP->fx_subsy;
4223 add_number = fixP->fx_offset;
4224 pcrel = fixP->fx_pcrel;
4226 /* We want function-relative stabs to work on systems which
4227 may use a relaxing linker; thus we must handle the sym1-sym2
4228 fixups function-relative stabs generates.
4230 Of course, if you actually enable relaxing in the linker, the
4231 line and block scoping information is going to be incorrect
4232 in some cases. The only way to really fix this is to support
4233 a reloc involving the difference of two symbols. */
4235 && (!sub_symbolP || pcrel))
4239 if (fixP->fx_tcbit && SF_GET_CALLNAME (add_symbolP))
4241 /* Relocation should be done via the associated 'bal' entry
4244 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP)))
4246 as_bad_where (fixP->fx_file, fixP->fx_line,
4247 _("No 'bal' entry point for leafproc %s"),
4248 S_GET_NAME (add_symbolP));
4251 fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP);
4255 /* Make sure the symbols have been resolved; this may not have
4256 happened if these are expression symbols. */
4257 if (add_symbolP != NULL && ! add_symbolP->sy_resolved)
4258 resolve_symbol_value (add_symbolP);
4260 if (add_symbolP != NULL)
4262 /* If this fixup is against a symbol which has been equated
4263 to another symbol, convert it to the other symbol. */
4264 if (add_symbolP->sy_value.X_op == O_symbol
4265 && (! S_IS_DEFINED (add_symbolP)
4266 || S_IS_COMMON (add_symbolP)))
4268 while (add_symbolP->sy_value.X_op == O_symbol
4269 && (! S_IS_DEFINED (add_symbolP)
4270 || S_IS_COMMON (add_symbolP)))
4274 /* We must avoid looping, as that can occur with a
4275 badly written program. */
4276 n = add_symbolP->sy_value.X_add_symbol;
4277 if (n == add_symbolP)
4279 add_number += add_symbolP->sy_value.X_add_number;
4282 fixP->fx_addsy = add_symbolP;
4283 fixP->fx_offset = add_number;
4287 if (sub_symbolP != NULL && ! sub_symbolP->sy_resolved)
4288 resolve_symbol_value (sub_symbolP);
4290 if (add_symbolP != NULL
4291 && add_symbolP->sy_mri_common)
4293 know (add_symbolP->sy_value.X_op == O_symbol);
4294 add_number += S_GET_VALUE (add_symbolP);
4295 fixP->fx_offset = add_number;
4296 add_symbolP = fixP->fx_addsy = add_symbolP->sy_value.X_add_symbol;
4300 add_symbol_segment = S_GET_SEGMENT (add_symbolP);
4304 if (add_symbolP == NULL || add_symbol_segment == absolute_section)
4306 if (add_symbolP != NULL)
4308 add_number += S_GET_VALUE (add_symbolP);
4310 fixP->fx_addsy = NULL;
4313 /* It's just -sym. */
4314 if (S_GET_SEGMENT (sub_symbolP) == absolute_section)
4316 add_number -= S_GET_VALUE (sub_symbolP);
4323 as_bad_where (fixP->fx_file, fixP->fx_line,
4324 _("Negative of non-absolute symbol %s"),
4325 S_GET_NAME (sub_symbolP));
4327 add_number -= S_GET_VALUE (sub_symbolP);
4328 } /* not absolute */
4330 /* if sub_symbol is in the same segment that add_symbol
4331 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE. */
4333 else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
4334 && SEG_NORMAL (add_symbol_segment))
4336 /* Difference of 2 symbols from same segment. Can't
4337 make difference of 2 undefineds: 'value' means
4338 something different for N_UNDF. */
4340 /* Makes no sense to use the difference of 2 arbitrary symbols
4341 as the target of a call instruction. */
4343 as_bad_where (fixP->fx_file, fixP->fx_line,
4344 _("callj to difference of 2 symbols"));
4345 #endif /* TC_I960 */
4346 add_number += S_GET_VALUE (add_symbolP) -
4347 S_GET_VALUE (sub_symbolP);
4350 if (!TC_FORCE_RELOCATION (fixP))
4352 fixP->fx_addsy = NULL;
4353 fixP->fx_subsy = NULL;
4355 #ifdef TC_M68K /* is this right? */
4363 /* Different segments in subtraction. */
4364 know (!(S_IS_EXTERNAL (sub_symbolP) && (S_GET_SEGMENT (sub_symbolP) == absolute_section)));
4366 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section))
4367 add_number -= S_GET_VALUE (sub_symbolP);
4370 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type)
4372 /* Make it pc-relative. */
4373 add_number += (md_pcrel_from (fixP)
4374 - S_GET_VALUE (sub_symbolP));
4383 as_bad_where (fixP->fx_file, fixP->fx_line,
4384 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4385 segment_name (S_GET_SEGMENT (sub_symbolP)),
4386 S_GET_NAME (sub_symbolP),
4387 (long) (fragP->fr_address + where));
4394 if (add_symbol_segment == this_segment_type && pcrel)
4396 /* This fixup was made when the symbol's segment was
4397 SEG_UNKNOWN, but it is now in the local segment.
4398 So we know how to do the address without relocation. */
4400 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4401 in which cases it modifies *fixP as appropriate. In the case
4402 of a 'calls', no further work is required, and *fixP has been
4403 set up to make the rest of the code below a no-op. */
4405 #endif /* TC_I960 */
4407 add_number += S_GET_VALUE (add_symbolP);
4408 add_number -= md_pcrel_from (fixP);
4411 add_number -= segP->scnhdr.s_vaddr;
4412 if defined (TC_I386) || defined (TE_LYNX). I now
4413 think that was an error propagated from the case when
4414 we are going to emit the relocation. If we are not
4415 going to emit the relocation, then we just want to
4416 set add_number to the difference between the symbols.
4417 This is a case that would only arise when there is a
4418 PC relative reference from a section other than .text
4419 to a symbol defined in the same section, and the
4420 reference is not relaxed. Since jump instructions on
4421 the i386 are relaxed, this could only arise with a
4422 call instruction. */
4424 pcrel = 0; /* Lie. Don't want further pcrel processing. */
4425 if (!TC_FORCE_RELOCATION (fixP))
4427 fixP->fx_addsy = NULL;
4433 switch (add_symbol_segment)
4435 case absolute_section:
4437 /* See comment about reloc_callj() above. */
4439 #endif /* TC_I960 */
4440 add_number += S_GET_VALUE (add_symbolP);
4443 if (!TC_FORCE_RELOCATION (fixP))
4445 fixP->fx_addsy = NULL;
4451 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K) || defined(TC_OR32)
4452 /* This really should be handled in the linker, but
4453 backward compatibility forbids. */
4454 add_number += S_GET_VALUE (add_symbolP);
4456 add_number += S_GET_VALUE (add_symbolP) +
4457 segment_info[S_GET_SEGMENT (add_symbolP)].scnhdr.s_paddr;
4463 if ((int) fixP->fx_bit_fixP == 13)
4465 /* This is a COBR instruction. They have only a
4466 13-bit displacement and are only to be used
4467 for local branches: flag as error, don't generate
4469 as_bad_where (fixP->fx_file, fixP->fx_line,
4470 _("can't use COBR format with external label"));
4471 fixP->fx_addsy = NULL;
4475 #endif /* TC_I960 */
4476 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4477 /* 386 COFF uses a peculiar format in which the
4478 value of a common symbol is stored in the .text
4479 segment (I've checked this on SVR3.2 and SCO
4480 3.2.2) Ian Taylor <ian@cygnus.com>. */
4481 /* This is also true for 68k COFF on sysv machines
4482 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4483 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4484 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4485 if (S_IS_COMMON (add_symbolP))
4486 add_number += S_GET_VALUE (add_symbolP);
4496 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K) && !defined(TC_OR32)
4497 /* This adjustment is not correct on the m88k, for which the
4498 linker does all the computation. */
4499 add_number -= md_pcrel_from (fixP);
4501 if (add_symbolP == 0)
4502 fixP->fx_addsy = &abs_symbol;
4503 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4504 /* On the 386 we must adjust by the segment vaddr as well.
4507 I changed the i960 to work this way as well. This is
4508 compatible with the current GNU linker behaviour. I do
4509 not know what other i960 COFF assemblers do. This is not
4510 a common case: normally, only assembler code will contain
4511 a PC relative reloc, and only branches which do not
4512 originate in the .text section will have a non-zero
4515 I changed the m68k to work this way as well. This will
4516 break existing PC relative relocs from sections which do
4517 not start at address 0, but it will make ld -r work.
4518 Ian Taylor, 4 Oct 96. */
4520 add_number -= segP->scnhdr.s_vaddr;
4524 md_apply_fix3 (fixP, (valueT *) & add_number, this_segment_type);
4526 if (!fixP->fx_bit_fixP && ! fixP->fx_no_overflow)
4529 /* The m88k uses the offset field of the reloc to get around
4532 && ((add_number & ~0xFF)
4533 || (fixP->fx_signed && (add_number & 0x80)))
4534 && ((add_number & ~0xFF) != (-1 & ~0xFF)
4535 || (add_number & 0x80) == 0))
4537 && ((add_number & ~0xFFFF)
4538 || (fixP->fx_signed && (add_number & 0x8000)))
4539 && ((add_number & ~0xFFFF) != (-1 & ~0xFFFF)
4540 || (add_number & 0x8000) == 0)))
4542 as_bad_where (fixP->fx_file, fixP->fx_line,
4543 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4544 (long) add_number, size,
4545 (unsigned long) (fragP->fr_address + where));
4548 #ifdef WARN_SIGNED_OVERFLOW_WORD
4549 /* Warn if a .word value is too large when treated as a
4550 signed number. We already know it is not too negative.
4551 This is to catch over-large switches generated by gcc on
4553 if (!flag_signed_overflow_ok
4555 && add_number > 0x7fff)
4556 as_bad_where (fixP->fx_file, fixP->fx_line,
4557 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4559 (unsigned long) (fragP->fr_address + where));
4567 /* The first entry in a .stab section is special. */
4570 obj_coff_init_stab_section (seg)
4576 unsigned int stroff;
4578 /* Make space for this first symbol. */
4582 as_where (&file, (unsigned int *) NULL);
4583 stabstr_name = (char *) alloca (strlen (segment_info[seg].name) + 4);
4584 strcpy (stabstr_name, segment_info[seg].name);
4585 strcat (stabstr_name, "str");
4586 stroff = get_stab_string_offset (file, stabstr_name);
4588 md_number_to_chars (p, stroff, 4);
4591 /* Fill in the counts in the first entry in a .stab section. */
4594 adjust_stab_section(abfd, seg)
4598 segT stabstrseg = SEG_UNKNOWN;
4599 const char *secname, *name2;
4602 int i, strsz = 0, nsyms;
4603 fragS *frag = segment_info[seg].frchainP->frch_root;
4605 /* Look for the associated string table section. */
4607 secname = segment_info[seg].name;
4608 name = (char *) alloca (strlen (secname) + 4);
4609 strcpy (name, secname);
4610 strcat (name, "str");
4612 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
4614 name2 = segment_info[i].name;
4615 if (name2 != NULL && strncmp(name2, name, 8) == 0)
4622 /* If we found the section, get its size. */
4623 if (stabstrseg != SEG_UNKNOWN)
4624 strsz = size_section (abfd, stabstrseg);
4626 nsyms = size_section (abfd, seg) / 12 - 1;
4628 /* Look for the first frag of sufficient size for the initial stab
4629 symbol, and collect a pointer to it. */
4630 while (frag && frag->fr_fix < 12)
4631 frag = frag->fr_next;
4633 p = frag->fr_literal;
4636 /* Write in the number of stab symbols and the size of the string
4638 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
4639 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
4642 #endif /* not BFD_ASSEMBLER */
4644 const pseudo_typeS coff_pseudo_table[] =
4646 {"def", obj_coff_def, 0},
4647 {"dim", obj_coff_dim, 0},
4648 {"endef", obj_coff_endef, 0},
4649 {"line", obj_coff_line, 0},
4650 {"ln", obj_coff_ln, 0},
4651 #ifdef BFD_ASSEMBLER
4652 {"loc", obj_coff_loc, 0},
4654 {"appline", obj_coff_ln, 1},
4655 {"scl", obj_coff_scl, 0},
4656 {"size", obj_coff_size, 0},
4657 {"tag", obj_coff_tag, 0},
4658 {"type", obj_coff_type, 0},
4659 {"val", obj_coff_val, 0},
4660 {"section", obj_coff_section, 0},
4661 {"sect", obj_coff_section, 0},
4662 /* FIXME: We ignore the MRI short attribute. */
4663 {"section.s", obj_coff_section, 0},
4664 {"sect.s", obj_coff_section, 0},
4665 /* We accept the .bss directive for backward compatibility with
4666 earlier versions of gas. */
4667 {"bss", obj_coff_bss, 0},
4668 {"ident", obj_coff_ident, 0},
4669 #ifndef BFD_ASSEMBLER
4670 {"use", obj_coff_section, 0},
4671 {"text", obj_coff_text, 0},
4672 {"data", obj_coff_data, 0},
4673 {"lcomm", obj_coff_lcomm, 0},
4675 {"weak", obj_coff_weak, 0},
4676 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
4678 {"version", s_ignore, 0},
4679 {"ABORT", s_abort, 0},
4680 #if defined( TC_M88K ) || defined ( TC_TIC4X )
4681 /* The m88k and tic4x uses sdef instead of def. */
4682 {"sdef", obj_coff_def, 0},
4684 {NULL, NULL, 0} /* end sentinel */
4685 }; /* coff_pseudo_table */
4687 #ifdef BFD_ASSEMBLER
4689 /* Support for a COFF emulation. */
4691 static void coff_pop_insert PARAMS ((void));
4692 static int coff_separate_stab_sections PARAMS ((void));
4697 pop_insert (coff_pseudo_table);
4701 coff_separate_stab_sections ()
4706 const struct format_ops coff_format_ops =
4708 bfd_target_coff_flavour,
4709 0, /* dfl_leading_underscore */
4710 1, /* emit_section_symbols */
4715 0, /* frob_file_before_adjust */
4716 0, /* frob_file_before_fix */
4717 coff_frob_file_after_relocs,
4720 0, /* s_get_align */
4721 0, /* s_set_align */
4722 0, /* s_get_other */
4723 0, /* s_set_other */
4728 0, /* copy_symbol_attributes */
4729 0, /* generate_asm_lineno */
4730 0, /* process_stab */
4731 coff_separate_stab_sections,
4732 obj_coff_init_stab_section,
4733 0, /* sec_sym_ok_for_reloc */
4735 0, /* ecoff_set_ext */
4736 coff_obj_read_begin_hook,
4737 coff_obj_symbol_new_hook