1 /* symbols.c -symbol table-
2 Copyright (C) 1987-2020 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* #define DEBUG_SYMS / * to debug symbol list maintenance. */
24 #include "safe-ctype.h"
25 #include "obstack.h" /* For "symbols.h" */
31 /* Whether the symbol is a local_symbol. */
32 unsigned int local_symbol
: 1;
34 /* Weather symbol has been written. */
35 unsigned int written
: 1;
37 /* Whether symbol value has been completely resolved (used during
38 final pass over symbol table). */
39 unsigned int resolved
: 1;
41 /* Whether the symbol value is currently being resolved (used to
42 detect loops in symbol dependencies). */
43 unsigned int resolving
: 1;
45 /* Whether the symbol value is used in a reloc. This is used to
46 ensure that symbols used in relocs are written out, even if they
47 are local and would otherwise not be. */
48 unsigned int used_in_reloc
: 1;
50 /* Whether the symbol is used as an operand or in an expression.
51 NOTE: Not all the backends keep this information accurate;
52 backends which use this bit are responsible for setting it when
53 a symbol is used in backend routines. */
54 unsigned int used
: 1;
56 /* Whether the symbol can be re-defined. */
57 unsigned int volatil
: 1;
59 /* Whether the symbol is a forward reference. */
60 unsigned int forward_ref
: 1;
62 /* This is set if the symbol is defined in an MRI common section.
63 We handle such sections as single common symbols, so symbols
64 defined within them must be treated specially by the relocation
66 unsigned int mri_common
: 1;
68 /* This is set if the symbol is set with a .weakref directive. */
69 unsigned int weakrefr
: 1;
71 /* This is set when the symbol is referenced as part of a .weakref
72 directive, but only if the symbol was not in the symbol table
73 before. It is cleared as soon as any direct reference to the
75 unsigned int weakrefd
: 1;
78 /* A pointer in the symbol may point to either a complete symbol
79 (struct symbol below) or to a local symbol (struct local_symbol
80 defined here). The symbol code can detect the case by examining
81 the first field which is present in both structs.
83 We do this because we ordinarily only need a small amount of
84 information for a local symbol. The symbol table takes up a lot of
85 space, and storing less information for a local symbol can make a
86 big difference in assembler memory usage when assembling a large
91 /* Symbol flags. Only local_symbol and resolved are relevant. */
92 struct symbol_flags flags
;
94 /* The symbol section. This also serves as a flag. If this is
95 reg_section, then this symbol has been converted into a regular
96 symbol, and sym points to it. */
99 /* The symbol name. */
102 /* The symbol frag or the real symbol, depending upon the value in
110 /* The value of the symbol. */
114 /* The information we keep for a symbol. Note that the symbol table
115 holds pointers both to this and to local_symbol structures. */
120 struct symbol_flags flags
;
125 /* The value of the symbol. */
128 /* Forwards and backwards chain pointers. */
130 struct symbol
*previous
;
132 /* Pointer to the frag this symbol is attached to, if any.
136 #ifdef OBJ_SYMFIELD_TYPE
137 OBJ_SYMFIELD_TYPE obj
;
140 #ifdef TC_SYMFIELD_TYPE
147 const char *symbol_name
;
152 typedef struct symbol_entry symbol_entry_t
;
154 /* Hash function for a symbol_entry. */
157 hash_symbol_entry (const void *e
)
159 symbol_entry_t
*entry
= (symbol_entry_t
*) e
;
160 if (entry
->hash
== 0)
161 entry
->hash
= htab_hash_string (entry
->symbol_name
);
166 /* Equality function for a symbol_entry. */
169 eq_symbol_entry (const void *a
, const void *b
)
171 const symbol_entry_t
*ea
= (const symbol_entry_t
*) a
;
172 const symbol_entry_t
*eb
= (const symbol_entry_t
*) b
;
174 return strcmp (ea
->symbol_name
, eb
->symbol_name
) == 0;
177 static symbol_entry_t
*
178 symbol_entry_alloc (const char *symbol_name
, void *symbol
)
180 symbol_entry_t
*entry
= XNEW (symbol_entry_t
);
181 entry
->symbol_name
= symbol_name
;
183 entry
->symbol
= symbol
;
188 symbol_entry_find (htab_t table
, const char *symbol_name
)
190 symbol_entry_t needle
= { symbol_name
, 0, NULL
};
191 symbol_entry_t
*entry
= htab_find (table
, &needle
);
192 return entry
!= NULL
? entry
->symbol
: NULL
;
196 #define local_symbol_converted_p(l) ((l)->section == reg_section)
197 #define local_symbol_mark_converted(l) ((l)->section = reg_section)
198 #define local_symbol_get_real_symbol(l) ((l)->u.sym)
199 #define local_symbol_set_real_symbol(l, s) ((l)->u.sym = (s))
201 /* This is non-zero if symbols are case sensitive, which is the
203 int symbols_case_sensitive
= 1;
205 #ifndef WORKING_DOT_WORD
206 extern int new_broken_words
;
209 /* symbol-name => struct symbol pointer */
210 static htab_t sy_hash
;
212 /* Table of local symbols. */
213 static htab_t local_hash
;
215 /* Below are commented in "symbols.h". */
216 symbolS
*symbol_rootP
;
217 symbolS
*symbol_lastP
;
222 #define debug_verify_symchain verify_symbol_chain
224 #define debug_verify_symchain(root, last) ((void) 0)
227 #define DOLLAR_LABEL_CHAR '\001'
228 #define LOCAL_LABEL_CHAR '\002'
230 #ifndef TC_LABEL_IS_LOCAL
231 #define TC_LABEL_IS_LOCAL(name) 0
234 struct obstack notes
;
236 /* The name of an external symbol which is
237 used to make weak PE symbol names unique. */
238 const char * an_external_name
;
241 static const char *save_symbol_name (const char *);
242 static void fb_label_init (void);
243 static long dollar_label_instance (long);
244 static long fb_label_instance (long);
246 static void print_binary (FILE *, const char *, expressionS
*);
248 /* Return a pointer to a new symbol. Die if we can't make a new
249 symbol. Fill in the symbol's values. Add symbol to end of symbol
252 This function should be called in the general case of creating a
253 symbol. However, if the output file symbol table has already been
254 set, and you are certain that this symbol won't be wanted in the
255 output file, you can call symbol_create. */
258 symbol_new (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
260 symbolS
*symbolP
= symbol_create (name
, segment
, frag
, valu
);
262 /* Link to end of symbol chain. */
263 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
268 /* Save a symbol name on a permanent obstack, and convert it according
269 to the object file format. */
272 save_symbol_name (const char *name
)
277 gas_assert (name
!= NULL
);
278 name_length
= strlen (name
) + 1; /* +1 for \0. */
279 obstack_grow (¬es
, name
, name_length
);
280 ret
= (char *) obstack_finish (¬es
);
282 #ifdef tc_canonicalize_symbol_name
283 ret
= tc_canonicalize_symbol_name (ret
);
286 if (! symbols_case_sensitive
)
290 for (s
= ret
; *s
!= '\0'; s
++)
297 /* Create a symbol. NAME is copied, the caller can destroy/modify. */
300 symbol_create (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
302 const char *preserved_copy_of_name
;
305 preserved_copy_of_name
= save_symbol_name (name
);
307 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
309 /* symbol must be born in some fixed state. This seems as good as any. */
310 memset (symbolP
, 0, sizeof (symbolS
));
312 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
313 if (symbolP
->bsym
== NULL
)
314 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
315 S_SET_NAME (symbolP
, preserved_copy_of_name
);
317 S_SET_SEGMENT (symbolP
, segment
);
318 S_SET_VALUE (symbolP
, valu
);
319 symbol_clear_list_pointers (symbolP
);
321 symbolP
->frag
= frag
;
323 obj_symbol_new_hook (symbolP
);
325 #ifdef tc_symbol_new_hook
326 tc_symbol_new_hook (symbolP
);
333 /* Local symbol support. If we can get away with it, we keep only a
334 small amount of information for local symbols. */
336 static symbolS
*local_symbol_convert (struct local_symbol
*);
338 /* Used for statistics. */
340 static unsigned long local_symbol_count
;
341 static unsigned long local_symbol_conversion_count
;
343 /* This macro is called with a symbol argument passed by reference.
344 It returns whether this is a local symbol. If necessary, it
345 changes its argument to the real symbol. */
347 #define LOCAL_SYMBOL_CHECK(s) \
348 (s->flags.local_symbol \
349 ? (local_symbol_converted_p ((struct local_symbol *) s) \
350 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
355 /* Create a local symbol and insert it into the local hash table. */
357 struct local_symbol
*
358 local_symbol_make (const char *name
, segT section
, fragS
*frag
, valueT val
)
360 const char *name_copy
;
361 struct local_symbol
*ret
;
362 struct symbol_flags flags
= { .local_symbol
= 1, .resolved
= 0 };
364 ++local_symbol_count
;
366 name_copy
= save_symbol_name (name
);
368 ret
= (struct local_symbol
*) obstack_alloc (¬es
, sizeof *ret
);
370 ret
->name
= name_copy
;
371 ret
->section
= section
;
375 htab_insert (local_hash
, symbol_entry_alloc (name_copy
, ret
));
380 /* Convert a local symbol into a real symbol. Note that we do not
381 reclaim the space used by the local symbol. */
384 local_symbol_convert (struct local_symbol
*locsym
)
388 gas_assert (locsym
->flags
.local_symbol
);
389 if (local_symbol_converted_p (locsym
))
390 return local_symbol_get_real_symbol (locsym
);
392 ++local_symbol_conversion_count
;
394 ret
= symbol_new (locsym
->name
, locsym
->section
,
395 locsym
->u
.frag
, locsym
->value
);
397 if (locsym
->flags
.resolved
)
398 ret
->flags
.resolved
= 1;
400 /* Local symbols are always either defined or used. */
403 #ifdef TC_LOCAL_SYMFIELD_CONVERT
404 TC_LOCAL_SYMFIELD_CONVERT (locsym
, ret
);
407 symbol_table_insert (ret
);
409 local_symbol_mark_converted (locsym
);
410 local_symbol_set_real_symbol (locsym
, ret
);
412 htab_insert (local_hash
, symbol_entry_alloc (locsym
->name
, NULL
));
418 define_sym_at_dot (symbolS
*symbolP
)
420 symbolP
->frag
= frag_now
;
421 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
422 S_SET_SEGMENT (symbolP
, now_seg
);
425 /* We have just seen "<name>:".
426 Creates a struct symbol unless it already exists.
428 Gripes if we are redefining a symbol incompatibly (and ignores it). */
431 colon (/* Just seen "x:" - rattle symbols & frags. */
432 const char *sym_name
/* Symbol name, as a canonical string. */
433 /* We copy this string: OK to alter later. */)
435 symbolS
*symbolP
; /* Symbol we are working with. */
437 /* Sun local labels go out of scope whenever a non-local symbol is
439 if (LOCAL_LABELS_DOLLAR
440 && !bfd_is_local_label_name (stdoutput
, sym_name
))
441 dollar_label_clear ();
443 #ifndef WORKING_DOT_WORD
444 if (new_broken_words
)
446 struct broken_word
*a
;
451 if (now_seg
== absolute_section
)
453 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
457 possible_bytes
= (md_short_jump_size
458 + new_broken_words
* md_long_jump_size
);
461 frag_opcode
= frag_var (rs_broken_word
,
465 (symbolS
*) broken_words
,
469 /* We want to store the pointer to where to insert the jump
470 table in the fr_opcode of the rs_broken_word frag. This
471 requires a little hackery. */
473 && (frag_tmp
->fr_type
!= rs_broken_word
474 || frag_tmp
->fr_opcode
))
475 frag_tmp
= frag_tmp
->fr_next
;
477 frag_tmp
->fr_opcode
= frag_opcode
;
478 new_broken_words
= 0;
480 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
481 a
->dispfrag
= frag_tmp
;
483 #endif /* WORKING_DOT_WORD */
485 #ifdef obj_frob_colon
486 obj_frob_colon (sym_name
);
489 if ((symbolP
= symbol_find (sym_name
)) != 0)
491 S_CLEAR_WEAKREFR (symbolP
);
492 #ifdef RESOLVE_SYMBOL_REDEFINITION
493 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
496 /* Now check for undefined symbols. */
497 if (LOCAL_SYMBOL_CHECK (symbolP
))
499 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
501 if (locsym
->section
!= undefined_section
502 && (locsym
->u
.frag
!= frag_now
503 || locsym
->section
!= now_seg
504 || locsym
->value
!= frag_now_fix ()))
506 as_bad (_("symbol `%s' is already defined"), sym_name
);
510 locsym
->section
= now_seg
;
511 locsym
->u
.frag
= frag_now
;
512 locsym
->value
= frag_now_fix ();
514 else if (!(S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
515 || S_IS_COMMON (symbolP
)
516 || S_IS_VOLATILE (symbolP
))
518 if (S_IS_VOLATILE (symbolP
))
520 symbolP
= symbol_clone (symbolP
, 1);
521 S_SET_VALUE (symbolP
, 0);
522 S_CLEAR_VOLATILE (symbolP
);
524 if (S_GET_VALUE (symbolP
) == 0)
526 define_sym_at_dot (symbolP
);
529 #endif /* if we have one, it better be zero. */
534 /* There are still several cases to check:
536 A .comm/.lcomm symbol being redefined as initialized
539 A .comm/.lcomm symbol being redefined with a larger
542 This only used to be allowed on VMS gas, but Sun cc
543 on the sparc also depends on it. */
545 if (((!S_IS_DEBUG (symbolP
)
546 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
547 && S_IS_EXTERNAL (symbolP
))
548 || S_GET_SEGMENT (symbolP
) == bss_section
)
549 && (now_seg
== data_section
550 || now_seg
== bss_section
551 || now_seg
== S_GET_SEGMENT (symbolP
)))
553 /* Select which of the 2 cases this is. */
554 if (now_seg
!= data_section
)
556 /* New .comm for prev .comm symbol.
558 If the new size is larger we just change its
559 value. If the new size is smaller, we ignore
561 if (S_GET_VALUE (symbolP
)
562 < ((unsigned) frag_now_fix ()))
564 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
569 /* It is a .comm/.lcomm being converted to initialized
571 define_sym_at_dot (symbolP
);
576 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT))
577 static const char *od_buf
= "";
581 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
582 sprintf (od_buf
, "%d.%d.",
583 S_GET_OTHER (symbolP
),
584 S_GET_DESC (symbolP
));
586 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
588 segment_name (S_GET_SEGMENT (symbolP
)),
590 (long) S_GET_VALUE (symbolP
));
592 } /* if the undefined symbol has no value */
596 /* Don't blow up if the definition is the same. */
597 if (!(frag_now
== symbolP
->frag
598 && S_GET_VALUE (symbolP
) == frag_now_fix ()
599 && S_GET_SEGMENT (symbolP
) == now_seg
))
601 as_bad (_("symbol `%s' is already defined"), sym_name
);
602 symbolP
= symbol_clone (symbolP
, 0);
603 define_sym_at_dot (symbolP
);
608 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
610 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
, frag_now
,
615 symbolP
= symbol_new (sym_name
, now_seg
, frag_now
, frag_now_fix ());
617 symbol_table_insert (symbolP
);
620 if (mri_common_symbol
!= NULL
)
622 /* This symbol is actually being defined within an MRI common
623 section. This requires special handling. */
624 if (LOCAL_SYMBOL_CHECK (symbolP
))
625 symbolP
= local_symbol_convert ((struct local_symbol
*) symbolP
);
626 symbolP
->value
.X_op
= O_symbol
;
627 symbolP
->value
.X_add_symbol
= mri_common_symbol
;
628 symbolP
->value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
629 symbolP
->frag
= &zero_address_frag
;
630 S_SET_SEGMENT (symbolP
, expr_section
);
631 symbolP
->flags
.mri_common
= 1;
635 tc_frob_label (symbolP
);
637 #ifdef obj_frob_label
638 obj_frob_label (symbolP
);
644 /* Die if we can't insert the symbol. */
647 symbol_table_insert (symbolS
*symbolP
)
650 know (S_GET_NAME (symbolP
));
652 if (LOCAL_SYMBOL_CHECK (symbolP
))
653 htab_insert (local_hash
,
654 symbol_entry_alloc (S_GET_NAME (symbolP
),
655 (struct local_symbol
*)symbolP
));
657 htab_insert (sy_hash
, symbol_entry_alloc (S_GET_NAME (symbolP
),
658 (struct local_symbol
*)symbolP
));
661 /* If a symbol name does not exist, create it as undefined, and insert
662 it into the symbol table. Return a pointer to it. */
665 symbol_find_or_make (const char *name
)
669 symbolP
= symbol_find (name
);
673 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
675 symbolP
= md_undefined_symbol ((char *) name
);
679 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
680 &zero_address_frag
, 0);
684 symbolP
= symbol_make (name
);
686 symbol_table_insert (symbolP
);
687 } /* if symbol wasn't found */
693 symbol_make (const char *name
)
697 /* Let the machine description default it, e.g. for register names. */
698 symbolP
= md_undefined_symbol ((char *) name
);
701 symbolP
= symbol_new (name
, undefined_section
, &zero_address_frag
, 0);
707 symbol_clone (symbolS
*orgsymP
, int replace
)
710 asymbol
*bsymorg
, *bsymnew
;
712 /* Make sure we never clone the dot special symbol. */
713 gas_assert (orgsymP
!= &dot_symbol
);
715 /* Running local_symbol_convert on a clone that's not the one currently
716 in local_hash would incorrectly replace the hash entry. Thus the
717 symbol must be converted here. Note that the rest of the function
718 depends on not encountering an unconverted symbol. */
719 if (LOCAL_SYMBOL_CHECK (orgsymP
))
720 orgsymP
= local_symbol_convert ((struct local_symbol
*) orgsymP
);
721 bsymorg
= orgsymP
->bsym
;
723 newsymP
= (symbolS
*) obstack_alloc (¬es
, sizeof (*newsymP
));
725 bsymnew
= bfd_make_empty_symbol (bfd_asymbol_bfd (bsymorg
));
727 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
728 newsymP
->bsym
= bsymnew
;
729 bsymnew
->name
= bsymorg
->name
;
730 bsymnew
->flags
= bsymorg
->flags
& ~BSF_SECTION_SYM
;
731 bsymnew
->section
= bsymorg
->section
;
732 bfd_copy_private_symbol_data (bfd_asymbol_bfd (bsymorg
), bsymorg
,
733 bfd_asymbol_bfd (bsymnew
), bsymnew
);
735 #ifdef obj_symbol_clone_hook
736 obj_symbol_clone_hook (newsymP
, orgsymP
);
739 #ifdef tc_symbol_clone_hook
740 tc_symbol_clone_hook (newsymP
, orgsymP
);
745 if (symbol_rootP
== orgsymP
)
746 symbol_rootP
= newsymP
;
747 else if (orgsymP
->previous
)
749 orgsymP
->previous
->next
= newsymP
;
750 orgsymP
->previous
= NULL
;
752 if (symbol_lastP
== orgsymP
)
753 symbol_lastP
= newsymP
;
754 else if (orgsymP
->next
)
755 orgsymP
->next
->previous
= newsymP
;
757 /* Symbols that won't be output can't be external. */
758 S_CLEAR_EXTERNAL (orgsymP
);
759 orgsymP
->previous
= orgsymP
->next
= orgsymP
;
760 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
762 symbol_table_insert (newsymP
);
766 /* Symbols that won't be output can't be external. */
767 S_CLEAR_EXTERNAL (newsymP
);
768 newsymP
->previous
= newsymP
->next
= newsymP
;
774 /* If S is a local symbol that has been converted, return the
775 converted symbol. Otherwise return S. */
777 static inline symbolS
*
778 get_real_sym (symbolS
*s
)
781 && s
->flags
.local_symbol
782 && local_symbol_converted_p ((struct local_symbol
*) s
))
783 s
= local_symbol_get_real_symbol ((struct local_symbol
*) s
);
787 /* Referenced symbols, if they are forward references, need to be cloned
788 (without replacing the original) so that the value of the referenced
789 symbols at the point of use is saved by the clone. */
791 #undef symbol_clone_if_forward_ref
793 symbol_clone_if_forward_ref (symbolS
*symbolP
, int is_forward
)
795 if (symbolP
&& !LOCAL_SYMBOL_CHECK (symbolP
))
797 symbolS
*orig_add_symbol
= get_real_sym (symbolP
->value
.X_add_symbol
);
798 symbolS
*orig_op_symbol
= get_real_sym (symbolP
->value
.X_op_symbol
);
799 symbolS
*add_symbol
= orig_add_symbol
;
800 symbolS
*op_symbol
= orig_op_symbol
;
802 if (symbolP
->flags
.forward_ref
)
807 /* assign_symbol() clones volatile symbols; pre-existing expressions
808 hold references to the original instance, but want the current
809 value. Just repeat the lookup. */
810 if (add_symbol
&& S_IS_VOLATILE (add_symbol
))
811 add_symbol
= symbol_find_exact (S_GET_NAME (add_symbol
));
812 if (op_symbol
&& S_IS_VOLATILE (op_symbol
))
813 op_symbol
= symbol_find_exact (S_GET_NAME (op_symbol
));
816 /* Re-using resolving here, as this routine cannot get called from
817 symbol resolution code. */
818 if ((symbolP
->bsym
->section
== expr_section
819 || symbolP
->flags
.forward_ref
)
820 && !symbolP
->flags
.resolving
)
822 symbolP
->flags
.resolving
= 1;
823 add_symbol
= symbol_clone_if_forward_ref (add_symbol
, is_forward
);
824 op_symbol
= symbol_clone_if_forward_ref (op_symbol
, is_forward
);
825 symbolP
->flags
.resolving
= 0;
828 if (symbolP
->flags
.forward_ref
829 || add_symbol
!= orig_add_symbol
830 || op_symbol
!= orig_op_symbol
)
832 if (symbolP
!= &dot_symbol
)
834 symbolP
= symbol_clone (symbolP
, 0);
835 symbolP
->flags
.resolving
= 0;
839 symbolP
= symbol_temp_new_now ();
840 #ifdef tc_new_dot_label
841 tc_new_dot_label (symbolP
);
846 symbolP
->value
.X_add_symbol
= add_symbol
;
847 symbolP
->value
.X_op_symbol
= op_symbol
;
854 symbol_temp_new (segT seg
, fragS
*frag
, valueT ofs
)
856 return symbol_new (FAKE_LABEL_NAME
, seg
, frag
, ofs
);
860 symbol_temp_new_now (void)
862 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix ());
866 symbol_temp_new_now_octets (void)
868 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix_octets ());
872 symbol_temp_make (void)
874 return symbol_make (FAKE_LABEL_NAME
);
877 /* Implement symbol table lookup.
878 In: A symbol's name as a string: '\0' can't be part of a symbol name.
879 Out: NULL if the name was not in the symbol table, else the address
880 of a struct symbol associated with that name. */
883 symbol_find_exact (const char *name
)
885 return symbol_find_exact_noref (name
, 0);
889 symbol_find_exact_noref (const char *name
, int noref
)
891 symbolS
*sym
= symbol_entry_find (local_hash
, name
);
895 sym
= symbol_entry_find (sy_hash
, name
);
897 /* Any references to the symbol, except for the reference in
898 .weakref, must clear this flag, such that the symbol does not
899 turn into a weak symbol. Note that we don't have to handle the
900 local_symbol case, since a weakrefd is always promoted out of the
901 local_symbol table when it is turned into a weak symbol. */
903 S_CLEAR_WEAKREFD (sym
);
909 symbol_find (const char *name
)
911 return symbol_find_noref (name
, 0);
915 symbol_find_noref (const char *name
, int noref
)
920 #ifdef tc_canonicalize_symbol_name
922 copy
= xstrdup (name
);
923 name
= tc_canonicalize_symbol_name (copy
);
927 if (! symbols_case_sensitive
)
936 name
= copy
= XNEWVEC (char, strlen (name
) + 1);
938 while ((c
= *orig
++) != '\0')
939 *copy
++ = TOUPPER (c
);
943 copy
= (char *) name
;
946 result
= symbol_find_exact_noref (name
, noref
);
951 /* Once upon a time, symbols were kept in a singly linked list. At
952 least coff needs to be able to rearrange them from time to time, for
953 which a doubly linked list is much more convenient. Loic did these
954 as macros which seemed dangerous to me so they're now functions.
957 /* Link symbol ADDME after symbol TARGET in the chain. */
960 symbol_append (symbolS
*addme
, symbolS
*target
,
961 symbolS
**rootPP
, symbolS
**lastPP
)
963 extern int symbol_table_frozen
;
964 if (symbol_table_frozen
)
966 if (LOCAL_SYMBOL_CHECK (addme
))
968 if (target
!= NULL
&& LOCAL_SYMBOL_CHECK (target
))
973 know (*rootPP
== NULL
);
974 know (*lastPP
== NULL
);
976 addme
->previous
= NULL
;
980 } /* if the list is empty */
982 if (target
->next
!= NULL
)
984 target
->next
->previous
= addme
;
988 know (*lastPP
== target
);
990 } /* if we have a next */
992 addme
->next
= target
->next
;
993 target
->next
= addme
;
994 addme
->previous
= target
;
996 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
999 /* Set the chain pointers of SYMBOL to null. */
1002 symbol_clear_list_pointers (symbolS
*symbolP
)
1004 if (LOCAL_SYMBOL_CHECK (symbolP
))
1006 symbolP
->next
= NULL
;
1007 symbolP
->previous
= NULL
;
1010 /* Remove SYMBOLP from the list. */
1013 symbol_remove (symbolS
*symbolP
, symbolS
**rootPP
, symbolS
**lastPP
)
1015 if (LOCAL_SYMBOL_CHECK (symbolP
))
1018 if (symbolP
== *rootPP
)
1020 *rootPP
= symbolP
->next
;
1021 } /* if it was the root */
1023 if (symbolP
== *lastPP
)
1025 *lastPP
= symbolP
->previous
;
1026 } /* if it was the tail */
1028 if (symbolP
->next
!= NULL
)
1030 symbolP
->next
->previous
= symbolP
->previous
;
1033 if (symbolP
->previous
!= NULL
)
1035 symbolP
->previous
->next
= symbolP
->next
;
1036 } /* if not first */
1038 debug_verify_symchain (*rootPP
, *lastPP
);
1041 /* Link symbol ADDME before symbol TARGET in the chain. */
1044 symbol_insert (symbolS
*addme
, symbolS
*target
,
1045 symbolS
**rootPP
, symbolS
**lastPP ATTRIBUTE_UNUSED
)
1047 extern int symbol_table_frozen
;
1048 if (symbol_table_frozen
)
1050 if (LOCAL_SYMBOL_CHECK (addme
))
1052 if (LOCAL_SYMBOL_CHECK (target
))
1055 if (target
->previous
!= NULL
)
1057 target
->previous
->next
= addme
;
1061 know (*rootPP
== target
);
1063 } /* if not first */
1065 addme
->previous
= target
->previous
;
1066 target
->previous
= addme
;
1067 addme
->next
= target
;
1069 debug_verify_symchain (*rootPP
, *lastPP
);
1073 verify_symbol_chain (symbolS
*rootP
, symbolS
*lastP
)
1075 symbolS
*symbolP
= rootP
;
1077 if (symbolP
== NULL
)
1080 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
1082 gas_assert (symbolP
->bsym
!= NULL
);
1083 gas_assert (symbolP
->flags
.local_symbol
== 0);
1084 gas_assert (symbolP
->next
->previous
== symbolP
);
1087 gas_assert (lastP
== symbolP
);
1091 symbol_on_chain (symbolS
*s
, symbolS
*rootPP
, symbolS
*lastPP
)
1093 return (!LOCAL_SYMBOL_CHECK (s
)
1096 && s
->next
->previous
== s
)
1098 && ((s
->previous
!= s
1099 && s
->previous
!= NULL
1100 && s
->previous
->next
== s
)
1104 #ifdef OBJ_COMPLEX_RELC
1107 use_complex_relocs_for (symbolS
* symp
)
1109 switch (symp
->value
.X_op
)
1119 case O_bit_inclusive_or
:
1121 case O_bit_exclusive_or
:
1133 if ((S_IS_COMMON (symp
->value
.X_op_symbol
)
1134 || S_IS_LOCAL (symp
->value
.X_op_symbol
))
1135 && S_IS_DEFINED (symp
->value
.X_op_symbol
)
1136 && S_GET_SEGMENT (symp
->value
.X_op_symbol
) != expr_section
)
1143 if ((S_IS_COMMON (symp
->value
.X_add_symbol
)
1144 || S_IS_LOCAL (symp
->value
.X_add_symbol
))
1145 && S_IS_DEFINED (symp
->value
.X_add_symbol
)
1146 && S_GET_SEGMENT (symp
->value
.X_add_symbol
) != expr_section
)
1159 report_op_error (symbolS
*symp
, symbolS
*left
, operatorT op
, symbolS
*right
)
1163 segT seg_left
= left
? S_GET_SEGMENT (left
) : 0;
1164 segT seg_right
= S_GET_SEGMENT (right
);
1173 case O_uminus
: opname
= "-"; break;
1174 case O_bit_not
: opname
= "~"; break;
1175 case O_logical_not
: opname
= "!"; break;
1176 case O_multiply
: opname
= "*"; break;
1177 case O_divide
: opname
= "/"; break;
1178 case O_modulus
: opname
= "%"; break;
1179 case O_left_shift
: opname
= "<<"; break;
1180 case O_right_shift
: opname
= ">>"; break;
1181 case O_bit_inclusive_or
: opname
= "|"; break;
1182 case O_bit_or_not
: opname
= "|~"; break;
1183 case O_bit_exclusive_or
: opname
= "^"; break;
1184 case O_bit_and
: opname
= "&"; break;
1185 case O_add
: opname
= "+"; break;
1186 case O_subtract
: opname
= "-"; break;
1187 case O_eq
: opname
= "=="; break;
1188 case O_ne
: opname
= "!="; break;
1189 case O_lt
: opname
= "<"; break;
1190 case O_le
: opname
= "<="; break;
1191 case O_ge
: opname
= ">="; break;
1192 case O_gt
: opname
= ">"; break;
1193 case O_logical_and
: opname
= "&&"; break;
1194 case O_logical_or
: opname
= "||"; break;
1197 if (expr_symbol_where (symp
, &file
, &line
))
1200 as_bad_where (file
, line
,
1201 _("invalid operands (%s and %s sections) for `%s'"),
1202 seg_left
->name
, seg_right
->name
, opname
);
1204 as_bad_where (file
, line
,
1205 _("invalid operand (%s section) for `%s'"),
1206 seg_right
->name
, opname
);
1210 const char *sname
= S_GET_NAME (symp
);
1213 as_bad (_("invalid operands (%s and %s sections) for `%s' when setting `%s'"),
1214 seg_left
->name
, seg_right
->name
, opname
, sname
);
1216 as_bad (_("invalid operand (%s section) for `%s' when setting `%s'"),
1217 seg_right
->name
, opname
, sname
);
1221 /* Resolve the value of a symbol. This is called during the final
1222 pass over the symbol table to resolve any symbols with complex
1226 resolve_symbol_value (symbolS
*symp
)
1232 if (LOCAL_SYMBOL_CHECK (symp
))
1234 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1236 final_val
= locsym
->value
;
1237 if (locsym
->flags
.resolved
)
1240 /* Symbols whose section has SEC_ELF_OCTETS set,
1241 resolve to octets instead of target bytes. */
1242 if (locsym
->section
->flags
& SEC_OCTETS
)
1243 final_val
+= locsym
->u
.frag
->fr_address
;
1245 final_val
+= locsym
->u
.frag
->fr_address
/ OCTETS_PER_BYTE
;
1249 locsym
->value
= final_val
;
1250 locsym
->flags
.resolved
= 1;
1256 if (symp
->flags
.resolved
)
1259 while (symp
->value
.X_op
== O_symbol
)
1261 final_val
+= symp
->value
.X_add_number
;
1262 symp
= symp
->value
.X_add_symbol
;
1263 if (LOCAL_SYMBOL_CHECK (symp
))
1265 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1266 final_val
+= locsym
->value
;
1269 if (!symp
->flags
.resolved
)
1272 if (symp
->value
.X_op
== O_constant
)
1273 final_val
+= symp
->value
.X_add_number
;
1280 final_seg
= S_GET_SEGMENT (symp
);
1282 if (symp
->flags
.resolving
)
1285 as_bad (_("symbol definition loop encountered at `%s'"),
1290 #ifdef OBJ_COMPLEX_RELC
1291 else if (final_seg
== expr_section
1292 && use_complex_relocs_for (symp
))
1294 symbolS
* relc_symbol
= NULL
;
1295 char * relc_symbol_name
= NULL
;
1297 relc_symbol_name
= symbol_relc_make_expr (& symp
->value
);
1299 /* For debugging, print out conversion input & output. */
1301 print_expr (& symp
->value
);
1302 if (relc_symbol_name
)
1303 fprintf (stderr
, "-> relc symbol: %s\n", relc_symbol_name
);
1306 if (relc_symbol_name
!= NULL
)
1307 relc_symbol
= symbol_new (relc_symbol_name
, undefined_section
,
1308 &zero_address_frag
, 0);
1310 if (relc_symbol
== NULL
)
1312 as_bad (_("cannot convert expression symbol %s to complex relocation"),
1318 symbol_table_insert (relc_symbol
);
1320 /* S_CLEAR_EXTERNAL (relc_symbol); */
1321 if (symp
->bsym
->flags
& BSF_SRELC
)
1322 relc_symbol
->bsym
->flags
|= BSF_SRELC
;
1324 relc_symbol
->bsym
->flags
|= BSF_RELC
;
1325 /* symp->bsym->flags |= BSF_RELC; */
1326 copy_symbol_attributes (symp
, relc_symbol
);
1327 symp
->value
.X_op
= O_symbol
;
1328 symp
->value
.X_add_symbol
= relc_symbol
;
1329 symp
->value
.X_add_number
= 0;
1334 final_seg
= undefined_section
;
1335 goto exit_dont_set_value
;
1340 symbolS
*add_symbol
, *op_symbol
;
1341 offsetT left
, right
;
1342 segT seg_left
, seg_right
;
1346 symp
->flags
.resolving
= 1;
1348 /* Help out with CSE. */
1349 add_symbol
= symp
->value
.X_add_symbol
;
1350 op_symbol
= symp
->value
.X_op_symbol
;
1351 final_val
= symp
->value
.X_add_number
;
1352 op
= symp
->value
.X_op
;
1365 /* Symbols whose section has SEC_ELF_OCTETS set,
1366 resolve to octets instead of target bytes. */
1367 if (symp
->bsym
->section
->flags
& SEC_OCTETS
)
1368 final_val
+= symp
->frag
->fr_address
;
1370 final_val
+= symp
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1371 if (final_seg
== expr_section
)
1372 final_seg
= absolute_section
;
1381 left
= resolve_symbol_value (add_symbol
);
1382 seg_left
= S_GET_SEGMENT (add_symbol
);
1384 symp
->value
.X_op_symbol
= NULL
;
1387 if (S_IS_WEAKREFR (symp
))
1389 gas_assert (final_val
== 0);
1390 if (S_IS_WEAKREFR (add_symbol
))
1392 gas_assert (add_symbol
->value
.X_op
== O_symbol
1393 && add_symbol
->value
.X_add_number
== 0);
1394 add_symbol
= add_symbol
->value
.X_add_symbol
;
1395 gas_assert (! S_IS_WEAKREFR (add_symbol
));
1396 symp
->value
.X_add_symbol
= add_symbol
;
1400 if (symp
->flags
.mri_common
)
1402 /* This is a symbol inside an MRI common section. The
1403 relocation routines are going to handle it specially.
1404 Don't change the value. */
1405 resolved
= symbol_resolved_p (add_symbol
);
1409 /* Don't leave symbol loops. */
1411 && !LOCAL_SYMBOL_CHECK (add_symbol
)
1412 && add_symbol
->flags
.resolving
)
1415 if (finalize_syms
&& final_val
== 0)
1417 if (LOCAL_SYMBOL_CHECK (add_symbol
))
1418 add_symbol
= local_symbol_convert ((struct local_symbol
*)
1420 copy_symbol_attributes (symp
, add_symbol
);
1423 /* If we have equated this symbol to an undefined or common
1424 symbol, keep X_op set to O_symbol, and don't change
1425 X_add_number. This permits the routine which writes out
1426 relocation to detect this case, and convert the
1427 relocation to be against the symbol to which this symbol
1429 if (seg_left
== undefined_section
1430 || bfd_is_com_section (seg_left
)
1431 #if defined (OBJ_COFF) && defined (TE_PE)
1432 || S_IS_WEAK (add_symbol
)
1435 && ((final_seg
== expr_section
1436 && seg_left
!= expr_section
1437 && seg_left
!= absolute_section
)
1438 || symbol_shadow_p (symp
))))
1442 symp
->value
.X_op
= O_symbol
;
1443 symp
->value
.X_add_symbol
= add_symbol
;
1444 symp
->value
.X_add_number
= final_val
;
1445 /* Use X_op_symbol as a flag. */
1446 symp
->value
.X_op_symbol
= add_symbol
;
1448 final_seg
= seg_left
;
1449 final_val
+= symp
->frag
->fr_address
+ left
;
1450 resolved
= symbol_resolved_p (add_symbol
);
1451 symp
->flags
.resolving
= 0;
1452 goto exit_dont_set_value
;
1456 final_val
+= symp
->frag
->fr_address
+ left
;
1457 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1458 final_seg
= seg_left
;
1461 resolved
= symbol_resolved_p (add_symbol
);
1462 if (S_IS_WEAKREFR (symp
))
1464 symp
->flags
.resolving
= 0;
1465 goto exit_dont_set_value
;
1472 left
= resolve_symbol_value (add_symbol
);
1473 seg_left
= S_GET_SEGMENT (add_symbol
);
1475 /* By reducing these to the relevant dyadic operator, we get
1476 !S -> S == 0 permitted on anything,
1477 -S -> 0 - S only permitted on absolute
1478 ~S -> S ^ ~0 only permitted on absolute */
1479 if (op
!= O_logical_not
&& seg_left
!= absolute_section
1481 report_op_error (symp
, NULL
, op
, add_symbol
);
1483 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1484 final_seg
= absolute_section
;
1488 else if (op
== O_logical_not
)
1493 final_val
+= left
+ symp
->frag
->fr_address
;
1495 resolved
= symbol_resolved_p (add_symbol
);
1503 case O_bit_inclusive_or
:
1505 case O_bit_exclusive_or
:
1517 left
= resolve_symbol_value (add_symbol
);
1518 right
= resolve_symbol_value (op_symbol
);
1519 seg_left
= S_GET_SEGMENT (add_symbol
);
1520 seg_right
= S_GET_SEGMENT (op_symbol
);
1522 /* Simplify addition or subtraction of a constant by folding the
1523 constant into X_add_number. */
1526 if (seg_right
== absolute_section
)
1531 else if (seg_left
== absolute_section
)
1534 add_symbol
= op_symbol
;
1536 seg_left
= seg_right
;
1540 else if (op
== O_subtract
)
1542 if (seg_right
== absolute_section
)
1550 /* Equality and non-equality tests are permitted on anything.
1551 Subtraction, and other comparison operators are permitted if
1552 both operands are in the same section. Otherwise, both
1553 operands must be absolute. We already handled the case of
1554 addition or subtraction of a constant above. This will
1555 probably need to be changed for an object file format which
1556 supports arbitrary expressions. */
1557 if (!(seg_left
== absolute_section
1558 && seg_right
== absolute_section
)
1559 && !(op
== O_eq
|| op
== O_ne
)
1560 && !((op
== O_subtract
1561 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1562 && seg_left
== seg_right
1563 && (seg_left
!= undefined_section
1564 || add_symbol
== op_symbol
)))
1566 /* Don't emit messages unless we're finalizing the symbol value,
1567 otherwise we may get the same message multiple times. */
1569 report_op_error (symp
, add_symbol
, op
, op_symbol
);
1570 /* However do not move the symbol into the absolute section
1571 if it cannot currently be resolved - this would confuse
1572 other parts of the assembler into believing that the
1573 expression had been evaluated to zero. */
1579 && (final_seg
== expr_section
|| final_seg
== undefined_section
))
1580 final_seg
= absolute_section
;
1582 /* Check for division by zero. */
1583 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1585 /* If seg_right is not absolute_section, then we've
1586 already issued a warning about using a bad symbol. */
1587 if (seg_right
== absolute_section
&& finalize_syms
)
1592 if (expr_symbol_where (symp
, &file
, &line
))
1593 as_bad_where (file
, line
, _("division by zero"));
1595 as_bad (_("division by zero when setting `%s'"),
1602 switch (symp
->value
.X_op
)
1604 case O_multiply
: left
*= right
; break;
1605 case O_divide
: left
/= right
; break;
1606 case O_modulus
: left
%= right
; break;
1607 case O_left_shift
: left
<<= right
; break;
1608 case O_right_shift
: left
>>= right
; break;
1609 case O_bit_inclusive_or
: left
|= right
; break;
1610 case O_bit_or_not
: left
|= ~right
; break;
1611 case O_bit_exclusive_or
: left
^= right
; break;
1612 case O_bit_and
: left
&= right
; break;
1613 case O_add
: left
+= right
; break;
1614 case O_subtract
: left
-= right
; break;
1617 left
= (left
== right
&& seg_left
== seg_right
1618 && (seg_left
!= undefined_section
1619 || add_symbol
== op_symbol
)
1620 ? ~ (offsetT
) 0 : 0);
1621 if (symp
->value
.X_op
== O_ne
)
1624 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1625 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1626 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1627 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1628 case O_logical_and
: left
= left
&& right
; break;
1629 case O_logical_or
: left
= left
|| right
; break;
1634 /* See PR 20895 for a reproducer. */
1635 as_bad (_("Invalid operation on symbol"));
1636 goto exit_dont_set_value
;
1642 final_val
+= symp
->frag
->fr_address
+ left
;
1643 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1645 if (seg_left
== undefined_section
1646 || seg_right
== undefined_section
)
1647 final_seg
= undefined_section
;
1648 else if (seg_left
== absolute_section
)
1649 final_seg
= seg_right
;
1651 final_seg
= seg_left
;
1653 resolved
= (symbol_resolved_p (add_symbol
)
1654 && symbol_resolved_p (op_symbol
));
1659 /* Give an error (below) if not in expr_section. We don't
1660 want to worry about expr_section symbols, because they
1661 are fictional (they are created as part of expression
1662 resolution), and any problems may not actually mean
1667 symp
->flags
.resolving
= 0;
1671 S_SET_VALUE (symp
, final_val
);
1673 exit_dont_set_value
:
1674 /* Always set the segment, even if not finalizing the value.
1675 The segment is used to determine whether a symbol is defined. */
1676 S_SET_SEGMENT (symp
, final_seg
);
1678 /* Don't worry if we can't resolve an expr_section symbol. */
1682 symp
->flags
.resolved
= 1;
1683 else if (S_GET_SEGMENT (symp
) != expr_section
)
1685 as_bad (_("can't resolve value for symbol `%s'"),
1687 symp
->flags
.resolved
= 1;
1694 /* A static function passed to hash_traverse. */
1697 resolve_local_symbol (void **slot
, void *arg ATTRIBUTE_UNUSED
)
1699 symbol_entry_t
*entry
= *((symbol_entry_t
**) slot
);
1700 if (entry
->symbol
!= NULL
)
1701 resolve_symbol_value ((symbolS
*) entry
->symbol
);
1706 /* Resolve all local symbols. */
1709 resolve_local_symbol_values (void)
1711 htab_traverse (local_hash
, resolve_local_symbol
, NULL
);
1714 /* Obtain the current value of a symbol without changing any
1715 sub-expressions used. */
1718 snapshot_symbol (symbolS
**symbolPP
, valueT
*valueP
, segT
*segP
, fragS
**fragPP
)
1720 symbolS
*symbolP
= *symbolPP
;
1722 if (LOCAL_SYMBOL_CHECK (symbolP
))
1724 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1726 *valueP
= locsym
->value
;
1727 *segP
= locsym
->section
;
1728 *fragPP
= locsym
->u
.frag
;
1732 expressionS exp
= symbolP
->value
;
1734 if (!symbolP
->flags
.resolved
&& exp
.X_op
!= O_illegal
)
1738 if (symbolP
->flags
.resolving
)
1740 symbolP
->flags
.resolving
= 1;
1741 resolved
= resolve_expression (&exp
);
1742 symbolP
->flags
.resolving
= 0;
1750 if (!symbol_equated_p (symbolP
))
1755 symbolP
= exp
.X_add_symbol
;
1762 *symbolPP
= symbolP
;
1764 /* A bogus input file can result in resolve_expression()
1765 generating a local symbol, so we have to check again. */
1766 if (LOCAL_SYMBOL_CHECK (symbolP
))
1768 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1770 *valueP
= locsym
->value
;
1771 *segP
= locsym
->section
;
1772 *fragPP
= locsym
->u
.frag
;
1776 *valueP
= exp
.X_add_number
;
1777 *segP
= symbolP
->bsym
->section
;
1778 *fragPP
= symbolP
->frag
;
1781 if (*segP
== expr_section
)
1784 case O_constant
: *segP
= absolute_section
; break;
1785 case O_register
: *segP
= reg_section
; break;
1793 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1794 They are *really* local. That is, they go out of scope whenever we see a
1795 label that isn't local. Also, like fb labels, there can be multiple
1796 instances of a dollar label. Therefor, we name encode each instance with
1797 the instance number, keep a list of defined symbols separate from the real
1798 symbol table, and we treat these buggers as a sparse array. */
1800 static long *dollar_labels
;
1801 static long *dollar_label_instances
;
1802 static char *dollar_label_defines
;
1803 static unsigned long dollar_label_count
;
1804 static unsigned long dollar_label_max
;
1807 dollar_label_defined (long label
)
1811 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1813 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1815 return dollar_label_defines
[i
- dollar_labels
];
1817 /* If we get here, label isn't defined. */
1822 dollar_label_instance (long label
)
1826 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1828 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1830 return (dollar_label_instances
[i
- dollar_labels
]);
1832 /* If we get here, we haven't seen the label before.
1833 Therefore its instance count is zero. */
1838 dollar_label_clear (void)
1840 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
1843 #define DOLLAR_LABEL_BUMP_BY 10
1846 define_dollar_label (long label
)
1850 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1853 ++dollar_label_instances
[i
- dollar_labels
];
1854 dollar_label_defines
[i
- dollar_labels
] = 1;
1858 /* If we get to here, we don't have label listed yet. */
1860 if (dollar_labels
== NULL
)
1862 dollar_labels
= XNEWVEC (long, DOLLAR_LABEL_BUMP_BY
);
1863 dollar_label_instances
= XNEWVEC (long, DOLLAR_LABEL_BUMP_BY
);
1864 dollar_label_defines
= XNEWVEC (char, DOLLAR_LABEL_BUMP_BY
);
1865 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1866 dollar_label_count
= 0;
1868 else if (dollar_label_count
== dollar_label_max
)
1870 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1871 dollar_labels
= XRESIZEVEC (long, dollar_labels
, dollar_label_max
);
1872 dollar_label_instances
= XRESIZEVEC (long, dollar_label_instances
,
1874 dollar_label_defines
= XRESIZEVEC (char, dollar_label_defines
,
1876 } /* if we needed to grow */
1878 dollar_labels
[dollar_label_count
] = label
;
1879 dollar_label_instances
[dollar_label_count
] = 1;
1880 dollar_label_defines
[dollar_label_count
] = 1;
1881 ++dollar_label_count
;
1884 /* Caller must copy returned name: we re-use the area for the next name.
1886 The mth occurrence of label n: is turned into the symbol "Ln^Am"
1887 where n is the label number and m is the instance number. "L" makes
1888 it a label discarded unless debugging and "^A"('\1') ensures no
1889 ordinary symbol SHOULD get the same name as a local label
1890 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1892 fb labels get the same treatment, except that ^B is used in place
1895 char * /* Return local label name. */
1896 dollar_label_name (long n
, /* we just saw "n$:" : n a number. */
1897 int augend
/* 0 for current instance, 1 for new instance. */)
1900 /* Returned to caller, then copied. Used for created names ("4f"). */
1901 static char symbol_name_build
[24];
1904 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
1907 know (augend
== 0 || augend
== 1);
1908 p
= symbol_name_build
;
1909 #ifdef LOCAL_LABEL_PREFIX
1910 *p
++ = LOCAL_LABEL_PREFIX
;
1914 /* Next code just does sprintf( {}, "%d", n); */
1916 q
= symbol_name_temporary
;
1917 for (*q
++ = 0, i
= n
; i
; ++q
)
1922 while ((*p
= *--q
) != '\0')
1925 *p
++ = DOLLAR_LABEL_CHAR
; /* ^A */
1927 /* Instance number. */
1928 q
= symbol_name_temporary
;
1929 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
1934 while ((*p
++ = *--q
) != '\0');
1936 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1937 return symbol_name_build
;
1940 /* Somebody else's idea of local labels. They are made by "n:" where n
1941 is any decimal digit. Refer to them with
1942 "nb" for previous (backward) n:
1943 or "nf" for next (forward) n:.
1945 We do a little better and let n be any number, not just a single digit, but
1946 since the other guy's assembler only does ten, we treat the first ten
1949 Like someone else's assembler, we have one set of local label counters for
1950 entire assembly, not one set per (sub)segment like in most assemblers. This
1951 implies that one can refer to a label in another segment, and indeed some
1952 crufty compilers have done just that.
1954 Since there could be a LOT of these things, treat them as a sparse
1957 #define FB_LABEL_SPECIAL (10)
1959 static long fb_low_counter
[FB_LABEL_SPECIAL
];
1960 static long *fb_labels
;
1961 static long *fb_label_instances
;
1962 static long fb_label_count
;
1963 static long fb_label_max
;
1965 /* This must be more than FB_LABEL_SPECIAL. */
1966 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1969 fb_label_init (void)
1971 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
1974 /* Add one to the instance number of this fb label. */
1977 fb_label_instance_inc (long label
)
1981 if ((unsigned long) label
< FB_LABEL_SPECIAL
)
1983 ++fb_low_counter
[label
];
1987 if (fb_labels
!= NULL
)
1989 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
1990 i
< fb_labels
+ fb_label_count
; ++i
)
1994 ++fb_label_instances
[i
- fb_labels
];
1996 } /* if we find it */
1997 } /* for each existing label */
2000 /* If we get to here, we don't have label listed yet. */
2002 if (fb_labels
== NULL
)
2004 fb_labels
= XNEWVEC (long, FB_LABEL_BUMP_BY
);
2005 fb_label_instances
= XNEWVEC (long, FB_LABEL_BUMP_BY
);
2006 fb_label_max
= FB_LABEL_BUMP_BY
;
2007 fb_label_count
= FB_LABEL_SPECIAL
;
2010 else if (fb_label_count
== fb_label_max
)
2012 fb_label_max
+= FB_LABEL_BUMP_BY
;
2013 fb_labels
= XRESIZEVEC (long, fb_labels
, fb_label_max
);
2014 fb_label_instances
= XRESIZEVEC (long, fb_label_instances
, fb_label_max
);
2015 } /* if we needed to grow */
2017 fb_labels
[fb_label_count
] = label
;
2018 fb_label_instances
[fb_label_count
] = 1;
2023 fb_label_instance (long label
)
2027 if ((unsigned long) label
< FB_LABEL_SPECIAL
)
2029 return (fb_low_counter
[label
]);
2032 if (fb_labels
!= NULL
)
2034 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2035 i
< fb_labels
+ fb_label_count
; ++i
)
2039 return (fb_label_instances
[i
- fb_labels
]);
2040 } /* if we find it */
2041 } /* for each existing label */
2044 /* We didn't find the label, so this must be a reference to the
2049 /* Caller must copy returned name: we re-use the area for the next name.
2051 The mth occurrence of label n: is turned into the symbol "Ln^Bm"
2052 where n is the label number and m is the instance number. "L" makes
2053 it a label discarded unless debugging and "^B"('\2') ensures no
2054 ordinary symbol SHOULD get the same name as a local label
2055 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
2057 dollar labels get the same treatment, except that ^A is used in
2060 char * /* Return local label name. */
2061 fb_label_name (long n
, /* We just saw "n:", "nf" or "nb" : n a number. */
2062 long augend
/* 0 for nb, 1 for n:, nf. */)
2065 /* Returned to caller, then copied. Used for created names ("4f"). */
2066 static char symbol_name_build
[24];
2069 char symbol_name_temporary
[20]; /* Build up a number, BACKWARDS. */
2073 know ((unsigned long) augend
<= 2 /* See mmix_fb_label. */);
2075 know ((unsigned long) augend
<= 1);
2077 p
= symbol_name_build
;
2078 #ifdef LOCAL_LABEL_PREFIX
2079 *p
++ = LOCAL_LABEL_PREFIX
;
2083 /* Next code just does sprintf( {}, "%d", n); */
2085 q
= symbol_name_temporary
;
2086 for (*q
++ = 0, i
= n
; i
; ++q
)
2091 while ((*p
= *--q
) != '\0')
2094 *p
++ = LOCAL_LABEL_CHAR
; /* ^B */
2096 /* Instance number. */
2097 q
= symbol_name_temporary
;
2098 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
2103 while ((*p
++ = *--q
) != '\0');
2105 /* The label, as a '\0' ended string, starts at symbol_name_build. */
2106 return (symbol_name_build
);
2109 /* Decode name that may have been generated by foo_label_name() above.
2110 If the name wasn't generated by foo_label_name(), then return it
2111 unaltered. This is used for error messages. */
2114 decode_local_label_name (char *s
)
2117 char *symbol_decode
;
2119 int instance_number
;
2121 const char *message_format
;
2124 #ifdef LOCAL_LABEL_PREFIX
2125 if (s
[lindex
] == LOCAL_LABEL_PREFIX
)
2129 if (s
[lindex
] != 'L')
2132 for (label_number
= 0, p
= s
+ lindex
+ 1; ISDIGIT (*p
); ++p
)
2133 label_number
= (10 * label_number
) + *p
- '0';
2135 if (*p
== DOLLAR_LABEL_CHAR
)
2137 else if (*p
== LOCAL_LABEL_CHAR
)
2142 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
2143 instance_number
= (10 * instance_number
) + *p
- '0';
2145 message_format
= _("\"%d\" (instance number %d of a %s label)");
2146 symbol_decode
= (char *) obstack_alloc (¬es
, strlen (message_format
) + 30);
2147 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
2149 return symbol_decode
;
2152 /* Get the value of a symbol. */
2155 S_GET_VALUE (symbolS
*s
)
2157 if (LOCAL_SYMBOL_CHECK (s
))
2158 return resolve_symbol_value (s
);
2160 if (!s
->flags
.resolved
)
2162 valueT val
= resolve_symbol_value (s
);
2166 if (S_IS_WEAKREFR (s
))
2167 return S_GET_VALUE (s
->value
.X_add_symbol
);
2169 if (s
->value
.X_op
!= O_constant
)
2171 if (! s
->flags
.resolved
2172 || s
->value
.X_op
!= O_symbol
2173 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
2174 as_bad (_("attempt to get value of unresolved symbol `%s'"),
2177 return (valueT
) s
->value
.X_add_number
;
2180 /* Set the value of a symbol. */
2183 S_SET_VALUE (symbolS
*s
, valueT val
)
2185 if (LOCAL_SYMBOL_CHECK (s
))
2187 ((struct local_symbol
*) s
)->value
= val
;
2191 s
->value
.X_op
= O_constant
;
2192 s
->value
.X_add_number
= (offsetT
) val
;
2193 s
->value
.X_unsigned
= 0;
2194 S_CLEAR_WEAKREFR (s
);
2198 copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2200 if (LOCAL_SYMBOL_CHECK (dest
))
2201 dest
= local_symbol_convert ((struct local_symbol
*) dest
);
2202 if (LOCAL_SYMBOL_CHECK (src
))
2203 src
= local_symbol_convert ((struct local_symbol
*) src
);
2205 /* In an expression, transfer the settings of these flags.
2206 The user can override later, of course. */
2207 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT \
2208 | BSF_GNU_INDIRECT_FUNCTION)
2209 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
2211 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
2212 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2215 #ifdef TC_COPY_SYMBOL_ATTRIBUTES
2216 TC_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2221 S_IS_FUNCTION (symbolS
*s
)
2225 if (LOCAL_SYMBOL_CHECK (s
))
2228 flags
= s
->bsym
->flags
;
2230 return (flags
& BSF_FUNCTION
) != 0;
2234 S_IS_EXTERNAL (symbolS
*s
)
2238 if (LOCAL_SYMBOL_CHECK (s
))
2241 flags
= s
->bsym
->flags
;
2244 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2247 return (flags
& BSF_GLOBAL
) != 0;
2251 S_IS_WEAK (symbolS
*s
)
2253 if (LOCAL_SYMBOL_CHECK (s
))
2255 /* Conceptually, a weakrefr is weak if the referenced symbol is. We
2256 could probably handle a WEAKREFR as always weak though. E.g., if
2257 the referenced symbol has lost its weak status, there's no reason
2258 to keep handling the weakrefr as if it was weak. */
2259 if (S_IS_WEAKREFR (s
))
2260 return S_IS_WEAK (s
->value
.X_add_symbol
);
2261 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
2265 S_IS_WEAKREFR (symbolS
*s
)
2267 if (LOCAL_SYMBOL_CHECK (s
))
2269 return s
->flags
.weakrefr
!= 0;
2273 S_IS_WEAKREFD (symbolS
*s
)
2275 if (LOCAL_SYMBOL_CHECK (s
))
2277 return s
->flags
.weakrefd
!= 0;
2281 S_IS_COMMON (symbolS
*s
)
2283 if (LOCAL_SYMBOL_CHECK (s
))
2285 return bfd_is_com_section (s
->bsym
->section
);
2289 S_IS_DEFINED (symbolS
*s
)
2291 if (LOCAL_SYMBOL_CHECK (s
))
2292 return ((struct local_symbol
*) s
)->section
!= undefined_section
;
2293 return s
->bsym
->section
!= undefined_section
;
2297 #ifndef EXTERN_FORCE_RELOC
2298 #define EXTERN_FORCE_RELOC IS_ELF
2301 /* Return true for symbols that should not be reduced to section
2302 symbols or eliminated from expressions, because they may be
2303 overridden by the linker. */
2305 S_FORCE_RELOC (symbolS
*s
, int strict
)
2308 if (LOCAL_SYMBOL_CHECK (s
))
2309 sec
= ((struct local_symbol
*) s
)->section
;
2313 && ((s
->bsym
->flags
& BSF_WEAK
) != 0
2314 || (EXTERN_FORCE_RELOC
2315 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)))
2316 || (s
->bsym
->flags
& BSF_GNU_INDIRECT_FUNCTION
) != 0)
2318 sec
= s
->bsym
->section
;
2320 return bfd_is_und_section (sec
) || bfd_is_com_section (sec
);
2324 S_IS_DEBUG (symbolS
*s
)
2326 if (LOCAL_SYMBOL_CHECK (s
))
2328 if (s
->bsym
->flags
& BSF_DEBUGGING
)
2334 S_IS_LOCAL (symbolS
*s
)
2339 if (LOCAL_SYMBOL_CHECK (s
))
2342 flags
= s
->bsym
->flags
;
2345 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2348 if (bfd_asymbol_section (s
->bsym
) == reg_section
)
2351 if (flag_strip_local_absolute
2352 /* Keep BSF_FILE symbols in order to allow debuggers to identify
2353 the source file even when the object file is stripped. */
2354 && (flags
& (BSF_GLOBAL
| BSF_FILE
)) == 0
2355 && bfd_asymbol_section (s
->bsym
) == absolute_section
)
2358 name
= S_GET_NAME (s
);
2359 return (name
!= NULL
2361 && (strchr (name
, DOLLAR_LABEL_CHAR
)
2362 || strchr (name
, LOCAL_LABEL_CHAR
)
2363 #if FAKE_LABEL_CHAR != DOLLAR_LABEL_CHAR
2364 || strchr (name
, FAKE_LABEL_CHAR
)
2366 || TC_LABEL_IS_LOCAL (name
)
2367 || (! flag_keep_locals
2368 && (bfd_is_local_label (stdoutput
, s
->bsym
)
2371 && name
[1] == '?')))));
2375 S_IS_STABD (symbolS
*s
)
2377 return S_GET_NAME (s
) == 0;
2381 S_CAN_BE_REDEFINED (const symbolS
*s
)
2383 if (LOCAL_SYMBOL_CHECK (s
))
2384 return (((struct local_symbol
*) s
)->u
.frag
2385 == &predefined_address_frag
);
2386 /* Permit register names to be redefined. */
2387 return s
->bsym
->section
== reg_section
;
2391 S_IS_VOLATILE (const symbolS
*s
)
2393 if (LOCAL_SYMBOL_CHECK (s
))
2395 return s
->flags
.volatil
;
2399 S_IS_FORWARD_REF (const symbolS
*s
)
2401 if (LOCAL_SYMBOL_CHECK (s
))
2403 return s
->flags
.forward_ref
;
2407 S_GET_NAME (symbolS
*s
)
2409 if (LOCAL_SYMBOL_CHECK (s
))
2410 return ((struct local_symbol
*) s
)->name
;
2411 return s
->bsym
->name
;
2415 S_GET_SEGMENT (symbolS
*s
)
2417 if (LOCAL_SYMBOL_CHECK (s
))
2418 return ((struct local_symbol
*) s
)->section
;
2419 return s
->bsym
->section
;
2423 S_SET_SEGMENT (symbolS
*s
, segT seg
)
2425 /* Don't reassign section symbols. The direct reason is to prevent seg
2426 faults assigning back to const global symbols such as *ABS*, but it
2427 shouldn't happen anyway. */
2429 if (LOCAL_SYMBOL_CHECK (s
))
2431 if (seg
== reg_section
)
2432 s
= local_symbol_convert ((struct local_symbol
*) s
);
2435 ((struct local_symbol
*) s
)->section
= seg
;
2440 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2442 if (s
->bsym
->section
!= seg
)
2446 s
->bsym
->section
= seg
;
2450 S_SET_EXTERNAL (symbolS
*s
)
2452 if (LOCAL_SYMBOL_CHECK (s
))
2453 s
= local_symbol_convert ((struct local_symbol
*) s
);
2454 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2456 /* Let .weak override .global. */
2459 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2461 /* Do not reassign section symbols. */
2462 as_warn (_("section symbols are already global"));
2465 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
2466 if (S_GET_SEGMENT (s
) == reg_section
)
2468 as_bad ("can't make register symbol `%s' global",
2473 s
->bsym
->flags
|= BSF_GLOBAL
;
2474 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
2477 if (! an_external_name
&& S_GET_NAME(s
)[0] != '.')
2478 an_external_name
= S_GET_NAME (s
);
2483 S_CLEAR_EXTERNAL (symbolS
*s
)
2485 if (LOCAL_SYMBOL_CHECK (s
))
2487 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2489 /* Let .weak override. */
2492 s
->bsym
->flags
|= BSF_LOCAL
;
2493 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
2497 S_SET_WEAK (symbolS
*s
)
2499 if (LOCAL_SYMBOL_CHECK (s
))
2500 s
= local_symbol_convert ((struct local_symbol
*) s
);
2501 #ifdef obj_set_weak_hook
2502 obj_set_weak_hook (s
);
2504 s
->bsym
->flags
|= BSF_WEAK
;
2505 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
2509 S_SET_WEAKREFR (symbolS
*s
)
2511 if (LOCAL_SYMBOL_CHECK (s
))
2512 s
= local_symbol_convert ((struct local_symbol
*) s
);
2513 s
->flags
.weakrefr
= 1;
2514 /* If the alias was already used, make sure we mark the target as
2515 used as well, otherwise it might be dropped from the symbol
2516 table. This may have unintended side effects if the alias is
2517 later redirected to another symbol, such as keeping the unused
2518 previous target in the symbol table. Since it will be weak, it's
2521 symbol_mark_used (s
->value
.X_add_symbol
);
2525 S_CLEAR_WEAKREFR (symbolS
*s
)
2527 if (LOCAL_SYMBOL_CHECK (s
))
2529 s
->flags
.weakrefr
= 0;
2533 S_SET_WEAKREFD (symbolS
*s
)
2535 if (LOCAL_SYMBOL_CHECK (s
))
2536 s
= local_symbol_convert ((struct local_symbol
*) s
);
2537 s
->flags
.weakrefd
= 1;
2542 S_CLEAR_WEAKREFD (symbolS
*s
)
2544 if (LOCAL_SYMBOL_CHECK (s
))
2546 if (s
->flags
.weakrefd
)
2548 s
->flags
.weakrefd
= 0;
2549 /* If a weakref target symbol is weak, then it was never
2550 referenced directly before, not even in a .global directive,
2551 so decay it to local. If it remains undefined, it will be
2552 later turned into a global, like any other undefined
2554 if (s
->bsym
->flags
& BSF_WEAK
)
2556 #ifdef obj_clear_weak_hook
2557 obj_clear_weak_hook (s
);
2559 s
->bsym
->flags
&= ~BSF_WEAK
;
2560 s
->bsym
->flags
|= BSF_LOCAL
;
2566 S_SET_THREAD_LOCAL (symbolS
*s
)
2568 if (LOCAL_SYMBOL_CHECK (s
))
2569 s
= local_symbol_convert ((struct local_symbol
*) s
);
2570 if (bfd_is_com_section (s
->bsym
->section
)
2571 && (s
->bsym
->flags
& BSF_THREAD_LOCAL
) != 0)
2573 s
->bsym
->flags
|= BSF_THREAD_LOCAL
;
2574 if ((s
->bsym
->flags
& BSF_FUNCTION
) != 0)
2575 as_bad (_("Accessing function `%s' as thread-local object"),
2577 else if (! bfd_is_und_section (s
->bsym
->section
)
2578 && (s
->bsym
->section
->flags
& SEC_THREAD_LOCAL
) == 0)
2579 as_bad (_("Accessing `%s' as thread-local object"),
2584 S_SET_NAME (symbolS
*s
, const char *name
)
2586 if (LOCAL_SYMBOL_CHECK (s
))
2588 ((struct local_symbol
*) s
)->name
= name
;
2591 s
->bsym
->name
= name
;
2595 S_SET_VOLATILE (symbolS
*s
)
2597 if (LOCAL_SYMBOL_CHECK (s
))
2598 s
= local_symbol_convert ((struct local_symbol
*) s
);
2599 s
->flags
.volatil
= 1;
2603 S_CLEAR_VOLATILE (symbolS
*s
)
2605 if (!LOCAL_SYMBOL_CHECK (s
))
2606 s
->flags
.volatil
= 0;
2610 S_SET_FORWARD_REF (symbolS
*s
)
2612 if (LOCAL_SYMBOL_CHECK (s
))
2613 s
= local_symbol_convert ((struct local_symbol
*) s
);
2614 s
->flags
.forward_ref
= 1;
2617 /* Return the previous symbol in a chain. */
2620 symbol_previous (symbolS
*s
)
2622 if (LOCAL_SYMBOL_CHECK (s
))
2627 /* Return the next symbol in a chain. */
2630 symbol_next (symbolS
*s
)
2632 if (LOCAL_SYMBOL_CHECK (s
))
2637 /* Return a pointer to the value of a symbol as an expression. */
2640 symbol_get_value_expression (symbolS
*s
)
2642 if (LOCAL_SYMBOL_CHECK (s
))
2643 s
= local_symbol_convert ((struct local_symbol
*) s
);
2647 /* Set the value of a symbol to an expression. */
2650 symbol_set_value_expression (symbolS
*s
, const expressionS
*exp
)
2652 if (LOCAL_SYMBOL_CHECK (s
))
2653 s
= local_symbol_convert ((struct local_symbol
*) s
);
2655 S_CLEAR_WEAKREFR (s
);
2658 /* Return whether 2 symbols are the same. */
2661 symbol_same_p (symbolS
*s1
, symbolS
*s2
)
2663 s1
= get_real_sym (s1
);
2664 s2
= get_real_sym (s2
);
2668 /* Return a pointer to the X_add_number component of a symbol. */
2671 symbol_X_add_number (symbolS
*s
)
2673 if (LOCAL_SYMBOL_CHECK (s
))
2674 return (offsetT
*) &((struct local_symbol
*) s
)->value
;
2676 return &s
->value
.X_add_number
;
2679 /* Set the value of SYM to the current position in the current segment. */
2682 symbol_set_value_now (symbolS
*sym
)
2684 S_SET_SEGMENT (sym
, now_seg
);
2685 S_SET_VALUE (sym
, frag_now_fix ());
2686 symbol_set_frag (sym
, frag_now
);
2689 /* Set the frag of a symbol. */
2692 symbol_set_frag (symbolS
*s
, fragS
*f
)
2694 if (LOCAL_SYMBOL_CHECK (s
))
2696 ((struct local_symbol
*) s
)->u
.frag
= f
;
2700 S_CLEAR_WEAKREFR (s
);
2703 /* Return the frag of a symbol. */
2706 symbol_get_frag (symbolS
*s
)
2708 if (LOCAL_SYMBOL_CHECK (s
))
2709 return ((struct local_symbol
*) s
)->u
.frag
;
2713 /* Mark a symbol as having been used. */
2716 symbol_mark_used (symbolS
*s
)
2718 if (LOCAL_SYMBOL_CHECK (s
))
2721 if (S_IS_WEAKREFR (s
))
2722 symbol_mark_used (s
->value
.X_add_symbol
);
2725 /* Clear the mark of whether a symbol has been used. */
2728 symbol_clear_used (symbolS
*s
)
2730 if (LOCAL_SYMBOL_CHECK (s
))
2731 s
= local_symbol_convert ((struct local_symbol
*) s
);
2735 /* Return whether a symbol has been used. */
2738 symbol_used_p (symbolS
*s
)
2740 if (LOCAL_SYMBOL_CHECK (s
))
2742 return s
->flags
.used
;
2745 /* Mark a symbol as having been used in a reloc. */
2748 symbol_mark_used_in_reloc (symbolS
*s
)
2750 if (LOCAL_SYMBOL_CHECK (s
))
2751 s
= local_symbol_convert ((struct local_symbol
*) s
);
2752 s
->flags
.used_in_reloc
= 1;
2755 /* Clear the mark of whether a symbol has been used in a reloc. */
2758 symbol_clear_used_in_reloc (symbolS
*s
)
2760 if (LOCAL_SYMBOL_CHECK (s
))
2762 s
->flags
.used_in_reloc
= 0;
2765 /* Return whether a symbol has been used in a reloc. */
2768 symbol_used_in_reloc_p (symbolS
*s
)
2770 if (LOCAL_SYMBOL_CHECK (s
))
2772 return s
->flags
.used_in_reloc
;
2775 /* Mark a symbol as an MRI common symbol. */
2778 symbol_mark_mri_common (symbolS
*s
)
2780 if (LOCAL_SYMBOL_CHECK (s
))
2781 s
= local_symbol_convert ((struct local_symbol
*) s
);
2782 s
->flags
.mri_common
= 1;
2785 /* Clear the mark of whether a symbol is an MRI common symbol. */
2788 symbol_clear_mri_common (symbolS
*s
)
2790 if (LOCAL_SYMBOL_CHECK (s
))
2792 s
->flags
.mri_common
= 0;
2795 /* Return whether a symbol is an MRI common symbol. */
2798 symbol_mri_common_p (symbolS
*s
)
2800 if (LOCAL_SYMBOL_CHECK (s
))
2802 return s
->flags
.mri_common
;
2805 /* Mark a symbol as having been written. */
2808 symbol_mark_written (symbolS
*s
)
2810 if (LOCAL_SYMBOL_CHECK (s
))
2812 s
->flags
.written
= 1;
2815 /* Clear the mark of whether a symbol has been written. */
2818 symbol_clear_written (symbolS
*s
)
2820 if (LOCAL_SYMBOL_CHECK (s
))
2822 s
->flags
.written
= 0;
2825 /* Return whether a symbol has been written. */
2828 symbol_written_p (symbolS
*s
)
2830 if (LOCAL_SYMBOL_CHECK (s
))
2832 return s
->flags
.written
;
2835 /* Mark a symbol has having been resolved. */
2838 symbol_mark_resolved (symbolS
*s
)
2840 if (LOCAL_SYMBOL_CHECK (s
))
2842 ((struct local_symbol
*) s
)->flags
.resolved
= 1;
2845 s
->flags
.resolved
= 1;
2848 /* Return whether a symbol has been resolved. */
2851 symbol_resolved_p (symbolS
*s
)
2853 if (LOCAL_SYMBOL_CHECK (s
))
2854 return ((struct local_symbol
*) s
)->flags
.resolved
;
2855 return s
->flags
.resolved
;
2858 /* Return whether a symbol is a section symbol. */
2861 symbol_section_p (symbolS
*s ATTRIBUTE_UNUSED
)
2863 if (LOCAL_SYMBOL_CHECK (s
))
2865 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2868 /* Return whether a symbol is equated to another symbol. */
2871 symbol_equated_p (symbolS
*s
)
2873 if (LOCAL_SYMBOL_CHECK (s
))
2875 return s
->value
.X_op
== O_symbol
;
2878 /* Return whether a symbol is equated to another symbol, and should be
2879 treated specially when writing out relocs. */
2882 symbol_equated_reloc_p (symbolS
*s
)
2884 if (LOCAL_SYMBOL_CHECK (s
))
2886 /* X_op_symbol, normally not used for O_symbol, is set by
2887 resolve_symbol_value to flag expression syms that have been
2889 return (s
->value
.X_op
== O_symbol
2890 #if defined (OBJ_COFF) && defined (TE_PE)
2893 && ((s
->flags
.resolved
&& s
->value
.X_op_symbol
!= NULL
)
2894 || ! S_IS_DEFINED (s
)
2895 || S_IS_COMMON (s
)));
2898 /* Return whether a symbol has a constant value. */
2901 symbol_constant_p (symbolS
*s
)
2903 if (LOCAL_SYMBOL_CHECK (s
))
2905 return s
->value
.X_op
== O_constant
;
2908 /* Return whether a symbol was cloned and thus removed from the global
2912 symbol_shadow_p (symbolS
*s
)
2914 if (LOCAL_SYMBOL_CHECK (s
))
2916 return s
->next
== s
;
2919 /* If S was created as a struct symbol, return S, otherwise if S is a
2920 converted local_symbol return the converted symbol, otherwise
2924 symbol_symbolS (symbolS
*s
)
2926 if (LOCAL_SYMBOL_CHECK (s
))
2931 /* Return the BFD symbol for a symbol. */
2934 symbol_get_bfdsym (symbolS
*s
)
2936 if (LOCAL_SYMBOL_CHECK (s
))
2937 s
= local_symbol_convert ((struct local_symbol
*) s
);
2941 /* Set the BFD symbol for a symbol. */
2944 symbol_set_bfdsym (symbolS
*s
, asymbol
*bsym
)
2946 if (LOCAL_SYMBOL_CHECK (s
))
2947 s
= local_symbol_convert ((struct local_symbol
*) s
);
2948 /* Usually, it is harmless to reset a symbol to a BFD section
2949 symbol. For example, obj_elf_change_section sets the BFD symbol
2950 of an old symbol with the newly created section symbol. But when
2951 we have multiple sections with the same name, the newly created
2952 section may have the same name as an old section. We check if the
2953 old symbol has been already marked as a section symbol before
2955 if ((s
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
2957 /* else XXX - What do we do now ? */
2960 #ifdef OBJ_SYMFIELD_TYPE
2962 /* Get a pointer to the object format information for a symbol. */
2965 symbol_get_obj (symbolS
*s
)
2967 if (LOCAL_SYMBOL_CHECK (s
))
2968 s
= local_symbol_convert ((struct local_symbol
*) s
);
2972 /* Set the object format information for a symbol. */
2975 symbol_set_obj (symbolS
*s
, OBJ_SYMFIELD_TYPE
*o
)
2977 if (LOCAL_SYMBOL_CHECK (s
))
2978 s
= local_symbol_convert ((struct local_symbol
*) s
);
2982 #endif /* OBJ_SYMFIELD_TYPE */
2984 #ifdef TC_SYMFIELD_TYPE
2986 /* Get a pointer to the processor information for a symbol. */
2989 symbol_get_tc (symbolS
*s
)
2991 if (LOCAL_SYMBOL_CHECK (s
))
2992 s
= local_symbol_convert ((struct local_symbol
*) s
);
2996 /* Set the processor information for a symbol. */
2999 symbol_set_tc (symbolS
*s
, TC_SYMFIELD_TYPE
*o
)
3001 if (LOCAL_SYMBOL_CHECK (s
))
3002 s
= local_symbol_convert ((struct local_symbol
*) s
);
3006 #endif /* TC_SYMFIELD_TYPE */
3011 symbol_lastP
= NULL
;
3012 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
3013 sy_hash
= htab_create_alloc (16, hash_symbol_entry
, eq_symbol_entry
,
3014 NULL
, xcalloc
, free
);
3015 local_hash
= htab_create_alloc (16, hash_symbol_entry
, eq_symbol_entry
,
3016 NULL
, xcalloc
, free
);
3018 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
3019 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
3020 abs_symbol
.bsym
= bfd_abs_section_ptr
->symbol
;
3022 abs_symbol
.value
.X_op
= O_constant
;
3023 abs_symbol
.frag
= &zero_address_frag
;
3025 if (LOCAL_LABELS_FB
)
3030 dot_symbol_init (void)
3032 dot_symbol
.bsym
= bfd_make_empty_symbol (stdoutput
);
3033 if (dot_symbol
.bsym
== NULL
)
3034 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
3035 dot_symbol
.bsym
->name
= ".";
3036 dot_symbol
.flags
.forward_ref
= 1;
3037 dot_symbol
.value
.X_op
= O_constant
;
3042 /* Maximum indent level.
3043 Available for modification inside a gdb session. */
3044 static int max_indent_level
= 8;
3047 print_symbol_value_1 (FILE *file
, symbolS
*sym
)
3049 const char *name
= S_GET_NAME (sym
);
3050 if (!name
|| !name
[0])
3052 fprintf (file
, "sym ");
3053 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) sym
));
3054 fprintf (file
, " %s", name
);
3056 if (LOCAL_SYMBOL_CHECK (sym
))
3058 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
3060 if (locsym
->u
.frag
!= & zero_address_frag
3061 && locsym
->u
.frag
!= NULL
)
3063 fprintf (file
, " frag ");
3064 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) locsym
->u
.frag
));
3066 if (locsym
->flags
.resolved
)
3067 fprintf (file
, " resolved");
3068 fprintf (file
, " local");
3072 if (sym
->frag
!= &zero_address_frag
)
3074 fprintf (file
, " frag ");
3075 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) sym
->frag
));
3077 if (sym
->flags
.written
)
3078 fprintf (file
, " written");
3079 if (sym
->flags
.resolved
)
3080 fprintf (file
, " resolved");
3081 else if (sym
->flags
.resolving
)
3082 fprintf (file
, " resolving");
3083 if (sym
->flags
.used_in_reloc
)
3084 fprintf (file
, " used-in-reloc");
3085 if (sym
->flags
.used
)
3086 fprintf (file
, " used");
3087 if (S_IS_LOCAL (sym
))
3088 fprintf (file
, " local");
3089 if (S_IS_EXTERNAL (sym
))
3090 fprintf (file
, " extern");
3091 if (S_IS_WEAK (sym
))
3092 fprintf (file
, " weak");
3093 if (S_IS_DEBUG (sym
))
3094 fprintf (file
, " debug");
3095 if (S_IS_DEFINED (sym
))
3096 fprintf (file
, " defined");
3098 if (S_IS_WEAKREFR (sym
))
3099 fprintf (file
, " weakrefr");
3100 if (S_IS_WEAKREFD (sym
))
3101 fprintf (file
, " weakrefd");
3102 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
3103 if (symbol_resolved_p (sym
))
3105 segT s
= S_GET_SEGMENT (sym
);
3107 if (s
!= undefined_section
3108 && s
!= expr_section
)
3109 fprintf (file
, " %lx", (unsigned long) S_GET_VALUE (sym
));
3111 else if (indent_level
< max_indent_level
3112 && S_GET_SEGMENT (sym
) != undefined_section
)
3115 fprintf (file
, "\n%*s<", indent_level
* 4, "");
3116 if (LOCAL_SYMBOL_CHECK (sym
))
3117 fprintf (file
, "constant %lx",
3118 (unsigned long) ((struct local_symbol
*) sym
)->value
);
3120 print_expr_1 (file
, &sym
->value
);
3121 fprintf (file
, ">");
3128 print_symbol_value (symbolS
*sym
)
3131 print_symbol_value_1 (stderr
, sym
);
3132 fprintf (stderr
, "\n");
3136 print_binary (FILE *file
, const char *name
, expressionS
*exp
)
3139 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
3140 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3141 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3142 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3143 fprintf (file
, ">");
3148 print_expr_1 (FILE *file
, expressionS
*exp
)
3150 fprintf (file
, "expr ");
3151 fprintf_vma (file
, (bfd_vma
) ((bfd_hostptr_t
) exp
));
3152 fprintf (file
, " ");
3156 fprintf (file
, "illegal");
3159 fprintf (file
, "absent");
3162 fprintf (file
, "constant %lx", (unsigned long) exp
->X_add_number
);
3166 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
3167 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3168 fprintf (file
, ">");
3170 if (exp
->X_add_number
)
3171 fprintf (file
, "\n%*s%lx", indent_level
* 4, "",
3172 (unsigned long) exp
->X_add_number
);
3176 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
3179 fprintf (file
, "big");
3182 fprintf (file
, "uminus -<");
3184 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3185 fprintf (file
, ">");
3186 goto maybe_print_addnum
;
3188 fprintf (file
, "bit_not");
3191 print_binary (file
, "multiply", exp
);
3194 print_binary (file
, "divide", exp
);
3197 print_binary (file
, "modulus", exp
);
3200 print_binary (file
, "lshift", exp
);
3203 print_binary (file
, "rshift", exp
);
3205 case O_bit_inclusive_or
:
3206 print_binary (file
, "bit_ior", exp
);
3208 case O_bit_exclusive_or
:
3209 print_binary (file
, "bit_xor", exp
);
3212 print_binary (file
, "bit_and", exp
);
3215 print_binary (file
, "eq", exp
);
3218 print_binary (file
, "ne", exp
);
3221 print_binary (file
, "lt", exp
);
3224 print_binary (file
, "le", exp
);
3227 print_binary (file
, "ge", exp
);
3230 print_binary (file
, "gt", exp
);
3233 print_binary (file
, "logical_and", exp
);
3236 print_binary (file
, "logical_or", exp
);
3240 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
3241 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3242 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3243 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3244 fprintf (file
, ">");
3245 goto maybe_print_addnum
;
3248 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
3249 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3250 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3251 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3252 fprintf (file
, ">");
3253 goto maybe_print_addnum
;
3255 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
3262 print_expr (expressionS
*exp
)
3264 print_expr_1 (stderr
, exp
);
3265 fprintf (stderr
, "\n");
3269 symbol_print_statistics (FILE *file
)
3271 htab_print_statistics (file
, "symbol table", sy_hash
);
3272 htab_print_statistics (file
, "mini local symbol table", local_hash
);
3273 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
3274 local_symbol_count
, local_symbol_conversion_count
);
3277 #ifdef OBJ_COMPLEX_RELC
3279 /* Convert given symbol to a new complex-relocation symbol name. This
3280 may be a recursive function, since it might be called for non-leaf
3281 nodes (plain symbols) in the expression tree. The caller owns the
3282 returning string, so should free it eventually. Errors are
3283 indicated via as_bad and a NULL return value. The given symbol
3284 is marked with used_in_reloc. */
3287 symbol_relc_make_sym (symbolS
* sym
)
3289 char * terminal
= NULL
;
3294 gas_assert (sym
!= NULL
);
3296 /* Recurse to symbol_relc_make_expr if this symbol
3297 is defined as an expression or a plain value. */
3298 if ( S_GET_SEGMENT (sym
) == expr_section
3299 || S_GET_SEGMENT (sym
) == absolute_section
)
3300 return symbol_relc_make_expr (symbol_get_value_expression (sym
));
3302 /* This may be a "fake symbol", referring to ".".
3303 Write out a special null symbol to refer to this position. */
3304 if (! strcmp (S_GET_NAME (sym
), FAKE_LABEL_NAME
))
3305 return xstrdup (".");
3307 /* We hope this is a plain leaf symbol. Construct the encoding
3308 as {S,s}II...:CCCCCCC....
3309 where 'S'/'s' means section symbol / plain symbol
3310 III is decimal for the symbol name length
3311 CCC is the symbol name itself. */
3312 symbol_mark_used_in_reloc (sym
);
3314 sname
= S_GET_NAME (sym
);
3315 sname_len
= strlen (sname
);
3316 typetag
= symbol_section_p (sym
) ? 'S' : 's';
3318 terminal
= XNEWVEC (char, (1 /* S or s */
3319 + 8 /* sname_len in decimal */
3321 + sname_len
/* name itself */
3324 sprintf (terminal
, "%c%d:%s", typetag
, sname_len
, sname
);
3328 /* Convert given value to a new complex-relocation symbol name. This
3329 is a non-recursive function, since it is be called for leaf nodes
3330 (plain values) in the expression tree. The caller owns the
3331 returning string, so should free() it eventually. No errors. */
3334 symbol_relc_make_value (offsetT val
)
3336 char * terminal
= XNEWVEC (char, 28); /* Enough for long long. */
3339 bfd_sprintf_vma (stdoutput
, terminal
+ 1, val
);
3343 /* Convert given expression to a new complex-relocation symbol name.
3344 This is a recursive function, since it traverses the entire given
3345 expression tree. The caller owns the returning string, so should
3346 free() it eventually. Errors are indicated via as_bad() and a NULL
3350 symbol_relc_make_expr (expressionS
* exp
)
3352 const char * opstr
= NULL
; /* Operator prefix string. */
3353 int arity
= 0; /* Arity of this operator. */
3354 char * operands
[3]; /* Up to three operands. */
3355 char * concat_string
= NULL
;
3357 operands
[0] = operands
[1] = operands
[2] = NULL
;
3359 gas_assert (exp
!= NULL
);
3361 /* Match known operators -> fill in opstr, arity, operands[] and fall
3362 through to construct subexpression fragments; may instead return
3363 string directly for leaf nodes. */
3365 /* See expr.h for the meaning of all these enums. Many operators
3366 have an unnatural arity (X_add_number implicitly added). The
3367 conversion logic expands them to explicit "+" subexpressions. */
3372 as_bad ("Unknown expression operator (enum %d)", exp
->X_op
);
3377 return symbol_relc_make_value (exp
->X_add_number
);
3380 if (exp
->X_add_number
)
3384 operands
[0] = symbol_relc_make_sym (exp
->X_add_symbol
);
3385 operands
[1] = symbol_relc_make_value (exp
->X_add_number
);
3389 return symbol_relc_make_sym (exp
->X_add_symbol
);
3391 /* Helper macros for nesting nodes. */
3393 #define HANDLE_XADD_OPT1(str_) \
3394 if (exp->X_add_number) \
3397 opstr = "+:" str_; \
3398 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3399 operands[1] = symbol_relc_make_value (exp->X_add_number); \
3406 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3410 #define HANDLE_XADD_OPT2(str_) \
3411 if (exp->X_add_number) \
3414 opstr = "+:" str_; \
3415 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3416 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3417 operands[2] = symbol_relc_make_value (exp->X_add_number); \
3423 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3424 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3428 /* Nesting nodes. */
3430 case O_uminus
: HANDLE_XADD_OPT1 ("0-");
3431 case O_bit_not
: HANDLE_XADD_OPT1 ("~");
3432 case O_logical_not
: HANDLE_XADD_OPT1 ("!");
3433 case O_multiply
: HANDLE_XADD_OPT2 ("*");
3434 case O_divide
: HANDLE_XADD_OPT2 ("/");
3435 case O_modulus
: HANDLE_XADD_OPT2 ("%");
3436 case O_left_shift
: HANDLE_XADD_OPT2 ("<<");
3437 case O_right_shift
: HANDLE_XADD_OPT2 (">>");
3438 case O_bit_inclusive_or
: HANDLE_XADD_OPT2 ("|");
3439 case O_bit_exclusive_or
: HANDLE_XADD_OPT2 ("^");
3440 case O_bit_and
: HANDLE_XADD_OPT2 ("&");
3441 case O_add
: HANDLE_XADD_OPT2 ("+");
3442 case O_subtract
: HANDLE_XADD_OPT2 ("-");
3443 case O_eq
: HANDLE_XADD_OPT2 ("==");
3444 case O_ne
: HANDLE_XADD_OPT2 ("!=");
3445 case O_lt
: HANDLE_XADD_OPT2 ("<");
3446 case O_le
: HANDLE_XADD_OPT2 ("<=");
3447 case O_ge
: HANDLE_XADD_OPT2 (">=");
3448 case O_gt
: HANDLE_XADD_OPT2 (">");
3449 case O_logical_and
: HANDLE_XADD_OPT2 ("&&");
3450 case O_logical_or
: HANDLE_XADD_OPT2 ("||");
3453 /* Validate & reject early. */
3454 if (arity
>= 1 && ((operands
[0] == NULL
) || (strlen (operands
[0]) == 0)))
3456 if (arity
>= 2 && ((operands
[1] == NULL
) || (strlen (operands
[1]) == 0)))
3458 if (arity
>= 3 && ((operands
[2] == NULL
) || (strlen (operands
[2]) == 0)))
3462 concat_string
= NULL
;
3463 else if (arity
== 0)
3464 concat_string
= xstrdup (opstr
);
3465 else if (arity
== 1)
3466 concat_string
= concat (opstr
, ":", operands
[0], (char *) NULL
);
3467 else if (arity
== 2)
3468 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1],
3471 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1], ":",
3472 operands
[2], (char *) NULL
);
3474 /* Free operand strings (not opstr). */
3475 if (arity
>= 1) xfree (operands
[0]);
3476 if (arity
>= 2) xfree (operands
[1]);
3477 if (arity
>= 3) xfree (operands
[2]);
3479 return concat_string
;