1 // object.cc -- support for an object file for linking in gold
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 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.
29 #include "libiberty.h"
32 #include "target-select.h"
33 #include "dwarf_reader.h"
42 #include "compressed_output.h"
43 #include "incremental.h"
48 // Struct Read_symbols_data.
50 // Destroy any remaining File_view objects.
52 Read_symbols_data::~Read_symbols_data()
54 if (this->section_headers
!= NULL
)
55 delete this->section_headers
;
56 if (this->section_names
!= NULL
)
57 delete this->section_names
;
58 if (this->symbols
!= NULL
)
60 if (this->symbol_names
!= NULL
)
61 delete this->symbol_names
;
62 if (this->versym
!= NULL
)
64 if (this->verdef
!= NULL
)
66 if (this->verneed
!= NULL
)
72 // Initialize the symtab_xindex_ array. Find the SHT_SYMTAB_SHNDX
73 // section and read it in. SYMTAB_SHNDX is the index of the symbol
74 // table we care about.
76 template<int size
, bool big_endian
>
78 Xindex::initialize_symtab_xindex(Object
* object
, unsigned int symtab_shndx
)
80 if (!this->symtab_xindex_
.empty())
83 gold_assert(symtab_shndx
!= 0);
85 // Look through the sections in reverse order, on the theory that it
86 // is more likely to be near the end than the beginning.
87 unsigned int i
= object
->shnum();
91 if (object
->section_type(i
) == elfcpp::SHT_SYMTAB_SHNDX
92 && this->adjust_shndx(object
->section_link(i
)) == symtab_shndx
)
94 this->read_symtab_xindex
<size
, big_endian
>(object
, i
, NULL
);
99 object
->error(_("missing SHT_SYMTAB_SHNDX section"));
102 // Read in the symtab_xindex_ array, given the section index of the
103 // SHT_SYMTAB_SHNDX section. If PSHDRS is not NULL, it points at the
106 template<int size
, bool big_endian
>
108 Xindex::read_symtab_xindex(Object
* object
, unsigned int xindex_shndx
,
109 const unsigned char* pshdrs
)
111 section_size_type bytecount
;
112 const unsigned char* contents
;
114 contents
= object
->section_contents(xindex_shndx
, &bytecount
, false);
117 const unsigned char* p
= (pshdrs
119 * elfcpp::Elf_sizes
<size
>::shdr_size
));
120 typename
elfcpp::Shdr
<size
, big_endian
> shdr(p
);
121 bytecount
= convert_to_section_size_type(shdr
.get_sh_size());
122 contents
= object
->get_view(shdr
.get_sh_offset(), bytecount
, true, false);
125 gold_assert(this->symtab_xindex_
.empty());
126 this->symtab_xindex_
.reserve(bytecount
/ 4);
127 for (section_size_type i
= 0; i
< bytecount
; i
+= 4)
129 unsigned int shndx
= elfcpp::Swap
<32, big_endian
>::readval(contents
+ i
);
130 // We preadjust the section indexes we save.
131 this->symtab_xindex_
.push_back(this->adjust_shndx(shndx
));
135 // Symbol symndx has a section of SHN_XINDEX; return the real section
139 Xindex::sym_xindex_to_shndx(Object
* object
, unsigned int symndx
)
141 if (symndx
>= this->symtab_xindex_
.size())
143 object
->error(_("symbol %u out of range for SHT_SYMTAB_SHNDX section"),
145 return elfcpp::SHN_UNDEF
;
147 unsigned int shndx
= this->symtab_xindex_
[symndx
];
148 if (shndx
< elfcpp::SHN_LORESERVE
|| shndx
>= object
->shnum())
150 object
->error(_("extended index for symbol %u out of range: %u"),
152 return elfcpp::SHN_UNDEF
;
159 // Report an error for this object file. This is used by the
160 // elfcpp::Elf_file interface, and also called by the Object code
164 Object::error(const char* format
, ...) const
167 va_start(args
, format
);
169 if (vasprintf(&buf
, format
, args
) < 0)
172 gold_error(_("%s: %s"), this->name().c_str(), buf
);
176 // Return a view of the contents of a section.
179 Object::section_contents(unsigned int shndx
, section_size_type
* plen
,
181 { return this->do_section_contents(shndx
, plen
, cache
); }
183 // Read the section data into SD. This is code common to Sized_relobj_file
184 // and Sized_dynobj, so we put it into Object.
186 template<int size
, bool big_endian
>
188 Object::read_section_data(elfcpp::Elf_file
<size
, big_endian
, Object
>* elf_file
,
189 Read_symbols_data
* sd
)
191 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
193 // Read the section headers.
194 const off_t shoff
= elf_file
->shoff();
195 const unsigned int shnum
= this->shnum();
196 sd
->section_headers
= this->get_lasting_view(shoff
, shnum
* shdr_size
,
199 // Read the section names.
200 const unsigned char* pshdrs
= sd
->section_headers
->data();
201 const unsigned char* pshdrnames
= pshdrs
+ elf_file
->shstrndx() * shdr_size
;
202 typename
elfcpp::Shdr
<size
, big_endian
> shdrnames(pshdrnames
);
204 if (shdrnames
.get_sh_type() != elfcpp::SHT_STRTAB
)
205 this->error(_("section name section has wrong type: %u"),
206 static_cast<unsigned int>(shdrnames
.get_sh_type()));
208 sd
->section_names_size
=
209 convert_to_section_size_type(shdrnames
.get_sh_size());
210 sd
->section_names
= this->get_lasting_view(shdrnames
.get_sh_offset(),
211 sd
->section_names_size
, false,
215 // If NAME is the name of a special .gnu.warning section, arrange for
216 // the warning to be issued. SHNDX is the section index. Return
217 // whether it is a warning section.
220 Object::handle_gnu_warning_section(const char* name
, unsigned int shndx
,
221 Symbol_table
* symtab
)
223 const char warn_prefix
[] = ".gnu.warning.";
224 const int warn_prefix_len
= sizeof warn_prefix
- 1;
225 if (strncmp(name
, warn_prefix
, warn_prefix_len
) == 0)
227 // Read the section contents to get the warning text. It would
228 // be nicer if we only did this if we have to actually issue a
229 // warning. Unfortunately, warnings are issued as we relocate
230 // sections. That means that we can not lock the object then,
231 // as we might try to issue the same warning multiple times
233 section_size_type len
;
234 const unsigned char* contents
= this->section_contents(shndx
, &len
,
238 const char* warning
= name
+ warn_prefix_len
;
239 contents
= reinterpret_cast<const unsigned char*>(warning
);
240 len
= strlen(warning
);
242 std::string
warning(reinterpret_cast<const char*>(contents
), len
);
243 symtab
->add_warning(name
+ warn_prefix_len
, this, warning
);
249 // If NAME is the name of the special section which indicates that
250 // this object was compiled with -fsplit-stack, mark it accordingly.
253 Object::handle_split_stack_section(const char* name
)
255 if (strcmp(name
, ".note.GNU-split-stack") == 0)
257 this->uses_split_stack_
= true;
260 if (strcmp(name
, ".note.GNU-no-split-stack") == 0)
262 this->has_no_split_stack_
= true;
270 // To copy the symbols data read from the file to a local data structure.
271 // This function is called from do_layout only while doing garbage
275 Relobj::copy_symbols_data(Symbols_data
* gc_sd
, Read_symbols_data
* sd
,
276 unsigned int section_header_size
)
278 gc_sd
->section_headers_data
=
279 new unsigned char[(section_header_size
)];
280 memcpy(gc_sd
->section_headers_data
, sd
->section_headers
->data(),
281 section_header_size
);
282 gc_sd
->section_names_data
=
283 new unsigned char[sd
->section_names_size
];
284 memcpy(gc_sd
->section_names_data
, sd
->section_names
->data(),
285 sd
->section_names_size
);
286 gc_sd
->section_names_size
= sd
->section_names_size
;
287 if (sd
->symbols
!= NULL
)
289 gc_sd
->symbols_data
=
290 new unsigned char[sd
->symbols_size
];
291 memcpy(gc_sd
->symbols_data
, sd
->symbols
->data(),
296 gc_sd
->symbols_data
= NULL
;
298 gc_sd
->symbols_size
= sd
->symbols_size
;
299 gc_sd
->external_symbols_offset
= sd
->external_symbols_offset
;
300 if (sd
->symbol_names
!= NULL
)
302 gc_sd
->symbol_names_data
=
303 new unsigned char[sd
->symbol_names_size
];
304 memcpy(gc_sd
->symbol_names_data
, sd
->symbol_names
->data(),
305 sd
->symbol_names_size
);
309 gc_sd
->symbol_names_data
= NULL
;
311 gc_sd
->symbol_names_size
= sd
->symbol_names_size
;
314 // This function determines if a particular section name must be included
315 // in the link. This is used during garbage collection to determine the
316 // roots of the worklist.
319 Relobj::is_section_name_included(const char* name
)
321 if (is_prefix_of(".ctors", name
)
322 || is_prefix_of(".dtors", name
)
323 || is_prefix_of(".note", name
)
324 || is_prefix_of(".init", name
)
325 || is_prefix_of(".fini", name
)
326 || is_prefix_of(".gcc_except_table", name
)
327 || is_prefix_of(".jcr", name
)
328 || is_prefix_of(".preinit_array", name
)
329 || (is_prefix_of(".text", name
)
330 && strstr(name
, "personality"))
331 || (is_prefix_of(".data", name
)
332 && strstr(name
, "personality"))
333 || (is_prefix_of(".gnu.linkonce.d", name
)
334 && strstr(name
, "personality")))
341 // Finalize the incremental relocation information. Allocates a block
342 // of relocation entries for each symbol, and sets the reloc_bases_
343 // array to point to the first entry in each block. If CLEAR_COUNTS
344 // is TRUE, also clear the per-symbol relocation counters.
347 Relobj::finalize_incremental_relocs(Layout
* layout
, bool clear_counts
)
349 unsigned int nsyms
= this->get_global_symbols()->size();
350 this->reloc_bases_
= new unsigned int[nsyms
];
352 gold_assert(this->reloc_bases_
!= NULL
);
353 gold_assert(layout
->incremental_inputs() != NULL
);
355 unsigned int rindex
= layout
->incremental_inputs()->get_reloc_count();
356 for (unsigned int i
= 0; i
< nsyms
; ++i
)
358 this->reloc_bases_
[i
] = rindex
;
359 rindex
+= this->reloc_counts_
[i
];
361 this->reloc_counts_
[i
] = 0;
363 layout
->incremental_inputs()->set_reloc_count(rindex
);
366 // Class Sized_relobj.
368 // Iterate over local symbols, calling a visitor class V for each GOT offset
369 // associated with a local symbol.
371 template<int size
, bool big_endian
>
373 Sized_relobj
<size
, big_endian
>::do_for_all_local_got_entries(
374 Got_offset_list::Visitor
* v
) const
376 unsigned int nsyms
= this->local_symbol_count();
377 for (unsigned int i
= 0; i
< nsyms
; i
++)
379 Local_got_offsets::const_iterator p
= this->local_got_offsets_
.find(i
);
380 if (p
!= this->local_got_offsets_
.end())
382 const Got_offset_list
* got_offsets
= p
->second
;
383 got_offsets
->for_all_got_offsets(v
);
388 // Class Sized_relobj_file.
390 template<int size
, bool big_endian
>
391 Sized_relobj_file
<size
, big_endian
>::Sized_relobj_file(
392 const std::string
& name
,
393 Input_file
* input_file
,
395 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
396 : Sized_relobj
<size
, big_endian
>(name
, input_file
, offset
),
397 elf_file_(this, ehdr
),
399 local_symbol_count_(0),
400 output_local_symbol_count_(0),
401 output_local_dynsym_count_(0),
404 local_symbol_offset_(0),
405 local_dynsym_offset_(0),
407 local_plt_offsets_(),
408 kept_comdat_sections_(),
409 has_eh_frame_(false),
410 discarded_eh_frame_shndx_(-1U),
412 deferred_layout_relocs_(),
413 compressed_sections_()
415 this->e_type_
= ehdr
.get_e_type();
418 template<int size
, bool big_endian
>
419 Sized_relobj_file
<size
, big_endian
>::~Sized_relobj_file()
423 // Set up an object file based on the file header. This sets up the
424 // section information.
426 template<int size
, bool big_endian
>
428 Sized_relobj_file
<size
, big_endian
>::do_setup()
430 const unsigned int shnum
= this->elf_file_
.shnum();
431 this->set_shnum(shnum
);
434 // Find the SHT_SYMTAB section, given the section headers. The ELF
435 // standard says that maybe in the future there can be more than one
436 // SHT_SYMTAB section. Until somebody figures out how that could
437 // work, we assume there is only one.
439 template<int size
, bool big_endian
>
441 Sized_relobj_file
<size
, big_endian
>::find_symtab(const unsigned char* pshdrs
)
443 const unsigned int shnum
= this->shnum();
444 this->symtab_shndx_
= 0;
447 // Look through the sections in reverse order, since gas tends
448 // to put the symbol table at the end.
449 const unsigned char* p
= pshdrs
+ shnum
* This::shdr_size
;
450 unsigned int i
= shnum
;
451 unsigned int xindex_shndx
= 0;
452 unsigned int xindex_link
= 0;
456 p
-= This::shdr_size
;
457 typename
This::Shdr
shdr(p
);
458 if (shdr
.get_sh_type() == elfcpp::SHT_SYMTAB
)
460 this->symtab_shndx_
= i
;
461 if (xindex_shndx
> 0 && xindex_link
== i
)
464 new Xindex(this->elf_file_
.large_shndx_offset());
465 xindex
->read_symtab_xindex
<size
, big_endian
>(this,
468 this->set_xindex(xindex
);
473 // Try to pick up the SHT_SYMTAB_SHNDX section, if there is
474 // one. This will work if it follows the SHT_SYMTAB
476 if (shdr
.get_sh_type() == elfcpp::SHT_SYMTAB_SHNDX
)
479 xindex_link
= this->adjust_shndx(shdr
.get_sh_link());
485 // Return the Xindex structure to use for object with lots of
488 template<int size
, bool big_endian
>
490 Sized_relobj_file
<size
, big_endian
>::do_initialize_xindex()
492 gold_assert(this->symtab_shndx_
!= -1U);
493 Xindex
* xindex
= new Xindex(this->elf_file_
.large_shndx_offset());
494 xindex
->initialize_symtab_xindex
<size
, big_endian
>(this, this->symtab_shndx_
);
498 // Return whether SHDR has the right type and flags to be a GNU
499 // .eh_frame section.
501 template<int size
, bool big_endian
>
503 Sized_relobj_file
<size
, big_endian
>::check_eh_frame_flags(
504 const elfcpp::Shdr
<size
, big_endian
>* shdr
) const
506 elfcpp::Elf_Word sh_type
= shdr
->get_sh_type();
507 return ((sh_type
== elfcpp::SHT_PROGBITS
508 || sh_type
== elfcpp::SHT_X86_64_UNWIND
)
509 && (shdr
->get_sh_flags() & elfcpp::SHF_ALLOC
) != 0);
512 // Return whether there is a GNU .eh_frame section, given the section
513 // headers and the section names.
515 template<int size
, bool big_endian
>
517 Sized_relobj_file
<size
, big_endian
>::find_eh_frame(
518 const unsigned char* pshdrs
,
520 section_size_type names_size
) const
522 const unsigned int shnum
= this->shnum();
523 const unsigned char* p
= pshdrs
+ This::shdr_size
;
524 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= This::shdr_size
)
526 typename
This::Shdr
shdr(p
);
527 if (this->check_eh_frame_flags(&shdr
))
529 if (shdr
.get_sh_name() >= names_size
)
531 this->error(_("bad section name offset for section %u: %lu"),
532 i
, static_cast<unsigned long>(shdr
.get_sh_name()));
536 const char* name
= names
+ shdr
.get_sh_name();
537 if (strcmp(name
, ".eh_frame") == 0)
544 // Return TRUE if this is a section whose contents will be needed in the
545 // Add_symbols task. This function is only called for sections that have
546 // already passed the test in is_compressed_debug_section(), so we know
547 // that the section name begins with ".zdebug".
550 need_decompressed_section(const char* name
)
552 // Skip over the ".zdebug" and a quick check for the "_".
557 #ifdef ENABLE_THREADS
558 // Decompressing these sections now will help only if we're
560 if (parameters
->options().threads())
562 // We will need .zdebug_str if this is not an incremental link
563 // (i.e., we are processing string merge sections) or if we need
564 // to build a gdb index.
565 if ((!parameters
->incremental() || parameters
->options().gdb_index())
566 && strcmp(name
, "str") == 0)
569 // We will need these other sections when building a gdb index.
570 if (parameters
->options().gdb_index()
571 && (strcmp(name
, "info") == 0
572 || strcmp(name
, "types") == 0
573 || strcmp(name
, "pubnames") == 0
574 || strcmp(name
, "pubtypes") == 0
575 || strcmp(name
, "ranges") == 0
576 || strcmp(name
, "abbrev") == 0))
581 // Even when single-threaded, we will need .zdebug_str if this is
582 // not an incremental link and we are building a gdb index.
583 // Otherwise, we would decompress the section twice: once for
584 // string merge processing, and once for building the gdb index.
585 if (!parameters
->incremental()
586 && parameters
->options().gdb_index()
587 && strcmp(name
, "str") == 0)
593 // Build a table for any compressed debug sections, mapping each section index
594 // to the uncompressed size and (if needed) the decompressed contents.
596 template<int size
, bool big_endian
>
597 Compressed_section_map
*
598 build_compressed_section_map(
599 const unsigned char* pshdrs
,
602 section_size_type names_size
,
603 Sized_relobj_file
<size
, big_endian
>* obj
)
605 Compressed_section_map
* uncompressed_map
= new Compressed_section_map();
606 const unsigned int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
607 const unsigned char* p
= pshdrs
+ shdr_size
;
609 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= shdr_size
)
611 typename
elfcpp::Shdr
<size
, big_endian
> shdr(p
);
612 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
613 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) == 0)
615 if (shdr
.get_sh_name() >= names_size
)
617 obj
->error(_("bad section name offset for section %u: %lu"),
618 i
, static_cast<unsigned long>(shdr
.get_sh_name()));
622 const char* name
= names
+ shdr
.get_sh_name();
623 if (is_compressed_debug_section(name
))
625 section_size_type len
;
626 const unsigned char* contents
=
627 obj
->section_contents(i
, &len
, false);
628 uint64_t uncompressed_size
= get_uncompressed_size(contents
, len
);
629 Compressed_section_info info
;
630 info
.size
= convert_to_section_size_type(uncompressed_size
);
631 info
.contents
= NULL
;
632 if (uncompressed_size
!= -1ULL)
634 unsigned char* uncompressed_data
= NULL
;
635 if (need_decompressed_section(name
))
637 uncompressed_data
= new unsigned char[uncompressed_size
];
638 if (decompress_input_section(contents
, len
,
641 info
.contents
= uncompressed_data
;
643 delete[] uncompressed_data
;
645 (*uncompressed_map
)[i
] = info
;
650 return uncompressed_map
;
653 // Read the sections and symbols from an object file.
655 template<int size
, bool big_endian
>
657 Sized_relobj_file
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
659 bool need_local_symbols
= false;
661 this->read_section_data(&this->elf_file_
, sd
);
663 const unsigned char* const pshdrs
= sd
->section_headers
->data();
665 this->find_symtab(pshdrs
);
667 const unsigned char* namesu
= sd
->section_names
->data();
668 const char* names
= reinterpret_cast<const char*>(namesu
);
669 if (memmem(names
, sd
->section_names_size
, ".eh_frame", 10) != NULL
)
671 if (this->find_eh_frame(pshdrs
, names
, sd
->section_names_size
))
672 this->has_eh_frame_
= true;
674 if (memmem(names
, sd
->section_names_size
, ".zdebug_", 8) != NULL
)
675 this->compressed_sections_
=
676 build_compressed_section_map(pshdrs
, this->shnum(), names
,
677 sd
->section_names_size
, this);
679 if (this->has_eh_frame_
680 || (!parameters
->options().relocatable()
681 && parameters
->options().gdb_index()
682 && (memmem(names
, sd
->section_names_size
, "debug_info", 12) == 0
683 || memmem(names
, sd
->section_names_size
, "debug_types",
685 need_local_symbols
= true;
688 sd
->symbols_size
= 0;
689 sd
->external_symbols_offset
= 0;
690 sd
->symbol_names
= NULL
;
691 sd
->symbol_names_size
= 0;
693 if (this->symtab_shndx_
== 0)
695 // No symbol table. Weird but legal.
699 // Get the symbol table section header.
700 typename
This::Shdr
symtabshdr(pshdrs
701 + this->symtab_shndx_
* This::shdr_size
);
702 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
704 // If this object has a .eh_frame section, or if building a .gdb_index
705 // section and there is debug info, we need all the symbols.
706 // Otherwise we only need the external symbols. While it would be
707 // simpler to just always read all the symbols, I've seen object
708 // files with well over 2000 local symbols, which for a 64-bit
709 // object file format is over 5 pages that we don't need to read
712 const int sym_size
= This::sym_size
;
713 const unsigned int loccount
= symtabshdr
.get_sh_info();
714 this->local_symbol_count_
= loccount
;
715 this->local_values_
.resize(loccount
);
716 section_offset_type locsize
= loccount
* sym_size
;
717 off_t dataoff
= symtabshdr
.get_sh_offset();
718 section_size_type datasize
=
719 convert_to_section_size_type(symtabshdr
.get_sh_size());
720 off_t extoff
= dataoff
+ locsize
;
721 section_size_type extsize
= datasize
- locsize
;
723 off_t readoff
= need_local_symbols
? dataoff
: extoff
;
724 section_size_type readsize
= need_local_symbols
? datasize
: extsize
;
728 // No external symbols. Also weird but also legal.
732 File_view
* fvsymtab
= this->get_lasting_view(readoff
, readsize
, true, false);
734 // Read the section header for the symbol names.
735 unsigned int strtab_shndx
= this->adjust_shndx(symtabshdr
.get_sh_link());
736 if (strtab_shndx
>= this->shnum())
738 this->error(_("invalid symbol table name index: %u"), strtab_shndx
);
741 typename
This::Shdr
strtabshdr(pshdrs
+ strtab_shndx
* This::shdr_size
);
742 if (strtabshdr
.get_sh_type() != elfcpp::SHT_STRTAB
)
744 this->error(_("symbol table name section has wrong type: %u"),
745 static_cast<unsigned int>(strtabshdr
.get_sh_type()));
749 // Read the symbol names.
750 File_view
* fvstrtab
= this->get_lasting_view(strtabshdr
.get_sh_offset(),
751 strtabshdr
.get_sh_size(),
754 sd
->symbols
= fvsymtab
;
755 sd
->symbols_size
= readsize
;
756 sd
->external_symbols_offset
= need_local_symbols
? locsize
: 0;
757 sd
->symbol_names
= fvstrtab
;
758 sd
->symbol_names_size
=
759 convert_to_section_size_type(strtabshdr
.get_sh_size());
762 // Return the section index of symbol SYM. Set *VALUE to its value in
763 // the object file. Set *IS_ORDINARY if this is an ordinary section
764 // index, not a special code between SHN_LORESERVE and SHN_HIRESERVE.
765 // Note that for a symbol which is not defined in this object file,
766 // this will set *VALUE to 0 and return SHN_UNDEF; it will not return
767 // the final value of the symbol in the link.
769 template<int size
, bool big_endian
>
771 Sized_relobj_file
<size
, big_endian
>::symbol_section_and_value(unsigned int sym
,
775 section_size_type symbols_size
;
776 const unsigned char* symbols
= this->section_contents(this->symtab_shndx_
,
780 const size_t count
= symbols_size
/ This::sym_size
;
781 gold_assert(sym
< count
);
783 elfcpp::Sym
<size
, big_endian
> elfsym(symbols
+ sym
* This::sym_size
);
784 *value
= elfsym
.get_st_value();
786 return this->adjust_sym_shndx(sym
, elfsym
.get_st_shndx(), is_ordinary
);
789 // Return whether to include a section group in the link. LAYOUT is
790 // used to keep track of which section groups we have already seen.
791 // INDEX is the index of the section group and SHDR is the section
792 // header. If we do not want to include this group, we set bits in
793 // OMIT for each section which should be discarded.
795 template<int size
, bool big_endian
>
797 Sized_relobj_file
<size
, big_endian
>::include_section_group(
798 Symbol_table
* symtab
,
802 const unsigned char* shdrs
,
803 const char* section_names
,
804 section_size_type section_names_size
,
805 std::vector
<bool>* omit
)
807 // Read the section contents.
808 typename
This::Shdr
shdr(shdrs
+ index
* This::shdr_size
);
809 const unsigned char* pcon
= this->get_view(shdr
.get_sh_offset(),
810 shdr
.get_sh_size(), true, false);
811 const elfcpp::Elf_Word
* pword
=
812 reinterpret_cast<const elfcpp::Elf_Word
*>(pcon
);
814 // The first word contains flags. We only care about COMDAT section
815 // groups. Other section groups are always included in the link
816 // just like ordinary sections.
817 elfcpp::Elf_Word flags
= elfcpp::Swap
<32, big_endian
>::readval(pword
);
819 // Look up the group signature, which is the name of a symbol. ELF
820 // uses a symbol name because some group signatures are long, and
821 // the name is generally already in the symbol table, so it makes
822 // sense to put the long string just once in .strtab rather than in
823 // both .strtab and .shstrtab.
825 // Get the appropriate symbol table header (this will normally be
826 // the single SHT_SYMTAB section, but in principle it need not be).
827 const unsigned int link
= this->adjust_shndx(shdr
.get_sh_link());
828 typename
This::Shdr
symshdr(this, this->elf_file_
.section_header(link
));
830 // Read the symbol table entry.
831 unsigned int symndx
= shdr
.get_sh_info();
832 if (symndx
>= symshdr
.get_sh_size() / This::sym_size
)
834 this->error(_("section group %u info %u out of range"),
838 off_t symoff
= symshdr
.get_sh_offset() + symndx
* This::sym_size
;
839 const unsigned char* psym
= this->get_view(symoff
, This::sym_size
, true,
841 elfcpp::Sym
<size
, big_endian
> sym(psym
);
843 // Read the symbol table names.
844 section_size_type symnamelen
;
845 const unsigned char* psymnamesu
;
846 psymnamesu
= this->section_contents(this->adjust_shndx(symshdr
.get_sh_link()),
848 const char* psymnames
= reinterpret_cast<const char*>(psymnamesu
);
850 // Get the section group signature.
851 if (sym
.get_st_name() >= symnamelen
)
853 this->error(_("symbol %u name offset %u out of range"),
854 symndx
, sym
.get_st_name());
858 std::string
signature(psymnames
+ sym
.get_st_name());
860 // It seems that some versions of gas will create a section group
861 // associated with a section symbol, and then fail to give a name to
862 // the section symbol. In such a case, use the name of the section.
863 if (signature
[0] == '\0' && sym
.get_st_type() == elfcpp::STT_SECTION
)
866 unsigned int sym_shndx
= this->adjust_sym_shndx(symndx
,
869 if (!is_ordinary
|| sym_shndx
>= this->shnum())
871 this->error(_("symbol %u invalid section index %u"),
875 typename
This::Shdr
member_shdr(shdrs
+ sym_shndx
* This::shdr_size
);
876 if (member_shdr
.get_sh_name() < section_names_size
)
877 signature
= section_names
+ member_shdr
.get_sh_name();
880 // Record this section group in the layout, and see whether we've already
881 // seen one with the same signature.
884 Kept_section
* kept_section
= NULL
;
886 if ((flags
& elfcpp::GRP_COMDAT
) == 0)
888 include_group
= true;
893 include_group
= layout
->find_or_add_kept_section(signature
,
895 true, &kept_section
);
899 if (is_comdat
&& include_group
)
901 Incremental_inputs
* incremental_inputs
= layout
->incremental_inputs();
902 if (incremental_inputs
!= NULL
)
903 incremental_inputs
->report_comdat_group(this, signature
.c_str());
906 size_t count
= shdr
.get_sh_size() / sizeof(elfcpp::Elf_Word
);
908 std::vector
<unsigned int> shndxes
;
909 bool relocate_group
= include_group
&& parameters
->options().relocatable();
911 shndxes
.reserve(count
- 1);
913 for (size_t i
= 1; i
< count
; ++i
)
915 elfcpp::Elf_Word shndx
=
916 this->adjust_shndx(elfcpp::Swap
<32, big_endian
>::readval(pword
+ i
));
919 shndxes
.push_back(shndx
);
921 if (shndx
>= this->shnum())
923 this->error(_("section %u in section group %u out of range"),
928 // Check for an earlier section number, since we're going to get
929 // it wrong--we may have already decided to include the section.
931 this->error(_("invalid section group %u refers to earlier section %u"),
934 // Get the name of the member section.
935 typename
This::Shdr
member_shdr(shdrs
+ shndx
* This::shdr_size
);
936 if (member_shdr
.get_sh_name() >= section_names_size
)
938 // This is an error, but it will be diagnosed eventually
939 // in do_layout, so we don't need to do anything here but
943 std::string
mname(section_names
+ member_shdr
.get_sh_name());
948 kept_section
->add_comdat_section(mname
, shndx
,
949 member_shdr
.get_sh_size());
953 (*omit
)[shndx
] = true;
957 Relobj
* kept_object
= kept_section
->object();
958 if (kept_section
->is_comdat())
960 // Find the corresponding kept section, and store
961 // that info in the discarded section table.
962 unsigned int kept_shndx
;
964 if (kept_section
->find_comdat_section(mname
, &kept_shndx
,
967 // We don't keep a mapping for this section if
968 // it has a different size. The mapping is only
969 // used for relocation processing, and we don't
970 // want to treat the sections as similar if the
971 // sizes are different. Checking the section
972 // size is the approach used by the GNU linker.
973 if (kept_size
== member_shdr
.get_sh_size())
974 this->set_kept_comdat_section(shndx
, kept_object
,
980 // The existing section is a linkonce section. Add
981 // a mapping if there is exactly one section in the
982 // group (which is true when COUNT == 2) and if it
985 && (kept_section
->linkonce_size()
986 == member_shdr
.get_sh_size()))
987 this->set_kept_comdat_section(shndx
, kept_object
,
988 kept_section
->shndx());
995 layout
->layout_group(symtab
, this, index
, name
, signature
.c_str(),
996 shdr
, flags
, &shndxes
);
998 return include_group
;
1001 // Whether to include a linkonce section in the link. NAME is the
1002 // name of the section and SHDR is the section header.
1004 // Linkonce sections are a GNU extension implemented in the original
1005 // GNU linker before section groups were defined. The semantics are
1006 // that we only include one linkonce section with a given name. The
1007 // name of a linkonce section is normally .gnu.linkonce.T.SYMNAME,
1008 // where T is the type of section and SYMNAME is the name of a symbol.
1009 // In an attempt to make linkonce sections interact well with section
1010 // groups, we try to identify SYMNAME and use it like a section group
1011 // signature. We want to block section groups with that signature,
1012 // but not other linkonce sections with that signature. We also use
1013 // the full name of the linkonce section as a normal section group
1016 template<int size
, bool big_endian
>
1018 Sized_relobj_file
<size
, big_endian
>::include_linkonce_section(
1022 const elfcpp::Shdr
<size
, big_endian
>& shdr
)
1024 typename
elfcpp::Elf_types
<size
>::Elf_WXword sh_size
= shdr
.get_sh_size();
1025 // In general the symbol name we want will be the string following
1026 // the last '.'. However, we have to handle the case of
1027 // .gnu.linkonce.t.__i686.get_pc_thunk.bx, which was generated by
1028 // some versions of gcc. So we use a heuristic: if the name starts
1029 // with ".gnu.linkonce.t.", we use everything after that. Otherwise
1030 // we look for the last '.'. We can't always simply skip
1031 // ".gnu.linkonce.X", because we have to deal with cases like
1032 // ".gnu.linkonce.d.rel.ro.local".
1033 const char* const linkonce_t
= ".gnu.linkonce.t.";
1034 const char* symname
;
1035 if (strncmp(name
, linkonce_t
, strlen(linkonce_t
)) == 0)
1036 symname
= name
+ strlen(linkonce_t
);
1038 symname
= strrchr(name
, '.') + 1;
1039 std::string
sig1(symname
);
1040 std::string
sig2(name
);
1041 Kept_section
* kept1
;
1042 Kept_section
* kept2
;
1043 bool include1
= layout
->find_or_add_kept_section(sig1
, this, index
, false,
1045 bool include2
= layout
->find_or_add_kept_section(sig2
, this, index
, false,
1050 // We are not including this section because we already saw the
1051 // name of the section as a signature. This normally implies
1052 // that the kept section is another linkonce section. If it is
1053 // the same size, record it as the section which corresponds to
1055 if (kept2
->object() != NULL
1056 && !kept2
->is_comdat()
1057 && kept2
->linkonce_size() == sh_size
)
1058 this->set_kept_comdat_section(index
, kept2
->object(), kept2
->shndx());
1062 // The section is being discarded on the basis of its symbol
1063 // name. This means that the corresponding kept section was
1064 // part of a comdat group, and it will be difficult to identify
1065 // the specific section within that group that corresponds to
1066 // this linkonce section. We'll handle the simple case where
1067 // the group has only one member section. Otherwise, it's not
1068 // worth the effort.
1069 unsigned int kept_shndx
;
1071 if (kept1
->object() != NULL
1072 && kept1
->is_comdat()
1073 && kept1
->find_single_comdat_section(&kept_shndx
, &kept_size
)
1074 && kept_size
== sh_size
)
1075 this->set_kept_comdat_section(index
, kept1
->object(), kept_shndx
);
1079 kept1
->set_linkonce_size(sh_size
);
1080 kept2
->set_linkonce_size(sh_size
);
1083 return include1
&& include2
;
1086 // Layout an input section.
1088 template<int size
, bool big_endian
>
1090 Sized_relobj_file
<size
, big_endian
>::layout_section(
1094 const typename
This::Shdr
& shdr
,
1095 unsigned int reloc_shndx
,
1096 unsigned int reloc_type
)
1099 Output_section
* os
= layout
->layout(this, shndx
, name
, shdr
,
1100 reloc_shndx
, reloc_type
, &offset
);
1102 this->output_sections()[shndx
] = os
;
1104 this->section_offsets()[shndx
] = invalid_address
;
1106 this->section_offsets()[shndx
] = convert_types
<Address
, off_t
>(offset
);
1108 // If this section requires special handling, and if there are
1109 // relocs that apply to it, then we must do the special handling
1110 // before we apply the relocs.
1111 if (offset
== -1 && reloc_shndx
!= 0)
1112 this->set_relocs_must_follow_section_writes();
1115 // Layout an input .eh_frame section.
1117 template<int size
, bool big_endian
>
1119 Sized_relobj_file
<size
, big_endian
>::layout_eh_frame_section(
1121 const unsigned char* symbols_data
,
1122 section_size_type symbols_size
,
1123 const unsigned char* symbol_names_data
,
1124 section_size_type symbol_names_size
,
1126 const typename
This::Shdr
& shdr
,
1127 unsigned int reloc_shndx
,
1128 unsigned int reloc_type
)
1130 gold_assert(this->has_eh_frame_
);
1133 Output_section
* os
= layout
->layout_eh_frame(this,
1143 this->output_sections()[shndx
] = os
;
1144 if (os
== NULL
|| offset
== -1)
1146 // An object can contain at most one section holding exception
1147 // frame information.
1148 gold_assert(this->discarded_eh_frame_shndx_
== -1U);
1149 this->discarded_eh_frame_shndx_
= shndx
;
1150 this->section_offsets()[shndx
] = invalid_address
;
1153 this->section_offsets()[shndx
] = convert_types
<Address
, off_t
>(offset
);
1155 // If this section requires special handling, and if there are
1156 // relocs that aply to it, then we must do the special handling
1157 // before we apply the relocs.
1158 if (os
!= NULL
&& offset
== -1 && reloc_shndx
!= 0)
1159 this->set_relocs_must_follow_section_writes();
1162 // Lay out the input sections. We walk through the sections and check
1163 // whether they should be included in the link. If they should, we
1164 // pass them to the Layout object, which will return an output section
1166 // During garbage collection (--gc-sections) and identical code folding
1167 // (--icf), this function is called twice. When it is called the first
1168 // time, it is for setting up some sections as roots to a work-list for
1169 // --gc-sections and to do comdat processing. Actual layout happens the
1170 // second time around after all the relevant sections have been determined.
1171 // The first time, is_worklist_ready or is_icf_ready is false. It is then
1172 // set to true after the garbage collection worklist or identical code
1173 // folding is processed and the relevant sections to be kept are
1174 // determined. Then, this function is called again to layout the sections.
1176 template<int size
, bool big_endian
>
1178 Sized_relobj_file
<size
, big_endian
>::do_layout(Symbol_table
* symtab
,
1180 Read_symbols_data
* sd
)
1182 const unsigned int shnum
= this->shnum();
1183 bool is_gc_pass_one
= ((parameters
->options().gc_sections()
1184 && !symtab
->gc()->is_worklist_ready())
1185 || (parameters
->options().icf_enabled()
1186 && !symtab
->icf()->is_icf_ready()));
1188 bool is_gc_pass_two
= ((parameters
->options().gc_sections()
1189 && symtab
->gc()->is_worklist_ready())
1190 || (parameters
->options().icf_enabled()
1191 && symtab
->icf()->is_icf_ready()));
1193 bool is_gc_or_icf
= (parameters
->options().gc_sections()
1194 || parameters
->options().icf_enabled());
1196 // Both is_gc_pass_one and is_gc_pass_two should not be true.
1197 gold_assert(!(is_gc_pass_one
&& is_gc_pass_two
));
1201 Symbols_data
* gc_sd
= NULL
;
1204 // During garbage collection save the symbols data to use it when
1205 // re-entering this function.
1206 gc_sd
= new Symbols_data
;
1207 this->copy_symbols_data(gc_sd
, sd
, This::shdr_size
* shnum
);
1208 this->set_symbols_data(gc_sd
);
1210 else if (is_gc_pass_two
)
1212 gc_sd
= this->get_symbols_data();
1215 const unsigned char* section_headers_data
= NULL
;
1216 section_size_type section_names_size
;
1217 const unsigned char* symbols_data
= NULL
;
1218 section_size_type symbols_size
;
1219 const unsigned char* symbol_names_data
= NULL
;
1220 section_size_type symbol_names_size
;
1224 section_headers_data
= gc_sd
->section_headers_data
;
1225 section_names_size
= gc_sd
->section_names_size
;
1226 symbols_data
= gc_sd
->symbols_data
;
1227 symbols_size
= gc_sd
->symbols_size
;
1228 symbol_names_data
= gc_sd
->symbol_names_data
;
1229 symbol_names_size
= gc_sd
->symbol_names_size
;
1233 section_headers_data
= sd
->section_headers
->data();
1234 section_names_size
= sd
->section_names_size
;
1235 if (sd
->symbols
!= NULL
)
1236 symbols_data
= sd
->symbols
->data();
1237 symbols_size
= sd
->symbols_size
;
1238 if (sd
->symbol_names
!= NULL
)
1239 symbol_names_data
= sd
->symbol_names
->data();
1240 symbol_names_size
= sd
->symbol_names_size
;
1243 // Get the section headers.
1244 const unsigned char* shdrs
= section_headers_data
;
1245 const unsigned char* pshdrs
;
1247 // Get the section names.
1248 const unsigned char* pnamesu
= (is_gc_or_icf
)
1249 ? gc_sd
->section_names_data
1250 : sd
->section_names
->data();
1252 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
1254 // If any input files have been claimed by plugins, we need to defer
1255 // actual layout until the replacement files have arrived.
1256 const bool should_defer_layout
=
1257 (parameters
->options().has_plugins()
1258 && parameters
->options().plugins()->should_defer_layout());
1259 unsigned int num_sections_to_defer
= 0;
1261 // For each section, record the index of the reloc section if any.
1262 // Use 0 to mean that there is no reloc section, -1U to mean that
1263 // there is more than one.
1264 std::vector
<unsigned int> reloc_shndx(shnum
, 0);
1265 std::vector
<unsigned int> reloc_type(shnum
, elfcpp::SHT_NULL
);
1266 // Skip the first, dummy, section.
1267 pshdrs
= shdrs
+ This::shdr_size
;
1268 for (unsigned int i
= 1; i
< shnum
; ++i
, pshdrs
+= This::shdr_size
)
1270 typename
This::Shdr
shdr(pshdrs
);
1272 // Count the number of sections whose layout will be deferred.
1273 if (should_defer_layout
&& (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
))
1274 ++num_sections_to_defer
;
1276 unsigned int sh_type
= shdr
.get_sh_type();
1277 if (sh_type
== elfcpp::SHT_REL
|| sh_type
== elfcpp::SHT_RELA
)
1279 unsigned int target_shndx
= this->adjust_shndx(shdr
.get_sh_info());
1280 if (target_shndx
== 0 || target_shndx
>= shnum
)
1282 this->error(_("relocation section %u has bad info %u"),
1287 if (reloc_shndx
[target_shndx
] != 0)
1288 reloc_shndx
[target_shndx
] = -1U;
1291 reloc_shndx
[target_shndx
] = i
;
1292 reloc_type
[target_shndx
] = sh_type
;
1297 Output_sections
& out_sections(this->output_sections());
1298 std::vector
<Address
>& out_section_offsets(this->section_offsets());
1300 if (!is_gc_pass_two
)
1302 out_sections
.resize(shnum
);
1303 out_section_offsets
.resize(shnum
);
1306 // If we are only linking for symbols, then there is nothing else to
1308 if (this->input_file()->just_symbols())
1310 if (!is_gc_pass_two
)
1312 delete sd
->section_headers
;
1313 sd
->section_headers
= NULL
;
1314 delete sd
->section_names
;
1315 sd
->section_names
= NULL
;
1320 if (num_sections_to_defer
> 0)
1322 parameters
->options().plugins()->add_deferred_layout_object(this);
1323 this->deferred_layout_
.reserve(num_sections_to_defer
);
1326 // Whether we've seen a .note.GNU-stack section.
1327 bool seen_gnu_stack
= false;
1328 // The flags of a .note.GNU-stack section.
1329 uint64_t gnu_stack_flags
= 0;
1331 // Keep track of which sections to omit.
1332 std::vector
<bool> omit(shnum
, false);
1334 // Keep track of reloc sections when emitting relocations.
1335 const bool relocatable
= parameters
->options().relocatable();
1336 const bool emit_relocs
= (relocatable
1337 || parameters
->options().emit_relocs());
1338 std::vector
<unsigned int> reloc_sections
;
1340 // Keep track of .eh_frame sections.
1341 std::vector
<unsigned int> eh_frame_sections
;
1343 // Keep track of .debug_info and .debug_types sections.
1344 std::vector
<unsigned int> debug_info_sections
;
1345 std::vector
<unsigned int> debug_types_sections
;
1347 // Skip the first, dummy, section.
1348 pshdrs
= shdrs
+ This::shdr_size
;
1349 for (unsigned int i
= 1; i
< shnum
; ++i
, pshdrs
+= This::shdr_size
)
1351 typename
This::Shdr
shdr(pshdrs
);
1353 if (shdr
.get_sh_name() >= section_names_size
)
1355 this->error(_("bad section name offset for section %u: %lu"),
1356 i
, static_cast<unsigned long>(shdr
.get_sh_name()));
1360 const char* name
= pnames
+ shdr
.get_sh_name();
1362 if (!is_gc_pass_two
)
1364 if (this->handle_gnu_warning_section(name
, i
, symtab
))
1366 if (!relocatable
&& !parameters
->options().shared())
1370 // The .note.GNU-stack section is special. It gives the
1371 // protection flags that this object file requires for the stack
1373 if (strcmp(name
, ".note.GNU-stack") == 0)
1375 seen_gnu_stack
= true;
1376 gnu_stack_flags
|= shdr
.get_sh_flags();
1380 // The .note.GNU-split-stack section is also special. It
1381 // indicates that the object was compiled with
1383 if (this->handle_split_stack_section(name
))
1385 if (!relocatable
&& !parameters
->options().shared())
1389 // Skip attributes section.
1390 if (parameters
->target().is_attributes_section(name
))
1395 bool discard
= omit
[i
];
1398 if (shdr
.get_sh_type() == elfcpp::SHT_GROUP
)
1400 if (!this->include_section_group(symtab
, layout
, i
, name
,
1406 else if ((shdr
.get_sh_flags() & elfcpp::SHF_GROUP
) == 0
1407 && Layout::is_linkonce(name
))
1409 if (!this->include_linkonce_section(layout
, i
, name
, shdr
))
1414 // Add the section to the incremental inputs layout.
1415 Incremental_inputs
* incremental_inputs
= layout
->incremental_inputs();
1416 if (incremental_inputs
!= NULL
1418 && can_incremental_update(shdr
.get_sh_type()))
1420 off_t sh_size
= shdr
.get_sh_size();
1421 section_size_type uncompressed_size
;
1422 if (this->section_is_compressed(i
, &uncompressed_size
))
1423 sh_size
= uncompressed_size
;
1424 incremental_inputs
->report_input_section(this, i
, name
, sh_size
);
1429 // Do not include this section in the link.
1430 out_sections
[i
] = NULL
;
1431 out_section_offsets
[i
] = invalid_address
;
1436 if (is_gc_pass_one
&& parameters
->options().gc_sections())
1438 if (this->is_section_name_included(name
)
1439 || shdr
.get_sh_type() == elfcpp::SHT_INIT_ARRAY
1440 || shdr
.get_sh_type() == elfcpp::SHT_FINI_ARRAY
)
1442 symtab
->gc()->worklist().push(Section_id(this, i
));
1444 // If the section name XXX can be represented as a C identifier
1445 // it cannot be discarded if there are references to
1446 // __start_XXX and __stop_XXX symbols. These need to be
1447 // specially handled.
1448 if (is_cident(name
))
1450 symtab
->gc()->add_cident_section(name
, Section_id(this, i
));
1454 // When doing a relocatable link we are going to copy input
1455 // reloc sections into the output. We only want to copy the
1456 // ones associated with sections which are not being discarded.
1457 // However, we don't know that yet for all sections. So save
1458 // reloc sections and process them later. Garbage collection is
1459 // not triggered when relocatable code is desired.
1461 && (shdr
.get_sh_type() == elfcpp::SHT_REL
1462 || shdr
.get_sh_type() == elfcpp::SHT_RELA
))
1464 reloc_sections
.push_back(i
);
1468 if (relocatable
&& shdr
.get_sh_type() == elfcpp::SHT_GROUP
)
1471 // The .eh_frame section is special. It holds exception frame
1472 // information that we need to read in order to generate the
1473 // exception frame header. We process these after all the other
1474 // sections so that the exception frame reader can reliably
1475 // determine which sections are being discarded, and discard the
1476 // corresponding information.
1478 && strcmp(name
, ".eh_frame") == 0
1479 && this->check_eh_frame_flags(&shdr
))
1483 out_sections
[i
] = reinterpret_cast<Output_section
*>(1);
1484 out_section_offsets
[i
] = invalid_address
;
1486 else if (should_defer_layout
)
1487 this->deferred_layout_
.push_back(Deferred_layout(i
, name
,
1492 eh_frame_sections
.push_back(i
);
1496 if (is_gc_pass_two
&& parameters
->options().gc_sections())
1498 // This is executed during the second pass of garbage
1499 // collection. do_layout has been called before and some
1500 // sections have been already discarded. Simply ignore
1501 // such sections this time around.
1502 if (out_sections
[i
] == NULL
)
1504 gold_assert(out_section_offsets
[i
] == invalid_address
);
1507 if (((shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
1508 && symtab
->gc()->is_section_garbage(this, i
))
1510 if (parameters
->options().print_gc_sections())
1511 gold_info(_("%s: removing unused section from '%s'"
1513 program_name
, this->section_name(i
).c_str(),
1514 this->name().c_str());
1515 out_sections
[i
] = NULL
;
1516 out_section_offsets
[i
] = invalid_address
;
1521 if (is_gc_pass_two
&& parameters
->options().icf_enabled())
1523 if (out_sections
[i
] == NULL
)
1525 gold_assert(out_section_offsets
[i
] == invalid_address
);
1528 if (((shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
1529 && symtab
->icf()->is_section_folded(this, i
))
1531 if (parameters
->options().print_icf_sections())
1534 symtab
->icf()->get_folded_section(this, i
);
1535 Relobj
* folded_obj
=
1536 reinterpret_cast<Relobj
*>(folded
.first
);
1537 gold_info(_("%s: ICF folding section '%s' in file '%s'"
1538 "into '%s' in file '%s'"),
1539 program_name
, this->section_name(i
).c_str(),
1540 this->name().c_str(),
1541 folded_obj
->section_name(folded
.second
).c_str(),
1542 folded_obj
->name().c_str());
1544 out_sections
[i
] = NULL
;
1545 out_section_offsets
[i
] = invalid_address
;
1550 // Defer layout here if input files are claimed by plugins. When gc
1551 // is turned on this function is called twice. For the second call
1552 // should_defer_layout should be false.
1553 if (should_defer_layout
&& (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
))
1555 gold_assert(!is_gc_pass_two
);
1556 this->deferred_layout_
.push_back(Deferred_layout(i
, name
,
1560 // Put dummy values here; real values will be supplied by
1561 // do_layout_deferred_sections.
1562 out_sections
[i
] = reinterpret_cast<Output_section
*>(2);
1563 out_section_offsets
[i
] = invalid_address
;
1567 // During gc_pass_two if a section that was previously deferred is
1568 // found, do not layout the section as layout_deferred_sections will
1569 // do it later from gold.cc.
1571 && (out_sections
[i
] == reinterpret_cast<Output_section
*>(2)))
1576 // This is during garbage collection. The out_sections are
1577 // assigned in the second call to this function.
1578 out_sections
[i
] = reinterpret_cast<Output_section
*>(1);
1579 out_section_offsets
[i
] = invalid_address
;
1583 // When garbage collection is switched on the actual layout
1584 // only happens in the second call.
1585 this->layout_section(layout
, i
, name
, shdr
, reloc_shndx
[i
],
1588 // When generating a .gdb_index section, we do additional
1589 // processing of .debug_info and .debug_types sections after all
1590 // the other sections for the same reason as above.
1592 && parameters
->options().gdb_index()
1593 && !(shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
))
1595 if (strcmp(name
, ".debug_info") == 0
1596 || strcmp(name
, ".zdebug_info") == 0)
1597 debug_info_sections
.push_back(i
);
1598 else if (strcmp(name
, ".debug_types") == 0
1599 || strcmp(name
, ".zdebug_types") == 0)
1600 debug_types_sections
.push_back(i
);
1605 if (!is_gc_pass_two
)
1606 layout
->layout_gnu_stack(seen_gnu_stack
, gnu_stack_flags
, this);
1608 // When doing a relocatable link handle the reloc sections at the
1609 // end. Garbage collection and Identical Code Folding is not
1610 // turned on for relocatable code.
1612 this->size_relocatable_relocs();
1614 gold_assert(!(is_gc_or_icf
) || reloc_sections
.empty());
1616 for (std::vector
<unsigned int>::const_iterator p
= reloc_sections
.begin();
1617 p
!= reloc_sections
.end();
1620 unsigned int i
= *p
;
1621 const unsigned char* pshdr
;
1622 pshdr
= section_headers_data
+ i
* This::shdr_size
;
1623 typename
This::Shdr
shdr(pshdr
);
1625 unsigned int data_shndx
= this->adjust_shndx(shdr
.get_sh_info());
1626 if (data_shndx
>= shnum
)
1628 // We already warned about this above.
1632 Output_section
* data_section
= out_sections
[data_shndx
];
1633 if (data_section
== reinterpret_cast<Output_section
*>(2))
1635 // The layout for the data section was deferred, so we need
1636 // to defer the relocation section, too.
1637 const char* name
= pnames
+ shdr
.get_sh_name();
1638 this->deferred_layout_relocs_
.push_back(
1639 Deferred_layout(i
, name
, pshdr
, 0, elfcpp::SHT_NULL
));
1640 out_sections
[i
] = reinterpret_cast<Output_section
*>(2);
1641 out_section_offsets
[i
] = invalid_address
;
1644 if (data_section
== NULL
)
1646 out_sections
[i
] = NULL
;
1647 out_section_offsets
[i
] = invalid_address
;
1651 Relocatable_relocs
* rr
= new Relocatable_relocs();
1652 this->set_relocatable_relocs(i
, rr
);
1654 Output_section
* os
= layout
->layout_reloc(this, i
, shdr
, data_section
,
1656 out_sections
[i
] = os
;
1657 out_section_offsets
[i
] = invalid_address
;
1660 // Handle the .eh_frame sections at the end.
1661 gold_assert(!is_gc_pass_one
|| eh_frame_sections
.empty());
1662 for (std::vector
<unsigned int>::const_iterator p
= eh_frame_sections
.begin();
1663 p
!= eh_frame_sections
.end();
1666 unsigned int i
= *p
;
1667 const unsigned char* pshdr
;
1668 pshdr
= section_headers_data
+ i
* This::shdr_size
;
1669 typename
This::Shdr
shdr(pshdr
);
1671 this->layout_eh_frame_section(layout
,
1682 // When building a .gdb_index section, scan the .debug_info and
1683 // .debug_types sections.
1684 gold_assert(!is_gc_pass_one
1685 || (debug_info_sections
.empty() && debug_types_sections
.empty()));
1686 for (std::vector
<unsigned int>::const_iterator p
1687 = debug_info_sections
.begin();
1688 p
!= debug_info_sections
.end();
1691 unsigned int i
= *p
;
1692 layout
->add_to_gdb_index(false, this, symbols_data
, symbols_size
,
1693 i
, reloc_shndx
[i
], reloc_type
[i
]);
1695 for (std::vector
<unsigned int>::const_iterator p
1696 = debug_types_sections
.begin();
1697 p
!= debug_types_sections
.end();
1700 unsigned int i
= *p
;
1701 layout
->add_to_gdb_index(true, this, symbols_data
, symbols_size
,
1702 i
, reloc_shndx
[i
], reloc_type
[i
]);
1707 delete[] gc_sd
->section_headers_data
;
1708 delete[] gc_sd
->section_names_data
;
1709 delete[] gc_sd
->symbols_data
;
1710 delete[] gc_sd
->symbol_names_data
;
1711 this->set_symbols_data(NULL
);
1715 delete sd
->section_headers
;
1716 sd
->section_headers
= NULL
;
1717 delete sd
->section_names
;
1718 sd
->section_names
= NULL
;
1722 // Layout sections whose layout was deferred while waiting for
1723 // input files from a plugin.
1725 template<int size
, bool big_endian
>
1727 Sized_relobj_file
<size
, big_endian
>::do_layout_deferred_sections(Layout
* layout
)
1729 typename
std::vector
<Deferred_layout
>::iterator deferred
;
1731 for (deferred
= this->deferred_layout_
.begin();
1732 deferred
!= this->deferred_layout_
.end();
1735 typename
This::Shdr
shdr(deferred
->shdr_data_
);
1736 // If the section is not included, it is because the garbage collector
1737 // decided it is not needed. Avoid reverting that decision.
1738 if (!this->is_section_included(deferred
->shndx_
))
1741 if (parameters
->options().relocatable()
1742 || deferred
->name_
!= ".eh_frame"
1743 || !this->check_eh_frame_flags(&shdr
))
1744 this->layout_section(layout
, deferred
->shndx_
, deferred
->name_
.c_str(),
1745 shdr
, deferred
->reloc_shndx_
,
1746 deferred
->reloc_type_
);
1749 // Reading the symbols again here may be slow.
1750 Read_symbols_data sd
;
1751 this->read_symbols(&sd
);
1752 this->layout_eh_frame_section(layout
,
1755 sd
.symbol_names
->data(),
1756 sd
.symbol_names_size
,
1759 deferred
->reloc_shndx_
,
1760 deferred
->reloc_type_
);
1764 this->deferred_layout_
.clear();
1766 // Now handle the deferred relocation sections.
1768 Output_sections
& out_sections(this->output_sections());
1769 std::vector
<Address
>& out_section_offsets(this->section_offsets());
1771 for (deferred
= this->deferred_layout_relocs_
.begin();
1772 deferred
!= this->deferred_layout_relocs_
.end();
1775 unsigned int shndx
= deferred
->shndx_
;
1776 typename
This::Shdr
shdr(deferred
->shdr_data_
);
1777 unsigned int data_shndx
= this->adjust_shndx(shdr
.get_sh_info());
1779 Output_section
* data_section
= out_sections
[data_shndx
];
1780 if (data_section
== NULL
)
1782 out_sections
[shndx
] = NULL
;
1783 out_section_offsets
[shndx
] = invalid_address
;
1787 Relocatable_relocs
* rr
= new Relocatable_relocs();
1788 this->set_relocatable_relocs(shndx
, rr
);
1790 Output_section
* os
= layout
->layout_reloc(this, shndx
, shdr
,
1792 out_sections
[shndx
] = os
;
1793 out_section_offsets
[shndx
] = invalid_address
;
1797 // Add the symbols to the symbol table.
1799 template<int size
, bool big_endian
>
1801 Sized_relobj_file
<size
, big_endian
>::do_add_symbols(Symbol_table
* symtab
,
1802 Read_symbols_data
* sd
,
1805 if (sd
->symbols
== NULL
)
1807 gold_assert(sd
->symbol_names
== NULL
);
1811 const int sym_size
= This::sym_size
;
1812 size_t symcount
= ((sd
->symbols_size
- sd
->external_symbols_offset
)
1814 if (symcount
* sym_size
!= sd
->symbols_size
- sd
->external_symbols_offset
)
1816 this->error(_("size of symbols is not multiple of symbol size"));
1820 this->symbols_
.resize(symcount
);
1822 const char* sym_names
=
1823 reinterpret_cast<const char*>(sd
->symbol_names
->data());
1824 symtab
->add_from_relobj(this,
1825 sd
->symbols
->data() + sd
->external_symbols_offset
,
1826 symcount
, this->local_symbol_count_
,
1827 sym_names
, sd
->symbol_names_size
,
1829 &this->defined_count_
);
1833 delete sd
->symbol_names
;
1834 sd
->symbol_names
= NULL
;
1837 // Find out if this object, that is a member of a lib group, should be included
1838 // in the link. We check every symbol defined by this object. If the symbol
1839 // table has a strong undefined reference to that symbol, we have to include
1842 template<int size
, bool big_endian
>
1843 Archive::Should_include
1844 Sized_relobj_file
<size
, big_endian
>::do_should_include_member(
1845 Symbol_table
* symtab
,
1847 Read_symbols_data
* sd
,
1850 char* tmpbuf
= NULL
;
1851 size_t tmpbuflen
= 0;
1852 const char* sym_names
=
1853 reinterpret_cast<const char*>(sd
->symbol_names
->data());
1854 const unsigned char* syms
=
1855 sd
->symbols
->data() + sd
->external_symbols_offset
;
1856 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1857 size_t symcount
= ((sd
->symbols_size
- sd
->external_symbols_offset
)
1860 const unsigned char* p
= syms
;
1862 for (size_t i
= 0; i
< symcount
; ++i
, p
+= sym_size
)
1864 elfcpp::Sym
<size
, big_endian
> sym(p
);
1865 unsigned int st_shndx
= sym
.get_st_shndx();
1866 if (st_shndx
== elfcpp::SHN_UNDEF
)
1869 unsigned int st_name
= sym
.get_st_name();
1870 const char* name
= sym_names
+ st_name
;
1872 Archive::Should_include t
= Archive::should_include_member(symtab
,
1878 if (t
== Archive::SHOULD_INCLUDE_YES
)
1887 return Archive::SHOULD_INCLUDE_UNKNOWN
;
1890 // Iterate over global defined symbols, calling a visitor class V for each.
1892 template<int size
, bool big_endian
>
1894 Sized_relobj_file
<size
, big_endian
>::do_for_all_global_symbols(
1895 Read_symbols_data
* sd
,
1896 Library_base::Symbol_visitor_base
* v
)
1898 const char* sym_names
=
1899 reinterpret_cast<const char*>(sd
->symbol_names
->data());
1900 const unsigned char* syms
=
1901 sd
->symbols
->data() + sd
->external_symbols_offset
;
1902 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1903 size_t symcount
= ((sd
->symbols_size
- sd
->external_symbols_offset
)
1905 const unsigned char* p
= syms
;
1907 for (size_t i
= 0; i
< symcount
; ++i
, p
+= sym_size
)
1909 elfcpp::Sym
<size
, big_endian
> sym(p
);
1910 if (sym
.get_st_shndx() != elfcpp::SHN_UNDEF
)
1911 v
->visit(sym_names
+ sym
.get_st_name());
1915 // Return whether the local symbol SYMNDX has a PLT offset.
1917 template<int size
, bool big_endian
>
1919 Sized_relobj_file
<size
, big_endian
>::local_has_plt_offset(
1920 unsigned int symndx
) const
1922 typename
Local_plt_offsets::const_iterator p
=
1923 this->local_plt_offsets_
.find(symndx
);
1924 return p
!= this->local_plt_offsets_
.end();
1927 // Get the PLT offset of a local symbol.
1929 template<int size
, bool big_endian
>
1931 Sized_relobj_file
<size
, big_endian
>::do_local_plt_offset(
1932 unsigned int symndx
) const
1934 typename
Local_plt_offsets::const_iterator p
=
1935 this->local_plt_offsets_
.find(symndx
);
1936 gold_assert(p
!= this->local_plt_offsets_
.end());
1940 // Set the PLT offset of a local symbol.
1942 template<int size
, bool big_endian
>
1944 Sized_relobj_file
<size
, big_endian
>::set_local_plt_offset(
1945 unsigned int symndx
, unsigned int plt_offset
)
1947 std::pair
<typename
Local_plt_offsets::iterator
, bool> ins
=
1948 this->local_plt_offsets_
.insert(std::make_pair(symndx
, plt_offset
));
1949 gold_assert(ins
.second
);
1952 // First pass over the local symbols. Here we add their names to
1953 // *POOL and *DYNPOOL, and we store the symbol value in
1954 // THIS->LOCAL_VALUES_. This function is always called from a
1955 // singleton thread. This is followed by a call to
1956 // finalize_local_symbols.
1958 template<int size
, bool big_endian
>
1960 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(Stringpool
* pool
,
1961 Stringpool
* dynpool
)
1963 gold_assert(this->symtab_shndx_
!= -1U);
1964 if (this->symtab_shndx_
== 0)
1966 // This object has no symbols. Weird but legal.
1970 // Read the symbol table section header.
1971 const unsigned int symtab_shndx
= this->symtab_shndx_
;
1972 typename
This::Shdr
symtabshdr(this,
1973 this->elf_file_
.section_header(symtab_shndx
));
1974 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
1976 // Read the local symbols.
1977 const int sym_size
= This::sym_size
;
1978 const unsigned int loccount
= this->local_symbol_count_
;
1979 gold_assert(loccount
== symtabshdr
.get_sh_info());
1980 off_t locsize
= loccount
* sym_size
;
1981 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
1982 locsize
, true, true);
1984 // Read the symbol names.
1985 const unsigned int strtab_shndx
=
1986 this->adjust_shndx(symtabshdr
.get_sh_link());
1987 section_size_type strtab_size
;
1988 const unsigned char* pnamesu
= this->section_contents(strtab_shndx
,
1991 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
1993 // Loop over the local symbols.
1995 const Output_sections
& out_sections(this->output_sections());
1996 unsigned int shnum
= this->shnum();
1997 unsigned int count
= 0;
1998 unsigned int dyncount
= 0;
1999 // Skip the first, dummy, symbol.
2001 bool strip_all
= parameters
->options().strip_all();
2002 bool discard_all
= parameters
->options().discard_all();
2003 bool discard_locals
= parameters
->options().discard_locals();
2004 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2006 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2008 Symbol_value
<size
>& lv(this->local_values_
[i
]);
2011 unsigned int shndx
= this->adjust_sym_shndx(i
, sym
.get_st_shndx(),
2013 lv
.set_input_shndx(shndx
, is_ordinary
);
2015 if (sym
.get_st_type() == elfcpp::STT_SECTION
)
2016 lv
.set_is_section_symbol();
2017 else if (sym
.get_st_type() == elfcpp::STT_TLS
)
2018 lv
.set_is_tls_symbol();
2019 else if (sym
.get_st_type() == elfcpp::STT_GNU_IFUNC
)
2020 lv
.set_is_ifunc_symbol();
2022 // Save the input symbol value for use in do_finalize_local_symbols().
2023 lv
.set_input_value(sym
.get_st_value());
2025 // Decide whether this symbol should go into the output file.
2027 if ((shndx
< shnum
&& out_sections
[shndx
] == NULL
)
2028 || shndx
== this->discarded_eh_frame_shndx_
)
2030 lv
.set_no_output_symtab_entry();
2031 gold_assert(!lv
.needs_output_dynsym_entry());
2035 if (sym
.get_st_type() == elfcpp::STT_SECTION
)
2037 lv
.set_no_output_symtab_entry();
2038 gold_assert(!lv
.needs_output_dynsym_entry());
2042 if (sym
.get_st_name() >= strtab_size
)
2044 this->error(_("local symbol %u section name out of range: %u >= %u"),
2045 i
, sym
.get_st_name(),
2046 static_cast<unsigned int>(strtab_size
));
2047 lv
.set_no_output_symtab_entry();
2051 const char* name
= pnames
+ sym
.get_st_name();
2053 // If needed, add the symbol to the dynamic symbol table string pool.
2054 if (lv
.needs_output_dynsym_entry())
2056 dynpool
->add(name
, true, NULL
);
2061 || (discard_all
&& lv
.may_be_discarded_from_output_symtab()))
2063 lv
.set_no_output_symtab_entry();
2067 // If --discard-locals option is used, discard all temporary local
2068 // symbols. These symbols start with system-specific local label
2069 // prefixes, typically .L for ELF system. We want to be compatible
2070 // with GNU ld so here we essentially use the same check in
2071 // bfd_is_local_label(). The code is different because we already
2074 // - the symbol is local and thus cannot have global or weak binding.
2075 // - the symbol is not a section symbol.
2076 // - the symbol has a name.
2078 // We do not discard a symbol if it needs a dynamic symbol entry.
2080 && sym
.get_st_type() != elfcpp::STT_FILE
2081 && !lv
.needs_output_dynsym_entry()
2082 && lv
.may_be_discarded_from_output_symtab()
2083 && parameters
->target().is_local_label_name(name
))
2085 lv
.set_no_output_symtab_entry();
2089 // Discard the local symbol if -retain_symbols_file is specified
2090 // and the local symbol is not in that file.
2091 if (!parameters
->options().should_retain_symbol(name
))
2093 lv
.set_no_output_symtab_entry();
2097 // Add the symbol to the symbol table string pool.
2098 pool
->add(name
, true, NULL
);
2102 this->output_local_symbol_count_
= count
;
2103 this->output_local_dynsym_count_
= dyncount
;
2106 // Compute the final value of a local symbol.
2108 template<int size
, bool big_endian
>
2109 typename Sized_relobj_file
<size
, big_endian
>::Compute_final_local_value_status
2110 Sized_relobj_file
<size
, big_endian
>::compute_final_local_value_internal(
2112 const Symbol_value
<size
>* lv_in
,
2113 Symbol_value
<size
>* lv_out
,
2115 const Output_sections
& out_sections
,
2116 const std::vector
<Address
>& out_offsets
,
2117 const Symbol_table
* symtab
)
2119 // We are going to overwrite *LV_OUT, if it has a merged symbol value,
2120 // we may have a memory leak.
2121 gold_assert(lv_out
->has_output_value());
2124 unsigned int shndx
= lv_in
->input_shndx(&is_ordinary
);
2126 // Set the output symbol value.
2130 if (shndx
== elfcpp::SHN_ABS
|| Symbol::is_common_shndx(shndx
))
2131 lv_out
->set_output_value(lv_in
->input_value());
2134 this->error(_("unknown section index %u for local symbol %u"),
2136 lv_out
->set_output_value(0);
2137 return This::CFLV_ERROR
;
2142 if (shndx
>= this->shnum())
2144 this->error(_("local symbol %u section index %u out of range"),
2146 lv_out
->set_output_value(0);
2147 return This::CFLV_ERROR
;
2150 Output_section
* os
= out_sections
[shndx
];
2151 Address secoffset
= out_offsets
[shndx
];
2152 if (symtab
->is_section_folded(this, shndx
))
2154 gold_assert(os
== NULL
&& secoffset
== invalid_address
);
2155 // Get the os of the section it is folded onto.
2156 Section_id folded
= symtab
->icf()->get_folded_section(this,
2158 gold_assert(folded
.first
!= NULL
);
2159 Sized_relobj_file
<size
, big_endian
>* folded_obj
= reinterpret_cast
2160 <Sized_relobj_file
<size
, big_endian
>*>(folded
.first
);
2161 os
= folded_obj
->output_section(folded
.second
);
2162 gold_assert(os
!= NULL
);
2163 secoffset
= folded_obj
->get_output_section_offset(folded
.second
);
2165 // This could be a relaxed input section.
2166 if (secoffset
== invalid_address
)
2168 const Output_relaxed_input_section
* relaxed_section
=
2169 os
->find_relaxed_input_section(folded_obj
, folded
.second
);
2170 gold_assert(relaxed_section
!= NULL
);
2171 secoffset
= relaxed_section
->address() - os
->address();
2177 // This local symbol belongs to a section we are discarding.
2178 // In some cases when applying relocations later, we will
2179 // attempt to match it to the corresponding kept section,
2180 // so we leave the input value unchanged here.
2181 return This::CFLV_DISCARDED
;
2183 else if (secoffset
== invalid_address
)
2187 // This is a SHF_MERGE section or one which otherwise
2188 // requires special handling.
2189 if (shndx
== this->discarded_eh_frame_shndx_
)
2191 // This local symbol belongs to a discarded .eh_frame
2192 // section. Just treat it like the case in which
2193 // os == NULL above.
2194 gold_assert(this->has_eh_frame_
);
2195 return This::CFLV_DISCARDED
;
2197 else if (!lv_in
->is_section_symbol())
2199 // This is not a section symbol. We can determine
2200 // the final value now.
2201 lv_out
->set_output_value(
2202 os
->output_address(this, shndx
, lv_in
->input_value()));
2204 else if (!os
->find_starting_output_address(this, shndx
, &start
))
2206 // This is a section symbol, but apparently not one in a
2207 // merged section. First check to see if this is a relaxed
2208 // input section. If so, use its address. Otherwise just
2209 // use the start of the output section. This happens with
2210 // relocatable links when the input object has section
2211 // symbols for arbitrary non-merge sections.
2212 const Output_section_data
* posd
=
2213 os
->find_relaxed_input_section(this, shndx
);
2216 Address relocatable_link_adjustment
=
2217 relocatable
? os
->address() : 0;
2218 lv_out
->set_output_value(posd
->address()
2219 - relocatable_link_adjustment
);
2222 lv_out
->set_output_value(os
->address());
2226 // We have to consider the addend to determine the
2227 // value to use in a relocation. START is the start
2228 // of this input section. If we are doing a relocatable
2229 // link, use offset from start output section instead of
2231 Address adjusted_start
=
2232 relocatable
? start
- os
->address() : start
;
2233 Merged_symbol_value
<size
>* msv
=
2234 new Merged_symbol_value
<size
>(lv_in
->input_value(),
2236 lv_out
->set_merged_symbol_value(msv
);
2239 else if (lv_in
->is_tls_symbol())
2240 lv_out
->set_output_value(os
->tls_offset()
2242 + lv_in
->input_value());
2244 lv_out
->set_output_value((relocatable
? 0 : os
->address())
2246 + lv_in
->input_value());
2248 return This::CFLV_OK
;
2251 // Compute final local symbol value. R_SYM is the index of a local
2252 // symbol in symbol table. LV points to a symbol value, which is
2253 // expected to hold the input value and to be over-written by the
2254 // final value. SYMTAB points to a symbol table. Some targets may want
2255 // to know would-be-finalized local symbol values in relaxation.
2256 // Hence we provide this method. Since this method updates *LV, a
2257 // callee should make a copy of the original local symbol value and
2258 // use the copy instead of modifying an object's local symbols before
2259 // everything is finalized. The caller should also free up any allocated
2260 // memory in the return value in *LV.
2261 template<int size
, bool big_endian
>
2262 typename Sized_relobj_file
<size
, big_endian
>::Compute_final_local_value_status
2263 Sized_relobj_file
<size
, big_endian
>::compute_final_local_value(
2265 const Symbol_value
<size
>* lv_in
,
2266 Symbol_value
<size
>* lv_out
,
2267 const Symbol_table
* symtab
)
2269 // This is just a wrapper of compute_final_local_value_internal.
2270 const bool relocatable
= parameters
->options().relocatable();
2271 const Output_sections
& out_sections(this->output_sections());
2272 const std::vector
<Address
>& out_offsets(this->section_offsets());
2273 return this->compute_final_local_value_internal(r_sym
, lv_in
, lv_out
,
2274 relocatable
, out_sections
,
2275 out_offsets
, symtab
);
2278 // Finalize the local symbols. Here we set the final value in
2279 // THIS->LOCAL_VALUES_ and set their output symbol table indexes.
2280 // This function is always called from a singleton thread. The actual
2281 // output of the local symbols will occur in a separate task.
2283 template<int size
, bool big_endian
>
2285 Sized_relobj_file
<size
, big_endian
>::do_finalize_local_symbols(
2288 Symbol_table
* symtab
)
2290 gold_assert(off
== static_cast<off_t
>(align_address(off
, size
>> 3)));
2292 const unsigned int loccount
= this->local_symbol_count_
;
2293 this->local_symbol_offset_
= off
;
2295 const bool relocatable
= parameters
->options().relocatable();
2296 const Output_sections
& out_sections(this->output_sections());
2297 const std::vector
<Address
>& out_offsets(this->section_offsets());
2299 for (unsigned int i
= 1; i
< loccount
; ++i
)
2301 Symbol_value
<size
>* lv
= &this->local_values_
[i
];
2303 Compute_final_local_value_status cflv_status
=
2304 this->compute_final_local_value_internal(i
, lv
, lv
, relocatable
,
2305 out_sections
, out_offsets
,
2307 switch (cflv_status
)
2310 if (!lv
->is_output_symtab_index_set())
2312 lv
->set_output_symtab_index(index
);
2316 case CFLV_DISCARDED
:
2327 // Set the output dynamic symbol table indexes for the local variables.
2329 template<int size
, bool big_endian
>
2331 Sized_relobj_file
<size
, big_endian
>::do_set_local_dynsym_indexes(
2334 const unsigned int loccount
= this->local_symbol_count_
;
2335 for (unsigned int i
= 1; i
< loccount
; ++i
)
2337 Symbol_value
<size
>& lv(this->local_values_
[i
]);
2338 if (lv
.needs_output_dynsym_entry())
2340 lv
.set_output_dynsym_index(index
);
2347 // Set the offset where local dynamic symbol information will be stored.
2348 // Returns the count of local symbols contributed to the symbol table by
2351 template<int size
, bool big_endian
>
2353 Sized_relobj_file
<size
, big_endian
>::do_set_local_dynsym_offset(off_t off
)
2355 gold_assert(off
== static_cast<off_t
>(align_address(off
, size
>> 3)));
2356 this->local_dynsym_offset_
= off
;
2357 return this->output_local_dynsym_count_
;
2360 // If Symbols_data is not NULL get the section flags from here otherwise
2361 // get it from the file.
2363 template<int size
, bool big_endian
>
2365 Sized_relobj_file
<size
, big_endian
>::do_section_flags(unsigned int shndx
)
2367 Symbols_data
* sd
= this->get_symbols_data();
2370 const unsigned char* pshdrs
= sd
->section_headers_data
2371 + This::shdr_size
* shndx
;
2372 typename
This::Shdr
shdr(pshdrs
);
2373 return shdr
.get_sh_flags();
2375 // If sd is NULL, read the section header from the file.
2376 return this->elf_file_
.section_flags(shndx
);
2379 // Get the section's ent size from Symbols_data. Called by get_section_contents
2382 template<int size
, bool big_endian
>
2384 Sized_relobj_file
<size
, big_endian
>::do_section_entsize(unsigned int shndx
)
2386 Symbols_data
* sd
= this->get_symbols_data();
2387 gold_assert(sd
!= NULL
);
2389 const unsigned char* pshdrs
= sd
->section_headers_data
2390 + This::shdr_size
* shndx
;
2391 typename
This::Shdr
shdr(pshdrs
);
2392 return shdr
.get_sh_entsize();
2395 // Write out the local symbols.
2397 template<int size
, bool big_endian
>
2399 Sized_relobj_file
<size
, big_endian
>::write_local_symbols(
2401 const Stringpool
* sympool
,
2402 const Stringpool
* dynpool
,
2403 Output_symtab_xindex
* symtab_xindex
,
2404 Output_symtab_xindex
* dynsym_xindex
,
2407 const bool strip_all
= parameters
->options().strip_all();
2410 if (this->output_local_dynsym_count_
== 0)
2412 this->output_local_symbol_count_
= 0;
2415 gold_assert(this->symtab_shndx_
!= -1U);
2416 if (this->symtab_shndx_
== 0)
2418 // This object has no symbols. Weird but legal.
2422 // Read the symbol table section header.
2423 const unsigned int symtab_shndx
= this->symtab_shndx_
;
2424 typename
This::Shdr
symtabshdr(this,
2425 this->elf_file_
.section_header(symtab_shndx
));
2426 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
2427 const unsigned int loccount
= this->local_symbol_count_
;
2428 gold_assert(loccount
== symtabshdr
.get_sh_info());
2430 // Read the local symbols.
2431 const int sym_size
= This::sym_size
;
2432 off_t locsize
= loccount
* sym_size
;
2433 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
2434 locsize
, true, false);
2436 // Read the symbol names.
2437 const unsigned int strtab_shndx
=
2438 this->adjust_shndx(symtabshdr
.get_sh_link());
2439 section_size_type strtab_size
;
2440 const unsigned char* pnamesu
= this->section_contents(strtab_shndx
,
2443 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
2445 // Get views into the output file for the portions of the symbol table
2446 // and the dynamic symbol table that we will be writing.
2447 off_t output_size
= this->output_local_symbol_count_
* sym_size
;
2448 unsigned char* oview
= NULL
;
2449 if (output_size
> 0)
2450 oview
= of
->get_output_view(symtab_off
+ this->local_symbol_offset_
,
2453 off_t dyn_output_size
= this->output_local_dynsym_count_
* sym_size
;
2454 unsigned char* dyn_oview
= NULL
;
2455 if (dyn_output_size
> 0)
2456 dyn_oview
= of
->get_output_view(this->local_dynsym_offset_
,
2459 const Output_sections
out_sections(this->output_sections());
2461 gold_assert(this->local_values_
.size() == loccount
);
2463 unsigned char* ov
= oview
;
2464 unsigned char* dyn_ov
= dyn_oview
;
2466 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2468 elfcpp::Sym
<size
, big_endian
> isym(psyms
);
2470 Symbol_value
<size
>& lv(this->local_values_
[i
]);
2473 unsigned int st_shndx
= this->adjust_sym_shndx(i
, isym
.get_st_shndx(),
2477 gold_assert(st_shndx
< out_sections
.size());
2478 if (out_sections
[st_shndx
] == NULL
)
2480 st_shndx
= out_sections
[st_shndx
]->out_shndx();
2481 if (st_shndx
>= elfcpp::SHN_LORESERVE
)
2483 if (lv
.has_output_symtab_entry())
2484 symtab_xindex
->add(lv
.output_symtab_index(), st_shndx
);
2485 if (lv
.has_output_dynsym_entry())
2486 dynsym_xindex
->add(lv
.output_dynsym_index(), st_shndx
);
2487 st_shndx
= elfcpp::SHN_XINDEX
;
2491 // Write the symbol to the output symbol table.
2492 if (lv
.has_output_symtab_entry())
2494 elfcpp::Sym_write
<size
, big_endian
> osym(ov
);
2496 gold_assert(isym
.get_st_name() < strtab_size
);
2497 const char* name
= pnames
+ isym
.get_st_name();
2498 osym
.put_st_name(sympool
->get_offset(name
));
2499 osym
.put_st_value(this->local_values_
[i
].value(this, 0));
2500 osym
.put_st_size(isym
.get_st_size());
2501 osym
.put_st_info(isym
.get_st_info());
2502 osym
.put_st_other(isym
.get_st_other());
2503 osym
.put_st_shndx(st_shndx
);
2508 // Write the symbol to the output dynamic symbol table.
2509 if (lv
.has_output_dynsym_entry())
2511 gold_assert(dyn_ov
< dyn_oview
+ dyn_output_size
);
2512 elfcpp::Sym_write
<size
, big_endian
> osym(dyn_ov
);
2514 gold_assert(isym
.get_st_name() < strtab_size
);
2515 const char* name
= pnames
+ isym
.get_st_name();
2516 osym
.put_st_name(dynpool
->get_offset(name
));
2517 osym
.put_st_value(this->local_values_
[i
].value(this, 0));
2518 osym
.put_st_size(isym
.get_st_size());
2519 osym
.put_st_info(isym
.get_st_info());
2520 osym
.put_st_other(isym
.get_st_other());
2521 osym
.put_st_shndx(st_shndx
);
2528 if (output_size
> 0)
2530 gold_assert(ov
- oview
== output_size
);
2531 of
->write_output_view(symtab_off
+ this->local_symbol_offset_
,
2532 output_size
, oview
);
2535 if (dyn_output_size
> 0)
2537 gold_assert(dyn_ov
- dyn_oview
== dyn_output_size
);
2538 of
->write_output_view(this->local_dynsym_offset_
, dyn_output_size
,
2543 // Set *INFO to symbolic information about the offset OFFSET in the
2544 // section SHNDX. Return true if we found something, false if we
2547 template<int size
, bool big_endian
>
2549 Sized_relobj_file
<size
, big_endian
>::get_symbol_location_info(
2552 Symbol_location_info
* info
)
2554 if (this->symtab_shndx_
== 0)
2557 section_size_type symbols_size
;
2558 const unsigned char* symbols
= this->section_contents(this->symtab_shndx_
,
2562 unsigned int symbol_names_shndx
=
2563 this->adjust_shndx(this->section_link(this->symtab_shndx_
));
2564 section_size_type names_size
;
2565 const unsigned char* symbol_names_u
=
2566 this->section_contents(symbol_names_shndx
, &names_size
, false);
2567 const char* symbol_names
= reinterpret_cast<const char*>(symbol_names_u
);
2569 const int sym_size
= This::sym_size
;
2570 const size_t count
= symbols_size
/ sym_size
;
2572 const unsigned char* p
= symbols
;
2573 for (size_t i
= 0; i
< count
; ++i
, p
+= sym_size
)
2575 elfcpp::Sym
<size
, big_endian
> sym(p
);
2577 if (sym
.get_st_type() == elfcpp::STT_FILE
)
2579 if (sym
.get_st_name() >= names_size
)
2580 info
->source_file
= "(invalid)";
2582 info
->source_file
= symbol_names
+ sym
.get_st_name();
2587 unsigned int st_shndx
= this->adjust_sym_shndx(i
, sym
.get_st_shndx(),
2590 && st_shndx
== shndx
2591 && static_cast<off_t
>(sym
.get_st_value()) <= offset
2592 && (static_cast<off_t
>(sym
.get_st_value() + sym
.get_st_size())
2595 if (sym
.get_st_name() > names_size
)
2596 info
->enclosing_symbol_name
= "(invalid)";
2599 info
->enclosing_symbol_name
= symbol_names
+ sym
.get_st_name();
2600 if (parameters
->options().do_demangle())
2602 char* demangled_name
= cplus_demangle(
2603 info
->enclosing_symbol_name
.c_str(),
2604 DMGL_ANSI
| DMGL_PARAMS
);
2605 if (demangled_name
!= NULL
)
2607 info
->enclosing_symbol_name
.assign(demangled_name
);
2608 free(demangled_name
);
2619 // Look for a kept section corresponding to the given discarded section,
2620 // and return its output address. This is used only for relocations in
2621 // debugging sections. If we can't find the kept section, return 0.
2623 template<int size
, bool big_endian
>
2624 typename Sized_relobj_file
<size
, big_endian
>::Address
2625 Sized_relobj_file
<size
, big_endian
>::map_to_kept_section(
2629 Relobj
* kept_object
;
2630 unsigned int kept_shndx
;
2631 if (this->get_kept_comdat_section(shndx
, &kept_object
, &kept_shndx
))
2633 Sized_relobj_file
<size
, big_endian
>* kept_relobj
=
2634 static_cast<Sized_relobj_file
<size
, big_endian
>*>(kept_object
);
2635 Output_section
* os
= kept_relobj
->output_section(kept_shndx
);
2636 Address offset
= kept_relobj
->get_output_section_offset(kept_shndx
);
2637 if (os
!= NULL
&& offset
!= invalid_address
)
2640 return os
->address() + offset
;
2647 // Get symbol counts.
2649 template<int size
, bool big_endian
>
2651 Sized_relobj_file
<size
, big_endian
>::do_get_global_symbol_counts(
2652 const Symbol_table
*,
2656 *defined
= this->defined_count_
;
2658 for (typename
Symbols::const_iterator p
= this->symbols_
.begin();
2659 p
!= this->symbols_
.end();
2662 && (*p
)->source() == Symbol::FROM_OBJECT
2663 && (*p
)->object() == this
2664 && (*p
)->is_defined())
2669 // Return a view of the decompressed contents of a section. Set *PLEN
2670 // to the size. Set *IS_NEW to true if the contents need to be freed
2673 template<int size
, bool big_endian
>
2674 const unsigned char*
2675 Sized_relobj_file
<size
, big_endian
>::do_decompressed_section_contents(
2677 section_size_type
* plen
,
2680 section_size_type buffer_size
;
2681 const unsigned char* buffer
= this->do_section_contents(shndx
, &buffer_size
,
2684 if (this->compressed_sections_
== NULL
)
2686 *plen
= buffer_size
;
2691 Compressed_section_map::const_iterator p
=
2692 this->compressed_sections_
->find(shndx
);
2693 if (p
== this->compressed_sections_
->end())
2695 *plen
= buffer_size
;
2700 section_size_type uncompressed_size
= p
->second
.size
;
2701 if (p
->second
.contents
!= NULL
)
2703 *plen
= uncompressed_size
;
2705 return p
->second
.contents
;
2708 unsigned char* uncompressed_data
= new unsigned char[uncompressed_size
];
2709 if (!decompress_input_section(buffer
,
2713 this->error(_("could not decompress section %s"),
2714 this->do_section_name(shndx
).c_str());
2716 // We could cache the results in p->second.contents and store
2717 // false in *IS_NEW, but build_compressed_section_map() would
2718 // have done so if it had expected it to be profitable. If
2719 // we reach this point, we expect to need the contents only
2720 // once in this pass.
2721 *plen
= uncompressed_size
;
2723 return uncompressed_data
;
2726 // Discard any buffers of uncompressed sections. This is done
2727 // at the end of the Add_symbols task.
2729 template<int size
, bool big_endian
>
2731 Sized_relobj_file
<size
, big_endian
>::do_discard_decompressed_sections()
2733 if (this->compressed_sections_
== NULL
)
2736 for (Compressed_section_map::iterator p
= this->compressed_sections_
->begin();
2737 p
!= this->compressed_sections_
->end();
2740 if (p
->second
.contents
!= NULL
)
2742 delete[] p
->second
.contents
;
2743 p
->second
.contents
= NULL
;
2748 // Input_objects methods.
2750 // Add a regular relocatable object to the list. Return false if this
2751 // object should be ignored.
2754 Input_objects::add_object(Object
* obj
)
2756 // Print the filename if the -t/--trace option is selected.
2757 if (parameters
->options().trace())
2758 gold_info("%s", obj
->name().c_str());
2760 if (!obj
->is_dynamic())
2761 this->relobj_list_
.push_back(static_cast<Relobj
*>(obj
));
2764 // See if this is a duplicate SONAME.
2765 Dynobj
* dynobj
= static_cast<Dynobj
*>(obj
);
2766 const char* soname
= dynobj
->soname();
2768 std::pair
<Unordered_set
<std::string
>::iterator
, bool> ins
=
2769 this->sonames_
.insert(soname
);
2772 // We have already seen a dynamic object with this soname.
2776 this->dynobj_list_
.push_back(dynobj
);
2779 // Add this object to the cross-referencer if requested.
2780 if (parameters
->options().user_set_print_symbol_counts()
2781 || parameters
->options().cref())
2783 if (this->cref_
== NULL
)
2784 this->cref_
= new Cref();
2785 this->cref_
->add_object(obj
);
2791 // For each dynamic object, record whether we've seen all of its
2792 // explicit dependencies.
2795 Input_objects::check_dynamic_dependencies() const
2797 bool issued_copy_dt_needed_error
= false;
2798 for (Dynobj_list::const_iterator p
= this->dynobj_list_
.begin();
2799 p
!= this->dynobj_list_
.end();
2802 const Dynobj::Needed
& needed((*p
)->needed());
2803 bool found_all
= true;
2804 Dynobj::Needed::const_iterator pneeded
;
2805 for (pneeded
= needed
.begin(); pneeded
!= needed
.end(); ++pneeded
)
2807 if (this->sonames_
.find(*pneeded
) == this->sonames_
.end())
2813 (*p
)->set_has_unknown_needed_entries(!found_all
);
2815 // --copy-dt-needed-entries aka --add-needed is a GNU ld option
2816 // that gold does not support. However, they cause no trouble
2817 // unless there is a DT_NEEDED entry that we don't know about;
2818 // warn only in that case.
2820 && !issued_copy_dt_needed_error
2821 && (parameters
->options().copy_dt_needed_entries()
2822 || parameters
->options().add_needed()))
2824 const char* optname
;
2825 if (parameters
->options().copy_dt_needed_entries())
2826 optname
= "--copy-dt-needed-entries";
2828 optname
= "--add-needed";
2829 gold_error(_("%s is not supported but is required for %s in %s"),
2830 optname
, (*pneeded
).c_str(), (*p
)->name().c_str());
2831 issued_copy_dt_needed_error
= true;
2836 // Start processing an archive.
2839 Input_objects::archive_start(Archive
* archive
)
2841 if (parameters
->options().user_set_print_symbol_counts()
2842 || parameters
->options().cref())
2844 if (this->cref_
== NULL
)
2845 this->cref_
= new Cref();
2846 this->cref_
->add_archive_start(archive
);
2850 // Stop processing an archive.
2853 Input_objects::archive_stop(Archive
* archive
)
2855 if (parameters
->options().user_set_print_symbol_counts()
2856 || parameters
->options().cref())
2857 this->cref_
->add_archive_stop(archive
);
2860 // Print symbol counts
2863 Input_objects::print_symbol_counts(const Symbol_table
* symtab
) const
2865 if (parameters
->options().user_set_print_symbol_counts()
2866 && this->cref_
!= NULL
)
2867 this->cref_
->print_symbol_counts(symtab
);
2870 // Print a cross reference table.
2873 Input_objects::print_cref(const Symbol_table
* symtab
, FILE* f
) const
2875 if (parameters
->options().cref() && this->cref_
!= NULL
)
2876 this->cref_
->print_cref(symtab
, f
);
2879 // Relocate_info methods.
2881 // Return a string describing the location of a relocation when file
2882 // and lineno information is not available. This is only used in
2885 template<int size
, bool big_endian
>
2887 Relocate_info
<size
, big_endian
>::location(size_t, off_t offset
) const
2889 Sized_dwarf_line_info
<size
, big_endian
> line_info(this->object
);
2890 std::string ret
= line_info
.addr2line(this->data_shndx
, offset
, NULL
);
2894 ret
= this->object
->name();
2896 Symbol_location_info info
;
2897 if (this->object
->get_symbol_location_info(this->data_shndx
, offset
, &info
))
2899 if (!info
.source_file
.empty())
2902 ret
+= info
.source_file
;
2904 size_t len
= info
.enclosing_symbol_name
.length() + 100;
2905 char* buf
= new char[len
];
2906 snprintf(buf
, len
, _(":function %s"),
2907 info
.enclosing_symbol_name
.c_str());
2914 ret
+= this->object
->section_name(this->data_shndx
);
2916 snprintf(buf
, sizeof buf
, "+0x%lx)", static_cast<long>(offset
));
2921 } // End namespace gold.
2926 using namespace gold
;
2928 // Read an ELF file with the header and return the appropriate
2929 // instance of Object.
2931 template<int size
, bool big_endian
>
2933 make_elf_sized_object(const std::string
& name
, Input_file
* input_file
,
2934 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
,
2935 bool* punconfigured
)
2937 Target
* target
= select_target(ehdr
.get_e_machine(), size
, big_endian
,
2938 ehdr
.get_e_ident()[elfcpp::EI_OSABI
],
2939 ehdr
.get_e_ident()[elfcpp::EI_ABIVERSION
]);
2941 gold_fatal(_("%s: unsupported ELF machine number %d"),
2942 name
.c_str(), ehdr
.get_e_machine());
2944 if (!parameters
->target_valid())
2945 set_parameters_target(target
);
2946 else if (target
!= ¶meters
->target())
2948 if (punconfigured
!= NULL
)
2949 *punconfigured
= true;
2951 gold_error(_("%s: incompatible target"), name
.c_str());
2955 return target
->make_elf_object
<size
, big_endian
>(name
, input_file
, offset
,
2959 } // End anonymous namespace.
2964 // Return whether INPUT_FILE is an ELF object.
2967 is_elf_object(Input_file
* input_file
, off_t offset
,
2968 const unsigned char** start
, int* read_size
)
2970 off_t filesize
= input_file
->file().filesize();
2971 int want
= elfcpp::Elf_recognizer::max_header_size
;
2972 if (filesize
- offset
< want
)
2973 want
= filesize
- offset
;
2975 const unsigned char* p
= input_file
->file().get_view(offset
, 0, want
,
2980 return elfcpp::Elf_recognizer::is_elf_file(p
, want
);
2983 // Read an ELF file and return the appropriate instance of Object.
2986 make_elf_object(const std::string
& name
, Input_file
* input_file
, off_t offset
,
2987 const unsigned char* p
, section_offset_type bytes
,
2988 bool* punconfigured
)
2990 if (punconfigured
!= NULL
)
2991 *punconfigured
= false;
2994 bool big_endian
= false;
2996 if (!elfcpp::Elf_recognizer::is_valid_header(p
, bytes
, &size
,
2997 &big_endian
, &error
))
2999 gold_error(_("%s: %s"), name
.c_str(), error
.c_str());
3007 #ifdef HAVE_TARGET_32_BIG
3008 elfcpp::Ehdr
<32, true> ehdr(p
);
3009 return make_elf_sized_object
<32, true>(name
, input_file
,
3010 offset
, ehdr
, punconfigured
);
3012 if (punconfigured
!= NULL
)
3013 *punconfigured
= true;
3015 gold_error(_("%s: not configured to support "
3016 "32-bit big-endian object"),
3023 #ifdef HAVE_TARGET_32_LITTLE
3024 elfcpp::Ehdr
<32, false> ehdr(p
);
3025 return make_elf_sized_object
<32, false>(name
, input_file
,
3026 offset
, ehdr
, punconfigured
);
3028 if (punconfigured
!= NULL
)
3029 *punconfigured
= true;
3031 gold_error(_("%s: not configured to support "
3032 "32-bit little-endian object"),
3038 else if (size
== 64)
3042 #ifdef HAVE_TARGET_64_BIG
3043 elfcpp::Ehdr
<64, true> ehdr(p
);
3044 return make_elf_sized_object
<64, true>(name
, input_file
,
3045 offset
, ehdr
, punconfigured
);
3047 if (punconfigured
!= NULL
)
3048 *punconfigured
= true;
3050 gold_error(_("%s: not configured to support "
3051 "64-bit big-endian object"),
3058 #ifdef HAVE_TARGET_64_LITTLE
3059 elfcpp::Ehdr
<64, false> ehdr(p
);
3060 return make_elf_sized_object
<64, false>(name
, input_file
,
3061 offset
, ehdr
, punconfigured
);
3063 if (punconfigured
!= NULL
)
3064 *punconfigured
= true;
3066 gold_error(_("%s: not configured to support "
3067 "64-bit little-endian object"),
3077 // Instantiate the templates we need.
3079 #ifdef HAVE_TARGET_32_LITTLE
3082 Object::read_section_data
<32, false>(elfcpp::Elf_file
<32, false, Object
>*,
3083 Read_symbols_data
*);
3086 #ifdef HAVE_TARGET_32_BIG
3089 Object::read_section_data
<32, true>(elfcpp::Elf_file
<32, true, Object
>*,
3090 Read_symbols_data
*);
3093 #ifdef HAVE_TARGET_64_LITTLE
3096 Object::read_section_data
<64, false>(elfcpp::Elf_file
<64, false, Object
>*,
3097 Read_symbols_data
*);
3100 #ifdef HAVE_TARGET_64_BIG
3103 Object::read_section_data
<64, true>(elfcpp::Elf_file
<64, true, Object
>*,
3104 Read_symbols_data
*);
3107 #ifdef HAVE_TARGET_32_LITTLE
3109 class Sized_relobj_file
<32, false>;
3112 #ifdef HAVE_TARGET_32_BIG
3114 class Sized_relobj_file
<32, true>;
3117 #ifdef HAVE_TARGET_64_LITTLE
3119 class Sized_relobj_file
<64, false>;
3122 #ifdef HAVE_TARGET_64_BIG
3124 class Sized_relobj_file
<64, true>;
3127 #ifdef HAVE_TARGET_32_LITTLE
3129 struct Relocate_info
<32, false>;
3132 #ifdef HAVE_TARGET_32_BIG
3134 struct Relocate_info
<32, true>;
3137 #ifdef HAVE_TARGET_64_LITTLE
3139 struct Relocate_info
<64, false>;
3142 #ifdef HAVE_TARGET_64_BIG
3144 struct Relocate_info
<64, true>;
3147 #ifdef HAVE_TARGET_32_LITTLE
3150 Xindex::initialize_symtab_xindex
<32, false>(Object
*, unsigned int);
3154 Xindex::read_symtab_xindex
<32, false>(Object
*, unsigned int,
3155 const unsigned char*);
3158 #ifdef HAVE_TARGET_32_BIG
3161 Xindex::initialize_symtab_xindex
<32, true>(Object
*, unsigned int);
3165 Xindex::read_symtab_xindex
<32, true>(Object
*, unsigned int,
3166 const unsigned char*);
3169 #ifdef HAVE_TARGET_64_LITTLE
3172 Xindex::initialize_symtab_xindex
<64, false>(Object
*, unsigned int);
3176 Xindex::read_symtab_xindex
<64, false>(Object
*, unsigned int,
3177 const unsigned char*);
3180 #ifdef HAVE_TARGET_64_BIG
3183 Xindex::initialize_symtab_xindex
<64, true>(Object
*, unsigned int);
3187 Xindex::read_symtab_xindex
<64, true>(Object
*, unsigned int,
3188 const unsigned char*);
3191 } // End namespace gold.