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
;
154 #define local_symbol_converted_p(l) ((l)->lsy_section == reg_section)
155 #define local_symbol_mark_converted(l) ((l)->lsy_section = reg_section)
156 #define local_symbol_resolved_p(l) ((l)->lsy_flags.sy_resolved)
157 #define local_symbol_mark_resolved(l) ((l)->lsy_flags.sy_resolved = 1)
158 #define local_symbol_get_frag(l) ((l)->u.lsy_frag)
159 #define local_symbol_set_frag(l, f) ((l)->u.lsy_frag = (f))
160 #define local_symbol_get_real_symbol(l) ((l)->u.lsy_sym)
161 #define local_symbol_set_real_symbol(l, s) ((l)->u.lsy_sym = (s))
163 /* This is non-zero if symbols are case sensitive, which is the
165 int symbols_case_sensitive
= 1;
167 #ifndef WORKING_DOT_WORD
168 extern int new_broken_words
;
171 /* symbol-name => struct symbol pointer */
172 static struct hash_control
*sy_hash
;
174 /* Table of local symbols. */
175 static struct hash_control
*local_hash
;
177 /* Below are commented in "symbols.h". */
178 symbolS
*symbol_rootP
;
179 symbolS
*symbol_lastP
;
184 #define debug_verify_symchain verify_symbol_chain
186 #define debug_verify_symchain(root, last) ((void) 0)
189 #define DOLLAR_LABEL_CHAR '\001'
190 #define LOCAL_LABEL_CHAR '\002'
192 #ifndef TC_LABEL_IS_LOCAL
193 #define TC_LABEL_IS_LOCAL(name) 0
196 struct obstack notes
;
198 /* The name of an external symbol which is
199 used to make weak PE symbol names unique. */
200 const char * an_external_name
;
203 static const char *save_symbol_name (const char *);
204 static void fb_label_init (void);
205 static long dollar_label_instance (long);
206 static long fb_label_instance (long);
208 static void print_binary (FILE *, const char *, expressionS
*);
210 /* Return a pointer to a new symbol. Die if we can't make a new
211 symbol. Fill in the symbol's values. Add symbol to end of symbol
214 This function should be called in the general case of creating a
215 symbol. However, if the output file symbol table has already been
216 set, and you are certain that this symbol won't be wanted in the
217 output file, you can call symbol_create. */
220 symbol_new (const char *name
, segT segment
, valueT valu
, fragS
*frag
)
222 symbolS
*symbolP
= symbol_create (name
, segment
, valu
, frag
);
224 /* Link to end of symbol chain. */
226 extern int symbol_table_frozen
;
227 if (symbol_table_frozen
)
230 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
235 /* Save a symbol name on a permanent obstack, and convert it according
236 to the object file format. */
239 save_symbol_name (const char *name
)
244 gas_assert (name
!= NULL
);
245 name_length
= strlen (name
) + 1; /* +1 for \0. */
246 obstack_grow (¬es
, name
, name_length
);
247 ret
= (char *) obstack_finish (¬es
);
249 #ifdef tc_canonicalize_symbol_name
250 ret
= tc_canonicalize_symbol_name (ret
);
253 if (! symbols_case_sensitive
)
257 for (s
= ret
; *s
!= '\0'; s
++)
265 symbol_create (const char *name
, /* It is copied, the caller can destroy/modify. */
266 segT segment
, /* Segment identifier (SEG_<something>). */
267 valueT valu
, /* Symbol value. */
268 fragS
*frag
/* Associated fragment. */)
270 const char *preserved_copy_of_name
;
273 preserved_copy_of_name
= save_symbol_name (name
);
275 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
277 /* symbol must be born in some fixed state. This seems as good as any. */
278 memset (symbolP
, 0, sizeof (symbolS
));
280 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
281 if (symbolP
->bsym
== NULL
)
282 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
283 S_SET_NAME (symbolP
, preserved_copy_of_name
);
285 S_SET_SEGMENT (symbolP
, segment
);
286 S_SET_VALUE (symbolP
, valu
);
287 symbol_clear_list_pointers (symbolP
);
289 symbolP
->sy_frag
= frag
;
291 obj_symbol_new_hook (symbolP
);
293 #ifdef tc_symbol_new_hook
294 tc_symbol_new_hook (symbolP
);
301 /* Local symbol support. If we can get away with it, we keep only a
302 small amount of information for local symbols. */
304 static symbolS
*local_symbol_convert (struct local_symbol
*);
306 /* Used for statistics. */
308 static unsigned long local_symbol_count
;
309 static unsigned long local_symbol_conversion_count
;
311 /* This macro is called with a symbol argument passed by reference.
312 It returns whether this is a local symbol. If necessary, it
313 changes its argument to the real symbol. */
315 #define LOCAL_SYMBOL_CHECK(s) \
316 (s->sy_flags.sy_local_symbol \
317 ? (local_symbol_converted_p ((struct local_symbol *) s) \
318 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
323 /* Create a local symbol and insert it into the local hash table. */
325 struct local_symbol
*
326 local_symbol_make (const char *name
, segT section
, valueT val
, fragS
*frag
)
328 const char *name_copy
;
329 struct local_symbol
*ret
;
331 ++local_symbol_count
;
333 name_copy
= save_symbol_name (name
);
335 ret
= (struct local_symbol
*) obstack_alloc (¬es
, sizeof *ret
);
336 ret
->lsy_flags
.sy_local_symbol
= 1;
337 ret
->lsy_flags
.sy_resolved
= 0;
338 ret
->lsy_name
= name_copy
;
339 ret
->lsy_section
= section
;
340 local_symbol_set_frag (ret
, frag
);
341 ret
->lsy_value
= val
;
343 hash_jam (local_hash
, name_copy
, (void *) ret
);
348 /* Convert a local symbol into a real symbol. Note that we do not
349 reclaim the space used by the local symbol. */
352 local_symbol_convert (struct local_symbol
*locsym
)
356 gas_assert (locsym
->lsy_flags
.sy_local_symbol
);
357 if (local_symbol_converted_p (locsym
))
358 return local_symbol_get_real_symbol (locsym
);
360 ++local_symbol_conversion_count
;
362 ret
= symbol_new (locsym
->lsy_name
, locsym
->lsy_section
, locsym
->lsy_value
,
363 local_symbol_get_frag (locsym
));
365 if (local_symbol_resolved_p (locsym
))
366 ret
->sy_flags
.sy_resolved
= 1;
368 /* Local symbols are always either defined or used. */
369 ret
->sy_flags
.sy_used
= 1;
371 #ifdef TC_LOCAL_SYMFIELD_CONVERT
372 TC_LOCAL_SYMFIELD_CONVERT (locsym
, ret
);
375 symbol_table_insert (ret
);
377 local_symbol_mark_converted (locsym
);
378 local_symbol_set_real_symbol (locsym
, ret
);
380 hash_jam (local_hash
, locsym
->lsy_name
, NULL
);
386 define_sym_at_dot (symbolS
*symbolP
)
388 symbolP
->sy_frag
= frag_now
;
389 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
390 S_SET_SEGMENT (symbolP
, now_seg
);
393 /* We have just seen "<name>:".
394 Creates a struct symbol unless it already exists.
396 Gripes if we are redefining a symbol incompatibly (and ignores it). */
399 colon (/* Just seen "x:" - rattle symbols & frags. */
400 const char *sym_name
/* Symbol name, as a canonical string. */
401 /* We copy this string: OK to alter later. */)
403 symbolS
*symbolP
; /* Symbol we are working with. */
405 /* Sun local labels go out of scope whenever a non-local symbol is
407 if (LOCAL_LABELS_DOLLAR
408 && !bfd_is_local_label_name (stdoutput
, sym_name
))
409 dollar_label_clear ();
411 #ifndef WORKING_DOT_WORD
412 if (new_broken_words
)
414 struct broken_word
*a
;
419 if (now_seg
== absolute_section
)
421 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
425 possible_bytes
= (md_short_jump_size
426 + new_broken_words
* md_long_jump_size
);
429 frag_opcode
= frag_var (rs_broken_word
,
433 (symbolS
*) broken_words
,
437 /* We want to store the pointer to where to insert the jump
438 table in the fr_opcode of the rs_broken_word frag. This
439 requires a little hackery. */
441 && (frag_tmp
->fr_type
!= rs_broken_word
442 || frag_tmp
->fr_opcode
))
443 frag_tmp
= frag_tmp
->fr_next
;
445 frag_tmp
->fr_opcode
= frag_opcode
;
446 new_broken_words
= 0;
448 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
449 a
->dispfrag
= frag_tmp
;
451 #endif /* WORKING_DOT_WORD */
453 #ifdef obj_frob_colon
454 obj_frob_colon (sym_name
);
457 if ((symbolP
= symbol_find (sym_name
)) != 0)
459 S_CLEAR_WEAKREFR (symbolP
);
460 #ifdef RESOLVE_SYMBOL_REDEFINITION
461 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
464 /* Now check for undefined symbols. */
465 if (LOCAL_SYMBOL_CHECK (symbolP
))
467 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
469 if (locsym
->lsy_section
!= undefined_section
470 && (local_symbol_get_frag (locsym
) != frag_now
471 || locsym
->lsy_section
!= now_seg
472 || locsym
->lsy_value
!= frag_now_fix ()))
474 as_bad (_("symbol `%s' is already defined"), sym_name
);
478 locsym
->lsy_section
= now_seg
;
479 local_symbol_set_frag (locsym
, frag_now
);
480 locsym
->lsy_value
= frag_now_fix ();
482 else if (!(S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
483 || S_IS_COMMON (symbolP
)
484 || S_IS_VOLATILE (symbolP
))
486 if (S_IS_VOLATILE (symbolP
))
488 symbolP
= symbol_clone (symbolP
, 1);
489 S_SET_VALUE (symbolP
, 0);
490 S_CLEAR_VOLATILE (symbolP
);
492 if (S_GET_VALUE (symbolP
) == 0)
494 define_sym_at_dot (symbolP
);
497 #endif /* if we have one, it better be zero. */
502 /* There are still several cases to check:
504 A .comm/.lcomm symbol being redefined as initialized
507 A .comm/.lcomm symbol being redefined with a larger
510 This only used to be allowed on VMS gas, but Sun cc
511 on the sparc also depends on it. */
513 if (((!S_IS_DEBUG (symbolP
)
514 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
515 && S_IS_EXTERNAL (symbolP
))
516 || S_GET_SEGMENT (symbolP
) == bss_section
)
517 && (now_seg
== data_section
518 || now_seg
== bss_section
519 || now_seg
== S_GET_SEGMENT (symbolP
)))
521 /* Select which of the 2 cases this is. */
522 if (now_seg
!= data_section
)
524 /* New .comm for prev .comm symbol.
526 If the new size is larger we just change its
527 value. If the new size is smaller, we ignore
529 if (S_GET_VALUE (symbolP
)
530 < ((unsigned) frag_now_fix ()))
532 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
537 /* It is a .comm/.lcomm being converted to initialized
539 define_sym_at_dot (symbolP
);
544 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT))
545 static const char *od_buf
= "";
549 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
550 sprintf (od_buf
, "%d.%d.",
551 S_GET_OTHER (symbolP
),
552 S_GET_DESC (symbolP
));
554 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
556 segment_name (S_GET_SEGMENT (symbolP
)),
558 (long) S_GET_VALUE (symbolP
));
560 } /* if the undefined symbol has no value */
564 /* Don't blow up if the definition is the same. */
565 if (!(frag_now
== symbolP
->sy_frag
566 && S_GET_VALUE (symbolP
) == frag_now_fix ()
567 && S_GET_SEGMENT (symbolP
) == now_seg
))
569 as_bad (_("symbol `%s' is already defined"), sym_name
);
570 symbolP
= symbol_clone (symbolP
, 0);
571 define_sym_at_dot (symbolP
);
576 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
578 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
,
579 (valueT
) frag_now_fix (),
584 symbolP
= symbol_new (sym_name
, now_seg
, (valueT
) frag_now_fix (),
587 symbol_table_insert (symbolP
);
590 if (mri_common_symbol
!= NULL
)
592 /* This symbol is actually being defined within an MRI common
593 section. This requires special handling. */
594 if (LOCAL_SYMBOL_CHECK (symbolP
))
595 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
596 symbolP
->sy_value
.X_op
= O_symbol
;
597 symbolP
->sy_value
.X_add_symbol
= mri_common_symbol
;
598 symbolP
->sy_value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
599 symbolP
->sy_frag
= &zero_address_frag
;
600 S_SET_SEGMENT (symbolP
, expr_section
);
601 symbolP
->sy_flags
.sy_mri_common
= 1;
605 tc_frob_label (symbolP
);
607 #ifdef obj_frob_label
608 obj_frob_label (symbolP
);
614 /* Die if we can't insert the symbol. */
617 symbol_table_insert (symbolS
*symbolP
)
619 const char *error_string
;
622 know (S_GET_NAME (symbolP
));
624 if (LOCAL_SYMBOL_CHECK (symbolP
))
626 error_string
= hash_jam (local_hash
, S_GET_NAME (symbolP
),
628 if (error_string
!= NULL
)
629 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
630 S_GET_NAME (symbolP
), error_string
);
634 if ((error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (void *) symbolP
)))
636 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
637 S_GET_NAME (symbolP
), error_string
);
641 /* If a symbol name does not exist, create it as undefined, and insert
642 it into the symbol table. Return a pointer to it. */
645 symbol_find_or_make (const char *name
)
649 symbolP
= symbol_find (name
);
653 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
655 symbolP
= md_undefined_symbol ((char *) name
);
659 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
665 symbolP
= symbol_make (name
);
667 symbol_table_insert (symbolP
);
668 } /* if symbol wasn't found */
674 symbol_make (const char *name
)
678 /* Let the machine description default it, e.g. for register names. */
679 symbolP
= md_undefined_symbol ((char *) name
);
682 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
688 symbol_clone (symbolS
*orgsymP
, int replace
)
691 asymbol
*bsymorg
, *bsymnew
;
693 /* Make sure we never clone the dot special symbol. */
694 gas_assert (orgsymP
!= &dot_symbol
);
696 /* Running local_symbol_convert on a clone that's not the one currently
697 in local_hash would incorrectly replace the hash entry. Thus the
698 symbol must be converted here. Note that the rest of the function
699 depends on not encountering an unconverted symbol. */
700 if (LOCAL_SYMBOL_CHECK (orgsymP
))
701 orgsymP
= local_symbol_convert ((struct local_symbol
*) orgsymP
);
702 bsymorg
= orgsymP
->bsym
;
704 newsymP
= (symbolS
*) obstack_alloc (¬es
, sizeof (*newsymP
));
706 bsymnew
= bfd_make_empty_symbol (bfd_asymbol_bfd (bsymorg
));
708 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
709 newsymP
->bsym
= bsymnew
;
710 bsymnew
->name
= bsymorg
->name
;
711 bsymnew
->flags
= bsymorg
->flags
& ~BSF_SECTION_SYM
;
712 bsymnew
->section
= bsymorg
->section
;
713 bfd_copy_private_symbol_data (bfd_asymbol_bfd (bsymorg
), bsymorg
,
714 bfd_asymbol_bfd (bsymnew
), bsymnew
);
716 #ifdef obj_symbol_clone_hook
717 obj_symbol_clone_hook (newsymP
, orgsymP
);
720 #ifdef tc_symbol_clone_hook
721 tc_symbol_clone_hook (newsymP
, orgsymP
);
726 if (symbol_rootP
== orgsymP
)
727 symbol_rootP
= newsymP
;
728 else if (orgsymP
->sy_previous
)
730 orgsymP
->sy_previous
->sy_next
= newsymP
;
731 orgsymP
->sy_previous
= NULL
;
733 if (symbol_lastP
== orgsymP
)
734 symbol_lastP
= newsymP
;
735 else if (orgsymP
->sy_next
)
736 orgsymP
->sy_next
->sy_previous
= newsymP
;
738 /* Symbols that won't be output can't be external. */
739 S_CLEAR_EXTERNAL (orgsymP
);
740 orgsymP
->sy_previous
= orgsymP
->sy_next
= orgsymP
;
741 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
743 symbol_table_insert (newsymP
);
747 /* Symbols that won't be output can't be external. */
748 S_CLEAR_EXTERNAL (newsymP
);
749 newsymP
->sy_previous
= newsymP
->sy_next
= newsymP
;
755 /* If S is a local symbol that has been converted, return the
756 converted symbol. Otherwise return S. */
758 static inline symbolS
*
759 get_real_sym (symbolS
*s
)
762 && s
->sy_flags
.sy_local_symbol
763 && local_symbol_converted_p ((struct local_symbol
*) s
))
764 s
= local_symbol_get_real_symbol ((struct local_symbol
*) s
);
768 /* Referenced symbols, if they are forward references, need to be cloned
769 (without replacing the original) so that the value of the referenced
770 symbols at the point of use is saved by the clone. */
772 #undef symbol_clone_if_forward_ref
774 symbol_clone_if_forward_ref (symbolS
*symbolP
, int is_forward
)
776 if (symbolP
&& !LOCAL_SYMBOL_CHECK (symbolP
))
778 symbolS
*orig_add_symbol
= get_real_sym (symbolP
->sy_value
.X_add_symbol
);
779 symbolS
*orig_op_symbol
= get_real_sym (symbolP
->sy_value
.X_op_symbol
);
780 symbolS
*add_symbol
= orig_add_symbol
;
781 symbolS
*op_symbol
= orig_op_symbol
;
783 if (symbolP
->sy_flags
.sy_forward_ref
)
788 /* assign_symbol() clones volatile symbols; pre-existing expressions
789 hold references to the original instance, but want the current
790 value. Just repeat the lookup. */
791 if (add_symbol
&& S_IS_VOLATILE (add_symbol
))
792 add_symbol
= symbol_find_exact (S_GET_NAME (add_symbol
));
793 if (op_symbol
&& S_IS_VOLATILE (op_symbol
))
794 op_symbol
= symbol_find_exact (S_GET_NAME (op_symbol
));
797 /* Re-using sy_resolving here, as this routine cannot get called from
798 symbol resolution code. */
799 if ((symbolP
->bsym
->section
== expr_section
800 || symbolP
->sy_flags
.sy_forward_ref
)
801 && !symbolP
->sy_flags
.sy_resolving
)
803 symbolP
->sy_flags
.sy_resolving
= 1;
804 add_symbol
= symbol_clone_if_forward_ref (add_symbol
, is_forward
);
805 op_symbol
= symbol_clone_if_forward_ref (op_symbol
, is_forward
);
806 symbolP
->sy_flags
.sy_resolving
= 0;
809 if (symbolP
->sy_flags
.sy_forward_ref
810 || add_symbol
!= orig_add_symbol
811 || op_symbol
!= orig_op_symbol
)
813 if (symbolP
!= &dot_symbol
)
815 symbolP
= symbol_clone (symbolP
, 0);
816 symbolP
->sy_flags
.sy_resolving
= 0;
820 symbolP
= symbol_temp_new_now ();
821 #ifdef tc_new_dot_label
822 tc_new_dot_label (symbolP
);
827 symbolP
->sy_value
.X_add_symbol
= add_symbol
;
828 symbolP
->sy_value
.X_op_symbol
= op_symbol
;
835 symbol_temp_new (segT seg
, valueT ofs
, fragS
*frag
)
837 return symbol_new (FAKE_LABEL_NAME
, seg
, ofs
, frag
);
841 symbol_temp_new_now (void)
843 return symbol_temp_new (now_seg
, frag_now_fix (), frag_now
);
847 symbol_temp_new_now_octets (void)
849 return symbol_temp_new (now_seg
, frag_now_fix_octets (), frag_now
);
853 symbol_temp_make (void)
855 return symbol_make (FAKE_LABEL_NAME
);
858 /* Implement symbol table lookup.
859 In: A symbol's name as a string: '\0' can't be part of a symbol name.
860 Out: NULL if the name was not in the symbol table, else the address
861 of a struct symbol associated with that name. */
864 symbol_find_exact (const char *name
)
866 return symbol_find_exact_noref (name
, 0);
870 symbol_find_exact_noref (const char *name
, int noref
)
872 struct local_symbol
*locsym
;
875 locsym
= (struct local_symbol
*) hash_find (local_hash
, name
);
877 return (symbolS
*) locsym
;
879 sym
= ((symbolS
*) hash_find (sy_hash
, name
));
881 /* Any references to the symbol, except for the reference in
882 .weakref, must clear this flag, such that the symbol does not
883 turn into a weak symbol. Note that we don't have to handle the
884 local_symbol case, since a weakrefd is always promoted out of the
885 local_symbol table when it is turned into a weak symbol. */
887 S_CLEAR_WEAKREFD (sym
);
893 symbol_find (const char *name
)
895 return symbol_find_noref (name
, 0);
899 symbol_find_noref (const char *name
, int noref
)
904 #ifdef tc_canonicalize_symbol_name
906 copy
= xstrdup (name
);
907 name
= tc_canonicalize_symbol_name (copy
);
911 if (! symbols_case_sensitive
)
920 name
= copy
= XNEWVEC (char, strlen (name
) + 1);
922 while ((c
= *orig
++) != '\0')
923 *copy
++ = TOUPPER (c
);
928 copy
= (char *) name
;
931 result
= symbol_find_exact_noref (name
, noref
);
937 /* Once upon a time, symbols were kept in a singly linked list. At
938 least coff needs to be able to rearrange them from time to time, for
939 which a doubly linked list is much more convenient. Loic did these
940 as macros which seemed dangerous to me so they're now functions.
943 /* Link symbol ADDME after symbol TARGET in the chain. */
946 symbol_append (symbolS
*addme
, symbolS
*target
,
947 symbolS
**rootPP
, symbolS
**lastPP
)
949 if (LOCAL_SYMBOL_CHECK (addme
))
951 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
956 know (*rootPP
== NULL
);
957 know (*lastPP
== NULL
);
958 addme
->sy_next
= NULL
;
959 addme
->sy_previous
= NULL
;
963 } /* if the list is empty */
965 if (target
->sy_next
!= NULL
)
967 target
->sy_next
->sy_previous
= addme
;
971 know (*lastPP
== target
);
973 } /* if we have a next */
975 addme
->sy_next
= target
->sy_next
;
976 target
->sy_next
= addme
;
977 addme
->sy_previous
= target
;
979 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
982 /* Set the chain pointers of SYMBOL to null. */
985 symbol_clear_list_pointers (symbolS
*symbolP
)
987 if (LOCAL_SYMBOL_CHECK (symbolP
))
989 symbolP
->sy_next
= NULL
;
990 symbolP
->sy_previous
= NULL
;
993 /* Remove SYMBOLP from the list. */
996 symbol_remove (symbolS
*symbolP
, symbolS
**rootPP
, symbolS
**lastPP
)
998 if (LOCAL_SYMBOL_CHECK (symbolP
))
1001 if (symbolP
== *rootPP
)
1003 *rootPP
= symbolP
->sy_next
;
1004 } /* if it was the root */
1006 if (symbolP
== *lastPP
)
1008 *lastPP
= symbolP
->sy_previous
;
1009 } /* if it was the tail */
1011 if (symbolP
->sy_next
!= NULL
)
1013 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
1016 if (symbolP
->sy_previous
!= NULL
)
1018 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
1019 } /* if not first */
1021 debug_verify_symchain (*rootPP
, *lastPP
);
1024 /* Link symbol ADDME before symbol TARGET in the chain. */
1027 symbol_insert (symbolS
*addme
, symbolS
*target
,
1028 symbolS
**rootPP
, symbolS
**lastPP ATTRIBUTE_UNUSED
)
1030 if (LOCAL_SYMBOL_CHECK (addme
))
1032 if (LOCAL_SYMBOL_CHECK (target
))
1035 if (target
->sy_previous
!= NULL
)
1037 target
->sy_previous
->sy_next
= addme
;
1041 know (*rootPP
== target
);
1043 } /* if not first */
1045 addme
->sy_previous
= target
->sy_previous
;
1046 target
->sy_previous
= addme
;
1047 addme
->sy_next
= target
;
1049 debug_verify_symchain (*rootPP
, *lastPP
);
1053 verify_symbol_chain (symbolS
*rootP
, symbolS
*lastP
)
1055 symbolS
*symbolP
= rootP
;
1057 if (symbolP
== NULL
)
1060 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
1062 gas_assert (symbolP
->bsym
!= NULL
);
1063 gas_assert (symbolP
->sy_flags
.sy_local_symbol
== 0);
1064 gas_assert (symbolP
->sy_next
->sy_previous
== symbolP
);
1067 gas_assert (lastP
== symbolP
);
1071 symbol_on_chain (symbolS
*s
, symbolS
*rootPP
, symbolS
*lastPP
)
1073 return (!LOCAL_SYMBOL_CHECK (s
)
1074 && ((s
->sy_next
!= s
1075 && s
->sy_next
!= NULL
1076 && s
->sy_next
->sy_previous
== s
)
1078 && ((s
->sy_previous
!= s
1079 && s
->sy_previous
!= NULL
1080 && s
->sy_previous
->sy_next
== s
)
1084 #ifdef OBJ_COMPLEX_RELC
1087 use_complex_relocs_for (symbolS
* symp
)
1089 switch (symp
->sy_value
.X_op
)
1099 case O_bit_inclusive_or
:
1101 case O_bit_exclusive_or
:
1113 if ((S_IS_COMMON (symp
->sy_value
.X_op_symbol
)
1114 || S_IS_LOCAL (symp
->sy_value
.X_op_symbol
))
1115 && S_IS_DEFINED (symp
->sy_value
.X_op_symbol
)
1116 && S_GET_SEGMENT (symp
->sy_value
.X_op_symbol
) != expr_section
)
1123 if ((S_IS_COMMON (symp
->sy_value
.X_add_symbol
)
1124 || S_IS_LOCAL (symp
->sy_value
.X_add_symbol
))
1125 && S_IS_DEFINED (symp
->sy_value
.X_add_symbol
)
1126 && S_GET_SEGMENT (symp
->sy_value
.X_add_symbol
) != expr_section
)
1139 report_op_error (symbolS
*symp
, symbolS
*left
, operatorT op
, symbolS
*right
)
1143 segT seg_left
= left
? S_GET_SEGMENT (left
) : 0;
1144 segT seg_right
= S_GET_SEGMENT (right
);
1153 case O_uminus
: opname
= "-"; break;
1154 case O_bit_not
: opname
= "~"; break;
1155 case O_logical_not
: opname
= "!"; break;
1156 case O_multiply
: opname
= "*"; break;
1157 case O_divide
: opname
= "/"; break;
1158 case O_modulus
: opname
= "%"; break;
1159 case O_left_shift
: opname
= "<<"; break;
1160 case O_right_shift
: opname
= ">>"; break;
1161 case O_bit_inclusive_or
: opname
= "|"; break;
1162 case O_bit_or_not
: opname
= "|~"; break;
1163 case O_bit_exclusive_or
: opname
= "^"; break;
1164 case O_bit_and
: opname
= "&"; break;
1165 case O_add
: opname
= "+"; break;
1166 case O_subtract
: opname
= "-"; break;
1167 case O_eq
: opname
= "=="; break;
1168 case O_ne
: opname
= "!="; break;
1169 case O_lt
: opname
= "<"; break;
1170 case O_le
: opname
= "<="; break;
1171 case O_ge
: opname
= ">="; break;
1172 case O_gt
: opname
= ">"; break;
1173 case O_logical_and
: opname
= "&&"; break;
1174 case O_logical_or
: opname
= "||"; break;
1177 if (expr_symbol_where (symp
, &file
, &line
))
1180 as_bad_where (file
, line
,
1181 _("invalid operands (%s and %s sections) for `%s'"),
1182 seg_left
->name
, seg_right
->name
, opname
);
1184 as_bad_where (file
, line
,
1185 _("invalid operand (%s section) for `%s'"),
1186 seg_right
->name
, opname
);
1190 const char *sname
= S_GET_NAME (symp
);
1193 as_bad (_("invalid operands (%s and %s sections) for `%s' when setting `%s'"),
1194 seg_left
->name
, seg_right
->name
, opname
, sname
);
1196 as_bad (_("invalid operand (%s section) for `%s' when setting `%s'"),
1197 seg_right
->name
, opname
, sname
);
1201 /* Resolve the value of a symbol. This is called during the final
1202 pass over the symbol table to resolve any symbols with complex
1206 resolve_symbol_value (symbolS
*symp
)
1212 if (LOCAL_SYMBOL_CHECK (symp
))
1214 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1216 final_val
= locsym
->lsy_value
;
1217 if (local_symbol_resolved_p (locsym
))
1220 /* Symbols whose section has SEC_ELF_OCTETS set,
1221 resolve to octets instead of target bytes. */
1222 if (locsym
->lsy_section
->flags
& SEC_OCTETS
)
1223 final_val
+= local_symbol_get_frag (locsym
)->fr_address
;
1225 final_val
+= (local_symbol_get_frag (locsym
)->fr_address
1230 locsym
->lsy_value
= final_val
;
1231 local_symbol_mark_resolved (locsym
);
1237 if (symp
->sy_flags
.sy_resolved
)
1240 while (symp
->sy_value
.X_op
== O_symbol
)
1242 final_val
+= symp
->sy_value
.X_add_number
;
1243 symp
= symp
->sy_value
.X_add_symbol
;
1244 if (LOCAL_SYMBOL_CHECK (symp
))
1246 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1247 final_val
+= locsym
->lsy_value
;
1250 if (!symp
->sy_flags
.sy_resolved
)
1253 if (symp
->sy_value
.X_op
== O_constant
)
1254 final_val
+= symp
->sy_value
.X_add_number
;
1261 final_seg
= S_GET_SEGMENT (symp
);
1263 if (symp
->sy_flags
.sy_resolving
)
1266 as_bad (_("symbol definition loop encountered at `%s'"),
1271 #ifdef OBJ_COMPLEX_RELC
1272 else if (final_seg
== expr_section
1273 && use_complex_relocs_for (symp
))
1275 symbolS
* relc_symbol
= NULL
;
1276 char * relc_symbol_name
= NULL
;
1278 relc_symbol_name
= symbol_relc_make_expr (& symp
->sy_value
);
1280 /* For debugging, print out conversion input & output. */
1282 print_expr (& symp
->sy_value
);
1283 if (relc_symbol_name
)
1284 fprintf (stderr
, "-> relc symbol: %s\n", relc_symbol_name
);
1287 if (relc_symbol_name
!= NULL
)
1288 relc_symbol
= symbol_new (relc_symbol_name
, undefined_section
,
1289 0, & zero_address_frag
);
1291 if (relc_symbol
== NULL
)
1293 as_bad (_("cannot convert expression symbol %s to complex relocation"),
1299 symbol_table_insert (relc_symbol
);
1301 /* S_CLEAR_EXTERNAL (relc_symbol); */
1302 if (symp
->bsym
->flags
& BSF_SRELC
)
1303 relc_symbol
->bsym
->flags
|= BSF_SRELC
;
1305 relc_symbol
->bsym
->flags
|= BSF_RELC
;
1306 /* symp->bsym->flags |= BSF_RELC; */
1307 copy_symbol_attributes (symp
, relc_symbol
);
1308 symp
->sy_value
.X_op
= O_symbol
;
1309 symp
->sy_value
.X_add_symbol
= relc_symbol
;
1310 symp
->sy_value
.X_add_number
= 0;
1315 final_seg
= undefined_section
;
1316 goto exit_dont_set_value
;
1321 symbolS
*add_symbol
, *op_symbol
;
1322 offsetT left
, right
;
1323 segT seg_left
, seg_right
;
1327 symp
->sy_flags
.sy_resolving
= 1;
1329 /* Help out with CSE. */
1330 add_symbol
= symp
->sy_value
.X_add_symbol
;
1331 op_symbol
= symp
->sy_value
.X_op_symbol
;
1332 final_val
= symp
->sy_value
.X_add_number
;
1333 op
= symp
->sy_value
.X_op
;
1346 /* Symbols whose section has SEC_ELF_OCTETS set,
1347 resolve to octets instead of target bytes. */
1348 if (symp
->bsym
->section
->flags
& SEC_OCTETS
)
1349 final_val
+= symp
->sy_frag
->fr_address
;
1351 final_val
+= symp
->sy_frag
->fr_address
/ OCTETS_PER_BYTE
;
1352 if (final_seg
== expr_section
)
1353 final_seg
= absolute_section
;
1362 left
= resolve_symbol_value (add_symbol
);
1363 seg_left
= S_GET_SEGMENT (add_symbol
);
1365 symp
->sy_value
.X_op_symbol
= NULL
;
1368 if (S_IS_WEAKREFR (symp
))
1370 gas_assert (final_val
== 0);
1371 if (S_IS_WEAKREFR (add_symbol
))
1373 gas_assert (add_symbol
->sy_value
.X_op
== O_symbol
1374 && add_symbol
->sy_value
.X_add_number
== 0);
1375 add_symbol
= add_symbol
->sy_value
.X_add_symbol
;
1376 gas_assert (! S_IS_WEAKREFR (add_symbol
));
1377 symp
->sy_value
.X_add_symbol
= add_symbol
;
1381 if (symp
->sy_flags
.sy_mri_common
)
1383 /* This is a symbol inside an MRI common section. The
1384 relocation routines are going to handle it specially.
1385 Don't change the value. */
1386 resolved
= symbol_resolved_p (add_symbol
);
1390 /* Don't leave symbol loops. */
1392 && add_symbol
->sy_flags
.sy_resolving
)
1395 if (finalize_syms
&& final_val
== 0)
1397 if (LOCAL_SYMBOL_CHECK (add_symbol
))
1398 add_symbol
= local_symbol_convert ((struct local_symbol
*)
1400 copy_symbol_attributes (symp
, add_symbol
);
1403 /* If we have equated this symbol to an undefined or common
1404 symbol, keep X_op set to O_symbol, and don't change
1405 X_add_number. This permits the routine which writes out
1406 relocation to detect this case, and convert the
1407 relocation to be against the symbol to which this symbol
1409 if (seg_left
== undefined_section
1410 || bfd_is_com_section (seg_left
)
1411 #if defined (OBJ_COFF) && defined (TE_PE)
1412 || S_IS_WEAK (add_symbol
)
1415 && ((final_seg
== expr_section
1416 && seg_left
!= expr_section
1417 && seg_left
!= absolute_section
)
1418 || symbol_shadow_p (symp
))))
1422 symp
->sy_value
.X_op
= O_symbol
;
1423 symp
->sy_value
.X_add_symbol
= add_symbol
;
1424 symp
->sy_value
.X_add_number
= final_val
;
1425 /* Use X_op_symbol as a flag. */
1426 symp
->sy_value
.X_op_symbol
= add_symbol
;
1428 final_seg
= seg_left
;
1429 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1430 resolved
= symbol_resolved_p (add_symbol
);
1431 symp
->sy_flags
.sy_resolving
= 0;
1432 goto exit_dont_set_value
;
1436 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1437 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1438 final_seg
= seg_left
;
1441 resolved
= symbol_resolved_p (add_symbol
);
1442 if (S_IS_WEAKREFR (symp
))
1444 symp
->sy_flags
.sy_resolving
= 0;
1445 goto exit_dont_set_value
;
1452 left
= resolve_symbol_value (add_symbol
);
1453 seg_left
= S_GET_SEGMENT (add_symbol
);
1455 /* By reducing these to the relevant dyadic operator, we get
1456 !S -> S == 0 permitted on anything,
1457 -S -> 0 - S only permitted on absolute
1458 ~S -> S ^ ~0 only permitted on absolute */
1459 if (op
!= O_logical_not
&& seg_left
!= absolute_section
1461 report_op_error (symp
, NULL
, op
, add_symbol
);
1463 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1464 final_seg
= absolute_section
;
1468 else if (op
== O_logical_not
)
1473 final_val
+= left
+ symp
->sy_frag
->fr_address
;
1475 resolved
= symbol_resolved_p (add_symbol
);
1483 case O_bit_inclusive_or
:
1485 case O_bit_exclusive_or
:
1497 left
= resolve_symbol_value (add_symbol
);
1498 right
= resolve_symbol_value (op_symbol
);
1499 seg_left
= S_GET_SEGMENT (add_symbol
);
1500 seg_right
= S_GET_SEGMENT (op_symbol
);
1502 /* Simplify addition or subtraction of a constant by folding the
1503 constant into X_add_number. */
1506 if (seg_right
== absolute_section
)
1511 else if (seg_left
== absolute_section
)
1514 add_symbol
= op_symbol
;
1516 seg_left
= seg_right
;
1520 else if (op
== O_subtract
)
1522 if (seg_right
== absolute_section
)
1530 /* Equality and non-equality tests are permitted on anything.
1531 Subtraction, and other comparison operators are permitted if
1532 both operands are in the same section. Otherwise, both
1533 operands must be absolute. We already handled the case of
1534 addition or subtraction of a constant above. This will
1535 probably need to be changed for an object file format which
1536 supports arbitrary expressions. */
1537 if (!(seg_left
== absolute_section
1538 && seg_right
== absolute_section
)
1539 && !(op
== O_eq
|| op
== O_ne
)
1540 && !((op
== O_subtract
1541 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1542 && seg_left
== seg_right
1543 && (seg_left
!= undefined_section
1544 || add_symbol
== op_symbol
)))
1546 /* Don't emit messages unless we're finalizing the symbol value,
1547 otherwise we may get the same message multiple times. */
1549 report_op_error (symp
, add_symbol
, op
, op_symbol
);
1550 /* However do not move the symbol into the absolute section
1551 if it cannot currently be resolved - this would confuse
1552 other parts of the assembler into believing that the
1553 expression had been evaluated to zero. */
1559 && (final_seg
== expr_section
|| final_seg
== undefined_section
))
1560 final_seg
= absolute_section
;
1562 /* Check for division by zero. */
1563 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1565 /* If seg_right is not absolute_section, then we've
1566 already issued a warning about using a bad symbol. */
1567 if (seg_right
== absolute_section
&& finalize_syms
)
1572 if (expr_symbol_where (symp
, &file
, &line
))
1573 as_bad_where (file
, line
, _("division by zero"));
1575 as_bad (_("division by zero when setting `%s'"),
1582 switch (symp
->sy_value
.X_op
)
1584 case O_multiply
: left
*= right
; break;
1585 case O_divide
: left
/= right
; break;
1586 case O_modulus
: left
%= right
; break;
1587 case O_left_shift
: left
<<= right
; break;
1588 case O_right_shift
: left
>>= right
; break;
1589 case O_bit_inclusive_or
: left
|= right
; break;
1590 case O_bit_or_not
: left
|= ~right
; break;
1591 case O_bit_exclusive_or
: left
^= right
; break;
1592 case O_bit_and
: left
&= right
; break;
1593 case O_add
: left
+= right
; break;
1594 case O_subtract
: left
-= right
; break;
1597 left
= (left
== right
&& seg_left
== seg_right
1598 && (seg_left
!= undefined_section
1599 || add_symbol
== op_symbol
)
1600 ? ~ (offsetT
) 0 : 0);
1601 if (symp
->sy_value
.X_op
== O_ne
)
1604 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1605 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1606 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1607 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1608 case O_logical_and
: left
= left
&& right
; break;
1609 case O_logical_or
: left
= left
|| right
; break;
1614 /* See PR 20895 for a reproducer. */
1615 as_bad (_("Invalid operation on symbol"));
1616 goto exit_dont_set_value
;
1622 final_val
+= symp
->sy_frag
->fr_address
+ left
;
1623 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1625 if (seg_left
== undefined_section
1626 || seg_right
== undefined_section
)
1627 final_seg
= undefined_section
;
1628 else if (seg_left
== absolute_section
)
1629 final_seg
= seg_right
;
1631 final_seg
= seg_left
;
1633 resolved
= (symbol_resolved_p (add_symbol
)
1634 && symbol_resolved_p (op_symbol
));
1639 /* Give an error (below) if not in expr_section. We don't
1640 want to worry about expr_section symbols, because they
1641 are fictional (they are created as part of expression
1642 resolution), and any problems may not actually mean
1647 symp
->sy_flags
.sy_resolving
= 0;
1651 S_SET_VALUE (symp
, final_val
);
1653 exit_dont_set_value
:
1654 /* Always set the segment, even if not finalizing the value.
1655 The segment is used to determine whether a symbol is defined. */
1656 S_SET_SEGMENT (symp
, final_seg
);
1658 /* Don't worry if we can't resolve an expr_section symbol. */
1662 symp
->sy_flags
.sy_resolved
= 1;
1663 else if (S_GET_SEGMENT (symp
) != expr_section
)
1665 as_bad (_("can't resolve value for symbol `%s'"),
1667 symp
->sy_flags
.sy_resolved
= 1;
1674 static void resolve_local_symbol (const char *, void *);
1676 /* A static function passed to hash_traverse. */
1679 resolve_local_symbol (const char *key ATTRIBUTE_UNUSED
, void *value
)
1682 resolve_symbol_value ((symbolS
*) value
);
1685 /* Resolve all local symbols. */
1688 resolve_local_symbol_values (void)
1690 hash_traverse (local_hash
, resolve_local_symbol
);
1693 /* Obtain the current value of a symbol without changing any
1694 sub-expressions used. */
1697 snapshot_symbol (symbolS
**symbolPP
, valueT
*valueP
, segT
*segP
, fragS
**fragPP
)
1699 symbolS
*symbolP
= *symbolPP
;
1701 if (LOCAL_SYMBOL_CHECK (symbolP
))
1703 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1705 *valueP
= locsym
->lsy_value
;
1706 *segP
= locsym
->lsy_section
;
1707 *fragPP
= local_symbol_get_frag (locsym
);
1711 expressionS exp
= symbolP
->sy_value
;
1713 if (!symbolP
->sy_flags
.sy_resolved
&& exp
.X_op
!= O_illegal
)
1717 if (symbolP
->sy_flags
.sy_resolving
)
1719 symbolP
->sy_flags
.sy_resolving
= 1;
1720 resolved
= resolve_expression (&exp
);
1721 symbolP
->sy_flags
.sy_resolving
= 0;
1729 if (!symbol_equated_p (symbolP
))
1734 symbolP
= exp
.X_add_symbol
;
1741 *symbolPP
= symbolP
;
1743 /* A bogus input file can result in resolve_expression()
1744 generating a local symbol, so we have to check again. */
1745 if (LOCAL_SYMBOL_CHECK (symbolP
))
1747 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1749 *valueP
= locsym
->lsy_value
;
1750 *segP
= locsym
->lsy_section
;
1751 *fragPP
= local_symbol_get_frag (locsym
);
1755 *valueP
= exp
.X_add_number
;
1756 *segP
= symbolP
->bsym
->section
;
1757 *fragPP
= symbolP
->sy_frag
;
1760 if (*segP
== expr_section
)
1763 case O_constant
: *segP
= absolute_section
; break;
1764 case O_register
: *segP
= reg_section
; break;
1772 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1773 They are *really* local. That is, they go out of scope whenever we see a
1774 label that isn't local. Also, like fb labels, there can be multiple
1775 instances of a dollar label. Therefor, we name encode each instance with
1776 the instance number, keep a list of defined symbols separate from the real
1777 symbol table, and we treat these buggers as a sparse array. */
1779 static long *dollar_labels
;
1780 static long *dollar_label_instances
;
1781 static char *dollar_label_defines
;
1782 static unsigned long dollar_label_count
;
1783 static unsigned long dollar_label_max
;
1786 dollar_label_defined (long label
)
1790 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1792 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1794 return dollar_label_defines
[i
- dollar_labels
];
1796 /* If we get here, label isn't defined. */
1801 dollar_label_instance (long label
)
1805 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1807 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1809 return (dollar_label_instances
[i
- dollar_labels
]);
1811 /* If we get here, we haven't seen the label before.
1812 Therefore its instance count is zero. */
1817 dollar_label_clear (void)
1819 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1822 #define DOLLAR_LABEL_BUMP_BY 10
1825 define_dollar_label (long label
)
1829 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1832 ++dollar_label_instances
[i
- dollar_labels
];
1833 dollar_label_defines
[i
- dollar_labels
] = 1;
1837 /* If we get to here, we don't have label listed yet. */
1839 if (dollar_labels
== NULL
)
1841 dollar_labels
= XNEWVEC (long, DOLLAR_LABEL_BUMP_BY
);
1842 dollar_label_instances
= XNEWVEC (long, DOLLAR_LABEL_BUMP_BY
);
1843 dollar_label_defines
= XNEWVEC (char, DOLLAR_LABEL_BUMP_BY
);
1844 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1845 dollar_label_count
= 0;
1847 else if (dollar_label_count
== dollar_label_max
)
1849 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1850 dollar_labels
= XRESIZEVEC (long, dollar_labels
, dollar_label_max
);
1851 dollar_label_instances
= XRESIZEVEC (long, dollar_label_instances
,
1853 dollar_label_defines
= XRESIZEVEC (char, dollar_label_defines
,
1855 } /* if we needed to grow */
1857 dollar_labels
[dollar_label_count
] = label
;
1858 dollar_label_instances
[dollar_label_count
] = 1;
1859 dollar_label_defines
[dollar_label_count
] = 1;
1860 ++dollar_label_count
;
1863 /* Caller must copy returned name: we re-use the area for the next name.
1865 The mth occurrence of label n: is turned into the symbol "Ln^Am"
1866 where n is the label number and m is the instance number. "L" makes
1867 it a label discarded unless debugging and "^A"('\1') ensures no
1868 ordinary symbol SHOULD get the same name as a local label
1869 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1871 fb labels get the same treatment, except that ^B is used in place
1874 char * /* Return local label name. */
1875 dollar_label_name (long n
, /* we just saw "n$:" : n a number. */
1876 int augend
/* 0 for current instance, 1 for new instance. */)
1879 /* Returned to caller, then copied. Used for created names ("4f"). */
1880 static char symbol_name_build
[24];
1883 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1886 know (augend
== 0 || augend
== 1);
1887 p
= symbol_name_build
;
1888 #ifdef LOCAL_LABEL_PREFIX
1889 *p
++ = LOCAL_LABEL_PREFIX
;
1893 /* Next code just does sprintf( {}, "%d", n); */
1895 q
= symbol_name_temporary
;
1896 for (*q
++ = 0, i
= n
; i
; ++q
)
1901 while ((*p
= *--q
) != '\0')
1904 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1906 /* Instance number. */
1907 q
= symbol_name_temporary
;
1908 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1913 while ((*p
++ = *--q
) != '\0');
1915 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1916 return symbol_name_build
;
1919 /* Somebody else's idea of local labels. They are made by "n:" where n
1920 is any decimal digit. Refer to them with
1921 "nb" for previous (backward) n:
1922 or "nf" for next (forward) n:.
1924 We do a little better and let n be any number, not just a single digit, but
1925 since the other guy's assembler only does ten, we treat the first ten
1928 Like someone else's assembler, we have one set of local label counters for
1929 entire assembly, not one set per (sub)segment like in most assemblers. This
1930 implies that one can refer to a label in another segment, and indeed some
1931 crufty compilers have done just that.
1933 Since there could be a LOT of these things, treat them as a sparse
1936 #define FB_LABEL_SPECIAL (10)
1938 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1939 static long *fb_labels
;
1940 static long *fb_label_instances
;
1941 static long fb_label_count
;
1942 static long fb_label_max
;
1944 /* This must be more than FB_LABEL_SPECIAL. */
1945 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1948 fb_label_init (void)
1950 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1953 /* Add one to the instance number of this fb label. */
1956 fb_label_instance_inc (long label
)
1960 if ((unsigned long) label
< FB_LABEL_SPECIAL
)
1962 ++fb_low_counter
[label
];
1966 if (fb_labels
!= NULL
)
1968 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1969 i
< fb_labels
+ fb_label_count
; ++i
)
1973 ++fb_label_instances
[i
- fb_labels
];
1975 } /* if we find it */
1976 } /* for each existing label */
1979 /* If we get to here, we don't have label listed yet. */
1981 if (fb_labels
== NULL
)
1983 fb_labels
= XNEWVEC (long, FB_LABEL_BUMP_BY
);
1984 fb_label_instances
= XNEWVEC (long, FB_LABEL_BUMP_BY
);
1985 fb_label_max
= FB_LABEL_BUMP_BY
;
1986 fb_label_count
= FB_LABEL_SPECIAL
;
1989 else if (fb_label_count
== fb_label_max
)
1991 fb_label_max
+= FB_LABEL_BUMP_BY
;
1992 fb_labels
= XRESIZEVEC (long, fb_labels
, fb_label_max
);
1993 fb_label_instances
= XRESIZEVEC (long, fb_label_instances
, fb_label_max
);
1994 } /* if we needed to grow */
1996 fb_labels
[fb_label_count
] = label
;
1997 fb_label_instances
[fb_label_count
] = 1;
2002 fb_label_instance (long label
)
2006 if ((unsigned long) label
< FB_LABEL_SPECIAL
)
2008 return (fb_low_counter
[label
]);
2011 if (fb_labels
!= NULL
)
2013 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2014 i
< fb_labels
+ fb_label_count
; ++i
)
2018 return (fb_label_instances
[i
- fb_labels
]);
2019 } /* if we find it */
2020 } /* for each existing label */
2023 /* We didn't find the label, so this must be a reference to the
2028 /* Caller must copy returned name: we re-use the area for the next name.
2030 The mth occurrence of label n: is turned into the symbol "Ln^Bm"
2031 where n is the label number and m is the instance number. "L" makes
2032 it a label discarded unless debugging and "^B"('\2') ensures no
2033 ordinary symbol SHOULD get the same name as a local label
2034 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
2036 dollar labels get the same treatment, except that ^A is used in
2039 char * /* Return local label name. */
2040 fb_label_name (long n
, /* We just saw "n:", "nf" or "nb" : n a number. */
2041 long augend
/* 0 for nb, 1 for n:, nf. */)
2044 /* Returned to caller, then copied. Used for created names ("4f"). */
2045 static char symbol_name_build
[24];
2048 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
2052 know ((unsigned long) augend
<= 2 /* See mmix_fb_label. */);
2054 know ((unsigned long) augend
<= 1);
2056 p
= symbol_name_build
;
2057 #ifdef LOCAL_LABEL_PREFIX
2058 *p
++ = LOCAL_LABEL_PREFIX
;
2062 /* Next code just does sprintf( {}, "%d", n); */
2064 q
= symbol_name_temporary
;
2065 for (*q
++ = 0, i
= n
; i
; ++q
)
2070 while ((*p
= *--q
) != '\0')
2073 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
2075 /* Instance number. */
2076 q
= symbol_name_temporary
;
2077 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
2082 while ((*p
++ = *--q
) != '\0');
2084 /* The label, as a '\0' ended string, starts at symbol_name_build. */
2085 return (symbol_name_build
);
2088 /* Decode name that may have been generated by foo_label_name() above.
2089 If the name wasn't generated by foo_label_name(), then return it
2090 unaltered. This is used for error messages. */
2093 decode_local_label_name (char *s
)
2096 char *symbol_decode
;
2098 int instance_number
;
2100 const char *message_format
;
2103 #ifdef LOCAL_LABEL_PREFIX
2104 if (s
[lindex
] == LOCAL_LABEL_PREFIX
)
2108 if (s
[lindex
] != 'L')
2111 for (label_number
= 0, p
= s
+ lindex
+ 1; ISDIGIT (*p
); ++p
)
2112 label_number
= (10 * label_number
) + *p
- '0';
2114 if (*p
== DOLLAR_LABEL_CHAR
)
2116 else if (*p
== LOCAL_LABEL_CHAR
)
2121 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
2122 instance_number
= (10 * instance_number
) + *p
- '0';
2124 message_format
= _("\"%d\" (instance number %d of a %s label)");
2125 symbol_decode
= (char *) obstack_alloc (¬es
, strlen (message_format
) + 30);
2126 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
2128 return symbol_decode
;
2131 /* Get the value of a symbol. */
2134 S_GET_VALUE (symbolS
*s
)
2136 if (LOCAL_SYMBOL_CHECK (s
))
2137 return resolve_symbol_value (s
);
2139 if (!s
->sy_flags
.sy_resolved
)
2141 valueT val
= resolve_symbol_value (s
);
2145 if (S_IS_WEAKREFR (s
))
2146 return S_GET_VALUE (s
->sy_value
.X_add_symbol
);
2148 if (s
->sy_value
.X_op
!= O_constant
)
2150 if (! s
->sy_flags
.sy_resolved
2151 || s
->sy_value
.X_op
!= O_symbol
2152 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
2153 as_bad (_("attempt to get value of unresolved symbol `%s'"),
2156 return (valueT
) s
->sy_value
.X_add_number
;
2159 /* Set the value of a symbol. */
2162 S_SET_VALUE (symbolS
*s
, valueT val
)
2164 if (LOCAL_SYMBOL_CHECK (s
))
2166 ((struct local_symbol
*) s
)->lsy_value
= val
;
2170 s
->sy_value
.X_op
= O_constant
;
2171 s
->sy_value
.X_add_number
= (offsetT
) val
;
2172 s
->sy_value
.X_unsigned
= 0;
2173 S_CLEAR_WEAKREFR (s
);
2177 copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2179 if (LOCAL_SYMBOL_CHECK (dest
))
2180 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
2181 if (LOCAL_SYMBOL_CHECK (src
))
2182 src
= local_symbol_convert ((struct local_symbol
*) src
);
2184 /* In an expression, transfer the settings of these flags.
2185 The user can override later, of course. */
2186 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT \
2187 | BSF_GNU_INDIRECT_FUNCTION)
2188 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
2190 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
2191 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2194 #ifdef TC_COPY_SYMBOL_ATTRIBUTES
2195 TC_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2200 S_IS_FUNCTION (symbolS
*s
)
2204 if (LOCAL_SYMBOL_CHECK (s
))
2207 flags
= s
->bsym
->flags
;
2209 return (flags
& BSF_FUNCTION
) != 0;
2213 S_IS_EXTERNAL (symbolS
*s
)
2217 if (LOCAL_SYMBOL_CHECK (s
))
2220 flags
= s
->bsym
->flags
;
2223 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2226 return (flags
& BSF_GLOBAL
) != 0;
2230 S_IS_WEAK (symbolS
*s
)
2232 if (LOCAL_SYMBOL_CHECK (s
))
2234 /* Conceptually, a weakrefr is weak if the referenced symbol is. We
2235 could probably handle a WEAKREFR as always weak though. E.g., if
2236 the referenced symbol has lost its weak status, there's no reason
2237 to keep handling the weakrefr as if it was weak. */
2238 if (S_IS_WEAKREFR (s
))
2239 return S_IS_WEAK (s
->sy_value
.X_add_symbol
);
2240 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
2244 S_IS_WEAKREFR (symbolS
*s
)
2246 if (LOCAL_SYMBOL_CHECK (s
))
2248 return s
->sy_flags
.sy_weakrefr
!= 0;
2252 S_IS_WEAKREFD (symbolS
*s
)
2254 if (LOCAL_SYMBOL_CHECK (s
))
2256 return s
->sy_flags
.sy_weakrefd
!= 0;
2260 S_IS_COMMON (symbolS
*s
)
2262 if (LOCAL_SYMBOL_CHECK (s
))
2264 return bfd_is_com_section (s
->bsym
->section
);
2268 S_IS_DEFINED (symbolS
*s
)
2270 if (LOCAL_SYMBOL_CHECK (s
))
2271 return ((struct local_symbol
*) s
)->lsy_section
!= undefined_section
;
2272 return s
->bsym
->section
!= undefined_section
;
2276 #ifndef EXTERN_FORCE_RELOC
2277 #define EXTERN_FORCE_RELOC IS_ELF
2280 /* Return true for symbols that should not be reduced to section
2281 symbols or eliminated from expressions, because they may be
2282 overridden by the linker. */
2284 S_FORCE_RELOC (symbolS
*s
, int strict
)
2287 if (LOCAL_SYMBOL_CHECK (s
))
2288 sec
= ((struct local_symbol
*) s
)->lsy_section
;
2292 && ((s
->bsym
->flags
& BSF_WEAK
) != 0
2293 || (EXTERN_FORCE_RELOC
2294 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)))
2295 || (s
->bsym
->flags
& BSF_GNU_INDIRECT_FUNCTION
) != 0)
2297 sec
= s
->bsym
->section
;
2299 return bfd_is_und_section (sec
) || bfd_is_com_section (sec
);
2303 S_IS_DEBUG (symbolS
*s
)
2305 if (LOCAL_SYMBOL_CHECK (s
))
2307 if (s
->bsym
->flags
& BSF_DEBUGGING
)
2313 S_IS_LOCAL (symbolS
*s
)
2318 if (LOCAL_SYMBOL_CHECK (s
))
2321 flags
= s
->bsym
->flags
;
2324 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2327 if (bfd_asymbol_section (s
->bsym
) == reg_section
)
2330 if (flag_strip_local_absolute
2331 /* Keep BSF_FILE symbols in order to allow debuggers to identify
2332 the source file even when the object file is stripped. */
2333 && (flags
& (BSF_GLOBAL
| BSF_FILE
)) == 0
2334 && bfd_asymbol_section (s
->bsym
) == absolute_section
)
2337 name
= S_GET_NAME (s
);
2338 return (name
!= NULL
2340 && (strchr (name
, DOLLAR_LABEL_CHAR
)
2341 || strchr (name
, LOCAL_LABEL_CHAR
)
2342 #if FAKE_LABEL_CHAR != DOLLAR_LABEL_CHAR
2343 || strchr (name
, FAKE_LABEL_CHAR
)
2345 || TC_LABEL_IS_LOCAL (name
)
2346 || (! flag_keep_locals
2347 && (bfd_is_local_label (stdoutput
, s
->bsym
)
2350 && name
[1] == '?')))));
2354 S_IS_STABD (symbolS
*s
)
2356 return S_GET_NAME (s
) == 0;
2360 S_CAN_BE_REDEFINED (const symbolS
*s
)
2362 if (LOCAL_SYMBOL_CHECK (s
))
2363 return (local_symbol_get_frag ((struct local_symbol
*) s
)
2364 == &predefined_address_frag
);
2365 /* Permit register names to be redefined. */
2366 return s
->bsym
->section
== reg_section
;
2370 S_IS_VOLATILE (const symbolS
*s
)
2372 if (LOCAL_SYMBOL_CHECK (s
))
2374 return s
->sy_flags
.sy_volatile
;
2378 S_IS_FORWARD_REF (const symbolS
*s
)
2380 if (LOCAL_SYMBOL_CHECK (s
))
2382 return s
->sy_flags
.sy_forward_ref
;
2386 S_GET_NAME (symbolS
*s
)
2388 if (LOCAL_SYMBOL_CHECK (s
))
2389 return ((struct local_symbol
*) s
)->lsy_name
;
2390 return s
->bsym
->name
;
2394 S_GET_SEGMENT (symbolS
*s
)
2396 if (LOCAL_SYMBOL_CHECK (s
))
2397 return ((struct local_symbol
*) s
)->lsy_section
;
2398 return s
->bsym
->section
;
2402 S_SET_SEGMENT (symbolS
*s
, segT seg
)
2404 /* Don't reassign section symbols. The direct reason is to prevent seg
2405 faults assigning back to const global symbols such as *ABS*, but it
2406 shouldn't happen anyway. */
2408 if (LOCAL_SYMBOL_CHECK (s
))
2410 if (seg
== reg_section
)
2411 s
= local_symbol_convert ((struct local_symbol
*) s
);
2414 ((struct local_symbol
*) s
)->lsy_section
= seg
;
2419 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2421 if (s
->bsym
->section
!= seg
)
2425 s
->bsym
->section
= seg
;
2429 S_SET_EXTERNAL (symbolS
*s
)
2431 if (LOCAL_SYMBOL_CHECK (s
))
2432 s
= local_symbol_convert ((struct local_symbol
*) s
);
2433 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2435 /* Let .weak override .global. */
2438 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2440 /* Do not reassign section symbols. */
2441 as_warn (_("section symbols are already global"));
2444 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
2445 if (S_GET_SEGMENT (s
) == reg_section
)
2447 as_bad ("can't make register symbol `%s' global",
2452 s
->bsym
->flags
|= BSF_GLOBAL
;
2453 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
2456 if (! an_external_name
&& S_GET_NAME(s
)[0] != '.')
2457 an_external_name
= S_GET_NAME (s
);
2462 S_CLEAR_EXTERNAL (symbolS
*s
)
2464 if (LOCAL_SYMBOL_CHECK (s
))
2466 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2468 /* Let .weak override. */
2471 s
->bsym
->flags
|= BSF_LOCAL
;
2472 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
2476 S_SET_WEAK (symbolS
*s
)
2478 if (LOCAL_SYMBOL_CHECK (s
))
2479 s
= local_symbol_convert ((struct local_symbol
*) s
);
2480 #ifdef obj_set_weak_hook
2481 obj_set_weak_hook (s
);
2483 s
->bsym
->flags
|= BSF_WEAK
;
2484 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
2488 S_SET_WEAKREFR (symbolS
*s
)
2490 if (LOCAL_SYMBOL_CHECK (s
))
2491 s
= local_symbol_convert ((struct local_symbol
*) s
);
2492 s
->sy_flags
.sy_weakrefr
= 1;
2493 /* If the alias was already used, make sure we mark the target as
2494 used as well, otherwise it might be dropped from the symbol
2495 table. This may have unintended side effects if the alias is
2496 later redirected to another symbol, such as keeping the unused
2497 previous target in the symbol table. Since it will be weak, it's
2499 if (s
->sy_flags
.sy_used
)
2500 symbol_mark_used (s
->sy_value
.X_add_symbol
);
2504 S_CLEAR_WEAKREFR (symbolS
*s
)
2506 if (LOCAL_SYMBOL_CHECK (s
))
2508 s
->sy_flags
.sy_weakrefr
= 0;
2512 S_SET_WEAKREFD (symbolS
*s
)
2514 if (LOCAL_SYMBOL_CHECK (s
))
2515 s
= local_symbol_convert ((struct local_symbol
*) s
);
2516 s
->sy_flags
.sy_weakrefd
= 1;
2521 S_CLEAR_WEAKREFD (symbolS
*s
)
2523 if (LOCAL_SYMBOL_CHECK (s
))
2525 if (s
->sy_flags
.sy_weakrefd
)
2527 s
->sy_flags
.sy_weakrefd
= 0;
2528 /* If a weakref target symbol is weak, then it was never
2529 referenced directly before, not even in a .global directive,
2530 so decay it to local. If it remains undefined, it will be
2531 later turned into a global, like any other undefined
2533 if (s
->bsym
->flags
& BSF_WEAK
)
2535 #ifdef obj_clear_weak_hook
2536 obj_clear_weak_hook (s
);
2538 s
->bsym
->flags
&= ~BSF_WEAK
;
2539 s
->bsym
->flags
|= BSF_LOCAL
;
2545 S_SET_THREAD_LOCAL (symbolS
*s
)
2547 if (LOCAL_SYMBOL_CHECK (s
))
2548 s
= local_symbol_convert ((struct local_symbol
*) s
);
2549 if (bfd_is_com_section (s
->bsym
->section
)
2550 && (s
->bsym
->flags
& BSF_THREAD_LOCAL
) != 0)
2552 s
->bsym
->flags
|= BSF_THREAD_LOCAL
;
2553 if ((s
->bsym
->flags
& BSF_FUNCTION
) != 0)
2554 as_bad (_("Accessing function `%s' as thread-local object"),
2556 else if (! bfd_is_und_section (s
->bsym
->section
)
2557 && (s
->bsym
->section
->flags
& SEC_THREAD_LOCAL
) == 0)
2558 as_bad (_("Accessing `%s' as thread-local object"),
2563 S_SET_NAME (symbolS
*s
, const char *name
)
2565 if (LOCAL_SYMBOL_CHECK (s
))
2567 ((struct local_symbol
*) s
)->lsy_name
= name
;
2570 s
->bsym
->name
= name
;
2574 S_SET_VOLATILE (symbolS
*s
)
2576 if (LOCAL_SYMBOL_CHECK (s
))
2577 s
= local_symbol_convert ((struct local_symbol
*) s
);
2578 s
->sy_flags
.sy_volatile
= 1;
2582 S_CLEAR_VOLATILE (symbolS
*s
)
2584 if (!LOCAL_SYMBOL_CHECK (s
))
2585 s
->sy_flags
.sy_volatile
= 0;
2589 S_SET_FORWARD_REF (symbolS
*s
)
2591 if (LOCAL_SYMBOL_CHECK (s
))
2592 s
= local_symbol_convert ((struct local_symbol
*) s
);
2593 s
->sy_flags
.sy_forward_ref
= 1;
2596 /* Return the previous symbol in a chain. */
2599 symbol_previous (symbolS
*s
)
2601 if (LOCAL_SYMBOL_CHECK (s
))
2603 return s
->sy_previous
;
2606 /* Return the next symbol in a chain. */
2609 symbol_next (symbolS
*s
)
2611 if (LOCAL_SYMBOL_CHECK (s
))
2616 /* Return a pointer to the value of a symbol as an expression. */
2619 symbol_get_value_expression (symbolS
*s
)
2621 if (LOCAL_SYMBOL_CHECK (s
))
2622 s
= local_symbol_convert ((struct local_symbol
*) s
);
2623 return &s
->sy_value
;
2626 /* Set the value of a symbol to an expression. */
2629 symbol_set_value_expression (symbolS
*s
, const expressionS
*exp
)
2631 if (LOCAL_SYMBOL_CHECK (s
))
2632 s
= local_symbol_convert ((struct local_symbol
*) s
);
2634 S_CLEAR_WEAKREFR (s
);
2637 /* Return whether 2 symbols are the same. */
2640 symbol_same_p (symbolS
*s1
, symbolS
*s2
)
2642 s1
= get_real_sym (s1
);
2643 s2
= get_real_sym (s2
);
2647 /* Return a pointer to the X_add_number component of a symbol. */
2650 symbol_X_add_number (symbolS
*s
)
2652 if (LOCAL_SYMBOL_CHECK (s
))
2653 return (offsetT
*) &((struct local_symbol
*) s
)->lsy_value
;
2655 return &s
->sy_value
.X_add_number
;
2658 /* Set the value of SYM to the current position in the current segment. */
2661 symbol_set_value_now (symbolS
*sym
)
2663 S_SET_SEGMENT (sym
, now_seg
);
2664 S_SET_VALUE (sym
, frag_now_fix ());
2665 symbol_set_frag (sym
, frag_now
);
2668 /* Set the frag of a symbol. */
2671 symbol_set_frag (symbolS
*s
, fragS
*f
)
2673 if (LOCAL_SYMBOL_CHECK (s
))
2675 local_symbol_set_frag ((struct local_symbol
*) s
, f
);
2679 S_CLEAR_WEAKREFR (s
);
2682 /* Return the frag of a symbol. */
2685 symbol_get_frag (symbolS
*s
)
2687 if (LOCAL_SYMBOL_CHECK (s
))
2688 return local_symbol_get_frag ((struct local_symbol
*) s
);
2692 /* Mark a symbol as having been used. */
2695 symbol_mark_used (symbolS
*s
)
2697 if (LOCAL_SYMBOL_CHECK (s
))
2699 s
->sy_flags
.sy_used
= 1;
2700 if (S_IS_WEAKREFR (s
))
2701 symbol_mark_used (s
->sy_value
.X_add_symbol
);
2704 /* Clear the mark of whether a symbol has been used. */
2707 symbol_clear_used (symbolS
*s
)
2709 if (LOCAL_SYMBOL_CHECK (s
))
2710 s
= local_symbol_convert ((struct local_symbol
*) s
);
2711 s
->sy_flags
.sy_used
= 0;
2714 /* Return whether a symbol has been used. */
2717 symbol_used_p (symbolS
*s
)
2719 if (LOCAL_SYMBOL_CHECK (s
))
2721 return s
->sy_flags
.sy_used
;
2724 /* Mark a symbol as having been used in a reloc. */
2727 symbol_mark_used_in_reloc (symbolS
*s
)
2729 if (LOCAL_SYMBOL_CHECK (s
))
2730 s
= local_symbol_convert ((struct local_symbol
*) s
);
2731 s
->sy_flags
.sy_used_in_reloc
= 1;
2734 /* Clear the mark of whether a symbol has been used in a reloc. */
2737 symbol_clear_used_in_reloc (symbolS
*s
)
2739 if (LOCAL_SYMBOL_CHECK (s
))
2741 s
->sy_flags
.sy_used_in_reloc
= 0;
2744 /* Return whether a symbol has been used in a reloc. */
2747 symbol_used_in_reloc_p (symbolS
*s
)
2749 if (LOCAL_SYMBOL_CHECK (s
))
2751 return s
->sy_flags
.sy_used_in_reloc
;
2754 /* Mark a symbol as an MRI common symbol. */
2757 symbol_mark_mri_common (symbolS
*s
)
2759 if (LOCAL_SYMBOL_CHECK (s
))
2760 s
= local_symbol_convert ((struct local_symbol
*) s
);
2761 s
->sy_flags
.sy_mri_common
= 1;
2764 /* Clear the mark of whether a symbol is an MRI common symbol. */
2767 symbol_clear_mri_common (symbolS
*s
)
2769 if (LOCAL_SYMBOL_CHECK (s
))
2771 s
->sy_flags
.sy_mri_common
= 0;
2774 /* Return whether a symbol is an MRI common symbol. */
2777 symbol_mri_common_p (symbolS
*s
)
2779 if (LOCAL_SYMBOL_CHECK (s
))
2781 return s
->sy_flags
.sy_mri_common
;
2784 /* Mark a symbol as having been written. */
2787 symbol_mark_written (symbolS
*s
)
2789 if (LOCAL_SYMBOL_CHECK (s
))
2791 s
->sy_flags
.sy_written
= 1;
2794 /* Clear the mark of whether a symbol has been written. */
2797 symbol_clear_written (symbolS
*s
)
2799 if (LOCAL_SYMBOL_CHECK (s
))
2801 s
->sy_flags
.sy_written
= 0;
2804 /* Return whether a symbol has been written. */
2807 symbol_written_p (symbolS
*s
)
2809 if (LOCAL_SYMBOL_CHECK (s
))
2811 return s
->sy_flags
.sy_written
;
2814 /* Mark a symbol has having been resolved. */
2817 symbol_mark_resolved (symbolS
*s
)
2819 if (LOCAL_SYMBOL_CHECK (s
))
2821 local_symbol_mark_resolved ((struct local_symbol
*) s
);
2824 s
->sy_flags
.sy_resolved
= 1;
2827 /* Return whether a symbol has been resolved. */
2830 symbol_resolved_p (symbolS
*s
)
2832 if (LOCAL_SYMBOL_CHECK (s
))
2833 return local_symbol_resolved_p ((struct local_symbol
*) s
);
2834 return s
->sy_flags
.sy_resolved
;
2837 /* Return whether a symbol is a section symbol. */
2840 symbol_section_p (symbolS
*s ATTRIBUTE_UNUSED
)
2842 if (LOCAL_SYMBOL_CHECK (s
))
2844 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2847 /* Return whether a symbol is equated to another symbol. */
2850 symbol_equated_p (symbolS
*s
)
2852 if (LOCAL_SYMBOL_CHECK (s
))
2854 return s
->sy_value
.X_op
== O_symbol
;
2857 /* Return whether a symbol is equated to another symbol, and should be
2858 treated specially when writing out relocs. */
2861 symbol_equated_reloc_p (symbolS
*s
)
2863 if (LOCAL_SYMBOL_CHECK (s
))
2865 /* X_op_symbol, normally not used for O_symbol, is set by
2866 resolve_symbol_value to flag expression syms that have been
2868 return (s
->sy_value
.X_op
== O_symbol
2869 #if defined (OBJ_COFF) && defined (TE_PE)
2872 && ((s
->sy_flags
.sy_resolved
&& s
->sy_value
.X_op_symbol
!= NULL
)
2873 || ! S_IS_DEFINED (s
)
2874 || S_IS_COMMON (s
)));
2877 /* Return whether a symbol has a constant value. */
2880 symbol_constant_p (symbolS
*s
)
2882 if (LOCAL_SYMBOL_CHECK (s
))
2884 return s
->sy_value
.X_op
== O_constant
;
2887 /* Return whether a symbol was cloned and thus removed from the global
2891 symbol_shadow_p (symbolS
*s
)
2893 if (LOCAL_SYMBOL_CHECK (s
))
2895 return s
->sy_next
== s
;
2898 /* If S was created as a struct symbol, return S, otherwise if S is a
2899 converted local_symbol return the converted symbol, otherwise
2903 symbol_symbolS (symbolS
*s
)
2905 if (LOCAL_SYMBOL_CHECK (s
))
2910 /* Return the BFD symbol for a symbol. */
2913 symbol_get_bfdsym (symbolS
*s
)
2915 if (LOCAL_SYMBOL_CHECK (s
))
2916 s
= local_symbol_convert ((struct local_symbol
*) s
);
2920 /* Set the BFD symbol for a symbol. */
2923 symbol_set_bfdsym (symbolS
*s
, asymbol
*bsym
)
2925 if (LOCAL_SYMBOL_CHECK (s
))
2926 s
= local_symbol_convert ((struct local_symbol
*) s
);
2927 /* Usually, it is harmless to reset a symbol to a BFD section
2928 symbol. For example, obj_elf_change_section sets the BFD symbol
2929 of an old symbol with the newly created section symbol. But when
2930 we have multiple sections with the same name, the newly created
2931 section may have the same name as an old section. We check if the
2932 old symbol has been already marked as a section symbol before
2934 if ((s
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
2936 /* else XXX - What do we do now ? */
2939 #ifdef OBJ_SYMFIELD_TYPE
2941 /* Get a pointer to the object format information for a symbol. */
2944 symbol_get_obj (symbolS
*s
)
2946 if (LOCAL_SYMBOL_CHECK (s
))
2947 s
= local_symbol_convert ((struct local_symbol
*) s
);
2951 /* Set the object format information for a symbol. */
2954 symbol_set_obj (symbolS
*s
, OBJ_SYMFIELD_TYPE
*o
)
2956 if (LOCAL_SYMBOL_CHECK (s
))
2957 s
= local_symbol_convert ((struct local_symbol
*) s
);
2961 #endif /* OBJ_SYMFIELD_TYPE */
2963 #ifdef TC_SYMFIELD_TYPE
2965 /* Get a pointer to the processor information for a symbol. */
2968 symbol_get_tc (symbolS
*s
)
2970 if (LOCAL_SYMBOL_CHECK (s
))
2971 s
= local_symbol_convert ((struct local_symbol
*) s
);
2975 /* Set the processor information for a symbol. */
2978 symbol_set_tc (symbolS
*s
, TC_SYMFIELD_TYPE
*o
)
2980 if (LOCAL_SYMBOL_CHECK (s
))
2981 s
= local_symbol_convert ((struct local_symbol
*) s
);
2985 #endif /* TC_SYMFIELD_TYPE */
2990 symbol_lastP
= NULL
;
2991 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
2992 sy_hash
= hash_new ();
2993 local_hash
= hash_new ();
2995 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
2996 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2997 abs_symbol
.bsym
= bfd_abs_section_ptr
->symbol
;
2999 abs_symbol
.sy_value
.X_op
= O_constant
;
3000 abs_symbol
.sy_frag
= &zero_address_frag
;
3002 if (LOCAL_LABELS_FB
)
3007 dot_symbol_init (void)
3009 dot_symbol
.bsym
= bfd_make_empty_symbol (stdoutput
);
3010 if (dot_symbol
.bsym
== NULL
)
3011 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
3012 dot_symbol
.bsym
->name
= ".";
3013 dot_symbol
.sy_flags
.sy_forward_ref
= 1;
3014 dot_symbol
.sy_value
.X_op
= O_constant
;
3019 /* Maximum indent level.
3020 Available for modification inside a gdb session. */
3021 static int max_indent_level
= 8;
3024 print_symbol_value_1 (FILE *file
, symbolS
*sym
)
3026 const char *name
= S_GET_NAME (sym
);
3027 if (!name
|| !name
[0])
3029 fprintf (file
, "sym ");
3030 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) sym
));
3031 fprintf (file
, " %s", name
);
3033 if (LOCAL_SYMBOL_CHECK (sym
))
3035 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
3037 if (local_symbol_get_frag (locsym
) != & zero_address_frag
3038 && local_symbol_get_frag (locsym
) != NULL
)
3040 fprintf (file
, " frag ");
3041 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) local_symbol_get_frag (locsym
)));
3043 if (local_symbol_resolved_p (locsym
))
3044 fprintf (file
, " resolved");
3045 fprintf (file
, " local");
3049 if (sym
->sy_frag
!= &zero_address_frag
)
3051 fprintf (file
, " frag ");
3052 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) sym
->sy_frag
));
3054 if (sym
->sy_flags
.sy_written
)
3055 fprintf (file
, " written");
3056 if (sym
->sy_flags
.sy_resolved
)
3057 fprintf (file
, " resolved");
3058 else if (sym
->sy_flags
.sy_resolving
)
3059 fprintf (file
, " resolving");
3060 if (sym
->sy_flags
.sy_used_in_reloc
)
3061 fprintf (file
, " used-in-reloc");
3062 if (sym
->sy_flags
.sy_used
)
3063 fprintf (file
, " used");
3064 if (S_IS_LOCAL (sym
))
3065 fprintf (file
, " local");
3066 if (S_IS_EXTERNAL (sym
))
3067 fprintf (file
, " extern");
3068 if (S_IS_WEAK (sym
))
3069 fprintf (file
, " weak");
3070 if (S_IS_DEBUG (sym
))
3071 fprintf (file
, " debug");
3072 if (S_IS_DEFINED (sym
))
3073 fprintf (file
, " defined");
3075 if (S_IS_WEAKREFR (sym
))
3076 fprintf (file
, " weakrefr");
3077 if (S_IS_WEAKREFD (sym
))
3078 fprintf (file
, " weakrefd");
3079 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
3080 if (symbol_resolved_p (sym
))
3082 segT s
= S_GET_SEGMENT (sym
);
3084 if (s
!= undefined_section
3085 && s
!= expr_section
)
3086 fprintf (file
, " %lx", (unsigned long) S_GET_VALUE (sym
));
3088 else if (indent_level
< max_indent_level
3089 && S_GET_SEGMENT (sym
) != undefined_section
)
3092 fprintf (file
, "\n%*s<", indent_level
* 4, "");
3093 if (LOCAL_SYMBOL_CHECK (sym
))
3094 fprintf (file
, "constant %lx",
3095 (unsigned long) ((struct local_symbol
*) sym
)->lsy_value
);
3097 print_expr_1 (file
, &sym
->sy_value
);
3098 fprintf (file
, ">");
3105 print_symbol_value (symbolS
*sym
)
3108 print_symbol_value_1 (stderr
, sym
);
3109 fprintf (stderr
, "\n");
3113 print_binary (FILE *file
, const char *name
, expressionS
*exp
)
3116 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
3117 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3118 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3119 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3120 fprintf (file
, ">");
3125 print_expr_1 (FILE *file
, expressionS
*exp
)
3127 fprintf (file
, "expr ");
3128 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) exp
));
3129 fprintf (file
, " ");
3133 fprintf (file
, "illegal");
3136 fprintf (file
, "absent");
3139 fprintf (file
, "constant %lx", (unsigned long) exp
->X_add_number
);
3143 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
3144 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3145 fprintf (file
, ">");
3147 if (exp
->X_add_number
)
3148 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
3149 (unsigned long) exp
->X_add_number
);
3153 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
3156 fprintf (file
, "big");
3159 fprintf (file
, "uminus -<");
3161 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3162 fprintf (file
, ">");
3163 goto maybe_print_addnum
;
3165 fprintf (file
, "bit_not");
3168 print_binary (file
, "multiply", exp
);
3171 print_binary (file
, "divide", exp
);
3174 print_binary (file
, "modulus", exp
);
3177 print_binary (file
, "lshift", exp
);
3180 print_binary (file
, "rshift", exp
);
3182 case O_bit_inclusive_or
:
3183 print_binary (file
, "bit_ior", exp
);
3185 case O_bit_exclusive_or
:
3186 print_binary (file
, "bit_xor", exp
);
3189 print_binary (file
, "bit_and", exp
);
3192 print_binary (file
, "eq", exp
);
3195 print_binary (file
, "ne", exp
);
3198 print_binary (file
, "lt", exp
);
3201 print_binary (file
, "le", exp
);
3204 print_binary (file
, "ge", exp
);
3207 print_binary (file
, "gt", exp
);
3210 print_binary (file
, "logical_and", exp
);
3213 print_binary (file
, "logical_or", exp
);
3217 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
3218 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3219 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3220 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3221 fprintf (file
, ">");
3222 goto maybe_print_addnum
;
3225 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
3226 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3227 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3228 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3229 fprintf (file
, ">");
3230 goto maybe_print_addnum
;
3232 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
3239 print_expr (expressionS
*exp
)
3241 print_expr_1 (stderr
, exp
);
3242 fprintf (stderr
, "\n");
3246 symbol_print_statistics (FILE *file
)
3248 hash_print_statistics (file
, "symbol table", sy_hash
);
3249 hash_print_statistics (file
, "mini local symbol table", local_hash
);
3250 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
3251 local_symbol_count
, local_symbol_conversion_count
);
3254 #ifdef OBJ_COMPLEX_RELC
3256 /* Convert given symbol to a new complex-relocation symbol name. This
3257 may be a recursive function, since it might be called for non-leaf
3258 nodes (plain symbols) in the expression tree. The caller owns the
3259 returning string, so should free it eventually. Errors are
3260 indicated via as_bad and a NULL return value. The given symbol
3261 is marked with sy_used_in_reloc. */
3264 symbol_relc_make_sym (symbolS
* sym
)
3266 char * terminal
= NULL
;
3271 gas_assert (sym
!= NULL
);
3273 /* Recurse to symbol_relc_make_expr if this symbol
3274 is defined as an expression or a plain value. */
3275 if ( S_GET_SEGMENT (sym
) == expr_section
3276 || S_GET_SEGMENT (sym
) == absolute_section
)
3277 return symbol_relc_make_expr (symbol_get_value_expression (sym
));
3279 /* This may be a "fake symbol", referring to ".".
3280 Write out a special null symbol to refer to this position. */
3281 if (! strcmp (S_GET_NAME (sym
), FAKE_LABEL_NAME
))
3282 return xstrdup (".");
3284 /* We hope this is a plain leaf symbol. Construct the encoding
3285 as {S,s}II...:CCCCCCC....
3286 where 'S'/'s' means section symbol / plain symbol
3287 III is decimal for the symbol name length
3288 CCC is the symbol name itself. */
3289 symbol_mark_used_in_reloc (sym
);
3291 sname
= S_GET_NAME (sym
);
3292 sname_len
= strlen (sname
);
3293 typetag
= symbol_section_p (sym
) ? 'S' : 's';
3295 terminal
= XNEWVEC (char, (1 /* S or s */
3296 + 8 /* sname_len in decimal */
3298 + sname_len
/* name itself */
3301 sprintf (terminal
, "%c%d:%s", typetag
, sname_len
, sname
);
3305 /* Convert given value to a new complex-relocation symbol name. This
3306 is a non-recursive function, since it is be called for leaf nodes
3307 (plain values) in the expression tree. The caller owns the
3308 returning string, so should free() it eventually. No errors. */
3311 symbol_relc_make_value (offsetT val
)
3313 char * terminal
= XNEWVEC (char, 28); /* Enough for long long. */
3316 bfd_sprintf_vma (stdoutput
, terminal
+ 1, val
);
3320 /* Convert given expression to a new complex-relocation symbol name.
3321 This is a recursive function, since it traverses the entire given
3322 expression tree. The caller owns the returning string, so should
3323 free() it eventually. Errors are indicated via as_bad() and a NULL
3327 symbol_relc_make_expr (expressionS
* exp
)
3329 const char * opstr
= NULL
; /* Operator prefix string. */
3330 int arity
= 0; /* Arity of this operator. */
3331 char * operands
[3]; /* Up to three operands. */
3332 char * concat_string
= NULL
;
3334 operands
[0] = operands
[1] = operands
[2] = NULL
;
3336 gas_assert (exp
!= NULL
);
3338 /* Match known operators -> fill in opstr, arity, operands[] and fall
3339 through to construct subexpression fragments; may instead return
3340 string directly for leaf nodes. */
3342 /* See expr.h for the meaning of all these enums. Many operators
3343 have an unnatural arity (X_add_number implicitly added). The
3344 conversion logic expands them to explicit "+" subexpressions. */
3349 as_bad ("Unknown expression operator (enum %d)", exp
->X_op
);
3354 return symbol_relc_make_value (exp
->X_add_number
);
3357 if (exp
->X_add_number
)
3361 operands
[0] = symbol_relc_make_sym (exp
->X_add_symbol
);
3362 operands
[1] = symbol_relc_make_value (exp
->X_add_number
);
3366 return symbol_relc_make_sym (exp
->X_add_symbol
);
3368 /* Helper macros for nesting nodes. */
3370 #define HANDLE_XADD_OPT1(str_) \
3371 if (exp->X_add_number) \
3374 opstr = "+:" str_; \
3375 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3376 operands[1] = symbol_relc_make_value (exp->X_add_number); \
3383 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3387 #define HANDLE_XADD_OPT2(str_) \
3388 if (exp->X_add_number) \
3391 opstr = "+:" str_; \
3392 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3393 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3394 operands[2] = symbol_relc_make_value (exp->X_add_number); \
3400 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3401 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3405 /* Nesting nodes. */
3407 case O_uminus
: HANDLE_XADD_OPT1 ("0-");
3408 case O_bit_not
: HANDLE_XADD_OPT1 ("~");
3409 case O_logical_not
: HANDLE_XADD_OPT1 ("!");
3410 case O_multiply
: HANDLE_XADD_OPT2 ("*");
3411 case O_divide
: HANDLE_XADD_OPT2 ("/");
3412 case O_modulus
: HANDLE_XADD_OPT2 ("%");
3413 case O_left_shift
: HANDLE_XADD_OPT2 ("<<");
3414 case O_right_shift
: HANDLE_XADD_OPT2 (">>");
3415 case O_bit_inclusive_or
: HANDLE_XADD_OPT2 ("|");
3416 case O_bit_exclusive_or
: HANDLE_XADD_OPT2 ("^");
3417 case O_bit_and
: HANDLE_XADD_OPT2 ("&");
3418 case O_add
: HANDLE_XADD_OPT2 ("+");
3419 case O_subtract
: HANDLE_XADD_OPT2 ("-");
3420 case O_eq
: HANDLE_XADD_OPT2 ("==");
3421 case O_ne
: HANDLE_XADD_OPT2 ("!=");
3422 case O_lt
: HANDLE_XADD_OPT2 ("<");
3423 case O_le
: HANDLE_XADD_OPT2 ("<=");
3424 case O_ge
: HANDLE_XADD_OPT2 (">=");
3425 case O_gt
: HANDLE_XADD_OPT2 (">");
3426 case O_logical_and
: HANDLE_XADD_OPT2 ("&&");
3427 case O_logical_or
: HANDLE_XADD_OPT2 ("||");
3430 /* Validate & reject early. */
3431 if (arity
>= 1 && ((operands
[0] == NULL
) || (strlen (operands
[0]) == 0)))
3433 if (arity
>= 2 && ((operands
[1] == NULL
) || (strlen (operands
[1]) == 0)))
3435 if (arity
>= 3 && ((operands
[2] == NULL
) || (strlen (operands
[2]) == 0)))
3439 concat_string
= NULL
;
3440 else if (arity
== 0)
3441 concat_string
= xstrdup (opstr
);
3442 else if (arity
== 1)
3443 concat_string
= concat (opstr
, ":", operands
[0], (char *) NULL
);
3444 else if (arity
== 2)
3445 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1],
3448 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1], ":",
3449 operands
[2], (char *) NULL
);
3451 /* Free operand strings (not opstr). */
3452 if (arity
>= 1) xfree (operands
[0]);
3453 if (arity
>= 2) xfree (operands
[1]);
3454 if (arity
>= 3) xfree (operands
[2]);
3456 return concat_string
;