Made many changes to eliminate gcc warnings. Made various
[deliverable/binutils-gdb.git] / ld / ldindr.c
1
2 /* ldindr.c
3 Handle indirect symbols.
4
5 Copyright (C) 1991 Free Software Foundation, Inc.
6 Written by Steve Chamberlain steve@cygnus.com
7
8 This file is part of GLD, the Gnu Linker.
9
10 GLD is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 GLD is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GLD; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 */
25
26 /*
27 An indirect symbol is where a global symbol in one file say's that
28 all refs like it should be turned into refs of the symbol pointed
29 at by the value of the indirect symbol.
30
31 BFD supplies symbols to be indirected with the BFD_INDIRECT bit
32 set. Whenever the linker gets one of these, it calls add_indirect
33 with the symbol. We look up the symbol which this one dereferneces,
34 and stop if they are the same. If they are not the same, copy all
35 the information from the current to the dereffed symbol. Set the
36 indirect bit in the flag. From now on the ldsym_get stuff will
37 perform the indirection for us, at no charge.
38 */
39
40
41
42 #include "bfd.h"
43 #include "sysdep.h"
44 #include "ld.h"
45 #include "ldsym.h"
46 #include "ldmain.h"
47 #include "ldmisc.h"
48
49 static asymbol **
50 move_it (a_list, b_list)
51 asymbol **a_list;
52 asymbol **b_list;
53 {
54 asymbol **head = a_list;
55 asymbol **cursor = head;
56
57 if (a_list == 0) return b_list;
58 if (b_list == 0) return a_list;
59
60 while (1) {
61 asymbol *ptr = cursor[0];
62 asymbol **next = (asymbol **)(ptr->udata);
63 if (next == 0) {
64 ptr->udata = (PTR) b_list;
65 return head;
66 }
67 cursor = next;
68 }
69 }
70
71 #if 0
72 void
73 copy_over (ldsym, bfdsym)
74 ldsym_type *ldsym;
75 asymbol **bfdsym;
76 {
77 while (list && *list)
78 {
79 refize(enter_global_ref(list, name));
80 list = (asymbol **)((*list)->udata);
81 }
82 }
83 #endif
84
85 /* This call allows us to change the symbol table so that all future
86 refs to the symbol are patched to know the alias - but we still
87 have to fix all the old ones */
88 void
89 add_indirect (ptr)
90 asymbol **ptr;
91 {
92 ldsym_type *lgs = ldsym_get((*ptr)->name);
93 ldsym_type *new = ldsym_get(((asymbol *)((*ptr)->value))->name);
94
95 /* If the mapping has already been done, stop now */
96 if (lgs == new) return;
97
98 lgs->flags |= SYM_INDIRECT;
99
100 if (lgs->sdefs_chain && lgs->sdefs_chain[0])
101 {
102 einfo("indirect symbol already has definition %s\n", lgs->sdefs_chain[0]);
103 }
104 new->scoms_chain = move_it(new->scoms_chain, lgs->scoms_chain);
105 lgs->scoms_chain = 0;
106 new->srefs_chain = move_it(new->srefs_chain, lgs->srefs_chain);
107 lgs->srefs_chain = 0;
108 new->sdefs_chain = move_it(new->sdefs_chain, lgs->sdefs_chain);
109 lgs->sdefs_chain = 0;
110
111 /* If the result has any commons they should be turned into refs */
112
113 if (new->sdefs_chain && new->scoms_chain)
114 {
115 refize(new, new->scoms_chain);
116 }
117 lgs->sdefs_chain = (asymbol **)new;
118 lgs->srefs_chain = ptr;
119 }
120
121
122
This page took 0.031822 seconds and 4 git commands to generate.