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 unsigned int r_type = elfcpp::elf_r_type<size>(reloc.get_r_info());
685 this->copy_relocs_.copy_reloc(symtab, layout,
686 symtab->get_sized_symbol<size>(sym),
687 object, shndx, output_section,
688 r_type, reloc.get_r_offset(),
689 reloc.get_r_addend(),
690 this->rela_dyn_section(layout));
693 // Information about this specific target which we pass to the
694 // general Target structure.
695 static Target::Target_info s390_info;
697 // The types of GOT entries needed for this platform.
698 // These values are exposed to the ABI in an incremental link.
699 // Do not renumber existing values without changing the version
700 // number of the .gnu_incremental_inputs section.
703 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
704 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
705 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
709 Output_data_got<size, true>* got_;
711 Output_data_plt_s390<size>* plt_;
712 // The GOT PLT section.
713 Output_data_got_plt_s390<size>* got_plt_;
714 // The GOT section for IRELATIVE relocations.
715 Output_data_space* got_irelative_;
716 // The _GLOBAL_OFFSET_TABLE_ symbol.
717 Symbol* global_offset_table_;
718 // The dynamic reloc section.
719 Reloc_section* rela_dyn_;
720 // The section to use for IRELATIVE relocs.
721 Reloc_section* rela_irelative_;
722 // Relocs saved to avoid a COPY reloc.
723 Copy_relocs<elfcpp::SHT_RELA, size, true> copy_relocs_;
724 // Offset of the GOT entry for the TLS module index.
725 unsigned int got_mod_index_offset_;
726 // True if the _TLS_MODULE_BASE_ symbol has been defined.
727 bool tls_base_symbol_defined_;
728 // For use in do_tls_offset_for_*
733 Target::Target_info Target_s390<32>::s390_info =
736 true, // is_big_endian
737 elfcpp::EM_S390, // machine_code
738 false, // has_make_symbol
739 false, // has_resolve
740 true, // has_code_fill
741 true, // is_default_stack_executable
742 true, // can_icf_inline_merge_sections
744 "/lib/ld.so.1", // dynamic_linker
745 0x00400000, // default_text_segment_address
746 4 * 1024, // abi_pagesize (overridable by -z max-page-size)
747 4 * 1024, // common_pagesize (overridable by -z common-page-size)
748 false, // isolate_execinstr
750 elfcpp::SHN_UNDEF, // small_common_shndx
751 elfcpp::SHN_UNDEF, // large_common_shndx
752 0, // small_common_section_flags
753 0, // large_common_section_flags
754 NULL, // attributes_section
755 NULL, // attributes_vendor
756 "_start", // entry_symbol_name
757 32, // hash_entry_size
761 Target::Target_info Target_s390<64>::s390_info =
764 true, // is_big_endian
765 elfcpp::EM_S390, // machine_code
766 false, // has_make_symbol
767 false, // has_resolve
768 true, // has_code_fill
769 true, // is_default_stack_executable
770 true, // can_icf_inline_merge_sections
772 "/lib/ld64.so.1", // dynamic_linker
773 0x80000000ll, // default_text_segment_address
774 4 * 1024, // abi_pagesize (overridable by -z max-page-size)
775 4 * 1024, // common_pagesize (overridable by -z common-page-size)
776 false, // isolate_execinstr
778 elfcpp::SHN_UNDEF, // small_common_shndx
779 elfcpp::SHN_UNDEF, // large_common_shndx
780 0, // small_common_section_flags
781 0, // large_common_section_flags
782 NULL, // attributes_section
783 NULL, // attributes_vendor
784 "_start", // entry_symbol_name
785 64, // hash_entry_size
789 class S390_relocate_functions
809 typedef S390_relocate_functions<size> This;
810 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
812 template<int valsize>
814 has_overflow_signed(Address value)
816 // limit = 1 << (valsize - 1) without shift count exceeding size of type
817 Address limit = static_cast<Address>(1) << ((valsize - 1) >> 1);
818 limit <<= ((valsize - 1) >> 1);
819 limit <<= ((valsize - 1) - 2 * ((valsize - 1) >> 1));
820 return value + limit > (limit << 1) - 1;
823 template<int valsize>
825 has_overflow_unsigned(Address value)
827 Address limit = static_cast<Address>(1) << ((valsize - 1) >> 1);
828 limit <<= ((valsize - 1) >> 1);
829 limit <<= ((valsize - 1) - 2 * ((valsize - 1) >> 1));
830 return value > (limit << 1) - 1;
833 template<int fieldsize>
835 rela(unsigned char* view, Address mask, Address value)
837 typedef typename elfcpp::Swap<fieldsize, true>::Valtype Valtype;
838 Valtype* wv = reinterpret_cast<Valtype*>(view);
839 Valtype val = elfcpp::Swap<fieldsize, true>::readval(view);
842 elfcpp::Swap<fieldsize, true>::writeval(wv, val | value);
846 // R_390_12, R_390_GOT12, R_390_GOTPLT12, R_390_GOTIE12
848 rela12(unsigned char* view, Address value)
850 if (This::template has_overflow_unsigned<12>(value))
851 return STATUS_OVERFLOW;
852 This::template rela<16>(view, 0x0fff, value);
856 // R_390_16, R_390_GOT16, R_390_GOTPLT16, R_390_GOTOFF16, R_390_PLTOFF16
858 rela16(unsigned char* view, Address value)
860 if (This::template has_overflow_signed<16>(value))
861 return STATUS_OVERFLOW;
862 This::template rela<16>(view, 0xffff, value);
866 // R_390_20, R_390_GOT20, R_390_GOTPLT20, R_390_GOTIE20
868 rela20(unsigned char* view, Address value)
870 if (This::template has_overflow_signed<20>(value))
871 return STATUS_OVERFLOW;
872 This::template rela<16>(view, 0x0fff, value);
873 This::template rela<16>(view + 2, 0xff00, value >> (12 - 8));
877 // R_390_PC12DBL, R_390_PLT12DBL
879 pcrela12dbl(unsigned char* view, Address value, Address address)
882 if ((value & 1) != 0)
883 return STATUS_OVERFLOW;
884 if (This::template has_overflow_signed<13>(value))
885 return STATUS_OVERFLOW;
887 This::template rela<16>(view, 0x0fff, value);
891 // R_390_PC16DBL, R_390_PLT16DBL
893 pcrela16dbl(unsigned char* view, Address value, Address address)
896 if ((value & 1) != 0)
897 return STATUS_OVERFLOW;
898 if (This::template has_overflow_signed<17>(value))
899 return STATUS_OVERFLOW;
901 This::template rela<16>(view, 0xffff, value);
905 // R_390_PC24DBL, R_390_PLT24DBL
907 pcrela24dbl(unsigned char* view, Address value, Address address)
910 if ((value & 1) != 0)
911 return STATUS_OVERFLOW;
912 if (This::template has_overflow_signed<25>(value))
913 return STATUS_OVERFLOW;
915 // Swap doesn't take 24-bit fields well...
916 This::template rela<8>(view, 0xff, value >> 16);
917 This::template rela<16>(view + 1, 0xffff, value);
921 // R_390_PC32DBL, R_390_PLT32DBL, R_390_GOTPCDBL, R_390_GOTENT, R_390_GOTPLTENT
923 pcrela32dbl(unsigned char* view, Address value, Address address)
925 Address reloc = value - address;
926 if ((reloc & 1) != 0)
928 gold_warning(_("R_390_PC32DBL target misaligned at %llx"), (long long)address);
929 // Wait for a fix for https://sourceware.org/bugzilla/show_bug.cgi?id=18960
930 // return STATUS_OVERFLOW;
932 if (This::template has_overflow_signed<33>(reloc))
933 return STATUS_OVERFLOW;
935 if (value < address && size == 32)
937 This::template rela<32>(view, 0xffffffff, reloc);
943 // Initialize the PLT section.
947 Output_data_plt_s390<size>::init(Layout* layout)
949 this->rel_ = new Reloc_section(false);
950 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
951 elfcpp::SHF_ALLOC, this->rel_,
952 ORDER_DYNAMIC_PLT_RELOCS, false);
957 Output_data_plt_s390<size>::do_adjust_output_section(Output_section* os)
959 os->set_entsize(plt_entry_size);
962 // Add an entry to the PLT.
966 Output_data_plt_s390<size>::add_entry(Symbol_table* symtab, Layout* layout,
969 gold_assert(!gsym->has_plt_offset());
971 unsigned int plt_index;
973 section_offset_type got_offset;
975 unsigned int* pcount;
977 unsigned int reserved;
978 Output_section_data_build* got;
979 if (gsym->type() == elfcpp::STT_GNU_IFUNC
980 && gsym->can_use_relative_reloc(false))
982 pcount = &this->irelative_count_;
985 got = this->got_irelative_;
989 pcount = &this->count_;
992 got = this->got_plt_;
995 if (!this->is_data_size_valid())
997 // Note that when setting the PLT offset for a non-IRELATIVE
998 // entry we skip the initial reserved PLT entry.
999 plt_index = *pcount + offset;
1000 plt_offset = plt_index * plt_entry_size;
1004 got_offset = (plt_index - offset + reserved) * size / 8;
1005 gold_assert(got_offset == got->current_data_size());
1007 // Every PLT entry needs a GOT entry which points back to the PLT
1008 // entry (this will be changed by the dynamic linker, normally
1009 // lazily when the function is called).
1010 got->set_current_data_size(got_offset + size / 8);
1014 // FIXME: This is probably not correct for IRELATIVE relocs.
1016 // For incremental updates, find an available slot.
1017 plt_offset = this->free_list_.allocate(plt_entry_size,
1019 if (plt_offset == -1)
1020 gold_fallback(_("out of patch space (PLT);"
1021 " relink with --incremental-full"));
1023 // The GOT and PLT entries have a 1-1 correspondance, so the GOT offset
1024 // can be calculated from the PLT index, adjusting for the three
1025 // reserved entries at the beginning of the GOT.
1026 plt_index = plt_offset / plt_entry_size - 1;
1027 got_offset = (plt_index - offset + reserved) * size / 8;
1030 gsym->set_plt_offset(plt_offset);
1032 // Every PLT entry needs a reloc.
1033 this->add_relocation(symtab, layout, gsym, got_offset);
1035 // Note that we don't need to save the symbol. The contents of the
1036 // PLT are independent of which symbols are used. The symbols only
1037 // appear in the relocations.
1040 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol. Return
1045 Output_data_plt_s390<size>::add_local_ifunc_entry(
1046 Symbol_table* symtab,
1048 Sized_relobj_file<size, true>* relobj,
1049 unsigned int local_sym_index)
1051 unsigned int plt_offset = this->irelative_count_ * plt_entry_size;
1052 ++this->irelative_count_;
1054 section_offset_type got_offset = this->got_irelative_->current_data_size();
1056 // Every PLT entry needs a GOT entry which points back to the PLT
1058 this->got_irelative_->set_current_data_size(got_offset + size / 8);
1060 // Every PLT entry needs a reloc.
1061 Reloc_section* rela = this->rela_irelative(symtab, layout);
1062 rela->add_symbolless_local_addend(relobj, local_sym_index,
1063 elfcpp::R_390_IRELATIVE,
1064 this->got_irelative_, got_offset, 0);
1069 // Add the relocation for a PLT entry.
1073 Output_data_plt_s390<size>::add_relocation(Symbol_table* symtab,
1076 unsigned int got_offset)
1078 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1079 && gsym->can_use_relative_reloc(false))
1081 Reloc_section* rela = this->rela_irelative(symtab, layout);
1082 rela->add_symbolless_global_addend(gsym, elfcpp::R_390_IRELATIVE,
1083 this->got_irelative_, got_offset, 0);
1087 gsym->set_needs_dynsym_entry();
1088 this->rel_->add_global(gsym, elfcpp::R_390_JMP_SLOT, this->got_plt_,
1093 // Return where the IRELATIVE relocations should go in the PLT. These
1094 // follow the JUMP_SLOT and the TLSDESC relocations.
1097 typename Output_data_plt_s390<size>::Reloc_section*
1098 Output_data_plt_s390<size>::rela_irelative(Symbol_table* symtab,
1101 if (this->irelative_rel_ == NULL)
1103 this->irelative_rel_ = new Reloc_section(false);
1104 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1105 elfcpp::SHF_ALLOC, this->irelative_rel_,
1106 ORDER_DYNAMIC_PLT_RELOCS, false);
1107 gold_assert(this->irelative_rel_->output_section()
1108 == this->rel_->output_section());
1110 if (parameters->doing_static_link())
1112 // A statically linked executable will only have a .rela.plt
1113 // section to hold R_390_IRELATIVE relocs for
1114 // STT_GNU_IFUNC symbols. The library will use these
1115 // symbols to locate the IRELATIVE relocs at program startup
1117 symtab->define_in_output_data("__rela_iplt_start", NULL,
1118 Symbol_table::PREDEFINED,
1119 this->irelative_rel_, 0, 0,
1120 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1121 elfcpp::STV_HIDDEN, 0, false, true);
1122 symtab->define_in_output_data("__rela_iplt_end", NULL,
1123 Symbol_table::PREDEFINED,
1124 this->irelative_rel_, 0, 0,
1125 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1126 elfcpp::STV_HIDDEN, 0, true, true);
1129 return this->irelative_rel_;
1132 // Return the PLT address to use for a global symbol.
1136 Output_data_plt_s390<size>::address_for_global(const Symbol* gsym)
1138 uint64_t offset = 0;
1139 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1140 && gsym->can_use_relative_reloc(false))
1141 offset = (this->count_ + 1) * plt_entry_size;
1142 return this->address() + offset + gsym->plt_offset();
1145 // Return the PLT address to use for a local symbol. These are always
1146 // IRELATIVE relocs.
1150 Output_data_plt_s390<size>::address_for_local(const Relobj* object,
1153 return (this->address()
1154 + (this->count_ + 1) * plt_entry_size
1155 + object->local_plt_offset(r_sym));
1158 // Set the final size.
1161 Output_data_plt_s390<size>::set_final_data_size()
1163 unsigned int count = this->count_ + this->irelative_count_;
1164 this->set_data_size((count + 1) * plt_entry_size);
1169 Output_data_plt_s390<size>::first_plt_entry_32_abs[plt_entry_size] =
1171 0x50, 0x10, 0xf0, 0x1c, // st %r1, 28(%r15)
1172 0x0d, 0x10, // basr %r1, %r0
1173 0x58, 0x10, 0x10, 0x12, // l %r1, 18(%r1)
1174 0xd2, 0x03, 0xf0, 0x18, 0x10, 0x04, // mvc 24(4,%r15), 4(%r1)
1175 0x58, 0x10, 0x10, 0x08, // l %r1, 8(%r1)
1176 0x07, 0xf1, // br %r1
1177 0x00, 0x00, // padding
1178 0x00, 0x00, 0x00, 0x00, // _GLOBAL_OFFSET_TABLE_ (to fill)
1179 0x00, 0x00, 0x00, 0x00, // padding
1184 Output_data_plt_s390<size>::first_plt_entry_32_pic[plt_entry_size] =
1186 0x50, 0x10, 0xf0, 0x1c, // st %r1, 28(%r15)
1187 0x58, 0x10, 0xc0, 0x04, // l %r1, 4(%r12)
1188 0x50, 0x10, 0xf0, 0x18, // st %r1, 24(%r15)
1189 0x58, 0x10, 0xc0, 0x08, // l %r1, 8(%r12)
1190 0x07, 0xf1, // br %r1
1191 0x00, 0x00, // padding
1192 0x00, 0x00, 0x00, 0x00, // padding
1193 0x00, 0x00, 0x00, 0x00, // padding
1194 0x00, 0x00, 0x00, 0x00, // padding
1199 Output_data_plt_s390<size>::first_plt_entry_64[plt_entry_size] =
1201 0xe3, 0x10, 0xf0, 0x38, 0x00, 0x24, // stg %r1, 56(%r15)
1202 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, // larl %r1, _GLOBAL_OFFSET_TABLE_ (to fill)
1203 0xd2, 0x07, 0xf0, 0x30, 0x10, 0x08, // mvc 48(8,%r15), 8(%r1)
1204 0xe3, 0x10, 0x10, 0x10, 0x00, 0x04, // lg %r1, 16(%r1)
1205 0x07, 0xf1, // br %r1
1213 Output_data_plt_s390<size>::fill_first_plt_entry(
1215 typename elfcpp::Elf_types<size>::Elf_Addr got_address,
1216 typename elfcpp::Elf_types<size>::Elf_Addr plt_address)
1220 memcpy(pov, first_plt_entry_64, plt_entry_size);
1221 S390_relocate_functions<size>::pcrela32dbl(pov + 8, got_address, (plt_address + 6));
1223 else if (!parameters->options().output_is_position_independent())
1225 memcpy(pov, first_plt_entry_32_abs, plt_entry_size);
1226 elfcpp::Swap<32, true>::writeval(pov + 24, got_address);
1230 memcpy(pov, first_plt_entry_32_pic, plt_entry_size);
1236 Output_data_plt_s390<size>::plt_entry_32_abs[plt_entry_size] =
1239 0x0d, 0x10, // basr %r1, %r0
1240 0x58, 0x10, 0x10, 0x16, // l %r1, 22(%r1)
1241 0x58, 0x10, 0x10, 0x00, // l %r1, 0(%r1)
1242 0x07, 0xf1, // br %r1
1244 0x0d, 0x10, // basr %r1, %r0
1245 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1246 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1247 0x00, 0x00, // padding
1248 0x00, 0x00, 0x00, 0x00, // _GLOBAL_OFFSET_TABLE_+sym@gotplt (to fill)
1249 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1254 Output_data_plt_s390<size>::plt_entry_32_pic12[plt_entry_size] =
1257 0x58, 0x10, 0xc0, 0x00, // l %r1, sym@gotplt(%r12) (to fill)
1258 0x07, 0xf1, // br %r1
1259 0x00, 0x00, // padding
1260 0x00, 0x00, 0x00, 0x00, // padding
1262 0x0d, 0x10, // basr %r1, %r0
1263 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1264 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1265 0x00, 0x00, // padding
1266 0x00, 0x00, 0x00, 0x00, // padding
1267 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1272 Output_data_plt_s390<size>::plt_entry_32_pic16[plt_entry_size] =
1275 0xa7, 0x18, 0x00, 0x00, // lhi %r1, sym@gotplt (to fill)
1276 0x58, 0x11, 0xc0, 0x00, // l %r1, 0(%r1, %r12)
1277 0x07, 0xf1, // br %r1
1278 0x00, 0x00, // padding
1280 0x0d, 0x10, // basr %r1, %r0
1281 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1282 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1283 0x00, 0x00, // padding
1284 0x00, 0x00, 0x00, 0x00, // padding
1285 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1290 Output_data_plt_s390<size>::plt_entry_32_pic[plt_entry_size] =
1293 0x0d, 0x10, // basr %r1, %r0
1294 0x58, 0x10, 0x10, 0x16, // l %r1, 22(%r1)
1295 0x58, 0x11, 0xc0, 0x00, // l %r1, 0(%r1, %r12)
1296 0x07, 0xf1, // br %r1
1298 0x0d, 0x10, // basr %r1, %r0
1299 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1300 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1301 0x00, 0x00, // padding
1302 0x00, 0x00, 0x00, 0x00, // sym@gotplt (to fill)
1303 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1308 Output_data_plt_s390<size>::plt_entry_64[plt_entry_size] =
1311 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, // larl %r1, _GLOBAL_OFFSET_TABLE_+off (to fill)
1312 0xe3, 0x10, 0x10, 0x00, 0x00, 0x04, // lg %r1, 0(%r1)
1313 0x07, 0xf1, // br %r1
1315 0x0d, 0x10, // basr %r1, %r0
1316 0xe3, 0x10, 0x10, 0x0c, 0x00, 0x14, // lgf %r1, 12(%r1)
1317 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, // jg first_plt_entry (to fill)
1318 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1323 Output_data_plt_s390<size>::fill_plt_entry(
1325 typename elfcpp::Elf_types<size>::Elf_Addr got_address,
1326 typename elfcpp::Elf_types<size>::Elf_Addr plt_address,
1327 unsigned int got_offset,
1328 unsigned int plt_offset,
1329 unsigned int plt_rel_offset)
1333 memcpy(pov, plt_entry_64, plt_entry_size);
1334 S390_relocate_functions<size>::pcrela32dbl(pov + 2, got_address + got_offset, plt_address + plt_offset);
1335 S390_relocate_functions<size>::pcrela32dbl(pov + 24, plt_address, plt_address + plt_offset + 22);
1339 if (!parameters->options().output_is_position_independent())
1341 memcpy(pov, plt_entry_32_abs, plt_entry_size);
1342 elfcpp::Swap<32, true>::writeval(pov + 24, got_address + got_offset);
1346 if (got_offset < 0x1000)
1348 memcpy(pov, plt_entry_32_pic12, plt_entry_size);
1349 S390_relocate_functions<size>::rela12(pov + 2, got_offset);
1351 else if (got_offset < 0x8000)
1353 memcpy(pov, plt_entry_32_pic16, plt_entry_size);
1354 S390_relocate_functions<size>::rela16(pov + 2, got_offset);
1358 memcpy(pov, plt_entry_32_pic, plt_entry_size);
1359 elfcpp::Swap<32, true>::writeval(pov + 24, got_offset);
1362 typename elfcpp::Elf_types<size>::Elf_Addr target = plt_address;
1363 if (plt_offset >= 0x10000)
1365 // Would overflow pcrela16dbl - aim at the farthest previous jump
1367 if (plt_offset > 0x10000)
1369 // Use the full range of pcrel16dbl.
1370 target = plt_address + plt_offset - 0x10000 + 18;
1374 // if plt_offset is exactly 0x10000, the above would aim at 18th byte
1375 // of first_plt_entry, which doesn't have the jump back like the others.
1376 // Aim at the next entry instead.
1377 target = plt_address + plt_offset - 0xffe0 + 18;
1380 S390_relocate_functions<size>::pcrela16dbl(pov + 20, target, plt_address + plt_offset + 18);
1382 elfcpp::Swap<32, true>::writeval(pov + 28, plt_rel_offset);
1389 // The .eh_frame unwind information for the PLT.
1393 Output_data_plt_s390<32>::plt_eh_frame_cie[plt_eh_frame_cie_size] =
1396 'z', // Augmentation: augmentation size included.
1397 'R', // Augmentation: FDE encoding included.
1398 '\0', // End of augmentation string.
1399 1, // Code alignment factor.
1400 0x7c, // Data alignment factor.
1401 14, // Return address column.
1402 1, // Augmentation size.
1403 (elfcpp::DW_EH_PE_pcrel // FDE encoding.
1404 | elfcpp::DW_EH_PE_sdata4),
1405 elfcpp::DW_CFA_def_cfa, 15, 0x60, // DW_CFA_def_cfa: r15 ofs 0x60.
1410 Output_data_plt_s390<64>::plt_eh_frame_cie[plt_eh_frame_cie_size] =
1413 'z', // Augmentation: augmentation size included.
1414 'R', // Augmentation: FDE encoding included.
1415 '\0', // End of augmentation string.
1416 1, // Code alignment factor.
1417 0x78, // Data alignment factor.
1418 14, // Return address column.
1419 1, // Augmentation size.
1420 (elfcpp::DW_EH_PE_pcrel // FDE encoding.
1421 | elfcpp::DW_EH_PE_sdata4),
1422 elfcpp::DW_CFA_def_cfa, 15, 0xa0, // DW_CFA_def_cfa: r15 ofs 0xa0.
1427 Output_data_plt_s390<size>::plt_eh_frame_fde[plt_eh_frame_fde_size] =
1429 0, 0, 0, 0, // Replaced with offset to .plt.
1430 0, 0, 0, 0, // Replaced with size of .plt.
1431 0, // Augmentation size.
1437 // Write out the PLT. This uses the hand-coded instructions above,
1438 // and adjusts them as needed.
1442 Output_data_plt_s390<size>::do_write(Output_file* of)
1444 const off_t offset = this->offset();
1445 const section_size_type oview_size =
1446 convert_to_section_size_type(this->data_size());
1447 unsigned char* const oview = of->get_output_view(offset, oview_size);
1449 const off_t got_file_offset = this->got_plt_->offset();
1450 gold_assert(parameters->incremental_update()
1451 || (got_file_offset + this->got_plt_->data_size()
1452 == this->got_irelative_->offset()));
1453 const section_size_type got_size =
1454 convert_to_section_size_type(this->got_plt_->data_size()
1455 + this->got_irelative_->data_size());
1456 unsigned char* const got_view = of->get_output_view(got_file_offset,
1459 unsigned char* pov = oview;
1461 // The base address of the .plt section.
1462 typename elfcpp::Elf_types<size>::Elf_Addr plt_address = this->address();
1463 // The base address of the PLT portion of the .got section,
1464 // which is where the GOT pointer will point, and where the
1465 // three reserved GOT entries are located.
1466 typename elfcpp::Elf_types<size>::Elf_Addr got_address
1467 = this->got_plt_->address();
1469 this->fill_first_plt_entry(pov, got_address, plt_address);
1470 pov += this->get_plt_entry_size();
1472 unsigned char* got_pov = got_view;
1474 const int rel_size = elfcpp::Elf_sizes<size>::rela_size;
1476 unsigned int plt_offset = this->get_plt_entry_size();
1477 unsigned int plt_rel_offset = 0;
1478 unsigned int got_offset = 3 * size / 8;
1479 const unsigned int count = this->count_ + this->irelative_count_;
1480 // The first three entries in the GOT are reserved, and are written
1481 // by Output_data_got_plt_s390::do_write.
1482 got_pov += 3 * size / 8;
1484 for (unsigned int plt_index = 0;
1487 pov += plt_entry_size,
1488 got_pov += size / 8,
1489 plt_offset += plt_entry_size,
1490 plt_rel_offset += rel_size,
1491 got_offset += size / 8)
1493 // Set and adjust the PLT entry itself.
1494 unsigned int lazy_offset = this->fill_plt_entry(pov,
1495 got_address, plt_address,
1496 got_offset, plt_offset,
1499 // Set the entry in the GOT.
1500 elfcpp::Swap<size, true>::writeval(got_pov,
1501 plt_address + plt_offset + lazy_offset);
1504 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1505 gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size);
1507 of->write_output_view(offset, oview_size, oview);
1508 of->write_output_view(got_file_offset, got_size, got_view);
1511 // Get the GOT section, creating it if necessary.
1514 Output_data_got<size, true>*
1515 Target_s390<size>::got_section(Symbol_table* symtab, Layout* layout)
1517 if (this->got_ == NULL)
1519 gold_assert(symtab != NULL && layout != NULL);
1521 // When using -z now, we can treat .got as a relro section.
1522 // Without -z now, it is modified after program startup by lazy
1524 bool is_got_relro = parameters->options().now();
1525 Output_section_order got_order = (is_got_relro
1529 // The old GNU linker creates a .got.plt section. We just
1530 // create another set of data in the .got section. Note that we
1531 // always create a PLT if we create a GOT, although the PLT
1533 this->got_plt_ = new Output_data_got_plt_s390<size>(layout);
1534 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1535 (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE),
1536 this->got_plt_, got_order, is_got_relro);
1538 // The first three entries are reserved.
1539 this->got_plt_->set_current_data_size(3 * size / 8);
1541 // If there are any IRELATIVE relocations, they get GOT entries
1542 // in .got.plt after the jump slot entries.
1543 this->got_irelative_ = new Output_data_space(size / 8, "** GOT IRELATIVE PLT");
1544 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1545 (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE),
1546 this->got_irelative_,
1547 got_order, is_got_relro);
1549 // Unlike some targets (.e.g x86), S/390 does not use separate .got and
1550 // .got.plt sections in output. The output .got section contains both
1551 // PLT and non-PLT GOT entries.
1552 this->got_ = new Output_data_got<size, true>();
1554 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1555 (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE),
1556 this->got_, got_order, is_got_relro);
1558 // Define _GLOBAL_OFFSET_TABLE_ at the start of the GOT.
1559 this->global_offset_table_ =
1560 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1561 Symbol_table::PREDEFINED,
1563 0, 0, elfcpp::STT_OBJECT,
1565 elfcpp::STV_HIDDEN, 0,
1572 // Get the dynamic reloc section, creating it if necessary.
1575 typename Target_s390<size>::Reloc_section*
1576 Target_s390<size>::rela_dyn_section(Layout* layout)
1578 if (this->rela_dyn_ == NULL)
1580 gold_assert(layout != NULL);
1581 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1582 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1583 elfcpp::SHF_ALLOC, this->rela_dyn_,
1584 ORDER_DYNAMIC_RELOCS, false);
1586 return this->rela_dyn_;
1589 // Get the section to use for IRELATIVE relocs, creating it if
1590 // necessary. These go in .rela.dyn, but only after all other dynamic
1591 // relocations. They need to follow the other dynamic relocations so
1592 // that they can refer to global variables initialized by those
1596 typename Target_s390<size>::Reloc_section*
1597 Target_s390<size>::rela_irelative_section(Layout* layout)
1599 if (this->rela_irelative_ == NULL)
1601 // Make sure we have already created the dynamic reloc section.
1602 this->rela_dyn_section(layout);
1603 this->rela_irelative_ = new Reloc_section(false);
1604 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1605 elfcpp::SHF_ALLOC, this->rela_irelative_,
1606 ORDER_DYNAMIC_RELOCS, false);
1607 gold_assert(this->rela_dyn_->output_section()
1608 == this->rela_irelative_->output_section());
1610 return this->rela_irelative_;
1613 // Write the first three reserved words of the .got.plt section.
1614 // The remainder of the section is written while writing the PLT
1615 // in Output_data_plt_s390::do_write.
1619 Output_data_got_plt_s390<size>::do_write(Output_file* of)
1621 // The first entry in the GOT is the address of the .dynamic section
1622 // aka the PT_DYNAMIC segment. The next two entries are reserved.
1623 // We saved space for them when we created the section in
1624 // Target_x86_64::got_section.
1625 const off_t got_file_offset = this->offset();
1626 gold_assert(this->data_size() >= 3 * size / 8);
1627 unsigned char* const got_view =
1628 of->get_output_view(got_file_offset, 3 * size / 8);
1629 Output_section* dynamic = this->layout_->dynamic_section();
1630 uint64_t dynamic_addr = dynamic == NULL ? 0 : dynamic->address();
1631 elfcpp::Swap<size, true>::writeval(got_view, dynamic_addr);
1632 memset(got_view + size / 8, 0, 2 * size / 8);
1633 of->write_output_view(got_file_offset, 3 * size / 8, got_view);
1636 // Create the PLT section.
1640 Target_s390<size>::make_plt_section(Symbol_table* symtab, Layout* layout)
1642 if (this->plt_ == NULL)
1644 // Create the GOT sections first.
1645 this->got_section(symtab, layout);
1647 // Ensure that .rela.dyn always appears before .rela.plt This is
1648 // necessary due to how, on 32-bit S/390 and some other targets,
1649 // .rela.dyn needs to include .rela.plt in it's range.
1650 this->rela_dyn_section(layout);
1652 this->plt_ = new Output_data_plt_s390<size>(layout,
1653 this->got_, this->got_plt_, this->got_irelative_);
1655 // Add unwind information if requested.
1656 if (parameters->options().ld_generated_unwind_info())
1657 this->plt_->add_eh_frame(layout);
1659 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1661 | elfcpp::SHF_EXECINSTR),
1662 this->plt_, ORDER_PLT, false);
1664 // Make the sh_info field of .rela.plt point to .plt.
1665 Output_section* rela_plt_os = this->plt_->rela_plt()->output_section();
1666 rela_plt_os->set_info_section(this->plt_->output_section());
1670 // Create a PLT entry for a global symbol.
1674 Target_s390<size>::make_plt_entry(Symbol_table* symtab, Layout* layout,
1677 if (gsym->has_plt_offset())
1680 if (this->plt_ == NULL)
1681 this->make_plt_section(symtab, layout);
1683 this->plt_->add_entry(symtab, layout, gsym);
1686 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1690 Target_s390<size>::make_local_ifunc_plt_entry(
1691 Symbol_table* symtab, Layout* layout,
1692 Sized_relobj_file<size, true>* relobj,
1693 unsigned int local_sym_index)
1695 if (relobj->local_has_plt_offset(local_sym_index))
1697 if (this->plt_ == NULL)
1698 this->make_plt_section(symtab, layout);
1699 unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout,
1702 relobj->set_local_plt_offset(local_sym_index, plt_offset);
1705 // Return the number of entries in the PLT.
1709 Target_s390<size>::plt_entry_count() const
1711 if (this->plt_ == NULL)
1713 return this->plt_->entry_count();
1716 // Return the offset of the first non-reserved PLT entry.
1720 Target_s390<size>::first_plt_entry_offset() const
1722 return this->plt_->first_plt_entry_offset();
1725 // Return the size of each PLT entry.
1729 Target_s390<size>::plt_entry_size() const
1731 return this->plt_->get_plt_entry_size();
1734 // Create the GOT and PLT sections for an incremental update.
1737 Output_data_got_base*
1738 Target_s390<size>::init_got_plt_for_update(Symbol_table* symtab,
1740 unsigned int got_count,
1741 unsigned int plt_count)
1743 gold_assert(this->got_ == NULL);
1745 // Add the three reserved entries.
1746 this->got_plt_ = new Output_data_got_plt_s390<size>(layout, (plt_count + 3) * size / 8);
1747 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1749 | elfcpp::SHF_WRITE),
1750 this->got_plt_, ORDER_NON_RELRO_FIRST,
1753 // If there are any IRELATIVE relocations, they get GOT entries in
1754 // .got.plt after the jump slot entries.
1755 this->got_irelative_ = new Output_data_space(0, size / 8, "** GOT IRELATIVE PLT");
1756 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1757 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
1758 this->got_irelative_,
1759 ORDER_NON_RELRO_FIRST, false);
1761 this->got_ = new Output_data_got<size, true>(got_count * size / 8);
1762 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1764 | elfcpp::SHF_WRITE),
1765 this->got_, ORDER_RELRO_LAST,
1768 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
1769 this->global_offset_table_ =
1770 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1771 Symbol_table::PREDEFINED,
1773 0, 0, elfcpp::STT_OBJECT,
1775 elfcpp::STV_HIDDEN, 0,
1778 // Create the PLT section.
1779 this->plt_ = new Output_data_plt_s390<size>(layout,
1780 this->got_, this->got_plt_, this->got_irelative_, plt_count);
1782 // Add unwind information if requested.
1783 if (parameters->options().ld_generated_unwind_info())
1784 this->plt_->add_eh_frame(layout);
1786 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1787 elfcpp::SHF_ALLOC | elfcpp::SHF_EXECINSTR,
1788 this->plt_, ORDER_PLT, false);
1790 // Make the sh_info field of .rela.plt point to .plt.
1791 Output_section* rela_plt_os = this->plt_->rela_plt()->output_section();
1792 rela_plt_os->set_info_section(this->plt_->output_section());
1794 // Create the rela_dyn section.
1795 this->rela_dyn_section(layout);
1800 // Reserve a GOT entry for a local symbol, and regenerate any
1801 // necessary dynamic relocations.
1805 Target_s390<size>::reserve_local_got_entry(
1806 unsigned int got_index,
1807 Sized_relobj<size, true>* obj,
1809 unsigned int got_type)
1811 unsigned int got_offset = got_index * size / 8;
1812 Reloc_section* rela_dyn = this->rela_dyn_section(NULL);
1814 this->got_->reserve_local(got_index, obj, r_sym, got_type);
1817 case GOT_TYPE_STANDARD:
1818 if (parameters->options().output_is_position_independent())
1819 rela_dyn->add_local_relative(obj, r_sym, elfcpp::R_390_RELATIVE,
1820 this->got_, got_offset, 0, false);
1822 case GOT_TYPE_TLS_OFFSET:
1823 rela_dyn->add_local(obj, r_sym, elfcpp::R_390_TLS_TPOFF,
1824 this->got_, got_offset, 0);
1826 case GOT_TYPE_TLS_PAIR:
1827 this->got_->reserve_slot(got_index + 1);
1828 rela_dyn->add_local(obj, r_sym, elfcpp::R_390_TLS_DTPMOD,
1829 this->got_, got_offset, 0);
1836 // Reserve a GOT entry for a global symbol, and regenerate any
1837 // necessary dynamic relocations.
1841 Target_s390<size>::reserve_global_got_entry(unsigned int got_index,
1843 unsigned int got_type)
1845 unsigned int got_offset = got_index * size / 8;
1846 Reloc_section* rela_dyn = this->rela_dyn_section(NULL);
1848 this->got_->reserve_global(got_index, gsym, got_type);
1851 case GOT_TYPE_STANDARD:
1852 if (!gsym->final_value_is_known())
1854 if (gsym->is_from_dynobj()
1855 || gsym->is_undefined()
1856 || gsym->is_preemptible()
1857 || gsym->type() == elfcpp::STT_GNU_IFUNC)
1858 rela_dyn->add_global(gsym, elfcpp::R_390_GLOB_DAT,
1859 this->got_, got_offset, 0);
1861 rela_dyn->add_global_relative(gsym, elfcpp::R_390_RELATIVE,
1862 this->got_, got_offset, 0, false);
1865 case GOT_TYPE_TLS_OFFSET:
1866 rela_dyn->add_global_relative(gsym, elfcpp::R_390_TLS_TPOFF,
1867 this->got_, got_offset, 0, false);
1869 case GOT_TYPE_TLS_PAIR:
1870 this->got_->reserve_slot(got_index + 1);
1871 rela_dyn->add_global_relative(gsym, elfcpp::R_390_TLS_DTPMOD,
1872 this->got_, got_offset, 0, false);
1873 rela_dyn->add_global_relative(gsym, elfcpp::R_390_TLS_DTPOFF,
1874 this->got_, got_offset + size / 8, 0, false);
1881 // Register an existing PLT entry for a global symbol.
1885 Target_s390<size>::register_global_plt_entry(Symbol_table* symtab,
1887 unsigned int plt_index,
1890 gold_assert(this->plt_ != NULL);
1891 gold_assert(!gsym->has_plt_offset());
1893 this->plt_->reserve_slot(plt_index);
1895 gsym->set_plt_offset((plt_index + 1) * this->plt_entry_size());
1897 unsigned int got_offset = (plt_index + 3) * size / 8;
1898 this->plt_->add_relocation(symtab, layout, gsym, got_offset);
1901 // Force a COPY relocation for a given symbol.
1905 Target_s390<size>::emit_copy_reloc(
1906 Symbol_table* symtab, Symbol* sym, Output_section* os, off_t offset)
1908 this->copy_relocs_.emit_copy_reloc(symtab,
1909 symtab->get_sized_symbol<size>(sym),
1912 this->rela_dyn_section(NULL));
1915 // Create a GOT entry for the TLS module index.
1919 Target_s390<size>::got_mod_index_entry(Symbol_table* symtab, Layout* layout,
1920 Sized_relobj_file<size, true>* object)
1922 if (this->got_mod_index_offset_ == -1U)
1924 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1925 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1926 Output_data_got<size, true>* got = this->got_section(symtab, layout);
1927 unsigned int got_offset = got->add_constant(0);
1928 rela_dyn->add_local(object, 0, elfcpp::R_390_TLS_DTPMOD, got,
1930 got->add_constant(0);
1931 this->got_mod_index_offset_ = got_offset;
1933 return this->got_mod_index_offset_;
1936 // Optimize the TLS relocation type based on what we know about the
1937 // symbol. IS_FINAL is true if the final address of this symbol is
1938 // known at link time.
1941 tls::Tls_optimization
1942 Target_s390<size>::optimize_tls_reloc(bool is_final, int r_type)
1944 // If we are generating a shared library, then we can't do anything
1946 if (parameters->options().shared())
1947 return tls::TLSOPT_NONE;
1951 case elfcpp::R_390_TLS_GD32:
1952 case elfcpp::R_390_TLS_GD64:
1953 case elfcpp::R_390_TLS_GDCALL:
1954 // These are General-Dynamic which permits fully general TLS
1955 // access. Since we know that we are generating an executable,
1956 // we can convert this to Initial-Exec. If we also know that
1957 // this is a local symbol, we can further switch to Local-Exec.
1959 return tls::TLSOPT_TO_LE;
1960 return tls::TLSOPT_TO_IE;
1962 case elfcpp::R_390_TLS_LDM32:
1963 case elfcpp::R_390_TLS_LDM64:
1964 case elfcpp::R_390_TLS_LDO32:
1965 case elfcpp::R_390_TLS_LDO64:
1966 case elfcpp::R_390_TLS_LDCALL:
1967 // This is Local-Dynamic, which refers to a local symbol in the
1968 // dynamic TLS block. Since we know that we generating an
1969 // executable, we can switch to Local-Exec.
1970 return tls::TLSOPT_TO_LE;
1972 case elfcpp::R_390_TLS_IE32:
1973 case elfcpp::R_390_TLS_IE64:
1974 case elfcpp::R_390_TLS_GOTIE32:
1975 case elfcpp::R_390_TLS_GOTIE64:
1976 case elfcpp::R_390_TLS_LOAD:
1977 // These are Initial-Exec relocs which get the thread offset
1978 // from the GOT. If we know that we are linking against the
1979 // local symbol, we can switch to Local-Exec, which links the
1980 // thread offset into the instruction.
1982 return tls::TLSOPT_TO_LE;
1983 return tls::TLSOPT_NONE;
1985 case elfcpp::R_390_TLS_GOTIE12:
1986 case elfcpp::R_390_TLS_IEENT:
1987 case elfcpp::R_390_TLS_GOTIE20:
1988 // These are Initial-Exec, but cannot be optimized.
1989 return tls::TLSOPT_NONE;
1991 case elfcpp::R_390_TLS_LE32:
1992 case elfcpp::R_390_TLS_LE64:
1993 // When we already have Local-Exec, there is nothing further we
1995 return tls::TLSOPT_NONE;
2002 // Get the Reference_flags for a particular relocation.
2006 Target_s390<size>::Scan::get_reference_flags(unsigned int r_type)
2010 case elfcpp::R_390_NONE:
2011 case elfcpp::R_390_GNU_VTINHERIT:
2012 case elfcpp::R_390_GNU_VTENTRY:
2013 case elfcpp::R_390_GOTPC:
2014 case elfcpp::R_390_GOTPCDBL:
2015 // No symbol reference.
2018 case elfcpp::R_390_64:
2019 case elfcpp::R_390_32:
2020 case elfcpp::R_390_20:
2021 case elfcpp::R_390_16:
2022 case elfcpp::R_390_12:
2023 case elfcpp::R_390_8:
2024 return Symbol::ABSOLUTE_REF;
2026 case elfcpp::R_390_PC12DBL:
2027 case elfcpp::R_390_PC16:
2028 case elfcpp::R_390_PC16DBL:
2029 case elfcpp::R_390_PC24DBL:
2030 case elfcpp::R_390_PC32:
2031 case elfcpp::R_390_PC32DBL:
2032 case elfcpp::R_390_PC64:
2033 case elfcpp::R_390_GOTOFF16:
2034 case elfcpp::R_390_GOTOFF32:
2035 case elfcpp::R_390_GOTOFF64:
2036 return Symbol::RELATIVE_REF;
2038 case elfcpp::R_390_PLT12DBL:
2039 case elfcpp::R_390_PLT16DBL:
2040 case elfcpp::R_390_PLT24DBL:
2041 case elfcpp::R_390_PLT32:
2042 case elfcpp::R_390_PLT32DBL:
2043 case elfcpp::R_390_PLT64:
2044 case elfcpp::R_390_PLTOFF16:
2045 case elfcpp::R_390_PLTOFF32:
2046 case elfcpp::R_390_PLTOFF64:
2047 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
2049 case elfcpp::R_390_GOT12:
2050 case elfcpp::R_390_GOT16:
2051 case elfcpp::R_390_GOT20:
2052 case elfcpp::R_390_GOT32:
2053 case elfcpp::R_390_GOT64:
2054 case elfcpp::R_390_GOTENT:
2055 case elfcpp::R_390_GOTPLT12:
2056 case elfcpp::R_390_GOTPLT16:
2057 case elfcpp::R_390_GOTPLT20:
2058 case elfcpp::R_390_GOTPLT32:
2059 case elfcpp::R_390_GOTPLT64:
2060 case elfcpp::R_390_GOTPLTENT:
2062 return Symbol::ABSOLUTE_REF;
2064 case elfcpp::R_390_TLS_GD32: // Global-dynamic
2065 case elfcpp::R_390_TLS_GD64:
2066 case elfcpp::R_390_TLS_GDCALL:
2067 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2068 case elfcpp::R_390_TLS_LDM64:
2069 case elfcpp::R_390_TLS_LDO32:
2070 case elfcpp::R_390_TLS_LDO64:
2071 case elfcpp::R_390_TLS_LDCALL:
2072 case elfcpp::R_390_TLS_IE32: // Initial-exec
2073 case elfcpp::R_390_TLS_IE64:
2074 case elfcpp::R_390_TLS_IEENT:
2075 case elfcpp::R_390_TLS_GOTIE12:
2076 case elfcpp::R_390_TLS_GOTIE20:
2077 case elfcpp::R_390_TLS_GOTIE32:
2078 case elfcpp::R_390_TLS_GOTIE64:
2079 case elfcpp::R_390_TLS_LOAD:
2080 case elfcpp::R_390_TLS_LE32: // Local-exec
2081 case elfcpp::R_390_TLS_LE64:
2082 return Symbol::TLS_REF;
2084 case elfcpp::R_390_COPY:
2085 case elfcpp::R_390_GLOB_DAT:
2086 case elfcpp::R_390_JMP_SLOT:
2087 case elfcpp::R_390_RELATIVE:
2088 case elfcpp::R_390_IRELATIVE:
2089 case elfcpp::R_390_TLS_TPOFF:
2090 case elfcpp::R_390_TLS_DTPOFF:
2091 case elfcpp::R_390_TLS_DTPMOD:
2093 // Not expected. We will give an error later.
2098 // Report an unsupported relocation against a local symbol.
2102 Target_s390<size>::Scan::unsupported_reloc_local(
2103 Sized_relobj_file<size, true>* object,
2104 unsigned int r_type)
2106 gold_error(_("%s: unsupported reloc %u against local symbol"),
2107 object->name().c_str(), r_type);
2110 // We are about to emit a dynamic relocation of type R_TYPE. If the
2111 // dynamic linker does not support it, issue an error.
2115 Target_s390<size>::Scan::check_non_pic(Relobj* object, unsigned int r_type)
2117 gold_assert(r_type != elfcpp::R_390_NONE);
2123 // These are the relocation types supported by glibc for s390 64-bit.
2124 case elfcpp::R_390_RELATIVE:
2125 case elfcpp::R_390_IRELATIVE:
2126 case elfcpp::R_390_COPY:
2127 case elfcpp::R_390_GLOB_DAT:
2128 case elfcpp::R_390_JMP_SLOT:
2129 case elfcpp::R_390_TLS_DTPMOD:
2130 case elfcpp::R_390_TLS_DTPOFF:
2131 case elfcpp::R_390_TLS_TPOFF:
2132 case elfcpp::R_390_8:
2133 case elfcpp::R_390_16:
2134 case elfcpp::R_390_32:
2135 case elfcpp::R_390_64:
2136 case elfcpp::R_390_PC16:
2137 case elfcpp::R_390_PC16DBL:
2138 case elfcpp::R_390_PC32:
2139 case elfcpp::R_390_PC32DBL:
2140 case elfcpp::R_390_PC64:
2151 // These are the relocation types supported by glibc for s390 32-bit.
2152 case elfcpp::R_390_RELATIVE:
2153 case elfcpp::R_390_IRELATIVE:
2154 case elfcpp::R_390_COPY:
2155 case elfcpp::R_390_GLOB_DAT:
2156 case elfcpp::R_390_JMP_SLOT:
2157 case elfcpp::R_390_TLS_DTPMOD:
2158 case elfcpp::R_390_TLS_DTPOFF:
2159 case elfcpp::R_390_TLS_TPOFF:
2160 case elfcpp::R_390_8:
2161 case elfcpp::R_390_16:
2162 case elfcpp::R_390_32:
2163 case elfcpp::R_390_PC16:
2164 case elfcpp::R_390_PC16DBL:
2165 case elfcpp::R_390_PC32:
2166 case elfcpp::R_390_PC32DBL:
2174 // This prevents us from issuing more than one error per reloc
2175 // section. But we can still wind up issuing more than one
2176 // error per object file.
2177 if (this->issued_non_pic_error_)
2179 gold_assert(parameters->options().output_is_position_independent());
2180 object->error(_("requires unsupported dynamic reloc; "
2181 "recompile with -fPIC"));
2182 this->issued_non_pic_error_ = true;
2186 // Return whether we need to make a PLT entry for a relocation of the
2187 // given type against a STT_GNU_IFUNC symbol.
2191 Target_s390<size>::Scan::reloc_needs_plt_for_ifunc(
2192 Sized_relobj_file<size, true>* object,
2193 unsigned int r_type)
2195 int flags = Scan::get_reference_flags(r_type);
2196 if (flags & Symbol::TLS_REF)
2197 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2198 object->name().c_str(), r_type);
2202 // Scan a relocation for a local symbol.
2206 Target_s390<size>::Scan::local(Symbol_table* symtab,
2208 Target_s390<size>* target,
2209 Sized_relobj_file<size, true>* object,
2210 unsigned int data_shndx,
2211 Output_section* output_section,
2212 const elfcpp::Rela<size, true>& reloc,
2213 unsigned int r_type,
2214 const elfcpp::Sym<size, true>& lsym,
2220 // A local STT_GNU_IFUNC symbol may require a PLT entry.
2221 bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
2223 if (is_ifunc && this->reloc_needs_plt_for_ifunc(object, r_type))
2225 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2226 target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
2231 case elfcpp::R_390_NONE:
2232 case elfcpp::R_390_GNU_VTINHERIT:
2233 case elfcpp::R_390_GNU_VTENTRY:
2236 case elfcpp::R_390_64:
2237 // If building a shared library (or a position-independent
2238 // executable), we need to create a dynamic relocation for this
2239 // location. The relocation applied at link time will apply the
2240 // link-time value, so we flag the location with an
2241 // R_390_RELATIVE relocation so the dynamic loader can
2242 // relocate it easily.
2243 if (parameters->options().output_is_position_independent() && size == 64)
2245 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2246 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2247 rela_dyn->add_local_relative(object, r_sym,
2248 elfcpp::R_390_RELATIVE,
2249 output_section, data_shndx,
2250 reloc.get_r_offset(),
2251 reloc.get_r_addend(), is_ifunc);
2255 case elfcpp::R_390_32:
2256 case elfcpp::R_390_20:
2257 case elfcpp::R_390_16:
2258 case elfcpp::R_390_12:
2259 case elfcpp::R_390_8:
2260 if (parameters->options().output_is_position_independent())
2262 if (size == 32 && r_type == elfcpp::R_390_32)
2264 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2265 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2266 rela_dyn->add_local_relative(object, r_sym,
2267 elfcpp::R_390_RELATIVE,
2268 output_section, data_shndx,
2269 reloc.get_r_offset(),
2270 reloc.get_r_addend(), is_ifunc);
2274 check_non_pic(object, r_type);
2276 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2277 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2278 if (lsym.get_st_type() != elfcpp::STT_SECTION)
2279 rela_dyn->add_local(object, r_sym, r_type, output_section,
2280 data_shndx, reloc.get_r_offset(),
2281 reloc.get_r_addend());
2284 gold_assert(lsym.get_st_value() == 0);
2285 unsigned int shndx = lsym.get_st_shndx();
2287 shndx = object->adjust_sym_shndx(r_sym, shndx,
2290 object->error(_("section symbol %u has bad shndx %u"),
2293 rela_dyn->add_local_section(object, shndx,
2294 r_type, output_section,
2295 data_shndx, reloc.get_r_offset(),
2296 reloc.get_r_addend());
2301 case elfcpp::R_390_PC12DBL:
2302 case elfcpp::R_390_PC16:
2303 case elfcpp::R_390_PC16DBL:
2304 case elfcpp::R_390_PC24DBL:
2305 case elfcpp::R_390_PC32:
2306 case elfcpp::R_390_PC32DBL:
2307 case elfcpp::R_390_PC64:
2310 case elfcpp::R_390_PLT12DBL:
2311 case elfcpp::R_390_PLT16DBL:
2312 case elfcpp::R_390_PLT24DBL:
2313 case elfcpp::R_390_PLT32:
2314 case elfcpp::R_390_PLT32DBL:
2315 case elfcpp::R_390_PLT64:
2316 // Since we know this is a local symbol, we can handle this as a
2320 case elfcpp::R_390_GOTPC:
2321 case elfcpp::R_390_GOTPCDBL:
2322 case elfcpp::R_390_GOTOFF16:
2323 case elfcpp::R_390_GOTOFF32:
2324 case elfcpp::R_390_GOTOFF64:
2325 case elfcpp::R_390_PLTOFF16:
2326 case elfcpp::R_390_PLTOFF32:
2327 case elfcpp::R_390_PLTOFF64:
2328 // We need a GOT section.
2329 target->got_section(symtab, layout);
2330 // For PLTOFF*, we'd normally want a PLT section, but since we
2331 // know this is a local symbol, no PLT is needed.
2334 case elfcpp::R_390_GOT12:
2335 case elfcpp::R_390_GOT16:
2336 case elfcpp::R_390_GOT20:
2337 case elfcpp::R_390_GOT32:
2338 case elfcpp::R_390_GOT64:
2339 case elfcpp::R_390_GOTENT:
2340 case elfcpp::R_390_GOTPLT12:
2341 case elfcpp::R_390_GOTPLT16:
2342 case elfcpp::R_390_GOTPLT20:
2343 case elfcpp::R_390_GOTPLT32:
2344 case elfcpp::R_390_GOTPLT64:
2345 case elfcpp::R_390_GOTPLTENT:
2347 // The symbol requires a GOT section.
2348 Output_data_got<size, true>* got = target->got_section(symtab, layout);
2350 // The symbol requires a GOT entry.
2351 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2353 // For a STT_GNU_IFUNC symbol we want the PLT offset. That
2354 // lets function pointers compare correctly with shared
2355 // libraries. Otherwise we would need an IRELATIVE reloc.
2358 is_new = got->add_local_plt(object, r_sym, GOT_TYPE_STANDARD);
2360 is_new = got->add_local(object, r_sym, GOT_TYPE_STANDARD);
2363 // If we are generating a shared object, we need to add a
2364 // dynamic relocation for this symbol's GOT entry.
2365 if (parameters->options().output_is_position_independent())
2367 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2368 unsigned int got_offset =
2369 object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
2370 rela_dyn->add_local_relative(object, r_sym,
2371 elfcpp::R_390_RELATIVE,
2372 got, got_offset, 0, is_ifunc);
2375 // For GOTPLT*, we'd normally want a PLT section, but since
2376 // we know this is a local symbol, no PLT is needed.
2380 case elfcpp::R_390_COPY:
2381 case elfcpp::R_390_GLOB_DAT:
2382 case elfcpp::R_390_JMP_SLOT:
2383 case elfcpp::R_390_RELATIVE:
2384 case elfcpp::R_390_IRELATIVE:
2385 // These are outstanding tls relocs, which are unexpected when linking
2386 case elfcpp::R_390_TLS_TPOFF:
2387 case elfcpp::R_390_TLS_DTPOFF:
2388 case elfcpp::R_390_TLS_DTPMOD:
2389 gold_error(_("%s: unexpected reloc %u in object file"),
2390 object->name().c_str(), r_type);
2393 // These are initial tls relocs, which are expected when linking
2394 case elfcpp::R_390_TLS_GD32: // Global-dynamic
2395 case elfcpp::R_390_TLS_GD64:
2396 case elfcpp::R_390_TLS_GDCALL:
2397 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2398 case elfcpp::R_390_TLS_LDM64:
2399 case elfcpp::R_390_TLS_LDO32:
2400 case elfcpp::R_390_TLS_LDO64:
2401 case elfcpp::R_390_TLS_LDCALL:
2402 case elfcpp::R_390_TLS_IE32: // Initial-exec
2403 case elfcpp::R_390_TLS_IE64:
2404 case elfcpp::R_390_TLS_IEENT:
2405 case elfcpp::R_390_TLS_GOTIE12:
2406 case elfcpp::R_390_TLS_GOTIE20:
2407 case elfcpp::R_390_TLS_GOTIE32:
2408 case elfcpp::R_390_TLS_GOTIE64:
2409 case elfcpp::R_390_TLS_LOAD:
2410 case elfcpp::R_390_TLS_LE32: // Local-exec
2411 case elfcpp::R_390_TLS_LE64:
2413 bool output_is_shared = parameters->options().shared();
2414 const tls::Tls_optimization optimized_type
2415 = Target_s390<size>::optimize_tls_reloc(!output_is_shared,
2419 case elfcpp::R_390_TLS_GD32: // General-dynamic
2420 case elfcpp::R_390_TLS_GD64:
2421 case elfcpp::R_390_TLS_GDCALL:
2422 if (optimized_type == tls::TLSOPT_NONE)
2424 // Create a pair of GOT entries for the module index and
2425 // dtv-relative offset.
2426 Output_data_got<size, true>* got
2427 = target->got_section(symtab, layout);
2428 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2429 unsigned int shndx = lsym.get_st_shndx();
2431 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
2433 object->error(_("local symbol %u has bad shndx %u"),
2436 got->add_local_pair_with_rel(object, r_sym,
2439 target->rela_dyn_section(layout),
2440 elfcpp::R_390_TLS_DTPMOD);
2442 else if (optimized_type != tls::TLSOPT_TO_LE)
2443 unsupported_reloc_local(object, r_type);
2446 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2447 case elfcpp::R_390_TLS_LDM64:
2448 case elfcpp::R_390_TLS_LDCALL:
2449 if (optimized_type == tls::TLSOPT_NONE)
2451 // Create a GOT entry for the module index.
2452 target->got_mod_index_entry(symtab, layout, object);
2454 else if (optimized_type != tls::TLSOPT_TO_LE)
2455 unsupported_reloc_local(object, r_type);
2458 case elfcpp::R_390_TLS_LDO32:
2459 case elfcpp::R_390_TLS_LDO64:
2462 case elfcpp::R_390_TLS_IE32: // Initial-exec
2463 case elfcpp::R_390_TLS_IE64:
2464 // These two involve an absolute address
2465 if (parameters->options().shared()
2466 && optimized_type == tls::TLSOPT_NONE)
2468 if ((size == 32 && r_type == elfcpp::R_390_TLS_IE32) ||
2469 (size == 64 && r_type == elfcpp::R_390_TLS_IE64))
2471 // We need to create a dynamic relocation.
2472 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2473 unsigned int r_sym =
2474 elfcpp::elf_r_sym<size>(reloc.get_r_info());
2475 rela_dyn->add_local_relative(object, r_sym,
2476 elfcpp::R_390_RELATIVE,
2477 output_section, data_shndx,
2478 reloc.get_r_offset(),
2479 reloc.get_r_addend(), false);
2483 unsupported_reloc_local(object, r_type);
2487 case elfcpp::R_390_TLS_IEENT:
2488 case elfcpp::R_390_TLS_GOTIE12:
2489 case elfcpp::R_390_TLS_GOTIE20:
2490 case elfcpp::R_390_TLS_GOTIE32:
2491 case elfcpp::R_390_TLS_GOTIE64:
2492 case elfcpp::R_390_TLS_LOAD:
2493 layout->set_has_static_tls();
2494 if (optimized_type == tls::TLSOPT_NONE)
2496 if (!output_is_shared)
2498 // We're making an executable, and the symbol is local, but
2499 // we cannot optimize to LE. Make a const GOT entry instead.
2500 Output_data_got<size, true>* got
2501 = target->got_section(symtab, layout);
2503 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2504 got->add_local_plt(object, r_sym, GOT_TYPE_TLS_OFFSET);
2508 // Create a GOT entry for the tp-relative offset.
2509 Output_data_got<size, true>* got
2510 = target->got_section(symtab, layout);
2512 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2513 got->add_local_with_rel(object, r_sym, GOT_TYPE_TLS_OFFSET,
2514 target->rela_dyn_section(layout),
2515 elfcpp::R_390_TLS_TPOFF);
2518 else if (optimized_type != tls::TLSOPT_TO_LE)
2519 unsupported_reloc_local(object, r_type);
2522 case elfcpp::R_390_TLS_LE32: // Local-exec
2523 case elfcpp::R_390_TLS_LE64:
2524 layout->set_has_static_tls();
2525 if (output_is_shared)
2527 // We need to create a dynamic relocation.
2528 if ((size == 32 && r_type == elfcpp::R_390_TLS_LE32) ||
2529 (size == 64 && r_type == elfcpp::R_390_TLS_LE64))
2531 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2533 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2534 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
2535 rela_dyn->add_local(object, r_sym, elfcpp::R_390_TLS_TPOFF,
2536 output_section, data_shndx,
2537 reloc.get_r_offset(),
2538 reloc.get_r_addend());
2542 unsupported_reloc_local(object, r_type);
2554 gold_error(_("%s: unsupported reloc %u against local symbol"),
2555 object->name().c_str(), r_type);
2560 // Scan a relocation for a global symbol.
2564 Target_s390<size>::Scan::global(Symbol_table* symtab,
2566 Target_s390<size>* target,
2567 Sized_relobj_file<size, true>* object,
2568 unsigned int data_shndx,
2569 Output_section* output_section,
2570 const elfcpp::Rela<size, true>& reloc,
2571 unsigned int r_type,
2574 // A STT_GNU_IFUNC symbol may require a PLT entry.
2575 if (gsym->type() == elfcpp::STT_GNU_IFUNC
2576 && this->reloc_needs_plt_for_ifunc(object, r_type))
2577 target->make_plt_entry(symtab, layout, gsym);
2581 case elfcpp::R_390_NONE:
2582 case elfcpp::R_390_GNU_VTINHERIT:
2583 case elfcpp::R_390_GNU_VTENTRY:
2586 case elfcpp::R_390_64:
2587 case elfcpp::R_390_32:
2588 case elfcpp::R_390_20:
2589 case elfcpp::R_390_16:
2590 case elfcpp::R_390_12:
2591 case elfcpp::R_390_8:
2593 // Make a PLT entry if necessary.
2594 if (gsym->needs_plt_entry())
2596 target->make_plt_entry(symtab, layout, gsym);
2597 // Since this is not a PC-relative relocation, we may be
2598 // taking the address of a function. In that case we need to
2599 // set the entry in the dynamic symbol table to the address of
2601 if (gsym->is_from_dynobj() && !parameters->options().shared())
2602 gsym->set_needs_dynsym_value();
2604 // Make a dynamic relocation if necessary.
2605 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2607 if (!parameters->options().output_is_position_independent()
2608 && gsym->may_need_copy_reloc())
2610 target->copy_reloc(symtab, layout, object,
2611 data_shndx, output_section, gsym, reloc);
2613 else if (((size == 64 && r_type == elfcpp::R_390_64)
2614 || (size == 32 && r_type == elfcpp::R_390_32))
2615 && gsym->type() == elfcpp::STT_GNU_IFUNC
2616 && gsym->can_use_relative_reloc(false)
2617 && !gsym->is_from_dynobj()
2618 && !gsym->is_undefined()
2619 && !gsym->is_preemptible())
2621 // Use an IRELATIVE reloc for a locally defined
2622 // STT_GNU_IFUNC symbol. This makes a function
2623 // address in a PIE executable match the address in a
2624 // shared library that it links against.
2625 Reloc_section* rela_dyn =
2626 target->rela_irelative_section(layout);
2627 unsigned int r_type = elfcpp::R_390_IRELATIVE;
2628 rela_dyn->add_symbolless_global_addend(gsym, r_type,
2629 output_section, object,
2631 reloc.get_r_offset(),
2632 reloc.get_r_addend());
2634 else if (((size == 64 && r_type == elfcpp::R_390_64)
2635 || (size == 32 && r_type == elfcpp::R_390_32))
2636 && gsym->can_use_relative_reloc(false))
2638 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2639 rela_dyn->add_global_relative(gsym, elfcpp::R_390_RELATIVE,
2640 output_section, object,
2642 reloc.get_r_offset(),
2643 reloc.get_r_addend(), false);
2647 check_non_pic(object, r_type);
2648 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2649 rela_dyn->add_global(gsym, r_type, output_section, object,
2650 data_shndx, reloc.get_r_offset(),
2651 reloc.get_r_addend());
2657 case elfcpp::R_390_PC12DBL:
2658 case elfcpp::R_390_PC16:
2659 case elfcpp::R_390_PC16DBL:
2660 case elfcpp::R_390_PC24DBL:
2661 case elfcpp::R_390_PC32:
2662 case elfcpp::R_390_PC32DBL:
2663 case elfcpp::R_390_PC64:
2665 // Make a PLT entry if necessary.
2666 if (gsym->needs_plt_entry())
2668 target->make_plt_entry(symtab, layout, gsym);
2669 // larl is often used to take address of a function. Aim the
2670 // symbol at the PLT entry.
2671 if (gsym->is_from_dynobj() && !parameters->options().shared())
2672 gsym->set_needs_dynsym_value();
2674 // Make a dynamic relocation if necessary.
2675 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2677 if (parameters->options().output_is_executable()
2678 && gsym->may_need_copy_reloc())
2680 target->copy_reloc(symtab, layout, object,
2681 data_shndx, output_section, gsym, reloc);
2685 check_non_pic(object, r_type);
2686 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2687 rela_dyn->add_global(gsym, r_type, output_section, object,
2688 data_shndx, reloc.get_r_offset(),
2689 reloc.get_r_addend());
2695 case elfcpp::R_390_PLT12DBL:
2696 case elfcpp::R_390_PLT16DBL:
2697 case elfcpp::R_390_PLT24DBL:
2698 case elfcpp::R_390_PLT32:
2699 case elfcpp::R_390_PLT32DBL:
2700 case elfcpp::R_390_PLT64:
2701 // If the symbol is fully resolved, this is just a PC32 reloc.
2702 // Otherwise we need a PLT entry.
2703 if (gsym->final_value_is_known())
2705 // If building a shared library, we can also skip the PLT entry
2706 // if the symbol is defined in the output file and is protected
2708 if (gsym->is_defined()
2709 && !gsym->is_from_dynobj()
2710 && !gsym->is_preemptible())
2712 target->make_plt_entry(symtab, layout, gsym);
2715 case elfcpp::R_390_GOTPC:
2716 case elfcpp::R_390_GOTPCDBL:
2717 case elfcpp::R_390_GOTOFF16:
2718 case elfcpp::R_390_GOTOFF32:
2719 case elfcpp::R_390_GOTOFF64:
2720 case elfcpp::R_390_PLTOFF16:
2721 case elfcpp::R_390_PLTOFF32:
2722 case elfcpp::R_390_PLTOFF64:
2723 // We need a GOT section.
2724 target->got_section(symtab, layout);
2725 // For PLTOFF*, we also need a PLT entry (but only if the
2726 // symbol is not fully resolved).
2727 if ((r_type == elfcpp::R_390_PLTOFF16
2728 || r_type == elfcpp::R_390_PLTOFF32
2729 || r_type == elfcpp::R_390_PLTOFF64)
2730 && !gsym->final_value_is_known())
2731 target->make_plt_entry(symtab, layout, gsym);
2734 case elfcpp::R_390_GOT12:
2735 case elfcpp::R_390_GOT16:
2736 case elfcpp::R_390_GOT20:
2737 case elfcpp::R_390_GOT32:
2738 case elfcpp::R_390_GOT64:
2739 case elfcpp::R_390_GOTENT:
2740 case elfcpp::R_390_GOTPLT12:
2741 case elfcpp::R_390_GOTPLT16:
2742 case elfcpp::R_390_GOTPLT20:
2743 case elfcpp::R_390_GOTPLT32:
2744 case elfcpp::R_390_GOTPLT64:
2745 case elfcpp::R_390_GOTPLTENT:
2747 // The symbol requires a GOT entry.
2748 Output_data_got<size, true>* got = target->got_section(symtab, layout);
2750 if (gsym->final_value_is_known())
2752 // For a STT_GNU_IFUNC symbol we want the PLT address.
2753 if (gsym->type() == elfcpp::STT_GNU_IFUNC)
2754 got->add_global_plt(gsym, GOT_TYPE_STANDARD);
2756 got->add_global(gsym, GOT_TYPE_STANDARD);
2760 // If this symbol is not fully resolved, we need to add a
2761 // dynamic relocation for it.
2762 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2764 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2766 // 1) The symbol may be defined in some other module.
2768 // 2) We are building a shared library and this is a
2769 // protected symbol; using GLOB_DAT means that the dynamic
2770 // linker can use the address of the PLT in the main
2771 // executable when appropriate so that function address
2772 // comparisons work.
2774 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2775 // code, again so that function address comparisons work.
2776 if (gsym->is_from_dynobj()
2777 || gsym->is_undefined()
2778 || gsym->is_preemptible()
2779 || (gsym->visibility() == elfcpp::STV_PROTECTED
2780 && parameters->options().shared())
2781 || (gsym->type() == elfcpp::STT_GNU_IFUNC
2782 && parameters->options().output_is_position_independent()))
2783 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn,
2784 elfcpp::R_390_GLOB_DAT);
2787 // For a STT_GNU_IFUNC symbol we want to write the PLT
2788 // offset into the GOT, so that function pointer
2789 // comparisons work correctly.
2791 if (gsym->type() != elfcpp::STT_GNU_IFUNC)
2792 is_new = got->add_global(gsym, GOT_TYPE_STANDARD);
2795 is_new = got->add_global_plt(gsym, GOT_TYPE_STANDARD);
2796 // Tell the dynamic linker to use the PLT address
2797 // when resolving relocations.
2798 if (gsym->is_from_dynobj()
2799 && !parameters->options().shared())
2800 gsym->set_needs_dynsym_value();
2804 unsigned int got_off = gsym->got_offset(GOT_TYPE_STANDARD);
2805 rela_dyn->add_global_relative(gsym,
2806 elfcpp::R_390_RELATIVE,
2807 got, got_off, 0, false);
2814 case elfcpp::R_390_COPY:
2815 case elfcpp::R_390_GLOB_DAT:
2816 case elfcpp::R_390_JMP_SLOT:
2817 case elfcpp::R_390_RELATIVE:
2818 case elfcpp::R_390_IRELATIVE:
2819 // These are outstanding tls relocs, which are unexpected when linking
2820 case elfcpp::R_390_TLS_TPOFF:
2821 case elfcpp::R_390_TLS_DTPOFF:
2822 case elfcpp::R_390_TLS_DTPMOD:
2823 gold_error(_("%s: unexpected reloc %u in object file"),
2824 object->name().c_str(), r_type);
2827 // These are initial tls relocs, which are expected for global()
2828 case elfcpp::R_390_TLS_GD32: // Global-dynamic
2829 case elfcpp::R_390_TLS_GD64:
2830 case elfcpp::R_390_TLS_GDCALL:
2831 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2832 case elfcpp::R_390_TLS_LDM64:
2833 case elfcpp::R_390_TLS_LDO32:
2834 case elfcpp::R_390_TLS_LDO64:
2835 case elfcpp::R_390_TLS_LDCALL:
2836 case elfcpp::R_390_TLS_IE32: // Initial-exec
2837 case elfcpp::R_390_TLS_IE64:
2838 case elfcpp::R_390_TLS_IEENT:
2839 case elfcpp::R_390_TLS_GOTIE12:
2840 case elfcpp::R_390_TLS_GOTIE20:
2841 case elfcpp::R_390_TLS_GOTIE32:
2842 case elfcpp::R_390_TLS_GOTIE64:
2843 case elfcpp::R_390_TLS_LOAD:
2844 case elfcpp::R_390_TLS_LE32: // Local-exec
2845 case elfcpp::R_390_TLS_LE64:
2847 // For the optimizable Initial-Exec model, we can treat undef symbols
2848 // as final when building an executable.
2849 const bool is_final = (gsym->final_value_is_known() ||
2850 ((r_type == elfcpp::R_390_TLS_IE32 ||
2851 r_type == elfcpp::R_390_TLS_IE64 ||
2852 r_type == elfcpp::R_390_TLS_GOTIE32 ||
2853 r_type == elfcpp::R_390_TLS_GOTIE64) &&
2854 gsym->is_undefined() &&
2855 parameters->options().output_is_executable()));
2856 const tls::Tls_optimization optimized_type
2857 = Target_s390<size>::optimize_tls_reloc(is_final, r_type);
2860 case elfcpp::R_390_TLS_GD32: // General-dynamic
2861 case elfcpp::R_390_TLS_GD64:
2862 case elfcpp::R_390_TLS_GDCALL:
2863 if (optimized_type == tls::TLSOPT_NONE)
2865 // Create a pair of GOT entries for the module index and
2866 // dtv-relative offset.
2867 Output_data_got<size, true>* got
2868 = target->got_section(symtab, layout);
2869 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
2870 target->rela_dyn_section(layout),
2871 elfcpp::R_390_TLS_DTPMOD,
2872 elfcpp::R_390_TLS_DTPOFF);
2874 else if (optimized_type == tls::TLSOPT_TO_IE)
2876 // Create a GOT entry for the tp-relative offset.
2877 Output_data_got<size, true>* got
2878 = target->got_section(symtab, layout);
2879 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2880 target->rela_dyn_section(layout),
2881 elfcpp::R_390_TLS_TPOFF);
2883 else if (optimized_type != tls::TLSOPT_TO_LE)
2884 unsupported_reloc_global(object, r_type, gsym);
2887 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
2888 case elfcpp::R_390_TLS_LDM64:
2889 case elfcpp::R_390_TLS_LDCALL:
2890 if (optimized_type == tls::TLSOPT_NONE)
2892 // Create a GOT entry for the module index.
2893 target->got_mod_index_entry(symtab, layout, object);
2895 else if (optimized_type != tls::TLSOPT_TO_LE)
2896 unsupported_reloc_global(object, r_type, gsym);
2899 case elfcpp::R_390_TLS_LDO32:
2900 case elfcpp::R_390_TLS_LDO64:
2903 case elfcpp::R_390_TLS_IE32: // Initial-exec
2904 case elfcpp::R_390_TLS_IE64:
2905 // These two involve an absolute address
2906 if (parameters->options().shared())
2908 if ((size == 32 && r_type == elfcpp::R_390_TLS_IE32) ||
2909 (size == 64 && r_type == elfcpp::R_390_TLS_IE64))
2911 // We need to create a dynamic relocation.
2912 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2913 rela_dyn->add_global_relative(gsym, elfcpp::R_390_RELATIVE,
2914 output_section, object,
2916 reloc.get_r_offset(),
2917 reloc.get_r_addend(), false);
2921 unsupported_reloc_global(object, r_type, gsym);
2925 case elfcpp::R_390_TLS_IEENT:
2926 case elfcpp::R_390_TLS_GOTIE12:
2927 case elfcpp::R_390_TLS_GOTIE20:
2928 case elfcpp::R_390_TLS_GOTIE32:
2929 case elfcpp::R_390_TLS_GOTIE64:
2930 case elfcpp::R_390_TLS_LOAD:
2931 layout->set_has_static_tls();
2932 if (optimized_type == tls::TLSOPT_NONE)
2934 if (is_final && !parameters->options().shared())
2936 // We're making an executable, and the symbol is local, but
2937 // we cannot optimize to LE. Make a const GOT entry instead.
2938 Output_data_got<size, true>* got
2939 = target->got_section(symtab, layout);
2940 got->add_global_plt(gsym, GOT_TYPE_TLS_OFFSET);
2944 // Create a GOT entry for the tp-relative offset.
2945 Output_data_got<size, true>* got
2946 = target->got_section(symtab, layout);
2947 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2948 target->rela_dyn_section(layout),
2949 elfcpp::R_390_TLS_TPOFF);
2952 else if (optimized_type != tls::TLSOPT_TO_LE)
2953 unsupported_reloc_global(object, r_type, gsym);
2956 case elfcpp::R_390_TLS_LE32: // Local-exec
2957 case elfcpp::R_390_TLS_LE64:
2958 layout->set_has_static_tls();
2959 if (parameters->options().shared())
2961 // We need to create a dynamic relocation.
2962 if ((size == 32 && r_type == elfcpp::R_390_TLS_LE32) ||
2963 (size == 64 && r_type == elfcpp::R_390_TLS_LE64))
2965 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2966 rela_dyn->add_global(gsym, elfcpp::R_390_TLS_TPOFF,
2967 output_section, object,
2968 data_shndx, reloc.get_r_offset(),
2969 reloc.get_r_addend());
2973 unsupported_reloc_global(object, r_type, gsym);
2985 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2986 object->name().c_str(), r_type,
2987 gsym->demangled_name().c_str());
2993 // Report an unsupported relocation against a global symbol.
2997 Target_s390<size>::Scan::unsupported_reloc_global(
2998 Sized_relobj_file<size, true>* object,
2999 unsigned int r_type,
3002 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3003 object->name().c_str(), r_type, gsym->demangled_name().c_str());
3006 // Returns true if this relocation type could be that of a function pointer.
3009 Target_s390<size>::Scan::possible_function_pointer_reloc(unsigned int r_type)
3013 case elfcpp::R_390_32:
3014 case elfcpp::R_390_64:
3015 case elfcpp::R_390_PC32DBL: // could be used by larl insn
3016 case elfcpp::R_390_GOT12:
3017 case elfcpp::R_390_GOT16:
3018 case elfcpp::R_390_GOT20:
3019 case elfcpp::R_390_GOT32:
3020 case elfcpp::R_390_GOT64:
3021 case elfcpp::R_390_GOTENT:
3022 case elfcpp::R_390_GOTOFF16:
3023 case elfcpp::R_390_GOTOFF32:
3024 case elfcpp::R_390_GOTOFF64:
3030 // For safe ICF, scan a relocation for a local symbol to check if it
3031 // corresponds to a function pointer being taken. In that case mark
3032 // the function whose pointer was taken as not foldable.
3036 Target_s390<size>::Scan::local_reloc_may_be_function_pointer(
3039 Target_s390<size>* ,
3040 Sized_relobj_file<size, true>* ,
3043 const elfcpp::Rela<size, true>& ,
3044 unsigned int r_type,
3045 const elfcpp::Sym<size, true>&)
3047 // When building a shared library, do not fold any local symbols.
3048 return (parameters->options().shared()
3049 || possible_function_pointer_reloc(r_type));
3052 // For safe ICF, scan a relocation for a global symbol to check if it
3053 // corresponds to a function pointer being taken. In that case mark
3054 // the function whose pointer was taken as not foldable.
3058 Target_s390<size>::Scan::global_reloc_may_be_function_pointer(
3061 Target_s390<size>* ,
3062 Sized_relobj_file<size, true>* ,
3065 const elfcpp::Rela<size, true>& ,
3066 unsigned int r_type,
3069 // When building a shared library, do not fold symbols whose visibility
3070 // is hidden, internal or protected.
3071 return ((parameters->options().shared()
3072 && (gsym->visibility() == elfcpp::STV_INTERNAL
3073 || gsym->visibility() == elfcpp::STV_PROTECTED
3074 || gsym->visibility() == elfcpp::STV_HIDDEN))
3075 || possible_function_pointer_reloc(r_type));
3080 Target_s390<size>::gc_process_relocs(Symbol_table* symtab,
3082 Sized_relobj_file<size, true>* object,
3083 unsigned int data_shndx,
3084 unsigned int sh_type,
3085 const unsigned char* prelocs,
3087 Output_section* output_section,
3088 bool needs_special_offset_handling,
3089 size_t local_symbol_count,
3090 const unsigned char* plocal_symbols)
3093 if (sh_type == elfcpp::SHT_REL)
3096 gold::gc_process_relocs<size, true, Target_s390<size>, elfcpp::SHT_RELA,
3097 typename Target_s390<size>::Scan,
3098 typename Target_s390<size>::Relocatable_size_for_reloc>(
3107 needs_special_offset_handling,
3112 // Perform a relocation.
3116 Target_s390<size>::Relocate::relocate(
3117 const Relocate_info<size, true>* relinfo,
3118 Target_s390<size>* target,
3121 const elfcpp::Rela<size, true>& rela,
3122 unsigned int r_type,
3123 const Sized_symbol<size>* gsym,
3124 const Symbol_value<size>* psymval,
3125 unsigned char* view,
3126 typename elfcpp::Elf_types<size>::Elf_Addr address,
3127 section_size_type view_size)
3132 const Sized_relobj_file<size, true>* object = relinfo->object;
3134 // Pick the value to use for symbols defined in the PLT.
3135 Symbol_value<size> symval;
3137 && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
3139 symval.set_output_value(target->plt_address_for_global(gsym));
3142 else if (gsym == NULL && psymval->is_ifunc_symbol())
3144 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3145 if (object->local_has_plt_offset(r_sym))
3147 symval.set_output_value(target->plt_address_for_local(object, r_sym));
3152 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3154 typename elfcpp::Elf_types<size>::Elf_Addr value = 0;
3158 case elfcpp::R_390_PLT64:
3159 case elfcpp::R_390_PLT32:
3160 case elfcpp::R_390_PLT32DBL:
3161 case elfcpp::R_390_PLT24DBL:
3162 case elfcpp::R_390_PLT16DBL:
3163 case elfcpp::R_390_PLT12DBL:
3164 gold_assert(gsym == NULL
3165 || gsym->has_plt_offset()
3166 || gsym->final_value_is_known()
3167 || (gsym->is_defined()
3168 && !gsym->is_from_dynobj()
3169 && !gsym->is_preemptible()));
3171 case elfcpp::R_390_8:
3172 case elfcpp::R_390_12:
3173 case elfcpp::R_390_16:
3174 case elfcpp::R_390_20:
3175 case elfcpp::R_390_32:
3176 case elfcpp::R_390_64:
3177 case elfcpp::R_390_PC16:
3178 case elfcpp::R_390_PC32:
3179 case elfcpp::R_390_PC64:
3180 case elfcpp::R_390_PC32DBL:
3181 case elfcpp::R_390_PC24DBL:
3182 case elfcpp::R_390_PC16DBL:
3183 case elfcpp::R_390_PC12DBL:
3184 value = psymval->value(object, addend);
3187 case elfcpp::R_390_GOTPC:
3188 case elfcpp::R_390_GOTPCDBL:
3189 gold_assert(gsym != NULL);
3190 value = target->got_address() + addend;
3193 case elfcpp::R_390_PLTOFF64:
3194 case elfcpp::R_390_PLTOFF32:
3195 case elfcpp::R_390_PLTOFF16:
3196 gold_assert(gsym == NULL
3197 || gsym->has_plt_offset()
3198 || gsym->final_value_is_known());
3200 case elfcpp::R_390_GOTOFF64:
3201 case elfcpp::R_390_GOTOFF32:
3202 case elfcpp::R_390_GOTOFF16:
3203 value = (psymval->value(object, addend)
3204 - target->got_address());
3207 case elfcpp::R_390_GOT12:
3208 case elfcpp::R_390_GOT16:
3209 case elfcpp::R_390_GOT20:
3210 case elfcpp::R_390_GOT32:
3211 case elfcpp::R_390_GOT64:
3212 case elfcpp::R_390_GOTENT:
3213 case elfcpp::R_390_GOTPLT12:
3214 case elfcpp::R_390_GOTPLT16:
3215 case elfcpp::R_390_GOTPLT20:
3216 case elfcpp::R_390_GOTPLT32:
3217 case elfcpp::R_390_GOTPLT64:
3218 case elfcpp::R_390_GOTPLTENT:
3220 unsigned int got_offset = 0;
3223 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
3224 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
3228 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3229 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
3230 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
3232 value = got_offset + target->got_main_offset() + addend;
3236 // These are initial tls relocs, which are expected when linking
3237 case elfcpp::R_390_TLS_LOAD:
3238 case elfcpp::R_390_TLS_GDCALL: // Global-dynamic
3239 case elfcpp::R_390_TLS_GD32:
3240 case elfcpp::R_390_TLS_GD64:
3241 case elfcpp::R_390_TLS_LDCALL: // Local-dynamic
3242 case elfcpp::R_390_TLS_LDM32:
3243 case elfcpp::R_390_TLS_LDM64:
3244 case elfcpp::R_390_TLS_LDO32:
3245 case elfcpp::R_390_TLS_LDO64:
3246 case elfcpp::R_390_TLS_GOTIE12: // Initial-exec
3247 case elfcpp::R_390_TLS_GOTIE20:
3248 case elfcpp::R_390_TLS_GOTIE32:
3249 case elfcpp::R_390_TLS_GOTIE64:
3250 case elfcpp::R_390_TLS_IE32:
3251 case elfcpp::R_390_TLS_IE64:
3252 case elfcpp::R_390_TLS_IEENT:
3253 case elfcpp::R_390_TLS_LE32: // Local-exec
3254 case elfcpp::R_390_TLS_LE64:
3255 value = this->relocate_tls(relinfo, target, relnum, rela, r_type, gsym, psymval,
3263 typename S390_relocate_functions<size>::Status status
3264 = S390_relocate_functions<size>::STATUS_OK;
3268 case elfcpp::R_390_NONE:
3269 case elfcpp::R_390_GNU_VTINHERIT:
3270 case elfcpp::R_390_GNU_VTENTRY:
3271 case elfcpp::R_390_TLS_GDCALL:
3272 case elfcpp::R_390_TLS_LDCALL:
3273 case elfcpp::R_390_TLS_LOAD:
3276 case elfcpp::R_390_64:
3277 case elfcpp::R_390_GOT64:
3278 case elfcpp::R_390_GOTPLT64:
3279 case elfcpp::R_390_PLTOFF64:
3280 case elfcpp::R_390_GOTOFF64:
3281 case elfcpp::R_390_TLS_GD64:
3282 case elfcpp::R_390_TLS_LDM64:
3283 case elfcpp::R_390_TLS_LDO64:
3284 case elfcpp::R_390_TLS_GOTIE64:
3285 case elfcpp::R_390_TLS_IE64:
3286 case elfcpp::R_390_TLS_LE64:
3287 Relocate_functions<size, true>::rela64(view, value, 0);
3290 case elfcpp::R_390_32:
3291 case elfcpp::R_390_GOT32:
3292 case elfcpp::R_390_GOTPLT32:
3293 case elfcpp::R_390_PLTOFF32:
3294 case elfcpp::R_390_GOTOFF32:
3295 case elfcpp::R_390_TLS_GD32:
3296 case elfcpp::R_390_TLS_LDM32:
3297 case elfcpp::R_390_TLS_LDO32:
3298 case elfcpp::R_390_TLS_GOTIE32:
3299 case elfcpp::R_390_TLS_IE32:
3300 case elfcpp::R_390_TLS_LE32:
3301 Relocate_functions<size, true>::rela32(view, value, 0);
3304 case elfcpp::R_390_20:
3305 case elfcpp::R_390_GOT20:
3306 case elfcpp::R_390_GOTPLT20:
3307 case elfcpp::R_390_TLS_GOTIE20:
3308 status = S390_relocate_functions<size>::rela20(view, value);
3311 case elfcpp::R_390_16:
3312 case elfcpp::R_390_GOT16:
3313 case elfcpp::R_390_GOTPLT16:
3314 case elfcpp::R_390_PLTOFF16:
3315 case elfcpp::R_390_GOTOFF16:
3316 status = S390_relocate_functions<size>::rela16(view, value);
3319 case elfcpp::R_390_12:
3320 case elfcpp::R_390_GOT12:
3321 case elfcpp::R_390_GOTPLT12:
3322 case elfcpp::R_390_TLS_GOTIE12:
3323 status = S390_relocate_functions<size>::rela12(view, value);
3326 case elfcpp::R_390_8:
3327 Relocate_functions<size, true>::rela8(view, value, 0);
3330 case elfcpp::R_390_PC16:
3331 Relocate_functions<size, true>::pcrela16(view, value, 0,
3335 case elfcpp::R_390_PLT64:
3336 case elfcpp::R_390_PC64:
3337 Relocate_functions<size, true>::pcrela64(view, value, 0, address);
3340 case elfcpp::R_390_PLT32:
3341 case elfcpp::R_390_PC32:
3342 case elfcpp::R_390_GOTPC:
3343 Relocate_functions<size, true>::pcrela32(view, value, 0, address);
3346 case elfcpp::R_390_PLT32DBL:
3347 case elfcpp::R_390_PC32DBL:
3348 case elfcpp::R_390_GOTPCDBL:
3349 status = S390_relocate_functions<size>::pcrela32dbl(view, value, address);
3352 case elfcpp::R_390_PLT24DBL:
3353 case elfcpp::R_390_PC24DBL:
3354 status = S390_relocate_functions<size>::pcrela24dbl(view, value, address);
3357 case elfcpp::R_390_PLT16DBL:
3358 case elfcpp::R_390_PC16DBL:
3359 status = S390_relocate_functions<size>::pcrela16dbl(view, value, address);
3362 case elfcpp::R_390_PLT12DBL:
3363 case elfcpp::R_390_PC12DBL:
3364 status = S390_relocate_functions<size>::pcrela12dbl(view, value, address);
3367 case elfcpp::R_390_GOTENT:
3368 case elfcpp::R_390_GOTPLTENT:
3369 case elfcpp::R_390_TLS_IEENT:
3370 value += target->got_address();
3371 status = S390_relocate_functions<size>::pcrela32dbl(view, value, address);
3374 case elfcpp::R_390_COPY:
3375 case elfcpp::R_390_GLOB_DAT:
3376 case elfcpp::R_390_JMP_SLOT:
3377 case elfcpp::R_390_RELATIVE:
3378 case elfcpp::R_390_IRELATIVE:
3379 // These are outstanding tls relocs, which are unexpected when linking
3380 case elfcpp::R_390_TLS_TPOFF:
3381 case elfcpp::R_390_TLS_DTPMOD:
3382 case elfcpp::R_390_TLS_DTPOFF:
3383 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3384 _("unexpected reloc %u in object file"),
3389 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3390 _("unsupported reloc %u"),
3395 if (status != S390_relocate_functions<size>::STATUS_OK)
3397 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3398 _("relocation overflow"));
3404 // Perform a TLS relocation.
3407 inline typename elfcpp::Elf_types<size>::Elf_Addr
3408 Target_s390<size>::Relocate::relocate_tls(
3409 const Relocate_info<size, true>* relinfo,
3410 Target_s390<size>* target,
3412 const elfcpp::Rela<size, true>& rela,
3413 unsigned int r_type,
3414 const Sized_symbol<size>* gsym,
3415 const Symbol_value<size>* psymval,
3416 unsigned char* view,
3417 section_size_type view_size)
3419 Output_segment* tls_segment = relinfo->layout->tls_segment();
3421 const Sized_relobj_file<size, true>* object = relinfo->object;
3422 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3423 elfcpp::Shdr<size, true> data_shdr(relinfo->data_shdr);
3424 bool is_allocatable = (data_shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0;
3426 typename elfcpp::Elf_types<size>::Elf_Addr value
3427 = psymval->value(relinfo->object, addend);
3429 const bool is_final = (gsym == NULL
3430 ? !parameters->options().shared()
3431 : gsym->final_value_is_known());
3432 tls::Tls_optimization optimized_type
3433 = Target_s390<size>::optimize_tls_reloc(is_final, r_type);
3436 case elfcpp::R_390_TLS_GDCALL: // Global-dynamic marker
3437 if (optimized_type == tls::TLSOPT_TO_LE)
3439 if (tls_segment == NULL)
3441 gold_assert(parameters->errors()->error_count() > 0
3442 || issue_undefined_symbol_error(gsym));
3445 this->tls_gd_to_le(relinfo, relnum, rela, view, view_size);
3450 if (optimized_type == tls::TLSOPT_TO_IE)
3452 this->tls_gd_to_ie(relinfo, relnum, rela, view, view_size);
3455 else if (optimized_type == tls::TLSOPT_NONE)
3460 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3461 _("unsupported reloc %u"), r_type);
3464 case elfcpp::R_390_TLS_GD32: // Global-dynamic
3465 case elfcpp::R_390_TLS_GD64:
3466 if (optimized_type == tls::TLSOPT_TO_LE)
3468 if (tls_segment == NULL)
3470 gold_assert(parameters->errors()->error_count() > 0
3471 || issue_undefined_symbol_error(gsym));
3474 return value - tls_segment->memsz();
3478 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
3479 ? GOT_TYPE_TLS_OFFSET
3480 : GOT_TYPE_TLS_PAIR);
3483 gold_assert(gsym->has_got_offset(got_type));
3484 return (gsym->got_offset(got_type)
3485 + target->got_main_offset()
3490 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3491 gold_assert(object->local_has_got_offset(r_sym, got_type));
3492 return (object->local_got_offset(r_sym, got_type)
3493 + target->got_main_offset()
3497 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3498 _("unsupported reloc %u"), r_type);
3501 case elfcpp::R_390_TLS_LDCALL: // Local-dynamic marker
3502 // This is a marker relocation. If the sequence is being turned to LE,
3503 // we modify the instruction, otherwise the instruction is untouched.
3504 if (optimized_type == tls::TLSOPT_TO_LE)
3506 if (tls_segment == NULL)
3508 gold_assert(parameters->errors()->error_count() > 0
3509 || issue_undefined_symbol_error(gsym));
3512 this->tls_ld_to_le(relinfo, relnum, rela, view, view_size);
3515 else if (optimized_type == tls::TLSOPT_NONE)
3519 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3520 _("unsupported reloc %u"), r_type);
3523 case elfcpp::R_390_TLS_LDM32: // Local-dynamic module
3524 case elfcpp::R_390_TLS_LDM64:
3525 if (optimized_type == tls::TLSOPT_TO_LE)
3527 if (tls_segment == NULL)
3529 gold_assert(parameters->errors()->error_count() > 0
3530 || issue_undefined_symbol_error(gsym));
3533 // Doesn't matter what we fill it with - it's going to be unused.
3536 else if (optimized_type == tls::TLSOPT_NONE)
3538 // Relocate the field with the offset of the GOT entry for
3539 // the module index.
3540 return (target->got_mod_index_entry(NULL, NULL, NULL)
3542 + target->got_main_offset());
3544 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3545 _("unsupported reloc %u"), r_type);
3548 case elfcpp::R_390_TLS_LDO32: // Local-dynamic offset
3549 case elfcpp::R_390_TLS_LDO64:
3550 // This relocation type is used in debugging information.
3551 // In that case we need to not optimize the value. If the
3552 // section is not allocatable, then we assume we should not
3553 // optimize this reloc.
3554 if (optimized_type == tls::TLSOPT_TO_LE && is_allocatable)
3556 if (tls_segment == NULL)
3558 gold_assert(parameters->errors()->error_count() > 0
3559 || issue_undefined_symbol_error(gsym));
3562 value -= tls_segment->memsz();
3566 case elfcpp::R_390_TLS_LOAD: // Initial-exec marker
3567 // This is a marker relocation. If the sequence is being turned to LE,
3568 // we modify the instruction, otherwise the instruction is untouched.
3570 && gsym->is_undefined()
3571 && parameters->options().output_is_executable())
3573 Target_s390<size>::Relocate::tls_ie_to_le(relinfo, relnum,
3578 else if (optimized_type == tls::TLSOPT_TO_LE)
3580 if (tls_segment == NULL)
3582 gold_assert(parameters->errors()->error_count() > 0
3583 || issue_undefined_symbol_error(gsym));
3586 Target_s390<size>::Relocate::tls_ie_to_le(relinfo, relnum,
3591 else if (optimized_type == tls::TLSOPT_NONE)
3595 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3596 _("unsupported reloc type %u"),
3600 case elfcpp::R_390_TLS_GOTIE12: // Initial-exec, not optimizable
3601 case elfcpp::R_390_TLS_GOTIE20:
3602 case elfcpp::R_390_TLS_IEENT:
3603 case elfcpp::R_390_TLS_GOTIE32: // Initial-exec, optimizable
3604 case elfcpp::R_390_TLS_GOTIE64:
3605 case elfcpp::R_390_TLS_IE32:
3606 case elfcpp::R_390_TLS_IE64:
3608 && gsym->is_undefined()
3609 && parameters->options().output_is_executable()
3610 // These three cannot be optimized to LE, no matter what
3611 && r_type != elfcpp::R_390_TLS_GOTIE12
3612 && r_type != elfcpp::R_390_TLS_GOTIE20
3613 && r_type != elfcpp::R_390_TLS_IEENT)
3617 else if (optimized_type == tls::TLSOPT_TO_LE)
3619 if (tls_segment == NULL)
3621 gold_assert(parameters->errors()->error_count() > 0
3622 || issue_undefined_symbol_error(gsym));
3625 return value - tls_segment->memsz();
3627 else if (optimized_type == tls::TLSOPT_NONE)
3629 // Relocate the field with the offset of the GOT entry for
3630 // the tp-relative offset of the symbol.
3631 unsigned int got_offset;
3634 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
3635 got_offset = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
3639 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3640 gold_assert(object->local_has_got_offset(r_sym,
3641 GOT_TYPE_TLS_OFFSET));
3642 got_offset = object->local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET);
3644 got_offset += target->got_main_offset();
3645 if (r_type == elfcpp::R_390_TLS_IE32
3646 || r_type == elfcpp::R_390_TLS_IE64)
3647 return target->got_address() + got_offset + addend;
3649 return got_offset + addend;
3651 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3652 _("unsupported reloc type %u"),
3656 case elfcpp::R_390_TLS_LE32: // Local-exec
3657 case elfcpp::R_390_TLS_LE64:
3658 if (tls_segment == NULL)
3660 gold_assert(parameters->errors()->error_count() > 0
3661 || issue_undefined_symbol_error(gsym));
3664 return value - tls_segment->memsz();
3669 // Do a relocation in which we convert a TLS General-Dynamic to an
3674 Target_s390<size>::Relocate::tls_gd_to_ie(
3675 const Relocate_info<size, true>* relinfo,
3677 const elfcpp::Rela<size, true>& rela,
3678 unsigned char* view,
3679 section_size_type view_size)
3681 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
3682 if (view[0] == 0x4d)
3684 // bas, don't care about details
3685 // Change to l %r2, 0(%r2, %r12)
3692 else if (view[0] == 0xc0)
3694 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 6);
3695 // brasl %r14, __tls_get_offset@plt
3696 if (view[1] == 0xe5)
3698 // Change to l/lg %r2, 0(%r2, %r12)
3699 // There was a PLT32DBL reloc at the last 4 bytes, overwrite its result.
3724 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3725 _("unsupported op for GD to IE"));
3728 // Do a relocation in which we convert a TLS General-Dynamic to a
3733 Target_s390<size>::Relocate::tls_gd_to_le(
3734 const Relocate_info<size, true>* relinfo,
3736 const elfcpp::Rela<size, true>& rela,
3737 unsigned char* view,
3738 section_size_type view_size)
3740 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 2);
3741 if (view[0] == 0x0d)
3743 // basr, change to nop
3747 else if (view[0] == 0x4d)
3749 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
3750 // bas, don't care about details, change to nop
3757 else if (view[0] == 0xc0)
3759 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 6);
3760 // brasl %r14, __tls_get_offset@plt
3761 if (view[1] == 0xe5)
3763 // Change to nop jump. There was a PLT32DBL reloc at the last
3764 // 4 bytes, overwrite its result.
3773 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3774 _("unsupported op for GD to LE"));
3779 Target_s390<size>::Relocate::tls_ld_to_le(
3780 const Relocate_info<size, true>* relinfo,
3782 const elfcpp::Rela<size, true>& rela,
3783 unsigned char* view,
3784 section_size_type view_size)
3786 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
3788 if (view[0] == 0x0d)
3790 // basr, change to nop
3794 else if (view[0] == 0x4d)
3796 // bas, don't care about details, change to nop
3803 else if (view[0] == 0xc0)
3805 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 6);
3806 // brasl %r14, __tls_get_offset@plt
3807 if (view[1] == 0xe5)
3809 // Change to nop jump. There was a PLT32DBL reloc at the last
3810 // 4 bytes, overwrite its result.
3819 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3820 _("unsupported op for LD to LE"));
3823 // Do a relocation in which we convert a TLS Initial-Exec to a
3828 Target_s390<size>::Relocate::tls_ie_to_le(
3829 const Relocate_info<size, true>* relinfo,
3831 const elfcpp::Rela<size, true>& rela,
3832 unsigned char* view,
3833 section_size_type view_size)
3835 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
3837 if (view[0] == 0x58)
3839 // l %rX, 0(%rY) or l %rX, 0(%rY, %r12)
3840 if ((view[2] & 0x0f) != 0 || view[3] != 0)
3842 int rx = view[1] >> 4 & 0xf;
3843 int ry = view[1] & 0xf;
3844 int rz = view[2] >> 4 & 0xf;
3863 view[1] = rx << 4 | ry;
3868 else if (view[0] == 0xe3)
3870 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 6);
3871 // lg %rX, 0(%rY) or lg %rX, 0(%rY, %r12)
3872 if ((view[2] & 0x0f) != 0 ||
3877 int rx = view[1] >> 4 & 0xf;
3878 int ry = view[1] & 0xf;
3879 int rz = view[2] >> 4 & 0xf;
3896 // to sllg %rX, $rY, 0
3898 view[1] = rx << 4 | ry;
3907 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3908 _("unsupported op for IE to LE"));
3912 // Scan relocations for a section.
3916 Target_s390<size>::scan_relocs(Symbol_table* symtab,
3918 Sized_relobj_file<size, true>* object,
3919 unsigned int data_shndx,
3920 unsigned int sh_type,
3921 const unsigned char* prelocs,
3923 Output_section* output_section,
3924 bool needs_special_offset_handling,
3925 size_t local_symbol_count,
3926 const unsigned char* plocal_symbols)
3928 if (sh_type == elfcpp::SHT_REL)
3930 gold_error(_("%s: unsupported REL reloc section"),
3931 object->name().c_str());
3935 gold::scan_relocs<size, true, Target_s390<size>, elfcpp::SHT_RELA,
3936 typename Target_s390<size>::Scan>(
3945 needs_special_offset_handling,
3950 // Finalize the sections.
3954 Target_s390<size>::do_finalize_sections(
3956 const Input_objects*,
3957 Symbol_table* symtab)
3959 const Reloc_section* rel_plt = (this->plt_ == NULL
3961 : this->plt_->rela_plt());
3962 layout->add_target_dynamic_tags(false, this->got_plt_, rel_plt,
3963 this->rela_dyn_, true, size == 32);
3965 this->layout_ = layout;
3967 // Emit any relocs we saved in an attempt to avoid generating COPY
3969 if (this->copy_relocs_.any_saved_relocs())
3970 this->copy_relocs_.emit(this->rela_dyn_section(layout));
3972 // Set the size of the _GLOBAL_OFFSET_TABLE_ symbol to the size of
3973 // the .got section.
3974 Symbol* sym = this->global_offset_table_;
3977 uint64_t data_size = this->got_->current_data_size();
3978 symtab->get_sized_symbol<size>(sym)->set_symsize(data_size);
3981 if (parameters->doing_static_link()
3982 && (this->plt_ == NULL || !this->plt_->has_irelative_section()))
3984 // If linking statically, make sure that the __rela_iplt symbols
3985 // were defined if necessary, even if we didn't create a PLT.
3986 static const Define_symbol_in_segment syms[] =
3989 "__rela_iplt_start", // name
3990 elfcpp::PT_LOAD, // segment_type
3991 elfcpp::PF_W, // segment_flags_set
3992 elfcpp::PF(0), // segment_flags_clear
3995 elfcpp::STT_NOTYPE, // type
3996 elfcpp::STB_GLOBAL, // binding
3997 elfcpp::STV_HIDDEN, // visibility
3999 Symbol::SEGMENT_START, // offset_from_base
4003 "__rela_iplt_end", // name
4004 elfcpp::PT_LOAD, // segment_type
4005 elfcpp::PF_W, // segment_flags_set
4006 elfcpp::PF(0), // segment_flags_clear
4009 elfcpp::STT_NOTYPE, // type
4010 elfcpp::STB_GLOBAL, // binding
4011 elfcpp::STV_HIDDEN, // visibility
4013 Symbol::SEGMENT_START, // offset_from_base
4018 symtab->define_symbols(layout, 2, syms,
4019 layout->script_options()->saw_sections_clause());
4023 // Return the size of a relocation while scanning during a relocatable
4028 Target_s390<size>::Relocatable_size_for_reloc::get_size_for_reloc(
4029 unsigned int r_type,
4034 case elfcpp::R_390_NONE:
4035 case elfcpp::R_390_GNU_VTINHERIT:
4036 case elfcpp::R_390_GNU_VTENTRY:
4037 case elfcpp::R_390_TLS_GD32: // Global-dynamic
4038 case elfcpp::R_390_TLS_GD64:
4039 case elfcpp::R_390_TLS_GDCALL:
4040 case elfcpp::R_390_TLS_LDM32: // Local-dynamic
4041 case elfcpp::R_390_TLS_LDM64:
4042 case elfcpp::R_390_TLS_LDO32:
4043 case elfcpp::R_390_TLS_LDO64:
4044 case elfcpp::R_390_TLS_LDCALL:
4045 case elfcpp::R_390_TLS_IE32: // Initial-exec
4046 case elfcpp::R_390_TLS_IE64:
4047 case elfcpp::R_390_TLS_IEENT:
4048 case elfcpp::R_390_TLS_GOTIE12:
4049 case elfcpp::R_390_TLS_GOTIE20:
4050 case elfcpp::R_390_TLS_GOTIE32:
4051 case elfcpp::R_390_TLS_GOTIE64:
4052 case elfcpp::R_390_TLS_LOAD:
4053 case elfcpp::R_390_TLS_LE32: // Local-exec
4054 case elfcpp::R_390_TLS_LE64:
4057 case elfcpp::R_390_64:
4058 case elfcpp::R_390_PC64:
4059 case elfcpp::R_390_GOT64:
4060 case elfcpp::R_390_PLT64:
4061 case elfcpp::R_390_GOTOFF64:
4062 case elfcpp::R_390_GOTPLT64:
4063 case elfcpp::R_390_PLTOFF64:
4066 case elfcpp::R_390_32:
4067 case elfcpp::R_390_PC32:
4068 case elfcpp::R_390_GOT32:
4069 case elfcpp::R_390_PLT32:
4070 case elfcpp::R_390_GOTOFF32:
4071 case elfcpp::R_390_GOTPC:
4072 case elfcpp::R_390_PC32DBL:
4073 case elfcpp::R_390_PLT32DBL:
4074 case elfcpp::R_390_GOTPCDBL:
4075 case elfcpp::R_390_GOTENT:
4076 case elfcpp::R_390_GOTPLT32:
4077 case elfcpp::R_390_GOTPLTENT:
4078 case elfcpp::R_390_PLTOFF32:
4079 case elfcpp::R_390_20:
4080 case elfcpp::R_390_GOT20:
4081 case elfcpp::R_390_GOTPLT20:
4084 case elfcpp::R_390_PC24DBL:
4085 case elfcpp::R_390_PLT24DBL:
4088 case elfcpp::R_390_12:
4089 case elfcpp::R_390_GOT12:
4090 case elfcpp::R_390_GOTPLT12:
4091 case elfcpp::R_390_PC12DBL:
4092 case elfcpp::R_390_PLT12DBL:
4093 case elfcpp::R_390_16:
4094 case elfcpp::R_390_GOT16:
4095 case elfcpp::R_390_PC16:
4096 case elfcpp::R_390_PC16DBL:
4097 case elfcpp::R_390_PLT16DBL:
4098 case elfcpp::R_390_GOTOFF16:
4099 case elfcpp::R_390_GOTPLT16:
4100 case elfcpp::R_390_PLTOFF16:
4103 case elfcpp::R_390_8:
4106 // These are relocations which should only be seen by the
4107 // dynamic linker, and should never be seen here.
4108 case elfcpp::R_390_COPY:
4109 case elfcpp::R_390_GLOB_DAT:
4110 case elfcpp::R_390_JMP_SLOT:
4111 case elfcpp::R_390_RELATIVE:
4112 case elfcpp::R_390_IRELATIVE:
4113 case elfcpp::R_390_TLS_DTPMOD:
4114 case elfcpp::R_390_TLS_DTPOFF:
4115 case elfcpp::R_390_TLS_TPOFF:
4116 object->error(_("unexpected reloc %u in object file"), r_type);
4120 object->error(_("unsupported reloc %u in object file"), r_type);
4125 // Scan the relocs during a relocatable link.
4129 Target_s390<size>::scan_relocatable_relocs(
4130 Symbol_table* symtab,
4132 Sized_relobj_file<size, true>* object,
4133 unsigned int data_shndx,
4134 unsigned int sh_type,
4135 const unsigned char* prelocs,
4137 Output_section* output_section,
4138 bool needs_special_offset_handling,
4139 size_t local_symbol_count,
4140 const unsigned char* plocal_symbols,
4141 Relocatable_relocs* rr)
4143 gold_assert(sh_type == elfcpp::SHT_RELA);
4145 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
4146 Relocatable_size_for_reloc> Scan_relocatable_relocs;
4148 gold::scan_relocatable_relocs<size, true, elfcpp::SHT_RELA,
4149 Scan_relocatable_relocs>(
4157 needs_special_offset_handling,
4163 // Relocate a section during a relocatable link.
4167 Target_s390<size>::relocate_relocs(
4168 const Relocate_info<size, true>* relinfo,
4169 unsigned int sh_type,
4170 const unsigned char* prelocs,
4172 Output_section* output_section,
4173 typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
4174 const Relocatable_relocs* rr,
4175 unsigned char* view,
4176 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
4177 section_size_type view_size,
4178 unsigned char* reloc_view,
4179 section_size_type reloc_view_size)
4181 gold_assert(sh_type == elfcpp::SHT_RELA);
4183 gold::relocate_relocs<size, true, elfcpp::SHT_RELA>(
4188 offset_in_output_section,
4197 // Return the offset to use for the GOT_INDX'th got entry which is
4198 // for a local tls symbol specified by OBJECT, SYMNDX.
4201 Target_s390<size>::do_tls_offset_for_local(
4206 // The only way we can get called is when IEENT/GOTIE12/GOTIE20
4207 // couldn't be optimised to LE.
4208 Output_segment* tls_segment = layout_->tls_segment();
4209 return -tls_segment->memsz();
4212 // Return the offset to use for the GOT_INDX'th got entry which is
4213 // for global tls symbol GSYM.
4216 Target_s390<size>::do_tls_offset_for_global(
4220 Output_segment* tls_segment = layout_->tls_segment();
4221 return -tls_segment->memsz();
4224 // Return the value to use for a dynamic which requires special
4225 // treatment. This is how we support equality comparisons of function
4226 // pointers across shared library boundaries, as described in the
4227 // processor specific ABI supplement.
4231 Target_s390<size>::do_dynsym_value(const Symbol* gsym) const
4233 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
4234 return this->plt_address_for_global(gsym);
4237 // Return a string used to fill a code section with nops to take up
4238 // the specified length.
4242 Target_s390<size>::do_code_fill(section_size_type length) const
4245 gold_warning(_("S/390 code fill of odd length requested"));
4246 return std::string(length, static_cast<char>(0x07));
4249 // Relocate section data.
4253 Target_s390<size>::relocate_section(
4254 const Relocate_info<size, true>* relinfo,
4255 unsigned int sh_type,
4256 const unsigned char* prelocs,
4258 Output_section* output_section,
4259 bool needs_special_offset_handling,
4260 unsigned char* view,
4261 typename elfcpp::Elf_types<size>::Elf_Addr address,
4262 section_size_type view_size,
4263 const Reloc_symbol_changes* reloc_symbol_changes)
4265 gold_assert(sh_type == elfcpp::SHT_RELA);
4267 gold::relocate_section<size, true, Target_s390<size>, elfcpp::SHT_RELA,
4268 typename Target_s390<size>::Relocate,
4269 gold::Default_comdat_behavior>(
4275 needs_special_offset_handling,
4279 reloc_symbol_changes);
4282 // Apply an incremental relocation. Incremental relocations always refer
4283 // to global symbols.
4287 Target_s390<size>::apply_relocation(
4288 const Relocate_info<size, true>* relinfo,
4289 typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
4290 unsigned int r_type,
4291 typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
4293 unsigned char* view,
4294 typename elfcpp::Elf_types<size>::Elf_Addr address,
4295 section_size_type view_size)
4297 gold::apply_relocation<size, true, Target_s390<size>,
4298 typename Target_s390<size>::Relocate>(
4310 // The selector for s390 object files.
4313 class Target_selector_s390 : public Target_selector
4316 Target_selector_s390()
4317 : Target_selector(elfcpp::EM_S390, size, true,
4318 (size == 64 ? "elf64-s390" : "elf32-s390"),
4319 (size == 64 ? "elf64_s390" : "elf32_s390"))
4323 do_instantiate_target()
4324 { return new Target_s390<size>(); }
4327 Target_selector_s390<32> target_selector_s390;
4328 Target_selector_s390<64> target_selector_s390x;
4330 } // End anonymous namespace.