| OLD | NEW |
| 1 /* BFD back-end for National Semiconductor's CR16 ELF | 1 /* BFD back-end for National Semiconductor's CR16 ELF |
| 2 Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc. | 2 Copyright 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc. |
| 3 Written by M R Swami Reddy. | 3 Written by M R Swami Reddy. |
| 4 | 4 |
| 5 This file is part of BFD, the Binary File Descriptor library. | 5 This file is part of BFD, the Binary File Descriptor library. |
| 6 | 6 |
| 7 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 |
| 8 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 |
| 9 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. | 10 (at your option) any later version. |
| 11 | 11 |
| 12 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, |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 static bfd_boolean | 578 static bfd_boolean |
| 579 _bfd_cr16_elf_create_got_section (bfd * abfd, struct bfd_link_info * info) | 579 _bfd_cr16_elf_create_got_section (bfd * abfd, struct bfd_link_info * info) |
| 580 { | 580 { |
| 581 flagword flags; | 581 flagword flags; |
| 582 asection * s; | 582 asection * s; |
| 583 struct elf_link_hash_entry * h; | 583 struct elf_link_hash_entry * h; |
| 584 const struct elf_backend_data * bed = get_elf_backend_data (abfd); | 584 const struct elf_backend_data * bed = get_elf_backend_data (abfd); |
| 585 int ptralign; | 585 int ptralign; |
| 586 | 586 |
| 587 /* This function may be called more than once. */ | 587 /* This function may be called more than once. */ |
| 588 if (bfd_get_section_by_name (abfd, ".got") != NULL) | 588 if (bfd_get_linker_section (abfd, ".got") != NULL) |
| 589 return TRUE; | 589 return TRUE; |
| 590 | 590 |
| 591 switch (bed->s->arch_size) | 591 switch (bed->s->arch_size) |
| 592 { | 592 { |
| 593 case 16: | 593 case 16: |
| 594 ptralign = 1; | 594 ptralign = 1; |
| 595 break; | 595 break; |
| 596 | 596 |
| 597 case 32: | 597 case 32: |
| 598 ptralign = 2; | 598 ptralign = 2; |
| 599 break; | 599 break; |
| 600 | 600 |
| 601 default: | 601 default: |
| 602 bfd_set_error (bfd_error_bad_value); | 602 bfd_set_error (bfd_error_bad_value); |
| 603 return FALSE; | 603 return FALSE; |
| 604 } | 604 } |
| 605 | 605 |
| 606 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | 606 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
| 607 | SEC_LINKER_CREATED); | 607 | SEC_LINKER_CREATED); |
| 608 | 608 |
| 609 s = bfd_make_section_with_flags (abfd, ".got", flags); | 609 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); |
| 610 if (s == NULL | 610 if (s == NULL |
| 611 || ! bfd_set_section_alignment (abfd, s, ptralign)) | 611 || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 612 return FALSE; | 612 return FALSE; |
| 613 | 613 |
| 614 if (bed->want_got_plt) | 614 if (bed->want_got_plt) |
| 615 { | 615 { |
| 616 s = bfd_make_section_with_flags (abfd, ".got.plt", flags); | 616 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); |
| 617 if (s == NULL | 617 if (s == NULL |
| 618 || ! bfd_set_section_alignment (abfd, s, ptralign)) | 618 || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 619 return FALSE; | 619 return FALSE; |
| 620 } | 620 } |
| 621 | 621 |
| 622 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got | 622 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got |
| 623 (or .got.plt) section. We don't do this in the linker script | 623 (or .got.plt) section. We don't do this in the linker script |
| 624 because we don't want to define the symbol if we are not creating | 624 because we don't want to define the symbol if we are not creating |
| 625 a global offset table. */ | 625 a global offset table. */ |
| 626 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); | 626 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 } | 745 } |
| 746 | 746 |
| 747 switch (ELF32_R_TYPE (rel->r_info)) | 747 switch (ELF32_R_TYPE (rel->r_info)) |
| 748 { | 748 { |
| 749 case R_CR16_GOT_REGREL20: | 749 case R_CR16_GOT_REGREL20: |
| 750 case R_CR16_GOTC_REGREL20: | 750 case R_CR16_GOTC_REGREL20: |
| 751 /* This symbol requires a global offset table entry. */ | 751 /* This symbol requires a global offset table entry. */ |
| 752 | 752 |
| 753 if (sgot == NULL) | 753 if (sgot == NULL) |
| 754 { | 754 { |
| 755 sgot = bfd_get_section_by_name (dynobj, ".got"); | 755 sgot = bfd_get_linker_section (dynobj, ".got"); |
| 756 BFD_ASSERT (sgot != NULL); | 756 BFD_ASSERT (sgot != NULL); |
| 757 } | 757 } |
| 758 | 758 |
| 759 if (srelgot == NULL | 759 if (srelgot == NULL |
| 760 && (h != NULL || info->executable)) | 760 && (h != NULL || info->executable)) |
| 761 { | 761 { |
| 762 srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | 762 srelgot = bfd_get_linker_section (dynobj, ".rela.got"); |
| 763 if (srelgot == NULL) | 763 if (srelgot == NULL) |
| 764 { | 764 { |
| 765 srelgot = bfd_make_section_with_flags (dynobj, | 765 » » flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS |
| 766 ".rela.got", | 766 » » » » | SEC_IN_MEMORY | SEC_LINKER_CREATED |
| 767 (SEC_ALLOC | 767 » » » » | SEC_READONLY); |
| 768 | SEC_LOAD | 768 » » srelgot = bfd_make_section_anyway_with_flags (dynobj, |
| 769 | SEC_HAS_CONTENTS | 769 » » » » » » » » ".rela.got", |
| 770 | SEC_IN_MEMORY | 770 » » » » » » » » flags); |
| 771 | SEC_LINKER_CREATED | |
| 772 | SEC_READONLY)); | |
| 773 if (srelgot == NULL | 771 if (srelgot == NULL |
| 774 || ! bfd_set_section_alignment (dynobj, srelgot, 2)) | 772 || ! bfd_set_section_alignment (dynobj, srelgot, 2)) |
| 775 goto fail; | 773 goto fail; |
| 776 } | 774 } |
| 777 } | 775 } |
| 778 | 776 |
| 779 if (h != NULL) | 777 if (h != NULL) |
| 780 { | 778 { |
| 781 if (h->got.offset != (bfd_vma) -1) | 779 if (h->got.offset != (bfd_vma) -1) |
| 782 /* We have already allocated space in the .got. */ | 780 /* We have already allocated space in the .got. */ |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 /* Check for range. */ | 1038 /* Check for range. */ |
| 1041 if ((long) Rvalue > 0xfffff || (long) Rvalue < 0x0) | 1039 if ((long) Rvalue > 0xfffff || (long) Rvalue < 0x0) |
| 1042 return bfd_reloc_overflow; | 1040 return bfd_reloc_overflow; |
| 1043 | 1041 |
| 1044 bfd_put_16 (input_bfd, ((bfd_get_16 (input_bfd, hit_data) & 0xfff0) | 1042 bfd_put_16 (input_bfd, ((bfd_get_16 (input_bfd, hit_data) & 0xfff0) |
| 1045 | ((Rvalue >> 16) & 0xf)), hit_data); | 1043 | ((Rvalue >> 16) & 0xf)), hit_data); |
| 1046 bfd_put_16 (input_bfd, (Rvalue) & 0xffff, hit_data + 2); | 1044 bfd_put_16 (input_bfd, (Rvalue) & 0xffff, hit_data + 2); |
| 1047 } | 1045 } |
| 1048 else if (r_type == R_CR16_GOT_REGREL20) | 1046 else if (r_type == R_CR16_GOT_REGREL20) |
| 1049 { | 1047 { |
| 1050 asection * sgot = bfd_get_section_by_name (dynobj, ".got"); | 1048 asection * sgot = bfd_get_linker_section (dynobj, ".got"); |
| 1051 | 1049 |
| 1052 if (h != NULL) | 1050 if (h != NULL) |
| 1053 { | 1051 { |
| 1054 bfd_vma off; | 1052 bfd_vma off; |
| 1055 | 1053 |
| 1056 off = h->got.offset; | 1054 off = h->got.offset; |
| 1057 BFD_ASSERT (off != (bfd_vma) -1); | 1055 BFD_ASSERT (off != (bfd_vma) -1); |
| 1058 | 1056 |
| 1059 if (! elf_hash_table (info)->dynamic_sections_created | 1057 if (! elf_hash_table (info)->dynamic_sections_created |
| 1060 || SYMBOL_REFERENCES_LOCAL (info, h)) | 1058 || SYMBOL_REFERENCES_LOCAL (info, h)) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1089 | 1087 |
| 1090 | 1088 |
| 1091 bfd_put_16 (input_bfd, (bfd_get_16 (input_bfd, hit_data)) | 1089 bfd_put_16 (input_bfd, (bfd_get_16 (input_bfd, hit_data)) |
| 1092 | (((Rvalue >> 16) & 0xf) << 8), hit_data); | 1090 | (((Rvalue >> 16) & 0xf) << 8), hit_data); |
| 1093 bfd_put_16 (input_bfd, (Rvalue) & 0xffff, hit_data + 2); | 1091 bfd_put_16 (input_bfd, (Rvalue) & 0xffff, hit_data + 2); |
| 1094 | 1092 |
| 1095 } | 1093 } |
| 1096 else if (r_type == R_CR16_GOTC_REGREL20) | 1094 else if (r_type == R_CR16_GOTC_REGREL20) |
| 1097 { | 1095 { |
| 1098 asection * sgot; | 1096 asection * sgot; |
| 1099 sgot = bfd_get_section_by_name (dynobj, ".got"); | 1097 sgot = bfd_get_linker_section (dynobj, ".got"); |
| 1100 | 1098 |
| 1101 if (h != NULL) | 1099 if (h != NULL) |
| 1102 { | 1100 { |
| 1103 bfd_vma off; | 1101 bfd_vma off; |
| 1104 | 1102 |
| 1105 off = h->got.offset; | 1103 off = h->got.offset; |
| 1106 BFD_ASSERT (off != (bfd_vma) -1); | 1104 BFD_ASSERT (off != (bfd_vma) -1); |
| 1107 | 1105 |
| 1108 Rvalue >>=1; /* For code symbols. */ | 1106 Rvalue >>=1; /* For code symbols. */ |
| 1109 | 1107 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 else | 1422 else |
| 1425 { | 1423 { |
| 1426 bfd_boolean unresolved_reloc, warned; | 1424 bfd_boolean unresolved_reloc, warned; |
| 1427 | 1425 |
| 1428 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, | 1426 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
| 1429 r_symndx, symtab_hdr, sym_hashes, | 1427 r_symndx, symtab_hdr, sym_hashes, |
| 1430 h, sec, relocation, | 1428 h, sec, relocation, |
| 1431 unresolved_reloc, warned); | 1429 unresolved_reloc, warned); |
| 1432 } | 1430 } |
| 1433 | 1431 |
| 1434 if (sec != NULL && elf_discarded_section (sec)) | 1432 if (sec != NULL && discarded_section (sec)) |
| 1435 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, | 1433 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
| 1436 » » » » » rel, relend, howto, contents); | 1434 » » » » » rel, 1, relend, howto, 0, contents); |
| 1437 | 1435 |
| 1438 if (info->relocatable) | 1436 if (info->relocatable) |
| 1439 continue; | 1437 continue; |
| 1440 | 1438 |
| 1441 r = cr16_elf_final_link_relocate (howto, input_bfd, output_bfd, | 1439 r = cr16_elf_final_link_relocate (howto, input_bfd, output_bfd, |
| 1442 input_section, | 1440 input_section, |
| 1443 contents, rel->r_offset, | 1441 contents, rel->r_offset, |
| 1444 relocation, rel->r_addend, | 1442 relocation, rel->r_addend, |
| 1445 (struct elf_link_hash_entry *) h, | 1443 (struct elf_link_hash_entry *) h, |
| 1446 r_symndx, | 1444 r_symndx, |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 bfd_set_error (bfd_error_bad_value); | 2269 bfd_set_error (bfd_error_bad_value); |
| 2272 return FALSE; | 2270 return FALSE; |
| 2273 } | 2271 } |
| 2274 | 2272 |
| 2275 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and | 2273 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and |
| 2276 .rel[a].bss sections. */ | 2274 .rel[a].bss sections. */ |
| 2277 | 2275 |
| 2278 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | 2276 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
| 2279 | SEC_LINKER_CREATED); | 2277 | SEC_LINKER_CREATED); |
| 2280 | 2278 |
| 2281 s = bfd_make_section_with_flags (abfd, | 2279 s = bfd_make_section_anyway_with_flags (abfd, |
| 2282 (bed->default_use_rela_p | 2280 » » » » » (bed->default_use_rela_p |
| 2283 ? ".rela.plt" : ".rel.plt"), | 2281 » » » » » ? ".rela.plt" : ".rel.plt"), |
| 2284 flags | SEC_READONLY); | 2282 » » » » » flags | SEC_READONLY); |
| 2285 if (s == NULL | 2283 if (s == NULL |
| 2286 || ! bfd_set_section_alignment (abfd, s, ptralign)) | 2284 || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 2287 return FALSE; | 2285 return FALSE; |
| 2288 | 2286 |
| 2289 if (! _bfd_cr16_elf_create_got_section (abfd, info)) | 2287 if (! _bfd_cr16_elf_create_got_section (abfd, info)) |
| 2290 return FALSE; | 2288 return FALSE; |
| 2291 | 2289 |
| 2292 { | |
| 2293 const char * secname; | |
| 2294 char * relname; | |
| 2295 flagword secflags; | |
| 2296 asection * sec; | |
| 2297 | |
| 2298 for (sec = abfd->sections; sec; sec = sec->next) | |
| 2299 { | |
| 2300 secflags = bfd_get_section_flags (abfd, sec); | |
| 2301 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED)) | |
| 2302 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS)) | |
| 2303 continue; | |
| 2304 | |
| 2305 secname = bfd_get_section_name (abfd, sec); | |
| 2306 relname = (char *) bfd_malloc (strlen (secname) + 6); | |
| 2307 strcpy (relname, ".rela"); | |
| 2308 strcat (relname, secname); | |
| 2309 | |
| 2310 s = bfd_make_section_with_flags (abfd, relname, | |
| 2311 flags | SEC_READONLY); | |
| 2312 if (s == NULL | |
| 2313 || ! bfd_set_section_alignment (abfd, s, ptralign)) | |
| 2314 return FALSE; | |
| 2315 } | |
| 2316 } | |
| 2317 | |
| 2318 if (bed->want_dynbss) | 2290 if (bed->want_dynbss) |
| 2319 { | 2291 { |
| 2320 /* The .dynbss section is a place to put symbols which are defined | 2292 /* The .dynbss section is a place to put symbols which are defined |
| 2321 by dynamic objects, are referenced by regular objects, and are | 2293 by dynamic objects, are referenced by regular objects, and are |
| 2322 not functions. We must allocate space for them in the process | 2294 not functions. We must allocate space for them in the process |
| 2323 image and use a R_*_COPY reloc to tell the dynamic linker to | 2295 image and use a R_*_COPY reloc to tell the dynamic linker to |
| 2324 initialize them at run time. The linker script puts the .dynbss | 2296 initialize them at run time. The linker script puts the .dynbss |
| 2325 section into the .bss section of the final image. */ | 2297 section into the .bss section of the final image. */ |
| 2326 s = bfd_make_section_with_flags (abfd, ".dynbss", | 2298 s = bfd_make_section_anyway_with_flags (abfd, ".dynbss", |
| 2327 SEC_ALLOC | SEC_LINKER_CREATED); | 2299 » » » » » SEC_ALLOC | SEC_LINKER_CREATED); |
| 2328 if (s == NULL) | 2300 if (s == NULL) |
| 2329 return FALSE; | 2301 return FALSE; |
| 2330 | 2302 |
| 2331 /* The .rel[a].bss section holds copy relocs. This section is not | 2303 /* The .rel[a].bss section holds copy relocs. This section is not |
| 2332 normally needed. We need to create it here, though, so that the | 2304 normally needed. We need to create it here, though, so that the |
| 2333 linker will map it to an output section. We can't just create it | 2305 linker will map it to an output section. We can't just create it |
| 2334 only if we need it, because we will not know whether we need it | 2306 only if we need it, because we will not know whether we need it |
| 2335 until we have seen all the input files, and the first time the | 2307 until we have seen all the input files, and the first time the |
| 2336 main linker code calls BFD after examining all the input files | 2308 main linker code calls BFD after examining all the input files |
| 2337 (size_dynamic_sections) the input sections have already been | 2309 (size_dynamic_sections) the input sections have already been |
| 2338 mapped to the output sections. If the section turns out not to | 2310 mapped to the output sections. If the section turns out not to |
| 2339 be needed, we can discard it later. We will never need this | 2311 be needed, we can discard it later. We will never need this |
| 2340 section when generating a shared object, since they do not use | 2312 section when generating a shared object, since they do not use |
| 2341 copy relocs. */ | 2313 copy relocs. */ |
| 2342 if (! info->executable) | 2314 if (! info->executable) |
| 2343 { | 2315 { |
| 2344 s = bfd_make_section_with_flags (abfd, | 2316 s = bfd_make_section_anyway_with_flags (abfd, |
| 2345 (bed->default_use_rela_p | 2317 » » » » » » (bed->default_use_rela_p |
| 2346 ? ".rela.bss" : ".rel.bss"), | 2318 » » » » » » ? ".rela.bss" : ".rel.bss"), |
| 2347 flags | SEC_READONLY); | 2319 » » » » » » flags | SEC_READONLY); |
| 2348 if (s == NULL | 2320 if (s == NULL |
| 2349 || ! bfd_set_section_alignment (abfd, s, ptralign)) | 2321 || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 2350 return FALSE; | 2322 return FALSE; |
| 2351 } | 2323 } |
| 2352 } | 2324 } |
| 2353 | 2325 |
| 2354 return TRUE; | 2326 return TRUE; |
| 2355 } | 2327 } |
| 2356 | 2328 |
| 2357 | 2329 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2396 BFD_ASSERT (h->needs_plt); | 2368 BFD_ASSERT (h->needs_plt); |
| 2397 return TRUE; | 2369 return TRUE; |
| 2398 } | 2370 } |
| 2399 | 2371 |
| 2400 /* Make sure this symbol is output as a dynamic symbol. */ | 2372 /* Make sure this symbol is output as a dynamic symbol. */ |
| 2401 if (h->dynindx == -1) | 2373 if (h->dynindx == -1) |
| 2402 { | 2374 { |
| 2403 if (! bfd_elf_link_record_dynamic_symbol (info, h)) | 2375 if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 2404 return FALSE; | 2376 return FALSE; |
| 2405 } | 2377 } |
error: old chunk mismatch |
None
| OLD | NEW |