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