1 /* coff object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010
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 3, 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, 51 Franklin Street - Fifth Floor, Boston, MA
23 #define OBJ_HEADER "obj-coff.h"
26 #include "safe-ctype.h"
29 #include "struc-symbol.h"
36 #include "coff/xcoff.h"
39 #define streq(a,b) (strcmp ((a), (b)) == 0)
40 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
42 /* I think this is probably always correct. */
43 #ifndef KEEP_RELOC_INFO
44 #define KEEP_RELOC_INFO
47 /* obj_coff_section will use this macro to set a new section's
48 attributes when a directive has no valid flags or the "w" flag is
49 used. This default should be appropriate for most. */
50 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
51 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
54 /* This is used to hold the symbol built by a sequence of pseudo-ops
55 from .def and .endef. */
56 static symbolS
*def_symbol_in_progress
;
58 /* PE weak alternate symbols begin with this string. */
59 static const char weak_altprefix
[] = ".weak.";
62 #include "obj-coff-seh.c"
66 unsigned long chunk_size
;
67 unsigned long element_size
;
70 unsigned long pointer
;
78 stack_init (unsigned long chunk_size
,
79 unsigned long element_size
)
83 st
= malloc (sizeof (* st
));
86 st
->data
= malloc (chunk_size
);
93 st
->size
= chunk_size
;
94 st
->chunk_size
= chunk_size
;
95 st
->element_size
= element_size
;
100 stack_push (stack
*st
, char *element
)
102 if (st
->pointer
+ st
->element_size
>= st
->size
)
104 st
->size
+= st
->chunk_size
;
105 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == NULL
)
108 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
109 st
->pointer
+= st
->element_size
;
110 return st
->data
+ st
->pointer
;
114 stack_pop (stack
*st
)
116 if (st
->pointer
< st
->element_size
)
121 st
->pointer
-= st
->element_size
;
122 return st
->data
+ st
->pointer
;
125 /* Maintain a list of the tagnames of the structures. */
127 static struct hash_control
*tag_hash
;
132 tag_hash
= hash_new ();
136 tag_insert (const char *name
, symbolS
*symbolP
)
138 const char *error_string
;
140 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
141 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
146 tag_find (char *name
)
148 return (symbolS
*) hash_find (tag_hash
, name
);
152 tag_find_or_make (char *name
)
156 if ((symbolP
= tag_find (name
)) == NULL
)
158 symbolP
= symbol_new (name
, undefined_section
,
159 0, &zero_address_frag
);
161 tag_insert (S_GET_NAME (symbolP
), symbolP
);
162 symbol_table_insert (symbolP
);
168 /* We accept the .bss directive to set the section for backward
169 compatibility with earlier versions of gas. */
172 obj_coff_bss (int ignore ATTRIBUTE_UNUSED
)
174 if (*input_line_pointer
== '\n')
175 subseg_new (".bss", get_absolute_expression ());
181 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
182 Parse a possible alignment value. */
185 obj_coff_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
189 if (*input_line_pointer
== ',')
191 align
= parse_align (0);
192 if (align
== (addressT
) -1)
196 S_SET_VALUE (symbolP
, size
);
197 S_SET_EXTERNAL (symbolP
);
198 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
200 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
202 /* There is no S_SET_ALIGN (symbolP, align) in COFF/PE.
203 Instead we must add a note to the .drectve section. */
206 segT current_seg
= now_seg
;
207 subsegT current_subseg
= now_subseg
;
210 size_t pfxlen
, numlen
;
214 sec
= subseg_new (".drectve", 0);
215 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
216 if (oldflags
== SEC_NO_FLAGS
)
218 if (!bfd_set_section_flags (stdoutput
, sec
,
219 TC_COFF_SECTION_DEFAULT_ATTRIBUTES
))
220 as_warn (_("error setting flags for \"%s\": %s"),
221 bfd_section_name (stdoutput
, sec
),
222 bfd_errmsg (bfd_get_error ()));
225 /* Emit a string. Note no NUL-termination. */
226 pfxlen
= strlen (" -aligncomm:") + 2 + strlen (S_GET_NAME (symbolP
)) + 1;
227 numlen
= snprintf (numbuff
, sizeof (numbuff
), "%d", (int) align
);
228 frag
= frag_more (pfxlen
+ numlen
);
229 (void) sprintf (frag
, " -aligncomm:\"%s\",", S_GET_NAME (symbolP
));
230 memcpy (frag
+ pfxlen
, numbuff
, numlen
);
231 /* Restore original subseg. */
232 subseg_set (current_seg
, current_subseg
);
239 obj_coff_comm (int ignore ATTRIBUTE_UNUSED
)
241 s_comm_internal (ignore
, obj_coff_common_parse
);
245 #define GET_FILENAME_STRING(X) \
246 ((char *) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
250 fetch_coff_debug_section (void)
252 static segT debug_section
;
258 s
= bfd_make_debug_symbol (stdoutput
, NULL
, 0);
260 debug_section
= s
->section
;
262 return debug_section
;
266 SA_SET_SYM_ENDNDX (symbolS
*sym
, symbolS
*val
)
268 combined_entry_type
*entry
, *p
;
270 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
271 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
272 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
277 SA_SET_SYM_TAGNDX (symbolS
*sym
, symbolS
*val
)
279 combined_entry_type
*entry
, *p
;
281 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
282 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
283 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
288 S_GET_DATA_TYPE (symbolS
*sym
)
290 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
294 S_SET_DATA_TYPE (symbolS
*sym
, int val
)
296 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
301 S_GET_STORAGE_CLASS (symbolS
*sym
)
303 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
307 S_SET_STORAGE_CLASS (symbolS
*sym
, int val
)
309 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
313 /* Merge a debug symbol containing debug information into a normal symbol. */
316 c_symbol_merge (symbolS
*debug
, symbolS
*normal
)
318 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
319 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
321 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
322 /* Take the most we have. */
323 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
325 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
326 /* Move all the auxiliary information. */
327 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
328 (S_GET_NUMBER_AUXILIARY (debug
)
329 * sizeof (*SYM_AUXINFO (debug
))));
331 /* Move the debug flags. */
332 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
336 c_dot_file_symbol (const char *filename
, int appfile ATTRIBUTE_UNUSED
)
340 /* BFD converts filename to a .file symbol with an aux entry. It
341 also handles chaining. */
342 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
344 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
345 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
347 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
354 listing_source_file (filename
);
358 /* Make sure that the symbol is first on the symbol chain. */
359 if (symbol_rootP
!= symbolP
)
361 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
362 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
366 /* Line number handling. */
370 struct line_no
*next
;
377 /* Symbol of last function, which we should hang line#s off of. */
378 static symbolS
*line_fsym
;
380 #define in_function() (line_fsym != 0)
381 #define clear_function() (line_fsym = 0)
382 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
386 coff_obj_symbol_new_hook (symbolS
*symbolP
)
388 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
389 char * s
= xmalloc (sz
);
392 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
394 S_SET_DATA_TYPE (symbolP
, T_NULL
);
395 S_SET_STORAGE_CLASS (symbolP
, 0);
396 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
398 if (S_IS_STRING (symbolP
))
399 SF_SET_STRING (symbolP
);
401 if (S_IS_LOCAL (symbolP
))
402 SF_SET_LOCAL (symbolP
);
406 coff_obj_symbol_clone_hook (symbolS
*newsymP
, symbolS
*orgsymP
)
408 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
409 combined_entry_type
* s
= xmalloc (sz
);
411 memcpy (s
, coffsymbol (symbol_get_bfdsym (orgsymP
))->native
, sz
);
412 coffsymbol (symbol_get_bfdsym (newsymP
))->native
= s
;
414 SF_SET (newsymP
, SF_GET (orgsymP
));
418 /* Handle .ln directives. */
420 static symbolS
*current_lineno_sym
;
421 static struct line_no
*line_nos
;
422 /* FIXME: Blindly assume all .ln directives will be in the .text section. */
426 add_lineno (fragS
* frag
, addressT offset
, int num
)
428 struct line_no
* new_line
= xmalloc (sizeof (* new_line
));
430 if (!current_lineno_sym
)
434 /* The native aix assembler accepts negative line number. */
438 /* Zero is used as an end marker in the file. */
439 as_warn (_("Line numbers must be positive integers\n"));
442 #endif /* OBJ_XCOFF */
443 new_line
->next
= line_nos
;
444 new_line
->frag
= frag
;
445 new_line
->l
.line_number
= num
;
446 new_line
->l
.u
.offset
= offset
;
452 coff_add_linesym (symbolS
*sym
)
456 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
461 current_lineno_sym
= sym
;
465 obj_coff_ln (int appline
)
469 if (! appline
&& def_symbol_in_progress
!= NULL
)
471 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
472 demand_empty_rest_of_line ();
476 l
= get_absolute_expression ();
478 /* If there is no lineno symbol, treat a .ln
479 directive as if it were a .appline directive. */
480 if (appline
|| current_lineno_sym
== NULL
)
481 new_logical_line ((char *) NULL
, l
- 1);
483 add_lineno (frag_now
, frag_now_fix (), l
);
492 l
+= coff_line_base
- 1;
493 listing_source_line (l
);
498 demand_empty_rest_of_line ();
501 /* .loc is essentially the same as .ln; parse it for assembler
505 obj_coff_loc (int ignore ATTRIBUTE_UNUSED
)
509 /* FIXME: Why do we need this check? We need it for ECOFF, but why
510 do we need it for COFF? */
511 if (now_seg
!= text_section
)
513 as_warn (_(".loc outside of .text"));
514 demand_empty_rest_of_line ();
518 if (def_symbol_in_progress
!= NULL
)
520 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
521 demand_empty_rest_of_line ();
525 /* Skip the file number. */
527 get_absolute_expression ();
530 lineno
= get_absolute_expression ();
538 lineno
+= coff_line_base
- 1;
539 listing_source_line (lineno
);
544 demand_empty_rest_of_line ();
546 add_lineno (frag_now
, frag_now_fix (), lineno
);
549 /* Handle the .ident pseudo-op. */
552 obj_coff_ident (int ignore ATTRIBUTE_UNUSED
)
554 segT current_seg
= now_seg
;
555 subsegT current_subseg
= now_subseg
;
561 /* We could put it in .comment, but that creates an extra section
562 that shouldn't be loaded into memory, which requires linker
563 changes... For now, until proven otherwise, use .rdata. */
564 sec
= subseg_new (".rdata$zzz", 0);
565 bfd_set_section_flags (stdoutput
, sec
,
566 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
567 & bfd_applicable_section_flags (stdoutput
)));
570 subseg_new (".comment", 0);
574 subseg_set (current_seg
, current_subseg
);
577 /* Handle .def directives.
579 One might ask : why can't we symbol_new if the symbol does not
580 already exist and fill it with debug information. Because of
581 the C_EFCN special symbol. It would clobber the value of the
582 function symbol before we have a chance to notice that it is
583 a C_EFCN. And a second reason is that the code is more clear this
584 way. (at least I think it is :-). */
586 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
587 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
588 *input_line_pointer == '\t') \
589 input_line_pointer++;
592 obj_coff_def (int what ATTRIBUTE_UNUSED
)
594 char name_end
; /* Char after the end of name. */
595 char *symbol_name
; /* Name of the debug symbol. */
596 char *symbol_name_copy
; /* Temporary copy of the name. */
597 unsigned int symbol_name_length
;
599 if (def_symbol_in_progress
!= NULL
)
601 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
602 demand_empty_rest_of_line ();
608 symbol_name
= input_line_pointer
;
609 name_end
= get_symbol_end ();
610 symbol_name_length
= strlen (symbol_name
);
611 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
612 strcpy (symbol_name_copy
, symbol_name
);
613 #ifdef tc_canonicalize_symbol_name
614 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
617 /* Initialize the new symbol. */
618 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
619 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
620 S_SET_VALUE (def_symbol_in_progress
, 0);
622 if (S_IS_STRING (def_symbol_in_progress
))
623 SF_SET_STRING (def_symbol_in_progress
);
625 *input_line_pointer
= name_end
;
627 demand_empty_rest_of_line ();
631 obj_coff_endef (int ignore ATTRIBUTE_UNUSED
)
633 symbolS
*symbolP
= NULL
;
635 if (def_symbol_in_progress
== NULL
)
637 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
638 demand_empty_rest_of_line ();
642 /* Set the section number according to storage class. */
643 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
648 SF_SET_TAG (def_symbol_in_progress
);
652 SF_SET_DEBUG (def_symbol_in_progress
);
653 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
657 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
660 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing. */
666 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
668 name
= S_GET_NAME (def_symbol_in_progress
);
669 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
675 if (! in_function ())
676 as_warn (_("`%s' symbol without preceding function"), name
);
677 /* Will need relocating. */
678 SF_SET_PROCESS (def_symbol_in_progress
);
684 /* The MS compilers output the actual endline, not the
685 function-relative one... we want to match without
686 changing the assembler input. */
687 SA_SET_SYM_LNNO (def_symbol_in_progress
,
688 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
699 #endif /* C_AUTOARG */
706 /* According to the COFF documentation:
708 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
710 A special section number (-2) marks symbolic debugging symbols,
711 including structure/union/enumeration tag names, typedefs, and
712 the name of the file. A section number of -1 indicates that the
713 symbol has a value but is not relocatable. Examples of
714 absolute-valued symbols include automatic and register variables,
715 function arguments, and .eos symbols.
717 But from Ian Lance Taylor:
719 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
721 the actual tools all marked them as section -1. So the GNU COFF
722 assembler follows historical COFF assemblers.
724 However, it causes problems for djgpp
726 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
728 By defining STRICTCOFF, a COFF port can make the assembler to
729 follow the documented behavior. */
736 SF_SET_DEBUG (def_symbol_in_progress
);
737 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
745 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
756 /* Valid but set somewhere else (s_comm, s_lcomm, colon). */
763 as_warn (_("unexpected storage class %d"),
764 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
768 /* Now that we have built a debug symbol, try to find if we should
769 merge with an existing symbol or not. If a symbol is C_EFCN or
770 absolute_section or untagged SEG_DEBUG it never merges. We also
771 don't merge labels, which are in a different namespace, nor
772 symbols which have not yet been defined since they are typically
773 unique, nor do we merge tags with non-tags. */
775 /* Two cases for functions. Either debug followed by definition or
776 definition followed by debug. For definition first, we will
777 merge the debug symbol into the definition. For debug first, the
778 lineno entry MUST point to the definition function or else it
779 will point off into space when obj_crawl_symbol_chain() merges
780 the debug symbol into the real symbol. Therefor, let's presume
781 the debug symbol is a real function reference. */
783 /* FIXME-SOON If for some reason the definition label/symbol is
784 never seen, this will probably leave an undefined symbol at link
787 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
788 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
789 || (streq (bfd_get_section_name (stdoutput
,
790 S_GET_SEGMENT (def_symbol_in_progress
)),
792 && !SF_GET_TAG (def_symbol_in_progress
))
793 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
794 || ! symbol_constant_p (def_symbol_in_progress
)
795 || (symbolP
= symbol_find (S_GET_NAME (def_symbol_in_progress
))) == NULL
796 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
798 /* If it already is at the end of the symbol list, do nothing */
799 if (def_symbol_in_progress
!= symbol_lastP
)
801 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
802 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
808 /* This symbol already exists, merge the newly created symbol
809 into the old one. This is not mandatory. The linker can
810 handle duplicate symbols correctly. But I guess that it save
811 a *lot* of space if the assembly file defines a lot of
814 /* The debug entry (def_symbol_in_progress) is merged into the
815 previous definition. */
817 c_symbol_merge (def_symbol_in_progress
, symbolP
);
818 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
820 def_symbol_in_progress
= symbolP
;
822 if (SF_GET_FUNCTION (def_symbol_in_progress
)
823 || SF_GET_TAG (def_symbol_in_progress
)
824 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
826 /* For functions, and tags, and static symbols, the symbol
827 *must* be where the debug symbol appears. Move the
828 existing symbol to the current place. */
829 /* If it already is at the end of the symbol list, do nothing. */
830 if (def_symbol_in_progress
!= symbol_lastP
)
832 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
833 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
838 if (SF_GET_TAG (def_symbol_in_progress
))
842 oldtag
= symbol_find (S_GET_NAME (def_symbol_in_progress
));
843 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
844 tag_insert (S_GET_NAME (def_symbol_in_progress
),
845 def_symbol_in_progress
);
848 if (SF_GET_FUNCTION (def_symbol_in_progress
))
850 set_function (def_symbol_in_progress
);
851 SF_SET_PROCESS (def_symbol_in_progress
);
854 /* That is, if this is the first time we've seen the
856 symbol_table_insert (def_symbol_in_progress
);
860 def_symbol_in_progress
= NULL
;
861 demand_empty_rest_of_line ();
865 obj_coff_dim (int ignore ATTRIBUTE_UNUSED
)
869 if (def_symbol_in_progress
== NULL
)
871 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
872 demand_empty_rest_of_line ();
876 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
878 for (d_index
= 0; d_index
< DIMNUM
; d_index
++)
881 SA_SET_SYM_DIMEN (def_symbol_in_progress
, d_index
,
882 get_absolute_expression ());
884 switch (*input_line_pointer
)
887 input_line_pointer
++;
891 as_warn (_("badly formed .dim directive ignored"));
900 demand_empty_rest_of_line ();
904 obj_coff_line (int ignore ATTRIBUTE_UNUSED
)
908 if (def_symbol_in_progress
== NULL
)
910 /* Probably stabs-style line? */
915 this_base
= get_absolute_expression ();
916 if (streq (".bf", S_GET_NAME (def_symbol_in_progress
)))
917 coff_line_base
= this_base
;
919 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
920 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
922 demand_empty_rest_of_line ();
925 if (streq (".bf", S_GET_NAME (def_symbol_in_progress
)))
930 listing_source_line ((unsigned int) this_base
);
936 obj_coff_size (int ignore ATTRIBUTE_UNUSED
)
938 if (def_symbol_in_progress
== NULL
)
940 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
941 demand_empty_rest_of_line ();
945 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
946 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
947 demand_empty_rest_of_line ();
951 obj_coff_scl (int ignore ATTRIBUTE_UNUSED
)
953 if (def_symbol_in_progress
== NULL
)
955 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
956 demand_empty_rest_of_line ();
960 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
961 demand_empty_rest_of_line ();
965 obj_coff_tag (int ignore ATTRIBUTE_UNUSED
)
970 if (def_symbol_in_progress
== NULL
)
972 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
973 demand_empty_rest_of_line ();
977 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
978 symbol_name
= input_line_pointer
;
979 name_end
= get_symbol_end ();
981 #ifdef tc_canonicalize_symbol_name
982 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
985 /* Assume that the symbol referred to by .tag is always defined.
986 This was a bad assumption. I've added find_or_make. xoxorich. */
987 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
988 tag_find_or_make (symbol_name
));
989 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
990 as_warn (_("tag not found for .tag %s"), symbol_name
);
992 SF_SET_TAGGED (def_symbol_in_progress
);
993 *input_line_pointer
= name_end
;
995 demand_empty_rest_of_line ();
999 obj_coff_type (int ignore ATTRIBUTE_UNUSED
)
1001 if (def_symbol_in_progress
== NULL
)
1003 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1004 demand_empty_rest_of_line ();
1008 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1010 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1011 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1012 SF_SET_FUNCTION (def_symbol_in_progress
);
1014 demand_empty_rest_of_line ();
1018 obj_coff_val (int ignore ATTRIBUTE_UNUSED
)
1020 if (def_symbol_in_progress
== NULL
)
1022 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1023 demand_empty_rest_of_line ();
1027 if (is_name_beginner (*input_line_pointer
))
1029 char *symbol_name
= input_line_pointer
;
1030 char name_end
= get_symbol_end ();
1032 #ifdef tc_canonicalize_symbol_name
1033 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1035 if (streq (symbol_name
, "."))
1037 /* If the .val is != from the .def (e.g. statics). */
1038 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1039 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1041 else if (! streq (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1045 exp
.X_op
= O_symbol
;
1046 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1047 exp
.X_op_symbol
= NULL
;
1048 exp
.X_add_number
= 0;
1049 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1051 /* If the segment is undefined when the forward reference is
1052 resolved, then copy the segment id from the forward
1054 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1056 /* FIXME: gcc can generate address expressions here in
1057 unusual cases (search for "obscure" in sdbout.c). We
1058 just ignore the offset here, thus generating incorrect
1059 debugging information. We ignore the rest of the line
1062 /* Otherwise, it is the name of a non debug symbol and its value
1063 will be calculated later. */
1064 *input_line_pointer
= name_end
;
1068 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1071 demand_empty_rest_of_line ();
1076 /* Return nonzero if name begins with weak alternate symbol prefix. */
1079 weak_is_altname (const char * name
)
1081 return strneq (name
, weak_altprefix
, sizeof (weak_altprefix
) - 1);
1084 /* Return the name of the alternate symbol
1085 name corresponding to a weak symbol's name. */
1088 weak_name2altname (const char * name
)
1092 alt_name
= xmalloc (sizeof (weak_altprefix
) + strlen (name
));
1093 strcpy (alt_name
, weak_altprefix
);
1094 return strcat (alt_name
, name
);
1097 /* Return the name of the weak symbol corresponding to an
1098 alternate symbol. */
1101 weak_altname2name (const char * name
)
1103 gas_assert (weak_is_altname (name
));
1104 return xstrdup (name
+ 6);
1107 /* Make a weak symbol name unique by
1108 appending the name of an external symbol. */
1111 weak_uniquify (const char * name
)
1114 const char * unique
= "";
1117 if (an_external_name
!= NULL
)
1118 unique
= an_external_name
;
1120 gas_assert (weak_is_altname (name
));
1122 ret
= xmalloc (strlen (name
) + strlen (unique
) + 2);
1125 strcat (ret
, unique
);
1130 pecoff_obj_set_weak_hook (symbolS
*symbolP
)
1132 symbolS
*alternateP
;
1134 /* See _Microsoft Portable Executable and Common Object
1135 File Format Specification_, section 5.5.3.
1136 Create a symbol representing the alternate value.
1137 coff_frob_symbol will set the value of this symbol from
1138 the value of the weak symbol itself. */
1139 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
1140 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1141 SA_SET_SYM_FSIZE (symbolP
, IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY
);
1143 alternateP
= symbol_find_or_make (weak_name2altname (S_GET_NAME (symbolP
)));
1144 S_SET_EXTERNAL (alternateP
);
1145 S_SET_STORAGE_CLASS (alternateP
, C_NT_WEAK
);
1147 SA_SET_SYM_TAGNDX (symbolP
, alternateP
);
1151 pecoff_obj_clear_weak_hook (symbolS
*symbolP
)
1153 symbolS
*alternateP
;
1155 S_SET_STORAGE_CLASS (symbolP
, 0);
1156 SA_SET_SYM_FSIZE (symbolP
, 0);
1158 alternateP
= symbol_find (weak_name2altname (S_GET_NAME (symbolP
)));
1159 S_CLEAR_EXTERNAL (alternateP
);
1164 /* Handle .weak. This is a GNU extension in formats other than PE. */
1167 obj_coff_weak (int ignore ATTRIBUTE_UNUSED
)
1175 name
= input_line_pointer
;
1176 c
= get_symbol_end ();
1179 as_warn (_("badly formed .weak directive ignored"));
1180 ignore_rest_of_line ();
1184 symbolP
= symbol_find_or_make (name
);
1185 *input_line_pointer
= c
;
1187 S_SET_WEAK (symbolP
);
1191 input_line_pointer
++;
1193 if (*input_line_pointer
== '\n')
1200 demand_empty_rest_of_line ();
1204 coff_obj_read_begin_hook (void)
1206 /* These had better be the same. Usually 18 bytes. */
1207 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1208 know (SYMESZ
== AUXESZ
);
1212 symbolS
*coff_last_function
;
1214 static symbolS
*coff_last_bf
;
1218 coff_frob_symbol (symbolS
*symp
, int *punt
)
1220 static symbolS
*last_tagP
;
1221 static stack
*block_stack
;
1222 static symbolS
*set_end
;
1223 symbolS
*next_set_end
= NULL
;
1225 if (symp
== &abs_symbol
)
1231 if (current_lineno_sym
)
1232 coff_add_linesym (NULL
);
1235 block_stack
= stack_init (512, sizeof (symbolS
*));
1238 if (S_GET_STORAGE_CLASS (symp
) == C_NT_WEAK
1239 && ! S_IS_WEAK (symp
)
1240 && weak_is_altname (S_GET_NAME (symp
)))
1242 /* This is a weak alternate symbol. All processing of
1243 PECOFFweak symbols is done here, through the alternate. */
1244 symbolS
*weakp
= symbol_find_noref (weak_altname2name
1245 (S_GET_NAME (symp
)), 1);
1248 gas_assert (S_GET_NUMBER_AUXILIARY (weakp
) == 1);
1250 if (! S_IS_WEAK (weakp
))
1252 /* The symbol was turned from weak to strong. Discard altname. */
1256 else if (symbol_equated_p (weakp
))
1258 /* The weak symbol has an alternate specified; symp is unneeded. */
1259 S_SET_STORAGE_CLASS (weakp
, C_NT_WEAK
);
1260 SA_SET_SYM_TAGNDX (weakp
,
1261 symbol_get_value_expression (weakp
)->X_add_symbol
);
1263 S_CLEAR_EXTERNAL (symp
);
1269 /* The weak symbol has been assigned an alternate value.
1270 Copy this value to symp, and set symp as weakp's alternate. */
1271 if (S_GET_STORAGE_CLASS (weakp
) != C_NT_WEAK
)
1273 S_SET_STORAGE_CLASS (symp
, S_GET_STORAGE_CLASS (weakp
));
1274 S_SET_STORAGE_CLASS (weakp
, C_NT_WEAK
);
1277 if (S_IS_DEFINED (weakp
))
1279 /* This is a defined weak symbol. Copy value information
1280 from the weak symbol itself to the alternate symbol. */
1281 symbol_set_value_expression (symp
,
1282 symbol_get_value_expression (weakp
));
1283 symbol_set_frag (symp
, symbol_get_frag (weakp
));
1284 S_SET_SEGMENT (symp
, S_GET_SEGMENT (weakp
));
1288 /* This is an undefined weak symbol.
1289 Define the alternate symbol to zero. */
1290 S_SET_VALUE (symp
, 0);
1291 S_SET_SEGMENT (symp
, absolute_section
);
1294 S_SET_NAME (symp
, weak_uniquify (S_GET_NAME (symp
)));
1295 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1297 S_SET_VALUE (weakp
, 0);
1298 S_SET_SEGMENT (weakp
, undefined_section
);
1302 if (S_IS_WEAK (symp
))
1303 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1306 if (!S_IS_DEFINED (symp
)
1307 && !S_IS_WEAK (symp
)
1308 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1309 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1311 if (!SF_GET_DEBUG (symp
))
1315 if (!SF_GET_LOCAL (symp
)
1316 && !SF_GET_STATICS (symp
)
1317 && S_GET_STORAGE_CLASS (symp
) != C_LABEL
1318 && symbol_constant_p (symp
)
1319 && (real
= symbol_find_noref (S_GET_NAME (symp
), 1))
1320 && S_GET_STORAGE_CLASS (real
) == C_NULL
1323 c_symbol_merge (symp
, real
);
1328 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1330 gas_assert (S_GET_VALUE (symp
) == 0);
1331 if (S_IS_WEAKREFD (symp
))
1334 S_SET_EXTERNAL (symp
);
1336 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1338 if (S_GET_SEGMENT (symp
) == text_section
1339 && symp
!= seg_info (text_section
)->sym
)
1340 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1342 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1345 if (SF_GET_PROCESS (symp
))
1347 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1349 if (streq (S_GET_NAME (symp
), ".bb"))
1350 stack_push (block_stack
, (char *) &symp
);
1355 begin
= *(symbolS
**) stack_pop (block_stack
);
1357 as_warn (_("mismatched .eb"));
1359 next_set_end
= begin
;
1363 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
)
1364 && S_IS_DEFINED (symp
))
1366 union internal_auxent
*auxp
;
1368 coff_last_function
= symp
;
1369 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1370 S_SET_NUMBER_AUXILIARY (symp
, 1);
1371 auxp
= SYM_AUXENT (symp
);
1372 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1373 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1376 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
1377 && S_IS_DEFINED (symp
))
1379 if (coff_last_function
== 0)
1380 as_fatal (_("C_EFCN symbol for %s out of scope"),
1382 SA_SET_SYM_FSIZE (coff_last_function
,
1383 (long) (S_GET_VALUE (symp
)
1384 - S_GET_VALUE (coff_last_function
)));
1385 next_set_end
= coff_last_function
;
1386 coff_last_function
= 0;
1390 if (S_IS_EXTERNAL (symp
))
1391 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1392 else if (SF_GET_LOCAL (symp
))
1395 if (SF_GET_FUNCTION (symp
))
1396 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1399 /* Double check weak symbols. */
1400 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1401 as_bad (_("Symbol `%s' can not be both weak and common"),
1404 if (SF_GET_TAG (symp
))
1406 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1407 next_set_end
= last_tagP
;
1410 /* This is pretty horrible, but we have to set *punt correctly in
1411 order to call SA_SET_SYM_ENDNDX correctly. */
1412 if (! symbol_used_in_reloc_p (symp
)
1413 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1414 || (! (S_IS_EXTERNAL (symp
) || S_IS_WEAK (symp
))
1415 && ! symbol_get_tc (symp
)->output
1416 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1420 if (set_end
!= (symbolS
*) NULL
1422 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1423 || (S_IS_DEFINED (symp
)
1424 && ! S_IS_COMMON (symp
)
1425 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1427 SA_SET_SYM_ENDNDX (set_end
, symp
);
1431 if (next_set_end
!= NULL
)
1433 if (set_end
!= NULL
)
1434 as_warn (_("Warning: internal error: forgetting to set endndx of %s"),
1435 S_GET_NAME (set_end
));
1436 set_end
= next_set_end
;
1441 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1442 && streq (S_GET_NAME (symp
), ".bf"))
1444 if (coff_last_bf
!= NULL
)
1445 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1446 coff_last_bf
= symp
;
1449 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1452 struct line_no
*lptr
;
1455 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1456 for (i
= 0; lptr
; lptr
= lptr
->next
)
1458 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1460 /* We need i entries for line numbers, plus 1 for the first
1461 entry which BFD will override, plus 1 for the last zero
1462 entry (a marker for BFD). */
1463 l
= xmalloc ((i
+ 2) * sizeof (* l
));
1464 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1465 l
[i
+ 1].line_number
= 0;
1466 l
[i
+ 1].u
.sym
= NULL
;
1470 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1478 coff_adjust_section_syms (bfd
*abfd ATTRIBUTE_UNUSED
,
1480 void * x ATTRIBUTE_UNUSED
)
1483 segment_info_type
*seginfo
= seg_info (sec
);
1484 int nlnno
, nrelocs
= 0;
1486 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1487 tc-ppc.c. Do not get confused by it. */
1488 if (seginfo
== NULL
)
1491 if (streq (sec
->name
, ".text"))
1492 nlnno
= coff_n_line_nos
;
1496 /* @@ Hope that none of the fixups expand to more than one reloc
1498 fixS
*fixp
= seginfo
->fix_root
;
1501 if (! fixp
->fx_done
)
1503 fixp
= fixp
->fx_next
;
1506 if (bfd_get_section_size (sec
) == 0
1509 && sec
!= text_section
1510 && sec
!= data_section
1511 && sec
!= bss_section
)
1514 secsym
= section_symbol (sec
);
1515 /* This is an estimate; we'll plug in the real value using
1516 SET_SECTION_RELOCS later */
1517 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1518 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1522 coff_frob_file_after_relocs (void)
1524 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, NULL
);
1527 /* Implement the .section pseudo op:
1528 .section name {, "flags"}
1530 | +--- optional flags: 'b' for bss
1532 +-- section name 'l' for lib
1536 'd' (apparently m88k for data)
1539 'r' for read-only data
1540 's' for shared data (PE)
1542 '0' - '9' for power-of-two alignment (GNU extension).
1543 But if the argument is not a quoted string, treat it as a
1546 Note the 'a' flag is silently ignored. This allows the same
1547 .section directive to be parsed in both ELF and COFF formats. */
1550 obj_coff_section (int ignore ATTRIBUTE_UNUSED
)
1552 /* Strip out the section name. */
1558 flagword flags
, oldflags
;
1569 section_name
= input_line_pointer
;
1570 c
= get_symbol_end ();
1572 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1573 strcpy (name
, section_name
);
1575 *input_line_pointer
= c
;
1580 flags
= SEC_NO_FLAGS
;
1582 if (*input_line_pointer
== ',')
1584 ++input_line_pointer
;
1586 if (*input_line_pointer
!= '"')
1587 exp
= get_absolute_expression ();
1591 int readonly_removed
= 0;
1592 int load_removed
= 0;
1594 while (attr
= *++input_line_pointer
,
1596 && ! is_end_of_line
[attr
])
1600 alignment
= attr
- '0';
1606 /* Exclude section from linking. */
1607 flags
|= SEC_EXCLUDE
;
1611 /* Uninitialised data section. */
1617 /* Section not loaded. */
1619 flags
|= SEC_NEVER_LOAD
;
1624 /* Shared section. */
1625 flags
|= SEC_COFF_SHARED
;
1632 flags
&=~ SEC_READONLY
;
1636 /* Writable section. */
1637 flags
&=~ SEC_READONLY
;
1638 readonly_removed
= 1;
1642 /* Ignore. Here for compatibility with ELF. */
1645 case 'r': /* Read-only section. Implies a data section. */
1646 readonly_removed
= 0;
1648 case 'x': /* Executable section. */
1649 /* If we are setting the 'x' attribute or if the 'r'
1650 attribute is being used to restore the readonly status
1651 of a code section (eg "wxr") then set the SEC_CODE flag,
1652 otherwise set the SEC_DATA flag. */
1653 flags
|= (attr
== 'x' || (flags
& SEC_CODE
) ? SEC_CODE
: SEC_DATA
);
1656 /* Note - the READONLY flag is set here, even for the 'x'
1657 attribute in order to be compatible with the MSVC
1659 if (! readonly_removed
)
1660 flags
|= SEC_READONLY
;
1664 flags
|= SEC_COFF_NOREAD
| SEC_READONLY
;
1667 case 'i': /* STYP_INFO */
1668 case 'l': /* STYP_LIB */
1669 case 'o': /* STYP_OVER */
1670 as_warn (_("unsupported section attribute '%c'"), attr
);
1674 as_warn (_("unknown section attribute '%c'"), attr
);
1679 ++input_line_pointer
;
1683 sec
= subseg_new (name
, (subsegT
) exp
);
1686 sec
->alignment_power
= alignment
;
1688 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1689 if (oldflags
== SEC_NO_FLAGS
)
1691 /* Set section flags for a new section just created by subseg_new.
1692 Provide a default if no flags were parsed. */
1693 if (flags
== SEC_NO_FLAGS
)
1694 flags
= TC_COFF_SECTION_DEFAULT_ATTRIBUTES
;
1696 #ifdef COFF_LONG_SECTION_NAMES
1697 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1698 sections so adjust_reloc_syms in write.c will correctly handle
1699 relocs which refer to non-local symbols in these sections. */
1700 if (strneq (name
, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1))
1701 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1704 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1705 as_warn (_("error setting flags for \"%s\": %s"),
1706 bfd_section_name (stdoutput
, sec
),
1707 bfd_errmsg (bfd_get_error ()));
1709 else if (flags
!= SEC_NO_FLAGS
)
1711 /* This section's attributes have already been set. Warn if the
1712 attributes don't match. */
1713 flagword matchflags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1714 | SEC_DATA
| SEC_COFF_SHARED
| SEC_NEVER_LOAD
1716 if ((flags
^ oldflags
) & matchflags
)
1717 as_warn (_("Ignoring changed section attributes for %s"), name
);
1720 demand_empty_rest_of_line ();
1724 coff_adjust_symtab (void)
1726 if (symbol_rootP
== NULL
1727 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1728 c_dot_file_symbol ("fake", 0);
1732 coff_frob_section (segT sec
)
1739 /* The COFF back end in BFD requires that all section sizes be
1740 rounded up to multiples of the corresponding section alignments,
1741 supposedly because standard COFF has no other way of encoding alignment
1742 for sections. If your COFF flavor has a different way of encoding
1743 section alignment, then skip this step, as TICOFF does. */
1744 bfd_vma size
= bfd_get_section_size (sec
);
1745 #if !defined(TICOFF)
1746 bfd_vma align_power
= (bfd_vma
) sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1747 bfd_vma mask
= ((bfd_vma
) 1 << align_power
) - 1;
1754 new_size
= (size
+ mask
) & ~mask
;
1755 bfd_set_section_size (stdoutput
, sec
, new_size
);
1757 /* If the size had to be rounded up, add some padding in
1758 the last non-empty frag. */
1759 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1760 last
= seg_info (sec
)->frchainP
->frch_last
;
1761 while (fragp
->fr_next
!= last
)
1762 fragp
= fragp
->fr_next
;
1763 last
->fr_address
= size
;
1764 fragp
->fr_offset
+= new_size
- size
;
1768 /* If the section size is non-zero, the section symbol needs an aux
1769 entry associated with it, indicating the size. We don't know
1770 all the values yet; coff_frob_symbol will fill them in later. */
1773 || sec
== text_section
1774 || sec
== data_section
1775 || sec
== bss_section
)
1778 symbolS
*secsym
= section_symbol (sec
);
1779 unsigned char sclass
= C_STAT
;
1782 if (bfd_get_section_flags (stdoutput
, sec
) & SEC_DEBUGGING
)
1785 S_SET_STORAGE_CLASS (secsym
, sclass
);
1786 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1787 SF_SET_STATICS (secsym
);
1788 SA_SET_SCN_SCNLEN (secsym
, size
);
1790 /* FIXME: These should be in a "stabs.h" file, or maybe as.h. */
1791 #ifndef STAB_SECTION_NAME
1792 #define STAB_SECTION_NAME ".stab"
1794 #ifndef STAB_STRING_SECTION_NAME
1795 #define STAB_STRING_SECTION_NAME ".stabstr"
1797 if (! streq (STAB_STRING_SECTION_NAME
, sec
->name
))
1801 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1802 /* size is already rounded up, since other section will be listed first */
1803 size
= bfd_get_section_size (strsec
);
1805 n_entries
= bfd_get_section_size (sec
) / 12 - 1;
1807 /* Find first non-empty frag. It should be large enough. */
1808 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1809 while (fragp
&& fragp
->fr_fix
== 0)
1810 fragp
= fragp
->fr_next
;
1811 gas_assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1813 /* Store the values. */
1814 p
= fragp
->fr_literal
;
1815 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1816 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1820 obj_coff_init_stab_section (segT seg
)
1825 unsigned int stroff
;
1827 /* Make space for this first symbol. */
1831 as_where (&file
, (unsigned int *) NULL
);
1832 stabstr_name
= xmalloc (strlen (seg
->name
) + 4);
1833 strcpy (stabstr_name
, seg
->name
);
1834 strcat (stabstr_name
, "str");
1835 stroff
= get_stab_string_offset (file
, stabstr_name
);
1837 md_number_to_chars (p
, stroff
, 4);
1841 const char * s_get_name (symbolS
*);
1844 s_get_name (symbolS
*s
)
1846 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1849 void symbol_dump (void);
1856 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1857 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1858 (unsigned long) symbolP
,
1859 S_GET_NAME (symbolP
),
1860 (long) S_GET_DATA_TYPE (symbolP
),
1861 S_GET_STORAGE_CLASS (symbolP
),
1862 (int) S_GET_SEGMENT (symbolP
));
1867 const pseudo_typeS coff_pseudo_table
[] =
1869 {"ABORT", s_abort
, 0},
1870 {"appline", obj_coff_ln
, 1},
1871 /* We accept the .bss directive for backward compatibility with
1872 earlier versions of gas. */
1873 {"bss", obj_coff_bss
, 0},
1875 /* PE provides an enhanced version of .comm with alignment. */
1876 {"comm", obj_coff_comm
, 0},
1878 {"def", obj_coff_def
, 0},
1879 {"dim", obj_coff_dim
, 0},
1880 {"endef", obj_coff_endef
, 0},
1881 {"ident", obj_coff_ident
, 0},
1882 {"line", obj_coff_line
, 0},
1883 {"ln", obj_coff_ln
, 0},
1884 {"scl", obj_coff_scl
, 0},
1885 {"sect", obj_coff_section
, 0},
1886 {"sect.s", obj_coff_section
, 0},
1887 {"section", obj_coff_section
, 0},
1888 {"section.s", obj_coff_section
, 0},
1889 /* FIXME: We ignore the MRI short attribute. */
1890 {"size", obj_coff_size
, 0},
1891 {"tag", obj_coff_tag
, 0},
1892 {"type", obj_coff_type
, 0},
1893 {"val", obj_coff_val
, 0},
1894 {"version", s_ignore
, 0},
1895 {"loc", obj_coff_loc
, 0},
1896 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
1897 {"weak", obj_coff_weak
, 0},
1898 #if defined TC_TIC4X
1899 /* The tic4x uses sdef instead of def. */
1900 {"sdef", obj_coff_def
, 0},
1902 #if defined(SEH_CMDS)
1909 /* Support for a COFF emulation. */
1912 coff_pop_insert (void)
1914 pop_insert (coff_pseudo_table
);
1918 coff_separate_stab_sections (void)
1923 const struct format_ops coff_format_ops
=
1925 bfd_target_coff_flavour
,
1926 0, /* dfl_leading_underscore */
1927 1, /* emit_section_symbols */
1932 0, /* frob_file_before_adjust */
1933 0, /* frob_file_before_fix */
1934 coff_frob_file_after_relocs
,
1937 0, /* s_get_align */
1938 0, /* s_set_align */
1939 0, /* s_get_other */
1940 0, /* s_set_other */
1945 0, /* copy_symbol_attributes */
1946 0, /* generate_asm_lineno */
1947 0, /* process_stab */
1948 coff_separate_stab_sections
,
1949 obj_coff_init_stab_section
,
1950 0, /* sec_sym_ok_for_reloc */
1952 0, /* ecoff_set_ext */
1953 coff_obj_read_begin_hook
,
1954 coff_obj_symbol_new_hook
,
1955 coff_obj_symbol_clone_hook
,