| 1 | // sparc.cc -- sparc target support for gold. |
| 2 | |
| 3 | // Copyright 2008, 2009 Free Software Foundation, Inc. |
| 4 | // Written by David S. Miller <davem@davemloft.net>. |
| 5 | |
| 6 | // This file is part of gold. |
| 7 | |
| 8 | // This program is free software; you can redistribute it and/or modify |
| 9 | // it under the terms of the GNU General Public License as published by |
| 10 | // the Free Software Foundation; either version 3 of the License, or |
| 11 | // (at your option) any later version. |
| 12 | |
| 13 | // This program is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
| 21 | // MA 02110-1301, USA. |
| 22 | |
| 23 | #include "gold.h" |
| 24 | |
| 25 | #include <cstdlib> |
| 26 | #include <cstdio> |
| 27 | #include <cstring> |
| 28 | |
| 29 | #include "elfcpp.h" |
| 30 | #include "parameters.h" |
| 31 | #include "reloc.h" |
| 32 | #include "sparc.h" |
| 33 | #include "object.h" |
| 34 | #include "symtab.h" |
| 35 | #include "layout.h" |
| 36 | #include "output.h" |
| 37 | #include "copy-relocs.h" |
| 38 | #include "target.h" |
| 39 | #include "target-reloc.h" |
| 40 | #include "target-select.h" |
| 41 | #include "tls.h" |
| 42 | #include "errors.h" |
| 43 | #include "gc.h" |
| 44 | |
| 45 | namespace |
| 46 | { |
| 47 | |
| 48 | using namespace gold; |
| 49 | |
| 50 | template<int size, bool big_endian> |
| 51 | class Output_data_plt_sparc; |
| 52 | |
| 53 | template<int size, bool big_endian> |
| 54 | class Target_sparc : public Sized_target<size, big_endian> |
| 55 | { |
| 56 | public: |
| 57 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section; |
| 58 | |
| 59 | Target_sparc() |
| 60 | : Sized_target<size, big_endian>(&sparc_info), |
| 61 | got_(NULL), plt_(NULL), rela_dyn_(NULL), |
| 62 | copy_relocs_(elfcpp::R_SPARC_COPY), dynbss_(NULL), |
| 63 | got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL) |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | // Process the relocations to determine unreferenced sections for |
| 68 | // garbage collection. |
| 69 | void |
| 70 | gc_process_relocs(Symbol_table* symtab, |
| 71 | Layout* layout, |
| 72 | Sized_relobj<size, big_endian>* 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 | |
| 82 | // Scan the relocations to look for symbol adjustments. |
| 83 | void |
| 84 | scan_relocs(Symbol_table* symtab, |
| 85 | Layout* layout, |
| 86 | Sized_relobj<size, big_endian>* object, |
| 87 | unsigned int data_shndx, |
| 88 | unsigned int sh_type, |
| 89 | const unsigned char* prelocs, |
| 90 | size_t reloc_count, |
| 91 | Output_section* output_section, |
| 92 | bool needs_special_offset_handling, |
| 93 | size_t local_symbol_count, |
| 94 | const unsigned char* plocal_symbols); |
| 95 | // Finalize the sections. |
| 96 | void |
| 97 | do_finalize_sections(Layout*, const Input_objects*); |
| 98 | |
| 99 | // Return the value to use for a dynamic which requires special |
| 100 | // treatment. |
| 101 | uint64_t |
| 102 | do_dynsym_value(const Symbol*) const; |
| 103 | |
| 104 | // Relocate a section. |
| 105 | void |
| 106 | relocate_section(const Relocate_info<size, big_endian>*, |
| 107 | unsigned int sh_type, |
| 108 | const unsigned char* prelocs, |
| 109 | size_t reloc_count, |
| 110 | Output_section* output_section, |
| 111 | bool needs_special_offset_handling, |
| 112 | unsigned char* view, |
| 113 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, |
| 114 | section_size_type view_size, |
| 115 | const Reloc_symbol_changes*); |
| 116 | |
| 117 | // Scan the relocs during a relocatable link. |
| 118 | void |
| 119 | scan_relocatable_relocs(Symbol_table* symtab, |
| 120 | Layout* layout, |
| 121 | Sized_relobj<size, big_endian>* object, |
| 122 | unsigned int data_shndx, |
| 123 | unsigned int sh_type, |
| 124 | const unsigned char* prelocs, |
| 125 | size_t reloc_count, |
| 126 | Output_section* output_section, |
| 127 | bool needs_special_offset_handling, |
| 128 | size_t local_symbol_count, |
| 129 | const unsigned char* plocal_symbols, |
| 130 | Relocatable_relocs*); |
| 131 | |
| 132 | // Relocate a section during a relocatable link. |
| 133 | void |
| 134 | relocate_for_relocatable(const Relocate_info<size, big_endian>*, |
| 135 | unsigned int sh_type, |
| 136 | const unsigned char* prelocs, |
| 137 | size_t reloc_count, |
| 138 | Output_section* output_section, |
| 139 | off_t offset_in_output_section, |
| 140 | const Relocatable_relocs*, |
| 141 | unsigned char* view, |
| 142 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, |
| 143 | section_size_type view_size, |
| 144 | unsigned char* reloc_view, |
| 145 | section_size_type reloc_view_size); |
| 146 | // Return whether SYM is defined by the ABI. |
| 147 | bool |
| 148 | do_is_defined_by_abi(const Symbol* sym) const |
| 149 | { |
| 150 | // XXX Really need to support this better... |
| 151 | if (sym->type() == elfcpp::STT_SPARC_REGISTER) |
| 152 | return 1; |
| 153 | |
| 154 | return strcmp(sym->name(), "___tls_get_addr") == 0; |
| 155 | } |
| 156 | |
| 157 | // Return whether there is a GOT section. |
| 158 | bool |
| 159 | has_got_section() const |
| 160 | { return this->got_ != NULL; } |
| 161 | |
| 162 | // Return the size of the GOT section. |
| 163 | section_size_type |
| 164 | got_size() |
| 165 | { |
| 166 | gold_assert(this->got_ != NULL); |
| 167 | return this->got_->data_size(); |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | |
| 172 | // The class which scans relocations. |
| 173 | class Scan |
| 174 | { |
| 175 | public: |
| 176 | Scan() |
| 177 | : issued_non_pic_error_(false) |
| 178 | { } |
| 179 | |
| 180 | inline void |
| 181 | local(Symbol_table* symtab, Layout* layout, Target_sparc* target, |
| 182 | Sized_relobj<size, big_endian>* object, |
| 183 | unsigned int data_shndx, |
| 184 | Output_section* output_section, |
| 185 | const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type, |
| 186 | const elfcpp::Sym<size, big_endian>& lsym); |
| 187 | |
| 188 | inline void |
| 189 | global(Symbol_table* symtab, Layout* layout, Target_sparc* target, |
| 190 | Sized_relobj<size, big_endian>* object, |
| 191 | unsigned int data_shndx, |
| 192 | Output_section* output_section, |
| 193 | const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type, |
| 194 | Symbol* gsym); |
| 195 | |
| 196 | private: |
| 197 | static void |
| 198 | unsupported_reloc_local(Sized_relobj<size, big_endian>*, |
| 199 | unsigned int r_type); |
| 200 | |
| 201 | static void |
| 202 | unsupported_reloc_global(Sized_relobj<size, big_endian>*, |
| 203 | unsigned int r_type, Symbol*); |
| 204 | |
| 205 | static void |
| 206 | generate_tls_call(Symbol_table* symtab, Layout* layout, |
| 207 | Target_sparc* target); |
| 208 | |
| 209 | void |
| 210 | check_non_pic(Relobj*, unsigned int r_type); |
| 211 | |
| 212 | // Whether we have issued an error about a non-PIC compilation. |
| 213 | bool issued_non_pic_error_; |
| 214 | }; |
| 215 | |
| 216 | // The class which implements relocation. |
| 217 | class Relocate |
| 218 | { |
| 219 | public: |
| 220 | Relocate() |
| 221 | : ignore_gd_add_(false) |
| 222 | { } |
| 223 | |
| 224 | ~Relocate() |
| 225 | { |
| 226 | if (this->ignore_gd_add_) |
| 227 | { |
| 228 | // FIXME: This needs to specify the location somehow. |
| 229 | gold_error(_("missing expected TLS relocation")); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // Do a relocation. Return false if the caller should not issue |
| 234 | // any warnings about this relocation. |
| 235 | inline bool |
| 236 | relocate(const Relocate_info<size, big_endian>*, Target_sparc*, |
| 237 | Output_section*, size_t relnum, |
| 238 | const elfcpp::Rela<size, big_endian>&, |
| 239 | unsigned int r_type, const Sized_symbol<size>*, |
| 240 | const Symbol_value<size>*, |
| 241 | unsigned char*, |
| 242 | typename elfcpp::Elf_types<size>::Elf_Addr, |
| 243 | section_size_type); |
| 244 | |
| 245 | private: |
| 246 | // Do a TLS relocation. |
| 247 | inline void |
| 248 | relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target, |
| 249 | size_t relnum, const elfcpp::Rela<size, big_endian>&, |
| 250 | unsigned int r_type, const Sized_symbol<size>*, |
| 251 | const Symbol_value<size>*, |
| 252 | unsigned char*, |
| 253 | typename elfcpp::Elf_types<size>::Elf_Addr, |
| 254 | section_size_type); |
| 255 | |
| 256 | // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD |
| 257 | bool ignore_gd_add_; |
| 258 | }; |
| 259 | |
| 260 | // A class which returns the size required for a relocation type, |
| 261 | // used while scanning relocs during a relocatable link. |
| 262 | class Relocatable_size_for_reloc |
| 263 | { |
| 264 | public: |
| 265 | unsigned int |
| 266 | get_size_for_reloc(unsigned int, Relobj*); |
| 267 | }; |
| 268 | |
| 269 | // Get the GOT section, creating it if necessary. |
| 270 | Output_data_got<size, big_endian>* |
| 271 | got_section(Symbol_table*, Layout*); |
| 272 | |
| 273 | // Create a PLT entry for a global symbol. |
| 274 | void |
| 275 | make_plt_entry(Symbol_table*, Layout*, Symbol*); |
| 276 | |
| 277 | // Create a GOT entry for the TLS module index. |
| 278 | unsigned int |
| 279 | got_mod_index_entry(Symbol_table* symtab, Layout* layout, |
| 280 | Sized_relobj<size, big_endian>* object); |
| 281 | |
| 282 | // Return the gsym for "__tls_get_addr". Cache if not already |
| 283 | // cached. |
| 284 | Symbol* |
| 285 | tls_get_addr_sym(Symbol_table* symtab) |
| 286 | { |
| 287 | if (!this->tls_get_addr_sym_) |
| 288 | this->tls_get_addr_sym_ = symtab->lookup("__tls_get_addr", NULL); |
| 289 | gold_assert(this->tls_get_addr_sym_); |
| 290 | return this->tls_get_addr_sym_; |
| 291 | } |
| 292 | |
| 293 | // Get the PLT section. |
| 294 | const Output_data_plt_sparc<size, big_endian>* |
| 295 | plt_section() const |
| 296 | { |
| 297 | gold_assert(this->plt_ != NULL); |
| 298 | return this->plt_; |
| 299 | } |
| 300 | |
| 301 | // Get the dynamic reloc section, creating it if necessary. |
| 302 | Reloc_section* |
| 303 | rela_dyn_section(Layout*); |
| 304 | |
| 305 | // Copy a relocation against a global symbol. |
| 306 | void |
| 307 | copy_reloc(Symbol_table* symtab, Layout* layout, |
| 308 | Sized_relobj<size, big_endian>* object, |
| 309 | unsigned int shndx, Output_section* output_section, |
| 310 | Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc) |
| 311 | { |
| 312 | this->copy_relocs_.copy_reloc(symtab, layout, |
| 313 | symtab->get_sized_symbol<size>(sym), |
| 314 | object, shndx, output_section, |
| 315 | reloc, this->rela_dyn_section(layout)); |
| 316 | } |
| 317 | |
| 318 | // Information about this specific target which we pass to the |
| 319 | // general Target structure. |
| 320 | static Target::Target_info sparc_info; |
| 321 | |
| 322 | // The types of GOT entries needed for this platform. |
| 323 | enum Got_type |
| 324 | { |
| 325 | GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol |
| 326 | GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset |
| 327 | GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair |
| 328 | }; |
| 329 | |
| 330 | // The GOT section. |
| 331 | Output_data_got<size, big_endian>* got_; |
| 332 | // The PLT section. |
| 333 | Output_data_plt_sparc<size, big_endian>* plt_; |
| 334 | // The dynamic reloc section. |
| 335 | Reloc_section* rela_dyn_; |
| 336 | // Relocs saved to avoid a COPY reloc. |
| 337 | Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_; |
| 338 | // Space for variables copied with a COPY reloc. |
| 339 | Output_data_space* dynbss_; |
| 340 | // Offset of the GOT entry for the TLS module index; |
| 341 | unsigned int got_mod_index_offset_; |
| 342 | // Cached pointer to __tls_get_addr symbol |
| 343 | Symbol* tls_get_addr_sym_; |
| 344 | }; |
| 345 | |
| 346 | template<> |
| 347 | Target::Target_info Target_sparc<32, true>::sparc_info = |
| 348 | { |
| 349 | 32, // size |
| 350 | true, // is_big_endian |
| 351 | elfcpp::EM_SPARC, // machine_code |
| 352 | false, // has_make_symbol |
| 353 | false, // has_resolve |
| 354 | false, // has_code_fill |
| 355 | true, // is_default_stack_executable |
| 356 | '\0', // wrap_char |
| 357 | "/usr/lib/ld.so.1", // dynamic_linker |
| 358 | 0x00010000, // default_text_segment_address |
| 359 | 64 * 1024, // abi_pagesize (overridable by -z max-page-size) |
| 360 | 8 * 1024, // common_pagesize (overridable by -z common-page-size) |
| 361 | elfcpp::SHN_UNDEF, // small_common_shndx |
| 362 | elfcpp::SHN_UNDEF, // large_common_shndx |
| 363 | 0, // small_common_section_flags |
| 364 | 0 // large_common_section_flags |
| 365 | }; |
| 366 | |
| 367 | template<> |
| 368 | Target::Target_info Target_sparc<64, true>::sparc_info = |
| 369 | { |
| 370 | 64, // size |
| 371 | true, // is_big_endian |
| 372 | elfcpp::EM_SPARCV9, // machine_code |
| 373 | false, // has_make_symbol |
| 374 | false, // has_resolve |
| 375 | false, // has_code_fill |
| 376 | true, // is_default_stack_executable |
| 377 | '\0', // wrap_char |
| 378 | "/usr/lib/sparcv9/ld.so.1", // dynamic_linker |
| 379 | 0x100000, // default_text_segment_address |
| 380 | 64 * 1024, // abi_pagesize (overridable by -z max-page-size) |
| 381 | 8 * 1024, // common_pagesize (overridable by -z common-page-size) |
| 382 | elfcpp::SHN_UNDEF, // small_common_shndx |
| 383 | elfcpp::SHN_UNDEF, // large_common_shndx |
| 384 | 0, // small_common_section_flags |
| 385 | 0 // large_common_section_flags |
| 386 | }; |
| 387 | |
| 388 | // We have to take care here, even when operating in little-endian |
| 389 | // mode, sparc instructions are still big endian. |
| 390 | template<int size, bool big_endian> |
| 391 | class Sparc_relocate_functions |
| 392 | { |
| 393 | private: |
| 394 | // Do a simple relocation with the addend in the relocation. |
| 395 | template<int valsize> |
| 396 | static inline void |
| 397 | rela(unsigned char* view, |
| 398 | unsigned int right_shift, |
| 399 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, |
| 400 | typename elfcpp::Swap<size, big_endian>::Valtype value, |
| 401 | typename elfcpp::Swap<size, big_endian>::Valtype addend) |
| 402 | { |
| 403 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; |
| 404 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 405 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); |
| 406 | Valtype reloc = ((value + addend) >> right_shift); |
| 407 | |
| 408 | val &= ~dst_mask; |
| 409 | reloc &= dst_mask; |
| 410 | |
| 411 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); |
| 412 | } |
| 413 | |
| 414 | // Do a simple relocation using a symbol value with the addend in |
| 415 | // the relocation. |
| 416 | template<int valsize> |
| 417 | static inline void |
| 418 | rela(unsigned char* view, |
| 419 | unsigned int right_shift, |
| 420 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, |
| 421 | const Sized_relobj<size, big_endian>* object, |
| 422 | const Symbol_value<size>* psymval, |
| 423 | typename elfcpp::Swap<valsize, big_endian>::Valtype addend) |
| 424 | { |
| 425 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; |
| 426 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 427 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); |
| 428 | Valtype reloc = (psymval->value(object, addend) >> right_shift); |
| 429 | |
| 430 | val &= ~dst_mask; |
| 431 | reloc &= dst_mask; |
| 432 | |
| 433 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); |
| 434 | } |
| 435 | |
| 436 | // Do a simple relocation using a symbol value with the addend in |
| 437 | // the relocation, unaligned. |
| 438 | template<int valsize> |
| 439 | static inline void |
| 440 | rela_ua(unsigned char* view, |
| 441 | unsigned int right_shift, elfcpp::Elf_Xword dst_mask, |
| 442 | const Sized_relobj<size, big_endian>* object, |
| 443 | const Symbol_value<size>* psymval, |
| 444 | typename elfcpp::Swap<size, big_endian>::Valtype addend) |
| 445 | { |
| 446 | typedef typename elfcpp::Swap_unaligned<valsize, |
| 447 | big_endian>::Valtype Valtype; |
| 448 | unsigned char* wv = view; |
| 449 | Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv); |
| 450 | Valtype reloc = (psymval->value(object, addend) >> right_shift); |
| 451 | |
| 452 | val &= ~dst_mask; |
| 453 | reloc &= dst_mask; |
| 454 | |
| 455 | elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc); |
| 456 | } |
| 457 | |
| 458 | // Do a simple PC relative relocation with a Symbol_value with the |
| 459 | // addend in the relocation. |
| 460 | template<int valsize> |
| 461 | static inline void |
| 462 | pcrela(unsigned char* view, |
| 463 | unsigned int right_shift, |
| 464 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, |
| 465 | const Sized_relobj<size, big_endian>* object, |
| 466 | const Symbol_value<size>* psymval, |
| 467 | typename elfcpp::Swap<size, big_endian>::Valtype addend, |
| 468 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 469 | { |
| 470 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; |
| 471 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 472 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); |
| 473 | Valtype reloc = ((psymval->value(object, addend) - address) |
| 474 | >> right_shift); |
| 475 | |
| 476 | val &= ~dst_mask; |
| 477 | reloc &= dst_mask; |
| 478 | |
| 479 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); |
| 480 | } |
| 481 | |
| 482 | template<int valsize> |
| 483 | static inline void |
| 484 | pcrela_unaligned(unsigned char* view, |
| 485 | const Sized_relobj<size, big_endian>* object, |
| 486 | const Symbol_value<size>* psymval, |
| 487 | typename elfcpp::Swap<size, big_endian>::Valtype addend, |
| 488 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 489 | { |
| 490 | typedef typename elfcpp::Swap_unaligned<valsize, |
| 491 | big_endian>::Valtype Valtype; |
| 492 | unsigned char* wv = view; |
| 493 | Valtype reloc = (psymval->value(object, addend) - address); |
| 494 | |
| 495 | elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc); |
| 496 | } |
| 497 | |
| 498 | typedef Sparc_relocate_functions<size, big_endian> This; |
| 499 | typedef Sparc_relocate_functions<size, true> This_insn; |
| 500 | |
| 501 | public: |
| 502 | // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2 |
| 503 | static inline void |
| 504 | wdisp30(unsigned char* view, |
| 505 | const Sized_relobj<size, big_endian>* object, |
| 506 | const Symbol_value<size>* psymval, |
| 507 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 508 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 509 | { |
| 510 | This_insn::template pcrela<32>(view, 2, 0x3fffffff, object, |
| 511 | psymval, addend, address); |
| 512 | } |
| 513 | |
| 514 | // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2 |
| 515 | static inline void |
| 516 | wdisp22(unsigned char* view, |
| 517 | const Sized_relobj<size, big_endian>* object, |
| 518 | const Symbol_value<size>* psymval, |
| 519 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 520 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 521 | { |
| 522 | This_insn::template pcrela<32>(view, 2, 0x003fffff, object, |
| 523 | psymval, addend, address); |
| 524 | } |
| 525 | |
| 526 | // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2 |
| 527 | static inline void |
| 528 | wdisp19(unsigned char* view, |
| 529 | const Sized_relobj<size, big_endian>* object, |
| 530 | const Symbol_value<size>* psymval, |
| 531 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 532 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 533 | { |
| 534 | This_insn::template pcrela<32>(view, 2, 0x0007ffff, object, |
| 535 | psymval, addend, address); |
| 536 | } |
| 537 | |
| 538 | // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2 |
| 539 | static inline void |
| 540 | wdisp16(unsigned char* view, |
| 541 | const Sized_relobj<size, big_endian>* object, |
| 542 | const Symbol_value<size>* psymval, |
| 543 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 544 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 545 | { |
| 546 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; |
| 547 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 548 | Valtype val = elfcpp::Swap<32, true>::readval(wv); |
| 549 | Valtype reloc = ((psymval->value(object, addend) - address) |
| 550 | >> 2); |
| 551 | |
| 552 | // The relocation value is split between the low 14 bits, |
| 553 | // and bits 20-21. |
| 554 | val &= ~((0x3 << 20) | 0x3fff); |
| 555 | reloc = (((reloc & 0xc000) << (20 - 14)) |
| 556 | | (reloc & 0x3ffff)); |
| 557 | |
| 558 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); |
| 559 | } |
| 560 | |
| 561 | // R_SPARC_PC22: (Symbol + Addend - Address) >> 10 |
| 562 | static inline void |
| 563 | pc22(unsigned char* view, |
| 564 | const Sized_relobj<size, big_endian>* object, |
| 565 | const Symbol_value<size>* psymval, |
| 566 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 567 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 568 | { |
| 569 | This_insn::template pcrela<32>(view, 10, 0x003fffff, object, |
| 570 | psymval, addend, address); |
| 571 | } |
| 572 | |
| 573 | // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff |
| 574 | static inline void |
| 575 | pc10(unsigned char* view, |
| 576 | const Sized_relobj<size, big_endian>* object, |
| 577 | const Symbol_value<size>* psymval, |
| 578 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 579 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 580 | { |
| 581 | This_insn::template pcrela<32>(view, 0, 0x000003ff, object, |
| 582 | psymval, addend, address); |
| 583 | } |
| 584 | |
| 585 | // R_SPARC_HI22: (Symbol + Addend) >> 10 |
| 586 | static inline void |
| 587 | hi22(unsigned char* view, |
| 588 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
| 589 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 590 | { |
| 591 | This_insn::template rela<32>(view, 10, 0x003fffff, value, addend); |
| 592 | } |
| 593 | |
| 594 | // R_SPARC_HI22: (Symbol + Addend) >> 10 |
| 595 | static inline void |
| 596 | hi22(unsigned char* view, |
| 597 | const Sized_relobj<size, big_endian>* object, |
| 598 | const Symbol_value<size>* psymval, |
| 599 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 600 | { |
| 601 | This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend); |
| 602 | } |
| 603 | |
| 604 | // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10 |
| 605 | static inline void |
| 606 | pcplt22(unsigned char* view, |
| 607 | const Sized_relobj<size, big_endian>* object, |
| 608 | const Symbol_value<size>* psymval, |
| 609 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 610 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 611 | { |
| 612 | This_insn::template pcrela<32>(view, 10, 0x003fffff, object, |
| 613 | psymval, addend, address); |
| 614 | } |
| 615 | |
| 616 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff |
| 617 | static inline void |
| 618 | lo10(unsigned char* view, |
| 619 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
| 620 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 621 | { |
| 622 | This_insn::template rela<32>(view, 0, 0x000003ff, value, addend); |
| 623 | } |
| 624 | |
| 625 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff |
| 626 | static inline void |
| 627 | lo10(unsigned char* view, |
| 628 | const Sized_relobj<size, big_endian>* object, |
| 629 | const Symbol_value<size>* psymval, |
| 630 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 631 | { |
| 632 | This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend); |
| 633 | } |
| 634 | |
| 635 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff |
| 636 | static inline void |
| 637 | lo10(unsigned char* view, |
| 638 | const Sized_relobj<size, big_endian>* object, |
| 639 | const Symbol_value<size>* psymval, |
| 640 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 641 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 642 | { |
| 643 | This_insn::template pcrela<32>(view, 0, 0x000003ff, object, |
| 644 | psymval, addend, address); |
| 645 | } |
| 646 | |
| 647 | // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2 |
| 648 | static inline void |
| 649 | olo10(unsigned char* view, |
| 650 | const Sized_relobj<size, big_endian>* object, |
| 651 | const Symbol_value<size>* psymval, |
| 652 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 653 | typename elfcpp::Elf_types<size>::Elf_Addr addend2) |
| 654 | { |
| 655 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; |
| 656 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 657 | Valtype val = elfcpp::Swap<32, true>::readval(wv); |
| 658 | Valtype reloc = psymval->value(object, addend); |
| 659 | |
| 660 | val &= ~0x1fff; |
| 661 | reloc &= 0x3ff; |
| 662 | reloc += addend2; |
| 663 | reloc &= 0x1fff; |
| 664 | |
| 665 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); |
| 666 | } |
| 667 | |
| 668 | // R_SPARC_22: (Symbol + Addend) |
| 669 | static inline void |
| 670 | rela32_22(unsigned char* view, |
| 671 | const Sized_relobj<size, big_endian>* object, |
| 672 | const Symbol_value<size>* psymval, |
| 673 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 674 | { |
| 675 | This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend); |
| 676 | } |
| 677 | |
| 678 | // R_SPARC_13: (Symbol + Addend) |
| 679 | static inline void |
| 680 | rela32_13(unsigned char* view, |
| 681 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
| 682 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 683 | { |
| 684 | This_insn::template rela<32>(view, 0, 0x00001fff, value, addend); |
| 685 | } |
| 686 | |
| 687 | // R_SPARC_13: (Symbol + Addend) |
| 688 | static inline void |
| 689 | rela32_13(unsigned char* view, |
| 690 | const Sized_relobj<size, big_endian>* object, |
| 691 | const Symbol_value<size>* psymval, |
| 692 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 693 | { |
| 694 | This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend); |
| 695 | } |
| 696 | |
| 697 | // R_SPARC_UA16: (Symbol + Addend) |
| 698 | static inline void |
| 699 | ua16(unsigned char* view, |
| 700 | const Sized_relobj<size, big_endian>* object, |
| 701 | const Symbol_value<size>* psymval, |
| 702 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 703 | { |
| 704 | This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend); |
| 705 | } |
| 706 | |
| 707 | // R_SPARC_UA32: (Symbol + Addend) |
| 708 | static inline void |
| 709 | ua32(unsigned char* view, |
| 710 | const Sized_relobj<size, big_endian>* object, |
| 711 | const Symbol_value<size>* psymval, |
| 712 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 713 | { |
| 714 | This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend); |
| 715 | } |
| 716 | |
| 717 | // R_SPARC_UA64: (Symbol + Addend) |
| 718 | static inline void |
| 719 | ua64(unsigned char* view, |
| 720 | const Sized_relobj<size, big_endian>* object, |
| 721 | const Symbol_value<size>* psymval, |
| 722 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 723 | { |
| 724 | This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0, |
| 725 | object, psymval, addend); |
| 726 | } |
| 727 | |
| 728 | // R_SPARC_DISP8: (Symbol + Addend - Address) |
| 729 | static inline void |
| 730 | disp8(unsigned char* view, |
| 731 | const Sized_relobj<size, big_endian>* object, |
| 732 | const Symbol_value<size>* psymval, |
| 733 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 734 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 735 | { |
| 736 | This::template pcrela_unaligned<8>(view, object, psymval, |
| 737 | addend, address); |
| 738 | } |
| 739 | |
| 740 | // R_SPARC_DISP16: (Symbol + Addend - Address) |
| 741 | static inline void |
| 742 | disp16(unsigned char* view, |
| 743 | const Sized_relobj<size, big_endian>* object, |
| 744 | const Symbol_value<size>* psymval, |
| 745 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 746 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 747 | { |
| 748 | This::template pcrela_unaligned<16>(view, object, psymval, |
| 749 | addend, address); |
| 750 | } |
| 751 | |
| 752 | // R_SPARC_DISP32: (Symbol + Addend - Address) |
| 753 | static inline void |
| 754 | disp32(unsigned char* view, |
| 755 | const Sized_relobj<size, big_endian>* object, |
| 756 | const Symbol_value<size>* psymval, |
| 757 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 758 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 759 | { |
| 760 | This::template pcrela_unaligned<32>(view, object, psymval, |
| 761 | addend, address); |
| 762 | } |
| 763 | |
| 764 | // R_SPARC_DISP64: (Symbol + Addend - Address) |
| 765 | static inline void |
| 766 | disp64(unsigned char* view, |
| 767 | const Sized_relobj<size, big_endian>* object, |
| 768 | const Symbol_value<size>* psymval, |
| 769 | elfcpp::Elf_Xword addend, |
| 770 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 771 | { |
| 772 | This::template pcrela_unaligned<64>(view, object, psymval, |
| 773 | addend, address); |
| 774 | } |
| 775 | |
| 776 | // R_SPARC_H44: (Symbol + Addend) >> 22 |
| 777 | static inline void |
| 778 | h44(unsigned char* view, |
| 779 | const Sized_relobj<size, big_endian>* object, |
| 780 | const Symbol_value<size>* psymval, |
| 781 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 782 | { |
| 783 | This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend); |
| 784 | } |
| 785 | |
| 786 | // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff |
| 787 | static inline void |
| 788 | m44(unsigned char* view, |
| 789 | const Sized_relobj<size, big_endian>* object, |
| 790 | const Symbol_value<size>* psymval, |
| 791 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 792 | { |
| 793 | This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend); |
| 794 | } |
| 795 | |
| 796 | // R_SPARC_L44: (Symbol + Addend) & 0xfff |
| 797 | static inline void |
| 798 | l44(unsigned char* view, |
| 799 | const Sized_relobj<size, big_endian>* object, |
| 800 | const Symbol_value<size>* psymval, |
| 801 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 802 | { |
| 803 | This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend); |
| 804 | } |
| 805 | |
| 806 | // R_SPARC_HH22: (Symbol + Addend) >> 42 |
| 807 | static inline void |
| 808 | hh22(unsigned char* view, |
| 809 | const Sized_relobj<size, big_endian>* object, |
| 810 | const Symbol_value<size>* psymval, |
| 811 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 812 | { |
| 813 | This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend); |
| 814 | } |
| 815 | |
| 816 | // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42 |
| 817 | static inline void |
| 818 | pc_hh22(unsigned char* view, |
| 819 | const Sized_relobj<size, big_endian>* object, |
| 820 | const Symbol_value<size>* psymval, |
| 821 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 822 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 823 | { |
| 824 | This_insn::template pcrela<32>(view, 42, 0x003fffff, object, |
| 825 | psymval, addend, address); |
| 826 | } |
| 827 | |
| 828 | // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff |
| 829 | static inline void |
| 830 | hm10(unsigned char* view, |
| 831 | const Sized_relobj<size, big_endian>* object, |
| 832 | const Symbol_value<size>* psymval, |
| 833 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 834 | { |
| 835 | This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend); |
| 836 | } |
| 837 | |
| 838 | // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff |
| 839 | static inline void |
| 840 | pc_hm10(unsigned char* view, |
| 841 | const Sized_relobj<size, big_endian>* object, |
| 842 | const Symbol_value<size>* psymval, |
| 843 | typename elfcpp::Elf_types<size>::Elf_Addr addend, |
| 844 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
| 845 | { |
| 846 | This_insn::template pcrela<32>(view, 32, 0x000003ff, object, |
| 847 | psymval, addend, address); |
| 848 | } |
| 849 | |
| 850 | // R_SPARC_11: (Symbol + Addend) |
| 851 | static inline void |
| 852 | rela32_11(unsigned char* view, |
| 853 | const Sized_relobj<size, big_endian>* object, |
| 854 | const Symbol_value<size>* psymval, |
| 855 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 856 | { |
| 857 | This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend); |
| 858 | } |
| 859 | |
| 860 | // R_SPARC_10: (Symbol + Addend) |
| 861 | static inline void |
| 862 | rela32_10(unsigned char* view, |
| 863 | const Sized_relobj<size, big_endian>* object, |
| 864 | const Symbol_value<size>* psymval, |
| 865 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 866 | { |
| 867 | This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend); |
| 868 | } |
| 869 | |
| 870 | // R_SPARC_7: (Symbol + Addend) |
| 871 | static inline void |
| 872 | rela32_7(unsigned char* view, |
| 873 | const Sized_relobj<size, big_endian>* object, |
| 874 | const Symbol_value<size>* psymval, |
| 875 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 876 | { |
| 877 | This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend); |
| 878 | } |
| 879 | |
| 880 | // R_SPARC_6: (Symbol + Addend) |
| 881 | static inline void |
| 882 | rela32_6(unsigned char* view, |
| 883 | const Sized_relobj<size, big_endian>* object, |
| 884 | const Symbol_value<size>* psymval, |
| 885 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 886 | { |
| 887 | This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend); |
| 888 | } |
| 889 | |
| 890 | // R_SPARC_5: (Symbol + Addend) |
| 891 | static inline void |
| 892 | rela32_5(unsigned char* view, |
| 893 | const Sized_relobj<size, big_endian>* object, |
| 894 | const Symbol_value<size>* psymval, |
| 895 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 896 | { |
| 897 | This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend); |
| 898 | } |
| 899 | |
| 900 | // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10 |
| 901 | static inline void |
| 902 | ldo_hix22(unsigned char* view, |
| 903 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
| 904 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 905 | { |
| 906 | This_insn::hi22(view, value, addend); |
| 907 | } |
| 908 | |
| 909 | // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff |
| 910 | static inline void |
| 911 | ldo_lox10(unsigned char* view, |
| 912 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
| 913 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 914 | { |
| 915 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; |
| 916 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 917 | Valtype val = elfcpp::Swap<32, true>::readval(wv); |
| 918 | Valtype reloc = (value + addend); |
| 919 | |
| 920 | val &= ~0x1fff; |
| 921 | reloc &= 0x3ff; |
| 922 | |
| 923 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); |
| 924 | } |
| 925 | |
| 926 | // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10 |
| 927 | static inline void |
| 928 | hix22(unsigned char* view, |
| 929 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
| 930 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 931 | { |
| 932 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; |
| 933 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 934 | Valtype val = elfcpp::Swap<32, true>::readval(wv); |
| 935 | Valtype reloc = (value + addend); |
| 936 | |
| 937 | val &= ~0x3fffff; |
| 938 | |
| 939 | reloc ^= ~(Valtype)0; |
| 940 | reloc >>= 10; |
| 941 | |
| 942 | reloc &= 0x3fffff; |
| 943 | |
| 944 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); |
| 945 | } |
| 946 | |
| 947 | // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10 |
| 948 | static inline void |
| 949 | hix22(unsigned char* view, |
| 950 | const Sized_relobj<size, big_endian>* object, |
| 951 | const Symbol_value<size>* psymval, |
| 952 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 953 | { |
| 954 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; |
| 955 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 956 | Valtype val = elfcpp::Swap<32, true>::readval(wv); |
| 957 | Valtype reloc = psymval->value(object, addend); |
| 958 | |
| 959 | val &= ~0x3fffff; |
| 960 | |
| 961 | reloc ^= ~(Valtype)0; |
| 962 | reloc >>= 10; |
| 963 | |
| 964 | reloc &= 0x3fffff; |
| 965 | |
| 966 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); |
| 967 | } |
| 968 | |
| 969 | |
| 970 | // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00 |
| 971 | static inline void |
| 972 | lox10(unsigned char* view, |
| 973 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
| 974 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 975 | { |
| 976 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; |
| 977 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 978 | Valtype val = elfcpp::Swap<32, true>::readval(wv); |
| 979 | Valtype reloc = (value + addend); |
| 980 | |
| 981 | val &= ~0x1fff; |
| 982 | reloc &= 0x3ff; |
| 983 | reloc |= 0x1c00; |
| 984 | |
| 985 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); |
| 986 | } |
| 987 | |
| 988 | // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00 |
| 989 | static inline void |
| 990 | lox10(unsigned char* view, |
| 991 | const Sized_relobj<size, big_endian>* object, |
| 992 | const Symbol_value<size>* psymval, |
| 993 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
| 994 | { |
| 995 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; |
| 996 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
| 997 | Valtype val = elfcpp::Swap<32, true>::readval(wv); |
| 998 | Valtype reloc = psymval->value(object, addend); |
| 999 | |
| 1000 | val &= ~0x1fff; |
| 1001 | reloc &= 0x3ff; |
| 1002 | reloc |= 0x1c00; |
| 1003 | |
| 1004 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); |
| 1005 | } |
| 1006 | }; |
| 1007 | |
| 1008 | // Get the GOT section, creating it if necessary. |
| 1009 | |
| 1010 | template<int size, bool big_endian> |
| 1011 | Output_data_got<size, big_endian>* |
| 1012 | Target_sparc<size, big_endian>::got_section(Symbol_table* symtab, |
| 1013 | Layout* layout) |
| 1014 | { |
| 1015 | if (this->got_ == NULL) |
| 1016 | { |
| 1017 | gold_assert(symtab != NULL && layout != NULL); |
| 1018 | |
| 1019 | this->got_ = new Output_data_got<size, big_endian>(); |
| 1020 | |
| 1021 | Output_section* os; |
| 1022 | os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS, |
| 1023 | (elfcpp::SHF_ALLOC |
| 1024 | | elfcpp::SHF_WRITE), |
| 1025 | this->got_, false); |
| 1026 | os->set_is_relro(); |
| 1027 | |
| 1028 | // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section. |
| 1029 | symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL, |
| 1030 | this->got_, |
| 1031 | 0, 0, elfcpp::STT_OBJECT, |
| 1032 | elfcpp::STB_LOCAL, |
| 1033 | elfcpp::STV_HIDDEN, 0, |
| 1034 | false, false); |
| 1035 | } |
| 1036 | |
| 1037 | return this->got_; |
| 1038 | } |
| 1039 | |
| 1040 | // Get the dynamic reloc section, creating it if necessary. |
| 1041 | |
| 1042 | template<int size, bool big_endian> |
| 1043 | typename Target_sparc<size, big_endian>::Reloc_section* |
| 1044 | Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout) |
| 1045 | { |
| 1046 | if (this->rela_dyn_ == NULL) |
| 1047 | { |
| 1048 | gold_assert(layout != NULL); |
| 1049 | this->rela_dyn_ = new Reloc_section(parameters->options().combreloc()); |
| 1050 | layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA, |
| 1051 | elfcpp::SHF_ALLOC, this->rela_dyn_, true); |
| 1052 | } |
| 1053 | return this->rela_dyn_; |
| 1054 | } |
| 1055 | |
| 1056 | // A class to handle the PLT data. |
| 1057 | |
| 1058 | template<int size, bool big_endian> |
| 1059 | class Output_data_plt_sparc : public Output_section_data |
| 1060 | { |
| 1061 | public: |
| 1062 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, |
| 1063 | size, big_endian> Reloc_section; |
| 1064 | |
| 1065 | Output_data_plt_sparc(Layout*); |
| 1066 | |
| 1067 | // Add an entry to the PLT. |
| 1068 | void add_entry(Symbol* gsym); |
| 1069 | |
| 1070 | // Return the .rela.plt section data. |
| 1071 | const Reloc_section* rel_plt() const |
| 1072 | { |
| 1073 | return this->rel_; |
| 1074 | } |
| 1075 | |
| 1076 | protected: |
| 1077 | void do_adjust_output_section(Output_section* os); |
| 1078 | |
| 1079 | // Write to a map file. |
| 1080 | void |
| 1081 | do_print_to_mapfile(Mapfile* mapfile) const |
| 1082 | { mapfile->print_output_data(this, _("** PLT")); } |
| 1083 | |
| 1084 | private: |
| 1085 | // The size of an entry in the PLT. |
| 1086 | static const int base_plt_entry_size = (size == 32 ? 12 : 32); |
| 1087 | |
| 1088 | static const unsigned int plt_entries_per_block = 160; |
| 1089 | static const unsigned int plt_insn_chunk_size = 24; |
| 1090 | static const unsigned int plt_pointer_chunk_size = 8; |
| 1091 | static const unsigned int plt_block_size = |
| 1092 | (plt_entries_per_block |
| 1093 | * (plt_insn_chunk_size + plt_pointer_chunk_size)); |
| 1094 | |
| 1095 | // Set the final size. |
| 1096 | void |
| 1097 | set_final_data_size() |
| 1098 | { |
| 1099 | unsigned int full_count = this->count_ + 4; |
| 1100 | unsigned int extra = (size == 32 ? 4 : 0); |
| 1101 | |
| 1102 | if (size == 32 || full_count < 32768) |
| 1103 | this->set_data_size((full_count * base_plt_entry_size) + extra); |
| 1104 | else |
| 1105 | { |
| 1106 | unsigned int ext_cnt = full_count - 32768; |
| 1107 | |
| 1108 | this->set_data_size((32768 * base_plt_entry_size) |
| 1109 | + (ext_cnt |
| 1110 | * (plt_insn_chunk_size |
| 1111 | + plt_pointer_chunk_size))); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | // Write out the PLT data. |
| 1116 | void |
| 1117 | do_write(Output_file*); |
| 1118 | |
| 1119 | // The reloc section. |
| 1120 | Reloc_section* rel_; |
| 1121 | // The number of PLT entries. |
| 1122 | unsigned int count_; |
| 1123 | }; |
| 1124 | |
| 1125 | // Define the constants as required by C++ standard. |
| 1126 | |
| 1127 | template<int size, bool big_endian> |
| 1128 | const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size; |
| 1129 | |
| 1130 | template<int size, bool big_endian> |
| 1131 | const unsigned int |
| 1132 | Output_data_plt_sparc<size, big_endian>::plt_entries_per_block; |
| 1133 | |
| 1134 | template<int size, bool big_endian> |
| 1135 | const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size; |
| 1136 | |
| 1137 | template<int size, bool big_endian> |
| 1138 | const unsigned int |
| 1139 | Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size; |
| 1140 | |
| 1141 | template<int size, bool big_endian> |
| 1142 | const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size; |
| 1143 | |
| 1144 | // Create the PLT section. The ordinary .got section is an argument, |
| 1145 | // since we need to refer to the start. |
| 1146 | |
| 1147 | template<int size, bool big_endian> |
| 1148 | Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout) |
| 1149 | : Output_section_data(size == 32 ? 4 : 8), count_(0) |
| 1150 | { |
| 1151 | this->rel_ = new Reloc_section(false); |
| 1152 | layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA, |
| 1153 | elfcpp::SHF_ALLOC, this->rel_, true); |
| 1154 | } |
| 1155 | |
| 1156 | template<int size, bool big_endian> |
| 1157 | void |
| 1158 | Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os) |
| 1159 | { |
| 1160 | os->set_entsize(0); |
| 1161 | } |
| 1162 | |
| 1163 | // Add an entry to the PLT. |
| 1164 | |
| 1165 | template<int size, bool big_endian> |
| 1166 | void |
| 1167 | Output_data_plt_sparc<size, big_endian>::add_entry(Symbol* gsym) |
| 1168 | { |
| 1169 | gold_assert(!gsym->has_plt_offset()); |
| 1170 | |
| 1171 | unsigned int index = this->count_ + 4; |
| 1172 | section_offset_type plt_offset; |
| 1173 | |
| 1174 | if (size == 32 || index < 32768) |
| 1175 | plt_offset = index * base_plt_entry_size; |
| 1176 | else |
| 1177 | { |
| 1178 | unsigned int ext_index = index - 32768; |
| 1179 | |
| 1180 | plt_offset = (32768 * base_plt_entry_size) |
| 1181 | + ((ext_index / plt_entries_per_block) |
| 1182 | * plt_block_size) |
| 1183 | + ((ext_index % plt_entries_per_block) |
| 1184 | * plt_insn_chunk_size); |
| 1185 | } |
| 1186 | |
| 1187 | gsym->set_plt_offset(plt_offset); |
| 1188 | |
| 1189 | ++this->count_; |
| 1190 | |
| 1191 | // Every PLT entry needs a reloc. |
| 1192 | gsym->set_needs_dynsym_entry(); |
| 1193 | this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this, |
| 1194 | plt_offset, 0); |
| 1195 | |
| 1196 | // Note that we don't need to save the symbol. The contents of the |
| 1197 | // PLT are independent of which symbols are used. The symbols only |
| 1198 | // appear in the relocations. |
| 1199 | } |
| 1200 | |
| 1201 | static const unsigned int sparc_nop = 0x01000000; |
| 1202 | static const unsigned int sparc_sethi_g1 = 0x03000000; |
| 1203 | static const unsigned int sparc_branch_always = 0x30800000; |
| 1204 | static const unsigned int sparc_branch_always_pt = 0x30680000; |
| 1205 | static const unsigned int sparc_mov = 0x80100000; |
| 1206 | static const unsigned int sparc_mov_g0_o0 = 0x90100000; |
| 1207 | static const unsigned int sparc_mov_o7_g5 = 0x8a10000f; |
| 1208 | static const unsigned int sparc_call_plus_8 = 0x40000002; |
| 1209 | static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000; |
| 1210 | static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001; |
| 1211 | static const unsigned int sparc_mov_g5_o7 = 0x9e100005; |
| 1212 | |
| 1213 | // Write out the PLT. |
| 1214 | |
| 1215 | template<int size, bool big_endian> |
| 1216 | void |
| 1217 | Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of) |
| 1218 | { |
| 1219 | const off_t offset = this->offset(); |
| 1220 | const section_size_type oview_size = |
| 1221 | convert_to_section_size_type(this->data_size()); |
| 1222 | unsigned char* const oview = of->get_output_view(offset, oview_size); |
| 1223 | unsigned char* pov = oview; |
| 1224 | |
| 1225 | memset(pov, 0, base_plt_entry_size * 4); |
| 1226 | pov += base_plt_entry_size * 4; |
| 1227 | |
| 1228 | unsigned int plt_offset = base_plt_entry_size * 4; |
| 1229 | const unsigned int count = this->count_; |
| 1230 | |
| 1231 | if (size == 64) |
| 1232 | { |
| 1233 | unsigned int limit; |
| 1234 | |
| 1235 | limit = (count > 32768 ? 32768 : count); |
| 1236 | |
| 1237 | for (unsigned int i = 0; i < limit; ++i) |
| 1238 | { |
| 1239 | elfcpp::Swap<32, true>::writeval(pov + 0x00, |
| 1240 | sparc_sethi_g1 + plt_offset); |
| 1241 | elfcpp::Swap<32, true>::writeval(pov + 0x04, |
| 1242 | sparc_branch_always_pt + |
| 1243 | (((base_plt_entry_size - |
| 1244 | (plt_offset + 4)) >> 2) & |
| 1245 | 0x7ffff)); |
| 1246 | elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop); |
| 1247 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop); |
| 1248 | elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop); |
| 1249 | elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop); |
| 1250 | elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop); |
| 1251 | elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop); |
| 1252 | |
| 1253 | pov += base_plt_entry_size; |
| 1254 | plt_offset += base_plt_entry_size; |
| 1255 | } |
| 1256 | |
| 1257 | if (count > 32768) |
| 1258 | { |
| 1259 | unsigned int ext_cnt = count - 32768; |
| 1260 | unsigned int blks = ext_cnt / plt_entries_per_block; |
| 1261 | |
| 1262 | for (unsigned int i = 0; i < blks; ++i) |
| 1263 | { |
| 1264 | unsigned int data_off = (plt_entries_per_block |
| 1265 | * plt_insn_chunk_size) - 4; |
| 1266 | |
| 1267 | for (unsigned int j = 0; j < plt_entries_per_block; ++j) |
| 1268 | { |
| 1269 | elfcpp::Swap<32, true>::writeval(pov + 0x00, |
| 1270 | sparc_mov_o7_g5); |
| 1271 | elfcpp::Swap<32, true>::writeval(pov + 0x04, |
| 1272 | sparc_call_plus_8); |
| 1273 | elfcpp::Swap<32, true>::writeval(pov + 0x08, |
| 1274 | sparc_nop); |
| 1275 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, |
| 1276 | sparc_ldx_o7_imm_g1 + |
| 1277 | (data_off & 0x1fff)); |
| 1278 | elfcpp::Swap<32, true>::writeval(pov + 0x10, |
| 1279 | sparc_jmpl_o7_g1_g1); |
| 1280 | elfcpp::Swap<32, true>::writeval(pov + 0x14, |
| 1281 | sparc_mov_g5_o7); |
| 1282 | |
| 1283 | elfcpp::Swap<64, big_endian>::writeval( |
| 1284 | pov + 0x4 + data_off, |
| 1285 | (elfcpp::Elf_Xword) (oview - (pov + 0x04))); |
| 1286 | |
| 1287 | pov += plt_insn_chunk_size; |
| 1288 | data_off -= 16; |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block; |
| 1293 | for (unsigned int i = 0; i < sub_blk_cnt; ++i) |
| 1294 | { |
| 1295 | unsigned int data_off = (sub_blk_cnt |
| 1296 | * plt_insn_chunk_size) - 4; |
| 1297 | |
| 1298 | for (unsigned int j = 0; j < plt_entries_per_block; ++j) |
| 1299 | { |
| 1300 | elfcpp::Swap<32, true>::writeval(pov + 0x00, |
| 1301 | sparc_mov_o7_g5); |
| 1302 | elfcpp::Swap<32, true>::writeval(pov + 0x04, |
| 1303 | sparc_call_plus_8); |
| 1304 | elfcpp::Swap<32, true>::writeval(pov + 0x08, |
| 1305 | sparc_nop); |
| 1306 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, |
| 1307 | sparc_ldx_o7_imm_g1 + |
| 1308 | (data_off & 0x1fff)); |
| 1309 | elfcpp::Swap<32, true>::writeval(pov + 0x10, |
| 1310 | sparc_jmpl_o7_g1_g1); |
| 1311 | elfcpp::Swap<32, true>::writeval(pov + 0x14, |
| 1312 | sparc_mov_g5_o7); |
| 1313 | |
| 1314 | elfcpp::Swap<64, big_endian>::writeval( |
| 1315 | pov + 0x4 + data_off, |
| 1316 | (elfcpp::Elf_Xword) (oview - (pov + 0x04))); |
| 1317 | |
| 1318 | pov += plt_insn_chunk_size; |
| 1319 | data_off -= 16; |
| 1320 | } |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | else |
| 1325 | { |
| 1326 | for (unsigned int i = 0; i < count; ++i) |
| 1327 | { |
| 1328 | elfcpp::Swap<32, true>::writeval(pov + 0x00, |
| 1329 | sparc_sethi_g1 + plt_offset); |
| 1330 | elfcpp::Swap<32, true>::writeval(pov + 0x04, |
| 1331 | sparc_branch_always + |
| 1332 | (((- (plt_offset + 4)) >> 2) & |
| 1333 | 0x003fffff)); |
| 1334 | elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop); |
| 1335 | |
| 1336 | pov += base_plt_entry_size; |
| 1337 | plt_offset += base_plt_entry_size; |
| 1338 | } |
| 1339 | |
| 1340 | elfcpp::Swap<32, true>::writeval(pov, sparc_nop); |
| 1341 | pov += 4; |
| 1342 | } |
| 1343 | |
| 1344 | gold_assert(static_cast<section_size_type>(pov - oview) == oview_size); |
| 1345 | |
| 1346 | of->write_output_view(offset, oview_size, oview); |
| 1347 | } |
| 1348 | |
| 1349 | // Create a PLT entry for a global symbol. |
| 1350 | |
| 1351 | template<int size, bool big_endian> |
| 1352 | void |
| 1353 | Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab, |
| 1354 | Layout* layout, |
| 1355 | Symbol* gsym) |
| 1356 | { |
| 1357 | if (gsym->has_plt_offset()) |
| 1358 | return; |
| 1359 | |
| 1360 | if (this->plt_ == NULL) |
| 1361 | { |
| 1362 | // Create the GOT sections first. |
| 1363 | this->got_section(symtab, layout); |
| 1364 | |
| 1365 | this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout); |
| 1366 | layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS, |
| 1367 | (elfcpp::SHF_ALLOC |
| 1368 | | elfcpp::SHF_EXECINSTR |
| 1369 | | elfcpp::SHF_WRITE), |
| 1370 | this->plt_, false); |
| 1371 | |
| 1372 | // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. |
| 1373 | symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL, |
| 1374 | this->plt_, |
| 1375 | 0, 0, elfcpp::STT_OBJECT, |
| 1376 | elfcpp::STB_LOCAL, |
| 1377 | elfcpp::STV_HIDDEN, 0, |
| 1378 | false, false); |
| 1379 | } |
| 1380 | |
| 1381 | this->plt_->add_entry(gsym); |
| 1382 | } |
| 1383 | |
| 1384 | // Create a GOT entry for the TLS module index. |
| 1385 | |
| 1386 | template<int size, bool big_endian> |
| 1387 | unsigned int |
| 1388 | Target_sparc<size, big_endian>::got_mod_index_entry(Symbol_table* symtab, |
| 1389 | Layout* layout, |
| 1390 | Sized_relobj<size, big_endian>* object) |
| 1391 | { |
| 1392 | if (this->got_mod_index_offset_ == -1U) |
| 1393 | { |
| 1394 | gold_assert(symtab != NULL && layout != NULL && object != NULL); |
| 1395 | Reloc_section* rela_dyn = this->rela_dyn_section(layout); |
| 1396 | Output_data_got<size, big_endian>* got; |
| 1397 | unsigned int got_offset; |
| 1398 | |
| 1399 | got = this->got_section(symtab, layout); |
| 1400 | got_offset = got->add_constant(0); |
| 1401 | rela_dyn->add_local(object, 0, |
| 1402 | (size == 64 ? |
| 1403 | elfcpp::R_SPARC_TLS_DTPMOD64 : |
| 1404 | elfcpp::R_SPARC_TLS_DTPMOD32), got, |
| 1405 | got_offset, 0); |
| 1406 | got->add_constant(0); |
| 1407 | this->got_mod_index_offset_ = got_offset; |
| 1408 | } |
| 1409 | return this->got_mod_index_offset_; |
| 1410 | } |
| 1411 | |
| 1412 | // Optimize the TLS relocation type based on what we know about the |
| 1413 | // symbol. IS_FINAL is true if the final address of this symbol is |
| 1414 | // known at link time. |
| 1415 | |
| 1416 | static tls::Tls_optimization |
| 1417 | optimize_tls_reloc(bool is_final, int r_type) |
| 1418 | { |
| 1419 | // If we are generating a shared library, then we can't do anything |
| 1420 | // in the linker. |
| 1421 | if (parameters->options().shared()) |
| 1422 | return tls::TLSOPT_NONE; |
| 1423 | |
| 1424 | switch (r_type) |
| 1425 | { |
| 1426 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic |
| 1427 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 1428 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 1429 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 1430 | // These are General-Dynamic which permits fully general TLS |
| 1431 | // access. Since we know that we are generating an executable, |
| 1432 | // we can convert this to Initial-Exec. If we also know that |
| 1433 | // this is a local symbol, we can further switch to Local-Exec. |
| 1434 | if (is_final) |
| 1435 | return tls::TLSOPT_TO_LE; |
| 1436 | return tls::TLSOPT_TO_IE; |
| 1437 | |
| 1438 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic |
| 1439 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 1440 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 1441 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 1442 | // This is Local-Dynamic, which refers to a local symbol in the |
| 1443 | // dynamic TLS block. Since we know that we generating an |
| 1444 | // executable, we can switch to Local-Exec. |
| 1445 | return tls::TLSOPT_TO_LE; |
| 1446 | |
| 1447 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic |
| 1448 | case elfcpp::R_SPARC_TLS_LDO_LOX10: |
| 1449 | case elfcpp::R_SPARC_TLS_LDO_ADD: |
| 1450 | // Another type of Local-Dynamic relocation. |
| 1451 | return tls::TLSOPT_TO_LE; |
| 1452 | |
| 1453 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec |
| 1454 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 1455 | case elfcpp::R_SPARC_TLS_IE_LD: |
| 1456 | case elfcpp::R_SPARC_TLS_IE_LDX: |
| 1457 | case elfcpp::R_SPARC_TLS_IE_ADD: |
| 1458 | // These are Initial-Exec relocs which get the thread offset |
| 1459 | // from the GOT. If we know that we are linking against the |
| 1460 | // local symbol, we can switch to Local-Exec, which links the |
| 1461 | // thread offset into the instruction. |
| 1462 | if (is_final) |
| 1463 | return tls::TLSOPT_TO_LE; |
| 1464 | return tls::TLSOPT_NONE; |
| 1465 | |
| 1466 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec |
| 1467 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 1468 | // When we already have Local-Exec, there is nothing further we |
| 1469 | // can do. |
| 1470 | return tls::TLSOPT_NONE; |
| 1471 | |
| 1472 | default: |
| 1473 | gold_unreachable(); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | // Generate a PLT entry slot for a call to __tls_get_addr |
| 1478 | template<int size, bool big_endian> |
| 1479 | void |
| 1480 | Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab, |
| 1481 | Layout* layout, |
| 1482 | Target_sparc<size, big_endian>* target) |
| 1483 | { |
| 1484 | Symbol* gsym = target->tls_get_addr_sym(symtab); |
| 1485 | |
| 1486 | target->make_plt_entry(symtab, layout, gsym); |
| 1487 | } |
| 1488 | |
| 1489 | // Report an unsupported relocation against a local symbol. |
| 1490 | |
| 1491 | template<int size, bool big_endian> |
| 1492 | void |
| 1493 | Target_sparc<size, big_endian>::Scan::unsupported_reloc_local( |
| 1494 | Sized_relobj<size, big_endian>* object, |
| 1495 | unsigned int r_type) |
| 1496 | { |
| 1497 | gold_error(_("%s: unsupported reloc %u against local symbol"), |
| 1498 | object->name().c_str(), r_type); |
| 1499 | } |
| 1500 | |
| 1501 | // We are about to emit a dynamic relocation of type R_TYPE. If the |
| 1502 | // dynamic linker does not support it, issue an error. |
| 1503 | |
| 1504 | template<int size, bool big_endian> |
| 1505 | void |
| 1506 | Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type) |
| 1507 | { |
| 1508 | gold_assert(r_type != elfcpp::R_SPARC_NONE); |
| 1509 | |
| 1510 | if (size == 64) |
| 1511 | { |
| 1512 | switch (r_type) |
| 1513 | { |
| 1514 | // These are the relocation types supported by glibc for sparc 64-bit. |
| 1515 | case elfcpp::R_SPARC_RELATIVE: |
| 1516 | case elfcpp::R_SPARC_COPY: |
| 1517 | case elfcpp::R_SPARC_64: |
| 1518 | case elfcpp::R_SPARC_GLOB_DAT: |
| 1519 | case elfcpp::R_SPARC_JMP_SLOT: |
| 1520 | case elfcpp::R_SPARC_TLS_DTPMOD64: |
| 1521 | case elfcpp::R_SPARC_TLS_DTPOFF64: |
| 1522 | case elfcpp::R_SPARC_TLS_TPOFF64: |
| 1523 | case elfcpp::R_SPARC_TLS_LE_HIX22: |
| 1524 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 1525 | case elfcpp::R_SPARC_8: |
| 1526 | case elfcpp::R_SPARC_16: |
| 1527 | case elfcpp::R_SPARC_DISP8: |
| 1528 | case elfcpp::R_SPARC_DISP16: |
| 1529 | case elfcpp::R_SPARC_DISP32: |
| 1530 | case elfcpp::R_SPARC_WDISP30: |
| 1531 | case elfcpp::R_SPARC_LO10: |
| 1532 | case elfcpp::R_SPARC_HI22: |
| 1533 | case elfcpp::R_SPARC_OLO10: |
| 1534 | case elfcpp::R_SPARC_H44: |
| 1535 | case elfcpp::R_SPARC_M44: |
| 1536 | case elfcpp::R_SPARC_L44: |
| 1537 | case elfcpp::R_SPARC_HH22: |
| 1538 | case elfcpp::R_SPARC_HM10: |
| 1539 | case elfcpp::R_SPARC_LM22: |
| 1540 | case elfcpp::R_SPARC_UA16: |
| 1541 | case elfcpp::R_SPARC_UA32: |
| 1542 | case elfcpp::R_SPARC_UA64: |
| 1543 | return; |
| 1544 | |
| 1545 | default: |
| 1546 | break; |
| 1547 | } |
| 1548 | } |
| 1549 | else |
| 1550 | { |
| 1551 | switch (r_type) |
| 1552 | { |
| 1553 | // These are the relocation types supported by glibc for sparc 32-bit. |
| 1554 | case elfcpp::R_SPARC_RELATIVE: |
| 1555 | case elfcpp::R_SPARC_COPY: |
| 1556 | case elfcpp::R_SPARC_GLOB_DAT: |
| 1557 | case elfcpp::R_SPARC_32: |
| 1558 | case elfcpp::R_SPARC_JMP_SLOT: |
| 1559 | case elfcpp::R_SPARC_TLS_DTPMOD32: |
| 1560 | case elfcpp::R_SPARC_TLS_DTPOFF32: |
| 1561 | case elfcpp::R_SPARC_TLS_TPOFF32: |
| 1562 | case elfcpp::R_SPARC_TLS_LE_HIX22: |
| 1563 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 1564 | case elfcpp::R_SPARC_8: |
| 1565 | case elfcpp::R_SPARC_16: |
| 1566 | case elfcpp::R_SPARC_DISP8: |
| 1567 | case elfcpp::R_SPARC_DISP16: |
| 1568 | case elfcpp::R_SPARC_DISP32: |
| 1569 | case elfcpp::R_SPARC_LO10: |
| 1570 | case elfcpp::R_SPARC_WDISP30: |
| 1571 | case elfcpp::R_SPARC_HI22: |
| 1572 | case elfcpp::R_SPARC_UA16: |
| 1573 | case elfcpp::R_SPARC_UA32: |
| 1574 | return; |
| 1575 | |
| 1576 | default: |
| 1577 | break; |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | // This prevents us from issuing more than one error per reloc |
| 1582 | // section. But we can still wind up issuing more than one |
| 1583 | // error per object file. |
| 1584 | if (this->issued_non_pic_error_) |
| 1585 | return; |
| 1586 | gold_assert(parameters->options().output_is_position_independent()); |
| 1587 | object->error(_("requires unsupported dynamic reloc; " |
| 1588 | "recompile with -fPIC")); |
| 1589 | this->issued_non_pic_error_ = true; |
| 1590 | return; |
| 1591 | } |
| 1592 | |
| 1593 | // Scan a relocation for a local symbol. |
| 1594 | |
| 1595 | template<int size, bool big_endian> |
| 1596 | inline void |
| 1597 | Target_sparc<size, big_endian>::Scan::local( |
| 1598 | Symbol_table* symtab, |
| 1599 | Layout* layout, |
| 1600 | Target_sparc<size, big_endian>* target, |
| 1601 | Sized_relobj<size, big_endian>* object, |
| 1602 | unsigned int data_shndx, |
| 1603 | Output_section* output_section, |
| 1604 | const elfcpp::Rela<size, big_endian>& reloc, |
| 1605 | unsigned int r_type, |
| 1606 | const elfcpp::Sym<size, big_endian>& lsym) |
| 1607 | { |
| 1608 | unsigned int orig_r_type = r_type; |
| 1609 | |
| 1610 | r_type &= 0xff; |
| 1611 | switch (r_type) |
| 1612 | { |
| 1613 | case elfcpp::R_SPARC_NONE: |
| 1614 | case elfcpp::R_SPARC_REGISTER: |
| 1615 | case elfcpp::R_SPARC_GNU_VTINHERIT: |
| 1616 | case elfcpp::R_SPARC_GNU_VTENTRY: |
| 1617 | break; |
| 1618 | |
| 1619 | case elfcpp::R_SPARC_64: |
| 1620 | case elfcpp::R_SPARC_32: |
| 1621 | // If building a shared library (or a position-independent |
| 1622 | // executable), we need to create a dynamic relocation for |
| 1623 | // this location. The relocation applied at link time will |
| 1624 | // apply the link-time value, so we flag the location with |
| 1625 | // an R_SPARC_RELATIVE relocation so the dynamic loader can |
| 1626 | // relocate it easily. |
| 1627 | if (parameters->options().output_is_position_independent()) |
| 1628 | { |
| 1629 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 1630 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); |
| 1631 | rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE, |
| 1632 | output_section, data_shndx, |
| 1633 | reloc.get_r_offset(), |
| 1634 | reloc.get_r_addend()); |
| 1635 | } |
| 1636 | break; |
| 1637 | |
| 1638 | case elfcpp::R_SPARC_HIX22: |
| 1639 | case elfcpp::R_SPARC_LOX10: |
| 1640 | case elfcpp::R_SPARC_H44: |
| 1641 | case elfcpp::R_SPARC_M44: |
| 1642 | case elfcpp::R_SPARC_L44: |
| 1643 | case elfcpp::R_SPARC_HH22: |
| 1644 | case elfcpp::R_SPARC_HM10: |
| 1645 | case elfcpp::R_SPARC_LM22: |
| 1646 | case elfcpp::R_SPARC_UA64: |
| 1647 | case elfcpp::R_SPARC_UA32: |
| 1648 | case elfcpp::R_SPARC_UA16: |
| 1649 | case elfcpp::R_SPARC_HI22: |
| 1650 | case elfcpp::R_SPARC_LO10: |
| 1651 | case elfcpp::R_SPARC_OLO10: |
| 1652 | case elfcpp::R_SPARC_16: |
| 1653 | case elfcpp::R_SPARC_11: |
| 1654 | case elfcpp::R_SPARC_10: |
| 1655 | case elfcpp::R_SPARC_8: |
| 1656 | case elfcpp::R_SPARC_7: |
| 1657 | case elfcpp::R_SPARC_6: |
| 1658 | case elfcpp::R_SPARC_5: |
| 1659 | // If building a shared library (or a position-independent |
| 1660 | // executable), we need to create a dynamic relocation for |
| 1661 | // this location. |
| 1662 | if (parameters->options().output_is_position_independent()) |
| 1663 | { |
| 1664 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 1665 | |
| 1666 | check_non_pic(object, r_type); |
| 1667 | if (lsym.get_st_type() != elfcpp::STT_SECTION) |
| 1668 | { |
| 1669 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); |
| 1670 | rela_dyn->add_local(object, r_sym, orig_r_type, output_section, |
| 1671 | data_shndx, reloc.get_r_offset(), |
| 1672 | reloc.get_r_addend()); |
| 1673 | } |
| 1674 | else |
| 1675 | { |
| 1676 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); |
| 1677 | gold_assert(lsym.get_st_value() == 0); |
| 1678 | rela_dyn->add_local_relative(object, r_sym, orig_r_type, |
| 1679 | output_section, data_shndx, |
| 1680 | reloc.get_r_offset(), |
| 1681 | reloc.get_r_addend()); |
| 1682 | } |
| 1683 | } |
| 1684 | break; |
| 1685 | |
| 1686 | case elfcpp::R_SPARC_WDISP30: |
| 1687 | case elfcpp::R_SPARC_WDISP22: |
| 1688 | case elfcpp::R_SPARC_WDISP19: |
| 1689 | case elfcpp::R_SPARC_WDISP16: |
| 1690 | case elfcpp::R_SPARC_DISP8: |
| 1691 | case elfcpp::R_SPARC_DISP16: |
| 1692 | case elfcpp::R_SPARC_DISP32: |
| 1693 | case elfcpp::R_SPARC_DISP64: |
| 1694 | case elfcpp::R_SPARC_PC10: |
| 1695 | case elfcpp::R_SPARC_PC22: |
| 1696 | break; |
| 1697 | |
| 1698 | case elfcpp::R_SPARC_GOT10: |
| 1699 | case elfcpp::R_SPARC_GOT13: |
| 1700 | case elfcpp::R_SPARC_GOT22: |
| 1701 | { |
| 1702 | // The symbol requires a GOT entry. |
| 1703 | Output_data_got<size, big_endian>* got; |
| 1704 | unsigned int r_sym; |
| 1705 | |
| 1706 | got = target->got_section(symtab, layout); |
| 1707 | r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); |
| 1708 | |
| 1709 | // If we are generating a shared object, we need to add a |
| 1710 | // dynamic relocation for this symbol's GOT entry. |
| 1711 | if (parameters->options().output_is_position_independent()) |
| 1712 | { |
| 1713 | if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD)) |
| 1714 | { |
| 1715 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 1716 | unsigned int off; |
| 1717 | |
| 1718 | off = got->add_constant(0); |
| 1719 | object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off); |
| 1720 | rela_dyn->add_local_relative(object, r_sym, |
| 1721 | elfcpp::R_SPARC_RELATIVE, |
| 1722 | got, off, 0); |
| 1723 | } |
| 1724 | } |
| 1725 | else |
| 1726 | got->add_local(object, r_sym, GOT_TYPE_STANDARD); |
| 1727 | } |
| 1728 | break; |
| 1729 | |
| 1730 | // These are initial TLS relocs, which are expected when |
| 1731 | // linking. |
| 1732 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic |
| 1733 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 1734 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 1735 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 1736 | case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic |
| 1737 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 1738 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 1739 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 1740 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic |
| 1741 | case elfcpp::R_SPARC_TLS_LDO_LOX10: |
| 1742 | case elfcpp::R_SPARC_TLS_LDO_ADD: |
| 1743 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec |
| 1744 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 1745 | case elfcpp::R_SPARC_TLS_IE_LD: |
| 1746 | case elfcpp::R_SPARC_TLS_IE_LDX: |
| 1747 | case elfcpp::R_SPARC_TLS_IE_ADD: |
| 1748 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec |
| 1749 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 1750 | { |
| 1751 | bool output_is_shared = parameters->options().shared(); |
| 1752 | const tls::Tls_optimization optimized_type |
| 1753 | = optimize_tls_reloc(!output_is_shared, r_type); |
| 1754 | switch (r_type) |
| 1755 | { |
| 1756 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic |
| 1757 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 1758 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 1759 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 1760 | if (optimized_type == tls::TLSOPT_NONE) |
| 1761 | { |
| 1762 | // Create a pair of GOT entries for the module index and |
| 1763 | // dtv-relative offset. |
| 1764 | Output_data_got<size, big_endian>* got |
| 1765 | = target->got_section(symtab, layout); |
| 1766 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); |
| 1767 | unsigned int shndx = lsym.get_st_shndx(); |
| 1768 | bool is_ordinary; |
| 1769 | shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary); |
| 1770 | if (!is_ordinary) |
| 1771 | object->error(_("local symbol %u has bad shndx %u"), |
| 1772 | r_sym, shndx); |
| 1773 | else |
| 1774 | got->add_local_pair_with_rela(object, r_sym, |
| 1775 | lsym.get_st_shndx(), |
| 1776 | GOT_TYPE_TLS_PAIR, |
| 1777 | target->rela_dyn_section(layout), |
| 1778 | (size == 64 |
| 1779 | ? elfcpp::R_SPARC_TLS_DTPMOD64 |
| 1780 | : elfcpp::R_SPARC_TLS_DTPMOD32), |
| 1781 | 0); |
| 1782 | if (r_type == elfcpp::R_SPARC_TLS_GD_CALL) |
| 1783 | generate_tls_call(symtab, layout, target); |
| 1784 | } |
| 1785 | else if (optimized_type != tls::TLSOPT_TO_LE) |
| 1786 | unsupported_reloc_local(object, r_type); |
| 1787 | break; |
| 1788 | |
| 1789 | case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic |
| 1790 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 1791 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 1792 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 1793 | if (optimized_type == tls::TLSOPT_NONE) |
| 1794 | { |
| 1795 | // Create a GOT entry for the module index. |
| 1796 | target->got_mod_index_entry(symtab, layout, object); |
| 1797 | |
| 1798 | if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL) |
| 1799 | generate_tls_call(symtab, layout, target); |
| 1800 | } |
| 1801 | else if (optimized_type != tls::TLSOPT_TO_LE) |
| 1802 | unsupported_reloc_local(object, r_type); |
| 1803 | break; |
| 1804 | |
| 1805 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic |
| 1806 | case elfcpp::R_SPARC_TLS_LDO_LOX10: |
| 1807 | case elfcpp::R_SPARC_TLS_LDO_ADD: |
| 1808 | break; |
| 1809 | |
| 1810 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec |
| 1811 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 1812 | case elfcpp::R_SPARC_TLS_IE_LD: |
| 1813 | case elfcpp::R_SPARC_TLS_IE_LDX: |
| 1814 | case elfcpp::R_SPARC_TLS_IE_ADD: |
| 1815 | layout->set_has_static_tls(); |
| 1816 | if (optimized_type == tls::TLSOPT_NONE) |
| 1817 | { |
| 1818 | // Create a GOT entry for the tp-relative offset. |
| 1819 | Output_data_got<size, big_endian>* got |
| 1820 | = target->got_section(symtab, layout); |
| 1821 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); |
| 1822 | |
| 1823 | if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET)) |
| 1824 | { |
| 1825 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 1826 | unsigned int off = got->add_constant(0); |
| 1827 | |
| 1828 | object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, |
| 1829 | off); |
| 1830 | rela_dyn->add_local_relative(object, r_sym, |
| 1831 | (size == 64 ? |
| 1832 | elfcpp::R_SPARC_TLS_TPOFF64 : |
| 1833 | elfcpp::R_SPARC_TLS_TPOFF32), |
| 1834 | got, off, 0); |
| 1835 | } |
| 1836 | } |
| 1837 | else if (optimized_type != tls::TLSOPT_TO_LE) |
| 1838 | unsupported_reloc_local(object, r_type); |
| 1839 | break; |
| 1840 | |
| 1841 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec |
| 1842 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 1843 | layout->set_has_static_tls(); |
| 1844 | if (output_is_shared) |
| 1845 | { |
| 1846 | // We need to create a dynamic relocation. |
| 1847 | gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION); |
| 1848 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); |
| 1849 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 1850 | rela_dyn->add_local_relative(object, r_sym, r_type, |
| 1851 | output_section, data_shndx, |
| 1852 | reloc.get_r_offset(), 0); |
| 1853 | } |
| 1854 | break; |
| 1855 | } |
| 1856 | } |
| 1857 | break; |
| 1858 | |
| 1859 | // These are relocations which should only be seen by the |
| 1860 | // dynamic linker, and should never be seen here. |
| 1861 | case elfcpp::R_SPARC_COPY: |
| 1862 | case elfcpp::R_SPARC_GLOB_DAT: |
| 1863 | case elfcpp::R_SPARC_JMP_SLOT: |
| 1864 | case elfcpp::R_SPARC_RELATIVE: |
| 1865 | case elfcpp::R_SPARC_TLS_DTPMOD64: |
| 1866 | case elfcpp::R_SPARC_TLS_DTPMOD32: |
| 1867 | case elfcpp::R_SPARC_TLS_DTPOFF64: |
| 1868 | case elfcpp::R_SPARC_TLS_DTPOFF32: |
| 1869 | case elfcpp::R_SPARC_TLS_TPOFF64: |
| 1870 | case elfcpp::R_SPARC_TLS_TPOFF32: |
| 1871 | gold_error(_("%s: unexpected reloc %u in object file"), |
| 1872 | object->name().c_str(), r_type); |
| 1873 | break; |
| 1874 | |
| 1875 | default: |
| 1876 | unsupported_reloc_local(object, r_type); |
| 1877 | break; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | // Report an unsupported relocation against a global symbol. |
| 1882 | |
| 1883 | template<int size, bool big_endian> |
| 1884 | void |
| 1885 | Target_sparc<size, big_endian>::Scan::unsupported_reloc_global( |
| 1886 | Sized_relobj<size, big_endian>* object, |
| 1887 | unsigned int r_type, |
| 1888 | Symbol* gsym) |
| 1889 | { |
| 1890 | gold_error(_("%s: unsupported reloc %u against global symbol %s"), |
| 1891 | object->name().c_str(), r_type, gsym->demangled_name().c_str()); |
| 1892 | } |
| 1893 | |
| 1894 | // Scan a relocation for a global symbol. |
| 1895 | |
| 1896 | template<int size, bool big_endian> |
| 1897 | inline void |
| 1898 | Target_sparc<size, big_endian>::Scan::global( |
| 1899 | Symbol_table* symtab, |
| 1900 | Layout* layout, |
| 1901 | Target_sparc<size, big_endian>* target, |
| 1902 | Sized_relobj<size, big_endian>* object, |
| 1903 | unsigned int data_shndx, |
| 1904 | Output_section* output_section, |
| 1905 | const elfcpp::Rela<size, big_endian>& reloc, |
| 1906 | unsigned int r_type, |
| 1907 | Symbol* gsym) |
| 1908 | { |
| 1909 | unsigned int orig_r_type = r_type; |
| 1910 | |
| 1911 | // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got |
| 1912 | // section. We check here to avoid creating a dynamic reloc against |
| 1913 | // _GLOBAL_OFFSET_TABLE_. |
| 1914 | if (!target->has_got_section() |
| 1915 | && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0) |
| 1916 | target->got_section(symtab, layout); |
| 1917 | |
| 1918 | r_type &= 0xff; |
| 1919 | switch (r_type) |
| 1920 | { |
| 1921 | case elfcpp::R_SPARC_NONE: |
| 1922 | case elfcpp::R_SPARC_REGISTER: |
| 1923 | case elfcpp::R_SPARC_GNU_VTINHERIT: |
| 1924 | case elfcpp::R_SPARC_GNU_VTENTRY: |
| 1925 | break; |
| 1926 | |
| 1927 | case elfcpp::R_SPARC_PLT64: |
| 1928 | case elfcpp::R_SPARC_PLT32: |
| 1929 | case elfcpp::R_SPARC_HIPLT22: |
| 1930 | case elfcpp::R_SPARC_LOPLT10: |
| 1931 | case elfcpp::R_SPARC_PCPLT32: |
| 1932 | case elfcpp::R_SPARC_PCPLT22: |
| 1933 | case elfcpp::R_SPARC_PCPLT10: |
| 1934 | case elfcpp::R_SPARC_WPLT30: |
| 1935 | // If the symbol is fully resolved, this is just a PC32 reloc. |
| 1936 | // Otherwise we need a PLT entry. |
| 1937 | if (gsym->final_value_is_known()) |
| 1938 | break; |
| 1939 | // If building a shared library, we can also skip the PLT entry |
| 1940 | // if the symbol is defined in the output file and is protected |
| 1941 | // or hidden. |
| 1942 | if (gsym->is_defined() |
| 1943 | && !gsym->is_from_dynobj() |
| 1944 | && !gsym->is_preemptible()) |
| 1945 | break; |
| 1946 | target->make_plt_entry(symtab, layout, gsym); |
| 1947 | break; |
| 1948 | |
| 1949 | case elfcpp::R_SPARC_DISP8: |
| 1950 | case elfcpp::R_SPARC_DISP16: |
| 1951 | case elfcpp::R_SPARC_DISP32: |
| 1952 | case elfcpp::R_SPARC_DISP64: |
| 1953 | case elfcpp::R_SPARC_PC_HH22: |
| 1954 | case elfcpp::R_SPARC_PC_HM10: |
| 1955 | case elfcpp::R_SPARC_PC_LM22: |
| 1956 | case elfcpp::R_SPARC_PC10: |
| 1957 | case elfcpp::R_SPARC_PC22: |
| 1958 | case elfcpp::R_SPARC_WDISP30: |
| 1959 | case elfcpp::R_SPARC_WDISP22: |
| 1960 | case elfcpp::R_SPARC_WDISP19: |
| 1961 | case elfcpp::R_SPARC_WDISP16: |
| 1962 | { |
| 1963 | if (gsym->needs_plt_entry()) |
| 1964 | target->make_plt_entry(symtab, layout, gsym); |
| 1965 | // Make a dynamic relocation if necessary. |
| 1966 | int flags = Symbol::NON_PIC_REF; |
| 1967 | if (gsym->type() == elfcpp::STT_FUNC) |
| 1968 | flags |= Symbol::FUNCTION_CALL; |
| 1969 | if (gsym->needs_dynamic_reloc(flags)) |
| 1970 | { |
| 1971 | if (gsym->may_need_copy_reloc()) |
| 1972 | { |
| 1973 | target->copy_reloc(symtab, layout, object, |
| 1974 | data_shndx, output_section, gsym, |
| 1975 | reloc); |
| 1976 | } |
| 1977 | else |
| 1978 | { |
| 1979 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 1980 | check_non_pic(object, r_type); |
| 1981 | rela_dyn->add_global(gsym, orig_r_type, output_section, object, |
| 1982 | data_shndx, reloc.get_r_offset(), |
| 1983 | reloc.get_r_addend()); |
| 1984 | } |
| 1985 | } |
| 1986 | } |
| 1987 | break; |
| 1988 | |
| 1989 | case elfcpp::R_SPARC_UA64: |
| 1990 | case elfcpp::R_SPARC_64: |
| 1991 | case elfcpp::R_SPARC_HIX22: |
| 1992 | case elfcpp::R_SPARC_LOX10: |
| 1993 | case elfcpp::R_SPARC_H44: |
| 1994 | case elfcpp::R_SPARC_M44: |
| 1995 | case elfcpp::R_SPARC_L44: |
| 1996 | case elfcpp::R_SPARC_HH22: |
| 1997 | case elfcpp::R_SPARC_HM10: |
| 1998 | case elfcpp::R_SPARC_LM22: |
| 1999 | case elfcpp::R_SPARC_HI22: |
| 2000 | case elfcpp::R_SPARC_LO10: |
| 2001 | case elfcpp::R_SPARC_OLO10: |
| 2002 | case elfcpp::R_SPARC_UA32: |
| 2003 | case elfcpp::R_SPARC_32: |
| 2004 | case elfcpp::R_SPARC_UA16: |
| 2005 | case elfcpp::R_SPARC_16: |
| 2006 | case elfcpp::R_SPARC_11: |
| 2007 | case elfcpp::R_SPARC_10: |
| 2008 | case elfcpp::R_SPARC_8: |
| 2009 | case elfcpp::R_SPARC_7: |
| 2010 | case elfcpp::R_SPARC_6: |
| 2011 | case elfcpp::R_SPARC_5: |
| 2012 | { |
| 2013 | // Make a PLT entry if necessary. |
| 2014 | if (gsym->needs_plt_entry()) |
| 2015 | { |
| 2016 | target->make_plt_entry(symtab, layout, gsym); |
| 2017 | // Since this is not a PC-relative relocation, we may be |
| 2018 | // taking the address of a function. In that case we need to |
| 2019 | // set the entry in the dynamic symbol table to the address of |
| 2020 | // the PLT entry. |
| 2021 | if (gsym->is_from_dynobj() && !parameters->options().shared()) |
| 2022 | gsym->set_needs_dynsym_value(); |
| 2023 | } |
| 2024 | // Make a dynamic relocation if necessary. |
| 2025 | if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF)) |
| 2026 | { |
| 2027 | if (gsym->may_need_copy_reloc()) |
| 2028 | { |
| 2029 | target->copy_reloc(symtab, layout, object, |
| 2030 | data_shndx, output_section, gsym, reloc); |
| 2031 | } |
| 2032 | else if ((r_type == elfcpp::R_SPARC_32 |
| 2033 | || r_type == elfcpp::R_SPARC_64) |
| 2034 | && gsym->can_use_relative_reloc(false)) |
| 2035 | { |
| 2036 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 2037 | rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE, |
| 2038 | output_section, object, |
| 2039 | data_shndx, reloc.get_r_offset(), |
| 2040 | reloc.get_r_addend()); |
| 2041 | } |
| 2042 | else |
| 2043 | { |
| 2044 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 2045 | |
| 2046 | check_non_pic(object, r_type); |
| 2047 | if (gsym->is_from_dynobj() |
| 2048 | || gsym->is_undefined() |
| 2049 | || gsym->is_preemptible()) |
| 2050 | rela_dyn->add_global(gsym, orig_r_type, output_section, |
| 2051 | object, data_shndx, |
| 2052 | reloc.get_r_offset(), |
| 2053 | reloc.get_r_addend()); |
| 2054 | else |
| 2055 | rela_dyn->add_global_relative(gsym, orig_r_type, |
| 2056 | output_section, object, |
| 2057 | data_shndx, |
| 2058 | reloc.get_r_offset(), |
| 2059 | reloc.get_r_addend()); |
| 2060 | } |
| 2061 | } |
| 2062 | } |
| 2063 | break; |
| 2064 | |
| 2065 | case elfcpp::R_SPARC_GOT10: |
| 2066 | case elfcpp::R_SPARC_GOT13: |
| 2067 | case elfcpp::R_SPARC_GOT22: |
| 2068 | { |
| 2069 | // The symbol requires a GOT entry. |
| 2070 | Output_data_got<size, big_endian>* got; |
| 2071 | |
| 2072 | got = target->got_section(symtab, layout); |
| 2073 | if (gsym->final_value_is_known()) |
| 2074 | got->add_global(gsym, GOT_TYPE_STANDARD); |
| 2075 | else |
| 2076 | { |
| 2077 | // If this symbol is not fully resolved, we need to add a |
| 2078 | // dynamic relocation for it. |
| 2079 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 2080 | if (gsym->is_from_dynobj() |
| 2081 | || gsym->is_undefined() |
| 2082 | || gsym->is_preemptible()) |
| 2083 | got->add_global_with_rela(gsym, GOT_TYPE_STANDARD, rela_dyn, |
| 2084 | elfcpp::R_SPARC_GLOB_DAT); |
| 2085 | else if (!gsym->has_got_offset(GOT_TYPE_STANDARD)) |
| 2086 | { |
| 2087 | unsigned int off = got->add_constant(0); |
| 2088 | |
| 2089 | gsym->set_got_offset(GOT_TYPE_STANDARD, off); |
| 2090 | rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE, |
| 2091 | got, off, 0); |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | break; |
| 2096 | |
| 2097 | // These are initial tls relocs, which are expected when |
| 2098 | // linking. |
| 2099 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic |
| 2100 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 2101 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 2102 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 2103 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic |
| 2104 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 2105 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 2106 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 2107 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic |
| 2108 | case elfcpp::R_SPARC_TLS_LDO_LOX10: |
| 2109 | case elfcpp::R_SPARC_TLS_LDO_ADD: |
| 2110 | case elfcpp::R_SPARC_TLS_LE_HIX22: |
| 2111 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 2112 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec |
| 2113 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 2114 | case elfcpp::R_SPARC_TLS_IE_LD: |
| 2115 | case elfcpp::R_SPARC_TLS_IE_LDX: |
| 2116 | case elfcpp::R_SPARC_TLS_IE_ADD: |
| 2117 | { |
| 2118 | const bool is_final = gsym->final_value_is_known(); |
| 2119 | const tls::Tls_optimization optimized_type |
| 2120 | = optimize_tls_reloc(is_final, r_type); |
| 2121 | switch (r_type) |
| 2122 | { |
| 2123 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic |
| 2124 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 2125 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 2126 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 2127 | if (optimized_type == tls::TLSOPT_NONE) |
| 2128 | { |
| 2129 | // Create a pair of GOT entries for the module index and |
| 2130 | // dtv-relative offset. |
| 2131 | Output_data_got<size, big_endian>* got |
| 2132 | = target->got_section(symtab, layout); |
| 2133 | got->add_global_pair_with_rela(gsym, GOT_TYPE_TLS_PAIR, |
| 2134 | target->rela_dyn_section(layout), |
| 2135 | (size == 64 ? |
| 2136 | elfcpp::R_SPARC_TLS_DTPMOD64 : |
| 2137 | elfcpp::R_SPARC_TLS_DTPMOD32), |
| 2138 | (size == 64 ? |
| 2139 | elfcpp::R_SPARC_TLS_DTPOFF64 : |
| 2140 | elfcpp::R_SPARC_TLS_DTPOFF32)); |
| 2141 | |
| 2142 | // Emit R_SPARC_WPLT30 against "__tls_get_addr" |
| 2143 | if (r_type == elfcpp::R_SPARC_TLS_GD_CALL) |
| 2144 | generate_tls_call(symtab, layout, target); |
| 2145 | } |
| 2146 | else if (optimized_type == tls::TLSOPT_TO_IE) |
| 2147 | { |
| 2148 | // Create a GOT entry for the tp-relative offset. |
| 2149 | Output_data_got<size, big_endian>* got |
| 2150 | = target->got_section(symtab, layout); |
| 2151 | got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET, |
| 2152 | target->rela_dyn_section(layout), |
| 2153 | (size == 64 ? |
| 2154 | elfcpp::R_SPARC_TLS_TPOFF64 : |
| 2155 | elfcpp::R_SPARC_TLS_TPOFF32)); |
| 2156 | } |
| 2157 | else if (optimized_type != tls::TLSOPT_TO_LE) |
| 2158 | unsupported_reloc_global(object, r_type, gsym); |
| 2159 | break; |
| 2160 | |
| 2161 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic |
| 2162 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 2163 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 2164 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 2165 | if (optimized_type == tls::TLSOPT_NONE) |
| 2166 | { |
| 2167 | // Create a GOT entry for the module index. |
| 2168 | target->got_mod_index_entry(symtab, layout, object); |
| 2169 | |
| 2170 | if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL) |
| 2171 | generate_tls_call(symtab, layout, target); |
| 2172 | } |
| 2173 | else if (optimized_type != tls::TLSOPT_TO_LE) |
| 2174 | unsupported_reloc_global(object, r_type, gsym); |
| 2175 | break; |
| 2176 | |
| 2177 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic |
| 2178 | case elfcpp::R_SPARC_TLS_LDO_LOX10: |
| 2179 | case elfcpp::R_SPARC_TLS_LDO_ADD: |
| 2180 | break; |
| 2181 | |
| 2182 | case elfcpp::R_SPARC_TLS_LE_HIX22: |
| 2183 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 2184 | layout->set_has_static_tls(); |
| 2185 | if (parameters->options().shared()) |
| 2186 | { |
| 2187 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
| 2188 | rela_dyn->add_global_relative(gsym, orig_r_type, |
| 2189 | output_section, object, |
| 2190 | data_shndx, reloc.get_r_offset(), |
| 2191 | 0); |
| 2192 | } |
| 2193 | break; |
| 2194 | |
| 2195 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec |
| 2196 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 2197 | case elfcpp::R_SPARC_TLS_IE_LD: |
| 2198 | case elfcpp::R_SPARC_TLS_IE_LDX: |
| 2199 | case elfcpp::R_SPARC_TLS_IE_ADD: |
| 2200 | layout->set_has_static_tls(); |
| 2201 | if (optimized_type == tls::TLSOPT_NONE) |
| 2202 | { |
| 2203 | // Create a GOT entry for the tp-relative offset. |
| 2204 | Output_data_got<size, big_endian>* got |
| 2205 | = target->got_section(symtab, layout); |
| 2206 | got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET, |
| 2207 | target->rela_dyn_section(layout), |
| 2208 | (size == 64 ? |
| 2209 | elfcpp::R_SPARC_TLS_TPOFF64 : |
| 2210 | elfcpp::R_SPARC_TLS_TPOFF32)); |
| 2211 | } |
| 2212 | else if (optimized_type != tls::TLSOPT_TO_LE) |
| 2213 | unsupported_reloc_global(object, r_type, gsym); |
| 2214 | break; |
| 2215 | } |
| 2216 | } |
| 2217 | break; |
| 2218 | |
| 2219 | // These are relocations which should only be seen by the |
| 2220 | // dynamic linker, and should never be seen here. |
| 2221 | case elfcpp::R_SPARC_COPY: |
| 2222 | case elfcpp::R_SPARC_GLOB_DAT: |
| 2223 | case elfcpp::R_SPARC_JMP_SLOT: |
| 2224 | case elfcpp::R_SPARC_RELATIVE: |
| 2225 | case elfcpp::R_SPARC_TLS_DTPMOD64: |
| 2226 | case elfcpp::R_SPARC_TLS_DTPMOD32: |
| 2227 | case elfcpp::R_SPARC_TLS_DTPOFF64: |
| 2228 | case elfcpp::R_SPARC_TLS_DTPOFF32: |
| 2229 | case elfcpp::R_SPARC_TLS_TPOFF64: |
| 2230 | case elfcpp::R_SPARC_TLS_TPOFF32: |
| 2231 | gold_error(_("%s: unexpected reloc %u in object file"), |
| 2232 | object->name().c_str(), r_type); |
| 2233 | break; |
| 2234 | |
| 2235 | default: |
| 2236 | unsupported_reloc_global(object, r_type, gsym); |
| 2237 | break; |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | // Process relocations for gc. |
| 2242 | |
| 2243 | template<int size, bool big_endian> |
| 2244 | void |
| 2245 | Target_sparc<size, big_endian>::gc_process_relocs( |
| 2246 | Symbol_table* symtab, |
| 2247 | Layout* layout, |
| 2248 | Sized_relobj<size, big_endian>* object, |
| 2249 | unsigned int data_shndx, |
| 2250 | unsigned int, |
| 2251 | const unsigned char* prelocs, |
| 2252 | size_t reloc_count, |
| 2253 | Output_section* output_section, |
| 2254 | bool needs_special_offset_handling, |
| 2255 | size_t local_symbol_count, |
| 2256 | const unsigned char* plocal_symbols) |
| 2257 | { |
| 2258 | typedef Target_sparc<size, big_endian> Sparc; |
| 2259 | typedef typename Target_sparc<size, big_endian>::Scan Scan; |
| 2260 | |
| 2261 | gold::gc_process_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>( |
| 2262 | symtab, |
| 2263 | layout, |
| 2264 | this, |
| 2265 | object, |
| 2266 | data_shndx, |
| 2267 | prelocs, |
| 2268 | reloc_count, |
| 2269 | output_section, |
| 2270 | needs_special_offset_handling, |
| 2271 | local_symbol_count, |
| 2272 | plocal_symbols); |
| 2273 | } |
| 2274 | |
| 2275 | // Scan relocations for a section. |
| 2276 | |
| 2277 | template<int size, bool big_endian> |
| 2278 | void |
| 2279 | Target_sparc<size, big_endian>::scan_relocs( |
| 2280 | Symbol_table* symtab, |
| 2281 | Layout* layout, |
| 2282 | Sized_relobj<size, big_endian>* object, |
| 2283 | unsigned int data_shndx, |
| 2284 | unsigned int sh_type, |
| 2285 | const unsigned char* prelocs, |
| 2286 | size_t reloc_count, |
| 2287 | Output_section* output_section, |
| 2288 | bool needs_special_offset_handling, |
| 2289 | size_t local_symbol_count, |
| 2290 | const unsigned char* plocal_symbols) |
| 2291 | { |
| 2292 | typedef Target_sparc<size, big_endian> Sparc; |
| 2293 | typedef typename Target_sparc<size, big_endian>::Scan Scan; |
| 2294 | |
| 2295 | if (sh_type == elfcpp::SHT_REL) |
| 2296 | { |
| 2297 | gold_error(_("%s: unsupported REL reloc section"), |
| 2298 | object->name().c_str()); |
| 2299 | return; |
| 2300 | } |
| 2301 | |
| 2302 | gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>( |
| 2303 | symtab, |
| 2304 | layout, |
| 2305 | this, |
| 2306 | object, |
| 2307 | data_shndx, |
| 2308 | prelocs, |
| 2309 | reloc_count, |
| 2310 | output_section, |
| 2311 | needs_special_offset_handling, |
| 2312 | local_symbol_count, |
| 2313 | plocal_symbols); |
| 2314 | } |
| 2315 | |
| 2316 | // Finalize the sections. |
| 2317 | |
| 2318 | template<int size, bool big_endian> |
| 2319 | void |
| 2320 | Target_sparc<size, big_endian>::do_finalize_sections( |
| 2321 | Layout* layout, |
| 2322 | const Input_objects*) |
| 2323 | { |
| 2324 | // Fill in some more dynamic tags. |
| 2325 | Output_data_dynamic* const odyn = layout->dynamic_data(); |
| 2326 | if (odyn != NULL) |
| 2327 | { |
| 2328 | if (this->plt_ != NULL |
| 2329 | && this->plt_->output_section() != NULL) |
| 2330 | { |
| 2331 | const Output_data* od = this->plt_->rel_plt(); |
| 2332 | odyn->add_section_size(elfcpp::DT_PLTRELSZ, od); |
| 2333 | odyn->add_section_address(elfcpp::DT_JMPREL, od); |
| 2334 | odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA); |
| 2335 | |
| 2336 | odyn->add_section_address(elfcpp::DT_PLTGOT, this->plt_); |
| 2337 | } |
| 2338 | |
| 2339 | if (this->rela_dyn_ != NULL |
| 2340 | && this->rela_dyn_->output_section() != NULL) |
| 2341 | { |
| 2342 | const Output_data* od = this->rela_dyn_; |
| 2343 | odyn->add_section_address(elfcpp::DT_RELA, od); |
| 2344 | odyn->add_section_size(elfcpp::DT_RELASZ, od); |
| 2345 | odyn->add_constant(elfcpp::DT_RELAENT, |
| 2346 | elfcpp::Elf_sizes<size>::rela_size); |
| 2347 | } |
| 2348 | |
| 2349 | if (!parameters->options().shared()) |
| 2350 | { |
| 2351 | // The value of the DT_DEBUG tag is filled in by the dynamic |
| 2352 | // linker at run time, and used by the debugger. |
| 2353 | odyn->add_constant(elfcpp::DT_DEBUG, 0); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | // Emit any relocs we saved in an attempt to avoid generating COPY |
| 2358 | // relocs. |
| 2359 | if (this->copy_relocs_.any_saved_relocs()) |
| 2360 | this->copy_relocs_.emit(this->rela_dyn_section(layout)); |
| 2361 | } |
| 2362 | |
| 2363 | // Perform a relocation. |
| 2364 | |
| 2365 | template<int size, bool big_endian> |
| 2366 | inline bool |
| 2367 | Target_sparc<size, big_endian>::Relocate::relocate( |
| 2368 | const Relocate_info<size, big_endian>* relinfo, |
| 2369 | Target_sparc* target, |
| 2370 | Output_section*, |
| 2371 | size_t relnum, |
| 2372 | const elfcpp::Rela<size, big_endian>& rela, |
| 2373 | unsigned int r_type, |
| 2374 | const Sized_symbol<size>* gsym, |
| 2375 | const Symbol_value<size>* psymval, |
| 2376 | unsigned char* view, |
| 2377 | typename elfcpp::Elf_types<size>::Elf_Addr address, |
| 2378 | section_size_type view_size) |
| 2379 | { |
| 2380 | r_type &= 0xff; |
| 2381 | |
| 2382 | if (this->ignore_gd_add_) |
| 2383 | { |
| 2384 | if (r_type != elfcpp::R_SPARC_TLS_GD_ADD) |
| 2385 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
| 2386 | _("missing expected TLS relocation")); |
| 2387 | else |
| 2388 | { |
| 2389 | this->ignore_gd_add_ = false; |
| 2390 | return false; |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | typedef Sparc_relocate_functions<size, big_endian> Reloc; |
| 2395 | |
| 2396 | // Pick the value to use for symbols defined in shared objects. |
| 2397 | Symbol_value<size> symval; |
| 2398 | if (gsym != NULL |
| 2399 | && gsym->use_plt_offset(r_type == elfcpp::R_SPARC_DISP8 |
| 2400 | || r_type == elfcpp::R_SPARC_DISP16 |
| 2401 | || r_type == elfcpp::R_SPARC_DISP32 |
| 2402 | || r_type == elfcpp::R_SPARC_DISP64 |
| 2403 | || r_type == elfcpp::R_SPARC_PC_HH22 |
| 2404 | || r_type == elfcpp::R_SPARC_PC_HM10 |
| 2405 | || r_type == elfcpp::R_SPARC_PC_LM22 |
| 2406 | || r_type == elfcpp::R_SPARC_PC10 |
| 2407 | || r_type == elfcpp::R_SPARC_PC22 |
| 2408 | || r_type == elfcpp::R_SPARC_WDISP30 |
| 2409 | || r_type == elfcpp::R_SPARC_WDISP22 |
| 2410 | || r_type == elfcpp::R_SPARC_WDISP19 |
| 2411 | || r_type == elfcpp::R_SPARC_WDISP16)) |
| 2412 | { |
| 2413 | elfcpp::Elf_Xword value; |
| 2414 | |
| 2415 | value = target->plt_section()->address() + gsym->plt_offset(); |
| 2416 | |
| 2417 | symval.set_output_value(value); |
| 2418 | |
| 2419 | psymval = &symval; |
| 2420 | } |
| 2421 | |
| 2422 | const Sized_relobj<size, big_endian>* object = relinfo->object; |
| 2423 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); |
| 2424 | |
| 2425 | // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT |
| 2426 | // pointer points to the beginning, not the end, of the table. |
| 2427 | // So we just use the plain offset. |
| 2428 | bool have_got_offset = false; |
| 2429 | unsigned int got_offset = 0; |
| 2430 | switch (r_type) |
| 2431 | { |
| 2432 | case elfcpp::R_SPARC_GOT10: |
| 2433 | case elfcpp::R_SPARC_GOT13: |
| 2434 | case elfcpp::R_SPARC_GOT22: |
| 2435 | if (gsym != NULL) |
| 2436 | { |
| 2437 | gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD)); |
| 2438 | got_offset = gsym->got_offset(GOT_TYPE_STANDARD); |
| 2439 | } |
| 2440 | else |
| 2441 | { |
| 2442 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); |
| 2443 | gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD)); |
| 2444 | got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD); |
| 2445 | } |
| 2446 | have_got_offset = true; |
| 2447 | break; |
| 2448 | |
| 2449 | default: |
| 2450 | break; |
| 2451 | } |
| 2452 | |
| 2453 | switch (r_type) |
| 2454 | { |
| 2455 | case elfcpp::R_SPARC_NONE: |
| 2456 | case elfcpp::R_SPARC_REGISTER: |
| 2457 | case elfcpp::R_SPARC_GNU_VTINHERIT: |
| 2458 | case elfcpp::R_SPARC_GNU_VTENTRY: |
| 2459 | break; |
| 2460 | |
| 2461 | case elfcpp::R_SPARC_8: |
| 2462 | Relocate_functions<size, big_endian>::rela8(view, object, |
| 2463 | psymval, addend); |
| 2464 | break; |
| 2465 | |
| 2466 | case elfcpp::R_SPARC_16: |
| 2467 | Relocate_functions<size, big_endian>::rela16(view, object, |
| 2468 | psymval, addend); |
| 2469 | break; |
| 2470 | |
| 2471 | case elfcpp::R_SPARC_32: |
| 2472 | if (!parameters->options().output_is_position_independent()) |
| 2473 | Relocate_functions<size, big_endian>::rela32(view, object, |
| 2474 | psymval, addend); |
| 2475 | break; |
| 2476 | |
| 2477 | case elfcpp::R_SPARC_DISP8: |
| 2478 | Reloc::disp8(view, object, psymval, addend, address); |
| 2479 | break; |
| 2480 | |
| 2481 | case elfcpp::R_SPARC_DISP16: |
| 2482 | Reloc::disp16(view, object, psymval, addend, address); |
| 2483 | break; |
| 2484 | |
| 2485 | case elfcpp::R_SPARC_DISP32: |
| 2486 | Reloc::disp32(view, object, psymval, addend, address); |
| 2487 | break; |
| 2488 | |
| 2489 | case elfcpp::R_SPARC_DISP64: |
| 2490 | Reloc::disp64(view, object, psymval, addend, address); |
| 2491 | break; |
| 2492 | |
| 2493 | case elfcpp::R_SPARC_WDISP30: |
| 2494 | case elfcpp::R_SPARC_WPLT30: |
| 2495 | Reloc::wdisp30(view, object, psymval, addend, address); |
| 2496 | break; |
| 2497 | |
| 2498 | case elfcpp::R_SPARC_WDISP22: |
| 2499 | Reloc::wdisp22(view, object, psymval, addend, address); |
| 2500 | break; |
| 2501 | |
| 2502 | case elfcpp::R_SPARC_WDISP19: |
| 2503 | Reloc::wdisp19(view, object, psymval, addend, address); |
| 2504 | break; |
| 2505 | |
| 2506 | case elfcpp::R_SPARC_WDISP16: |
| 2507 | Reloc::wdisp16(view, object, psymval, addend, address); |
| 2508 | break; |
| 2509 | |
| 2510 | case elfcpp::R_SPARC_HI22: |
| 2511 | Reloc::hi22(view, object, psymval, addend); |
| 2512 | break; |
| 2513 | |
| 2514 | case elfcpp::R_SPARC_22: |
| 2515 | Reloc::rela32_22(view, object, psymval, addend); |
| 2516 | break; |
| 2517 | |
| 2518 | case elfcpp::R_SPARC_13: |
| 2519 | Reloc::rela32_13(view, object, psymval, addend); |
| 2520 | break; |
| 2521 | |
| 2522 | case elfcpp::R_SPARC_LO10: |
| 2523 | Reloc::lo10(view, object, psymval, addend); |
| 2524 | break; |
| 2525 | |
| 2526 | case elfcpp::R_SPARC_GOT10: |
| 2527 | Reloc::lo10(view, got_offset, addend); |
| 2528 | break; |
| 2529 | |
| 2530 | case elfcpp::R_SPARC_GOT13: |
| 2531 | Reloc::rela32_13(view, got_offset, addend); |
| 2532 | break; |
| 2533 | |
| 2534 | case elfcpp::R_SPARC_GOT22: |
| 2535 | Reloc::hi22(view, got_offset, addend); |
| 2536 | break; |
| 2537 | |
| 2538 | case elfcpp::R_SPARC_PC10: |
| 2539 | Reloc::pc10(view, object, psymval, addend, address); |
| 2540 | break; |
| 2541 | |
| 2542 | case elfcpp::R_SPARC_PC22: |
| 2543 | Reloc::pc22(view, object, psymval, addend, address); |
| 2544 | break; |
| 2545 | |
| 2546 | case elfcpp::R_SPARC_TLS_DTPOFF32: |
| 2547 | case elfcpp::R_SPARC_UA32: |
| 2548 | Reloc::ua32(view, object, psymval, addend); |
| 2549 | break; |
| 2550 | |
| 2551 | case elfcpp::R_SPARC_PLT64: |
| 2552 | Relocate_functions<size, big_endian>::rela64(view, object, |
| 2553 | psymval, addend); |
| 2554 | break; |
| 2555 | |
| 2556 | case elfcpp::R_SPARC_PLT32: |
| 2557 | Relocate_functions<size, big_endian>::rela32(view, object, |
| 2558 | psymval, addend); |
| 2559 | break; |
| 2560 | |
| 2561 | case elfcpp::R_SPARC_HIPLT22: |
| 2562 | Reloc::hi22(view, object, psymval, addend); |
| 2563 | break; |
| 2564 | |
| 2565 | case elfcpp::R_SPARC_LOPLT10: |
| 2566 | Reloc::lo10(view, object, psymval, addend); |
| 2567 | break; |
| 2568 | |
| 2569 | case elfcpp::R_SPARC_PCPLT32: |
| 2570 | Reloc::disp32(view, object, psymval, addend, address); |
| 2571 | break; |
| 2572 | |
| 2573 | case elfcpp::R_SPARC_PCPLT22: |
| 2574 | Reloc::pcplt22(view, object, psymval, addend, address); |
| 2575 | break; |
| 2576 | |
| 2577 | case elfcpp::R_SPARC_PCPLT10: |
| 2578 | Reloc::lo10(view, object, psymval, addend, address); |
| 2579 | break; |
| 2580 | |
| 2581 | case elfcpp::R_SPARC_64: |
| 2582 | if (!parameters->options().output_is_position_independent()) |
| 2583 | Relocate_functions<size, big_endian>::rela64(view, object, |
| 2584 | psymval, addend); |
| 2585 | break; |
| 2586 | |
| 2587 | case elfcpp::R_SPARC_OLO10: |
| 2588 | { |
| 2589 | unsigned int addend2 = rela.get_r_info() & 0xffffffff; |
| 2590 | addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000; |
| 2591 | Reloc::olo10(view, object, psymval, addend, addend2); |
| 2592 | } |
| 2593 | break; |
| 2594 | |
| 2595 | case elfcpp::R_SPARC_HH22: |
| 2596 | Reloc::hh22(view, object, psymval, addend); |
| 2597 | break; |
| 2598 | |
| 2599 | case elfcpp::R_SPARC_PC_HH22: |
| 2600 | Reloc::pc_hh22(view, object, psymval, addend, address); |
| 2601 | break; |
| 2602 | |
| 2603 | case elfcpp::R_SPARC_HM10: |
| 2604 | Reloc::hm10(view, object, psymval, addend); |
| 2605 | break; |
| 2606 | |
| 2607 | case elfcpp::R_SPARC_PC_HM10: |
| 2608 | Reloc::pc_hm10(view, object, psymval, addend, address); |
| 2609 | break; |
| 2610 | |
| 2611 | case elfcpp::R_SPARC_LM22: |
| 2612 | Reloc::hi22(view, object, psymval, addend); |
| 2613 | break; |
| 2614 | |
| 2615 | case elfcpp::R_SPARC_PC_LM22: |
| 2616 | Reloc::pcplt22(view, object, psymval, addend, address); |
| 2617 | break; |
| 2618 | |
| 2619 | case elfcpp::R_SPARC_11: |
| 2620 | Reloc::rela32_11(view, object, psymval, addend); |
| 2621 | break; |
| 2622 | |
| 2623 | case elfcpp::R_SPARC_10: |
| 2624 | Reloc::rela32_10(view, object, psymval, addend); |
| 2625 | break; |
| 2626 | |
| 2627 | case elfcpp::R_SPARC_7: |
| 2628 | Reloc::rela32_7(view, object, psymval, addend); |
| 2629 | break; |
| 2630 | |
| 2631 | case elfcpp::R_SPARC_6: |
| 2632 | Reloc::rela32_6(view, object, psymval, addend); |
| 2633 | break; |
| 2634 | |
| 2635 | case elfcpp::R_SPARC_5: |
| 2636 | Reloc::rela32_5(view, object, psymval, addend); |
| 2637 | break; |
| 2638 | |
| 2639 | case elfcpp::R_SPARC_HIX22: |
| 2640 | Reloc::hix22(view, object, psymval, addend); |
| 2641 | break; |
| 2642 | |
| 2643 | case elfcpp::R_SPARC_LOX10: |
| 2644 | Reloc::lox10(view, object, psymval, addend); |
| 2645 | break; |
| 2646 | |
| 2647 | case elfcpp::R_SPARC_H44: |
| 2648 | Reloc::h44(view, object, psymval, addend); |
| 2649 | break; |
| 2650 | |
| 2651 | case elfcpp::R_SPARC_M44: |
| 2652 | Reloc::m44(view, object, psymval, addend); |
| 2653 | break; |
| 2654 | |
| 2655 | case elfcpp::R_SPARC_L44: |
| 2656 | Reloc::l44(view, object, psymval, addend); |
| 2657 | break; |
| 2658 | |
| 2659 | case elfcpp::R_SPARC_TLS_DTPOFF64: |
| 2660 | case elfcpp::R_SPARC_UA64: |
| 2661 | Reloc::ua64(view, object, psymval, addend); |
| 2662 | break; |
| 2663 | |
| 2664 | case elfcpp::R_SPARC_UA16: |
| 2665 | Reloc::ua16(view, object, psymval, addend); |
| 2666 | break; |
| 2667 | |
| 2668 | case elfcpp::R_SPARC_TLS_GD_HI22: |
| 2669 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 2670 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 2671 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 2672 | case elfcpp::R_SPARC_TLS_LDM_HI22: |
| 2673 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 2674 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 2675 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 2676 | case elfcpp::R_SPARC_TLS_LDO_HIX22: |
| 2677 | case elfcpp::R_SPARC_TLS_LDO_LOX10: |
| 2678 | case elfcpp::R_SPARC_TLS_LDO_ADD: |
| 2679 | case elfcpp::R_SPARC_TLS_IE_HI22: |
| 2680 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 2681 | case elfcpp::R_SPARC_TLS_IE_LD: |
| 2682 | case elfcpp::R_SPARC_TLS_IE_LDX: |
| 2683 | case elfcpp::R_SPARC_TLS_IE_ADD: |
| 2684 | case elfcpp::R_SPARC_TLS_LE_HIX22: |
| 2685 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 2686 | this->relocate_tls(relinfo, target, relnum, rela, |
| 2687 | r_type, gsym, psymval, view, |
| 2688 | address, view_size); |
| 2689 | break; |
| 2690 | |
| 2691 | case elfcpp::R_SPARC_COPY: |
| 2692 | case elfcpp::R_SPARC_GLOB_DAT: |
| 2693 | case elfcpp::R_SPARC_JMP_SLOT: |
| 2694 | case elfcpp::R_SPARC_RELATIVE: |
| 2695 | // These are outstanding tls relocs, which are unexpected when |
| 2696 | // linking. |
| 2697 | case elfcpp::R_SPARC_TLS_DTPMOD64: |
| 2698 | case elfcpp::R_SPARC_TLS_DTPMOD32: |
| 2699 | case elfcpp::R_SPARC_TLS_TPOFF64: |
| 2700 | case elfcpp::R_SPARC_TLS_TPOFF32: |
| 2701 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
| 2702 | _("unexpected reloc %u in object file"), |
| 2703 | r_type); |
| 2704 | break; |
| 2705 | |
| 2706 | default: |
| 2707 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
| 2708 | _("unsupported reloc %u"), |
| 2709 | r_type); |
| 2710 | break; |
| 2711 | } |
| 2712 | |
| 2713 | return true; |
| 2714 | } |
| 2715 | |
| 2716 | // Perform a TLS relocation. |
| 2717 | |
| 2718 | template<int size, bool big_endian> |
| 2719 | inline void |
| 2720 | Target_sparc<size, big_endian>::Relocate::relocate_tls( |
| 2721 | const Relocate_info<size, big_endian>* relinfo, |
| 2722 | Target_sparc<size, big_endian>* target, |
| 2723 | size_t relnum, |
| 2724 | const elfcpp::Rela<size, big_endian>& rela, |
| 2725 | unsigned int r_type, |
| 2726 | const Sized_symbol<size>* gsym, |
| 2727 | const Symbol_value<size>* psymval, |
| 2728 | unsigned char* view, |
| 2729 | typename elfcpp::Elf_types<size>::Elf_Addr address, |
| 2730 | section_size_type) |
| 2731 | { |
| 2732 | Output_segment* tls_segment = relinfo->layout->tls_segment(); |
| 2733 | typedef Sparc_relocate_functions<size, big_endian> Reloc; |
| 2734 | const Sized_relobj<size, big_endian>* object = relinfo->object; |
| 2735 | typedef typename elfcpp::Swap<32, true>::Valtype Insntype; |
| 2736 | |
| 2737 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); |
| 2738 | typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0); |
| 2739 | |
| 2740 | const bool is_final = |
| 2741 | (gsym == NULL |
| 2742 | ? !parameters->options().output_is_position_independent() |
| 2743 | : gsym->final_value_is_known()); |
| 2744 | const tls::Tls_optimization optimized_type |
| 2745 | = optimize_tls_reloc(is_final, r_type); |
| 2746 | |
| 2747 | switch (r_type) |
| 2748 | { |
| 2749 | case elfcpp::R_SPARC_TLS_GD_HI22: |
| 2750 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 2751 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 2752 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 2753 | if (optimized_type == tls::TLSOPT_TO_LE) |
| 2754 | { |
| 2755 | Insntype* wv = reinterpret_cast<Insntype*>(view); |
| 2756 | Insntype val; |
| 2757 | |
| 2758 | value -= tls_segment->memsz(); |
| 2759 | |
| 2760 | switch (r_type) |
| 2761 | { |
| 2762 | case elfcpp::R_SPARC_TLS_GD_HI22: |
| 2763 | // TLS_GD_HI22 --> TLS_LE_HIX22 |
| 2764 | Reloc::hix22(view, value, addend); |
| 2765 | break; |
| 2766 | |
| 2767 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 2768 | // TLS_GD_LO10 --> TLS_LE_LOX10 |
| 2769 | Reloc::lox10(view, value, addend); |
| 2770 | break; |
| 2771 | |
| 2772 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 2773 | // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3 |
| 2774 | val = elfcpp::Swap<32, true>::readval(wv); |
| 2775 | val = (val & ~0x7c000) | 0x1c000; |
| 2776 | elfcpp::Swap<32, true>::writeval(wv, val); |
| 2777 | break; |
| 2778 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 2779 | // call __tls_get_addr --> nop |
| 2780 | elfcpp::Swap<32, true>::writeval(wv, sparc_nop); |
| 2781 | break; |
| 2782 | } |
| 2783 | break; |
| 2784 | } |
| 2785 | else |
| 2786 | { |
| 2787 | unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE |
| 2788 | ? GOT_TYPE_TLS_OFFSET |
| 2789 | : GOT_TYPE_TLS_PAIR); |
| 2790 | if (gsym != NULL) |
| 2791 | { |
| 2792 | gold_assert(gsym->has_got_offset(got_type)); |
| 2793 | value = gsym->got_offset(got_type); |
| 2794 | } |
| 2795 | else |
| 2796 | { |
| 2797 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); |
| 2798 | gold_assert(object->local_has_got_offset(r_sym, got_type)); |
| 2799 | value = object->local_got_offset(r_sym, got_type); |
| 2800 | } |
| 2801 | if (optimized_type == tls::TLSOPT_TO_IE) |
| 2802 | { |
| 2803 | Insntype* wv = reinterpret_cast<Insntype*>(view); |
| 2804 | Insntype val; |
| 2805 | |
| 2806 | switch (r_type) |
| 2807 | { |
| 2808 | case elfcpp::R_SPARC_TLS_GD_HI22: |
| 2809 | // TLS_GD_HI22 --> TLS_IE_HI22 |
| 2810 | Reloc::hi22(view, value, addend); |
| 2811 | break; |
| 2812 | |
| 2813 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 2814 | // TLS_GD_LO10 --> TLS_IE_LO10 |
| 2815 | Reloc::lo10(view, value, addend); |
| 2816 | break; |
| 2817 | |
| 2818 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 2819 | // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3 |
| 2820 | val = elfcpp::Swap<32, true>::readval(wv); |
| 2821 | |
| 2822 | if (size == 64) |
| 2823 | val |= 0xc0580000; |
| 2824 | else |
| 2825 | val |= 0xc0000000; |
| 2826 | |
| 2827 | elfcpp::Swap<32, true>::writeval(wv, val); |
| 2828 | break; |
| 2829 | |
| 2830 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 2831 | // The compiler can put the TLS_GD_ADD instruction |
| 2832 | // into the delay slot of the call. If so, we need |
| 2833 | // to transpose the two instructions so that the |
| 2834 | // the new sequence works properly. |
| 2835 | // |
| 2836 | // The test we use is if the instruction in the |
| 2837 | // delay slot is an add with destination register |
| 2838 | // equal to %o0 |
| 2839 | val = elfcpp::Swap<32, true>::readval(wv + 1); |
| 2840 | if ((val & 0x81f80000) == 0x80000000 |
| 2841 | && ((val >> 25) & 0x1f) == 0x8) |
| 2842 | { |
| 2843 | if (size == 64) |
| 2844 | val |= 0xc0580000; |
| 2845 | else |
| 2846 | val |= 0xc0000000; |
| 2847 | |
| 2848 | elfcpp::Swap<32, true>::writeval(wv, val); |
| 2849 | |
| 2850 | wv += 1; |
| 2851 | this->ignore_gd_add_ = true; |
| 2852 | } |
| 2853 | |
| 2854 | // call __tls_get_addr --> add %g7, %o0, %o0 |
| 2855 | elfcpp::Swap<32, true>::writeval(wv, 0x9001c008); |
| 2856 | break; |
| 2857 | } |
| 2858 | break; |
| 2859 | } |
| 2860 | else if (optimized_type == tls::TLSOPT_NONE) |
| 2861 | { |
| 2862 | switch (r_type) |
| 2863 | { |
| 2864 | case elfcpp::R_SPARC_TLS_GD_HI22: |
| 2865 | Reloc::hi22(view, value, addend); |
| 2866 | break; |
| 2867 | case elfcpp::R_SPARC_TLS_GD_LO10: |
| 2868 | Reloc::lo10(view, value, addend); |
| 2869 | break; |
| 2870 | case elfcpp::R_SPARC_TLS_GD_ADD: |
| 2871 | break; |
| 2872 | case elfcpp::R_SPARC_TLS_GD_CALL: |
| 2873 | { |
| 2874 | Symbol_value<size> symval; |
| 2875 | elfcpp::Elf_Xword value; |
| 2876 | Symbol* tsym; |
| 2877 | |
| 2878 | tsym = target->tls_get_addr_sym_; |
| 2879 | gold_assert(tsym); |
| 2880 | value = (target->plt_section()->address() + |
| 2881 | tsym->plt_offset()); |
| 2882 | symval.set_output_value(value); |
| 2883 | Reloc::wdisp30(view, object, &symval, addend, address); |
| 2884 | } |
| 2885 | break; |
| 2886 | } |
| 2887 | break; |
| 2888 | } |
| 2889 | } |
| 2890 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
| 2891 | _("unsupported reloc %u"), |
| 2892 | r_type); |
| 2893 | break; |
| 2894 | |
| 2895 | case elfcpp::R_SPARC_TLS_LDM_HI22: |
| 2896 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 2897 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 2898 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 2899 | if (optimized_type == tls::TLSOPT_TO_LE) |
| 2900 | { |
| 2901 | Insntype* wv = reinterpret_cast<Insntype*>(view); |
| 2902 | |
| 2903 | switch (r_type) |
| 2904 | { |
| 2905 | case elfcpp::R_SPARC_TLS_LDM_HI22: |
| 2906 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 2907 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 2908 | elfcpp::Swap<32, true>::writeval(wv, sparc_nop); |
| 2909 | break; |
| 2910 | |
| 2911 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 2912 | elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0); |
| 2913 | break; |
| 2914 | } |
| 2915 | break; |
| 2916 | } |
| 2917 | else if (optimized_type == tls::TLSOPT_NONE) |
| 2918 | { |
| 2919 | // Relocate the field with the offset of the GOT entry for |
| 2920 | // the module index. |
| 2921 | unsigned int got_offset; |
| 2922 | |
| 2923 | got_offset = target->got_mod_index_entry(NULL, NULL, NULL); |
| 2924 | switch (r_type) |
| 2925 | { |
| 2926 | case elfcpp::R_SPARC_TLS_LDM_HI22: |
| 2927 | Reloc::hi22(view, got_offset, addend); |
| 2928 | break; |
| 2929 | case elfcpp::R_SPARC_TLS_LDM_LO10: |
| 2930 | Reloc::lo10(view, got_offset, addend); |
| 2931 | break; |
| 2932 | case elfcpp::R_SPARC_TLS_LDM_ADD: |
| 2933 | break; |
| 2934 | case elfcpp::R_SPARC_TLS_LDM_CALL: |
| 2935 | { |
| 2936 | Symbol_value<size> symval; |
| 2937 | elfcpp::Elf_Xword value; |
| 2938 | Symbol* tsym; |
| 2939 | |
| 2940 | tsym = target->tls_get_addr_sym_; |
| 2941 | gold_assert(tsym); |
| 2942 | value = (target->plt_section()->address() + |
| 2943 | tsym->plt_offset()); |
| 2944 | symval.set_output_value(value); |
| 2945 | Reloc::wdisp30(view, object, &symval, addend, address); |
| 2946 | } |
| 2947 | break; |
| 2948 | } |
| 2949 | break; |
| 2950 | } |
| 2951 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
| 2952 | _("unsupported reloc %u"), |
| 2953 | r_type); |
| 2954 | break; |
| 2955 | |
| 2956 | // These relocs can appear in debugging sections, in which case |
| 2957 | // we won't see the TLS_LDM relocs. The local_dynamic_type |
| 2958 | // field tells us this. |
| 2959 | case elfcpp::R_SPARC_TLS_LDO_HIX22: |
| 2960 | if (optimized_type == tls::TLSOPT_TO_LE) |
| 2961 | { |
| 2962 | value -= tls_segment->memsz(); |
| 2963 | Reloc::hix22(view, value, addend); |
| 2964 | } |
| 2965 | else |
| 2966 | Reloc::ldo_hix22(view, value, addend); |
| 2967 | break; |
| 2968 | case elfcpp::R_SPARC_TLS_LDO_LOX10: |
| 2969 | if (optimized_type == tls::TLSOPT_TO_LE) |
| 2970 | { |
| 2971 | value -= tls_segment->memsz(); |
| 2972 | Reloc::lox10(view, value, addend); |
| 2973 | } |
| 2974 | else |
| 2975 | Reloc::ldo_lox10(view, value, addend); |
| 2976 | break; |
| 2977 | case elfcpp::R_SPARC_TLS_LDO_ADD: |
| 2978 | if (optimized_type == tls::TLSOPT_TO_LE) |
| 2979 | { |
| 2980 | Insntype* wv = reinterpret_cast<Insntype*>(view); |
| 2981 | Insntype val; |
| 2982 | |
| 2983 | // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3 |
| 2984 | val = elfcpp::Swap<32, true>::readval(wv); |
| 2985 | val = (val & ~0x7c000) | 0x1c000; |
| 2986 | elfcpp::Swap<32, true>::writeval(wv, val); |
| 2987 | } |
| 2988 | break; |
| 2989 | |
| 2990 | // When optimizing IE --> LE, the only relocation that is handled |
| 2991 | // differently is R_SPARC_TLS_IE_LD, it is rewritten from |
| 2992 | // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is |
| 2993 | // rs2 and rd are the same. |
| 2994 | case elfcpp::R_SPARC_TLS_IE_LD: |
| 2995 | case elfcpp::R_SPARC_TLS_IE_LDX: |
| 2996 | if (optimized_type == tls::TLSOPT_TO_LE) |
| 2997 | { |
| 2998 | Insntype* wv = reinterpret_cast<Insntype*>(view); |
| 2999 | Insntype val = elfcpp::Swap<32, true>::readval(wv); |
| 3000 | Insntype rs2 = val & 0x1f; |
| 3001 | Insntype rd = (val >> 25) & 0x1f; |
| 3002 | |
| 3003 | if (rs2 == rd) |
| 3004 | val = sparc_nop; |
| 3005 | else |
| 3006 | val = sparc_mov | (val & 0x3e00001f); |
| 3007 | |
| 3008 | elfcpp::Swap<32, true>::writeval(wv, val); |
| 3009 | } |
| 3010 | break; |
| 3011 | |
| 3012 | case elfcpp::R_SPARC_TLS_IE_HI22: |
| 3013 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 3014 | if (optimized_type == tls::TLSOPT_TO_LE) |
| 3015 | { |
| 3016 | value -= tls_segment->memsz(); |
| 3017 | switch (r_type) |
| 3018 | { |
| 3019 | case elfcpp::R_SPARC_TLS_IE_HI22: |
| 3020 | // IE_HI22 --> LE_HIX22 |
| 3021 | Reloc::hix22(view, value, addend); |
| 3022 | break; |
| 3023 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 3024 | // IE_LO10 --> LE_LOX10 |
| 3025 | Reloc::lox10(view, value, addend); |
| 3026 | break; |
| 3027 | } |
| 3028 | break; |
| 3029 | } |
| 3030 | else if (optimized_type == tls::TLSOPT_NONE) |
| 3031 | { |
| 3032 | // Relocate the field with the offset of the GOT entry for |
| 3033 | // the tp-relative offset of the symbol. |
| 3034 | if (gsym != NULL) |
| 3035 | { |
| 3036 | gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET)); |
| 3037 | value = gsym->got_offset(GOT_TYPE_TLS_OFFSET); |
| 3038 | } |
| 3039 | else |
| 3040 | { |
| 3041 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); |
| 3042 | gold_assert(object->local_has_got_offset(r_sym, |
| 3043 | GOT_TYPE_TLS_OFFSET)); |
| 3044 | value = object->local_got_offset(r_sym, |
| 3045 | GOT_TYPE_TLS_OFFSET); |
| 3046 | } |
| 3047 | switch (r_type) |
| 3048 | { |
| 3049 | case elfcpp::R_SPARC_TLS_IE_HI22: |
| 3050 | Reloc::hi22(view, value, addend); |
| 3051 | break; |
| 3052 | case elfcpp::R_SPARC_TLS_IE_LO10: |
| 3053 | Reloc::lo10(view, value, addend); |
| 3054 | break; |
| 3055 | } |
| 3056 | break; |
| 3057 | } |
| 3058 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), |
| 3059 | _("unsupported reloc %u"), |
| 3060 | r_type); |
| 3061 | break; |
| 3062 | |
| 3063 | case elfcpp::R_SPARC_TLS_IE_ADD: |
| 3064 | // This seems to be mainly so that we can find the addition |
| 3065 | // instruction if there is one. There doesn't seem to be any |
| 3066 | // actual relocation to apply. |
| 3067 | break; |
| 3068 | |
| 3069 | case elfcpp::R_SPARC_TLS_LE_HIX22: |
| 3070 | // If we're creating a shared library, a dynamic relocation will |
| 3071 | // have been created for this location, so do not apply it now. |
| 3072 | if (!parameters->options().shared()) |
| 3073 | { |
| 3074 | value -= tls_segment->memsz(); |
| 3075 | Reloc::hix22(view, value, addend); |
| 3076 | } |
| 3077 | break; |
| 3078 | |
| 3079 | case elfcpp::R_SPARC_TLS_LE_LOX10: |
| 3080 | // If we're creating a shared library, a dynamic relocation will |
| 3081 | // have been created for this location, so do not apply it now. |
| 3082 | if (!parameters->options().shared()) |
| 3083 | { |
| 3084 | value -= tls_segment->memsz(); |
| 3085 | Reloc::lox10(view, value, addend); |
| 3086 | } |
| 3087 | break; |
| 3088 | } |
| 3089 | } |
| 3090 | |
| 3091 | // Relocate section data. |
| 3092 | |
| 3093 | template<int size, bool big_endian> |
| 3094 | void |
| 3095 | Target_sparc<size, big_endian>::relocate_section( |
| 3096 | const Relocate_info<size, big_endian>* relinfo, |
| 3097 | unsigned int sh_type, |
| 3098 | const unsigned char* prelocs, |
| 3099 | size_t reloc_count, |
| 3100 | Output_section* output_section, |
| 3101 | bool needs_special_offset_handling, |
| 3102 | unsigned char* view, |
| 3103 | typename elfcpp::Elf_types<size>::Elf_Addr address, |
| 3104 | section_size_type view_size, |
| 3105 | const Reloc_symbol_changes* reloc_symbol_changes) |
| 3106 | { |
| 3107 | typedef Target_sparc<size, big_endian> Sparc; |
| 3108 | typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate; |
| 3109 | |
| 3110 | gold_assert(sh_type == elfcpp::SHT_RELA); |
| 3111 | |
| 3112 | gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA, |
| 3113 | Sparc_relocate>( |
| 3114 | relinfo, |
| 3115 | this, |
| 3116 | prelocs, |
| 3117 | reloc_count, |
| 3118 | output_section, |
| 3119 | needs_special_offset_handling, |
| 3120 | view, |
| 3121 | address, |
| 3122 | view_size, |
| 3123 | reloc_symbol_changes); |
| 3124 | } |
| 3125 | |
| 3126 | // Return the size of a relocation while scanning during a relocatable |
| 3127 | // link. |
| 3128 | |
| 3129 | template<int size, bool big_endian> |
| 3130 | unsigned int |
| 3131 | Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc( |
| 3132 | unsigned int, |
| 3133 | Relobj*) |
| 3134 | { |
| 3135 | // We are always SHT_RELA, so we should never get here. |
| 3136 | gold_unreachable(); |
| 3137 | return 0; |
| 3138 | } |
| 3139 | |
| 3140 | // Scan the relocs during a relocatable link. |
| 3141 | |
| 3142 | template<int size, bool big_endian> |
| 3143 | void |
| 3144 | Target_sparc<size, big_endian>::scan_relocatable_relocs( |
| 3145 | Symbol_table* symtab, |
| 3146 | Layout* layout, |
| 3147 | Sized_relobj<size, big_endian>* object, |
| 3148 | unsigned int data_shndx, |
| 3149 | unsigned int sh_type, |
| 3150 | const unsigned char* prelocs, |
| 3151 | size_t reloc_count, |
| 3152 | Output_section* output_section, |
| 3153 | bool needs_special_offset_handling, |
| 3154 | size_t local_symbol_count, |
| 3155 | const unsigned char* plocal_symbols, |
| 3156 | Relocatable_relocs* rr) |
| 3157 | { |
| 3158 | gold_assert(sh_type == elfcpp::SHT_RELA); |
| 3159 | |
| 3160 | typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA, |
| 3161 | Relocatable_size_for_reloc> Scan_relocatable_relocs; |
| 3162 | |
| 3163 | gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA, |
| 3164 | Scan_relocatable_relocs>( |
| 3165 | symtab, |
| 3166 | layout, |
| 3167 | object, |
| 3168 | data_shndx, |
| 3169 | prelocs, |
| 3170 | reloc_count, |
| 3171 | output_section, |
| 3172 | needs_special_offset_handling, |
| 3173 | local_symbol_count, |
| 3174 | plocal_symbols, |
| 3175 | rr); |
| 3176 | } |
| 3177 | |
| 3178 | // Relocate a section during a relocatable link. |
| 3179 | |
| 3180 | template<int size, bool big_endian> |
| 3181 | void |
| 3182 | Target_sparc<size, big_endian>::relocate_for_relocatable( |
| 3183 | const Relocate_info<size, big_endian>* relinfo, |
| 3184 | unsigned int sh_type, |
| 3185 | const unsigned char* prelocs, |
| 3186 | size_t reloc_count, |
| 3187 | Output_section* output_section, |
| 3188 | off_t offset_in_output_section, |
| 3189 | const Relocatable_relocs* rr, |
| 3190 | unsigned char* view, |
| 3191 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, |
| 3192 | section_size_type view_size, |
| 3193 | unsigned char* reloc_view, |
| 3194 | section_size_type reloc_view_size) |
| 3195 | { |
| 3196 | gold_assert(sh_type == elfcpp::SHT_RELA); |
| 3197 | |
| 3198 | gold::relocate_for_relocatable<size, big_endian, elfcpp::SHT_RELA>( |
| 3199 | relinfo, |
| 3200 | prelocs, |
| 3201 | reloc_count, |
| 3202 | output_section, |
| 3203 | offset_in_output_section, |
| 3204 | rr, |
| 3205 | view, |
| 3206 | view_address, |
| 3207 | view_size, |
| 3208 | reloc_view, |
| 3209 | reloc_view_size); |
| 3210 | } |
| 3211 | |
| 3212 | // Return the value to use for a dynamic which requires special |
| 3213 | // treatment. This is how we support equality comparisons of function |
| 3214 | // pointers across shared library boundaries, as described in the |
| 3215 | // processor specific ABI supplement. |
| 3216 | |
| 3217 | template<int size, bool big_endian> |
| 3218 | uint64_t |
| 3219 | Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const |
| 3220 | { |
| 3221 | gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset()); |
| 3222 | return this->plt_section()->address() + gsym->plt_offset(); |
| 3223 | } |
| 3224 | |
| 3225 | // The selector for sparc object files. |
| 3226 | |
| 3227 | template<int size, bool big_endian> |
| 3228 | class Target_selector_sparc : public Target_selector |
| 3229 | { |
| 3230 | public: |
| 3231 | Target_selector_sparc() |
| 3232 | : Target_selector(elfcpp::EM_NONE, size, big_endian, |
| 3233 | (size == 64 ? "elf64-sparc" : "elf32-sparc")) |
| 3234 | { } |
| 3235 | |
| 3236 | Target* do_recognize(int machine, int, int) |
| 3237 | { |
| 3238 | switch (size) |
| 3239 | { |
| 3240 | case 64: |
| 3241 | if (machine != elfcpp::EM_SPARCV9) |
| 3242 | return NULL; |
| 3243 | break; |
| 3244 | |
| 3245 | case 32: |
| 3246 | if (machine != elfcpp::EM_SPARC |
| 3247 | && machine != elfcpp::EM_SPARC32PLUS) |
| 3248 | return NULL; |
| 3249 | break; |
| 3250 | |
| 3251 | default: |
| 3252 | return NULL; |
| 3253 | } |
| 3254 | |
| 3255 | return this->instantiate_target(); |
| 3256 | } |
| 3257 | |
| 3258 | Target* do_instantiate_target() |
| 3259 | { return new Target_sparc<size, big_endian>(); } |
| 3260 | }; |
| 3261 | |
| 3262 | Target_selector_sparc<32, true> target_selector_sparc32; |
| 3263 | Target_selector_sparc<64, true> target_selector_sparc64; |
| 3264 | |
| 3265 | } // End anonymous namespace. |