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
;
317 if (now_seg
== absolute_section
)
319 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
323 possible_bytes
= (md_short_jump_size
324 + new_broken_words
* md_long_jump_size
);
327 frag_opcode
= frag_var (rs_broken_word
,
331 (symbolS
*) broken_words
,
335 /* We want to store the pointer to where to insert the jump
336 table in the fr_opcode of the rs_broken_word frag. This
337 requires a little hackery. */
339 && (frag_tmp
->fr_type
!= rs_broken_word
340 || frag_tmp
->fr_opcode
))
341 frag_tmp
= frag_tmp
->fr_next
;
343 frag_tmp
->fr_opcode
= frag_opcode
;
344 new_broken_words
= 0;
346 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
347 a
->dispfrag
= frag_tmp
;
349 #endif /* WORKING_DOT_WORD */
351 if ((symbolP
= symbol_find (sym_name
)) != 0)
353 #ifdef RESOLVE_SYMBOL_REDEFINITION
354 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
357 /* Now check for undefined symbols. */
358 if (LOCAL_SYMBOL_CHECK (symbolP
))
361 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
363 if (locsym
->lsy_section
!= undefined_section
364 && (local_symbol_get_frag (locsym
) != frag_now
365 || locsym
->lsy_section
!= now_seg
366 || locsym
->lsy_value
!= frag_now_fix ()))
368 as_bad (_("symbol `%s' is already defined"), sym_name
);
372 locsym
->lsy_section
= now_seg
;
373 local_symbol_set_frag (locsym
, frag_now
);
374 locsym
->lsy_value
= frag_now_fix ();
377 else if (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
379 if (S_GET_VALUE (symbolP
) == 0)
381 symbolP
->sy_frag
= frag_now
;
383 S_SET_OTHER (symbolP
, const_flag
);
385 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
386 S_SET_SEGMENT (symbolP
, now_seg
);
389 #endif /* if we have one, it better be zero. */
394 /* There are still several cases to check:
396 A .comm/.lcomm symbol being redefined as initialized
399 A .comm/.lcomm symbol being redefined with a larger
402 This only used to be allowed on VMS gas, but Sun cc
403 on the sparc also depends on it. */
405 if (((!S_IS_DEBUG (symbolP
)
406 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
407 && S_IS_EXTERNAL (symbolP
))
408 || S_GET_SEGMENT (symbolP
) == bss_section
)
409 && (now_seg
== data_section
410 || now_seg
== S_GET_SEGMENT (symbolP
)))
412 /* Select which of the 2 cases this is. */
413 if (now_seg
!= data_section
)
415 /* New .comm for prev .comm symbol.
417 If the new size is larger we just change its
418 value. If the new size is smaller, we ignore
420 if (S_GET_VALUE (symbolP
)
421 < ((unsigned) frag_now_fix ()))
423 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
428 /* It is a .comm/.lcomm being converted to initialized
430 symbolP
->sy_frag
= frag_now
;
432 S_SET_OTHER (symbolP
, const_flag
);
434 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
435 S_SET_SEGMENT (symbolP
, now_seg
); /* Keep N_EXT bit. */
440 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
441 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
442 static const char *od_buf
= "";
447 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
449 sprintf (od_buf
, "%d.%d.",
450 S_GET_OTHER (symbolP
),
451 S_GET_DESC (symbolP
));
453 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
455 segment_name (S_GET_SEGMENT (symbolP
)),
457 (long) S_GET_VALUE (symbolP
));
459 } /* if the undefined symbol has no value */
463 /* Don't blow up if the definition is the same. */
464 if (!(frag_now
== symbolP
->sy_frag
465 && S_GET_VALUE (symbolP
) == frag_now_fix ()
466 && S_GET_SEGMENT (symbolP
) == now_seg
))
467 as_bad (_("symbol `%s' is already defined"), sym_name
);
472 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
474 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
475 (valueT
) frag_now_fix (),
478 #endif /* BFD_ASSEMBLER */
481 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
484 S_SET_OTHER (symbolP
, const_flag
);
487 symbol_table_insert (symbolP
);
490 if (mri_common_symbol
!= NULL
)
492 /* This symbol is actually being defined within an MRI common
493 section. This requires special handling. */
494 if (LOCAL_SYMBOL_CHECK (symbolP
))
495 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
496 symbolP
->sy_value
.X_op
= O_symbol
;
497 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
498 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
499 symbolP
->sy_frag
= &zero_address_frag
;
500 S_SET_SEGMENT (symbolP
, expr_section
);
501 symbolP
->sy_mri_common
= 1;
505 tc_frob_label (symbolP
);
507 #ifdef obj_frob_label
508 obj_frob_label (symbolP
);
514 /* Die if we can't insert the symbol. */
517 symbol_table_insert (symbolP
)
520 register const char *error_string
;
523 know (S_GET_NAME (symbolP
));
525 if (LOCAL_SYMBOL_CHECK (symbolP
))
527 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
529 if (error_string
!= NULL
)
530 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
531 S_GET_NAME (symbolP
), error_string
);
535 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
537 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
538 S_GET_NAME (symbolP
), error_string
);
542 /* If a symbol name does not exist, create it as undefined, and insert
543 it into the symbol table. Return a pointer to it. */
546 symbol_find_or_make (name
)
549 register symbolS
*symbolP
;
551 symbolP
= symbol_find (name
);
556 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
558 symbolP
= md_undefined_symbol ((char *) name
);
562 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
569 symbolP
= symbol_make (name
);
571 symbol_table_insert (symbolP
);
572 } /* if symbol wasn't found */
583 /* Let the machine description default it, e.g. for register names. */
584 symbolP
= md_undefined_symbol ((char *) name
);
587 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
592 /* Implement symbol table lookup.
593 In: A symbol's name as a string: '\0' can't be part of a symbol name.
594 Out: NULL if the name was not in the symbol table, else the address
595 of a struct symbol associated with that name. */
601 #ifdef STRIP_UNDERSCORE
602 return (symbol_find_base (name
, 1));
603 #else /* STRIP_UNDERSCORE */
604 return (symbol_find_base (name
, 0));
605 #endif /* STRIP_UNDERSCORE */
609 symbol_find_exact (name
)
614 struct local_symbol
*locsym
;
616 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
618 return (symbolS
*) locsym
;
622 return ((symbolS
*) hash_find (sy_hash
, name
));
626 symbol_find_base (name
, strip_underscore
)
628 int strip_underscore
;
630 if (strip_underscore
&& *name
== '_')
633 #ifdef tc_canonicalize_symbol_name
636 size_t len
= strlen (name
) + 1;
638 copy
= (char *) alloca (len
);
639 memcpy (copy
, name
, len
);
640 name
= tc_canonicalize_symbol_name (copy
);
644 if (! symbols_case_sensitive
)
651 name
= copy
= (char *) alloca (strlen (name
) + 1);
653 while ((c
= *orig
++) != '\0')
655 *copy
++ = TOUPPER (c
);
660 return symbol_find_exact (name
);
663 /* Once upon a time, symbols were kept in a singly linked list. At
664 least coff needs to be able to rearrange them from time to time, for
665 which a doubly linked list is much more convenient. Loic did these
666 as macros which seemed dangerous to me so they're now functions.
669 /* Link symbol ADDME after symbol TARGET in the chain. */
672 symbol_append (addme
, target
, rootPP
, lastPP
)
678 if (LOCAL_SYMBOL_CHECK (addme
))
680 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
685 know (*rootPP
== NULL
);
686 know (*lastPP
== NULL
);
687 addme
->sy_next
= NULL
;
688 #ifdef SYMBOLS_NEED_BACKPOINTERS
689 addme
->sy_previous
= NULL
;
694 } /* if the list is empty */
696 if (target
->sy_next
!= NULL
)
698 #ifdef SYMBOLS_NEED_BACKPOINTERS
699 target
->sy_next
->sy_previous
= addme
;
700 #endif /* SYMBOLS_NEED_BACKPOINTERS */
704 know (*lastPP
== target
);
706 } /* if we have a next */
708 addme
->sy_next
= target
->sy_next
;
709 target
->sy_next
= addme
;
711 #ifdef SYMBOLS_NEED_BACKPOINTERS
712 addme
->sy_previous
= target
;
713 #endif /* SYMBOLS_NEED_BACKPOINTERS */
715 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
718 /* Set the chain pointers of SYMBOL to null. */
721 symbol_clear_list_pointers (symbolP
)
724 if (LOCAL_SYMBOL_CHECK (symbolP
))
726 symbolP
->sy_next
= NULL
;
727 #ifdef SYMBOLS_NEED_BACKPOINTERS
728 symbolP
->sy_previous
= NULL
;
732 #ifdef SYMBOLS_NEED_BACKPOINTERS
733 /* Remove SYMBOLP from the list. */
736 symbol_remove (symbolP
, rootPP
, lastPP
)
741 if (LOCAL_SYMBOL_CHECK (symbolP
))
744 if (symbolP
== *rootPP
)
746 *rootPP
= symbolP
->sy_next
;
747 } /* if it was the root */
749 if (symbolP
== *lastPP
)
751 *lastPP
= symbolP
->sy_previous
;
752 } /* if it was the tail */
754 if (symbolP
->sy_next
!= NULL
)
756 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
759 if (symbolP
->sy_previous
!= NULL
)
761 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
764 debug_verify_symchain (*rootPP
, *lastPP
);
767 /* Link symbol ADDME before symbol TARGET in the chain. */
770 symbol_insert (addme
, target
, rootPP
, lastPP
)
774 symbolS
**lastPP ATTRIBUTE_UNUSED
;
776 if (LOCAL_SYMBOL_CHECK (addme
))
778 if (LOCAL_SYMBOL_CHECK (target
))
781 if (target
->sy_previous
!= NULL
)
783 target
->sy_previous
->sy_next
= addme
;
787 know (*rootPP
== target
);
791 addme
->sy_previous
= target
->sy_previous
;
792 target
->sy_previous
= addme
;
793 addme
->sy_next
= target
;
795 debug_verify_symchain (*rootPP
, *lastPP
);
798 #endif /* SYMBOLS_NEED_BACKPOINTERS */
801 verify_symbol_chain (rootP
, lastP
)
805 symbolS
*symbolP
= rootP
;
810 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
813 assert (symbolP
->bsym
!= NULL
);
815 #ifdef SYMBOLS_NEED_BACKPOINTERS
816 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
818 /* Walk the list anyways, to make sure pointers are still good. */
820 #endif /* SYMBOLS_NEED_BACKPOINTERS */
823 assert (lastP
== symbolP
);
827 verify_symbol_chain_2 (sym
)
830 symbolS
*p
= sym
, *n
= sym
;
831 #ifdef SYMBOLS_NEED_BACKPOINTERS
832 while (symbol_previous (p
))
833 p
= symbol_previous (p
);
835 while (symbol_next (n
))
837 verify_symbol_chain (p
, n
);
840 /* Resolve the value of a symbol. This is called during the final
841 pass over the symbol table to resolve any symbols with complex
845 resolve_symbol_value (symp
)
849 valueT final_val
= 0;
853 if (LOCAL_SYMBOL_CHECK (symp
))
855 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
857 final_val
= locsym
->lsy_value
;
858 if (local_symbol_resolved_p (locsym
))
861 final_val
+= local_symbol_get_frag (locsym
)->fr_address
/ OCTETS_PER_BYTE
;
865 locsym
->lsy_value
= final_val
;
866 local_symbol_mark_resolved (locsym
);
873 if (symp
->sy_resolved
)
875 if (symp
->sy_value
.X_op
== O_constant
)
876 return (valueT
) symp
->sy_value
.X_add_number
;
882 final_seg
= S_GET_SEGMENT (symp
);
884 if (symp
->sy_resolving
)
887 as_bad (_("symbol definition loop encountered at `%s'"),
894 symbolS
*add_symbol
, *op_symbol
;
896 segT seg_left
, seg_right
;
899 symp
->sy_resolving
= 1;
901 /* Help out with CSE. */
902 add_symbol
= symp
->sy_value
.X_add_symbol
;
903 op_symbol
= symp
->sy_value
.X_op_symbol
;
904 final_val
= symp
->sy_value
.X_add_number
;
905 op
= symp
->sy_value
.X_op
;
918 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
919 if (final_seg
== expr_section
)
920 final_seg
= absolute_section
;
926 left
= resolve_symbol_value (add_symbol
);
927 seg_left
= S_GET_SEGMENT (add_symbol
);
929 symp
->sy_value
.X_op_symbol
= NULL
;
932 if (symp
->sy_mri_common
)
934 /* This is a symbol inside an MRI common section. The
935 relocation routines are going to handle it specially.
936 Don't change the value. */
937 resolved
= symbol_resolved_p (add_symbol
);
941 if (finalize_syms
&& final_val
== 0)
943 if (LOCAL_SYMBOL_CHECK (add_symbol
))
944 add_symbol
= local_symbol_convert ((struct local_symbol
*)
946 copy_symbol_attributes (symp
, add_symbol
);
949 /* If we have equated this symbol to an undefined or common
950 symbol, keep X_op set to O_symbol, and don't change
951 X_add_number. This permits the routine which writes out
952 relocation to detect this case, and convert the
953 relocation to be against the symbol to which this symbol
955 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
959 symp
->sy_value
.X_op
= O_symbol
;
960 symp
->sy_value
.X_add_symbol
= add_symbol
;
961 symp
->sy_value
.X_add_number
= final_val
;
962 /* Use X_op_symbol as a flag. */
963 symp
->sy_value
.X_op_symbol
= add_symbol
;
964 final_seg
= seg_left
;
967 resolved
= symbol_resolved_p (add_symbol
);
968 symp
->sy_resolving
= 0;
969 goto exit_dont_set_value
;
971 else if (finalize_syms
&& final_seg
== expr_section
972 && seg_left
!= expr_section
)
974 /* If the symbol is an expression symbol, do similarly
975 as for undefined and common syms above. Handles
976 "sym +/- expr" where "expr" cannot be evaluated
977 immediately, and we want relocations to be against
978 "sym", eg. because it is weak. */
979 symp
->sy_value
.X_op
= O_symbol
;
980 symp
->sy_value
.X_add_symbol
= add_symbol
;
981 symp
->sy_value
.X_add_number
= final_val
;
982 symp
->sy_value
.X_op_symbol
= add_symbol
;
983 final_seg
= seg_left
;
984 final_val
+= symp
->sy_frag
->fr_address
+ left
;
985 resolved
= symbol_resolved_p (add_symbol
);
986 symp
->sy_resolving
= 0;
987 goto exit_dont_set_value
;
991 final_val
+= symp
->sy_frag
->fr_address
+ left
;
992 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
993 final_seg
= seg_left
;
996 resolved
= symbol_resolved_p (add_symbol
);
1002 left
= resolve_symbol_value (add_symbol
);
1003 seg_left
= S_GET_SEGMENT (add_symbol
);
1007 else if (op
== O_logical_not
)
1012 final_val
+= left
+ symp
->sy_frag
->fr_address
;
1013 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1014 final_seg
= seg_left
;
1016 resolved
= symbol_resolved_p (add_symbol
);
1024 case O_bit_inclusive_or
:
1026 case O_bit_exclusive_or
:
1038 left
= resolve_symbol_value (add_symbol
);
1039 right
= resolve_symbol_value (op_symbol
);
1040 seg_left
= S_GET_SEGMENT (add_symbol
);
1041 seg_right
= S_GET_SEGMENT (op_symbol
);
1043 /* Simplify addition or subtraction of a constant by folding the
1044 constant into X_add_number. */
1047 if (seg_right
== absolute_section
)
1052 else if (seg_left
== absolute_section
)
1055 add_symbol
= op_symbol
;
1057 seg_left
= seg_right
;
1061 else if (op
== O_subtract
)
1063 if (seg_right
== absolute_section
)
1070 /* Equality and non-equality tests are permitted on anything.
1071 Subtraction, and other comparison operators are permitted if
1072 both operands are in the same section. Otherwise, both
1073 operands must be absolute. We already handled the case of
1074 addition or subtraction of a constant above. This will
1075 probably need to be changed for an object file format which
1076 supports arbitrary expressions, such as IEEE-695.
1078 Don't emit messages unless we're finalizing the symbol value,
1079 otherwise we may get the same message multiple times. */
1080 if ((op
== O_eq
|| op
== O_ne
)
1081 || ((op
== O_subtract
1082 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1083 && seg_left
== seg_right
1084 && (seg_left
!= undefined_section
1085 || add_symbol
== op_symbol
))
1086 || (seg_left
== absolute_section
1087 && seg_right
== absolute_section
))
1089 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1090 final_seg
= absolute_section
;
1092 else if (finalize_syms
)
1097 if (expr_symbol_where (symp
, &file
, &line
))
1099 if (seg_left
== undefined_section
)
1100 as_bad_where (file
, line
,
1101 _("undefined symbol `%s' in operation"),
1102 S_GET_NAME (symp
->sy_value
.X_add_symbol
));
1103 if (seg_right
== undefined_section
)
1104 as_bad_where (file
, line
,
1105 _("undefined symbol `%s' in operation"),
1106 S_GET_NAME (symp
->sy_value
.X_op_symbol
));
1107 if (seg_left
!= undefined_section
1108 && seg_right
!= undefined_section
)
1109 as_bad_where (file
, line
,
1110 _("invalid section for operation"));
1114 if (seg_left
== undefined_section
)
1115 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1116 S_GET_NAME (symp
->sy_value
.X_add_symbol
),
1118 if (seg_right
== undefined_section
)
1119 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1120 S_GET_NAME (symp
->sy_value
.X_op_symbol
),
1122 if (seg_left
!= undefined_section
1123 && seg_right
!= undefined_section
)
1124 as_bad (_("invalid section for operation setting `%s'"),
1127 /* Prevent the error propagating. */
1128 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1129 final_seg
= absolute_section
;
1132 /* Check for division by zero. */
1133 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1135 /* If seg_right is not absolute_section, then we've
1136 already issued a warning about using a bad symbol. */
1137 if (seg_right
== absolute_section
&& finalize_syms
)
1142 if (expr_symbol_where (symp
, &file
, &line
))
1143 as_bad_where (file
, line
, _("division by zero"));
1145 as_bad (_("division by zero when setting `%s'"),
1152 switch (symp
->sy_value
.X_op
)
1154 case O_multiply
: left
*= right
; break;
1155 case O_divide
: left
/= right
; break;
1156 case O_modulus
: left
%= right
; break;
1157 case O_left_shift
: left
<<= right
; break;
1158 case O_right_shift
: left
>>= right
; break;
1159 case O_bit_inclusive_or
: left
|= right
; break;
1160 case O_bit_or_not
: left
|= ~right
; break;
1161 case O_bit_exclusive_or
: left
^= right
; break;
1162 case O_bit_and
: left
&= right
; break;
1163 case O_add
: left
+= right
; break;
1164 case O_subtract
: left
-= right
; break;
1167 left
= (left
== right
&& seg_left
== seg_right
1168 && (seg_left
!= undefined_section
1169 || add_symbol
== op_symbol
)
1170 ? ~ (offsetT
) 0 : 0);
1171 if (symp
->sy_value
.X_op
== O_ne
)
1174 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1175 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1176 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1177 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1178 case O_logical_and
: left
= left
&& right
; break;
1179 case O_logical_or
: left
= left
|| right
; break;
1183 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1184 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1186 if (seg_left
== undefined_section
1187 || seg_right
== undefined_section
)
1188 final_seg
= undefined_section
;
1189 else if (seg_left
== absolute_section
)
1190 final_seg
= seg_right
;
1192 final_seg
= seg_left
;
1194 resolved
= (symbol_resolved_p (add_symbol
)
1195 && symbol_resolved_p (op_symbol
));
1201 /* Give an error (below) if not in expr_section. We don't
1202 want to worry about expr_section symbols, because they
1203 are fictional (they are created as part of expression
1204 resolution), and any problems may not actually mean
1209 symp
->sy_resolving
= 0;
1213 S_SET_VALUE (symp
, final_val
);
1215 exit_dont_set_value
:
1216 /* Always set the segment, even if not finalizing the value.
1217 The segment is used to determine whether a symbol is defined. */
1218 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1219 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1220 for a stab symbol, so we use this bad hack. */
1221 if (final_seg
!= S_GET_SEGMENT (symp
))
1223 S_SET_SEGMENT (symp
, final_seg
);
1225 /* Don't worry if we can't resolve an expr_section symbol. */
1229 symp
->sy_resolved
= 1;
1230 else if (S_GET_SEGMENT (symp
) != expr_section
)
1232 as_bad (_("can't resolve value for symbol `%s'"),
1234 symp
->sy_resolved
= 1;
1241 #ifdef BFD_ASSEMBLER
1243 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1245 /* A static function passed to hash_traverse. */
1248 resolve_local_symbol (key
, value
)
1249 const char *key ATTRIBUTE_UNUSED
;
1253 resolve_symbol_value (value
);
1258 /* Resolve all local symbols. */
1261 resolve_local_symbol_values ()
1263 #ifdef BFD_ASSEMBLER
1264 hash_traverse (local_hash
, resolve_local_symbol
);
1268 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1269 They are *really* local. That is, they go out of scope whenever we see a
1270 label that isn't local. Also, like fb labels, there can be multiple
1271 instances of a dollar label. Therefor, we name encode each instance with
1272 the instance number, keep a list of defined symbols separate from the real
1273 symbol table, and we treat these buggers as a sparse array. */
1275 static long *dollar_labels
;
1276 static long *dollar_label_instances
;
1277 static char *dollar_label_defines
;
1278 static unsigned long dollar_label_count
;
1279 static unsigned long dollar_label_max
;
1282 dollar_label_defined (label
)
1287 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1289 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1291 return dollar_label_defines
[i
- dollar_labels
];
1293 /* If we get here, label isn't defined. */
1298 dollar_label_instance (label
)
1303 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1305 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1307 return (dollar_label_instances
[i
- dollar_labels
]);
1309 /* If we get here, we haven't seen the label before.
1310 Therefore its instance count is zero. */
1315 dollar_label_clear ()
1317 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1320 #define DOLLAR_LABEL_BUMP_BY 10
1323 define_dollar_label (label
)
1328 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1331 ++dollar_label_instances
[i
- dollar_labels
];
1332 dollar_label_defines
[i
- dollar_labels
] = 1;
1336 /* If we get to here, we don't have label listed yet. */
1338 if (dollar_labels
== NULL
)
1340 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1341 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1342 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1343 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1344 dollar_label_count
= 0;
1346 else if (dollar_label_count
== dollar_label_max
)
1348 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1349 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1350 dollar_label_max
* sizeof (long));
1351 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1352 dollar_label_max
* sizeof (long));
1353 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1354 } /* if we needed to grow */
1356 dollar_labels
[dollar_label_count
] = label
;
1357 dollar_label_instances
[dollar_label_count
] = 1;
1358 dollar_label_defines
[dollar_label_count
] = 1;
1359 ++dollar_label_count
;
1362 /* Caller must copy returned name: we re-use the area for the next name.
1364 The mth occurence of label n: is turned into the symbol "Ln^Am"
1365 where n is the label number and m is the instance number. "L" makes
1366 it a label discarded unless debugging and "^A"('\1') ensures no
1367 ordinary symbol SHOULD get the same name as a local label
1368 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1370 fb labels get the same treatment, except that ^B is used in place
1373 char * /* Return local label name. */
1374 dollar_label_name (n
, augend
)
1375 register long n
; /* we just saw "n$:" : n a number. */
1376 register int augend
; /* 0 for current instance, 1 for new instance. */
1379 /* Returned to caller, then copied. Used for created names ("4f"). */
1380 static char symbol_name_build
[24];
1383 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1386 know (augend
== 0 || augend
== 1);
1387 p
= symbol_name_build
;
1388 #ifdef LOCAL_LABEL_PREFIX
1389 *p
++ = LOCAL_LABEL_PREFIX
;
1393 /* Next code just does sprintf( {}, "%d", n); */
1395 q
= symbol_name_temporary
;
1396 for (*q
++ = 0, i
= n
; i
; ++q
)
1401 while ((*p
= *--q
) != '\0')
1404 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1406 /* Instance number. */
1407 q
= symbol_name_temporary
;
1408 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1413 while ((*p
++ = *--q
) != '\0');;
1415 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1416 return symbol_name_build
;
1419 /* Sombody else's idea of local labels. They are made by "n:" where n
1420 is any decimal digit. Refer to them with
1421 "nb" for previous (backward) n:
1422 or "nf" for next (forward) n:.
1424 We do a little better and let n be any number, not just a single digit, but
1425 since the other guy's assembler only does ten, we treat the first ten
1428 Like someone else's assembler, we have one set of local label counters for
1429 entire assembly, not one set per (sub)segment like in most assemblers. This
1430 implies that one can refer to a label in another segment, and indeed some
1431 crufty compilers have done just that.
1433 Since there could be a LOT of these things, treat them as a sparse
1436 #define FB_LABEL_SPECIAL (10)
1438 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1439 static long *fb_labels
;
1440 static long *fb_label_instances
;
1441 static long fb_label_count
;
1442 static long fb_label_max
;
1444 /* This must be more than FB_LABEL_SPECIAL. */
1445 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1450 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1453 /* Add one to the instance number of this fb label. */
1456 fb_label_instance_inc (label
)
1461 if (label
< FB_LABEL_SPECIAL
)
1463 ++fb_low_counter
[label
];
1467 if (fb_labels
!= NULL
)
1469 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1470 i
< fb_labels
+ fb_label_count
; ++i
)
1474 ++fb_label_instances
[i
- fb_labels
];
1476 } /* if we find it */
1477 } /* for each existing label */
1480 /* If we get to here, we don't have label listed yet. */
1482 if (fb_labels
== NULL
)
1484 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1485 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1486 fb_label_max
= FB_LABEL_BUMP_BY
;
1487 fb_label_count
= FB_LABEL_SPECIAL
;
1490 else if (fb_label_count
== fb_label_max
)
1492 fb_label_max
+= FB_LABEL_BUMP_BY
;
1493 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1494 fb_label_max
* sizeof (long));
1495 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1496 fb_label_max
* sizeof (long));
1497 } /* if we needed to grow */
1499 fb_labels
[fb_label_count
] = label
;
1500 fb_label_instances
[fb_label_count
] = 1;
1505 fb_label_instance (label
)
1510 if (label
< FB_LABEL_SPECIAL
)
1512 return (fb_low_counter
[label
]);
1515 if (fb_labels
!= NULL
)
1517 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1518 i
< fb_labels
+ fb_label_count
; ++i
)
1522 return (fb_label_instances
[i
- fb_labels
]);
1523 } /* if we find it */
1524 } /* for each existing label */
1527 /* We didn't find the label, so this must be a reference to the
1532 /* Caller must copy returned name: we re-use the area for the next name.
1534 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1535 where n is the label number and m is the instance number. "L" makes
1536 it a label discarded unless debugging and "^B"('\2') ensures no
1537 ordinary symbol SHOULD get the same name as a local label
1538 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1540 dollar labels get the same treatment, except that ^A is used in
1543 char * /* Return local label name. */
1544 fb_label_name (n
, augend
)
1545 long n
; /* We just saw "n:", "nf" or "nb" : n a number. */
1546 long augend
; /* 0 for nb, 1 for n:, nf. */
1549 /* Returned to caller, then copied. Used for created names ("4f"). */
1550 static char symbol_name_build
[24];
1553 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1556 know (augend
== 0 || augend
== 1);
1557 p
= symbol_name_build
;
1558 #ifdef LOCAL_LABEL_PREFIX
1559 *p
++ = LOCAL_LABEL_PREFIX
;
1563 /* Next code just does sprintf( {}, "%d", n); */
1565 q
= symbol_name_temporary
;
1566 for (*q
++ = 0, i
= n
; i
; ++q
)
1571 while ((*p
= *--q
) != '\0')
1574 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
1576 /* Instance number. */
1577 q
= symbol_name_temporary
;
1578 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1583 while ((*p
++ = *--q
) != '\0');;
1585 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1586 return (symbol_name_build
);
1589 /* Decode name that may have been generated by foo_label_name() above.
1590 If the name wasn't generated by foo_label_name(), then return it
1591 unaltered. This is used for error messages. */
1594 decode_local_label_name (s
)
1598 char *symbol_decode
;
1600 int instance_number
;
1602 const char *message_format
;
1605 #ifdef LOCAL_LABEL_PREFIX
1606 if (s
[index
] == LOCAL_LABEL_PREFIX
)
1610 if (s
[index
] != 'L')
1613 for (label_number
= 0, p
= s
+ index
+ 1; ISDIGIT (*p
); ++p
)
1614 label_number
= (10 * label_number
) + *p
- '0';
1616 if (*p
== DOLLAR_LABEL_CHAR
)
1618 else if (*p
== LOCAL_LABEL_CHAR
)
1623 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
1624 instance_number
= (10 * instance_number
) + *p
- '0';
1626 message_format
= _("\"%d\" (instance number %d of a %s label)");
1627 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1628 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1630 return symbol_decode
;
1633 /* Get the value of a symbol. */
1639 #ifdef BFD_ASSEMBLER
1640 if (LOCAL_SYMBOL_CHECK (s
))
1641 return resolve_symbol_value (s
);
1644 if (!s
->sy_resolved
)
1646 valueT val
= resolve_symbol_value (s
);
1650 if (s
->sy_value
.X_op
!= O_constant
)
1652 static symbolS
*recur
;
1654 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1655 may call S_GET_VALUE. We use a static symbol to avoid the
1656 immediate recursion. */
1658 return (valueT
) s
->sy_value
.X_add_number
;
1660 if (! s
->sy_resolved
1661 || s
->sy_value
.X_op
!= O_symbol
1662 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1663 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1667 return (valueT
) s
->sy_value
.X_add_number
;
1670 /* Set the value of a symbol. */
1673 S_SET_VALUE (s
, val
)
1677 #ifdef BFD_ASSEMBLER
1678 if (LOCAL_SYMBOL_CHECK (s
))
1680 ((struct local_symbol
*) s
)->lsy_value
= val
;
1685 s
->sy_value
.X_op
= O_constant
;
1686 s
->sy_value
.X_add_number
= (offsetT
) val
;
1687 s
->sy_value
.X_unsigned
= 0;
1691 copy_symbol_attributes (dest
, src
)
1692 symbolS
*dest
, *src
;
1694 if (LOCAL_SYMBOL_CHECK (dest
))
1695 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
1696 if (LOCAL_SYMBOL_CHECK (src
))
1697 src
= local_symbol_convert ((struct local_symbol
*) src
);
1699 #ifdef BFD_ASSEMBLER
1700 /* In an expression, transfer the settings of these flags.
1701 The user can override later, of course. */
1702 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1703 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1706 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1707 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1711 #ifdef BFD_ASSEMBLER
1719 if (LOCAL_SYMBOL_CHECK (s
))
1722 flags
= s
->bsym
->flags
;
1724 return (flags
& BSF_FUNCTION
) != 0;
1733 if (LOCAL_SYMBOL_CHECK (s
))
1736 flags
= s
->bsym
->flags
;
1739 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1742 return (flags
& BSF_GLOBAL
) != 0;
1749 if (LOCAL_SYMBOL_CHECK (s
))
1751 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1758 if (LOCAL_SYMBOL_CHECK (s
))
1760 return bfd_is_com_section (s
->bsym
->section
);
1767 if (LOCAL_SYMBOL_CHECK (s
))
1768 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1769 return s
->bsym
->section
!= undefined_section
;
1773 #ifndef EXTERN_FORCE_RELOC
1774 #define EXTERN_FORCE_RELOC IS_ELF
1777 /* Return true for symbols that should not be reduced to section
1778 symbols or eliminated from expressions, because they may be
1779 overridden by the linker. */
1784 if (LOCAL_SYMBOL_CHECK (s
))
1785 return ((struct local_symbol
*) s
)->lsy_section
== undefined_section
;
1787 return ((s
->bsym
->flags
& BSF_WEAK
) != 0
1788 || (EXTERN_FORCE_RELOC
1789 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)
1790 || s
->bsym
->section
== undefined_section
1791 || bfd_is_com_section (s
->bsym
->section
));
1798 if (LOCAL_SYMBOL_CHECK (s
))
1800 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1812 if (LOCAL_SYMBOL_CHECK (s
))
1815 flags
= s
->bsym
->flags
;
1818 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1821 if (bfd_get_section (s
->bsym
) == reg_section
)
1824 if (flag_strip_local_absolute
1825 && (flags
& BSF_GLOBAL
) == 0
1826 && bfd_get_section (s
->bsym
) == absolute_section
)
1829 name
= S_GET_NAME (s
);
1830 return (name
!= NULL
1832 && (strchr (name
, DOLLAR_LABEL_CHAR
)
1833 || strchr (name
, LOCAL_LABEL_CHAR
)
1834 || (! flag_keep_locals
1835 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1838 && name
[1] == '?')))));
1845 return S_IS_EXTERNAL (s
);
1852 return S_GET_NAME (s
) == 0;
1859 if (LOCAL_SYMBOL_CHECK (s
))
1860 return ((struct local_symbol
*) s
)->lsy_name
;
1861 return s
->bsym
->name
;
1868 if (LOCAL_SYMBOL_CHECK (s
))
1869 return ((struct local_symbol
*) s
)->lsy_section
;
1870 return s
->bsym
->section
;
1874 S_SET_SEGMENT (s
, seg
)
1878 /* Don't reassign section symbols. The direct reason is to prevent seg
1879 faults assigning back to const global symbols such as *ABS*, but it
1880 shouldn't happen anyway. */
1882 if (LOCAL_SYMBOL_CHECK (s
))
1884 if (seg
== reg_section
)
1885 s
= local_symbol_convert ((struct local_symbol
*) s
);
1888 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1893 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1895 if (s
->bsym
->section
!= seg
)
1899 s
->bsym
->section
= seg
;
1906 if (LOCAL_SYMBOL_CHECK (s
))
1907 s
= local_symbol_convert ((struct local_symbol
*) s
);
1908 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1910 /* Let .weak override .global. */
1913 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1918 /* Do not reassign section symbols. */
1919 as_where (& file
, & line
);
1920 as_warn_where (file
, line
,
1921 _("section symbols are already global"));
1924 s
->bsym
->flags
|= BSF_GLOBAL
;
1925 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
1929 S_CLEAR_EXTERNAL (s
)
1932 if (LOCAL_SYMBOL_CHECK (s
))
1934 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1936 /* Let .weak override. */
1939 s
->bsym
->flags
|= BSF_LOCAL
;
1940 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
1947 if (LOCAL_SYMBOL_CHECK (s
))
1948 s
= local_symbol_convert ((struct local_symbol
*) s
);
1949 s
->bsym
->flags
|= BSF_WEAK
;
1950 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
1954 S_SET_NAME (s
, name
)
1958 if (LOCAL_SYMBOL_CHECK (s
))
1960 ((struct local_symbol
*) s
)->lsy_name
= name
;
1963 s
->bsym
->name
= name
;
1965 #endif /* BFD_ASSEMBLER */
1967 #ifdef SYMBOLS_NEED_BACKPOINTERS
1969 /* Return the previous symbol in a chain. */
1975 if (LOCAL_SYMBOL_CHECK (s
))
1977 return s
->sy_previous
;
1980 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1982 /* Return the next symbol in a chain. */
1988 if (LOCAL_SYMBOL_CHECK (s
))
1993 /* Return a pointer to the value of a symbol as an expression. */
1996 symbol_get_value_expression (s
)
1999 if (LOCAL_SYMBOL_CHECK (s
))
2000 s
= local_symbol_convert ((struct local_symbol
*) s
);
2001 return &s
->sy_value
;
2004 /* Set the value of a symbol to an expression. */
2007 symbol_set_value_expression (s
, exp
)
2009 const expressionS
*exp
;
2011 if (LOCAL_SYMBOL_CHECK (s
))
2012 s
= local_symbol_convert ((struct local_symbol
*) s
);
2016 /* Set the frag of a symbol. */
2019 symbol_set_frag (s
, f
)
2023 #ifdef BFD_ASSEMBLER
2024 if (LOCAL_SYMBOL_CHECK (s
))
2026 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
2033 /* Return the frag of a symbol. */
2039 #ifdef BFD_ASSEMBLER
2040 if (LOCAL_SYMBOL_CHECK (s
))
2041 return local_symbol_get_frag ((struct local_symbol
*) s
);
2046 /* Mark a symbol as having been used. */
2049 symbol_mark_used (s
)
2052 if (LOCAL_SYMBOL_CHECK (s
))
2057 /* Clear the mark of whether a symbol has been used. */
2060 symbol_clear_used (s
)
2063 if (LOCAL_SYMBOL_CHECK (s
))
2064 s
= local_symbol_convert ((struct local_symbol
*) s
);
2068 /* Return whether a symbol has been used. */
2074 if (LOCAL_SYMBOL_CHECK (s
))
2079 /* Mark a symbol as having been used in a reloc. */
2082 symbol_mark_used_in_reloc (s
)
2085 if (LOCAL_SYMBOL_CHECK (s
))
2086 s
= local_symbol_convert ((struct local_symbol
*) s
);
2087 s
->sy_used_in_reloc
= 1;
2090 /* Clear the mark of whether a symbol has been used in a reloc. */
2093 symbol_clear_used_in_reloc (s
)
2096 if (LOCAL_SYMBOL_CHECK (s
))
2098 s
->sy_used_in_reloc
= 0;
2101 /* Return whether a symbol has been used in a reloc. */
2104 symbol_used_in_reloc_p (s
)
2107 if (LOCAL_SYMBOL_CHECK (s
))
2109 return s
->sy_used_in_reloc
;
2112 /* Mark a symbol as an MRI common symbol. */
2115 symbol_mark_mri_common (s
)
2118 if (LOCAL_SYMBOL_CHECK (s
))
2119 s
= local_symbol_convert ((struct local_symbol
*) s
);
2120 s
->sy_mri_common
= 1;
2123 /* Clear the mark of whether a symbol is an MRI common symbol. */
2126 symbol_clear_mri_common (s
)
2129 if (LOCAL_SYMBOL_CHECK (s
))
2131 s
->sy_mri_common
= 0;
2134 /* Return whether a symbol is an MRI common symbol. */
2137 symbol_mri_common_p (s
)
2140 if (LOCAL_SYMBOL_CHECK (s
))
2142 return s
->sy_mri_common
;
2145 /* Mark a symbol as having been written. */
2148 symbol_mark_written (s
)
2151 if (LOCAL_SYMBOL_CHECK (s
))
2156 /* Clear the mark of whether a symbol has been written. */
2159 symbol_clear_written (s
)
2162 if (LOCAL_SYMBOL_CHECK (s
))
2167 /* Return whether a symbol has been written. */
2170 symbol_written_p (s
)
2173 if (LOCAL_SYMBOL_CHECK (s
))
2178 /* Mark a symbol has having been resolved. */
2181 symbol_mark_resolved (s
)
2184 #ifdef BFD_ASSEMBLER
2185 if (LOCAL_SYMBOL_CHECK (s
))
2187 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2194 /* Return whether a symbol has been resolved. */
2197 symbol_resolved_p (s
)
2200 #ifdef BFD_ASSEMBLER
2201 if (LOCAL_SYMBOL_CHECK (s
))
2202 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2204 return s
->sy_resolved
;
2207 /* Return whether a symbol is a section symbol. */
2210 symbol_section_p (s
)
2211 symbolS
*s ATTRIBUTE_UNUSED
;
2213 if (LOCAL_SYMBOL_CHECK (s
))
2215 #ifdef BFD_ASSEMBLER
2216 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2223 /* Return whether a symbol is equated to another symbol. */
2226 symbol_equated_p (s
)
2229 if (LOCAL_SYMBOL_CHECK (s
))
2231 return s
->sy_value
.X_op
== O_symbol
;
2234 /* Return whether a symbol is equated to another symbol, and should be
2235 treated specially when writing out relocs. */
2238 symbol_equated_reloc_p (s
)
2241 if (LOCAL_SYMBOL_CHECK (s
))
2243 /* X_op_symbol, normally not used for O_symbol, is set by
2244 resolve_symbol_value to flag expression syms that have been
2246 return (s
->sy_value
.X_op
== O_symbol
2247 && ((s
->sy_resolved
&& s
->sy_value
.X_op_symbol
!= NULL
)
2248 || ! S_IS_DEFINED (s
)
2249 || S_IS_COMMON (s
)));
2252 /* Return whether a symbol has a constant value. */
2255 symbol_constant_p (s
)
2258 if (LOCAL_SYMBOL_CHECK (s
))
2260 return s
->sy_value
.X_op
== O_constant
;
2263 #ifdef BFD_ASSEMBLER
2265 /* Return the BFD symbol for a symbol. */
2268 symbol_get_bfdsym (s
)
2271 if (LOCAL_SYMBOL_CHECK (s
))
2272 s
= local_symbol_convert ((struct local_symbol
*) s
);
2276 /* Set the BFD symbol for a symbol. */
2279 symbol_set_bfdsym (s
, bsym
)
2283 if (LOCAL_SYMBOL_CHECK (s
))
2284 s
= local_symbol_convert ((struct local_symbol
*) s
);
2288 #endif /* BFD_ASSEMBLER */
2290 #ifdef OBJ_SYMFIELD_TYPE
2292 /* Get a pointer to the object format information for a symbol. */
2298 if (LOCAL_SYMBOL_CHECK (s
))
2299 s
= local_symbol_convert ((struct local_symbol
*) s
);
2303 /* Set the object format information for a symbol. */
2306 symbol_set_obj (s
, o
)
2308 OBJ_SYMFIELD_TYPE
*o
;
2310 if (LOCAL_SYMBOL_CHECK (s
))
2311 s
= local_symbol_convert ((struct local_symbol
*) s
);
2315 #endif /* OBJ_SYMFIELD_TYPE */
2317 #ifdef TC_SYMFIELD_TYPE
2319 /* Get a pointer to the processor information for a symbol. */
2325 if (LOCAL_SYMBOL_CHECK (s
))
2326 s
= local_symbol_convert ((struct local_symbol
*) s
);
2330 /* Set the processor information for a symbol. */
2333 symbol_set_tc (s
, o
)
2335 TC_SYMFIELD_TYPE
*o
;
2337 if (LOCAL_SYMBOL_CHECK (s
))
2338 s
= local_symbol_convert ((struct local_symbol
*) s
);
2342 #endif /* TC_SYMFIELD_TYPE */
2347 symbol_lastP
= NULL
;
2348 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2349 sy_hash
= hash_new ();
2350 #ifdef BFD_ASSEMBLER
2351 local_hash
= hash_new ();
2354 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2355 #ifdef BFD_ASSEMBLER
2356 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2357 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2360 /* Can't initialise a union. Sigh. */
2361 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2363 abs_symbol
.sy_value
.X_op
= O_constant
;
2364 abs_symbol
.sy_frag
= &zero_address_frag
;
2366 if (LOCAL_LABELS_FB
)
2372 /* Maximum indent level.
2373 Available for modification inside a gdb session. */
2374 int max_indent_level
= 8;
2381 printf ("%*s", indent_level
* 4, "");
2387 print_symbol_value_1 (file
, sym
)
2391 const char *name
= S_GET_NAME (sym
);
2392 if (!name
|| !name
[0])
2394 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2396 if (LOCAL_SYMBOL_CHECK (sym
))
2398 #ifdef BFD_ASSEMBLER
2399 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2400 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2401 && local_symbol_get_frag (locsym
) != NULL
)
2402 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2403 if (local_symbol_resolved_p (locsym
))
2404 fprintf (file
, " resolved");
2405 fprintf (file
, " local");
2410 if (sym
->sy_frag
!= &zero_address_frag
)
2411 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2413 fprintf (file
, " written");
2414 if (sym
->sy_resolved
)
2415 fprintf (file
, " resolved");
2416 else if (sym
->sy_resolving
)
2417 fprintf (file
, " resolving");
2418 if (sym
->sy_used_in_reloc
)
2419 fprintf (file
, " used-in-reloc");
2421 fprintf (file
, " used");
2422 if (S_IS_LOCAL (sym
))
2423 fprintf (file
, " local");
2424 if (S_IS_EXTERN (sym
))
2425 fprintf (file
, " extern");
2426 if (S_IS_DEBUG (sym
))
2427 fprintf (file
, " debug");
2428 if (S_IS_DEFINED (sym
))
2429 fprintf (file
, " defined");
2431 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2432 if (symbol_resolved_p (sym
))
2434 segT s
= S_GET_SEGMENT (sym
);
2436 if (s
!= undefined_section
2437 && s
!= expr_section
)
2438 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2440 else if (indent_level
< max_indent_level
2441 && S_GET_SEGMENT (sym
) != undefined_section
)
2444 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2445 #ifdef BFD_ASSEMBLER
2446 if (LOCAL_SYMBOL_CHECK (sym
))
2447 fprintf (file
, "constant %lx",
2448 (long) ((struct local_symbol
*) sym
)->lsy_value
);
2451 print_expr_1 (file
, &sym
->sy_value
);
2452 fprintf (file
, ">");
2459 print_symbol_value (sym
)
2463 print_symbol_value_1 (stderr
, sym
);
2464 fprintf (stderr
, "\n");
2468 print_binary (file
, name
, exp
)
2474 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2475 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2476 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2477 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2478 fprintf (file
, ">");
2483 print_expr_1 (file
, exp
)
2487 fprintf (file
, "expr %lx ", (long) exp
);
2491 fprintf (file
, "illegal");
2494 fprintf (file
, "absent");
2497 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2501 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2502 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2503 fprintf (file
, ">");
2505 if (exp
->X_add_number
)
2506 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2507 (long) exp
->X_add_number
);
2511 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2514 fprintf (file
, "big");
2517 fprintf (file
, "uminus -<");
2519 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2520 fprintf (file
, ">");
2521 goto maybe_print_addnum
;
2523 fprintf (file
, "bit_not");
2526 print_binary (file
, "multiply", exp
);
2529 print_binary (file
, "divide", exp
);
2532 print_binary (file
, "modulus", exp
);
2535 print_binary (file
, "lshift", exp
);
2538 print_binary (file
, "rshift", exp
);
2540 case O_bit_inclusive_or
:
2541 print_binary (file
, "bit_ior", exp
);
2543 case O_bit_exclusive_or
:
2544 print_binary (file
, "bit_xor", exp
);
2547 print_binary (file
, "bit_and", exp
);
2550 print_binary (file
, "eq", exp
);
2553 print_binary (file
, "ne", exp
);
2556 print_binary (file
, "lt", exp
);
2559 print_binary (file
, "le", exp
);
2562 print_binary (file
, "ge", exp
);
2565 print_binary (file
, "gt", exp
);
2568 print_binary (file
, "logical_and", exp
);
2571 print_binary (file
, "logical_or", exp
);
2575 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2576 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2577 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2578 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2579 fprintf (file
, ">");
2580 goto maybe_print_addnum
;
2583 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
2584 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2585 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2586 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2587 fprintf (file
, ">");
2588 goto maybe_print_addnum
;
2590 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2600 print_expr_1 (stderr
, exp
);
2601 fprintf (stderr
, "\n");
2605 symbol_print_statistics (file
)
2608 hash_print_statistics (file
, "symbol table", sy_hash
);
2609 #ifdef BFD_ASSEMBLER
2610 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2611 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2612 local_symbol_count
, local_symbol_conversion_count
);