1 /* IBM S/390-specific support for ELF 32 and 64 bit functions
2 Copyright (C) 2000-2014 Free Software Foundation, Inc.
3 Contributed by Andreas Krebbel.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 /* Return TRUE if H is an IFUNC symbol. Simply checking for the
24 symbol type might not be enough since it might get changed to
25 STT_FUNC for pointer equality reasons. */
26 static inline bfd_boolean
27 s390_is_ifunc_symbol_p (struct elf_link_hash_entry
*h
)
29 struct elf_s390_link_hash_entry
*eh
= (struct elf_s390_link_hash_entry
*)h
;
30 return h
->type
== STT_GNU_IFUNC
|| eh
->ifunc_resolver_address
!= 0;
33 /* Create sections needed by STT_GNU_IFUNC symbol. */
36 s390_elf_create_ifunc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
40 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
41 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
43 if (htab
->iplt
!= NULL
)
46 flags
= bed
->dynamic_sec_flags
;
50 s
= bfd_make_section_with_flags (abfd
, ".rela.ifunc",
51 flags
| SEC_READONLY
);
53 || ! bfd_set_section_alignment (abfd
, s
,
54 bed
->s
->log_file_align
))
59 /* Create .iplt, .rel[a].iplt, and .igot.plt. */
60 s
= bfd_make_section_with_flags (abfd
, ".iplt",
61 flags
| SEC_CODE
| SEC_READONLY
);
63 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
67 s
= bfd_make_section_with_flags (abfd
, ".rela.iplt", flags
| SEC_READONLY
);
69 || ! bfd_set_section_alignment (abfd
, s
,
70 bed
->s
->log_file_align
))
74 s
= bfd_make_section_with_flags (abfd
, ".igot.plt", flags
);
76 || !bfd_set_section_alignment (abfd
, s
,
77 bed
->s
->log_file_align
))
85 /* Allocate space in .plt, .got and associated reloc sections for
86 dynamic relocs against a STT_GNU_IFUNC symbol definition. */
89 s390_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info
*info
,
90 struct elf_link_hash_entry
*h
,
91 struct elf_dyn_relocs
**head
)
93 struct elf_dyn_relocs
*p
;
94 struct elf_link_hash_table
*htab
;
95 struct elf_s390_link_hash_entry
*eh
= (struct elf_s390_link_hash_entry
*)h
;
97 htab
= elf_hash_table (info
);
98 eh
->ifunc_resolver_address
= h
->root
.u
.def
.value
;
99 eh
->ifunc_resolver_section
= h
->root
.u
.def
.section
;
101 /* Support garbage collection against STT_GNU_IFUNC symbols. */
102 if (h
->plt
.refcount
<= 0 && h
->got
.refcount
<= 0)
104 /* When building shared library, we need to handle the case
105 where it is marked with regular reference, but not non-GOT
106 reference. It may happen if we didn't see STT_GNU_IFUNC
107 symbol at the time when checking relocations. */
111 for (p
= *head
; p
!= NULL
; p
= p
->next
)
118 h
->got
= htab
->init_got_offset
;
119 h
->plt
= htab
->init_plt_offset
;
124 /* Return and discard space for dynamic relocations against it if
125 it is never referenced in a non-shared object. */
128 if (h
->plt
.refcount
> 0
129 || h
->got
.refcount
> 0)
131 h
->got
= htab
->init_got_offset
;
132 h
->plt
= htab
->init_plt_offset
;
138 /* Without checking h->plt.refcount here we allocate a PLT slot.
139 When setting plt.refcount in check_relocs it might not have been
140 known that this will be an IFUNC symol. */
141 h
->plt
.offset
= htab
->iplt
->size
;
143 htab
->iplt
->size
+= PLT_ENTRY_SIZE
;
144 htab
->igotplt
->size
+= GOT_ENTRY_SIZE
;
145 htab
->irelplt
->size
+= RELA_ENTRY_SIZE
;
146 htab
->irelplt
->reloc_count
++;
148 /* In order to make pointer equality work with IFUNC symbols defined
149 in a non-PIE executable and referenced in a shared lib, we turn
150 the symbol into a STT_FUNC symbol and make the symbol value to
151 point to the IPLT slot. That way the referencing shared lib will
152 always get the PLT slot address when resolving the respective
153 R_390_GLOB_DAT/R_390_64 relocs on that symbol. */
154 if (info
->executable
&& !info
->shared
&& h
->def_regular
&& h
->ref_dynamic
)
156 h
->root
.u
.def
.section
= htab
->iplt
;
157 h
->root
.u
.def
.value
= h
->plt
.offset
;
158 h
->size
= PLT_ENTRY_SIZE
;
162 /* We need dynamic relocation for STT_GNU_IFUNC symbol only when
163 there is a non-GOT reference in a shared object. */
164 if (!info
->shared
|| !h
->non_got_ref
)
167 /* Finally, allocate space. */
171 bfd_size_type count
= 0;
178 htab
->irelifunc
->size
+= count
* RELA_ENTRY_SIZE
;
181 /* Decide whether the got.iplt slot can be used. This has to be
182 avoided if the values in the GOT slots could differ for pointer
184 if (h
->got
.refcount
<= 0
186 && (h
->dynindx
== -1 || h
->forced_local
))
187 || (info
->executable
&& info
->shared
)
188 || htab
->sgot
== NULL
)
191 h
->got
.offset
= (bfd_vma
) -1;
195 h
->got
.offset
= htab
->sgot
->size
;
196 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
198 htab
->srelgot
->size
+= RELA_ENTRY_SIZE
;
205 elf_s390_allocate_local_syminfo (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
)
209 size
= symtab_hdr
->sh_info
;
210 size
*= (sizeof (bfd_signed_vma
) /* local got */
211 + sizeof (struct plt_entry
) /* local plt */
212 + sizeof(char)); /* local tls type */
213 elf_local_got_refcounts (abfd
) = ((bfd_signed_vma
*)
214 bfd_zalloc (abfd
, size
));
215 if (elf_local_got_refcounts (abfd
) == NULL
)
217 elf_s390_local_plt (abfd
)
218 = (struct plt_entry
*)(elf_local_got_refcounts (abfd
)
219 + symtab_hdr
->sh_info
);
220 elf_s390_local_got_tls_type (abfd
)
221 = (char *) (elf_s390_local_plt (abfd
) + symtab_hdr
->sh_info
);
226 /* Pick ELFOSABI_GNU if IFUNC symbols are used. */
229 elf_s390_add_symbol_hook (bfd
*abfd
,
230 struct bfd_link_info
*info
,
231 Elf_Internal_Sym
*sym
,
232 const char **namep ATTRIBUTE_UNUSED
,
233 flagword
*flagsp ATTRIBUTE_UNUSED
,
234 asection
**secp ATTRIBUTE_UNUSED
,
235 bfd_vma
*valp ATTRIBUTE_UNUSED
)
237 if ((abfd
->flags
& DYNAMIC
) == 0
238 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
239 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
This page took 0.034255 seconds and 4 git commands to generate.