1 /* coff object file format with bfd
2 Copyright (C) 1989, 1990, 1991, 1993 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 2, 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
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 How does this releate to the rest of GAS ?
24 Well, all the other files in gas are more or less a black box. It
25 takes care of opening files, parsing command lines, stripping blanks
26 etc etc. This module gets a chance to register what it wants to do by
27 saying that it is interested in various pseduo ops. The other big
28 change is write_object_file. This runs through all the data
29 structures that gas builds, and outputs the file in the format of our
32 Hacked for BFDness by steve chamberlain
34 This object module now supports everything but the i960 and i860.
43 /* This is needed because we include internal bfd things. */
45 #include "../bfd/libbfd.h"
46 #include "../bfd/libcoff.h"
48 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
49 that we can stick sections together without causing trouble. */
51 #define NOP_OPCODE 0x00
54 #define MIN(a,b) ((a) < (b)? (a) : (b))
55 /* This vector is used to turn an internal segment into a section #
56 suitable for insertion into a coff symbol table
59 const short seg_N_TYPE
[] =
60 { /* in: segT out: N_TYPE bits */
72 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
73 C_UNDEF_SECTION
, /* SEG_GOOF */
74 C_UNDEF_SECTION
, /* SEG_EXPR */
75 C_DEBUG_SECTION
, /* SEG_DEBUG */
76 C_NTV_SECTION
, /* SEG_NTV */
77 C_PTV_SECTION
, /* SEG_PTV */
78 C_REGISTER_SECTION
, /* SEG_REGISTER */
81 int function_lineoff
= -1; /* Offset in line#s where the last function
82 started (the odd entry for line #0) */
84 static symbolS
*last_line_symbol
;
86 /* Add 4 to the real value to get the index and compensate the
87 negatives. This vector is used by S_GET_SEGMENT to turn a coff
88 section number into a segment number
90 static symbolS
*previous_file_symbol
= NULL
;
91 void c_symbol_merge ();
94 symbolS
*c_section_symbol ();
97 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
98 segT this_segment_type
));
101 static void fixup_mdeps
PARAMS ((fragS
*,
106 static void fill_section
PARAMS ((bfd
* abfd
,
111 char *s_get_name
PARAMS ((symbolS
* s
));
112 static symbolS
*tag_find_or_make
PARAMS ((char *name
));
113 static symbolS
*tag_find
PARAMS ((char *name
));
116 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
117 unsigned short line_number
,
121 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
122 symbolS
* symbol_rootP
));
124 static char *stack_pop
PARAMS ((stack
* st
));
125 static char *stack_push
PARAMS ((stack
* st
, char *element
));
127 static char *stack_top
PARAMS ((stack
* st
));
129 static stack
*stack_init
PARAMS ((unsigned long chunk_size
,
130 unsigned long element_size
));
133 static void tag_init
PARAMS ((void));
134 static void tag_insert
PARAMS ((char *name
, symbolS
* symbolP
));
135 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
137 static struct hash_control
*tag_hash
;
139 static symbolS
*def_symbol_in_progress
= NULL
;
141 static void obj_coff_def
PARAMS ((int));
142 static void obj_coff_lcomm
PARAMS ((int));
143 static void obj_coff_dim
PARAMS ((int));
144 static void obj_coff_text
PARAMS ((int));
145 static void obj_coff_data
PARAMS ((int));
146 static void obj_coff_bss
PARAMS ((int));
147 static void obj_coff_ident
PARAMS ((int));
148 static void obj_coff_endef
PARAMS ((int));
149 static void obj_coff_line
PARAMS ((int));
150 static void obj_coff_ln
PARAMS ((int));
151 static void obj_coff_scl
PARAMS ((int));
152 static void obj_coff_size
PARAMS ((int));
153 static void obj_coff_tag
PARAMS ((int));
154 static void obj_coff_type
PARAMS ((int));
155 static void obj_coff_val
PARAMS ((int));
156 void obj_coff_section
PARAMS ((int));
158 const pseudo_typeS obj_pseudo_table
[] =
160 {"def", obj_coff_def
, 0},
161 {"dim", obj_coff_dim
, 0},
162 {"endef", obj_coff_endef
, 0},
163 {"line", obj_coff_line
, 0},
164 {"ln", obj_coff_ln
, 0},
165 {"appline", obj_coff_ln
, 1},
166 {"scl", obj_coff_scl
, 0},
167 {"size", obj_coff_size
, 0},
168 {"tag", obj_coff_tag
, 0},
169 {"type", obj_coff_type
, 0},
170 {"val", obj_coff_val
, 0},
171 {"section", obj_coff_section
, 0},
172 {"use", obj_coff_section
, 0},
173 {"sect", obj_coff_section
, 0},
174 {"text", obj_coff_text
, 0},
175 {"data", obj_coff_data
, 0},
176 {"bss", obj_coff_bss
, 0},
177 {"ident", obj_coff_ident
, 0},
178 {"ABORT", s_abort
, 0},
179 {"lcomm", obj_coff_lcomm
, 0},
181 /* The m88k uses sdef instead of def. */
182 {"sdef", obj_coff_def
, 0},
184 {NULL
} /* end sentinel */
185 }; /* obj_pseudo_table */
191 We allow more than just the standard 3 sections, infact, we allow
192 10 sections, (though the usual three have to be there).
194 This structure performs the mappings for us:
199 static struct internal_scnhdr bss_section_header;
200 struct internal_scnhdr data_section_header;
201 struct internal_scnhdr text_section_header;
203 const segT N_TYPE_seg [32] =
217 seg_info_type seg_info_off_by_4
[N_SEG
] =
248 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
249 #define SEG_INFO_FROM_SEG_NUMBER(x) (seg_info_off_by_4[(x)])
252 static relax_addressT
253 DEFUN (relax_align
, (address
, alignment
),
254 register relax_addressT address AND
255 register long alignment
)
258 relax_addressT new_address
;
260 mask
= ~((~0) << alignment
);
261 new_address
= (address
+ mask
) & (~mask
);
262 return (new_address
- address
);
263 } /* relax_align() */
267 DEFUN (s_get_segment
, (x
),
270 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
275 /* calculate the size of the frag chain and fill in the section header
276 to contain all of it, also fill in the addr of the sections */
278 DEFUN (size_section
, (abfd
, idx
),
283 unsigned int size
= 0;
284 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
287 size
= frag
->fr_address
;
288 if (frag
->fr_address
!= size
)
290 printf ("Out of step\n");
291 size
= frag
->fr_address
;
294 switch (frag
->fr_type
)
296 #ifdef TC_COFF_SIZEMACHDEP
297 case rs_machine_dependent
:
298 size
+= TC_COFF_SIZEMACHDEP (frag
);
303 size
+= frag
->fr_fix
;
304 size
+= frag
->fr_offset
* frag
->fr_var
;
307 size
+= frag
->fr_fix
;
308 size
+= relax_align (size
, frag
->fr_offset
);
311 BAD_CASE (frag
->fr_type
);
314 frag
= frag
->fr_next
;
316 segment_info
[idx
].scnhdr
.s_size
= size
;
322 DEFUN (count_entries_in_chain
, (idx
),
325 unsigned int nrelocs
;
328 /* Count the relocations */
329 fixup_ptr
= segment_info
[idx
].fix_root
;
331 while (fixup_ptr
!= (fixS
*) NULL
)
333 if (TC_COUNT_RELOC (fixup_ptr
))
336 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
345 fixup_ptr
= fixup_ptr
->fx_next
;
350 /* output all the relocations for a section */
352 DEFUN (do_relocs_for
, (abfd
, h
, file_cursor
),
354 object_headers
* h AND
355 unsigned long *file_cursor
)
357 unsigned int nrelocs
;
359 unsigned long reloc_start
= *file_cursor
;
361 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
363 if (segment_info
[idx
].scnhdr
.s_name
[0])
365 struct external_reloc
*ext_ptr
;
366 struct external_reloc
*external_reloc_vec
;
367 unsigned int external_reloc_size
;
368 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
369 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
370 nrelocs
= count_entries_in_chain (idx
);
373 /* Bypass this stuff if no relocs. This also incidentally
374 avoids a SCO bug, where free(malloc(0)) tends to crash. */
376 external_reloc_size
= nrelocs
* RELSZ
;
378 (struct external_reloc
*) malloc (external_reloc_size
);
380 ext_ptr
= external_reloc_vec
;
382 /* Fill in the internal coff style reloc struct from the
383 internal fix list. */
387 struct internal_reloc intr
;
389 /* Only output some of the relocations */
390 if (TC_COUNT_RELOC (fix_ptr
))
392 #ifdef TC_RELOC_MANGLE
393 TC_RELOC_MANGLE (fix_ptr
, &intr
, base
);
397 symbol_ptr
= fix_ptr
->fx_addsy
;
399 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
401 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
404 intr
.r_offset
= fix_ptr
->fx_offset
;
409 /* Turn the segment of the symbol into an offset. */
412 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
415 intr
.r_symndx
= dot
->sy_number
;
419 intr
.r_symndx
= symbol_ptr
->sy_number
;
429 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
434 /* The 29k has a special kludge for the high 16 bit
435 reloc. Two relocations are emited, R_IHIHALF,
436 and R_IHCONST. The second one doesn't contain a
437 symbol, but uses the value for offset. */
439 if (intr
.r_type
== R_IHIHALF
)
441 /* now emit the second bit */
442 intr
.r_type
= R_IHCONST
;
443 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
444 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
450 fix_ptr
= fix_ptr
->fx_next
;
453 /* Write out the reloc table */
454 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
456 free (external_reloc_vec
);
458 /* Fill in section header info. */
459 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
460 *file_cursor
+= external_reloc_size
;
461 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
466 segment_info
[idx
].scnhdr
.s_relptr
= 0;
470 /* Set relocation_size field in file headers */
471 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
475 /* run through a frag chain and write out the data to go with it, fill
476 in the scnhdrs with the info on the file postions
479 DEFUN (fill_section
, (abfd
, h
, file_cursor
),
481 object_headers
*h AND
482 unsigned long *file_cursor
)
486 unsigned int paddr
= 0;
488 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
490 unsigned int offset
= 0;
492 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
496 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
503 buffer
= xmalloc (s
->s_size
);
504 s
->s_scnptr
= *file_cursor
;
506 know (s
->s_paddr
== paddr
);
508 if (strcmp (s
->s_name
, ".text") == 0)
509 s
->s_flags
|= STYP_TEXT
;
510 else if (strcmp (s
->s_name
, ".data") == 0)
511 s
->s_flags
|= STYP_DATA
;
512 else if (strcmp (s
->s_name
, ".bss") == 0)
515 s
->s_flags
|= STYP_BSS
;
518 /* Apparently the SVR3 linker is confused by noload
519 sections. So is the UDI mondfe program. */
520 s
->s_flags
|= STYP_NOLOAD
;
524 else if (strcmp (s
->s_name
, ".lit") == 0)
525 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
526 else if (strcmp (s
->s_name
, ".init") == 0)
527 s
->s_flags
|= STYP_TEXT
;
528 else if (strcmp (s
->s_name
, ".fini") == 0)
529 s
->s_flags
|= STYP_TEXT
;
530 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
531 s
->s_flags
|= STYP_INFO
;
535 unsigned int fill_size
;
536 switch (frag
->fr_type
)
538 case rs_machine_dependent
:
541 memcpy (buffer
+ frag
->fr_address
,
543 (unsigned int) frag
->fr_fix
);
544 offset
+= frag
->fr_fix
;
553 memcpy (buffer
+ frag
->fr_address
,
555 (unsigned int) frag
->fr_fix
);
556 offset
+= frag
->fr_fix
;
559 fill_size
= frag
->fr_var
;
560 if (fill_size
&& frag
->fr_offset
> 0)
563 unsigned int off
= frag
->fr_fix
;
564 for (count
= frag
->fr_offset
; count
; count
--)
566 if (fill_size
+ frag
->fr_address
+ off
< s
->s_size
)
568 memcpy (buffer
+ frag
->fr_address
+ off
,
569 frag
->fr_literal
+ frag
->fr_fix
,
582 frag
= frag
->fr_next
;
587 if (s
->s_scnptr
!= 0)
589 bfd_write (buffer
, s
->s_size
, 1, abfd
);
590 *file_cursor
+= s
->s_size
;
599 /* Coff file generation & utilities */
602 DEFUN (coff_header_append
, (abfd
, h
),
610 bfd_seek (abfd
, 0, 0);
612 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
613 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
614 H_SET_VERSION_STAMP (h
, 0);
615 H_SET_ENTRY_POINT (h
, 0);
616 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
617 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
618 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
620 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
621 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
622 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
624 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
626 bfd_write (buffer
, i
, 1, abfd
);
627 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
629 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
631 if (segment_info
[i
].scnhdr
.s_name
[0])
634 bfd_coff_swap_scnhdr_out (abfd
,
635 &(segment_info
[i
].scnhdr
),
637 bfd_write (buffer
, size
, 1, abfd
);
644 DEFUN (symbol_to_chars
, (abfd
, where
, symbolP
),
649 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
653 /* Turn any symbols with register attributes into abs symbols */
654 if (S_GET_SEGMENT (symbolP
) == SEG_REGISTER
)
656 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
658 /* At the same time, relocate all symbols to their output value */
660 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
661 + S_GET_VALUE (symbolP
));
663 S_SET_VALUE (symbolP
, val
);
665 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
667 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
670 for (i
= 0; i
< numaux
; i
++)
672 where
+= bfd_coff_swap_aux_out (abfd
,
673 &symbolP
->sy_symbol
.ost_auxent
[i
],
674 S_GET_DATA_TYPE (symbolP
),
675 S_GET_STORAGE_CLASS (symbolP
),
684 obj_symbol_new_hook (symbolP
)
687 char underscore
= 0; /* Symbol has leading _ */
689 /* Effective symbol */
690 /* Store the pointer in the offset. */
691 S_SET_ZEROES (symbolP
, 0L);
692 S_SET_DATA_TYPE (symbolP
, T_NULL
);
693 S_SET_STORAGE_CLASS (symbolP
, 0);
694 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
695 /* Additional information */
696 symbolP
->sy_symbol
.ost_flags
= 0;
697 /* Auxiliary entries */
698 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
700 #ifdef STRIP_UNDERSCORE
701 /* Remove leading underscore at the beginning of the symbol.
702 * This is to be compatible with the standard librairies.
704 if (*S_GET_NAME (symbolP
) == '_')
707 S_SET_NAME (symbolP
, S_GET_NAME (symbolP
) + 1);
708 } /* strip underscore */
709 #endif /* STRIP_UNDERSCORE */
711 if (S_IS_STRING (symbolP
))
712 SF_SET_STRING (symbolP
);
713 if (!underscore
&& S_IS_LOCAL (symbolP
))
714 SF_SET_LOCAL (symbolP
);
719 stack_init (chunk_size
, element_size
)
720 unsigned long chunk_size
;
721 unsigned long element_size
;
725 if ((st
= (stack
*) malloc (sizeof (stack
))) == (stack
*) 0)
727 if ((st
->data
= malloc (chunk_size
)) == (char *) 0)
733 st
->size
= chunk_size
;
734 st
->chunk_size
= chunk_size
;
735 st
->element_size
= element_size
;
748 stack_push (st
, element
)
752 if (st
->pointer
+ st
->element_size
>= st
->size
)
754 st
->size
+= st
->chunk_size
;
755 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
758 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
759 st
->pointer
+= st
->element_size
;
760 return st
->data
+ st
->pointer
;
767 if (st
->pointer
< st
->element_size
)
772 st
->pointer
-= st
->element_size
;
773 return st
->data
+ st
->pointer
;
782 return st
->data
+ st
->pointer
- st
->element_size
;
787 * Handle .ln directives.
791 obj_coff_ln (appline
)
796 if (! appline
&& def_symbol_in_progress
!= NULL
)
798 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
799 demand_empty_rest_of_line ();
801 } /* wrong context */
804 obstack_next_free (&frags
) - frag_now
->fr_literal
,
805 l
= get_absolute_expression (),
815 listing_source_line ((unsigned int) l
);
820 demand_empty_rest_of_line ();
826 * Handle .def directives.
828 * One might ask : why can't we symbol_new if the symbol does not
829 * already exist and fill it with debug information. Because of
830 * the C_EFCN special symbol. It would clobber the value of the
831 * function symbol before we have a chance to notice that it is
832 * a C_EFCN. And a second reason is that the code is more clear this
833 * way. (at least I think it is :-).
837 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
838 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
839 *input_line_pointer == '\t') \
840 input_line_pointer++;
843 DEFUN (obj_coff_def
, (what
),
846 char name_end
; /* Char after the end of name */
847 char *symbol_name
; /* Name of the debug symbol */
848 char *symbol_name_copy
; /* Temporary copy of the name */
849 unsigned int symbol_name_length
;
850 /*$char* directiveP;$ *//* Name of the pseudo opcode */
851 /*$char directive[MAX_DIRECTIVE];$ *//* Backup of the directive */
852 /*$char end = 0;$ *//* If 1, stop parsing */
854 if (def_symbol_in_progress
!= NULL
)
856 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
857 demand_empty_rest_of_line ();
859 } /* if not inside .def/.endef */
863 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
864 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
866 symbol_name
= input_line_pointer
;
867 name_end
= get_symbol_end ();
868 symbol_name_length
= strlen (symbol_name
);
869 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
870 strcpy (symbol_name_copy
, symbol_name
);
872 /* Initialize the new symbol */
873 #ifdef STRIP_UNDERSCORE
874 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
875 ? symbol_name_copy
+ 1
876 : symbol_name_copy
));
877 #else /* STRIP_UNDERSCORE */
878 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
879 #endif /* STRIP_UNDERSCORE */
880 /* free(symbol_name_copy); */
881 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
882 def_symbol_in_progress
->sy_number
= ~0;
883 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
884 S_SET_VALUE (def_symbol_in_progress
, 0);
886 if (S_IS_STRING (def_symbol_in_progress
))
888 SF_SET_STRING (def_symbol_in_progress
);
891 *input_line_pointer
= name_end
;
893 demand_empty_rest_of_line ();
896 unsigned int dim_index
;
900 obj_coff_endef (ignore
)
903 symbolS
*symbolP
= 0;
904 /* DIM BUG FIX sac@cygnus.com */
906 if (def_symbol_in_progress
== NULL
)
908 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
909 demand_empty_rest_of_line ();
911 } /* if not inside .def/.endef */
913 /* Set the section number according to storage class. */
914 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
919 SF_SET_TAG (def_symbol_in_progress
);
920 /* intentional fallthrough */
923 SF_SET_DEBUG (def_symbol_in_progress
);
924 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
928 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
929 /* intentional fallthrough */
931 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
932 /* intentional fallthrough */
934 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
936 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
938 if (function_lineoff
< 0)
940 fprintf (stderr
, "`.bf' symbol without preceding function\n");
941 } /* missing function symbol */
942 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
944 SF_SET_PROCESS (last_line_symbol
);
945 function_lineoff
= -1;
947 /* Value is always set to . */
948 def_symbol_in_progress
->sy_frag
= frag_now
;
949 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
954 #endif /* C_AUTOARG */
964 SF_SET_DEBUG (def_symbol_in_progress
);
965 S_SET_SEGMENT (def_symbol_in_progress
, SEG_ABSOLUTE
);
971 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
977 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
979 } /* switch on storage class */
981 /* Now that we have built a debug symbol, try to find if we should
982 merge with an existing symbol or not. If a symbol is C_EFCN or
983 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. We also
984 don't merge labels, which are in a different namespace, nor
985 symbols which have not yet been defined since they are typically
986 unique, nor do we merge tags with non-tags. */
988 /* Two cases for functions. Either debug followed by definition or
989 definition followed by debug. For definition first, we will
990 merge the debug symbol into the definition. For debug first, the
991 lineno entry MUST point to the definition function or else it
992 will point off into space when crawl_symbols() merges the debug
993 symbol into the real symbol. Therefor, let's presume the debug
994 symbol is a real function reference. */
996 /* FIXME-SOON If for some reason the definition label/symbol is
997 never seen, this will probably leave an undefined symbol at link
1000 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
1001 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
1002 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
1003 && !SF_GET_TAG (def_symbol_in_progress
))
1004 || S_GET_SEGMENT (def_symbol_in_progress
) == SEG_ABSOLUTE
1005 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
1006 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
1007 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
1009 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
1014 /* This symbol already exists, merge the newly created symbol
1015 into the This is not mandatory. The linker can handle
1016 duplicate symbols correctly. But I guess that it save a *lot*
1017 of space if the assembly file defines a lot of
1020 /* The debug entry (def_symbol_in_progress) is merged into the
1021 previous definition. */
1023 c_symbol_merge (def_symbol_in_progress
, symbolP
);
1024 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
1025 def_symbol_in_progress
= symbolP
;
1027 if (SF_GET_FUNCTION (def_symbol_in_progress
)
1028 || SF_GET_TAG (def_symbol_in_progress
))
1030 /* For functions, and tags, the symbol *must* be where the
1031 debug symbol appears. Move the existing symbol to the
1033 /* If it already is at the end of the symbol list, do nothing */
1034 if (def_symbol_in_progress
!= symbol_lastP
)
1036 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
1038 symbol_append (def_symbol_in_progress
, symbol_lastP
,
1039 &symbol_rootP
, &symbol_lastP
);
1040 } /* if not already in place */
1042 } /* normal or mergable */
1044 if (SF_GET_TAG (def_symbol_in_progress
)
1045 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
1047 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
1050 if (SF_GET_FUNCTION (def_symbol_in_progress
))
1052 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
1054 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
1056 SF_SET_PROCESS (def_symbol_in_progress
);
1058 if (symbolP
== NULL
)
1060 /* That is, if this is the first time we've seen the
1062 symbol_table_insert (def_symbol_in_progress
);
1063 } /* definition follows debug */
1064 } /* Create the line number entry pointing to the function being defined */
1066 def_symbol_in_progress
= NULL
;
1067 demand_empty_rest_of_line ();
1071 obj_coff_dim (ignore
)
1074 register int dim_index
;
1076 if (def_symbol_in_progress
== NULL
)
1078 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
1079 demand_empty_rest_of_line ();
1081 } /* if not inside .def/.endef */
1083 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1085 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
1087 SKIP_WHITESPACES ();
1088 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
, get_absolute_expression ());
1090 switch (*input_line_pointer
)
1094 input_line_pointer
++;
1098 as_warn ("badly formed .dim directive ignored");
1099 /* intentional fallthrough */
1104 } /* switch on following character */
1105 } /* for each dimension */
1107 demand_empty_rest_of_line ();
1111 obj_coff_line (ignore
)
1116 if (def_symbol_in_progress
== NULL
)
1120 } /* if it looks like a stabs style line */
1122 this_base
= get_absolute_expression ();
1123 if (this_base
> line_base
)
1125 line_base
= this_base
;
1134 listing_source_line ((unsigned int) line_base
);
1138 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1139 SA_SET_SYM_LNNO (def_symbol_in_progress
, line_base
);
1141 demand_empty_rest_of_line ();
1145 obj_coff_size (ignore
)
1148 if (def_symbol_in_progress
== NULL
)
1150 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
1151 demand_empty_rest_of_line ();
1153 } /* if not inside .def/.endef */
1155 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1156 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
1157 demand_empty_rest_of_line ();
1161 obj_coff_scl (ignore
)
1164 if (def_symbol_in_progress
== NULL
)
1166 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
1167 demand_empty_rest_of_line ();
1169 } /* if not inside .def/.endef */
1171 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
1172 demand_empty_rest_of_line ();
1176 obj_coff_tag (ignore
)
1182 if (def_symbol_in_progress
== NULL
)
1184 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
1185 demand_empty_rest_of_line ();
1187 } /* if not inside .def/.endef */
1189 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1190 symbol_name
= input_line_pointer
;
1191 name_end
= get_symbol_end ();
1193 /* Assume that the symbol referred to by .tag is always defined. */
1194 /* This was a bad assumption. I've added find_or_make. xoxorich. */
1195 SA_SET_SYM_TAGNDX (def_symbol_in_progress
, (long) tag_find_or_make (symbol_name
));
1196 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1198 as_warn ("tag not found for .tag %s", symbol_name
);
1201 SF_SET_TAGGED (def_symbol_in_progress
);
1202 *input_line_pointer
= name_end
;
1204 demand_empty_rest_of_line ();
1208 obj_coff_type (ignore
)
1211 if (def_symbol_in_progress
== NULL
)
1213 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
1214 demand_empty_rest_of_line ();
1216 } /* if not inside .def/.endef */
1218 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1220 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1221 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1223 SF_SET_FUNCTION (def_symbol_in_progress
);
1224 } /* is a function */
1226 demand_empty_rest_of_line ();
1230 obj_coff_val (ignore
)
1233 if (def_symbol_in_progress
== NULL
)
1235 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
1236 demand_empty_rest_of_line ();
1238 } /* if not inside .def/.endef */
1240 if (is_name_beginner (*input_line_pointer
))
1242 char *symbol_name
= input_line_pointer
;
1243 char name_end
= get_symbol_end ();
1245 if (!strcmp (symbol_name
, "."))
1247 def_symbol_in_progress
->sy_frag
= frag_now
;
1248 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1249 /* If the .val is != from the .def (e.g. statics) */
1251 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1253 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
1254 def_symbol_in_progress
->sy_value
.X_add_symbol
=
1255 symbol_find_or_make (symbol_name
);
1256 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
1257 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
1259 /* If the segment is undefined when the forward reference is
1260 resolved, then copy the segment id from the forward
1262 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1264 /* FIXME: gcc can generate address expressions
1265 here in unusual cases (search for "obscure"
1266 in sdbout.c). We just ignore the offset
1267 here, thus generating incorrect debugging
1268 information. We ignore the rest of the
1271 /* Otherwise, it is the name of a non debug symbol and
1272 its value will be calculated later. */
1273 *input_line_pointer
= name_end
;
1275 /* FIXME: this is to avoid an error message in the
1276 FIXME case mentioned just above. */
1277 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1278 ++input_line_pointer
;
1282 S_SET_VALUE (def_symbol_in_progress
,
1283 (valueT
) get_absolute_expression ());
1284 } /* if symbol based */
1286 demand_empty_rest_of_line ();
1290 * Maintain a list of the tagnames of the structres.
1296 tag_hash
= hash_new ();
1300 tag_insert (name
, symbolP
)
1304 register const char *error_string
;
1306 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
1308 as_fatal ("Inserting \"%s\" into structure table failed: %s",
1309 name
, error_string
);
1314 tag_find_or_make (name
)
1319 if ((symbolP
= tag_find (name
)) == NULL
)
1321 symbolP
= symbol_new (name
,
1324 &zero_address_frag
);
1326 tag_insert (S_GET_NAME (symbolP
), symbolP
);
1330 } /* tag_find_or_make() */
1336 #ifdef STRIP_UNDERSCORE
1339 #endif /* STRIP_UNDERSCORE */
1340 return ((symbolS
*) hash_find (tag_hash
, name
));
1344 obj_read_begin_hook ()
1346 /* These had better be the same. Usually 18 bytes. */
1348 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1349 know (SYMESZ
== AUXESZ
);
1354 /* This function runs through the symbol table and puts all the
1355 externals onto another chain */
1357 /* The chain of externals */
1358 symbolS
*symbol_externP
= NULL
;
1359 symbolS
*symbol_extern_lastP
= NULL
;
1362 symbolS
*last_functionP
= NULL
;
1366 DEFUN_VOID (yank_symbols
)
1369 unsigned int symbol_number
= 0;
1370 unsigned int last_file_symno
= 0;
1372 for (symbolP
= symbol_rootP
;
1374 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
1376 if (!SF_GET_DEBUG (symbolP
))
1378 /* Debug symbols do not need all this rubbish */
1379 symbolS
*real_symbolP
;
1381 /* L* and C_EFCN symbols never merge. */
1382 if (!SF_GET_LOCAL (symbolP
)
1383 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
1384 && symbolP
->sy_value
.X_op
== O_constant
1385 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
1386 && real_symbolP
!= symbolP
)
1388 /* FIXME-SOON: where do dups come from?
1389 Maybe tag references before definitions? xoxorich. */
1390 /* Move the debug data from the debug symbol to the
1391 real symbol. Do NOT do the oposite (i.e. move from
1392 real symbol to debug symbol and remove real symbol from the
1393 list.) Because some pointers refer to the real symbol
1394 whereas no pointers refer to the debug symbol. */
1395 c_symbol_merge (symbolP
, real_symbolP
);
1396 /* Replace the current symbol by the real one */
1397 /* The symbols will never be the last or the first
1398 because : 1st symbol is .file and 3 last symbols are
1399 .text, .data, .bss */
1400 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
1401 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
1402 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1403 symbolP
= real_symbolP
;
1404 } /* if not local but dup'd */
1406 if (flagseen
['R'] && (S_GET_SEGMENT (symbolP
) == SEG_E1
))
1408 S_SET_SEGMENT (symbolP
, SEG_E0
);
1409 } /* push data into text */
1411 resolve_symbol_value (symbolP
);
1413 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
1415 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
1417 S_SET_EXTERNAL (symbolP
);
1419 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
1421 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
1425 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1429 /* Mainly to speed up if not -g */
1430 if (SF_GET_PROCESS (symbolP
))
1432 /* Handle the nested blocks auxiliary info. */
1433 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
1435 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
1436 stack_push (block_stack
, (char *) &symbolP
);
1439 register symbolS
*begin_symbolP
;
1440 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
1441 if (begin_symbolP
== (symbolS
*) 0)
1442 as_warn ("mismatched .eb");
1444 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
1447 /* If we are able to identify the type of a function, and we
1448 are out of a function (last_functionP == 0) then, the
1449 function symbol will be associated with an auxiliary
1451 if (last_functionP
== (symbolS
*) 0 &&
1452 SF_GET_FUNCTION (symbolP
))
1454 last_functionP
= symbolP
;
1456 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
1458 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1459 } /* make it at least 1 */
1461 /* Clobber possible stale .dim information. */
1463 /* Iffed out by steve - this fries the lnnoptr info too */
1464 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
1465 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
1468 /* The C_FCN doesn't need any additional information. I
1469 don't even know if this is needed for sdb. But the
1470 standard assembler generates it, so... */
1471 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
1473 if (last_functionP
== (symbolS
*) 0)
1474 as_fatal ("C_EFCN symbol out of scope");
1475 SA_SET_SYM_FSIZE (last_functionP
,
1476 (long) (S_GET_VALUE (symbolP
) -
1477 S_GET_VALUE (last_functionP
)));
1478 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
1479 last_functionP
= (symbolS
*) 0;
1483 else if (SF_GET_TAG (symbolP
))
1485 /* First descriptor of a structure must point to
1486 the first slot after the structure description. */
1487 last_tagP
= symbolP
;
1490 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
1492 /* +2 take in account the current symbol */
1493 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
1495 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
1497 if (S_GET_VALUE (symbolP
))
1499 S_SET_VALUE (symbolP
, last_file_symno
);
1500 last_file_symno
= symbol_number
;
1501 } /* no one points at the first .file symbol */
1502 } /* if debug or tag or eos or file */
1504 /* We must put the external symbols apart. The loader
1505 does not bomb if we do not. But the references in
1506 the endndx field for a .bb symbol are not corrected
1507 if an external symbol is removed between .bb and .be.
1508 I.e in the following case :
1509 [20] .bb endndx = 22
1512 ld will move the symbol 21 to the end of the list but
1513 endndx will still be 22 instead of 21. */
1516 if (SF_GET_LOCAL (symbolP
))
1518 /* remove C_EFCN and LOCAL (L...) symbols */
1519 /* next pointer remains valid */
1520 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1523 else if (!S_IS_DEFINED (symbolP
)
1524 && !S_IS_DEBUG (symbolP
)
1525 && !SF_GET_STATICS (symbolP
) &&
1526 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
1527 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
1528 /* if external, Remove from the list */
1529 symbolS
*hold
= symbol_previous (symbolP
);
1531 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1532 symbol_clear_list_pointers (symbolP
);
1533 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
1538 if (SF_GET_STRING (symbolP
))
1540 symbolP
->sy_name_offset
= string_byte_count
;
1541 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
1545 symbolP
->sy_name_offset
= 0;
1546 } /* fix "long" names */
1548 symbolP
->sy_number
= symbol_number
;
1549 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
1550 } /* if local symbol */
1551 } /* traverse the symbol list */
1552 return symbol_number
;
1558 DEFUN_VOID (glue_symbols
)
1560 unsigned int symbol_number
= 0;
1562 for (symbolP
= symbol_externP
; symbol_externP
;)
1564 symbolS
*tmp
= symbol_externP
;
1567 symbol_remove (tmp
, &symbol_externP
, &symbol_extern_lastP
);
1568 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
1571 if (SF_GET_STRING (tmp
))
1573 tmp
->sy_name_offset
= string_byte_count
;
1574 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
1578 tmp
->sy_name_offset
= 0;
1579 } /* fix "long" names */
1581 tmp
->sy_number
= symbol_number
;
1582 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
1583 } /* append the entire extern chain */
1584 return symbol_number
;
1589 DEFUN_VOID (tie_tags
)
1591 unsigned int symbol_number
= 0;
1594 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
1595 symbol_next (symbolP
))
1597 symbolP
->sy_number
= symbol_number
;
1601 if (SF_GET_TAGGED (symbolP
))
1605 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
1608 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
1610 return symbol_number
;
1615 DEFUN (crawl_symbols
, (h
, abfd
),
1616 object_headers
*h AND
1621 /* Initialize the stack used to keep track of the matching .bb .be */
1623 block_stack
= stack_init (512, sizeof (symbolS
*));
1625 /* The symbol list should be ordered according to the following sequence
1628 * . debug entries for functions
1629 * . fake symbols for the sections, including.text .data and .bss
1631 * . undefined symbols
1632 * But this is not mandatory. The only important point is to put the
1633 * undefined symbols at the end of the list.
1636 if (symbol_rootP
== NULL
1637 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1639 c_dot_file_symbol ("fake");
1641 /* Is there a .file symbol ? If not insert one at the beginning. */
1644 * Build up static symbols for the sections, they are filled in later
1648 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
1650 if (segment_info
[i
].scnhdr
.s_name
[0])
1654 strncpy (name
, segment_info
[i
].scnhdr
.s_name
, 8);
1656 segment_info
[i
].dot
= c_section_symbol (name
, i
- SEG_E0
+ 1);
1661 /* Take all the externals out and put them into another chain */
1662 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
1663 /* Take the externals and glue them onto the end.*/
1664 H_SET_SYMBOL_TABLE_SIZE (h
, H_GET_SYMBOL_COUNT (h
) + glue_symbols ());
1666 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
1667 know (symbol_externP
== NULL
);
1668 know (symbol_extern_lastP
== NULL
);
1672 * Find strings by crawling along symbol table chain.
1676 DEFUN (w_strings
, (where
),
1681 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
1682 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
1684 for (symbolP
= symbol_rootP
;
1686 symbolP
= symbol_next (symbolP
))
1690 if (SF_GET_STRING (symbolP
))
1692 size
= strlen (S_GET_NAME (symbolP
)) + 1;
1694 memcpy (where
, S_GET_NAME (symbolP
), size
);
1702 DEFUN (do_linenos_for
, (abfd
, h
, file_cursor
),
1704 object_headers
* h AND
1705 unsigned long *file_cursor
)
1708 unsigned long start
= *file_cursor
;
1710 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
1712 segment_info_type
*s
= segment_info
+ idx
;
1715 if (s
->scnhdr
.s_nlnno
!= 0)
1717 struct lineno_list
*line_ptr
;
1719 struct external_lineno
*buffer
=
1720 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
1722 struct external_lineno
*dst
= buffer
;
1724 /* Run through the table we've built and turn it into its external
1725 form, take this chance to remove duplicates */
1727 for (line_ptr
= s
->lineno_list_head
;
1728 line_ptr
!= (struct lineno_list
*) NULL
;
1729 line_ptr
= line_ptr
->next
)
1732 if (line_ptr
->line
.l_lnno
== 0)
1734 /* Turn a pointer to a symbol into the symbols' index */
1735 line_ptr
->line
.l_addr
.l_symndx
=
1736 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
1740 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
1744 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
1749 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
1751 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
1754 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
1757 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
1761 /* Now we run through the list of frag chains in a segment and
1762 make all the subsegment frags appear at the end of the
1763 list, as if the seg 0 was extra long */
1766 DEFUN_VOID (remove_subsegs
)
1770 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1772 frchainS
*head
= segment_info
[i
].frchainP
;
1774 fragS
*prev_frag
= &dummy
;
1776 while (head
&& head
->frch_seg
== i
)
1778 prev_frag
->fr_next
= head
->frch_root
;
1779 prev_frag
= head
->frch_last
;
1780 head
= head
->frch_next
;
1782 prev_frag
->fr_next
= 0;
1786 unsigned long machine
;
1789 DEFUN_VOID (write_object_file
)
1793 struct frchain
*frchain_ptr
;
1795 object_headers headers
;
1796 unsigned long file_cursor
;
1799 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
1804 as_perror ("FATAL: Can't create %s", out_file_name
);
1807 bfd_set_format (abfd
, bfd_object
);
1808 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
1810 string_byte_count
= 4;
1812 for (frchain_ptr
= frchain_root
;
1813 frchain_ptr
!= (struct frchain
*) NULL
;
1814 frchain_ptr
= frchain_ptr
->frch_next
)
1816 /* Run through all the sub-segments and align them up. Also close any
1817 open frags. We tack a .fill onto the end of the frag chain so
1818 that any .align's size can be worked by looking at the next
1821 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
1822 #ifndef SUB_SEGMENT_ALIGN
1823 #define SUB_SEGMENT_ALIGN(SEG) 1
1825 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
1826 frag_wane (frag_now
);
1827 frag_now
->fr_fix
= 0;
1828 know (frag_now
->fr_next
== NULL
);
1835 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1837 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
1840 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
1842 /* Find out how big the sections are, and set the addresses. */
1844 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1848 segment_info
[i
].scnhdr
.s_paddr
= addr
;
1849 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
1851 if (segment_info
[i
].scnhdr
.s_name
[0])
1853 H_SET_NUMBER_OF_SECTIONS (&headers
,
1854 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
1857 size
= size_section (abfd
, (unsigned int) i
);
1861 H_SET_TEXT_SIZE (&headers
, size
);
1862 else if (i
== SEG_E1
)
1863 H_SET_DATA_SIZE (&headers
, size
);
1864 else if (i
== SEG_E2
)
1865 H_SET_BSS_SIZE (&headers
, size
);
1868 /* Turn the gas native symbol table shape into a coff symbol table */
1869 crawl_symbols (&headers
, abfd
);
1871 if (string_byte_count
== 4)
1872 string_byte_count
= 0;
1874 H_SET_STRING_SIZE (&headers
, string_byte_count
);
1876 #if !defined(TC_H8300) && !defined(TC_Z8K)
1877 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1879 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
1880 fixup_segment (&segment_info
[i
], i
);
1884 /* Look for ".stab" segments and fill in their initial symbols
1886 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1888 name
= segment_info
[i
].scnhdr
.s_name
;
1891 && strncmp (".stab", name
, 5) == 0
1892 && strncmp (".stabstr", name
, 8) != 0)
1893 adjust_stab_section (abfd
, i
);
1896 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
1898 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
1900 /* Plant the data */
1902 fill_section (abfd
, &headers
, &file_cursor
);
1904 do_relocs_for (abfd
, &headers
, &file_cursor
);
1906 do_linenos_for (abfd
, &headers
, &file_cursor
);
1908 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
1909 #ifndef OBJ_COFF_OMIT_TIMESTAMP
1910 H_SET_TIME_STAMP (&headers
, (long)time((long*)0));
1912 H_SET_TIME_STAMP (&headers
, 0);
1915 #ifdef KEEP_RELOC_INFO
1916 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
1917 COFF_FLAGS
| coff_flags
));
1919 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
1920 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
1921 COFF_FLAGS
| coff_flags
));
1925 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
1926 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
1928 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
1929 w_symbols (abfd
, buffer1
, symbol_rootP
);
1930 if (string_byte_count
> 0)
1931 w_strings (buffer1
+ symtable_size
);
1932 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
1936 coff_header_append (abfd
, &headers
);
1938 /* Recent changes to write need this, but where it should
1939 go is up to Ken.. */
1940 if (bfd_close_all_done (abfd
) == false)
1941 as_fatal ("Can't close %s: %s", out_file_name
,
1942 bfd_errmsg (bfd_get_error ()));
1945 extern bfd
*stdoutput
;
1952 /* Add a new segment. This is called from subseg_new via the
1953 obj_new_segment macro. */
1956 obj_coff_add_segment (name
)
1962 /* Find out if we've already got a section of this name. */
1963 len
= strlen (name
);
1964 if (len
< sizeof (segment_info
[i
].scnhdr
.s_name
))
1967 len
= sizeof (segment_info
[i
].scnhdr
.s_name
);
1968 for (i
= SEG_E0
; i
< SEG_E9
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
1969 if (strncmp (segment_info
[i
].scnhdr
.s_name
, name
, len
) == 0
1970 && (len
== sizeof (segment_info
[i
].scnhdr
.s_name
)
1971 || segment_info
[i
].scnhdr
.s_name
[len
] == '\0'))
1976 as_bad ("Too many new sections; can't add \"%s\"", name
);
1980 /* Add a new section. */
1981 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
1982 sizeof (segment_info
[i
].scnhdr
.s_name
));
1983 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
1989 * implement the .section pseudo op:
1990 * .section name {, "flags"}
1992 * | +--- optional flags: 'b' for bss
1994 * +-- section name 'l' for lib
1998 * 'd' (apparently m88k for data)
2000 * But if the argument is not a quoted string, treat it as a
2001 * subsegment number.
2005 obj_coff_section (ignore
)
2008 /* Strip out the section name */
2010 char *section_name_end
;
2017 section_name
= input_line_pointer
;
2018 c
= get_symbol_end ();
2019 section_name_end
= input_line_pointer
;
2021 len
= section_name_end
- section_name
;
2022 input_line_pointer
++;
2028 else if (*input_line_pointer
== ',')
2031 ++input_line_pointer
;
2039 if (*input_line_pointer
!= '"')
2040 exp
= get_absolute_expression ();
2043 ++input_line_pointer
;
2044 while (*input_line_pointer
!= '"'
2045 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
2047 switch (*input_line_pointer
)
2049 case 'b': flags
|= STYP_BSS
; break;
2050 case 'i': flags
|= STYP_INFO
; break;
2051 case 'l': flags
|= STYP_LIB
; break;
2052 case 'n': flags
|= STYP_NOLOAD
; break;
2053 case 'o': flags
|= STYP_OVER
; break;
2055 case 'w': flags
|= STYP_DATA
; break;
2056 case 'x': flags
|= STYP_TEXT
; break;
2058 as_warn("unknown section attribute '%c'",
2059 *input_line_pointer
);
2062 ++input_line_pointer
;
2064 if (*input_line_pointer
== '"')
2065 ++input_line_pointer
;
2069 subseg_new (section_name
, (subsegT
) exp
);
2071 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
2073 *section_name_end
= c
;
2078 obj_coff_text (ignore
)
2081 subseg_new (".text", get_absolute_expression ());
2086 obj_coff_data (ignore
)
2090 subseg_new (".text", get_absolute_expression () + 1000);
2092 subseg_new (".data", get_absolute_expression ());
2096 obj_coff_bss (ignore
)
2099 if (*input_line_pointer
== '\n') /* .bss */
2100 subseg_new(".bss", get_absolute_expression());
2101 else /* .bss id,expr */
2106 obj_coff_ident (ignore
)
2109 segT current_seg
= now_seg
; /* save current seg */
2110 subsegT current_subseg
= now_subseg
;
2111 subseg_new (".comment", 0); /* .comment seg */
2112 stringer (1); /* read string */
2113 subseg_set (current_seg
, current_subseg
); /* restore current seg */
2117 c_symbol_merge (debug
, normal
)
2121 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
2122 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
2124 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
2126 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
2127 } /* take the most we have */
2129 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
2131 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
2132 (char *) &debug
->sy_symbol
.ost_auxent
[0],
2133 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
2134 } /* Move all the auxiliary information */
2136 /* Move the debug flags. */
2137 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
2138 } /* c_symbol_merge() */
2141 DEFUN (c_line_new
, (symbol
, paddr
, line_number
, frag
),
2142 symbolS
* symbol AND
2144 unsigned short line_number AND
2147 struct lineno_list
*new_line
=
2148 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
2150 segment_info_type
*s
= segment_info
+ now_seg
;
2151 new_line
->line
.l_lnno
= line_number
;
2153 if (line_number
== 0)
2155 last_line_symbol
= symbol
;
2156 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
2160 new_line
->line
.l_addr
.l_paddr
= paddr
;
2163 new_line
->frag
= (char *) frag
;
2164 new_line
->next
= (struct lineno_list
*) NULL
;
2167 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
2169 s
->lineno_list_head
= new_line
;
2173 s
->lineno_list_tail
->next
= new_line
;
2175 s
->lineno_list_tail
= new_line
;
2176 return LINESZ
* s
->scnhdr
.s_nlnno
++;
2180 c_dot_file_symbol (filename
)
2185 symbolP
= symbol_new (".file",
2188 &zero_address_frag
);
2190 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
2191 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2192 SA_SET_FILE_FNAME (symbolP
, filename
);
2198 listing_source_file (filename
);
2204 SF_SET_DEBUG (symbolP
);
2205 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
2207 previous_file_symbol
= symbolP
;
2209 /* Make sure that the symbol is first on the symbol chain */
2210 if (symbol_rootP
!= symbolP
)
2212 if (symbolP
== symbol_lastP
)
2214 symbol_lastP
= symbol_lastP
->sy_previous
;
2215 } /* if it was the last thing on the list */
2217 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2218 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
2219 symbol_rootP
= symbolP
;
2220 } /* if not first on the list */
2222 } /* c_dot_file_symbol() */
2225 * Build a 'section static' symbol.
2229 c_section_symbol (name
, idx
)
2235 symbolP
= symbol_new (name
, idx
,
2237 &zero_address_frag
);
2239 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2240 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2242 SF_SET_STATICS (symbolP
);
2245 } /* c_section_symbol() */
2248 DEFUN (w_symbols
, (abfd
, where
, symbol_rootP
),
2251 symbolS
* symbol_rootP
)
2256 /* First fill in those values we have only just worked out */
2257 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
2259 symbolP
= segment_info
[i
].dot
;
2263 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
2264 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
2265 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
2271 * Emit all symbols left in the symbol chain.
2273 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2275 /* Used to save the offset of the name. It is used to point
2276 to the string in memory but must be a file offset. */
2277 register char *temp
;
2279 tc_coff_symbol_emit_hook (symbolP
);
2281 temp
= S_GET_NAME (symbolP
);
2282 if (SF_GET_STRING (symbolP
))
2284 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
2285 S_SET_ZEROES (symbolP
, 0);
2289 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
2290 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
2292 where
= symbol_to_chars (abfd
, where
, symbolP
);
2293 S_SET_NAME (symbolP
, temp
);
2299 obj_coff_lcomm (ignore
)
2310 name
= input_line_pointer
;
2312 c
= get_symbol_end ();
2313 p
= input_line_pointer
;
2316 if (*input_line_pointer
!= ',')
2318 as_bad ("Expected comma after name");
2319 ignore_rest_of_line ();
2322 if (*input_line_pointer
== '\n')
2324 as_bad ("Missing size expression");
2327 input_line_pointer
++;
2328 if ((temp
= get_absolute_expression ()) < 0)
2330 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
2331 ignore_rest_of_line ();
2336 symbolP
= symbol_find_or_make(name
);
2338 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
2339 S_GET_VALUE(symbolP
) == 0)
2344 segT current_seg
= now_seg
; /* save current seg */
2345 subsegT current_subseg
= now_subseg
;
2347 subseg_set (SEG_E2
, 1);
2348 symbolP
->sy_frag
= frag_now
;
2349 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
2352 subseg_set (current_seg
, current_subseg
); /* restore current seg */
2353 S_SET_SEGMENT(symbolP
, SEG_E2
);
2354 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
2358 as_bad("Symbol %s already defined", name
);
2360 demand_empty_rest_of_line();
2364 DEFUN (fixup_mdeps
, (frags
, h
, this_segment
),
2366 object_headers
* h AND
2369 subseg_change (this_segment
, 0);
2372 switch (frags
->fr_type
)
2376 frags
->fr_type
= rs_fill
;
2378 (frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
);
2380 case rs_machine_dependent
:
2381 md_convert_frag (h
, frags
);
2387 frags
= frags
->fr_next
;
2393 DEFUN (fixup_segment
, (segP
, this_segment_type
),
2394 segment_info_type
* segP AND
2395 segT this_segment_type
)
2397 register fixS
* fixP
;
2398 register symbolS
*add_symbolP
;
2399 register symbolS
*sub_symbolP
;
2400 register long add_number
;
2402 register char *place
;
2403 register long where
;
2404 register char pcrel
;
2405 register fragS
*fragP
;
2406 register segT add_symbol_segment
= SEG_ABSOLUTE
;
2409 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
2411 fragP
= fixP
->fx_frag
;
2413 where
= fixP
->fx_where
;
2414 place
= fragP
->fr_literal
+ where
;
2415 size
= fixP
->fx_size
;
2416 add_symbolP
= fixP
->fx_addsy
;
2418 if (fixP
->fx_tcbit
&& TC_S_IS_CALLNAME (add_symbolP
))
2420 /* Relocation should be done via the associated 'bal' entry
2423 if (!TC_S_IS_BALNAME (tc_get_bal_of_call (add_symbolP
)))
2425 as_bad ("No 'bal' entry point for leafproc %s",
2426 S_GET_NAME (add_symbolP
));
2429 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
2432 sub_symbolP
= fixP
->fx_subsy
;
2433 add_number
= fixP
->fx_offset
;
2434 pcrel
= fixP
->fx_pcrel
;
2438 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
2439 } /* if there is an addend */
2446 if (S_GET_SEGMENT (sub_symbolP
) != SEG_ABSOLUTE
)
2448 as_bad ("Negative of non-absolute symbol %s", S_GET_NAME (sub_symbolP
));
2449 } /* not absolute */
2451 add_number
-= S_GET_VALUE (sub_symbolP
);
2454 /* if sub_symbol is in the same segment that add_symbol
2455 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
2457 else if ((S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
)
2458 && (SEG_NORMAL (add_symbol_segment
)
2459 || (add_symbol_segment
== SEG_ABSOLUTE
)))
2461 /* Difference of 2 symbols from same segment. Can't
2462 make difference of 2 undefineds: 'value' means
2463 something different for N_UNDF. */
2465 /* Makes no sense to use the difference of 2 arbitrary symbols
2466 as the target of a call instruction. */
2469 as_bad ("callj to difference of 2 symbols");
2471 #endif /* TC_I960 */
2472 add_number
+= S_GET_VALUE (add_symbolP
) -
2473 S_GET_VALUE (sub_symbolP
);
2476 fixP
->fx_addsy
= NULL
;
2481 /* Different segments in subtraction. */
2482 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == SEG_ABSOLUTE
)));
2484 if ((S_GET_SEGMENT (sub_symbolP
) == SEG_ABSOLUTE
))
2486 add_number
-= S_GET_VALUE (sub_symbolP
);
2490 && S_GET_SEGMENT (sub_symbolP
) == this_segment_type
)
2492 /* Make it pc-relative. */
2493 add_number
+= (md_pcrel_from (fixP
)
2494 - S_GET_VALUE (sub_symbolP
));
2503 as_bad ("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
2504 segment_name (S_GET_SEGMENT (sub_symbolP
)),
2505 S_GET_NAME (sub_symbolP
),
2506 (long) (fragP
->fr_address
+ where
));
2509 } /* if sub_symbolP */
2513 if (add_symbol_segment
== this_segment_type
&& pcrel
)
2516 * This fixup was made when the symbol's segment was
2517 * SEG_UNKNOWN, but it is now in the local segment.
2518 * So we know how to do the address without relocation.
2521 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
2522 * in which cases it modifies *fixP as appropriate. In the case
2523 * of a 'calls', no further work is required, and *fixP has been
2524 * set up to make the rest of the code below a no-op.
2527 #endif /* TC_I960 */
2529 add_number
+= S_GET_VALUE (add_symbolP
);
2530 add_number
-= md_pcrel_from (fixP
);
2532 /* On the 386 we must adjust by the segment
2533 vaddr as well. Ian Taylor. */
2534 add_number
-= segP
->scnhdr
.s_vaddr
;
2536 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
2537 fixP
->fx_addsy
= NULL
;
2542 switch (add_symbol_segment
)
2546 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
2547 #endif /* TC_I960 */
2548 add_number
+= S_GET_VALUE (add_symbolP
);
2549 fixP
->fx_addsy
= NULL
;
2556 /* This really should be handled in the linker, but
2557 backward compatibility forbids. */
2558 add_number
+= S_GET_VALUE (add_symbolP
);
2560 add_number
+= S_GET_VALUE (add_symbolP
) +
2561 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
2567 if ((int) fixP
->fx_bit_fixP
== 13)
2569 /* This is a COBR instruction. They have only a
2570 * 13-bit displacement and are only to be used
2571 * for local branches: flag as error, don't generate
2574 as_bad ("can't use COBR format with external label");
2575 fixP
->fx_addsy
= NULL
;
2579 #endif /* TC_I960 */
2581 /* 386 COFF uses a peculiar format in
2582 which the value of a common symbol is
2583 stored in the .text segment (I've
2584 checked this on SVR3.2 and SCO 3.2.2)
2585 Ian Taylor <ian@cygnus.com>. */
2586 if (S_IS_COMMON (add_symbolP
))
2587 add_number
+= S_GET_VALUE (add_symbolP
);
2592 } /* switch on symbol seg */
2593 } /* if not in local seg */
2594 } /* if there was a + symbol */
2599 /* This adjustment is not correct on the m88k, for which the
2600 linker does all the computation. */
2601 add_number
-= md_pcrel_from (fixP
);
2603 if (add_symbolP
== 0)
2605 fixP
->fx_addsy
= &abs_symbol
;
2606 } /* if there's an add_symbol */
2608 /* On the 386 we must adjust by the segment vaddr
2609 as well. Ian Taylor. */
2610 add_number
-= segP
->scnhdr
.s_vaddr
;
2614 if (!fixP
->fx_bit_fixP
)
2617 /* The m88k uses the offset field of the reloc to get around
2620 (add_number
& ~0xFF) && ((add_number
& ~0xFF) != (-1 & ~0xFF))) ||
2622 (add_number
& ~0xFFFF) && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
2624 as_bad ("Value of %ld too large for field of %d bytes at 0x%lx",
2625 (long) add_number
, size
,
2626 (unsigned long) (fragP
->fr_address
+ where
));
2627 } /* generic error checking */
2629 #ifdef WARN_SIGNED_OVERFLOW_WORD
2630 /* Warn if a .word value is too large when treated as
2631 a signed number. We already know it is not too
2632 negative. This is to catch over-large switches
2633 generated by gcc on the 68k. */
2636 && add_number
> 0x7fff)
2637 as_bad ("Signed .word overflow; switch may be too large; %ld at 0x%lx",
2639 (unsigned long) (fragP
->fr_address
+ where
));
2641 } /* not a bit fix */
2642 /* once this fix has been applied, we don't have to output anything
2643 nothing more need be done -*/
2644 md_apply_fix (fixP
, add_number
);
2645 } /* For each fixS in this segment. */
2646 } /* fixup_segment() */
2650 /* The first entry in a .stab section is special. */
2653 obj_coff_init_stab_section (seg
)
2659 unsigned int stroff
;
2661 /* Make space for this first symbol. */
2665 as_where (&file
, (unsigned int *) NULL
);
2666 stabstr_name
= alloca (strlen (segment_info
[seg
].scnhdr
.s_name
) + 4);
2667 strcpy (stabstr_name
, segment_info
[seg
].scnhdr
.s_name
);
2668 strcat (stabstr_name
, "str");
2669 stroff
= get_stab_string_offset (file
, stabstr_name
);
2671 md_number_to_chars (p
, stroff
, 4);
2674 /* Fill in the counts in the first entry in a .stab section. */
2677 adjust_stab_section(abfd
, seg
)
2681 segT stabstrseg
= -1;
2682 char *secname
, *name
, *name2
;
2684 int i
, strsz
= 0, nsyms
;
2685 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
2687 /* Look for the associated string table section. */
2689 secname
= segment_info
[seg
].scnhdr
.s_name
;
2690 name
= (char *) alloca (strlen (secname
) + 4);
2691 strcpy (name
, secname
);
2692 strcat (name
, "str");
2694 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2696 name2
= segment_info
[i
].scnhdr
.s_name
;
2697 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
2704 /* If we found the section, get its size. */
2705 if (stabstrseg
>= 0)
2706 strsz
= size_section (abfd
, stabstrseg
);
2708 nsyms
= size_section (abfd
, seg
) / 12 - 1;
2710 /* Look for the first frag of sufficient size for the initial stab
2711 symbol, and collect a pointer to it. */
2712 while (frag
&& frag
->fr_fix
< 12)
2713 frag
= frag
->fr_next
;
2715 p
= frag
->fr_literal
;
2718 /* Write in the number of stab symbols and the size of the string
2720 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
2721 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);