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 struct local_symbol
*local_symbol_make
PARAMS ((const char *, segT
,
187 static symbolS
*local_symbol_convert
PARAMS ((struct local_symbol
*));
189 /* Used for statistics. */
191 static unsigned long local_symbol_count
;
192 static unsigned long local_symbol_conversion_count
;
194 /* This macro is called with a symbol argument passed by reference.
195 It returns whether this is a local symbol. If necessary, it
196 changes its argument to the real symbol. */
198 #define LOCAL_SYMBOL_CHECK(s) \
200 ? (local_symbol_converted_p ((struct local_symbol *) s) \
201 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
206 /* Create a local symbol and insert it into the local hash table. */
208 static struct local_symbol
*
209 local_symbol_make (name
, section
, value
, frag
)
216 struct local_symbol
*ret
;
218 ++local_symbol_count
;
220 name_copy
= save_symbol_name (name
);
222 ret
= (struct local_symbol
*) obstack_alloc (¬es
, sizeof *ret
);
223 ret
->lsy_marker
= NULL
;
224 ret
->lsy_name
= name_copy
;
225 ret
->lsy_section
= section
;
226 local_symbol_set_frag (ret
, frag
);
227 ret
->lsy_value
= value
;
229 hash_jam (local_hash
, name_copy
, (PTR
) ret
);
234 /* Convert a local symbol into a real symbol. Note that we do not
235 reclaim the space used by the local symbol. */
238 local_symbol_convert (locsym
)
239 struct local_symbol
*locsym
;
243 assert (locsym
->lsy_marker
== NULL
);
244 if (local_symbol_converted_p (locsym
))
245 return local_symbol_get_real_symbol (locsym
);
247 ++local_symbol_conversion_count
;
249 ret
= symbol_new (locsym
->lsy_name
, locsym
->lsy_section
, locsym
->lsy_value
,
250 local_symbol_get_frag (locsym
));
252 if (local_symbol_resolved_p (locsym
))
253 ret
->sy_resolved
= 1;
255 /* Local symbols are always either defined or used. */
258 #ifdef TC_LOCAL_SYMFIELD_CONVERT
259 TC_LOCAL_SYMFIELD_CONVERT (locsym
, ret
);
262 symbol_table_insert (ret
);
264 local_symbol_mark_converted (locsym
);
265 local_symbol_set_real_symbol (locsym
, ret
);
267 hash_jam (local_hash
, locsym
->lsy_name
, NULL
);
272 #else /* ! BFD_ASSEMBLER */
274 #define LOCAL_SYMBOL_CHECK(s) 0
275 #define local_symbol_convert(s) ((symbolS *) s)
277 #endif /* ! BFD_ASSEMBLER */
279 /* We have just seen "<name>:".
280 Creates a struct symbol unless it already exists.
282 Gripes if we are redefining a symbol incompatibly (and ignores it). */
285 colon (sym_name
) /* Just seen "x:" - rattle symbols & frags. */
286 const char *sym_name
; /* Symbol name, as a cannonical string. */
287 /* We copy this string: OK to alter later. */
289 register symbolS
*symbolP
; /* Symbol we are working with. */
291 /* Sun local labels go out of scope whenever a non-local symbol is
293 if (LOCAL_LABELS_DOLLAR
)
298 local
= bfd_is_local_label_name (stdoutput
, sym_name
);
300 local
= LOCAL_LABEL (sym_name
);
304 dollar_label_clear ();
307 #ifndef WORKING_DOT_WORD
308 if (new_broken_words
)
310 struct broken_word
*a
;
315 extern const int md_short_jump_size
;
316 extern const int md_long_jump_size
;
318 if (now_seg
== absolute_section
)
320 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
324 possible_bytes
= (md_short_jump_size
325 + new_broken_words
* md_long_jump_size
);
328 frag_opcode
= frag_var (rs_broken_word
,
332 (symbolS
*) broken_words
,
336 /* We want to store the pointer to where to insert the jump
337 table in the fr_opcode of the rs_broken_word frag. This
338 requires a little hackery. */
340 && (frag_tmp
->fr_type
!= rs_broken_word
341 || frag_tmp
->fr_opcode
))
342 frag_tmp
= frag_tmp
->fr_next
;
344 frag_tmp
->fr_opcode
= frag_opcode
;
345 new_broken_words
= 0;
347 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
348 a
->dispfrag
= frag_tmp
;
350 #endif /* WORKING_DOT_WORD */
352 if ((symbolP
= symbol_find (sym_name
)) != 0)
354 #ifdef RESOLVE_SYMBOL_REDEFINITION
355 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
358 /* Now check for undefined symbols. */
359 if (LOCAL_SYMBOL_CHECK (symbolP
))
362 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
364 if (locsym
->lsy_section
!= undefined_section
365 && (local_symbol_get_frag (locsym
) != frag_now
366 || locsym
->lsy_section
!= now_seg
367 || locsym
->lsy_value
!= frag_now_fix ()))
369 as_bad (_("symbol `%s' is already defined"), sym_name
);
373 locsym
->lsy_section
= now_seg
;
374 local_symbol_set_frag (locsym
, frag_now
);
375 locsym
->lsy_value
= frag_now_fix ();
378 else if (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
380 if (S_GET_VALUE (symbolP
) == 0)
382 symbolP
->sy_frag
= frag_now
;
384 S_SET_OTHER (symbolP
, const_flag
);
386 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
387 S_SET_SEGMENT (symbolP
, now_seg
);
390 #endif /* if we have one, it better be zero. */
395 /* There are still several cases to check:
397 A .comm/.lcomm symbol being redefined as initialized
400 A .comm/.lcomm symbol being redefined with a larger
403 This only used to be allowed on VMS gas, but Sun cc
404 on the sparc also depends on it. */
406 if (((!S_IS_DEBUG (symbolP
)
407 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
408 && S_IS_EXTERNAL (symbolP
))
409 || S_GET_SEGMENT (symbolP
) == bss_section
)
410 && (now_seg
== data_section
411 || now_seg
== S_GET_SEGMENT (symbolP
)))
413 /* Select which of the 2 cases this is. */
414 if (now_seg
!= data_section
)
416 /* New .comm for prev .comm symbol.
418 If the new size is larger we just change its
419 value. If the new size is smaller, we ignore
421 if (S_GET_VALUE (symbolP
)
422 < ((unsigned) frag_now_fix ()))
424 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
429 /* It is a .comm/.lcomm being converted to initialized
431 symbolP
->sy_frag
= frag_now
;
433 S_SET_OTHER (symbolP
, const_flag
);
435 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
436 S_SET_SEGMENT (symbolP
, now_seg
); /* Keep N_EXT bit. */
441 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
442 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
443 static const char *od_buf
= "";
448 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
450 sprintf (od_buf
, "%d.%d.",
451 S_GET_OTHER (symbolP
),
452 S_GET_DESC (symbolP
));
454 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
456 segment_name (S_GET_SEGMENT (symbolP
)),
458 (long) S_GET_VALUE (symbolP
));
460 } /* if the undefined symbol has no value */
464 /* Don't blow up if the definition is the same. */
465 if (!(frag_now
== symbolP
->sy_frag
466 && S_GET_VALUE (symbolP
) == frag_now_fix ()
467 && S_GET_SEGMENT (symbolP
) == now_seg
))
468 as_bad (_("symbol `%s' is already defined"), sym_name
);
473 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
475 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
476 (valueT
) frag_now_fix (),
479 #endif /* BFD_ASSEMBLER */
482 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
485 S_SET_OTHER (symbolP
, const_flag
);
488 symbol_table_insert (symbolP
);
491 if (mri_common_symbol
!= NULL
)
493 /* This symbol is actually being defined within an MRI common
494 section. This requires special handling. */
495 if (LOCAL_SYMBOL_CHECK (symbolP
))
496 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
497 symbolP
->sy_value
.X_op
= O_symbol
;
498 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
499 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
500 symbolP
->sy_frag
= &zero_address_frag
;
501 S_SET_SEGMENT (symbolP
, expr_section
);
502 symbolP
->sy_mri_common
= 1;
506 tc_frob_label (symbolP
);
508 #ifdef obj_frob_label
509 obj_frob_label (symbolP
);
515 /* Die if we can't insert the symbol. */
518 symbol_table_insert (symbolP
)
521 register const char *error_string
;
524 know (S_GET_NAME (symbolP
));
526 if (LOCAL_SYMBOL_CHECK (symbolP
))
528 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
530 if (error_string
!= NULL
)
531 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
532 S_GET_NAME (symbolP
), error_string
);
536 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
538 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
539 S_GET_NAME (symbolP
), error_string
);
543 /* If a symbol name does not exist, create it as undefined, and insert
544 it into the symbol table. Return a pointer to it. */
547 symbol_find_or_make (name
)
550 register symbolS
*symbolP
;
552 symbolP
= symbol_find (name
);
557 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
559 symbolP
= md_undefined_symbol ((char *) name
);
563 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
570 symbolP
= symbol_make (name
);
572 symbol_table_insert (symbolP
);
573 } /* if symbol wasn't found */
584 /* Let the machine description default it, e.g. for register names. */
585 symbolP
= md_undefined_symbol ((char *) name
);
588 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
593 /* Implement symbol table lookup.
594 In: A symbol's name as a string: '\0' can't be part of a symbol name.
595 Out: NULL if the name was not in the symbol table, else the address
596 of a struct symbol associated with that name. */
602 #ifdef STRIP_UNDERSCORE
603 return (symbol_find_base (name
, 1));
604 #else /* STRIP_UNDERSCORE */
605 return (symbol_find_base (name
, 0));
606 #endif /* STRIP_UNDERSCORE */
610 symbol_find_exact (name
)
615 struct local_symbol
*locsym
;
617 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
619 return (symbolS
*) locsym
;
623 return ((symbolS
*) hash_find (sy_hash
, name
));
627 symbol_find_base (name
, strip_underscore
)
629 int strip_underscore
;
631 if (strip_underscore
&& *name
== '_')
634 #ifdef tc_canonicalize_symbol_name
637 size_t len
= strlen (name
) + 1;
639 copy
= (char *) alloca (len
);
640 memcpy (copy
, name
, len
);
641 name
= tc_canonicalize_symbol_name (copy
);
645 if (! symbols_case_sensitive
)
652 name
= copy
= (char *) alloca (strlen (name
) + 1);
654 while ((c
= *orig
++) != '\0')
656 *copy
++ = TOUPPER (c
);
661 return symbol_find_exact (name
);
664 /* Once upon a time, symbols were kept in a singly linked list. At
665 least coff needs to be able to rearrange them from time to time, for
666 which a doubly linked list is much more convenient. Loic did these
667 as macros which seemed dangerous to me so they're now functions.
670 /* Link symbol ADDME after symbol TARGET in the chain. */
673 symbol_append (addme
, target
, rootPP
, lastPP
)
679 if (LOCAL_SYMBOL_CHECK (addme
))
681 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
686 know (*rootPP
== NULL
);
687 know (*lastPP
== NULL
);
688 addme
->sy_next
= NULL
;
689 #ifdef SYMBOLS_NEED_BACKPOINTERS
690 addme
->sy_previous
= NULL
;
695 } /* if the list is empty */
697 if (target
->sy_next
!= NULL
)
699 #ifdef SYMBOLS_NEED_BACKPOINTERS
700 target
->sy_next
->sy_previous
= addme
;
701 #endif /* SYMBOLS_NEED_BACKPOINTERS */
705 know (*lastPP
== target
);
707 } /* if we have a next */
709 addme
->sy_next
= target
->sy_next
;
710 target
->sy_next
= addme
;
712 #ifdef SYMBOLS_NEED_BACKPOINTERS
713 addme
->sy_previous
= target
;
714 #endif /* SYMBOLS_NEED_BACKPOINTERS */
716 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
719 /* Set the chain pointers of SYMBOL to null. */
722 symbol_clear_list_pointers (symbolP
)
725 if (LOCAL_SYMBOL_CHECK (symbolP
))
727 symbolP
->sy_next
= NULL
;
728 #ifdef SYMBOLS_NEED_BACKPOINTERS
729 symbolP
->sy_previous
= NULL
;
733 #ifdef SYMBOLS_NEED_BACKPOINTERS
734 /* Remove SYMBOLP from the list. */
737 symbol_remove (symbolP
, rootPP
, lastPP
)
742 if (LOCAL_SYMBOL_CHECK (symbolP
))
745 if (symbolP
== *rootPP
)
747 *rootPP
= symbolP
->sy_next
;
748 } /* if it was the root */
750 if (symbolP
== *lastPP
)
752 *lastPP
= symbolP
->sy_previous
;
753 } /* if it was the tail */
755 if (symbolP
->sy_next
!= NULL
)
757 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
760 if (symbolP
->sy_previous
!= NULL
)
762 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
765 debug_verify_symchain (*rootPP
, *lastPP
);
768 /* Link symbol ADDME before symbol TARGET in the chain. */
771 symbol_insert (addme
, target
, rootPP
, lastPP
)
775 symbolS
**lastPP ATTRIBUTE_UNUSED
;
777 if (LOCAL_SYMBOL_CHECK (addme
))
779 if (LOCAL_SYMBOL_CHECK (target
))
782 if (target
->sy_previous
!= NULL
)
784 target
->sy_previous
->sy_next
= addme
;
788 know (*rootPP
== target
);
792 addme
->sy_previous
= target
->sy_previous
;
793 target
->sy_previous
= addme
;
794 addme
->sy_next
= target
;
796 debug_verify_symchain (*rootPP
, *lastPP
);
799 #endif /* SYMBOLS_NEED_BACKPOINTERS */
802 verify_symbol_chain (rootP
, lastP
)
806 symbolS
*symbolP
= rootP
;
811 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
814 assert (symbolP
->bsym
!= NULL
);
816 #ifdef SYMBOLS_NEED_BACKPOINTERS
817 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
819 /* Walk the list anyways, to make sure pointers are still good. */
821 #endif /* SYMBOLS_NEED_BACKPOINTERS */
824 assert (lastP
== symbolP
);
828 verify_symbol_chain_2 (sym
)
831 symbolS
*p
= sym
, *n
= sym
;
832 #ifdef SYMBOLS_NEED_BACKPOINTERS
833 while (symbol_previous (p
))
834 p
= symbol_previous (p
);
836 while (symbol_next (n
))
838 verify_symbol_chain (p
, n
);
842 report_op_error (symp
, left
, right
)
844 symbolS
*left
, *right
;
848 segT seg_left
= S_GET_SEGMENT (left
);
849 segT seg_right
= right
? S_GET_SEGMENT (right
) : 0;
851 if (expr_symbol_where (symp
, &file
, &line
))
853 if (seg_left
== undefined_section
)
854 as_bad_where (file
, line
,
855 _("undefined symbol `%s' in operation"),
857 if (seg_right
== undefined_section
)
858 as_bad_where (file
, line
,
859 _("undefined symbol `%s' in operation"),
861 if (seg_left
!= undefined_section
862 && seg_right
!= undefined_section
)
865 as_bad_where (file
, line
,
866 _("invalid sections for operation on `%s' and `%s'"),
867 S_GET_NAME (left
), S_GET_NAME (right
));
869 as_bad_where (file
, line
,
870 _("invalid section for operation on `%s'"),
877 if (seg_left
== undefined_section
)
878 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
879 S_GET_NAME (left
), S_GET_NAME (symp
));
880 if (seg_right
== undefined_section
)
881 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
882 S_GET_NAME (right
), S_GET_NAME (symp
));
883 if (seg_left
!= undefined_section
884 && seg_right
!= undefined_section
)
887 as_bad_where (file
, line
,
888 _("invalid sections for operation on `%s' and `%s' setting `%s'"),
889 S_GET_NAME (left
), S_GET_NAME (right
), S_GET_NAME (symp
));
891 as_bad_where (file
, line
,
892 _("invalid section for operation on `%s' setting `%s'"),
893 S_GET_NAME (left
), S_GET_NAME (symp
));
898 /* Resolve the value of a symbol. This is called during the final
899 pass over the symbol table to resolve any symbols with complex
903 resolve_symbol_value (symp
)
907 valueT final_val
= 0;
911 if (LOCAL_SYMBOL_CHECK (symp
))
913 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
915 final_val
= locsym
->lsy_value
;
916 if (local_symbol_resolved_p (locsym
))
919 final_val
+= local_symbol_get_frag (locsym
)->fr_address
/ OCTETS_PER_BYTE
;
923 locsym
->lsy_value
= final_val
;
924 local_symbol_mark_resolved (locsym
);
931 if (symp
->sy_resolved
)
933 if (symp
->sy_value
.X_op
== O_constant
)
934 return (valueT
) symp
->sy_value
.X_add_number
;
940 final_seg
= S_GET_SEGMENT (symp
);
942 if (symp
->sy_resolving
)
945 as_bad (_("symbol definition loop encountered at `%s'"),
952 symbolS
*add_symbol
, *op_symbol
;
954 segT seg_left
, seg_right
;
957 symp
->sy_resolving
= 1;
959 /* Help out with CSE. */
960 add_symbol
= symp
->sy_value
.X_add_symbol
;
961 op_symbol
= symp
->sy_value
.X_op_symbol
;
962 final_val
= symp
->sy_value
.X_add_number
;
963 op
= symp
->sy_value
.X_op
;
976 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
977 if (final_seg
== expr_section
)
978 final_seg
= absolute_section
;
984 left
= resolve_symbol_value (add_symbol
);
985 seg_left
= S_GET_SEGMENT (add_symbol
);
987 symp
->sy_value
.X_op_symbol
= NULL
;
990 if (symp
->sy_mri_common
)
992 /* This is a symbol inside an MRI common section. The
993 relocation routines are going to handle it specially.
994 Don't change the value. */
995 resolved
= symbol_resolved_p (add_symbol
);
999 if (finalize_syms
&& final_val
== 0)
1001 if (LOCAL_SYMBOL_CHECK (add_symbol
))
1002 add_symbol
= local_symbol_convert ((struct local_symbol
*)
1004 copy_symbol_attributes (symp
, add_symbol
);
1007 /* If we have equated this symbol to an undefined or common
1008 symbol, keep X_op set to O_symbol, and don't change
1009 X_add_number. This permits the routine which writes out
1010 relocation to detect this case, and convert the
1011 relocation to be against the symbol to which this symbol
1013 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
1017 symp
->sy_value
.X_op
= O_symbol
;
1018 symp
->sy_value
.X_add_symbol
= add_symbol
;
1019 symp
->sy_value
.X_add_number
= final_val
;
1020 /* Use X_op_symbol as a flag. */
1021 symp
->sy_value
.X_op_symbol
= add_symbol
;
1022 final_seg
= seg_left
;
1025 resolved
= symbol_resolved_p (add_symbol
);
1026 symp
->sy_resolving
= 0;
1027 goto exit_dont_set_value
;
1029 else if (finalize_syms
&& final_seg
== expr_section
1030 && seg_left
!= expr_section
)
1032 /* If the symbol is an expression symbol, do similarly
1033 as for undefined and common syms above. Handles
1034 "sym +/- expr" where "expr" cannot be evaluated
1035 immediately, and we want relocations to be against
1036 "sym", eg. because it is weak. */
1037 symp
->sy_value
.X_op
= O_symbol
;
1038 symp
->sy_value
.X_add_symbol
= add_symbol
;
1039 symp
->sy_value
.X_add_number
= final_val
;
1040 symp
->sy_value
.X_op_symbol
= add_symbol
;
1041 final_seg
= seg_left
;
1042 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1043 resolved
= symbol_resolved_p (add_symbol
);
1044 symp
->sy_resolving
= 0;
1045 goto exit_dont_set_value
;
1049 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1050 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1051 final_seg
= seg_left
;
1054 resolved
= symbol_resolved_p (add_symbol
);
1060 left
= resolve_symbol_value (add_symbol
);
1061 seg_left
= S_GET_SEGMENT (add_symbol
);
1063 /* By reducing these to the relevant dyadic operator, we get
1064 !S -> S == 0 permitted on anything,
1065 -S -> 0 - S only permitted on absolute
1066 ~S -> S ^ ~0 only permitted on absolute */
1067 if (op
!= O_logical_not
&& seg_left
!= absolute_section
1069 report_op_error (symp
, add_symbol
, NULL
);
1071 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1072 final_seg
= absolute_section
;
1076 else if (op
== O_logical_not
)
1081 final_val
+= left
+ symp
->sy_frag
->fr_address
;
1083 resolved
= symbol_resolved_p (add_symbol
);
1091 case O_bit_inclusive_or
:
1093 case O_bit_exclusive_or
:
1105 left
= resolve_symbol_value (add_symbol
);
1106 right
= resolve_symbol_value (op_symbol
);
1107 seg_left
= S_GET_SEGMENT (add_symbol
);
1108 seg_right
= S_GET_SEGMENT (op_symbol
);
1110 /* Simplify addition or subtraction of a constant by folding the
1111 constant into X_add_number. */
1114 if (seg_right
== absolute_section
)
1119 else if (seg_left
== absolute_section
)
1122 add_symbol
= op_symbol
;
1124 seg_left
= seg_right
;
1128 else if (op
== O_subtract
)
1130 if (seg_right
== absolute_section
)
1137 /* Equality and non-equality tests are permitted on anything.
1138 Subtraction, and other comparison operators are permitted if
1139 both operands are in the same section. Otherwise, both
1140 operands must be absolute. We already handled the case of
1141 addition or subtraction of a constant above. This will
1142 probably need to be changed for an object file format which
1143 supports arbitrary expressions, such as IEEE-695.
1145 Don't emit messages unless we're finalizing the symbol value,
1146 otherwise we may get the same message multiple times. */
1148 && !(seg_left
== absolute_section
1149 && seg_right
== absolute_section
)
1150 && !(op
== O_eq
|| op
== O_ne
)
1151 && !((op
== O_subtract
1152 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1153 && seg_left
== seg_right
1154 && (seg_left
!= undefined_section
1155 || add_symbol
== op_symbol
)))
1156 report_op_error (symp
, add_symbol
, op_symbol
);
1158 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1159 final_seg
= absolute_section
;
1161 /* Check for division by zero. */
1162 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1164 /* If seg_right is not absolute_section, then we've
1165 already issued a warning about using a bad symbol. */
1166 if (seg_right
== absolute_section
&& finalize_syms
)
1171 if (expr_symbol_where (symp
, &file
, &line
))
1172 as_bad_where (file
, line
, _("division by zero"));
1174 as_bad (_("division by zero when setting `%s'"),
1181 switch (symp
->sy_value
.X_op
)
1183 case O_multiply
: left
*= right
; break;
1184 case O_divide
: left
/= right
; break;
1185 case O_modulus
: left
%= right
; break;
1186 case O_left_shift
: left
<<= right
; break;
1187 case O_right_shift
: left
>>= right
; break;
1188 case O_bit_inclusive_or
: left
|= right
; break;
1189 case O_bit_or_not
: left
|= ~right
; break;
1190 case O_bit_exclusive_or
: left
^= right
; break;
1191 case O_bit_and
: left
&= right
; break;
1192 case O_add
: left
+= right
; break;
1193 case O_subtract
: left
-= right
; break;
1196 left
= (left
== right
&& seg_left
== seg_right
1197 && (seg_left
!= undefined_section
1198 || add_symbol
== op_symbol
)
1199 ? ~ (offsetT
) 0 : 0);
1200 if (symp
->sy_value
.X_op
== O_ne
)
1203 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1204 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1205 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1206 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1207 case O_logical_and
: left
= left
&& right
; break;
1208 case O_logical_or
: left
= left
|| right
; break;
1212 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1213 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1215 if (seg_left
== undefined_section
1216 || seg_right
== undefined_section
)
1217 final_seg
= undefined_section
;
1218 else if (seg_left
== absolute_section
)
1219 final_seg
= seg_right
;
1221 final_seg
= seg_left
;
1223 resolved
= (symbol_resolved_p (add_symbol
)
1224 && symbol_resolved_p (op_symbol
));
1230 /* Give an error (below) if not in expr_section. We don't
1231 want to worry about expr_section symbols, because they
1232 are fictional (they are created as part of expression
1233 resolution), and any problems may not actually mean
1238 symp
->sy_resolving
= 0;
1242 S_SET_VALUE (symp
, final_val
);
1244 exit_dont_set_value
:
1245 /* Always set the segment, even if not finalizing the value.
1246 The segment is used to determine whether a symbol is defined. */
1247 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1248 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1249 for a stab symbol, so we use this bad hack. */
1250 if (final_seg
!= S_GET_SEGMENT (symp
))
1252 S_SET_SEGMENT (symp
, final_seg
);
1254 /* Don't worry if we can't resolve an expr_section symbol. */
1258 symp
->sy_resolved
= 1;
1259 else if (S_GET_SEGMENT (symp
) != expr_section
)
1261 as_bad (_("can't resolve value for symbol `%s'"),
1263 symp
->sy_resolved
= 1;
1270 #ifdef BFD_ASSEMBLER
1272 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1274 /* A static function passed to hash_traverse. */
1277 resolve_local_symbol (key
, value
)
1278 const char *key ATTRIBUTE_UNUSED
;
1282 resolve_symbol_value (value
);
1287 /* Resolve all local symbols. */
1290 resolve_local_symbol_values ()
1292 #ifdef BFD_ASSEMBLER
1293 hash_traverse (local_hash
, resolve_local_symbol
);
1297 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1298 They are *really* local. That is, they go out of scope whenever we see a
1299 label that isn't local. Also, like fb labels, there can be multiple
1300 instances of a dollar label. Therefor, we name encode each instance with
1301 the instance number, keep a list of defined symbols separate from the real
1302 symbol table, and we treat these buggers as a sparse array. */
1304 static long *dollar_labels
;
1305 static long *dollar_label_instances
;
1306 static char *dollar_label_defines
;
1307 static unsigned long dollar_label_count
;
1308 static unsigned long dollar_label_max
;
1311 dollar_label_defined (label
)
1316 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1318 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1320 return dollar_label_defines
[i
- dollar_labels
];
1322 /* If we get here, label isn't defined. */
1327 dollar_label_instance (label
)
1332 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1334 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1336 return (dollar_label_instances
[i
- dollar_labels
]);
1338 /* If we get here, we haven't seen the label before.
1339 Therefore its instance count is zero. */
1344 dollar_label_clear ()
1346 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1349 #define DOLLAR_LABEL_BUMP_BY 10
1352 define_dollar_label (label
)
1357 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1360 ++dollar_label_instances
[i
- dollar_labels
];
1361 dollar_label_defines
[i
- dollar_labels
] = 1;
1365 /* If we get to here, we don't have label listed yet. */
1367 if (dollar_labels
== NULL
)
1369 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1370 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1371 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1372 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1373 dollar_label_count
= 0;
1375 else if (dollar_label_count
== dollar_label_max
)
1377 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1378 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1379 dollar_label_max
* sizeof (long));
1380 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1381 dollar_label_max
* sizeof (long));
1382 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1383 } /* if we needed to grow */
1385 dollar_labels
[dollar_label_count
] = label
;
1386 dollar_label_instances
[dollar_label_count
] = 1;
1387 dollar_label_defines
[dollar_label_count
] = 1;
1388 ++dollar_label_count
;
1391 /* Caller must copy returned name: we re-use the area for the next name.
1393 The mth occurence of label n: is turned into the symbol "Ln^Am"
1394 where n is the label number and m is the instance number. "L" makes
1395 it a label discarded unless debugging and "^A"('\1') ensures no
1396 ordinary symbol SHOULD get the same name as a local label
1397 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1399 fb labels get the same treatment, except that ^B is used in place
1402 char * /* Return local label name. */
1403 dollar_label_name (n
, augend
)
1404 register long n
; /* we just saw "n$:" : n a number. */
1405 register int augend
; /* 0 for current instance, 1 for new instance. */
1408 /* Returned to caller, then copied. Used for created names ("4f"). */
1409 static char symbol_name_build
[24];
1412 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1415 know (augend
== 0 || augend
== 1);
1416 p
= symbol_name_build
;
1417 #ifdef LOCAL_LABEL_PREFIX
1418 *p
++ = LOCAL_LABEL_PREFIX
;
1422 /* Next code just does sprintf( {}, "%d", n); */
1424 q
= symbol_name_temporary
;
1425 for (*q
++ = 0, i
= n
; i
; ++q
)
1430 while ((*p
= *--q
) != '\0')
1433 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1435 /* Instance number. */
1436 q
= symbol_name_temporary
;
1437 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1442 while ((*p
++ = *--q
) != '\0');;
1444 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1445 return symbol_name_build
;
1448 /* Sombody else's idea of local labels. They are made by "n:" where n
1449 is any decimal digit. Refer to them with
1450 "nb" for previous (backward) n:
1451 or "nf" for next (forward) n:.
1453 We do a little better and let n be any number, not just a single digit, but
1454 since the other guy's assembler only does ten, we treat the first ten
1457 Like someone else's assembler, we have one set of local label counters for
1458 entire assembly, not one set per (sub)segment like in most assemblers. This
1459 implies that one can refer to a label in another segment, and indeed some
1460 crufty compilers have done just that.
1462 Since there could be a LOT of these things, treat them as a sparse
1465 #define FB_LABEL_SPECIAL (10)
1467 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1468 static long *fb_labels
;
1469 static long *fb_label_instances
;
1470 static long fb_label_count
;
1471 static long fb_label_max
;
1473 /* This must be more than FB_LABEL_SPECIAL. */
1474 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1479 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1482 /* Add one to the instance number of this fb label. */
1485 fb_label_instance_inc (label
)
1490 if (label
< FB_LABEL_SPECIAL
)
1492 ++fb_low_counter
[label
];
1496 if (fb_labels
!= NULL
)
1498 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1499 i
< fb_labels
+ fb_label_count
; ++i
)
1503 ++fb_label_instances
[i
- fb_labels
];
1505 } /* if we find it */
1506 } /* for each existing label */
1509 /* If we get to here, we don't have label listed yet. */
1511 if (fb_labels
== NULL
)
1513 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1514 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1515 fb_label_max
= FB_LABEL_BUMP_BY
;
1516 fb_label_count
= FB_LABEL_SPECIAL
;
1519 else if (fb_label_count
== fb_label_max
)
1521 fb_label_max
+= FB_LABEL_BUMP_BY
;
1522 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1523 fb_label_max
* sizeof (long));
1524 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1525 fb_label_max
* sizeof (long));
1526 } /* if we needed to grow */
1528 fb_labels
[fb_label_count
] = label
;
1529 fb_label_instances
[fb_label_count
] = 1;
1534 fb_label_instance (label
)
1539 if (label
< FB_LABEL_SPECIAL
)
1541 return (fb_low_counter
[label
]);
1544 if (fb_labels
!= NULL
)
1546 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1547 i
< fb_labels
+ fb_label_count
; ++i
)
1551 return (fb_label_instances
[i
- fb_labels
]);
1552 } /* if we find it */
1553 } /* for each existing label */
1556 /* We didn't find the label, so this must be a reference to the
1561 /* Caller must copy returned name: we re-use the area for the next name.
1563 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1564 where n is the label number and m is the instance number. "L" makes
1565 it a label discarded unless debugging and "^B"('\2') ensures no
1566 ordinary symbol SHOULD get the same name as a local label
1567 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1569 dollar labels get the same treatment, except that ^A is used in
1572 char * /* Return local label name. */
1573 fb_label_name (n
, augend
)
1574 long n
; /* We just saw "n:", "nf" or "nb" : n a number. */
1575 long augend
; /* 0 for nb, 1 for n:, nf. */
1578 /* Returned to caller, then copied. Used for created names ("4f"). */
1579 static char symbol_name_build
[24];
1582 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1585 know (augend
== 0 || augend
== 1);
1586 p
= symbol_name_build
;
1587 #ifdef LOCAL_LABEL_PREFIX
1588 *p
++ = LOCAL_LABEL_PREFIX
;
1592 /* Next code just does sprintf( {}, "%d", n); */
1594 q
= symbol_name_temporary
;
1595 for (*q
++ = 0, i
= n
; i
; ++q
)
1600 while ((*p
= *--q
) != '\0')
1603 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
1605 /* Instance number. */
1606 q
= symbol_name_temporary
;
1607 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1612 while ((*p
++ = *--q
) != '\0');;
1614 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1615 return (symbol_name_build
);
1618 /* Decode name that may have been generated by foo_label_name() above.
1619 If the name wasn't generated by foo_label_name(), then return it
1620 unaltered. This is used for error messages. */
1623 decode_local_label_name (s
)
1627 char *symbol_decode
;
1629 int instance_number
;
1631 const char *message_format
;
1634 #ifdef LOCAL_LABEL_PREFIX
1635 if (s
[index
] == LOCAL_LABEL_PREFIX
)
1639 if (s
[index
] != 'L')
1642 for (label_number
= 0, p
= s
+ index
+ 1; ISDIGIT (*p
); ++p
)
1643 label_number
= (10 * label_number
) + *p
- '0';
1645 if (*p
== DOLLAR_LABEL_CHAR
)
1647 else if (*p
== LOCAL_LABEL_CHAR
)
1652 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
1653 instance_number
= (10 * instance_number
) + *p
- '0';
1655 message_format
= _("\"%d\" (instance number %d of a %s label)");
1656 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1657 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1659 return symbol_decode
;
1662 /* Get the value of a symbol. */
1668 #ifdef BFD_ASSEMBLER
1669 if (LOCAL_SYMBOL_CHECK (s
))
1670 return resolve_symbol_value (s
);
1673 if (!s
->sy_resolved
)
1675 valueT val
= resolve_symbol_value (s
);
1679 if (s
->sy_value
.X_op
!= O_constant
)
1681 static symbolS
*recur
;
1683 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1684 may call S_GET_VALUE. We use a static symbol to avoid the
1685 immediate recursion. */
1687 return (valueT
) s
->sy_value
.X_add_number
;
1689 if (! s
->sy_resolved
1690 || s
->sy_value
.X_op
!= O_symbol
1691 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1692 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1696 return (valueT
) s
->sy_value
.X_add_number
;
1699 /* Set the value of a symbol. */
1702 S_SET_VALUE (s
, val
)
1706 #ifdef BFD_ASSEMBLER
1707 if (LOCAL_SYMBOL_CHECK (s
))
1709 ((struct local_symbol
*) s
)->lsy_value
= val
;
1714 s
->sy_value
.X_op
= O_constant
;
1715 s
->sy_value
.X_add_number
= (offsetT
) val
;
1716 s
->sy_value
.X_unsigned
= 0;
1720 copy_symbol_attributes (dest
, src
)
1721 symbolS
*dest
, *src
;
1723 if (LOCAL_SYMBOL_CHECK (dest
))
1724 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
1725 if (LOCAL_SYMBOL_CHECK (src
))
1726 src
= local_symbol_convert ((struct local_symbol
*) src
);
1728 #ifdef BFD_ASSEMBLER
1729 /* In an expression, transfer the settings of these flags.
1730 The user can override later, of course. */
1731 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1732 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1735 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1736 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1740 #ifdef BFD_ASSEMBLER
1748 if (LOCAL_SYMBOL_CHECK (s
))
1751 flags
= s
->bsym
->flags
;
1753 return (flags
& BSF_FUNCTION
) != 0;
1762 if (LOCAL_SYMBOL_CHECK (s
))
1765 flags
= s
->bsym
->flags
;
1768 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1771 return (flags
& BSF_GLOBAL
) != 0;
1778 if (LOCAL_SYMBOL_CHECK (s
))
1780 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1787 if (LOCAL_SYMBOL_CHECK (s
))
1789 return bfd_is_com_section (s
->bsym
->section
);
1796 if (LOCAL_SYMBOL_CHECK (s
))
1797 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1798 return s
->bsym
->section
!= undefined_section
;
1802 #ifndef EXTERN_FORCE_RELOC
1803 #define EXTERN_FORCE_RELOC IS_ELF
1806 /* Return true for symbols that should not be reduced to section
1807 symbols or eliminated from expressions, because they may be
1808 overridden by the linker. */
1810 S_FORCE_RELOC (s
, strict
)
1814 if (LOCAL_SYMBOL_CHECK (s
))
1815 return ((struct local_symbol
*) s
)->lsy_section
== undefined_section
;
1818 && ((s
->bsym
->flags
& BSF_WEAK
) != 0
1819 || (EXTERN_FORCE_RELOC
1820 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)))
1821 || s
->bsym
->section
== undefined_section
1822 || bfd_is_com_section (s
->bsym
->section
));
1829 if (LOCAL_SYMBOL_CHECK (s
))
1831 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1843 if (LOCAL_SYMBOL_CHECK (s
))
1846 flags
= s
->bsym
->flags
;
1849 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1852 if (bfd_get_section (s
->bsym
) == reg_section
)
1855 if (flag_strip_local_absolute
1856 && (flags
& BSF_GLOBAL
) == 0
1857 && bfd_get_section (s
->bsym
) == absolute_section
)
1860 name
= S_GET_NAME (s
);
1861 return (name
!= NULL
1863 && (strchr (name
, DOLLAR_LABEL_CHAR
)
1864 || strchr (name
, LOCAL_LABEL_CHAR
)
1865 || (! flag_keep_locals
1866 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1869 && name
[1] == '?')))));
1876 return S_IS_EXTERNAL (s
);
1883 return S_GET_NAME (s
) == 0;
1890 if (LOCAL_SYMBOL_CHECK (s
))
1891 return ((struct local_symbol
*) s
)->lsy_name
;
1892 return s
->bsym
->name
;
1899 if (LOCAL_SYMBOL_CHECK (s
))
1900 return ((struct local_symbol
*) s
)->lsy_section
;
1901 return s
->bsym
->section
;
1905 S_SET_SEGMENT (s
, seg
)
1909 /* Don't reassign section symbols. The direct reason is to prevent seg
1910 faults assigning back to const global symbols such as *ABS*, but it
1911 shouldn't happen anyway. */
1913 if (LOCAL_SYMBOL_CHECK (s
))
1915 if (seg
== reg_section
)
1916 s
= local_symbol_convert ((struct local_symbol
*) s
);
1919 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1924 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1926 if (s
->bsym
->section
!= seg
)
1930 s
->bsym
->section
= seg
;
1937 if (LOCAL_SYMBOL_CHECK (s
))
1938 s
= local_symbol_convert ((struct local_symbol
*) s
);
1939 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1941 /* Let .weak override .global. */
1944 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1949 /* Do not reassign section symbols. */
1950 as_where (& file
, & line
);
1951 as_warn_where (file
, line
,
1952 _("section symbols are already global"));
1955 s
->bsym
->flags
|= BSF_GLOBAL
;
1956 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
1960 S_CLEAR_EXTERNAL (s
)
1963 if (LOCAL_SYMBOL_CHECK (s
))
1965 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1967 /* Let .weak override. */
1970 s
->bsym
->flags
|= BSF_LOCAL
;
1971 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
1978 if (LOCAL_SYMBOL_CHECK (s
))
1979 s
= local_symbol_convert ((struct local_symbol
*) s
);
1980 s
->bsym
->flags
|= BSF_WEAK
;
1981 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
1985 S_SET_THREAD_LOCAL (s
)
1988 if (LOCAL_SYMBOL_CHECK (s
))
1989 s
= local_symbol_convert ((struct local_symbol
*) s
);
1990 if (bfd_is_com_section (s
->bsym
->section
)
1991 && (s
->bsym
->flags
& BSF_THREAD_LOCAL
) != 0)
1993 s
->bsym
->flags
|= BSF_THREAD_LOCAL
;
1994 if ((s
->bsym
->flags
& BSF_FUNCTION
) != 0)
1995 as_bad (_("Accessing function `%s' as thread-local object"),
1997 else if (! bfd_is_und_section (s
->bsym
->section
)
1998 && (s
->bsym
->section
->flags
& SEC_THREAD_LOCAL
) == 0)
1999 as_bad (_("Accessing `%s' as thread-local object"),
2004 S_SET_NAME (s
, name
)
2008 if (LOCAL_SYMBOL_CHECK (s
))
2010 ((struct local_symbol
*) s
)->lsy_name
= name
;
2013 s
->bsym
->name
= name
;
2015 #endif /* BFD_ASSEMBLER */
2017 #ifdef SYMBOLS_NEED_BACKPOINTERS
2019 /* Return the previous symbol in a chain. */
2025 if (LOCAL_SYMBOL_CHECK (s
))
2027 return s
->sy_previous
;
2030 #endif /* SYMBOLS_NEED_BACKPOINTERS */
2032 /* Return the next symbol in a chain. */
2038 if (LOCAL_SYMBOL_CHECK (s
))
2043 /* Return a pointer to the value of a symbol as an expression. */
2046 symbol_get_value_expression (s
)
2049 if (LOCAL_SYMBOL_CHECK (s
))
2050 s
= local_symbol_convert ((struct local_symbol
*) s
);
2051 return &s
->sy_value
;
2054 /* Set the value of a symbol to an expression. */
2057 symbol_set_value_expression (s
, exp
)
2059 const expressionS
*exp
;
2061 if (LOCAL_SYMBOL_CHECK (s
))
2062 s
= local_symbol_convert ((struct local_symbol
*) s
);
2066 /* Set the frag of a symbol. */
2069 symbol_set_frag (s
, f
)
2073 #ifdef BFD_ASSEMBLER
2074 if (LOCAL_SYMBOL_CHECK (s
))
2076 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
2083 /* Return the frag of a symbol. */
2089 #ifdef BFD_ASSEMBLER
2090 if (LOCAL_SYMBOL_CHECK (s
))
2091 return local_symbol_get_frag ((struct local_symbol
*) s
);
2096 /* Mark a symbol as having been used. */
2099 symbol_mark_used (s
)
2102 if (LOCAL_SYMBOL_CHECK (s
))
2107 /* Clear the mark of whether a symbol has been used. */
2110 symbol_clear_used (s
)
2113 if (LOCAL_SYMBOL_CHECK (s
))
2114 s
= local_symbol_convert ((struct local_symbol
*) s
);
2118 /* Return whether a symbol has been used. */
2124 if (LOCAL_SYMBOL_CHECK (s
))
2129 /* Mark a symbol as having been used in a reloc. */
2132 symbol_mark_used_in_reloc (s
)
2135 if (LOCAL_SYMBOL_CHECK (s
))
2136 s
= local_symbol_convert ((struct local_symbol
*) s
);
2137 s
->sy_used_in_reloc
= 1;
2140 /* Clear the mark of whether a symbol has been used in a reloc. */
2143 symbol_clear_used_in_reloc (s
)
2146 if (LOCAL_SYMBOL_CHECK (s
))
2148 s
->sy_used_in_reloc
= 0;
2151 /* Return whether a symbol has been used in a reloc. */
2154 symbol_used_in_reloc_p (s
)
2157 if (LOCAL_SYMBOL_CHECK (s
))
2159 return s
->sy_used_in_reloc
;
2162 /* Mark a symbol as an MRI common symbol. */
2165 symbol_mark_mri_common (s
)
2168 if (LOCAL_SYMBOL_CHECK (s
))
2169 s
= local_symbol_convert ((struct local_symbol
*) s
);
2170 s
->sy_mri_common
= 1;
2173 /* Clear the mark of whether a symbol is an MRI common symbol. */
2176 symbol_clear_mri_common (s
)
2179 if (LOCAL_SYMBOL_CHECK (s
))
2181 s
->sy_mri_common
= 0;
2184 /* Return whether a symbol is an MRI common symbol. */
2187 symbol_mri_common_p (s
)
2190 if (LOCAL_SYMBOL_CHECK (s
))
2192 return s
->sy_mri_common
;
2195 /* Mark a symbol as having been written. */
2198 symbol_mark_written (s
)
2201 if (LOCAL_SYMBOL_CHECK (s
))
2206 /* Clear the mark of whether a symbol has been written. */
2209 symbol_clear_written (s
)
2212 if (LOCAL_SYMBOL_CHECK (s
))
2217 /* Return whether a symbol has been written. */
2220 symbol_written_p (s
)
2223 if (LOCAL_SYMBOL_CHECK (s
))
2228 /* Mark a symbol has having been resolved. */
2231 symbol_mark_resolved (s
)
2234 #ifdef BFD_ASSEMBLER
2235 if (LOCAL_SYMBOL_CHECK (s
))
2237 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2244 /* Return whether a symbol has been resolved. */
2247 symbol_resolved_p (s
)
2250 #ifdef BFD_ASSEMBLER
2251 if (LOCAL_SYMBOL_CHECK (s
))
2252 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2254 return s
->sy_resolved
;
2257 /* Return whether a symbol is a section symbol. */
2260 symbol_section_p (s
)
2261 symbolS
*s ATTRIBUTE_UNUSED
;
2263 if (LOCAL_SYMBOL_CHECK (s
))
2265 #ifdef BFD_ASSEMBLER
2266 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2273 /* Return whether a symbol is equated to another symbol. */
2276 symbol_equated_p (s
)
2279 if (LOCAL_SYMBOL_CHECK (s
))
2281 return s
->sy_value
.X_op
== O_symbol
;
2284 /* Return whether a symbol is equated to another symbol, and should be
2285 treated specially when writing out relocs. */
2288 symbol_equated_reloc_p (s
)
2291 if (LOCAL_SYMBOL_CHECK (s
))
2293 /* X_op_symbol, normally not used for O_symbol, is set by
2294 resolve_symbol_value to flag expression syms that have been
2296 return (s
->sy_value
.X_op
== O_symbol
2297 && ((s
->sy_resolved
&& s
->sy_value
.X_op_symbol
!= NULL
)
2298 || ! S_IS_DEFINED (s
)
2299 || S_IS_COMMON (s
)));
2302 /* Return whether a symbol has a constant value. */
2305 symbol_constant_p (s
)
2308 if (LOCAL_SYMBOL_CHECK (s
))
2310 return s
->sy_value
.X_op
== O_constant
;
2313 #ifdef BFD_ASSEMBLER
2315 /* Return the BFD symbol for a symbol. */
2318 symbol_get_bfdsym (s
)
2321 if (LOCAL_SYMBOL_CHECK (s
))
2322 s
= local_symbol_convert ((struct local_symbol
*) s
);
2326 /* Set the BFD symbol for a symbol. */
2329 symbol_set_bfdsym (s
, bsym
)
2333 if (LOCAL_SYMBOL_CHECK (s
))
2334 s
= local_symbol_convert ((struct local_symbol
*) s
);
2338 #endif /* BFD_ASSEMBLER */
2340 #ifdef OBJ_SYMFIELD_TYPE
2342 /* Get a pointer to the object format information for a symbol. */
2348 if (LOCAL_SYMBOL_CHECK (s
))
2349 s
= local_symbol_convert ((struct local_symbol
*) s
);
2353 /* Set the object format information for a symbol. */
2356 symbol_set_obj (s
, o
)
2358 OBJ_SYMFIELD_TYPE
*o
;
2360 if (LOCAL_SYMBOL_CHECK (s
))
2361 s
= local_symbol_convert ((struct local_symbol
*) s
);
2365 #endif /* OBJ_SYMFIELD_TYPE */
2367 #ifdef TC_SYMFIELD_TYPE
2369 /* Get a pointer to the processor information for a symbol. */
2375 if (LOCAL_SYMBOL_CHECK (s
))
2376 s
= local_symbol_convert ((struct local_symbol
*) s
);
2380 /* Set the processor information for a symbol. */
2383 symbol_set_tc (s
, o
)
2385 TC_SYMFIELD_TYPE
*o
;
2387 if (LOCAL_SYMBOL_CHECK (s
))
2388 s
= local_symbol_convert ((struct local_symbol
*) s
);
2392 #endif /* TC_SYMFIELD_TYPE */
2397 symbol_lastP
= NULL
;
2398 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2399 sy_hash
= hash_new ();
2400 #ifdef BFD_ASSEMBLER
2401 local_hash
= hash_new ();
2404 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2405 #ifdef BFD_ASSEMBLER
2406 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2407 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2410 /* Can't initialise a union. Sigh. */
2411 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2413 abs_symbol
.sy_value
.X_op
= O_constant
;
2414 abs_symbol
.sy_frag
= &zero_address_frag
;
2416 if (LOCAL_LABELS_FB
)
2422 /* Maximum indent level.
2423 Available for modification inside a gdb session. */
2424 int max_indent_level
= 8;
2431 printf ("%*s", indent_level
* 4, "");
2437 print_symbol_value_1 (file
, sym
)
2441 const char *name
= S_GET_NAME (sym
);
2442 if (!name
|| !name
[0])
2444 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2446 if (LOCAL_SYMBOL_CHECK (sym
))
2448 #ifdef BFD_ASSEMBLER
2449 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2450 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2451 && local_symbol_get_frag (locsym
) != NULL
)
2452 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2453 if (local_symbol_resolved_p (locsym
))
2454 fprintf (file
, " resolved");
2455 fprintf (file
, " local");
2460 if (sym
->sy_frag
!= &zero_address_frag
)
2461 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2463 fprintf (file
, " written");
2464 if (sym
->sy_resolved
)
2465 fprintf (file
, " resolved");
2466 else if (sym
->sy_resolving
)
2467 fprintf (file
, " resolving");
2468 if (sym
->sy_used_in_reloc
)
2469 fprintf (file
, " used-in-reloc");
2471 fprintf (file
, " used");
2472 if (S_IS_LOCAL (sym
))
2473 fprintf (file
, " local");
2474 if (S_IS_EXTERN (sym
))
2475 fprintf (file
, " extern");
2476 if (S_IS_DEBUG (sym
))
2477 fprintf (file
, " debug");
2478 if (S_IS_DEFINED (sym
))
2479 fprintf (file
, " defined");
2481 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2482 if (symbol_resolved_p (sym
))
2484 segT s
= S_GET_SEGMENT (sym
);
2486 if (s
!= undefined_section
2487 && s
!= expr_section
)
2488 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2490 else if (indent_level
< max_indent_level
2491 && S_GET_SEGMENT (sym
) != undefined_section
)
2494 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2495 #ifdef BFD_ASSEMBLER
2496 if (LOCAL_SYMBOL_CHECK (sym
))
2497 fprintf (file
, "constant %lx",
2498 (long) ((struct local_symbol
*) sym
)->lsy_value
);
2501 print_expr_1 (file
, &sym
->sy_value
);
2502 fprintf (file
, ">");
2509 print_symbol_value (sym
)
2513 print_symbol_value_1 (stderr
, sym
);
2514 fprintf (stderr
, "\n");
2518 print_binary (file
, name
, exp
)
2524 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2525 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2526 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2527 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2528 fprintf (file
, ">");
2533 print_expr_1 (file
, exp
)
2537 fprintf (file
, "expr %lx ", (long) exp
);
2541 fprintf (file
, "illegal");
2544 fprintf (file
, "absent");
2547 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2551 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2552 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2553 fprintf (file
, ">");
2555 if (exp
->X_add_number
)
2556 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2557 (long) exp
->X_add_number
);
2561 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2564 fprintf (file
, "big");
2567 fprintf (file
, "uminus -<");
2569 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2570 fprintf (file
, ">");
2571 goto maybe_print_addnum
;
2573 fprintf (file
, "bit_not");
2576 print_binary (file
, "multiply", exp
);
2579 print_binary (file
, "divide", exp
);
2582 print_binary (file
, "modulus", exp
);
2585 print_binary (file
, "lshift", exp
);
2588 print_binary (file
, "rshift", exp
);
2590 case O_bit_inclusive_or
:
2591 print_binary (file
, "bit_ior", exp
);
2593 case O_bit_exclusive_or
:
2594 print_binary (file
, "bit_xor", exp
);
2597 print_binary (file
, "bit_and", exp
);
2600 print_binary (file
, "eq", exp
);
2603 print_binary (file
, "ne", exp
);
2606 print_binary (file
, "lt", exp
);
2609 print_binary (file
, "le", exp
);
2612 print_binary (file
, "ge", exp
);
2615 print_binary (file
, "gt", exp
);
2618 print_binary (file
, "logical_and", exp
);
2621 print_binary (file
, "logical_or", exp
);
2625 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2626 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2627 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2628 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2629 fprintf (file
, ">");
2630 goto maybe_print_addnum
;
2633 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
2634 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2635 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2636 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2637 fprintf (file
, ">");
2638 goto maybe_print_addnum
;
2640 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2650 print_expr_1 (stderr
, exp
);
2651 fprintf (stderr
, "\n");
2655 symbol_print_statistics (file
)
2658 hash_print_statistics (file
, "symbol table", sy_hash
);
2659 #ifdef BFD_ASSEMBLER
2660 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2661 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2662 local_symbol_count
, local_symbol_conversion_count
);