1 /* symbols.c -symbol table-
2 Copyright (C) 1987-2024 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" */
37 /* Whether the symbol is a local_symbol. */
38 unsigned int local_symbol
: 1;
40 /* Weather symbol has been written. */
41 unsigned int written
: 1;
43 /* Whether symbol value has been completely resolved (used during
44 final pass over symbol table). */
45 unsigned int resolved
: 1;
47 /* Whether the symbol value is currently being resolved (used to
48 detect loops in symbol dependencies). */
49 unsigned int resolving
: 1;
51 /* Whether the symbol value is used in a reloc. This is used to
52 ensure that symbols used in relocs are written out, even if they
53 are local and would otherwise not be. */
54 unsigned int used_in_reloc
: 1;
56 /* Whether the symbol is used as an operand or in an expression.
57 NOTE: Not all the backends keep this information accurate;
58 backends which use this bit are responsible for setting it when
59 a symbol is used in backend routines. */
60 unsigned int used
: 1;
62 /* Whether the symbol can be re-defined. */
63 unsigned int volatil
: 1;
65 /* Whether the symbol is a forward reference, and whether such has
67 unsigned int forward_ref
: 1;
68 unsigned int forward_resolved
: 1;
70 /* This is set if the symbol is defined in an MRI common section.
71 We handle such sections as single common symbols, so symbols
72 defined within them must be treated specially by the relocation
74 unsigned int mri_common
: 1;
76 /* This is set if the symbol is set with a .weakref directive. */
77 unsigned int weakrefr
: 1;
79 /* This is set when the symbol is referenced as part of a .weakref
80 directive, but only if the symbol was not in the symbol table
81 before. It is cleared as soon as any direct reference to the
83 unsigned int weakrefd
: 1;
85 /* Whether the symbol has been marked to be removed by a .symver
87 unsigned int removed
: 1;
89 /* Set when a warning about the symbol containing multibyte characters
91 unsigned int multibyte_warned
: 1;
94 /* A pointer in the symbol may point to either a complete symbol
95 (struct symbol below) or to a local symbol (struct local_symbol
96 defined here). The symbol code can detect the case by examining
97 the first field which is present in both structs.
99 We do this because we ordinarily only need a small amount of
100 information for a local symbol. The symbol table takes up a lot of
101 space, and storing less information for a local symbol can make a
102 big difference in assembler memory usage when assembling a large
107 /* Symbol flags. Only local_symbol and resolved are relevant. */
108 struct symbol_flags flags
;
110 /* Hash value calculated from name. */
113 /* The symbol name. */
116 /* The symbol frag. */
119 /* The symbol section. */
122 /* The value of the symbol. */
126 /* The information we keep for a symbol. The symbol table holds
127 pointers both to this and to local_symbol structures. The first
128 three fields must be identical to struct local_symbol, and the size
129 should be the same as or smaller than struct local_symbol.
130 Fields that don't fit go to an extension structure. */
135 struct symbol_flags flags
;
137 /* Hash value calculated from name. */
140 /* The symbol name. */
143 /* Pointer to the frag this symbol is attached to, if any.
150 /* Extra symbol fields that won't fit. */
154 /* Extra fields to make up a full symbol. */
158 /* The value of the symbol. */
161 /* Forwards and backwards chain pointers. */
163 struct symbol
*previous
;
165 #ifdef OBJ_SYMFIELD_TYPE
166 OBJ_SYMFIELD_TYPE obj
;
169 #ifdef TC_SYMFIELD_TYPE
174 typedef union symbol_entry
176 struct local_symbol lsy
;
180 /* Hash function for a symbol_entry. */
183 hash_symbol_entry (const void *e
)
185 symbol_entry_t
*entry
= (symbol_entry_t
*) e
;
186 if (entry
->sy
.hash
== 0)
187 entry
->sy
.hash
= htab_hash_string (entry
->sy
.name
);
189 return entry
->sy
.hash
;
192 /* Equality function for a symbol_entry. */
195 eq_symbol_entry (const void *a
, const void *b
)
197 const symbol_entry_t
*ea
= (const symbol_entry_t
*) a
;
198 const symbol_entry_t
*eb
= (const symbol_entry_t
*) b
;
200 return (ea
->sy
.hash
== eb
->sy
.hash
201 && strcmp (ea
->sy
.name
, eb
->sy
.name
) == 0);
205 symbol_entry_find (htab_t table
, const char *name
)
207 hashval_t hash
= htab_hash_string (name
);
208 symbol_entry_t needle
= { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
209 hash
, name
, 0, 0, 0 } };
210 return htab_find_with_hash (table
, &needle
, hash
);
214 /* This is non-zero if symbols are case sensitive, which is the
216 int symbols_case_sensitive
= 1;
218 #ifndef WORKING_DOT_WORD
219 extern int new_broken_words
;
222 static htab_t sy_hash
;
224 /* Below are commented in "symbols.h". */
225 symbolS
*symbol_rootP
;
226 symbolS
*symbol_lastP
;
228 struct xsymbol abs_symbol_x
;
230 struct xsymbol dot_symbol_x
;
233 #define debug_verify_symchain verify_symbol_chain
235 #define debug_verify_symchain(root, last) ((void) 0)
238 #define DOLLAR_LABEL_CHAR '\001'
239 #define LOCAL_LABEL_CHAR '\002'
241 #ifndef TC_LABEL_IS_LOCAL
242 #define TC_LABEL_IS_LOCAL(name) 0
245 struct obstack notes
;
247 /* Utility functions to allocate and duplicate memory on the notes
248 obstack, each like the corresponding function without "notes_"
249 prefix. All of these exit on an allocation failure. */
252 notes_alloc (size_t size
)
254 return obstack_alloc (¬es
, size
);
258 notes_calloc (size_t n
, size_t size
)
262 if (gas_mul_overflow (n
, size
, &amt
))
264 obstack_alloc_failed_handler ();
267 ret
= notes_alloc (amt
);
268 memset (ret
, 0, amt
);
273 notes_memdup (const void *src
, size_t copy_size
, size_t alloc_size
)
275 void *ret
= obstack_alloc (¬es
, alloc_size
);
276 memcpy (ret
, src
, copy_size
);
277 if (alloc_size
> copy_size
)
278 memset ((char *) ret
+ copy_size
, 0, alloc_size
- copy_size
);
283 notes_strdup (const char *str
)
285 size_t len
= strlen (str
) + 1;
286 return notes_memdup (str
, len
, len
);
290 notes_concat (const char *first
, ...)
295 va_start (args
, first
);
296 for (str
= first
; str
; str
= va_arg (args
, const char *))
298 size_t size
= strlen (str
);
299 obstack_grow (¬es
, str
, size
);
302 obstack_1grow (¬es
, 0);
303 return obstack_finish (¬es
);
306 /* Use with caution! Frees PTR and all more recently allocated memory
307 on the notes obstack. */
310 notes_free (void *ptr
)
312 obstack_free (¬es
, ptr
);
316 /* The name of an external symbol which is
317 used to make weak PE symbol names unique. */
318 const char * an_external_name
;
321 /* Return a pointer to a new symbol. Die if we can't make a new
322 symbol. Fill in the symbol's values. Add symbol to end of symbol
325 This function should be called in the general case of creating a
326 symbol. However, if the output file symbol table has already been
327 set, and you are certain that this symbol won't be wanted in the
328 output file, you can call symbol_create. */
331 symbol_new (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
333 symbolS
*symbolP
= symbol_create (name
, segment
, frag
, valu
);
335 /* Link to end of symbol chain. */
336 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
341 /* Save a symbol name on a permanent obstack, and convert it according
342 to the object file format. */
345 save_symbol_name (const char *name
)
349 gas_assert (name
!= NULL
);
350 ret
= notes_strdup (name
);
352 #ifdef tc_canonicalize_symbol_name
353 ret
= tc_canonicalize_symbol_name (ret
);
356 if (! symbols_case_sensitive
)
360 for (s
= ret
; *s
!= '\0'; s
++)
368 symbol_init (symbolS
*symbolP
, const char *name
, asection
*sec
,
369 fragS
*frag
, valueT valu
)
371 symbolP
->frag
= frag
;
372 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
373 if (symbolP
->bsym
== NULL
)
374 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
375 symbolP
->bsym
->name
= name
;
376 symbolP
->bsym
->section
= sec
;
378 if (multibyte_handling
== multibyte_warn_syms
379 && ! symbolP
->flags
.local_symbol
380 && sec
!= undefined_section
381 && ! symbolP
->flags
.multibyte_warned
382 && scan_for_multibyte_characters ((const unsigned char *) name
,
383 (const unsigned char *) name
+ strlen (name
),
384 false /* Do not warn. */))
386 as_warn (_("symbol '%s' contains multibyte characters"), name
);
387 symbolP
->flags
.multibyte_warned
= 1;
390 S_SET_VALUE (symbolP
, valu
);
391 if (sec
== reg_section
)
392 symbolP
->x
->value
.X_op
= O_register
;
394 symbol_clear_list_pointers (symbolP
);
396 obj_symbol_new_hook (symbolP
);
398 #ifdef tc_symbol_new_hook
399 tc_symbol_new_hook (symbolP
);
403 /* Create a symbol. NAME is copied, the caller can destroy/modify. */
406 symbol_create (const char *name
, segT segment
, fragS
*frag
, valueT valu
)
408 const char *preserved_copy_of_name
;
412 preserved_copy_of_name
= save_symbol_name (name
);
414 size
= sizeof (symbolS
) + sizeof (struct xsymbol
);
415 symbolP
= notes_alloc (size
);
417 /* symbol must be born in some fixed state. This seems as good as any. */
418 memset (symbolP
, 0, size
);
419 symbolP
->name
= preserved_copy_of_name
;
420 symbolP
->x
= (struct xsymbol
*) (symbolP
+ 1);
422 symbol_init (symbolP
, preserved_copy_of_name
, segment
, frag
, valu
);
428 /* Local symbol support. If we can get away with it, we keep only a
429 small amount of information for local symbols. */
431 /* Used for statistics. */
433 static unsigned long local_symbol_count
;
434 static unsigned long local_symbol_conversion_count
;
436 /* Create a local symbol and insert it into the local hash table. */
438 struct local_symbol
*
439 local_symbol_make (const char *name
, segT section
, fragS
*frag
, valueT val
)
441 const char *name_copy
;
442 struct local_symbol
*ret
;
443 struct symbol_flags flags
= { .local_symbol
= 1, .resolved
= 0 };
445 ++local_symbol_count
;
447 name_copy
= save_symbol_name (name
);
449 ret
= notes_alloc (sizeof *ret
);
452 ret
->name
= name_copy
;
454 ret
->section
= section
;
457 htab_insert (sy_hash
, ret
, 1);
462 /* Convert a local symbol into a real symbol. */
465 local_symbol_convert (void *sym
)
467 symbol_entry_t
*ent
= (symbol_entry_t
*) sym
;
468 struct xsymbol
*xtra
;
471 gas_assert (ent
->lsy
.flags
.local_symbol
);
473 ++local_symbol_conversion_count
;
475 xtra
= notes_alloc (sizeof (*xtra
));
476 memset (xtra
, 0, sizeof (*xtra
));
477 val
= ent
->lsy
.value
;
480 /* Local symbols are always either defined or used. */
481 ent
->sy
.flags
.used
= 1;
482 ent
->sy
.flags
.local_symbol
= 0;
484 symbol_init (&ent
->sy
, ent
->lsy
.name
, ent
->lsy
.section
, ent
->lsy
.frag
, val
);
485 symbol_append (&ent
->sy
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
491 define_sym_at_dot (symbolS
*symbolP
)
493 symbolP
->frag
= frag_now
;
494 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
495 S_SET_SEGMENT (symbolP
, now_seg
);
498 /* We have just seen "<name>:".
499 Creates a struct symbol unless it already exists.
501 Gripes if we are redefining a symbol incompatibly (and ignores it). */
504 colon (/* Just seen "x:" - rattle symbols & frags. */
505 const char *sym_name
/* Symbol name, as a canonical string. */
506 /* We copy this string: OK to alter later. */)
508 symbolS
*symbolP
; /* Symbol we are working with. */
510 /* Sun local labels go out of scope whenever a non-local symbol is
512 if (LOCAL_LABELS_DOLLAR
513 && !bfd_is_local_label_name (stdoutput
, sym_name
))
514 dollar_label_clear ();
516 #ifndef WORKING_DOT_WORD
517 if (new_broken_words
)
519 struct broken_word
*a
;
524 if (now_seg
== absolute_section
)
526 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name
);
530 possible_bytes
= (md_short_jump_size
531 + new_broken_words
* md_long_jump_size
);
534 frag_opcode
= frag_var (rs_broken_word
,
538 (symbolS
*) broken_words
,
542 /* We want to store the pointer to where to insert the jump
543 table in the fr_opcode of the rs_broken_word frag. This
544 requires a little hackery. */
546 && (frag_tmp
->fr_type
!= rs_broken_word
547 || frag_tmp
->fr_opcode
))
548 frag_tmp
= frag_tmp
->fr_next
;
550 frag_tmp
->fr_opcode
= frag_opcode
;
551 new_broken_words
= 0;
553 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
554 a
->dispfrag
= frag_tmp
;
556 #endif /* WORKING_DOT_WORD */
558 #ifdef obj_frob_colon
559 obj_frob_colon (sym_name
);
562 if ((symbolP
= symbol_find (sym_name
)) != 0)
564 S_CLEAR_WEAKREFR (symbolP
);
565 #ifdef RESOLVE_SYMBOL_REDEFINITION
566 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
569 /* Now check for undefined symbols. */
570 if (symbolP
->flags
.local_symbol
)
572 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
574 if (locsym
->section
!= undefined_section
575 && (locsym
->frag
!= frag_now
576 || locsym
->section
!= now_seg
577 || locsym
->value
!= frag_now_fix ()))
579 as_bad (_("symbol `%s' is already defined"), sym_name
);
583 locsym
->section
= now_seg
;
584 locsym
->frag
= frag_now
;
585 locsym
->value
= frag_now_fix ();
587 else if (!(S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
588 || S_IS_COMMON (symbolP
)
589 || S_IS_VOLATILE (symbolP
))
591 if (S_IS_VOLATILE (symbolP
))
593 symbolP
= symbol_clone (symbolP
, 1);
594 S_SET_VALUE (symbolP
, 0);
595 S_CLEAR_VOLATILE (symbolP
);
597 if (S_GET_VALUE (symbolP
) == 0)
599 define_sym_at_dot (symbolP
);
602 #endif /* if we have one, it better be zero. */
607 /* There are still several cases to check:
609 A .comm/.lcomm symbol being redefined as initialized
612 A .comm/.lcomm symbol being redefined with a larger
615 This only used to be allowed on VMS gas, but Sun cc
616 on the sparc also depends on it. */
618 if (((!S_IS_DEBUG (symbolP
)
619 && (!S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
))
620 && S_IS_EXTERNAL (symbolP
))
621 || S_GET_SEGMENT (symbolP
) == bss_section
)
622 && (now_seg
== data_section
623 || now_seg
== bss_section
624 || now_seg
== S_GET_SEGMENT (symbolP
)))
626 /* Select which of the 2 cases this is. */
627 if (now_seg
!= data_section
)
629 /* New .comm for prev .comm symbol.
631 If the new size is larger we just change its
632 value. If the new size is smaller, we ignore
634 if (S_GET_VALUE (symbolP
)
635 < ((unsigned) frag_now_fix ()))
637 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
642 /* It is a .comm/.lcomm being converted to initialized
644 define_sym_at_dot (symbolP
);
649 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT))
650 static const char *od_buf
= "";
654 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
655 sprintf (od_buf
, "%d.%d.",
656 S_GET_OTHER (symbolP
),
657 S_GET_DESC (symbolP
));
659 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
661 segment_name (S_GET_SEGMENT (symbolP
)),
663 (long) S_GET_VALUE (symbolP
));
665 } /* if the undefined symbol has no value */
669 /* Don't blow up if the definition is the same. */
670 if (!(frag_now
== symbolP
->frag
671 && S_GET_VALUE (symbolP
) == frag_now_fix ()
672 && S_GET_SEGMENT (symbolP
) == now_seg
))
674 as_bad (_("symbol `%s' is already defined"), sym_name
);
675 symbolP
= symbol_clone (symbolP
, 0);
676 define_sym_at_dot (symbolP
);
681 else if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, sym_name
))
683 symbolP
= (symbolS
*) local_symbol_make (sym_name
, now_seg
, frag_now
,
688 symbolP
= symbol_new (sym_name
, now_seg
, frag_now
, frag_now_fix ());
690 symbol_table_insert (symbolP
);
693 if (mri_common_symbol
!= NULL
)
695 /* This symbol is actually being defined within an MRI common
696 section. This requires special handling. */
697 if (symbolP
->flags
.local_symbol
)
698 symbolP
= local_symbol_convert (symbolP
);
699 symbolP
->x
->value
.X_op
= O_symbol
;
700 symbolP
->x
->value
.X_add_symbol
= mri_common_symbol
;
701 symbolP
->x
->value
.X_add_number
= S_GET_VALUE (mri_common_symbol
);
702 symbolP
->frag
= &zero_address_frag
;
703 S_SET_SEGMENT (symbolP
, expr_section
);
704 symbolP
->flags
.mri_common
= 1;
708 tc_frob_label (symbolP
);
710 #ifdef obj_frob_label
711 obj_frob_label (symbolP
);
714 ginsn_frob_label (symbolP
);
719 /* Die if we can't insert the symbol. */
722 symbol_table_insert (symbolS
*symbolP
)
726 htab_insert (sy_hash
, symbolP
, 1);
729 /* If a symbol name does not exist, create it as undefined, and insert
730 it into the symbol table. Return a pointer to it. */
733 symbol_find_or_make (const char *name
)
737 symbolP
= symbol_find (name
);
741 if (! flag_keep_locals
&& bfd_is_local_label_name (stdoutput
, name
))
743 symbolP
= md_undefined_symbol ((char *) name
);
747 symbolP
= (symbolS
*) local_symbol_make (name
, undefined_section
,
748 &zero_address_frag
, 0);
752 symbolP
= symbol_make (name
);
754 symbol_table_insert (symbolP
);
755 } /* if symbol wasn't found */
761 symbol_make (const char *name
)
765 /* Let the machine description default it, e.g. for register names. */
766 symbolP
= md_undefined_symbol ((char *) name
);
769 symbolP
= symbol_new (name
, undefined_section
, &zero_address_frag
, 0);
775 symbol_clone (symbolS
*orgsymP
, int replace
)
778 asymbol
*bsymorg
, *bsymnew
;
780 /* Make sure we never clone the dot special symbol. */
781 gas_assert (orgsymP
!= &dot_symbol
);
783 /* When cloning a local symbol it isn't absolutely necessary to
784 convert the original, but converting makes the code much
785 simpler to cover this unexpected case. As of 2020-08-21
786 symbol_clone won't be called on a local symbol. */
787 if (orgsymP
->flags
.local_symbol
)
788 orgsymP
= local_symbol_convert (orgsymP
);
789 bsymorg
= orgsymP
->bsym
;
791 newsymP
= notes_alloc (sizeof (symbolS
) + sizeof (struct xsymbol
));
793 newsymP
->x
= (struct xsymbol
*) (newsymP
+ 1);
794 *newsymP
->x
= *orgsymP
->x
;
795 bsymnew
= bfd_make_empty_symbol (bfd_asymbol_bfd (bsymorg
));
797 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
798 newsymP
->bsym
= bsymnew
;
799 bsymnew
->name
= bsymorg
->name
;
800 bsymnew
->flags
= bsymorg
->flags
& ~BSF_SECTION_SYM
;
801 bsymnew
->section
= bsymorg
->section
;
802 bfd_copy_private_symbol_data (bfd_asymbol_bfd (bsymorg
), bsymorg
,
803 bfd_asymbol_bfd (bsymnew
), bsymnew
);
805 #ifdef obj_symbol_clone_hook
806 obj_symbol_clone_hook (newsymP
, orgsymP
);
809 #ifdef tc_symbol_clone_hook
810 tc_symbol_clone_hook (newsymP
, orgsymP
);
815 if (symbol_rootP
== orgsymP
)
816 symbol_rootP
= newsymP
;
817 else if (orgsymP
->x
->previous
)
819 orgsymP
->x
->previous
->x
->next
= newsymP
;
820 orgsymP
->x
->previous
= NULL
;
822 if (symbol_lastP
== orgsymP
)
823 symbol_lastP
= newsymP
;
824 else if (orgsymP
->x
->next
)
825 orgsymP
->x
->next
->x
->previous
= newsymP
;
827 /* Symbols that won't be output can't be external. */
828 S_CLEAR_EXTERNAL (orgsymP
);
829 orgsymP
->x
->previous
= orgsymP
->x
->next
= orgsymP
;
830 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
832 symbol_table_insert (newsymP
);
836 /* Symbols that won't be output can't be external. */
837 S_CLEAR_EXTERNAL (newsymP
);
838 newsymP
->x
->previous
= newsymP
->x
->next
= newsymP
;
844 /* Referenced symbols, if they are forward references, need to be cloned
845 (without replacing the original) so that the value of the referenced
846 symbols at the point of use is saved by the clone. */
848 #undef symbol_clone_if_forward_ref
850 symbol_clone_if_forward_ref (symbolS
*symbolP
, int is_forward
)
853 && !symbolP
->flags
.local_symbol
854 && !symbolP
->flags
.forward_resolved
)
856 symbolS
*orig_add_symbol
= symbolP
->x
->value
.X_add_symbol
;
857 symbolS
*orig_op_symbol
= symbolP
->x
->value
.X_op_symbol
;
858 symbolS
*add_symbol
= orig_add_symbol
;
859 symbolS
*op_symbol
= orig_op_symbol
;
861 if (symbolP
->flags
.forward_ref
)
866 /* assign_symbol() clones volatile symbols; pre-existing expressions
867 hold references to the original instance, but want the current
868 value. Just repeat the lookup. */
869 if (add_symbol
&& S_IS_VOLATILE (add_symbol
))
870 add_symbol
= symbol_find_exact (S_GET_NAME (add_symbol
));
871 if (op_symbol
&& S_IS_VOLATILE (op_symbol
))
872 op_symbol
= symbol_find_exact (S_GET_NAME (op_symbol
));
875 /* Re-using resolving here, as this routine cannot get called from
876 symbol resolution code. */
877 if ((symbolP
->bsym
->section
== expr_section
878 || symbolP
->flags
.forward_ref
)
879 && !symbolP
->flags
.resolving
)
881 symbolP
->flags
.resolving
= 1;
882 add_symbol
= symbol_clone_if_forward_ref (add_symbol
, is_forward
);
883 op_symbol
= symbol_clone_if_forward_ref (op_symbol
, is_forward
);
884 symbolP
->flags
.resolving
= 0;
887 if (symbolP
->flags
.forward_ref
888 || add_symbol
!= orig_add_symbol
889 || op_symbol
!= orig_op_symbol
)
891 if (symbolP
!= &dot_symbol
)
893 symbolP
= symbol_clone (symbolP
, 0);
894 symbolP
->flags
.resolving
= 0;
898 symbolP
= symbol_temp_new_now ();
899 #ifdef tc_new_dot_label
900 tc_new_dot_label (symbolP
);
905 symbolP
->x
->value
.X_add_symbol
= add_symbol
;
906 symbolP
->x
->value
.X_op_symbol
= op_symbol
;
907 symbolP
->flags
.forward_resolved
= 1;
914 symbol_temp_new (segT seg
, fragS
*frag
, valueT ofs
)
916 return symbol_new (FAKE_LABEL_NAME
, seg
, frag
, ofs
);
920 symbol_temp_new_now (void)
922 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix ());
926 symbol_temp_new_now_octets (void)
928 return symbol_temp_new (now_seg
, frag_now
, frag_now_fix_octets ());
932 symbol_temp_make (void)
934 return symbol_make (FAKE_LABEL_NAME
);
937 /* Implement symbol table lookup.
938 In: A symbol's name as a string: '\0' can't be part of a symbol name.
939 Out: NULL if the name was not in the symbol table, else the address
940 of a struct symbol associated with that name. */
943 symbol_find_exact (const char *name
)
945 return symbol_find_exact_noref (name
, 0);
949 symbol_find_exact_noref (const char *name
, int noref
)
951 symbolS
*sym
= symbol_entry_find (sy_hash
, name
);
953 /* Any references to the symbol, except for the reference in
954 .weakref, must clear this flag, such that the symbol does not
955 turn into a weak symbol. Note that we don't have to handle the
956 local_symbol case, since a weakrefd is always promoted out of the
957 local_symbol table when it is turned into a weak symbol. */
959 S_CLEAR_WEAKREFD (sym
);
965 symbol_find (const char *name
)
967 return symbol_find_noref (name
, 0);
971 symbol_find_noref (const char *name
, int noref
)
976 #ifdef tc_canonicalize_symbol_name
978 copy
= xstrdup (name
);
979 name
= tc_canonicalize_symbol_name (copy
);
983 if (! symbols_case_sensitive
)
992 name
= copy
= XNEWVEC (char, strlen (name
) + 1);
994 while ((c
= *orig
++) != '\0')
995 *copy
++ = TOUPPER (c
);
999 copy
= (char *) name
;
1002 result
= symbol_find_exact_noref (name
, noref
);
1007 /* Once upon a time, symbols were kept in a singly linked list. At
1008 least coff needs to be able to rearrange them from time to time, for
1009 which a doubly linked list is much more convenient. Loic did these
1010 as macros which seemed dangerous to me so they're now functions.
1013 /* Link symbol ADDME after symbol TARGET in the chain. */
1016 symbol_append (symbolS
*addme
, symbolS
*target
,
1017 symbolS
**rootPP
, symbolS
**lastPP
)
1019 extern int symbol_table_frozen
;
1020 if (symbol_table_frozen
)
1022 if (addme
->flags
.local_symbol
)
1024 if (target
!= NULL
&& target
->flags
.local_symbol
)
1029 know (*rootPP
== NULL
);
1030 know (*lastPP
== NULL
);
1031 addme
->x
->next
= NULL
;
1032 addme
->x
->previous
= NULL
;
1036 } /* if the list is empty */
1038 if (target
->x
->next
!= NULL
)
1040 target
->x
->next
->x
->previous
= addme
;
1044 know (*lastPP
== target
);
1046 } /* if we have a next */
1048 addme
->x
->next
= target
->x
->next
;
1049 target
->x
->next
= addme
;
1050 addme
->x
->previous
= target
;
1052 debug_verify_symchain (symbol_rootP
, symbol_lastP
);
1055 /* Set the chain pointers of SYMBOL to null. */
1058 symbol_clear_list_pointers (symbolS
*symbolP
)
1060 if (symbolP
->flags
.local_symbol
)
1062 symbolP
->x
->next
= NULL
;
1063 symbolP
->x
->previous
= NULL
;
1066 /* Remove SYMBOLP from the list. */
1069 symbol_remove (symbolS
*symbolP
, symbolS
**rootPP
, symbolS
**lastPP
)
1071 if (symbolP
->flags
.local_symbol
)
1074 if (symbolP
== *rootPP
)
1076 *rootPP
= symbolP
->x
->next
;
1077 } /* if it was the root */
1079 if (symbolP
== *lastPP
)
1081 *lastPP
= symbolP
->x
->previous
;
1082 } /* if it was the tail */
1084 if (symbolP
->x
->next
!= NULL
)
1086 symbolP
->x
->next
->x
->previous
= symbolP
->x
->previous
;
1089 if (symbolP
->x
->previous
!= NULL
)
1091 symbolP
->x
->previous
->x
->next
= symbolP
->x
->next
;
1092 } /* if not first */
1094 debug_verify_symchain (*rootPP
, *lastPP
);
1097 /* Link symbol ADDME before symbol TARGET in the chain. */
1100 symbol_insert (symbolS
*addme
, symbolS
*target
,
1101 symbolS
**rootPP
, symbolS
**lastPP ATTRIBUTE_UNUSED
)
1103 extern int symbol_table_frozen
;
1104 if (symbol_table_frozen
)
1106 if (addme
->flags
.local_symbol
)
1108 if (target
->flags
.local_symbol
)
1111 if (target
->x
->previous
!= NULL
)
1113 target
->x
->previous
->x
->next
= addme
;
1117 know (*rootPP
== target
);
1119 } /* if not first */
1121 addme
->x
->previous
= target
->x
->previous
;
1122 target
->x
->previous
= addme
;
1123 addme
->x
->next
= target
;
1125 debug_verify_symchain (*rootPP
, *lastPP
);
1129 verify_symbol_chain (symbolS
*rootP
, symbolS
*lastP
)
1131 symbolS
*symbolP
= rootP
;
1133 if (symbolP
== NULL
)
1136 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
1138 gas_assert (symbolP
->bsym
!= NULL
);
1139 gas_assert (symbolP
->flags
.local_symbol
== 0);
1140 gas_assert (symbolP
->x
->next
->x
->previous
== symbolP
);
1143 gas_assert (lastP
== symbolP
);
1147 symbol_on_chain (symbolS
*s
, symbolS
*rootPP
, symbolS
*lastPP
)
1149 return (!s
->flags
.local_symbol
1150 && ((s
->x
->next
!= s
1151 && s
->x
->next
!= NULL
1152 && s
->x
->next
->x
->previous
== s
)
1154 && ((s
->x
->previous
!= s
1155 && s
->x
->previous
!= NULL
1156 && s
->x
->previous
->x
->next
== s
)
1160 #ifdef OBJ_COMPLEX_RELC
1163 use_complex_relocs_for (symbolS
* symp
)
1165 switch (symp
->x
->value
.X_op
)
1175 case O_bit_inclusive_or
:
1177 case O_bit_exclusive_or
:
1189 if ((S_IS_COMMON (symp
->x
->value
.X_op_symbol
)
1190 || S_IS_LOCAL (symp
->x
->value
.X_op_symbol
))
1191 && S_IS_DEFINED (symp
->x
->value
.X_op_symbol
)
1192 && S_GET_SEGMENT (symp
->x
->value
.X_op_symbol
) != expr_section
)
1199 if ((S_IS_COMMON (symp
->x
->value
.X_add_symbol
)
1200 || S_IS_LOCAL (symp
->x
->value
.X_add_symbol
))
1201 && S_IS_DEFINED (symp
->x
->value
.X_add_symbol
)
1202 && S_GET_SEGMENT (symp
->x
->value
.X_add_symbol
) != expr_section
)
1215 report_op_error (symbolS
*symp
, symbolS
*left
, operatorT op
, symbolS
*right
)
1219 segT seg_left
= left
? S_GET_SEGMENT (left
) : 0;
1220 segT seg_right
= S_GET_SEGMENT (right
);
1229 case O_uminus
: opname
= "-"; break;
1230 case O_bit_not
: opname
= "~"; break;
1231 case O_logical_not
: opname
= "!"; break;
1232 case O_multiply
: opname
= "*"; break;
1233 case O_divide
: opname
= "/"; break;
1234 case O_modulus
: opname
= "%"; break;
1235 case O_left_shift
: opname
= "<<"; break;
1236 case O_right_shift
: opname
= ">>"; break;
1237 case O_bit_inclusive_or
: opname
= "|"; break;
1238 case O_bit_or_not
: opname
= "|~"; break;
1239 case O_bit_exclusive_or
: opname
= "^"; break;
1240 case O_bit_and
: opname
= "&"; break;
1241 case O_add
: opname
= "+"; break;
1242 case O_subtract
: opname
= "-"; break;
1243 case O_eq
: opname
= "=="; break;
1244 case O_ne
: opname
= "!="; break;
1245 case O_lt
: opname
= "<"; break;
1246 case O_le
: opname
= "<="; break;
1247 case O_ge
: opname
= ">="; break;
1248 case O_gt
: opname
= ">"; break;
1249 case O_logical_and
: opname
= "&&"; break;
1250 case O_logical_or
: opname
= "||"; break;
1253 if (expr_symbol_where (symp
, &file
, &line
))
1256 as_bad_where (file
, line
,
1257 _("invalid operands (%s and %s sections) for `%s'"),
1258 seg_left
->name
, seg_right
->name
, opname
);
1260 as_bad_where (file
, line
,
1261 _("invalid operand (%s section) for `%s'"),
1262 seg_right
->name
, opname
);
1266 const char *sname
= S_GET_NAME (symp
);
1269 as_bad (_("invalid operands (%s and %s sections) for `%s' when setting `%s'"),
1270 seg_left
->name
, seg_right
->name
, opname
, sname
);
1272 as_bad (_("invalid operand (%s section) for `%s' when setting `%s'"),
1273 seg_right
->name
, opname
, sname
);
1277 /* Resolve the value of a symbol. This is called during the final
1278 pass over the symbol table to resolve any symbols with complex
1282 resolve_symbol_value (symbolS
*symp
)
1288 if (symp
->flags
.local_symbol
)
1290 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1292 final_val
= locsym
->value
;
1293 if (locsym
->flags
.resolved
)
1296 /* Symbols whose section has SEC_ELF_OCTETS set,
1297 resolve to octets instead of target bytes. */
1298 if (locsym
->section
->flags
& SEC_OCTETS
)
1299 final_val
+= locsym
->frag
->fr_address
;
1301 final_val
+= locsym
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1305 locsym
->value
= final_val
;
1306 locsym
->flags
.resolved
= 1;
1312 if (symp
->flags
.resolved
)
1315 while (symp
->x
->value
.X_op
== O_symbol
)
1317 final_val
+= symp
->x
->value
.X_add_number
;
1318 symp
= symp
->x
->value
.X_add_symbol
;
1319 if (symp
->flags
.local_symbol
)
1321 struct local_symbol
*locsym
= (struct local_symbol
*) symp
;
1322 final_val
+= locsym
->value
;
1325 if (!symp
->flags
.resolved
)
1328 if (symp
->x
->value
.X_op
== O_constant
)
1329 final_val
+= symp
->x
->value
.X_add_number
;
1336 final_seg
= S_GET_SEGMENT (symp
);
1338 if (symp
->flags
.resolving
)
1341 as_bad (_("symbol definition loop encountered at `%s'"),
1346 #ifdef OBJ_COMPLEX_RELC
1347 else if (final_seg
== expr_section
1348 && use_complex_relocs_for (symp
))
1350 symbolS
* relc_symbol
= NULL
;
1351 char * relc_symbol_name
= NULL
;
1353 relc_symbol_name
= symbol_relc_make_expr (& symp
->x
->value
);
1355 /* For debugging, print out conversion input & output. */
1357 print_expr (& symp
->x
->value
);
1358 if (relc_symbol_name
)
1359 fprintf (stderr
, "-> relc symbol: %s\n", relc_symbol_name
);
1362 if (relc_symbol_name
!= NULL
)
1363 relc_symbol
= symbol_new (relc_symbol_name
, undefined_section
,
1364 &zero_address_frag
, 0);
1366 if (relc_symbol
== NULL
)
1368 as_bad (_("cannot convert expression symbol %s to complex relocation"),
1374 symbol_table_insert (relc_symbol
);
1376 /* S_CLEAR_EXTERNAL (relc_symbol); */
1377 if (symp
->bsym
->flags
& BSF_SRELC
)
1378 relc_symbol
->bsym
->flags
|= BSF_SRELC
;
1380 relc_symbol
->bsym
->flags
|= BSF_RELC
;
1381 /* symp->bsym->flags |= BSF_RELC; */
1382 copy_symbol_attributes (symp
, relc_symbol
);
1383 symp
->x
->value
.X_op
= O_symbol
;
1384 symp
->x
->value
.X_add_symbol
= relc_symbol
;
1385 symp
->x
->value
.X_add_number
= 0;
1390 final_seg
= undefined_section
;
1391 goto exit_dont_set_value
;
1396 symbolS
*add_symbol
, *op_symbol
;
1397 offsetT left
, right
;
1398 segT seg_left
, seg_right
;
1402 symp
->flags
.resolving
= 1;
1404 /* Help out with CSE. */
1405 add_symbol
= symp
->x
->value
.X_add_symbol
;
1406 op_symbol
= symp
->x
->value
.X_op_symbol
;
1407 final_val
= symp
->x
->value
.X_add_number
;
1408 op
= symp
->x
->value
.X_op
;
1448 #ifdef md_resolve_symbol
1449 resolved
= md_resolve_symbol (symp
, &final_val
, &final_seg
);
1453 goto exit_dont_set_value
;
1460 /* Symbols whose section has SEC_ELF_OCTETS set,
1461 resolve to octets instead of target bytes. */
1462 if (symp
->bsym
->section
->flags
& SEC_OCTETS
)
1463 final_val
+= symp
->frag
->fr_address
;
1465 final_val
+= symp
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1466 if (final_seg
== expr_section
)
1467 final_seg
= absolute_section
;
1477 left
= resolve_symbol_value (add_symbol
);
1478 seg_left
= S_GET_SEGMENT (add_symbol
);
1480 symp
->x
->value
.X_op_symbol
= NULL
;
1483 if (S_IS_WEAKREFR (symp
))
1485 gas_assert (final_val
== 0);
1486 if (S_IS_WEAKREFR (add_symbol
))
1488 gas_assert (add_symbol
->x
->value
.X_op
== O_symbol
1489 && add_symbol
->x
->value
.X_add_number
== 0);
1490 add_symbol
= add_symbol
->x
->value
.X_add_symbol
;
1491 gas_assert (! S_IS_WEAKREFR (add_symbol
));
1492 symp
->x
->value
.X_add_symbol
= add_symbol
;
1496 if (symp
->flags
.mri_common
)
1498 /* This is a symbol inside an MRI common section. The
1499 relocation routines are going to handle it specially.
1500 Don't change the value. */
1501 resolved
= symbol_resolved_p (add_symbol
);
1505 /* Don't leave symbol loops. */
1507 && !add_symbol
->flags
.local_symbol
1508 && add_symbol
->flags
.resolving
)
1511 if (finalize_syms
&& final_val
== 0
1513 /* Avoid changing symp's "within" when dealing with
1514 AIX debug symbols. For some storage classes, "within"
1515 have a special meaning.
1516 C_DWARF should behave like on Linux, thus this check
1517 isn't done to be closer. */
1518 && ((symbol_get_bfdsym (symp
)->flags
& BSF_DEBUGGING
) == 0
1519 || (S_GET_STORAGE_CLASS (symp
) == C_DWARF
))
1523 if (add_symbol
->flags
.local_symbol
)
1524 add_symbol
= local_symbol_convert (add_symbol
);
1525 copy_symbol_attributes (symp
, add_symbol
);
1528 /* If we have equated this symbol to an undefined or common
1529 symbol, keep X_op set to O_symbol, and don't change
1530 X_add_number. This permits the routine which writes out
1531 relocation to detect this case, and convert the
1532 relocation to be against the symbol to which this symbol
1534 if (seg_left
== undefined_section
1535 || bfd_is_com_section (seg_left
)
1536 #if defined (OBJ_COFF) && defined (TE_PE)
1537 || S_IS_WEAK (add_symbol
)
1540 && ((final_seg
== expr_section
1541 && seg_left
!= expr_section
1542 && seg_left
!= absolute_section
)
1543 || symbol_shadow_p (symp
))))
1547 symp
->x
->value
.X_op
= O_symbol
;
1548 symp
->x
->value
.X_add_symbol
= add_symbol
;
1549 symp
->x
->value
.X_add_number
= final_val
;
1550 /* Use X_op_symbol as a flag. */
1551 symp
->x
->value
.X_op_symbol
= add_symbol
;
1553 final_seg
= seg_left
;
1554 final_val
+= symp
->frag
->fr_address
+ left
;
1555 resolved
= symbol_resolved_p (add_symbol
);
1556 symp
->flags
.resolving
= 0;
1558 if (op
== O_secidx
&& seg_left
!= undefined_section
)
1564 goto exit_dont_set_value
;
1568 final_val
+= symp
->frag
->fr_address
+ left
;
1569 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1570 final_seg
= seg_left
;
1573 resolved
= symbol_resolved_p (add_symbol
);
1574 if (S_IS_WEAKREFR (symp
))
1576 symp
->flags
.resolving
= 0;
1577 goto exit_dont_set_value
;
1584 left
= resolve_symbol_value (add_symbol
);
1585 seg_left
= S_GET_SEGMENT (add_symbol
);
1587 /* By reducing these to the relevant dyadic operator, we get
1588 !S -> S == 0 permitted on anything,
1589 -S -> 0 - S only permitted on absolute
1590 ~S -> S ^ ~0 only permitted on absolute */
1591 if (op
!= O_logical_not
&& seg_left
!= absolute_section
1593 report_op_error (symp
, NULL
, op
, add_symbol
);
1595 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1596 final_seg
= absolute_section
;
1600 else if (op
== O_logical_not
)
1605 final_val
+= left
+ symp
->frag
->fr_address
;
1607 resolved
= symbol_resolved_p (add_symbol
);
1615 case O_bit_inclusive_or
:
1617 case O_bit_exclusive_or
:
1629 left
= resolve_symbol_value (add_symbol
);
1630 right
= resolve_symbol_value (op_symbol
);
1631 seg_left
= S_GET_SEGMENT (add_symbol
);
1632 seg_right
= S_GET_SEGMENT (op_symbol
);
1634 /* Simplify addition or subtraction of a constant by folding the
1635 constant into X_add_number. */
1638 if (seg_right
== absolute_section
)
1643 else if (seg_left
== absolute_section
)
1646 add_symbol
= op_symbol
;
1648 seg_left
= seg_right
;
1652 else if (op
== O_subtract
)
1654 if (seg_right
== absolute_section
)
1662 /* Equality and non-equality tests are permitted on anything.
1663 Subtraction, and other comparison operators are permitted if
1664 both operands are in the same section. Otherwise, both
1665 operands must be absolute. We already handled the case of
1666 addition or subtraction of a constant above. This will
1667 probably need to be changed for an object file format which
1668 supports arbitrary expressions. */
1669 if (!(seg_left
== absolute_section
1670 && seg_right
== absolute_section
)
1671 && !(op
== O_eq
|| op
== O_ne
)
1672 && !((op
== O_subtract
1673 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
1674 && seg_left
== seg_right
1675 && (seg_left
!= undefined_section
1676 || add_symbol
== op_symbol
)))
1678 /* Don't emit messages unless we're finalizing the symbol value,
1679 otherwise we may get the same message multiple times. */
1681 report_op_error (symp
, add_symbol
, op
, op_symbol
);
1682 /* However do not move the symbol into the absolute section
1683 if it cannot currently be resolved - this would confuse
1684 other parts of the assembler into believing that the
1685 expression had been evaluated to zero. */
1691 && (final_seg
== expr_section
|| final_seg
== undefined_section
))
1692 final_seg
= absolute_section
;
1694 /* Check for division by zero. */
1695 if ((op
== O_divide
|| op
== O_modulus
) && right
== 0)
1697 /* If seg_right is not absolute_section, then we've
1698 already issued a warning about using a bad symbol. */
1699 if (seg_right
== absolute_section
&& finalize_syms
)
1704 if (expr_symbol_where (symp
, &file
, &line
))
1705 as_bad_where (file
, line
, _("division by zero"));
1707 as_bad (_("division by zero when setting `%s'"),
1713 if ((op
== O_left_shift
|| op
== O_right_shift
)
1714 && (valueT
) right
>= sizeof (valueT
) * CHAR_BIT
)
1716 as_warn_value_out_of_range (_("shift count"), right
, 0,
1717 sizeof (valueT
) * CHAR_BIT
- 1,
1722 switch (symp
->x
->value
.X_op
)
1724 case O_multiply
: left
*= right
; break;
1725 case O_divide
: left
/= right
; break;
1726 case O_modulus
: left
%= right
; break;
1728 left
= (valueT
) left
<< (valueT
) right
; break;
1730 left
= (valueT
) left
>> (valueT
) right
; break;
1731 case O_bit_inclusive_or
: left
|= right
; break;
1732 case O_bit_or_not
: left
|= ~right
; break;
1733 case O_bit_exclusive_or
: left
^= right
; break;
1734 case O_bit_and
: left
&= right
; break;
1735 case O_add
: left
+= right
; break;
1736 case O_subtract
: left
-= right
; break;
1739 left
= (left
== right
&& seg_left
== seg_right
1740 && (seg_left
!= undefined_section
1741 || add_symbol
== op_symbol
)
1742 ? ~ (offsetT
) 0 : 0);
1743 if (symp
->x
->value
.X_op
== O_ne
)
1746 case O_lt
: left
= left
< right
? ~ (offsetT
) 0 : 0; break;
1747 case O_le
: left
= left
<= right
? ~ (offsetT
) 0 : 0; break;
1748 case O_ge
: left
= left
>= right
? ~ (offsetT
) 0 : 0; break;
1749 case O_gt
: left
= left
> right
? ~ (offsetT
) 0 : 0; break;
1750 case O_logical_and
: left
= left
&& right
; break;
1751 case O_logical_or
: left
= left
|| right
; break;
1756 /* See PR 20895 for a reproducer. */
1757 as_bad (_("Invalid operation on symbol"));
1758 goto exit_dont_set_value
;
1764 final_val
+= symp
->frag
->fr_address
+ left
;
1765 if (final_seg
== expr_section
|| final_seg
== undefined_section
)
1767 if (seg_left
== undefined_section
1768 || seg_right
== undefined_section
)
1769 final_seg
= undefined_section
;
1770 else if (seg_left
== absolute_section
)
1771 final_seg
= seg_right
;
1773 final_seg
= seg_left
;
1775 resolved
= (symbol_resolved_p (add_symbol
)
1776 && symbol_resolved_p (op_symbol
));
1781 /* Give an error (below) if not in expr_section. We don't
1782 want to worry about expr_section symbols, because they
1783 are fictional (they are created as part of expression
1784 resolution), and any problems may not actually mean
1789 symp
->flags
.resolving
= 0;
1793 S_SET_VALUE (symp
, final_val
);
1795 exit_dont_set_value
:
1796 /* Always set the segment, even if not finalizing the value.
1797 The segment is used to determine whether a symbol is defined. */
1798 S_SET_SEGMENT (symp
, final_seg
);
1800 /* Don't worry if we can't resolve an expr_section symbol. */
1804 symp
->flags
.resolved
= 1;
1805 else if (S_GET_SEGMENT (symp
) != expr_section
)
1807 as_bad (_("can't resolve value for symbol `%s'"),
1809 symp
->flags
.resolved
= 1;
1816 /* A static function passed to hash_traverse. */
1819 resolve_local_symbol (void **slot
, void *arg ATTRIBUTE_UNUSED
)
1821 symbol_entry_t
*entry
= *((symbol_entry_t
**) slot
);
1822 if (entry
->sy
.flags
.local_symbol
)
1823 resolve_symbol_value (&entry
->sy
);
1828 /* Resolve all local symbols. */
1831 resolve_local_symbol_values (void)
1833 htab_traverse_noresize (sy_hash
, resolve_local_symbol
, NULL
);
1836 /* Obtain the current value of a symbol without changing any
1837 sub-expressions used. */
1840 snapshot_symbol (symbolS
**symbolPP
, valueT
*valueP
, segT
*segP
, fragS
**fragPP
)
1842 symbolS
*symbolP
= *symbolPP
;
1844 if (symbolP
->flags
.local_symbol
)
1846 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1848 *valueP
= locsym
->value
;
1849 *segP
= locsym
->section
;
1850 *fragPP
= locsym
->frag
;
1854 expressionS exp
= symbolP
->x
->value
;
1856 if (!symbolP
->flags
.resolved
&& exp
.X_op
!= O_illegal
)
1860 if (symbolP
->flags
.resolving
)
1862 symbolP
->flags
.resolving
= 1;
1863 resolved
= resolve_expression (&exp
);
1864 symbolP
->flags
.resolving
= 0;
1872 if (!symbol_equated_p (symbolP
))
1877 symbolP
= exp
.X_add_symbol
;
1884 *symbolPP
= symbolP
;
1886 /* A bogus input file can result in resolve_expression()
1887 generating a local symbol, so we have to check again. */
1888 if (symbolP
->flags
.local_symbol
)
1890 struct local_symbol
*locsym
= (struct local_symbol
*) symbolP
;
1892 *valueP
= locsym
->value
;
1893 *segP
= locsym
->section
;
1894 *fragPP
= locsym
->frag
;
1898 *valueP
= exp
.X_add_number
;
1899 *segP
= symbolP
->bsym
->section
;
1900 *fragPP
= symbolP
->frag
;
1903 if (*segP
== expr_section
)
1906 case O_constant
: *segP
= absolute_section
; break;
1907 case O_register
: *segP
= reg_section
; break;
1915 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1916 They are *really* local. That is, they go out of scope whenever we see a
1917 label that isn't local. Also, like fb labels, there can be multiple
1918 instances of a dollar label. Therefor, we name encode each instance with
1919 the instance number, keep a list of defined symbols separate from the real
1920 symbol table, and we treat these buggers as a sparse array. */
1922 typedef unsigned int dollar_ent
;
1923 static dollar_ent
*dollar_labels
;
1924 static dollar_ent
*dollar_label_instances
;
1925 static char *dollar_label_defines
;
1926 static size_t dollar_label_count
;
1927 static size_t dollar_label_max
;
1930 dollar_label_defined (unsigned int label
)
1934 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1936 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1938 return dollar_label_defines
[i
- dollar_labels
];
1940 /* If we get here, label isn't defined. */
1945 dollar_label_instance (unsigned int label
)
1949 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
1951 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1953 return (dollar_label_instances
[i
- dollar_labels
]);
1955 /* If we get here, we haven't seen the label before.
1956 Therefore its instance count is zero. */
1961 dollar_label_clear (void)
1963 if (dollar_label_count
)
1964 memset (dollar_label_defines
, '\0', dollar_label_count
);
1967 #define DOLLAR_LABEL_BUMP_BY 10
1970 define_dollar_label (unsigned int label
)
1974 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
1977 ++dollar_label_instances
[i
- dollar_labels
];
1978 dollar_label_defines
[i
- dollar_labels
] = 1;
1982 /* If we get to here, we don't have label listed yet. */
1984 if (dollar_labels
== NULL
)
1986 dollar_labels
= XNEWVEC (dollar_ent
, DOLLAR_LABEL_BUMP_BY
);
1987 dollar_label_instances
= XNEWVEC (dollar_ent
, DOLLAR_LABEL_BUMP_BY
);
1988 dollar_label_defines
= XNEWVEC (char, DOLLAR_LABEL_BUMP_BY
);
1989 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
1990 dollar_label_count
= 0;
1992 else if (dollar_label_count
== dollar_label_max
)
1994 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
1995 dollar_labels
= XRESIZEVEC (dollar_ent
, dollar_labels
,
1997 dollar_label_instances
= XRESIZEVEC (dollar_ent
,
1998 dollar_label_instances
,
2000 dollar_label_defines
= XRESIZEVEC (char, dollar_label_defines
,
2002 } /* if we needed to grow */
2004 dollar_labels
[dollar_label_count
] = label
;
2005 dollar_label_instances
[dollar_label_count
] = 1;
2006 dollar_label_defines
[dollar_label_count
] = 1;
2007 ++dollar_label_count
;
2010 /* Caller must copy returned name: we re-use the area for the next name.
2012 The mth occurrence of label n: is turned into the symbol "Ln^Am"
2013 where n is the label number and m is the instance number. "L" makes
2014 it a label discarded unless debugging and "^A"('\1') ensures no
2015 ordinary symbol SHOULD get the same name as a local label
2016 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
2018 fb labels get the same treatment, except that ^B is used in place
2021 AUGEND is 0 for current instance, 1 for new instance. */
2024 dollar_label_name (unsigned int n
, unsigned int augend
)
2026 /* Returned to caller, then copied. Used for created names ("4f"). */
2027 static char symbol_name_build
[24];
2028 char *p
= symbol_name_build
;
2030 #ifdef LOCAL_LABEL_PREFIX
2031 *p
++ = LOCAL_LABEL_PREFIX
;
2033 sprintf (p
, "L%u%c%u",
2034 n
, DOLLAR_LABEL_CHAR
, dollar_label_instance (n
) + augend
);
2035 return symbol_name_build
;
2038 /* Somebody else's idea of local labels. They are made by "n:" where n
2039 is any decimal digit. Refer to them with
2040 "nb" for previous (backward) n:
2041 or "nf" for next (forward) n:.
2043 We do a little better and let n be any number, not just a single digit, but
2044 since the other guy's assembler only does ten, we treat the first ten
2047 Like someone else's assembler, we have one set of local label counters for
2048 entire assembly, not one set per (sub)segment like in most assemblers. This
2049 implies that one can refer to a label in another segment, and indeed some
2050 crufty compilers have done just that.
2052 Since there could be a LOT of these things, treat them as a sparse
2055 #define FB_LABEL_SPECIAL (10)
2057 typedef unsigned int fb_ent
;
2058 static fb_ent fb_low_counter
[FB_LABEL_SPECIAL
];
2059 static fb_ent
*fb_labels
;
2060 static fb_ent
*fb_label_instances
;
2061 static size_t fb_label_count
;
2062 static size_t fb_label_max
;
2064 /* This must be more than FB_LABEL_SPECIAL. */
2065 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
2068 fb_label_init (void)
2070 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
2073 /* Add one to the instance number of this fb label. */
2076 fb_label_instance_inc (unsigned int label
)
2080 if (label
< FB_LABEL_SPECIAL
)
2082 ++fb_low_counter
[label
];
2086 if (fb_labels
!= NULL
)
2088 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2089 i
< fb_labels
+ fb_label_count
; ++i
)
2093 ++fb_label_instances
[i
- fb_labels
];
2095 } /* if we find it */
2096 } /* for each existing label */
2099 /* If we get to here, we don't have label listed yet. */
2101 if (fb_labels
== NULL
)
2103 fb_labels
= XNEWVEC (fb_ent
, FB_LABEL_BUMP_BY
);
2104 fb_label_instances
= XNEWVEC (fb_ent
, FB_LABEL_BUMP_BY
);
2105 fb_label_max
= FB_LABEL_BUMP_BY
;
2106 fb_label_count
= FB_LABEL_SPECIAL
;
2109 else if (fb_label_count
== fb_label_max
)
2111 fb_label_max
+= FB_LABEL_BUMP_BY
;
2112 fb_labels
= XRESIZEVEC (fb_ent
, fb_labels
, fb_label_max
);
2113 fb_label_instances
= XRESIZEVEC (fb_ent
, fb_label_instances
,
2115 } /* if we needed to grow */
2117 fb_labels
[fb_label_count
] = label
;
2118 fb_label_instances
[fb_label_count
] = 1;
2123 fb_label_instance (unsigned int label
)
2127 if (label
< FB_LABEL_SPECIAL
)
2128 return (fb_low_counter
[label
]);
2130 if (fb_labels
!= NULL
)
2132 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
2133 i
< fb_labels
+ fb_label_count
; ++i
)
2136 return (fb_label_instances
[i
- fb_labels
]);
2140 /* We didn't find the label, so this must be a reference to the
2145 /* Caller must copy returned name: we re-use the area for the next name.
2147 The mth occurrence of label n: is turned into the symbol "Ln^Bm"
2148 where n is the label number and m is the instance number. "L" makes
2149 it a label discarded unless debugging and "^B"('\2') ensures no
2150 ordinary symbol SHOULD get the same name as a local label
2151 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
2153 dollar labels get the same treatment, except that ^A is used in
2156 AUGEND is 0 for nb, 1 for n:, nf. */
2159 fb_label_name (unsigned int n
, unsigned int augend
)
2161 /* Returned to caller, then copied. Used for created names ("4f"). */
2162 static char symbol_name_build
[24];
2163 char *p
= symbol_name_build
;
2166 know (augend
<= 2 /* See mmix_fb_label. */);
2171 #ifdef LOCAL_LABEL_PREFIX
2172 *p
++ = LOCAL_LABEL_PREFIX
;
2174 sprintf (p
, "L%u%c%u",
2175 n
, LOCAL_LABEL_CHAR
, fb_label_instance (n
) + augend
);
2176 return symbol_name_build
;
2179 /* Decode name that may have been generated by foo_label_name() above.
2180 If the name wasn't generated by foo_label_name(), then return it
2181 unaltered. This is used for error messages. */
2184 decode_local_label_name (char *s
)
2187 char *symbol_decode
;
2189 int instance_number
;
2191 const char *message_format
;
2194 #ifdef LOCAL_LABEL_PREFIX
2195 if (s
[lindex
] == LOCAL_LABEL_PREFIX
)
2199 if (s
[lindex
] != 'L')
2202 for (label_number
= 0, p
= s
+ lindex
+ 1; ISDIGIT (*p
); ++p
)
2203 label_number
= (10 * label_number
) + *p
- '0';
2205 if (*p
== DOLLAR_LABEL_CHAR
)
2207 else if (*p
== LOCAL_LABEL_CHAR
)
2212 for (instance_number
= 0, p
++; ISDIGIT (*p
); ++p
)
2213 instance_number
= (10 * instance_number
) + *p
- '0';
2215 message_format
= _("\"%d\" (instance number %d of a %s label)");
2216 symbol_decode
= notes_alloc (strlen (message_format
) + 30);
2217 sprintf (symbol_decode
, message_format
, label_number
, instance_number
, type
);
2219 return symbol_decode
;
2222 /* Get the value of a symbol. */
2225 S_GET_VALUE_WHERE (symbolS
*s
, const char * file
, unsigned int line
)
2227 if (s
->flags
.local_symbol
)
2228 return resolve_symbol_value (s
);
2230 if (!s
->flags
.resolved
)
2232 valueT val
= resolve_symbol_value (s
);
2236 if (S_IS_WEAKREFR (s
))
2237 return S_GET_VALUE (s
->x
->value
.X_add_symbol
);
2239 if (s
->x
->value
.X_op
!= O_constant
)
2241 if (! s
->flags
.resolved
2242 || s
->x
->value
.X_op
!= O_symbol
2243 || (S_IS_DEFINED (s
) && ! S_IS_COMMON (s
)))
2245 if (strcmp (S_GET_NAME (s
), FAKE_LABEL_NAME
) == 0)
2246 as_bad_where (file
, line
, _("expression is too complex to be resolved or converted into relocations"));
2247 else if (file
!= NULL
)
2248 as_bad_where (file
, line
, _("attempt to get value of unresolved symbol `%s'"),
2251 as_bad (_("attempt to get value of unresolved symbol `%s'"),
2255 return (valueT
) s
->x
->value
.X_add_number
;
2259 S_GET_VALUE (symbolS
*s
)
2261 return S_GET_VALUE_WHERE (s
, NULL
, 0);
2264 /* Set the value of a symbol. */
2267 S_SET_VALUE (symbolS
*s
, valueT val
)
2269 if (s
->flags
.local_symbol
)
2271 ((struct local_symbol
*) s
)->value
= val
;
2275 s
->x
->value
.X_op
= O_constant
;
2276 s
->x
->value
.X_add_number
= (offsetT
) val
;
2277 s
->x
->value
.X_unsigned
= 0;
2278 S_CLEAR_WEAKREFR (s
);
2282 copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2284 if (dest
->flags
.local_symbol
)
2285 dest
= local_symbol_convert (dest
);
2286 if (src
->flags
.local_symbol
)
2287 src
= local_symbol_convert (src
);
2289 /* In an expression, transfer the settings of these flags.
2290 The user can override later, of course. */
2291 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT \
2292 | BSF_GNU_INDIRECT_FUNCTION)
2293 dest
->bsym
->flags
|= src
->bsym
->flags
& COPIED_SYMFLAGS
;
2295 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
2296 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2299 #ifdef TC_COPY_SYMBOL_ATTRIBUTES
2300 TC_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
2305 S_IS_FUNCTION (const symbolS
*s
)
2309 if (s
->flags
.local_symbol
)
2312 flags
= s
->bsym
->flags
;
2314 return (flags
& BSF_FUNCTION
) != 0;
2318 S_IS_EXTERNAL (const symbolS
*s
)
2322 if (s
->flags
.local_symbol
)
2325 flags
= s
->bsym
->flags
;
2328 if ((flags
& BSF_LOCAL
) && (flags
& BSF_GLOBAL
))
2331 return (flags
& BSF_GLOBAL
) != 0;
2335 S_IS_WEAK (const symbolS
*s
)
2337 if (s
->flags
.local_symbol
)
2339 /* Conceptually, a weakrefr is weak if the referenced symbol is. We
2340 could probably handle a WEAKREFR as always weak though. E.g., if
2341 the referenced symbol has lost its weak status, there's no reason
2342 to keep handling the weakrefr as if it was weak. */
2343 if (S_IS_WEAKREFR (s
))
2344 return S_IS_WEAK (s
->x
->value
.X_add_symbol
);
2345 return (s
->bsym
->flags
& BSF_WEAK
) != 0;
2349 S_IS_WEAKREFR (const symbolS
*s
)
2351 if (s
->flags
.local_symbol
)
2353 return s
->flags
.weakrefr
!= 0;
2357 S_IS_WEAKREFD (const symbolS
*s
)
2359 if (s
->flags
.local_symbol
)
2361 return s
->flags
.weakrefd
!= 0;
2365 S_IS_COMMON (const symbolS
*s
)
2367 if (s
->flags
.local_symbol
)
2369 return bfd_is_com_section (s
->bsym
->section
);
2373 S_IS_DEFINED (const symbolS
*s
)
2375 if (s
->flags
.local_symbol
)
2376 return ((struct local_symbol
*) s
)->section
!= undefined_section
;
2377 return s
->bsym
->section
!= undefined_section
;
2381 #ifndef EXTERN_FORCE_RELOC
2382 #define EXTERN_FORCE_RELOC IS_ELF
2385 /* Return true for symbols that should not be reduced to section
2386 symbols or eliminated from expressions, because they may be
2387 overridden by the linker. */
2389 S_FORCE_RELOC (const symbolS
*s
, int strict
)
2392 if (s
->flags
.local_symbol
)
2393 sec
= ((struct local_symbol
*) s
)->section
;
2397 && ((s
->bsym
->flags
& BSF_WEAK
) != 0
2398 || (EXTERN_FORCE_RELOC
2399 && (s
->bsym
->flags
& BSF_GLOBAL
) != 0)))
2400 || (s
->bsym
->flags
& BSF_GNU_INDIRECT_FUNCTION
) != 0)
2402 sec
= s
->bsym
->section
;
2404 return bfd_is_und_section (sec
) || bfd_is_com_section (sec
);
2408 S_IS_DEBUG (const symbolS
*s
)
2410 if (s
->flags
.local_symbol
)
2412 if (s
->bsym
->flags
& BSF_DEBUGGING
)
2418 S_IS_LOCAL (const symbolS
*s
)
2423 if (s
->flags
.local_symbol
)
2426 if (S_IS_EXTERNAL (s
))
2429 if (bfd_asymbol_section (s
->bsym
) == reg_section
)
2432 flags
= s
->bsym
->flags
;
2434 if (flag_strip_local_absolute
2435 /* Keep BSF_FILE symbols in order to allow debuggers to identify
2436 the source file even when the object file is stripped. */
2437 && (flags
& (BSF_GLOBAL
| BSF_FILE
)) == 0
2438 && bfd_asymbol_section (s
->bsym
) == absolute_section
)
2441 name
= S_GET_NAME (s
);
2442 return (name
!= NULL
2444 && (strchr (name
, DOLLAR_LABEL_CHAR
)
2445 || strchr (name
, LOCAL_LABEL_CHAR
)
2446 #if FAKE_LABEL_CHAR != DOLLAR_LABEL_CHAR
2447 || strchr (name
, FAKE_LABEL_CHAR
)
2449 || TC_LABEL_IS_LOCAL (name
)
2450 || (! flag_keep_locals
2451 && (bfd_is_local_label (stdoutput
, s
->bsym
)
2454 && name
[1] == '?')))));
2458 S_IS_STABD (const symbolS
*s
)
2460 return S_GET_NAME (s
) == 0;
2464 S_CAN_BE_REDEFINED (const symbolS
*s
)
2466 if (s
->flags
.local_symbol
)
2467 return (((struct local_symbol
*) s
)->frag
2468 == &predefined_address_frag
);
2469 /* Permit register names to be redefined. */
2470 return s
->x
->value
.X_op
== O_register
;
2474 S_IS_VOLATILE (const symbolS
*s
)
2476 if (s
->flags
.local_symbol
)
2478 return s
->flags
.volatil
;
2482 S_IS_FORWARD_REF (const symbolS
*s
)
2484 if (s
->flags
.local_symbol
)
2486 return s
->flags
.forward_ref
;
2490 S_GET_NAME (const symbolS
*s
)
2496 S_GET_SEGMENT (const symbolS
*s
)
2498 if (s
->flags
.local_symbol
)
2499 return ((struct local_symbol
*) s
)->section
;
2500 return s
->bsym
->section
;
2504 S_SET_SEGMENT (symbolS
*s
, segT seg
)
2506 if (s
->flags
.local_symbol
)
2508 ((struct local_symbol
*) s
)->section
= seg
;
2512 /* Don't reassign section symbols. The direct reason is to prevent seg
2513 faults assigning back to const global symbols such as *ABS*, but it
2514 shouldn't happen anyway. */
2515 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2517 if (s
->bsym
->section
!= seg
)
2522 if (multibyte_handling
== multibyte_warn_syms
2523 && ! s
->flags
.local_symbol
2524 && seg
!= undefined_section
2525 && ! s
->flags
.multibyte_warned
2526 && scan_for_multibyte_characters ((const unsigned char *) s
->name
,
2527 (const unsigned char *) s
->name
+ strlen (s
->name
),
2530 as_warn (_("symbol '%s' contains multibyte characters"), s
->name
);
2531 s
->flags
.multibyte_warned
= 1;
2534 s
->bsym
->section
= seg
;
2539 S_SET_EXTERNAL (symbolS
*s
)
2541 if (s
->flags
.local_symbol
)
2542 s
= local_symbol_convert (s
);
2543 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2545 /* Let .weak override .global. */
2548 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
2550 /* Do not reassign section symbols. */
2551 as_warn (_("can't make section symbol global"));
2554 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
2555 if (S_GET_SEGMENT (s
) == reg_section
)
2557 as_bad (_("can't make register symbol global"));
2561 s
->bsym
->flags
|= BSF_GLOBAL
;
2562 s
->bsym
->flags
&= ~(BSF_LOCAL
| BSF_WEAK
);
2565 if (! an_external_name
&& S_GET_NAME(s
)[0] != '.')
2566 an_external_name
= S_GET_NAME (s
);
2571 S_CLEAR_EXTERNAL (symbolS
*s
)
2573 if (s
->flags
.local_symbol
)
2575 if ((s
->bsym
->flags
& BSF_WEAK
) != 0)
2577 /* Let .weak override. */
2580 s
->bsym
->flags
|= BSF_LOCAL
;
2581 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_WEAK
);
2585 S_SET_WEAK (symbolS
*s
)
2587 if (s
->flags
.local_symbol
)
2588 s
= local_symbol_convert (s
);
2589 #ifdef obj_set_weak_hook
2590 obj_set_weak_hook (s
);
2592 s
->bsym
->flags
|= BSF_WEAK
;
2593 s
->bsym
->flags
&= ~(BSF_GLOBAL
| BSF_LOCAL
);
2597 S_SET_WEAKREFR (symbolS
*s
)
2599 if (s
->flags
.local_symbol
)
2600 s
= local_symbol_convert (s
);
2601 s
->flags
.weakrefr
= 1;
2602 /* If the alias was already used, make sure we mark the target as
2603 used as well, otherwise it might be dropped from the symbol
2604 table. This may have unintended side effects if the alias is
2605 later redirected to another symbol, such as keeping the unused
2606 previous target in the symbol table. Since it will be weak, it's
2609 symbol_mark_used (s
->x
->value
.X_add_symbol
);
2613 S_CLEAR_WEAKREFR (symbolS
*s
)
2615 if (s
->flags
.local_symbol
)
2617 s
->flags
.weakrefr
= 0;
2621 S_SET_WEAKREFD (symbolS
*s
)
2623 if (s
->flags
.local_symbol
)
2624 s
= local_symbol_convert (s
);
2625 s
->flags
.weakrefd
= 1;
2630 S_CLEAR_WEAKREFD (symbolS
*s
)
2632 if (s
->flags
.local_symbol
)
2634 if (s
->flags
.weakrefd
)
2636 s
->flags
.weakrefd
= 0;
2637 /* If a weakref target symbol is weak, then it was never
2638 referenced directly before, not even in a .global directive,
2639 so decay it to local. If it remains undefined, it will be
2640 later turned into a global, like any other undefined
2642 if (s
->bsym
->flags
& BSF_WEAK
)
2644 #ifdef obj_clear_weak_hook
2645 obj_clear_weak_hook (s
);
2647 s
->bsym
->flags
&= ~BSF_WEAK
;
2648 s
->bsym
->flags
|= BSF_LOCAL
;
2654 S_SET_THREAD_LOCAL (symbolS
*s
)
2656 if (s
->flags
.local_symbol
)
2657 s
= local_symbol_convert (s
);
2658 if (bfd_is_com_section (s
->bsym
->section
)
2659 && (s
->bsym
->flags
& BSF_THREAD_LOCAL
) != 0)
2661 s
->bsym
->flags
|= BSF_THREAD_LOCAL
;
2662 if ((s
->bsym
->flags
& BSF_FUNCTION
) != 0)
2663 as_bad (_("Accessing function `%s' as thread-local object"),
2665 else if (! bfd_is_und_section (s
->bsym
->section
)
2666 && (s
->bsym
->section
->flags
& SEC_THREAD_LOCAL
) == 0)
2667 as_bad (_("Accessing `%s' as thread-local object"),
2672 S_SET_NAME (symbolS
*s
, const char *name
)
2675 if (s
->flags
.local_symbol
)
2677 s
->bsym
->name
= name
;
2681 S_SET_VOLATILE (symbolS
*s
)
2683 if (s
->flags
.local_symbol
)
2684 s
= local_symbol_convert (s
);
2685 s
->flags
.volatil
= 1;
2689 S_CLEAR_VOLATILE (symbolS
*s
)
2691 if (!s
->flags
.local_symbol
)
2692 s
->flags
.volatil
= 0;
2696 S_SET_FORWARD_REF (symbolS
*s
)
2698 if (s
->flags
.local_symbol
)
2699 s
= local_symbol_convert (s
);
2700 s
->flags
.forward_ref
= 1;
2703 /* Return the previous symbol in a chain. */
2706 symbol_previous (const symbolS
*s
)
2708 if (s
->flags
.local_symbol
)
2710 return s
->x
->previous
;
2713 /* Return the next symbol in a chain. */
2716 symbol_next (const symbolS
*s
)
2718 if (s
->flags
.local_symbol
)
2723 /* Return a pointer to the value of a symbol as an expression. */
2726 symbol_get_value_expression (symbolS
*s
)
2728 if (s
->flags
.local_symbol
)
2729 s
= local_symbol_convert (s
);
2730 return &s
->x
->value
;
2733 /* Set the value of a symbol to an expression. */
2736 symbol_set_value_expression (symbolS
*s
, const expressionS
*exp
)
2738 if (s
->flags
.local_symbol
)
2739 s
= local_symbol_convert (s
);
2741 S_CLEAR_WEAKREFR (s
);
2744 /* Return whether 2 symbols are the same. */
2747 symbol_same_p (const symbolS
*s1
, const symbolS
*s2
)
2752 /* Return a pointer to the X_add_number component of a symbol. */
2755 symbol_X_add_number (const symbolS
*s
)
2757 if (s
->flags
.local_symbol
)
2758 return (offsetT
*) &((struct local_symbol
*) s
)->value
;
2760 return &s
->x
->value
.X_add_number
;
2763 /* Set the value of SYM to the current position in the current segment. */
2766 symbol_set_value_now (symbolS
*sym
)
2768 S_SET_SEGMENT (sym
, now_seg
);
2769 S_SET_VALUE (sym
, frag_now_fix ());
2770 symbol_set_frag (sym
, frag_now
);
2773 /* Set the frag of a symbol. */
2776 symbol_set_frag (symbolS
*s
, fragS
*f
)
2778 if (s
->flags
.local_symbol
)
2780 ((struct local_symbol
*) s
)->frag
= f
;
2784 S_CLEAR_WEAKREFR (s
);
2787 /* Return the frag of a symbol. */
2790 symbol_get_frag (const symbolS
*s
)
2792 if (s
->flags
.local_symbol
)
2793 return ((struct local_symbol
*) s
)->frag
;
2797 /* Mark a symbol as having been used. */
2800 symbol_mark_used (symbolS
*s
)
2802 if (s
->flags
.local_symbol
)
2805 if (S_IS_WEAKREFR (s
))
2806 symbol_mark_used (s
->x
->value
.X_add_symbol
);
2809 /* Clear the mark of whether a symbol has been used. */
2812 symbol_clear_used (symbolS
*s
)
2814 if (s
->flags
.local_symbol
)
2815 s
= local_symbol_convert (s
);
2819 /* Return whether a symbol has been used. */
2822 symbol_used_p (const symbolS
*s
)
2824 if (s
->flags
.local_symbol
)
2826 return s
->flags
.used
;
2829 /* Mark a symbol as having been used in a reloc. */
2832 symbol_mark_used_in_reloc (symbolS
*s
)
2834 if (s
->flags
.local_symbol
)
2835 s
= local_symbol_convert (s
);
2836 s
->flags
.used_in_reloc
= 1;
2839 /* Clear the mark of whether a symbol has been used in a reloc. */
2842 symbol_clear_used_in_reloc (symbolS
*s
)
2844 if (s
->flags
.local_symbol
)
2846 s
->flags
.used_in_reloc
= 0;
2849 /* Return whether a symbol has been used in a reloc. */
2852 symbol_used_in_reloc_p (const symbolS
*s
)
2854 if (s
->flags
.local_symbol
)
2856 return s
->flags
.used_in_reloc
;
2859 /* Mark a symbol as an MRI common symbol. */
2862 symbol_mark_mri_common (symbolS
*s
)
2864 if (s
->flags
.local_symbol
)
2865 s
= local_symbol_convert (s
);
2866 s
->flags
.mri_common
= 1;
2869 /* Clear the mark of whether a symbol is an MRI common symbol. */
2872 symbol_clear_mri_common (symbolS
*s
)
2874 if (s
->flags
.local_symbol
)
2876 s
->flags
.mri_common
= 0;
2879 /* Return whether a symbol is an MRI common symbol. */
2882 symbol_mri_common_p (const symbolS
*s
)
2884 if (s
->flags
.local_symbol
)
2886 return s
->flags
.mri_common
;
2889 /* Mark a symbol as having been written. */
2892 symbol_mark_written (symbolS
*s
)
2894 if (s
->flags
.local_symbol
)
2896 s
->flags
.written
= 1;
2899 /* Clear the mark of whether a symbol has been written. */
2902 symbol_clear_written (symbolS
*s
)
2904 if (s
->flags
.local_symbol
)
2906 s
->flags
.written
= 0;
2909 /* Return whether a symbol has been written. */
2912 symbol_written_p (const symbolS
*s
)
2914 if (s
->flags
.local_symbol
)
2916 return s
->flags
.written
;
2919 /* Mark a symbol as to be removed. */
2922 symbol_mark_removed (symbolS
*s
)
2924 if (s
->flags
.local_symbol
)
2926 s
->flags
.removed
= 1;
2929 /* Return whether a symbol has been marked to be removed. */
2932 symbol_removed_p (const symbolS
*s
)
2934 if (s
->flags
.local_symbol
)
2936 return s
->flags
.removed
;
2939 /* Mark a symbol as having been resolved. */
2942 symbol_mark_resolved (symbolS
*s
)
2944 s
->flags
.resolved
= 1;
2947 /* Return whether a symbol has been resolved. */
2950 symbol_resolved_p (const symbolS
*s
)
2952 return s
->flags
.resolved
;
2955 /* Mark a symbol as being resolved. */
2958 symbol_mark_resolving (symbolS
*s
)
2960 s
->flags
.resolving
= 1;
2964 symbol_clear_resolving (symbolS
*s
)
2966 s
->flags
.resolving
= 0;
2969 /* Return whether a symbol is being resolved. */
2972 symbol_resolving_p (const symbolS
*s
)
2974 return s
->flags
.resolving
;
2977 /* Return whether a symbol is a section symbol. */
2980 symbol_section_p (const symbolS
*s
)
2982 if (s
->flags
.local_symbol
)
2984 return (s
->bsym
->flags
& BSF_SECTION_SYM
) != 0;
2987 /* Return whether a symbol is equated to another symbol. */
2990 symbol_equated_p (const symbolS
*s
)
2992 if (s
->flags
.local_symbol
)
2994 return s
->x
->value
.X_op
== O_symbol
;
2997 /* Return whether a symbol is equated to another symbol, and should be
2998 treated specially when writing out relocs. */
3001 symbol_equated_reloc_p (const symbolS
*s
)
3003 if (s
->flags
.local_symbol
)
3005 /* X_op_symbol, normally not used for O_symbol, is set by
3006 resolve_symbol_value to flag expression syms that have been
3008 return (s
->x
->value
.X_op
== O_symbol
3009 #if defined (OBJ_COFF) && defined (TE_PE)
3012 && ((s
->flags
.resolved
&& s
->x
->value
.X_op_symbol
!= NULL
)
3013 || ! S_IS_DEFINED (s
)
3014 || S_IS_COMMON (s
)));
3017 /* Return whether a symbol has a constant value. */
3020 symbol_constant_p (const symbolS
*s
)
3022 if (s
->flags
.local_symbol
)
3024 return s
->x
->value
.X_op
== O_constant
;
3027 /* Return whether a symbol was cloned and thus removed from the global
3031 symbol_shadow_p (const symbolS
*s
)
3033 if (s
->flags
.local_symbol
)
3035 return s
->x
->next
== s
;
3038 /* If S is a struct symbol return S, otherwise return NULL. */
3041 symbol_symbolS (symbolS
*s
)
3043 if (s
->flags
.local_symbol
)
3048 /* Return the BFD symbol for a symbol. */
3051 symbol_get_bfdsym (symbolS
*s
)
3053 if (s
->flags
.local_symbol
)
3054 s
= local_symbol_convert (s
);
3058 /* Set the BFD symbol for a symbol. */
3061 symbol_set_bfdsym (symbolS
*s
, asymbol
*bsym
)
3063 if (s
->flags
.local_symbol
)
3064 s
= local_symbol_convert (s
);
3065 /* Usually, it is harmless to reset a symbol to a BFD section
3066 symbol. For example, obj_elf_change_section sets the BFD symbol
3067 of an old symbol with the newly created section symbol. But when
3068 we have multiple sections with the same name, the newly created
3069 section may have the same name as an old section. We check if the
3070 old symbol has been already marked as a section symbol before
3072 if ((s
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
3074 /* else XXX - What do we do now ? */
3077 #ifdef OBJ_SYMFIELD_TYPE
3079 /* Get a pointer to the object format information for a symbol. */
3082 symbol_get_obj (symbolS
*s
)
3084 if (s
->flags
.local_symbol
)
3085 s
= local_symbol_convert (s
);
3089 /* Set the object format information for a symbol. */
3092 symbol_set_obj (symbolS
*s
, OBJ_SYMFIELD_TYPE
*o
)
3094 if (s
->flags
.local_symbol
)
3095 s
= local_symbol_convert (s
);
3099 #endif /* OBJ_SYMFIELD_TYPE */
3101 #ifdef TC_SYMFIELD_TYPE
3103 /* Get a pointer to the processor information for a symbol. */
3106 symbol_get_tc (symbolS
*s
)
3108 if (s
->flags
.local_symbol
)
3109 s
= local_symbol_convert (s
);
3113 /* Set the processor information for a symbol. */
3116 symbol_set_tc (symbolS
*s
, TC_SYMFIELD_TYPE
*o
)
3118 if (s
->flags
.local_symbol
)
3119 s
= local_symbol_convert (s
);
3123 #endif /* TC_SYMFIELD_TYPE */
3128 symbol_lastP
= NULL
;
3129 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
3130 sy_hash
= htab_create_alloc (1024, hash_symbol_entry
, eq_symbol_entry
,
3131 NULL
, xcalloc
, free
);
3133 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
3134 abs_symbol
.bsym
= bfd_abs_section_ptr
->symbol
;
3136 abs_symbol
.x
= &abs_symbol_x
;
3137 abs_symbol
.x
->value
.X_op
= O_constant
;
3138 abs_symbol
.frag
= &zero_address_frag
;
3140 if (LOCAL_LABELS_FB
)
3147 htab_delete (sy_hash
);
3151 dot_symbol_init (void)
3153 dot_symbol
.name
= ".";
3154 dot_symbol
.flags
.forward_ref
= 1;
3155 dot_symbol
.bsym
= bfd_make_empty_symbol (stdoutput
);
3156 if (dot_symbol
.bsym
== NULL
)
3157 as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
3158 dot_symbol
.bsym
->name
= ".";
3159 dot_symbol
.x
= &dot_symbol_x
;
3160 dot_symbol
.x
->value
.X_op
= O_constant
;
3165 /* Maximum indent level.
3166 Available for modification inside a gdb session. */
3167 static int max_indent_level
= 8;
3170 print_symbol_value_1 (FILE *file
, symbolS
*sym
)
3172 const char *name
= S_GET_NAME (sym
);
3173 if (!name
|| !name
[0])
3175 fprintf (file
, "sym %p %s", sym
, name
);
3177 if (sym
->flags
.local_symbol
)
3179 struct local_symbol
*locsym
= (struct local_symbol
*) sym
;
3181 if (locsym
->frag
!= &zero_address_frag
3182 && locsym
->frag
!= NULL
)
3183 fprintf (file
, " frag %p", locsym
->frag
);
3184 if (locsym
->flags
.resolved
)
3185 fprintf (file
, " resolved");
3186 fprintf (file
, " local");
3190 if (sym
->frag
!= &zero_address_frag
)
3191 fprintf (file
, " frag %p", sym
->frag
);
3192 if (sym
->flags
.written
)
3193 fprintf (file
, " written");
3194 if (sym
->flags
.resolved
)
3195 fprintf (file
, " resolved");
3196 else if (sym
->flags
.resolving
)
3197 fprintf (file
, " resolving");
3198 if (sym
->flags
.used_in_reloc
)
3199 fprintf (file
, " used-in-reloc");
3200 if (sym
->flags
.used
)
3201 fprintf (file
, " used");
3202 if (S_IS_LOCAL (sym
))
3203 fprintf (file
, " local");
3204 if (S_IS_EXTERNAL (sym
))
3205 fprintf (file
, " extern");
3206 if (S_IS_WEAK (sym
))
3207 fprintf (file
, " weak");
3208 if (S_IS_DEBUG (sym
))
3209 fprintf (file
, " debug");
3210 if (S_IS_DEFINED (sym
))
3211 fprintf (file
, " defined");
3213 if (S_IS_WEAKREFR (sym
))
3214 fprintf (file
, " weakrefr");
3215 if (S_IS_WEAKREFD (sym
))
3216 fprintf (file
, " weakrefd");
3217 fprintf (file
, " %s", segment_name (S_GET_SEGMENT (sym
)));
3218 if (symbol_resolved_p (sym
))
3220 segT s
= S_GET_SEGMENT (sym
);
3222 if (s
!= undefined_section
3223 && s
!= expr_section
)
3224 fprintf (file
, " %lx", (unsigned long) S_GET_VALUE (sym
));
3226 else if (indent_level
< max_indent_level
3227 && S_GET_SEGMENT (sym
) != undefined_section
)
3230 fprintf (file
, "\n%*s<", indent_level
* 4, "");
3231 if (sym
->flags
.local_symbol
)
3232 fprintf (file
, "constant %lx",
3233 (unsigned long) ((struct local_symbol
*) sym
)->value
);
3235 print_expr_1 (file
, &sym
->x
->value
);
3236 fprintf (file
, ">");
3243 print_symbol_value (symbolS
*sym
)
3246 print_symbol_value_1 (stderr
, sym
);
3247 fprintf (stderr
, "\n");
3251 print_binary (FILE *file
, const char *name
, expressionS
*exp
)
3254 fprintf (file
, "%s\n%*s<", name
, indent_level
* 4, "");
3255 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3256 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3257 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3258 fprintf (file
, ">");
3263 print_expr_1 (FILE *file
, expressionS
*exp
)
3265 fprintf (file
, "expr %p ", exp
);
3269 fprintf (file
, "illegal");
3272 fprintf (file
, "absent");
3275 fprintf (file
, "constant %" PRIx64
, (uint64_t) exp
->X_add_number
);
3279 fprintf (file
, "symbol\n%*s<", indent_level
* 4, "");
3280 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3281 fprintf (file
, ">");
3283 if (exp
->X_add_number
)
3284 fprintf (file
, "\n%*s%" PRIx64
, indent_level
* 4, "",
3285 (uint64_t) exp
->X_add_number
);
3289 fprintf (file
, "register #%d", (int) exp
->X_add_number
);
3292 fprintf (file
, "big");
3295 fprintf (file
, "uminus -<");
3297 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3298 fprintf (file
, ">");
3299 goto maybe_print_addnum
;
3301 fprintf (file
, "bit_not");
3304 print_binary (file
, "multiply", exp
);
3307 print_binary (file
, "divide", exp
);
3310 print_binary (file
, "modulus", exp
);
3313 print_binary (file
, "lshift", exp
);
3316 print_binary (file
, "rshift", exp
);
3318 case O_bit_inclusive_or
:
3319 print_binary (file
, "bit_ior", exp
);
3321 case O_bit_exclusive_or
:
3322 print_binary (file
, "bit_xor", exp
);
3325 print_binary (file
, "bit_and", exp
);
3328 print_binary (file
, "eq", exp
);
3331 print_binary (file
, "ne", exp
);
3334 print_binary (file
, "lt", exp
);
3337 print_binary (file
, "le", exp
);
3340 print_binary (file
, "ge", exp
);
3343 print_binary (file
, "gt", exp
);
3346 print_binary (file
, "logical_and", exp
);
3349 print_binary (file
, "logical_or", exp
);
3353 fprintf (file
, "add\n%*s<", indent_level
* 4, "");
3354 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3355 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3356 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3357 fprintf (file
, ">");
3358 goto maybe_print_addnum
;
3361 fprintf (file
, "subtract\n%*s<", indent_level
* 4, "");
3362 print_symbol_value_1 (file
, exp
->X_add_symbol
);
3363 fprintf (file
, ">\n%*s<", indent_level
* 4, "");
3364 print_symbol_value_1 (file
, exp
->X_op_symbol
);
3365 fprintf (file
, ">");
3366 goto maybe_print_addnum
;
3368 fprintf (file
, "{unknown opcode %d}", (int) exp
->X_op
);
3375 print_expr (expressionS
*exp
)
3377 print_expr_1 (stderr
, exp
);
3378 fprintf (stderr
, "\n");
3382 symbol_print_statistics (FILE *file
)
3384 htab_print_statistics (file
, "symbol table", sy_hash
);
3385 fprintf (file
, "%lu mini local symbols created, %lu converted\n",
3386 local_symbol_count
, local_symbol_conversion_count
);
3389 #ifdef OBJ_COMPLEX_RELC
3391 /* Convert given symbol to a new complex-relocation symbol name. This
3392 may be a recursive function, since it might be called for non-leaf
3393 nodes (plain symbols) in the expression tree. The caller owns the
3394 returning string, so should free it eventually. Errors are
3395 indicated via as_bad and a NULL return value. The given symbol
3396 is marked with used_in_reloc. */
3399 symbol_relc_make_sym (symbolS
* sym
)
3401 char * terminal
= NULL
;
3406 gas_assert (sym
!= NULL
);
3408 /* Recurse to symbol_relc_make_expr if this symbol
3409 is defined as an expression or a plain value. */
3410 if ( S_GET_SEGMENT (sym
) == expr_section
3411 || S_GET_SEGMENT (sym
) == absolute_section
)
3412 return symbol_relc_make_expr (symbol_get_value_expression (sym
));
3414 /* This may be a "fake symbol", referring to ".".
3415 Write out a special null symbol to refer to this position. */
3416 if (! strcmp (S_GET_NAME (sym
), FAKE_LABEL_NAME
))
3417 return xstrdup (".");
3419 /* We hope this is a plain leaf symbol. Construct the encoding
3420 as {S,s}II...:CCCCCCC....
3421 where 'S'/'s' means section symbol / plain symbol
3422 III is decimal for the symbol name length
3423 CCC is the symbol name itself. */
3424 symbol_mark_used_in_reloc (sym
);
3426 sname
= S_GET_NAME (sym
);
3427 sname_len
= strlen (sname
);
3428 typetag
= symbol_section_p (sym
) ? 'S' : 's';
3430 terminal
= XNEWVEC (char, (1 /* S or s */
3431 + 8 /* sname_len in decimal */
3433 + sname_len
/* name itself */
3436 sprintf (terminal
, "%c%d:%s", typetag
, sname_len
, sname
);
3440 /* Convert given value to a new complex-relocation symbol name. This
3441 is a non-recursive function, since it is be called for leaf nodes
3442 (plain values) in the expression tree. The caller owns the
3443 returning string, so should free() it eventually. No errors. */
3446 symbol_relc_make_value (offsetT val
)
3448 char * terminal
= XNEWVEC (char, 28); /* Enough for long long. */
3451 bfd_sprintf_vma (stdoutput
, terminal
+ 1, val
);
3455 /* Convert given expression to a new complex-relocation symbol name.
3456 This is a recursive function, since it traverses the entire given
3457 expression tree. The caller owns the returning string, so should
3458 free() it eventually. Errors are indicated via as_bad() and a NULL
3462 symbol_relc_make_expr (expressionS
* exp
)
3464 const char * opstr
= NULL
; /* Operator prefix string. */
3465 int arity
= 0; /* Arity of this operator. */
3466 char * operands
[3]; /* Up to three operands. */
3467 char * concat_string
= NULL
;
3469 operands
[0] = operands
[1] = operands
[2] = NULL
;
3471 gas_assert (exp
!= NULL
);
3473 /* Match known operators -> fill in opstr, arity, operands[] and fall
3474 through to construct subexpression fragments; may instead return
3475 string directly for leaf nodes. */
3477 /* See expr.h for the meaning of all these enums. Many operators
3478 have an unnatural arity (X_add_number implicitly added). The
3479 conversion logic expands them to explicit "+" subexpressions. */
3484 as_bad ("Unknown expression operator (enum %d)", exp
->X_op
);
3489 return symbol_relc_make_value (exp
->X_add_number
);
3492 if (exp
->X_add_number
)
3496 operands
[0] = symbol_relc_make_sym (exp
->X_add_symbol
);
3497 operands
[1] = symbol_relc_make_value (exp
->X_add_number
);
3501 return symbol_relc_make_sym (exp
->X_add_symbol
);
3503 /* Helper macros for nesting nodes. */
3505 #define HANDLE_XADD_OPT1(str_) \
3506 if (exp->X_add_number) \
3509 opstr = "+:" str_; \
3510 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3511 operands[1] = symbol_relc_make_value (exp->X_add_number); \
3518 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3522 #define HANDLE_XADD_OPT2(str_) \
3523 if (exp->X_add_number) \
3526 opstr = "+:" str_; \
3527 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3528 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3529 operands[2] = symbol_relc_make_value (exp->X_add_number); \
3535 operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \
3536 operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \
3540 /* Nesting nodes. */
3542 case O_uminus
: HANDLE_XADD_OPT1 ("0-");
3543 case O_bit_not
: HANDLE_XADD_OPT1 ("~");
3544 case O_logical_not
: HANDLE_XADD_OPT1 ("!");
3545 case O_multiply
: HANDLE_XADD_OPT2 ("*");
3546 case O_divide
: HANDLE_XADD_OPT2 ("/");
3547 case O_modulus
: HANDLE_XADD_OPT2 ("%");
3548 case O_left_shift
: HANDLE_XADD_OPT2 ("<<");
3549 case O_right_shift
: HANDLE_XADD_OPT2 (">>");
3550 case O_bit_inclusive_or
: HANDLE_XADD_OPT2 ("|");
3551 case O_bit_exclusive_or
: HANDLE_XADD_OPT2 ("^");
3552 case O_bit_and
: HANDLE_XADD_OPT2 ("&");
3553 case O_add
: HANDLE_XADD_OPT2 ("+");
3554 case O_subtract
: HANDLE_XADD_OPT2 ("-");
3555 case O_eq
: HANDLE_XADD_OPT2 ("==");
3556 case O_ne
: HANDLE_XADD_OPT2 ("!=");
3557 case O_lt
: HANDLE_XADD_OPT2 ("<");
3558 case O_le
: HANDLE_XADD_OPT2 ("<=");
3559 case O_ge
: HANDLE_XADD_OPT2 (">=");
3560 case O_gt
: HANDLE_XADD_OPT2 (">");
3561 case O_logical_and
: HANDLE_XADD_OPT2 ("&&");
3562 case O_logical_or
: HANDLE_XADD_OPT2 ("||");
3565 /* Validate & reject early. */
3566 if (arity
>= 1 && ((operands
[0] == NULL
) || (strlen (operands
[0]) == 0)))
3568 if (arity
>= 2 && ((operands
[1] == NULL
) || (strlen (operands
[1]) == 0)))
3570 if (arity
>= 3 && ((operands
[2] == NULL
) || (strlen (operands
[2]) == 0)))
3574 concat_string
= NULL
;
3575 else if (arity
== 0)
3576 concat_string
= xstrdup (opstr
);
3577 else if (arity
== 1)
3578 concat_string
= concat (opstr
, ":", operands
[0], (char *) NULL
);
3579 else if (arity
== 2)
3580 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1],
3583 concat_string
= concat (opstr
, ":", operands
[0], ":", operands
[1], ":",
3584 operands
[2], (char *) NULL
);
3586 /* Free operand strings (not opstr). */
3587 if (arity
>= 1) xfree (operands
[0]);
3588 if (arity
>= 2) xfree (operands
[1]);
3589 if (arity
>= 3) xfree (operands
[2]);
3591 return concat_string
;