1 // s390.cc -- s390 target support for gold.
3 // Copyright (C) 2015 Free Software Foundation, Inc.
4 // Written by Marcin KoĆcielnicki <koriakin@0x04.net>.
6 // This file is part of gold.
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.
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.
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.
29 #include "parameters.h"
36 #include "copy-relocs.h"
38 #include "target-reloc.h"
39 #include "target-select.h"
49 // A class to handle the .got.plt section.
52 class Output_data_got_plt_s390 : public Output_section_data_build
55 Output_data_got_plt_s390(Layout* layout)
56 : Output_section_data_build(size/8),
60 Output_data_got_plt_s390(Layout* layout, off_t data_size)
61 : Output_section_data_build(data_size, size/8),
66 // Write out the PLT data.
68 do_write(Output_file*);
70 // Write to a map file.
72 do_print_to_mapfile(Mapfile* mapfile) const
73 { mapfile->print_output_data(this, "** GOT PLT"); }
76 // A pointer to the Layout class, so that we can find the .dynamic
77 // section when we write out the GOT PLT section.
81 // A class to handle the PLT data.
84 class Output_data_plt_s390 : public Output_section_data
87 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, true>
90 Output_data_plt_s390(Layout* layout,
91 Output_data_got<size, true>* got,
92 Output_data_got_plt_s390<size>* got_plt,
93 Output_data_space* got_irelative)
94 : Output_section_data(4), layout_(layout),
95 irelative_rel_(NULL), got_(got), got_plt_(got_plt),
96 got_irelative_(got_irelative), count_(0),
97 irelative_count_(0), free_list_()
98 { this->init(layout); }
100 Output_data_plt_s390(Layout* layout,
101 Output_data_got<size, true>* got,
102 Output_data_got_plt_s390<size>* got_plt,
103 Output_data_space* got_irelative,
104 unsigned int plt_count)
105 : Output_section_data((plt_count + 1) * plt_entry_size,
107 layout_(layout), irelative_rel_(NULL), got_(got),
108 got_plt_(got_plt), got_irelative_(got_irelative), count_(plt_count),
109 irelative_count_(0), free_list_()
113 // Initialize the free list and reserve the first entry.
114 this->free_list_.init((plt_count + 1) * plt_entry_size, false);
115 this->free_list_.remove(0, plt_entry_size);
118 // Initialize the PLT section.
120 init(Layout* layout);
122 // Add an entry to the PLT.
124 add_entry(Symbol_table*, Layout*, Symbol* gsym);
126 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
128 add_local_ifunc_entry(Symbol_table*, Layout*,
129 Sized_relobj_file<size, true>*, unsigned int);
131 // Add the relocation for a PLT entry.
133 add_relocation(Symbol_table*, Layout*, Symbol*, unsigned int);
135 // Return the .rela.plt section data.
138 { return this->rel_; }
140 // Return where the IRELATIVE relocations should go in the PLT
143 rela_irelative(Symbol_table*, Layout*);
145 // Return whether we created a section for IRELATIVE relocations.
147 has_irelative_section() const
148 { return this->irelative_rel_ != NULL; }
150 // Return the number of PLT entries.
153 { return this->count_ + this->irelative_count_; }
155 // Return the offset of the first non-reserved PLT entry.
157 first_plt_entry_offset()
158 { return plt_entry_size; }
160 // Return the size of a PLT entry.
162 get_plt_entry_size() const
163 { return plt_entry_size; }
165 // Reserve a slot in the PLT for an existing symbol in an incremental update.
167 reserve_slot(unsigned int plt_index)
169 this->free_list_.remove((plt_index + 1) * plt_entry_size,
170 (plt_index + 2) * plt_entry_size);
173 // Return the PLT address to use for a global symbol.
175 address_for_global(const Symbol*);
177 // Return the PLT address to use for a local symbol.
179 address_for_local(const Relobj*, unsigned int symndx);
181 // Add .eh_frame information for the PLT.
183 add_eh_frame(Layout* layout)
186 layout->add_eh_frame_for_plt(this,
188 plt_eh_frame_cie_size,
190 plt_eh_frame_fde_size);
194 // Fill in the first PLT entry.
196 fill_first_plt_entry(unsigned char* pov,
197 typename elfcpp::Elf_types<size>::Elf_Addr got_address,
198 typename elfcpp::Elf_types<size>::Elf_Addr plt_address);
200 // Fill in a normal PLT entry. Returns the offset into the entry that
201 // should be the initial GOT slot value.
203 fill_plt_entry(unsigned char* pov,
204 typename elfcpp::Elf_types<size>::Elf_Addr got_address,
205 typename elfcpp::Elf_types<size>::Elf_Addr plt_address,
206 unsigned int got_offset,
207 unsigned int plt_offset,
208 unsigned int plt_rel_offset);
211 do_adjust_output_section(Output_section* os);
213 // Write to a map file.
215 do_print_to_mapfile(Mapfile* mapfile) const
216 { mapfile->print_output_data(this, _("** PLT")); }
219 // Set the final size.
221 set_final_data_size();
223 // Write out the PLT data.
225 do_write(Output_file*);
227 // A pointer to the Layout class, so that we can find the .dynamic
228 // section when we write out the GOT PLT section.
230 // The reloc section.
232 // The IRELATIVE relocs, if necessary. These must follow the
233 // regular PLT relocations.
234 Reloc_section* irelative_rel_;
236 Output_data_got<size, true>* got_;
237 // The .got.plt section.
238 Output_data_got_plt_s390<size>* got_plt_;
239 // The part of the .got.plt section used for IRELATIVE relocs.
240 Output_data_space* got_irelative_;
241 // The number of PLT entries.
243 // Number of PLT entries with R_TILEGX_IRELATIVE relocs. These
244 // follow the regular PLT entries.
245 unsigned int irelative_count_;
246 // List of available regions within the section, for incremental
248 Free_list free_list_;
250 // The size of an entry in the PLT.
251 static const int plt_entry_size = 0x20;
252 // The first entry in the PLT.
253 static const unsigned char first_plt_entry_32_abs[plt_entry_size];
254 static const unsigned char first_plt_entry_32_pic[plt_entry_size];
255 static const unsigned char first_plt_entry_64[plt_entry_size];
256 // Other entries in the PLT for an executable.
257 static const unsigned char plt_entry_32_abs[plt_entry_size];
258 static const unsigned char plt_entry_32_pic12[plt_entry_size];
259 static const unsigned char plt_entry_32_pic16[plt_entry_size];
260 static const unsigned char plt_entry_32_pic[plt_entry_size];
261 static const unsigned char plt_entry_64[plt_entry_size];
263 // The .eh_frame unwind information for the PLT.
264 static const int plt_eh_frame_cie_size = 12;
265 static const unsigned char plt_eh_frame_cie[plt_eh_frame_cie_size];
266 static const int plt_eh_frame_fde_size = 12;
267 static const unsigned char plt_eh_frame_fde[plt_eh_frame_fde_size];
272 class Target_s390 : public Sized_target<size, true>
275 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, true> Reloc_section;
278 : Sized_target<size, true>(&s390_info),
279 got_(NULL), plt_(NULL), got_plt_(NULL), got_irelative_(NULL),
280 global_offset_table_(NULL), rela_dyn_(NULL),
281 rela_irelative_(NULL), copy_relocs_(elfcpp::R_390_COPY),
282 got_mod_index_offset_(-1U), tls_base_symbol_defined_(false),
286 // Scan the relocations to look for symbol adjustments.
288 gc_process_relocs(Symbol_table* symtab,
290 Sized_relobj_file<size, true>* object,
291 unsigned int data_shndx,
292 unsigned int sh_type,
293 const unsigned char* prelocs,
295 Output_section* output_section,
296 bool needs_special_offset_handling,
297 size_t local_symbol_count,
298 const unsigned char* plocal_symbols);
300 // Scan the relocations to look for symbol adjustments.
302 scan_relocs(Symbol_table* symtab,
304 Sized_relobj_file<size, true>* object,
305 unsigned int data_shndx,
306 unsigned int sh_type,
307 const unsigned char* prelocs,
309 Output_section* output_section,
310 bool needs_special_offset_handling,
311 size_t local_symbol_count,
312 const unsigned char* plocal_symbols);
314 // Finalize the sections.
316 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
318 // Return the value to use for a dynamic which requires special
321 do_dynsym_value(const Symbol*) const;
323 // Relocate a section.
325 relocate_section(const Relocate_info<size, true>*,
326 unsigned int sh_type,
327 const unsigned char* prelocs,
329 Output_section* output_section,
330 bool needs_special_offset_handling,
332 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
333 section_size_type view_size,
334 const Reloc_symbol_changes*);
336 // Scan the relocs during a relocatable link.
338 scan_relocatable_relocs(Symbol_table* symtab,
340 Sized_relobj_file<size, true>* object,
341 unsigned int data_shndx,
342 unsigned int sh_type,
343 const unsigned char* prelocs,
345 Output_section* output_section,
346 bool needs_special_offset_handling,
347 size_t local_symbol_count,
348 const unsigned char* plocal_symbols,
349 Relocatable_relocs*);
351 // Return a string used to fill a code section with nops.
353 do_code_fill(section_size_type length) const;
355 // Emit relocations for a section.
358 const Relocate_info<size, true>*,
359 unsigned int sh_type,
360 const unsigned char* prelocs,
362 Output_section* output_section,
363 typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
364 const Relocatable_relocs*,
366 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
367 section_size_type view_size,
368 unsigned char* reloc_view,
369 section_size_type reloc_view_size);
371 // Return whether SYM is defined by the ABI.
373 do_is_defined_by_abi(const Symbol* sym) const
374 { return strcmp(sym->name(), "__tls_get_offset") == 0; }
376 // Return the PLT address to use for a global symbol.
378 do_plt_address_for_global(const Symbol* gsym) const
379 { return this->plt_section()->address_for_global(gsym); }
382 do_plt_address_for_local(const Relobj* relobj, unsigned int symndx) const
383 { return this->plt_section()->address_for_local(relobj, symndx); }
385 // Return the offset to use for the GOT_INDX'th got entry which is
386 // for a local tls symbol specified by OBJECT, SYMNDX.
388 do_tls_offset_for_local(const Relobj* object,
390 unsigned int got_indx) const;
392 // Return the offset to use for the GOT_INDX'th got entry which is
393 // for global tls symbol GSYM.
395 do_tls_offset_for_global(Symbol* gsym, unsigned int got_indx) const;
397 // This function should be defined in targets that can use relocation
398 // types to determine (implemented in local_reloc_may_be_function_pointer
399 // and global_reloc_may_be_function_pointer)
400 // if a function's pointer is taken. ICF uses this in safe mode to only
401 // fold those functions whose pointer is defintely not taken.
403 do_can_check_for_function_pointers() const
406 // Return the size of the GOT section.
410 gold_assert(this->got_ != NULL);
411 return this->got_->data_size();
414 // Return the number of entries in the GOT.
416 got_entry_count() const
418 if (this->got_ == NULL)
420 return this->got_size() / (size / 8);
423 // Return the number of entries in the PLT.
425 plt_entry_count() const;
427 // Return the offset of the first non-reserved PLT entry.
429 first_plt_entry_offset() const;
431 // Return the size of each PLT entry.
433 plt_entry_size() const;
435 // Create the GOT section for an incremental update.
436 Output_data_got_base*
437 init_got_plt_for_update(Symbol_table* symtab,
439 unsigned int got_count,
440 unsigned int plt_count);
442 // Reserve a GOT entry for a local symbol, and regenerate any
443 // necessary dynamic relocations.
445 reserve_local_got_entry(unsigned int got_index,
446 Sized_relobj<size, true>* obj,
448 unsigned int got_type);
450 // Reserve a GOT entry for a global symbol, and regenerate any
451 // necessary dynamic relocations.
453 reserve_global_got_entry(unsigned int got_index, Symbol* gsym,
454 unsigned int got_type);
456 // Register an existing PLT entry for a global symbol.
458 register_global_plt_entry(Symbol_table*, Layout*, unsigned int plt_index,
461 // Force a COPY relocation for a given symbol.
463 emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t);
465 // Apply an incremental relocation.
467 apply_relocation(const Relocate_info<size, true>* relinfo,
468 typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
470 typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
473 typename elfcpp::Elf_types<size>::Elf_Addr address,
474 section_size_type view_size);
478 // The class which scans relocations.
483 : issued_non_pic_error_(false)
487 get_reference_flags(unsigned int r_type);
490 local(Symbol_table* symtab, Layout* layout, Target_s390* target,
491 Sized_relobj_file<size, true>* object,
492 unsigned int data_shndx,
493 Output_section* output_section,
494 const elfcpp::Rela<size, true>& reloc, unsigned int r_type,
495 const elfcpp::Sym<size, true>& lsym,
499 global(Symbol_table* symtab, Layout* layout, Target_s390* target,
500 Sized_relobj_file<size, true>* object,
501 unsigned int data_shndx,
502 Output_section* output_section,
503 const elfcpp::Rela<size, true>& reloc, unsigned int r_type,
507 local_reloc_may_be_function_pointer(Symbol_table* symtab, Layout* layout,
509 Sized_relobj_file<size, true>* object,
510 unsigned int data_shndx,
511 Output_section* output_section,
512 const elfcpp::Rela<size, true>& reloc,
514 const elfcpp::Sym<size, true>& lsym);
517 global_reloc_may_be_function_pointer(Symbol_table* symtab, Layout* layout,
519 Sized_relobj_file<size, true>* object,
520 unsigned int data_shndx,
521 Output_section* output_section,
522 const elfcpp::Rela<size, true>& reloc,
528 unsupported_reloc_local(Sized_relobj_file<size, true>*,
529 unsigned int r_type);
532 unsupported_reloc_global(Sized_relobj_file<size, true>*,
533 unsigned int r_type, Symbol*);
536 check_non_pic(Relobj*, unsigned int r_type);
539 possible_function_pointer_reloc(unsigned int r_type);
542 reloc_needs_plt_for_ifunc(Sized_relobj_file<size, true>*,
543 unsigned int r_type);
545 // Whether we have issued an error about a non-PIC compilation.
546 bool issued_non_pic_error_;
549 // The class which implements relocation.
553 // Do a relocation. Return false if the caller should not issue
554 // any warnings about this relocation.
556 relocate(const Relocate_info<size, true>*, Target_s390*,
558 size_t relnum, const elfcpp::Rela<size, true>&,
559 unsigned int r_type, const Sized_symbol<size>*,
560 const Symbol_value<size>*,
561 unsigned char*, typename elfcpp::Elf_types<size>::Elf_Addr,
565 // Do a TLS relocation.
566 inline typename elfcpp::Elf_types<size>::Elf_Addr
567 relocate_tls(const Relocate_info<size, true>*, Target_s390*,
568 size_t relnum, const elfcpp::Rela<size, true>&,
569 unsigned int r_type, const Sized_symbol<size>*,
570 const Symbol_value<size>*,
571 unsigned char*, section_size_type);
573 // Do a TLS General-Dynamic to Initial-Exec transition.
575 tls_gd_to_ie(const Relocate_info<size, true>*, size_t relnum,
576 const elfcpp::Rela<size, true>&,
578 section_size_type view_size);
580 // Do a TLS General-Dynamic to Local-Exec transition.
582 tls_gd_to_le(const Relocate_info<size, true>*, size_t relnum,
583 const elfcpp::Rela<size, true>&,
585 section_size_type view_size);
587 // Do a TLS Local-Dynamic to Local-Exec transition.
589 tls_ld_to_le(const Relocate_info<size, true>*, size_t relnum,
590 const elfcpp::Rela<size, true>&,
592 section_size_type view_size);
594 // Do a TLS Initial-Exec to Local-Exec transition.
596 tls_ie_to_le(const Relocate_info<size, true>*, size_t relnum,
597 const elfcpp::Rela<size, true>&,
599 section_size_type view_size);
602 // A class which returns the size required for a relocation type,
603 // used while scanning relocs during a relocatable link.
604 class Relocatable_size_for_reloc
608 get_size_for_reloc(unsigned int, Relobj*);
611 // Adjust TLS relocation type based on the options and whether this
612 // is a local symbol.
613 static tls::Tls_optimization
614 optimize_tls_reloc(bool is_final, int r_type);
616 // Get the GOT section.
617 const Output_data_got<size, true>*
620 gold_assert(this->got_ != NULL);
624 // Get the GOT section, creating it if necessary.
625 Output_data_got<size, true>*
626 got_section(Symbol_table*, Layout*);
628 typename elfcpp::Elf_types<size>::Elf_Addr
631 gold_assert(this->got_ != NULL);
632 return this->got_plt_->address();
635 typename elfcpp::Elf_types<size>::Elf_Addr
636 got_main_offset() const
638 gold_assert(this->got_ != NULL);
639 return this->got_->address() - this->got_address();
642 // Create the PLT section.
644 make_plt_section(Symbol_table* symtab, Layout* layout);
646 // Create a PLT entry for a global symbol.
648 make_plt_entry(Symbol_table*, Layout*, Symbol*);
650 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
652 make_local_ifunc_plt_entry(Symbol_table*, Layout*,
653 Sized_relobj_file<size, true>* relobj,
654 unsigned int local_sym_index);
656 // Create a GOT entry for the TLS module index.
658 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
659 Sized_relobj_file<size, true>* object);
661 // Get the PLT section.
662 Output_data_plt_s390<size>*
665 gold_assert(this->plt_ != NULL);
669 // Get the dynamic reloc section, creating it if necessary.
671 rela_dyn_section(Layout*);
673 // Get the section to use for IRELATIVE relocations.
675 rela_irelative_section(Layout*);
677 // Add a potential copy relocation.
679 copy_reloc(Symbol_table* symtab, Layout* layout,
680 Sized_relobj_file<size, true>* object,
681 unsigned int shndx, Output_section* output_section,
682 Symbol* sym, const elfcpp::Rela<size, true>& reloc)
684 this->copy_relocs_.copy_reloc(symtab, layout,
685 symtab->get_sized_symbol<size>(sym),
686 object, shndx, output_section,
687 reloc, this->rela_dyn_section(layout));
690 // Information about this specific target which we pass to the
691 // general Target structure.
692 static Target::Target_info s390_info;
694 // The types of GOT entries needed for this platform.
695 // These values are exposed to the ABI in an incremental link.
696 // Do not renumber existing values without changing the version
697 // number of the .gnu_incremental_inputs section.
700 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
701 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
702 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
706 Output_data_got<size, true>* got_;
708 Output_data_plt_s390<size>* plt_;
709 // The GOT PLT section.
710 Output_data_got_plt_s390<size>* got_plt_;
711 // The GOT section for IRELATIVE relocations.
712 Output_data_space* got_irelative_;
713 // The _GLOBAL_OFFSET_TABLE_ symbol.
714 Symbol* global_offset_table_;
715 // The dynamic reloc section.
716 Reloc_section* rela_dyn_;
717 // The section to use for IRELATIVE relocs.
718 Reloc_section* rela_irelative_;
719 // Relocs saved to avoid a COPY reloc.
720 Copy_relocs<elfcpp::SHT_RELA, size, true> copy_relocs_;
721 // Offset of the GOT entry for the TLS module index.
722 unsigned int got_mod_index_offset_;
723 // True if the _TLS_MODULE_BASE_ symbol has been defined.
724 bool tls_base_symbol_defined_;
725 // For use in do_tls_offset_for_*
730 Target::Target_info Target_s390<32>::s390_info =
733 true, // is_big_endian
734 elfcpp::EM_S390, // machine_code
735 false, // has_make_symbol
736 false, // has_resolve
737 true, // has_code_fill
738 true, // is_default_stack_executable
739 true, // can_icf_inline_merge_sections
741 "/lib/ld.so.1", // dynamic_linker
742 0x00400000, // default_text_segment_address
743 4 * 1024, // abi_pagesize (overridable by -z max-page-size)
744 4 * 1024, // common_pagesize (overridable by -z common-page-size)
745 false, // isolate_execinstr
747 elfcpp::SHN_UNDEF, // small_common_shndx
748 elfcpp::SHN_UNDEF, // large_common_shndx
749 0, // small_common_section_flags
750 0, // large_common_section_flags
751 NULL, // attributes_section
752 NULL, // attributes_vendor
753 "_start", // entry_symbol_name
754 32, // hash_entry_size
758 Target::Target_info Target_s390<64>::s390_info =
761 true, // is_big_endian
762 elfcpp::EM_S390, // machine_code
763 false, // has_make_symbol
764 false, // has_resolve
765 true, // has_code_fill
766 true, // is_default_stack_executable
767 true, // can_icf_inline_merge_sections
769 "/lib/ld64.so.1", // dynamic_linker
770 0x80000000ll, // default_text_segment_address
771 4 * 1024, // abi_pagesize (overridable by -z max-page-size)
772 4 * 1024, // common_pagesize (overridable by -z common-page-size)
773 false, // isolate_execinstr
775 elfcpp::SHN_UNDEF, // small_common_shndx
776 elfcpp::SHN_UNDEF, // large_common_shndx
777 0, // small_common_section_flags
778 0, // large_common_section_flags
779 NULL, // attributes_section
780 NULL, // attributes_vendor
781 "_start", // entry_symbol_name
782 64, // hash_entry_size
786 class S390_relocate_functions
806 typedef S390_relocate_functions<size> This;
807 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
809 template<int valsize>
811 has_overflow_signed(Address value)
813 // limit = 1 << (valsize - 1) without shift count exceeding size of type
814 Address limit = static_cast<Address>(1) << ((valsize - 1) >> 1);
815 limit <<= ((valsize - 1) >> 1);
816 limit <<= ((valsize - 1) - 2 * ((valsize - 1) >> 1));
817 return value + limit > (limit << 1) - 1;
820 template<int valsize>
822 has_overflow_unsigned(Address value)
824 Address limit = static_cast<Address>(1) << ((valsize - 1) >> 1);
825 limit <<= ((valsize - 1) >> 1);
826 limit <<= ((valsize - 1) - 2 * ((valsize - 1) >> 1));
827 return value > (limit << 1) - 1;
830 template<int fieldsize>
832 rela(unsigned char* view, Address mask, Address value)
834 typedef typename elfcpp::Swap<fieldsize, true>::Valtype Valtype;
835 Valtype* wv = reinterpret_cast<Valtype*>(view);
836 Valtype val = elfcpp::Swap<fieldsize, true>::readval(view);
839 elfcpp::Swap<fieldsize, true>::writeval(wv, val | value);
843 // R_390_12, R_390_GOT12, R_390_GOTPLT12, R_390_GOTIE12
845 rela12(unsigned char* view, Address value)
847 if (This::template has_overflow_unsigned<12>(value))
848 return STATUS_OVERFLOW;
849 This::template rela<16>(view, 0x0fff, value);
853 // R_390_16, R_390_GOT16, R_390_GOTPLT16, R_390_GOTOFF16, R_390_PLTOFF16
855 rela16(unsigned char* view, Address value)
857 if (This::template has_overflow_signed<16>(value))
858 return STATUS_OVERFLOW;
859 This::template rela<16>(view, 0xffff, value);
863 // R_390_20, R_390_GOT20, R_390_GOTPLT20, R_390_GOTIE20
865 rela20(unsigned char* view, Address value)
867 if (This::template has_overflow_signed<20>(value))
868 return STATUS_OVERFLOW;
869 This::template rela<16>(view, 0x0fff, value);
870 This::template rela<16>(view + 2, 0xff00, value >> (12 - 8));
874 // R_390_PC12DBL, R_390_PLT12DBL
876 pcrela12dbl(unsigned char* view, Address value, Address address)
879 if ((value & 1) != 0)
880 return STATUS_OVERFLOW;
881 if (This::template has_overflow_signed<13>(value))
882 return STATUS_OVERFLOW;
884 This::template rela<16>(view, 0x0fff, value);
888 // R_390_PC16DBL, R_390_PLT16DBL
890 pcrela16dbl(unsigned char* view, Address value, Address address)
893 if ((value & 1) != 0)
894 return STATUS_OVERFLOW;
895 if (This::template has_overflow_signed<17>(value))
896 return STATUS_OVERFLOW;
898 This::template rela<16>(view, 0xffff, value);
902 // R_390_PC24DBL, R_390_PLT24DBL
904 pcrela24dbl(unsigned char* view, Address value, Address address)
907 if ((value & 1) != 0)
908 return STATUS_OVERFLOW;
909 if (This::template has_overflow_signed<25>(value))
910 return STATUS_OVERFLOW;
912 // Swap doesn't take 24-bit fields well...
913 This::template rela<8>(view, 0xff, value >> 16);
914 This::template rela<16>(view + 1, 0xffff, value);
918 // R_390_PC32DBL, R_390_PLT32DBL, R_390_GOTPCDBL, R_390_GOTENT, R_390_GOTPLTENT
920 pcrela32dbl(unsigned char* view, Address value, Address address)
922 Address reloc = value - address;
923 if ((reloc & 1) != 0)
925 gold_warning(_("R_390_PC32DBL target misaligned at %llx"), (long long)address);
926 // Wait for a fix for https://sourceware.org/bugzilla/show_bug.cgi?id=18960
927 // return STATUS_OVERFLOW;
929 if (This::template has_overflow_signed<33>(reloc))
930 return STATUS_OVERFLOW;
932 if (value < address && size == 32)
934 This::template rela<32>(view, 0xffffffff, reloc);
940 // Initialize the PLT section.
944 Output_data_plt_s390<size>::init(Layout* layout)
946 this->rel_ = new Reloc_section(false);
947 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
948 elfcpp::SHF_ALLOC, this->rel_,
949 ORDER_DYNAMIC_PLT_RELOCS, false);
954 Output_data_plt_s390<size>::do_adjust_output_section(Output_section* os)
956 os->set_entsize(plt_entry_size);
959 // Add an entry to the PLT.
963 Output_data_plt_s390<size>::add_entry(Symbol_table* symtab, Layout* layout,
966 gold_assert(!gsym->has_plt_offset());
968 unsigned int plt_index;
970 section_offset_type got_offset;
972 unsigned int* pcount;
974 unsigned int reserved;
975 Output_section_data_build* got;
976 if (gsym->type() == elfcpp::STT_GNU_IFUNC
977 && gsym->can_use_relative_reloc(false))
979 pcount = &this->irelative_count_;
982 got = this->got_irelative_;
986 pcount = &this->count_;
989 got = this->got_plt_;
992 if (!this->is_data_size_valid())
994 // Note that when setting the PLT offset for a non-IRELATIVE
995 // entry we skip the initial reserved PLT entry.
996 plt_index = *pcount + offset;
997 plt_offset = plt_index * plt_entry_size;
1001 got_offset = (plt_index - offset + reserved) * size / 8;
1002 gold_assert(got_offset == got->current_data_size());
1004 // Every PLT entry needs a GOT entry which points back to the PLT
1005 // entry (this will be changed by the dynamic linker, normally
1006 // lazily when the function is called).
1007 got->set_current_data_size(got_offset + size / 8);
1011 // FIXME: This is probably not correct for IRELATIVE relocs.
1013 // For incremental updates, find an available slot.
1014 plt_offset = this->free_list_.allocate(plt_entry_size,
1016 if (plt_offset == -1)
1017 gold_fallback(_("out of patch space (PLT);"
1018 " relink with --incremental-full"));
1020 // The GOT and PLT entries have a 1-1 correspondance, so the GOT offset
1021 // can be calculated from the PLT index, adjusting for the three
1022 // reserved entries at the beginning of the GOT.
1023 plt_index = plt_offset / plt_entry_size - 1;
1024 got_offset = (plt_index - offset + reserved) * size / 8;
1027 gsym->set_plt_offset(plt_offset);
1029 // Every PLT entry needs a reloc.
1030 this->add_relocation(symtab, layout, gsym, got_offset);
1032 // Note that we don't need to save the symbol. The contents of the
1033 // PLT are independent of which symbols are used. The symbols only
1034 // appear in the relocations.
1037 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol. Return
1042 Output_data_plt_s390<size>::add_local_ifunc_entry(
1043 Symbol_table* symtab,
1045 Sized_relobj_file<size, true>* relobj,
1046 unsigned int local_sym_index)
1048 unsigned int plt_offset = this->irelative_count_ * plt_entry_size;
1049 ++this->irelative_count_;
1051 section_offset_type got_offset = this->got_irelative_->current_data_size();
1053 // Every PLT entry needs a GOT entry which points back to the PLT
1055 this->got_irelative_->set_current_data_size(got_offset + size / 8);
1057 // Every PLT entry needs a reloc.
1058 Reloc_section* rela = this->rela_irelative(symtab, layout);
1059 rela->add_symbolless_local_addend(relobj, local_sym_index,
1060 elfcpp::R_390_IRELATIVE,
1061 this->got_irelative_, got_offset, 0);
1066 // Add the relocation for a PLT entry.
1070 Output_data_plt_s390<size>::add_relocation(Symbol_table* symtab,
1073 unsigned int got_offset)
1075 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1076 && gsym->can_use_relative_reloc(false))
1078 Reloc_section* rela = this->rela_irelative(symtab, layout);
1079 rela->add_symbolless_global_addend(gsym, elfcpp::R_390_IRELATIVE,
1080 this->got_irelative_, got_offset, 0);
1084 gsym->set_needs_dynsym_entry();
1085 this->rel_->add_global(gsym, elfcpp::R_390_JMP_SLOT, this->got_plt_,
1090 // Return where the IRELATIVE relocations should go in the PLT. These
1091 // follow the JUMP_SLOT and the TLSDESC relocations.
1094 typename Output_data_plt_s390<size>::Reloc_section*
1095 Output_data_plt_s390<size>::rela_irelative(Symbol_table* symtab,
1098 if (this->irelative_rel_ == NULL)
1100 this->irelative_rel_ = new Reloc_section(false);
1101 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1102 elfcpp::SHF_ALLOC, this->irelative_rel_,
1103 ORDER_DYNAMIC_PLT_RELOCS, false);
1104 gold_assert(this->irelative_rel_->output_section()
1105 == this->rel_->output_section());
1107 if (parameters->doing_static_link())
1109 // A statically linked executable will only have a .rela.plt
1110 // section to hold R_390_IRELATIVE relocs for
1111 // STT_GNU_IFUNC symbols. The library will use these
1112 // symbols to locate the IRELATIVE relocs at program startup
1114 symtab->define_in_output_data("__rela_iplt_start", NULL,
1115 Symbol_table::PREDEFINED,
1116 this->irelative_rel_, 0, 0,
1117 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1118 elfcpp::STV_HIDDEN, 0, false, true);
1119 symtab->define_in_output_data("__rela_iplt_end", NULL,
1120 Symbol_table::PREDEFINED,
1121 this->irelative_rel_, 0, 0,
1122 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1123 elfcpp::STV_HIDDEN, 0, true, true);
1126 return this->irelative_rel_;
1129 // Return the PLT address to use for a global symbol.
1133 Output_data_plt_s390<size>::address_for_global(const Symbol* gsym)
1135 uint64_t offset = 0;
1136 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1137 && gsym->can_use_relative_reloc(false))
1138 offset = (this->count_ + 1) * plt_entry_size;
1139 return this->address() + offset + gsym->plt_offset();
1142 // Return the PLT address to use for a local symbol. These are always
1143 // IRELATIVE relocs.
1147 Output_data_plt_s390<size>::address_for_local(const Relobj* object,
1150 return (this->address()
1151 + (this->count_ + 1) * plt_entry_size
1152 + object->local_plt_offset(r_sym));
1155 // Set the final size.
1158 Output_data_plt_s390<size>::set_final_data_size()
1160 unsigned int count = this->count_ + this->irelative_count_;
1161 this->set_data_size((count + 1) * plt_entry_size);
1166 Output_data_plt_s390<size>::first_plt_entry_32_abs[plt_entry_size] =
1168 0x50, 0x10, 0xf0, 0x1c, // st %r1, 28(%r15)
1169 0x0d, 0x10, // basr %r1, %r0
1170 0x58, 0x10, 0x10, 0x12, // l %r1, 18(%r1)
1171 0xd2, 0x03, 0xf0, 0x18, 0x10, 0x04, // mvc 24(4,%r15), 4(%r1)
1172 0x58, 0x10, 0x10, 0x08, // l %r1, 8(%r1)
1173 0x07, 0xf1, // br %r1
1174 0x00, 0x00, // padding
1175 0x00, 0x00, 0x00, 0x00, // _GLOBAL_OFFSET_TABLE_ (to fill)
1176 0x00, 0x00, 0x00, 0x00, // padding
1181 Output_data_plt_s390<size>::first_plt_entry_32_pic[plt_entry_size] =
1183 0x50, 0x10, 0xf0, 0x1c, // st %r1, 28(%r15)
1184 0x58, 0x10, 0xc0, 0x04, // l %r1, 4(%r12)
1185 0x50, 0x10, 0xf0, 0x18, // st %r1, 24(%r15)
1186 0x58, 0x10, 0xc0, 0x08, // l %r1, 8(%r12)
1187 0x07, 0xf1, // br %r1
1188 0x00, 0x00, // padding
1189 0x00, 0x00, 0x00, 0x00, // padding
1190 0x00, 0x00, 0x00, 0x00, // padding
1191 0x00, 0x00, 0x00, 0x00, // padding
1196 Output_data_plt_s390<size>::first_plt_entry_64[plt_entry_size] =
1198 0xe3, 0x10, 0xf0, 0x38, 0x00, 0x24, // stg %r1, 56(%r15)
1199 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, // larl %r1, _GLOBAL_OFFSET_TABLE_ (to fill)
1200 0xd2, 0x07, 0xf0, 0x30, 0x10, 0x08, // mvc 48(8,%r15), 8(%r1)
1201 0xe3, 0x10, 0x10, 0x10, 0x00, 0x04, // lg %r1, 16(%r1)
1202 0x07, 0xf1, // br %r1
1210 Output_data_plt_s390<size>::fill_first_plt_entry(
1212 typename elfcpp::Elf_types<size>::Elf_Addr got_address,
1213 typename elfcpp::Elf_types<size>::Elf_Addr plt_address)
1217 memcpy(pov, first_plt_entry_64, plt_entry_size);
1218 S390_relocate_functions<size>::pcrela32dbl(pov + 8, got_address, (plt_address + 6));
1220 else if (!parameters->options().output_is_position_independent())
1222 memcpy(pov, first_plt_entry_32_abs, plt_entry_size);
1223 elfcpp::Swap<32, true>::writeval(pov + 24, got_address);
1227 memcpy(pov, first_plt_entry_32_pic, plt_entry_size);
1233 Output_data_plt_s390<size>::plt_entry_32_abs[plt_entry_size] =
1236 0x0d, 0x10, // basr %r1, %r0
1237 0x58, 0x10, 0x10, 0x16, // l %r1, 22(%r1)
1238 0x58, 0x10, 0x10, 0x00, // l %r1, 0(%r1)
1239 0x07, 0xf1, // br %r1
1241 0x0d, 0x10, // basr %r1, %r0
1242 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1243 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1244 0x00, 0x00, // padding
1245 0x00, 0x00, 0x00, 0x00, // _GLOBAL_OFFSET_TABLE_+sym@gotplt (to fill)
1246 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1251 Output_data_plt_s390<size>::plt_entry_32_pic12[plt_entry_size] =
1254 0x58, 0x10, 0xc0, 0x00, // l %r1, sym@gotplt(%r12) (to fill)
1255 0x07, 0xf1, // br %r1
1256 0x00, 0x00, // padding
1257 0x00, 0x00, 0x00, 0x00, // padding
1259 0x0d, 0x10, // basr %r1, %r0
1260 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1261 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1262 0x00, 0x00, // padding
1263 0x00, 0x00, 0x00, 0x00, // padding
1264 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1269 Output_data_plt_s390<size>::plt_entry_32_pic16[plt_entry_size] =
1272 0xa7, 0x18, 0x00, 0x00, // lhi %r1, sym@gotplt (to fill)
1273 0x58, 0x11, 0xc0, 0x00, // l %r1, 0(%r1, %r12)
1274 0x07, 0xf1, // br %r1
1275 0x00, 0x00, // padding
1277 0x0d, 0x10, // basr %r1, %r0
1278 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1279 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1280 0x00, 0x00, // padding
1281 0x00, 0x00, 0x00, 0x00, // padding
1282 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1287 Output_data_plt_s390<size>::plt_entry_32_pic[plt_entry_size] =
1290 0x0d, 0x10, // basr %r1, %r0
1291 0x58, 0x10, 0x10, 0x16, // l %r1, 22(%r1)
1292 0x58, 0x11, 0xc0, 0x00, // l %r1, 0(%r1, %r12)
1293 0x07, 0xf1, // br %r1
1295 0x0d, 0x10, // basr %r1, %r0
1296 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1297 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1298 0x00, 0x00, // padding
1299 0x00, 0x00, 0x00, 0x00, // sym@gotplt (to fill)
1300 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1305 Output_data_plt_s390<size>::plt_entry_64[plt_entry_size] =
1308 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, // larl %r1, _GLOBAL_OFFSET_TABLE_+off (to fill)
1309 0xe3, 0x10, 0x10, 0x00, 0x00, 0x04, // lg %r1, 0(%r1)
1310 0x07, 0xf1, // br %r1
1312 0x0d, 0x10, // basr %r1, %r0
1313 0xe3, 0x10, 0x10, 0x0c, 0x00, 0x14, // lgf %r1, 12(%r1)
1314 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, // jg first_plt_entry (to fill)
1315 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1320 Output_data_plt_s390<size>::fill_plt_entry(
1322 typename elfcpp::Elf_types<size>::Elf_Addr got_address,
1323 typename elfcpp::Elf_types<size>::Elf_Addr plt_address,
1324 unsigned int got_offset,
1325 unsigned int plt_offset,
1326 unsigned int plt_rel_offset)
1330 memcpy(pov, plt_entry_64, plt_entry_size);
1331 S390_relocate_functions<size>::pcrela32dbl(pov + 2, got_address + got_offset, plt_address + plt_offset);
1332 S390_relocate_functions<size>::pcrela32dbl(pov + 24, plt_address, plt_address + plt_offset + 22);
1336 if (!parameters->options().output_is_position_independent())
1338 memcpy(pov, plt_entry_32_abs, plt_entry_size);
1339 elfcpp::Swap<32, true>::writeval(pov + 24, got_address + got_offset);
1343 if (got_offset < 0x1000)
1345 memcpy(pov, plt_entry_32_pic12, plt_entry_size);
1346 S390_relocate_functions<size>::rela12(pov + 2, got_offset);
1348 else if (got_offset < 0x8000)
1350 memcpy(pov, plt_entry_32_pic16, plt_entry_size);
1351 S390_relocate_functions<size>::rela16(pov + 2, got_offset);
1355 memcpy(pov, plt_entry_32_pic, plt_entry_size);
1356 elfcpp::Swap<32, true>::writeval(pov + 24, got_offset);
1359 typename elfcpp::Elf_types<size>::Elf_Addr target = plt_address;
1360 if (plt_offset >= 0x10000)
1362 // Would overflow pcrela16dbl - aim at the farthest previous jump
1364 if (plt_offset > 0x10000)
1366 // Use the full range of pcrel16dbl.
1367 target = plt_address + plt_offset - 0x10000 + 18;
1371 // if plt_offset is exactly 0x10000, the above would aim at 18th byte
1372 // of first_plt_entry, which doesn't have the jump back like the others.
1373 // Aim at the next entry instead.
1374 target = plt_address + plt_offset - 0xffe0 + 18;
1377 S390_relocate_functions<size>::pcrela16dbl(pov + 20, target, plt_address + plt_offset + 18);
1379 elfcpp::Swap<32, true>::writeval(pov + 28, plt_rel_offset);
1386 // The .eh_frame unwind information for the PLT.
1390 Output_data_plt_s390<32>::plt_eh_frame_cie[plt_eh_frame_cie_size] =
1393 'z', // Augmentation: augmentation size included.
1394 'R', // Augmentation: FDE encoding included.
1395 '\0', // End of augmentation string.
1396 1, // Code alignment factor.
1397 0x7c, // Data alignment factor.
1398 14, // Return address column.
1399 1, // Augmentation size.
1400 (elfcpp::DW_EH_PE_pcrel // FDE encoding.
1401 | elfcpp::DW_EH_PE_sdata4),
1402 elfcpp::DW_CFA_def_cfa, 15, 0x60, // DW_CFA_def_cfa: r15 ofs 0x60.
1407 Output_data_plt_s390<64>::plt_eh_frame_cie[plt_eh_frame_cie_size] =
1410 'z', // Augmentation: augmentation size included.
1411 'R', // Augmentation: FDE encoding included.
1412 '\0', // End of augmentation string.
1413 1, // Code alignment factor.
1414 0x78, // Data alignment factor.
1415 14, // Return address column.
1416 1, // Augmentation size.
1417 (elfcpp::DW_EH_PE_pcrel // FDE encoding.
1418 | elfcpp::DW_EH_PE_sdata4),
1419 elfcpp::DW_CFA_def_cfa, 15, 0xa0, // DW_CFA_def_cfa: r15 ofs 0xa0.
1424 Output_data_plt_s390<size>::plt_eh_frame_fde[plt_eh_frame_fde_size] =
1426 0, 0, 0, 0, // Replaced with offset to .plt.
1427 0, 0, 0, 0, // Replaced with size of .plt.
1428 0, // Augmentation size.
1434 // Write out the PLT. This uses the hand-coded instructions above,
1435 // and adjusts them as needed.
1439 Output_data_plt_s390<size>::do_write(Output_file* of)
1441 const off_t offset = this->offset();
1442 const section_size_type oview_size =
1443 convert_to_section_size_type(this->data_size());
1444 unsigned char* const oview = of->get_output_view(offset, oview_size);
1446 const off_t got_file_offset = this->got_plt_->offset();
1447 gold_assert(parameters->incremental_update()
1448 || (got_file_offset + this->got_plt_->data_size()
1449 == this->got_irelative_->offset()));
1450 const section_size_type got_size =
1451 convert_to_section_size_type(this->got_plt_->data_size()
1452 + this->got_irelative_->data_size());
1453 unsigned char* const got_view = of->get_output_view(got_file_offset,
1456 unsigned char* pov = oview;
1458 // The base address of the .plt section.
1459 typename elfcpp::Elf_types<size>::Elf_Addr plt_address = this->address();
1460 // The base address of the PLT portion of the .got section,
1461 // which is where the GOT pointer will point, and where the
1462 // three reserved GOT entries are located.
1463 typename elfcpp::Elf_types<size>::Elf_Addr got_address
1464 = this->got_plt_->address();
1466 this->fill_first_plt_entry(pov, got_address, plt_address);
1467 pov += this->get_plt_entry_size();
1469 unsigned char* got_pov = got_view;
1471 const int rel_size = elfcpp::Elf_sizes<size>::rela_size;
1473 unsigned int plt_offset = this->get_plt_entry_size();
1474 unsigned int plt_rel_offset = 0;
1475 unsigned int got_offset = 3 * size / 8;
1476 const unsigned int count = this->count_ + this->irelative_count_;
1477 // The first three entries in the GOT are reserved, and are written
1478 // by Output_data_got_plt_s390::do_write.
1479 got_pov += 3 * size / 8;
1481 for (unsigned int plt_index = 0;
1484 pov += plt_entry_size,
1485 got_pov += size / 8,
1486 plt_offset += plt_entry_size,
1487 plt_rel_offset += rel_size,
1488 got_offset += size / 8)
1490 // Set and adjust the PLT entry itself.
1491 unsigned int lazy_offset = this->fill_plt_entry(pov,
1492 got_address, plt_address,
1493 got_offset, plt_offset,
1496 // Set the entry in the GOT.
1497 elfcpp::Swap<size, true>::writeval(got_pov,
1498 plt_address + plt_offset + lazy_offset);
1501 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1502 gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size);
1504 of->write_output_view(offset, oview_size, oview);
1505 of->write_output_view(got_file_offset, got_size, got_view);
1508 // Get the GOT section, creating it if necessary.
1511 Output_data_got<size, true>*
1512 Target_s390<size>::got_section(Symbol_table* symtab, Layout* layout)
1514 if (this->got_ == NULL)
1516 gold_assert(symtab != NULL && layout != NULL);
1518 // When using -z now, we can treat .got as a relro section.
1519 // Without -z now, it is modified after program startup by lazy
1521 bool is_got_relro = parameters->options().now();
1522 Output_section_order got_order = (is_got_relro
1526 // The old GNU linker creates a .got.plt section. We just
1527 // create another set of data in the .got section. Note that we
1528 // always create a PLT if we create a GOT, although the PLT
1530 this->got_plt_ = new Output_data_got_plt_s390<size>(layout);
1531 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1532 (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE),
1533 this->got_plt_, got_order, is_got_relro);
1535 // The first three entries are reserved.
1536 this->got_plt_->set_current_data_size(3 * size / 8);
1538 // If there are any IRELATIVE relocations, they get GOT entries
1539 // in .got.plt after the jump slot entries.
1540 this->got_irelative_ = new Output_data_space(size / 8, "** GOT IRELATIVE PLT");
1541 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1542 (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE),
1543 this->got_irelative_,
1544 got_order, is_got_relro);
1546 // Unlike some targets (.e.g x86), S/390 does not use separate .got and
1547 // .got.plt sections in output. The output .got section contains both
1548 // PLT and non-PLT GOT entries.
1549 this->got_ = new Output_data_got<size, true>();
1551 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1552 (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE),
1553 this->got_, got_order, is_got_relro);
1555 // Define _GLOBAL_OFFSET_TABLE_ at the start of the GOT.
1556 this->global_offset_table_ =
1557 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1558 Symbol_table::PREDEFINED,
1560 0, 0, elfcpp::STT_OBJECT,
1562 elfcpp::STV_HIDDEN, 0,
1569 // Get the dynamic reloc section, creating it if necessary.
1572 typename Target_s390<size>::Reloc_section*
1573 Target_s390<size>::rela_dyn_section(Layout* layout)
1575 if (this->rela_dyn_ == NULL)
1577 gold_assert(layout != NULL);
1578 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1579 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1580 elfcpp::SHF_ALLOC, this->rela_dyn_,
1581 ORDER_DYNAMIC_RELOCS, false);
1583 return this->rela_dyn_;
1586 // Get the section to use for IRELATIVE relocs, creating it if
1587 // necessary. These go in .rela.dyn, but only after all other dynamic
1588 // relocations. They need to follow the other dynamic relocations so
1589 // that they can refer to global variables initialized by those
1593 typename Target_s390<size>::Reloc_section*
1594 Target_s390<size>::rela_irelative_section(Layout* layout)
1596 if (this->rela_irelative_ == NULL)
1598 // Make sure we have already created the dynamic reloc section.
1599 this->rela_dyn_section(layout);
1600 this->rela_irelative_ = new Reloc_section(false);
1601 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1602 elfcpp::SHF_ALLOC, this->rela_irelative_,
1603 ORDER_DYNAMIC_RELOCS, false);
1604 gold_assert(this->rela_dyn_->output_section()
1605 == this->rela_irelative_->output_section());
1607 return this->rela_irelative_;
1610 // Write the first three reserved words of the .got.plt section.
1611 // The remainder of the section is written while writing the PLT
1612 // in Output_data_plt_s390::do_write.
1616 Output_data_got_plt_s390<size>::do_write(Output_file* of)
1618 // The first entry in the GOT is the address of the .dynamic section
1619 // aka the PT_DYNAMIC segment. The next two entries are reserved.
1620 // We saved space for them when we created the section in
1621 // Target_x86_64::got_section.
1622 const off_t got_file_offset = this->offset();
1623 gold_assert(this->data_size() >= 3 * size / 8);
1624 unsigned char* const got_view =
1625 of->get_output_view(got_file_offset, 3 * size / 8);
1626 Output_section* dynamic = this->layout_->dynamic_section();
1627 uint64_t dynamic_addr = dynamic == NULL ? 0 : dynamic->address();
1628 elfcpp::Swap<size, true>::writeval(got_view, dynamic_addr);
1629 memset(got_view + size / 8, 0, 2 * size / 8);
1630 of->write_output_view(got_file_offset, 3 * size / 8, got_view);
1633 // Create the PLT section.
1637 Target_s390<size>::make_plt_section(Symbol_table* symtab, Layout* layout)
1639 if (this->plt_ == NULL)
1641 // Create the GOT sections first.
1642 this->got_section(symtab, layout);
1644 // Ensure that .rela.dyn always appears before .rela.plt This is
1645 // necessary due to how, on 32-bit S/390 and some other targets,
1646 // .rela.dyn needs to include .rela.plt in it's range.
1647 this->rela_dyn_section(layout);
1649 this->plt_ = new Output_data_plt_s390<size>(layout,
1650 this->got_, this->got_plt_, this->got_irelative_);
1652 // Add unwind information if requested.
1653 if (parameters->options().ld_generated_unwind_info())
1654 this->plt_->add_eh_frame(layout);
1656 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1658 | elfcpp::SHF_EXECINSTR),
1659 this->plt_, ORDER_PLT, false);
1661 // Make the sh_info field of .rela.plt point to .plt.
1662 Output_section* rela_plt_os = this->plt_->rela_plt()->output_section();
1663 rela_plt_os->set_info_section(this->plt_->output_section());
1667 // Create a PLT entry for a global symbol.
1671 Target_s390<size>::make_plt_entry(Symbol_table* symtab, Layout* layout,
1674 if (gsym->has_plt_offset())
1677 if (this->plt_ == NULL)
1678 this->make_plt_section(symtab, layout);
1680 this->plt_->add_entry(symtab, layout, gsym);
1683 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1687 Target_s390<size>::make_local_ifunc_plt_entry(
1688 Symbol_table* symtab, Layout* layout,
1689 Sized_relobj_file<size, true>* relobj,
1690 unsigned int local_sym_index)
1692 if (relobj->local_has_plt_offset(local_sym_index))
1694 if (this->plt_ == NULL)
1695 this->make_plt_section(symtab, layout);
1696 unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout,
1699 relobj->set_local_plt_offset(local_sym_index, plt_offset);
1702 // Return the number of entries in the PLT.
1706 Target_s390<size>::plt_entry_count() const
1708 if (this->plt_ == NULL)
1710 return this->plt_->entry_count();
1713 // Return the offset of the first non-reserved PLT entry.
1717 Target_s390<size>::first_plt_entry_offset() const
1719 return this->plt_->first_plt_entry_offset();
1722 // Return the size of each PLT entry.
1726 Target_s390<size>::plt_entry_size() const
1728 return this->plt_->get_plt_entry_size();
1731 // Create the GOT and PLT sections for an incremental update.
1734 Output_data_got_base*
1735 Target_s390<size>::init_got_plt_for_update(Symbol_table* symtab,
1737 unsigned int got_count,
1738 unsigned int plt_count)
1740 gold_assert(this->got_ == NULL);
1742 // Add the three reserved entries.
1743 this->got_plt_ = new Output_data_got_plt_s390<size>(layout, (plt_count + 3) * size / 8);
1744 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1746 | elfcpp::SHF_WRITE),
1747 this->got_plt_, ORDER_NON_RELRO_FIRST,
1750 // If there are any IRELATIVE relocations, they get GOT entries in
1751 // .got.plt after the jump slot entries.
1752 this->got_irelative_ = new Output_data_space(0, size / 8, "** GOT IRELATIVE PLT");
1753 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1754 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
1755 this->got_irelative_,
1756 ORDER_NON_RELRO_FIRST, false);
1758 this->got_ = new Output_data_got<size, true>(got_count * size / 8);
1759 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1761 | elfcpp::SHF_WRITE),
1762 this->got_, ORDER_RELRO_LAST,
1765 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
1766 this->global_offset_table_ =
1767 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1768 Symbol_table::PREDEFINED,
1770 0, 0, elfcpp::STT_OBJECT,
1772 elfcpp::STV_HIDDEN, 0,
1775 // Create the PLT section.
1776 this->plt_ = new Output_data_plt_s390<size>(layout,
1777 this->got_, this->got_plt_, this->got_irelative_, plt_count);
1779 // Add unwind information if requested.
1780 if (parameters->options().ld_generated_unwind_info())
1781 this->plt_->add_eh_frame(layout);
1783 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1784 elfcpp::SHF_ALLOC | elfcpp::SHF_EXECINSTR,
1785 this->plt_, ORDER_PLT, false);
1787 // Make the sh_info field of .rela.plt point to .plt.
1788 Output_section* rela_plt_os = this->plt_->rela_plt()->output_section();
1789 rela_plt_os->set_info_section(this->plt_->output_section());
1791 // Create the rela_dyn section.
1792 this->rela_dyn_section(layout);
1797 // Reserve a GOT entry for a local symbol, and regenerate any
1798 // necessary dynamic relocations.
1802 Target_s390<size>::reserve_local_got_entry(
1803 unsigned int got_index,
1804 Sized_relobj<size, true>* obj,
1806 unsigned int got_type)
1808 unsigned int got_offset = got_index * size / 8;
1809 Reloc_section* rela_dyn = this->rela_dyn_section(NULL);
1811 this->got_->reserve_local(got_index, obj, r_sym, got_type);
1814 case GOT_TYPE_STANDARD:
1815 if (parameters->options().output_is_position_independent())
1816 rela_dyn->add_local_relative(obj, r_sym, elfcpp::R_390_RELATIVE,
1817 this->got_, got_offset, 0, false);
1819 case GOT_TYPE_TLS_OFFSET:
1820 rela_dyn->add_local(obj, r_sym, elfcpp::R_390_TLS_TPOFF,
1821 this->got_, got_offset, 0);
1823 case GOT_TYPE_TLS_PAIR:
1824 this->got_->reserve_slot(got_index + 1);
1825 rela_dyn->add_local(obj, r_sym, elfcpp::R_390_TLS_DTPMOD,
1826 this->got_, got_offset, 0);
1833 // Reserve a GOT entry for a global symbol, and regenerate any
1834 // necessary dynamic relocations.
1838 Target_s390<size>::reserve_global_got_entry(unsigned int got_index,
1840 unsigned int got_type)
1842 unsigned int got_offset = got_index * size / 8;
1843 Reloc_section* rela_dyn = this->rela_dyn_section(NULL);
1845 this->got_->reserve_global(got_index, gsym, got_type);
1848 case GOT_TYPE_STANDARD:
1849 if (!gsym->final_value_is_known())
1851 if (gsym->is_from_dynobj()
1852 || gsym->is_undefined()
1853 || gsym->is_preemptible()
1854 || gsym->type() == elfcpp::STT_GNU_IFUNC)
1855 rela_dyn->add_global(gsym, elfcpp::R_390_GLOB_DAT,
1856 this->got_, got_offset, 0);
1858 rela_dyn->add_global_relative(gsym, elfcpp::R_390_RELATIVE,
1859 this->got_, got_offset, 0, false);
1862 case GOT_TYPE_TLS_OFFSET:
1863 rela_dyn->add_global_relative(gsym, elfcpp::R_390_TLS_TPOFF,
1864 this->got_, got_offset, 0, false);
1866 case GOT_TYPE_TLS_PAIR:
1867 this->got_->reserve_slot(got_index + 1);
1868 rela_dyn->add_global_relative(gsym, elfcpp::R_390_TLS_DTPMOD,
1869 this->got_, got_offset, 0, false);
1870 rela_dyn->add_global_relative(gsym, elfcpp::R_390_TLS_DTPOFF,
1871 this->got_, got_offset + size / 8, 0, false);
1878 // Register an existing PLT entry for a global symbol.
1882 Target_s390<size>::register_global_plt_entry(Symbol_table* symtab,
1884 unsigned int plt_index,
1887 gold_assert(this->plt_ != NULL);
1888 gold_assert(!gsym->has_plt_offset());
1890 this->plt_->reserve_slot(plt_index);
1892 gsym->set_plt_offset((plt_index + 1) * this->plt_entry_size());
1894 unsigned int got_offset = (plt_index + 3) * size / 8;
1895 this->plt_->add_relocation(symtab, layout, gsym, got_offset);
1898 // Force a COPY relocation for a given symbol.
1902 Target_s390<size>::emit_copy_reloc(
1903 Symbol_table* symtab, Symbol* sym, Output_section* os, off_t offset)
1905 this->copy_relocs_.emit_copy_reloc(symtab,
1906 symtab->get_sized_symbol<size>(sym),
1909 this->rela_dyn_section(NULL));
1912 // Create a GOT entry for the TLS module index.
1916 Target_s390<size>::got_mod_index_entry(Symbol_table* symtab, Layout* layout,
1917 Sized_relobj_file<size, true>* object)
1919 if (this->got_mod_index_offset_ == -1U)
1921 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1922 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1923 Output_data_got<size, true>* got = this->got_section(symtab, layout);
1924 unsigned int got_offset = got->add_constant(0);
1925 rela_dyn->add_local(object, 0, elfcpp::R_390_TLS_DTPMOD, got,
1927 got->add_constant(0);
1928 this->got_mod_index_offset_ = got_offset;
1930 return this->got_mod_index_offset_;
1933 // Optimize the TLS relocation type based on what we know about the
1934 // symbol. IS_FINAL is true if the final address of this symbol is
1935 // known at link time.
1938 tls::Tls_optimization
1939 Target_s390<size>::optimize_tls_reloc(bool is_final, int r_type)
1941 // If we are generating a shared library, then we can't do anything
1943 if (parameters->options().shared())
1944 return tls::TLSOPT_NONE;
1948 case elfcpp::R_390_TLS_GD32:
1949 case elfcpp::R_390_TLS_GD64:
1950 case elfcpp::R_390_TLS_GDCALL:
1951 // These are General-Dynamic which permits fully general TLS
1952 // access. Since we know that we are generating an executable,
1953 // we can convert this to Initial-Exec. If we also know that
1954 // this is a local symbol, we can further switch to Local-Exec.
1956 return tls::TLSOPT_TO_LE;
1957 return tls::TLSOPT_TO_IE;
1959 case elfcpp::R_390_TLS_LDM32:
1960 case elfcpp::R_390_TLS_LDM64:
1961 case elfcpp::R_390_TLS_LDO32:
1962 case elfcpp::R_390_TLS_LDO64:
1963 case elfcpp::R_390_TLS_LDCALL:
1964 // This is Local-Dynamic, which refers to a local symbol in the
1965 // dynamic TLS block. Since we know that we generating an
1966 // executable, we can switch to Local-Exec.
1967 return tls::TLSOPT_TO_LE;
1969 case elfcpp::R_390_TLS_IE32:
1970 case elfcpp::R_390_TLS_IE64:
1971 case elfcpp::R_390_TLS_GOTIE32:
1972 case elfcpp::R_390_TLS_GOTIE64:
1973 case elfcpp::R_390_TLS_LOAD:
1974 // These are Initial-Exec relocs which get the thread offset
1975 // from the GOT. If we know that we are linking against the
1976 // local symbol, we can switch to Local-Exec, which links the
1977 // thread offset into the instruction.
1979 return tls::TLSOPT_TO_LE;
1980 return tls::TLSOPT_NONE;
1982 case elfcpp::R_390_TLS_GOTIE12:
1983 case elfcpp::R_390_TLS_IEENT:
1984 case elfcpp::R_390_TLS_GOTIE20:
1985 // These are Initial-Exec, but cannot be optimized.
1986 return tls::TLSOPT_NONE;
1988 case elfcpp::R_390_TLS_LE32:
1989 case elfcpp::R_390_TLS_LE64:
1990 // When we already have Local-Exec, there is nothing further we
1992 return tls::TLSOPT_NONE;
1999 // Get the Reference_flags for a particular relocation.
2003 Target_s390<size>::Scan::get_reference_flags(unsigned int r_type)
2007 case elfcpp::R_390_NONE:
2008 case elfcpp::R_390_GNU_VTINHERIT:
2009 case elfcpp::R_390_GNU_VTENTRY:
2010 case elfcpp::R_390_GOTPC:
2011 case elfcpp::R_390_GOTPCDBL:
2012 // No symbol reference.
2015 case elfcpp::R_390_64:
2016 case elfcpp::R_390_32:
2017 case elfcpp::R_390_20:
2018 case elfcpp::R_390_16:
2019 case elfcpp::R_390_12:
2020 case elfcpp::R_390_8:
2021 return Symbol::ABSOLUTE_REF;
2023 case elfcpp::R_390_PC12DBL:
2024 case elfcpp::R_390_PC16:
2025 case elfcpp::R_390_PC16DBL:
2026 case elfcpp::R_390_PC24DBL:
2027 case elfcpp::R_390_PC32:
2028 case elfcpp::R_390_PC32DBL:
2029 case elfcpp::R_390_PC64:
2030 case elfcpp::R_390_GOTOFF16:
2031 case elfcpp::R_390_GOTOFF32:
2032 case elfcpp::R_390_GOTOFF64:
2033 return Symbol::RELATIVE_REF;
2035 case elfcpp::R_390_PLT12DBL:
2036 case elfcpp::R_390_PLT16DBL:
2037 case elfcpp::R_390_PLT24DBL:
2038 case elfcpp::R_390_PLT32:
2039 case elfcpp::R_390_PLT32DBL:
2040 case elfcpp::R_390_PLT64:
2041 case elfcpp::R_390_PLTOFF16:
2042 case elfcpp::R_390_PLTOFF32:
2043 case elfcpp::R_390_PLTOFF64:
2044 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
2046 case elfcpp::R_390_GOT12:
2047 case elfcpp::R_390_GOT16:
2048 case elfcpp::R_390_GOT20:
2049 case elfcpp::R_390_GOT32:
2050 case elfcpp::R_390_GOT64:
2051 case elfcpp::R_390_GOTENT:
2052 case elfcpp::R_390_GOTPLT12:
2053 case elfcpp::R_390_GOTPLT16:
2054 case elfcpp::R_390_GOTPLT20:
2055 case elfcpp::R_390_GOTPLT32:
2056 case elfcpp::R_390_GOTPLT64:
2057 case elfcpp::R_390_GOTPLTENT:
2059 return Symbol::ABSOLUTE_REF;
2061 case elfcpp::R_390_TLS_GD32: // Global-dynamic
2062 case elfcpp::R_390_TLS_GD64:
2063 case elfcpp::R_390_TLS_GDCALL:
2064 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2065 case elfcpp::R_390_TLS_LDM64:
2066 case elfcpp::R_390_TLS_LDO32:
2067 case elfcpp::R_390_TLS_LDO64:
2068 case elfcpp::R_390_TLS_LDCALL:
2069 case elfcpp::R_390_TLS_IE32: // Initial-exec
2070 case elfcpp::R_390_TLS_IE64:
2071 case elfcpp::R_390_TLS_IEENT:
2072 case elfcpp::R_390_TLS_GOTIE12:
2073 case elfcpp::R_390_TLS_GOTIE20:
2074 case elfcpp::R_390_TLS_GOTIE32:
2075 case elfcpp::R_390_TLS_GOTIE64:
2076 case elfcpp::R_390_TLS_LOAD:
2077 case elfcpp::R_390_TLS_LE32: // Local-exec
2078 case elfcpp::R_390_TLS_LE64:
2079 return Symbol::TLS_REF;
2081 case elfcpp::R_390_COPY:
2082 case elfcpp::R_390_GLOB_DAT:
2083 case elfcpp::R_390_JMP_SLOT:
2084 case elfcpp::R_390_RELATIVE:
2085 case elfcpp::R_390_IRELATIVE:
2086 case elfcpp::R_390_TLS_TPOFF:
2087 case elfcpp::R_390_TLS_DTPOFF:
2088 case elfcpp::R_390_TLS_DTPMOD:
2090 // Not expected. We will give an error later.
2095 // Report an unsupported relocation against a local symbol.
2099 Target_s390<size>::Scan::unsupported_reloc_local(
2100 Sized_relobj_file<size, true>* object,
2101 unsigned int r_type)
2103 gold_error(_("%s: unsupported reloc %u against local symbol"),
2104 object->name().c_str(), r_type);
2107 // We are about to emit a dynamic relocation of type R_TYPE. If the
2108 // dynamic linker does not support it, issue an error.
2112 Target_s390<size>::Scan::check_non_pic(Relobj* object, unsigned int r_type)
2114 gold_assert(r_type != elfcpp::R_390_NONE);
2120 // These are the relocation types supported by glibc for s390 64-bit.
2121 case elfcpp::R_390_RELATIVE:
2122 case elfcpp::R_390_IRELATIVE:
2123 case elfcpp::R_390_COPY:
2124 case elfcpp::R_390_GLOB_DAT:
2125 case elfcpp::R_390_JMP_SLOT:
2126 case elfcpp::R_390_TLS_DTPMOD:
2127 case elfcpp::R_390_TLS_DTPOFF:
2128 case elfcpp::R_390_TLS_TPOFF:
2129 case elfcpp::R_390_8:
2130 case elfcpp::R_390_16:
2131 case elfcpp::R_390_32:
2132 case elfcpp::R_390_64:
2133 case elfcpp::R_390_PC16:
2134 case elfcpp::R_390_PC16DBL:
2135 case elfcpp::R_390_PC32:
2136 case elfcpp::R_390_PC32DBL:
2137 case elfcpp::R_390_PC64:
2148 // These are the relocation types supported by glibc for s390 32-bit.
2149 case elfcpp::R_390_RELATIVE:
2150 case elfcpp::R_390_IRELATIVE:
2151 case elfcpp::R_390_COPY:
2152 case elfcpp::R_390_GLOB_DAT:
2153 case elfcpp::R_390_JMP_SLOT:
2154 case elfcpp::R_390_TLS_DTPMOD:
2155 case elfcpp::R_390_TLS_DTPOFF:
2156 case elfcpp::R_390_TLS_TPOFF:
2157 case elfcpp::R_390_8:
2158 case elfcpp::R_390_16:
2159 case elfcpp::R_390_32:
2160 case elfcpp::R_390_PC16:
2161 case elfcpp::R_390_PC16DBL:
2162 case elfcpp::R_390_PC32:
2163 case elfcpp::R_390_PC32DBL:
2171 // This prevents us from issuing more than one error per reloc
2172 // section. But we can still wind up issuing more than one
2173 // error per object file.
2174 if (this->issued_non_pic_error_)
2176 gold_assert(parameters->options().output_is_position_independent());
2177 object->error(_("requires unsupported dynamic reloc; "
2178 "recompile with -fPIC"));
2179 this->issued_non_pic_error_ = true;
2183 // Return whether we need to make a PLT entry for a relocation of the
2184 // given type against a STT_GNU_IFUNC symbol.
2188 Target_s390<size>::Scan::reloc_needs_plt_for_ifunc(
2189 Sized_relobj_file<size, true>* object,
2190 unsigned int r_type)
2192 int flags = Scan::get_reference_flags(r_type);
2193 if (flags & Symbol::TLS_REF)
2194 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2195 object->name().c_str(), r_type);
2199 // Scan a relocation for a local symbol.
2203 Target_s390<size>::Scan::local(Symbol_table* symtab,
2205 Target_s390<size>* target,
2206 Sized_relobj_file<size, true>* object,
2207 unsigned int data_shndx,
2208 Output_section* output_section,
2209 const elfcpp::Rela<size, true>& reloc,
2210 unsigned int r_type,
2211 const elfcpp::Sym<size, true>& lsym,
2217 // A local STT_GNU_IFUNC symbol may require a PLT entry.
2218 bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
2220 if (is_ifunc && this->reloc_needs_plt_for_ifunc(object, r_type))
2222 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2223 target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
2228 case elfcpp::R_390_NONE:
2229 case elfcpp::R_390_GNU_VTINHERIT:
2230 case elfcpp::R_390_GNU_VTENTRY:
2233 case elfcpp::R_390_64:
2234 // If building a shared library (or a position-independent
2235 // executable), we need to create a dynamic relocation for this
2236 // location. The relocation applied at link time will apply the
2237 // link-time value, so we flag the location with an
2238 // R_390_RELATIVE relocation so the dynamic loader can
2239 // relocate it easily.
2240 if (parameters->options().output_is_position_independent() && size == 64)
2242 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2243 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2244 rela_dyn->add_local_relative(object, r_sym,
2245 elfcpp::R_390_RELATIVE,
2246 output_section, data_shndx,
2247 reloc.get_r_offset(),
2248 reloc.get_r_addend(), is_ifunc);
2252 case elfcpp::R_390_32:
2253 case elfcpp::R_390_20:
2254 case elfcpp::R_390_16:
2255 case elfcpp::R_390_12:
2256 case elfcpp::R_390_8:
2257 if (parameters->options().output_is_position_independent())
2259 if (size == 32 && r_type == elfcpp::R_390_32)
2261 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2262 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2263 rela_dyn->add_local_relative(object, r_sym,
2264 elfcpp::R_390_RELATIVE,
2265 output_section, data_shndx,
2266 reloc.get_r_offset(),
2267 reloc.get_r_addend(), is_ifunc);
2271 check_non_pic(object, r_type);
2273 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2274 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2275 if (lsym.get_st_type() != elfcpp::STT_SECTION)
2276 rela_dyn->add_local(object, r_sym, r_type, output_section,
2277 data_shndx, reloc.get_r_offset(),
2278 reloc.get_r_addend());
2281 gold_assert(lsym.get_st_value() == 0);
2282 unsigned int shndx = lsym.get_st_shndx();
2284 shndx = object->adjust_sym_shndx(r_sym, shndx,
2287 object->error(_("section symbol %u has bad shndx %u"),
2290 rela_dyn->add_local_section(object, shndx,
2291 r_type, output_section,
2292 data_shndx, reloc.get_r_offset(),
2293 reloc.get_r_addend());
2298 case elfcpp::R_390_PC12DBL:
2299 case elfcpp::R_390_PC16:
2300 case elfcpp::R_390_PC16DBL:
2301 case elfcpp::R_390_PC24DBL:
2302 case elfcpp::R_390_PC32:
2303 case elfcpp::R_390_PC32DBL:
2304 case elfcpp::R_390_PC64:
2307 case elfcpp::R_390_PLT12DBL:
2308 case elfcpp::R_390_PLT16DBL:
2309 case elfcpp::R_390_PLT24DBL:
2310 case elfcpp::R_390_PLT32:
2311 case elfcpp::R_390_PLT32DBL:
2312 case elfcpp::R_390_PLT64:
2313 // Since we know this is a local symbol, we can handle this as a
2317 case elfcpp::R_390_GOTPC:
2318 case elfcpp::R_390_GOTPCDBL:
2319 case elfcpp::R_390_GOTOFF16:
2320 case elfcpp::R_390_GOTOFF32:
2321 case elfcpp::R_390_GOTOFF64:
2322 case elfcpp::R_390_PLTOFF16:
2323 case elfcpp::R_390_PLTOFF32:
2324 case elfcpp::R_390_PLTOFF64:
2325 // We need a GOT section.
2326 target->got_section(symtab, layout);
2327 // For PLTOFF*, we'd normally want a PLT section, but since we
2328 // know this is a local symbol, no PLT is needed.
2331 case elfcpp::R_390_GOT12:
2332 case elfcpp::R_390_GOT16:
2333 case elfcpp::R_390_GOT20:
2334 case elfcpp::R_390_GOT32:
2335 case elfcpp::R_390_GOT64:
2336 case elfcpp::R_390_GOTENT:
2337 case elfcpp::R_390_GOTPLT12:
2338 case elfcpp::R_390_GOTPLT16:
2339 case elfcpp::R_390_GOTPLT20:
2340 case elfcpp::R_390_GOTPLT32:
2341 case elfcpp::R_390_GOTPLT64:
2342 case elfcpp::R_390_GOTPLTENT:
2344 // The symbol requires a GOT section.
2345 Output_data_got<size, true>* got = target->got_section(symtab, layout);
2347 // The symbol requires a GOT entry.
2348 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2350 // For a STT_GNU_IFUNC symbol we want the PLT offset. That
2351 // lets function pointers compare correctly with shared
2352 // libraries. Otherwise we would need an IRELATIVE reloc.
2355 is_new = got->add_local_plt(object, r_sym, GOT_TYPE_STANDARD);
2357 is_new = got->add_local(object, r_sym, GOT_TYPE_STANDARD);
2360 // If we are generating a shared object, we need to add a
2361 // dynamic relocation for this symbol's GOT entry.
2362 if (parameters->options().output_is_position_independent())
2364 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2365 unsigned int got_offset =
2366 object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
2367 rela_dyn->add_local_relative(object, r_sym,
2368 elfcpp::R_390_RELATIVE,
2369 got, got_offset, 0, is_ifunc);
2372 // For GOTPLT*, we'd normally want a PLT section, but since
2373 // we know this is a local symbol, no PLT is needed.
2377 case elfcpp::R_390_COPY:
2378 case elfcpp::R_390_GLOB_DAT:
2379 case elfcpp::R_390_JMP_SLOT:
2380 case elfcpp::R_390_RELATIVE:
2381 case elfcpp::R_390_IRELATIVE:
2382 // These are outstanding tls relocs, which are unexpected when linking
2383 case elfcpp::R_390_TLS_TPOFF:
2384 case elfcpp::R_390_TLS_DTPOFF:
2385 case elfcpp::R_390_TLS_DTPMOD:
2386 gold_error(_("%s: unexpected reloc %u in object file"),
2387 object->name().c_str(), r_type);
2390 // These are initial tls relocs, which are expected when linking
2391 case elfcpp::R_390_TLS_GD32: // Global-dynamic
2392 case elfcpp::R_390_TLS_GD64:
2393 case elfcpp::R_390_TLS_GDCALL:
2394 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2395 case elfcpp::R_390_TLS_LDM64:
2396 case elfcpp::R_390_TLS_LDO32:
2397 case elfcpp::R_390_TLS_LDO64:
2398 case elfcpp::R_390_TLS_LDCALL:
2399 case elfcpp::R_390_TLS_IE32: // Initial-exec
2400 case elfcpp::R_390_TLS_IE64:
2401 case elfcpp::R_390_TLS_IEENT:
2402 case elfcpp::R_390_TLS_GOTIE12:
2403 case elfcpp::R_390_TLS_GOTIE20:
2404 case elfcpp::R_390_TLS_GOTIE32:
2405 case elfcpp::R_390_TLS_GOTIE64:
2406 case elfcpp::R_390_TLS_LOAD:
2407 case elfcpp::R_390_TLS_LE32: // Local-exec
2408 case elfcpp::R_390_TLS_LE64:
2410 bool output_is_shared = parameters->options().shared();
2411 const tls::Tls_optimization optimized_type
2412 = Target_s390<size>::optimize_tls_reloc(!output_is_shared,
2416 case elfcpp::R_390_TLS_GD32: // General-dynamic
2417 case elfcpp::R_390_TLS_GD64:
2418 case elfcpp::R_390_TLS_GDCALL:
2419 if (optimized_type == tls::TLSOPT_NONE)
2421 // Create a pair of GOT entries for the module index and
2422 // dtv-relative offset.
2423 Output_data_got<size, true>* got
2424 = target->got_section(symtab, layout);
2425 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2426 unsigned int shndx = lsym.get_st_shndx();
2428 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
2430 object->error(_("local symbol %u has bad shndx %u"),
2433 got->add_local_pair_with_rel(object, r_sym,
2436 target->rela_dyn_section(layout),
2437 elfcpp::R_390_TLS_DTPMOD);
2439 else if (optimized_type != tls::TLSOPT_TO_LE)
2440 unsupported_reloc_local(object, r_type);
2443 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2444 case elfcpp::R_390_TLS_LDM64:
2445 case elfcpp::R_390_TLS_LDCALL:
2446 if (optimized_type == tls::TLSOPT_NONE)
2448 // Create a GOT entry for the module index.
2449 target->got_mod_index_entry(symtab, layout, object);
2451 else if (optimized_type != tls::TLSOPT_TO_LE)
2452 unsupported_reloc_local(object, r_type);
2455 case elfcpp::R_390_TLS_LDO32:
2456 case elfcpp::R_390_TLS_LDO64:
2459 case elfcpp::R_390_TLS_IE32: // Initial-exec
2460 case elfcpp::R_390_TLS_IE64:
2461 // These two involve an absolute address
2462 if (parameters->options().shared()
2463 && optimized_type == tls::TLSOPT_NONE)
2465 if ((size == 32 && r_type == elfcpp::R_390_TLS_IE32) ||
2466 (size == 64 && r_type == elfcpp::R_390_TLS_IE64))
2468 // We need to create a dynamic relocation.
2469 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2470 unsigned int r_sym =
2471 elfcpp::elf_r_sym<size>(reloc.get_r_info());
2472 rela_dyn->add_local_relative(object, r_sym,
2473 elfcpp::R_390_RELATIVE,
2474 output_section, data_shndx,
2475 reloc.get_r_offset(),
2476 reloc.get_r_addend(), false);
2480 unsupported_reloc_local(object, r_type);
2484 case elfcpp::R_390_TLS_IEENT:
2485 case elfcpp::R_390_TLS_GOTIE12:
2486 case elfcpp::R_390_TLS_GOTIE20:
2487 case elfcpp::R_390_TLS_GOTIE32:
2488 case elfcpp::R_390_TLS_GOTIE64:
2489 case elfcpp::R_390_TLS_LOAD:
2490 layout->set_has_static_tls();
2491 if (optimized_type == tls::TLSOPT_NONE)
2493 if (!output_is_shared)
2495 // We're making an executable, and the symbol is local, but
2496 // we cannot optimize to LE. Make a const GOT entry instead.
2497 Output_data_got<size, true>* got
2498 = target->got_section(symtab, layout);
2500 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2501 got->add_local_plt(object, r_sym, GOT_TYPE_TLS_OFFSET);
2505 // Create a GOT entry for the tp-relative offset.
2506 Output_data_got<size, true>* got
2507 = target->got_section(symtab, layout);
2509 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2510 got->add_local_with_rel(object, r_sym, GOT_TYPE_TLS_OFFSET,
2511 target->rela_dyn_section(layout),
2512 elfcpp::R_390_TLS_TPOFF);
2515 else if (optimized_type != tls::TLSOPT_TO_LE)
2516 unsupported_reloc_local(object, r_type);
2519 case elfcpp::R_390_TLS_LE32: // Local-exec
2520 case elfcpp::R_390_TLS_LE64:
2521 layout->set_has_static_tls();
2522 if (output_is_shared)
2524 // We need to create a dynamic relocation.
2525 if ((size == 32 && r_type == elfcpp::R_390_TLS_LE32) ||
2526 (size == 64 && r_type == elfcpp::R_390_TLS_LE64))
2528 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2530 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2531 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
2532 rela_dyn->add_local(object, r_sym, elfcpp::R_390_TLS_TPOFF,
2533 output_section, data_shndx,
2534 reloc.get_r_offset(),
2535 reloc.get_r_addend());
2539 unsupported_reloc_local(object, r_type);
2551 gold_error(_("%s: unsupported reloc %u against local symbol"),
2552 object->name().c_str(), r_type);
2557 // Scan a relocation for a global symbol.
2561 Target_s390<size>::Scan::global(Symbol_table* symtab,
2563 Target_s390<size>* target,
2564 Sized_relobj_file<size, true>* object,
2565 unsigned int data_shndx,
2566 Output_section* output_section,
2567 const elfcpp::Rela<size, true>& reloc,
2568 unsigned int r_type,
2571 // A STT_GNU_IFUNC symbol may require a PLT entry.
2572 if (gsym->type() == elfcpp::STT_GNU_IFUNC
2573 && this->reloc_needs_plt_for_ifunc(object, r_type))
2574 target->make_plt_entry(symtab, layout, gsym);
2578 case elfcpp::R_390_NONE:
2579 case elfcpp::R_390_GNU_VTINHERIT:
2580 case elfcpp::R_390_GNU_VTENTRY:
2583 case elfcpp::R_390_64:
2584 case elfcpp::R_390_32:
2585 case elfcpp::R_390_20:
2586 case elfcpp::R_390_16:
2587 case elfcpp::R_390_12:
2588 case elfcpp::R_390_8:
2590 // Make a PLT entry if necessary.
2591 if (gsym->needs_plt_entry())
2593 target->make_plt_entry(symtab, layout, gsym);
2594 // Since this is not a PC-relative relocation, we may be
2595 // taking the address of a function. In that case we need to
2596 // set the entry in the dynamic symbol table to the address of
2598 if (gsym->is_from_dynobj() && !parameters->options().shared())
2599 gsym->set_needs_dynsym_value();
2601 // Make a dynamic relocation if necessary.
2602 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2604 if (!parameters->options().output_is_position_independent()
2605 && gsym->may_need_copy_reloc())
2607 target->copy_reloc(symtab, layout, object,
2608 data_shndx, output_section, gsym, reloc);
2610 else if (((size == 64 && r_type == elfcpp::R_390_64)
2611 || (size == 32 && r_type == elfcpp::R_390_32))
2612 && gsym->type() == elfcpp::STT_GNU_IFUNC
2613 && gsym->can_use_relative_reloc(false)
2614 && !gsym->is_from_dynobj()
2615 && !gsym->is_undefined()
2616 && !gsym->is_preemptible())
2618 // Use an IRELATIVE reloc for a locally defined
2619 // STT_GNU_IFUNC symbol. This makes a function
2620 // address in a PIE executable match the address in a
2621 // shared library that it links against.
2622 Reloc_section* rela_dyn =
2623 target->rela_irelative_section(layout);
2624 unsigned int r_type = elfcpp::R_390_IRELATIVE;
2625 rela_dyn->add_symbolless_global_addend(gsym, r_type,
2626 output_section, object,
2628 reloc.get_r_offset(),
2629 reloc.get_r_addend());
2631 else if (((size == 64 && r_type == elfcpp::R_390_64)
2632 || (size == 32 && r_type == elfcpp::R_390_32))
2633 && gsym->can_use_relative_reloc(false))
2635 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2636 rela_dyn->add_global_relative(gsym, elfcpp::R_390_RELATIVE,
2637 output_section, object,
2639 reloc.get_r_offset(),
2640 reloc.get_r_addend(), false);
2644 check_non_pic(object, r_type);
2645 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2646 rela_dyn->add_global(gsym, r_type, output_section, object,
2647 data_shndx, reloc.get_r_offset(),
2648 reloc.get_r_addend());
2654 case elfcpp::R_390_PC12DBL:
2655 case elfcpp::R_390_PC16:
2656 case elfcpp::R_390_PC16DBL:
2657 case elfcpp::R_390_PC24DBL:
2658 case elfcpp::R_390_PC32:
2659 case elfcpp::R_390_PC32DBL:
2660 case elfcpp::R_390_PC64:
2662 // Make a PLT entry if necessary.
2663 if (gsym->needs_plt_entry())
2665 target->make_plt_entry(symtab, layout, gsym);
2666 // larl is often used to take address of a function. Aim the
2667 // symbol at the PLT entry.
2668 if (gsym->is_from_dynobj() && !parameters->options().shared())
2669 gsym->set_needs_dynsym_value();
2671 // Make a dynamic relocation if necessary.
2672 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2674 if (parameters->options().output_is_executable()
2675 && gsym->may_need_copy_reloc())
2677 target->copy_reloc(symtab, layout, object,
2678 data_shndx, output_section, gsym, reloc);
2682 check_non_pic(object, r_type);
2683 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2684 rela_dyn->add_global(gsym, r_type, output_section, object,
2685 data_shndx, reloc.get_r_offset(),
2686 reloc.get_r_addend());
2692 case elfcpp::R_390_PLT12DBL:
2693 case elfcpp::R_390_PLT16DBL:
2694 case elfcpp::R_390_PLT24DBL:
2695 case elfcpp::R_390_PLT32:
2696 case elfcpp::R_390_PLT32DBL:
2697 case elfcpp::R_390_PLT64:
2698 // If the symbol is fully resolved, this is just a PC32 reloc.
2699 // Otherwise we need a PLT entry.
2700 if (gsym->final_value_is_known())
2702 // If building a shared library, we can also skip the PLT entry
2703 // if the symbol is defined in the output file and is protected
2705 if (gsym->is_defined()
2706 && !gsym->is_from_dynobj()
2707 && !gsym->is_preemptible())
2709 target->make_plt_entry(symtab, layout, gsym);
2712 case elfcpp::R_390_GOTPC:
2713 case elfcpp::R_390_GOTPCDBL:
2714 case elfcpp::R_390_GOTOFF16:
2715 case elfcpp::R_390_GOTOFF32:
2716 case elfcpp::R_390_GOTOFF64:
2717 case elfcpp::R_390_PLTOFF16:
2718 case elfcpp::R_390_PLTOFF32:
2719 case elfcpp::R_390_PLTOFF64:
2720 // We need a GOT section.
2721 target->got_section(symtab, layout);
2722 // For PLTOFF*, we also need a PLT entry (but only if the
2723 // symbol is not fully resolved).
2724 if ((r_type == elfcpp::R_390_PLTOFF16
2725 || r_type == elfcpp::R_390_PLTOFF32
2726 || r_type == elfcpp::R_390_PLTOFF64)
2727 && !gsym->final_value_is_known())
2728 target->make_plt_entry(symtab, layout, gsym);
2731 case elfcpp::R_390_GOT12:
2732 case elfcpp::R_390_GOT16:
2733 case elfcpp::R_390_GOT20:
2734 case elfcpp::R_390_GOT32:
2735 case elfcpp::R_390_GOT64:
2736 case elfcpp::R_390_GOTENT:
2737 case elfcpp::R_390_GOTPLT12:
2738 case elfcpp::R_390_GOTPLT16:
2739 case elfcpp::R_390_GOTPLT20:
2740 case elfcpp::R_390_GOTPLT32:
2741 case elfcpp::R_390_GOTPLT64:
2742 case elfcpp::R_390_GOTPLTENT:
2744 // The symbol requires a GOT entry.
2745 Output_data_got<size, true>* got = target->got_section(symtab, layout);
2747 if (gsym->final_value_is_known())
2749 // For a STT_GNU_IFUNC symbol we want the PLT address.
2750 if (gsym->type() == elfcpp::STT_GNU_IFUNC)
2751 got->add_global_plt(gsym, GOT_TYPE_STANDARD);
2753 got->add_global(gsym, GOT_TYPE_STANDARD);
2757 // If this symbol is not fully resolved, we need to add a
2758 // dynamic relocation for it.
2759 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2761 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2763 // 1) The symbol may be defined in some other module.
2765 // 2) We are building a shared library and this is a
2766 // protected symbol; using GLOB_DAT means that the dynamic
2767 // linker can use the address of the PLT in the main
2768 // executable when appropriate so that function address
2769 // comparisons work.
2771 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2772 // code, again so that function address comparisons work.
2773 if (gsym->is_from_dynobj()
2774 || gsym->is_undefined()
2775 || gsym->is_preemptible()
2776 || (gsym->visibility() == elfcpp::STV_PROTECTED
2777 && parameters->options().shared())
2778 || (gsym->type() == elfcpp::STT_GNU_IFUNC
2779 && parameters->options().output_is_position_independent()))
2780 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn,
2781 elfcpp::R_390_GLOB_DAT);
2784 // For a STT_GNU_IFUNC symbol we want to write the PLT
2785 // offset into the GOT, so that function pointer
2786 // comparisons work correctly.
2788 if (gsym->type() != elfcpp::STT_GNU_IFUNC)
2789 is_new = got->add_global(gsym, GOT_TYPE_STANDARD);
2792 is_new = got->add_global_plt(gsym, GOT_TYPE_STANDARD);
2793 // Tell the dynamic linker to use the PLT address
2794 // when resolving relocations.
2795 if (gsym->is_from_dynobj()
2796 && !parameters->options().shared())
2797 gsym->set_needs_dynsym_value();
2801 unsigned int got_off = gsym->got_offset(GOT_TYPE_STANDARD);
2802 rela_dyn->add_global_relative(gsym,
2803 elfcpp::R_390_RELATIVE,
2804 got, got_off, 0, false);
2811 case elfcpp::R_390_COPY:
2812 case elfcpp::R_390_GLOB_DAT:
2813 case elfcpp::R_390_JMP_SLOT:
2814 case elfcpp::R_390_RELATIVE:
2815 case elfcpp::R_390_IRELATIVE:
2816 // These are outstanding tls relocs, which are unexpected when linking
2817 case elfcpp::R_390_TLS_TPOFF:
2818 case elfcpp::R_390_TLS_DTPOFF:
2819 case elfcpp::R_390_TLS_DTPMOD:
2820 gold_error(_("%s: unexpected reloc %u in object file"),
2821 object->name().c_str(), r_type);
2824 // These are initial tls relocs, which are expected for global()
2825 case elfcpp::R_390_TLS_GD32: // Global-dynamic
2826 case elfcpp::R_390_TLS_GD64:
2827 case elfcpp::R_390_TLS_GDCALL:
2828 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2829 case elfcpp::R_390_TLS_LDM64:
2830 case elfcpp::R_390_TLS_LDO32:
2831 case elfcpp::R_390_TLS_LDO64:
2832 case elfcpp::R_390_TLS_LDCALL:
2833 case elfcpp::R_390_TLS_IE32: // Initial-exec
2834 case elfcpp::R_390_TLS_IE64:
2835 case elfcpp::R_390_TLS_IEENT:
2836 case elfcpp::R_390_TLS_GOTIE12:
2837 case elfcpp::R_390_TLS_GOTIE20:
2838 case elfcpp::R_390_TLS_GOTIE32:
2839 case elfcpp::R_390_TLS_GOTIE64:
2840 case elfcpp::R_390_TLS_LOAD:
2841 case elfcpp::R_390_TLS_LE32: // Local-exec
2842 case elfcpp::R_390_TLS_LE64:
2844 // For the optimizable Initial-Exec model, we can treat undef symbols
2845 // as final when building an executable.
2846 const bool is_final = (gsym->final_value_is_known() ||
2847 ((r_type == elfcpp::R_390_TLS_IE32 ||
2848 r_type == elfcpp::R_390_TLS_IE64 ||
2849 r_type == elfcpp::R_390_TLS_GOTIE32 ||
2850 r_type == elfcpp::R_390_TLS_GOTIE64) &&
2851 gsym->is_undefined() &&
2852 parameters->options().output_is_executable()));
2853 const tls::Tls_optimization optimized_type
2854 = Target_s390<size>::optimize_tls_reloc(is_final, r_type);
2857 case elfcpp::R_390_TLS_GD32: // General-dynamic
2858 case elfcpp::R_390_TLS_GD64:
2859 case elfcpp::R_390_TLS_GDCALL:
2860 if (optimized_type == tls::TLSOPT_NONE)
2862 // Create a pair of GOT entries for the module index and
2863 // dtv-relative offset.
2864 Output_data_got<size, true>* got
2865 = target->got_section(symtab, layout);
2866 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
2867 target->rela_dyn_section(layout),
2868 elfcpp::R_390_TLS_DTPMOD,
2869 elfcpp::R_390_TLS_DTPOFF);
2871 else if (optimized_type == tls::TLSOPT_TO_IE)
2873 // Create a GOT entry for the tp-relative offset.
2874 Output_data_got<size, true>* got
2875 = target->got_section(symtab, layout);
2876 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2877 target->rela_dyn_section(layout),
2878 elfcpp::R_390_TLS_TPOFF);
2880 else if (optimized_type != tls::TLSOPT_TO_LE)
2881 unsupported_reloc_global(object, r_type, gsym);
2884 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2885 case elfcpp::R_390_TLS_LDM64:
2886 case elfcpp::R_390_TLS_LDCALL:
2887 if (optimized_type == tls::TLSOPT_NONE)
2889 // Create a GOT entry for the module index.
2890 target->got_mod_index_entry(symtab, layout, object);
2892 else if (optimized_type != tls::TLSOPT_TO_LE)
2893 unsupported_reloc_global(object, r_type, gsym);
2896 case elfcpp::R_390_TLS_LDO32:
2897 case elfcpp::R_390_TLS_LDO64:
2900 case elfcpp::R_390_TLS_IE32: // Initial-exec
2901 case elfcpp::R_390_TLS_IE64:
2902 // These two involve an absolute address
2903 if (parameters->options().shared())
2905 if ((size == 32 && r_type == elfcpp::R_390_TLS_IE32) ||
2906 (size == 64 && r_type == elfcpp::R_390_TLS_IE64))
2908 // We need to create a dynamic relocation.
2909 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2910 rela_dyn->add_global_relative(gsym, elfcpp::R_390_RELATIVE,
2911 output_section, object,
2913 reloc.get_r_offset(),
2914 reloc.get_r_addend(), false);
2918 unsupported_reloc_global(object, r_type, gsym);
2922 case elfcpp::R_390_TLS_IEENT:
2923 case elfcpp::R_390_TLS_GOTIE12:
2924 case elfcpp::R_390_TLS_GOTIE20:
2925 case elfcpp::R_390_TLS_GOTIE32:
2926 case elfcpp::R_390_TLS_GOTIE64:
2927 case elfcpp::R_390_TLS_LOAD:
2928 layout->set_has_static_tls();
2929 if (optimized_type == tls::TLSOPT_NONE)
2931 if (is_final && !parameters->options().shared())
2933 // We're making an executable, and the symbol is local, but
2934 // we cannot optimize to LE. Make a const GOT entry instead.
2935 Output_data_got<size, true>* got
2936 = target->got_section(symtab, layout);
2937 got->add_global_plt(gsym, GOT_TYPE_TLS_OFFSET);
2941 // Create a GOT entry for the tp-relative offset.
2942 Output_data_got<size, true>* got
2943 = target->got_section(symtab, layout);
2944 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2945 target->rela_dyn_section(layout),
2946 elfcpp::R_390_TLS_TPOFF);
2949 else if (optimized_type != tls::TLSOPT_TO_LE)
2950 unsupported_reloc_global(object, r_type, gsym);
2953 case elfcpp::R_390_TLS_LE32: // Local-exec
2954 case elfcpp::R_390_TLS_LE64:
2955 layout->set_has_static_tls();
2956 if (parameters->options().shared())
2958 // We need to create a dynamic relocation.
2959 if ((size == 32 && r_type == elfcpp::R_390_TLS_LE32) ||
2960 (size == 64 && r_type == elfcpp::R_390_TLS_LE64))
2962 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2963 rela_dyn->add_global(gsym, elfcpp::R_390_TLS_TPOFF,
2964 output_section, object,
2965 data_shndx, reloc.get_r_offset(),
2966 reloc.get_r_addend());
2970 unsupported_reloc_global(object, r_type, gsym);
2982 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2983 object->name().c_str(), r_type,
2984 gsym->demangled_name().c_str());
2990 // Report an unsupported relocation against a global symbol.
2994 Target_s390<size>::Scan::unsupported_reloc_global(
2995 Sized_relobj_file<size, true>* object,
2996 unsigned int r_type,
2999 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3000 object->name().c_str(), r_type, gsym->demangled_name().c_str());
3003 // Returns true if this relocation type could be that of a function pointer.
3006 Target_s390<size>::Scan::possible_function_pointer_reloc(unsigned int r_type)
3010 case elfcpp::R_390_32:
3011 case elfcpp::R_390_64:
3012 case elfcpp::R_390_PC32DBL: // could be used by larl insn
3013 case elfcpp::R_390_GOT12:
3014 case elfcpp::R_390_GOT16:
3015 case elfcpp::R_390_GOT20:
3016 case elfcpp::R_390_GOT32:
3017 case elfcpp::R_390_GOT64:
3018 case elfcpp::R_390_GOTENT:
3019 case elfcpp::R_390_GOTOFF16:
3020 case elfcpp::R_390_GOTOFF32:
3021 case elfcpp::R_390_GOTOFF64:
3027 // For safe ICF, scan a relocation for a local symbol to check if it
3028 // corresponds to a function pointer being taken. In that case mark
3029 // the function whose pointer was taken as not foldable.
3033 Target_s390<size>::Scan::local_reloc_may_be_function_pointer(
3036 Target_s390<size>* ,
3037 Sized_relobj_file<size, true>* ,
3040 const elfcpp::Rela<size, true>& ,
3041 unsigned int r_type,
3042 const elfcpp::Sym<size, true>&)
3044 // When building a shared library, do not fold any local symbols.
3045 return (parameters->options().shared()
3046 || possible_function_pointer_reloc(r_type));
3049 // For safe ICF, scan a relocation for a global symbol to check if it
3050 // corresponds to a function pointer being taken. In that case mark
3051 // the function whose pointer was taken as not foldable.
3055 Target_s390<size>::Scan::global_reloc_may_be_function_pointer(
3058 Target_s390<size>* ,
3059 Sized_relobj_file<size, true>* ,
3062 const elfcpp::Rela<size, true>& ,
3063 unsigned int r_type,
3066 // When building a shared library, do not fold symbols whose visibility
3067 // is hidden, internal or protected.
3068 return ((parameters->options().shared()
3069 && (gsym->visibility() == elfcpp::STV_INTERNAL
3070 || gsym->visibility() == elfcpp::STV_PROTECTED
3071 || gsym->visibility() == elfcpp::STV_HIDDEN))
3072 || possible_function_pointer_reloc(r_type));
3077 Target_s390<size>::gc_process_relocs(Symbol_table* symtab,
3079 Sized_relobj_file<size, true>* object,
3080 unsigned int data_shndx,
3081 unsigned int sh_type,
3082 const unsigned char* prelocs,
3084 Output_section* output_section,
3085 bool needs_special_offset_handling,
3086 size_t local_symbol_count,
3087 const unsigned char* plocal_symbols)
3090 if (sh_type == elfcpp::SHT_REL)
3093 gold::gc_process_relocs<size, true, Target_s390<size>, elfcpp::SHT_RELA,
3094 typename Target_s390<size>::Scan,
3095 typename Target_s390<size>::Relocatable_size_for_reloc>(
3104 needs_special_offset_handling,
3109 // Perform a relocation.
3113 Target_s390<size>::Relocate::relocate(
3114 const Relocate_info<size, true>* relinfo,
3115 Target_s390<size>* target,
3118 const elfcpp::Rela<size, true>& rela,
3119 unsigned int r_type,
3120 const Sized_symbol<size>* gsym,
3121 const Symbol_value<size>* psymval,
3122 unsigned char* view,
3123 typename elfcpp::Elf_types<size>::Elf_Addr address,
3124 section_size_type view_size)
3129 const Sized_relobj_file<size, true>* object = relinfo->object;
3131 // Pick the value to use for symbols defined in the PLT.
3132 Symbol_value<size> symval;
3134 && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
3136 symval.set_output_value(target->plt_address_for_global(gsym));
3139 else if (gsym == NULL && psymval->is_ifunc_symbol())
3141 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3142 if (object->local_has_plt_offset(r_sym))
3144 symval.set_output_value(target->plt_address_for_local(object, r_sym));
3149 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3151 typename elfcpp::Elf_types<size>::Elf_Addr value = 0;
3155 case elfcpp::R_390_PLT64:
3156 case elfcpp::R_390_PLT32:
3157 case elfcpp::R_390_PLT32DBL:
3158 case elfcpp::R_390_PLT24DBL:
3159 case elfcpp::R_390_PLT16DBL:
3160 case elfcpp::R_390_PLT12DBL:
3161 gold_assert(gsym == NULL
3162 || gsym->has_plt_offset()
3163 || gsym->final_value_is_known()
3164 || (gsym->is_defined()
3165 && !gsym->is_from_dynobj()
3166 && !gsym->is_preemptible()));
3168 case elfcpp::R_390_8:
3169 case elfcpp::R_390_12:
3170 case elfcpp::R_390_16:
3171 case elfcpp::R_390_20:
3172 case elfcpp::R_390_32:
3173 case elfcpp::R_390_64:
3174 case elfcpp::R_390_PC16:
3175 case elfcpp::R_390_PC32:
3176 case elfcpp::R_390_PC64:
3177 case elfcpp::R_390_PC32DBL:
3178 case elfcpp::R_390_PC24DBL:
3179 case elfcpp::R_390_PC16DBL:
3180 case elfcpp::R_390_PC12DBL:
3181 value = psymval->value(object, addend);
3184 case elfcpp::R_390_GOTPC:
3185 case elfcpp::R_390_GOTPCDBL:
3186 gold_assert(gsym != NULL);
3187 value = target->got_address() + addend;
3190 case elfcpp::R_390_PLTOFF64:
3191 case elfcpp::R_390_PLTOFF32:
3192 case elfcpp::R_390_PLTOFF16:
3193 gold_assert(gsym == NULL
3194 || gsym->has_plt_offset()
3195 || gsym->final_value_is_known());
3197 case elfcpp::R_390_GOTOFF64:
3198 case elfcpp::R_390_GOTOFF32:
3199 case elfcpp::R_390_GOTOFF16:
3200 value = (psymval->value(object, addend)
3201 - target->got_address());
3204 case elfcpp::R_390_GOT12:
3205 case elfcpp::R_390_GOT16:
3206 case elfcpp::R_390_GOT20:
3207 case elfcpp::R_390_GOT32:
3208 case elfcpp::R_390_GOT64:
3209 case elfcpp::R_390_GOTENT:
3210 case elfcpp::R_390_GOTPLT12:
3211 case elfcpp::R_390_GOTPLT16:
3212 case elfcpp::R_390_GOTPLT20:
3213 case elfcpp::R_390_GOTPLT32:
3214 case elfcpp::R_390_GOTPLT64:
3215 case elfcpp::R_390_GOTPLTENT:
3217 unsigned int got_offset = 0;
3220 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
3221 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
3225 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3226 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
3227 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
3229 value = got_offset + target->got_main_offset() + addend;
3233 // These are initial tls relocs, which are expected when linking
3234 case elfcpp::R_390_TLS_LOAD:
3235 case elfcpp::R_390_TLS_GDCALL: // Global-dynamic
3236 case elfcpp::R_390_TLS_GD32:
3237 case elfcpp::R_390_TLS_GD64:
3238 case elfcpp::R_390_TLS_LDCALL: // Local-dynamic
3239 case elfcpp::R_390_TLS_LDM32:
3240 case elfcpp::R_390_TLS_LDM64:
3241 case elfcpp::R_390_TLS_LDO32:
3242 case elfcpp::R_390_TLS_LDO64:
3243 case elfcpp::R_390_TLS_GOTIE12: // Initial-exec
3244 case elfcpp::R_390_TLS_GOTIE20:
3245 case elfcpp::R_390_TLS_GOTIE32:
3246 case elfcpp::R_390_TLS_GOTIE64:
3247 case elfcpp::R_390_TLS_IE32:
3248 case elfcpp::R_390_TLS_IE64:
3249 case elfcpp::R_390_TLS_IEENT:
3250 case elfcpp::R_390_TLS_LE32: // Local-exec
3251 case elfcpp::R_390_TLS_LE64:
3252 value = this->relocate_tls(relinfo, target, relnum, rela, r_type, gsym, psymval,
3260 typename S390_relocate_functions<size>::Status status
3261 = S390_relocate_functions<size>::STATUS_OK;
3265 case elfcpp::R_390_NONE:
3266 case elfcpp::R_390_GNU_VTINHERIT:
3267 case elfcpp::R_390_GNU_VTENTRY:
3268 case elfcpp::R_390_TLS_GDCALL:
3269 case elfcpp::R_390_TLS_LDCALL:
3270 case elfcpp::R_390_TLS_LOAD:
3273 case elfcpp::R_390_64:
3274 case elfcpp::R_390_GOT64:
3275 case elfcpp::R_390_GOTPLT64:
3276 case elfcpp::R_390_PLTOFF64:
3277 case elfcpp::R_390_GOTOFF64:
3278 case elfcpp::R_390_TLS_GD64:
3279 case elfcpp::R_390_TLS_LDM64:
3280 case elfcpp::R_390_TLS_LDO64:
3281 case elfcpp::R_390_TLS_GOTIE64:
3282 case elfcpp::R_390_TLS_IE64:
3283 case elfcpp::R_390_TLS_LE64:
3284 Relocate_functions<size, true>::rela64(view, value, 0);
3287 case elfcpp::R_390_32:
3288 case elfcpp::R_390_GOT32:
3289 case elfcpp::R_390_GOTPLT32:
3290 case elfcpp::R_390_PLTOFF32:
3291 case elfcpp::R_390_GOTOFF32:
3292 case elfcpp::R_390_TLS_GD32:
3293 case elfcpp::R_390_TLS_LDM32:
3294 case elfcpp::R_390_TLS_LDO32:
3295 case elfcpp::R_390_TLS_GOTIE32:
3296 case elfcpp::R_390_TLS_IE32:
3297 case elfcpp::R_390_TLS_LE32:
3298 Relocate_functions<size, true>::rela32(view, value, 0);
3301 case elfcpp::R_390_20:
3302 case elfcpp::R_390_GOT20:
3303 case elfcpp::R_390_GOTPLT20:
3304 case elfcpp::R_390_TLS_GOTIE20:
3305 status = S390_relocate_functions<size>::rela20(view, value);
3308 case elfcpp::R_390_16:
3309 case elfcpp::R_390_GOT16:
3310 case elfcpp::R_390_GOTPLT16:
3311 case elfcpp::R_390_PLTOFF16:
3312 case elfcpp::R_390_GOTOFF16:
3313 status = S390_relocate_functions<size>::rela16(view, value);
3316 case elfcpp::R_390_12:
3317 case elfcpp::R_390_GOT12:
3318 case elfcpp::R_390_GOTPLT12:
3319 case elfcpp::R_390_TLS_GOTIE12:
3320 status = S390_relocate_functions<size>::rela12(view, value);
3323 case elfcpp::R_390_8:
3324 Relocate_functions<size, true>::rela8(view, value, 0);
3327 case elfcpp::R_390_PC16:
3328 Relocate_functions<size, true>::pcrela16(view, value, 0,
3332 case elfcpp::R_390_PLT64:
3333 case elfcpp::R_390_PC64:
3334 Relocate_functions<size, true>::pcrela64(view, value, 0, address);
3337 case elfcpp::R_390_PLT32:
3338 case elfcpp::R_390_PC32:
3339 case elfcpp::R_390_GOTPC:
3340 Relocate_functions<size, true>::pcrela32(view, value, 0, address);
3343 case elfcpp::R_390_PLT32DBL:
3344 case elfcpp::R_390_PC32DBL:
3345 case elfcpp::R_390_GOTPCDBL:
3346 status = S390_relocate_functions<size>::pcrela32dbl(view, value, address);
3349 case elfcpp::R_390_PLT24DBL:
3350 case elfcpp::R_390_PC24DBL:
3351 status = S390_relocate_functions<size>::pcrela24dbl(view, value, address);
3354 case elfcpp::R_390_PLT16DBL:
3355 case elfcpp::R_390_PC16DBL:
3356 status = S390_relocate_functions<size>::pcrela16dbl(view, value, address);
3359 case elfcpp::R_390_PLT12DBL:
3360 case elfcpp::R_390_PC12DBL:
3361 status = S390_relocate_functions<size>::pcrela12dbl(view, value, address);
3364 case elfcpp::R_390_GOTENT:
3365 case elfcpp::R_390_GOTPLTENT:
3366 case elfcpp::R_390_TLS_IEENT:
3367 value += target->got_address();
3368 status = S390_relocate_functions<size>::pcrela32dbl(view, value, address);
3371 case elfcpp::R_390_COPY:
3372 case elfcpp::R_390_GLOB_DAT:
3373 case elfcpp::R_390_JMP_SLOT:
3374 case elfcpp::R_390_RELATIVE:
3375 case elfcpp::R_390_IRELATIVE:
3376 // These are outstanding tls relocs, which are unexpected when linking
3377 case elfcpp::R_390_TLS_TPOFF:
3378 case elfcpp::R_390_TLS_DTPMOD:
3379 case elfcpp::R_390_TLS_DTPOFF:
3380 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3381 _("unexpected reloc %u in object file"),
3386 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3387 _("unsupported reloc %u"),
3392 if (status != S390_relocate_functions<size>::STATUS_OK)
3394 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3395 _("relocation overflow"));
3401 // Perform a TLS relocation.
3404 inline typename elfcpp::Elf_types<size>::Elf_Addr
3405 Target_s390<size>::Relocate::relocate_tls(
3406 const Relocate_info<size, true>* relinfo,
3407 Target_s390<size>* target,
3409 const elfcpp::Rela<size, true>& rela,
3410 unsigned int r_type,
3411 const Sized_symbol<size>* gsym,
3412 const Symbol_value<size>* psymval,
3413 unsigned char* view,
3414 section_size_type view_size)
3416 Output_segment* tls_segment = relinfo->layout->tls_segment();
3418 const Sized_relobj_file<size, true>* object = relinfo->object;
3419 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3420 elfcpp::Shdr<size, true> data_shdr(relinfo->data_shdr);
3421 bool is_allocatable = (data_shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0;
3423 typename elfcpp::Elf_types<size>::Elf_Addr value
3424 = psymval->value(relinfo->object, addend);
3426 const bool is_final = (gsym == NULL
3427 ? !parameters->options().shared()
3428 : gsym->final_value_is_known());
3429 tls::Tls_optimization optimized_type
3430 = Target_s390<size>::optimize_tls_reloc(is_final, r_type);
3433 case elfcpp::R_390_TLS_GDCALL: // Global-dynamic marker
3434 if (optimized_type == tls::TLSOPT_TO_LE)
3436 if (tls_segment == NULL)
3438 gold_assert(parameters->errors()->error_count() > 0
3439 || issue_undefined_symbol_error(gsym));
3442 this->tls_gd_to_le(relinfo, relnum, rela, view, view_size);
3447 if (optimized_type == tls::TLSOPT_TO_IE)
3449 this->tls_gd_to_ie(relinfo, relnum, rela, view, view_size);
3452 else if (optimized_type == tls::TLSOPT_NONE)
3457 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3458 _("unsupported reloc %u"), r_type);
3461 case elfcpp::R_390_TLS_GD32: // Global-dynamic
3462 case elfcpp::R_390_TLS_GD64:
3463 if (optimized_type == tls::TLSOPT_TO_LE)
3465 if (tls_segment == NULL)
3467 gold_assert(parameters->errors()->error_count() > 0
3468 || issue_undefined_symbol_error(gsym));
3471 return value - tls_segment->memsz();
3475 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
3476 ? GOT_TYPE_TLS_OFFSET
3477 : GOT_TYPE_TLS_PAIR);
3480 gold_assert(gsym->has_got_offset(got_type));
3481 return (gsym->got_offset(got_type)
3482 + target->got_main_offset()
3487 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3488 gold_assert(object->local_has_got_offset(r_sym, got_type));
3489 return (object->local_got_offset(r_sym, got_type)
3490 + target->got_main_offset()
3494 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3495 _("unsupported reloc %u"), r_type);
3498 case elfcpp::R_390_TLS_LDCALL: // Local-dynamic marker
3499 // This is a marker relocation. If the sequence is being turned to LE,
3500 // we modify the instruction, otherwise the instruction is untouched.
3501 if (optimized_type == tls::TLSOPT_TO_LE)
3503 if (tls_segment == NULL)
3505 gold_assert(parameters->errors()->error_count() > 0
3506 || issue_undefined_symbol_error(gsym));
3509 this->tls_ld_to_le(relinfo, relnum, rela, view, view_size);
3512 else if (optimized_type == tls::TLSOPT_NONE)
3516 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3517 _("unsupported reloc %u"), r_type);
3520 case elfcpp::R_390_TLS_LDM32: // Local-dynamic module
3521 case elfcpp::R_390_TLS_LDM64:
3522 if (optimized_type == tls::TLSOPT_TO_LE)
3524 if (tls_segment == NULL)
3526 gold_assert(parameters->errors()->error_count() > 0
3527 || issue_undefined_symbol_error(gsym));
3530 // Doesn't matter what we fill it with - it's going to be unused.
3533 else if (optimized_type == tls::TLSOPT_NONE)
3535 // Relocate the field with the offset of the GOT entry for
3536 // the module index.
3537 return (target->got_mod_index_entry(NULL, NULL, NULL)
3539 + target->got_main_offset());
3541 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3542 _("unsupported reloc %u"), r_type);
3545 case elfcpp::R_390_TLS_LDO32: // Local-dynamic offset
3546 case elfcpp::R_390_TLS_LDO64:
3547 // This relocation type is used in debugging information.
3548 // In that case we need to not optimize the value. If the
3549 // section is not allocatable, then we assume we should not
3550 // optimize this reloc.
3551 if (optimized_type == tls::TLSOPT_TO_LE && is_allocatable)
3553 if (tls_segment == NULL)
3555 gold_assert(parameters->errors()->error_count() > 0
3556 || issue_undefined_symbol_error(gsym));
3559 value -= tls_segment->memsz();
3563 case elfcpp::R_390_TLS_LOAD: // Initial-exec marker
3564 // This is a marker relocation. If the sequence is being turned to LE,
3565 // we modify the instruction, otherwise the instruction is untouched.
3567 && gsym->is_undefined()
3568 && parameters->options().output_is_executable())
3570 Target_s390<size>::Relocate::tls_ie_to_le(relinfo, relnum,
3575 else if (optimized_type == tls::TLSOPT_TO_LE)
3577 if (tls_segment == NULL)
3579 gold_assert(parameters->errors()->error_count() > 0
3580 || issue_undefined_symbol_error(gsym));
3583 Target_s390<size>::Relocate::tls_ie_to_le(relinfo, relnum,
3588 else if (optimized_type == tls::TLSOPT_NONE)
3592 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3593 _("unsupported reloc type %u"),
3597 case elfcpp::R_390_TLS_GOTIE12: // Initial-exec, not optimizable
3598 case elfcpp::R_390_TLS_GOTIE20:
3599 case elfcpp::R_390_TLS_IEENT:
3600 case elfcpp::R_390_TLS_GOTIE32: // Initial-exec, optimizable
3601 case elfcpp::R_390_TLS_GOTIE64:
3602 case elfcpp::R_390_TLS_IE32:
3603 case elfcpp::R_390_TLS_IE64:
3605 && gsym->is_undefined()
3606 && parameters->options().output_is_executable()
3607 // These three cannot be optimized to LE, no matter what
3608 && r_type != elfcpp::R_390_TLS_GOTIE12
3609 && r_type != elfcpp::R_390_TLS_GOTIE20
3610 && r_type != elfcpp::R_390_TLS_IEENT)
3614 else if (optimized_type == tls::TLSOPT_TO_LE)
3616 if (tls_segment == NULL)
3618 gold_assert(parameters->errors()->error_count() > 0
3619 || issue_undefined_symbol_error(gsym));
3622 return value - tls_segment->memsz();
3624 else if (optimized_type == tls::TLSOPT_NONE)
3626 // Relocate the field with the offset of the GOT entry for
3627 // the tp-relative offset of the symbol.
3628 unsigned int got_offset;
3631 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
3632 got_offset = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
3636 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3637 gold_assert(object->local_has_got_offset(r_sym,
3638 GOT_TYPE_TLS_OFFSET));
3639 got_offset = object->local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET);
3641 got_offset += target->got_main_offset();
3642 if (r_type == elfcpp::R_390_TLS_IE32
3643 || r_type == elfcpp::R_390_TLS_IE64)
3644 return target->got_address() + got_offset + addend;
3646 return got_offset + addend;
3648 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3649 _("unsupported reloc type %u"),
3653 case elfcpp::R_390_TLS_LE32: // Local-exec
3654 case elfcpp::R_390_TLS_LE64:
3655 if (tls_segment == NULL)
3657 gold_assert(parameters->errors()->error_count() > 0
3658 || issue_undefined_symbol_error(gsym));
3661 return value - tls_segment->memsz();
3666 // Do a relocation in which we convert a TLS General-Dynamic to an
3671 Target_s390<size>::Relocate::tls_gd_to_ie(
3672 const Relocate_info<size, true>* relinfo,
3674 const elfcpp::Rela<size, true>& rela,
3675 unsigned char* view,
3676 section_size_type view_size)
3678 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
3679 if (view[0] == 0x4d)
3681 // bas, don't care about details
3682 // Change to l %r2, 0(%r2, %r12)
3689 else if (view[0] == 0xc0)
3691 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 6);
3692 // brasl %r14, __tls_get_offset@plt
3693 if (view[1] == 0xe5)
3695 // Change to l/lg %r2, 0(%r2, %r12)
3696 // There was a PLT32DBL reloc at the last 4 bytes, overwrite its result.
3721 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3722 _("unsupported op for GD to IE"));
3725 // Do a relocation in which we convert a TLS General-Dynamic to a
3730 Target_s390<size>::Relocate::tls_gd_to_le(
3731 const Relocate_info<size, true>* relinfo,
3733 const elfcpp::Rela<size, true>& rela,
3734 unsigned char* view,
3735 section_size_type view_size)
3737 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 2);
3738 if (view[0] == 0x0d)
3740 // basr, change to nop
3744 else if (view[0] == 0x4d)
3746 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
3747 // bas, don't care about details, change to nop
3754 else if (view[0] == 0xc0)
3756 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 6);
3757 // brasl %r14, __tls_get_offset@plt
3758 if (view[1] == 0xe5)
3760 // Change to nop jump. There was a PLT32DBL reloc at the last
3761 // 4 bytes, overwrite its result.
3770 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3771 _("unsupported op for GD to LE"));
3776 Target_s390<size>::Relocate::tls_ld_to_le(
3777 const Relocate_info<size, true>* relinfo,
3779 const elfcpp::Rela<size, true>& rela,
3780 unsigned char* view,
3781 section_size_type view_size)
3783 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
3785 if (view[0] == 0x0d)
3787 // basr, change to nop
3791 else if (view[0] == 0x4d)
3793 // bas, don't care about details, change to nop
3800 else if (view[0] == 0xc0)
3802 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 6);
3803 // brasl %r14, __tls_get_offset@plt
3804 if (view[1] == 0xe5)
3806 // Change to nop jump. There was a PLT32DBL reloc at the last
3807 // 4 bytes, overwrite its result.
3816 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3817 _("unsupported op for LD to LE"));
3820 // Do a relocation in which we convert a TLS Initial-Exec to a
3825 Target_s390<size>::Relocate::tls_ie_to_le(
3826 const Relocate_info<size, true>* relinfo,
3828 const elfcpp::Rela<size, true>& rela,
3829 unsigned char* view,
3830 section_size_type view_size)
3832 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
3834 if (view[0] == 0x58)
3836 // l %rX, 0(%rY) or l %rX, 0(%rY, %r12)
3837 if ((view[2] & 0x0f) != 0 || view[3] != 0)
3839 int rx = view[1] >> 4 & 0xf;
3840 int ry = view[1] & 0xf;
3841 int rz = view[2] >> 4 & 0xf;
3860 view[1] = rx << 4 | ry;
3865 else if (view[0] == 0xe3)
3867 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 6);
3868 // lg %rX, 0(%rY) or lg %rX, 0(%rY, %r12)
3869 if ((view[2] & 0x0f) != 0 ||
3874 int rx = view[1] >> 4 & 0xf;
3875 int ry = view[1] & 0xf;
3876 int rz = view[2] >> 4 & 0xf;
3893 // to sllg %rX, $rY, 0
3895 view[1] = rx << 4 | ry;
3904 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3905 _("unsupported op for IE to LE"));
3909 // Scan relocations for a section.
3913 Target_s390<size>::scan_relocs(Symbol_table* symtab,
3915 Sized_relobj_file<size, true>* object,
3916 unsigned int data_shndx,
3917 unsigned int sh_type,
3918 const unsigned char* prelocs,
3920 Output_section* output_section,
3921 bool needs_special_offset_handling,
3922 size_t local_symbol_count,
3923 const unsigned char* plocal_symbols)
3925 if (sh_type == elfcpp::SHT_REL)
3927 gold_error(_("%s: unsupported REL reloc section"),
3928 object->name().c_str());
3932 gold::scan_relocs<size, true, Target_s390<size>, elfcpp::SHT_RELA,
3933 typename Target_s390<size>::Scan>(
3942 needs_special_offset_handling,
3947 // Finalize the sections.
3951 Target_s390<size>::do_finalize_sections(
3953 const Input_objects*,
3954 Symbol_table* symtab)
3956 const Reloc_section* rel_plt = (this->plt_ == NULL
3958 : this->plt_->rela_plt());
3959 layout->add_target_dynamic_tags(false, this->got_plt_, rel_plt,
3960 this->rela_dyn_, true, size == 32);
3962 this->layout_ = layout;
3964 // Emit any relocs we saved in an attempt to avoid generating COPY
3966 if (this->copy_relocs_.any_saved_relocs())
3967 this->copy_relocs_.emit(this->rela_dyn_section(layout));
3969 // Set the size of the _GLOBAL_OFFSET_TABLE_ symbol to the size of
3970 // the .got section.
3971 Symbol* sym = this->global_offset_table_;
3974 uint64_t data_size = this->got_->current_data_size();
3975 symtab->get_sized_symbol<size>(sym)->set_symsize(data_size);
3978 if (parameters->doing_static_link()
3979 && (this->plt_ == NULL || !this->plt_->has_irelative_section()))
3981 // If linking statically, make sure that the __rela_iplt symbols
3982 // were defined if necessary, even if we didn't create a PLT.
3983 static const Define_symbol_in_segment syms[] =
3986 "__rela_iplt_start", // name
3987 elfcpp::PT_LOAD, // segment_type
3988 elfcpp::PF_W, // segment_flags_set
3989 elfcpp::PF(0), // segment_flags_clear
3992 elfcpp::STT_NOTYPE, // type
3993 elfcpp::STB_GLOBAL, // binding
3994 elfcpp::STV_HIDDEN, // visibility
3996 Symbol::SEGMENT_START, // offset_from_base
4000 "__rela_iplt_end", // name
4001 elfcpp::PT_LOAD, // segment_type
4002 elfcpp::PF_W, // segment_flags_set
4003 elfcpp::PF(0), // segment_flags_clear
4006 elfcpp::STT_NOTYPE, // type
4007 elfcpp::STB_GLOBAL, // binding
4008 elfcpp::STV_HIDDEN, // visibility
4010 Symbol::SEGMENT_START, // offset_from_base
4015 symtab->define_symbols(layout, 2, syms,
4016 layout->script_options()->saw_sections_clause());
4020 // Return the size of a relocation while scanning during a relocatable
4025 Target_s390<size>::Relocatable_size_for_reloc::get_size_for_reloc(
4026 unsigned int r_type,
4031 case elfcpp::R_390_NONE:
4032 case elfcpp::R_390_GNU_VTINHERIT:
4033 case elfcpp::R_390_GNU_VTENTRY:
4034 case elfcpp::R_390_TLS_GD32: // Global-dynamic
4035 case elfcpp::R_390_TLS_GD64:
4036 case elfcpp::R_390_TLS_GDCALL:
4037 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
4038 case elfcpp::R_390_TLS_LDM64:
4039 case elfcpp::R_390_TLS_LDO32:
4040 case elfcpp::R_390_TLS_LDO64:
4041 case elfcpp::R_390_TLS_LDCALL:
4042 case elfcpp::R_390_TLS_IE32: // Initial-exec
4043 case elfcpp::R_390_TLS_IE64:
4044 case elfcpp::R_390_TLS_IEENT:
4045 case elfcpp::R_390_TLS_GOTIE12:
4046 case elfcpp::R_390_TLS_GOTIE20:
4047 case elfcpp::R_390_TLS_GOTIE32:
4048 case elfcpp::R_390_TLS_GOTIE64:
4049 case elfcpp::R_390_TLS_LOAD:
4050 case elfcpp::R_390_TLS_LE32: // Local-exec
4051 case elfcpp::R_390_TLS_LE64:
4054 case elfcpp::R_390_64:
4055 case elfcpp::R_390_PC64:
4056 case elfcpp::R_390_GOT64:
4057 case elfcpp::R_390_PLT64:
4058 case elfcpp::R_390_GOTOFF64:
4059 case elfcpp::R_390_GOTPLT64:
4060 case elfcpp::R_390_PLTOFF64:
4063 case elfcpp::R_390_32:
4064 case elfcpp::R_390_PC32:
4065 case elfcpp::R_390_GOT32:
4066 case elfcpp::R_390_PLT32:
4067 case elfcpp::R_390_GOTOFF32:
4068 case elfcpp::R_390_GOTPC:
4069 case elfcpp::R_390_PC32DBL:
4070 case elfcpp::R_390_PLT32DBL:
4071 case elfcpp::R_390_GOTPCDBL:
4072 case elfcpp::R_390_GOTENT:
4073 case elfcpp::R_390_GOTPLT32:
4074 case elfcpp::R_390_GOTPLTENT:
4075 case elfcpp::R_390_PLTOFF32:
4076 case elfcpp::R_390_20:
4077 case elfcpp::R_390_GOT20:
4078 case elfcpp::R_390_GOTPLT20:
4081 case elfcpp::R_390_PC24DBL:
4082 case elfcpp::R_390_PLT24DBL:
4085 case elfcpp::R_390_12:
4086 case elfcpp::R_390_GOT12:
4087 case elfcpp::R_390_GOTPLT12:
4088 case elfcpp::R_390_PC12DBL:
4089 case elfcpp::R_390_PLT12DBL:
4090 case elfcpp::R_390_16:
4091 case elfcpp::R_390_GOT16:
4092 case elfcpp::R_390_PC16:
4093 case elfcpp::R_390_PC16DBL:
4094 case elfcpp::R_390_PLT16DBL:
4095 case elfcpp::R_390_GOTOFF16:
4096 case elfcpp::R_390_GOTPLT16:
4097 case elfcpp::R_390_PLTOFF16:
4100 case elfcpp::R_390_8:
4103 // These are relocations which should only be seen by the
4104 // dynamic linker, and should never be seen here.
4105 case elfcpp::R_390_COPY:
4106 case elfcpp::R_390_GLOB_DAT:
4107 case elfcpp::R_390_JMP_SLOT:
4108 case elfcpp::R_390_RELATIVE:
4109 case elfcpp::R_390_IRELATIVE:
4110 case elfcpp::R_390_TLS_DTPMOD:
4111 case elfcpp::R_390_TLS_DTPOFF:
4112 case elfcpp::R_390_TLS_TPOFF:
4113 object->error(_("unexpected reloc %u in object file"), r_type);
4117 object->error(_("unsupported reloc %u in object file"), r_type);
4122 // Scan the relocs during a relocatable link.
4126 Target_s390<size>::scan_relocatable_relocs(
4127 Symbol_table* symtab,
4129 Sized_relobj_file<size, true>* object,
4130 unsigned int data_shndx,
4131 unsigned int sh_type,
4132 const unsigned char* prelocs,
4134 Output_section* output_section,
4135 bool needs_special_offset_handling,
4136 size_t local_symbol_count,
4137 const unsigned char* plocal_symbols,
4138 Relocatable_relocs* rr)
4140 gold_assert(sh_type == elfcpp::SHT_RELA);
4142 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
4143 Relocatable_size_for_reloc> Scan_relocatable_relocs;
4145 gold::scan_relocatable_relocs<size, true, elfcpp::SHT_RELA,
4146 Scan_relocatable_relocs>(
4154 needs_special_offset_handling,
4160 // Relocate a section during a relocatable link.
4164 Target_s390<size>::relocate_relocs(
4165 const Relocate_info<size, true>* relinfo,
4166 unsigned int sh_type,
4167 const unsigned char* prelocs,
4169 Output_section* output_section,
4170 typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
4171 const Relocatable_relocs* rr,
4172 unsigned char* view,
4173 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
4174 section_size_type view_size,
4175 unsigned char* reloc_view,
4176 section_size_type reloc_view_size)
4178 gold_assert(sh_type == elfcpp::SHT_RELA);
4180 gold::relocate_relocs<size, true, elfcpp::SHT_RELA>(
4185 offset_in_output_section,
4194 // Return the offset to use for the GOT_INDX'th got entry which is
4195 // for a local tls symbol specified by OBJECT, SYMNDX.
4198 Target_s390<size>::do_tls_offset_for_local(
4203 // The only way we can get called is when IEENT/GOTIE12/GOTIE20
4204 // couldn't be optimised to LE.
4205 Output_segment* tls_segment = layout_->tls_segment();
4206 return -tls_segment->memsz();
4209 // Return the offset to use for the GOT_INDX'th got entry which is
4210 // for global tls symbol GSYM.
4213 Target_s390<size>::do_tls_offset_for_global(
4217 Output_segment* tls_segment = layout_->tls_segment();
4218 return -tls_segment->memsz();
4221 // Return the value to use for a dynamic which requires special
4222 // treatment. This is how we support equality comparisons of function
4223 // pointers across shared library boundaries, as described in the
4224 // processor specific ABI supplement.
4228 Target_s390<size>::do_dynsym_value(const Symbol* gsym) const
4230 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
4231 return this->plt_address_for_global(gsym);
4234 // Return a string used to fill a code section with nops to take up
4235 // the specified length.
4239 Target_s390<size>::do_code_fill(section_size_type length) const
4242 gold_warning(_("S/390 code fill of odd length requested"));
4243 return std::string(length, static_cast<char>(0x07));
4246 // Relocate section data.
4250 Target_s390<size>::relocate_section(
4251 const Relocate_info<size, true>* relinfo,
4252 unsigned int sh_type,
4253 const unsigned char* prelocs,
4255 Output_section* output_section,
4256 bool needs_special_offset_handling,
4257 unsigned char* view,
4258 typename elfcpp::Elf_types<size>::Elf_Addr address,
4259 section_size_type view_size,
4260 const Reloc_symbol_changes* reloc_symbol_changes)
4262 gold_assert(sh_type == elfcpp::SHT_RELA);
4264 gold::relocate_section<size, true, Target_s390<size>, elfcpp::SHT_RELA,
4265 typename Target_s390<size>::Relocate,
4266 gold::Default_comdat_behavior>(
4272 needs_special_offset_handling,
4276 reloc_symbol_changes);
4279 // Apply an incremental relocation. Incremental relocations always refer
4280 // to global symbols.
4284 Target_s390<size>::apply_relocation(
4285 const Relocate_info<size, true>* relinfo,
4286 typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
4287 unsigned int r_type,
4288 typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
4290 unsigned char* view,
4291 typename elfcpp::Elf_types<size>::Elf_Addr address,
4292 section_size_type view_size)
4294 gold::apply_relocation<size, true, Target_s390<size>,
4295 typename Target_s390<size>::Relocate>(
4307 // The selector for s390 object files.
4310 class Target_selector_s390 : public Target_selector
4313 Target_selector_s390()
4314 : Target_selector(elfcpp::EM_S390, size, true,
4315 (size == 64 ? "elf64-s390" : "elf32-s390"),
4316 (size == 64 ? "elf64_s390" : "elf32_s390"))
4320 do_instantiate_target()
4321 { return new Target_s390<size>(); }
4324 Target_selector_s390<32> target_selector_s390;
4325 Target_selector_s390<64> target_selector_s390x;
4327 } // End anonymous namespace.