1 /* symbols.c -symbol table-
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003
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
*));
69 static void report_op_error
PARAMS ((symbolS
*, symbolS
*, symbolS
*));
71 /* Return a pointer to a new symbol. Die if we can't make a new
72 symbol. Fill in the symbol's values. Add symbol to end of symbol
75 This function should be called in the general case of creating a
76 symbol. However, if the output file symbol table has already been
77 set, and you are certain that this symbol won't be wanted in the
78 output file, you can call symbol_create. */
81 symbol_new (name
, segment
, valu
, frag
)
87 symbolS
*symbolP
= symbol_create (name
, segment
, valu
, frag
);
89 /* Link to end of symbol chain. */
92 extern int symbol_table_frozen
;
93 if (symbol_table_frozen
)
97 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
102 /* Save a symbol name on a permanent obstack, and convert it according
103 to the object file format. */
106 save_symbol_name (name
)
109 unsigned int name_length
;
112 name_length
= strlen (name
) + 1; /* +1 for \0. */
113 obstack_grow (¬es
, name
, name_length
);
114 ret
= obstack_finish (¬es
);
116 #ifdef STRIP_UNDERSCORE
121 #ifdef tc_canonicalize_symbol_name
122 ret
= tc_canonicalize_symbol_name (ret
);
125 if (! symbols_case_sensitive
)
129 for (s
= ret
; *s
!= '\0'; s
++)
137 symbol_create (name
, segment
, valu
, frag
)
138 const char *name
; /* It is copied, the caller can destroy/modify. */
139 segT segment
; /* Segment identifier (SEG_<something>). */
140 valueT valu
; /* Symbol value. */
141 fragS
*frag
; /* Associated fragment. */
143 char *preserved_copy_of_name
;
146 preserved_copy_of_name
= save_symbol_name (name
);
148 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
150 /* symbol must be born in some fixed state. This seems as good as any. */
151 memset (symbolP
, 0, sizeof (symbolS
));
154 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
155 if (symbolP
->bsym
== NULL
)
156 as_perror ("%s", "bfd_make_empty_symbol");
157 symbolP
->bsym
->udata
.p
= (PTR
) symbolP
;
159 S_SET_NAME (symbolP
, preserved_copy_of_name
);
161 S_SET_SEGMENT (symbolP
, segment
);
162 S_SET_VALUE (symbolP
, valu
);
163 symbol_clear_list_pointers (symbolP
);
165 symbolP
->sy_frag
= frag
;
166 #ifndef BFD_ASSEMBLER
167 symbolP
->sy_number
= ~0;
168 symbolP
->sy_name_offset
= (unsigned int) ~0;
171 obj_symbol_new_hook (symbolP
);
173 #ifdef tc_symbol_new_hook
174 tc_symbol_new_hook (symbolP
);
182 /* Local symbol support. If we can get away with it, we keep only a
183 small amount of information for local symbols. */
185 static symbolS
*local_symbol_convert
PARAMS ((struct local_symbol
*));
187 /* Used for statistics. */
189 static unsigned long local_symbol_count
;
190 static unsigned long local_symbol_conversion_count
;
192 /* This macro is called with a symbol argument passed by reference.
193 It returns whether this is a local symbol. If necessary, it
194 changes its argument to the real symbol. */
196 #define LOCAL_SYMBOL_CHECK(s) \
198 ? (local_symbol_converted_p ((struct local_symbol *) s) \
199 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
204 /* Create a local symbol and insert it into the local hash table. */
206 struct local_symbol
*
207 local_symbol_make (name
, section
, value
, frag
)
214 struct local_symbol
*ret
;
216 ++local_symbol_count
;
218 name_copy
= save_symbol_name (name
);
220 ret
= (struct local_symbol
*) obstack_alloc (¬es
, sizeof *ret
);
221 ret
->lsy_marker
= NULL
;
222 ret
->lsy_name
= name_copy
;
223 ret
->lsy_section
= section
;
224 local_symbol_set_frag (ret
, frag
);
225 ret
->lsy_value
= value
;
227 hash_jam (local_hash
, name_copy
, (PTR
) ret
);
232 /* Convert a local symbol into a real symbol. Note that we do not
233 reclaim the space used by the local symbol. */
236 local_symbol_convert (locsym
)
237 struct local_symbol
*locsym
;
241 assert (locsym
->lsy_marker
== NULL
);
242 if (local_symbol_converted_p (locsym
))
243 return local_symbol_get_real_symbol (locsym
);
245 ++local_symbol_conversion_count
;
247 ret
= symbol_new (locsym
->lsy_name
, locsym
->lsy_section
, locsym
->lsy_value
,
248 local_symbol_get_frag (locsym
));
250 if (local_symbol_resolved_p (locsym
))
251 ret
->sy_resolved
= 1;
253 /* Local symbols are always either defined or used. */
256 #ifdef TC_LOCAL_SYMFIELD_CONVERT
257 TC_LOCAL_SYMFIELD_CONVERT (locsym
, ret
);
260 symbol_table_insert (ret
);
262 local_symbol_mark_converted (locsym
);
263 local_symbol_set_real_symbol (locsym
, ret
);
265 hash_jam (local_hash
, locsym
->lsy_name
, NULL
);
270 #else /* ! BFD_ASSEMBLER */
272 #define LOCAL_SYMBOL_CHECK(s) 0
273 #define local_symbol_convert(s) ((symbolS *) s)
275 #endif /* ! BFD_ASSEMBLER */
277 /* We have just seen "<name>:".
278 Creates a struct symbol unless it already exists.
280 Gripes if we are redefining a symbol incompatibly (and ignores it). */
283 colon (sym_name
) /* Just seen "x:" - rattle symbols & frags. */
284 const char *sym_name
; /* Symbol name, as a cannonical string. */
285 /* We copy this string: OK to alter later. */
287 register symbolS
*symbolP
; /* Symbol we are working with. */
289 /* Sun local labels go out of scope whenever a non-local symbol is
291 if (LOCAL_LABELS_DOLLAR
)
296 local
= bfd_is_local_label_name (stdoutput
, sym_name
);
298 local
= LOCAL_LABEL (sym_name
);
302 dollar_label_clear ();
305 #ifndef WORKING_DOT_WORD
306 if (new_broken_words
)
308 struct broken_word
*a
;
313 extern const int md_short_jump_size
;
314 extern const int md_long_jump_size
;
316 if (now_seg
== absolute_section
)
318 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
322 possible_bytes
= (md_short_jump_size
323 + new_broken_words
* md_long_jump_size
);
326 frag_opcode
= frag_var (rs_broken_word
,
330 (symbolS
*) broken_words
,
334 /* We want to store the pointer to where to insert the jump
335 table in the fr_opcode of the rs_broken_word frag. This
336 requires a little hackery. */
338 && (frag_tmp
->fr_type
!= rs_broken_word
339 || frag_tmp
->fr_opcode
))
340 frag_tmp
= frag_tmp
->fr_next
;
342 frag_tmp
->fr_opcode
= frag_opcode
;
343 new_broken_words
= 0;
345 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
346 a
->dispfrag
= frag_tmp
;
348 #endif /* WORKING_DOT_WORD */
350 if ((symbolP
= symbol_find (sym_name
)) != 0)
352 #ifdef RESOLVE_SYMBOL_REDEFINITION
353 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
356 /* Now check for undefined symbols. */
357 if (LOCAL_SYMBOL_CHECK (symbolP
))
360 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
362 if (locsym
->lsy_section
!= undefined_section
363 && (local_symbol_get_frag (locsym
) != frag_now
364 || locsym
->lsy_section
!= now_seg
365 || locsym
->lsy_value
!= frag_now_fix ()))
367 as_bad (_("symbol `%s' is already defined"), sym_name
);
371 locsym
->lsy_section
= now_seg
;
372 local_symbol_set_frag (locsym
, frag_now
);
373 locsym
->lsy_value
= frag_now_fix ();
376 else if (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
378 if (S_GET_VALUE (symbolP
) == 0)
380 symbolP
->sy_frag
= frag_now
;
382 S_SET_OTHER (symbolP
, const_flag
);
384 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
385 S_SET_SEGMENT (symbolP
, now_seg
);
388 #endif /* if we have one, it better be zero. */
393 /* There are still several cases to check:
395 A .comm/.lcomm symbol being redefined as initialized
398 A .comm/.lcomm symbol being redefined with a larger
401 This only used to be allowed on VMS gas, but Sun cc
402 on the sparc also depends on it. */
404 if (((!S_IS_DEBUG (symbolP
)
405 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
406 && S_IS_EXTERNAL (symbolP
))
407 || S_GET_SEGMENT (symbolP
) == bss_section
)
408 && (now_seg
== data_section
409 || now_seg
== S_GET_SEGMENT (symbolP
)))
411 /* Select which of the 2 cases this is. */
412 if (now_seg
!= data_section
)
414 /* New .comm for prev .comm symbol.
416 If the new size is larger we just change its
417 value. If the new size is smaller, we ignore
419 if (S_GET_VALUE (symbolP
)
420 < ((unsigned) frag_now_fix ()))
422 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
427 /* It is a .comm/.lcomm being converted to initialized
429 symbolP
->sy_frag
= frag_now
;
431 S_SET_OTHER (symbolP
, const_flag
);
433 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
434 S_SET_SEGMENT (symbolP
, now_seg
); /* Keep N_EXT bit. */
439 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
440 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
441 static const char *od_buf
= "";
446 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
448 sprintf (od_buf
, "%d.%d.",
449 S_GET_OTHER (symbolP
),
450 S_GET_DESC (symbolP
));
452 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
454 segment_name (S_GET_SEGMENT (symbolP
)),
456 (long) S_GET_VALUE (symbolP
));
458 } /* if the undefined symbol has no value */
462 /* Don't blow up if the definition is the same. */
463 if (!(frag_now
== symbolP
->sy_frag
464 && S_GET_VALUE (symbolP
) == frag_now_fix ()
465 && S_GET_SEGMENT (symbolP
) == now_seg
))
466 as_bad (_("symbol `%s' is already defined"), sym_name
);
471 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
473 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
474 (valueT
) frag_now_fix (),
477 #endif /* BFD_ASSEMBLER */
480 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
483 S_SET_OTHER (symbolP
, const_flag
);
486 symbol_table_insert (symbolP
);
489 if (mri_common_symbol
!= NULL
)
491 /* This symbol is actually being defined within an MRI common
492 section. This requires special handling. */
493 if (LOCAL_SYMBOL_CHECK (symbolP
))
494 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
495 symbolP
->sy_value
.X_op
= O_symbol
;
496 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
497 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
498 symbolP
->sy_frag
= &zero_address_frag
;
499 S_SET_SEGMENT (symbolP
, expr_section
);
500 symbolP
->sy_mri_common
= 1;
504 tc_frob_label (symbolP
);
506 #ifdef obj_frob_label
507 obj_frob_label (symbolP
);
513 /* Die if we can't insert the symbol. */
516 symbol_table_insert (symbolP
)
519 register const char *error_string
;
522 know (S_GET_NAME (symbolP
));
524 if (LOCAL_SYMBOL_CHECK (symbolP
))
526 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
528 if (error_string
!= NULL
)
529 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
530 S_GET_NAME (symbolP
), error_string
);
534 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
536 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
537 S_GET_NAME (symbolP
), error_string
);
541 /* If a symbol name does not exist, create it as undefined, and insert
542 it into the symbol table. Return a pointer to it. */
545 symbol_find_or_make (name
)
548 register symbolS
*symbolP
;
550 symbolP
= symbol_find (name
);
555 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
557 symbolP
= md_undefined_symbol ((char *) name
);
561 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
568 symbolP
= symbol_make (name
);
570 symbol_table_insert (symbolP
);
571 } /* if symbol wasn't found */
582 /* Let the machine description default it, e.g. for register names. */
583 symbolP
= md_undefined_symbol ((char *) name
);
586 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
591 /* Implement symbol table lookup.
592 In: A symbol's name as a string: '\0' can't be part of a symbol name.
593 Out: NULL if the name was not in the symbol table, else the address
594 of a struct symbol associated with that name. */
600 #ifdef STRIP_UNDERSCORE
601 return (symbol_find_base (name
, 1));
602 #else /* STRIP_UNDERSCORE */
603 return (symbol_find_base (name
, 0));
604 #endif /* STRIP_UNDERSCORE */
608 symbol_find_exact (name
)
613 struct local_symbol
*locsym
;
615 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
617 return (symbolS
*) locsym
;
621 return ((symbolS
*) hash_find (sy_hash
, name
));
625 symbol_find_base (name
, strip_underscore
)
627 int strip_underscore
;
629 if (strip_underscore
&& *name
== '_')
632 #ifdef tc_canonicalize_symbol_name
635 size_t len
= strlen (name
) + 1;
637 copy
= (char *) alloca (len
);
638 memcpy (copy
, name
, len
);
639 name
= tc_canonicalize_symbol_name (copy
);
643 if (! symbols_case_sensitive
)
650 name
= copy
= (char *) alloca (strlen (name
) + 1);
652 while ((c
= *orig
++) != '\0')
654 *copy
++ = TOUPPER (c
);
659 return symbol_find_exact (name
);
662 /* Once upon a time, symbols were kept in a singly linked list. At
663 least coff needs to be able to rearrange them from time to time, for
664 which a doubly linked list is much more convenient. Loic did these
665 as macros which seemed dangerous to me so they're now functions.
668 /* Link symbol ADDME after symbol TARGET in the chain. */
671 symbol_append (addme
, target
, rootPP
, lastPP
)
677 if (LOCAL_SYMBOL_CHECK (addme
))
679 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
684 know (*rootPP
== NULL
);
685 know (*lastPP
== NULL
);
686 addme
->sy_next
= NULL
;
687 #ifdef SYMBOLS_NEED_BACKPOINTERS
688 addme
->sy_previous
= NULL
;
693 } /* if the list is empty */
695 if (target
->sy_next
!= NULL
)
697 #ifdef SYMBOLS_NEED_BACKPOINTERS
698 target
->sy_next
->sy_previous
= addme
;
699 #endif /* SYMBOLS_NEED_BACKPOINTERS */
703 know (*lastPP
== target
);
705 } /* if we have a next */
707 addme
->sy_next
= target
->sy_next
;
708 target
->sy_next
= addme
;
710 #ifdef SYMBOLS_NEED_BACKPOINTERS
711 addme
->sy_previous
= target
;
712 #endif /* SYMBOLS_NEED_BACKPOINTERS */
714 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
717 /* Set the chain pointers of SYMBOL to null. */
720 symbol_clear_list_pointers (symbolP
)
723 if (LOCAL_SYMBOL_CHECK (symbolP
))
725 symbolP
->sy_next
= NULL
;
726 #ifdef SYMBOLS_NEED_BACKPOINTERS
727 symbolP
->sy_previous
= NULL
;
731 #ifdef SYMBOLS_NEED_BACKPOINTERS
732 /* Remove SYMBOLP from the list. */
735 symbol_remove (symbolP
, rootPP
, lastPP
)
740 if (LOCAL_SYMBOL_CHECK (symbolP
))
743 if (symbolP
== *rootPP
)
745 *rootPP
= symbolP
->sy_next
;
746 } /* if it was the root */
748 if (symbolP
== *lastPP
)
750 *lastPP
= symbolP
->sy_previous
;
751 } /* if it was the tail */
753 if (symbolP
->sy_next
!= NULL
)
755 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
758 if (symbolP
->sy_previous
!= NULL
)
760 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
763 debug_verify_symchain (*rootPP
, *lastPP
);
766 /* Link symbol ADDME before symbol TARGET in the chain. */
769 symbol_insert (addme
, target
, rootPP
, lastPP
)
773 symbolS
**lastPP ATTRIBUTE_UNUSED
;
775 if (LOCAL_SYMBOL_CHECK (addme
))
777 if (LOCAL_SYMBOL_CHECK (target
))
780 if (target
->sy_previous
!= NULL
)
782 target
->sy_previous
->sy_next
= addme
;
786 know (*rootPP
== target
);
790 addme
->sy_previous
= target
->sy_previous
;
791 target
->sy_previous
= addme
;
792 addme
->sy_next
= target
;
794 debug_verify_symchain (*rootPP
, *lastPP
);
797 #endif /* SYMBOLS_NEED_BACKPOINTERS */
800 verify_symbol_chain (rootP
, lastP
)
804 symbolS
*symbolP
= rootP
;
809 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
812 assert (symbolP
->bsym
!= NULL
);
814 #ifdef SYMBOLS_NEED_BACKPOINTERS
815 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
817 /* Walk the list anyways, to make sure pointers are still good. */
819 #endif /* SYMBOLS_NEED_BACKPOINTERS */
822 assert (lastP
== symbolP
);
826 verify_symbol_chain_2 (sym
)
829 symbolS
*p
= sym
, *n
= sym
;
830 #ifdef SYMBOLS_NEED_BACKPOINTERS
831 while (symbol_previous (p
))
832 p
= symbol_previous (p
);
834 while (symbol_next (n
))
836 verify_symbol_chain (p
, n
);
840 report_op_error (symp
, left
, right
)
842 symbolS
*left
, *right
;
846 segT seg_left
= S_GET_SEGMENT (left
);
847 segT seg_right
= right
? S_GET_SEGMENT (right
) : 0;
849 if (expr_symbol_where (symp
, &file
, &line
))
851 if (seg_left
== undefined_section
)
852 as_bad_where (file
, line
,
853 _("undefined symbol `%s' in operation"),
855 if (seg_right
== undefined_section
)
856 as_bad_where (file
, line
,
857 _("undefined symbol `%s' in operation"),
859 if (seg_left
!= undefined_section
860 && seg_right
!= undefined_section
)
863 as_bad_where (file
, line
,
864 _("invalid sections for operation on `%s' and `%s'"),
865 S_GET_NAME (left
), S_GET_NAME (right
));
867 as_bad_where (file
, line
,
868 _("invalid section for operation on `%s'"),
875 if (seg_left
== undefined_section
)
876 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
877 S_GET_NAME (left
), S_GET_NAME (symp
));
878 if (seg_right
== undefined_section
)
879 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
880 S_GET_NAME (right
), S_GET_NAME (symp
));
881 if (seg_left
!= undefined_section
882 && seg_right
!= undefined_section
)
885 as_bad_where (file
, line
,
886 _("invalid sections for operation on `%s' and `%s' setting `%s'"),
887 S_GET_NAME (left
), S_GET_NAME (right
), S_GET_NAME (symp
));
889 as_bad_where (file
, line
,
890 _("invalid section for operation on `%s' setting `%s'"),
891 S_GET_NAME (left
), S_GET_NAME (symp
));
896 /* Resolve the value of a symbol. This is called during the final
897 pass over the symbol table to resolve any symbols with complex
901 resolve_symbol_value (symp
)
905 valueT final_val
= 0;
909 if (LOCAL_SYMBOL_CHECK (symp
))
911 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
913 final_val
= locsym
->lsy_value
;
914 if (local_symbol_resolved_p (locsym
))
917 final_val
+= local_symbol_get_frag (locsym
)->fr_address
/ OCTETS_PER_BYTE
;
921 locsym
->lsy_value
= final_val
;
922 local_symbol_mark_resolved (locsym
);
929 if (symp
->sy_resolved
)
931 if (symp
->sy_value
.X_op
== O_constant
)
932 return (valueT
) symp
->sy_value
.X_add_number
;
938 final_seg
= S_GET_SEGMENT (symp
);
940 if (symp
->sy_resolving
)
943 as_bad (_("symbol definition loop encountered at `%s'"),
950 symbolS
*add_symbol
, *op_symbol
;
952 segT seg_left
, seg_right
;
955 symp
->sy_resolving
= 1;
957 /* Help out with CSE. */
958 add_symbol
= symp
->sy_value
.X_add_symbol
;
959 op_symbol
= symp
->sy_value
.X_op_symbol
;
960 final_val
= symp
->sy_value
.X_add_number
;
961 op
= symp
->sy_value
.X_op
;
974 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
975 if (final_seg
== expr_section
)
976 final_seg
= absolute_section
;
982 left
= resolve_symbol_value (add_symbol
);
983 seg_left
= S_GET_SEGMENT (add_symbol
);
985 symp
->sy_value
.X_op_symbol
= NULL
;
988 if (symp
->sy_mri_common
)
990 /* This is a symbol inside an MRI common section. The
991 relocation routines are going to handle it specially.
992 Don't change the value. */
993 resolved
= symbol_resolved_p (add_symbol
);
997 if (finalize_syms
&& final_val
== 0)
999 if (LOCAL_SYMBOL_CHECK (add_symbol
))
1000 add_symbol
= local_symbol_convert ((struct local_symbol
*)
1002 copy_symbol_attributes (symp
, add_symbol
);
1005 /* If we have equated this symbol to an undefined or common
1006 symbol, keep X_op set to O_symbol, and don't change
1007 X_add_number. This permits the routine which writes out
1008 relocation to detect this case, and convert the
1009 relocation to be against the symbol to which this symbol
1011 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
1015 symp
->sy_value
.X_op
= O_symbol
;
1016 symp
->sy_value
.X_add_symbol
= add_symbol
;
1017 symp
->sy_value
.X_add_number
= final_val
;
1018 /* Use X_op_symbol as a flag. */
1019 symp
->sy_value
.X_op_symbol
= add_symbol
;
1020 final_seg
= seg_left
;
1023 resolved
= symbol_resolved_p (add_symbol
);
1024 symp
->sy_resolving
= 0;
1025 goto exit_dont_set_value
;
1027 else if (finalize_syms
&& final_seg
== expr_section
1028 && seg_left
!= expr_section
)
1030 /* If the symbol is an expression symbol, do similarly
1031 as for undefined and common syms above. Handles
1032 "sym +/- expr" where "expr" cannot be evaluated
1033 immediately, and we want relocations to be against
1034 "sym", eg. because it is weak. */
1035 symp
->sy_value
.X_op
= O_symbol
;
1036 symp
->sy_value
.X_add_symbol
= add_symbol
;
1037 symp
->sy_value
.X_add_number
= final_val
;
1038 symp
->sy_value
.X_op_symbol
= add_symbol
;
1039 final_seg
= seg_left
;
1040 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1041 resolved
= symbol_resolved_p (add_symbol
);
1042 symp
->sy_resolving
= 0;
1043 goto exit_dont_set_value
;
1047 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1048 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1049 final_seg
= seg_left
;
1052 resolved
= symbol_resolved_p (add_symbol
);
1058 left
= resolve_symbol_value (add_symbol
);
1059 seg_left
= S_GET_SEGMENT (add_symbol
);
1061 /* By reducing these to the relevant dyadic operator, we get
1062 !S -> S == 0 permitted on anything,
1063 -S -> 0 - S only permitted on absolute
1064 ~S -> S ^ ~0 only permitted on absolute */
1065 if (op
!= O_logical_not
&& seg_left
!= absolute_section
1067 report_op_error (symp
, add_symbol
, NULL
);
1069 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1070 final_seg
= absolute_section
;
1074 else if (op
== O_logical_not
)
1079 final_val
+= left
+ symp
->sy_frag
->fr_address
;
1081 resolved
= symbol_resolved_p (add_symbol
);
1089 case O_bit_inclusive_or
:
1091 case O_bit_exclusive_or
:
1103 left
= resolve_symbol_value (add_symbol
);
1104 right
= resolve_symbol_value (op_symbol
);
1105 seg_left
= S_GET_SEGMENT (add_symbol
);
1106 seg_right
= S_GET_SEGMENT (op_symbol
);
1108 /* Simplify addition or subtraction of a constant by folding the
1109 constant into X_add_number. */
1112 if (seg_right
== absolute_section
)
1117 else if (seg_left
== absolute_section
)
1120 add_symbol
= op_symbol
;
1122 seg_left
= seg_right
;
1126 else if (op
== O_subtract
)
1128 if (seg_right
== absolute_section
)
1135 /* Equality and non-equality tests are permitted on anything.
1136 Subtraction, and other comparison operators are permitted if
1137 both operands are in the same section. Otherwise, both
1138 operands must be absolute. We already handled the case of
1139 addition or subtraction of a constant above. This will
1140 probably need to be changed for an object file format which
1141 supports arbitrary expressions, such as IEEE-695.
1143 Don't emit messages unless we're finalizing the symbol value,
1144 otherwise we may get the same message multiple times. */
1146 && !(seg_left
== absolute_section
1147 && seg_right
== absolute_section
)
1148 && !(op
== O_eq
|| op
== O_ne
)
1149 && !((op
== O_subtract
1150 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1151 && seg_left
== seg_right
1152 && (seg_left
!= undefined_section
1153 || add_symbol
== op_symbol
)))
1154 report_op_error (symp
, add_symbol
, op_symbol
);
1156 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1157 final_seg
= absolute_section
;
1159 /* Check for division by zero. */
1160 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1162 /* If seg_right is not absolute_section, then we've
1163 already issued a warning about using a bad symbol. */
1164 if (seg_right
== absolute_section
&& finalize_syms
)
1169 if (expr_symbol_where (symp
, &file
, &line
))
1170 as_bad_where (file
, line
, _("division by zero"));
1172 as_bad (_("division by zero when setting `%s'"),
1179 switch (symp
->sy_value
.X_op
)
1181 case O_multiply
: left
*= right
; break;
1182 case O_divide
: left
/= right
; break;
1183 case O_modulus
: left
%= right
; break;
1184 case O_left_shift
: left
<<= right
; break;
1185 case O_right_shift
: left
>>= right
; break;
1186 case O_bit_inclusive_or
: left
|= right
; break;
1187 case O_bit_or_not
: left
|= ~right
; break;
1188 case O_bit_exclusive_or
: left
^= right
; break;
1189 case O_bit_and
: left
&= right
; break;
1190 case O_add
: left
+= right
; break;
1191 case O_subtract
: left
-= right
; break;
1194 left
= (left
== right
&& seg_left
== seg_right
1195 && (seg_left
!= undefined_section
1196 || add_symbol
== op_symbol
)
1197 ? ~ (offsetT
) 0 : 0);
1198 if (symp
->sy_value
.X_op
== O_ne
)
1201 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1202 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1203 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1204 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1205 case O_logical_and
: left
= left
&& right
; break;
1206 case O_logical_or
: left
= left
|| right
; break;
1210 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1211 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1213 if (seg_left
== undefined_section
1214 || seg_right
== undefined_section
)
1215 final_seg
= undefined_section
;
1216 else if (seg_left
== absolute_section
)
1217 final_seg
= seg_right
;
1219 final_seg
= seg_left
;
1221 resolved
= (symbol_resolved_p (add_symbol
)
1222 && symbol_resolved_p (op_symbol
));
1228 /* Give an error (below) if not in expr_section. We don't
1229 want to worry about expr_section symbols, because they
1230 are fictional (they are created as part of expression
1231 resolution), and any problems may not actually mean
1236 symp
->sy_resolving
= 0;
1240 S_SET_VALUE (symp
, final_val
);
1242 exit_dont_set_value
:
1243 /* Always set the segment, even if not finalizing the value.
1244 The segment is used to determine whether a symbol is defined. */
1245 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1246 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1247 for a stab symbol, so we use this bad hack. */
1248 if (final_seg
!= S_GET_SEGMENT (symp
))
1250 S_SET_SEGMENT (symp
, final_seg
);
1252 /* Don't worry if we can't resolve an expr_section symbol. */
1256 symp
->sy_resolved
= 1;
1257 else if (S_GET_SEGMENT (symp
) != expr_section
)
1259 as_bad (_("can't resolve value for symbol `%s'"),
1261 symp
->sy_resolved
= 1;
1268 #ifdef BFD_ASSEMBLER
1270 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1272 /* A static function passed to hash_traverse. */
1275 resolve_local_symbol (key
, value
)
1276 const char *key ATTRIBUTE_UNUSED
;
1280 resolve_symbol_value (value
);
1285 /* Resolve all local symbols. */
1288 resolve_local_symbol_values ()
1290 #ifdef BFD_ASSEMBLER
1291 hash_traverse (local_hash
, resolve_local_symbol
);
1295 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1296 They are *really* local. That is, they go out of scope whenever we see a
1297 label that isn't local. Also, like fb labels, there can be multiple
1298 instances of a dollar label. Therefor, we name encode each instance with
1299 the instance number, keep a list of defined symbols separate from the real
1300 symbol table, and we treat these buggers as a sparse array. */
1302 static long *dollar_labels
;
1303 static long *dollar_label_instances
;
1304 static char *dollar_label_defines
;
1305 static unsigned long dollar_label_count
;
1306 static unsigned long dollar_label_max
;
1309 dollar_label_defined (label
)
1314 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1316 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1318 return dollar_label_defines
[i
- dollar_labels
];
1320 /* If we get here, label isn't defined. */
1325 dollar_label_instance (label
)
1330 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1332 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1334 return (dollar_label_instances
[i
- dollar_labels
]);
1336 /* If we get here, we haven't seen the label before.
1337 Therefore its instance count is zero. */
1342 dollar_label_clear ()
1344 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1347 #define DOLLAR_LABEL_BUMP_BY 10
1350 define_dollar_label (label
)
1355 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1358 ++dollar_label_instances
[i
- dollar_labels
];
1359 dollar_label_defines
[i
- dollar_labels
] = 1;
1363 /* If we get to here, we don't have label listed yet. */
1365 if (dollar_labels
== NULL
)
1367 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1368 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1369 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1370 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1371 dollar_label_count
= 0;
1373 else if (dollar_label_count
== dollar_label_max
)
1375 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1376 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1377 dollar_label_max
* sizeof (long));
1378 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1379 dollar_label_max
* sizeof (long));
1380 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1381 } /* if we needed to grow */
1383 dollar_labels
[dollar_label_count
] = label
;
1384 dollar_label_instances
[dollar_label_count
] = 1;
1385 dollar_label_defines
[dollar_label_count
] = 1;
1386 ++dollar_label_count
;
1389 /* Caller must copy returned name: we re-use the area for the next name.
1391 The mth occurence of label n: is turned into the symbol "Ln^Am"
1392 where n is the label number and m is the instance number. "L" makes
1393 it a label discarded unless debugging and "^A"('\1') ensures no
1394 ordinary symbol SHOULD get the same name as a local label
1395 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1397 fb labels get the same treatment, except that ^B is used in place
1400 char * /* Return local label name. */
1401 dollar_label_name (n
, augend
)
1402 register long n
; /* we just saw "n$:" : n a number. */
1403 register int augend
; /* 0 for current instance, 1 for new instance. */
1406 /* Returned to caller, then copied. Used for created names ("4f"). */
1407 static char symbol_name_build
[24];
1410 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1413 know (augend
== 0 || augend
== 1);
1414 p
= symbol_name_build
;
1415 #ifdef LOCAL_LABEL_PREFIX
1416 *p
++ = LOCAL_LABEL_PREFIX
;
1420 /* Next code just does sprintf( {}, "%d", n); */
1422 q
= symbol_name_temporary
;
1423 for (*q
++ = 0, i
= n
; i
; ++q
)
1428 while ((*p
= *--q
) != '\0')
1431 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1433 /* Instance number. */
1434 q
= symbol_name_temporary
;
1435 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1440 while ((*p
++ = *--q
) != '\0');;
1442 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1443 return symbol_name_build
;
1446 /* Sombody else's idea of local labels. They are made by "n:" where n
1447 is any decimal digit. Refer to them with
1448 "nb" for previous (backward) n:
1449 or "nf" for next (forward) n:.
1451 We do a little better and let n be any number, not just a single digit, but
1452 since the other guy's assembler only does ten, we treat the first ten
1455 Like someone else's assembler, we have one set of local label counters for
1456 entire assembly, not one set per (sub)segment like in most assemblers. This
1457 implies that one can refer to a label in another segment, and indeed some
1458 crufty compilers have done just that.
1460 Since there could be a LOT of these things, treat them as a sparse
1463 #define FB_LABEL_SPECIAL (10)
1465 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1466 static long *fb_labels
;
1467 static long *fb_label_instances
;
1468 static long fb_label_count
;
1469 static long fb_label_max
;
1471 /* This must be more than FB_LABEL_SPECIAL. */
1472 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1477 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1480 /* Add one to the instance number of this fb label. */
1483 fb_label_instance_inc (label
)
1488 if (label
< FB_LABEL_SPECIAL
)
1490 ++fb_low_counter
[label
];
1494 if (fb_labels
!= NULL
)
1496 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1497 i
< fb_labels
+ fb_label_count
; ++i
)
1501 ++fb_label_instances
[i
- fb_labels
];
1503 } /* if we find it */
1504 } /* for each existing label */
1507 /* If we get to here, we don't have label listed yet. */
1509 if (fb_labels
== NULL
)
1511 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1512 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1513 fb_label_max
= FB_LABEL_BUMP_BY
;
1514 fb_label_count
= FB_LABEL_SPECIAL
;
1517 else if (fb_label_count
== fb_label_max
)
1519 fb_label_max
+= FB_LABEL_BUMP_BY
;
1520 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1521 fb_label_max
* sizeof (long));
1522 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1523 fb_label_max
* sizeof (long));
1524 } /* if we needed to grow */
1526 fb_labels
[fb_label_count
] = label
;
1527 fb_label_instances
[fb_label_count
] = 1;
1532 fb_label_instance (label
)
1537 if (label
< FB_LABEL_SPECIAL
)
1539 return (fb_low_counter
[label
]);
1542 if (fb_labels
!= NULL
)
1544 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1545 i
< fb_labels
+ fb_label_count
; ++i
)
1549 return (fb_label_instances
[i
- fb_labels
]);
1550 } /* if we find it */
1551 } /* for each existing label */
1554 /* We didn't find the label, so this must be a reference to the
1559 /* Caller must copy returned name: we re-use the area for the next name.
1561 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1562 where n is the label number and m is the instance number. "L" makes
1563 it a label discarded unless debugging and "^B"('\2') ensures no
1564 ordinary symbol SHOULD get the same name as a local label
1565 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1567 dollar labels get the same treatment, except that ^A is used in
1570 char * /* Return local label name. */
1571 fb_label_name (n
, augend
)
1572 long n
; /* We just saw "n:", "nf" or "nb" : n a number. */
1573 long augend
; /* 0 for nb, 1 for n:, nf. */
1576 /* Returned to caller, then copied. Used for created names ("4f"). */
1577 static char symbol_name_build
[24];
1580 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1583 know (augend
== 0 || augend
== 1);
1584 p
= symbol_name_build
;
1585 #ifdef LOCAL_LABEL_PREFIX
1586 *p
++ = LOCAL_LABEL_PREFIX
;
1590 /* Next code just does sprintf( {}, "%d", n); */
1592 q
= symbol_name_temporary
;
1593 for (*q
++ = 0, i
= n
; i
; ++q
)
1598 while ((*p
= *--q
) != '\0')
1601 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
1603 /* Instance number. */
1604 q
= symbol_name_temporary
;
1605 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1610 while ((*p
++ = *--q
) != '\0');;
1612 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1613 return (symbol_name_build
);
1616 /* Decode name that may have been generated by foo_label_name() above.
1617 If the name wasn't generated by foo_label_name(), then return it
1618 unaltered. This is used for error messages. */
1621 decode_local_label_name (s
)
1625 char *symbol_decode
;
1627 int instance_number
;
1629 const char *message_format
;
1632 #ifdef LOCAL_LABEL_PREFIX
1633 if (s
[index
] == LOCAL_LABEL_PREFIX
)
1637 if (s
[index
] != 'L')
1640 for (label_number
= 0, p
= s
+ index
+ 1; ISDIGIT (*p
); ++p
)
1641 label_number
= (10 * label_number
) + *p
- '0';
1643 if (*p
== DOLLAR_LABEL_CHAR
)
1645 else if (*p
== LOCAL_LABEL_CHAR
)
1650 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
1651 instance_number
= (10 * instance_number
) + *p
- '0';
1653 message_format
= _("\"%d\" (instance number %d of a %s label)");
1654 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1655 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1657 return symbol_decode
;
1660 /* Get the value of a symbol. */
1666 #ifdef BFD_ASSEMBLER
1667 if (LOCAL_SYMBOL_CHECK (s
))
1668 return resolve_symbol_value (s
);
1671 if (!s
->sy_resolved
)
1673 valueT val
= resolve_symbol_value (s
);
1677 if (s
->sy_value
.X_op
!= O_constant
)
1679 static symbolS
*recur
;
1681 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1682 may call S_GET_VALUE. We use a static symbol to avoid the
1683 immediate recursion. */
1685 return (valueT
) s
->sy_value
.X_add_number
;
1687 if (! s
->sy_resolved
1688 || s
->sy_value
.X_op
!= O_symbol
1689 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1690 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1694 return (valueT
) s
->sy_value
.X_add_number
;
1697 /* Set the value of a symbol. */
1700 S_SET_VALUE (s
, val
)
1704 #ifdef BFD_ASSEMBLER
1705 if (LOCAL_SYMBOL_CHECK (s
))
1707 ((struct local_symbol
*) s
)->lsy_value
= val
;
1712 s
->sy_value
.X_op
= O_constant
;
1713 s
->sy_value
.X_add_number
= (offsetT
) val
;
1714 s
->sy_value
.X_unsigned
= 0;
1718 copy_symbol_attributes (dest
, src
)
1719 symbolS
*dest
, *src
;
1721 if (LOCAL_SYMBOL_CHECK (dest
))
1722 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
1723 if (LOCAL_SYMBOL_CHECK (src
))
1724 src
= local_symbol_convert ((struct local_symbol
*) src
);
1726 #ifdef BFD_ASSEMBLER
1727 /* In an expression, transfer the settings of these flags.
1728 The user can override later, of course. */
1729 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1730 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1733 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1734 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1738 #ifdef BFD_ASSEMBLER
1746 if (LOCAL_SYMBOL_CHECK (s
))
1749 flags
= s
->bsym
->flags
;
1751 return (flags
& BSF_FUNCTION
) != 0;
1760 if (LOCAL_SYMBOL_CHECK (s
))
1763 flags
= s
->bsym
->flags
;
1766 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1769 return (flags
& BSF_GLOBAL
) != 0;
1776 if (LOCAL_SYMBOL_CHECK (s
))
1778 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1785 if (LOCAL_SYMBOL_CHECK (s
))
1787 return bfd_is_com_section (s
->bsym
->section
);
1794 if (LOCAL_SYMBOL_CHECK (s
))
1795 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1796 return s
->bsym
->section
!= undefined_section
;
1800 #ifndef EXTERN_FORCE_RELOC
1801 #define EXTERN_FORCE_RELOC IS_ELF
1804 /* Return true for symbols that should not be reduced to section
1805 symbols or eliminated from expressions, because they may be
1806 overridden by the linker. */
1808 S_FORCE_RELOC (s
, strict
)
1812 if (LOCAL_SYMBOL_CHECK (s
))
1813 return ((struct local_symbol
*) s
)->lsy_section
== undefined_section
;
1816 && ((s
->bsym
->flags
& BSF_WEAK
) != 0
1817 || (EXTERN_FORCE_RELOC
1818 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)))
1819 || s
->bsym
->section
== undefined_section
1820 || bfd_is_com_section (s
->bsym
->section
));
1827 if (LOCAL_SYMBOL_CHECK (s
))
1829 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1841 if (LOCAL_SYMBOL_CHECK (s
))
1844 flags
= s
->bsym
->flags
;
1847 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1850 if (bfd_get_section (s
->bsym
) == reg_section
)
1853 if (flag_strip_local_absolute
1854 && (flags
& BSF_GLOBAL
) == 0
1855 && bfd_get_section (s
->bsym
) == absolute_section
)
1858 name
= S_GET_NAME (s
);
1859 return (name
!= NULL
1861 && (strchr (name
, DOLLAR_LABEL_CHAR
)
1862 || strchr (name
, LOCAL_LABEL_CHAR
)
1863 || (! flag_keep_locals
1864 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1867 && name
[1] == '?')))));
1874 return S_IS_EXTERNAL (s
);
1881 return S_GET_NAME (s
) == 0;
1888 if (LOCAL_SYMBOL_CHECK (s
))
1889 return ((struct local_symbol
*) s
)->lsy_name
;
1890 return s
->bsym
->name
;
1897 if (LOCAL_SYMBOL_CHECK (s
))
1898 return ((struct local_symbol
*) s
)->lsy_section
;
1899 return s
->bsym
->section
;
1903 S_SET_SEGMENT (s
, seg
)
1907 /* Don't reassign section symbols. The direct reason is to prevent seg
1908 faults assigning back to const global symbols such as *ABS*, but it
1909 shouldn't happen anyway. */
1911 if (LOCAL_SYMBOL_CHECK (s
))
1913 if (seg
== reg_section
)
1914 s
= local_symbol_convert ((struct local_symbol
*) s
);
1917 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1922 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1924 if (s
->bsym
->section
!= seg
)
1928 s
->bsym
->section
= seg
;
1935 if (LOCAL_SYMBOL_CHECK (s
))
1936 s
= local_symbol_convert ((struct local_symbol
*) s
);
1937 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1939 /* Let .weak override .global. */
1942 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1947 /* Do not reassign section symbols. */
1948 as_where (& file
, & line
);
1949 as_warn_where (file
, line
,
1950 _("section symbols are already global"));
1953 s
->bsym
->flags
|= BSF_GLOBAL
;
1954 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
1958 S_CLEAR_EXTERNAL (s
)
1961 if (LOCAL_SYMBOL_CHECK (s
))
1963 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1965 /* Let .weak override. */
1968 s
->bsym
->flags
|= BSF_LOCAL
;
1969 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
1976 if (LOCAL_SYMBOL_CHECK (s
))
1977 s
= local_symbol_convert ((struct local_symbol
*) s
);
1978 s
->bsym
->flags
|= BSF_WEAK
;
1979 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
1983 S_SET_THREAD_LOCAL (s
)
1986 if (LOCAL_SYMBOL_CHECK (s
))
1987 s
= local_symbol_convert ((struct local_symbol
*) s
);
1988 if (bfd_is_com_section (s
->bsym
->section
)
1989 && (s
->bsym
->flags
& BSF_THREAD_LOCAL
) != 0)
1991 s
->bsym
->flags
|= BSF_THREAD_LOCAL
;
1992 if ((s
->bsym
->flags
& BSF_FUNCTION
) != 0)
1993 as_bad (_("Accessing function `%s' as thread-local object"),
1995 else if (! bfd_is_und_section (s
->bsym
->section
)
1996 && (s
->bsym
->section
->flags
& SEC_THREAD_LOCAL
) == 0)
1997 as_bad (_("Accessing `%s' as thread-local object"),
2002 S_SET_NAME (s
, name
)
2006 if (LOCAL_SYMBOL_CHECK (s
))
2008 ((struct local_symbol
*) s
)->lsy_name
= name
;
2011 s
->bsym
->name
= name
;
2013 #endif /* BFD_ASSEMBLER */
2015 #ifdef SYMBOLS_NEED_BACKPOINTERS
2017 /* Return the previous symbol in a chain. */
2023 if (LOCAL_SYMBOL_CHECK (s
))
2025 return s
->sy_previous
;
2028 #endif /* SYMBOLS_NEED_BACKPOINTERS */
2030 /* Return the next symbol in a chain. */
2036 if (LOCAL_SYMBOL_CHECK (s
))
2041 /* Return a pointer to the value of a symbol as an expression. */
2044 symbol_get_value_expression (s
)
2047 if (LOCAL_SYMBOL_CHECK (s
))
2048 s
= local_symbol_convert ((struct local_symbol
*) s
);
2049 return &s
->sy_value
;
2052 /* Set the value of a symbol to an expression. */
2055 symbol_set_value_expression (s
, exp
)
2057 const expressionS
*exp
;
2059 if (LOCAL_SYMBOL_CHECK (s
))
2060 s
= local_symbol_convert ((struct local_symbol
*) s
);
2064 /* Set the frag of a symbol. */
2067 symbol_set_frag (s
, f
)
2071 #ifdef BFD_ASSEMBLER
2072 if (LOCAL_SYMBOL_CHECK (s
))
2074 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
2081 /* Return the frag of a symbol. */
2087 #ifdef BFD_ASSEMBLER
2088 if (LOCAL_SYMBOL_CHECK (s
))
2089 return local_symbol_get_frag ((struct local_symbol
*) s
);
2094 /* Mark a symbol as having been used. */
2097 symbol_mark_used (s
)
2100 if (LOCAL_SYMBOL_CHECK (s
))
2105 /* Clear the mark of whether a symbol has been used. */
2108 symbol_clear_used (s
)
2111 if (LOCAL_SYMBOL_CHECK (s
))
2112 s
= local_symbol_convert ((struct local_symbol
*) s
);
2116 /* Return whether a symbol has been used. */
2122 if (LOCAL_SYMBOL_CHECK (s
))
2127 /* Mark a symbol as having been used in a reloc. */
2130 symbol_mark_used_in_reloc (s
)
2133 if (LOCAL_SYMBOL_CHECK (s
))
2134 s
= local_symbol_convert ((struct local_symbol
*) s
);
2135 s
->sy_used_in_reloc
= 1;
2138 /* Clear the mark of whether a symbol has been used in a reloc. */
2141 symbol_clear_used_in_reloc (s
)
2144 if (LOCAL_SYMBOL_CHECK (s
))
2146 s
->sy_used_in_reloc
= 0;
2149 /* Return whether a symbol has been used in a reloc. */
2152 symbol_used_in_reloc_p (s
)
2155 if (LOCAL_SYMBOL_CHECK (s
))
2157 return s
->sy_used_in_reloc
;
2160 /* Mark a symbol as an MRI common symbol. */
2163 symbol_mark_mri_common (s
)
2166 if (LOCAL_SYMBOL_CHECK (s
))
2167 s
= local_symbol_convert ((struct local_symbol
*) s
);
2168 s
->sy_mri_common
= 1;
2171 /* Clear the mark of whether a symbol is an MRI common symbol. */
2174 symbol_clear_mri_common (s
)
2177 if (LOCAL_SYMBOL_CHECK (s
))
2179 s
->sy_mri_common
= 0;
2182 /* Return whether a symbol is an MRI common symbol. */
2185 symbol_mri_common_p (s
)
2188 if (LOCAL_SYMBOL_CHECK (s
))
2190 return s
->sy_mri_common
;
2193 /* Mark a symbol as having been written. */
2196 symbol_mark_written (s
)
2199 if (LOCAL_SYMBOL_CHECK (s
))
2204 /* Clear the mark of whether a symbol has been written. */
2207 symbol_clear_written (s
)
2210 if (LOCAL_SYMBOL_CHECK (s
))
2215 /* Return whether a symbol has been written. */
2218 symbol_written_p (s
)
2221 if (LOCAL_SYMBOL_CHECK (s
))
2226 /* Mark a symbol has having been resolved. */
2229 symbol_mark_resolved (s
)
2232 #ifdef BFD_ASSEMBLER
2233 if (LOCAL_SYMBOL_CHECK (s
))
2235 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2242 /* Return whether a symbol has been resolved. */
2245 symbol_resolved_p (s
)
2248 #ifdef BFD_ASSEMBLER
2249 if (LOCAL_SYMBOL_CHECK (s
))
2250 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2252 return s
->sy_resolved
;
2255 /* Return whether a symbol is a section symbol. */
2258 symbol_section_p (s
)
2259 symbolS
*s ATTRIBUTE_UNUSED
;
2261 if (LOCAL_SYMBOL_CHECK (s
))
2263 #ifdef BFD_ASSEMBLER
2264 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2271 /* Return whether a symbol is equated to another symbol. */
2274 symbol_equated_p (s
)
2277 if (LOCAL_SYMBOL_CHECK (s
))
2279 return s
->sy_value
.X_op
== O_symbol
;
2282 /* Return whether a symbol is equated to another symbol, and should be
2283 treated specially when writing out relocs. */
2286 symbol_equated_reloc_p (s
)
2289 if (LOCAL_SYMBOL_CHECK (s
))
2291 /* X_op_symbol, normally not used for O_symbol, is set by
2292 resolve_symbol_value to flag expression syms that have been
2294 return (s
->sy_value
.X_op
== O_symbol
2295 && ((s
->sy_resolved
&& s
->sy_value
.X_op_symbol
!= NULL
)
2296 || ! S_IS_DEFINED (s
)
2297 || S_IS_COMMON (s
)));
2300 /* Return whether a symbol has a constant value. */
2303 symbol_constant_p (s
)
2306 if (LOCAL_SYMBOL_CHECK (s
))
2308 return s
->sy_value
.X_op
== O_constant
;
2311 #ifdef BFD_ASSEMBLER
2313 /* Return the BFD symbol for a symbol. */
2316 symbol_get_bfdsym (s
)
2319 if (LOCAL_SYMBOL_CHECK (s
))
2320 s
= local_symbol_convert ((struct local_symbol
*) s
);
2324 /* Set the BFD symbol for a symbol. */
2327 symbol_set_bfdsym (s
, bsym
)
2331 if (LOCAL_SYMBOL_CHECK (s
))
2332 s
= local_symbol_convert ((struct local_symbol
*) s
);
2336 #endif /* BFD_ASSEMBLER */
2338 #ifdef OBJ_SYMFIELD_TYPE
2340 /* Get a pointer to the object format information for a symbol. */
2346 if (LOCAL_SYMBOL_CHECK (s
))
2347 s
= local_symbol_convert ((struct local_symbol
*) s
);
2351 /* Set the object format information for a symbol. */
2354 symbol_set_obj (s
, o
)
2356 OBJ_SYMFIELD_TYPE
*o
;
2358 if (LOCAL_SYMBOL_CHECK (s
))
2359 s
= local_symbol_convert ((struct local_symbol
*) s
);
2363 #endif /* OBJ_SYMFIELD_TYPE */
2365 #ifdef TC_SYMFIELD_TYPE
2367 /* Get a pointer to the processor information for a symbol. */
2373 if (LOCAL_SYMBOL_CHECK (s
))
2374 s
= local_symbol_convert ((struct local_symbol
*) s
);
2378 /* Set the processor information for a symbol. */
2381 symbol_set_tc (s
, o
)
2383 TC_SYMFIELD_TYPE
*o
;
2385 if (LOCAL_SYMBOL_CHECK (s
))
2386 s
= local_symbol_convert ((struct local_symbol
*) s
);
2390 #endif /* TC_SYMFIELD_TYPE */
2395 symbol_lastP
= NULL
;
2396 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2397 sy_hash
= hash_new ();
2398 #ifdef BFD_ASSEMBLER
2399 local_hash
= hash_new ();
2402 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2403 #ifdef BFD_ASSEMBLER
2404 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2405 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2408 /* Can't initialise a union. Sigh. */
2409 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2411 abs_symbol
.sy_value
.X_op
= O_constant
;
2412 abs_symbol
.sy_frag
= &zero_address_frag
;
2414 if (LOCAL_LABELS_FB
)
2420 /* Maximum indent level.
2421 Available for modification inside a gdb session. */
2422 int max_indent_level
= 8;
2429 printf ("%*s", indent_level
* 4, "");
2435 print_symbol_value_1 (file
, sym
)
2439 const char *name
= S_GET_NAME (sym
);
2440 if (!name
|| !name
[0])
2442 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2444 if (LOCAL_SYMBOL_CHECK (sym
))
2446 #ifdef BFD_ASSEMBLER
2447 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2448 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2449 && local_symbol_get_frag (locsym
) != NULL
)
2450 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2451 if (local_symbol_resolved_p (locsym
))
2452 fprintf (file
, " resolved");
2453 fprintf (file
, " local");
2458 if (sym
->sy_frag
!= &zero_address_frag
)
2459 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2461 fprintf (file
, " written");
2462 if (sym
->sy_resolved
)
2463 fprintf (file
, " resolved");
2464 else if (sym
->sy_resolving
)
2465 fprintf (file
, " resolving");
2466 if (sym
->sy_used_in_reloc
)
2467 fprintf (file
, " used-in-reloc");
2469 fprintf (file
, " used");
2470 if (S_IS_LOCAL (sym
))
2471 fprintf (file
, " local");
2472 if (S_IS_EXTERN (sym
))
2473 fprintf (file
, " extern");
2474 if (S_IS_DEBUG (sym
))
2475 fprintf (file
, " debug");
2476 if (S_IS_DEFINED (sym
))
2477 fprintf (file
, " defined");
2479 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2480 if (symbol_resolved_p (sym
))
2482 segT s
= S_GET_SEGMENT (sym
);
2484 if (s
!= undefined_section
2485 && s
!= expr_section
)
2486 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2488 else if (indent_level
< max_indent_level
2489 && S_GET_SEGMENT (sym
) != undefined_section
)
2492 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2493 #ifdef BFD_ASSEMBLER
2494 if (LOCAL_SYMBOL_CHECK (sym
))
2495 fprintf (file
, "constant %lx",
2496 (long) ((struct local_symbol
*) sym
)->lsy_value
);
2499 print_expr_1 (file
, &sym
->sy_value
);
2500 fprintf (file
, ">");
2507 print_symbol_value (sym
)
2511 print_symbol_value_1 (stderr
, sym
);
2512 fprintf (stderr
, "\n");
2516 print_binary (file
, name
, exp
)
2522 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2523 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2524 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2525 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2526 fprintf (file
, ">");
2531 print_expr_1 (file
, exp
)
2535 fprintf (file
, "expr %lx ", (long) exp
);
2539 fprintf (file
, "illegal");
2542 fprintf (file
, "absent");
2545 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2549 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2550 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2551 fprintf (file
, ">");
2553 if (exp
->X_add_number
)
2554 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2555 (long) exp
->X_add_number
);
2559 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2562 fprintf (file
, "big");
2565 fprintf (file
, "uminus -<");
2567 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2568 fprintf (file
, ">");
2569 goto maybe_print_addnum
;
2571 fprintf (file
, "bit_not");
2574 print_binary (file
, "multiply", exp
);
2577 print_binary (file
, "divide", exp
);
2580 print_binary (file
, "modulus", exp
);
2583 print_binary (file
, "lshift", exp
);
2586 print_binary (file
, "rshift", exp
);
2588 case O_bit_inclusive_or
:
2589 print_binary (file
, "bit_ior", exp
);
2591 case O_bit_exclusive_or
:
2592 print_binary (file
, "bit_xor", exp
);
2595 print_binary (file
, "bit_and", exp
);
2598 print_binary (file
, "eq", exp
);
2601 print_binary (file
, "ne", exp
);
2604 print_binary (file
, "lt", exp
);
2607 print_binary (file
, "le", exp
);
2610 print_binary (file
, "ge", exp
);
2613 print_binary (file
, "gt", exp
);
2616 print_binary (file
, "logical_and", exp
);
2619 print_binary (file
, "logical_or", exp
);
2623 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2624 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2625 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2626 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2627 fprintf (file
, ">");
2628 goto maybe_print_addnum
;
2631 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
2632 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2633 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2634 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2635 fprintf (file
, ">");
2636 goto maybe_print_addnum
;
2638 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2648 print_expr_1 (stderr
, exp
);
2649 fprintf (stderr
, "\n");
2653 symbol_print_statistics (file
)
2656 hash_print_statistics (file
, "symbol table", sy_hash
);
2657 #ifdef BFD_ASSEMBLER
2658 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2659 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2660 local_symbol_count
, local_symbol_conversion_count
);