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
|
/* Symbol table.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
Contributed by Jan Hubicka
This file is part of GCC.
GCC 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.
GCC 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 GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "tree-inline.h"
#include "langhooks.h"
#include "hashtab.h"
#include "ggc.h"
#include "cgraph.h"
#include "diagnostic.h"
#include "timevar.h"
#include "lto-streamer.h"
#include "rtl.h"
const char * const ld_plugin_symbol_resolution_names[]=
{
"",
"undef",
"prevailing_def",
"prevailing_def_ironly",
"preempted_reg",
"preempted_ir",
"resolved_ir",
"resolved_exec",
"resolved_dyn",
"prevailing_def_ironly_exp"
};
/* Hash table used to convert declarations into nodes. */
static GTY((param_is (union symtab_node_def))) htab_t symtab_hash;
/* Hash table used to convert assembler names into nodes. */
static GTY((param_is (union symtab_node_def))) htab_t assembler_name_hash;
/* Linked list of symbol table nodes. */
symtab_node symtab_nodes;
/* The order index of the next symtab node to be created. This is
used so that we can sort the cgraph nodes in order by when we saw
them, to support -fno-toplevel-reorder. */
int symtab_order;
/* Returns a hash code for P. */
static hashval_t
hash_node (const void *p)
{
const_symtab_node n = (const_symtab_node ) p;
return (hashval_t) DECL_UID (n->symbol.decl);
}
/* Returns nonzero if P1 and P2 are equal. */
static int
eq_node (const void *p1, const void *p2)
{
const_symtab_node n1 = (const_symtab_node) p1;
const_symtab_node n2 = (const_symtab_node) p2;
return DECL_UID (n1->symbol.decl) == DECL_UID (n2->symbol.decl);
}
/* Returns a hash code for P. */
static hashval_t
hash_node_by_assembler_name (const void *p)
{
const_symtab_node n = (const_symtab_node) p;
return (hashval_t) decl_assembler_name_hash (DECL_ASSEMBLER_NAME (n->symbol.decl));
}
/* Returns nonzero if P1 and P2 are equal. */
static int
eq_assembler_name (const void *p1, const void *p2)
{
const_symtab_node n1 = (const_symtab_node) p1;
const_tree name = (const_tree)p2;
return (decl_assembler_name_equal (n1->symbol.decl, name));
}
/* Insert NODE to assembler name hash. */
static void
insert_to_assembler_name_hash (symtab_node node, bool with_clones)
{
if (is_a <varpool_node> (node) && DECL_HARD_REGISTER (node->symbol.decl))
return;
gcc_checking_assert (!node->symbol.previous_sharing_asm_name
&& !node->symbol.next_sharing_asm_name);
if (assembler_name_hash)
{
void **aslot;
struct cgraph_node *cnode;
tree decl = node->symbol.decl;
tree name = DECL_ASSEMBLER_NAME (node->symbol.decl);
aslot = htab_find_slot_with_hash (assembler_name_hash, name,
decl_assembler_name_hash (name),
INSERT);
gcc_assert (*aslot != node);
node->symbol.next_sharing_asm_name = (symtab_node)*aslot;
if (*aslot != NULL)
((symtab_node)*aslot)->symbol.previous_sharing_asm_name = node;
*aslot = node;
/* Update also possible inline clones sharing a decl. */
cnode = dyn_cast <cgraph_node> (node);
if (cnode && cnode->clones && with_clones)
for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
if (cnode->symbol.decl == decl)
insert_to_assembler_name_hash ((symtab_node) cnode, true);
}
}
/* Remove NODE from assembler name hash. */
static void
unlink_from_assembler_name_hash (symtab_node node, bool with_clones)
{
if (assembler_name_hash)
{
struct cgraph_node *cnode;
tree decl = node->symbol.decl;
if (node->symbol.next_sharing_asm_name)
node->symbol.next_sharing_asm_name->symbol.previous_sharing_asm_name
= node->symbol.previous_sharing_asm_name;
if (node->symbol.previous_sharing_asm_name)
{
node->symbol.previous_sharing_asm_name->symbol.next_sharing_asm_name
= node->symbol.next_sharing_asm_name;
}
else
{
tree name = DECL_ASSEMBLER_NAME (node->symbol.decl);
void **slot;
slot = htab_find_slot_with_hash (assembler_name_hash, name,
decl_assembler_name_hash (name),
NO_INSERT);
gcc_assert (*slot == node);
if (!node->symbol.next_sharing_asm_name)
htab_clear_slot (assembler_name_hash, slot);
else
*slot = node->symbol.next_sharing_asm_name;
}
node->symbol.next_sharing_asm_name = NULL;
node->symbol.previous_sharing_asm_name = NULL;
/* Update also possible inline clones sharing a decl. */
cnode = dyn_cast <cgraph_node> (node);
if (cnode && cnode->clones && with_clones)
for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
if (cnode->symbol.decl == decl)
unlink_from_assembler_name_hash ((symtab_node) cnode, true);
}
}
/* Arrange node to be first in its entry of assembler_name_hash. */
void
symtab_prevail_in_asm_name_hash (symtab_node node)
{
unlink_from_assembler_name_hash (node, false);
insert_to_assembler_name_hash (node, false);
}
/* Add node into symbol table. This function is not used directly, but via
cgraph/varpool node creation routines. */
void
symtab_register_node (symtab_node node)
{
struct symtab_node_base key;
symtab_node *slot;
node->symbol.next = symtab_nodes;
node->symbol.previous = NULL;
if (symtab_nodes)
symtab_nodes->symbol.previous = node;
symtab_nodes = node;
if (!symtab_hash)
symtab_hash = htab_create_ggc (10, hash_node, eq_node, NULL);
key.decl = node->symbol.decl;
slot = (symtab_node *) htab_find_slot (symtab_hash, &key, INSERT);
if (*slot == NULL)
*slot = node;
ipa_empty_ref_list (&node->symbol.ref_list);
node->symbol.order = symtab_order++;
/* Be sure to do this last; C++ FE might create new nodes via
DECL_ASSEMBLER_NAME langhook! */
insert_to_assembler_name_hash (node, false);
}
/* Make NODE to be the one symtab hash is pointing to. Used when reshaping tree
of inline clones. */
void
symtab_insert_node_to_hashtable (symtab_node node)
{
struct symtab_node_base key;
symtab_node *slot;
if (!symtab_hash)
symtab_hash = htab_create_ggc (10, hash_node, eq_node, NULL);
key.decl = node->symbol.decl;
slot = (symtab_node *) htab_find_slot (symtab_hash, &key, INSERT);
*slot = node;
}
/* Remove node from symbol table. This function is not used directly, but via
cgraph/varpool node removal routines. */
void
symtab_unregister_node (symtab_node node)
{
void **slot;
ipa_remove_all_references (&node->symbol.ref_list);
ipa_remove_all_referring (&node->symbol.ref_list);
if (node->symbol.same_comdat_group)
{
symtab_node prev;
for (prev = node->symbol.same_comdat_group;
prev->symbol.same_comdat_group != node;
prev = prev->symbol.same_comdat_group)
;
if (node->symbol.same_comdat_group == prev)
prev->symbol.same_comdat_group = NULL;
else
prev->symbol.same_comdat_group = node->symbol.same_comdat_group;
node->symbol.same_comdat_group = NULL;
}
if (node->symbol.previous)
node->symbol.previous->symbol.next = node->symbol.next;
else
symtab_nodes = node->symbol.next;
if (node->symbol.next)
node->symbol.next->symbol.previous = node->symbol.previous;
node->symbol.next = NULL;
node->symbol.previous = NULL;
slot = htab_find_slot (symtab_hash, node, NO_INSERT);
if (*slot == node)
{
symtab_node replacement_node = NULL;
if (cgraph_node *cnode = dyn_cast <cgraph_node> (node))
replacement_node = (symtab_node)cgraph_find_replacement_node (cnode);
if (!replacement_node)
htab_clear_slot (symtab_hash, slot);
else
*slot = replacement_node;
}
unlink_from_assembler_name_hash (node, false);
}
/* Return symbol table node associated with DECL, if any,
and NULL otherwise. */
symtab_node
symtab_get_node (const_tree decl)
{
symtab_node *slot;
struct symtab_node_base key;
gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
|| (TREE_CODE (decl) == VAR_DECL
&& (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
|| in_lto_p)));
if (!symtab_hash)
return NULL;
key.decl = CONST_CAST2 (tree, const_tree, decl);
slot = (symtab_node *) htab_find_slot (symtab_hash, &key,
NO_INSERT);
if (slot)
return *slot;
return NULL;
}
/* Remove symtab NODE from the symbol table. */
void
symtab_remove_node (symtab_node node)
{
if (cgraph_node *cnode = dyn_cast <cgraph_node> (node))
cgraph_remove_node (cnode);
else if (varpool_node *vnode = dyn_cast <varpool_node> (node))
varpool_remove_node (vnode);
}
/* Initalize asm name hash unless. */
void
symtab_initialize_asm_name_hash (void)
{
symtab_node node;
if (!assembler_name_hash)
{
assembler_name_hash =
htab_create_ggc (10, hash_node_by_assembler_name, eq_assembler_name,
NULL);
FOR_EACH_SYMBOL (node)
insert_to_assembler_name_hash (node, false);
}
}
/* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
Return NULL if there's no such node. */
symtab_node
symtab_node_for_asm (const_tree asmname)
{
symtab_node node;
void **slot;
symtab_initialize_asm_name_hash ();
slot = htab_find_slot_with_hash (assembler_name_hash, asmname,
decl_assembler_name_hash (asmname),
NO_INSERT);
if (slot)
{
node = (symtab_node) *slot;
return node;
}
return NULL;
}
/* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
void
change_decl_assembler_name (tree decl, tree name)
{
symtab_node node = NULL;
/* We can have user ASM names on things, like global register variables, that
are not in the symbol table. */
if ((TREE_CODE (decl) == VAR_DECL
&& (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
|| TREE_CODE (decl) == FUNCTION_DECL)
node = symtab_get_node (decl);
if (!DECL_ASSEMBLER_NAME_SET_P (decl))
{
SET_DECL_ASSEMBLER_NAME (decl, name);
if (node)
insert_to_assembler_name_hash (node, true);
}
else
{
if (name == DECL_ASSEMBLER_NAME (decl))
return;
if (node)
unlink_from_assembler_name_hash (node, true);
if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
&& DECL_RTL_SET_P (decl))
warning (0, "%D renamed after being referenced in assembly", decl);
SET_DECL_ASSEMBLER_NAME (decl, name);
if (node)
insert_to_assembler_name_hash (node, true);
}
}
/* Add NEW_ to the same comdat group that OLD is in. */
void
symtab_add_to_same_comdat_group (symtab_node new_node,
symtab_node old_node)
{
gcc_assert (DECL_ONE_ONLY (old_node->symbol.decl));
gcc_assert (!new_node->symbol.same_comdat_group);
gcc_assert (new_node != old_node);
DECL_COMDAT_GROUP (new_node->symbol.decl) = DECL_COMDAT_GROUP (old_node->symbol.decl);
new_node->symbol.same_comdat_group = old_node;
if (!old_node->symbol.same_comdat_group)
old_node->symbol.same_comdat_group = new_node;
else
{
symtab_node n;
for (n = old_node->symbol.same_comdat_group;
n->symbol.same_comdat_group != old_node;
n = n->symbol.same_comdat_group)
;
n->symbol.same_comdat_group = new_node;
}
}
/* Dissolve the same_comdat_group list in which NODE resides. */
void
symtab_dissolve_same_comdat_group_list (symtab_node node)
{
symtab_node n = node, next;
if (!node->symbol.same_comdat_group)
return;
do
{
next = n->symbol.same_comdat_group;
n->symbol.same_comdat_group = NULL;
n = next;
}
while (n != node);
}
/* Return printable assembler name of NODE.
This function is used only for debugging. When assembler name
is unknown go with identifier name. */
const char *
symtab_node_asm_name (symtab_node node)
{
if (!DECL_ASSEMBLER_NAME_SET_P (node->symbol.decl))
return lang_hooks.decl_printable_name (node->symbol.decl, 2);
return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->symbol.decl));
}
/* Return printable identifier name. */
const char *
symtab_node_name (symtab_node node)
{
return lang_hooks.decl_printable_name (node->symbol.decl, 2);
}
static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
/* Dump base fields of symtab nodes. Not to be used directly. */
void
dump_symtab_base (FILE *f, symtab_node node)
{
static const char * const visibility_types[] = {
"default", "protected", "hidden", "internal"
};
fprintf (f, "%s/%i (%s)",
symtab_node_asm_name (node),
node->symbol.order,
symtab_node_name (node));
dump_addr (f, " @", (void *)node);
fprintf (f, "\n Type: %s", symtab_type_names[node->symbol.type]);
if (node->symbol.definition)
fprintf (f, " definition");
if (node->symbol.analyzed)
fprintf (f, " analyzed");
if (node->symbol.alias)
fprintf (f, " alias");
if (node->symbol.cpp_implicit_alias)
fprintf (f, " cpp_implicit_alias");
if (node->symbol.alias_target)
fprintf (f, " target:%s",
DECL_P (node->symbol.alias_target)
? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
(node->symbol.alias_target))
: IDENTIFIER_POINTER (node->symbol.alias_target));
fprintf (f, "\n Visibility:");
if (node->symbol.in_other_partition)
fprintf (f, " in_other_partition");
if (node->symbol.used_from_other_partition)
fprintf (f, " used_from_other_partition");
if (node->symbol.force_output)
fprintf (f, " force_output");
if (node->symbol.forced_by_abi)
fprintf (f, " forced_by_abi");
if (node->symbol.resolution != LDPR_UNKNOWN)
fprintf (f, " %s",
ld_plugin_symbol_resolution_names[(int)node->symbol.resolution]);
if (TREE_ASM_WRITTEN (node->symbol.decl))
fprintf (f, " asm_written");
if (DECL_EXTERNAL (node->symbol.decl))
fprintf (f, " external");
if (TREE_PUBLIC (node->symbol.decl))
fprintf (f, " public");
if (DECL_COMMON (node->symbol.decl))
fprintf (f, " common");
if (DECL_WEAK (node->symbol.decl))
fprintf (f, " weak");
if (DECL_DLLIMPORT_P (node->symbol.decl))
fprintf (f, " dll_import");
if (DECL_COMDAT (node->symbol.decl))
fprintf (f, " comdat");
if (DECL_COMDAT_GROUP (node->symbol.decl))
fprintf (f, " comdat_group:%s",
IDENTIFIER_POINTER (DECL_COMDAT_GROUP (node->symbol.decl)));
if (DECL_ONE_ONLY (node->symbol.decl))
fprintf (f, " one_only");
if (DECL_SECTION_NAME (node->symbol.decl))
fprintf (f, " section_name:%s",
TREE_STRING_POINTER (DECL_SECTION_NAME (node->symbol.decl)));
if (DECL_VISIBILITY_SPECIFIED (node->symbol.decl))
fprintf (f, " visibility_specified");
if (DECL_VISIBILITY (node->symbol.decl))
fprintf (f, " visibility:%s",
visibility_types [DECL_VISIBILITY (node->symbol.decl)]);
if (DECL_VIRTUAL_P (node->symbol.decl))
fprintf (f, " virtual");
if (DECL_ARTIFICIAL (node->symbol.decl))
fprintf (f, " artificial");
if (TREE_CODE (node->symbol.decl) == FUNCTION_DECL)
{
if (DECL_STATIC_CONSTRUCTOR (node->symbol.decl))
fprintf (f, " constructor");
if (DECL_STATIC_DESTRUCTOR (node->symbol.decl))
fprintf (f, " destructor");
}
fprintf (f, "\n");
if (node->symbol.same_comdat_group)
fprintf (f, " Same comdat group as: %s/%i\n",
symtab_node_asm_name (node->symbol.same_comdat_group),
node->symbol.same_comdat_group->symbol.order);
if (node->symbol.next_sharing_asm_name)
fprintf (f, " next sharing asm name: %i\n",
node->symbol.next_sharing_asm_name->symbol.order);
if (node->symbol.previous_sharing_asm_name)
fprintf (f, " previous sharing asm name: %i\n",
node->symbol.previous_sharing_asm_name->symbol.order);
if (node->symbol.address_taken)
fprintf (f, " Address is taken.\n");
if (node->symbol.aux)
{
fprintf (f, " Aux:");
dump_addr (f, " @", (void *)node->symbol.aux);
}
fprintf (f, " References: ");
ipa_dump_references (f, &node->symbol.ref_list);
fprintf (f, " Referring: ");
ipa_dump_referring (f, &node->symbol.ref_list);
if (node->symbol.lto_file_data)
fprintf (f, " Read from file: %s\n",
node->symbol.lto_file_data->file_name);
}
/* Dump symtab node. */
void
dump_symtab_node (FILE *f, symtab_node node)
{
if (cgraph_node *cnode = dyn_cast <cgraph_node> (node))
dump_cgraph_node (f, cnode);
else if (varpool_node *vnode = dyn_cast <varpool_node> (node))
dump_varpool_node (f, vnode);
}
/* Dump symbol table. */
void
dump_symtab (FILE *f)
{
symtab_node node;
fprintf (f, "Symbol table:\n\n");
FOR_EACH_SYMBOL (node)
dump_symtab_node (f, node);
}
/* Dump symtab node NODE to stderr. */
DEBUG_FUNCTION void
debug_symtab_node (symtab_node node)
{
dump_symtab_node (stderr, node);
}
/* Dump symbol table to stderr. */
DEBUG_FUNCTION void
debug_symtab (void)
{
dump_symtab (stderr);
}
/* Verify common part of symtab nodes. */
DEBUG_FUNCTION bool
verify_symtab_base (symtab_node node)
{
bool error_found = false;
symtab_node hashed_node;
if (is_a <cgraph_node> (node))
{
if (TREE_CODE (node->symbol.decl) != FUNCTION_DECL)
{
error ("function symbol is not function");
error_found = true;
}
}
else if (is_a <varpool_node> (node))
{
if (TREE_CODE (node->symbol.decl) != VAR_DECL)
{
error ("variable symbol is not variable");
error_found = true;
}
}
else
{
error ("node has unknown type");
error_found = true;
}
hashed_node = symtab_get_node (node->symbol.decl);
if (!hashed_node)
{
error ("node not found in symtab decl hashtable");
error_found = true;
}
if (assembler_name_hash)
{
hashed_node = symtab_node_for_asm (DECL_ASSEMBLER_NAME (node->symbol.decl));
if (hashed_node && hashed_node->symbol.previous_sharing_asm_name)
{
error ("assembler name hash list corrupted");
error_found = true;
}
while (hashed_node)
{
if (hashed_node == node)
break;
hashed_node = hashed_node->symbol.next_sharing_asm_name;
}
if (!hashed_node
&& !(is_a <varpool_node> (node)
|| DECL_HARD_REGISTER (node->symbol.decl)))
{
error ("node not found in symtab assembler name hash");
error_found = true;
}
}
if (node->symbol.previous_sharing_asm_name
&& node->symbol.previous_sharing_asm_name->symbol.next_sharing_asm_name != node)
{
error ("double linked list of assembler names corrupted");
error_found = true;
}
if (node->symbol.analyzed && !node->symbol.definition)
{
error ("node is analyzed byt it is not a definition");
error_found = true;
}
if (node->symbol.cpp_implicit_alias && !node->symbol.alias)
{
error ("node is alias but not implicit alias");
error_found = true;
}
if (node->symbol.alias && !node->symbol.definition
&& !lookup_attribute ("weakref", DECL_ATTRIBUTES (node->symbol.decl)))
{
error ("node is alias but not definition");
error_found = true;
}
if (node->symbol.same_comdat_group)
{
symtab_node n = node->symbol.same_comdat_group;
if (!DECL_ONE_ONLY (n->symbol.decl))
{
error ("non-DECL_ONE_ONLY node in a same_comdat_group list");
error_found = true;
}
if (n->symbol.type != node->symbol.type)
{
error ("mixing different types of symbol in same comdat groups is not supported");
error_found = true;
}
if (n == node)
{
error ("node is alone in a comdat group");
error_found = true;
}
do
{
if (!n->symbol.same_comdat_group)
{
error ("same_comdat_group is not a circular list");
error_found = true;
break;
}
n = n->symbol.same_comdat_group;
}
while (n != node);
}
return error_found;
}
/* Verify consistency of NODE. */
DEBUG_FUNCTION void
verify_symtab_node (symtab_node node)
{
if (seen_error ())
return;
timevar_push (TV_CGRAPH_VERIFY);
if (cgraph_node *cnode = dyn_cast <cgraph_node> (node))
verify_cgraph_node (cnode);
else
if (verify_symtab_base (node))
{
dump_symtab_node (stderr, node);
internal_error ("verify_symtab_node failed");
}
timevar_pop (TV_CGRAPH_VERIFY);
}
/* Verify symbol table for internal consistency. */
DEBUG_FUNCTION void
verify_symtab (void)
{
symtab_node node;
FOR_EACH_SYMBOL (node)
verify_symtab_node (node);
}
/* Return true when RESOLUTION indicate that linker will use
the symbol from non-LTO object files. */
bool
resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution)
{
return (resolution == LDPR_PREVAILING_DEF
|| resolution == LDPR_PREEMPTED_REG
|| resolution == LDPR_RESOLVED_EXEC
|| resolution == LDPR_RESOLVED_DYN);
}
/* Return true when NODE is known to be used from other (non-LTO) object file.
Known only when doing LTO via linker plugin. */
bool
symtab_used_from_object_file_p (symtab_node node)
{
if (!TREE_PUBLIC (node->symbol.decl) || DECL_EXTERNAL (node->symbol.decl))
return false;
if (resolution_used_from_other_file_p (node->symbol.resolution))
return true;
return false;
}
/* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
but other code such as notice_global_symbol generates rtl. */
void
symtab_make_decl_local (tree decl)
{
rtx rtl, symbol;
if (TREE_CODE (decl) == VAR_DECL)
DECL_COMMON (decl) = 0;
else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
if (DECL_ONE_ONLY (decl) || DECL_COMDAT (decl))
{
DECL_SECTION_NAME (decl) = 0;
DECL_COMDAT (decl) = 0;
}
DECL_COMDAT_GROUP (decl) = 0;
DECL_WEAK (decl) = 0;
DECL_EXTERNAL (decl) = 0;
DECL_VISIBILITY_SPECIFIED (decl) = 0;
DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
TREE_PUBLIC (decl) = 0;
DECL_VISIBILITY_SPECIFIED (decl) = 0;
DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
if (!DECL_RTL_SET_P (decl))
return;
/* Update rtl flags. */
make_decl_rtl (decl);
rtl = DECL_RTL (decl);
if (!MEM_P (rtl))
return;
symbol = XEXP (rtl, 0);
if (GET_CODE (symbol) != SYMBOL_REF)
return;
SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
}
/* Return availability of NODE. */
enum availability
symtab_node_availability (symtab_node node)
{
if (is_a <cgraph_node> (node))
return cgraph_function_body_availability (cgraph (node));
else
return cgraph_variable_initializer_availability (varpool (node));
}
/* Given NODE, walk the alias chain to return the symbol NODE is alias of.
If NODE is not an alias, return NODE.
When AVAILABILITY is non-NULL, get minimal availability in the chain. */
symtab_node
symtab_alias_ultimate_target (symtab_node node, enum availability *availability)
{
bool weakref_p = false;
if (!node->symbol.alias)
{
if (availability)
*availability = symtab_node_availability (node);
return node;
}
/* To determine visibility of the target, we follow ELF semantic of aliases.
Here alias is an alternative assembler name of a given definition. Its
availablity prevails the availablity of its target (i.e. static alias of
weak definition is available.
Weakref is a different animal (and not part of ELF per se). It is just
alternative name of a given symbol used within one complation unit
and is translated prior hitting the object file. It inherits the
visibility of its target (i.e. weakref of non-overwritable definition
is non-overwritable, while weakref of weak definition is weak).
If we ever get into supporting targets with different semantics, a target
hook will be needed here. */
if (availability)
{
weakref_p = DECL_EXTERNAL (node->symbol.decl) && node->symbol.alias;
if (!weakref_p)
*availability = symtab_node_availability (node);
else
*availability = AVAIL_LOCAL;
}
while (node)
{
if (node->symbol.alias && node->symbol.analyzed)
node = symtab_alias_target (node);
else
{
if (!availability)
;
else if (node->symbol.analyzed)
{
if (weakref_p)
{
enum availability a = symtab_node_availability (node);
if (a < *availability)
*availability = a;
}
}
else
*availability = AVAIL_NOT_AVAILABLE;
return node;
}
if (node && availability && weakref_p)
{
enum availability a = symtab_node_availability (node);
if (a < *availability)
*availability = a;
weakref_p = DECL_EXTERNAL (node->symbol.decl) && node->symbol.alias;
}
}
if (availability)
*availability = AVAIL_NOT_AVAILABLE;
return NULL;
}
/* C++ FE sometimes change linkage flags after producing same body aliases.
FIXME: C++ produce implicit aliases for virtual functions and vtables that
are obviously equivalent. The way it is doing so is however somewhat
kludgy and interferes with the visibility code. As a result we need to
copy the visibility from the target to get things right. */
void
fixup_same_cpp_alias_visibility (symtab_node node, symtab_node target)
{
if (is_a <cgraph_node> (node))
{
DECL_DECLARED_INLINE_P (node->symbol.decl)
= DECL_DECLARED_INLINE_P (target->symbol.decl);
DECL_DISREGARD_INLINE_LIMITS (node->symbol.decl)
= DECL_DISREGARD_INLINE_LIMITS (target->symbol.decl);
}
/* FIXME: It is not really clear why those flags should not be copied for
functions, too. */
else
{
DECL_WEAK (node->symbol.decl) = DECL_WEAK (target->symbol.decl);
DECL_EXTERNAL (node->symbol.decl) = DECL_EXTERNAL (target->symbol.decl);
DECL_VISIBILITY (node->symbol.decl) = DECL_VISIBILITY (target->symbol.decl);
}
DECL_VIRTUAL_P (node->symbol.decl) = DECL_VIRTUAL_P (target->symbol.decl);
if (TREE_PUBLIC (node->symbol.decl))
{
DECL_EXTERNAL (node->symbol.decl) = DECL_EXTERNAL (target->symbol.decl);
DECL_COMDAT (node->symbol.decl) = DECL_COMDAT (target->symbol.decl);
DECL_COMDAT_GROUP (node->symbol.decl)
= DECL_COMDAT_GROUP (target->symbol.decl);
if (DECL_ONE_ONLY (target->symbol.decl)
&& !node->symbol.same_comdat_group)
symtab_add_to_same_comdat_group ((symtab_node)node, (symtab_node)target);
}
node->symbol.externally_visible = target->symbol.externally_visible;
}
/* Add reference recording that NODE is alias of TARGET.
The function can fail in the case of aliasing cycles; in this case
it returns false. */
bool
symtab_resolve_alias (symtab_node node, symtab_node target)
{
symtab_node n;
gcc_assert (!node->symbol.analyzed
&& !vec_safe_length (node->symbol.ref_list.references));
/* Never let cycles to creep into the symbol table alias references;
those will make alias walkers to be infinite. */
for (n = target; n && n->symbol.alias;
n = n->symbol.analyzed ? symtab_alias_target (n) : NULL)
if (n == node)
{
if (is_a <cgraph_node> (node))
error ("function %q+D part of alias cycle", node->symbol.decl);
else if (is_a <varpool_node> (node))
error ("variable %q+D part of alias cycle", node->symbol.decl);
else
gcc_unreachable ();
node->symbol.alias = false;
return false;
}
/* "analyze" the node - i.e. mark the reference. */
node->symbol.definition = true;
node->symbol.alias = true;
node->symbol.analyzed = true;
ipa_record_reference (node, target, IPA_REF_ALIAS, NULL);
/* Alias targets become reudndant after alias is resolved into an reference.
We do not want to keep it around or we would have to mind updating them
when renaming symbols. */
node->symbol.alias_target = NULL;
DECL_ATTRIBUTES (node->symbol.decl)
= remove_attribute ("alias", DECL_ATTRIBUTES (node->symbol.decl));
if (node->symbol.cpp_implicit_alias && cgraph_state >= CGRAPH_STATE_CONSTRUCTION)
fixup_same_cpp_alias_visibility (node, target);
/* If alias has address taken, so does the target. */
if (node->symbol.address_taken)
symtab_alias_ultimate_target (target, NULL)->symbol.address_taken = true;
return true;
}
#include "gt-symtab.h"
|