]>
Commit | Line | Data |
---|---|---|
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 <[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 | ||
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 |
46 | namespace gold |
47 | { | |
48 | ||
a3ad94ed ILT |
49 | // Output_data variables. |
50 | ||
27bc2bce | 51 | bool Output_data::allocated_sizes_are_fixed; |
a3ad94ed | 52 | |
a2fb1b05 ILT |
53 | // Output_data methods. |
54 | ||
55 | Output_data::~Output_data() | |
56 | { | |
57 | } | |
58 | ||
730cdc88 ILT |
59 | // Return the default alignment for the target size. |
60 | ||
61 | uint64_t | |
62 | Output_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 | ||
69 | uint64_t | |
730cdc88 | 70 | Output_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 | ||
83 | Output_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 | 116 | void |
61ba1cf9 | 117 | Output_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 | ||
161 | template<int size, bool big_endian> | |
162 | void | |
163 | Output_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 | 211 | Output_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 | 227 | void |
61ba1cf9 | 228 | Output_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 | ||
272 | template<int size, bool big_endian> | |
273 | void | |
274 | Output_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 | 295 | Output_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 | ||
320 | void | |
321 | Output_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 | ||
330 | void | |
61ba1cf9 | 331 | Output_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 | ||
379 | template<int size, bool big_endian> | |
380 | void | |
381 | Output_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 | ||
443 | template<int size> | |
444 | typename elfcpp::Elf_types<size>::Elf_Addr | |
445 | Output_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 | ||
485 | void | |
a3ad94ed | 486 | Output_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 | ||
493 | void | |
494 | Output_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 | ||
503 | void | |
504 | Output_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 |
513 | unsigned int |
514 | Output_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 | |
524 | void | |
27bc2bce | 525 | Output_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 | ||
533 | void | |
534 | Output_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 | ||
543 | template<bool dynamic, int size, bool big_endian> | |
544 | Output_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 | ||
559 | template<bool dynamic, int size, bool big_endian> | |
560 | Output_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 | ||
579 | template<bool dynamic, int size, bool big_endian> | |
580 | Output_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 | ||
598 | template<bool dynamic, int size, bool big_endian> | |
599 | Output_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 | ||
620 | template<bool dynamic, int size, bool big_endian> | |
621 | Output_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 | ||
635 | template<bool dynamic, int size, bool big_endian> | |
636 | Output_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 | ||
654 | template<bool dynamic, int size, bool big_endian> | |
655 | unsigned int | |
656 | Output_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 | ||
700 | template<bool dynamic, int size, bool big_endian> | |
701 | template<typename Write_rel> | |
702 | void | |
703 | Output_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 | ||
731 | template<bool dynamic, int size, bool big_endian> | |
732 | void | |
733 | Output_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 | ||
742 | template<bool dynamic, int size, bool big_endian> | |
743 | typename elfcpp::Elf_types<size>::Elf_Addr | |
744 | Output_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 | ||
760 | template<bool dynamic, int size, bool big_endian> | |
761 | void | |
762 | Output_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 | ||
777 | template<int sh_type, bool dynamic, int size, bool big_endian> | |
778 | void | |
779 | Output_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 | ||
796 | template<int sh_type, bool dynamic, int size, bool big_endian> | |
797 | void | |
798 | Output_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 | ||
826 | template<int size, bool big_endian> | |
827 | void | |
7e1edb90 | 828 | Output_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 | ||
867 | template<int size, bool big_endian> | |
868 | bool | |
869 | Output_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. | |
882 | template<int size, bool big_endian> | |
883 | void | |
884 | Output_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 | ||
899 | template<int size, bool big_endian> | |
900 | void | |
901 | Output_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 | ||
920 | template<int size, bool big_endian> | |
921 | bool | |
922 | Output_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. | |
937 | template<int size, bool big_endian> | |
938 | void | |
939 | Output_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 | ||
955 | template<int size, bool big_endian> | |
956 | void | |
957 | Output_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 | ||
979 | template<int size, bool big_endian> | |
980 | bool | |
7bf1f802 | 981 | Output_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. | |
996 | template<int size, bool big_endian> | |
997 | void | |
998 | Output_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 | ||
1013 | template<int size, bool big_endian> | |
1014 | void | |
1015 | Output_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. | |
1032 | template<int size, bool big_endian> | |
1033 | void | |
1034 | Output_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 | ||
1054 | template<int size, bool big_endian> | |
1055 | void | |
1056 | Output_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 | ||
1082 | template<int size, bool big_endian> | |
1083 | bool | |
1084 | Output_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. | |
1105 | template<int size, bool big_endian> | |
1106 | void | |
1107 | Output_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 | ||
1133 | template<int size, bool big_endian> | |
1134 | void | |
1135 | Output_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 | ||
1163 | template<int size, bool big_endian> | |
1164 | void | |
dbe717ef | 1165 | Output_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 | ||
1194 | template<int size, bool big_endian> | |
1195 | void | |
1196 | Output_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 | ||
1241 | void | |
1242 | Output_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 | ||
1254 | void | |
27bc2bce | 1255 | Output_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 | ||
1272 | void | |
1273 | Output_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 | ||
1317 | template<int size, bool big_endian> | |
1318 | void | |
1319 | Output_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 | ||
1350 | off_t | |
1351 | Output_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 | ||
1361 | void | |
96803768 ILT |
1362 | Output_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 | ||
1376 | void | |
1377 | Output_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 | 1387 | inline bool |
8383303e ILT |
1388 | Output_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 | ||
1408 | inline bool | |
1409 | Output_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 | ||
1421 | void | |
1422 | Output_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 | ||
1431 | void | |
1432 | Output_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 | 1442 | Output_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 |
1475 | Output_section::~Output_section() |
1476 | { | |
1477 | } | |
1478 | ||
16649710 ILT |
1479 | // Set the entry size. |
1480 | ||
1481 | void | |
1482 | Output_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 | |
1500 | template<int size, bool big_endian> | |
1501 | off_t | |
730cdc88 ILT |
1502 | Output_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 | ||
1585 | void | |
1586 | Output_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 |
1594 | void |
1595 | Output_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 | ||
1611 | void | |
1612 | Output_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 | ||
1621 | bool | |
1622 | Output_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 | ||
1677 | bool | |
1678 | Output_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 | 1704 | section_offset_type |
730cdc88 | 1705 | Output_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 | ||
1726 | uint64_t | |
1727 | Output_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 | ||
1759 | uint64_t | |
1760 | Output_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 | ||
1787 | void | |
27bc2bce | 1788 | Output_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 | ||
1814 | void | |
1815 | Output_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 | ||
1822 | template<int size, bool big_endian> | |
1823 | void | |
16649710 ILT |
1824 | Output_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 | ||
1854 | void | |
1855 | Output_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 | { | |
14144f39 | 1864 | std::string fill_data(parameters->target()->code_fill(p->length())); |
c51e6221 ILT |
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 | ||
1877 | void | |
1878 | Output_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 | ||
1908 | void | |
1909 | Output_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 | ||
1936 | void | |
1937 | Output_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 | ||
1948 | Output_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 | ||
1965 | void | |
75f65a3e | 1966 | Output_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 | ||
2069 | void | |
2070 | Output_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 | |
2079 | uint64_t | |
ead1e424 | 2080 | Output_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 | ||
2102 | uint64_t | |
2103 | Output_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 | ||
2119 | unsigned int | |
2120 | Output_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 | ||
2128 | unsigned int | |
2129 | Output_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 | |
2144 | uint64_t | |
ead1e424 ILT |
2145 | Output_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 | |
2178 | uint64_t | |
2179 | Output_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 | ||
2215 | void | |
2216 | Output_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 | ||
2262 | void | |
2263 | Output_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 | ||
2280 | unsigned int | |
2281 | Output_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 | ||
2289 | unsigned int | |
2290 | Output_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 | ||
2305 | template<int size, bool big_endian> | |
2306 | void | |
ead1e424 | 2307 | Output_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 | ||
2321 | template<int size, bool big_endian> | |
2322 | unsigned char* | |
16649710 ILT |
2323 | Output_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 | ||
2346 | template<int size, bool big_endian> | |
2347 | unsigned char* | |
16649710 ILT |
2348 | Output_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 | ||
14144f39 ILT |
2375 | Output_file::Output_file(const char* name) |
2376 | : name_(name), | |
61ba1cf9 ILT |
2377 | o_(-1), |
2378 | file_size_(0), | |
c420411f ILT |
2379 | base_(NULL), |
2380 | map_is_anonymous_(false) | |
61ba1cf9 ILT |
2381 | { |
2382 | } | |
2383 | ||
2384 | // Open the output file. | |
2385 | ||
a2fb1b05 | 2386 | void |
61ba1cf9 | 2387 | Output_file::open(off_t file_size) |
a2fb1b05 | 2388 | { |
61ba1cf9 ILT |
2389 | this->file_size_ = file_size; |
2390 | ||
4e9d8586 ILT |
2391 | // Unlink the file first; otherwise the open() may fail if the file |
2392 | // is busy (e.g. it's an executable that's currently being executed). | |
2393 | // | |
2394 | // However, the linker may be part of a system where a zero-length | |
2395 | // file is created for it to write to, with tight permissions (gcc | |
2396 | // 2.95 did something like this). Unlinking the file would work | |
2397 | // around those permission controls, so we only unlink if the file | |
2398 | // has a non-zero size. We also unlink only regular files to avoid | |
2399 | // trouble with directories/etc. | |
2400 | // | |
2401 | // If we fail, continue; this command is merely a best-effort attempt | |
2402 | // to improve the odds for open(). | |
2403 | ||
42a1b686 ILT |
2404 | // We let the name "-" mean "stdout" |
2405 | if (strcmp(this->name_, "-") == 0) | |
2406 | this->o_ = STDOUT_FILENO; | |
2407 | else | |
2408 | { | |
2409 | struct stat s; | |
2410 | if (::stat(this->name_, &s) == 0 && s.st_size != 0) | |
2411 | unlink_if_ordinary(this->name_); | |
2412 | ||
2413 | int mode = parameters->output_is_object() ? 0666 : 0777; | |
2414 | int o = ::open(this->name_, O_RDWR | O_CREAT | O_TRUNC, mode); | |
2415 | if (o < 0) | |
2416 | gold_fatal(_("%s: open: %s"), this->name_, strerror(errno)); | |
2417 | this->o_ = o; | |
2418 | } | |
61ba1cf9 | 2419 | |
27bc2bce ILT |
2420 | this->map(); |
2421 | } | |
2422 | ||
2423 | // Resize the output file. | |
2424 | ||
2425 | void | |
2426 | Output_file::resize(off_t file_size) | |
2427 | { | |
c420411f ILT |
2428 | // If the mmap is mapping an anonymous memory buffer, this is easy: |
2429 | // just mremap to the new size. If it's mapping to a file, we want | |
2430 | // to unmap to flush to the file, then remap after growing the file. | |
2431 | if (this->map_is_anonymous_) | |
2432 | { | |
2433 | void* base = ::mremap(this->base_, this->file_size_, file_size, | |
2434 | MREMAP_MAYMOVE); | |
2435 | if (base == MAP_FAILED) | |
2436 | gold_fatal(_("%s: mremap: %s"), this->name_, strerror(errno)); | |
2437 | this->base_ = static_cast<unsigned char*>(base); | |
2438 | this->file_size_ = file_size; | |
2439 | } | |
2440 | else | |
2441 | { | |
2442 | this->unmap(); | |
2443 | this->file_size_ = file_size; | |
2444 | this->map(); | |
2445 | } | |
27bc2bce ILT |
2446 | } |
2447 | ||
2448 | // Map the file into memory. | |
2449 | ||
2450 | void | |
2451 | Output_file::map() | |
2452 | { | |
c420411f | 2453 | const int o = this->o_; |
61ba1cf9 | 2454 | |
c420411f ILT |
2455 | // If the output file is not a regular file, don't try to mmap it; |
2456 | // instead, we'll mmap a block of memory (an anonymous buffer), and | |
2457 | // then later write the buffer to the file. | |
2458 | void* base; | |
2459 | struct stat statbuf; | |
42a1b686 ILT |
2460 | if (o == STDOUT_FILENO || o == STDERR_FILENO |
2461 | || ::fstat(o, &statbuf) != 0 | |
c420411f ILT |
2462 | || !S_ISREG(statbuf.st_mode)) |
2463 | { | |
2464 | this->map_is_anonymous_ = true; | |
2465 | base = ::mmap(NULL, this->file_size_, PROT_READ | PROT_WRITE, | |
2466 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
2467 | } | |
2468 | else | |
2469 | { | |
2470 | // Write out one byte to make the file the right size. | |
2471 | if (::lseek(o, this->file_size_ - 1, SEEK_SET) < 0) | |
2472 | gold_fatal(_("%s: lseek: %s"), this->name_, strerror(errno)); | |
2473 | char b = 0; | |
2474 | if (::write(o, &b, 1) != 1) | |
2475 | gold_fatal(_("%s: write: %s"), this->name_, strerror(errno)); | |
2476 | ||
2477 | // Map the file into memory. | |
2478 | this->map_is_anonymous_ = false; | |
2479 | base = ::mmap(NULL, this->file_size_, PROT_READ | PROT_WRITE, | |
2480 | MAP_SHARED, o, 0); | |
2481 | } | |
61ba1cf9 | 2482 | if (base == MAP_FAILED) |
75f2446e | 2483 | gold_fatal(_("%s: mmap: %s"), this->name_, strerror(errno)); |
61ba1cf9 ILT |
2484 | this->base_ = static_cast<unsigned char*>(base); |
2485 | } | |
2486 | ||
c420411f | 2487 | // Unmap the file from memory. |
61ba1cf9 ILT |
2488 | |
2489 | void | |
c420411f | 2490 | Output_file::unmap() |
61ba1cf9 ILT |
2491 | { |
2492 | if (::munmap(this->base_, this->file_size_) < 0) | |
a0c4fb0a | 2493 | gold_error(_("%s: munmap: %s"), this->name_, strerror(errno)); |
61ba1cf9 | 2494 | this->base_ = NULL; |
c420411f ILT |
2495 | } |
2496 | ||
2497 | // Close the output file. | |
2498 | ||
2499 | void | |
2500 | Output_file::close() | |
2501 | { | |
2502 | // If the map isn't file-backed, we need to write it now. | |
2503 | if (this->map_is_anonymous_) | |
2504 | { | |
2505 | size_t bytes_to_write = this->file_size_; | |
2506 | while (bytes_to_write > 0) | |
2507 | { | |
2508 | ssize_t bytes_written = ::write(this->o_, this->base_, bytes_to_write); | |
2509 | if (bytes_written == 0) | |
2510 | gold_error(_("%s: write: unexpected 0 return-value"), this->name_); | |
2511 | else if (bytes_written < 0) | |
2512 | gold_error(_("%s: write: %s"), this->name_, strerror(errno)); | |
2513 | else | |
2514 | bytes_to_write -= bytes_written; | |
2515 | } | |
2516 | } | |
2517 | this->unmap(); | |
61ba1cf9 | 2518 | |
42a1b686 ILT |
2519 | // We don't close stdout or stderr |
2520 | if (this->o_ != STDOUT_FILENO && this->o_ != STDERR_FILENO) | |
2521 | if (::close(this->o_) < 0) | |
2522 | gold_error(_("%s: close: %s"), this->name_, strerror(errno)); | |
61ba1cf9 | 2523 | this->o_ = -1; |
a2fb1b05 ILT |
2524 | } |
2525 | ||
2526 | // Instantiate the templates we need. We could use the configure | |
2527 | // script to restrict this to only the ones for implemented targets. | |
2528 | ||
193a53d9 | 2529 | #ifdef HAVE_TARGET_32_LITTLE |
a2fb1b05 ILT |
2530 | template |
2531 | off_t | |
2532 | Output_section::add_input_section<32, false>( | |
730cdc88 | 2533 | Sized_relobj<32, false>* object, |
ead1e424 | 2534 | unsigned int shndx, |
a2fb1b05 | 2535 | const char* secname, |
730cdc88 ILT |
2536 | const elfcpp::Shdr<32, false>& shdr, |
2537 | unsigned int reloc_shndx); | |
193a53d9 | 2538 | #endif |
a2fb1b05 | 2539 | |
193a53d9 | 2540 | #ifdef HAVE_TARGET_32_BIG |
a2fb1b05 ILT |
2541 | template |
2542 | off_t | |
2543 | Output_section::add_input_section<32, true>( | |
730cdc88 | 2544 | Sized_relobj<32, true>* object, |
ead1e424 | 2545 | unsigned int shndx, |
a2fb1b05 | 2546 | const char* secname, |
730cdc88 ILT |
2547 | const elfcpp::Shdr<32, true>& shdr, |
2548 | unsigned int reloc_shndx); | |
193a53d9 | 2549 | #endif |
a2fb1b05 | 2550 | |
193a53d9 | 2551 | #ifdef HAVE_TARGET_64_LITTLE |
a2fb1b05 ILT |
2552 | template |
2553 | off_t | |
2554 | Output_section::add_input_section<64, false>( | |
730cdc88 | 2555 | Sized_relobj<64, false>* object, |
ead1e424 | 2556 | unsigned int shndx, |
a2fb1b05 | 2557 | const char* secname, |
730cdc88 ILT |
2558 | const elfcpp::Shdr<64, false>& shdr, |
2559 | unsigned int reloc_shndx); | |
193a53d9 | 2560 | #endif |
a2fb1b05 | 2561 | |
193a53d9 | 2562 | #ifdef HAVE_TARGET_64_BIG |
a2fb1b05 ILT |
2563 | template |
2564 | off_t | |
2565 | Output_section::add_input_section<64, true>( | |
730cdc88 | 2566 | Sized_relobj<64, true>* object, |
ead1e424 | 2567 | unsigned int shndx, |
a2fb1b05 | 2568 | const char* secname, |
730cdc88 ILT |
2569 | const elfcpp::Shdr<64, true>& shdr, |
2570 | unsigned int reloc_shndx); | |
193a53d9 | 2571 | #endif |
a2fb1b05 | 2572 | |
193a53d9 | 2573 | #ifdef HAVE_TARGET_32_LITTLE |
c06b7b0b ILT |
2574 | template |
2575 | class Output_data_reloc<elfcpp::SHT_REL, false, 32, false>; | |
193a53d9 | 2576 | #endif |
c06b7b0b | 2577 | |
193a53d9 | 2578 | #ifdef HAVE_TARGET_32_BIG |
c06b7b0b ILT |
2579 | template |
2580 | class Output_data_reloc<elfcpp::SHT_REL, false, 32, true>; | |
193a53d9 | 2581 | #endif |
c06b7b0b | 2582 | |
193a53d9 | 2583 | #ifdef HAVE_TARGET_64_LITTLE |
c06b7b0b ILT |
2584 | template |
2585 | class Output_data_reloc<elfcpp::SHT_REL, false, 64, false>; | |
193a53d9 | 2586 | #endif |
c06b7b0b | 2587 | |
193a53d9 | 2588 | #ifdef HAVE_TARGET_64_BIG |
c06b7b0b ILT |
2589 | template |
2590 | class Output_data_reloc<elfcpp::SHT_REL, false, 64, true>; | |
193a53d9 | 2591 | #endif |
c06b7b0b | 2592 | |
193a53d9 | 2593 | #ifdef HAVE_TARGET_32_LITTLE |
c06b7b0b ILT |
2594 | template |
2595 | class Output_data_reloc<elfcpp::SHT_REL, true, 32, false>; | |
193a53d9 | 2596 | #endif |
c06b7b0b | 2597 | |
193a53d9 | 2598 | #ifdef HAVE_TARGET_32_BIG |
c06b7b0b ILT |
2599 | template |
2600 | class Output_data_reloc<elfcpp::SHT_REL, true, 32, true>; | |
193a53d9 | 2601 | #endif |
c06b7b0b | 2602 | |
193a53d9 | 2603 | #ifdef HAVE_TARGET_64_LITTLE |
c06b7b0b ILT |
2604 | template |
2605 | class Output_data_reloc<elfcpp::SHT_REL, true, 64, false>; | |
193a53d9 | 2606 | #endif |
c06b7b0b | 2607 | |
193a53d9 | 2608 | #ifdef HAVE_TARGET_64_BIG |
c06b7b0b ILT |
2609 | template |
2610 | class Output_data_reloc<elfcpp::SHT_REL, true, 64, true>; | |
193a53d9 | 2611 | #endif |
c06b7b0b | 2612 | |
193a53d9 | 2613 | #ifdef HAVE_TARGET_32_LITTLE |
c06b7b0b ILT |
2614 | template |
2615 | class Output_data_reloc<elfcpp::SHT_RELA, false, 32, false>; | |
193a53d9 | 2616 | #endif |
c06b7b0b | 2617 | |
193a53d9 | 2618 | #ifdef HAVE_TARGET_32_BIG |
c06b7b0b ILT |
2619 | template |
2620 | class Output_data_reloc<elfcpp::SHT_RELA, false, 32, true>; | |
193a53d9 | 2621 | #endif |
c06b7b0b | 2622 | |
193a53d9 | 2623 | #ifdef HAVE_TARGET_64_LITTLE |
c06b7b0b ILT |
2624 | template |
2625 | class Output_data_reloc<elfcpp::SHT_RELA, false, 64, false>; | |
193a53d9 | 2626 | #endif |
c06b7b0b | 2627 | |
193a53d9 | 2628 | #ifdef HAVE_TARGET_64_BIG |
c06b7b0b ILT |
2629 | template |
2630 | class Output_data_reloc<elfcpp::SHT_RELA, false, 64, true>; | |
193a53d9 | 2631 | #endif |
c06b7b0b | 2632 | |
193a53d9 | 2633 | #ifdef HAVE_TARGET_32_LITTLE |
c06b7b0b ILT |
2634 | template |
2635 | class Output_data_reloc<elfcpp::SHT_RELA, true, 32, false>; | |
193a53d9 | 2636 | #endif |
c06b7b0b | 2637 | |
193a53d9 | 2638 | #ifdef HAVE_TARGET_32_BIG |
c06b7b0b ILT |
2639 | template |
2640 | class Output_data_reloc<elfcpp::SHT_RELA, true, 32, true>; | |
193a53d9 | 2641 | #endif |
c06b7b0b | 2642 | |
193a53d9 | 2643 | #ifdef HAVE_TARGET_64_LITTLE |
c06b7b0b ILT |
2644 | template |
2645 | class Output_data_reloc<elfcpp::SHT_RELA, true, 64, false>; | |
193a53d9 | 2646 | #endif |
c06b7b0b | 2647 | |
193a53d9 | 2648 | #ifdef HAVE_TARGET_64_BIG |
c06b7b0b ILT |
2649 | template |
2650 | class Output_data_reloc<elfcpp::SHT_RELA, true, 64, true>; | |
193a53d9 | 2651 | #endif |
c06b7b0b | 2652 | |
193a53d9 | 2653 | #ifdef HAVE_TARGET_32_LITTLE |
ead1e424 | 2654 | template |
dbe717ef | 2655 | class Output_data_got<32, false>; |
193a53d9 | 2656 | #endif |
ead1e424 | 2657 | |
193a53d9 | 2658 | #ifdef HAVE_TARGET_32_BIG |
ead1e424 | 2659 | template |
dbe717ef | 2660 | class Output_data_got<32, true>; |
193a53d9 | 2661 | #endif |
ead1e424 | 2662 | |
193a53d9 | 2663 | #ifdef HAVE_TARGET_64_LITTLE |
ead1e424 | 2664 | template |
dbe717ef | 2665 | class Output_data_got<64, false>; |
193a53d9 | 2666 | #endif |
ead1e424 | 2667 | |
193a53d9 | 2668 | #ifdef HAVE_TARGET_64_BIG |
ead1e424 | 2669 | template |
dbe717ef | 2670 | class Output_data_got<64, true>; |
193a53d9 | 2671 | #endif |
ead1e424 | 2672 | |
a2fb1b05 | 2673 | } // End namespace gold. |