]>
Commit | Line | Data |
---|---|---|
2e30d253 ILT |
1 | // x86_64.cc -- x86_64 target support for gold. |
2 | ||
6d03d481 | 3 | // Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
2e30d253 ILT |
4 | // Written by Ian Lance Taylor <[email protected]>. |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8b105e34 ILT |
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 | |
2e30d253 ILT |
11 | // (at your option) any later version. |
12 | ||
8b105e34 ILT |
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. | |
2e30d253 ILT |
22 | |
23 | #include "gold.h" | |
24 | ||
25 | #include <cstring> | |
26 | ||
27 | #include "elfcpp.h" | |
28 | #include "parameters.h" | |
29 | #include "reloc.h" | |
30 | #include "x86_64.h" | |
31 | #include "object.h" | |
32 | #include "symtab.h" | |
33 | #include "layout.h" | |
34 | #include "output.h" | |
12c0daef | 35 | #include "copy-relocs.h" |
2e30d253 ILT |
36 | #include "target.h" |
37 | #include "target-reloc.h" | |
38 | #include "target-select.h" | |
e041f13d | 39 | #include "tls.h" |
36959681 | 40 | #include "freebsd.h" |
f345227a | 41 | #include "gc.h" |
2e30d253 ILT |
42 | |
43 | namespace | |
44 | { | |
45 | ||
46 | using namespace gold; | |
47 | ||
48 | class Output_data_plt_x86_64; | |
49 | ||
50 | // The x86_64 target class. | |
d61c17ea ILT |
51 | // See the ABI at |
52 | // http://www.x86-64.org/documentation/abi.pdf | |
53 | // TLS info comes from | |
54 | // http://people.redhat.com/drepper/tls.pdf | |
0ffd9845 | 55 | // http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt |
2e30d253 | 56 | |
36959681 | 57 | class Target_x86_64 : public Target_freebsd<64, false> |
2e30d253 ILT |
58 | { |
59 | public: | |
e822f2b1 ILT |
60 | // In the x86_64 ABI (p 68), it says "The AMD64 ABI architectures |
61 | // uses only Elf64_Rela relocation entries with explicit addends." | |
2e30d253 ILT |
62 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, 64, false> Reloc_section; |
63 | ||
64 | Target_x86_64() | |
36959681 | 65 | : Target_freebsd<64, false>(&x86_64_info), |
0ffd9845 | 66 | got_(NULL), plt_(NULL), got_plt_(NULL), rela_dyn_(NULL), |
12c0daef | 67 | copy_relocs_(elfcpp::R_X86_64_COPY), dynbss_(NULL), |
edfbb029 | 68 | got_mod_index_offset_(-1U), tls_base_symbol_defined_(false) |
2e30d253 ILT |
69 | { } |
70 | ||
8a5e3e08 ILT |
71 | // Hook for a new output section. |
72 | void | |
73 | do_new_output_section(Output_section*) const; | |
74 | ||
6d03d481 ST |
75 | // Scan the relocations to look for symbol adjustments. |
76 | void | |
ad0f2072 | 77 | gc_process_relocs(Symbol_table* symtab, |
6d03d481 ST |
78 | Layout* layout, |
79 | Sized_relobj<64, false>* object, | |
80 | unsigned int data_shndx, | |
81 | unsigned int sh_type, | |
82 | const unsigned char* prelocs, | |
83 | size_t reloc_count, | |
84 | Output_section* output_section, | |
85 | bool needs_special_offset_handling, | |
86 | size_t local_symbol_count, | |
87 | const unsigned char* plocal_symbols); | |
88 | ||
2e30d253 ILT |
89 | // Scan the relocations to look for symbol adjustments. |
90 | void | |
ad0f2072 | 91 | scan_relocs(Symbol_table* symtab, |
2e30d253 ILT |
92 | Layout* layout, |
93 | Sized_relobj<64, false>* object, | |
94 | unsigned int data_shndx, | |
95 | unsigned int sh_type, | |
96 | const unsigned char* prelocs, | |
97 | size_t reloc_count, | |
730cdc88 ILT |
98 | Output_section* output_section, |
99 | bool needs_special_offset_handling, | |
2e30d253 | 100 | size_t local_symbol_count, |
730cdc88 | 101 | const unsigned char* plocal_symbols); |
2e30d253 ILT |
102 | |
103 | // Finalize the sections. | |
104 | void | |
f59f41f3 | 105 | do_finalize_sections(Layout*, const Input_objects*, Symbol_table*); |
2e30d253 | 106 | |
4fb6c25d ILT |
107 | // Return the value to use for a dynamic which requires special |
108 | // treatment. | |
109 | uint64_t | |
110 | do_dynsym_value(const Symbol*) const; | |
111 | ||
2e30d253 ILT |
112 | // Relocate a section. |
113 | void | |
114 | relocate_section(const Relocate_info<64, false>*, | |
115 | unsigned int sh_type, | |
116 | const unsigned char* prelocs, | |
117 | size_t reloc_count, | |
730cdc88 ILT |
118 | Output_section* output_section, |
119 | bool needs_special_offset_handling, | |
2e30d253 ILT |
120 | unsigned char* view, |
121 | elfcpp::Elf_types<64>::Elf_Addr view_address, | |
364c7fa5 ILT |
122 | section_size_type view_size, |
123 | const Reloc_symbol_changes*); | |
2e30d253 | 124 | |
6a74a719 ILT |
125 | // Scan the relocs during a relocatable link. |
126 | void | |
ad0f2072 | 127 | scan_relocatable_relocs(Symbol_table* symtab, |
6a74a719 ILT |
128 | Layout* layout, |
129 | Sized_relobj<64, false>* object, | |
130 | unsigned int data_shndx, | |
131 | unsigned int sh_type, | |
132 | const unsigned char* prelocs, | |
133 | size_t reloc_count, | |
134 | Output_section* output_section, | |
135 | bool needs_special_offset_handling, | |
136 | size_t local_symbol_count, | |
137 | const unsigned char* plocal_symbols, | |
138 | Relocatable_relocs*); | |
139 | ||
140 | // Relocate a section during a relocatable link. | |
141 | void | |
142 | relocate_for_relocatable(const Relocate_info<64, false>*, | |
143 | unsigned int sh_type, | |
144 | const unsigned char* prelocs, | |
145 | size_t reloc_count, | |
146 | Output_section* output_section, | |
147 | off_t offset_in_output_section, | |
148 | const Relocatable_relocs*, | |
149 | unsigned char* view, | |
150 | elfcpp::Elf_types<64>::Elf_Addr view_address, | |
151 | section_size_type view_size, | |
152 | unsigned char* reloc_view, | |
153 | section_size_type reloc_view_size); | |
154 | ||
2e30d253 ILT |
155 | // Return a string used to fill a code section with nops. |
156 | std::string | |
8851ecca | 157 | do_code_fill(section_size_type length) const; |
2e30d253 | 158 | |
9a2d6984 ILT |
159 | // Return whether SYM is defined by the ABI. |
160 | bool | |
9c2d0ef9 | 161 | do_is_defined_by_abi(const Symbol* sym) const |
9a2d6984 ILT |
162 | { return strcmp(sym->name(), "__tls_get_addr") == 0; } |
163 | ||
364c7fa5 ILT |
164 | // Adjust -fstack-split code which calls non-stack-split code. |
165 | void | |
166 | do_calls_non_split(Relobj* object, unsigned int shndx, | |
167 | section_offset_type fnoffset, section_size_type fnsize, | |
168 | unsigned char* view, section_size_type view_size, | |
169 | std::string* from, std::string* to) const; | |
170 | ||
96f2030e | 171 | // Return the size of the GOT section. |
fe8718a4 | 172 | section_size_type |
96f2030e ILT |
173 | got_size() |
174 | { | |
175 | gold_assert(this->got_ != NULL); | |
176 | return this->got_->data_size(); | |
177 | } | |
178 | ||
2e30d253 ILT |
179 | private: |
180 | // The class which scans relocations. | |
a036edd8 | 181 | class Scan |
2e30d253 | 182 | { |
a036edd8 ILT |
183 | public: |
184 | Scan() | |
185 | : issued_non_pic_error_(false) | |
186 | { } | |
187 | ||
2e30d253 | 188 | inline void |
ad0f2072 | 189 | local(Symbol_table* symtab, Layout* layout, Target_x86_64* target, |
2e30d253 ILT |
190 | Sized_relobj<64, false>* object, |
191 | unsigned int data_shndx, | |
07f397ab | 192 | Output_section* output_section, |
2e30d253 ILT |
193 | const elfcpp::Rela<64, false>& reloc, unsigned int r_type, |
194 | const elfcpp::Sym<64, false>& lsym); | |
195 | ||
196 | inline void | |
ad0f2072 | 197 | global(Symbol_table* symtab, Layout* layout, Target_x86_64* target, |
2e30d253 ILT |
198 | Sized_relobj<64, false>* object, |
199 | unsigned int data_shndx, | |
07f397ab | 200 | Output_section* output_section, |
2e30d253 ILT |
201 | const elfcpp::Rela<64, false>& reloc, unsigned int r_type, |
202 | Symbol* gsym); | |
e041f13d | 203 | |
a036edd8 | 204 | private: |
e041f13d ILT |
205 | static void |
206 | unsupported_reloc_local(Sized_relobj<64, false>*, unsigned int r_type); | |
207 | ||
208 | static void | |
209 | unsupported_reloc_global(Sized_relobj<64, false>*, unsigned int r_type, | |
210 | Symbol*); | |
a036edd8 ILT |
211 | |
212 | void | |
213 | check_non_pic(Relobj*, unsigned int r_type); | |
214 | ||
215 | // Whether we have issued an error about a non-PIC compilation. | |
216 | bool issued_non_pic_error_; | |
2e30d253 ILT |
217 | }; |
218 | ||
219 | // The class which implements relocation. | |
220 | class Relocate | |
221 | { | |
222 | public: | |
223 | Relocate() | |
497897f9 | 224 | : skip_call_tls_get_addr_(false), saw_tls_block_reloc_(false) |
2e30d253 ILT |
225 | { } |
226 | ||
227 | ~Relocate() | |
228 | { | |
229 | if (this->skip_call_tls_get_addr_) | |
230 | { | |
231 | // FIXME: This needs to specify the location somehow. | |
a0c4fb0a | 232 | gold_error(_("missing expected TLS relocation")); |
2e30d253 ILT |
233 | } |
234 | } | |
235 | ||
236 | // Do a relocation. Return false if the caller should not issue | |
237 | // any warnings about this relocation. | |
238 | inline bool | |
031cdbed ILT |
239 | relocate(const Relocate_info<64, false>*, Target_x86_64*, Output_section*, |
240 | size_t relnum, const elfcpp::Rela<64, false>&, | |
2e30d253 ILT |
241 | unsigned int r_type, const Sized_symbol<64>*, |
242 | const Symbol_value<64>*, | |
243 | unsigned char*, elfcpp::Elf_types<64>::Elf_Addr, | |
fe8718a4 | 244 | section_size_type); |
2e30d253 ILT |
245 | |
246 | private: | |
247 | // Do a TLS relocation. | |
248 | inline void | |
7bf1f802 ILT |
249 | relocate_tls(const Relocate_info<64, false>*, Target_x86_64*, |
250 | size_t relnum, const elfcpp::Rela<64, false>&, | |
2e30d253 ILT |
251 | unsigned int r_type, const Sized_symbol<64>*, |
252 | const Symbol_value<64>*, | |
fe8718a4 ILT |
253 | unsigned char*, elfcpp::Elf_types<64>::Elf_Addr, |
254 | section_size_type); | |
2e30d253 | 255 | |
c2b45e22 | 256 | // Do a TLS General-Dynamic to Initial-Exec transition. |
7bf1f802 ILT |
257 | inline void |
258 | tls_gd_to_ie(const Relocate_info<64, false>*, size_t relnum, | |
259 | Output_segment* tls_segment, | |
260 | const elfcpp::Rela<64, false>&, unsigned int r_type, | |
261 | elfcpp::Elf_types<64>::Elf_Addr value, | |
262 | unsigned char* view, | |
c2b45e22 | 263 | elfcpp::Elf_types<64>::Elf_Addr, |
fe8718a4 | 264 | section_size_type view_size); |
7bf1f802 | 265 | |
56622147 ILT |
266 | // Do a TLS General-Dynamic to Local-Exec transition. |
267 | inline void | |
268 | tls_gd_to_le(const Relocate_info<64, false>*, size_t relnum, | |
2e30d253 ILT |
269 | Output_segment* tls_segment, |
270 | const elfcpp::Rela<64, false>&, unsigned int r_type, | |
271 | elfcpp::Elf_types<64>::Elf_Addr value, | |
272 | unsigned char* view, | |
fe8718a4 | 273 | section_size_type view_size); |
2e30d253 | 274 | |
c2b45e22 CC |
275 | // Do a TLSDESC-style General-Dynamic to Initial-Exec transition. |
276 | inline void | |
277 | tls_desc_gd_to_ie(const Relocate_info<64, false>*, size_t relnum, | |
278 | Output_segment* tls_segment, | |
279 | const elfcpp::Rela<64, false>&, unsigned int r_type, | |
280 | elfcpp::Elf_types<64>::Elf_Addr value, | |
281 | unsigned char* view, | |
282 | elfcpp::Elf_types<64>::Elf_Addr, | |
283 | section_size_type view_size); | |
284 | ||
285 | // Do a TLSDESC-style General-Dynamic to Local-Exec transition. | |
286 | inline void | |
287 | tls_desc_gd_to_le(const Relocate_info<64, false>*, size_t relnum, | |
288 | Output_segment* tls_segment, | |
289 | const elfcpp::Rela<64, false>&, unsigned int r_type, | |
290 | elfcpp::Elf_types<64>::Elf_Addr value, | |
291 | unsigned char* view, | |
292 | section_size_type view_size); | |
293 | ||
56622147 | 294 | // Do a TLS Local-Dynamic to Local-Exec transition. |
2e30d253 | 295 | inline void |
56622147 | 296 | tls_ld_to_le(const Relocate_info<64, false>*, size_t relnum, |
2e30d253 ILT |
297 | Output_segment* tls_segment, |
298 | const elfcpp::Rela<64, false>&, unsigned int r_type, | |
299 | elfcpp::Elf_types<64>::Elf_Addr value, | |
300 | unsigned char* view, | |
fe8718a4 | 301 | section_size_type view_size); |
2e30d253 | 302 | |
56622147 ILT |
303 | // Do a TLS Initial-Exec to Local-Exec transition. |
304 | static inline void | |
305 | tls_ie_to_le(const Relocate_info<64, false>*, size_t relnum, | |
72ec2876 ILT |
306 | Output_segment* tls_segment, |
307 | const elfcpp::Rela<64, false>&, unsigned int r_type, | |
308 | elfcpp::Elf_types<64>::Elf_Addr value, | |
309 | unsigned char* view, | |
fe8718a4 | 310 | section_size_type view_size); |
2e30d253 ILT |
311 | |
312 | // This is set if we should skip the next reloc, which should be a | |
313 | // PLT32 reloc against ___tls_get_addr. | |
314 | bool skip_call_tls_get_addr_; | |
497897f9 ILT |
315 | |
316 | // This is set if we see a relocation which could load the address | |
317 | // of the TLS block. Whether we see such a relocation determines | |
318 | // how we handle the R_X86_64_DTPOFF32 relocation, which is used | |
319 | // in debugging sections. | |
320 | bool saw_tls_block_reloc_; | |
2e30d253 ILT |
321 | }; |
322 | ||
6a74a719 ILT |
323 | // A class which returns the size required for a relocation type, |
324 | // used while scanning relocs during a relocatable link. | |
325 | class Relocatable_size_for_reloc | |
326 | { | |
327 | public: | |
328 | unsigned int | |
329 | get_size_for_reloc(unsigned int, Relobj*); | |
330 | }; | |
331 | ||
2e30d253 ILT |
332 | // Adjust TLS relocation type based on the options and whether this |
333 | // is a local symbol. | |
e041f13d | 334 | static tls::Tls_optimization |
2e30d253 ILT |
335 | optimize_tls_reloc(bool is_final, int r_type); |
336 | ||
337 | // Get the GOT section, creating it if necessary. | |
338 | Output_data_got<64, false>* | |
339 | got_section(Symbol_table*, Layout*); | |
340 | ||
96f2030e ILT |
341 | // Get the GOT PLT section. |
342 | Output_data_space* | |
343 | got_plt_section() const | |
344 | { | |
345 | gold_assert(this->got_plt_ != NULL); | |
346 | return this->got_plt_; | |
347 | } | |
348 | ||
c2b45e22 CC |
349 | // Create the PLT section. |
350 | void | |
351 | make_plt_section(Symbol_table* symtab, Layout* layout); | |
352 | ||
2e30d253 ILT |
353 | // Create a PLT entry for a global symbol. |
354 | void | |
355 | make_plt_entry(Symbol_table*, Layout*, Symbol*); | |
356 | ||
9fa33bee | 357 | // Define the _TLS_MODULE_BASE_ symbol in the TLS segment. |
edfbb029 CC |
358 | void |
359 | define_tls_base_symbol(Symbol_table*, Layout*); | |
360 | ||
c2b45e22 CC |
361 | // Create the reserved PLT and GOT entries for the TLS descriptor resolver. |
362 | void | |
363 | reserve_tlsdesc_entries(Symbol_table* symtab, Layout* layout); | |
364 | ||
31d60480 ILT |
365 | // Create a GOT entry for the TLS module index. |
366 | unsigned int | |
367 | got_mod_index_entry(Symbol_table* symtab, Layout* layout, | |
368 | Sized_relobj<64, false>* object); | |
369 | ||
2e30d253 ILT |
370 | // Get the PLT section. |
371 | Output_data_plt_x86_64* | |
372 | plt_section() const | |
373 | { | |
374 | gold_assert(this->plt_ != NULL); | |
375 | return this->plt_; | |
376 | } | |
377 | ||
378 | // Get the dynamic reloc section, creating it if necessary. | |
379 | Reloc_section* | |
0ffd9845 | 380 | rela_dyn_section(Layout*); |
2e30d253 | 381 | |
12c0daef | 382 | // Add a potential copy relocation. |
2e30d253 | 383 | void |
ef9beddf ILT |
384 | copy_reloc(Symbol_table* symtab, Layout* layout, |
385 | Sized_relobj<64, false>* object, | |
12c0daef ILT |
386 | unsigned int shndx, Output_section* output_section, |
387 | Symbol* sym, const elfcpp::Rela<64, false>& reloc) | |
388 | { | |
389 | this->copy_relocs_.copy_reloc(symtab, layout, | |
390 | symtab->get_sized_symbol<64>(sym), | |
391 | object, shndx, output_section, | |
392 | reloc, this->rela_dyn_section(layout)); | |
393 | } | |
2e30d253 ILT |
394 | |
395 | // Information about this specific target which we pass to the | |
396 | // general Target structure. | |
397 | static const Target::Target_info x86_64_info; | |
398 | ||
0a65a3a7 CC |
399 | enum Got_type |
400 | { | |
401 | GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol | |
402 | GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset | |
403 | GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair | |
404 | GOT_TYPE_TLS_DESC = 3 // GOT entry for TLS_DESC pair | |
405 | }; | |
406 | ||
2e30d253 ILT |
407 | // The GOT section. |
408 | Output_data_got<64, false>* got_; | |
409 | // The PLT section. | |
410 | Output_data_plt_x86_64* plt_; | |
411 | // The GOT PLT section. | |
412 | Output_data_space* got_plt_; | |
413 | // The dynamic reloc section. | |
0ffd9845 | 414 | Reloc_section* rela_dyn_; |
2e30d253 | 415 | // Relocs saved to avoid a COPY reloc. |
12c0daef | 416 | Copy_relocs<elfcpp::SHT_RELA, 64, false> copy_relocs_; |
2e30d253 ILT |
417 | // Space for variables copied with a COPY reloc. |
418 | Output_data_space* dynbss_; | |
c2b45e22 | 419 | // Offset of the GOT entry for the TLS module index. |
31d60480 | 420 | unsigned int got_mod_index_offset_; |
edfbb029 CC |
421 | // True if the _TLS_MODULE_BASE_ symbol has been defined. |
422 | bool tls_base_symbol_defined_; | |
2e30d253 ILT |
423 | }; |
424 | ||
425 | const Target::Target_info Target_x86_64::x86_64_info = | |
426 | { | |
427 | 64, // size | |
428 | false, // is_big_endian | |
429 | elfcpp::EM_X86_64, // machine_code | |
430 | false, // has_make_symbol | |
431 | false, // has_resolve | |
432 | true, // has_code_fill | |
35cdfc9a | 433 | true, // is_default_stack_executable |
0864d551 | 434 | '\0', // wrap_char |
2e30d253 | 435 | "/lib/ld64.so.1", // program interpreter |
0c5e9c22 | 436 | 0x400000, // default_text_segment_address |
cd72c291 | 437 | 0x1000, // abi_pagesize (overridable by -z max-page-size) |
8a5e3e08 ILT |
438 | 0x1000, // common_pagesize (overridable by -z common-page-size) |
439 | elfcpp::SHN_UNDEF, // small_common_shndx | |
440 | elfcpp::SHN_X86_64_LCOMMON, // large_common_shndx | |
441 | 0, // small_common_section_flags | |
05a352e6 DK |
442 | elfcpp::SHF_X86_64_LARGE, // large_common_section_flags |
443 | NULL, // attributes_section | |
444 | NULL // attributes_vendor | |
2e30d253 ILT |
445 | }; |
446 | ||
8a5e3e08 ILT |
447 | // This is called when a new output section is created. This is where |
448 | // we handle the SHF_X86_64_LARGE. | |
449 | ||
450 | void | |
451 | Target_x86_64::do_new_output_section(Output_section *os) const | |
452 | { | |
453 | if ((os->flags() & elfcpp::SHF_X86_64_LARGE) != 0) | |
454 | os->set_is_large_section(); | |
455 | } | |
456 | ||
2e30d253 ILT |
457 | // Get the GOT section, creating it if necessary. |
458 | ||
459 | Output_data_got<64, false>* | |
460 | Target_x86_64::got_section(Symbol_table* symtab, Layout* layout) | |
461 | { | |
462 | if (this->got_ == NULL) | |
463 | { | |
464 | gold_assert(symtab != NULL && layout != NULL); | |
465 | ||
466 | this->got_ = new Output_data_got<64, false>(); | |
467 | ||
9f1d377b ILT |
468 | Output_section* os; |
469 | os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS, | |
470 | (elfcpp::SHF_ALLOC | |
471 | | elfcpp::SHF_WRITE), | |
f5c870d2 | 472 | this->got_, false); |
9f1d377b | 473 | os->set_is_relro(); |
2e30d253 ILT |
474 | |
475 | // The old GNU linker creates a .got.plt section. We just | |
476 | // create another set of data in the .got section. Note that we | |
477 | // always create a PLT if we create a GOT, although the PLT | |
478 | // might be empty. | |
7d9e3d98 | 479 | this->got_plt_ = new Output_data_space(8, "** GOT PLT"); |
9f1d377b ILT |
480 | os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS, |
481 | (elfcpp::SHF_ALLOC | |
482 | | elfcpp::SHF_WRITE), | |
f5c870d2 | 483 | this->got_plt_, false); |
9f1d377b | 484 | os->set_is_relro(); |
2e30d253 ILT |
485 | |
486 | // The first three entries are reserved. | |
27bc2bce | 487 | this->got_plt_->set_current_data_size(3 * 8); |
2e30d253 ILT |
488 | |
489 | // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT. | |
9b07f471 | 490 | symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL, |
2e30d253 ILT |
491 | this->got_plt_, |
492 | 0, 0, elfcpp::STT_OBJECT, | |
493 | elfcpp::STB_LOCAL, | |
494 | elfcpp::STV_HIDDEN, 0, | |
495 | false, false); | |
496 | } | |
497 | ||
498 | return this->got_; | |
499 | } | |
500 | ||
501 | // Get the dynamic reloc section, creating it if necessary. | |
502 | ||
503 | Target_x86_64::Reloc_section* | |
0ffd9845 | 504 | Target_x86_64::rela_dyn_section(Layout* layout) |
2e30d253 | 505 | { |
0ffd9845 | 506 | if (this->rela_dyn_ == NULL) |
2e30d253 ILT |
507 | { |
508 | gold_assert(layout != NULL); | |
d98bc257 | 509 | this->rela_dyn_ = new Reloc_section(parameters->options().combreloc()); |
2e30d253 | 510 | layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA, |
f5c870d2 | 511 | elfcpp::SHF_ALLOC, this->rela_dyn_, true); |
2e30d253 | 512 | } |
0ffd9845 | 513 | return this->rela_dyn_; |
2e30d253 ILT |
514 | } |
515 | ||
516 | // A class to handle the PLT data. | |
517 | ||
518 | class Output_data_plt_x86_64 : public Output_section_data | |
519 | { | |
520 | public: | |
521 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, 64, false> Reloc_section; | |
522 | ||
c2b45e22 CC |
523 | Output_data_plt_x86_64(Layout*, Output_data_got<64, false>*, |
524 | Output_data_space*); | |
2e30d253 ILT |
525 | |
526 | // Add an entry to the PLT. | |
527 | void | |
528 | add_entry(Symbol* gsym); | |
529 | ||
c2b45e22 CC |
530 | // Add the reserved TLSDESC_PLT entry to the PLT. |
531 | void | |
532 | reserve_tlsdesc_entry(unsigned int got_offset) | |
533 | { this->tlsdesc_got_offset_ = got_offset; } | |
534 | ||
535 | // Return true if a TLSDESC_PLT entry has been reserved. | |
536 | bool | |
537 | has_tlsdesc_entry() const | |
538 | { return this->tlsdesc_got_offset_ != -1U; } | |
539 | ||
540 | // Return the GOT offset for the reserved TLSDESC_PLT entry. | |
541 | unsigned int | |
542 | get_tlsdesc_got_offset() const | |
543 | { return this->tlsdesc_got_offset_; } | |
544 | ||
545 | // Return the offset of the reserved TLSDESC_PLT entry. | |
546 | unsigned int | |
547 | get_tlsdesc_plt_offset() const | |
548 | { return (this->count_ + 1) * plt_entry_size; } | |
549 | ||
2e30d253 ILT |
550 | // Return the .rel.plt section data. |
551 | const Reloc_section* | |
552 | rel_plt() const | |
553 | { return this->rel_; } | |
554 | ||
555 | protected: | |
556 | void | |
557 | do_adjust_output_section(Output_section* os); | |
558 | ||
7d9e3d98 ILT |
559 | // Write to a map file. |
560 | void | |
561 | do_print_to_mapfile(Mapfile* mapfile) const | |
562 | { mapfile->print_output_data(this, _("** PLT")); } | |
563 | ||
2e30d253 ILT |
564 | private: |
565 | // The size of an entry in the PLT. | |
566 | static const int plt_entry_size = 16; | |
567 | ||
568 | // The first entry in the PLT. | |
569 | // From the AMD64 ABI: "Unlike Intel386 ABI, this ABI uses the same | |
570 | // procedure linkage table for both programs and shared objects." | |
571 | static unsigned char first_plt_entry[plt_entry_size]; | |
572 | ||
573 | // Other entries in the PLT for an executable. | |
574 | static unsigned char plt_entry[plt_entry_size]; | |
575 | ||
c2b45e22 CC |
576 | // The reserved TLSDESC entry in the PLT for an executable. |
577 | static unsigned char tlsdesc_plt_entry[plt_entry_size]; | |
578 | ||
2e30d253 ILT |
579 | // Set the final size. |
580 | void | |
c2b45e22 | 581 | set_final_data_size(); |
2e30d253 ILT |
582 | |
583 | // Write out the PLT data. | |
584 | void | |
585 | do_write(Output_file*); | |
586 | ||
587 | // The reloc section. | |
588 | Reloc_section* rel_; | |
c2b45e22 CC |
589 | // The .got section. |
590 | Output_data_got<64, false>* got_; | |
2e30d253 ILT |
591 | // The .got.plt section. |
592 | Output_data_space* got_plt_; | |
593 | // The number of PLT entries. | |
594 | unsigned int count_; | |
c2b45e22 CC |
595 | // Offset of the reserved TLSDESC_GOT entry when needed. |
596 | unsigned int tlsdesc_got_offset_; | |
2e30d253 ILT |
597 | }; |
598 | ||
599 | // Create the PLT section. The ordinary .got section is an argument, | |
600 | // since we need to refer to the start. We also create our own .got | |
601 | // section just for PLT entries. | |
602 | ||
603 | Output_data_plt_x86_64::Output_data_plt_x86_64(Layout* layout, | |
c2b45e22 | 604 | Output_data_got<64, false>* got, |
2e30d253 | 605 | Output_data_space* got_plt) |
c2b45e22 CC |
606 | : Output_section_data(8), got_(got), got_plt_(got_plt), count_(0), |
607 | tlsdesc_got_offset_(-1U) | |
2e30d253 | 608 | { |
d98bc257 | 609 | this->rel_ = new Reloc_section(false); |
2e30d253 | 610 | layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA, |
f5c870d2 | 611 | elfcpp::SHF_ALLOC, this->rel_, true); |
2e30d253 ILT |
612 | } |
613 | ||
614 | void | |
615 | Output_data_plt_x86_64::do_adjust_output_section(Output_section* os) | |
616 | { | |
b0481b0b | 617 | os->set_entsize(plt_entry_size); |
2e30d253 ILT |
618 | } |
619 | ||
620 | // Add an entry to the PLT. | |
621 | ||
622 | void | |
623 | Output_data_plt_x86_64::add_entry(Symbol* gsym) | |
624 | { | |
625 | gold_assert(!gsym->has_plt_offset()); | |
626 | ||
627 | // Note that when setting the PLT offset we skip the initial | |
628 | // reserved PLT entry. | |
629 | gsym->set_plt_offset((this->count_ + 1) * plt_entry_size); | |
630 | ||
631 | ++this->count_; | |
632 | ||
fe8718a4 | 633 | section_offset_type got_offset = this->got_plt_->current_data_size(); |
2e30d253 ILT |
634 | |
635 | // Every PLT entry needs a GOT entry which points back to the PLT | |
636 | // entry (this will be changed by the dynamic linker, normally | |
637 | // lazily when the function is called). | |
27bc2bce | 638 | this->got_plt_->set_current_data_size(got_offset + 8); |
2e30d253 ILT |
639 | |
640 | // Every PLT entry needs a reloc. | |
641 | gsym->set_needs_dynsym_entry(); | |
642 | this->rel_->add_global(gsym, elfcpp::R_X86_64_JUMP_SLOT, this->got_plt_, | |
643 | got_offset, 0); | |
644 | ||
645 | // Note that we don't need to save the symbol. The contents of the | |
646 | // PLT are independent of which symbols are used. The symbols only | |
647 | // appear in the relocations. | |
648 | } | |
649 | ||
c2b45e22 CC |
650 | // Set the final size. |
651 | void | |
652 | Output_data_plt_x86_64::set_final_data_size() | |
653 | { | |
654 | unsigned int count = this->count_; | |
655 | if (this->has_tlsdesc_entry()) | |
656 | ++count; | |
657 | this->set_data_size((count + 1) * plt_entry_size); | |
658 | } | |
659 | ||
2e30d253 ILT |
660 | // The first entry in the PLT for an executable. |
661 | ||
662 | unsigned char Output_data_plt_x86_64::first_plt_entry[plt_entry_size] = | |
663 | { | |
664 | // From AMD64 ABI Draft 0.98, page 76 | |
665 | 0xff, 0x35, // pushq contents of memory address | |
2e30d253 | 666 | 0, 0, 0, 0, // replaced with address of .got + 8 |
78d911fd ILT |
667 | 0xff, 0x25, // jmp indirect |
668 | 0, 0, 0, 0, // replaced with address of .got + 16 | |
2e30d253 ILT |
669 | 0x90, 0x90, 0x90, 0x90 // noop (x4) |
670 | }; | |
671 | ||
672 | // Subsequent entries in the PLT for an executable. | |
673 | ||
674 | unsigned char Output_data_plt_x86_64::plt_entry[plt_entry_size] = | |
675 | { | |
676 | // From AMD64 ABI Draft 0.98, page 76 | |
677 | 0xff, 0x25, // jmpq indirect | |
678 | 0, 0, 0, 0, // replaced with address of symbol in .got | |
679 | 0x68, // pushq immediate | |
680 | 0, 0, 0, 0, // replaced with offset into relocation table | |
681 | 0xe9, // jmpq relative | |
682 | 0, 0, 0, 0 // replaced with offset to start of .plt | |
683 | }; | |
684 | ||
c2b45e22 CC |
685 | // The reserved TLSDESC entry in the PLT for an executable. |
686 | ||
687 | unsigned char Output_data_plt_x86_64::tlsdesc_plt_entry[plt_entry_size] = | |
688 | { | |
689 | // From Alexandre Oliva, "Thread-Local Storage Descriptors for IA32 | |
690 | // and AMD64/EM64T", Version 0.9.4 (2005-10-10). | |
691 | 0xff, 0x35, // pushq x(%rip) | |
692 | 0, 0, 0, 0, // replaced with address of linkmap GOT entry (at PLTGOT + 8) | |
693 | 0xff, 0x25, // jmpq *y(%rip) | |
694 | 0, 0, 0, 0, // replaced with offset of reserved TLSDESC_GOT entry | |
695 | 0x0f, 0x1f, // nop | |
696 | 0x40, 0 | |
697 | }; | |
698 | ||
2e30d253 ILT |
699 | // Write out the PLT. This uses the hand-coded instructions above, |
700 | // and adjusts them as needed. This is specified by the AMD64 ABI. | |
701 | ||
702 | void | |
703 | Output_data_plt_x86_64::do_write(Output_file* of) | |
704 | { | |
2ea97941 | 705 | const off_t offset = this->offset(); |
fe8718a4 ILT |
706 | const section_size_type oview_size = |
707 | convert_to_section_size_type(this->data_size()); | |
2ea97941 | 708 | unsigned char* const oview = of->get_output_view(offset, oview_size); |
2e30d253 ILT |
709 | |
710 | const off_t got_file_offset = this->got_plt_->offset(); | |
fe8718a4 ILT |
711 | const section_size_type got_size = |
712 | convert_to_section_size_type(this->got_plt_->data_size()); | |
2e30d253 ILT |
713 | unsigned char* const got_view = of->get_output_view(got_file_offset, |
714 | got_size); | |
715 | ||
716 | unsigned char* pov = oview; | |
717 | ||
c2b45e22 | 718 | // The base address of the .plt section. |
a984ee1d | 719 | elfcpp::Elf_types<64>::Elf_Addr plt_address = this->address(); |
c2b45e22 | 720 | // The base address of the .got section. |
a984ee1d | 721 | elfcpp::Elf_types<64>::Elf_Addr got_base = this->got_->address(); |
c2b45e22 CC |
722 | // The base address of the PLT portion of the .got section, |
723 | // which is where the GOT pointer will point, and where the | |
724 | // three reserved GOT entries are located. | |
a984ee1d | 725 | elfcpp::Elf_types<64>::Elf_Addr got_address = this->got_plt_->address(); |
2e30d253 ILT |
726 | |
727 | memcpy(pov, first_plt_entry, plt_entry_size); | |
78d911fd | 728 | // We do a jmp relative to the PC at the end of this instruction. |
a984ee1d ILT |
729 | elfcpp::Swap_unaligned<32, false>::writeval(pov + 2, |
730 | (got_address + 8 | |
731 | - (plt_address + 6))); | |
732 | elfcpp::Swap<32, false>::writeval(pov + 8, | |
733 | (got_address + 16 | |
734 | - (plt_address + 12))); | |
2e30d253 ILT |
735 | pov += plt_entry_size; |
736 | ||
737 | unsigned char* got_pov = got_view; | |
738 | ||
739 | memset(got_pov, 0, 24); | |
740 | got_pov += 24; | |
741 | ||
742 | unsigned int plt_offset = plt_entry_size; | |
743 | unsigned int got_offset = 24; | |
744 | const unsigned int count = this->count_; | |
745 | for (unsigned int plt_index = 0; | |
746 | plt_index < count; | |
747 | ++plt_index, | |
748 | pov += plt_entry_size, | |
749 | got_pov += 8, | |
750 | plt_offset += plt_entry_size, | |
751 | got_offset += 8) | |
752 | { | |
753 | // Set and adjust the PLT entry itself. | |
754 | memcpy(pov, plt_entry, plt_entry_size); | |
78d911fd ILT |
755 | elfcpp::Swap_unaligned<32, false>::writeval(pov + 2, |
756 | (got_address + got_offset | |
757 | - (plt_address + plt_offset | |
758 | + 6))); | |
2e30d253 ILT |
759 | |
760 | elfcpp::Swap_unaligned<32, false>::writeval(pov + 7, plt_index); | |
761 | elfcpp::Swap<32, false>::writeval(pov + 12, | |
762 | - (plt_offset + plt_entry_size)); | |
763 | ||
764 | // Set the entry in the GOT. | |
765 | elfcpp::Swap<64, false>::writeval(got_pov, plt_address + plt_offset + 6); | |
766 | } | |
767 | ||
c2b45e22 CC |
768 | if (this->has_tlsdesc_entry()) |
769 | { | |
770 | // Set and adjust the reserved TLSDESC PLT entry. | |
771 | unsigned int tlsdesc_got_offset = this->get_tlsdesc_got_offset(); | |
772 | memcpy(pov, tlsdesc_plt_entry, plt_entry_size); | |
773 | elfcpp::Swap_unaligned<32, false>::writeval(pov + 2, | |
774 | (got_address + 8 | |
775 | - (plt_address + plt_offset | |
776 | + 6))); | |
777 | elfcpp::Swap_unaligned<32, false>::writeval(pov + 8, | |
778 | (got_base | |
779 | + tlsdesc_got_offset | |
780 | - (plt_address + plt_offset | |
781 | + 12))); | |
782 | pov += plt_entry_size; | |
783 | } | |
784 | ||
fe8718a4 ILT |
785 | gold_assert(static_cast<section_size_type>(pov - oview) == oview_size); |
786 | gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size); | |
2e30d253 | 787 | |
2ea97941 | 788 | of->write_output_view(offset, oview_size, oview); |
2e30d253 ILT |
789 | of->write_output_view(got_file_offset, got_size, got_view); |
790 | } | |
791 | ||
c2b45e22 | 792 | // Create the PLT section. |
2e30d253 ILT |
793 | |
794 | void | |
c2b45e22 | 795 | Target_x86_64::make_plt_section(Symbol_table* symtab, Layout* layout) |
2e30d253 | 796 | { |
2e30d253 ILT |
797 | if (this->plt_ == NULL) |
798 | { | |
799 | // Create the GOT sections first. | |
800 | this->got_section(symtab, layout); | |
801 | ||
c2b45e22 CC |
802 | this->plt_ = new Output_data_plt_x86_64(layout, this->got_, |
803 | this->got_plt_); | |
2e30d253 ILT |
804 | layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS, |
805 | (elfcpp::SHF_ALLOC | |
806 | | elfcpp::SHF_EXECINSTR), | |
f5c870d2 | 807 | this->plt_, false); |
2e30d253 | 808 | } |
c2b45e22 CC |
809 | } |
810 | ||
811 | // Create a PLT entry for a global symbol. | |
812 | ||
813 | void | |
814 | Target_x86_64::make_plt_entry(Symbol_table* symtab, Layout* layout, | |
815 | Symbol* gsym) | |
816 | { | |
817 | if (gsym->has_plt_offset()) | |
818 | return; | |
819 | ||
820 | if (this->plt_ == NULL) | |
821 | this->make_plt_section(symtab, layout); | |
2e30d253 ILT |
822 | |
823 | this->plt_->add_entry(gsym); | |
824 | } | |
825 | ||
9fa33bee | 826 | // Define the _TLS_MODULE_BASE_ symbol in the TLS segment. |
edfbb029 CC |
827 | |
828 | void | |
829 | Target_x86_64::define_tls_base_symbol(Symbol_table* symtab, Layout* layout) | |
830 | { | |
831 | if (this->tls_base_symbol_defined_) | |
832 | return; | |
833 | ||
834 | Output_segment* tls_segment = layout->tls_segment(); | |
835 | if (tls_segment != NULL) | |
836 | { | |
183fd0e3 | 837 | bool is_exec = parameters->options().output_is_executable(); |
edfbb029 CC |
838 | symtab->define_in_output_segment("_TLS_MODULE_BASE_", NULL, |
839 | tls_segment, 0, 0, | |
840 | elfcpp::STT_TLS, | |
841 | elfcpp::STB_LOCAL, | |
842 | elfcpp::STV_HIDDEN, 0, | |
183fd0e3 AO |
843 | (is_exec |
844 | ? Symbol::SEGMENT_END | |
845 | : Symbol::SEGMENT_START), | |
846 | true); | |
edfbb029 CC |
847 | } |
848 | this->tls_base_symbol_defined_ = true; | |
849 | } | |
850 | ||
c2b45e22 CC |
851 | // Create the reserved PLT and GOT entries for the TLS descriptor resolver. |
852 | ||
853 | void | |
854 | Target_x86_64::reserve_tlsdesc_entries(Symbol_table* symtab, | |
855 | Layout* layout) | |
856 | { | |
857 | if (this->plt_ == NULL) | |
858 | this->make_plt_section(symtab, layout); | |
859 | ||
860 | if (!this->plt_->has_tlsdesc_entry()) | |
861 | { | |
862 | // Allocate the TLSDESC_GOT entry. | |
863 | Output_data_got<64, false>* got = this->got_section(symtab, layout); | |
864 | unsigned int got_offset = got->add_constant(0); | |
865 | ||
866 | // Allocate the TLSDESC_PLT entry. | |
867 | this->plt_->reserve_tlsdesc_entry(got_offset); | |
868 | } | |
869 | } | |
870 | ||
31d60480 ILT |
871 | // Create a GOT entry for the TLS module index. |
872 | ||
873 | unsigned int | |
874 | Target_x86_64::got_mod_index_entry(Symbol_table* symtab, Layout* layout, | |
875 | Sized_relobj<64, false>* object) | |
876 | { | |
877 | if (this->got_mod_index_offset_ == -1U) | |
878 | { | |
879 | gold_assert(symtab != NULL && layout != NULL && object != NULL); | |
880 | Reloc_section* rela_dyn = this->rela_dyn_section(layout); | |
881 | Output_data_got<64, false>* got = this->got_section(symtab, layout); | |
882 | unsigned int got_offset = got->add_constant(0); | |
883 | rela_dyn->add_local(object, 0, elfcpp::R_X86_64_DTPMOD64, got, | |
884 | got_offset, 0); | |
009a67a2 | 885 | got->add_constant(0); |
31d60480 ILT |
886 | this->got_mod_index_offset_ = got_offset; |
887 | } | |
888 | return this->got_mod_index_offset_; | |
889 | } | |
890 | ||
2e30d253 ILT |
891 | // Optimize the TLS relocation type based on what we know about the |
892 | // symbol. IS_FINAL is true if the final address of this symbol is | |
893 | // known at link time. | |
894 | ||
e041f13d | 895 | tls::Tls_optimization |
2e30d253 ILT |
896 | Target_x86_64::optimize_tls_reloc(bool is_final, int r_type) |
897 | { | |
2e30d253 ILT |
898 | // If we are generating a shared library, then we can't do anything |
899 | // in the linker. | |
8851ecca | 900 | if (parameters->options().shared()) |
e041f13d | 901 | return tls::TLSOPT_NONE; |
2e30d253 ILT |
902 | |
903 | switch (r_type) | |
904 | { | |
905 | case elfcpp::R_X86_64_TLSGD: | |
e041f13d ILT |
906 | case elfcpp::R_X86_64_GOTPC32_TLSDESC: |
907 | case elfcpp::R_X86_64_TLSDESC_CALL: | |
908 | // These are General-Dynamic which permits fully general TLS | |
2e30d253 ILT |
909 | // access. Since we know that we are generating an executable, |
910 | // we can convert this to Initial-Exec. If we also know that | |
911 | // this is a local symbol, we can further switch to Local-Exec. | |
912 | if (is_final) | |
e041f13d ILT |
913 | return tls::TLSOPT_TO_LE; |
914 | return tls::TLSOPT_TO_IE; | |
2e30d253 | 915 | |
d61c17ea | 916 | case elfcpp::R_X86_64_TLSLD: |
2e30d253 ILT |
917 | // This is Local-Dynamic, which refers to a local symbol in the |
918 | // dynamic TLS block. Since we know that we generating an | |
919 | // executable, we can switch to Local-Exec. | |
e041f13d | 920 | return tls::TLSOPT_TO_LE; |
2e30d253 | 921 | |
0ffd9845 | 922 | case elfcpp::R_X86_64_DTPOFF32: |
0ffd9845 ILT |
923 | case elfcpp::R_X86_64_DTPOFF64: |
924 | // Another Local-Dynamic reloc. | |
e041f13d | 925 | return tls::TLSOPT_TO_LE; |
0ffd9845 | 926 | |
d61c17ea | 927 | case elfcpp::R_X86_64_GOTTPOFF: |
2e30d253 ILT |
928 | // These are Initial-Exec relocs which get the thread offset |
929 | // from the GOT. If we know that we are linking against the | |
930 | // local symbol, we can switch to Local-Exec, which links the | |
931 | // thread offset into the instruction. | |
932 | if (is_final) | |
e041f13d ILT |
933 | return tls::TLSOPT_TO_LE; |
934 | return tls::TLSOPT_NONE; | |
2e30d253 | 935 | |
d61c17ea | 936 | case elfcpp::R_X86_64_TPOFF32: |
2e30d253 ILT |
937 | // When we already have Local-Exec, there is nothing further we |
938 | // can do. | |
e041f13d | 939 | return tls::TLSOPT_NONE; |
2e30d253 ILT |
940 | |
941 | default: | |
942 | gold_unreachable(); | |
943 | } | |
2e30d253 ILT |
944 | } |
945 | ||
e041f13d ILT |
946 | // Report an unsupported relocation against a local symbol. |
947 | ||
948 | void | |
949 | Target_x86_64::Scan::unsupported_reloc_local(Sized_relobj<64, false>* object, | |
950 | unsigned int r_type) | |
951 | { | |
75f2446e ILT |
952 | gold_error(_("%s: unsupported reloc %u against local symbol"), |
953 | object->name().c_str(), r_type); | |
e041f13d ILT |
954 | } |
955 | ||
a036edd8 ILT |
956 | // We are about to emit a dynamic relocation of type R_TYPE. If the |
957 | // dynamic linker does not support it, issue an error. The GNU linker | |
958 | // only issues a non-PIC error for an allocated read-only section. | |
959 | // Here we know the section is allocated, but we don't know that it is | |
960 | // read-only. But we check for all the relocation types which the | |
961 | // glibc dynamic linker supports, so it seems appropriate to issue an | |
962 | // error even if the section is not read-only. | |
963 | ||
964 | void | |
965 | Target_x86_64::Scan::check_non_pic(Relobj* object, unsigned int r_type) | |
966 | { | |
967 | switch (r_type) | |
968 | { | |
969 | // These are the relocation types supported by glibc for x86_64. | |
970 | case elfcpp::R_X86_64_RELATIVE: | |
971 | case elfcpp::R_X86_64_GLOB_DAT: | |
972 | case elfcpp::R_X86_64_JUMP_SLOT: | |
973 | case elfcpp::R_X86_64_DTPMOD64: | |
974 | case elfcpp::R_X86_64_DTPOFF64: | |
975 | case elfcpp::R_X86_64_TPOFF64: | |
976 | case elfcpp::R_X86_64_64: | |
977 | case elfcpp::R_X86_64_32: | |
978 | case elfcpp::R_X86_64_PC32: | |
979 | case elfcpp::R_X86_64_COPY: | |
980 | return; | |
981 | ||
982 | default: | |
983 | // This prevents us from issuing more than one error per reloc | |
984 | // section. But we can still wind up issuing more than one | |
985 | // error per object file. | |
986 | if (this->issued_non_pic_error_) | |
987 | return; | |
33aea2fd | 988 | gold_assert(parameters->options().output_is_position_independent()); |
a036edd8 ILT |
989 | object->error(_("requires unsupported dynamic reloc; " |
990 | "recompile with -fPIC")); | |
991 | this->issued_non_pic_error_ = true; | |
992 | return; | |
993 | ||
994 | case elfcpp::R_X86_64_NONE: | |
995 | gold_unreachable(); | |
996 | } | |
997 | } | |
998 | ||
2e30d253 ILT |
999 | // Scan a relocation for a local symbol. |
1000 | ||
1001 | inline void | |
ad0f2072 | 1002 | Target_x86_64::Scan::local(Symbol_table* symtab, |
d61c17ea ILT |
1003 | Layout* layout, |
1004 | Target_x86_64* target, | |
1005 | Sized_relobj<64, false>* object, | |
0ffd9845 | 1006 | unsigned int data_shndx, |
4f4c5f80 | 1007 | Output_section* output_section, |
0ffd9845 | 1008 | const elfcpp::Rela<64, false>& reloc, |
d61c17ea | 1009 | unsigned int r_type, |
7bf1f802 | 1010 | const elfcpp::Sym<64, false>& lsym) |
2e30d253 ILT |
1011 | { |
1012 | switch (r_type) | |
1013 | { | |
1014 | case elfcpp::R_X86_64_NONE: | |
e822f2b1 ILT |
1015 | case elfcpp::R_386_GNU_VTINHERIT: |
1016 | case elfcpp::R_386_GNU_VTENTRY: | |
2e30d253 ILT |
1017 | break; |
1018 | ||
1019 | case elfcpp::R_X86_64_64: | |
d61c6bd4 | 1020 | // If building a shared library (or a position-independent |
dceae3c1 ILT |
1021 | // executable), we need to create a dynamic relocation for this |
1022 | // location. The relocation applied at link time will apply the | |
1023 | // link-time value, so we flag the location with an | |
1024 | // R_X86_64_RELATIVE relocation so the dynamic loader can | |
d61c6bd4 | 1025 | // relocate it easily. |
8851ecca | 1026 | if (parameters->options().output_is_position_independent()) |
d61c6bd4 | 1027 | { |
e8c846c3 | 1028 | unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info()); |
d61c6bd4 | 1029 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
e8c846c3 ILT |
1030 | rela_dyn->add_local_relative(object, r_sym, |
1031 | elfcpp::R_X86_64_RELATIVE, | |
1032 | output_section, data_shndx, | |
1033 | reloc.get_r_offset(), | |
1034 | reloc.get_r_addend()); | |
d61c6bd4 ILT |
1035 | } |
1036 | break; | |
1037 | ||
2e30d253 ILT |
1038 | case elfcpp::R_X86_64_32: |
1039 | case elfcpp::R_X86_64_32S: | |
1040 | case elfcpp::R_X86_64_16: | |
1041 | case elfcpp::R_X86_64_8: | |
96f2030e | 1042 | // If building a shared library (or a position-independent |
dceae3c1 ILT |
1043 | // executable), we need to create a dynamic relocation for this |
1044 | // location. We can't use an R_X86_64_RELATIVE relocation | |
1045 | // because that is always a 64-bit relocation. | |
8851ecca | 1046 | if (parameters->options().output_is_position_independent()) |
96f2030e | 1047 | { |
a036edd8 ILT |
1048 | this->check_non_pic(object, r_type); |
1049 | ||
96f2030e | 1050 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
d491d34e | 1051 | unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info()); |
dceae3c1 | 1052 | if (lsym.get_st_type() != elfcpp::STT_SECTION) |
d491d34e ILT |
1053 | rela_dyn->add_local(object, r_sym, r_type, output_section, |
1054 | data_shndx, reloc.get_r_offset(), | |
1055 | reloc.get_r_addend()); | |
dceae3c1 ILT |
1056 | else |
1057 | { | |
1058 | gold_assert(lsym.get_st_value() == 0); | |
d491d34e ILT |
1059 | unsigned int shndx = lsym.get_st_shndx(); |
1060 | bool is_ordinary; | |
1061 | shndx = object->adjust_sym_shndx(r_sym, shndx, | |
1062 | &is_ordinary); | |
1063 | if (!is_ordinary) | |
1064 | object->error(_("section symbol %u has bad shndx %u"), | |
1065 | r_sym, shndx); | |
1066 | else | |
1067 | rela_dyn->add_local_section(object, shndx, | |
1068 | r_type, output_section, | |
1069 | data_shndx, reloc.get_r_offset(), | |
1070 | reloc.get_r_addend()); | |
dceae3c1 | 1071 | } |
96f2030e | 1072 | } |
2e30d253 ILT |
1073 | break; |
1074 | ||
1075 | case elfcpp::R_X86_64_PC64: | |
1076 | case elfcpp::R_X86_64_PC32: | |
1077 | case elfcpp::R_X86_64_PC16: | |
1078 | case elfcpp::R_X86_64_PC8: | |
1079 | break; | |
1080 | ||
f389a824 ILT |
1081 | case elfcpp::R_X86_64_PLT32: |
1082 | // Since we know this is a local symbol, we can handle this as a | |
1083 | // PC32 reloc. | |
1084 | break; | |
1085 | ||
fdc2f80f | 1086 | case elfcpp::R_X86_64_GOTPC32: |
e822f2b1 | 1087 | case elfcpp::R_X86_64_GOTOFF64: |
fdc2f80f ILT |
1088 | case elfcpp::R_X86_64_GOTPC64: |
1089 | case elfcpp::R_X86_64_PLTOFF64: | |
2e30d253 ILT |
1090 | // We need a GOT section. |
1091 | target->got_section(symtab, layout); | |
ee9e9e86 ILT |
1092 | // For PLTOFF64, we'd normally want a PLT section, but since we |
1093 | // know this is a local symbol, no PLT is needed. | |
2e30d253 ILT |
1094 | break; |
1095 | ||
0ffd9845 ILT |
1096 | case elfcpp::R_X86_64_GOT64: |
1097 | case elfcpp::R_X86_64_GOT32: | |
1098 | case elfcpp::R_X86_64_GOTPCREL64: | |
1099 | case elfcpp::R_X86_64_GOTPCREL: | |
ee9e9e86 | 1100 | case elfcpp::R_X86_64_GOTPLT64: |
0ffd9845 ILT |
1101 | { |
1102 | // The symbol requires a GOT entry. | |
1103 | Output_data_got<64, false>* got = target->got_section(symtab, layout); | |
1104 | unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info()); | |
0a65a3a7 | 1105 | if (got->add_local(object, r_sym, GOT_TYPE_STANDARD)) |
0ffd9845 ILT |
1106 | { |
1107 | // If we are generating a shared object, we need to add a | |
7bf1f802 | 1108 | // dynamic relocation for this symbol's GOT entry. |
8851ecca | 1109 | if (parameters->options().output_is_position_independent()) |
0ffd9845 ILT |
1110 | { |
1111 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
7bf1f802 ILT |
1112 | // R_X86_64_RELATIVE assumes a 64-bit relocation. |
1113 | if (r_type != elfcpp::R_X86_64_GOT32) | |
0a65a3a7 CC |
1114 | rela_dyn->add_local_relative( |
1115 | object, r_sym, elfcpp::R_X86_64_RELATIVE, got, | |
1116 | object->local_got_offset(r_sym, GOT_TYPE_STANDARD), 0); | |
7bf1f802 | 1117 | else |
dceae3c1 | 1118 | { |
a036edd8 ILT |
1119 | this->check_non_pic(object, r_type); |
1120 | ||
dceae3c1 | 1121 | gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION); |
0a65a3a7 CC |
1122 | rela_dyn->add_local( |
1123 | object, r_sym, r_type, got, | |
1124 | object->local_got_offset(r_sym, GOT_TYPE_STANDARD), 0); | |
dceae3c1 | 1125 | } |
0ffd9845 ILT |
1126 | } |
1127 | } | |
ee9e9e86 ILT |
1128 | // For GOTPLT64, we'd normally want a PLT section, but since |
1129 | // we know this is a local symbol, no PLT is needed. | |
0ffd9845 ILT |
1130 | } |
1131 | break; | |
1132 | ||
2e30d253 ILT |
1133 | case elfcpp::R_X86_64_COPY: |
1134 | case elfcpp::R_X86_64_GLOB_DAT: | |
1135 | case elfcpp::R_X86_64_JUMP_SLOT: | |
1136 | case elfcpp::R_X86_64_RELATIVE: | |
d61c17ea | 1137 | // These are outstanding tls relocs, which are unexpected when linking |
2e30d253 | 1138 | case elfcpp::R_X86_64_TPOFF64: |
2e30d253 | 1139 | case elfcpp::R_X86_64_DTPMOD64: |
2e30d253 | 1140 | case elfcpp::R_X86_64_TLSDESC: |
75f2446e ILT |
1141 | gold_error(_("%s: unexpected reloc %u in object file"), |
1142 | object->name().c_str(), r_type); | |
2e30d253 ILT |
1143 | break; |
1144 | ||
d61c17ea | 1145 | // These are initial tls relocs, which are expected when linking |
56622147 ILT |
1146 | case elfcpp::R_X86_64_TLSGD: // Global-dynamic |
1147 | case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url) | |
e041f13d | 1148 | case elfcpp::R_X86_64_TLSDESC_CALL: |
56622147 | 1149 | case elfcpp::R_X86_64_TLSLD: // Local-dynamic |
0ffd9845 ILT |
1150 | case elfcpp::R_X86_64_DTPOFF32: |
1151 | case elfcpp::R_X86_64_DTPOFF64: | |
56622147 ILT |
1152 | case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec |
1153 | case elfcpp::R_X86_64_TPOFF32: // Local-exec | |
2e30d253 | 1154 | { |
8851ecca | 1155 | bool output_is_shared = parameters->options().shared(); |
e041f13d ILT |
1156 | const tls::Tls_optimization optimized_type |
1157 | = Target_x86_64::optimize_tls_reloc(!output_is_shared, r_type); | |
2e30d253 ILT |
1158 | switch (r_type) |
1159 | { | |
56622147 | 1160 | case elfcpp::R_X86_64_TLSGD: // General-dynamic |
7bf1f802 ILT |
1161 | if (optimized_type == tls::TLSOPT_NONE) |
1162 | { | |
1163 | // Create a pair of GOT entries for the module index and | |
1164 | // dtv-relative offset. | |
1165 | Output_data_got<64, false>* got | |
1166 | = target->got_section(symtab, layout); | |
1167 | unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info()); | |
d491d34e ILT |
1168 | unsigned int shndx = lsym.get_st_shndx(); |
1169 | bool is_ordinary; | |
1170 | shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary); | |
1171 | if (!is_ordinary) | |
1172 | object->error(_("local symbol %u has bad shndx %u"), | |
1173 | r_sym, shndx); | |
1174 | else | |
1175 | got->add_local_pair_with_rela(object, r_sym, | |
1176 | shndx, | |
1177 | GOT_TYPE_TLS_PAIR, | |
1178 | target->rela_dyn_section(layout), | |
1179 | elfcpp::R_X86_64_DTPMOD64, 0); | |
7bf1f802 ILT |
1180 | } |
1181 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
1182 | unsupported_reloc_local(object, r_type); | |
1183 | break; | |
1184 | ||
56622147 | 1185 | case elfcpp::R_X86_64_GOTPC32_TLSDESC: |
edfbb029 | 1186 | target->define_tls_base_symbol(symtab, layout); |
c2b45e22 CC |
1187 | if (optimized_type == tls::TLSOPT_NONE) |
1188 | { | |
1189 | // Create reserved PLT and GOT entries for the resolver. | |
1190 | target->reserve_tlsdesc_entries(symtab, layout); | |
1191 | ||
1192 | // Generate a double GOT entry with an R_X86_64_TLSDESC reloc. | |
1193 | Output_data_got<64, false>* got | |
1194 | = target->got_section(symtab, layout); | |
1195 | unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info()); | |
d491d34e ILT |
1196 | unsigned int shndx = lsym.get_st_shndx(); |
1197 | bool is_ordinary; | |
1198 | shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary); | |
1199 | if (!is_ordinary) | |
1200 | object->error(_("local symbol %u has bad shndx %u"), | |
1201 | r_sym, shndx); | |
1202 | else | |
1203 | got->add_local_pair_with_rela(object, r_sym, | |
1204 | shndx, | |
1205 | GOT_TYPE_TLS_DESC, | |
1206 | target->rela_dyn_section(layout), | |
1207 | elfcpp::R_X86_64_TLSDESC, 0); | |
c2b45e22 CC |
1208 | } |
1209 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
56622147 | 1210 | unsupported_reloc_local(object, r_type); |
2e30d253 ILT |
1211 | break; |
1212 | ||
c2b45e22 CC |
1213 | case elfcpp::R_X86_64_TLSDESC_CALL: |
1214 | break; | |
1215 | ||
e041f13d | 1216 | case elfcpp::R_X86_64_TLSLD: // Local-dynamic |
7bf1f802 ILT |
1217 | if (optimized_type == tls::TLSOPT_NONE) |
1218 | { | |
1219 | // Create a GOT entry for the module index. | |
31d60480 | 1220 | target->got_mod_index_entry(symtab, layout, object); |
7bf1f802 ILT |
1221 | } |
1222 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
1223 | unsupported_reloc_local(object, r_type); | |
1224 | break; | |
1225 | ||
0ffd9845 ILT |
1226 | case elfcpp::R_X86_64_DTPOFF32: |
1227 | case elfcpp::R_X86_64_DTPOFF64: | |
e041f13d ILT |
1228 | break; |
1229 | ||
56622147 | 1230 | case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec |
535890bb | 1231 | layout->set_has_static_tls(); |
7bf1f802 ILT |
1232 | if (optimized_type == tls::TLSOPT_NONE) |
1233 | { | |
1234 | // Create a GOT entry for the tp-relative offset. | |
1235 | Output_data_got<64, false>* got | |
1236 | = target->got_section(symtab, layout); | |
1237 | unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info()); | |
0a65a3a7 | 1238 | got->add_local_with_rela(object, r_sym, GOT_TYPE_TLS_OFFSET, |
7bf1f802 ILT |
1239 | target->rela_dyn_section(layout), |
1240 | elfcpp::R_X86_64_TPOFF64); | |
1241 | } | |
1242 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
56622147 ILT |
1243 | unsupported_reloc_local(object, r_type); |
1244 | break; | |
0ffd9845 | 1245 | |
56622147 | 1246 | case elfcpp::R_X86_64_TPOFF32: // Local-exec |
535890bb | 1247 | layout->set_has_static_tls(); |
7bf1f802 ILT |
1248 | if (output_is_shared) |
1249 | unsupported_reloc_local(object, r_type); | |
2e30d253 | 1250 | break; |
e041f13d ILT |
1251 | |
1252 | default: | |
1253 | gold_unreachable(); | |
2e30d253 ILT |
1254 | } |
1255 | } | |
1256 | break; | |
2e30d253 | 1257 | |
fdc2f80f ILT |
1258 | case elfcpp::R_X86_64_SIZE32: |
1259 | case elfcpp::R_X86_64_SIZE64: | |
2e30d253 | 1260 | default: |
75f2446e ILT |
1261 | gold_error(_("%s: unsupported reloc %u against local symbol"), |
1262 | object->name().c_str(), r_type); | |
2e30d253 ILT |
1263 | break; |
1264 | } | |
1265 | } | |
1266 | ||
1267 | ||
e041f13d ILT |
1268 | // Report an unsupported relocation against a global symbol. |
1269 | ||
1270 | void | |
1271 | Target_x86_64::Scan::unsupported_reloc_global(Sized_relobj<64, false>* object, | |
1272 | unsigned int r_type, | |
1273 | Symbol* gsym) | |
1274 | { | |
75f2446e | 1275 | gold_error(_("%s: unsupported reloc %u against global symbol %s"), |
a2b1aa12 | 1276 | object->name().c_str(), r_type, gsym->demangled_name().c_str()); |
e041f13d ILT |
1277 | } |
1278 | ||
2e30d253 ILT |
1279 | // Scan a relocation for a global symbol. |
1280 | ||
1281 | inline void | |
ad0f2072 | 1282 | Target_x86_64::Scan::global(Symbol_table* symtab, |
d61c17ea ILT |
1283 | Layout* layout, |
1284 | Target_x86_64* target, | |
1285 | Sized_relobj<64, false>* object, | |
1286 | unsigned int data_shndx, | |
4f4c5f80 | 1287 | Output_section* output_section, |
d61c17ea ILT |
1288 | const elfcpp::Rela<64, false>& reloc, |
1289 | unsigned int r_type, | |
1290 | Symbol* gsym) | |
2e30d253 ILT |
1291 | { |
1292 | switch (r_type) | |
1293 | { | |
1294 | case elfcpp::R_X86_64_NONE: | |
e822f2b1 ILT |
1295 | case elfcpp::R_386_GNU_VTINHERIT: |
1296 | case elfcpp::R_386_GNU_VTENTRY: | |
2e30d253 ILT |
1297 | break; |
1298 | ||
1299 | case elfcpp::R_X86_64_64: | |
2e30d253 ILT |
1300 | case elfcpp::R_X86_64_32: |
1301 | case elfcpp::R_X86_64_32S: | |
2e30d253 | 1302 | case elfcpp::R_X86_64_16: |
2e30d253 | 1303 | case elfcpp::R_X86_64_8: |
96f2030e | 1304 | { |
d61c6bd4 ILT |
1305 | // Make a PLT entry if necessary. |
1306 | if (gsym->needs_plt_entry()) | |
1307 | { | |
1308 | target->make_plt_entry(symtab, layout, gsym); | |
1309 | // Since this is not a PC-relative relocation, we may be | |
1310 | // taking the address of a function. In that case we need to | |
1311 | // set the entry in the dynamic symbol table to the address of | |
1312 | // the PLT entry. | |
8851ecca | 1313 | if (gsym->is_from_dynobj() && !parameters->options().shared()) |
d61c6bd4 ILT |
1314 | gsym->set_needs_dynsym_value(); |
1315 | } | |
1316 | // Make a dynamic relocation if necessary. | |
0700cf32 | 1317 | if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF)) |
d61c6bd4 | 1318 | { |
966d4097 | 1319 | if (gsym->may_need_copy_reloc()) |
d61c6bd4 | 1320 | { |
12c0daef | 1321 | target->copy_reloc(symtab, layout, object, |
7bf1f802 | 1322 | data_shndx, output_section, gsym, reloc); |
d61c6bd4 ILT |
1323 | } |
1324 | else if (r_type == elfcpp::R_X86_64_64 | |
1325 | && gsym->can_use_relative_reloc(false)) | |
1326 | { | |
1327 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
e8c846c3 ILT |
1328 | rela_dyn->add_global_relative(gsym, elfcpp::R_X86_64_RELATIVE, |
1329 | output_section, object, | |
1330 | data_shndx, reloc.get_r_offset(), | |
1331 | reloc.get_r_addend()); | |
d61c6bd4 ILT |
1332 | } |
1333 | else | |
1334 | { | |
a036edd8 | 1335 | this->check_non_pic(object, r_type); |
96f2030e | 1336 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
4f4c5f80 ILT |
1337 | rela_dyn->add_global(gsym, r_type, output_section, object, |
1338 | data_shndx, reloc.get_r_offset(), | |
96f2030e | 1339 | reloc.get_r_addend()); |
d61c6bd4 ILT |
1340 | } |
1341 | } | |
1342 | } | |
1343 | break; | |
1344 | ||
1345 | case elfcpp::R_X86_64_PC64: | |
1346 | case elfcpp::R_X86_64_PC32: | |
1347 | case elfcpp::R_X86_64_PC16: | |
1348 | case elfcpp::R_X86_64_PC8: | |
1349 | { | |
1350 | // Make a PLT entry if necessary. | |
1351 | if (gsym->needs_plt_entry()) | |
1352 | target->make_plt_entry(symtab, layout, gsym); | |
1353 | // Make a dynamic relocation if necessary. | |
0700cf32 | 1354 | int flags = Symbol::NON_PIC_REF; |
53d7974c | 1355 | if (gsym->is_func()) |
0700cf32 ILT |
1356 | flags |= Symbol::FUNCTION_CALL; |
1357 | if (gsym->needs_dynamic_reloc(flags)) | |
86849f1f | 1358 | { |
966d4097 | 1359 | if (gsym->may_need_copy_reloc()) |
d61c6bd4 | 1360 | { |
12c0daef | 1361 | target->copy_reloc(symtab, layout, object, |
7bf1f802 | 1362 | data_shndx, output_section, gsym, reloc); |
d61c6bd4 | 1363 | } |
86849f1f | 1364 | else |
d61c6bd4 | 1365 | { |
a036edd8 | 1366 | this->check_non_pic(object, r_type); |
d61c6bd4 | 1367 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
4f4c5f80 ILT |
1368 | rela_dyn->add_global(gsym, r_type, output_section, object, |
1369 | data_shndx, reloc.get_r_offset(), | |
d61c6bd4 ILT |
1370 | reloc.get_r_addend()); |
1371 | } | |
86849f1f | 1372 | } |
d61c6bd4 | 1373 | } |
2e30d253 ILT |
1374 | break; |
1375 | ||
ff006520 | 1376 | case elfcpp::R_X86_64_GOT64: |
2e30d253 | 1377 | case elfcpp::R_X86_64_GOT32: |
ff006520 ILT |
1378 | case elfcpp::R_X86_64_GOTPCREL64: |
1379 | case elfcpp::R_X86_64_GOTPCREL: | |
1380 | case elfcpp::R_X86_64_GOTPLT64: | |
2e30d253 ILT |
1381 | { |
1382 | // The symbol requires a GOT entry. | |
1383 | Output_data_got<64, false>* got = target->got_section(symtab, layout); | |
7bf1f802 | 1384 | if (gsym->final_value_is_known()) |
0a65a3a7 | 1385 | got->add_global(gsym, GOT_TYPE_STANDARD); |
7bf1f802 ILT |
1386 | else |
1387 | { | |
2e30d253 ILT |
1388 | // If this symbol is not fully resolved, we need to add a |
1389 | // dynamic relocation for it. | |
7bf1f802 | 1390 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
8fc19601 ILT |
1391 | if (gsym->is_from_dynobj() |
1392 | || gsym->is_undefined() | |
1393 | || gsym->is_preemptible()) | |
0a65a3a7 | 1394 | got->add_global_with_rela(gsym, GOT_TYPE_STANDARD, rela_dyn, |
7bf1f802 ILT |
1395 | elfcpp::R_X86_64_GLOB_DAT); |
1396 | else | |
2e30d253 | 1397 | { |
0a65a3a7 CC |
1398 | if (got->add_global(gsym, GOT_TYPE_STANDARD)) |
1399 | rela_dyn->add_global_relative( | |
1400 | gsym, elfcpp::R_X86_64_RELATIVE, got, | |
1401 | gsym->got_offset(GOT_TYPE_STANDARD), 0); | |
2e30d253 ILT |
1402 | } |
1403 | } | |
ee9e9e86 ILT |
1404 | // For GOTPLT64, we also need a PLT entry (but only if the |
1405 | // symbol is not fully resolved). | |
1406 | if (r_type == elfcpp::R_X86_64_GOTPLT64 | |
1407 | && !gsym->final_value_is_known()) | |
1408 | target->make_plt_entry(symtab, layout, gsym); | |
2e30d253 ILT |
1409 | } |
1410 | break; | |
1411 | ||
1412 | case elfcpp::R_X86_64_PLT32: | |
1413 | // If the symbol is fully resolved, this is just a PC32 reloc. | |
1414 | // Otherwise we need a PLT entry. | |
1415 | if (gsym->final_value_is_known()) | |
1416 | break; | |
96f2030e ILT |
1417 | // If building a shared library, we can also skip the PLT entry |
1418 | // if the symbol is defined in the output file and is protected | |
1419 | // or hidden. | |
1420 | if (gsym->is_defined() | |
1421 | && !gsym->is_from_dynobj() | |
1422 | && !gsym->is_preemptible()) | |
1423 | break; | |
2e30d253 ILT |
1424 | target->make_plt_entry(symtab, layout, gsym); |
1425 | break; | |
1426 | ||
fdc2f80f | 1427 | case elfcpp::R_X86_64_GOTPC32: |
e822f2b1 | 1428 | case elfcpp::R_X86_64_GOTOFF64: |
fdc2f80f ILT |
1429 | case elfcpp::R_X86_64_GOTPC64: |
1430 | case elfcpp::R_X86_64_PLTOFF64: | |
2e30d253 ILT |
1431 | // We need a GOT section. |
1432 | target->got_section(symtab, layout); | |
ee9e9e86 ILT |
1433 | // For PLTOFF64, we also need a PLT entry (but only if the |
1434 | // symbol is not fully resolved). | |
1435 | if (r_type == elfcpp::R_X86_64_PLTOFF64 | |
1436 | && !gsym->final_value_is_known()) | |
1437 | target->make_plt_entry(symtab, layout, gsym); | |
2e30d253 ILT |
1438 | break; |
1439 | ||
2e30d253 ILT |
1440 | case elfcpp::R_X86_64_COPY: |
1441 | case elfcpp::R_X86_64_GLOB_DAT: | |
1442 | case elfcpp::R_X86_64_JUMP_SLOT: | |
1443 | case elfcpp::R_X86_64_RELATIVE: | |
d61c17ea | 1444 | // These are outstanding tls relocs, which are unexpected when linking |
e822f2b1 | 1445 | case elfcpp::R_X86_64_TPOFF64: |
2e30d253 | 1446 | case elfcpp::R_X86_64_DTPMOD64: |
e822f2b1 | 1447 | case elfcpp::R_X86_64_TLSDESC: |
75f2446e ILT |
1448 | gold_error(_("%s: unexpected reloc %u in object file"), |
1449 | object->name().c_str(), r_type); | |
2e30d253 | 1450 | break; |
2e30d253 | 1451 | |
d61c17ea | 1452 | // These are initial tls relocs, which are expected for global() |
56622147 ILT |
1453 | case elfcpp::R_X86_64_TLSGD: // Global-dynamic |
1454 | case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url) | |
e041f13d | 1455 | case elfcpp::R_X86_64_TLSDESC_CALL: |
56622147 | 1456 | case elfcpp::R_X86_64_TLSLD: // Local-dynamic |
0ffd9845 ILT |
1457 | case elfcpp::R_X86_64_DTPOFF32: |
1458 | case elfcpp::R_X86_64_DTPOFF64: | |
56622147 ILT |
1459 | case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec |
1460 | case elfcpp::R_X86_64_TPOFF32: // Local-exec | |
2e30d253 ILT |
1461 | { |
1462 | const bool is_final = gsym->final_value_is_known(); | |
e041f13d ILT |
1463 | const tls::Tls_optimization optimized_type |
1464 | = Target_x86_64::optimize_tls_reloc(is_final, r_type); | |
2e30d253 ILT |
1465 | switch (r_type) |
1466 | { | |
56622147 | 1467 | case elfcpp::R_X86_64_TLSGD: // General-dynamic |
7bf1f802 ILT |
1468 | if (optimized_type == tls::TLSOPT_NONE) |
1469 | { | |
1470 | // Create a pair of GOT entries for the module index and | |
1471 | // dtv-relative offset. | |
1472 | Output_data_got<64, false>* got | |
1473 | = target->got_section(symtab, layout); | |
0a65a3a7 CC |
1474 | got->add_global_pair_with_rela(gsym, GOT_TYPE_TLS_PAIR, |
1475 | target->rela_dyn_section(layout), | |
1476 | elfcpp::R_X86_64_DTPMOD64, | |
1477 | elfcpp::R_X86_64_DTPOFF64); | |
7bf1f802 ILT |
1478 | } |
1479 | else if (optimized_type == tls::TLSOPT_TO_IE) | |
1480 | { | |
1481 | // Create a GOT entry for the tp-relative offset. | |
1482 | Output_data_got<64, false>* got | |
1483 | = target->got_section(symtab, layout); | |
0a65a3a7 | 1484 | got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET, |
7bf1f802 ILT |
1485 | target->rela_dyn_section(layout), |
1486 | elfcpp::R_X86_64_TPOFF64); | |
1487 | } | |
1488 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
1489 | unsupported_reloc_global(object, r_type, gsym); | |
1490 | break; | |
1491 | ||
56622147 | 1492 | case elfcpp::R_X86_64_GOTPC32_TLSDESC: |
edfbb029 | 1493 | target->define_tls_base_symbol(symtab, layout); |
c2b45e22 CC |
1494 | if (optimized_type == tls::TLSOPT_NONE) |
1495 | { | |
1496 | // Create reserved PLT and GOT entries for the resolver. | |
1497 | target->reserve_tlsdesc_entries(symtab, layout); | |
1498 | ||
1499 | // Create a double GOT entry with an R_X86_64_TLSDESC reloc. | |
1500 | Output_data_got<64, false>* got | |
1501 | = target->got_section(symtab, layout); | |
1502 | got->add_global_pair_with_rela(gsym, GOT_TYPE_TLS_DESC, | |
1503 | target->rela_dyn_section(layout), | |
1504 | elfcpp::R_X86_64_TLSDESC, 0); | |
1505 | } | |
1506 | else if (optimized_type == tls::TLSOPT_TO_IE) | |
1507 | { | |
1508 | // Create a GOT entry for the tp-relative offset. | |
1509 | Output_data_got<64, false>* got | |
1510 | = target->got_section(symtab, layout); | |
1511 | got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET, | |
1512 | target->rela_dyn_section(layout), | |
1513 | elfcpp::R_X86_64_TPOFF64); | |
1514 | } | |
1515 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
56622147 | 1516 | unsupported_reloc_global(object, r_type, gsym); |
2e30d253 ILT |
1517 | break; |
1518 | ||
c2b45e22 CC |
1519 | case elfcpp::R_X86_64_TLSDESC_CALL: |
1520 | break; | |
1521 | ||
e041f13d | 1522 | case elfcpp::R_X86_64_TLSLD: // Local-dynamic |
7bf1f802 ILT |
1523 | if (optimized_type == tls::TLSOPT_NONE) |
1524 | { | |
1525 | // Create a GOT entry for the module index. | |
31d60480 | 1526 | target->got_mod_index_entry(symtab, layout, object); |
7bf1f802 ILT |
1527 | } |
1528 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
1529 | unsupported_reloc_global(object, r_type, gsym); | |
1530 | break; | |
1531 | ||
0ffd9845 ILT |
1532 | case elfcpp::R_X86_64_DTPOFF32: |
1533 | case elfcpp::R_X86_64_DTPOFF64: | |
e041f13d ILT |
1534 | break; |
1535 | ||
56622147 | 1536 | case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec |
535890bb | 1537 | layout->set_has_static_tls(); |
7bf1f802 ILT |
1538 | if (optimized_type == tls::TLSOPT_NONE) |
1539 | { | |
1540 | // Create a GOT entry for the tp-relative offset. | |
1541 | Output_data_got<64, false>* got | |
1542 | = target->got_section(symtab, layout); | |
0a65a3a7 | 1543 | got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET, |
7bf1f802 ILT |
1544 | target->rela_dyn_section(layout), |
1545 | elfcpp::R_X86_64_TPOFF64); | |
1546 | } | |
1547 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
56622147 ILT |
1548 | unsupported_reloc_global(object, r_type, gsym); |
1549 | break; | |
0ffd9845 | 1550 | |
56622147 | 1551 | case elfcpp::R_X86_64_TPOFF32: // Local-exec |
535890bb | 1552 | layout->set_has_static_tls(); |
8851ecca | 1553 | if (parameters->options().shared()) |
7bf1f802 | 1554 | unsupported_reloc_local(object, r_type); |
2e30d253 | 1555 | break; |
e041f13d ILT |
1556 | |
1557 | default: | |
1558 | gold_unreachable(); | |
2e30d253 ILT |
1559 | } |
1560 | } | |
1561 | break; | |
fdc2f80f ILT |
1562 | |
1563 | case elfcpp::R_X86_64_SIZE32: | |
1564 | case elfcpp::R_X86_64_SIZE64: | |
2e30d253 | 1565 | default: |
75f2446e | 1566 | gold_error(_("%s: unsupported reloc %u against global symbol %s"), |
a2b1aa12 ILT |
1567 | object->name().c_str(), r_type, |
1568 | gsym->demangled_name().c_str()); | |
2e30d253 ILT |
1569 | break; |
1570 | } | |
1571 | } | |
1572 | ||
6d03d481 | 1573 | void |
ad0f2072 | 1574 | Target_x86_64::gc_process_relocs(Symbol_table* symtab, |
6d03d481 ST |
1575 | Layout* layout, |
1576 | Sized_relobj<64, false>* object, | |
1577 | unsigned int data_shndx, | |
1578 | unsigned int sh_type, | |
1579 | const unsigned char* prelocs, | |
1580 | size_t reloc_count, | |
1581 | Output_section* output_section, | |
1582 | bool needs_special_offset_handling, | |
1583 | size_t local_symbol_count, | |
1584 | const unsigned char* plocal_symbols) | |
1585 | { | |
1586 | ||
1587 | if (sh_type == elfcpp::SHT_REL) | |
1588 | { | |
1589 | return; | |
1590 | } | |
1591 | ||
1592 | gold::gc_process_relocs<64, false, Target_x86_64, elfcpp::SHT_RELA, | |
1593 | Target_x86_64::Scan>( | |
6d03d481 ST |
1594 | symtab, |
1595 | layout, | |
1596 | this, | |
1597 | object, | |
1598 | data_shndx, | |
1599 | prelocs, | |
1600 | reloc_count, | |
1601 | output_section, | |
1602 | needs_special_offset_handling, | |
1603 | local_symbol_count, | |
1604 | plocal_symbols); | |
1605 | ||
1606 | } | |
2e30d253 ILT |
1607 | // Scan relocations for a section. |
1608 | ||
1609 | void | |
ad0f2072 | 1610 | Target_x86_64::scan_relocs(Symbol_table* symtab, |
d61c17ea ILT |
1611 | Layout* layout, |
1612 | Sized_relobj<64, false>* object, | |
1613 | unsigned int data_shndx, | |
1614 | unsigned int sh_type, | |
1615 | const unsigned char* prelocs, | |
1616 | size_t reloc_count, | |
730cdc88 ILT |
1617 | Output_section* output_section, |
1618 | bool needs_special_offset_handling, | |
d61c17ea | 1619 | size_t local_symbol_count, |
730cdc88 | 1620 | const unsigned char* plocal_symbols) |
2e30d253 ILT |
1621 | { |
1622 | if (sh_type == elfcpp::SHT_REL) | |
1623 | { | |
75f2446e ILT |
1624 | gold_error(_("%s: unsupported REL reloc section"), |
1625 | object->name().c_str()); | |
1626 | return; | |
2e30d253 ILT |
1627 | } |
1628 | ||
1629 | gold::scan_relocs<64, false, Target_x86_64, elfcpp::SHT_RELA, | |
1630 | Target_x86_64::Scan>( | |
2e30d253 ILT |
1631 | symtab, |
1632 | layout, | |
1633 | this, | |
1634 | object, | |
1635 | data_shndx, | |
1636 | prelocs, | |
1637 | reloc_count, | |
730cdc88 ILT |
1638 | output_section, |
1639 | needs_special_offset_handling, | |
2e30d253 | 1640 | local_symbol_count, |
730cdc88 | 1641 | plocal_symbols); |
2e30d253 ILT |
1642 | } |
1643 | ||
1644 | // Finalize the sections. | |
1645 | ||
1646 | void | |
f59f41f3 DK |
1647 | Target_x86_64::do_finalize_sections( |
1648 | Layout* layout, | |
1649 | const Input_objects*, | |
1650 | Symbol_table*) | |
2e30d253 ILT |
1651 | { |
1652 | // Fill in some more dynamic tags. | |
1653 | Output_data_dynamic* const odyn = layout->dynamic_data(); | |
1654 | if (odyn != NULL) | |
1655 | { | |
22b127cc ILT |
1656 | if (this->got_plt_ != NULL |
1657 | && this->got_plt_->output_section() != NULL) | |
2e30d253 ILT |
1658 | odyn->add_section_address(elfcpp::DT_PLTGOT, this->got_plt_); |
1659 | ||
22b127cc ILT |
1660 | if (this->plt_ != NULL |
1661 | && this->plt_->output_section() != NULL) | |
2e30d253 ILT |
1662 | { |
1663 | const Output_data* od = this->plt_->rel_plt(); | |
1664 | odyn->add_section_size(elfcpp::DT_PLTRELSZ, od); | |
1665 | odyn->add_section_address(elfcpp::DT_JMPREL, od); | |
1666 | odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA); | |
c2b45e22 CC |
1667 | if (this->plt_->has_tlsdesc_entry()) |
1668 | { | |
1669 | unsigned int plt_offset = this->plt_->get_tlsdesc_plt_offset(); | |
1670 | unsigned int got_offset = this->plt_->get_tlsdesc_got_offset(); | |
1671 | this->got_->finalize_data_size(); | |
1672 | odyn->add_section_plus_offset(elfcpp::DT_TLSDESC_PLT, | |
1673 | this->plt_, plt_offset); | |
1674 | odyn->add_section_plus_offset(elfcpp::DT_TLSDESC_GOT, | |
1675 | this->got_, got_offset); | |
1676 | } | |
2e30d253 ILT |
1677 | } |
1678 | ||
22b127cc ILT |
1679 | if (this->rela_dyn_ != NULL |
1680 | && this->rela_dyn_->output_section() != NULL) | |
2e30d253 | 1681 | { |
0ffd9845 | 1682 | const Output_data* od = this->rela_dyn_; |
2e30d253 | 1683 | odyn->add_section_address(elfcpp::DT_RELA, od); |
e84992bb | 1684 | odyn->add_section_size(elfcpp::DT_RELASZ, od); |
2e30d253 | 1685 | odyn->add_constant(elfcpp::DT_RELAENT, |
e84992bb | 1686 | elfcpp::Elf_sizes<64>::rela_size); |
2e30d253 ILT |
1687 | } |
1688 | ||
8851ecca | 1689 | if (!parameters->options().shared()) |
2e30d253 ILT |
1690 | { |
1691 | // The value of the DT_DEBUG tag is filled in by the dynamic | |
1692 | // linker at run time, and used by the debugger. | |
1693 | odyn->add_constant(elfcpp::DT_DEBUG, 0); | |
1694 | } | |
1695 | } | |
1696 | ||
1697 | // Emit any relocs we saved in an attempt to avoid generating COPY | |
1698 | // relocs. | |
12c0daef ILT |
1699 | if (this->copy_relocs_.any_saved_relocs()) |
1700 | this->copy_relocs_.emit(this->rela_dyn_section(layout)); | |
2e30d253 ILT |
1701 | } |
1702 | ||
1703 | // Perform a relocation. | |
1704 | ||
1705 | inline bool | |
1706 | Target_x86_64::Relocate::relocate(const Relocate_info<64, false>* relinfo, | |
1707 | Target_x86_64* target, | |
031cdbed | 1708 | Output_section*, |
2e30d253 | 1709 | size_t relnum, |
0ffd9845 | 1710 | const elfcpp::Rela<64, false>& rela, |
2e30d253 ILT |
1711 | unsigned int r_type, |
1712 | const Sized_symbol<64>* gsym, | |
1713 | const Symbol_value<64>* psymval, | |
1714 | unsigned char* view, | |
1715 | elfcpp::Elf_types<64>::Elf_Addr address, | |
fe8718a4 | 1716 | section_size_type view_size) |
2e30d253 ILT |
1717 | { |
1718 | if (this->skip_call_tls_get_addr_) | |
1719 | { | |
5efc7cd2 CC |
1720 | if ((r_type != elfcpp::R_X86_64_PLT32 |
1721 | && r_type != elfcpp::R_X86_64_PC32) | |
2e30d253 | 1722 | || gsym == NULL |
0ffd9845 | 1723 | || strcmp(gsym->name(), "__tls_get_addr") != 0) |
2e30d253 | 1724 | { |
75f2446e ILT |
1725 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
1726 | _("missing expected TLS relocation")); | |
1727 | } | |
1728 | else | |
1729 | { | |
1730 | this->skip_call_tls_get_addr_ = false; | |
1731 | return false; | |
2e30d253 | 1732 | } |
2e30d253 ILT |
1733 | } |
1734 | ||
1735 | // Pick the value to use for symbols defined in shared objects. | |
1736 | Symbol_value<64> symval; | |
96f2030e | 1737 | if (gsym != NULL |
de4c45bd ILT |
1738 | && gsym->use_plt_offset(r_type == elfcpp::R_X86_64_PC64 |
1739 | || r_type == elfcpp::R_X86_64_PC32 | |
1740 | || r_type == elfcpp::R_X86_64_PC16 | |
1741 | || r_type == elfcpp::R_X86_64_PC8)) | |
2e30d253 ILT |
1742 | { |
1743 | symval.set_output_value(target->plt_section()->address() | |
1744 | + gsym->plt_offset()); | |
1745 | psymval = &symval; | |
1746 | } | |
1747 | ||
1748 | const Sized_relobj<64, false>* object = relinfo->object; | |
0ffd9845 ILT |
1749 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); |
1750 | ||
1751 | // Get the GOT offset if needed. | |
96f2030e ILT |
1752 | // The GOT pointer points to the end of the GOT section. |
1753 | // We need to subtract the size of the GOT section to get | |
1754 | // the actual offset to use in the relocation. | |
0ffd9845 ILT |
1755 | bool have_got_offset = false; |
1756 | unsigned int got_offset = 0; | |
1757 | switch (r_type) | |
1758 | { | |
1759 | case elfcpp::R_X86_64_GOT32: | |
1760 | case elfcpp::R_X86_64_GOT64: | |
1761 | case elfcpp::R_X86_64_GOTPLT64: | |
1762 | case elfcpp::R_X86_64_GOTPCREL: | |
1763 | case elfcpp::R_X86_64_GOTPCREL64: | |
1764 | if (gsym != NULL) | |
1765 | { | |
0a65a3a7 CC |
1766 | gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD)); |
1767 | got_offset = gsym->got_offset(GOT_TYPE_STANDARD) - target->got_size(); | |
0ffd9845 ILT |
1768 | } |
1769 | else | |
1770 | { | |
1771 | unsigned int r_sym = elfcpp::elf_r_sym<64>(rela.get_r_info()); | |
0a65a3a7 CC |
1772 | gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD)); |
1773 | got_offset = (object->local_got_offset(r_sym, GOT_TYPE_STANDARD) | |
1774 | - target->got_size()); | |
0ffd9845 ILT |
1775 | } |
1776 | have_got_offset = true; | |
1777 | break; | |
1778 | ||
1779 | default: | |
1780 | break; | |
1781 | } | |
2e30d253 ILT |
1782 | |
1783 | switch (r_type) | |
1784 | { | |
1785 | case elfcpp::R_X86_64_NONE: | |
e822f2b1 ILT |
1786 | case elfcpp::R_386_GNU_VTINHERIT: |
1787 | case elfcpp::R_386_GNU_VTENTRY: | |
2e30d253 ILT |
1788 | break; |
1789 | ||
1790 | case elfcpp::R_X86_64_64: | |
1791 | Relocate_functions<64, false>::rela64(view, object, psymval, addend); | |
1792 | break; | |
1793 | ||
1794 | case elfcpp::R_X86_64_PC64: | |
1795 | Relocate_functions<64, false>::pcrela64(view, object, psymval, addend, | |
1796 | address); | |
1797 | break; | |
1798 | ||
1799 | case elfcpp::R_X86_64_32: | |
7bb3655e ILT |
1800 | // FIXME: we need to verify that value + addend fits into 32 bits: |
1801 | // uint64_t x = value + addend; | |
1802 | // x == static_cast<uint64_t>(static_cast<uint32_t>(x)) | |
1803 | // Likewise for other <=32-bit relocations (but see R_X86_64_32S). | |
2e30d253 ILT |
1804 | Relocate_functions<64, false>::rela32(view, object, psymval, addend); |
1805 | break; | |
1806 | ||
1807 | case elfcpp::R_X86_64_32S: | |
7bb3655e ILT |
1808 | // FIXME: we need to verify that value + addend fits into 32 bits: |
1809 | // int64_t x = value + addend; // note this quantity is signed! | |
1810 | // x == static_cast<int64_t>(static_cast<int32_t>(x)) | |
2e30d253 ILT |
1811 | Relocate_functions<64, false>::rela32(view, object, psymval, addend); |
1812 | break; | |
1813 | ||
1814 | case elfcpp::R_X86_64_PC32: | |
1815 | Relocate_functions<64, false>::pcrela32(view, object, psymval, addend, | |
1816 | address); | |
1817 | break; | |
1818 | ||
1819 | case elfcpp::R_X86_64_16: | |
1820 | Relocate_functions<64, false>::rela16(view, object, psymval, addend); | |
1821 | break; | |
1822 | ||
1823 | case elfcpp::R_X86_64_PC16: | |
1824 | Relocate_functions<64, false>::pcrela16(view, object, psymval, addend, | |
1825 | address); | |
1826 | break; | |
1827 | ||
1828 | case elfcpp::R_X86_64_8: | |
1829 | Relocate_functions<64, false>::rela8(view, object, psymval, addend); | |
1830 | break; | |
1831 | ||
1832 | case elfcpp::R_X86_64_PC8: | |
1833 | Relocate_functions<64, false>::pcrela8(view, object, psymval, addend, | |
1834 | address); | |
1835 | break; | |
1836 | ||
1837 | case elfcpp::R_X86_64_PLT32: | |
f389a824 ILT |
1838 | gold_assert(gsym == NULL |
1839 | || gsym->has_plt_offset() | |
99f8faca ILT |
1840 | || gsym->final_value_is_known() |
1841 | || (gsym->is_defined() | |
1842 | && !gsym->is_from_dynobj() | |
1843 | && !gsym->is_preemptible())); | |
ee9e9e86 ILT |
1844 | // Note: while this code looks the same as for R_X86_64_PC32, it |
1845 | // behaves differently because psymval was set to point to | |
1846 | // the PLT entry, rather than the symbol, in Scan::global(). | |
2e30d253 ILT |
1847 | Relocate_functions<64, false>::pcrela32(view, object, psymval, addend, |
1848 | address); | |
1849 | break; | |
1850 | ||
ee9e9e86 ILT |
1851 | case elfcpp::R_X86_64_PLTOFF64: |
1852 | { | |
1853 | gold_assert(gsym); | |
1854 | gold_assert(gsym->has_plt_offset() | |
1855 | || gsym->final_value_is_known()); | |
1856 | elfcpp::Elf_types<64>::Elf_Addr got_address; | |
1857 | got_address = target->got_section(NULL, NULL)->address(); | |
c1866bd5 ILT |
1858 | Relocate_functions<64, false>::rela64(view, object, psymval, |
1859 | addend - got_address); | |
ee9e9e86 ILT |
1860 | } |
1861 | ||
2e30d253 | 1862 | case elfcpp::R_X86_64_GOT32: |
0ffd9845 ILT |
1863 | gold_assert(have_got_offset); |
1864 | Relocate_functions<64, false>::rela32(view, got_offset, addend); | |
2e30d253 ILT |
1865 | break; |
1866 | ||
e822f2b1 ILT |
1867 | case elfcpp::R_X86_64_GOTPC32: |
1868 | { | |
1869 | gold_assert(gsym); | |
1870 | elfcpp::Elf_types<64>::Elf_Addr value; | |
96f2030e | 1871 | value = target->got_plt_section()->address(); |
e822f2b1 ILT |
1872 | Relocate_functions<64, false>::pcrela32(view, value, addend, address); |
1873 | } | |
1874 | break; | |
1875 | ||
1876 | case elfcpp::R_X86_64_GOT64: | |
1877 | // The ABI doc says "Like GOT64, but indicates a PLT entry is needed." | |
1878 | // Since we always add a PLT entry, this is equivalent. | |
fdc2f80f | 1879 | case elfcpp::R_X86_64_GOTPLT64: |
0ffd9845 ILT |
1880 | gold_assert(have_got_offset); |
1881 | Relocate_functions<64, false>::rela64(view, got_offset, addend); | |
e822f2b1 ILT |
1882 | break; |
1883 | ||
1884 | case elfcpp::R_X86_64_GOTPC64: | |
1885 | { | |
1886 | gold_assert(gsym); | |
1887 | elfcpp::Elf_types<64>::Elf_Addr value; | |
96f2030e | 1888 | value = target->got_plt_section()->address(); |
e822f2b1 ILT |
1889 | Relocate_functions<64, false>::pcrela64(view, value, addend, address); |
1890 | } | |
1891 | break; | |
1892 | ||
2e30d253 ILT |
1893 | case elfcpp::R_X86_64_GOTOFF64: |
1894 | { | |
1895 | elfcpp::Elf_types<64>::Elf_Addr value; | |
1896 | value = (psymval->value(object, 0) | |
96f2030e | 1897 | - target->got_plt_section()->address()); |
2e30d253 ILT |
1898 | Relocate_functions<64, false>::rela64(view, value, addend); |
1899 | } | |
1900 | break; | |
1901 | ||
1902 | case elfcpp::R_X86_64_GOTPCREL: | |
1903 | { | |
0ffd9845 ILT |
1904 | gold_assert(have_got_offset); |
1905 | elfcpp::Elf_types<64>::Elf_Addr value; | |
96f2030e | 1906 | value = target->got_plt_section()->address() + got_offset; |
0ffd9845 | 1907 | Relocate_functions<64, false>::pcrela32(view, value, addend, address); |
2e30d253 ILT |
1908 | } |
1909 | break; | |
1910 | ||
e822f2b1 ILT |
1911 | case elfcpp::R_X86_64_GOTPCREL64: |
1912 | { | |
0ffd9845 ILT |
1913 | gold_assert(have_got_offset); |
1914 | elfcpp::Elf_types<64>::Elf_Addr value; | |
96f2030e | 1915 | value = target->got_plt_section()->address() + got_offset; |
0ffd9845 | 1916 | Relocate_functions<64, false>::pcrela64(view, value, addend, address); |
e822f2b1 ILT |
1917 | } |
1918 | break; | |
1919 | ||
2e30d253 ILT |
1920 | case elfcpp::R_X86_64_COPY: |
1921 | case elfcpp::R_X86_64_GLOB_DAT: | |
1922 | case elfcpp::R_X86_64_JUMP_SLOT: | |
1923 | case elfcpp::R_X86_64_RELATIVE: | |
d61c17ea | 1924 | // These are outstanding tls relocs, which are unexpected when linking |
2e30d253 | 1925 | case elfcpp::R_X86_64_TPOFF64: |
2e30d253 | 1926 | case elfcpp::R_X86_64_DTPMOD64: |
2e30d253 | 1927 | case elfcpp::R_X86_64_TLSDESC: |
75f2446e ILT |
1928 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
1929 | _("unexpected reloc %u in object file"), | |
1930 | r_type); | |
2e30d253 ILT |
1931 | break; |
1932 | ||
d61c17ea | 1933 | // These are initial tls relocs, which are expected when linking |
56622147 ILT |
1934 | case elfcpp::R_X86_64_TLSGD: // Global-dynamic |
1935 | case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url) | |
e041f13d | 1936 | case elfcpp::R_X86_64_TLSDESC_CALL: |
56622147 | 1937 | case elfcpp::R_X86_64_TLSLD: // Local-dynamic |
0ffd9845 ILT |
1938 | case elfcpp::R_X86_64_DTPOFF32: |
1939 | case elfcpp::R_X86_64_DTPOFF64: | |
56622147 ILT |
1940 | case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec |
1941 | case elfcpp::R_X86_64_TPOFF32: // Local-exec | |
7bf1f802 ILT |
1942 | this->relocate_tls(relinfo, target, relnum, rela, r_type, gsym, psymval, |
1943 | view, address, view_size); | |
2e30d253 | 1944 | break; |
2e30d253 | 1945 | |
fdc2f80f ILT |
1946 | case elfcpp::R_X86_64_SIZE32: |
1947 | case elfcpp::R_X86_64_SIZE64: | |
2e30d253 | 1948 | default: |
75f2446e ILT |
1949 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
1950 | _("unsupported reloc %u"), | |
1951 | r_type); | |
2e30d253 ILT |
1952 | break; |
1953 | } | |
1954 | ||
1955 | return true; | |
1956 | } | |
1957 | ||
1958 | // Perform a TLS relocation. | |
1959 | ||
1960 | inline void | |
d61c17ea | 1961 | Target_x86_64::Relocate::relocate_tls(const Relocate_info<64, false>* relinfo, |
7bf1f802 | 1962 | Target_x86_64* target, |
d61c17ea | 1963 | size_t relnum, |
72ec2876 | 1964 | const elfcpp::Rela<64, false>& rela, |
d61c17ea ILT |
1965 | unsigned int r_type, |
1966 | const Sized_symbol<64>* gsym, | |
1967 | const Symbol_value<64>* psymval, | |
1968 | unsigned char* view, | |
6a41d30b | 1969 | elfcpp::Elf_types<64>::Elf_Addr address, |
fe8718a4 | 1970 | section_size_type view_size) |
2e30d253 | 1971 | { |
2e30d253 | 1972 | Output_segment* tls_segment = relinfo->layout->tls_segment(); |
7bf1f802 ILT |
1973 | |
1974 | const Sized_relobj<64, false>* object = relinfo->object; | |
6a41d30b | 1975 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); |
2e30d253 ILT |
1976 | |
1977 | elfcpp::Elf_types<64>::Elf_Addr value = psymval->value(relinfo->object, 0); | |
1978 | ||
1979 | const bool is_final = (gsym == NULL | |
8851ecca | 1980 | ? !parameters->options().output_is_position_independent() |
2e30d253 | 1981 | : gsym->final_value_is_known()); |
e041f13d ILT |
1982 | const tls::Tls_optimization optimized_type |
1983 | = Target_x86_64::optimize_tls_reloc(is_final, r_type); | |
2e30d253 ILT |
1984 | switch (r_type) |
1985 | { | |
56622147 | 1986 | case elfcpp::R_X86_64_TLSGD: // Global-dynamic |
497897f9 | 1987 | this->saw_tls_block_reloc_ = true; |
e041f13d | 1988 | if (optimized_type == tls::TLSOPT_TO_LE) |
2e30d253 | 1989 | { |
7bf1f802 | 1990 | gold_assert(tls_segment != NULL); |
2e30d253 | 1991 | this->tls_gd_to_le(relinfo, relnum, tls_segment, |
72ec2876 | 1992 | rela, r_type, value, view, |
2e30d253 ILT |
1993 | view_size); |
1994 | break; | |
1995 | } | |
7bf1f802 ILT |
1996 | else |
1997 | { | |
c2b45e22 CC |
1998 | unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE |
1999 | ? GOT_TYPE_TLS_OFFSET | |
2000 | : GOT_TYPE_TLS_PAIR); | |
7bf1f802 ILT |
2001 | unsigned int got_offset; |
2002 | if (gsym != NULL) | |
2003 | { | |
c2b45e22 CC |
2004 | gold_assert(gsym->has_got_offset(got_type)); |
2005 | got_offset = gsym->got_offset(got_type) - target->got_size(); | |
7bf1f802 ILT |
2006 | } |
2007 | else | |
2008 | { | |
2009 | unsigned int r_sym = elfcpp::elf_r_sym<64>(rela.get_r_info()); | |
c2b45e22 CC |
2010 | gold_assert(object->local_has_got_offset(r_sym, got_type)); |
2011 | got_offset = (object->local_got_offset(r_sym, got_type) | |
7bf1f802 ILT |
2012 | - target->got_size()); |
2013 | } | |
2014 | if (optimized_type == tls::TLSOPT_TO_IE) | |
2015 | { | |
2016 | gold_assert(tls_segment != NULL); | |
c2b45e22 | 2017 | value = target->got_plt_section()->address() + got_offset; |
7bf1f802 | 2018 | this->tls_gd_to_ie(relinfo, relnum, tls_segment, rela, r_type, |
c2b45e22 | 2019 | value, view, address, view_size); |
7bf1f802 ILT |
2020 | break; |
2021 | } | |
2022 | else if (optimized_type == tls::TLSOPT_NONE) | |
2023 | { | |
2024 | // Relocate the field with the offset of the pair of GOT | |
2025 | // entries. | |
6a41d30b ILT |
2026 | value = target->got_plt_section()->address() + got_offset; |
2027 | Relocate_functions<64, false>::pcrela32(view, value, addend, | |
2028 | address); | |
7bf1f802 ILT |
2029 | break; |
2030 | } | |
2031 | } | |
72ec2876 | 2032 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
75f2446e | 2033 | _("unsupported reloc %u"), r_type); |
2e30d253 ILT |
2034 | break; |
2035 | ||
c2b45e22 CC |
2036 | case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url) |
2037 | case elfcpp::R_X86_64_TLSDESC_CALL: | |
497897f9 | 2038 | this->saw_tls_block_reloc_ = true; |
c2b45e22 CC |
2039 | if (optimized_type == tls::TLSOPT_TO_LE) |
2040 | { | |
2041 | gold_assert(tls_segment != NULL); | |
2042 | this->tls_desc_gd_to_le(relinfo, relnum, tls_segment, | |
2043 | rela, r_type, value, view, | |
2044 | view_size); | |
2045 | break; | |
2046 | } | |
2047 | else | |
2048 | { | |
2049 | unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE | |
2050 | ? GOT_TYPE_TLS_OFFSET | |
2051 | : GOT_TYPE_TLS_DESC); | |
2052 | unsigned int got_offset; | |
2053 | if (gsym != NULL) | |
2054 | { | |
2055 | gold_assert(gsym->has_got_offset(got_type)); | |
2056 | got_offset = gsym->got_offset(got_type) - target->got_size(); | |
2057 | } | |
2058 | else | |
2059 | { | |
2060 | unsigned int r_sym = elfcpp::elf_r_sym<64>(rela.get_r_info()); | |
2061 | gold_assert(object->local_has_got_offset(r_sym, got_type)); | |
2062 | got_offset = (object->local_got_offset(r_sym, got_type) | |
2063 | - target->got_size()); | |
2064 | } | |
2065 | if (optimized_type == tls::TLSOPT_TO_IE) | |
2066 | { | |
2067 | gold_assert(tls_segment != NULL); | |
2068 | value = target->got_plt_section()->address() + got_offset; | |
2069 | this->tls_desc_gd_to_ie(relinfo, relnum, tls_segment, | |
2070 | rela, r_type, value, view, address, | |
2071 | view_size); | |
2072 | break; | |
2073 | } | |
2074 | else if (optimized_type == tls::TLSOPT_NONE) | |
2075 | { | |
2076 | if (r_type == elfcpp::R_X86_64_GOTPC32_TLSDESC) | |
2077 | { | |
2078 | // Relocate the field with the offset of the pair of GOT | |
2079 | // entries. | |
2080 | value = target->got_plt_section()->address() + got_offset; | |
2081 | Relocate_functions<64, false>::pcrela32(view, value, addend, | |
2082 | address); | |
2083 | } | |
2084 | break; | |
2085 | } | |
2086 | } | |
2087 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
2088 | _("unsupported reloc %u"), r_type); | |
2089 | break; | |
2090 | ||
56622147 | 2091 | case elfcpp::R_X86_64_TLSLD: // Local-dynamic |
497897f9 | 2092 | this->saw_tls_block_reloc_ = true; |
e041f13d ILT |
2093 | if (optimized_type == tls::TLSOPT_TO_LE) |
2094 | { | |
7bf1f802 | 2095 | gold_assert(tls_segment != NULL); |
72ec2876 ILT |
2096 | this->tls_ld_to_le(relinfo, relnum, tls_segment, rela, r_type, |
2097 | value, view, view_size); | |
2098 | break; | |
e041f13d | 2099 | } |
7bf1f802 ILT |
2100 | else if (optimized_type == tls::TLSOPT_NONE) |
2101 | { | |
2102 | // Relocate the field with the offset of the GOT entry for | |
2103 | // the module index. | |
2104 | unsigned int got_offset; | |
31d60480 ILT |
2105 | got_offset = (target->got_mod_index_entry(NULL, NULL, NULL) |
2106 | - target->got_size()); | |
6a41d30b ILT |
2107 | value = target->got_plt_section()->address() + got_offset; |
2108 | Relocate_functions<64, false>::pcrela32(view, value, addend, | |
2109 | address); | |
7bf1f802 ILT |
2110 | break; |
2111 | } | |
72ec2876 | 2112 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
75f2446e | 2113 | _("unsupported reloc %u"), r_type); |
2e30d253 | 2114 | break; |
0ffd9845 ILT |
2115 | |
2116 | case elfcpp::R_X86_64_DTPOFF32: | |
e041f13d | 2117 | if (optimized_type == tls::TLSOPT_TO_LE) |
497897f9 ILT |
2118 | { |
2119 | // This relocation type is used in debugging information. | |
2120 | // In that case we need to not optimize the value. If we | |
2121 | // haven't seen a TLSLD reloc, then we assume we should not | |
2122 | // optimize this reloc. | |
2123 | if (this->saw_tls_block_reloc_) | |
27721062 ST |
2124 | { |
2125 | gold_assert(tls_segment != NULL); | |
2126 | value -= tls_segment->memsz(); | |
2127 | } | |
497897f9 | 2128 | } |
d85c80a3 | 2129 | Relocate_functions<64, false>::rela32(view, value, addend); |
0ffd9845 ILT |
2130 | break; |
2131 | ||
2132 | case elfcpp::R_X86_64_DTPOFF64: | |
e041f13d | 2133 | if (optimized_type == tls::TLSOPT_TO_LE) |
497897f9 ILT |
2134 | { |
2135 | // See R_X86_64_DTPOFF32, just above, for why we test this. | |
2136 | if (this->saw_tls_block_reloc_) | |
27721062 ST |
2137 | { |
2138 | gold_assert(tls_segment != NULL); | |
2139 | value -= tls_segment->memsz(); | |
2140 | } | |
497897f9 | 2141 | } |
d85c80a3 | 2142 | Relocate_functions<64, false>::rela64(view, value, addend); |
0ffd9845 | 2143 | break; |
2e30d253 | 2144 | |
56622147 ILT |
2145 | case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec |
2146 | if (optimized_type == tls::TLSOPT_TO_LE) | |
2147 | { | |
7bf1f802 | 2148 | gold_assert(tls_segment != NULL); |
56622147 ILT |
2149 | Target_x86_64::Relocate::tls_ie_to_le(relinfo, relnum, tls_segment, |
2150 | rela, r_type, value, view, | |
2151 | view_size); | |
2152 | break; | |
2153 | } | |
7bf1f802 ILT |
2154 | else if (optimized_type == tls::TLSOPT_NONE) |
2155 | { | |
2156 | // Relocate the field with the offset of the GOT entry for | |
2157 | // the tp-relative offset of the symbol. | |
2158 | unsigned int got_offset; | |
2159 | if (gsym != NULL) | |
2160 | { | |
0a65a3a7 CC |
2161 | gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET)); |
2162 | got_offset = (gsym->got_offset(GOT_TYPE_TLS_OFFSET) | |
2163 | - target->got_size()); | |
7bf1f802 ILT |
2164 | } |
2165 | else | |
2166 | { | |
2167 | unsigned int r_sym = elfcpp::elf_r_sym<64>(rela.get_r_info()); | |
0a65a3a7 CC |
2168 | gold_assert(object->local_has_got_offset(r_sym, |
2169 | GOT_TYPE_TLS_OFFSET)); | |
2170 | got_offset = (object->local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET) | |
7bf1f802 ILT |
2171 | - target->got_size()); |
2172 | } | |
6a41d30b ILT |
2173 | value = target->got_plt_section()->address() + got_offset; |
2174 | Relocate_functions<64, false>::pcrela32(view, value, addend, address); | |
7bf1f802 ILT |
2175 | break; |
2176 | } | |
56622147 ILT |
2177 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
2178 | _("unsupported reloc type %u"), | |
2179 | r_type); | |
2180 | break; | |
0ffd9845 | 2181 | |
56622147 | 2182 | case elfcpp::R_X86_64_TPOFF32: // Local-exec |
6a41d30b | 2183 | value -= tls_segment->memsz(); |
d85c80a3 | 2184 | Relocate_functions<64, false>::rela32(view, value, addend); |
56622147 | 2185 | break; |
2e30d253 | 2186 | } |
2e30d253 ILT |
2187 | } |
2188 | ||
7bf1f802 ILT |
2189 | // Do a relocation in which we convert a TLS General-Dynamic to an |
2190 | // Initial-Exec. | |
2191 | ||
2192 | inline void | |
2193 | Target_x86_64::Relocate::tls_gd_to_ie(const Relocate_info<64, false>* relinfo, | |
2194 | size_t relnum, | |
c2b45e22 | 2195 | Output_segment*, |
7bf1f802 ILT |
2196 | const elfcpp::Rela<64, false>& rela, |
2197 | unsigned int, | |
2198 | elfcpp::Elf_types<64>::Elf_Addr value, | |
2199 | unsigned char* view, | |
c2b45e22 | 2200 | elfcpp::Elf_types<64>::Elf_Addr address, |
fe8718a4 | 2201 | section_size_type view_size) |
7bf1f802 ILT |
2202 | { |
2203 | // .byte 0x66; leaq foo@tlsgd(%rip),%rdi; | |
2204 | // .word 0x6666; rex64; call __tls_get_addr | |
2205 | // ==> movq %fs:0,%rax; addq x@gottpoff(%rip),%rax | |
2206 | ||
2207 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -4); | |
2208 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 12); | |
2209 | ||
2210 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), | |
2211 | (memcmp(view - 4, "\x66\x48\x8d\x3d", 4) == 0)); | |
2212 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), | |
2213 | (memcmp(view + 4, "\x66\x66\x48\xe8", 4) == 0)); | |
2214 | ||
2215 | memcpy(view - 4, "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0\0", 16); | |
2216 | ||
c2b45e22 CC |
2217 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); |
2218 | Relocate_functions<64, false>::pcrela32(view + 8, value, addend - 8, address); | |
7bf1f802 ILT |
2219 | |
2220 | // The next reloc should be a PLT32 reloc against __tls_get_addr. | |
2221 | // We can skip it. | |
2222 | this->skip_call_tls_get_addr_ = true; | |
2223 | } | |
2224 | ||
e041f13d | 2225 | // Do a relocation in which we convert a TLS General-Dynamic to a |
2e30d253 ILT |
2226 | // Local-Exec. |
2227 | ||
2228 | inline void | |
d61c17ea ILT |
2229 | Target_x86_64::Relocate::tls_gd_to_le(const Relocate_info<64, false>* relinfo, |
2230 | size_t relnum, | |
2231 | Output_segment* tls_segment, | |
72ec2876 | 2232 | const elfcpp::Rela<64, false>& rela, |
d61c17ea ILT |
2233 | unsigned int, |
2234 | elfcpp::Elf_types<64>::Elf_Addr value, | |
2235 | unsigned char* view, | |
fe8718a4 | 2236 | section_size_type view_size) |
2e30d253 | 2237 | { |
0ffd9845 ILT |
2238 | // .byte 0x66; leaq foo@tlsgd(%rip),%rdi; |
2239 | // .word 0x6666; rex64; call __tls_get_addr | |
2240 | // ==> movq %fs:0,%rax; leaq x@tpoff(%rax),%rax | |
2e30d253 | 2241 | |
72ec2876 ILT |
2242 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -4); |
2243 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 12); | |
2e30d253 | 2244 | |
72ec2876 ILT |
2245 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), |
2246 | (memcmp(view - 4, "\x66\x48\x8d\x3d", 4) == 0)); | |
2247 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), | |
2248 | (memcmp(view + 4, "\x66\x66\x48\xe8", 4) == 0)); | |
2e30d253 | 2249 | |
0ffd9845 | 2250 | memcpy(view - 4, "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0\0", 16); |
2e30d253 | 2251 | |
6a41d30b | 2252 | value -= tls_segment->memsz(); |
0ffd9845 | 2253 | Relocate_functions<64, false>::rela32(view + 8, value, 0); |
2e30d253 ILT |
2254 | |
2255 | // The next reloc should be a PLT32 reloc against __tls_get_addr. | |
2256 | // We can skip it. | |
2257 | this->skip_call_tls_get_addr_ = true; | |
2e30d253 ILT |
2258 | } |
2259 | ||
c2b45e22 CC |
2260 | // Do a TLSDESC-style General-Dynamic to Initial-Exec transition. |
2261 | ||
2262 | inline void | |
2263 | Target_x86_64::Relocate::tls_desc_gd_to_ie( | |
2264 | const Relocate_info<64, false>* relinfo, | |
2265 | size_t relnum, | |
2266 | Output_segment*, | |
2267 | const elfcpp::Rela<64, false>& rela, | |
2268 | unsigned int r_type, | |
2269 | elfcpp::Elf_types<64>::Elf_Addr value, | |
2270 | unsigned char* view, | |
2271 | elfcpp::Elf_types<64>::Elf_Addr address, | |
2272 | section_size_type view_size) | |
2273 | { | |
2274 | if (r_type == elfcpp::R_X86_64_GOTPC32_TLSDESC) | |
2275 | { | |
2276 | // leaq foo@tlsdesc(%rip), %rax | |
2277 | // ==> movq foo@gottpoff(%rip), %rax | |
2278 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3); | |
2279 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4); | |
2280 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), | |
2281 | view[-3] == 0x48 && view[-2] == 0x8d && view[-1] == 0x05); | |
2282 | view[-2] = 0x8b; | |
2283 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); | |
2284 | Relocate_functions<64, false>::pcrela32(view, value, addend, address); | |
2285 | } | |
2286 | else | |
2287 | { | |
2288 | // call *foo@tlscall(%rax) | |
2289 | // ==> nop; nop | |
2290 | gold_assert(r_type == elfcpp::R_X86_64_TLSDESC_CALL); | |
2291 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 2); | |
2292 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), | |
2293 | view[0] == 0xff && view[1] == 0x10); | |
2294 | view[0] = 0x66; | |
2295 | view[1] = 0x90; | |
2296 | } | |
2297 | } | |
2298 | ||
2299 | // Do a TLSDESC-style General-Dynamic to Local-Exec transition. | |
2300 | ||
2301 | inline void | |
2302 | Target_x86_64::Relocate::tls_desc_gd_to_le( | |
2303 | const Relocate_info<64, false>* relinfo, | |
2304 | size_t relnum, | |
2305 | Output_segment* tls_segment, | |
2306 | const elfcpp::Rela<64, false>& rela, | |
2307 | unsigned int r_type, | |
2308 | elfcpp::Elf_types<64>::Elf_Addr value, | |
2309 | unsigned char* view, | |
2310 | section_size_type view_size) | |
2311 | { | |
2312 | if (r_type == elfcpp::R_X86_64_GOTPC32_TLSDESC) | |
2313 | { | |
2314 | // leaq foo@tlsdesc(%rip), %rax | |
2315 | // ==> movq foo@tpoff, %rax | |
2316 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3); | |
2317 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4); | |
2318 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), | |
2319 | view[-3] == 0x48 && view[-2] == 0x8d && view[-1] == 0x05); | |
2320 | view[-2] = 0xc7; | |
2321 | view[-1] = 0xc0; | |
2322 | value -= tls_segment->memsz(); | |
2323 | Relocate_functions<64, false>::rela32(view, value, 0); | |
2324 | } | |
2325 | else | |
2326 | { | |
2327 | // call *foo@tlscall(%rax) | |
2328 | // ==> nop; nop | |
2329 | gold_assert(r_type == elfcpp::R_X86_64_TLSDESC_CALL); | |
2330 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 2); | |
2331 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), | |
2332 | view[0] == 0xff && view[1] == 0x10); | |
2333 | view[0] = 0x66; | |
2334 | view[1] = 0x90; | |
2335 | } | |
2336 | } | |
2337 | ||
2e30d253 | 2338 | inline void |
72ec2876 ILT |
2339 | Target_x86_64::Relocate::tls_ld_to_le(const Relocate_info<64, false>* relinfo, |
2340 | size_t relnum, | |
2341 | Output_segment*, | |
2342 | const elfcpp::Rela<64, false>& rela, | |
2343 | unsigned int, | |
2344 | elfcpp::Elf_types<64>::Elf_Addr, | |
2345 | unsigned char* view, | |
fe8718a4 | 2346 | section_size_type view_size) |
2e30d253 | 2347 | { |
72ec2876 ILT |
2348 | // leaq foo@tlsld(%rip),%rdi; call __tls_get_addr@plt; |
2349 | // ... leq foo@dtpoff(%rax),%reg | |
2350 | // ==> .word 0x6666; .byte 0x66; movq %fs:0,%rax ... leaq x@tpoff(%rax),%rdx | |
2e30d253 | 2351 | |
72ec2876 ILT |
2352 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3); |
2353 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 9); | |
2e30d253 | 2354 | |
72ec2876 ILT |
2355 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), |
2356 | view[-3] == 0x48 && view[-2] == 0x8d && view[-1] == 0x3d); | |
2357 | ||
2358 | tls::check_tls(relinfo, relnum, rela.get_r_offset(), view[4] == 0xe8); | |
2359 | ||
2360 | memcpy(view - 3, "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0\0", 12); | |
2361 | ||
2362 | // The next reloc should be a PLT32 reloc against __tls_get_addr. | |
2363 | // We can skip it. | |
2364 | this->skip_call_tls_get_addr_ = true; | |
2e30d253 ILT |
2365 | } |
2366 | ||
56622147 ILT |
2367 | // Do a relocation in which we convert a TLS Initial-Exec to a |
2368 | // Local-Exec. | |
2369 | ||
2370 | inline void | |
2371 | Target_x86_64::Relocate::tls_ie_to_le(const Relocate_info<64, false>* relinfo, | |
2372 | size_t relnum, | |
2373 | Output_segment* tls_segment, | |
2374 | const elfcpp::Rela<64, false>& rela, | |
2375 | unsigned int, | |
2376 | elfcpp::Elf_types<64>::Elf_Addr value, | |
2377 | unsigned char* view, | |
fe8718a4 | 2378 | section_size_type view_size) |
56622147 ILT |
2379 | { |
2380 | // We need to examine the opcodes to figure out which instruction we | |
2381 | // are looking at. | |
2382 | ||
2383 | // movq foo@gottpoff(%rip),%reg ==> movq $YY,%reg | |
2384 | // addq foo@gottpoff(%rip),%reg ==> addq $YY,%reg | |
2385 | ||
2386 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3); | |
2387 | tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4); | |
2388 | ||
2389 | unsigned char op1 = view[-3]; | |
2390 | unsigned char op2 = view[-2]; | |
2391 | unsigned char op3 = view[-1]; | |
2392 | unsigned char reg = op3 >> 3; | |
2393 | ||
2394 | if (op2 == 0x8b) | |
2395 | { | |
2396 | // movq | |
2397 | if (op1 == 0x4c) | |
2398 | view[-3] = 0x49; | |
2399 | view[-2] = 0xc7; | |
2400 | view[-1] = 0xc0 | reg; | |
2401 | } | |
2402 | else if (reg == 4) | |
2403 | { | |
2404 | // Special handling for %rsp. | |
2405 | if (op1 == 0x4c) | |
2406 | view[-3] = 0x49; | |
2407 | view[-2] = 0x81; | |
2408 | view[-1] = 0xc0 | reg; | |
2409 | } | |
2410 | else | |
2411 | { | |
2412 | // addq | |
2413 | if (op1 == 0x4c) | |
2414 | view[-3] = 0x4d; | |
2415 | view[-2] = 0x8d; | |
2416 | view[-1] = 0x80 | reg | (reg << 3); | |
2417 | } | |
2418 | ||
6a41d30b | 2419 | value -= tls_segment->memsz(); |
56622147 ILT |
2420 | Relocate_functions<64, false>::rela32(view, value, 0); |
2421 | } | |
2422 | ||
2e30d253 ILT |
2423 | // Relocate section data. |
2424 | ||
2425 | void | |
364c7fa5 ILT |
2426 | Target_x86_64::relocate_section( |
2427 | const Relocate_info<64, false>* relinfo, | |
2428 | unsigned int sh_type, | |
2429 | const unsigned char* prelocs, | |
2430 | size_t reloc_count, | |
2431 | Output_section* output_section, | |
2432 | bool needs_special_offset_handling, | |
2433 | unsigned char* view, | |
2434 | elfcpp::Elf_types<64>::Elf_Addr address, | |
2435 | section_size_type view_size, | |
2436 | const Reloc_symbol_changes* reloc_symbol_changes) | |
2e30d253 ILT |
2437 | { |
2438 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
2439 | ||
2440 | gold::relocate_section<64, false, Target_x86_64, elfcpp::SHT_RELA, | |
2441 | Target_x86_64::Relocate>( | |
2442 | relinfo, | |
2443 | this, | |
2444 | prelocs, | |
2445 | reloc_count, | |
730cdc88 ILT |
2446 | output_section, |
2447 | needs_special_offset_handling, | |
2e30d253 ILT |
2448 | view, |
2449 | address, | |
364c7fa5 ILT |
2450 | view_size, |
2451 | reloc_symbol_changes); | |
2e30d253 ILT |
2452 | } |
2453 | ||
6a74a719 ILT |
2454 | // Return the size of a relocation while scanning during a relocatable |
2455 | // link. | |
2456 | ||
2457 | unsigned int | |
2458 | Target_x86_64::Relocatable_size_for_reloc::get_size_for_reloc( | |
2459 | unsigned int r_type, | |
2460 | Relobj* object) | |
2461 | { | |
2462 | switch (r_type) | |
2463 | { | |
2464 | case elfcpp::R_X86_64_NONE: | |
2465 | case elfcpp::R_386_GNU_VTINHERIT: | |
2466 | case elfcpp::R_386_GNU_VTENTRY: | |
2467 | case elfcpp::R_X86_64_TLSGD: // Global-dynamic | |
2468 | case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url) | |
2469 | case elfcpp::R_X86_64_TLSDESC_CALL: | |
2470 | case elfcpp::R_X86_64_TLSLD: // Local-dynamic | |
2471 | case elfcpp::R_X86_64_DTPOFF32: | |
2472 | case elfcpp::R_X86_64_DTPOFF64: | |
2473 | case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec | |
2474 | case elfcpp::R_X86_64_TPOFF32: // Local-exec | |
2475 | return 0; | |
2476 | ||
2477 | case elfcpp::R_X86_64_64: | |
2478 | case elfcpp::R_X86_64_PC64: | |
2479 | case elfcpp::R_X86_64_GOTOFF64: | |
2480 | case elfcpp::R_X86_64_GOTPC64: | |
2481 | case elfcpp::R_X86_64_PLTOFF64: | |
2482 | case elfcpp::R_X86_64_GOT64: | |
2483 | case elfcpp::R_X86_64_GOTPCREL64: | |
2484 | case elfcpp::R_X86_64_GOTPCREL: | |
2485 | case elfcpp::R_X86_64_GOTPLT64: | |
2486 | return 8; | |
2487 | ||
2488 | case elfcpp::R_X86_64_32: | |
2489 | case elfcpp::R_X86_64_32S: | |
2490 | case elfcpp::R_X86_64_PC32: | |
2491 | case elfcpp::R_X86_64_PLT32: | |
2492 | case elfcpp::R_X86_64_GOTPC32: | |
2493 | case elfcpp::R_X86_64_GOT32: | |
2494 | return 4; | |
2495 | ||
2496 | case elfcpp::R_X86_64_16: | |
2497 | case elfcpp::R_X86_64_PC16: | |
2498 | return 2; | |
2499 | ||
2500 | case elfcpp::R_X86_64_8: | |
2501 | case elfcpp::R_X86_64_PC8: | |
2502 | return 1; | |
2503 | ||
2504 | case elfcpp::R_X86_64_COPY: | |
2505 | case elfcpp::R_X86_64_GLOB_DAT: | |
2506 | case elfcpp::R_X86_64_JUMP_SLOT: | |
2507 | case elfcpp::R_X86_64_RELATIVE: | |
2508 | // These are outstanding tls relocs, which are unexpected when linking | |
2509 | case elfcpp::R_X86_64_TPOFF64: | |
2510 | case elfcpp::R_X86_64_DTPMOD64: | |
2511 | case elfcpp::R_X86_64_TLSDESC: | |
2512 | object->error(_("unexpected reloc %u in object file"), r_type); | |
2513 | return 0; | |
2514 | ||
2515 | case elfcpp::R_X86_64_SIZE32: | |
2516 | case elfcpp::R_X86_64_SIZE64: | |
2517 | default: | |
2518 | object->error(_("unsupported reloc %u against local symbol"), r_type); | |
2519 | return 0; | |
2520 | } | |
2521 | } | |
2522 | ||
2523 | // Scan the relocs during a relocatable link. | |
2524 | ||
2525 | void | |
ad0f2072 | 2526 | Target_x86_64::scan_relocatable_relocs(Symbol_table* symtab, |
6a74a719 ILT |
2527 | Layout* layout, |
2528 | Sized_relobj<64, false>* object, | |
2529 | unsigned int data_shndx, | |
2530 | unsigned int sh_type, | |
2531 | const unsigned char* prelocs, | |
2532 | size_t reloc_count, | |
2533 | Output_section* output_section, | |
2534 | bool needs_special_offset_handling, | |
2535 | size_t local_symbol_count, | |
2536 | const unsigned char* plocal_symbols, | |
2537 | Relocatable_relocs* rr) | |
2538 | { | |
2539 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
2540 | ||
2541 | typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA, | |
2542 | Relocatable_size_for_reloc> Scan_relocatable_relocs; | |
2543 | ||
7019cd25 | 2544 | gold::scan_relocatable_relocs<64, false, elfcpp::SHT_RELA, |
6a74a719 | 2545 | Scan_relocatable_relocs>( |
6a74a719 ILT |
2546 | symtab, |
2547 | layout, | |
2548 | object, | |
2549 | data_shndx, | |
2550 | prelocs, | |
2551 | reloc_count, | |
2552 | output_section, | |
2553 | needs_special_offset_handling, | |
2554 | local_symbol_count, | |
2555 | plocal_symbols, | |
2556 | rr); | |
2557 | } | |
2558 | ||
2559 | // Relocate a section during a relocatable link. | |
2560 | ||
2561 | void | |
2562 | Target_x86_64::relocate_for_relocatable( | |
2563 | const Relocate_info<64, false>* relinfo, | |
2564 | unsigned int sh_type, | |
2565 | const unsigned char* prelocs, | |
2566 | size_t reloc_count, | |
2567 | Output_section* output_section, | |
2568 | off_t offset_in_output_section, | |
2569 | const Relocatable_relocs* rr, | |
2570 | unsigned char* view, | |
2571 | elfcpp::Elf_types<64>::Elf_Addr view_address, | |
2572 | section_size_type view_size, | |
2573 | unsigned char* reloc_view, | |
2574 | section_size_type reloc_view_size) | |
2575 | { | |
2576 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
2577 | ||
7019cd25 | 2578 | gold::relocate_for_relocatable<64, false, elfcpp::SHT_RELA>( |
6a74a719 ILT |
2579 | relinfo, |
2580 | prelocs, | |
2581 | reloc_count, | |
2582 | output_section, | |
2583 | offset_in_output_section, | |
2584 | rr, | |
2585 | view, | |
2586 | view_address, | |
2587 | view_size, | |
2588 | reloc_view, | |
2589 | reloc_view_size); | |
2590 | } | |
2591 | ||
4fb6c25d ILT |
2592 | // Return the value to use for a dynamic which requires special |
2593 | // treatment. This is how we support equality comparisons of function | |
2594 | // pointers across shared library boundaries, as described in the | |
2595 | // processor specific ABI supplement. | |
2596 | ||
2597 | uint64_t | |
2598 | Target_x86_64::do_dynsym_value(const Symbol* gsym) const | |
2599 | { | |
2600 | gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset()); | |
2601 | return this->plt_section()->address() + gsym->plt_offset(); | |
2602 | } | |
2603 | ||
2e30d253 ILT |
2604 | // Return a string used to fill a code section with nops to take up |
2605 | // the specified length. | |
2606 | ||
2607 | std::string | |
8851ecca | 2608 | Target_x86_64::do_code_fill(section_size_type length) const |
2e30d253 ILT |
2609 | { |
2610 | if (length >= 16) | |
2611 | { | |
2612 | // Build a jmpq instruction to skip over the bytes. | |
2613 | unsigned char jmp[5]; | |
2614 | jmp[0] = 0xe9; | |
04bf7072 | 2615 | elfcpp::Swap_unaligned<32, false>::writeval(jmp + 1, length - 5); |
2e30d253 ILT |
2616 | return (std::string(reinterpret_cast<char*>(&jmp[0]), 5) |
2617 | + std::string(length - 5, '\0')); | |
2618 | } | |
2619 | ||
2620 | // Nop sequences of various lengths. | |
2621 | const char nop1[1] = { 0x90 }; // nop | |
2622 | const char nop2[2] = { 0x66, 0x90 }; // xchg %ax %ax | |
1caf2c51 ILT |
2623 | const char nop3[3] = { 0x0f, 0x1f, 0x00 }; // nop (%rax) |
2624 | const char nop4[4] = { 0x0f, 0x1f, 0x40, 0x00}; // nop 0(%rax) | |
2625 | const char nop5[5] = { 0x0f, 0x1f, 0x44, 0x00, // nop 0(%rax,%rax,1) | |
2626 | 0x00 }; | |
2627 | const char nop6[6] = { 0x66, 0x0f, 0x1f, 0x44, // nopw 0(%rax,%rax,1) | |
2e30d253 | 2628 | 0x00, 0x00 }; |
1caf2c51 | 2629 | const char nop7[7] = { 0x0f, 0x1f, 0x80, 0x00, // nopl 0L(%rax) |
2e30d253 | 2630 | 0x00, 0x00, 0x00 }; |
1caf2c51 ILT |
2631 | const char nop8[8] = { 0x0f, 0x1f, 0x84, 0x00, // nopl 0L(%rax,%rax,1) |
2632 | 0x00, 0x00, 0x00, 0x00 }; | |
2633 | const char nop9[9] = { 0x66, 0x0f, 0x1f, 0x84, // nopw 0L(%rax,%rax,1) | |
2634 | 0x00, 0x00, 0x00, 0x00, | |
2e30d253 | 2635 | 0x00 }; |
1caf2c51 ILT |
2636 | const char nop10[10] = { 0x66, 0x2e, 0x0f, 0x1f, // nopw %cs:0L(%rax,%rax,1) |
2637 | 0x84, 0x00, 0x00, 0x00, | |
2e30d253 | 2638 | 0x00, 0x00 }; |
1caf2c51 ILT |
2639 | const char nop11[11] = { 0x66, 0x66, 0x2e, 0x0f, // data16 |
2640 | 0x1f, 0x84, 0x00, 0x00, // nopw %cs:0L(%rax,%rax,1) | |
2e30d253 | 2641 | 0x00, 0x00, 0x00 }; |
1caf2c51 ILT |
2642 | const char nop12[12] = { 0x66, 0x66, 0x66, 0x2e, // data16; data16 |
2643 | 0x0f, 0x1f, 0x84, 0x00, // nopw %cs:0L(%rax,%rax,1) | |
2e30d253 | 2644 | 0x00, 0x00, 0x00, 0x00 }; |
1caf2c51 ILT |
2645 | const char nop13[13] = { 0x66, 0x66, 0x66, 0x66, // data16; data16; data16 |
2646 | 0x2e, 0x0f, 0x1f, 0x84, // nopw %cs:0L(%rax,%rax,1) | |
2647 | 0x00, 0x00, 0x00, 0x00, | |
2e30d253 | 2648 | 0x00 }; |
1caf2c51 ILT |
2649 | const char nop14[14] = { 0x66, 0x66, 0x66, 0x66, // data16; data16; data16 |
2650 | 0x66, 0x2e, 0x0f, 0x1f, // data16 | |
2651 | 0x84, 0x00, 0x00, 0x00, // nopw %cs:0L(%rax,%rax,1) | |
2e30d253 | 2652 | 0x00, 0x00 }; |
1caf2c51 ILT |
2653 | const char nop15[15] = { 0x66, 0x66, 0x66, 0x66, // data16; data16; data16 |
2654 | 0x66, 0x66, 0x2e, 0x0f, // data16; data16 | |
2655 | 0x1f, 0x84, 0x00, 0x00, // nopw %cs:0L(%rax,%rax,1) | |
2656 | 0x00, 0x00, 0x00 }; | |
2e30d253 ILT |
2657 | |
2658 | const char* nops[16] = { | |
2659 | NULL, | |
2660 | nop1, nop2, nop3, nop4, nop5, nop6, nop7, | |
2661 | nop8, nop9, nop10, nop11, nop12, nop13, nop14, nop15 | |
2662 | }; | |
2663 | ||
2664 | return std::string(nops[length], length); | |
2665 | } | |
2666 | ||
364c7fa5 ILT |
2667 | // FNOFFSET in section SHNDX in OBJECT is the start of a function |
2668 | // compiled with -fstack-split. The function calls non-stack-split | |
2669 | // code. We have to change the function so that it always ensures | |
2670 | // that it has enough stack space to run some random function. | |
2671 | ||
2672 | void | |
2673 | Target_x86_64::do_calls_non_split(Relobj* object, unsigned int shndx, | |
2674 | section_offset_type fnoffset, | |
2675 | section_size_type fnsize, | |
2676 | unsigned char* view, | |
2677 | section_size_type view_size, | |
2678 | std::string* from, | |
2679 | std::string* to) const | |
2680 | { | |
2681 | // The function starts with a comparison of the stack pointer and a | |
2682 | // field in the TCB. This is followed by a jump. | |
2683 | ||
2684 | // cmp %fs:NN,%rsp | |
2685 | if (this->match_view(view, view_size, fnoffset, "\x64\x48\x3b\x24\x25", 5) | |
2686 | && fnsize > 9) | |
2687 | { | |
2688 | // We will call __morestack if the carry flag is set after this | |
2689 | // comparison. We turn the comparison into an stc instruction | |
2690 | // and some nops. | |
2691 | view[fnoffset] = '\xf9'; | |
2692 | this->set_view_to_nop(view, view_size, fnoffset + 1, 8); | |
2693 | } | |
2694 | // lea NN(%rsp),%r10 | |
cbc999b9 ILT |
2695 | // lea NN(%rsp),%r11 |
2696 | else if ((this->match_view(view, view_size, fnoffset, | |
2697 | "\x4c\x8d\x94\x24", 4) | |
2698 | || this->match_view(view, view_size, fnoffset, | |
2699 | "\x4c\x8d\x9c\x24", 4)) | |
364c7fa5 ILT |
2700 | && fnsize > 8) |
2701 | { | |
2702 | // This is loading an offset from the stack pointer for a | |
2703 | // comparison. The offset is negative, so we decrease the | |
2704 | // offset by the amount of space we need for the stack. This | |
2705 | // means we will avoid calling __morestack if there happens to | |
2706 | // be plenty of space on the stack already. | |
2707 | unsigned char* pval = view + fnoffset + 4; | |
2708 | uint32_t val = elfcpp::Swap_unaligned<32, false>::readval(pval); | |
2709 | val -= parameters->options().split_stack_adjust_size(); | |
2710 | elfcpp::Swap_unaligned<32, false>::writeval(pval, val); | |
2711 | } | |
2712 | else | |
2713 | { | |
2714 | if (!object->has_no_split_stack()) | |
2715 | object->error(_("failed to match split-stack sequence at " | |
2716 | "section %u offset %0zx"), | |
ac33a407 | 2717 | shndx, static_cast<size_t>(fnoffset)); |
364c7fa5 ILT |
2718 | return; |
2719 | } | |
2720 | ||
2721 | // We have to change the function so that it calls | |
2722 | // __morestack_non_split instead of __morestack. The former will | |
2723 | // allocate additional stack space. | |
2724 | *from = "__morestack"; | |
2725 | *to = "__morestack_non_split"; | |
2726 | } | |
2727 | ||
2e30d253 ILT |
2728 | // The selector for x86_64 object files. |
2729 | ||
36959681 | 2730 | class Target_selector_x86_64 : public Target_selector_freebsd |
2e30d253 ILT |
2731 | { |
2732 | public: | |
2733 | Target_selector_x86_64() | |
36959681 ILT |
2734 | : Target_selector_freebsd(elfcpp::EM_X86_64, 64, false, "elf64-x86-64", |
2735 | "elf64-x86-64-freebsd") | |
2e30d253 ILT |
2736 | { } |
2737 | ||
2738 | Target* | |
e96caa79 ILT |
2739 | do_instantiate_target() |
2740 | { return new Target_x86_64(); } | |
36959681 | 2741 | |
2e30d253 ILT |
2742 | }; |
2743 | ||
2e30d253 ILT |
2744 | Target_selector_x86_64 target_selector_x86_64; |
2745 | ||
2746 | } // End anonymous namespace. |