OLD | NEW |
1 /* BFD back-end for linux flavored sparc a.out binaries. | 1 /* BFD back-end for linux flavored sparc a.out binaries. |
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, | 2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, |
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 | 3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 |
4 Free Software Foundation, Inc. | 4 Free Software Foundation, Inc. |
5 | 5 |
6 This file is part of BFD, the Binary File Descriptor library. | 6 This file is part of BFD, the Binary File Descriptor library. |
7 | 7 |
8 This program is free software; you can redistribute it and/or modify | 8 This program is free software; you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
10 the Free Software Foundation; either version 3 of the License, or | 10 the Free Software Foundation; either version 3 of the License, or |
11 (at your option) any later version. | 11 (at your option) any later version. |
12 | 12 |
13 This program is distributed in the hope that it will be useful, | 13 This program is distributed in the hope that it will be useful, |
(...skipping 28 matching lines...) Expand all Loading... |
42 #define MY(OP) CONCAT2 (sparclinux_,OP) | 42 #define MY(OP) CONCAT2 (sparclinux_,OP) |
43 #define TARGETNAME "a.out-sparc-linux" | 43 #define TARGETNAME "a.out-sparc-linux" |
44 | 44 |
45 extern const bfd_target MY(vec); | 45 extern const bfd_target MY(vec); |
46 | 46 |
47 /* We always generate QMAGIC files in preference to ZMAGIC files. It | 47 /* We always generate QMAGIC files in preference to ZMAGIC files. It |
48 would be possible to make this a linker option, if that ever | 48 would be possible to make this a linker option, if that ever |
49 becomes important. */ | 49 becomes important. */ |
50 | 50 |
51 static void MY_final_link_callback | 51 static void MY_final_link_callback |
52 PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *)); | 52 (bfd *, file_ptr *, file_ptr *, file_ptr *); |
53 | |
54 static bfd_boolean sparclinux_bfd_final_link | |
55 PARAMS ((bfd *abfd, struct bfd_link_info *info)); | |
56 | 53 |
57 static bfd_boolean | 54 static bfd_boolean |
58 sparclinux_bfd_final_link (abfd, info) | 55 sparclinux_bfd_final_link (bfd *abfd, struct bfd_link_info *info) |
59 bfd *abfd; | |
60 struct bfd_link_info *info; | |
61 { | 56 { |
62 obj_aout_subformat (abfd) = q_magic_format; | 57 obj_aout_subformat (abfd) = q_magic_format; |
63 return NAME(aout,final_link) (abfd, info, MY_final_link_callback); | 58 return NAME(aout,final_link) (abfd, info, MY_final_link_callback); |
64 } | 59 } |
65 | 60 |
66 #define MY_bfd_final_link sparclinux_bfd_final_link | 61 #define MY_bfd_final_link sparclinux_bfd_final_link |
67 | 62 |
68 /* Set the machine type correctly. */ | 63 /* Set the machine type correctly. */ |
69 | 64 |
70 static bfd_boolean sparclinux_write_object_contents PARAMS ((bfd *abfd)); | |
71 | |
72 static bfd_boolean | 65 static bfd_boolean |
73 sparclinux_write_object_contents (abfd) | 66 sparclinux_write_object_contents (bfd *abfd) |
74 bfd *abfd; | |
75 { | 67 { |
76 struct external_exec exec_bytes; | 68 struct external_exec exec_bytes; |
77 struct internal_exec *execp = exec_hdr (abfd); | 69 struct internal_exec *execp = exec_hdr (abfd); |
78 | 70 |
79 N_SET_MACHTYPE (*execp, M_SPARC); | 71 N_SET_MACHTYPE (*execp, M_SPARC); |
80 | 72 |
81 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | 73 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; |
82 | 74 |
83 WRITE_HEADERS(abfd, execp); | 75 WRITE_HEADERS(abfd, execp); |
84 | 76 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 /* Number of fixups. */ | 155 /* Number of fixups. */ |
164 size_t fixup_count; | 156 size_t fixup_count; |
165 | 157 |
166 /* Number of builtin fixups. */ | 158 /* Number of builtin fixups. */ |
167 size_t local_builtins; | 159 size_t local_builtins; |
168 | 160 |
169 /* List of fixups. */ | 161 /* List of fixups. */ |
170 struct fixup *fixup_list; | 162 struct fixup *fixup_list; |
171 }; | 163 }; |
172 | 164 |
173 static struct bfd_hash_entry *linux_link_hash_newfunc | |
174 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
175 static struct bfd_link_hash_table *linux_link_hash_table_create | |
176 PARAMS ((bfd *)); | |
177 static struct fixup *new_fixup | |
178 PARAMS ((struct bfd_link_info *, struct linux_link_hash_entry *, | |
179 bfd_vma, int)); | |
180 static bfd_boolean linux_link_create_dynamic_sections | |
181 PARAMS ((bfd *, struct bfd_link_info *)); | |
182 static bfd_boolean linux_add_one_symbol | |
183 PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *, | |
184 bfd_vma, const char *, bfd_boolean, bfd_boolean, | |
185 struct bfd_link_hash_entry **)); | |
186 static bfd_boolean linux_tally_symbols | |
187 PARAMS ((struct linux_link_hash_entry *, PTR)); | |
188 static bfd_boolean linux_finish_dynamic_link | |
189 PARAMS ((bfd *, struct bfd_link_info *)); | |
190 | 165 |
191 /* Routine to create an entry in an Linux link hash table. */ | 166 /* Routine to create an entry in an Linux link hash table. */ |
192 | 167 |
193 static struct bfd_hash_entry * | 168 static struct bfd_hash_entry * |
194 linux_link_hash_newfunc (entry, table, string) | 169 linux_link_hash_newfunc (struct bfd_hash_entry *entry, |
195 struct bfd_hash_entry *entry; | 170 » » » struct bfd_hash_table *table, |
196 struct bfd_hash_table *table; | 171 » » » const char *string) |
197 const char *string; | |
198 { | 172 { |
199 struct linux_link_hash_entry *ret = (struct linux_link_hash_entry *) entry; | 173 struct linux_link_hash_entry *ret = (struct linux_link_hash_entry *) entry; |
200 | 174 |
201 /* Allocate the structure if it has not already been allocated by a | 175 /* Allocate the structure if it has not already been allocated by a |
202 subclass. */ | 176 subclass. */ |
203 if (ret == (struct linux_link_hash_entry *) NULL) | 177 if (ret == (struct linux_link_hash_entry *) NULL) |
204 ret = ((struct linux_link_hash_entry *) | 178 ret = ((struct linux_link_hash_entry *) |
205 bfd_hash_allocate (table, sizeof (struct linux_link_hash_entry))); | 179 bfd_hash_allocate (table, sizeof (struct linux_link_hash_entry))); |
206 if (ret == NULL) | 180 if (ret == NULL) |
207 return (struct bfd_hash_entry *) ret; | 181 return (struct bfd_hash_entry *) ret; |
208 | 182 |
209 /* Call the allocation method of the superclass. */ | 183 /* Call the allocation method of the superclass. */ |
210 ret = ((struct linux_link_hash_entry *) | 184 ret = ((struct linux_link_hash_entry *) |
211 NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret, | 185 NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret, |
212 table, string)); | 186 table, string)); |
213 if (ret != NULL) | 187 if (ret != NULL) |
214 { | 188 { |
215 /* Set local fields; there aren't any. */ | 189 /* Set local fields; there aren't any. */ |
216 } | 190 } |
217 | 191 |
218 return (struct bfd_hash_entry *) ret; | 192 return (struct bfd_hash_entry *) ret; |
219 } | 193 } |
220 | 194 |
221 /* Create a Linux link hash table. */ | 195 /* Create a Linux link hash table. */ |
222 | 196 |
223 static struct bfd_link_hash_table * | 197 static struct bfd_link_hash_table * |
224 linux_link_hash_table_create (abfd) | 198 linux_link_hash_table_create (bfd *abfd) |
225 bfd *abfd; | |
226 { | 199 { |
227 struct linux_link_hash_table *ret; | 200 struct linux_link_hash_table *ret; |
228 bfd_size_type amt = sizeof (struct linux_link_hash_table); | 201 bfd_size_type amt = sizeof (struct linux_link_hash_table); |
229 | 202 |
230 ret = (struct linux_link_hash_table *) bfd_malloc (amt); | 203 ret = (struct linux_link_hash_table *) bfd_malloc (amt); |
231 if (ret == (struct linux_link_hash_table *) NULL) | 204 if (ret == (struct linux_link_hash_table *) NULL) |
232 return (struct bfd_link_hash_table *) NULL; | 205 return (struct bfd_link_hash_table *) NULL; |
233 if (!NAME(aout,link_hash_table_init) (&ret->root, abfd, | 206 if (!NAME(aout,link_hash_table_init) (&ret->root, abfd, |
234 linux_link_hash_newfunc, | 207 linux_link_hash_newfunc, |
235 sizeof (struct linux_link_hash_entry))) | 208 sizeof (struct linux_link_hash_entry))) |
(...skipping 15 matching lines...) Expand all Loading... |
251 #define linux_link_hash_lookup(table, string, create, copy, follow) \ | 224 #define linux_link_hash_lookup(table, string, create, copy, follow) \ |
252 ((struct linux_link_hash_entry *) \ | 225 ((struct linux_link_hash_entry *) \ |
253 aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\ | 226 aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\ |
254 (follow))) | 227 (follow))) |
255 | 228 |
256 /* Traverse a Linux link hash table. */ | 229 /* Traverse a Linux link hash table. */ |
257 | 230 |
258 #define linux_link_hash_traverse(table, func, info) \ | 231 #define linux_link_hash_traverse(table, func, info) \ |
259 (aout_link_hash_traverse \ | 232 (aout_link_hash_traverse \ |
260 (&(table)->root, \ | 233 (&(table)->root, \ |
261 (bfd_boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \ | 234 (bfd_boolean (*) (struct aout_link_hash_entry *, void *)) (func), \ |
262 (info))) | 235 (info))) |
263 | 236 |
264 /* Get the Linux link hash table from the info structure. This is | 237 /* Get the Linux link hash table from the info structure. This is |
265 just a cast. */ | 238 just a cast. */ |
266 | 239 |
267 #define linux_hash_table(p) ((struct linux_link_hash_table *) ((p)->hash)) | 240 #define linux_hash_table(p) ((struct linux_link_hash_table *) ((p)->hash)) |
268 | 241 |
269 /* Store the information for a new fixup. */ | 242 /* Store the information for a new fixup. */ |
270 | 243 |
271 static struct fixup * | 244 static struct fixup * |
272 new_fixup (info, h, value, builtin) | 245 new_fixup (struct bfd_link_info *info, |
273 struct bfd_link_info *info; | 246 » struct linux_link_hash_entry *h, |
274 struct linux_link_hash_entry *h; | 247 » bfd_vma value, |
275 bfd_vma value; | 248 » int builtin) |
276 int builtin; | |
277 { | 249 { |
278 struct fixup *f; | 250 struct fixup *f; |
279 | 251 |
280 f = (struct fixup *) bfd_hash_allocate (&info->hash->table, | 252 f = (struct fixup *) bfd_hash_allocate (&info->hash->table, |
281 sizeof (struct fixup)); | 253 sizeof (struct fixup)); |
282 if (f == NULL) | 254 if (f == NULL) |
283 return f; | 255 return f; |
284 f->next = linux_hash_table (info)->fixup_list; | 256 f->next = linux_hash_table (info)->fixup_list; |
285 linux_hash_table (info)->fixup_list = f; | 257 linux_hash_table (info)->fixup_list = f; |
286 f->h = h; | 258 f->h = h; |
287 f->value = value; | 259 f->value = value; |
288 f->builtin = builtin; | 260 f->builtin = builtin; |
289 f->jump = 0; | 261 f->jump = 0; |
290 ++linux_hash_table (info)->fixup_count; | 262 ++linux_hash_table (info)->fixup_count; |
291 return f; | 263 return f; |
292 } | 264 } |
293 | 265 |
294 /* We come here once we realize that we are going to link to a shared | 266 /* We come here once we realize that we are going to link to a shared |
295 library. We need to create a special section that contains the | 267 library. We need to create a special section that contains the |
296 fixup table, and we ultimately need to add a pointer to this into | 268 fixup table, and we ultimately need to add a pointer to this into |
297 the set vector for SHARABLE_CONFLICTS. At this point we do not | 269 the set vector for SHARABLE_CONFLICTS. At this point we do not |
298 know the size of the section, but that's OK - we just need to | 270 know the size of the section, but that's OK - we just need to |
299 create it for now. */ | 271 create it for now. */ |
300 | 272 |
301 static bfd_boolean | 273 static bfd_boolean |
302 linux_link_create_dynamic_sections (abfd, info) | 274 linux_link_create_dynamic_sections (bfd *abfd, |
303 bfd *abfd; | 275 » » » » struct bfd_link_info *info ATTRIBUTE_UNUSED) |
304 struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
305 { | 276 { |
306 flagword flags; | 277 flagword flags; |
307 register asection *s; | 278 asection *s; |
308 | 279 |
309 /* Note that we set the SEC_IN_MEMORY flag. */ | 280 /* Note that we set the SEC_IN_MEMORY flag. */ |
310 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY; | 281 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY; |
311 | 282 |
312 /* We choose to use the name ".linux-dynamic" for the fixup table. | 283 /* We choose to use the name ".linux-dynamic" for the fixup table. |
313 Why not? */ | 284 Why not? */ |
314 s = bfd_make_section_with_flags (abfd, ".linux-dynamic", flags); | 285 s = bfd_make_section_with_flags (abfd, ".linux-dynamic", flags); |
315 if (s == NULL | 286 if (s == NULL |
316 || ! bfd_set_section_alignment (abfd, s, 2)) | 287 || ! bfd_set_section_alignment (abfd, s, 2)) |
317 return FALSE; | 288 return FALSE; |
318 s->size = 0; | 289 s->size = 0; |
319 s->contents = 0; | 290 s->contents = 0; |
320 | 291 |
321 return TRUE; | 292 return TRUE; |
322 } | 293 } |
323 | 294 |
324 /* Function to add a single symbol to the linker hash table. This is | 295 /* Function to add a single symbol to the linker hash table. This is |
325 a wrapper around _bfd_generic_link_add_one_symbol which handles the | 296 a wrapper around _bfd_generic_link_add_one_symbol which handles the |
326 tweaking needed for dynamic linking support. */ | 297 tweaking needed for dynamic linking support. */ |
327 | 298 |
328 static bfd_boolean | 299 static bfd_boolean |
329 linux_add_one_symbol (info, abfd, name, flags, section, value, string, | 300 linux_add_one_symbol (struct bfd_link_info *info, |
330 » » copy, collect, hashp) | 301 » » bfd *abfd, |
331 struct bfd_link_info *info; | 302 » » const char *name, |
332 bfd *abfd; | 303 » » flagword flags, |
333 const char *name; | 304 » » asection *section, |
334 flagword flags; | 305 » » bfd_vma value, |
335 asection *section; | 306 » » const char *string, |
336 bfd_vma value; | 307 » » bfd_boolean copy, |
337 const char *string; | 308 » » bfd_boolean collect, |
338 bfd_boolean copy; | 309 » » struct bfd_link_hash_entry **hashp) |
339 bfd_boolean collect; | |
340 struct bfd_link_hash_entry **hashp; | |
341 { | 310 { |
342 struct linux_link_hash_entry *h; | 311 struct linux_link_hash_entry *h; |
343 bfd_boolean insert; | 312 bfd_boolean insert; |
344 | 313 |
345 /* Look up and see if we already have this symbol in the hash table. | 314 /* Look up and see if we already have this symbol in the hash table. |
346 If we do, and the defining entry is from a shared library, we | 315 If we do, and the defining entry is from a shared library, we |
347 need to create the dynamic sections. | 316 need to create the dynamic sections. |
348 | 317 |
349 FIXME: What if abfd->xvec != info->output_bfd->xvec? We may | 318 FIXME: What if abfd->xvec != info->output_bfd->xvec? We may |
350 want to be able to link Linux a.out and ELF objects together, | 319 want to be able to link Linux a.out and ELF objects together, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 return TRUE; | 510 return TRUE; |
542 } | 511 } |
543 | 512 |
544 /* This is called to set the size of the .linux-dynamic section is. | 513 /* This is called to set the size of the .linux-dynamic section is. |
545 It is called by the Linux linker emulation before_allocation | 514 It is called by the Linux linker emulation before_allocation |
546 routine. We have finished reading all of the input files, and now | 515 routine. We have finished reading all of the input files, and now |
547 we just scan the hash tables to find out how many additional fixups | 516 we just scan the hash tables to find out how many additional fixups |
548 are required. */ | 517 are required. */ |
549 | 518 |
550 bfd_boolean | 519 bfd_boolean |
551 bfd_sparclinux_size_dynamic_sections (output_bfd, info) | 520 bfd_sparclinux_size_dynamic_sections (bfd *output_bfd, |
552 bfd *output_bfd; | 521 » » » » struct bfd_link_info *info) |
553 struct bfd_link_info *info; | |
554 { | 522 { |
555 struct fixup *f; | 523 struct fixup *f; |
556 asection *s; | 524 asection *s; |
557 | 525 |
558 if (output_bfd->xvec != &MY(vec)) | 526 if (output_bfd->xvec != &MY(vec)) |
559 return TRUE; | 527 return TRUE; |
560 | 528 |
561 /* First find the fixups... */ | 529 /* First find the fixups... */ |
562 linux_link_hash_traverse (linux_hash_table (info), | 530 linux_link_hash_traverse (linux_hash_table (info), |
563 linux_tally_symbols, | 531 linux_tally_symbols, |
564 » » » (PTR) info); | 532 » » » info); |
565 | 533 |
566 /* If there are builtin fixups, leave room for a marker. This is | 534 /* If there are builtin fixups, leave room for a marker. This is |
567 used by the dynamic linker so that it knows that all that follow | 535 used by the dynamic linker so that it knows that all that follow |
568 are builtin fixups instead of regular fixups. */ | 536 are builtin fixups instead of regular fixups. */ |
569 for (f = linux_hash_table (info)->fixup_list; f != NULL; f = f->next) | 537 for (f = linux_hash_table (info)->fixup_list; f != NULL; f = f->next) |
570 { | 538 { |
571 if (f->builtin) | 539 if (f->builtin) |
572 { | 540 { |
573 ++linux_hash_table (info)->fixup_count; | 541 ++linux_hash_table (info)->fixup_count; |
574 ++linux_hash_table (info)->local_builtins; | 542 ++linux_hash_table (info)->local_builtins; |
(...skipping 21 matching lines...) Expand all Loading... |
596 } | 564 } |
597 | 565 |
598 return TRUE; | 566 return TRUE; |
599 } | 567 } |
600 | 568 |
601 /* We come here once we are ready to actually write the fixup table to | 569 /* We come here once we are ready to actually write the fixup table to |
602 the output file. Scan the fixup tables and so forth and generate | 570 the output file. Scan the fixup tables and so forth and generate |
603 the stuff we need. */ | 571 the stuff we need. */ |
604 | 572 |
605 static bfd_boolean | 573 static bfd_boolean |
606 linux_finish_dynamic_link (output_bfd, info) | 574 linux_finish_dynamic_link (bfd *output_bfd, struct bfd_link_info *info) |
607 bfd *output_bfd; | |
608 struct bfd_link_info *info; | |
609 { | 575 { |
610 asection *s, *os, *is; | 576 asection *s, *os, *is; |
611 bfd_byte *fixup_table; | 577 bfd_byte *fixup_table; |
612 struct linux_link_hash_entry *h; | 578 struct linux_link_hash_entry *h; |
613 struct fixup *f; | 579 struct fixup *f; |
614 unsigned int new_addr; | 580 unsigned int new_addr; |
615 int section_offset; | 581 int section_offset; |
616 unsigned int fixups_written; | 582 unsigned int fixups_written; |
617 | 583 |
618 if (linux_hash_table (info)->dynobj == NULL) | 584 if (linux_hash_table (info)->dynobj == NULL) |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 714 |
749 bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table); | 715 bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table); |
750 } | 716 } |
751 else | 717 else |
752 bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table); | 718 bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table); |
753 | 719 |
754 if (bfd_seek (output_bfd, (file_ptr) (os->filepos + s->output_offset), | 720 if (bfd_seek (output_bfd, (file_ptr) (os->filepos + s->output_offset), |
755 SEEK_SET) != 0) | 721 SEEK_SET) != 0) |
756 return FALSE; | 722 return FALSE; |
757 | 723 |
758 if (bfd_bwrite ((PTR) s->contents, s->size, output_bfd) != s->size) | 724 if (bfd_bwrite (s->contents, s->size, output_bfd) != s->size) |
759 return FALSE; | 725 return FALSE; |
760 | 726 |
761 return TRUE; | 727 return TRUE; |
762 } | 728 } |
763 | 729 |
764 #define MY_bfd_link_hash_table_create linux_link_hash_table_create | 730 #define MY_bfd_link_hash_table_create linux_link_hash_table_create |
765 #define MY_add_one_symbol linux_add_one_symbol | 731 #define MY_add_one_symbol linux_add_one_symbol |
766 #define MY_finish_dynamic_link linux_finish_dynamic_link | 732 #define MY_finish_dynamic_link linux_finish_dynamic_link |
767 | 733 |
768 #define MY_zmagic_contiguous 1 | 734 #define MY_zmagic_contiguous 1 |
769 | 735 |
770 #include "aout-target.h" | 736 #include "aout-target.h" |
OLD | NEW |