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