1 /* coff object file format
2 Copyright (C) 1989-2021 Free Software Foundation, Inc.
4 This file is part of GAS.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 #define OBJ_HEADER "obj-coff.h"
24 #include "safe-ctype.h"
32 #include "coff/xcoff.h"
35 #define streq(a,b) (strcmp ((a), (b)) == 0)
36 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
38 /* I think this is probably always correct. */
39 #ifndef KEEP_RELOC_INFO
40 #define KEEP_RELOC_INFO
43 /* obj_coff_section will use this macro to set a new section's
44 attributes when a directive has no valid flags or the "w" flag is
45 used. This default should be appropriate for most. */
46 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
47 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
50 /* This is used to hold the symbol built by a sequence of pseudo-ops
51 from .def and .endef. */
52 static symbolS
*def_symbol_in_progress
;
54 /* PE weak alternate symbols begin with this string. */
55 static const char weak_altprefix
[] = ".weak.";
58 #include "obj-coff-seh.c"
62 unsigned long chunk_size
;
63 unsigned long element_size
;
66 unsigned long pointer
;
74 stack_init (unsigned long chunk_size
,
75 unsigned long element_size
)
80 st
->data
= XNEWVEC (char, chunk_size
);
87 st
->size
= chunk_size
;
88 st
->chunk_size
= chunk_size
;
89 st
->element_size
= element_size
;
94 stack_push (stack
*st
, char *element
)
96 if (st
->pointer
+ st
->element_size
>= st
->size
)
98 st
->size
+= st
->chunk_size
;
99 st
->data
= XRESIZEVEC (char, st
->data
, st
->size
);
101 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
102 st
->pointer
+= st
->element_size
;
103 return st
->data
+ st
->pointer
;
107 stack_pop (stack
*st
)
109 if (st
->pointer
< st
->element_size
)
114 st
->pointer
-= st
->element_size
;
115 return st
->data
+ st
->pointer
;
118 /* Maintain a list of the tagnames of the structures. */
120 static htab_t tag_hash
;
125 tag_hash
= str_htab_create ();
129 tag_insert (const char *name
, symbolS
*symbolP
)
131 str_hash_insert (tag_hash
, name
, symbolP
, 1);
135 tag_find (char *name
)
137 return (symbolS
*) str_hash_find (tag_hash
, name
);
141 tag_find_or_make (char *name
)
145 if ((symbolP
= tag_find (name
)) == NULL
)
147 symbolP
= symbol_new (name
, undefined_section
, &zero_address_frag
, 0);
149 tag_insert (S_GET_NAME (symbolP
), symbolP
);
150 symbol_table_insert (symbolP
);
156 /* We accept the .bss directive to set the section for backward
157 compatibility with earlier versions of gas. */
160 obj_coff_bss (int ignore ATTRIBUTE_UNUSED
)
162 if (*input_line_pointer
== '\n')
163 subseg_new (".bss", get_absolute_expression ());
169 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
170 Parse a possible alignment value. */
173 obj_coff_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
177 if (*input_line_pointer
== ',')
179 align
= parse_align (0);
180 if (align
== (addressT
) -1)
184 S_SET_VALUE (symbolP
, size
);
185 S_SET_EXTERNAL (symbolP
);
186 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
188 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
190 /* There is no S_SET_ALIGN (symbolP, align) in COFF/PE.
191 Instead we must add a note to the .drectve section. */
194 segT current_seg
= now_seg
;
195 subsegT current_subseg
= now_subseg
;
198 size_t pfxlen
, numlen
;
202 sec
= subseg_new (".drectve", 0);
203 oldflags
= bfd_section_flags (sec
);
204 if (oldflags
== SEC_NO_FLAGS
)
206 if (!bfd_set_section_flags (sec
, TC_COFF_SECTION_DEFAULT_ATTRIBUTES
))
207 as_warn (_("error setting flags for \"%s\": %s"),
208 bfd_section_name (sec
),
209 bfd_errmsg (bfd_get_error ()));
212 /* Emit a string. Note no NUL-termination. */
213 pfxlen
= strlen (" -aligncomm:") + 2 + strlen (S_GET_NAME (symbolP
)) + 1;
214 numlen
= snprintf (numbuff
, sizeof (numbuff
), "%d", (int) align
);
215 frag
= frag_more (pfxlen
+ numlen
);
216 (void) sprintf (frag
, " -aligncomm:\"%s\",", S_GET_NAME (symbolP
));
217 memcpy (frag
+ pfxlen
, numbuff
, numlen
);
218 /* Restore original subseg. */
219 subseg_set (current_seg
, current_subseg
);
226 obj_coff_comm (int ignore ATTRIBUTE_UNUSED
)
228 s_comm_internal (ignore
, obj_coff_common_parse
);
234 fetch_coff_debug_section (void)
236 static segT debug_section
;
242 s
= bfd_make_debug_symbol (stdoutput
, NULL
, 0);
244 debug_section
= s
->section
;
246 return debug_section
;
250 SA_SET_SYM_ENDNDX (symbolS
*sym
, symbolS
*val
)
252 combined_entry_type
*entry
, *p
;
254 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
255 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
256 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
261 SA_SET_SYM_TAGNDX (symbolS
*sym
, symbolS
*val
)
263 combined_entry_type
*entry
, *p
;
265 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
266 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
267 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
272 S_GET_DATA_TYPE (symbolS
*sym
)
274 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
278 S_SET_DATA_TYPE (symbolS
*sym
, int val
)
280 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
285 S_GET_STORAGE_CLASS (symbolS
*sym
)
287 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
291 S_SET_STORAGE_CLASS (symbolS
*sym
, int val
)
293 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
297 /* Merge a debug symbol containing debug information into a normal symbol. */
300 c_symbol_merge (symbolS
*debug
, symbolS
*normal
)
302 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
303 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
305 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
306 /* Take the most we have. */
307 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
309 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
310 /* Move all the auxiliary information. */
311 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
312 (S_GET_NUMBER_AUXILIARY (debug
)
313 * sizeof (*SYM_AUXINFO (debug
))));
315 /* Move the debug flags. */
316 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
320 c_dot_file_symbol (const char *filename
, int appfile ATTRIBUTE_UNUSED
)
324 /* BFD converts filename to a .file symbol with an aux entry. It
325 also handles chaining. */
326 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, &zero_address_frag
, 0);
328 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
329 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
331 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
338 listing_source_file (filename
);
342 /* Make sure that the symbol is first on the symbol chain. */
343 if (symbol_rootP
!= symbolP
)
345 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
346 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
350 /* Line number handling. */
354 struct line_no
*next
;
361 /* Symbol of last function, which we should hang line#s off of. */
362 static symbolS
*line_fsym
;
364 #define in_function() (line_fsym != 0)
365 #define clear_function() (line_fsym = 0)
366 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
370 coff_obj_symbol_new_hook (symbolS
*symbolP
)
372 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
373 char * s
= XNEWVEC (char, sz
);
376 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
377 coffsymbol (symbol_get_bfdsym (symbolP
))->native
->is_sym
= TRUE
;
379 S_SET_DATA_TYPE (symbolP
, T_NULL
);
380 S_SET_STORAGE_CLASS (symbolP
, 0);
381 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
383 if (S_IS_STRING (symbolP
))
384 SF_SET_STRING (symbolP
);
386 if (S_IS_LOCAL (symbolP
))
387 SF_SET_LOCAL (symbolP
);
391 coff_obj_symbol_clone_hook (symbolS
*newsymP
, symbolS
*orgsymP
)
393 long elts
= OBJ_COFF_MAX_AUXENTRIES
+ 1;
394 combined_entry_type
* s
= XNEWVEC (combined_entry_type
, elts
);
396 memcpy (s
, coffsymbol (symbol_get_bfdsym (orgsymP
))->native
,
397 elts
* sizeof (combined_entry_type
));
398 coffsymbol (symbol_get_bfdsym (newsymP
))->native
= s
;
400 SF_SET (newsymP
, SF_GET (orgsymP
));
404 /* Handle .ln directives. */
406 static symbolS
*current_lineno_sym
;
407 static struct line_no
*line_nos
;
408 /* FIXME: Blindly assume all .ln directives will be in the .text section. */
412 add_lineno (fragS
* frag
, addressT offset
, int num
)
414 struct line_no
* new_line
= XNEW (struct line_no
);
416 if (!current_lineno_sym
)
420 /* The native aix assembler accepts negative line number. */
424 /* Zero is used as an end marker in the file. */
425 as_warn (_("Line numbers must be positive integers\n"));
428 #endif /* OBJ_XCOFF */
429 new_line
->next
= line_nos
;
430 new_line
->frag
= frag
;
431 new_line
->l
.line_number
= num
;
432 new_line
->l
.u
.offset
= offset
;
438 coff_add_linesym (symbolS
*sym
)
442 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
447 current_lineno_sym
= sym
;
451 obj_coff_ln (int appline
)
455 if (! appline
&& def_symbol_in_progress
!= NULL
)
457 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
458 demand_empty_rest_of_line ();
462 l
= get_absolute_expression ();
464 /* If there is no lineno symbol, treat a .ln
465 directive as if it were a .appline directive. */
466 if (appline
|| current_lineno_sym
== NULL
)
467 new_logical_line ((char *) NULL
, l
- 1);
469 add_lineno (frag_now
, frag_now_fix (), l
);
478 l
+= coff_line_base
- 1;
479 listing_source_line (l
);
484 demand_empty_rest_of_line ();
487 /* .loc is essentially the same as .ln; parse it for assembler
491 obj_coff_loc (int ignore ATTRIBUTE_UNUSED
)
495 /* FIXME: Why do we need this check? We need it for ECOFF, but why
496 do we need it for COFF? */
497 if (now_seg
!= text_section
)
499 as_warn (_(".loc outside of .text"));
500 demand_empty_rest_of_line ();
504 if (def_symbol_in_progress
!= NULL
)
506 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
507 demand_empty_rest_of_line ();
511 /* Skip the file number. */
513 get_absolute_expression ();
516 lineno
= get_absolute_expression ();
524 lineno
+= coff_line_base
- 1;
525 listing_source_line (lineno
);
530 demand_empty_rest_of_line ();
532 add_lineno (frag_now
, frag_now_fix (), lineno
);
535 /* Handle the .ident pseudo-op. */
538 obj_coff_ident (int ignore ATTRIBUTE_UNUSED
)
540 segT current_seg
= now_seg
;
541 subsegT current_subseg
= now_subseg
;
547 /* We could put it in .comment, but that creates an extra section
548 that shouldn't be loaded into memory, which requires linker
549 changes... For now, until proven otherwise, use .rdata. */
550 sec
= subseg_new (".rdata$zzz", 0);
551 bfd_set_section_flags (sec
,
552 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
553 & bfd_applicable_section_flags (stdoutput
)));
556 subseg_new (".comment", 0);
560 subseg_set (current_seg
, current_subseg
);
563 /* Handle .def directives.
565 One might ask : why can't we symbol_new if the symbol does not
566 already exist and fill it with debug information. Because of
567 the C_EFCN special symbol. It would clobber the value of the
568 function symbol before we have a chance to notice that it is
569 a C_EFCN. And a second reason is that the code is more clear this
570 way. (at least I think it is :-). */
572 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
573 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
574 *input_line_pointer == '\t') \
575 input_line_pointer++;
578 obj_coff_def (int what ATTRIBUTE_UNUSED
)
580 char name_end
; /* Char after the end of name. */
581 char *symbol_name
; /* Name of the debug symbol. */
582 char *symbol_name_copy
; /* Temporary copy of the name. */
584 if (def_symbol_in_progress
!= NULL
)
586 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
587 demand_empty_rest_of_line ();
593 name_end
= get_symbol_name (&symbol_name
);
594 symbol_name_copy
= xstrdup (symbol_name
);
595 #ifdef tc_canonicalize_symbol_name
596 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
599 /* Initialize the new symbol. */
600 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
601 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
602 S_SET_VALUE (def_symbol_in_progress
, 0);
604 if (S_IS_STRING (def_symbol_in_progress
))
605 SF_SET_STRING (def_symbol_in_progress
);
607 (void) restore_line_pointer (name_end
);
609 demand_empty_rest_of_line ();
613 obj_coff_endef (int ignore ATTRIBUTE_UNUSED
)
615 symbolS
*symbolP
= NULL
;
617 if (def_symbol_in_progress
== NULL
)
619 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
620 demand_empty_rest_of_line ();
624 /* Set the section number according to storage class. */
625 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
630 SF_SET_TAG (def_symbol_in_progress
);
634 SF_SET_DEBUG (def_symbol_in_progress
);
635 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
639 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
642 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing. */
648 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
650 name
= S_GET_NAME (def_symbol_in_progress
);
651 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
657 if (! in_function ())
658 as_warn (_("`%s' symbol without preceding function"), name
);
659 /* Will need relocating. */
660 SF_SET_PROCESS (def_symbol_in_progress
);
666 /* The MS compilers output the actual endline, not the
667 function-relative one... we want to match without
668 changing the assembler input. */
669 SA_SET_SYM_LNNO (def_symbol_in_progress
,
670 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
681 #endif /* C_AUTOARG */
688 /* According to the COFF documentation:
690 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
692 A special section number (-2) marks symbolic debugging symbols,
693 including structure/union/enumeration tag names, typedefs, and
694 the name of the file. A section number of -1 indicates that the
695 symbol has a value but is not relocatable. Examples of
696 absolute-valued symbols include automatic and register variables,
697 function arguments, and .eos symbols.
699 But from Ian Lance Taylor:
701 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
703 the actual tools all marked them as section -1. So the GNU COFF
704 assembler follows historical COFF assemblers.
706 However, it causes problems for djgpp
708 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
710 By defining STRICTCOFF, a COFF port can make the assembler to
711 follow the documented behavior. */
718 SF_SET_DEBUG (def_symbol_in_progress
);
719 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
727 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
738 /* Valid but set somewhere else (s_comm, s_lcomm, colon). */
745 as_warn (_("unexpected storage class %d"),
746 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
750 /* Now that we have built a debug symbol, try to find if we should
751 merge with an existing symbol or not. If a symbol is C_EFCN or
752 absolute_section or untagged SEG_DEBUG it never merges. We also
753 don't merge labels, which are in a different namespace, nor
754 symbols which have not yet been defined since they are typically
755 unique, nor do we merge tags with non-tags. */
757 /* Two cases for functions. Either debug followed by definition or
758 definition followed by debug. For definition first, we will
759 merge the debug symbol into the definition. For debug first, the
760 lineno entry MUST point to the definition function or else it
761 will point off into space when obj_crawl_symbol_chain() merges
762 the debug symbol into the real symbol. Therefor, let's presume
763 the debug symbol is a real function reference. */
765 /* FIXME-SOON If for some reason the definition label/symbol is
766 never seen, this will probably leave an undefined symbol at link
769 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
770 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
771 || (streq (bfd_section_name (S_GET_SEGMENT (def_symbol_in_progress
)),
773 && !SF_GET_TAG (def_symbol_in_progress
))
774 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
775 || ! symbol_constant_p (def_symbol_in_progress
)
776 || (symbolP
= symbol_find (S_GET_NAME (def_symbol_in_progress
))) == NULL
777 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
779 /* If it already is at the end of the symbol list, do nothing */
780 if (def_symbol_in_progress
!= symbol_lastP
)
782 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
783 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
789 /* This symbol already exists, merge the newly created symbol
790 into the old one. This is not mandatory. The linker can
791 handle duplicate symbols correctly. But I guess that it save
792 a *lot* of space if the assembly file defines a lot of
795 /* The debug entry (def_symbol_in_progress) is merged into the
796 previous definition. */
798 c_symbol_merge (def_symbol_in_progress
, symbolP
);
799 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
801 def_symbol_in_progress
= symbolP
;
803 if (SF_GET_FUNCTION (def_symbol_in_progress
)
804 || SF_GET_TAG (def_symbol_in_progress
)
805 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
807 /* For functions, and tags, and static symbols, the symbol
808 *must* be where the debug symbol appears. Move the
809 existing symbol to the current place. */
810 /* If it already is at the end of the symbol list, do nothing. */
811 if (def_symbol_in_progress
!= symbol_lastP
)
813 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
814 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
819 if (SF_GET_TAG (def_symbol_in_progress
))
823 oldtag
= symbol_find (S_GET_NAME (def_symbol_in_progress
));
824 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
825 tag_insert (S_GET_NAME (def_symbol_in_progress
),
826 def_symbol_in_progress
);
829 if (SF_GET_FUNCTION (def_symbol_in_progress
))
831 set_function (def_symbol_in_progress
);
832 SF_SET_PROCESS (def_symbol_in_progress
);
835 /* That is, if this is the first time we've seen the
837 symbol_table_insert (def_symbol_in_progress
);
841 def_symbol_in_progress
= NULL
;
842 demand_empty_rest_of_line ();
846 obj_coff_dim (int ignore ATTRIBUTE_UNUSED
)
850 if (def_symbol_in_progress
== NULL
)
852 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
853 demand_empty_rest_of_line ();
857 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
859 for (d_index
= 0; d_index
< DIMNUM
; d_index
++)
862 SA_SET_SYM_DIMEN (def_symbol_in_progress
, d_index
,
863 get_absolute_expression ());
865 switch (*input_line_pointer
)
868 input_line_pointer
++;
872 as_warn (_("badly formed .dim directive ignored"));
881 demand_empty_rest_of_line ();
885 obj_coff_line (int ignore ATTRIBUTE_UNUSED
)
889 if (def_symbol_in_progress
== NULL
)
891 /* Probably stabs-style line? */
896 this_base
= get_absolute_expression ();
897 if (streq (".bf", S_GET_NAME (def_symbol_in_progress
)))
898 coff_line_base
= this_base
;
900 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
901 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
903 demand_empty_rest_of_line ();
906 if (streq (".bf", S_GET_NAME (def_symbol_in_progress
)))
911 listing_source_line ((unsigned int) this_base
);
917 obj_coff_size (int ignore ATTRIBUTE_UNUSED
)
919 if (def_symbol_in_progress
== NULL
)
921 as_warn (_(".size pseudo-op used outside of .def/.endef: ignored."));
922 demand_empty_rest_of_line ();
926 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
927 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
928 demand_empty_rest_of_line ();
932 obj_coff_scl (int ignore ATTRIBUTE_UNUSED
)
934 if (def_symbol_in_progress
== NULL
)
936 as_warn (_(".scl pseudo-op used outside of .def/.endef: ignored."));
937 demand_empty_rest_of_line ();
941 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
942 demand_empty_rest_of_line ();
946 obj_coff_tag (int ignore ATTRIBUTE_UNUSED
)
951 if (def_symbol_in_progress
== NULL
)
953 as_warn (_(".tag pseudo-op used outside of .def/.endef: ignored."));
954 demand_empty_rest_of_line ();
958 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
959 name_end
= get_symbol_name (&symbol_name
);
961 #ifdef tc_canonicalize_symbol_name
962 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
965 /* Assume that the symbol referred to by .tag is always defined.
966 This was a bad assumption. I've added find_or_make. xoxorich. */
967 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
968 tag_find_or_make (symbol_name
));
969 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
970 as_warn (_("tag not found for .tag %s"), symbol_name
);
972 SF_SET_TAGGED (def_symbol_in_progress
);
974 (void) restore_line_pointer (name_end
);
975 demand_empty_rest_of_line ();
979 obj_coff_type (int ignore ATTRIBUTE_UNUSED
)
981 if (def_symbol_in_progress
== NULL
)
983 as_warn (_(".type pseudo-op used outside of .def/.endef: ignored."));
984 demand_empty_rest_of_line ();
988 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
990 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
991 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
992 SF_SET_FUNCTION (def_symbol_in_progress
);
994 demand_empty_rest_of_line ();
998 obj_coff_val (int ignore ATTRIBUTE_UNUSED
)
1000 if (def_symbol_in_progress
== NULL
)
1002 as_warn (_(".val pseudo-op used outside of .def/.endef: ignored."));
1003 demand_empty_rest_of_line ();
1007 if (is_name_beginner (*input_line_pointer
))
1010 char name_end
= get_symbol_name (&symbol_name
);
1012 #ifdef tc_canonicalize_symbol_name
1013 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1015 if (streq (symbol_name
, "."))
1017 /* If the .val is != from the .def (e.g. statics). */
1018 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1019 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1021 else if (! streq (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1025 exp
.X_op
= O_symbol
;
1026 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1027 exp
.X_op_symbol
= NULL
;
1028 exp
.X_add_number
= 0;
1029 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1031 /* If the segment is undefined when the forward reference is
1032 resolved, then copy the segment id from the forward
1034 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1036 /* FIXME: gcc can generate address expressions here in
1037 unusual cases (search for "obscure" in sdbout.c). We
1038 just ignore the offset here, thus generating incorrect
1039 debugging information. We ignore the rest of the line
1042 /* Otherwise, it is the name of a non debug symbol and its value
1043 will be calculated later. */
1044 (void) restore_line_pointer (name_end
);
1048 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1051 demand_empty_rest_of_line ();
1056 /* Return nonzero if name begins with weak alternate symbol prefix. */
1059 weak_is_altname (const char * name
)
1061 return strneq (name
, weak_altprefix
, sizeof (weak_altprefix
) - 1);
1064 /* Return the name of the alternate symbol
1065 name corresponding to a weak symbol's name. */
1068 weak_name2altname (const char * name
)
1070 return concat (weak_altprefix
, name
, (char *) NULL
);
1073 /* Return the name of the weak symbol corresponding to an
1074 alternate symbol. */
1077 weak_altname2name (const char * name
)
1079 gas_assert (weak_is_altname (name
));
1080 return xstrdup (name
+ 6);
1083 /* Make a weak symbol name unique by
1084 appending the name of an external symbol. */
1087 weak_uniquify (const char * name
)
1089 const char * unique
= "";
1092 if (an_external_name
!= NULL
)
1093 unique
= an_external_name
;
1095 gas_assert (weak_is_altname (name
));
1097 return concat (name
, ".", unique
, (char *) NULL
);
1101 pecoff_obj_set_weak_hook (symbolS
*symbolP
)
1103 symbolS
*alternateP
;
1105 /* See _Microsoft Portable Executable and Common Object
1106 File Format Specification_, section 5.5.3.
1107 Create a symbol representing the alternate value.
1108 coff_frob_symbol will set the value of this symbol from
1109 the value of the weak symbol itself. */
1110 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
1111 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1112 SA_SET_SYM_FSIZE (symbolP
, IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY
);
1114 alternateP
= symbol_find_or_make (weak_name2altname (S_GET_NAME (symbolP
)));
1115 S_SET_EXTERNAL (alternateP
);
1116 S_SET_STORAGE_CLASS (alternateP
, C_NT_WEAK
);
1118 SA_SET_SYM_TAGNDX (symbolP
, alternateP
);
1122 pecoff_obj_clear_weak_hook (symbolS
*symbolP
)
1124 symbolS
*alternateP
;
1126 S_SET_STORAGE_CLASS (symbolP
, 0);
1127 SA_SET_SYM_FSIZE (symbolP
, 0);
1129 alternateP
= symbol_find (weak_name2altname (S_GET_NAME (symbolP
)));
1130 S_CLEAR_EXTERNAL (alternateP
);
1135 /* Handle .weak. This is a GNU extension in formats other than PE. */
1138 obj_coff_weak (int ignore ATTRIBUTE_UNUSED
)
1146 c
= get_symbol_name (&name
);
1149 as_warn (_("badly formed .weak directive ignored"));
1150 ignore_rest_of_line ();
1154 symbolP
= symbol_find_or_make (name
);
1155 *input_line_pointer
= c
;
1156 SKIP_WHITESPACE_AFTER_NAME ();
1157 S_SET_WEAK (symbolP
);
1161 input_line_pointer
++;
1163 if (*input_line_pointer
== '\n')
1170 demand_empty_rest_of_line ();
1174 coff_obj_read_begin_hook (void)
1176 /* These had better be the same. Usually 18 bytes. */
1177 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1178 know (SYMESZ
== AUXESZ
);
1182 symbolS
*coff_last_function
;
1184 static symbolS
*coff_last_bf
;
1188 coff_frob_symbol (symbolS
*symp
, int *punt
)
1190 static symbolS
*last_tagP
;
1191 static stack
*block_stack
;
1192 static symbolS
*set_end
;
1193 symbolS
*next_set_end
= NULL
;
1195 if (symp
== &abs_symbol
)
1201 if (current_lineno_sym
)
1202 coff_add_linesym (NULL
);
1205 block_stack
= stack_init (512, sizeof (symbolS
*));
1208 if (S_GET_STORAGE_CLASS (symp
) == C_NT_WEAK
1209 && ! S_IS_WEAK (symp
)
1210 && weak_is_altname (S_GET_NAME (symp
)))
1212 /* This is a weak alternate symbol. All processing of
1213 PECOFFweak symbols is done here, through the alternate. */
1214 symbolS
*weakp
= symbol_find_noref (weak_altname2name
1215 (S_GET_NAME (symp
)), 1);
1218 gas_assert (S_GET_NUMBER_AUXILIARY (weakp
) == 1);
1220 if (! S_IS_WEAK (weakp
))
1222 /* The symbol was turned from weak to strong. Discard altname. */
1226 else if (symbol_equated_p (weakp
))
1228 /* The weak symbol has an alternate specified; symp is unneeded. */
1229 S_SET_STORAGE_CLASS (weakp
, C_NT_WEAK
);
1230 SA_SET_SYM_TAGNDX (weakp
,
1231 symbol_get_value_expression (weakp
)->X_add_symbol
);
1233 S_CLEAR_EXTERNAL (symp
);
1239 /* The weak symbol has been assigned an alternate value.
1240 Copy this value to symp, and set symp as weakp's alternate. */
1241 if (S_GET_STORAGE_CLASS (weakp
) != C_NT_WEAK
)
1243 S_SET_STORAGE_CLASS (symp
, S_GET_STORAGE_CLASS (weakp
));
1244 S_SET_STORAGE_CLASS (weakp
, C_NT_WEAK
);
1247 if (S_IS_DEFINED (weakp
))
1249 /* This is a defined weak symbol. Copy value information
1250 from the weak symbol itself to the alternate symbol. */
1251 symbol_set_value_expression (symp
,
1252 symbol_get_value_expression (weakp
));
1253 symbol_set_frag (symp
, symbol_get_frag (weakp
));
1254 S_SET_SEGMENT (symp
, S_GET_SEGMENT (weakp
));
1258 /* This is an undefined weak symbol.
1259 Define the alternate symbol to zero. */
1260 S_SET_VALUE (symp
, 0);
1261 S_SET_SEGMENT (symp
, absolute_section
);
1264 S_SET_NAME (symp
, weak_uniquify (S_GET_NAME (symp
)));
1265 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1267 S_SET_VALUE (weakp
, 0);
1268 S_SET_SEGMENT (weakp
, undefined_section
);
1272 if (S_IS_WEAK (symp
))
1273 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1276 if (!S_IS_DEFINED (symp
)
1277 && !S_IS_WEAK (symp
)
1278 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1279 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1281 if (!SF_GET_DEBUG (symp
))
1285 if (!SF_GET_LOCAL (symp
)
1286 && !SF_GET_STATICS (symp
)
1287 && S_GET_STORAGE_CLASS (symp
) != C_LABEL
1288 && symbol_constant_p (symp
)
1289 && (real
= symbol_find_noref (S_GET_NAME (symp
), 1))
1290 && S_GET_STORAGE_CLASS (real
) == C_NULL
1293 c_symbol_merge (symp
, real
);
1298 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1300 gas_assert (S_GET_VALUE (symp
) == 0);
1301 if (S_IS_WEAKREFD (symp
))
1304 S_SET_EXTERNAL (symp
);
1306 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1308 if (S_GET_SEGMENT (symp
) == text_section
1309 && symp
!= seg_info (text_section
)->sym
)
1310 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1312 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1315 if (SF_GET_PROCESS (symp
))
1317 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1319 if (streq (S_GET_NAME (symp
), ".bb"))
1320 stack_push (block_stack
, (char *) &symp
);
1325 begin
= *(symbolS
**) stack_pop (block_stack
);
1327 as_warn (_("mismatched .eb"));
1329 next_set_end
= begin
;
1333 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
)
1334 && S_IS_DEFINED (symp
))
1336 union internal_auxent
*auxp
;
1338 coff_last_function
= symp
;
1339 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1340 S_SET_NUMBER_AUXILIARY (symp
, 1);
1341 auxp
= SYM_AUXENT (symp
);
1342 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1343 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1346 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
1347 && S_IS_DEFINED (symp
))
1349 if (coff_last_function
== 0)
1350 as_fatal (_("C_EFCN symbol for %s out of scope"),
1352 SA_SET_SYM_FSIZE (coff_last_function
,
1353 (long) (S_GET_VALUE (symp
)
1354 - S_GET_VALUE (coff_last_function
)));
1355 next_set_end
= coff_last_function
;
1356 coff_last_function
= 0;
1360 if (S_IS_EXTERNAL (symp
))
1361 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1362 else if (SF_GET_LOCAL (symp
))
1365 if (SF_GET_FUNCTION (symp
))
1366 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1369 /* Double check weak symbols. */
1370 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1371 as_bad (_("Symbol `%s' can not be both weak and common"),
1374 if (SF_GET_TAG (symp
))
1376 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1377 next_set_end
= last_tagP
;
1380 /* This is pretty horrible, but we have to set *punt correctly in
1381 order to call SA_SET_SYM_ENDNDX correctly. */
1382 if (! symbol_used_in_reloc_p (symp
)
1383 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1384 || (! (S_IS_EXTERNAL (symp
) || S_IS_WEAK (symp
))
1385 && ! symbol_get_tc (symp
)->output
1386 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1390 if (set_end
!= (symbolS
*) NULL
1392 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1393 || (S_IS_DEFINED (symp
)
1394 && ! S_IS_COMMON (symp
)
1395 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1397 SA_SET_SYM_ENDNDX (set_end
, symp
);
1401 if (next_set_end
!= NULL
)
1403 if (set_end
!= NULL
)
1404 as_warn (_("Warning: internal error: forgetting to set endndx of %s"),
1405 S_GET_NAME (set_end
));
1406 set_end
= next_set_end
;
1411 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1412 && streq (S_GET_NAME (symp
), ".bf"))
1414 if (coff_last_bf
!= NULL
)
1415 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1416 coff_last_bf
= symp
;
1419 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1422 struct line_no
*lptr
;
1425 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1426 for (i
= 0; lptr
; lptr
= lptr
->next
)
1428 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1430 /* We need i entries for line numbers, plus 1 for the first
1431 entry which BFD will override, plus 1 for the last zero
1432 entry (a marker for BFD). */
1433 l
= XNEWVEC (alent
, (i
+ 2));
1434 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1435 l
[i
+ 1].line_number
= 0;
1436 l
[i
+ 1].u
.sym
= NULL
;
1440 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1448 coff_adjust_section_syms (bfd
*abfd ATTRIBUTE_UNUSED
,
1450 void * x ATTRIBUTE_UNUSED
)
1453 segment_info_type
*seginfo
= seg_info (sec
);
1454 int nlnno
, nrelocs
= 0;
1456 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1457 tc-ppc.c. Do not get confused by it. */
1458 if (seginfo
== NULL
)
1461 if (streq (sec
->name
, ".text"))
1462 nlnno
= coff_n_line_nos
;
1466 /* @@ Hope that none of the fixups expand to more than one reloc
1468 fixS
*fixp
= seginfo
->fix_root
;
1471 if (! fixp
->fx_done
)
1473 fixp
= fixp
->fx_next
;
1476 if (bfd_section_size (sec
) == 0
1479 && sec
!= text_section
1480 && sec
!= data_section
1481 && sec
!= bss_section
)
1484 secsym
= section_symbol (sec
);
1485 /* This is an estimate; we'll plug in the real value using
1486 SET_SECTION_RELOCS later */
1487 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1488 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1492 coff_frob_file_after_relocs (void)
1494 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, NULL
);
1497 /* Implement the .section pseudo op:
1498 .section name {, "flags"}
1500 | +--- optional flags: 'b' for bss
1502 +-- section name 'l' for lib
1506 'd' (apparently m88k for data)
1509 'r' for read-only data
1510 's' for shared data (PE)
1512 '0' - '9' for power-of-two alignment (GNU extension).
1513 But if the argument is not a quoted string, treat it as a
1516 Note the 'a' flag is silently ignored. This allows the same
1517 .section directive to be parsed in both ELF and COFF formats. */
1520 obj_coff_section (int ignore ATTRIBUTE_UNUSED
)
1522 /* Strip out the section name. */
1528 flagword flags
, oldflags
;
1530 bfd_boolean is_bss
= FALSE
;
1540 c
= get_symbol_name (§ion_name
);
1541 name
= xmemdup0 (section_name
, input_line_pointer
- section_name
);
1542 *input_line_pointer
= c
;
1543 SKIP_WHITESPACE_AFTER_NAME ();
1546 flags
= SEC_NO_FLAGS
;
1548 if (*input_line_pointer
== ',')
1550 ++input_line_pointer
;
1552 if (*input_line_pointer
!= '"')
1553 exp
= get_absolute_expression ();
1557 int readonly_removed
= 0;
1558 int load_removed
= 0;
1560 while (attr
= *++input_line_pointer
,
1562 && ! is_end_of_line
[attr
])
1566 alignment
= attr
- '0';
1572 /* Exclude section from linking. */
1573 flags
|= SEC_EXCLUDE
;
1577 /* Uninitialised data section. */
1584 /* Section not loaded. */
1586 flags
|= SEC_NEVER_LOAD
;
1591 /* Shared section. */
1592 flags
|= SEC_COFF_SHARED
;
1599 flags
&=~ SEC_READONLY
;
1603 /* Writable section. */
1604 flags
&=~ SEC_READONLY
;
1605 readonly_removed
= 1;
1609 /* Ignore. Here for compatibility with ELF. */
1612 case 'r': /* Read-only section. Implies a data section. */
1613 readonly_removed
= 0;
1615 case 'x': /* Executable section. */
1616 /* If we are setting the 'x' attribute or if the 'r'
1617 attribute is being used to restore the readonly status
1618 of a code section (eg "wxr") then set the SEC_CODE flag,
1619 otherwise set the SEC_DATA flag. */
1620 flags
|= (attr
== 'x' || (flags
& SEC_CODE
) ? SEC_CODE
: SEC_DATA
);
1623 /* Note - the READONLY flag is set here, even for the 'x'
1624 attribute in order to be compatible with the MSVC
1626 if (! readonly_removed
)
1627 flags
|= SEC_READONLY
;
1631 flags
|= SEC_COFF_NOREAD
| SEC_READONLY
;
1634 case 'i': /* STYP_INFO */
1635 case 'l': /* STYP_LIB */
1636 case 'o': /* STYP_OVER */
1637 as_warn (_("unsupported section attribute '%c'"), attr
);
1641 as_warn (_("unknown section attribute '%c'"), attr
);
1646 ++input_line_pointer
;
1650 sec
= subseg_new (name
, (subsegT
) exp
);
1653 seg_info (sec
)->bss
= 1;
1656 sec
->alignment_power
= alignment
;
1658 oldflags
= bfd_section_flags (sec
);
1659 if (oldflags
== SEC_NO_FLAGS
)
1661 /* Set section flags for a new section just created by subseg_new.
1662 Provide a default if no flags were parsed. */
1663 if (flags
== SEC_NO_FLAGS
)
1664 flags
= TC_COFF_SECTION_DEFAULT_ATTRIBUTES
;
1666 #ifdef COFF_LONG_SECTION_NAMES
1667 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1668 sections so adjust_reloc_syms in write.c will correctly handle
1669 relocs which refer to non-local symbols in these sections. */
1670 if (strneq (name
, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1))
1671 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1674 if (!bfd_set_section_flags (sec
, flags
))
1675 as_warn (_("error setting flags for \"%s\": %s"),
1676 bfd_section_name (sec
),
1677 bfd_errmsg (bfd_get_error ()));
1679 else if (flags
!= SEC_NO_FLAGS
)
1681 /* This section's attributes have already been set. Warn if the
1682 attributes don't match. */
1683 flagword matchflags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1684 | SEC_DATA
| SEC_COFF_SHARED
| SEC_NEVER_LOAD
1686 if ((flags
^ oldflags
) & matchflags
)
1687 as_warn (_("Ignoring changed section attributes for %s"), name
);
1690 demand_empty_rest_of_line ();
1694 coff_adjust_symtab (void)
1696 if (symbol_rootP
== NULL
1697 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1698 c_dot_file_symbol ("fake", 0);
1702 coff_frob_section (segT sec
)
1709 /* The COFF back end in BFD requires that all section sizes be
1710 rounded up to multiples of the corresponding section alignments,
1711 supposedly because standard COFF has no other way of encoding alignment
1712 for sections. If your COFF flavor has a different way of encoding
1713 section alignment, then skip this step, as TICOFF does. */
1714 bfd_vma size
= bfd_section_size (sec
);
1715 #if !defined(TICOFF)
1716 bfd_vma align_power
= (bfd_vma
) sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1717 bfd_vma mask
= ((bfd_vma
) 1 << align_power
) - 1;
1724 new_size
= (size
+ mask
) & ~mask
;
1725 bfd_set_section_size (sec
, new_size
);
1727 /* If the size had to be rounded up, add some padding in
1728 the last non-empty frag. */
1729 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1730 last
= seg_info (sec
)->frchainP
->frch_last
;
1731 while (fragp
->fr_next
!= last
)
1732 fragp
= fragp
->fr_next
;
1733 last
->fr_address
= size
;
1734 fragp
->fr_offset
+= new_size
- size
;
1738 /* If the section size is non-zero, the section symbol needs an aux
1739 entry associated with it, indicating the size. We don't know
1740 all the values yet; coff_frob_symbol will fill them in later. */
1743 || sec
== text_section
1744 || sec
== data_section
1745 || sec
== bss_section
)
1748 symbolS
*secsym
= section_symbol (sec
);
1749 unsigned char sclass
= C_STAT
;
1752 if (bfd_section_flags (sec
) & SEC_DEBUGGING
)
1755 S_SET_STORAGE_CLASS (secsym
, sclass
);
1756 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1757 SF_SET_STATICS (secsym
);
1758 SA_SET_SCN_SCNLEN (secsym
, size
);
1760 /* FIXME: These should be in a "stabs.h" file, or maybe as.h. */
1761 #ifndef STAB_SECTION_NAME
1762 #define STAB_SECTION_NAME ".stab"
1764 #ifndef STAB_STRING_SECTION_NAME
1765 #define STAB_STRING_SECTION_NAME ".stabstr"
1767 if (! streq (STAB_STRING_SECTION_NAME
, sec
->name
))
1771 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1772 /* size is already rounded up, since other section will be listed first */
1773 size
= bfd_section_size (strsec
);
1775 n_entries
= bfd_section_size (sec
) / 12 - 1;
1777 /* Find first non-empty frag. It should be large enough. */
1778 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1779 while (fragp
&& fragp
->fr_fix
== 0)
1780 fragp
= fragp
->fr_next
;
1781 gas_assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1783 /* Store the values. */
1784 p
= fragp
->fr_literal
;
1785 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1786 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1790 obj_coff_init_stab_section (segT seg
)
1795 unsigned int stroff
;
1797 /* Make space for this first symbol. */
1801 file
= as_where ((unsigned int *) NULL
);
1802 stabstr_name
= concat (seg
->name
, "str", (char *) NULL
);
1803 stroff
= get_stab_string_offset (file
, stabstr_name
, TRUE
);
1805 md_number_to_chars (p
, stroff
, 4);
1809 const char * s_get_name (symbolS
*);
1812 s_get_name (symbolS
*s
)
1814 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1817 void symbol_dump (void);
1824 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1825 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1826 (unsigned long) symbolP
,
1827 S_GET_NAME (symbolP
),
1828 (long) S_GET_DATA_TYPE (symbolP
),
1829 S_GET_STORAGE_CLASS (symbolP
),
1830 (int) S_GET_SEGMENT (symbolP
));
1835 const pseudo_typeS coff_pseudo_table
[] =
1837 {"ABORT", s_abort
, 0},
1838 {"appline", obj_coff_ln
, 1},
1839 /* We accept the .bss directive for backward compatibility with
1840 earlier versions of gas. */
1841 {"bss", obj_coff_bss
, 0},
1843 /* PE provides an enhanced version of .comm with alignment. */
1844 {"comm", obj_coff_comm
, 0},
1846 {"def", obj_coff_def
, 0},
1847 {"dim", obj_coff_dim
, 0},
1848 {"endef", obj_coff_endef
, 0},
1849 {"ident", obj_coff_ident
, 0},
1850 {"line", obj_coff_line
, 0},
1851 {"ln", obj_coff_ln
, 0},
1852 {"scl", obj_coff_scl
, 0},
1853 {"sect", obj_coff_section
, 0},
1854 {"sect.s", obj_coff_section
, 0},
1855 {"section", obj_coff_section
, 0},
1856 {"section.s", obj_coff_section
, 0},
1857 /* FIXME: We ignore the MRI short attribute. */
1858 {"size", obj_coff_size
, 0},
1859 {"tag", obj_coff_tag
, 0},
1860 {"type", obj_coff_type
, 0},
1861 {"val", obj_coff_val
, 0},
1862 {"version", s_ignore
, 0},
1863 {"loc", obj_coff_loc
, 0},
1864 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
1865 {"weak", obj_coff_weak
, 0},
1866 #if defined TC_TIC4X
1867 /* The tic4x uses sdef instead of def. */
1868 {"sdef", obj_coff_def
, 0},
1870 #if defined(SEH_CMDS)
1877 /* Support for a COFF emulation. */
1880 coff_pop_insert (void)
1882 pop_insert (coff_pseudo_table
);
1886 coff_separate_stab_sections (void)
1891 const struct format_ops coff_format_ops
=
1893 bfd_target_coff_flavour
,
1894 0, /* dfl_leading_underscore */
1895 1, /* emit_section_symbols */
1900 0, /* frob_file_before_adjust */
1901 0, /* frob_file_before_fix */
1902 coff_frob_file_after_relocs
,
1905 0, /* s_get_align */
1906 0, /* s_set_align */
1907 0, /* s_get_other */
1908 0, /* s_set_other */
1913 0, /* copy_symbol_attributes */
1914 0, /* generate_asm_lineno */
1915 0, /* process_stab */
1916 coff_separate_stab_sections
,
1917 obj_coff_init_stab_section
,
1918 0, /* sec_sym_ok_for_reloc */
1920 0, /* ecoff_set_ext */
1921 coff_obj_read_begin_hook
,
1922 coff_obj_symbol_new_hook
,
1923 coff_obj_symbol_clone_hook
,