1 /* symbols.c -symbol table-
2 Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* #define DEBUG_SYMS / * to debug symbol list maintenance */
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)
60 static void fb_label_init
PARAMS ((void));
61 static long dollar_label_instance
PARAMS ((long));
62 static long fb_label_instance
PARAMS ((long));
64 static void print_binary
PARAMS ((FILE *, const char *, expressionS
*));
68 Return a pointer to a new symbol. Die if we can't make a new
69 symbol. Fill in the symbol's values. Add symbol to end of symbol
72 This function should be called in the general case of creating a
73 symbol. However, if the output file symbol table has already been
74 set, and you are certain that this symbol won't be wanted in the
75 output file, you can call symbol_create. */
78 symbol_new (name
, segment
, valu
, frag
)
84 symbolS
*symbolP
= symbol_create (name
, segment
, valu
, frag
);
87 * Link to end of symbol chain.
91 extern int symbol_table_frozen
;
92 if (symbol_table_frozen
)
96 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
101 /* Save a symbol name on a permanent obstack, and convert it according
102 to the object file format. */
105 save_symbol_name (name
)
108 unsigned int name_length
;
111 name_length
= strlen (name
) + 1; /* +1 for \0 */
112 obstack_grow (¬es
, name
, name_length
);
113 ret
= obstack_finish (¬es
);
115 #ifdef STRIP_UNDERSCORE
120 #ifdef tc_canonicalize_symbol_name
121 ret
= tc_canonicalize_symbol_name (ret
);
124 if (! symbols_case_sensitive
)
128 for (s
= (unsigned char *) 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
, offset
, 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_offset
= offset
;
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_offset
,
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 symbol_table_insert (ret
);
260 local_symbol_mark_converted (locsym
);
261 local_symbol_set_real_symbol (locsym
, ret
);
263 hash_jam (local_hash
, locsym
->lsy_name
, NULL
);
268 #else /* ! BFD_ASSEMBLER */
270 #define LOCAL_SYMBOL_CHECK(s) 0
271 #define local_symbol_convert(s) ((symbolS *) s)
273 #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).
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 table in the
331 fr_opcode of the rs_broken_word frag. This requires a little
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
))
353 * Now check for undefined symbols
355 if (LOCAL_SYMBOL_CHECK (symbolP
))
357 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
359 if (locsym
->lsy_section
!= undefined_section
360 && (local_symbol_get_frag (locsym
) != frag_now
361 || locsym
->lsy_section
!= now_seg
362 || locsym
->lsy_offset
!= frag_now_fix ()))
364 as_bad (_("Symbol %s already defined."), sym_name
);
368 locsym
->lsy_section
= now_seg
;
369 local_symbol_set_frag (locsym
, frag_now
);
370 locsym
->lsy_offset
= 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. */
390 * There are still several cases to check:
391 * A .comm/.lcomm symbol being redefined as
392 * initialized data is OK
393 * A .comm/.lcomm symbol being redefined with
394 * a larger size is also OK
396 * This only used to be allowed on VMS gas, but Sun cc
397 * 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
)))
408 * Select which of the 2 cases this is
410 if (now_seg
!= data_section
)
413 * New .comm for prev .comm symbol.
414 * If the new size is larger we just
415 * change its value. If the new size
416 * is smaller, we ignore this symbol
418 if (S_GET_VALUE (symbolP
)
419 < ((unsigned) frag_now_fix ()))
421 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
426 /* It is a .comm/.lcomm being converted to initialized
428 symbolP
->sy_frag
= frag_now
;
430 S_SET_OTHER(symbolP
, const_flag
);
432 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
433 S_SET_SEGMENT (symbolP
, now_seg
); /* keep N_EXT bit */
438 #if defined (S_GET_OTHER) && defined (S_GET_DESC)
439 as_fatal (_("Symbol \"%s\" is already defined as \"%s\"/%d.%d.%ld."),
441 segment_name (S_GET_SEGMENT (symbolP
)),
442 S_GET_OTHER (symbolP
), S_GET_DESC (symbolP
),
443 (long) S_GET_VALUE (symbolP
));
445 as_fatal (_("Symbol \"%s\" is already defined as \"%s\"/%ld."),
447 segment_name (S_GET_SEGMENT (symbolP
)),
448 (long) S_GET_VALUE (symbolP
));
451 } /* if the undefined symbol has no value */
455 /* Don't blow up if the definition is the same */
456 if (!(frag_now
== symbolP
->sy_frag
457 && S_GET_VALUE (symbolP
) == frag_now_fix ()
458 && S_GET_SEGMENT (symbolP
) == now_seg
))
459 as_fatal (_("Symbol %s already defined."), sym_name
);
460 } /* if this symbol is not yet defined */
464 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
466 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
467 (valueT
) frag_now_fix (),
470 #endif /* BFD_ASSEMBLER */
473 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
476 S_SET_OTHER (symbolP
, const_flag
);
479 symbol_table_insert (symbolP
);
480 } /* if we have seen this symbol before */
482 if (mri_common_symbol
!= NULL
)
484 /* This symbol is actually being defined within an MRI common
485 section. This requires special handling. */
486 if (LOCAL_SYMBOL_CHECK (symbolP
))
487 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
488 symbolP
->sy_value
.X_op
= O_symbol
;
489 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
490 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
491 symbolP
->sy_frag
= &zero_address_frag
;
492 S_SET_SEGMENT (symbolP
, expr_section
);
493 symbolP
->sy_mri_common
= 1;
497 tc_frob_label (symbolP
);
499 #ifdef obj_frob_label
500 obj_frob_label (symbolP
);
508 * symbol_table_insert()
510 * Die if we can't insert the symbol.
515 symbol_table_insert (symbolP
)
518 register const char *error_string
;
521 know (S_GET_NAME (symbolP
));
523 if (LOCAL_SYMBOL_CHECK (symbolP
))
525 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
527 if (error_string
!= NULL
)
528 as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
529 S_GET_NAME (symbolP
), error_string
);
533 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
535 as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
536 S_GET_NAME (symbolP
), error_string
);
538 } /* symbol_table_insert() */
541 * symbol_find_or_make()
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 */
576 } /* symbol_find_or_make() */
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
);
591 } /* symbol_make() */
596 * Implement symbol table lookup.
597 * In: A symbol's name as a string: '\0' can't be part of a symbol name.
598 * Out: NULL if the name was not in the symbol table, else the address
599 * of a struct symbol associated with that name.
606 #ifdef STRIP_UNDERSCORE
607 return (symbol_find_base (name
, 1));
608 #else /* STRIP_UNDERSCORE */
609 return (symbol_find_base (name
, 0));
610 #endif /* STRIP_UNDERSCORE */
611 } /* symbol_find() */
614 symbol_find_base (name
, strip_underscore
)
616 int strip_underscore
;
618 struct local_symbol
*locsym
;
620 if (strip_underscore
&& *name
== '_')
623 #ifdef tc_canonicalize_symbol_name
626 size_t len
= strlen (name
) + 1;
628 copy
= (char *) alloca (len
);
629 memcpy (copy
, name
, len
);
630 name
= tc_canonicalize_symbol_name (copy
);
634 if (! symbols_case_sensitive
)
641 name
= copy
= (char *) alloca (strlen (name
) + 1);
643 while ((c
= *orig
++) != '\0')
652 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
654 return (symbolS
*) locsym
;
656 return ((symbolS
*) hash_find (sy_hash
, name
));
660 * Once upon a time, symbols were kept in a singly linked list. At
661 * least coff needs to be able to rearrange them from time to time, for
662 * which a doubly linked list is much more convenient. Loic did these
663 * as macros which seemed dangerous to me so they're now functions.
667 /* Link symbol ADDME after symbol TARGET in the chain. */
669 symbol_append (addme
, target
, rootPP
, lastPP
)
675 if (LOCAL_SYMBOL_CHECK (addme
))
677 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
682 know (*rootPP
== NULL
);
683 know (*lastPP
== NULL
);
684 addme
->sy_next
= NULL
;
685 #ifdef SYMBOLS_NEED_BACKPOINTERS
686 addme
->sy_previous
= NULL
;
691 } /* if the list is empty */
693 if (target
->sy_next
!= NULL
)
695 #ifdef SYMBOLS_NEED_BACKPOINTERS
696 target
->sy_next
->sy_previous
= addme
;
697 #endif /* SYMBOLS_NEED_BACKPOINTERS */
701 know (*lastPP
== target
);
703 } /* if we have a next */
705 addme
->sy_next
= target
->sy_next
;
706 target
->sy_next
= addme
;
708 #ifdef SYMBOLS_NEED_BACKPOINTERS
709 addme
->sy_previous
= target
;
710 #endif /* SYMBOLS_NEED_BACKPOINTERS */
712 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
715 /* Set the chain pointers of SYMBOL to null. */
717 symbol_clear_list_pointers (symbolP
)
720 if (LOCAL_SYMBOL_CHECK (symbolP
))
722 symbolP
->sy_next
= NULL
;
723 #ifdef SYMBOLS_NEED_BACKPOINTERS
724 symbolP
->sy_previous
= NULL
;
728 #ifdef SYMBOLS_NEED_BACKPOINTERS
729 /* Remove SYMBOLP from the list. */
731 symbol_remove (symbolP
, rootPP
, lastPP
)
736 if (LOCAL_SYMBOL_CHECK (symbolP
))
739 if (symbolP
== *rootPP
)
741 *rootPP
= symbolP
->sy_next
;
742 } /* if it was the root */
744 if (symbolP
== *lastPP
)
746 *lastPP
= symbolP
->sy_previous
;
747 } /* if it was the tail */
749 if (symbolP
->sy_next
!= NULL
)
751 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
754 if (symbolP
->sy_previous
!= NULL
)
756 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
759 debug_verify_symchain (*rootPP
, *lastPP
);
762 /* Link symbol ADDME before symbol TARGET in the chain. */
764 symbol_insert (addme
, target
, rootPP
, lastPP
)
770 if (LOCAL_SYMBOL_CHECK (addme
))
772 if (LOCAL_SYMBOL_CHECK (target
))
775 if (target
->sy_previous
!= NULL
)
777 target
->sy_previous
->sy_next
= addme
;
781 know (*rootPP
== target
);
785 addme
->sy_previous
= target
->sy_previous
;
786 target
->sy_previous
= addme
;
787 addme
->sy_next
= target
;
789 debug_verify_symchain (*rootPP
, *lastPP
);
792 #endif /* SYMBOLS_NEED_BACKPOINTERS */
795 verify_symbol_chain (rootP
, lastP
)
799 symbolS
*symbolP
= rootP
;
804 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
807 assert (symbolP
->bsym
!= NULL
);
809 #ifdef SYMBOLS_NEED_BACKPOINTERS
810 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
812 /* Walk the list anyways, to make sure pointers are still good. */
814 #endif /* SYMBOLS_NEED_BACKPOINTERS */
817 assert (lastP
== symbolP
);
821 verify_symbol_chain_2 (sym
)
824 symbolS
*p
= sym
, *n
= sym
;
825 #ifdef SYMBOLS_NEED_BACKPOINTERS
826 while (symbol_previous (p
))
827 p
= symbol_previous (p
);
829 while (symbol_next (n
))
831 verify_symbol_chain (p
, n
);
834 /* Resolve the value of a symbol. This is called during the final
835 pass over the symbol table to resolve any symbols with complex
839 resolve_symbol_value (symp
, finalize
)
847 if (LOCAL_SYMBOL_CHECK (symp
))
849 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
851 if (local_symbol_resolved_p (locsym
))
852 return locsym
->lsy_offset
;
854 final_val
= (local_symbol_get_frag (locsym
)->fr_address
855 + locsym
->lsy_offset
);
859 locsym
->lsy_offset
= final_val
;
860 local_symbol_mark_resolved (locsym
);
866 if (symp
->sy_resolved
)
868 if (symp
->sy_value
.X_op
== O_constant
)
869 return (valueT
) symp
->sy_value
.X_add_number
;
875 final_seg
= S_GET_SEGMENT (symp
);
877 if (symp
->sy_resolving
)
880 as_bad (_("Symbol definition loop encountered at %s"), S_GET_NAME (symp
));
886 symbolS
*add_symbol
, *op_symbol
;
888 segT seg_left
, seg_right
;
891 symp
->sy_resolving
= 1;
893 /* Help out with CSE. */
894 add_symbol
= symp
->sy_value
.X_add_symbol
;
895 op_symbol
= symp
->sy_value
.X_op_symbol
;
896 final_val
= symp
->sy_value
.X_add_number
;
897 op
= symp
->sy_value
.X_op
;
910 final_val
+= symp
->sy_frag
->fr_address
;
911 if (final_seg
== expr_section
)
912 final_seg
= absolute_section
;
918 left
= resolve_symbol_value (add_symbol
, finalize
);
921 if (symp
->sy_mri_common
)
923 /* This is a symbol inside an MRI common section. The
924 relocation routines are going to handle it specially.
925 Don't change the value. */
926 resolved
= symbol_resolved_p (add_symbol
);
930 if (finalize
&& final_val
== 0)
932 if (LOCAL_SYMBOL_CHECK (add_symbol
))
933 add_symbol
= local_symbol_convert ((struct local_symbol
*)
935 copy_symbol_attributes (symp
, add_symbol
);
938 /* If we have equated this symbol to an undefined symbol, we
939 keep X_op set to O_symbol, and we don't change
940 X_add_number. This permits the routine which writes out
941 relocation to detect this case, and convert the
942 relocation to be against the symbol to which this symbol
944 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
948 S_SET_SEGMENT (symp
, S_GET_SEGMENT (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
;
954 resolved
= symbol_resolved_p (add_symbol
);
955 goto exit_dont_set_value
;
959 final_val
+= symp
->sy_frag
->fr_address
+ left
;
960 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
961 final_seg
= S_GET_SEGMENT (add_symbol
);
964 resolved
= symbol_resolved_p (add_symbol
);
970 left
= resolve_symbol_value (add_symbol
, finalize
);
974 else if (op
== O_logical_not
)
979 final_val
+= left
+ symp
->sy_frag
->fr_address
;
980 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
981 final_seg
= absolute_section
;
983 resolved
= symbol_resolved_p (add_symbol
);
991 case O_bit_inclusive_or
:
993 case O_bit_exclusive_or
:
1005 left
= resolve_symbol_value (add_symbol
, finalize
);
1006 right
= resolve_symbol_value (op_symbol
, finalize
);
1007 seg_left
= S_GET_SEGMENT (add_symbol
);
1008 seg_right
= S_GET_SEGMENT (op_symbol
);
1010 /* Simplify addition or subtraction of a constant by folding the
1011 constant into X_add_number. */
1012 if (op
== O_add
|| op
== O_subtract
)
1014 if (seg_right
== absolute_section
)
1024 else if (seg_left
== absolute_section
&& op
== O_add
)
1028 add_symbol
= op_symbol
;
1035 /* Subtraction is permitted if both operands are in the same
1036 section. Otherwise, both operands must be absolute. We
1037 already handled the case of addition or subtraction of a
1038 constant above. This will probably need to be changed
1039 for an object file format which supports arbitrary
1040 expressions, such as IEEE-695. */
1041 /* Don't emit messages unless we're finalizing the symbol value,
1042 otherwise we may get the same message multiple times. */
1043 if ((seg_left
!= absolute_section
|| seg_right
!= absolute_section
)
1044 && (op
!= O_subtract
|| seg_left
!= seg_right
)
1050 if (expr_symbol_where (symp
, &file
, &line
))
1052 if (seg_left
== undefined_section
)
1053 as_bad_where (file
, line
,
1054 _("undefined symbol %s in operation"),
1055 S_GET_NAME (symp
->sy_value
.X_add_symbol
));
1056 if (seg_right
== undefined_section
)
1057 as_bad_where (file
, line
,
1058 _("undefined symbol %s in operation"),
1059 S_GET_NAME (symp
->sy_value
.X_op_symbol
));
1060 if (seg_left
!= undefined_section
1061 && seg_right
!= undefined_section
)
1062 as_bad_where (file
, line
, _("invalid section for operation"));
1066 if (seg_left
== undefined_section
)
1067 as_bad (_("undefined symbol %s in operation setting %s"),
1068 S_GET_NAME (symp
->sy_value
.X_add_symbol
),
1070 if (seg_right
== undefined_section
)
1071 as_bad (_("undefined symbol %s in operation setting %s"),
1072 S_GET_NAME (symp
->sy_value
.X_op_symbol
),
1074 if (seg_left
!= undefined_section
1075 && seg_right
!= undefined_section
)
1076 as_bad (_("invalid section for operation setting %s"),
1081 /* Check for division by zero. */
1082 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1084 /* If seg_right is not absolute_section, then we've
1085 already issued a warning about using a bad symbol. */
1086 if (seg_right
== absolute_section
&& finalize
)
1091 if (expr_symbol_where (symp
, &file
, &line
))
1092 as_bad_where (file
, line
, _("division by zero"));
1094 as_bad (_("division by zero when setting %s"),
1101 switch (symp
->sy_value
.X_op
)
1103 case O_multiply
: left
*= right
; break;
1104 case O_divide
: left
/= right
; break;
1105 case O_modulus
: left
%= right
; break;
1106 case O_left_shift
: left
<<= right
; break;
1107 case O_right_shift
: left
>>= right
; break;
1108 case O_bit_inclusive_or
: left
|= right
; break;
1109 case O_bit_or_not
: left
|= ~right
; break;
1110 case O_bit_exclusive_or
: left
^= right
; break;
1111 case O_bit_and
: left
&= right
; break;
1112 case O_add
: left
+= right
; break;
1113 case O_subtract
: left
-= right
; break;
1114 case O_eq
: left
= left
== right
? ~ (offsetT
) 0 : 0; break;
1115 case O_ne
: left
= left
!= right
? ~ (offsetT
) 0 : 0; break;
1116 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1117 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1118 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1119 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1120 case O_logical_and
: left
= left
&& right
; break;
1121 case O_logical_or
: left
= left
|| right
; break;
1125 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1126 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1127 final_seg
= absolute_section
;
1128 resolved
= (symbol_resolved_p (add_symbol
)
1129 && symbol_resolved_p (op_symbol
));
1135 /* Give an error (below) if not in expr_section. We don't
1136 want to worry about expr_section symbols, because they
1137 are fictional (they are created as part of expression
1138 resolution), and any problems may not actually mean
1143 symp
->sy_resolving
= 0;
1148 S_SET_VALUE (symp
, final_val
);
1150 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1151 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1152 for a stab symbol, so we use this bad hack. */
1153 if (final_seg
!= S_GET_SEGMENT (symp
))
1155 S_SET_SEGMENT (symp
, final_seg
);
1158 exit_dont_set_value
:
1159 /* Don't worry if we can't resolve an expr_section symbol. */
1163 symp
->sy_resolved
= 1;
1164 else if (S_GET_SEGMENT (symp
) != expr_section
)
1166 as_bad (_("can't resolve value for symbol \"%s\""), S_GET_NAME (symp
));
1167 symp
->sy_resolved
= 1;
1174 #ifdef BFD_ASSEMBLER
1176 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1178 /* A static function passed to hash_traverse. */
1181 resolve_local_symbol (key
, value
)
1186 resolve_symbol_value (value
, 1);
1191 /* Resolve all local symbols. */
1194 resolve_local_symbol_values ()
1196 #ifdef BFD_ASSEMBLER
1197 hash_traverse (local_hash
, resolve_local_symbol
);
1201 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1202 They are *really* local. That is, they go out of scope whenever we see a
1203 label that isn't local. Also, like fb labels, there can be multiple
1204 instances of a dollar label. Therefor, we name encode each instance with
1205 the instance number, keep a list of defined symbols separate from the real
1206 symbol table, and we treat these buggers as a sparse array. */
1208 static long *dollar_labels
;
1209 static long *dollar_label_instances
;
1210 static char *dollar_label_defines
;
1211 static unsigned long dollar_label_count
;
1212 static unsigned long dollar_label_max
;
1215 dollar_label_defined (label
)
1220 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1222 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1224 return dollar_label_defines
[i
- dollar_labels
];
1226 /* if we get here, label isn't defined */
1228 } /* dollar_label_defined() */
1231 dollar_label_instance (label
)
1236 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1238 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1240 return (dollar_label_instances
[i
- dollar_labels
]);
1242 /* If we get here, we haven't seen the label before, therefore its instance
1248 dollar_label_clear ()
1250 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1253 #define DOLLAR_LABEL_BUMP_BY 10
1256 define_dollar_label (label
)
1261 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1264 ++dollar_label_instances
[i
- dollar_labels
];
1265 dollar_label_defines
[i
- dollar_labels
] = 1;
1269 /* if we get to here, we don't have label listed yet. */
1271 if (dollar_labels
== NULL
)
1273 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1274 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1275 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1276 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1277 dollar_label_count
= 0;
1279 else if (dollar_label_count
== dollar_label_max
)
1281 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1282 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1283 dollar_label_max
* sizeof (long));
1284 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1285 dollar_label_max
* sizeof (long));
1286 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1287 } /* if we needed to grow */
1289 dollar_labels
[dollar_label_count
] = label
;
1290 dollar_label_instances
[dollar_label_count
] = 1;
1291 dollar_label_defines
[dollar_label_count
] = 1;
1292 ++dollar_label_count
;
1296 * dollar_label_name()
1298 * Caller must copy returned name: we re-use the area for the next name.
1300 * The mth occurence of label n: is turned into the symbol "Ln^Am"
1301 * where n is the label number and m is the instance number. "L" makes
1302 * it a label discarded unless debugging and "^A"('\1') ensures no
1303 * ordinary symbol SHOULD get the same name as a local label
1304 * symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1306 * fb labels get the same treatment, except that ^B is used in place of ^A.
1309 char * /* Return local label name. */
1310 dollar_label_name (n
, augend
)
1311 register long n
; /* we just saw "n$:" : n a number */
1312 register int augend
; /* 0 for current instance, 1 for new instance */
1315 /* Returned to caller, then copied. used for created names ("4f") */
1316 static char symbol_name_build
[24];
1319 char symbol_name_temporary
[20]; /* build up a number, BACKWARDS */
1322 know (augend
== 0 || augend
== 1);
1323 p
= symbol_name_build
;
1326 /* Next code just does sprintf( {}, "%d", n); */
1328 q
= symbol_name_temporary
;
1329 for (*q
++ = 0, i
= n
; i
; ++q
)
1334 while ((*p
= *--q
) != '\0')
1339 /* instance number */
1340 q
= symbol_name_temporary
;
1341 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1346 while ((*p
++ = *--q
) != '\0');;
1348 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1349 return symbol_name_build
;
1353 * Sombody else's idea of local labels. They are made by "n:" where n
1354 * is any decimal digit. Refer to them with
1355 * "nb" for previous (backward) n:
1356 * or "nf" for next (forward) n:.
1358 * We do a little better and let n be any number, not just a single digit, but
1359 * since the other guy's assembler only does ten, we treat the first ten
1362 * Like someone else's assembler, we have one set of local label counters for
1363 * entire assembly, not one set per (sub)segment like in most assemblers. This
1364 * implies that one can refer to a label in another segment, and indeed some
1365 * crufty compilers have done just that.
1367 * Since there could be a LOT of these things, treat them as a sparse array.
1370 #define FB_LABEL_SPECIAL (10)
1372 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1373 static long *fb_labels
;
1374 static long *fb_label_instances
;
1375 static long fb_label_count
;
1376 static long fb_label_max
;
1378 /* this must be more than FB_LABEL_SPECIAL */
1379 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1384 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1385 } /* fb_label_init() */
1387 /* add one to the instance number of this fb label */
1389 fb_label_instance_inc (label
)
1394 if (label
< FB_LABEL_SPECIAL
)
1396 ++fb_low_counter
[label
];
1400 if (fb_labels
!= NULL
)
1402 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1403 i
< fb_labels
+ fb_label_count
; ++i
)
1407 ++fb_label_instances
[i
- fb_labels
];
1409 } /* if we find it */
1410 } /* for each existing label */
1413 /* if we get to here, we don't have label listed yet. */
1415 if (fb_labels
== NULL
)
1417 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1418 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1419 fb_label_max
= FB_LABEL_BUMP_BY
;
1420 fb_label_count
= FB_LABEL_SPECIAL
;
1423 else if (fb_label_count
== fb_label_max
)
1425 fb_label_max
+= FB_LABEL_BUMP_BY
;
1426 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1427 fb_label_max
* sizeof (long));
1428 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1429 fb_label_max
* sizeof (long));
1430 } /* if we needed to grow */
1432 fb_labels
[fb_label_count
] = label
;
1433 fb_label_instances
[fb_label_count
] = 1;
1438 fb_label_instance (label
)
1443 if (label
< FB_LABEL_SPECIAL
)
1445 return (fb_low_counter
[label
]);
1448 if (fb_labels
!= NULL
)
1450 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1451 i
< fb_labels
+ fb_label_count
; ++i
)
1455 return (fb_label_instances
[i
- fb_labels
]);
1456 } /* if we find it */
1457 } /* for each existing label */
1460 /* We didn't find the label, so this must be a reference to the
1468 * Caller must copy returned name: we re-use the area for the next name.
1470 * The mth occurence of label n: is turned into the symbol "Ln^Bm"
1471 * where n is the label number and m is the instance number. "L" makes
1472 * it a label discarded unless debugging and "^B"('\2') ensures no
1473 * ordinary symbol SHOULD get the same name as a local label
1474 * symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1476 * dollar labels get the same treatment, except that ^A is used in place of ^B. */
1478 char * /* Return local label name. */
1479 fb_label_name (n
, augend
)
1480 long n
; /* we just saw "n:", "nf" or "nb" : n a number */
1481 long augend
; /* 0 for nb, 1 for n:, nf */
1484 /* Returned to caller, then copied. used for created names ("4f") */
1485 static char symbol_name_build
[24];
1488 char symbol_name_temporary
[20]; /* build up a number, BACKWARDS */
1491 know (augend
== 0 || augend
== 1);
1492 p
= symbol_name_build
;
1495 /* Next code just does sprintf( {}, "%d", n); */
1497 q
= symbol_name_temporary
;
1498 for (*q
++ = 0, i
= n
; i
; ++q
)
1503 while ((*p
= *--q
) != '\0')
1508 /* instance number */
1509 q
= symbol_name_temporary
;
1510 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1515 while ((*p
++ = *--q
) != '\0');;
1517 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1518 return (symbol_name_build
);
1519 } /* fb_label_name() */
1522 * decode name that may have been generated by foo_label_name() above. If
1523 * the name wasn't generated by foo_label_name(), then return it unaltered.
1524 * This is used for error messages.
1528 decode_local_label_name (s
)
1532 char *symbol_decode
;
1534 int instance_number
;
1536 const char *message_format
= _("\"%d\" (instance number %d of a %s label)");
1541 for (label_number
= 0, p
= s
+ 1; isdigit ((unsigned char) *p
); ++p
)
1542 label_number
= (10 * label_number
) + *p
- '0';
1551 for (instance_number
= 0, p
++; isdigit ((unsigned char) *p
); ++p
)
1552 instance_number
= (10 * instance_number
) + *p
- '0';
1554 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1555 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1557 return symbol_decode
;
1560 /* Get the value of a symbol. */
1566 if (LOCAL_SYMBOL_CHECK (s
))
1567 return ((struct local_symbol
*) s
)->lsy_offset
;
1569 if (!s
->sy_resolved
&& s
->sy_value
.X_op
!= O_constant
)
1570 resolve_symbol_value (s
, 1);
1571 if (s
->sy_value
.X_op
!= O_constant
)
1573 static symbolS
*recur
;
1575 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1576 may call S_GET_VALUE. We use a static symbol to avoid the
1577 immediate recursion. */
1579 return (valueT
) s
->sy_value
.X_add_number
;
1581 if (! s
->sy_resolved
1582 || s
->sy_value
.X_op
!= O_symbol
1583 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1584 as_bad (_("Attempt to get value of unresolved symbol %s"),
1588 return (valueT
) s
->sy_value
.X_add_number
;
1591 /* Set the value of a symbol. */
1594 S_SET_VALUE (s
, val
)
1598 if (LOCAL_SYMBOL_CHECK (s
))
1600 ((struct local_symbol
*) s
)->lsy_offset
= val
;
1604 s
->sy_value
.X_op
= O_constant
;
1605 s
->sy_value
.X_add_number
= (offsetT
) val
;
1606 s
->sy_value
.X_unsigned
= 0;
1610 copy_symbol_attributes (dest
, src
)
1611 symbolS
*dest
, *src
;
1613 if (LOCAL_SYMBOL_CHECK (dest
))
1615 if (LOCAL_SYMBOL_CHECK (src
))
1618 #ifdef BFD_ASSEMBLER
1619 /* In an expression, transfer the settings of these flags.
1620 The user can override later, of course. */
1621 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1622 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1625 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1626 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1630 #ifdef BFD_ASSEMBLER
1638 if (LOCAL_SYMBOL_CHECK (s
))
1641 flags
= s
->bsym
->flags
;
1643 return (flags
& BSF_FUNCTION
) != 0;
1652 if (LOCAL_SYMBOL_CHECK (s
))
1655 flags
= s
->bsym
->flags
;
1658 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1661 return (flags
& BSF_GLOBAL
) != 0;
1668 if (LOCAL_SYMBOL_CHECK (s
))
1670 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1677 if (LOCAL_SYMBOL_CHECK (s
))
1679 return bfd_is_com_section (s
->bsym
->section
);
1686 if (LOCAL_SYMBOL_CHECK (s
))
1687 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1688 return s
->bsym
->section
!= undefined_section
;
1695 if (LOCAL_SYMBOL_CHECK (s
))
1697 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1709 if (LOCAL_SYMBOL_CHECK (s
))
1712 flags
= s
->bsym
->flags
;
1715 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1718 if (bfd_get_section (s
->bsym
) == reg_section
)
1721 if (flag_strip_local_absolute
1722 && (flags
& BSF_GLOBAL
) == 0
1723 && bfd_get_section (s
->bsym
) == absolute_section
)
1726 name
= S_GET_NAME (s
);
1727 return (name
!= NULL
1729 && (strchr (name
, '\001')
1730 || strchr (name
, '\002')
1731 || (! flag_keep_locals
1732 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1735 && name
[1] == '?')))));
1742 return S_IS_EXTERNAL (s
);
1749 return S_GET_NAME (s
) == 0;
1756 if (LOCAL_SYMBOL_CHECK (s
))
1757 return ((struct local_symbol
*) s
)->lsy_name
;
1758 return s
->bsym
->name
;
1765 if (LOCAL_SYMBOL_CHECK (s
))
1766 return ((struct local_symbol
*) s
)->lsy_section
;
1767 return s
->bsym
->section
;
1771 S_SET_SEGMENT (s
, seg
)
1775 /* Don't reassign section symbols. The direct reason is to prevent seg
1776 faults assigning back to const global symbols such as *ABS*, but it
1777 shouldn't happen anyway. */
1779 if (LOCAL_SYMBOL_CHECK (s
))
1781 if (seg
== reg_section
)
1782 s
= local_symbol_convert ((struct local_symbol
*) s
);
1785 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1790 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1792 if (s
->bsym
->section
!= seg
)
1796 s
->bsym
->section
= seg
;
1803 if (LOCAL_SYMBOL_CHECK (s
))
1804 s
= local_symbol_convert ((struct local_symbol
*) s
);
1805 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1807 /* Let .weak override .global. */
1810 s
->bsym
->flags
|= BSF_GLOBAL
;
1811 s
->bsym
->flags
&= ~(BSF_LOCAL
|BSF_WEAK
);
1815 S_CLEAR_EXTERNAL (s
)
1818 if (LOCAL_SYMBOL_CHECK (s
))
1820 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1822 /* Let .weak override. */
1825 s
->bsym
->flags
|= BSF_LOCAL
;
1826 s
->bsym
->flags
&= ~(BSF_GLOBAL
|BSF_WEAK
);
1833 if (LOCAL_SYMBOL_CHECK (s
))
1834 s
= local_symbol_convert ((struct local_symbol
*) s
);
1835 s
->bsym
->flags
|= BSF_WEAK
;
1836 s
->bsym
->flags
&= ~(BSF_GLOBAL
|BSF_LOCAL
);
1840 S_SET_NAME (s
, name
)
1844 if (LOCAL_SYMBOL_CHECK (s
))
1846 ((struct local_symbol
*) s
)->lsy_name
= name
;
1849 s
->bsym
->name
= name
;
1851 #endif /* BFD_ASSEMBLER */
1853 #ifdef SYMBOLS_NEED_BACKPOINTERS
1855 /* Return the previous symbol in a chain. */
1861 if (LOCAL_SYMBOL_CHECK (s
))
1863 return s
->sy_previous
;
1866 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1868 /* Return the next symbol in a chain. */
1874 if (LOCAL_SYMBOL_CHECK (s
))
1879 /* Return a pointer to the value of a symbol as an expression. */
1882 symbol_get_value_expression (s
)
1885 if (LOCAL_SYMBOL_CHECK (s
))
1886 s
= local_symbol_convert ((struct local_symbol
*) s
);
1887 return &s
->sy_value
;
1890 /* Set the value of a symbol to an expression. */
1893 symbol_set_value_expression (s
, exp
)
1895 const expressionS
*exp
;
1897 if (LOCAL_SYMBOL_CHECK (s
))
1898 s
= local_symbol_convert ((struct local_symbol
*) s
);
1902 /* Set the frag of a symbol. */
1905 symbol_set_frag (s
, f
)
1909 if (LOCAL_SYMBOL_CHECK (s
))
1911 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
1917 /* Return the frag of a symbol. */
1923 if (LOCAL_SYMBOL_CHECK (s
))
1924 return local_symbol_get_frag ((struct local_symbol
*) s
);
1928 /* Mark a symbol as having been used. */
1931 symbol_mark_used (s
)
1934 if (LOCAL_SYMBOL_CHECK (s
))
1939 /* Clear the mark of whether a symbol has been used. */
1942 symbol_clear_used (s
)
1945 if (LOCAL_SYMBOL_CHECK (s
))
1946 s
= local_symbol_convert ((struct local_symbol
*) s
);
1950 /* Return whether a symbol has been used. */
1956 if (LOCAL_SYMBOL_CHECK (s
))
1961 /* Mark a symbol as having been used in a reloc. */
1964 symbol_mark_used_in_reloc (s
)
1967 if (LOCAL_SYMBOL_CHECK (s
))
1968 s
= local_symbol_convert ((struct local_symbol
*) s
);
1969 s
->sy_used_in_reloc
= 1;
1972 /* Clear the mark of whether a symbol has been used in a reloc. */
1975 symbol_clear_used_in_reloc (s
)
1978 if (LOCAL_SYMBOL_CHECK (s
))
1980 s
->sy_used_in_reloc
= 0;
1983 /* Return whether a symbol has been used in a reloc. */
1986 symbol_used_in_reloc_p (s
)
1989 if (LOCAL_SYMBOL_CHECK (s
))
1991 return s
->sy_used_in_reloc
;
1994 /* Mark a symbol as an MRI common symbol. */
1997 symbol_mark_mri_common (s
)
2000 if (LOCAL_SYMBOL_CHECK (s
))
2001 s
= local_symbol_convert ((struct local_symbol
*) s
);
2002 s
->sy_mri_common
= 1;
2005 /* Clear the mark of whether a symbol is an MRI common symbol. */
2008 symbol_clear_mri_common (s
)
2011 if (LOCAL_SYMBOL_CHECK (s
))
2013 s
->sy_mri_common
= 0;
2016 /* Return whether a symbol is an MRI common symbol. */
2019 symbol_mri_common_p (s
)
2022 if (LOCAL_SYMBOL_CHECK (s
))
2024 return s
->sy_mri_common
;
2027 /* Mark a symbol as having been written. */
2030 symbol_mark_written (s
)
2033 if (LOCAL_SYMBOL_CHECK (s
))
2038 /* Clear the mark of whether a symbol has been written. */
2041 symbol_clear_written (s
)
2044 if (LOCAL_SYMBOL_CHECK (s
))
2049 /* Return whether a symbol has been written. */
2052 symbol_written_p (s
)
2055 if (LOCAL_SYMBOL_CHECK (s
))
2060 /* Mark a symbol has having been resolved. */
2063 symbol_mark_resolved (s
)
2066 if (LOCAL_SYMBOL_CHECK (s
))
2068 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2074 /* Return whether a symbol has been resolved. */
2077 symbol_resolved_p (s
)
2080 if (LOCAL_SYMBOL_CHECK (s
))
2081 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2082 return s
->sy_resolved
;
2085 /* Return whether a symbol is a section symbol. */
2088 symbol_section_p (s
)
2091 if (LOCAL_SYMBOL_CHECK (s
))
2093 #ifdef BFD_ASSEMBLER
2094 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2101 /* Return whether a symbol is equated to another symbol. */
2104 symbol_equated_p (s
)
2107 if (LOCAL_SYMBOL_CHECK (s
))
2109 return s
->sy_value
.X_op
== O_symbol
;
2112 /* Return whether a symbol has a constant value. */
2115 symbol_constant_p (s
)
2118 if (LOCAL_SYMBOL_CHECK (s
))
2120 return s
->sy_value
.X_op
== O_constant
;
2123 #ifdef BFD_ASSEMBLER
2125 /* Return the BFD symbol for a symbol. */
2128 symbol_get_bfdsym (s
)
2131 if (LOCAL_SYMBOL_CHECK (s
))
2132 s
= local_symbol_convert ((struct local_symbol
*) s
);
2136 /* Set the BFD symbol for a symbol. */
2139 symbol_set_bfdsym (s
, bsym
)
2143 if (LOCAL_SYMBOL_CHECK (s
))
2144 s
= local_symbol_convert ((struct local_symbol
*) s
);
2148 #endif /* BFD_ASSEMBLER */
2150 #ifdef OBJ_SYMFIELD_TYPE
2152 /* Get a pointer to the object format information for a symbol. */
2158 if (LOCAL_SYMBOL_CHECK (s
))
2159 s
= local_symbol_convert ((struct local_symbol
*) s
);
2163 /* Set the object format information for a symbol. */
2166 symbol_set_obj (s
, o
)
2168 OBJ_SYMFIELD_TYPE
*o
;
2170 if (LOCAL_SYMBOL_CHECK (s
))
2171 s
= local_symbol_convert ((struct local_symbol
*) s
);
2175 #endif /* OBJ_SYMFIELD_TYPE */
2177 #ifdef TC_SYMFIELD_TYPE
2179 /* Get a pointer to the processor information for a symbol. */
2185 if (LOCAL_SYMBOL_CHECK (s
))
2186 s
= local_symbol_convert ((struct local_symbol
*) s
);
2190 /* Set the processor information for a symbol. */
2193 symbol_set_tc (s
, o
)
2195 TC_SYMFIELD_TYPE
*o
;
2197 if (LOCAL_SYMBOL_CHECK (s
))
2198 s
= local_symbol_convert ((struct local_symbol
*) s
);
2202 #endif /* TC_SYMFIELD_TYPE */
2207 symbol_lastP
= NULL
;
2208 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2209 sy_hash
= hash_new ();
2210 #ifdef BFD_ASSEMBLER
2211 local_hash
= hash_new ();
2214 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2215 #ifdef BFD_ASSEMBLER
2216 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2217 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2220 /* Can't initialise a union. Sigh. */
2221 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2223 abs_symbol
.sy_value
.X_op
= O_constant
;
2224 abs_symbol
.sy_frag
= &zero_address_frag
;
2226 if (LOCAL_LABELS_FB
)
2234 /* Maximum indent level.
2235 Available for modification inside a gdb session. */
2236 int max_indent_level
= 8;
2243 printf ("%*s", indent_level
* 4, "");
2249 print_symbol_value_1 (file
, sym
)
2253 const char *name
= S_GET_NAME (sym
);
2254 if (!name
|| !name
[0])
2256 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2258 if (LOCAL_SYMBOL_CHECK (sym
))
2260 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2261 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2262 && local_symbol_get_frag (locsym
) != NULL
)
2263 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2264 if (local_symbol_resolved_p (locsym
))
2265 fprintf (file
, " resolved");
2266 fprintf (file
, " local");
2270 if (sym
->sy_frag
!= &zero_address_frag
)
2271 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2273 fprintf (file
, " written");
2274 if (sym
->sy_resolved
)
2275 fprintf (file
, " resolved");
2276 else if (sym
->sy_resolving
)
2277 fprintf (file
, " resolving");
2278 if (sym
->sy_used_in_reloc
)
2279 fprintf (file
, " used-in-reloc");
2281 fprintf (file
, " used");
2282 if (S_IS_LOCAL (sym
))
2283 fprintf (file
, " local");
2284 if (S_IS_EXTERN (sym
))
2285 fprintf (file
, " extern");
2286 if (S_IS_DEBUG (sym
))
2287 fprintf (file
, " debug");
2288 if (S_IS_DEFINED (sym
))
2289 fprintf (file
, " defined");
2291 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2292 if (symbol_resolved_p (sym
))
2294 segT s
= S_GET_SEGMENT (sym
);
2296 if (s
!= undefined_section
2297 && s
!= expr_section
)
2298 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2300 else if (indent_level
< max_indent_level
2301 && S_GET_SEGMENT (sym
) != undefined_section
)
2304 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2305 if (LOCAL_SYMBOL_CHECK (sym
))
2306 fprintf (file
, "constant %lx",
2307 (long) ((struct local_symbol
*) sym
)->lsy_offset
);
2309 print_expr_1 (file
, &sym
->sy_value
);
2310 fprintf (file
, ">");
2317 print_symbol_value (sym
)
2321 print_symbol_value_1 (stderr
, sym
);
2322 fprintf (stderr
, "\n");
2326 print_binary (file
, name
, exp
)
2332 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2333 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2334 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2335 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2336 fprintf (file
, ">");
2341 print_expr_1 (file
, exp
)
2345 fprintf (file
, "expr %lx ", (long) exp
);
2349 fprintf (file
, "illegal");
2352 fprintf (file
, "absent");
2355 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2359 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2360 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2361 fprintf (file
, ">");
2363 if (exp
->X_add_number
)
2364 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2365 (long) exp
->X_add_number
);
2369 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2372 fprintf (file
, "big");
2375 fprintf (file
, "uminus -<");
2377 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2378 fprintf (file
, ">");
2379 goto maybe_print_addnum
;
2381 fprintf (file
, "bit_not");
2384 print_binary (file
, "multiply", exp
);
2387 print_binary (file
, "divide", exp
);
2390 print_binary (file
, "modulus", exp
);
2393 print_binary (file
, "lshift", exp
);
2396 print_binary (file
, "rshift", exp
);
2398 case O_bit_inclusive_or
:
2399 print_binary (file
, "bit_ior", exp
);
2401 case O_bit_exclusive_or
:
2402 print_binary (file
, "bit_xor", exp
);
2405 print_binary (file
, "bit_and", exp
);
2408 print_binary (file
, "eq", exp
);
2411 print_binary (file
, "ne", exp
);
2414 print_binary (file
, "lt", exp
);
2417 print_binary (file
, "le", exp
);
2420 print_binary (file
, "ge", exp
);
2423 print_binary (file
, "gt", exp
);
2426 print_binary (file
, "logical_and", exp
);
2429 print_binary (file
, "logical_or", exp
);
2433 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2434 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2435 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2436 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2437 fprintf (file
, ">");
2438 goto maybe_print_addnum
;
2441 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
2442 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2443 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2444 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2445 fprintf (file
, ">");
2446 goto maybe_print_addnum
;
2448 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2458 print_expr_1 (stderr
, exp
);
2459 fprintf (stderr
, "\n");
2463 symbol_print_statistics (file
)
2466 hash_print_statistics (file
, "symbol table", sy_hash
);
2467 #ifdef BFD_ASSEMBLER
2468 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2469 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2470 local_symbol_count
, local_symbol_conversion_count
);
2474 /* end of symbols.c */