Commit | Line | Data |
---|---|---|
29f33467 | 1 | |
812df84b SC |
2 | /* ldindr.c |
3 | Handle indirect symbols. | |
4 | ||
29f33467 SC |
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 | /* | |
32846f9c SC |
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 | ||
812df84b SC |
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 | |
1af27af8 SC |
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. | |
812df84b SC |
38 | */ |
39 | ||
40 | ||
41 | ||
812df84b | 42 | #include "bfd.h" |
f177a611 | 43 | #include "sysdep.h" |
812df84b SC |
44 | #include "ld.h" |
45 | #include "ldsym.h" | |
fcf276c4 | 46 | #include "ldmain.h" |
1af27af8 | 47 | #include "ldmisc.h" |
812df84b | 48 | |
1af27af8 | 49 | static asymbol ** |
8ddef552 DM |
50 | move_it (a_list, b_list) |
51 | asymbol **a_list; | |
52 | asymbol **b_list; | |
812df84b | 53 | { |
1af27af8 SC |
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; | |
812df84b SC |
68 | } |
69 | } | |
70 | ||
32846f9c SC |
71 | #if 0 |
72 | void | |
8ddef552 DM |
73 | copy_over (ldsym, bfdsym) |
74 | ldsym_type *ldsym; | |
75 | asymbol **bfdsym; | |
32846f9c SC |
76 | { |
77 | while (list && *list) | |
8ddef552 | 78 | { |
c3cbe3f4 | 79 | refize(enter_global_ref(list, name)); |
8ddef552 DM |
80 | list = (asymbol **)((*list)->udata); |
81 | } | |
32846f9c SC |
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 */ | |
812df84b | 88 | void |
8ddef552 DM |
89 | add_indirect (ptr) |
90 | asymbol **ptr; | |
812df84b | 91 | { |
1af27af8 SC |
92 | ldsym_type *lgs = ldsym_get((*ptr)->name); |
93 | ldsym_type *new = ldsym_get(((asymbol *)((*ptr)->value))->name); | |
812df84b | 94 | |
1af27af8 SC |
95 | /* If the mapping has already been done, stop now */ |
96 | if (lgs == new) return; | |
32846f9c | 97 | |
1af27af8 | 98 | lgs->flags |= SYM_INDIRECT; |
812df84b | 99 | |
32846f9c SC |
100 | if (lgs->sdefs_chain && lgs->sdefs_chain[0]) |
101 | { | |
8bf66be8 | 102 | einfo("indirect symbol already has definition %s\n", lgs->sdefs_chain[0]); |
32846f9c | 103 | } |
1af27af8 SC |
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; | |
812df84b | 110 | |
32846f9c SC |
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 | } | |
29f33467 SC |
117 | lgs->sdefs_chain = (asymbol **)new; |
118 | lgs->srefs_chain = ptr; | |
1af27af8 | 119 | } |
812df84b | 120 | |
812df84b SC |
121 | |
122 |