1 /* symbols.c -symbol table-
2 Copyright (C) 1987-2022 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
);
391 symbol_clear_list_pointers (symbolP
);
393 obj_symbol_new_hook (symbolP
);
395 #ifdef tc_symbol_new_hook
396 tc_symbol_new_hook (symbolP
);
400 /* Create a symbol. NAME is copied, the caller can destroy/modify. */
403 symbol_create (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
405 const char *preserved_copy_of_name
;
409 preserved_copy_of_name
= save_symbol_name (name
);
411 size
= sizeof (symbolS
) + sizeof (struct xsymbol
);
412 symbolP
= notes_alloc (size
);
414 /* symbol must be born in some fixed state. This seems as good as any. */
415 memset (symbolP
, 0, size
);
416 symbolP
->name
= preserved_copy_of_name
;
417 symbolP
->x
= (struct xsymbol
*) (symbolP
+ 1);
419 symbol_init (symbolP
, preserved_copy_of_name
, segment
, frag
, valu
);
425 /* Local symbol support. If we can get away with it, we keep only a
426 small amount of information for local symbols. */
428 /* Used for statistics. */
430 static unsigned long local_symbol_count
;
431 static unsigned long local_symbol_conversion_count
;
433 /* Create a local symbol and insert it into the local hash table. */
435 struct local_symbol
*
436 local_symbol_make (const char *name
, segT section
, fragS
*frag
, valueT val
)
438 const char *name_copy
;
439 struct local_symbol
*ret
;
440 struct symbol_flags flags
= { .local_symbol
= 1, .resolved
= 0 };
442 ++local_symbol_count
;
444 name_copy
= save_symbol_name (name
);
446 ret
= notes_alloc (sizeof *ret
);
449 ret
->name
= name_copy
;
451 ret
->section
= section
;
454 htab_insert (sy_hash
, ret
, 1);
459 /* Convert a local symbol into a real symbol. */
462 local_symbol_convert (void *sym
)
464 symbol_entry_t
*ent
= (symbol_entry_t
*) sym
;
465 struct xsymbol
*xtra
;
468 gas_assert (ent
->lsy
.flags
.local_symbol
);
470 ++local_symbol_conversion_count
;
472 xtra
= notes_alloc (sizeof (*xtra
));
473 memset (xtra
, 0, sizeof (*xtra
));
474 val
= ent
->lsy
.value
;
477 /* Local symbols are always either defined or used. */
478 ent
->sy
.flags
.used
= 1;
479 ent
->sy
.flags
.local_symbol
= 0;
481 symbol_init (&ent
->sy
, ent
->lsy
.name
, ent
->lsy
.section
, ent
->lsy
.frag
, val
);
482 symbol_append (&ent
->sy
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
488 define_sym_at_dot (symbolS
*symbolP
)
490 symbolP
->frag
= frag_now
;
491 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
492 S_SET_SEGMENT (symbolP
, now_seg
);
495 /* We have just seen "<name>:".
496 Creates a struct symbol unless it already exists.
498 Gripes if we are redefining a symbol incompatibly (and ignores it). */
501 colon (/* Just seen "x:" - rattle symbols & frags. */
502 const char *sym_name
/* Symbol name, as a canonical string. */
503 /* We copy this string: OK to alter later. */)
505 symbolS
*symbolP
; /* Symbol we are working with. */
507 /* Sun local labels go out of scope whenever a non-local symbol is
509 if (LOCAL_LABELS_DOLLAR
510 && !bfd_is_local_label_name (stdoutput
, sym_name
))
511 dollar_label_clear ();
513 #ifndef WORKING_DOT_WORD
514 if (new_broken_words
)
516 struct broken_word
*a
;
521 if (now_seg
== absolute_section
)
523 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
527 possible_bytes
= (md_short_jump_size
528 + new_broken_words
* md_long_jump_size
);
531 frag_opcode
= frag_var (rs_broken_word
,
535 (symbolS
*) broken_words
,
539 /* We want to store the pointer to where to insert the jump
540 table in the fr_opcode of the rs_broken_word frag. This
541 requires a little hackery. */
543 && (frag_tmp
->fr_type
!= rs_broken_word
544 || frag_tmp
->fr_opcode
))
545 frag_tmp
= frag_tmp
->fr_next
;
547 frag_tmp
->fr_opcode
= frag_opcode
;
548 new_broken_words
= 0;
550 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
551 a
->dispfrag
= frag_tmp
;
553 #endif /* WORKING_DOT_WORD */
555 #ifdef obj_frob_colon
556 obj_frob_colon (sym_name
);
559 if ((symbolP
= symbol_find (sym_name
)) != 0)
561 S_CLEAR_WEAKREFR (symbolP
);
562 #ifdef RESOLVE_SYMBOL_REDEFINITION
563 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
566 /* Now check for undefined symbols. */
567 if (symbolP
->flags
.local_symbol
)
569 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
571 if (locsym
->section
!= undefined_section
572 && (locsym
->frag
!= frag_now
573 || locsym
->section
!= now_seg
574 || locsym
->value
!= frag_now_fix ()))
576 as_bad (_("symbol `%s' is already defined"), sym_name
);
580 locsym
->section
= now_seg
;
581 locsym
->frag
= frag_now
;
582 locsym
->value
= frag_now_fix ();
584 else if (!(S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
585 || S_IS_COMMON (symbolP
)
586 || S_IS_VOLATILE (symbolP
))
588 if (S_IS_VOLATILE (symbolP
))
590 symbolP
= symbol_clone (symbolP
, 1);
591 S_SET_VALUE (symbolP
, 0);
592 S_CLEAR_VOLATILE (symbolP
);
594 if (S_GET_VALUE (symbolP
) == 0)
596 define_sym_at_dot (symbolP
);
599 #endif /* if we have one, it better be zero. */
604 /* There are still several cases to check:
606 A .comm/.lcomm symbol being redefined as initialized
609 A .comm/.lcomm symbol being redefined with a larger
612 This only used to be allowed on VMS gas, but Sun cc
613 on the sparc also depends on it. */
615 if (((!S_IS_DEBUG (symbolP
)
616 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
617 && S_IS_EXTERNAL (symbolP
))
618 || S_GET_SEGMENT (symbolP
) == bss_section
)
619 && (now_seg
== data_section
620 || now_seg
== bss_section
621 || now_seg
== S_GET_SEGMENT (symbolP
)))
623 /* Select which of the 2 cases this is. */
624 if (now_seg
!= data_section
)
626 /* New .comm for prev .comm symbol.
628 If the new size is larger we just change its
629 value. If the new size is smaller, we ignore
631 if (S_GET_VALUE (symbolP
)
632 < ((unsigned) frag_now_fix ()))
634 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
639 /* It is a .comm/.lcomm being converted to initialized
641 define_sym_at_dot (symbolP
);
646 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT))
647 static const char *od_buf
= "";
651 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
652 sprintf (od_buf
, "%d.%d.",
653 S_GET_OTHER (symbolP
),
654 S_GET_DESC (symbolP
));
656 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
658 segment_name (S_GET_SEGMENT (symbolP
)),
660 (long) S_GET_VALUE (symbolP
));
662 } /* if the undefined symbol has no value */
666 /* Don't blow up if the definition is the same. */
667 if (!(frag_now
== symbolP
->frag
668 && S_GET_VALUE (symbolP
) == frag_now_fix ()
669 && S_GET_SEGMENT (symbolP
) == now_seg
))
671 as_bad (_("symbol `%s' is already defined"), sym_name
);
672 symbolP
= symbol_clone (symbolP
, 0);
673 define_sym_at_dot (symbolP
);
678 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
680 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
, frag_now
,
685 symbolP
= symbol_new (sym_name
, now_seg
, frag_now
, frag_now_fix ());
687 symbol_table_insert (symbolP
);
690 if (mri_common_symbol
!= NULL
)
692 /* This symbol is actually being defined within an MRI common
693 section. This requires special handling. */
694 if (symbolP
->flags
.local_symbol
)
695 symbolP
= local_symbol_convert (symbolP
);
696 symbolP
->x
->value
.X_op
= O_symbol
;
697 symbolP
->x
->value
.X_add_symbol
= mri_common_symbol
;
698 symbolP
->x
->value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
699 symbolP
->frag
= &zero_address_frag
;
700 S_SET_SEGMENT (symbolP
, expr_section
);
701 symbolP
->flags
.mri_common
= 1;
705 tc_frob_label (symbolP
);
707 #ifdef obj_frob_label
708 obj_frob_label (symbolP
);
714 /* Die if we can't insert the symbol. */
717 symbol_table_insert (symbolS
*symbolP
)
721 htab_insert (sy_hash
, symbolP
, 1);
724 /* If a symbol name does not exist, create it as undefined, and insert
725 it into the symbol table. Return a pointer to it. */
728 symbol_find_or_make (const char *name
)
732 symbolP
= symbol_find (name
);
736 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
738 symbolP
= md_undefined_symbol ((char *) name
);
742 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
743 &zero_address_frag
, 0);
747 symbolP
= symbol_make (name
);
749 symbol_table_insert (symbolP
);
750 } /* if symbol wasn't found */
756 symbol_make (const char *name
)
760 /* Let the machine description default it, e.g. for register names. */
761 symbolP
= md_undefined_symbol ((char *) name
);
764 symbolP
= symbol_new (name
, undefined_section
, &zero_address_frag
, 0);
770 symbol_clone (symbolS
*orgsymP
, int replace
)
773 asymbol
*bsymorg
, *bsymnew
;
775 /* Make sure we never clone the dot special symbol. */
776 gas_assert (orgsymP
!= &dot_symbol
);
778 /* When cloning a local symbol it isn't absolutely necessary to
779 convert the original, but converting makes the code much
780 simpler to cover this unexpected case. As of 2020-08-21
781 symbol_clone won't be called on a local symbol. */
782 if (orgsymP
->flags
.local_symbol
)
783 orgsymP
= local_symbol_convert (orgsymP
);
784 bsymorg
= orgsymP
->bsym
;
786 newsymP
= notes_alloc (sizeof (symbolS
) + sizeof (struct xsymbol
));
788 newsymP
->x
= (struct xsymbol
*) (newsymP
+ 1);
789 *newsymP
->x
= *orgsymP
->x
;
790 bsymnew
= bfd_make_empty_symbol (bfd_asymbol_bfd (bsymorg
));
792 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
793 newsymP
->bsym
= bsymnew
;
794 bsymnew
->name
= bsymorg
->name
;
795 bsymnew
->flags
= bsymorg
->flags
& ~BSF_SECTION_SYM
;
796 bsymnew
->section
= bsymorg
->section
;
797 bfd_copy_private_symbol_data (bfd_asymbol_bfd (bsymorg
), bsymorg
,
798 bfd_asymbol_bfd (bsymnew
), bsymnew
);
800 #ifdef obj_symbol_clone_hook
801 obj_symbol_clone_hook (newsymP
, orgsymP
);
804 #ifdef tc_symbol_clone_hook
805 tc_symbol_clone_hook (newsymP
, orgsymP
);
810 if (symbol_rootP
== orgsymP
)
811 symbol_rootP
= newsymP
;
812 else if (orgsymP
->x
->previous
)
814 orgsymP
->x
->previous
->x
->next
= newsymP
;
815 orgsymP
->x
->previous
= NULL
;
817 if (symbol_lastP
== orgsymP
)
818 symbol_lastP
= newsymP
;
819 else if (orgsymP
->x
->next
)
820 orgsymP
->x
->next
->x
->previous
= newsymP
;
822 /* Symbols that won't be output can't be external. */
823 S_CLEAR_EXTERNAL (orgsymP
);
824 orgsymP
->x
->previous
= orgsymP
->x
->next
= orgsymP
;
825 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
827 symbol_table_insert (newsymP
);
831 /* Symbols that won't be output can't be external. */
832 S_CLEAR_EXTERNAL (newsymP
);
833 newsymP
->x
->previous
= newsymP
->x
->next
= newsymP
;
839 /* Referenced symbols, if they are forward references, need to be cloned
840 (without replacing the original) so that the value of the referenced
841 symbols at the point of use is saved by the clone. */
843 #undef symbol_clone_if_forward_ref
845 symbol_clone_if_forward_ref (symbolS
*symbolP
, int is_forward
)
848 && !symbolP
->flags
.local_symbol
849 && !symbolP
->flags
.forward_resolved
)
851 symbolS
*orig_add_symbol
= symbolP
->x
->value
.X_add_symbol
;
852 symbolS
*orig_op_symbol
= symbolP
->x
->value
.X_op_symbol
;
853 symbolS
*add_symbol
= orig_add_symbol
;
854 symbolS
*op_symbol
= orig_op_symbol
;
856 if (symbolP
->flags
.forward_ref
)
861 /* assign_symbol() clones volatile symbols; pre-existing expressions
862 hold references to the original instance, but want the current
863 value. Just repeat the lookup. */
864 if (add_symbol
&& S_IS_VOLATILE (add_symbol
))
865 add_symbol
= symbol_find_exact (S_GET_NAME (add_symbol
));
866 if (op_symbol
&& S_IS_VOLATILE (op_symbol
))
867 op_symbol
= symbol_find_exact (S_GET_NAME (op_symbol
));
870 /* Re-using resolving here, as this routine cannot get called from
871 symbol resolution code. */
872 if ((symbolP
->bsym
->section
== expr_section
873 || symbolP
->flags
.forward_ref
)
874 && !symbolP
->flags
.resolving
)
876 symbolP
->flags
.resolving
= 1;
877 add_symbol
= symbol_clone_if_forward_ref (add_symbol
, is_forward
);
878 op_symbol
= symbol_clone_if_forward_ref (op_symbol
, is_forward
);
879 symbolP
->flags
.resolving
= 0;
882 if (symbolP
->flags
.forward_ref
883 || add_symbol
!= orig_add_symbol
884 || op_symbol
!= orig_op_symbol
)
886 if (symbolP
!= &dot_symbol
)
888 symbolP
= symbol_clone (symbolP
, 0);
889 symbolP
->flags
.resolving
= 0;
893 symbolP
= symbol_temp_new_now ();
894 #ifdef tc_new_dot_label
895 tc_new_dot_label (symbolP
);
900 symbolP
->x
->value
.X_add_symbol
= add_symbol
;
901 symbolP
->x
->value
.X_op_symbol
= op_symbol
;
902 symbolP
->flags
.forward_resolved
= 1;
909 symbol_temp_new (segT seg
, fragS
*frag
, valueT ofs
)
911 return symbol_new (FAKE_LABEL_NAME
, seg
, frag
, ofs
);
915 symbol_temp_new_now (void)
917 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix ());
921 symbol_temp_new_now_octets (void)
923 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix_octets ());
927 symbol_temp_make (void)
929 return symbol_make (FAKE_LABEL_NAME
);
932 /* Implement symbol table lookup.
933 In: A symbol's name as a string: '\0' can't be part of a symbol name.
934 Out: NULL if the name was not in the symbol table, else the address
935 of a struct symbol associated with that name. */
938 symbol_find_exact (const char *name
)
940 return symbol_find_exact_noref (name
, 0);
944 symbol_find_exact_noref (const char *name
, int noref
)
946 symbolS
*sym
= symbol_entry_find (sy_hash
, name
);
948 /* Any references to the symbol, except for the reference in
949 .weakref, must clear this flag, such that the symbol does not
950 turn into a weak symbol. Note that we don't have to handle the
951 local_symbol case, since a weakrefd is always promoted out of the
952 local_symbol table when it is turned into a weak symbol. */
954 S_CLEAR_WEAKREFD (sym
);
960 symbol_find (const char *name
)
962 return symbol_find_noref (name
, 0);
966 symbol_find_noref (const char *name
, int noref
)
971 #ifdef tc_canonicalize_symbol_name
973 copy
= xstrdup (name
);
974 name
= tc_canonicalize_symbol_name (copy
);
978 if (! symbols_case_sensitive
)
987 name
= copy
= XNEWVEC (char, strlen (name
) + 1);
989 while ((c
= *orig
++) != '\0')
990 *copy
++ = TOUPPER (c
);
994 copy
= (char *) name
;
997 result
= symbol_find_exact_noref (name
, noref
);
1002 /* Once upon a time, symbols were kept in a singly linked list. At
1003 least coff needs to be able to rearrange them from time to time, for
1004 which a doubly linked list is much more convenient. Loic did these
1005 as macros which seemed dangerous to me so they're now functions.
1008 /* Link symbol ADDME after symbol TARGET in the chain. */
1011 symbol_append (symbolS
*addme
, symbolS
*target
,
1012 symbolS
**rootPP
, symbolS
**lastPP
)
1014 extern int symbol_table_frozen
;
1015 if (symbol_table_frozen
)
1017 if (addme
->flags
.local_symbol
)
1019 if (target
!= NULL
&& target
->flags
.local_symbol
)
1024 know (*rootPP
== NULL
);
1025 know (*lastPP
== NULL
);
1026 addme
->x
->next
= NULL
;
1027 addme
->x
->previous
= NULL
;
1031 } /* if the list is empty */
1033 if (target
->x
->next
!= NULL
)
1035 target
->x
->next
->x
->previous
= addme
;
1039 know (*lastPP
== target
);
1041 } /* if we have a next */
1043 addme
->x
->next
= target
->x
->next
;
1044 target
->x
->next
= addme
;
1045 addme
->x
->previous
= target
;
1047 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
1050 /* Set the chain pointers of SYMBOL to null. */
1053 symbol_clear_list_pointers (symbolS
*symbolP
)
1055 if (symbolP
->flags
.local_symbol
)
1057 symbolP
->x
->next
= NULL
;
1058 symbolP
->x
->previous
= NULL
;
1061 /* Remove SYMBOLP from the list. */
1064 symbol_remove (symbolS
*symbolP
, symbolS
**rootPP
, symbolS
**lastPP
)
1066 if (symbolP
->flags
.local_symbol
)
1069 if (symbolP
== *rootPP
)
1071 *rootPP
= symbolP
->x
->next
;
1072 } /* if it was the root */
1074 if (symbolP
== *lastPP
)
1076 *lastPP
= symbolP
->x
->previous
;
1077 } /* if it was the tail */
1079 if (symbolP
->x
->next
!= NULL
)
1081 symbolP
->x
->next
->x
->previous
= symbolP
->x
->previous
;
1084 if (symbolP
->x
->previous
!= NULL
)
1086 symbolP
->x
->previous
->x
->next
= symbolP
->x
->next
;
1087 } /* if not first */
1089 debug_verify_symchain (*rootPP
, *lastPP
);
1092 /* Link symbol ADDME before symbol TARGET in the chain. */
1095 symbol_insert (symbolS
*addme
, symbolS
*target
,
1096 symbolS
**rootPP
, symbolS
**lastPP ATTRIBUTE_UNUSED
)
1098 extern int symbol_table_frozen
;
1099 if (symbol_table_frozen
)
1101 if (addme
->flags
.local_symbol
)
1103 if (target
->flags
.local_symbol
)
1106 if (target
->x
->previous
!= NULL
)
1108 target
->x
->previous
->x
->next
= addme
;
1112 know (*rootPP
== target
);
1114 } /* if not first */
1116 addme
->x
->previous
= target
->x
->previous
;
1117 target
->x
->previous
= addme
;
1118 addme
->x
->next
= target
;
1120 debug_verify_symchain (*rootPP
, *lastPP
);
1124 verify_symbol_chain (symbolS
*rootP
, symbolS
*lastP
)
1126 symbolS
*symbolP
= rootP
;
1128 if (symbolP
== NULL
)
1131 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
1133 gas_assert (symbolP
->bsym
!= NULL
);
1134 gas_assert (symbolP
->flags
.local_symbol
== 0);
1135 gas_assert (symbolP
->x
->next
->x
->previous
== symbolP
);
1138 gas_assert (lastP
== symbolP
);
1142 symbol_on_chain (symbolS
*s
, symbolS
*rootPP
, symbolS
*lastPP
)
1144 return (!s
->flags
.local_symbol
1145 && ((s
->x
->next
!= s
1146 && s
->x
->next
!= NULL
1147 && s
->x
->next
->x
->previous
== s
)
1149 && ((s
->x
->previous
!= s
1150 && s
->x
->previous
!= NULL
1151 && s
->x
->previous
->x
->next
== s
)
1155 #ifdef OBJ_COMPLEX_RELC
1158 use_complex_relocs_for (symbolS
* symp
)
1160 switch (symp
->x
->value
.X_op
)
1170 case O_bit_inclusive_or
:
1172 case O_bit_exclusive_or
:
1184 if ((S_IS_COMMON (symp
->x
->value
.X_op_symbol
)
1185 || S_IS_LOCAL (symp
->x
->value
.X_op_symbol
))
1186 && S_IS_DEFINED (symp
->x
->value
.X_op_symbol
)
1187 && S_GET_SEGMENT (symp
->x
->value
.X_op_symbol
) != expr_section
)
1194 if ((S_IS_COMMON (symp
->x
->value
.X_add_symbol
)
1195 || S_IS_LOCAL (symp
->x
->value
.X_add_symbol
))
1196 && S_IS_DEFINED (symp
->x
->value
.X_add_symbol
)
1197 && S_GET_SEGMENT (symp
->x
->value
.X_add_symbol
) != expr_section
)
1210 report_op_error (symbolS
*symp
, symbolS
*left
, operatorT op
, symbolS
*right
)
1214 segT seg_left
= left
? S_GET_SEGMENT (left
) : 0;
1215 segT seg_right
= S_GET_SEGMENT (right
);
1224 case O_uminus
: opname
= "-"; break;
1225 case O_bit_not
: opname
= "~"; break;
1226 case O_logical_not
: opname
= "!"; break;
1227 case O_multiply
: opname
= "*"; break;
1228 case O_divide
: opname
= "/"; break;
1229 case O_modulus
: opname
= "%"; break;
1230 case O_left_shift
: opname
= "<<"; break;
1231 case O_right_shift
: opname
= ">>"; break;
1232 case O_bit_inclusive_or
: opname
= "|"; break;
1233 case O_bit_or_not
: opname
= "|~"; break;
1234 case O_bit_exclusive_or
: opname
= "^"; break;
1235 case O_bit_and
: opname
= "&"; break;
1236 case O_add
: opname
= "+"; break;
1237 case O_subtract
: opname
= "-"; break;
1238 case O_eq
: opname
= "=="; break;
1239 case O_ne
: opname
= "!="; break;
1240 case O_lt
: opname
= "<"; break;
1241 case O_le
: opname
= "<="; break;
1242 case O_ge
: opname
= ">="; break;
1243 case O_gt
: opname
= ">"; break;
1244 case O_logical_and
: opname
= "&&"; break;
1245 case O_logical_or
: opname
= "||"; break;
1248 if (expr_symbol_where (symp
, &file
, &line
))
1251 as_bad_where (file
, line
,
1252 _("invalid operands (%s and %s sections) for `%s'"),
1253 seg_left
->name
, seg_right
->name
, opname
);
1255 as_bad_where (file
, line
,
1256 _("invalid operand (%s section) for `%s'"),
1257 seg_right
->name
, opname
);
1261 const char *sname
= S_GET_NAME (symp
);
1264 as_bad (_("invalid operands (%s and %s sections) for `%s' when setting `%s'"),
1265 seg_left
->name
, seg_right
->name
, opname
, sname
);
1267 as_bad (_("invalid operand (%s section) for `%s' when setting `%s'"),
1268 seg_right
->name
, opname
, sname
);
1272 /* Resolve the value of a symbol. This is called during the final
1273 pass over the symbol table to resolve any symbols with complex
1277 resolve_symbol_value (symbolS
*symp
)
1283 if (symp
->flags
.local_symbol
)
1285 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1287 final_val
= locsym
->value
;
1288 if (locsym
->flags
.resolved
)
1291 /* Symbols whose section has SEC_ELF_OCTETS set,
1292 resolve to octets instead of target bytes. */
1293 if (locsym
->section
->flags
& SEC_OCTETS
)
1294 final_val
+= locsym
->frag
->fr_address
;
1296 final_val
+= locsym
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1300 locsym
->value
= final_val
;
1301 locsym
->flags
.resolved
= 1;
1307 if (symp
->flags
.resolved
)
1310 while (symp
->x
->value
.X_op
== O_symbol
)
1312 final_val
+= symp
->x
->value
.X_add_number
;
1313 symp
= symp
->x
->value
.X_add_symbol
;
1314 if (symp
->flags
.local_symbol
)
1316 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1317 final_val
+= locsym
->value
;
1320 if (!symp
->flags
.resolved
)
1323 if (symp
->x
->value
.X_op
== O_constant
)
1324 final_val
+= symp
->x
->value
.X_add_number
;
1331 final_seg
= S_GET_SEGMENT (symp
);
1333 if (symp
->flags
.resolving
)
1336 as_bad (_("symbol definition loop encountered at `%s'"),
1341 #ifdef OBJ_COMPLEX_RELC
1342 else if (final_seg
== expr_section
1343 && use_complex_relocs_for (symp
))
1345 symbolS
* relc_symbol
= NULL
;
1346 char * relc_symbol_name
= NULL
;
1348 relc_symbol_name
= symbol_relc_make_expr (& symp
->x
->value
);
1350 /* For debugging, print out conversion input & output. */
1352 print_expr (& symp
->x
->value
);
1353 if (relc_symbol_name
)
1354 fprintf (stderr
, "-> relc symbol: %s\n", relc_symbol_name
);
1357 if (relc_symbol_name
!= NULL
)
1358 relc_symbol
= symbol_new (relc_symbol_name
, undefined_section
,
1359 &zero_address_frag
, 0);
1361 if (relc_symbol
== NULL
)
1363 as_bad (_("cannot convert expression symbol %s to complex relocation"),
1369 symbol_table_insert (relc_symbol
);
1371 /* S_CLEAR_EXTERNAL (relc_symbol); */
1372 if (symp
->bsym
->flags
& BSF_SRELC
)
1373 relc_symbol
->bsym
->flags
|= BSF_SRELC
;
1375 relc_symbol
->bsym
->flags
|= BSF_RELC
;
1376 /* symp->bsym->flags |= BSF_RELC; */
1377 copy_symbol_attributes (symp
, relc_symbol
);
1378 symp
->x
->value
.X_op
= O_symbol
;
1379 symp
->x
->value
.X_add_symbol
= relc_symbol
;
1380 symp
->x
->value
.X_add_number
= 0;
1385 final_seg
= undefined_section
;
1386 goto exit_dont_set_value
;
1391 symbolS
*add_symbol
, *op_symbol
;
1392 offsetT left
, right
;
1393 segT seg_left
, seg_right
;
1397 symp
->flags
.resolving
= 1;
1399 /* Help out with CSE. */
1400 add_symbol
= symp
->x
->value
.X_add_symbol
;
1401 op_symbol
= symp
->x
->value
.X_op_symbol
;
1402 final_val
= symp
->x
->value
.X_add_number
;
1403 op
= symp
->x
->value
.X_op
;
1443 #ifdef md_resolve_symbol
1444 resolved
= md_resolve_symbol (symp
, &final_val
, &final_seg
);
1448 goto exit_dont_set_value
;
1455 /* Symbols whose section has SEC_ELF_OCTETS set,
1456 resolve to octets instead of target bytes. */
1457 if (symp
->bsym
->section
->flags
& SEC_OCTETS
)
1458 final_val
+= symp
->frag
->fr_address
;
1460 final_val
+= symp
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1461 if (final_seg
== expr_section
)
1462 final_seg
= absolute_section
;
1472 left
= resolve_symbol_value (add_symbol
);
1473 seg_left
= S_GET_SEGMENT (add_symbol
);
1475 symp
->x
->value
.X_op_symbol
= NULL
;
1478 if (S_IS_WEAKREFR (symp
))
1480 gas_assert (final_val
== 0);
1481 if (S_IS_WEAKREFR (add_symbol
))
1483 gas_assert (add_symbol
->x
->value
.X_op
== O_symbol
1484 && add_symbol
->x
->value
.X_add_number
== 0);
1485 add_symbol
= add_symbol
->x
->value
.X_add_symbol
;
1486 gas_assert (! S_IS_WEAKREFR (add_symbol
));
1487 symp
->x
->value
.X_add_symbol
= add_symbol
;
1491 if (symp
->flags
.mri_common
)
1493 /* This is a symbol inside an MRI common section. The
1494 relocation routines are going to handle it specially.
1495 Don't change the value. */
1496 resolved
= symbol_resolved_p (add_symbol
);
1500 /* Don't leave symbol loops. */
1502 && !add_symbol
->flags
.local_symbol
1503 && add_symbol
->flags
.resolving
)
1506 if (finalize_syms
&& final_val
== 0
1508 /* Avoid changing symp's "within" when dealing with
1509 AIX debug symbols. For some storage classes, "within"
1510 have a special meaning.
1511 C_DWARF should behave like on Linux, thus this check
1512 isn't done to be closer. */
1513 && ((symbol_get_bfdsym (symp
)->flags
& BSF_DEBUGGING
) == 0
1514 || (S_GET_STORAGE_CLASS (symp
) == C_DWARF
))
1518 if (add_symbol
->flags
.local_symbol
)
1519 add_symbol
= local_symbol_convert (add_symbol
);
1520 copy_symbol_attributes (symp
, add_symbol
);
1523 /* If we have equated this symbol to an undefined or common
1524 symbol, keep X_op set to O_symbol, and don't change
1525 X_add_number. This permits the routine which writes out
1526 relocation to detect this case, and convert the
1527 relocation to be against the symbol to which this symbol
1529 if (seg_left
== undefined_section
1530 || bfd_is_com_section (seg_left
)
1531 #if defined (OBJ_COFF) && defined (TE_PE)
1532 || S_IS_WEAK (add_symbol
)
1535 && ((final_seg
== expr_section
1536 && seg_left
!= expr_section
1537 && seg_left
!= absolute_section
)
1538 || symbol_shadow_p (symp
))))
1542 symp
->x
->value
.X_op
= O_symbol
;
1543 symp
->x
->value
.X_add_symbol
= add_symbol
;
1544 symp
->x
->value
.X_add_number
= final_val
;
1545 /* Use X_op_symbol as a flag. */
1546 symp
->x
->value
.X_op_symbol
= add_symbol
;
1548 final_seg
= seg_left
;
1549 final_val
+= symp
->frag
->fr_address
+ left
;
1550 resolved
= symbol_resolved_p (add_symbol
);
1551 symp
->flags
.resolving
= 0;
1553 if (op
== O_secidx
&& seg_left
!= undefined_section
)
1559 goto exit_dont_set_value
;
1563 final_val
+= symp
->frag
->fr_address
+ left
;
1564 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1565 final_seg
= seg_left
;
1568 resolved
= symbol_resolved_p (add_symbol
);
1569 if (S_IS_WEAKREFR (symp
))
1571 symp
->flags
.resolving
= 0;
1572 goto exit_dont_set_value
;
1579 left
= resolve_symbol_value (add_symbol
);
1580 seg_left
= S_GET_SEGMENT (add_symbol
);
1582 /* By reducing these to the relevant dyadic operator, we get
1583 !S -> S == 0 permitted on anything,
1584 -S -> 0 - S only permitted on absolute
1585 ~S -> S ^ ~0 only permitted on absolute */
1586 if (op
!= O_logical_not
&& seg_left
!= absolute_section
1588 report_op_error (symp
, NULL
, op
, add_symbol
);
1590 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1591 final_seg
= absolute_section
;
1595 else if (op
== O_logical_not
)
1600 final_val
+= left
+ symp
->frag
->fr_address
;
1602 resolved
= symbol_resolved_p (add_symbol
);
1610 case O_bit_inclusive_or
:
1612 case O_bit_exclusive_or
:
1624 left
= resolve_symbol_value (add_symbol
);
1625 right
= resolve_symbol_value (op_symbol
);
1626 seg_left
= S_GET_SEGMENT (add_symbol
);
1627 seg_right
= S_GET_SEGMENT (op_symbol
);
1629 /* Simplify addition or subtraction of a constant by folding the
1630 constant into X_add_number. */
1633 if (seg_right
== absolute_section
)
1638 else if (seg_left
== absolute_section
)
1641 add_symbol
= op_symbol
;
1643 seg_left
= seg_right
;
1647 else if (op
== O_subtract
)
1649 if (seg_right
== absolute_section
)
1657 /* Equality and non-equality tests are permitted on anything.
1658 Subtraction, and other comparison operators are permitted if
1659 both operands are in the same section. Otherwise, both
1660 operands must be absolute. We already handled the case of
1661 addition or subtraction of a constant above. This will
1662 probably need to be changed for an object file format which
1663 supports arbitrary expressions. */
1664 if (!(seg_left
== absolute_section
1665 && seg_right
== absolute_section
)
1666 && !(op
== O_eq
|| op
== O_ne
)
1667 && !((op
== O_subtract
1668 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1669 && seg_left
== seg_right
1670 && (seg_left
!= undefined_section
1671 || add_symbol
== op_symbol
)))
1673 /* Don't emit messages unless we're finalizing the symbol value,
1674 otherwise we may get the same message multiple times. */
1676 report_op_error (symp
, add_symbol
, op
, op_symbol
);
1677 /* However do not move the symbol into the absolute section
1678 if it cannot currently be resolved - this would confuse
1679 other parts of the assembler into believing that the
1680 expression had been evaluated to zero. */
1686 && (final_seg
== expr_section
|| final_seg
== undefined_section
))
1687 final_seg
= absolute_section
;
1689 /* Check for division by zero. */
1690 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1692 /* If seg_right is not absolute_section, then we've
1693 already issued a warning about using a bad symbol. */
1694 if (seg_right
== absolute_section
&& finalize_syms
)
1699 if (expr_symbol_where (symp
, &file
, &line
))
1700 as_bad_where (file
, line
, _("division by zero"));
1702 as_bad (_("division by zero when setting `%s'"),
1708 if ((op
== O_left_shift
|| op
== O_right_shift
)
1709 && (valueT
) right
>= sizeof (valueT
) * CHAR_BIT
)
1711 as_warn_value_out_of_range (_("shift count"), right
, 0,
1712 sizeof (valueT
) * CHAR_BIT
- 1,
1717 switch (symp
->x
->value
.X_op
)
1719 case O_multiply
: left
*= right
; break;
1720 case O_divide
: left
/= right
; break;
1721 case O_modulus
: left
%= right
; break;
1723 left
= (valueT
) left
<< (valueT
) right
; break;
1725 left
= (valueT
) left
>> (valueT
) right
; break;
1726 case O_bit_inclusive_or
: left
|= right
; break;
1727 case O_bit_or_not
: left
|= ~right
; break;
1728 case O_bit_exclusive_or
: left
^= right
; break;
1729 case O_bit_and
: left
&= right
; break;
1730 case O_add
: left
+= right
; break;
1731 case O_subtract
: left
-= right
; break;
1734 left
= (left
== right
&& seg_left
== seg_right
1735 && (seg_left
!= undefined_section
1736 || add_symbol
== op_symbol
)
1737 ? ~ (offsetT
) 0 : 0);
1738 if (symp
->x
->value
.X_op
== O_ne
)
1741 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1742 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1743 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1744 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1745 case O_logical_and
: left
= left
&& right
; break;
1746 case O_logical_or
: left
= left
|| right
; break;
1751 /* See PR 20895 for a reproducer. */
1752 as_bad (_("Invalid operation on symbol"));
1753 goto exit_dont_set_value
;
1759 final_val
+= symp
->frag
->fr_address
+ left
;
1760 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1762 if (seg_left
== undefined_section
1763 || seg_right
== undefined_section
)
1764 final_seg
= undefined_section
;
1765 else if (seg_left
== absolute_section
)
1766 final_seg
= seg_right
;
1768 final_seg
= seg_left
;
1770 resolved
= (symbol_resolved_p (add_symbol
)
1771 && symbol_resolved_p (op_symbol
));
1776 /* Give an error (below) if not in expr_section. We don't
1777 want to worry about expr_section symbols, because they
1778 are fictional (they are created as part of expression
1779 resolution), and any problems may not actually mean
1784 symp
->flags
.resolving
= 0;
1788 S_SET_VALUE (symp
, final_val
);
1790 exit_dont_set_value
:
1791 /* Always set the segment, even if not finalizing the value.
1792 The segment is used to determine whether a symbol is defined. */
1793 S_SET_SEGMENT (symp
, final_seg
);
1795 /* Don't worry if we can't resolve an expr_section symbol. */
1799 symp
->flags
.resolved
= 1;
1800 else if (S_GET_SEGMENT (symp
) != expr_section
)
1802 as_bad (_("can't resolve value for symbol `%s'"),
1804 symp
->flags
.resolved
= 1;
1811 /* A static function passed to hash_traverse. */
1814 resolve_local_symbol (void **slot
, void *arg ATTRIBUTE_UNUSED
)
1816 symbol_entry_t
*entry
= *((symbol_entry_t
**) slot
);
1817 if (entry
->sy
.flags
.local_symbol
)
1818 resolve_symbol_value (&entry
->sy
);
1823 /* Resolve all local symbols. */
1826 resolve_local_symbol_values (void)
1828 htab_traverse_noresize (sy_hash
, resolve_local_symbol
, NULL
);
1831 /* Obtain the current value of a symbol without changing any
1832 sub-expressions used. */
1835 snapshot_symbol (symbolS
**symbolPP
, valueT
*valueP
, segT
*segP
, fragS
**fragPP
)
1837 symbolS
*symbolP
= *symbolPP
;
1839 if (symbolP
->flags
.local_symbol
)
1841 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1843 *valueP
= locsym
->value
;
1844 *segP
= locsym
->section
;
1845 *fragPP
= locsym
->frag
;
1849 expressionS exp
= symbolP
->x
->value
;
1851 if (!symbolP
->flags
.resolved
&& exp
.X_op
!= O_illegal
)
1855 if (symbolP
->flags
.resolving
)
1857 symbolP
->flags
.resolving
= 1;
1858 resolved
= resolve_expression (&exp
);
1859 symbolP
->flags
.resolving
= 0;
1867 if (!symbol_equated_p (symbolP
))
1872 symbolP
= exp
.X_add_symbol
;
1879 *symbolPP
= symbolP
;
1881 /* A bogus input file can result in resolve_expression()
1882 generating a local symbol, so we have to check again. */
1883 if (symbolP
->flags
.local_symbol
)
1885 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1887 *valueP
= locsym
->value
;
1888 *segP
= locsym
->section
;
1889 *fragPP
= locsym
->frag
;
1893 *valueP
= exp
.X_add_number
;
1894 *segP
= symbolP
->bsym
->section
;
1895 *fragPP
= symbolP
->frag
;
1898 if (*segP
== expr_section
)
1901 case O_constant
: *segP
= absolute_section
; break;
1902 case O_register
: *segP
= reg_section
; break;
1910 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1911 They are *really* local. That is, they go out of scope whenever we see a
1912 label that isn't local. Also, like fb labels, there can be multiple
1913 instances of a dollar label. Therefor, we name encode each instance with
1914 the instance number, keep a list of defined symbols separate from the real
1915 symbol table, and we treat these buggers as a sparse array. */
1917 typedef unsigned int dollar_ent
;
1918 static dollar_ent
*dollar_labels
;
1919 static dollar_ent
*dollar_label_instances
;
1920 static char *dollar_label_defines
;
1921 static size_t dollar_label_count
;
1922 static size_t dollar_label_max
;
1925 dollar_label_defined (unsigned int label
)
1929 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1931 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1933 return dollar_label_defines
[i
- dollar_labels
];
1935 /* If we get here, label isn't defined. */
1940 dollar_label_instance (unsigned int label
)
1944 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1946 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1948 return (dollar_label_instances
[i
- dollar_labels
]);
1950 /* If we get here, we haven't seen the label before.
1951 Therefore its instance count is zero. */
1956 dollar_label_clear (void)
1958 if (dollar_label_count
)
1959 memset (dollar_label_defines
, '\0', dollar_label_count
);
1962 #define DOLLAR_LABEL_BUMP_BY 10
1965 define_dollar_label (unsigned int label
)
1969 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1972 ++dollar_label_instances
[i
- dollar_labels
];
1973 dollar_label_defines
[i
- dollar_labels
] = 1;
1977 /* If we get to here, we don't have label listed yet. */
1979 if (dollar_labels
== NULL
)
1981 dollar_labels
= XNEWVEC (dollar_ent
, DOLLAR_LABEL_BUMP_BY
);
1982 dollar_label_instances
= XNEWVEC (dollar_ent
, DOLLAR_LABEL_BUMP_BY
);
1983 dollar_label_defines
= XNEWVEC (char, DOLLAR_LABEL_BUMP_BY
);
1984 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1985 dollar_label_count
= 0;
1987 else if (dollar_label_count
== dollar_label_max
)
1989 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1990 dollar_labels
= XRESIZEVEC (dollar_ent
, dollar_labels
,
1992 dollar_label_instances
= XRESIZEVEC (dollar_ent
,
1993 dollar_label_instances
,
1995 dollar_label_defines
= XRESIZEVEC (char, dollar_label_defines
,
1997 } /* if we needed to grow */
1999 dollar_labels
[dollar_label_count
] = label
;
2000 dollar_label_instances
[dollar_label_count
] = 1;
2001 dollar_label_defines
[dollar_label_count
] = 1;
2002 ++dollar_label_count
;
2005 /* Caller must copy returned name: we re-use the area for the next name.
2007 The mth occurrence of label n: is turned into the symbol "Ln^Am"
2008 where n is the label number and m is the instance number. "L" makes
2009 it a label discarded unless debugging and "^A"('\1') ensures no
2010 ordinary symbol SHOULD get the same name as a local label
2011 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
2013 fb labels get the same treatment, except that ^B is used in place
2016 AUGEND is 0 for current instance, 1 for new instance. */
2019 dollar_label_name (unsigned int n
, unsigned int augend
)
2021 /* Returned to caller, then copied. Used for created names ("4f"). */
2022 static char symbol_name_build
[24];
2023 char *p
= symbol_name_build
;
2025 #ifdef LOCAL_LABEL_PREFIX
2026 *p
++ = LOCAL_LABEL_PREFIX
;
2028 sprintf (p
, "L%u%c%u",
2029 n
, DOLLAR_LABEL_CHAR
, dollar_label_instance (n
) + augend
);
2030 return symbol_name_build
;
2033 /* Somebody else's idea of local labels. They are made by "n:" where n
2034 is any decimal digit. Refer to them with
2035 "nb" for previous (backward) n:
2036 or "nf" for next (forward) n:.
2038 We do a little better and let n be any number, not just a single digit, but
2039 since the other guy's assembler only does ten, we treat the first ten
2042 Like someone else's assembler, we have one set of local label counters for
2043 entire assembly, not one set per (sub)segment like in most assemblers. This
2044 implies that one can refer to a label in another segment, and indeed some
2045 crufty compilers have done just that.
2047 Since there could be a LOT of these things, treat them as a sparse
2050 #define FB_LABEL_SPECIAL (10)
2052 typedef unsigned int fb_ent
;
2053 static fb_ent fb_low_counter
[FB_LABEL_SPECIAL
];
2054 static fb_ent
*fb_labels
;
2055 static fb_ent
*fb_label_instances
;
2056 static size_t fb_label_count
;
2057 static size_t fb_label_max
;
2059 /* This must be more than FB_LABEL_SPECIAL. */
2060 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
2063 fb_label_init (void)
2065 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
2068 /* Add one to the instance number of this fb label. */
2071 fb_label_instance_inc (unsigned int label
)
2075 if (label
< FB_LABEL_SPECIAL
)
2077 ++fb_low_counter
[label
];
2081 if (fb_labels
!= NULL
)
2083 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2084 i
< fb_labels
+ fb_label_count
; ++i
)
2088 ++fb_label_instances
[i
- fb_labels
];
2090 } /* if we find it */
2091 } /* for each existing label */
2094 /* If we get to here, we don't have label listed yet. */
2096 if (fb_labels
== NULL
)
2098 fb_labels
= XNEWVEC (fb_ent
, FB_LABEL_BUMP_BY
);
2099 fb_label_instances
= XNEWVEC (fb_ent
, FB_LABEL_BUMP_BY
);
2100 fb_label_max
= FB_LABEL_BUMP_BY
;
2101 fb_label_count
= FB_LABEL_SPECIAL
;
2104 else if (fb_label_count
== fb_label_max
)
2106 fb_label_max
+= FB_LABEL_BUMP_BY
;
2107 fb_labels
= XRESIZEVEC (fb_ent
, fb_labels
, fb_label_max
);
2108 fb_label_instances
= XRESIZEVEC (fb_ent
, fb_label_instances
,
2110 } /* if we needed to grow */
2112 fb_labels
[fb_label_count
] = label
;
2113 fb_label_instances
[fb_label_count
] = 1;
2118 fb_label_instance (unsigned int label
)
2122 if (label
< FB_LABEL_SPECIAL
)
2123 return (fb_low_counter
[label
]);
2125 if (fb_labels
!= NULL
)
2127 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2128 i
< fb_labels
+ fb_label_count
; ++i
)
2131 return (fb_label_instances
[i
- fb_labels
]);
2135 /* We didn't find the label, so this must be a reference to the
2140 /* Caller must copy returned name: we re-use the area for the next name.
2142 The mth occurrence of label n: is turned into the symbol "Ln^Bm"
2143 where n is the label number and m is the instance number. "L" makes
2144 it a label discarded unless debugging and "^B"('\2') ensures no
2145 ordinary symbol SHOULD get the same name as a local label
2146 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
2148 dollar labels get the same treatment, except that ^A is used in
2151 AUGEND is 0 for nb, 1 for n:, nf. */
2154 fb_label_name (unsigned int n
, unsigned int augend
)
2156 /* Returned to caller, then copied. Used for created names ("4f"). */
2157 static char symbol_name_build
[24];
2158 char *p
= symbol_name_build
;
2161 know (augend
<= 2 /* See mmix_fb_label. */);
2166 #ifdef LOCAL_LABEL_PREFIX
2167 *p
++ = LOCAL_LABEL_PREFIX
;
2169 sprintf (p
, "L%u%c%u",
2170 n
, LOCAL_LABEL_CHAR
, fb_label_instance (n
) + augend
);
2171 return symbol_name_build
;
2174 /* Decode name that may have been generated by foo_label_name() above.
2175 If the name wasn't generated by foo_label_name(), then return it
2176 unaltered. This is used for error messages. */
2179 decode_local_label_name (char *s
)
2182 char *symbol_decode
;
2184 int instance_number
;
2186 const char *message_format
;
2189 #ifdef LOCAL_LABEL_PREFIX
2190 if (s
[lindex
] == LOCAL_LABEL_PREFIX
)
2194 if (s
[lindex
] != 'L')
2197 for (label_number
= 0, p
= s
+ lindex
+ 1; ISDIGIT (*p
); ++p
)
2198 label_number
= (10 * label_number
) + *p
- '0';
2200 if (*p
== DOLLAR_LABEL_CHAR
)
2202 else if (*p
== LOCAL_LABEL_CHAR
)
2207 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
2208 instance_number
= (10 * instance_number
) + *p
- '0';
2210 message_format
= _("\"%d\" (instance number %d of a %s label)");
2211 symbol_decode
= notes_alloc (strlen (message_format
) + 30);
2212 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
2214 return symbol_decode
;
2217 /* Get the value of a symbol. */
2220 S_GET_VALUE_WHERE (symbolS
*s
, const char * file
, unsigned int line
)
2222 if (s
->flags
.local_symbol
)
2223 return resolve_symbol_value (s
);
2225 if (!s
->flags
.resolved
)
2227 valueT val
= resolve_symbol_value (s
);
2231 if (S_IS_WEAKREFR (s
))
2232 return S_GET_VALUE (s
->x
->value
.X_add_symbol
);
2234 if (s
->x
->value
.X_op
!= O_constant
)
2236 if (! s
->flags
.resolved
2237 || s
->x
->value
.X_op
!= O_symbol
2238 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
2240 if (strcmp (S_GET_NAME (s
), FAKE_LABEL_NAME
) == 0)
2241 as_bad_where (file
, line
, _("expression is too complex to be resolved or converted into relocations"));
2242 else if (file
!= NULL
)
2243 as_bad_where (file
, line
, _("attempt to get value of unresolved symbol `%s'"),
2246 as_bad (_("attempt to get value of unresolved symbol `%s'"),
2250 return (valueT
) s
->x
->value
.X_add_number
;
2254 S_GET_VALUE (symbolS
*s
)
2256 return S_GET_VALUE_WHERE (s
, NULL
, 0);
2259 /* Set the value of a symbol. */
2262 S_SET_VALUE (symbolS
*s
, valueT val
)
2264 if (s
->flags
.local_symbol
)
2266 ((struct local_symbol
*) s
)->value
= val
;
2270 s
->x
->value
.X_op
= O_constant
;
2271 s
->x
->value
.X_add_number
= (offsetT
) val
;
2272 s
->x
->value
.X_unsigned
= 0;
2273 S_CLEAR_WEAKREFR (s
);
2277 copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2279 if (dest
->flags
.local_symbol
)
2280 dest
= local_symbol_convert (dest
);
2281 if (src
->flags
.local_symbol
)
2282 src
= local_symbol_convert (src
);
2284 /* In an expression, transfer the settings of these flags.
2285 The user can override later, of course. */
2286 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT \
2287 | BSF_GNU_INDIRECT_FUNCTION)
2288 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
2290 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
2291 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2294 #ifdef TC_COPY_SYMBOL_ATTRIBUTES
2295 TC_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2300 S_IS_FUNCTION (symbolS
*s
)
2304 if (s
->flags
.local_symbol
)
2307 flags
= s
->bsym
->flags
;
2309 return (flags
& BSF_FUNCTION
) != 0;
2313 S_IS_EXTERNAL (symbolS
*s
)
2317 if (s
->flags
.local_symbol
)
2320 flags
= s
->bsym
->flags
;
2323 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2326 return (flags
& BSF_GLOBAL
) != 0;
2330 S_IS_WEAK (symbolS
*s
)
2332 if (s
->flags
.local_symbol
)
2334 /* Conceptually, a weakrefr is weak if the referenced symbol is. We
2335 could probably handle a WEAKREFR as always weak though. E.g., if
2336 the referenced symbol has lost its weak status, there's no reason
2337 to keep handling the weakrefr as if it was weak. */
2338 if (S_IS_WEAKREFR (s
))
2339 return S_IS_WEAK (s
->x
->value
.X_add_symbol
);
2340 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
2344 S_IS_WEAKREFR (symbolS
*s
)
2346 if (s
->flags
.local_symbol
)
2348 return s
->flags
.weakrefr
!= 0;
2352 S_IS_WEAKREFD (symbolS
*s
)
2354 if (s
->flags
.local_symbol
)
2356 return s
->flags
.weakrefd
!= 0;
2360 S_IS_COMMON (symbolS
*s
)
2362 if (s
->flags
.local_symbol
)
2364 return bfd_is_com_section (s
->bsym
->section
);
2368 S_IS_DEFINED (symbolS
*s
)
2370 if (s
->flags
.local_symbol
)
2371 return ((struct local_symbol
*) s
)->section
!= undefined_section
;
2372 return s
->bsym
->section
!= undefined_section
;
2376 #ifndef EXTERN_FORCE_RELOC
2377 #define EXTERN_FORCE_RELOC IS_ELF
2380 /* Return true for symbols that should not be reduced to section
2381 symbols or eliminated from expressions, because they may be
2382 overridden by the linker. */
2384 S_FORCE_RELOC (symbolS
*s
, int strict
)
2387 if (s
->flags
.local_symbol
)
2388 sec
= ((struct local_symbol
*) s
)->section
;
2392 && ((s
->bsym
->flags
& BSF_WEAK
) != 0
2393 || (EXTERN_FORCE_RELOC
2394 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)))
2395 || (s
->bsym
->flags
& BSF_GNU_INDIRECT_FUNCTION
) != 0)
2397 sec
= s
->bsym
->section
;
2399 return bfd_is_und_section (sec
) || bfd_is_com_section (sec
);
2403 S_IS_DEBUG (symbolS
*s
)
2405 if (s
->flags
.local_symbol
)
2407 if (s
->bsym
->flags
& BSF_DEBUGGING
)
2413 S_IS_LOCAL (symbolS
*s
)
2418 if (s
->flags
.local_symbol
)
2421 flags
= s
->bsym
->flags
;
2424 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2427 if (bfd_asymbol_section (s
->bsym
) == reg_section
)
2430 if (flag_strip_local_absolute
2431 /* Keep BSF_FILE symbols in order to allow debuggers to identify
2432 the source file even when the object file is stripped. */
2433 && (flags
& (BSF_GLOBAL
| BSF_FILE
)) == 0
2434 && bfd_asymbol_section (s
->bsym
) == absolute_section
)
2437 name
= S_GET_NAME (s
);
2438 return (name
!= NULL
2440 && (strchr (name
, DOLLAR_LABEL_CHAR
)
2441 || strchr (name
, LOCAL_LABEL_CHAR
)
2442 #if FAKE_LABEL_CHAR != DOLLAR_LABEL_CHAR
2443 || strchr (name
, FAKE_LABEL_CHAR
)
2445 || TC_LABEL_IS_LOCAL (name
)
2446 || (! flag_keep_locals
2447 && (bfd_is_local_label (stdoutput
, s
->bsym
)
2450 && name
[1] == '?')))));
2454 S_IS_STABD (symbolS
*s
)
2456 return S_GET_NAME (s
) == 0;
2460 S_CAN_BE_REDEFINED (const symbolS
*s
)
2462 if (s
->flags
.local_symbol
)
2463 return (((struct local_symbol
*) s
)->frag
2464 == &predefined_address_frag
);
2465 /* Permit register names to be redefined. */
2466 return s
->bsym
->section
== reg_section
;
2470 S_IS_VOLATILE (const symbolS
*s
)
2472 if (s
->flags
.local_symbol
)
2474 return s
->flags
.volatil
;
2478 S_IS_FORWARD_REF (const symbolS
*s
)
2480 if (s
->flags
.local_symbol
)
2482 return s
->flags
.forward_ref
;
2486 S_GET_NAME (symbolS
*s
)
2492 S_GET_SEGMENT (symbolS
*s
)
2494 if (s
->flags
.local_symbol
)
2495 return ((struct local_symbol
*) s
)->section
;
2496 return s
->bsym
->section
;
2500 S_SET_SEGMENT (symbolS
*s
, segT seg
)
2502 if (s
->flags
.local_symbol
)
2504 ((struct local_symbol
*) s
)->section
= seg
;
2508 /* Don't reassign section symbols. The direct reason is to prevent seg
2509 faults assigning back to const global symbols such as *ABS*, but it
2510 shouldn't happen anyway. */
2511 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2513 if (s
->bsym
->section
!= seg
)
2518 if (multibyte_handling
== multibyte_warn_syms
2519 && ! s
->flags
.local_symbol
2520 && seg
!= undefined_section
2521 && ! s
->flags
.multibyte_warned
2522 && scan_for_multibyte_characters ((const unsigned char *) s
->name
,
2523 (const unsigned char *) s
->name
+ strlen (s
->name
),
2526 as_warn (_("symbol '%s' contains multibyte characters"), s
->name
);
2527 s
->flags
.multibyte_warned
= 1;
2530 s
->bsym
->section
= seg
;
2535 S_SET_EXTERNAL (symbolS
*s
)
2537 if (s
->flags
.local_symbol
)
2538 s
= local_symbol_convert (s
);
2539 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2541 /* Let .weak override .global. */
2544 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2546 /* Do not reassign section symbols. */
2547 as_warn (_("can't make section symbol global"));
2550 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
2551 if (S_GET_SEGMENT (s
) == reg_section
)
2553 as_bad (_("can't make register symbol global"));
2557 s
->bsym
->flags
|= BSF_GLOBAL
;
2558 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
2561 if (! an_external_name
&& S_GET_NAME(s
)[0] != '.')
2562 an_external_name
= S_GET_NAME (s
);
2567 S_CLEAR_EXTERNAL (symbolS
*s
)
2569 if (s
->flags
.local_symbol
)
2571 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2573 /* Let .weak override. */
2576 s
->bsym
->flags
|= BSF_LOCAL
;
2577 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
2581 S_SET_WEAK (symbolS
*s
)
2583 if (s
->flags
.local_symbol
)
2584 s
= local_symbol_convert (s
);
2585 #ifdef obj_set_weak_hook
2586 obj_set_weak_hook (s
);
2588 s
->bsym
->flags
|= BSF_WEAK
;
2589 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
2593 S_SET_WEAKREFR (symbolS
*s
)
2595 if (s
->flags
.local_symbol
)
2596 s
= local_symbol_convert (s
);
2597 s
->flags
.weakrefr
= 1;
2598 /* If the alias was already used, make sure we mark the target as
2599 used as well, otherwise it might be dropped from the symbol
2600 table. This may have unintended side effects if the alias is
2601 later redirected to another symbol, such as keeping the unused
2602 previous target in the symbol table. Since it will be weak, it's
2605 symbol_mark_used (s
->x
->value
.X_add_symbol
);
2609 S_CLEAR_WEAKREFR (symbolS
*s
)
2611 if (s
->flags
.local_symbol
)
2613 s
->flags
.weakrefr
= 0;
2617 S_SET_WEAKREFD (symbolS
*s
)
2619 if (s
->flags
.local_symbol
)
2620 s
= local_symbol_convert (s
);
2621 s
->flags
.weakrefd
= 1;
2626 S_CLEAR_WEAKREFD (symbolS
*s
)
2628 if (s
->flags
.local_symbol
)
2630 if (s
->flags
.weakrefd
)
2632 s
->flags
.weakrefd
= 0;
2633 /* If a weakref target symbol is weak, then it was never
2634 referenced directly before, not even in a .global directive,
2635 so decay it to local. If it remains undefined, it will be
2636 later turned into a global, like any other undefined
2638 if (s
->bsym
->flags
& BSF_WEAK
)
2640 #ifdef obj_clear_weak_hook
2641 obj_clear_weak_hook (s
);
2643 s
->bsym
->flags
&= ~BSF_WEAK
;
2644 s
->bsym
->flags
|= BSF_LOCAL
;
2650 S_SET_THREAD_LOCAL (symbolS
*s
)
2652 if (s
->flags
.local_symbol
)
2653 s
= local_symbol_convert (s
);
2654 if (bfd_is_com_section (s
->bsym
->section
)
2655 && (s
->bsym
->flags
& BSF_THREAD_LOCAL
) != 0)
2657 s
->bsym
->flags
|= BSF_THREAD_LOCAL
;
2658 if ((s
->bsym
->flags
& BSF_FUNCTION
) != 0)
2659 as_bad (_("Accessing function `%s' as thread-local object"),
2661 else if (! bfd_is_und_section (s
->bsym
->section
)
2662 && (s
->bsym
->section
->flags
& SEC_THREAD_LOCAL
) == 0)
2663 as_bad (_("Accessing `%s' as thread-local object"),
2668 S_SET_NAME (symbolS
*s
, const char *name
)
2671 if (s
->flags
.local_symbol
)
2673 s
->bsym
->name
= name
;
2677 S_SET_VOLATILE (symbolS
*s
)
2679 if (s
->flags
.local_symbol
)
2680 s
= local_symbol_convert (s
);
2681 s
->flags
.volatil
= 1;
2685 S_CLEAR_VOLATILE (symbolS
*s
)
2687 if (!s
->flags
.local_symbol
)
2688 s
->flags
.volatil
= 0;
2692 S_SET_FORWARD_REF (symbolS
*s
)
2694 if (s
->flags
.local_symbol
)
2695 s
= local_symbol_convert (s
);
2696 s
->flags
.forward_ref
= 1;
2699 /* Return the previous symbol in a chain. */
2702 symbol_previous (symbolS
*s
)
2704 if (s
->flags
.local_symbol
)
2706 return s
->x
->previous
;
2709 /* Return the next symbol in a chain. */
2712 symbol_next (symbolS
*s
)
2714 if (s
->flags
.local_symbol
)
2719 /* Return a pointer to the value of a symbol as an expression. */
2722 symbol_get_value_expression (symbolS
*s
)
2724 if (s
->flags
.local_symbol
)
2725 s
= local_symbol_convert (s
);
2726 return &s
->x
->value
;
2729 /* Set the value of a symbol to an expression. */
2732 symbol_set_value_expression (symbolS
*s
, const expressionS
*exp
)
2734 if (s
->flags
.local_symbol
)
2735 s
= local_symbol_convert (s
);
2737 S_CLEAR_WEAKREFR (s
);
2740 /* Return whether 2 symbols are the same. */
2743 symbol_same_p (symbolS
*s1
, symbolS
*s2
)
2748 /* Return a pointer to the X_add_number component of a symbol. */
2751 symbol_X_add_number (symbolS
*s
)
2753 if (s
->flags
.local_symbol
)
2754 return (offsetT
*) &((struct local_symbol
*) s
)->value
;
2756 return &s
->x
->value
.X_add_number
;
2759 /* Set the value of SYM to the current position in the current segment. */
2762 symbol_set_value_now (symbolS
*sym
)
2764 S_SET_SEGMENT (sym
, now_seg
);
2765 S_SET_VALUE (sym
, frag_now_fix ());
2766 symbol_set_frag (sym
, frag_now
);
2769 /* Set the frag of a symbol. */
2772 symbol_set_frag (symbolS
*s
, fragS
*f
)
2774 if (s
->flags
.local_symbol
)
2776 ((struct local_symbol
*) s
)->frag
= f
;
2780 S_CLEAR_WEAKREFR (s
);
2783 /* Return the frag of a symbol. */
2786 symbol_get_frag (symbolS
*s
)
2788 if (s
->flags
.local_symbol
)
2789 return ((struct local_symbol
*) s
)->frag
;
2793 /* Mark a symbol as having been used. */
2796 symbol_mark_used (symbolS
*s
)
2798 if (s
->flags
.local_symbol
)
2801 if (S_IS_WEAKREFR (s
))
2802 symbol_mark_used (s
->x
->value
.X_add_symbol
);
2805 /* Clear the mark of whether a symbol has been used. */
2808 symbol_clear_used (symbolS
*s
)
2810 if (s
->flags
.local_symbol
)
2811 s
= local_symbol_convert (s
);
2815 /* Return whether a symbol has been used. */
2818 symbol_used_p (symbolS
*s
)
2820 if (s
->flags
.local_symbol
)
2822 return s
->flags
.used
;
2825 /* Mark a symbol as having been used in a reloc. */
2828 symbol_mark_used_in_reloc (symbolS
*s
)
2830 if (s
->flags
.local_symbol
)
2831 s
= local_symbol_convert (s
);
2832 s
->flags
.used_in_reloc
= 1;
2835 /* Clear the mark of whether a symbol has been used in a reloc. */
2838 symbol_clear_used_in_reloc (symbolS
*s
)
2840 if (s
->flags
.local_symbol
)
2842 s
->flags
.used_in_reloc
= 0;
2845 /* Return whether a symbol has been used in a reloc. */
2848 symbol_used_in_reloc_p (symbolS
*s
)
2850 if (s
->flags
.local_symbol
)
2852 return s
->flags
.used_in_reloc
;
2855 /* Mark a symbol as an MRI common symbol. */
2858 symbol_mark_mri_common (symbolS
*s
)
2860 if (s
->flags
.local_symbol
)
2861 s
= local_symbol_convert (s
);
2862 s
->flags
.mri_common
= 1;
2865 /* Clear the mark of whether a symbol is an MRI common symbol. */
2868 symbol_clear_mri_common (symbolS
*s
)
2870 if (s
->flags
.local_symbol
)
2872 s
->flags
.mri_common
= 0;
2875 /* Return whether a symbol is an MRI common symbol. */
2878 symbol_mri_common_p (symbolS
*s
)
2880 if (s
->flags
.local_symbol
)
2882 return s
->flags
.mri_common
;
2885 /* Mark a symbol as having been written. */
2888 symbol_mark_written (symbolS
*s
)
2890 if (s
->flags
.local_symbol
)
2892 s
->flags
.written
= 1;
2895 /* Clear the mark of whether a symbol has been written. */
2898 symbol_clear_written (symbolS
*s
)
2900 if (s
->flags
.local_symbol
)
2902 s
->flags
.written
= 0;
2905 /* Return whether a symbol has been written. */
2908 symbol_written_p (symbolS
*s
)
2910 if (s
->flags
.local_symbol
)
2912 return s
->flags
.written
;
2915 /* Mark a symbol as to be removed. */
2918 symbol_mark_removed (symbolS
*s
)
2920 if (s
->flags
.local_symbol
)
2922 s
->flags
.removed
= 1;
2925 /* Return whether a symbol has been marked to be removed. */
2928 symbol_removed_p (symbolS
*s
)
2930 if (s
->flags
.local_symbol
)
2932 return s
->flags
.removed
;
2935 /* Mark a symbol has having been resolved. */
2938 symbol_mark_resolved (symbolS
*s
)
2940 s
->flags
.resolved
= 1;
2943 /* Return whether a symbol has been resolved. */
2946 symbol_resolved_p (symbolS
*s
)
2948 return s
->flags
.resolved
;
2951 /* Return whether a symbol is a section symbol. */
2954 symbol_section_p (symbolS
*s
)
2956 if (s
->flags
.local_symbol
)
2958 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2961 /* Return whether a symbol is equated to another symbol. */
2964 symbol_equated_p (symbolS
*s
)
2966 if (s
->flags
.local_symbol
)
2968 return s
->x
->value
.X_op
== O_symbol
;
2971 /* Return whether a symbol is equated to another symbol, and should be
2972 treated specially when writing out relocs. */
2975 symbol_equated_reloc_p (symbolS
*s
)
2977 if (s
->flags
.local_symbol
)
2979 /* X_op_symbol, normally not used for O_symbol, is set by
2980 resolve_symbol_value to flag expression syms that have been
2982 return (s
->x
->value
.X_op
== O_symbol
2983 #if defined (OBJ_COFF) && defined (TE_PE)
2986 && ((s
->flags
.resolved
&& s
->x
->value
.X_op_symbol
!= NULL
)
2987 || ! S_IS_DEFINED (s
)
2988 || S_IS_COMMON (s
)));
2991 /* Return whether a symbol has a constant value. */
2994 symbol_constant_p (symbolS
*s
)
2996 if (s
->flags
.local_symbol
)
2998 return s
->x
->value
.X_op
== O_constant
;
3001 /* Return whether a symbol was cloned and thus removed from the global
3005 symbol_shadow_p (symbolS
*s
)
3007 if (s
->flags
.local_symbol
)
3009 return s
->x
->next
== s
;
3012 /* If S is a struct symbol return S, otherwise return NULL. */
3015 symbol_symbolS (symbolS
*s
)
3017 if (s
->flags
.local_symbol
)
3022 /* Return the BFD symbol for a symbol. */
3025 symbol_get_bfdsym (symbolS
*s
)
3027 if (s
->flags
.local_symbol
)
3028 s
= local_symbol_convert (s
);
3032 /* Set the BFD symbol for a symbol. */
3035 symbol_set_bfdsym (symbolS
*s
, asymbol
*bsym
)
3037 if (s
->flags
.local_symbol
)
3038 s
= local_symbol_convert (s
);
3039 /* Usually, it is harmless to reset a symbol to a BFD section
3040 symbol. For example, obj_elf_change_section sets the BFD symbol
3041 of an old symbol with the newly created section symbol. But when
3042 we have multiple sections with the same name, the newly created
3043 section may have the same name as an old section. We check if the
3044 old symbol has been already marked as a section symbol before
3046 if ((s
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
3048 /* else XXX - What do we do now ? */
3051 #ifdef OBJ_SYMFIELD_TYPE
3053 /* Get a pointer to the object format information for a symbol. */
3056 symbol_get_obj (symbolS
*s
)
3058 if (s
->flags
.local_symbol
)
3059 s
= local_symbol_convert (s
);
3063 /* Set the object format information for a symbol. */
3066 symbol_set_obj (symbolS
*s
, OBJ_SYMFIELD_TYPE
*o
)
3068 if (s
->flags
.local_symbol
)
3069 s
= local_symbol_convert (s
);
3073 #endif /* OBJ_SYMFIELD_TYPE */
3075 #ifdef TC_SYMFIELD_TYPE
3077 /* Get a pointer to the processor information for a symbol. */
3080 symbol_get_tc (symbolS
*s
)
3082 if (s
->flags
.local_symbol
)
3083 s
= local_symbol_convert (s
);
3087 /* Set the processor information for a symbol. */
3090 symbol_set_tc (symbolS
*s
, TC_SYMFIELD_TYPE
*o
)
3092 if (s
->flags
.local_symbol
)
3093 s
= local_symbol_convert (s
);
3097 #endif /* TC_SYMFIELD_TYPE */
3102 symbol_lastP
= NULL
;
3103 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
3104 sy_hash
= htab_create_alloc (16, hash_symbol_entry
, eq_symbol_entry
,
3105 NULL
, xcalloc
, free
);
3107 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
3108 abs_symbol
.bsym
= bfd_abs_section_ptr
->symbol
;
3110 abs_symbol
.x
= &abs_symbol_x
;
3111 abs_symbol
.x
->value
.X_op
= O_constant
;
3112 abs_symbol
.frag
= &zero_address_frag
;
3114 if (LOCAL_LABELS_FB
)
3121 htab_delete (sy_hash
);
3125 dot_symbol_init (void)
3127 dot_symbol
.name
= ".";
3128 dot_symbol
.flags
.forward_ref
= 1;
3129 dot_symbol
.bsym
= bfd_make_empty_symbol (stdoutput
);
3130 if (dot_symbol
.bsym
== NULL
)
3131 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
3132 dot_symbol
.bsym
->name
= ".";
3133 dot_symbol
.x
= &dot_symbol_x
;
3134 dot_symbol
.x
->value
.X_op
= O_constant
;
3139 /* Maximum indent level.
3140 Available for modification inside a gdb session. */
3141 static int max_indent_level
= 8;
3144 print_symbol_value_1 (FILE *file
, symbolS
*sym
)
3146 const char *name
= S_GET_NAME (sym
);
3147 if (!name
|| !name
[0])
3149 fprintf (file
, "sym %p %s", sym
, name
);
3151 if (sym
->flags
.local_symbol
)
3153 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
3155 if (locsym
->frag
!= &zero_address_frag
3156 && locsym
->frag
!= NULL
)
3157 fprintf (file
, " frag %p", locsym
->frag
);
3158 if (locsym
->flags
.resolved
)
3159 fprintf (file
, " resolved");
3160 fprintf (file
, " local");
3164 if (sym
->frag
!= &zero_address_frag
)
3165 fprintf (file
, " frag %p", sym
->frag
);
3166 if (sym
->flags
.written
)
3167 fprintf (file
, " written");
3168 if (sym
->flags
.resolved
)
3169 fprintf (file
, " resolved");
3170 else if (sym
->flags
.resolving
)
3171 fprintf (file
, " resolving");
3172 if (sym
->flags
.used_in_reloc
)
3173 fprintf (file
, " used-in-reloc");
3174 if (sym
->flags
.used
)
3175 fprintf (file
, " used");
3176 if (S_IS_LOCAL (sym
))
3177 fprintf (file
, " local");
3178 if (S_IS_EXTERNAL (sym
))
3179 fprintf (file
, " extern");
3180 if (S_IS_WEAK (sym
))
3181 fprintf (file
, " weak");
3182 if (S_IS_DEBUG (sym
))
3183 fprintf (file
, " debug");
3184 if (S_IS_DEFINED (sym
))
3185 fprintf (file
, " defined");
3187 if (S_IS_WEAKREFR (sym
))
3188 fprintf (file
, " weakrefr");
3189 if (S_IS_WEAKREFD (sym
))
3190 fprintf (file
, " weakrefd");
3191 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
3192 if (symbol_resolved_p (sym
))
3194 segT s
= S_GET_SEGMENT (sym
);
3196 if (s
!= undefined_section
3197 && s
!= expr_section
)
3198 fprintf (file
, " %lx", (unsigned long) S_GET_VALUE (sym
));
3200 else if (indent_level
< max_indent_level
3201 && S_GET_SEGMENT (sym
) != undefined_section
)
3204 fprintf (file
, "\n%*s<", indent_level
* 4, "");
3205 if (sym
->flags
.local_symbol
)
3206 fprintf (file
, "constant %lx",
3207 (unsigned long) ((struct local_symbol
*) sym
)->value
);
3209 print_expr_1 (file
, &sym
->x
->value
);
3210 fprintf (file
, ">");
3217 print_symbol_value (symbolS
*sym
)
3220 print_symbol_value_1 (stderr
, sym
);
3221 fprintf (stderr
, "\n");
3225 print_binary (FILE *file
, const char *name
, expressionS
*exp
)
3228 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
3229 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3230 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3231 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3232 fprintf (file
, ">");
3237 print_expr_1 (FILE *file
, expressionS
*exp
)
3239 fprintf (file
, "expr %p ", exp
);
3243 fprintf (file
, "illegal");
3246 fprintf (file
, "absent");
3249 fprintf (file
, "constant %" PRIx64
, (uint64_t) exp
->X_add_number
);
3253 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
3254 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3255 fprintf (file
, ">");
3257 if (exp
->X_add_number
)
3258 fprintf (file
, "\n%*s%" PRIx64
, indent_level
* 4, "",
3259 (uint64_t) exp
->X_add_number
);
3263 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
3266 fprintf (file
, "big");
3269 fprintf (file
, "uminus -<");
3271 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3272 fprintf (file
, ">");
3273 goto maybe_print_addnum
;
3275 fprintf (file
, "bit_not");
3278 print_binary (file
, "multiply", exp
);
3281 print_binary (file
, "divide", exp
);
3284 print_binary (file
, "modulus", exp
);
3287 print_binary (file
, "lshift", exp
);
3290 print_binary (file
, "rshift", exp
);
3292 case O_bit_inclusive_or
:
3293 print_binary (file
, "bit_ior", exp
);
3295 case O_bit_exclusive_or
:
3296 print_binary (file
, "bit_xor", exp
);
3299 print_binary (file
, "bit_and", exp
);
3302 print_binary (file
, "eq", exp
);
3305 print_binary (file
, "ne", exp
);
3308 print_binary (file
, "lt", exp
);
3311 print_binary (file
, "le", exp
);
3314 print_binary (file
, "ge", exp
);
3317 print_binary (file
, "gt", exp
);
3320 print_binary (file
, "logical_and", exp
);
3323 print_binary (file
, "logical_or", exp
);
3327 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
3328 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3329 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3330 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3331 fprintf (file
, ">");
3332 goto maybe_print_addnum
;
3335 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
3336 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3337 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3338 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3339 fprintf (file
, ">");
3340 goto maybe_print_addnum
;
3342 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
3349 print_expr (expressionS
*exp
)
3351 print_expr_1 (stderr
, exp
);
3352 fprintf (stderr
, "\n");
3356 symbol_print_statistics (FILE *file
)
3358 htab_print_statistics (file
, "symbol table", sy_hash
);
3359 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
3360 local_symbol_count
, local_symbol_conversion_count
);
3363 #ifdef OBJ_COMPLEX_RELC
3365 /* Convert given symbol to a new complex-relocation symbol name. This
3366 may be a recursive function, since it might be called for non-leaf
3367 nodes (plain symbols) in the expression tree. The caller owns the
3368 returning string, so should free it eventually. Errors are
3369 indicated via as_bad and a NULL return value. The given symbol
3370 is marked with used_in_reloc. */
3373 symbol_relc_make_sym (symbolS
* sym
)
3375 char * terminal
= NULL
;
3380 gas_assert (sym
!= NULL
);
3382 /* Recurse to symbol_relc_make_expr if this symbol
3383 is defined as an expression or a plain value. */
3384 if ( S_GET_SEGMENT (sym
) == expr_section
3385 || S_GET_SEGMENT (sym
) == absolute_section
)
3386 return symbol_relc_make_expr (symbol_get_value_expression (sym
));
3388 /* This may be a "fake symbol", referring to ".".
3389 Write out a special null symbol to refer to this position. */
3390 if (! strcmp (S_GET_NAME (sym
), FAKE_LABEL_NAME
))
3391 return xstrdup (".");
3393 /* We hope this is a plain leaf symbol. Construct the encoding
3394 as {S,s}II...:CCCCCCC....
3395 where 'S'/'s' means section symbol / plain symbol
3396 III is decimal for the symbol name length
3397 CCC is the symbol name itself. */
3398 symbol_mark_used_in_reloc (sym
);
3400 sname
= S_GET_NAME (sym
);
3401 sname_len
= strlen (sname
);
3402 typetag
= symbol_section_p (sym
) ? 'S' : 's';
3404 terminal
= XNEWVEC (char, (1 /* S or s */
3405 + 8 /* sname_len in decimal */
3407 + sname_len
/* name itself */
3410 sprintf (terminal
, "%c%d:%s", typetag
, sname_len
, sname
);
3414 /* Convert given value to a new complex-relocation symbol name. This
3415 is a non-recursive function, since it is be called for leaf nodes
3416 (plain values) in the expression tree. The caller owns the
3417 returning string, so should free() it eventually. No errors. */
3420 symbol_relc_make_value (offsetT val
)
3422 char * terminal
= XNEWVEC (char, 28); /* Enough for long long. */
3425 bfd_sprintf_vma (stdoutput
, terminal
+ 1, val
);
3429 /* Convert given expression to a new complex-relocation symbol name.
3430 This is a recursive function, since it traverses the entire given
3431 expression tree. The caller owns the returning string, so should
3432 free() it eventually. Errors are indicated via as_bad() and a NULL
3436 symbol_relc_make_expr (expressionS
* exp
)
3438 const char * opstr
= NULL
; /* Operator prefix string. */
3439 int arity
= 0; /* Arity of this operator. */
3440 char * operands
[3]; /* Up to three operands. */
3441 char * concat_string
= NULL
;
3443 operands
[0] = operands
[1] = operands
[2] = NULL
;
3445 gas_assert (exp
!= NULL
);
3447 /* Match known operators -> fill in opstr, arity, operands[] and fall
3448 through to construct subexpression fragments; may instead return
3449 string directly for leaf nodes. */
3451 /* See expr.h for the meaning of all these enums. Many operators
3452 have an unnatural arity (X_add_number implicitly added). The
3453 conversion logic expands them to explicit "+" subexpressions. */
3458 as_bad ("Unknown expression operator (enum %d)", exp
->X_op
);
3463 return symbol_relc_make_value (exp
->X_add_number
);
3466 if (exp
->X_add_number
)
3470 operands
[0] = symbol_relc_make_sym (exp
->X_add_symbol
);
3471 operands
[1] = symbol_relc_make_value (exp
->X_add_number
);
3475 return symbol_relc_make_sym (exp
->X_add_symbol
);
3477 /* Helper macros for nesting nodes. */
3479 #define HANDLE_XADD_OPT1(str_) \
3480 if (exp->X_add_number) \
3483 opstr = "+:" str_; \
3484 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3485 operands[1] = symbol_relc_make_value (exp->X_add_number); \
3492 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3496 #define HANDLE_XADD_OPT2(str_) \
3497 if (exp->X_add_number) \
3500 opstr = "+:" str_; \
3501 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3502 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3503 operands[2] = symbol_relc_make_value (exp->X_add_number); \
3509 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3510 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3514 /* Nesting nodes. */
3516 case O_uminus
: HANDLE_XADD_OPT1 ("0-");
3517 case O_bit_not
: HANDLE_XADD_OPT1 ("~");
3518 case O_logical_not
: HANDLE_XADD_OPT1 ("!");
3519 case O_multiply
: HANDLE_XADD_OPT2 ("*");
3520 case O_divide
: HANDLE_XADD_OPT2 ("/");
3521 case O_modulus
: HANDLE_XADD_OPT2 ("%");
3522 case O_left_shift
: HANDLE_XADD_OPT2 ("<<");
3523 case O_right_shift
: HANDLE_XADD_OPT2 (">>");
3524 case O_bit_inclusive_or
: HANDLE_XADD_OPT2 ("|");
3525 case O_bit_exclusive_or
: HANDLE_XADD_OPT2 ("^");
3526 case O_bit_and
: HANDLE_XADD_OPT2 ("&");
3527 case O_add
: HANDLE_XADD_OPT2 ("+");
3528 case O_subtract
: HANDLE_XADD_OPT2 ("-");
3529 case O_eq
: HANDLE_XADD_OPT2 ("==");
3530 case O_ne
: HANDLE_XADD_OPT2 ("!=");
3531 case O_lt
: HANDLE_XADD_OPT2 ("<");
3532 case O_le
: HANDLE_XADD_OPT2 ("<=");
3533 case O_ge
: HANDLE_XADD_OPT2 (">=");
3534 case O_gt
: HANDLE_XADD_OPT2 (">");
3535 case O_logical_and
: HANDLE_XADD_OPT2 ("&&");
3536 case O_logical_or
: HANDLE_XADD_OPT2 ("||");
3539 /* Validate & reject early. */
3540 if (arity
>= 1 && ((operands
[0] == NULL
) || (strlen (operands
[0]) == 0)))
3542 if (arity
>= 2 && ((operands
[1] == NULL
) || (strlen (operands
[1]) == 0)))
3544 if (arity
>= 3 && ((operands
[2] == NULL
) || (strlen (operands
[2]) == 0)))
3548 concat_string
= NULL
;
3549 else if (arity
== 0)
3550 concat_string
= xstrdup (opstr
);
3551 else if (arity
== 1)
3552 concat_string
= concat (opstr
, ":", operands
[0], (char *) NULL
);
3553 else if (arity
== 2)
3554 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1],
3557 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1], ":",
3558 operands
[2], (char *) NULL
);
3560 /* Free operand strings (not opstr). */
3561 if (arity
>= 1) xfree (operands
[0]);
3562 if (arity
>= 2) xfree (operands
[1]);
3563 if (arity
>= 3) xfree (operands
[2]);
3565 return concat_string
;