1 /* symbols.c -symbol table-
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* #define DEBUG_SYMS / * to debug symbol list maintenance. */
27 #include "safe-ctype.h"
28 #include "obstack.h" /* For "symbols.h" */
31 #include "struc-symbol.h"
33 /* This is non-zero if symbols are case sensitive, which is the
35 int symbols_case_sensitive
= 1;
37 #ifndef WORKING_DOT_WORD
38 extern int new_broken_words
;
41 /* symbol-name => struct symbol pointer */
42 static struct hash_control
*sy_hash
;
44 /* Table of local symbols. */
45 static struct hash_control
*local_hash
;
47 /* Below are commented in "symbols.h". */
48 symbolS
*symbol_rootP
;
49 symbolS
*symbol_lastP
;
53 #define debug_verify_symchain verify_symbol_chain
55 #define debug_verify_symchain(root, last) ((void) 0)
58 #define DOLLAR_LABEL_CHAR '\001'
59 #define LOCAL_LABEL_CHAR '\002'
63 static char *save_symbol_name
PARAMS ((const char *));
64 static void fb_label_init
PARAMS ((void));
65 static long dollar_label_instance
PARAMS ((long));
66 static long fb_label_instance
PARAMS ((long));
68 static void print_binary
PARAMS ((FILE *, const char *, expressionS
*));
70 /* Return a pointer to a new symbol. Die if we can't make a new
71 symbol. Fill in the symbol's values. Add symbol to end of symbol
74 This function should be called in the general case of creating a
75 symbol. However, if the output file symbol table has already been
76 set, and you are certain that this symbol won't be wanted in the
77 output file, you can call symbol_create. */
80 symbol_new (name
, segment
, valu
, frag
)
86 symbolS
*symbolP
= symbol_create (name
, segment
, valu
, frag
);
88 /* Link to end of symbol chain. */
91 extern int symbol_table_frozen
;
92 if (symbol_table_frozen
)
96 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
101 /* Save a symbol name on a permanent obstack, and convert it according
102 to the object file format. */
105 save_symbol_name (name
)
108 unsigned int name_length
;
111 name_length
= strlen (name
) + 1; /* +1 for \0. */
112 obstack_grow (¬es
, name
, name_length
);
113 ret
= obstack_finish (¬es
);
115 #ifdef STRIP_UNDERSCORE
120 #ifdef tc_canonicalize_symbol_name
121 ret
= tc_canonicalize_symbol_name (ret
);
124 if (! symbols_case_sensitive
)
128 for (s
= ret
; *s
!= '\0'; s
++)
136 symbol_create (name
, segment
, valu
, frag
)
137 const char *name
; /* It is copied, the caller can destroy/modify. */
138 segT segment
; /* Segment identifier (SEG_<something>). */
139 valueT valu
; /* Symbol value. */
140 fragS
*frag
; /* Associated fragment. */
142 char *preserved_copy_of_name
;
145 preserved_copy_of_name
= save_symbol_name (name
);
147 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
149 /* symbol must be born in some fixed state. This seems as good as any. */
150 memset (symbolP
, 0, sizeof (symbolS
));
153 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
154 if (symbolP
->bsym
== NULL
)
155 as_perror ("%s", "bfd_make_empty_symbol");
156 symbolP
->bsym
->udata
.p
= (PTR
) symbolP
;
158 S_SET_NAME (symbolP
, preserved_copy_of_name
);
160 S_SET_SEGMENT (symbolP
, segment
);
161 S_SET_VALUE (symbolP
, valu
);
162 symbol_clear_list_pointers (symbolP
);
164 symbolP
->sy_frag
= frag
;
165 #ifndef BFD_ASSEMBLER
166 symbolP
->sy_number
= ~0;
167 symbolP
->sy_name_offset
= (unsigned int) ~0;
170 obj_symbol_new_hook (symbolP
);
172 #ifdef tc_symbol_new_hook
173 tc_symbol_new_hook (symbolP
);
181 /* Local symbol support. If we can get away with it, we keep only a
182 small amount of information for local symbols. */
184 static struct local_symbol
*local_symbol_make
PARAMS ((const char *, segT
,
186 static symbolS
*local_symbol_convert
PARAMS ((struct local_symbol
*));
188 /* Used for statistics. */
190 static unsigned long local_symbol_count
;
191 static unsigned long local_symbol_conversion_count
;
193 /* This macro is called with a symbol argument passed by reference.
194 It returns whether this is a local symbol. If necessary, it
195 changes its argument to the real symbol. */
197 #define LOCAL_SYMBOL_CHECK(s) \
199 ? (local_symbol_converted_p ((struct local_symbol *) s) \
200 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
205 /* Create a local symbol and insert it into the local hash table. */
207 static struct local_symbol
*
208 local_symbol_make (name
, section
, value
, frag
)
215 struct local_symbol
*ret
;
217 ++local_symbol_count
;
219 name_copy
= save_symbol_name (name
);
221 ret
= (struct local_symbol
*) obstack_alloc (¬es
, sizeof *ret
);
222 ret
->lsy_marker
= NULL
;
223 ret
->lsy_name
= name_copy
;
224 ret
->lsy_section
= section
;
225 local_symbol_set_frag (ret
, frag
);
226 ret
->lsy_value
= value
;
228 hash_jam (local_hash
, name_copy
, (PTR
) ret
);
233 /* Convert a local symbol into a real symbol. Note that we do not
234 reclaim the space used by the local symbol. */
237 local_symbol_convert (locsym
)
238 struct local_symbol
*locsym
;
242 assert (locsym
->lsy_marker
== NULL
);
243 if (local_symbol_converted_p (locsym
))
244 return local_symbol_get_real_symbol (locsym
);
246 ++local_symbol_conversion_count
;
248 ret
= symbol_new (locsym
->lsy_name
, locsym
->lsy_section
, locsym
->lsy_value
,
249 local_symbol_get_frag (locsym
));
251 if (local_symbol_resolved_p (locsym
))
252 ret
->sy_resolved
= 1;
254 /* Local symbols are always either defined or used. */
257 #ifdef TC_LOCAL_SYMFIELD_CONVERT
258 TC_LOCAL_SYMFIELD_CONVERT (locsym
, ret
);
261 symbol_table_insert (ret
);
263 local_symbol_mark_converted (locsym
);
264 local_symbol_set_real_symbol (locsym
, ret
);
266 hash_jam (local_hash
, locsym
->lsy_name
, NULL
);
271 #else /* ! BFD_ASSEMBLER */
273 #define LOCAL_SYMBOL_CHECK(s) 0
274 #define local_symbol_convert(s) ((symbolS *) s)
276 #endif /* ! BFD_ASSEMBLER */
278 /* We have just seen "<name>:".
279 Creates a struct symbol unless it already exists.
281 Gripes if we are redefining a symbol incompatibly (and ignores it). */
284 colon (sym_name
) /* Just seen "x:" - rattle symbols & frags. */
285 const char *sym_name
; /* Symbol name, as a cannonical string. */
286 /* We copy this string: OK to alter later. */
288 register symbolS
*symbolP
; /* Symbol we are working with. */
290 /* Sun local labels go out of scope whenever a non-local symbol is
292 if (LOCAL_LABELS_DOLLAR
)
297 local
= bfd_is_local_label_name (stdoutput
, sym_name
);
299 local
= LOCAL_LABEL (sym_name
);
303 dollar_label_clear ();
306 #ifndef WORKING_DOT_WORD
307 if (new_broken_words
)
309 struct broken_word
*a
;
314 extern const int md_short_jump_size
;
315 extern const int md_long_jump_size
;
316 possible_bytes
= (md_short_jump_size
317 + new_broken_words
* md_long_jump_size
);
320 frag_opcode
= frag_var (rs_broken_word
,
324 (symbolS
*) broken_words
,
328 /* We want to store the pointer to where to insert the jump
329 table in the fr_opcode of the rs_broken_word frag. This
330 requires a little hackery. */
332 && (frag_tmp
->fr_type
!= rs_broken_word
333 || frag_tmp
->fr_opcode
))
334 frag_tmp
= frag_tmp
->fr_next
;
336 frag_tmp
->fr_opcode
= frag_opcode
;
337 new_broken_words
= 0;
339 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
340 a
->dispfrag
= frag_tmp
;
342 #endif /* WORKING_DOT_WORD */
344 if ((symbolP
= symbol_find (sym_name
)) != 0)
346 #ifdef RESOLVE_SYMBOL_REDEFINITION
347 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
350 /* Now check for undefined symbols. */
351 if (LOCAL_SYMBOL_CHECK (symbolP
))
354 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
356 if (locsym
->lsy_section
!= undefined_section
357 && (local_symbol_get_frag (locsym
) != frag_now
358 || locsym
->lsy_section
!= now_seg
359 || locsym
->lsy_value
!= frag_now_fix ()))
361 as_bad (_("symbol `%s' is already defined"), sym_name
);
365 locsym
->lsy_section
= now_seg
;
366 local_symbol_set_frag (locsym
, frag_now
);
367 locsym
->lsy_value
= frag_now_fix ();
370 else if (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
372 if (S_GET_VALUE (symbolP
) == 0)
374 symbolP
->sy_frag
= frag_now
;
376 S_SET_OTHER (symbolP
, const_flag
);
378 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
379 S_SET_SEGMENT (symbolP
, now_seg
);
382 #endif /* if we have one, it better be zero. */
387 /* There are still several cases to check:
389 A .comm/.lcomm symbol being redefined as initialized
392 A .comm/.lcomm symbol being redefined with a larger
395 This only used to be allowed on VMS gas, but Sun cc
396 on the sparc also depends on it. */
398 if (((!S_IS_DEBUG (symbolP
)
399 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
400 && S_IS_EXTERNAL (symbolP
))
401 || S_GET_SEGMENT (symbolP
) == bss_section
)
402 && (now_seg
== data_section
403 || now_seg
== S_GET_SEGMENT (symbolP
)))
405 /* Select which of the 2 cases this is. */
406 if (now_seg
!= data_section
)
408 /* New .comm for prev .comm symbol.
410 If the new size is larger we just change its
411 value. If the new size is smaller, we ignore
413 if (S_GET_VALUE (symbolP
)
414 < ((unsigned) frag_now_fix ()))
416 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
421 /* It is a .comm/.lcomm being converted to initialized
423 symbolP
->sy_frag
= frag_now
;
425 S_SET_OTHER (symbolP
, const_flag
);
427 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
428 S_SET_SEGMENT (symbolP
, now_seg
); /* Keep N_EXT bit. */
433 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
434 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
435 static const char *od_buf
= "";
440 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
442 sprintf (od_buf
, "%d.%d.",
443 S_GET_OTHER (symbolP
),
444 S_GET_DESC (symbolP
));
446 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
448 segment_name (S_GET_SEGMENT (symbolP
)),
450 (long) S_GET_VALUE (symbolP
));
452 } /* if the undefined symbol has no value */
456 /* Don't blow up if the definition is the same. */
457 if (!(frag_now
== symbolP
->sy_frag
458 && S_GET_VALUE (symbolP
) == frag_now_fix ()
459 && S_GET_SEGMENT (symbolP
) == now_seg
))
460 as_bad (_("symbol `%s' is already defined"), sym_name
);
465 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
467 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
468 (valueT
) frag_now_fix (),
471 #endif /* BFD_ASSEMBLER */
474 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
477 S_SET_OTHER (symbolP
, const_flag
);
480 symbol_table_insert (symbolP
);
483 if (mri_common_symbol
!= NULL
)
485 /* This symbol is actually being defined within an MRI common
486 section. This requires special handling. */
487 if (LOCAL_SYMBOL_CHECK (symbolP
))
488 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
489 symbolP
->sy_value
.X_op
= O_symbol
;
490 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
491 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
492 symbolP
->sy_frag
= &zero_address_frag
;
493 S_SET_SEGMENT (symbolP
, expr_section
);
494 symbolP
->sy_mri_common
= 1;
498 tc_frob_label (symbolP
);
500 #ifdef obj_frob_label
501 obj_frob_label (symbolP
);
507 /* Die if we can't insert the symbol. */
510 symbol_table_insert (symbolP
)
513 register const char *error_string
;
516 know (S_GET_NAME (symbolP
));
518 if (LOCAL_SYMBOL_CHECK (symbolP
))
520 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
522 if (error_string
!= NULL
)
523 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
524 S_GET_NAME (symbolP
), error_string
);
528 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
530 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
531 S_GET_NAME (symbolP
), error_string
);
535 /* If a symbol name does not exist, create it as undefined, and insert
536 it into the symbol table. Return a pointer to it. */
539 symbol_find_or_make (name
)
542 register symbolS
*symbolP
;
544 symbolP
= symbol_find (name
);
549 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
551 symbolP
= md_undefined_symbol ((char *) name
);
555 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
562 symbolP
= symbol_make (name
);
564 symbol_table_insert (symbolP
);
565 } /* if symbol wasn't found */
576 /* Let the machine description default it, e.g. for register names. */
577 symbolP
= md_undefined_symbol ((char *) name
);
580 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
585 /* Implement symbol table lookup.
586 In: A symbol's name as a string: '\0' can't be part of a symbol name.
587 Out: NULL if the name was not in the symbol table, else the address
588 of a struct symbol associated with that name. */
594 #ifdef STRIP_UNDERSCORE
595 return (symbol_find_base (name
, 1));
596 #else /* STRIP_UNDERSCORE */
597 return (symbol_find_base (name
, 0));
598 #endif /* STRIP_UNDERSCORE */
602 symbol_find_exact (name
)
607 struct local_symbol
*locsym
;
609 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
611 return (symbolS
*) locsym
;
615 return ((symbolS
*) hash_find (sy_hash
, name
));
619 symbol_find_base (name
, strip_underscore
)
621 int strip_underscore
;
623 if (strip_underscore
&& *name
== '_')
626 #ifdef tc_canonicalize_symbol_name
629 size_t len
= strlen (name
) + 1;
631 copy
= (char *) alloca (len
);
632 memcpy (copy
, name
, len
);
633 name
= tc_canonicalize_symbol_name (copy
);
637 if (! symbols_case_sensitive
)
644 name
= copy
= (char *) alloca (strlen (name
) + 1);
646 while ((c
= *orig
++) != '\0')
648 *copy
++ = TOUPPER (c
);
653 return symbol_find_exact (name
);
656 /* Once upon a time, symbols were kept in a singly linked list. At
657 least coff needs to be able to rearrange them from time to time, for
658 which a doubly linked list is much more convenient. Loic did these
659 as macros which seemed dangerous to me so they're now functions.
662 /* Link symbol ADDME after symbol TARGET in the chain. */
665 symbol_append (addme
, target
, rootPP
, lastPP
)
671 if (LOCAL_SYMBOL_CHECK (addme
))
673 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
678 know (*rootPP
== NULL
);
679 know (*lastPP
== NULL
);
680 addme
->sy_next
= NULL
;
681 #ifdef SYMBOLS_NEED_BACKPOINTERS
682 addme
->sy_previous
= NULL
;
687 } /* if the list is empty */
689 if (target
->sy_next
!= NULL
)
691 #ifdef SYMBOLS_NEED_BACKPOINTERS
692 target
->sy_next
->sy_previous
= addme
;
693 #endif /* SYMBOLS_NEED_BACKPOINTERS */
697 know (*lastPP
== target
);
699 } /* if we have a next */
701 addme
->sy_next
= target
->sy_next
;
702 target
->sy_next
= addme
;
704 #ifdef SYMBOLS_NEED_BACKPOINTERS
705 addme
->sy_previous
= target
;
706 #endif /* SYMBOLS_NEED_BACKPOINTERS */
708 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
711 /* Set the chain pointers of SYMBOL to null. */
714 symbol_clear_list_pointers (symbolP
)
717 if (LOCAL_SYMBOL_CHECK (symbolP
))
719 symbolP
->sy_next
= NULL
;
720 #ifdef SYMBOLS_NEED_BACKPOINTERS
721 symbolP
->sy_previous
= NULL
;
725 #ifdef SYMBOLS_NEED_BACKPOINTERS
726 /* Remove SYMBOLP from the list. */
729 symbol_remove (symbolP
, rootPP
, lastPP
)
734 if (LOCAL_SYMBOL_CHECK (symbolP
))
737 if (symbolP
== *rootPP
)
739 *rootPP
= symbolP
->sy_next
;
740 } /* if it was the root */
742 if (symbolP
== *lastPP
)
744 *lastPP
= symbolP
->sy_previous
;
745 } /* if it was the tail */
747 if (symbolP
->sy_next
!= NULL
)
749 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
752 if (symbolP
->sy_previous
!= NULL
)
754 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
757 debug_verify_symchain (*rootPP
, *lastPP
);
760 /* Link symbol ADDME before symbol TARGET in the chain. */
763 symbol_insert (addme
, target
, rootPP
, lastPP
)
767 symbolS
**lastPP ATTRIBUTE_UNUSED
;
769 if (LOCAL_SYMBOL_CHECK (addme
))
771 if (LOCAL_SYMBOL_CHECK (target
))
774 if (target
->sy_previous
!= NULL
)
776 target
->sy_previous
->sy_next
= addme
;
780 know (*rootPP
== target
);
784 addme
->sy_previous
= target
->sy_previous
;
785 target
->sy_previous
= addme
;
786 addme
->sy_next
= target
;
788 debug_verify_symchain (*rootPP
, *lastPP
);
791 #endif /* SYMBOLS_NEED_BACKPOINTERS */
794 verify_symbol_chain (rootP
, lastP
)
798 symbolS
*symbolP
= rootP
;
803 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
806 assert (symbolP
->bsym
!= NULL
);
808 #ifdef SYMBOLS_NEED_BACKPOINTERS
809 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
811 /* Walk the list anyways, to make sure pointers are still good. */
813 #endif /* SYMBOLS_NEED_BACKPOINTERS */
816 assert (lastP
== symbolP
);
820 verify_symbol_chain_2 (sym
)
823 symbolS
*p
= sym
, *n
= sym
;
824 #ifdef SYMBOLS_NEED_BACKPOINTERS
825 while (symbol_previous (p
))
826 p
= symbol_previous (p
);
828 while (symbol_next (n
))
830 verify_symbol_chain (p
, n
);
833 /* Resolve the value of a symbol. This is called during the final
834 pass over the symbol table to resolve any symbols with complex
838 resolve_symbol_value (symp
)
842 valueT final_val
= 0;
846 if (LOCAL_SYMBOL_CHECK (symp
))
848 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
850 final_val
= locsym
->lsy_value
;
851 if (local_symbol_resolved_p (locsym
))
854 final_val
+= local_symbol_get_frag (locsym
)->fr_address
/ OCTETS_PER_BYTE
;
858 locsym
->lsy_value
= final_val
;
859 local_symbol_mark_resolved (locsym
);
866 if (symp
->sy_resolved
)
868 if (symp
->sy_value
.X_op
== O_constant
)
869 return (valueT
) symp
->sy_value
.X_add_number
;
875 final_seg
= S_GET_SEGMENT (symp
);
877 if (symp
->sy_resolving
)
880 as_bad (_("symbol definition loop encountered at `%s'"),
887 symbolS
*add_symbol
, *op_symbol
;
889 segT seg_left
, seg_right
;
892 symp
->sy_resolving
= 1;
894 /* Help out with CSE. */
895 add_symbol
= symp
->sy_value
.X_add_symbol
;
896 op_symbol
= symp
->sy_value
.X_op_symbol
;
897 final_val
= symp
->sy_value
.X_add_number
;
898 op
= symp
->sy_value
.X_op
;
911 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
912 if (final_seg
== expr_section
)
913 final_seg
= absolute_section
;
919 left
= resolve_symbol_value (add_symbol
);
920 seg_left
= S_GET_SEGMENT (add_symbol
);
922 symp
->sy_value
.X_op_symbol
= NULL
;
925 if (symp
->sy_mri_common
)
927 /* This is a symbol inside an MRI common section. The
928 relocation routines are going to handle it specially.
929 Don't change the value. */
930 resolved
= symbol_resolved_p (add_symbol
);
934 if (finalize_syms
&& final_val
== 0)
936 if (LOCAL_SYMBOL_CHECK (add_symbol
))
937 add_symbol
= local_symbol_convert ((struct local_symbol
*)
939 copy_symbol_attributes (symp
, add_symbol
);
942 /* If we have equated this symbol to an undefined or common
943 symbol, keep X_op set to O_symbol, and don't change
944 X_add_number. This permits the routine which writes out
945 relocation to detect this case, and convert the
946 relocation to be against the symbol to which this symbol
948 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
952 symp
->sy_value
.X_op
= O_symbol
;
953 symp
->sy_value
.X_add_symbol
= add_symbol
;
954 symp
->sy_value
.X_add_number
= final_val
;
955 /* Use X_op_symbol as a flag. */
956 symp
->sy_value
.X_op_symbol
= add_symbol
;
957 final_seg
= seg_left
;
960 resolved
= symbol_resolved_p (add_symbol
);
961 symp
->sy_resolving
= 0;
962 goto exit_dont_set_value
;
964 else if (finalize_syms
&& final_seg
== expr_section
965 && seg_left
!= expr_section
)
967 /* If the symbol is an expression symbol, do similarly
968 as for undefined and common syms above. Handles
969 "sym +/- expr" where "expr" cannot be evaluated
970 immediately, and we want relocations to be against
971 "sym", eg. because it is weak. */
972 symp
->sy_value
.X_op
= O_symbol
;
973 symp
->sy_value
.X_add_symbol
= add_symbol
;
974 symp
->sy_value
.X_add_number
= final_val
;
975 symp
->sy_value
.X_op_symbol
= add_symbol
;
976 final_seg
= seg_left
;
977 final_val
+= symp
->sy_frag
->fr_address
+ left
;
978 resolved
= symbol_resolved_p (add_symbol
);
979 symp
->sy_resolving
= 0;
980 goto exit_dont_set_value
;
984 final_val
+= symp
->sy_frag
->fr_address
+ left
;
985 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
986 final_seg
= seg_left
;
989 resolved
= symbol_resolved_p (add_symbol
);
995 left
= resolve_symbol_value (add_symbol
);
996 seg_left
= S_GET_SEGMENT (add_symbol
);
1000 else if (op
== O_logical_not
)
1005 final_val
+= left
+ symp
->sy_frag
->fr_address
;
1006 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1007 final_seg
= seg_left
;
1009 resolved
= symbol_resolved_p (add_symbol
);
1017 case O_bit_inclusive_or
:
1019 case O_bit_exclusive_or
:
1031 left
= resolve_symbol_value (add_symbol
);
1032 right
= resolve_symbol_value (op_symbol
);
1033 seg_left
= S_GET_SEGMENT (add_symbol
);
1034 seg_right
= S_GET_SEGMENT (op_symbol
);
1036 /* Simplify addition or subtraction of a constant by folding the
1037 constant into X_add_number. */
1040 if (seg_right
== absolute_section
)
1045 else if (seg_left
== absolute_section
)
1048 add_symbol
= op_symbol
;
1050 seg_left
= seg_right
;
1054 else if (op
== O_subtract
)
1056 if (seg_right
== absolute_section
)
1063 /* Equality and non-equality tests are permitted on anything.
1064 Subtraction, and other comparison operators are permitted if
1065 both operands are in the same section. Otherwise, both
1066 operands must be absolute. We already handled the case of
1067 addition or subtraction of a constant above. This will
1068 probably need to be changed for an object file format which
1069 supports arbitrary expressions, such as IEEE-695.
1071 Don't emit messages unless we're finalizing the symbol value,
1072 otherwise we may get the same message multiple times. */
1073 if ((op
== O_eq
|| op
== O_ne
)
1074 || ((op
== O_subtract
1075 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1076 && seg_left
== seg_right
1077 && (seg_left
!= undefined_section
1078 || add_symbol
== op_symbol
))
1079 || (seg_left
== absolute_section
1080 && seg_right
== absolute_section
))
1082 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1083 final_seg
= absolute_section
;
1085 else if (finalize_syms
)
1090 if (expr_symbol_where (symp
, &file
, &line
))
1092 if (seg_left
== undefined_section
)
1093 as_bad_where (file
, line
,
1094 _("undefined symbol `%s' in operation"),
1095 S_GET_NAME (symp
->sy_value
.X_add_symbol
));
1096 if (seg_right
== undefined_section
)
1097 as_bad_where (file
, line
,
1098 _("undefined symbol `%s' in operation"),
1099 S_GET_NAME (symp
->sy_value
.X_op_symbol
));
1100 if (seg_left
!= undefined_section
1101 && seg_right
!= undefined_section
)
1102 as_bad_where (file
, line
,
1103 _("invalid section for operation"));
1107 if (seg_left
== undefined_section
)
1108 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1109 S_GET_NAME (symp
->sy_value
.X_add_symbol
),
1111 if (seg_right
== undefined_section
)
1112 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1113 S_GET_NAME (symp
->sy_value
.X_op_symbol
),
1115 if (seg_left
!= undefined_section
1116 && seg_right
!= undefined_section
)
1117 as_bad (_("invalid section for operation setting `%s'"),
1120 /* Prevent the error propagating. */
1121 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1122 final_seg
= absolute_section
;
1125 /* Check for division by zero. */
1126 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1128 /* If seg_right is not absolute_section, then we've
1129 already issued a warning about using a bad symbol. */
1130 if (seg_right
== absolute_section
&& finalize_syms
)
1135 if (expr_symbol_where (symp
, &file
, &line
))
1136 as_bad_where (file
, line
, _("division by zero"));
1138 as_bad (_("division by zero when setting `%s'"),
1145 switch (symp
->sy_value
.X_op
)
1147 case O_multiply
: left
*= right
; break;
1148 case O_divide
: left
/= right
; break;
1149 case O_modulus
: left
%= right
; break;
1150 case O_left_shift
: left
<<= right
; break;
1151 case O_right_shift
: left
>>= right
; break;
1152 case O_bit_inclusive_or
: left
|= right
; break;
1153 case O_bit_or_not
: left
|= ~right
; break;
1154 case O_bit_exclusive_or
: left
^= right
; break;
1155 case O_bit_and
: left
&= right
; break;
1156 case O_add
: left
+= right
; break;
1157 case O_subtract
: left
-= right
; break;
1160 left
= (left
== right
&& seg_left
== seg_right
1161 && (seg_left
!= undefined_section
1162 || add_symbol
== op_symbol
)
1163 ? ~ (offsetT
) 0 : 0);
1164 if (symp
->sy_value
.X_op
== O_ne
)
1167 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1168 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1169 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1170 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1171 case O_logical_and
: left
= left
&& right
; break;
1172 case O_logical_or
: left
= left
|| right
; break;
1176 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1177 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1179 if (seg_left
== undefined_section
1180 || seg_right
== undefined_section
)
1181 final_seg
= undefined_section
;
1182 else if (seg_left
== absolute_section
)
1183 final_seg
= seg_right
;
1185 final_seg
= seg_left
;
1187 resolved
= (symbol_resolved_p (add_symbol
)
1188 && symbol_resolved_p (op_symbol
));
1194 /* Give an error (below) if not in expr_section. We don't
1195 want to worry about expr_section symbols, because they
1196 are fictional (they are created as part of expression
1197 resolution), and any problems may not actually mean
1202 symp
->sy_resolving
= 0;
1206 S_SET_VALUE (symp
, final_val
);
1208 exit_dont_set_value
:
1209 /* Always set the segment, even if not finalizing the value.
1210 The segment is used to determine whether a symbol is defined. */
1211 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1212 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1213 for a stab symbol, so we use this bad hack. */
1214 if (final_seg
!= S_GET_SEGMENT (symp
))
1216 S_SET_SEGMENT (symp
, final_seg
);
1218 /* Don't worry if we can't resolve an expr_section symbol. */
1222 symp
->sy_resolved
= 1;
1223 else if (S_GET_SEGMENT (symp
) != expr_section
)
1225 as_bad (_("can't resolve value for symbol `%s'"),
1227 symp
->sy_resolved
= 1;
1234 #ifdef BFD_ASSEMBLER
1236 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1238 /* A static function passed to hash_traverse. */
1241 resolve_local_symbol (key
, value
)
1242 const char *key ATTRIBUTE_UNUSED
;
1246 resolve_symbol_value (value
);
1251 /* Resolve all local symbols. */
1254 resolve_local_symbol_values ()
1256 #ifdef BFD_ASSEMBLER
1257 hash_traverse (local_hash
, resolve_local_symbol
);
1261 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1262 They are *really* local. That is, they go out of scope whenever we see a
1263 label that isn't local. Also, like fb labels, there can be multiple
1264 instances of a dollar label. Therefor, we name encode each instance with
1265 the instance number, keep a list of defined symbols separate from the real
1266 symbol table, and we treat these buggers as a sparse array. */
1268 static long *dollar_labels
;
1269 static long *dollar_label_instances
;
1270 static char *dollar_label_defines
;
1271 static unsigned long dollar_label_count
;
1272 static unsigned long dollar_label_max
;
1275 dollar_label_defined (label
)
1280 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1282 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1284 return dollar_label_defines
[i
- dollar_labels
];
1286 /* If we get here, label isn't defined. */
1291 dollar_label_instance (label
)
1296 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1298 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1300 return (dollar_label_instances
[i
- dollar_labels
]);
1302 /* If we get here, we haven't seen the label before.
1303 Therefore its instance count is zero. */
1308 dollar_label_clear ()
1310 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1313 #define DOLLAR_LABEL_BUMP_BY 10
1316 define_dollar_label (label
)
1321 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1324 ++dollar_label_instances
[i
- dollar_labels
];
1325 dollar_label_defines
[i
- dollar_labels
] = 1;
1329 /* If we get to here, we don't have label listed yet. */
1331 if (dollar_labels
== NULL
)
1333 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1334 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1335 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1336 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1337 dollar_label_count
= 0;
1339 else if (dollar_label_count
== dollar_label_max
)
1341 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1342 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1343 dollar_label_max
* sizeof (long));
1344 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1345 dollar_label_max
* sizeof (long));
1346 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1347 } /* if we needed to grow */
1349 dollar_labels
[dollar_label_count
] = label
;
1350 dollar_label_instances
[dollar_label_count
] = 1;
1351 dollar_label_defines
[dollar_label_count
] = 1;
1352 ++dollar_label_count
;
1355 /* Caller must copy returned name: we re-use the area for the next name.
1357 The mth occurence of label n: is turned into the symbol "Ln^Am"
1358 where n is the label number and m is the instance number. "L" makes
1359 it a label discarded unless debugging and "^A"('\1') ensures no
1360 ordinary symbol SHOULD get the same name as a local label
1361 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1363 fb labels get the same treatment, except that ^B is used in place
1366 char * /* Return local label name. */
1367 dollar_label_name (n
, augend
)
1368 register long n
; /* we just saw "n$:" : n a number. */
1369 register int augend
; /* 0 for current instance, 1 for new instance. */
1372 /* Returned to caller, then copied. Used for created names ("4f"). */
1373 static char symbol_name_build
[24];
1376 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1379 know (augend
== 0 || augend
== 1);
1380 p
= symbol_name_build
;
1381 #ifdef LOCAL_LABEL_PREFIX
1382 *p
++ = LOCAL_LABEL_PREFIX
;
1386 /* Next code just does sprintf( {}, "%d", n); */
1388 q
= symbol_name_temporary
;
1389 for (*q
++ = 0, i
= n
; i
; ++q
)
1394 while ((*p
= *--q
) != '\0')
1397 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1399 /* Instance number. */
1400 q
= symbol_name_temporary
;
1401 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1406 while ((*p
++ = *--q
) != '\0');;
1408 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1409 return symbol_name_build
;
1412 /* Sombody else's idea of local labels. They are made by "n:" where n
1413 is any decimal digit. Refer to them with
1414 "nb" for previous (backward) n:
1415 or "nf" for next (forward) n:.
1417 We do a little better and let n be any number, not just a single digit, but
1418 since the other guy's assembler only does ten, we treat the first ten
1421 Like someone else's assembler, we have one set of local label counters for
1422 entire assembly, not one set per (sub)segment like in most assemblers. This
1423 implies that one can refer to a label in another segment, and indeed some
1424 crufty compilers have done just that.
1426 Since there could be a LOT of these things, treat them as a sparse
1429 #define FB_LABEL_SPECIAL (10)
1431 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1432 static long *fb_labels
;
1433 static long *fb_label_instances
;
1434 static long fb_label_count
;
1435 static long fb_label_max
;
1437 /* This must be more than FB_LABEL_SPECIAL. */
1438 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1443 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1446 /* Add one to the instance number of this fb label. */
1449 fb_label_instance_inc (label
)
1454 if (label
< FB_LABEL_SPECIAL
)
1456 ++fb_low_counter
[label
];
1460 if (fb_labels
!= NULL
)
1462 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1463 i
< fb_labels
+ fb_label_count
; ++i
)
1467 ++fb_label_instances
[i
- fb_labels
];
1469 } /* if we find it */
1470 } /* for each existing label */
1473 /* If we get to here, we don't have label listed yet. */
1475 if (fb_labels
== NULL
)
1477 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1478 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1479 fb_label_max
= FB_LABEL_BUMP_BY
;
1480 fb_label_count
= FB_LABEL_SPECIAL
;
1483 else if (fb_label_count
== fb_label_max
)
1485 fb_label_max
+= FB_LABEL_BUMP_BY
;
1486 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1487 fb_label_max
* sizeof (long));
1488 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1489 fb_label_max
* sizeof (long));
1490 } /* if we needed to grow */
1492 fb_labels
[fb_label_count
] = label
;
1493 fb_label_instances
[fb_label_count
] = 1;
1498 fb_label_instance (label
)
1503 if (label
< FB_LABEL_SPECIAL
)
1505 return (fb_low_counter
[label
]);
1508 if (fb_labels
!= NULL
)
1510 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1511 i
< fb_labels
+ fb_label_count
; ++i
)
1515 return (fb_label_instances
[i
- fb_labels
]);
1516 } /* if we find it */
1517 } /* for each existing label */
1520 /* We didn't find the label, so this must be a reference to the
1525 /* Caller must copy returned name: we re-use the area for the next name.
1527 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1528 where n is the label number and m is the instance number. "L" makes
1529 it a label discarded unless debugging and "^B"('\2') ensures no
1530 ordinary symbol SHOULD get the same name as a local label
1531 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1533 dollar labels get the same treatment, except that ^A is used in
1536 char * /* Return local label name. */
1537 fb_label_name (n
, augend
)
1538 long n
; /* We just saw "n:", "nf" or "nb" : n a number. */
1539 long augend
; /* 0 for nb, 1 for n:, nf. */
1542 /* Returned to caller, then copied. Used for created names ("4f"). */
1543 static char symbol_name_build
[24];
1546 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1549 know (augend
== 0 || augend
== 1);
1550 p
= symbol_name_build
;
1551 #ifdef LOCAL_LABEL_PREFIX
1552 *p
++ = LOCAL_LABEL_PREFIX
;
1556 /* Next code just does sprintf( {}, "%d", n); */
1558 q
= symbol_name_temporary
;
1559 for (*q
++ = 0, i
= n
; i
; ++q
)
1564 while ((*p
= *--q
) != '\0')
1567 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
1569 /* Instance number. */
1570 q
= symbol_name_temporary
;
1571 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1576 while ((*p
++ = *--q
) != '\0');;
1578 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1579 return (symbol_name_build
);
1582 /* Decode name that may have been generated by foo_label_name() above.
1583 If the name wasn't generated by foo_label_name(), then return it
1584 unaltered. This is used for error messages. */
1587 decode_local_label_name (s
)
1591 char *symbol_decode
;
1593 int instance_number
;
1595 const char *message_format
;
1598 #ifdef LOCAL_LABEL_PREFIX
1599 if (s
[index
] == LOCAL_LABEL_PREFIX
)
1603 if (s
[index
] != 'L')
1606 for (label_number
= 0, p
= s
+ index
+ 1; ISDIGIT (*p
); ++p
)
1607 label_number
= (10 * label_number
) + *p
- '0';
1609 if (*p
== DOLLAR_LABEL_CHAR
)
1611 else if (*p
== LOCAL_LABEL_CHAR
)
1616 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
1617 instance_number
= (10 * instance_number
) + *p
- '0';
1619 message_format
= _("\"%d\" (instance number %d of a %s label)");
1620 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1621 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1623 return symbol_decode
;
1626 /* Get the value of a symbol. */
1632 #ifdef BFD_ASSEMBLER
1633 if (LOCAL_SYMBOL_CHECK (s
))
1634 return resolve_symbol_value (s
);
1637 if (!s
->sy_resolved
)
1639 valueT val
= resolve_symbol_value (s
);
1643 if (s
->sy_value
.X_op
!= O_constant
)
1645 static symbolS
*recur
;
1647 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1648 may call S_GET_VALUE. We use a static symbol to avoid the
1649 immediate recursion. */
1651 return (valueT
) s
->sy_value
.X_add_number
;
1653 if (! s
->sy_resolved
1654 || s
->sy_value
.X_op
!= O_symbol
1655 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1656 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1660 return (valueT
) s
->sy_value
.X_add_number
;
1663 /* Set the value of a symbol. */
1666 S_SET_VALUE (s
, val
)
1670 #ifdef BFD_ASSEMBLER
1671 if (LOCAL_SYMBOL_CHECK (s
))
1673 ((struct local_symbol
*) s
)->lsy_value
= val
;
1678 s
->sy_value
.X_op
= O_constant
;
1679 s
->sy_value
.X_add_number
= (offsetT
) val
;
1680 s
->sy_value
.X_unsigned
= 0;
1684 copy_symbol_attributes (dest
, src
)
1685 symbolS
*dest
, *src
;
1687 if (LOCAL_SYMBOL_CHECK (dest
))
1688 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
1689 if (LOCAL_SYMBOL_CHECK (src
))
1690 src
= local_symbol_convert ((struct local_symbol
*) src
);
1692 #ifdef BFD_ASSEMBLER
1693 /* In an expression, transfer the settings of these flags.
1694 The user can override later, of course. */
1695 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1696 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1699 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1700 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1704 #ifdef BFD_ASSEMBLER
1712 if (LOCAL_SYMBOL_CHECK (s
))
1715 flags
= s
->bsym
->flags
;
1717 return (flags
& BSF_FUNCTION
) != 0;
1726 if (LOCAL_SYMBOL_CHECK (s
))
1729 flags
= s
->bsym
->flags
;
1732 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1735 return (flags
& BSF_GLOBAL
) != 0;
1742 if (LOCAL_SYMBOL_CHECK (s
))
1744 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1751 if (LOCAL_SYMBOL_CHECK (s
))
1753 return bfd_is_com_section (s
->bsym
->section
);
1760 if (LOCAL_SYMBOL_CHECK (s
))
1761 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1762 return s
->bsym
->section
!= undefined_section
;
1769 if (LOCAL_SYMBOL_CHECK (s
))
1771 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1783 if (LOCAL_SYMBOL_CHECK (s
))
1786 flags
= s
->bsym
->flags
;
1789 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1792 if (bfd_get_section (s
->bsym
) == reg_section
)
1795 if (flag_strip_local_absolute
1796 && (flags
& BSF_GLOBAL
) == 0
1797 && bfd_get_section (s
->bsym
) == absolute_section
)
1800 name
= S_GET_NAME (s
);
1801 return (name
!= NULL
1803 && (strchr (name
, DOLLAR_LABEL_CHAR
)
1804 || strchr (name
, LOCAL_LABEL_CHAR
)
1805 || (! flag_keep_locals
1806 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1809 && name
[1] == '?')))));
1816 return S_IS_EXTERNAL (s
);
1823 return S_GET_NAME (s
) == 0;
1830 if (LOCAL_SYMBOL_CHECK (s
))
1831 return ((struct local_symbol
*) s
)->lsy_name
;
1832 return s
->bsym
->name
;
1839 if (LOCAL_SYMBOL_CHECK (s
))
1840 return ((struct local_symbol
*) s
)->lsy_section
;
1841 return s
->bsym
->section
;
1845 S_SET_SEGMENT (s
, seg
)
1849 /* Don't reassign section symbols. The direct reason is to prevent seg
1850 faults assigning back to const global symbols such as *ABS*, but it
1851 shouldn't happen anyway. */
1853 if (LOCAL_SYMBOL_CHECK (s
))
1855 if (seg
== reg_section
)
1856 s
= local_symbol_convert ((struct local_symbol
*) s
);
1859 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1864 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1866 if (s
->bsym
->section
!= seg
)
1870 s
->bsym
->section
= seg
;
1877 if (LOCAL_SYMBOL_CHECK (s
))
1878 s
= local_symbol_convert ((struct local_symbol
*) s
);
1879 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1881 /* Let .weak override .global. */
1884 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1889 /* Do not reassign section symbols. */
1890 as_where (& file
, & line
);
1891 as_warn_where (file
, line
,
1892 _("section symbols are already global"));
1895 s
->bsym
->flags
|= BSF_GLOBAL
;
1896 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
1900 S_CLEAR_EXTERNAL (s
)
1903 if (LOCAL_SYMBOL_CHECK (s
))
1905 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1907 /* Let .weak override. */
1910 s
->bsym
->flags
|= BSF_LOCAL
;
1911 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
1918 if (LOCAL_SYMBOL_CHECK (s
))
1919 s
= local_symbol_convert ((struct local_symbol
*) s
);
1920 s
->bsym
->flags
|= BSF_WEAK
;
1921 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
1925 S_SET_NAME (s
, name
)
1929 if (LOCAL_SYMBOL_CHECK (s
))
1931 ((struct local_symbol
*) s
)->lsy_name
= name
;
1934 s
->bsym
->name
= name
;
1936 #endif /* BFD_ASSEMBLER */
1938 #ifdef SYMBOLS_NEED_BACKPOINTERS
1940 /* Return the previous symbol in a chain. */
1946 if (LOCAL_SYMBOL_CHECK (s
))
1948 return s
->sy_previous
;
1951 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1953 /* Return the next symbol in a chain. */
1959 if (LOCAL_SYMBOL_CHECK (s
))
1964 /* Return a pointer to the value of a symbol as an expression. */
1967 symbol_get_value_expression (s
)
1970 if (LOCAL_SYMBOL_CHECK (s
))
1971 s
= local_symbol_convert ((struct local_symbol
*) s
);
1972 return &s
->sy_value
;
1975 /* Set the value of a symbol to an expression. */
1978 symbol_set_value_expression (s
, exp
)
1980 const expressionS
*exp
;
1982 if (LOCAL_SYMBOL_CHECK (s
))
1983 s
= local_symbol_convert ((struct local_symbol
*) s
);
1987 /* Set the frag of a symbol. */
1990 symbol_set_frag (s
, f
)
1994 #ifdef BFD_ASSEMBLER
1995 if (LOCAL_SYMBOL_CHECK (s
))
1997 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
2004 /* Return the frag of a symbol. */
2010 #ifdef BFD_ASSEMBLER
2011 if (LOCAL_SYMBOL_CHECK (s
))
2012 return local_symbol_get_frag ((struct local_symbol
*) s
);
2017 /* Mark a symbol as having been used. */
2020 symbol_mark_used (s
)
2023 if (LOCAL_SYMBOL_CHECK (s
))
2028 /* Clear the mark of whether a symbol has been used. */
2031 symbol_clear_used (s
)
2034 if (LOCAL_SYMBOL_CHECK (s
))
2035 s
= local_symbol_convert ((struct local_symbol
*) s
);
2039 /* Return whether a symbol has been used. */
2045 if (LOCAL_SYMBOL_CHECK (s
))
2050 /* Mark a symbol as having been used in a reloc. */
2053 symbol_mark_used_in_reloc (s
)
2056 if (LOCAL_SYMBOL_CHECK (s
))
2057 s
= local_symbol_convert ((struct local_symbol
*) s
);
2058 s
->sy_used_in_reloc
= 1;
2061 /* Clear the mark of whether a symbol has been used in a reloc. */
2064 symbol_clear_used_in_reloc (s
)
2067 if (LOCAL_SYMBOL_CHECK (s
))
2069 s
->sy_used_in_reloc
= 0;
2072 /* Return whether a symbol has been used in a reloc. */
2075 symbol_used_in_reloc_p (s
)
2078 if (LOCAL_SYMBOL_CHECK (s
))
2080 return s
->sy_used_in_reloc
;
2083 /* Mark a symbol as an MRI common symbol. */
2086 symbol_mark_mri_common (s
)
2089 if (LOCAL_SYMBOL_CHECK (s
))
2090 s
= local_symbol_convert ((struct local_symbol
*) s
);
2091 s
->sy_mri_common
= 1;
2094 /* Clear the mark of whether a symbol is an MRI common symbol. */
2097 symbol_clear_mri_common (s
)
2100 if (LOCAL_SYMBOL_CHECK (s
))
2102 s
->sy_mri_common
= 0;
2105 /* Return whether a symbol is an MRI common symbol. */
2108 symbol_mri_common_p (s
)
2111 if (LOCAL_SYMBOL_CHECK (s
))
2113 return s
->sy_mri_common
;
2116 /* Mark a symbol as having been written. */
2119 symbol_mark_written (s
)
2122 if (LOCAL_SYMBOL_CHECK (s
))
2127 /* Clear the mark of whether a symbol has been written. */
2130 symbol_clear_written (s
)
2133 if (LOCAL_SYMBOL_CHECK (s
))
2138 /* Return whether a symbol has been written. */
2141 symbol_written_p (s
)
2144 if (LOCAL_SYMBOL_CHECK (s
))
2149 /* Mark a symbol has having been resolved. */
2152 symbol_mark_resolved (s
)
2155 #ifdef BFD_ASSEMBLER
2156 if (LOCAL_SYMBOL_CHECK (s
))
2158 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2165 /* Return whether a symbol has been resolved. */
2168 symbol_resolved_p (s
)
2171 #ifdef BFD_ASSEMBLER
2172 if (LOCAL_SYMBOL_CHECK (s
))
2173 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2175 return s
->sy_resolved
;
2178 /* Return whether a symbol is a section symbol. */
2181 symbol_section_p (s
)
2182 symbolS
*s ATTRIBUTE_UNUSED
;
2184 if (LOCAL_SYMBOL_CHECK (s
))
2186 #ifdef BFD_ASSEMBLER
2187 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2194 /* Return whether a symbol is equated to another symbol. */
2197 symbol_equated_p (s
)
2200 if (LOCAL_SYMBOL_CHECK (s
))
2202 return s
->sy_value
.X_op
== O_symbol
;
2205 /* Return whether a symbol is equated to another symbol, and should be
2206 treated specially when writing out relocs. */
2209 symbol_equated_reloc_p (s
)
2212 if (LOCAL_SYMBOL_CHECK (s
))
2214 /* X_op_symbol, normally not used for O_symbol, is set by
2215 resolve_symbol_value to flag expression syms that have been
2217 return (s
->sy_value
.X_op
== O_symbol
2218 && ((s
->sy_resolved
&& s
->sy_value
.X_op_symbol
!= NULL
)
2219 || ! S_IS_DEFINED (s
)
2220 || S_IS_COMMON (s
)));
2223 /* Return whether a symbol has a constant value. */
2226 symbol_constant_p (s
)
2229 if (LOCAL_SYMBOL_CHECK (s
))
2231 return s
->sy_value
.X_op
== O_constant
;
2234 #ifdef BFD_ASSEMBLER
2236 /* Return the BFD symbol for a symbol. */
2239 symbol_get_bfdsym (s
)
2242 if (LOCAL_SYMBOL_CHECK (s
))
2243 s
= local_symbol_convert ((struct local_symbol
*) s
);
2247 /* Set the BFD symbol for a symbol. */
2250 symbol_set_bfdsym (s
, bsym
)
2254 if (LOCAL_SYMBOL_CHECK (s
))
2255 s
= local_symbol_convert ((struct local_symbol
*) s
);
2259 #endif /* BFD_ASSEMBLER */
2261 #ifdef OBJ_SYMFIELD_TYPE
2263 /* Get a pointer to the object format information for a symbol. */
2269 if (LOCAL_SYMBOL_CHECK (s
))
2270 s
= local_symbol_convert ((struct local_symbol
*) s
);
2274 /* Set the object format information for a symbol. */
2277 symbol_set_obj (s
, o
)
2279 OBJ_SYMFIELD_TYPE
*o
;
2281 if (LOCAL_SYMBOL_CHECK (s
))
2282 s
= local_symbol_convert ((struct local_symbol
*) s
);
2286 #endif /* OBJ_SYMFIELD_TYPE */
2288 #ifdef TC_SYMFIELD_TYPE
2290 /* Get a pointer to the processor information for a symbol. */
2296 if (LOCAL_SYMBOL_CHECK (s
))
2297 s
= local_symbol_convert ((struct local_symbol
*) s
);
2301 /* Set the processor information for a symbol. */
2304 symbol_set_tc (s
, o
)
2306 TC_SYMFIELD_TYPE
*o
;
2308 if (LOCAL_SYMBOL_CHECK (s
))
2309 s
= local_symbol_convert ((struct local_symbol
*) s
);
2313 #endif /* TC_SYMFIELD_TYPE */
2318 symbol_lastP
= NULL
;
2319 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2320 sy_hash
= hash_new ();
2321 #ifdef BFD_ASSEMBLER
2322 local_hash
= hash_new ();
2325 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2326 #ifdef BFD_ASSEMBLER
2327 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2328 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2331 /* Can't initialise a union. Sigh. */
2332 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2334 abs_symbol
.sy_value
.X_op
= O_constant
;
2335 abs_symbol
.sy_frag
= &zero_address_frag
;
2337 if (LOCAL_LABELS_FB
)
2343 /* Maximum indent level.
2344 Available for modification inside a gdb session. */
2345 int max_indent_level
= 8;
2352 printf ("%*s", indent_level
* 4, "");
2358 print_symbol_value_1 (file
, sym
)
2362 const char *name
= S_GET_NAME (sym
);
2363 if (!name
|| !name
[0])
2365 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2367 if (LOCAL_SYMBOL_CHECK (sym
))
2369 #ifdef BFD_ASSEMBLER
2370 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2371 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2372 && local_symbol_get_frag (locsym
) != NULL
)
2373 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2374 if (local_symbol_resolved_p (locsym
))
2375 fprintf (file
, " resolved");
2376 fprintf (file
, " local");
2381 if (sym
->sy_frag
!= &zero_address_frag
)
2382 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2384 fprintf (file
, " written");
2385 if (sym
->sy_resolved
)
2386 fprintf (file
, " resolved");
2387 else if (sym
->sy_resolving
)
2388 fprintf (file
, " resolving");
2389 if (sym
->sy_used_in_reloc
)
2390 fprintf (file
, " used-in-reloc");
2392 fprintf (file
, " used");
2393 if (S_IS_LOCAL (sym
))
2394 fprintf (file
, " local");
2395 if (S_IS_EXTERN (sym
))
2396 fprintf (file
, " extern");
2397 if (S_IS_DEBUG (sym
))
2398 fprintf (file
, " debug");
2399 if (S_IS_DEFINED (sym
))
2400 fprintf (file
, " defined");
2402 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2403 if (symbol_resolved_p (sym
))
2405 segT s
= S_GET_SEGMENT (sym
);
2407 if (s
!= undefined_section
2408 && s
!= expr_section
)
2409 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2411 else if (indent_level
< max_indent_level
2412 && S_GET_SEGMENT (sym
) != undefined_section
)
2415 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2416 #ifdef BFD_ASSEMBLER
2417 if (LOCAL_SYMBOL_CHECK (sym
))
2418 fprintf (file
, "constant %lx",
2419 (long) ((struct local_symbol
*) sym
)->lsy_value
);
2422 print_expr_1 (file
, &sym
->sy_value
);
2423 fprintf (file
, ">");
2430 print_symbol_value (sym
)
2434 print_symbol_value_1 (stderr
, sym
);
2435 fprintf (stderr
, "\n");
2439 print_binary (file
, name
, exp
)
2445 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2446 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2447 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2448 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2449 fprintf (file
, ">");
2454 print_expr_1 (file
, exp
)
2458 fprintf (file
, "expr %lx ", (long) exp
);
2462 fprintf (file
, "illegal");
2465 fprintf (file
, "absent");
2468 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2472 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2473 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2474 fprintf (file
, ">");
2476 if (exp
->X_add_number
)
2477 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2478 (long) exp
->X_add_number
);
2482 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2485 fprintf (file
, "big");
2488 fprintf (file
, "uminus -<");
2490 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2491 fprintf (file
, ">");
2492 goto maybe_print_addnum
;
2494 fprintf (file
, "bit_not");
2497 print_binary (file
, "multiply", exp
);
2500 print_binary (file
, "divide", exp
);
2503 print_binary (file
, "modulus", exp
);
2506 print_binary (file
, "lshift", exp
);
2509 print_binary (file
, "rshift", exp
);
2511 case O_bit_inclusive_or
:
2512 print_binary (file
, "bit_ior", exp
);
2514 case O_bit_exclusive_or
:
2515 print_binary (file
, "bit_xor", exp
);
2518 print_binary (file
, "bit_and", exp
);
2521 print_binary (file
, "eq", exp
);
2524 print_binary (file
, "ne", exp
);
2527 print_binary (file
, "lt", exp
);
2530 print_binary (file
, "le", exp
);
2533 print_binary (file
, "ge", exp
);
2536 print_binary (file
, "gt", exp
);
2539 print_binary (file
, "logical_and", exp
);
2542 print_binary (file
, "logical_or", exp
);
2546 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2547 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2548 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2549 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2550 fprintf (file
, ">");
2551 goto maybe_print_addnum
;
2554 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
2555 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2556 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2557 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2558 fprintf (file
, ">");
2559 goto maybe_print_addnum
;
2561 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2571 print_expr_1 (stderr
, exp
);
2572 fprintf (stderr
, "\n");
2576 symbol_print_statistics (file
)
2579 hash_print_statistics (file
, "symbol table", sy_hash
);
2580 #ifdef BFD_ASSEMBLER
2581 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2582 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2583 local_symbol_count
, local_symbol_conversion_count
);