1 /* symbols.c -symbol table-
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* #define DEBUG_SYMS / * to debug symbol list maintenance. */
29 #include "obstack.h" /* For "symbols.h" */
32 #include "struc-symbol.h"
34 /* This is non-zero if symbols are case sensitive, which is the
36 int symbols_case_sensitive
= 1;
38 #ifndef WORKING_DOT_WORD
39 extern int new_broken_words
;
42 /* symbol-name => struct symbol pointer */
43 static struct hash_control
*sy_hash
;
45 /* Table of local symbols. */
46 static struct hash_control
*local_hash
;
48 /* Below are commented in "symbols.h". */
49 symbolS
*symbol_rootP
;
50 symbolS
*symbol_lastP
;
54 #define debug_verify_symchain verify_symbol_chain
56 #define debug_verify_symchain(root, last) ((void) 0)
59 #define DOLLAR_LABEL_CHAR '\001'
60 #define LOCAL_LABEL_CHAR '\002'
64 static char *save_symbol_name
PARAMS ((const char *));
65 static void fb_label_init
PARAMS ((void));
66 static long dollar_label_instance
PARAMS ((long));
67 static long fb_label_instance
PARAMS ((long));
69 static void print_binary
PARAMS ((FILE *, const char *, expressionS
*));
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
= (unsigned char *) ret
; *s
!= '\0'; s
++)
138 symbol_create (name
, segment
, valu
, frag
)
139 const char *name
; /* It is copied, the caller can destroy/modify. */
140 segT segment
; /* Segment identifier (SEG_<something>). */
141 valueT valu
; /* Symbol value. */
142 fragS
*frag
; /* Associated fragment. */
144 char *preserved_copy_of_name
;
147 preserved_copy_of_name
= save_symbol_name (name
);
149 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
151 /* symbol must be born in some fixed state. This seems as good as any. */
152 memset (symbolP
, 0, sizeof (symbolS
));
155 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
156 if (symbolP
->bsym
== NULL
)
157 as_perror ("%s", "bfd_make_empty_symbol");
158 symbolP
->bsym
->udata
.p
= (PTR
) symbolP
;
160 S_SET_NAME (symbolP
, preserved_copy_of_name
);
162 S_SET_SEGMENT (symbolP
, segment
);
163 S_SET_VALUE (symbolP
, valu
);
164 symbol_clear_list_pointers (symbolP
);
166 symbolP
->sy_frag
= frag
;
167 #ifndef BFD_ASSEMBLER
168 symbolP
->sy_number
= ~0;
169 symbolP
->sy_name_offset
= (unsigned int) ~0;
172 obj_symbol_new_hook (symbolP
);
174 #ifdef tc_symbol_new_hook
175 tc_symbol_new_hook (symbolP
);
183 /* Local symbol support. If we can get away with it, we keep only a
184 small amount of information for local symbols. */
186 static struct local_symbol
*local_symbol_make
PARAMS ((const char *, segT
,
188 static symbolS
*local_symbol_convert
PARAMS ((struct local_symbol
*));
190 /* Used for statistics. */
192 static unsigned long local_symbol_count
;
193 static unsigned long local_symbol_conversion_count
;
195 /* This macro is called with a symbol argument passed by reference.
196 It returns whether this is a local symbol. If necessary, it
197 changes its argument to the real symbol. */
199 #define LOCAL_SYMBOL_CHECK(s) \
201 ? (local_symbol_converted_p ((struct local_symbol *) s) \
202 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
207 /* Create a local symbol and insert it into the local hash table. */
209 static struct local_symbol
*
210 local_symbol_make (name
, section
, value
, frag
)
217 struct local_symbol
*ret
;
219 ++local_symbol_count
;
221 name_copy
= save_symbol_name (name
);
223 ret
= (struct local_symbol
*) obstack_alloc (¬es
, sizeof *ret
);
224 ret
->lsy_marker
= NULL
;
225 ret
->lsy_name
= name_copy
;
226 ret
->lsy_section
= section
;
227 local_symbol_set_frag (ret
, frag
);
228 ret
->lsy_value
= value
;
230 hash_jam (local_hash
, name_copy
, (PTR
) ret
);
235 /* Convert a local symbol into a real symbol. Note that we do not
236 reclaim the space used by the local symbol. */
239 local_symbol_convert (locsym
)
240 struct local_symbol
*locsym
;
244 assert (locsym
->lsy_marker
== NULL
);
245 if (local_symbol_converted_p (locsym
))
246 return local_symbol_get_real_symbol (locsym
);
248 ++local_symbol_conversion_count
;
250 ret
= symbol_new (locsym
->lsy_name
, locsym
->lsy_section
, locsym
->lsy_value
,
251 local_symbol_get_frag (locsym
));
253 if (local_symbol_resolved_p (locsym
))
254 ret
->sy_resolved
= 1;
256 /* Local symbols are always either defined or used. */
259 #ifdef TC_LOCAL_SYMFIELD_CONVERT
260 TC_LOCAL_SYMFIELD_CONVERT (locsym
, ret
);
263 symbol_table_insert (ret
);
265 local_symbol_mark_converted (locsym
);
266 local_symbol_set_real_symbol (locsym
, ret
);
268 hash_jam (local_hash
, locsym
->lsy_name
, NULL
);
273 #else /* ! BFD_ASSEMBLER */
275 #define LOCAL_SYMBOL_CHECK(s) 0
276 #define local_symbol_convert(s) ((symbolS *) s)
278 #endif /* ! BFD_ASSEMBLER */
280 /* We have just seen "<name>:".
281 Creates a struct symbol unless it already exists.
283 Gripes if we are redefining a symbol incompatibly (and ignores it). */
286 colon (sym_name
) /* Just seen "x:" - rattle symbols & frags. */
287 const char *sym_name
; /* Symbol name, as a cannonical string. */
288 /* We copy this string: OK to alter later. */
290 register symbolS
*symbolP
; /* Symbol we are working with. */
292 /* Sun local labels go out of scope whenever a non-local symbol is
294 if (LOCAL_LABELS_DOLLAR
)
299 local
= bfd_is_local_label_name (stdoutput
, sym_name
);
301 local
= LOCAL_LABEL (sym_name
);
305 dollar_label_clear ();
308 #ifndef WORKING_DOT_WORD
309 if (new_broken_words
)
311 struct broken_word
*a
;
316 extern const int md_short_jump_size
;
317 extern const int md_long_jump_size
;
318 possible_bytes
= (md_short_jump_size
319 + new_broken_words
* md_long_jump_size
);
322 frag_opcode
= frag_var (rs_broken_word
,
326 (symbolS
*) broken_words
,
330 /* We want to store the pointer to where to insert the jump
331 table in the fr_opcode of the rs_broken_word frag. This
332 requires a little hackery. */
334 && (frag_tmp
->fr_type
!= rs_broken_word
335 || frag_tmp
->fr_opcode
))
336 frag_tmp
= frag_tmp
->fr_next
;
338 frag_tmp
->fr_opcode
= frag_opcode
;
339 new_broken_words
= 0;
341 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
342 a
->dispfrag
= frag_tmp
;
344 #endif /* WORKING_DOT_WORD */
346 if ((symbolP
= symbol_find (sym_name
)) != 0)
348 #ifdef RESOLVE_SYMBOL_REDEFINITION
349 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
352 /* Now check for undefined symbols. */
353 if (LOCAL_SYMBOL_CHECK (symbolP
))
356 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
358 if (locsym
->lsy_section
!= undefined_section
359 && (local_symbol_get_frag (locsym
) != frag_now
360 || locsym
->lsy_section
!= now_seg
361 || locsym
->lsy_value
!= frag_now_fix ()))
363 as_bad (_("symbol `%s' is already defined"), sym_name
);
367 locsym
->lsy_section
= now_seg
;
368 local_symbol_set_frag (locsym
, frag_now
);
369 locsym
->lsy_value
= frag_now_fix ();
372 else if (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
374 if (S_GET_VALUE (symbolP
) == 0)
376 symbolP
->sy_frag
= frag_now
;
378 S_SET_OTHER (symbolP
, const_flag
);
380 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
381 S_SET_SEGMENT (symbolP
, now_seg
);
384 #endif /* if we have one, it better be zero. */
389 /* There are still several cases to check:
391 A .comm/.lcomm symbol being redefined as initialized
394 A .comm/.lcomm symbol being redefined with a larger
397 This only used to be allowed on VMS gas, but Sun cc
398 on the sparc also depends on it. */
400 if (((!S_IS_DEBUG (symbolP
)
401 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
402 && S_IS_EXTERNAL (symbolP
))
403 || S_GET_SEGMENT (symbolP
) == bss_section
)
404 && (now_seg
== data_section
405 || now_seg
== S_GET_SEGMENT (symbolP
)))
407 /* Select which of the 2 cases this is. */
408 if (now_seg
!= data_section
)
410 /* New .comm for prev .comm symbol.
412 If the new size is larger we just change its
413 value. If the new size is smaller, we ignore
415 if (S_GET_VALUE (symbolP
)
416 < ((unsigned) frag_now_fix ()))
418 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
423 /* It is a .comm/.lcomm being converted to initialized
425 symbolP
->sy_frag
= frag_now
;
427 S_SET_OTHER (symbolP
, const_flag
);
429 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
430 S_SET_SEGMENT (symbolP
, now_seg
); /* Keep N_EXT bit. */
435 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
436 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
437 static const char *od_buf
= "";
442 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
444 sprintf(od_buf
, "%d.%d.",
445 S_GET_OTHER (symbolP
),
446 S_GET_DESC (symbolP
));
448 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
450 segment_name (S_GET_SEGMENT (symbolP
)),
452 (long) S_GET_VALUE (symbolP
));
454 } /* if the undefined symbol has no value */
458 /* Don't blow up if the definition is the same. */
459 if (!(frag_now
== symbolP
->sy_frag
460 && S_GET_VALUE (symbolP
) == frag_now_fix ()
461 && S_GET_SEGMENT (symbolP
) == now_seg
))
462 as_bad (_("symbol `%s' is already defined"), sym_name
);
467 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
469 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
470 (valueT
) frag_now_fix (),
473 #endif /* BFD_ASSEMBLER */
476 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
479 S_SET_OTHER (symbolP
, const_flag
);
482 symbol_table_insert (symbolP
);
485 if (mri_common_symbol
!= NULL
)
487 /* This symbol is actually being defined within an MRI common
488 section. This requires special handling. */
489 if (LOCAL_SYMBOL_CHECK (symbolP
))
490 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
491 symbolP
->sy_value
.X_op
= O_symbol
;
492 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
493 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
494 symbolP
->sy_frag
= &zero_address_frag
;
495 S_SET_SEGMENT (symbolP
, expr_section
);
496 symbolP
->sy_mri_common
= 1;
500 tc_frob_label (symbolP
);
502 #ifdef obj_frob_label
503 obj_frob_label (symbolP
);
509 /* Die if we can't insert the symbol. */
512 symbol_table_insert (symbolP
)
515 register const char *error_string
;
518 know (S_GET_NAME (symbolP
));
520 if (LOCAL_SYMBOL_CHECK (symbolP
))
522 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
524 if (error_string
!= NULL
)
525 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
526 S_GET_NAME (symbolP
), error_string
);
530 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
532 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
533 S_GET_NAME (symbolP
), error_string
);
537 /* If a symbol name does not exist, create it as undefined, and insert
538 it into the symbol table. Return a pointer to it. */
541 symbol_find_or_make (name
)
544 register symbolS
*symbolP
;
546 symbolP
= symbol_find (name
);
551 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
553 symbolP
= md_undefined_symbol ((char *) name
);
557 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
564 symbolP
= symbol_make (name
);
566 symbol_table_insert (symbolP
);
567 } /* if symbol wasn't found */
578 /* Let the machine description default it, e.g. for register names. */
579 symbolP
= md_undefined_symbol ((char *) name
);
582 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
587 /* Implement symbol table lookup.
588 In: A symbol's name as a string: '\0' can't be part of a symbol name.
589 Out: NULL if the name was not in the symbol table, else the address
590 of a struct symbol associated with that name. */
596 #ifdef STRIP_UNDERSCORE
597 return (symbol_find_base (name
, 1));
598 #else /* STRIP_UNDERSCORE */
599 return (symbol_find_base (name
, 0));
600 #endif /* STRIP_UNDERSCORE */
604 symbol_find_base (name
, strip_underscore
)
606 int strip_underscore
;
608 if (strip_underscore
&& *name
== '_')
611 #ifdef tc_canonicalize_symbol_name
614 size_t len
= strlen (name
) + 1;
616 copy
= (char *) alloca (len
);
617 memcpy (copy
, name
, len
);
618 name
= tc_canonicalize_symbol_name (copy
);
622 if (! symbols_case_sensitive
)
629 name
= copy
= (char *) alloca (strlen (name
) + 1);
631 while ((c
= *orig
++) != '\0')
642 struct local_symbol
*locsym
;
644 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
646 return (symbolS
*) locsym
;
650 return ((symbolS
*) hash_find (sy_hash
, name
));
653 /* Once upon a time, symbols were kept in a singly linked list. At
654 least coff needs to be able to rearrange them from time to time, for
655 which a doubly linked list is much more convenient. Loic did these
656 as macros which seemed dangerous to me so they're now functions.
659 /* Link symbol ADDME after symbol TARGET in the chain. */
662 symbol_append (addme
, target
, rootPP
, lastPP
)
668 if (LOCAL_SYMBOL_CHECK (addme
))
670 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
675 know (*rootPP
== NULL
);
676 know (*lastPP
== NULL
);
677 addme
->sy_next
= NULL
;
678 #ifdef SYMBOLS_NEED_BACKPOINTERS
679 addme
->sy_previous
= NULL
;
684 } /* if the list is empty */
686 if (target
->sy_next
!= NULL
)
688 #ifdef SYMBOLS_NEED_BACKPOINTERS
689 target
->sy_next
->sy_previous
= addme
;
690 #endif /* SYMBOLS_NEED_BACKPOINTERS */
694 know (*lastPP
== target
);
696 } /* if we have a next */
698 addme
->sy_next
= target
->sy_next
;
699 target
->sy_next
= addme
;
701 #ifdef SYMBOLS_NEED_BACKPOINTERS
702 addme
->sy_previous
= target
;
703 #endif /* SYMBOLS_NEED_BACKPOINTERS */
705 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
708 /* Set the chain pointers of SYMBOL to null. */
711 symbol_clear_list_pointers (symbolP
)
714 if (LOCAL_SYMBOL_CHECK (symbolP
))
716 symbolP
->sy_next
= NULL
;
717 #ifdef SYMBOLS_NEED_BACKPOINTERS
718 symbolP
->sy_previous
= NULL
;
722 #ifdef SYMBOLS_NEED_BACKPOINTERS
723 /* Remove SYMBOLP from the list. */
726 symbol_remove (symbolP
, rootPP
, lastPP
)
731 if (LOCAL_SYMBOL_CHECK (symbolP
))
734 if (symbolP
== *rootPP
)
736 *rootPP
= symbolP
->sy_next
;
737 } /* if it was the root */
739 if (symbolP
== *lastPP
)
741 *lastPP
= symbolP
->sy_previous
;
742 } /* if it was the tail */
744 if (symbolP
->sy_next
!= NULL
)
746 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
749 if (symbolP
->sy_previous
!= NULL
)
751 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
754 debug_verify_symchain (*rootPP
, *lastPP
);
757 /* Link symbol ADDME before symbol TARGET in the chain. */
760 symbol_insert (addme
, target
, rootPP
, lastPP
)
764 symbolS
**lastPP ATTRIBUTE_UNUSED
;
766 if (LOCAL_SYMBOL_CHECK (addme
))
768 if (LOCAL_SYMBOL_CHECK (target
))
771 if (target
->sy_previous
!= NULL
)
773 target
->sy_previous
->sy_next
= addme
;
777 know (*rootPP
== target
);
781 addme
->sy_previous
= target
->sy_previous
;
782 target
->sy_previous
= addme
;
783 addme
->sy_next
= target
;
785 debug_verify_symchain (*rootPP
, *lastPP
);
788 #endif /* SYMBOLS_NEED_BACKPOINTERS */
791 verify_symbol_chain (rootP
, lastP
)
795 symbolS
*symbolP
= rootP
;
800 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
803 assert (symbolP
->bsym
!= NULL
);
805 #ifdef SYMBOLS_NEED_BACKPOINTERS
806 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
808 /* Walk the list anyways, to make sure pointers are still good. */
810 #endif /* SYMBOLS_NEED_BACKPOINTERS */
813 assert (lastP
== symbolP
);
817 verify_symbol_chain_2 (sym
)
820 symbolS
*p
= sym
, *n
= sym
;
821 #ifdef SYMBOLS_NEED_BACKPOINTERS
822 while (symbol_previous (p
))
823 p
= symbol_previous (p
);
825 while (symbol_next (n
))
827 verify_symbol_chain (p
, n
);
830 /* Resolve the value of a symbol. This is called during the final
831 pass over the symbol table to resolve any symbols with complex
835 resolve_symbol_value (symp
)
843 if (LOCAL_SYMBOL_CHECK (symp
))
845 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
847 final_val
= locsym
->lsy_value
;
848 if (local_symbol_resolved_p (locsym
))
851 final_val
+= local_symbol_get_frag (locsym
)->fr_address
/ OCTETS_PER_BYTE
;
855 locsym
->lsy_value
= final_val
;
856 local_symbol_mark_resolved (locsym
);
863 if (symp
->sy_resolved
)
865 if (symp
->sy_value
.X_op
== O_constant
)
866 return (valueT
) symp
->sy_value
.X_add_number
;
872 final_seg
= S_GET_SEGMENT (symp
);
874 if (symp
->sy_resolving
)
877 as_bad (_("symbol definition loop encountered at `%s'"),
884 symbolS
*add_symbol
, *op_symbol
;
886 segT seg_left
, seg_right
;
889 symp
->sy_resolving
= 1;
891 /* Help out with CSE. */
892 add_symbol
= symp
->sy_value
.X_add_symbol
;
893 op_symbol
= symp
->sy_value
.X_op_symbol
;
894 final_val
= symp
->sy_value
.X_add_number
;
895 op
= symp
->sy_value
.X_op
;
908 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
909 if (final_seg
== expr_section
)
910 final_seg
= absolute_section
;
916 left
= resolve_symbol_value (add_symbol
);
917 seg_left
= S_GET_SEGMENT (add_symbol
);
919 symp
->sy_value
.X_op_symbol
= NULL
;
922 if (symp
->sy_mri_common
)
924 /* This is a symbol inside an MRI common section. The
925 relocation routines are going to handle it specially.
926 Don't change the value. */
927 resolved
= symbol_resolved_p (add_symbol
);
931 if (finalize_syms
&& final_val
== 0)
933 if (LOCAL_SYMBOL_CHECK (add_symbol
))
934 add_symbol
= local_symbol_convert ((struct local_symbol
*)
936 copy_symbol_attributes (symp
, add_symbol
);
939 /* If we have equated this symbol to an undefined or common
940 symbol, keep X_op set to O_symbol, and don't change
941 X_add_number. This permits the routine which writes out
942 relocation to detect this case, and convert the
943 relocation to be against the symbol to which this symbol
945 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
949 symp
->sy_value
.X_op
= O_symbol
;
950 symp
->sy_value
.X_add_symbol
= add_symbol
;
951 symp
->sy_value
.X_add_number
= final_val
;
952 /* Use X_op_symbol as a flag. */
953 symp
->sy_value
.X_op_symbol
= add_symbol
;
954 final_seg
= seg_left
;
957 resolved
= symbol_resolved_p (add_symbol
);
958 symp
->sy_resolving
= 0;
959 goto exit_dont_set_value
;
961 else if (finalize_syms
&& final_seg
== expr_section
962 && seg_left
!= expr_section
)
964 /* If the symbol is an expression symbol, do similarly
965 as for undefined and common syms above. Handles
966 "sym +/- expr" where "expr" cannot be evaluated
967 immediately, and we want relocations to be against
968 "sym", eg. because it is weak. */
969 symp
->sy_value
.X_op
= O_symbol
;
970 symp
->sy_value
.X_add_symbol
= add_symbol
;
971 symp
->sy_value
.X_add_number
= final_val
;
972 symp
->sy_value
.X_op_symbol
= add_symbol
;
973 final_seg
= seg_left
;
974 final_val
+= symp
->sy_frag
->fr_address
+ left
;
975 resolved
= symbol_resolved_p (add_symbol
);
976 symp
->sy_resolving
= 0;
977 goto exit_dont_set_value
;
981 final_val
+= symp
->sy_frag
->fr_address
+ left
;
982 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
983 final_seg
= seg_left
;
986 resolved
= symbol_resolved_p (add_symbol
);
992 left
= resolve_symbol_value (add_symbol
);
996 else if (op
== O_logical_not
)
1001 final_val
+= left
+ symp
->sy_frag
->fr_address
;
1002 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1003 final_seg
= absolute_section
;
1005 resolved
= symbol_resolved_p (add_symbol
);
1013 case O_bit_inclusive_or
:
1015 case O_bit_exclusive_or
:
1027 left
= resolve_symbol_value (add_symbol
);
1028 right
= resolve_symbol_value (op_symbol
);
1029 seg_left
= S_GET_SEGMENT (add_symbol
);
1030 seg_right
= S_GET_SEGMENT (op_symbol
);
1032 /* Simplify addition or subtraction of a constant by folding the
1033 constant into X_add_number. */
1036 if (seg_right
== absolute_section
)
1041 else if (seg_left
== absolute_section
)
1044 add_symbol
= op_symbol
;
1046 seg_left
= seg_right
;
1050 else if (op
== O_subtract
)
1052 if (seg_right
== absolute_section
)
1059 /* Equality and non-equality tests are permitted on anything.
1060 Subtraction, and other comparison operators are permitted if
1061 both operands are in the same section. Otherwise, both
1062 operands must be absolute. We already handled the case of
1063 addition or subtraction of a constant above. This will
1064 probably need to be changed for an object file format which
1065 supports arbitrary expressions, such as IEEE-695.
1067 Don't emit messages unless we're finalizing the symbol value,
1068 otherwise we may get the same message multiple times. */
1069 if (op
!= O_eq
&& op
!= O_ne
1070 && (seg_left
!= absolute_section
1071 || seg_right
!= absolute_section
)
1072 && ((op
!= O_subtract
1073 && op
!= O_lt
&& op
!= O_le
&& op
!= O_ge
&& op
!= O_gt
)
1074 || seg_left
!= seg_right
1075 || (seg_left
== undefined_section
1076 && add_symbol
!= op_symbol
))
1082 if (expr_symbol_where (symp
, &file
, &line
))
1084 if (seg_left
== undefined_section
)
1085 as_bad_where (file
, line
,
1086 _("undefined symbol `%s' in operation"),
1087 S_GET_NAME (symp
->sy_value
.X_add_symbol
));
1088 if (seg_right
== undefined_section
)
1089 as_bad_where (file
, line
,
1090 _("undefined symbol `%s' in operation"),
1091 S_GET_NAME (symp
->sy_value
.X_op_symbol
));
1092 if (seg_left
!= undefined_section
1093 && seg_right
!= undefined_section
)
1094 as_bad_where (file
, line
,
1095 _("invalid section for operation"));
1099 if (seg_left
== undefined_section
)
1100 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1101 S_GET_NAME (symp
->sy_value
.X_add_symbol
),
1103 if (seg_right
== undefined_section
)
1104 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1105 S_GET_NAME (symp
->sy_value
.X_op_symbol
),
1107 if (seg_left
!= undefined_section
1108 && seg_right
!= undefined_section
)
1109 as_bad (_("invalid section for operation setting `%s'"),
1114 /* Check for division by zero. */
1115 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1117 /* If seg_right is not absolute_section, then we've
1118 already issued a warning about using a bad symbol. */
1119 if (seg_right
== absolute_section
&& finalize_syms
)
1124 if (expr_symbol_where (symp
, &file
, &line
))
1125 as_bad_where (file
, line
, _("division by zero"));
1127 as_bad (_("division by zero when setting `%s'"),
1134 switch (symp
->sy_value
.X_op
)
1136 case O_multiply
: left
*= right
; break;
1137 case O_divide
: left
/= right
; break;
1138 case O_modulus
: left
%= right
; break;
1139 case O_left_shift
: left
<<= right
; break;
1140 case O_right_shift
: left
>>= right
; break;
1141 case O_bit_inclusive_or
: left
|= right
; break;
1142 case O_bit_or_not
: left
|= ~right
; break;
1143 case O_bit_exclusive_or
: left
^= right
; break;
1144 case O_bit_and
: left
&= right
; break;
1145 case O_add
: left
+= right
; break;
1146 case O_subtract
: left
-= right
; break;
1149 left
= (left
== right
&& seg_left
== seg_right
1150 && (seg_left
!= undefined_section
1151 || add_symbol
== op_symbol
)
1152 ? ~ (offsetT
) 0 : 0);
1153 if (symp
->sy_value
.X_op
== O_ne
)
1156 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1157 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1158 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1159 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1160 case O_logical_and
: left
= left
&& right
; break;
1161 case O_logical_or
: left
= left
|| right
; break;
1165 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1166 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1167 final_seg
= absolute_section
;
1168 resolved
= (symbol_resolved_p (add_symbol
)
1169 && symbol_resolved_p (op_symbol
));
1175 /* Give an error (below) if not in expr_section. We don't
1176 want to worry about expr_section symbols, because they
1177 are fictional (they are created as part of expression
1178 resolution), and any problems may not actually mean
1183 symp
->sy_resolving
= 0;
1187 S_SET_VALUE (symp
, final_val
);
1189 exit_dont_set_value
:
1190 /* Always set the segment, even if not finalizing the value.
1191 The segment is used to determine whether a symbol is defined. */
1192 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1193 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1194 for a stab symbol, so we use this bad hack. */
1195 if (final_seg
!= S_GET_SEGMENT (symp
))
1197 S_SET_SEGMENT (symp
, final_seg
);
1199 /* Don't worry if we can't resolve an expr_section symbol. */
1203 symp
->sy_resolved
= 1;
1204 else if (S_GET_SEGMENT (symp
) != expr_section
)
1206 as_bad (_("can't resolve value for symbol `%s'"),
1208 symp
->sy_resolved
= 1;
1215 #ifdef BFD_ASSEMBLER
1217 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1219 /* A static function passed to hash_traverse. */
1222 resolve_local_symbol (key
, value
)
1223 const char *key ATTRIBUTE_UNUSED
;
1227 resolve_symbol_value (value
);
1232 /* Resolve all local symbols. */
1235 resolve_local_symbol_values ()
1237 #ifdef BFD_ASSEMBLER
1238 hash_traverse (local_hash
, resolve_local_symbol
);
1242 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1243 They are *really* local. That is, they go out of scope whenever we see a
1244 label that isn't local. Also, like fb labels, there can be multiple
1245 instances of a dollar label. Therefor, we name encode each instance with
1246 the instance number, keep a list of defined symbols separate from the real
1247 symbol table, and we treat these buggers as a sparse array. */
1249 static long *dollar_labels
;
1250 static long *dollar_label_instances
;
1251 static char *dollar_label_defines
;
1252 static unsigned long dollar_label_count
;
1253 static unsigned long dollar_label_max
;
1256 dollar_label_defined (label
)
1261 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1263 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1265 return dollar_label_defines
[i
- dollar_labels
];
1267 /* If we get here, label isn't defined. */
1272 dollar_label_instance (label
)
1277 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1279 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1281 return (dollar_label_instances
[i
- dollar_labels
]);
1283 /* If we get here, we haven't seen the label before.
1284 Therefore its instance count is zero. */
1289 dollar_label_clear ()
1291 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1294 #define DOLLAR_LABEL_BUMP_BY 10
1297 define_dollar_label (label
)
1302 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1305 ++dollar_label_instances
[i
- dollar_labels
];
1306 dollar_label_defines
[i
- dollar_labels
] = 1;
1310 /* If we get to here, we don't have label listed yet. */
1312 if (dollar_labels
== NULL
)
1314 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1315 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1316 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1317 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1318 dollar_label_count
= 0;
1320 else if (dollar_label_count
== dollar_label_max
)
1322 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1323 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1324 dollar_label_max
* sizeof (long));
1325 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1326 dollar_label_max
* sizeof (long));
1327 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1328 } /* if we needed to grow */
1330 dollar_labels
[dollar_label_count
] = label
;
1331 dollar_label_instances
[dollar_label_count
] = 1;
1332 dollar_label_defines
[dollar_label_count
] = 1;
1333 ++dollar_label_count
;
1336 /* Caller must copy returned name: we re-use the area for the next name.
1338 The mth occurence of label n: is turned into the symbol "Ln^Am"
1339 where n is the label number and m is the instance number. "L" makes
1340 it a label discarded unless debugging and "^A"('\1') ensures no
1341 ordinary symbol SHOULD get the same name as a local label
1342 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1344 fb labels get the same treatment, except that ^B is used in place
1347 char * /* Return local label name. */
1348 dollar_label_name (n
, augend
)
1349 register long n
; /* we just saw "n$:" : n a number. */
1350 register int augend
; /* 0 for current instance, 1 for new instance. */
1353 /* Returned to caller, then copied. Used for created names ("4f"). */
1354 static char symbol_name_build
[24];
1357 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1360 know (augend
== 0 || augend
== 1);
1361 p
= symbol_name_build
;
1362 #ifdef LOCAL_LABEL_PREFIX
1363 *p
++ = LOCAL_LABEL_PREFIX
;
1367 /* Next code just does sprintf( {}, "%d", n); */
1369 q
= symbol_name_temporary
;
1370 for (*q
++ = 0, i
= n
; i
; ++q
)
1375 while ((*p
= *--q
) != '\0')
1378 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1380 /* Instance number. */
1381 q
= symbol_name_temporary
;
1382 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1387 while ((*p
++ = *--q
) != '\0');;
1389 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1390 return symbol_name_build
;
1393 /* Sombody else's idea of local labels. They are made by "n:" where n
1394 is any decimal digit. Refer to them with
1395 "nb" for previous (backward) n:
1396 or "nf" for next (forward) n:.
1398 We do a little better and let n be any number, not just a single digit, but
1399 since the other guy's assembler only does ten, we treat the first ten
1402 Like someone else's assembler, we have one set of local label counters for
1403 entire assembly, not one set per (sub)segment like in most assemblers. This
1404 implies that one can refer to a label in another segment, and indeed some
1405 crufty compilers have done just that.
1407 Since there could be a LOT of these things, treat them as a sparse
1410 #define FB_LABEL_SPECIAL (10)
1412 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1413 static long *fb_labels
;
1414 static long *fb_label_instances
;
1415 static long fb_label_count
;
1416 static long fb_label_max
;
1418 /* This must be more than FB_LABEL_SPECIAL. */
1419 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1424 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1427 /* Add one to the instance number of this fb label. */
1430 fb_label_instance_inc (label
)
1435 if (label
< FB_LABEL_SPECIAL
)
1437 ++fb_low_counter
[label
];
1441 if (fb_labels
!= NULL
)
1443 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1444 i
< fb_labels
+ fb_label_count
; ++i
)
1448 ++fb_label_instances
[i
- fb_labels
];
1450 } /* if we find it */
1451 } /* for each existing label */
1454 /* If we get to here, we don't have label listed yet. */
1456 if (fb_labels
== NULL
)
1458 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1459 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1460 fb_label_max
= FB_LABEL_BUMP_BY
;
1461 fb_label_count
= FB_LABEL_SPECIAL
;
1464 else if (fb_label_count
== fb_label_max
)
1466 fb_label_max
+= FB_LABEL_BUMP_BY
;
1467 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1468 fb_label_max
* sizeof (long));
1469 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1470 fb_label_max
* sizeof (long));
1471 } /* if we needed to grow */
1473 fb_labels
[fb_label_count
] = label
;
1474 fb_label_instances
[fb_label_count
] = 1;
1479 fb_label_instance (label
)
1484 if (label
< FB_LABEL_SPECIAL
)
1486 return (fb_low_counter
[label
]);
1489 if (fb_labels
!= NULL
)
1491 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1492 i
< fb_labels
+ fb_label_count
; ++i
)
1496 return (fb_label_instances
[i
- fb_labels
]);
1497 } /* if we find it */
1498 } /* for each existing label */
1501 /* We didn't find the label, so this must be a reference to the
1506 /* Caller must copy returned name: we re-use the area for the next name.
1508 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1509 where n is the label number and m is the instance number. "L" makes
1510 it a label discarded unless debugging and "^B"('\2') ensures no
1511 ordinary symbol SHOULD get the same name as a local label
1512 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1514 dollar labels get the same treatment, except that ^A is used in
1517 char * /* Return local label name. */
1518 fb_label_name (n
, augend
)
1519 long n
; /* We just saw "n:", "nf" or "nb" : n a number. */
1520 long augend
; /* 0 for nb, 1 for n:, nf. */
1523 /* Returned to caller, then copied. Used for created names ("4f"). */
1524 static char symbol_name_build
[24];
1527 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1530 know (augend
== 0 || augend
== 1);
1531 p
= symbol_name_build
;
1532 #ifdef LOCAL_LABEL_PREFIX
1533 *p
++ = LOCAL_LABEL_PREFIX
;
1537 /* Next code just does sprintf( {}, "%d", n); */
1539 q
= symbol_name_temporary
;
1540 for (*q
++ = 0, i
= n
; i
; ++q
)
1545 while ((*p
= *--q
) != '\0')
1548 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
1550 /* Instance number. */
1551 q
= symbol_name_temporary
;
1552 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1557 while ((*p
++ = *--q
) != '\0');;
1559 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1560 return (symbol_name_build
);
1563 /* Decode name that may have been generated by foo_label_name() above.
1564 If the name wasn't generated by foo_label_name(), then return it
1565 unaltered. This is used for error messages. */
1568 decode_local_label_name (s
)
1572 char *symbol_decode
;
1574 int instance_number
;
1576 const char *message_format
;
1579 #ifdef LOCAL_LABEL_PREFIX
1580 if (s
[index
] == LOCAL_LABEL_PREFIX
)
1584 if (s
[index
] != 'L')
1587 for (label_number
= 0, p
= s
+ index
+ 1; isdigit ((unsigned char) *p
); ++p
)
1588 label_number
= (10 * label_number
) + *p
- '0';
1590 if (*p
== DOLLAR_LABEL_CHAR
)
1592 else if (*p
== LOCAL_LABEL_CHAR
)
1597 for (instance_number
= 0, p
++; isdigit ((unsigned char) *p
); ++p
)
1598 instance_number
= (10 * instance_number
) + *p
- '0';
1600 message_format
= _("\"%d\" (instance number %d of a %s label)");
1601 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1602 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1604 return symbol_decode
;
1607 /* Get the value of a symbol. */
1613 #ifdef BFD_ASSEMBLER
1614 if (LOCAL_SYMBOL_CHECK (s
))
1615 return resolve_symbol_value (s
);
1618 if (!s
->sy_resolved
)
1620 valueT val
= resolve_symbol_value (s
);
1624 if (s
->sy_value
.X_op
!= O_constant
)
1626 static symbolS
*recur
;
1628 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1629 may call S_GET_VALUE. We use a static symbol to avoid the
1630 immediate recursion. */
1632 return (valueT
) s
->sy_value
.X_add_number
;
1634 if (! s
->sy_resolved
1635 || s
->sy_value
.X_op
!= O_symbol
1636 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1637 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1641 return (valueT
) s
->sy_value
.X_add_number
;
1644 /* Set the value of a symbol. */
1647 S_SET_VALUE (s
, val
)
1651 #ifdef BFD_ASSEMBLER
1652 if (LOCAL_SYMBOL_CHECK (s
))
1654 ((struct local_symbol
*) s
)->lsy_value
= val
;
1659 s
->sy_value
.X_op
= O_constant
;
1660 s
->sy_value
.X_add_number
= (offsetT
) val
;
1661 s
->sy_value
.X_unsigned
= 0;
1665 copy_symbol_attributes (dest
, src
)
1666 symbolS
*dest
, *src
;
1668 if (LOCAL_SYMBOL_CHECK (dest
))
1669 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
1670 if (LOCAL_SYMBOL_CHECK (src
))
1671 src
= local_symbol_convert ((struct local_symbol
*) src
);
1673 #ifdef BFD_ASSEMBLER
1674 /* In an expression, transfer the settings of these flags.
1675 The user can override later, of course. */
1676 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1677 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1680 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1681 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1685 #ifdef BFD_ASSEMBLER
1693 if (LOCAL_SYMBOL_CHECK (s
))
1696 flags
= s
->bsym
->flags
;
1698 return (flags
& BSF_FUNCTION
) != 0;
1707 if (LOCAL_SYMBOL_CHECK (s
))
1710 flags
= s
->bsym
->flags
;
1713 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1716 return (flags
& BSF_GLOBAL
) != 0;
1723 if (LOCAL_SYMBOL_CHECK (s
))
1725 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1732 if (LOCAL_SYMBOL_CHECK (s
))
1734 return bfd_is_com_section (s
->bsym
->section
);
1741 if (LOCAL_SYMBOL_CHECK (s
))
1742 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1743 return s
->bsym
->section
!= undefined_section
;
1750 if (LOCAL_SYMBOL_CHECK (s
))
1752 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1764 if (LOCAL_SYMBOL_CHECK (s
))
1767 flags
= s
->bsym
->flags
;
1770 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1773 if (bfd_get_section (s
->bsym
) == reg_section
)
1776 if (flag_strip_local_absolute
1777 && (flags
& BSF_GLOBAL
) == 0
1778 && bfd_get_section (s
->bsym
) == absolute_section
)
1781 name
= S_GET_NAME (s
);
1782 return (name
!= NULL
1784 && (strchr (name
, DOLLAR_LABEL_CHAR
)
1785 || strchr (name
, LOCAL_LABEL_CHAR
)
1786 || (! flag_keep_locals
1787 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1790 && name
[1] == '?')))));
1797 return S_IS_EXTERNAL (s
);
1804 return S_GET_NAME (s
) == 0;
1811 if (LOCAL_SYMBOL_CHECK (s
))
1812 return ((struct local_symbol
*) s
)->lsy_name
;
1813 return s
->bsym
->name
;
1820 if (LOCAL_SYMBOL_CHECK (s
))
1821 return ((struct local_symbol
*) s
)->lsy_section
;
1822 return s
->bsym
->section
;
1826 S_SET_SEGMENT (s
, seg
)
1830 /* Don't reassign section symbols. The direct reason is to prevent seg
1831 faults assigning back to const global symbols such as *ABS*, but it
1832 shouldn't happen anyway. */
1834 if (LOCAL_SYMBOL_CHECK (s
))
1836 if (seg
== reg_section
)
1837 s
= local_symbol_convert ((struct local_symbol
*) s
);
1840 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1845 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1847 if (s
->bsym
->section
!= seg
)
1851 s
->bsym
->section
= seg
;
1858 if (LOCAL_SYMBOL_CHECK (s
))
1859 s
= local_symbol_convert ((struct local_symbol
*) s
);
1860 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1862 /* Let .weak override .global. */
1865 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1870 /* Do not reassign section symbols. */
1871 as_where (& file
, & line
);
1872 as_warn_where (file
, line
,
1873 _("section symbols are already global"));
1876 s
->bsym
->flags
|= BSF_GLOBAL
;
1877 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
1881 S_CLEAR_EXTERNAL (s
)
1884 if (LOCAL_SYMBOL_CHECK (s
))
1886 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1888 /* Let .weak override. */
1891 s
->bsym
->flags
|= BSF_LOCAL
;
1892 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
1899 if (LOCAL_SYMBOL_CHECK (s
))
1900 s
= local_symbol_convert ((struct local_symbol
*) s
);
1901 s
->bsym
->flags
|= BSF_WEAK
;
1902 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
1906 S_SET_NAME (s
, name
)
1910 if (LOCAL_SYMBOL_CHECK (s
))
1912 ((struct local_symbol
*) s
)->lsy_name
= name
;
1915 s
->bsym
->name
= name
;
1917 #endif /* BFD_ASSEMBLER */
1919 #ifdef SYMBOLS_NEED_BACKPOINTERS
1921 /* Return the previous symbol in a chain. */
1927 if (LOCAL_SYMBOL_CHECK (s
))
1929 return s
->sy_previous
;
1932 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1934 /* Return the next symbol in a chain. */
1940 if (LOCAL_SYMBOL_CHECK (s
))
1945 /* Return a pointer to the value of a symbol as an expression. */
1948 symbol_get_value_expression (s
)
1951 if (LOCAL_SYMBOL_CHECK (s
))
1952 s
= local_symbol_convert ((struct local_symbol
*) s
);
1953 return &s
->sy_value
;
1956 /* Set the value of a symbol to an expression. */
1959 symbol_set_value_expression (s
, exp
)
1961 const expressionS
*exp
;
1963 if (LOCAL_SYMBOL_CHECK (s
))
1964 s
= local_symbol_convert ((struct local_symbol
*) s
);
1968 /* Set the frag of a symbol. */
1971 symbol_set_frag (s
, f
)
1975 #ifdef BFD_ASSEMBLER
1976 if (LOCAL_SYMBOL_CHECK (s
))
1978 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
1985 /* Return the frag of a symbol. */
1991 #ifdef BFD_ASSEMBLER
1992 if (LOCAL_SYMBOL_CHECK (s
))
1993 return local_symbol_get_frag ((struct local_symbol
*) s
);
1998 /* Mark a symbol as having been used. */
2001 symbol_mark_used (s
)
2004 if (LOCAL_SYMBOL_CHECK (s
))
2009 /* Clear the mark of whether a symbol has been used. */
2012 symbol_clear_used (s
)
2015 if (LOCAL_SYMBOL_CHECK (s
))
2016 s
= local_symbol_convert ((struct local_symbol
*) s
);
2020 /* Return whether a symbol has been used. */
2026 if (LOCAL_SYMBOL_CHECK (s
))
2031 /* Mark a symbol as having been used in a reloc. */
2034 symbol_mark_used_in_reloc (s
)
2037 if (LOCAL_SYMBOL_CHECK (s
))
2038 s
= local_symbol_convert ((struct local_symbol
*) s
);
2039 s
->sy_used_in_reloc
= 1;
2042 /* Clear the mark of whether a symbol has been used in a reloc. */
2045 symbol_clear_used_in_reloc (s
)
2048 if (LOCAL_SYMBOL_CHECK (s
))
2050 s
->sy_used_in_reloc
= 0;
2053 /* Return whether a symbol has been used in a reloc. */
2056 symbol_used_in_reloc_p (s
)
2059 if (LOCAL_SYMBOL_CHECK (s
))
2061 return s
->sy_used_in_reloc
;
2064 /* Mark a symbol as an MRI common symbol. */
2067 symbol_mark_mri_common (s
)
2070 if (LOCAL_SYMBOL_CHECK (s
))
2071 s
= local_symbol_convert ((struct local_symbol
*) s
);
2072 s
->sy_mri_common
= 1;
2075 /* Clear the mark of whether a symbol is an MRI common symbol. */
2078 symbol_clear_mri_common (s
)
2081 if (LOCAL_SYMBOL_CHECK (s
))
2083 s
->sy_mri_common
= 0;
2086 /* Return whether a symbol is an MRI common symbol. */
2089 symbol_mri_common_p (s
)
2092 if (LOCAL_SYMBOL_CHECK (s
))
2094 return s
->sy_mri_common
;
2097 /* Mark a symbol as having been written. */
2100 symbol_mark_written (s
)
2103 if (LOCAL_SYMBOL_CHECK (s
))
2108 /* Clear the mark of whether a symbol has been written. */
2111 symbol_clear_written (s
)
2114 if (LOCAL_SYMBOL_CHECK (s
))
2119 /* Return whether a symbol has been written. */
2122 symbol_written_p (s
)
2125 if (LOCAL_SYMBOL_CHECK (s
))
2130 /* Mark a symbol has having been resolved. */
2133 symbol_mark_resolved (s
)
2136 #ifdef BFD_ASSEMBLER
2137 if (LOCAL_SYMBOL_CHECK (s
))
2139 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2146 /* Return whether a symbol has been resolved. */
2149 symbol_resolved_p (s
)
2152 #ifdef BFD_ASSEMBLER
2153 if (LOCAL_SYMBOL_CHECK (s
))
2154 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2156 return s
->sy_resolved
;
2159 /* Return whether a symbol is a section symbol. */
2162 symbol_section_p (s
)
2163 symbolS
*s ATTRIBUTE_UNUSED
;
2165 if (LOCAL_SYMBOL_CHECK (s
))
2167 #ifdef BFD_ASSEMBLER
2168 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2175 /* Return whether a symbol is equated to another symbol. */
2178 symbol_equated_p (s
)
2181 if (LOCAL_SYMBOL_CHECK (s
))
2183 return s
->sy_value
.X_op
== O_symbol
;
2186 /* Return whether a symbol is equated to another symbol, and should be
2187 treated specially when writing out relocs. */
2190 symbol_equated_reloc_p (s
)
2193 if (LOCAL_SYMBOL_CHECK (s
))
2195 /* X_op_symbol, normally not used for O_symbol, is set by
2196 resolve_symbol_value to flag expression syms that have been
2198 return (s
->sy_value
.X_op
== O_symbol
2199 && ((s
->sy_resolved
&& s
->sy_value
.X_op_symbol
!= NULL
)
2200 || ! S_IS_DEFINED (s
)
2201 || S_IS_COMMON (s
)));
2204 /* Return whether a symbol has a constant value. */
2207 symbol_constant_p (s
)
2210 if (LOCAL_SYMBOL_CHECK (s
))
2212 return s
->sy_value
.X_op
== O_constant
;
2215 #ifdef BFD_ASSEMBLER
2217 /* Return the BFD symbol for a symbol. */
2220 symbol_get_bfdsym (s
)
2223 if (LOCAL_SYMBOL_CHECK (s
))
2224 s
= local_symbol_convert ((struct local_symbol
*) s
);
2228 /* Set the BFD symbol for a symbol. */
2231 symbol_set_bfdsym (s
, bsym
)
2235 if (LOCAL_SYMBOL_CHECK (s
))
2236 s
= local_symbol_convert ((struct local_symbol
*) s
);
2240 #endif /* BFD_ASSEMBLER */
2242 #ifdef OBJ_SYMFIELD_TYPE
2244 /* Get a pointer to the object format information for a symbol. */
2250 if (LOCAL_SYMBOL_CHECK (s
))
2251 s
= local_symbol_convert ((struct local_symbol
*) s
);
2255 /* Set the object format information for a symbol. */
2258 symbol_set_obj (s
, o
)
2260 OBJ_SYMFIELD_TYPE
*o
;
2262 if (LOCAL_SYMBOL_CHECK (s
))
2263 s
= local_symbol_convert ((struct local_symbol
*) s
);
2267 #endif /* OBJ_SYMFIELD_TYPE */
2269 #ifdef TC_SYMFIELD_TYPE
2271 /* Get a pointer to the processor information for a symbol. */
2277 if (LOCAL_SYMBOL_CHECK (s
))
2278 s
= local_symbol_convert ((struct local_symbol
*) s
);
2282 /* Set the processor information for a symbol. */
2285 symbol_set_tc (s
, o
)
2287 TC_SYMFIELD_TYPE
*o
;
2289 if (LOCAL_SYMBOL_CHECK (s
))
2290 s
= local_symbol_convert ((struct local_symbol
*) s
);
2294 #endif /* TC_SYMFIELD_TYPE */
2299 symbol_lastP
= NULL
;
2300 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2301 sy_hash
= hash_new ();
2302 #ifdef BFD_ASSEMBLER
2303 local_hash
= hash_new ();
2306 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2307 #ifdef BFD_ASSEMBLER
2308 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2309 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2312 /* Can't initialise a union. Sigh. */
2313 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2315 abs_symbol
.sy_value
.X_op
= O_constant
;
2316 abs_symbol
.sy_frag
= &zero_address_frag
;
2318 if (LOCAL_LABELS_FB
)
2324 /* Maximum indent level.
2325 Available for modification inside a gdb session. */
2326 int max_indent_level
= 8;
2333 printf ("%*s", indent_level
* 4, "");
2339 print_symbol_value_1 (file
, sym
)
2343 const char *name
= S_GET_NAME (sym
);
2344 if (!name
|| !name
[0])
2346 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2348 if (LOCAL_SYMBOL_CHECK (sym
))
2350 #ifdef BFD_ASSEMBLER
2351 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2352 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2353 && local_symbol_get_frag (locsym
) != NULL
)
2354 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2355 if (local_symbol_resolved_p (locsym
))
2356 fprintf (file
, " resolved");
2357 fprintf (file
, " local");
2362 if (sym
->sy_frag
!= &zero_address_frag
)
2363 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2365 fprintf (file
, " written");
2366 if (sym
->sy_resolved
)
2367 fprintf (file
, " resolved");
2368 else if (sym
->sy_resolving
)
2369 fprintf (file
, " resolving");
2370 if (sym
->sy_used_in_reloc
)
2371 fprintf (file
, " used-in-reloc");
2373 fprintf (file
, " used");
2374 if (S_IS_LOCAL (sym
))
2375 fprintf (file
, " local");
2376 if (S_IS_EXTERN (sym
))
2377 fprintf (file
, " extern");
2378 if (S_IS_DEBUG (sym
))
2379 fprintf (file
, " debug");
2380 if (S_IS_DEFINED (sym
))
2381 fprintf (file
, " defined");
2383 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2384 if (symbol_resolved_p (sym
))
2386 segT s
= S_GET_SEGMENT (sym
);
2388 if (s
!= undefined_section
2389 && s
!= expr_section
)
2390 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2392 else if (indent_level
< max_indent_level
2393 && S_GET_SEGMENT (sym
) != undefined_section
)
2396 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2397 #ifdef BFD_ASSEMBLER
2398 if (LOCAL_SYMBOL_CHECK (sym
))
2399 fprintf (file
, "constant %lx",
2400 (long) ((struct local_symbol
*) sym
)->lsy_value
);
2403 print_expr_1 (file
, &sym
->sy_value
);
2404 fprintf (file
, ">");
2411 print_symbol_value (sym
)
2415 print_symbol_value_1 (stderr
, sym
);
2416 fprintf (stderr
, "\n");
2420 print_binary (file
, name
, exp
)
2426 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2427 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2428 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2429 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2430 fprintf (file
, ">");
2435 print_expr_1 (file
, exp
)
2439 fprintf (file
, "expr %lx ", (long) exp
);
2443 fprintf (file
, "illegal");
2446 fprintf (file
, "absent");
2449 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2453 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2454 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2455 fprintf (file
, ">");
2457 if (exp
->X_add_number
)
2458 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2459 (long) exp
->X_add_number
);
2463 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2466 fprintf (file
, "big");
2469 fprintf (file
, "uminus -<");
2471 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2472 fprintf (file
, ">");
2473 goto maybe_print_addnum
;
2475 fprintf (file
, "bit_not");
2478 print_binary (file
, "multiply", exp
);
2481 print_binary (file
, "divide", exp
);
2484 print_binary (file
, "modulus", exp
);
2487 print_binary (file
, "lshift", exp
);
2490 print_binary (file
, "rshift", exp
);
2492 case O_bit_inclusive_or
:
2493 print_binary (file
, "bit_ior", exp
);
2495 case O_bit_exclusive_or
:
2496 print_binary (file
, "bit_xor", exp
);
2499 print_binary (file
, "bit_and", exp
);
2502 print_binary (file
, "eq", exp
);
2505 print_binary (file
, "ne", exp
);
2508 print_binary (file
, "lt", exp
);
2511 print_binary (file
, "le", exp
);
2514 print_binary (file
, "ge", exp
);
2517 print_binary (file
, "gt", exp
);
2520 print_binary (file
, "logical_and", exp
);
2523 print_binary (file
, "logical_or", exp
);
2527 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2528 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2529 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2530 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2531 fprintf (file
, ">");
2532 goto maybe_print_addnum
;
2535 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
2536 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2537 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2538 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2539 fprintf (file
, ">");
2540 goto maybe_print_addnum
;
2542 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2552 print_expr_1 (stderr
, exp
);
2553 fprintf (stderr
, "\n");
2557 symbol_print_statistics (file
)
2560 hash_print_statistics (file
, "symbol table", sy_hash
);
2561 #ifdef BFD_ASSEMBLER
2562 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2563 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2564 local_symbol_count
, local_symbol_conversion_count
);