]> Git Repo - binutils.git/blob - gold/object.cc
PR 11855
[binutils.git] / gold / object.cc
1 // object.cc -- support for an object file for linking in gold
2
3 // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <[email protected]>.
5
6 // This file is part of gold.
7
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.
12
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.
17
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.
22
23 #include "gold.h"
24
25 #include <cerrno>
26 #include <cstring>
27 #include <cstdarg>
28 #include "demangle.h"
29 #include "libiberty.h"
30
31 #include "gc.h"
32 #include "target-select.h"
33 #include "dwarf_reader.h"
34 #include "layout.h"
35 #include "output.h"
36 #include "symtab.h"
37 #include "cref.h"
38 #include "reloc.h"
39 #include "object.h"
40 #include "dynobj.h"
41 #include "plugin.h"
42 #include "compressed_output.h"
43
44 namespace gold
45 {
46
47 // Struct Read_symbols_data.
48
49 // Destroy any remaining File_view objects.
50
51 Read_symbols_data::~Read_symbols_data()
52 {
53   if (this->section_headers != NULL)
54     delete this->section_headers;
55   if (this->section_names != NULL)
56     delete this->section_names;
57   if (this->symbols != NULL)
58     delete this->symbols;
59   if (this->symbol_names != NULL)
60     delete this->symbol_names;
61   if (this->versym != NULL)
62     delete this->versym;
63   if (this->verdef != NULL)
64     delete this->verdef;
65   if (this->verneed != NULL)
66     delete this->verneed;
67 }
68
69 // Class Xindex.
70
71 // Initialize the symtab_xindex_ array.  Find the SHT_SYMTAB_SHNDX
72 // section and read it in.  SYMTAB_SHNDX is the index of the symbol
73 // table we care about.
74
75 template<int size, bool big_endian>
76 void
77 Xindex::initialize_symtab_xindex(Object* object, unsigned int symtab_shndx)
78 {
79   if (!this->symtab_xindex_.empty())
80     return;
81
82   gold_assert(symtab_shndx != 0);
83
84   // Look through the sections in reverse order, on the theory that it
85   // is more likely to be near the end than the beginning.
86   unsigned int i = object->shnum();
87   while (i > 0)
88     {
89       --i;
90       if (object->section_type(i) == elfcpp::SHT_SYMTAB_SHNDX
91           && this->adjust_shndx(object->section_link(i)) == symtab_shndx)
92         {
93           this->read_symtab_xindex<size, big_endian>(object, i, NULL);
94           return;
95         }
96     }
97
98   object->error(_("missing SHT_SYMTAB_SHNDX section"));
99 }
100
101 // Read in the symtab_xindex_ array, given the section index of the
102 // SHT_SYMTAB_SHNDX section.  If PSHDRS is not NULL, it points at the
103 // section headers.
104
105 template<int size, bool big_endian>
106 void
107 Xindex::read_symtab_xindex(Object* object, unsigned int xindex_shndx,
108                            const unsigned char* pshdrs)
109 {
110   section_size_type bytecount;
111   const unsigned char* contents;
112   if (pshdrs == NULL)
113     contents = object->section_contents(xindex_shndx, &bytecount, false);
114   else
115     {
116       const unsigned char* p = (pshdrs
117                                 + (xindex_shndx
118                                    * elfcpp::Elf_sizes<size>::shdr_size));
119       typename elfcpp::Shdr<size, big_endian> shdr(p);
120       bytecount = convert_to_section_size_type(shdr.get_sh_size());
121       contents = object->get_view(shdr.get_sh_offset(), bytecount, true, false);
122     }
123
124   gold_assert(this->symtab_xindex_.empty());
125   this->symtab_xindex_.reserve(bytecount / 4);
126   for (section_size_type i = 0; i < bytecount; i += 4)
127     {
128       unsigned int shndx = elfcpp::Swap<32, big_endian>::readval(contents + i);
129       // We preadjust the section indexes we save.
130       this->symtab_xindex_.push_back(this->adjust_shndx(shndx));
131     }
132 }
133
134 // Symbol symndx has a section of SHN_XINDEX; return the real section
135 // index.
136
137 unsigned int
138 Xindex::sym_xindex_to_shndx(Object* object, unsigned int symndx)
139 {
140   if (symndx >= this->symtab_xindex_.size())
141     {
142       object->error(_("symbol %u out of range for SHT_SYMTAB_SHNDX section"),
143                     symndx);
144       return elfcpp::SHN_UNDEF;
145     }
146   unsigned int shndx = this->symtab_xindex_[symndx];
147   if (shndx < elfcpp::SHN_LORESERVE || shndx >= object->shnum())
148     {
149       object->error(_("extended index for symbol %u out of range: %u"),
150                     symndx, shndx);
151       return elfcpp::SHN_UNDEF;
152     }
153   return shndx;
154 }
155
156 // Class Object.
157
158 // Report an error for this object file.  This is used by the
159 // elfcpp::Elf_file interface, and also called by the Object code
160 // itself.
161
162 void
163 Object::error(const char* format, ...) const
164 {
165   va_list args;
166   va_start(args, format);
167   char* buf = NULL;
168   if (vasprintf(&buf, format, args) < 0)
169     gold_nomem();
170   va_end(args);
171   gold_error(_("%s: %s"), this->name().c_str(), buf);
172   free(buf);
173 }
174
175 // Return a view of the contents of a section.
176
177 const unsigned char*
178 Object::section_contents(unsigned int shndx, section_size_type* plen,
179                          bool cache)
180 {
181   Location loc(this->do_section_contents(shndx));
182   *plen = convert_to_section_size_type(loc.data_size);
183   if (*plen == 0)
184     {
185       static const unsigned char empty[1] = { '\0' };
186       return empty;
187     }
188   return this->get_view(loc.file_offset, *plen, true, cache);
189 }
190
191 // Read the section data into SD.  This is code common to Sized_relobj
192 // and Sized_dynobj, so we put it into Object.
193
194 template<int size, bool big_endian>
195 void
196 Object::read_section_data(elfcpp::Elf_file<size, big_endian, Object>* elf_file,
197                           Read_symbols_data* sd)
198 {
199   const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
200
201   // Read the section headers.
202   const off_t shoff = elf_file->shoff();
203   const unsigned int shnum = this->shnum();
204   sd->section_headers = this->get_lasting_view(shoff, shnum * shdr_size,
205                                                true, true);
206
207   // Read the section names.
208   const unsigned char* pshdrs = sd->section_headers->data();
209   const unsigned char* pshdrnames = pshdrs + elf_file->shstrndx() * shdr_size;
210   typename elfcpp::Shdr<size, big_endian> shdrnames(pshdrnames);
211
212   if (shdrnames.get_sh_type() != elfcpp::SHT_STRTAB)
213     this->error(_("section name section has wrong type: %u"),
214                 static_cast<unsigned int>(shdrnames.get_sh_type()));
215
216   sd->section_names_size =
217     convert_to_section_size_type(shdrnames.get_sh_size());
218   sd->section_names = this->get_lasting_view(shdrnames.get_sh_offset(),
219                                              sd->section_names_size, false,
220                                              false);
221 }
222
223 // If NAME is the name of a special .gnu.warning section, arrange for
224 // the warning to be issued.  SHNDX is the section index.  Return
225 // whether it is a warning section.
226
227 bool
228 Object::handle_gnu_warning_section(const char* name, unsigned int shndx,
229                                    Symbol_table* symtab)
230 {
231   const char warn_prefix[] = ".gnu.warning.";
232   const int warn_prefix_len = sizeof warn_prefix - 1;
233   if (strncmp(name, warn_prefix, warn_prefix_len) == 0)
234     {
235       // Read the section contents to get the warning text.  It would
236       // be nicer if we only did this if we have to actually issue a
237       // warning.  Unfortunately, warnings are issued as we relocate
238       // sections.  That means that we can not lock the object then,
239       // as we might try to issue the same warning multiple times
240       // simultaneously.
241       section_size_type len;
242       const unsigned char* contents = this->section_contents(shndx, &len,
243                                                              false);
244       if (len == 0)
245         {
246           const char* warning = name + warn_prefix_len;
247           contents = reinterpret_cast<const unsigned char*>(warning);
248           len = strlen(warning);
249         }
250       std::string warning(reinterpret_cast<const char*>(contents), len);
251       symtab->add_warning(name + warn_prefix_len, this, warning);
252       return true;
253     }
254   return false;
255 }
256
257 // If NAME is the name of the special section which indicates that
258 // this object was compiled with -fstack-split, mark it accordingly.
259
260 bool
261 Object::handle_split_stack_section(const char* name)
262 {
263   if (strcmp(name, ".note.GNU-split-stack") == 0)
264     {
265       this->uses_split_stack_ = true;
266       return true;
267     }
268   if (strcmp(name, ".note.GNU-no-split-stack") == 0)
269     {
270       this->has_no_split_stack_ = true;
271       return true;
272     }
273   return false;
274 }
275
276 // Class Relobj
277
278 // To copy the symbols data read from the file to a local data structure.
279 // This function is called from do_layout only while doing garbage 
280 // collection.
281
282 void
283 Relobj::copy_symbols_data(Symbols_data* gc_sd, Read_symbols_data* sd, 
284                           unsigned int section_header_size)
285 {
286   gc_sd->section_headers_data = 
287          new unsigned char[(section_header_size)];
288   memcpy(gc_sd->section_headers_data, sd->section_headers->data(),
289          section_header_size);
290   gc_sd->section_names_data = 
291          new unsigned char[sd->section_names_size];
292   memcpy(gc_sd->section_names_data, sd->section_names->data(),
293          sd->section_names_size);
294   gc_sd->section_names_size = sd->section_names_size;
295   if (sd->symbols != NULL)
296     {
297       gc_sd->symbols_data = 
298              new unsigned char[sd->symbols_size];
299       memcpy(gc_sd->symbols_data, sd->symbols->data(),
300             sd->symbols_size);
301     }
302   else
303     {
304       gc_sd->symbols_data = NULL;
305     }
306   gc_sd->symbols_size = sd->symbols_size;
307   gc_sd->external_symbols_offset = sd->external_symbols_offset;
308   if (sd->symbol_names != NULL)
309     {
310       gc_sd->symbol_names_data =
311              new unsigned char[sd->symbol_names_size];
312       memcpy(gc_sd->symbol_names_data, sd->symbol_names->data(),
313             sd->symbol_names_size);
314     }
315   else
316     {
317       gc_sd->symbol_names_data = NULL;
318     }
319   gc_sd->symbol_names_size = sd->symbol_names_size;
320 }
321
322 // This function determines if a particular section name must be included
323 // in the link.  This is used during garbage collection to determine the
324 // roots of the worklist.
325
326 bool
327 Relobj::is_section_name_included(const char* name)
328 {
329   if (is_prefix_of(".ctors", name) 
330       || is_prefix_of(".dtors", name) 
331       || is_prefix_of(".note", name) 
332       || is_prefix_of(".init", name) 
333       || is_prefix_of(".fini", name) 
334       || is_prefix_of(".gcc_except_table", name) 
335       || is_prefix_of(".jcr", name) 
336       || is_prefix_of(".preinit_array", name) 
337       || (is_prefix_of(".text", name) 
338           && strstr(name, "personality")) 
339       || (is_prefix_of(".data", name) 
340           &&  strstr(name, "personality")) 
341       || (is_prefix_of(".gnu.linkonce.d", name)
342           && strstr(name, "personality")))
343     {
344       return true; 
345     }
346   return false;
347 }
348
349 // Class Sized_relobj.
350
351 template<int size, bool big_endian>
352 Sized_relobj<size, big_endian>::Sized_relobj(
353     const std::string& name,
354     Input_file* input_file,
355     off_t offset,
356     const elfcpp::Ehdr<size, big_endian>& ehdr)
357   : Relobj(name, input_file, offset),
358     elf_file_(this, ehdr),
359     symtab_shndx_(-1U),
360     local_symbol_count_(0),
361     output_local_symbol_count_(0),
362     output_local_dynsym_count_(0),
363     symbols_(),
364     defined_count_(0),
365     local_symbol_offset_(0),
366     local_dynsym_offset_(0),
367     local_values_(),
368     local_got_offsets_(),
369     kept_comdat_sections_(),
370     has_eh_frame_(false),
371     discarded_eh_frame_shndx_(-1U),
372     deferred_layout_(),
373     deferred_layout_relocs_(),
374     compressed_sections_()
375 {
376 }
377
378 template<int size, bool big_endian>
379 Sized_relobj<size, big_endian>::~Sized_relobj()
380 {
381 }
382
383 // Set up an object file based on the file header.  This sets up the
384 // section information.
385
386 template<int size, bool big_endian>
387 void
388 Sized_relobj<size, big_endian>::do_setup()
389 {
390   const unsigned int shnum = this->elf_file_.shnum();
391   this->set_shnum(shnum);
392 }
393
394 // Find the SHT_SYMTAB section, given the section headers.  The ELF
395 // standard says that maybe in the future there can be more than one
396 // SHT_SYMTAB section.  Until somebody figures out how that could
397 // work, we assume there is only one.
398
399 template<int size, bool big_endian>
400 void
401 Sized_relobj<size, big_endian>::find_symtab(const unsigned char* pshdrs)
402 {
403   const unsigned int shnum = this->shnum();
404   this->symtab_shndx_ = 0;
405   if (shnum > 0)
406     {
407       // Look through the sections in reverse order, since gas tends
408       // to put the symbol table at the end.
409       const unsigned char* p = pshdrs + shnum * This::shdr_size;
410       unsigned int i = shnum;
411       unsigned int xindex_shndx = 0;
412       unsigned int xindex_link = 0;
413       while (i > 0)
414         {
415           --i;
416           p -= This::shdr_size;
417           typename This::Shdr shdr(p);
418           if (shdr.get_sh_type() == elfcpp::SHT_SYMTAB)
419             {
420               this->symtab_shndx_ = i;
421               if (xindex_shndx > 0 && xindex_link == i)
422                 {
423                   Xindex* xindex =
424                     new Xindex(this->elf_file_.large_shndx_offset());
425                   xindex->read_symtab_xindex<size, big_endian>(this,
426                                                                xindex_shndx,
427                                                                pshdrs);
428                   this->set_xindex(xindex);
429                 }
430               break;
431             }
432
433           // Try to pick up the SHT_SYMTAB_SHNDX section, if there is
434           // one.  This will work if it follows the SHT_SYMTAB
435           // section.
436           if (shdr.get_sh_type() == elfcpp::SHT_SYMTAB_SHNDX)
437             {
438               xindex_shndx = i;
439               xindex_link = this->adjust_shndx(shdr.get_sh_link());
440             }
441         }
442     }
443 }
444
445 // Return the Xindex structure to use for object with lots of
446 // sections.
447
448 template<int size, bool big_endian>
449 Xindex*
450 Sized_relobj<size, big_endian>::do_initialize_xindex()
451 {
452   gold_assert(this->symtab_shndx_ != -1U);
453   Xindex* xindex = new Xindex(this->elf_file_.large_shndx_offset());
454   xindex->initialize_symtab_xindex<size, big_endian>(this, this->symtab_shndx_);
455   return xindex;
456 }
457
458 // Return whether SHDR has the right type and flags to be a GNU
459 // .eh_frame section.
460
461 template<int size, bool big_endian>
462 bool
463 Sized_relobj<size, big_endian>::check_eh_frame_flags(
464     const elfcpp::Shdr<size, big_endian>* shdr) const
465 {
466   return (shdr->get_sh_type() == elfcpp::SHT_PROGBITS
467           && (shdr->get_sh_flags() & elfcpp::SHF_ALLOC) != 0);
468 }
469
470 // Return whether there is a GNU .eh_frame section, given the section
471 // headers and the section names.
472
473 template<int size, bool big_endian>
474 bool
475 Sized_relobj<size, big_endian>::find_eh_frame(
476     const unsigned char* pshdrs,
477     const char* names,
478     section_size_type names_size) const
479 {
480   const unsigned int shnum = this->shnum();
481   const unsigned char* p = pshdrs + This::shdr_size;
482   for (unsigned int i = 1; i < shnum; ++i, p += This::shdr_size)
483     {
484       typename This::Shdr shdr(p);
485       if (this->check_eh_frame_flags(&shdr))
486         {
487           if (shdr.get_sh_name() >= names_size)
488             {
489               this->error(_("bad section name offset for section %u: %lu"),
490                           i, static_cast<unsigned long>(shdr.get_sh_name()));
491               continue;
492             }
493
494           const char* name = names + shdr.get_sh_name();
495           if (strcmp(name, ".eh_frame") == 0)
496             return true;
497         }
498     }
499   return false;
500 }
501
502 // Build a table for any compressed debug sections, mapping each section index
503 // to the uncompressed size.
504
505 template<int size, bool big_endian>
506 Compressed_section_map*
507 build_compressed_section_map(
508     const unsigned char* pshdrs,
509     unsigned int shnum,
510     const char* names,
511     section_size_type names_size,
512     Sized_relobj<size, big_endian>* obj)
513 {
514   Compressed_section_map* uncompressed_sizes = new Compressed_section_map();
515   const unsigned int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
516   const unsigned char* p = pshdrs + shdr_size;
517   for (unsigned int i = 1; i < shnum; ++i, p += shdr_size)
518     {
519       typename elfcpp::Shdr<size, big_endian> shdr(p);
520       if (shdr.get_sh_type() == elfcpp::SHT_PROGBITS
521           && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0)
522         {
523           if (shdr.get_sh_name() >= names_size)
524             {
525               obj->error(_("bad section name offset for section %u: %lu"),
526                          i, static_cast<unsigned long>(shdr.get_sh_name()));
527               continue;
528             }
529
530           const char* name = names + shdr.get_sh_name();
531           if (is_compressed_debug_section(name))
532             {
533               section_size_type len;
534               const unsigned char* contents =
535                   obj->section_contents(i, &len, false);
536               uint64_t uncompressed_size = get_uncompressed_size(contents, len);
537               if (uncompressed_size != -1ULL)
538                 (*uncompressed_sizes)[i] =
539                     convert_to_section_size_type(uncompressed_size);
540             }
541         }
542     }
543   return uncompressed_sizes;
544 }
545
546 // Read the sections and symbols from an object file.
547
548 template<int size, bool big_endian>
549 void
550 Sized_relobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
551 {
552   this->read_section_data(&this->elf_file_, sd);
553
554   const unsigned char* const pshdrs = sd->section_headers->data();
555
556   this->find_symtab(pshdrs);
557
558   const unsigned char* namesu = sd->section_names->data();
559   const char* names = reinterpret_cast<const char*>(namesu);
560   if (memmem(names, sd->section_names_size, ".eh_frame", 10) != NULL)
561     {
562       if (this->find_eh_frame(pshdrs, names, sd->section_names_size))
563         this->has_eh_frame_ = true;
564     }
565   if (memmem(names, sd->section_names_size, ".zdebug_", 8) != NULL)
566     this->compressed_sections_ =
567         build_compressed_section_map(pshdrs, this->shnum(), names,
568                                      sd->section_names_size, this);
569
570   sd->symbols = NULL;
571   sd->symbols_size = 0;
572   sd->external_symbols_offset = 0;
573   sd->symbol_names = NULL;
574   sd->symbol_names_size = 0;
575
576   if (this->symtab_shndx_ == 0)
577     {
578       // No symbol table.  Weird but legal.
579       return;
580     }
581
582   // Get the symbol table section header.
583   typename This::Shdr symtabshdr(pshdrs
584                                  + this->symtab_shndx_ * This::shdr_size);
585   gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
586
587   // If this object has a .eh_frame section, we need all the symbols.
588   // Otherwise we only need the external symbols.  While it would be
589   // simpler to just always read all the symbols, I've seen object
590   // files with well over 2000 local symbols, which for a 64-bit
591   // object file format is over 5 pages that we don't need to read
592   // now.
593
594   const int sym_size = This::sym_size;
595   const unsigned int loccount = symtabshdr.get_sh_info();
596   this->local_symbol_count_ = loccount;
597   this->local_values_.resize(loccount);
598   section_offset_type locsize = loccount * sym_size;
599   off_t dataoff = symtabshdr.get_sh_offset();
600   section_size_type datasize =
601     convert_to_section_size_type(symtabshdr.get_sh_size());
602   off_t extoff = dataoff + locsize;
603   section_size_type extsize = datasize - locsize;
604
605   off_t readoff = this->has_eh_frame_ ? dataoff : extoff;
606   section_size_type readsize = this->has_eh_frame_ ? datasize : extsize;
607
608   if (readsize == 0)
609     {
610       // No external symbols.  Also weird but also legal.
611       return;
612     }
613
614   File_view* fvsymtab = this->get_lasting_view(readoff, readsize, true, false);
615
616   // Read the section header for the symbol names.
617   unsigned int strtab_shndx = this->adjust_shndx(symtabshdr.get_sh_link());
618   if (strtab_shndx >= this->shnum())
619     {
620       this->error(_("invalid symbol table name index: %u"), strtab_shndx);
621       return;
622     }
623   typename This::Shdr strtabshdr(pshdrs + strtab_shndx * This::shdr_size);
624   if (strtabshdr.get_sh_type() != elfcpp::SHT_STRTAB)
625     {
626       this->error(_("symbol table name section has wrong type: %u"),
627                   static_cast<unsigned int>(strtabshdr.get_sh_type()));
628       return;
629     }
630
631   // Read the symbol names.
632   File_view* fvstrtab = this->get_lasting_view(strtabshdr.get_sh_offset(),
633                                                strtabshdr.get_sh_size(),
634                                                false, true);
635
636   sd->symbols = fvsymtab;
637   sd->symbols_size = readsize;
638   sd->external_symbols_offset = this->has_eh_frame_ ? locsize : 0;
639   sd->symbol_names = fvstrtab;
640   sd->symbol_names_size =
641     convert_to_section_size_type(strtabshdr.get_sh_size());
642 }
643
644 // Return the section index of symbol SYM.  Set *VALUE to its value in
645 // the object file.  Set *IS_ORDINARY if this is an ordinary section
646 // index.  not a special cod between SHN_LORESERVE and SHN_HIRESERVE.
647 // Note that for a symbol which is not defined in this object file,
648 // this will set *VALUE to 0 and return SHN_UNDEF; it will not return
649 // the final value of the symbol in the link.
650
651 template<int size, bool big_endian>
652 unsigned int
653 Sized_relobj<size, big_endian>::symbol_section_and_value(unsigned int sym,
654                                                          Address* value,
655                                                          bool* is_ordinary)
656 {
657   section_size_type symbols_size;
658   const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
659                                                         &symbols_size,
660                                                         false);
661
662   const size_t count = symbols_size / This::sym_size;
663   gold_assert(sym < count);
664
665   elfcpp::Sym<size, big_endian> elfsym(symbols + sym * This::sym_size);
666   *value = elfsym.get_st_value();
667
668   return this->adjust_sym_shndx(sym, elfsym.get_st_shndx(), is_ordinary);
669 }
670
671 // Return whether to include a section group in the link.  LAYOUT is
672 // used to keep track of which section groups we have already seen.
673 // INDEX is the index of the section group and SHDR is the section
674 // header.  If we do not want to include this group, we set bits in
675 // OMIT for each section which should be discarded.
676
677 template<int size, bool big_endian>
678 bool
679 Sized_relobj<size, big_endian>::include_section_group(
680     Symbol_table* symtab,
681     Layout* layout,
682     unsigned int index,
683     const char* name,
684     const unsigned char* shdrs,
685     const char* section_names,
686     section_size_type section_names_size,
687     std::vector<bool>* omit)
688 {
689   // Read the section contents.
690   typename This::Shdr shdr(shdrs + index * This::shdr_size);
691   const unsigned char* pcon = this->get_view(shdr.get_sh_offset(),
692                                              shdr.get_sh_size(), true, false);
693   const elfcpp::Elf_Word* pword =
694     reinterpret_cast<const elfcpp::Elf_Word*>(pcon);
695
696   // The first word contains flags.  We only care about COMDAT section
697   // groups.  Other section groups are always included in the link
698   // just like ordinary sections.
699   elfcpp::Elf_Word flags = elfcpp::Swap<32, big_endian>::readval(pword);
700
701   // Look up the group signature, which is the name of a symbol.  This
702   // is a lot of effort to go to to read a string.  Why didn't they
703   // just have the group signature point into the string table, rather
704   // than indirect through a symbol?
705
706   // Get the appropriate symbol table header (this will normally be
707   // the single SHT_SYMTAB section, but in principle it need not be).
708   const unsigned int link = this->adjust_shndx(shdr.get_sh_link());
709   typename This::Shdr symshdr(this, this->elf_file_.section_header(link));
710
711   // Read the symbol table entry.
712   unsigned int symndx = shdr.get_sh_info();
713   if (symndx >= symshdr.get_sh_size() / This::sym_size)
714     {
715       this->error(_("section group %u info %u out of range"),
716                   index, symndx);
717       return false;
718     }
719   off_t symoff = symshdr.get_sh_offset() + symndx * This::sym_size;
720   const unsigned char* psym = this->get_view(symoff, This::sym_size, true,
721                                              false);
722   elfcpp::Sym<size, big_endian> sym(psym);
723
724   // Read the symbol table names.
725   section_size_type symnamelen;
726   const unsigned char* psymnamesu;
727   psymnamesu = this->section_contents(this->adjust_shndx(symshdr.get_sh_link()),
728                                       &symnamelen, true);
729   const char* psymnames = reinterpret_cast<const char*>(psymnamesu);
730
731   // Get the section group signature.
732   if (sym.get_st_name() >= symnamelen)
733     {
734       this->error(_("symbol %u name offset %u out of range"),
735                   symndx, sym.get_st_name());
736       return false;
737     }
738
739   std::string signature(psymnames + sym.get_st_name());
740
741   // It seems that some versions of gas will create a section group
742   // associated with a section symbol, and then fail to give a name to
743   // the section symbol.  In such a case, use the name of the section.
744   if (signature[0] == '\0' && sym.get_st_type() == elfcpp::STT_SECTION)
745     {
746       bool is_ordinary;
747       unsigned int sym_shndx = this->adjust_sym_shndx(symndx,
748                                                       sym.get_st_shndx(),
749                                                       &is_ordinary);
750       if (!is_ordinary || sym_shndx >= this->shnum())
751         {
752           this->error(_("symbol %u invalid section index %u"),
753                       symndx, sym_shndx);
754           return false;
755         }
756       typename This::Shdr member_shdr(shdrs + sym_shndx * This::shdr_size);
757       if (member_shdr.get_sh_name() < section_names_size)
758         signature = section_names + member_shdr.get_sh_name();
759     }
760
761   // Record this section group in the layout, and see whether we've already
762   // seen one with the same signature.
763   bool include_group;
764   bool is_comdat;
765   Kept_section* kept_section = NULL;
766
767   if ((flags & elfcpp::GRP_COMDAT) == 0)
768     {
769       include_group = true;
770       is_comdat = false;
771     }
772   else
773     {
774       include_group = layout->find_or_add_kept_section(signature,
775                                                        this, index, true,
776                                                        true, &kept_section);
777       is_comdat = true;
778     }
779
780   size_t count = shdr.get_sh_size() / sizeof(elfcpp::Elf_Word);
781
782   std::vector<unsigned int> shndxes;
783   bool relocate_group = include_group && parameters->options().relocatable();
784   if (relocate_group)
785     shndxes.reserve(count - 1);
786
787   for (size_t i = 1; i < count; ++i)
788     {
789       elfcpp::Elf_Word shndx =
790         this->adjust_shndx(elfcpp::Swap<32, big_endian>::readval(pword + i));
791
792       if (relocate_group)
793         shndxes.push_back(shndx);
794
795       if (shndx >= this->shnum())
796         {
797           this->error(_("section %u in section group %u out of range"),
798                       shndx, index);
799           continue;
800         }
801
802       // Check for an earlier section number, since we're going to get
803       // it wrong--we may have already decided to include the section.
804       if (shndx < index)
805         this->error(_("invalid section group %u refers to earlier section %u"),
806                     index, shndx);
807
808       // Get the name of the member section.
809       typename This::Shdr member_shdr(shdrs + shndx * This::shdr_size);
810       if (member_shdr.get_sh_name() >= section_names_size)
811         {
812           // This is an error, but it will be diagnosed eventually
813           // in do_layout, so we don't need to do anything here but
814           // ignore it.
815           continue;
816         }
817       std::string mname(section_names + member_shdr.get_sh_name());
818
819       if (include_group)
820         {
821           if (is_comdat)
822             kept_section->add_comdat_section(mname, shndx,
823                                              member_shdr.get_sh_size());
824         }
825       else
826         {
827           (*omit)[shndx] = true;
828
829           if (is_comdat)
830             {
831               Relobj* kept_object = kept_section->object();
832               if (kept_section->is_comdat())
833                 {
834                   // Find the corresponding kept section, and store
835                   // that info in the discarded section table.
836                   unsigned int kept_shndx;
837                   uint64_t kept_size;
838                   if (kept_section->find_comdat_section(mname, &kept_shndx,
839                                                         &kept_size))
840                     {
841                       // We don't keep a mapping for this section if
842                       // it has a different size.  The mapping is only
843                       // used for relocation processing, and we don't
844                       // want to treat the sections as similar if the
845                       // sizes are different.  Checking the section
846                       // size is the approach used by the GNU linker.
847                       if (kept_size == member_shdr.get_sh_size())
848                         this->set_kept_comdat_section(shndx, kept_object,
849                                                       kept_shndx);
850                     }
851                 }
852               else
853                 {
854                   // The existing section is a linkonce section.  Add
855                   // a mapping if there is exactly one section in the
856                   // group (which is true when COUNT == 2) and if it
857                   // is the same size.
858                   if (count == 2
859                       && (kept_section->linkonce_size()
860                           == member_shdr.get_sh_size()))
861                     this->set_kept_comdat_section(shndx, kept_object,
862                                                   kept_section->shndx());
863                 }
864             }
865         }
866     }
867
868   if (relocate_group)
869     layout->layout_group(symtab, this, index, name, signature.c_str(),
870                          shdr, flags, &shndxes);
871
872   return include_group;
873 }
874
875 // Whether to include a linkonce section in the link.  NAME is the
876 // name of the section and SHDR is the section header.
877
878 // Linkonce sections are a GNU extension implemented in the original
879 // GNU linker before section groups were defined.  The semantics are
880 // that we only include one linkonce section with a given name.  The
881 // name of a linkonce section is normally .gnu.linkonce.T.SYMNAME,
882 // where T is the type of section and SYMNAME is the name of a symbol.
883 // In an attempt to make linkonce sections interact well with section
884 // groups, we try to identify SYMNAME and use it like a section group
885 // signature.  We want to block section groups with that signature,
886 // but not other linkonce sections with that signature.  We also use
887 // the full name of the linkonce section as a normal section group
888 // signature.
889
890 template<int size, bool big_endian>
891 bool
892 Sized_relobj<size, big_endian>::include_linkonce_section(
893     Layout* layout,
894     unsigned int index,
895     const char* name,
896     const elfcpp::Shdr<size, big_endian>& shdr)
897 {
898   typename elfcpp::Elf_types<size>::Elf_WXword sh_size = shdr.get_sh_size();
899   // In general the symbol name we want will be the string following
900   // the last '.'.  However, we have to handle the case of
901   // .gnu.linkonce.t.__i686.get_pc_thunk.bx, which was generated by
902   // some versions of gcc.  So we use a heuristic: if the name starts
903   // with ".gnu.linkonce.t.", we use everything after that.  Otherwise
904   // we look for the last '.'.  We can't always simply skip
905   // ".gnu.linkonce.X", because we have to deal with cases like
906   // ".gnu.linkonce.d.rel.ro.local".
907   const char* const linkonce_t = ".gnu.linkonce.t.";
908   const char* symname;
909   if (strncmp(name, linkonce_t, strlen(linkonce_t)) == 0)
910     symname = name + strlen(linkonce_t);
911   else
912     symname = strrchr(name, '.') + 1;
913   std::string sig1(symname);
914   std::string sig2(name);
915   Kept_section* kept1;
916   Kept_section* kept2;
917   bool include1 = layout->find_or_add_kept_section(sig1, this, index, false,
918                                                    false, &kept1);
919   bool include2 = layout->find_or_add_kept_section(sig2, this, index, false,
920                                                    true, &kept2);
921
922   if (!include2)
923     {
924       // We are not including this section because we already saw the
925       // name of the section as a signature.  This normally implies
926       // that the kept section is another linkonce section.  If it is
927       // the same size, record it as the section which corresponds to
928       // this one.
929       if (kept2->object() != NULL
930           && !kept2->is_comdat()
931           && kept2->linkonce_size() == sh_size)
932         this->set_kept_comdat_section(index, kept2->object(), kept2->shndx());
933     }
934   else if (!include1)
935     {
936       // The section is being discarded on the basis of its symbol
937       // name.  This means that the corresponding kept section was
938       // part of a comdat group, and it will be difficult to identify
939       // the specific section within that group that corresponds to
940       // this linkonce section.  We'll handle the simple case where
941       // the group has only one member section.  Otherwise, it's not
942       // worth the effort.
943       unsigned int kept_shndx;
944       uint64_t kept_size;
945       if (kept1->object() != NULL
946           && kept1->is_comdat()
947           && kept1->find_single_comdat_section(&kept_shndx, &kept_size)
948           && kept_size == sh_size)
949         this->set_kept_comdat_section(index, kept1->object(), kept_shndx);
950     }
951   else
952     {
953       kept1->set_linkonce_size(sh_size);
954       kept2->set_linkonce_size(sh_size);
955     }
956
957   return include1 && include2;
958 }
959
960 // Layout an input section.
961
962 template<int size, bool big_endian>
963 inline void
964 Sized_relobj<size, big_endian>::layout_section(Layout* layout,
965                                                unsigned int shndx,
966                                                const char* name,
967                                                typename This::Shdr& shdr,
968                                                unsigned int reloc_shndx,
969                                                unsigned int reloc_type)
970 {
971   off_t offset;
972   Output_section* os = layout->layout(this, shndx, name, shdr,
973                                           reloc_shndx, reloc_type, &offset);
974
975   this->output_sections()[shndx] = os;
976   if (offset == -1)
977     this->section_offsets_[shndx] = invalid_address;
978   else
979     this->section_offsets_[shndx] = convert_types<Address, off_t>(offset);
980
981   // If this section requires special handling, and if there are
982   // relocs that apply to it, then we must do the special handling
983   // before we apply the relocs.
984   if (offset == -1 && reloc_shndx != 0)
985     this->set_relocs_must_follow_section_writes();
986 }
987
988 // Lay out the input sections.  We walk through the sections and check
989 // whether they should be included in the link.  If they should, we
990 // pass them to the Layout object, which will return an output section
991 // and an offset.  
992 // During garbage collection (--gc-sections) and identical code folding 
993 // (--icf), this function is called twice.  When it is called the first 
994 // time, it is for setting up some sections as roots to a work-list for
995 // --gc-sections and to do comdat processing.  Actual layout happens the 
996 // second time around after all the relevant sections have been determined.  
997 // The first time, is_worklist_ready or is_icf_ready is false. It is then 
998 // set to true after the garbage collection worklist or identical code 
999 // folding is processed and the relevant sections to be kept are 
1000 // determined.  Then, this function is called again to layout the sections.
1001
1002 template<int size, bool big_endian>
1003 void
1004 Sized_relobj<size, big_endian>::do_layout(Symbol_table* symtab,
1005                                           Layout* layout,
1006                                           Read_symbols_data* sd)
1007 {
1008   const unsigned int shnum = this->shnum();
1009   bool is_gc_pass_one = ((parameters->options().gc_sections() 
1010                           && !symtab->gc()->is_worklist_ready())
1011                          || (parameters->options().icf_enabled()
1012                              && !symtab->icf()->is_icf_ready()));
1013  
1014   bool is_gc_pass_two = ((parameters->options().gc_sections() 
1015                           && symtab->gc()->is_worklist_ready())
1016                          || (parameters->options().icf_enabled()
1017                              && symtab->icf()->is_icf_ready()));
1018
1019   bool is_gc_or_icf = (parameters->options().gc_sections()
1020                        || parameters->options().icf_enabled()); 
1021
1022   // Both is_gc_pass_one and is_gc_pass_two should not be true.
1023   gold_assert(!(is_gc_pass_one  && is_gc_pass_two));
1024
1025   if (shnum == 0)
1026     return;
1027   Symbols_data* gc_sd = NULL;
1028   if (is_gc_pass_one)
1029     {
1030       // During garbage collection save the symbols data to use it when 
1031       // re-entering this function.   
1032       gc_sd = new Symbols_data;
1033       this->copy_symbols_data(gc_sd, sd, This::shdr_size * shnum);
1034       this->set_symbols_data(gc_sd);
1035     }
1036   else if (is_gc_pass_two)
1037     {
1038       gc_sd = this->get_symbols_data();
1039     }
1040
1041   const unsigned char* section_headers_data = NULL;
1042   section_size_type section_names_size;
1043   const unsigned char* symbols_data = NULL;
1044   section_size_type symbols_size;
1045   section_offset_type external_symbols_offset;
1046   const unsigned char* symbol_names_data = NULL;
1047   section_size_type symbol_names_size;
1048  
1049   if (is_gc_or_icf)
1050     {
1051       section_headers_data = gc_sd->section_headers_data;
1052       section_names_size = gc_sd->section_names_size;
1053       symbols_data = gc_sd->symbols_data;
1054       symbols_size = gc_sd->symbols_size;
1055       external_symbols_offset = gc_sd->external_symbols_offset;
1056       symbol_names_data = gc_sd->symbol_names_data;
1057       symbol_names_size = gc_sd->symbol_names_size;
1058     }
1059   else
1060     {
1061       section_headers_data = sd->section_headers->data();
1062       section_names_size = sd->section_names_size;
1063       if (sd->symbols != NULL)
1064         symbols_data = sd->symbols->data();
1065       symbols_size = sd->symbols_size;
1066       external_symbols_offset = sd->external_symbols_offset;
1067       if (sd->symbol_names != NULL)
1068         symbol_names_data = sd->symbol_names->data();
1069       symbol_names_size = sd->symbol_names_size;
1070     }
1071
1072   // Get the section headers.
1073   const unsigned char* shdrs = section_headers_data;
1074   const unsigned char* pshdrs;
1075
1076   // Get the section names.
1077   const unsigned char* pnamesu = (is_gc_or_icf) 
1078                                  ? gc_sd->section_names_data
1079                                  : sd->section_names->data();
1080
1081   const char* pnames = reinterpret_cast<const char*>(pnamesu);
1082
1083   // If any input files have been claimed by plugins, we need to defer
1084   // actual layout until the replacement files have arrived.
1085   const bool should_defer_layout =
1086       (parameters->options().has_plugins()
1087        && parameters->options().plugins()->should_defer_layout());
1088   unsigned int num_sections_to_defer = 0;
1089
1090   // For each section, record the index of the reloc section if any.
1091   // Use 0 to mean that there is no reloc section, -1U to mean that
1092   // there is more than one.
1093   std::vector<unsigned int> reloc_shndx(shnum, 0);
1094   std::vector<unsigned int> reloc_type(shnum, elfcpp::SHT_NULL);
1095   // Skip the first, dummy, section.
1096   pshdrs = shdrs + This::shdr_size;
1097   for (unsigned int i = 1; i < shnum; ++i, pshdrs += This::shdr_size)
1098     {
1099       typename This::Shdr shdr(pshdrs);
1100
1101       // Count the number of sections whose layout will be deferred.
1102       if (should_defer_layout && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC))
1103         ++num_sections_to_defer;
1104
1105       unsigned int sh_type = shdr.get_sh_type();
1106       if (sh_type == elfcpp::SHT_REL || sh_type == elfcpp::SHT_RELA)
1107         {
1108           unsigned int target_shndx = this->adjust_shndx(shdr.get_sh_info());
1109           if (target_shndx == 0 || target_shndx >= shnum)
1110             {
1111               this->error(_("relocation section %u has bad info %u"),
1112                           i, target_shndx);
1113               continue;
1114             }
1115
1116           if (reloc_shndx[target_shndx] != 0)
1117             reloc_shndx[target_shndx] = -1U;
1118           else
1119             {
1120               reloc_shndx[target_shndx] = i;
1121               reloc_type[target_shndx] = sh_type;
1122             }
1123         }
1124     }
1125
1126   Output_sections& out_sections(this->output_sections());
1127   std::vector<Address>& out_section_offsets(this->section_offsets_);
1128
1129   if (!is_gc_pass_two)
1130     {
1131       out_sections.resize(shnum);
1132       out_section_offsets.resize(shnum);
1133     }
1134
1135   // If we are only linking for symbols, then there is nothing else to
1136   // do here.
1137   if (this->input_file()->just_symbols())
1138     {
1139       if (!is_gc_pass_two)
1140         {
1141           delete sd->section_headers;
1142           sd->section_headers = NULL;
1143           delete sd->section_names;
1144           sd->section_names = NULL;
1145         }
1146       return;
1147     }
1148
1149   if (num_sections_to_defer > 0)
1150     {
1151       parameters->options().plugins()->add_deferred_layout_object(this);
1152       this->deferred_layout_.reserve(num_sections_to_defer);
1153     }
1154
1155   // Whether we've seen a .note.GNU-stack section.
1156   bool seen_gnu_stack = false;
1157   // The flags of a .note.GNU-stack section.
1158   uint64_t gnu_stack_flags = 0;
1159
1160   // Keep track of which sections to omit.
1161   std::vector<bool> omit(shnum, false);
1162
1163   // Keep track of reloc sections when emitting relocations.
1164   const bool relocatable = parameters->options().relocatable();
1165   const bool emit_relocs = (relocatable
1166                             || parameters->options().emit_relocs());
1167   std::vector<unsigned int> reloc_sections;
1168
1169   // Keep track of .eh_frame sections.
1170   std::vector<unsigned int> eh_frame_sections;
1171
1172   // Skip the first, dummy, section.
1173   pshdrs = shdrs + This::shdr_size;
1174   for (unsigned int i = 1; i < shnum; ++i, pshdrs += This::shdr_size)
1175     {
1176       typename This::Shdr shdr(pshdrs);
1177
1178       if (shdr.get_sh_name() >= section_names_size)
1179         {
1180           this->error(_("bad section name offset for section %u: %lu"),
1181                       i, static_cast<unsigned long>(shdr.get_sh_name()));
1182           return;
1183         }
1184
1185       const char* name = pnames + shdr.get_sh_name();
1186
1187       if (!is_gc_pass_two)
1188         { 
1189           if (this->handle_gnu_warning_section(name, i, symtab))
1190             { 
1191               if (!relocatable)
1192                 omit[i] = true;
1193             }
1194
1195           // The .note.GNU-stack section is special.  It gives the
1196           // protection flags that this object file requires for the stack
1197           // in memory.
1198           if (strcmp(name, ".note.GNU-stack") == 0)
1199             {
1200               seen_gnu_stack = true;
1201               gnu_stack_flags |= shdr.get_sh_flags();
1202               omit[i] = true;
1203             }
1204
1205           // The .note.GNU-split-stack section is also special.  It
1206           // indicates that the object was compiled with
1207           // -fsplit-stack.
1208           if (this->handle_split_stack_section(name))
1209             {
1210               if (!parameters->options().relocatable()
1211                   && !parameters->options().shared())
1212                 omit[i] = true;
1213             }
1214
1215           // Skip attributes section.
1216           if (parameters->target().is_attributes_section(name))
1217             {
1218               omit[i] = true;
1219             }
1220
1221           bool discard = omit[i];
1222           if (!discard)
1223             {
1224               if (shdr.get_sh_type() == elfcpp::SHT_GROUP)
1225                 {
1226                   if (!this->include_section_group(symtab, layout, i, name, 
1227                                                    shdrs, pnames, 
1228                                                    section_names_size,
1229                                                    &omit))
1230                     discard = true;
1231                 }
1232               else if ((shdr.get_sh_flags() & elfcpp::SHF_GROUP) == 0
1233                        && Layout::is_linkonce(name))
1234                 {
1235                   if (!this->include_linkonce_section(layout, i, name, shdr))
1236                     discard = true;
1237                 }
1238             }
1239
1240           if (discard)
1241             {
1242               // Do not include this section in the link.
1243               out_sections[i] = NULL;
1244               out_section_offsets[i] = invalid_address;
1245               continue;
1246             }
1247         }
1248  
1249       if (is_gc_pass_one && parameters->options().gc_sections())
1250         {
1251           if (is_section_name_included(name)
1252               || shdr.get_sh_type() == elfcpp::SHT_INIT_ARRAY 
1253               || shdr.get_sh_type() == elfcpp::SHT_FINI_ARRAY)
1254             {
1255               symtab->gc()->worklist().push(Section_id(this, i)); 
1256             }
1257           // If the section name XXX can be represented as a C identifier
1258           // it cannot be discarded if there are references to
1259           // __start_XXX and __stop_XXX symbols.  These need to be
1260           // specially handled.
1261           if (is_cident(name))
1262             {
1263               symtab->gc()->add_cident_section(name, Section_id(this, i));
1264             }
1265         }
1266
1267       // When doing a relocatable link we are going to copy input
1268       // reloc sections into the output.  We only want to copy the
1269       // ones associated with sections which are not being discarded.
1270       // However, we don't know that yet for all sections.  So save
1271       // reloc sections and process them later. Garbage collection is
1272       // not triggered when relocatable code is desired.
1273       if (emit_relocs
1274           && (shdr.get_sh_type() == elfcpp::SHT_REL
1275               || shdr.get_sh_type() == elfcpp::SHT_RELA))
1276         {
1277           reloc_sections.push_back(i);
1278           continue;
1279         }
1280
1281       if (relocatable && shdr.get_sh_type() == elfcpp::SHT_GROUP)
1282         continue;
1283
1284       // The .eh_frame section is special.  It holds exception frame
1285       // information that we need to read in order to generate the
1286       // exception frame header.  We process these after all the other
1287       // sections so that the exception frame reader can reliably
1288       // determine which sections are being discarded, and discard the
1289       // corresponding information.
1290       if (!relocatable
1291           && strcmp(name, ".eh_frame") == 0
1292           && this->check_eh_frame_flags(&shdr))
1293         {
1294           if (is_gc_pass_one)
1295             {
1296               out_sections[i] = reinterpret_cast<Output_section*>(1);
1297               out_section_offsets[i] = invalid_address;
1298             }
1299           else
1300             eh_frame_sections.push_back(i);
1301           continue;
1302         }
1303
1304       if (is_gc_pass_two && parameters->options().gc_sections())
1305         {
1306           // This is executed during the second pass of garbage 
1307           // collection. do_layout has been called before and some 
1308           // sections have been already discarded. Simply ignore 
1309           // such sections this time around.
1310           if (out_sections[i] == NULL)
1311             {
1312               gold_assert(out_section_offsets[i] == invalid_address);
1313               continue; 
1314             }
1315           if (((shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0)
1316               && symtab->gc()->is_section_garbage(this, i))
1317               {
1318                 if (parameters->options().print_gc_sections())
1319                   gold_info(_("%s: removing unused section from '%s'" 
1320                               " in file '%s'"),
1321                             program_name, this->section_name(i).c_str(), 
1322                             this->name().c_str());
1323                 out_sections[i] = NULL;
1324                 out_section_offsets[i] = invalid_address;
1325                 continue;
1326               }
1327         }
1328
1329       if (is_gc_pass_two && parameters->options().icf_enabled())
1330         {
1331           if (out_sections[i] == NULL)
1332             {
1333               gold_assert(out_section_offsets[i] == invalid_address);
1334               continue;
1335             }
1336           if (((shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0)
1337               && symtab->icf()->is_section_folded(this, i))
1338               {
1339                 if (parameters->options().print_icf_sections())
1340                   {
1341                     Section_id folded =
1342                                 symtab->icf()->get_folded_section(this, i);
1343                     Relobj* folded_obj =
1344                                 reinterpret_cast<Relobj*>(folded.first);
1345                     gold_info(_("%s: ICF folding section '%s' in file '%s'"
1346                                 "into '%s' in file '%s'"),
1347                               program_name, this->section_name(i).c_str(),
1348                               this->name().c_str(),
1349                               folded_obj->section_name(folded.second).c_str(),
1350                               folded_obj->name().c_str());
1351                   }
1352                 out_sections[i] = NULL;
1353                 out_section_offsets[i] = invalid_address;
1354                 continue;
1355               }
1356         }
1357
1358       // Defer layout here if input files are claimed by plugins.  When gc
1359       // is turned on this function is called twice.  For the second call
1360       // should_defer_layout should be false.
1361       if (should_defer_layout && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC))
1362         {
1363           gold_assert(!is_gc_pass_two);
1364           this->deferred_layout_.push_back(Deferred_layout(i, name, 
1365                                                            pshdrs,
1366                                                            reloc_shndx[i],
1367                                                            reloc_type[i]));
1368           // Put dummy values here; real values will be supplied by
1369           // do_layout_deferred_sections.
1370           out_sections[i] = reinterpret_cast<Output_section*>(2);
1371           out_section_offsets[i] = invalid_address;
1372           continue;
1373         }
1374
1375       // During gc_pass_two if a section that was previously deferred is
1376       // found, do not layout the section as layout_deferred_sections will
1377       // do it later from gold.cc.
1378       if (is_gc_pass_two 
1379           && (out_sections[i] == reinterpret_cast<Output_section*>(2)))
1380         continue;
1381
1382       if (is_gc_pass_one)
1383         {
1384           // This is during garbage collection. The out_sections are 
1385           // assigned in the second call to this function. 
1386           out_sections[i] = reinterpret_cast<Output_section*>(1);
1387           out_section_offsets[i] = invalid_address;
1388         }
1389       else
1390         {
1391           // When garbage collection is switched on the actual layout
1392           // only happens in the second call.
1393           this->layout_section(layout, i, name, shdr, reloc_shndx[i],
1394                                reloc_type[i]);
1395         }
1396     }
1397
1398   if (!is_gc_pass_two)
1399     layout->layout_gnu_stack(seen_gnu_stack, gnu_stack_flags);
1400
1401   // When doing a relocatable link handle the reloc sections at the
1402   // end.  Garbage collection  and Identical Code Folding is not 
1403   // turned on for relocatable code. 
1404   if (emit_relocs)
1405     this->size_relocatable_relocs();
1406
1407   gold_assert(!(is_gc_or_icf) || reloc_sections.empty());
1408
1409   for (std::vector<unsigned int>::const_iterator p = reloc_sections.begin();
1410        p != reloc_sections.end();
1411        ++p)
1412     {
1413       unsigned int i = *p;
1414       const unsigned char* pshdr;
1415       pshdr = section_headers_data + i * This::shdr_size;
1416       typename This::Shdr shdr(pshdr);
1417
1418       unsigned int data_shndx = this->adjust_shndx(shdr.get_sh_info());
1419       if (data_shndx >= shnum)
1420         {
1421           // We already warned about this above.
1422           continue;
1423         }
1424
1425       Output_section* data_section = out_sections[data_shndx];
1426       if (data_section == reinterpret_cast<Output_section*>(2))
1427         {
1428           // The layout for the data section was deferred, so we need
1429           // to defer the relocation section, too.
1430           const char* name = pnames + shdr.get_sh_name();
1431           this->deferred_layout_relocs_.push_back(
1432               Deferred_layout(i, name, pshdr, 0, elfcpp::SHT_NULL));
1433           out_sections[i] = reinterpret_cast<Output_section*>(2);
1434           out_section_offsets[i] = invalid_address;
1435           continue;
1436         }
1437       if (data_section == NULL)
1438         {
1439           out_sections[i] = NULL;
1440           out_section_offsets[i] = invalid_address;
1441           continue;
1442         }
1443
1444       Relocatable_relocs* rr = new Relocatable_relocs();
1445       this->set_relocatable_relocs(i, rr);
1446
1447       Output_section* os = layout->layout_reloc(this, i, shdr, data_section,
1448                                                 rr);
1449       out_sections[i] = os;
1450       out_section_offsets[i] = invalid_address;
1451     }
1452
1453   // Handle the .eh_frame sections at the end.
1454   gold_assert(!is_gc_pass_one || eh_frame_sections.empty());
1455   for (std::vector<unsigned int>::const_iterator p = eh_frame_sections.begin();
1456        p != eh_frame_sections.end();
1457        ++p)
1458     {
1459       gold_assert(this->has_eh_frame_);
1460       gold_assert(external_symbols_offset != 0);
1461
1462       unsigned int i = *p;
1463       const unsigned char *pshdr;
1464       pshdr = section_headers_data + i * This::shdr_size;
1465       typename This::Shdr shdr(pshdr);
1466
1467       off_t offset;
1468       Output_section* os = layout->layout_eh_frame(this,
1469                                                    symbols_data,
1470                                                    symbols_size,
1471                                                    symbol_names_data,
1472                                                    symbol_names_size,
1473                                                    i, shdr,
1474                                                    reloc_shndx[i],
1475                                                    reloc_type[i],
1476                                                    &offset);
1477       out_sections[i] = os;
1478       if (os == NULL || offset == -1)
1479         {
1480           // An object can contain at most one section holding exception
1481           // frame information.
1482           gold_assert(this->discarded_eh_frame_shndx_ == -1U);
1483           this->discarded_eh_frame_shndx_ = i;
1484           out_section_offsets[i] = invalid_address;
1485         }
1486       else
1487         out_section_offsets[i] = convert_types<Address, off_t>(offset);
1488
1489       // If this section requires special handling, and if there are
1490       // relocs that apply to it, then we must do the special handling
1491       // before we apply the relocs.
1492       if (os != NULL && offset == -1 && reloc_shndx[i] != 0)
1493         this->set_relocs_must_follow_section_writes();
1494     }
1495
1496   if (is_gc_pass_two)
1497     {
1498       delete[] gc_sd->section_headers_data;
1499       delete[] gc_sd->section_names_data;
1500       delete[] gc_sd->symbols_data;
1501       delete[] gc_sd->symbol_names_data;
1502       this->set_symbols_data(NULL);
1503     }
1504   else
1505     {
1506       delete sd->section_headers;
1507       sd->section_headers = NULL;
1508       delete sd->section_names;
1509       sd->section_names = NULL;
1510     }
1511 }
1512
1513 // Layout sections whose layout was deferred while waiting for
1514 // input files from a plugin.
1515
1516 template<int size, bool big_endian>
1517 void
1518 Sized_relobj<size, big_endian>::do_layout_deferred_sections(Layout* layout)
1519 {
1520   typename std::vector<Deferred_layout>::iterator deferred;
1521
1522   for (deferred = this->deferred_layout_.begin();
1523        deferred != this->deferred_layout_.end();
1524        ++deferred)
1525     {
1526       typename This::Shdr shdr(deferred->shdr_data_);
1527       // If the section is not included, it is because the garbage collector
1528       // decided it is not needed.  Avoid reverting that decision.
1529       if (!this->is_section_included(deferred->shndx_))
1530         continue;
1531
1532       this->layout_section(layout, deferred->shndx_, deferred->name_.c_str(),
1533                            shdr, deferred->reloc_shndx_, deferred->reloc_type_);
1534     }
1535
1536   this->deferred_layout_.clear();
1537
1538   // Now handle the deferred relocation sections.
1539
1540   Output_sections& out_sections(this->output_sections());
1541   std::vector<Address>& out_section_offsets(this->section_offsets_);
1542
1543   for (deferred = this->deferred_layout_relocs_.begin();
1544        deferred != this->deferred_layout_relocs_.end();
1545        ++deferred)
1546     {
1547       unsigned int shndx = deferred->shndx_;
1548       typename This::Shdr shdr(deferred->shdr_data_);
1549       unsigned int data_shndx = this->adjust_shndx(shdr.get_sh_info());
1550
1551       Output_section* data_section = out_sections[data_shndx];
1552       if (data_section == NULL)
1553         {
1554           out_sections[shndx] = NULL;
1555           out_section_offsets[shndx] = invalid_address;
1556           continue;
1557         }
1558
1559       Relocatable_relocs* rr = new Relocatable_relocs();
1560       this->set_relocatable_relocs(shndx, rr);
1561
1562       Output_section* os = layout->layout_reloc(this, shndx, shdr,
1563                                                 data_section, rr);
1564       out_sections[shndx] = os;
1565       out_section_offsets[shndx] = invalid_address;
1566     }
1567 }
1568
1569 // Add the symbols to the symbol table.
1570
1571 template<int size, bool big_endian>
1572 void
1573 Sized_relobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
1574                                                Read_symbols_data* sd,
1575                                                Layout*)
1576 {
1577   if (sd->symbols == NULL)
1578     {
1579       gold_assert(sd->symbol_names == NULL);
1580       return;
1581     }
1582
1583   const int sym_size = This::sym_size;
1584   size_t symcount = ((sd->symbols_size - sd->external_symbols_offset)
1585                      / sym_size);
1586   if (symcount * sym_size != sd->symbols_size - sd->external_symbols_offset)
1587     {
1588       this->error(_("size of symbols is not multiple of symbol size"));
1589       return;
1590     }
1591
1592   this->symbols_.resize(symcount);
1593
1594   const char* sym_names =
1595     reinterpret_cast<const char*>(sd->symbol_names->data());
1596   symtab->add_from_relobj(this,
1597                           sd->symbols->data() + sd->external_symbols_offset,
1598                           symcount, this->local_symbol_count_,
1599                           sym_names, sd->symbol_names_size,
1600                           &this->symbols_,
1601                           &this->defined_count_);
1602
1603   delete sd->symbols;
1604   sd->symbols = NULL;
1605   delete sd->symbol_names;
1606   sd->symbol_names = NULL;
1607 }
1608
1609 // Find out if this object, that is a member of a lib group, should be included
1610 // in the link. We check every symbol defined by this object. If the symbol
1611 // table has a strong undefined reference to that symbol, we have to include
1612 // the object.
1613
1614 template<int size, bool big_endian>
1615 Archive::Should_include
1616 Sized_relobj<size, big_endian>::do_should_include_member(Symbol_table* symtab,
1617                                                          Layout* layout,
1618                                                          Read_symbols_data* sd,
1619                                                          std::string* why)
1620 {
1621   char* tmpbuf = NULL;
1622   size_t tmpbuflen = 0;
1623   const char* sym_names =
1624       reinterpret_cast<const char*>(sd->symbol_names->data());
1625   const unsigned char* syms =
1626       sd->symbols->data() + sd->external_symbols_offset;
1627   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1628   size_t symcount = ((sd->symbols_size - sd->external_symbols_offset)
1629                          / sym_size);
1630
1631   const unsigned char* p = syms;
1632
1633   for (size_t i = 0; i < symcount; ++i, p += sym_size)
1634     {
1635       elfcpp::Sym<size, big_endian> sym(p);
1636       unsigned int st_shndx = sym.get_st_shndx();
1637       if (st_shndx == elfcpp::SHN_UNDEF)
1638         continue;
1639
1640       unsigned int st_name = sym.get_st_name();
1641       const char* name = sym_names + st_name;
1642       Symbol* symbol;
1643       Archive::Should_include t = Archive::should_include_member(symtab,
1644                                                                  layout,
1645                                                                  name,
1646                                                                  &symbol, why,
1647                                                                  &tmpbuf,
1648                                                                  &tmpbuflen);
1649       if (t == Archive::SHOULD_INCLUDE_YES)
1650         {
1651           if (tmpbuf != NULL)
1652             free(tmpbuf);
1653           return t;
1654         }
1655     }
1656   if (tmpbuf != NULL)
1657     free(tmpbuf);
1658   return Archive::SHOULD_INCLUDE_UNKNOWN;
1659 }
1660
1661 // First pass over the local symbols.  Here we add their names to
1662 // *POOL and *DYNPOOL, and we store the symbol value in
1663 // THIS->LOCAL_VALUES_.  This function is always called from a
1664 // singleton thread.  This is followed by a call to
1665 // finalize_local_symbols.
1666
1667 template<int size, bool big_endian>
1668 void
1669 Sized_relobj<size, big_endian>::do_count_local_symbols(Stringpool* pool,
1670                                                        Stringpool* dynpool)
1671 {
1672   gold_assert(this->symtab_shndx_ != -1U);
1673   if (this->symtab_shndx_ == 0)
1674     {
1675       // This object has no symbols.  Weird but legal.
1676       return;
1677     }
1678
1679   // Read the symbol table section header.
1680   const unsigned int symtab_shndx = this->symtab_shndx_;
1681   typename This::Shdr symtabshdr(this,
1682                                  this->elf_file_.section_header(symtab_shndx));
1683   gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
1684
1685   // Read the local symbols.
1686   const int sym_size = This::sym_size;
1687   const unsigned int loccount = this->local_symbol_count_;
1688   gold_assert(loccount == symtabshdr.get_sh_info());
1689   off_t locsize = loccount * sym_size;
1690   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
1691                                               locsize, true, true);
1692
1693   // Read the symbol names.
1694   const unsigned int strtab_shndx =
1695     this->adjust_shndx(symtabshdr.get_sh_link());
1696   section_size_type strtab_size;
1697   const unsigned char* pnamesu = this->section_contents(strtab_shndx,
1698                                                         &strtab_size,
1699                                                         true);
1700   const char* pnames = reinterpret_cast<const char*>(pnamesu);
1701
1702   // Loop over the local symbols.
1703
1704   const Output_sections& out_sections(this->output_sections());
1705   unsigned int shnum = this->shnum();
1706   unsigned int count = 0;
1707   unsigned int dyncount = 0;
1708   // Skip the first, dummy, symbol.
1709   psyms += sym_size;
1710   bool discard_all = parameters->options().discard_all();
1711   bool discard_locals = parameters->options().discard_locals();
1712   for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
1713     {
1714       elfcpp::Sym<size, big_endian> sym(psyms);
1715
1716       Symbol_value<size>& lv(this->local_values_[i]);
1717
1718       bool is_ordinary;
1719       unsigned int shndx = this->adjust_sym_shndx(i, sym.get_st_shndx(),
1720                                                   &is_ordinary);
1721       lv.set_input_shndx(shndx, is_ordinary);
1722
1723       if (sym.get_st_type() == elfcpp::STT_SECTION)
1724         lv.set_is_section_symbol();
1725       else if (sym.get_st_type() == elfcpp::STT_TLS)
1726         lv.set_is_tls_symbol();
1727
1728       // Save the input symbol value for use in do_finalize_local_symbols().
1729       lv.set_input_value(sym.get_st_value());
1730
1731       // Decide whether this symbol should go into the output file.
1732
1733       if ((shndx < shnum && out_sections[shndx] == NULL)
1734           || shndx == this->discarded_eh_frame_shndx_)
1735         {
1736           lv.set_no_output_symtab_entry();
1737           gold_assert(!lv.needs_output_dynsym_entry());
1738           continue;
1739         }
1740
1741       if (sym.get_st_type() == elfcpp::STT_SECTION)
1742         {
1743           lv.set_no_output_symtab_entry();
1744           gold_assert(!lv.needs_output_dynsym_entry());
1745           continue;
1746         }
1747
1748       if (sym.get_st_name() >= strtab_size)
1749         {
1750           this->error(_("local symbol %u section name out of range: %u >= %u"),
1751                       i, sym.get_st_name(),
1752                       static_cast<unsigned int>(strtab_size));
1753           lv.set_no_output_symtab_entry();
1754           continue;
1755         }
1756
1757       const char* name = pnames + sym.get_st_name();
1758
1759       // If needed, add the symbol to the dynamic symbol table string pool.
1760       if (lv.needs_output_dynsym_entry())
1761         {
1762           dynpool->add(name, true, NULL);
1763           ++dyncount;
1764         }
1765
1766       if (discard_all && lv.may_be_discarded_from_output_symtab())
1767         {
1768           lv.set_no_output_symtab_entry();
1769           continue;
1770         }
1771
1772       // If --discard-locals option is used, discard all temporary local
1773       // symbols.  These symbols start with system-specific local label
1774       // prefixes, typically .L for ELF system.  We want to be compatible
1775       // with GNU ld so here we essentially use the same check in
1776       // bfd_is_local_label().  The code is different because we already
1777       // know that:
1778       //
1779       //   - the symbol is local and thus cannot have global or weak binding.
1780       //   - the symbol is not a section symbol.
1781       //   - the symbol has a name.
1782       //
1783       // We do not discard a symbol if it needs a dynamic symbol entry.
1784       if (discard_locals
1785           && sym.get_st_type() != elfcpp::STT_FILE
1786           && !lv.needs_output_dynsym_entry()
1787           && lv.may_be_discarded_from_output_symtab()
1788           && parameters->target().is_local_label_name(name))
1789         {
1790           lv.set_no_output_symtab_entry();
1791           continue;
1792         }
1793
1794       // Discard the local symbol if -retain_symbols_file is specified
1795       // and the local symbol is not in that file.
1796       if (!parameters->options().should_retain_symbol(name))
1797         {
1798           lv.set_no_output_symtab_entry();
1799           continue;
1800         }
1801
1802       // Add the symbol to the symbol table string pool.
1803       pool->add(name, true, NULL);
1804       ++count;
1805     }
1806
1807   this->output_local_symbol_count_ = count;
1808   this->output_local_dynsym_count_ = dyncount;
1809 }
1810
1811 // Finalize the local symbols.  Here we set the final value in
1812 // THIS->LOCAL_VALUES_ and set their output symbol table indexes.
1813 // This function is always called from a singleton thread.  The actual
1814 // output of the local symbols will occur in a separate task.
1815
1816 template<int size, bool big_endian>
1817 unsigned int
1818 Sized_relobj<size, big_endian>::do_finalize_local_symbols(unsigned int index,
1819                                                           off_t off,
1820                                                           Symbol_table* symtab)
1821 {
1822   gold_assert(off == static_cast<off_t>(align_address(off, size >> 3)));
1823
1824   const unsigned int loccount = this->local_symbol_count_;
1825   this->local_symbol_offset_ = off;
1826
1827   const bool relocatable = parameters->options().relocatable();
1828   const Output_sections& out_sections(this->output_sections());
1829   const std::vector<Address>& out_offsets(this->section_offsets_);
1830   unsigned int shnum = this->shnum();
1831
1832   for (unsigned int i = 1; i < loccount; ++i)
1833     {
1834       Symbol_value<size>& lv(this->local_values_[i]);
1835
1836       bool is_ordinary;
1837       unsigned int shndx = lv.input_shndx(&is_ordinary);
1838
1839       // Set the output symbol value.
1840
1841       if (!is_ordinary)
1842         {
1843           if (shndx == elfcpp::SHN_ABS || Symbol::is_common_shndx(shndx))
1844             lv.set_output_value(lv.input_value());
1845           else
1846             {
1847               this->error(_("unknown section index %u for local symbol %u"),
1848                           shndx, i);
1849               lv.set_output_value(0);
1850             }
1851         }
1852       else
1853         {
1854           if (shndx >= shnum)
1855             {
1856               this->error(_("local symbol %u section index %u out of range"),
1857                           i, shndx);
1858               shndx = 0;
1859             }
1860
1861           Output_section* os = out_sections[shndx];
1862           Address secoffset = out_offsets[shndx];
1863           if (symtab->is_section_folded(this, shndx))
1864             {
1865               gold_assert (os == NULL && secoffset == invalid_address);
1866               // Get the os of the section it is folded onto.
1867               Section_id folded = symtab->icf()->get_folded_section(this,
1868                                                                     shndx);
1869               gold_assert(folded.first != NULL);
1870               Sized_relobj<size, big_endian>* folded_obj = reinterpret_cast
1871                 <Sized_relobj<size, big_endian>*>(folded.first);
1872               os = folded_obj->output_section(folded.second);
1873               gold_assert(os != NULL);
1874               secoffset = folded_obj->get_output_section_offset(folded.second);
1875
1876               // This could be a relaxed input section.
1877               if (secoffset == invalid_address)
1878                 {
1879                   const Output_relaxed_input_section* relaxed_section =
1880                     os->find_relaxed_input_section(folded_obj, folded.second);
1881                   gold_assert(relaxed_section != NULL);
1882                   secoffset = relaxed_section->address() - os->address();
1883                 }
1884             }
1885
1886           if (os == NULL)
1887             {
1888               // This local symbol belongs to a section we are discarding.
1889               // In some cases when applying relocations later, we will
1890               // attempt to match it to the corresponding kept section,
1891               // so we leave the input value unchanged here.
1892               continue;
1893             }
1894           else if (secoffset == invalid_address)
1895             {
1896               uint64_t start;
1897
1898               // This is a SHF_MERGE section or one which otherwise
1899               // requires special handling.
1900               if (shndx == this->discarded_eh_frame_shndx_)
1901                 {
1902                   // This local symbol belongs to a discarded .eh_frame
1903                   // section.  Just treat it like the case in which
1904                   // os == NULL above.
1905                   gold_assert(this->has_eh_frame_);
1906                   continue;
1907                 }
1908               else if (!lv.is_section_symbol())
1909                 {
1910                   // This is not a section symbol.  We can determine
1911                   // the final value now.
1912                   lv.set_output_value(os->output_address(this, shndx,
1913                                                          lv.input_value()));
1914                 }
1915               else if (!os->find_starting_output_address(this, shndx, &start))
1916                 {
1917                   // This is a section symbol, but apparently not one in a
1918                   // merged section.  First check to see if this is a relaxed
1919                   // input section.  If so, use its address.  Otherwise just
1920                   // use the start of the output section.  This happens with
1921                   // relocatable links when the input object has section
1922                   // symbols for arbitrary non-merge sections.
1923                   const Output_section_data* posd =
1924                     os->find_relaxed_input_section(this, shndx);
1925                   if (posd != NULL)
1926                     {
1927                       Address relocatable_link_adjustment =
1928                         relocatable ? os->address() : 0;
1929                       lv.set_output_value(posd->address()
1930                                           - relocatable_link_adjustment);
1931                     }
1932                   else
1933                     lv.set_output_value(os->address());
1934                 }
1935               else
1936                 {
1937                   // We have to consider the addend to determine the
1938                   // value to use in a relocation.  START is the start
1939                   // of this input section.  If we are doing a relocatable
1940                   // link, use offset from start output section instead of
1941                   // address.
1942                   Address adjusted_start =
1943                     relocatable ? start - os->address() : start;
1944                   Merged_symbol_value<size>* msv =
1945                     new Merged_symbol_value<size>(lv.input_value(),
1946                                                   adjusted_start);
1947                   lv.set_merged_symbol_value(msv);
1948                 }
1949             }
1950           else if (lv.is_tls_symbol())
1951             lv.set_output_value(os->tls_offset()
1952                                 + secoffset
1953                                 + lv.input_value());
1954           else
1955             lv.set_output_value((relocatable ? 0 : os->address())
1956                                 + secoffset
1957                                 + lv.input_value());
1958         }
1959
1960       if (!lv.is_output_symtab_index_set())
1961         {
1962           lv.set_output_symtab_index(index);
1963           ++index;
1964         }
1965     }
1966   return index;
1967 }
1968
1969 // Set the output dynamic symbol table indexes for the local variables.
1970
1971 template<int size, bool big_endian>
1972 unsigned int
1973 Sized_relobj<size, big_endian>::do_set_local_dynsym_indexes(unsigned int index)
1974 {
1975   const unsigned int loccount = this->local_symbol_count_;
1976   for (unsigned int i = 1; i < loccount; ++i)
1977     {
1978       Symbol_value<size>& lv(this->local_values_[i]);
1979       if (lv.needs_output_dynsym_entry())
1980         {
1981           lv.set_output_dynsym_index(index);
1982           ++index;
1983         }
1984     }
1985   return index;
1986 }
1987
1988 // Set the offset where local dynamic symbol information will be stored.
1989 // Returns the count of local symbols contributed to the symbol table by
1990 // this object.
1991
1992 template<int size, bool big_endian>
1993 unsigned int
1994 Sized_relobj<size, big_endian>::do_set_local_dynsym_offset(off_t off)
1995 {
1996   gold_assert(off == static_cast<off_t>(align_address(off, size >> 3)));
1997   this->local_dynsym_offset_ = off;
1998   return this->output_local_dynsym_count_;
1999 }
2000
2001 // If Symbols_data is not NULL get the section flags from here otherwise
2002 // get it from the file.
2003
2004 template<int size, bool big_endian>
2005 uint64_t
2006 Sized_relobj<size, big_endian>::do_section_flags(unsigned int shndx)
2007 {
2008   Symbols_data* sd = this->get_symbols_data();
2009   if (sd != NULL)
2010     {
2011       const unsigned char* pshdrs = sd->section_headers_data
2012                                     + This::shdr_size * shndx;
2013       typename This::Shdr shdr(pshdrs);
2014       return shdr.get_sh_flags(); 
2015     }
2016   // If sd is NULL, read the section header from the file.
2017   return this->elf_file_.section_flags(shndx); 
2018 }
2019
2020 // Get the section's ent size from Symbols_data.  Called by get_section_contents
2021 // in icf.cc
2022
2023 template<int size, bool big_endian>
2024 uint64_t
2025 Sized_relobj<size, big_endian>::do_section_entsize(unsigned int shndx)
2026 {
2027   Symbols_data* sd = this->get_symbols_data();
2028   gold_assert (sd != NULL);
2029
2030   const unsigned char* pshdrs = sd->section_headers_data
2031                                 + This::shdr_size * shndx;
2032   typename This::Shdr shdr(pshdrs);
2033   return shdr.get_sh_entsize(); 
2034 }
2035
2036
2037 // Write out the local symbols.
2038
2039 template<int size, bool big_endian>
2040 void
2041 Sized_relobj<size, big_endian>::write_local_symbols(
2042     Output_file* of,
2043     const Stringpool* sympool,
2044     const Stringpool* dynpool,
2045     Output_symtab_xindex* symtab_xindex,
2046     Output_symtab_xindex* dynsym_xindex)
2047 {
2048   const bool strip_all = parameters->options().strip_all();
2049   if (strip_all)
2050     {
2051       if (this->output_local_dynsym_count_ == 0)
2052         return;
2053       this->output_local_symbol_count_ = 0;
2054     }
2055
2056   gold_assert(this->symtab_shndx_ != -1U);
2057   if (this->symtab_shndx_ == 0)
2058     {
2059       // This object has no symbols.  Weird but legal.
2060       return;
2061     }
2062
2063   // Read the symbol table section header.
2064   const unsigned int symtab_shndx = this->symtab_shndx_;
2065   typename This::Shdr symtabshdr(this,
2066                                  this->elf_file_.section_header(symtab_shndx));
2067   gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
2068   const unsigned int loccount = this->local_symbol_count_;
2069   gold_assert(loccount == symtabshdr.get_sh_info());
2070
2071   // Read the local symbols.
2072   const int sym_size = This::sym_size;
2073   off_t locsize = loccount * sym_size;
2074   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
2075                                               locsize, true, false);
2076
2077   // Read the symbol names.
2078   const unsigned int strtab_shndx =
2079     this->adjust_shndx(symtabshdr.get_sh_link());
2080   section_size_type strtab_size;
2081   const unsigned char* pnamesu = this->section_contents(strtab_shndx,
2082                                                         &strtab_size,
2083                                                         false);
2084   const char* pnames = reinterpret_cast<const char*>(pnamesu);
2085
2086   // Get views into the output file for the portions of the symbol table
2087   // and the dynamic symbol table that we will be writing.
2088   off_t output_size = this->output_local_symbol_count_ * sym_size;
2089   unsigned char* oview = NULL;
2090   if (output_size > 0)
2091     oview = of->get_output_view(this->local_symbol_offset_, output_size);
2092
2093   off_t dyn_output_size = this->output_local_dynsym_count_ * sym_size;
2094   unsigned char* dyn_oview = NULL;
2095   if (dyn_output_size > 0)
2096     dyn_oview = of->get_output_view(this->local_dynsym_offset_,
2097                                     dyn_output_size);
2098
2099   const Output_sections out_sections(this->output_sections());
2100
2101   gold_assert(this->local_values_.size() == loccount);
2102
2103   unsigned char* ov = oview;
2104   unsigned char* dyn_ov = dyn_oview;
2105   psyms += sym_size;
2106   for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
2107     {
2108       elfcpp::Sym<size, big_endian> isym(psyms);
2109
2110       Symbol_value<size>& lv(this->local_values_[i]);
2111
2112       bool is_ordinary;
2113       unsigned int st_shndx = this->adjust_sym_shndx(i, isym.get_st_shndx(),
2114                                                      &is_ordinary);
2115       if (is_ordinary)
2116         {
2117           gold_assert(st_shndx < out_sections.size());
2118           if (out_sections[st_shndx] == NULL)
2119             continue;
2120           st_shndx = out_sections[st_shndx]->out_shndx();
2121           if (st_shndx >= elfcpp::SHN_LORESERVE)
2122             {
2123               if (lv.has_output_symtab_entry())
2124                 symtab_xindex->add(lv.output_symtab_index(), st_shndx);
2125               if (lv.has_output_dynsym_entry())
2126                 dynsym_xindex->add(lv.output_dynsym_index(), st_shndx);
2127               st_shndx = elfcpp::SHN_XINDEX;
2128             }
2129         }
2130
2131       // Write the symbol to the output symbol table.
2132       if (lv.has_output_symtab_entry())
2133         {
2134           elfcpp::Sym_write<size, big_endian> osym(ov);
2135
2136           gold_assert(isym.get_st_name() < strtab_size);
2137           const char* name = pnames + isym.get_st_name();
2138           osym.put_st_name(sympool->get_offset(name));
2139           osym.put_st_value(this->local_values_[i].value(this, 0));
2140           osym.put_st_size(isym.get_st_size());
2141           osym.put_st_info(isym.get_st_info());
2142           osym.put_st_other(isym.get_st_other());
2143           osym.put_st_shndx(st_shndx);
2144
2145           ov += sym_size;
2146         }
2147
2148       // Write the symbol to the output dynamic symbol table.
2149       if (lv.has_output_dynsym_entry())
2150         {
2151           gold_assert(dyn_ov < dyn_oview + dyn_output_size);
2152           elfcpp::Sym_write<size, big_endian> osym(dyn_ov);
2153
2154           gold_assert(isym.get_st_name() < strtab_size);
2155           const char* name = pnames + isym.get_st_name();
2156           osym.put_st_name(dynpool->get_offset(name));
2157           osym.put_st_value(this->local_values_[i].value(this, 0));
2158           osym.put_st_size(isym.get_st_size());
2159           osym.put_st_info(isym.get_st_info());
2160           osym.put_st_other(isym.get_st_other());
2161           osym.put_st_shndx(st_shndx);
2162
2163           dyn_ov += sym_size;
2164         }
2165     }
2166
2167
2168   if (output_size > 0)
2169     {
2170       gold_assert(ov - oview == output_size);
2171       of->write_output_view(this->local_symbol_offset_, output_size, oview);
2172     }
2173
2174   if (dyn_output_size > 0)
2175     {
2176       gold_assert(dyn_ov - dyn_oview == dyn_output_size);
2177       of->write_output_view(this->local_dynsym_offset_, dyn_output_size,
2178                             dyn_oview);
2179     }
2180 }
2181
2182 // Set *INFO to symbolic information about the offset OFFSET in the
2183 // section SHNDX.  Return true if we found something, false if we
2184 // found nothing.
2185
2186 template<int size, bool big_endian>
2187 bool
2188 Sized_relobj<size, big_endian>::get_symbol_location_info(
2189     unsigned int shndx,
2190     off_t offset,
2191     Symbol_location_info* info)
2192 {
2193   if (this->symtab_shndx_ == 0)
2194     return false;
2195
2196   section_size_type symbols_size;
2197   const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
2198                                                         &symbols_size,
2199                                                         false);
2200
2201   unsigned int symbol_names_shndx =
2202     this->adjust_shndx(this->section_link(this->symtab_shndx_));
2203   section_size_type names_size;
2204   const unsigned char* symbol_names_u =
2205     this->section_contents(symbol_names_shndx, &names_size, false);
2206   const char* symbol_names = reinterpret_cast<const char*>(symbol_names_u);
2207
2208   const int sym_size = This::sym_size;
2209   const size_t count = symbols_size / sym_size;
2210
2211   const unsigned char* p = symbols;
2212   for (size_t i = 0; i < count; ++i, p += sym_size)
2213     {
2214       elfcpp::Sym<size, big_endian> sym(p);
2215
2216       if (sym.get_st_type() == elfcpp::STT_FILE)
2217         {
2218           if (sym.get_st_name() >= names_size)
2219             info->source_file = "(invalid)";
2220           else
2221             info->source_file = symbol_names + sym.get_st_name();
2222           continue;
2223         }
2224
2225       bool is_ordinary;
2226       unsigned int st_shndx = this->adjust_sym_shndx(i, sym.get_st_shndx(),
2227                                                      &is_ordinary);
2228       if (is_ordinary
2229           && st_shndx == shndx
2230           && static_cast<off_t>(sym.get_st_value()) <= offset
2231           && (static_cast<off_t>(sym.get_st_value() + sym.get_st_size())
2232               > offset))
2233         {
2234           if (sym.get_st_name() > names_size)
2235             info->enclosing_symbol_name = "(invalid)";
2236           else
2237             {
2238               info->enclosing_symbol_name = symbol_names + sym.get_st_name();
2239               if (parameters->options().do_demangle())
2240                 {
2241                   char* demangled_name = cplus_demangle(
2242                       info->enclosing_symbol_name.c_str(),
2243                       DMGL_ANSI | DMGL_PARAMS);
2244                   if (demangled_name != NULL)
2245                     {
2246                       info->enclosing_symbol_name.assign(demangled_name);
2247                       free(demangled_name);
2248                     }
2249                 }
2250             }
2251           return true;
2252         }
2253     }
2254
2255   return false;
2256 }
2257
2258 // Look for a kept section corresponding to the given discarded section,
2259 // and return its output address.  This is used only for relocations in
2260 // debugging sections.  If we can't find the kept section, return 0.
2261
2262 template<int size, bool big_endian>
2263 typename Sized_relobj<size, big_endian>::Address
2264 Sized_relobj<size, big_endian>::map_to_kept_section(
2265     unsigned int shndx,
2266     bool* found) const
2267 {
2268   Relobj* kept_object;
2269   unsigned int kept_shndx;
2270   if (this->get_kept_comdat_section(shndx, &kept_object, &kept_shndx))
2271     {
2272       Sized_relobj<size, big_endian>* kept_relobj =
2273         static_cast<Sized_relobj<size, big_endian>*>(kept_object);
2274       Output_section* os = kept_relobj->output_section(kept_shndx);
2275       Address offset = kept_relobj->get_output_section_offset(kept_shndx);
2276       if (os != NULL && offset != invalid_address)
2277         {
2278           *found = true;
2279           return os->address() + offset;
2280         }
2281     }
2282   *found = false;
2283   return 0;
2284 }
2285
2286 // Get symbol counts.
2287
2288 template<int size, bool big_endian>
2289 void
2290 Sized_relobj<size, big_endian>::do_get_global_symbol_counts(
2291     const Symbol_table*,
2292     size_t* defined,
2293     size_t* used) const
2294 {
2295   *defined = this->defined_count_;
2296   size_t count = 0;
2297   for (Symbols::const_iterator p = this->symbols_.begin();
2298        p != this->symbols_.end();
2299        ++p)
2300     if (*p != NULL
2301         && (*p)->source() == Symbol::FROM_OBJECT
2302         && (*p)->object() == this
2303         && (*p)->is_defined())
2304       ++count;
2305   *used = count;
2306 }
2307
2308 // Input_objects methods.
2309
2310 // Add a regular relocatable object to the list.  Return false if this
2311 // object should be ignored.
2312
2313 bool
2314 Input_objects::add_object(Object* obj)
2315 {
2316   // Print the filename if the -t/--trace option is selected.
2317   if (parameters->options().trace())
2318     gold_info("%s", obj->name().c_str());
2319
2320   if (!obj->is_dynamic())
2321     this->relobj_list_.push_back(static_cast<Relobj*>(obj));
2322   else
2323     {
2324       // See if this is a duplicate SONAME.
2325       Dynobj* dynobj = static_cast<Dynobj*>(obj);
2326       const char* soname = dynobj->soname();
2327
2328       std::pair<Unordered_set<std::string>::iterator, bool> ins =
2329         this->sonames_.insert(soname);
2330       if (!ins.second)
2331         {
2332           // We have already seen a dynamic object with this soname.
2333           return false;
2334         }
2335
2336       this->dynobj_list_.push_back(dynobj);
2337     }
2338
2339   // Add this object to the cross-referencer if requested.
2340   if (parameters->options().user_set_print_symbol_counts()
2341       || parameters->options().cref())
2342     {
2343       if (this->cref_ == NULL)
2344         this->cref_ = new Cref();
2345       this->cref_->add_object(obj);
2346     }
2347
2348   return true;
2349 }
2350
2351 // For each dynamic object, record whether we've seen all of its
2352 // explicit dependencies.
2353
2354 void
2355 Input_objects::check_dynamic_dependencies() const
2356 {
2357   bool issued_copy_dt_needed_error = false;
2358   for (Dynobj_list::const_iterator p = this->dynobj_list_.begin();
2359        p != this->dynobj_list_.end();
2360        ++p)
2361     {
2362       const Dynobj::Needed& needed((*p)->needed());
2363       bool found_all = true;
2364       Dynobj::Needed::const_iterator pneeded;
2365       for (pneeded = needed.begin(); pneeded != needed.end(); ++pneeded)
2366         {
2367           if (this->sonames_.find(*pneeded) == this->sonames_.end())
2368             {
2369               found_all = false;
2370               break;
2371             }
2372         }
2373       (*p)->set_has_unknown_needed_entries(!found_all);
2374
2375       // --copy-dt-needed-entries aka --add-needed is a GNU ld option
2376       // that gold does not support.  However, they cause no trouble
2377       // unless there is a DT_NEEDED entry that we don't know about;
2378       // warn only in that case.
2379       if (!found_all
2380           && !issued_copy_dt_needed_error
2381           && (parameters->options().copy_dt_needed_entries()
2382               || parameters->options().add_needed()))
2383         {
2384           const char* optname;
2385           if (parameters->options().copy_dt_needed_entries())
2386             optname = "--copy-dt-needed-entries";
2387           else
2388             optname = "--add-needed";
2389           gold_error(_("%s is not supported but is required for %s in %s"),
2390                      optname, (*pneeded).c_str(), (*p)->name().c_str());
2391           issued_copy_dt_needed_error = true;
2392         }
2393     }
2394 }
2395
2396 // Start processing an archive.
2397
2398 void
2399 Input_objects::archive_start(Archive* archive)
2400 {
2401   if (parameters->options().user_set_print_symbol_counts()
2402       || parameters->options().cref())
2403     {
2404       if (this->cref_ == NULL)
2405         this->cref_ = new Cref();
2406       this->cref_->add_archive_start(archive);
2407     }
2408 }
2409
2410 // Stop processing an archive.
2411
2412 void
2413 Input_objects::archive_stop(Archive* archive)
2414 {
2415   if (parameters->options().user_set_print_symbol_counts()
2416       || parameters->options().cref())
2417     this->cref_->add_archive_stop(archive);
2418 }
2419
2420 // Print symbol counts
2421
2422 void
2423 Input_objects::print_symbol_counts(const Symbol_table* symtab) const
2424 {
2425   if (parameters->options().user_set_print_symbol_counts()
2426       && this->cref_ != NULL)
2427     this->cref_->print_symbol_counts(symtab);
2428 }
2429
2430 // Print a cross reference table.
2431
2432 void
2433 Input_objects::print_cref(const Symbol_table* symtab, FILE* f) const
2434 {
2435   if (parameters->options().cref() && this->cref_ != NULL)
2436     this->cref_->print_cref(symtab, f);
2437 }
2438
2439 // Relocate_info methods.
2440
2441 // Return a string describing the location of a relocation.  This is
2442 // only used in error messages.
2443
2444 template<int size, bool big_endian>
2445 std::string
2446 Relocate_info<size, big_endian>::location(size_t, off_t offset) const
2447 {
2448   // See if we can get line-number information from debugging sections.
2449   std::string filename;
2450   std::string file_and_lineno;   // Better than filename-only, if available.
2451
2452   Sized_dwarf_line_info<size, big_endian> line_info(this->object);
2453   // This will be "" if we failed to parse the debug info for any reason.
2454   file_and_lineno = line_info.addr2line(this->data_shndx, offset);
2455
2456   std::string ret(this->object->name());
2457   ret += ':';
2458   Symbol_location_info info;
2459   if (this->object->get_symbol_location_info(this->data_shndx, offset, &info))
2460     {
2461       ret += " in function ";
2462       ret += info.enclosing_symbol_name;
2463       ret += ":";
2464       filename = info.source_file;
2465     }
2466
2467   if (!file_and_lineno.empty())
2468     ret += file_and_lineno;
2469   else
2470     {
2471       if (!filename.empty())
2472         ret += filename;
2473       ret += "(";
2474       ret += this->object->section_name(this->data_shndx);
2475       char buf[100];
2476       // Offsets into sections have to be positive.
2477       snprintf(buf, sizeof(buf), "+0x%lx", static_cast<long>(offset));
2478       ret += buf;
2479       ret += ")";
2480     }
2481   return ret;
2482 }
2483
2484 } // End namespace gold.
2485
2486 namespace
2487 {
2488
2489 using namespace gold;
2490
2491 // Read an ELF file with the header and return the appropriate
2492 // instance of Object.
2493
2494 template<int size, bool big_endian>
2495 Object*
2496 make_elf_sized_object(const std::string& name, Input_file* input_file,
2497                       off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr,
2498                       bool* punconfigured)
2499 {
2500   Target* target = select_target(ehdr.get_e_machine(), size, big_endian,
2501                                  ehdr.get_e_ident()[elfcpp::EI_OSABI],
2502                                  ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
2503   if (target == NULL)
2504     gold_fatal(_("%s: unsupported ELF machine number %d"),
2505                name.c_str(), ehdr.get_e_machine());
2506
2507   if (!parameters->target_valid())
2508     set_parameters_target(target);
2509   else if (target != &parameters->target())
2510     {
2511       if (punconfigured != NULL)
2512         *punconfigured = true;
2513       else
2514         gold_error(_("%s: incompatible target"), name.c_str());
2515       return NULL;
2516     }
2517
2518   return target->make_elf_object<size, big_endian>(name, input_file, offset,
2519                                                    ehdr);
2520 }
2521
2522 } // End anonymous namespace.
2523
2524 namespace gold
2525 {
2526
2527 // Return whether INPUT_FILE is an ELF object.
2528
2529 bool
2530 is_elf_object(Input_file* input_file, off_t offset,
2531               const unsigned char** start, int *read_size)
2532 {
2533   off_t filesize = input_file->file().filesize();
2534   int want = elfcpp::Elf_recognizer::max_header_size;
2535   if (filesize - offset < want)
2536     want = filesize - offset;
2537
2538   const unsigned char* p = input_file->file().get_view(offset, 0, want,
2539                                                        true, false);
2540   *start = p;
2541   *read_size = want;
2542
2543   return elfcpp::Elf_recognizer::is_elf_file(p, want);
2544 }
2545
2546 // Read an ELF file and return the appropriate instance of Object.
2547
2548 Object*
2549 make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
2550                 const unsigned char* p, section_offset_type bytes,
2551                 bool* punconfigured)
2552 {
2553   if (punconfigured != NULL)
2554     *punconfigured = false;
2555
2556   std::string error;
2557   bool big_endian = false;
2558   int size = 0;
2559   if (!elfcpp::Elf_recognizer::is_valid_header(p, bytes, &size,
2560                                                &big_endian, &error))
2561     {
2562       gold_error(_("%s: %s"), name.c_str(), error.c_str());
2563       return NULL;
2564     }
2565
2566   if (size == 32)
2567     {
2568       if (big_endian)
2569         {
2570 #ifdef HAVE_TARGET_32_BIG
2571           elfcpp::Ehdr<32, true> ehdr(p);
2572           return make_elf_sized_object<32, true>(name, input_file,
2573                                                  offset, ehdr, punconfigured);
2574 #else
2575           if (punconfigured != NULL)
2576             *punconfigured = true;
2577           else
2578             gold_error(_("%s: not configured to support "
2579                          "32-bit big-endian object"),
2580                        name.c_str());
2581           return NULL;
2582 #endif
2583         }
2584       else
2585         {
2586 #ifdef HAVE_TARGET_32_LITTLE
2587           elfcpp::Ehdr<32, false> ehdr(p);
2588           return make_elf_sized_object<32, false>(name, input_file,
2589                                                   offset, ehdr, punconfigured);
2590 #else
2591           if (punconfigured != NULL)
2592             *punconfigured = true;
2593           else
2594             gold_error(_("%s: not configured to support "
2595                          "32-bit little-endian object"),
2596                        name.c_str());
2597           return NULL;
2598 #endif
2599         }
2600     }
2601   else if (size == 64)
2602     {
2603       if (big_endian)
2604         {
2605 #ifdef HAVE_TARGET_64_BIG
2606           elfcpp::Ehdr<64, true> ehdr(p);
2607           return make_elf_sized_object<64, true>(name, input_file,
2608                                                  offset, ehdr, punconfigured);
2609 #else
2610           if (punconfigured != NULL)
2611             *punconfigured = true;
2612           else
2613             gold_error(_("%s: not configured to support "
2614                          "64-bit big-endian object"),
2615                        name.c_str());
2616           return NULL;
2617 #endif
2618         }
2619       else
2620         {
2621 #ifdef HAVE_TARGET_64_LITTLE
2622           elfcpp::Ehdr<64, false> ehdr(p);
2623           return make_elf_sized_object<64, false>(name, input_file,
2624                                                   offset, ehdr, punconfigured);
2625 #else
2626           if (punconfigured != NULL)
2627             *punconfigured = true;
2628           else
2629             gold_error(_("%s: not configured to support "
2630                          "64-bit little-endian object"),
2631                        name.c_str());
2632           return NULL;
2633 #endif
2634         }
2635     }
2636   else
2637     gold_unreachable();
2638 }
2639
2640 // Instantiate the templates we need.
2641
2642 #ifdef HAVE_TARGET_32_LITTLE
2643 template
2644 void
2645 Object::read_section_data<32, false>(elfcpp::Elf_file<32, false, Object>*,
2646                                      Read_symbols_data*);
2647 #endif
2648
2649 #ifdef HAVE_TARGET_32_BIG
2650 template
2651 void
2652 Object::read_section_data<32, true>(elfcpp::Elf_file<32, true, Object>*,
2653                                     Read_symbols_data*);
2654 #endif
2655
2656 #ifdef HAVE_TARGET_64_LITTLE
2657 template
2658 void
2659 Object::read_section_data<64, false>(elfcpp::Elf_file<64, false, Object>*,
2660                                      Read_symbols_data*);
2661 #endif
2662
2663 #ifdef HAVE_TARGET_64_BIG
2664 template
2665 void
2666 Object::read_section_data<64, true>(elfcpp::Elf_file<64, true, Object>*,
2667                                     Read_symbols_data*);
2668 #endif
2669
2670 #ifdef HAVE_TARGET_32_LITTLE
2671 template
2672 class Sized_relobj<32, false>;
2673 #endif
2674
2675 #ifdef HAVE_TARGET_32_BIG
2676 template
2677 class Sized_relobj<32, true>;
2678 #endif
2679
2680 #ifdef HAVE_TARGET_64_LITTLE
2681 template
2682 class Sized_relobj<64, false>;
2683 #endif
2684
2685 #ifdef HAVE_TARGET_64_BIG
2686 template
2687 class Sized_relobj<64, true>;
2688 #endif
2689
2690 #ifdef HAVE_TARGET_32_LITTLE
2691 template
2692 struct Relocate_info<32, false>;
2693 #endif
2694
2695 #ifdef HAVE_TARGET_32_BIG
2696 template
2697 struct Relocate_info<32, true>;
2698 #endif
2699
2700 #ifdef HAVE_TARGET_64_LITTLE
2701 template
2702 struct Relocate_info<64, false>;
2703 #endif
2704
2705 #ifdef HAVE_TARGET_64_BIG
2706 template
2707 struct Relocate_info<64, true>;
2708 #endif
2709
2710 #ifdef HAVE_TARGET_32_LITTLE
2711 template
2712 void
2713 Xindex::initialize_symtab_xindex<32, false>(Object*, unsigned int);
2714
2715 template
2716 void
2717 Xindex::read_symtab_xindex<32, false>(Object*, unsigned int,
2718                                       const unsigned char*);
2719 #endif
2720
2721 #ifdef HAVE_TARGET_32_BIG
2722 template
2723 void
2724 Xindex::initialize_symtab_xindex<32, true>(Object*, unsigned int);
2725
2726 template
2727 void
2728 Xindex::read_symtab_xindex<32, true>(Object*, unsigned int,
2729                                      const unsigned char*);
2730 #endif
2731
2732 #ifdef HAVE_TARGET_64_LITTLE
2733 template
2734 void
2735 Xindex::initialize_symtab_xindex<64, false>(Object*, unsigned int);
2736
2737 template
2738 void
2739 Xindex::read_symtab_xindex<64, false>(Object*, unsigned int,
2740                                       const unsigned char*);
2741 #endif
2742
2743 #ifdef HAVE_TARGET_64_BIG
2744 template
2745 void
2746 Xindex::initialize_symtab_xindex<64, true>(Object*, unsigned int);
2747
2748 template
2749 void
2750 Xindex::read_symtab_xindex<64, true>(Object*, unsigned int,
2751                                      const unsigned char*);
2752 #endif
2753
2754 } // End namespace gold.
This page took 0.177098 seconds and 4 git commands to generate.