1 /* symbols.c -symbol table-
2 Copyright (C) 1987-2023 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" */
36 /* Whether the symbol is a local_symbol. */
37 unsigned int local_symbol
: 1;
39 /* Weather symbol has been written. */
40 unsigned int written
: 1;
42 /* Whether symbol value has been completely resolved (used during
43 final pass over symbol table). */
44 unsigned int resolved
: 1;
46 /* Whether the symbol value is currently being resolved (used to
47 detect loops in symbol dependencies). */
48 unsigned int resolving
: 1;
50 /* Whether the symbol value is used in a reloc. This is used to
51 ensure that symbols used in relocs are written out, even if they
52 are local and would otherwise not be. */
53 unsigned int used_in_reloc
: 1;
55 /* Whether the symbol is used as an operand or in an expression.
56 NOTE: Not all the backends keep this information accurate;
57 backends which use this bit are responsible for setting it when
58 a symbol is used in backend routines. */
59 unsigned int used
: 1;
61 /* Whether the symbol can be re-defined. */
62 unsigned int volatil
: 1;
64 /* Whether the symbol is a forward reference, and whether such has
66 unsigned int forward_ref
: 1;
67 unsigned int forward_resolved
: 1;
69 /* This is set if the symbol is defined in an MRI common section.
70 We handle such sections as single common symbols, so symbols
71 defined within them must be treated specially by the relocation
73 unsigned int mri_common
: 1;
75 /* This is set if the symbol is set with a .weakref directive. */
76 unsigned int weakrefr
: 1;
78 /* This is set when the symbol is referenced as part of a .weakref
79 directive, but only if the symbol was not in the symbol table
80 before. It is cleared as soon as any direct reference to the
82 unsigned int weakrefd
: 1;
84 /* Whether the symbol has been marked to be removed by a .symver
86 unsigned int removed
: 1;
88 /* Set when a warning about the symbol containing multibyte characters
90 unsigned int multibyte_warned
: 1;
93 /* A pointer in the symbol may point to either a complete symbol
94 (struct symbol below) or to a local symbol (struct local_symbol
95 defined here). The symbol code can detect the case by examining
96 the first field which is present in both structs.
98 We do this because we ordinarily only need a small amount of
99 information for a local symbol. The symbol table takes up a lot of
100 space, and storing less information for a local symbol can make a
101 big difference in assembler memory usage when assembling a large
106 /* Symbol flags. Only local_symbol and resolved are relevant. */
107 struct symbol_flags flags
;
109 /* Hash value calculated from name. */
112 /* The symbol name. */
115 /* The symbol frag. */
118 /* The symbol section. */
121 /* The value of the symbol. */
125 /* The information we keep for a symbol. The symbol table holds
126 pointers both to this and to local_symbol structures. The first
127 three fields must be identical to struct local_symbol, and the size
128 should be the same as or smaller than struct local_symbol.
129 Fields that don't fit go to an extension structure. */
134 struct symbol_flags flags
;
136 /* Hash value calculated from name. */
139 /* The symbol name. */
142 /* Pointer to the frag this symbol is attached to, if any.
149 /* Extra symbol fields that won't fit. */
153 /* Extra fields to make up a full symbol. */
157 /* The value of the symbol. */
160 /* Forwards and backwards chain pointers. */
162 struct symbol
*previous
;
164 #ifdef OBJ_SYMFIELD_TYPE
165 OBJ_SYMFIELD_TYPE obj
;
168 #ifdef TC_SYMFIELD_TYPE
173 typedef union symbol_entry
175 struct local_symbol lsy
;
179 /* Hash function for a symbol_entry. */
182 hash_symbol_entry (const void *e
)
184 symbol_entry_t
*entry
= (symbol_entry_t
*) e
;
185 if (entry
->sy
.hash
== 0)
186 entry
->sy
.hash
= htab_hash_string (entry
->sy
.name
);
188 return entry
->sy
.hash
;
191 /* Equality function for a symbol_entry. */
194 eq_symbol_entry (const void *a
, const void *b
)
196 const symbol_entry_t
*ea
= (const symbol_entry_t
*) a
;
197 const symbol_entry_t
*eb
= (const symbol_entry_t
*) b
;
199 return (ea
->sy
.hash
== eb
->sy
.hash
200 && strcmp (ea
->sy
.name
, eb
->sy
.name
) == 0);
204 symbol_entry_find (htab_t table
, const char *name
)
206 hashval_t hash
= htab_hash_string (name
);
207 symbol_entry_t needle
= { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
208 hash
, name
, 0, 0, 0 } };
209 return htab_find_with_hash (table
, &needle
, hash
);
213 /* This is non-zero if symbols are case sensitive, which is the
215 int symbols_case_sensitive
= 1;
217 #ifndef WORKING_DOT_WORD
218 extern int new_broken_words
;
221 static htab_t sy_hash
;
223 /* Below are commented in "symbols.h". */
224 symbolS
*symbol_rootP
;
225 symbolS
*symbol_lastP
;
227 struct xsymbol abs_symbol_x
;
229 struct xsymbol dot_symbol_x
;
232 #define debug_verify_symchain verify_symbol_chain
234 #define debug_verify_symchain(root, last) ((void) 0)
237 #define DOLLAR_LABEL_CHAR '\001'
238 #define LOCAL_LABEL_CHAR '\002'
240 #ifndef TC_LABEL_IS_LOCAL
241 #define TC_LABEL_IS_LOCAL(name) 0
244 struct obstack notes
;
246 /* Utility functions to allocate and duplicate memory on the notes
247 obstack, each like the corresponding function without "notes_"
248 prefix. All of these exit on an allocation failure. */
251 notes_alloc (size_t size
)
253 return obstack_alloc (¬es
, size
);
257 notes_calloc (size_t n
, size_t size
)
261 if (gas_mul_overflow (n
, size
, &amt
))
263 obstack_alloc_failed_handler ();
266 ret
= notes_alloc (amt
);
267 memset (ret
, 0, amt
);
272 notes_memdup (const void *src
, size_t copy_size
, size_t alloc_size
)
274 void *ret
= obstack_alloc (¬es
, alloc_size
);
275 memcpy (ret
, src
, copy_size
);
276 if (alloc_size
> copy_size
)
277 memset ((char *) ret
+ copy_size
, 0, alloc_size
- copy_size
);
282 notes_strdup (const char *str
)
284 size_t len
= strlen (str
) + 1;
285 return notes_memdup (str
, len
, len
);
289 notes_concat (const char *first
, ...)
294 va_start (args
, first
);
295 for (str
= first
; str
; str
= va_arg (args
, const char *))
297 size_t size
= strlen (str
);
298 obstack_grow (¬es
, str
, size
);
301 obstack_1grow (¬es
, 0);
302 return obstack_finish (¬es
);
305 /* Use with caution! Frees PTR and all more recently allocated memory
306 on the notes obstack. */
309 notes_free (void *ptr
)
311 obstack_free (¬es
, ptr
);
315 /* The name of an external symbol which is
316 used to make weak PE symbol names unique. */
317 const char * an_external_name
;
320 /* Return a pointer to a new symbol. Die if we can't make a new
321 symbol. Fill in the symbol's values. Add symbol to end of symbol
324 This function should be called in the general case of creating a
325 symbol. However, if the output file symbol table has already been
326 set, and you are certain that this symbol won't be wanted in the
327 output file, you can call symbol_create. */
330 symbol_new (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
332 symbolS
*symbolP
= symbol_create (name
, segment
, frag
, valu
);
334 /* Link to end of symbol chain. */
335 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
340 /* Save a symbol name on a permanent obstack, and convert it according
341 to the object file format. */
344 save_symbol_name (const char *name
)
348 gas_assert (name
!= NULL
);
349 ret
= notes_strdup (name
);
351 #ifdef tc_canonicalize_symbol_name
352 ret
= tc_canonicalize_symbol_name (ret
);
355 if (! symbols_case_sensitive
)
359 for (s
= ret
; *s
!= '\0'; s
++)
367 symbol_init (symbolS
*symbolP
, const char *name
, asection
*sec
,
368 fragS
*frag
, valueT valu
)
370 symbolP
->frag
= frag
;
371 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
372 if (symbolP
->bsym
== NULL
)
373 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
374 symbolP
->bsym
->name
= name
;
375 symbolP
->bsym
->section
= sec
;
377 if (multibyte_handling
== multibyte_warn_syms
378 && ! symbolP
->flags
.local_symbol
379 && sec
!= undefined_section
380 && ! symbolP
->flags
.multibyte_warned
381 && scan_for_multibyte_characters ((const unsigned char *) name
,
382 (const unsigned char *) name
+ strlen (name
),
383 false /* Do not warn. */))
385 as_warn (_("symbol '%s' contains multibyte characters"), name
);
386 symbolP
->flags
.multibyte_warned
= 1;
389 S_SET_VALUE (symbolP
, valu
);
390 if (sec
== reg_section
)
391 symbolP
->x
->value
.X_op
= O_register
;
393 symbol_clear_list_pointers (symbolP
);
395 obj_symbol_new_hook (symbolP
);
397 #ifdef tc_symbol_new_hook
398 tc_symbol_new_hook (symbolP
);
402 /* Create a symbol. NAME is copied, the caller can destroy/modify. */
405 symbol_create (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
407 const char *preserved_copy_of_name
;
411 preserved_copy_of_name
= save_symbol_name (name
);
413 size
= sizeof (symbolS
) + sizeof (struct xsymbol
);
414 symbolP
= notes_alloc (size
);
416 /* symbol must be born in some fixed state. This seems as good as any. */
417 memset (symbolP
, 0, size
);
418 symbolP
->name
= preserved_copy_of_name
;
419 symbolP
->x
= (struct xsymbol
*) (symbolP
+ 1);
421 symbol_init (symbolP
, preserved_copy_of_name
, segment
, frag
, valu
);
427 /* Local symbol support. If we can get away with it, we keep only a
428 small amount of information for local symbols. */
430 /* Used for statistics. */
432 static unsigned long local_symbol_count
;
433 static unsigned long local_symbol_conversion_count
;
435 /* Create a local symbol and insert it into the local hash table. */
437 struct local_symbol
*
438 local_symbol_make (const char *name
, segT section
, fragS
*frag
, valueT val
)
440 const char *name_copy
;
441 struct local_symbol
*ret
;
442 struct symbol_flags flags
= { .local_symbol
= 1, .resolved
= 0 };
444 ++local_symbol_count
;
446 name_copy
= save_symbol_name (name
);
448 ret
= notes_alloc (sizeof *ret
);
451 ret
->name
= name_copy
;
453 ret
->section
= section
;
456 htab_insert (sy_hash
, ret
, 1);
461 /* Convert a local symbol into a real symbol. */
464 local_symbol_convert (void *sym
)
466 symbol_entry_t
*ent
= (symbol_entry_t
*) sym
;
467 struct xsymbol
*xtra
;
470 gas_assert (ent
->lsy
.flags
.local_symbol
);
472 ++local_symbol_conversion_count
;
474 xtra
= notes_alloc (sizeof (*xtra
));
475 memset (xtra
, 0, sizeof (*xtra
));
476 val
= ent
->lsy
.value
;
479 /* Local symbols are always either defined or used. */
480 ent
->sy
.flags
.used
= 1;
481 ent
->sy
.flags
.local_symbol
= 0;
483 symbol_init (&ent
->sy
, ent
->lsy
.name
, ent
->lsy
.section
, ent
->lsy
.frag
, val
);
484 symbol_append (&ent
->sy
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
490 define_sym_at_dot (symbolS
*symbolP
)
492 symbolP
->frag
= frag_now
;
493 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
494 S_SET_SEGMENT (symbolP
, now_seg
);
497 /* We have just seen "<name>:".
498 Creates a struct symbol unless it already exists.
500 Gripes if we are redefining a symbol incompatibly (and ignores it). */
503 colon (/* Just seen "x:" - rattle symbols & frags. */
504 const char *sym_name
/* Symbol name, as a canonical string. */
505 /* We copy this string: OK to alter later. */)
507 symbolS
*symbolP
; /* Symbol we are working with. */
509 /* Sun local labels go out of scope whenever a non-local symbol is
511 if (LOCAL_LABELS_DOLLAR
512 && !bfd_is_local_label_name (stdoutput
, sym_name
))
513 dollar_label_clear ();
515 #ifndef WORKING_DOT_WORD
516 if (new_broken_words
)
518 struct broken_word
*a
;
523 if (now_seg
== absolute_section
)
525 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
529 possible_bytes
= (md_short_jump_size
530 + new_broken_words
* md_long_jump_size
);
533 frag_opcode
= frag_var (rs_broken_word
,
537 (symbolS
*) broken_words
,
541 /* We want to store the pointer to where to insert the jump
542 table in the fr_opcode of the rs_broken_word frag. This
543 requires a little hackery. */
545 && (frag_tmp
->fr_type
!= rs_broken_word
546 || frag_tmp
->fr_opcode
))
547 frag_tmp
= frag_tmp
->fr_next
;
549 frag_tmp
->fr_opcode
= frag_opcode
;
550 new_broken_words
= 0;
552 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
553 a
->dispfrag
= frag_tmp
;
555 #endif /* WORKING_DOT_WORD */
557 #ifdef obj_frob_colon
558 obj_frob_colon (sym_name
);
561 if ((symbolP
= symbol_find (sym_name
)) != 0)
563 S_CLEAR_WEAKREFR (symbolP
);
564 #ifdef RESOLVE_SYMBOL_REDEFINITION
565 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
568 /* Now check for undefined symbols. */
569 if (symbolP
->flags
.local_symbol
)
571 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
573 if (locsym
->section
!= undefined_section
574 && (locsym
->frag
!= frag_now
575 || locsym
->section
!= now_seg
576 || locsym
->value
!= frag_now_fix ()))
578 as_bad (_("symbol `%s' is already defined"), sym_name
);
582 locsym
->section
= now_seg
;
583 locsym
->frag
= frag_now
;
584 locsym
->value
= frag_now_fix ();
586 else if (!(S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
587 || S_IS_COMMON (symbolP
)
588 || S_IS_VOLATILE (symbolP
))
590 if (S_IS_VOLATILE (symbolP
))
592 symbolP
= symbol_clone (symbolP
, 1);
593 S_SET_VALUE (symbolP
, 0);
594 S_CLEAR_VOLATILE (symbolP
);
596 if (S_GET_VALUE (symbolP
) == 0)
598 define_sym_at_dot (symbolP
);
601 #endif /* if we have one, it better be zero. */
606 /* There are still several cases to check:
608 A .comm/.lcomm symbol being redefined as initialized
611 A .comm/.lcomm symbol being redefined with a larger
614 This only used to be allowed on VMS gas, but Sun cc
615 on the sparc also depends on it. */
617 if (((!S_IS_DEBUG (symbolP
)
618 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
619 && S_IS_EXTERNAL (symbolP
))
620 || S_GET_SEGMENT (symbolP
) == bss_section
)
621 && (now_seg
== data_section
622 || now_seg
== bss_section
623 || now_seg
== S_GET_SEGMENT (symbolP
)))
625 /* Select which of the 2 cases this is. */
626 if (now_seg
!= data_section
)
628 /* New .comm for prev .comm symbol.
630 If the new size is larger we just change its
631 value. If the new size is smaller, we ignore
633 if (S_GET_VALUE (symbolP
)
634 < ((unsigned) frag_now_fix ()))
636 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
641 /* It is a .comm/.lcomm being converted to initialized
643 define_sym_at_dot (symbolP
);
648 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT))
649 static const char *od_buf
= "";
653 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
654 sprintf (od_buf
, "%d.%d.",
655 S_GET_OTHER (symbolP
),
656 S_GET_DESC (symbolP
));
658 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
660 segment_name (S_GET_SEGMENT (symbolP
)),
662 (long) S_GET_VALUE (symbolP
));
664 } /* if the undefined symbol has no value */
668 /* Don't blow up if the definition is the same. */
669 if (!(frag_now
== symbolP
->frag
670 && S_GET_VALUE (symbolP
) == frag_now_fix ()
671 && S_GET_SEGMENT (symbolP
) == now_seg
))
673 as_bad (_("symbol `%s' is already defined"), sym_name
);
674 symbolP
= symbol_clone (symbolP
, 0);
675 define_sym_at_dot (symbolP
);
680 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
682 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
, frag_now
,
687 symbolP
= symbol_new (sym_name
, now_seg
, frag_now
, frag_now_fix ());
689 symbol_table_insert (symbolP
);
692 if (mri_common_symbol
!= NULL
)
694 /* This symbol is actually being defined within an MRI common
695 section. This requires special handling. */
696 if (symbolP
->flags
.local_symbol
)
697 symbolP
= local_symbol_convert (symbolP
);
698 symbolP
->x
->value
.X_op
= O_symbol
;
699 symbolP
->x
->value
.X_add_symbol
= mri_common_symbol
;
700 symbolP
->x
->value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
701 symbolP
->frag
= &zero_address_frag
;
702 S_SET_SEGMENT (symbolP
, expr_section
);
703 symbolP
->flags
.mri_common
= 1;
707 tc_frob_label (symbolP
);
709 #ifdef obj_frob_label
710 obj_frob_label (symbolP
);
716 /* Die if we can't insert the symbol. */
719 symbol_table_insert (symbolS
*symbolP
)
723 htab_insert (sy_hash
, symbolP
, 1);
726 /* If a symbol name does not exist, create it as undefined, and insert
727 it into the symbol table. Return a pointer to it. */
730 symbol_find_or_make (const char *name
)
734 symbolP
= symbol_find (name
);
738 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
740 symbolP
= md_undefined_symbol ((char *) name
);
744 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
745 &zero_address_frag
, 0);
749 symbolP
= symbol_make (name
);
751 symbol_table_insert (symbolP
);
752 } /* if symbol wasn't found */
758 symbol_make (const char *name
)
762 /* Let the machine description default it, e.g. for register names. */
763 symbolP
= md_undefined_symbol ((char *) name
);
766 symbolP
= symbol_new (name
, undefined_section
, &zero_address_frag
, 0);
772 symbol_clone (symbolS
*orgsymP
, int replace
)
775 asymbol
*bsymorg
, *bsymnew
;
777 /* Make sure we never clone the dot special symbol. */
778 gas_assert (orgsymP
!= &dot_symbol
);
780 /* When cloning a local symbol it isn't absolutely necessary to
781 convert the original, but converting makes the code much
782 simpler to cover this unexpected case. As of 2020-08-21
783 symbol_clone won't be called on a local symbol. */
784 if (orgsymP
->flags
.local_symbol
)
785 orgsymP
= local_symbol_convert (orgsymP
);
786 bsymorg
= orgsymP
->bsym
;
788 newsymP
= notes_alloc (sizeof (symbolS
) + sizeof (struct xsymbol
));
790 newsymP
->x
= (struct xsymbol
*) (newsymP
+ 1);
791 *newsymP
->x
= *orgsymP
->x
;
792 bsymnew
= bfd_make_empty_symbol (bfd_asymbol_bfd (bsymorg
));
794 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
795 newsymP
->bsym
= bsymnew
;
796 bsymnew
->name
= bsymorg
->name
;
797 bsymnew
->flags
= bsymorg
->flags
& ~BSF_SECTION_SYM
;
798 bsymnew
->section
= bsymorg
->section
;
799 bfd_copy_private_symbol_data (bfd_asymbol_bfd (bsymorg
), bsymorg
,
800 bfd_asymbol_bfd (bsymnew
), bsymnew
);
802 #ifdef obj_symbol_clone_hook
803 obj_symbol_clone_hook (newsymP
, orgsymP
);
806 #ifdef tc_symbol_clone_hook
807 tc_symbol_clone_hook (newsymP
, orgsymP
);
812 if (symbol_rootP
== orgsymP
)
813 symbol_rootP
= newsymP
;
814 else if (orgsymP
->x
->previous
)
816 orgsymP
->x
->previous
->x
->next
= newsymP
;
817 orgsymP
->x
->previous
= NULL
;
819 if (symbol_lastP
== orgsymP
)
820 symbol_lastP
= newsymP
;
821 else if (orgsymP
->x
->next
)
822 orgsymP
->x
->next
->x
->previous
= newsymP
;
824 /* Symbols that won't be output can't be external. */
825 S_CLEAR_EXTERNAL (orgsymP
);
826 orgsymP
->x
->previous
= orgsymP
->x
->next
= orgsymP
;
827 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
829 symbol_table_insert (newsymP
);
833 /* Symbols that won't be output can't be external. */
834 S_CLEAR_EXTERNAL (newsymP
);
835 newsymP
->x
->previous
= newsymP
->x
->next
= newsymP
;
841 /* Referenced symbols, if they are forward references, need to be cloned
842 (without replacing the original) so that the value of the referenced
843 symbols at the point of use is saved by the clone. */
845 #undef symbol_clone_if_forward_ref
847 symbol_clone_if_forward_ref (symbolS
*symbolP
, int is_forward
)
850 && !symbolP
->flags
.local_symbol
851 && !symbolP
->flags
.forward_resolved
)
853 symbolS
*orig_add_symbol
= symbolP
->x
->value
.X_add_symbol
;
854 symbolS
*orig_op_symbol
= symbolP
->x
->value
.X_op_symbol
;
855 symbolS
*add_symbol
= orig_add_symbol
;
856 symbolS
*op_symbol
= orig_op_symbol
;
858 if (symbolP
->flags
.forward_ref
)
863 /* assign_symbol() clones volatile symbols; pre-existing expressions
864 hold references to the original instance, but want the current
865 value. Just repeat the lookup. */
866 if (add_symbol
&& S_IS_VOLATILE (add_symbol
))
867 add_symbol
= symbol_find_exact (S_GET_NAME (add_symbol
));
868 if (op_symbol
&& S_IS_VOLATILE (op_symbol
))
869 op_symbol
= symbol_find_exact (S_GET_NAME (op_symbol
));
872 /* Re-using resolving here, as this routine cannot get called from
873 symbol resolution code. */
874 if ((symbolP
->bsym
->section
== expr_section
875 || symbolP
->flags
.forward_ref
)
876 && !symbolP
->flags
.resolving
)
878 symbolP
->flags
.resolving
= 1;
879 add_symbol
= symbol_clone_if_forward_ref (add_symbol
, is_forward
);
880 op_symbol
= symbol_clone_if_forward_ref (op_symbol
, is_forward
);
881 symbolP
->flags
.resolving
= 0;
884 if (symbolP
->flags
.forward_ref
885 || add_symbol
!= orig_add_symbol
886 || op_symbol
!= orig_op_symbol
)
888 if (symbolP
!= &dot_symbol
)
890 symbolP
= symbol_clone (symbolP
, 0);
891 symbolP
->flags
.resolving
= 0;
895 symbolP
= symbol_temp_new_now ();
896 #ifdef tc_new_dot_label
897 tc_new_dot_label (symbolP
);
902 symbolP
->x
->value
.X_add_symbol
= add_symbol
;
903 symbolP
->x
->value
.X_op_symbol
= op_symbol
;
904 symbolP
->flags
.forward_resolved
= 1;
911 symbol_temp_new (segT seg
, fragS
*frag
, valueT ofs
)
913 return symbol_new (FAKE_LABEL_NAME
, seg
, frag
, ofs
);
917 symbol_temp_new_now (void)
919 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix ());
923 symbol_temp_new_now_octets (void)
925 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix_octets ());
929 symbol_temp_make (void)
931 return symbol_make (FAKE_LABEL_NAME
);
934 /* Implement symbol table lookup.
935 In: A symbol's name as a string: '\0' can't be part of a symbol name.
936 Out: NULL if the name was not in the symbol table, else the address
937 of a struct symbol associated with that name. */
940 symbol_find_exact (const char *name
)
942 return symbol_find_exact_noref (name
, 0);
946 symbol_find_exact_noref (const char *name
, int noref
)
948 symbolS
*sym
= symbol_entry_find (sy_hash
, name
);
950 /* Any references to the symbol, except for the reference in
951 .weakref, must clear this flag, such that the symbol does not
952 turn into a weak symbol. Note that we don't have to handle the
953 local_symbol case, since a weakrefd is always promoted out of the
954 local_symbol table when it is turned into a weak symbol. */
956 S_CLEAR_WEAKREFD (sym
);
962 symbol_find (const char *name
)
964 return symbol_find_noref (name
, 0);
968 symbol_find_noref (const char *name
, int noref
)
973 #ifdef tc_canonicalize_symbol_name
975 copy
= xstrdup (name
);
976 name
= tc_canonicalize_symbol_name (copy
);
980 if (! symbols_case_sensitive
)
989 name
= copy
= XNEWVEC (char, strlen (name
) + 1);
991 while ((c
= *orig
++) != '\0')
992 *copy
++ = TOUPPER (c
);
996 copy
= (char *) name
;
999 result
= symbol_find_exact_noref (name
, noref
);
1004 /* Once upon a time, symbols were kept in a singly linked list. At
1005 least coff needs to be able to rearrange them from time to time, for
1006 which a doubly linked list is much more convenient. Loic did these
1007 as macros which seemed dangerous to me so they're now functions.
1010 /* Link symbol ADDME after symbol TARGET in the chain. */
1013 symbol_append (symbolS
*addme
, symbolS
*target
,
1014 symbolS
**rootPP
, symbolS
**lastPP
)
1016 extern int symbol_table_frozen
;
1017 if (symbol_table_frozen
)
1019 if (addme
->flags
.local_symbol
)
1021 if (target
!= NULL
&& target
->flags
.local_symbol
)
1026 know (*rootPP
== NULL
);
1027 know (*lastPP
== NULL
);
1028 addme
->x
->next
= NULL
;
1029 addme
->x
->previous
= NULL
;
1033 } /* if the list is empty */
1035 if (target
->x
->next
!= NULL
)
1037 target
->x
->next
->x
->previous
= addme
;
1041 know (*lastPP
== target
);
1043 } /* if we have a next */
1045 addme
->x
->next
= target
->x
->next
;
1046 target
->x
->next
= addme
;
1047 addme
->x
->previous
= target
;
1049 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
1052 /* Set the chain pointers of SYMBOL to null. */
1055 symbol_clear_list_pointers (symbolS
*symbolP
)
1057 if (symbolP
->flags
.local_symbol
)
1059 symbolP
->x
->next
= NULL
;
1060 symbolP
->x
->previous
= NULL
;
1063 /* Remove SYMBOLP from the list. */
1066 symbol_remove (symbolS
*symbolP
, symbolS
**rootPP
, symbolS
**lastPP
)
1068 if (symbolP
->flags
.local_symbol
)
1071 if (symbolP
== *rootPP
)
1073 *rootPP
= symbolP
->x
->next
;
1074 } /* if it was the root */
1076 if (symbolP
== *lastPP
)
1078 *lastPP
= symbolP
->x
->previous
;
1079 } /* if it was the tail */
1081 if (symbolP
->x
->next
!= NULL
)
1083 symbolP
->x
->next
->x
->previous
= symbolP
->x
->previous
;
1086 if (symbolP
->x
->previous
!= NULL
)
1088 symbolP
->x
->previous
->x
->next
= symbolP
->x
->next
;
1089 } /* if not first */
1091 debug_verify_symchain (*rootPP
, *lastPP
);
1094 /* Link symbol ADDME before symbol TARGET in the chain. */
1097 symbol_insert (symbolS
*addme
, symbolS
*target
,
1098 symbolS
**rootPP
, symbolS
**lastPP ATTRIBUTE_UNUSED
)
1100 extern int symbol_table_frozen
;
1101 if (symbol_table_frozen
)
1103 if (addme
->flags
.local_symbol
)
1105 if (target
->flags
.local_symbol
)
1108 if (target
->x
->previous
!= NULL
)
1110 target
->x
->previous
->x
->next
= addme
;
1114 know (*rootPP
== target
);
1116 } /* if not first */
1118 addme
->x
->previous
= target
->x
->previous
;
1119 target
->x
->previous
= addme
;
1120 addme
->x
->next
= target
;
1122 debug_verify_symchain (*rootPP
, *lastPP
);
1126 verify_symbol_chain (symbolS
*rootP
, symbolS
*lastP
)
1128 symbolS
*symbolP
= rootP
;
1130 if (symbolP
== NULL
)
1133 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
1135 gas_assert (symbolP
->bsym
!= NULL
);
1136 gas_assert (symbolP
->flags
.local_symbol
== 0);
1137 gas_assert (symbolP
->x
->next
->x
->previous
== symbolP
);
1140 gas_assert (lastP
== symbolP
);
1144 symbol_on_chain (symbolS
*s
, symbolS
*rootPP
, symbolS
*lastPP
)
1146 return (!s
->flags
.local_symbol
1147 && ((s
->x
->next
!= s
1148 && s
->x
->next
!= NULL
1149 && s
->x
->next
->x
->previous
== s
)
1151 && ((s
->x
->previous
!= s
1152 && s
->x
->previous
!= NULL
1153 && s
->x
->previous
->x
->next
== s
)
1157 #ifdef OBJ_COMPLEX_RELC
1160 use_complex_relocs_for (symbolS
* symp
)
1162 switch (symp
->x
->value
.X_op
)
1172 case O_bit_inclusive_or
:
1174 case O_bit_exclusive_or
:
1186 if ((S_IS_COMMON (symp
->x
->value
.X_op_symbol
)
1187 || S_IS_LOCAL (symp
->x
->value
.X_op_symbol
))
1188 && S_IS_DEFINED (symp
->x
->value
.X_op_symbol
)
1189 && S_GET_SEGMENT (symp
->x
->value
.X_op_symbol
) != expr_section
)
1196 if ((S_IS_COMMON (symp
->x
->value
.X_add_symbol
)
1197 || S_IS_LOCAL (symp
->x
->value
.X_add_symbol
))
1198 && S_IS_DEFINED (symp
->x
->value
.X_add_symbol
)
1199 && S_GET_SEGMENT (symp
->x
->value
.X_add_symbol
) != expr_section
)
1212 report_op_error (symbolS
*symp
, symbolS
*left
, operatorT op
, symbolS
*right
)
1216 segT seg_left
= left
? S_GET_SEGMENT (left
) : 0;
1217 segT seg_right
= S_GET_SEGMENT (right
);
1226 case O_uminus
: opname
= "-"; break;
1227 case O_bit_not
: opname
= "~"; break;
1228 case O_logical_not
: opname
= "!"; break;
1229 case O_multiply
: opname
= "*"; break;
1230 case O_divide
: opname
= "/"; break;
1231 case O_modulus
: opname
= "%"; break;
1232 case O_left_shift
: opname
= "<<"; break;
1233 case O_right_shift
: opname
= ">>"; break;
1234 case O_bit_inclusive_or
: opname
= "|"; break;
1235 case O_bit_or_not
: opname
= "|~"; break;
1236 case O_bit_exclusive_or
: opname
= "^"; break;
1237 case O_bit_and
: opname
= "&"; break;
1238 case O_add
: opname
= "+"; break;
1239 case O_subtract
: opname
= "-"; break;
1240 case O_eq
: opname
= "=="; break;
1241 case O_ne
: opname
= "!="; break;
1242 case O_lt
: opname
= "<"; break;
1243 case O_le
: opname
= "<="; break;
1244 case O_ge
: opname
= ">="; break;
1245 case O_gt
: opname
= ">"; break;
1246 case O_logical_and
: opname
= "&&"; break;
1247 case O_logical_or
: opname
= "||"; break;
1250 if (expr_symbol_where (symp
, &file
, &line
))
1253 as_bad_where (file
, line
,
1254 _("invalid operands (%s and %s sections) for `%s'"),
1255 seg_left
->name
, seg_right
->name
, opname
);
1257 as_bad_where (file
, line
,
1258 _("invalid operand (%s section) for `%s'"),
1259 seg_right
->name
, opname
);
1263 const char *sname
= S_GET_NAME (symp
);
1266 as_bad (_("invalid operands (%s and %s sections) for `%s' when setting `%s'"),
1267 seg_left
->name
, seg_right
->name
, opname
, sname
);
1269 as_bad (_("invalid operand (%s section) for `%s' when setting `%s'"),
1270 seg_right
->name
, opname
, sname
);
1274 /* Resolve the value of a symbol. This is called during the final
1275 pass over the symbol table to resolve any symbols with complex
1279 resolve_symbol_value (symbolS
*symp
)
1285 if (symp
->flags
.local_symbol
)
1287 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1289 final_val
= locsym
->value
;
1290 if (locsym
->flags
.resolved
)
1293 /* Symbols whose section has SEC_ELF_OCTETS set,
1294 resolve to octets instead of target bytes. */
1295 if (locsym
->section
->flags
& SEC_OCTETS
)
1296 final_val
+= locsym
->frag
->fr_address
;
1298 final_val
+= locsym
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1302 locsym
->value
= final_val
;
1303 locsym
->flags
.resolved
= 1;
1309 if (symp
->flags
.resolved
)
1312 while (symp
->x
->value
.X_op
== O_symbol
)
1314 final_val
+= symp
->x
->value
.X_add_number
;
1315 symp
= symp
->x
->value
.X_add_symbol
;
1316 if (symp
->flags
.local_symbol
)
1318 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1319 final_val
+= locsym
->value
;
1322 if (!symp
->flags
.resolved
)
1325 if (symp
->x
->value
.X_op
== O_constant
)
1326 final_val
+= symp
->x
->value
.X_add_number
;
1333 final_seg
= S_GET_SEGMENT (symp
);
1335 if (symp
->flags
.resolving
)
1338 as_bad (_("symbol definition loop encountered at `%s'"),
1343 #ifdef OBJ_COMPLEX_RELC
1344 else if (final_seg
== expr_section
1345 && use_complex_relocs_for (symp
))
1347 symbolS
* relc_symbol
= NULL
;
1348 char * relc_symbol_name
= NULL
;
1350 relc_symbol_name
= symbol_relc_make_expr (& symp
->x
->value
);
1352 /* For debugging, print out conversion input & output. */
1354 print_expr (& symp
->x
->value
);
1355 if (relc_symbol_name
)
1356 fprintf (stderr
, "-> relc symbol: %s\n", relc_symbol_name
);
1359 if (relc_symbol_name
!= NULL
)
1360 relc_symbol
= symbol_new (relc_symbol_name
, undefined_section
,
1361 &zero_address_frag
, 0);
1363 if (relc_symbol
== NULL
)
1365 as_bad (_("cannot convert expression symbol %s to complex relocation"),
1371 symbol_table_insert (relc_symbol
);
1373 /* S_CLEAR_EXTERNAL (relc_symbol); */
1374 if (symp
->bsym
->flags
& BSF_SRELC
)
1375 relc_symbol
->bsym
->flags
|= BSF_SRELC
;
1377 relc_symbol
->bsym
->flags
|= BSF_RELC
;
1378 /* symp->bsym->flags |= BSF_RELC; */
1379 copy_symbol_attributes (symp
, relc_symbol
);
1380 symp
->x
->value
.X_op
= O_symbol
;
1381 symp
->x
->value
.X_add_symbol
= relc_symbol
;
1382 symp
->x
->value
.X_add_number
= 0;
1387 final_seg
= undefined_section
;
1388 goto exit_dont_set_value
;
1393 symbolS
*add_symbol
, *op_symbol
;
1394 offsetT left
, right
;
1395 segT seg_left
, seg_right
;
1399 symp
->flags
.resolving
= 1;
1401 /* Help out with CSE. */
1402 add_symbol
= symp
->x
->value
.X_add_symbol
;
1403 op_symbol
= symp
->x
->value
.X_op_symbol
;
1404 final_val
= symp
->x
->value
.X_add_number
;
1405 op
= symp
->x
->value
.X_op
;
1445 #ifdef md_resolve_symbol
1446 resolved
= md_resolve_symbol (symp
, &final_val
, &final_seg
);
1450 goto exit_dont_set_value
;
1457 /* Symbols whose section has SEC_ELF_OCTETS set,
1458 resolve to octets instead of target bytes. */
1459 if (symp
->bsym
->section
->flags
& SEC_OCTETS
)
1460 final_val
+= symp
->frag
->fr_address
;
1462 final_val
+= symp
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1463 if (final_seg
== expr_section
)
1464 final_seg
= absolute_section
;
1474 left
= resolve_symbol_value (add_symbol
);
1475 seg_left
= S_GET_SEGMENT (add_symbol
);
1477 symp
->x
->value
.X_op_symbol
= NULL
;
1480 if (S_IS_WEAKREFR (symp
))
1482 gas_assert (final_val
== 0);
1483 if (S_IS_WEAKREFR (add_symbol
))
1485 gas_assert (add_symbol
->x
->value
.X_op
== O_symbol
1486 && add_symbol
->x
->value
.X_add_number
== 0);
1487 add_symbol
= add_symbol
->x
->value
.X_add_symbol
;
1488 gas_assert (! S_IS_WEAKREFR (add_symbol
));
1489 symp
->x
->value
.X_add_symbol
= add_symbol
;
1493 if (symp
->flags
.mri_common
)
1495 /* This is a symbol inside an MRI common section. The
1496 relocation routines are going to handle it specially.
1497 Don't change the value. */
1498 resolved
= symbol_resolved_p (add_symbol
);
1502 /* Don't leave symbol loops. */
1504 && !add_symbol
->flags
.local_symbol
1505 && add_symbol
->flags
.resolving
)
1508 if (finalize_syms
&& final_val
== 0
1510 /* Avoid changing symp's "within" when dealing with
1511 AIX debug symbols. For some storage classes, "within"
1512 have a special meaning.
1513 C_DWARF should behave like on Linux, thus this check
1514 isn't done to be closer. */
1515 && ((symbol_get_bfdsym (symp
)->flags
& BSF_DEBUGGING
) == 0
1516 || (S_GET_STORAGE_CLASS (symp
) == C_DWARF
))
1520 if (add_symbol
->flags
.local_symbol
)
1521 add_symbol
= local_symbol_convert (add_symbol
);
1522 copy_symbol_attributes (symp
, add_symbol
);
1525 /* If we have equated this symbol to an undefined or common
1526 symbol, keep X_op set to O_symbol, and don't change
1527 X_add_number. This permits the routine which writes out
1528 relocation to detect this case, and convert the
1529 relocation to be against the symbol to which this symbol
1531 if (seg_left
== undefined_section
1532 || bfd_is_com_section (seg_left
)
1533 #if defined (OBJ_COFF) && defined (TE_PE)
1534 || S_IS_WEAK (add_symbol
)
1537 && ((final_seg
== expr_section
1538 && seg_left
!= expr_section
1539 && seg_left
!= absolute_section
)
1540 || symbol_shadow_p (symp
))))
1544 symp
->x
->value
.X_op
= O_symbol
;
1545 symp
->x
->value
.X_add_symbol
= add_symbol
;
1546 symp
->x
->value
.X_add_number
= final_val
;
1547 /* Use X_op_symbol as a flag. */
1548 symp
->x
->value
.X_op_symbol
= add_symbol
;
1550 final_seg
= seg_left
;
1551 final_val
+= symp
->frag
->fr_address
+ left
;
1552 resolved
= symbol_resolved_p (add_symbol
);
1553 symp
->flags
.resolving
= 0;
1555 if (op
== O_secidx
&& seg_left
!= undefined_section
)
1561 goto exit_dont_set_value
;
1565 final_val
+= symp
->frag
->fr_address
+ left
;
1566 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1567 final_seg
= seg_left
;
1570 resolved
= symbol_resolved_p (add_symbol
);
1571 if (S_IS_WEAKREFR (symp
))
1573 symp
->flags
.resolving
= 0;
1574 goto exit_dont_set_value
;
1581 left
= resolve_symbol_value (add_symbol
);
1582 seg_left
= S_GET_SEGMENT (add_symbol
);
1584 /* By reducing these to the relevant dyadic operator, we get
1585 !S -> S == 0 permitted on anything,
1586 -S -> 0 - S only permitted on absolute
1587 ~S -> S ^ ~0 only permitted on absolute */
1588 if (op
!= O_logical_not
&& seg_left
!= absolute_section
1590 report_op_error (symp
, NULL
, op
, add_symbol
);
1592 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1593 final_seg
= absolute_section
;
1597 else if (op
== O_logical_not
)
1602 final_val
+= left
+ symp
->frag
->fr_address
;
1604 resolved
= symbol_resolved_p (add_symbol
);
1612 case O_bit_inclusive_or
:
1614 case O_bit_exclusive_or
:
1626 left
= resolve_symbol_value (add_symbol
);
1627 right
= resolve_symbol_value (op_symbol
);
1628 seg_left
= S_GET_SEGMENT (add_symbol
);
1629 seg_right
= S_GET_SEGMENT (op_symbol
);
1631 /* Simplify addition or subtraction of a constant by folding the
1632 constant into X_add_number. */
1635 if (seg_right
== absolute_section
)
1640 else if (seg_left
== absolute_section
)
1643 add_symbol
= op_symbol
;
1645 seg_left
= seg_right
;
1649 else if (op
== O_subtract
)
1651 if (seg_right
== absolute_section
)
1659 /* Equality and non-equality tests are permitted on anything.
1660 Subtraction, and other comparison operators are permitted if
1661 both operands are in the same section. Otherwise, both
1662 operands must be absolute. We already handled the case of
1663 addition or subtraction of a constant above. This will
1664 probably need to be changed for an object file format which
1665 supports arbitrary expressions. */
1666 if (!(seg_left
== absolute_section
1667 && seg_right
== absolute_section
)
1668 && !(op
== O_eq
|| op
== O_ne
)
1669 && !((op
== O_subtract
1670 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1671 && seg_left
== seg_right
1672 && (seg_left
!= undefined_section
1673 || add_symbol
== op_symbol
)))
1675 /* Don't emit messages unless we're finalizing the symbol value,
1676 otherwise we may get the same message multiple times. */
1678 report_op_error (symp
, add_symbol
, op
, op_symbol
);
1679 /* However do not move the symbol into the absolute section
1680 if it cannot currently be resolved - this would confuse
1681 other parts of the assembler into believing that the
1682 expression had been evaluated to zero. */
1688 && (final_seg
== expr_section
|| final_seg
== undefined_section
))
1689 final_seg
= absolute_section
;
1691 /* Check for division by zero. */
1692 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1694 /* If seg_right is not absolute_section, then we've
1695 already issued a warning about using a bad symbol. */
1696 if (seg_right
== absolute_section
&& finalize_syms
)
1701 if (expr_symbol_where (symp
, &file
, &line
))
1702 as_bad_where (file
, line
, _("division by zero"));
1704 as_bad (_("division by zero when setting `%s'"),
1710 if ((op
== O_left_shift
|| op
== O_right_shift
)
1711 && (valueT
) right
>= sizeof (valueT
) * CHAR_BIT
)
1713 as_warn_value_out_of_range (_("shift count"), right
, 0,
1714 sizeof (valueT
) * CHAR_BIT
- 1,
1719 switch (symp
->x
->value
.X_op
)
1721 case O_multiply
: left
*= right
; break;
1722 case O_divide
: left
/= right
; break;
1723 case O_modulus
: left
%= right
; break;
1725 left
= (valueT
) left
<< (valueT
) right
; break;
1727 left
= (valueT
) left
>> (valueT
) right
; break;
1728 case O_bit_inclusive_or
: left
|= right
; break;
1729 case O_bit_or_not
: left
|= ~right
; break;
1730 case O_bit_exclusive_or
: left
^= right
; break;
1731 case O_bit_and
: left
&= right
; break;
1732 case O_add
: left
+= right
; break;
1733 case O_subtract
: left
-= right
; break;
1736 left
= (left
== right
&& seg_left
== seg_right
1737 && (seg_left
!= undefined_section
1738 || add_symbol
== op_symbol
)
1739 ? ~ (offsetT
) 0 : 0);
1740 if (symp
->x
->value
.X_op
== O_ne
)
1743 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1744 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1745 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1746 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1747 case O_logical_and
: left
= left
&& right
; break;
1748 case O_logical_or
: left
= left
|| right
; break;
1753 /* See PR 20895 for a reproducer. */
1754 as_bad (_("Invalid operation on symbol"));
1755 goto exit_dont_set_value
;
1761 final_val
+= symp
->frag
->fr_address
+ left
;
1762 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1764 if (seg_left
== undefined_section
1765 || seg_right
== undefined_section
)
1766 final_seg
= undefined_section
;
1767 else if (seg_left
== absolute_section
)
1768 final_seg
= seg_right
;
1770 final_seg
= seg_left
;
1772 resolved
= (symbol_resolved_p (add_symbol
)
1773 && symbol_resolved_p (op_symbol
));
1778 /* Give an error (below) if not in expr_section. We don't
1779 want to worry about expr_section symbols, because they
1780 are fictional (they are created as part of expression
1781 resolution), and any problems may not actually mean
1786 symp
->flags
.resolving
= 0;
1790 S_SET_VALUE (symp
, final_val
);
1792 exit_dont_set_value
:
1793 /* Always set the segment, even if not finalizing the value.
1794 The segment is used to determine whether a symbol is defined. */
1795 S_SET_SEGMENT (symp
, final_seg
);
1797 /* Don't worry if we can't resolve an expr_section symbol. */
1801 symp
->flags
.resolved
= 1;
1802 else if (S_GET_SEGMENT (symp
) != expr_section
)
1804 as_bad (_("can't resolve value for symbol `%s'"),
1806 symp
->flags
.resolved
= 1;
1813 /* A static function passed to hash_traverse. */
1816 resolve_local_symbol (void **slot
, void *arg ATTRIBUTE_UNUSED
)
1818 symbol_entry_t
*entry
= *((symbol_entry_t
**) slot
);
1819 if (entry
->sy
.flags
.local_symbol
)
1820 resolve_symbol_value (&entry
->sy
);
1825 /* Resolve all local symbols. */
1828 resolve_local_symbol_values (void)
1830 htab_traverse_noresize (sy_hash
, resolve_local_symbol
, NULL
);
1833 /* Obtain the current value of a symbol without changing any
1834 sub-expressions used. */
1837 snapshot_symbol (symbolS
**symbolPP
, valueT
*valueP
, segT
*segP
, fragS
**fragPP
)
1839 symbolS
*symbolP
= *symbolPP
;
1841 if (symbolP
->flags
.local_symbol
)
1843 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1845 *valueP
= locsym
->value
;
1846 *segP
= locsym
->section
;
1847 *fragPP
= locsym
->frag
;
1851 expressionS exp
= symbolP
->x
->value
;
1853 if (!symbolP
->flags
.resolved
&& exp
.X_op
!= O_illegal
)
1857 if (symbolP
->flags
.resolving
)
1859 symbolP
->flags
.resolving
= 1;
1860 resolved
= resolve_expression (&exp
);
1861 symbolP
->flags
.resolving
= 0;
1869 if (!symbol_equated_p (symbolP
))
1874 symbolP
= exp
.X_add_symbol
;
1881 *symbolPP
= symbolP
;
1883 /* A bogus input file can result in resolve_expression()
1884 generating a local symbol, so we have to check again. */
1885 if (symbolP
->flags
.local_symbol
)
1887 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1889 *valueP
= locsym
->value
;
1890 *segP
= locsym
->section
;
1891 *fragPP
= locsym
->frag
;
1895 *valueP
= exp
.X_add_number
;
1896 *segP
= symbolP
->bsym
->section
;
1897 *fragPP
= symbolP
->frag
;
1900 if (*segP
== expr_section
)
1903 case O_constant
: *segP
= absolute_section
; break;
1904 case O_register
: *segP
= reg_section
; break;
1912 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1913 They are *really* local. That is, they go out of scope whenever we see a
1914 label that isn't local. Also, like fb labels, there can be multiple
1915 instances of a dollar label. Therefor, we name encode each instance with
1916 the instance number, keep a list of defined symbols separate from the real
1917 symbol table, and we treat these buggers as a sparse array. */
1919 typedef unsigned int dollar_ent
;
1920 static dollar_ent
*dollar_labels
;
1921 static dollar_ent
*dollar_label_instances
;
1922 static char *dollar_label_defines
;
1923 static size_t dollar_label_count
;
1924 static size_t dollar_label_max
;
1927 dollar_label_defined (unsigned int label
)
1931 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1933 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1935 return dollar_label_defines
[i
- dollar_labels
];
1937 /* If we get here, label isn't defined. */
1942 dollar_label_instance (unsigned int label
)
1946 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1948 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1950 return (dollar_label_instances
[i
- dollar_labels
]);
1952 /* If we get here, we haven't seen the label before.
1953 Therefore its instance count is zero. */
1958 dollar_label_clear (void)
1960 if (dollar_label_count
)
1961 memset (dollar_label_defines
, '\0', dollar_label_count
);
1964 #define DOLLAR_LABEL_BUMP_BY 10
1967 define_dollar_label (unsigned int label
)
1971 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1974 ++dollar_label_instances
[i
- dollar_labels
];
1975 dollar_label_defines
[i
- dollar_labels
] = 1;
1979 /* If we get to here, we don't have label listed yet. */
1981 if (dollar_labels
== NULL
)
1983 dollar_labels
= XNEWVEC (dollar_ent
, DOLLAR_LABEL_BUMP_BY
);
1984 dollar_label_instances
= XNEWVEC (dollar_ent
, DOLLAR_LABEL_BUMP_BY
);
1985 dollar_label_defines
= XNEWVEC (char, DOLLAR_LABEL_BUMP_BY
);
1986 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1987 dollar_label_count
= 0;
1989 else if (dollar_label_count
== dollar_label_max
)
1991 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1992 dollar_labels
= XRESIZEVEC (dollar_ent
, dollar_labels
,
1994 dollar_label_instances
= XRESIZEVEC (dollar_ent
,
1995 dollar_label_instances
,
1997 dollar_label_defines
= XRESIZEVEC (char, dollar_label_defines
,
1999 } /* if we needed to grow */
2001 dollar_labels
[dollar_label_count
] = label
;
2002 dollar_label_instances
[dollar_label_count
] = 1;
2003 dollar_label_defines
[dollar_label_count
] = 1;
2004 ++dollar_label_count
;
2007 /* Caller must copy returned name: we re-use the area for the next name.
2009 The mth occurrence of label n: is turned into the symbol "Ln^Am"
2010 where n is the label number and m is the instance number. "L" makes
2011 it a label discarded unless debugging and "^A"('\1') ensures no
2012 ordinary symbol SHOULD get the same name as a local label
2013 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
2015 fb labels get the same treatment, except that ^B is used in place
2018 AUGEND is 0 for current instance, 1 for new instance. */
2021 dollar_label_name (unsigned int n
, unsigned int augend
)
2023 /* Returned to caller, then copied. Used for created names ("4f"). */
2024 static char symbol_name_build
[24];
2025 char *p
= symbol_name_build
;
2027 #ifdef LOCAL_LABEL_PREFIX
2028 *p
++ = LOCAL_LABEL_PREFIX
;
2030 sprintf (p
, "L%u%c%u",
2031 n
, DOLLAR_LABEL_CHAR
, dollar_label_instance (n
) + augend
);
2032 return symbol_name_build
;
2035 /* Somebody else's idea of local labels. They are made by "n:" where n
2036 is any decimal digit. Refer to them with
2037 "nb" for previous (backward) n:
2038 or "nf" for next (forward) n:.
2040 We do a little better and let n be any number, not just a single digit, but
2041 since the other guy's assembler only does ten, we treat the first ten
2044 Like someone else's assembler, we have one set of local label counters for
2045 entire assembly, not one set per (sub)segment like in most assemblers. This
2046 implies that one can refer to a label in another segment, and indeed some
2047 crufty compilers have done just that.
2049 Since there could be a LOT of these things, treat them as a sparse
2052 #define FB_LABEL_SPECIAL (10)
2054 typedef unsigned int fb_ent
;
2055 static fb_ent fb_low_counter
[FB_LABEL_SPECIAL
];
2056 static fb_ent
*fb_labels
;
2057 static fb_ent
*fb_label_instances
;
2058 static size_t fb_label_count
;
2059 static size_t fb_label_max
;
2061 /* This must be more than FB_LABEL_SPECIAL. */
2062 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
2065 fb_label_init (void)
2067 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
2070 /* Add one to the instance number of this fb label. */
2073 fb_label_instance_inc (unsigned int label
)
2077 if (label
< FB_LABEL_SPECIAL
)
2079 ++fb_low_counter
[label
];
2083 if (fb_labels
!= NULL
)
2085 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2086 i
< fb_labels
+ fb_label_count
; ++i
)
2090 ++fb_label_instances
[i
- fb_labels
];
2092 } /* if we find it */
2093 } /* for each existing label */
2096 /* If we get to here, we don't have label listed yet. */
2098 if (fb_labels
== NULL
)
2100 fb_labels
= XNEWVEC (fb_ent
, FB_LABEL_BUMP_BY
);
2101 fb_label_instances
= XNEWVEC (fb_ent
, FB_LABEL_BUMP_BY
);
2102 fb_label_max
= FB_LABEL_BUMP_BY
;
2103 fb_label_count
= FB_LABEL_SPECIAL
;
2106 else if (fb_label_count
== fb_label_max
)
2108 fb_label_max
+= FB_LABEL_BUMP_BY
;
2109 fb_labels
= XRESIZEVEC (fb_ent
, fb_labels
, fb_label_max
);
2110 fb_label_instances
= XRESIZEVEC (fb_ent
, fb_label_instances
,
2112 } /* if we needed to grow */
2114 fb_labels
[fb_label_count
] = label
;
2115 fb_label_instances
[fb_label_count
] = 1;
2120 fb_label_instance (unsigned int label
)
2124 if (label
< FB_LABEL_SPECIAL
)
2125 return (fb_low_counter
[label
]);
2127 if (fb_labels
!= NULL
)
2129 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2130 i
< fb_labels
+ fb_label_count
; ++i
)
2133 return (fb_label_instances
[i
- fb_labels
]);
2137 /* We didn't find the label, so this must be a reference to the
2142 /* Caller must copy returned name: we re-use the area for the next name.
2144 The mth occurrence of label n: is turned into the symbol "Ln^Bm"
2145 where n is the label number and m is the instance number. "L" makes
2146 it a label discarded unless debugging and "^B"('\2') ensures no
2147 ordinary symbol SHOULD get the same name as a local label
2148 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
2150 dollar labels get the same treatment, except that ^A is used in
2153 AUGEND is 0 for nb, 1 for n:, nf. */
2156 fb_label_name (unsigned int n
, unsigned int augend
)
2158 /* Returned to caller, then copied. Used for created names ("4f"). */
2159 static char symbol_name_build
[24];
2160 char *p
= symbol_name_build
;
2163 know (augend
<= 2 /* See mmix_fb_label. */);
2168 #ifdef LOCAL_LABEL_PREFIX
2169 *p
++ = LOCAL_LABEL_PREFIX
;
2171 sprintf (p
, "L%u%c%u",
2172 n
, LOCAL_LABEL_CHAR
, fb_label_instance (n
) + augend
);
2173 return symbol_name_build
;
2176 /* Decode name that may have been generated by foo_label_name() above.
2177 If the name wasn't generated by foo_label_name(), then return it
2178 unaltered. This is used for error messages. */
2181 decode_local_label_name (char *s
)
2184 char *symbol_decode
;
2186 int instance_number
;
2188 const char *message_format
;
2191 #ifdef LOCAL_LABEL_PREFIX
2192 if (s
[lindex
] == LOCAL_LABEL_PREFIX
)
2196 if (s
[lindex
] != 'L')
2199 for (label_number
= 0, p
= s
+ lindex
+ 1; ISDIGIT (*p
); ++p
)
2200 label_number
= (10 * label_number
) + *p
- '0';
2202 if (*p
== DOLLAR_LABEL_CHAR
)
2204 else if (*p
== LOCAL_LABEL_CHAR
)
2209 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
2210 instance_number
= (10 * instance_number
) + *p
- '0';
2212 message_format
= _("\"%d\" (instance number %d of a %s label)");
2213 symbol_decode
= notes_alloc (strlen (message_format
) + 30);
2214 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
2216 return symbol_decode
;
2219 /* Get the value of a symbol. */
2222 S_GET_VALUE_WHERE (symbolS
*s
, const char * file
, unsigned int line
)
2224 if (s
->flags
.local_symbol
)
2225 return resolve_symbol_value (s
);
2227 if (!s
->flags
.resolved
)
2229 valueT val
= resolve_symbol_value (s
);
2233 if (S_IS_WEAKREFR (s
))
2234 return S_GET_VALUE (s
->x
->value
.X_add_symbol
);
2236 if (s
->x
->value
.X_op
!= O_constant
)
2238 if (! s
->flags
.resolved
2239 || s
->x
->value
.X_op
!= O_symbol
2240 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
2242 if (strcmp (S_GET_NAME (s
), FAKE_LABEL_NAME
) == 0)
2243 as_bad_where (file
, line
, _("expression is too complex to be resolved or converted into relocations"));
2244 else if (file
!= NULL
)
2245 as_bad_where (file
, line
, _("attempt to get value of unresolved symbol `%s'"),
2248 as_bad (_("attempt to get value of unresolved symbol `%s'"),
2252 return (valueT
) s
->x
->value
.X_add_number
;
2256 S_GET_VALUE (symbolS
*s
)
2258 return S_GET_VALUE_WHERE (s
, NULL
, 0);
2261 /* Set the value of a symbol. */
2264 S_SET_VALUE (symbolS
*s
, valueT val
)
2266 if (s
->flags
.local_symbol
)
2268 ((struct local_symbol
*) s
)->value
= val
;
2272 s
->x
->value
.X_op
= O_constant
;
2273 s
->x
->value
.X_add_number
= (offsetT
) val
;
2274 s
->x
->value
.X_unsigned
= 0;
2275 S_CLEAR_WEAKREFR (s
);
2279 copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2281 if (dest
->flags
.local_symbol
)
2282 dest
= local_symbol_convert (dest
);
2283 if (src
->flags
.local_symbol
)
2284 src
= local_symbol_convert (src
);
2286 /* In an expression, transfer the settings of these flags.
2287 The user can override later, of course. */
2288 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT \
2289 | BSF_GNU_INDIRECT_FUNCTION)
2290 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
2292 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
2293 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2296 #ifdef TC_COPY_SYMBOL_ATTRIBUTES
2297 TC_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2302 S_IS_FUNCTION (symbolS
*s
)
2306 if (s
->flags
.local_symbol
)
2309 flags
= s
->bsym
->flags
;
2311 return (flags
& BSF_FUNCTION
) != 0;
2315 S_IS_EXTERNAL (symbolS
*s
)
2319 if (s
->flags
.local_symbol
)
2322 flags
= s
->bsym
->flags
;
2325 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2328 return (flags
& BSF_GLOBAL
) != 0;
2332 S_IS_WEAK (symbolS
*s
)
2334 if (s
->flags
.local_symbol
)
2336 /* Conceptually, a weakrefr is weak if the referenced symbol is. We
2337 could probably handle a WEAKREFR as always weak though. E.g., if
2338 the referenced symbol has lost its weak status, there's no reason
2339 to keep handling the weakrefr as if it was weak. */
2340 if (S_IS_WEAKREFR (s
))
2341 return S_IS_WEAK (s
->x
->value
.X_add_symbol
);
2342 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
2346 S_IS_WEAKREFR (symbolS
*s
)
2348 if (s
->flags
.local_symbol
)
2350 return s
->flags
.weakrefr
!= 0;
2354 S_IS_WEAKREFD (symbolS
*s
)
2356 if (s
->flags
.local_symbol
)
2358 return s
->flags
.weakrefd
!= 0;
2362 S_IS_COMMON (symbolS
*s
)
2364 if (s
->flags
.local_symbol
)
2366 return bfd_is_com_section (s
->bsym
->section
);
2370 S_IS_DEFINED (symbolS
*s
)
2372 if (s
->flags
.local_symbol
)
2373 return ((struct local_symbol
*) s
)->section
!= undefined_section
;
2374 return s
->bsym
->section
!= undefined_section
;
2378 #ifndef EXTERN_FORCE_RELOC
2379 #define EXTERN_FORCE_RELOC IS_ELF
2382 /* Return true for symbols that should not be reduced to section
2383 symbols or eliminated from expressions, because they may be
2384 overridden by the linker. */
2386 S_FORCE_RELOC (symbolS
*s
, int strict
)
2389 if (s
->flags
.local_symbol
)
2390 sec
= ((struct local_symbol
*) s
)->section
;
2394 && ((s
->bsym
->flags
& BSF_WEAK
) != 0
2395 || (EXTERN_FORCE_RELOC
2396 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)))
2397 || (s
->bsym
->flags
& BSF_GNU_INDIRECT_FUNCTION
) != 0)
2399 sec
= s
->bsym
->section
;
2401 return bfd_is_und_section (sec
) || bfd_is_com_section (sec
);
2405 S_IS_DEBUG (symbolS
*s
)
2407 if (s
->flags
.local_symbol
)
2409 if (s
->bsym
->flags
& BSF_DEBUGGING
)
2415 S_IS_LOCAL (symbolS
*s
)
2420 if (s
->flags
.local_symbol
)
2423 flags
= s
->bsym
->flags
;
2426 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2429 if (bfd_asymbol_section (s
->bsym
) == reg_section
)
2432 if (flag_strip_local_absolute
2433 /* Keep BSF_FILE symbols in order to allow debuggers to identify
2434 the source file even when the object file is stripped. */
2435 && (flags
& (BSF_GLOBAL
| BSF_FILE
)) == 0
2436 && bfd_asymbol_section (s
->bsym
) == absolute_section
)
2439 name
= S_GET_NAME (s
);
2440 return (name
!= NULL
2442 && (strchr (name
, DOLLAR_LABEL_CHAR
)
2443 || strchr (name
, LOCAL_LABEL_CHAR
)
2444 #if FAKE_LABEL_CHAR != DOLLAR_LABEL_CHAR
2445 || strchr (name
, FAKE_LABEL_CHAR
)
2447 || TC_LABEL_IS_LOCAL (name
)
2448 || (! flag_keep_locals
2449 && (bfd_is_local_label (stdoutput
, s
->bsym
)
2452 && name
[1] == '?')))));
2456 S_IS_STABD (symbolS
*s
)
2458 return S_GET_NAME (s
) == 0;
2462 S_CAN_BE_REDEFINED (const symbolS
*s
)
2464 if (s
->flags
.local_symbol
)
2465 return (((struct local_symbol
*) s
)->frag
2466 == &predefined_address_frag
);
2467 /* Permit register names to be redefined. */
2468 return s
->x
->value
.X_op
== O_register
;
2472 S_IS_VOLATILE (const symbolS
*s
)
2474 if (s
->flags
.local_symbol
)
2476 return s
->flags
.volatil
;
2480 S_IS_FORWARD_REF (const symbolS
*s
)
2482 if (s
->flags
.local_symbol
)
2484 return s
->flags
.forward_ref
;
2488 S_GET_NAME (symbolS
*s
)
2494 S_GET_SEGMENT (symbolS
*s
)
2496 if (s
->flags
.local_symbol
)
2497 return ((struct local_symbol
*) s
)->section
;
2498 return s
->bsym
->section
;
2502 S_SET_SEGMENT (symbolS
*s
, segT seg
)
2504 if (s
->flags
.local_symbol
)
2506 ((struct local_symbol
*) s
)->section
= seg
;
2510 /* Don't reassign section symbols. The direct reason is to prevent seg
2511 faults assigning back to const global symbols such as *ABS*, but it
2512 shouldn't happen anyway. */
2513 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2515 if (s
->bsym
->section
!= seg
)
2520 if (multibyte_handling
== multibyte_warn_syms
2521 && ! s
->flags
.local_symbol
2522 && seg
!= undefined_section
2523 && ! s
->flags
.multibyte_warned
2524 && scan_for_multibyte_characters ((const unsigned char *) s
->name
,
2525 (const unsigned char *) s
->name
+ strlen (s
->name
),
2528 as_warn (_("symbol '%s' contains multibyte characters"), s
->name
);
2529 s
->flags
.multibyte_warned
= 1;
2532 s
->bsym
->section
= seg
;
2537 S_SET_EXTERNAL (symbolS
*s
)
2539 if (s
->flags
.local_symbol
)
2540 s
= local_symbol_convert (s
);
2541 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2543 /* Let .weak override .global. */
2546 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2548 /* Do not reassign section symbols. */
2549 as_warn (_("can't make section symbol global"));
2552 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
2553 if (S_GET_SEGMENT (s
) == reg_section
)
2555 as_bad (_("can't make register symbol global"));
2559 s
->bsym
->flags
|= BSF_GLOBAL
;
2560 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
2563 if (! an_external_name
&& S_GET_NAME(s
)[0] != '.')
2564 an_external_name
= S_GET_NAME (s
);
2569 S_CLEAR_EXTERNAL (symbolS
*s
)
2571 if (s
->flags
.local_symbol
)
2573 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2575 /* Let .weak override. */
2578 s
->bsym
->flags
|= BSF_LOCAL
;
2579 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
2583 S_SET_WEAK (symbolS
*s
)
2585 if (s
->flags
.local_symbol
)
2586 s
= local_symbol_convert (s
);
2587 #ifdef obj_set_weak_hook
2588 obj_set_weak_hook (s
);
2590 s
->bsym
->flags
|= BSF_WEAK
;
2591 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
2595 S_SET_WEAKREFR (symbolS
*s
)
2597 if (s
->flags
.local_symbol
)
2598 s
= local_symbol_convert (s
);
2599 s
->flags
.weakrefr
= 1;
2600 /* If the alias was already used, make sure we mark the target as
2601 used as well, otherwise it might be dropped from the symbol
2602 table. This may have unintended side effects if the alias is
2603 later redirected to another symbol, such as keeping the unused
2604 previous target in the symbol table. Since it will be weak, it's
2607 symbol_mark_used (s
->x
->value
.X_add_symbol
);
2611 S_CLEAR_WEAKREFR (symbolS
*s
)
2613 if (s
->flags
.local_symbol
)
2615 s
->flags
.weakrefr
= 0;
2619 S_SET_WEAKREFD (symbolS
*s
)
2621 if (s
->flags
.local_symbol
)
2622 s
= local_symbol_convert (s
);
2623 s
->flags
.weakrefd
= 1;
2628 S_CLEAR_WEAKREFD (symbolS
*s
)
2630 if (s
->flags
.local_symbol
)
2632 if (s
->flags
.weakrefd
)
2634 s
->flags
.weakrefd
= 0;
2635 /* If a weakref target symbol is weak, then it was never
2636 referenced directly before, not even in a .global directive,
2637 so decay it to local. If it remains undefined, it will be
2638 later turned into a global, like any other undefined
2640 if (s
->bsym
->flags
& BSF_WEAK
)
2642 #ifdef obj_clear_weak_hook
2643 obj_clear_weak_hook (s
);
2645 s
->bsym
->flags
&= ~BSF_WEAK
;
2646 s
->bsym
->flags
|= BSF_LOCAL
;
2652 S_SET_THREAD_LOCAL (symbolS
*s
)
2654 if (s
->flags
.local_symbol
)
2655 s
= local_symbol_convert (s
);
2656 if (bfd_is_com_section (s
->bsym
->section
)
2657 && (s
->bsym
->flags
& BSF_THREAD_LOCAL
) != 0)
2659 s
->bsym
->flags
|= BSF_THREAD_LOCAL
;
2660 if ((s
->bsym
->flags
& BSF_FUNCTION
) != 0)
2661 as_bad (_("Accessing function `%s' as thread-local object"),
2663 else if (! bfd_is_und_section (s
->bsym
->section
)
2664 && (s
->bsym
->section
->flags
& SEC_THREAD_LOCAL
) == 0)
2665 as_bad (_("Accessing `%s' as thread-local object"),
2670 S_SET_NAME (symbolS
*s
, const char *name
)
2673 if (s
->flags
.local_symbol
)
2675 s
->bsym
->name
= name
;
2679 S_SET_VOLATILE (symbolS
*s
)
2681 if (s
->flags
.local_symbol
)
2682 s
= local_symbol_convert (s
);
2683 s
->flags
.volatil
= 1;
2687 S_CLEAR_VOLATILE (symbolS
*s
)
2689 if (!s
->flags
.local_symbol
)
2690 s
->flags
.volatil
= 0;
2694 S_SET_FORWARD_REF (symbolS
*s
)
2696 if (s
->flags
.local_symbol
)
2697 s
= local_symbol_convert (s
);
2698 s
->flags
.forward_ref
= 1;
2701 /* Return the previous symbol in a chain. */
2704 symbol_previous (symbolS
*s
)
2706 if (s
->flags
.local_symbol
)
2708 return s
->x
->previous
;
2711 /* Return the next symbol in a chain. */
2714 symbol_next (symbolS
*s
)
2716 if (s
->flags
.local_symbol
)
2721 /* Return a pointer to the value of a symbol as an expression. */
2724 symbol_get_value_expression (symbolS
*s
)
2726 if (s
->flags
.local_symbol
)
2727 s
= local_symbol_convert (s
);
2728 return &s
->x
->value
;
2731 /* Set the value of a symbol to an expression. */
2734 symbol_set_value_expression (symbolS
*s
, const expressionS
*exp
)
2736 if (s
->flags
.local_symbol
)
2737 s
= local_symbol_convert (s
);
2739 S_CLEAR_WEAKREFR (s
);
2742 /* Return whether 2 symbols are the same. */
2745 symbol_same_p (symbolS
*s1
, symbolS
*s2
)
2750 /* Return a pointer to the X_add_number component of a symbol. */
2753 symbol_X_add_number (symbolS
*s
)
2755 if (s
->flags
.local_symbol
)
2756 return (offsetT
*) &((struct local_symbol
*) s
)->value
;
2758 return &s
->x
->value
.X_add_number
;
2761 /* Set the value of SYM to the current position in the current segment. */
2764 symbol_set_value_now (symbolS
*sym
)
2766 S_SET_SEGMENT (sym
, now_seg
);
2767 S_SET_VALUE (sym
, frag_now_fix ());
2768 symbol_set_frag (sym
, frag_now
);
2771 /* Set the frag of a symbol. */
2774 symbol_set_frag (symbolS
*s
, fragS
*f
)
2776 if (s
->flags
.local_symbol
)
2778 ((struct local_symbol
*) s
)->frag
= f
;
2782 S_CLEAR_WEAKREFR (s
);
2785 /* Return the frag of a symbol. */
2788 symbol_get_frag (symbolS
*s
)
2790 if (s
->flags
.local_symbol
)
2791 return ((struct local_symbol
*) s
)->frag
;
2795 /* Mark a symbol as having been used. */
2798 symbol_mark_used (symbolS
*s
)
2800 if (s
->flags
.local_symbol
)
2803 if (S_IS_WEAKREFR (s
))
2804 symbol_mark_used (s
->x
->value
.X_add_symbol
);
2807 /* Clear the mark of whether a symbol has been used. */
2810 symbol_clear_used (symbolS
*s
)
2812 if (s
->flags
.local_symbol
)
2813 s
= local_symbol_convert (s
);
2817 /* Return whether a symbol has been used. */
2820 symbol_used_p (symbolS
*s
)
2822 if (s
->flags
.local_symbol
)
2824 return s
->flags
.used
;
2827 /* Mark a symbol as having been used in a reloc. */
2830 symbol_mark_used_in_reloc (symbolS
*s
)
2832 if (s
->flags
.local_symbol
)
2833 s
= local_symbol_convert (s
);
2834 s
->flags
.used_in_reloc
= 1;
2837 /* Clear the mark of whether a symbol has been used in a reloc. */
2840 symbol_clear_used_in_reloc (symbolS
*s
)
2842 if (s
->flags
.local_symbol
)
2844 s
->flags
.used_in_reloc
= 0;
2847 /* Return whether a symbol has been used in a reloc. */
2850 symbol_used_in_reloc_p (symbolS
*s
)
2852 if (s
->flags
.local_symbol
)
2854 return s
->flags
.used_in_reloc
;
2857 /* Mark a symbol as an MRI common symbol. */
2860 symbol_mark_mri_common (symbolS
*s
)
2862 if (s
->flags
.local_symbol
)
2863 s
= local_symbol_convert (s
);
2864 s
->flags
.mri_common
= 1;
2867 /* Clear the mark of whether a symbol is an MRI common symbol. */
2870 symbol_clear_mri_common (symbolS
*s
)
2872 if (s
->flags
.local_symbol
)
2874 s
->flags
.mri_common
= 0;
2877 /* Return whether a symbol is an MRI common symbol. */
2880 symbol_mri_common_p (symbolS
*s
)
2882 if (s
->flags
.local_symbol
)
2884 return s
->flags
.mri_common
;
2887 /* Mark a symbol as having been written. */
2890 symbol_mark_written (symbolS
*s
)
2892 if (s
->flags
.local_symbol
)
2894 s
->flags
.written
= 1;
2897 /* Clear the mark of whether a symbol has been written. */
2900 symbol_clear_written (symbolS
*s
)
2902 if (s
->flags
.local_symbol
)
2904 s
->flags
.written
= 0;
2907 /* Return whether a symbol has been written. */
2910 symbol_written_p (symbolS
*s
)
2912 if (s
->flags
.local_symbol
)
2914 return s
->flags
.written
;
2917 /* Mark a symbol as to be removed. */
2920 symbol_mark_removed (symbolS
*s
)
2922 if (s
->flags
.local_symbol
)
2924 s
->flags
.removed
= 1;
2927 /* Return whether a symbol has been marked to be removed. */
2930 symbol_removed_p (symbolS
*s
)
2932 if (s
->flags
.local_symbol
)
2934 return s
->flags
.removed
;
2937 /* Mark a symbol has having been resolved. */
2940 symbol_mark_resolved (symbolS
*s
)
2942 s
->flags
.resolved
= 1;
2945 /* Return whether a symbol has been resolved. */
2948 symbol_resolved_p (symbolS
*s
)
2950 return s
->flags
.resolved
;
2953 /* Return whether a symbol is a section symbol. */
2956 symbol_section_p (symbolS
*s
)
2958 if (s
->flags
.local_symbol
)
2960 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2963 /* Return whether a symbol is equated to another symbol. */
2966 symbol_equated_p (symbolS
*s
)
2968 if (s
->flags
.local_symbol
)
2970 return s
->x
->value
.X_op
== O_symbol
;
2973 /* Return whether a symbol is equated to another symbol, and should be
2974 treated specially when writing out relocs. */
2977 symbol_equated_reloc_p (symbolS
*s
)
2979 if (s
->flags
.local_symbol
)
2981 /* X_op_symbol, normally not used for O_symbol, is set by
2982 resolve_symbol_value to flag expression syms that have been
2984 return (s
->x
->value
.X_op
== O_symbol
2985 #if defined (OBJ_COFF) && defined (TE_PE)
2988 && ((s
->flags
.resolved
&& s
->x
->value
.X_op_symbol
!= NULL
)
2989 || ! S_IS_DEFINED (s
)
2990 || S_IS_COMMON (s
)));
2993 /* Return whether a symbol has a constant value. */
2996 symbol_constant_p (symbolS
*s
)
2998 if (s
->flags
.local_symbol
)
3000 return s
->x
->value
.X_op
== O_constant
;
3003 /* Return whether a symbol was cloned and thus removed from the global
3007 symbol_shadow_p (symbolS
*s
)
3009 if (s
->flags
.local_symbol
)
3011 return s
->x
->next
== s
;
3014 /* If S is a struct symbol return S, otherwise return NULL. */
3017 symbol_symbolS (symbolS
*s
)
3019 if (s
->flags
.local_symbol
)
3024 /* Return the BFD symbol for a symbol. */
3027 symbol_get_bfdsym (symbolS
*s
)
3029 if (s
->flags
.local_symbol
)
3030 s
= local_symbol_convert (s
);
3034 /* Set the BFD symbol for a symbol. */
3037 symbol_set_bfdsym (symbolS
*s
, asymbol
*bsym
)
3039 if (s
->flags
.local_symbol
)
3040 s
= local_symbol_convert (s
);
3041 /* Usually, it is harmless to reset a symbol to a BFD section
3042 symbol. For example, obj_elf_change_section sets the BFD symbol
3043 of an old symbol with the newly created section symbol. But when
3044 we have multiple sections with the same name, the newly created
3045 section may have the same name as an old section. We check if the
3046 old symbol has been already marked as a section symbol before
3048 if ((s
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
3050 /* else XXX - What do we do now ? */
3053 #ifdef OBJ_SYMFIELD_TYPE
3055 /* Get a pointer to the object format information for a symbol. */
3058 symbol_get_obj (symbolS
*s
)
3060 if (s
->flags
.local_symbol
)
3061 s
= local_symbol_convert (s
);
3065 /* Set the object format information for a symbol. */
3068 symbol_set_obj (symbolS
*s
, OBJ_SYMFIELD_TYPE
*o
)
3070 if (s
->flags
.local_symbol
)
3071 s
= local_symbol_convert (s
);
3075 #endif /* OBJ_SYMFIELD_TYPE */
3077 #ifdef TC_SYMFIELD_TYPE
3079 /* Get a pointer to the processor information for a symbol. */
3082 symbol_get_tc (symbolS
*s
)
3084 if (s
->flags
.local_symbol
)
3085 s
= local_symbol_convert (s
);
3089 /* Set the processor information for a symbol. */
3092 symbol_set_tc (symbolS
*s
, TC_SYMFIELD_TYPE
*o
)
3094 if (s
->flags
.local_symbol
)
3095 s
= local_symbol_convert (s
);
3099 #endif /* TC_SYMFIELD_TYPE */
3104 symbol_lastP
= NULL
;
3105 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
3106 sy_hash
= htab_create_alloc (16, hash_symbol_entry
, eq_symbol_entry
,
3107 NULL
, xcalloc
, free
);
3109 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
3110 abs_symbol
.bsym
= bfd_abs_section_ptr
->symbol
;
3112 abs_symbol
.x
= &abs_symbol_x
;
3113 abs_symbol
.x
->value
.X_op
= O_constant
;
3114 abs_symbol
.frag
= &zero_address_frag
;
3116 if (LOCAL_LABELS_FB
)
3123 htab_delete (sy_hash
);
3127 dot_symbol_init (void)
3129 dot_symbol
.name
= ".";
3130 dot_symbol
.flags
.forward_ref
= 1;
3131 dot_symbol
.bsym
= bfd_make_empty_symbol (stdoutput
);
3132 if (dot_symbol
.bsym
== NULL
)
3133 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
3134 dot_symbol
.bsym
->name
= ".";
3135 dot_symbol
.x
= &dot_symbol_x
;
3136 dot_symbol
.x
->value
.X_op
= O_constant
;
3141 /* Maximum indent level.
3142 Available for modification inside a gdb session. */
3143 static int max_indent_level
= 8;
3146 print_symbol_value_1 (FILE *file
, symbolS
*sym
)
3148 const char *name
= S_GET_NAME (sym
);
3149 if (!name
|| !name
[0])
3151 fprintf (file
, "sym %p %s", sym
, name
);
3153 if (sym
->flags
.local_symbol
)
3155 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
3157 if (locsym
->frag
!= &zero_address_frag
3158 && locsym
->frag
!= NULL
)
3159 fprintf (file
, " frag %p", locsym
->frag
);
3160 if (locsym
->flags
.resolved
)
3161 fprintf (file
, " resolved");
3162 fprintf (file
, " local");
3166 if (sym
->frag
!= &zero_address_frag
)
3167 fprintf (file
, " frag %p", sym
->frag
);
3168 if (sym
->flags
.written
)
3169 fprintf (file
, " written");
3170 if (sym
->flags
.resolved
)
3171 fprintf (file
, " resolved");
3172 else if (sym
->flags
.resolving
)
3173 fprintf (file
, " resolving");
3174 if (sym
->flags
.used_in_reloc
)
3175 fprintf (file
, " used-in-reloc");
3176 if (sym
->flags
.used
)
3177 fprintf (file
, " used");
3178 if (S_IS_LOCAL (sym
))
3179 fprintf (file
, " local");
3180 if (S_IS_EXTERNAL (sym
))
3181 fprintf (file
, " extern");
3182 if (S_IS_WEAK (sym
))
3183 fprintf (file
, " weak");
3184 if (S_IS_DEBUG (sym
))
3185 fprintf (file
, " debug");
3186 if (S_IS_DEFINED (sym
))
3187 fprintf (file
, " defined");
3189 if (S_IS_WEAKREFR (sym
))
3190 fprintf (file
, " weakrefr");
3191 if (S_IS_WEAKREFD (sym
))
3192 fprintf (file
, " weakrefd");
3193 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
3194 if (symbol_resolved_p (sym
))
3196 segT s
= S_GET_SEGMENT (sym
);
3198 if (s
!= undefined_section
3199 && s
!= expr_section
)
3200 fprintf (file
, " %lx", (unsigned long) S_GET_VALUE (sym
));
3202 else if (indent_level
< max_indent_level
3203 && S_GET_SEGMENT (sym
) != undefined_section
)
3206 fprintf (file
, "\n%*s<", indent_level
* 4, "");
3207 if (sym
->flags
.local_symbol
)
3208 fprintf (file
, "constant %lx",
3209 (unsigned long) ((struct local_symbol
*) sym
)->value
);
3211 print_expr_1 (file
, &sym
->x
->value
);
3212 fprintf (file
, ">");
3219 print_symbol_value (symbolS
*sym
)
3222 print_symbol_value_1 (stderr
, sym
);
3223 fprintf (stderr
, "\n");
3227 print_binary (FILE *file
, const char *name
, expressionS
*exp
)
3230 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
3231 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3232 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3233 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3234 fprintf (file
, ">");
3239 print_expr_1 (FILE *file
, expressionS
*exp
)
3241 fprintf (file
, "expr %p ", exp
);
3245 fprintf (file
, "illegal");
3248 fprintf (file
, "absent");
3251 fprintf (file
, "constant %" PRIx64
, (uint64_t) exp
->X_add_number
);
3255 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
3256 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3257 fprintf (file
, ">");
3259 if (exp
->X_add_number
)
3260 fprintf (file
, "\n%*s%" PRIx64
, indent_level
* 4, "",
3261 (uint64_t) exp
->X_add_number
);
3265 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
3268 fprintf (file
, "big");
3271 fprintf (file
, "uminus -<");
3273 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3274 fprintf (file
, ">");
3275 goto maybe_print_addnum
;
3277 fprintf (file
, "bit_not");
3280 print_binary (file
, "multiply", exp
);
3283 print_binary (file
, "divide", exp
);
3286 print_binary (file
, "modulus", exp
);
3289 print_binary (file
, "lshift", exp
);
3292 print_binary (file
, "rshift", exp
);
3294 case O_bit_inclusive_or
:
3295 print_binary (file
, "bit_ior", exp
);
3297 case O_bit_exclusive_or
:
3298 print_binary (file
, "bit_xor", exp
);
3301 print_binary (file
, "bit_and", exp
);
3304 print_binary (file
, "eq", exp
);
3307 print_binary (file
, "ne", exp
);
3310 print_binary (file
, "lt", exp
);
3313 print_binary (file
, "le", exp
);
3316 print_binary (file
, "ge", exp
);
3319 print_binary (file
, "gt", exp
);
3322 print_binary (file
, "logical_and", exp
);
3325 print_binary (file
, "logical_or", exp
);
3329 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
3330 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3331 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3332 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3333 fprintf (file
, ">");
3334 goto maybe_print_addnum
;
3337 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
3338 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3339 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3340 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3341 fprintf (file
, ">");
3342 goto maybe_print_addnum
;
3344 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
3351 print_expr (expressionS
*exp
)
3353 print_expr_1 (stderr
, exp
);
3354 fprintf (stderr
, "\n");
3358 symbol_print_statistics (FILE *file
)
3360 htab_print_statistics (file
, "symbol table", sy_hash
);
3361 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
3362 local_symbol_count
, local_symbol_conversion_count
);
3365 #ifdef OBJ_COMPLEX_RELC
3367 /* Convert given symbol to a new complex-relocation symbol name. This
3368 may be a recursive function, since it might be called for non-leaf
3369 nodes (plain symbols) in the expression tree. The caller owns the
3370 returning string, so should free it eventually. Errors are
3371 indicated via as_bad and a NULL return value. The given symbol
3372 is marked with used_in_reloc. */
3375 symbol_relc_make_sym (symbolS
* sym
)
3377 char * terminal
= NULL
;
3382 gas_assert (sym
!= NULL
);
3384 /* Recurse to symbol_relc_make_expr if this symbol
3385 is defined as an expression or a plain value. */
3386 if ( S_GET_SEGMENT (sym
) == expr_section
3387 || S_GET_SEGMENT (sym
) == absolute_section
)
3388 return symbol_relc_make_expr (symbol_get_value_expression (sym
));
3390 /* This may be a "fake symbol", referring to ".".
3391 Write out a special null symbol to refer to this position. */
3392 if (! strcmp (S_GET_NAME (sym
), FAKE_LABEL_NAME
))
3393 return xstrdup (".");
3395 /* We hope this is a plain leaf symbol. Construct the encoding
3396 as {S,s}II...:CCCCCCC....
3397 where 'S'/'s' means section symbol / plain symbol
3398 III is decimal for the symbol name length
3399 CCC is the symbol name itself. */
3400 symbol_mark_used_in_reloc (sym
);
3402 sname
= S_GET_NAME (sym
);
3403 sname_len
= strlen (sname
);
3404 typetag
= symbol_section_p (sym
) ? 'S' : 's';
3406 terminal
= XNEWVEC (char, (1 /* S or s */
3407 + 8 /* sname_len in decimal */
3409 + sname_len
/* name itself */
3412 sprintf (terminal
, "%c%d:%s", typetag
, sname_len
, sname
);
3416 /* Convert given value to a new complex-relocation symbol name. This
3417 is a non-recursive function, since it is be called for leaf nodes
3418 (plain values) in the expression tree. The caller owns the
3419 returning string, so should free() it eventually. No errors. */
3422 symbol_relc_make_value (offsetT val
)
3424 char * terminal
= XNEWVEC (char, 28); /* Enough for long long. */
3427 bfd_sprintf_vma (stdoutput
, terminal
+ 1, val
);
3431 /* Convert given expression to a new complex-relocation symbol name.
3432 This is a recursive function, since it traverses the entire given
3433 expression tree. The caller owns the returning string, so should
3434 free() it eventually. Errors are indicated via as_bad() and a NULL
3438 symbol_relc_make_expr (expressionS
* exp
)
3440 const char * opstr
= NULL
; /* Operator prefix string. */
3441 int arity
= 0; /* Arity of this operator. */
3442 char * operands
[3]; /* Up to three operands. */
3443 char * concat_string
= NULL
;
3445 operands
[0] = operands
[1] = operands
[2] = NULL
;
3447 gas_assert (exp
!= NULL
);
3449 /* Match known operators -> fill in opstr, arity, operands[] and fall
3450 through to construct subexpression fragments; may instead return
3451 string directly for leaf nodes. */
3453 /* See expr.h for the meaning of all these enums. Many operators
3454 have an unnatural arity (X_add_number implicitly added). The
3455 conversion logic expands them to explicit "+" subexpressions. */
3460 as_bad ("Unknown expression operator (enum %d)", exp
->X_op
);
3465 return symbol_relc_make_value (exp
->X_add_number
);
3468 if (exp
->X_add_number
)
3472 operands
[0] = symbol_relc_make_sym (exp
->X_add_symbol
);
3473 operands
[1] = symbol_relc_make_value (exp
->X_add_number
);
3477 return symbol_relc_make_sym (exp
->X_add_symbol
);
3479 /* Helper macros for nesting nodes. */
3481 #define HANDLE_XADD_OPT1(str_) \
3482 if (exp->X_add_number) \
3485 opstr = "+:" str_; \
3486 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3487 operands[1] = symbol_relc_make_value (exp->X_add_number); \
3494 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3498 #define HANDLE_XADD_OPT2(str_) \
3499 if (exp->X_add_number) \
3502 opstr = "+:" str_; \
3503 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3504 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3505 operands[2] = symbol_relc_make_value (exp->X_add_number); \
3511 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3512 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3516 /* Nesting nodes. */
3518 case O_uminus
: HANDLE_XADD_OPT1 ("0-");
3519 case O_bit_not
: HANDLE_XADD_OPT1 ("~");
3520 case O_logical_not
: HANDLE_XADD_OPT1 ("!");
3521 case O_multiply
: HANDLE_XADD_OPT2 ("*");
3522 case O_divide
: HANDLE_XADD_OPT2 ("/");
3523 case O_modulus
: HANDLE_XADD_OPT2 ("%");
3524 case O_left_shift
: HANDLE_XADD_OPT2 ("<<");
3525 case O_right_shift
: HANDLE_XADD_OPT2 (">>");
3526 case O_bit_inclusive_or
: HANDLE_XADD_OPT2 ("|");
3527 case O_bit_exclusive_or
: HANDLE_XADD_OPT2 ("^");
3528 case O_bit_and
: HANDLE_XADD_OPT2 ("&");
3529 case O_add
: HANDLE_XADD_OPT2 ("+");
3530 case O_subtract
: HANDLE_XADD_OPT2 ("-");
3531 case O_eq
: HANDLE_XADD_OPT2 ("==");
3532 case O_ne
: HANDLE_XADD_OPT2 ("!=");
3533 case O_lt
: HANDLE_XADD_OPT2 ("<");
3534 case O_le
: HANDLE_XADD_OPT2 ("<=");
3535 case O_ge
: HANDLE_XADD_OPT2 (">=");
3536 case O_gt
: HANDLE_XADD_OPT2 (">");
3537 case O_logical_and
: HANDLE_XADD_OPT2 ("&&");
3538 case O_logical_or
: HANDLE_XADD_OPT2 ("||");
3541 /* Validate & reject early. */
3542 if (arity
>= 1 && ((operands
[0] == NULL
) || (strlen (operands
[0]) == 0)))
3544 if (arity
>= 2 && ((operands
[1] == NULL
) || (strlen (operands
[1]) == 0)))
3546 if (arity
>= 3 && ((operands
[2] == NULL
) || (strlen (operands
[2]) == 0)))
3550 concat_string
= NULL
;
3551 else if (arity
== 0)
3552 concat_string
= xstrdup (opstr
);
3553 else if (arity
== 1)
3554 concat_string
= concat (opstr
, ":", operands
[0], (char *) NULL
);
3555 else if (arity
== 2)
3556 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1],
3559 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1], ":",
3560 operands
[2], (char *) NULL
);
3562 /* Free operand strings (not opstr). */
3563 if (arity
>= 1) xfree (operands
[0]);
3564 if (arity
>= 2) xfree (operands
[1]);
3565 if (arity
>= 3) xfree (operands
[2]);
3567 return concat_string
;