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 #ifdef TC_LOCAL_SYMFIELD_CONVERT
259 TC_LOCAL_SYMFIELD_CONVERT (locsym
, ret
);
262 symbol_table_insert (ret
);
264 local_symbol_mark_converted (locsym
);
265 local_symbol_set_real_symbol (locsym
, ret
);
267 hash_jam (local_hash
, locsym
->lsy_name
, NULL
);
272 #else /* ! BFD_ASSEMBLER */
274 #define LOCAL_SYMBOL_CHECK(s) 0
275 #define local_symbol_convert(s) ((symbolS *) s)
277 #endif /* ! BFD_ASSEMBLER */
279 /* We have just seen "<name>:".
280 Creates a struct symbol unless it already exists.
282 Gripes if we are redefining a symbol incompatibly (and ignores it). */
285 colon (sym_name
) /* Just seen "x:" - rattle symbols & frags. */
286 const char *sym_name
; /* Symbol name, as a cannonical string. */
287 /* We copy this string: OK to alter later. */
289 register symbolS
*symbolP
; /* Symbol we are working with. */
291 /* Sun local labels go out of scope whenever a non-local symbol is
293 if (LOCAL_LABELS_DOLLAR
)
298 local
= bfd_is_local_label_name (stdoutput
, sym_name
);
300 local
= LOCAL_LABEL (sym_name
);
304 dollar_label_clear ();
307 #ifndef WORKING_DOT_WORD
308 if (new_broken_words
)
310 struct broken_word
*a
;
315 extern const int md_short_jump_size
;
316 extern const int md_long_jump_size
;
317 possible_bytes
= (md_short_jump_size
318 + new_broken_words
* md_long_jump_size
);
321 frag_opcode
= frag_var (rs_broken_word
,
325 (symbolS
*) broken_words
,
329 /* We want to store the pointer to where to insert the jump
330 table in the fr_opcode of the rs_broken_word frag. This
331 requires a little hackery. */
333 && (frag_tmp
->fr_type
!= rs_broken_word
334 || frag_tmp
->fr_opcode
))
335 frag_tmp
= frag_tmp
->fr_next
;
337 frag_tmp
->fr_opcode
= frag_opcode
;
338 new_broken_words
= 0;
340 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
341 a
->dispfrag
= frag_tmp
;
343 #endif /* WORKING_DOT_WORD */
345 if ((symbolP
= symbol_find (sym_name
)) != 0)
347 #ifdef RESOLVE_SYMBOL_REDEFINITION
348 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
351 /* Now check for undefined symbols. */
352 if (LOCAL_SYMBOL_CHECK (symbolP
))
355 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
357 if (locsym
->lsy_section
!= undefined_section
358 && (local_symbol_get_frag (locsym
) != frag_now
359 || locsym
->lsy_section
!= now_seg
360 || locsym
->lsy_offset
!= frag_now_fix ()))
362 as_bad (_("Symbol %s already defined."), sym_name
);
366 locsym
->lsy_section
= now_seg
;
367 local_symbol_set_frag (locsym
, frag_now
);
368 locsym
->lsy_offset
= frag_now_fix ();
371 else if (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
373 if (S_GET_VALUE (symbolP
) == 0)
375 symbolP
->sy_frag
= frag_now
;
377 S_SET_OTHER (symbolP
, const_flag
);
379 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
380 S_SET_SEGMENT (symbolP
, now_seg
);
383 #endif /* if we have one, it better be zero. */
388 /* There are still several cases to check:
390 A .comm/.lcomm symbol being redefined as initialized
393 A .comm/.lcomm symbol being redefined with a larger
396 This only used to be allowed on VMS gas, but Sun cc
397 on the sparc also depends on it. */
399 if (((!S_IS_DEBUG (symbolP
)
400 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
401 && S_IS_EXTERNAL (symbolP
))
402 || S_GET_SEGMENT (symbolP
) == bss_section
)
403 && (now_seg
== data_section
404 || now_seg
== S_GET_SEGMENT (symbolP
)))
406 /* Select which of the 2 cases this is. */
407 if (now_seg
!= data_section
)
409 /* New .comm for prev .comm symbol.
411 If the new size is larger we just change its
412 value. If the new size is smaller, we ignore
414 if (S_GET_VALUE (symbolP
)
415 < ((unsigned) frag_now_fix ()))
417 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
422 /* It is a .comm/.lcomm being converted to initialized
424 symbolP
->sy_frag
= frag_now
;
426 S_SET_OTHER (symbolP
, const_flag
);
428 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
429 S_SET_SEGMENT (symbolP
, now_seg
); /* Keep N_EXT bit. */
434 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
435 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
436 static const char *od_buf
= "";
441 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
443 sprintf(od_buf
, "%d.%d.",
444 S_GET_OTHER (symbolP
),
445 S_GET_DESC (symbolP
));
447 as_bad (_("Symbol \"%s\" is already defined as \"%s\"/%s%ld."),
449 segment_name (S_GET_SEGMENT (symbolP
)),
451 (long) S_GET_VALUE (symbolP
));
453 } /* if the undefined symbol has no value */
457 /* Don't blow up if the definition is the same. */
458 if (!(frag_now
== symbolP
->sy_frag
459 && S_GET_VALUE (symbolP
) == frag_now_fix ()
460 && S_GET_SEGMENT (symbolP
) == now_seg
))
461 as_bad (_("Symbol %s already defined."), sym_name
);
466 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
468 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
469 (valueT
) frag_now_fix (),
472 #endif /* BFD_ASSEMBLER */
475 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
478 S_SET_OTHER (symbolP
, const_flag
);
481 symbol_table_insert (symbolP
);
484 if (mri_common_symbol
!= NULL
)
486 /* This symbol is actually being defined within an MRI common
487 section. This requires special handling. */
488 if (LOCAL_SYMBOL_CHECK (symbolP
))
489 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
490 symbolP
->sy_value
.X_op
= O_symbol
;
491 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
492 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
493 symbolP
->sy_frag
= &zero_address_frag
;
494 S_SET_SEGMENT (symbolP
, expr_section
);
495 symbolP
->sy_mri_common
= 1;
499 tc_frob_label (symbolP
);
501 #ifdef obj_frob_label
502 obj_frob_label (symbolP
);
508 /* Die if we can't insert the symbol. */
511 symbol_table_insert (symbolP
)
514 register const char *error_string
;
517 know (S_GET_NAME (symbolP
));
519 if (LOCAL_SYMBOL_CHECK (symbolP
))
521 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
523 if (error_string
!= NULL
)
524 as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
525 S_GET_NAME (symbolP
), error_string
);
529 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
531 as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
532 S_GET_NAME (symbolP
), error_string
);
536 /* If a symbol name does not exist, create it as undefined, and insert
537 it into the symbol table. Return a pointer to it. */
540 symbol_find_or_make (name
)
543 register symbolS
*symbolP
;
545 symbolP
= symbol_find (name
);
550 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
552 symbolP
= md_undefined_symbol ((char *) name
);
556 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
563 symbolP
= symbol_make (name
);
565 symbol_table_insert (symbolP
);
566 } /* if symbol wasn't found */
577 /* Let the machine description default it, e.g. for register names. */
578 symbolP
= md_undefined_symbol ((char *) name
);
581 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
586 /* Implement symbol table lookup.
587 In: A symbol's name as a string: '\0' can't be part of a symbol name.
588 Out: NULL if the name was not in the symbol table, else the address
589 of a struct symbol associated with that name. */
595 #ifdef STRIP_UNDERSCORE
596 return (symbol_find_base (name
, 1));
597 #else /* STRIP_UNDERSCORE */
598 return (symbol_find_base (name
, 0));
599 #endif /* STRIP_UNDERSCORE */
603 symbol_find_base (name
, strip_underscore
)
605 int strip_underscore
;
607 if (strip_underscore
&& *name
== '_')
610 #ifdef tc_canonicalize_symbol_name
613 size_t len
= strlen (name
) + 1;
615 copy
= (char *) alloca (len
);
616 memcpy (copy
, name
, len
);
617 name
= tc_canonicalize_symbol_name (copy
);
621 if (! symbols_case_sensitive
)
628 name
= copy
= (char *) alloca (strlen (name
) + 1);
630 while ((c
= *orig
++) != '\0')
641 struct local_symbol
*locsym
;
643 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
645 return (symbolS
*) locsym
;
649 return ((symbolS
*) hash_find (sy_hash
, name
));
652 /* Once upon a time, symbols were kept in a singly linked list. At
653 least coff needs to be able to rearrange them from time to time, for
654 which a doubly linked list is much more convenient. Loic did these
655 as macros which seemed dangerous to me so they're now functions.
658 /* Link symbol ADDME after symbol TARGET in the chain. */
661 symbol_append (addme
, target
, rootPP
, lastPP
)
667 if (LOCAL_SYMBOL_CHECK (addme
))
669 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
674 know (*rootPP
== NULL
);
675 know (*lastPP
== NULL
);
676 addme
->sy_next
= NULL
;
677 #ifdef SYMBOLS_NEED_BACKPOINTERS
678 addme
->sy_previous
= NULL
;
683 } /* if the list is empty */
685 if (target
->sy_next
!= NULL
)
687 #ifdef SYMBOLS_NEED_BACKPOINTERS
688 target
->sy_next
->sy_previous
= addme
;
689 #endif /* SYMBOLS_NEED_BACKPOINTERS */
693 know (*lastPP
== target
);
695 } /* if we have a next */
697 addme
->sy_next
= target
->sy_next
;
698 target
->sy_next
= addme
;
700 #ifdef SYMBOLS_NEED_BACKPOINTERS
701 addme
->sy_previous
= target
;
702 #endif /* SYMBOLS_NEED_BACKPOINTERS */
704 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
707 /* Set the chain pointers of SYMBOL to null. */
710 symbol_clear_list_pointers (symbolP
)
713 if (LOCAL_SYMBOL_CHECK (symbolP
))
715 symbolP
->sy_next
= NULL
;
716 #ifdef SYMBOLS_NEED_BACKPOINTERS
717 symbolP
->sy_previous
= NULL
;
721 #ifdef SYMBOLS_NEED_BACKPOINTERS
722 /* Remove SYMBOLP from the list. */
725 symbol_remove (symbolP
, rootPP
, lastPP
)
730 if (LOCAL_SYMBOL_CHECK (symbolP
))
733 if (symbolP
== *rootPP
)
735 *rootPP
= symbolP
->sy_next
;
736 } /* if it was the root */
738 if (symbolP
== *lastPP
)
740 *lastPP
= symbolP
->sy_previous
;
741 } /* if it was the tail */
743 if (symbolP
->sy_next
!= NULL
)
745 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
748 if (symbolP
->sy_previous
!= NULL
)
750 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
753 debug_verify_symchain (*rootPP
, *lastPP
);
756 /* Link symbol ADDME before symbol TARGET in the chain. */
759 symbol_insert (addme
, target
, rootPP
, lastPP
)
763 symbolS
**lastPP ATTRIBUTE_UNUSED
;
765 if (LOCAL_SYMBOL_CHECK (addme
))
767 if (LOCAL_SYMBOL_CHECK (target
))
770 if (target
->sy_previous
!= NULL
)
772 target
->sy_previous
->sy_next
= addme
;
776 know (*rootPP
== target
);
780 addme
->sy_previous
= target
->sy_previous
;
781 target
->sy_previous
= addme
;
782 addme
->sy_next
= target
;
784 debug_verify_symchain (*rootPP
, *lastPP
);
787 #endif /* SYMBOLS_NEED_BACKPOINTERS */
790 verify_symbol_chain (rootP
, lastP
)
794 symbolS
*symbolP
= rootP
;
799 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
802 assert (symbolP
->bsym
!= NULL
);
804 #ifdef SYMBOLS_NEED_BACKPOINTERS
805 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
807 /* Walk the list anyways, to make sure pointers are still good. */
809 #endif /* SYMBOLS_NEED_BACKPOINTERS */
812 assert (lastP
== symbolP
);
816 verify_symbol_chain_2 (sym
)
819 symbolS
*p
= sym
, *n
= sym
;
820 #ifdef SYMBOLS_NEED_BACKPOINTERS
821 while (symbol_previous (p
))
822 p
= symbol_previous (p
);
824 while (symbol_next (n
))
826 verify_symbol_chain (p
, n
);
829 /* Resolve the value of a symbol. This is called during the final
830 pass over the symbol table to resolve any symbols with complex
834 resolve_symbol_value (symp
)
842 if (LOCAL_SYMBOL_CHECK (symp
))
844 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
846 if (local_symbol_resolved_p (locsym
))
847 return locsym
->lsy_offset
/ bfd_octets_per_byte (stdoutput
);
849 final_val
= (local_symbol_get_frag (locsym
)->fr_address
850 + locsym
->lsy_offset
) / bfd_octets_per_byte (stdoutput
);
854 locsym
->lsy_offset
= final_val
;
855 local_symbol_mark_resolved (locsym
);
862 if (symp
->sy_resolved
)
864 if (symp
->sy_value
.X_op
== O_constant
)
865 return (valueT
) symp
->sy_value
.X_add_number
;
871 final_seg
= S_GET_SEGMENT (symp
);
873 if (symp
->sy_resolving
)
876 as_bad (_("Symbol definition loop encountered at %s"),
883 symbolS
*add_symbol
, *op_symbol
;
885 segT seg_left
, seg_right
;
888 symp
->sy_resolving
= 1;
890 /* Help out with CSE. */
891 add_symbol
= symp
->sy_value
.X_add_symbol
;
892 op_symbol
= symp
->sy_value
.X_op_symbol
;
893 final_val
= symp
->sy_value
.X_add_number
;
894 op
= symp
->sy_value
.X_op
;
907 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
908 if (final_seg
== expr_section
)
909 final_seg
= absolute_section
;
915 left
= resolve_symbol_value (add_symbol
);
918 if (symp
->sy_mri_common
)
920 /* This is a symbol inside an MRI common section. The
921 relocation routines are going to handle it specially.
922 Don't change the value. */
923 resolved
= symbol_resolved_p (add_symbol
);
927 if (finalize_syms
&& final_val
== 0)
929 if (LOCAL_SYMBOL_CHECK (add_symbol
))
930 add_symbol
= local_symbol_convert ((struct local_symbol
*)
932 copy_symbol_attributes (symp
, add_symbol
);
935 /* If we have equated this symbol to an undefined symbol, we
936 keep X_op set to O_symbol, and we don't change
937 X_add_number. This permits the routine which writes out
938 relocation to detect this case, and convert the
939 relocation to be against the symbol to which this symbol
941 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
945 S_SET_SEGMENT (symp
, S_GET_SEGMENT (add_symbol
));
946 symp
->sy_value
.X_op
= O_symbol
;
947 symp
->sy_value
.X_add_symbol
= add_symbol
;
948 symp
->sy_value
.X_add_number
= final_val
;
951 resolved
= symbol_resolved_p (add_symbol
);
952 goto exit_dont_set_value
;
956 final_val
+= symp
->sy_frag
->fr_address
+ left
;
957 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
958 final_seg
= S_GET_SEGMENT (add_symbol
);
961 resolved
= symbol_resolved_p (add_symbol
);
967 left
= resolve_symbol_value (add_symbol
);
971 else if (op
== O_logical_not
)
976 final_val
+= left
+ symp
->sy_frag
->fr_address
;
977 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
978 final_seg
= absolute_section
;
980 resolved
= symbol_resolved_p (add_symbol
);
988 case O_bit_inclusive_or
:
990 case O_bit_exclusive_or
:
1002 left
= resolve_symbol_value (add_symbol
);
1003 right
= resolve_symbol_value (op_symbol
);
1004 seg_left
= S_GET_SEGMENT (add_symbol
);
1005 seg_right
= S_GET_SEGMENT (op_symbol
);
1007 /* Simplify addition or subtraction of a constant by folding the
1008 constant into X_add_number. */
1009 if (op
== O_add
|| op
== O_subtract
)
1011 if (seg_right
== absolute_section
)
1021 else if (seg_left
== absolute_section
&& op
== O_add
)
1025 add_symbol
= op_symbol
;
1032 /* Subtraction is permitted if both operands are in the same
1033 section. Otherwise, both operands must be absolute. We
1034 already handled the case of addition or subtraction of a
1035 constant above. This will probably need to be changed
1036 for an object file format which supports arbitrary
1037 expressions, such as IEEE-695. */
1038 /* Don't emit messages unless we're finalizing the symbol value,
1039 otherwise we may get the same message multiple times. */
1040 if ((seg_left
!= absolute_section
1041 || seg_right
!= absolute_section
)
1042 && (op
!= O_subtract
1043 || seg_left
!= seg_right
1044 || seg_left
== undefined_section
)
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
,
1063 _("invalid section for operation"));
1067 if (seg_left
== undefined_section
)
1068 as_bad (_("undefined symbol %s in operation setting %s"),
1069 S_GET_NAME (symp
->sy_value
.X_add_symbol
),
1071 if (seg_right
== undefined_section
)
1072 as_bad (_("undefined symbol %s in operation setting %s"),
1073 S_GET_NAME (symp
->sy_value
.X_op_symbol
),
1075 if (seg_left
!= undefined_section
1076 && seg_right
!= undefined_section
)
1077 as_bad (_("invalid section for operation setting %s"),
1082 /* Check for division by zero. */
1083 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1085 /* If seg_right is not absolute_section, then we've
1086 already issued a warning about using a bad symbol. */
1087 if (seg_right
== absolute_section
&& finalize_syms
)
1092 if (expr_symbol_where (symp
, &file
, &line
))
1093 as_bad_where (file
, line
, _("division by zero"));
1095 as_bad (_("division by zero when setting %s"),
1102 switch (symp
->sy_value
.X_op
)
1104 case O_multiply
: left
*= right
; break;
1105 case O_divide
: left
/= right
; break;
1106 case O_modulus
: left
%= right
; break;
1107 case O_left_shift
: left
<<= right
; break;
1108 case O_right_shift
: left
>>= right
; break;
1109 case O_bit_inclusive_or
: left
|= right
; break;
1110 case O_bit_or_not
: left
|= ~right
; break;
1111 case O_bit_exclusive_or
: left
^= right
; break;
1112 case O_bit_and
: left
&= right
; break;
1113 case O_add
: left
+= right
; break;
1114 case O_subtract
: left
-= right
; break;
1115 case O_eq
: left
= left
== right
? ~ (offsetT
) 0 : 0; break;
1116 case O_ne
: left
= left
!= right
? ~ (offsetT
) 0 : 0; break;
1117 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1118 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1119 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1120 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1121 case O_logical_and
: left
= left
&& right
; break;
1122 case O_logical_or
: left
= left
|| right
; break;
1126 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1127 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1128 final_seg
= absolute_section
;
1129 resolved
= (symbol_resolved_p (add_symbol
)
1130 && symbol_resolved_p (op_symbol
));
1136 /* Give an error (below) if not in expr_section. We don't
1137 want to worry about expr_section symbols, because they
1138 are fictional (they are created as part of expression
1139 resolution), and any problems may not actually mean
1144 symp
->sy_resolving
= 0;
1149 S_SET_VALUE (symp
, final_val
);
1151 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1152 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1153 for a stab symbol, so we use this bad hack. */
1154 if (final_seg
!= S_GET_SEGMENT (symp
))
1156 S_SET_SEGMENT (symp
, final_seg
);
1159 exit_dont_set_value
:
1160 /* Don't worry if we can't resolve an expr_section symbol. */
1164 symp
->sy_resolved
= 1;
1165 else if (S_GET_SEGMENT (symp
) != expr_section
)
1167 as_bad (_("can't resolve value for symbol \"%s\""),
1169 symp
->sy_resolved
= 1;
1176 #ifdef BFD_ASSEMBLER
1178 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1180 /* A static function passed to hash_traverse. */
1183 resolve_local_symbol (key
, value
)
1184 const char *key ATTRIBUTE_UNUSED
;
1188 resolve_symbol_value (value
);
1193 /* Resolve all local symbols. */
1196 resolve_local_symbol_values ()
1198 #ifdef BFD_ASSEMBLER
1199 hash_traverse (local_hash
, resolve_local_symbol
);
1203 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1204 They are *really* local. That is, they go out of scope whenever we see a
1205 label that isn't local. Also, like fb labels, there can be multiple
1206 instances of a dollar label. Therefor, we name encode each instance with
1207 the instance number, keep a list of defined symbols separate from the real
1208 symbol table, and we treat these buggers as a sparse array. */
1210 static long *dollar_labels
;
1211 static long *dollar_label_instances
;
1212 static char *dollar_label_defines
;
1213 static unsigned long dollar_label_count
;
1214 static unsigned long dollar_label_max
;
1217 dollar_label_defined (label
)
1222 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1224 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1226 return dollar_label_defines
[i
- dollar_labels
];
1228 /* If we get here, label isn't defined. */
1233 dollar_label_instance (label
)
1238 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1240 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1242 return (dollar_label_instances
[i
- dollar_labels
]);
1244 /* If we get here, we haven't seen the label before.
1245 Therefore its instance count is zero. */
1250 dollar_label_clear ()
1252 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1255 #define DOLLAR_LABEL_BUMP_BY 10
1258 define_dollar_label (label
)
1263 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1266 ++dollar_label_instances
[i
- dollar_labels
];
1267 dollar_label_defines
[i
- dollar_labels
] = 1;
1271 /* If we get to here, we don't have label listed yet. */
1273 if (dollar_labels
== NULL
)
1275 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1276 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1277 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1278 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1279 dollar_label_count
= 0;
1281 else if (dollar_label_count
== dollar_label_max
)
1283 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1284 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1285 dollar_label_max
* sizeof (long));
1286 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1287 dollar_label_max
* sizeof (long));
1288 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1289 } /* if we needed to grow */
1291 dollar_labels
[dollar_label_count
] = label
;
1292 dollar_label_instances
[dollar_label_count
] = 1;
1293 dollar_label_defines
[dollar_label_count
] = 1;
1294 ++dollar_label_count
;
1297 /* Caller must copy returned name: we re-use the area for the next name.
1299 The mth occurence of label n: is turned into the symbol "Ln^Am"
1300 where n is the label number and m is the instance number. "L" makes
1301 it a label discarded unless debugging and "^A"('\1') ensures no
1302 ordinary symbol SHOULD get the same name as a local label
1303 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1305 fb labels get the same treatment, except that ^B is used in place
1308 char * /* Return local label name. */
1309 dollar_label_name (n
, augend
)
1310 register long n
; /* we just saw "n$:" : n a number. */
1311 register int augend
; /* 0 for current instance, 1 for new instance. */
1314 /* Returned to caller, then copied. Used for created names ("4f"). */
1315 static char symbol_name_build
[24];
1318 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1321 know (augend
== 0 || augend
== 1);
1322 p
= symbol_name_build
;
1323 #ifdef LOCAL_LABEL_PREFIX
1324 *p
++ = LOCAL_LABEL_PREFIX
;
1328 /* Next code just does sprintf( {}, "%d", n); */
1330 q
= symbol_name_temporary
;
1331 for (*q
++ = 0, i
= n
; i
; ++q
)
1336 while ((*p
= *--q
) != '\0')
1339 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1341 /* Instance number. */
1342 q
= symbol_name_temporary
;
1343 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1348 while ((*p
++ = *--q
) != '\0');;
1350 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1351 return symbol_name_build
;
1354 /* Sombody else's idea of local labels. They are made by "n:" where n
1355 is any decimal digit. Refer to them with
1356 "nb" for previous (backward) n:
1357 or "nf" for next (forward) n:.
1359 We do a little better and let n be any number, not just a single digit, but
1360 since the other guy's assembler only does ten, we treat the first ten
1363 Like someone else's assembler, we have one set of local label counters for
1364 entire assembly, not one set per (sub)segment like in most assemblers. This
1365 implies that one can refer to a label in another segment, and indeed some
1366 crufty compilers have done just that.
1368 Since there could be a LOT of these things, treat them as a sparse
1371 #define FB_LABEL_SPECIAL (10)
1373 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1374 static long *fb_labels
;
1375 static long *fb_label_instances
;
1376 static long fb_label_count
;
1377 static long fb_label_max
;
1379 /* This must be more than FB_LABEL_SPECIAL. */
1380 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1385 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1388 /* Add one to the instance number of this fb label. */
1391 fb_label_instance_inc (label
)
1396 if (label
< FB_LABEL_SPECIAL
)
1398 ++fb_low_counter
[label
];
1402 if (fb_labels
!= NULL
)
1404 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1405 i
< fb_labels
+ fb_label_count
; ++i
)
1409 ++fb_label_instances
[i
- fb_labels
];
1411 } /* if we find it */
1412 } /* for each existing label */
1415 /* If we get to here, we don't have label listed yet. */
1417 if (fb_labels
== NULL
)
1419 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1420 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1421 fb_label_max
= FB_LABEL_BUMP_BY
;
1422 fb_label_count
= FB_LABEL_SPECIAL
;
1425 else if (fb_label_count
== fb_label_max
)
1427 fb_label_max
+= FB_LABEL_BUMP_BY
;
1428 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1429 fb_label_max
* sizeof (long));
1430 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1431 fb_label_max
* sizeof (long));
1432 } /* if we needed to grow */
1434 fb_labels
[fb_label_count
] = label
;
1435 fb_label_instances
[fb_label_count
] = 1;
1440 fb_label_instance (label
)
1445 if (label
< FB_LABEL_SPECIAL
)
1447 return (fb_low_counter
[label
]);
1450 if (fb_labels
!= NULL
)
1452 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1453 i
< fb_labels
+ fb_label_count
; ++i
)
1457 return (fb_label_instances
[i
- fb_labels
]);
1458 } /* if we find it */
1459 } /* for each existing label */
1462 /* We didn't find the label, so this must be a reference to the
1467 /* Caller must copy returned name: we re-use the area for the next name.
1469 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1470 where n is the label number and m is the instance number. "L" makes
1471 it a label discarded unless debugging and "^B"('\2') ensures no
1472 ordinary symbol SHOULD get the same name as a local label
1473 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1475 dollar labels get the same treatment, except that ^A is used in
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
;
1493 #ifdef LOCAL_LABEL_PREFIX
1494 *p
++ = LOCAL_LABEL_PREFIX
;
1498 /* Next code just does sprintf( {}, "%d", n); */
1500 q
= symbol_name_temporary
;
1501 for (*q
++ = 0, i
= n
; i
; ++q
)
1506 while ((*p
= *--q
) != '\0')
1509 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
1511 /* Instance number. */
1512 q
= symbol_name_temporary
;
1513 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1518 while ((*p
++ = *--q
) != '\0');;
1520 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1521 return (symbol_name_build
);
1524 /* Decode name that may have been generated by foo_label_name() above.
1525 If the name wasn't generated by foo_label_name(), then return it
1526 unaltered. This is used for error messages. */
1529 decode_local_label_name (s
)
1533 char *symbol_decode
;
1535 int instance_number
;
1537 const char *message_format
;
1540 #ifdef LOCAL_LABEL_PREFIX
1541 if (s
[index
] == LOCAL_LABEL_PREFIX
)
1545 if (s
[index
] != 'L')
1548 for (label_number
= 0, p
= s
+ index
+ 1; isdigit ((unsigned char) *p
); ++p
)
1549 label_number
= (10 * label_number
) + *p
- '0';
1551 if (*p
== DOLLAR_LABEL_CHAR
)
1553 else if (*p
== LOCAL_LABEL_CHAR
)
1558 for (instance_number
= 0, p
++; isdigit ((unsigned char) *p
); ++p
)
1559 instance_number
= (10 * instance_number
) + *p
- '0';
1561 message_format
= _("\"%d\" (instance number %d of a %s label)");
1562 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1563 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1565 return symbol_decode
;
1568 /* Get the value of a symbol. */
1574 #ifdef BFD_ASSEMBLER
1575 if (LOCAL_SYMBOL_CHECK (s
))
1576 return ((struct local_symbol
*) s
)->lsy_offset
;
1579 if (!s
->sy_resolved
&& s
->sy_value
.X_op
!= O_constant
)
1581 valueT val
= resolve_symbol_value (s
);
1585 if (s
->sy_value
.X_op
!= O_constant
)
1587 static symbolS
*recur
;
1589 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1590 may call S_GET_VALUE. We use a static symbol to avoid the
1591 immediate recursion. */
1593 return (valueT
) s
->sy_value
.X_add_number
;
1595 if (! s
->sy_resolved
1596 || s
->sy_value
.X_op
!= O_symbol
1597 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1598 as_bad (_("Attempt to get value of unresolved symbol %s"),
1602 return (valueT
) s
->sy_value
.X_add_number
;
1605 /* Set the value of a symbol. */
1608 S_SET_VALUE (s
, val
)
1612 #ifdef BFD_ASSEMBLER
1613 if (LOCAL_SYMBOL_CHECK (s
))
1615 ((struct local_symbol
*) s
)->lsy_offset
= val
;
1620 s
->sy_value
.X_op
= O_constant
;
1621 s
->sy_value
.X_add_number
= (offsetT
) val
;
1622 s
->sy_value
.X_unsigned
= 0;
1626 copy_symbol_attributes (dest
, src
)
1627 symbolS
*dest
, *src
;
1629 if (LOCAL_SYMBOL_CHECK (dest
))
1630 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
1631 if (LOCAL_SYMBOL_CHECK (src
))
1632 src
= local_symbol_convert ((struct local_symbol
*) src
);
1634 #ifdef BFD_ASSEMBLER
1635 /* In an expression, transfer the settings of these flags.
1636 The user can override later, of course. */
1637 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1638 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1641 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1642 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1646 #ifdef BFD_ASSEMBLER
1654 if (LOCAL_SYMBOL_CHECK (s
))
1657 flags
= s
->bsym
->flags
;
1659 return (flags
& BSF_FUNCTION
) != 0;
1668 if (LOCAL_SYMBOL_CHECK (s
))
1671 flags
= s
->bsym
->flags
;
1674 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1677 return (flags
& BSF_GLOBAL
) != 0;
1684 if (LOCAL_SYMBOL_CHECK (s
))
1686 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1693 if (LOCAL_SYMBOL_CHECK (s
))
1695 return bfd_is_com_section (s
->bsym
->section
);
1702 if (LOCAL_SYMBOL_CHECK (s
))
1703 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1704 return s
->bsym
->section
!= undefined_section
;
1711 if (LOCAL_SYMBOL_CHECK (s
))
1713 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1725 if (LOCAL_SYMBOL_CHECK (s
))
1728 flags
= s
->bsym
->flags
;
1731 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1734 if (bfd_get_section (s
->bsym
) == reg_section
)
1737 if (flag_strip_local_absolute
1738 && (flags
& BSF_GLOBAL
) == 0
1739 && bfd_get_section (s
->bsym
) == absolute_section
)
1742 name
= S_GET_NAME (s
);
1743 return (name
!= NULL
1745 && (strchr (name
, DOLLAR_LABEL_CHAR
)
1746 || strchr (name
, LOCAL_LABEL_CHAR
)
1747 || (! flag_keep_locals
1748 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1751 && name
[1] == '?')))));
1758 return S_IS_EXTERNAL (s
);
1765 return S_GET_NAME (s
) == 0;
1772 if (LOCAL_SYMBOL_CHECK (s
))
1773 return ((struct local_symbol
*) s
)->lsy_name
;
1774 return s
->bsym
->name
;
1781 if (LOCAL_SYMBOL_CHECK (s
))
1782 return ((struct local_symbol
*) s
)->lsy_section
;
1783 return s
->bsym
->section
;
1787 S_SET_SEGMENT (s
, seg
)
1791 /* Don't reassign section symbols. The direct reason is to prevent seg
1792 faults assigning back to const global symbols such as *ABS*, but it
1793 shouldn't happen anyway. */
1795 if (LOCAL_SYMBOL_CHECK (s
))
1797 if (seg
== reg_section
)
1798 s
= local_symbol_convert ((struct local_symbol
*) s
);
1801 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1806 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1808 if (s
->bsym
->section
!= seg
)
1812 s
->bsym
->section
= seg
;
1819 if (LOCAL_SYMBOL_CHECK (s
))
1820 s
= local_symbol_convert ((struct local_symbol
*) s
);
1821 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1823 /* Let .weak override .global. */
1826 s
->bsym
->flags
|= BSF_GLOBAL
;
1827 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
1831 S_CLEAR_EXTERNAL (s
)
1834 if (LOCAL_SYMBOL_CHECK (s
))
1836 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1838 /* Let .weak override. */
1841 s
->bsym
->flags
|= BSF_LOCAL
;
1842 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
1849 if (LOCAL_SYMBOL_CHECK (s
))
1850 s
= local_symbol_convert ((struct local_symbol
*) s
);
1851 s
->bsym
->flags
|= BSF_WEAK
;
1852 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
1856 S_SET_NAME (s
, name
)
1860 if (LOCAL_SYMBOL_CHECK (s
))
1862 ((struct local_symbol
*) s
)->lsy_name
= name
;
1865 s
->bsym
->name
= name
;
1867 #endif /* BFD_ASSEMBLER */
1869 #ifdef SYMBOLS_NEED_BACKPOINTERS
1871 /* Return the previous symbol in a chain. */
1877 if (LOCAL_SYMBOL_CHECK (s
))
1879 return s
->sy_previous
;
1882 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1884 /* Return the next symbol in a chain. */
1890 if (LOCAL_SYMBOL_CHECK (s
))
1895 /* Return a pointer to the value of a symbol as an expression. */
1898 symbol_get_value_expression (s
)
1901 if (LOCAL_SYMBOL_CHECK (s
))
1902 s
= local_symbol_convert ((struct local_symbol
*) s
);
1903 return &s
->sy_value
;
1906 /* Set the value of a symbol to an expression. */
1909 symbol_set_value_expression (s
, exp
)
1911 const expressionS
*exp
;
1913 if (LOCAL_SYMBOL_CHECK (s
))
1914 s
= local_symbol_convert ((struct local_symbol
*) s
);
1918 /* Set the frag of a symbol. */
1921 symbol_set_frag (s
, f
)
1925 #ifdef BFD_ASSEMBLER
1926 if (LOCAL_SYMBOL_CHECK (s
))
1928 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
1935 /* Return the frag of a symbol. */
1941 #ifdef BFD_ASSEMBLER
1942 if (LOCAL_SYMBOL_CHECK (s
))
1943 return local_symbol_get_frag ((struct local_symbol
*) s
);
1948 /* Mark a symbol as having been used. */
1951 symbol_mark_used (s
)
1954 if (LOCAL_SYMBOL_CHECK (s
))
1959 /* Clear the mark of whether a symbol has been used. */
1962 symbol_clear_used (s
)
1965 if (LOCAL_SYMBOL_CHECK (s
))
1966 s
= local_symbol_convert ((struct local_symbol
*) s
);
1970 /* Return whether a symbol has been used. */
1976 if (LOCAL_SYMBOL_CHECK (s
))
1981 /* Mark a symbol as having been used in a reloc. */
1984 symbol_mark_used_in_reloc (s
)
1987 if (LOCAL_SYMBOL_CHECK (s
))
1988 s
= local_symbol_convert ((struct local_symbol
*) s
);
1989 s
->sy_used_in_reloc
= 1;
1992 /* Clear the mark of whether a symbol has been used in a reloc. */
1995 symbol_clear_used_in_reloc (s
)
1998 if (LOCAL_SYMBOL_CHECK (s
))
2000 s
->sy_used_in_reloc
= 0;
2003 /* Return whether a symbol has been used in a reloc. */
2006 symbol_used_in_reloc_p (s
)
2009 if (LOCAL_SYMBOL_CHECK (s
))
2011 return s
->sy_used_in_reloc
;
2014 /* Mark a symbol as an MRI common symbol. */
2017 symbol_mark_mri_common (s
)
2020 if (LOCAL_SYMBOL_CHECK (s
))
2021 s
= local_symbol_convert ((struct local_symbol
*) s
);
2022 s
->sy_mri_common
= 1;
2025 /* Clear the mark of whether a symbol is an MRI common symbol. */
2028 symbol_clear_mri_common (s
)
2031 if (LOCAL_SYMBOL_CHECK (s
))
2033 s
->sy_mri_common
= 0;
2036 /* Return whether a symbol is an MRI common symbol. */
2039 symbol_mri_common_p (s
)
2042 if (LOCAL_SYMBOL_CHECK (s
))
2044 return s
->sy_mri_common
;
2047 /* Mark a symbol as having been written. */
2050 symbol_mark_written (s
)
2053 if (LOCAL_SYMBOL_CHECK (s
))
2058 /* Clear the mark of whether a symbol has been written. */
2061 symbol_clear_written (s
)
2064 if (LOCAL_SYMBOL_CHECK (s
))
2069 /* Return whether a symbol has been written. */
2072 symbol_written_p (s
)
2075 if (LOCAL_SYMBOL_CHECK (s
))
2080 /* Mark a symbol has having been resolved. */
2083 symbol_mark_resolved (s
)
2086 #ifdef BFD_ASSEMBLER
2087 if (LOCAL_SYMBOL_CHECK (s
))
2089 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2096 /* Return whether a symbol has been resolved. */
2099 symbol_resolved_p (s
)
2102 #ifdef BFD_ASSEMBLER
2103 if (LOCAL_SYMBOL_CHECK (s
))
2104 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2106 return s
->sy_resolved
;
2109 /* Return whether a symbol is a section symbol. */
2112 symbol_section_p (s
)
2113 symbolS
*s ATTRIBUTE_UNUSED
;
2115 if (LOCAL_SYMBOL_CHECK (s
))
2117 #ifdef BFD_ASSEMBLER
2118 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2125 /* Return whether a symbol is equated to another symbol. */
2128 symbol_equated_p (s
)
2131 if (LOCAL_SYMBOL_CHECK (s
))
2133 return s
->sy_value
.X_op
== O_symbol
;
2136 /* Return whether a symbol has a constant value. */
2139 symbol_constant_p (s
)
2142 if (LOCAL_SYMBOL_CHECK (s
))
2144 return s
->sy_value
.X_op
== O_constant
;
2147 #ifdef BFD_ASSEMBLER
2149 /* Return the BFD symbol for a symbol. */
2152 symbol_get_bfdsym (s
)
2155 if (LOCAL_SYMBOL_CHECK (s
))
2156 s
= local_symbol_convert ((struct local_symbol
*) s
);
2160 /* Set the BFD symbol for a symbol. */
2163 symbol_set_bfdsym (s
, bsym
)
2167 if (LOCAL_SYMBOL_CHECK (s
))
2168 s
= local_symbol_convert ((struct local_symbol
*) s
);
2172 #endif /* BFD_ASSEMBLER */
2174 #ifdef OBJ_SYMFIELD_TYPE
2176 /* Get a pointer to the object format information for a symbol. */
2182 if (LOCAL_SYMBOL_CHECK (s
))
2183 s
= local_symbol_convert ((struct local_symbol
*) s
);
2187 /* Set the object format information for a symbol. */
2190 symbol_set_obj (s
, o
)
2192 OBJ_SYMFIELD_TYPE
*o
;
2194 if (LOCAL_SYMBOL_CHECK (s
))
2195 s
= local_symbol_convert ((struct local_symbol
*) s
);
2199 #endif /* OBJ_SYMFIELD_TYPE */
2201 #ifdef TC_SYMFIELD_TYPE
2203 /* Get a pointer to the processor information for a symbol. */
2209 if (LOCAL_SYMBOL_CHECK (s
))
2210 s
= local_symbol_convert ((struct local_symbol
*) s
);
2214 /* Set the processor information for a symbol. */
2217 symbol_set_tc (s
, o
)
2219 TC_SYMFIELD_TYPE
*o
;
2221 if (LOCAL_SYMBOL_CHECK (s
))
2222 s
= local_symbol_convert ((struct local_symbol
*) s
);
2226 #endif /* TC_SYMFIELD_TYPE */
2231 symbol_lastP
= NULL
;
2232 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2233 sy_hash
= hash_new ();
2234 #ifdef BFD_ASSEMBLER
2235 local_hash
= hash_new ();
2238 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2239 #ifdef BFD_ASSEMBLER
2240 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2241 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2244 /* Can't initialise a union. Sigh. */
2245 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2247 abs_symbol
.sy_value
.X_op
= O_constant
;
2248 abs_symbol
.sy_frag
= &zero_address_frag
;
2250 if (LOCAL_LABELS_FB
)
2256 /* Maximum indent level.
2257 Available for modification inside a gdb session. */
2258 int max_indent_level
= 8;
2265 printf ("%*s", indent_level
* 4, "");
2271 print_symbol_value_1 (file
, sym
)
2275 const char *name
= S_GET_NAME (sym
);
2276 if (!name
|| !name
[0])
2278 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2280 if (LOCAL_SYMBOL_CHECK (sym
))
2282 #ifdef BFD_ASSEMBLER
2283 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2284 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2285 && local_symbol_get_frag (locsym
) != NULL
)
2286 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2287 if (local_symbol_resolved_p (locsym
))
2288 fprintf (file
, " resolved");
2289 fprintf (file
, " local");
2294 if (sym
->sy_frag
!= &zero_address_frag
)
2295 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2297 fprintf (file
, " written");
2298 if (sym
->sy_resolved
)
2299 fprintf (file
, " resolved");
2300 else if (sym
->sy_resolving
)
2301 fprintf (file
, " resolving");
2302 if (sym
->sy_used_in_reloc
)
2303 fprintf (file
, " used-in-reloc");
2305 fprintf (file
, " used");
2306 if (S_IS_LOCAL (sym
))
2307 fprintf (file
, " local");
2308 if (S_IS_EXTERN (sym
))
2309 fprintf (file
, " extern");
2310 if (S_IS_DEBUG (sym
))
2311 fprintf (file
, " debug");
2312 if (S_IS_DEFINED (sym
))
2313 fprintf (file
, " defined");
2315 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2316 if (symbol_resolved_p (sym
))
2318 segT s
= S_GET_SEGMENT (sym
);
2320 if (s
!= undefined_section
2321 && s
!= expr_section
)
2322 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2324 else if (indent_level
< max_indent_level
2325 && S_GET_SEGMENT (sym
) != undefined_section
)
2328 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2329 #ifdef BFD_ASSEMBLER
2330 if (LOCAL_SYMBOL_CHECK (sym
))
2331 fprintf (file
, "constant %lx",
2332 (long) ((struct local_symbol
*) sym
)->lsy_offset
);
2335 print_expr_1 (file
, &sym
->sy_value
);
2336 fprintf (file
, ">");
2343 print_symbol_value (sym
)
2347 print_symbol_value_1 (stderr
, sym
);
2348 fprintf (stderr
, "\n");
2352 print_binary (file
, name
, exp
)
2358 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2359 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2360 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2361 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2362 fprintf (file
, ">");
2367 print_expr_1 (file
, exp
)
2371 fprintf (file
, "expr %lx ", (long) exp
);
2375 fprintf (file
, "illegal");
2378 fprintf (file
, "absent");
2381 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2385 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2386 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2387 fprintf (file
, ">");
2389 if (exp
->X_add_number
)
2390 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2391 (long) exp
->X_add_number
);
2395 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2398 fprintf (file
, "big");
2401 fprintf (file
, "uminus -<");
2403 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2404 fprintf (file
, ">");
2405 goto maybe_print_addnum
;
2407 fprintf (file
, "bit_not");
2410 print_binary (file
, "multiply", exp
);
2413 print_binary (file
, "divide", exp
);
2416 print_binary (file
, "modulus", exp
);
2419 print_binary (file
, "lshift", exp
);
2422 print_binary (file
, "rshift", exp
);
2424 case O_bit_inclusive_or
:
2425 print_binary (file
, "bit_ior", exp
);
2427 case O_bit_exclusive_or
:
2428 print_binary (file
, "bit_xor", exp
);
2431 print_binary (file
, "bit_and", exp
);
2434 print_binary (file
, "eq", exp
);
2437 print_binary (file
, "ne", exp
);
2440 print_binary (file
, "lt", exp
);
2443 print_binary (file
, "le", exp
);
2446 print_binary (file
, "ge", exp
);
2449 print_binary (file
, "gt", exp
);
2452 print_binary (file
, "logical_and", exp
);
2455 print_binary (file
, "logical_or", exp
);
2459 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2460 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2461 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2462 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2463 fprintf (file
, ">");
2464 goto maybe_print_addnum
;
2467 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
2468 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2469 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2470 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2471 fprintf (file
, ">");
2472 goto maybe_print_addnum
;
2474 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2484 print_expr_1 (stderr
, exp
);
2485 fprintf (stderr
, "\n");
2489 symbol_print_statistics (file
)
2492 hash_print_statistics (file
, "symbol table", sy_hash
);
2493 #ifdef BFD_ASSEMBLER
2494 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2495 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2496 local_symbol_count
, local_symbol_conversion_count
);