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 void fb_label_init
PARAMS ((void));
65 static long dollar_label_instance
PARAMS ((long));
66 static long fb_label_instance
PARAMS ((long));
68 static void print_binary
PARAMS ((FILE *, const char *, expressionS
*));
70 /* Return a pointer to a new symbol. Die if we can't make a new
71 symbol. Fill in the symbol's values. Add symbol to end of symbol
74 This function should be called in the general case of creating a
75 symbol. However, if the output file symbol table has already been
76 set, and you are certain that this symbol won't be wanted in the
77 output file, you can call symbol_create. */
80 symbol_new (name
, segment
, valu
, frag
)
86 symbolS
*symbolP
= symbol_create (name
, segment
, valu
, frag
);
88 /* Link to end of symbol chain. */
91 extern int symbol_table_frozen
;
92 if (symbol_table_frozen
)
96 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
101 /* Save a symbol name on a permanent obstack, and convert it according
102 to the object file format. */
105 save_symbol_name (name
)
108 unsigned int name_length
;
111 name_length
= strlen (name
) + 1; /* +1 for \0. */
112 obstack_grow (¬es
, name
, name_length
);
113 ret
= obstack_finish (¬es
);
115 #ifdef STRIP_UNDERSCORE
120 #ifdef tc_canonicalize_symbol_name
121 ret
= tc_canonicalize_symbol_name (ret
);
124 if (! symbols_case_sensitive
)
128 for (s
= (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 */
275 /* We have just seen "<name>:".
276 Creates a struct symbol unless it already exists.
278 Gripes if we are redefining a symbol incompatibly (and ignores it). */
281 colon (sym_name
) /* Just seen "x:" - rattle symbols & frags. */
282 const char *sym_name
; /* Symbol name, as a cannonical string. */
283 /* We copy this string: OK to alter later. */
285 register symbolS
*symbolP
; /* Symbol we are working with. */
287 /* Sun local labels go out of scope whenever a non-local symbol is
289 if (LOCAL_LABELS_DOLLAR
)
294 local
= bfd_is_local_label_name (stdoutput
, sym_name
);
296 local
= LOCAL_LABEL (sym_name
);
300 dollar_label_clear ();
303 #ifndef WORKING_DOT_WORD
304 if (new_broken_words
)
306 struct broken_word
*a
;
311 extern const int md_short_jump_size
;
312 extern const int md_long_jump_size
;
313 possible_bytes
= (md_short_jump_size
314 + new_broken_words
* md_long_jump_size
);
317 frag_opcode
= frag_var (rs_broken_word
,
321 (symbolS
*) broken_words
,
325 /* We want to store the pointer to where to insert the jump
326 table in the fr_opcode of the rs_broken_word frag. This
327 requires a little hackery. */
329 && (frag_tmp
->fr_type
!= rs_broken_word
330 || frag_tmp
->fr_opcode
))
331 frag_tmp
= frag_tmp
->fr_next
;
333 frag_tmp
->fr_opcode
= frag_opcode
;
334 new_broken_words
= 0;
336 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
337 a
->dispfrag
= frag_tmp
;
339 #endif /* WORKING_DOT_WORD */
341 if ((symbolP
= symbol_find (sym_name
)) != 0)
343 #ifdef RESOLVE_SYMBOL_REDEFINITION
344 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
347 /* Now check for undefined symbols. */
348 if (LOCAL_SYMBOL_CHECK (symbolP
))
351 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
353 if (locsym
->lsy_section
!= undefined_section
354 && (local_symbol_get_frag (locsym
) != frag_now
355 || locsym
->lsy_section
!= now_seg
356 || locsym
->lsy_offset
!= frag_now_fix ()))
358 as_bad (_("Symbol %s already defined."), sym_name
);
362 locsym
->lsy_section
= now_seg
;
363 local_symbol_set_frag (locsym
, frag_now
);
364 locsym
->lsy_offset
= frag_now_fix ();
367 else if (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
369 if (S_GET_VALUE (symbolP
) == 0)
371 symbolP
->sy_frag
= frag_now
;
373 S_SET_OTHER (symbolP
, const_flag
);
375 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
376 S_SET_SEGMENT (symbolP
, now_seg
);
379 #endif /* if we have one, it better be zero. */
384 /* There are still several cases to check:
386 A .comm/.lcomm symbol being redefined as initialized
389 A .comm/.lcomm symbol being redefined with a larger
392 This only used to be allowed on VMS gas, but Sun cc
393 on the sparc also depends on it. */
395 if (((!S_IS_DEBUG (symbolP
)
396 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
397 && S_IS_EXTERNAL (symbolP
))
398 || S_GET_SEGMENT (symbolP
) == bss_section
)
399 && (now_seg
== data_section
400 || now_seg
== S_GET_SEGMENT (symbolP
)))
402 /* Select which of the 2 cases this is. */
403 if (now_seg
!= data_section
)
405 /* New .comm for prev .comm symbol.
407 If the new size is larger we just change its
408 value. If the new size is smaller, we ignore
410 if (S_GET_VALUE (symbolP
)
411 < ((unsigned) frag_now_fix ()))
413 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
418 /* It is a .comm/.lcomm being converted to initialized
420 symbolP
->sy_frag
= frag_now
;
422 S_SET_OTHER (symbolP
, const_flag
);
424 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
425 S_SET_SEGMENT (symbolP
, now_seg
); /* Keep N_EXT bit. */
430 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
431 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
432 static const char *od_buf
= "";
437 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
439 sprintf(od_buf
, "%d.%d.",
440 S_GET_OTHER (symbolP
),
441 S_GET_DESC (symbolP
));
443 as_bad (_("Symbol \"%s\" is already defined as \"%s\"/%s%ld."),
445 segment_name (S_GET_SEGMENT (symbolP
)),
447 (long) S_GET_VALUE (symbolP
));
449 } /* if the undefined symbol has no value */
453 /* Don't blow up if the definition is the same. */
454 if (!(frag_now
== symbolP
->sy_frag
455 && S_GET_VALUE (symbolP
) == frag_now_fix ()
456 && S_GET_SEGMENT (symbolP
) == now_seg
))
457 as_bad (_("Symbol %s already defined."), sym_name
);
462 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
464 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
465 (valueT
) frag_now_fix (),
468 #endif /* BFD_ASSEMBLER */
471 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
474 S_SET_OTHER (symbolP
, const_flag
);
477 symbol_table_insert (symbolP
);
480 if (mri_common_symbol
!= NULL
)
482 /* This symbol is actually being defined within an MRI common
483 section. This requires special handling. */
484 if (LOCAL_SYMBOL_CHECK (symbolP
))
485 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
486 symbolP
->sy_value
.X_op
= O_symbol
;
487 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
488 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
489 symbolP
->sy_frag
= &zero_address_frag
;
490 S_SET_SEGMENT (symbolP
, expr_section
);
491 symbolP
->sy_mri_common
= 1;
495 tc_frob_label (symbolP
);
497 #ifdef obj_frob_label
498 obj_frob_label (symbolP
);
504 /* Die if we can't insert the symbol. */
507 symbol_table_insert (symbolP
)
510 register const char *error_string
;
513 know (S_GET_NAME (symbolP
));
515 if (LOCAL_SYMBOL_CHECK (symbolP
))
517 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
519 if (error_string
!= NULL
)
520 as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
521 S_GET_NAME (symbolP
), error_string
);
525 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
527 as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
528 S_GET_NAME (symbolP
), error_string
);
532 /* If a symbol name does not exist, create it as undefined, and insert
533 it into the symbol table. Return a pointer to it. */
536 symbol_find_or_make (name
)
539 register symbolS
*symbolP
;
541 symbolP
= symbol_find (name
);
546 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
548 symbolP
= md_undefined_symbol ((char *) name
);
552 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
559 symbolP
= symbol_make (name
);
561 symbol_table_insert (symbolP
);
562 } /* if symbol wasn't found */
573 /* Let the machine description default it, e.g. for register names. */
574 symbolP
= md_undefined_symbol ((char *) name
);
577 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
582 /* Implement symbol table lookup.
583 In: A symbol's name as a string: '\0' can't be part of a symbol name.
584 Out: NULL if the name was not in the symbol table, else the address
585 of a struct symbol associated with that name. */
591 #ifdef STRIP_UNDERSCORE
592 return (symbol_find_base (name
, 1));
593 #else /* STRIP_UNDERSCORE */
594 return (symbol_find_base (name
, 0));
595 #endif /* STRIP_UNDERSCORE */
599 symbol_find_base (name
, strip_underscore
)
601 int strip_underscore
;
603 if (strip_underscore
&& *name
== '_')
606 #ifdef tc_canonicalize_symbol_name
609 size_t len
= strlen (name
) + 1;
611 copy
= (char *) alloca (len
);
612 memcpy (copy
, name
, len
);
613 name
= tc_canonicalize_symbol_name (copy
);
617 if (! symbols_case_sensitive
)
624 name
= copy
= (char *) alloca (strlen (name
) + 1);
626 while ((c
= *orig
++) != '\0')
637 struct local_symbol
*locsym
;
639 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
641 return (symbolS
*) locsym
;
645 return ((symbolS
*) hash_find (sy_hash
, name
));
648 /* Once upon a time, symbols were kept in a singly linked list. At
649 least coff needs to be able to rearrange them from time to time, for
650 which a doubly linked list is much more convenient. Loic did these
651 as macros which seemed dangerous to me so they're now functions.
654 /* Link symbol ADDME after symbol TARGET in the chain. */
657 symbol_append (addme
, target
, rootPP
, lastPP
)
663 if (LOCAL_SYMBOL_CHECK (addme
))
665 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
670 know (*rootPP
== NULL
);
671 know (*lastPP
== NULL
);
672 addme
->sy_next
= NULL
;
673 #ifdef SYMBOLS_NEED_BACKPOINTERS
674 addme
->sy_previous
= NULL
;
679 } /* if the list is empty */
681 if (target
->sy_next
!= NULL
)
683 #ifdef SYMBOLS_NEED_BACKPOINTERS
684 target
->sy_next
->sy_previous
= addme
;
685 #endif /* SYMBOLS_NEED_BACKPOINTERS */
689 know (*lastPP
== target
);
691 } /* if we have a next */
693 addme
->sy_next
= target
->sy_next
;
694 target
->sy_next
= addme
;
696 #ifdef SYMBOLS_NEED_BACKPOINTERS
697 addme
->sy_previous
= target
;
698 #endif /* SYMBOLS_NEED_BACKPOINTERS */
700 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
703 /* Set the chain pointers of SYMBOL to null. */
706 symbol_clear_list_pointers (symbolP
)
709 if (LOCAL_SYMBOL_CHECK (symbolP
))
711 symbolP
->sy_next
= NULL
;
712 #ifdef SYMBOLS_NEED_BACKPOINTERS
713 symbolP
->sy_previous
= NULL
;
717 #ifdef SYMBOLS_NEED_BACKPOINTERS
718 /* Remove SYMBOLP from the list. */
721 symbol_remove (symbolP
, rootPP
, lastPP
)
726 if (LOCAL_SYMBOL_CHECK (symbolP
))
729 if (symbolP
== *rootPP
)
731 *rootPP
= symbolP
->sy_next
;
732 } /* if it was the root */
734 if (symbolP
== *lastPP
)
736 *lastPP
= symbolP
->sy_previous
;
737 } /* if it was the tail */
739 if (symbolP
->sy_next
!= NULL
)
741 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
744 if (symbolP
->sy_previous
!= NULL
)
746 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
749 debug_verify_symchain (*rootPP
, *lastPP
);
752 /* Link symbol ADDME before symbol TARGET in the chain. */
755 symbol_insert (addme
, target
, rootPP
, lastPP
)
759 symbolS
**lastPP ATTRIBUTE_UNUSED
;
761 if (LOCAL_SYMBOL_CHECK (addme
))
763 if (LOCAL_SYMBOL_CHECK (target
))
766 if (target
->sy_previous
!= NULL
)
768 target
->sy_previous
->sy_next
= addme
;
772 know (*rootPP
== target
);
776 addme
->sy_previous
= target
->sy_previous
;
777 target
->sy_previous
= addme
;
778 addme
->sy_next
= target
;
780 debug_verify_symchain (*rootPP
, *lastPP
);
783 #endif /* SYMBOLS_NEED_BACKPOINTERS */
786 verify_symbol_chain (rootP
, lastP
)
790 symbolS
*symbolP
= rootP
;
795 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
798 assert (symbolP
->bsym
!= NULL
);
800 #ifdef SYMBOLS_NEED_BACKPOINTERS
801 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
803 /* Walk the list anyways, to make sure pointers are still good. */
805 #endif /* SYMBOLS_NEED_BACKPOINTERS */
808 assert (lastP
== symbolP
);
812 verify_symbol_chain_2 (sym
)
815 symbolS
*p
= sym
, *n
= sym
;
816 #ifdef SYMBOLS_NEED_BACKPOINTERS
817 while (symbol_previous (p
))
818 p
= symbol_previous (p
);
820 while (symbol_next (n
))
822 verify_symbol_chain (p
, n
);
825 /* Resolve the value of a symbol. This is called during the final
826 pass over the symbol table to resolve any symbols with complex
830 resolve_symbol_value (symp
, finalize
)
839 if (LOCAL_SYMBOL_CHECK (symp
))
841 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
843 if (local_symbol_resolved_p (locsym
))
844 return locsym
->lsy_offset
/ bfd_octets_per_byte (stdoutput
);
846 final_val
= (local_symbol_get_frag (locsym
)->fr_address
847 + locsym
->lsy_offset
) / bfd_octets_per_byte (stdoutput
);
851 locsym
->lsy_offset
= final_val
;
852 local_symbol_mark_resolved (locsym
);
859 if (symp
->sy_resolved
)
861 if (symp
->sy_value
.X_op
== O_constant
)
862 return (valueT
) symp
->sy_value
.X_add_number
;
868 final_seg
= S_GET_SEGMENT (symp
);
870 if (symp
->sy_resolving
)
873 as_bad (_("Symbol definition loop encountered at %s"),
880 symbolS
*add_symbol
, *op_symbol
;
882 segT seg_left
, seg_right
;
885 symp
->sy_resolving
= 1;
887 /* Help out with CSE. */
888 add_symbol
= symp
->sy_value
.X_add_symbol
;
889 op_symbol
= symp
->sy_value
.X_op_symbol
;
890 final_val
= symp
->sy_value
.X_add_number
;
891 op
= symp
->sy_value
.X_op
;
904 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
905 if (final_seg
== expr_section
)
906 final_seg
= absolute_section
;
912 left
= resolve_symbol_value (add_symbol
, finalize
);
915 if (symp
->sy_mri_common
)
917 /* This is a symbol inside an MRI common section. The
918 relocation routines are going to handle it specially.
919 Don't change the value. */
920 resolved
= symbol_resolved_p (add_symbol
);
924 if (finalize
&& final_val
== 0)
926 if (LOCAL_SYMBOL_CHECK (add_symbol
))
927 add_symbol
= local_symbol_convert ((struct local_symbol
*)
929 copy_symbol_attributes (symp
, add_symbol
);
932 /* If we have equated this symbol to an undefined symbol, we
933 keep X_op set to O_symbol, and we don't change
934 X_add_number. This permits the routine which writes out
935 relocation to detect this case, and convert the
936 relocation to be against the symbol to which this symbol
938 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
942 S_SET_SEGMENT (symp
, S_GET_SEGMENT (add_symbol
));
943 symp
->sy_value
.X_op
= O_symbol
;
944 symp
->sy_value
.X_add_symbol
= add_symbol
;
945 symp
->sy_value
.X_add_number
= final_val
;
948 resolved
= symbol_resolved_p (add_symbol
);
949 goto exit_dont_set_value
;
953 final_val
+= symp
->sy_frag
->fr_address
+ left
;
954 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
955 final_seg
= S_GET_SEGMENT (add_symbol
);
958 resolved
= symbol_resolved_p (add_symbol
);
964 left
= resolve_symbol_value (add_symbol
, finalize
);
968 else if (op
== O_logical_not
)
973 final_val
+= left
+ symp
->sy_frag
->fr_address
;
974 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
975 final_seg
= absolute_section
;
977 resolved
= symbol_resolved_p (add_symbol
);
985 case O_bit_inclusive_or
:
987 case O_bit_exclusive_or
:
999 left
= resolve_symbol_value (add_symbol
, finalize
);
1000 right
= resolve_symbol_value (op_symbol
, finalize
);
1001 seg_left
= S_GET_SEGMENT (add_symbol
);
1002 seg_right
= S_GET_SEGMENT (op_symbol
);
1004 /* Simplify addition or subtraction of a constant by folding the
1005 constant into X_add_number. */
1006 if (op
== O_add
|| op
== O_subtract
)
1008 if (seg_right
== absolute_section
)
1018 else if (seg_left
== absolute_section
&& op
== O_add
)
1022 add_symbol
= op_symbol
;
1029 /* Subtraction is permitted if both operands are in the same
1030 section. Otherwise, both operands must be absolute. We
1031 already handled the case of addition or subtraction of a
1032 constant above. This will probably need to be changed
1033 for an object file format which supports arbitrary
1034 expressions, such as IEEE-695. */
1035 /* Don't emit messages unless we're finalizing the symbol value,
1036 otherwise we may get the same message multiple times. */
1037 if ((seg_left
!= absolute_section
1038 || seg_right
!= absolute_section
)
1039 && (op
!= O_subtract
1040 || seg_left
!= seg_right
1041 || seg_left
== undefined_section
)
1047 if (expr_symbol_where (symp
, &file
, &line
))
1049 if (seg_left
== undefined_section
)
1050 as_bad_where (file
, line
,
1051 _("undefined symbol %s in operation"),
1052 S_GET_NAME (symp
->sy_value
.X_add_symbol
));
1053 if (seg_right
== undefined_section
)
1054 as_bad_where (file
, line
,
1055 _("undefined symbol %s in operation"),
1056 S_GET_NAME (symp
->sy_value
.X_op_symbol
));
1057 if (seg_left
!= undefined_section
1058 && seg_right
!= undefined_section
)
1059 as_bad_where (file
, line
,
1060 _("invalid section for operation"));
1064 if (seg_left
== undefined_section
)
1065 as_bad (_("undefined symbol %s in operation setting %s"),
1066 S_GET_NAME (symp
->sy_value
.X_add_symbol
),
1068 if (seg_right
== undefined_section
)
1069 as_bad (_("undefined symbol %s in operation setting %s"),
1070 S_GET_NAME (symp
->sy_value
.X_op_symbol
),
1072 if (seg_left
!= undefined_section
1073 && seg_right
!= undefined_section
)
1074 as_bad (_("invalid section for operation setting %s"),
1079 /* Check for division by zero. */
1080 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1082 /* If seg_right is not absolute_section, then we've
1083 already issued a warning about using a bad symbol. */
1084 if (seg_right
== absolute_section
&& finalize
)
1089 if (expr_symbol_where (symp
, &file
, &line
))
1090 as_bad_where (file
, line
, _("division by zero"));
1092 as_bad (_("division by zero when setting %s"),
1099 switch (symp
->sy_value
.X_op
)
1101 case O_multiply
: left
*= right
; break;
1102 case O_divide
: left
/= right
; break;
1103 case O_modulus
: left
%= right
; break;
1104 case O_left_shift
: left
<<= right
; break;
1105 case O_right_shift
: left
>>= right
; break;
1106 case O_bit_inclusive_or
: left
|= right
; break;
1107 case O_bit_or_not
: left
|= ~right
; break;
1108 case O_bit_exclusive_or
: left
^= right
; break;
1109 case O_bit_and
: left
&= right
; break;
1110 case O_add
: left
+= right
; break;
1111 case O_subtract
: left
-= right
; break;
1112 case O_eq
: left
= left
== right
? ~ (offsetT
) 0 : 0; break;
1113 case O_ne
: left
= left
!= right
? ~ (offsetT
) 0 : 0; break;
1114 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1115 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1116 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1117 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1118 case O_logical_and
: left
= left
&& right
; break;
1119 case O_logical_or
: left
= left
|| right
; break;
1123 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1124 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1125 final_seg
= absolute_section
;
1126 resolved
= (symbol_resolved_p (add_symbol
)
1127 && symbol_resolved_p (op_symbol
));
1133 /* Give an error (below) if not in expr_section. We don't
1134 want to worry about expr_section symbols, because they
1135 are fictional (they are created as part of expression
1136 resolution), and any problems may not actually mean
1141 symp
->sy_resolving
= 0;
1146 S_SET_VALUE (symp
, final_val
);
1148 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1149 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1150 for a stab symbol, so we use this bad hack. */
1151 if (final_seg
!= S_GET_SEGMENT (symp
))
1153 S_SET_SEGMENT (symp
, final_seg
);
1156 exit_dont_set_value
:
1157 /* Don't worry if we can't resolve an expr_section symbol. */
1161 symp
->sy_resolved
= 1;
1162 else if (S_GET_SEGMENT (symp
) != expr_section
)
1164 as_bad (_("can't resolve value for symbol \"%s\""),
1166 symp
->sy_resolved
= 1;
1173 #ifdef BFD_ASSEMBLER
1175 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1177 /* A static function passed to hash_traverse. */
1180 resolve_local_symbol (key
, value
)
1181 const char *key ATTRIBUTE_UNUSED
;
1185 resolve_symbol_value (value
, 1);
1190 /* Resolve all local symbols. */
1193 resolve_local_symbol_values ()
1195 #ifdef BFD_ASSEMBLER
1196 hash_traverse (local_hash
, resolve_local_symbol
);
1200 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1201 They are *really* local. That is, they go out of scope whenever we see a
1202 label that isn't local. Also, like fb labels, there can be multiple
1203 instances of a dollar label. Therefor, we name encode each instance with
1204 the instance number, keep a list of defined symbols separate from the real
1205 symbol table, and we treat these buggers as a sparse array. */
1207 static long *dollar_labels
;
1208 static long *dollar_label_instances
;
1209 static char *dollar_label_defines
;
1210 static unsigned long dollar_label_count
;
1211 static unsigned long dollar_label_max
;
1214 dollar_label_defined (label
)
1219 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1221 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1223 return dollar_label_defines
[i
- dollar_labels
];
1225 /* If we get here, label isn't defined. */
1230 dollar_label_instance (label
)
1235 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1237 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1239 return (dollar_label_instances
[i
- dollar_labels
]);
1241 /* If we get here, we haven't seen the label before.
1242 Therefore its instance count is zero. */
1247 dollar_label_clear ()
1249 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1252 #define DOLLAR_LABEL_BUMP_BY 10
1255 define_dollar_label (label
)
1260 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1263 ++dollar_label_instances
[i
- dollar_labels
];
1264 dollar_label_defines
[i
- dollar_labels
] = 1;
1268 /* If we get to here, we don't have label listed yet. */
1270 if (dollar_labels
== NULL
)
1272 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1273 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1274 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1275 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1276 dollar_label_count
= 0;
1278 else if (dollar_label_count
== dollar_label_max
)
1280 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1281 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1282 dollar_label_max
* sizeof (long));
1283 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1284 dollar_label_max
* sizeof (long));
1285 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1286 } /* if we needed to grow */
1288 dollar_labels
[dollar_label_count
] = label
;
1289 dollar_label_instances
[dollar_label_count
] = 1;
1290 dollar_label_defines
[dollar_label_count
] = 1;
1291 ++dollar_label_count
;
1294 /* Caller must copy returned name: we re-use the area for the next name.
1296 The mth occurence of label n: is turned into the symbol "Ln^Am"
1297 where n is the label number and m is the instance number. "L" makes
1298 it a label discarded unless debugging and "^A"('\1') ensures no
1299 ordinary symbol SHOULD get the same name as a local label
1300 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1302 fb labels get the same treatment, except that ^B is used in place
1305 char * /* Return local label name. */
1306 dollar_label_name (n
, augend
)
1307 register long n
; /* we just saw "n$:" : n a number. */
1308 register int augend
; /* 0 for current instance, 1 for new instance. */
1311 /* Returned to caller, then copied. Used for created names ("4f"). */
1312 static char symbol_name_build
[24];
1315 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1318 know (augend
== 0 || augend
== 1);
1319 p
= symbol_name_build
;
1320 #ifdef LOCAL_LABEL_PREFIX
1321 *p
++ = LOCAL_LABEL_PREFIX
;
1325 /* Next code just does sprintf( {}, "%d", n); */
1327 q
= symbol_name_temporary
;
1328 for (*q
++ = 0, i
= n
; i
; ++q
)
1333 while ((*p
= *--q
) != '\0')
1336 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1338 /* Instance number. */
1339 q
= symbol_name_temporary
;
1340 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1345 while ((*p
++ = *--q
) != '\0');;
1347 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1348 return symbol_name_build
;
1351 /* Sombody else's idea of local labels. They are made by "n:" where n
1352 is any decimal digit. Refer to them with
1353 "nb" for previous (backward) n:
1354 or "nf" for next (forward) n:.
1356 We do a little better and let n be any number, not just a single digit, but
1357 since the other guy's assembler only does ten, we treat the first ten
1360 Like someone else's assembler, we have one set of local label counters for
1361 entire assembly, not one set per (sub)segment like in most assemblers. This
1362 implies that one can refer to a label in another segment, and indeed some
1363 crufty compilers have done just that.
1365 Since there could be a LOT of these things, treat them as a sparse
1368 #define FB_LABEL_SPECIAL (10)
1370 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1371 static long *fb_labels
;
1372 static long *fb_label_instances
;
1373 static long fb_label_count
;
1374 static long fb_label_max
;
1376 /* This must be more than FB_LABEL_SPECIAL. */
1377 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1382 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1385 /* Add one to the instance number of this fb label. */
1388 fb_label_instance_inc (label
)
1393 if (label
< FB_LABEL_SPECIAL
)
1395 ++fb_low_counter
[label
];
1399 if (fb_labels
!= NULL
)
1401 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1402 i
< fb_labels
+ fb_label_count
; ++i
)
1406 ++fb_label_instances
[i
- fb_labels
];
1408 } /* if we find it */
1409 } /* for each existing label */
1412 /* If we get to here, we don't have label listed yet. */
1414 if (fb_labels
== NULL
)
1416 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1417 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1418 fb_label_max
= FB_LABEL_BUMP_BY
;
1419 fb_label_count
= FB_LABEL_SPECIAL
;
1422 else if (fb_label_count
== fb_label_max
)
1424 fb_label_max
+= FB_LABEL_BUMP_BY
;
1425 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1426 fb_label_max
* sizeof (long));
1427 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1428 fb_label_max
* sizeof (long));
1429 } /* if we needed to grow */
1431 fb_labels
[fb_label_count
] = label
;
1432 fb_label_instances
[fb_label_count
] = 1;
1437 fb_label_instance (label
)
1442 if (label
< FB_LABEL_SPECIAL
)
1444 return (fb_low_counter
[label
]);
1447 if (fb_labels
!= NULL
)
1449 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1450 i
< fb_labels
+ fb_label_count
; ++i
)
1454 return (fb_label_instances
[i
- fb_labels
]);
1455 } /* if we find it */
1456 } /* for each existing label */
1459 /* We didn't find the label, so this must be a reference to the
1464 /* Caller must copy returned name: we re-use the area for the next name.
1466 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1467 where n is the label number and m is the instance number. "L" makes
1468 it a label discarded unless debugging and "^B"('\2') ensures no
1469 ordinary symbol SHOULD get the same name as a local label
1470 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1472 dollar labels get the same treatment, except that ^A is used in
1475 char * /* Return local label name. */
1476 fb_label_name (n
, augend
)
1477 long n
; /* We just saw "n:", "nf" or "nb" : n a number. */
1478 long augend
; /* 0 for nb, 1 for n:, nf. */
1481 /* Returned to caller, then copied. Used for created names ("4f"). */
1482 static char symbol_name_build
[24];
1485 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1488 know (augend
== 0 || augend
== 1);
1489 p
= symbol_name_build
;
1490 #ifdef LOCAL_LABEL_PREFIX
1491 *p
++ = LOCAL_LABEL_PREFIX
;
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')
1506 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
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
);
1521 /* Decode name that may have been generated by foo_label_name() above.
1522 If the name wasn't generated by foo_label_name(), then return it
1523 unaltered. This is used for error messages. */
1526 decode_local_label_name (s
)
1530 char *symbol_decode
;
1532 int instance_number
;
1534 const char *message_format
;
1537 #ifdef LOCAL_LABEL_PREFIX
1538 if (s
[index
] == LOCAL_LABEL_PREFIX
)
1542 if (s
[index
] != 'L')
1545 for (label_number
= 0, p
= s
+ index
+ 1; isdigit ((unsigned char) *p
); ++p
)
1546 label_number
= (10 * label_number
) + *p
- '0';
1548 if (*p
== DOLLAR_LABEL_CHAR
)
1550 else if (*p
== LOCAL_LABEL_CHAR
)
1555 for (instance_number
= 0, p
++; isdigit ((unsigned char) *p
); ++p
)
1556 instance_number
= (10 * instance_number
) + *p
- '0';
1558 message_format
= _("\"%d\" (instance number %d of a %s label)");
1559 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1560 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1562 return symbol_decode
;
1565 /* Get the value of a symbol. */
1571 #ifdef BFD_ASSEMBLER
1572 if (LOCAL_SYMBOL_CHECK (s
))
1573 return ((struct local_symbol
*) s
)->lsy_offset
;
1576 if (!s
->sy_resolved
&& s
->sy_value
.X_op
!= O_constant
)
1577 resolve_symbol_value (s
, 1);
1578 if (s
->sy_value
.X_op
!= O_constant
)
1580 static symbolS
*recur
;
1582 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1583 may call S_GET_VALUE. We use a static symbol to avoid the
1584 immediate recursion. */
1586 return (valueT
) s
->sy_value
.X_add_number
;
1588 if (! s
->sy_resolved
1589 || s
->sy_value
.X_op
!= O_symbol
1590 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1591 as_bad (_("Attempt to get value of unresolved symbol %s"),
1595 return (valueT
) s
->sy_value
.X_add_number
;
1598 /* Set the value of a symbol. */
1601 S_SET_VALUE (s
, val
)
1605 #ifdef BFD_ASSEMBLER
1606 if (LOCAL_SYMBOL_CHECK (s
))
1608 ((struct local_symbol
*) s
)->lsy_offset
= val
;
1613 s
->sy_value
.X_op
= O_constant
;
1614 s
->sy_value
.X_add_number
= (offsetT
) val
;
1615 s
->sy_value
.X_unsigned
= 0;
1619 copy_symbol_attributes (dest
, src
)
1620 symbolS
*dest
, *src
;
1622 if (LOCAL_SYMBOL_CHECK (dest
))
1623 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
1624 if (LOCAL_SYMBOL_CHECK (src
))
1625 src
= local_symbol_convert ((struct local_symbol
*) src
);
1627 #ifdef BFD_ASSEMBLER
1628 /* In an expression, transfer the settings of these flags.
1629 The user can override later, of course. */
1630 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1631 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1634 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1635 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1639 #ifdef BFD_ASSEMBLER
1647 if (LOCAL_SYMBOL_CHECK (s
))
1650 flags
= s
->bsym
->flags
;
1652 return (flags
& BSF_FUNCTION
) != 0;
1661 if (LOCAL_SYMBOL_CHECK (s
))
1664 flags
= s
->bsym
->flags
;
1667 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1670 return (flags
& BSF_GLOBAL
) != 0;
1677 if (LOCAL_SYMBOL_CHECK (s
))
1679 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1686 if (LOCAL_SYMBOL_CHECK (s
))
1688 return bfd_is_com_section (s
->bsym
->section
);
1695 if (LOCAL_SYMBOL_CHECK (s
))
1696 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1697 return s
->bsym
->section
!= undefined_section
;
1704 if (LOCAL_SYMBOL_CHECK (s
))
1706 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1718 if (LOCAL_SYMBOL_CHECK (s
))
1721 flags
= s
->bsym
->flags
;
1724 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1727 if (bfd_get_section (s
->bsym
) == reg_section
)
1730 if (flag_strip_local_absolute
1731 && (flags
& BSF_GLOBAL
) == 0
1732 && bfd_get_section (s
->bsym
) == absolute_section
)
1735 name
= S_GET_NAME (s
);
1736 return (name
!= NULL
1738 && (strchr (name
, DOLLAR_LABEL_CHAR
)
1739 || strchr (name
, LOCAL_LABEL_CHAR
)
1740 || (! flag_keep_locals
1741 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1744 && name
[1] == '?')))));
1751 return S_IS_EXTERNAL (s
);
1758 return S_GET_NAME (s
) == 0;
1765 if (LOCAL_SYMBOL_CHECK (s
))
1766 return ((struct local_symbol
*) s
)->lsy_name
;
1767 return s
->bsym
->name
;
1774 if (LOCAL_SYMBOL_CHECK (s
))
1775 return ((struct local_symbol
*) s
)->lsy_section
;
1776 return s
->bsym
->section
;
1780 S_SET_SEGMENT (s
, seg
)
1784 /* Don't reassign section symbols. The direct reason is to prevent seg
1785 faults assigning back to const global symbols such as *ABS*, but it
1786 shouldn't happen anyway. */
1788 if (LOCAL_SYMBOL_CHECK (s
))
1790 if (seg
== reg_section
)
1791 s
= local_symbol_convert ((struct local_symbol
*) s
);
1794 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1799 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1801 if (s
->bsym
->section
!= seg
)
1805 s
->bsym
->section
= seg
;
1812 if (LOCAL_SYMBOL_CHECK (s
))
1813 s
= local_symbol_convert ((struct local_symbol
*) s
);
1814 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1816 /* Let .weak override .global. */
1819 s
->bsym
->flags
|= BSF_GLOBAL
;
1820 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
1824 S_CLEAR_EXTERNAL (s
)
1827 if (LOCAL_SYMBOL_CHECK (s
))
1829 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1831 /* Let .weak override. */
1834 s
->bsym
->flags
|= BSF_LOCAL
;
1835 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
1842 if (LOCAL_SYMBOL_CHECK (s
))
1843 s
= local_symbol_convert ((struct local_symbol
*) s
);
1844 s
->bsym
->flags
|= BSF_WEAK
;
1845 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
1849 S_SET_NAME (s
, name
)
1853 if (LOCAL_SYMBOL_CHECK (s
))
1855 ((struct local_symbol
*) s
)->lsy_name
= name
;
1858 s
->bsym
->name
= name
;
1860 #endif /* BFD_ASSEMBLER */
1862 #ifdef SYMBOLS_NEED_BACKPOINTERS
1864 /* Return the previous symbol in a chain. */
1870 if (LOCAL_SYMBOL_CHECK (s
))
1872 return s
->sy_previous
;
1875 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1877 /* Return the next symbol in a chain. */
1883 if (LOCAL_SYMBOL_CHECK (s
))
1888 /* Return a pointer to the value of a symbol as an expression. */
1891 symbol_get_value_expression (s
)
1894 if (LOCAL_SYMBOL_CHECK (s
))
1895 s
= local_symbol_convert ((struct local_symbol
*) s
);
1896 return &s
->sy_value
;
1899 /* Set the value of a symbol to an expression. */
1902 symbol_set_value_expression (s
, exp
)
1904 const expressionS
*exp
;
1906 if (LOCAL_SYMBOL_CHECK (s
))
1907 s
= local_symbol_convert ((struct local_symbol
*) s
);
1911 /* Set the frag of a symbol. */
1914 symbol_set_frag (s
, f
)
1918 #ifdef BFD_ASSEMBLER
1919 if (LOCAL_SYMBOL_CHECK (s
))
1921 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
1928 /* Return the frag of a symbol. */
1934 #ifdef BFD_ASSEMBLER
1935 if (LOCAL_SYMBOL_CHECK (s
))
1936 return local_symbol_get_frag ((struct local_symbol
*) s
);
1941 /* Mark a symbol as having been used. */
1944 symbol_mark_used (s
)
1947 if (LOCAL_SYMBOL_CHECK (s
))
1952 /* Clear the mark of whether a symbol has been used. */
1955 symbol_clear_used (s
)
1958 if (LOCAL_SYMBOL_CHECK (s
))
1959 s
= local_symbol_convert ((struct local_symbol
*) s
);
1963 /* Return whether a symbol has been used. */
1969 if (LOCAL_SYMBOL_CHECK (s
))
1974 /* Mark a symbol as having been used in a reloc. */
1977 symbol_mark_used_in_reloc (s
)
1980 if (LOCAL_SYMBOL_CHECK (s
))
1981 s
= local_symbol_convert ((struct local_symbol
*) s
);
1982 s
->sy_used_in_reloc
= 1;
1985 /* Clear the mark of whether a symbol has been used in a reloc. */
1988 symbol_clear_used_in_reloc (s
)
1991 if (LOCAL_SYMBOL_CHECK (s
))
1993 s
->sy_used_in_reloc
= 0;
1996 /* Return whether a symbol has been used in a reloc. */
1999 symbol_used_in_reloc_p (s
)
2002 if (LOCAL_SYMBOL_CHECK (s
))
2004 return s
->sy_used_in_reloc
;
2007 /* Mark a symbol as an MRI common symbol. */
2010 symbol_mark_mri_common (s
)
2013 if (LOCAL_SYMBOL_CHECK (s
))
2014 s
= local_symbol_convert ((struct local_symbol
*) s
);
2015 s
->sy_mri_common
= 1;
2018 /* Clear the mark of whether a symbol is an MRI common symbol. */
2021 symbol_clear_mri_common (s
)
2024 if (LOCAL_SYMBOL_CHECK (s
))
2026 s
->sy_mri_common
= 0;
2029 /* Return whether a symbol is an MRI common symbol. */
2032 symbol_mri_common_p (s
)
2035 if (LOCAL_SYMBOL_CHECK (s
))
2037 return s
->sy_mri_common
;
2040 /* Mark a symbol as having been written. */
2043 symbol_mark_written (s
)
2046 if (LOCAL_SYMBOL_CHECK (s
))
2051 /* Clear the mark of whether a symbol has been written. */
2054 symbol_clear_written (s
)
2057 if (LOCAL_SYMBOL_CHECK (s
))
2062 /* Return whether a symbol has been written. */
2065 symbol_written_p (s
)
2068 if (LOCAL_SYMBOL_CHECK (s
))
2073 /* Mark a symbol has having been resolved. */
2076 symbol_mark_resolved (s
)
2079 #ifdef BFD_ASSEMBLER
2080 if (LOCAL_SYMBOL_CHECK (s
))
2082 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2089 /* Return whether a symbol has been resolved. */
2092 symbol_resolved_p (s
)
2095 #ifdef BFD_ASSEMBLER
2096 if (LOCAL_SYMBOL_CHECK (s
))
2097 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2099 return s
->sy_resolved
;
2102 /* Return whether a symbol is a section symbol. */
2105 symbol_section_p (s
)
2106 symbolS
*s ATTRIBUTE_UNUSED
;
2108 if (LOCAL_SYMBOL_CHECK (s
))
2110 #ifdef BFD_ASSEMBLER
2111 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2118 /* Return whether a symbol is equated to another symbol. */
2121 symbol_equated_p (s
)
2124 if (LOCAL_SYMBOL_CHECK (s
))
2126 return s
->sy_value
.X_op
== O_symbol
;
2129 /* Return whether a symbol has a constant value. */
2132 symbol_constant_p (s
)
2135 if (LOCAL_SYMBOL_CHECK (s
))
2137 return s
->sy_value
.X_op
== O_constant
;
2140 #ifdef BFD_ASSEMBLER
2142 /* Return the BFD symbol for a symbol. */
2145 symbol_get_bfdsym (s
)
2148 if (LOCAL_SYMBOL_CHECK (s
))
2149 s
= local_symbol_convert ((struct local_symbol
*) s
);
2153 /* Set the BFD symbol for a symbol. */
2156 symbol_set_bfdsym (s
, bsym
)
2160 if (LOCAL_SYMBOL_CHECK (s
))
2161 s
= local_symbol_convert ((struct local_symbol
*) s
);
2165 #endif /* BFD_ASSEMBLER */
2167 #ifdef OBJ_SYMFIELD_TYPE
2169 /* Get a pointer to the object format information for a symbol. */
2175 if (LOCAL_SYMBOL_CHECK (s
))
2176 s
= local_symbol_convert ((struct local_symbol
*) s
);
2180 /* Set the object format information for a symbol. */
2183 symbol_set_obj (s
, o
)
2185 OBJ_SYMFIELD_TYPE
*o
;
2187 if (LOCAL_SYMBOL_CHECK (s
))
2188 s
= local_symbol_convert ((struct local_symbol
*) s
);
2192 #endif /* OBJ_SYMFIELD_TYPE */
2194 #ifdef TC_SYMFIELD_TYPE
2196 /* Get a pointer to the processor information for a symbol. */
2202 if (LOCAL_SYMBOL_CHECK (s
))
2203 s
= local_symbol_convert ((struct local_symbol
*) s
);
2207 /* Set the processor information for a symbol. */
2210 symbol_set_tc (s
, o
)
2212 TC_SYMFIELD_TYPE
*o
;
2214 if (LOCAL_SYMBOL_CHECK (s
))
2215 s
= local_symbol_convert ((struct local_symbol
*) s
);
2219 #endif /* TC_SYMFIELD_TYPE */
2224 symbol_lastP
= NULL
;
2225 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2226 sy_hash
= hash_new ();
2227 #ifdef BFD_ASSEMBLER
2228 local_hash
= hash_new ();
2231 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2232 #ifdef BFD_ASSEMBLER
2233 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2234 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2237 /* Can't initialise a union. Sigh. */
2238 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2240 abs_symbol
.sy_value
.X_op
= O_constant
;
2241 abs_symbol
.sy_frag
= &zero_address_frag
;
2243 if (LOCAL_LABELS_FB
)
2249 /* Maximum indent level.
2250 Available for modification inside a gdb session. */
2251 int max_indent_level
= 8;
2258 printf ("%*s", indent_level
* 4, "");
2264 print_symbol_value_1 (file
, sym
)
2268 const char *name
= S_GET_NAME (sym
);
2269 if (!name
|| !name
[0])
2271 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2273 if (LOCAL_SYMBOL_CHECK (sym
))
2275 #ifdef BFD_ASSEMBLER
2276 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2277 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2278 && local_symbol_get_frag (locsym
) != NULL
)
2279 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2280 if (local_symbol_resolved_p (locsym
))
2281 fprintf (file
, " resolved");
2282 fprintf (file
, " local");
2287 if (sym
->sy_frag
!= &zero_address_frag
)
2288 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2290 fprintf (file
, " written");
2291 if (sym
->sy_resolved
)
2292 fprintf (file
, " resolved");
2293 else if (sym
->sy_resolving
)
2294 fprintf (file
, " resolving");
2295 if (sym
->sy_used_in_reloc
)
2296 fprintf (file
, " used-in-reloc");
2298 fprintf (file
, " used");
2299 if (S_IS_LOCAL (sym
))
2300 fprintf (file
, " local");
2301 if (S_IS_EXTERN (sym
))
2302 fprintf (file
, " extern");
2303 if (S_IS_DEBUG (sym
))
2304 fprintf (file
, " debug");
2305 if (S_IS_DEFINED (sym
))
2306 fprintf (file
, " defined");
2308 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2309 if (symbol_resolved_p (sym
))
2311 segT s
= S_GET_SEGMENT (sym
);
2313 if (s
!= undefined_section
2314 && s
!= expr_section
)
2315 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2317 else if (indent_level
< max_indent_level
2318 && S_GET_SEGMENT (sym
) != undefined_section
)
2321 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2322 #ifdef BFD_ASSEMBLER
2323 if (LOCAL_SYMBOL_CHECK (sym
))
2324 fprintf (file
, "constant %lx",
2325 (long) ((struct local_symbol
*) sym
)->lsy_offset
);
2328 print_expr_1 (file
, &sym
->sy_value
);
2329 fprintf (file
, ">");
2336 print_symbol_value (sym
)
2340 print_symbol_value_1 (stderr
, sym
);
2341 fprintf (stderr
, "\n");
2345 print_binary (file
, name
, exp
)
2351 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2352 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2353 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2354 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2355 fprintf (file
, ">");
2360 print_expr_1 (file
, exp
)
2364 fprintf (file
, "expr %lx ", (long) exp
);
2368 fprintf (file
, "illegal");
2371 fprintf (file
, "absent");
2374 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2378 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2379 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2380 fprintf (file
, ">");
2382 if (exp
->X_add_number
)
2383 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2384 (long) exp
->X_add_number
);
2388 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2391 fprintf (file
, "big");
2394 fprintf (file
, "uminus -<");
2396 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2397 fprintf (file
, ">");
2398 goto maybe_print_addnum
;
2400 fprintf (file
, "bit_not");
2403 print_binary (file
, "multiply", exp
);
2406 print_binary (file
, "divide", exp
);
2409 print_binary (file
, "modulus", exp
);
2412 print_binary (file
, "lshift", exp
);
2415 print_binary (file
, "rshift", exp
);
2417 case O_bit_inclusive_or
:
2418 print_binary (file
, "bit_ior", exp
);
2420 case O_bit_exclusive_or
:
2421 print_binary (file
, "bit_xor", exp
);
2424 print_binary (file
, "bit_and", exp
);
2427 print_binary (file
, "eq", exp
);
2430 print_binary (file
, "ne", exp
);
2433 print_binary (file
, "lt", exp
);
2436 print_binary (file
, "le", exp
);
2439 print_binary (file
, "ge", exp
);
2442 print_binary (file
, "gt", exp
);
2445 print_binary (file
, "logical_and", exp
);
2448 print_binary (file
, "logical_or", exp
);
2452 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2453 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2454 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2455 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2456 fprintf (file
, ">");
2457 goto maybe_print_addnum
;
2460 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
2461 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2462 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2463 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2464 fprintf (file
, ">");
2465 goto maybe_print_addnum
;
2467 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2477 print_expr_1 (stderr
, exp
);
2478 fprintf (stderr
, "\n");
2482 symbol_print_statistics (file
)
2485 hash_print_statistics (file
, "symbol table", sy_hash
);
2486 #ifdef BFD_ASSEMBLER
2487 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2488 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2489 local_symbol_count
, local_symbol_conversion_count
);