1 // layout.cc -- lay out output file sections for gold
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
32 #include "libiberty.h"
36 #include "parameters.h"
39 #include "script-sections.h"
44 #include "compressed_output.h"
51 // Layout_task_runner methods.
53 // Lay out the sections. This is called after all the input objects
57 Layout_task_runner::run(Workqueue
* workqueue
, const Task
* task
)
59 off_t file_size
= this->layout_
->finalize(this->input_objects_
,
64 // Now we know the final size of the output file and we know where
65 // each piece of information goes.
66 Output_file
* of
= new Output_file(parameters
->options().output_file_name());
67 if (this->options_
.oformat_enum() != General_options::OBJECT_FORMAT_ELF
)
68 of
->set_is_temporary();
71 // Queue up the final set of tasks.
72 gold::queue_final_tasks(this->options_
, this->input_objects_
,
73 this->symtab_
, this->layout_
, workqueue
, of
);
78 Layout::Layout(const General_options
& options
, Script_options
* script_options
)
79 : options_(options
), script_options_(script_options
), namepool_(),
80 sympool_(), dynpool_(), signatures_(),
81 section_name_map_(), segment_list_(), section_list_(),
82 unattached_section_list_(), sections_are_attached_(false),
83 special_output_list_(), section_headers_(NULL
), tls_segment_(NULL
),
84 symtab_section_(NULL
), dynsym_section_(NULL
), dynamic_section_(NULL
),
85 dynamic_data_(NULL
), eh_frame_section_(NULL
), eh_frame_data_(NULL
),
86 added_eh_frame_data_(false), eh_frame_hdr_section_(NULL
),
87 build_id_note_(NULL
), group_signatures_(), output_file_size_(-1),
88 input_requires_executable_stack_(false),
89 input_with_gnu_stack_note_(false),
90 input_without_gnu_stack_note_(false),
91 has_static_tls_(false),
92 any_postprocessing_sections_(false)
94 // Make space for more than enough segments for a typical file.
95 // This is just for efficiency--it's OK if we wind up needing more.
96 this->segment_list_
.reserve(12);
98 // We expect two unattached Output_data objects: the file header and
99 // the segment headers.
100 this->special_output_list_
.reserve(2);
103 // Hash a key we use to look up an output section mapping.
106 Layout::Hash_key::operator()(const Layout::Key
& k
) const
108 return k
.first
+ k
.second
.first
+ k
.second
.second
;
111 // Return whether PREFIX is a prefix of STR.
114 is_prefix_of(const char* prefix
, const char* str
)
116 return strncmp(prefix
, str
, strlen(prefix
)) == 0;
119 // Returns whether the given section is in the list of
120 // debug-sections-used-by-some-version-of-gdb. Currently,
121 // we've checked versions of gdb up to and including 6.7.1.
123 static const char* gdb_sections
[] =
125 // ".debug_aranges", // not used by gdb as of 6.7.1
131 // ".debug_pubnames", // not used by gdb as of 6.7.1
137 is_gdb_debug_section(const char* str
)
139 // We can do this faster: binary search or a hashtable. But why bother?
140 for (size_t i
= 0; i
< sizeof(gdb_sections
)/sizeof(*gdb_sections
); ++i
)
141 if (strcmp(str
, gdb_sections
[i
]) == 0)
146 // Whether to include this section in the link.
148 template<int size
, bool big_endian
>
150 Layout::include_section(Sized_relobj
<size
, big_endian
>*, const char* name
,
151 const elfcpp::Shdr
<size
, big_endian
>& shdr
)
153 switch (shdr
.get_sh_type())
155 case elfcpp::SHT_NULL
:
156 case elfcpp::SHT_SYMTAB
:
157 case elfcpp::SHT_DYNSYM
:
158 case elfcpp::SHT_STRTAB
:
159 case elfcpp::SHT_HASH
:
160 case elfcpp::SHT_DYNAMIC
:
161 case elfcpp::SHT_SYMTAB_SHNDX
:
164 case elfcpp::SHT_RELA
:
165 case elfcpp::SHT_REL
:
166 case elfcpp::SHT_GROUP
:
167 // If we are emitting relocations these should be handled
169 gold_assert(!parameters
->options().relocatable()
170 && !parameters
->options().emit_relocs());
173 case elfcpp::SHT_PROGBITS
:
174 if (parameters
->options().strip_debug()
175 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) == 0)
177 // Debugging sections can only be recognized by name.
178 if (is_prefix_of(".debug", name
)
179 || is_prefix_of(".gnu.linkonce.wi.", name
)
180 || is_prefix_of(".line", name
)
181 || is_prefix_of(".stab", name
))
184 if (parameters
->options().strip_debug_gdb()
185 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) == 0)
187 // Debugging sections can only be recognized by name.
188 if (is_prefix_of(".debug", name
)
189 && !is_gdb_debug_section(name
))
199 // Return an output section named NAME, or NULL if there is none.
202 Layout::find_output_section(const char* name
) const
204 for (Section_list::const_iterator p
= this->section_list_
.begin();
205 p
!= this->section_list_
.end();
207 if (strcmp((*p
)->name(), name
) == 0)
212 // Return an output segment of type TYPE, with segment flags SET set
213 // and segment flags CLEAR clear. Return NULL if there is none.
216 Layout::find_output_segment(elfcpp::PT type
, elfcpp::Elf_Word set
,
217 elfcpp::Elf_Word clear
) const
219 for (Segment_list::const_iterator p
= this->segment_list_
.begin();
220 p
!= this->segment_list_
.end();
222 if (static_cast<elfcpp::PT
>((*p
)->type()) == type
223 && ((*p
)->flags() & set
) == set
224 && ((*p
)->flags() & clear
) == 0)
229 // Return the output section to use for section NAME with type TYPE
230 // and section flags FLAGS. NAME must be canonicalized in the string
231 // pool, and NAME_KEY is the key.
234 Layout::get_output_section(const char* name
, Stringpool::Key name_key
,
235 elfcpp::Elf_Word type
, elfcpp::Elf_Xword flags
)
237 elfcpp::Elf_Xword lookup_flags
= flags
;
239 // Ignoring SHF_WRITE and SHF_EXECINSTR here means that we combine
240 // read-write with read-only sections. Some other ELF linkers do
241 // not do this. FIXME: Perhaps there should be an option
243 lookup_flags
&= ~(elfcpp::SHF_WRITE
| elfcpp::SHF_EXECINSTR
);
245 const Key
key(name_key
, std::make_pair(type
, lookup_flags
));
246 const std::pair
<Key
, Output_section
*> v(key
, NULL
);
247 std::pair
<Section_name_map::iterator
, bool> ins(
248 this->section_name_map_
.insert(v
));
251 return ins
.first
->second
;
254 // This is the first time we've seen this name/type/flags
255 // combination. For compatibility with the GNU linker, we
256 // combine sections with contents and zero flags with sections
257 // with non-zero flags. This is a workaround for cases where
258 // assembler code forgets to set section flags. FIXME: Perhaps
259 // there should be an option to control this.
260 Output_section
* os
= NULL
;
262 if (type
== elfcpp::SHT_PROGBITS
)
266 Output_section
* same_name
= this->find_output_section(name
);
267 if (same_name
!= NULL
268 && same_name
->type() == elfcpp::SHT_PROGBITS
269 && (same_name
->flags() & elfcpp::SHF_TLS
) == 0)
272 else if ((flags
& elfcpp::SHF_TLS
) == 0)
274 elfcpp::Elf_Xword zero_flags
= 0;
275 const Key
zero_key(name_key
, std::make_pair(type
, zero_flags
));
276 Section_name_map::iterator p
=
277 this->section_name_map_
.find(zero_key
);
278 if (p
!= this->section_name_map_
.end())
284 os
= this->make_output_section(name
, type
, flags
);
285 ins
.first
->second
= os
;
290 // Pick the output section to use for section NAME, in input file
291 // RELOBJ, with type TYPE and flags FLAGS. RELOBJ may be NULL for a
292 // linker created section. IS_INPUT_SECTION is true if we are
293 // choosing an output section for an input section found in a input
294 // file. This will return NULL if the input section should be
298 Layout::choose_output_section(const Relobj
* relobj
, const char* name
,
299 elfcpp::Elf_Word type
, elfcpp::Elf_Xword flags
,
300 bool is_input_section
)
302 // We should not see any input sections after we have attached
303 // sections to segments.
304 gold_assert(!is_input_section
|| !this->sections_are_attached_
);
306 // Some flags in the input section should not be automatically
307 // copied to the output section.
308 flags
&= ~ (elfcpp::SHF_INFO_LINK
309 | elfcpp::SHF_LINK_ORDER
312 | elfcpp::SHF_STRINGS
);
314 if (this->script_options_
->saw_sections_clause())
316 // We are using a SECTIONS clause, so the output section is
317 // chosen based only on the name.
319 Script_sections
* ss
= this->script_options_
->script_sections();
320 const char* file_name
= relobj
== NULL
? NULL
: relobj
->name().c_str();
321 Output_section
** output_section_slot
;
322 name
= ss
->output_section_name(file_name
, name
, &output_section_slot
);
325 // The SECTIONS clause says to discard this input section.
329 // If this is an orphan section--one not mentioned in the linker
330 // script--then OUTPUT_SECTION_SLOT will be NULL, and we do the
331 // default processing below.
333 if (output_section_slot
!= NULL
)
335 if (*output_section_slot
!= NULL
)
336 return *output_section_slot
;
338 // We don't put sections found in the linker script into
339 // SECTION_NAME_MAP_. That keeps us from getting confused
340 // if an orphan section is mapped to a section with the same
341 // name as one in the linker script.
343 name
= this->namepool_
.add(name
, false, NULL
);
345 Output_section
* os
= this->make_output_section(name
, type
, flags
);
346 os
->set_found_in_sections_clause();
347 *output_section_slot
= os
;
352 // FIXME: Handle SHF_OS_NONCONFORMING somewhere.
354 // Turn NAME from the name of the input section into the name of the
357 size_t len
= strlen(name
);
358 if (is_input_section
&& !parameters
->options().relocatable())
359 name
= Layout::output_section_name(name
, &len
);
361 Stringpool::Key name_key
;
362 name
= this->namepool_
.add_with_length(name
, len
, true, &name_key
);
364 // Find or make the output section. The output section is selected
365 // based on the section name, type, and flags.
366 return this->get_output_section(name
, name_key
, type
, flags
);
369 // Return the output section to use for input section SHNDX, with name
370 // NAME, with header HEADER, from object OBJECT. RELOC_SHNDX is the
371 // index of a relocation section which applies to this section, or 0
372 // if none, or -1U if more than one. RELOC_TYPE is the type of the
373 // relocation section if there is one. Set *OFF to the offset of this
374 // input section without the output section. Return NULL if the
375 // section should be discarded. Set *OFF to -1 if the section
376 // contents should not be written directly to the output file, but
377 // will instead receive special handling.
379 template<int size
, bool big_endian
>
381 Layout::layout(Sized_relobj
<size
, big_endian
>* object
, unsigned int shndx
,
382 const char* name
, const elfcpp::Shdr
<size
, big_endian
>& shdr
,
383 unsigned int reloc_shndx
, unsigned int, off_t
* off
)
385 if (!this->include_section(object
, name
, shdr
))
390 // In a relocatable link a grouped section must not be combined with
391 // any other sections.
392 if (parameters
->options().relocatable()
393 && (shdr
.get_sh_flags() & elfcpp::SHF_GROUP
) != 0)
395 name
= this->namepool_
.add(name
, true, NULL
);
396 os
= this->make_output_section(name
, shdr
.get_sh_type(),
397 shdr
.get_sh_flags());
401 os
= this->choose_output_section(object
, name
, shdr
.get_sh_type(),
402 shdr
.get_sh_flags(), true);
407 // By default the GNU linker sorts input sections whose names match
408 // .ctor.*, .dtor.*, .init_array.*, or .fini_array.*. The sections
409 // are sorted by name. This is used to implement constructor
410 // priority ordering. We are compatible.
411 if (!this->script_options_
->saw_sections_clause()
412 && (is_prefix_of(".ctors.", name
)
413 || is_prefix_of(".dtors.", name
)
414 || is_prefix_of(".init_array.", name
)
415 || is_prefix_of(".fini_array.", name
)))
416 os
->set_must_sort_attached_input_sections();
418 // FIXME: Handle SHF_LINK_ORDER somewhere.
420 *off
= os
->add_input_section(object
, shndx
, name
, shdr
, reloc_shndx
,
421 this->script_options_
->saw_sections_clause());
426 // Handle a relocation section when doing a relocatable link.
428 template<int size
, bool big_endian
>
430 Layout::layout_reloc(Sized_relobj
<size
, big_endian
>* object
,
432 const elfcpp::Shdr
<size
, big_endian
>& shdr
,
433 Output_section
* data_section
,
434 Relocatable_relocs
* rr
)
436 gold_assert(parameters
->options().relocatable()
437 || parameters
->options().emit_relocs());
439 int sh_type
= shdr
.get_sh_type();
442 if (sh_type
== elfcpp::SHT_REL
)
444 else if (sh_type
== elfcpp::SHT_RELA
)
448 name
+= data_section
->name();
450 Output_section
* os
= this->choose_output_section(object
, name
.c_str(),
455 os
->set_should_link_to_symtab();
456 os
->set_info_section(data_section
);
458 Output_section_data
* posd
;
459 if (sh_type
== elfcpp::SHT_REL
)
461 os
->set_entsize(elfcpp::Elf_sizes
<size
>::rel_size
);
462 posd
= new Output_relocatable_relocs
<elfcpp::SHT_REL
,
466 else if (sh_type
== elfcpp::SHT_RELA
)
468 os
->set_entsize(elfcpp::Elf_sizes
<size
>::rela_size
);
469 posd
= new Output_relocatable_relocs
<elfcpp::SHT_RELA
,
476 os
->add_output_section_data(posd
);
477 rr
->set_output_data(posd
);
482 // Handle a group section when doing a relocatable link.
484 template<int size
, bool big_endian
>
486 Layout::layout_group(Symbol_table
* symtab
,
487 Sized_relobj
<size
, big_endian
>* object
,
489 const char* group_section_name
,
490 const char* signature
,
491 const elfcpp::Shdr
<size
, big_endian
>& shdr
,
492 const elfcpp::Elf_Word
* contents
)
494 gold_assert(parameters
->options().relocatable());
495 gold_assert(shdr
.get_sh_type() == elfcpp::SHT_GROUP
);
496 group_section_name
= this->namepool_
.add(group_section_name
, true, NULL
);
497 Output_section
* os
= this->make_output_section(group_section_name
,
499 shdr
.get_sh_flags());
501 // We need to find a symbol with the signature in the symbol table.
502 // If we don't find one now, we need to look again later.
503 Symbol
* sym
= symtab
->lookup(signature
, NULL
);
505 os
->set_info_symndx(sym
);
508 // We will wind up using a symbol whose name is the signature.
509 // So just put the signature in the symbol name pool to save it.
510 signature
= symtab
->canonicalize_name(signature
);
511 this->group_signatures_
.push_back(Group_signature(os
, signature
));
514 os
->set_should_link_to_symtab();
517 section_size_type entry_count
=
518 convert_to_section_size_type(shdr
.get_sh_size() / 4);
519 Output_section_data
* posd
=
520 new Output_data_group
<size
, big_endian
>(object
, entry_count
, contents
);
521 os
->add_output_section_data(posd
);
524 // Special GNU handling of sections name .eh_frame. They will
525 // normally hold exception frame data as defined by the C++ ABI
526 // (http://codesourcery.com/cxx-abi/).
528 template<int size
, bool big_endian
>
530 Layout::layout_eh_frame(Sized_relobj
<size
, big_endian
>* object
,
531 const unsigned char* symbols
,
533 const unsigned char* symbol_names
,
534 off_t symbol_names_size
,
536 const elfcpp::Shdr
<size
, big_endian
>& shdr
,
537 unsigned int reloc_shndx
, unsigned int reloc_type
,
540 gold_assert(shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
);
541 gold_assert((shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0);
543 const char* const name
= ".eh_frame";
544 Output_section
* os
= this->choose_output_section(object
,
546 elfcpp::SHT_PROGBITS
,
552 if (this->eh_frame_section_
== NULL
)
554 this->eh_frame_section_
= os
;
555 this->eh_frame_data_
= new Eh_frame();
557 if (this->options_
.eh_frame_hdr())
559 Output_section
* hdr_os
=
560 this->choose_output_section(NULL
,
562 elfcpp::SHT_PROGBITS
,
568 Eh_frame_hdr
* hdr_posd
= new Eh_frame_hdr(os
,
569 this->eh_frame_data_
);
570 hdr_os
->add_output_section_data(hdr_posd
);
572 hdr_os
->set_after_input_sections();
574 if (!this->script_options_
->saw_phdrs_clause())
576 Output_segment
* hdr_oseg
;
577 hdr_oseg
= this->make_output_segment(elfcpp::PT_GNU_EH_FRAME
,
579 hdr_oseg
->add_output_section(hdr_os
, elfcpp::PF_R
);
582 this->eh_frame_data_
->set_eh_frame_hdr(hdr_posd
);
587 gold_assert(this->eh_frame_section_
== os
);
589 if (this->eh_frame_data_
->add_ehframe_input_section(object
,
598 os
->update_flags_for_input_section(shdr
.get_sh_flags());
600 // We found a .eh_frame section we are going to optimize, so now
601 // we can add the set of optimized sections to the output
602 // section. We need to postpone adding this until we've found a
603 // section we can optimize so that the .eh_frame section in
604 // crtbegin.o winds up at the start of the output section.
605 if (!this->added_eh_frame_data_
)
607 os
->add_output_section_data(this->eh_frame_data_
);
608 this->added_eh_frame_data_
= true;
614 // We couldn't handle this .eh_frame section for some reason.
615 // Add it as a normal section.
616 bool saw_sections_clause
= this->script_options_
->saw_sections_clause();
617 *off
= os
->add_input_section(object
, shndx
, name
, shdr
, reloc_shndx
,
618 saw_sections_clause
);
624 // Add POSD to an output section using NAME, TYPE, and FLAGS.
627 Layout::add_output_section_data(const char* name
, elfcpp::Elf_Word type
,
628 elfcpp::Elf_Xword flags
,
629 Output_section_data
* posd
)
631 Output_section
* os
= this->choose_output_section(NULL
, name
, type
, flags
,
634 os
->add_output_section_data(posd
);
637 // Map section flags to segment flags.
640 Layout::section_flags_to_segment(elfcpp::Elf_Xword flags
)
642 elfcpp::Elf_Word ret
= elfcpp::PF_R
;
643 if ((flags
& elfcpp::SHF_WRITE
) != 0)
645 if ((flags
& elfcpp::SHF_EXECINSTR
) != 0)
650 // Sometimes we compress sections. This is typically done for
651 // sections that are not part of normal program execution (such as
652 // .debug_* sections), and where the readers of these sections know
653 // how to deal with compressed sections. (To make it easier for them,
654 // we will rename the ouput section in such cases from .foo to
655 // .foo.zlib.nnnn, where nnnn is the uncompressed size.) This routine
656 // doesn't say for certain whether we'll compress -- it depends on
657 // commandline options as well -- just whether this section is a
658 // candidate for compression.
661 is_compressible_debug_section(const char* secname
)
663 return (strncmp(secname
, ".debug", sizeof(".debug") - 1) == 0);
666 // Make a new Output_section, and attach it to segments as
670 Layout::make_output_section(const char* name
, elfcpp::Elf_Word type
,
671 elfcpp::Elf_Xword flags
)
674 if ((flags
& elfcpp::SHF_ALLOC
) == 0
675 && strcmp(this->options_
.compress_debug_sections(), "none") != 0
676 && is_compressible_debug_section(name
))
677 os
= new Output_compressed_section(&this->options_
, name
, type
, flags
);
679 os
= new Output_section(name
, type
, flags
);
681 this->section_list_
.push_back(os
);
683 // The GNU linker by default sorts some sections by priority, so we
684 // do the same. We need to know that this might happen before we
685 // attach any input sections.
686 if (!this->script_options_
->saw_sections_clause()
687 && (strcmp(name
, ".ctors") == 0
688 || strcmp(name
, ".dtors") == 0
689 || strcmp(name
, ".init_array") == 0
690 || strcmp(name
, ".fini_array") == 0))
691 os
->set_may_sort_attached_input_sections();
693 // If we have already attached the sections to segments, then we
694 // need to attach this one now. This happens for sections created
695 // directly by the linker.
696 if (this->sections_are_attached_
)
697 this->attach_section_to_segment(os
);
702 // Attach output sections to segments. This is called after we have
703 // seen all the input sections.
706 Layout::attach_sections_to_segments()
708 for (Section_list::iterator p
= this->section_list_
.begin();
709 p
!= this->section_list_
.end();
711 this->attach_section_to_segment(*p
);
713 this->sections_are_attached_
= true;
716 // Attach an output section to a segment.
719 Layout::attach_section_to_segment(Output_section
* os
)
721 if ((os
->flags() & elfcpp::SHF_ALLOC
) == 0)
722 this->unattached_section_list_
.push_back(os
);
724 this->attach_allocated_section_to_segment(os
);
727 // Attach an allocated output section to a segment.
730 Layout::attach_allocated_section_to_segment(Output_section
* os
)
732 elfcpp::Elf_Xword flags
= os
->flags();
733 gold_assert((flags
& elfcpp::SHF_ALLOC
) != 0);
735 if (parameters
->options().relocatable())
738 // If we have a SECTIONS clause, we can't handle the attachment to
739 // segments until after we've seen all the sections.
740 if (this->script_options_
->saw_sections_clause())
743 gold_assert(!this->script_options_
->saw_phdrs_clause());
745 // This output section goes into a PT_LOAD segment.
747 elfcpp::Elf_Word seg_flags
= Layout::section_flags_to_segment(flags
);
749 // In general the only thing we really care about for PT_LOAD
750 // segments is whether or not they are writable, so that is how we
751 // search for them. People who need segments sorted on some other
752 // basis will have to use a linker script.
754 Segment_list::const_iterator p
;
755 for (p
= this->segment_list_
.begin();
756 p
!= this->segment_list_
.end();
759 if ((*p
)->type() == elfcpp::PT_LOAD
760 && ((*p
)->flags() & elfcpp::PF_W
) == (seg_flags
& elfcpp::PF_W
))
762 // If -Tbss was specified, we need to separate the data
764 if (this->options_
.user_set_Tbss())
766 if ((os
->type() == elfcpp::SHT_NOBITS
)
767 == (*p
)->has_any_data_sections())
771 (*p
)->add_output_section(os
, seg_flags
);
776 if (p
== this->segment_list_
.end())
778 Output_segment
* oseg
= this->make_output_segment(elfcpp::PT_LOAD
,
780 oseg
->add_output_section(os
, seg_flags
);
783 // If we see a loadable SHT_NOTE section, we create a PT_NOTE
785 if (os
->type() == elfcpp::SHT_NOTE
)
787 // See if we already have an equivalent PT_NOTE segment.
788 for (p
= this->segment_list_
.begin();
789 p
!= segment_list_
.end();
792 if ((*p
)->type() == elfcpp::PT_NOTE
793 && (((*p
)->flags() & elfcpp::PF_W
)
794 == (seg_flags
& elfcpp::PF_W
)))
796 (*p
)->add_output_section(os
, seg_flags
);
801 if (p
== this->segment_list_
.end())
803 Output_segment
* oseg
= this->make_output_segment(elfcpp::PT_NOTE
,
805 oseg
->add_output_section(os
, seg_flags
);
809 // If we see a loadable SHF_TLS section, we create a PT_TLS
810 // segment. There can only be one such segment.
811 if ((flags
& elfcpp::SHF_TLS
) != 0)
813 if (this->tls_segment_
== NULL
)
814 this->tls_segment_
= this->make_output_segment(elfcpp::PT_TLS
,
816 this->tls_segment_
->add_output_section(os
, seg_flags
);
820 // Make an output section for a script.
823 Layout::make_output_section_for_script(const char* name
)
825 name
= this->namepool_
.add(name
, false, NULL
);
826 Output_section
* os
= this->make_output_section(name
, elfcpp::SHT_PROGBITS
,
828 os
->set_found_in_sections_clause();
832 // Return the number of segments we expect to see.
835 Layout::expected_segment_count() const
837 size_t ret
= this->segment_list_
.size();
839 // If we didn't see a SECTIONS clause in a linker script, we should
840 // already have the complete list of segments. Otherwise we ask the
841 // SECTIONS clause how many segments it expects, and add in the ones
842 // we already have (PT_GNU_STACK, PT_GNU_EH_FRAME, etc.)
844 if (!this->script_options_
->saw_sections_clause())
848 const Script_sections
* ss
= this->script_options_
->script_sections();
849 return ret
+ ss
->expected_segment_count(this);
853 // Handle the .note.GNU-stack section at layout time. SEEN_GNU_STACK
854 // is whether we saw a .note.GNU-stack section in the object file.
855 // GNU_STACK_FLAGS is the section flags. The flags give the
856 // protection required for stack memory. We record this in an
857 // executable as a PT_GNU_STACK segment. If an object file does not
858 // have a .note.GNU-stack segment, we must assume that it is an old
859 // object. On some targets that will force an executable stack.
862 Layout::layout_gnu_stack(bool seen_gnu_stack
, uint64_t gnu_stack_flags
)
865 this->input_without_gnu_stack_note_
= true;
868 this->input_with_gnu_stack_note_
= true;
869 if ((gnu_stack_flags
& elfcpp::SHF_EXECINSTR
) != 0)
870 this->input_requires_executable_stack_
= true;
874 // Create the dynamic sections which are needed before we read the
878 Layout::create_initial_dynamic_sections(Symbol_table
* symtab
)
880 if (parameters
->doing_static_link())
883 this->dynamic_section_
= this->choose_output_section(NULL
, ".dynamic",
886 | elfcpp::SHF_WRITE
),
889 symtab
->define_in_output_data("_DYNAMIC", NULL
, this->dynamic_section_
, 0, 0,
890 elfcpp::STT_OBJECT
, elfcpp::STB_LOCAL
,
891 elfcpp::STV_HIDDEN
, 0, false, false);
893 this->dynamic_data_
= new Output_data_dynamic(&this->dynpool_
);
895 this->dynamic_section_
->add_output_section_data(this->dynamic_data_
);
898 // For each output section whose name can be represented as C symbol,
899 // define __start and __stop symbols for the section. This is a GNU
903 Layout::define_section_symbols(Symbol_table
* symtab
)
905 for (Section_list::const_iterator p
= this->section_list_
.begin();
906 p
!= this->section_list_
.end();
909 const char* const name
= (*p
)->name();
910 if (name
[strspn(name
,
912 "ABCDEFGHIJKLMNOPWRSTUVWXYZ"
913 "abcdefghijklmnopqrstuvwxyz"
917 const std::string
name_string(name
);
918 const std::string
start_name("__start_" + name_string
);
919 const std::string
stop_name("__stop_" + name_string
);
921 symtab
->define_in_output_data(start_name
.c_str(),
930 false, // offset_is_from_end
931 true); // only_if_ref
933 symtab
->define_in_output_data(stop_name
.c_str(),
942 true, // offset_is_from_end
943 true); // only_if_ref
948 // Define symbols for group signatures.
951 Layout::define_group_signatures(Symbol_table
* symtab
)
953 for (Group_signatures::iterator p
= this->group_signatures_
.begin();
954 p
!= this->group_signatures_
.end();
957 Symbol
* sym
= symtab
->lookup(p
->signature
, NULL
);
959 p
->section
->set_info_symndx(sym
);
962 // Force the name of the group section to the group
963 // signature, and use the group's section symbol as the
965 if (strcmp(p
->section
->name(), p
->signature
) != 0)
967 const char* name
= this->namepool_
.add(p
->signature
,
969 p
->section
->set_name(name
);
971 p
->section
->set_needs_symtab_index();
972 p
->section
->set_info_section_symndx(p
->section
);
976 this->group_signatures_
.clear();
979 // Find the first read-only PT_LOAD segment, creating one if
983 Layout::find_first_load_seg()
985 for (Segment_list::const_iterator p
= this->segment_list_
.begin();
986 p
!= this->segment_list_
.end();
989 if ((*p
)->type() == elfcpp::PT_LOAD
990 && ((*p
)->flags() & elfcpp::PF_R
) != 0
991 && ((*p
)->flags() & elfcpp::PF_W
) == 0)
995 gold_assert(!this->script_options_
->saw_phdrs_clause());
997 Output_segment
* load_seg
= this->make_output_segment(elfcpp::PT_LOAD
,
1002 // Finalize the layout. When this is called, we have created all the
1003 // output sections and all the output segments which are based on
1004 // input sections. We have several things to do, and we have to do
1005 // them in the right order, so that we get the right results correctly
1008 // 1) Finalize the list of output segments and create the segment
1011 // 2) Finalize the dynamic symbol table and associated sections.
1013 // 3) Determine the final file offset of all the output segments.
1015 // 4) Determine the final file offset of all the SHF_ALLOC output
1018 // 5) Create the symbol table sections and the section name table
1021 // 6) Finalize the symbol table: set symbol values to their final
1022 // value and make a final determination of which symbols are going
1023 // into the output symbol table.
1025 // 7) Create the section table header.
1027 // 8) Determine the final file offset of all the output sections which
1028 // are not SHF_ALLOC, including the section table header.
1030 // 9) Finalize the ELF file header.
1032 // This function returns the size of the output file.
1035 Layout::finalize(const Input_objects
* input_objects
, Symbol_table
* symtab
,
1036 Target
* target
, const Task
* task
)
1038 target
->finalize_sections(this);
1040 this->count_local_symbols(task
, input_objects
);
1042 this->create_gold_note();
1043 this->create_executable_stack_info(target
);
1044 this->create_build_id();
1046 Output_segment
* phdr_seg
= NULL
;
1047 if (!parameters
->options().relocatable() && !parameters
->doing_static_link())
1049 // There was a dynamic object in the link. We need to create
1050 // some information for the dynamic linker.
1052 // Create the PT_PHDR segment which will hold the program
1054 if (!this->script_options_
->saw_phdrs_clause())
1055 phdr_seg
= this->make_output_segment(elfcpp::PT_PHDR
, elfcpp::PF_R
);
1057 // Create the dynamic symbol table, including the hash table.
1058 Output_section
* dynstr
;
1059 std::vector
<Symbol
*> dynamic_symbols
;
1060 unsigned int local_dynamic_count
;
1061 Versions
versions(*this->script_options()->version_script_info(),
1063 this->create_dynamic_symtab(input_objects
, symtab
, &dynstr
,
1064 &local_dynamic_count
, &dynamic_symbols
,
1067 // Create the .interp section to hold the name of the
1068 // interpreter, and put it in a PT_INTERP segment.
1069 if (!parameters
->options().shared())
1070 this->create_interp(target
);
1072 // Finish the .dynamic section to hold the dynamic data, and put
1073 // it in a PT_DYNAMIC segment.
1074 this->finish_dynamic_section(input_objects
, symtab
);
1076 // We should have added everything we need to the dynamic string
1078 this->dynpool_
.set_string_offsets();
1080 // Create the version sections. We can't do this until the
1081 // dynamic string table is complete.
1082 this->create_version_sections(&versions
, symtab
, local_dynamic_count
,
1083 dynamic_symbols
, dynstr
);
1086 // If there is a SECTIONS clause, put all the input sections into
1087 // the required order.
1088 Output_segment
* load_seg
;
1089 if (this->script_options_
->saw_sections_clause())
1090 load_seg
= this->set_section_addresses_from_script(symtab
);
1091 else if (parameters
->options().relocatable())
1094 load_seg
= this->find_first_load_seg();
1096 if (this->options_
.oformat_enum() != General_options::OBJECT_FORMAT_ELF
)
1099 gold_assert(phdr_seg
== NULL
|| load_seg
!= NULL
);
1101 // Lay out the segment headers.
1102 Output_segment_headers
* segment_headers
;
1103 if (parameters
->options().relocatable())
1104 segment_headers
= NULL
;
1107 segment_headers
= new Output_segment_headers(this->segment_list_
);
1108 if (load_seg
!= NULL
)
1109 load_seg
->add_initial_output_data(segment_headers
);
1110 if (phdr_seg
!= NULL
)
1111 phdr_seg
->add_initial_output_data(segment_headers
);
1114 // Lay out the file header.
1115 Output_file_header
* file_header
;
1116 file_header
= new Output_file_header(target
, symtab
, segment_headers
,
1117 this->options_
.entry());
1118 if (load_seg
!= NULL
)
1119 load_seg
->add_initial_output_data(file_header
);
1121 this->special_output_list_
.push_back(file_header
);
1122 if (segment_headers
!= NULL
)
1123 this->special_output_list_
.push_back(segment_headers
);
1125 if (this->script_options_
->saw_phdrs_clause()
1126 && !parameters
->options().relocatable())
1128 // Support use of FILEHDRS and PHDRS attachments in a PHDRS
1129 // clause in a linker script.
1130 Script_sections
* ss
= this->script_options_
->script_sections();
1131 ss
->put_headers_in_phdrs(file_header
, segment_headers
);
1134 // We set the output section indexes in set_segment_offsets and
1135 // set_section_indexes.
1136 unsigned int shndx
= 1;
1138 // Set the file offsets of all the segments, and all the sections
1141 if (!parameters
->options().relocatable())
1142 off
= this->set_segment_offsets(target
, load_seg
, &shndx
);
1144 off
= this->set_relocatable_section_offsets(file_header
, &shndx
);
1146 // Set the file offsets of all the non-data sections we've seen so
1147 // far which don't have to wait for the input sections. We need
1148 // this in order to finalize local symbols in non-allocated
1150 off
= this->set_section_offsets(off
, BEFORE_INPUT_SECTIONS_PASS
);
1152 // Create the symbol table sections.
1153 this->create_symtab_sections(input_objects
, symtab
, &off
);
1154 if (!parameters
->doing_static_link())
1155 this->assign_local_dynsym_offsets(input_objects
);
1157 // Process any symbol assignments from a linker script. This must
1158 // be called after the symbol table has been finalized.
1159 this->script_options_
->finalize_symbols(symtab
, this);
1161 // Create the .shstrtab section.
1162 Output_section
* shstrtab_section
= this->create_shstrtab();
1164 // Set the file offsets of the rest of the non-data sections which
1165 // don't have to wait for the input sections.
1166 off
= this->set_section_offsets(off
, BEFORE_INPUT_SECTIONS_PASS
);
1168 // Now that all sections have been created, set the section indexes.
1169 shndx
= this->set_section_indexes(shndx
);
1171 // Create the section table header.
1172 this->create_shdrs(&off
);
1174 // If there are no sections which require postprocessing, we can
1175 // handle the section names now, and avoid a resize later.
1176 if (!this->any_postprocessing_sections_
)
1177 off
= this->set_section_offsets(off
,
1178 STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS
);
1180 file_header
->set_section_info(this->section_headers_
, shstrtab_section
);
1182 // Now we know exactly where everything goes in the output file
1183 // (except for non-allocated sections which require postprocessing).
1184 Output_data::layout_complete();
1186 this->output_file_size_
= off
;
1191 // Create a note header following the format defined in the ELF ABI.
1192 // NAME is the name, NOTE_TYPE is the type, DESCSZ is the size of the
1193 // descriptor. ALLOCATE is true if the section should be allocated in
1194 // memory. This returns the new note section. It sets
1195 // *TRAILING_PADDING to the number of trailing zero bytes required.
1198 Layout::create_note(const char* name
, int note_type
, size_t descsz
,
1199 bool allocate
, size_t* trailing_padding
)
1201 // Authorities all agree that the values in a .note field should
1202 // be aligned on 4-byte boundaries for 32-bit binaries. However,
1203 // they differ on what the alignment is for 64-bit binaries.
1204 // The GABI says unambiguously they take 8-byte alignment:
1205 // http://sco.com/developers/gabi/latest/ch5.pheader.html#note_section
1206 // Other documentation says alignment should always be 4 bytes:
1207 // http://www.netbsd.org/docs/kernel/elf-notes.html#note-format
1208 // GNU ld and GNU readelf both support the latter (at least as of
1209 // version 2.16.91), and glibc always generates the latter for
1210 // .note.ABI-tag (as of version 1.6), so that's the one we go with
1212 #ifdef GABI_FORMAT_FOR_DOTNOTE_SECTION // This is not defined by default.
1213 const int size
= parameters
->target().get_size();
1215 const int size
= 32;
1218 // The contents of the .note section.
1219 size_t namesz
= strlen(name
) + 1;
1220 size_t aligned_namesz
= align_address(namesz
, size
/ 8);
1221 size_t aligned_descsz
= align_address(descsz
, size
/ 8);
1223 size_t notehdrsz
= 3 * (size
/ 8) + aligned_namesz
;
1225 unsigned char* buffer
= new unsigned char[notehdrsz
];
1226 memset(buffer
, 0, notehdrsz
);
1228 bool is_big_endian
= parameters
->target().is_big_endian();
1234 elfcpp::Swap
<32, false>::writeval(buffer
, namesz
);
1235 elfcpp::Swap
<32, false>::writeval(buffer
+ 4, descsz
);
1236 elfcpp::Swap
<32, false>::writeval(buffer
+ 8, note_type
);
1240 elfcpp::Swap
<32, true>::writeval(buffer
, namesz
);
1241 elfcpp::Swap
<32, true>::writeval(buffer
+ 4, descsz
);
1242 elfcpp::Swap
<32, true>::writeval(buffer
+ 8, note_type
);
1245 else if (size
== 64)
1249 elfcpp::Swap
<64, false>::writeval(buffer
, namesz
);
1250 elfcpp::Swap
<64, false>::writeval(buffer
+ 8, descsz
);
1251 elfcpp::Swap
<64, false>::writeval(buffer
+ 16, note_type
);
1255 elfcpp::Swap
<64, true>::writeval(buffer
, namesz
);
1256 elfcpp::Swap
<64, true>::writeval(buffer
+ 8, descsz
);
1257 elfcpp::Swap
<64, true>::writeval(buffer
+ 16, note_type
);
1263 memcpy(buffer
+ 3 * (size
/ 8), name
, namesz
);
1265 const char* note_name
= this->namepool_
.add(".note", false, NULL
);
1266 elfcpp::Elf_Xword flags
= 0;
1268 flags
= elfcpp::SHF_ALLOC
;
1269 Output_section
* os
= this->make_output_section(note_name
,
1272 Output_section_data
* posd
= new Output_data_const_buffer(buffer
, notehdrsz
,
1274 os
->add_output_section_data(posd
);
1276 *trailing_padding
= aligned_descsz
- descsz
;
1281 // For an executable or shared library, create a note to record the
1282 // version of gold used to create the binary.
1285 Layout::create_gold_note()
1287 if (parameters
->options().relocatable())
1290 std::string desc
= std::string("gold ") + gold::get_version_string();
1292 size_t trailing_padding
;
1293 Output_section
*os
= this->create_note("GNU", elfcpp::NT_GNU_GOLD_VERSION
,
1294 desc
.size(), false, &trailing_padding
);
1296 Output_section_data
* posd
= new Output_data_const(desc
, 4);
1297 os
->add_output_section_data(posd
);
1299 if (trailing_padding
> 0)
1301 posd
= new Output_data_fixed_space(trailing_padding
, 0);
1302 os
->add_output_section_data(posd
);
1306 // Record whether the stack should be executable. This can be set
1307 // from the command line using the -z execstack or -z noexecstack
1308 // options. Otherwise, if any input file has a .note.GNU-stack
1309 // section with the SHF_EXECINSTR flag set, the stack should be
1310 // executable. Otherwise, if at least one input file a
1311 // .note.GNU-stack section, and some input file has no .note.GNU-stack
1312 // section, we use the target default for whether the stack should be
1313 // executable. Otherwise, we don't generate a stack note. When
1314 // generating a object file, we create a .note.GNU-stack section with
1315 // the appropriate marking. When generating an executable or shared
1316 // library, we create a PT_GNU_STACK segment.
1319 Layout::create_executable_stack_info(const Target
* target
)
1321 bool is_stack_executable
;
1322 if (this->options_
.is_execstack_set())
1323 is_stack_executable
= this->options_
.is_stack_executable();
1324 else if (!this->input_with_gnu_stack_note_
)
1328 if (this->input_requires_executable_stack_
)
1329 is_stack_executable
= true;
1330 else if (this->input_without_gnu_stack_note_
)
1331 is_stack_executable
= target
->is_default_stack_executable();
1333 is_stack_executable
= false;
1336 if (parameters
->options().relocatable())
1338 const char* name
= this->namepool_
.add(".note.GNU-stack", false, NULL
);
1339 elfcpp::Elf_Xword flags
= 0;
1340 if (is_stack_executable
)
1341 flags
|= elfcpp::SHF_EXECINSTR
;
1342 this->make_output_section(name
, elfcpp::SHT_PROGBITS
, flags
);
1346 if (this->script_options_
->saw_phdrs_clause())
1348 int flags
= elfcpp::PF_R
| elfcpp::PF_W
;
1349 if (is_stack_executable
)
1350 flags
|= elfcpp::PF_X
;
1351 this->make_output_segment(elfcpp::PT_GNU_STACK
, flags
);
1355 // If --build-id was used, set up the build ID note.
1358 Layout::create_build_id()
1360 if (!parameters
->options().user_set_build_id())
1363 const char* style
= parameters
->options().build_id();
1364 if (strcmp(style
, "none") == 0)
1367 // Set DESCSZ to the size of the note descriptor. When possible,
1368 // set DESC to the note descriptor contents.
1371 if (strcmp(style
, "md5") == 0)
1373 else if (strcmp(style
, "sha1") == 0)
1375 else if (strcmp(style
, "uuid") == 0)
1377 const size_t uuidsz
= 128 / 8;
1379 char buffer
[uuidsz
];
1380 memset(buffer
, 0, uuidsz
);
1382 int descriptor
= ::open("/dev/urandom", O_RDONLY
);
1384 gold_error(_("--build-id=uuid failed: could not open /dev/urandom: %s"),
1388 ssize_t got
= ::read(descriptor
, buffer
, uuidsz
);
1389 ::close(descriptor
);
1391 gold_error(_("/dev/urandom: read failed: %s"), strerror(errno
));
1392 else if (static_cast<size_t>(got
) != uuidsz
)
1393 gold_error(_("/dev/urandom: expected %zu bytes, got %zd bytes"),
1397 desc
.assign(buffer
, uuidsz
);
1400 else if (strncmp(style
, "0x", 2) == 0)
1403 const char* p
= style
+ 2;
1406 if (hex_p(p
[0]) && hex_p(p
[1]))
1408 char c
= (hex_value(p
[0]) << 4) | hex_value(p
[1]);
1412 else if (*p
== '-' || *p
== ':')
1415 gold_fatal(_("--build-id argument '%s' not a valid hex number"),
1418 descsz
= desc
.size();
1421 gold_fatal(_("unrecognized --build-id argument '%s'"), style
);
1424 size_t trailing_padding
;
1425 Output_section
* os
= this->create_note("GNU", elfcpp::NT_GNU_BUILD_ID
,
1426 descsz
, true, &trailing_padding
);
1430 // We know the value already, so we fill it in now.
1431 gold_assert(desc
.size() == descsz
);
1433 Output_section_data
* posd
= new Output_data_const(desc
, 4);
1434 os
->add_output_section_data(posd
);
1436 if (trailing_padding
!= 0)
1438 posd
= new Output_data_fixed_space(trailing_padding
, 0);
1439 os
->add_output_section_data(posd
);
1444 // We need to compute a checksum after we have completed the
1446 gold_assert(trailing_padding
== 0);
1447 this->build_id_note_
= new Output_data_fixed_space(descsz
, 4);
1448 os
->add_output_section_data(this->build_id_note_
);
1449 os
->set_after_input_sections();
1453 // Return whether SEG1 should be before SEG2 in the output file. This
1454 // is based entirely on the segment type and flags. When this is
1455 // called the segment addresses has normally not yet been set.
1458 Layout::segment_precedes(const Output_segment
* seg1
,
1459 const Output_segment
* seg2
)
1461 elfcpp::Elf_Word type1
= seg1
->type();
1462 elfcpp::Elf_Word type2
= seg2
->type();
1464 // The single PT_PHDR segment is required to precede any loadable
1465 // segment. We simply make it always first.
1466 if (type1
== elfcpp::PT_PHDR
)
1468 gold_assert(type2
!= elfcpp::PT_PHDR
);
1471 if (type2
== elfcpp::PT_PHDR
)
1474 // The single PT_INTERP segment is required to precede any loadable
1475 // segment. We simply make it always second.
1476 if (type1
== elfcpp::PT_INTERP
)
1478 gold_assert(type2
!= elfcpp::PT_INTERP
);
1481 if (type2
== elfcpp::PT_INTERP
)
1484 // We then put PT_LOAD segments before any other segments.
1485 if (type1
== elfcpp::PT_LOAD
&& type2
!= elfcpp::PT_LOAD
)
1487 if (type2
== elfcpp::PT_LOAD
&& type1
!= elfcpp::PT_LOAD
)
1490 // We put the PT_TLS segment last, because that is where the dynamic
1491 // linker expects to find it (this is just for efficiency; other
1492 // positions would also work correctly).
1493 if (type1
== elfcpp::PT_TLS
&& type2
!= elfcpp::PT_TLS
)
1495 if (type2
== elfcpp::PT_TLS
&& type1
!= elfcpp::PT_TLS
)
1498 const elfcpp::Elf_Word flags1
= seg1
->flags();
1499 const elfcpp::Elf_Word flags2
= seg2
->flags();
1501 // The order of non-PT_LOAD segments is unimportant. We simply sort
1502 // by the numeric segment type and flags values. There should not
1503 // be more than one segment with the same type and flags.
1504 if (type1
!= elfcpp::PT_LOAD
)
1507 return type1
< type2
;
1508 gold_assert(flags1
!= flags2
);
1509 return flags1
< flags2
;
1512 // If the addresses are set already, sort by load address.
1513 if (seg1
->are_addresses_set())
1515 if (!seg2
->are_addresses_set())
1518 unsigned int section_count1
= seg1
->output_section_count();
1519 unsigned int section_count2
= seg2
->output_section_count();
1520 if (section_count1
== 0 && section_count2
> 0)
1522 if (section_count1
> 0 && section_count2
== 0)
1525 uint64_t paddr1
= seg1
->first_section_load_address();
1526 uint64_t paddr2
= seg2
->first_section_load_address();
1527 if (paddr1
!= paddr2
)
1528 return paddr1
< paddr2
;
1530 else if (seg2
->are_addresses_set())
1533 // We sort PT_LOAD segments based on the flags. Readonly segments
1534 // come before writable segments. Then writable segments with data
1535 // come before writable segments without data. Then executable
1536 // segments come before non-executable segments. Then the unlikely
1537 // case of a non-readable segment comes before the normal case of a
1538 // readable segment. If there are multiple segments with the same
1539 // type and flags, we require that the address be set, and we sort
1540 // by virtual address and then physical address.
1541 if ((flags1
& elfcpp::PF_W
) != (flags2
& elfcpp::PF_W
))
1542 return (flags1
& elfcpp::PF_W
) == 0;
1543 if ((flags1
& elfcpp::PF_W
) != 0
1544 && seg1
->has_any_data_sections() != seg2
->has_any_data_sections())
1545 return seg1
->has_any_data_sections();
1546 if ((flags1
& elfcpp::PF_X
) != (flags2
& elfcpp::PF_X
))
1547 return (flags1
& elfcpp::PF_X
) != 0;
1548 if ((flags1
& elfcpp::PF_R
) != (flags2
& elfcpp::PF_R
))
1549 return (flags1
& elfcpp::PF_R
) == 0;
1551 // We shouldn't get here--we shouldn't create segments which we
1552 // can't distinguish.
1556 // Set the file offsets of all the segments, and all the sections they
1557 // contain. They have all been created. LOAD_SEG must be be laid out
1558 // first. Return the offset of the data to follow.
1561 Layout::set_segment_offsets(const Target
* target
, Output_segment
* load_seg
,
1562 unsigned int *pshndx
)
1564 // Sort them into the final order.
1565 std::sort(this->segment_list_
.begin(), this->segment_list_
.end(),
1566 Layout::Compare_segments());
1568 // Find the PT_LOAD segments, and set their addresses and offsets
1569 // and their section's addresses and offsets.
1571 if (this->options_
.user_set_Ttext())
1572 addr
= this->options_
.Ttext();
1573 else if (parameters
->options().shared())
1576 addr
= target
->default_text_segment_address();
1579 // If LOAD_SEG is NULL, then the file header and segment headers
1580 // will not be loadable. But they still need to be at offset 0 in
1581 // the file. Set their offsets now.
1582 if (load_seg
== NULL
)
1584 for (Data_list::iterator p
= this->special_output_list_
.begin();
1585 p
!= this->special_output_list_
.end();
1588 off
= align_address(off
, (*p
)->addralign());
1589 (*p
)->set_address_and_file_offset(0, off
);
1590 off
+= (*p
)->data_size();
1594 bool was_readonly
= false;
1595 for (Segment_list::iterator p
= this->segment_list_
.begin();
1596 p
!= this->segment_list_
.end();
1599 if ((*p
)->type() == elfcpp::PT_LOAD
)
1601 if (load_seg
!= NULL
&& load_seg
!= *p
)
1605 bool are_addresses_set
= (*p
)->are_addresses_set();
1606 if (are_addresses_set
)
1608 // When it comes to setting file offsets, we care about
1609 // the physical address.
1610 addr
= (*p
)->paddr();
1612 else if (this->options_
.user_set_Tdata()
1613 && ((*p
)->flags() & elfcpp::PF_W
) != 0
1614 && (!this->options_
.user_set_Tbss()
1615 || (*p
)->has_any_data_sections()))
1617 addr
= this->options_
.Tdata();
1618 are_addresses_set
= true;
1620 else if (this->options_
.user_set_Tbss()
1621 && ((*p
)->flags() & elfcpp::PF_W
) != 0
1622 && !(*p
)->has_any_data_sections())
1624 addr
= this->options_
.Tbss();
1625 are_addresses_set
= true;
1628 uint64_t orig_addr
= addr
;
1629 uint64_t orig_off
= off
;
1631 uint64_t aligned_addr
= 0;
1632 uint64_t abi_pagesize
= target
->abi_pagesize();
1634 // FIXME: This should depend on the -n and -N options.
1635 (*p
)->set_minimum_p_align(target
->common_pagesize());
1637 if (are_addresses_set
)
1639 // Adjust the file offset to the same address modulo the
1641 uint64_t unsigned_off
= off
;
1642 uint64_t aligned_off
= ((unsigned_off
& ~(abi_pagesize
- 1))
1643 | (addr
& (abi_pagesize
- 1)));
1644 if (aligned_off
< unsigned_off
)
1645 aligned_off
+= abi_pagesize
;
1650 // If the last segment was readonly, and this one is
1651 // not, then skip the address forward one page,
1652 // maintaining the same position within the page. This
1653 // lets us store both segments overlapping on a single
1654 // page in the file, but the loader will put them on
1655 // different pages in memory.
1657 addr
= align_address(addr
, (*p
)->maximum_alignment());
1658 aligned_addr
= addr
;
1660 if (was_readonly
&& ((*p
)->flags() & elfcpp::PF_W
) != 0)
1662 if ((addr
& (abi_pagesize
- 1)) != 0)
1663 addr
= addr
+ abi_pagesize
;
1666 off
= orig_off
+ ((addr
- orig_addr
) & (abi_pagesize
- 1));
1669 unsigned int shndx_hold
= *pshndx
;
1670 uint64_t new_addr
= (*p
)->set_section_addresses(this, false, addr
,
1673 // Now that we know the size of this segment, we may be able
1674 // to save a page in memory, at the cost of wasting some
1675 // file space, by instead aligning to the start of a new
1676 // page. Here we use the real machine page size rather than
1677 // the ABI mandated page size.
1679 if (!are_addresses_set
&& aligned_addr
!= addr
)
1681 uint64_t common_pagesize
= target
->common_pagesize();
1682 uint64_t first_off
= (common_pagesize
1684 & (common_pagesize
- 1)));
1685 uint64_t last_off
= new_addr
& (common_pagesize
- 1);
1688 && ((aligned_addr
& ~ (common_pagesize
- 1))
1689 != (new_addr
& ~ (common_pagesize
- 1)))
1690 && first_off
+ last_off
<= common_pagesize
)
1692 *pshndx
= shndx_hold
;
1693 addr
= align_address(aligned_addr
, common_pagesize
);
1694 addr
= align_address(addr
, (*p
)->maximum_alignment());
1695 off
= orig_off
+ ((addr
- orig_addr
) & (abi_pagesize
- 1));
1696 new_addr
= (*p
)->set_section_addresses(this, true, addr
,
1703 if (((*p
)->flags() & elfcpp::PF_W
) == 0)
1704 was_readonly
= true;
1708 // Handle the non-PT_LOAD segments, setting their offsets from their
1709 // section's offsets.
1710 for (Segment_list::iterator p
= this->segment_list_
.begin();
1711 p
!= this->segment_list_
.end();
1714 if ((*p
)->type() != elfcpp::PT_LOAD
)
1718 // Set the TLS offsets for each section in the PT_TLS segment.
1719 if (this->tls_segment_
!= NULL
)
1720 this->tls_segment_
->set_tls_offsets();
1725 // Set the offsets of all the allocated sections when doing a
1726 // relocatable link. This does the same jobs as set_segment_offsets,
1727 // only for a relocatable link.
1730 Layout::set_relocatable_section_offsets(Output_data
* file_header
,
1731 unsigned int *pshndx
)
1735 file_header
->set_address_and_file_offset(0, 0);
1736 off
+= file_header
->data_size();
1738 for (Section_list::iterator p
= this->section_list_
.begin();
1739 p
!= this->section_list_
.end();
1742 // We skip unallocated sections here, except that group sections
1743 // have to come first.
1744 if (((*p
)->flags() & elfcpp::SHF_ALLOC
) == 0
1745 && (*p
)->type() != elfcpp::SHT_GROUP
)
1748 off
= align_address(off
, (*p
)->addralign());
1750 // The linker script might have set the address.
1751 if (!(*p
)->is_address_valid())
1752 (*p
)->set_address(0);
1753 (*p
)->set_file_offset(off
);
1754 (*p
)->finalize_data_size();
1755 off
+= (*p
)->data_size();
1757 (*p
)->set_out_shndx(*pshndx
);
1764 // Set the file offset of all the sections not associated with a
1768 Layout::set_section_offsets(off_t off
, Layout::Section_offset_pass pass
)
1770 for (Section_list::iterator p
= this->unattached_section_list_
.begin();
1771 p
!= this->unattached_section_list_
.end();
1774 // The symtab section is handled in create_symtab_sections.
1775 if (*p
== this->symtab_section_
)
1778 // If we've already set the data size, don't set it again.
1779 if ((*p
)->is_offset_valid() && (*p
)->is_data_size_valid())
1782 if (pass
== BEFORE_INPUT_SECTIONS_PASS
1783 && (*p
)->requires_postprocessing())
1785 (*p
)->create_postprocessing_buffer();
1786 this->any_postprocessing_sections_
= true;
1789 if (pass
== BEFORE_INPUT_SECTIONS_PASS
1790 && (*p
)->after_input_sections())
1792 else if (pass
== POSTPROCESSING_SECTIONS_PASS
1793 && (!(*p
)->after_input_sections()
1794 || (*p
)->type() == elfcpp::SHT_STRTAB
))
1796 else if (pass
== STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS
1797 && (!(*p
)->after_input_sections()
1798 || (*p
)->type() != elfcpp::SHT_STRTAB
))
1801 off
= align_address(off
, (*p
)->addralign());
1802 (*p
)->set_file_offset(off
);
1803 (*p
)->finalize_data_size();
1804 off
+= (*p
)->data_size();
1806 // At this point the name must be set.
1807 if (pass
!= STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS
)
1808 this->namepool_
.add((*p
)->name(), false, NULL
);
1813 // Set the section indexes of all the sections not associated with a
1817 Layout::set_section_indexes(unsigned int shndx
)
1819 const bool output_is_object
= parameters
->options().relocatable();
1820 for (Section_list::iterator p
= this->unattached_section_list_
.begin();
1821 p
!= this->unattached_section_list_
.end();
1824 // In a relocatable link, we already did group sections.
1825 if (output_is_object
1826 && (*p
)->type() == elfcpp::SHT_GROUP
)
1829 (*p
)->set_out_shndx(shndx
);
1835 // Set the section addresses according to the linker script. This is
1836 // only called when we see a SECTIONS clause. This returns the
1837 // program segment which should hold the file header and segment
1838 // headers, if any. It will return NULL if they should not be in a
1842 Layout::set_section_addresses_from_script(Symbol_table
* symtab
)
1844 Script_sections
* ss
= this->script_options_
->script_sections();
1845 gold_assert(ss
->saw_sections_clause());
1847 // Place each orphaned output section in the script.
1848 for (Section_list::iterator p
= this->section_list_
.begin();
1849 p
!= this->section_list_
.end();
1852 if (!(*p
)->found_in_sections_clause())
1853 ss
->place_orphan(*p
);
1856 return this->script_options_
->set_section_addresses(symtab
, this);
1859 // Count the local symbols in the regular symbol table and the dynamic
1860 // symbol table, and build the respective string pools.
1863 Layout::count_local_symbols(const Task
* task
,
1864 const Input_objects
* input_objects
)
1866 // First, figure out an upper bound on the number of symbols we'll
1867 // be inserting into each pool. This helps us create the pools with
1868 // the right size, to avoid unnecessary hashtable resizing.
1869 unsigned int symbol_count
= 0;
1870 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
1871 p
!= input_objects
->relobj_end();
1873 symbol_count
+= (*p
)->local_symbol_count();
1875 // Go from "upper bound" to "estimate." We overcount for two
1876 // reasons: we double-count symbols that occur in more than one
1877 // object file, and we count symbols that are dropped from the
1878 // output. Add it all together and assume we overcount by 100%.
1881 // We assume all symbols will go into both the sympool and dynpool.
1882 this->sympool_
.reserve(symbol_count
);
1883 this->dynpool_
.reserve(symbol_count
);
1885 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
1886 p
!= input_objects
->relobj_end();
1889 Task_lock_obj
<Object
> tlo(task
, *p
);
1890 (*p
)->count_local_symbols(&this->sympool_
, &this->dynpool_
);
1894 // Create the symbol table sections. Here we also set the final
1895 // values of the symbols. At this point all the loadable sections are
1899 Layout::create_symtab_sections(const Input_objects
* input_objects
,
1900 Symbol_table
* symtab
,
1905 if (parameters
->target().get_size() == 32)
1907 symsize
= elfcpp::Elf_sizes
<32>::sym_size
;
1910 else if (parameters
->target().get_size() == 64)
1912 symsize
= elfcpp::Elf_sizes
<64>::sym_size
;
1919 off
= align_address(off
, align
);
1920 off_t startoff
= off
;
1922 // Save space for the dummy symbol at the start of the section. We
1923 // never bother to write this out--it will just be left as zero.
1925 unsigned int local_symbol_index
= 1;
1927 // Add STT_SECTION symbols for each Output section which needs one.
1928 for (Section_list::iterator p
= this->section_list_
.begin();
1929 p
!= this->section_list_
.end();
1932 if (!(*p
)->needs_symtab_index())
1933 (*p
)->set_symtab_index(-1U);
1936 (*p
)->set_symtab_index(local_symbol_index
);
1937 ++local_symbol_index
;
1942 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
1943 p
!= input_objects
->relobj_end();
1946 unsigned int index
= (*p
)->finalize_local_symbols(local_symbol_index
,
1948 off
+= (index
- local_symbol_index
) * symsize
;
1949 local_symbol_index
= index
;
1952 unsigned int local_symcount
= local_symbol_index
;
1953 gold_assert(local_symcount
* symsize
== off
- startoff
);
1956 size_t dyn_global_index
;
1958 if (this->dynsym_section_
== NULL
)
1961 dyn_global_index
= 0;
1966 dyn_global_index
= this->dynsym_section_
->info();
1967 off_t locsize
= dyn_global_index
* this->dynsym_section_
->entsize();
1968 dynoff
= this->dynsym_section_
->offset() + locsize
;
1969 dyncount
= (this->dynsym_section_
->data_size() - locsize
) / symsize
;
1970 gold_assert(static_cast<off_t
>(dyncount
* symsize
)
1971 == this->dynsym_section_
->data_size() - locsize
);
1974 off
= symtab
->finalize(off
, dynoff
, dyn_global_index
, dyncount
,
1975 &this->sympool_
, &local_symcount
);
1977 if (!parameters
->options().strip_all())
1979 this->sympool_
.set_string_offsets();
1981 const char* symtab_name
= this->namepool_
.add(".symtab", false, NULL
);
1982 Output_section
* osymtab
= this->make_output_section(symtab_name
,
1985 this->symtab_section_
= osymtab
;
1987 Output_section_data
* pos
= new Output_data_fixed_space(off
- startoff
,
1989 osymtab
->add_output_section_data(pos
);
1991 const char* strtab_name
= this->namepool_
.add(".strtab", false, NULL
);
1992 Output_section
* ostrtab
= this->make_output_section(strtab_name
,
1996 Output_section_data
* pstr
= new Output_data_strtab(&this->sympool_
);
1997 ostrtab
->add_output_section_data(pstr
);
1999 osymtab
->set_file_offset(startoff
);
2000 osymtab
->finalize_data_size();
2001 osymtab
->set_link_section(ostrtab
);
2002 osymtab
->set_info(local_symcount
);
2003 osymtab
->set_entsize(symsize
);
2009 // Create the .shstrtab section, which holds the names of the
2010 // sections. At the time this is called, we have created all the
2011 // output sections except .shstrtab itself.
2014 Layout::create_shstrtab()
2016 // FIXME: We don't need to create a .shstrtab section if we are
2017 // stripping everything.
2019 const char* name
= this->namepool_
.add(".shstrtab", false, NULL
);
2021 Output_section
* os
= this->make_output_section(name
, elfcpp::SHT_STRTAB
, 0);
2023 // We can't write out this section until we've set all the section
2024 // names, and we don't set the names of compressed output sections
2025 // until relocations are complete.
2026 os
->set_after_input_sections();
2028 Output_section_data
* posd
= new Output_data_strtab(&this->namepool_
);
2029 os
->add_output_section_data(posd
);
2034 // Create the section headers. SIZE is 32 or 64. OFF is the file
2038 Layout::create_shdrs(off_t
* poff
)
2040 Output_section_headers
* oshdrs
;
2041 oshdrs
= new Output_section_headers(this,
2042 &this->segment_list_
,
2043 &this->section_list_
,
2044 &this->unattached_section_list_
,
2046 off_t off
= align_address(*poff
, oshdrs
->addralign());
2047 oshdrs
->set_address_and_file_offset(0, off
);
2048 off
+= oshdrs
->data_size();
2050 this->section_headers_
= oshdrs
;
2053 // Create the dynamic symbol table.
2056 Layout::create_dynamic_symtab(const Input_objects
* input_objects
,
2057 Symbol_table
* symtab
,
2058 Output_section
**pdynstr
,
2059 unsigned int* plocal_dynamic_count
,
2060 std::vector
<Symbol
*>* pdynamic_symbols
,
2061 Versions
* pversions
)
2063 // Count all the symbols in the dynamic symbol table, and set the
2064 // dynamic symbol indexes.
2066 // Skip symbol 0, which is always all zeroes.
2067 unsigned int index
= 1;
2069 // Add STT_SECTION symbols for each Output section which needs one.
2070 for (Section_list::iterator p
= this->section_list_
.begin();
2071 p
!= this->section_list_
.end();
2074 if (!(*p
)->needs_dynsym_index())
2075 (*p
)->set_dynsym_index(-1U);
2078 (*p
)->set_dynsym_index(index
);
2083 // Count the local symbols that need to go in the dynamic symbol table,
2084 // and set the dynamic symbol indexes.
2085 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
2086 p
!= input_objects
->relobj_end();
2089 unsigned int new_index
= (*p
)->set_local_dynsym_indexes(index
);
2093 unsigned int local_symcount
= index
;
2094 *plocal_dynamic_count
= local_symcount
;
2096 // FIXME: We have to tell set_dynsym_indexes whether the
2097 // -E/--export-dynamic option was used.
2098 index
= symtab
->set_dynsym_indexes(index
, pdynamic_symbols
,
2099 &this->dynpool_
, pversions
);
2103 const int size
= parameters
->target().get_size();
2106 symsize
= elfcpp::Elf_sizes
<32>::sym_size
;
2109 else if (size
== 64)
2111 symsize
= elfcpp::Elf_sizes
<64>::sym_size
;
2117 // Create the dynamic symbol table section.
2119 Output_section
* dynsym
= this->choose_output_section(NULL
, ".dynsym",
2124 Output_section_data
* odata
= new Output_data_fixed_space(index
* symsize
,
2126 dynsym
->add_output_section_data(odata
);
2128 dynsym
->set_info(local_symcount
);
2129 dynsym
->set_entsize(symsize
);
2130 dynsym
->set_addralign(align
);
2132 this->dynsym_section_
= dynsym
;
2134 Output_data_dynamic
* const odyn
= this->dynamic_data_
;
2135 odyn
->add_section_address(elfcpp::DT_SYMTAB
, dynsym
);
2136 odyn
->add_constant(elfcpp::DT_SYMENT
, symsize
);
2138 // Create the dynamic string table section.
2140 Output_section
* dynstr
= this->choose_output_section(NULL
, ".dynstr",
2145 Output_section_data
* strdata
= new Output_data_strtab(&this->dynpool_
);
2146 dynstr
->add_output_section_data(strdata
);
2148 dynsym
->set_link_section(dynstr
);
2149 this->dynamic_section_
->set_link_section(dynstr
);
2151 odyn
->add_section_address(elfcpp::DT_STRTAB
, dynstr
);
2152 odyn
->add_section_size(elfcpp::DT_STRSZ
, dynstr
);
2156 // Create the hash tables.
2158 if (strcmp(parameters
->options().hash_style(), "sysv") == 0
2159 || strcmp(parameters
->options().hash_style(), "both") == 0)
2161 unsigned char* phash
;
2162 unsigned int hashlen
;
2163 Dynobj::create_elf_hash_table(*pdynamic_symbols
, local_symcount
,
2166 Output_section
* hashsec
= this->choose_output_section(NULL
, ".hash",
2171 Output_section_data
* hashdata
= new Output_data_const_buffer(phash
,
2174 hashsec
->add_output_section_data(hashdata
);
2176 hashsec
->set_link_section(dynsym
);
2177 hashsec
->set_entsize(4);
2179 odyn
->add_section_address(elfcpp::DT_HASH
, hashsec
);
2182 if (strcmp(parameters
->options().hash_style(), "gnu") == 0
2183 || strcmp(parameters
->options().hash_style(), "both") == 0)
2185 unsigned char* phash
;
2186 unsigned int hashlen
;
2187 Dynobj::create_gnu_hash_table(*pdynamic_symbols
, local_symcount
,
2190 Output_section
* hashsec
= this->choose_output_section(NULL
, ".gnu.hash",
2191 elfcpp::SHT_GNU_HASH
,
2195 Output_section_data
* hashdata
= new Output_data_const_buffer(phash
,
2198 hashsec
->add_output_section_data(hashdata
);
2200 hashsec
->set_link_section(dynsym
);
2201 hashsec
->set_entsize(4);
2203 odyn
->add_section_address(elfcpp::DT_GNU_HASH
, hashsec
);
2207 // Assign offsets to each local portion of the dynamic symbol table.
2210 Layout::assign_local_dynsym_offsets(const Input_objects
* input_objects
)
2212 Output_section
* dynsym
= this->dynsym_section_
;
2213 gold_assert(dynsym
!= NULL
);
2215 off_t off
= dynsym
->offset();
2217 // Skip the dummy symbol at the start of the section.
2218 off
+= dynsym
->entsize();
2220 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
2221 p
!= input_objects
->relobj_end();
2224 unsigned int count
= (*p
)->set_local_dynsym_offset(off
);
2225 off
+= count
* dynsym
->entsize();
2229 // Create the version sections.
2232 Layout::create_version_sections(const Versions
* versions
,
2233 const Symbol_table
* symtab
,
2234 unsigned int local_symcount
,
2235 const std::vector
<Symbol
*>& dynamic_symbols
,
2236 const Output_section
* dynstr
)
2238 if (!versions
->any_defs() && !versions
->any_needs())
2241 switch (parameters
->size_and_endianness())
2243 #ifdef HAVE_TARGET_32_LITTLE
2244 case Parameters::TARGET_32_LITTLE
:
2245 this->sized_create_version_sections
<32, false>(versions
, symtab
,
2247 dynamic_symbols
, dynstr
);
2250 #ifdef HAVE_TARGET_32_BIG
2251 case Parameters::TARGET_32_BIG
:
2252 this->sized_create_version_sections
<32, true>(versions
, symtab
,
2254 dynamic_symbols
, dynstr
);
2257 #ifdef HAVE_TARGET_64_LITTLE
2258 case Parameters::TARGET_64_LITTLE
:
2259 this->sized_create_version_sections
<64, false>(versions
, symtab
,
2261 dynamic_symbols
, dynstr
);
2264 #ifdef HAVE_TARGET_64_BIG
2265 case Parameters::TARGET_64_BIG
:
2266 this->sized_create_version_sections
<64, true>(versions
, symtab
,
2268 dynamic_symbols
, dynstr
);
2276 // Create the version sections, sized version.
2278 template<int size
, bool big_endian
>
2280 Layout::sized_create_version_sections(
2281 const Versions
* versions
,
2282 const Symbol_table
* symtab
,
2283 unsigned int local_symcount
,
2284 const std::vector
<Symbol
*>& dynamic_symbols
,
2285 const Output_section
* dynstr
)
2287 Output_section
* vsec
= this->choose_output_section(NULL
, ".gnu.version",
2288 elfcpp::SHT_GNU_versym
,
2292 unsigned char* vbuf
;
2294 versions
->symbol_section_contents
<size
, big_endian
>(symtab
, &this->dynpool_
,
2299 Output_section_data
* vdata
= new Output_data_const_buffer(vbuf
, vsize
, 2);
2301 vsec
->add_output_section_data(vdata
);
2302 vsec
->set_entsize(2);
2303 vsec
->set_link_section(this->dynsym_section_
);
2305 Output_data_dynamic
* const odyn
= this->dynamic_data_
;
2306 odyn
->add_section_address(elfcpp::DT_VERSYM
, vsec
);
2308 if (versions
->any_defs())
2310 Output_section
* vdsec
;
2311 vdsec
= this->choose_output_section(NULL
, ".gnu.version_d",
2312 elfcpp::SHT_GNU_verdef
,
2316 unsigned char* vdbuf
;
2317 unsigned int vdsize
;
2318 unsigned int vdentries
;
2319 versions
->def_section_contents
<size
, big_endian
>(&this->dynpool_
, &vdbuf
,
2320 &vdsize
, &vdentries
);
2322 Output_section_data
* vddata
= new Output_data_const_buffer(vdbuf
,
2326 vdsec
->add_output_section_data(vddata
);
2327 vdsec
->set_link_section(dynstr
);
2328 vdsec
->set_info(vdentries
);
2330 odyn
->add_section_address(elfcpp::DT_VERDEF
, vdsec
);
2331 odyn
->add_constant(elfcpp::DT_VERDEFNUM
, vdentries
);
2334 if (versions
->any_needs())
2336 Output_section
* vnsec
;
2337 vnsec
= this->choose_output_section(NULL
, ".gnu.version_r",
2338 elfcpp::SHT_GNU_verneed
,
2342 unsigned char* vnbuf
;
2343 unsigned int vnsize
;
2344 unsigned int vnentries
;
2345 versions
->need_section_contents
<size
, big_endian
>(&this->dynpool_
,
2349 Output_section_data
* vndata
= new Output_data_const_buffer(vnbuf
,
2353 vnsec
->add_output_section_data(vndata
);
2354 vnsec
->set_link_section(dynstr
);
2355 vnsec
->set_info(vnentries
);
2357 odyn
->add_section_address(elfcpp::DT_VERNEED
, vnsec
);
2358 odyn
->add_constant(elfcpp::DT_VERNEEDNUM
, vnentries
);
2362 // Create the .interp section and PT_INTERP segment.
2365 Layout::create_interp(const Target
* target
)
2367 const char* interp
= this->options_
.dynamic_linker();
2370 interp
= target
->dynamic_linker();
2371 gold_assert(interp
!= NULL
);
2374 size_t len
= strlen(interp
) + 1;
2376 Output_section_data
* odata
= new Output_data_const(interp
, len
, 1);
2378 Output_section
* osec
= this->choose_output_section(NULL
, ".interp",
2379 elfcpp::SHT_PROGBITS
,
2382 osec
->add_output_section_data(odata
);
2384 if (!this->script_options_
->saw_phdrs_clause())
2386 Output_segment
* oseg
= this->make_output_segment(elfcpp::PT_INTERP
,
2388 oseg
->add_initial_output_section(osec
, elfcpp::PF_R
);
2392 // Finish the .dynamic section and PT_DYNAMIC segment.
2395 Layout::finish_dynamic_section(const Input_objects
* input_objects
,
2396 const Symbol_table
* symtab
)
2398 if (!this->script_options_
->saw_phdrs_clause())
2400 Output_segment
* oseg
= this->make_output_segment(elfcpp::PT_DYNAMIC
,
2403 oseg
->add_initial_output_section(this->dynamic_section_
,
2404 elfcpp::PF_R
| elfcpp::PF_W
);
2407 Output_data_dynamic
* const odyn
= this->dynamic_data_
;
2409 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
2410 p
!= input_objects
->dynobj_end();
2413 // FIXME: Handle --as-needed.
2414 odyn
->add_string(elfcpp::DT_NEEDED
, (*p
)->soname());
2417 if (parameters
->options().shared())
2419 const char* soname
= this->options_
.soname();
2421 odyn
->add_string(elfcpp::DT_SONAME
, soname
);
2424 // FIXME: Support --init and --fini.
2425 Symbol
* sym
= symtab
->lookup("_init");
2426 if (sym
!= NULL
&& sym
->is_defined() && !sym
->is_from_dynobj())
2427 odyn
->add_symbol(elfcpp::DT_INIT
, sym
);
2429 sym
= symtab
->lookup("_fini");
2430 if (sym
!= NULL
&& sym
->is_defined() && !sym
->is_from_dynobj())
2431 odyn
->add_symbol(elfcpp::DT_FINI
, sym
);
2433 // FIXME: Support DT_INIT_ARRAY and DT_FINI_ARRAY.
2435 // Add a DT_RPATH entry if needed.
2436 const General_options::Dir_list
& rpath(this->options_
.rpath());
2439 std::string rpath_val
;
2440 for (General_options::Dir_list::const_iterator p
= rpath
.begin();
2444 if (rpath_val
.empty())
2445 rpath_val
= p
->name();
2448 // Eliminate duplicates.
2449 General_options::Dir_list::const_iterator q
;
2450 for (q
= rpath
.begin(); q
!= p
; ++q
)
2451 if (q
->name() == p
->name())
2456 rpath_val
+= p
->name();
2461 odyn
->add_string(elfcpp::DT_RPATH
, rpath_val
);
2464 // Look for text segments that have dynamic relocations.
2465 bool have_textrel
= false;
2466 if (!this->script_options_
->saw_sections_clause())
2468 for (Segment_list::const_iterator p
= this->segment_list_
.begin();
2469 p
!= this->segment_list_
.end();
2472 if (((*p
)->flags() & elfcpp::PF_W
) == 0
2473 && (*p
)->dynamic_reloc_count() > 0)
2475 have_textrel
= true;
2482 // We don't know the section -> segment mapping, so we are
2483 // conservative and just look for readonly sections with
2484 // relocations. If those sections wind up in writable segments,
2485 // then we have created an unnecessary DT_TEXTREL entry.
2486 for (Section_list::const_iterator p
= this->section_list_
.begin();
2487 p
!= this->section_list_
.end();
2490 if (((*p
)->flags() & elfcpp::SHF_ALLOC
) != 0
2491 && ((*p
)->flags() & elfcpp::SHF_WRITE
) == 0
2492 && ((*p
)->dynamic_reloc_count() > 0))
2494 have_textrel
= true;
2500 // Add a DT_FLAGS entry. We add it even if no flags are set so that
2501 // post-link tools can easily modify these flags if desired.
2502 unsigned int flags
= 0;
2505 // Add a DT_TEXTREL for compatibility with older loaders.
2506 odyn
->add_constant(elfcpp::DT_TEXTREL
, 0);
2507 flags
|= elfcpp::DF_TEXTREL
;
2509 if (parameters
->options().shared() && this->has_static_tls())
2510 flags
|= elfcpp::DF_STATIC_TLS
;
2511 odyn
->add_constant(elfcpp::DT_FLAGS
, flags
);
2514 // The mapping of .gnu.linkonce section names to real section names.
2516 #define MAPPING_INIT(f, t) { f, sizeof(f) - 1, t, sizeof(t) - 1 }
2517 const Layout::Linkonce_mapping
Layout::linkonce_mapping
[] =
2519 MAPPING_INIT("d.rel.ro", ".data.rel.ro"), // Must be before "d".
2520 MAPPING_INIT("t", ".text"),
2521 MAPPING_INIT("r", ".rodata"),
2522 MAPPING_INIT("d", ".data"),
2523 MAPPING_INIT("b", ".bss"),
2524 MAPPING_INIT("s", ".sdata"),
2525 MAPPING_INIT("sb", ".sbss"),
2526 MAPPING_INIT("s2", ".sdata2"),
2527 MAPPING_INIT("sb2", ".sbss2"),
2528 MAPPING_INIT("wi", ".debug_info"),
2529 MAPPING_INIT("td", ".tdata"),
2530 MAPPING_INIT("tb", ".tbss"),
2531 MAPPING_INIT("lr", ".lrodata"),
2532 MAPPING_INIT("l", ".ldata"),
2533 MAPPING_INIT("lb", ".lbss"),
2537 const int Layout::linkonce_mapping_count
=
2538 sizeof(Layout::linkonce_mapping
) / sizeof(Layout::linkonce_mapping
[0]);
2540 // Return the name of the output section to use for a .gnu.linkonce
2541 // section. This is based on the default ELF linker script of the old
2542 // GNU linker. For example, we map a name like ".gnu.linkonce.t.foo"
2543 // to ".text". Set *PLEN to the length of the name. *PLEN is
2544 // initialized to the length of NAME.
2547 Layout::linkonce_output_name(const char* name
, size_t *plen
)
2549 const char* s
= name
+ sizeof(".gnu.linkonce") - 1;
2553 const Linkonce_mapping
* plm
= linkonce_mapping
;
2554 for (int i
= 0; i
< linkonce_mapping_count
; ++i
, ++plm
)
2556 if (strncmp(s
, plm
->from
, plm
->fromlen
) == 0 && s
[plm
->fromlen
] == '.')
2565 // Choose the output section name to use given an input section name.
2566 // Set *PLEN to the length of the name. *PLEN is initialized to the
2570 Layout::output_section_name(const char* name
, size_t* plen
)
2572 if (Layout::is_linkonce(name
))
2574 // .gnu.linkonce sections are laid out as though they were named
2575 // for the sections are placed into.
2576 return Layout::linkonce_output_name(name
, plen
);
2579 // gcc 4.3 generates the following sorts of section names when it
2580 // needs a section name specific to a function:
2586 // .data.rel.local.FN
2588 // .data.rel.ro.local.FN
2595 // The GNU linker maps all of those to the part before the .FN,
2596 // except that .data.rel.local.FN is mapped to .data, and
2597 // .data.rel.ro.local.FN is mapped to .data.rel.ro. The sections
2598 // beginning with .data.rel.ro.local are grouped together.
2600 // For an anonymous namespace, the string FN can contain a '.'.
2602 // Also of interest: .rodata.strN.N, .rodata.cstN, both of which the
2603 // GNU linker maps to .rodata.
2605 // The .data.rel.ro sections enable a security feature triggered by
2606 // the -z relro option. Section which need to be relocated at
2607 // program startup time but which may be readonly after startup are
2608 // grouped into .data.rel.ro. They are then put into a PT_GNU_RELRO
2609 // segment. The dynamic linker will make that segment writable,
2610 // perform relocations, and then make it read-only. FIXME: We do
2611 // not yet implement this optimization.
2613 // It is hard to handle this in a principled way.
2615 // These are the rules we follow:
2617 // If the section name has no initial '.', or no dot other than an
2618 // initial '.', we use the name unchanged (i.e., "mysection" and
2619 // ".text" are unchanged).
2621 // If the name starts with ".data.rel.ro" we use ".data.rel.ro".
2623 // Otherwise, we drop the second '.' and everything that comes after
2624 // it (i.e., ".text.XXX" becomes ".text").
2626 const char* s
= name
;
2630 const char* sdot
= strchr(s
, '.');
2634 const char* const data_rel_ro
= ".data.rel.ro";
2635 if (strncmp(name
, data_rel_ro
, strlen(data_rel_ro
)) == 0)
2637 *plen
= strlen(data_rel_ro
);
2641 *plen
= sdot
- name
;
2645 // Record the signature of a comdat section, and return whether to
2646 // include it in the link. If GROUP is true, this is a regular
2647 // section group. If GROUP is false, this is a group signature
2648 // derived from the name of a linkonce section. We want linkonce
2649 // signatures and group signatures to block each other, but we don't
2650 // want a linkonce signature to block another linkonce signature.
2653 Layout::add_comdat(const char* signature
, bool group
)
2655 std::string
sig(signature
);
2656 std::pair
<Signatures::iterator
, bool> ins(
2657 this->signatures_
.insert(std::make_pair(sig
, group
)));
2661 // This is the first time we've seen this signature.
2665 if (ins
.first
->second
)
2667 // We've already seen a real section group with this signature.
2672 // This is a real section group, and we've already seen a
2673 // linkonce section with this signature. Record that we've seen
2674 // a section group, and don't include this section group.
2675 ins
.first
->second
= true;
2680 // We've already seen a linkonce section and this is a linkonce
2681 // section. These don't block each other--this may be the same
2682 // symbol name with different section types.
2687 // Store the allocated sections into the section list.
2690 Layout::get_allocated_sections(Section_list
* section_list
) const
2692 for (Section_list::const_iterator p
= this->section_list_
.begin();
2693 p
!= this->section_list_
.end();
2695 if (((*p
)->flags() & elfcpp::SHF_ALLOC
) != 0)
2696 section_list
->push_back(*p
);
2699 // Create an output segment.
2702 Layout::make_output_segment(elfcpp::Elf_Word type
, elfcpp::Elf_Word flags
)
2704 gold_assert(!parameters
->options().relocatable());
2705 Output_segment
* oseg
= new Output_segment(type
, flags
);
2706 this->segment_list_
.push_back(oseg
);
2710 // Write out the Output_sections. Most won't have anything to write,
2711 // since most of the data will come from input sections which are
2712 // handled elsewhere. But some Output_sections do have Output_data.
2715 Layout::write_output_sections(Output_file
* of
) const
2717 for (Section_list::const_iterator p
= this->section_list_
.begin();
2718 p
!= this->section_list_
.end();
2721 if (!(*p
)->after_input_sections())
2726 // Write out data not associated with a section or the symbol table.
2729 Layout::write_data(const Symbol_table
* symtab
, Output_file
* of
) const
2731 if (!parameters
->options().strip_all())
2733 const Output_section
* symtab_section
= this->symtab_section_
;
2734 for (Section_list::const_iterator p
= this->section_list_
.begin();
2735 p
!= this->section_list_
.end();
2738 if ((*p
)->needs_symtab_index())
2740 gold_assert(symtab_section
!= NULL
);
2741 unsigned int index
= (*p
)->symtab_index();
2742 gold_assert(index
> 0 && index
!= -1U);
2743 off_t off
= (symtab_section
->offset()
2744 + index
* symtab_section
->entsize());
2745 symtab
->write_section_symbol(*p
, of
, off
);
2750 const Output_section
* dynsym_section
= this->dynsym_section_
;
2751 for (Section_list::const_iterator p
= this->section_list_
.begin();
2752 p
!= this->section_list_
.end();
2755 if ((*p
)->needs_dynsym_index())
2757 gold_assert(dynsym_section
!= NULL
);
2758 unsigned int index
= (*p
)->dynsym_index();
2759 gold_assert(index
> 0 && index
!= -1U);
2760 off_t off
= (dynsym_section
->offset()
2761 + index
* dynsym_section
->entsize());
2762 symtab
->write_section_symbol(*p
, of
, off
);
2766 // Write out the Output_data which are not in an Output_section.
2767 for (Data_list::const_iterator p
= this->special_output_list_
.begin();
2768 p
!= this->special_output_list_
.end();
2773 // Write out the Output_sections which can only be written after the
2774 // input sections are complete.
2777 Layout::write_sections_after_input_sections(Output_file
* of
)
2779 // Determine the final section offsets, and thus the final output
2780 // file size. Note we finalize the .shstrab last, to allow the
2781 // after_input_section sections to modify their section-names before
2783 if (this->any_postprocessing_sections_
)
2785 off_t off
= this->output_file_size_
;
2786 off
= this->set_section_offsets(off
, POSTPROCESSING_SECTIONS_PASS
);
2788 // Now that we've finalized the names, we can finalize the shstrab.
2790 this->set_section_offsets(off
,
2791 STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS
);
2793 if (off
> this->output_file_size_
)
2796 this->output_file_size_
= off
;
2800 for (Section_list::const_iterator p
= this->section_list_
.begin();
2801 p
!= this->section_list_
.end();
2804 if ((*p
)->after_input_sections())
2808 this->section_headers_
->write(of
);
2811 // If the build ID requires computing a checksum, do so here, and
2812 // write it out. We compute a checksum over the entire file because
2813 // that is simplest.
2816 Layout::write_build_id(Output_file
* of
) const
2818 if (this->build_id_note_
== NULL
)
2821 const unsigned char* iv
= of
->get_input_view(0, this->output_file_size_
);
2823 unsigned char* ov
= of
->get_output_view(this->build_id_note_
->offset(),
2824 this->build_id_note_
->data_size());
2826 const char* style
= parameters
->options().build_id();
2827 if (strcmp(style
, "sha1") == 0)
2830 sha1_init_ctx(&ctx
);
2831 sha1_process_bytes(iv
, this->output_file_size_
, &ctx
);
2832 sha1_finish_ctx(&ctx
, ov
);
2834 else if (strcmp(style
, "md5") == 0)
2838 md5_process_bytes(iv
, this->output_file_size_
, &ctx
);
2839 md5_finish_ctx(&ctx
, ov
);
2844 of
->write_output_view(this->build_id_note_
->offset(),
2845 this->build_id_note_
->data_size(),
2848 of
->free_input_view(0, this->output_file_size_
, iv
);
2851 // Write out a binary file. This is called after the link is
2852 // complete. IN is the temporary output file we used to generate the
2853 // ELF code. We simply walk through the segments, read them from
2854 // their file offset in IN, and write them to their load address in
2855 // the output file. FIXME: with a bit more work, we could support
2856 // S-records and/or Intel hex format here.
2859 Layout::write_binary(Output_file
* in
) const
2861 gold_assert(this->options_
.oformat_enum()
2862 == General_options::OBJECT_FORMAT_BINARY
);
2864 // Get the size of the binary file.
2865 uint64_t max_load_address
= 0;
2866 for (Segment_list::const_iterator p
= this->segment_list_
.begin();
2867 p
!= this->segment_list_
.end();
2870 if ((*p
)->type() == elfcpp::PT_LOAD
&& (*p
)->filesz() > 0)
2872 uint64_t max_paddr
= (*p
)->paddr() + (*p
)->filesz();
2873 if (max_paddr
> max_load_address
)
2874 max_load_address
= max_paddr
;
2878 Output_file
out(parameters
->options().output_file_name());
2879 out
.open(max_load_address
);
2881 for (Segment_list::const_iterator p
= this->segment_list_
.begin();
2882 p
!= this->segment_list_
.end();
2885 if ((*p
)->type() == elfcpp::PT_LOAD
&& (*p
)->filesz() > 0)
2887 const unsigned char* vin
= in
->get_input_view((*p
)->offset(),
2889 unsigned char* vout
= out
.get_output_view((*p
)->paddr(),
2891 memcpy(vout
, vin
, (*p
)->filesz());
2892 out
.write_output_view((*p
)->paddr(), (*p
)->filesz(), vout
);
2893 in
->free_input_view((*p
)->offset(), (*p
)->filesz(), vin
);
2900 // Print statistical information to stderr. This is used for --stats.
2903 Layout::print_stats() const
2905 this->namepool_
.print_stats("section name pool");
2906 this->sympool_
.print_stats("output symbol name pool");
2907 this->dynpool_
.print_stats("dynamic name pool");
2909 for (Section_list::const_iterator p
= this->section_list_
.begin();
2910 p
!= this->section_list_
.end();
2912 (*p
)->print_merge_stats();
2915 // Write_sections_task methods.
2917 // We can always run this task.
2920 Write_sections_task::is_runnable()
2925 // We need to unlock both OUTPUT_SECTIONS_BLOCKER and FINAL_BLOCKER
2929 Write_sections_task::locks(Task_locker
* tl
)
2931 tl
->add(this, this->output_sections_blocker_
);
2932 tl
->add(this, this->final_blocker_
);
2935 // Run the task--write out the data.
2938 Write_sections_task::run(Workqueue
*)
2940 this->layout_
->write_output_sections(this->of_
);
2943 // Write_data_task methods.
2945 // We can always run this task.
2948 Write_data_task::is_runnable()
2953 // We need to unlock FINAL_BLOCKER when finished.
2956 Write_data_task::locks(Task_locker
* tl
)
2958 tl
->add(this, this->final_blocker_
);
2961 // Run the task--write out the data.
2964 Write_data_task::run(Workqueue
*)
2966 this->layout_
->write_data(this->symtab_
, this->of_
);
2969 // Write_symbols_task methods.
2971 // We can always run this task.
2974 Write_symbols_task::is_runnable()
2979 // We need to unlock FINAL_BLOCKER when finished.
2982 Write_symbols_task::locks(Task_locker
* tl
)
2984 tl
->add(this, this->final_blocker_
);
2987 // Run the task--write out the symbols.
2990 Write_symbols_task::run(Workqueue
*)
2992 this->symtab_
->write_globals(this->input_objects_
, this->sympool_
,
2993 this->dynpool_
, this->of_
);
2996 // Write_after_input_sections_task methods.
2998 // We can only run this task after the input sections have completed.
3001 Write_after_input_sections_task::is_runnable()
3003 if (this->input_sections_blocker_
->is_blocked())
3004 return this->input_sections_blocker_
;
3008 // We need to unlock FINAL_BLOCKER when finished.
3011 Write_after_input_sections_task::locks(Task_locker
* tl
)
3013 tl
->add(this, this->final_blocker_
);
3019 Write_after_input_sections_task::run(Workqueue
*)
3021 this->layout_
->write_sections_after_input_sections(this->of_
);
3024 // Close_task_runner methods.
3026 // Run the task--close the file.
3029 Close_task_runner::run(Workqueue
*, const Task
*)
3031 // If we need to compute a checksum for the BUILD if, we do so here.
3032 this->layout_
->write_build_id(this->of_
);
3034 // If we've been asked to create a binary file, we do so here.
3035 if (this->options_
->oformat_enum() != General_options::OBJECT_FORMAT_ELF
)
3036 this->layout_
->write_binary(this->of_
);
3041 // Instantiate the templates we need. We could use the configure
3042 // script to restrict this to only the ones for implemented targets.
3044 #ifdef HAVE_TARGET_32_LITTLE
3047 Layout::layout
<32, false>(Sized_relobj
<32, false>* object
, unsigned int shndx
,
3049 const elfcpp::Shdr
<32, false>& shdr
,
3050 unsigned int, unsigned int, off_t
*);
3053 #ifdef HAVE_TARGET_32_BIG
3056 Layout::layout
<32, true>(Sized_relobj
<32, true>* object
, unsigned int shndx
,
3058 const elfcpp::Shdr
<32, true>& shdr
,
3059 unsigned int, unsigned int, off_t
*);
3062 #ifdef HAVE_TARGET_64_LITTLE
3065 Layout::layout
<64, false>(Sized_relobj
<64, false>* object
, unsigned int shndx
,
3067 const elfcpp::Shdr
<64, false>& shdr
,
3068 unsigned int, unsigned int, off_t
*);
3071 #ifdef HAVE_TARGET_64_BIG
3074 Layout::layout
<64, true>(Sized_relobj
<64, true>* object
, unsigned int shndx
,
3076 const elfcpp::Shdr
<64, true>& shdr
,
3077 unsigned int, unsigned int, off_t
*);
3080 #ifdef HAVE_TARGET_32_LITTLE
3083 Layout::layout_reloc
<32, false>(Sized_relobj
<32, false>* object
,
3084 unsigned int reloc_shndx
,
3085 const elfcpp::Shdr
<32, false>& shdr
,
3086 Output_section
* data_section
,
3087 Relocatable_relocs
* rr
);
3090 #ifdef HAVE_TARGET_32_BIG
3093 Layout::layout_reloc
<32, true>(Sized_relobj
<32, true>* object
,
3094 unsigned int reloc_shndx
,
3095 const elfcpp::Shdr
<32, true>& shdr
,
3096 Output_section
* data_section
,
3097 Relocatable_relocs
* rr
);
3100 #ifdef HAVE_TARGET_64_LITTLE
3103 Layout::layout_reloc
<64, false>(Sized_relobj
<64, false>* object
,
3104 unsigned int reloc_shndx
,
3105 const elfcpp::Shdr
<64, false>& shdr
,
3106 Output_section
* data_section
,
3107 Relocatable_relocs
* rr
);
3110 #ifdef HAVE_TARGET_64_BIG
3113 Layout::layout_reloc
<64, true>(Sized_relobj
<64, true>* object
,
3114 unsigned int reloc_shndx
,
3115 const elfcpp::Shdr
<64, true>& shdr
,
3116 Output_section
* data_section
,
3117 Relocatable_relocs
* rr
);
3120 #ifdef HAVE_TARGET_32_LITTLE
3123 Layout::layout_group
<32, false>(Symbol_table
* symtab
,
3124 Sized_relobj
<32, false>* object
,
3126 const char* group_section_name
,
3127 const char* signature
,
3128 const elfcpp::Shdr
<32, false>& shdr
,
3129 const elfcpp::Elf_Word
* contents
);
3132 #ifdef HAVE_TARGET_32_BIG
3135 Layout::layout_group
<32, true>(Symbol_table
* symtab
,
3136 Sized_relobj
<32, true>* object
,
3138 const char* group_section_name
,
3139 const char* signature
,
3140 const elfcpp::Shdr
<32, true>& shdr
,
3141 const elfcpp::Elf_Word
* contents
);
3144 #ifdef HAVE_TARGET_64_LITTLE
3147 Layout::layout_group
<64, false>(Symbol_table
* symtab
,
3148 Sized_relobj
<64, false>* object
,
3150 const char* group_section_name
,
3151 const char* signature
,
3152 const elfcpp::Shdr
<64, false>& shdr
,
3153 const elfcpp::Elf_Word
* contents
);
3156 #ifdef HAVE_TARGET_64_BIG
3159 Layout::layout_group
<64, true>(Symbol_table
* symtab
,
3160 Sized_relobj
<64, true>* object
,
3162 const char* group_section_name
,
3163 const char* signature
,
3164 const elfcpp::Shdr
<64, true>& shdr
,
3165 const elfcpp::Elf_Word
* contents
);
3168 #ifdef HAVE_TARGET_32_LITTLE
3171 Layout::layout_eh_frame
<32, false>(Sized_relobj
<32, false>* object
,
3172 const unsigned char* symbols
,
3174 const unsigned char* symbol_names
,
3175 off_t symbol_names_size
,
3177 const elfcpp::Shdr
<32, false>& shdr
,
3178 unsigned int reloc_shndx
,
3179 unsigned int reloc_type
,
3183 #ifdef HAVE_TARGET_32_BIG
3186 Layout::layout_eh_frame
<32, true>(Sized_relobj
<32, true>* object
,
3187 const unsigned char* symbols
,
3189 const unsigned char* symbol_names
,
3190 off_t symbol_names_size
,
3192 const elfcpp::Shdr
<32, true>& shdr
,
3193 unsigned int reloc_shndx
,
3194 unsigned int reloc_type
,
3198 #ifdef HAVE_TARGET_64_LITTLE
3201 Layout::layout_eh_frame
<64, false>(Sized_relobj
<64, false>* object
,
3202 const unsigned char* symbols
,
3204 const unsigned char* symbol_names
,
3205 off_t symbol_names_size
,
3207 const elfcpp::Shdr
<64, false>& shdr
,
3208 unsigned int reloc_shndx
,
3209 unsigned int reloc_type
,
3213 #ifdef HAVE_TARGET_64_BIG
3216 Layout::layout_eh_frame
<64, true>(Sized_relobj
<64, true>* object
,
3217 const unsigned char* symbols
,
3219 const unsigned char* symbol_names
,
3220 off_t symbol_names_size
,
3222 const elfcpp::Shdr
<64, true>& shdr
,
3223 unsigned int reloc_shndx
,
3224 unsigned int reloc_type
,
3228 } // End namespace gold.