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, 2010, 2011 Free Software Foundation, Inc. | 3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 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 |
(...skipping 2525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 { | 2536 { |
2537 off = this->set_section_offsets(off, | 2537 off = this->set_section_offsets(off, |
2538 POSTPROCESSING_SECTIONS_PASS); | 2538 POSTPROCESSING_SECTIONS_PASS); |
2539 off = | 2539 off = |
2540 this->set_section_offsets(off, | 2540 this->set_section_offsets(off, |
2541 STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS); | 2541 STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS); |
2542 } | 2542 } |
2543 | 2543 |
2544 file_header->set_section_info(this->section_headers_, shstrtab_section); | 2544 file_header->set_section_info(this->section_headers_, shstrtab_section); |
2545 | 2545 |
| 2546 // Sets data with values that are only known after sections are finalized. |
| 2547 // For MIPS it is needed to set flag if there are more then 0x10000 symbols |
| 2548 // in dynamic symbol table. |
| 2549 target->fix_sections (this, symtab); |
| 2550 |
2546 // Now we know exactly where everything goes in the output file | 2551 // Now we know exactly where everything goes in the output file |
2547 // (except for non-allocated sections which require postprocessing). | 2552 // (except for non-allocated sections which require postprocessing). |
2548 Output_data::layout_complete(); | 2553 Output_data::layout_complete(); |
2549 | 2554 |
2550 this->output_file_size_ = off; | 2555 this->output_file_size_ = off; |
2551 | 2556 |
2552 return off; | 2557 return off; |
2553 } | 2558 } |
2554 | 2559 |
2555 // Create a note header following the format defined in the ELF ABI. | 2560 // Create a note header following the format defined in the ELF ABI. |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2966 // The single PT_INTERP segment is required to precede any loadable | 2971 // The single PT_INTERP segment is required to precede any loadable |
2967 // segment. We simply make it always second. | 2972 // segment. We simply make it always second. |
2968 if (type1 == elfcpp::PT_INTERP) | 2973 if (type1 == elfcpp::PT_INTERP) |
2969 { | 2974 { |
2970 gold_assert(type2 != elfcpp::PT_INTERP); | 2975 gold_assert(type2 != elfcpp::PT_INTERP); |
2971 return true; | 2976 return true; |
2972 } | 2977 } |
2973 if (type2 == elfcpp::PT_INTERP) | 2978 if (type2 == elfcpp::PT_INTERP) |
2974 return false; | 2979 return false; |
2975 | 2980 |
| 2981 // This single PT_MIPS_REGINFO segment is required to precede any loadable |
| 2982 // segment. We simply make it always third. |
| 2983 // TODO AS: Make this only valid for MIPS !!! |
| 2984 if (type1 == elfcpp::PT_MIPS_REGINFO) |
| 2985 { |
| 2986 gold_assert(type2 != elfcpp::PT_MIPS_REGINFO); |
| 2987 return true; |
| 2988 } |
| 2989 if (type2 == elfcpp::PT_MIPS_REGINFO) |
| 2990 return false; |
| 2991 |
2976 // We then put PT_LOAD segments before any other segments. | 2992 // We then put PT_LOAD segments before any other segments. |
2977 if (type1 == elfcpp::PT_LOAD && type2 != elfcpp::PT_LOAD) | 2993 if (type1 == elfcpp::PT_LOAD && type2 != elfcpp::PT_LOAD) |
2978 return true; | 2994 return true; |
2979 if (type2 == elfcpp::PT_LOAD && type1 != elfcpp::PT_LOAD) | 2995 if (type2 == elfcpp::PT_LOAD && type1 != elfcpp::PT_LOAD) |
2980 return false; | 2996 return false; |
2981 | 2997 |
| 2998 // MIPS needs PT_NULL segment to be last. |
| 2999 if (type1 == elfcpp::PT_NULL) |
| 3000 { |
| 3001 gold_assert(type2 != elfcpp::PT_NULL); |
| 3002 return false; |
| 3003 } |
| 3004 if (type2 == elfcpp::PT_NULL) |
| 3005 return true; |
| 3006 |
2982 // We put the PT_TLS segment last except for the PT_GNU_RELRO | 3007 // We put the PT_TLS segment last except for the PT_GNU_RELRO |
2983 // segment, because that is where the dynamic linker expects to find | 3008 // segment, because that is where the dynamic linker expects to find |
2984 // it (this is just for efficiency; other positions would also work | 3009 // it (this is just for efficiency; other positions would also work |
2985 // correctly). | 3010 // correctly). |
2986 if (type1 == elfcpp::PT_TLS | 3011 if (type1 == elfcpp::PT_TLS |
2987 && type2 != elfcpp::PT_TLS | 3012 && type2 != elfcpp::PT_TLS |
2988 && type2 != elfcpp::PT_GNU_RELRO) | 3013 && type2 != elfcpp::PT_GNU_RELRO) |
2989 return false; | 3014 return false; |
2990 if (type2 == elfcpp::PT_TLS | 3015 if (type2 == elfcpp::PT_TLS |
2991 && type1 != elfcpp::PT_TLS | 3016 && type1 != elfcpp::PT_TLS |
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4502 // Add a DT_TEXTREL for compatibility with older loaders. | 4527 // Add a DT_TEXTREL for compatibility with older loaders. |
4503 odyn->add_constant(elfcpp::DT_TEXTREL, 0); | 4528 odyn->add_constant(elfcpp::DT_TEXTREL, 0); |
4504 flags |= elfcpp::DF_TEXTREL; | 4529 flags |= elfcpp::DF_TEXTREL; |
4505 | 4530 |
4506 if (parameters->options().text()) | 4531 if (parameters->options().text()) |
4507 gold_error(_("read-only segment has dynamic relocations")); | 4532 gold_error(_("read-only segment has dynamic relocations")); |
4508 else if (parameters->options().warn_shared_textrel() | 4533 else if (parameters->options().warn_shared_textrel() |
4509 && parameters->options().shared()) | 4534 && parameters->options().shared()) |
4510 gold_warning(_("shared library text segment is not shareable")); | 4535 gold_warning(_("shared library text segment is not shareable")); |
4511 } | 4536 } |
4512 if (parameters->options().shared() && this->has_static_tls()) | 4537 if ((parameters->options().shared() || parameters->options().pie()) |
| 4538 && this->has_static_tls()) |
4513 flags |= elfcpp::DF_STATIC_TLS; | 4539 flags |= elfcpp::DF_STATIC_TLS; |
4514 if (parameters->options().origin()) | 4540 if (parameters->options().origin()) |
4515 flags |= elfcpp::DF_ORIGIN; | 4541 flags |= elfcpp::DF_ORIGIN; |
4516 if (parameters->options().Bsymbolic()) | 4542 if (parameters->options().Bsymbolic()) |
4517 { | 4543 { |
4518 flags |= elfcpp::DF_SYMBOLIC; | 4544 flags |= elfcpp::DF_SYMBOLIC; |
4519 // Add DT_SYMBOLIC for compatibility with older loaders. | 4545 // Add DT_SYMBOLIC for compatibility with older loaders. |
4520 odyn->add_constant(elfcpp::DT_SYMBOLIC, 0); | 4546 odyn->add_constant(elfcpp::DT_SYMBOLIC, 0); |
4521 } | 4547 } |
4522 if (parameters->options().now()) | 4548 if (parameters->options().now()) |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5481 Layout::add_to_gdb_index(bool is_type_unit, | 5507 Layout::add_to_gdb_index(bool is_type_unit, |
5482 Sized_relobj<64, true>* object, | 5508 Sized_relobj<64, true>* object, |
5483 const unsigned char* symbols, | 5509 const unsigned char* symbols, |
5484 off_t symbols_size, | 5510 off_t symbols_size, |
5485 unsigned int shndx, | 5511 unsigned int shndx, |
5486 unsigned int reloc_shndx, | 5512 unsigned int reloc_shndx, |
5487 unsigned int reloc_type); | 5513 unsigned int reloc_type); |
5488 #endif | 5514 #endif |
5489 | 5515 |
5490 } // End namespace gold. | 5516 } // End namespace gold. |
OLD | NEW |