1 // s390.cc -- s390 target support for gold.
3 // Copyright (C) 2015-2016 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
,
365 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
366 section_size_type view_size
,
367 unsigned char* reloc_view
,
368 section_size_type reloc_view_size
);
370 // Return whether SYM is defined by the ABI.
372 do_is_defined_by_abi(const Symbol
* sym
) const
373 { return strcmp(sym
->name(), "__tls_get_offset") == 0; }
375 // Return the PLT address to use for a global symbol.
377 do_plt_address_for_global(const Symbol
* gsym
) const
378 { return this->plt_section()->address_for_global(gsym
); }
381 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
382 { return this->plt_section()->address_for_local(relobj
, symndx
); }
384 // Return the offset to use for the GOT_INDX'th got entry which is
385 // for a local tls symbol specified by OBJECT, SYMNDX.
387 do_tls_offset_for_local(const Relobj
* object
,
389 unsigned int got_indx
) const;
391 // Return the offset to use for the GOT_INDX'th got entry which is
392 // for global tls symbol GSYM.
394 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
396 // This function should be defined in targets that can use relocation
397 // types to determine (implemented in local_reloc_may_be_function_pointer
398 // and global_reloc_may_be_function_pointer)
399 // if a function's pointer is taken. ICF uses this in safe mode to only
400 // fold those functions whose pointer is defintely not taken.
402 do_can_check_for_function_pointers() const
405 // Return the size of the GOT section.
409 gold_assert(this->got_
!= NULL
);
410 return this->got_
->data_size();
413 // Return the number of entries in the GOT.
415 got_entry_count() const
417 if (this->got_
== NULL
)
419 return this->got_size() / (size
/ 8);
422 // Return the number of entries in the PLT.
424 plt_entry_count() const;
426 // Return the offset of the first non-reserved PLT entry.
428 first_plt_entry_offset() const;
430 // Return the size of each PLT entry.
432 plt_entry_size() const;
434 // Create the GOT section for an incremental update.
435 Output_data_got_base
*
436 init_got_plt_for_update(Symbol_table
* symtab
,
438 unsigned int got_count
,
439 unsigned int plt_count
);
441 // Reserve a GOT entry for a local symbol, and regenerate any
442 // necessary dynamic relocations.
444 reserve_local_got_entry(unsigned int got_index
,
445 Sized_relobj
<size
, true>* obj
,
447 unsigned int got_type
);
449 // Reserve a GOT entry for a global symbol, and regenerate any
450 // necessary dynamic relocations.
452 reserve_global_got_entry(unsigned int got_index
, Symbol
* gsym
,
453 unsigned int got_type
);
455 // Register an existing PLT entry for a global symbol.
457 register_global_plt_entry(Symbol_table
*, Layout
*, unsigned int plt_index
,
460 // Force a COPY relocation for a given symbol.
462 emit_copy_reloc(Symbol_table
*, Symbol
*, Output_section
*, off_t
);
464 // Apply an incremental relocation.
466 apply_relocation(const Relocate_info
<size
, true>* relinfo
,
467 typename
elfcpp::Elf_types
<size
>::Elf_Addr r_offset
,
469 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
,
472 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
473 section_size_type view_size
);
477 // The class which scans relocations.
482 : issued_non_pic_error_(false)
486 get_reference_flags(unsigned int r_type
);
489 local(Symbol_table
* symtab
, Layout
* layout
, Target_s390
* target
,
490 Sized_relobj_file
<size
, true>* object
,
491 unsigned int data_shndx
,
492 Output_section
* output_section
,
493 const elfcpp::Rela
<size
, true>& reloc
, unsigned int r_type
,
494 const elfcpp::Sym
<size
, true>& lsym
,
498 global(Symbol_table
* symtab
, Layout
* layout
, Target_s390
* target
,
499 Sized_relobj_file
<size
, true>* object
,
500 unsigned int data_shndx
,
501 Output_section
* output_section
,
502 const elfcpp::Rela
<size
, true>& reloc
, unsigned int r_type
,
506 local_reloc_may_be_function_pointer(Symbol_table
* symtab
, Layout
* layout
,
508 Sized_relobj_file
<size
, true>* object
,
509 unsigned int data_shndx
,
510 Output_section
* output_section
,
511 const elfcpp::Rela
<size
, true>& reloc
,
513 const elfcpp::Sym
<size
, true>& lsym
);
516 global_reloc_may_be_function_pointer(Symbol_table
* symtab
, Layout
* layout
,
518 Sized_relobj_file
<size
, true>* object
,
519 unsigned int data_shndx
,
520 Output_section
* output_section
,
521 const elfcpp::Rela
<size
, true>& reloc
,
527 unsupported_reloc_local(Sized_relobj_file
<size
, true>*,
528 unsigned int r_type
);
531 unsupported_reloc_global(Sized_relobj_file
<size
, true>*,
532 unsigned int r_type
, Symbol
*);
535 check_non_pic(Relobj
*, unsigned int r_type
);
538 possible_function_pointer_reloc(unsigned int r_type
);
541 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, true>*,
542 unsigned int r_type
);
544 // Whether we have issued an error about a non-PIC compilation.
545 bool issued_non_pic_error_
;
548 // The class which implements relocation.
552 // Do a relocation. Return false if the caller should not issue
553 // any warnings about this relocation.
555 relocate(const Relocate_info
<size
, true>*, unsigned int,
556 Target_s390
*, Output_section
*, size_t, const unsigned char*,
557 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
558 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
562 // Do a TLS relocation.
563 inline typename
elfcpp::Elf_types
<size
>::Elf_Addr
564 relocate_tls(const Relocate_info
<size
, true>*, Target_s390
*,
565 size_t relnum
, const elfcpp::Rela
<size
, true>&,
566 unsigned int r_type
, const Sized_symbol
<size
>*,
567 const Symbol_value
<size
>*,
568 unsigned char*, section_size_type
);
570 // Do a TLS General-Dynamic to Initial-Exec transition.
572 tls_gd_to_ie(const Relocate_info
<size
, true>*, size_t relnum
,
573 const elfcpp::Rela
<size
, true>&,
575 section_size_type view_size
);
577 // Do a TLS General-Dynamic to Local-Exec transition.
579 tls_gd_to_le(const Relocate_info
<size
, true>*, size_t relnum
,
580 const elfcpp::Rela
<size
, true>&,
582 section_size_type view_size
);
584 // Do a TLS Local-Dynamic to Local-Exec transition.
586 tls_ld_to_le(const Relocate_info
<size
, true>*, size_t relnum
,
587 const elfcpp::Rela
<size
, true>&,
589 section_size_type view_size
);
591 // Do a TLS Initial-Exec to Local-Exec transition.
593 tls_ie_to_le(const Relocate_info
<size
, true>*, size_t relnum
,
594 const elfcpp::Rela
<size
, true>&,
596 section_size_type view_size
);
599 // A class which returns the size required for a relocation type,
600 // used while scanning relocs during a relocatable link.
601 class Relocatable_size_for_reloc
605 get_size_for_reloc(unsigned int, Relobj
*);
608 // Adjust TLS relocation type based on the options and whether this
609 // is a local symbol.
610 static tls::Tls_optimization
611 optimize_tls_reloc(bool is_final
, int r_type
);
613 // Get the GOT section.
614 const Output_data_got
<size
, true>*
617 gold_assert(this->got_
!= NULL
);
621 // Get the GOT section, creating it if necessary.
622 Output_data_got
<size
, true>*
623 got_section(Symbol_table
*, Layout
*);
625 typename
elfcpp::Elf_types
<size
>::Elf_Addr
628 gold_assert(this->got_
!= NULL
);
629 return this->got_plt_
->address();
632 typename
elfcpp::Elf_types
<size
>::Elf_Addr
633 got_main_offset() const
635 gold_assert(this->got_
!= NULL
);
636 return this->got_
->address() - this->got_address();
639 // Create the PLT section.
641 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
643 // Create a PLT entry for a global symbol.
645 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
647 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
649 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
650 Sized_relobj_file
<size
, true>* relobj
,
651 unsigned int local_sym_index
);
653 // Create a GOT entry for the TLS module index.
655 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
656 Sized_relobj_file
<size
, true>* object
);
658 // Get the PLT section.
659 Output_data_plt_s390
<size
>*
662 gold_assert(this->plt_
!= NULL
);
666 // Get the dynamic reloc section, creating it if necessary.
668 rela_dyn_section(Layout
*);
670 // Get the section to use for IRELATIVE relocations.
672 rela_irelative_section(Layout
*);
674 // Add a potential copy relocation.
676 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
677 Sized_relobj_file
<size
, true>* object
,
678 unsigned int shndx
, Output_section
* output_section
,
679 Symbol
* sym
, const elfcpp::Rela
<size
, true>& reloc
)
681 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
682 this->copy_relocs_
.copy_reloc(symtab
, layout
,
683 symtab
->get_sized_symbol
<size
>(sym
),
684 object
, shndx
, output_section
,
685 r_type
, reloc
.get_r_offset(),
686 reloc
.get_r_addend(),
687 this->rela_dyn_section(layout
));
690 // Information about this specific target which we pass to the
691 // general Target structure.
692 static Target::Target_info s390_info
;
694 // The types of GOT entries needed for this platform.
695 // These values are exposed to the ABI in an incremental link.
696 // Do not renumber existing values without changing the version
697 // number of the .gnu_incremental_inputs section.
700 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
701 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
702 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
706 Output_data_got
<size
, true>* got_
;
708 Output_data_plt_s390
<size
>* plt_
;
709 // The GOT PLT section.
710 Output_data_got_plt_s390
<size
>* got_plt_
;
711 // The GOT section for IRELATIVE relocations.
712 Output_data_space
* got_irelative_
;
713 // The _GLOBAL_OFFSET_TABLE_ symbol.
714 Symbol
* global_offset_table_
;
715 // The dynamic reloc section.
716 Reloc_section
* rela_dyn_
;
717 // The section to use for IRELATIVE relocs.
718 Reloc_section
* rela_irelative_
;
719 // Relocs saved to avoid a COPY reloc.
720 Copy_relocs
<elfcpp::SHT_RELA
, size
, true> copy_relocs_
;
721 // Offset of the GOT entry for the TLS module index.
722 unsigned int got_mod_index_offset_
;
723 // True if the _TLS_MODULE_BASE_ symbol has been defined.
724 bool tls_base_symbol_defined_
;
725 // For use in do_tls_offset_for_*
730 Target::Target_info Target_s390
<32>::s390_info
=
733 true, // is_big_endian
734 elfcpp::EM_S390
, // machine_code
735 false, // has_make_symbol
736 false, // has_resolve
737 true, // has_code_fill
738 true, // is_default_stack_executable
739 true, // can_icf_inline_merge_sections
741 "/lib/ld.so.1", // dynamic_linker
742 0x00400000, // default_text_segment_address
743 4 * 1024, // abi_pagesize (overridable by -z max-page-size)
744 4 * 1024, // common_pagesize (overridable by -z common-page-size)
745 false, // isolate_execinstr
747 elfcpp::SHN_UNDEF
, // small_common_shndx
748 elfcpp::SHN_UNDEF
, // large_common_shndx
749 0, // small_common_section_flags
750 0, // large_common_section_flags
751 NULL
, // attributes_section
752 NULL
, // attributes_vendor
753 "_start", // entry_symbol_name
754 32, // hash_entry_size
758 Target::Target_info Target_s390
<64>::s390_info
=
761 true, // is_big_endian
762 elfcpp::EM_S390
, // machine_code
763 false, // has_make_symbol
764 false, // has_resolve
765 true, // has_code_fill
766 true, // is_default_stack_executable
767 true, // can_icf_inline_merge_sections
769 "/lib/ld64.so.1", // dynamic_linker
770 0x80000000ll
, // default_text_segment_address
771 4 * 1024, // abi_pagesize (overridable by -z max-page-size)
772 4 * 1024, // common_pagesize (overridable by -z common-page-size)
773 false, // isolate_execinstr
775 elfcpp::SHN_UNDEF
, // small_common_shndx
776 elfcpp::SHN_UNDEF
, // large_common_shndx
777 0, // small_common_section_flags
778 0, // large_common_section_flags
779 NULL
, // attributes_section
780 NULL
, // attributes_vendor
781 "_start", // entry_symbol_name
782 64, // hash_entry_size
786 class S390_relocate_functions
806 typedef S390_relocate_functions
<size
> This
;
807 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
809 template<int valsize
>
811 has_overflow_signed(Address value
)
813 // limit = 1 << (valsize - 1) without shift count exceeding size of type
814 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
815 limit
<<= ((valsize
- 1) >> 1);
816 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
817 return value
+ limit
> (limit
<< 1) - 1;
820 template<int valsize
>
822 has_overflow_unsigned(Address value
)
824 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
825 limit
<<= ((valsize
- 1) >> 1);
826 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
827 return value
> (limit
<< 1) - 1;
830 template<int fieldsize
>
832 rela(unsigned char* view
, Address mask
, Address value
)
834 typedef typename
elfcpp::Swap
<fieldsize
, true>::Valtype Valtype
;
835 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
836 Valtype val
= elfcpp::Swap
<fieldsize
, true>::readval(view
);
839 elfcpp::Swap
<fieldsize
, true>::writeval(wv
, val
| value
);
843 // R_390_12, R_390_GOT12, R_390_GOTPLT12, R_390_GOTIE12
845 rela12(unsigned char* view
, Address value
)
847 if (This::template has_overflow_unsigned
<12>(value
))
848 return STATUS_OVERFLOW
;
849 This::template rela
<16>(view
, 0x0fff, value
);
853 // R_390_16, R_390_GOT16, R_390_GOTPLT16, R_390_GOTOFF16, R_390_PLTOFF16
855 rela16(unsigned char* view
, Address value
)
857 if (This::template has_overflow_signed
<16>(value
))
858 return STATUS_OVERFLOW
;
859 This::template rela
<16>(view
, 0xffff, value
);
863 // R_390_20, R_390_GOT20, R_390_GOTPLT20, R_390_GOTIE20
865 rela20(unsigned char* view
, Address value
)
867 if (This::template has_overflow_signed
<20>(value
))
868 return STATUS_OVERFLOW
;
869 This::template rela
<16>(view
, 0x0fff, value
);
870 This::template rela
<16>(view
+ 2, 0xff00, value
>> (12 - 8));
874 // R_390_PC12DBL, R_390_PLT12DBL
876 pcrela12dbl(unsigned char* view
, Address value
, Address address
)
879 if ((value
& 1) != 0)
880 return STATUS_OVERFLOW
;
881 if (This::template has_overflow_signed
<13>(value
))
882 return STATUS_OVERFLOW
;
884 This::template rela
<16>(view
, 0x0fff, value
);
888 // R_390_PC16DBL, R_390_PLT16DBL
890 pcrela16dbl(unsigned char* view
, Address value
, Address address
)
893 if ((value
& 1) != 0)
894 return STATUS_OVERFLOW
;
895 if (This::template has_overflow_signed
<17>(value
))
896 return STATUS_OVERFLOW
;
898 This::template rela
<16>(view
, 0xffff, value
);
902 // R_390_PC24DBL, R_390_PLT24DBL
904 pcrela24dbl(unsigned char* view
, Address value
, Address address
)
907 if ((value
& 1) != 0)
908 return STATUS_OVERFLOW
;
909 if (This::template has_overflow_signed
<25>(value
))
910 return STATUS_OVERFLOW
;
912 // Swap doesn't take 24-bit fields well...
913 This::template rela
<8>(view
, 0xff, value
>> 16);
914 This::template rela
<16>(view
+ 1, 0xffff, value
);
918 // R_390_PC32DBL, R_390_PLT32DBL, R_390_GOTPCDBL, R_390_GOTENT, R_390_GOTPLTENT
920 pcrela32dbl(unsigned char* view
, Address value
, Address address
)
922 Address reloc
= value
- address
;
923 if ((reloc
& 1) != 0)
925 gold_warning(_("R_390_PC32DBL target misaligned at %llx"), (long long)address
);
926 // Wait for a fix for https://sourceware.org/bugzilla/show_bug.cgi?id=18960
927 // return STATUS_OVERFLOW;
929 if (This::template has_overflow_signed
<33>(reloc
))
930 return STATUS_OVERFLOW
;
932 if (value
< address
&& size
== 32)
934 This::template rela
<32>(view
, 0xffffffff, reloc
);
940 // Initialize the PLT section.
944 Output_data_plt_s390
<size
>::init(Layout
* layout
)
946 this->rel_
= new Reloc_section(false);
947 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
948 elfcpp::SHF_ALLOC
, this->rel_
,
949 ORDER_DYNAMIC_PLT_RELOCS
, false);
954 Output_data_plt_s390
<size
>::do_adjust_output_section(Output_section
* os
)
956 os
->set_entsize(plt_entry_size
);
959 // Add an entry to the PLT.
963 Output_data_plt_s390
<size
>::add_entry(Symbol_table
* symtab
, Layout
* layout
,
966 gold_assert(!gsym
->has_plt_offset());
968 unsigned int plt_index
;
970 section_offset_type got_offset
;
972 unsigned int* pcount
;
974 unsigned int reserved
;
975 Output_section_data_build
* got
;
976 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
977 && gsym
->can_use_relative_reloc(false))
979 pcount
= &this->irelative_count_
;
982 got
= this->got_irelative_
;
986 pcount
= &this->count_
;
989 got
= this->got_plt_
;
992 if (!this->is_data_size_valid())
994 // Note that when setting the PLT offset for a non-IRELATIVE
995 // entry we skip the initial reserved PLT entry.
996 plt_index
= *pcount
+ offset
;
997 plt_offset
= plt_index
* plt_entry_size
;
1001 got_offset
= (plt_index
- offset
+ reserved
) * size
/ 8;
1002 gold_assert(got_offset
== got
->current_data_size());
1004 // Every PLT entry needs a GOT entry which points back to the PLT
1005 // entry (this will be changed by the dynamic linker, normally
1006 // lazily when the function is called).
1007 got
->set_current_data_size(got_offset
+ size
/ 8);
1011 // FIXME: This is probably not correct for IRELATIVE relocs.
1013 // For incremental updates, find an available slot.
1014 plt_offset
= this->free_list_
.allocate(plt_entry_size
,
1016 if (plt_offset
== -1)
1017 gold_fallback(_("out of patch space (PLT);"
1018 " relink with --incremental-full"));
1020 // The GOT and PLT entries have a 1-1 correspondance, so the GOT offset
1021 // can be calculated from the PLT index, adjusting for the three
1022 // reserved entries at the beginning of the GOT.
1023 plt_index
= plt_offset
/ plt_entry_size
- 1;
1024 got_offset
= (plt_index
- offset
+ reserved
) * size
/ 8;
1027 gsym
->set_plt_offset(plt_offset
);
1029 // Every PLT entry needs a reloc.
1030 this->add_relocation(symtab
, layout
, gsym
, got_offset
);
1032 // Note that we don't need to save the symbol. The contents of the
1033 // PLT are independent of which symbols are used. The symbols only
1034 // appear in the relocations.
1037 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol. Return
1042 Output_data_plt_s390
<size
>::add_local_ifunc_entry(
1043 Symbol_table
* symtab
,
1045 Sized_relobj_file
<size
, true>* relobj
,
1046 unsigned int local_sym_index
)
1048 unsigned int plt_offset
= this->irelative_count_
* plt_entry_size
;
1049 ++this->irelative_count_
;
1051 section_offset_type got_offset
= this->got_irelative_
->current_data_size();
1053 // Every PLT entry needs a GOT entry which points back to the PLT
1055 this->got_irelative_
->set_current_data_size(got_offset
+ size
/ 8);
1057 // Every PLT entry needs a reloc.
1058 Reloc_section
* rela
= this->rela_irelative(symtab
, layout
);
1059 rela
->add_symbolless_local_addend(relobj
, local_sym_index
,
1060 elfcpp::R_390_IRELATIVE
,
1061 this->got_irelative_
, got_offset
, 0);
1066 // Add the relocation for a PLT entry.
1070 Output_data_plt_s390
<size
>::add_relocation(Symbol_table
* symtab
,
1073 unsigned int got_offset
)
1075 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1076 && gsym
->can_use_relative_reloc(false))
1078 Reloc_section
* rela
= this->rela_irelative(symtab
, layout
);
1079 rela
->add_symbolless_global_addend(gsym
, elfcpp::R_390_IRELATIVE
,
1080 this->got_irelative_
, got_offset
, 0);
1084 gsym
->set_needs_dynsym_entry();
1085 this->rel_
->add_global(gsym
, elfcpp::R_390_JMP_SLOT
, this->got_plt_
,
1090 // Return where the IRELATIVE relocations should go in the PLT. These
1091 // follow the JUMP_SLOT and the TLSDESC relocations.
1094 typename Output_data_plt_s390
<size
>::Reloc_section
*
1095 Output_data_plt_s390
<size
>::rela_irelative(Symbol_table
* symtab
,
1098 if (this->irelative_rel_
== NULL
)
1100 this->irelative_rel_
= new Reloc_section(false);
1101 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1102 elfcpp::SHF_ALLOC
, this->irelative_rel_
,
1103 ORDER_DYNAMIC_PLT_RELOCS
, false);
1104 gold_assert(this->irelative_rel_
->output_section()
1105 == this->rel_
->output_section());
1107 if (parameters
->doing_static_link())
1109 // A statically linked executable will only have a .rela.plt
1110 // section to hold R_390_IRELATIVE relocs for
1111 // STT_GNU_IFUNC symbols. The library will use these
1112 // symbols to locate the IRELATIVE relocs at program startup
1114 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1115 Symbol_table::PREDEFINED
,
1116 this->irelative_rel_
, 0, 0,
1117 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1118 elfcpp::STV_HIDDEN
, 0, false, true);
1119 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1120 Symbol_table::PREDEFINED
,
1121 this->irelative_rel_
, 0, 0,
1122 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1123 elfcpp::STV_HIDDEN
, 0, true, true);
1126 return this->irelative_rel_
;
1129 // Return the PLT address to use for a global symbol.
1133 Output_data_plt_s390
<size
>::address_for_global(const Symbol
* gsym
)
1135 uint64_t offset
= 0;
1136 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1137 && gsym
->can_use_relative_reloc(false))
1138 offset
= (this->count_
+ 1) * plt_entry_size
;
1139 return this->address() + offset
+ gsym
->plt_offset();
1142 // Return the PLT address to use for a local symbol. These are always
1143 // IRELATIVE relocs.
1147 Output_data_plt_s390
<size
>::address_for_local(const Relobj
* object
,
1150 return (this->address()
1151 + (this->count_
+ 1) * plt_entry_size
1152 + object
->local_plt_offset(r_sym
));
1155 // Set the final size.
1158 Output_data_plt_s390
<size
>::set_final_data_size()
1160 unsigned int count
= this->count_
+ this->irelative_count_
;
1161 this->set_data_size((count
+ 1) * plt_entry_size
);
1166 Output_data_plt_s390
<size
>::first_plt_entry_32_abs
[plt_entry_size
] =
1168 0x50, 0x10, 0xf0, 0x1c, // st %r1, 28(%r15)
1169 0x0d, 0x10, // basr %r1, %r0
1170 0x58, 0x10, 0x10, 0x12, // l %r1, 18(%r1)
1171 0xd2, 0x03, 0xf0, 0x18, 0x10, 0x04, // mvc 24(4,%r15), 4(%r1)
1172 0x58, 0x10, 0x10, 0x08, // l %r1, 8(%r1)
1173 0x07, 0xf1, // br %r1
1174 0x00, 0x00, // padding
1175 0x00, 0x00, 0x00, 0x00, // _GLOBAL_OFFSET_TABLE_ (to fill)
1176 0x00, 0x00, 0x00, 0x00, // padding
1181 Output_data_plt_s390
<size
>::first_plt_entry_32_pic
[plt_entry_size
] =
1183 0x50, 0x10, 0xf0, 0x1c, // st %r1, 28(%r15)
1184 0x58, 0x10, 0xc0, 0x04, // l %r1, 4(%r12)
1185 0x50, 0x10, 0xf0, 0x18, // st %r1, 24(%r15)
1186 0x58, 0x10, 0xc0, 0x08, // l %r1, 8(%r12)
1187 0x07, 0xf1, // br %r1
1188 0x00, 0x00, // padding
1189 0x00, 0x00, 0x00, 0x00, // padding
1190 0x00, 0x00, 0x00, 0x00, // padding
1191 0x00, 0x00, 0x00, 0x00, // padding
1196 Output_data_plt_s390
<size
>::first_plt_entry_64
[plt_entry_size
] =
1198 0xe3, 0x10, 0xf0, 0x38, 0x00, 0x24, // stg %r1, 56(%r15)
1199 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, // larl %r1, _GLOBAL_OFFSET_TABLE_ (to fill)
1200 0xd2, 0x07, 0xf0, 0x30, 0x10, 0x08, // mvc 48(8,%r15), 8(%r1)
1201 0xe3, 0x10, 0x10, 0x10, 0x00, 0x04, // lg %r1, 16(%r1)
1202 0x07, 0xf1, // br %r1
1210 Output_data_plt_s390
<size
>::fill_first_plt_entry(
1212 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
1213 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
)
1217 memcpy(pov
, first_plt_entry_64
, plt_entry_size
);
1218 S390_relocate_functions
<size
>::pcrela32dbl(pov
+ 8, got_address
, (plt_address
+ 6));
1220 else if (!parameters
->options().output_is_position_independent())
1222 memcpy(pov
, first_plt_entry_32_abs
, plt_entry_size
);
1223 elfcpp::Swap
<32, true>::writeval(pov
+ 24, got_address
);
1227 memcpy(pov
, first_plt_entry_32_pic
, plt_entry_size
);
1233 Output_data_plt_s390
<size
>::plt_entry_32_abs
[plt_entry_size
] =
1236 0x0d, 0x10, // basr %r1, %r0
1237 0x58, 0x10, 0x10, 0x16, // l %r1, 22(%r1)
1238 0x58, 0x10, 0x10, 0x00, // l %r1, 0(%r1)
1239 0x07, 0xf1, // br %r1
1241 0x0d, 0x10, // basr %r1, %r0
1242 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1243 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1244 0x00, 0x00, // padding
1245 0x00, 0x00, 0x00, 0x00, // _GLOBAL_OFFSET_TABLE_+sym@gotplt (to fill)
1246 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1251 Output_data_plt_s390
<size
>::plt_entry_32_pic12
[plt_entry_size
] =
1254 0x58, 0x10, 0xc0, 0x00, // l %r1, sym@gotplt(%r12) (to fill)
1255 0x07, 0xf1, // br %r1
1256 0x00, 0x00, // padding
1257 0x00, 0x00, 0x00, 0x00, // padding
1259 0x0d, 0x10, // basr %r1, %r0
1260 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1261 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1262 0x00, 0x00, // padding
1263 0x00, 0x00, 0x00, 0x00, // padding
1264 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1269 Output_data_plt_s390
<size
>::plt_entry_32_pic16
[plt_entry_size
] =
1272 0xa7, 0x18, 0x00, 0x00, // lhi %r1, sym@gotplt (to fill)
1273 0x58, 0x11, 0xc0, 0x00, // l %r1, 0(%r1, %r12)
1274 0x07, 0xf1, // br %r1
1275 0x00, 0x00, // padding
1277 0x0d, 0x10, // basr %r1, %r0
1278 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1279 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1280 0x00, 0x00, // padding
1281 0x00, 0x00, 0x00, 0x00, // padding
1282 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1287 Output_data_plt_s390
<size
>::plt_entry_32_pic
[plt_entry_size
] =
1290 0x0d, 0x10, // basr %r1, %r0
1291 0x58, 0x10, 0x10, 0x16, // l %r1, 22(%r1)
1292 0x58, 0x11, 0xc0, 0x00, // l %r1, 0(%r1, %r12)
1293 0x07, 0xf1, // br %r1
1295 0x0d, 0x10, // basr %r1, %r0
1296 0x58, 0x10, 0x10, 0x0e, // l %r1, 14(%r1)
1297 0xa7, 0xf4, 0x00, 0x00, // j first_plt_entry (to fill)
1298 0x00, 0x00, // padding
1299 0x00, 0x00, 0x00, 0x00, // sym@gotplt (to fill)
1300 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1305 Output_data_plt_s390
<size
>::plt_entry_64
[plt_entry_size
] =
1308 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, // larl %r1, _GLOBAL_OFFSET_TABLE_+off (to fill)
1309 0xe3, 0x10, 0x10, 0x00, 0x00, 0x04, // lg %r1, 0(%r1)
1310 0x07, 0xf1, // br %r1
1312 0x0d, 0x10, // basr %r1, %r0
1313 0xe3, 0x10, 0x10, 0x0c, 0x00, 0x14, // lgf %r1, 12(%r1)
1314 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, // jg first_plt_entry (to fill)
1315 0x00, 0x00, 0x00, 0x00, // offset of relocation in .rela.plt (to fill)
1320 Output_data_plt_s390
<size
>::fill_plt_entry(
1322 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
1323 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
1324 unsigned int got_offset
,
1325 unsigned int plt_offset
,
1326 unsigned int plt_rel_offset
)
1330 memcpy(pov
, plt_entry_64
, plt_entry_size
);
1331 S390_relocate_functions
<size
>::pcrela32dbl(pov
+ 2, got_address
+ got_offset
, plt_address
+ plt_offset
);
1332 S390_relocate_functions
<size
>::pcrela32dbl(pov
+ 24, plt_address
, plt_address
+ plt_offset
+ 22);
1336 if (!parameters
->options().output_is_position_independent())
1338 memcpy(pov
, plt_entry_32_abs
, plt_entry_size
);
1339 elfcpp::Swap
<32, true>::writeval(pov
+ 24, got_address
+ got_offset
);
1343 if (got_offset
< 0x1000)
1345 memcpy(pov
, plt_entry_32_pic12
, plt_entry_size
);
1346 S390_relocate_functions
<size
>::rela12(pov
+ 2, got_offset
);
1348 else if (got_offset
< 0x8000)
1350 memcpy(pov
, plt_entry_32_pic16
, plt_entry_size
);
1351 S390_relocate_functions
<size
>::rela16(pov
+ 2, got_offset
);
1355 memcpy(pov
, plt_entry_32_pic
, plt_entry_size
);
1356 elfcpp::Swap
<32, true>::writeval(pov
+ 24, got_offset
);
1359 typename
elfcpp::Elf_types
<size
>::Elf_Addr target
= plt_address
;
1360 if (plt_offset
>= 0x10000)
1362 // Would overflow pcrela16dbl - aim at the farthest previous jump
1364 if (plt_offset
> 0x10000)
1366 // Use the full range of pcrel16dbl.
1367 target
= plt_address
+ plt_offset
- 0x10000 + 18;
1371 // if plt_offset is exactly 0x10000, the above would aim at 18th byte
1372 // of first_plt_entry, which doesn't have the jump back like the others.
1373 // Aim at the next entry instead.
1374 target
= plt_address
+ plt_offset
- 0xffe0 + 18;
1377 S390_relocate_functions
<size
>::pcrela16dbl(pov
+ 20, target
, plt_address
+ plt_offset
+ 18);
1379 elfcpp::Swap
<32, true>::writeval(pov
+ 28, plt_rel_offset
);
1386 // The .eh_frame unwind information for the PLT.
1390 Output_data_plt_s390
<32>::plt_eh_frame_cie
[plt_eh_frame_cie_size
] =
1393 'z', // Augmentation: augmentation size included.
1394 'R', // Augmentation: FDE encoding included.
1395 '\0', // End of augmentation string.
1396 1, // Code alignment factor.
1397 0x7c, // Data alignment factor.
1398 14, // Return address column.
1399 1, // Augmentation size.
1400 (elfcpp::DW_EH_PE_pcrel
// FDE encoding.
1401 | elfcpp::DW_EH_PE_sdata4
),
1402 elfcpp::DW_CFA_def_cfa
, 15, 0x60, // DW_CFA_def_cfa: r15 ofs 0x60.
1407 Output_data_plt_s390
<64>::plt_eh_frame_cie
[plt_eh_frame_cie_size
] =
1410 'z', // Augmentation: augmentation size included.
1411 'R', // Augmentation: FDE encoding included.
1412 '\0', // End of augmentation string.
1413 1, // Code alignment factor.
1414 0x78, // Data alignment factor.
1415 14, // Return address column.
1416 1, // Augmentation size.
1417 (elfcpp::DW_EH_PE_pcrel
// FDE encoding.
1418 | elfcpp::DW_EH_PE_sdata4
),
1419 elfcpp::DW_CFA_def_cfa
, 15, 0xa0, // DW_CFA_def_cfa: r15 ofs 0xa0.
1424 Output_data_plt_s390
<size
>::plt_eh_frame_fde
[plt_eh_frame_fde_size
] =
1426 0, 0, 0, 0, // Replaced with offset to .plt.
1427 0, 0, 0, 0, // Replaced with size of .plt.
1428 0, // Augmentation size.
1434 // Write out the PLT. This uses the hand-coded instructions above,
1435 // and adjusts them as needed.
1439 Output_data_plt_s390
<size
>::do_write(Output_file
* of
)
1441 const off_t offset
= this->offset();
1442 const section_size_type oview_size
=
1443 convert_to_section_size_type(this->data_size());
1444 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1446 const off_t got_file_offset
= this->got_plt_
->offset();
1447 gold_assert(parameters
->incremental_update()
1448 || (got_file_offset
+ this->got_plt_
->data_size()
1449 == this->got_irelative_
->offset()));
1450 const section_size_type got_size
=
1451 convert_to_section_size_type(this->got_plt_
->data_size()
1452 + this->got_irelative_
->data_size());
1453 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
1456 unsigned char* pov
= oview
;
1458 // The base address of the .plt section.
1459 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
= this->address();
1460 // The base address of the PLT portion of the .got section,
1461 // which is where the GOT pointer will point, and where the
1462 // three reserved GOT entries are located.
1463 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
1464 = this->got_plt_
->address();
1466 this->fill_first_plt_entry(pov
, got_address
, plt_address
);
1467 pov
+= this->get_plt_entry_size();
1469 unsigned char* got_pov
= got_view
;
1471 const int rel_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
1473 unsigned int plt_offset
= this->get_plt_entry_size();
1474 unsigned int plt_rel_offset
= 0;
1475 unsigned int got_offset
= 3 * size
/ 8;
1476 const unsigned int count
= this->count_
+ this->irelative_count_
;
1477 // The first three entries in the GOT are reserved, and are written
1478 // by Output_data_got_plt_s390::do_write.
1479 got_pov
+= 3 * size
/ 8;
1481 for (unsigned int plt_index
= 0;
1484 pov
+= plt_entry_size
,
1485 got_pov
+= size
/ 8,
1486 plt_offset
+= plt_entry_size
,
1487 plt_rel_offset
+= rel_size
,
1488 got_offset
+= size
/ 8)
1490 // Set and adjust the PLT entry itself.
1491 unsigned int lazy_offset
= this->fill_plt_entry(pov
,
1492 got_address
, plt_address
,
1493 got_offset
, plt_offset
,
1496 // Set the entry in the GOT.
1497 elfcpp::Swap
<size
, true>::writeval(got_pov
,
1498 plt_address
+ plt_offset
+ lazy_offset
);
1501 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1502 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
1504 of
->write_output_view(offset
, oview_size
, oview
);
1505 of
->write_output_view(got_file_offset
, got_size
, got_view
);
1508 // Get the GOT section, creating it if necessary.
1511 Output_data_got
<size
, true>*
1512 Target_s390
<size
>::got_section(Symbol_table
* symtab
, Layout
* layout
)
1514 if (this->got_
== NULL
)
1516 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1518 // When using -z now, we can treat .got as a relro section.
1519 // Without -z now, it is modified after program startup by lazy
1521 bool is_got_relro
= parameters
->options().now();
1522 Output_section_order got_order
= (is_got_relro
1526 // The old GNU linker creates a .got.plt section. We just
1527 // create another set of data in the .got section. Note that we
1528 // always create a PLT if we create a GOT, although the PLT
1530 this->got_plt_
= new Output_data_got_plt_s390
<size
>(layout
);
1531 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1532 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
1533 this->got_plt_
, got_order
, is_got_relro
);
1535 // The first three entries are reserved.
1536 this->got_plt_
->set_current_data_size(3 * size
/ 8);
1538 // If there are any IRELATIVE relocations, they get GOT entries
1539 // in .got.plt after the jump slot entries.
1540 this->got_irelative_
= new Output_data_space(size
/ 8, "** GOT IRELATIVE PLT");
1541 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1542 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
1543 this->got_irelative_
,
1544 got_order
, is_got_relro
);
1546 // Unlike some targets (.e.g x86), S/390 does not use separate .got and
1547 // .got.plt sections in output. The output .got section contains both
1548 // PLT and non-PLT GOT entries.
1549 this->got_
= new Output_data_got
<size
, true>();
1551 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1552 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
1553 this->got_
, got_order
, is_got_relro
);
1555 // Define _GLOBAL_OFFSET_TABLE_ at the start of the GOT.
1556 this->global_offset_table_
=
1557 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1558 Symbol_table::PREDEFINED
,
1560 0, 0, elfcpp::STT_OBJECT
,
1562 elfcpp::STV_HIDDEN
, 0,
1569 // Get the dynamic reloc section, creating it if necessary.
1572 typename Target_s390
<size
>::Reloc_section
*
1573 Target_s390
<size
>::rela_dyn_section(Layout
* layout
)
1575 if (this->rela_dyn_
== NULL
)
1577 gold_assert(layout
!= NULL
);
1578 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1579 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1580 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1581 ORDER_DYNAMIC_RELOCS
, false);
1583 return this->rela_dyn_
;
1586 // Get the section to use for IRELATIVE relocs, creating it if
1587 // necessary. These go in .rela.dyn, but only after all other dynamic
1588 // relocations. They need to follow the other dynamic relocations so
1589 // that they can refer to global variables initialized by those
1593 typename Target_s390
<size
>::Reloc_section
*
1594 Target_s390
<size
>::rela_irelative_section(Layout
* layout
)
1596 if (this->rela_irelative_
== NULL
)
1598 // Make sure we have already created the dynamic reloc section.
1599 this->rela_dyn_section(layout
);
1600 this->rela_irelative_
= new Reloc_section(false);
1601 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1602 elfcpp::SHF_ALLOC
, this->rela_irelative_
,
1603 ORDER_DYNAMIC_RELOCS
, false);
1604 gold_assert(this->rela_dyn_
->output_section()
1605 == this->rela_irelative_
->output_section());
1607 return this->rela_irelative_
;
1610 // Write the first three reserved words of the .got.plt section.
1611 // The remainder of the section is written while writing the PLT
1612 // in Output_data_plt_s390::do_write.
1616 Output_data_got_plt_s390
<size
>::do_write(Output_file
* of
)
1618 // The first entry in the GOT is the address of the .dynamic section
1619 // aka the PT_DYNAMIC segment. The next two entries are reserved.
1620 // We saved space for them when we created the section in
1621 // Target_x86_64::got_section.
1622 const off_t got_file_offset
= this->offset();
1623 gold_assert(this->data_size() >= 3 * size
/ 8);
1624 unsigned char* const got_view
=
1625 of
->get_output_view(got_file_offset
, 3 * size
/ 8);
1626 Output_section
* dynamic
= this->layout_
->dynamic_section();
1627 uint64_t dynamic_addr
= dynamic
== NULL
? 0 : dynamic
->address();
1628 elfcpp::Swap
<size
, true>::writeval(got_view
, dynamic_addr
);
1629 memset(got_view
+ size
/ 8, 0, 2 * size
/ 8);
1630 of
->write_output_view(got_file_offset
, 3 * size
/ 8, got_view
);
1633 // Create the PLT section.
1637 Target_s390
<size
>::make_plt_section(Symbol_table
* symtab
, Layout
* layout
)
1639 if (this->plt_
== NULL
)
1641 // Create the GOT sections first.
1642 this->got_section(symtab
, layout
);
1644 // Ensure that .rela.dyn always appears before .rela.plt This is
1645 // necessary due to how, on 32-bit S/390 and some other targets,
1646 // .rela.dyn needs to include .rela.plt in it's range.
1647 this->rela_dyn_section(layout
);
1649 this->plt_
= new Output_data_plt_s390
<size
>(layout
,
1650 this->got_
, this->got_plt_
, this->got_irelative_
);
1652 // Add unwind information if requested.
1653 if (parameters
->options().ld_generated_unwind_info())
1654 this->plt_
->add_eh_frame(layout
);
1656 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1658 | elfcpp::SHF_EXECINSTR
),
1659 this->plt_
, ORDER_PLT
, false);
1661 // Make the sh_info field of .rela.plt point to .plt.
1662 Output_section
* rela_plt_os
= this->plt_
->rela_plt()->output_section();
1663 rela_plt_os
->set_info_section(this->plt_
->output_section());
1667 // Create a PLT entry for a global symbol.
1671 Target_s390
<size
>::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
1674 if (gsym
->has_plt_offset())
1677 if (this->plt_
== NULL
)
1678 this->make_plt_section(symtab
, layout
);
1680 this->plt_
->add_entry(symtab
, layout
, gsym
);
1683 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1687 Target_s390
<size
>::make_local_ifunc_plt_entry(
1688 Symbol_table
* symtab
, Layout
* layout
,
1689 Sized_relobj_file
<size
, true>* relobj
,
1690 unsigned int local_sym_index
)
1692 if (relobj
->local_has_plt_offset(local_sym_index
))
1694 if (this->plt_
== NULL
)
1695 this->make_plt_section(symtab
, layout
);
1696 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1699 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1702 // Return the number of entries in the PLT.
1706 Target_s390
<size
>::plt_entry_count() const
1708 if (this->plt_
== NULL
)
1710 return this->plt_
->entry_count();
1713 // Return the offset of the first non-reserved PLT entry.
1717 Target_s390
<size
>::first_plt_entry_offset() const
1719 return this->plt_
->first_plt_entry_offset();
1722 // Return the size of each PLT entry.
1726 Target_s390
<size
>::plt_entry_size() const
1728 return this->plt_
->get_plt_entry_size();
1731 // Create the GOT and PLT sections for an incremental update.
1734 Output_data_got_base
*
1735 Target_s390
<size
>::init_got_plt_for_update(Symbol_table
* symtab
,
1737 unsigned int got_count
,
1738 unsigned int plt_count
)
1740 gold_assert(this->got_
== NULL
);
1742 // Add the three reserved entries.
1743 this->got_plt_
= new Output_data_got_plt_s390
<size
>(layout
, (plt_count
+ 3) * size
/ 8);
1744 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1746 | elfcpp::SHF_WRITE
),
1747 this->got_plt_
, ORDER_NON_RELRO_FIRST
,
1750 // If there are any IRELATIVE relocations, they get GOT entries in
1751 // .got.plt after the jump slot entries.
1752 this->got_irelative_
= new Output_data_space(0, size
/ 8, "** GOT IRELATIVE PLT");
1753 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1754 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1755 this->got_irelative_
,
1756 ORDER_NON_RELRO_FIRST
, false);
1758 this->got_
= new Output_data_got
<size
, true>(got_count
* size
/ 8);
1759 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1761 | elfcpp::SHF_WRITE
),
1762 this->got_
, ORDER_RELRO_LAST
,
1765 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
1766 this->global_offset_table_
=
1767 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1768 Symbol_table::PREDEFINED
,
1770 0, 0, elfcpp::STT_OBJECT
,
1772 elfcpp::STV_HIDDEN
, 0,
1775 // Create the PLT section.
1776 this->plt_
= new Output_data_plt_s390
<size
>(layout
,
1777 this->got_
, this->got_plt_
, this->got_irelative_
, plt_count
);
1779 // Add unwind information if requested.
1780 if (parameters
->options().ld_generated_unwind_info())
1781 this->plt_
->add_eh_frame(layout
);
1783 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1784 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
1785 this->plt_
, ORDER_PLT
, false);
1787 // Make the sh_info field of .rela.plt point to .plt.
1788 Output_section
* rela_plt_os
= this->plt_
->rela_plt()->output_section();
1789 rela_plt_os
->set_info_section(this->plt_
->output_section());
1791 // Create the rela_dyn section.
1792 this->rela_dyn_section(layout
);
1797 // Reserve a GOT entry for a local symbol, and regenerate any
1798 // necessary dynamic relocations.
1802 Target_s390
<size
>::reserve_local_got_entry(
1803 unsigned int got_index
,
1804 Sized_relobj
<size
, true>* obj
,
1806 unsigned int got_type
)
1808 unsigned int got_offset
= got_index
* size
/ 8;
1809 Reloc_section
* rela_dyn
= this->rela_dyn_section(NULL
);
1811 this->got_
->reserve_local(got_index
, obj
, r_sym
, got_type
);
1814 case GOT_TYPE_STANDARD
:
1815 if (parameters
->options().output_is_position_independent())
1816 rela_dyn
->add_local_relative(obj
, r_sym
, elfcpp::R_390_RELATIVE
,
1817 this->got_
, got_offset
, 0, false);
1819 case GOT_TYPE_TLS_OFFSET
:
1820 rela_dyn
->add_local(obj
, r_sym
, elfcpp::R_390_TLS_TPOFF
,
1821 this->got_
, got_offset
, 0);
1823 case GOT_TYPE_TLS_PAIR
:
1824 this->got_
->reserve_slot(got_index
+ 1);
1825 rela_dyn
->add_local(obj
, r_sym
, elfcpp::R_390_TLS_DTPMOD
,
1826 this->got_
, got_offset
, 0);
1833 // Reserve a GOT entry for a global symbol, and regenerate any
1834 // necessary dynamic relocations.
1838 Target_s390
<size
>::reserve_global_got_entry(unsigned int got_index
,
1840 unsigned int got_type
)
1842 unsigned int got_offset
= got_index
* size
/ 8;
1843 Reloc_section
* rela_dyn
= this->rela_dyn_section(NULL
);
1845 this->got_
->reserve_global(got_index
, gsym
, got_type
);
1848 case GOT_TYPE_STANDARD
:
1849 if (!gsym
->final_value_is_known())
1851 if (gsym
->is_from_dynobj()
1852 || gsym
->is_undefined()
1853 || gsym
->is_preemptible()
1854 || gsym
->type() == elfcpp::STT_GNU_IFUNC
)
1855 rela_dyn
->add_global(gsym
, elfcpp::R_390_GLOB_DAT
,
1856 this->got_
, got_offset
, 0);
1858 rela_dyn
->add_global_relative(gsym
, elfcpp::R_390_RELATIVE
,
1859 this->got_
, got_offset
, 0, false);
1862 case GOT_TYPE_TLS_OFFSET
:
1863 rela_dyn
->add_global_relative(gsym
, elfcpp::R_390_TLS_TPOFF
,
1864 this->got_
, got_offset
, 0, false);
1866 case GOT_TYPE_TLS_PAIR
:
1867 this->got_
->reserve_slot(got_index
+ 1);
1868 rela_dyn
->add_global_relative(gsym
, elfcpp::R_390_TLS_DTPMOD
,
1869 this->got_
, got_offset
, 0, false);
1870 rela_dyn
->add_global_relative(gsym
, elfcpp::R_390_TLS_DTPOFF
,
1871 this->got_
, got_offset
+ size
/ 8, 0, false);
1878 // Register an existing PLT entry for a global symbol.
1882 Target_s390
<size
>::register_global_plt_entry(Symbol_table
* symtab
,
1884 unsigned int plt_index
,
1887 gold_assert(this->plt_
!= NULL
);
1888 gold_assert(!gsym
->has_plt_offset());
1890 this->plt_
->reserve_slot(plt_index
);
1892 gsym
->set_plt_offset((plt_index
+ 1) * this->plt_entry_size());
1894 unsigned int got_offset
= (plt_index
+ 3) * size
/ 8;
1895 this->plt_
->add_relocation(symtab
, layout
, gsym
, got_offset
);
1898 // Force a COPY relocation for a given symbol.
1902 Target_s390
<size
>::emit_copy_reloc(
1903 Symbol_table
* symtab
, Symbol
* sym
, Output_section
* os
, off_t offset
)
1905 this->copy_relocs_
.emit_copy_reloc(symtab
,
1906 symtab
->get_sized_symbol
<size
>(sym
),
1909 this->rela_dyn_section(NULL
));
1912 // Create a GOT entry for the TLS module index.
1916 Target_s390
<size
>::got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
1917 Sized_relobj_file
<size
, true>* object
)
1919 if (this->got_mod_index_offset_
== -1U)
1921 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1922 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1923 Output_data_got
<size
, true>* got
= this->got_section(symtab
, layout
);
1924 unsigned int got_offset
= got
->add_constant(0);
1925 rela_dyn
->add_local(object
, 0, elfcpp::R_390_TLS_DTPMOD
, got
,
1927 got
->add_constant(0);
1928 this->got_mod_index_offset_
= got_offset
;
1930 return this->got_mod_index_offset_
;
1933 // Optimize the TLS relocation type based on what we know about the
1934 // symbol. IS_FINAL is true if the final address of this symbol is
1935 // known at link time.
1938 tls::Tls_optimization
1939 Target_s390
<size
>::optimize_tls_reloc(bool is_final
, int r_type
)
1941 // If we are generating a shared library, then we can't do anything
1943 if (parameters
->options().shared())
1944 return tls::TLSOPT_NONE
;
1948 case elfcpp::R_390_TLS_GD32
:
1949 case elfcpp::R_390_TLS_GD64
:
1950 case elfcpp::R_390_TLS_GDCALL
:
1951 // These are General-Dynamic which permits fully general TLS
1952 // access. Since we know that we are generating an executable,
1953 // we can convert this to Initial-Exec. If we also know that
1954 // this is a local symbol, we can further switch to Local-Exec.
1956 return tls::TLSOPT_TO_LE
;
1957 return tls::TLSOPT_TO_IE
;
1959 case elfcpp::R_390_TLS_LDM32
:
1960 case elfcpp::R_390_TLS_LDM64
:
1961 case elfcpp::R_390_TLS_LDO32
:
1962 case elfcpp::R_390_TLS_LDO64
:
1963 case elfcpp::R_390_TLS_LDCALL
:
1964 // This is Local-Dynamic, which refers to a local symbol in the
1965 // dynamic TLS block. Since we know that we generating an
1966 // executable, we can switch to Local-Exec.
1967 return tls::TLSOPT_TO_LE
;
1969 case elfcpp::R_390_TLS_IE32
:
1970 case elfcpp::R_390_TLS_IE64
:
1971 case elfcpp::R_390_TLS_GOTIE32
:
1972 case elfcpp::R_390_TLS_GOTIE64
:
1973 case elfcpp::R_390_TLS_LOAD
:
1974 // These are Initial-Exec relocs which get the thread offset
1975 // from the GOT. If we know that we are linking against the
1976 // local symbol, we can switch to Local-Exec, which links the
1977 // thread offset into the instruction.
1979 return tls::TLSOPT_TO_LE
;
1980 return tls::TLSOPT_NONE
;
1982 case elfcpp::R_390_TLS_GOTIE12
:
1983 case elfcpp::R_390_TLS_IEENT
:
1984 case elfcpp::R_390_TLS_GOTIE20
:
1985 // These are Initial-Exec, but cannot be optimized.
1986 return tls::TLSOPT_NONE
;
1988 case elfcpp::R_390_TLS_LE32
:
1989 case elfcpp::R_390_TLS_LE64
:
1990 // When we already have Local-Exec, there is nothing further we
1992 return tls::TLSOPT_NONE
;
1999 // Get the Reference_flags for a particular relocation.
2003 Target_s390
<size
>::Scan::get_reference_flags(unsigned int r_type
)
2007 case elfcpp::R_390_NONE
:
2008 case elfcpp::R_390_GNU_VTINHERIT
:
2009 case elfcpp::R_390_GNU_VTENTRY
:
2010 case elfcpp::R_390_GOTPC
:
2011 case elfcpp::R_390_GOTPCDBL
:
2012 // No symbol reference.
2015 case elfcpp::R_390_64
:
2016 case elfcpp::R_390_32
:
2017 case elfcpp::R_390_20
:
2018 case elfcpp::R_390_16
:
2019 case elfcpp::R_390_12
:
2020 case elfcpp::R_390_8
:
2021 return Symbol::ABSOLUTE_REF
;
2023 case elfcpp::R_390_PC12DBL
:
2024 case elfcpp::R_390_PC16
:
2025 case elfcpp::R_390_PC16DBL
:
2026 case elfcpp::R_390_PC24DBL
:
2027 case elfcpp::R_390_PC32
:
2028 case elfcpp::R_390_PC32DBL
:
2029 case elfcpp::R_390_PC64
:
2030 case elfcpp::R_390_GOTOFF16
:
2031 case elfcpp::R_390_GOTOFF32
:
2032 case elfcpp::R_390_GOTOFF64
:
2033 return Symbol::RELATIVE_REF
;
2035 case elfcpp::R_390_PLT12DBL
:
2036 case elfcpp::R_390_PLT16DBL
:
2037 case elfcpp::R_390_PLT24DBL
:
2038 case elfcpp::R_390_PLT32
:
2039 case elfcpp::R_390_PLT32DBL
:
2040 case elfcpp::R_390_PLT64
:
2041 case elfcpp::R_390_PLTOFF16
:
2042 case elfcpp::R_390_PLTOFF32
:
2043 case elfcpp::R_390_PLTOFF64
:
2044 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2046 case elfcpp::R_390_GOT12
:
2047 case elfcpp::R_390_GOT16
:
2048 case elfcpp::R_390_GOT20
:
2049 case elfcpp::R_390_GOT32
:
2050 case elfcpp::R_390_GOT64
:
2051 case elfcpp::R_390_GOTENT
:
2052 case elfcpp::R_390_GOTPLT12
:
2053 case elfcpp::R_390_GOTPLT16
:
2054 case elfcpp::R_390_GOTPLT20
:
2055 case elfcpp::R_390_GOTPLT32
:
2056 case elfcpp::R_390_GOTPLT64
:
2057 case elfcpp::R_390_GOTPLTENT
:
2059 return Symbol::ABSOLUTE_REF
;
2061 case elfcpp::R_390_TLS_GD32
: // Global-dynamic
2062 case elfcpp::R_390_TLS_GD64
:
2063 case elfcpp::R_390_TLS_GDCALL
:
2064 case elfcpp::R_390_TLS_LDM32
: // Local-dynamic
2065 case elfcpp::R_390_TLS_LDM64
:
2066 case elfcpp::R_390_TLS_LDO32
:
2067 case elfcpp::R_390_TLS_LDO64
:
2068 case elfcpp::R_390_TLS_LDCALL
:
2069 case elfcpp::R_390_TLS_IE32
: // Initial-exec
2070 case elfcpp::R_390_TLS_IE64
:
2071 case elfcpp::R_390_TLS_IEENT
:
2072 case elfcpp::R_390_TLS_GOTIE12
:
2073 case elfcpp::R_390_TLS_GOTIE20
:
2074 case elfcpp::R_390_TLS_GOTIE32
:
2075 case elfcpp::R_390_TLS_GOTIE64
:
2076 case elfcpp::R_390_TLS_LOAD
:
2077 case elfcpp::R_390_TLS_LE32
: // Local-exec
2078 case elfcpp::R_390_TLS_LE64
:
2079 return Symbol::TLS_REF
;
2081 case elfcpp::R_390_COPY
:
2082 case elfcpp::R_390_GLOB_DAT
:
2083 case elfcpp::R_390_JMP_SLOT
:
2084 case elfcpp::R_390_RELATIVE
:
2085 case elfcpp::R_390_IRELATIVE
:
2086 case elfcpp::R_390_TLS_TPOFF
:
2087 case elfcpp::R_390_TLS_DTPOFF
:
2088 case elfcpp::R_390_TLS_DTPMOD
:
2090 // Not expected. We will give an error later.
2095 // Report an unsupported relocation against a local symbol.
2099 Target_s390
<size
>::Scan::unsupported_reloc_local(
2100 Sized_relobj_file
<size
, true>* object
,
2101 unsigned int r_type
)
2103 gold_error(_("%s: unsupported reloc %u against local symbol"),
2104 object
->name().c_str(), r_type
);
2107 // We are about to emit a dynamic relocation of type R_TYPE. If the
2108 // dynamic linker does not support it, issue an error.
2112 Target_s390
<size
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
2114 gold_assert(r_type
!= elfcpp::R_390_NONE
);
2120 // These are the relocation types supported by glibc for s390 64-bit.
2121 case elfcpp::R_390_RELATIVE
:
2122 case elfcpp::R_390_IRELATIVE
:
2123 case elfcpp::R_390_COPY
:
2124 case elfcpp::R_390_GLOB_DAT
:
2125 case elfcpp::R_390_JMP_SLOT
:
2126 case elfcpp::R_390_TLS_DTPMOD
:
2127 case elfcpp::R_390_TLS_DTPOFF
:
2128 case elfcpp::R_390_TLS_TPOFF
:
2129 case elfcpp::R_390_8
:
2130 case elfcpp::R_390_16
:
2131 case elfcpp::R_390_32
:
2132 case elfcpp::R_390_64
:
2133 case elfcpp::R_390_PC16
:
2134 case elfcpp::R_390_PC16DBL
:
2135 case elfcpp::R_390_PC32
:
2136 case elfcpp::R_390_PC32DBL
:
2137 case elfcpp::R_390_PC64
:
2148 // These are the relocation types supported by glibc for s390 32-bit.
2149 case elfcpp::R_390_RELATIVE
:
2150 case elfcpp::R_390_IRELATIVE
:
2151 case elfcpp::R_390_COPY
:
2152 case elfcpp::R_390_GLOB_DAT
:
2153 case elfcpp::R_390_JMP_SLOT
:
2154 case elfcpp::R_390_TLS_DTPMOD
:
2155 case elfcpp::R_390_TLS_DTPOFF
:
2156 case elfcpp::R_390_TLS_TPOFF
:
2157 case elfcpp::R_390_8
:
2158 case elfcpp::R_390_16
:
2159 case elfcpp::R_390_32
:
2160 case elfcpp::R_390_PC16
:
2161 case elfcpp::R_390_PC16DBL
:
2162 case elfcpp::R_390_PC32
:
2163 case elfcpp::R_390_PC32DBL
:
2171 // This prevents us from issuing more than one error per reloc
2172 // section. But we can still wind up issuing more than one
2173 // error per object file.
2174 if (this->issued_non_pic_error_
)
2176 gold_assert(parameters
->options().output_is_position_independent());
2177 object
->error(_("requires unsupported dynamic reloc; "
2178 "recompile with -fPIC"));
2179 this->issued_non_pic_error_
= true;
2183 // Return whether we need to make a PLT entry for a relocation of the
2184 // given type against a STT_GNU_IFUNC symbol.
2188 Target_s390
<size
>::Scan::reloc_needs_plt_for_ifunc(
2189 Sized_relobj_file
<size
, true>* object
,
2190 unsigned int r_type
)
2192 int flags
= Scan::get_reference_flags(r_type
);
2193 if (flags
& Symbol::TLS_REF
)
2194 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2195 object
->name().c_str(), r_type
);
2199 // Scan a relocation for a local symbol.
2203 Target_s390
<size
>::Scan::local(Symbol_table
* symtab
,
2205 Target_s390
<size
>* target
,
2206 Sized_relobj_file
<size
, true>* object
,
2207 unsigned int data_shndx
,
2208 Output_section
* output_section
,
2209 const elfcpp::Rela
<size
, true>& reloc
,
2210 unsigned int r_type
,
2211 const elfcpp::Sym
<size
, true>& lsym
,
2217 // A local STT_GNU_IFUNC symbol may require a PLT entry.
2218 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2220 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(object
, r_type
))
2222 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2223 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
2228 case elfcpp::R_390_NONE
:
2229 case elfcpp::R_390_GNU_VTINHERIT
:
2230 case elfcpp::R_390_GNU_VTENTRY
:
2233 case elfcpp::R_390_64
:
2234 // If building a shared library (or a position-independent
2235 // executable), we need to create a dynamic relocation for this
2236 // location. The relocation applied at link time will apply the
2237 // link-time value, so we flag the location with an
2238 // R_390_RELATIVE relocation so the dynamic loader can
2239 // relocate it easily.
2240 if (parameters
->options().output_is_position_independent() && size
== 64)
2242 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2243 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2244 rela_dyn
->add_local_relative(object
, r_sym
,
2245 elfcpp::R_390_RELATIVE
,
2246 output_section
, data_shndx
,
2247 reloc
.get_r_offset(),
2248 reloc
.get_r_addend(), is_ifunc
);
2252 case elfcpp::R_390_32
:
2253 case elfcpp::R_390_20
:
2254 case elfcpp::R_390_16
:
2255 case elfcpp::R_390_12
:
2256 case elfcpp::R_390_8
:
2257 if (parameters
->options().output_is_position_independent())
2259 if (size
== 32 && r_type
== elfcpp::R_390_32
)
2261 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2262 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2263 rela_dyn
->add_local_relative(object
, r_sym
,
2264 elfcpp::R_390_RELATIVE
,
2265 output_section
, data_shndx
,
2266 reloc
.get_r_offset(),
2267 reloc
.get_r_addend(), is_ifunc
);
2271 check_non_pic(object
, r_type
);
2273 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2274 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2275 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2276 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
2277 data_shndx
, reloc
.get_r_offset(),
2278 reloc
.get_r_addend());
2281 gold_assert(lsym
.get_st_value() == 0);
2282 unsigned int shndx
= lsym
.get_st_shndx();
2284 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
2287 object
->error(_("section symbol %u has bad shndx %u"),
2290 rela_dyn
->add_local_section(object
, shndx
,
2291 r_type
, output_section
,
2292 data_shndx
, reloc
.get_r_offset(),
2293 reloc
.get_r_addend());
2298 case elfcpp::R_390_PC12DBL
:
2299 case elfcpp::R_390_PC16
:
2300 case elfcpp::R_390_PC16DBL
:
2301 case elfcpp::R_390_PC24DBL
:
2302 case elfcpp::R_390_PC32
:
2303 case elfcpp::R_390_PC32DBL
:
2304 case elfcpp::R_390_PC64
:
2307 case elfcpp::R_390_PLT12DBL
:
2308 case elfcpp::R_390_PLT16DBL
:
2309 case elfcpp::R_390_PLT24DBL
:
2310 case elfcpp::R_390_PLT32
:
2311 case elfcpp::R_390_PLT32DBL
:
2312 case elfcpp::R_390_PLT64
:
2313 // Since we know this is a local symbol, we can handle this as a
2317 case elfcpp::R_390_GOTPC
:
2318 case elfcpp::R_390_GOTPCDBL
:
2319 case elfcpp::R_390_GOTOFF16
:
2320 case elfcpp::R_390_GOTOFF32
:
2321 case elfcpp::R_390_GOTOFF64
:
2322 case elfcpp::R_390_PLTOFF16
:
2323 case elfcpp::R_390_PLTOFF32
:
2324 case elfcpp::R_390_PLTOFF64
:
2325 // We need a GOT section.
2326 target
->got_section(symtab
, layout
);
2327 // For PLTOFF*, we'd normally want a PLT section, but since we
2328 // know this is a local symbol, no PLT is needed.
2331 case elfcpp::R_390_GOT12
:
2332 case elfcpp::R_390_GOT16
:
2333 case elfcpp::R_390_GOT20
:
2334 case elfcpp::R_390_GOT32
:
2335 case elfcpp::R_390_GOT64
:
2336 case elfcpp::R_390_GOTENT
:
2337 case elfcpp::R_390_GOTPLT12
:
2338 case elfcpp::R_390_GOTPLT16
:
2339 case elfcpp::R_390_GOTPLT20
:
2340 case elfcpp::R_390_GOTPLT32
:
2341 case elfcpp::R_390_GOTPLT64
:
2342 case elfcpp::R_390_GOTPLTENT
:
2344 // The symbol requires a GOT section.
2345 Output_data_got
<size
, true>* got
= target
->got_section(symtab
, layout
);
2347 // The symbol requires a GOT entry.
2348 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2350 // For a STT_GNU_IFUNC symbol we want the PLT offset. That
2351 // lets function pointers compare correctly with shared
2352 // libraries. Otherwise we would need an IRELATIVE reloc.
2355 is_new
= got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
2357 is_new
= got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2360 // If we are generating a shared object, we need to add a
2361 // dynamic relocation for this symbol's GOT entry.
2362 if (parameters
->options().output_is_position_independent())
2364 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2365 unsigned int got_offset
=
2366 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2367 rela_dyn
->add_local_relative(object
, r_sym
,
2368 elfcpp::R_390_RELATIVE
,
2369 got
, got_offset
, 0, is_ifunc
);
2372 // For GOTPLT*, we'd normally want a PLT section, but since
2373 // we know this is a local symbol, no PLT is needed.
2377 case elfcpp::R_390_COPY
:
2378 case elfcpp::R_390_GLOB_DAT
:
2379 case elfcpp::R_390_JMP_SLOT
:
2380 case elfcpp::R_390_RELATIVE
:
2381 case elfcpp::R_390_IRELATIVE
:
2382 // These are outstanding tls relocs, which are unexpected when linking
2383 case elfcpp::R_390_TLS_TPOFF
:
2384 case elfcpp::R_390_TLS_DTPOFF
:
2385 case elfcpp::R_390_TLS_DTPMOD
:
2386 gold_error(_("%s: unexpected reloc %u in object file"),
2387 object
->name().c_str(), r_type
);
2390 // These are initial tls relocs, which are expected when linking
2391 case elfcpp::R_390_TLS_GD32
: // Global-dynamic
2392 case elfcpp::R_390_TLS_GD64
:
2393 case elfcpp::R_390_TLS_GDCALL
:
2394 case elfcpp::R_390_TLS_LDM32
: // Local-dynamic
2395 case elfcpp::R_390_TLS_LDM64
:
2396 case elfcpp::R_390_TLS_LDO32
:
2397 case elfcpp::R_390_TLS_LDO64
:
2398 case elfcpp::R_390_TLS_LDCALL
:
2399 case elfcpp::R_390_TLS_IE32
: // Initial-exec
2400 case elfcpp::R_390_TLS_IE64
:
2401 case elfcpp::R_390_TLS_IEENT
:
2402 case elfcpp::R_390_TLS_GOTIE12
:
2403 case elfcpp::R_390_TLS_GOTIE20
:
2404 case elfcpp::R_390_TLS_GOTIE32
:
2405 case elfcpp::R_390_TLS_GOTIE64
:
2406 case elfcpp::R_390_TLS_LOAD
:
2407 case elfcpp::R_390_TLS_LE32
: // Local-exec
2408 case elfcpp::R_390_TLS_LE64
:
2410 bool output_is_shared
= parameters
->options().shared();
2411 const tls::Tls_optimization optimized_type
2412 = Target_s390
<size
>::optimize_tls_reloc(!output_is_shared
,
2416 case elfcpp::R_390_TLS_GD32
: // General-dynamic
2417 case elfcpp::R_390_TLS_GD64
:
2418 case elfcpp::R_390_TLS_GDCALL
:
2419 if (optimized_type
== tls::TLSOPT_NONE
)
2421 // Create a pair of GOT entries for the module index and
2422 // dtv-relative offset.
2423 Output_data_got
<size
, true>* got
2424 = target
->got_section(symtab
, layout
);
2425 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2426 unsigned int shndx
= lsym
.get_st_shndx();
2428 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2430 object
->error(_("local symbol %u has bad shndx %u"),
2433 got
->add_local_pair_with_rel(object
, r_sym
,
2436 target
->rela_dyn_section(layout
),
2437 elfcpp::R_390_TLS_DTPMOD
);
2439 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2440 unsupported_reloc_local(object
, r_type
);
2443 case elfcpp::R_390_TLS_LDM32
: // Local-dynamic
2444 case elfcpp::R_390_TLS_LDM64
:
2445 case elfcpp::R_390_TLS_LDCALL
:
2446 if (optimized_type
== tls::TLSOPT_NONE
)
2448 // Create a GOT entry for the module index.
2449 target
->got_mod_index_entry(symtab
, layout
, object
);
2451 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2452 unsupported_reloc_local(object
, r_type
);
2455 case elfcpp::R_390_TLS_LDO32
:
2456 case elfcpp::R_390_TLS_LDO64
:
2459 case elfcpp::R_390_TLS_IE32
: // Initial-exec
2460 case elfcpp::R_390_TLS_IE64
:
2461 // These two involve an absolute address
2462 if (parameters
->options().shared()
2463 && optimized_type
== tls::TLSOPT_NONE
)
2465 if ((size
== 32 && r_type
== elfcpp::R_390_TLS_IE32
) ||
2466 (size
== 64 && r_type
== elfcpp::R_390_TLS_IE64
))
2468 // We need to create a dynamic relocation.
2469 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2470 unsigned int r_sym
=
2471 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2472 rela_dyn
->add_local_relative(object
, r_sym
,
2473 elfcpp::R_390_RELATIVE
,
2474 output_section
, data_shndx
,
2475 reloc
.get_r_offset(),
2476 reloc
.get_r_addend(), false);
2480 unsupported_reloc_local(object
, r_type
);
2484 case elfcpp::R_390_TLS_IEENT
:
2485 case elfcpp::R_390_TLS_GOTIE12
:
2486 case elfcpp::R_390_TLS_GOTIE20
:
2487 case elfcpp::R_390_TLS_GOTIE32
:
2488 case elfcpp::R_390_TLS_GOTIE64
:
2489 case elfcpp::R_390_TLS_LOAD
:
2490 layout
->set_has_static_tls();
2491 if (optimized_type
== tls::TLSOPT_NONE
)
2493 if (!output_is_shared
)
2495 // We're making an executable, and the symbol is local, but
2496 // we cannot optimize to LE. Make a const GOT entry instead.
2497 Output_data_got
<size
, true>* got
2498 = target
->got_section(symtab
, layout
);
2500 = elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2501 got
->add_local_plt(object
, r_sym
, GOT_TYPE_TLS_OFFSET
);
2505 // Create a GOT entry for the tp-relative offset.
2506 Output_data_got
<size
, true>* got
2507 = target
->got_section(symtab
, layout
);
2509 = elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2510 got
->add_local_with_rel(object
, r_sym
, GOT_TYPE_TLS_OFFSET
,
2511 target
->rela_dyn_section(layout
),
2512 elfcpp::R_390_TLS_TPOFF
);
2515 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2516 unsupported_reloc_local(object
, r_type
);
2519 case elfcpp::R_390_TLS_LE32
: // Local-exec
2520 case elfcpp::R_390_TLS_LE64
:
2521 layout
->set_has_static_tls();
2522 if (output_is_shared
)
2524 // We need to create a dynamic relocation.
2525 if ((size
== 32 && r_type
== elfcpp::R_390_TLS_LE32
) ||
2526 (size
== 64 && r_type
== elfcpp::R_390_TLS_LE64
))
2528 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2530 = elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2531 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2532 rela_dyn
->add_local(object
, r_sym
, elfcpp::R_390_TLS_TPOFF
,
2533 output_section
, data_shndx
,
2534 reloc
.get_r_offset(),
2535 reloc
.get_r_addend());
2539 unsupported_reloc_local(object
, r_type
);
2551 gold_error(_("%s: unsupported reloc %u against local symbol"),
2552 object
->name().c_str(), r_type
);
2557 // Scan a relocation for a global symbol.
2561 Target_s390
<size
>::Scan::global(Symbol_table
* symtab
,
2563 Target_s390
<size
>* target
,
2564 Sized_relobj_file
<size
, true>* object
,
2565 unsigned int data_shndx
,
2566 Output_section
* output_section
,
2567 const elfcpp::Rela
<size
, true>& reloc
,
2568 unsigned int r_type
,
2571 // A STT_GNU_IFUNC symbol may require a PLT entry.
2572 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
2573 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2574 target
->make_plt_entry(symtab
, layout
, gsym
);
2578 case elfcpp::R_390_NONE
:
2579 case elfcpp::R_390_GNU_VTINHERIT
:
2580 case elfcpp::R_390_GNU_VTENTRY
:
2583 case elfcpp::R_390_64
:
2584 case elfcpp::R_390_32
:
2585 case elfcpp::R_390_20
:
2586 case elfcpp::R_390_16
:
2587 case elfcpp::R_390_12
:
2588 case elfcpp::R_390_8
:
2590 // Make a PLT entry if necessary.
2591 if (gsym
->needs_plt_entry())
2593 target
->make_plt_entry(symtab
, layout
, gsym
);
2594 // Since this is not a PC-relative relocation, we may be
2595 // taking the address of a function. In that case we need to
2596 // set the entry in the dynamic symbol table to the address of
2598 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2599 gsym
->set_needs_dynsym_value();
2601 // Make a dynamic relocation if necessary.
2602 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2604 if (!parameters
->options().output_is_position_independent()
2605 && gsym
->may_need_copy_reloc())
2607 target
->copy_reloc(symtab
, layout
, object
,
2608 data_shndx
, output_section
, gsym
, reloc
);
2610 else if (((size
== 64 && r_type
== elfcpp::R_390_64
)
2611 || (size
== 32 && r_type
== elfcpp::R_390_32
))
2612 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2613 && gsym
->can_use_relative_reloc(false)
2614 && !gsym
->is_from_dynobj()
2615 && !gsym
->is_undefined()
2616 && !gsym
->is_preemptible())
2618 // Use an IRELATIVE reloc for a locally defined
2619 // STT_GNU_IFUNC symbol. This makes a function
2620 // address in a PIE executable match the address in a
2621 // shared library that it links against.
2622 Reloc_section
* rela_dyn
=
2623 target
->rela_irelative_section(layout
);
2624 unsigned int r_type
= elfcpp::R_390_IRELATIVE
;
2625 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2626 output_section
, object
,
2628 reloc
.get_r_offset(),
2629 reloc
.get_r_addend());
2631 else if (((size
== 64 && r_type
== elfcpp::R_390_64
)
2632 || (size
== 32 && r_type
== elfcpp::R_390_32
))
2633 && gsym
->can_use_relative_reloc(false))
2635 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2636 rela_dyn
->add_global_relative(gsym
, elfcpp::R_390_RELATIVE
,
2637 output_section
, object
,
2639 reloc
.get_r_offset(),
2640 reloc
.get_r_addend(), false);
2644 check_non_pic(object
, r_type
);
2645 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2646 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
2647 data_shndx
, reloc
.get_r_offset(),
2648 reloc
.get_r_addend());
2654 case elfcpp::R_390_PC12DBL
:
2655 case elfcpp::R_390_PC16
:
2656 case elfcpp::R_390_PC16DBL
:
2657 case elfcpp::R_390_PC24DBL
:
2658 case elfcpp::R_390_PC32
:
2659 case elfcpp::R_390_PC32DBL
:
2660 case elfcpp::R_390_PC64
:
2662 // Make a PLT entry if necessary.
2663 if (gsym
->needs_plt_entry())
2665 target
->make_plt_entry(symtab
, layout
, gsym
);
2666 // larl is often used to take address of a function. Aim the
2667 // symbol at the PLT entry.
2668 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2669 gsym
->set_needs_dynsym_value();
2671 // Make a dynamic relocation if necessary.
2672 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2674 if (parameters
->options().output_is_executable()
2675 && gsym
->may_need_copy_reloc())
2677 target
->copy_reloc(symtab
, layout
, object
,
2678 data_shndx
, output_section
, gsym
, reloc
);
2682 check_non_pic(object
, r_type
);
2683 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2684 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
2685 data_shndx
, reloc
.get_r_offset(),
2686 reloc
.get_r_addend());
2692 case elfcpp::R_390_PLT12DBL
:
2693 case elfcpp::R_390_PLT16DBL
:
2694 case elfcpp::R_390_PLT24DBL
:
2695 case elfcpp::R_390_PLT32
:
2696 case elfcpp::R_390_PLT32DBL
:
2697 case elfcpp::R_390_PLT64
:
2698 // If the symbol is fully resolved, this is just a PC32 reloc.
2699 // Otherwise we need a PLT entry.
2700 if (gsym
->final_value_is_known())
2702 // If building a shared library, we can also skip the PLT entry
2703 // if the symbol is defined in the output file and is protected
2705 if (gsym
->is_defined()
2706 && !gsym
->is_from_dynobj()
2707 && !gsym
->is_preemptible())
2709 target
->make_plt_entry(symtab
, layout
, gsym
);
2712 case elfcpp::R_390_GOTPC
:
2713 case elfcpp::R_390_GOTPCDBL
:
2714 case elfcpp::R_390_GOTOFF16
:
2715 case elfcpp::R_390_GOTOFF32
:
2716 case elfcpp::R_390_GOTOFF64
:
2717 case elfcpp::R_390_PLTOFF16
:
2718 case elfcpp::R_390_PLTOFF32
:
2719 case elfcpp::R_390_PLTOFF64
:
2720 // We need a GOT section.
2721 target
->got_section(symtab
, layout
);
2722 // For PLTOFF*, we also need a PLT entry (but only if the
2723 // symbol is not fully resolved).
2724 if ((r_type
== elfcpp::R_390_PLTOFF16
2725 || r_type
== elfcpp::R_390_PLTOFF32
2726 || r_type
== elfcpp::R_390_PLTOFF64
)
2727 && !gsym
->final_value_is_known())
2728 target
->make_plt_entry(symtab
, layout
, gsym
);
2731 case elfcpp::R_390_GOT12
:
2732 case elfcpp::R_390_GOT16
:
2733 case elfcpp::R_390_GOT20
:
2734 case elfcpp::R_390_GOT32
:
2735 case elfcpp::R_390_GOT64
:
2736 case elfcpp::R_390_GOTENT
:
2737 case elfcpp::R_390_GOTPLT12
:
2738 case elfcpp::R_390_GOTPLT16
:
2739 case elfcpp::R_390_GOTPLT20
:
2740 case elfcpp::R_390_GOTPLT32
:
2741 case elfcpp::R_390_GOTPLT64
:
2742 case elfcpp::R_390_GOTPLTENT
:
2744 // The symbol requires a GOT entry.
2745 Output_data_got
<size
, true>* got
= target
->got_section(symtab
, layout
);
2747 if (gsym
->final_value_is_known())
2749 // For a STT_GNU_IFUNC symbol we want the PLT address.
2750 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2751 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2753 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2757 // If this symbol is not fully resolved, we need to add a
2758 // dynamic relocation for it.
2759 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2761 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2763 // 1) The symbol may be defined in some other module.
2765 // 2) We are building a shared library and this is a
2766 // protected symbol; using GLOB_DAT means that the dynamic
2767 // linker can use the address of the PLT in the main
2768 // executable when appropriate so that function address
2769 // comparisons work.
2771 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2772 // code, again so that function address comparisons work.
2773 if (gsym
->is_from_dynobj()
2774 || gsym
->is_undefined()
2775 || gsym
->is_preemptible()
2776 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2777 && parameters
->options().shared())
2778 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2779 && parameters
->options().output_is_position_independent()))
2780 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2781 elfcpp::R_390_GLOB_DAT
);
2784 // For a STT_GNU_IFUNC symbol we want to write the PLT
2785 // offset into the GOT, so that function pointer
2786 // comparisons work correctly.
2788 if (gsym
->type() != elfcpp::STT_GNU_IFUNC
)
2789 is_new
= got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2792 is_new
= got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2793 // Tell the dynamic linker to use the PLT address
2794 // when resolving relocations.
2795 if (gsym
->is_from_dynobj()
2796 && !parameters
->options().shared())
2797 gsym
->set_needs_dynsym_value();
2801 unsigned int got_off
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2802 rela_dyn
->add_global_relative(gsym
,
2803 elfcpp::R_390_RELATIVE
,
2804 got
, got_off
, 0, false);
2811 case elfcpp::R_390_COPY
:
2812 case elfcpp::R_390_GLOB_DAT
:
2813 case elfcpp::R_390_JMP_SLOT
:
2814 case elfcpp::R_390_RELATIVE
:
2815 case elfcpp::R_390_IRELATIVE
:
2816 // These are outstanding tls relocs, which are unexpected when linking
2817 case elfcpp::R_390_TLS_TPOFF
:
2818 case elfcpp::R_390_TLS_DTPOFF
:
2819 case elfcpp::R_390_TLS_DTPMOD
:
2820 gold_error(_("%s: unexpected reloc %u in object file"),
2821 object
->name().c_str(), r_type
);
2824 // These are initial tls relocs, which are expected for global()
2825 case elfcpp::R_390_TLS_GD32
: // Global-dynamic
2826 case elfcpp::R_390_TLS_GD64
:
2827 case elfcpp::R_390_TLS_GDCALL
:
2828 case elfcpp::R_390_TLS_LDM32
: // Local-dynamic
2829 case elfcpp::R_390_TLS_LDM64
:
2830 case elfcpp::R_390_TLS_LDO32
:
2831 case elfcpp::R_390_TLS_LDO64
:
2832 case elfcpp::R_390_TLS_LDCALL
:
2833 case elfcpp::R_390_TLS_IE32
: // Initial-exec
2834 case elfcpp::R_390_TLS_IE64
:
2835 case elfcpp::R_390_TLS_IEENT
:
2836 case elfcpp::R_390_TLS_GOTIE12
:
2837 case elfcpp::R_390_TLS_GOTIE20
:
2838 case elfcpp::R_390_TLS_GOTIE32
:
2839 case elfcpp::R_390_TLS_GOTIE64
:
2840 case elfcpp::R_390_TLS_LOAD
:
2841 case elfcpp::R_390_TLS_LE32
: // Local-exec
2842 case elfcpp::R_390_TLS_LE64
:
2844 // For the optimizable Initial-Exec model, we can treat undef symbols
2845 // as final when building an executable.
2846 const bool is_final
= (gsym
->final_value_is_known() ||
2847 ((r_type
== elfcpp::R_390_TLS_IE32
||
2848 r_type
== elfcpp::R_390_TLS_IE64
||
2849 r_type
== elfcpp::R_390_TLS_GOTIE32
||
2850 r_type
== elfcpp::R_390_TLS_GOTIE64
) &&
2851 gsym
->is_undefined() &&
2852 parameters
->options().output_is_executable()));
2853 const tls::Tls_optimization optimized_type
2854 = Target_s390
<size
>::optimize_tls_reloc(is_final
, r_type
);
2857 case elfcpp::R_390_TLS_GD32
: // General-dynamic
2858 case elfcpp::R_390_TLS_GD64
:
2859 case elfcpp::R_390_TLS_GDCALL
:
2860 if (optimized_type
== tls::TLSOPT_NONE
)
2862 // Create a pair of GOT entries for the module index and
2863 // dtv-relative offset.
2864 Output_data_got
<size
, true>* got
2865 = target
->got_section(symtab
, layout
);
2866 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2867 target
->rela_dyn_section(layout
),
2868 elfcpp::R_390_TLS_DTPMOD
,
2869 elfcpp::R_390_TLS_DTPOFF
);
2871 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2873 // Create a GOT entry for the tp-relative offset.
2874 Output_data_got
<size
, true>* got
2875 = target
->got_section(symtab
, layout
);
2876 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2877 target
->rela_dyn_section(layout
),
2878 elfcpp::R_390_TLS_TPOFF
);
2880 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2881 unsupported_reloc_global(object
, r_type
, gsym
);
2884 case elfcpp::R_390_TLS_LDM32
: // Local-dynamic
2885 case elfcpp::R_390_TLS_LDM64
:
2886 case elfcpp::R_390_TLS_LDCALL
:
2887 if (optimized_type
== tls::TLSOPT_NONE
)
2889 // Create a GOT entry for the module index.
2890 target
->got_mod_index_entry(symtab
, layout
, object
);
2892 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2893 unsupported_reloc_global(object
, r_type
, gsym
);
2896 case elfcpp::R_390_TLS_LDO32
:
2897 case elfcpp::R_390_TLS_LDO64
:
2900 case elfcpp::R_390_TLS_IE32
: // Initial-exec
2901 case elfcpp::R_390_TLS_IE64
:
2902 // These two involve an absolute address
2903 if (parameters
->options().shared())
2905 if ((size
== 32 && r_type
== elfcpp::R_390_TLS_IE32
) ||
2906 (size
== 64 && r_type
== elfcpp::R_390_TLS_IE64
))
2908 // We need to create a dynamic relocation.
2909 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2910 rela_dyn
->add_global_relative(gsym
, elfcpp::R_390_RELATIVE
,
2911 output_section
, object
,
2913 reloc
.get_r_offset(),
2914 reloc
.get_r_addend(), false);
2918 unsupported_reloc_global(object
, r_type
, gsym
);
2922 case elfcpp::R_390_TLS_IEENT
:
2923 case elfcpp::R_390_TLS_GOTIE12
:
2924 case elfcpp::R_390_TLS_GOTIE20
:
2925 case elfcpp::R_390_TLS_GOTIE32
:
2926 case elfcpp::R_390_TLS_GOTIE64
:
2927 case elfcpp::R_390_TLS_LOAD
:
2928 layout
->set_has_static_tls();
2929 if (optimized_type
== tls::TLSOPT_NONE
)
2931 if (is_final
&& !parameters
->options().shared())
2933 // We're making an executable, and the symbol is local, but
2934 // we cannot optimize to LE. Make a const GOT entry instead.
2935 Output_data_got
<size
, true>* got
2936 = target
->got_section(symtab
, layout
);
2937 got
->add_global_plt(gsym
, GOT_TYPE_TLS_OFFSET
);
2941 // Create a GOT entry for the tp-relative offset.
2942 Output_data_got
<size
, true>* got
2943 = target
->got_section(symtab
, layout
);
2944 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2945 target
->rela_dyn_section(layout
),
2946 elfcpp::R_390_TLS_TPOFF
);
2949 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2950 unsupported_reloc_global(object
, r_type
, gsym
);
2953 case elfcpp::R_390_TLS_LE32
: // Local-exec
2954 case elfcpp::R_390_TLS_LE64
:
2955 layout
->set_has_static_tls();
2956 if (parameters
->options().shared())
2958 // We need to create a dynamic relocation.
2959 if ((size
== 32 && r_type
== elfcpp::R_390_TLS_LE32
) ||
2960 (size
== 64 && r_type
== elfcpp::R_390_TLS_LE64
))
2962 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2963 rela_dyn
->add_global(gsym
, elfcpp::R_390_TLS_TPOFF
,
2964 output_section
, object
,
2965 data_shndx
, reloc
.get_r_offset(),
2966 reloc
.get_r_addend());
2970 unsupported_reloc_global(object
, r_type
, gsym
);
2982 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2983 object
->name().c_str(), r_type
,
2984 gsym
->demangled_name().c_str());
2990 // Report an unsupported relocation against a global symbol.
2994 Target_s390
<size
>::Scan::unsupported_reloc_global(
2995 Sized_relobj_file
<size
, true>* object
,
2996 unsigned int r_type
,
2999 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3000 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
3003 // Returns true if this relocation type could be that of a function pointer.
3006 Target_s390
<size
>::Scan::possible_function_pointer_reloc(unsigned int r_type
)
3010 case elfcpp::R_390_32
:
3011 case elfcpp::R_390_64
:
3012 case elfcpp::R_390_PC32DBL
: // could be used by larl insn
3013 case elfcpp::R_390_GOT12
:
3014 case elfcpp::R_390_GOT16
:
3015 case elfcpp::R_390_GOT20
:
3016 case elfcpp::R_390_GOT32
:
3017 case elfcpp::R_390_GOT64
:
3018 case elfcpp::R_390_GOTENT
:
3019 case elfcpp::R_390_GOTOFF16
:
3020 case elfcpp::R_390_GOTOFF32
:
3021 case elfcpp::R_390_GOTOFF64
:
3027 // For safe ICF, scan a relocation for a local symbol to check if it
3028 // corresponds to a function pointer being taken. In that case mark
3029 // the function whose pointer was taken as not foldable.
3033 Target_s390
<size
>::Scan::local_reloc_may_be_function_pointer(
3036 Target_s390
<size
>* ,
3037 Sized_relobj_file
<size
, true>* ,
3040 const elfcpp::Rela
<size
, true>& ,
3041 unsigned int r_type
,
3042 const elfcpp::Sym
<size
, true>&)
3044 // When building a shared library, do not fold any local symbols.
3045 return (parameters
->options().shared()
3046 || possible_function_pointer_reloc(r_type
));
3049 // For safe ICF, scan a relocation for a global symbol to check if it
3050 // corresponds to a function pointer being taken. In that case mark
3051 // the function whose pointer was taken as not foldable.
3055 Target_s390
<size
>::Scan::global_reloc_may_be_function_pointer(
3058 Target_s390
<size
>* ,
3059 Sized_relobj_file
<size
, true>* ,
3062 const elfcpp::Rela
<size
, true>& ,
3063 unsigned int r_type
,
3066 // When building a shared library, do not fold symbols whose visibility
3067 // is hidden, internal or protected.
3068 return ((parameters
->options().shared()
3069 && (gsym
->visibility() == elfcpp::STV_INTERNAL
3070 || gsym
->visibility() == elfcpp::STV_PROTECTED
3071 || gsym
->visibility() == elfcpp::STV_HIDDEN
))
3072 || possible_function_pointer_reloc(r_type
));
3077 Target_s390
<size
>::gc_process_relocs(Symbol_table
* symtab
,
3079 Sized_relobj_file
<size
, true>* object
,
3080 unsigned int data_shndx
,
3081 unsigned int sh_type
,
3082 const unsigned char* prelocs
,
3084 Output_section
* output_section
,
3085 bool needs_special_offset_handling
,
3086 size_t local_symbol_count
,
3087 const unsigned char* plocal_symbols
)
3090 if (sh_type
== elfcpp::SHT_REL
)
3093 gold::gc_process_relocs
<size
, true, Target_s390
<size
>, elfcpp::SHT_RELA
,
3094 typename Target_s390
<size
>::Scan
,
3095 typename Target_s390
<size
>::Relocatable_size_for_reloc
>(
3104 needs_special_offset_handling
,
3109 // Perform a relocation.
3113 Target_s390
<size
>::Relocate::relocate(
3114 const Relocate_info
<size
, true>* relinfo
,
3116 Target_s390
<size
>* target
,
3119 const unsigned char* preloc
,
3120 const Sized_symbol
<size
>* gsym
,
3121 const Symbol_value
<size
>* psymval
,
3122 unsigned char* view
,
3123 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3124 section_size_type view_size
)
3129 const elfcpp::Rela
<size
, true> rela(preloc
);
3130 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
3131 const Sized_relobj_file
<size
, true>* object
= relinfo
->object
;
3133 // Pick the value to use for symbols defined in the PLT.
3134 Symbol_value
<size
> symval
;
3136 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
3138 symval
.set_output_value(target
->plt_address_for_global(gsym
));
3141 else if (gsym
== NULL
&& psymval
->is_ifunc_symbol())
3143 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3144 if (object
->local_has_plt_offset(r_sym
))
3146 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
));
3151 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3153 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= 0;
3157 case elfcpp::R_390_PLT64
:
3158 case elfcpp::R_390_PLT32
:
3159 case elfcpp::R_390_PLT32DBL
:
3160 case elfcpp::R_390_PLT24DBL
:
3161 case elfcpp::R_390_PLT16DBL
:
3162 case elfcpp::R_390_PLT12DBL
:
3163 gold_assert(gsym
== NULL
3164 || gsym
->has_plt_offset()
3165 || gsym
->final_value_is_known()
3166 || (gsym
->is_defined()
3167 && !gsym
->is_from_dynobj()
3168 && !gsym
->is_preemptible()));
3170 case elfcpp::R_390_8
:
3171 case elfcpp::R_390_12
:
3172 case elfcpp::R_390_16
:
3173 case elfcpp::R_390_20
:
3174 case elfcpp::R_390_32
:
3175 case elfcpp::R_390_64
:
3176 case elfcpp::R_390_PC16
:
3177 case elfcpp::R_390_PC32
:
3178 case elfcpp::R_390_PC64
:
3179 case elfcpp::R_390_PC32DBL
:
3180 case elfcpp::R_390_PC24DBL
:
3181 case elfcpp::R_390_PC16DBL
:
3182 case elfcpp::R_390_PC12DBL
:
3183 value
= psymval
->value(object
, addend
);
3186 case elfcpp::R_390_GOTPC
:
3187 case elfcpp::R_390_GOTPCDBL
:
3188 gold_assert(gsym
!= NULL
);
3189 value
= target
->got_address() + addend
;
3192 case elfcpp::R_390_PLTOFF64
:
3193 case elfcpp::R_390_PLTOFF32
:
3194 case elfcpp::R_390_PLTOFF16
:
3195 gold_assert(gsym
== NULL
3196 || gsym
->has_plt_offset()
3197 || gsym
->final_value_is_known());
3199 case elfcpp::R_390_GOTOFF64
:
3200 case elfcpp::R_390_GOTOFF32
:
3201 case elfcpp::R_390_GOTOFF16
:
3202 value
= (psymval
->value(object
, addend
)
3203 - target
->got_address());
3206 case elfcpp::R_390_GOT12
:
3207 case elfcpp::R_390_GOT16
:
3208 case elfcpp::R_390_GOT20
:
3209 case elfcpp::R_390_GOT32
:
3210 case elfcpp::R_390_GOT64
:
3211 case elfcpp::R_390_GOTENT
:
3212 case elfcpp::R_390_GOTPLT12
:
3213 case elfcpp::R_390_GOTPLT16
:
3214 case elfcpp::R_390_GOTPLT20
:
3215 case elfcpp::R_390_GOTPLT32
:
3216 case elfcpp::R_390_GOTPLT64
:
3217 case elfcpp::R_390_GOTPLTENT
:
3219 unsigned int got_offset
= 0;
3222 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3223 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3227 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3228 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3229 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3231 value
= got_offset
+ target
->got_main_offset() + addend
;
3235 // These are initial tls relocs, which are expected when linking
3236 case elfcpp::R_390_TLS_LOAD
:
3237 case elfcpp::R_390_TLS_GDCALL
: // Global-dynamic
3238 case elfcpp::R_390_TLS_GD32
:
3239 case elfcpp::R_390_TLS_GD64
:
3240 case elfcpp::R_390_TLS_LDCALL
: // Local-dynamic
3241 case elfcpp::R_390_TLS_LDM32
:
3242 case elfcpp::R_390_TLS_LDM64
:
3243 case elfcpp::R_390_TLS_LDO32
:
3244 case elfcpp::R_390_TLS_LDO64
:
3245 case elfcpp::R_390_TLS_GOTIE12
: // Initial-exec
3246 case elfcpp::R_390_TLS_GOTIE20
:
3247 case elfcpp::R_390_TLS_GOTIE32
:
3248 case elfcpp::R_390_TLS_GOTIE64
:
3249 case elfcpp::R_390_TLS_IE32
:
3250 case elfcpp::R_390_TLS_IE64
:
3251 case elfcpp::R_390_TLS_IEENT
:
3252 case elfcpp::R_390_TLS_LE32
: // Local-exec
3253 case elfcpp::R_390_TLS_LE64
:
3254 value
= this->relocate_tls(relinfo
, target
, relnum
, rela
, r_type
, gsym
, psymval
,
3262 typename S390_relocate_functions
<size
>::Status status
3263 = S390_relocate_functions
<size
>::STATUS_OK
;
3267 case elfcpp::R_390_NONE
:
3268 case elfcpp::R_390_GNU_VTINHERIT
:
3269 case elfcpp::R_390_GNU_VTENTRY
:
3270 case elfcpp::R_390_TLS_GDCALL
:
3271 case elfcpp::R_390_TLS_LDCALL
:
3272 case elfcpp::R_390_TLS_LOAD
:
3275 case elfcpp::R_390_64
:
3276 case elfcpp::R_390_GOT64
:
3277 case elfcpp::R_390_GOTPLT64
:
3278 case elfcpp::R_390_PLTOFF64
:
3279 case elfcpp::R_390_GOTOFF64
:
3280 case elfcpp::R_390_TLS_GD64
:
3281 case elfcpp::R_390_TLS_LDM64
:
3282 case elfcpp::R_390_TLS_LDO64
:
3283 case elfcpp::R_390_TLS_GOTIE64
:
3284 case elfcpp::R_390_TLS_IE64
:
3285 case elfcpp::R_390_TLS_LE64
:
3286 Relocate_functions
<size
, true>::rela64(view
, value
, 0);
3289 case elfcpp::R_390_32
:
3290 case elfcpp::R_390_GOT32
:
3291 case elfcpp::R_390_GOTPLT32
:
3292 case elfcpp::R_390_PLTOFF32
:
3293 case elfcpp::R_390_GOTOFF32
:
3294 case elfcpp::R_390_TLS_GD32
:
3295 case elfcpp::R_390_TLS_LDM32
:
3296 case elfcpp::R_390_TLS_LDO32
:
3297 case elfcpp::R_390_TLS_GOTIE32
:
3298 case elfcpp::R_390_TLS_IE32
:
3299 case elfcpp::R_390_TLS_LE32
:
3300 Relocate_functions
<size
, true>::rela32(view
, value
, 0);
3303 case elfcpp::R_390_20
:
3304 case elfcpp::R_390_GOT20
:
3305 case elfcpp::R_390_GOTPLT20
:
3306 case elfcpp::R_390_TLS_GOTIE20
:
3307 status
= S390_relocate_functions
<size
>::rela20(view
, value
);
3310 case elfcpp::R_390_16
:
3311 case elfcpp::R_390_GOT16
:
3312 case elfcpp::R_390_GOTPLT16
:
3313 case elfcpp::R_390_PLTOFF16
:
3314 case elfcpp::R_390_GOTOFF16
:
3315 status
= S390_relocate_functions
<size
>::rela16(view
, value
);
3318 case elfcpp::R_390_12
:
3319 case elfcpp::R_390_GOT12
:
3320 case elfcpp::R_390_GOTPLT12
:
3321 case elfcpp::R_390_TLS_GOTIE12
:
3322 status
= S390_relocate_functions
<size
>::rela12(view
, value
);
3325 case elfcpp::R_390_8
:
3326 Relocate_functions
<size
, true>::rela8(view
, value
, 0);
3329 case elfcpp::R_390_PC16
:
3330 Relocate_functions
<size
, true>::pcrela16(view
, value
, 0,
3334 case elfcpp::R_390_PLT64
:
3335 case elfcpp::R_390_PC64
:
3336 Relocate_functions
<size
, true>::pcrela64(view
, value
, 0, address
);
3339 case elfcpp::R_390_PLT32
:
3340 case elfcpp::R_390_PC32
:
3341 case elfcpp::R_390_GOTPC
:
3342 Relocate_functions
<size
, true>::pcrela32(view
, value
, 0, address
);
3345 case elfcpp::R_390_PLT32DBL
:
3346 case elfcpp::R_390_PC32DBL
:
3347 case elfcpp::R_390_GOTPCDBL
:
3348 status
= S390_relocate_functions
<size
>::pcrela32dbl(view
, value
, address
);
3351 case elfcpp::R_390_PLT24DBL
:
3352 case elfcpp::R_390_PC24DBL
:
3353 status
= S390_relocate_functions
<size
>::pcrela24dbl(view
, value
, address
);
3356 case elfcpp::R_390_PLT16DBL
:
3357 case elfcpp::R_390_PC16DBL
:
3358 status
= S390_relocate_functions
<size
>::pcrela16dbl(view
, value
, address
);
3361 case elfcpp::R_390_PLT12DBL
:
3362 case elfcpp::R_390_PC12DBL
:
3363 status
= S390_relocate_functions
<size
>::pcrela12dbl(view
, value
, address
);
3366 case elfcpp::R_390_GOTENT
:
3367 case elfcpp::R_390_GOTPLTENT
:
3368 case elfcpp::R_390_TLS_IEENT
:
3369 value
+= target
->got_address();
3370 status
= S390_relocate_functions
<size
>::pcrela32dbl(view
, value
, address
);
3373 case elfcpp::R_390_COPY
:
3374 case elfcpp::R_390_GLOB_DAT
:
3375 case elfcpp::R_390_JMP_SLOT
:
3376 case elfcpp::R_390_RELATIVE
:
3377 case elfcpp::R_390_IRELATIVE
:
3378 // These are outstanding tls relocs, which are unexpected when linking
3379 case elfcpp::R_390_TLS_TPOFF
:
3380 case elfcpp::R_390_TLS_DTPMOD
:
3381 case elfcpp::R_390_TLS_DTPOFF
:
3382 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3383 _("unexpected reloc %u in object file"),
3388 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3389 _("unsupported reloc %u"),
3394 if (status
!= S390_relocate_functions
<size
>::STATUS_OK
)
3396 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3397 _("relocation overflow"));
3403 // Perform a TLS relocation.
3406 inline typename
elfcpp::Elf_types
<size
>::Elf_Addr
3407 Target_s390
<size
>::Relocate::relocate_tls(
3408 const Relocate_info
<size
, true>* relinfo
,
3409 Target_s390
<size
>* target
,
3411 const elfcpp::Rela
<size
, true>& rela
,
3412 unsigned int r_type
,
3413 const Sized_symbol
<size
>* gsym
,
3414 const Symbol_value
<size
>* psymval
,
3415 unsigned char* view
,
3416 section_size_type view_size
)
3418 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3420 const Sized_relobj_file
<size
, true>* object
= relinfo
->object
;
3421 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3422 elfcpp::Shdr
<size
, true> data_shdr(relinfo
->data_shdr
);
3423 bool is_allocatable
= (data_shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0;
3425 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
3426 = psymval
->value(relinfo
->object
, addend
);
3428 const bool is_final
= (gsym
== NULL
3429 ? !parameters
->options().shared()
3430 : gsym
->final_value_is_known());
3431 tls::Tls_optimization optimized_type
3432 = Target_s390
<size
>::optimize_tls_reloc(is_final
, r_type
);
3435 case elfcpp::R_390_TLS_GDCALL
: // Global-dynamic marker
3436 if (optimized_type
== tls::TLSOPT_TO_LE
)
3438 if (tls_segment
== NULL
)
3440 gold_assert(parameters
->errors()->error_count() > 0
3441 || issue_undefined_symbol_error(gsym
));
3444 this->tls_gd_to_le(relinfo
, relnum
, rela
, view
, view_size
);
3449 if (optimized_type
== tls::TLSOPT_TO_IE
)
3451 this->tls_gd_to_ie(relinfo
, relnum
, rela
, view
, view_size
);
3454 else if (optimized_type
== tls::TLSOPT_NONE
)
3459 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3460 _("unsupported reloc %u"), r_type
);
3463 case elfcpp::R_390_TLS_GD32
: // Global-dynamic
3464 case elfcpp::R_390_TLS_GD64
:
3465 if (optimized_type
== tls::TLSOPT_TO_LE
)
3467 if (tls_segment
== NULL
)
3469 gold_assert(parameters
->errors()->error_count() > 0
3470 || issue_undefined_symbol_error(gsym
));
3473 return value
- tls_segment
->memsz();
3477 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3478 ? GOT_TYPE_TLS_OFFSET
3479 : GOT_TYPE_TLS_PAIR
);
3482 gold_assert(gsym
->has_got_offset(got_type
));
3483 return (gsym
->got_offset(got_type
)
3484 + target
->got_main_offset()
3489 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3490 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3491 return (object
->local_got_offset(r_sym
, got_type
)
3492 + target
->got_main_offset()
3496 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3497 _("unsupported reloc %u"), r_type
);
3500 case elfcpp::R_390_TLS_LDCALL
: // Local-dynamic marker
3501 // This is a marker relocation. If the sequence is being turned to LE,
3502 // we modify the instruction, otherwise the instruction is untouched.
3503 if (optimized_type
== tls::TLSOPT_TO_LE
)
3505 if (tls_segment
== NULL
)
3507 gold_assert(parameters
->errors()->error_count() > 0
3508 || issue_undefined_symbol_error(gsym
));
3511 this->tls_ld_to_le(relinfo
, relnum
, rela
, view
, view_size
);
3514 else if (optimized_type
== tls::TLSOPT_NONE
)
3518 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3519 _("unsupported reloc %u"), r_type
);
3522 case elfcpp::R_390_TLS_LDM32
: // Local-dynamic module
3523 case elfcpp::R_390_TLS_LDM64
:
3524 if (optimized_type
== tls::TLSOPT_TO_LE
)
3526 if (tls_segment
== NULL
)
3528 gold_assert(parameters
->errors()->error_count() > 0
3529 || issue_undefined_symbol_error(gsym
));
3532 // Doesn't matter what we fill it with - it's going to be unused.
3535 else if (optimized_type
== tls::TLSOPT_NONE
)
3537 // Relocate the field with the offset of the GOT entry for
3538 // the module index.
3539 return (target
->got_mod_index_entry(NULL
, NULL
, NULL
)
3541 + target
->got_main_offset());
3543 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3544 _("unsupported reloc %u"), r_type
);
3547 case elfcpp::R_390_TLS_LDO32
: // Local-dynamic offset
3548 case elfcpp::R_390_TLS_LDO64
:
3549 // This relocation type is used in debugging information.
3550 // In that case we need to not optimize the value. If the
3551 // section is not allocatable, then we assume we should not
3552 // optimize this reloc.
3553 if (optimized_type
== tls::TLSOPT_TO_LE
&& is_allocatable
)
3555 if (tls_segment
== NULL
)
3557 gold_assert(parameters
->errors()->error_count() > 0
3558 || issue_undefined_symbol_error(gsym
));
3561 value
-= tls_segment
->memsz();
3565 case elfcpp::R_390_TLS_LOAD
: // Initial-exec marker
3566 // This is a marker relocation. If the sequence is being turned to LE,
3567 // we modify the instruction, otherwise the instruction is untouched.
3569 && gsym
->is_undefined()
3570 && parameters
->options().output_is_executable())
3572 Target_s390
<size
>::Relocate::tls_ie_to_le(relinfo
, relnum
,
3577 else if (optimized_type
== tls::TLSOPT_TO_LE
)
3579 if (tls_segment
== NULL
)
3581 gold_assert(parameters
->errors()->error_count() > 0
3582 || issue_undefined_symbol_error(gsym
));
3585 Target_s390
<size
>::Relocate::tls_ie_to_le(relinfo
, relnum
,
3590 else if (optimized_type
== tls::TLSOPT_NONE
)
3594 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3595 _("unsupported reloc type %u"),
3599 case elfcpp::R_390_TLS_GOTIE12
: // Initial-exec, not optimizable
3600 case elfcpp::R_390_TLS_GOTIE20
:
3601 case elfcpp::R_390_TLS_IEENT
:
3602 case elfcpp::R_390_TLS_GOTIE32
: // Initial-exec, optimizable
3603 case elfcpp::R_390_TLS_GOTIE64
:
3604 case elfcpp::R_390_TLS_IE32
:
3605 case elfcpp::R_390_TLS_IE64
:
3607 && gsym
->is_undefined()
3608 && parameters
->options().output_is_executable()
3609 // These three cannot be optimized to LE, no matter what
3610 && r_type
!= elfcpp::R_390_TLS_GOTIE12
3611 && r_type
!= elfcpp::R_390_TLS_GOTIE20
3612 && r_type
!= elfcpp::R_390_TLS_IEENT
)
3616 else if (optimized_type
== tls::TLSOPT_TO_LE
)
3618 if (tls_segment
== NULL
)
3620 gold_assert(parameters
->errors()->error_count() > 0
3621 || issue_undefined_symbol_error(gsym
));
3624 return value
- tls_segment
->memsz();
3626 else if (optimized_type
== tls::TLSOPT_NONE
)
3628 // Relocate the field with the offset of the GOT entry for
3629 // the tp-relative offset of the symbol.
3630 unsigned int got_offset
;
3633 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3634 got_offset
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3638 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3639 gold_assert(object
->local_has_got_offset(r_sym
,
3640 GOT_TYPE_TLS_OFFSET
));
3641 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
);
3643 got_offset
+= target
->got_main_offset();
3644 if (r_type
== elfcpp::R_390_TLS_IE32
3645 || r_type
== elfcpp::R_390_TLS_IE64
)
3646 return target
->got_address() + got_offset
+ addend
;
3648 return got_offset
+ addend
;
3650 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3651 _("unsupported reloc type %u"),
3655 case elfcpp::R_390_TLS_LE32
: // Local-exec
3656 case elfcpp::R_390_TLS_LE64
:
3657 if (tls_segment
== NULL
)
3659 gold_assert(parameters
->errors()->error_count() > 0
3660 || issue_undefined_symbol_error(gsym
));
3663 return value
- tls_segment
->memsz();
3668 // Do a relocation in which we convert a TLS General-Dynamic to an
3673 Target_s390
<size
>::Relocate::tls_gd_to_ie(
3674 const Relocate_info
<size
, true>* relinfo
,
3676 const elfcpp::Rela
<size
, true>& rela
,
3677 unsigned char* view
,
3678 section_size_type view_size
)
3680 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
3681 if (view
[0] == 0x4d)
3683 // bas, don't care about details
3684 // Change to l %r2, 0(%r2, %r12)
3691 else if (view
[0] == 0xc0)
3693 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 6);
3694 // brasl %r14, __tls_get_offset@plt
3695 if (view
[1] == 0xe5)
3697 // Change to l/lg %r2, 0(%r2, %r12)
3698 // There was a PLT32DBL reloc at the last 4 bytes, overwrite its result.
3723 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3724 _("unsupported op for GD to IE"));
3727 // Do a relocation in which we convert a TLS General-Dynamic to a
3732 Target_s390
<size
>::Relocate::tls_gd_to_le(
3733 const Relocate_info
<size
, true>* relinfo
,
3735 const elfcpp::Rela
<size
, true>& rela
,
3736 unsigned char* view
,
3737 section_size_type view_size
)
3739 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 2);
3740 if (view
[0] == 0x0d)
3742 // basr, change to nop
3746 else if (view
[0] == 0x4d)
3748 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
3749 // bas, don't care about details, change to nop
3756 else if (view
[0] == 0xc0)
3758 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 6);
3759 // brasl %r14, __tls_get_offset@plt
3760 if (view
[1] == 0xe5)
3762 // Change to nop jump. There was a PLT32DBL reloc at the last
3763 // 4 bytes, overwrite its result.
3772 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3773 _("unsupported op for GD to LE"));
3778 Target_s390
<size
>::Relocate::tls_ld_to_le(
3779 const Relocate_info
<size
, true>* relinfo
,
3781 const elfcpp::Rela
<size
, true>& rela
,
3782 unsigned char* view
,
3783 section_size_type view_size
)
3785 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
3787 if (view
[0] == 0x0d)
3789 // basr, change to nop
3793 else if (view
[0] == 0x4d)
3795 // bas, don't care about details, change to nop
3802 else if (view
[0] == 0xc0)
3804 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 6);
3805 // brasl %r14, __tls_get_offset@plt
3806 if (view
[1] == 0xe5)
3808 // Change to nop jump. There was a PLT32DBL reloc at the last
3809 // 4 bytes, overwrite its result.
3818 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3819 _("unsupported op for LD to LE"));
3822 // Do a relocation in which we convert a TLS Initial-Exec to a
3827 Target_s390
<size
>::Relocate::tls_ie_to_le(
3828 const Relocate_info
<size
, true>* relinfo
,
3830 const elfcpp::Rela
<size
, true>& rela
,
3831 unsigned char* view
,
3832 section_size_type view_size
)
3834 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
3836 if (view
[0] == 0x58)
3838 // l %rX, 0(%rY) or l %rX, 0(%rY, %r12)
3839 if ((view
[2] & 0x0f) != 0 || view
[3] != 0)
3841 int rx
= view
[1] >> 4 & 0xf;
3842 int ry
= view
[1] & 0xf;
3843 int rz
= view
[2] >> 4 & 0xf;
3862 view
[1] = rx
<< 4 | ry
;
3867 else if (view
[0] == 0xe3)
3869 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 6);
3870 // lg %rX, 0(%rY) or lg %rX, 0(%rY, %r12)
3871 if ((view
[2] & 0x0f) != 0 ||
3876 int rx
= view
[1] >> 4 & 0xf;
3877 int ry
= view
[1] & 0xf;
3878 int rz
= view
[2] >> 4 & 0xf;
3895 // to sllg %rX, $rY, 0
3897 view
[1] = rx
<< 4 | ry
;
3906 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3907 _("unsupported op for IE to LE"));
3911 // Scan relocations for a section.
3915 Target_s390
<size
>::scan_relocs(Symbol_table
* symtab
,
3917 Sized_relobj_file
<size
, true>* object
,
3918 unsigned int data_shndx
,
3919 unsigned int sh_type
,
3920 const unsigned char* prelocs
,
3922 Output_section
* output_section
,
3923 bool needs_special_offset_handling
,
3924 size_t local_symbol_count
,
3925 const unsigned char* plocal_symbols
)
3927 if (sh_type
== elfcpp::SHT_REL
)
3929 gold_error(_("%s: unsupported REL reloc section"),
3930 object
->name().c_str());
3934 gold::scan_relocs
<size
, true, Target_s390
<size
>, elfcpp::SHT_RELA
,
3935 typename Target_s390
<size
>::Scan
>(
3944 needs_special_offset_handling
,
3949 // Finalize the sections.
3953 Target_s390
<size
>::do_finalize_sections(
3955 const Input_objects
*,
3956 Symbol_table
* symtab
)
3958 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3960 : this->plt_
->rela_plt());
3961 layout
->add_target_dynamic_tags(false, this->got_plt_
, rel_plt
,
3962 this->rela_dyn_
, true, size
== 32);
3964 this->layout_
= layout
;
3966 // Emit any relocs we saved in an attempt to avoid generating COPY
3968 if (this->copy_relocs_
.any_saved_relocs())
3969 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3971 // Set the size of the _GLOBAL_OFFSET_TABLE_ symbol to the size of
3972 // the .got section.
3973 Symbol
* sym
= this->global_offset_table_
;
3976 uint64_t data_size
= this->got_
->current_data_size();
3977 symtab
->get_sized_symbol
<size
>(sym
)->set_symsize(data_size
);
3980 if (parameters
->doing_static_link()
3981 && (this->plt_
== NULL
|| !this->plt_
->has_irelative_section()))
3983 // If linking statically, make sure that the __rela_iplt symbols
3984 // were defined if necessary, even if we didn't create a PLT.
3985 static const Define_symbol_in_segment syms
[] =
3988 "__rela_iplt_start", // name
3989 elfcpp::PT_LOAD
, // segment_type
3990 elfcpp::PF_W
, // segment_flags_set
3991 elfcpp::PF(0), // segment_flags_clear
3994 elfcpp::STT_NOTYPE
, // type
3995 elfcpp::STB_GLOBAL
, // binding
3996 elfcpp::STV_HIDDEN
, // visibility
3998 Symbol::SEGMENT_START
, // offset_from_base
4002 "__rela_iplt_end", // name
4003 elfcpp::PT_LOAD
, // segment_type
4004 elfcpp::PF_W
, // segment_flags_set
4005 elfcpp::PF(0), // segment_flags_clear
4008 elfcpp::STT_NOTYPE
, // type
4009 elfcpp::STB_GLOBAL
, // binding
4010 elfcpp::STV_HIDDEN
, // visibility
4012 Symbol::SEGMENT_START
, // offset_from_base
4017 symtab
->define_symbols(layout
, 2, syms
,
4018 layout
->script_options()->saw_sections_clause());
4022 // Return the size of a relocation while scanning during a relocatable
4027 Target_s390
<size
>::Relocatable_size_for_reloc::get_size_for_reloc(
4028 unsigned int r_type
,
4033 case elfcpp::R_390_NONE
:
4034 case elfcpp::R_390_GNU_VTINHERIT
:
4035 case elfcpp::R_390_GNU_VTENTRY
:
4036 case elfcpp::R_390_TLS_GD32
: // Global-dynamic
4037 case elfcpp::R_390_TLS_GD64
:
4038 case elfcpp::R_390_TLS_GDCALL
:
4039 case elfcpp::R_390_TLS_LDM32
: // Local-dynamic
4040 case elfcpp::R_390_TLS_LDM64
:
4041 case elfcpp::R_390_TLS_LDO32
:
4042 case elfcpp::R_390_TLS_LDO64
:
4043 case elfcpp::R_390_TLS_LDCALL
:
4044 case elfcpp::R_390_TLS_IE32
: // Initial-exec
4045 case elfcpp::R_390_TLS_IE64
:
4046 case elfcpp::R_390_TLS_IEENT
:
4047 case elfcpp::R_390_TLS_GOTIE12
:
4048 case elfcpp::R_390_TLS_GOTIE20
:
4049 case elfcpp::R_390_TLS_GOTIE32
:
4050 case elfcpp::R_390_TLS_GOTIE64
:
4051 case elfcpp::R_390_TLS_LOAD
:
4052 case elfcpp::R_390_TLS_LE32
: // Local-exec
4053 case elfcpp::R_390_TLS_LE64
:
4056 case elfcpp::R_390_64
:
4057 case elfcpp::R_390_PC64
:
4058 case elfcpp::R_390_GOT64
:
4059 case elfcpp::R_390_PLT64
:
4060 case elfcpp::R_390_GOTOFF64
:
4061 case elfcpp::R_390_GOTPLT64
:
4062 case elfcpp::R_390_PLTOFF64
:
4065 case elfcpp::R_390_32
:
4066 case elfcpp::R_390_PC32
:
4067 case elfcpp::R_390_GOT32
:
4068 case elfcpp::R_390_PLT32
:
4069 case elfcpp::R_390_GOTOFF32
:
4070 case elfcpp::R_390_GOTPC
:
4071 case elfcpp::R_390_PC32DBL
:
4072 case elfcpp::R_390_PLT32DBL
:
4073 case elfcpp::R_390_GOTPCDBL
:
4074 case elfcpp::R_390_GOTENT
:
4075 case elfcpp::R_390_GOTPLT32
:
4076 case elfcpp::R_390_GOTPLTENT
:
4077 case elfcpp::R_390_PLTOFF32
:
4078 case elfcpp::R_390_20
:
4079 case elfcpp::R_390_GOT20
:
4080 case elfcpp::R_390_GOTPLT20
:
4083 case elfcpp::R_390_PC24DBL
:
4084 case elfcpp::R_390_PLT24DBL
:
4087 case elfcpp::R_390_12
:
4088 case elfcpp::R_390_GOT12
:
4089 case elfcpp::R_390_GOTPLT12
:
4090 case elfcpp::R_390_PC12DBL
:
4091 case elfcpp::R_390_PLT12DBL
:
4092 case elfcpp::R_390_16
:
4093 case elfcpp::R_390_GOT16
:
4094 case elfcpp::R_390_PC16
:
4095 case elfcpp::R_390_PC16DBL
:
4096 case elfcpp::R_390_PLT16DBL
:
4097 case elfcpp::R_390_GOTOFF16
:
4098 case elfcpp::R_390_GOTPLT16
:
4099 case elfcpp::R_390_PLTOFF16
:
4102 case elfcpp::R_390_8
:
4105 // These are relocations which should only be seen by the
4106 // dynamic linker, and should never be seen here.
4107 case elfcpp::R_390_COPY
:
4108 case elfcpp::R_390_GLOB_DAT
:
4109 case elfcpp::R_390_JMP_SLOT
:
4110 case elfcpp::R_390_RELATIVE
:
4111 case elfcpp::R_390_IRELATIVE
:
4112 case elfcpp::R_390_TLS_DTPMOD
:
4113 case elfcpp::R_390_TLS_DTPOFF
:
4114 case elfcpp::R_390_TLS_TPOFF
:
4115 object
->error(_("unexpected reloc %u in object file"), r_type
);
4119 object
->error(_("unsupported reloc %u in object file"), r_type
);
4124 // Scan the relocs during a relocatable link.
4128 Target_s390
<size
>::scan_relocatable_relocs(
4129 Symbol_table
* symtab
,
4131 Sized_relobj_file
<size
, true>* object
,
4132 unsigned int data_shndx
,
4133 unsigned int sh_type
,
4134 const unsigned char* prelocs
,
4136 Output_section
* output_section
,
4137 bool needs_special_offset_handling
,
4138 size_t local_symbol_count
,
4139 const unsigned char* plocal_symbols
,
4140 Relocatable_relocs
* rr
)
4142 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4144 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
4145 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
4147 gold::scan_relocatable_relocs
<size
, true, elfcpp::SHT_RELA
,
4148 Scan_relocatable_relocs
>(
4156 needs_special_offset_handling
,
4162 // Relocate a section during a relocatable link.
4166 Target_s390
<size
>::relocate_relocs(
4167 const Relocate_info
<size
, true>* relinfo
,
4168 unsigned int sh_type
,
4169 const unsigned char* prelocs
,
4171 Output_section
* output_section
,
4172 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
4173 unsigned char* view
,
4174 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
4175 section_size_type view_size
,
4176 unsigned char* reloc_view
,
4177 section_size_type reloc_view_size
)
4179 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4181 gold::relocate_relocs
<size
, true, elfcpp::SHT_RELA
>(
4186 offset_in_output_section
,
4194 // Return the offset to use for the GOT_INDX'th got entry which is
4195 // for a local tls symbol specified by OBJECT, SYMNDX.
4198 Target_s390
<size
>::do_tls_offset_for_local(
4203 // The only way we can get called is when IEENT/GOTIE12/GOTIE20
4204 // couldn't be optimised to LE.
4205 Output_segment
* tls_segment
= layout_
->tls_segment();
4206 return -tls_segment
->memsz();
4209 // Return the offset to use for the GOT_INDX'th got entry which is
4210 // for global tls symbol GSYM.
4213 Target_s390
<size
>::do_tls_offset_for_global(
4217 Output_segment
* tls_segment
= layout_
->tls_segment();
4218 return -tls_segment
->memsz();
4221 // Return the value to use for a dynamic which requires special
4222 // treatment. This is how we support equality comparisons of function
4223 // pointers across shared library boundaries, as described in the
4224 // processor specific ABI supplement.
4228 Target_s390
<size
>::do_dynsym_value(const Symbol
* gsym
) const
4230 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4231 return this->plt_address_for_global(gsym
);
4234 // Return a string used to fill a code section with nops to take up
4235 // the specified length.
4239 Target_s390
<size
>::do_code_fill(section_size_type length
) const
4242 gold_warning(_("S/390 code fill of odd length requested"));
4243 return std::string(length
, static_cast<char>(0x07));
4246 // Relocate section data.
4250 Target_s390
<size
>::relocate_section(
4251 const Relocate_info
<size
, true>* relinfo
,
4252 unsigned int sh_type
,
4253 const unsigned char* prelocs
,
4255 Output_section
* output_section
,
4256 bool needs_special_offset_handling
,
4257 unsigned char* view
,
4258 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4259 section_size_type view_size
,
4260 const Reloc_symbol_changes
* reloc_symbol_changes
)
4262 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4264 gold::relocate_section
<size
, true, Target_s390
<size
>, elfcpp::SHT_RELA
,
4265 typename Target_s390
<size
>::Relocate
,
4266 gold::Default_comdat_behavior
>(
4272 needs_special_offset_handling
,
4276 reloc_symbol_changes
);
4279 // Apply an incremental relocation. Incremental relocations always refer
4280 // to global symbols.
4284 Target_s390
<size
>::apply_relocation(
4285 const Relocate_info
<size
, true>* relinfo
,
4286 typename
elfcpp::Elf_types
<size
>::Elf_Addr r_offset
,
4287 unsigned int r_type
,
4288 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
,
4290 unsigned char* view
,
4291 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4292 section_size_type view_size
)
4294 gold::apply_relocation
<size
, true, Target_s390
<size
>,
4295 typename Target_s390
<size
>::Relocate
>(
4307 // The selector for s390 object files.
4310 class Target_selector_s390
: public Target_selector
4313 Target_selector_s390()
4314 : Target_selector(elfcpp::EM_S390
, size
, true,
4315 (size
== 64 ? "elf64-s390" : "elf32-s390"),
4316 (size
== 64 ? "elf64_s390" : "elf32_s390"))
4320 do_instantiate_target()
4321 { return new Target_s390
<size
>(); }
4324 Target_selector_s390
<32> target_selector_s390
;
4325 Target_selector_s390
<64> target_selector_s390x
;
4327 } // End anonymous namespace.