daily update
[deliverable/binutils-gdb.git] / gold / output.cc
CommitLineData
a2fb1b05
ILT
1// output.cc -- manage the output file for gold
2
6cb15b7f
ILT
3// Copyright 2006, 2007 Free Software Foundation, Inc.
4// Written by Ian Lance Taylor <iant@google.com>.
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
a2fb1b05
ILT
23#include "gold.h"
24
25#include <cstdlib>
61ba1cf9
ILT
26#include <cerrno>
27#include <fcntl.h>
28#include <unistd.h>
29#include <sys/mman.h>
4e9d8586 30#include <sys/stat.h>
75f65a3e 31#include <algorithm>
5ffcaa86 32#include "libiberty.h" // for unlink_if_ordinary()
a2fb1b05 33
7e1edb90 34#include "parameters.h"
a2fb1b05 35#include "object.h"
ead1e424
ILT
36#include "symtab.h"
37#include "reloc.h"
b8e6aad9 38#include "merge.h"
a2fb1b05
ILT
39#include "output.h"
40
c420411f
ILT
41// Some BSD systems still use MAP_ANON instead of MAP_ANONYMOUS
42#ifndef MAP_ANONYMOUS
43# define MAP_ANONYMOUS MAP_ANON
44#endif
45
a2fb1b05
ILT
46namespace gold
47{
48
a3ad94ed
ILT
49// Output_data variables.
50
27bc2bce 51bool Output_data::allocated_sizes_are_fixed;
a3ad94ed 52
a2fb1b05
ILT
53// Output_data methods.
54
55Output_data::~Output_data()
56{
57}
58
730cdc88
ILT
59// Return the default alignment for the target size.
60
61uint64_t
62Output_data::default_alignment()
63{
64 return Output_data::default_alignment_for_size(parameters->get_size());
65}
66
75f65a3e
ILT
67// Return the default alignment for a size--32 or 64.
68
69uint64_t
730cdc88 70Output_data::default_alignment_for_size(int size)
75f65a3e
ILT
71{
72 if (size == 32)
73 return 4;
74 else if (size == 64)
75 return 8;
76 else
a3ad94ed 77 gold_unreachable();
75f65a3e
ILT
78}
79
75f65a3e
ILT
80// Output_section_header methods. This currently assumes that the
81// segment and section lists are complete at construction time.
82
83Output_section_headers::Output_section_headers(
16649710
ILT
84 const Layout* layout,
85 const Layout::Segment_list* segment_list,
86 const Layout::Section_list* unattached_section_list,
61ba1cf9 87 const Stringpool* secnamepool)
9025d29d 88 : layout_(layout),
75f65a3e 89 segment_list_(segment_list),
a3ad94ed 90 unattached_section_list_(unattached_section_list),
61ba1cf9 91 secnamepool_(secnamepool)
75f65a3e 92{
61ba1cf9
ILT
93 // Count all the sections. Start with 1 for the null section.
94 off_t count = 1;
16649710
ILT
95 for (Layout::Segment_list::const_iterator p = segment_list->begin();
96 p != segment_list->end();
75f65a3e 97 ++p)
ead1e424
ILT
98 if ((*p)->type() == elfcpp::PT_LOAD)
99 count += (*p)->output_section_count();
16649710 100 count += unattached_section_list->size();
75f65a3e 101
9025d29d 102 const int size = parameters->get_size();
75f65a3e
ILT
103 int shdr_size;
104 if (size == 32)
105 shdr_size = elfcpp::Elf_sizes<32>::shdr_size;
106 else if (size == 64)
107 shdr_size = elfcpp::Elf_sizes<64>::shdr_size;
108 else
a3ad94ed 109 gold_unreachable();
75f65a3e
ILT
110
111 this->set_data_size(count * shdr_size);
112}
113
61ba1cf9
ILT
114// Write out the section headers.
115
75f65a3e 116void
61ba1cf9 117Output_section_headers::do_write(Output_file* of)
a2fb1b05 118{
9025d29d 119 if (parameters->get_size() == 32)
61ba1cf9 120 {
9025d29d
ILT
121 if (parameters->is_big_endian())
122 {
123#ifdef HAVE_TARGET_32_BIG
124 this->do_sized_write<32, true>(of);
125#else
126 gold_unreachable();
127#endif
128 }
61ba1cf9 129 else
9025d29d
ILT
130 {
131#ifdef HAVE_TARGET_32_LITTLE
132 this->do_sized_write<32, false>(of);
133#else
134 gold_unreachable();
135#endif
136 }
61ba1cf9 137 }
9025d29d 138 else if (parameters->get_size() == 64)
61ba1cf9 139 {
9025d29d
ILT
140 if (parameters->is_big_endian())
141 {
142#ifdef HAVE_TARGET_64_BIG
143 this->do_sized_write<64, true>(of);
144#else
145 gold_unreachable();
146#endif
147 }
61ba1cf9 148 else
9025d29d
ILT
149 {
150#ifdef HAVE_TARGET_64_LITTLE
151 this->do_sized_write<64, false>(of);
152#else
153 gold_unreachable();
154#endif
155 }
61ba1cf9
ILT
156 }
157 else
a3ad94ed 158 gold_unreachable();
61ba1cf9
ILT
159}
160
161template<int size, bool big_endian>
162void
163Output_section_headers::do_sized_write(Output_file* of)
164{
165 off_t all_shdrs_size = this->data_size();
166 unsigned char* view = of->get_output_view(this->offset(), all_shdrs_size);
167
168 const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
169 unsigned char* v = view;
170
171 {
172 typename elfcpp::Shdr_write<size, big_endian> oshdr(v);
173 oshdr.put_sh_name(0);
174 oshdr.put_sh_type(elfcpp::SHT_NULL);
175 oshdr.put_sh_flags(0);
176 oshdr.put_sh_addr(0);
177 oshdr.put_sh_offset(0);
178 oshdr.put_sh_size(0);
179 oshdr.put_sh_link(0);
180 oshdr.put_sh_info(0);
181 oshdr.put_sh_addralign(0);
182 oshdr.put_sh_entsize(0);
183 }
184
185 v += shdr_size;
186
ead1e424 187 unsigned shndx = 1;
16649710
ILT
188 for (Layout::Segment_list::const_iterator p = this->segment_list_->begin();
189 p != this->segment_list_->end();
61ba1cf9 190 ++p)
593f47df 191 v = (*p)->write_section_headers SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
16649710 192 this->layout_, this->secnamepool_, v, &shndx
ead1e424 193 SELECT_SIZE_ENDIAN(size, big_endian));
a3ad94ed 194 for (Layout::Section_list::const_iterator p =
16649710
ILT
195 this->unattached_section_list_->begin();
196 p != this->unattached_section_list_->end();
61ba1cf9
ILT
197 ++p)
198 {
a3ad94ed 199 gold_assert(shndx == (*p)->out_shndx());
61ba1cf9 200 elfcpp::Shdr_write<size, big_endian> oshdr(v);
16649710 201 (*p)->write_header(this->layout_, this->secnamepool_, &oshdr);
61ba1cf9 202 v += shdr_size;
ead1e424 203 ++shndx;
61ba1cf9
ILT
204 }
205
206 of->write_output_view(this->offset(), all_shdrs_size, view);
a2fb1b05
ILT
207}
208
54dc6425
ILT
209// Output_segment_header methods.
210
61ba1cf9 211Output_segment_headers::Output_segment_headers(
61ba1cf9 212 const Layout::Segment_list& segment_list)
9025d29d 213 : segment_list_(segment_list)
61ba1cf9 214{
9025d29d 215 const int size = parameters->get_size();
61ba1cf9
ILT
216 int phdr_size;
217 if (size == 32)
218 phdr_size = elfcpp::Elf_sizes<32>::phdr_size;
219 else if (size == 64)
220 phdr_size = elfcpp::Elf_sizes<64>::phdr_size;
221 else
a3ad94ed 222 gold_unreachable();
61ba1cf9
ILT
223
224 this->set_data_size(segment_list.size() * phdr_size);
225}
226
54dc6425 227void
61ba1cf9 228Output_segment_headers::do_write(Output_file* of)
75f65a3e 229{
9025d29d 230 if (parameters->get_size() == 32)
61ba1cf9 231 {
9025d29d
ILT
232 if (parameters->is_big_endian())
233 {
234#ifdef HAVE_TARGET_32_BIG
235 this->do_sized_write<32, true>(of);
236#else
237 gold_unreachable();
238#endif
239 }
61ba1cf9 240 else
9025d29d
ILT
241 {
242#ifdef HAVE_TARGET_32_LITTLE
61ba1cf9 243 this->do_sized_write<32, false>(of);
9025d29d
ILT
244#else
245 gold_unreachable();
246#endif
247 }
61ba1cf9 248 }
9025d29d 249 else if (parameters->get_size() == 64)
61ba1cf9 250 {
9025d29d
ILT
251 if (parameters->is_big_endian())
252 {
253#ifdef HAVE_TARGET_64_BIG
254 this->do_sized_write<64, true>(of);
255#else
256 gold_unreachable();
257#endif
258 }
61ba1cf9 259 else
9025d29d
ILT
260 {
261#ifdef HAVE_TARGET_64_LITTLE
262 this->do_sized_write<64, false>(of);
263#else
264 gold_unreachable();
265#endif
266 }
61ba1cf9
ILT
267 }
268 else
a3ad94ed 269 gold_unreachable();
61ba1cf9
ILT
270}
271
272template<int size, bool big_endian>
273void
274Output_segment_headers::do_sized_write(Output_file* of)
275{
276 const int phdr_size = elfcpp::Elf_sizes<size>::phdr_size;
277 off_t all_phdrs_size = this->segment_list_.size() * phdr_size;
278 unsigned char* view = of->get_output_view(this->offset(),
279 all_phdrs_size);
280 unsigned char* v = view;
281 for (Layout::Segment_list::const_iterator p = this->segment_list_.begin();
282 p != this->segment_list_.end();
283 ++p)
284 {
285 elfcpp::Phdr_write<size, big_endian> ophdr(v);
286 (*p)->write_header(&ophdr);
287 v += phdr_size;
288 }
289
290 of->write_output_view(this->offset(), all_phdrs_size, view);
75f65a3e
ILT
291}
292
293// Output_file_header methods.
294
9025d29d 295Output_file_header::Output_file_header(const Target* target,
75f65a3e 296 const Symbol_table* symtab,
d391083d
ILT
297 const Output_segment_headers* osh,
298 const char* entry)
9025d29d 299 : target_(target),
75f65a3e 300 symtab_(symtab),
61ba1cf9 301 segment_header_(osh),
75f65a3e 302 section_header_(NULL),
d391083d
ILT
303 shstrtab_(NULL),
304 entry_(entry)
75f65a3e 305{
9025d29d 306 const int size = parameters->get_size();
61ba1cf9
ILT
307 int ehdr_size;
308 if (size == 32)
309 ehdr_size = elfcpp::Elf_sizes<32>::ehdr_size;
310 else if (size == 64)
311 ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
312 else
a3ad94ed 313 gold_unreachable();
61ba1cf9
ILT
314
315 this->set_data_size(ehdr_size);
75f65a3e
ILT
316}
317
318// Set the section table information for a file header.
319
320void
321Output_file_header::set_section_info(const Output_section_headers* shdrs,
322 const Output_section* shstrtab)
323{
324 this->section_header_ = shdrs;
325 this->shstrtab_ = shstrtab;
326}
327
328// Write out the file header.
329
330void
61ba1cf9 331Output_file_header::do_write(Output_file* of)
54dc6425 332{
27bc2bce
ILT
333 gold_assert(this->offset() == 0);
334
9025d29d 335 if (parameters->get_size() == 32)
61ba1cf9 336 {
9025d29d
ILT
337 if (parameters->is_big_endian())
338 {
339#ifdef HAVE_TARGET_32_BIG
340 this->do_sized_write<32, true>(of);
341#else
342 gold_unreachable();
343#endif
344 }
61ba1cf9 345 else
9025d29d
ILT
346 {
347#ifdef HAVE_TARGET_32_LITTLE
348 this->do_sized_write<32, false>(of);
349#else
350 gold_unreachable();
351#endif
352 }
61ba1cf9 353 }
9025d29d 354 else if (parameters->get_size() == 64)
61ba1cf9 355 {
9025d29d
ILT
356 if (parameters->is_big_endian())
357 {
358#ifdef HAVE_TARGET_64_BIG
359 this->do_sized_write<64, true>(of);
360#else
361 gold_unreachable();
362#endif
363 }
61ba1cf9 364 else
9025d29d
ILT
365 {
366#ifdef HAVE_TARGET_64_LITTLE
367 this->do_sized_write<64, false>(of);
368#else
369 gold_unreachable();
370#endif
371 }
61ba1cf9
ILT
372 }
373 else
a3ad94ed 374 gold_unreachable();
61ba1cf9
ILT
375}
376
377// Write out the file header with appropriate size and endianess.
378
379template<int size, bool big_endian>
380void
381Output_file_header::do_sized_write(Output_file* of)
382{
a3ad94ed 383 gold_assert(this->offset() == 0);
61ba1cf9
ILT
384
385 int ehdr_size = elfcpp::Elf_sizes<size>::ehdr_size;
386 unsigned char* view = of->get_output_view(0, ehdr_size);
387 elfcpp::Ehdr_write<size, big_endian> oehdr(view);
388
389 unsigned char e_ident[elfcpp::EI_NIDENT];
390 memset(e_ident, 0, elfcpp::EI_NIDENT);
391 e_ident[elfcpp::EI_MAG0] = elfcpp::ELFMAG0;
392 e_ident[elfcpp::EI_MAG1] = elfcpp::ELFMAG1;
393 e_ident[elfcpp::EI_MAG2] = elfcpp::ELFMAG2;
394 e_ident[elfcpp::EI_MAG3] = elfcpp::ELFMAG3;
395 if (size == 32)
396 e_ident[elfcpp::EI_CLASS] = elfcpp::ELFCLASS32;
397 else if (size == 64)
398 e_ident[elfcpp::EI_CLASS] = elfcpp::ELFCLASS64;
399 else
a3ad94ed 400 gold_unreachable();
61ba1cf9
ILT
401 e_ident[elfcpp::EI_DATA] = (big_endian
402 ? elfcpp::ELFDATA2MSB
403 : elfcpp::ELFDATA2LSB);
404 e_ident[elfcpp::EI_VERSION] = elfcpp::EV_CURRENT;
405 // FIXME: Some targets may need to set EI_OSABI and EI_ABIVERSION.
406 oehdr.put_e_ident(e_ident);
407
408 elfcpp::ET e_type;
7e1edb90 409 if (parameters->output_is_object())
61ba1cf9 410 e_type = elfcpp::ET_REL;
436ca963
ILT
411 else if (parameters->output_is_shared())
412 e_type = elfcpp::ET_DYN;
61ba1cf9
ILT
413 else
414 e_type = elfcpp::ET_EXEC;
415 oehdr.put_e_type(e_type);
416
417 oehdr.put_e_machine(this->target_->machine_code());
418 oehdr.put_e_version(elfcpp::EV_CURRENT);
419
d391083d 420 oehdr.put_e_entry(this->entry<size>());
61ba1cf9
ILT
421
422 oehdr.put_e_phoff(this->segment_header_->offset());
423 oehdr.put_e_shoff(this->section_header_->offset());
424
425 // FIXME: The target needs to set the flags.
426 oehdr.put_e_flags(0);
427
428 oehdr.put_e_ehsize(elfcpp::Elf_sizes<size>::ehdr_size);
429 oehdr.put_e_phentsize(elfcpp::Elf_sizes<size>::phdr_size);
430 oehdr.put_e_phnum(this->segment_header_->data_size()
431 / elfcpp::Elf_sizes<size>::phdr_size);
432 oehdr.put_e_shentsize(elfcpp::Elf_sizes<size>::shdr_size);
433 oehdr.put_e_shnum(this->section_header_->data_size()
434 / elfcpp::Elf_sizes<size>::shdr_size);
ead1e424 435 oehdr.put_e_shstrndx(this->shstrtab_->out_shndx());
61ba1cf9
ILT
436
437 of->write_output_view(0, ehdr_size, view);
54dc6425
ILT
438}
439
d391083d
ILT
440// Return the value to use for the entry address. THIS->ENTRY_ is the
441// symbol specified on the command line, if any.
442
443template<int size>
444typename elfcpp::Elf_types<size>::Elf_Addr
445Output_file_header::entry()
446{
447 const bool should_issue_warning = (this->entry_ != NULL
448 && parameters->output_is_executable());
449
450 // FIXME: Need to support target specific entry symbol.
451 const char* entry = this->entry_;
452 if (entry == NULL)
453 entry = "_start";
454
455 Symbol* sym = this->symtab_->lookup(entry);
456
457 typename Sized_symbol<size>::Value_type v;
458 if (sym != NULL)
459 {
460 Sized_symbol<size>* ssym;
461 ssym = this->symtab_->get_sized_symbol<size>(sym);
462 if (!ssym->is_defined() && should_issue_warning)
463 gold_warning("entry symbol '%s' exists but is not defined", entry);
464 v = ssym->value();
465 }
466 else
467 {
468 // We couldn't find the entry symbol. See if we can parse it as
469 // a number. This supports, e.g., -e 0x1000.
470 char* endptr;
471 v = strtoull(entry, &endptr, 0);
472 if (*endptr != '\0')
473 {
474 if (should_issue_warning)
475 gold_warning("cannot find entry symbol '%s'", entry);
476 v = 0;
477 }
478 }
479
480 return v;
481}
482
dbe717ef
ILT
483// Output_data_const methods.
484
485void
a3ad94ed 486Output_data_const::do_write(Output_file* of)
dbe717ef 487{
a3ad94ed
ILT
488 of->write(this->offset(), this->data_.data(), this->data_.size());
489}
490
491// Output_data_const_buffer methods.
492
493void
494Output_data_const_buffer::do_write(Output_file* of)
495{
496 of->write(this->offset(), this->p_, this->data_size());
dbe717ef
ILT
497}
498
499// Output_section_data methods.
500
16649710
ILT
501// Record the output section, and set the entry size and such.
502
503void
504Output_section_data::set_output_section(Output_section* os)
505{
506 gold_assert(this->output_section_ == NULL);
507 this->output_section_ = os;
508 this->do_adjust_output_section(os);
509}
510
511// Return the section index of the output section.
512
dbe717ef
ILT
513unsigned int
514Output_section_data::do_out_shndx() const
515{
a3ad94ed 516 gold_assert(this->output_section_ != NULL);
dbe717ef
ILT
517 return this->output_section_->out_shndx();
518}
519
a3ad94ed
ILT
520// Output_data_strtab methods.
521
27bc2bce 522// Set the final data size.
a3ad94ed
ILT
523
524void
27bc2bce 525Output_data_strtab::set_final_data_size()
a3ad94ed
ILT
526{
527 this->strtab_->set_string_offsets();
528 this->set_data_size(this->strtab_->get_strtab_size());
529}
530
531// Write out a string table.
532
533void
534Output_data_strtab::do_write(Output_file* of)
535{
536 this->strtab_->write(of, this->offset());
537}
538
c06b7b0b
ILT
539// Output_reloc methods.
540
7bf1f802
ILT
541// A reloc against a global symbol.
542
543template<bool dynamic, int size, bool big_endian>
544Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::Output_reloc(
545 Symbol* gsym,
546 unsigned int type,
547 Output_data* od,
e8c846c3
ILT
548 Address address,
549 bool is_relative)
7bf1f802 550 : address_(address), local_sym_index_(GSYM_CODE), type_(type),
e8c846c3 551 is_relative_(is_relative), shndx_(INVALID_CODE)
7bf1f802
ILT
552{
553 this->u1_.gsym = gsym;
554 this->u2_.od = od;
e8c846c3 555 if (dynamic && !is_relative)
7bf1f802
ILT
556 gsym->set_needs_dynsym_entry();
557}
558
559template<bool dynamic, int size, bool big_endian>
560Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::Output_reloc(
561 Symbol* gsym,
562 unsigned int type,
563 Relobj* relobj,
564 unsigned int shndx,
e8c846c3
ILT
565 Address address,
566 bool is_relative)
7bf1f802 567 : address_(address), local_sym_index_(GSYM_CODE), type_(type),
e8c846c3 568 is_relative_(is_relative), shndx_(shndx)
7bf1f802
ILT
569{
570 gold_assert(shndx != INVALID_CODE);
571 this->u1_.gsym = gsym;
572 this->u2_.relobj = relobj;
e8c846c3 573 if (dynamic && !is_relative)
7bf1f802
ILT
574 gsym->set_needs_dynsym_entry();
575}
576
577// A reloc against a local symbol.
578
579template<bool dynamic, int size, bool big_endian>
580Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::Output_reloc(
581 Sized_relobj<size, big_endian>* relobj,
582 unsigned int local_sym_index,
583 unsigned int type,
584 Output_data* od,
e8c846c3
ILT
585 Address address,
586 bool is_relative)
7bf1f802 587 : address_(address), local_sym_index_(local_sym_index), type_(type),
e8c846c3 588 is_relative_(is_relative), shndx_(INVALID_CODE)
7bf1f802
ILT
589{
590 gold_assert(local_sym_index != GSYM_CODE
591 && local_sym_index != INVALID_CODE);
592 this->u1_.relobj = relobj;
593 this->u2_.od = od;
e8c846c3 594 if (dynamic && !is_relative)
7bf1f802
ILT
595 relobj->set_needs_output_dynsym_entry(local_sym_index);
596}
597
598template<bool dynamic, int size, bool big_endian>
599Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::Output_reloc(
600 Sized_relobj<size, big_endian>* relobj,
601 unsigned int local_sym_index,
602 unsigned int type,
603 unsigned int shndx,
e8c846c3
ILT
604 Address address,
605 bool is_relative)
7bf1f802 606 : address_(address), local_sym_index_(local_sym_index), type_(type),
e8c846c3 607 is_relative_(is_relative), shndx_(shndx)
7bf1f802
ILT
608{
609 gold_assert(local_sym_index != GSYM_CODE
610 && local_sym_index != INVALID_CODE);
611 gold_assert(shndx != INVALID_CODE);
612 this->u1_.relobj = relobj;
613 this->u2_.relobj = relobj;
e8c846c3 614 if (dynamic && !is_relative)
7bf1f802
ILT
615 relobj->set_needs_output_dynsym_entry(local_sym_index);
616}
617
618// A reloc against the STT_SECTION symbol of an output section.
619
620template<bool dynamic, int size, bool big_endian>
621Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::Output_reloc(
622 Output_section* os,
623 unsigned int type,
624 Output_data* od,
625 Address address)
626 : address_(address), local_sym_index_(SECTION_CODE), type_(type),
e8c846c3 627 is_relative_(false), shndx_(INVALID_CODE)
7bf1f802
ILT
628{
629 this->u1_.os = os;
630 this->u2_.od = od;
631 if (dynamic)
632 os->set_needs_dynsym_index();
633}
634
635template<bool dynamic, int size, bool big_endian>
636Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::Output_reloc(
637 Output_section* os,
638 unsigned int type,
639 Relobj* relobj,
640 unsigned int shndx,
641 Address address)
642 : address_(address), local_sym_index_(SECTION_CODE), type_(type),
e8c846c3 643 is_relative_(false), shndx_(shndx)
7bf1f802
ILT
644{
645 gold_assert(shndx != INVALID_CODE);
646 this->u1_.os = os;
647 this->u2_.relobj = relobj;
648 if (dynamic)
649 os->set_needs_dynsym_index();
650}
651
c06b7b0b
ILT
652// Get the symbol index of a relocation.
653
654template<bool dynamic, int size, bool big_endian>
655unsigned int
656Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::get_symbol_index()
657 const
658{
659 unsigned int index;
660 switch (this->local_sym_index_)
661 {
662 case INVALID_CODE:
a3ad94ed 663 gold_unreachable();
c06b7b0b
ILT
664
665 case GSYM_CODE:
5a6f7e2d 666 if (this->u1_.gsym == NULL)
c06b7b0b
ILT
667 index = 0;
668 else if (dynamic)
5a6f7e2d 669 index = this->u1_.gsym->dynsym_index();
c06b7b0b 670 else
5a6f7e2d 671 index = this->u1_.gsym->symtab_index();
c06b7b0b
ILT
672 break;
673
674 case SECTION_CODE:
675 if (dynamic)
5a6f7e2d 676 index = this->u1_.os->dynsym_index();
c06b7b0b 677 else
5a6f7e2d 678 index = this->u1_.os->symtab_index();
c06b7b0b
ILT
679 break;
680
436ca963
ILT
681 case 0:
682 // Relocations without symbols use a symbol index of 0.
683 index = 0;
684 break;
685
c06b7b0b
ILT
686 default:
687 if (dynamic)
7bf1f802 688 index = this->u1_.relobj->dynsym_index(this->local_sym_index_);
c06b7b0b 689 else
5a6f7e2d 690 index = this->u1_.relobj->symtab_index(this->local_sym_index_);
c06b7b0b
ILT
691 break;
692 }
a3ad94ed 693 gold_assert(index != -1U);
c06b7b0b
ILT
694 return index;
695}
696
697// Write out the offset and info fields of a Rel or Rela relocation
698// entry.
699
700template<bool dynamic, int size, bool big_endian>
701template<typename Write_rel>
702void
703Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::write_rel(
704 Write_rel* wr) const
705{
a3ad94ed 706 Address address = this->address_;
5a6f7e2d
ILT
707 if (this->shndx_ != INVALID_CODE)
708 {
8383303e 709 section_offset_type off;
5a6f7e2d
ILT
710 Output_section* os = this->u2_.relobj->output_section(this->shndx_,
711 &off);
712 gold_assert(os != NULL);
730cdc88
ILT
713 if (off != -1)
714 address += os->address() + off;
715 else
716 {
717 address = os->output_address(this->u2_.relobj, this->shndx_,
718 address);
719 gold_assert(address != -1U);
720 }
5a6f7e2d
ILT
721 }
722 else if (this->u2_.od != NULL)
723 address += this->u2_.od->address();
a3ad94ed 724 wr->put_r_offset(address);
e8c846c3
ILT
725 unsigned int sym_index = this->is_relative_ ? 0 : this->get_symbol_index();
726 wr->put_r_info(elfcpp::elf_r_info<size>(sym_index, this->type_));
c06b7b0b
ILT
727}
728
729// Write out a Rel relocation.
730
731template<bool dynamic, int size, bool big_endian>
732void
733Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::write(
734 unsigned char* pov) const
735{
736 elfcpp::Rel_write<size, big_endian> orel(pov);
737 this->write_rel(&orel);
738}
739
e8c846c3
ILT
740// Get the value of the symbol referred to by a Rel relocation.
741
742template<bool dynamic, int size, bool big_endian>
743typename elfcpp::Elf_types<size>::Elf_Addr
744Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::symbol_value() const
745{
746 if (this->local_sym_index_ == GSYM_CODE)
747 {
748 const Sized_symbol<size>* sym;
749 sym = static_cast<const Sized_symbol<size>*>(this->u1_.gsym);
750 return sym->value();
751 }
752 gold_assert(this->local_sym_index_ != SECTION_CODE
753 && this->local_sym_index_ != INVALID_CODE);
754 const Sized_relobj<size, big_endian>* relobj = this->u1_.relobj;
755 return relobj->local_symbol_value(this->local_sym_index_);
756}
757
c06b7b0b
ILT
758// Write out a Rela relocation.
759
760template<bool dynamic, int size, bool big_endian>
761void
762Output_reloc<elfcpp::SHT_RELA, dynamic, size, big_endian>::write(
763 unsigned char* pov) const
764{
765 elfcpp::Rela_write<size, big_endian> orel(pov);
766 this->rel_.write_rel(&orel);
e8c846c3
ILT
767 Addend addend = this->addend_;
768 if (rel_.is_relative())
769 addend += rel_.symbol_value();
770 orel.put_r_addend(addend);
c06b7b0b
ILT
771}
772
773// Output_data_reloc_base methods.
774
16649710
ILT
775// Adjust the output section.
776
777template<int sh_type, bool dynamic, int size, bool big_endian>
778void
779Output_data_reloc_base<sh_type, dynamic, size, big_endian>
780 ::do_adjust_output_section(Output_section* os)
781{
782 if (sh_type == elfcpp::SHT_REL)
783 os->set_entsize(elfcpp::Elf_sizes<size>::rel_size);
784 else if (sh_type == elfcpp::SHT_RELA)
785 os->set_entsize(elfcpp::Elf_sizes<size>::rela_size);
786 else
787 gold_unreachable();
788 if (dynamic)
789 os->set_should_link_to_dynsym();
790 else
791 os->set_should_link_to_symtab();
792}
793
c06b7b0b
ILT
794// Write out relocation data.
795
796template<int sh_type, bool dynamic, int size, bool big_endian>
797void
798Output_data_reloc_base<sh_type, dynamic, size, big_endian>::do_write(
799 Output_file* of)
800{
801 const off_t off = this->offset();
802 const off_t oview_size = this->data_size();
803 unsigned char* const oview = of->get_output_view(off, oview_size);
804
805 unsigned char* pov = oview;
806 for (typename Relocs::const_iterator p = this->relocs_.begin();
807 p != this->relocs_.end();
808 ++p)
809 {
810 p->write(pov);
811 pov += reloc_size;
812 }
813
a3ad94ed 814 gold_assert(pov - oview == oview_size);
c06b7b0b
ILT
815
816 of->write_output_view(off, oview_size, oview);
817
818 // We no longer need the relocation entries.
819 this->relocs_.clear();
820}
821
dbe717ef 822// Output_data_got::Got_entry methods.
ead1e424
ILT
823
824// Write out the entry.
825
826template<int size, bool big_endian>
827void
7e1edb90 828Output_data_got<size, big_endian>::Got_entry::write(unsigned char* pov) const
ead1e424
ILT
829{
830 Valtype val = 0;
831
832 switch (this->local_sym_index_)
833 {
834 case GSYM_CODE:
835 {
e8c846c3
ILT
836 // If the symbol is resolved locally, we need to write out the
837 // link-time value, which will be relocated dynamically by a
838 // RELATIVE relocation.
ead1e424 839 Symbol* gsym = this->u_.gsym;
e8c846c3
ILT
840 Sized_symbol<size>* sgsym;
841 // This cast is a bit ugly. We don't want to put a
842 // virtual method in Symbol, because we want Symbol to be
843 // as small as possible.
844 sgsym = static_cast<Sized_symbol<size>*>(gsym);
845 val = sgsym->value();
ead1e424
ILT
846 }
847 break;
848
849 case CONSTANT_CODE:
850 val = this->u_.constant;
851 break;
852
853 default:
e727fa71
ILT
854 val = this->u_.object->local_symbol_value(this->local_sym_index_);
855 break;
ead1e424
ILT
856 }
857
a3ad94ed 858 elfcpp::Swap<size, big_endian>::writeval(pov, val);
ead1e424
ILT
859}
860
dbe717ef 861// Output_data_got methods.
ead1e424 862
dbe717ef
ILT
863// Add an entry for a global symbol to the GOT. This returns true if
864// this is a new GOT entry, false if the symbol already had a GOT
865// entry.
866
867template<int size, bool big_endian>
868bool
869Output_data_got<size, big_endian>::add_global(Symbol* gsym)
ead1e424 870{
dbe717ef
ILT
871 if (gsym->has_got_offset())
872 return false;
ead1e424 873
dbe717ef
ILT
874 this->entries_.push_back(Got_entry(gsym));
875 this->set_got_size();
876 gsym->set_got_offset(this->last_got_offset());
877 return true;
878}
ead1e424 879
7bf1f802
ILT
880// Add an entry for a global symbol to the GOT, and add a dynamic
881// relocation of type R_TYPE for the GOT entry.
882template<int size, bool big_endian>
883void
884Output_data_got<size, big_endian>::add_global_with_rel(
885 Symbol* gsym,
886 Rel_dyn* rel_dyn,
887 unsigned int r_type)
888{
889 if (gsym->has_got_offset())
890 return;
891
892 this->entries_.push_back(Got_entry());
893 this->set_got_size();
894 unsigned int got_offset = this->last_got_offset();
895 gsym->set_got_offset(got_offset);
896 rel_dyn->add_global(gsym, r_type, this, got_offset);
897}
898
899template<int size, bool big_endian>
900void
901Output_data_got<size, big_endian>::add_global_with_rela(
902 Symbol* gsym,
903 Rela_dyn* rela_dyn,
904 unsigned int r_type)
905{
906 if (gsym->has_got_offset())
907 return;
908
909 this->entries_.push_back(Got_entry());
910 this->set_got_size();
911 unsigned int got_offset = this->last_got_offset();
912 gsym->set_got_offset(got_offset);
913 rela_dyn->add_global(gsym, r_type, this, got_offset, 0);
914}
915
e727fa71
ILT
916// Add an entry for a local symbol to the GOT. This returns true if
917// this is a new GOT entry, false if the symbol already has a GOT
918// entry.
919
920template<int size, bool big_endian>
921bool
922Output_data_got<size, big_endian>::add_local(
923 Sized_relobj<size, big_endian>* object,
924 unsigned int symndx)
925{
926 if (object->local_has_got_offset(symndx))
927 return false;
07f397ab 928
e727fa71
ILT
929 this->entries_.push_back(Got_entry(object, symndx));
930 this->set_got_size();
931 object->set_local_got_offset(symndx, this->last_got_offset());
932 return true;
933}
934
7bf1f802
ILT
935// Add an entry for a local symbol to the GOT, and add a dynamic
936// relocation of type R_TYPE for the GOT entry.
937template<int size, bool big_endian>
938void
939Output_data_got<size, big_endian>::add_local_with_rel(
940 Sized_relobj<size, big_endian>* object,
941 unsigned int symndx,
942 Rel_dyn* rel_dyn,
943 unsigned int r_type)
944{
945 if (object->local_has_got_offset(symndx))
946 return;
947
948 this->entries_.push_back(Got_entry());
949 this->set_got_size();
950 unsigned int got_offset = this->last_got_offset();
951 object->set_local_got_offset(symndx, got_offset);
952 rel_dyn->add_local(object, symndx, r_type, this, got_offset);
953}
954
955template<int size, bool big_endian>
956void
957Output_data_got<size, big_endian>::add_local_with_rela(
958 Sized_relobj<size, big_endian>* object,
959 unsigned int symndx,
960 Rela_dyn* rela_dyn,
961 unsigned int r_type)
962{
963 if (object->local_has_got_offset(symndx))
964 return;
965
966 this->entries_.push_back(Got_entry());
967 this->set_got_size();
968 unsigned int got_offset = this->last_got_offset();
969 object->set_local_got_offset(symndx, got_offset);
970 rela_dyn->add_local(object, symndx, r_type, this, got_offset, 0);
971}
972
07f397ab
ILT
973// Add an entry (or a pair of entries) for a global TLS symbol to the GOT.
974// In a pair of entries, the first value in the pair will be used for the
975// module index, and the second value will be used for the dtv-relative
976// offset. This returns true if this is a new GOT entry, false if the symbol
977// already has a GOT entry.
978
979template<int size, bool big_endian>
980bool
7bf1f802 981Output_data_got<size, big_endian>::add_global_tls(Symbol* gsym, bool need_pair)
07f397ab
ILT
982{
983 if (gsym->has_tls_got_offset(need_pair))
984 return false;
985
986 this->entries_.push_back(Got_entry(gsym));
987 gsym->set_tls_got_offset(this->last_got_offset(), need_pair);
988 if (need_pair)
989 this->entries_.push_back(Got_entry(gsym));
990 this->set_got_size();
991 return true;
992}
993
7bf1f802
ILT
994// Add an entry for a global TLS symbol to the GOT, and add a dynamic
995// relocation of type R_TYPE.
996template<int size, bool big_endian>
997void
998Output_data_got<size, big_endian>::add_global_tls_with_rel(
999 Symbol* gsym,
1000 Rel_dyn* rel_dyn,
1001 unsigned int r_type)
1002{
1003 if (gsym->has_tls_got_offset(false))
1004 return;
1005
1006 this->entries_.push_back(Got_entry());
1007 this->set_got_size();
1008 unsigned int got_offset = this->last_got_offset();
1009 gsym->set_tls_got_offset(got_offset, false);
1010 rel_dyn->add_global(gsym, r_type, this, got_offset);
1011}
1012
1013template<int size, bool big_endian>
1014void
1015Output_data_got<size, big_endian>::add_global_tls_with_rela(
1016 Symbol* gsym,
1017 Rela_dyn* rela_dyn,
1018 unsigned int r_type)
1019{
1020 if (gsym->has_tls_got_offset(false))
1021 return;
1022
1023 this->entries_.push_back(Got_entry());
1024 this->set_got_size();
1025 unsigned int got_offset = this->last_got_offset();
1026 gsym->set_tls_got_offset(got_offset, false);
1027 rela_dyn->add_global(gsym, r_type, this, got_offset, 0);
1028}
1029
1030// Add a pair of entries for a global TLS symbol to the GOT, and add
1031// dynamic relocations of type MOD_R_TYPE and DTV_R_TYPE, respectively.
1032template<int size, bool big_endian>
1033void
1034Output_data_got<size, big_endian>::add_global_tls_with_rel(
1035 Symbol* gsym,
1036 Rel_dyn* rel_dyn,
1037 unsigned int mod_r_type,
1038 unsigned int dtv_r_type)
1039{
1040 if (gsym->has_tls_got_offset(true))
1041 return;
1042
1043 this->entries_.push_back(Got_entry());
1044 unsigned int got_offset = this->last_got_offset();
1045 gsym->set_tls_got_offset(got_offset, true);
1046 rel_dyn->add_global(gsym, mod_r_type, this, got_offset);
1047
1048 this->entries_.push_back(Got_entry());
1049 this->set_got_size();
1050 got_offset = this->last_got_offset();
1051 rel_dyn->add_global(gsym, dtv_r_type, this, got_offset);
1052}
1053
1054template<int size, bool big_endian>
1055void
1056Output_data_got<size, big_endian>::add_global_tls_with_rela(
1057 Symbol* gsym,
1058 Rela_dyn* rela_dyn,
1059 unsigned int mod_r_type,
1060 unsigned int dtv_r_type)
1061{
1062 if (gsym->has_tls_got_offset(true))
1063 return;
1064
1065 this->entries_.push_back(Got_entry());
1066 unsigned int got_offset = this->last_got_offset();
1067 gsym->set_tls_got_offset(got_offset, true);
1068 rela_dyn->add_global(gsym, mod_r_type, this, got_offset, 0);
1069
1070 this->entries_.push_back(Got_entry());
1071 this->set_got_size();
1072 got_offset = this->last_got_offset();
1073 rela_dyn->add_global(gsym, dtv_r_type, this, got_offset, 0);
1074}
1075
07f397ab
ILT
1076// Add an entry (or a pair of entries) for a local TLS symbol to the GOT.
1077// In a pair of entries, the first value in the pair will be used for the
1078// module index, and the second value will be used for the dtv-relative
1079// offset. This returns true if this is a new GOT entry, false if the symbol
1080// already has a GOT entry.
1081
1082template<int size, bool big_endian>
1083bool
1084Output_data_got<size, big_endian>::add_local_tls(
1085 Sized_relobj<size, big_endian>* object,
1086 unsigned int symndx,
1087 bool need_pair)
1088{
1089 if (object->local_has_tls_got_offset(symndx, need_pair))
1090 return false;
1091
1092 this->entries_.push_back(Got_entry(object, symndx));
1093 object->set_local_tls_got_offset(symndx, this->last_got_offset(), need_pair);
1094 if (need_pair)
1095 this->entries_.push_back(Got_entry(object, symndx));
1096 this->set_got_size();
1097 return true;
1098}
1099
7bf1f802
ILT
1100// Add an entry (or pair of entries) for a local TLS symbol to the GOT,
1101// and add a dynamic relocation of type R_TYPE for the first GOT entry.
1102// Because this is a local symbol, the first GOT entry can be relocated
1103// relative to a section symbol, and the second GOT entry will have an
1104// dtv-relative value that can be computed at link time.
1105template<int size, bool big_endian>
1106void
1107Output_data_got<size, big_endian>::add_local_tls_with_rel(
1108 Sized_relobj<size, big_endian>* object,
1109 unsigned int symndx,
1110 unsigned int shndx,
1111 bool need_pair,
1112 Rel_dyn* rel_dyn,
1113 unsigned int r_type)
1114{
1115 if (object->local_has_tls_got_offset(symndx, need_pair))
1116 return;
1117
1118 this->entries_.push_back(Got_entry());
1119 unsigned int got_offset = this->last_got_offset();
1120 object->set_local_tls_got_offset(symndx, got_offset, need_pair);
8383303e 1121 section_offset_type off;
7bf1f802
ILT
1122 Output_section* os = object->output_section(shndx, &off);
1123 rel_dyn->add_output_section(os, r_type, this, got_offset);
1124
1125 // The second entry of the pair will be statically initialized
1126 // with the TLS offset of the symbol.
1127 if (need_pair)
1128 this->entries_.push_back(Got_entry(object, symndx));
1129
1130 this->set_got_size();
1131}
1132
1133template<int size, bool big_endian>
1134void
1135Output_data_got<size, big_endian>::add_local_tls_with_rela(
1136 Sized_relobj<size, big_endian>* object,
1137 unsigned int symndx,
1138 unsigned int shndx,
1139 bool need_pair,
1140 Rela_dyn* rela_dyn,
1141 unsigned int r_type)
1142{
1143 if (object->local_has_tls_got_offset(symndx, need_pair))
1144 return;
1145
1146 this->entries_.push_back(Got_entry());
1147 unsigned int got_offset = this->last_got_offset();
1148 object->set_local_tls_got_offset(symndx, got_offset, need_pair);
8383303e 1149 section_offset_type off;
7bf1f802
ILT
1150 Output_section* os = object->output_section(shndx, &off);
1151 rela_dyn->add_output_section(os, r_type, this, got_offset, 0);
1152
1153 // The second entry of the pair will be statically initialized
1154 // with the TLS offset of the symbol.
1155 if (need_pair)
1156 this->entries_.push_back(Got_entry(object, symndx));
1157
1158 this->set_got_size();
1159}
1160
ead1e424
ILT
1161// Write out the GOT.
1162
1163template<int size, bool big_endian>
1164void
dbe717ef 1165Output_data_got<size, big_endian>::do_write(Output_file* of)
ead1e424
ILT
1166{
1167 const int add = size / 8;
1168
1169 const off_t off = this->offset();
c06b7b0b 1170 const off_t oview_size = this->data_size();
ead1e424
ILT
1171 unsigned char* const oview = of->get_output_view(off, oview_size);
1172
1173 unsigned char* pov = oview;
1174 for (typename Got_entries::const_iterator p = this->entries_.begin();
1175 p != this->entries_.end();
1176 ++p)
1177 {
7e1edb90 1178 p->write(pov);
ead1e424
ILT
1179 pov += add;
1180 }
1181
a3ad94ed 1182 gold_assert(pov - oview == oview_size);
c06b7b0b 1183
ead1e424
ILT
1184 of->write_output_view(off, oview_size, oview);
1185
1186 // We no longer need the GOT entries.
1187 this->entries_.clear();
1188}
1189
a3ad94ed
ILT
1190// Output_data_dynamic::Dynamic_entry methods.
1191
1192// Write out the entry.
1193
1194template<int size, bool big_endian>
1195void
1196Output_data_dynamic::Dynamic_entry::write(
1197 unsigned char* pov,
1ddbd1e6
ILT
1198 const Stringpool* pool
1199 ACCEPT_SIZE_ENDIAN) const
a3ad94ed
ILT
1200{
1201 typename elfcpp::Elf_types<size>::Elf_WXword val;
1202 switch (this->classification_)
1203 {
1204 case DYNAMIC_NUMBER:
1205 val = this->u_.val;
1206 break;
1207
1208 case DYNAMIC_SECTION_ADDRESS:
16649710 1209 val = this->u_.od->address();
a3ad94ed
ILT
1210 break;
1211
1212 case DYNAMIC_SECTION_SIZE:
16649710 1213 val = this->u_.od->data_size();
a3ad94ed
ILT
1214 break;
1215
1216 case DYNAMIC_SYMBOL:
1217 {
16649710
ILT
1218 const Sized_symbol<size>* s =
1219 static_cast<const Sized_symbol<size>*>(this->u_.sym);
a3ad94ed
ILT
1220 val = s->value();
1221 }
1222 break;
1223
1224 case DYNAMIC_STRING:
1225 val = pool->get_offset(this->u_.str);
1226 break;
1227
1228 default:
1229 gold_unreachable();
1230 }
1231
1232 elfcpp::Dyn_write<size, big_endian> dw(pov);
1233 dw.put_d_tag(this->tag_);
1234 dw.put_d_val(val);
1235}
1236
1237// Output_data_dynamic methods.
1238
16649710
ILT
1239// Adjust the output section to set the entry size.
1240
1241void
1242Output_data_dynamic::do_adjust_output_section(Output_section* os)
1243{
9025d29d 1244 if (parameters->get_size() == 32)
16649710 1245 os->set_entsize(elfcpp::Elf_sizes<32>::dyn_size);
9025d29d 1246 else if (parameters->get_size() == 64)
16649710
ILT
1247 os->set_entsize(elfcpp::Elf_sizes<64>::dyn_size);
1248 else
1249 gold_unreachable();
1250}
1251
a3ad94ed
ILT
1252// Set the final data size.
1253
1254void
27bc2bce 1255Output_data_dynamic::set_final_data_size()
a3ad94ed
ILT
1256{
1257 // Add the terminating entry.
1258 this->add_constant(elfcpp::DT_NULL, 0);
1259
1260 int dyn_size;
9025d29d 1261 if (parameters->get_size() == 32)
a3ad94ed 1262 dyn_size = elfcpp::Elf_sizes<32>::dyn_size;
9025d29d 1263 else if (parameters->get_size() == 64)
a3ad94ed
ILT
1264 dyn_size = elfcpp::Elf_sizes<64>::dyn_size;
1265 else
1266 gold_unreachable();
1267 this->set_data_size(this->entries_.size() * dyn_size);
1268}
1269
1270// Write out the dynamic entries.
1271
1272void
1273Output_data_dynamic::do_write(Output_file* of)
1274{
9025d29d 1275 if (parameters->get_size() == 32)
a3ad94ed 1276 {
9025d29d
ILT
1277 if (parameters->is_big_endian())
1278 {
1279#ifdef HAVE_TARGET_32_BIG
1280 this->sized_write<32, true>(of);
1281#else
1282 gold_unreachable();
1283#endif
1284 }
a3ad94ed 1285 else
9025d29d
ILT
1286 {
1287#ifdef HAVE_TARGET_32_LITTLE
1288 this->sized_write<32, false>(of);
1289#else
1290 gold_unreachable();
1291#endif
1292 }
a3ad94ed 1293 }
9025d29d 1294 else if (parameters->get_size() == 64)
a3ad94ed 1295 {
9025d29d
ILT
1296 if (parameters->is_big_endian())
1297 {
1298#ifdef HAVE_TARGET_64_BIG
1299 this->sized_write<64, true>(of);
1300#else
1301 gold_unreachable();
1302#endif
1303 }
a3ad94ed 1304 else
9025d29d
ILT
1305 {
1306#ifdef HAVE_TARGET_64_LITTLE
1307 this->sized_write<64, false>(of);
1308#else
1309 gold_unreachable();
1310#endif
1311 }
a3ad94ed
ILT
1312 }
1313 else
1314 gold_unreachable();
1315}
1316
1317template<int size, bool big_endian>
1318void
1319Output_data_dynamic::sized_write(Output_file* of)
1320{
1321 const int dyn_size = elfcpp::Elf_sizes<size>::dyn_size;
1322
1323 const off_t offset = this->offset();
1324 const off_t oview_size = this->data_size();
1325 unsigned char* const oview = of->get_output_view(offset, oview_size);
1326
1327 unsigned char* pov = oview;
1328 for (typename Dynamic_entries::const_iterator p = this->entries_.begin();
1329 p != this->entries_.end();
1330 ++p)
1331 {
1ddbd1e6
ILT
1332 p->write SELECT_SIZE_ENDIAN_NAME(size, big_endian)(
1333 pov, this->pool_ SELECT_SIZE_ENDIAN(size, big_endian));
a3ad94ed
ILT
1334 pov += dyn_size;
1335 }
1336
1337 gold_assert(pov - oview == oview_size);
1338
1339 of->write_output_view(offset, oview_size, oview);
1340
1341 // We no longer need the dynamic entries.
1342 this->entries_.clear();
1343}
1344
ead1e424
ILT
1345// Output_section::Input_section methods.
1346
1347// Return the data size. For an input section we store the size here.
1348// For an Output_section_data, we have to ask it for the size.
1349
1350off_t
1351Output_section::Input_section::data_size() const
1352{
1353 if (this->is_input_section())
b8e6aad9 1354 return this->u1_.data_size;
ead1e424 1355 else
b8e6aad9 1356 return this->u2_.posd->data_size();
ead1e424
ILT
1357}
1358
1359// Set the address and file offset.
1360
1361void
96803768
ILT
1362Output_section::Input_section::set_address_and_file_offset(
1363 uint64_t address,
1364 off_t file_offset,
1365 off_t section_file_offset)
ead1e424
ILT
1366{
1367 if (this->is_input_section())
96803768
ILT
1368 this->u2_.object->set_section_offset(this->shndx_,
1369 file_offset - section_file_offset);
ead1e424 1370 else
96803768
ILT
1371 this->u2_.posd->set_address_and_file_offset(address, file_offset);
1372}
1373
1374// Finalize the data size.
1375
1376void
1377Output_section::Input_section::finalize_data_size()
1378{
1379 if (!this->is_input_section())
1380 this->u2_.posd->finalize_data_size();
b8e6aad9
ILT
1381}
1382
1e983657
ILT
1383// Try to turn an input offset into an output offset. We want to
1384// return the output offset relative to the start of this
1385// Input_section in the output section.
b8e6aad9 1386
8f00aeb8 1387inline bool
8383303e
ILT
1388Output_section::Input_section::output_offset(
1389 const Relobj* object,
1390 unsigned int shndx,
1391 section_offset_type offset,
1392 section_offset_type *poutput) const
b8e6aad9
ILT
1393{
1394 if (!this->is_input_section())
730cdc88 1395 return this->u2_.posd->output_offset(object, shndx, offset, poutput);
b8e6aad9
ILT
1396 else
1397 {
730cdc88 1398 if (this->shndx_ != shndx || this->u2_.object != object)
b8e6aad9 1399 return false;
1e983657 1400 *poutput = offset;
b8e6aad9
ILT
1401 return true;
1402 }
ead1e424
ILT
1403}
1404
a9a60db6
ILT
1405// Return whether this is the merge section for the input section
1406// SHNDX in OBJECT.
1407
1408inline bool
1409Output_section::Input_section::is_merge_section_for(const Relobj* object,
1410 unsigned int shndx) const
1411{
1412 if (this->is_input_section())
1413 return false;
1414 return this->u2_.posd->is_merge_section_for(object, shndx);
1415}
1416
ead1e424
ILT
1417// Write out the data. We don't have to do anything for an input
1418// section--they are handled via Object::relocate--but this is where
1419// we write out the data for an Output_section_data.
1420
1421void
1422Output_section::Input_section::write(Output_file* of)
1423{
1424 if (!this->is_input_section())
b8e6aad9 1425 this->u2_.posd->write(of);
ead1e424
ILT
1426}
1427
96803768
ILT
1428// Write the data to a buffer. As for write(), we don't have to do
1429// anything for an input section.
1430
1431void
1432Output_section::Input_section::write_to_buffer(unsigned char* buffer)
1433{
1434 if (!this->is_input_section())
1435 this->u2_.posd->write_to_buffer(buffer);
1436}
1437
a2fb1b05
ILT
1438// Output_section methods.
1439
1440// Construct an Output_section. NAME will point into a Stringpool.
1441
96803768 1442Output_section::Output_section(const char* name, elfcpp::Elf_Word type,
b8e6aad9 1443 elfcpp::Elf_Xword flags)
96803768 1444 : name_(name),
a2fb1b05
ILT
1445 addralign_(0),
1446 entsize_(0),
16649710 1447 link_section_(NULL),
a2fb1b05 1448 link_(0),
16649710 1449 info_section_(NULL),
a2fb1b05
ILT
1450 info_(0),
1451 type_(type),
61ba1cf9 1452 flags_(flags),
91ea499d 1453 out_shndx_(-1U),
c06b7b0b
ILT
1454 symtab_index_(0),
1455 dynsym_index_(0),
ead1e424
ILT
1456 input_sections_(),
1457 first_input_offset_(0),
c51e6221 1458 fills_(),
96803768 1459 postprocessing_buffer_(NULL),
a3ad94ed 1460 needs_symtab_index_(false),
16649710
ILT
1461 needs_dynsym_index_(false),
1462 should_link_to_symtab_(false),
730cdc88 1463 should_link_to_dynsym_(false),
27bc2bce 1464 after_input_sections_(false),
7bf1f802
ILT
1465 requires_postprocessing_(false),
1466 tls_offset_(0)
a2fb1b05 1467{
27bc2bce
ILT
1468 // An unallocated section has no address. Forcing this means that
1469 // we don't need special treatment for symbols defined in debug
1470 // sections.
1471 if ((flags & elfcpp::SHF_ALLOC) == 0)
1472 this->set_address(0);
a2fb1b05
ILT
1473}
1474
54dc6425
ILT
1475Output_section::~Output_section()
1476{
1477}
1478
16649710
ILT
1479// Set the entry size.
1480
1481void
1482Output_section::set_entsize(uint64_t v)
1483{
1484 if (this->entsize_ == 0)
1485 this->entsize_ = v;
1486 else
1487 gold_assert(this->entsize_ == v);
1488}
1489
ead1e424 1490// Add the input section SHNDX, with header SHDR, named SECNAME, in
730cdc88
ILT
1491// OBJECT, to the Output_section. RELOC_SHNDX is the index of a
1492// relocation section which applies to this section, or 0 if none, or
1493// -1U if more than one. Return the offset of the input section
1494// within the output section. Return -1 if the input section will
1495// receive special handling. In the normal case we don't always keep
1496// track of input sections for an Output_section. Instead, each
1497// Object keeps track of the Output_section for each of its input
1498// sections.
a2fb1b05
ILT
1499
1500template<int size, bool big_endian>
1501off_t
730cdc88
ILT
1502Output_section::add_input_section(Sized_relobj<size, big_endian>* object,
1503 unsigned int shndx,
ead1e424 1504 const char* secname,
730cdc88
ILT
1505 const elfcpp::Shdr<size, big_endian>& shdr,
1506 unsigned int reloc_shndx)
a2fb1b05
ILT
1507{
1508 elfcpp::Elf_Xword addralign = shdr.get_sh_addralign();
1509 if ((addralign & (addralign - 1)) != 0)
1510 {
75f2446e
ILT
1511 object->error(_("invalid alignment %lu for section \"%s\""),
1512 static_cast<unsigned long>(addralign), secname);
1513 addralign = 1;
a2fb1b05 1514 }
a2fb1b05
ILT
1515
1516 if (addralign > this->addralign_)
1517 this->addralign_ = addralign;
1518
44a43cf9 1519 typename elfcpp::Elf_types<size>::Elf_WXword sh_flags = shdr.get_sh_flags();
4f833eee 1520 uint64_t entsize = shdr.get_sh_entsize();
44a43cf9
ILT
1521
1522 // .debug_str is a mergeable string section, but is not always so
1523 // marked by compilers. Mark manually here so we can optimize.
1524 if (strcmp(secname, ".debug_str") == 0)
4f833eee
ILT
1525 {
1526 sh_flags |= (elfcpp::SHF_MERGE | elfcpp::SHF_STRINGS);
1527 entsize = 1;
1528 }
44a43cf9 1529
b8e6aad9 1530 // If this is a SHF_MERGE section, we pass all the input sections to
730cdc88
ILT
1531 // a Output_data_merge. We don't try to handle relocations for such
1532 // a section.
44a43cf9 1533 if ((sh_flags & elfcpp::SHF_MERGE) != 0
730cdc88 1534 && reloc_shndx == 0)
b8e6aad9 1535 {
44a43cf9 1536 if (this->add_merge_input_section(object, shndx, sh_flags,
96803768 1537 entsize, addralign))
b8e6aad9
ILT
1538 {
1539 // Tell the relocation routines that they need to call the
730cdc88 1540 // output_offset method to determine the final address.
b8e6aad9
ILT
1541 return -1;
1542 }
1543 }
1544
27bc2bce 1545 off_t offset_in_section = this->current_data_size_for_child();
c51e6221
ILT
1546 off_t aligned_offset_in_section = align_address(offset_in_section,
1547 addralign);
1548
1549 if (aligned_offset_in_section > offset_in_section
44a43cf9 1550 && (sh_flags & elfcpp::SHF_EXECINSTR) != 0
c51e6221
ILT
1551 && object->target()->has_code_fill())
1552 {
1553 // We need to add some fill data. Using fill_list_ when
1554 // possible is an optimization, since we will often have fill
1555 // sections without input sections.
1556 off_t fill_len = aligned_offset_in_section - offset_in_section;
1557 if (this->input_sections_.empty())
1558 this->fills_.push_back(Fill(offset_in_section, fill_len));
1559 else
1560 {
1561 // FIXME: When relaxing, the size needs to adjust to
1562 // maintain a constant alignment.
1563 std::string fill_data(object->target()->code_fill(fill_len));
1564 Output_data_const* odc = new Output_data_const(fill_data, 1);
1565 this->input_sections_.push_back(Input_section(odc));
1566 }
1567 }
1568
27bc2bce
ILT
1569 this->set_current_data_size_for_child(aligned_offset_in_section
1570 + shdr.get_sh_size());
a2fb1b05 1571
ead1e424
ILT
1572 // We need to keep track of this section if we are already keeping
1573 // track of sections, or if we are relaxing. FIXME: Add test for
1574 // relaxing.
c51e6221 1575 if (!this->input_sections_.empty())
ead1e424
ILT
1576 this->input_sections_.push_back(Input_section(object, shndx,
1577 shdr.get_sh_size(),
1578 addralign));
54dc6425 1579
c51e6221 1580 return aligned_offset_in_section;
61ba1cf9
ILT
1581}
1582
ead1e424
ILT
1583// Add arbitrary data to an output section.
1584
1585void
1586Output_section::add_output_section_data(Output_section_data* posd)
1587{
b8e6aad9
ILT
1588 Input_section inp(posd);
1589 this->add_output_section_data(&inp);
1590}
1591
1592// Add arbitrary data to an output section by Input_section.
c06b7b0b 1593
b8e6aad9
ILT
1594void
1595Output_section::add_output_section_data(Input_section* inp)
1596{
ead1e424 1597 if (this->input_sections_.empty())
27bc2bce 1598 this->first_input_offset_ = this->current_data_size_for_child();
c06b7b0b 1599
b8e6aad9 1600 this->input_sections_.push_back(*inp);
c06b7b0b 1601
b8e6aad9 1602 uint64_t addralign = inp->addralign();
ead1e424
ILT
1603 if (addralign > this->addralign_)
1604 this->addralign_ = addralign;
c06b7b0b 1605
b8e6aad9
ILT
1606 inp->set_output_section(this);
1607}
1608
1609// Add a merge section to an output section.
1610
1611void
1612Output_section::add_output_merge_section(Output_section_data* posd,
1613 bool is_string, uint64_t entsize)
1614{
1615 Input_section inp(posd, is_string, entsize);
1616 this->add_output_section_data(&inp);
1617}
1618
1619// Add an input section to a SHF_MERGE section.
1620
1621bool
1622Output_section::add_merge_input_section(Relobj* object, unsigned int shndx,
1623 uint64_t flags, uint64_t entsize,
96803768 1624 uint64_t addralign)
b8e6aad9 1625{
87f95776
ILT
1626 bool is_string = (flags & elfcpp::SHF_STRINGS) != 0;
1627
1628 // We only merge strings if the alignment is not more than the
1629 // character size. This could be handled, but it's unusual.
1630 if (is_string && addralign > entsize)
b8e6aad9
ILT
1631 return false;
1632
b8e6aad9
ILT
1633 Input_section_list::iterator p;
1634 for (p = this->input_sections_.begin();
1635 p != this->input_sections_.end();
1636 ++p)
87f95776 1637 if (p->is_merge_section(is_string, entsize, addralign))
9a0910c3
ILT
1638 {
1639 p->add_input_section(object, shndx);
1640 return true;
1641 }
b8e6aad9
ILT
1642
1643 // We handle the actual constant merging in Output_merge_data or
1644 // Output_merge_string_data.
9a0910c3
ILT
1645 Output_section_data* posd;
1646 if (!is_string)
1647 posd = new Output_merge_data(entsize, addralign);
b8e6aad9
ILT
1648 else
1649 {
9a0910c3
ILT
1650 switch (entsize)
1651 {
1652 case 1:
1653 posd = new Output_merge_string<char>(addralign);
1654 break;
1655 case 2:
1656 posd = new Output_merge_string<uint16_t>(addralign);
1657 break;
1658 case 4:
1659 posd = new Output_merge_string<uint32_t>(addralign);
1660 break;
1661 default:
1662 return false;
1663 }
b8e6aad9
ILT
1664 }
1665
9a0910c3
ILT
1666 this->add_output_merge_section(posd, is_string, entsize);
1667 posd->add_input_section(object, shndx);
1668
b8e6aad9
ILT
1669 return true;
1670}
1671
730cdc88
ILT
1672// Given an address OFFSET relative to the start of input section
1673// SHNDX in OBJECT, return whether this address is being included in
1674// the final link. This should only be called if SHNDX in OBJECT has
1675// a special mapping.
1676
1677bool
1678Output_section::is_input_address_mapped(const Relobj* object,
1679 unsigned int shndx,
1680 off_t offset) const
1681{
1682 gold_assert(object->is_section_specially_mapped(shndx));
1683
1684 for (Input_section_list::const_iterator p = this->input_sections_.begin();
1685 p != this->input_sections_.end();
1686 ++p)
1687 {
8383303e 1688 section_offset_type output_offset;
730cdc88
ILT
1689 if (p->output_offset(object, shndx, offset, &output_offset))
1690 return output_offset != -1;
1691 }
1692
1693 // By default we assume that the address is mapped. This should
1694 // only be called after we have passed all sections to Layout. At
1695 // that point we should know what we are discarding.
1696 return true;
1697}
1698
1699// Given an address OFFSET relative to the start of input section
1700// SHNDX in object OBJECT, return the output offset relative to the
1e983657
ILT
1701// start of the input section in the output section. This should only
1702// be called if SHNDX in OBJECT has a special mapping.
730cdc88 1703
8383303e 1704section_offset_type
730cdc88 1705Output_section::output_offset(const Relobj* object, unsigned int shndx,
8383303e 1706 section_offset_type offset) const
730cdc88
ILT
1707{
1708 gold_assert(object->is_section_specially_mapped(shndx));
1709 // This can only be called meaningfully when layout is complete.
1710 gold_assert(Output_data::is_layout_complete());
1711
1712 for (Input_section_list::const_iterator p = this->input_sections_.begin();
1713 p != this->input_sections_.end();
1714 ++p)
1715 {
8383303e 1716 section_offset_type output_offset;
730cdc88
ILT
1717 if (p->output_offset(object, shndx, offset, &output_offset))
1718 return output_offset;
1719 }
1720 gold_unreachable();
1721}
1722
b8e6aad9
ILT
1723// Return the output virtual address of OFFSET relative to the start
1724// of input section SHNDX in object OBJECT.
1725
1726uint64_t
1727Output_section::output_address(const Relobj* object, unsigned int shndx,
1728 off_t offset) const
1729{
730cdc88 1730 gold_assert(object->is_section_specially_mapped(shndx));
730cdc88 1731
b8e6aad9
ILT
1732 uint64_t addr = this->address() + this->first_input_offset_;
1733 for (Input_section_list::const_iterator p = this->input_sections_.begin();
1734 p != this->input_sections_.end();
1735 ++p)
1736 {
1737 addr = align_address(addr, p->addralign());
8383303e 1738 section_offset_type output_offset;
730cdc88
ILT
1739 if (p->output_offset(object, shndx, offset, &output_offset))
1740 {
1741 if (output_offset == -1)
1742 return -1U;
1743 return addr + output_offset;
1744 }
b8e6aad9
ILT
1745 addr += p->data_size();
1746 }
1747
1748 // If we get here, it means that we don't know the mapping for this
1749 // input section. This might happen in principle if
1750 // add_input_section were called before add_output_section_data.
1751 // But it should never actually happen.
1752
1753 gold_unreachable();
ead1e424
ILT
1754}
1755
a9a60db6
ILT
1756// Return the output address of the start of the merged section for
1757// input section SHNDX in object OBJECT.
1758
1759uint64_t
1760Output_section::starting_output_address(const Relobj* object,
1761 unsigned int shndx) const
1762{
1763 gold_assert(object->is_section_specially_mapped(shndx));
1764
1765 uint64_t addr = this->address() + this->first_input_offset_;
1766 for (Input_section_list::const_iterator p = this->input_sections_.begin();
1767 p != this->input_sections_.end();
1768 ++p)
1769 {
1770 addr = align_address(addr, p->addralign());
1771
1772 // It would be nice if we could use the existing output_offset
1773 // method to get the output offset of input offset 0.
1774 // Unfortunately we don't know for sure that input offset 0 is
1775 // mapped at all.
1776 if (p->is_merge_section_for(object, shndx))
1777 return addr;
1778
1779 addr += p->data_size();
1780 }
1781 gold_unreachable();
1782}
1783
27bc2bce 1784// Set the data size of an Output_section. This is where we handle
ead1e424
ILT
1785// setting the addresses of any Output_section_data objects.
1786
1787void
27bc2bce 1788Output_section::set_final_data_size()
ead1e424
ILT
1789{
1790 if (this->input_sections_.empty())
27bc2bce
ILT
1791 {
1792 this->set_data_size(this->current_data_size_for_child());
1793 return;
1794 }
ead1e424 1795
27bc2bce
ILT
1796 uint64_t address = this->address();
1797 off_t startoff = this->offset();
ead1e424
ILT
1798 off_t off = startoff + this->first_input_offset_;
1799 for (Input_section_list::iterator p = this->input_sections_.begin();
1800 p != this->input_sections_.end();
1801 ++p)
1802 {
1803 off = align_address(off, p->addralign());
96803768
ILT
1804 p->set_address_and_file_offset(address + (off - startoff), off,
1805 startoff);
ead1e424
ILT
1806 off += p->data_size();
1807 }
1808
1809 this->set_data_size(off - startoff);
1810}
9a0910c3 1811
7bf1f802
ILT
1812// Set the TLS offset. Called only for SHT_TLS sections.
1813
1814void
1815Output_section::do_set_tls_offset(uint64_t tls_base)
1816{
1817 this->tls_offset_ = this->address() - tls_base;
1818}
1819
61ba1cf9
ILT
1820// Write the section header to *OSHDR.
1821
1822template<int size, bool big_endian>
1823void
16649710
ILT
1824Output_section::write_header(const Layout* layout,
1825 const Stringpool* secnamepool,
61ba1cf9
ILT
1826 elfcpp::Shdr_write<size, big_endian>* oshdr) const
1827{
1828 oshdr->put_sh_name(secnamepool->get_offset(this->name_));
1829 oshdr->put_sh_type(this->type_);
1830 oshdr->put_sh_flags(this->flags_);
1831 oshdr->put_sh_addr(this->address());
1832 oshdr->put_sh_offset(this->offset());
1833 oshdr->put_sh_size(this->data_size());
16649710
ILT
1834 if (this->link_section_ != NULL)
1835 oshdr->put_sh_link(this->link_section_->out_shndx());
1836 else if (this->should_link_to_symtab_)
1837 oshdr->put_sh_link(layout->symtab_section()->out_shndx());
1838 else if (this->should_link_to_dynsym_)
1839 oshdr->put_sh_link(layout->dynsym_section()->out_shndx());
1840 else
1841 oshdr->put_sh_link(this->link_);
1842 if (this->info_section_ != NULL)
1843 oshdr->put_sh_info(this->info_section_->out_shndx());
1844 else
1845 oshdr->put_sh_info(this->info_);
61ba1cf9
ILT
1846 oshdr->put_sh_addralign(this->addralign_);
1847 oshdr->put_sh_entsize(this->entsize_);
a2fb1b05
ILT
1848}
1849
ead1e424
ILT
1850// Write out the data. For input sections the data is written out by
1851// Object::relocate, but we have to handle Output_section_data objects
1852// here.
1853
1854void
1855Output_section::do_write(Output_file* of)
1856{
96803768
ILT
1857 gold_assert(!this->requires_postprocessing());
1858
c51e6221
ILT
1859 off_t output_section_file_offset = this->offset();
1860 for (Fill_list::iterator p = this->fills_.begin();
1861 p != this->fills_.end();
1862 ++p)
1863 {
1864 std::string fill_data(of->target()->code_fill(p->length()));
1865 of->write(output_section_file_offset + p->section_offset(),
1866 fill_data.data(), fill_data.size());
1867 }
1868
ead1e424
ILT
1869 for (Input_section_list::iterator p = this->input_sections_.begin();
1870 p != this->input_sections_.end();
1871 ++p)
1872 p->write(of);
1873}
1874
96803768
ILT
1875// If a section requires postprocessing, create the buffer to use.
1876
1877void
1878Output_section::create_postprocessing_buffer()
1879{
1880 gold_assert(this->requires_postprocessing());
1bedcac5
ILT
1881
1882 if (this->postprocessing_buffer_ != NULL)
1883 return;
96803768
ILT
1884
1885 if (!this->input_sections_.empty())
1886 {
1887 off_t off = this->first_input_offset_;
1888 for (Input_section_list::iterator p = this->input_sections_.begin();
1889 p != this->input_sections_.end();
1890 ++p)
1891 {
1892 off = align_address(off, p->addralign());
1893 p->finalize_data_size();
1894 off += p->data_size();
1895 }
1896 this->set_current_data_size_for_child(off);
1897 }
1898
1899 off_t buffer_size = this->current_data_size_for_child();
1900 this->postprocessing_buffer_ = new unsigned char[buffer_size];
1901}
1902
1903// Write all the data of an Output_section into the postprocessing
1904// buffer. This is used for sections which require postprocessing,
1905// such as compression. Input sections are handled by
1906// Object::Relocate.
1907
1908void
1909Output_section::write_to_postprocessing_buffer()
1910{
1911 gold_assert(this->requires_postprocessing());
1912
1913 Target* target = parameters->target();
1914 unsigned char* buffer = this->postprocessing_buffer();
1915 for (Fill_list::iterator p = this->fills_.begin();
1916 p != this->fills_.end();
1917 ++p)
1918 {
1919 std::string fill_data(target->code_fill(p->length()));
1920 memcpy(buffer + p->section_offset(), fill_data.data(), fill_data.size());
1921 }
1922
1923 off_t off = this->first_input_offset_;
1924 for (Input_section_list::iterator p = this->input_sections_.begin();
1925 p != this->input_sections_.end();
1926 ++p)
1927 {
1928 off = align_address(off, p->addralign());
1929 p->write_to_buffer(buffer + off);
1930 off += p->data_size();
1931 }
1932}
1933
38c5e8b4
ILT
1934// Print stats for merge sections to stderr.
1935
1936void
1937Output_section::print_merge_stats()
1938{
1939 Input_section_list::iterator p;
1940 for (p = this->input_sections_.begin();
1941 p != this->input_sections_.end();
1942 ++p)
1943 p->print_merge_stats(this->name_);
1944}
1945
a2fb1b05
ILT
1946// Output segment methods.
1947
1948Output_segment::Output_segment(elfcpp::Elf_Word type, elfcpp::Elf_Word flags)
54dc6425 1949 : output_data_(),
75f65a3e 1950 output_bss_(),
a2fb1b05
ILT
1951 vaddr_(0),
1952 paddr_(0),
1953 memsz_(0),
1954 align_(0),
1955 offset_(0),
1956 filesz_(0),
1957 type_(type),
ead1e424
ILT
1958 flags_(flags),
1959 is_align_known_(false)
a2fb1b05
ILT
1960{
1961}
1962
1963// Add an Output_section to an Output_segment.
1964
1965void
75f65a3e 1966Output_segment::add_output_section(Output_section* os,
dbe717ef
ILT
1967 elfcpp::Elf_Word seg_flags,
1968 bool front)
a2fb1b05 1969{
a3ad94ed
ILT
1970 gold_assert((os->flags() & elfcpp::SHF_ALLOC) != 0);
1971 gold_assert(!this->is_align_known_);
75f65a3e 1972
ead1e424 1973 // Update the segment flags.
75f65a3e 1974 this->flags_ |= seg_flags;
75f65a3e
ILT
1975
1976 Output_segment::Output_data_list* pdl;
1977 if (os->type() == elfcpp::SHT_NOBITS)
1978 pdl = &this->output_bss_;
1979 else
1980 pdl = &this->output_data_;
54dc6425 1981
a2fb1b05
ILT
1982 // So that PT_NOTE segments will work correctly, we need to ensure
1983 // that all SHT_NOTE sections are adjacent. This will normally
1984 // happen automatically, because all the SHT_NOTE input sections
1985 // will wind up in the same output section. However, it is possible
1986 // for multiple SHT_NOTE input sections to have different section
1987 // flags, and thus be in different output sections, but for the
1988 // different section flags to map into the same segment flags and
1989 // thus the same output segment.
54dc6425
ILT
1990
1991 // Note that while there may be many input sections in an output
1992 // section, there are normally only a few output sections in an
1993 // output segment. This loop is expected to be fast.
1994
61ba1cf9 1995 if (os->type() == elfcpp::SHT_NOTE && !pdl->empty())
a2fb1b05 1996 {
a3ad94ed 1997 Output_segment::Output_data_list::iterator p = pdl->end();
75f65a3e 1998 do
54dc6425 1999 {
75f65a3e 2000 --p;
54dc6425
ILT
2001 if ((*p)->is_section_type(elfcpp::SHT_NOTE))
2002 {
dbe717ef 2003 // We don't worry about the FRONT parameter.
54dc6425 2004 ++p;
75f65a3e 2005 pdl->insert(p, os);
54dc6425
ILT
2006 return;
2007 }
2008 }
75f65a3e 2009 while (p != pdl->begin());
54dc6425
ILT
2010 }
2011
2012 // Similarly, so that PT_TLS segments will work, we need to group
75f65a3e
ILT
2013 // SHF_TLS sections. An SHF_TLS/SHT_NOBITS section is a special
2014 // case: we group the SHF_TLS/SHT_NOBITS sections right after the
2015 // SHF_TLS/SHT_PROGBITS sections. This lets us set up PT_TLS
07f397ab
ILT
2016 // correctly. SHF_TLS sections get added to both a PT_LOAD segment
2017 // and the PT_TLS segment -- we do this grouping only for the
2018 // PT_LOAD segment.
2019 if (this->type_ != elfcpp::PT_TLS
2020 && (os->flags() & elfcpp::SHF_TLS) != 0
2021 && !this->output_data_.empty())
54dc6425 2022 {
75f65a3e
ILT
2023 pdl = &this->output_data_;
2024 bool nobits = os->type() == elfcpp::SHT_NOBITS;
ead1e424 2025 bool sawtls = false;
a3ad94ed 2026 Output_segment::Output_data_list::iterator p = pdl->end();
75f65a3e 2027 do
a2fb1b05 2028 {
75f65a3e 2029 --p;
ead1e424
ILT
2030 bool insert;
2031 if ((*p)->is_section_flag_set(elfcpp::SHF_TLS))
2032 {
2033 sawtls = true;
2034 // Put a NOBITS section after the first TLS section.
2035 // But a PROGBITS section after the first TLS/PROGBITS
2036 // section.
2037 insert = nobits || !(*p)->is_section_type(elfcpp::SHT_NOBITS);
2038 }
2039 else
2040 {
2041 // If we've gone past the TLS sections, but we've seen a
2042 // TLS section, then we need to insert this section now.
2043 insert = sawtls;
2044 }
2045
2046 if (insert)
a2fb1b05 2047 {
dbe717ef 2048 // We don't worry about the FRONT parameter.
a2fb1b05 2049 ++p;
75f65a3e 2050 pdl->insert(p, os);
a2fb1b05
ILT
2051 return;
2052 }
2053 }
75f65a3e 2054 while (p != pdl->begin());
ead1e424 2055
dbe717ef
ILT
2056 // There are no TLS sections yet; put this one at the requested
2057 // location in the section list.
a2fb1b05
ILT
2058 }
2059
dbe717ef
ILT
2060 if (front)
2061 pdl->push_front(os);
2062 else
2063 pdl->push_back(os);
75f65a3e
ILT
2064}
2065
2066// Add an Output_data (which is not an Output_section) to the start of
2067// a segment.
2068
2069void
2070Output_segment::add_initial_output_data(Output_data* od)
2071{
a3ad94ed 2072 gold_assert(!this->is_align_known_);
75f65a3e
ILT
2073 this->output_data_.push_front(od);
2074}
2075
2076// Return the maximum alignment of the Output_data in Output_segment.
ead1e424 2077// Once we compute this, we prohibit new sections from being added.
75f65a3e
ILT
2078
2079uint64_t
ead1e424 2080Output_segment::addralign()
75f65a3e 2081{
ead1e424
ILT
2082 if (!this->is_align_known_)
2083 {
2084 uint64_t addralign;
2085
2086 addralign = Output_segment::maximum_alignment(&this->output_data_);
2087 if (addralign > this->align_)
2088 this->align_ = addralign;
2089
2090 addralign = Output_segment::maximum_alignment(&this->output_bss_);
2091 if (addralign > this->align_)
2092 this->align_ = addralign;
2093
2094 this->is_align_known_ = true;
2095 }
2096
75f65a3e
ILT
2097 return this->align_;
2098}
2099
ead1e424
ILT
2100// Return the maximum alignment of a list of Output_data.
2101
2102uint64_t
2103Output_segment::maximum_alignment(const Output_data_list* pdl)
2104{
2105 uint64_t ret = 0;
2106 for (Output_data_list::const_iterator p = pdl->begin();
2107 p != pdl->end();
2108 ++p)
2109 {
2110 uint64_t addralign = (*p)->addralign();
2111 if (addralign > ret)
2112 ret = addralign;
2113 }
2114 return ret;
2115}
2116
4f4c5f80
ILT
2117// Return the number of dynamic relocs applied to this segment.
2118
2119unsigned int
2120Output_segment::dynamic_reloc_count() const
2121{
2122 return (this->dynamic_reloc_count_list(&this->output_data_)
2123 + this->dynamic_reloc_count_list(&this->output_bss_));
2124}
2125
2126// Return the number of dynamic relocs applied to an Output_data_list.
2127
2128unsigned int
2129Output_segment::dynamic_reloc_count_list(const Output_data_list* pdl) const
2130{
2131 unsigned int count = 0;
2132 for (Output_data_list::const_iterator p = pdl->begin();
2133 p != pdl->end();
2134 ++p)
2135 count += (*p)->dynamic_reloc_count();
2136 return count;
2137}
2138
75f65a3e 2139// Set the section addresses for an Output_segment. ADDR is the
ead1e424
ILT
2140// address and *POFF is the file offset. Set the section indexes
2141// starting with *PSHNDX. Return the address of the immediately
2142// following segment. Update *POFF and *PSHNDX.
75f65a3e
ILT
2143
2144uint64_t
ead1e424
ILT
2145Output_segment::set_section_addresses(uint64_t addr, off_t* poff,
2146 unsigned int* pshndx)
75f65a3e 2147{
a3ad94ed 2148 gold_assert(this->type_ == elfcpp::PT_LOAD);
75f65a3e
ILT
2149
2150 this->vaddr_ = addr;
2151 this->paddr_ = addr;
2152
2153 off_t orig_off = *poff;
2154 this->offset_ = orig_off;
2155
ead1e424
ILT
2156 *poff = align_address(*poff, this->addralign());
2157
2158 addr = this->set_section_list_addresses(&this->output_data_, addr, poff,
2159 pshndx);
75f65a3e
ILT
2160 this->filesz_ = *poff - orig_off;
2161
2162 off_t off = *poff;
2163
61ba1cf9 2164 uint64_t ret = this->set_section_list_addresses(&this->output_bss_, addr,
ead1e424 2165 poff, pshndx);
75f65a3e
ILT
2166 this->memsz_ = *poff - orig_off;
2167
2168 // Ignore the file offset adjustments made by the BSS Output_data
2169 // objects.
2170 *poff = off;
61ba1cf9
ILT
2171
2172 return ret;
75f65a3e
ILT
2173}
2174
b8e6aad9
ILT
2175// Set the addresses and file offsets in a list of Output_data
2176// structures.
75f65a3e
ILT
2177
2178uint64_t
2179Output_segment::set_section_list_addresses(Output_data_list* pdl,
ead1e424
ILT
2180 uint64_t addr, off_t* poff,
2181 unsigned int* pshndx)
75f65a3e 2182{
ead1e424 2183 off_t startoff = *poff;
75f65a3e 2184
ead1e424 2185 off_t off = startoff;
75f65a3e
ILT
2186 for (Output_data_list::iterator p = pdl->begin();
2187 p != pdl->end();
2188 ++p)
2189 {
ead1e424 2190 off = align_address(off, (*p)->addralign());
27bc2bce 2191 (*p)->set_address_and_file_offset(addr + (off - startoff), off);
ead1e424
ILT
2192
2193 // Unless this is a PT_TLS segment, we want to ignore the size
2194 // of a SHF_TLS/SHT_NOBITS section. Such a section does not
2195 // affect the size of a PT_LOAD segment.
2196 if (this->type_ == elfcpp::PT_TLS
2197 || !(*p)->is_section_flag_set(elfcpp::SHF_TLS)
2198 || !(*p)->is_section_type(elfcpp::SHT_NOBITS))
2199 off += (*p)->data_size();
75f65a3e 2200
ead1e424
ILT
2201 if ((*p)->is_section())
2202 {
2203 (*p)->set_out_shndx(*pshndx);
2204 ++*pshndx;
2205 }
75f65a3e
ILT
2206 }
2207
2208 *poff = off;
ead1e424 2209 return addr + (off - startoff);
75f65a3e
ILT
2210}
2211
2212// For a non-PT_LOAD segment, set the offset from the sections, if
2213// any.
2214
2215void
2216Output_segment::set_offset()
2217{
a3ad94ed 2218 gold_assert(this->type_ != elfcpp::PT_LOAD);
75f65a3e
ILT
2219
2220 if (this->output_data_.empty() && this->output_bss_.empty())
2221 {
2222 this->vaddr_ = 0;
2223 this->paddr_ = 0;
2224 this->memsz_ = 0;
2225 this->align_ = 0;
2226 this->offset_ = 0;
2227 this->filesz_ = 0;
2228 return;
2229 }
2230
2231 const Output_data* first;
2232 if (this->output_data_.empty())
2233 first = this->output_bss_.front();
2234 else
2235 first = this->output_data_.front();
2236 this->vaddr_ = first->address();
2237 this->paddr_ = this->vaddr_;
2238 this->offset_ = first->offset();
2239
2240 if (this->output_data_.empty())
2241 this->filesz_ = 0;
2242 else
2243 {
2244 const Output_data* last_data = this->output_data_.back();
2245 this->filesz_ = (last_data->address()
2246 + last_data->data_size()
2247 - this->vaddr_);
2248 }
2249
2250 const Output_data* last;
2251 if (this->output_bss_.empty())
2252 last = this->output_data_.back();
2253 else
2254 last = this->output_bss_.back();
2255 this->memsz_ = (last->address()
2256 + last->data_size()
2257 - this->vaddr_);
75f65a3e
ILT
2258}
2259
7bf1f802
ILT
2260// Set the TLS offsets of the sections in the PT_TLS segment.
2261
2262void
2263Output_segment::set_tls_offsets()
2264{
2265 gold_assert(this->type_ == elfcpp::PT_TLS);
2266
2267 for (Output_data_list::iterator p = this->output_data_.begin();
2268 p != this->output_data_.end();
2269 ++p)
2270 (*p)->set_tls_offset(this->vaddr_);
2271
2272 for (Output_data_list::iterator p = this->output_bss_.begin();
2273 p != this->output_bss_.end();
2274 ++p)
2275 (*p)->set_tls_offset(this->vaddr_);
2276}
2277
75f65a3e
ILT
2278// Return the number of Output_sections in an Output_segment.
2279
2280unsigned int
2281Output_segment::output_section_count() const
2282{
2283 return (this->output_section_count_list(&this->output_data_)
2284 + this->output_section_count_list(&this->output_bss_));
2285}
2286
2287// Return the number of Output_sections in an Output_data_list.
2288
2289unsigned int
2290Output_segment::output_section_count_list(const Output_data_list* pdl) const
2291{
2292 unsigned int count = 0;
2293 for (Output_data_list::const_iterator p = pdl->begin();
2294 p != pdl->end();
2295 ++p)
2296 {
2297 if ((*p)->is_section())
2298 ++count;
2299 }
2300 return count;
a2fb1b05
ILT
2301}
2302
61ba1cf9
ILT
2303// Write the segment data into *OPHDR.
2304
2305template<int size, bool big_endian>
2306void
ead1e424 2307Output_segment::write_header(elfcpp::Phdr_write<size, big_endian>* ophdr)
61ba1cf9
ILT
2308{
2309 ophdr->put_p_type(this->type_);
2310 ophdr->put_p_offset(this->offset_);
2311 ophdr->put_p_vaddr(this->vaddr_);
2312 ophdr->put_p_paddr(this->paddr_);
2313 ophdr->put_p_filesz(this->filesz_);
2314 ophdr->put_p_memsz(this->memsz_);
2315 ophdr->put_p_flags(this->flags_);
ead1e424 2316 ophdr->put_p_align(this->addralign());
61ba1cf9
ILT
2317}
2318
2319// Write the section headers into V.
2320
2321template<int size, bool big_endian>
2322unsigned char*
16649710
ILT
2323Output_segment::write_section_headers(const Layout* layout,
2324 const Stringpool* secnamepool,
ead1e424
ILT
2325 unsigned char* v,
2326 unsigned int *pshndx
5482377d
ILT
2327 ACCEPT_SIZE_ENDIAN) const
2328{
ead1e424
ILT
2329 // Every section that is attached to a segment must be attached to a
2330 // PT_LOAD segment, so we only write out section headers for PT_LOAD
2331 // segments.
2332 if (this->type_ != elfcpp::PT_LOAD)
2333 return v;
2334
593f47df
ILT
2335 v = this->write_section_headers_list
2336 SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
16649710 2337 layout, secnamepool, &this->output_data_, v, pshndx
593f47df
ILT
2338 SELECT_SIZE_ENDIAN(size, big_endian));
2339 v = this->write_section_headers_list
2340 SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
16649710 2341 layout, secnamepool, &this->output_bss_, v, pshndx
593f47df 2342 SELECT_SIZE_ENDIAN(size, big_endian));
61ba1cf9
ILT
2343 return v;
2344}
2345
2346template<int size, bool big_endian>
2347unsigned char*
16649710
ILT
2348Output_segment::write_section_headers_list(const Layout* layout,
2349 const Stringpool* secnamepool,
61ba1cf9 2350 const Output_data_list* pdl,
ead1e424
ILT
2351 unsigned char* v,
2352 unsigned int* pshndx
5482377d 2353 ACCEPT_SIZE_ENDIAN) const
61ba1cf9
ILT
2354{
2355 const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
2356 for (Output_data_list::const_iterator p = pdl->begin();
2357 p != pdl->end();
2358 ++p)
2359 {
2360 if ((*p)->is_section())
2361 {
5482377d 2362 const Output_section* ps = static_cast<const Output_section*>(*p);
a3ad94ed 2363 gold_assert(*pshndx == ps->out_shndx());
61ba1cf9 2364 elfcpp::Shdr_write<size, big_endian> oshdr(v);
16649710 2365 ps->write_header(layout, secnamepool, &oshdr);
61ba1cf9 2366 v += shdr_size;
ead1e424 2367 ++*pshndx;
61ba1cf9
ILT
2368 }
2369 }
2370 return v;
2371}
2372
a2fb1b05
ILT
2373// Output_file methods.
2374
c51e6221 2375Output_file::Output_file(const General_options& options, Target* target)
61ba1cf9 2376 : options_(options),
c51e6221 2377 target_(target),
61ba1cf9
ILT
2378 name_(options.output_file_name()),
2379 o_(-1),
2380 file_size_(0),
c420411f
ILT
2381 base_(NULL),
2382 map_is_anonymous_(false)
61ba1cf9
ILT
2383{
2384}
2385
2386// Open the output file.
2387
a2fb1b05 2388void
61ba1cf9 2389Output_file::open(off_t file_size)
a2fb1b05 2390{
61ba1cf9
ILT
2391 this->file_size_ = file_size;
2392
4e9d8586
ILT
2393 // Unlink the file first; otherwise the open() may fail if the file
2394 // is busy (e.g. it's an executable that's currently being executed).
2395 //
2396 // However, the linker may be part of a system where a zero-length
2397 // file is created for it to write to, with tight permissions (gcc
2398 // 2.95 did something like this). Unlinking the file would work
2399 // around those permission controls, so we only unlink if the file
2400 // has a non-zero size. We also unlink only regular files to avoid
2401 // trouble with directories/etc.
2402 //
2403 // If we fail, continue; this command is merely a best-effort attempt
2404 // to improve the odds for open().
2405
42a1b686
ILT
2406 // We let the name "-" mean "stdout"
2407 if (strcmp(this->name_, "-") == 0)
2408 this->o_ = STDOUT_FILENO;
2409 else
2410 {
2411 struct stat s;
2412 if (::stat(this->name_, &s) == 0 && s.st_size != 0)
2413 unlink_if_ordinary(this->name_);
2414
2415 int mode = parameters->output_is_object() ? 0666 : 0777;
2416 int o = ::open(this->name_, O_RDWR | O_CREAT | O_TRUNC, mode);
2417 if (o < 0)
2418 gold_fatal(_("%s: open: %s"), this->name_, strerror(errno));
2419 this->o_ = o;
2420 }
61ba1cf9 2421
27bc2bce
ILT
2422 this->map();
2423}
2424
2425// Resize the output file.
2426
2427void
2428Output_file::resize(off_t file_size)
2429{
c420411f
ILT
2430 // If the mmap is mapping an anonymous memory buffer, this is easy:
2431 // just mremap to the new size. If it's mapping to a file, we want
2432 // to unmap to flush to the file, then remap after growing the file.
2433 if (this->map_is_anonymous_)
2434 {
2435 void* base = ::mremap(this->base_, this->file_size_, file_size,
2436 MREMAP_MAYMOVE);
2437 if (base == MAP_FAILED)
2438 gold_fatal(_("%s: mremap: %s"), this->name_, strerror(errno));
2439 this->base_ = static_cast<unsigned char*>(base);
2440 this->file_size_ = file_size;
2441 }
2442 else
2443 {
2444 this->unmap();
2445 this->file_size_ = file_size;
2446 this->map();
2447 }
27bc2bce
ILT
2448}
2449
2450// Map the file into memory.
2451
2452void
2453Output_file::map()
2454{
c420411f 2455 const int o = this->o_;
61ba1cf9 2456
c420411f
ILT
2457 // If the output file is not a regular file, don't try to mmap it;
2458 // instead, we'll mmap a block of memory (an anonymous buffer), and
2459 // then later write the buffer to the file.
2460 void* base;
2461 struct stat statbuf;
42a1b686
ILT
2462 if (o == STDOUT_FILENO || o == STDERR_FILENO
2463 || ::fstat(o, &statbuf) != 0
c420411f
ILT
2464 || !S_ISREG(statbuf.st_mode))
2465 {
2466 this->map_is_anonymous_ = true;
2467 base = ::mmap(NULL, this->file_size_, PROT_READ | PROT_WRITE,
2468 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
2469 }
2470 else
2471 {
2472 // Write out one byte to make the file the right size.
2473 if (::lseek(o, this->file_size_ - 1, SEEK_SET) < 0)
2474 gold_fatal(_("%s: lseek: %s"), this->name_, strerror(errno));
2475 char b = 0;
2476 if (::write(o, &b, 1) != 1)
2477 gold_fatal(_("%s: write: %s"), this->name_, strerror(errno));
2478
2479 // Map the file into memory.
2480 this->map_is_anonymous_ = false;
2481 base = ::mmap(NULL, this->file_size_, PROT_READ | PROT_WRITE,
2482 MAP_SHARED, o, 0);
2483 }
61ba1cf9 2484 if (base == MAP_FAILED)
75f2446e 2485 gold_fatal(_("%s: mmap: %s"), this->name_, strerror(errno));
61ba1cf9
ILT
2486 this->base_ = static_cast<unsigned char*>(base);
2487}
2488
c420411f 2489// Unmap the file from memory.
61ba1cf9
ILT
2490
2491void
c420411f 2492Output_file::unmap()
61ba1cf9
ILT
2493{
2494 if (::munmap(this->base_, this->file_size_) < 0)
a0c4fb0a 2495 gold_error(_("%s: munmap: %s"), this->name_, strerror(errno));
61ba1cf9 2496 this->base_ = NULL;
c420411f
ILT
2497}
2498
2499// Close the output file.
2500
2501void
2502Output_file::close()
2503{
2504 // If the map isn't file-backed, we need to write it now.
2505 if (this->map_is_anonymous_)
2506 {
2507 size_t bytes_to_write = this->file_size_;
2508 while (bytes_to_write > 0)
2509 {
2510 ssize_t bytes_written = ::write(this->o_, this->base_, bytes_to_write);
2511 if (bytes_written == 0)
2512 gold_error(_("%s: write: unexpected 0 return-value"), this->name_);
2513 else if (bytes_written < 0)
2514 gold_error(_("%s: write: %s"), this->name_, strerror(errno));
2515 else
2516 bytes_to_write -= bytes_written;
2517 }
2518 }
2519 this->unmap();
61ba1cf9 2520
42a1b686
ILT
2521 // We don't close stdout or stderr
2522 if (this->o_ != STDOUT_FILENO && this->o_ != STDERR_FILENO)
2523 if (::close(this->o_) < 0)
2524 gold_error(_("%s: close: %s"), this->name_, strerror(errno));
61ba1cf9 2525 this->o_ = -1;
a2fb1b05
ILT
2526}
2527
2528// Instantiate the templates we need. We could use the configure
2529// script to restrict this to only the ones for implemented targets.
2530
193a53d9 2531#ifdef HAVE_TARGET_32_LITTLE
a2fb1b05
ILT
2532template
2533off_t
2534Output_section::add_input_section<32, false>(
730cdc88 2535 Sized_relobj<32, false>* object,
ead1e424 2536 unsigned int shndx,
a2fb1b05 2537 const char* secname,
730cdc88
ILT
2538 const elfcpp::Shdr<32, false>& shdr,
2539 unsigned int reloc_shndx);
193a53d9 2540#endif
a2fb1b05 2541
193a53d9 2542#ifdef HAVE_TARGET_32_BIG
a2fb1b05
ILT
2543template
2544off_t
2545Output_section::add_input_section<32, true>(
730cdc88 2546 Sized_relobj<32, true>* object,
ead1e424 2547 unsigned int shndx,
a2fb1b05 2548 const char* secname,
730cdc88
ILT
2549 const elfcpp::Shdr<32, true>& shdr,
2550 unsigned int reloc_shndx);
193a53d9 2551#endif
a2fb1b05 2552
193a53d9 2553#ifdef HAVE_TARGET_64_LITTLE
a2fb1b05
ILT
2554template
2555off_t
2556Output_section::add_input_section<64, false>(
730cdc88 2557 Sized_relobj<64, false>* object,
ead1e424 2558 unsigned int shndx,
a2fb1b05 2559 const char* secname,
730cdc88
ILT
2560 const elfcpp::Shdr<64, false>& shdr,
2561 unsigned int reloc_shndx);
193a53d9 2562#endif
a2fb1b05 2563
193a53d9 2564#ifdef HAVE_TARGET_64_BIG
a2fb1b05
ILT
2565template
2566off_t
2567Output_section::add_input_section<64, true>(
730cdc88 2568 Sized_relobj<64, true>* object,
ead1e424 2569 unsigned int shndx,
a2fb1b05 2570 const char* secname,
730cdc88
ILT
2571 const elfcpp::Shdr<64, true>& shdr,
2572 unsigned int reloc_shndx);
193a53d9 2573#endif
a2fb1b05 2574
193a53d9 2575#ifdef HAVE_TARGET_32_LITTLE
c06b7b0b
ILT
2576template
2577class Output_data_reloc<elfcpp::SHT_REL, false, 32, false>;
193a53d9 2578#endif
c06b7b0b 2579
193a53d9 2580#ifdef HAVE_TARGET_32_BIG
c06b7b0b
ILT
2581template
2582class Output_data_reloc<elfcpp::SHT_REL, false, 32, true>;
193a53d9 2583#endif
c06b7b0b 2584
193a53d9 2585#ifdef HAVE_TARGET_64_LITTLE
c06b7b0b
ILT
2586template
2587class Output_data_reloc<elfcpp::SHT_REL, false, 64, false>;
193a53d9 2588#endif
c06b7b0b 2589
193a53d9 2590#ifdef HAVE_TARGET_64_BIG
c06b7b0b
ILT
2591template
2592class Output_data_reloc<elfcpp::SHT_REL, false, 64, true>;
193a53d9 2593#endif
c06b7b0b 2594
193a53d9 2595#ifdef HAVE_TARGET_32_LITTLE
c06b7b0b
ILT
2596template
2597class Output_data_reloc<elfcpp::SHT_REL, true, 32, false>;
193a53d9 2598#endif
c06b7b0b 2599
193a53d9 2600#ifdef HAVE_TARGET_32_BIG
c06b7b0b
ILT
2601template
2602class Output_data_reloc<elfcpp::SHT_REL, true, 32, true>;
193a53d9 2603#endif
c06b7b0b 2604
193a53d9 2605#ifdef HAVE_TARGET_64_LITTLE
c06b7b0b
ILT
2606template
2607class Output_data_reloc<elfcpp::SHT_REL, true, 64, false>;
193a53d9 2608#endif
c06b7b0b 2609
193a53d9 2610#ifdef HAVE_TARGET_64_BIG
c06b7b0b
ILT
2611template
2612class Output_data_reloc<elfcpp::SHT_REL, true, 64, true>;
193a53d9 2613#endif
c06b7b0b 2614
193a53d9 2615#ifdef HAVE_TARGET_32_LITTLE
c06b7b0b
ILT
2616template
2617class Output_data_reloc<elfcpp::SHT_RELA, false, 32, false>;
193a53d9 2618#endif
c06b7b0b 2619
193a53d9 2620#ifdef HAVE_TARGET_32_BIG
c06b7b0b
ILT
2621template
2622class Output_data_reloc<elfcpp::SHT_RELA, false, 32, true>;
193a53d9 2623#endif
c06b7b0b 2624
193a53d9 2625#ifdef HAVE_TARGET_64_LITTLE
c06b7b0b
ILT
2626template
2627class Output_data_reloc<elfcpp::SHT_RELA, false, 64, false>;
193a53d9 2628#endif
c06b7b0b 2629
193a53d9 2630#ifdef HAVE_TARGET_64_BIG
c06b7b0b
ILT
2631template
2632class Output_data_reloc<elfcpp::SHT_RELA, false, 64, true>;
193a53d9 2633#endif
c06b7b0b 2634
193a53d9 2635#ifdef HAVE_TARGET_32_LITTLE
c06b7b0b
ILT
2636template
2637class Output_data_reloc<elfcpp::SHT_RELA, true, 32, false>;
193a53d9 2638#endif
c06b7b0b 2639
193a53d9 2640#ifdef HAVE_TARGET_32_BIG
c06b7b0b
ILT
2641template
2642class Output_data_reloc<elfcpp::SHT_RELA, true, 32, true>;
193a53d9 2643#endif
c06b7b0b 2644
193a53d9 2645#ifdef HAVE_TARGET_64_LITTLE
c06b7b0b
ILT
2646template
2647class Output_data_reloc<elfcpp::SHT_RELA, true, 64, false>;
193a53d9 2648#endif
c06b7b0b 2649
193a53d9 2650#ifdef HAVE_TARGET_64_BIG
c06b7b0b
ILT
2651template
2652class Output_data_reloc<elfcpp::SHT_RELA, true, 64, true>;
193a53d9 2653#endif
c06b7b0b 2654
193a53d9 2655#ifdef HAVE_TARGET_32_LITTLE
ead1e424 2656template
dbe717ef 2657class Output_data_got<32, false>;
193a53d9 2658#endif
ead1e424 2659
193a53d9 2660#ifdef HAVE_TARGET_32_BIG
ead1e424 2661template
dbe717ef 2662class Output_data_got<32, true>;
193a53d9 2663#endif
ead1e424 2664
193a53d9 2665#ifdef HAVE_TARGET_64_LITTLE
ead1e424 2666template
dbe717ef 2667class Output_data_got<64, false>;
193a53d9 2668#endif
ead1e424 2669
193a53d9 2670#ifdef HAVE_TARGET_64_BIG
ead1e424 2671template
dbe717ef 2672class Output_data_got<64, true>;
193a53d9 2673#endif
ead1e424 2674
a2fb1b05 2675} // End namespace gold.
This page took 0.196597 seconds and 4 git commands to generate.