1 /* symbols.c -symbol table-
2 Copyright (C) 1987-2020 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* #define DEBUG_SYMS / * to debug symbol list maintenance. */
24 #include "safe-ctype.h"
25 #include "obstack.h" /* For "symbols.h" */
31 /* Whether the symbol is a local_symbol. */
32 unsigned int sy_local_symbol
: 1;
34 /* Weather symbol has been written. */
35 unsigned int sy_written
: 1;
37 /* Whether symbol value has been completely resolved (used during
38 final pass over symbol table). */
39 unsigned int sy_resolved
: 1;
41 /* Whether the symbol value is currently being resolved (used to
42 detect loops in symbol dependencies). */
43 unsigned int sy_resolving
: 1;
45 /* Whether the symbol value is used in a reloc. This is used to
46 ensure that symbols used in relocs are written out, even if they
47 are local and would otherwise not be. */
48 unsigned int sy_used_in_reloc
: 1;
50 /* Whether the symbol is used as an operand or in an expression.
51 NOTE: Not all the backends keep this information accurate;
52 backends which use this bit are responsible for setting it when
53 a symbol is used in backend routines. */
54 unsigned int sy_used
: 1;
56 /* Whether the symbol can be re-defined. */
57 unsigned int sy_volatile
: 1;
59 /* Whether the symbol is a forward reference. */
60 unsigned int sy_forward_ref
: 1;
62 /* This is set if the symbol is defined in an MRI common section.
63 We handle such sections as single common symbols, so symbols
64 defined within them must be treated specially by the relocation
66 unsigned int sy_mri_common
: 1;
68 /* This is set if the symbol is set with a .weakref directive. */
69 unsigned int sy_weakrefr
: 1;
71 /* This is set when the symbol is referenced as part of a .weakref
72 directive, but only if the symbol was not in the symbol table
73 before. It is cleared as soon as any direct reference to the
75 unsigned int sy_weakrefd
: 1;
78 /* The information we keep for a symbol. Note that the symbol table
79 holds pointers both to this and to local_symbol structures. See
85 struct symbol_flags sy_flags
;
90 /* The value of the symbol. */
93 /* Forwards and (optionally) backwards chain pointers. */
94 struct symbol
*sy_next
;
95 struct symbol
*sy_previous
;
97 /* Pointer to the frag this symbol is attached to, if any.
101 #ifdef OBJ_SYMFIELD_TYPE
102 OBJ_SYMFIELD_TYPE sy_obj
;
105 #ifdef TC_SYMFIELD_TYPE
106 TC_SYMFIELD_TYPE sy_tc
;
109 #ifdef TARGET_SYMBOL_FIELDS
114 /* A pointer in the symbol may point to either a complete symbol
115 (struct symbol above) or to a local symbol (struct local_symbol
116 defined here). The symbol code can detect the case by examining
117 the first field which is present in both structs.
119 We do this because we ordinarily only need a small amount of
120 information for a local symbol. The symbol table takes up a lot of
121 space, and storing less information for a local symbol can make a
122 big difference in assembler memory usage when assembling a large
127 /* Symbol flags. Only sy_local_symbol and sy_resolved are relevant. */
128 struct symbol_flags lsy_flags
;
130 /* The symbol section. This also serves as a flag. If this is
131 reg_section, then this symbol has been converted into a regular
132 symbol, and lsy_sym points to it. */
135 /* The symbol name. */
136 const char *lsy_name
;
138 /* The symbol frag or the real symbol, depending upon the value in
146 /* The value of the symbol. */
149 #ifdef TC_LOCAL_SYMFIELD_TYPE
150 TC_LOCAL_SYMFIELD_TYPE lsy_tc
;
156 const char *symbol_name
;
161 typedef struct symbol_entry symbol_entry_t
;
163 /* Hash function for a symbol_entry. */
166 hash_symbol_entry (const void *e
)
168 symbol_entry_t
*entry
= (symbol_entry_t
*) e
;
169 if (entry
->hash
== 0)
170 entry
->hash
= htab_hash_string (entry
->symbol_name
);
175 /* Equality function for a symbol_entry. */
178 eq_symbol_entry (const void *a
, const void *b
)
180 const symbol_entry_t
*ea
= (const symbol_entry_t
*) a
;
181 const symbol_entry_t
*eb
= (const symbol_entry_t
*) b
;
183 return strcmp (ea
->symbol_name
, eb
->symbol_name
) == 0;
186 static symbol_entry_t
*
187 symbol_entry_alloc (const char *symbol_name
, void *symbol
)
189 symbol_entry_t
*entry
= XNEW (symbol_entry_t
);
190 entry
->symbol_name
= symbol_name
;
192 entry
->symbol
= symbol
;
197 symbol_entry_find (htab_t table
, const char *symbol_name
)
199 symbol_entry_t needle
= { symbol_name
, 0, NULL
};
200 symbol_entry_t
*entry
= htab_find (table
, &needle
);
201 return entry
!= NULL
? entry
->symbol
: NULL
;
205 #define local_symbol_converted_p(l) ((l)->lsy_section == reg_section)
206 #define local_symbol_mark_converted(l) ((l)->lsy_section = reg_section)
207 #define local_symbol_resolved_p(l) ((l)->lsy_flags.sy_resolved)
208 #define local_symbol_mark_resolved(l) ((l)->lsy_flags.sy_resolved = 1)
209 #define local_symbol_get_frag(l) ((l)->u.lsy_frag)
210 #define local_symbol_set_frag(l, f) ((l)->u.lsy_frag = (f))
211 #define local_symbol_get_real_symbol(l) ((l)->u.lsy_sym)
212 #define local_symbol_set_real_symbol(l, s) ((l)->u.lsy_sym = (s))
214 /* This is non-zero if symbols are case sensitive, which is the
216 int symbols_case_sensitive
= 1;
218 #ifndef WORKING_DOT_WORD
219 extern int new_broken_words
;
222 /* symbol-name => struct symbol pointer */
223 static htab_t sy_hash
;
225 /* Table of local symbols. */
226 static htab_t local_hash
;
228 /* Below are commented in "symbols.h". */
229 symbolS
*symbol_rootP
;
230 symbolS
*symbol_lastP
;
235 #define debug_verify_symchain verify_symbol_chain
237 #define debug_verify_symchain(root, last) ((void) 0)
240 #define DOLLAR_LABEL_CHAR '\001'
241 #define LOCAL_LABEL_CHAR '\002'
243 #ifndef TC_LABEL_IS_LOCAL
244 #define TC_LABEL_IS_LOCAL(name) 0
247 struct obstack notes
;
249 /* The name of an external symbol which is
250 used to make weak PE symbol names unique. */
251 const char * an_external_name
;
254 static const char *save_symbol_name (const char *);
255 static void fb_label_init (void);
256 static long dollar_label_instance (long);
257 static long fb_label_instance (long);
259 static void print_binary (FILE *, const char *, expressionS
*);
261 /* Return a pointer to a new symbol. Die if we can't make a new
262 symbol. Fill in the symbol's values. Add symbol to end of symbol
265 This function should be called in the general case of creating a
266 symbol. However, if the output file symbol table has already been
267 set, and you are certain that this symbol won't be wanted in the
268 output file, you can call symbol_create. */
271 symbol_new (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
273 symbolS
*symbolP
= symbol_create (name
, segment
, frag
, valu
);
275 /* Link to end of symbol chain. */
277 extern int symbol_table_frozen
;
278 if (symbol_table_frozen
)
281 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
286 /* Save a symbol name on a permanent obstack, and convert it according
287 to the object file format. */
290 save_symbol_name (const char *name
)
295 gas_assert (name
!= NULL
);
296 name_length
= strlen (name
) + 1; /* +1 for \0. */
297 obstack_grow (¬es
, name
, name_length
);
298 ret
= (char *) obstack_finish (¬es
);
300 #ifdef tc_canonicalize_symbol_name
301 ret
= tc_canonicalize_symbol_name (ret
);
304 if (! symbols_case_sensitive
)
308 for (s
= ret
; *s
!= '\0'; s
++)
315 /* Create a symbol. NAME is copied, the caller can destroy/modify. */
318 symbol_create (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
320 const char *preserved_copy_of_name
;
323 preserved_copy_of_name
= save_symbol_name (name
);
325 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
327 /* symbol must be born in some fixed state. This seems as good as any. */
328 memset (symbolP
, 0, sizeof (symbolS
));
330 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
331 if (symbolP
->bsym
== NULL
)
332 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
333 S_SET_NAME (symbolP
, preserved_copy_of_name
);
335 S_SET_SEGMENT (symbolP
, segment
);
336 S_SET_VALUE (symbolP
, valu
);
337 symbol_clear_list_pointers (symbolP
);
339 symbolP
->sy_frag
= frag
;
341 obj_symbol_new_hook (symbolP
);
343 #ifdef tc_symbol_new_hook
344 tc_symbol_new_hook (symbolP
);
351 /* Local symbol support. If we can get away with it, we keep only a
352 small amount of information for local symbols. */
354 static symbolS
*local_symbol_convert (struct local_symbol
*);
356 /* Used for statistics. */
358 static unsigned long local_symbol_count
;
359 static unsigned long local_symbol_conversion_count
;
361 /* This macro is called with a symbol argument passed by reference.
362 It returns whether this is a local symbol. If necessary, it
363 changes its argument to the real symbol. */
365 #define LOCAL_SYMBOL_CHECK(s) \
366 (s->sy_flags.sy_local_symbol \
367 ? (local_symbol_converted_p ((struct local_symbol *) s) \
368 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
373 /* Create a local symbol and insert it into the local hash table. */
375 struct local_symbol
*
376 local_symbol_make (const char *name
, segT section
, fragS
*frag
, valueT val
)
378 const char *name_copy
;
379 struct local_symbol
*ret
;
380 struct symbol_flags flags
= { .sy_local_symbol
= 1, .sy_resolved
= 0 };
382 ++local_symbol_count
;
384 name_copy
= save_symbol_name (name
);
386 ret
= (struct local_symbol
*) obstack_alloc (¬es
, sizeof *ret
);
387 ret
->lsy_flags
= flags
;
388 ret
->lsy_name
= name_copy
;
389 ret
->lsy_section
= section
;
390 local_symbol_set_frag (ret
, frag
);
391 ret
->lsy_value
= val
;
393 htab_insert (local_hash
, symbol_entry_alloc (name_copy
, ret
));
398 /* Convert a local symbol into a real symbol. Note that we do not
399 reclaim the space used by the local symbol. */
402 local_symbol_convert (struct local_symbol
*locsym
)
406 gas_assert (locsym
->lsy_flags
.sy_local_symbol
);
407 if (local_symbol_converted_p (locsym
))
408 return local_symbol_get_real_symbol (locsym
);
410 ++local_symbol_conversion_count
;
412 ret
= symbol_new (locsym
->lsy_name
, locsym
->lsy_section
,
413 local_symbol_get_frag (locsym
), locsym
->lsy_value
);
415 if (local_symbol_resolved_p (locsym
))
416 ret
->sy_flags
.sy_resolved
= 1;
418 /* Local symbols are always either defined or used. */
419 ret
->sy_flags
.sy_used
= 1;
421 #ifdef TC_LOCAL_SYMFIELD_CONVERT
422 TC_LOCAL_SYMFIELD_CONVERT (locsym
, ret
);
425 symbol_table_insert (ret
);
427 local_symbol_mark_converted (locsym
);
428 local_symbol_set_real_symbol (locsym
, ret
);
430 htab_insert (local_hash
, symbol_entry_alloc (locsym
->lsy_name
, NULL
));
436 define_sym_at_dot (symbolS
*symbolP
)
438 symbolP
->sy_frag
= frag_now
;
439 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
440 S_SET_SEGMENT (symbolP
, now_seg
);
443 /* We have just seen "<name>:".
444 Creates a struct symbol unless it already exists.
446 Gripes if we are redefining a symbol incompatibly (and ignores it). */
449 colon (/* Just seen "x:" - rattle symbols & frags. */
450 const char *sym_name
/* Symbol name, as a canonical string. */
451 /* We copy this string: OK to alter later. */)
453 symbolS
*symbolP
; /* Symbol we are working with. */
455 /* Sun local labels go out of scope whenever a non-local symbol is
457 if (LOCAL_LABELS_DOLLAR
458 && !bfd_is_local_label_name (stdoutput
, sym_name
))
459 dollar_label_clear ();
461 #ifndef WORKING_DOT_WORD
462 if (new_broken_words
)
464 struct broken_word
*a
;
469 if (now_seg
== absolute_section
)
471 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
475 possible_bytes
= (md_short_jump_size
476 + new_broken_words
* md_long_jump_size
);
479 frag_opcode
= frag_var (rs_broken_word
,
483 (symbolS
*) broken_words
,
487 /* We want to store the pointer to where to insert the jump
488 table in the fr_opcode of the rs_broken_word frag. This
489 requires a little hackery. */
491 && (frag_tmp
->fr_type
!= rs_broken_word
492 || frag_tmp
->fr_opcode
))
493 frag_tmp
= frag_tmp
->fr_next
;
495 frag_tmp
->fr_opcode
= frag_opcode
;
496 new_broken_words
= 0;
498 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
499 a
->dispfrag
= frag_tmp
;
501 #endif /* WORKING_DOT_WORD */
503 #ifdef obj_frob_colon
504 obj_frob_colon (sym_name
);
507 if ((symbolP
= symbol_find (sym_name
)) != 0)
509 S_CLEAR_WEAKREFR (symbolP
);
510 #ifdef RESOLVE_SYMBOL_REDEFINITION
511 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
514 /* Now check for undefined symbols. */
515 if (LOCAL_SYMBOL_CHECK (symbolP
))
517 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
519 if (locsym
->lsy_section
!= undefined_section
520 && (local_symbol_get_frag (locsym
) != frag_now
521 || locsym
->lsy_section
!= now_seg
522 || locsym
->lsy_value
!= frag_now_fix ()))
524 as_bad (_("symbol `%s' is already defined"), sym_name
);
528 locsym
->lsy_section
= now_seg
;
529 local_symbol_set_frag (locsym
, frag_now
);
530 locsym
->lsy_value
= frag_now_fix ();
532 else if (!(S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
533 || S_IS_COMMON (symbolP
)
534 || S_IS_VOLATILE (symbolP
))
536 if (S_IS_VOLATILE (symbolP
))
538 symbolP
= symbol_clone (symbolP
, 1);
539 S_SET_VALUE (symbolP
, 0);
540 S_CLEAR_VOLATILE (symbolP
);
542 if (S_GET_VALUE (symbolP
) == 0)
544 define_sym_at_dot (symbolP
);
547 #endif /* if we have one, it better be zero. */
552 /* There are still several cases to check:
554 A .comm/.lcomm symbol being redefined as initialized
557 A .comm/.lcomm symbol being redefined with a larger
560 This only used to be allowed on VMS gas, but Sun cc
561 on the sparc also depends on it. */
563 if (((!S_IS_DEBUG (symbolP
)
564 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
565 && S_IS_EXTERNAL (symbolP
))
566 || S_GET_SEGMENT (symbolP
) == bss_section
)
567 && (now_seg
== data_section
568 || now_seg
== bss_section
569 || now_seg
== S_GET_SEGMENT (symbolP
)))
571 /* Select which of the 2 cases this is. */
572 if (now_seg
!= data_section
)
574 /* New .comm for prev .comm symbol.
576 If the new size is larger we just change its
577 value. If the new size is smaller, we ignore
579 if (S_GET_VALUE (symbolP
)
580 < ((unsigned) frag_now_fix ()))
582 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
587 /* It is a .comm/.lcomm being converted to initialized
589 define_sym_at_dot (symbolP
);
594 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT))
595 static const char *od_buf
= "";
599 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
600 sprintf (od_buf
, "%d.%d.",
601 S_GET_OTHER (symbolP
),
602 S_GET_DESC (symbolP
));
604 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
606 segment_name (S_GET_SEGMENT (symbolP
)),
608 (long) S_GET_VALUE (symbolP
));
610 } /* if the undefined symbol has no value */
614 /* Don't blow up if the definition is the same. */
615 if (!(frag_now
== symbolP
->sy_frag
616 && S_GET_VALUE (symbolP
) == frag_now_fix ()
617 && S_GET_SEGMENT (symbolP
) == now_seg
))
619 as_bad (_("symbol `%s' is already defined"), sym_name
);
620 symbolP
= symbol_clone (symbolP
, 0);
621 define_sym_at_dot (symbolP
);
626 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
628 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
, frag_now
,
633 symbolP
= symbol_new (sym_name
, now_seg
, frag_now
, frag_now_fix ());
635 symbol_table_insert (symbolP
);
638 if (mri_common_symbol
!= NULL
)
640 /* This symbol is actually being defined within an MRI common
641 section. This requires special handling. */
642 if (LOCAL_SYMBOL_CHECK (symbolP
))
643 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
644 symbolP
->sy_value
.X_op
= O_symbol
;
645 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
646 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
647 symbolP
->sy_frag
= &zero_address_frag
;
648 S_SET_SEGMENT (symbolP
, expr_section
);
649 symbolP
->sy_flags
.sy_mri_common
= 1;
653 tc_frob_label (symbolP
);
655 #ifdef obj_frob_label
656 obj_frob_label (symbolP
);
662 /* Die if we can't insert the symbol. */
665 symbol_table_insert (symbolS
*symbolP
)
668 know (S_GET_NAME (symbolP
));
670 if (LOCAL_SYMBOL_CHECK (symbolP
))
671 htab_insert (local_hash
,
672 symbol_entry_alloc (S_GET_NAME (symbolP
),
673 (struct local_symbol
*)symbolP
));
675 htab_insert (sy_hash
, symbol_entry_alloc (S_GET_NAME (symbolP
),
676 (struct local_symbol
*)symbolP
));
679 /* If a symbol name does not exist, create it as undefined, and insert
680 it into the symbol table. Return a pointer to it. */
683 symbol_find_or_make (const char *name
)
687 symbolP
= symbol_find (name
);
691 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
693 symbolP
= md_undefined_symbol ((char *) name
);
697 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
698 &zero_address_frag
, 0);
702 symbolP
= symbol_make (name
);
704 symbol_table_insert (symbolP
);
705 } /* if symbol wasn't found */
711 symbol_make (const char *name
)
715 /* Let the machine description default it, e.g. for register names. */
716 symbolP
= md_undefined_symbol ((char *) name
);
719 symbolP
= symbol_new (name
, undefined_section
, &zero_address_frag
, 0);
725 symbol_clone (symbolS
*orgsymP
, int replace
)
728 asymbol
*bsymorg
, *bsymnew
;
730 /* Make sure we never clone the dot special symbol. */
731 gas_assert (orgsymP
!= &dot_symbol
);
733 /* Running local_symbol_convert on a clone that's not the one currently
734 in local_hash would incorrectly replace the hash entry. Thus the
735 symbol must be converted here. Note that the rest of the function
736 depends on not encountering an unconverted symbol. */
737 if (LOCAL_SYMBOL_CHECK (orgsymP
))
738 orgsymP
= local_symbol_convert ((struct local_symbol
*) orgsymP
);
739 bsymorg
= orgsymP
->bsym
;
741 newsymP
= (symbolS
*) obstack_alloc (¬es
, sizeof (*newsymP
));
743 bsymnew
= bfd_make_empty_symbol (bfd_asymbol_bfd (bsymorg
));
745 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
746 newsymP
->bsym
= bsymnew
;
747 bsymnew
->name
= bsymorg
->name
;
748 bsymnew
->flags
= bsymorg
->flags
& ~BSF_SECTION_SYM
;
749 bsymnew
->section
= bsymorg
->section
;
750 bfd_copy_private_symbol_data (bfd_asymbol_bfd (bsymorg
), bsymorg
,
751 bfd_asymbol_bfd (bsymnew
), bsymnew
);
753 #ifdef obj_symbol_clone_hook
754 obj_symbol_clone_hook (newsymP
, orgsymP
);
757 #ifdef tc_symbol_clone_hook
758 tc_symbol_clone_hook (newsymP
, orgsymP
);
763 if (symbol_rootP
== orgsymP
)
764 symbol_rootP
= newsymP
;
765 else if (orgsymP
->sy_previous
)
767 orgsymP
->sy_previous
->sy_next
= newsymP
;
768 orgsymP
->sy_previous
= NULL
;
770 if (symbol_lastP
== orgsymP
)
771 symbol_lastP
= newsymP
;
772 else if (orgsymP
->sy_next
)
773 orgsymP
->sy_next
->sy_previous
= newsymP
;
775 /* Symbols that won't be output can't be external. */
776 S_CLEAR_EXTERNAL (orgsymP
);
777 orgsymP
->sy_previous
= orgsymP
->sy_next
= orgsymP
;
778 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
780 symbol_table_insert (newsymP
);
784 /* Symbols that won't be output can't be external. */
785 S_CLEAR_EXTERNAL (newsymP
);
786 newsymP
->sy_previous
= newsymP
->sy_next
= newsymP
;
792 /* If S is a local symbol that has been converted, return the
793 converted symbol. Otherwise return S. */
795 static inline symbolS
*
796 get_real_sym (symbolS
*s
)
799 && s
->sy_flags
.sy_local_symbol
800 && local_symbol_converted_p ((struct local_symbol
*) s
))
801 s
= local_symbol_get_real_symbol ((struct local_symbol
*) s
);
805 /* Referenced symbols, if they are forward references, need to be cloned
806 (without replacing the original) so that the value of the referenced
807 symbols at the point of use is saved by the clone. */
809 #undef symbol_clone_if_forward_ref
811 symbol_clone_if_forward_ref (symbolS
*symbolP
, int is_forward
)
813 if (symbolP
&& !LOCAL_SYMBOL_CHECK (symbolP
))
815 symbolS
*orig_add_symbol
= get_real_sym (symbolP
->sy_value
.X_add_symbol
);
816 symbolS
*orig_op_symbol
= get_real_sym (symbolP
->sy_value
.X_op_symbol
);
817 symbolS
*add_symbol
= orig_add_symbol
;
818 symbolS
*op_symbol
= orig_op_symbol
;
820 if (symbolP
->sy_flags
.sy_forward_ref
)
825 /* assign_symbol() clones volatile symbols; pre-existing expressions
826 hold references to the original instance, but want the current
827 value. Just repeat the lookup. */
828 if (add_symbol
&& S_IS_VOLATILE (add_symbol
))
829 add_symbol
= symbol_find_exact (S_GET_NAME (add_symbol
));
830 if (op_symbol
&& S_IS_VOLATILE (op_symbol
))
831 op_symbol
= symbol_find_exact (S_GET_NAME (op_symbol
));
834 /* Re-using sy_resolving here, as this routine cannot get called from
835 symbol resolution code. */
836 if ((symbolP
->bsym
->section
== expr_section
837 || symbolP
->sy_flags
.sy_forward_ref
)
838 && !symbolP
->sy_flags
.sy_resolving
)
840 symbolP
->sy_flags
.sy_resolving
= 1;
841 add_symbol
= symbol_clone_if_forward_ref (add_symbol
, is_forward
);
842 op_symbol
= symbol_clone_if_forward_ref (op_symbol
, is_forward
);
843 symbolP
->sy_flags
.sy_resolving
= 0;
846 if (symbolP
->sy_flags
.sy_forward_ref
847 || add_symbol
!= orig_add_symbol
848 || op_symbol
!= orig_op_symbol
)
850 if (symbolP
!= &dot_symbol
)
852 symbolP
= symbol_clone (symbolP
, 0);
853 symbolP
->sy_flags
.sy_resolving
= 0;
857 symbolP
= symbol_temp_new_now ();
858 #ifdef tc_new_dot_label
859 tc_new_dot_label (symbolP
);
864 symbolP
->sy_value
.X_add_symbol
= add_symbol
;
865 symbolP
->sy_value
.X_op_symbol
= op_symbol
;
872 symbol_temp_new (segT seg
, fragS
*frag
, valueT ofs
)
874 return symbol_new (FAKE_LABEL_NAME
, seg
, frag
, ofs
);
878 symbol_temp_new_now (void)
880 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix ());
884 symbol_temp_new_now_octets (void)
886 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix_octets ());
890 symbol_temp_make (void)
892 return symbol_make (FAKE_LABEL_NAME
);
895 /* Implement symbol table lookup.
896 In: A symbol's name as a string: '\0' can't be part of a symbol name.
897 Out: NULL if the name was not in the symbol table, else the address
898 of a struct symbol associated with that name. */
901 symbol_find_exact (const char *name
)
903 return symbol_find_exact_noref (name
, 0);
907 symbol_find_exact_noref (const char *name
, int noref
)
909 symbolS
*sym
= symbol_entry_find (local_hash
, name
);
913 sym
= symbol_entry_find (sy_hash
, name
);
915 /* Any references to the symbol, except for the reference in
916 .weakref, must clear this flag, such that the symbol does not
917 turn into a weak symbol. Note that we don't have to handle the
918 local_symbol case, since a weakrefd is always promoted out of the
919 local_symbol table when it is turned into a weak symbol. */
921 S_CLEAR_WEAKREFD (sym
);
927 symbol_find (const char *name
)
929 return symbol_find_noref (name
, 0);
933 symbol_find_noref (const char *name
, int noref
)
938 #ifdef tc_canonicalize_symbol_name
940 copy
= xstrdup (name
);
941 name
= tc_canonicalize_symbol_name (copy
);
945 if (! symbols_case_sensitive
)
954 name
= copy
= XNEWVEC (char, strlen (name
) + 1);
956 while ((c
= *orig
++) != '\0')
957 *copy
++ = TOUPPER (c
);
961 copy
= (char *) name
;
964 result
= symbol_find_exact_noref (name
, noref
);
969 /* Once upon a time, symbols were kept in a singly linked list. At
970 least coff needs to be able to rearrange them from time to time, for
971 which a doubly linked list is much more convenient. Loic did these
972 as macros which seemed dangerous to me so they're now functions.
975 /* Link symbol ADDME after symbol TARGET in the chain. */
978 symbol_append (symbolS
*addme
, symbolS
*target
,
979 symbolS
**rootPP
, symbolS
**lastPP
)
981 if (LOCAL_SYMBOL_CHECK (addme
))
983 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
988 know (*rootPP
== NULL
);
989 know (*lastPP
== NULL
);
990 addme
->sy_next
= NULL
;
991 addme
->sy_previous
= NULL
;
995 } /* if the list is empty */
997 if (target
->sy_next
!= NULL
)
999 target
->sy_next
->sy_previous
= addme
;
1003 know (*lastPP
== target
);
1005 } /* if we have a next */
1007 addme
->sy_next
= target
->sy_next
;
1008 target
->sy_next
= addme
;
1009 addme
->sy_previous
= target
;
1011 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
1014 /* Set the chain pointers of SYMBOL to null. */
1017 symbol_clear_list_pointers (symbolS
*symbolP
)
1019 if (LOCAL_SYMBOL_CHECK (symbolP
))
1021 symbolP
->sy_next
= NULL
;
1022 symbolP
->sy_previous
= NULL
;
1025 /* Remove SYMBOLP from the list. */
1028 symbol_remove (symbolS
*symbolP
, symbolS
**rootPP
, symbolS
**lastPP
)
1030 if (LOCAL_SYMBOL_CHECK (symbolP
))
1033 if (symbolP
== *rootPP
)
1035 *rootPP
= symbolP
->sy_next
;
1036 } /* if it was the root */
1038 if (symbolP
== *lastPP
)
1040 *lastPP
= symbolP
->sy_previous
;
1041 } /* if it was the tail */
1043 if (symbolP
->sy_next
!= NULL
)
1045 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
1048 if (symbolP
->sy_previous
!= NULL
)
1050 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
1051 } /* if not first */
1053 debug_verify_symchain (*rootPP
, *lastPP
);
1056 /* Link symbol ADDME before symbol TARGET in the chain. */
1059 symbol_insert (symbolS
*addme
, symbolS
*target
,
1060 symbolS
**rootPP
, symbolS
**lastPP ATTRIBUTE_UNUSED
)
1062 if (LOCAL_SYMBOL_CHECK (addme
))
1064 if (LOCAL_SYMBOL_CHECK (target
))
1067 if (target
->sy_previous
!= NULL
)
1069 target
->sy_previous
->sy_next
= addme
;
1073 know (*rootPP
== target
);
1075 } /* if not first */
1077 addme
->sy_previous
= target
->sy_previous
;
1078 target
->sy_previous
= addme
;
1079 addme
->sy_next
= target
;
1081 debug_verify_symchain (*rootPP
, *lastPP
);
1085 verify_symbol_chain (symbolS
*rootP
, symbolS
*lastP
)
1087 symbolS
*symbolP
= rootP
;
1089 if (symbolP
== NULL
)
1092 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
1094 gas_assert (symbolP
->bsym
!= NULL
);
1095 gas_assert (symbolP
->sy_flags
.sy_local_symbol
== 0);
1096 gas_assert (symbolP
->sy_next
->sy_previous
== symbolP
);
1099 gas_assert (lastP
== symbolP
);
1103 symbol_on_chain (symbolS
*s
, symbolS
*rootPP
, symbolS
*lastPP
)
1105 return (!LOCAL_SYMBOL_CHECK (s
)
1106 && ((s
->sy_next
!= s
1107 && s
->sy_next
!= NULL
1108 && s
->sy_next
->sy_previous
== s
)
1110 && ((s
->sy_previous
!= s
1111 && s
->sy_previous
!= NULL
1112 && s
->sy_previous
->sy_next
== s
)
1116 #ifdef OBJ_COMPLEX_RELC
1119 use_complex_relocs_for (symbolS
* symp
)
1121 switch (symp
->sy_value
.X_op
)
1131 case O_bit_inclusive_or
:
1133 case O_bit_exclusive_or
:
1145 if ((S_IS_COMMON (symp
->sy_value
.X_op_symbol
)
1146 || S_IS_LOCAL (symp
->sy_value
.X_op_symbol
))
1147 && S_IS_DEFINED (symp
->sy_value
.X_op_symbol
)
1148 && S_GET_SEGMENT (symp
->sy_value
.X_op_symbol
) != expr_section
)
1155 if ((S_IS_COMMON (symp
->sy_value
.X_add_symbol
)
1156 || S_IS_LOCAL (symp
->sy_value
.X_add_symbol
))
1157 && S_IS_DEFINED (symp
->sy_value
.X_add_symbol
)
1158 && S_GET_SEGMENT (symp
->sy_value
.X_add_symbol
) != expr_section
)
1171 report_op_error (symbolS
*symp
, symbolS
*left
, operatorT op
, symbolS
*right
)
1175 segT seg_left
= left
? S_GET_SEGMENT (left
) : 0;
1176 segT seg_right
= S_GET_SEGMENT (right
);
1185 case O_uminus
: opname
= "-"; break;
1186 case O_bit_not
: opname
= "~"; break;
1187 case O_logical_not
: opname
= "!"; break;
1188 case O_multiply
: opname
= "*"; break;
1189 case O_divide
: opname
= "/"; break;
1190 case O_modulus
: opname
= "%"; break;
1191 case O_left_shift
: opname
= "<<"; break;
1192 case O_right_shift
: opname
= ">>"; break;
1193 case O_bit_inclusive_or
: opname
= "|"; break;
1194 case O_bit_or_not
: opname
= "|~"; break;
1195 case O_bit_exclusive_or
: opname
= "^"; break;
1196 case O_bit_and
: opname
= "&"; break;
1197 case O_add
: opname
= "+"; break;
1198 case O_subtract
: opname
= "-"; break;
1199 case O_eq
: opname
= "=="; break;
1200 case O_ne
: opname
= "!="; break;
1201 case O_lt
: opname
= "<"; break;
1202 case O_le
: opname
= "<="; break;
1203 case O_ge
: opname
= ">="; break;
1204 case O_gt
: opname
= ">"; break;
1205 case O_logical_and
: opname
= "&&"; break;
1206 case O_logical_or
: opname
= "||"; break;
1209 if (expr_symbol_where (symp
, &file
, &line
))
1212 as_bad_where (file
, line
,
1213 _("invalid operands (%s and %s sections) for `%s'"),
1214 seg_left
->name
, seg_right
->name
, opname
);
1216 as_bad_where (file
, line
,
1217 _("invalid operand (%s section) for `%s'"),
1218 seg_right
->name
, opname
);
1222 const char *sname
= S_GET_NAME (symp
);
1225 as_bad (_("invalid operands (%s and %s sections) for `%s' when setting `%s'"),
1226 seg_left
->name
, seg_right
->name
, opname
, sname
);
1228 as_bad (_("invalid operand (%s section) for `%s' when setting `%s'"),
1229 seg_right
->name
, opname
, sname
);
1233 /* Resolve the value of a symbol. This is called during the final
1234 pass over the symbol table to resolve any symbols with complex
1238 resolve_symbol_value (symbolS
*symp
)
1244 if (LOCAL_SYMBOL_CHECK (symp
))
1246 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1248 final_val
= locsym
->lsy_value
;
1249 if (local_symbol_resolved_p (locsym
))
1252 /* Symbols whose section has SEC_ELF_OCTETS set,
1253 resolve to octets instead of target bytes. */
1254 if (locsym
->lsy_section
->flags
& SEC_OCTETS
)
1255 final_val
+= local_symbol_get_frag (locsym
)->fr_address
;
1257 final_val
+= (local_symbol_get_frag (locsym
)->fr_address
1262 locsym
->lsy_value
= final_val
;
1263 local_symbol_mark_resolved (locsym
);
1269 if (symp
->sy_flags
.sy_resolved
)
1272 while (symp
->sy_value
.X_op
== O_symbol
)
1274 final_val
+= symp
->sy_value
.X_add_number
;
1275 symp
= symp
->sy_value
.X_add_symbol
;
1276 if (LOCAL_SYMBOL_CHECK (symp
))
1278 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1279 final_val
+= locsym
->lsy_value
;
1282 if (!symp
->sy_flags
.sy_resolved
)
1285 if (symp
->sy_value
.X_op
== O_constant
)
1286 final_val
+= symp
->sy_value
.X_add_number
;
1293 final_seg
= S_GET_SEGMENT (symp
);
1295 if (symp
->sy_flags
.sy_resolving
)
1298 as_bad (_("symbol definition loop encountered at `%s'"),
1303 #ifdef OBJ_COMPLEX_RELC
1304 else if (final_seg
== expr_section
1305 && use_complex_relocs_for (symp
))
1307 symbolS
* relc_symbol
= NULL
;
1308 char * relc_symbol_name
= NULL
;
1310 relc_symbol_name
= symbol_relc_make_expr (& symp
->sy_value
);
1312 /* For debugging, print out conversion input & output. */
1314 print_expr (& symp
->sy_value
);
1315 if (relc_symbol_name
)
1316 fprintf (stderr
, "-> relc symbol: %s\n", relc_symbol_name
);
1319 if (relc_symbol_name
!= NULL
)
1320 relc_symbol
= symbol_new (relc_symbol_name
, undefined_section
,
1321 &zero_address_frag
, 0);
1323 if (relc_symbol
== NULL
)
1325 as_bad (_("cannot convert expression symbol %s to complex relocation"),
1331 symbol_table_insert (relc_symbol
);
1333 /* S_CLEAR_EXTERNAL (relc_symbol); */
1334 if (symp
->bsym
->flags
& BSF_SRELC
)
1335 relc_symbol
->bsym
->flags
|= BSF_SRELC
;
1337 relc_symbol
->bsym
->flags
|= BSF_RELC
;
1338 /* symp->bsym->flags |= BSF_RELC; */
1339 copy_symbol_attributes (symp
, relc_symbol
);
1340 symp
->sy_value
.X_op
= O_symbol
;
1341 symp
->sy_value
.X_add_symbol
= relc_symbol
;
1342 symp
->sy_value
.X_add_number
= 0;
1347 final_seg
= undefined_section
;
1348 goto exit_dont_set_value
;
1353 symbolS
*add_symbol
, *op_symbol
;
1354 offsetT left
, right
;
1355 segT seg_left
, seg_right
;
1359 symp
->sy_flags
.sy_resolving
= 1;
1361 /* Help out with CSE. */
1362 add_symbol
= symp
->sy_value
.X_add_symbol
;
1363 op_symbol
= symp
->sy_value
.X_op_symbol
;
1364 final_val
= symp
->sy_value
.X_add_number
;
1365 op
= symp
->sy_value
.X_op
;
1378 /* Symbols whose section has SEC_ELF_OCTETS set,
1379 resolve to octets instead of target bytes. */
1380 if (symp
->bsym
->section
->flags
& SEC_OCTETS
)
1381 final_val
+= symp
->sy_frag
->fr_address
;
1383 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
1384 if (final_seg
== expr_section
)
1385 final_seg
= absolute_section
;
1394 left
= resolve_symbol_value (add_symbol
);
1395 seg_left
= S_GET_SEGMENT (add_symbol
);
1397 symp
->sy_value
.X_op_symbol
= NULL
;
1400 if (S_IS_WEAKREFR (symp
))
1402 gas_assert (final_val
== 0);
1403 if (S_IS_WEAKREFR (add_symbol
))
1405 gas_assert (add_symbol
->sy_value
.X_op
== O_symbol
1406 && add_symbol
->sy_value
.X_add_number
== 0);
1407 add_symbol
= add_symbol
->sy_value
.X_add_symbol
;
1408 gas_assert (! S_IS_WEAKREFR (add_symbol
));
1409 symp
->sy_value
.X_add_symbol
= add_symbol
;
1413 if (symp
->sy_flags
.sy_mri_common
)
1415 /* This is a symbol inside an MRI common section. The
1416 relocation routines are going to handle it specially.
1417 Don't change the value. */
1418 resolved
= symbol_resolved_p (add_symbol
);
1422 /* Don't leave symbol loops. */
1424 && !LOCAL_SYMBOL_CHECK (add_symbol
)
1425 && add_symbol
->sy_flags
.sy_resolving
)
1428 if (finalize_syms
&& final_val
== 0)
1430 if (LOCAL_SYMBOL_CHECK (add_symbol
))
1431 add_symbol
= local_symbol_convert ((struct local_symbol
*)
1433 copy_symbol_attributes (symp
, add_symbol
);
1436 /* If we have equated this symbol to an undefined or common
1437 symbol, keep X_op set to O_symbol, and don't change
1438 X_add_number. This permits the routine which writes out
1439 relocation to detect this case, and convert the
1440 relocation to be against the symbol to which this symbol
1442 if (seg_left
== undefined_section
1443 || bfd_is_com_section (seg_left
)
1444 #if defined (OBJ_COFF) && defined (TE_PE)
1445 || S_IS_WEAK (add_symbol
)
1448 && ((final_seg
== expr_section
1449 && seg_left
!= expr_section
1450 && seg_left
!= absolute_section
)
1451 || symbol_shadow_p (symp
))))
1455 symp
->sy_value
.X_op
= O_symbol
;
1456 symp
->sy_value
.X_add_symbol
= add_symbol
;
1457 symp
->sy_value
.X_add_number
= final_val
;
1458 /* Use X_op_symbol as a flag. */
1459 symp
->sy_value
.X_op_symbol
= add_symbol
;
1461 final_seg
= seg_left
;
1462 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1463 resolved
= symbol_resolved_p (add_symbol
);
1464 symp
->sy_flags
.sy_resolving
= 0;
1465 goto exit_dont_set_value
;
1469 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1470 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1471 final_seg
= seg_left
;
1474 resolved
= symbol_resolved_p (add_symbol
);
1475 if (S_IS_WEAKREFR (symp
))
1477 symp
->sy_flags
.sy_resolving
= 0;
1478 goto exit_dont_set_value
;
1485 left
= resolve_symbol_value (add_symbol
);
1486 seg_left
= S_GET_SEGMENT (add_symbol
);
1488 /* By reducing these to the relevant dyadic operator, we get
1489 !S -> S == 0 permitted on anything,
1490 -S -> 0 - S only permitted on absolute
1491 ~S -> S ^ ~0 only permitted on absolute */
1492 if (op
!= O_logical_not
&& seg_left
!= absolute_section
1494 report_op_error (symp
, NULL
, op
, add_symbol
);
1496 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1497 final_seg
= absolute_section
;
1501 else if (op
== O_logical_not
)
1506 final_val
+= left
+ symp
->sy_frag
->fr_address
;
1508 resolved
= symbol_resolved_p (add_symbol
);
1516 case O_bit_inclusive_or
:
1518 case O_bit_exclusive_or
:
1530 left
= resolve_symbol_value (add_symbol
);
1531 right
= resolve_symbol_value (op_symbol
);
1532 seg_left
= S_GET_SEGMENT (add_symbol
);
1533 seg_right
= S_GET_SEGMENT (op_symbol
);
1535 /* Simplify addition or subtraction of a constant by folding the
1536 constant into X_add_number. */
1539 if (seg_right
== absolute_section
)
1544 else if (seg_left
== absolute_section
)
1547 add_symbol
= op_symbol
;
1549 seg_left
= seg_right
;
1553 else if (op
== O_subtract
)
1555 if (seg_right
== absolute_section
)
1563 /* Equality and non-equality tests are permitted on anything.
1564 Subtraction, and other comparison operators are permitted if
1565 both operands are in the same section. Otherwise, both
1566 operands must be absolute. We already handled the case of
1567 addition or subtraction of a constant above. This will
1568 probably need to be changed for an object file format which
1569 supports arbitrary expressions. */
1570 if (!(seg_left
== absolute_section
1571 && seg_right
== absolute_section
)
1572 && !(op
== O_eq
|| op
== O_ne
)
1573 && !((op
== O_subtract
1574 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1575 && seg_left
== seg_right
1576 && (seg_left
!= undefined_section
1577 || add_symbol
== op_symbol
)))
1579 /* Don't emit messages unless we're finalizing the symbol value,
1580 otherwise we may get the same message multiple times. */
1582 report_op_error (symp
, add_symbol
, op
, op_symbol
);
1583 /* However do not move the symbol into the absolute section
1584 if it cannot currently be resolved - this would confuse
1585 other parts of the assembler into believing that the
1586 expression had been evaluated to zero. */
1592 && (final_seg
== expr_section
|| final_seg
== undefined_section
))
1593 final_seg
= absolute_section
;
1595 /* Check for division by zero. */
1596 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1598 /* If seg_right is not absolute_section, then we've
1599 already issued a warning about using a bad symbol. */
1600 if (seg_right
== absolute_section
&& finalize_syms
)
1605 if (expr_symbol_where (symp
, &file
, &line
))
1606 as_bad_where (file
, line
, _("division by zero"));
1608 as_bad (_("division by zero when setting `%s'"),
1615 switch (symp
->sy_value
.X_op
)
1617 case O_multiply
: left
*= right
; break;
1618 case O_divide
: left
/= right
; break;
1619 case O_modulus
: left
%= right
; break;
1620 case O_left_shift
: left
<<= right
; break;
1621 case O_right_shift
: left
>>= right
; break;
1622 case O_bit_inclusive_or
: left
|= right
; break;
1623 case O_bit_or_not
: left
|= ~right
; break;
1624 case O_bit_exclusive_or
: left
^= right
; break;
1625 case O_bit_and
: left
&= right
; break;
1626 case O_add
: left
+= right
; break;
1627 case O_subtract
: left
-= right
; break;
1630 left
= (left
== right
&& seg_left
== seg_right
1631 && (seg_left
!= undefined_section
1632 || add_symbol
== op_symbol
)
1633 ? ~ (offsetT
) 0 : 0);
1634 if (symp
->sy_value
.X_op
== O_ne
)
1637 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1638 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1639 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1640 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1641 case O_logical_and
: left
= left
&& right
; break;
1642 case O_logical_or
: left
= left
|| right
; break;
1647 /* See PR 20895 for a reproducer. */
1648 as_bad (_("Invalid operation on symbol"));
1649 goto exit_dont_set_value
;
1655 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1656 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1658 if (seg_left
== undefined_section
1659 || seg_right
== undefined_section
)
1660 final_seg
= undefined_section
;
1661 else if (seg_left
== absolute_section
)
1662 final_seg
= seg_right
;
1664 final_seg
= seg_left
;
1666 resolved
= (symbol_resolved_p (add_symbol
)
1667 && symbol_resolved_p (op_symbol
));
1672 /* Give an error (below) if not in expr_section. We don't
1673 want to worry about expr_section symbols, because they
1674 are fictional (they are created as part of expression
1675 resolution), and any problems may not actually mean
1680 symp
->sy_flags
.sy_resolving
= 0;
1684 S_SET_VALUE (symp
, final_val
);
1686 exit_dont_set_value
:
1687 /* Always set the segment, even if not finalizing the value.
1688 The segment is used to determine whether a symbol is defined. */
1689 S_SET_SEGMENT (symp
, final_seg
);
1691 /* Don't worry if we can't resolve an expr_section symbol. */
1695 symp
->sy_flags
.sy_resolved
= 1;
1696 else if (S_GET_SEGMENT (symp
) != expr_section
)
1698 as_bad (_("can't resolve value for symbol `%s'"),
1700 symp
->sy_flags
.sy_resolved
= 1;
1707 /* A static function passed to hash_traverse. */
1710 resolve_local_symbol (void **slot
, void *arg ATTRIBUTE_UNUSED
)
1712 symbol_entry_t
*entry
= *((symbol_entry_t
**) slot
);
1713 if (entry
->symbol
!= NULL
)
1714 resolve_symbol_value ((symbolS
*) entry
->symbol
);
1719 /* Resolve all local symbols. */
1722 resolve_local_symbol_values (void)
1724 htab_traverse (local_hash
, resolve_local_symbol
, NULL
);
1727 /* Obtain the current value of a symbol without changing any
1728 sub-expressions used. */
1731 snapshot_symbol (symbolS
**symbolPP
, valueT
*valueP
, segT
*segP
, fragS
**fragPP
)
1733 symbolS
*symbolP
= *symbolPP
;
1735 if (LOCAL_SYMBOL_CHECK (symbolP
))
1737 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1739 *valueP
= locsym
->lsy_value
;
1740 *segP
= locsym
->lsy_section
;
1741 *fragPP
= local_symbol_get_frag (locsym
);
1745 expressionS exp
= symbolP
->sy_value
;
1747 if (!symbolP
->sy_flags
.sy_resolved
&& exp
.X_op
!= O_illegal
)
1751 if (symbolP
->sy_flags
.sy_resolving
)
1753 symbolP
->sy_flags
.sy_resolving
= 1;
1754 resolved
= resolve_expression (&exp
);
1755 symbolP
->sy_flags
.sy_resolving
= 0;
1763 if (!symbol_equated_p (symbolP
))
1768 symbolP
= exp
.X_add_symbol
;
1775 *symbolPP
= symbolP
;
1777 /* A bogus input file can result in resolve_expression()
1778 generating a local symbol, so we have to check again. */
1779 if (LOCAL_SYMBOL_CHECK (symbolP
))
1781 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1783 *valueP
= locsym
->lsy_value
;
1784 *segP
= locsym
->lsy_section
;
1785 *fragPP
= local_symbol_get_frag (locsym
);
1789 *valueP
= exp
.X_add_number
;
1790 *segP
= symbolP
->bsym
->section
;
1791 *fragPP
= symbolP
->sy_frag
;
1794 if (*segP
== expr_section
)
1797 case O_constant
: *segP
= absolute_section
; break;
1798 case O_register
: *segP
= reg_section
; break;
1806 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1807 They are *really* local. That is, they go out of scope whenever we see a
1808 label that isn't local. Also, like fb labels, there can be multiple
1809 instances of a dollar label. Therefor, we name encode each instance with
1810 the instance number, keep a list of defined symbols separate from the real
1811 symbol table, and we treat these buggers as a sparse array. */
1813 static long *dollar_labels
;
1814 static long *dollar_label_instances
;
1815 static char *dollar_label_defines
;
1816 static unsigned long dollar_label_count
;
1817 static unsigned long dollar_label_max
;
1820 dollar_label_defined (long label
)
1824 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1826 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1828 return dollar_label_defines
[i
- dollar_labels
];
1830 /* If we get here, label isn't defined. */
1835 dollar_label_instance (long label
)
1839 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1841 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1843 return (dollar_label_instances
[i
- dollar_labels
]);
1845 /* If we get here, we haven't seen the label before.
1846 Therefore its instance count is zero. */
1851 dollar_label_clear (void)
1853 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1856 #define DOLLAR_LABEL_BUMP_BY 10
1859 define_dollar_label (long label
)
1863 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1866 ++dollar_label_instances
[i
- dollar_labels
];
1867 dollar_label_defines
[i
- dollar_labels
] = 1;
1871 /* If we get to here, we don't have label listed yet. */
1873 if (dollar_labels
== NULL
)
1875 dollar_labels
= XNEWVEC (long, DOLLAR_LABEL_BUMP_BY
);
1876 dollar_label_instances
= XNEWVEC (long, DOLLAR_LABEL_BUMP_BY
);
1877 dollar_label_defines
= XNEWVEC (char, DOLLAR_LABEL_BUMP_BY
);
1878 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1879 dollar_label_count
= 0;
1881 else if (dollar_label_count
== dollar_label_max
)
1883 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1884 dollar_labels
= XRESIZEVEC (long, dollar_labels
, dollar_label_max
);
1885 dollar_label_instances
= XRESIZEVEC (long, dollar_label_instances
,
1887 dollar_label_defines
= XRESIZEVEC (char, dollar_label_defines
,
1889 } /* if we needed to grow */
1891 dollar_labels
[dollar_label_count
] = label
;
1892 dollar_label_instances
[dollar_label_count
] = 1;
1893 dollar_label_defines
[dollar_label_count
] = 1;
1894 ++dollar_label_count
;
1897 /* Caller must copy returned name: we re-use the area for the next name.
1899 The mth occurrence of label n: is turned into the symbol "Ln^Am"
1900 where n is the label number and m is the instance number. "L" makes
1901 it a label discarded unless debugging and "^A"('\1') ensures no
1902 ordinary symbol SHOULD get the same name as a local label
1903 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1905 fb labels get the same treatment, except that ^B is used in place
1908 char * /* Return local label name. */
1909 dollar_label_name (long n
, /* we just saw "n$:" : n a number. */
1910 int augend
/* 0 for current instance, 1 for new instance. */)
1913 /* Returned to caller, then copied. Used for created names ("4f"). */
1914 static char symbol_name_build
[24];
1917 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1920 know (augend
== 0 || augend
== 1);
1921 p
= symbol_name_build
;
1922 #ifdef LOCAL_LABEL_PREFIX
1923 *p
++ = LOCAL_LABEL_PREFIX
;
1927 /* Next code just does sprintf( {}, "%d", n); */
1929 q
= symbol_name_temporary
;
1930 for (*q
++ = 0, i
= n
; i
; ++q
)
1935 while ((*p
= *--q
) != '\0')
1938 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1940 /* Instance number. */
1941 q
= symbol_name_temporary
;
1942 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1947 while ((*p
++ = *--q
) != '\0');
1949 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1950 return symbol_name_build
;
1953 /* Somebody else's idea of local labels. They are made by "n:" where n
1954 is any decimal digit. Refer to them with
1955 "nb" for previous (backward) n:
1956 or "nf" for next (forward) n:.
1958 We do a little better and let n be any number, not just a single digit, but
1959 since the other guy's assembler only does ten, we treat the first ten
1962 Like someone else's assembler, we have one set of local label counters for
1963 entire assembly, not one set per (sub)segment like in most assemblers. This
1964 implies that one can refer to a label in another segment, and indeed some
1965 crufty compilers have done just that.
1967 Since there could be a LOT of these things, treat them as a sparse
1970 #define FB_LABEL_SPECIAL (10)
1972 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1973 static long *fb_labels
;
1974 static long *fb_label_instances
;
1975 static long fb_label_count
;
1976 static long fb_label_max
;
1978 /* This must be more than FB_LABEL_SPECIAL. */
1979 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1982 fb_label_init (void)
1984 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1987 /* Add one to the instance number of this fb label. */
1990 fb_label_instance_inc (long label
)
1994 if ((unsigned long) label
< FB_LABEL_SPECIAL
)
1996 ++fb_low_counter
[label
];
2000 if (fb_labels
!= NULL
)
2002 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2003 i
< fb_labels
+ fb_label_count
; ++i
)
2007 ++fb_label_instances
[i
- fb_labels
];
2009 } /* if we find it */
2010 } /* for each existing label */
2013 /* If we get to here, we don't have label listed yet. */
2015 if (fb_labels
== NULL
)
2017 fb_labels
= XNEWVEC (long, FB_LABEL_BUMP_BY
);
2018 fb_label_instances
= XNEWVEC (long, FB_LABEL_BUMP_BY
);
2019 fb_label_max
= FB_LABEL_BUMP_BY
;
2020 fb_label_count
= FB_LABEL_SPECIAL
;
2023 else if (fb_label_count
== fb_label_max
)
2025 fb_label_max
+= FB_LABEL_BUMP_BY
;
2026 fb_labels
= XRESIZEVEC (long, fb_labels
, fb_label_max
);
2027 fb_label_instances
= XRESIZEVEC (long, fb_label_instances
, fb_label_max
);
2028 } /* if we needed to grow */
2030 fb_labels
[fb_label_count
] = label
;
2031 fb_label_instances
[fb_label_count
] = 1;
2036 fb_label_instance (long label
)
2040 if ((unsigned long) label
< FB_LABEL_SPECIAL
)
2042 return (fb_low_counter
[label
]);
2045 if (fb_labels
!= NULL
)
2047 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2048 i
< fb_labels
+ fb_label_count
; ++i
)
2052 return (fb_label_instances
[i
- fb_labels
]);
2053 } /* if we find it */
2054 } /* for each existing label */
2057 /* We didn't find the label, so this must be a reference to the
2062 /* Caller must copy returned name: we re-use the area for the next name.
2064 The mth occurrence of label n: is turned into the symbol "Ln^Bm"
2065 where n is the label number and m is the instance number. "L" makes
2066 it a label discarded unless debugging and "^B"('\2') ensures no
2067 ordinary symbol SHOULD get the same name as a local label
2068 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
2070 dollar labels get the same treatment, except that ^A is used in
2073 char * /* Return local label name. */
2074 fb_label_name (long n
, /* We just saw "n:", "nf" or "nb" : n a number. */
2075 long augend
/* 0 for nb, 1 for n:, nf. */)
2078 /* Returned to caller, then copied. Used for created names ("4f"). */
2079 static char symbol_name_build
[24];
2082 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
2086 know ((unsigned long) augend
<= 2 /* See mmix_fb_label. */);
2088 know ((unsigned long) augend
<= 1);
2090 p
= symbol_name_build
;
2091 #ifdef LOCAL_LABEL_PREFIX
2092 *p
++ = LOCAL_LABEL_PREFIX
;
2096 /* Next code just does sprintf( {}, "%d", n); */
2098 q
= symbol_name_temporary
;
2099 for (*q
++ = 0, i
= n
; i
; ++q
)
2104 while ((*p
= *--q
) != '\0')
2107 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
2109 /* Instance number. */
2110 q
= symbol_name_temporary
;
2111 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
2116 while ((*p
++ = *--q
) != '\0');
2118 /* The label, as a '\0' ended string, starts at symbol_name_build. */
2119 return (symbol_name_build
);
2122 /* Decode name that may have been generated by foo_label_name() above.
2123 If the name wasn't generated by foo_label_name(), then return it
2124 unaltered. This is used for error messages. */
2127 decode_local_label_name (char *s
)
2130 char *symbol_decode
;
2132 int instance_number
;
2134 const char *message_format
;
2137 #ifdef LOCAL_LABEL_PREFIX
2138 if (s
[lindex
] == LOCAL_LABEL_PREFIX
)
2142 if (s
[lindex
] != 'L')
2145 for (label_number
= 0, p
= s
+ lindex
+ 1; ISDIGIT (*p
); ++p
)
2146 label_number
= (10 * label_number
) + *p
- '0';
2148 if (*p
== DOLLAR_LABEL_CHAR
)
2150 else if (*p
== LOCAL_LABEL_CHAR
)
2155 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
2156 instance_number
= (10 * instance_number
) + *p
- '0';
2158 message_format
= _("\"%d\" (instance number %d of a %s label)");
2159 symbol_decode
= (char *) obstack_alloc (¬es
, strlen (message_format
) + 30);
2160 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
2162 return symbol_decode
;
2165 /* Get the value of a symbol. */
2168 S_GET_VALUE (symbolS
*s
)
2170 if (LOCAL_SYMBOL_CHECK (s
))
2171 return resolve_symbol_value (s
);
2173 if (!s
->sy_flags
.sy_resolved
)
2175 valueT val
= resolve_symbol_value (s
);
2179 if (S_IS_WEAKREFR (s
))
2180 return S_GET_VALUE (s
->sy_value
.X_add_symbol
);
2182 if (s
->sy_value
.X_op
!= O_constant
)
2184 if (! s
->sy_flags
.sy_resolved
2185 || s
->sy_value
.X_op
!= O_symbol
2186 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
2187 as_bad (_("attempt to get value of unresolved symbol `%s'"),
2190 return (valueT
) s
->sy_value
.X_add_number
;
2193 /* Set the value of a symbol. */
2196 S_SET_VALUE (symbolS
*s
, valueT val
)
2198 if (LOCAL_SYMBOL_CHECK (s
))
2200 ((struct local_symbol
*) s
)->lsy_value
= val
;
2204 s
->sy_value
.X_op
= O_constant
;
2205 s
->sy_value
.X_add_number
= (offsetT
) val
;
2206 s
->sy_value
.X_unsigned
= 0;
2207 S_CLEAR_WEAKREFR (s
);
2211 copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2213 if (LOCAL_SYMBOL_CHECK (dest
))
2214 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
2215 if (LOCAL_SYMBOL_CHECK (src
))
2216 src
= local_symbol_convert ((struct local_symbol
*) src
);
2218 /* In an expression, transfer the settings of these flags.
2219 The user can override later, of course. */
2220 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT \
2221 | BSF_GNU_INDIRECT_FUNCTION)
2222 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
2224 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
2225 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2228 #ifdef TC_COPY_SYMBOL_ATTRIBUTES
2229 TC_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2234 S_IS_FUNCTION (symbolS
*s
)
2238 if (LOCAL_SYMBOL_CHECK (s
))
2241 flags
= s
->bsym
->flags
;
2243 return (flags
& BSF_FUNCTION
) != 0;
2247 S_IS_EXTERNAL (symbolS
*s
)
2251 if (LOCAL_SYMBOL_CHECK (s
))
2254 flags
= s
->bsym
->flags
;
2257 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2260 return (flags
& BSF_GLOBAL
) != 0;
2264 S_IS_WEAK (symbolS
*s
)
2266 if (LOCAL_SYMBOL_CHECK (s
))
2268 /* Conceptually, a weakrefr is weak if the referenced symbol is. We
2269 could probably handle a WEAKREFR as always weak though. E.g., if
2270 the referenced symbol has lost its weak status, there's no reason
2271 to keep handling the weakrefr as if it was weak. */
2272 if (S_IS_WEAKREFR (s
))
2273 return S_IS_WEAK (s
->sy_value
.X_add_symbol
);
2274 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
2278 S_IS_WEAKREFR (symbolS
*s
)
2280 if (LOCAL_SYMBOL_CHECK (s
))
2282 return s
->sy_flags
.sy_weakrefr
!= 0;
2286 S_IS_WEAKREFD (symbolS
*s
)
2288 if (LOCAL_SYMBOL_CHECK (s
))
2290 return s
->sy_flags
.sy_weakrefd
!= 0;
2294 S_IS_COMMON (symbolS
*s
)
2296 if (LOCAL_SYMBOL_CHECK (s
))
2298 return bfd_is_com_section (s
->bsym
->section
);
2302 S_IS_DEFINED (symbolS
*s
)
2304 if (LOCAL_SYMBOL_CHECK (s
))
2305 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
2306 return s
->bsym
->section
!= undefined_section
;
2310 #ifndef EXTERN_FORCE_RELOC
2311 #define EXTERN_FORCE_RELOC IS_ELF
2314 /* Return true for symbols that should not be reduced to section
2315 symbols or eliminated from expressions, because they may be
2316 overridden by the linker. */
2318 S_FORCE_RELOC (symbolS
*s
, int strict
)
2321 if (LOCAL_SYMBOL_CHECK (s
))
2322 sec
= ((struct local_symbol
*) s
)->lsy_section
;
2326 && ((s
->bsym
->flags
& BSF_WEAK
) != 0
2327 || (EXTERN_FORCE_RELOC
2328 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)))
2329 || (s
->bsym
->flags
& BSF_GNU_INDIRECT_FUNCTION
) != 0)
2331 sec
= s
->bsym
->section
;
2333 return bfd_is_und_section (sec
) || bfd_is_com_section (sec
);
2337 S_IS_DEBUG (symbolS
*s
)
2339 if (LOCAL_SYMBOL_CHECK (s
))
2341 if (s
->bsym
->flags
& BSF_DEBUGGING
)
2347 S_IS_LOCAL (symbolS
*s
)
2352 if (LOCAL_SYMBOL_CHECK (s
))
2355 flags
= s
->bsym
->flags
;
2358 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2361 if (bfd_asymbol_section (s
->bsym
) == reg_section
)
2364 if (flag_strip_local_absolute
2365 /* Keep BSF_FILE symbols in order to allow debuggers to identify
2366 the source file even when the object file is stripped. */
2367 && (flags
& (BSF_GLOBAL
| BSF_FILE
)) == 0
2368 && bfd_asymbol_section (s
->bsym
) == absolute_section
)
2371 name
= S_GET_NAME (s
);
2372 return (name
!= NULL
2374 && (strchr (name
, DOLLAR_LABEL_CHAR
)
2375 || strchr (name
, LOCAL_LABEL_CHAR
)
2376 #if FAKE_LABEL_CHAR != DOLLAR_LABEL_CHAR
2377 || strchr (name
, FAKE_LABEL_CHAR
)
2379 || TC_LABEL_IS_LOCAL (name
)
2380 || (! flag_keep_locals
2381 && (bfd_is_local_label (stdoutput
, s
->bsym
)
2384 && name
[1] == '?')))));
2388 S_IS_STABD (symbolS
*s
)
2390 return S_GET_NAME (s
) == 0;
2394 S_CAN_BE_REDEFINED (const symbolS
*s
)
2396 if (LOCAL_SYMBOL_CHECK (s
))
2397 return (local_symbol_get_frag ((struct local_symbol
*) s
)
2398 == &predefined_address_frag
);
2399 /* Permit register names to be redefined. */
2400 return s
->bsym
->section
== reg_section
;
2404 S_IS_VOLATILE (const symbolS
*s
)
2406 if (LOCAL_SYMBOL_CHECK (s
))
2408 return s
->sy_flags
.sy_volatile
;
2412 S_IS_FORWARD_REF (const symbolS
*s
)
2414 if (LOCAL_SYMBOL_CHECK (s
))
2416 return s
->sy_flags
.sy_forward_ref
;
2420 S_GET_NAME (symbolS
*s
)
2422 if (LOCAL_SYMBOL_CHECK (s
))
2423 return ((struct local_symbol
*) s
)->lsy_name
;
2424 return s
->bsym
->name
;
2428 S_GET_SEGMENT (symbolS
*s
)
2430 if (LOCAL_SYMBOL_CHECK (s
))
2431 return ((struct local_symbol
*) s
)->lsy_section
;
2432 return s
->bsym
->section
;
2436 S_SET_SEGMENT (symbolS
*s
, segT seg
)
2438 /* Don't reassign section symbols. The direct reason is to prevent seg
2439 faults assigning back to const global symbols such as *ABS*, but it
2440 shouldn't happen anyway. */
2442 if (LOCAL_SYMBOL_CHECK (s
))
2444 if (seg
== reg_section
)
2445 s
= local_symbol_convert ((struct local_symbol
*) s
);
2448 ((struct local_symbol
*) s
)->lsy_section
= seg
;
2453 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2455 if (s
->bsym
->section
!= seg
)
2459 s
->bsym
->section
= seg
;
2463 S_SET_EXTERNAL (symbolS
*s
)
2465 if (LOCAL_SYMBOL_CHECK (s
))
2466 s
= local_symbol_convert ((struct local_symbol
*) s
);
2467 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2469 /* Let .weak override .global. */
2472 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2474 /* Do not reassign section symbols. */
2475 as_warn (_("section symbols are already global"));
2478 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
2479 if (S_GET_SEGMENT (s
) == reg_section
)
2481 as_bad ("can't make register symbol `%s' global",
2486 s
->bsym
->flags
|= BSF_GLOBAL
;
2487 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
2490 if (! an_external_name
&& S_GET_NAME(s
)[0] != '.')
2491 an_external_name
= S_GET_NAME (s
);
2496 S_CLEAR_EXTERNAL (symbolS
*s
)
2498 if (LOCAL_SYMBOL_CHECK (s
))
2500 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2502 /* Let .weak override. */
2505 s
->bsym
->flags
|= BSF_LOCAL
;
2506 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
2510 S_SET_WEAK (symbolS
*s
)
2512 if (LOCAL_SYMBOL_CHECK (s
))
2513 s
= local_symbol_convert ((struct local_symbol
*) s
);
2514 #ifdef obj_set_weak_hook
2515 obj_set_weak_hook (s
);
2517 s
->bsym
->flags
|= BSF_WEAK
;
2518 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
2522 S_SET_WEAKREFR (symbolS
*s
)
2524 if (LOCAL_SYMBOL_CHECK (s
))
2525 s
= local_symbol_convert ((struct local_symbol
*) s
);
2526 s
->sy_flags
.sy_weakrefr
= 1;
2527 /* If the alias was already used, make sure we mark the target as
2528 used as well, otherwise it might be dropped from the symbol
2529 table. This may have unintended side effects if the alias is
2530 later redirected to another symbol, such as keeping the unused
2531 previous target in the symbol table. Since it will be weak, it's
2533 if (s
->sy_flags
.sy_used
)
2534 symbol_mark_used (s
->sy_value
.X_add_symbol
);
2538 S_CLEAR_WEAKREFR (symbolS
*s
)
2540 if (LOCAL_SYMBOL_CHECK (s
))
2542 s
->sy_flags
.sy_weakrefr
= 0;
2546 S_SET_WEAKREFD (symbolS
*s
)
2548 if (LOCAL_SYMBOL_CHECK (s
))
2549 s
= local_symbol_convert ((struct local_symbol
*) s
);
2550 s
->sy_flags
.sy_weakrefd
= 1;
2555 S_CLEAR_WEAKREFD (symbolS
*s
)
2557 if (LOCAL_SYMBOL_CHECK (s
))
2559 if (s
->sy_flags
.sy_weakrefd
)
2561 s
->sy_flags
.sy_weakrefd
= 0;
2562 /* If a weakref target symbol is weak, then it was never
2563 referenced directly before, not even in a .global directive,
2564 so decay it to local. If it remains undefined, it will be
2565 later turned into a global, like any other undefined
2567 if (s
->bsym
->flags
& BSF_WEAK
)
2569 #ifdef obj_clear_weak_hook
2570 obj_clear_weak_hook (s
);
2572 s
->bsym
->flags
&= ~BSF_WEAK
;
2573 s
->bsym
->flags
|= BSF_LOCAL
;
2579 S_SET_THREAD_LOCAL (symbolS
*s
)
2581 if (LOCAL_SYMBOL_CHECK (s
))
2582 s
= local_symbol_convert ((struct local_symbol
*) s
);
2583 if (bfd_is_com_section (s
->bsym
->section
)
2584 && (s
->bsym
->flags
& BSF_THREAD_LOCAL
) != 0)
2586 s
->bsym
->flags
|= BSF_THREAD_LOCAL
;
2587 if ((s
->bsym
->flags
& BSF_FUNCTION
) != 0)
2588 as_bad (_("Accessing function `%s' as thread-local object"),
2590 else if (! bfd_is_und_section (s
->bsym
->section
)
2591 && (s
->bsym
->section
->flags
& SEC_THREAD_LOCAL
) == 0)
2592 as_bad (_("Accessing `%s' as thread-local object"),
2597 S_SET_NAME (symbolS
*s
, const char *name
)
2599 if (LOCAL_SYMBOL_CHECK (s
))
2601 ((struct local_symbol
*) s
)->lsy_name
= name
;
2604 s
->bsym
->name
= name
;
2608 S_SET_VOLATILE (symbolS
*s
)
2610 if (LOCAL_SYMBOL_CHECK (s
))
2611 s
= local_symbol_convert ((struct local_symbol
*) s
);
2612 s
->sy_flags
.sy_volatile
= 1;
2616 S_CLEAR_VOLATILE (symbolS
*s
)
2618 if (!LOCAL_SYMBOL_CHECK (s
))
2619 s
->sy_flags
.sy_volatile
= 0;
2623 S_SET_FORWARD_REF (symbolS
*s
)
2625 if (LOCAL_SYMBOL_CHECK (s
))
2626 s
= local_symbol_convert ((struct local_symbol
*) s
);
2627 s
->sy_flags
.sy_forward_ref
= 1;
2630 /* Return the previous symbol in a chain. */
2633 symbol_previous (symbolS
*s
)
2635 if (LOCAL_SYMBOL_CHECK (s
))
2637 return s
->sy_previous
;
2640 /* Return the next symbol in a chain. */
2643 symbol_next (symbolS
*s
)
2645 if (LOCAL_SYMBOL_CHECK (s
))
2650 /* Return a pointer to the value of a symbol as an expression. */
2653 symbol_get_value_expression (symbolS
*s
)
2655 if (LOCAL_SYMBOL_CHECK (s
))
2656 s
= local_symbol_convert ((struct local_symbol
*) s
);
2657 return &s
->sy_value
;
2660 /* Set the value of a symbol to an expression. */
2663 symbol_set_value_expression (symbolS
*s
, const expressionS
*exp
)
2665 if (LOCAL_SYMBOL_CHECK (s
))
2666 s
= local_symbol_convert ((struct local_symbol
*) s
);
2668 S_CLEAR_WEAKREFR (s
);
2671 /* Return whether 2 symbols are the same. */
2674 symbol_same_p (symbolS
*s1
, symbolS
*s2
)
2676 s1
= get_real_sym (s1
);
2677 s2
= get_real_sym (s2
);
2681 /* Return a pointer to the X_add_number component of a symbol. */
2684 symbol_X_add_number (symbolS
*s
)
2686 if (LOCAL_SYMBOL_CHECK (s
))
2687 return (offsetT
*) &((struct local_symbol
*) s
)->lsy_value
;
2689 return &s
->sy_value
.X_add_number
;
2692 /* Set the value of SYM to the current position in the current segment. */
2695 symbol_set_value_now (symbolS
*sym
)
2697 S_SET_SEGMENT (sym
, now_seg
);
2698 S_SET_VALUE (sym
, frag_now_fix ());
2699 symbol_set_frag (sym
, frag_now
);
2702 /* Set the frag of a symbol. */
2705 symbol_set_frag (symbolS
*s
, fragS
*f
)
2707 if (LOCAL_SYMBOL_CHECK (s
))
2709 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
2713 S_CLEAR_WEAKREFR (s
);
2716 /* Return the frag of a symbol. */
2719 symbol_get_frag (symbolS
*s
)
2721 if (LOCAL_SYMBOL_CHECK (s
))
2722 return local_symbol_get_frag ((struct local_symbol
*) s
);
2726 /* Mark a symbol as having been used. */
2729 symbol_mark_used (symbolS
*s
)
2731 if (LOCAL_SYMBOL_CHECK (s
))
2733 s
->sy_flags
.sy_used
= 1;
2734 if (S_IS_WEAKREFR (s
))
2735 symbol_mark_used (s
->sy_value
.X_add_symbol
);
2738 /* Clear the mark of whether a symbol has been used. */
2741 symbol_clear_used (symbolS
*s
)
2743 if (LOCAL_SYMBOL_CHECK (s
))
2744 s
= local_symbol_convert ((struct local_symbol
*) s
);
2745 s
->sy_flags
.sy_used
= 0;
2748 /* Return whether a symbol has been used. */
2751 symbol_used_p (symbolS
*s
)
2753 if (LOCAL_SYMBOL_CHECK (s
))
2755 return s
->sy_flags
.sy_used
;
2758 /* Mark a symbol as having been used in a reloc. */
2761 symbol_mark_used_in_reloc (symbolS
*s
)
2763 if (LOCAL_SYMBOL_CHECK (s
))
2764 s
= local_symbol_convert ((struct local_symbol
*) s
);
2765 s
->sy_flags
.sy_used_in_reloc
= 1;
2768 /* Clear the mark of whether a symbol has been used in a reloc. */
2771 symbol_clear_used_in_reloc (symbolS
*s
)
2773 if (LOCAL_SYMBOL_CHECK (s
))
2775 s
->sy_flags
.sy_used_in_reloc
= 0;
2778 /* Return whether a symbol has been used in a reloc. */
2781 symbol_used_in_reloc_p (symbolS
*s
)
2783 if (LOCAL_SYMBOL_CHECK (s
))
2785 return s
->sy_flags
.sy_used_in_reloc
;
2788 /* Mark a symbol as an MRI common symbol. */
2791 symbol_mark_mri_common (symbolS
*s
)
2793 if (LOCAL_SYMBOL_CHECK (s
))
2794 s
= local_symbol_convert ((struct local_symbol
*) s
);
2795 s
->sy_flags
.sy_mri_common
= 1;
2798 /* Clear the mark of whether a symbol is an MRI common symbol. */
2801 symbol_clear_mri_common (symbolS
*s
)
2803 if (LOCAL_SYMBOL_CHECK (s
))
2805 s
->sy_flags
.sy_mri_common
= 0;
2808 /* Return whether a symbol is an MRI common symbol. */
2811 symbol_mri_common_p (symbolS
*s
)
2813 if (LOCAL_SYMBOL_CHECK (s
))
2815 return s
->sy_flags
.sy_mri_common
;
2818 /* Mark a symbol as having been written. */
2821 symbol_mark_written (symbolS
*s
)
2823 if (LOCAL_SYMBOL_CHECK (s
))
2825 s
->sy_flags
.sy_written
= 1;
2828 /* Clear the mark of whether a symbol has been written. */
2831 symbol_clear_written (symbolS
*s
)
2833 if (LOCAL_SYMBOL_CHECK (s
))
2835 s
->sy_flags
.sy_written
= 0;
2838 /* Return whether a symbol has been written. */
2841 symbol_written_p (symbolS
*s
)
2843 if (LOCAL_SYMBOL_CHECK (s
))
2845 return s
->sy_flags
.sy_written
;
2848 /* Mark a symbol has having been resolved. */
2851 symbol_mark_resolved (symbolS
*s
)
2853 if (LOCAL_SYMBOL_CHECK (s
))
2855 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2858 s
->sy_flags
.sy_resolved
= 1;
2861 /* Return whether a symbol has been resolved. */
2864 symbol_resolved_p (symbolS
*s
)
2866 if (LOCAL_SYMBOL_CHECK (s
))
2867 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2868 return s
->sy_flags
.sy_resolved
;
2871 /* Return whether a symbol is a section symbol. */
2874 symbol_section_p (symbolS
*s ATTRIBUTE_UNUSED
)
2876 if (LOCAL_SYMBOL_CHECK (s
))
2878 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2881 /* Return whether a symbol is equated to another symbol. */
2884 symbol_equated_p (symbolS
*s
)
2886 if (LOCAL_SYMBOL_CHECK (s
))
2888 return s
->sy_value
.X_op
== O_symbol
;
2891 /* Return whether a symbol is equated to another symbol, and should be
2892 treated specially when writing out relocs. */
2895 symbol_equated_reloc_p (symbolS
*s
)
2897 if (LOCAL_SYMBOL_CHECK (s
))
2899 /* X_op_symbol, normally not used for O_symbol, is set by
2900 resolve_symbol_value to flag expression syms that have been
2902 return (s
->sy_value
.X_op
== O_symbol
2903 #if defined (OBJ_COFF) && defined (TE_PE)
2906 && ((s
->sy_flags
.sy_resolved
&& s
->sy_value
.X_op_symbol
!= NULL
)
2907 || ! S_IS_DEFINED (s
)
2908 || S_IS_COMMON (s
)));
2911 /* Return whether a symbol has a constant value. */
2914 symbol_constant_p (symbolS
*s
)
2916 if (LOCAL_SYMBOL_CHECK (s
))
2918 return s
->sy_value
.X_op
== O_constant
;
2921 /* Return whether a symbol was cloned and thus removed from the global
2925 symbol_shadow_p (symbolS
*s
)
2927 if (LOCAL_SYMBOL_CHECK (s
))
2929 return s
->sy_next
== s
;
2932 /* If S was created as a struct symbol, return S, otherwise if S is a
2933 converted local_symbol return the converted symbol, otherwise
2937 symbol_symbolS (symbolS
*s
)
2939 if (LOCAL_SYMBOL_CHECK (s
))
2944 /* Return the BFD symbol for a symbol. */
2947 symbol_get_bfdsym (symbolS
*s
)
2949 if (LOCAL_SYMBOL_CHECK (s
))
2950 s
= local_symbol_convert ((struct local_symbol
*) s
);
2954 /* Set the BFD symbol for a symbol. */
2957 symbol_set_bfdsym (symbolS
*s
, asymbol
*bsym
)
2959 if (LOCAL_SYMBOL_CHECK (s
))
2960 s
= local_symbol_convert ((struct local_symbol
*) s
);
2961 /* Usually, it is harmless to reset a symbol to a BFD section
2962 symbol. For example, obj_elf_change_section sets the BFD symbol
2963 of an old symbol with the newly created section symbol. But when
2964 we have multiple sections with the same name, the newly created
2965 section may have the same name as an old section. We check if the
2966 old symbol has been already marked as a section symbol before
2968 if ((s
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
2970 /* else XXX - What do we do now ? */
2973 #ifdef OBJ_SYMFIELD_TYPE
2975 /* Get a pointer to the object format information for a symbol. */
2978 symbol_get_obj (symbolS
*s
)
2980 if (LOCAL_SYMBOL_CHECK (s
))
2981 s
= local_symbol_convert ((struct local_symbol
*) s
);
2985 /* Set the object format information for a symbol. */
2988 symbol_set_obj (symbolS
*s
, OBJ_SYMFIELD_TYPE
*o
)
2990 if (LOCAL_SYMBOL_CHECK (s
))
2991 s
= local_symbol_convert ((struct local_symbol
*) s
);
2995 #endif /* OBJ_SYMFIELD_TYPE */
2997 #ifdef TC_SYMFIELD_TYPE
2999 /* Get a pointer to the processor information for a symbol. */
3002 symbol_get_tc (symbolS
*s
)
3004 if (LOCAL_SYMBOL_CHECK (s
))
3005 s
= local_symbol_convert ((struct local_symbol
*) s
);
3009 /* Set the processor information for a symbol. */
3012 symbol_set_tc (symbolS
*s
, TC_SYMFIELD_TYPE
*o
)
3014 if (LOCAL_SYMBOL_CHECK (s
))
3015 s
= local_symbol_convert ((struct local_symbol
*) s
);
3019 #endif /* TC_SYMFIELD_TYPE */
3024 symbol_lastP
= NULL
;
3025 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
3026 sy_hash
= htab_create_alloc (16, hash_symbol_entry
, eq_symbol_entry
,
3027 NULL
, xcalloc
, free
);
3028 local_hash
= htab_create_alloc (16, hash_symbol_entry
, eq_symbol_entry
,
3029 NULL
, xcalloc
, free
);
3031 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
3032 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
3033 abs_symbol
.bsym
= bfd_abs_section_ptr
->symbol
;
3035 abs_symbol
.sy_value
.X_op
= O_constant
;
3036 abs_symbol
.sy_frag
= &zero_address_frag
;
3038 if (LOCAL_LABELS_FB
)
3043 dot_symbol_init (void)
3045 dot_symbol
.bsym
= bfd_make_empty_symbol (stdoutput
);
3046 if (dot_symbol
.bsym
== NULL
)
3047 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
3048 dot_symbol
.bsym
->name
= ".";
3049 dot_symbol
.sy_flags
.sy_forward_ref
= 1;
3050 dot_symbol
.sy_value
.X_op
= O_constant
;
3055 /* Maximum indent level.
3056 Available for modification inside a gdb session. */
3057 static int max_indent_level
= 8;
3060 print_symbol_value_1 (FILE *file
, symbolS
*sym
)
3062 const char *name
= S_GET_NAME (sym
);
3063 if (!name
|| !name
[0])
3065 fprintf (file
, "sym ");
3066 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) sym
));
3067 fprintf (file
, " %s", name
);
3069 if (LOCAL_SYMBOL_CHECK (sym
))
3071 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
3073 if (local_symbol_get_frag (locsym
) != & zero_address_frag
3074 && local_symbol_get_frag (locsym
) != NULL
)
3076 fprintf (file
, " frag ");
3077 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) local_symbol_get_frag (locsym
)));
3079 if (local_symbol_resolved_p (locsym
))
3080 fprintf (file
, " resolved");
3081 fprintf (file
, " local");
3085 if (sym
->sy_frag
!= &zero_address_frag
)
3087 fprintf (file
, " frag ");
3088 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) sym
->sy_frag
));
3090 if (sym
->sy_flags
.sy_written
)
3091 fprintf (file
, " written");
3092 if (sym
->sy_flags
.sy_resolved
)
3093 fprintf (file
, " resolved");
3094 else if (sym
->sy_flags
.sy_resolving
)
3095 fprintf (file
, " resolving");
3096 if (sym
->sy_flags
.sy_used_in_reloc
)
3097 fprintf (file
, " used-in-reloc");
3098 if (sym
->sy_flags
.sy_used
)
3099 fprintf (file
, " used");
3100 if (S_IS_LOCAL (sym
))
3101 fprintf (file
, " local");
3102 if (S_IS_EXTERNAL (sym
))
3103 fprintf (file
, " extern");
3104 if (S_IS_WEAK (sym
))
3105 fprintf (file
, " weak");
3106 if (S_IS_DEBUG (sym
))
3107 fprintf (file
, " debug");
3108 if (S_IS_DEFINED (sym
))
3109 fprintf (file
, " defined");
3111 if (S_IS_WEAKREFR (sym
))
3112 fprintf (file
, " weakrefr");
3113 if (S_IS_WEAKREFD (sym
))
3114 fprintf (file
, " weakrefd");
3115 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
3116 if (symbol_resolved_p (sym
))
3118 segT s
= S_GET_SEGMENT (sym
);
3120 if (s
!= undefined_section
3121 && s
!= expr_section
)
3122 fprintf (file
, " %lx", (unsigned long) S_GET_VALUE (sym
));
3124 else if (indent_level
< max_indent_level
3125 && S_GET_SEGMENT (sym
) != undefined_section
)
3128 fprintf (file
, "\n%*s<", indent_level
* 4, "");
3129 if (LOCAL_SYMBOL_CHECK (sym
))
3130 fprintf (file
, "constant %lx",
3131 (unsigned long) ((struct local_symbol
*) sym
)->lsy_value
);
3133 print_expr_1 (file
, &sym
->sy_value
);
3134 fprintf (file
, ">");
3141 print_symbol_value (symbolS
*sym
)
3144 print_symbol_value_1 (stderr
, sym
);
3145 fprintf (stderr
, "\n");
3149 print_binary (FILE *file
, const char *name
, expressionS
*exp
)
3152 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
3153 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3154 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3155 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3156 fprintf (file
, ">");
3161 print_expr_1 (FILE *file
, expressionS
*exp
)
3163 fprintf (file
, "expr ");
3164 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) exp
));
3165 fprintf (file
, " ");
3169 fprintf (file
, "illegal");
3172 fprintf (file
, "absent");
3175 fprintf (file
, "constant %lx", (unsigned long) exp
->X_add_number
);
3179 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
3180 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3181 fprintf (file
, ">");
3183 if (exp
->X_add_number
)
3184 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
3185 (unsigned long) exp
->X_add_number
);
3189 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
3192 fprintf (file
, "big");
3195 fprintf (file
, "uminus -<");
3197 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3198 fprintf (file
, ">");
3199 goto maybe_print_addnum
;
3201 fprintf (file
, "bit_not");
3204 print_binary (file
, "multiply", exp
);
3207 print_binary (file
, "divide", exp
);
3210 print_binary (file
, "modulus", exp
);
3213 print_binary (file
, "lshift", exp
);
3216 print_binary (file
, "rshift", exp
);
3218 case O_bit_inclusive_or
:
3219 print_binary (file
, "bit_ior", exp
);
3221 case O_bit_exclusive_or
:
3222 print_binary (file
, "bit_xor", exp
);
3225 print_binary (file
, "bit_and", exp
);
3228 print_binary (file
, "eq", exp
);
3231 print_binary (file
, "ne", exp
);
3234 print_binary (file
, "lt", exp
);
3237 print_binary (file
, "le", exp
);
3240 print_binary (file
, "ge", exp
);
3243 print_binary (file
, "gt", exp
);
3246 print_binary (file
, "logical_and", exp
);
3249 print_binary (file
, "logical_or", exp
);
3253 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
3254 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3255 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3256 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3257 fprintf (file
, ">");
3258 goto maybe_print_addnum
;
3261 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
3262 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3263 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3264 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3265 fprintf (file
, ">");
3266 goto maybe_print_addnum
;
3268 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
3275 print_expr (expressionS
*exp
)
3277 print_expr_1 (stderr
, exp
);
3278 fprintf (stderr
, "\n");
3282 symbol_print_statistics (FILE *file
)
3284 htab_print_statistics (file
, "symbol table", sy_hash
);
3285 htab_print_statistics (file
, "mini local symbol table", local_hash
);
3286 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
3287 local_symbol_count
, local_symbol_conversion_count
);
3290 #ifdef OBJ_COMPLEX_RELC
3292 /* Convert given symbol to a new complex-relocation symbol name. This
3293 may be a recursive function, since it might be called for non-leaf
3294 nodes (plain symbols) in the expression tree. The caller owns the
3295 returning string, so should free it eventually. Errors are
3296 indicated via as_bad and a NULL return value. The given symbol
3297 is marked with sy_used_in_reloc. */
3300 symbol_relc_make_sym (symbolS
* sym
)
3302 char * terminal
= NULL
;
3307 gas_assert (sym
!= NULL
);
3309 /* Recurse to symbol_relc_make_expr if this symbol
3310 is defined as an expression or a plain value. */
3311 if ( S_GET_SEGMENT (sym
) == expr_section
3312 || S_GET_SEGMENT (sym
) == absolute_section
)
3313 return symbol_relc_make_expr (symbol_get_value_expression (sym
));
3315 /* This may be a "fake symbol", referring to ".".
3316 Write out a special null symbol to refer to this position. */
3317 if (! strcmp (S_GET_NAME (sym
), FAKE_LABEL_NAME
))
3318 return xstrdup (".");
3320 /* We hope this is a plain leaf symbol. Construct the encoding
3321 as {S,s}II...:CCCCCCC....
3322 where 'S'/'s' means section symbol / plain symbol
3323 III is decimal for the symbol name length
3324 CCC is the symbol name itself. */
3325 symbol_mark_used_in_reloc (sym
);
3327 sname
= S_GET_NAME (sym
);
3328 sname_len
= strlen (sname
);
3329 typetag
= symbol_section_p (sym
) ? 'S' : 's';
3331 terminal
= XNEWVEC (char, (1 /* S or s */
3332 + 8 /* sname_len in decimal */
3334 + sname_len
/* name itself */
3337 sprintf (terminal
, "%c%d:%s", typetag
, sname_len
, sname
);
3341 /* Convert given value to a new complex-relocation symbol name. This
3342 is a non-recursive function, since it is be called for leaf nodes
3343 (plain values) in the expression tree. The caller owns the
3344 returning string, so should free() it eventually. No errors. */
3347 symbol_relc_make_value (offsetT val
)
3349 char * terminal
= XNEWVEC (char, 28); /* Enough for long long. */
3352 bfd_sprintf_vma (stdoutput
, terminal
+ 1, val
);
3356 /* Convert given expression to a new complex-relocation symbol name.
3357 This is a recursive function, since it traverses the entire given
3358 expression tree. The caller owns the returning string, so should
3359 free() it eventually. Errors are indicated via as_bad() and a NULL
3363 symbol_relc_make_expr (expressionS
* exp
)
3365 const char * opstr
= NULL
; /* Operator prefix string. */
3366 int arity
= 0; /* Arity of this operator. */
3367 char * operands
[3]; /* Up to three operands. */
3368 char * concat_string
= NULL
;
3370 operands
[0] = operands
[1] = operands
[2] = NULL
;
3372 gas_assert (exp
!= NULL
);
3374 /* Match known operators -> fill in opstr, arity, operands[] and fall
3375 through to construct subexpression fragments; may instead return
3376 string directly for leaf nodes. */
3378 /* See expr.h for the meaning of all these enums. Many operators
3379 have an unnatural arity (X_add_number implicitly added). The
3380 conversion logic expands them to explicit "+" subexpressions. */
3385 as_bad ("Unknown expression operator (enum %d)", exp
->X_op
);
3390 return symbol_relc_make_value (exp
->X_add_number
);
3393 if (exp
->X_add_number
)
3397 operands
[0] = symbol_relc_make_sym (exp
->X_add_symbol
);
3398 operands
[1] = symbol_relc_make_value (exp
->X_add_number
);
3402 return symbol_relc_make_sym (exp
->X_add_symbol
);
3404 /* Helper macros for nesting nodes. */
3406 #define HANDLE_XADD_OPT1(str_) \
3407 if (exp->X_add_number) \
3410 opstr = "+:" str_; \
3411 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3412 operands[1] = symbol_relc_make_value (exp->X_add_number); \
3419 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3423 #define HANDLE_XADD_OPT2(str_) \
3424 if (exp->X_add_number) \
3427 opstr = "+:" str_; \
3428 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3429 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3430 operands[2] = symbol_relc_make_value (exp->X_add_number); \
3436 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3437 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3441 /* Nesting nodes. */
3443 case O_uminus
: HANDLE_XADD_OPT1 ("0-");
3444 case O_bit_not
: HANDLE_XADD_OPT1 ("~");
3445 case O_logical_not
: HANDLE_XADD_OPT1 ("!");
3446 case O_multiply
: HANDLE_XADD_OPT2 ("*");
3447 case O_divide
: HANDLE_XADD_OPT2 ("/");
3448 case O_modulus
: HANDLE_XADD_OPT2 ("%");
3449 case O_left_shift
: HANDLE_XADD_OPT2 ("<<");
3450 case O_right_shift
: HANDLE_XADD_OPT2 (">>");
3451 case O_bit_inclusive_or
: HANDLE_XADD_OPT2 ("|");
3452 case O_bit_exclusive_or
: HANDLE_XADD_OPT2 ("^");
3453 case O_bit_and
: HANDLE_XADD_OPT2 ("&");
3454 case O_add
: HANDLE_XADD_OPT2 ("+");
3455 case O_subtract
: HANDLE_XADD_OPT2 ("-");
3456 case O_eq
: HANDLE_XADD_OPT2 ("==");
3457 case O_ne
: HANDLE_XADD_OPT2 ("!=");
3458 case O_lt
: HANDLE_XADD_OPT2 ("<");
3459 case O_le
: HANDLE_XADD_OPT2 ("<=");
3460 case O_ge
: HANDLE_XADD_OPT2 (">=");
3461 case O_gt
: HANDLE_XADD_OPT2 (">");
3462 case O_logical_and
: HANDLE_XADD_OPT2 ("&&");
3463 case O_logical_or
: HANDLE_XADD_OPT2 ("||");
3466 /* Validate & reject early. */
3467 if (arity
>= 1 && ((operands
[0] == NULL
) || (strlen (operands
[0]) == 0)))
3469 if (arity
>= 2 && ((operands
[1] == NULL
) || (strlen (operands
[1]) == 0)))
3471 if (arity
>= 3 && ((operands
[2] == NULL
) || (strlen (operands
[2]) == 0)))
3475 concat_string
= NULL
;
3476 else if (arity
== 0)
3477 concat_string
= xstrdup (opstr
);
3478 else if (arity
== 1)
3479 concat_string
= concat (opstr
, ":", operands
[0], (char *) NULL
);
3480 else if (arity
== 2)
3481 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1],
3484 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1], ":",
3485 operands
[2], (char *) NULL
);
3487 /* Free operand strings (not opstr). */
3488 if (arity
>= 1) xfree (operands
[0]);
3489 if (arity
>= 2) xfree (operands
[1]);
3490 if (arity
>= 3) xfree (operands
[2]);
3492 return concat_string
;