OLD | NEW |
1 // layout.cc -- lay out output file sections for gold | 1 // layout.cc -- lay out output file sections for gold |
2 | 2 |
3 // Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. | 3 // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
4 // Written by Ian Lance Taylor <iant@google.com>. | 4 // Written by Ian Lance Taylor <iant@google.com>. |
5 | 5 |
6 // This file is part of gold. | 6 // This file is part of gold. |
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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 return false; | 342 return false; |
343 } | 343 } |
344 if (parameters->options().strip_lto_sections() | 344 if (parameters->options().strip_lto_sections() |
345 && !parameters->options().relocatable() | 345 && !parameters->options().relocatable() |
346 && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0) | 346 && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0) |
347 { | 347 { |
348 // Ignore LTO sections containing intermediate code. | 348 // Ignore LTO sections containing intermediate code. |
349 if (is_prefix_of(".gnu.lto_", name)) | 349 if (is_prefix_of(".gnu.lto_", name)) |
350 return false; | 350 return false; |
351 } | 351 } |
| 352 // The GNU linker strips .gnu_debuglink sections, so we do too. |
| 353 // This is a feature used to keep debugging information in |
| 354 // separate files. |
| 355 if (strcmp(name, ".gnu_debuglink") == 0) |
| 356 return false; |
352 return true; | 357 return true; |
353 | 358 |
354 default: | 359 default: |
355 return true; | 360 return true; |
356 } | 361 } |
357 } | 362 } |
358 | 363 |
359 // Return an output section named NAME, or NULL if there is none. | 364 // Return an output section named NAME, or NULL if there is none. |
360 | 365 |
361 Output_section* | 366 Output_section* |
(...skipping 19 matching lines...) Expand all Loading... |
381 ++p) | 386 ++p) |
382 if (static_cast<elfcpp::PT>((*p)->type()) == type | 387 if (static_cast<elfcpp::PT>((*p)->type()) == type |
383 && ((*p)->flags() & set) == set | 388 && ((*p)->flags() & set) == set |
384 && ((*p)->flags() & clear) == 0) | 389 && ((*p)->flags() & clear) == 0) |
385 return *p; | 390 return *p; |
386 return NULL; | 391 return NULL; |
387 } | 392 } |
388 | 393 |
389 // Return the output section to use for section NAME with type TYPE | 394 // Return the output section to use for section NAME with type TYPE |
390 // and section flags FLAGS. NAME must be canonicalized in the string | 395 // and section flags FLAGS. NAME must be canonicalized in the string |
391 // pool, and NAME_KEY is the key. | 396 // pool, and NAME_KEY is the key. IS_INTERP is true if this is the |
| 397 // .interp section. IS_DYNAMIC_LINKER_SECTION is true if this section |
| 398 // is used by the dynamic linker. |
392 | 399 |
393 Output_section* | 400 Output_section* |
394 Layout::get_output_section(const char* name, Stringpool::Key name_key, | 401 Layout::get_output_section(const char* name, Stringpool::Key name_key, |
395 » » » elfcpp::Elf_Word type, elfcpp::Elf_Xword flags) | 402 » » » elfcpp::Elf_Word type, elfcpp::Elf_Xword flags, |
| 403 » » » bool is_interp, bool is_dynamic_linker_section) |
396 { | 404 { |
397 elfcpp::Elf_Xword lookup_flags = flags; | 405 elfcpp::Elf_Xword lookup_flags = flags; |
398 | 406 |
399 // Ignoring SHF_WRITE and SHF_EXECINSTR here means that we combine | 407 // Ignoring SHF_WRITE and SHF_EXECINSTR here means that we combine |
400 // read-write with read-only sections. Some other ELF linkers do | 408 // read-write with read-only sections. Some other ELF linkers do |
401 // not do this. FIXME: Perhaps there should be an option | 409 // not do this. FIXME: Perhaps there should be an option |
402 // controlling this. | 410 // controlling this. |
403 lookup_flags &= ~(elfcpp::SHF_WRITE | elfcpp::SHF_EXECINSTR); | 411 lookup_flags &= ~(elfcpp::SHF_WRITE | elfcpp::SHF_EXECINSTR); |
404 | 412 |
405 const Key key(name_key, std::make_pair(type, lookup_flags)); | 413 const Key key(name_key, std::make_pair(type, lookup_flags)); |
(...skipping 28 matching lines...) Expand all Loading... |
434 elfcpp::Elf_Xword zero_flags = 0; | 442 elfcpp::Elf_Xword zero_flags = 0; |
435 const Key zero_key(name_key, std::make_pair(type, zero_flags)); | 443 const Key zero_key(name_key, std::make_pair(type, zero_flags)); |
436 Section_name_map::iterator p = | 444 Section_name_map::iterator p = |
437 this->section_name_map_.find(zero_key); | 445 this->section_name_map_.find(zero_key); |
438 if (p != this->section_name_map_.end()) | 446 if (p != this->section_name_map_.end()) |
439 os = p->second; | 447 os = p->second; |
440 } | 448 } |
441 } | 449 } |
442 | 450 |
443 if (os == NULL) | 451 if (os == NULL) |
444 » os = this->make_output_section(name, type, flags); | 452 » os = this->make_output_section(name, type, flags, is_interp, |
| 453 » » » » is_dynamic_linker_section); |
445 ins.first->second = os; | 454 ins.first->second = os; |
446 return os; | 455 return os; |
447 } | 456 } |
448 } | 457 } |
449 | 458 |
450 // Pick the output section to use for section NAME, in input file | 459 // Pick the output section to use for section NAME, in input file |
451 // RELOBJ, with type TYPE and flags FLAGS. RELOBJ may be NULL for a | 460 // RELOBJ, with type TYPE and flags FLAGS. RELOBJ may be NULL for a |
452 // linker created section. IS_INPUT_SECTION is true if we are | 461 // linker created section. IS_INPUT_SECTION is true if we are |
453 // choosing an output section for an input section found in a input | 462 // choosing an output section for an input section found in a input |
454 // file. This will return NULL if the input section should be | 463 // file. IS_INTERP is true if this is the .interp section. |
455 // discarded. | 464 // IS_DYNAMIC_LINKER_SECTION is true if this section is used by the |
| 465 // dynamic linker. This will return NULL if the input section should |
| 466 // be discarded. |
456 | 467 |
457 Output_section* | 468 Output_section* |
458 Layout::choose_output_section(const Relobj* relobj, const char* name, | 469 Layout::choose_output_section(const Relobj* relobj, const char* name, |
459 elfcpp::Elf_Word type, elfcpp::Elf_Xword flags, | 470 elfcpp::Elf_Word type, elfcpp::Elf_Xword flags, |
460 » » » bool is_input_section) | 471 » » » bool is_input_section, bool is_interp, |
| 472 » » » bool is_dynamic_linker_section) |
461 { | 473 { |
462 // We should not see any input sections after we have attached | 474 // We should not see any input sections after we have attached |
463 // sections to segments. | 475 // sections to segments. |
464 gold_assert(!is_input_section || !this->sections_are_attached_); | 476 gold_assert(!is_input_section || !this->sections_are_attached_); |
465 | 477 |
466 // Some flags in the input section should not be automatically | 478 // Some flags in the input section should not be automatically |
467 // copied to the output section. | 479 // copied to the output section. |
468 flags &= ~ (elfcpp::SHF_INFO_LINK | 480 flags &= ~ (elfcpp::SHF_INFO_LINK |
469 | elfcpp::SHF_LINK_ORDER | 481 | elfcpp::SHF_LINK_ORDER |
470 | elfcpp::SHF_GROUP | 482 | elfcpp::SHF_GROUP |
(...skipping 27 matching lines...) Expand all Loading... |
498 return *output_section_slot; | 510 return *output_section_slot; |
499 } | 511 } |
500 | 512 |
501 // We don't put sections found in the linker script into | 513 // We don't put sections found in the linker script into |
502 // SECTION_NAME_MAP_. That keeps us from getting confused | 514 // SECTION_NAME_MAP_. That keeps us from getting confused |
503 // if an orphan section is mapped to a section with the same | 515 // if an orphan section is mapped to a section with the same |
504 // name as one in the linker script. | 516 // name as one in the linker script. |
505 | 517 |
506 name = this->namepool_.add(name, false, NULL); | 518 name = this->namepool_.add(name, false, NULL); |
507 | 519 |
508 » Output_section* os = this->make_output_section(name, type, flags); | 520 » Output_section* os = |
| 521 » this->make_output_section(name, type, flags, is_interp, |
| 522 » » » » is_dynamic_linker_section); |
509 os->set_found_in_sections_clause(); | 523 os->set_found_in_sections_clause(); |
510 *output_section_slot = os; | 524 *output_section_slot = os; |
511 return os; | 525 return os; |
512 } | 526 } |
513 } | 527 } |
514 | 528 |
515 // FIXME: Handle SHF_OS_NONCONFORMING somewhere. | 529 // FIXME: Handle SHF_OS_NONCONFORMING somewhere. |
516 | 530 |
517 // Turn NAME from the name of the input section into the name of the | 531 // Turn NAME from the name of the input section into the name of the |
518 // output section. | 532 // output section. |
519 | 533 |
520 size_t len = strlen(name); | 534 size_t len = strlen(name); |
521 if (is_input_section | 535 if (is_input_section |
522 && !this->script_options_->saw_sections_clause() | 536 && !this->script_options_->saw_sections_clause() |
523 && !parameters->options().relocatable()) | 537 && !parameters->options().relocatable()) |
524 name = Layout::output_section_name(name, &len); | 538 name = Layout::output_section_name(name, &len); |
525 | 539 |
526 Stringpool::Key name_key; | 540 Stringpool::Key name_key; |
527 name = this->namepool_.add_with_length(name, len, true, &name_key); | 541 name = this->namepool_.add_with_length(name, len, true, &name_key); |
528 | 542 |
529 // Find or make the output section. The output section is selected | 543 // Find or make the output section. The output section is selected |
530 // based on the section name, type, and flags. | 544 // based on the section name, type, and flags. |
531 return this->get_output_section(name, name_key, type, flags); | 545 return this->get_output_section(name, name_key, type, flags, is_interp, |
| 546 » » » » is_dynamic_linker_section); |
532 } | 547 } |
533 | 548 |
534 // Return the output section to use for input section SHNDX, with name | 549 // Return the output section to use for input section SHNDX, with name |
535 // NAME, with header HEADER, from object OBJECT. RELOC_SHNDX is the | 550 // NAME, with header HEADER, from object OBJECT. RELOC_SHNDX is the |
536 // index of a relocation section which applies to this section, or 0 | 551 // index of a relocation section which applies to this section, or 0 |
537 // if none, or -1U if more than one. RELOC_TYPE is the type of the | 552 // if none, or -1U if more than one. RELOC_TYPE is the type of the |
538 // relocation section if there is one. Set *OFF to the offset of this | 553 // relocation section if there is one. Set *OFF to the offset of this |
539 // input section without the output section. Return NULL if the | 554 // input section without the output section. Return NULL if the |
540 // section should be discarded. Set *OFF to -1 if the section | 555 // section should be discarded. Set *OFF to -1 if the section |
541 // contents should not be written directly to the output file, but | 556 // contents should not be written directly to the output file, but |
(...skipping 12 matching lines...) Expand all Loading... |
554 | 569 |
555 Output_section* os; | 570 Output_section* os; |
556 | 571 |
557 // In a relocatable link a grouped section must not be combined with | 572 // In a relocatable link a grouped section must not be combined with |
558 // any other sections. | 573 // any other sections. |
559 if (parameters->options().relocatable() | 574 if (parameters->options().relocatable() |
560 && (shdr.get_sh_flags() & elfcpp::SHF_GROUP) != 0) | 575 && (shdr.get_sh_flags() & elfcpp::SHF_GROUP) != 0) |
561 { | 576 { |
562 name = this->namepool_.add(name, true, NULL); | 577 name = this->namepool_.add(name, true, NULL); |
563 os = this->make_output_section(name, shdr.get_sh_type(), | 578 os = this->make_output_section(name, shdr.get_sh_type(), |
564 » » » » shdr.get_sh_flags()); | 579 » » » » shdr.get_sh_flags(), false, false); |
565 } | 580 } |
566 else | 581 else |
567 { | 582 { |
568 os = this->choose_output_section(object, name, shdr.get_sh_type(), | 583 os = this->choose_output_section(object, name, shdr.get_sh_type(), |
569 » » » » shdr.get_sh_flags(), true); | 584 » » » » shdr.get_sh_flags(), true, false, |
| 585 » » » » false); |
570 if (os == NULL) | 586 if (os == NULL) |
571 return NULL; | 587 return NULL; |
572 } | 588 } |
573 | 589 |
574 // By default the GNU linker sorts input sections whose names match | 590 // By default the GNU linker sorts input sections whose names match |
575 // .ctor.*, .dtor.*, .init_array.*, or .fini_array.*. The sections | 591 // .ctor.*, .dtor.*, .init_array.*, or .fini_array.*. The sections |
576 // are sorted by name. This is used to implement constructor | 592 // are sorted by name. This is used to implement constructor |
577 // priority ordering. We are compatible. | 593 // priority ordering. We are compatible. |
578 if (!this->script_options_->saw_sections_clause() | 594 if (!this->script_options_->saw_sections_clause() |
579 && (is_prefix_of(".ctors.", name) | 595 && (is_prefix_of(".ctors.", name) |
(...skipping 30 matching lines...) Expand all Loading... |
610 name = ".rel"; | 626 name = ".rel"; |
611 else if (sh_type == elfcpp::SHT_RELA) | 627 else if (sh_type == elfcpp::SHT_RELA) |
612 name = ".rela"; | 628 name = ".rela"; |
613 else | 629 else |
614 gold_unreachable(); | 630 gold_unreachable(); |
615 name += data_section->name(); | 631 name += data_section->name(); |
616 | 632 |
617 Output_section* os = this->choose_output_section(object, name.c_str(), | 633 Output_section* os = this->choose_output_section(object, name.c_str(), |
618 sh_type, | 634 sh_type, |
619 shdr.get_sh_flags(), | 635 shdr.get_sh_flags(), |
620 » » » » » » false); | 636 » » » » » » false, false, false); |
621 | 637 |
622 os->set_should_link_to_symtab(); | 638 os->set_should_link_to_symtab(); |
623 os->set_info_section(data_section); | 639 os->set_info_section(data_section); |
624 | 640 |
625 Output_section_data* posd; | 641 Output_section_data* posd; |
626 if (sh_type == elfcpp::SHT_REL) | 642 if (sh_type == elfcpp::SHT_REL) |
627 { | 643 { |
628 os->set_entsize(elfcpp::Elf_sizes<size>::rel_size); | 644 os->set_entsize(elfcpp::Elf_sizes<size>::rel_size); |
629 posd = new Output_relocatable_relocs<elfcpp::SHT_REL, | 645 posd = new Output_relocatable_relocs<elfcpp::SHT_REL, |
630 size, | 646 size, |
(...skipping 26 matching lines...) Expand all Loading... |
657 const char* signature, | 673 const char* signature, |
658 const elfcpp::Shdr<size, big_endian>& shdr, | 674 const elfcpp::Shdr<size, big_endian>& shdr, |
659 elfcpp::Elf_Word flags, | 675 elfcpp::Elf_Word flags, |
660 std::vector<unsigned int>* shndxes) | 676 std::vector<unsigned int>* shndxes) |
661 { | 677 { |
662 gold_assert(parameters->options().relocatable()); | 678 gold_assert(parameters->options().relocatable()); |
663 gold_assert(shdr.get_sh_type() == elfcpp::SHT_GROUP); | 679 gold_assert(shdr.get_sh_type() == elfcpp::SHT_GROUP); |
664 group_section_name = this->namepool_.add(group_section_name, true, NULL); | 680 group_section_name = this->namepool_.add(group_section_name, true, NULL); |
665 Output_section* os = this->make_output_section(group_section_name, | 681 Output_section* os = this->make_output_section(group_section_name, |
666 elfcpp::SHT_GROUP, | 682 elfcpp::SHT_GROUP, |
667 » » » » » » shdr.get_sh_flags()); | 683 » » » » » » shdr.get_sh_flags(), |
| 684 » » » » » » false, false); |
668 | 685 |
669 // We need to find a symbol with the signature in the symbol table. | 686 // We need to find a symbol with the signature in the symbol table. |
670 // If we don't find one now, we need to look again later. | 687 // If we don't find one now, we need to look again later. |
671 Symbol* sym = symtab->lookup(signature, NULL); | 688 Symbol* sym = symtab->lookup(signature, NULL); |
672 if (sym != NULL) | 689 if (sym != NULL) |
673 os->set_info_symndx(sym); | 690 os->set_info_symndx(sym); |
674 else | 691 else |
675 { | 692 { |
676 // Reserve some space to minimize reallocations. | 693 // Reserve some space to minimize reallocations. |
677 if (this->group_signatures_.empty()) | 694 if (this->group_signatures_.empty()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 off_t* off) | 728 off_t* off) |
712 { | 729 { |
713 gold_assert(shdr.get_sh_type() == elfcpp::SHT_PROGBITS); | 730 gold_assert(shdr.get_sh_type() == elfcpp::SHT_PROGBITS); |
714 gold_assert((shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0); | 731 gold_assert((shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0); |
715 | 732 |
716 const char* const name = ".eh_frame"; | 733 const char* const name = ".eh_frame"; |
717 Output_section* os = this->choose_output_section(object, | 734 Output_section* os = this->choose_output_section(object, |
718 name, | 735 name, |
719 elfcpp::SHT_PROGBITS, | 736 elfcpp::SHT_PROGBITS, |
720 elfcpp::SHF_ALLOC, | 737 elfcpp::SHF_ALLOC, |
721 » » » » » » false); | 738 » » » » » » false, false, false); |
722 if (os == NULL) | 739 if (os == NULL) |
723 return NULL; | 740 return NULL; |
724 | 741 |
725 if (this->eh_frame_section_ == NULL) | 742 if (this->eh_frame_section_ == NULL) |
726 { | 743 { |
727 this->eh_frame_section_ = os; | 744 this->eh_frame_section_ = os; |
728 this->eh_frame_data_ = new Eh_frame(); | 745 this->eh_frame_data_ = new Eh_frame(); |
729 | 746 |
730 if (parameters->options().eh_frame_hdr()) | 747 if (parameters->options().eh_frame_hdr()) |
731 { | 748 { |
732 Output_section* hdr_os = | 749 Output_section* hdr_os = |
733 this->choose_output_section(NULL, | 750 this->choose_output_section(NULL, |
734 ".eh_frame_hdr", | 751 ".eh_frame_hdr", |
735 elfcpp::SHT_PROGBITS, | 752 elfcpp::SHT_PROGBITS, |
736 elfcpp::SHF_ALLOC, | 753 elfcpp::SHF_ALLOC, |
737 » » » » » false); | 754 » » » » » false, false, false); |
738 | 755 |
739 if (hdr_os != NULL) | 756 if (hdr_os != NULL) |
740 { | 757 { |
741 Eh_frame_hdr* hdr_posd = new Eh_frame_hdr(os, | 758 Eh_frame_hdr* hdr_posd = new Eh_frame_hdr(os, |
742 this->eh_frame_data_); | 759 this->eh_frame_data_); |
743 hdr_os->add_output_section_data(hdr_posd); | 760 hdr_os->add_output_section_data(hdr_posd); |
744 | 761 |
745 hdr_os->set_after_input_sections(); | 762 hdr_os->set_after_input_sections(); |
746 | 763 |
747 if (!this->script_options_->saw_phdrs_clause()) | 764 if (!this->script_options_->saw_phdrs_clause()) |
748 { | 765 { |
749 Output_segment* hdr_oseg; | 766 Output_segment* hdr_oseg; |
750 hdr_oseg = this->make_output_segment(elfcpp::PT_GNU_EH_FRAME, | 767 hdr_oseg = this->make_output_segment(elfcpp::PT_GNU_EH_FRAME, |
751 elfcpp::PF_R); | 768 elfcpp::PF_R); |
752 » » hdr_oseg->add_output_section(hdr_os, elfcpp::PF_R); | 769 » » hdr_oseg->add_output_section(hdr_os, elfcpp::PF_R, false); |
753 } | 770 } |
754 | 771 |
755 this->eh_frame_data_->set_eh_frame_hdr(hdr_posd); | 772 this->eh_frame_data_->set_eh_frame_hdr(hdr_posd); |
756 } | 773 } |
757 } | 774 } |
758 } | 775 } |
759 | 776 |
760 gold_assert(this->eh_frame_section_ == os); | 777 gold_assert(this->eh_frame_section_ == os); |
761 | 778 |
762 if (this->eh_frame_data_->add_ehframe_input_section(object, | 779 if (this->eh_frame_data_->add_ehframe_input_section(object, |
(...skipping 30 matching lines...) Expand all Loading... |
793 | 810 |
794 return os; | 811 return os; |
795 } | 812 } |
796 | 813 |
797 // Add POSD to an output section using NAME, TYPE, and FLAGS. Return | 814 // Add POSD to an output section using NAME, TYPE, and FLAGS. Return |
798 // the output section. | 815 // the output section. |
799 | 816 |
800 Output_section* | 817 Output_section* |
801 Layout::add_output_section_data(const char* name, elfcpp::Elf_Word type, | 818 Layout::add_output_section_data(const char* name, elfcpp::Elf_Word type, |
802 elfcpp::Elf_Xword flags, | 819 elfcpp::Elf_Xword flags, |
803 » » » » Output_section_data* posd) | 820 » » » » Output_section_data* posd, |
| 821 » » » » bool is_dynamic_linker_section) |
804 { | 822 { |
805 Output_section* os = this->choose_output_section(NULL, name, type, flags, | 823 Output_section* os = this->choose_output_section(NULL, name, type, flags, |
806 » » » » » » false); | 824 » » » » » » false, false, |
| 825 » » » » » » is_dynamic_linker_section); |
807 if (os != NULL) | 826 if (os != NULL) |
808 os->add_output_section_data(posd); | 827 os->add_output_section_data(posd); |
809 return os; | 828 return os; |
810 } | 829 } |
811 | 830 |
812 // Map section flags to segment flags. | 831 // Map section flags to segment flags. |
813 | 832 |
814 elfcpp::Elf_Word | 833 elfcpp::Elf_Word |
815 Layout::section_flags_to_segment(elfcpp::Elf_Xword flags) | 834 Layout::section_flags_to_segment(elfcpp::Elf_Xword flags) |
816 { | 835 { |
(...skipping 14 matching lines...) Expand all Loading... |
831 // (The Output_compressed_section class decides whether to compress | 850 // (The Output_compressed_section class decides whether to compress |
832 // a given section, and picks the name of the compressed section.) | 851 // a given section, and picks the name of the compressed section.) |
833 | 852 |
834 static bool | 853 static bool |
835 is_compressible_debug_section(const char* secname) | 854 is_compressible_debug_section(const char* secname) |
836 { | 855 { |
837 return (strncmp(secname, ".debug", sizeof(".debug") - 1) == 0); | 856 return (strncmp(secname, ".debug", sizeof(".debug") - 1) == 0); |
838 } | 857 } |
839 | 858 |
840 // Make a new Output_section, and attach it to segments as | 859 // Make a new Output_section, and attach it to segments as |
841 // appropriate. | 860 // appropriate. IS_INTERP is true if this is the .interp section. |
| 861 // IS_DYNAMIC_LINKER_SECTION is true if this section is used by the |
| 862 // dynamic linker. |
842 | 863 |
843 Output_section* | 864 Output_section* |
844 Layout::make_output_section(const char* name, elfcpp::Elf_Word type, | 865 Layout::make_output_section(const char* name, elfcpp::Elf_Word type, |
845 » » » elfcpp::Elf_Xword flags) | 866 » » » elfcpp::Elf_Xword flags, bool is_interp, |
| 867 » » » bool is_dynamic_linker_section) |
846 { | 868 { |
847 Output_section* os; | 869 Output_section* os; |
848 if ((flags & elfcpp::SHF_ALLOC) == 0 | 870 if ((flags & elfcpp::SHF_ALLOC) == 0 |
849 && strcmp(parameters->options().compress_debug_sections(), "none") != 0 | 871 && strcmp(parameters->options().compress_debug_sections(), "none") != 0 |
850 && is_compressible_debug_section(name)) | 872 && is_compressible_debug_section(name)) |
851 os = new Output_compressed_section(¶meters->options(), name, type, | 873 os = new Output_compressed_section(¶meters->options(), name, type, |
852 flags); | 874 flags); |
853 | |
854 else if ((flags & elfcpp::SHF_ALLOC) == 0 | 875 else if ((flags & elfcpp::SHF_ALLOC) == 0 |
855 && parameters->options().strip_debug_non_line() | 876 && parameters->options().strip_debug_non_line() |
856 && strcmp(".debug_abbrev", name) == 0) | 877 && strcmp(".debug_abbrev", name) == 0) |
857 { | 878 { |
858 os = this->debug_abbrev_ = new Output_reduced_debug_abbrev_section( | 879 os = this->debug_abbrev_ = new Output_reduced_debug_abbrev_section( |
859 name, type, flags); | 880 name, type, flags); |
860 if (this->debug_info_) | 881 if (this->debug_info_) |
861 this->debug_info_->set_abbreviations(this->debug_abbrev_); | 882 this->debug_info_->set_abbreviations(this->debug_abbrev_); |
862 } | 883 } |
863 else if ((flags & elfcpp::SHF_ALLOC) == 0 | 884 else if ((flags & elfcpp::SHF_ALLOC) == 0 |
864 && parameters->options().strip_debug_non_line() | 885 && parameters->options().strip_debug_non_line() |
865 && strcmp(".debug_info", name) == 0) | 886 && strcmp(".debug_info", name) == 0) |
866 { | 887 { |
867 os = this->debug_info_ = new Output_reduced_debug_info_section( | 888 os = this->debug_info_ = new Output_reduced_debug_info_section( |
868 name, type, flags); | 889 name, type, flags); |
869 if (this->debug_abbrev_) | 890 if (this->debug_abbrev_) |
870 this->debug_info_->set_abbreviations(this->debug_abbrev_); | 891 this->debug_info_->set_abbreviations(this->debug_abbrev_); |
871 } | 892 } |
872 else | 893 else |
873 { | 894 { |
874 // FIXME: const_cast is ugly. | 895 // FIXME: const_cast is ugly. |
875 Target* target = const_cast<Target*>(¶meters->target()); | 896 Target* target = const_cast<Target*>(¶meters->target()); |
876 os = target->make_output_section(name, type, flags); | 897 os = target->make_output_section(name, type, flags); |
877 } | 898 } |
878 | 899 |
| 900 if (is_interp) |
| 901 os->set_is_interp(); |
| 902 if (is_dynamic_linker_section) |
| 903 os->set_is_dynamic_linker_section(); |
| 904 |
879 parameters->target().new_output_section(os); | 905 parameters->target().new_output_section(os); |
880 | 906 |
881 this->section_list_.push_back(os); | 907 this->section_list_.push_back(os); |
882 | 908 |
883 // The GNU linker by default sorts some sections by priority, so we | 909 // The GNU linker by default sorts some sections by priority, so we |
884 // do the same. We need to know that this might happen before we | 910 // do the same. We need to know that this might happen before we |
885 // attach any input sections. | 911 // attach any input sections. |
886 if (!this->script_options_->saw_sections_clause() | 912 if (!this->script_options_->saw_sections_clause() |
887 && (strcmp(name, ".ctors") == 0 | 913 && (strcmp(name, ".ctors") == 0 |
888 || strcmp(name, ".dtors") == 0 | 914 || strcmp(name, ".dtors") == 0 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 // segments until after we've seen all the sections. | 990 // segments until after we've seen all the sections. |
965 if (this->script_options_->saw_sections_clause()) | 991 if (this->script_options_->saw_sections_clause()) |
966 return; | 992 return; |
967 | 993 |
968 gold_assert(!this->script_options_->saw_phdrs_clause()); | 994 gold_assert(!this->script_options_->saw_phdrs_clause()); |
969 | 995 |
970 // This output section goes into a PT_LOAD segment. | 996 // This output section goes into a PT_LOAD segment. |
971 | 997 |
972 elfcpp::Elf_Word seg_flags = Layout::section_flags_to_segment(flags); | 998 elfcpp::Elf_Word seg_flags = Layout::section_flags_to_segment(flags); |
973 | 999 |
| 1000 bool sort_sections = !this->script_options_->saw_sections_clause(); |
| 1001 |
974 // In general the only thing we really care about for PT_LOAD | 1002 // In general the only thing we really care about for PT_LOAD |
975 // segments is whether or not they are writable, so that is how we | 1003 // segments is whether or not they are writable, so that is how we |
976 // search for them. Large data sections also go into their own | 1004 // search for them. Large data sections also go into their own |
977 // PT_LOAD segment. People who need segments sorted on some other | 1005 // PT_LOAD segment. People who need segments sorted on some other |
978 // basis will have to use a linker script. | 1006 // basis will have to use a linker script. |
979 | 1007 |
980 Segment_list::const_iterator p; | 1008 Segment_list::const_iterator p; |
981 for (p = this->segment_list_.begin(); | 1009 for (p = this->segment_list_.begin(); |
982 p != this->segment_list_.end(); | 1010 p != this->segment_list_.end(); |
983 ++p) | 1011 ++p) |
984 { | 1012 { |
985 if ((*p)->type() != elfcpp::PT_LOAD) | 1013 if ((*p)->type() != elfcpp::PT_LOAD) |
986 continue; | 1014 continue; |
987 if (!parameters->options().omagic() | 1015 if (!parameters->options().omagic() |
988 && ((*p)->flags() & elfcpp::PF_W) != (seg_flags & elfcpp::PF_W)) | 1016 && ((*p)->flags() & elfcpp::PF_W) != (seg_flags & elfcpp::PF_W)) |
989 continue; | 1017 continue; |
990 // If -Tbss was specified, we need to separate the data and BSS | 1018 // If -Tbss was specified, we need to separate the data and BSS |
991 // segments. | 1019 // segments. |
992 if (parameters->options().user_set_Tbss()) | 1020 if (parameters->options().user_set_Tbss()) |
993 { | 1021 { |
994 if ((os->type() == elfcpp::SHT_NOBITS) | 1022 if ((os->type() == elfcpp::SHT_NOBITS) |
995 == (*p)->has_any_data_sections()) | 1023 == (*p)->has_any_data_sections()) |
996 continue; | 1024 continue; |
997 } | 1025 } |
998 if (os->is_large_data_section() && !(*p)->is_large_data_segment()) | 1026 if (os->is_large_data_section() && !(*p)->is_large_data_segment()) |
999 continue; | 1027 continue; |
1000 | 1028 |
1001 (*p)->add_output_section(os, seg_flags); | 1029 (*p)->add_output_section(os, seg_flags, sort_sections); |
1002 break; | 1030 break; |
1003 } | 1031 } |
1004 | 1032 |
1005 if (p == this->segment_list_.end()) | 1033 if (p == this->segment_list_.end()) |
1006 { | 1034 { |
1007 Output_segment* oseg = this->make_output_segment(elfcpp::PT_LOAD, | 1035 Output_segment* oseg = this->make_output_segment(elfcpp::PT_LOAD, |
1008 seg_flags); | 1036 seg_flags); |
1009 if (os->is_large_data_section()) | 1037 if (os->is_large_data_section()) |
1010 oseg->set_is_large_data_segment(); | 1038 oseg->set_is_large_data_segment(); |
1011 oseg->add_output_section(os, seg_flags); | 1039 oseg->add_output_section(os, seg_flags, sort_sections); |
1012 } | 1040 } |
1013 | 1041 |
1014 // If we see a loadable SHT_NOTE section, we create a PT_NOTE | 1042 // If we see a loadable SHT_NOTE section, we create a PT_NOTE |
1015 // segment. | 1043 // segment. |
1016 if (os->type() == elfcpp::SHT_NOTE) | 1044 if (os->type() == elfcpp::SHT_NOTE) |
1017 { | 1045 { |
1018 // See if we already have an equivalent PT_NOTE segment. | 1046 // See if we already have an equivalent PT_NOTE segment. |
1019 for (p = this->segment_list_.begin(); | 1047 for (p = this->segment_list_.begin(); |
1020 p != segment_list_.end(); | 1048 p != segment_list_.end(); |
1021 ++p) | 1049 ++p) |
1022 { | 1050 { |
1023 if ((*p)->type() == elfcpp::PT_NOTE | 1051 if ((*p)->type() == elfcpp::PT_NOTE |
1024 && (((*p)->flags() & elfcpp::PF_W) | 1052 && (((*p)->flags() & elfcpp::PF_W) |
1025 == (seg_flags & elfcpp::PF_W))) | 1053 == (seg_flags & elfcpp::PF_W))) |
1026 { | 1054 { |
1027 (*p)->add_output_section(os, seg_flags); | 1055 (*p)->add_output_section(os, seg_flags, false); |
1028 break; | 1056 break; |
1029 } | 1057 } |
1030 } | 1058 } |
1031 | 1059 |
1032 if (p == this->segment_list_.end()) | 1060 if (p == this->segment_list_.end()) |
1033 { | 1061 { |
1034 Output_segment* oseg = this->make_output_segment(elfcpp::PT_NOTE, | 1062 Output_segment* oseg = this->make_output_segment(elfcpp::PT_NOTE, |
1035 seg_flags); | 1063 seg_flags); |
1036 oseg->add_output_section(os, seg_flags); | 1064 oseg->add_output_section(os, seg_flags, false); |
1037 } | 1065 } |
1038 } | 1066 } |
1039 | 1067 |
1040 // If we see a loadable SHF_TLS section, we create a PT_TLS | 1068 // If we see a loadable SHF_TLS section, we create a PT_TLS |
1041 // segment. There can only be one such segment. | 1069 // segment. There can only be one such segment. |
1042 if ((flags & elfcpp::SHF_TLS) != 0) | 1070 if ((flags & elfcpp::SHF_TLS) != 0) |
1043 { | 1071 { |
1044 if (this->tls_segment_ == NULL) | 1072 if (this->tls_segment_ == NULL) |
1045 this->make_output_segment(elfcpp::PT_TLS, seg_flags); | 1073 this->make_output_segment(elfcpp::PT_TLS, seg_flags); |
1046 this->tls_segment_->add_output_section(os, seg_flags); | 1074 this->tls_segment_->add_output_section(os, seg_flags, false); |
1047 } | 1075 } |
1048 | 1076 |
1049 // If -z relro is in effect, and we see a relro section, we create a | 1077 // If -z relro is in effect, and we see a relro section, we create a |
1050 // PT_GNU_RELRO segment. There can only be one such segment. | 1078 // PT_GNU_RELRO segment. There can only be one such segment. |
1051 if (os->is_relro() && parameters->options().relro()) | 1079 if (os->is_relro() && parameters->options().relro()) |
1052 { | 1080 { |
1053 gold_assert(seg_flags == (elfcpp::PF_R | elfcpp::PF_W)); | 1081 gold_assert(seg_flags == (elfcpp::PF_R | elfcpp::PF_W)); |
1054 if (this->relro_segment_ == NULL) | 1082 if (this->relro_segment_ == NULL) |
1055 this->make_output_segment(elfcpp::PT_GNU_RELRO, seg_flags); | 1083 this->make_output_segment(elfcpp::PT_GNU_RELRO, seg_flags); |
1056 this->relro_segment_->add_output_section(os, seg_flags); | 1084 this->relro_segment_->add_output_section(os, seg_flags, false); |
1057 } | 1085 } |
1058 } | 1086 } |
1059 | 1087 |
1060 // Make an output section for a script. | 1088 // Make an output section for a script. |
1061 | 1089 |
1062 Output_section* | 1090 Output_section* |
1063 Layout::make_output_section_for_script(const char* name) | 1091 Layout::make_output_section_for_script(const char* name) |
1064 { | 1092 { |
1065 name = this->namepool_.add(name, false, NULL); | 1093 name = this->namepool_.add(name, false, NULL); |
1066 Output_section* os = this->make_output_section(name, elfcpp::SHT_PROGBITS, | 1094 Output_section* os = this->make_output_section(name, elfcpp::SHT_PROGBITS, |
1067 » » » » » » elfcpp::SHF_ALLOC); | 1095 » » » » » » elfcpp::SHF_ALLOC, false, |
| 1096 » » » » » » false); |
1068 os->set_found_in_sections_clause(); | 1097 os->set_found_in_sections_clause(); |
1069 return os; | 1098 return os; |
1070 } | 1099 } |
1071 | 1100 |
1072 // Return the number of segments we expect to see. | 1101 // Return the number of segments we expect to see. |
1073 | 1102 |
1074 size_t | 1103 size_t |
1075 Layout::expected_segment_count() const | 1104 Layout::expected_segment_count() const |
1076 { | 1105 { |
1077 size_t ret = this->segment_list_.size(); | 1106 size_t ret = this->segment_list_.size(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 void | 1156 void |
1128 Layout::create_initial_dynamic_sections(Symbol_table* symtab) | 1157 Layout::create_initial_dynamic_sections(Symbol_table* symtab) |
1129 { | 1158 { |
1130 if (parameters->doing_static_link()) | 1159 if (parameters->doing_static_link()) |
1131 return; | 1160 return; |
1132 | 1161 |
1133 this->dynamic_section_ = this->choose_output_section(NULL, ".dynamic", | 1162 this->dynamic_section_ = this->choose_output_section(NULL, ".dynamic", |
1134 elfcpp::SHT_DYNAMIC, | 1163 elfcpp::SHT_DYNAMIC, |
1135 (elfcpp::SHF_ALLOC | 1164 (elfcpp::SHF_ALLOC |
1136 | elfcpp::SHF_WRITE), | 1165 | elfcpp::SHF_WRITE), |
1137 » » » » » » false); | 1166 » » » » » » false, false, true); |
1138 this->dynamic_section_->set_is_relro(); | 1167 this->dynamic_section_->set_is_relro(); |
1139 | 1168 |
1140 symtab->define_in_output_data("_DYNAMIC", NULL, this->dynamic_section_, 0, 0, | 1169 symtab->define_in_output_data("_DYNAMIC", NULL, this->dynamic_section_, 0, 0, |
1141 elfcpp::STT_OBJECT, elfcpp::STB_LOCAL, | 1170 elfcpp::STT_OBJECT, elfcpp::STB_LOCAL, |
1142 elfcpp::STV_HIDDEN, 0, false, false); | 1171 elfcpp::STV_HIDDEN, 0, false, false); |
1143 | 1172 |
1144 this->dynamic_data_ = new Output_data_dynamic(&this->dynpool_); | 1173 this->dynamic_data_ = new Output_data_dynamic(&this->dynpool_); |
1145 | 1174 |
1146 this->dynamic_section_->add_output_section_data(this->dynamic_data_); | 1175 this->dynamic_section_->add_output_section_data(this->dynamic_data_); |
1147 } | 1176 } |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 else | 1754 else |
1726 gold_unreachable(); | 1755 gold_unreachable(); |
1727 | 1756 |
1728 memcpy(buffer + 3 * (size / 8), name, namesz); | 1757 memcpy(buffer + 3 * (size / 8), name, namesz); |
1729 | 1758 |
1730 elfcpp::Elf_Xword flags = 0; | 1759 elfcpp::Elf_Xword flags = 0; |
1731 if (allocate) | 1760 if (allocate) |
1732 flags = elfcpp::SHF_ALLOC; | 1761 flags = elfcpp::SHF_ALLOC; |
1733 Output_section* os = this->choose_output_section(NULL, section_name, | 1762 Output_section* os = this->choose_output_section(NULL, section_name, |
1734 elfcpp::SHT_NOTE, | 1763 elfcpp::SHT_NOTE, |
1735 » » » » » » flags, false); | 1764 » » » » » » flags, false, false, |
| 1765 » » » » » » false); |
1736 if (os == NULL) | 1766 if (os == NULL) |
1737 return NULL; | 1767 return NULL; |
1738 | 1768 |
1739 Output_section_data* posd = new Output_data_const_buffer(buffer, notehdrsz, | 1769 Output_section_data* posd = new Output_data_const_buffer(buffer, notehdrsz, |
1740 size / 8, | 1770 size / 8, |
1741 "** note header"); | 1771 "** note header"); |
1742 os->add_output_section_data(posd); | 1772 os->add_output_section_data(posd); |
1743 | 1773 |
1744 *trailing_padding = aligned_descsz - descsz; | 1774 *trailing_padding = aligned_descsz - descsz; |
1745 | 1775 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 else | 1834 else |
1805 is_stack_executable = false; | 1835 is_stack_executable = false; |
1806 } | 1836 } |
1807 | 1837 |
1808 if (parameters->options().relocatable()) | 1838 if (parameters->options().relocatable()) |
1809 { | 1839 { |
1810 const char* name = this->namepool_.add(".note.GNU-stack", false, NULL); | 1840 const char* name = this->namepool_.add(".note.GNU-stack", false, NULL); |
1811 elfcpp::Elf_Xword flags = 0; | 1841 elfcpp::Elf_Xword flags = 0; |
1812 if (is_stack_executable) | 1842 if (is_stack_executable) |
1813 flags |= elfcpp::SHF_EXECINSTR; | 1843 flags |= elfcpp::SHF_EXECINSTR; |
1814 this->make_output_section(name, elfcpp::SHT_PROGBITS, flags); | 1844 this->make_output_section(name, elfcpp::SHT_PROGBITS, flags, false, |
| 1845 » » » » false); |
1815 } | 1846 } |
1816 else | 1847 else |
1817 { | 1848 { |
1818 if (this->script_options_->saw_phdrs_clause()) | 1849 if (this->script_options_->saw_phdrs_clause()) |
1819 return; | 1850 return; |
1820 int flags = elfcpp::PF_R | elfcpp::PF_W; | 1851 int flags = elfcpp::PF_R | elfcpp::PF_W; |
1821 if (is_stack_executable) | 1852 if (is_stack_executable) |
1822 flags |= elfcpp::PF_X; | 1853 flags |= elfcpp::PF_X; |
1823 this->make_output_segment(elfcpp::PT_GNU_STACK, flags); | 1854 this->make_output_segment(elfcpp::PT_GNU_STACK, flags); |
1824 } | 1855 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1964 void | 1995 void |
1965 Layout::create_incremental_info_sections() | 1996 Layout::create_incremental_info_sections() |
1966 { | 1997 { |
1967 gold_assert(this->incremental_inputs_ != NULL); | 1998 gold_assert(this->incremental_inputs_ != NULL); |
1968 | 1999 |
1969 // Add the .gnu_incremental_inputs section. | 2000 // Add the .gnu_incremental_inputs section. |
1970 const char *incremental_inputs_name = | 2001 const char *incremental_inputs_name = |
1971 this->namepool_.add(".gnu_incremental_inputs", false, NULL); | 2002 this->namepool_.add(".gnu_incremental_inputs", false, NULL); |
1972 Output_section* inputs_os = | 2003 Output_section* inputs_os = |
1973 this->make_output_section(incremental_inputs_name, | 2004 this->make_output_section(incremental_inputs_name, |
1974 » » » elfcpp::SHT_GNU_INCREMENTAL_INPUTS, 0); | 2005 » » » elfcpp::SHT_GNU_INCREMENTAL_INPUTS, 0, |
| 2006 » » » false, false); |
1975 Output_section_data* posd = | 2007 Output_section_data* posd = |
1976 this->incremental_inputs_->create_incremental_inputs_section_data(); | 2008 this->incremental_inputs_->create_incremental_inputs_section_data(); |
1977 inputs_os->add_output_section_data(posd); | 2009 inputs_os->add_output_section_data(posd); |
1978 | 2010 |
1979 // Add the .gnu_incremental_strtab section. | 2011 // Add the .gnu_incremental_strtab section. |
1980 const char *incremental_strtab_name = | 2012 const char *incremental_strtab_name = |
1981 this->namepool_.add(".gnu_incremental_strtab", false, NULL); | 2013 this->namepool_.add(".gnu_incremental_strtab", false, NULL); |
1982 Output_section* strtab_os = this->make_output_section(incremental_strtab_name, | 2014 Output_section* strtab_os = this->make_output_section(incremental_strtab_name, |
1983 elfcpp::SHT_STRTAB, | 2015 elfcpp::SHT_STRTAB, |
1984 0); | 2016 0, false, false); |
1985 Output_data_strtab* strtab_data = | 2017 Output_data_strtab* strtab_data = |
1986 new Output_data_strtab(this->incremental_inputs_->get_stringpool()); | 2018 new Output_data_strtab(this->incremental_inputs_->get_stringpool()); |
1987 strtab_os->add_output_section_data(strtab_data); | 2019 strtab_os->add_output_section_data(strtab_data); |
1988 | 2020 |
1989 inputs_os->set_link_section(strtab_data); | 2021 inputs_os->set_link_section(strtab_data); |
1990 } | 2022 } |
1991 | 2023 |
1992 // Return whether SEG1 should be before SEG2 in the output file. This | 2024 // Return whether SEG1 should be before SEG2 in the output file. This |
1993 // is based entirely on the segment type and flags. When this is | 2025 // is based entirely on the segment type and flags. When this is |
1994 // called the segment addresses has normally not yet been set. | 2026 // called the segment addresses has normally not yet been set. |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2586 off = symtab->finalize(off, dynoff, dyn_global_index, dyncount, | 2618 off = symtab->finalize(off, dynoff, dyn_global_index, dyncount, |
2587 &this->sympool_, &local_symcount); | 2619 &this->sympool_, &local_symcount); |
2588 | 2620 |
2589 if (!parameters->options().strip_all()) | 2621 if (!parameters->options().strip_all()) |
2590 { | 2622 { |
2591 this->sympool_.set_string_offsets(); | 2623 this->sympool_.set_string_offsets(); |
2592 | 2624 |
2593 const char* symtab_name = this->namepool_.add(".symtab", false, NULL); | 2625 const char* symtab_name = this->namepool_.add(".symtab", false, NULL); |
2594 Output_section* osymtab = this->make_output_section(symtab_name, | 2626 Output_section* osymtab = this->make_output_section(symtab_name, |
2595 elfcpp::SHT_SYMTAB, | 2627 elfcpp::SHT_SYMTAB, |
2596 » » » » » » » 0); | 2628 » » » » » » » 0, false, false); |
2597 this->symtab_section_ = osymtab; | 2629 this->symtab_section_ = osymtab; |
2598 | 2630 |
2599 Output_section_data* pos = new Output_data_fixed_space(off - startoff, | 2631 Output_section_data* pos = new Output_data_fixed_space(off - startoff, |
2600 align, | 2632 align, |
2601 "** symtab"); | 2633 "** symtab"); |
2602 osymtab->add_output_section_data(pos); | 2634 osymtab->add_output_section_data(pos); |
2603 | 2635 |
2604 // We generate a .symtab_shndx section if we have more than | 2636 // We generate a .symtab_shndx section if we have more than |
2605 // SHN_LORESERVE sections. Technically it is possible that we | 2637 // SHN_LORESERVE sections. Technically it is possible that we |
2606 // don't need one, because it is possible that there are no | 2638 // don't need one, because it is possible that there are no |
2607 // symbols in any of sections with indexes larger than | 2639 // symbols in any of sections with indexes larger than |
2608 // SHN_LORESERVE. That is probably unusual, though, and it is | 2640 // SHN_LORESERVE. That is probably unusual, though, and it is |
2609 // easier to always create one than to compute section indexes | 2641 // easier to always create one than to compute section indexes |
2610 // twice (once here, once when writing out the symbols). | 2642 // twice (once here, once when writing out the symbols). |
2611 if (shnum >= elfcpp::SHN_LORESERVE) | 2643 if (shnum >= elfcpp::SHN_LORESERVE) |
2612 { | 2644 { |
2613 const char* symtab_xindex_name = this->namepool_.add(".symtab_shndx", | 2645 const char* symtab_xindex_name = this->namepool_.add(".symtab_shndx", |
2614 false, NULL); | 2646 false, NULL); |
2615 Output_section* osymtab_xindex = | 2647 Output_section* osymtab_xindex = |
2616 this->make_output_section(symtab_xindex_name, | 2648 this->make_output_section(symtab_xindex_name, |
2617 » » » » elfcpp::SHT_SYMTAB_SHNDX, 0); | 2649 » » » » elfcpp::SHT_SYMTAB_SHNDX, 0, false, |
| 2650 » » » » false); |
2618 | 2651 |
2619 size_t symcount = (off - startoff) / symsize; | 2652 size_t symcount = (off - startoff) / symsize; |
2620 this->symtab_xindex_ = new Output_symtab_xindex(symcount); | 2653 this->symtab_xindex_ = new Output_symtab_xindex(symcount); |
2621 | 2654 |
2622 osymtab_xindex->add_output_section_data(this->symtab_xindex_); | 2655 osymtab_xindex->add_output_section_data(this->symtab_xindex_); |
2623 | 2656 |
2624 osymtab_xindex->set_link_section(osymtab); | 2657 osymtab_xindex->set_link_section(osymtab); |
2625 osymtab_xindex->set_addralign(4); | 2658 osymtab_xindex->set_addralign(4); |
2626 osymtab_xindex->set_entsize(4); | 2659 osymtab_xindex->set_entsize(4); |
2627 | 2660 |
2628 osymtab_xindex->set_after_input_sections(); | 2661 osymtab_xindex->set_after_input_sections(); |
2629 | 2662 |
2630 // This tells the driver code to wait until the symbol table | 2663 // This tells the driver code to wait until the symbol table |
2631 // has written out before writing out the postprocessing | 2664 // has written out before writing out the postprocessing |
2632 // sections, including the .symtab_shndx section. | 2665 // sections, including the .symtab_shndx section. |
2633 this->any_postprocessing_sections_ = true; | 2666 this->any_postprocessing_sections_ = true; |
2634 } | 2667 } |
2635 | 2668 |
2636 const char* strtab_name = this->namepool_.add(".strtab", false, NULL); | 2669 const char* strtab_name = this->namepool_.add(".strtab", false, NULL); |
2637 Output_section* ostrtab = this->make_output_section(strtab_name, | 2670 Output_section* ostrtab = this->make_output_section(strtab_name, |
2638 elfcpp::SHT_STRTAB, | 2671 elfcpp::SHT_STRTAB, |
2639 » » » » » » » 0); | 2672 » » » » » » » 0, false, false); |
2640 | 2673 |
2641 Output_section_data* pstr = new Output_data_strtab(&this->sympool_); | 2674 Output_section_data* pstr = new Output_data_strtab(&this->sympool_); |
2642 ostrtab->add_output_section_data(pstr); | 2675 ostrtab->add_output_section_data(pstr); |
2643 | 2676 |
2644 osymtab->set_file_offset(startoff); | 2677 osymtab->set_file_offset(startoff); |
2645 osymtab->finalize_data_size(); | 2678 osymtab->finalize_data_size(); |
2646 osymtab->set_link_section(ostrtab); | 2679 osymtab->set_link_section(ostrtab); |
2647 osymtab->set_info(local_symcount); | 2680 osymtab->set_info(local_symcount); |
2648 osymtab->set_entsize(symsize); | 2681 osymtab->set_entsize(symsize); |
2649 | 2682 |
2650 *poff = off; | 2683 *poff = off; |
2651 } | 2684 } |
2652 } | 2685 } |
2653 | 2686 |
2654 // Create the .shstrtab section, which holds the names of the | 2687 // Create the .shstrtab section, which holds the names of the |
2655 // sections. At the time this is called, we have created all the | 2688 // sections. At the time this is called, we have created all the |
2656 // output sections except .shstrtab itself. | 2689 // output sections except .shstrtab itself. |
2657 | 2690 |
2658 Output_section* | 2691 Output_section* |
2659 Layout::create_shstrtab() | 2692 Layout::create_shstrtab() |
2660 { | 2693 { |
2661 // FIXME: We don't need to create a .shstrtab section if we are | 2694 // FIXME: We don't need to create a .shstrtab section if we are |
2662 // stripping everything. | 2695 // stripping everything. |
2663 | 2696 |
2664 const char* name = this->namepool_.add(".shstrtab", false, NULL); | 2697 const char* name = this->namepool_.add(".shstrtab", false, NULL); |
2665 | 2698 |
2666 Output_section* os = this->make_output_section(name, elfcpp::SHT_STRTAB, 0); | 2699 Output_section* os = this->make_output_section(name, elfcpp::SHT_STRTAB, 0, |
| 2700 » » » » » » false, false); |
2667 | 2701 |
2668 // We can't write out this section until we've set all the section | 2702 // We can't write out this section until we've set all the section |
2669 // names, and we don't set the names of compressed output sections | 2703 // names, and we don't set the names of compressed output sections |
2670 // until relocations are complete. | 2704 // until relocations are complete. |
2671 os->set_after_input_sections(); | 2705 os->set_after_input_sections(); |
2672 | 2706 |
2673 Output_section_data* posd = new Output_data_strtab(&this->namepool_); | 2707 Output_section_data* posd = new Output_data_strtab(&this->namepool_); |
2674 os->add_output_section_data(posd); | 2708 os->add_output_section_data(posd); |
2675 | 2709 |
2676 return os; | 2710 return os; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2769 align = 8; | 2803 align = 8; |
2770 } | 2804 } |
2771 else | 2805 else |
2772 gold_unreachable(); | 2806 gold_unreachable(); |
2773 | 2807 |
2774 // Create the dynamic symbol table section. | 2808 // Create the dynamic symbol table section. |
2775 | 2809 |
2776 Output_section* dynsym = this->choose_output_section(NULL, ".dynsym", | 2810 Output_section* dynsym = this->choose_output_section(NULL, ".dynsym", |
2777 elfcpp::SHT_DYNSYM, | 2811 elfcpp::SHT_DYNSYM, |
2778 elfcpp::SHF_ALLOC, | 2812 elfcpp::SHF_ALLOC, |
2779 » » » » » » false); | 2813 » » » » » » false, false, true); |
2780 | 2814 |
2781 Output_section_data* odata = new Output_data_fixed_space(index * symsize, | 2815 Output_section_data* odata = new Output_data_fixed_space(index * symsize, |
2782 align, | 2816 align, |
2783 "** dynsym"); | 2817 "** dynsym"); |
2784 dynsym->add_output_section_data(odata); | 2818 dynsym->add_output_section_data(odata); |
2785 | 2819 |
2786 dynsym->set_info(local_symcount); | 2820 dynsym->set_info(local_symcount); |
2787 dynsym->set_entsize(symsize); | 2821 dynsym->set_entsize(symsize); |
2788 dynsym->set_addralign(align); | 2822 dynsym->set_addralign(align); |
2789 | 2823 |
2790 this->dynsym_section_ = dynsym; | 2824 this->dynsym_section_ = dynsym; |
2791 | 2825 |
2792 Output_data_dynamic* const odyn = this->dynamic_data_; | 2826 Output_data_dynamic* const odyn = this->dynamic_data_; |
2793 odyn->add_section_address(elfcpp::DT_SYMTAB, dynsym); | 2827 odyn->add_section_address(elfcpp::DT_SYMTAB, dynsym); |
2794 odyn->add_constant(elfcpp::DT_SYMENT, symsize); | 2828 odyn->add_constant(elfcpp::DT_SYMENT, symsize); |
2795 | 2829 |
2796 // If there are more than SHN_LORESERVE allocated sections, we | 2830 // If there are more than SHN_LORESERVE allocated sections, we |
2797 // create a .dynsym_shndx section. It is possible that we don't | 2831 // create a .dynsym_shndx section. It is possible that we don't |
2798 // need one, because it is possible that there are no dynamic | 2832 // need one, because it is possible that there are no dynamic |
2799 // symbols in any of the sections with indexes larger than | 2833 // symbols in any of the sections with indexes larger than |
2800 // SHN_LORESERVE. This is probably unusual, though, and at this | 2834 // SHN_LORESERVE. This is probably unusual, though, and at this |
2801 // time we don't know the actual section indexes so it is | 2835 // time we don't know the actual section indexes so it is |
2802 // inconvenient to check. | 2836 // inconvenient to check. |
2803 if (this->allocated_output_section_count() >= elfcpp::SHN_LORESERVE) | 2837 if (this->allocated_output_section_count() >= elfcpp::SHN_LORESERVE) |
2804 { | 2838 { |
2805 Output_section* dynsym_xindex = | 2839 Output_section* dynsym_xindex = |
2806 this->choose_output_section(NULL, ".dynsym_shndx", | 2840 this->choose_output_section(NULL, ".dynsym_shndx", |
2807 elfcpp::SHT_SYMTAB_SHNDX, | 2841 elfcpp::SHT_SYMTAB_SHNDX, |
2808 elfcpp::SHF_ALLOC, | 2842 elfcpp::SHF_ALLOC, |
2809 » » » » false); | 2843 » » » » false, false, true); |
2810 | 2844 |
2811 this->dynsym_xindex_ = new Output_symtab_xindex(index); | 2845 this->dynsym_xindex_ = new Output_symtab_xindex(index); |
2812 | 2846 |
2813 dynsym_xindex->add_output_section_data(this->dynsym_xindex_); | 2847 dynsym_xindex->add_output_section_data(this->dynsym_xindex_); |
2814 | 2848 |
2815 dynsym_xindex->set_link_section(dynsym); | 2849 dynsym_xindex->set_link_section(dynsym); |
2816 dynsym_xindex->set_addralign(4); | 2850 dynsym_xindex->set_addralign(4); |
2817 dynsym_xindex->set_entsize(4); | 2851 dynsym_xindex->set_entsize(4); |
2818 | 2852 |
2819 dynsym_xindex->set_after_input_sections(); | 2853 dynsym_xindex->set_after_input_sections(); |
2820 | 2854 |
2821 // This tells the driver code to wait until the symbol table has | 2855 // This tells the driver code to wait until the symbol table has |
2822 // written out before writing out the postprocessing sections, | 2856 // written out before writing out the postprocessing sections, |
2823 // including the .dynsym_shndx section. | 2857 // including the .dynsym_shndx section. |
2824 this->any_postprocessing_sections_ = true; | 2858 this->any_postprocessing_sections_ = true; |
2825 } | 2859 } |
2826 | 2860 |
2827 // Create the dynamic string table section. | 2861 // Create the dynamic string table section. |
2828 | 2862 |
2829 Output_section* dynstr = this->choose_output_section(NULL, ".dynstr", | 2863 Output_section* dynstr = this->choose_output_section(NULL, ".dynstr", |
2830 elfcpp::SHT_STRTAB, | 2864 elfcpp::SHT_STRTAB, |
2831 elfcpp::SHF_ALLOC, | 2865 elfcpp::SHF_ALLOC, |
2832 » » » » » » false); | 2866 » » » » » » false, false, true); |
2833 | 2867 |
2834 Output_section_data* strdata = new Output_data_strtab(&this->dynpool_); | 2868 Output_section_data* strdata = new Output_data_strtab(&this->dynpool_); |
2835 dynstr->add_output_section_data(strdata); | 2869 dynstr->add_output_section_data(strdata); |
2836 | 2870 |
2837 dynsym->set_link_section(dynstr); | 2871 dynsym->set_link_section(dynstr); |
2838 this->dynamic_section_->set_link_section(dynstr); | 2872 this->dynamic_section_->set_link_section(dynstr); |
2839 | 2873 |
2840 odyn->add_section_address(elfcpp::DT_STRTAB, dynstr); | 2874 odyn->add_section_address(elfcpp::DT_STRTAB, dynstr); |
2841 odyn->add_section_size(elfcpp::DT_STRSZ, dynstr); | 2875 odyn->add_section_size(elfcpp::DT_STRSZ, dynstr); |
2842 | 2876 |
2843 *pdynstr = dynstr; | 2877 *pdynstr = dynstr; |
2844 | 2878 |
2845 // Create the hash tables. | 2879 // Create the hash tables. |
2846 | 2880 |
2847 if (strcmp(parameters->options().hash_style(), "sysv") == 0 | 2881 if (strcmp(parameters->options().hash_style(), "sysv") == 0 |
2848 || strcmp(parameters->options().hash_style(), "both") == 0) | 2882 || strcmp(parameters->options().hash_style(), "both") == 0) |
2849 { | 2883 { |
2850 unsigned char* phash; | 2884 unsigned char* phash; |
2851 unsigned int hashlen; | 2885 unsigned int hashlen; |
2852 Dynobj::create_elf_hash_table(*pdynamic_symbols, local_symcount, | 2886 Dynobj::create_elf_hash_table(*pdynamic_symbols, local_symcount, |
2853 &phash, &hashlen); | 2887 &phash, &hashlen); |
2854 | 2888 |
2855 Output_section* hashsec = this->choose_output_section(NULL, ".hash", | 2889 Output_section* hashsec = this->choose_output_section(NULL, ".hash", |
2856 elfcpp::SHT_HASH, | 2890 elfcpp::SHT_HASH, |
2857 elfcpp::SHF_ALLOC, | 2891 elfcpp::SHF_ALLOC, |
2858 » » » » » » » false); | 2892 » » » » » » » false, false, true); |
2859 | 2893 |
2860 Output_section_data* hashdata = new Output_data_const_buffer(phash, | 2894 Output_section_data* hashdata = new Output_data_const_buffer(phash, |
2861 hashlen, | 2895 hashlen, |
2862 align, | 2896 align, |
2863 "** hash"); | 2897 "** hash"); |
2864 hashsec->add_output_section_data(hashdata); | 2898 hashsec->add_output_section_data(hashdata); |
2865 | 2899 |
2866 hashsec->set_link_section(dynsym); | 2900 hashsec->set_link_section(dynsym); |
2867 hashsec->set_entsize(4); | 2901 hashsec->set_entsize(4); |
2868 | 2902 |
2869 odyn->add_section_address(elfcpp::DT_HASH, hashsec); | 2903 odyn->add_section_address(elfcpp::DT_HASH, hashsec); |
2870 } | 2904 } |
2871 | 2905 |
2872 if (strcmp(parameters->options().hash_style(), "gnu") == 0 | 2906 if (strcmp(parameters->options().hash_style(), "gnu") == 0 |
2873 || strcmp(parameters->options().hash_style(), "both") == 0) | 2907 || strcmp(parameters->options().hash_style(), "both") == 0) |
2874 { | 2908 { |
2875 unsigned char* phash; | 2909 unsigned char* phash; |
2876 unsigned int hashlen; | 2910 unsigned int hashlen; |
2877 Dynobj::create_gnu_hash_table(*pdynamic_symbols, local_symcount, | 2911 Dynobj::create_gnu_hash_table(*pdynamic_symbols, local_symcount, |
2878 &phash, &hashlen); | 2912 &phash, &hashlen); |
2879 | 2913 |
2880 Output_section* hashsec = this->choose_output_section(NULL, ".gnu.hash", | 2914 Output_section* hashsec = this->choose_output_section(NULL, ".gnu.hash", |
2881 elfcpp::SHT_GNU_HASH
, | 2915 elfcpp::SHT_GNU_HASH
, |
2882 elfcpp::SHF_ALLOC, | 2916 elfcpp::SHF_ALLOC, |
2883 » » » » » » » false); | 2917 » » » » » » » false, false, true); |
2884 | 2918 |
2885 Output_section_data* hashdata = new Output_data_const_buffer(phash, | 2919 Output_section_data* hashdata = new Output_data_const_buffer(phash, |
2886 hashlen, | 2920 hashlen, |
2887 align, | 2921 align, |
2888 "** hash"); | 2922 "** hash"); |
2889 hashsec->add_output_section_data(hashdata); | 2923 hashsec->add_output_section_data(hashdata); |
2890 | 2924 |
2891 hashsec->set_link_section(dynsym); | 2925 hashsec->set_link_section(dynsym); |
2892 hashsec->set_entsize(4); | 2926 hashsec->set_entsize(4); |
2893 | 2927 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2971 Layout::sized_create_version_sections( | 3005 Layout::sized_create_version_sections( |
2972 const Versions* versions, | 3006 const Versions* versions, |
2973 const Symbol_table* symtab, | 3007 const Symbol_table* symtab, |
2974 unsigned int local_symcount, | 3008 unsigned int local_symcount, |
2975 const std::vector<Symbol*>& dynamic_symbols, | 3009 const std::vector<Symbol*>& dynamic_symbols, |
2976 const Output_section* dynstr) | 3010 const Output_section* dynstr) |
2977 { | 3011 { |
2978 Output_section* vsec = this->choose_output_section(NULL, ".gnu.version", | 3012 Output_section* vsec = this->choose_output_section(NULL, ".gnu.version", |
2979 elfcpp::SHT_GNU_versym, | 3013 elfcpp::SHT_GNU_versym, |
2980 elfcpp::SHF_ALLOC, | 3014 elfcpp::SHF_ALLOC, |
2981 » » » » » » false); | 3015 » » » » » » false, false, true); |
2982 | 3016 |
2983 unsigned char* vbuf; | 3017 unsigned char* vbuf; |
2984 unsigned int vsize; | 3018 unsigned int vsize; |
2985 versions->symbol_section_contents<size, big_endian>(symtab, &this->dynpool_, | 3019 versions->symbol_section_contents<size, big_endian>(symtab, &this->dynpool_, |
2986 local_symcount, | 3020 local_symcount, |
2987 dynamic_symbols, | 3021 dynamic_symbols, |
2988 &vbuf, &vsize); | 3022 &vbuf, &vsize); |
2989 | 3023 |
2990 Output_section_data* vdata = new Output_data_const_buffer(vbuf, vsize, 2, | 3024 Output_section_data* vdata = new Output_data_const_buffer(vbuf, vsize, 2, |
2991 "** versions"); | 3025 "** versions"); |
2992 | 3026 |
2993 vsec->add_output_section_data(vdata); | 3027 vsec->add_output_section_data(vdata); |
2994 vsec->set_entsize(2); | 3028 vsec->set_entsize(2); |
2995 vsec->set_link_section(this->dynsym_section_); | 3029 vsec->set_link_section(this->dynsym_section_); |
2996 | 3030 |
2997 Output_data_dynamic* const odyn = this->dynamic_data_; | 3031 Output_data_dynamic* const odyn = this->dynamic_data_; |
2998 odyn->add_section_address(elfcpp::DT_VERSYM, vsec); | 3032 odyn->add_section_address(elfcpp::DT_VERSYM, vsec); |
2999 | 3033 |
3000 if (versions->any_defs()) | 3034 if (versions->any_defs()) |
3001 { | 3035 { |
3002 Output_section* vdsec; | 3036 Output_section* vdsec; |
3003 vdsec= this->choose_output_section(NULL, ".gnu.version_d", | 3037 vdsec= this->choose_output_section(NULL, ".gnu.version_d", |
3004 elfcpp::SHT_GNU_verdef, | 3038 elfcpp::SHT_GNU_verdef, |
3005 elfcpp::SHF_ALLOC, | 3039 elfcpp::SHF_ALLOC, |
3006 » » » » » false); | 3040 » » » » » false, false, true); |
3007 | 3041 |
3008 unsigned char* vdbuf; | 3042 unsigned char* vdbuf; |
3009 unsigned int vdsize; | 3043 unsigned int vdsize; |
3010 unsigned int vdentries; | 3044 unsigned int vdentries; |
3011 versions->def_section_contents<size, big_endian>(&this->dynpool_, &vdbuf, | 3045 versions->def_section_contents<size, big_endian>(&this->dynpool_, &vdbuf, |
3012 &vdsize, &vdentries); | 3046 &vdsize, &vdentries); |
3013 | 3047 |
3014 Output_section_data* vddata = | 3048 Output_section_data* vddata = |
3015 new Output_data_const_buffer(vdbuf, vdsize, 4, "** version defs"); | 3049 new Output_data_const_buffer(vdbuf, vdsize, 4, "** version defs"); |
3016 | 3050 |
3017 vdsec->add_output_section_data(vddata); | 3051 vdsec->add_output_section_data(vddata); |
3018 vdsec->set_link_section(dynstr); | 3052 vdsec->set_link_section(dynstr); |
3019 vdsec->set_info(vdentries); | 3053 vdsec->set_info(vdentries); |
3020 | 3054 |
3021 odyn->add_section_address(elfcpp::DT_VERDEF, vdsec); | 3055 odyn->add_section_address(elfcpp::DT_VERDEF, vdsec); |
3022 odyn->add_constant(elfcpp::DT_VERDEFNUM, vdentries); | 3056 odyn->add_constant(elfcpp::DT_VERDEFNUM, vdentries); |
3023 } | 3057 } |
3024 | 3058 |
3025 if (versions->any_needs()) | 3059 if (versions->any_needs()) |
3026 { | 3060 { |
3027 Output_section* vnsec; | 3061 Output_section* vnsec; |
3028 vnsec = this->choose_output_section(NULL, ".gnu.version_r", | 3062 vnsec = this->choose_output_section(NULL, ".gnu.version_r", |
3029 elfcpp::SHT_GNU_verneed, | 3063 elfcpp::SHT_GNU_verneed, |
3030 elfcpp::SHF_ALLOC, | 3064 elfcpp::SHF_ALLOC, |
3031 » » » » » false); | 3065 » » » » » false, false, true); |
3032 | 3066 |
3033 unsigned char* vnbuf; | 3067 unsigned char* vnbuf; |
3034 unsigned int vnsize; | 3068 unsigned int vnsize; |
3035 unsigned int vnentries; | 3069 unsigned int vnentries; |
3036 versions->need_section_contents<size, big_endian>(&this->dynpool_, | 3070 versions->need_section_contents<size, big_endian>(&this->dynpool_, |
3037 &vnbuf, &vnsize, | 3071 &vnbuf, &vnsize, |
3038 &vnentries); | 3072 &vnentries); |
3039 | 3073 |
3040 Output_section_data* vndata = | 3074 Output_section_data* vndata = |
3041 new Output_data_const_buffer(vnbuf, vnsize, 4, "** version refs"); | 3075 new Output_data_const_buffer(vnbuf, vnsize, 4, "** version refs"); |
(...skipping 19 matching lines...) Expand all Loading... |
3061 gold_assert(interp != NULL); | 3095 gold_assert(interp != NULL); |
3062 } | 3096 } |
3063 | 3097 |
3064 size_t len = strlen(interp) + 1; | 3098 size_t len = strlen(interp) + 1; |
3065 | 3099 |
3066 Output_section_data* odata = new Output_data_const(interp, len, 1); | 3100 Output_section_data* odata = new Output_data_const(interp, len, 1); |
3067 | 3101 |
3068 Output_section* osec = this->choose_output_section(NULL, ".interp", | 3102 Output_section* osec = this->choose_output_section(NULL, ".interp", |
3069 elfcpp::SHT_PROGBITS, | 3103 elfcpp::SHT_PROGBITS, |
3070 elfcpp::SHF_ALLOC, | 3104 elfcpp::SHF_ALLOC, |
3071 » » » » » » false); | 3105 » » » » » » false, true, true); |
3072 osec->add_output_section_data(odata); | 3106 osec->add_output_section_data(odata); |
3073 | 3107 |
3074 if (!this->script_options_->saw_phdrs_clause()) | 3108 if (!this->script_options_->saw_phdrs_clause()) |
3075 { | 3109 { |
3076 Output_segment* oseg = this->make_output_segment(elfcpp::PT_INTERP, | 3110 Output_segment* oseg = this->make_output_segment(elfcpp::PT_INTERP, |
3077 elfcpp::PF_R); | 3111 elfcpp::PF_R); |
3078 oseg->add_output_section(osec, elfcpp::PF_R); | 3112 oseg->add_output_section(osec, elfcpp::PF_R, false); |
3079 } | 3113 } |
3080 } | 3114 } |
3081 | 3115 |
3082 // Finish the .dynamic section and PT_DYNAMIC segment. | 3116 // Finish the .dynamic section and PT_DYNAMIC segment. |
3083 | 3117 |
3084 void | 3118 void |
3085 Layout::finish_dynamic_section(const Input_objects* input_objects, | 3119 Layout::finish_dynamic_section(const Input_objects* input_objects, |
3086 const Symbol_table* symtab) | 3120 const Symbol_table* symtab) |
3087 { | 3121 { |
3088 if (!this->script_options_->saw_phdrs_clause()) | 3122 if (!this->script_options_->saw_phdrs_clause()) |
3089 { | 3123 { |
3090 Output_segment* oseg = this->make_output_segment(elfcpp::PT_DYNAMIC, | 3124 Output_segment* oseg = this->make_output_segment(elfcpp::PT_DYNAMIC, |
3091 (elfcpp::PF_R | 3125 (elfcpp::PF_R |
3092 | elfcpp::PF_W)); | 3126 | elfcpp::PF_W)); |
3093 oseg->add_output_section(this->dynamic_section_, | 3127 oseg->add_output_section(this->dynamic_section_, |
3094 » » » elfcpp::PF_R | elfcpp::PF_W); | 3128 » » » elfcpp::PF_R | elfcpp::PF_W, |
| 3129 » » » false); |
3095 } | 3130 } |
3096 | 3131 |
3097 Output_data_dynamic* const odyn = this->dynamic_data_; | 3132 Output_data_dynamic* const odyn = this->dynamic_data_; |
3098 | 3133 |
3099 for (Input_objects::Dynobj_iterator p = input_objects->dynobj_begin(); | 3134 for (Input_objects::Dynobj_iterator p = input_objects->dynobj_begin(); |
3100 p != input_objects->dynobj_end(); | 3135 p != input_objects->dynobj_end(); |
3101 ++p) | 3136 ++p) |
3102 { | 3137 { |
3103 // FIXME: Handle --as-needed. | 3138 if (!(*p)->is_needed() |
| 3139 » && (*p)->input_file()->options().as_needed()) |
| 3140 » { |
| 3141 » // This dynamic object was linked with --as-needed, but it |
| 3142 » // is not needed. |
| 3143 » continue; |
| 3144 » } |
| 3145 |
3104 odyn->add_string(elfcpp::DT_NEEDED, (*p)->soname()); | 3146 odyn->add_string(elfcpp::DT_NEEDED, (*p)->soname()); |
3105 } | 3147 } |
3106 | 3148 |
3107 if (parameters->options().shared()) | 3149 if (parameters->options().shared()) |
3108 { | 3150 { |
3109 const char* soname = parameters->options().soname(); | 3151 const char* soname = parameters->options().soname(); |
3110 if (soname != NULL) | 3152 if (soname != NULL) |
3111 odyn->add_string(elfcpp::DT_SONAME, soname); | 3153 odyn->add_string(elfcpp::DT_SONAME, soname); |
3112 } | 3154 } |
3113 | 3155 |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4006 const unsigned char* symbol_names, | 4048 const unsigned char* symbol_names, |
4007 off_t symbol_names_size, | 4049 off_t symbol_names_size, |
4008 unsigned int shndx, | 4050 unsigned int shndx, |
4009 const elfcpp::Shdr<64, true>& shdr, | 4051 const elfcpp::Shdr<64, true>& shdr, |
4010 unsigned int reloc_shndx, | 4052 unsigned int reloc_shndx, |
4011 unsigned int reloc_type, | 4053 unsigned int reloc_type, |
4012 off_t* off); | 4054 off_t* off); |
4013 #endif | 4055 #endif |
4014 | 4056 |
4015 } // End namespace gold. | 4057 } // End namespace gold. |
OLD | NEW |