-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbols.c
3200 lines (2716 loc) · 81.1 KB
/
symbols.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* symbols.c -symbol table-
Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
GAS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to the Free
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
/* #define DEBUG_SYMS / * to debug symbol list maintenance. */
#include "as.h"
#include "safe-ctype.h"
#include "obstack.h" /* For "symbols.h" */
#include "subsegs.h"
#include "struc-symbol.h"
/* This is non-zero if symbols are case sensitive, which is the
default. */
int symbols_case_sensitive = 1;
#ifndef WORKING_DOT_WORD
extern int new_broken_words;
#endif
/* symbol-name => struct symbol pointer */
static struct hash_control *sy_hash;
/* Table of local symbols. */
static struct hash_control *local_hash;
/* Below are commented in "symbols.h". */
symbolS *symbol_rootP;
symbolS *symbol_lastP;
symbolS abs_symbol;
#ifdef DEBUG_SYMS
#define debug_verify_symchain verify_symbol_chain
#else
#define debug_verify_symchain(root, last) ((void) 0)
#endif
#define DOLLAR_LABEL_CHAR '\001'
#define LOCAL_LABEL_CHAR '\002'
struct obstack notes;
#ifdef TE_PE
/* The name of an external symbol which is
used to make weak PE symbol names unique. */
const char * an_external_name;
#endif
static char *save_symbol_name (const char *);
static void fb_label_init (void);
static long dollar_label_instance (long);
static long fb_label_instance (long);
static void print_binary (FILE *, const char *, expressionS *);
static void report_op_error (symbolS *, symbolS *, symbolS *);
/* Return a pointer to a new symbol. Die if we can't make a new
symbol. Fill in the symbol's values. Add symbol to end of symbol
chain.
This function should be called in the general case of creating a
symbol. However, if the output file symbol table has already been
set, and you are certain that this symbol won't be wanted in the
output file, you can call symbol_create. */
symbolS *
symbol_new (const char *name, segT segment, valueT valu, fragS *frag)
{
symbolS *symbolP = symbol_create (name, segment, valu, frag);
/* Link to end of symbol chain. */
{
extern int symbol_table_frozen;
if (symbol_table_frozen)
abort ();
}
symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
return symbolP;
}
/* Save a symbol name on a permanent obstack, and convert it according
to the object file format. */
static char *
save_symbol_name (const char *name)
{
unsigned int name_length;
char *ret;
name_length = strlen (name) + 1; /* +1 for \0. */
obstack_grow (¬es, name, name_length);
ret = (char *) obstack_finish (¬es);
#ifdef tc_canonicalize_symbol_name
ret = tc_canonicalize_symbol_name (ret);
#endif
if (! symbols_case_sensitive)
{
char *s;
for (s = ret; *s != '\0'; s++)
*s = TOUPPER (*s);
}
return ret;
}
symbolS *
symbol_create (const char *name, /* It is copied, the caller can destroy/modify. */
segT segment, /* Segment identifier (SEG_<something>). */
valueT valu, /* Symbol value. */
fragS *frag /* Associated fragment. */)
{
char *preserved_copy_of_name;
symbolS *symbolP;
preserved_copy_of_name = save_symbol_name (name);
symbolP = (symbolS *) obstack_alloc (¬es, sizeof (symbolS));
/* symbol must be born in some fixed state. This seems as good as any. */
memset (symbolP, 0, sizeof (symbolS));
symbolP->bsym = bfd_make_empty_symbol (stdoutput);
if (symbolP->bsym == NULL)
as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
S_SET_NAME (symbolP, preserved_copy_of_name);
S_SET_SEGMENT (symbolP, segment);
S_SET_VALUE (symbolP, valu);
symbol_clear_list_pointers (symbolP);
symbolP->sy_frag = frag;
obj_symbol_new_hook (symbolP);
#ifdef tc_symbol_new_hook
tc_symbol_new_hook (symbolP);
#endif
return symbolP;
}
/* Local symbol support. If we can get away with it, we keep only a
small amount of information for local symbols. */
static symbolS *local_symbol_convert (struct local_symbol *);
/* Used for statistics. */
static unsigned long local_symbol_count;
static unsigned long local_symbol_conversion_count;
/* This macro is called with a symbol argument passed by reference.
It returns whether this is a local symbol. If necessary, it
changes its argument to the real symbol. */
#define LOCAL_SYMBOL_CHECK(s) \
(s->bsym == NULL \
? (local_symbol_converted_p ((struct local_symbol *) s) \
? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
0) \
: 1) \
: 0)
/* Create a local symbol and insert it into the local hash table. */
static struct local_symbol *
local_symbol_make (const char *name, segT section, valueT val, fragS *frag)
{
char *name_copy;
struct local_symbol *ret;
++local_symbol_count;
name_copy = save_symbol_name (name);
ret = (struct local_symbol *) obstack_alloc (¬es, sizeof *ret);
ret->lsy_marker = NULL;
ret->lsy_name = name_copy;
ret->lsy_section = section;
local_symbol_set_frag (ret, frag);
ret->lsy_value = val;
hash_jam (local_hash, name_copy, (void *) ret);
return ret;
}
/* Convert a local symbol into a real symbol. Note that we do not
reclaim the space used by the local symbol. */
static symbolS *
local_symbol_convert (struct local_symbol *locsym)
{
symbolS *ret;
gas_assert (locsym->lsy_marker == NULL);
if (local_symbol_converted_p (locsym))
return local_symbol_get_real_symbol (locsym);
++local_symbol_conversion_count;
ret = symbol_new (locsym->lsy_name, locsym->lsy_section, locsym->lsy_value,
local_symbol_get_frag (locsym));
if (local_symbol_resolved_p (locsym))
ret->sy_resolved = 1;
/* Local symbols are always either defined or used. */
ret->sy_used = 1;
#ifdef TC_LOCAL_SYMFIELD_CONVERT
TC_LOCAL_SYMFIELD_CONVERT (locsym, ret);
#endif
symbol_table_insert (ret);
local_symbol_mark_converted (locsym);
local_symbol_set_real_symbol (locsym, ret);
hash_jam (local_hash, locsym->lsy_name, NULL);
return ret;
}
static void
define_sym_at_dot (symbolS *symbolP)
{
symbolP->sy_frag = frag_now;
#ifdef OBJ_VMS
S_SET_OTHER (symbolP, const_flag);
#endif
S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
S_SET_SEGMENT (symbolP, now_seg);
}
/* We have just seen "<name>:".
Creates a struct symbol unless it already exists.
Gripes if we are redefining a symbol incompatibly (and ignores it). */
symbolS *
colon (/* Just seen "x:" - rattle symbols & frags. */
const char *sym_name /* Symbol name, as a cannonical string. */
/* We copy this string: OK to alter later. */)
{
register symbolS *symbolP; /* Symbol we are working with. */
/* Sun local labels go out of scope whenever a non-local symbol is
defined. */
if (LOCAL_LABELS_DOLLAR
&& !bfd_is_local_label_name (stdoutput, sym_name))
dollar_label_clear ();
#ifndef WORKING_DOT_WORD
if (new_broken_words)
{
struct broken_word *a;
int possible_bytes;
fragS *frag_tmp;
char *frag_opcode;
if (now_seg == absolute_section)
{
as_bad (_("cannot define symbol `%s' in absolute section"), sym_name);
return NULL;
}
possible_bytes = (md_short_jump_size
+ new_broken_words * md_long_jump_size);
frag_tmp = frag_now;
frag_opcode = frag_var (rs_broken_word,
possible_bytes,
possible_bytes,
(relax_substateT) 0,
(symbolS *) broken_words,
(offsetT) 0,
NULL);
/* We want to store the pointer to where to insert the jump
table in the fr_opcode of the rs_broken_word frag. This
requires a little hackery. */
while (frag_tmp
&& (frag_tmp->fr_type != rs_broken_word
|| frag_tmp->fr_opcode))
frag_tmp = frag_tmp->fr_next;
know (frag_tmp);
frag_tmp->fr_opcode = frag_opcode;
new_broken_words = 0;
for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word)
a->dispfrag = frag_tmp;
}
#endif /* WORKING_DOT_WORD */
if ((symbolP = symbol_find (sym_name)) != 0)
{
S_CLEAR_WEAKREFR (symbolP);
#ifdef RESOLVE_SYMBOL_REDEFINITION
if (RESOLVE_SYMBOL_REDEFINITION (symbolP))
return symbolP;
#endif
/* Now check for undefined symbols. */
if (LOCAL_SYMBOL_CHECK (symbolP))
{
struct local_symbol *locsym = (struct local_symbol *) symbolP;
if (locsym->lsy_section != undefined_section
&& (local_symbol_get_frag (locsym) != frag_now
|| locsym->lsy_section != now_seg
|| locsym->lsy_value != frag_now_fix ()))
{
as_bad (_("symbol `%s' is already defined"), sym_name);
return symbolP;
}
locsym->lsy_section = now_seg;
local_symbol_set_frag (locsym, frag_now);
locsym->lsy_value = frag_now_fix ();
}
else if (!(S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
|| S_IS_COMMON (symbolP)
|| S_IS_VOLATILE (symbolP))
{
if (S_IS_VOLATILE (symbolP))
{
symbolP = symbol_clone (symbolP, 1);
S_SET_VALUE (symbolP, 0);
S_CLEAR_VOLATILE (symbolP);
}
if (S_GET_VALUE (symbolP) == 0)
{
define_sym_at_dot (symbolP);
#ifdef N_UNDF
know (N_UNDF == 0);
#endif /* if we have one, it better be zero. */
}
else
{
/* There are still several cases to check:
A .comm/.lcomm symbol being redefined as initialized
data is OK
A .comm/.lcomm symbol being redefined with a larger
size is also OK
This only used to be allowed on VMS gas, but Sun cc
on the sparc also depends on it. */
if (((!S_IS_DEBUG (symbolP)
&& (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
&& S_IS_EXTERNAL (symbolP))
|| S_GET_SEGMENT (symbolP) == bss_section)
&& (now_seg == data_section
|| now_seg == bss_section
|| now_seg == S_GET_SEGMENT (symbolP)))
{
/* Select which of the 2 cases this is. */
if (now_seg != data_section)
{
/* New .comm for prev .comm symbol.
If the new size is larger we just change its
value. If the new size is smaller, we ignore
this symbol. */
if (S_GET_VALUE (symbolP)
< ((unsigned) frag_now_fix ()))
{
S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
}
}
else
{
/* It is a .comm/.lcomm being converted to initialized
data. */
define_sym_at_dot (symbolP);
}
}
else
{
#if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
&& !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
static const char *od_buf = "";
#else
char od_buf[100];
od_buf[0] = '\0';
if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
sprintf (od_buf, "%d.%d.",
S_GET_OTHER (symbolP),
S_GET_DESC (symbolP));
#endif
as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
sym_name,
segment_name (S_GET_SEGMENT (symbolP)),
od_buf,
(long) S_GET_VALUE (symbolP));
}
} /* if the undefined symbol has no value */
}
else
{
/* Don't blow up if the definition is the same. */
if (!(frag_now == symbolP->sy_frag
&& S_GET_VALUE (symbolP) == frag_now_fix ()
&& S_GET_SEGMENT (symbolP) == now_seg))
{
as_bad (_("symbol `%s' is already defined"), sym_name);
symbolP = symbol_clone (symbolP, 0);
define_sym_at_dot (symbolP);
}
}
}
else if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, sym_name))
{
symbolP = (symbolS *) local_symbol_make (sym_name, now_seg,
(valueT) frag_now_fix (),
frag_now);
}
else
{
symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (),
frag_now);
#ifdef OBJ_VMS
S_SET_OTHER (symbolP, const_flag);
#endif /* OBJ_VMS */
symbol_table_insert (symbolP);
}
if (mri_common_symbol != NULL)
{
/* This symbol is actually being defined within an MRI common
section. This requires special handling. */
if (LOCAL_SYMBOL_CHECK (symbolP))
symbolP = local_symbol_convert ((struct local_symbol *) symbolP);
symbolP->sy_value.X_op = O_symbol;
symbolP->sy_value.X_add_symbol = mri_common_symbol;
symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol);
symbolP->sy_frag = &zero_address_frag;
S_SET_SEGMENT (symbolP, expr_section);
symbolP->sy_mri_common = 1;
}
#ifdef tc_frob_label
tc_frob_label (symbolP);
#endif
#ifdef obj_frob_label
obj_frob_label (symbolP);
#endif
return symbolP;
}
/* Die if we can't insert the symbol. */
void
symbol_table_insert (symbolS *symbolP)
{
register const char *error_string;
know (symbolP);
know (S_GET_NAME (symbolP));
if (LOCAL_SYMBOL_CHECK (symbolP))
{
error_string = hash_jam (local_hash, S_GET_NAME (symbolP),
(void *) symbolP);
if (error_string != NULL)
as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
S_GET_NAME (symbolP), error_string);
return;
}
if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (void *) symbolP)))
{
as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
S_GET_NAME (symbolP), error_string);
} /* on error */
}
/* If a symbol name does not exist, create it as undefined, and insert
it into the symbol table. Return a pointer to it. */
symbolS *
symbol_find_or_make (const char *name)
{
register symbolS *symbolP;
symbolP = symbol_find (name);
if (symbolP == NULL)
{
if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, name))
{
symbolP = md_undefined_symbol ((char *) name);
if (symbolP != NULL)
return symbolP;
symbolP = (symbolS *) local_symbol_make (name, undefined_section,
(valueT) 0,
&zero_address_frag);
return symbolP;
}
symbolP = symbol_make (name);
symbol_table_insert (symbolP);
} /* if symbol wasn't found */
return (symbolP);
}
symbolS *
symbol_make (const char *name)
{
symbolS *symbolP;
/* Let the machine description default it, e.g. for register names. */
symbolP = md_undefined_symbol ((char *) name);
if (!symbolP)
symbolP = symbol_new (name, undefined_section, (valueT) 0, &zero_address_frag);
return (symbolP);
}
symbolS *
symbol_clone (symbolS *orgsymP, int replace)
{
symbolS *newsymP;
asymbol *bsymorg, *bsymnew;
/* Running local_symbol_convert on a clone that's not the one currently
in local_hash would incorrectly replace the hash entry. Thus the
symbol must be converted here. Note that the rest of the function
depends on not encountering an unconverted symbol. */
if (LOCAL_SYMBOL_CHECK (orgsymP))
orgsymP = local_symbol_convert ((struct local_symbol *) orgsymP);
bsymorg = orgsymP->bsym;
newsymP = (symbolS *) obstack_alloc (¬es, sizeof (*newsymP));
*newsymP = *orgsymP;
bsymnew = bfd_make_empty_symbol (bfd_asymbol_bfd (bsymorg));
if (bsymnew == NULL)
as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
newsymP->bsym = bsymnew;
bsymnew->name = bsymorg->name;
bsymnew->flags = bsymorg->flags & ~BSF_SECTION_SYM;
bsymnew->section = bsymorg->section;
bfd_copy_private_symbol_data (bfd_asymbol_bfd (bsymorg), bsymorg,
bfd_asymbol_bfd (bsymnew), bsymnew);
#ifdef obj_symbol_clone_hook
obj_symbol_clone_hook (newsymP, orgsymP);
#endif
#ifdef tc_symbol_clone_hook
tc_symbol_clone_hook (newsymP, orgsymP);
#endif
if (replace)
{
if (symbol_rootP == orgsymP)
symbol_rootP = newsymP;
else if (orgsymP->sy_previous)
{
orgsymP->sy_previous->sy_next = newsymP;
orgsymP->sy_previous = NULL;
}
if (symbol_lastP == orgsymP)
symbol_lastP = newsymP;
else if (orgsymP->sy_next)
orgsymP->sy_next->sy_previous = newsymP;
/* Symbols that won't be output can't be external. */
S_CLEAR_EXTERNAL (orgsymP);
orgsymP->sy_previous = orgsymP->sy_next = orgsymP;
debug_verify_symchain (symbol_rootP, symbol_lastP);
symbol_table_insert (newsymP);
}
else
{
/* Symbols that won't be output can't be external. */
S_CLEAR_EXTERNAL (newsymP);
newsymP->sy_previous = newsymP->sy_next = newsymP;
}
return newsymP;
}
/* Referenced symbols, if they are forward references, need to be cloned
(without replacing the original) so that the value of the referenced
symbols at the point of use . */
#undef symbol_clone_if_forward_ref
symbolS *
symbol_clone_if_forward_ref (symbolS *symbolP, int is_forward)
{
if (symbolP && !LOCAL_SYMBOL_CHECK (symbolP))
{
symbolS *add_symbol = symbolP->sy_value.X_add_symbol;
symbolS *op_symbol = symbolP->sy_value.X_op_symbol;
if (symbolP->sy_forward_ref)
is_forward = 1;
if (is_forward)
{
/* assign_symbol() clones volatile symbols; pre-existing expressions
hold references to the original instance, but want the current
value. Just repeat the lookup. */
if (add_symbol && S_IS_VOLATILE (add_symbol))
add_symbol = symbol_find_exact (S_GET_NAME (add_symbol));
if (op_symbol && S_IS_VOLATILE (op_symbol))
op_symbol = symbol_find_exact (S_GET_NAME (op_symbol));
}
/* Re-using sy_resolving here, as this routine cannot get called from
symbol resolution code. */
if (symbolP->bsym->section == expr_section && !symbolP->sy_resolving)
{
symbolP->sy_resolving = 1;
add_symbol = symbol_clone_if_forward_ref (add_symbol, is_forward);
op_symbol = symbol_clone_if_forward_ref (op_symbol, is_forward);
symbolP->sy_resolving = 0;
}
if (symbolP->sy_forward_ref
|| add_symbol != symbolP->sy_value.X_add_symbol
|| op_symbol != symbolP->sy_value.X_op_symbol)
symbolP = symbol_clone (symbolP, 0);
symbolP->sy_value.X_add_symbol = add_symbol;
symbolP->sy_value.X_op_symbol = op_symbol;
}
return symbolP;
}
symbolS *
symbol_temp_new (segT seg, valueT ofs, fragS *frag)
{
return symbol_new (FAKE_LABEL_NAME, seg, ofs, frag);
}
symbolS *
symbol_temp_new_now (void)
{
return symbol_temp_new (now_seg, frag_now_fix (), frag_now);
}
symbolS *
symbol_temp_make (void)
{
return symbol_make (FAKE_LABEL_NAME);
}
/* Implement symbol table lookup.
In: A symbol's name as a string: '\0' can't be part of a symbol name.
Out: NULL if the name was not in the symbol table, else the address
of a struct symbol associated with that name. */
symbolS *
symbol_find_exact (const char *name)
{
return symbol_find_exact_noref (name, 0);
}
symbolS *
symbol_find_exact_noref (const char *name, int noref)
{
struct local_symbol *locsym;
symbolS* sym;
locsym = (struct local_symbol *) hash_find (local_hash, name);
if (locsym != NULL)
return (symbolS *) locsym;
sym = ((symbolS *) hash_find (sy_hash, name));
/* Any references to the symbol, except for the reference in
.weakref, must clear this flag, such that the symbol does not
turn into a weak symbol. Note that we don't have to handle the
local_symbol case, since a weakrefd is always promoted out of the
local_symbol table when it is turned into a weak symbol. */
if (sym && ! noref)
S_CLEAR_WEAKREFD (sym);
return sym;
}
symbolS *
symbol_find (const char *name)
{
return symbol_find_noref (name, 0);
}
symbolS *
symbol_find_noref (const char *name, int noref)
{
#ifdef tc_canonicalize_symbol_name
{
char *copy;
size_t len = strlen (name) + 1;
copy = (char *) alloca (len);
memcpy (copy, name, len);
name = tc_canonicalize_symbol_name (copy);
}
#endif
if (! symbols_case_sensitive)
{
char *copy;
const char *orig;
unsigned char c;
orig = name;
name = copy = (char *) alloca (strlen (name) + 1);
while ((c = *orig++) != '\0')
{
*copy++ = TOUPPER (c);
}
*copy = '\0';
}
return symbol_find_exact_noref (name, noref);
}
/* Once upon a time, symbols were kept in a singly linked list. At
least coff needs to be able to rearrange them from time to time, for
which a doubly linked list is much more convenient. Loic did these
as macros which seemed dangerous to me so they're now functions.
xoxorich. */
/* Link symbol ADDME after symbol TARGET in the chain. */
void
symbol_append (symbolS *addme, symbolS *target,
symbolS **rootPP, symbolS **lastPP)
{
if (LOCAL_SYMBOL_CHECK (addme))
abort ();
if (target != NULL && LOCAL_SYMBOL_CHECK (target))
abort ();
if (target == NULL)
{
know (*rootPP == NULL);
know (*lastPP == NULL);
addme->sy_next = NULL;
addme->sy_previous = NULL;
*rootPP = addme;
*lastPP = addme;
return;
} /* if the list is empty */
if (target->sy_next != NULL)
{
target->sy_next->sy_previous = addme;
}
else
{
know (*lastPP == target);
*lastPP = addme;
} /* if we have a next */
addme->sy_next = target->sy_next;
target->sy_next = addme;
addme->sy_previous = target;
debug_verify_symchain (symbol_rootP, symbol_lastP);
}
/* Set the chain pointers of SYMBOL to null. */
void
symbol_clear_list_pointers (symbolS *symbolP)
{
if (LOCAL_SYMBOL_CHECK (symbolP))
abort ();
symbolP->sy_next = NULL;
symbolP->sy_previous = NULL;
}
/* Remove SYMBOLP from the list. */
void
symbol_remove (symbolS *symbolP, symbolS **rootPP, symbolS **lastPP)
{
if (LOCAL_SYMBOL_CHECK (symbolP))
abort ();
if (symbolP == *rootPP)
{
*rootPP = symbolP->sy_next;
} /* if it was the root */
if (symbolP == *lastPP)
{
*lastPP = symbolP->sy_previous;
} /* if it was the tail */
if (symbolP->sy_next != NULL)
{
symbolP->sy_next->sy_previous = symbolP->sy_previous;
} /* if not last */
if (symbolP->sy_previous != NULL)
{
symbolP->sy_previous->sy_next = symbolP->sy_next;
} /* if not first */
debug_verify_symchain (*rootPP, *lastPP);
}
/* Link symbol ADDME before symbol TARGET in the chain. */
void
symbol_insert (symbolS *addme, symbolS *target,
symbolS **rootPP, symbolS **lastPP ATTRIBUTE_UNUSED)
{
if (LOCAL_SYMBOL_CHECK (addme))
abort ();
if (LOCAL_SYMBOL_CHECK (target))
abort ();
if (target->sy_previous != NULL)
{
target->sy_previous->sy_next = addme;
}
else
{
know (*rootPP == target);
*rootPP = addme;
} /* if not first */
addme->sy_previous = target->sy_previous;
target->sy_previous = addme;
addme->sy_next = target;
debug_verify_symchain (*rootPP, *lastPP);
}
void
verify_symbol_chain (symbolS *rootP, symbolS *lastP)
{
symbolS *symbolP = rootP;
if (symbolP == NULL)
return;
for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP))
{
gas_assert (symbolP->bsym != NULL);
gas_assert (symbolP->sy_next->sy_previous == symbolP);
}
gas_assert (lastP == symbolP);
}
#ifdef OBJ_COMPLEX_RELC
static int
use_complex_relocs_for (symbolS * symp)
{
switch (symp->sy_value.X_op)
{
case O_constant:
return 0;
case O_symbol:
case O_symbol_rva:
case O_uminus:
case O_bit_not:
case O_logical_not:
if ( (S_IS_COMMON (symp->sy_value.X_add_symbol)
|| S_IS_LOCAL (symp->sy_value.X_add_symbol))
&&
(S_IS_DEFINED (symp->sy_value.X_add_symbol)
&& S_GET_SEGMENT (symp->sy_value.X_add_symbol) != expr_section))
return 0;
break;
case O_multiply:
case O_divide:
case O_modulus:
case O_left_shift:
case O_right_shift:
case O_bit_inclusive_or:
case O_bit_or_not:
case O_bit_exclusive_or:
case O_bit_and:
case O_add:
case O_subtract:
case O_eq:
case O_ne:
case O_lt:
case O_le:
case O_ge:
case O_gt:
case O_logical_and:
case O_logical_or:
if ( (S_IS_COMMON (symp->sy_value.X_add_symbol)
|| S_IS_LOCAL (symp->sy_value.X_add_symbol))
&&
(S_IS_COMMON (symp->sy_value.X_op_symbol)
|| S_IS_LOCAL (symp->sy_value.X_op_symbol))
&& S_IS_DEFINED (symp->sy_value.X_add_symbol)
&& S_IS_DEFINED (symp->sy_value.X_op_symbol)
&& S_GET_SEGMENT (symp->sy_value.X_add_symbol) != expr_section
&& S_GET_SEGMENT (symp->sy_value.X_op_symbol) != expr_section)
return 0;
break;
default:
break;
}
return 1;
}
#endif
static void
report_op_error (symbolS *symp, symbolS *left, symbolS *right)
{
char *file;
unsigned int line;
segT seg_left = S_GET_SEGMENT (left);
segT seg_right = right ? S_GET_SEGMENT (right) : 0;
if (expr_symbol_where (symp, &file, &line))
{
if (seg_left == undefined_section)
as_bad_where (file, line,
_("undefined symbol `%s' in operation"),
S_GET_NAME (left));
if (seg_right == undefined_section)
as_bad_where (file, line,
_("undefined symbol `%s' in operation"),
S_GET_NAME (right));
if (seg_left != undefined_section
&& seg_right != undefined_section)
{
if (right)
as_bad_where (file, line,
_("invalid sections for operation on `%s' and `%s'"),
S_GET_NAME (left), S_GET_NAME (right));
else
as_bad_where (file, line,
_("invalid section for operation on `%s'"),
S_GET_NAME (left));
}
}
else
{
if (seg_left == undefined_section)
as_bad (_("undefined symbol `%s' in operation setting `%s'"),
S_GET_NAME (left), S_GET_NAME (symp));
if (seg_right == undefined_section)
as_bad (_("undefined symbol `%s' in operation setting `%s'"),
S_GET_NAME (right), S_GET_NAME (symp));
if (seg_left != undefined_section
&& seg_right != undefined_section)
{
if (right)
as_bad (_("invalid sections for operation on `%s' and `%s' setting `%s'"),
S_GET_NAME (left), S_GET_NAME (right), S_GET_NAME (symp));
else