1 /* symbols.c -symbol table-
2 Copyright (C) 1987, 1990, 1991, 1992, 1993 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 2, 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
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* #define DEBUG_SYMS / * to debug symbol list maintenance */
26 #include "obstack.h" /* For "symbols.h" */
29 #ifndef WORKING_DOT_WORD
30 extern int new_broken_words
;
33 /* symbol-name => struct symbol pointer */
34 static struct hash_control
*sy_hash
;
36 /* Below are commented in "symbols.h". */
37 symbolS
*symbol_rootP
;
38 symbolS
*symbol_lastP
;
41 symbolS
*dot_text_symbol
;
42 symbolS
*dot_data_symbol
;
43 symbolS
*dot_bss_symbol
;
47 static void fb_label_init
PARAMS ((void));
53 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
54 sy_hash
= hash_new ();
55 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
57 abs_symbol
.bsym
= bfd_abs_section
.symbol
;
59 /* Can't initialise a union. Sigh. */
60 S_SET_SEGMENT (&abs_symbol
, absolute_section
);
62 #ifdef LOCAL_LABELS_FB
64 #endif /* LOCAL_LABELS_FB */
70 * Return a pointer to a new symbol.
71 * Die if we can't make a new symbol.
72 * Fill in the symbol's values.
73 * Add symbol to end of symbol chain.
76 * Please always call this to create a new symbol.
78 * Changes since 1985: Symbol names may not contain '\0'. Sigh.
79 * 2nd argument is now a SEG rather than a TYPE. The mapping between
80 * segments and types is mostly encapsulated herein (actually, we inherit it
81 * from macros in struc-symbol.h).
85 symbol_new (name
, segment
, valu
, frag
)
86 CONST
char *name
; /* It is copied, the caller can destroy/modify */
87 segT segment
; /* Segment identifier (SEG_<something>) */
88 valueT valu
; /* Symbol value */
89 fragS
*frag
; /* Associated fragment */
91 unsigned int name_length
;
92 char *preserved_copy_of_name
;
95 name_length
= strlen (name
) + 1; /* +1 for \0 */
96 obstack_grow (¬es
, name
, name_length
);
97 preserved_copy_of_name
= obstack_finish (¬es
);
98 #ifdef STRIP_UNDERSCORE
99 if (preserved_copy_of_name
[0] == '_')
100 preserved_copy_of_name
++;
102 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
104 /* symbol must be born in some fixed state. This seems as good as any. */
105 memset (symbolP
, 0, sizeof (symbolS
));
109 symbolP
->bsym
= bfd_make_empty_symbol (stdoutput
);
110 assert (symbolP
->bsym
!= 0);
111 symbolP
->bsym
->udata
= (PTR
) symbolP
;
113 S_SET_NAME (symbolP
, preserved_copy_of_name
);
115 S_SET_SEGMENT (symbolP
, segment
);
116 S_SET_VALUE (symbolP
, valu
);
117 symbol_clear_list_pointers(symbolP
);
119 symbolP
->sy_frag
= frag
;
120 #ifndef BFD_ASSEMBLER
121 symbolP
->sy_number
= ~0;
122 symbolP
->sy_name_offset
= ~0;
126 * Link to end of symbol chain.
128 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
130 obj_symbol_new_hook (symbolP
);
133 verify_symbol_chain(symbol_rootP
, symbol_lastP
);
134 #endif /* DEBUG_SYMS */
143 * We have just seen "<name>:".
144 * Creates a struct symbol unless it already exists.
146 * Gripes if we are redefining a symbol incompatibly (and ignores it).
150 colon (sym_name
) /* just seen "x:" - rattle symbols & frags */
151 register char *sym_name
; /* symbol name, as a cannonical string */
152 /* We copy this string: OK to alter later. */
154 register symbolS
*symbolP
; /* symbol we are working with */
156 #ifdef LOCAL_LABELS_DOLLAR
157 /* Sun local labels go out of scope whenever a non-local symbol is
160 if (*sym_name
!= 'L')
161 dollar_label_clear ();
162 #endif /* LOCAL_LABELS_DOLLAR */
164 #ifndef WORKING_DOT_WORD
165 if (new_broken_words
)
167 struct broken_word
*a
;
172 extern const int md_short_jump_size
;
173 extern const int md_long_jump_size
;
174 possible_bytes
= (md_short_jump_size
175 + new_broken_words
* md_long_jump_size
);
178 frag_opcode
= frag_var (rs_broken_word
,
182 (symbolS
*) broken_words
,
186 /* We want to store the pointer to where to insert the jump table in the
187 fr_opcode of the rs_broken_word frag. This requires a little
190 && (frag_tmp
->fr_type
!= rs_broken_word
191 || frag_tmp
->fr_opcode
))
192 frag_tmp
= frag_tmp
->fr_next
;
194 frag_tmp
->fr_opcode
= frag_opcode
;
195 new_broken_words
= 0;
197 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
198 a
->dispfrag
= frag_tmp
;
200 #endif /* WORKING_DOT_WORD */
202 if ((symbolP
= symbol_find (sym_name
)) != 0)
204 #ifdef RESOLVE_SYMBOL_REDEFINITION
205 if (RESOLVE_SYMBOL_REDEFINITION (symbolP
))
209 * Now check for undefined symbols
211 if (!S_IS_DEFINED (symbolP
))
213 if (S_GET_VALUE (symbolP
) == 0)
215 symbolP
->sy_frag
= frag_now
;
217 S_GET_OTHER(symbolP
) = const_flag
;
219 S_SET_VALUE (symbolP
, (valueT
) ((char*)obstack_next_free (&frags
) - frag_now
->fr_literal
));
220 S_SET_SEGMENT (symbolP
, now_seg
);
223 #endif /* if we have one, it better be zero. */
229 * There are still several cases to check:
230 * A .comm/.lcomm symbol being redefined as
231 * initialized data is OK
232 * A .comm/.lcomm symbol being redefined with
233 * a larger size is also OK
235 * This only used to be allowed on VMS gas, but Sun cc
236 * on the sparc also depends on it.
239 if (((!S_IS_DEBUG (symbolP
)
240 && !S_IS_DEFINED (symbolP
)
241 && S_IS_EXTERNAL (symbolP
))
242 || S_GET_SEGMENT (symbolP
) == bss_section
)
243 && (now_seg
== data_section
244 || now_seg
== S_GET_SEGMENT (symbolP
)))
247 * Select which of the 2 cases this is
249 if (now_seg
!= data_section
)
252 * New .comm for prev .comm symbol.
253 * If the new size is larger we just
254 * change its value. If the new size
255 * is smaller, we ignore this symbol
257 if (S_GET_VALUE (symbolP
)
258 < ((unsigned) frag_now_fix ()))
260 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
265 /* It is a .comm/.lcomm being converted to initialized
267 symbolP
->sy_frag
= frag_now
;
269 S_GET_OTHER(symbolP
) = const_flag
;
271 S_SET_VALUE (symbolP
, (valueT
) frag_now_fix ());
272 S_SET_SEGMENT (symbolP
, now_seg
); /* keep N_EXT bit */
277 #if defined (S_GET_OTHER) && defined (S_GET_DESC)
278 as_fatal ("Symbol \"%s\" is already defined as \"%s\"/%d.%d.%ld.",
280 segment_name (S_GET_SEGMENT (symbolP
)),
281 S_GET_OTHER (symbolP
), S_GET_DESC (symbolP
),
282 (long) S_GET_VALUE (symbolP
));
284 as_fatal ("Symbol \"%s\" is already defined as \"%s\"/%ld.",
286 segment_name (S_GET_SEGMENT (symbolP
)),
287 (long) S_GET_VALUE (symbolP
));
290 } /* if the undefined symbol has no value */
294 /* Don't blow up if the definition is the same */
295 if (!(frag_now
== symbolP
->sy_frag
296 && S_GET_VALUE (symbolP
) == (char*)obstack_next_free (&frags
) - frag_now
->fr_literal
297 && S_GET_SEGMENT (symbolP
) == now_seg
))
298 as_fatal ("Symbol %s already defined.", sym_name
);
299 } /* if this symbol is not yet defined */
304 symbolP
= symbol_new (sym_name
,
306 (valueT
) ((char*)obstack_next_free (&frags
) - frag_now
->fr_literal
),
309 S_SET_OTHER (symbolP
, const_flag
);
312 symbol_table_insert (symbolP
);
313 } /* if we have seen this symbol before */
316 tc_frob_label (symbolP
);
322 * symbol_table_insert()
324 * Die if we can't insert the symbol.
329 symbol_table_insert (symbolP
)
332 register const char *error_string
;
335 know (S_GET_NAME (symbolP
));
337 if (*(error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (PTR
) symbolP
)))
339 as_fatal ("Inserting \"%s\" into symbol table failed: %s",
340 S_GET_NAME (symbolP
), error_string
);
342 } /* symbol_table_insert() */
345 * symbol_find_or_make()
347 * If a symbol name does not exist, create it as undefined, and insert
348 * it into the symbol table. Return a pointer to it.
351 symbol_find_or_make (name
)
354 register symbolS
*symbolP
;
356 symbolP
= symbol_find (name
);
360 symbolP
= symbol_make (name
);
362 symbol_table_insert (symbolP
);
363 } /* if symbol wasn't found */
366 } /* symbol_find_or_make() */
374 /* Let the machine description default it, e.g. for register names. */
375 symbolP
= md_undefined_symbol ((char *) name
);
378 symbolP
= symbol_new (name
, undefined_section
, (valueT
) 0, &zero_address_frag
);
381 } /* symbol_make() */
386 * Implement symbol table lookup.
387 * In: A symbol's name as a string: '\0' can't be part of a symbol name.
388 * Out: NULL if the name was not in the symbol table, else the address
389 * of a struct symbol associated with that name.
396 #ifdef STRIP_UNDERSCORE
397 return (symbol_find_base (name
, 1));
398 #else /* STRIP_UNDERSCORE */
399 return (symbol_find_base (name
, 0));
400 #endif /* STRIP_UNDERSCORE */
401 } /* symbol_find() */
404 symbol_find_base (name
, strip_underscore
)
406 int strip_underscore
;
408 if (strip_underscore
&& *name
== '_')
410 return ((symbolS
*) hash_find (sy_hash
, name
));
414 * Once upon a time, symbols were kept in a singly linked list. At
415 * least coff needs to be able to rearrange them from time to time, for
416 * which a doubly linked list is much more convenient. Loic did these
417 * as macros which seemed dangerous to me so they're now functions.
421 /* Link symbol ADDME after symbol TARGET in the chain. */
423 symbol_append (addme
, target
, rootPP
, lastPP
)
431 know (*rootPP
== NULL
);
432 know (*lastPP
== NULL
);
436 } /* if the list is empty */
438 if (target
->sy_next
!= NULL
)
440 #ifdef SYMBOLS_NEED_BACKPOINTERS
441 target
->sy_next
->sy_previous
= addme
;
442 #endif /* SYMBOLS_NEED_BACKPOINTERS */
446 know (*lastPP
== target
);
448 } /* if we have a next */
450 addme
->sy_next
= target
->sy_next
;
451 target
->sy_next
= addme
;
453 #ifdef SYMBOLS_NEED_BACKPOINTERS
454 addme
->sy_previous
= target
;
455 #endif /* SYMBOLS_NEED_BACKPOINTERS */
458 #ifdef SYMBOLS_NEED_BACKPOINTERS
459 /* Remove SYMBOLP from the list. */
461 symbol_remove (symbolP
, rootPP
, lastPP
)
466 if (symbolP
== *rootPP
)
468 *rootPP
= symbolP
->sy_next
;
469 } /* if it was the root */
471 if (symbolP
== *lastPP
)
473 *lastPP
= symbolP
->sy_previous
;
474 } /* if it was the tail */
476 if (symbolP
->sy_next
!= NULL
)
478 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
481 if (symbolP
->sy_previous
!= NULL
)
483 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
487 verify_symbol_chain (*rootPP
, *lastPP
);
488 #endif /* DEBUG_SYMS */
491 /* Set the chain pointers of SYMBOL to null. */
493 symbol_clear_list_pointers (symbolP
)
496 symbolP
->sy_next
= NULL
;
497 symbolP
->sy_previous
= NULL
;
500 /* Link symbol ADDME before symbol TARGET in the chain. */
502 symbol_insert (addme
, target
, rootPP
, lastPP
)
508 if (target
->sy_previous
!= NULL
)
510 target
->sy_previous
->sy_next
= addme
;
514 know (*rootPP
== target
);
518 addme
->sy_previous
= target
->sy_previous
;
519 target
->sy_previous
= addme
;
520 addme
->sy_next
= target
;
523 verify_symbol_chain (*rootPP
, *lastPP
);
524 #endif /* DEBUG_SYMS */
527 #endif /* SYMBOLS_NEED_BACKPOINTERS */
530 verify_symbol_chain (rootP
, lastP
)
534 symbolS
*symbolP
= rootP
;
539 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
541 #ifdef SYMBOLS_NEED_BACKPOINTERS
542 know (symbolP
->sy_next
->sy_previous
== symbolP
);
544 /* Walk the list anyways, to make sure pointers are still good. */
546 #endif /* SYMBOLS_NEED_BACKPOINTERS */
549 assert (lastP
== symbolP
);
553 verify_symbol_chain_2 (sym
)
556 symbolS
*p
= sym
, *n
= sym
;
557 #ifdef SYMBOLS_NEED_BACKPOINTERS
558 while (symbol_previous (p
))
559 p
= symbol_previous (p
);
561 while (symbol_next (n
))
563 verify_symbol_chain (p
, n
);
566 /* Resolve the value of a symbol. This is called during the final
567 pass over the symbol table to resolve any symbols with complex
571 resolve_symbol_value (symp
)
574 if (symp
->sy_resolved
)
577 if (symp
->sy_resolving
)
579 as_bad ("Symbol definition loop encountered at %s",
581 S_SET_VALUE (symp
, (valueT
) 0);
585 offsetT left
, right
, val
;
586 segT seg_left
, seg_right
;
588 symp
->sy_resolving
= 1;
590 switch (symp
->sy_value
.X_op
)
593 S_SET_VALUE (symp
, 0);
596 S_SET_VALUE (symp
, S_GET_VALUE (symp
) + symp
->sy_frag
->fr_address
);
597 if (S_GET_SEGMENT (symp
) == expr_section
)
598 S_SET_SEGMENT (symp
, absolute_section
);
602 resolve_symbol_value (symp
->sy_value
.X_add_symbol
);
604 #ifdef obj_frob_forward_symbol
605 /* Some object formats need to forward the segment. */
606 obj_frob_forward_symbol (symp
);
610 (symp
->sy_value
.X_add_number
611 + symp
->sy_frag
->fr_address
612 + S_GET_VALUE (symp
->sy_value
.X_add_symbol
)));
613 if (S_GET_SEGMENT (symp
) == expr_section
614 || S_GET_SEGMENT (symp
) == undefined_section
)
616 S_GET_SEGMENT (symp
->sy_value
.X_add_symbol
));
621 resolve_symbol_value (symp
->sy_value
.X_add_symbol
);
622 if (symp
->sy_value
.X_op
== O_uminus
)
623 val
= - S_GET_VALUE (symp
->sy_value
.X_add_symbol
);
625 val
= ~ S_GET_VALUE (symp
->sy_value
.X_add_symbol
);
628 + symp
->sy_value
.X_add_number
629 + symp
->sy_frag
->fr_address
));
630 if (S_GET_SEGMENT (symp
) == expr_section
631 || S_GET_SEGMENT (symp
) == undefined_section
)
632 S_SET_SEGMENT (symp
, absolute_section
);
640 case O_bit_inclusive_or
:
642 case O_bit_exclusive_or
:
646 resolve_symbol_value (symp
->sy_value
.X_add_symbol
);
647 resolve_symbol_value (symp
->sy_value
.X_op_symbol
);
648 seg_left
= S_GET_SEGMENT (symp
->sy_value
.X_add_symbol
);
649 seg_right
= S_GET_SEGMENT (symp
->sy_value
.X_op_symbol
);
650 if (seg_left
!= seg_right
651 && seg_left
!= undefined_section
652 && seg_right
!= undefined_section
)
653 as_bad ("%s is operation on symbols in different sections",
655 if ((S_GET_SEGMENT (symp
->sy_value
.X_add_symbol
)
657 && symp
->sy_value
.X_op
!= O_subtract
)
658 as_bad ("%s is illegal operation on non-absolute symbols",
660 left
= S_GET_VALUE (symp
->sy_value
.X_add_symbol
);
661 right
= S_GET_VALUE (symp
->sy_value
.X_op_symbol
);
662 switch (symp
->sy_value
.X_op
)
664 case O_multiply
: val
= left
* right
; break;
665 case O_divide
: val
= left
/ right
; break;
666 case O_modulus
: val
= left
% right
; break;
667 case O_left_shift
: val
= left
<< right
; break;
668 case O_right_shift
: val
= left
>> right
; break;
669 case O_bit_inclusive_or
: val
= left
| right
; break;
670 case O_bit_or_not
: val
= left
|~ right
; break;
671 case O_bit_exclusive_or
: val
= left
^ right
; break;
672 case O_bit_and
: val
= left
& right
; break;
673 case O_add
: val
= left
+ right
; break;
674 case O_subtract
: val
= left
- right
; break;
678 (symp
->sy_value
.X_add_number
679 + symp
->sy_frag
->fr_address
681 if (S_GET_SEGMENT (symp
) == expr_section
682 || S_GET_SEGMENT (symp
) == undefined_section
)
683 S_SET_SEGMENT (symp
, absolute_section
);
689 as_bad ("bad value for symbol \"%s\"", S_GET_NAME (symp
));
694 symp
->sy_resolved
= 1;
697 #ifdef LOCAL_LABELS_DOLLAR
699 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
700 They are *really* local. That is, they go out of scope whenever we see a
701 label that isn't local. Also, like fb labels, there can be multiple
702 instances of a dollar label. Therefor, we name encode each instance with
703 the instance number, keep a list of defined symbols separate from the real
704 symbol table, and we treat these buggers as a sparse array. */
706 static long *dollar_labels
;
707 static long *dollar_label_instances
;
708 static char *dollar_label_defines
;
709 static long dollar_label_count
;
710 static unsigned long dollar_label_max
;
713 dollar_label_defined (label
)
718 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
720 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
722 return dollar_label_defines
[i
- dollar_labels
];
724 /* if we get here, label isn't defined */
726 } /* dollar_label_defined() */
729 dollar_label_instance (label
)
734 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
736 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
738 return (dollar_label_instances
[i
- dollar_labels
]);
740 /* If we get here, we haven't seen the label before, therefore its instance
746 dollar_label_clear ()
748 memset (dollar_label_defines
, '\0', (unsigned int) dollar_label_count
);
751 #define DOLLAR_LABEL_BUMP_BY 10
754 define_dollar_label (label
)
759 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
762 ++dollar_label_instances
[i
- dollar_labels
];
763 dollar_label_defines
[i
- dollar_labels
] = 1;
767 /* if we get to here, we don't have label listed yet. */
769 if (dollar_labels
== NULL
)
771 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
772 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
773 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
774 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
775 dollar_label_count
= 0;
777 else if (dollar_label_count
== dollar_label_max
)
779 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
780 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
781 dollar_label_max
* sizeof (long));
782 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
783 dollar_label_max
* sizeof (long));
784 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
785 } /* if we needed to grow */
787 dollar_labels
[dollar_label_count
] = label
;
788 dollar_label_instances
[dollar_label_count
] = 1;
789 dollar_label_defines
[dollar_label_count
] = 1;
790 ++dollar_label_count
;
794 * dollar_label_name()
796 * Caller must copy returned name: we re-use the area for the next name.
798 * The mth occurence of label n: is turned into the symbol "Ln^Am"
799 * where n is the label number and m is the instance number. "L" makes
800 * it a label discarded unless debugging and "^A"('\1') ensures no
801 * ordinary symbol SHOULD get the same name as a local label
802 * symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
804 * fb labels get the same treatment, except that ^B is used in place of ^A.
807 char * /* Return local label name. */
808 dollar_label_name (n
, augend
)
809 register long n
; /* we just saw "n$:" : n a number */
810 register int augend
; /* 0 for current instance, 1 for new instance */
813 /* Returned to caller, then copied. used for created names ("4f") */
814 static char symbol_name_build
[24];
817 char symbol_name_temporary
[20]; /* build up a number, BACKWARDS */
820 know (augend
== 0 || augend
== 1);
821 p
= symbol_name_build
;
824 /* Next code just does sprintf( {}, "%d", n); */
826 q
= symbol_name_temporary
;
827 for (*q
++ = 0, i
= n
; i
; ++q
)
832 while ((*p
= *--q
) != '\0')
837 /* instance number */
838 q
= symbol_name_temporary
;
839 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
844 while ((*p
++ = *--q
) != '\0');;
846 /* The label, as a '\0' ended string, starts at symbol_name_build. */
847 return symbol_name_build
;
850 #endif /* LOCAL_LABELS_DOLLAR */
852 #ifdef LOCAL_LABELS_FB
855 * Sombody else's idea of local labels. They are made by "n:" where n
856 * is any decimal digit. Refer to them with
857 * "nb" for previous (backward) n:
858 * or "nf" for next (forward) n:.
860 * We do a little better and let n be any number, not just a single digit, but
861 * since the other guy's assembler only does ten, we treat the first ten
864 * Like someone else's assembler, we have one set of local label counters for
865 * entire assembly, not one set per (sub)segment like in most assemblers. This
866 * implies that one can refer to a label in another segment, and indeed some
867 * crufty compilers have done just that.
869 * Since there could be a LOT of these things, treat them as a sparse array.
872 #define FB_LABEL_SPECIAL (10)
874 static long fb_low_counter
[FB_LABEL_SPECIAL
];
875 static long *fb_labels
;
876 static long *fb_label_instances
;
877 static long fb_label_count
= 0;
878 static long fb_label_max
= 0;
880 /* this must be more than FB_LABEL_SPECIAL */
881 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
886 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
887 } /* fb_label_init() */
889 /* add one to the instance number of this fb label */
891 fb_label_instance_inc (label
)
896 if (label
< FB_LABEL_SPECIAL
)
898 ++fb_low_counter
[label
];
902 if (fb_labels
!= NULL
)
904 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
905 i
< fb_labels
+ fb_label_count
; ++i
)
909 ++fb_label_instances
[i
- fb_labels
];
911 } /* if we find it */
912 } /* for each existing label */
915 /* if we get to here, we don't have label listed yet. */
917 if (fb_labels
== NULL
)
919 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
920 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
921 fb_label_max
= FB_LABEL_BUMP_BY
;
922 fb_label_count
= FB_LABEL_SPECIAL
;
925 else if (fb_label_count
== fb_label_max
)
927 fb_label_max
+= FB_LABEL_BUMP_BY
;
928 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
929 fb_label_max
* sizeof (long));
930 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
931 fb_label_max
* sizeof (long));
932 } /* if we needed to grow */
934 fb_labels
[fb_label_count
] = label
;
935 fb_label_instances
[fb_label_count
] = 1;
940 fb_label_instance (label
)
945 if (label
< FB_LABEL_SPECIAL
)
947 return (fb_low_counter
[label
]);
950 if (fb_labels
!= NULL
)
952 for (i
= fb_labels
+ FB_LABEL_SPECIAL
;
953 i
< fb_labels
+ fb_label_count
; ++i
)
957 return (fb_label_instances
[i
- fb_labels
]);
958 } /* if we find it */
959 } /* for each existing label */
962 /* We didn't find the label, so this must be a reference to the
970 * Caller must copy returned name: we re-use the area for the next name.
972 * The mth occurence of label n: is turned into the symbol "Ln^Bm"
973 * where n is the label number and m is the instance number. "L" makes
974 * it a label discarded unless debugging and "^B"('\2') ensures no
975 * ordinary symbol SHOULD get the same name as a local label
976 * symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
978 * dollar labels get the same treatment, except that ^A is used in place of ^B. */
980 char * /* Return local label name. */
981 fb_label_name (n
, augend
)
982 long n
; /* we just saw "n:", "nf" or "nb" : n a number */
983 long augend
; /* 0 for nb, 1 for n:, nf */
986 /* Returned to caller, then copied. used for created names ("4f") */
987 static char symbol_name_build
[24];
990 char symbol_name_temporary
[20]; /* build up a number, BACKWARDS */
993 know (augend
== 0 || augend
== 1);
994 p
= symbol_name_build
;
997 /* Next code just does sprintf( {}, "%d", n); */
999 q
= symbol_name_temporary
;
1000 for (*q
++ = 0, i
= n
; i
; ++q
)
1005 while ((*p
= *--q
) != '\0')
1010 /* instance number */
1011 q
= symbol_name_temporary
;
1012 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
1017 while ((*p
++ = *--q
) != '\0');;
1019 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1020 return (symbol_name_build
);
1021 } /* fb_label_name() */
1023 #endif /* LOCAL_LABELS_FB */
1027 * decode name that may have been generated by foo_label_name() above. If
1028 * the name wasn't generated by foo_label_name(), then return it unaltered.
1029 * This is used for error messages.
1033 decode_local_label_name (s
)
1037 char *symbol_decode
;
1039 int instance_number
;
1041 const char *message_format
= "\"%d\" (instance number %d of a %s label)";
1046 for (label_number
= 0, p
= s
+ 1; isdigit (*p
); ++p
)
1048 label_number
= (10 * label_number
) + *p
- '0';
1064 for (instance_number
= 0, p
= s
+ 1; isdigit (*p
); ++p
)
1066 instance_number
= (10 * instance_number
) + *p
- '0';
1069 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
1070 (void) sprintf (symbol_decode
, message_format
, label_number
,
1071 instance_number
, type
);
1073 return (symbol_decode
);
1074 } /* decode_local_label_name() */
1076 /* Get the value of a symbol. */
1082 if (s
->sy_value
.X_op
!= O_constant
)
1083 as_bad ("Attempt to get value of unresolved symbol %s", S_GET_NAME (s
));
1084 return (valueT
) s
->sy_value
.X_add_number
;
1087 /* Set the value of a symbol. */
1090 S_SET_VALUE (s
, val
)
1094 s
->sy_value
.X_op
= O_constant
;
1095 s
->sy_value
.X_add_number
= (offsetT
) val
;
1098 #ifdef BFD_ASSEMBLER
1104 flagword flags
= s
->bsym
->flags
;
1107 if (flags
& BSF_LOCAL
&& flags
& (BSF_EXPORT
| BSF_GLOBAL
))
1110 return (flags
& (BSF_EXPORT
| BSF_GLOBAL
)) != 0;
1117 return s
->bsym
->section
== &bfd_com_section
;
1124 return s
->bsym
->section
!= undefined_section
;
1131 if (s
->bsym
->flags
& BSF_DEBUGGING
)
1140 flagword flags
= s
->bsym
->flags
;
1143 if (flags
& BSF_LOCAL
&& flags
& (BSF_EXPORT
| BSF_GLOBAL
))
1146 return (S_GET_NAME (s
)
1148 && (strchr (S_GET_NAME (s
), '\001')
1149 || strchr (S_GET_NAME (s
), '\002')
1150 || (S_LOCAL_NAME (s
)
1151 && !flagseen
['L'])));
1158 return S_IS_EXTERNAL (s
);
1165 return S_GET_NAME (s
) == 0;
1172 return s
->bsym
->name
;
1179 return s
->bsym
->section
;
1183 S_SET_SEGMENT (s
, seg
)
1187 s
->bsym
->section
= seg
;
1194 s
->bsym
->flags
|= BSF_GLOBAL
;
1195 s
->bsym
->flags
&= ~(BSF_LOCAL
|BSF_WEAK
);
1199 S_CLEAR_EXTERNAL (s
)
1202 s
->bsym
->flags
|= BSF_LOCAL
;
1203 s
->bsym
->flags
&= ~(BSF_GLOBAL
|BSF_WEAK
);
1210 s
->bsym
->flags
|= BSF_WEAK
;
1211 s
->bsym
->flags
&= ~(BSF_GLOBAL
|BSF_LOCAL
);
1215 S_SET_NAME (s
, name
)
1219 s
->bsym
->name
= name
;
1221 #endif /* BFD_ASSEMBLER */
1223 /* end of symbols.c */
This page took 0.072628 seconds and 4 git commands to generate.