1/* symbols.c -symbol table-
2   Copyright (C) 1987 Free Software Foundation, Inc.
3
4This file is part of GAS, the GNU Assembler.
5
6GAS is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GAS is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GAS; see the file COPYING.  If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20#include <stdlib.h>
21#include <string.h>
22#include <ctype.h>
23#include "as.h"
24#include "hash.h"
25#include "obstack.h"		/* For "symbols.h" */
26#include "struc-symbol.h"
27#include "symbols.h"
28#include "frags.h"
29#include "expr.h"
30#include "sections.h"
31#include "read.h"
32#include "xmalloc.h"
33#include "messages.h"
34#include "fixes.h"
35#include "input-scrub.h"
36#include "dwarf2dbg.h"
37
38/* symbol-name => struct symbol pointer */
39struct hash_control *sy_hash = NULL;
40
41/* FixS & symbols live here */
42struct obstack notes = { 0 };
43
44/* all the symbol nodes */
45symbolS *symbol_rootP = NULL;
46/* last struct symbol we made, or NULL */
47symbolS *symbol_lastP = NULL;
48/* The last symbol we assigned an index to. */
49symbolS *symbol_lastIndexedP = NULL;
50
51symbolS	abs_symbol = { {{0}} };
52
53/*
54 * Un*x idea of local labels. They are made by "n:" where n
55 * is any decimal digit. Refer to them with
56 *  "nb" for previous (backward) n:
57 *  or "nf" for next (forward) n:.
58 *
59 * Like Un*x AS, we have one set of local label counters for entire assembly,
60 * not one set per (sub)segment like in most assemblers. This implies that
61 * one can refer to a label in another segment, and indeed some crufty
62 * compilers have done just that.
63 *
64 * I document the symbol names here to save duplicating words elsewhere.
65 * The mth occurence of label n: is turned into the symbol "Ln^Am" where
66 * n is a digit and m is a decimal number. "L" makes it a label discarded
67 * unless debugging and "^A"('\1') ensures no ordinary symbol SHOULD get the
68 * same name as a local label symbol. The first "4:" is "L4^A1" - the m
69 * numbers begin at 1.
70 */
71
72typedef short unsigned int local_label_countT;
73
74static void make_stab_for_symbol(
75    symbolS *symbolP);
76
77static void make_subprogram_for_symbol(
78    symbolS *symbolP);
79
80static void fb_label_init(void);
81
82
83void
84symbol_begin(
85void)
86{
87  symbol_lastP = NULL;
88  symbol_rootP = NULL;		/* In case we have 0 symbols (!!) */
89  sy_hash = hash_new();
90  memset((char *)(&abs_symbol), '\0', sizeof(abs_symbol));
91  abs_symbol.sy_type = N_ABS;	/* Can't initialise a union. Sigh. */
92  fb_label_init ();
93}
94
95
96/* Somebody else's idea of local labels. They are made by "n:" where n
97   is any decimal digit. Refer to them with
98    "nb" for previous (backward) n:
99   or "nf" for next (forward) n:.
100
101   We do a little better and let n be any number, not just a single digit, but
102   since the other guy's assembler only does ten, we treat the first ten
103   specially.
104
105   Like someone else's assembler, we have one set of local label counters for
106   entire assembly, not one set per (sub)segment like in most assemblers. This
107   implies that one can refer to a label in another segment, and indeed some
108   crufty compilers have done just that.
109
110   Since there could be a LOT of these things, treat them as a sparse
111   array.  */
112
113#define LOCAL_LABEL_CHAR	'\002'
114#define FB_LABEL_SPECIAL (10)
115
116static int32_t fb_low_counter[FB_LABEL_SPECIAL];
117static int32_t *fb_labels;
118static int32_t *fb_label_instances;
119static int32_t fb_label_count;
120static int32_t fb_label_max;
121
122/* This must be more than FB_LABEL_SPECIAL.  */
123#define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
124
125static void
126fb_label_init (void)
127{
128  memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter));
129}
130
131/* Add one to the instance number of this fb label.  */
132
133void
134fb_label_instance_inc (int32_t label)
135{
136  int32_t *i;
137
138  if (label < FB_LABEL_SPECIAL)
139    {
140      ++fb_low_counter[label];
141      return;
142    }
143
144  if (fb_labels != NULL)
145    {
146      for (i = fb_labels + FB_LABEL_SPECIAL;
147	   i < fb_labels + fb_label_count; ++i)
148	{
149	  if (*i == label)
150	    {
151	      ++fb_label_instances[i - fb_labels];
152	      return;
153	    }			/* if we find it  */
154	}			/* for each existing label  */
155    }
156
157  /* If we get to here, we don't have label listed yet.  */
158
159  if (fb_labels == NULL)
160    {
161      fb_labels = (int32_t *) xmalloc (FB_LABEL_BUMP_BY * sizeof (int32_t));
162      fb_label_instances = (int32_t *) xmalloc (FB_LABEL_BUMP_BY * sizeof (int32_t));
163      fb_label_max = FB_LABEL_BUMP_BY;
164      fb_label_count = FB_LABEL_SPECIAL;
165
166    }
167  else if (fb_label_count == fb_label_max)
168    {
169      fb_label_max += FB_LABEL_BUMP_BY;
170      fb_labels = (int32_t *) xrealloc ((char *) fb_labels,
171				     fb_label_max * sizeof (int32_t));
172      fb_label_instances = (int32_t *) xrealloc ((char *) fb_label_instances,
173					      fb_label_max * sizeof (int32_t));
174    }				/* if we needed to grow  */
175
176  fb_labels[fb_label_count] = label;
177  fb_label_instances[fb_label_count] = 1;
178  ++fb_label_count;
179}
180
181static int32_t
182fb_label_instance (int32_t label)
183{
184  int32_t *i;
185
186  if (label < FB_LABEL_SPECIAL)
187    {
188      return (fb_low_counter[label]);
189    }
190
191  if (fb_labels != NULL)
192    {
193      for (i = fb_labels + FB_LABEL_SPECIAL;
194	   i < fb_labels + fb_label_count; ++i)
195	{
196	  if (*i == label)
197	    {
198	      return (fb_label_instances[i - fb_labels]);
199	    }			/* if we find it  */
200	}			/* for each existing label  */
201    }
202
203  /* We didn't find the label, so this must be a reference to the
204     first instance.  */
205  return 0;
206}
207
208/* Caller must copy returned name: we re-use the area for the next name.
209
210   The mth occurence of label n: is turned into the symbol "Ln^Bm"
211   where n is the label number and m is the instance number. "L" makes
212   it a label discarded unless debugging and "^B"('\2') ensures no
213   ordinary symbol SHOULD get the same name as a local label
214   symbol. The first "4:" is "L4^B1" - the m numbers begin at 1. */
215
216char *				/* Return local label name.  */
217fb_label_name (int32_t n,	/* We just saw "n:", "nf" or "nb" : n a number.  */
218	       int32_t augend	/* 0 for nb, 1 for n:, nf.  */)
219{
220  int32_t i;
221  /* Returned to caller, then copied.  Used for created names ("4f").  */
222  static char symbol_name_build[24];
223  register char *p;
224  register char *q;
225  char symbol_name_temporary[20];	/* Build up a number, BACKWARDS.  */
226
227  know (n >= 0);
228#ifdef TC_MMIX
229  know ((uint32_t) augend <= 2 /* See mmix_fb_label.  */);
230#else
231  know ((uint32_t) augend <= 1);
232#endif
233  p = symbol_name_build;
234#ifdef LOCAL_LABEL_PREFIX
235  *p++ = LOCAL_LABEL_PREFIX;
236#endif
237  *p++ = 'L';
238
239  /* Next code just does sprintf( {}, "%d", n);  */
240  /* Label number.  */
241  q = symbol_name_temporary;
242  for (*q++ = 0, i = n; i; ++q)
243    {
244      *q = i % 10 + '0';
245      i /= 10;
246    }
247  while ((*p = *--q) != '\0')
248    ++p;
249
250  *p++ = LOCAL_LABEL_CHAR;		/* ^B  */
251
252  /* Instance number.  */
253  q = symbol_name_temporary;
254  for (*q++ = 0, i = fb_label_instance (n) + augend; i; ++q)
255    {
256      *q = i % 10 + '0';
257      i /= 10;
258    }
259  while ((*p++ = *--q) != '\0');
260
261  /* The label, as a '\0' ended string, starts at symbol_name_build.  */
262  return (symbol_name_build);
263}
264
265/* Decode name that may have been generated by foo_label_name() above.
266   If the name wasn't generated by foo_label_name(), then return it
267   unaltered.  This is used for error messages.  */
268
269char *
270decode_local_label_name (char *s)
271{
272  char *p;
273  char *symbol_decode;
274  int label_number;
275  int instance_number;
276  char *type;
277  int index = 0;
278
279#ifdef LOCAL_LABEL_PREFIX
280  if (s[index] == LOCAL_LABEL_PREFIX)
281    ++index;
282#endif
283
284  if (s[index] != 'L')
285    return s;
286
287  for (label_number = 0, p = s + index + 1; isdigit (*p); ++p)
288    label_number = (10 * label_number) + *p - '0';
289
290  if (*p == LOCAL_LABEL_CHAR)
291    type = "fb";
292  else
293    return s;
294
295  for (instance_number = 0, p++; isdigit (*p); ++p)
296    instance_number = (10 * instance_number) + *p - '0';
297
298#define MESSAGE_FORMAT "\"%d\" (instance number %d of a %s label)"
299  symbol_decode = obstack_alloc (&notes, strlen (MESSAGE_FORMAT) + 30);
300  sprintf (symbol_decode, MESSAGE_FORMAT, label_number, instance_number, type);
301
302  return symbol_decode;
303}
304
305void
306local_colon(
307int n)	/* just saw "n:" */
308{
309  fb_label_instance_inc (n);
310  colon (fb_label_name (n, 0), 1);
311}
312
313/*
314 *			symbol_new()
315 *
316 * Return a pointer to a new symbol.
317 * Die if we can't make a new symbol.
318 * Fill in the symbol's values.
319 * Add symbol to end of symbol chain.
320 *
321 *
322 * Please always call this to create a new symbol.
323 *
324 * Changes since 1985: Symbol names may not contain '\0'. Sigh.
325 */
326symbolS *
327symbol_new(
328char	       *name,	/* We copy this: OK to alter your copy. */
329unsigned char	type,	/* As in <nlist.h>. */
330char		other,	/* As in <nlist.h>. */
331short		desc,	/* As in <nlist.h>. */
332valueT		value,	/* As in <nlist.h>, often an address. */
333			/* Often used as offset from frag address. */
334struct frag    *frag)	/* For sy_frag. */
335{
336  register symbolS *		symbolP;
337  register char *		preserved_copy_of_name;
338  register unsigned int		name_length;
339           char *		p;
340
341  name_length = strlen(name) + 1;
342  obstack_grow(&notes,name,name_length);
343  p=obstack_finish(&notes);
344  /* obstack_1done( &notes, name, name_length, &p ); */
345  preserved_copy_of_name = p;
346  p=obstack_alloc(&notes,sizeof(struct symbol));
347  /* obstack_1blank( &notes, sizeof(struct symbol), &p ); */
348  symbolP			= (symbolS *) p;
349  symbolP -> sy_name		= preserved_copy_of_name;
350  symbolP -> sy_type		= type;
351  symbolP -> sy_other		= other;
352  symbolP -> sy_desc		= desc;
353  symbolP -> sy_value		= value;
354  symbolP -> sy_frag		= frag;
355  symbolP -> sy_prev_by_index	= NULL; /* Don't know what this is yet. */
356  symbolP -> sy_has_been_resolved = 0;
357  symbolP -> sy_next		= NULL;	/* End of chain. */
358  symbolP -> sy_forward		= NULL; /* JF */
359  symbolP -> expression		= NULL;
360#ifdef SUSPECT
361  symbolP -> sy_name_offset	= ~ 0; /* Impossible offset catches errors. */
362  symbolP -> sy_number		= ~ 0; /* Ditto. */
363#endif
364  /*
365   * Link to end of symbol chain.
366   */
367  if (symbol_lastP)
368    {
369      symbol_lastP -> sy_next = symbolP;
370    }
371  else
372    {
373      symbol_rootP = symbolP;
374    }
375  symbol_lastP = symbolP;
376
377  return (symbolP);
378}
379
380/* FROM line 136 */
381symbolS *
382symbol_create (const char *name, /* It is copied, the caller can destroy/modify.  */
383	       segT segment,	/* Segment identifier (SEG_<something>).  */
384	       valueT valu,	/* Symbol value.  */
385	       fragS *frag	/* Associated fragment.  */)
386{
387  /* FIXME */
388  return symbol_new ((char *)name, 0, segment, 0, valu, frag);
389}
390
391/*
392 *			symbol_assign_index()
393 *
394 * Assigns the next index to the given symbol.
395 *
396 * Asserts that the symbol has not been assigned an index yet.
397 *
398 */
399void
400symbol_assign_index(
401struct symbol *symbolP)
402{
403  if (symbolP->sy_prev_by_index != NULL)
404    {
405      as_fatal("symbol %s already has an index", symbolP->sy_name);
406    }
407  symbolP->sy_prev_by_index = symbol_lastIndexedP;
408  symbol_lastIndexedP = symbolP;
409}
410
411/*
412 *			colon()
413 *
414 * We have just seen "<name>:".
415 * Creates a struct symbol unless it already exists.
416 *
417 * Gripes if we are redefining a symbol incompatibly (and ignores it).
418 *
419 */
420/* This is used to work around compiler optimizer bug #50416 */
421static volatile unsigned int temp;
422
423void
424colon(		/* just seen "x:" - rattle symbols & frags */
425char *sym_name, /* symbol name, as a cannonical string */
426		/* We copy this string: OK to alter later. */
427int local_colon)/* non-zero if called from local_colon() */
428{
429  register struct symbol * symbolP; /* symbol we are working with */
430
431  if (frchain_now == NULL)
432    {
433      know(flagseen['n']);
434      as_fatal("with -n a section directive must be seen before assembly "
435	       "can begin");
436    }
437  if (inlineasm_checks && local_colon == 0)
438   {
439     if (inlineasm_file_name)
440       as_warn_where_with_column(inlineasm_file_name, inlineasm_line_number,
441		    inlineasm_column_number, "label definition in inlineasm");
442     else
443       as_bad("label definition in inlineasm");
444   }
445  if ((symbolP = symbol_table_lookup( sym_name )))
446    {
447      /*
448       *	Now check for undefined symbols
449       */
450      if ((symbolP -> sy_type & N_TYPE) == N_UNDF)
451	{
452	  temp = symbolP->sy_desc;
453	  if(   symbolP -> sy_other == 0
454	     /* bug #50416 -O causes this not to work for:
455	     && ((symbolP->sy_desc) & (~REFERENCE_TYPE)) == 0
456	     */
457	     && (temp & (~(REFERENCE_TYPE | N_WEAK_REF | N_WEAK_DEF |
458			   N_ARM_THUMB_DEF | N_SYMBOL_RESOLVER |
459			   N_NO_DEAD_STRIP | REFERENCED_DYNAMICALLY))) == 0
460	     && symbolP -> sy_value == 0)
461	    {
462	      symbolP -> sy_frag  = frag_now;
463	      symbolP -> sy_value = obstack_next_free(& frags) - frag_now -> fr_literal;
464	      know( N_UNDF == 0 );
465	      symbolP -> sy_type |= N_SECT; /* keep N_EXT bit */
466	      symbolP -> sy_other = frchain_now->frch_nsect;
467	      symbolP -> sy_desc &= ~REFERENCE_TYPE;
468	      symbolP -> sy_desc &= ~(N_WEAK_REF & N_WEAK_DEF);
469	      symbol_assign_index(symbolP);
470#ifdef NeXT_MOD	/* generate stabs for debugging assembly code */
471	      if(flagseen['g'])
472		  make_stab_for_symbol(symbolP);
473#endif
474	      if(debug_type == DEBUG_DWARF2)
475		  make_subprogram_for_symbol(symbolP);
476	    }
477	  else
478	    {
479	      as_fatal( "Symbol \"%s\" is already defined as \"%s\"/%d.%d."
480			TA_DFMT ".",
481		      sym_name,
482		      seg_name [(int) N_TYPE_seg [symbolP -> sy_type & N_TYPE]],
483		      symbolP -> sy_other, symbolP -> sy_desc,
484		      symbolP -> sy_value);
485	    }
486	}
487      else
488	{
489	  as_fatal("Symbol %s already defined.",sym_name);
490	}
491    }
492  else
493    {
494      symbolP = symbol_new (sym_name,
495			    N_SECT,
496	      		    frchain_now->frch_nsect,
497			    0,
498			    (valueT)(obstack_next_free(&frags)-frag_now->fr_literal),
499			    frag_now);
500      symbol_table_insert (symbolP);
501      symbol_assign_index (symbolP);
502#ifdef NeXT_MOD	/* generate stabs for debugging assembly code */
503      if(flagseen['g'])
504	  make_stab_for_symbol(symbolP);
505#endif
506      if(debug_type == DEBUG_DWARF2)
507	  make_subprogram_for_symbol(symbolP);
508    }
509#ifdef tc_frob_label
510    tc_frob_label(symbolP);
511#endif
512}
513
514
515/*
516 *			symbol_table_insert()
517 *
518 * Die if we can't insert the symbol.
519 *
520 */
521void
522symbol_table_insert(
523struct symbol *symbolP)
524{
525  const char *	error_string;
526
527  know( symbolP );
528  know( symbolP -> sy_name );
529  error_string = hash_jam (sy_hash, symbolP -> sy_name, (char *)symbolP);
530  if (error_string != NULL && error_string[0] != '\0')
531    {
532      as_fatal( "Inserting \"%s\" into symbol table failed: %s",
533	      symbolP -> sy_name, error_string);
534    }
535}
536
537/*
538 *			symbol_find_or_make()
539 *
540 * If a symbol name does not exist, create it as undefined, and insert
541 * it into the symbol table. Return a pointer to it.
542 */
543symbolS *
544symbol_find_or_make(
545char *name)
546{
547  register symbolS *	symbolP;
548
549  symbolP = symbol_table_lookup (name);
550  if (symbolP == NULL)
551    {
552      symbolP = symbol_new (name, N_UNDF, 0, 0, 0, & zero_address_frag);
553      symbol_table_insert (symbolP);
554    }
555  return (symbolP);
556}
557
558/*
559 *			symbol_find()
560 *
561 * Implement symbol table lookup.
562 * In:	A symbol's name as a string: '\0' can't be part of a symbol name.
563 * Out:	NULL if the name was not in the symbol table, else the address
564 *	of a struct symbol associated with that name.
565 */
566symbolS *
567symbol_find(
568char *name)
569{
570  return ( (symbolS *) hash_find( sy_hash, name ));
571}
572
573/*
574 *			symbol_table_lookup()
575 *
576 * Same as symbol_find() except assumes the symbol is being looked up and is
577 * a non-lazy symbol reference.
578 */
579symbolS *
580symbol_table_lookup(
581char *name)
582{
583  register symbolS *	symbolP;
584
585  symbolP = (symbolS *) hash_find( sy_hash, name );
586  if(symbolP != NULL)
587    symbolP->sy_desc &= ~REFERENCE_FLAG_UNDEFINED_LAZY;
588  return(symbolP);
589}
590
591#ifdef NeXT_MOD	/* generate stabs for debugging assembly code */
592/*
593 * make_stab_for_symbol() is called when -g is present for a label that is
594 * being defined.  If the label is a text label and in the (__TEXT,__text)
595 * section and not a local label create a stab for it.
596 *
597 * See the detailed comments about stabs in read_a_source_file() for a
598 * description of what is going on here.
599 */
600static
601void
602make_stab_for_symbol(
603symbolS *symbolP)
604{
605    symbolS *stab;
606    int stabnamelen;
607    char *stabname;
608
609	if(symbolP->sy_name[0] == 'L')
610	    return;
611	if((symbolP->sy_type & N_TYPE) != N_SECT)
612	    return;
613	if(symbolP->sy_other != text_nsect)
614	    return;
615
616	stabnamelen = strlen(symbolP->sy_name) + sizeof(":f3");
617	stabname = xmalloc(stabnamelen);
618	strcpy(stabname, symbolP->sy_name);
619	if(symbolP->sy_type & N_EXT)
620	    strcat(stabname, ":F3");
621	else
622	    strcat(stabname, ":f3");
623
624	stab = symbol_new(
625		stabname,
626		36, /* N_FUN */
627		text_nsect, /* n_sect */
628		logical_input_line, /* n_desc, line number */
629		symbolP->sy_value,
630		symbolP->sy_frag);
631	free(stabname);
632}
633#endif /* NeXT generate stabs for debugging assembly code */
634
635/*
636 * make_subprogram_for_symbol() gathers the info that is needed for each
637 * symbol that will have a dwarf2_subprogram when generating dwarf debugging
638 * info for assembly files.
639 */
640static
641void
642make_subprogram_for_symbol(
643symbolS *symbolP)
644{
645    struct dwarf2_subprogram_info *i;
646    static struct dwarf2_subprogram_info *last_dwarf2_subprogram_info = NULL;
647
648	if(symbolP->sy_name[0] == 'L')
649	    return;
650	if((symbolP->sy_type & N_TYPE) != N_SECT)
651	    return;
652	if(symbolP->sy_other != text_nsect)
653	    return;
654
655	i = xmalloc(sizeof(struct dwarf2_subprogram_info));
656	i->name = symbolP->sy_name;
657	if(i->name[0] == '_')
658	    i->name++;
659	i->file_number = dwarf2_file_number;
660	i->line_number = logical_input_line;
661	/*
662	 * We can't used the symbolP directly as it may have the N_ARM_THUMB_DEF
663	 * bit set.  And that will cause the AT_high_pc and AT_low_pc values to
664	 * have the low bit set after relocation producing bad dwarf.  So we
665	 * create a temporary symbol that will not have the N_ARM_THUMB_DEF bit
666	 * set.
667	 */
668	i->symbol = symbol_temp_new(symbolP->sy_other, symbolP->sy_value,
669				    symbolP->sy_frag);
670	i->next = NULL;
671	if(dwarf2_subprograms_info == NULL){
672	    dwarf2_subprograms_info = i;
673	    last_dwarf2_subprogram_info = i;
674	}
675	else{
676	    last_dwarf2_subprogram_info->next = i;
677	    last_dwarf2_subprogram_info = i;
678	}
679}
680
681/*
682 * indirect_symbol_new()
683 *
684 * Return a pointer to a new indirect_symbol.
685 * Die if we can't make a new indirect_symbol.
686 * Fill in the indirect_symbol's values.
687 * Add symbol to end of section's indirect symbol chain.
688 */
689isymbolS *
690indirect_symbol_new(
691char	       *name,	  /* We copy this: OK to alter your copy. */
692struct frag    *frag,	  /* For sy_frag. */
693uint32_t	offset)	  /* Offset from frag address. */
694{
695    isymbolS *isymbolP;
696    char *preserved_copy_of_name;
697    uint32_t name_length;
698    char *p;
699    struct frag *fr_next;
700    symbolS *symbolP;
701#ifdef CHECK_INDIRECTS
702    uint32_t stride, fr_fix;
703#endif
704
705	/*
706	 * First see if the last frag recorded for an indirect symbol turned
707	 * out to be zero sized then changed that recorded frag to the next
708	 * non-zero frag in the list.  I think this happens because we record
709	 * the frag before we fill it and if we run out of space that frag gets
710	 * a zero size and a new one is created.
711	 */
712	if(frchain_now->frch_isym_last != NULL &&
713	   frchain_now->frch_isym_last->isy_frag->fr_fix == 0){
714	    if(frchain_now->frch_isym_last->isy_frag->fr_next != NULL){
715		fr_next = frchain_now->frch_isym_last->isy_frag->fr_next;
716		while(fr_next->fr_fix == 0 &&
717		      fr_next->fr_type == rs_fill &&
718		      fr_next->fr_next != NULL)
719			fr_next = fr_next->fr_next;
720		frchain_now->frch_isym_last->isy_frag = fr_next;
721	    }
722	}
723
724	name_length = strlen(name) + 1;
725	obstack_grow(&notes, name, name_length);
726	p = obstack_finish(&notes);
727	preserved_copy_of_name = p;
728	p = obstack_alloc(&notes, sizeof(struct indirect_symbol));
729	isymbolP = (isymbolS *)p;
730	isymbolP->isy_name    = preserved_copy_of_name;
731	isymbolP->isy_offset  = offset;
732	isymbolP->isy_frag    = frag;
733	isymbolP->isy_next    = NULL;	/* End of chain. */
734	isymbolP->isy_symbol  = NULL;
735
736	/*
737	 * Link to end of indirect symbol chain and check for missing indirect
738	 * symbols.
739	 */
740	if(frchain_now->frch_isym_root == NULL){
741#ifdef CHECK_INDIRECTS
742	    if(offset != 0)
743		as_bad("missing or bad indirect symbol for section (%s,%s)",
744			frchain_now->frch_section.segname,
745			frchain_now->frch_section.sectname);
746#endif
747	    frchain_now->frch_isym_root = isymbolP;
748	    frchain_now->frch_isym_last = isymbolP;
749	}
750	else{
751#ifdef CHECK_INDIRECTS
752	    if((frchain_now->frch_section.flags & SECTION_TYPE) ==
753	       S_SYMBOL_STUBS)
754		stride = frchain_now->frch_section.reserved2;
755	    else
756		stride = sizeof(uint32_t);
757	    if(frag == frchain_now->frch_isym_last->isy_frag){
758		if(offset - frchain_now->frch_isym_last->isy_offset != stride)
759		    as_bad("missing or bad indirect symbol for section "
760			    "(%s,%s)", frchain_now->frch_section.segname,
761			    frchain_now->frch_section.sectname);
762	    }
763	    else{
764		if(frchain_now->frch_isym_last->isy_frag->fr_fix < stride){
765		    fr_fix = 0;
766		    fr_next = frchain_now->frch_isym_last->isy_frag;
767		    while(fr_fix + fr_next->fr_fix < stride &&
768			  fr_next->fr_type == rs_fill &&
769			  fr_next->fr_next != NULL){
770			fr_fix += fr_next->fr_fix;
771			fr_next = fr_next->fr_next;
772		    }
773		    if(frag != fr_next->fr_next ||
774		       fr_fix + fr_next->fr_fix != stride ||
775		       offset != 0)
776			as_bad("missing or bad indirect symbol for section "
777				"(%s,%s)", frchain_now->frch_section.segname,
778				frchain_now->frch_section.sectname);
779		}
780		else{
781		    fr_next = frchain_now->frch_isym_last->isy_frag->fr_next;
782		    /*
783		     * Because of section changes there maybe some zero length
784		     * frags after the last one that passed through here.  So
785		     * skip them and get to the last real one.
786		     */
787		    while(fr_next->fr_fix == 0 &&
788			  fr_next->fr_type == rs_fill &&
789			  fr_next->fr_next != NULL)
790			fr_next = fr_next->fr_next;
791		    if(frag != fr_next || offset != 0)
792			as_bad("missing or bad indirect symbol for section "
793				"(%s,%s)", frchain_now->frch_section.segname,
794				frchain_now->frch_section.sectname);
795		}
796	    }
797#endif
798	    frchain_now->frch_isym_last->isy_next = isymbolP;
799	    frchain_now->frch_isym_last = isymbolP;
800	}
801	if((frchain_now->frch_section.flags & SECTION_TYPE) ==
802	   S_NON_LAZY_SYMBOL_POINTERS){
803	    symbolP = (symbolS *)hash_find(sy_hash, name);
804	    if(symbolP != NULL)
805		symbolP->sy_desc &= ~REFERENCE_FLAG_UNDEFINED_LAZY;
806	}
807	return(isymbolP);
808}
809
810const char *
811S_GET_NAME (symbolS *s)
812{
813  return s->sy_name;
814}
815
816int
817S_IS_DEFINED (symbolS *s)
818{
819  return (s->sy_type & N_TYPE) != N_UNDF;
820}
821
822/* FROM line 2317 */
823#ifdef TC_SYMFIELD_TYPE
824
825/* Get a pointer to the processor information for a symbol.  */
826
827TC_SYMFIELD_TYPE *
828symbol_get_tc (symbolS *s)
829{
830  return &s->sy_tc;
831}
832
833/* Set the processor information for a symbol.  */
834
835void
836symbol_set_tc (symbolS *s, TC_SYMFIELD_TYPE *o)
837{
838  s->sy_tc = *o;
839}
840
841#endif /* TC_SYMFIELD_TYPE */
842
843int
844S_IS_LOCAL (symbolS *s)
845{
846    const char *name;
847
848	name = S_GET_NAME (s);
849	if(name == NULL)
850	    return(1);
851
852	if(name[0] == 'L' && flagseen['L'] == FALSE)
853	    return(1);
854	else
855	    return(0);
856}
857
858fragS *
859symbol_get_frag (symbolS *s)
860{
861	return(s->sy_frag);
862}
863
864/*
865 * symbol_temp_new(), symbol_temp_new_now() are used by dwarf2dbg.c to make
866 * symbols in dwarf sections.  symbol_temp_make() is used to make an undefined
867 * symbol that its values are later set by symbol_set_value_now() to the current
868 * address in a dwarf section.
869 *
870 * These are used in expressions, so the expression values can be put out in
871 * dwarf section contents.
872 */
873symbolS *
874symbol_temp_new(
875segT nsect,
876valueT value,
877struct frag *frag)
878{
879    return(symbol_new(FAKE_LABEL_NAME, N_SECT, nsect, 0, value, frag));
880}
881
882symbolS *
883symbol_temp_new_now(void)
884{
885    return(symbol_temp_new(now_seg, frag_now_fix(), frag_now));
886}
887
888symbolS *
889symbol_temp_make(void)
890{
891    return(symbol_new(FAKE_LABEL_NAME, N_UNDF, 0, 0, 0, & zero_address_frag));
892}
893
894/* Set the value of SYM to the current position in the current segment.  */
895void
896symbol_set_value_now(
897symbolS *sym)
898{
899    sym->sy_type = N_SECT;
900    sym->sy_other = now_seg;
901    sym->sy_value = frag_now_fix();
902    sym->sy_frag = frag_now;
903}
904
905/* end: symbols.c */
906