1 /* symbols.c -symbol table-
2 Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* #define DEBUG_SYMS / * to debug symbol list maintenance. */
28 #include "obstack.h" /* For "symbols.h" */
31 #include "struc-symbol.h"
33 /* This is non-zero if symbols are case sensitive, which is the
35 int symbols_case_sensitive
= 1;
37 #ifndef WORKING_DOT_WORD
38 extern int new_broken_words
;
41 /* symbol-name => struct symbol pointer */
42 static struct hash_control
*sy_hash
;
44 /* Table of local symbols. */
45 static struct hash_control
*local_hash
;
47 /* Below are commented in "symbols.h". */
48 symbolS
*symbol_rootP
;
49 symbolS
*symbol_lastP
;
53 #define debug_verify_symchain verify_symbol_chain
55 #define debug_verify_symchain(root, last) ((void) 0)
58 #define DOLLAR_LABEL_CHAR '\001'
59 #define LOCAL_LABEL_CHAR '\002'
63 static void fb_label_init
PARAMS ((void));
64 static long dollar_label_instance
PARAMS ((long));
65 static long fb_label_instance
PARAMS ((long));
67 static void print_binary
PARAMS ((FILE *, const char *, expressionS
*));
69 /* Return a pointer to a new symbol. Die if we can't make a new
70 symbol. Fill in the symbol's values. Add symbol to end of symbol
73 This function should be called in the general case of creating a
74 symbol. However, if the output file symbol table has already been
75 set, and you are certain that this symbol won't be wanted in the
76 output file, you can call symbol_create. */
79 symbol_new (name
, segment
, valu
, frag
)
85 symbolS
*symbolP
= symbol_create (name
, segment
, valu
, frag
);
87 /* Link to end of symbol chain. */
90 extern int symbol_table_frozen
;
91 if (symbol_table_frozen
)
95 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
100 /* Save a symbol name on a permanent obstack, and convert it according
101 to the object file format. */
104 save_symbol_name (name
)
107 unsigned int name_length
;
110 name_length
= strlen (name
) + 1; /* +1 for \0. */
111 obstack_grow (¬es
, name
, name_length
);
112 ret
= obstack_finish (¬es
);
114 #ifdef STRIP_UNDERSCORE
119 #ifdef tc_canonicalize_symbol_name
120 ret
= tc_canonicalize_symbol_name (ret
);
123 if (! symbols_case_sensitive
)
127 for (s
= (unsigned char *) ret
; *s
!= '\0'; s
++)
136 symbol_create (name
, segment
, valu
, frag
)
137 const char *name
; /* It is copied, the caller can destroy/modify. */
138 segT segment
; /* Segment identifier (SEG_<something>). */
139 valueT valu
; /* Symbol value. */
140 fragS
*frag
; /* Associated fragment. */
142 char *preserved_copy_of_name
;
145 preserved_copy_of_name
= save_symbol_name (name
);
147 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
149 /* symbol must be born in some fixed state. This seems as good as any. */
150 memset (symbolP
, 0, sizeof (symbolS
));
153 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
154 if (symbolP
->bsym
== NULL
)
155 as_perror ("%s", "bfd_make_empty_symbol");
156 symbolP
->bsym
->udata
.p
= (PTR
) symbolP
;
158 S_SET_NAME (symbolP
, preserved_copy_of_name
);
160 S_SET_SEGMENT (symbolP
, segment
);
161 S_SET_VALUE (symbolP
, valu
);
162 symbol_clear_list_pointers (symbolP
);
164 symbolP
->sy_frag
= frag
;
165 #ifndef BFD_ASSEMBLER
166 symbolP
->sy_number
= ~0;
167 symbolP
->sy_name_offset
= (unsigned int) ~0;
170 obj_symbol_new_hook (symbolP
);
172 #ifdef tc_symbol_new_hook
173 tc_symbol_new_hook (symbolP
);
181 /* Local symbol support. If we can get away with it, we keep only a
182 small amount of information for local symbols. */
184 static struct local_symbol
*local_symbol_make
PARAMS ((const char *, segT
,
186 static symbolS
*local_symbol_convert
PARAMS ((struct local_symbol
*));
188 /* Used for statistics. */
190 static unsigned long local_symbol_count
;
191 static unsigned long local_symbol_conversion_count
;
193 /* This macro is called with a symbol argument passed by reference.
194 It returns whether this is a local symbol. If necessary, it
195 changes its argument to the real symbol. */
197 #define LOCAL_SYMBOL_CHECK(s) \
199 ? (local_symbol_converted_p ((struct local_symbol *) s) \
200 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
205 /* Create a local symbol and insert it into the local hash table. */
207 static struct local_symbol
*
208 local_symbol_make (name
, section
, offset
, frag
)
215 struct local_symbol
*ret
;
217 ++local_symbol_count
;
219 name_copy
= save_symbol_name (name
);
221 ret
= (struct local_symbol
*) obstack_alloc (¬es
, sizeof *ret
);
222 ret
->lsy_marker
= NULL
;
223 ret
->lsy_name
= name_copy
;
224 ret
->lsy_section
= section
;
225 local_symbol_set_frag (ret
, frag
);
226 ret
->lsy_offset
= offset
;
228 hash_jam (local_hash
, name_copy
, (PTR
) ret
);
233 /* Convert a local symbol into a real symbol. Note that we do not
234 reclaim the space used by the local symbol. */
237 local_symbol_convert (locsym
)
238 struct local_symbol
*locsym
;
242 assert (locsym
->lsy_marker
== NULL
);
243 if (local_symbol_converted_p (locsym
))
244 return local_symbol_get_real_symbol (locsym
);
246 ++local_symbol_conversion_count
;
248 ret
= symbol_new (locsym
->lsy_name
, locsym
->lsy_section
, locsym
->lsy_offset
,
249 local_symbol_get_frag (locsym
));
251 if (local_symbol_resolved_p (locsym
))
252 ret
->sy_resolved
= 1;
254 /* Local symbols are always either defined or used. */
257 symbol_table_insert (ret
);
259 local_symbol_mark_converted (locsym
);
260 local_symbol_set_real_symbol (locsym
, ret
);
262 hash_jam (local_hash
, locsym
->lsy_name
, NULL
);
267 #else /* ! BFD_ASSEMBLER */
269 #define LOCAL_SYMBOL_CHECK(s) 0
270 #define local_symbol_convert(s) ((symbolS *) s)
272 #endif /* ! BFD_ASSEMBLER */
274 /* We have just seen "<name>:".
275 Creates a struct symbol unless it already exists.
277 Gripes if we are redefining a symbol incompatibly (and ignores it). */
280 colon (sym_name
) /* Just seen "x:" - rattle symbols & frags. */
281 const char *sym_name
; /* Symbol name, as a cannonical string. */
282 /* We copy this string: OK to alter later. */
284 register symbolS
*symbolP
; /* Symbol we are working with. */
286 /* Sun local labels go out of scope whenever a non-local symbol is
288 if (LOCAL_LABELS_DOLLAR
)
293 local
= bfd_is_local_label_name (stdoutput
, sym_name
);
295 local
= LOCAL_LABEL (sym_name
);
299 dollar_label_clear ();
302 #ifndef WORKING_DOT_WORD
303 if (new_broken_words
)
305 struct broken_word
*a
;
310 extern const int md_short_jump_size
;
311 extern const int md_long_jump_size
;
312 possible_bytes
= (md_short_jump_size
313 + new_broken_words
* md_long_jump_size
);
316 frag_opcode
= frag_var (rs_broken_word
,
320 (symbolS
*) broken_words
,
324 /* We want to store the pointer to where to insert the jump
325 table in the fr_opcode of the rs_broken_word frag. This
326 requires a little hackery. */
328 && (frag_tmp
->fr_type
!= rs_broken_word
329 || frag_tmp
->fr_opcode
))
330 frag_tmp
= frag_tmp
->fr_next
;
332 frag_tmp
->fr_opcode
= frag_opcode
;
333 new_broken_words
= 0;
335 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
336 a
->dispfrag
= frag_tmp
;
338 #endif /* WORKING_DOT_WORD */
340 if ((symbolP
= symbol_find (sym_name
)) != 0)
342 #ifdef RESOLVE_SYMBOL_REDEFINITION
343 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
346 /* Now check for undefined symbols. */
347 if (LOCAL_SYMBOL_CHECK (symbolP
))
350 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
352 if (locsym
->lsy_section
!= undefined_section
353 && (local_symbol_get_frag (locsym
) != frag_now
354 || locsym
->lsy_section
!= now_seg
355 || locsym
->lsy_offset
!= frag_now_fix ()))
357 as_bad (_("Symbol %s already defined."), sym_name
);
361 locsym
->lsy_section
= now_seg
;
362 local_symbol_set_frag (locsym
, frag_now
);
363 locsym
->lsy_offset
= frag_now_fix ();
366 else if (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
368 if (S_GET_VALUE (symbolP
) == 0)
370 symbolP
->sy_frag
= frag_now
;
372 S_SET_OTHER (symbolP
, const_flag
);
374 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
375 S_SET_SEGMENT (symbolP
, now_seg
);
378 #endif /* if we have one, it better be zero. */
383 /* There are still several cases to check:
385 A .comm/.lcomm symbol being redefined as initialized
388 A .comm/.lcomm symbol being redefined with a larger
391 This only used to be allowed on VMS gas, but Sun cc
392 on the sparc also depends on it. */
394 if (((!S_IS_DEBUG (symbolP
)
395 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
396 && S_IS_EXTERNAL (symbolP
))
397 || S_GET_SEGMENT (symbolP
) == bss_section
)
398 && (now_seg
== data_section
399 || now_seg
== S_GET_SEGMENT (symbolP
)))
401 /* Select which of the 2 cases this is. */
402 if (now_seg
!= data_section
)
404 /* New .comm for prev .comm symbol.
406 If the new size is larger we just change its
407 value. If the new size is smaller, we ignore
409 if (S_GET_VALUE (symbolP
)
410 < ((unsigned) frag_now_fix ()))
412 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
417 /* It is a .comm/.lcomm being converted to initialized
419 symbolP
->sy_frag
= frag_now
;
421 S_SET_OTHER (symbolP
, const_flag
);
423 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
424 S_SET_SEGMENT (symbolP
, now_seg
); /* Keep N_EXT bit. */
429 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
430 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
431 static const char *od_buf
= "";
436 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
438 sprintf(od_buf
, "%d.%d.",
439 S_GET_OTHER (symbolP
),
440 S_GET_DESC (symbolP
));
442 as_bad (_("Symbol \"%s\" is already defined as \"%s\"/%s%ld."),
444 segment_name (S_GET_SEGMENT (symbolP
)),
446 (long) S_GET_VALUE (symbolP
));
448 } /* if the undefined symbol has no value */
452 /* Don't blow up if the definition is the same. */
453 if (!(frag_now
== symbolP
->sy_frag
454 && S_GET_VALUE (symbolP
) == frag_now_fix ()
455 && S_GET_SEGMENT (symbolP
) == now_seg
))
456 as_bad (_("Symbol %s already defined."), sym_name
);
461 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
463 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
464 (valueT
) frag_now_fix (),
467 #endif /* BFD_ASSEMBLER */
470 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
473 S_SET_OTHER (symbolP
, const_flag
);
476 symbol_table_insert (symbolP
);
479 if (mri_common_symbol
!= NULL
)
481 /* This symbol is actually being defined within an MRI common
482 section. This requires special handling. */
483 if (LOCAL_SYMBOL_CHECK (symbolP
))
484 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
485 symbolP
->sy_value
.X_op
= O_symbol
;
486 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
487 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
488 symbolP
->sy_frag
= &zero_address_frag
;
489 S_SET_SEGMENT (symbolP
, expr_section
);
490 symbolP
->sy_mri_common
= 1;
494 tc_frob_label (symbolP
);
496 #ifdef obj_frob_label
497 obj_frob_label (symbolP
);
503 /* Die if we can't insert the symbol. */
506 symbol_table_insert (symbolP
)
509 register const char *error_string
;
512 know (S_GET_NAME (symbolP
));
514 if (LOCAL_SYMBOL_CHECK (symbolP
))
516 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
518 if (error_string
!= NULL
)
519 as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
520 S_GET_NAME (symbolP
), error_string
);
524 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
526 as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
527 S_GET_NAME (symbolP
), error_string
);
531 /* If a symbol name does not exist, create it as undefined, and insert
532 it into the symbol table. Return a pointer to it. */
535 symbol_find_or_make (name
)
538 register symbolS
*symbolP
;
540 symbolP
= symbol_find (name
);
545 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
547 symbolP
= md_undefined_symbol ((char *) name
);
551 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
558 symbolP
= symbol_make (name
);
560 symbol_table_insert (symbolP
);
561 } /* if symbol wasn't found */
572 /* Let the machine description default it, e.g. for register names. */
573 symbolP
= md_undefined_symbol ((char *) name
);
576 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
581 /* Implement symbol table lookup.
582 In: A symbol's name as a string: '\0' can't be part of a symbol name.
583 Out: NULL if the name was not in the symbol table, else the address
584 of a struct symbol associated with that name. */
590 #ifdef STRIP_UNDERSCORE
591 return (symbol_find_base (name
, 1));
592 #else /* STRIP_UNDERSCORE */
593 return (symbol_find_base (name
, 0));
594 #endif /* STRIP_UNDERSCORE */
598 symbol_find_base (name
, strip_underscore
)
600 int strip_underscore
;
602 if (strip_underscore
&& *name
== '_')
605 #ifdef tc_canonicalize_symbol_name
608 size_t len
= strlen (name
) + 1;
610 copy
= (char *) alloca (len
);
611 memcpy (copy
, name
, len
);
612 name
= tc_canonicalize_symbol_name (copy
);
616 if (! symbols_case_sensitive
)
623 name
= copy
= (char *) alloca (strlen (name
) + 1);
625 while ((c
= *orig
++) != '\0')
636 struct local_symbol
*locsym
;
638 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
640 return (symbolS
*) locsym
;
644 return ((symbolS
*) hash_find (sy_hash
, name
));
647 /* Once upon a time, symbols were kept in a singly linked list. At
648 least coff needs to be able to rearrange them from time to time, for
649 which a doubly linked list is much more convenient. Loic did these
650 as macros which seemed dangerous to me so they're now functions.
653 /* Link symbol ADDME after symbol TARGET in the chain. */
656 symbol_append (addme
, target
, rootPP
, lastPP
)
662 if (LOCAL_SYMBOL_CHECK (addme
))
664 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
669 know (*rootPP
== NULL
);
670 know (*lastPP
== NULL
);
671 addme
->sy_next
= NULL
;
672 #ifdef SYMBOLS_NEED_BACKPOINTERS
673 addme
->sy_previous
= NULL
;
678 } /* if the list is empty */
680 if (target
->sy_next
!= NULL
)
682 #ifdef SYMBOLS_NEED_BACKPOINTERS
683 target
->sy_next
->sy_previous
= addme
;
684 #endif /* SYMBOLS_NEED_BACKPOINTERS */
688 know (*lastPP
== target
);
690 } /* if we have a next */
692 addme
->sy_next
= target
->sy_next
;
693 target
->sy_next
= addme
;
695 #ifdef SYMBOLS_NEED_BACKPOINTERS
696 addme
->sy_previous
= target
;
697 #endif /* SYMBOLS_NEED_BACKPOINTERS */
699 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
702 /* Set the chain pointers of SYMBOL to null. */
705 symbol_clear_list_pointers (symbolP
)
708 if (LOCAL_SYMBOL_CHECK (symbolP
))
710 symbolP
->sy_next
= NULL
;
711 #ifdef SYMBOLS_NEED_BACKPOINTERS
712 symbolP
->sy_previous
= NULL
;
716 #ifdef SYMBOLS_NEED_BACKPOINTERS
717 /* Remove SYMBOLP from the list. */
720 symbol_remove (symbolP
, rootPP
, lastPP
)
725 if (LOCAL_SYMBOL_CHECK (symbolP
))
728 if (symbolP
== *rootPP
)
730 *rootPP
= symbolP
->sy_next
;
731 } /* if it was the root */
733 if (symbolP
== *lastPP
)
735 *lastPP
= symbolP
->sy_previous
;
736 } /* if it was the tail */
738 if (symbolP
->sy_next
!= NULL
)
740 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
743 if (symbolP
->sy_previous
!= NULL
)
745 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
748 debug_verify_symchain (*rootPP
, *lastPP
);
751 /* Link symbol ADDME before symbol TARGET in the chain. */
754 symbol_insert (addme
, target
, rootPP
, lastPP
)
758 symbolS
**lastPP ATTRIBUTE_UNUSED
;
760 if (LOCAL_SYMBOL_CHECK (addme
))
762 if (LOCAL_SYMBOL_CHECK (target
))
765 if (target
->sy_previous
!= NULL
)
767 target
->sy_previous
->sy_next
= addme
;
771 know (*rootPP
== target
);
775 addme
->sy_previous
= target
->sy_previous
;
776 target
->sy_previous
= addme
;
777 addme
->sy_next
= target
;
779 debug_verify_symchain (*rootPP
, *lastPP
);
782 #endif /* SYMBOLS_NEED_BACKPOINTERS */
785 verify_symbol_chain (rootP
, lastP
)
789 symbolS
*symbolP
= rootP
;
794 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
797 assert (symbolP
->bsym
!= NULL
);
799 #ifdef SYMBOLS_NEED_BACKPOINTERS
800 assert (symbolP
->sy_next
->sy_previous
== symbolP
);
802 /* Walk the list anyways, to make sure pointers are still good. */
804 #endif /* SYMBOLS_NEED_BACKPOINTERS */
807 assert (lastP
== symbolP
);
811 verify_symbol_chain_2 (sym
)
814 symbolS
*p
= sym
, *n
= sym
;
815 #ifdef SYMBOLS_NEED_BACKPOINTERS
816 while (symbol_previous (p
))
817 p
= symbol_previous (p
);
819 while (symbol_next (n
))
821 verify_symbol_chain (p
, n
);
824 /* Resolve the value of a symbol. This is called during the final
825 pass over the symbol table to resolve any symbols with complex
829 resolve_symbol_value (symp
, finalize
)
838 if (LOCAL_SYMBOL_CHECK (symp
))
840 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
842 if (local_symbol_resolved_p (locsym
))
843 return locsym
->lsy_offset
/ bfd_octets_per_byte (stdoutput
);
845 final_val
= (local_symbol_get_frag (locsym
)->fr_address
846 + locsym
->lsy_offset
) / bfd_octets_per_byte (stdoutput
);
850 locsym
->lsy_offset
= final_val
;
851 local_symbol_mark_resolved (locsym
);
858 if (symp
->sy_resolved
)
860 if (symp
->sy_value
.X_op
== O_constant
)
861 return (valueT
) symp
->sy_value
.X_add_number
;
867 final_seg
= S_GET_SEGMENT (symp
);
869 if (symp
->sy_resolving
)
872 as_bad (_("Symbol definition loop encountered at %s"),
879 symbolS
*add_symbol
, *op_symbol
;
881 segT seg_left
, seg_right
;
884 symp
->sy_resolving
= 1;
886 /* Help out with CSE. */
887 add_symbol
= symp
->sy_value
.X_add_symbol
;
888 op_symbol
= symp
->sy_value
.X_op_symbol
;
889 final_val
= symp
->sy_value
.X_add_number
;
890 op
= symp
->sy_value
.X_op
;
903 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
904 if (final_seg
== expr_section
)
905 final_seg
= absolute_section
;
911 left
= resolve_symbol_value (add_symbol
, finalize
);
914 if (symp
->sy_mri_common
)
916 /* This is a symbol inside an MRI common section. The
917 relocation routines are going to handle it specially.
918 Don't change the value. */
919 resolved
= symbol_resolved_p (add_symbol
);
923 if (finalize
&& final_val
== 0)
925 if (LOCAL_SYMBOL_CHECK (add_symbol
))
926 add_symbol
= local_symbol_convert ((struct local_symbol
*)
928 copy_symbol_attributes (symp
, add_symbol
);
931 /* If we have equated this symbol to an undefined symbol, we
932 keep X_op set to O_symbol, and we don't change
933 X_add_number. This permits the routine which writes out
934 relocation to detect this case, and convert the
935 relocation to be against the symbol to which this symbol
937 if (! S_IS_DEFINED (add_symbol
) || S_IS_COMMON (add_symbol
))
941 S_SET_SEGMENT (symp
, S_GET_SEGMENT (add_symbol
));
942 symp
->sy_value
.X_op
= O_symbol
;
943 symp
->sy_value
.X_add_symbol
= add_symbol
;
944 symp
->sy_value
.X_add_number
= final_val
;
947 resolved
= symbol_resolved_p (add_symbol
);
948 goto exit_dont_set_value
;
952 final_val
+= symp
->sy_frag
->fr_address
+ left
;
953 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
954 final_seg
= S_GET_SEGMENT (add_symbol
);
957 resolved
= symbol_resolved_p (add_symbol
);
963 left
= resolve_symbol_value (add_symbol
, finalize
);
967 else if (op
== O_logical_not
)
972 final_val
+= left
+ symp
->sy_frag
->fr_address
;
973 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
974 final_seg
= absolute_section
;
976 resolved
= symbol_resolved_p (add_symbol
);
984 case O_bit_inclusive_or
:
986 case O_bit_exclusive_or
:
998 left
= resolve_symbol_value (add_symbol
, finalize
);
999 right
= resolve_symbol_value (op_symbol
, finalize
);
1000 seg_left
= S_GET_SEGMENT (add_symbol
);
1001 seg_right
= S_GET_SEGMENT (op_symbol
);
1003 /* Simplify addition or subtraction of a constant by folding the
1004 constant into X_add_number. */
1005 if (op
== O_add
|| op
== O_subtract
)
1007 if (seg_right
== absolute_section
)
1017 else if (seg_left
== absolute_section
&& op
== O_add
)
1021 add_symbol
= op_symbol
;
1028 /* Subtraction is permitted if both operands are in the same
1029 section. Otherwise, both operands must be absolute. We
1030 already handled the case of addition or subtraction of a
1031 constant above. This will probably need to be changed
1032 for an object file format which supports arbitrary
1033 expressions, such as IEEE-695. */
1034 /* Don't emit messages unless we're finalizing the symbol value,
1035 otherwise we may get the same message multiple times. */
1036 if ((seg_left
!= absolute_section
1037 || seg_right
!= absolute_section
)
1038 && (op
!= O_subtract
1039 || seg_left
!= seg_right
1040 || seg_left
== undefined_section
)
1046 if (expr_symbol_where (symp
, &file
, &line
))
1048 if (seg_left
== undefined_section
)
1049 as_bad_where (file
, line
,
1050 _("undefined symbol %s in operation"),
1051 S_GET_NAME (symp
->sy_value
.X_add_symbol
));
1052 if (seg_right
== undefined_section
)
1053 as_bad_where (file
, line
,
1054 _("undefined symbol %s in operation"),
1055 S_GET_NAME (symp
->sy_value
.X_op_symbol
));
1056 if (seg_left
!= undefined_section
1057 && seg_right
!= undefined_section
)
1058 as_bad_where (file
, line
,
1059 _("invalid section for operation"));
1063 if (seg_left
== undefined_section
)
1064 as_bad (_("undefined symbol %s in operation setting %s"),
1065 S_GET_NAME (symp
->sy_value
.X_add_symbol
),
1067 if (seg_right
== undefined_section
)
1068 as_bad (_("undefined symbol %s in operation setting %s"),
1069 S_GET_NAME (symp
->sy_value
.X_op_symbol
),
1071 if (seg_left
!= undefined_section
1072 && seg_right
!= undefined_section
)
1073 as_bad (_("invalid section for operation setting %s"),
1078 /* Check for division by zero. */
1079 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1081 /* If seg_right is not absolute_section, then we've
1082 already issued a warning about using a bad symbol. */
1083 if (seg_right
== absolute_section
&& finalize
)
1088 if (expr_symbol_where (symp
, &file
, &line
))
1089 as_bad_where (file
, line
, _("division by zero"));
1091 as_bad (_("division by zero when setting %s"),
1098 switch (symp
->sy_value
.X_op
)
1100 case O_multiply
: left
*= right
; break;
1101 case O_divide
: left
/= right
; break;
1102 case O_modulus
: left
%= right
; break;
1103 case O_left_shift
: left
<<= right
; break;
1104 case O_right_shift
: left
>>= right
; break;
1105 case O_bit_inclusive_or
: left
|= right
; break;
1106 case O_bit_or_not
: left
|= ~right
; break;
1107 case O_bit_exclusive_or
: left
^= right
; break;
1108 case O_bit_and
: left
&= right
; break;
1109 case O_add
: left
+= right
; break;
1110 case O_subtract
: left
-= right
; break;
1111 case O_eq
: left
= left
== right
? ~ (offsetT
) 0 : 0; break;
1112 case O_ne
: left
= left
!= right
? ~ (offsetT
) 0 : 0; break;
1113 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1114 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1115 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1116 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1117 case O_logical_and
: left
= left
&& right
; break;
1118 case O_logical_or
: left
= left
|| right
; break;
1122 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1123 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1124 final_seg
= absolute_section
;
1125 resolved
= (symbol_resolved_p (add_symbol
)
1126 && symbol_resolved_p (op_symbol
));
1132 /* Give an error (below) if not in expr_section. We don't
1133 want to worry about expr_section symbols, because they
1134 are fictional (they are created as part of expression
1135 resolution), and any problems may not actually mean
1140 symp
->sy_resolving
= 0;
1145 S_SET_VALUE (symp
, final_val
);
1147 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1148 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1149 for a stab symbol, so we use this bad hack. */
1150 if (final_seg
!= S_GET_SEGMENT (symp
))
1152 S_SET_SEGMENT (symp
, final_seg
);
1155 exit_dont_set_value
:
1156 /* Don't worry if we can't resolve an expr_section symbol. */
1160 symp
->sy_resolved
= 1;
1161 else if (S_GET_SEGMENT (symp
) != expr_section
)
1163 as_bad (_("can't resolve value for symbol \"%s\""),
1165 symp
->sy_resolved
= 1;
1172 #ifdef BFD_ASSEMBLER
1174 static void resolve_local_symbol
PARAMS ((const char *, PTR
));
1176 /* A static function passed to hash_traverse. */
1179 resolve_local_symbol (key
, value
)
1180 const char *key ATTRIBUTE_UNUSED
;
1184 resolve_symbol_value (value
, 1);
1189 /* Resolve all local symbols. */
1192 resolve_local_symbol_values ()
1194 #ifdef BFD_ASSEMBLER
1195 hash_traverse (local_hash
, resolve_local_symbol
);
1199 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1200 They are *really* local. That is, they go out of scope whenever we see a
1201 label that isn't local. Also, like fb labels, there can be multiple
1202 instances of a dollar label. Therefor, we name encode each instance with
1203 the instance number, keep a list of defined symbols separate from the real
1204 symbol table, and we treat these buggers as a sparse array. */
1206 static long *dollar_labels
;
1207 static long *dollar_label_instances
;
1208 static char *dollar_label_defines
;
1209 static unsigned long dollar_label_count
;
1210 static unsigned long dollar_label_max
;
1213 dollar_label_defined (label
)
1218 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1220 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1222 return dollar_label_defines
[i
- dollar_labels
];
1224 /* If we get here, label isn't defined. */
1229 dollar_label_instance (label
)
1234 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1236 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1238 return (dollar_label_instances
[i
- dollar_labels
]);
1240 /* If we get here, we haven't seen the label before.
1241 Therefore its instance count is zero. */
1246 dollar_label_clear ()
1248 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1251 #define DOLLAR_LABEL_BUMP_BY 10
1254 define_dollar_label (label
)
1259 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1262 ++dollar_label_instances
[i
- dollar_labels
];
1263 dollar_label_defines
[i
- dollar_labels
] = 1;
1267 /* If we get to here, we don't have label listed yet. */
1269 if (dollar_labels
== NULL
)
1271 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1272 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
1273 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
1274 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1275 dollar_label_count
= 0;
1277 else if (dollar_label_count
== dollar_label_max
)
1279 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1280 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
1281 dollar_label_max
* sizeof (long));
1282 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
1283 dollar_label_max
* sizeof (long));
1284 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
1285 } /* if we needed to grow */
1287 dollar_labels
[dollar_label_count
] = label
;
1288 dollar_label_instances
[dollar_label_count
] = 1;
1289 dollar_label_defines
[dollar_label_count
] = 1;
1290 ++dollar_label_count
;
1293 /* Caller must copy returned name: we re-use the area for the next name.
1295 The mth occurence of label n: is turned into the symbol "Ln^Am"
1296 where n is the label number and m is the instance number. "L" makes
1297 it a label discarded unless debugging and "^A"('\1') ensures no
1298 ordinary symbol SHOULD get the same name as a local label
1299 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1301 fb labels get the same treatment, except that ^B is used in place
1304 char * /* Return local label name. */
1305 dollar_label_name (n
, augend
)
1306 register long n
; /* we just saw "n$:" : n a number. */
1307 register int augend
; /* 0 for current instance, 1 for new instance. */
1310 /* Returned to caller, then copied. Used for created names ("4f"). */
1311 static char symbol_name_build
[24];
1314 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1317 know (augend
== 0 || augend
== 1);
1318 p
= symbol_name_build
;
1319 #ifdef LOCAL_LABEL_PREFIX
1320 *p
++ = LOCAL_LABEL_PREFIX
;
1324 /* Next code just does sprintf( {}, "%d", n); */
1326 q
= symbol_name_temporary
;
1327 for (*q
++ = 0, i
= n
; i
; ++q
)
1332 while ((*p
= *--q
) != '\0')
1335 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1337 /* Instance number. */
1338 q
= symbol_name_temporary
;
1339 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1344 while ((*p
++ = *--q
) != '\0');;
1346 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1347 return symbol_name_build
;
1350 /* Sombody else's idea of local labels. They are made by "n:" where n
1351 is any decimal digit. Refer to them with
1352 "nb" for previous (backward) n:
1353 or "nf" for next (forward) n:.
1355 We do a little better and let n be any number, not just a single digit, but
1356 since the other guy's assembler only does ten, we treat the first ten
1359 Like someone else's assembler, we have one set of local label counters for
1360 entire assembly, not one set per (sub)segment like in most assemblers. This
1361 implies that one can refer to a label in another segment, and indeed some
1362 crufty compilers have done just that.
1364 Since there could be a LOT of these things, treat them as a sparse
1367 #define FB_LABEL_SPECIAL (10)
1369 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1370 static long *fb_labels
;
1371 static long *fb_label_instances
;
1372 static long fb_label_count
;
1373 static long fb_label_max
;
1375 /* This must be more than FB_LABEL_SPECIAL. */
1376 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1381 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1384 /* Add one to the instance number of this fb label. */
1387 fb_label_instance_inc (label
)
1392 if (label
< FB_LABEL_SPECIAL
)
1394 ++fb_low_counter
[label
];
1398 if (fb_labels
!= NULL
)
1400 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1401 i
< fb_labels
+ fb_label_count
; ++i
)
1405 ++fb_label_instances
[i
- fb_labels
];
1407 } /* if we find it */
1408 } /* for each existing label */
1411 /* If we get to here, we don't have label listed yet. */
1413 if (fb_labels
== NULL
)
1415 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1416 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
1417 fb_label_max
= FB_LABEL_BUMP_BY
;
1418 fb_label_count
= FB_LABEL_SPECIAL
;
1421 else if (fb_label_count
== fb_label_max
)
1423 fb_label_max
+= FB_LABEL_BUMP_BY
;
1424 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
1425 fb_label_max
* sizeof (long));
1426 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
1427 fb_label_max
* sizeof (long));
1428 } /* if we needed to grow */
1430 fb_labels
[fb_label_count
] = label
;
1431 fb_label_instances
[fb_label_count
] = 1;
1436 fb_label_instance (label
)
1441 if (label
< FB_LABEL_SPECIAL
)
1443 return (fb_low_counter
[label
]);
1446 if (fb_labels
!= NULL
)
1448 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1449 i
< fb_labels
+ fb_label_count
; ++i
)
1453 return (fb_label_instances
[i
- fb_labels
]);
1454 } /* if we find it */
1455 } /* for each existing label */
1458 /* We didn't find the label, so this must be a reference to the
1463 /* Caller must copy returned name: we re-use the area for the next name.
1465 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1466 where n is the label number and m is the instance number. "L" makes
1467 it a label discarded unless debugging and "^B"('\2') ensures no
1468 ordinary symbol SHOULD get the same name as a local label
1469 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1471 dollar labels get the same treatment, except that ^A is used in
1474 char * /* Return local label name. */
1475 fb_label_name (n
, augend
)
1476 long n
; /* We just saw "n:", "nf" or "nb" : n a number. */
1477 long augend
; /* 0 for nb, 1 for n:, nf. */
1480 /* Returned to caller, then copied. Used for created names ("4f"). */
1481 static char symbol_name_build
[24];
1484 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1487 know (augend
== 0 || augend
== 1);
1488 p
= symbol_name_build
;
1489 #ifdef LOCAL_LABEL_PREFIX
1490 *p
++ = LOCAL_LABEL_PREFIX
;
1494 /* Next code just does sprintf( {}, "%d", n); */
1496 q
= symbol_name_temporary
;
1497 for (*q
++ = 0, i
= n
; i
; ++q
)
1502 while ((*p
= *--q
) != '\0')
1505 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
1507 /* Instance number. */
1508 q
= symbol_name_temporary
;
1509 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1514 while ((*p
++ = *--q
) != '\0');;
1516 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1517 return (symbol_name_build
);
1520 /* Decode name that may have been generated by foo_label_name() above.
1521 If the name wasn't generated by foo_label_name(), then return it
1522 unaltered. This is used for error messages. */
1525 decode_local_label_name (s
)
1529 char *symbol_decode
;
1531 int instance_number
;
1533 const char *message_format
;
1536 #ifdef LOCAL_LABEL_PREFIX
1537 if (s
[index
] == LOCAL_LABEL_PREFIX
)
1541 if (s
[index
] != 'L')
1544 for (label_number
= 0, p
= s
+ index
+ 1; isdigit ((unsigned char) *p
); ++p
)
1545 label_number
= (10 * label_number
) + *p
- '0';
1547 if (*p
== DOLLAR_LABEL_CHAR
)
1549 else if (*p
== LOCAL_LABEL_CHAR
)
1554 for (instance_number
= 0, p
++; isdigit ((unsigned char) *p
); ++p
)
1555 instance_number
= (10 * instance_number
) + *p
- '0';
1557 message_format
= _("\"%d\" (instance number %d of a %s label)");
1558 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1559 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
1561 return symbol_decode
;
1564 /* Get the value of a symbol. */
1570 #ifdef BFD_ASSEMBLER
1571 if (LOCAL_SYMBOL_CHECK (s
))
1572 return ((struct local_symbol
*) s
)->lsy_offset
;
1575 if (!s
->sy_resolved
&& s
->sy_value
.X_op
!= O_constant
)
1576 resolve_symbol_value (s
, 1);
1577 if (s
->sy_value
.X_op
!= O_constant
)
1579 static symbolS
*recur
;
1581 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1582 may call S_GET_VALUE. We use a static symbol to avoid the
1583 immediate recursion. */
1585 return (valueT
) s
->sy_value
.X_add_number
;
1587 if (! s
->sy_resolved
1588 || s
->sy_value
.X_op
!= O_symbol
1589 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
1590 as_bad (_("Attempt to get value of unresolved symbol %s"),
1594 return (valueT
) s
->sy_value
.X_add_number
;
1597 /* Set the value of a symbol. */
1600 S_SET_VALUE (s
, val
)
1604 #ifdef BFD_ASSEMBLER
1605 if (LOCAL_SYMBOL_CHECK (s
))
1607 ((struct local_symbol
*) s
)->lsy_offset
= val
;
1612 s
->sy_value
.X_op
= O_constant
;
1613 s
->sy_value
.X_add_number
= (offsetT
) val
;
1614 s
->sy_value
.X_unsigned
= 0;
1618 copy_symbol_attributes (dest
, src
)
1619 symbolS
*dest
, *src
;
1621 if (LOCAL_SYMBOL_CHECK (dest
))
1622 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
1623 if (LOCAL_SYMBOL_CHECK (src
))
1624 src
= local_symbol_convert ((struct local_symbol
*) src
);
1626 #ifdef BFD_ASSEMBLER
1627 /* In an expression, transfer the settings of these flags.
1628 The user can override later, of course. */
1629 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1630 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
1633 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1634 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
1638 #ifdef BFD_ASSEMBLER
1646 if (LOCAL_SYMBOL_CHECK (s
))
1649 flags
= s
->bsym
->flags
;
1651 return (flags
& BSF_FUNCTION
) != 0;
1660 if (LOCAL_SYMBOL_CHECK (s
))
1663 flags
= s
->bsym
->flags
;
1666 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1669 return (flags
& BSF_GLOBAL
) != 0;
1676 if (LOCAL_SYMBOL_CHECK (s
))
1678 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
1685 if (LOCAL_SYMBOL_CHECK (s
))
1687 return bfd_is_com_section (s
->bsym
->section
);
1694 if (LOCAL_SYMBOL_CHECK (s
))
1695 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
1696 return s
->bsym
->section
!= undefined_section
;
1703 if (LOCAL_SYMBOL_CHECK (s
))
1705 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1717 if (LOCAL_SYMBOL_CHECK (s
))
1720 flags
= s
->bsym
->flags
;
1723 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
1726 if (bfd_get_section (s
->bsym
) == reg_section
)
1729 if (flag_strip_local_absolute
1730 && (flags
& BSF_GLOBAL
) == 0
1731 && bfd_get_section (s
->bsym
) == absolute_section
)
1734 name
= S_GET_NAME (s
);
1735 return (name
!= NULL
1737 && (strchr (name
, DOLLAR_LABEL_CHAR
)
1738 || strchr (name
, LOCAL_LABEL_CHAR
)
1739 || (! flag_keep_locals
1740 && (bfd_is_local_label (stdoutput
, s
->bsym
)
1743 && name
[1] == '?')))));
1750 return S_IS_EXTERNAL (s
);
1757 return S_GET_NAME (s
) == 0;
1764 if (LOCAL_SYMBOL_CHECK (s
))
1765 return ((struct local_symbol
*) s
)->lsy_name
;
1766 return s
->bsym
->name
;
1773 if (LOCAL_SYMBOL_CHECK (s
))
1774 return ((struct local_symbol
*) s
)->lsy_section
;
1775 return s
->bsym
->section
;
1779 S_SET_SEGMENT (s
, seg
)
1783 /* Don't reassign section symbols. The direct reason is to prevent seg
1784 faults assigning back to const global symbols such as *ABS*, but it
1785 shouldn't happen anyway. */
1787 if (LOCAL_SYMBOL_CHECK (s
))
1789 if (seg
== reg_section
)
1790 s
= local_symbol_convert ((struct local_symbol
*) s
);
1793 ((struct local_symbol
*) s
)->lsy_section
= seg
;
1798 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
1800 if (s
->bsym
->section
!= seg
)
1804 s
->bsym
->section
= seg
;
1811 if (LOCAL_SYMBOL_CHECK (s
))
1812 s
= local_symbol_convert ((struct local_symbol
*) s
);
1813 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1815 /* Let .weak override .global. */
1818 s
->bsym
->flags
|= BSF_GLOBAL
;
1819 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
1823 S_CLEAR_EXTERNAL (s
)
1826 if (LOCAL_SYMBOL_CHECK (s
))
1828 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
1830 /* Let .weak override. */
1833 s
->bsym
->flags
|= BSF_LOCAL
;
1834 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
1841 if (LOCAL_SYMBOL_CHECK (s
))
1842 s
= local_symbol_convert ((struct local_symbol
*) s
);
1843 s
->bsym
->flags
|= BSF_WEAK
;
1844 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
1848 S_SET_NAME (s
, name
)
1852 if (LOCAL_SYMBOL_CHECK (s
))
1854 ((struct local_symbol
*) s
)->lsy_name
= name
;
1857 s
->bsym
->name
= name
;
1859 #endif /* BFD_ASSEMBLER */
1861 #ifdef SYMBOLS_NEED_BACKPOINTERS
1863 /* Return the previous symbol in a chain. */
1869 if (LOCAL_SYMBOL_CHECK (s
))
1871 return s
->sy_previous
;
1874 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1876 /* Return the next symbol in a chain. */
1882 if (LOCAL_SYMBOL_CHECK (s
))
1887 /* Return a pointer to the value of a symbol as an expression. */
1890 symbol_get_value_expression (s
)
1893 if (LOCAL_SYMBOL_CHECK (s
))
1894 s
= local_symbol_convert ((struct local_symbol
*) s
);
1895 return &s
->sy_value
;
1898 /* Set the value of a symbol to an expression. */
1901 symbol_set_value_expression (s
, exp
)
1903 const expressionS
*exp
;
1905 if (LOCAL_SYMBOL_CHECK (s
))
1906 s
= local_symbol_convert ((struct local_symbol
*) s
);
1910 /* Set the frag of a symbol. */
1913 symbol_set_frag (s
, f
)
1917 #ifdef BFD_ASSEMBLER
1918 if (LOCAL_SYMBOL_CHECK (s
))
1920 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
1927 /* Return the frag of a symbol. */
1933 #ifdef BFD_ASSEMBLER
1934 if (LOCAL_SYMBOL_CHECK (s
))
1935 return local_symbol_get_frag ((struct local_symbol
*) s
);
1940 /* Mark a symbol as having been used. */
1943 symbol_mark_used (s
)
1946 if (LOCAL_SYMBOL_CHECK (s
))
1951 /* Clear the mark of whether a symbol has been used. */
1954 symbol_clear_used (s
)
1957 if (LOCAL_SYMBOL_CHECK (s
))
1958 s
= local_symbol_convert ((struct local_symbol
*) s
);
1962 /* Return whether a symbol has been used. */
1968 if (LOCAL_SYMBOL_CHECK (s
))
1973 /* Mark a symbol as having been used in a reloc. */
1976 symbol_mark_used_in_reloc (s
)
1979 if (LOCAL_SYMBOL_CHECK (s
))
1980 s
= local_symbol_convert ((struct local_symbol
*) s
);
1981 s
->sy_used_in_reloc
= 1;
1984 /* Clear the mark of whether a symbol has been used in a reloc. */
1987 symbol_clear_used_in_reloc (s
)
1990 if (LOCAL_SYMBOL_CHECK (s
))
1992 s
->sy_used_in_reloc
= 0;
1995 /* Return whether a symbol has been used in a reloc. */
1998 symbol_used_in_reloc_p (s
)
2001 if (LOCAL_SYMBOL_CHECK (s
))
2003 return s
->sy_used_in_reloc
;
2006 /* Mark a symbol as an MRI common symbol. */
2009 symbol_mark_mri_common (s
)
2012 if (LOCAL_SYMBOL_CHECK (s
))
2013 s
= local_symbol_convert ((struct local_symbol
*) s
);
2014 s
->sy_mri_common
= 1;
2017 /* Clear the mark of whether a symbol is an MRI common symbol. */
2020 symbol_clear_mri_common (s
)
2023 if (LOCAL_SYMBOL_CHECK (s
))
2025 s
->sy_mri_common
= 0;
2028 /* Return whether a symbol is an MRI common symbol. */
2031 symbol_mri_common_p (s
)
2034 if (LOCAL_SYMBOL_CHECK (s
))
2036 return s
->sy_mri_common
;
2039 /* Mark a symbol as having been written. */
2042 symbol_mark_written (s
)
2045 if (LOCAL_SYMBOL_CHECK (s
))
2050 /* Clear the mark of whether a symbol has been written. */
2053 symbol_clear_written (s
)
2056 if (LOCAL_SYMBOL_CHECK (s
))
2061 /* Return whether a symbol has been written. */
2064 symbol_written_p (s
)
2067 if (LOCAL_SYMBOL_CHECK (s
))
2072 /* Mark a symbol has having been resolved. */
2075 symbol_mark_resolved (s
)
2078 #ifdef BFD_ASSEMBLER
2079 if (LOCAL_SYMBOL_CHECK (s
))
2081 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2088 /* Return whether a symbol has been resolved. */
2091 symbol_resolved_p (s
)
2094 #ifdef BFD_ASSEMBLER
2095 if (LOCAL_SYMBOL_CHECK (s
))
2096 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2098 return s
->sy_resolved
;
2101 /* Return whether a symbol is a section symbol. */
2104 symbol_section_p (s
)
2105 symbolS
*s ATTRIBUTE_UNUSED
;
2107 if (LOCAL_SYMBOL_CHECK (s
))
2109 #ifdef BFD_ASSEMBLER
2110 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2117 /* Return whether a symbol is equated to another symbol. */
2120 symbol_equated_p (s
)
2123 if (LOCAL_SYMBOL_CHECK (s
))
2125 return s
->sy_value
.X_op
== O_symbol
;
2128 /* Return whether a symbol has a constant value. */
2131 symbol_constant_p (s
)
2134 if (LOCAL_SYMBOL_CHECK (s
))
2136 return s
->sy_value
.X_op
== O_constant
;
2139 #ifdef BFD_ASSEMBLER
2141 /* Return the BFD symbol for a symbol. */
2144 symbol_get_bfdsym (s
)
2147 if (LOCAL_SYMBOL_CHECK (s
))
2148 s
= local_symbol_convert ((struct local_symbol
*) s
);
2152 /* Set the BFD symbol for a symbol. */
2155 symbol_set_bfdsym (s
, bsym
)
2159 if (LOCAL_SYMBOL_CHECK (s
))
2160 s
= local_symbol_convert ((struct local_symbol
*) s
);
2164 #endif /* BFD_ASSEMBLER */
2166 #ifdef OBJ_SYMFIELD_TYPE
2168 /* Get a pointer to the object format information for a symbol. */
2174 if (LOCAL_SYMBOL_CHECK (s
))
2175 s
= local_symbol_convert ((struct local_symbol
*) s
);
2179 /* Set the object format information for a symbol. */
2182 symbol_set_obj (s
, o
)
2184 OBJ_SYMFIELD_TYPE
*o
;
2186 if (LOCAL_SYMBOL_CHECK (s
))
2187 s
= local_symbol_convert ((struct local_symbol
*) s
);
2191 #endif /* OBJ_SYMFIELD_TYPE */
2193 #ifdef TC_SYMFIELD_TYPE
2195 /* Get a pointer to the processor information for a symbol. */
2201 if (LOCAL_SYMBOL_CHECK (s
))
2202 s
= local_symbol_convert ((struct local_symbol
*) s
);
2206 /* Set the processor information for a symbol. */
2209 symbol_set_tc (s
, o
)
2211 TC_SYMFIELD_TYPE
*o
;
2213 if (LOCAL_SYMBOL_CHECK (s
))
2214 s
= local_symbol_convert ((struct local_symbol
*) s
);
2218 #endif /* TC_SYMFIELD_TYPE */
2223 symbol_lastP
= NULL
;
2224 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2225 sy_hash
= hash_new ();
2226 #ifdef BFD_ASSEMBLER
2227 local_hash
= hash_new ();
2230 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2231 #ifdef BFD_ASSEMBLER
2232 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2233 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
2236 /* Can't initialise a union. Sigh. */
2237 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
2239 abs_symbol
.sy_value
.X_op
= O_constant
;
2240 abs_symbol
.sy_frag
= &zero_address_frag
;
2242 if (LOCAL_LABELS_FB
)
2248 /* Maximum indent level.
2249 Available for modification inside a gdb session. */
2250 int max_indent_level
= 8;
2257 printf ("%*s", indent_level
* 4, "");
2263 print_symbol_value_1 (file
, sym
)
2267 const char *name
= S_GET_NAME (sym
);
2268 if (!name
|| !name
[0])
2270 fprintf (file
, "sym %lx %s", (unsigned long) sym
, name
);
2272 if (LOCAL_SYMBOL_CHECK (sym
))
2274 #ifdef BFD_ASSEMBLER
2275 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
2276 if (local_symbol_get_frag (locsym
) != &zero_address_frag
2277 && local_symbol_get_frag (locsym
) != NULL
)
2278 fprintf (file
, " frag %lx", (long) local_symbol_get_frag (locsym
));
2279 if (local_symbol_resolved_p (locsym
))
2280 fprintf (file
, " resolved");
2281 fprintf (file
, " local");
2286 if (sym
->sy_frag
!= &zero_address_frag
)
2287 fprintf (file
, " frag %lx", (long) sym
->sy_frag
);
2289 fprintf (file
, " written");
2290 if (sym
->sy_resolved
)
2291 fprintf (file
, " resolved");
2292 else if (sym
->sy_resolving
)
2293 fprintf (file
, " resolving");
2294 if (sym
->sy_used_in_reloc
)
2295 fprintf (file
, " used-in-reloc");
2297 fprintf (file
, " used");
2298 if (S_IS_LOCAL (sym
))
2299 fprintf (file
, " local");
2300 if (S_IS_EXTERN (sym
))
2301 fprintf (file
, " extern");
2302 if (S_IS_DEBUG (sym
))
2303 fprintf (file
, " debug");
2304 if (S_IS_DEFINED (sym
))
2305 fprintf (file
, " defined");
2307 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
2308 if (symbol_resolved_p (sym
))
2310 segT s
= S_GET_SEGMENT (sym
);
2312 if (s
!= undefined_section
2313 && s
!= expr_section
)
2314 fprintf (file
, " %lx", (long) S_GET_VALUE (sym
));
2316 else if (indent_level
< max_indent_level
2317 && S_GET_SEGMENT (sym
) != undefined_section
)
2320 fprintf (file
, "\n%*s<", indent_level
* 4, "");
2321 #ifdef BFD_ASSEMBLER
2322 if (LOCAL_SYMBOL_CHECK (sym
))
2323 fprintf (file
, "constant %lx",
2324 (long) ((struct local_symbol
*) sym
)->lsy_offset
);
2327 print_expr_1 (file
, &sym
->sy_value
);
2328 fprintf (file
, ">");
2335 print_symbol_value (sym
)
2339 print_symbol_value_1 (stderr
, sym
);
2340 fprintf (stderr
, "\n");
2344 print_binary (file
, name
, exp
)
2350 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
2351 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2352 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2353 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2354 fprintf (file
, ">");
2359 print_expr_1 (file
, exp
)
2363 fprintf (file
, "expr %lx ", (long) exp
);
2367 fprintf (file
, "illegal");
2370 fprintf (file
, "absent");
2373 fprintf (file
, "constant %lx", (long) exp
->X_add_number
);
2377 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
2378 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2379 fprintf (file
, ">");
2381 if (exp
->X_add_number
)
2382 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
2383 (long) exp
->X_add_number
);
2387 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
2390 fprintf (file
, "big");
2393 fprintf (file
, "uminus -<");
2395 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2396 fprintf (file
, ">");
2397 goto maybe_print_addnum
;
2399 fprintf (file
, "bit_not");
2402 print_binary (file
, "multiply", exp
);
2405 print_binary (file
, "divide", exp
);
2408 print_binary (file
, "modulus", exp
);
2411 print_binary (file
, "lshift", exp
);
2414 print_binary (file
, "rshift", exp
);
2416 case O_bit_inclusive_or
:
2417 print_binary (file
, "bit_ior", exp
);
2419 case O_bit_exclusive_or
:
2420 print_binary (file
, "bit_xor", exp
);
2423 print_binary (file
, "bit_and", exp
);
2426 print_binary (file
, "eq", exp
);
2429 print_binary (file
, "ne", exp
);
2432 print_binary (file
, "lt", exp
);
2435 print_binary (file
, "le", exp
);
2438 print_binary (file
, "ge", exp
);
2441 print_binary (file
, "gt", exp
);
2444 print_binary (file
, "logical_and", exp
);
2447 print_binary (file
, "logical_or", exp
);
2451 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
2452 print_symbol_value_1 (file
, exp
->X_add_symbol
);
2453 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
2454 print_symbol_value_1 (file
, exp
->X_op_symbol
);
2455 fprintf (file
, ">");
2456 goto maybe_print_addnum
;
2459 fprintf (file
, "subtract\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
;
2466 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
2476 print_expr_1 (stderr
, exp
);
2477 fprintf (stderr
, "\n");
2481 symbol_print_statistics (file
)
2484 hash_print_statistics (file
, "symbol table", sy_hash
);
2485 #ifdef BFD_ASSEMBLER
2486 hash_print_statistics (file
, "mini local symbol table", local_hash
);
2487 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
2488 local_symbol_count
, local_symbol_conversion_count
);