Rev 5197 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5197 | Rev 6324 | ||
---|---|---|---|
1 | /* linker.c -- BFD linker routines |
1 | /* linker.c -- BFD linker routines |
2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
- | |
3 | 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
- | |
4 | Free Software Foundation, Inc. |
2 | Copyright (C) 1993-2015 Free Software Foundation, Inc. |
5 | Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support |
3 | Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support |
6 | 4 | ||
7 | This file is part of BFD, the Binary File Descriptor library. |
5 | This file is part of BFD, the Binary File Descriptor library. |
8 | 6 | ||
9 | This program is free software; you can redistribute it and/or modify |
7 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
11 | the Free Software Foundation; either version 3 of the License, or |
9 | the Free Software Foundation; either version 3 of the License, or |
12 | (at your option) any later version. |
10 | (at your option) any later version. |
13 | 11 | ||
14 | This program is distributed in the hope that it will be useful, |
12 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | GNU General Public License for more details. |
15 | GNU General Public License for more details. |
18 | 16 | ||
19 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
21 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
22 | MA 02110-1301, USA. */ |
20 | MA 02110-1301, USA. */ |
23 | 21 | ||
24 | #include "sysdep.h" |
22 | #include "sysdep.h" |
25 | #include "bfd.h" |
23 | #include "bfd.h" |
26 | #include "libbfd.h" |
24 | #include "libbfd.h" |
27 | #include "bfdlink.h" |
25 | #include "bfdlink.h" |
28 | #include "genlink.h" |
26 | #include "genlink.h" |
29 | 27 | ||
30 | /* |
28 | /* |
31 | SECTION |
29 | SECTION |
32 | Linker Functions |
30 | Linker Functions |
33 | 31 | ||
34 | @cindex Linker |
32 | @cindex Linker |
35 | The linker uses three special entry points in the BFD target |
33 | The linker uses three special entry points in the BFD target |
36 | vector. It is not necessary to write special routines for |
34 | vector. It is not necessary to write special routines for |
37 | these entry points when creating a new BFD back end, since |
35 | these entry points when creating a new BFD back end, since |
38 | generic versions are provided. However, writing them can |
36 | generic versions are provided. However, writing them can |
39 | speed up linking and make it use significantly less runtime |
37 | speed up linking and make it use significantly less runtime |
40 | memory. |
38 | memory. |
41 | 39 | ||
42 | The first routine creates a hash table used by the other |
40 | The first routine creates a hash table used by the other |
43 | routines. The second routine adds the symbols from an object |
41 | routines. The second routine adds the symbols from an object |
44 | file to the hash table. The third routine takes all the |
42 | file to the hash table. The third routine takes all the |
45 | object files and links them together to create the output |
43 | object files and links them together to create the output |
46 | file. These routines are designed so that the linker proper |
44 | file. These routines are designed so that the linker proper |
47 | does not need to know anything about the symbols in the object |
45 | does not need to know anything about the symbols in the object |
48 | files that it is linking. The linker merely arranges the |
46 | files that it is linking. The linker merely arranges the |
49 | sections as directed by the linker script and lets BFD handle |
47 | sections as directed by the linker script and lets BFD handle |
50 | the details of symbols and relocs. |
48 | the details of symbols and relocs. |
51 | 49 | ||
52 | The second routine and third routines are passed a pointer to |
50 | The second routine and third routines are passed a pointer to |
53 | a < |
51 | a < |
54 | < |
52 | < |
55 | including the linker hash table (which was created by the |
53 | including the linker hash table (which was created by the |
56 | first routine) and a set of callback functions to the linker |
54 | first routine) and a set of callback functions to the linker |
57 | proper. |
55 | proper. |
58 | 56 | ||
59 | The generic linker routines are in < |
57 | The generic linker routines are in < |
60 | header file < |
58 | header file < |
61 | ends which have implemented versions of these routines are |
59 | ends which have implemented versions of these routines are |
62 | a.out (in < |
60 | a.out (in < |
63 | routines are used as examples throughout this section. |
61 | routines are used as examples throughout this section. |
64 | 62 | ||
65 | @menu |
63 | @menu |
66 | @* Creating a Linker Hash Table:: |
64 | @* Creating a Linker Hash Table:: |
67 | @* Adding Symbols to the Hash Table:: |
65 | @* Adding Symbols to the Hash Table:: |
68 | @* Performing the Final Link:: |
66 | @* Performing the Final Link:: |
69 | @end menu |
67 | @end menu |
70 | 68 | ||
71 | INODE |
69 | INODE |
72 | Creating a Linker Hash Table, Adding Symbols to the Hash Table, Linker Functions, Linker Functions |
70 | Creating a Linker Hash Table, Adding Symbols to the Hash Table, Linker Functions, Linker Functions |
73 | SUBSECTION |
71 | SUBSECTION |
74 | Creating a linker hash table |
72 | Creating a linker hash table |
75 | 73 | ||
76 | @cindex _bfd_link_hash_table_create in target vector |
74 | @cindex _bfd_link_hash_table_create in target vector |
77 | @cindex target vector (_bfd_link_hash_table_create) |
75 | @cindex target vector (_bfd_link_hash_table_create) |
78 | The linker routines must create a hash table, which must be |
76 | The linker routines must create a hash table, which must be |
79 | derived from < |
77 | derived from < |
80 | < |
78 | < |
81 | create a derived hash table. This entry point is called using |
79 | create a derived hash table. This entry point is called using |
82 | the target vector of the linker output file. |
80 | the target vector of the linker output file. |
83 | 81 | ||
84 | The <<_bfd_link_hash_table_create>> entry point must allocate |
82 | The <<_bfd_link_hash_table_create>> entry point must allocate |
85 | and initialize an instance of the desired hash table. If the |
83 | and initialize an instance of the desired hash table. If the |
86 | back end does not require any additional information to be |
84 | back end does not require any additional information to be |
87 | stored with the entries in the hash table, the entry point may |
85 | stored with the entries in the hash table, the entry point may |
88 | simply create a < |
86 | simply create a < |
89 | however, some additional information will be needed. |
87 | however, some additional information will be needed. |
90 | 88 | ||
91 | For example, with each entry in the hash table the a.out |
89 | For example, with each entry in the hash table the a.out |
92 | linker keeps the index the symbol has in the final output file |
90 | linker keeps the index the symbol has in the final output file |
93 | (this index number is used so that when doing a relocatable |
91 | (this index number is used so that when doing a relocatable |
94 | link the symbol index used in the output file can be quickly |
92 | link the symbol index used in the output file can be quickly |
95 | filled in when copying over a reloc). The a.out linker code |
93 | filled in when copying over a reloc). The a.out linker code |
96 | defines the required structures and functions for a hash table |
94 | defines the required structures and functions for a hash table |
97 | derived from < |
95 | derived from < |
98 | hash table is created by the function |
96 | hash table is created by the function |
99 | < |
97 | < |
100 | space for the hash table, initializes it, and returns a |
98 | space for the hash table, initializes it, and returns a |
101 | pointer to it. |
99 | pointer to it. |
102 | 100 | ||
103 | When writing the linker routines for a new back end, you will |
101 | When writing the linker routines for a new back end, you will |
104 | generally not know exactly which fields will be required until |
102 | generally not know exactly which fields will be required until |
105 | you have finished. You should simply create a new hash table |
103 | you have finished. You should simply create a new hash table |
106 | which defines no additional fields, and then simply add fields |
104 | which defines no additional fields, and then simply add fields |
107 | as they become necessary. |
105 | as they become necessary. |
108 | 106 | ||
109 | INODE |
107 | INODE |
110 | Adding Symbols to the Hash Table, Performing the Final Link, Creating a Linker Hash Table, Linker Functions |
108 | Adding Symbols to the Hash Table, Performing the Final Link, Creating a Linker Hash Table, Linker Functions |
111 | SUBSECTION |
109 | SUBSECTION |
112 | Adding symbols to the hash table |
110 | Adding symbols to the hash table |
113 | 111 | ||
114 | @cindex _bfd_link_add_symbols in target vector |
112 | @cindex _bfd_link_add_symbols in target vector |
115 | @cindex target vector (_bfd_link_add_symbols) |
113 | @cindex target vector (_bfd_link_add_symbols) |
116 | The linker proper will call the <<_bfd_link_add_symbols>> |
114 | The linker proper will call the <<_bfd_link_add_symbols>> |
117 | entry point for each object file or archive which is to be |
115 | entry point for each object file or archive which is to be |
118 | linked (typically these are the files named on the command |
116 | linked (typically these are the files named on the command |
119 | line, but some may also come from the linker script). The |
117 | line, but some may also come from the linker script). The |
120 | entry point is responsible for examining the file. For an |
118 | entry point is responsible for examining the file. For an |
121 | object file, BFD must add any relevant symbol information to |
119 | object file, BFD must add any relevant symbol information to |
122 | the hash table. For an archive, BFD must determine which |
120 | the hash table. For an archive, BFD must determine which |
123 | elements of the archive should be used and adding them to the |
121 | elements of the archive should be used and adding them to the |
124 | link. |
122 | link. |
125 | 123 | ||
126 | The a.out version of this entry point is |
124 | The a.out version of this entry point is |
127 | < |
125 | < |
128 | 126 | ||
129 | @menu |
127 | @menu |
130 | @* Differing file formats:: |
128 | @* Differing file formats:: |
131 | @* Adding symbols from an object file:: |
129 | @* Adding symbols from an object file:: |
132 | @* Adding symbols from an archive:: |
130 | @* Adding symbols from an archive:: |
133 | @end menu |
131 | @end menu |
134 | 132 | ||
135 | INODE |
133 | INODE |
136 | Differing file formats, Adding symbols from an object file, Adding Symbols to the Hash Table, Adding Symbols to the Hash Table |
134 | Differing file formats, Adding symbols from an object file, Adding Symbols to the Hash Table, Adding Symbols to the Hash Table |
137 | SUBSUBSECTION |
135 | SUBSUBSECTION |
138 | Differing file formats |
136 | Differing file formats |
139 | 137 | ||
140 | Normally all the files involved in a link will be of the same |
138 | Normally all the files involved in a link will be of the same |
141 | format, but it is also possible to link together different |
139 | format, but it is also possible to link together different |
142 | format object files, and the back end must support that. The |
140 | format object files, and the back end must support that. The |
143 | <<_bfd_link_add_symbols>> entry point is called via the target |
141 | <<_bfd_link_add_symbols>> entry point is called via the target |
144 | vector of the file to be added. This has an important |
142 | vector of the file to be added. This has an important |
145 | consequence: the function may not assume that the hash table |
143 | consequence: the function may not assume that the hash table |
146 | is the type created by the corresponding |
144 | is the type created by the corresponding |
147 | <<_bfd_link_hash_table_create>> vector. All the |
145 | <<_bfd_link_hash_table_create>> vector. All the |
148 | <<_bfd_link_add_symbols>> function can assume about the hash |
146 | <<_bfd_link_add_symbols>> function can assume about the hash |
149 | table is that it is derived from < |
147 | table is that it is derived from < |
150 | bfd_link_hash_table>>. |
148 | bfd_link_hash_table>>. |
151 | 149 | ||
152 | Sometimes the <<_bfd_link_add_symbols>> function must store |
150 | Sometimes the <<_bfd_link_add_symbols>> function must store |
153 | some information in the hash table entry to be used by the |
151 | some information in the hash table entry to be used by the |
154 | <<_bfd_final_link>> function. In such a case the output bfd |
152 | <<_bfd_final_link>> function. In such a case the output bfd |
155 | xvec must be checked to make sure that the hash table was |
153 | xvec must be checked to make sure that the hash table was |
156 | created by an object file of the same format. |
154 | created by an object file of the same format. |
157 | 155 | ||
158 | The <<_bfd_final_link>> routine must be prepared to handle a |
156 | The <<_bfd_final_link>> routine must be prepared to handle a |
159 | hash entry without any extra information added by the |
157 | hash entry without any extra information added by the |
160 | <<_bfd_link_add_symbols>> function. A hash entry without |
158 | <<_bfd_link_add_symbols>> function. A hash entry without |
161 | extra information will also occur when the linker script |
159 | extra information will also occur when the linker script |
162 | directs the linker to create a symbol. Note that, regardless |
160 | directs the linker to create a symbol. Note that, regardless |
163 | of how a hash table entry is added, all the fields will be |
161 | of how a hash table entry is added, all the fields will be |
164 | initialized to some sort of null value by the hash table entry |
162 | initialized to some sort of null value by the hash table entry |
165 | initialization function. |
163 | initialization function. |
166 | 164 | ||
167 | See < |
165 | See < |
168 | check the output bfd before saving information (in this |
166 | check the output bfd before saving information (in this |
169 | case, the ECOFF external symbol debugging information) in a |
167 | case, the ECOFF external symbol debugging information) in a |
170 | hash table entry. |
168 | hash table entry. |
171 | 169 | ||
172 | INODE |
170 | INODE |
173 | Adding symbols from an object file, Adding symbols from an archive, Differing file formats, Adding Symbols to the Hash Table |
171 | Adding symbols from an object file, Adding symbols from an archive, Differing file formats, Adding Symbols to the Hash Table |
174 | SUBSUBSECTION |
172 | SUBSUBSECTION |
175 | Adding symbols from an object file |
173 | Adding symbols from an object file |
176 | 174 | ||
177 | When the <<_bfd_link_add_symbols>> routine is passed an object |
175 | When the <<_bfd_link_add_symbols>> routine is passed an object |
178 | file, it must add all externally visible symbols in that |
176 | file, it must add all externally visible symbols in that |
179 | object file to the hash table. The actual work of adding the |
177 | object file to the hash table. The actual work of adding the |
180 | symbol to the hash table is normally handled by the function |
178 | symbol to the hash table is normally handled by the function |
181 | <<_bfd_generic_link_add_one_symbol>>. The |
179 | <<_bfd_generic_link_add_one_symbol>>. The |
182 | <<_bfd_link_add_symbols>> routine is responsible for reading |
180 | <<_bfd_link_add_symbols>> routine is responsible for reading |
183 | all the symbols from the object file and passing the correct |
181 | all the symbols from the object file and passing the correct |
184 | information to <<_bfd_generic_link_add_one_symbol>>. |
182 | information to <<_bfd_generic_link_add_one_symbol>>. |
185 | 183 | ||
186 | The <<_bfd_link_add_symbols>> routine should not use |
184 | The <<_bfd_link_add_symbols>> routine should not use |
187 | < |
185 | < |
188 | providing this routine is to avoid the overhead of converting |
186 | providing this routine is to avoid the overhead of converting |
189 | the symbols into generic < |
187 | the symbols into generic < |
190 | 188 | ||
191 | @findex _bfd_generic_link_add_one_symbol |
189 | @findex _bfd_generic_link_add_one_symbol |
192 | <<_bfd_generic_link_add_one_symbol>> handles the details of |
190 | <<_bfd_generic_link_add_one_symbol>> handles the details of |
193 | combining common symbols, warning about multiple definitions, |
191 | combining common symbols, warning about multiple definitions, |
194 | and so forth. It takes arguments which describe the symbol to |
192 | and so forth. It takes arguments which describe the symbol to |
195 | add, notably symbol flags, a section, and an offset. The |
193 | add, notably symbol flags, a section, and an offset. The |
196 | symbol flags include such things as < |
194 | symbol flags include such things as < |
197 | < |
195 | < |
198 | file, or something like < |
196 | file, or something like < |
199 | symbol or < |
197 | symbol or < |
200 | 198 | ||
201 | If the <<_bfd_final_link>> routine is also going to need to |
199 | If the <<_bfd_final_link>> routine is also going to need to |
202 | read the symbol information, the <<_bfd_link_add_symbols>> |
200 | read the symbol information, the <<_bfd_link_add_symbols>> |
203 | routine should save it somewhere attached to the object file |
201 | routine should save it somewhere attached to the object file |
204 | BFD. However, the information should only be saved if the |
202 | BFD. However, the information should only be saved if the |
205 | < |
203 | < |
206 | that the <<-no-keep-memory>> linker switch is effective. |
204 | that the <<-no-keep-memory>> linker switch is effective. |
207 | 205 | ||
208 | The a.out function which adds symbols from an object file is |
206 | The a.out function which adds symbols from an object file is |
209 | < |
207 | < |
210 | work is in < |
208 | work is in < |
211 | pointers to the hash tables entries created by |
209 | pointers to the hash tables entries created by |
212 | <<_bfd_generic_link_add_one_symbol>> indexed by symbol number, |
210 | <<_bfd_generic_link_add_one_symbol>> indexed by symbol number, |
213 | so that the <<_bfd_final_link>> routine does not have to call |
211 | so that the <<_bfd_final_link>> routine does not have to call |
214 | the hash table lookup routine to locate the entry. |
212 | the hash table lookup routine to locate the entry. |
215 | 213 | ||
216 | INODE |
214 | INODE |
217 | Adding symbols from an archive, , Adding symbols from an object file, Adding Symbols to the Hash Table |
215 | Adding symbols from an archive, , Adding symbols from an object file, Adding Symbols to the Hash Table |
218 | SUBSUBSECTION |
216 | SUBSUBSECTION |
219 | Adding symbols from an archive |
217 | Adding symbols from an archive |
220 | 218 | ||
221 | When the <<_bfd_link_add_symbols>> routine is passed an |
219 | When the <<_bfd_link_add_symbols>> routine is passed an |
222 | archive, it must look through the symbols defined by the |
220 | archive, it must look through the symbols defined by the |
223 | archive and decide which elements of the archive should be |
221 | archive and decide which elements of the archive should be |
224 | included in the link. For each such element it must call the |
222 | included in the link. For each such element it must call the |
225 | < |
223 | < |
226 | symbols from the object file to the linker hash table. (The |
224 | symbols from the object file to the linker hash table. (The |
227 | callback may in fact indicate that a replacement BFD should be |
225 | callback may in fact indicate that a replacement BFD should be |
228 | used, in which case the symbols from that BFD should be added |
226 | used, in which case the symbols from that BFD should be added |
229 | to the linker hash table instead.) |
227 | to the linker hash table instead.) |
230 | 228 | ||
231 | @findex _bfd_generic_link_add_archive_symbols |
229 | @findex _bfd_generic_link_add_archive_symbols |
232 | In most cases the work of looking through the symbols in the |
230 | In most cases the work of looking through the symbols in the |
233 | archive should be done by the |
231 | archive should be done by the |
234 | <<_bfd_generic_link_add_archive_symbols>> function. This |
232 | <<_bfd_generic_link_add_archive_symbols>> function. |
235 | function builds a hash table from the archive symbol table and |
- | |
236 | looks through the list of undefined symbols to see which |
- | |
237 | elements should be included. |
- | |
238 | <<_bfd_generic_link_add_archive_symbols>> is passed a function |
233 | <<_bfd_generic_link_add_archive_symbols>> is passed a function |
239 | to call to make the final decision about adding an archive |
234 | to call to make the final decision about adding an archive |
240 | element to the link and to do the actual work of adding the |
235 | element to the link and to do the actual work of adding the |
241 | symbols to the linker hash table. |
236 | symbols to the linker hash table. If the element is to |
242 | - | ||
243 | The function passed to |
- | |
244 | <<_bfd_generic_link_add_archive_symbols>> must read the |
- | |
245 | symbols of the archive element and decide whether the archive |
- | |
246 | element should be included in the link. If the element is to |
- | |
247 | be included, the < |
237 | be included, the < |
248 | routine must be called with the element as an argument, and |
238 | routine must be called with the element as an argument, and |
249 | the element's symbols must be added to the linker hash table |
239 | the element's symbols must be added to the linker hash table |
250 | just as though the element had itself been passed to the |
240 | just as though the element had itself been passed to the |
251 | <<_bfd_link_add_symbols>> function. The < |
241 | <<_bfd_link_add_symbols>> function. |
252 | callback has the option to indicate that it would like to |
- | |
253 | replace the element archive with a substitute BFD, in which |
- | |
254 | case it is the symbols of that substitute BFD that must be |
- | |
255 | added to the linker hash table instead. |
- | |
256 | 242 | ||
257 | When the a.out <<_bfd_link_add_symbols>> function receives an |
243 | When the a.out <<_bfd_link_add_symbols>> function receives an |
258 | archive, it calls <<_bfd_generic_link_add_archive_symbols>> |
244 | archive, it calls <<_bfd_generic_link_add_archive_symbols>> |
259 | passing < |
245 | passing < |
260 | argument. < |
246 | argument. < |
261 | < |
247 | < |
262 | the element (an element is only added if it provides a real, |
248 | the element (an element is only added if it provides a real, |
263 | non-common, definition for a previously undefined or common |
249 | non-common, definition for a previously undefined or common |
264 | symbol) it calls the < |
250 | symbol) it calls the < |
265 | < |
251 | < |
266 | < |
252 | < |
267 | linker hash table - possibly those of a substitute BFD, if the |
253 | linker hash table - possibly those of a substitute BFD, if the |
268 | < |
254 | < |
269 | 255 | ||
270 | The ECOFF back end is unusual in that it does not normally |
256 | The ECOFF back end is unusual in that it does not normally |
271 | call <<_bfd_generic_link_add_archive_symbols>>, because ECOFF |
257 | call <<_bfd_generic_link_add_archive_symbols>>, because ECOFF |
272 | archives already contain a hash table of symbols. The ECOFF |
258 | archives already contain a hash table of symbols. The ECOFF |
273 | back end searches the archive itself to avoid the overhead of |
259 | back end searches the archive itself to avoid the overhead of |
274 | creating a new hash table. |
260 | creating a new hash table. |
275 | 261 | ||
276 | INODE |
262 | INODE |
277 | Performing the Final Link, , Adding Symbols to the Hash Table, Linker Functions |
263 | Performing the Final Link, , Adding Symbols to the Hash Table, Linker Functions |
278 | SUBSECTION |
264 | SUBSECTION |
279 | Performing the final link |
265 | Performing the final link |
280 | 266 | ||
281 | @cindex _bfd_link_final_link in target vector |
267 | @cindex _bfd_link_final_link in target vector |
282 | @cindex target vector (_bfd_final_link) |
268 | @cindex target vector (_bfd_final_link) |
283 | When all the input files have been processed, the linker calls |
269 | When all the input files have been processed, the linker calls |
284 | the <<_bfd_final_link>> entry point of the output BFD. This |
270 | the <<_bfd_final_link>> entry point of the output BFD. This |
285 | routine is responsible for producing the final output file, |
271 | routine is responsible for producing the final output file, |
286 | which has several aspects. It must relocate the contents of |
272 | which has several aspects. It must relocate the contents of |
287 | the input sections and copy the data into the output sections. |
273 | the input sections and copy the data into the output sections. |
288 | It must build an output symbol table including any local |
274 | It must build an output symbol table including any local |
289 | symbols from the input files and the global symbols from the |
275 | symbols from the input files and the global symbols from the |
290 | hash table. When producing relocatable output, it must |
276 | hash table. When producing relocatable output, it must |
291 | modify the input relocs and write them into the output file. |
277 | modify the input relocs and write them into the output file. |
292 | There may also be object format dependent work to be done. |
278 | There may also be object format dependent work to be done. |
293 | 279 | ||
294 | The linker will also call the < |
280 | The linker will also call the < |
295 | point when the BFD is closed. The two entry points must work |
281 | point when the BFD is closed. The two entry points must work |
296 | together in order to produce the correct output file. |
282 | together in order to produce the correct output file. |
297 | 283 | ||
298 | The details of how this works are inevitably dependent upon |
284 | The details of how this works are inevitably dependent upon |
299 | the specific object file format. The a.out |
285 | the specific object file format. The a.out |
300 | <<_bfd_final_link>> routine is < |
286 | <<_bfd_final_link>> routine is < |
301 | 287 | ||
302 | @menu |
288 | @menu |
303 | @* Information provided by the linker:: |
289 | @* Information provided by the linker:: |
304 | @* Relocating the section contents:: |
290 | @* Relocating the section contents:: |
305 | @* Writing the symbol table:: |
291 | @* Writing the symbol table:: |
306 | @end menu |
292 | @end menu |
307 | 293 | ||
308 | INODE |
294 | INODE |
309 | Information provided by the linker, Relocating the section contents, Performing the Final Link, Performing the Final Link |
295 | Information provided by the linker, Relocating the section contents, Performing the Final Link, Performing the Final Link |
310 | SUBSUBSECTION |
296 | SUBSUBSECTION |
311 | Information provided by the linker |
297 | Information provided by the linker |
312 | 298 | ||
313 | Before the linker calls the <<_bfd_final_link>> entry point, |
299 | Before the linker calls the <<_bfd_final_link>> entry point, |
314 | it sets up some data structures for the function to use. |
300 | it sets up some data structures for the function to use. |
315 | 301 | ||
316 | The < |
302 | The < |
317 | will point to a list of all the input files included in the |
303 | will point to a list of all the input files included in the |
318 | link. These files are linked through the < |
304 | link. These files are linked through the < |
319 | of the < |
305 | of the < |
320 | 306 | ||
321 | Each section in the output file will have a list of |
307 | Each section in the output file will have a list of |
322 | < |
308 | < |
323 | field (the < |
309 | field (the < |
324 | < |
310 | < |
325 | contents of the output section in terms of the contents of |
311 | contents of the output section in terms of the contents of |
326 | various input sections, fill constants, and, eventually, other |
312 | various input sections, fill constants, and, eventually, other |
327 | types of information. They also describe relocs that must be |
313 | types of information. They also describe relocs that must be |
328 | created by the BFD backend, but do not correspond to any input |
314 | created by the BFD backend, but do not correspond to any input |
329 | file; this is used to support -Ur, which builds constructors |
315 | file; this is used to support -Ur, which builds constructors |
330 | while generating a relocatable object file. |
316 | while generating a relocatable object file. |
331 | 317 | ||
332 | INODE |
318 | INODE |
333 | Relocating the section contents, Writing the symbol table, Information provided by the linker, Performing the Final Link |
319 | Relocating the section contents, Writing the symbol table, Information provided by the linker, Performing the Final Link |
334 | SUBSUBSECTION |
320 | SUBSUBSECTION |
335 | Relocating the section contents |
321 | Relocating the section contents |
336 | 322 | ||
337 | The <<_bfd_final_link>> function should look through the |
323 | The <<_bfd_final_link>> function should look through the |
338 | < |
324 | < |
339 | output file. Each < |
325 | output file. Each < |
340 | handled specially, or it should be passed to the function |
326 | handled specially, or it should be passed to the function |
341 | <<_bfd_default_link_order>> which will do the right thing |
327 | <<_bfd_default_link_order>> which will do the right thing |
342 | (<<_bfd_default_link_order>> is defined in < |
328 | (<<_bfd_default_link_order>> is defined in < |
343 | 329 | ||
344 | For efficiency, a < |
330 | For efficiency, a < |
345 | < |
331 | < |
346 | to a BFD of the same format as the output BFD must be handled |
332 | to a BFD of the same format as the output BFD must be handled |
347 | specially. This type of < |
333 | specially. This type of < |
348 | output section in terms of a section belonging to one of the |
334 | output section in terms of a section belonging to one of the |
349 | input files. The <<_bfd_final_link>> function should read the |
335 | input files. The <<_bfd_final_link>> function should read the |
350 | contents of the section and any associated relocs, apply the |
336 | contents of the section and any associated relocs, apply the |
351 | relocs to the section contents, and write out the modified |
337 | relocs to the section contents, and write out the modified |
352 | section contents. If performing a relocatable link, the |
338 | section contents. If performing a relocatable link, the |
353 | relocs themselves must also be modified and written out. |
339 | relocs themselves must also be modified and written out. |
354 | 340 | ||
355 | @findex _bfd_relocate_contents |
341 | @findex _bfd_relocate_contents |
356 | @findex _bfd_final_link_relocate |
342 | @findex _bfd_final_link_relocate |
357 | The functions <<_bfd_relocate_contents>> and |
343 | The functions <<_bfd_relocate_contents>> and |
358 | <<_bfd_final_link_relocate>> provide some general support for |
344 | <<_bfd_final_link_relocate>> provide some general support for |
359 | performing the actual relocations, notably overflow checking. |
345 | performing the actual relocations, notably overflow checking. |
360 | Their arguments include information about the symbol the |
346 | Their arguments include information about the symbol the |
361 | relocation is against and a < |
347 | relocation is against and a < |
362 | which describes the relocation to perform. These functions |
348 | which describes the relocation to perform. These functions |
363 | are defined in < |
349 | are defined in < |
364 | 350 | ||
365 | The a.out function which handles reading, relocating, and |
351 | The a.out function which handles reading, relocating, and |
366 | writing section contents is < |
352 | writing section contents is < |
367 | actual relocation is done in < |
353 | actual relocation is done in < |
368 | and < |
354 | and < |
369 | 355 | ||
370 | INODE |
356 | INODE |
371 | Writing the symbol table, , Relocating the section contents, Performing the Final Link |
357 | Writing the symbol table, , Relocating the section contents, Performing the Final Link |
372 | SUBSUBSECTION |
358 | SUBSUBSECTION |
373 | Writing the symbol table |
359 | Writing the symbol table |
374 | 360 | ||
375 | The <<_bfd_final_link>> function must gather all the symbols |
361 | The <<_bfd_final_link>> function must gather all the symbols |
376 | in the input files and write them out. It must also write out |
362 | in the input files and write them out. It must also write out |
377 | all the symbols in the global hash table. This must be |
363 | all the symbols in the global hash table. This must be |
378 | controlled by the < |
364 | controlled by the < |
379 | < |
365 | < |
380 | 366 | ||
381 | The local symbols of the input files will not have been |
367 | The local symbols of the input files will not have been |
382 | entered into the linker hash table. The <<_bfd_final_link>> |
368 | entered into the linker hash table. The <<_bfd_final_link>> |
383 | routine must consider each input file and include the symbols |
369 | routine must consider each input file and include the symbols |
384 | in the output file. It may be convenient to do this when |
370 | in the output file. It may be convenient to do this when |
385 | looking through the < |
371 | looking through the < |
386 | done by stepping through the < |
372 | done by stepping through the < |
387 | 373 | ||
388 | The <<_bfd_final_link>> routine must also traverse the global |
374 | The <<_bfd_final_link>> routine must also traverse the global |
389 | hash table to gather all the externally visible symbols. It |
375 | hash table to gather all the externally visible symbols. It |
390 | is possible that most of the externally visible symbols may be |
376 | is possible that most of the externally visible symbols may be |
391 | written out when considering the symbols of each input file, |
377 | written out when considering the symbols of each input file, |
392 | but it is still necessary to traverse the hash table since the |
378 | but it is still necessary to traverse the hash table since the |
393 | linker script may have defined some symbols that are not in |
379 | linker script may have defined some symbols that are not in |
394 | any of the input files. |
380 | any of the input files. |
395 | 381 | ||
396 | The < |
382 | The < |
397 | controls which symbols are written out. The possible values |
383 | controls which symbols are written out. The possible values |
398 | are listed in < |
384 | are listed in < |
399 | then the < |
385 | then the < |
400 | structure is a hash table of symbols to keep; each symbol |
386 | structure is a hash table of symbols to keep; each symbol |
401 | should be looked up in this hash table, and only symbols which |
387 | should be looked up in this hash table, and only symbols which |
402 | are present should be included in the output file. |
388 | are present should be included in the output file. |
403 | 389 | ||
404 | If the < |
390 | If the < |
405 | permits local symbols to be written out, the < |
391 | permits local symbols to be written out, the < |
406 | is used to further controls which local symbols are included |
392 | is used to further controls which local symbols are included |
407 | in the output file. If the value is < |
393 | in the output file. If the value is < |
408 | local symbols which begin with a certain prefix are discarded; |
394 | local symbols which begin with a certain prefix are discarded; |
409 | this is controlled by the < |
395 | this is controlled by the < |
410 | 396 | ||
411 | The a.out backend handles symbols by calling |
397 | The a.out backend handles symbols by calling |
412 | < |
398 | < |
413 | traversing the global hash table with the function |
399 | traversing the global hash table with the function |
414 | < |
400 | < |
415 | while writing out the symbols, which is written to the output |
401 | while writing out the symbols, which is written to the output |
416 | file at the end of < |
402 | file at the end of < |
417 | */ |
403 | */ |
418 | 404 | ||
419 | static bfd_boolean generic_link_add_object_symbols |
405 | static bfd_boolean generic_link_add_object_symbols |
420 | (bfd *, struct bfd_link_info *, bfd_boolean collect); |
406 | (bfd *, struct bfd_link_info *, bfd_boolean collect); |
421 | static bfd_boolean generic_link_add_symbols |
407 | static bfd_boolean generic_link_add_symbols |
422 | (bfd *, struct bfd_link_info *, bfd_boolean); |
408 | (bfd *, struct bfd_link_info *, bfd_boolean); |
423 | static bfd_boolean generic_link_check_archive_element_no_collect |
409 | static bfd_boolean generic_link_check_archive_element_no_collect |
424 | (bfd *, struct bfd_link_info *, bfd_boolean *); |
410 | (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, |
- | 411 | bfd_boolean *); |
|
425 | static bfd_boolean generic_link_check_archive_element_collect |
412 | static bfd_boolean generic_link_check_archive_element_collect |
426 | (bfd *, struct bfd_link_info *, bfd_boolean *); |
413 | (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, |
- | 414 | bfd_boolean *); |
|
427 | static bfd_boolean generic_link_check_archive_element |
415 | static bfd_boolean generic_link_check_archive_element |
428 | (bfd *, struct bfd_link_info *, bfd_boolean *, bfd_boolean); |
416 | (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, |
- | 417 | bfd_boolean *, bfd_boolean); |
|
429 | static bfd_boolean generic_link_add_symbol_list |
418 | static bfd_boolean generic_link_add_symbol_list |
430 | (bfd *, struct bfd_link_info *, bfd_size_type count, asymbol **, |
419 | (bfd *, struct bfd_link_info *, bfd_size_type count, asymbol **, |
431 | bfd_boolean); |
420 | bfd_boolean); |
432 | static bfd_boolean generic_add_output_symbol |
421 | static bfd_boolean generic_add_output_symbol |
433 | (bfd *, size_t *psymalloc, asymbol *); |
422 | (bfd *, size_t *psymalloc, asymbol *); |
434 | static bfd_boolean default_data_link_order |
423 | static bfd_boolean default_data_link_order |
435 | (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *); |
424 | (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *); |
436 | static bfd_boolean default_indirect_link_order |
425 | static bfd_boolean default_indirect_link_order |
437 | (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *, |
426 | (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *, |
438 | bfd_boolean); |
427 | bfd_boolean); |
439 | 428 | ||
440 | /* The link hash table structure is defined in bfdlink.h. It provides |
429 | /* The link hash table structure is defined in bfdlink.h. It provides |
441 | a base hash table which the backend specific hash tables are built |
430 | a base hash table which the backend specific hash tables are built |
442 | upon. */ |
431 | upon. */ |
443 | 432 | ||
444 | /* Routine to create an entry in the link hash table. */ |
433 | /* Routine to create an entry in the link hash table. */ |
445 | 434 | ||
446 | struct bfd_hash_entry * |
435 | struct bfd_hash_entry * |
447 | _bfd_link_hash_newfunc (struct bfd_hash_entry *entry, |
436 | _bfd_link_hash_newfunc (struct bfd_hash_entry *entry, |
448 | struct bfd_hash_table *table, |
437 | struct bfd_hash_table *table, |
449 | const char *string) |
438 | const char *string) |
450 | { |
439 | { |
451 | /* Allocate the structure if it has not already been allocated by a |
440 | /* Allocate the structure if it has not already been allocated by a |
452 | subclass. */ |
441 | subclass. */ |
453 | if (entry == NULL) |
442 | if (entry == NULL) |
454 | { |
443 | { |
455 | entry = (struct bfd_hash_entry *) |
444 | entry = (struct bfd_hash_entry *) |
456 | bfd_hash_allocate (table, sizeof (struct bfd_link_hash_entry)); |
445 | bfd_hash_allocate (table, sizeof (struct bfd_link_hash_entry)); |
457 | if (entry == NULL) |
446 | if (entry == NULL) |
458 | return entry; |
447 | return entry; |
459 | } |
448 | } |
460 | 449 | ||
461 | /* Call the allocation method of the superclass. */ |
450 | /* Call the allocation method of the superclass. */ |
462 | entry = bfd_hash_newfunc (entry, table, string); |
451 | entry = bfd_hash_newfunc (entry, table, string); |
463 | if (entry) |
452 | if (entry) |
464 | { |
453 | { |
465 | struct bfd_link_hash_entry *h = (struct bfd_link_hash_entry *) entry; |
454 | struct bfd_link_hash_entry *h = (struct bfd_link_hash_entry *) entry; |
466 | 455 | ||
467 | /* Initialize the local fields. */ |
456 | /* Initialize the local fields. */ |
468 | memset ((char *) &h->root + sizeof (h->root), 0, |
457 | memset ((char *) &h->root + sizeof (h->root), 0, |
469 | sizeof (*h) - sizeof (h->root)); |
458 | sizeof (*h) - sizeof (h->root)); |
470 | } |
459 | } |
471 | 460 | ||
472 | return entry; |
461 | return entry; |
473 | } |
462 | } |
474 | 463 | ||
475 | /* Initialize a link hash table. The BFD argument is the one |
464 | /* Initialize a link hash table. The BFD argument is the one |
476 | responsible for creating this table. */ |
465 | responsible for creating this table. */ |
477 | 466 | ||
478 | bfd_boolean |
467 | bfd_boolean |
479 | _bfd_link_hash_table_init |
468 | _bfd_link_hash_table_init |
480 | (struct bfd_link_hash_table *table, |
469 | (struct bfd_link_hash_table *table, |
481 | bfd *abfd ATTRIBUTE_UNUSED, |
470 | bfd *abfd ATTRIBUTE_UNUSED, |
482 | struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, |
471 | struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, |
483 | struct bfd_hash_table *, |
472 | struct bfd_hash_table *, |
484 | const char *), |
473 | const char *), |
485 | unsigned int entsize) |
474 | unsigned int entsize) |
486 | { |
475 | { |
- | 476 | bfd_boolean ret; |
|
- | 477 | ||
- | 478 | BFD_ASSERT (!abfd->is_linker_output && !abfd->link.hash); |
|
487 | table->undefs = NULL; |
479 | table->undefs = NULL; |
488 | table->undefs_tail = NULL; |
480 | table->undefs_tail = NULL; |
489 | table->type = bfd_link_generic_hash_table; |
481 | table->type = bfd_link_generic_hash_table; |
490 | 482 | ||
- | 483 | ret = bfd_hash_table_init (&table->table, newfunc, entsize); |
|
- | 484 | if (ret) |
|
- | 485 | { |
|
- | 486 | /* Arrange for destruction of this hash table on closing ABFD. */ |
|
- | 487 | table->hash_table_free = _bfd_generic_link_hash_table_free; |
|
- | 488 | abfd->link.hash = table; |
|
- | 489 | abfd->is_linker_output = TRUE; |
|
- | 490 | } |
|
491 | return bfd_hash_table_init (&table->table, newfunc, entsize); |
491 | return ret; |
492 | } |
492 | } |
493 | 493 | ||
494 | /* Look up a symbol in a link hash table. If follow is TRUE, we |
494 | /* Look up a symbol in a link hash table. If follow is TRUE, we |
495 | follow bfd_link_hash_indirect and bfd_link_hash_warning links to |
495 | follow bfd_link_hash_indirect and bfd_link_hash_warning links to |
496 | the real symbol. */ |
496 | the real symbol. */ |
497 | 497 | ||
498 | struct bfd_link_hash_entry * |
498 | struct bfd_link_hash_entry * |
499 | bfd_link_hash_lookup (struct bfd_link_hash_table *table, |
499 | bfd_link_hash_lookup (struct bfd_link_hash_table *table, |
500 | const char *string, |
500 | const char *string, |
501 | bfd_boolean create, |
501 | bfd_boolean create, |
502 | bfd_boolean copy, |
502 | bfd_boolean copy, |
503 | bfd_boolean follow) |
503 | bfd_boolean follow) |
504 | { |
504 | { |
505 | struct bfd_link_hash_entry *ret; |
505 | struct bfd_link_hash_entry *ret; |
506 | 506 | ||
507 | ret = ((struct bfd_link_hash_entry *) |
507 | ret = ((struct bfd_link_hash_entry *) |
508 | bfd_hash_lookup (&table->table, string, create, copy)); |
508 | bfd_hash_lookup (&table->table, string, create, copy)); |
509 | 509 | ||
510 | if (follow && ret != NULL) |
510 | if (follow && ret != NULL) |
511 | { |
511 | { |
512 | while (ret->type == bfd_link_hash_indirect |
512 | while (ret->type == bfd_link_hash_indirect |
513 | || ret->type == bfd_link_hash_warning) |
513 | || ret->type == bfd_link_hash_warning) |
514 | ret = ret->u.i.link; |
514 | ret = ret->u.i.link; |
515 | } |
515 | } |
516 | 516 | ||
517 | return ret; |
517 | return ret; |
518 | } |
518 | } |
519 | 519 | ||
520 | /* Look up a symbol in the main linker hash table if the symbol might |
520 | /* Look up a symbol in the main linker hash table if the symbol might |
521 | be wrapped. This should only be used for references to an |
521 | be wrapped. This should only be used for references to an |
522 | undefined symbol, not for definitions of a symbol. */ |
522 | undefined symbol, not for definitions of a symbol. */ |
523 | 523 | ||
524 | struct bfd_link_hash_entry * |
524 | struct bfd_link_hash_entry * |
525 | bfd_wrapped_link_hash_lookup (bfd *abfd, |
525 | bfd_wrapped_link_hash_lookup (bfd *abfd, |
526 | struct bfd_link_info *info, |
526 | struct bfd_link_info *info, |
527 | const char *string, |
527 | const char *string, |
528 | bfd_boolean create, |
528 | bfd_boolean create, |
529 | bfd_boolean copy, |
529 | bfd_boolean copy, |
530 | bfd_boolean follow) |
530 | bfd_boolean follow) |
531 | { |
531 | { |
532 | bfd_size_type amt; |
532 | bfd_size_type amt; |
533 | 533 | ||
534 | if (info->wrap_hash != NULL) |
534 | if (info->wrap_hash != NULL) |
535 | { |
535 | { |
536 | const char *l; |
536 | const char *l; |
537 | char prefix = '\0'; |
537 | char prefix = '\0'; |
538 | 538 | ||
539 | l = string; |
539 | l = string; |
540 | if (*l == bfd_get_symbol_leading_char (abfd) || *l == info->wrap_char) |
540 | if (*l == bfd_get_symbol_leading_char (abfd) || *l == info->wrap_char) |
541 | { |
541 | { |
542 | prefix = *l; |
542 | prefix = *l; |
543 | ++l; |
543 | ++l; |
544 | } |
544 | } |
545 | 545 | ||
546 | #undef WRAP |
546 | #undef WRAP |
547 | #define WRAP "__wrap_" |
547 | #define WRAP "__wrap_" |
548 | 548 | ||
549 | if (bfd_hash_lookup (info->wrap_hash, l, FALSE, FALSE) != NULL) |
549 | if (bfd_hash_lookup (info->wrap_hash, l, FALSE, FALSE) != NULL) |
550 | { |
550 | { |
551 | char *n; |
551 | char *n; |
552 | struct bfd_link_hash_entry *h; |
552 | struct bfd_link_hash_entry *h; |
553 | 553 | ||
554 | /* This symbol is being wrapped. We want to replace all |
554 | /* This symbol is being wrapped. We want to replace all |
555 | references to SYM with references to __wrap_SYM. */ |
555 | references to SYM with references to __wrap_SYM. */ |
556 | 556 | ||
557 | amt = strlen (l) + sizeof WRAP + 1; |
557 | amt = strlen (l) + sizeof WRAP + 1; |
558 | n = (char *) bfd_malloc (amt); |
558 | n = (char *) bfd_malloc (amt); |
559 | if (n == NULL) |
559 | if (n == NULL) |
560 | return NULL; |
560 | return NULL; |
561 | 561 | ||
562 | n[0] = prefix; |
562 | n[0] = prefix; |
563 | n[1] = '\0'; |
563 | n[1] = '\0'; |
564 | strcat (n, WRAP); |
564 | strcat (n, WRAP); |
565 | strcat (n, l); |
565 | strcat (n, l); |
566 | h = bfd_link_hash_lookup (info->hash, n, create, TRUE, follow); |
566 | h = bfd_link_hash_lookup (info->hash, n, create, TRUE, follow); |
567 | free (n); |
567 | free (n); |
568 | return h; |
568 | return h; |
569 | } |
569 | } |
570 | - | ||
571 | #undef WRAP |
- | |
572 | 570 | ||
573 | #undef REAL |
571 | #undef REAL |
574 | #define REAL "__real_" |
572 | #define REAL "__real_" |
575 | 573 | ||
576 | if (*l == '_' |
574 | if (*l == '_' |
577 | && CONST_STRNEQ (l, REAL) |
575 | && CONST_STRNEQ (l, REAL) |
578 | && bfd_hash_lookup (info->wrap_hash, l + sizeof REAL - 1, |
576 | && bfd_hash_lookup (info->wrap_hash, l + sizeof REAL - 1, |
579 | FALSE, FALSE) != NULL) |
577 | FALSE, FALSE) != NULL) |
580 | { |
578 | { |
581 | char *n; |
579 | char *n; |
582 | struct bfd_link_hash_entry *h; |
580 | struct bfd_link_hash_entry *h; |
583 | 581 | ||
584 | /* This is a reference to __real_SYM, where SYM is being |
582 | /* This is a reference to __real_SYM, where SYM is being |
585 | wrapped. We want to replace all references to __real_SYM |
583 | wrapped. We want to replace all references to __real_SYM |
586 | with references to SYM. */ |
584 | with references to SYM. */ |
587 | 585 | ||
588 | amt = strlen (l + sizeof REAL - 1) + 2; |
586 | amt = strlen (l + sizeof REAL - 1) + 2; |
589 | n = (char *) bfd_malloc (amt); |
587 | n = (char *) bfd_malloc (amt); |
590 | if (n == NULL) |
588 | if (n == NULL) |
591 | return NULL; |
589 | return NULL; |
592 | 590 | ||
593 | n[0] = prefix; |
591 | n[0] = prefix; |
594 | n[1] = '\0'; |
592 | n[1] = '\0'; |
595 | strcat (n, l + sizeof REAL - 1); |
593 | strcat (n, l + sizeof REAL - 1); |
596 | h = bfd_link_hash_lookup (info->hash, n, create, TRUE, follow); |
594 | h = bfd_link_hash_lookup (info->hash, n, create, TRUE, follow); |
597 | free (n); |
595 | free (n); |
598 | return h; |
596 | return h; |
599 | } |
597 | } |
600 | 598 | ||
601 | #undef REAL |
599 | #undef REAL |
602 | } |
600 | } |
603 | 601 | ||
604 | return bfd_link_hash_lookup (info->hash, string, create, copy, follow); |
602 | return bfd_link_hash_lookup (info->hash, string, create, copy, follow); |
605 | } |
603 | } |
- | 604 | ||
- | 605 | /* If H is a wrapped symbol, ie. the symbol name starts with "__wrap_" |
|
- | 606 | and the remainder is found in wrap_hash, return the real symbol. */ |
|
- | 607 | ||
- | 608 | struct bfd_link_hash_entry * |
|
- | 609 | unwrap_hash_lookup (struct bfd_link_info *info, |
|
- | 610 | bfd *input_bfd, |
|
- | 611 | struct bfd_link_hash_entry *h) |
|
- | 612 | { |
|
- | 613 | const char *l = h->root.string; |
|
- | 614 | ||
- | 615 | if (*l == bfd_get_symbol_leading_char (input_bfd) |
|
- | 616 | || *l == info->wrap_char) |
|
- | 617 | ++l; |
|
- | 618 | ||
- | 619 | if (CONST_STRNEQ (l, WRAP)) |
|
- | 620 | { |
|
- | 621 | l += sizeof WRAP - 1; |
|
- | 622 | ||
- | 623 | if (bfd_hash_lookup (info->wrap_hash, l, FALSE, FALSE) != NULL) |
|
- | 624 | { |
|
- | 625 | char save = 0; |
|
- | 626 | if (l - (sizeof WRAP - 1) != h->root.string) |
|
- | 627 | { |
|
- | 628 | --l; |
|
- | 629 | save = *l; |
|
- | 630 | *(char *) l = *h->root.string; |
|
- | 631 | } |
|
- | 632 | h = bfd_link_hash_lookup (info->hash, l, FALSE, FALSE, FALSE); |
|
- | 633 | if (save) |
|
- | 634 | *(char *) l = save; |
|
- | 635 | } |
|
- | 636 | } |
|
- | 637 | return h; |
|
- | 638 | } |
|
- | 639 | #undef WRAP |
|
606 | 640 | ||
607 | /* Traverse a generic link hash table. Differs from bfd_hash_traverse |
641 | /* Traverse a generic link hash table. Differs from bfd_hash_traverse |
608 | in the treatment of warning symbols. When warning symbols are |
642 | in the treatment of warning symbols. When warning symbols are |
609 | created they replace the real symbol, so you don't get to see the |
643 | created they replace the real symbol, so you don't get to see the |
610 | real symbol in a bfd_hash_travere. This traversal calls func with |
644 | real symbol in a bfd_hash_travere. This traversal calls func with |
611 | the real symbol. */ |
645 | the real symbol. */ |
612 | 646 | ||
613 | void |
647 | void |
614 | bfd_link_hash_traverse |
648 | bfd_link_hash_traverse |
615 | (struct bfd_link_hash_table *htab, |
649 | (struct bfd_link_hash_table *htab, |
616 | bfd_boolean (*func) (struct bfd_link_hash_entry *, void *), |
650 | bfd_boolean (*func) (struct bfd_link_hash_entry *, void *), |
617 | void *info) |
651 | void *info) |
618 | { |
652 | { |
619 | unsigned int i; |
653 | unsigned int i; |
620 | 654 | ||
621 | htab->table.frozen = 1; |
655 | htab->table.frozen = 1; |
622 | for (i = 0; i < htab->table.size; i++) |
656 | for (i = 0; i < htab->table.size; i++) |
623 | { |
657 | { |
624 | struct bfd_link_hash_entry *p; |
658 | struct bfd_link_hash_entry *p; |
625 | 659 | ||
626 | p = (struct bfd_link_hash_entry *) htab->table.table[i]; |
660 | p = (struct bfd_link_hash_entry *) htab->table.table[i]; |
627 | for (; p != NULL; p = (struct bfd_link_hash_entry *) p->root.next) |
661 | for (; p != NULL; p = (struct bfd_link_hash_entry *) p->root.next) |
628 | if (!(*func) (p->type == bfd_link_hash_warning ? p->u.i.link : p, info)) |
662 | if (!(*func) (p->type == bfd_link_hash_warning ? p->u.i.link : p, info)) |
629 | goto out; |
663 | goto out; |
630 | } |
664 | } |
631 | out: |
665 | out: |
632 | htab->table.frozen = 0; |
666 | htab->table.frozen = 0; |
633 | } |
667 | } |
634 | 668 | ||
635 | /* Add a symbol to the linker hash table undefs list. */ |
669 | /* Add a symbol to the linker hash table undefs list. */ |
636 | 670 | ||
637 | void |
671 | void |
638 | bfd_link_add_undef (struct bfd_link_hash_table *table, |
672 | bfd_link_add_undef (struct bfd_link_hash_table *table, |
639 | struct bfd_link_hash_entry *h) |
673 | struct bfd_link_hash_entry *h) |
640 | { |
674 | { |
641 | BFD_ASSERT (h->u.undef.next == NULL); |
675 | BFD_ASSERT (h->u.undef.next == NULL); |
642 | if (table->undefs_tail != NULL) |
676 | if (table->undefs_tail != NULL) |
643 | table->undefs_tail->u.undef.next = h; |
677 | table->undefs_tail->u.undef.next = h; |
644 | if (table->undefs == NULL) |
678 | if (table->undefs == NULL) |
645 | table->undefs = h; |
679 | table->undefs = h; |
646 | table->undefs_tail = h; |
680 | table->undefs_tail = h; |
647 | } |
681 | } |
648 | 682 | ||
649 | /* The undefs list was designed so that in normal use we don't need to |
683 | /* The undefs list was designed so that in normal use we don't need to |
650 | remove entries. However, if symbols on the list are changed from |
684 | remove entries. However, if symbols on the list are changed from |
651 | bfd_link_hash_undefined to either bfd_link_hash_undefweak or |
685 | bfd_link_hash_undefined to either bfd_link_hash_undefweak or |
652 | bfd_link_hash_new for some reason, then they must be removed from the |
686 | bfd_link_hash_new for some reason, then they must be removed from the |
653 | list. Failure to do so might result in the linker attempting to add |
687 | list. Failure to do so might result in the linker attempting to add |
654 | the symbol to the list again at a later stage. */ |
688 | the symbol to the list again at a later stage. */ |
655 | 689 | ||
656 | void |
690 | void |
657 | bfd_link_repair_undef_list (struct bfd_link_hash_table *table) |
691 | bfd_link_repair_undef_list (struct bfd_link_hash_table *table) |
658 | { |
692 | { |
659 | struct bfd_link_hash_entry **pun; |
693 | struct bfd_link_hash_entry **pun; |
660 | 694 | ||
661 | pun = &table->undefs; |
695 | pun = &table->undefs; |
662 | while (*pun != NULL) |
696 | while (*pun != NULL) |
663 | { |
697 | { |
664 | struct bfd_link_hash_entry *h = *pun; |
698 | struct bfd_link_hash_entry *h = *pun; |
665 | 699 | ||
666 | if (h->type == bfd_link_hash_new |
700 | if (h->type == bfd_link_hash_new |
667 | || h->type == bfd_link_hash_undefweak) |
701 | || h->type == bfd_link_hash_undefweak) |
668 | { |
702 | { |
669 | *pun = h->u.undef.next; |
703 | *pun = h->u.undef.next; |
670 | h->u.undef.next = NULL; |
704 | h->u.undef.next = NULL; |
671 | if (h == table->undefs_tail) |
705 | if (h == table->undefs_tail) |
672 | { |
706 | { |
673 | if (pun == &table->undefs) |
707 | if (pun == &table->undefs) |
674 | table->undefs_tail = NULL; |
708 | table->undefs_tail = NULL; |
675 | else |
709 | else |
676 | /* pun points at an u.undef.next field. Go back to |
710 | /* pun points at an u.undef.next field. Go back to |
677 | the start of the link_hash_entry. */ |
711 | the start of the link_hash_entry. */ |
678 | table->undefs_tail = (struct bfd_link_hash_entry *) |
712 | table->undefs_tail = (struct bfd_link_hash_entry *) |
679 | ((char *) pun - ((char *) &h->u.undef.next - (char *) h)); |
713 | ((char *) pun - ((char *) &h->u.undef.next - (char *) h)); |
680 | break; |
714 | break; |
681 | } |
715 | } |
682 | } |
716 | } |
683 | else |
717 | else |
684 | pun = &h->u.undef.next; |
718 | pun = &h->u.undef.next; |
685 | } |
719 | } |
686 | } |
720 | } |
687 | 721 | ||
688 | /* Routine to create an entry in a generic link hash table. */ |
722 | /* Routine to create an entry in a generic link hash table. */ |
689 | 723 | ||
690 | struct bfd_hash_entry * |
724 | struct bfd_hash_entry * |
691 | _bfd_generic_link_hash_newfunc (struct bfd_hash_entry *entry, |
725 | _bfd_generic_link_hash_newfunc (struct bfd_hash_entry *entry, |
692 | struct bfd_hash_table *table, |
726 | struct bfd_hash_table *table, |
693 | const char *string) |
727 | const char *string) |
694 | { |
728 | { |
695 | /* Allocate the structure if it has not already been allocated by a |
729 | /* Allocate the structure if it has not already been allocated by a |
696 | subclass. */ |
730 | subclass. */ |
697 | if (entry == NULL) |
731 | if (entry == NULL) |
698 | { |
732 | { |
699 | entry = (struct bfd_hash_entry *) |
733 | entry = (struct bfd_hash_entry *) |
700 | bfd_hash_allocate (table, sizeof (struct generic_link_hash_entry)); |
734 | bfd_hash_allocate (table, sizeof (struct generic_link_hash_entry)); |
701 | if (entry == NULL) |
735 | if (entry == NULL) |
702 | return entry; |
736 | return entry; |
703 | } |
737 | } |
704 | 738 | ||
705 | /* Call the allocation method of the superclass. */ |
739 | /* Call the allocation method of the superclass. */ |
706 | entry = _bfd_link_hash_newfunc (entry, table, string); |
740 | entry = _bfd_link_hash_newfunc (entry, table, string); |
707 | if (entry) |
741 | if (entry) |
708 | { |
742 | { |
709 | struct generic_link_hash_entry *ret; |
743 | struct generic_link_hash_entry *ret; |
710 | 744 | ||
711 | /* Set local fields. */ |
745 | /* Set local fields. */ |
712 | ret = (struct generic_link_hash_entry *) entry; |
746 | ret = (struct generic_link_hash_entry *) entry; |
713 | ret->written = FALSE; |
747 | ret->written = FALSE; |
714 | ret->sym = NULL; |
748 | ret->sym = NULL; |
715 | } |
749 | } |
716 | 750 | ||
717 | return entry; |
751 | return entry; |
718 | } |
752 | } |
719 | 753 | ||
720 | /* Create a generic link hash table. */ |
754 | /* Create a generic link hash table. */ |
721 | 755 | ||
722 | struct bfd_link_hash_table * |
756 | struct bfd_link_hash_table * |
723 | _bfd_generic_link_hash_table_create (bfd *abfd) |
757 | _bfd_generic_link_hash_table_create (bfd *abfd) |
724 | { |
758 | { |
725 | struct generic_link_hash_table *ret; |
759 | struct generic_link_hash_table *ret; |
726 | bfd_size_type amt = sizeof (struct generic_link_hash_table); |
760 | bfd_size_type amt = sizeof (struct generic_link_hash_table); |
727 | 761 | ||
728 | ret = (struct generic_link_hash_table *) bfd_malloc (amt); |
762 | ret = (struct generic_link_hash_table *) bfd_malloc (amt); |
729 | if (ret == NULL) |
763 | if (ret == NULL) |
730 | return NULL; |
764 | return NULL; |
731 | if (! _bfd_link_hash_table_init (&ret->root, abfd, |
765 | if (! _bfd_link_hash_table_init (&ret->root, abfd, |
732 | _bfd_generic_link_hash_newfunc, |
766 | _bfd_generic_link_hash_newfunc, |
733 | sizeof (struct generic_link_hash_entry))) |
767 | sizeof (struct generic_link_hash_entry))) |
734 | { |
768 | { |
735 | free (ret); |
769 | free (ret); |
736 | return NULL; |
770 | return NULL; |
737 | } |
771 | } |
738 | return &ret->root; |
772 | return &ret->root; |
739 | } |
773 | } |
740 | 774 | ||
741 | void |
775 | void |
742 | _bfd_generic_link_hash_table_free (struct bfd_link_hash_table *hash) |
776 | _bfd_generic_link_hash_table_free (bfd *obfd) |
743 | { |
777 | { |
744 | struct generic_link_hash_table *ret |
778 | struct generic_link_hash_table *ret; |
745 | = (struct generic_link_hash_table *) hash; |
- | |
- | 779 | ||
- | 780 | BFD_ASSERT (obfd->is_linker_output && obfd->link.hash); |
|
746 | 781 | ret = (struct generic_link_hash_table *) obfd->link.hash; |
|
747 | bfd_hash_table_free (&ret->root.table); |
782 | bfd_hash_table_free (&ret->root.table); |
- | 783 | free (ret); |
|
- | 784 | obfd->link.hash = NULL; |
|
748 | free (ret); |
785 | obfd->is_linker_output = FALSE; |
749 | } |
786 | } |
750 | 787 | ||
751 | /* Grab the symbols for an object file when doing a generic link. We |
788 | /* Grab the symbols for an object file when doing a generic link. We |
752 | store the symbols in the outsymbols field. We need to keep them |
789 | store the symbols in the outsymbols field. We need to keep them |
753 | around for the entire link to ensure that we only read them once. |
790 | around for the entire link to ensure that we only read them once. |
754 | If we read them multiple times, we might wind up with relocs and |
791 | If we read them multiple times, we might wind up with relocs and |
755 | the hash table pointing to different instances of the symbol |
792 | the hash table pointing to different instances of the symbol |
756 | structure. */ |
793 | structure. */ |
757 | 794 | ||
758 | bfd_boolean |
795 | bfd_boolean |
759 | bfd_generic_link_read_symbols (bfd *abfd) |
796 | bfd_generic_link_read_symbols (bfd *abfd) |
760 | { |
797 | { |
761 | if (bfd_get_outsymbols (abfd) == NULL) |
798 | if (bfd_get_outsymbols (abfd) == NULL) |
762 | { |
799 | { |
763 | long symsize; |
800 | long symsize; |
764 | long symcount; |
801 | long symcount; |
765 | 802 | ||
766 | symsize = bfd_get_symtab_upper_bound (abfd); |
803 | symsize = bfd_get_symtab_upper_bound (abfd); |
767 | if (symsize < 0) |
804 | if (symsize < 0) |
768 | return FALSE; |
805 | return FALSE; |
769 | bfd_get_outsymbols (abfd) = (struct bfd_symbol **) bfd_alloc (abfd, |
806 | bfd_get_outsymbols (abfd) = (struct bfd_symbol **) bfd_alloc (abfd, |
770 | symsize); |
807 | symsize); |
771 | if (bfd_get_outsymbols (abfd) == NULL && symsize != 0) |
808 | if (bfd_get_outsymbols (abfd) == NULL && symsize != 0) |
772 | return FALSE; |
809 | return FALSE; |
773 | symcount = bfd_canonicalize_symtab (abfd, bfd_get_outsymbols (abfd)); |
810 | symcount = bfd_canonicalize_symtab (abfd, bfd_get_outsymbols (abfd)); |
774 | if (symcount < 0) |
811 | if (symcount < 0) |
775 | return FALSE; |
812 | return FALSE; |
776 | bfd_get_symcount (abfd) = symcount; |
813 | bfd_get_symcount (abfd) = symcount; |
777 | } |
814 | } |
778 | 815 | ||
779 | return TRUE; |
816 | return TRUE; |
780 | } |
817 | } |
781 | 818 | ||
782 | /* Generic function to add symbols to from an object file to the |
819 | /* Generic function to add symbols to from an object file to the |
783 | global hash table. This version does not automatically collect |
820 | global hash table. This version does not automatically collect |
784 | constructors by name. */ |
821 | constructors by name. */ |
785 | 822 | ||
786 | bfd_boolean |
823 | bfd_boolean |
787 | _bfd_generic_link_add_symbols (bfd *abfd, struct bfd_link_info *info) |
824 | _bfd_generic_link_add_symbols (bfd *abfd, struct bfd_link_info *info) |
788 | { |
825 | { |
789 | return generic_link_add_symbols (abfd, info, FALSE); |
826 | return generic_link_add_symbols (abfd, info, FALSE); |
790 | } |
827 | } |
791 | 828 | ||
792 | /* Generic function to add symbols from an object file to the global |
829 | /* Generic function to add symbols from an object file to the global |
793 | hash table. This version automatically collects constructors by |
830 | hash table. This version automatically collects constructors by |
794 | name, as the collect2 program does. It should be used for any |
831 | name, as the collect2 program does. It should be used for any |
795 | target which does not provide some other mechanism for setting up |
832 | target which does not provide some other mechanism for setting up |
796 | constructors and destructors; these are approximately those targets |
833 | constructors and destructors; these are approximately those targets |
797 | for which gcc uses collect2 and do not support stabs. */ |
834 | for which gcc uses collect2 and do not support stabs. */ |
798 | 835 | ||
799 | bfd_boolean |
836 | bfd_boolean |
800 | _bfd_generic_link_add_symbols_collect (bfd *abfd, struct bfd_link_info *info) |
837 | _bfd_generic_link_add_symbols_collect (bfd *abfd, struct bfd_link_info *info) |
801 | { |
838 | { |
802 | return generic_link_add_symbols (abfd, info, TRUE); |
839 | return generic_link_add_symbols (abfd, info, TRUE); |
803 | } |
840 | } |
804 | 841 | ||
805 | /* Indicate that we are only retrieving symbol values from this |
842 | /* Indicate that we are only retrieving symbol values from this |
806 | section. We want the symbols to act as though the values in the |
843 | section. We want the symbols to act as though the values in the |
807 | file are absolute. */ |
844 | file are absolute. */ |
808 | 845 | ||
809 | void |
846 | void |
810 | _bfd_generic_link_just_syms (asection *sec, |
847 | _bfd_generic_link_just_syms (asection *sec, |
811 | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
848 | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
812 | { |
849 | { |
813 | sec->sec_info_type = SEC_INFO_TYPE_JUST_SYMS; |
850 | sec->sec_info_type = SEC_INFO_TYPE_JUST_SYMS; |
814 | sec->output_section = bfd_abs_section_ptr; |
851 | sec->output_section = bfd_abs_section_ptr; |
815 | sec->output_offset = sec->vma; |
852 | sec->output_offset = sec->vma; |
816 | } |
853 | } |
817 | 854 | ||
818 | /* Copy the type of a symbol assiciated with a linker hast table entry. |
- | |
819 | Override this so that symbols created in linker scripts get their |
855 | /* Copy the symbol type and other attributes for a linker script |
820 | type from the RHS of the assignment. |
856 | assignment from HSRC to HDEST. |
821 | The default implementation does nothing. */ |
857 | The default implementation does nothing. */ |
822 | void |
858 | void |
823 | _bfd_generic_copy_link_hash_symbol_type (bfd *abfd ATTRIBUTE_UNUSED, |
859 | _bfd_generic_copy_link_hash_symbol_type (bfd *abfd ATTRIBUTE_UNUSED, |
824 | struct bfd_link_hash_entry * hdest ATTRIBUTE_UNUSED, |
860 | struct bfd_link_hash_entry *hdest ATTRIBUTE_UNUSED, |
825 | struct bfd_link_hash_entry * hsrc ATTRIBUTE_UNUSED) |
861 | struct bfd_link_hash_entry *hsrc ATTRIBUTE_UNUSED) |
826 | { |
862 | { |
827 | } |
863 | } |
828 | 864 | ||
829 | /* Add symbols from an object file to the global hash table. */ |
865 | /* Add symbols from an object file to the global hash table. */ |
830 | 866 | ||
831 | static bfd_boolean |
867 | static bfd_boolean |
832 | generic_link_add_symbols (bfd *abfd, |
868 | generic_link_add_symbols (bfd *abfd, |
833 | struct bfd_link_info *info, |
869 | struct bfd_link_info *info, |
834 | bfd_boolean collect) |
870 | bfd_boolean collect) |
835 | { |
871 | { |
836 | bfd_boolean ret; |
872 | bfd_boolean ret; |
837 | 873 | ||
838 | switch (bfd_get_format (abfd)) |
874 | switch (bfd_get_format (abfd)) |
839 | { |
875 | { |
840 | case bfd_object: |
876 | case bfd_object: |
841 | ret = generic_link_add_object_symbols (abfd, info, collect); |
877 | ret = generic_link_add_object_symbols (abfd, info, collect); |
842 | break; |
878 | break; |
843 | case bfd_archive: |
879 | case bfd_archive: |
844 | ret = (_bfd_generic_link_add_archive_symbols |
880 | ret = (_bfd_generic_link_add_archive_symbols |
845 | (abfd, info, |
881 | (abfd, info, |
846 | (collect |
882 | (collect |
847 | ? generic_link_check_archive_element_collect |
883 | ? generic_link_check_archive_element_collect |
848 | : generic_link_check_archive_element_no_collect))); |
884 | : generic_link_check_archive_element_no_collect))); |
849 | break; |
885 | break; |
850 | default: |
886 | default: |
851 | bfd_set_error (bfd_error_wrong_format); |
887 | bfd_set_error (bfd_error_wrong_format); |
852 | ret = FALSE; |
888 | ret = FALSE; |
853 | } |
889 | } |
854 | 890 | ||
855 | return ret; |
891 | return ret; |
856 | } |
892 | } |
857 | 893 | ||
858 | /* Add symbols from an object file to the global hash table. */ |
894 | /* Add symbols from an object file to the global hash table. */ |
859 | 895 | ||
860 | static bfd_boolean |
896 | static bfd_boolean |
861 | generic_link_add_object_symbols (bfd *abfd, |
897 | generic_link_add_object_symbols (bfd *abfd, |
862 | struct bfd_link_info *info, |
898 | struct bfd_link_info *info, |
863 | bfd_boolean collect) |
899 | bfd_boolean collect) |
864 | { |
900 | { |
865 | bfd_size_type symcount; |
901 | bfd_size_type symcount; |
866 | struct bfd_symbol **outsyms; |
902 | struct bfd_symbol **outsyms; |
867 | 903 | ||
868 | if (!bfd_generic_link_read_symbols (abfd)) |
904 | if (!bfd_generic_link_read_symbols (abfd)) |
869 | return FALSE; |
905 | return FALSE; |
870 | symcount = _bfd_generic_link_get_symcount (abfd); |
906 | symcount = _bfd_generic_link_get_symcount (abfd); |
871 | outsyms = _bfd_generic_link_get_symbols (abfd); |
907 | outsyms = _bfd_generic_link_get_symbols (abfd); |
872 | return generic_link_add_symbol_list (abfd, info, symcount, outsyms, collect); |
908 | return generic_link_add_symbol_list (abfd, info, symcount, outsyms, collect); |
873 | } |
909 | } |
874 | 910 | ||
875 | /* We build a hash table of all symbols defined in an archive. */ |
- | |
876 | - | ||
877 | /* An archive symbol may be defined by multiple archive elements. |
- | |
878 | This linked list is used to hold the elements. */ |
- | |
879 | - | ||
880 | struct archive_list |
- | |
881 | { |
- | |
882 | struct archive_list *next; |
- | |
883 | unsigned int indx; |
- | |
884 | }; |
- | |
885 | - | ||
886 | /* An entry in an archive hash table. */ |
- | |
887 | - | ||
888 | struct archive_hash_entry |
- | |
889 | { |
- | |
890 | struct bfd_hash_entry root; |
- | |
891 | /* Where the symbol is defined. */ |
- | |
892 | struct archive_list *defs; |
- | |
893 | }; |
- | |
894 | - | ||
895 | /* An archive hash table itself. */ |
- | |
896 | - | ||
897 | struct archive_hash_table |
- | |
898 | { |
- | |
899 | struct bfd_hash_table table; |
- | |
900 | }; |
- | |
901 | - | ||
902 | /* Create a new entry for an archive hash table. */ |
- | |
903 | - | ||
904 | static struct bfd_hash_entry * |
- | |
905 | archive_hash_newfunc (struct bfd_hash_entry *entry, |
- | |
906 | struct bfd_hash_table *table, |
- | |
907 | const char *string) |
- | |
908 | { |
- | |
909 | struct archive_hash_entry *ret = (struct archive_hash_entry *) entry; |
- | |
910 | - | ||
911 | /* Allocate the structure if it has not already been allocated by a |
- | |
912 | subclass. */ |
- | |
913 | if (ret == NULL) |
- | |
914 | ret = (struct archive_hash_entry *) |
- | |
915 | bfd_hash_allocate (table, sizeof (struct archive_hash_entry)); |
- | |
916 | if (ret == NULL) |
- | |
917 | return NULL; |
- | |
918 | - | ||
919 | /* Call the allocation method of the superclass. */ |
- | |
920 | ret = ((struct archive_hash_entry *) |
- | |
921 | bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); |
- | |
922 | - | ||
923 | if (ret) |
- | |
924 | { |
- | |
925 | /* Initialize the local fields. */ |
- | |
926 | ret->defs = NULL; |
- | |
927 | } |
- | |
928 | - | ||
929 | return &ret->root; |
- | |
930 | } |
- | |
931 | - | ||
932 | /* Initialize an archive hash table. */ |
- | |
933 | - | ||
934 | static bfd_boolean |
- | |
935 | archive_hash_table_init |
- | |
936 | (struct archive_hash_table *table, |
- | |
937 | struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, |
- | |
938 | struct bfd_hash_table *, |
- | |
939 | const char *), |
- | |
940 | unsigned int entsize) |
- | |
941 | { |
- | |
942 | return bfd_hash_table_init (&table->table, newfunc, entsize); |
- | |
943 | } |
- | |
944 | - | ||
945 | /* Look up an entry in an archive hash table. */ |
- | |
946 | - | ||
947 | #define archive_hash_lookup(t, string, create, copy) \ |
- | |
948 | ((struct archive_hash_entry *) \ |
- | |
949 | bfd_hash_lookup (&(t)->table, (string), (create), (copy))) |
- | |
950 | - | ||
951 | /* Allocate space in an archive hash table. */ |
- | |
952 | - | ||
953 | #define archive_hash_allocate(t, size) bfd_hash_allocate (&(t)->table, (size)) |
- | |
954 | - | ||
955 | /* Free an archive hash table. */ |
- | |
956 | - | ||
957 | #define archive_hash_table_free(t) bfd_hash_table_free (&(t)->table) |
- | |
958 | - | ||
959 | /* Generic function to add symbols from an archive file to the global |
911 | /* Generic function to add symbols from an archive file to the global |
960 | hash file. This function presumes that the archive symbol table |
912 | hash file. This function presumes that the archive symbol table |
961 | has already been read in (this is normally done by the |
913 | has already been read in (this is normally done by the |
962 | bfd_check_format entry point). It looks through the undefined and |
914 | bfd_check_format entry point). It looks through the archive symbol |
963 | common symbols and searches the archive symbol table for them. If |
915 | table for symbols that are undefined or common in the linker global |
964 | it finds an entry, it includes the associated object file in the |
- | |
965 | link. |
- | |
966 | - | ||
967 | The old linker looked through the archive symbol table for |
- | |
968 | undefined symbols. We do it the other way around, looking through |
916 | symbol hash table. When one is found, the CHECKFN argument is used |
969 | undefined symbols for symbols defined in the archive. The |
- | |
970 | advantage of the newer scheme is that we only have to look through |
917 | to see if an object file should be included. This allows targets |
971 | the list of undefined symbols once, whereas the old method had to |
918 | to customize common symbol behaviour. CHECKFN should set *PNEEDED |
972 | re-search the symbol table each time a new object file was added. |
- | |
973 | - | ||
974 | The CHECKFN argument is used to see if an object file should be |
- | |
975 | included. CHECKFN should set *PNEEDED to TRUE if the object file |
- | |
976 | should be included, and must also call the bfd_link_info |
919 | to TRUE if the object file should be included, and must also call |
977 | add_archive_element callback function and handle adding the symbols |
920 | the bfd_link_info add_archive_element callback function and handle |
978 | to the global hash table. CHECKFN must notice if the callback |
921 | adding the symbols to the global hash table. CHECKFN must notice |
979 | indicates a substitute BFD, and arrange to add those symbols instead |
922 | if the callback indicates a substitute BFD, and arrange to add |
980 | if it does so. CHECKFN should only return FALSE if some sort of |
923 | those symbols instead if it does so. CHECKFN should only return |
981 | error occurs. |
- | |
982 | - | ||
983 | For some formats, such as a.out, it is possible to look through an |
- | |
984 | object file but not actually include it in the link. The |
- | |
985 | archive_pass field in a BFD is used to avoid checking the symbols |
- | |
986 | of an object files too many times. When an object is included in |
- | |
987 | the link, archive_pass is set to -1. If an object is scanned but |
- | |
988 | not included, archive_pass is set to the pass number. The pass |
- | |
989 | number is incremented each time a new object file is included. The |
- | |
990 | pass number is used because when a new object file is included it |
- | |
991 | may create new undefined symbols which cause a previously examined |
- | |
992 | object file to be included. */ |
924 | FALSE if some sort of error occurs. */ |
993 | 925 | ||
994 | bfd_boolean |
926 | bfd_boolean |
995 | _bfd_generic_link_add_archive_symbols |
927 | _bfd_generic_link_add_archive_symbols |
996 | (bfd *abfd, |
928 | (bfd *abfd, |
997 | struct bfd_link_info *info, |
929 | struct bfd_link_info *info, |
998 | bfd_boolean (*checkfn) (bfd *, struct bfd_link_info *, bfd_boolean *)) |
930 | bfd_boolean (*checkfn) (bfd *, struct bfd_link_info *, |
- | 931 | struct bfd_link_hash_entry *, const char *, |
|
- | 932 | bfd_boolean *)) |
|
999 | { |
933 | { |
1000 | carsym *arsyms; |
934 | bfd_boolean loop; |
1001 | carsym *arsym_end; |
- | |
1002 | register carsym *arsym; |
- | |
1003 | int pass; |
935 | bfd_size_type amt; |
1004 | struct archive_hash_table arsym_hash; |
- | |
1005 | unsigned int indx; |
936 | unsigned char *included; |
1006 | struct bfd_link_hash_entry **pundef; |
- | |
1007 | 937 | ||
1008 | if (! bfd_has_map (abfd)) |
938 | if (! bfd_has_map (abfd)) |
1009 | { |
939 | { |
1010 | /* An empty archive is a special case. */ |
940 | /* An empty archive is a special case. */ |
1011 | if (bfd_openr_next_archived_file (abfd, NULL) == NULL) |
941 | if (bfd_openr_next_archived_file (abfd, NULL) == NULL) |
1012 | return TRUE; |
942 | return TRUE; |
1013 | bfd_set_error (bfd_error_no_armap); |
943 | bfd_set_error (bfd_error_no_armap); |
1014 | return FALSE; |
944 | return FALSE; |
1015 | } |
945 | } |
1016 | 946 | ||
1017 | arsyms = bfd_ardata (abfd)->symdefs; |
947 | amt = bfd_ardata (abfd)->symdef_count; |
1018 | arsym_end = arsyms + bfd_ardata (abfd)->symdef_count; |
- | |
1019 | 948 | if (amt == 0) |
|
1020 | /* In order to quickly determine whether an symbol is defined in |
949 | return TRUE; |
1021 | this archive, we build a hash table of the symbols. */ |
950 | amt *= sizeof (*included); |
1022 | if (! archive_hash_table_init (&arsym_hash, archive_hash_newfunc, |
951 | included = (unsigned char *) bfd_zmalloc (amt); |
1023 | sizeof (struct archive_hash_entry))) |
952 | if (included == NULL) |
1024 | return FALSE; |
- | |
- | 953 | return FALSE; |
|
- | 954 | ||
1025 | for (arsym = arsyms, indx = 0; arsym < arsym_end; arsym++, indx++) |
955 | do |
- | 956 | { |
|
- | 957 | carsym *arsyms; |
|
- | 958 | carsym *arsym_end; |
|
- | 959 | carsym *arsym; |
|
1026 | { |
960 | unsigned int indx; |
- | 961 | file_ptr last_ar_offset = -1; |
|
1027 | struct archive_hash_entry *arh; |
962 | bfd_boolean needed = FALSE; |
1028 | struct archive_list *l, **pp; |
- | |
1029 | - | ||
1030 | arh = archive_hash_lookup (&arsym_hash, arsym->name, TRUE, FALSE); |
- | |
1031 | if (arh == NULL) |
- | |
1032 | goto error_return; |
- | |
1033 | l = ((struct archive_list *) |
- | |
1034 | archive_hash_allocate (&arsym_hash, sizeof (struct archive_list))); |
- | |
1035 | if (l == NULL) |
- | |
1036 | goto error_return; |
- | |
1037 | l->indx = indx; |
- | |
1038 | for (pp = &arh->defs; *pp != NULL; pp = &(*pp)->next) |
963 | bfd *element = NULL; |
1039 | ; |
- | |
1040 | *pp = l; |
- | |
1041 | l->next = NULL; |
- | |
1042 | } |
- | |
1043 | - | ||
1044 | /* The archive_pass field in the archive itself is used to |
- | |
1045 | initialize PASS, sine we may search the same archive multiple |
964 | |
1046 | times. */ |
- | |
1047 | pass = abfd->archive_pass + 1; |
965 | loop = FALSE; |
1048 | 966 | arsyms = bfd_ardata (abfd)->symdefs; |
|
1049 | /* New undefined symbols are added to the end of the list, so we |
- | |
1050 | only need to look through it once. */ |
- | |
1051 | pundef = &info->hash->undefs; |
967 | arsym_end = arsyms + bfd_ardata (abfd)->symdef_count; |
1052 | while (*pundef != NULL) |
968 | for (arsym = arsyms, indx = 0; arsym < arsym_end; arsym++, indx++) |
1053 | { |
969 | { |
1054 | struct bfd_link_hash_entry *h; |
- | |
1055 | struct archive_hash_entry *arh; |
970 | struct bfd_link_hash_entry *h; |
1056 | struct archive_list *l; |
- | |
1057 | - | ||
1058 | h = *pundef; |
971 | struct bfd_link_hash_entry *undefs_tail; |
1059 | 972 | ||
1060 | /* When a symbol is defined, it is not necessarily removed from |
- | |
1061 | the list. */ |
973 | if (included[indx]) |
1062 | if (h->type != bfd_link_hash_undefined |
- | |
1063 | && h->type != bfd_link_hash_common) |
- | |
1064 | { |
- | |
1065 | /* Remove this entry from the list, for general cleanliness |
- | |
1066 | and because we are going to look through the list again |
- | |
1067 | if we search any more libraries. We can't remove the |
- | |
1068 | entry if it is the tail, because that would lose any |
974 | continue; |
1069 | entries we add to the list later on (it would also cause |
- | |
1070 | us to lose track of whether the symbol has been |
- | |
1071 | referenced). */ |
- | |
1072 | if (*pundef != info->hash->undefs_tail) |
- | |
1073 | *pundef = (*pundef)->u.undef.next; |
975 | if (needed && arsym->file_offset == last_ar_offset) |
1074 | else |
976 | { |
1075 | pundef = &(*pundef)->u.undef.next; |
977 | included[indx] = 1; |
1076 | continue; |
978 | continue; |
1077 | } |
979 | } |
1078 | - | ||
1079 | /* Look for this symbol in the archive symbol map. */ |
980 | |
1080 | arh = archive_hash_lookup (&arsym_hash, h->root.string, FALSE, FALSE); |
- | |
1081 | if (arh == NULL) |
- | |
1082 | { |
- | |
1083 | /* If we haven't found the exact symbol we're looking for, |
- | |
1084 | let's look for its import thunk */ |
- | |
1085 | if (info->pei386_auto_import) |
- | |
1086 | { |
- | |
1087 | bfd_size_type amt = strlen (h->root.string) + 10; |
- | |
1088 | char *buf = (char *) bfd_malloc (amt); |
981 | h = bfd_link_hash_lookup (info->hash, arsym->name, |
1089 | if (buf == NULL) |
- | |
- | 982 | FALSE, FALSE, TRUE); |
|
- | 983 | ||
1090 | return FALSE; |
984 | if (h == NULL |
1091 | 985 | && info->pei386_auto_import |
|
1092 | sprintf (buf, "__imp_%s", h->root.string); |
986 | && CONST_STRNEQ (arsym->name, "__imp_")) |
1093 | arh = archive_hash_lookup (&arsym_hash, buf, FALSE, FALSE); |
- | |
1094 | free(buf); |
987 | h = bfd_link_hash_lookup (info->hash, arsym->name + 6, |
1095 | } |
- | |
1096 | if (arh == NULL) |
- | |
1097 | { |
988 | FALSE, FALSE, TRUE); |
1098 | pundef = &(*pundef)->u.undef.next; |
- | |
1099 | continue; |
- | |
1100 | } |
- | |
1101 | } |
- | |
1102 | /* Look at all the objects which define this symbol. */ |
- | |
1103 | for (l = arh->defs; l != NULL; l = l->next) |
- | |
1104 | { |
- | |
1105 | bfd *element; |
- | |
1106 | bfd_boolean needed; |
989 | if (h == NULL) |
1107 | 990 | continue; |
|
1108 | /* If the symbol has gotten defined along the way, quit. */ |
991 | |
1109 | if (h->type != bfd_link_hash_undefined |
- | |
1110 | && h->type != bfd_link_hash_common) |
992 | if (h->type != bfd_link_hash_undefined |
1111 | break; |
- | |
1112 | - | ||
1113 | element = bfd_get_elt_at_index (abfd, l->indx); |
- | |
1114 | if (element == NULL) |
- | |
1115 | goto error_return; |
993 | && h->type != bfd_link_hash_common) |
1116 | 994 | { |
|
1117 | /* If we've already included this element, or if we've |
- | |
1118 | already checked it on this pass, continue. */ |
995 | if (h->type != bfd_link_hash_undefweak) |
- | 996 | /* Symbol must be defined. Don't check it again. */ |
|
1119 | if (element->archive_pass == -1 |
- | |
1120 | || element->archive_pass == pass) |
997 | included[indx] = 1; |
1121 | continue; |
998 | continue; |
- | 999 | } |
|
- | 1000 | ||
1122 | 1001 | if (last_ar_offset != arsym->file_offset) |
|
- | 1002 | { |
|
1123 | /* If we can't figure this element out, just ignore it. */ |
1003 | last_ar_offset = arsym->file_offset; |
1124 | if (! bfd_check_format (element, bfd_object)) |
1004 | element = _bfd_get_elt_at_filepos (abfd, last_ar_offset); |
- | 1005 | if (element == NULL |
|
- | 1006 | || !bfd_check_format (element, bfd_object)) |
|
1125 | { |
1007 | goto error_return; |
1126 | element->archive_pass = -1; |
1008 | } |
1127 | continue; |
1009 | |
1128 | } |
1010 | undefs_tail = info->hash->undefs_tail; |
1129 | 1011 | ||
1130 | /* CHECKFN will see if this element should be included, and |
- | |
1131 | go ahead and include it if appropriate. */ |
- | |
1132 | if (! (*checkfn) (element, info, &needed)) |
1012 | /* CHECKFN will see if this element should be included, and |
1133 | goto error_return; |
1013 | go ahead and include it if appropriate. */ |
1134 | 1014 | if (! (*checkfn) (element, info, h, arsym->name, &needed)) |
|
1135 | if (! needed) |
1015 | goto error_return; |
- | 1016 | ||
- | 1017 | if (needed) |
|
- | 1018 | { |
|
- | 1019 | unsigned int mark; |
|
- | 1020 | ||
1136 | element->archive_pass = pass; |
1021 | /* Look backward to mark all symbols from this object file |
- | 1022 | which we have already seen in this pass. */ |
|
1137 | else |
1023 | mark = indx; |
1138 | { |
- | |
- | 1024 | do |
|
1139 | element->archive_pass = -1; |
1025 | { |
- | 1026 | included[mark] = 1; |
|
- | 1027 | if (mark == 0) |
|
1140 | 1028 | break; |
|
- | 1029 | --mark; |
|
1141 | /* Increment the pass count to show that we may need to |
- | |
1142 | recheck object files which were already checked. */ |
- | |
1143 | ++pass; |
- | |
1144 | } |
1030 | } |
1145 | } |
- | |
1146 | 1031 | while (arsyms[mark].file_offset == last_ar_offset); |
|
1147 | pundef = &(*pundef)->u.undef.next; |
1032 | |
1148 | } |
1033 | if (undefs_tail != info->hash->undefs_tail) |
1149 | 1034 | loop = TRUE; |
|
1150 | archive_hash_table_free (&arsym_hash); |
1035 | } |
1151 | 1036 | } |
|
1152 | /* Save PASS in case we are called again. */ |
1037 | } while (loop); |
1153 | abfd->archive_pass = pass; |
1038 | |
1154 | 1039 | free (included); |
|
1155 | return TRUE; |
1040 | return TRUE; |
1156 | 1041 | ||
1157 | error_return: |
1042 | error_return: |
1158 | archive_hash_table_free (&arsym_hash); |
1043 | free (included); |
1159 | return FALSE; |
1044 | return FALSE; |
1160 | } |
1045 | } |
1161 | 1046 | ||
1162 | /* See if we should include an archive element. This version is used |
1047 | /* See if we should include an archive element. This version is used |
1163 | when we do not want to automatically collect constructors based on |
1048 | when we do not want to automatically collect constructors based on |
1164 | the symbol name, presumably because we have some other mechanism |
1049 | the symbol name, presumably because we have some other mechanism |
1165 | for finding them. */ |
1050 | for finding them. */ |
1166 | 1051 | ||
1167 | static bfd_boolean |
1052 | static bfd_boolean |
1168 | generic_link_check_archive_element_no_collect ( |
1053 | generic_link_check_archive_element_no_collect (bfd *abfd, |
1169 | bfd *abfd, |
- | |
1170 | struct bfd_link_info *info, |
1054 | struct bfd_link_info *info, |
- | 1055 | struct bfd_link_hash_entry *h, |
|
- | 1056 | const char *name, |
|
1171 | bfd_boolean *pneeded) |
1057 | bfd_boolean *pneeded) |
1172 | { |
1058 | { |
1173 | return generic_link_check_archive_element (abfd, info, pneeded, FALSE); |
1059 | return generic_link_check_archive_element (abfd, info, h, name, pneeded, |
- | 1060 | FALSE); |
|
1174 | } |
1061 | } |
1175 | 1062 | ||
1176 | /* See if we should include an archive element. This version is used |
1063 | /* See if we should include an archive element. This version is used |
1177 | when we want to automatically collect constructors based on the |
1064 | when we want to automatically collect constructors based on the |
1178 | symbol name, as collect2 does. */ |
1065 | symbol name, as collect2 does. */ |
1179 | 1066 | ||
1180 | static bfd_boolean |
1067 | static bfd_boolean |
1181 | generic_link_check_archive_element_collect (bfd *abfd, |
1068 | generic_link_check_archive_element_collect (bfd *abfd, |
1182 | struct bfd_link_info *info, |
1069 | struct bfd_link_info *info, |
- | 1070 | struct bfd_link_hash_entry *h, |
|
- | 1071 | const char *name, |
|
1183 | bfd_boolean *pneeded) |
1072 | bfd_boolean *pneeded) |
1184 | { |
1073 | { |
1185 | return generic_link_check_archive_element (abfd, info, pneeded, TRUE); |
1074 | return generic_link_check_archive_element (abfd, info, h, name, pneeded, |
- | 1075 | TRUE); |
|
1186 | } |
1076 | } |
1187 | 1077 | ||
1188 | /* See if we should include an archive element. Optionally collect |
1078 | /* See if we should include an archive element. Optionally collect |
1189 | constructors. */ |
1079 | constructors. */ |
1190 | 1080 | ||
1191 | static bfd_boolean |
1081 | static bfd_boolean |
1192 | generic_link_check_archive_element (bfd *abfd, |
1082 | generic_link_check_archive_element (bfd *abfd, |
1193 | struct bfd_link_info *info, |
1083 | struct bfd_link_info *info, |
- | 1084 | struct bfd_link_hash_entry *h, |
|
- | 1085 | const char *name ATTRIBUTE_UNUSED, |
|
1194 | bfd_boolean *pneeded, |
1086 | bfd_boolean *pneeded, |
1195 | bfd_boolean collect) |
1087 | bfd_boolean collect) |
1196 | { |
1088 | { |
1197 | asymbol **pp, **ppend; |
1089 | asymbol **pp, **ppend; |
1198 | 1090 | ||
1199 | *pneeded = FALSE; |
1091 | *pneeded = FALSE; |
1200 | 1092 | ||
1201 | if (!bfd_generic_link_read_symbols (abfd)) |
1093 | if (!bfd_generic_link_read_symbols (abfd)) |
1202 | return FALSE; |
1094 | return FALSE; |
1203 | 1095 | ||
1204 | pp = _bfd_generic_link_get_symbols (abfd); |
1096 | pp = _bfd_generic_link_get_symbols (abfd); |
1205 | ppend = pp + _bfd_generic_link_get_symcount (abfd); |
1097 | ppend = pp + _bfd_generic_link_get_symcount (abfd); |
1206 | for (; pp < ppend; pp++) |
1098 | for (; pp < ppend; pp++) |
1207 | { |
1099 | { |
1208 | asymbol *p; |
1100 | asymbol *p; |
1209 | struct bfd_link_hash_entry *h; |
- | |
1210 | 1101 | ||
1211 | p = *pp; |
1102 | p = *pp; |
1212 | 1103 | ||
1213 | /* We are only interested in globally visible symbols. */ |
1104 | /* We are only interested in globally visible symbols. */ |
1214 | if (! bfd_is_com_section (p->section) |
1105 | if (! bfd_is_com_section (p->section) |
1215 | && (p->flags & (BSF_GLOBAL | BSF_INDIRECT | BSF_WEAK)) == 0) |
1106 | && (p->flags & (BSF_GLOBAL | BSF_INDIRECT | BSF_WEAK)) == 0) |
1216 | continue; |
1107 | continue; |
1217 | 1108 | ||
1218 | /* We are only interested if we know something about this |
1109 | /* We are only interested if we know something about this |
1219 | symbol, and it is undefined or common. An undefined weak |
1110 | symbol, and it is undefined or common. An undefined weak |
1220 | symbol (type bfd_link_hash_undefweak) is not considered to be |
1111 | symbol (type bfd_link_hash_undefweak) is not considered to be |
1221 | a reference when pulling files out of an archive. See the |
1112 | a reference when pulling files out of an archive. See the |
1222 | SVR4 ABI, p. 4-27. */ |
1113 | SVR4 ABI, p. 4-27. */ |
1223 | h = bfd_link_hash_lookup (info->hash, bfd_asymbol_name (p), FALSE, |
1114 | h = bfd_link_hash_lookup (info->hash, bfd_asymbol_name (p), FALSE, |
1224 | FALSE, TRUE); |
1115 | FALSE, TRUE); |
1225 | if (h == NULL |
1116 | if (h == NULL |
1226 | || (h->type != bfd_link_hash_undefined |
1117 | || (h->type != bfd_link_hash_undefined |
1227 | && h->type != bfd_link_hash_common)) |
1118 | && h->type != bfd_link_hash_common)) |
1228 | continue; |
1119 | continue; |
1229 | 1120 | ||
1230 | /* P is a symbol we are looking for. */ |
1121 | /* P is a symbol we are looking for. */ |
1231 | 1122 | ||
- | 1123 | if (! bfd_is_com_section (p->section) |
|
- | 1124 | || (h->type == bfd_link_hash_undefined |
|
1232 | if (! bfd_is_com_section (p->section)) |
1125 | && h->u.undef.abfd == NULL)) |
1233 | { |
1126 | { |
1234 | bfd_size_type symcount; |
- | |
1235 | asymbol **symbols; |
1127 | /* P is not a common symbol, or an undefined reference was |
1236 | bfd *oldbfd = abfd; |
- | |
1237 | 1128 | created from outside BFD such as from a linker -u option. |
|
- | 1129 | This object file defines the symbol, so pull it in. */ |
|
1238 | /* This object file defines this symbol, so pull it in. */ |
1130 | *pneeded = TRUE; |
1239 | if (!(*info->callbacks |
1131 | if (!(*info->callbacks |
1240 | ->add_archive_element) (info, abfd, bfd_asymbol_name (p), |
1132 | ->add_archive_element) (info, abfd, bfd_asymbol_name (p), |
1241 | &abfd)) |
1133 | &abfd)) |
1242 | return FALSE; |
1134 | return FALSE; |
1243 | /* Potentially, the add_archive_element hook may have set a |
1135 | /* Potentially, the add_archive_element hook may have set a |
1244 | substitute BFD for us. */ |
1136 | substitute BFD for us. */ |
1245 | if (abfd != oldbfd |
- | |
1246 | && !bfd_generic_link_read_symbols (abfd)) |
- | |
1247 | return FALSE; |
- | |
1248 | symcount = _bfd_generic_link_get_symcount (abfd); |
- | |
1249 | symbols = _bfd_generic_link_get_symbols (abfd); |
- | |
1250 | if (! generic_link_add_symbol_list (abfd, info, symcount, |
1137 | return generic_link_add_object_symbols (abfd, info, collect); |
1251 | symbols, collect)) |
- | |
1252 | return FALSE; |
- | |
1253 | *pneeded = TRUE; |
- | |
1254 | return TRUE; |
- | |
1255 | } |
1138 | } |
1256 | 1139 | ||
1257 | /* P is a common symbol. */ |
1140 | /* P is a common symbol. */ |
1258 | 1141 | ||
1259 | if (h->type == bfd_link_hash_undefined) |
1142 | if (h->type == bfd_link_hash_undefined) |
1260 | { |
1143 | { |
1261 | bfd *symbfd; |
1144 | bfd *symbfd; |
1262 | bfd_vma size; |
1145 | bfd_vma size; |
1263 | unsigned int power; |
1146 | unsigned int power; |
1264 | - | ||
1265 | symbfd = h->u.undef.abfd; |
- | |
1266 | if (symbfd == NULL) |
- | |
1267 | { |
- | |
1268 | /* This symbol was created as undefined from outside |
- | |
1269 | BFD. We assume that we should link in the object |
- | |
1270 | file. This is for the -u option in the linker. */ |
- | |
1271 | if (!(*info->callbacks |
- | |
1272 | ->add_archive_element) (info, abfd, bfd_asymbol_name (p), |
- | |
1273 | &abfd)) |
- | |
1274 | return FALSE; |
- | |
1275 | /* Potentially, the add_archive_element hook may have set a |
- | |
1276 | substitute BFD for us. But no symbols are going to get |
- | |
1277 | registered by anything we're returning to from here. */ |
- | |
1278 | *pneeded = TRUE; |
- | |
1279 | return TRUE; |
- | |
1280 | } |
- | |
1281 | 1147 | ||
1282 | /* Turn the symbol into a common symbol but do not link in |
1148 | /* Turn the symbol into a common symbol but do not link in |
1283 | the object file. This is how a.out works. Object |
1149 | the object file. This is how a.out works. Object |
1284 | formats that require different semantics must implement |
1150 | formats that require different semantics must implement |
1285 | this function differently. This symbol is already on the |
1151 | this function differently. This symbol is already on the |
1286 | undefs list. We add the section to a common section |
1152 | undefs list. We add the section to a common section |
1287 | attached to symbfd to ensure that it is in a BFD which |
1153 | attached to symbfd to ensure that it is in a BFD which |
1288 | will be linked in. */ |
1154 | will be linked in. */ |
- | 1155 | symbfd = h->u.undef.abfd; |
|
1289 | h->type = bfd_link_hash_common; |
1156 | h->type = bfd_link_hash_common; |
1290 | h->u.c.p = (struct bfd_link_hash_common_entry *) |
1157 | h->u.c.p = (struct bfd_link_hash_common_entry *) |
1291 | bfd_hash_allocate (&info->hash->table, |
1158 | bfd_hash_allocate (&info->hash->table, |
1292 | sizeof (struct bfd_link_hash_common_entry)); |
1159 | sizeof (struct bfd_link_hash_common_entry)); |
1293 | if (h->u.c.p == NULL) |
1160 | if (h->u.c.p == NULL) |
1294 | return FALSE; |
1161 | return FALSE; |
1295 | 1162 | ||
1296 | size = bfd_asymbol_value (p); |
1163 | size = bfd_asymbol_value (p); |
1297 | h->u.c.size = size; |
1164 | h->u.c.size = size; |
1298 | 1165 | ||
1299 | power = bfd_log2 (size); |
1166 | power = bfd_log2 (size); |
1300 | if (power > 4) |
1167 | if (power > 4) |
1301 | power = 4; |
1168 | power = 4; |
1302 | h->u.c.p->alignment_power = power; |
1169 | h->u.c.p->alignment_power = power; |
1303 | 1170 | ||
1304 | if (p->section == bfd_com_section_ptr) |
1171 | if (p->section == bfd_com_section_ptr) |
1305 | h->u.c.p->section = bfd_make_section_old_way (symbfd, "COMMON"); |
1172 | h->u.c.p->section = bfd_make_section_old_way (symbfd, "COMMON"); |
1306 | else |
1173 | else |
1307 | h->u.c.p->section = bfd_make_section_old_way (symbfd, |
1174 | h->u.c.p->section = bfd_make_section_old_way (symbfd, |
1308 | p->section->name); |
1175 | p->section->name); |
1309 | h->u.c.p->section->flags |= SEC_ALLOC; |
1176 | h->u.c.p->section->flags |= SEC_ALLOC; |
1310 | } |
1177 | } |
1311 | else |
1178 | else |
1312 | { |
1179 | { |
1313 | /* Adjust the size of the common symbol if necessary. This |
1180 | /* Adjust the size of the common symbol if necessary. This |
1314 | is how a.out works. Object formats that require |
1181 | is how a.out works. Object formats that require |
1315 | different semantics must implement this function |
1182 | different semantics must implement this function |
1316 | differently. */ |
1183 | differently. */ |
1317 | if (bfd_asymbol_value (p) > h->u.c.size) |
1184 | if (bfd_asymbol_value (p) > h->u.c.size) |
1318 | h->u.c.size = bfd_asymbol_value (p); |
1185 | h->u.c.size = bfd_asymbol_value (p); |
1319 | } |
1186 | } |
1320 | } |
1187 | } |
1321 | 1188 | ||
1322 | /* This archive element is not needed. */ |
1189 | /* This archive element is not needed. */ |
1323 | return TRUE; |
1190 | return TRUE; |
1324 | } |
1191 | } |
1325 | 1192 | ||
1326 | /* Add the symbols from an object file to the global hash table. ABFD |
1193 | /* Add the symbols from an object file to the global hash table. ABFD |
1327 | is the object file. INFO is the linker information. SYMBOL_COUNT |
1194 | is the object file. INFO is the linker information. SYMBOL_COUNT |
1328 | is the number of symbols. SYMBOLS is the list of symbols. COLLECT |
1195 | is the number of symbols. SYMBOLS is the list of symbols. COLLECT |
1329 | is TRUE if constructors should be automatically collected by name |
1196 | is TRUE if constructors should be automatically collected by name |
1330 | as is done by collect2. */ |
1197 | as is done by collect2. */ |
1331 | 1198 | ||
1332 | static bfd_boolean |
1199 | static bfd_boolean |
1333 | generic_link_add_symbol_list (bfd *abfd, |
1200 | generic_link_add_symbol_list (bfd *abfd, |
1334 | struct bfd_link_info *info, |
1201 | struct bfd_link_info *info, |
1335 | bfd_size_type symbol_count, |
1202 | bfd_size_type symbol_count, |
1336 | asymbol **symbols, |
1203 | asymbol **symbols, |
1337 | bfd_boolean collect) |
1204 | bfd_boolean collect) |
1338 | { |
1205 | { |
1339 | asymbol **pp, **ppend; |
1206 | asymbol **pp, **ppend; |
1340 | 1207 | ||
1341 | pp = symbols; |
1208 | pp = symbols; |
1342 | ppend = symbols + symbol_count; |
1209 | ppend = symbols + symbol_count; |
1343 | for (; pp < ppend; pp++) |
1210 | for (; pp < ppend; pp++) |
1344 | { |
1211 | { |
1345 | asymbol *p; |
1212 | asymbol *p; |
1346 | 1213 | ||
1347 | p = *pp; |
1214 | p = *pp; |
1348 | 1215 | ||
1349 | if ((p->flags & (BSF_INDIRECT |
1216 | if ((p->flags & (BSF_INDIRECT |
1350 | | BSF_WARNING |
1217 | | BSF_WARNING |
1351 | | BSF_GLOBAL |
1218 | | BSF_GLOBAL |
1352 | | BSF_CONSTRUCTOR |
1219 | | BSF_CONSTRUCTOR |
1353 | | BSF_WEAK)) != 0 |
1220 | | BSF_WEAK)) != 0 |
1354 | || bfd_is_und_section (bfd_get_section (p)) |
1221 | || bfd_is_und_section (bfd_get_section (p)) |
1355 | || bfd_is_com_section (bfd_get_section (p)) |
1222 | || bfd_is_com_section (bfd_get_section (p)) |
1356 | || bfd_is_ind_section (bfd_get_section (p))) |
1223 | || bfd_is_ind_section (bfd_get_section (p))) |
1357 | { |
1224 | { |
1358 | const char *name; |
1225 | const char *name; |
1359 | const char *string; |
1226 | const char *string; |
1360 | struct generic_link_hash_entry *h; |
1227 | struct generic_link_hash_entry *h; |
1361 | struct bfd_link_hash_entry *bh; |
1228 | struct bfd_link_hash_entry *bh; |
1362 | 1229 | ||
1363 | string = name = bfd_asymbol_name (p); |
1230 | string = name = bfd_asymbol_name (p); |
1364 | if (((p->flags & BSF_INDIRECT) != 0 |
1231 | if (((p->flags & BSF_INDIRECT) != 0 |
1365 | || bfd_is_ind_section (p->section)) |
1232 | || bfd_is_ind_section (p->section)) |
1366 | && pp + 1 < ppend) |
1233 | && pp + 1 < ppend) |
1367 | { |
1234 | { |
1368 | pp++; |
1235 | pp++; |
1369 | string = bfd_asymbol_name (*pp); |
1236 | string = bfd_asymbol_name (*pp); |
1370 | } |
1237 | } |
1371 | else if ((p->flags & BSF_WARNING) != 0 |
1238 | else if ((p->flags & BSF_WARNING) != 0 |
1372 | && pp + 1 < ppend) |
1239 | && pp + 1 < ppend) |
1373 | { |
1240 | { |
1374 | /* The name of P is actually the warning string, and the |
1241 | /* The name of P is actually the warning string, and the |
1375 | next symbol is the one to warn about. */ |
1242 | next symbol is the one to warn about. */ |
1376 | pp++; |
1243 | pp++; |
1377 | name = bfd_asymbol_name (*pp); |
1244 | name = bfd_asymbol_name (*pp); |
1378 | } |
1245 | } |
1379 | 1246 | ||
1380 | bh = NULL; |
1247 | bh = NULL; |
1381 | if (! (_bfd_generic_link_add_one_symbol |
1248 | if (! (_bfd_generic_link_add_one_symbol |
1382 | (info, abfd, name, p->flags, bfd_get_section (p), |
1249 | (info, abfd, name, p->flags, bfd_get_section (p), |
1383 | p->value, string, FALSE, collect, &bh))) |
1250 | p->value, string, FALSE, collect, &bh))) |
1384 | return FALSE; |
1251 | return FALSE; |
1385 | h = (struct generic_link_hash_entry *) bh; |
1252 | h = (struct generic_link_hash_entry *) bh; |
1386 | 1253 | ||
1387 | /* If this is a constructor symbol, and the linker didn't do |
1254 | /* If this is a constructor symbol, and the linker didn't do |
1388 | anything with it, then we want to just pass the symbol |
1255 | anything with it, then we want to just pass the symbol |
1389 | through to the output file. This will happen when |
1256 | through to the output file. This will happen when |
1390 | linking with -r. */ |
1257 | linking with -r. */ |
1391 | if ((p->flags & BSF_CONSTRUCTOR) != 0 |
1258 | if ((p->flags & BSF_CONSTRUCTOR) != 0 |
1392 | && (h == NULL || h->root.type == bfd_link_hash_new)) |
1259 | && (h == NULL || h->root.type == bfd_link_hash_new)) |
1393 | { |
1260 | { |
1394 | p->udata.p = NULL; |
1261 | p->udata.p = NULL; |
1395 | continue; |
1262 | continue; |
1396 | } |
1263 | } |
1397 | 1264 | ||
1398 | /* Save the BFD symbol so that we don't lose any backend |
1265 | /* Save the BFD symbol so that we don't lose any backend |
1399 | specific information that may be attached to it. We only |
1266 | specific information that may be attached to it. We only |
1400 | want this one if it gives more information than the |
1267 | want this one if it gives more information than the |
1401 | existing one; we don't want to replace a defined symbol |
1268 | existing one; we don't want to replace a defined symbol |
1402 | with an undefined one. This routine may be called with a |
1269 | with an undefined one. This routine may be called with a |
1403 | hash table other than the generic hash table, so we only |
1270 | hash table other than the generic hash table, so we only |
1404 | do this if we are certain that the hash table is a |
1271 | do this if we are certain that the hash table is a |
1405 | generic one. */ |
1272 | generic one. */ |
1406 | if (info->output_bfd->xvec == abfd->xvec) |
1273 | if (info->output_bfd->xvec == abfd->xvec) |
1407 | { |
1274 | { |
1408 | if (h->sym == NULL |
1275 | if (h->sym == NULL |
1409 | || (! bfd_is_und_section (bfd_get_section (p)) |
1276 | || (! bfd_is_und_section (bfd_get_section (p)) |
1410 | && (! bfd_is_com_section (bfd_get_section (p)) |
1277 | && (! bfd_is_com_section (bfd_get_section (p)) |
1411 | || bfd_is_und_section (bfd_get_section (h->sym))))) |
1278 | || bfd_is_und_section (bfd_get_section (h->sym))))) |
1412 | { |
1279 | { |
1413 | h->sym = p; |
1280 | h->sym = p; |
1414 | /* BSF_OLD_COMMON is a hack to support COFF reloc |
1281 | /* BSF_OLD_COMMON is a hack to support COFF reloc |
1415 | reading, and it should go away when the COFF |
1282 | reading, and it should go away when the COFF |
1416 | linker is switched to the new version. */ |
1283 | linker is switched to the new version. */ |
1417 | if (bfd_is_com_section (bfd_get_section (p))) |
1284 | if (bfd_is_com_section (bfd_get_section (p))) |
1418 | p->flags |= BSF_OLD_COMMON; |
1285 | p->flags |= BSF_OLD_COMMON; |
1419 | } |
1286 | } |
1420 | } |
1287 | } |
1421 | 1288 | ||
1422 | /* Store a back pointer from the symbol to the hash |
1289 | /* Store a back pointer from the symbol to the hash |
1423 | table entry for the benefit of relaxation code until |
1290 | table entry for the benefit of relaxation code until |
1424 | it gets rewritten to not use asymbol structures. |
1291 | it gets rewritten to not use asymbol structures. |
1425 | Setting this is also used to check whether these |
1292 | Setting this is also used to check whether these |
1426 | symbols were set up by the generic linker. */ |
1293 | symbols were set up by the generic linker. */ |
1427 | p->udata.p = h; |
1294 | p->udata.p = h; |
1428 | } |
1295 | } |
1429 | } |
1296 | } |
1430 | 1297 | ||
1431 | return TRUE; |
1298 | return TRUE; |
1432 | } |
1299 | } |
1433 | 1300 | ||
1434 | /* We use a state table to deal with adding symbols from an object |
1301 | /* We use a state table to deal with adding symbols from an object |
1435 | file. The first index into the state table describes the symbol |
1302 | file. The first index into the state table describes the symbol |
1436 | from the object file. The second index into the state table is the |
1303 | from the object file. The second index into the state table is the |
1437 | type of the symbol in the hash table. */ |
1304 | type of the symbol in the hash table. */ |
1438 | 1305 | ||
1439 | /* The symbol from the object file is turned into one of these row |
1306 | /* The symbol from the object file is turned into one of these row |
1440 | values. */ |
1307 | values. */ |
1441 | 1308 | ||
1442 | enum link_row |
1309 | enum link_row |
1443 | { |
1310 | { |
1444 | UNDEF_ROW, /* Undefined. */ |
1311 | UNDEF_ROW, /* Undefined. */ |
1445 | UNDEFW_ROW, /* Weak undefined. */ |
1312 | UNDEFW_ROW, /* Weak undefined. */ |
1446 | DEF_ROW, /* Defined. */ |
1313 | DEF_ROW, /* Defined. */ |
1447 | DEFW_ROW, /* Weak defined. */ |
1314 | DEFW_ROW, /* Weak defined. */ |
1448 | COMMON_ROW, /* Common. */ |
1315 | COMMON_ROW, /* Common. */ |
1449 | INDR_ROW, /* Indirect. */ |
1316 | INDR_ROW, /* Indirect. */ |
1450 | WARN_ROW, /* Warning. */ |
1317 | WARN_ROW, /* Warning. */ |
1451 | SET_ROW /* Member of set. */ |
1318 | SET_ROW /* Member of set. */ |
1452 | }; |
1319 | }; |
1453 | 1320 | ||
1454 | /* apparently needed for Hitachi 3050R(HI-UX/WE2)? */ |
1321 | /* apparently needed for Hitachi 3050R(HI-UX/WE2)? */ |
1455 | #undef FAIL |
1322 | #undef FAIL |
1456 | 1323 | ||
1457 | /* The actions to take in the state table. */ |
1324 | /* The actions to take in the state table. */ |
1458 | 1325 | ||
1459 | enum link_action |
1326 | enum link_action |
1460 | { |
1327 | { |
1461 | FAIL, /* Abort. */ |
1328 | FAIL, /* Abort. */ |
1462 | UND, /* Mark symbol undefined. */ |
1329 | UND, /* Mark symbol undefined. */ |
1463 | WEAK, /* Mark symbol weak undefined. */ |
1330 | WEAK, /* Mark symbol weak undefined. */ |
1464 | DEF, /* Mark symbol defined. */ |
1331 | DEF, /* Mark symbol defined. */ |
1465 | DEFW, /* Mark symbol weak defined. */ |
1332 | DEFW, /* Mark symbol weak defined. */ |
1466 | COM, /* Mark symbol common. */ |
1333 | COM, /* Mark symbol common. */ |
1467 | REF, /* Mark defined symbol referenced. */ |
1334 | REF, /* Mark defined symbol referenced. */ |
1468 | CREF, /* Possibly warn about common reference to defined symbol. */ |
1335 | CREF, /* Possibly warn about common reference to defined symbol. */ |
1469 | CDEF, /* Define existing common symbol. */ |
1336 | CDEF, /* Define existing common symbol. */ |
1470 | NOACT, /* No action. */ |
1337 | NOACT, /* No action. */ |
1471 | BIG, /* Mark symbol common using largest size. */ |
1338 | BIG, /* Mark symbol common using largest size. */ |
1472 | MDEF, /* Multiple definition error. */ |
1339 | MDEF, /* Multiple definition error. */ |
1473 | MIND, /* Multiple indirect symbols. */ |
1340 | MIND, /* Multiple indirect symbols. */ |
1474 | IND, /* Make indirect symbol. */ |
1341 | IND, /* Make indirect symbol. */ |
1475 | CIND, /* Make indirect symbol from existing common symbol. */ |
1342 | CIND, /* Make indirect symbol from existing common symbol. */ |
1476 | SET, /* Add value to set. */ |
1343 | SET, /* Add value to set. */ |
1477 | MWARN, /* Make warning symbol. */ |
1344 | MWARN, /* Make warning symbol. */ |
1478 | WARN, /* Issue warning. */ |
- | |
1479 | CWARN, /* Warn if referenced, else MWARN. */ |
1345 | WARN, /* Warn if referenced, else MWARN. */ |
1480 | CYCLE, /* Repeat with symbol pointed to. */ |
1346 | CYCLE, /* Repeat with symbol pointed to. */ |
1481 | REFC, /* Mark indirect symbol referenced and then CYCLE. */ |
1347 | REFC, /* Mark indirect symbol referenced and then CYCLE. */ |
1482 | WARNC /* Issue warning and then CYCLE. */ |
1348 | WARNC /* Issue warning and then CYCLE. */ |
1483 | }; |
1349 | }; |
1484 | 1350 | ||
1485 | /* The state table itself. The first index is a link_row and the |
1351 | /* The state table itself. The first index is a link_row and the |
1486 | second index is a bfd_link_hash_type. */ |
1352 | second index is a bfd_link_hash_type. */ |
1487 | 1353 | ||
1488 | static const enum link_action link_action[8][8] = |
1354 | static const enum link_action link_action[8][8] = |
1489 | { |
1355 | { |
1490 | /* current\prev new undef undefw def defw com indr warn */ |
1356 | /* current\prev new undef undefw def defw com indr warn */ |
1491 | /* UNDEF_ROW */ {UND, NOACT, UND, REF, REF, NOACT, REFC, WARNC }, |
1357 | /* UNDEF_ROW */ {UND, NOACT, UND, REF, REF, NOACT, REFC, WARNC }, |
1492 | /* UNDEFW_ROW */ {WEAK, NOACT, NOACT, REF, REF, NOACT, REFC, WARNC }, |
1358 | /* UNDEFW_ROW */ {WEAK, NOACT, NOACT, REF, REF, NOACT, REFC, WARNC }, |
1493 | /* DEF_ROW */ {DEF, DEF, DEF, MDEF, DEF, CDEF, MDEF, CYCLE }, |
1359 | /* DEF_ROW */ {DEF, DEF, DEF, MDEF, DEF, CDEF, MDEF, CYCLE }, |
1494 | /* DEFW_ROW */ {DEFW, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT, CYCLE }, |
1360 | /* DEFW_ROW */ {DEFW, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT, CYCLE }, |
1495 | /* COMMON_ROW */ {COM, COM, COM, CREF, COM, BIG, REFC, WARNC }, |
1361 | /* COMMON_ROW */ {COM, COM, COM, CREF, COM, BIG, REFC, WARNC }, |
1496 | /* INDR_ROW */ {IND, IND, IND, MDEF, IND, CIND, MIND, CYCLE }, |
1362 | /* INDR_ROW */ {IND, IND, IND, MDEF, IND, CIND, MIND, CYCLE }, |
1497 | /* WARN_ROW */ {MWARN, WARN, WARN, CWARN, CWARN, WARN, CWARN, NOACT }, |
1363 | /* WARN_ROW */ {MWARN, WARN, WARN, WARN, WARN, WARN, WARN, NOACT }, |
1498 | /* SET_ROW */ {SET, SET, SET, SET, SET, SET, CYCLE, CYCLE } |
1364 | /* SET_ROW */ {SET, SET, SET, SET, SET, SET, CYCLE, CYCLE } |
1499 | }; |
1365 | }; |
1500 | 1366 | ||
1501 | /* Most of the entries in the LINK_ACTION table are straightforward, |
1367 | /* Most of the entries in the LINK_ACTION table are straightforward, |
1502 | but a few are somewhat subtle. |
1368 | but a few are somewhat subtle. |
1503 | 1369 | ||
1504 | A reference to an indirect symbol (UNDEF_ROW/indr or |
1370 | A reference to an indirect symbol (UNDEF_ROW/indr or |
1505 | UNDEFW_ROW/indr) is counted as a reference both to the indirect |
1371 | UNDEFW_ROW/indr) is counted as a reference both to the indirect |
1506 | symbol and to the symbol the indirect symbol points to. |
1372 | symbol and to the symbol the indirect symbol points to. |
1507 | 1373 | ||
1508 | A reference to a warning symbol (UNDEF_ROW/warn or UNDEFW_ROW/warn) |
1374 | A reference to a warning symbol (UNDEF_ROW/warn or UNDEFW_ROW/warn) |
1509 | causes the warning to be issued. |
1375 | causes the warning to be issued. |
1510 | 1376 | ||
1511 | A common definition of an indirect symbol (COMMON_ROW/indr) is |
1377 | A common definition of an indirect symbol (COMMON_ROW/indr) is |
1512 | treated as a multiple definition error. Likewise for an indirect |
1378 | treated as a multiple definition error. Likewise for an indirect |
1513 | definition of a common symbol (INDR_ROW/com). |
1379 | definition of a common symbol (INDR_ROW/com). |
1514 | 1380 | ||
1515 | An indirect definition of a warning (INDR_ROW/warn) does not cause |
1381 | An indirect definition of a warning (INDR_ROW/warn) does not cause |
1516 | the warning to be issued. |
1382 | the warning to be issued. |
1517 | 1383 | ||
1518 | If a warning is created for an indirect symbol (WARN_ROW/indr) no |
1384 | If a warning is created for an indirect symbol (WARN_ROW/indr) no |
1519 | warning is created for the symbol the indirect symbol points to. |
1385 | warning is created for the symbol the indirect symbol points to. |
1520 | 1386 | ||
1521 | Adding an entry to a set does not count as a reference to a set, |
1387 | Adding an entry to a set does not count as a reference to a set, |
1522 | and no warning is issued (SET_ROW/warn). */ |
1388 | and no warning is issued (SET_ROW/warn). */ |
1523 | 1389 | ||
1524 | /* Return the BFD in which a hash entry has been defined, if known. */ |
1390 | /* Return the BFD in which a hash entry has been defined, if known. */ |
1525 | 1391 | ||
1526 | static bfd * |
1392 | static bfd * |
1527 | hash_entry_bfd (struct bfd_link_hash_entry *h) |
1393 | hash_entry_bfd (struct bfd_link_hash_entry *h) |
1528 | { |
1394 | { |
1529 | while (h->type == bfd_link_hash_warning) |
1395 | while (h->type == bfd_link_hash_warning) |
1530 | h = h->u.i.link; |
1396 | h = h->u.i.link; |
1531 | switch (h->type) |
1397 | switch (h->type) |
1532 | { |
1398 | { |
1533 | default: |
1399 | default: |
1534 | return NULL; |
1400 | return NULL; |
1535 | case bfd_link_hash_undefined: |
1401 | case bfd_link_hash_undefined: |
1536 | case bfd_link_hash_undefweak: |
1402 | case bfd_link_hash_undefweak: |
1537 | return h->u.undef.abfd; |
1403 | return h->u.undef.abfd; |
1538 | case bfd_link_hash_defined: |
1404 | case bfd_link_hash_defined: |
1539 | case bfd_link_hash_defweak: |
1405 | case bfd_link_hash_defweak: |
1540 | return h->u.def.section->owner; |
1406 | return h->u.def.section->owner; |
1541 | case bfd_link_hash_common: |
1407 | case bfd_link_hash_common: |
1542 | return h->u.c.p->section->owner; |
1408 | return h->u.c.p->section->owner; |
1543 | } |
1409 | } |
1544 | /*NOTREACHED*/ |
1410 | /*NOTREACHED*/ |
1545 | } |
1411 | } |
1546 | 1412 | ||
1547 | /* Add a symbol to the global hash table. |
1413 | /* Add a symbol to the global hash table. |
1548 | ABFD is the BFD the symbol comes from. |
1414 | ABFD is the BFD the symbol comes from. |
1549 | NAME is the name of the symbol. |
1415 | NAME is the name of the symbol. |
1550 | FLAGS is the BSF_* bits associated with the symbol. |
1416 | FLAGS is the BSF_* bits associated with the symbol. |
1551 | SECTION is the section in which the symbol is defined; this may be |
1417 | SECTION is the section in which the symbol is defined; this may be |
1552 | bfd_und_section_ptr or bfd_com_section_ptr. |
1418 | bfd_und_section_ptr or bfd_com_section_ptr. |
1553 | VALUE is the value of the symbol, relative to the section. |
1419 | VALUE is the value of the symbol, relative to the section. |
1554 | STRING is used for either an indirect symbol, in which case it is |
1420 | STRING is used for either an indirect symbol, in which case it is |
1555 | the name of the symbol to indirect to, or a warning symbol, in |
1421 | the name of the symbol to indirect to, or a warning symbol, in |
1556 | which case it is the warning string. |
1422 | which case it is the warning string. |
1557 | COPY is TRUE if NAME or STRING must be copied into locally |
1423 | COPY is TRUE if NAME or STRING must be copied into locally |
1558 | allocated memory if they need to be saved. |
1424 | allocated memory if they need to be saved. |
1559 | COLLECT is TRUE if we should automatically collect gcc constructor |
1425 | COLLECT is TRUE if we should automatically collect gcc constructor |
1560 | or destructor names as collect2 does. |
1426 | or destructor names as collect2 does. |
1561 | HASHP, if not NULL, is a place to store the created hash table |
1427 | HASHP, if not NULL, is a place to store the created hash table |
1562 | entry; if *HASHP is not NULL, the caller has already looked up |
1428 | entry; if *HASHP is not NULL, the caller has already looked up |
1563 | the hash table entry, and stored it in *HASHP. */ |
1429 | the hash table entry, and stored it in *HASHP. */ |
1564 | 1430 | ||
1565 | bfd_boolean |
1431 | bfd_boolean |
1566 | _bfd_generic_link_add_one_symbol (struct bfd_link_info *info, |
1432 | _bfd_generic_link_add_one_symbol (struct bfd_link_info *info, |
1567 | bfd *abfd, |
1433 | bfd *abfd, |
1568 | const char *name, |
1434 | const char *name, |
1569 | flagword flags, |
1435 | flagword flags, |
1570 | asection *section, |
1436 | asection *section, |
1571 | bfd_vma value, |
1437 | bfd_vma value, |
1572 | const char *string, |
1438 | const char *string, |
1573 | bfd_boolean copy, |
1439 | bfd_boolean copy, |
1574 | bfd_boolean collect, |
1440 | bfd_boolean collect, |
1575 | struct bfd_link_hash_entry **hashp) |
1441 | struct bfd_link_hash_entry **hashp) |
1576 | { |
1442 | { |
1577 | enum link_row row; |
1443 | enum link_row row; |
1578 | struct bfd_link_hash_entry *h; |
1444 | struct bfd_link_hash_entry *h; |
- | 1445 | struct bfd_link_hash_entry *inh = NULL; |
|
1579 | bfd_boolean cycle; |
1446 | bfd_boolean cycle; |
1580 | 1447 | ||
1581 | BFD_ASSERT (section != NULL); |
1448 | BFD_ASSERT (section != NULL); |
1582 | 1449 | ||
1583 | if (bfd_is_ind_section (section) |
1450 | if (bfd_is_ind_section (section) |
1584 | || (flags & BSF_INDIRECT) != 0) |
1451 | || (flags & BSF_INDIRECT) != 0) |
- | 1452 | { |
|
1585 | row = INDR_ROW; |
1453 | row = INDR_ROW; |
- | 1454 | /* Create the indirect symbol here. This is for the benefit of |
|
- | 1455 | the plugin "notice" function. |
|
- | 1456 | STRING is the name of the symbol we want to indirect to. */ |
|
- | 1457 | inh = bfd_wrapped_link_hash_lookup (abfd, info, string, TRUE, |
|
- | 1458 | copy, FALSE); |
|
- | 1459 | if (inh == NULL) |
|
- | 1460 | return FALSE; |
|
- | 1461 | } |
|
1586 | else if ((flags & BSF_WARNING) != 0) |
1462 | else if ((flags & BSF_WARNING) != 0) |
1587 | row = WARN_ROW; |
1463 | row = WARN_ROW; |
1588 | else if ((flags & BSF_CONSTRUCTOR) != 0) |
1464 | else if ((flags & BSF_CONSTRUCTOR) != 0) |
1589 | row = SET_ROW; |
1465 | row = SET_ROW; |
1590 | else if (bfd_is_und_section (section)) |
1466 | else if (bfd_is_und_section (section)) |
1591 | { |
1467 | { |
1592 | if ((flags & BSF_WEAK) != 0) |
1468 | if ((flags & BSF_WEAK) != 0) |
1593 | row = UNDEFW_ROW; |
1469 | row = UNDEFW_ROW; |
1594 | else |
1470 | else |
1595 | row = UNDEF_ROW; |
1471 | row = UNDEF_ROW; |
1596 | } |
1472 | } |
1597 | else if ((flags & BSF_WEAK) != 0) |
1473 | else if ((flags & BSF_WEAK) != 0) |
1598 | row = DEFW_ROW; |
1474 | row = DEFW_ROW; |
1599 | else if (bfd_is_com_section (section)) |
1475 | else if (bfd_is_com_section (section)) |
- | 1476 | { |
|
1600 | row = COMMON_ROW; |
1477 | row = COMMON_ROW; |
- | 1478 | if (strcmp (name, "__gnu_lto_slim") == 0) |
|
- | 1479 | (*_bfd_error_handler) |
|
- | 1480 | (_("%s: plugin needed to handle lto object"), |
|
- | 1481 | bfd_get_filename (abfd)); |
|
- | 1482 | } |
|
1601 | else |
1483 | else |
1602 | row = DEF_ROW; |
1484 | row = DEF_ROW; |
1603 | 1485 | ||
1604 | if (hashp != NULL && *hashp != NULL) |
1486 | if (hashp != NULL && *hashp != NULL) |
1605 | h = *hashp; |
1487 | h = *hashp; |
1606 | else |
1488 | else |
1607 | { |
1489 | { |
1608 | if (row == UNDEF_ROW || row == UNDEFW_ROW) |
1490 | if (row == UNDEF_ROW || row == UNDEFW_ROW) |
1609 | h = bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, copy, FALSE); |
1491 | h = bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, copy, FALSE); |
1610 | else |
1492 | else |
1611 | h = bfd_link_hash_lookup (info->hash, name, TRUE, copy, FALSE); |
1493 | h = bfd_link_hash_lookup (info->hash, name, TRUE, copy, FALSE); |
1612 | if (h == NULL) |
1494 | if (h == NULL) |
1613 | { |
1495 | { |
1614 | if (hashp != NULL) |
1496 | if (hashp != NULL) |
1615 | *hashp = NULL; |
1497 | *hashp = NULL; |
1616 | return FALSE; |
1498 | return FALSE; |
1617 | } |
1499 | } |
1618 | } |
1500 | } |
1619 | 1501 | ||
1620 | if (info->notice_all |
1502 | if (info->notice_all |
1621 | || (info->notice_hash != NULL |
1503 | || (info->notice_hash != NULL |
1622 | && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL)) |
1504 | && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL)) |
1623 | { |
1505 | { |
1624 | if (! (*info->callbacks->notice) (info, h, |
1506 | if (! (*info->callbacks->notice) (info, h, inh, |
1625 | abfd, section, value, flags, string)) |
1507 | abfd, section, value, flags)) |
1626 | return FALSE; |
1508 | return FALSE; |
1627 | } |
1509 | } |
1628 | 1510 | ||
1629 | if (hashp != NULL) |
1511 | if (hashp != NULL) |
1630 | *hashp = h; |
1512 | *hashp = h; |
1631 | 1513 | ||
1632 | do |
1514 | do |
1633 | { |
1515 | { |
1634 | enum link_action action; |
1516 | enum link_action action; |
1635 | 1517 | ||
1636 | cycle = FALSE; |
1518 | cycle = FALSE; |
1637 | action = link_action[(int) row][(int) h->type]; |
1519 | action = link_action[(int) row][(int) h->type]; |
1638 | switch (action) |
1520 | switch (action) |
1639 | { |
1521 | { |
1640 | case FAIL: |
1522 | case FAIL: |
1641 | abort (); |
1523 | abort (); |
1642 | 1524 | ||
1643 | case NOACT: |
1525 | case NOACT: |
1644 | /* Do nothing. */ |
1526 | /* Do nothing. */ |
1645 | break; |
1527 | break; |
1646 | 1528 | ||
1647 | case UND: |
1529 | case UND: |
1648 | /* Make a new undefined symbol. */ |
1530 | /* Make a new undefined symbol. */ |
1649 | h->type = bfd_link_hash_undefined; |
1531 | h->type = bfd_link_hash_undefined; |
1650 | h->u.undef.abfd = abfd; |
1532 | h->u.undef.abfd = abfd; |
1651 | bfd_link_add_undef (info->hash, h); |
1533 | bfd_link_add_undef (info->hash, h); |
1652 | break; |
1534 | break; |
1653 | 1535 | ||
1654 | case WEAK: |
1536 | case WEAK: |
1655 | /* Make a new weak undefined symbol. */ |
1537 | /* Make a new weak undefined symbol. */ |
1656 | h->type = bfd_link_hash_undefweak; |
1538 | h->type = bfd_link_hash_undefweak; |
1657 | h->u.undef.abfd = abfd; |
1539 | h->u.undef.abfd = abfd; |
1658 | break; |
1540 | break; |
1659 | 1541 | ||
1660 | case CDEF: |
1542 | case CDEF: |
1661 | /* We have found a definition for a symbol which was |
1543 | /* We have found a definition for a symbol which was |
1662 | previously common. */ |
1544 | previously common. */ |
1663 | BFD_ASSERT (h->type == bfd_link_hash_common); |
1545 | BFD_ASSERT (h->type == bfd_link_hash_common); |
1664 | if (! ((*info->callbacks->multiple_common) |
1546 | if (! ((*info->callbacks->multiple_common) |
1665 | (info, h, abfd, bfd_link_hash_defined, 0))) |
1547 | (info, h, abfd, bfd_link_hash_defined, 0))) |
1666 | return FALSE; |
1548 | return FALSE; |
1667 | /* Fall through. */ |
1549 | /* Fall through. */ |
1668 | case DEF: |
1550 | case DEF: |
1669 | case DEFW: |
1551 | case DEFW: |
1670 | { |
1552 | { |
1671 | enum bfd_link_hash_type oldtype; |
1553 | enum bfd_link_hash_type oldtype; |
1672 | 1554 | ||
1673 | /* Define a symbol. */ |
1555 | /* Define a symbol. */ |
1674 | oldtype = h->type; |
1556 | oldtype = h->type; |
1675 | if (action == DEFW) |
1557 | if (action == DEFW) |
1676 | h->type = bfd_link_hash_defweak; |
1558 | h->type = bfd_link_hash_defweak; |
1677 | else |
1559 | else |
1678 | h->type = bfd_link_hash_defined; |
1560 | h->type = bfd_link_hash_defined; |
1679 | h->u.def.section = section; |
1561 | h->u.def.section = section; |
1680 | h->u.def.value = value; |
1562 | h->u.def.value = value; |
- | 1563 | h->linker_def = 0; |
|
1681 | 1564 | ||
1682 | /* If we have been asked to, we act like collect2 and |
1565 | /* If we have been asked to, we act like collect2 and |
1683 | identify all functions that might be global |
1566 | identify all functions that might be global |
1684 | constructors and destructors and pass them up in a |
1567 | constructors and destructors and pass them up in a |
1685 | callback. We only do this for certain object file |
1568 | callback. We only do this for certain object file |
1686 | types, since many object file types can handle this |
1569 | types, since many object file types can handle this |
1687 | automatically. */ |
1570 | automatically. */ |
1688 | if (collect && name[0] == '_') |
1571 | if (collect && name[0] == '_') |
1689 | { |
1572 | { |
1690 | const char *s; |
1573 | const char *s; |
1691 | 1574 | ||
1692 | /* A constructor or destructor name starts like this: |
1575 | /* A constructor or destructor name starts like this: |
1693 | _+GLOBAL_[_.$][ID][_.$] where the first [_.$] and |
1576 | _+GLOBAL_[_.$][ID][_.$] where the first [_.$] and |
1694 | the second are the same character (we accept any |
1577 | the second are the same character (we accept any |
1695 | character there, in case a new object file format |
1578 | character there, in case a new object file format |
1696 | comes along with even worse naming restrictions). */ |
1579 | comes along with even worse naming restrictions). */ |
1697 | 1580 | ||
1698 | #define CONS_PREFIX "GLOBAL_" |
1581 | #define CONS_PREFIX "GLOBAL_" |
1699 | #define CONS_PREFIX_LEN (sizeof CONS_PREFIX - 1) |
1582 | #define CONS_PREFIX_LEN (sizeof CONS_PREFIX - 1) |
1700 | 1583 | ||
1701 | s = name + 1; |
1584 | s = name + 1; |
1702 | while (*s == '_') |
1585 | while (*s == '_') |
1703 | ++s; |
1586 | ++s; |
1704 | if (s[0] == 'G' && CONST_STRNEQ (s, CONS_PREFIX)) |
1587 | if (s[0] == 'G' && CONST_STRNEQ (s, CONS_PREFIX)) |
1705 | { |
1588 | { |
1706 | char c; |
1589 | char c; |
1707 | 1590 | ||
1708 | c = s[CONS_PREFIX_LEN + 1]; |
1591 | c = s[CONS_PREFIX_LEN + 1]; |
1709 | if ((c == 'I' || c == 'D') |
1592 | if ((c == 'I' || c == 'D') |
1710 | && s[CONS_PREFIX_LEN] == s[CONS_PREFIX_LEN + 2]) |
1593 | && s[CONS_PREFIX_LEN] == s[CONS_PREFIX_LEN + 2]) |
1711 | { |
1594 | { |
1712 | /* If this is a definition of a symbol which |
1595 | /* If this is a definition of a symbol which |
1713 | was previously weakly defined, we are in |
1596 | was previously weakly defined, we are in |
1714 | trouble. We have already added a |
1597 | trouble. We have already added a |
1715 | constructor entry for the weak defined |
1598 | constructor entry for the weak defined |
1716 | symbol, and now we are trying to add one |
1599 | symbol, and now we are trying to add one |
1717 | for the new symbol. Fortunately, this case |
1600 | for the new symbol. Fortunately, this case |
1718 | should never arise in practice. */ |
1601 | should never arise in practice. */ |
1719 | if (oldtype == bfd_link_hash_defweak) |
1602 | if (oldtype == bfd_link_hash_defweak) |
1720 | abort (); |
1603 | abort (); |
1721 | 1604 | ||
1722 | if (! ((*info->callbacks->constructor) |
1605 | if (! ((*info->callbacks->constructor) |
1723 | (info, c == 'I', |
1606 | (info, c == 'I', |
1724 | h->root.string, abfd, section, value))) |
1607 | h->root.string, abfd, section, value))) |
1725 | return FALSE; |
1608 | return FALSE; |
1726 | } |
1609 | } |
1727 | } |
1610 | } |
1728 | } |
1611 | } |
1729 | } |
1612 | } |
1730 | 1613 | ||
1731 | break; |
1614 | break; |
1732 | 1615 | ||
1733 | case COM: |
1616 | case COM: |
1734 | /* We have found a common definition for a symbol. */ |
1617 | /* We have found a common definition for a symbol. */ |
1735 | if (h->type == bfd_link_hash_new) |
1618 | if (h->type == bfd_link_hash_new) |
1736 | bfd_link_add_undef (info->hash, h); |
1619 | bfd_link_add_undef (info->hash, h); |
1737 | h->type = bfd_link_hash_common; |
1620 | h->type = bfd_link_hash_common; |
1738 | h->u.c.p = (struct bfd_link_hash_common_entry *) |
1621 | h->u.c.p = (struct bfd_link_hash_common_entry *) |
1739 | bfd_hash_allocate (&info->hash->table, |
1622 | bfd_hash_allocate (&info->hash->table, |
1740 | sizeof (struct bfd_link_hash_common_entry)); |
1623 | sizeof (struct bfd_link_hash_common_entry)); |
1741 | if (h->u.c.p == NULL) |
1624 | if (h->u.c.p == NULL) |
1742 | return FALSE; |
1625 | return FALSE; |
1743 | 1626 | ||
1744 | h->u.c.size = value; |
1627 | h->u.c.size = value; |
1745 | 1628 | ||
1746 | /* Select a default alignment based on the size. This may |
1629 | /* Select a default alignment based on the size. This may |
1747 | be overridden by the caller. */ |
1630 | be overridden by the caller. */ |
1748 | { |
1631 | { |
1749 | unsigned int power; |
1632 | unsigned int power; |
1750 | 1633 | ||
1751 | power = bfd_log2 (value); |
1634 | power = bfd_log2 (value); |
1752 | if (power > 4) |
1635 | if (power > 4) |
1753 | power = 4; |
1636 | power = 4; |
1754 | h->u.c.p->alignment_power = power; |
1637 | h->u.c.p->alignment_power = power; |
1755 | } |
1638 | } |
1756 | 1639 | ||
1757 | /* The section of a common symbol is only used if the common |
1640 | /* The section of a common symbol is only used if the common |
1758 | symbol is actually allocated. It basically provides a |
1641 | symbol is actually allocated. It basically provides a |
1759 | hook for the linker script to decide which output section |
1642 | hook for the linker script to decide which output section |
1760 | the common symbols should be put in. In most cases, the |
1643 | the common symbols should be put in. In most cases, the |
1761 | section of a common symbol will be bfd_com_section_ptr, |
1644 | section of a common symbol will be bfd_com_section_ptr, |
1762 | the code here will choose a common symbol section named |
1645 | the code here will choose a common symbol section named |
1763 | "COMMON", and the linker script will contain *(COMMON) in |
1646 | "COMMON", and the linker script will contain *(COMMON) in |
1764 | the appropriate place. A few targets use separate common |
1647 | the appropriate place. A few targets use separate common |
1765 | sections for small symbols, and they require special |
1648 | sections for small symbols, and they require special |
1766 | handling. */ |
1649 | handling. */ |
1767 | if (section == bfd_com_section_ptr) |
1650 | if (section == bfd_com_section_ptr) |
1768 | { |
1651 | { |
1769 | h->u.c.p->section = bfd_make_section_old_way (abfd, "COMMON"); |
1652 | h->u.c.p->section = bfd_make_section_old_way (abfd, "COMMON"); |
1770 | h->u.c.p->section->flags |= SEC_ALLOC; |
1653 | h->u.c.p->section->flags |= SEC_ALLOC; |
1771 | } |
1654 | } |
1772 | else if (section->owner != abfd) |
1655 | else if (section->owner != abfd) |
1773 | { |
1656 | { |
1774 | h->u.c.p->section = bfd_make_section_old_way (abfd, |
1657 | h->u.c.p->section = bfd_make_section_old_way (abfd, |
1775 | section->name); |
1658 | section->name); |
1776 | h->u.c.p->section->flags |= SEC_ALLOC; |
1659 | h->u.c.p->section->flags |= SEC_ALLOC; |
1777 | } |
1660 | } |
1778 | else |
1661 | else |
1779 | h->u.c.p->section = section; |
1662 | h->u.c.p->section = section; |
- | 1663 | h->linker_def = 0; |
|
1780 | break; |
1664 | break; |
1781 | 1665 | ||
1782 | case REF: |
1666 | case REF: |
1783 | /* A reference to a defined symbol. */ |
1667 | /* A reference to a defined symbol. */ |
1784 | if (h->u.undef.next == NULL && info->hash->undefs_tail != h) |
1668 | if (h->u.undef.next == NULL && info->hash->undefs_tail != h) |
1785 | h->u.undef.next = h; |
1669 | h->u.undef.next = h; |
1786 | break; |
1670 | break; |
1787 | 1671 | ||
1788 | case BIG: |
1672 | case BIG: |
1789 | /* We have found a common definition for a symbol which |
1673 | /* We have found a common definition for a symbol which |
1790 | already had a common definition. Use the maximum of the |
1674 | already had a common definition. Use the maximum of the |
1791 | two sizes, and use the section required by the larger symbol. */ |
1675 | two sizes, and use the section required by the larger symbol. */ |
1792 | BFD_ASSERT (h->type == bfd_link_hash_common); |
1676 | BFD_ASSERT (h->type == bfd_link_hash_common); |
1793 | if (! ((*info->callbacks->multiple_common) |
1677 | if (! ((*info->callbacks->multiple_common) |
1794 | (info, h, abfd, bfd_link_hash_common, value))) |
1678 | (info, h, abfd, bfd_link_hash_common, value))) |
1795 | return FALSE; |
1679 | return FALSE; |
1796 | if (value > h->u.c.size) |
1680 | if (value > h->u.c.size) |
1797 | { |
1681 | { |
1798 | unsigned int power; |
1682 | unsigned int power; |
1799 | 1683 | ||
1800 | h->u.c.size = value; |
1684 | h->u.c.size = value; |
1801 | 1685 | ||
1802 | /* Select a default alignment based on the size. This may |
1686 | /* Select a default alignment based on the size. This may |
1803 | be overridden by the caller. */ |
1687 | be overridden by the caller. */ |
1804 | power = bfd_log2 (value); |
1688 | power = bfd_log2 (value); |
1805 | if (power > 4) |
1689 | if (power > 4) |
1806 | power = 4; |
1690 | power = 4; |
1807 | h->u.c.p->alignment_power = power; |
1691 | h->u.c.p->alignment_power = power; |
1808 | 1692 | ||
1809 | /* Some systems have special treatment for small commons, |
1693 | /* Some systems have special treatment for small commons, |
1810 | hence we want to select the section used by the larger |
1694 | hence we want to select the section used by the larger |
1811 | symbol. This makes sure the symbol does not go in a |
1695 | symbol. This makes sure the symbol does not go in a |
1812 | small common section if it is now too large. */ |
1696 | small common section if it is now too large. */ |
1813 | if (section == bfd_com_section_ptr) |
1697 | if (section == bfd_com_section_ptr) |
1814 | { |
1698 | { |
1815 | h->u.c.p->section |
1699 | h->u.c.p->section |
1816 | = bfd_make_section_old_way (abfd, "COMMON"); |
1700 | = bfd_make_section_old_way (abfd, "COMMON"); |
1817 | h->u.c.p->section->flags |= SEC_ALLOC; |
1701 | h->u.c.p->section->flags |= SEC_ALLOC; |
1818 | } |
1702 | } |
1819 | else if (section->owner != abfd) |
1703 | else if (section->owner != abfd) |
1820 | { |
1704 | { |
1821 | h->u.c.p->section |
1705 | h->u.c.p->section |
1822 | = bfd_make_section_old_way (abfd, section->name); |
1706 | = bfd_make_section_old_way (abfd, section->name); |
1823 | h->u.c.p->section->flags |= SEC_ALLOC; |
1707 | h->u.c.p->section->flags |= SEC_ALLOC; |
1824 | } |
1708 | } |
1825 | else |
1709 | else |
1826 | h->u.c.p->section = section; |
1710 | h->u.c.p->section = section; |
1827 | } |
1711 | } |
1828 | break; |
1712 | break; |
1829 | 1713 | ||
1830 | case CREF: |
1714 | case CREF: |
1831 | /* We have found a common definition for a symbol which |
1715 | /* We have found a common definition for a symbol which |
1832 | was already defined. */ |
1716 | was already defined. */ |
1833 | if (! ((*info->callbacks->multiple_common) |
1717 | if (! ((*info->callbacks->multiple_common) |
1834 | (info, h, abfd, bfd_link_hash_common, value))) |
1718 | (info, h, abfd, bfd_link_hash_common, value))) |
1835 | return FALSE; |
1719 | return FALSE; |
1836 | break; |
1720 | break; |
1837 | 1721 | ||
1838 | case MIND: |
1722 | case MIND: |
1839 | /* Multiple indirect symbols. This is OK if they both point |
1723 | /* Multiple indirect symbols. This is OK if they both point |
1840 | to the same symbol. */ |
1724 | to the same symbol. */ |
1841 | if (strcmp (h->u.i.link->root.string, string) == 0) |
1725 | if (strcmp (h->u.i.link->root.string, string) == 0) |
1842 | break; |
1726 | break; |
1843 | /* Fall through. */ |
1727 | /* Fall through. */ |
1844 | case MDEF: |
1728 | case MDEF: |
1845 | /* Handle a multiple definition. */ |
1729 | /* Handle a multiple definition. */ |
1846 | if (! ((*info->callbacks->multiple_definition) |
1730 | if (! ((*info->callbacks->multiple_definition) |
1847 | (info, h, abfd, section, value))) |
1731 | (info, h, abfd, section, value))) |
1848 | return FALSE; |
1732 | return FALSE; |
1849 | break; |
1733 | break; |
1850 | 1734 | ||
1851 | case CIND: |
1735 | case CIND: |
1852 | /* Create an indirect symbol from an existing common symbol. */ |
1736 | /* Create an indirect symbol from an existing common symbol. */ |
1853 | BFD_ASSERT (h->type == bfd_link_hash_common); |
1737 | BFD_ASSERT (h->type == bfd_link_hash_common); |
1854 | if (! ((*info->callbacks->multiple_common) |
1738 | if (! ((*info->callbacks->multiple_common) |
1855 | (info, h, abfd, bfd_link_hash_indirect, 0))) |
1739 | (info, h, abfd, bfd_link_hash_indirect, 0))) |
1856 | return FALSE; |
1740 | return FALSE; |
1857 | /* Fall through. */ |
1741 | /* Fall through. */ |
1858 | case IND: |
1742 | case IND: |
1859 | /* Create an indirect symbol. */ |
- | |
1860 | { |
- | |
1861 | struct bfd_link_hash_entry *inh; |
- | |
1862 | - | ||
1863 | /* STRING is the name of the symbol we want to indirect |
- | |
1864 | to. */ |
- | |
1865 | inh = bfd_wrapped_link_hash_lookup (abfd, info, string, TRUE, |
- | |
1866 | copy, FALSE); |
- | |
1867 | if (inh == NULL) |
- | |
1868 | return FALSE; |
- | |
1869 | if (inh->type == bfd_link_hash_indirect |
1743 | if (inh->type == bfd_link_hash_indirect |
1870 | && inh->u.i.link == h) |
1744 | && inh->u.i.link == h) |
1871 | { |
1745 | { |
1872 | (*_bfd_error_handler) |
1746 | (*_bfd_error_handler) |
1873 | (_("%B: indirect symbol `%s' to `%s' is a loop"), |
1747 | (_("%B: indirect symbol `%s' to `%s' is a loop"), |
1874 | abfd, name, string); |
1748 | abfd, name, string); |
1875 | bfd_set_error (bfd_error_invalid_operation); |
1749 | bfd_set_error (bfd_error_invalid_operation); |
1876 | return FALSE; |
1750 | return FALSE; |
1877 | } |
1751 | } |
1878 | if (inh->type == bfd_link_hash_new) |
1752 | if (inh->type == bfd_link_hash_new) |
1879 | { |
1753 | { |
1880 | inh->type = bfd_link_hash_undefined; |
1754 | inh->type = bfd_link_hash_undefined; |
1881 | inh->u.undef.abfd = abfd; |
1755 | inh->u.undef.abfd = abfd; |
1882 | bfd_link_add_undef (info->hash, inh); |
1756 | bfd_link_add_undef (info->hash, inh); |
1883 | } |
1757 | } |
1884 | 1758 | ||
1885 | /* If the indirect symbol has been referenced, we need to |
1759 | /* If the indirect symbol has been referenced, we need to |
1886 | push the reference down to the symbol we are |
1760 | push the reference down to the symbol we are referencing. */ |
1887 | referencing. */ |
- | |
1888 | if (h->type != bfd_link_hash_new) |
1761 | if (h->type != bfd_link_hash_new) |
1889 | { |
1762 | { |
- | 1763 | /* ??? If inh->type == bfd_link_hash_undefweak this |
|
- | 1764 | converts inh to bfd_link_hash_undefined. */ |
|
1890 | row = UNDEF_ROW; |
1765 | row = UNDEF_ROW; |
1891 | cycle = TRUE; |
1766 | cycle = TRUE; |
1892 | } |
1767 | } |
1893 | 1768 | ||
1894 | h->type = bfd_link_hash_indirect; |
1769 | h->type = bfd_link_hash_indirect; |
1895 | h->u.i.link = inh; |
1770 | h->u.i.link = inh; |
- | 1771 | /* Not setting h = h->u.i.link here means that when cycle is |
|
- | 1772 | set above we'll always go to REFC, and then cycle again |
|
- | 1773 | to the indirected symbol. This means that any successful |
|
- | 1774 | change of an existing symbol to indirect counts as a |
|
- | 1775 | reference. ??? That may not be correct when the existing |
|
1896 | } |
1776 | symbol was defweak. */ |
1897 | break; |
1777 | break; |
1898 | 1778 | ||
1899 | case SET: |
1779 | case SET: |
1900 | /* Add an entry to a set. */ |
1780 | /* Add an entry to a set. */ |
1901 | if (! (*info->callbacks->add_to_set) (info, h, BFD_RELOC_CTOR, |
1781 | if (! (*info->callbacks->add_to_set) (info, h, BFD_RELOC_CTOR, |
1902 | abfd, section, value)) |
1782 | abfd, section, value)) |
1903 | return FALSE; |
1783 | return FALSE; |
1904 | break; |
1784 | break; |
1905 | 1785 | ||
1906 | case WARNC: |
1786 | case WARNC: |
1907 | /* Issue a warning and cycle. */ |
1787 | /* Issue a warning and cycle, except when the reference is |
- | 1788 | in LTO IR. */ |
|
1908 | if (h->u.i.warning != NULL) |
1789 | if (h->u.i.warning != NULL |
- | 1790 | && (abfd->flags & BFD_PLUGIN) == 0) |
|
1909 | { |
1791 | { |
1910 | if (! (*info->callbacks->warning) (info, h->u.i.warning, |
1792 | if (! (*info->callbacks->warning) (info, h->u.i.warning, |
1911 | h->root.string, abfd, |
1793 | h->root.string, abfd, |
1912 | NULL, 0)) |
1794 | NULL, 0)) |
1913 | return FALSE; |
1795 | return FALSE; |
1914 | /* Only issue a warning once. */ |
1796 | /* Only issue a warning once. */ |
1915 | h->u.i.warning = NULL; |
1797 | h->u.i.warning = NULL; |
1916 | } |
1798 | } |
1917 | /* Fall through. */ |
1799 | /* Fall through. */ |
1918 | case CYCLE: |
1800 | case CYCLE: |
1919 | /* Try again with the referenced symbol. */ |
1801 | /* Try again with the referenced symbol. */ |
1920 | h = h->u.i.link; |
1802 | h = h->u.i.link; |
1921 | cycle = TRUE; |
1803 | cycle = TRUE; |
1922 | break; |
1804 | break; |
1923 | 1805 | ||
1924 | case REFC: |
1806 | case REFC: |
1925 | /* A reference to an indirect symbol. */ |
1807 | /* A reference to an indirect symbol. */ |
1926 | if (h->u.undef.next == NULL && info->hash->undefs_tail != h) |
1808 | if (h->u.undef.next == NULL && info->hash->undefs_tail != h) |
1927 | h->u.undef.next = h; |
1809 | h->u.undef.next = h; |
1928 | h = h->u.i.link; |
1810 | h = h->u.i.link; |
1929 | cycle = TRUE; |
1811 | cycle = TRUE; |
1930 | break; |
1812 | break; |
1931 | 1813 | ||
1932 | case WARN: |
1814 | case WARN: |
1933 | /* Issue a warning. */ |
- | |
1934 | if (! (*info->callbacks->warning) (info, string, h->root.string, |
- | |
1935 | hash_entry_bfd (h), NULL, 0)) |
- | |
1936 | return FALSE; |
- | |
1937 | break; |
- | |
1938 | - | ||
1939 | case CWARN: |
- | |
1940 | /* Warn if this symbol has been referenced already, |
1815 | /* Warn if this symbol has been referenced already from non-IR, |
1941 | otherwise add a warning. A symbol has been referenced if |
1816 | otherwise add a warning. */ |
1942 | the u.undef.next field is not NULL, or it is the tail of the |
1817 | if ((!info->lto_plugin_active |
1943 | undefined symbol list. The REF case above helps to |
1818 | && (h->u.undef.next != NULL || info->hash->undefs_tail == h)) |
1944 | ensure this. */ |
1819 | || h->non_ir_ref) |
1945 | if (h->u.undef.next != NULL || info->hash->undefs_tail == h) |
- | |
1946 | { |
1820 | { |
1947 | if (! (*info->callbacks->warning) (info, string, h->root.string, |
1821 | if (! (*info->callbacks->warning) (info, string, h->root.string, |
1948 | hash_entry_bfd (h), NULL, 0)) |
1822 | hash_entry_bfd (h), NULL, 0)) |
1949 | return FALSE; |
1823 | return FALSE; |
1950 | break; |
1824 | break; |
1951 | } |
1825 | } |
1952 | /* Fall through. */ |
1826 | /* Fall through. */ |
1953 | case MWARN: |
1827 | case MWARN: |
1954 | /* Make a warning symbol. */ |
1828 | /* Make a warning symbol. */ |
1955 | { |
1829 | { |
1956 | struct bfd_link_hash_entry *sub; |
1830 | struct bfd_link_hash_entry *sub; |
1957 | 1831 | ||
1958 | /* STRING is the warning to give. */ |
1832 | /* STRING is the warning to give. */ |
1959 | sub = ((struct bfd_link_hash_entry *) |
1833 | sub = ((struct bfd_link_hash_entry *) |
1960 | ((*info->hash->table.newfunc) |
1834 | ((*info->hash->table.newfunc) |
1961 | (NULL, &info->hash->table, h->root.string))); |
1835 | (NULL, &info->hash->table, h->root.string))); |
1962 | if (sub == NULL) |
1836 | if (sub == NULL) |
1963 | return FALSE; |
1837 | return FALSE; |
1964 | *sub = *h; |
1838 | *sub = *h; |
1965 | sub->type = bfd_link_hash_warning; |
1839 | sub->type = bfd_link_hash_warning; |
1966 | sub->u.i.link = h; |
1840 | sub->u.i.link = h; |
1967 | if (! copy) |
1841 | if (! copy) |
1968 | sub->u.i.warning = string; |
1842 | sub->u.i.warning = string; |
1969 | else |
1843 | else |
1970 | { |
1844 | { |
1971 | char *w; |
1845 | char *w; |
1972 | size_t len = strlen (string) + 1; |
1846 | size_t len = strlen (string) + 1; |
1973 | 1847 | ||
1974 | w = (char *) bfd_hash_allocate (&info->hash->table, len); |
1848 | w = (char *) bfd_hash_allocate (&info->hash->table, len); |
1975 | if (w == NULL) |
1849 | if (w == NULL) |
1976 | return FALSE; |
1850 | return FALSE; |
1977 | memcpy (w, string, len); |
1851 | memcpy (w, string, len); |
1978 | sub->u.i.warning = w; |
1852 | sub->u.i.warning = w; |
1979 | } |
1853 | } |
1980 | 1854 | ||
1981 | bfd_hash_replace (&info->hash->table, |
1855 | bfd_hash_replace (&info->hash->table, |
1982 | (struct bfd_hash_entry *) h, |
1856 | (struct bfd_hash_entry *) h, |
1983 | (struct bfd_hash_entry *) sub); |
1857 | (struct bfd_hash_entry *) sub); |
1984 | if (hashp != NULL) |
1858 | if (hashp != NULL) |
1985 | *hashp = sub; |
1859 | *hashp = sub; |
1986 | } |
1860 | } |
1987 | break; |
1861 | break; |
1988 | } |
1862 | } |
1989 | } |
1863 | } |
1990 | while (cycle); |
1864 | while (cycle); |
1991 | 1865 | ||
1992 | return TRUE; |
1866 | return TRUE; |
1993 | } |
1867 | } |
1994 | 1868 | ||
1995 | /* Generic final link routine. */ |
1869 | /* Generic final link routine. */ |
1996 | 1870 | ||
1997 | bfd_boolean |
1871 | bfd_boolean |
1998 | _bfd_generic_final_link (bfd *abfd, struct bfd_link_info *info) |
1872 | _bfd_generic_final_link (bfd *abfd, struct bfd_link_info *info) |
1999 | { |
1873 | { |
2000 | bfd *sub; |
1874 | bfd *sub; |
2001 | asection *o; |
1875 | asection *o; |
2002 | struct bfd_link_order *p; |
1876 | struct bfd_link_order *p; |
2003 | size_t outsymalloc; |
1877 | size_t outsymalloc; |
2004 | struct generic_write_global_symbol_info wginfo; |
1878 | struct generic_write_global_symbol_info wginfo; |
2005 | 1879 | ||
2006 | bfd_get_outsymbols (abfd) = NULL; |
1880 | bfd_get_outsymbols (abfd) = NULL; |
2007 | bfd_get_symcount (abfd) = 0; |
1881 | bfd_get_symcount (abfd) = 0; |
2008 | outsymalloc = 0; |
1882 | outsymalloc = 0; |
2009 | 1883 | ||
2010 | /* Mark all sections which will be included in the output file. */ |
1884 | /* Mark all sections which will be included in the output file. */ |
2011 | for (o = abfd->sections; o != NULL; o = o->next) |
1885 | for (o = abfd->sections; o != NULL; o = o->next) |
2012 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
1886 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
2013 | if (p->type == bfd_indirect_link_order) |
1887 | if (p->type == bfd_indirect_link_order) |
2014 | p->u.indirect.section->linker_mark = TRUE; |
1888 | p->u.indirect.section->linker_mark = TRUE; |
2015 | 1889 | ||
2016 | /* Build the output symbol table. */ |
1890 | /* Build the output symbol table. */ |
2017 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) |
1891 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
2018 | if (! _bfd_generic_link_output_symbols (abfd, sub, info, &outsymalloc)) |
1892 | if (! _bfd_generic_link_output_symbols (abfd, sub, info, &outsymalloc)) |
2019 | return FALSE; |
1893 | return FALSE; |
2020 | 1894 | ||
2021 | /* Accumulate the global symbols. */ |
1895 | /* Accumulate the global symbols. */ |
2022 | wginfo.info = info; |
1896 | wginfo.info = info; |
2023 | wginfo.output_bfd = abfd; |
1897 | wginfo.output_bfd = abfd; |
2024 | wginfo.psymalloc = &outsymalloc; |
1898 | wginfo.psymalloc = &outsymalloc; |
2025 | _bfd_generic_link_hash_traverse (_bfd_generic_hash_table (info), |
1899 | _bfd_generic_link_hash_traverse (_bfd_generic_hash_table (info), |
2026 | _bfd_generic_link_write_global_symbol, |
1900 | _bfd_generic_link_write_global_symbol, |
2027 | &wginfo); |
1901 | &wginfo); |
2028 | 1902 | ||
2029 | /* Make sure we have a trailing NULL pointer on OUTSYMBOLS. We |
1903 | /* Make sure we have a trailing NULL pointer on OUTSYMBOLS. We |
2030 | shouldn't really need one, since we have SYMCOUNT, but some old |
1904 | shouldn't really need one, since we have SYMCOUNT, but some old |
2031 | code still expects one. */ |
1905 | code still expects one. */ |
2032 | if (! generic_add_output_symbol (abfd, &outsymalloc, NULL)) |
1906 | if (! generic_add_output_symbol (abfd, &outsymalloc, NULL)) |
2033 | return FALSE; |
1907 | return FALSE; |
2034 | 1908 | ||
2035 | if (info->relocatable) |
1909 | if (bfd_link_relocatable (info)) |
2036 | { |
1910 | { |
2037 | /* Allocate space for the output relocs for each section. */ |
1911 | /* Allocate space for the output relocs for each section. */ |
2038 | for (o = abfd->sections; o != NULL; o = o->next) |
1912 | for (o = abfd->sections; o != NULL; o = o->next) |
2039 | { |
1913 | { |
2040 | o->reloc_count = 0; |
1914 | o->reloc_count = 0; |
2041 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
1915 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
2042 | { |
1916 | { |
2043 | if (p->type == bfd_section_reloc_link_order |
1917 | if (p->type == bfd_section_reloc_link_order |
2044 | || p->type == bfd_symbol_reloc_link_order) |
1918 | || p->type == bfd_symbol_reloc_link_order) |
2045 | ++o->reloc_count; |
1919 | ++o->reloc_count; |
2046 | else if (p->type == bfd_indirect_link_order) |
1920 | else if (p->type == bfd_indirect_link_order) |
2047 | { |
1921 | { |
2048 | asection *input_section; |
1922 | asection *input_section; |
2049 | bfd *input_bfd; |
1923 | bfd *input_bfd; |
2050 | long relsize; |
1924 | long relsize; |
2051 | arelent **relocs; |
1925 | arelent **relocs; |
2052 | asymbol **symbols; |
1926 | asymbol **symbols; |
2053 | long reloc_count; |
1927 | long reloc_count; |
2054 | 1928 | ||
2055 | input_section = p->u.indirect.section; |
1929 | input_section = p->u.indirect.section; |
2056 | input_bfd = input_section->owner; |
1930 | input_bfd = input_section->owner; |
2057 | relsize = bfd_get_reloc_upper_bound (input_bfd, |
1931 | relsize = bfd_get_reloc_upper_bound (input_bfd, |
2058 | input_section); |
1932 | input_section); |
2059 | if (relsize < 0) |
1933 | if (relsize < 0) |
2060 | return FALSE; |
1934 | return FALSE; |
2061 | relocs = (arelent **) bfd_malloc (relsize); |
1935 | relocs = (arelent **) bfd_malloc (relsize); |
2062 | if (!relocs && relsize != 0) |
1936 | if (!relocs && relsize != 0) |
2063 | return FALSE; |
1937 | return FALSE; |
2064 | symbols = _bfd_generic_link_get_symbols (input_bfd); |
1938 | symbols = _bfd_generic_link_get_symbols (input_bfd); |
2065 | reloc_count = bfd_canonicalize_reloc (input_bfd, |
1939 | reloc_count = bfd_canonicalize_reloc (input_bfd, |
2066 | input_section, |
1940 | input_section, |
2067 | relocs, |
1941 | relocs, |
2068 | symbols); |
1942 | symbols); |
2069 | free (relocs); |
1943 | free (relocs); |
2070 | if (reloc_count < 0) |
1944 | if (reloc_count < 0) |
2071 | return FALSE; |
1945 | return FALSE; |
2072 | BFD_ASSERT ((unsigned long) reloc_count |
1946 | BFD_ASSERT ((unsigned long) reloc_count |
2073 | == input_section->reloc_count); |
1947 | == input_section->reloc_count); |
2074 | o->reloc_count += reloc_count; |
1948 | o->reloc_count += reloc_count; |
2075 | } |
1949 | } |
2076 | } |
1950 | } |
2077 | if (o->reloc_count > 0) |
1951 | if (o->reloc_count > 0) |
2078 | { |
1952 | { |
2079 | bfd_size_type amt; |
1953 | bfd_size_type amt; |
2080 | 1954 | ||
2081 | amt = o->reloc_count; |
1955 | amt = o->reloc_count; |
2082 | amt *= sizeof (arelent *); |
1956 | amt *= sizeof (arelent *); |
2083 | o->orelocation = (struct reloc_cache_entry **) bfd_alloc (abfd, amt); |
1957 | o->orelocation = (struct reloc_cache_entry **) bfd_alloc (abfd, amt); |
2084 | if (!o->orelocation) |
1958 | if (!o->orelocation) |
2085 | return FALSE; |
1959 | return FALSE; |
2086 | o->flags |= SEC_RELOC; |
1960 | o->flags |= SEC_RELOC; |
2087 | /* Reset the count so that it can be used as an index |
1961 | /* Reset the count so that it can be used as an index |
2088 | when putting in the output relocs. */ |
1962 | when putting in the output relocs. */ |
2089 | o->reloc_count = 0; |
1963 | o->reloc_count = 0; |
2090 | } |
1964 | } |
2091 | } |
1965 | } |
2092 | } |
1966 | } |
2093 | 1967 | ||
2094 | /* Handle all the link order information for the sections. */ |
1968 | /* Handle all the link order information for the sections. */ |
2095 | for (o = abfd->sections; o != NULL; o = o->next) |
1969 | for (o = abfd->sections; o != NULL; o = o->next) |
2096 | { |
1970 | { |
2097 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
1971 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
2098 | { |
1972 | { |
2099 | switch (p->type) |
1973 | switch (p->type) |
2100 | { |
1974 | { |
2101 | case bfd_section_reloc_link_order: |
1975 | case bfd_section_reloc_link_order: |
2102 | case bfd_symbol_reloc_link_order: |
1976 | case bfd_symbol_reloc_link_order: |
2103 | if (! _bfd_generic_reloc_link_order (abfd, info, o, p)) |
1977 | if (! _bfd_generic_reloc_link_order (abfd, info, o, p)) |
2104 | return FALSE; |
1978 | return FALSE; |
2105 | break; |
1979 | break; |
2106 | case bfd_indirect_link_order: |
1980 | case bfd_indirect_link_order: |
2107 | if (! default_indirect_link_order (abfd, info, o, p, TRUE)) |
1981 | if (! default_indirect_link_order (abfd, info, o, p, TRUE)) |
2108 | return FALSE; |
1982 | return FALSE; |
2109 | break; |
1983 | break; |
2110 | default: |
1984 | default: |
2111 | if (! _bfd_default_link_order (abfd, info, o, p)) |
1985 | if (! _bfd_default_link_order (abfd, info, o, p)) |
2112 | return FALSE; |
1986 | return FALSE; |
2113 | break; |
1987 | break; |
2114 | } |
1988 | } |
2115 | } |
1989 | } |
2116 | } |
1990 | } |
2117 | 1991 | ||
2118 | return TRUE; |
1992 | return TRUE; |
2119 | } |
1993 | } |
2120 | 1994 | ||
2121 | /* Add an output symbol to the output BFD. */ |
1995 | /* Add an output symbol to the output BFD. */ |
2122 | 1996 | ||
2123 | static bfd_boolean |
1997 | static bfd_boolean |
2124 | generic_add_output_symbol (bfd *output_bfd, size_t *psymalloc, asymbol *sym) |
1998 | generic_add_output_symbol (bfd *output_bfd, size_t *psymalloc, asymbol *sym) |
2125 | { |
1999 | { |
2126 | if (bfd_get_symcount (output_bfd) >= *psymalloc) |
2000 | if (bfd_get_symcount (output_bfd) >= *psymalloc) |
2127 | { |
2001 | { |
2128 | asymbol **newsyms; |
2002 | asymbol **newsyms; |
2129 | bfd_size_type amt; |
2003 | bfd_size_type amt; |
2130 | 2004 | ||
2131 | if (*psymalloc == 0) |
2005 | if (*psymalloc == 0) |
2132 | *psymalloc = 124; |
2006 | *psymalloc = 124; |
2133 | else |
2007 | else |
2134 | *psymalloc *= 2; |
2008 | *psymalloc *= 2; |
2135 | amt = *psymalloc; |
2009 | amt = *psymalloc; |
2136 | amt *= sizeof (asymbol *); |
2010 | amt *= sizeof (asymbol *); |
2137 | newsyms = (asymbol **) bfd_realloc (bfd_get_outsymbols (output_bfd), amt); |
2011 | newsyms = (asymbol **) bfd_realloc (bfd_get_outsymbols (output_bfd), amt); |
2138 | if (newsyms == NULL) |
2012 | if (newsyms == NULL) |
2139 | return FALSE; |
2013 | return FALSE; |
2140 | bfd_get_outsymbols (output_bfd) = newsyms; |
2014 | bfd_get_outsymbols (output_bfd) = newsyms; |
2141 | } |
2015 | } |
2142 | 2016 | ||
2143 | bfd_get_outsymbols (output_bfd) [bfd_get_symcount (output_bfd)] = sym; |
2017 | bfd_get_outsymbols (output_bfd) [bfd_get_symcount (output_bfd)] = sym; |
2144 | if (sym != NULL) |
2018 | if (sym != NULL) |
2145 | ++ bfd_get_symcount (output_bfd); |
2019 | ++ bfd_get_symcount (output_bfd); |
2146 | 2020 | ||
2147 | return TRUE; |
2021 | return TRUE; |
2148 | } |
2022 | } |
2149 | 2023 | ||
2150 | /* Handle the symbols for an input BFD. */ |
2024 | /* Handle the symbols for an input BFD. */ |
2151 | 2025 | ||
2152 | bfd_boolean |
2026 | bfd_boolean |
2153 | _bfd_generic_link_output_symbols (bfd *output_bfd, |
2027 | _bfd_generic_link_output_symbols (bfd *output_bfd, |
2154 | bfd *input_bfd, |
2028 | bfd *input_bfd, |
2155 | struct bfd_link_info *info, |
2029 | struct bfd_link_info *info, |
2156 | size_t *psymalloc) |
2030 | size_t *psymalloc) |
2157 | { |
2031 | { |
2158 | asymbol **sym_ptr; |
2032 | asymbol **sym_ptr; |
2159 | asymbol **sym_end; |
2033 | asymbol **sym_end; |
2160 | 2034 | ||
2161 | if (!bfd_generic_link_read_symbols (input_bfd)) |
2035 | if (!bfd_generic_link_read_symbols (input_bfd)) |
2162 | return FALSE; |
2036 | return FALSE; |
2163 | 2037 | ||
2164 | /* Create a filename symbol if we are supposed to. */ |
2038 | /* Create a filename symbol if we are supposed to. */ |
2165 | if (info->create_object_symbols_section != NULL) |
2039 | if (info->create_object_symbols_section != NULL) |
2166 | { |
2040 | { |
2167 | asection *sec; |
2041 | asection *sec; |
2168 | 2042 | ||
2169 | for (sec = input_bfd->sections; sec != NULL; sec = sec->next) |
2043 | for (sec = input_bfd->sections; sec != NULL; sec = sec->next) |
2170 | { |
2044 | { |
2171 | if (sec->output_section == info->create_object_symbols_section) |
2045 | if (sec->output_section == info->create_object_symbols_section) |
2172 | { |
2046 | { |
2173 | asymbol *newsym; |
2047 | asymbol *newsym; |
2174 | 2048 | ||
2175 | newsym = bfd_make_empty_symbol (input_bfd); |
2049 | newsym = bfd_make_empty_symbol (input_bfd); |
2176 | if (!newsym) |
2050 | if (!newsym) |
2177 | return FALSE; |
2051 | return FALSE; |
2178 | newsym->name = input_bfd->filename; |
2052 | newsym->name = input_bfd->filename; |
2179 | newsym->value = 0; |
2053 | newsym->value = 0; |
2180 | newsym->flags = BSF_LOCAL | BSF_FILE; |
2054 | newsym->flags = BSF_LOCAL | BSF_FILE; |
2181 | newsym->section = sec; |
2055 | newsym->section = sec; |
2182 | 2056 | ||
2183 | if (! generic_add_output_symbol (output_bfd, psymalloc, |
2057 | if (! generic_add_output_symbol (output_bfd, psymalloc, |
2184 | newsym)) |
2058 | newsym)) |
2185 | return FALSE; |
2059 | return FALSE; |
2186 | 2060 | ||
2187 | break; |
2061 | break; |
2188 | } |
2062 | } |
2189 | } |
2063 | } |
2190 | } |
2064 | } |
2191 | 2065 | ||
2192 | /* Adjust the values of the globally visible symbols, and write out |
2066 | /* Adjust the values of the globally visible symbols, and write out |
2193 | local symbols. */ |
2067 | local symbols. */ |
2194 | sym_ptr = _bfd_generic_link_get_symbols (input_bfd); |
2068 | sym_ptr = _bfd_generic_link_get_symbols (input_bfd); |
2195 | sym_end = sym_ptr + _bfd_generic_link_get_symcount (input_bfd); |
2069 | sym_end = sym_ptr + _bfd_generic_link_get_symcount (input_bfd); |
2196 | for (; sym_ptr < sym_end; sym_ptr++) |
2070 | for (; sym_ptr < sym_end; sym_ptr++) |
2197 | { |
2071 | { |
2198 | asymbol *sym; |
2072 | asymbol *sym; |
2199 | struct generic_link_hash_entry *h; |
2073 | struct generic_link_hash_entry *h; |
2200 | bfd_boolean output; |
2074 | bfd_boolean output; |
2201 | 2075 | ||
2202 | h = NULL; |
2076 | h = NULL; |
2203 | sym = *sym_ptr; |
2077 | sym = *sym_ptr; |
2204 | if ((sym->flags & (BSF_INDIRECT |
2078 | if ((sym->flags & (BSF_INDIRECT |
2205 | | BSF_WARNING |
2079 | | BSF_WARNING |
2206 | | BSF_GLOBAL |
2080 | | BSF_GLOBAL |
2207 | | BSF_CONSTRUCTOR |
2081 | | BSF_CONSTRUCTOR |
2208 | | BSF_WEAK)) != 0 |
2082 | | BSF_WEAK)) != 0 |
2209 | || bfd_is_und_section (bfd_get_section (sym)) |
2083 | || bfd_is_und_section (bfd_get_section (sym)) |
2210 | || bfd_is_com_section (bfd_get_section (sym)) |
2084 | || bfd_is_com_section (bfd_get_section (sym)) |
2211 | || bfd_is_ind_section (bfd_get_section (sym))) |
2085 | || bfd_is_ind_section (bfd_get_section (sym))) |
2212 | { |
2086 | { |
2213 | if (sym->udata.p != NULL) |
2087 | if (sym->udata.p != NULL) |
2214 | h = (struct generic_link_hash_entry *) sym->udata.p; |
2088 | h = (struct generic_link_hash_entry *) sym->udata.p; |
2215 | else if ((sym->flags & BSF_CONSTRUCTOR) != 0) |
2089 | else if ((sym->flags & BSF_CONSTRUCTOR) != 0) |
2216 | { |
2090 | { |
2217 | /* This case normally means that the main linker code |
2091 | /* This case normally means that the main linker code |
2218 | deliberately ignored this constructor symbol. We |
2092 | deliberately ignored this constructor symbol. We |
2219 | should just pass it through. This will screw up if |
2093 | should just pass it through. This will screw up if |
2220 | the constructor symbol is from a different, |
2094 | the constructor symbol is from a different, |
2221 | non-generic, object file format, but the case will |
2095 | non-generic, object file format, but the case will |
2222 | only arise when linking with -r, which will probably |
2096 | only arise when linking with -r, which will probably |
2223 | fail anyhow, since there will be no way to represent |
2097 | fail anyhow, since there will be no way to represent |
2224 | the relocs in the output format being used. */ |
2098 | the relocs in the output format being used. */ |
2225 | h = NULL; |
2099 | h = NULL; |
2226 | } |
2100 | } |
2227 | else if (bfd_is_und_section (bfd_get_section (sym))) |
2101 | else if (bfd_is_und_section (bfd_get_section (sym))) |
2228 | h = ((struct generic_link_hash_entry *) |
2102 | h = ((struct generic_link_hash_entry *) |
2229 | bfd_wrapped_link_hash_lookup (output_bfd, info, |
2103 | bfd_wrapped_link_hash_lookup (output_bfd, info, |
2230 | bfd_asymbol_name (sym), |
2104 | bfd_asymbol_name (sym), |
2231 | FALSE, FALSE, TRUE)); |
2105 | FALSE, FALSE, TRUE)); |
2232 | else |
2106 | else |
2233 | h = _bfd_generic_link_hash_lookup (_bfd_generic_hash_table (info), |
2107 | h = _bfd_generic_link_hash_lookup (_bfd_generic_hash_table (info), |
2234 | bfd_asymbol_name (sym), |
2108 | bfd_asymbol_name (sym), |
2235 | FALSE, FALSE, TRUE); |
2109 | FALSE, FALSE, TRUE); |
2236 | 2110 | ||
2237 | if (h != NULL) |
2111 | if (h != NULL) |
2238 | { |
2112 | { |
2239 | /* Force all references to this symbol to point to |
2113 | /* Force all references to this symbol to point to |
2240 | the same area in memory. It is possible that |
2114 | the same area in memory. It is possible that |
2241 | this routine will be called with a hash table |
2115 | this routine will be called with a hash table |
2242 | other than a generic hash table, so we double |
2116 | other than a generic hash table, so we double |
2243 | check that. */ |
2117 | check that. */ |
2244 | if (info->output_bfd->xvec == input_bfd->xvec) |
2118 | if (info->output_bfd->xvec == input_bfd->xvec) |
2245 | { |
2119 | { |
2246 | if (h->sym != NULL) |
2120 | if (h->sym != NULL) |
2247 | *sym_ptr = sym = h->sym; |
2121 | *sym_ptr = sym = h->sym; |
2248 | } |
2122 | } |
2249 | 2123 | ||
2250 | switch (h->root.type) |
2124 | switch (h->root.type) |
2251 | { |
2125 | { |
2252 | default: |
2126 | default: |
2253 | case bfd_link_hash_new: |
2127 | case bfd_link_hash_new: |
2254 | abort (); |
2128 | abort (); |
2255 | case bfd_link_hash_undefined: |
2129 | case bfd_link_hash_undefined: |
2256 | break; |
2130 | break; |
2257 | case bfd_link_hash_undefweak: |
2131 | case bfd_link_hash_undefweak: |
2258 | sym->flags |= BSF_WEAK; |
2132 | sym->flags |= BSF_WEAK; |
2259 | break; |
2133 | break; |
2260 | case bfd_link_hash_indirect: |
2134 | case bfd_link_hash_indirect: |
2261 | h = (struct generic_link_hash_entry *) h->root.u.i.link; |
2135 | h = (struct generic_link_hash_entry *) h->root.u.i.link; |
2262 | /* fall through */ |
2136 | /* fall through */ |
2263 | case bfd_link_hash_defined: |
2137 | case bfd_link_hash_defined: |
2264 | sym->flags |= BSF_GLOBAL; |
2138 | sym->flags |= BSF_GLOBAL; |
2265 | sym->flags &=~ BSF_CONSTRUCTOR; |
2139 | sym->flags &=~ (BSF_WEAK | BSF_CONSTRUCTOR); |
2266 | sym->value = h->root.u.def.value; |
2140 | sym->value = h->root.u.def.value; |
2267 | sym->section = h->root.u.def.section; |
2141 | sym->section = h->root.u.def.section; |
2268 | break; |
2142 | break; |
2269 | case bfd_link_hash_defweak: |
2143 | case bfd_link_hash_defweak: |
2270 | sym->flags |= BSF_WEAK; |
2144 | sym->flags |= BSF_WEAK; |
2271 | sym->flags &=~ BSF_CONSTRUCTOR; |
2145 | sym->flags &=~ BSF_CONSTRUCTOR; |
2272 | sym->value = h->root.u.def.value; |
2146 | sym->value = h->root.u.def.value; |
2273 | sym->section = h->root.u.def.section; |
2147 | sym->section = h->root.u.def.section; |
2274 | break; |
2148 | break; |
2275 | case bfd_link_hash_common: |
2149 | case bfd_link_hash_common: |
2276 | sym->value = h->root.u.c.size; |
2150 | sym->value = h->root.u.c.size; |
2277 | sym->flags |= BSF_GLOBAL; |
2151 | sym->flags |= BSF_GLOBAL; |
2278 | if (! bfd_is_com_section (sym->section)) |
2152 | if (! bfd_is_com_section (sym->section)) |
2279 | { |
2153 | { |
2280 | BFD_ASSERT (bfd_is_und_section (sym->section)); |
2154 | BFD_ASSERT (bfd_is_und_section (sym->section)); |
2281 | sym->section = bfd_com_section_ptr; |
2155 | sym->section = bfd_com_section_ptr; |
2282 | } |
2156 | } |
2283 | /* We do not set the section of the symbol to |
2157 | /* We do not set the section of the symbol to |
2284 | h->root.u.c.p->section. That value was saved so |
2158 | h->root.u.c.p->section. That value was saved so |
2285 | that we would know where to allocate the symbol |
2159 | that we would know where to allocate the symbol |
2286 | if it was defined. In this case the type is |
2160 | if it was defined. In this case the type is |
2287 | still bfd_link_hash_common, so we did not define |
2161 | still bfd_link_hash_common, so we did not define |
2288 | it, so we do not want to use that section. */ |
2162 | it, so we do not want to use that section. */ |
2289 | break; |
2163 | break; |
2290 | } |
2164 | } |
2291 | } |
2165 | } |
2292 | } |
2166 | } |
2293 | 2167 | ||
2294 | /* This switch is straight from the old code in |
2168 | /* This switch is straight from the old code in |
2295 | write_file_locals in ldsym.c. */ |
2169 | write_file_locals in ldsym.c. */ |
2296 | if (info->strip == strip_all |
2170 | if (info->strip == strip_all |
2297 | || (info->strip == strip_some |
2171 | || (info->strip == strip_some |
2298 | && bfd_hash_lookup (info->keep_hash, bfd_asymbol_name (sym), |
2172 | && bfd_hash_lookup (info->keep_hash, bfd_asymbol_name (sym), |
2299 | FALSE, FALSE) == NULL)) |
2173 | FALSE, FALSE) == NULL)) |
2300 | output = FALSE; |
2174 | output = FALSE; |
2301 | else if ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0) |
2175 | else if ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0) |
2302 | { |
2176 | { |
2303 | /* If this symbol is marked as occurring now, rather |
2177 | /* If this symbol is marked as occurring now, rather |
2304 | than at the end, output it now. This is used for |
2178 | than at the end, output it now. This is used for |
2305 | COFF C_EXT FCN symbols. FIXME: There must be a |
2179 | COFF C_EXT FCN symbols. FIXME: There must be a |
2306 | better way. */ |
2180 | better way. */ |
2307 | if (bfd_asymbol_bfd (sym) == input_bfd |
2181 | if (bfd_asymbol_bfd (sym) == input_bfd |
2308 | && (sym->flags & BSF_NOT_AT_END) != 0) |
2182 | && (sym->flags & BSF_NOT_AT_END) != 0) |
2309 | output = TRUE; |
2183 | output = TRUE; |
2310 | else |
2184 | else |
2311 | output = FALSE; |
2185 | output = FALSE; |
2312 | } |
2186 | } |
2313 | else if (bfd_is_ind_section (sym->section)) |
2187 | else if (bfd_is_ind_section (sym->section)) |
2314 | output = FALSE; |
2188 | output = FALSE; |
2315 | else if ((sym->flags & BSF_DEBUGGING) != 0) |
2189 | else if ((sym->flags & BSF_DEBUGGING) != 0) |
2316 | { |
2190 | { |
2317 | if (info->strip == strip_none) |
2191 | if (info->strip == strip_none) |
2318 | output = TRUE; |
2192 | output = TRUE; |
2319 | else |
2193 | else |
2320 | output = FALSE; |
2194 | output = FALSE; |
2321 | } |
2195 | } |
2322 | else if (bfd_is_und_section (sym->section) |
2196 | else if (bfd_is_und_section (sym->section) |
2323 | || bfd_is_com_section (sym->section)) |
2197 | || bfd_is_com_section (sym->section)) |
2324 | output = FALSE; |
2198 | output = FALSE; |
2325 | else if ((sym->flags & BSF_LOCAL) != 0) |
2199 | else if ((sym->flags & BSF_LOCAL) != 0) |
2326 | { |
2200 | { |
2327 | if ((sym->flags & BSF_WARNING) != 0) |
2201 | if ((sym->flags & BSF_WARNING) != 0) |
2328 | output = FALSE; |
2202 | output = FALSE; |
2329 | else |
2203 | else |
2330 | { |
2204 | { |
2331 | switch (info->discard) |
2205 | switch (info->discard) |
2332 | { |
2206 | { |
2333 | default: |
2207 | default: |
2334 | case discard_all: |
2208 | case discard_all: |
2335 | output = FALSE; |
2209 | output = FALSE; |
2336 | break; |
2210 | break; |
2337 | case discard_sec_merge: |
2211 | case discard_sec_merge: |
2338 | output = TRUE; |
2212 | output = TRUE; |
2339 | if (info->relocatable |
2213 | if (bfd_link_relocatable (info) |
2340 | || ! (sym->section->flags & SEC_MERGE)) |
2214 | || ! (sym->section->flags & SEC_MERGE)) |
2341 | break; |
2215 | break; |
2342 | /* FALLTHROUGH */ |
2216 | /* FALLTHROUGH */ |
2343 | case discard_l: |
2217 | case discard_l: |
2344 | if (bfd_is_local_label (input_bfd, sym)) |
2218 | if (bfd_is_local_label (input_bfd, sym)) |
2345 | output = FALSE; |
2219 | output = FALSE; |
2346 | else |
2220 | else |
2347 | output = TRUE; |
2221 | output = TRUE; |
2348 | break; |
2222 | break; |
2349 | case discard_none: |
2223 | case discard_none: |
2350 | output = TRUE; |
2224 | output = TRUE; |
2351 | break; |
2225 | break; |
2352 | } |
2226 | } |
2353 | } |
2227 | } |
2354 | } |
2228 | } |
2355 | else if ((sym->flags & BSF_CONSTRUCTOR)) |
2229 | else if ((sym->flags & BSF_CONSTRUCTOR)) |
2356 | { |
2230 | { |
2357 | if (info->strip != strip_all) |
2231 | if (info->strip != strip_all) |
2358 | output = TRUE; |
2232 | output = TRUE; |
2359 | else |
2233 | else |
2360 | output = FALSE; |
2234 | output = FALSE; |
2361 | } |
2235 | } |
2362 | else if (sym->flags == 0 |
2236 | else if (sym->flags == 0 |
2363 | && (sym->section->owner->flags & BFD_PLUGIN) != 0) |
2237 | && (sym->section->owner->flags & BFD_PLUGIN) != 0) |
2364 | /* LTO doesn't set symbol information. We get here with the |
2238 | /* LTO doesn't set symbol information. We get here with the |
2365 | generic linker for a symbol that was "common" but no longer |
2239 | generic linker for a symbol that was "common" but no longer |
2366 | needs to be global. */ |
2240 | needs to be global. */ |
2367 | output = FALSE; |
2241 | output = FALSE; |
2368 | else |
2242 | else |
2369 | abort (); |
2243 | abort (); |
2370 | 2244 | ||
2371 | /* If this symbol is in a section which is not being included |
2245 | /* If this symbol is in a section which is not being included |
2372 | in the output file, then we don't want to output the |
2246 | in the output file, then we don't want to output the |
2373 | symbol. */ |
2247 | symbol. */ |
2374 | if (!bfd_is_abs_section (sym->section) |
2248 | if (!bfd_is_abs_section (sym->section) |
2375 | && bfd_section_removed_from_list (output_bfd, |
2249 | && bfd_section_removed_from_list (output_bfd, |
2376 | sym->section->output_section)) |
2250 | sym->section->output_section)) |
2377 | output = FALSE; |
2251 | output = FALSE; |
2378 | 2252 | ||
2379 | if (output) |
2253 | if (output) |
2380 | { |
2254 | { |
2381 | if (! generic_add_output_symbol (output_bfd, psymalloc, sym)) |
2255 | if (! generic_add_output_symbol (output_bfd, psymalloc, sym)) |
2382 | return FALSE; |
2256 | return FALSE; |
2383 | if (h != NULL) |
2257 | if (h != NULL) |
2384 | h->written = TRUE; |
2258 | h->written = TRUE; |
2385 | } |
2259 | } |
2386 | } |
2260 | } |
2387 | 2261 | ||
2388 | return TRUE; |
2262 | return TRUE; |
2389 | } |
2263 | } |
2390 | 2264 | ||
2391 | /* Set the section and value of a generic BFD symbol based on a linker |
2265 | /* Set the section and value of a generic BFD symbol based on a linker |
2392 | hash table entry. */ |
2266 | hash table entry. */ |
2393 | 2267 | ||
2394 | static void |
2268 | static void |
2395 | set_symbol_from_hash (asymbol *sym, struct bfd_link_hash_entry *h) |
2269 | set_symbol_from_hash (asymbol *sym, struct bfd_link_hash_entry *h) |
2396 | { |
2270 | { |
2397 | switch (h->type) |
2271 | switch (h->type) |
2398 | { |
2272 | { |
2399 | default: |
2273 | default: |
2400 | abort (); |
2274 | abort (); |
2401 | break; |
2275 | break; |
2402 | case bfd_link_hash_new: |
2276 | case bfd_link_hash_new: |
2403 | /* This can happen when a constructor symbol is seen but we are |
2277 | /* This can happen when a constructor symbol is seen but we are |
2404 | not building constructors. */ |
2278 | not building constructors. */ |
2405 | if (sym->section != NULL) |
2279 | if (sym->section != NULL) |
2406 | { |
2280 | { |
2407 | BFD_ASSERT ((sym->flags & BSF_CONSTRUCTOR) != 0); |
2281 | BFD_ASSERT ((sym->flags & BSF_CONSTRUCTOR) != 0); |
2408 | } |
2282 | } |
2409 | else |
2283 | else |
2410 | { |
2284 | { |
2411 | sym->flags |= BSF_CONSTRUCTOR; |
2285 | sym->flags |= BSF_CONSTRUCTOR; |
2412 | sym->section = bfd_abs_section_ptr; |
2286 | sym->section = bfd_abs_section_ptr; |
2413 | sym->value = 0; |
2287 | sym->value = 0; |
2414 | } |
2288 | } |
2415 | break; |
2289 | break; |
2416 | case bfd_link_hash_undefined: |
2290 | case bfd_link_hash_undefined: |
2417 | sym->section = bfd_und_section_ptr; |
2291 | sym->section = bfd_und_section_ptr; |
2418 | sym->value = 0; |
2292 | sym->value = 0; |
2419 | break; |
2293 | break; |
2420 | case bfd_link_hash_undefweak: |
2294 | case bfd_link_hash_undefweak: |
2421 | sym->section = bfd_und_section_ptr; |
2295 | sym->section = bfd_und_section_ptr; |
2422 | sym->value = 0; |
2296 | sym->value = 0; |
2423 | sym->flags |= BSF_WEAK; |
2297 | sym->flags |= BSF_WEAK; |
2424 | break; |
2298 | break; |
2425 | case bfd_link_hash_defined: |
2299 | case bfd_link_hash_defined: |
2426 | sym->section = h->u.def.section; |
2300 | sym->section = h->u.def.section; |
2427 | sym->value = h->u.def.value; |
2301 | sym->value = h->u.def.value; |
2428 | break; |
2302 | break; |
2429 | case bfd_link_hash_defweak: |
2303 | case bfd_link_hash_defweak: |
2430 | sym->flags |= BSF_WEAK; |
2304 | sym->flags |= BSF_WEAK; |
2431 | sym->section = h->u.def.section; |
2305 | sym->section = h->u.def.section; |
2432 | sym->value = h->u.def.value; |
2306 | sym->value = h->u.def.value; |
2433 | break; |
2307 | break; |
2434 | case bfd_link_hash_common: |
2308 | case bfd_link_hash_common: |
2435 | sym->value = h->u.c.size; |
2309 | sym->value = h->u.c.size; |
2436 | if (sym->section == NULL) |
2310 | if (sym->section == NULL) |
2437 | sym->section = bfd_com_section_ptr; |
2311 | sym->section = bfd_com_section_ptr; |
2438 | else if (! bfd_is_com_section (sym->section)) |
2312 | else if (! bfd_is_com_section (sym->section)) |
2439 | { |
2313 | { |
2440 | BFD_ASSERT (bfd_is_und_section (sym->section)); |
2314 | BFD_ASSERT (bfd_is_und_section (sym->section)); |
2441 | sym->section = bfd_com_section_ptr; |
2315 | sym->section = bfd_com_section_ptr; |
2442 | } |
2316 | } |
2443 | /* Do not set the section; see _bfd_generic_link_output_symbols. */ |
2317 | /* Do not set the section; see _bfd_generic_link_output_symbols. */ |
2444 | break; |
2318 | break; |
2445 | case bfd_link_hash_indirect: |
2319 | case bfd_link_hash_indirect: |
2446 | case bfd_link_hash_warning: |
2320 | case bfd_link_hash_warning: |
2447 | /* FIXME: What should we do here? */ |
2321 | /* FIXME: What should we do here? */ |
2448 | break; |
2322 | break; |
2449 | } |
2323 | } |
2450 | } |
2324 | } |
2451 | 2325 | ||
2452 | /* Write out a global symbol, if it hasn't already been written out. |
2326 | /* Write out a global symbol, if it hasn't already been written out. |
2453 | This is called for each symbol in the hash table. */ |
2327 | This is called for each symbol in the hash table. */ |
2454 | 2328 | ||
2455 | bfd_boolean |
2329 | bfd_boolean |
2456 | _bfd_generic_link_write_global_symbol (struct generic_link_hash_entry *h, |
2330 | _bfd_generic_link_write_global_symbol (struct generic_link_hash_entry *h, |
2457 | void *data) |
2331 | void *data) |
2458 | { |
2332 | { |
2459 | struct generic_write_global_symbol_info *wginfo = |
2333 | struct generic_write_global_symbol_info *wginfo = |
2460 | (struct generic_write_global_symbol_info *) data; |
2334 | (struct generic_write_global_symbol_info *) data; |
2461 | asymbol *sym; |
2335 | asymbol *sym; |
2462 | 2336 | ||
2463 | if (h->written) |
2337 | if (h->written) |
2464 | return TRUE; |
2338 | return TRUE; |
2465 | 2339 | ||
2466 | h->written = TRUE; |
2340 | h->written = TRUE; |
2467 | 2341 | ||
2468 | if (wginfo->info->strip == strip_all |
2342 | if (wginfo->info->strip == strip_all |
2469 | || (wginfo->info->strip == strip_some |
2343 | || (wginfo->info->strip == strip_some |
2470 | && bfd_hash_lookup (wginfo->info->keep_hash, h->root.root.string, |
2344 | && bfd_hash_lookup (wginfo->info->keep_hash, h->root.root.string, |
2471 | FALSE, FALSE) == NULL)) |
2345 | FALSE, FALSE) == NULL)) |
2472 | return TRUE; |
2346 | return TRUE; |
2473 | 2347 | ||
2474 | if (h->sym != NULL) |
2348 | if (h->sym != NULL) |
2475 | sym = h->sym; |
2349 | sym = h->sym; |
2476 | else |
2350 | else |
2477 | { |
2351 | { |
2478 | sym = bfd_make_empty_symbol (wginfo->output_bfd); |
2352 | sym = bfd_make_empty_symbol (wginfo->output_bfd); |
2479 | if (!sym) |
2353 | if (!sym) |
2480 | return FALSE; |
2354 | return FALSE; |
2481 | sym->name = h->root.root.string; |
2355 | sym->name = h->root.root.string; |
2482 | sym->flags = 0; |
2356 | sym->flags = 0; |
2483 | } |
2357 | } |
2484 | 2358 | ||
2485 | set_symbol_from_hash (sym, &h->root); |
2359 | set_symbol_from_hash (sym, &h->root); |
2486 | 2360 | ||
2487 | sym->flags |= BSF_GLOBAL; |
2361 | sym->flags |= BSF_GLOBAL; |
2488 | 2362 | ||
2489 | if (! generic_add_output_symbol (wginfo->output_bfd, wginfo->psymalloc, |
2363 | if (! generic_add_output_symbol (wginfo->output_bfd, wginfo->psymalloc, |
2490 | sym)) |
2364 | sym)) |
2491 | { |
2365 | { |
2492 | /* FIXME: No way to return failure. */ |
2366 | /* FIXME: No way to return failure. */ |
2493 | abort (); |
2367 | abort (); |
2494 | } |
2368 | } |
2495 | 2369 | ||
2496 | return TRUE; |
2370 | return TRUE; |
2497 | } |
2371 | } |
2498 | 2372 | ||
2499 | /* Create a relocation. */ |
2373 | /* Create a relocation. */ |
2500 | 2374 | ||
2501 | bfd_boolean |
2375 | bfd_boolean |
2502 | _bfd_generic_reloc_link_order (bfd *abfd, |
2376 | _bfd_generic_reloc_link_order (bfd *abfd, |
2503 | struct bfd_link_info *info, |
2377 | struct bfd_link_info *info, |
2504 | asection *sec, |
2378 | asection *sec, |
2505 | struct bfd_link_order *link_order) |
2379 | struct bfd_link_order *link_order) |
2506 | { |
2380 | { |
2507 | arelent *r; |
2381 | arelent *r; |
2508 | 2382 | ||
2509 | if (! info->relocatable) |
2383 | if (! bfd_link_relocatable (info)) |
2510 | abort (); |
2384 | abort (); |
2511 | if (sec->orelocation == NULL) |
2385 | if (sec->orelocation == NULL) |
2512 | abort (); |
2386 | abort (); |
2513 | 2387 | ||
2514 | r = (arelent *) bfd_alloc (abfd, sizeof (arelent)); |
2388 | r = (arelent *) bfd_alloc (abfd, sizeof (arelent)); |
2515 | if (r == NULL) |
2389 | if (r == NULL) |
2516 | return FALSE; |
2390 | return FALSE; |
2517 | 2391 | ||
2518 | r->address = link_order->offset; |
2392 | r->address = link_order->offset; |
2519 | r->howto = bfd_reloc_type_lookup (abfd, link_order->u.reloc.p->reloc); |
2393 | r->howto = bfd_reloc_type_lookup (abfd, link_order->u.reloc.p->reloc); |
2520 | if (r->howto == 0) |
2394 | if (r->howto == 0) |
2521 | { |
2395 | { |
2522 | bfd_set_error (bfd_error_bad_value); |
2396 | bfd_set_error (bfd_error_bad_value); |
2523 | return FALSE; |
2397 | return FALSE; |
2524 | } |
2398 | } |
2525 | 2399 | ||
2526 | /* Get the symbol to use for the relocation. */ |
2400 | /* Get the symbol to use for the relocation. */ |
2527 | if (link_order->type == bfd_section_reloc_link_order) |
2401 | if (link_order->type == bfd_section_reloc_link_order) |
2528 | r->sym_ptr_ptr = link_order->u.reloc.p->u.section->symbol_ptr_ptr; |
2402 | r->sym_ptr_ptr = link_order->u.reloc.p->u.section->symbol_ptr_ptr; |
2529 | else |
2403 | else |
2530 | { |
2404 | { |
2531 | struct generic_link_hash_entry *h; |
2405 | struct generic_link_hash_entry *h; |
2532 | 2406 | ||
2533 | h = ((struct generic_link_hash_entry *) |
2407 | h = ((struct generic_link_hash_entry *) |
2534 | bfd_wrapped_link_hash_lookup (abfd, info, |
2408 | bfd_wrapped_link_hash_lookup (abfd, info, |
2535 | link_order->u.reloc.p->u.name, |
2409 | link_order->u.reloc.p->u.name, |
2536 | FALSE, FALSE, TRUE)); |
2410 | FALSE, FALSE, TRUE)); |
2537 | if (h == NULL |
2411 | if (h == NULL |
2538 | || ! h->written) |
2412 | || ! h->written) |
2539 | { |
2413 | { |
2540 | if (! ((*info->callbacks->unattached_reloc) |
2414 | if (! ((*info->callbacks->unattached_reloc) |
2541 | (info, link_order->u.reloc.p->u.name, NULL, NULL, 0))) |
2415 | (info, link_order->u.reloc.p->u.name, NULL, NULL, 0))) |
2542 | return FALSE; |
2416 | return FALSE; |
2543 | bfd_set_error (bfd_error_bad_value); |
2417 | bfd_set_error (bfd_error_bad_value); |
2544 | return FALSE; |
2418 | return FALSE; |
2545 | } |
2419 | } |
2546 | r->sym_ptr_ptr = &h->sym; |
2420 | r->sym_ptr_ptr = &h->sym; |
2547 | } |
2421 | } |
2548 | 2422 | ||
2549 | /* If this is an inplace reloc, write the addend to the object file. |
2423 | /* If this is an inplace reloc, write the addend to the object file. |
2550 | Otherwise, store it in the reloc addend. */ |
2424 | Otherwise, store it in the reloc addend. */ |
2551 | if (! r->howto->partial_inplace) |
2425 | if (! r->howto->partial_inplace) |
2552 | r->addend = link_order->u.reloc.p->addend; |
2426 | r->addend = link_order->u.reloc.p->addend; |
2553 | else |
2427 | else |
2554 | { |
2428 | { |
2555 | bfd_size_type size; |
2429 | bfd_size_type size; |
2556 | bfd_reloc_status_type rstat; |
2430 | bfd_reloc_status_type rstat; |
2557 | bfd_byte *buf; |
2431 | bfd_byte *buf; |
2558 | bfd_boolean ok; |
2432 | bfd_boolean ok; |
2559 | file_ptr loc; |
2433 | file_ptr loc; |
2560 | 2434 | ||
2561 | size = bfd_get_reloc_size (r->howto); |
2435 | size = bfd_get_reloc_size (r->howto); |
2562 | buf = (bfd_byte *) bfd_zmalloc (size); |
2436 | buf = (bfd_byte *) bfd_zmalloc (size); |
2563 | if (buf == NULL) |
2437 | if (buf == NULL && size != 0) |
2564 | return FALSE; |
2438 | return FALSE; |
2565 | rstat = _bfd_relocate_contents (r->howto, abfd, |
2439 | rstat = _bfd_relocate_contents (r->howto, abfd, |
2566 | (bfd_vma) link_order->u.reloc.p->addend, |
2440 | (bfd_vma) link_order->u.reloc.p->addend, |
2567 | buf); |
2441 | buf); |
2568 | switch (rstat) |
2442 | switch (rstat) |
2569 | { |
2443 | { |
2570 | case bfd_reloc_ok: |
2444 | case bfd_reloc_ok: |
2571 | break; |
2445 | break; |
2572 | default: |
2446 | default: |
2573 | case bfd_reloc_outofrange: |
2447 | case bfd_reloc_outofrange: |
2574 | abort (); |
2448 | abort (); |
2575 | case bfd_reloc_overflow: |
2449 | case bfd_reloc_overflow: |
2576 | if (! ((*info->callbacks->reloc_overflow) |
2450 | if (! ((*info->callbacks->reloc_overflow) |
2577 | (info, NULL, |
2451 | (info, NULL, |
2578 | (link_order->type == bfd_section_reloc_link_order |
2452 | (link_order->type == bfd_section_reloc_link_order |
2579 | ? bfd_section_name (abfd, link_order->u.reloc.p->u.section) |
2453 | ? bfd_section_name (abfd, link_order->u.reloc.p->u.section) |
2580 | : link_order->u.reloc.p->u.name), |
2454 | : link_order->u.reloc.p->u.name), |
2581 | r->howto->name, link_order->u.reloc.p->addend, |
2455 | r->howto->name, link_order->u.reloc.p->addend, |
2582 | NULL, NULL, 0))) |
2456 | NULL, NULL, 0))) |
2583 | { |
2457 | { |
2584 | free (buf); |
2458 | free (buf); |
2585 | return FALSE; |
2459 | return FALSE; |
2586 | } |
2460 | } |
2587 | break; |
2461 | break; |
2588 | } |
2462 | } |
2589 | loc = link_order->offset * bfd_octets_per_byte (abfd); |
2463 | loc = link_order->offset * bfd_octets_per_byte (abfd); |
2590 | ok = bfd_set_section_contents (abfd, sec, buf, loc, size); |
2464 | ok = bfd_set_section_contents (abfd, sec, buf, loc, size); |
2591 | free (buf); |
2465 | free (buf); |
2592 | if (! ok) |
2466 | if (! ok) |
2593 | return FALSE; |
2467 | return FALSE; |
2594 | 2468 | ||
2595 | r->addend = 0; |
2469 | r->addend = 0; |
2596 | } |
2470 | } |
2597 | 2471 | ||
2598 | sec->orelocation[sec->reloc_count] = r; |
2472 | sec->orelocation[sec->reloc_count] = r; |
2599 | ++sec->reloc_count; |
2473 | ++sec->reloc_count; |
2600 | 2474 | ||
2601 | return TRUE; |
2475 | return TRUE; |
2602 | } |
2476 | } |
2603 | 2477 | ||
2604 | /* Allocate a new link_order for a section. */ |
2478 | /* Allocate a new link_order for a section. */ |
2605 | 2479 | ||
2606 | struct bfd_link_order * |
2480 | struct bfd_link_order * |
2607 | bfd_new_link_order (bfd *abfd, asection *section) |
2481 | bfd_new_link_order (bfd *abfd, asection *section) |
2608 | { |
2482 | { |
2609 | bfd_size_type amt = sizeof (struct bfd_link_order); |
2483 | bfd_size_type amt = sizeof (struct bfd_link_order); |
2610 | struct bfd_link_order *new_lo; |
2484 | struct bfd_link_order *new_lo; |
2611 | 2485 | ||
2612 | new_lo = (struct bfd_link_order *) bfd_zalloc (abfd, amt); |
2486 | new_lo = (struct bfd_link_order *) bfd_zalloc (abfd, amt); |
2613 | if (!new_lo) |
2487 | if (!new_lo) |
2614 | return NULL; |
2488 | return NULL; |
2615 | 2489 | ||
2616 | new_lo->type = bfd_undefined_link_order; |
2490 | new_lo->type = bfd_undefined_link_order; |
2617 | 2491 | ||
2618 | if (section->map_tail.link_order != NULL) |
2492 | if (section->map_tail.link_order != NULL) |
2619 | section->map_tail.link_order->next = new_lo; |
2493 | section->map_tail.link_order->next = new_lo; |
2620 | else |
2494 | else |
2621 | section->map_head.link_order = new_lo; |
2495 | section->map_head.link_order = new_lo; |
2622 | section->map_tail.link_order = new_lo; |
2496 | section->map_tail.link_order = new_lo; |
2623 | 2497 | ||
2624 | return new_lo; |
2498 | return new_lo; |
2625 | } |
2499 | } |
2626 | 2500 | ||
2627 | /* Default link order processing routine. Note that we can not handle |
2501 | /* Default link order processing routine. Note that we can not handle |
2628 | the reloc_link_order types here, since they depend upon the details |
2502 | the reloc_link_order types here, since they depend upon the details |
2629 | of how the particular backends generates relocs. */ |
2503 | of how the particular backends generates relocs. */ |
2630 | 2504 | ||
2631 | bfd_boolean |
2505 | bfd_boolean |
2632 | _bfd_default_link_order (bfd *abfd, |
2506 | _bfd_default_link_order (bfd *abfd, |
2633 | struct bfd_link_info *info, |
2507 | struct bfd_link_info *info, |
2634 | asection *sec, |
2508 | asection *sec, |
2635 | struct bfd_link_order *link_order) |
2509 | struct bfd_link_order *link_order) |
2636 | { |
2510 | { |
2637 | switch (link_order->type) |
2511 | switch (link_order->type) |
2638 | { |
2512 | { |
2639 | case bfd_undefined_link_order: |
2513 | case bfd_undefined_link_order: |
2640 | case bfd_section_reloc_link_order: |
2514 | case bfd_section_reloc_link_order: |
2641 | case bfd_symbol_reloc_link_order: |
2515 | case bfd_symbol_reloc_link_order: |
2642 | default: |
2516 | default: |
2643 | abort (); |
2517 | abort (); |
2644 | case bfd_indirect_link_order: |
2518 | case bfd_indirect_link_order: |
2645 | return default_indirect_link_order (abfd, info, sec, link_order, |
2519 | return default_indirect_link_order (abfd, info, sec, link_order, |
2646 | FALSE); |
2520 | FALSE); |
2647 | case bfd_data_link_order: |
2521 | case bfd_data_link_order: |
2648 | return default_data_link_order (abfd, info, sec, link_order); |
2522 | return default_data_link_order (abfd, info, sec, link_order); |
2649 | } |
2523 | } |
2650 | } |
2524 | } |
2651 | 2525 | ||
2652 | /* Default routine to handle a bfd_data_link_order. */ |
2526 | /* Default routine to handle a bfd_data_link_order. */ |
2653 | 2527 | ||
2654 | static bfd_boolean |
2528 | static bfd_boolean |
2655 | default_data_link_order (bfd *abfd, |
2529 | default_data_link_order (bfd *abfd, |
2656 | struct bfd_link_info *info ATTRIBUTE_UNUSED, |
2530 | struct bfd_link_info *info ATTRIBUTE_UNUSED, |
2657 | asection *sec, |
2531 | asection *sec, |
2658 | struct bfd_link_order *link_order) |
2532 | struct bfd_link_order *link_order) |
2659 | { |
2533 | { |
2660 | bfd_size_type size; |
2534 | bfd_size_type size; |
2661 | size_t fill_size; |
2535 | size_t fill_size; |
2662 | bfd_byte *fill; |
2536 | bfd_byte *fill; |
2663 | file_ptr loc; |
2537 | file_ptr loc; |
2664 | bfd_boolean result; |
2538 | bfd_boolean result; |
2665 | 2539 | ||
2666 | BFD_ASSERT ((sec->flags & SEC_HAS_CONTENTS) != 0); |
2540 | BFD_ASSERT ((sec->flags & SEC_HAS_CONTENTS) != 0); |
2667 | 2541 | ||
2668 | size = link_order->size; |
2542 | size = link_order->size; |
2669 | if (size == 0) |
2543 | if (size == 0) |
2670 | return TRUE; |
2544 | return TRUE; |
2671 | 2545 | ||
2672 | fill = link_order->u.data.contents; |
2546 | fill = link_order->u.data.contents; |
2673 | fill_size = link_order->u.data.size; |
2547 | fill_size = link_order->u.data.size; |
2674 | if (fill_size == 0) |
2548 | if (fill_size == 0) |
2675 | { |
2549 | { |
2676 | fill = abfd->arch_info->fill (size, bfd_big_endian (abfd), |
2550 | fill = abfd->arch_info->fill (size, bfd_big_endian (abfd), |
2677 | (sec->flags & SEC_CODE) != 0); |
2551 | (sec->flags & SEC_CODE) != 0); |
2678 | if (fill == NULL) |
2552 | if (fill == NULL) |
2679 | return FALSE; |
2553 | return FALSE; |
2680 | } |
2554 | } |
2681 | else if (fill_size < size) |
2555 | else if (fill_size < size) |
2682 | { |
2556 | { |
2683 | bfd_byte *p; |
2557 | bfd_byte *p; |
2684 | fill = (bfd_byte *) bfd_malloc (size); |
2558 | fill = (bfd_byte *) bfd_malloc (size); |
2685 | if (fill == NULL) |
2559 | if (fill == NULL) |
2686 | return FALSE; |
2560 | return FALSE; |
2687 | p = fill; |
2561 | p = fill; |
2688 | if (fill_size == 1) |
2562 | if (fill_size == 1) |
2689 | memset (p, (int) link_order->u.data.contents[0], (size_t) size); |
2563 | memset (p, (int) link_order->u.data.contents[0], (size_t) size); |
2690 | else |
2564 | else |
2691 | { |
2565 | { |
2692 | do |
2566 | do |
2693 | { |
2567 | { |
2694 | memcpy (p, link_order->u.data.contents, fill_size); |
2568 | memcpy (p, link_order->u.data.contents, fill_size); |
2695 | p += fill_size; |
2569 | p += fill_size; |
2696 | size -= fill_size; |
2570 | size -= fill_size; |
2697 | } |
2571 | } |
2698 | while (size >= fill_size); |
2572 | while (size >= fill_size); |
2699 | if (size != 0) |
2573 | if (size != 0) |
2700 | memcpy (p, link_order->u.data.contents, (size_t) size); |
2574 | memcpy (p, link_order->u.data.contents, (size_t) size); |
2701 | size = link_order->size; |
2575 | size = link_order->size; |
2702 | } |
2576 | } |
2703 | } |
2577 | } |
2704 | 2578 | ||
2705 | loc = link_order->offset * bfd_octets_per_byte (abfd); |
2579 | loc = link_order->offset * bfd_octets_per_byte (abfd); |
2706 | result = bfd_set_section_contents (abfd, sec, fill, loc, size); |
2580 | result = bfd_set_section_contents (abfd, sec, fill, loc, size); |
2707 | 2581 | ||
2708 | if (fill != link_order->u.data.contents) |
2582 | if (fill != link_order->u.data.contents) |
2709 | free (fill); |
2583 | free (fill); |
2710 | return result; |
2584 | return result; |
2711 | } |
2585 | } |
2712 | 2586 | ||
2713 | /* Default routine to handle a bfd_indirect_link_order. */ |
2587 | /* Default routine to handle a bfd_indirect_link_order. */ |
2714 | 2588 | ||
2715 | static bfd_boolean |
2589 | static bfd_boolean |
2716 | default_indirect_link_order (bfd *output_bfd, |
2590 | default_indirect_link_order (bfd *output_bfd, |
2717 | struct bfd_link_info *info, |
2591 | struct bfd_link_info *info, |
2718 | asection *output_section, |
2592 | asection *output_section, |
2719 | struct bfd_link_order *link_order, |
2593 | struct bfd_link_order *link_order, |
2720 | bfd_boolean generic_linker) |
2594 | bfd_boolean generic_linker) |
2721 | { |
2595 | { |
2722 | asection *input_section; |
2596 | asection *input_section; |
2723 | bfd *input_bfd; |
2597 | bfd *input_bfd; |
2724 | bfd_byte *contents = NULL; |
2598 | bfd_byte *contents = NULL; |
2725 | bfd_byte *new_contents; |
2599 | bfd_byte *new_contents; |
2726 | bfd_size_type sec_size; |
2600 | bfd_size_type sec_size; |
2727 | file_ptr loc; |
2601 | file_ptr loc; |
2728 | 2602 | ||
2729 | BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0); |
2603 | BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0); |
2730 | 2604 | ||
2731 | input_section = link_order->u.indirect.section; |
2605 | input_section = link_order->u.indirect.section; |
2732 | input_bfd = input_section->owner; |
2606 | input_bfd = input_section->owner; |
2733 | if (input_section->size == 0) |
2607 | if (input_section->size == 0) |
2734 | return TRUE; |
2608 | return TRUE; |
2735 | 2609 | ||
2736 | BFD_ASSERT (input_section->output_section == output_section); |
2610 | BFD_ASSERT (input_section->output_section == output_section); |
2737 | BFD_ASSERT (input_section->output_offset == link_order->offset); |
2611 | BFD_ASSERT (input_section->output_offset == link_order->offset); |
2738 | BFD_ASSERT (input_section->size == link_order->size); |
2612 | BFD_ASSERT (input_section->size == link_order->size); |
2739 | 2613 | ||
2740 | if (info->relocatable |
2614 | if (bfd_link_relocatable (info) |
2741 | && input_section->reloc_count > 0 |
2615 | && input_section->reloc_count > 0 |
2742 | && output_section->orelocation == NULL) |
2616 | && output_section->orelocation == NULL) |
2743 | { |
2617 | { |
2744 | /* Space has not been allocated for the output relocations. |
2618 | /* Space has not been allocated for the output relocations. |
2745 | This can happen when we are called by a specific backend |
2619 | This can happen when we are called by a specific backend |
2746 | because somebody is attempting to link together different |
2620 | because somebody is attempting to link together different |
2747 | types of object files. Handling this case correctly is |
2621 | types of object files. Handling this case correctly is |
2748 | difficult, and sometimes impossible. */ |
2622 | difficult, and sometimes impossible. */ |
2749 | (*_bfd_error_handler) |
2623 | (*_bfd_error_handler) |
2750 | (_("Attempt to do relocatable link with %s input and %s output"), |
2624 | (_("Attempt to do relocatable link with %s input and %s output"), |
2751 | bfd_get_target (input_bfd), bfd_get_target (output_bfd)); |
2625 | bfd_get_target (input_bfd), bfd_get_target (output_bfd)); |
2752 | bfd_set_error (bfd_error_wrong_format); |
2626 | bfd_set_error (bfd_error_wrong_format); |
2753 | return FALSE; |
2627 | return FALSE; |
2754 | } |
2628 | } |
2755 | 2629 | ||
2756 | if (! generic_linker) |
2630 | if (! generic_linker) |
2757 | { |
2631 | { |
2758 | asymbol **sympp; |
2632 | asymbol **sympp; |
2759 | asymbol **symppend; |
2633 | asymbol **symppend; |
2760 | 2634 | ||
2761 | /* Get the canonical symbols. The generic linker will always |
2635 | /* Get the canonical symbols. The generic linker will always |
2762 | have retrieved them by this point, but we are being called by |
2636 | have retrieved them by this point, but we are being called by |
2763 | a specific linker, presumably because we are linking |
2637 | a specific linker, presumably because we are linking |
2764 | different types of object files together. */ |
2638 | different types of object files together. */ |
2765 | if (!bfd_generic_link_read_symbols (input_bfd)) |
2639 | if (!bfd_generic_link_read_symbols (input_bfd)) |
2766 | return FALSE; |
2640 | return FALSE; |
2767 | 2641 | ||
2768 | /* Since we have been called by a specific linker, rather than |
2642 | /* Since we have been called by a specific linker, rather than |
2769 | the generic linker, the values of the symbols will not be |
2643 | the generic linker, the values of the symbols will not be |
2770 | right. They will be the values as seen in the input file, |
2644 | right. They will be the values as seen in the input file, |
2771 | not the values of the final link. We need to fix them up |
2645 | not the values of the final link. We need to fix them up |
2772 | before we can relocate the section. */ |
2646 | before we can relocate the section. */ |
2773 | sympp = _bfd_generic_link_get_symbols (input_bfd); |
2647 | sympp = _bfd_generic_link_get_symbols (input_bfd); |
2774 | symppend = sympp + _bfd_generic_link_get_symcount (input_bfd); |
2648 | symppend = sympp + _bfd_generic_link_get_symcount (input_bfd); |
2775 | for (; sympp < symppend; sympp++) |
2649 | for (; sympp < symppend; sympp++) |
2776 | { |
2650 | { |
2777 | asymbol *sym; |
2651 | asymbol *sym; |
2778 | struct bfd_link_hash_entry *h; |
2652 | struct bfd_link_hash_entry *h; |
2779 | 2653 | ||
2780 | sym = *sympp; |
2654 | sym = *sympp; |
2781 | 2655 | ||
2782 | if ((sym->flags & (BSF_INDIRECT |
2656 | if ((sym->flags & (BSF_INDIRECT |
2783 | | BSF_WARNING |
2657 | | BSF_WARNING |
2784 | | BSF_GLOBAL |
2658 | | BSF_GLOBAL |
2785 | | BSF_CONSTRUCTOR |
2659 | | BSF_CONSTRUCTOR |
2786 | | BSF_WEAK)) != 0 |
2660 | | BSF_WEAK)) != 0 |
2787 | || bfd_is_und_section (bfd_get_section (sym)) |
2661 | || bfd_is_und_section (bfd_get_section (sym)) |
2788 | || bfd_is_com_section (bfd_get_section (sym)) |
2662 | || bfd_is_com_section (bfd_get_section (sym)) |
2789 | || bfd_is_ind_section (bfd_get_section (sym))) |
2663 | || bfd_is_ind_section (bfd_get_section (sym))) |
2790 | { |
2664 | { |
2791 | /* sym->udata may have been set by |
2665 | /* sym->udata may have been set by |
2792 | generic_link_add_symbol_list. */ |
2666 | generic_link_add_symbol_list. */ |
2793 | if (sym->udata.p != NULL) |
2667 | if (sym->udata.p != NULL) |
2794 | h = (struct bfd_link_hash_entry *) sym->udata.p; |
2668 | h = (struct bfd_link_hash_entry *) sym->udata.p; |
2795 | else if (bfd_is_und_section (bfd_get_section (sym))) |
2669 | else if (bfd_is_und_section (bfd_get_section (sym))) |
2796 | h = bfd_wrapped_link_hash_lookup (output_bfd, info, |
2670 | h = bfd_wrapped_link_hash_lookup (output_bfd, info, |
2797 | bfd_asymbol_name (sym), |
2671 | bfd_asymbol_name (sym), |
2798 | FALSE, FALSE, TRUE); |
2672 | FALSE, FALSE, TRUE); |
2799 | else |
2673 | else |
2800 | h = bfd_link_hash_lookup (info->hash, |
2674 | h = bfd_link_hash_lookup (info->hash, |
2801 | bfd_asymbol_name (sym), |
2675 | bfd_asymbol_name (sym), |
2802 | FALSE, FALSE, TRUE); |
2676 | FALSE, FALSE, TRUE); |
2803 | if (h != NULL) |
2677 | if (h != NULL) |
2804 | set_symbol_from_hash (sym, h); |
2678 | set_symbol_from_hash (sym, h); |
2805 | } |
2679 | } |
2806 | } |
2680 | } |
2807 | } |
2681 | } |
2808 | 2682 | ||
2809 | if ((output_section->flags & (SEC_GROUP | SEC_LINKER_CREATED)) == SEC_GROUP |
2683 | if ((output_section->flags & (SEC_GROUP | SEC_LINKER_CREATED)) == SEC_GROUP |
2810 | && input_section->size != 0) |
2684 | && input_section->size != 0) |
2811 | { |
2685 | { |
2812 | /* Group section contents are set by bfd_elf_set_group_contents. */ |
2686 | /* Group section contents are set by bfd_elf_set_group_contents. */ |
2813 | if (!output_bfd->output_has_begun) |
2687 | if (!output_bfd->output_has_begun) |
2814 | { |
2688 | { |
2815 | /* FIXME: This hack ensures bfd_elf_set_group_contents is called. */ |
2689 | /* FIXME: This hack ensures bfd_elf_set_group_contents is called. */ |
2816 | if (!bfd_set_section_contents (output_bfd, output_section, "", 0, 1)) |
2690 | if (!bfd_set_section_contents (output_bfd, output_section, "", 0, 1)) |
2817 | goto error_return; |
2691 | goto error_return; |
2818 | } |
2692 | } |
2819 | new_contents = output_section->contents; |
2693 | new_contents = output_section->contents; |
2820 | BFD_ASSERT (new_contents != NULL); |
2694 | BFD_ASSERT (new_contents != NULL); |
2821 | BFD_ASSERT (input_section->output_offset == 0); |
2695 | BFD_ASSERT (input_section->output_offset == 0); |
2822 | } |
2696 | } |
2823 | else |
2697 | else |
2824 | { |
2698 | { |
2825 | /* Get and relocate the section contents. */ |
2699 | /* Get and relocate the section contents. */ |
2826 | sec_size = (input_section->rawsize > input_section->size |
2700 | sec_size = (input_section->rawsize > input_section->size |
2827 | ? input_section->rawsize |
2701 | ? input_section->rawsize |
2828 | : input_section->size); |
2702 | : input_section->size); |
2829 | contents = (bfd_byte *) bfd_malloc (sec_size); |
2703 | contents = (bfd_byte *) bfd_malloc (sec_size); |
2830 | if (contents == NULL && sec_size != 0) |
2704 | if (contents == NULL && sec_size != 0) |
2831 | goto error_return; |
2705 | goto error_return; |
2832 | new_contents = (bfd_get_relocated_section_contents |
2706 | new_contents = (bfd_get_relocated_section_contents |
2833 | (output_bfd, info, link_order, contents, |
2707 | (output_bfd, info, link_order, contents, |
2834 | info->relocatable, |
2708 | bfd_link_relocatable (info), |
2835 | _bfd_generic_link_get_symbols (input_bfd))); |
2709 | _bfd_generic_link_get_symbols (input_bfd))); |
2836 | if (!new_contents) |
2710 | if (!new_contents) |
2837 | goto error_return; |
2711 | goto error_return; |
2838 | } |
2712 | } |
2839 | 2713 | ||
2840 | /* Output the section contents. */ |
2714 | /* Output the section contents. */ |
2841 | loc = input_section->output_offset * bfd_octets_per_byte (output_bfd); |
2715 | loc = input_section->output_offset * bfd_octets_per_byte (output_bfd); |
2842 | if (! bfd_set_section_contents (output_bfd, output_section, |
2716 | if (! bfd_set_section_contents (output_bfd, output_section, |
2843 | new_contents, loc, input_section->size)) |
2717 | new_contents, loc, input_section->size)) |
2844 | goto error_return; |
2718 | goto error_return; |
2845 | 2719 | ||
2846 | if (contents != NULL) |
2720 | if (contents != NULL) |
2847 | free (contents); |
2721 | free (contents); |
2848 | return TRUE; |
2722 | return TRUE; |
2849 | 2723 | ||
2850 | error_return: |
2724 | error_return: |
2851 | if (contents != NULL) |
2725 | if (contents != NULL) |
2852 | free (contents); |
2726 | free (contents); |
2853 | return FALSE; |
2727 | return FALSE; |
2854 | } |
2728 | } |
2855 | 2729 | ||
2856 | /* A little routine to count the number of relocs in a link_order |
2730 | /* A little routine to count the number of relocs in a link_order |
2857 | list. */ |
2731 | list. */ |
2858 | 2732 | ||
2859 | unsigned int |
2733 | unsigned int |
2860 | _bfd_count_link_order_relocs (struct bfd_link_order *link_order) |
2734 | _bfd_count_link_order_relocs (struct bfd_link_order *link_order) |
2861 | { |
2735 | { |
2862 | register unsigned int c; |
2736 | register unsigned int c; |
2863 | register struct bfd_link_order *l; |
2737 | register struct bfd_link_order *l; |
2864 | 2738 | ||
2865 | c = 0; |
2739 | c = 0; |
2866 | for (l = link_order; l != NULL; l = l->next) |
2740 | for (l = link_order; l != NULL; l = l->next) |
2867 | { |
2741 | { |
2868 | if (l->type == bfd_section_reloc_link_order |
2742 | if (l->type == bfd_section_reloc_link_order |
2869 | || l->type == bfd_symbol_reloc_link_order) |
2743 | || l->type == bfd_symbol_reloc_link_order) |
2870 | ++c; |
2744 | ++c; |
2871 | } |
2745 | } |
2872 | 2746 | ||
2873 | return c; |
2747 | return c; |
2874 | } |
2748 | } |
2875 | 2749 | ||
2876 | /* |
2750 | /* |
2877 | FUNCTION |
2751 | FUNCTION |
2878 | bfd_link_split_section |
2752 | bfd_link_split_section |
2879 | 2753 | ||
2880 | SYNOPSIS |
2754 | SYNOPSIS |
2881 | bfd_boolean bfd_link_split_section (bfd *abfd, asection *sec); |
2755 | bfd_boolean bfd_link_split_section (bfd *abfd, asection *sec); |
2882 | 2756 | ||
2883 | DESCRIPTION |
2757 | DESCRIPTION |
2884 | Return nonzero if @var{sec} should be split during a |
2758 | Return nonzero if @var{sec} should be split during a |
2885 | reloceatable or final link. |
2759 | reloceatable or final link. |
2886 | 2760 | ||
2887 | .#define bfd_link_split_section(abfd, sec) \ |
2761 | .#define bfd_link_split_section(abfd, sec) \ |
2888 | . BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec)) |
2762 | . BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec)) |
2889 | . |
2763 | . |
2890 | 2764 | ||
2891 | */ |
2765 | */ |
2892 | 2766 | ||
2893 | bfd_boolean |
2767 | bfd_boolean |
2894 | _bfd_generic_link_split_section (bfd *abfd ATTRIBUTE_UNUSED, |
2768 | _bfd_generic_link_split_section (bfd *abfd ATTRIBUTE_UNUSED, |
2895 | asection *sec ATTRIBUTE_UNUSED) |
2769 | asection *sec ATTRIBUTE_UNUSED) |
2896 | { |
2770 | { |
2897 | return FALSE; |
2771 | return FALSE; |
2898 | } |
2772 | } |
2899 | 2773 | ||
2900 | /* |
2774 | /* |
2901 | FUNCTION |
2775 | FUNCTION |
2902 | bfd_section_already_linked |
2776 | bfd_section_already_linked |
2903 | 2777 | ||
2904 | SYNOPSIS |
2778 | SYNOPSIS |
2905 | bfd_boolean bfd_section_already_linked (bfd *abfd, |
2779 | bfd_boolean bfd_section_already_linked (bfd *abfd, |
2906 | asection *sec, |
2780 | asection *sec, |
2907 | struct bfd_link_info *info); |
2781 | struct bfd_link_info *info); |
2908 | 2782 | ||
2909 | DESCRIPTION |
2783 | DESCRIPTION |
2910 | Check if @var{data} has been already linked during a reloceatable |
2784 | Check if @var{data} has been already linked during a reloceatable |
2911 | or final link. Return TRUE if it has. |
2785 | or final link. Return TRUE if it has. |
2912 | 2786 | ||
2913 | .#define bfd_section_already_linked(abfd, sec, info) \ |
2787 | .#define bfd_section_already_linked(abfd, sec, info) \ |
2914 | . BFD_SEND (abfd, _section_already_linked, (abfd, sec, info)) |
2788 | . BFD_SEND (abfd, _section_already_linked, (abfd, sec, info)) |
2915 | . |
2789 | . |
2916 | 2790 | ||
2917 | */ |
2791 | */ |
2918 | 2792 | ||
2919 | /* Sections marked with the SEC_LINK_ONCE flag should only be linked |
2793 | /* Sections marked with the SEC_LINK_ONCE flag should only be linked |
2920 | once into the output. This routine checks each section, and |
2794 | once into the output. This routine checks each section, and |
2921 | arrange to discard it if a section of the same name has already |
2795 | arrange to discard it if a section of the same name has already |
2922 | been linked. This code assumes that all relevant sections have the |
2796 | been linked. This code assumes that all relevant sections have the |
2923 | SEC_LINK_ONCE flag set; that is, it does not depend solely upon the |
2797 | SEC_LINK_ONCE flag set; that is, it does not depend solely upon the |
2924 | section name. bfd_section_already_linked is called via |
2798 | section name. bfd_section_already_linked is called via |
2925 | bfd_map_over_sections. */ |
2799 | bfd_map_over_sections. */ |
2926 | 2800 | ||
2927 | /* The hash table. */ |
2801 | /* The hash table. */ |
2928 | 2802 | ||
2929 | static struct bfd_hash_table _bfd_section_already_linked_table; |
2803 | static struct bfd_hash_table _bfd_section_already_linked_table; |
2930 | 2804 | ||
2931 | /* Support routines for the hash table used by section_already_linked, |
2805 | /* Support routines for the hash table used by section_already_linked, |
2932 | initialize the table, traverse, lookup, fill in an entry and remove |
2806 | initialize the table, traverse, lookup, fill in an entry and remove |
2933 | the table. */ |
2807 | the table. */ |
2934 | 2808 | ||
2935 | void |
2809 | void |
2936 | bfd_section_already_linked_table_traverse |
2810 | bfd_section_already_linked_table_traverse |
2937 | (bfd_boolean (*func) (struct bfd_section_already_linked_hash_entry *, |
2811 | (bfd_boolean (*func) (struct bfd_section_already_linked_hash_entry *, |
2938 | void *), void *info) |
2812 | void *), void *info) |
2939 | { |
2813 | { |
2940 | bfd_hash_traverse (&_bfd_section_already_linked_table, |
2814 | bfd_hash_traverse (&_bfd_section_already_linked_table, |
2941 | (bfd_boolean (*) (struct bfd_hash_entry *, |
2815 | (bfd_boolean (*) (struct bfd_hash_entry *, |
2942 | void *)) func, |
2816 | void *)) func, |
2943 | info); |
2817 | info); |
2944 | } |
2818 | } |
2945 | 2819 | ||
2946 | struct bfd_section_already_linked_hash_entry * |
2820 | struct bfd_section_already_linked_hash_entry * |
2947 | bfd_section_already_linked_table_lookup (const char *name) |
2821 | bfd_section_already_linked_table_lookup (const char *name) |
2948 | { |
2822 | { |
2949 | return ((struct bfd_section_already_linked_hash_entry *) |
2823 | return ((struct bfd_section_already_linked_hash_entry *) |
2950 | bfd_hash_lookup (&_bfd_section_already_linked_table, name, |
2824 | bfd_hash_lookup (&_bfd_section_already_linked_table, name, |
2951 | TRUE, FALSE)); |
2825 | TRUE, FALSE)); |
2952 | } |
2826 | } |
2953 | 2827 | ||
2954 | bfd_boolean |
2828 | bfd_boolean |
2955 | bfd_section_already_linked_table_insert |
2829 | bfd_section_already_linked_table_insert |
2956 | (struct bfd_section_already_linked_hash_entry *already_linked_list, |
2830 | (struct bfd_section_already_linked_hash_entry *already_linked_list, |
2957 | asection *sec) |
2831 | asection *sec) |
2958 | { |
2832 | { |
2959 | struct bfd_section_already_linked *l; |
2833 | struct bfd_section_already_linked *l; |
2960 | 2834 | ||
2961 | /* Allocate the memory from the same obstack as the hash table is |
2835 | /* Allocate the memory from the same obstack as the hash table is |
2962 | kept in. */ |
2836 | kept in. */ |
2963 | l = (struct bfd_section_already_linked *) |
2837 | l = (struct bfd_section_already_linked *) |
2964 | bfd_hash_allocate (&_bfd_section_already_linked_table, sizeof *l); |
2838 | bfd_hash_allocate (&_bfd_section_already_linked_table, sizeof *l); |
2965 | if (l == NULL) |
2839 | if (l == NULL) |
2966 | return FALSE; |
2840 | return FALSE; |
2967 | l->sec = sec; |
2841 | l->sec = sec; |
2968 | l->next = already_linked_list->entry; |
2842 | l->next = already_linked_list->entry; |
2969 | already_linked_list->entry = l; |
2843 | already_linked_list->entry = l; |
2970 | return TRUE; |
2844 | return TRUE; |
2971 | } |
2845 | } |
2972 | 2846 | ||
2973 | static struct bfd_hash_entry * |
2847 | static struct bfd_hash_entry * |
2974 | already_linked_newfunc (struct bfd_hash_entry *entry ATTRIBUTE_UNUSED, |
2848 | already_linked_newfunc (struct bfd_hash_entry *entry ATTRIBUTE_UNUSED, |
2975 | struct bfd_hash_table *table, |
2849 | struct bfd_hash_table *table, |
2976 | const char *string ATTRIBUTE_UNUSED) |
2850 | const char *string ATTRIBUTE_UNUSED) |
2977 | { |
2851 | { |
2978 | struct bfd_section_already_linked_hash_entry *ret = |
2852 | struct bfd_section_already_linked_hash_entry *ret = |
2979 | (struct bfd_section_already_linked_hash_entry *) |
2853 | (struct bfd_section_already_linked_hash_entry *) |
2980 | bfd_hash_allocate (table, sizeof *ret); |
2854 | bfd_hash_allocate (table, sizeof *ret); |
2981 | 2855 | ||
2982 | if (ret == NULL) |
2856 | if (ret == NULL) |
2983 | return NULL; |
2857 | return NULL; |
2984 | 2858 | ||
2985 | ret->entry = NULL; |
2859 | ret->entry = NULL; |
2986 | 2860 | ||
2987 | return &ret->root; |
2861 | return &ret->root; |
2988 | } |
2862 | } |
2989 | 2863 | ||
2990 | bfd_boolean |
2864 | bfd_boolean |
2991 | bfd_section_already_linked_table_init (void) |
2865 | bfd_section_already_linked_table_init (void) |
2992 | { |
2866 | { |
2993 | return bfd_hash_table_init_n (&_bfd_section_already_linked_table, |
2867 | return bfd_hash_table_init_n (&_bfd_section_already_linked_table, |
2994 | already_linked_newfunc, |
2868 | already_linked_newfunc, |
2995 | sizeof (struct bfd_section_already_linked_hash_entry), |
2869 | sizeof (struct bfd_section_already_linked_hash_entry), |
2996 | 42); |
2870 | 42); |
2997 | } |
2871 | } |
2998 | 2872 | ||
2999 | void |
2873 | void |
3000 | bfd_section_already_linked_table_free (void) |
2874 | bfd_section_already_linked_table_free (void) |
3001 | { |
2875 | { |
3002 | bfd_hash_table_free (&_bfd_section_already_linked_table); |
2876 | bfd_hash_table_free (&_bfd_section_already_linked_table); |
3003 | } |
2877 | } |
3004 | 2878 | ||
3005 | /* Report warnings as appropriate for duplicate section SEC. |
2879 | /* Report warnings as appropriate for duplicate section SEC. |
3006 | Return FALSE if we decide to keep SEC after all. */ |
2880 | Return FALSE if we decide to keep SEC after all. */ |
3007 | 2881 | ||
3008 | bfd_boolean |
2882 | bfd_boolean |
3009 | _bfd_handle_already_linked (asection *sec, |
2883 | _bfd_handle_already_linked (asection *sec, |
3010 | struct bfd_section_already_linked *l, |
2884 | struct bfd_section_already_linked *l, |
3011 | struct bfd_link_info *info) |
2885 | struct bfd_link_info *info) |
3012 | { |
2886 | { |
3013 | switch (sec->flags & SEC_LINK_DUPLICATES) |
2887 | switch (sec->flags & SEC_LINK_DUPLICATES) |
3014 | { |
2888 | { |
3015 | default: |
2889 | default: |
3016 | abort (); |
2890 | abort (); |
3017 | 2891 | ||
3018 | case SEC_LINK_DUPLICATES_DISCARD: |
2892 | case SEC_LINK_DUPLICATES_DISCARD: |
3019 | /* If we found an LTO IR match for this comdat group on |
2893 | /* If we found an LTO IR match for this comdat group on |
3020 | the first pass, replace it with the LTO output on the |
2894 | the first pass, replace it with the LTO output on the |
3021 | second pass. We can't simply choose real object |
2895 | second pass. We can't simply choose real object |
3022 | files over IR because the first pass may contain a |
2896 | files over IR because the first pass may contain a |
3023 | mix of LTO and normal objects and we must keep the |
2897 | mix of LTO and normal objects and we must keep the |
3024 | first match, be it IR or real. */ |
2898 | first match, be it IR or real. */ |
3025 | if (info->loading_lto_outputs |
2899 | if (sec->owner->lto_output |
3026 | && (l->sec->owner->flags & BFD_PLUGIN) != 0) |
2900 | && (l->sec->owner->flags & BFD_PLUGIN) != 0) |
3027 | { |
2901 | { |
3028 | l->sec = sec; |
2902 | l->sec = sec; |
3029 | return FALSE; |
2903 | return FALSE; |
3030 | } |
2904 | } |
3031 | break; |
2905 | break; |
3032 | 2906 | ||
3033 | case SEC_LINK_DUPLICATES_ONE_ONLY: |
2907 | case SEC_LINK_DUPLICATES_ONE_ONLY: |
3034 | info->callbacks->einfo |
2908 | info->callbacks->einfo |
3035 | (_("%B: ignoring duplicate section `%A'\n"), |
2909 | (_("%B: ignoring duplicate section `%A'\n"), |
3036 | sec->owner, sec); |
2910 | sec->owner, sec); |
3037 | break; |
2911 | break; |
3038 | 2912 | ||
3039 | case SEC_LINK_DUPLICATES_SAME_SIZE: |
2913 | case SEC_LINK_DUPLICATES_SAME_SIZE: |
3040 | if ((l->sec->owner->flags & BFD_PLUGIN) != 0) |
2914 | if ((l->sec->owner->flags & BFD_PLUGIN) != 0) |
3041 | ; |
2915 | ; |
3042 | else if (sec->size != l->sec->size) |
2916 | else if (sec->size != l->sec->size) |
3043 | info->callbacks->einfo |
2917 | info->callbacks->einfo |
3044 | (_("%B: duplicate section `%A' has different size\n"), |
2918 | (_("%B: duplicate section `%A' has different size\n"), |
3045 | sec->owner, sec); |
2919 | sec->owner, sec); |
3046 | break; |
2920 | break; |
3047 | 2921 | ||
3048 | case SEC_LINK_DUPLICATES_SAME_CONTENTS: |
2922 | case SEC_LINK_DUPLICATES_SAME_CONTENTS: |
3049 | if ((l->sec->owner->flags & BFD_PLUGIN) != 0) |
2923 | if ((l->sec->owner->flags & BFD_PLUGIN) != 0) |
3050 | ; |
2924 | ; |
3051 | else if (sec->size != l->sec->size) |
2925 | else if (sec->size != l->sec->size) |
3052 | info->callbacks->einfo |
2926 | info->callbacks->einfo |
3053 | (_("%B: duplicate section `%A' has different size\n"), |
2927 | (_("%B: duplicate section `%A' has different size\n"), |
3054 | sec->owner, sec); |
2928 | sec->owner, sec); |
3055 | else if (sec->size != 0) |
2929 | else if (sec->size != 0) |
3056 | { |
2930 | { |
3057 | bfd_byte *sec_contents, *l_sec_contents = NULL; |
2931 | bfd_byte *sec_contents, *l_sec_contents = NULL; |
3058 | 2932 | ||
3059 | if (!bfd_malloc_and_get_section (sec->owner, sec, &sec_contents)) |
2933 | if (!bfd_malloc_and_get_section (sec->owner, sec, &sec_contents)) |
3060 | info->callbacks->einfo |
2934 | info->callbacks->einfo |
3061 | (_("%B: could not read contents of section `%A'\n"), |
2935 | (_("%B: could not read contents of section `%A'\n"), |
3062 | sec->owner, sec); |
2936 | sec->owner, sec); |
3063 | else if (!bfd_malloc_and_get_section (l->sec->owner, l->sec, |
2937 | else if (!bfd_malloc_and_get_section (l->sec->owner, l->sec, |
3064 | &l_sec_contents)) |
2938 | &l_sec_contents)) |
3065 | info->callbacks->einfo |
2939 | info->callbacks->einfo |
3066 | (_("%B: could not read contents of section `%A'\n"), |
2940 | (_("%B: could not read contents of section `%A'\n"), |
3067 | l->sec->owner, l->sec); |
2941 | l->sec->owner, l->sec); |
3068 | else if (memcmp (sec_contents, l_sec_contents, sec->size) != 0) |
2942 | else if (memcmp (sec_contents, l_sec_contents, sec->size) != 0) |
3069 | info->callbacks->einfo |
2943 | info->callbacks->einfo |
3070 | (_("%B: duplicate section `%A' has different contents\n"), |
2944 | (_("%B: duplicate section `%A' has different contents\n"), |
3071 | sec->owner, sec); |
2945 | sec->owner, sec); |
3072 | 2946 | ||
3073 | if (sec_contents) |
2947 | if (sec_contents) |
3074 | free (sec_contents); |
2948 | free (sec_contents); |
3075 | if (l_sec_contents) |
2949 | if (l_sec_contents) |
3076 | free (l_sec_contents); |
2950 | free (l_sec_contents); |
3077 | } |
2951 | } |
3078 | break; |
2952 | break; |
3079 | } |
2953 | } |
3080 | 2954 | ||
3081 | /* Set the output_section field so that lang_add_section |
2955 | /* Set the output_section field so that lang_add_section |
3082 | does not create a lang_input_section structure for this |
2956 | does not create a lang_input_section structure for this |
3083 | section. Since there might be a symbol in the section |
2957 | section. Since there might be a symbol in the section |
3084 | being discarded, we must retain a pointer to the section |
2958 | being discarded, we must retain a pointer to the section |
3085 | which we are really going to use. */ |
2959 | which we are really going to use. */ |
3086 | sec->output_section = bfd_abs_section_ptr; |
2960 | sec->output_section = bfd_abs_section_ptr; |
3087 | sec->kept_section = l->sec; |
2961 | sec->kept_section = l->sec; |
3088 | return TRUE; |
2962 | return TRUE; |
3089 | } |
2963 | } |
3090 | 2964 | ||
3091 | /* This is used on non-ELF inputs. */ |
2965 | /* This is used on non-ELF inputs. */ |
3092 | 2966 | ||
3093 | bfd_boolean |
2967 | bfd_boolean |
3094 | _bfd_generic_section_already_linked (bfd *abfd ATTRIBUTE_UNUSED, |
2968 | _bfd_generic_section_already_linked (bfd *abfd ATTRIBUTE_UNUSED, |
3095 | asection *sec, |
2969 | asection *sec, |
3096 | struct bfd_link_info *info) |
2970 | struct bfd_link_info *info) |
3097 | { |
2971 | { |
3098 | const char *name; |
2972 | const char *name; |
3099 | struct bfd_section_already_linked *l; |
2973 | struct bfd_section_already_linked *l; |
3100 | struct bfd_section_already_linked_hash_entry *already_linked_list; |
2974 | struct bfd_section_already_linked_hash_entry *already_linked_list; |
3101 | 2975 | ||
3102 | if ((sec->flags & SEC_LINK_ONCE) == 0) |
2976 | if ((sec->flags & SEC_LINK_ONCE) == 0) |
3103 | return FALSE; |
2977 | return FALSE; |
3104 | 2978 | ||
3105 | /* The generic linker doesn't handle section groups. */ |
2979 | /* The generic linker doesn't handle section groups. */ |
3106 | if ((sec->flags & SEC_GROUP) != 0) |
2980 | if ((sec->flags & SEC_GROUP) != 0) |
3107 | return FALSE; |
2981 | return FALSE; |
3108 | 2982 | ||
3109 | /* FIXME: When doing a relocatable link, we may have trouble |
2983 | /* FIXME: When doing a relocatable link, we may have trouble |
3110 | copying relocations in other sections that refer to local symbols |
2984 | copying relocations in other sections that refer to local symbols |
3111 | in the section being discarded. Those relocations will have to |
2985 | in the section being discarded. Those relocations will have to |
3112 | be converted somehow; as of this writing I'm not sure that any of |
2986 | be converted somehow; as of this writing I'm not sure that any of |
3113 | the backends handle that correctly. |
2987 | the backends handle that correctly. |
3114 | 2988 | ||
3115 | It is tempting to instead not discard link once sections when |
2989 | It is tempting to instead not discard link once sections when |
3116 | doing a relocatable link (technically, they should be discarded |
2990 | doing a relocatable link (technically, they should be discarded |
3117 | whenever we are building constructors). However, that fails, |
2991 | whenever we are building constructors). However, that fails, |
3118 | because the linker winds up combining all the link once sections |
2992 | because the linker winds up combining all the link once sections |
3119 | into a single large link once section, which defeats the purpose |
2993 | into a single large link once section, which defeats the purpose |
3120 | of having link once sections in the first place. */ |
2994 | of having link once sections in the first place. */ |
3121 | 2995 | ||
3122 | name = bfd_get_section_name (abfd, sec); |
2996 | name = bfd_get_section_name (abfd, sec); |
3123 | 2997 | ||
3124 | already_linked_list = bfd_section_already_linked_table_lookup (name); |
2998 | already_linked_list = bfd_section_already_linked_table_lookup (name); |
3125 | 2999 | ||
3126 | l = already_linked_list->entry; |
3000 | l = already_linked_list->entry; |
3127 | if (l != NULL) |
3001 | if (l != NULL) |
3128 | { |
3002 | { |
3129 | /* The section has already been linked. See if we should |
3003 | /* The section has already been linked. See if we should |
3130 | issue a warning. */ |
3004 | issue a warning. */ |
3131 | return _bfd_handle_already_linked (sec, l, info); |
3005 | return _bfd_handle_already_linked (sec, l, info); |
3132 | } |
3006 | } |
3133 | 3007 | ||
3134 | /* This is the first section with this name. Record it. */ |
3008 | /* This is the first section with this name. Record it. */ |
3135 | if (!bfd_section_already_linked_table_insert (already_linked_list, sec)) |
3009 | if (!bfd_section_already_linked_table_insert (already_linked_list, sec)) |
3136 | info->callbacks->einfo (_("%F%P: already_linked_table: %E\n")); |
3010 | info->callbacks->einfo (_("%F%P: already_linked_table: %E\n")); |
3137 | return FALSE; |
3011 | return FALSE; |
3138 | } |
3012 | } |
3139 | 3013 | ||
3140 | /* Choose a neighbouring section to S in OBFD that will be output, or |
3014 | /* Choose a neighbouring section to S in OBFD that will be output, or |
3141 | the absolute section if ADDR is out of bounds of the neighbours. */ |
3015 | the absolute section if ADDR is out of bounds of the neighbours. */ |
3142 | 3016 | ||
3143 | asection * |
3017 | asection * |
3144 | _bfd_nearby_section (bfd *obfd, asection *s, bfd_vma addr) |
3018 | _bfd_nearby_section (bfd *obfd, asection *s, bfd_vma addr) |
3145 | { |
3019 | { |
3146 | asection *next, *prev, *best; |
3020 | asection *next, *prev, *best; |
3147 | 3021 | ||
3148 | /* Find preceding kept section. */ |
3022 | /* Find preceding kept section. */ |
3149 | for (prev = s->prev; prev != NULL; prev = prev->prev) |
3023 | for (prev = s->prev; prev != NULL; prev = prev->prev) |
3150 | if ((prev->flags & SEC_EXCLUDE) == 0 |
3024 | if ((prev->flags & SEC_EXCLUDE) == 0 |
3151 | && !bfd_section_removed_from_list (obfd, prev)) |
3025 | && !bfd_section_removed_from_list (obfd, prev)) |
3152 | break; |
3026 | break; |
3153 | 3027 | ||
3154 | /* Find following kept section. Start at prev->next because |
3028 | /* Find following kept section. Start at prev->next because |
3155 | other sections may have been added after S was removed. */ |
3029 | other sections may have been added after S was removed. */ |
3156 | if (s->prev != NULL) |
3030 | if (s->prev != NULL) |
3157 | next = s->prev->next; |
3031 | next = s->prev->next; |
3158 | else |
3032 | else |
3159 | next = s->owner->sections; |
3033 | next = s->owner->sections; |
3160 | for (; next != NULL; next = next->next) |
3034 | for (; next != NULL; next = next->next) |
3161 | if ((next->flags & SEC_EXCLUDE) == 0 |
3035 | if ((next->flags & SEC_EXCLUDE) == 0 |
3162 | && !bfd_section_removed_from_list (obfd, next)) |
3036 | && !bfd_section_removed_from_list (obfd, next)) |
3163 | break; |
3037 | break; |
3164 | 3038 | ||
3165 | /* Choose better of two sections, based on flags. The idea |
3039 | /* Choose better of two sections, based on flags. The idea |
3166 | is to choose a section that will be in the same segment |
3040 | is to choose a section that will be in the same segment |
3167 | as S would have been if it was kept. */ |
3041 | as S would have been if it was kept. */ |
3168 | best = next; |
3042 | best = next; |
3169 | if (prev == NULL) |
3043 | if (prev == NULL) |
3170 | { |
3044 | { |
3171 | if (next == NULL) |
3045 | if (next == NULL) |
3172 | best = bfd_abs_section_ptr; |
3046 | best = bfd_abs_section_ptr; |
3173 | } |
3047 | } |
3174 | else if (next == NULL) |
3048 | else if (next == NULL) |
3175 | best = prev; |
3049 | best = prev; |
3176 | else if (((prev->flags ^ next->flags) |
3050 | else if (((prev->flags ^ next->flags) |
3177 | & (SEC_ALLOC | SEC_THREAD_LOCAL | SEC_LOAD)) != 0) |
3051 | & (SEC_ALLOC | SEC_THREAD_LOCAL | SEC_LOAD)) != 0) |
3178 | { |
3052 | { |
3179 | if (((next->flags ^ s->flags) |
3053 | if (((next->flags ^ s->flags) |
3180 | & (SEC_ALLOC | SEC_THREAD_LOCAL)) != 0 |
3054 | & (SEC_ALLOC | SEC_THREAD_LOCAL)) != 0 |
3181 | /* We prefer to choose a loaded section. Section S |
3055 | /* We prefer to choose a loaded section. Section S |
3182 | doesn't have SEC_LOAD set (it being excluded, that |
3056 | doesn't have SEC_LOAD set (it being excluded, that |
3183 | part of the flag processing didn't happen) so we |
3057 | part of the flag processing didn't happen) so we |
3184 | can't compare that flag to those of NEXT and PREV. */ |
3058 | can't compare that flag to those of NEXT and PREV. */ |
3185 | || ((prev->flags & SEC_LOAD) != 0 |
3059 | || ((prev->flags & SEC_LOAD) != 0 |
3186 | && (next->flags & SEC_LOAD) == 0)) |
3060 | && (next->flags & SEC_LOAD) == 0)) |
3187 | best = prev; |
3061 | best = prev; |
3188 | } |
3062 | } |
3189 | else if (((prev->flags ^ next->flags) & SEC_READONLY) != 0) |
3063 | else if (((prev->flags ^ next->flags) & SEC_READONLY) != 0) |
3190 | { |
3064 | { |
3191 | if (((next->flags ^ s->flags) & SEC_READONLY) != 0) |
3065 | if (((next->flags ^ s->flags) & SEC_READONLY) != 0) |
3192 | best = prev; |
3066 | best = prev; |
3193 | } |
3067 | } |
3194 | else if (((prev->flags ^ next->flags) & SEC_CODE) != 0) |
3068 | else if (((prev->flags ^ next->flags) & SEC_CODE) != 0) |
3195 | { |
3069 | { |
3196 | if (((next->flags ^ s->flags) & SEC_CODE) != 0) |
3070 | if (((next->flags ^ s->flags) & SEC_CODE) != 0) |
3197 | best = prev; |
3071 | best = prev; |
3198 | } |
3072 | } |
3199 | else |
3073 | else |
3200 | { |
3074 | { |
3201 | /* Flags we care about are the same. Prefer the following |
3075 | /* Flags we care about are the same. Prefer the following |
3202 | section if that will result in a positive valued sym. */ |
3076 | section if that will result in a positive valued sym. */ |
3203 | if (addr < next->vma) |
3077 | if (addr < next->vma) |
3204 | best = prev; |
3078 | best = prev; |
3205 | } |
3079 | } |
3206 | 3080 | ||
3207 | return best; |
3081 | return best; |
3208 | } |
3082 | } |
3209 | 3083 | ||
3210 | /* Convert symbols in excluded output sections to use a kept section. */ |
3084 | /* Convert symbols in excluded output sections to use a kept section. */ |
3211 | 3085 | ||
3212 | static bfd_boolean |
3086 | static bfd_boolean |
3213 | fix_syms (struct bfd_link_hash_entry *h, void *data) |
3087 | fix_syms (struct bfd_link_hash_entry *h, void *data) |
3214 | { |
3088 | { |
3215 | bfd *obfd = (bfd *) data; |
3089 | bfd *obfd = (bfd *) data; |
3216 | 3090 | ||
3217 | if (h->type == bfd_link_hash_defined |
3091 | if (h->type == bfd_link_hash_defined |
3218 | || h->type == bfd_link_hash_defweak) |
3092 | || h->type == bfd_link_hash_defweak) |
3219 | { |
3093 | { |
3220 | asection *s = h->u.def.section; |
3094 | asection *s = h->u.def.section; |
3221 | if (s != NULL |
3095 | if (s != NULL |
3222 | && s->output_section != NULL |
3096 | && s->output_section != NULL |
3223 | && (s->output_section->flags & SEC_EXCLUDE) != 0 |
3097 | && (s->output_section->flags & SEC_EXCLUDE) != 0 |
3224 | && bfd_section_removed_from_list (obfd, s->output_section)) |
3098 | && bfd_section_removed_from_list (obfd, s->output_section)) |
3225 | { |
3099 | { |
3226 | asection *op; |
3100 | asection *op; |
3227 | 3101 | ||
3228 | h->u.def.value += s->output_offset + s->output_section->vma; |
3102 | h->u.def.value += s->output_offset + s->output_section->vma; |
3229 | op = _bfd_nearby_section (obfd, s->output_section, h->u.def.value); |
3103 | op = _bfd_nearby_section (obfd, s->output_section, h->u.def.value); |
3230 | h->u.def.value -= op->vma; |
3104 | h->u.def.value -= op->vma; |
3231 | h->u.def.section = op; |
3105 | h->u.def.section = op; |
3232 | } |
3106 | } |
3233 | } |
3107 | } |
3234 | 3108 | ||
3235 | return TRUE; |
3109 | return TRUE; |
3236 | } |
3110 | } |
3237 | 3111 | ||
3238 | void |
3112 | void |
3239 | _bfd_fix_excluded_sec_syms (bfd *obfd, struct bfd_link_info *info) |
3113 | _bfd_fix_excluded_sec_syms (bfd *obfd, struct bfd_link_info *info) |
3240 | { |
3114 | { |
3241 | bfd_link_hash_traverse (info->hash, fix_syms, obfd); |
3115 | bfd_link_hash_traverse (info->hash, fix_syms, obfd); |
3242 | } |
3116 | } |
3243 | 3117 | ||
3244 | /* |
3118 | /* |
3245 | FUNCTION |
3119 | FUNCTION |
3246 | bfd_generic_define_common_symbol |
3120 | bfd_generic_define_common_symbol |
3247 | 3121 | ||
3248 | SYNOPSIS |
3122 | SYNOPSIS |
3249 | bfd_boolean bfd_generic_define_common_symbol |
3123 | bfd_boolean bfd_generic_define_common_symbol |
3250 | (bfd *output_bfd, struct bfd_link_info *info, |
3124 | (bfd *output_bfd, struct bfd_link_info *info, |
3251 | struct bfd_link_hash_entry *h); |
3125 | struct bfd_link_hash_entry *h); |
3252 | 3126 | ||
3253 | DESCRIPTION |
3127 | DESCRIPTION |
3254 | Convert common symbol @var{h} into a defined symbol. |
3128 | Convert common symbol @var{h} into a defined symbol. |
3255 | Return TRUE on success and FALSE on failure. |
3129 | Return TRUE on success and FALSE on failure. |
3256 | 3130 | ||
3257 | .#define bfd_define_common_symbol(output_bfd, info, h) \ |
3131 | .#define bfd_define_common_symbol(output_bfd, info, h) \ |
3258 | . BFD_SEND (output_bfd, _bfd_define_common_symbol, (output_bfd, info, h)) |
3132 | . BFD_SEND (output_bfd, _bfd_define_common_symbol, (output_bfd, info, h)) |
3259 | . |
3133 | . |
3260 | */ |
3134 | */ |
3261 | 3135 | ||
3262 | bfd_boolean |
3136 | bfd_boolean |
3263 | bfd_generic_define_common_symbol (bfd *output_bfd, |
3137 | bfd_generic_define_common_symbol (bfd *output_bfd, |
3264 | struct bfd_link_info *info ATTRIBUTE_UNUSED, |
3138 | struct bfd_link_info *info ATTRIBUTE_UNUSED, |
3265 | struct bfd_link_hash_entry *h) |
3139 | struct bfd_link_hash_entry *h) |
3266 | { |
3140 | { |
3267 | unsigned int power_of_two; |
3141 | unsigned int power_of_two; |
3268 | bfd_vma alignment, size; |
3142 | bfd_vma alignment, size; |
3269 | asection *section; |
3143 | asection *section; |
3270 | 3144 | ||
3271 | BFD_ASSERT (h != NULL && h->type == bfd_link_hash_common); |
3145 | BFD_ASSERT (h != NULL && h->type == bfd_link_hash_common); |
3272 | 3146 | ||
3273 | size = h->u.c.size; |
3147 | size = h->u.c.size; |
3274 | power_of_two = h->u.c.p->alignment_power; |
3148 | power_of_two = h->u.c.p->alignment_power; |
3275 | section = h->u.c.p->section; |
3149 | section = h->u.c.p->section; |
3276 | 3150 | ||
3277 | /* Increase the size of the section to align the common symbol. |
3151 | /* Increase the size of the section to align the common symbol. |
3278 | The alignment must be a power of two. */ |
3152 | The alignment must be a power of two. */ |
3279 | alignment = bfd_octets_per_byte (output_bfd) << power_of_two; |
3153 | alignment = bfd_octets_per_byte (output_bfd) << power_of_two; |
3280 | BFD_ASSERT (alignment != 0 && (alignment & -alignment) == alignment); |
3154 | BFD_ASSERT (alignment != 0 && (alignment & -alignment) == alignment); |
3281 | section->size += alignment - 1; |
3155 | section->size += alignment - 1; |
3282 | section->size &= -alignment; |
3156 | section->size &= -alignment; |
3283 | 3157 | ||
3284 | /* Adjust the section's overall alignment if necessary. */ |
3158 | /* Adjust the section's overall alignment if necessary. */ |
3285 | if (power_of_two > section->alignment_power) |
3159 | if (power_of_two > section->alignment_power) |
3286 | section->alignment_power = power_of_two; |
3160 | section->alignment_power = power_of_two; |
3287 | 3161 | ||
3288 | /* Change the symbol from common to defined. */ |
3162 | /* Change the symbol from common to defined. */ |
3289 | h->type = bfd_link_hash_defined; |
3163 | h->type = bfd_link_hash_defined; |
3290 | h->u.def.section = section; |
3164 | h->u.def.section = section; |
3291 | h->u.def.value = section->size; |
3165 | h->u.def.value = section->size; |
3292 | 3166 | ||
3293 | /* Increase the size of the section. */ |
3167 | /* Increase the size of the section. */ |
3294 | section->size += size; |
3168 | section->size += size; |
3295 | 3169 | ||
3296 | /* Make sure the section is allocated in memory, and make sure that |
3170 | /* Make sure the section is allocated in memory, and make sure that |
3297 | it is no longer a common section. */ |
3171 | it is no longer a common section. */ |
3298 | section->flags |= SEC_ALLOC; |
3172 | section->flags |= SEC_ALLOC; |
3299 | section->flags &= ~SEC_IS_COMMON; |
3173 | section->flags &= ~SEC_IS_COMMON; |
3300 | return TRUE; |
3174 | return TRUE; |
3301 | } |
3175 | } |
3302 | 3176 | ||
3303 | /* |
3177 | /* |
3304 | FUNCTION |
3178 | FUNCTION |
3305 | bfd_find_version_for_sym |
3179 | bfd_find_version_for_sym |
3306 | 3180 | ||
3307 | SYNOPSIS |
3181 | SYNOPSIS |
3308 | struct bfd_elf_version_tree * bfd_find_version_for_sym |
3182 | struct bfd_elf_version_tree * bfd_find_version_for_sym |
3309 | (struct bfd_elf_version_tree *verdefs, |
3183 | (struct bfd_elf_version_tree *verdefs, |
3310 | const char *sym_name, bfd_boolean *hide); |
3184 | const char *sym_name, bfd_boolean *hide); |
3311 | 3185 | ||
3312 | DESCRIPTION |
3186 | DESCRIPTION |
3313 | Search an elf version script tree for symbol versioning |
3187 | Search an elf version script tree for symbol versioning |
3314 | info and export / don't-export status for a given symbol. |
3188 | info and export / don't-export status for a given symbol. |
3315 | Return non-NULL on success and NULL on failure; also sets |
3189 | Return non-NULL on success and NULL on failure; also sets |
3316 | the output @samp{hide} boolean parameter. |
3190 | the output @samp{hide} boolean parameter. |
3317 | 3191 | ||
3318 | */ |
3192 | */ |
3319 | 3193 | ||
3320 | struct bfd_elf_version_tree * |
3194 | struct bfd_elf_version_tree * |
3321 | bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs, |
3195 | bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs, |
3322 | const char *sym_name, |
3196 | const char *sym_name, |
3323 | bfd_boolean *hide) |
3197 | bfd_boolean *hide) |
3324 | { |
3198 | { |
3325 | struct bfd_elf_version_tree *t; |
3199 | struct bfd_elf_version_tree *t; |
3326 | struct bfd_elf_version_tree *local_ver, *global_ver, *exist_ver; |
3200 | struct bfd_elf_version_tree *local_ver, *global_ver, *exist_ver; |
3327 | struct bfd_elf_version_tree *star_local_ver, *star_global_ver; |
3201 | struct bfd_elf_version_tree *star_local_ver, *star_global_ver; |
3328 | 3202 | ||
3329 | local_ver = NULL; |
3203 | local_ver = NULL; |
3330 | global_ver = NULL; |
3204 | global_ver = NULL; |
3331 | star_local_ver = NULL; |
3205 | star_local_ver = NULL; |
3332 | star_global_ver = NULL; |
3206 | star_global_ver = NULL; |
3333 | exist_ver = NULL; |
3207 | exist_ver = NULL; |
3334 | for (t = verdefs; t != NULL; t = t->next) |
3208 | for (t = verdefs; t != NULL; t = t->next) |
3335 | { |
3209 | { |
3336 | if (t->globals.list != NULL) |
3210 | if (t->globals.list != NULL) |
3337 | { |
3211 | { |
3338 | struct bfd_elf_version_expr *d = NULL; |
3212 | struct bfd_elf_version_expr *d = NULL; |
3339 | 3213 | ||
3340 | while ((d = (*t->match) (&t->globals, d, sym_name)) != NULL) |
3214 | while ((d = (*t->match) (&t->globals, d, sym_name)) != NULL) |
3341 | { |
3215 | { |
3342 | if (d->literal || strcmp (d->pattern, "*") != 0) |
3216 | if (d->literal || strcmp (d->pattern, "*") != 0) |
3343 | global_ver = t; |
3217 | global_ver = t; |
3344 | else |
3218 | else |
3345 | star_global_ver = t; |
3219 | star_global_ver = t; |
3346 | if (d->symver) |
3220 | if (d->symver) |
3347 | exist_ver = t; |
3221 | exist_ver = t; |
3348 | d->script = 1; |
3222 | d->script = 1; |
3349 | /* If the match is a wildcard pattern, keep looking for |
3223 | /* If the match is a wildcard pattern, keep looking for |
3350 | a more explicit, perhaps even local, match. */ |
3224 | a more explicit, perhaps even local, match. */ |
3351 | if (d->literal) |
3225 | if (d->literal) |
3352 | break; |
3226 | break; |
3353 | } |
3227 | } |
3354 | 3228 | ||
3355 | if (d != NULL) |
3229 | if (d != NULL) |
3356 | break; |
3230 | break; |
3357 | } |
3231 | } |
3358 | 3232 | ||
3359 | if (t->locals.list != NULL) |
3233 | if (t->locals.list != NULL) |
3360 | { |
3234 | { |
3361 | struct bfd_elf_version_expr *d = NULL; |
3235 | struct bfd_elf_version_expr *d = NULL; |
3362 | 3236 | ||
3363 | while ((d = (*t->match) (&t->locals, d, sym_name)) != NULL) |
3237 | while ((d = (*t->match) (&t->locals, d, sym_name)) != NULL) |
3364 | { |
3238 | { |
3365 | if (d->literal || strcmp (d->pattern, "*") != 0) |
3239 | if (d->literal || strcmp (d->pattern, "*") != 0) |
3366 | local_ver = t; |
3240 | local_ver = t; |
3367 | else |
3241 | else |
3368 | star_local_ver = t; |
3242 | star_local_ver = t; |
3369 | /* If the match is a wildcard pattern, keep looking for |
3243 | /* If the match is a wildcard pattern, keep looking for |
3370 | a more explicit, perhaps even global, match. */ |
3244 | a more explicit, perhaps even global, match. */ |
3371 | if (d->literal) |
3245 | if (d->literal) |
3372 | { |
3246 | { |
3373 | /* An exact match overrides a global wildcard. */ |
3247 | /* An exact match overrides a global wildcard. */ |
3374 | global_ver = NULL; |
3248 | global_ver = NULL; |
3375 | star_global_ver = NULL; |
3249 | star_global_ver = NULL; |
3376 | break; |
3250 | break; |
3377 | } |
3251 | } |
3378 | } |
3252 | } |
3379 | 3253 | ||
3380 | if (d != NULL) |
3254 | if (d != NULL) |
3381 | break; |
3255 | break; |
3382 | } |
3256 | } |
3383 | } |
3257 | } |
3384 | 3258 | ||
3385 | if (global_ver == NULL && local_ver == NULL) |
3259 | if (global_ver == NULL && local_ver == NULL) |
3386 | global_ver = star_global_ver; |
3260 | global_ver = star_global_ver; |
3387 | 3261 | ||
3388 | if (global_ver != NULL) |
3262 | if (global_ver != NULL) |
3389 | { |
3263 | { |
3390 | /* If we already have a versioned symbol that matches the |
3264 | /* If we already have a versioned symbol that matches the |
3391 | node for this symbol, then we don't want to create a |
3265 | node for this symbol, then we don't want to create a |
3392 | duplicate from the unversioned symbol. Instead hide the |
3266 | duplicate from the unversioned symbol. Instead hide the |
3393 | unversioned symbol. */ |
3267 | unversioned symbol. */ |
3394 | *hide = exist_ver == global_ver; |
3268 | *hide = exist_ver == global_ver; |
3395 | return global_ver; |
3269 | return global_ver; |
3396 | } |
3270 | } |
3397 | 3271 | ||
3398 | if (local_ver == NULL) |
3272 | if (local_ver == NULL) |
3399 | local_ver = star_local_ver; |
3273 | local_ver = star_local_ver; |
3400 | 3274 | ||
3401 | if (local_ver != NULL) |
3275 | if (local_ver != NULL) |
3402 | { |
3276 | { |
3403 | *hide = TRUE; |
3277 | *hide = TRUE; |
3404 | return local_ver; |
3278 | return local_ver; |
3405 | } |
3279 | } |
3406 | 3280 | ||
3407 | return NULL; |
3281 | return NULL; |
3408 | } |
3282 | } |
3409 | 3283 | ||
3410 | /* |
3284 | /* |
3411 | FUNCTION |
3285 | FUNCTION |
3412 | bfd_hide_sym_by_version |
3286 | bfd_hide_sym_by_version |
3413 | 3287 | ||
3414 | SYNOPSIS |
3288 | SYNOPSIS |
3415 | bfd_boolean bfd_hide_sym_by_version |
3289 | bfd_boolean bfd_hide_sym_by_version |
3416 | (struct bfd_elf_version_tree *verdefs, const char *sym_name); |
3290 | (struct bfd_elf_version_tree *verdefs, const char *sym_name); |
3417 | 3291 | ||
3418 | DESCRIPTION |
3292 | DESCRIPTION |
3419 | Search an elf version script tree for symbol versioning |
3293 | Search an elf version script tree for symbol versioning |
3420 | info for a given symbol. Return TRUE if the symbol is hidden. |
3294 | info for a given symbol. Return TRUE if the symbol is hidden. |
3421 | 3295 | ||
3422 | */ |
3296 | */ |
3423 | 3297 | ||
3424 | bfd_boolean |
3298 | bfd_boolean |
3425 | bfd_hide_sym_by_version (struct bfd_elf_version_tree *verdefs, |
3299 | bfd_hide_sym_by_version (struct bfd_elf_version_tree *verdefs, |
3426 | const char *sym_name) |
3300 | const char *sym_name) |
3427 | { |
3301 | { |
3428 | bfd_boolean hidden = FALSE; |
3302 | bfd_boolean hidden = FALSE; |
3429 | bfd_find_version_for_sym (verdefs, sym_name, &hidden); |
3303 | bfd_find_version_for_sym (verdefs, sym_name, &hidden); |
3430 | return hidden; |
3304 | return hidden; |
3431 | }><>>>>>>>>>>>>>>> |
3305 | }><>>>>>>>>>>>>>>> |
3432 | > |
3306 | > |
3433 | ><_bfd_link_add_symbols><_bfd_link_hash_table_create><_bfd_link_add_symbols> |
3307 | ><_bfd_link_add_symbols><_bfd_link_hash_table_create><_bfd_link_add_symbols> |