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