Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for HP PA-RISC ELF files. |
6f2750fe | 2 | Copyright (C) 1990-2016 Free Software Foundation, Inc. |
252b5132 | 3 | |
30667bf3 | 4 | Original code by |
252b5132 RH |
5 | Center for Software Science |
6 | Department of Computer Science | |
7 | University of Utah | |
30667bf3 | 8 | Largely rewritten by Alan Modra <alan@linuxcare.com.au> |
9b52905e NC |
9 | Naming cleanup by Carlos O'Donell <carlos@systemhalted.org> |
10 | TLS support written by Randolph Chung <tausq@debian.org> | |
68ffbac6 | 11 | |
ae9a127f | 12 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 13 | |
ae9a127f NC |
14 | This program is free software; you can redistribute it and/or modify |
15 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 16 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 17 | (at your option) any later version. |
252b5132 | 18 | |
ae9a127f NC |
19 | This program is distributed in the hope that it will be useful, |
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | GNU General Public License for more details. | |
252b5132 | 23 | |
ae9a127f NC |
24 | You should have received a copy of the GNU General Public License |
25 | along with this program; if not, write to the Free Software | |
cd123cb7 NC |
26 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
27 | MA 02110-1301, USA. */ | |
252b5132 | 28 | |
252b5132 | 29 | #include "sysdep.h" |
3db64b00 | 30 | #include "bfd.h" |
252b5132 RH |
31 | #include "libbfd.h" |
32 | #include "elf-bfd.h" | |
9e103c9c JL |
33 | #include "elf/hppa.h" |
34 | #include "libhppa.h" | |
35 | #include "elf32-hppa.h" | |
36 | #define ARCH_SIZE 32 | |
edd21aca | 37 | #include "elf32-hppa.h" |
189c6563 | 38 | #include "elf-hppa.h" |
9e103c9c | 39 | |
74d1c347 AM |
40 | /* In order to gain some understanding of code in this file without |
41 | knowing all the intricate details of the linker, note the | |
42 | following: | |
43 | ||
44 | Functions named elf32_hppa_* are called by external routines, other | |
45 | functions are only called locally. elf32_hppa_* functions appear | |
46 | in this file more or less in the order in which they are called | |
47 | from external routines. eg. elf32_hppa_check_relocs is called | |
48 | early in the link process, elf32_hppa_finish_dynamic_sections is | |
49 | one of the last functions. */ | |
50 | ||
edd21aca | 51 | /* We use two hash tables to hold information for linking PA ELF objects. |
252b5132 RH |
52 | |
53 | The first is the elf32_hppa_link_hash_table which is derived | |
54 | from the standard ELF linker hash table. We use this as a place to | |
55 | attach other hash tables and static information. | |
56 | ||
57 | The second is the stub hash table which is derived from the | |
58 | base BFD hash table. The stub hash table holds the information | |
30667bf3 AM |
59 | necessary to build the linker stubs during a link. |
60 | ||
61 | There are a number of different stubs generated by the linker. | |
62 | ||
63 | Long branch stub: | |
64 | : ldil LR'X,%r1 | |
65 | : be,n RR'X(%sr4,%r1) | |
66 | ||
67 | PIC long branch stub: | |
68 | : b,l .+8,%r1 | |
3ee1d854 AM |
69 | : addil LR'X - ($PIC_pcrel$0 - 4),%r1 |
70 | : be,n RR'X - ($PIC_pcrel$0 - 8)(%sr4,%r1) | |
30667bf3 AM |
71 | |
72 | Import stub to call shared library routine from normal object file | |
73 | (single sub-space version) | |
3ee1d854 AM |
74 | : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point |
75 | : ldw RR'lt_ptr+ltoff(%r1),%r21 | |
46fe4e66 | 76 | : bv %r0(%r21) |
3ee1d854 | 77 | : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value. |
30667bf3 AM |
78 | |
79 | Import stub to call shared library routine from shared library | |
80 | (single sub-space version) | |
3ee1d854 AM |
81 | : addil LR'ltoff,%r19 ; get procedure entry point |
82 | : ldw RR'ltoff(%r1),%r21 | |
46fe4e66 | 83 | : bv %r0(%r21) |
3ee1d854 | 84 | : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value. |
30667bf3 AM |
85 | |
86 | Import stub to call shared library routine from normal object file | |
87 | (multiple sub-space support) | |
3ee1d854 AM |
88 | : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point |
89 | : ldw RR'lt_ptr+ltoff(%r1),%r21 | |
90 | : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value. | |
30667bf3 AM |
91 | : ldsid (%r21),%r1 |
92 | : mtsp %r1,%sr0 | |
93 | : be 0(%sr0,%r21) ; branch to target | |
94 | : stw %rp,-24(%sp) ; save rp | |
95 | ||
96 | Import stub to call shared library routine from shared library | |
97 | (multiple sub-space support) | |
3ee1d854 AM |
98 | : addil LR'ltoff,%r19 ; get procedure entry point |
99 | : ldw RR'ltoff(%r1),%r21 | |
100 | : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value. | |
30667bf3 AM |
101 | : ldsid (%r21),%r1 |
102 | : mtsp %r1,%sr0 | |
103 | : be 0(%sr0,%r21) ; branch to target | |
104 | : stw %rp,-24(%sp) ; save rp | |
105 | ||
106 | Export stub to return from shared lib routine (multiple sub-space support) | |
107 | One of these is created for each exported procedure in a shared | |
108 | library (and stored in the shared lib). Shared lib routines are | |
109 | called via the first instruction in the export stub so that we can | |
110 | do an inter-space return. Not required for single sub-space. | |
111 | : bl,n X,%rp ; trap the return | |
112 | : nop | |
113 | : ldw -24(%sp),%rp ; restore the original rp | |
114 | : ldsid (%rp),%r1 | |
115 | : mtsp %r1,%sr0 | |
ae9a127f | 116 | : be,n 0(%sr0,%rp) ; inter-space return. */ |
30667bf3 | 117 | |
875c0872 DA |
118 | |
119 | /* Variable names follow a coding style. | |
120 | Please follow this (Apps Hungarian) style: | |
121 | ||
122 | Structure/Variable Prefix | |
123 | elf_link_hash_table "etab" | |
124 | elf_link_hash_entry "eh" | |
68ffbac6 | 125 | |
875c0872 DA |
126 | elf32_hppa_link_hash_table "htab" |
127 | elf32_hppa_link_hash_entry "hh" | |
128 | ||
129 | bfd_hash_table "btab" | |
130 | bfd_hash_entry "bh" | |
68ffbac6 | 131 | |
875c0872 DA |
132 | bfd_hash_table containing stubs "bstab" |
133 | elf32_hppa_stub_hash_entry "hsh" | |
134 | ||
135 | elf32_hppa_dyn_reloc_entry "hdh" | |
68ffbac6 | 136 | |
875c0872 | 137 | Always remember to use GNU Coding Style. */ |
68ffbac6 | 138 | |
30667bf3 AM |
139 | #define PLT_ENTRY_SIZE 8 |
140 | #define GOT_ENTRY_SIZE 4 | |
141 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" | |
142 | ||
47d89dba AM |
143 | static const bfd_byte plt_stub[] = |
144 | { | |
145 | 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */ | |
146 | 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */ | |
147 | 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */ | |
148 | #define PLT_STUB_ENTRY (3*4) | |
149 | 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */ | |
150 | 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */ | |
151 | 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */ | |
152 | 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */ | |
153 | }; | |
154 | ||
30667bf3 | 155 | /* Section name for stubs is the associated section name plus this |
29942be8 NC |
156 | string. */ |
157 | #define STUB_SUFFIX ".stub" | |
30667bf3 | 158 | |
98ceb8ce AM |
159 | /* We don't need to copy certain PC- or GP-relative dynamic relocs |
160 | into a shared object's dynamic section. All the relocs of the | |
161 | limited class we are interested in, are absolute. */ | |
162 | #ifndef RELATIVE_DYNRELOCS | |
163 | #define RELATIVE_DYNRELOCS 0 | |
446f2863 | 164 | #define IS_ABSOLUTE_RELOC(r_type) 1 |
30667bf3 AM |
165 | #endif |
166 | ||
4fc8051d AM |
167 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
168 | copying dynamic variables from a shared lib into an app's dynbss | |
169 | section, and instead use a dynamic relocation to point into the | |
170 | shared lib. */ | |
171 | #define ELIMINATE_COPY_RELOCS 1 | |
172 | ||
9b52905e NC |
173 | enum elf32_hppa_stub_type |
174 | { | |
30667bf3 AM |
175 | hppa_stub_long_branch, |
176 | hppa_stub_long_branch_shared, | |
177 | hppa_stub_import, | |
178 | hppa_stub_import_shared, | |
179 | hppa_stub_export, | |
180 | hppa_stub_none | |
181 | }; | |
182 | ||
9b52905e NC |
183 | struct elf32_hppa_stub_hash_entry |
184 | { | |
edd21aca | 185 | /* Base hash table entry structure. */ |
a63e02c7 | 186 | struct bfd_hash_entry bh_root; |
252b5132 | 187 | |
edd21aca AM |
188 | /* The stub section. */ |
189 | asection *stub_sec; | |
190 | ||
191 | /* Offset within stub_sec of the beginning of this stub. */ | |
30667bf3 | 192 | bfd_vma stub_offset; |
252b5132 RH |
193 | |
194 | /* Given the symbol's value and its section we can determine its final | |
195 | value when building the stubs (so the stub knows where to jump. */ | |
30667bf3 | 196 | bfd_vma target_value; |
252b5132 | 197 | asection *target_section; |
30667bf3 AM |
198 | |
199 | enum elf32_hppa_stub_type stub_type; | |
200 | ||
201 | /* The symbol table entry, if any, that this was derived from. */ | |
a63e02c7 | 202 | struct elf32_hppa_link_hash_entry *hh; |
30667bf3 | 203 | |
25f72752 AM |
204 | /* Where this stub is being called from, or, in the case of combined |
205 | stub sections, the first input section in the group. */ | |
206 | asection *id_sec; | |
252b5132 RH |
207 | }; |
208 | ||
9b52905e NC |
209 | struct elf32_hppa_link_hash_entry |
210 | { | |
a63e02c7 | 211 | struct elf_link_hash_entry eh; |
30667bf3 AM |
212 | |
213 | /* A pointer to the most recently used stub hash entry against this | |
214 | symbol. */ | |
a63e02c7 | 215 | struct elf32_hppa_stub_hash_entry *hsh_cache; |
30667bf3 | 216 | |
30667bf3 AM |
217 | /* Used to count relocations for delayed sizing of relocation |
218 | sections. */ | |
9b52905e NC |
219 | struct elf32_hppa_dyn_reloc_entry |
220 | { | |
30667bf3 | 221 | /* Next relocation in the chain. */ |
a63e02c7 | 222 | struct elf32_hppa_dyn_reloc_entry *hdh_next; |
30667bf3 | 223 | |
98ceb8ce AM |
224 | /* The input section of the reloc. */ |
225 | asection *sec; | |
30667bf3 AM |
226 | |
227 | /* Number of relocs copied in this section. */ | |
228 | bfd_size_type count; | |
98ceb8ce AM |
229 | |
230 | #if RELATIVE_DYNRELOCS | |
231 | /* Number of relative relocs copied for the input section. */ | |
232 | bfd_size_type relative_count; | |
233 | #endif | |
234 | } *dyn_relocs; | |
30667bf3 | 235 | |
9b52905e NC |
236 | enum |
237 | { | |
238 | GOT_UNKNOWN = 0, GOT_NORMAL = 1, GOT_TLS_GD = 2, GOT_TLS_LDM = 4, GOT_TLS_IE = 8 | |
239 | } tls_type; | |
240 | ||
74d1c347 AM |
241 | /* Set if this symbol is used by a plabel reloc. */ |
242 | unsigned int plabel:1; | |
30667bf3 AM |
243 | }; |
244 | ||
9b52905e NC |
245 | struct elf32_hppa_link_hash_table |
246 | { | |
252b5132 | 247 | /* The main hash table. */ |
a63e02c7 | 248 | struct elf_link_hash_table etab; |
252b5132 RH |
249 | |
250 | /* The stub hash table. */ | |
a63e02c7 | 251 | struct bfd_hash_table bstab; |
252b5132 | 252 | |
30667bf3 AM |
253 | /* Linker stub bfd. */ |
254 | bfd *stub_bfd; | |
255 | ||
30667bf3 | 256 | /* Linker call-backs. */ |
c39a58e6 AM |
257 | asection * (*add_stub_section) (const char *, asection *); |
258 | void (*layout_sections_again) (void); | |
30667bf3 | 259 | |
25f72752 AM |
260 | /* Array to keep track of which stub sections have been created, and |
261 | information on stub grouping. */ | |
9b52905e NC |
262 | struct map_stub |
263 | { | |
25f72752 AM |
264 | /* This is the section to which stubs in the group will be |
265 | attached. */ | |
266 | asection *link_sec; | |
267 | /* The stub section. */ | |
268 | asection *stub_sec; | |
25f72752 | 269 | } *stub_group; |
30667bf3 | 270 | |
b4655ea9 AM |
271 | /* Assorted information used by elf32_hppa_size_stubs. */ |
272 | unsigned int bfd_count; | |
7292b3ac | 273 | unsigned int top_index; |
b4655ea9 AM |
274 | asection **input_list; |
275 | Elf_Internal_Sym **all_local_syms; | |
276 | ||
30667bf3 AM |
277 | /* Short-cuts to get to dynamic linker sections. */ |
278 | asection *sgot; | |
279 | asection *srelgot; | |
280 | asection *splt; | |
281 | asection *srelplt; | |
282 | asection *sdynbss; | |
283 | asection *srelbss; | |
47d89dba | 284 | |
c46b7515 AM |
285 | /* Used during a final link to store the base of the text and data |
286 | segments so that we can perform SEGREL relocations. */ | |
287 | bfd_vma text_segment_base; | |
288 | bfd_vma data_segment_base; | |
289 | ||
47d89dba AM |
290 | /* Whether we support multiple sub-spaces for shared libs. */ |
291 | unsigned int multi_subspace:1; | |
292 | ||
067fa4a6 | 293 | /* Flags set when various size branches are detected. Used to |
47d89dba AM |
294 | select suitable defaults for the stub group size. */ |
295 | unsigned int has_12bit_branch:1; | |
296 | unsigned int has_17bit_branch:1; | |
067fa4a6 | 297 | unsigned int has_22bit_branch:1; |
47d89dba AM |
298 | |
299 | /* Set if we need a .plt stub to support lazy dynamic linking. */ | |
300 | unsigned int need_plt_stub:1; | |
ec338859 | 301 | |
87d72d41 AM |
302 | /* Small local sym cache. */ |
303 | struct sym_cache sym_cache; | |
9b52905e NC |
304 | |
305 | /* Data for LDM relocations. */ | |
306 | union | |
307 | { | |
308 | bfd_signed_vma refcount; | |
309 | bfd_vma offset; | |
310 | } tls_ldm_got; | |
252b5132 RH |
311 | }; |
312 | ||
30667bf3 AM |
313 | /* Various hash macros and functions. */ |
314 | #define hppa_link_hash_table(p) \ | |
4dfe6ac6 NC |
315 | (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ |
316 | == HPPA32_ELF_DATA ? ((struct elf32_hppa_link_hash_table *) ((p)->hash)) : NULL) | |
252b5132 | 317 | |
875c0872 DA |
318 | #define hppa_elf_hash_entry(ent) \ |
319 | ((struct elf32_hppa_link_hash_entry *)(ent)) | |
320 | ||
321 | #define hppa_stub_hash_entry(ent) \ | |
322 | ((struct elf32_hppa_stub_hash_entry *)(ent)) | |
323 | ||
30667bf3 AM |
324 | #define hppa_stub_hash_lookup(table, string, create, copy) \ |
325 | ((struct elf32_hppa_stub_hash_entry *) \ | |
326 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
327 | ||
9b52905e NC |
328 | #define hppa_elf_local_got_tls_type(abfd) \ |
329 | ((char *)(elf_local_got_offsets (abfd) + (elf_tdata (abfd)->symtab_hdr.sh_info * 2))) | |
330 | ||
331 | #define hh_name(hh) \ | |
332 | (hh ? hh->eh.root.root.string : "<undef>") | |
333 | ||
334 | #define eh_name(eh) \ | |
335 | (eh ? eh->root.root.string : "<undef>") | |
336 | ||
252b5132 RH |
337 | /* Assorted hash table functions. */ |
338 | ||
339 | /* Initialize an entry in the stub hash table. */ | |
340 | ||
341 | static struct bfd_hash_entry * | |
c39a58e6 AM |
342 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
343 | struct bfd_hash_table *table, | |
344 | const char *string) | |
252b5132 | 345 | { |
252b5132 RH |
346 | /* Allocate the structure if it has not already been allocated by a |
347 | subclass. */ | |
ebe50bae | 348 | if (entry == NULL) |
30667bf3 | 349 | { |
ebe50bae AM |
350 | entry = bfd_hash_allocate (table, |
351 | sizeof (struct elf32_hppa_stub_hash_entry)); | |
352 | if (entry == NULL) | |
353 | return entry; | |
30667bf3 | 354 | } |
252b5132 RH |
355 | |
356 | /* Call the allocation method of the superclass. */ | |
ebe50bae AM |
357 | entry = bfd_hash_newfunc (entry, table, string); |
358 | if (entry != NULL) | |
252b5132 | 359 | { |
875c0872 | 360 | struct elf32_hppa_stub_hash_entry *hsh; |
ebe50bae | 361 | |
252b5132 | 362 | /* Initialize the local fields. */ |
875c0872 DA |
363 | hsh = hppa_stub_hash_entry (entry); |
364 | hsh->stub_sec = NULL; | |
365 | hsh->stub_offset = 0; | |
366 | hsh->target_value = 0; | |
367 | hsh->target_section = NULL; | |
368 | hsh->stub_type = hppa_stub_long_branch; | |
a63e02c7 | 369 | hsh->hh = NULL; |
875c0872 | 370 | hsh->id_sec = NULL; |
30667bf3 AM |
371 | } |
372 | ||
ebe50bae | 373 | return entry; |
30667bf3 AM |
374 | } |
375 | ||
30667bf3 AM |
376 | /* Initialize an entry in the link hash table. */ |
377 | ||
378 | static struct bfd_hash_entry * | |
c39a58e6 AM |
379 | hppa_link_hash_newfunc (struct bfd_hash_entry *entry, |
380 | struct bfd_hash_table *table, | |
381 | const char *string) | |
30667bf3 | 382 | { |
30667bf3 AM |
383 | /* Allocate the structure if it has not already been allocated by a |
384 | subclass. */ | |
ebe50bae | 385 | if (entry == NULL) |
30667bf3 | 386 | { |
ebe50bae AM |
387 | entry = bfd_hash_allocate (table, |
388 | sizeof (struct elf32_hppa_link_hash_entry)); | |
389 | if (entry == NULL) | |
390 | return entry; | |
30667bf3 AM |
391 | } |
392 | ||
393 | /* Call the allocation method of the superclass. */ | |
ebe50bae AM |
394 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); |
395 | if (entry != NULL) | |
30667bf3 | 396 | { |
875c0872 | 397 | struct elf32_hppa_link_hash_entry *hh; |
ebe50bae | 398 | |
30667bf3 | 399 | /* Initialize the local fields. */ |
875c0872 | 400 | hh = hppa_elf_hash_entry (entry); |
a63e02c7 | 401 | hh->hsh_cache = NULL; |
875c0872 DA |
402 | hh->dyn_relocs = NULL; |
403 | hh->plabel = 0; | |
9b52905e | 404 | hh->tls_type = GOT_UNKNOWN; |
252b5132 RH |
405 | } |
406 | ||
ebe50bae | 407 | return entry; |
252b5132 RH |
408 | } |
409 | ||
68faa637 AM |
410 | /* Free the derived linker hash table. */ |
411 | ||
412 | static void | |
d495ab0d | 413 | elf32_hppa_link_hash_table_free (bfd *obfd) |
68faa637 AM |
414 | { |
415 | struct elf32_hppa_link_hash_table *htab | |
d495ab0d | 416 | = (struct elf32_hppa_link_hash_table *) obfd->link.hash; |
68faa637 AM |
417 | |
418 | bfd_hash_table_free (&htab->bstab); | |
d495ab0d | 419 | _bfd_elf_link_hash_table_free (obfd); |
68faa637 AM |
420 | } |
421 | ||
252b5132 RH |
422 | /* Create the derived linker hash table. The PA ELF port uses the derived |
423 | hash table to keep information specific to the PA ELF linker (without | |
424 | using static variables). */ | |
425 | ||
426 | static struct bfd_link_hash_table * | |
c39a58e6 | 427 | elf32_hppa_link_hash_table_create (bfd *abfd) |
252b5132 | 428 | { |
875c0872 DA |
429 | struct elf32_hppa_link_hash_table *htab; |
430 | bfd_size_type amt = sizeof (*htab); | |
252b5132 | 431 | |
7bf52ea2 | 432 | htab = bfd_zmalloc (amt); |
875c0872 | 433 | if (htab == NULL) |
252b5132 | 434 | return NULL; |
edd21aca | 435 | |
66eb6687 | 436 | if (!_bfd_elf_link_hash_table_init (&htab->etab, abfd, hppa_link_hash_newfunc, |
4dfe6ac6 NC |
437 | sizeof (struct elf32_hppa_link_hash_entry), |
438 | HPPA32_ELF_DATA)) | |
252b5132 | 439 | { |
875c0872 | 440 | free (htab); |
252b5132 RH |
441 | return NULL; |
442 | } | |
edd21aca AM |
443 | |
444 | /* Init the stub hash table too. */ | |
66eb6687 AM |
445 | if (!bfd_hash_table_init (&htab->bstab, stub_hash_newfunc, |
446 | sizeof (struct elf32_hppa_stub_hash_entry))) | |
d495ab0d AM |
447 | { |
448 | _bfd_elf_link_hash_table_free (abfd); | |
449 | return NULL; | |
450 | } | |
451 | htab->etab.root.hash_table_free = elf32_hppa_link_hash_table_free; | |
edd21aca | 452 | |
875c0872 DA |
453 | htab->text_segment_base = (bfd_vma) -1; |
454 | htab->data_segment_base = (bfd_vma) -1; | |
a63e02c7 | 455 | return &htab->etab.root; |
252b5132 RH |
456 | } |
457 | ||
a464198b AM |
458 | /* Initialize the linker stubs BFD so that we can use it for linker |
459 | created dynamic sections. */ | |
460 | ||
461 | void | |
462 | elf32_hppa_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) | |
463 | { | |
464 | struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); | |
465 | ||
466 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS32; | |
467 | htab->etab.dynobj = abfd; | |
468 | } | |
469 | ||
30667bf3 AM |
470 | /* Build a name for an entry in the stub hash table. */ |
471 | ||
edd21aca | 472 | static char * |
c39a58e6 AM |
473 | hppa_stub_name (const asection *input_section, |
474 | const asection *sym_sec, | |
875c0872 DA |
475 | const struct elf32_hppa_link_hash_entry *hh, |
476 | const Elf_Internal_Rela *rela) | |
edd21aca AM |
477 | { |
478 | char *stub_name; | |
dc810e39 | 479 | bfd_size_type len; |
edd21aca | 480 | |
875c0872 | 481 | if (hh) |
30667bf3 | 482 | { |
9b52905e | 483 | len = 8 + 1 + strlen (hh_name (hh)) + 1 + 8 + 1; |
30667bf3 AM |
484 | stub_name = bfd_malloc (len); |
485 | if (stub_name != NULL) | |
9b52905e NC |
486 | sprintf (stub_name, "%08x_%s+%x", |
487 | input_section->id & 0xffffffff, | |
488 | hh_name (hh), | |
489 | (int) rela->r_addend & 0xffffffff); | |
30667bf3 AM |
490 | } |
491 | else | |
edd21aca | 492 | { |
30667bf3 AM |
493 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
494 | stub_name = bfd_malloc (len); | |
495 | if (stub_name != NULL) | |
9b52905e NC |
496 | sprintf (stub_name, "%08x_%x:%x+%x", |
497 | input_section->id & 0xffffffff, | |
498 | sym_sec->id & 0xffffffff, | |
499 | (int) ELF32_R_SYM (rela->r_info) & 0xffffffff, | |
500 | (int) rela->r_addend & 0xffffffff); | |
edd21aca AM |
501 | } |
502 | return stub_name; | |
503 | } | |
252b5132 | 504 | |
30667bf3 AM |
505 | /* Look up an entry in the stub hash. Stub entries are cached because |
506 | creating the stub name takes a bit of time. */ | |
507 | ||
508 | static struct elf32_hppa_stub_hash_entry * | |
c39a58e6 AM |
509 | hppa_get_stub_entry (const asection *input_section, |
510 | const asection *sym_sec, | |
875c0872 DA |
511 | struct elf32_hppa_link_hash_entry *hh, |
512 | const Elf_Internal_Rela *rela, | |
c39a58e6 | 513 | struct elf32_hppa_link_hash_table *htab) |
252b5132 | 514 | { |
a63e02c7 | 515 | struct elf32_hppa_stub_hash_entry *hsh_entry; |
25f72752 AM |
516 | const asection *id_sec; |
517 | ||
518 | /* If this input section is part of a group of sections sharing one | |
519 | stub section, then use the id of the first section in the group. | |
520 | Stub names need to include a section id, as there may well be | |
521 | more than one stub used to reach say, printf, and we need to | |
522 | distinguish between them. */ | |
83c81bfe | 523 | id_sec = htab->stub_group[input_section->id].link_sec; |
edd21aca | 524 | |
a63e02c7 DA |
525 | if (hh != NULL && hh->hsh_cache != NULL |
526 | && hh->hsh_cache->hh == hh | |
527 | && hh->hsh_cache->id_sec == id_sec) | |
edd21aca | 528 | { |
a63e02c7 | 529 | hsh_entry = hh->hsh_cache; |
30667bf3 AM |
530 | } |
531 | else | |
532 | { | |
30667bf3 | 533 | char *stub_name; |
edd21aca | 534 | |
875c0872 | 535 | stub_name = hppa_stub_name (id_sec, sym_sec, hh, rela); |
30667bf3 AM |
536 | if (stub_name == NULL) |
537 | return NULL; | |
edd21aca | 538 | |
a63e02c7 | 539 | hsh_entry = hppa_stub_hash_lookup (&htab->bstab, |
b34976b6 | 540 | stub_name, FALSE, FALSE); |
875c0872 | 541 | if (hh != NULL) |
a63e02c7 | 542 | hh->hsh_cache = hsh_entry; |
30667bf3 AM |
543 | |
544 | free (stub_name); | |
edd21aca | 545 | } |
30667bf3 | 546 | |
a63e02c7 | 547 | return hsh_entry; |
30667bf3 AM |
548 | } |
549 | ||
30667bf3 AM |
550 | /* Add a new stub entry to the stub hash. Not all fields of the new |
551 | stub entry are initialised. */ | |
552 | ||
553 | static struct elf32_hppa_stub_hash_entry * | |
c39a58e6 AM |
554 | hppa_add_stub (const char *stub_name, |
555 | asection *section, | |
556 | struct elf32_hppa_link_hash_table *htab) | |
30667bf3 | 557 | { |
25f72752 | 558 | asection *link_sec; |
30667bf3 | 559 | asection *stub_sec; |
875c0872 | 560 | struct elf32_hppa_stub_hash_entry *hsh; |
edd21aca | 561 | |
83c81bfe AM |
562 | link_sec = htab->stub_group[section->id].link_sec; |
563 | stub_sec = htab->stub_group[section->id].stub_sec; | |
30667bf3 | 564 | if (stub_sec == NULL) |
edd21aca | 565 | { |
83c81bfe | 566 | stub_sec = htab->stub_group[link_sec->id].stub_sec; |
30667bf3 AM |
567 | if (stub_sec == NULL) |
568 | { | |
d4c88bbb | 569 | size_t namelen; |
dc810e39 | 570 | bfd_size_type len; |
30667bf3 AM |
571 | char *s_name; |
572 | ||
d4c88bbb AM |
573 | namelen = strlen (link_sec->name); |
574 | len = namelen + sizeof (STUB_SUFFIX); | |
83c81bfe | 575 | s_name = bfd_alloc (htab->stub_bfd, len); |
30667bf3 AM |
576 | if (s_name == NULL) |
577 | return NULL; | |
578 | ||
d4c88bbb AM |
579 | memcpy (s_name, link_sec->name, namelen); |
580 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
83c81bfe | 581 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
30667bf3 AM |
582 | if (stub_sec == NULL) |
583 | return NULL; | |
83c81bfe | 584 | htab->stub_group[link_sec->id].stub_sec = stub_sec; |
30667bf3 | 585 | } |
83c81bfe | 586 | htab->stub_group[section->id].stub_sec = stub_sec; |
edd21aca | 587 | } |
252b5132 | 588 | |
30667bf3 | 589 | /* Enter this entry into the linker stub hash table. */ |
a63e02c7 | 590 | hsh = hppa_stub_hash_lookup (&htab->bstab, stub_name, |
b34976b6 | 591 | TRUE, FALSE); |
875c0872 | 592 | if (hsh == NULL) |
30667bf3 | 593 | { |
d003868e AM |
594 | (*_bfd_error_handler) (_("%B: cannot create stub entry %s"), |
595 | section->owner, | |
30667bf3 AM |
596 | stub_name); |
597 | return NULL; | |
edd21aca AM |
598 | } |
599 | ||
875c0872 DA |
600 | hsh->stub_sec = stub_sec; |
601 | hsh->stub_offset = 0; | |
602 | hsh->id_sec = link_sec; | |
603 | return hsh; | |
edd21aca AM |
604 | } |
605 | ||
30667bf3 AM |
606 | /* Determine the type of stub needed, if any, for a call. */ |
607 | ||
608 | static enum elf32_hppa_stub_type | |
c39a58e6 | 609 | hppa_type_of_stub (asection *input_sec, |
875c0872 DA |
610 | const Elf_Internal_Rela *rela, |
611 | struct elf32_hppa_link_hash_entry *hh, | |
a252afa4 DA |
612 | bfd_vma destination, |
613 | struct bfd_link_info *info) | |
edd21aca | 614 | { |
edd21aca | 615 | bfd_vma location; |
30667bf3 AM |
616 | bfd_vma branch_offset; |
617 | bfd_vma max_branch_offset; | |
618 | unsigned int r_type; | |
619 | ||
875c0872 | 620 | if (hh != NULL |
a63e02c7 DA |
621 | && hh->eh.plt.offset != (bfd_vma) -1 |
622 | && hh->eh.dynindx != -1 | |
875c0872 | 623 | && !hh->plabel |
0e1862bb | 624 | && (bfd_link_pic (info) |
a63e02c7 DA |
625 | || !hh->eh.def_regular |
626 | || hh->eh.root.type == bfd_link_hash_defweak)) | |
30667bf3 | 627 | { |
067fa4a6 AM |
628 | /* We need an import stub. Decide between hppa_stub_import |
629 | and hppa_stub_import_shared later. */ | |
30667bf3 AM |
630 | return hppa_stub_import; |
631 | } | |
edd21aca | 632 | |
30667bf3 AM |
633 | /* Determine where the call point is. */ |
634 | location = (input_sec->output_offset | |
635 | + input_sec->output_section->vma | |
875c0872 | 636 | + rela->r_offset); |
edd21aca | 637 | |
30667bf3 | 638 | branch_offset = destination - location - 8; |
875c0872 | 639 | r_type = ELF32_R_TYPE (rela->r_info); |
edd21aca | 640 | |
30667bf3 AM |
641 | /* Determine if a long branch stub is needed. parisc branch offsets |
642 | are relative to the second instruction past the branch, ie. +8 | |
643 | bytes on from the branch instruction location. The offset is | |
644 | signed and counts in units of 4 bytes. */ | |
645 | if (r_type == (unsigned int) R_PARISC_PCREL17F) | |
9b52905e NC |
646 | max_branch_offset = (1 << (17 - 1)) << 2; |
647 | ||
30667bf3 | 648 | else if (r_type == (unsigned int) R_PARISC_PCREL12F) |
9b52905e NC |
649 | max_branch_offset = (1 << (12 - 1)) << 2; |
650 | ||
25f72752 | 651 | else /* R_PARISC_PCREL22F. */ |
9b52905e | 652 | max_branch_offset = (1 << (22 - 1)) << 2; |
edd21aca | 653 | |
30667bf3 | 654 | if (branch_offset + max_branch_offset >= 2*max_branch_offset) |
98ceb8ce AM |
655 | return hppa_stub_long_branch; |
656 | ||
30667bf3 AM |
657 | return hppa_stub_none; |
658 | } | |
edd21aca | 659 | |
30667bf3 AM |
660 | /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY. |
661 | IN_ARG contains the link info pointer. */ | |
edd21aca | 662 | |
30667bf3 AM |
663 | #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */ |
664 | #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */ | |
edd21aca | 665 | |
30667bf3 | 666 | #define BL_R1 0xe8200000 /* b,l .+8,%r1 */ |
3ee1d854 | 667 | #define ADDIL_R1 0x28200000 /* addil LR'XXX,%r1,%r1 */ |
30667bf3 | 668 | #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */ |
252b5132 | 669 | |
3ee1d854 AM |
670 | #define ADDIL_DP 0x2b600000 /* addil LR'XXX,%dp,%r1 */ |
671 | #define LDW_R1_R21 0x48350000 /* ldw RR'XXX(%sr0,%r1),%r21 */ | |
30667bf3 | 672 | #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */ |
3ee1d854 | 673 | #define LDW_R1_R19 0x48330000 /* ldw RR'XXX(%sr0,%r1),%r19 */ |
252b5132 | 674 | |
3ee1d854 AM |
675 | #define ADDIL_R19 0x2a600000 /* addil LR'XXX,%r19,%r1 */ |
676 | #define LDW_R1_DP 0x483b0000 /* ldw RR'XXX(%sr0,%r1),%dp */ | |
edd21aca | 677 | |
30667bf3 AM |
678 | #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */ |
679 | #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */ | |
680 | #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */ | |
681 | #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */ | |
edd21aca | 682 | |
067fa4a6 | 683 | #define BL22_RP 0xe800a002 /* b,l,n XXX,%rp */ |
30667bf3 AM |
684 | #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */ |
685 | #define NOP 0x08000240 /* nop */ | |
686 | #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */ | |
687 | #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */ | |
688 | #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */ | |
edd21aca | 689 | |
30667bf3 AM |
690 | #ifndef R19_STUBS |
691 | #define R19_STUBS 1 | |
692 | #endif | |
edd21aca | 693 | |
30667bf3 AM |
694 | #if R19_STUBS |
695 | #define LDW_R1_DLT LDW_R1_R19 | |
696 | #else | |
697 | #define LDW_R1_DLT LDW_R1_DP | |
698 | #endif | |
edd21aca | 699 | |
b34976b6 | 700 | static bfd_boolean |
875c0872 | 701 | hppa_build_one_stub (struct bfd_hash_entry *bh, void *in_arg) |
30667bf3 | 702 | { |
875c0872 | 703 | struct elf32_hppa_stub_hash_entry *hsh; |
30667bf3 | 704 | struct bfd_link_info *info; |
83c81bfe | 705 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 AM |
706 | asection *stub_sec; |
707 | bfd *stub_bfd; | |
708 | bfd_byte *loc; | |
709 | bfd_vma sym_value; | |
74d1c347 | 710 | bfd_vma insn; |
8dea1268 | 711 | bfd_vma off; |
74d1c347 | 712 | int val; |
30667bf3 | 713 | int size; |
edd21aca | 714 | |
30667bf3 | 715 | /* Massage our args to the form they really have. */ |
875c0872 DA |
716 | hsh = hppa_stub_hash_entry (bh); |
717 | info = (struct bfd_link_info *)in_arg; | |
30667bf3 | 718 | |
83c81bfe | 719 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
720 | if (htab == NULL) |
721 | return FALSE; | |
722 | ||
875c0872 | 723 | stub_sec = hsh->stub_sec; |
edd21aca | 724 | |
30667bf3 | 725 | /* Make a note of the offset within the stubs for this entry. */ |
875c0872 DA |
726 | hsh->stub_offset = stub_sec->size; |
727 | loc = stub_sec->contents + hsh->stub_offset; | |
252b5132 | 728 | |
30667bf3 AM |
729 | stub_bfd = stub_sec->owner; |
730 | ||
875c0872 | 731 | switch (hsh->stub_type) |
30667bf3 AM |
732 | { |
733 | case hppa_stub_long_branch: | |
734 | /* Create the long branch. A long branch is formed with "ldil" | |
735 | loading the upper bits of the target address into a register, | |
736 | then branching with "be" which adds in the lower bits. | |
737 | The "be" has its delay slot nullified. */ | |
875c0872 DA |
738 | sym_value = (hsh->target_value |
739 | + hsh->target_section->output_offset | |
740 | + hsh->target_section->output_section->vma); | |
30667bf3 | 741 | |
c39a58e6 | 742 | val = hppa_field_adjust (sym_value, 0, e_lrsel); |
74d1c347 | 743 | insn = hppa_rebuild_insn ((int) LDIL_R1, val, 21); |
30667bf3 AM |
744 | bfd_put_32 (stub_bfd, insn, loc); |
745 | ||
c39a58e6 | 746 | val = hppa_field_adjust (sym_value, 0, e_rrsel) >> 2; |
74d1c347 | 747 | insn = hppa_rebuild_insn ((int) BE_SR4_R1, val, 17); |
30667bf3 AM |
748 | bfd_put_32 (stub_bfd, insn, loc + 4); |
749 | ||
30667bf3 | 750 | size = 8; |
edd21aca AM |
751 | break; |
752 | ||
30667bf3 AM |
753 | case hppa_stub_long_branch_shared: |
754 | /* Branches are relative. This is where we are going to. */ | |
875c0872 DA |
755 | sym_value = (hsh->target_value |
756 | + hsh->target_section->output_offset | |
757 | + hsh->target_section->output_section->vma); | |
30667bf3 AM |
758 | |
759 | /* And this is where we are coming from, more or less. */ | |
875c0872 | 760 | sym_value -= (hsh->stub_offset |
30667bf3 AM |
761 | + stub_sec->output_offset |
762 | + stub_sec->output_section->vma); | |
763 | ||
74d1c347 | 764 | bfd_put_32 (stub_bfd, (bfd_vma) BL_R1, loc); |
47d89dba | 765 | val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_lrsel); |
74d1c347 | 766 | insn = hppa_rebuild_insn ((int) ADDIL_R1, val, 21); |
30667bf3 AM |
767 | bfd_put_32 (stub_bfd, insn, loc + 4); |
768 | ||
47d89dba | 769 | val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_rrsel) >> 2; |
74d1c347 | 770 | insn = hppa_rebuild_insn ((int) BE_SR4_R1, val, 17); |
30667bf3 AM |
771 | bfd_put_32 (stub_bfd, insn, loc + 8); |
772 | size = 12; | |
773 | break; | |
edd21aca | 774 | |
30667bf3 AM |
775 | case hppa_stub_import: |
776 | case hppa_stub_import_shared: | |
a63e02c7 | 777 | off = hsh->hh->eh.plt.offset; |
8dea1268 | 778 | if (off >= (bfd_vma) -2) |
49e9d0d3 | 779 | abort (); |
8dea1268 AM |
780 | |
781 | off &= ~ (bfd_vma) 1; | |
782 | sym_value = (off | |
83c81bfe AM |
783 | + htab->splt->output_offset |
784 | + htab->splt->output_section->vma | |
785 | - elf_gp (htab->splt->output_section->owner)); | |
30667bf3 AM |
786 | |
787 | insn = ADDIL_DP; | |
788 | #if R19_STUBS | |
875c0872 | 789 | if (hsh->stub_type == hppa_stub_import_shared) |
30667bf3 AM |
790 | insn = ADDIL_R19; |
791 | #endif | |
c39a58e6 | 792 | val = hppa_field_adjust (sym_value, 0, e_lrsel), |
74d1c347 | 793 | insn = hppa_rebuild_insn ((int) insn, val, 21); |
30667bf3 | 794 | bfd_put_32 (stub_bfd, insn, loc); |
edd21aca | 795 | |
47d89dba AM |
796 | /* It is critical to use lrsel/rrsel here because we are using |
797 | two different offsets (+0 and +4) from sym_value. If we use | |
798 | lsel/rsel then with unfortunate sym_values we will round | |
799 | sym_value+4 up to the next 2k block leading to a mis-match | |
800 | between the lsel and rsel value. */ | |
c39a58e6 | 801 | val = hppa_field_adjust (sym_value, 0, e_rrsel); |
74d1c347 | 802 | insn = hppa_rebuild_insn ((int) LDW_R1_R21, val, 14); |
30667bf3 | 803 | bfd_put_32 (stub_bfd, insn, loc + 4); |
252b5132 | 804 | |
83c81bfe | 805 | if (htab->multi_subspace) |
30667bf3 | 806 | { |
47d89dba | 807 | val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel); |
74d1c347 | 808 | insn = hppa_rebuild_insn ((int) LDW_R1_DLT, val, 14); |
30667bf3 | 809 | bfd_put_32 (stub_bfd, insn, loc + 8); |
252b5132 | 810 | |
74d1c347 AM |
811 | bfd_put_32 (stub_bfd, (bfd_vma) LDSID_R21_R1, loc + 12); |
812 | bfd_put_32 (stub_bfd, (bfd_vma) MTSP_R1, loc + 16); | |
813 | bfd_put_32 (stub_bfd, (bfd_vma) BE_SR0_R21, loc + 20); | |
814 | bfd_put_32 (stub_bfd, (bfd_vma) STW_RP, loc + 24); | |
252b5132 | 815 | |
30667bf3 AM |
816 | size = 28; |
817 | } | |
818 | else | |
819 | { | |
74d1c347 | 820 | bfd_put_32 (stub_bfd, (bfd_vma) BV_R0_R21, loc + 8); |
47d89dba | 821 | val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel); |
74d1c347 | 822 | insn = hppa_rebuild_insn ((int) LDW_R1_DLT, val, 14); |
30667bf3 | 823 | bfd_put_32 (stub_bfd, insn, loc + 12); |
252b5132 | 824 | |
30667bf3 AM |
825 | size = 16; |
826 | } | |
252b5132 | 827 | |
30667bf3 | 828 | break; |
252b5132 | 829 | |
30667bf3 AM |
830 | case hppa_stub_export: |
831 | /* Branches are relative. This is where we are going to. */ | |
875c0872 DA |
832 | sym_value = (hsh->target_value |
833 | + hsh->target_section->output_offset | |
834 | + hsh->target_section->output_section->vma); | |
252b5132 | 835 | |
30667bf3 | 836 | /* And this is where we are coming from. */ |
875c0872 | 837 | sym_value -= (hsh->stub_offset |
30667bf3 AM |
838 | + stub_sec->output_offset |
839 | + stub_sec->output_section->vma); | |
edd21aca | 840 | |
067fa4a6 AM |
841 | if (sym_value - 8 + (1 << (17 + 1)) >= (1 << (17 + 2)) |
842 | && (!htab->has_22bit_branch | |
843 | || sym_value - 8 + (1 << (22 + 1)) >= (1 << (22 + 2)))) | |
30667bf3 | 844 | { |
edd21aca | 845 | (*_bfd_error_handler) |
d003868e | 846 | (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"), |
875c0872 | 847 | hsh->target_section->owner, |
d003868e | 848 | stub_sec, |
875c0872 | 849 | (long) hsh->stub_offset, |
a63e02c7 | 850 | hsh->bh_root.string); |
30667bf3 | 851 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 852 | return FALSE; |
252b5132 | 853 | } |
30667bf3 | 854 | |
74d1c347 | 855 | val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_fsel) >> 2; |
067fa4a6 AM |
856 | if (!htab->has_22bit_branch) |
857 | insn = hppa_rebuild_insn ((int) BL_RP, val, 17); | |
858 | else | |
859 | insn = hppa_rebuild_insn ((int) BL22_RP, val, 22); | |
30667bf3 AM |
860 | bfd_put_32 (stub_bfd, insn, loc); |
861 | ||
74d1c347 AM |
862 | bfd_put_32 (stub_bfd, (bfd_vma) NOP, loc + 4); |
863 | bfd_put_32 (stub_bfd, (bfd_vma) LDW_RP, loc + 8); | |
864 | bfd_put_32 (stub_bfd, (bfd_vma) LDSID_RP_R1, loc + 12); | |
865 | bfd_put_32 (stub_bfd, (bfd_vma) MTSP_R1, loc + 16); | |
866 | bfd_put_32 (stub_bfd, (bfd_vma) BE_SR0_RP, loc + 20); | |
30667bf3 AM |
867 | |
868 | /* Point the function symbol at the stub. */ | |
a63e02c7 DA |
869 | hsh->hh->eh.root.u.def.section = stub_sec; |
870 | hsh->hh->eh.root.u.def.value = stub_sec->size; | |
30667bf3 AM |
871 | |
872 | size = 24; | |
873 | break; | |
874 | ||
875 | default: | |
876 | BFD_FAIL (); | |
b34976b6 | 877 | return FALSE; |
252b5132 RH |
878 | } |
879 | ||
eea6121a | 880 | stub_sec->size += size; |
b34976b6 | 881 | return TRUE; |
252b5132 RH |
882 | } |
883 | ||
30667bf3 AM |
884 | #undef LDIL_R1 |
885 | #undef BE_SR4_R1 | |
886 | #undef BL_R1 | |
887 | #undef ADDIL_R1 | |
888 | #undef DEPI_R1 | |
30667bf3 AM |
889 | #undef LDW_R1_R21 |
890 | #undef LDW_R1_DLT | |
891 | #undef LDW_R1_R19 | |
892 | #undef ADDIL_R19 | |
893 | #undef LDW_R1_DP | |
894 | #undef LDSID_R21_R1 | |
895 | #undef MTSP_R1 | |
896 | #undef BE_SR0_R21 | |
897 | #undef STW_RP | |
898 | #undef BV_R0_R21 | |
899 | #undef BL_RP | |
900 | #undef NOP | |
901 | #undef LDW_RP | |
902 | #undef LDSID_RP_R1 | |
903 | #undef BE_SR0_RP | |
252b5132 | 904 | |
30667bf3 AM |
905 | /* As above, but don't actually build the stub. Just bump offset so |
906 | we know stub section sizes. */ | |
907 | ||
b34976b6 | 908 | static bfd_boolean |
875c0872 | 909 | hppa_size_one_stub (struct bfd_hash_entry *bh, void *in_arg) |
252b5132 | 910 | { |
875c0872 | 911 | struct elf32_hppa_stub_hash_entry *hsh; |
83c81bfe | 912 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 AM |
913 | int size; |
914 | ||
915 | /* Massage our args to the form they really have. */ | |
875c0872 | 916 | hsh = hppa_stub_hash_entry (bh); |
c39a58e6 | 917 | htab = in_arg; |
30667bf3 | 918 | |
875c0872 | 919 | if (hsh->stub_type == hppa_stub_long_branch) |
98ceb8ce | 920 | size = 8; |
875c0872 | 921 | else if (hsh->stub_type == hppa_stub_long_branch_shared) |
30667bf3 | 922 | size = 12; |
875c0872 | 923 | else if (hsh->stub_type == hppa_stub_export) |
30667bf3 | 924 | size = 24; |
74d1c347 | 925 | else /* hppa_stub_import or hppa_stub_import_shared. */ |
252b5132 | 926 | { |
83c81bfe | 927 | if (htab->multi_subspace) |
30667bf3 AM |
928 | size = 28; |
929 | else | |
930 | size = 16; | |
931 | } | |
252b5132 | 932 | |
875c0872 | 933 | hsh->stub_sec->size += size; |
b34976b6 | 934 | return TRUE; |
30667bf3 | 935 | } |
252b5132 | 936 | |
30667bf3 AM |
937 | /* Return nonzero if ABFD represents an HPPA ELF32 file. |
938 | Additionally we set the default architecture and machine. */ | |
939 | ||
b34976b6 | 940 | static bfd_boolean |
c39a58e6 | 941 | elf32_hppa_object_p (bfd *abfd) |
30667bf3 | 942 | { |
24a5e751 L |
943 | Elf_Internal_Ehdr * i_ehdrp; |
944 | unsigned int flags; | |
252b5132 | 945 | |
24a5e751 L |
946 | i_ehdrp = elf_elfheader (abfd); |
947 | if (strcmp (bfd_get_target (abfd), "elf32-hppa-linux") == 0) | |
948 | { | |
9c55345c | 949 | /* GCC on hppa-linux produces binaries with OSABI=GNU, |
6c21aa76 | 950 | but the kernel produces corefiles with OSABI=SysV. */ |
9c55345c | 951 | if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_GNU && |
6c21aa76 | 952 | i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */ |
b34976b6 | 953 | return FALSE; |
24a5e751 | 954 | } |
225247f0 JT |
955 | else if (strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") == 0) |
956 | { | |
957 | /* GCC on hppa-netbsd produces binaries with OSABI=NetBSD, | |
958 | but the kernel produces corefiles with OSABI=SysV. */ | |
959 | if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NETBSD && | |
960 | i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */ | |
961 | return FALSE; | |
962 | } | |
24a5e751 L |
963 | else |
964 | { | |
965 | if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX) | |
b34976b6 | 966 | return FALSE; |
24a5e751 L |
967 | } |
968 | ||
969 | flags = i_ehdrp->e_flags; | |
30667bf3 AM |
970 | switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE)) |
971 | { | |
972 | case EFA_PARISC_1_0: | |
973 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10); | |
974 | case EFA_PARISC_1_1: | |
975 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11); | |
976 | case EFA_PARISC_2_0: | |
977 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20); | |
978 | case EFA_PARISC_2_0 | EF_PARISC_WIDE: | |
979 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25); | |
980 | } | |
b34976b6 | 981 | return TRUE; |
252b5132 RH |
982 | } |
983 | ||
30667bf3 AM |
984 | /* Create the .plt and .got sections, and set up our hash table |
985 | short-cuts to various dynamic sections. */ | |
986 | ||
b34976b6 | 987 | static bfd_boolean |
c39a58e6 | 988 | elf32_hppa_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) |
252b5132 | 989 | { |
83c81bfe | 990 | struct elf32_hppa_link_hash_table *htab; |
875c0872 | 991 | struct elf_link_hash_entry *eh; |
edd21aca | 992 | |
30667bf3 | 993 | /* Don't try to create the .plt and .got twice. */ |
83c81bfe | 994 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
995 | if (htab == NULL) |
996 | return FALSE; | |
83c81bfe | 997 | if (htab->splt != NULL) |
b34976b6 | 998 | return TRUE; |
edd21aca | 999 | |
30667bf3 AM |
1000 | /* Call the generic code to do most of the work. */ |
1001 | if (! _bfd_elf_create_dynamic_sections (abfd, info)) | |
b34976b6 | 1002 | return FALSE; |
252b5132 | 1003 | |
3d4d4302 AM |
1004 | htab->splt = bfd_get_linker_section (abfd, ".plt"); |
1005 | htab->srelplt = bfd_get_linker_section (abfd, ".rela.plt"); | |
30667bf3 | 1006 | |
3d4d4302 AM |
1007 | htab->sgot = bfd_get_linker_section (abfd, ".got"); |
1008 | htab->srelgot = bfd_get_linker_section (abfd, ".rela.got"); | |
edd21aca | 1009 | |
3d4d4302 AM |
1010 | htab->sdynbss = bfd_get_linker_section (abfd, ".dynbss"); |
1011 | htab->srelbss = bfd_get_linker_section (abfd, ".rela.bss"); | |
30667bf3 | 1012 | |
b18e2ae5 AM |
1013 | /* hppa-linux needs _GLOBAL_OFFSET_TABLE_ to be visible from the main |
1014 | application, because __canonicalize_funcptr_for_compare needs it. */ | |
875c0872 DA |
1015 | eh = elf_hash_table (info)->hgot; |
1016 | eh->forced_local = 0; | |
1017 | eh->other = STV_DEFAULT; | |
1018 | return bfd_elf_link_record_dynamic_symbol (info, eh); | |
30667bf3 AM |
1019 | } |
1020 | ||
ebe50bae AM |
1021 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
1022 | ||
51b64d56 | 1023 | static void |
fcfa13d2 | 1024 | elf32_hppa_copy_indirect_symbol (struct bfd_link_info *info, |
875c0872 DA |
1025 | struct elf_link_hash_entry *eh_dir, |
1026 | struct elf_link_hash_entry *eh_ind) | |
ebe50bae | 1027 | { |
875c0872 | 1028 | struct elf32_hppa_link_hash_entry *hh_dir, *hh_ind; |
ebe50bae | 1029 | |
875c0872 DA |
1030 | hh_dir = hppa_elf_hash_entry (eh_dir); |
1031 | hh_ind = hppa_elf_hash_entry (eh_ind); | |
ebe50bae | 1032 | |
875c0872 | 1033 | if (hh_ind->dyn_relocs != NULL) |
ebe50bae | 1034 | { |
875c0872 | 1035 | if (hh_dir->dyn_relocs != NULL) |
bbd7ec4a | 1036 | { |
875c0872 DA |
1037 | struct elf32_hppa_dyn_reloc_entry **hdh_pp; |
1038 | struct elf32_hppa_dyn_reloc_entry *hdh_p; | |
bbd7ec4a | 1039 | |
fcfa13d2 | 1040 | /* Add reloc counts against the indirect sym to the direct sym |
bbd7ec4a | 1041 | list. Merge any entries against the same section. */ |
875c0872 | 1042 | for (hdh_pp = &hh_ind->dyn_relocs; (hdh_p = *hdh_pp) != NULL; ) |
bbd7ec4a | 1043 | { |
875c0872 | 1044 | struct elf32_hppa_dyn_reloc_entry *hdh_q; |
bbd7ec4a | 1045 | |
fcfa13d2 AM |
1046 | for (hdh_q = hh_dir->dyn_relocs; |
1047 | hdh_q != NULL; | |
1048 | hdh_q = hdh_q->hdh_next) | |
875c0872 | 1049 | if (hdh_q->sec == hdh_p->sec) |
bbd7ec4a AM |
1050 | { |
1051 | #if RELATIVE_DYNRELOCS | |
875c0872 | 1052 | hdh_q->relative_count += hdh_p->relative_count; |
bbd7ec4a | 1053 | #endif |
875c0872 | 1054 | hdh_q->count += hdh_p->count; |
a63e02c7 | 1055 | *hdh_pp = hdh_p->hdh_next; |
bbd7ec4a AM |
1056 | break; |
1057 | } | |
875c0872 | 1058 | if (hdh_q == NULL) |
a63e02c7 | 1059 | hdh_pp = &hdh_p->hdh_next; |
bbd7ec4a | 1060 | } |
875c0872 | 1061 | *hdh_pp = hh_dir->dyn_relocs; |
bbd7ec4a AM |
1062 | } |
1063 | ||
875c0872 DA |
1064 | hh_dir->dyn_relocs = hh_ind->dyn_relocs; |
1065 | hh_ind->dyn_relocs = NULL; | |
ebe50bae | 1066 | } |
ebe50bae | 1067 | |
4fc8051d | 1068 | if (ELIMINATE_COPY_RELOCS |
875c0872 DA |
1069 | && eh_ind->root.type != bfd_link_hash_indirect |
1070 | && eh_dir->dynamic_adjusted) | |
f5385ebf AM |
1071 | { |
1072 | /* If called to transfer flags for a weakdef during processing | |
1073 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. | |
1074 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
875c0872 DA |
1075 | eh_dir->ref_dynamic |= eh_ind->ref_dynamic; |
1076 | eh_dir->ref_regular |= eh_ind->ref_regular; | |
1077 | eh_dir->ref_regular_nonweak |= eh_ind->ref_regular_nonweak; | |
1078 | eh_dir->needs_plt |= eh_ind->needs_plt; | |
f5385ebf | 1079 | } |
4fc8051d | 1080 | else |
9b52905e NC |
1081 | { |
1082 | if (eh_ind->root.type == bfd_link_hash_indirect | |
1083 | && eh_dir->got.refcount <= 0) | |
1084 | { | |
1085 | hh_dir->tls_type = hh_ind->tls_type; | |
1086 | hh_ind->tls_type = GOT_UNKNOWN; | |
1087 | } | |
1088 | ||
1089 | _bfd_elf_link_hash_copy_indirect (info, eh_dir, eh_ind); | |
1090 | } | |
1091 | } | |
1092 | ||
1093 | static int | |
1094 | elf32_hppa_optimized_tls_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
1095 | int r_type, int is_local ATTRIBUTE_UNUSED) | |
1096 | { | |
1097 | /* For now we don't support linker optimizations. */ | |
1098 | return r_type; | |
ebe50bae AM |
1099 | } |
1100 | ||
d45b7d74 DA |
1101 | /* Return a pointer to the local GOT, PLT and TLS reference counts |
1102 | for ABFD. Returns NULL if the storage allocation fails. */ | |
1103 | ||
1104 | static bfd_signed_vma * | |
1105 | hppa32_elf_local_refcounts (bfd *abfd) | |
1106 | { | |
1107 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
1108 | bfd_signed_vma *local_refcounts; | |
68ffbac6 | 1109 | |
d45b7d74 DA |
1110 | local_refcounts = elf_local_got_refcounts (abfd); |
1111 | if (local_refcounts == NULL) | |
1112 | { | |
1113 | bfd_size_type size; | |
1114 | ||
1115 | /* Allocate space for local GOT and PLT reference | |
1116 | counts. Done this way to save polluting elf_obj_tdata | |
1117 | with another target specific pointer. */ | |
1118 | size = symtab_hdr->sh_info; | |
1119 | size *= 2 * sizeof (bfd_signed_vma); | |
1120 | /* Add in space to store the local GOT TLS types. */ | |
1121 | size += symtab_hdr->sh_info; | |
1122 | local_refcounts = bfd_zalloc (abfd, size); | |
1123 | if (local_refcounts == NULL) | |
1124 | return NULL; | |
1125 | elf_local_got_refcounts (abfd) = local_refcounts; | |
1126 | memset (hppa_elf_local_got_tls_type (abfd), GOT_UNKNOWN, | |
1127 | symtab_hdr->sh_info); | |
1128 | } | |
1129 | return local_refcounts; | |
1130 | } | |
1131 | ||
1132 | ||
30667bf3 | 1133 | /* Look through the relocs for a section during the first phase, and |
3ac8354b AM |
1134 | calculate needed space in the global offset table, procedure linkage |
1135 | table, and dynamic reloc sections. At this point we haven't | |
1136 | necessarily read all the input files. */ | |
252b5132 | 1137 | |
b34976b6 | 1138 | static bfd_boolean |
c39a58e6 AM |
1139 | elf32_hppa_check_relocs (bfd *abfd, |
1140 | struct bfd_link_info *info, | |
1141 | asection *sec, | |
1142 | const Elf_Internal_Rela *relocs) | |
252b5132 | 1143 | { |
30667bf3 | 1144 | Elf_Internal_Shdr *symtab_hdr; |
875c0872 DA |
1145 | struct elf_link_hash_entry **eh_syms; |
1146 | const Elf_Internal_Rela *rela; | |
1147 | const Elf_Internal_Rela *rela_end; | |
83c81bfe | 1148 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 | 1149 | asection *sreloc; |
9b52905e | 1150 | int tls_type = GOT_UNKNOWN, old_tls_type = GOT_UNKNOWN; |
30667bf3 | 1151 | |
0e1862bb | 1152 | if (bfd_link_relocatable (info)) |
b34976b6 | 1153 | return TRUE; |
30667bf3 | 1154 | |
83c81bfe | 1155 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
1156 | if (htab == NULL) |
1157 | return FALSE; | |
30667bf3 | 1158 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
875c0872 | 1159 | eh_syms = elf_sym_hashes (abfd); |
30667bf3 | 1160 | sreloc = NULL; |
30667bf3 | 1161 | |
875c0872 DA |
1162 | rela_end = relocs + sec->reloc_count; |
1163 | for (rela = relocs; rela < rela_end; rela++) | |
30667bf3 AM |
1164 | { |
1165 | enum { | |
1166 | NEED_GOT = 1, | |
1167 | NEED_PLT = 2, | |
1168 | NEED_DYNREL = 4, | |
98ceb8ce | 1169 | PLT_PLABEL = 8 |
30667bf3 | 1170 | }; |
edd21aca | 1171 | |
30667bf3 | 1172 | unsigned int r_symndx, r_type; |
875c0872 DA |
1173 | struct elf32_hppa_link_hash_entry *hh; |
1174 | int need_entry = 0; | |
252b5132 | 1175 | |
875c0872 | 1176 | r_symndx = ELF32_R_SYM (rela->r_info); |
252b5132 | 1177 | |
30667bf3 | 1178 | if (r_symndx < symtab_hdr->sh_info) |
875c0872 | 1179 | hh = NULL; |
30667bf3 | 1180 | else |
f7c5057a | 1181 | { |
875c0872 | 1182 | hh = hppa_elf_hash_entry (eh_syms[r_symndx - symtab_hdr->sh_info]); |
a63e02c7 DA |
1183 | while (hh->eh.root.type == bfd_link_hash_indirect |
1184 | || hh->eh.root.type == bfd_link_hash_warning) | |
1185 | hh = hppa_elf_hash_entry (hh->eh.root.u.i.link); | |
81fbe831 AM |
1186 | |
1187 | /* PR15323, ref flags aren't set for references in the same | |
1188 | object. */ | |
1189 | hh->eh.root.non_ir_ref = 1; | |
f7c5057a | 1190 | } |
252b5132 | 1191 | |
875c0872 | 1192 | r_type = ELF32_R_TYPE (rela->r_info); |
9b52905e | 1193 | r_type = elf32_hppa_optimized_tls_reloc (info, r_type, hh == NULL); |
252b5132 | 1194 | |
30667bf3 AM |
1195 | switch (r_type) |
1196 | { | |
1197 | case R_PARISC_DLTIND14F: | |
1198 | case R_PARISC_DLTIND14R: | |
1199 | case R_PARISC_DLTIND21L: | |
1200 | /* This symbol requires a global offset table entry. */ | |
1201 | need_entry = NEED_GOT; | |
30667bf3 AM |
1202 | break; |
1203 | ||
1204 | case R_PARISC_PLABEL14R: /* "Official" procedure labels. */ | |
1205 | case R_PARISC_PLABEL21L: | |
1206 | case R_PARISC_PLABEL32: | |
74d1c347 | 1207 | /* If the addend is non-zero, we break badly. */ |
875c0872 | 1208 | if (rela->r_addend != 0) |
49e9d0d3 | 1209 | abort (); |
74d1c347 AM |
1210 | |
1211 | /* If we are creating a shared library, then we need to | |
1212 | create a PLT entry for all PLABELs, because PLABELs with | |
1213 | local symbols may be passed via a pointer to another | |
1214 | object. Additionally, output a dynamic relocation | |
4dc86686 | 1215 | pointing to the PLT entry. |
875c0872 | 1216 | |
4dc86686 AM |
1217 | For executables, the original 32-bit ABI allowed two |
1218 | different styles of PLABELs (function pointers): For | |
1219 | global functions, the PLABEL word points into the .plt | |
1220 | two bytes past a (function address, gp) pair, and for | |
1221 | local functions the PLABEL points directly at the | |
1222 | function. The magic +2 for the first type allows us to | |
1223 | differentiate between the two. As you can imagine, this | |
1224 | is a real pain when it comes to generating code to call | |
1225 | functions indirectly or to compare function pointers. | |
1226 | We avoid the mess by always pointing a PLABEL into the | |
1227 | .plt, even for local functions. */ | |
74d1c347 | 1228 | need_entry = PLT_PLABEL | NEED_PLT | NEED_DYNREL; |
30667bf3 AM |
1229 | break; |
1230 | ||
1231 | case R_PARISC_PCREL12F: | |
83c81bfe | 1232 | htab->has_12bit_branch = 1; |
067fa4a6 AM |
1233 | goto branch_common; |
1234 | ||
30667bf3 AM |
1235 | case R_PARISC_PCREL17C: |
1236 | case R_PARISC_PCREL17F: | |
83c81bfe | 1237 | htab->has_17bit_branch = 1; |
067fa4a6 AM |
1238 | goto branch_common; |
1239 | ||
30667bf3 | 1240 | case R_PARISC_PCREL22F: |
067fa4a6 AM |
1241 | htab->has_22bit_branch = 1; |
1242 | branch_common: | |
47d89dba AM |
1243 | /* Function calls might need to go through the .plt, and |
1244 | might require long branch stubs. */ | |
875c0872 | 1245 | if (hh == NULL) |
30667bf3 AM |
1246 | { |
1247 | /* We know local syms won't need a .plt entry, and if | |
1248 | they need a long branch stub we can't guarantee that | |
1249 | we can reach the stub. So just flag an error later | |
1250 | if we're doing a shared link and find we need a long | |
1251 | branch stub. */ | |
1252 | continue; | |
1253 | } | |
1254 | else | |
1255 | { | |
1256 | /* Global symbols will need a .plt entry if they remain | |
1257 | global, and in most cases won't need a long branch | |
1258 | stub. Unfortunately, we have to cater for the case | |
1259 | where a symbol is forced local by versioning, or due | |
1260 | to symbolic linking, and we lose the .plt entry. */ | |
98ceb8ce | 1261 | need_entry = NEED_PLT; |
a63e02c7 | 1262 | if (hh->eh.type == STT_PARISC_MILLI) |
98ceb8ce | 1263 | need_entry = 0; |
30667bf3 AM |
1264 | } |
1265 | break; | |
1266 | ||
36751eee | 1267 | case R_PARISC_SEGBASE: /* Used to set segment base. */ |
c46b7515 | 1268 | case R_PARISC_SEGREL32: /* Relative reloc, used for unwind. */ |
30667bf3 AM |
1269 | case R_PARISC_PCREL14F: /* PC relative load/store. */ |
1270 | case R_PARISC_PCREL14R: | |
1271 | case R_PARISC_PCREL17R: /* External branches. */ | |
1272 | case R_PARISC_PCREL21L: /* As above, and for load/store too. */ | |
36751eee | 1273 | case R_PARISC_PCREL32: |
30667bf3 AM |
1274 | /* We don't need to propagate the relocation if linking a |
1275 | shared object since these are section relative. */ | |
1276 | continue; | |
1277 | ||
1278 | case R_PARISC_DPREL14F: /* Used for gp rel data load/store. */ | |
1279 | case R_PARISC_DPREL14R: | |
1280 | case R_PARISC_DPREL21L: | |
0e1862bb | 1281 | if (bfd_link_pic (info)) |
30667bf3 AM |
1282 | { |
1283 | (*_bfd_error_handler) | |
d003868e AM |
1284 | (_("%B: relocation %s can not be used when making a shared object; recompile with -fPIC"), |
1285 | abfd, | |
30667bf3 AM |
1286 | elf_hppa_howto_table[r_type].name); |
1287 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 1288 | return FALSE; |
30667bf3 AM |
1289 | } |
1290 | /* Fall through. */ | |
1291 | ||
1292 | case R_PARISC_DIR17F: /* Used for external branches. */ | |
1293 | case R_PARISC_DIR17R: | |
47d89dba AM |
1294 | case R_PARISC_DIR14F: /* Used for load/store from absolute locn. */ |
1295 | case R_PARISC_DIR14R: | |
30667bf3 | 1296 | case R_PARISC_DIR21L: /* As above, and for ext branches too. */ |
c46b7515 | 1297 | case R_PARISC_DIR32: /* .word relocs. */ |
30667bf3 AM |
1298 | /* We may want to output a dynamic relocation later. */ |
1299 | need_entry = NEED_DYNREL; | |
1300 | break; | |
1301 | ||
1302 | /* This relocation describes the C++ object vtable hierarchy. | |
1303 | Reconstruct it for later use during GC. */ | |
1304 | case R_PARISC_GNU_VTINHERIT: | |
a63e02c7 | 1305 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, &hh->eh, rela->r_offset)) |
b34976b6 | 1306 | return FALSE; |
30667bf3 AM |
1307 | continue; |
1308 | ||
1309 | /* This relocation describes which C++ vtable entries are actually | |
1310 | used. Record for later use during GC. */ | |
1311 | case R_PARISC_GNU_VTENTRY: | |
d17e0c6e JB |
1312 | BFD_ASSERT (hh != NULL); |
1313 | if (hh != NULL | |
1314 | && !bfd_elf_gc_record_vtentry (abfd, sec, &hh->eh, rela->r_addend)) | |
b34976b6 | 1315 | return FALSE; |
30667bf3 AM |
1316 | continue; |
1317 | ||
9b52905e NC |
1318 | case R_PARISC_TLS_GD21L: |
1319 | case R_PARISC_TLS_GD14R: | |
1320 | case R_PARISC_TLS_LDM21L: | |
1321 | case R_PARISC_TLS_LDM14R: | |
1322 | need_entry = NEED_GOT; | |
1323 | break; | |
1324 | ||
1325 | case R_PARISC_TLS_IE21L: | |
1326 | case R_PARISC_TLS_IE14R: | |
0e1862bb | 1327 | if (bfd_link_pic (info)) |
9b52905e NC |
1328 | info->flags |= DF_STATIC_TLS; |
1329 | need_entry = NEED_GOT; | |
1330 | break; | |
1331 | ||
30667bf3 AM |
1332 | default: |
1333 | continue; | |
1334 | } | |
1335 | ||
1336 | /* Now carry out our orders. */ | |
1337 | if (need_entry & NEED_GOT) | |
1338 | { | |
9b52905e NC |
1339 | switch (r_type) |
1340 | { | |
1341 | default: | |
1342 | tls_type = GOT_NORMAL; | |
1343 | break; | |
1344 | case R_PARISC_TLS_GD21L: | |
1345 | case R_PARISC_TLS_GD14R: | |
1346 | tls_type |= GOT_TLS_GD; | |
1347 | break; | |
1348 | case R_PARISC_TLS_LDM21L: | |
1349 | case R_PARISC_TLS_LDM14R: | |
1350 | tls_type |= GOT_TLS_LDM; | |
1351 | break; | |
1352 | case R_PARISC_TLS_IE21L: | |
1353 | case R_PARISC_TLS_IE14R: | |
1354 | tls_type |= GOT_TLS_IE; | |
1355 | break; | |
1356 | } | |
1357 | ||
30667bf3 | 1358 | /* Allocate space for a GOT entry, as well as a dynamic |
25f72752 | 1359 | relocation for this entry. */ |
83c81bfe | 1360 | if (htab->sgot == NULL) |
30667bf3 | 1361 | { |
a63e02c7 | 1362 | if (!elf32_hppa_create_dynamic_sections (htab->etab.dynobj, info)) |
b34976b6 | 1363 | return FALSE; |
30667bf3 AM |
1364 | } |
1365 | ||
9b52905e NC |
1366 | if (r_type == R_PARISC_TLS_LDM21L |
1367 | || r_type == R_PARISC_TLS_LDM14R) | |
4dfe6ac6 | 1368 | htab->tls_ldm_got.refcount += 1; |
30667bf3 AM |
1369 | else |
1370 | { | |
9b52905e NC |
1371 | if (hh != NULL) |
1372 | { | |
1373 | hh->eh.got.refcount += 1; | |
1374 | old_tls_type = hh->tls_type; | |
1375 | } | |
1376 | else | |
1377 | { | |
1378 | bfd_signed_vma *local_got_refcounts; | |
68ffbac6 | 1379 | |
9b52905e | 1380 | /* This is a global offset table entry for a local symbol. */ |
d45b7d74 | 1381 | local_got_refcounts = hppa32_elf_local_refcounts (abfd); |
9b52905e | 1382 | if (local_got_refcounts == NULL) |
d45b7d74 | 1383 | return FALSE; |
9b52905e NC |
1384 | local_got_refcounts[r_symndx] += 1; |
1385 | ||
1386 | old_tls_type = hppa_elf_local_got_tls_type (abfd) [r_symndx]; | |
1387 | } | |
1388 | ||
1389 | tls_type |= old_tls_type; | |
1390 | ||
1391 | if (old_tls_type != tls_type) | |
1392 | { | |
1393 | if (hh != NULL) | |
1394 | hh->tls_type = tls_type; | |
1395 | else | |
1396 | hppa_elf_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
1397 | } | |
1398 | ||
30667bf3 AM |
1399 | } |
1400 | } | |
1401 | ||
1402 | if (need_entry & NEED_PLT) | |
1403 | { | |
1404 | /* If we are creating a shared library, and this is a reloc | |
1405 | against a weak symbol or a global symbol in a dynamic | |
1406 | object, then we will be creating an import stub and a | |
1407 | .plt entry for the symbol. Similarly, on a normal link | |
1408 | to symbols defined in a dynamic object we'll need the | |
1409 | import stub and a .plt entry. We don't know yet whether | |
1410 | the symbol is defined or not, so make an entry anyway and | |
1411 | clean up later in adjust_dynamic_symbol. */ | |
1412 | if ((sec->flags & SEC_ALLOC) != 0) | |
1413 | { | |
875c0872 | 1414 | if (hh != NULL) |
30667bf3 | 1415 | { |
a63e02c7 DA |
1416 | hh->eh.needs_plt = 1; |
1417 | hh->eh.plt.refcount += 1; | |
74d1c347 | 1418 | |
36605136 AM |
1419 | /* If this .plt entry is for a plabel, mark it so |
1420 | that adjust_dynamic_symbol will keep the entry | |
1421 | even if it appears to be local. */ | |
74d1c347 | 1422 | if (need_entry & PLT_PLABEL) |
875c0872 | 1423 | hh->plabel = 1; |
74d1c347 AM |
1424 | } |
1425 | else if (need_entry & PLT_PLABEL) | |
1426 | { | |
3ac8354b | 1427 | bfd_signed_vma *local_got_refcounts; |
68fb2e56 | 1428 | bfd_signed_vma *local_plt_refcounts; |
74d1c347 | 1429 | |
d45b7d74 | 1430 | local_got_refcounts = hppa32_elf_local_refcounts (abfd); |
74d1c347 | 1431 | if (local_got_refcounts == NULL) |
d45b7d74 | 1432 | return FALSE; |
68fb2e56 AM |
1433 | local_plt_refcounts = (local_got_refcounts |
1434 | + symtab_hdr->sh_info); | |
ebe50bae | 1435 | local_plt_refcounts[r_symndx] += 1; |
30667bf3 | 1436 | } |
30667bf3 AM |
1437 | } |
1438 | } | |
1439 | ||
98ceb8ce | 1440 | if (need_entry & NEED_DYNREL) |
30667bf3 AM |
1441 | { |
1442 | /* Flag this symbol as having a non-got, non-plt reference | |
1443 | so that we generate copy relocs if it turns out to be | |
1444 | dynamic. */ | |
0e1862bb | 1445 | if (hh != NULL && !bfd_link_pic (info)) |
a63e02c7 | 1446 | hh->eh.non_got_ref = 1; |
30667bf3 AM |
1447 | |
1448 | /* If we are creating a shared library then we need to copy | |
1449 | the reloc into the shared library. However, if we are | |
1450 | linking with -Bsymbolic, we need only copy absolute | |
1451 | relocs or relocs against symbols that are not defined in | |
1452 | an object we are including in the link. PC- or DP- or | |
1453 | DLT-relative relocs against any local sym or global sym | |
1454 | with DEF_REGULAR set, can be discarded. At this point we | |
1455 | have not seen all the input files, so it is possible that | |
1456 | DEF_REGULAR is not set now but will be set later (it is | |
1457 | never cleared). We account for that possibility below by | |
98ceb8ce | 1458 | storing information in the dyn_relocs field of the |
30667bf3 AM |
1459 | hash table entry. |
1460 | ||
1461 | A similar situation to the -Bsymbolic case occurs when | |
1462 | creating shared libraries and symbol visibility changes | |
1463 | render the symbol local. | |
1464 | ||
1465 | As it turns out, all the relocs we will be creating here | |
1466 | are absolute, so we cannot remove them on -Bsymbolic | |
1467 | links or visibility changes anyway. A STUB_REL reloc | |
1468 | is absolute too, as in that case it is the reloc in the | |
1469 | stub we will be creating, rather than copying the PCREL | |
56882138 AM |
1470 | reloc in the branch. |
1471 | ||
1472 | If on the other hand, we are creating an executable, we | |
1473 | may need to keep relocations for symbols satisfied by a | |
1474 | dynamic library if we manage to avoid copy relocs for the | |
1475 | symbol. */ | |
0e1862bb | 1476 | if ((bfd_link_pic (info) |
446f2863 AM |
1477 | && (sec->flags & SEC_ALLOC) != 0 |
1478 | && (IS_ABSOLUTE_RELOC (r_type) | |
875c0872 | 1479 | || (hh != NULL |
a496fbc8 | 1480 | && (!SYMBOLIC_BIND (info, &hh->eh) |
a63e02c7 DA |
1481 | || hh->eh.root.type == bfd_link_hash_defweak |
1482 | || !hh->eh.def_regular)))) | |
4fc8051d | 1483 | || (ELIMINATE_COPY_RELOCS |
0e1862bb | 1484 | && !bfd_link_pic (info) |
446f2863 | 1485 | && (sec->flags & SEC_ALLOC) != 0 |
875c0872 | 1486 | && hh != NULL |
a63e02c7 DA |
1487 | && (hh->eh.root.type == bfd_link_hash_defweak |
1488 | || !hh->eh.def_regular))) | |
30667bf3 | 1489 | { |
875c0872 DA |
1490 | struct elf32_hppa_dyn_reloc_entry *hdh_p; |
1491 | struct elf32_hppa_dyn_reloc_entry **hdh_head; | |
ec338859 | 1492 | |
30667bf3 AM |
1493 | /* Create a reloc section in dynobj and make room for |
1494 | this reloc. */ | |
98ceb8ce | 1495 | if (sreloc == NULL) |
30667bf3 | 1496 | { |
83bac4b0 NC |
1497 | sreloc = _bfd_elf_make_dynamic_reloc_section |
1498 | (sec, htab->etab.dynobj, 2, abfd, /*rela?*/ TRUE); | |
1499 | ||
98ceb8ce | 1500 | if (sreloc == NULL) |
30667bf3 | 1501 | { |
83bac4b0 NC |
1502 | bfd_set_error (bfd_error_bad_value); |
1503 | return FALSE; | |
30667bf3 | 1504 | } |
30667bf3 AM |
1505 | } |
1506 | ||
98ceb8ce AM |
1507 | /* If this is a global symbol, we count the number of |
1508 | relocations we need for this symbol. */ | |
875c0872 | 1509 | if (hh != NULL) |
30667bf3 | 1510 | { |
875c0872 | 1511 | hdh_head = &hh->dyn_relocs; |
ec338859 AM |
1512 | } |
1513 | else | |
1514 | { | |
1515 | /* Track dynamic relocs needed for local syms too. | |
1516 | We really need local syms available to do this | |
1517 | easily. Oh well. */ | |
875c0872 | 1518 | asection *sr; |
6edfbbad | 1519 | void *vpp; |
87d72d41 | 1520 | Elf_Internal_Sym *isym; |
6edfbbad | 1521 | |
87d72d41 AM |
1522 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
1523 | abfd, r_symndx); | |
1524 | if (isym == NULL) | |
b34976b6 | 1525 | return FALSE; |
30667bf3 | 1526 | |
87d72d41 AM |
1527 | sr = bfd_section_from_elf_index (abfd, isym->st_shndx); |
1528 | if (sr == NULL) | |
1529 | sr = sec; | |
1530 | ||
6edfbbad DJ |
1531 | vpp = &elf_section_data (sr)->local_dynrel; |
1532 | hdh_head = (struct elf32_hppa_dyn_reloc_entry **) vpp; | |
ec338859 AM |
1533 | } |
1534 | ||
875c0872 DA |
1535 | hdh_p = *hdh_head; |
1536 | if (hdh_p == NULL || hdh_p->sec != sec) | |
ec338859 | 1537 | { |
a63e02c7 | 1538 | hdh_p = bfd_alloc (htab->etab.dynobj, sizeof *hdh_p); |
875c0872 | 1539 | if (hdh_p == NULL) |
b34976b6 | 1540 | return FALSE; |
a63e02c7 | 1541 | hdh_p->hdh_next = *hdh_head; |
875c0872 DA |
1542 | *hdh_head = hdh_p; |
1543 | hdh_p->sec = sec; | |
1544 | hdh_p->count = 0; | |
98ceb8ce | 1545 | #if RELATIVE_DYNRELOCS |
875c0872 | 1546 | hdh_p->relative_count = 0; |
98ceb8ce | 1547 | #endif |
ec338859 | 1548 | } |
98ceb8ce | 1549 | |
875c0872 | 1550 | hdh_p->count += 1; |
98ceb8ce | 1551 | #if RELATIVE_DYNRELOCS |
ec338859 | 1552 | if (!IS_ABSOLUTE_RELOC (rtype)) |
875c0872 | 1553 | hdh_p->relative_count += 1; |
98ceb8ce | 1554 | #endif |
30667bf3 AM |
1555 | } |
1556 | } | |
1557 | } | |
edd21aca | 1558 | |
b34976b6 | 1559 | return TRUE; |
edd21aca AM |
1560 | } |
1561 | ||
30667bf3 AM |
1562 | /* Return the section that should be marked against garbage collection |
1563 | for a given relocation. */ | |
1564 | ||
1565 | static asection * | |
c39a58e6 | 1566 | elf32_hppa_gc_mark_hook (asection *sec, |
07adf181 | 1567 | struct bfd_link_info *info, |
875c0872 DA |
1568 | Elf_Internal_Rela *rela, |
1569 | struct elf_link_hash_entry *hh, | |
c39a58e6 | 1570 | Elf_Internal_Sym *sym) |
30667bf3 | 1571 | { |
875c0872 | 1572 | if (hh != NULL) |
07adf181 AM |
1573 | switch ((unsigned int) ELF32_R_TYPE (rela->r_info)) |
1574 | { | |
1575 | case R_PARISC_GNU_VTINHERIT: | |
1576 | case R_PARISC_GNU_VTENTRY: | |
1577 | return NULL; | |
1578 | } | |
30667bf3 | 1579 | |
07adf181 | 1580 | return _bfd_elf_gc_mark_hook (sec, info, rela, hh, sym); |
30667bf3 AM |
1581 | } |
1582 | ||
30667bf3 AM |
1583 | /* Update the got and plt entry reference counts for the section being |
1584 | removed. */ | |
edd21aca | 1585 | |
b34976b6 | 1586 | static bfd_boolean |
c39a58e6 AM |
1587 | elf32_hppa_gc_sweep_hook (bfd *abfd, |
1588 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
1589 | asection *sec, | |
1590 | const Elf_Internal_Rela *relocs) | |
edd21aca | 1591 | { |
30667bf3 | 1592 | Elf_Internal_Shdr *symtab_hdr; |
875c0872 | 1593 | struct elf_link_hash_entry **eh_syms; |
30667bf3 | 1594 | bfd_signed_vma *local_got_refcounts; |
74d1c347 | 1595 | bfd_signed_vma *local_plt_refcounts; |
875c0872 | 1596 | const Elf_Internal_Rela *rela, *relend; |
4dfe6ac6 | 1597 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 | 1598 | |
0e1862bb | 1599 | if (bfd_link_relocatable (info)) |
7dda2462 TG |
1600 | return TRUE; |
1601 | ||
4dfe6ac6 NC |
1602 | htab = hppa_link_hash_table (info); |
1603 | if (htab == NULL) | |
1604 | return FALSE; | |
1605 | ||
ec338859 | 1606 | elf_section_data (sec)->local_dynrel = NULL; |
98ceb8ce | 1607 | |
30667bf3 | 1608 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
875c0872 | 1609 | eh_syms = elf_sym_hashes (abfd); |
30667bf3 | 1610 | local_got_refcounts = elf_local_got_refcounts (abfd); |
74d1c347 AM |
1611 | local_plt_refcounts = local_got_refcounts; |
1612 | if (local_plt_refcounts != NULL) | |
1613 | local_plt_refcounts += symtab_hdr->sh_info; | |
30667bf3 | 1614 | |
30667bf3 | 1615 | relend = relocs + sec->reloc_count; |
875c0872 | 1616 | for (rela = relocs; rela < relend; rela++) |
26e41594 AM |
1617 | { |
1618 | unsigned long r_symndx; | |
1619 | unsigned int r_type; | |
875c0872 | 1620 | struct elf_link_hash_entry *eh = NULL; |
26e41594 | 1621 | |
875c0872 | 1622 | r_symndx = ELF32_R_SYM (rela->r_info); |
26e41594 AM |
1623 | if (r_symndx >= symtab_hdr->sh_info) |
1624 | { | |
875c0872 DA |
1625 | struct elf32_hppa_link_hash_entry *hh; |
1626 | struct elf32_hppa_dyn_reloc_entry **hdh_pp; | |
1627 | struct elf32_hppa_dyn_reloc_entry *hdh_p; | |
26e41594 | 1628 | |
875c0872 DA |
1629 | eh = eh_syms[r_symndx - symtab_hdr->sh_info]; |
1630 | while (eh->root.type == bfd_link_hash_indirect | |
1631 | || eh->root.type == bfd_link_hash_warning) | |
1632 | eh = (struct elf_link_hash_entry *) eh->root.u.i.link; | |
1633 | hh = hppa_elf_hash_entry (eh); | |
26e41594 | 1634 | |
a63e02c7 | 1635 | for (hdh_pp = &hh->dyn_relocs; (hdh_p = *hdh_pp) != NULL; hdh_pp = &hdh_p->hdh_next) |
875c0872 | 1636 | if (hdh_p->sec == sec) |
26e41594 AM |
1637 | { |
1638 | /* Everything must go for SEC. */ | |
a63e02c7 | 1639 | *hdh_pp = hdh_p->hdh_next; |
26e41594 AM |
1640 | break; |
1641 | } | |
1642 | } | |
1643 | ||
875c0872 | 1644 | r_type = ELF32_R_TYPE (rela->r_info); |
9b52905e NC |
1645 | r_type = elf32_hppa_optimized_tls_reloc (info, r_type, eh != NULL); |
1646 | ||
26e41594 AM |
1647 | switch (r_type) |
1648 | { | |
1649 | case R_PARISC_DLTIND14F: | |
1650 | case R_PARISC_DLTIND14R: | |
1651 | case R_PARISC_DLTIND21L: | |
9b52905e NC |
1652 | case R_PARISC_TLS_GD21L: |
1653 | case R_PARISC_TLS_GD14R: | |
1654 | case R_PARISC_TLS_IE21L: | |
1655 | case R_PARISC_TLS_IE14R: | |
875c0872 | 1656 | if (eh != NULL) |
26e41594 | 1657 | { |
875c0872 DA |
1658 | if (eh->got.refcount > 0) |
1659 | eh->got.refcount -= 1; | |
26e41594 AM |
1660 | } |
1661 | else if (local_got_refcounts != NULL) | |
1662 | { | |
1663 | if (local_got_refcounts[r_symndx] > 0) | |
1664 | local_got_refcounts[r_symndx] -= 1; | |
1665 | } | |
1666 | break; | |
98ceb8ce | 1667 | |
9b52905e NC |
1668 | case R_PARISC_TLS_LDM21L: |
1669 | case R_PARISC_TLS_LDM14R: | |
4dfe6ac6 | 1670 | htab->tls_ldm_got.refcount -= 1; |
9b52905e NC |
1671 | break; |
1672 | ||
26e41594 AM |
1673 | case R_PARISC_PCREL12F: |
1674 | case R_PARISC_PCREL17C: | |
1675 | case R_PARISC_PCREL17F: | |
1676 | case R_PARISC_PCREL22F: | |
875c0872 | 1677 | if (eh != NULL) |
26e41594 | 1678 | { |
875c0872 DA |
1679 | if (eh->plt.refcount > 0) |
1680 | eh->plt.refcount -= 1; | |
26e41594 AM |
1681 | } |
1682 | break; | |
1683 | ||
1684 | case R_PARISC_PLABEL14R: | |
1685 | case R_PARISC_PLABEL21L: | |
1686 | case R_PARISC_PLABEL32: | |
875c0872 | 1687 | if (eh != NULL) |
26e41594 | 1688 | { |
875c0872 DA |
1689 | if (eh->plt.refcount > 0) |
1690 | eh->plt.refcount -= 1; | |
26e41594 AM |
1691 | } |
1692 | else if (local_plt_refcounts != NULL) | |
1693 | { | |
1694 | if (local_plt_refcounts[r_symndx] > 0) | |
1695 | local_plt_refcounts[r_symndx] -= 1; | |
1696 | } | |
1697 | break; | |
1698 | ||
1699 | default: | |
1700 | break; | |
1701 | } | |
1702 | } | |
252b5132 | 1703 | |
b34976b6 | 1704 | return TRUE; |
252b5132 RH |
1705 | } |
1706 | ||
edfc032f AM |
1707 | /* Support for core dump NOTE sections. */ |
1708 | ||
1709 | static bfd_boolean | |
1710 | elf32_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |
1711 | { | |
1712 | int offset; | |
1713 | size_t size; | |
1714 | ||
1715 | switch (note->descsz) | |
1716 | { | |
1717 | default: | |
1718 | return FALSE; | |
1719 | ||
1720 | case 396: /* Linux/hppa */ | |
1721 | /* pr_cursig */ | |
228e534f | 1722 | elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); |
edfc032f AM |
1723 | |
1724 | /* pr_pid */ | |
228e534f | 1725 | elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24); |
edfc032f AM |
1726 | |
1727 | /* pr_reg */ | |
1728 | offset = 72; | |
1729 | size = 320; | |
1730 | ||
1731 | break; | |
1732 | } | |
1733 | ||
1734 | /* Make a ".reg/999" section. */ | |
1735 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1736 | size, note->descpos + offset); | |
1737 | } | |
1738 | ||
1739 | static bfd_boolean | |
1740 | elf32_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
1741 | { | |
1742 | switch (note->descsz) | |
1743 | { | |
1744 | default: | |
1745 | return FALSE; | |
1746 | ||
1747 | case 124: /* Linux/hppa elf_prpsinfo. */ | |
228e534f | 1748 | elf_tdata (abfd)->core->program |
edfc032f | 1749 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); |
228e534f | 1750 | elf_tdata (abfd)->core->command |
edfc032f AM |
1751 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); |
1752 | } | |
1753 | ||
1754 | /* Note that for some reason, a spurious space is tacked | |
1755 | onto the end of the args in some (at least one anyway) | |
1756 | implementations, so strip it off if it exists. */ | |
1757 | { | |
228e534f | 1758 | char *command = elf_tdata (abfd)->core->command; |
edfc032f AM |
1759 | int n = strlen (command); |
1760 | ||
1761 | if (0 < n && command[n - 1] == ' ') | |
1762 | command[n - 1] = '\0'; | |
1763 | } | |
1764 | ||
1765 | return TRUE; | |
1766 | } | |
1767 | ||
74d1c347 AM |
1768 | /* Our own version of hide_symbol, so that we can keep plt entries for |
1769 | plabels. */ | |
1770 | ||
1771 | static void | |
c39a58e6 | 1772 | elf32_hppa_hide_symbol (struct bfd_link_info *info, |
875c0872 | 1773 | struct elf_link_hash_entry *eh, |
c39a58e6 | 1774 | bfd_boolean force_local) |
74d1c347 | 1775 | { |
e5094212 AM |
1776 | if (force_local) |
1777 | { | |
875c0872 DA |
1778 | eh->forced_local = 1; |
1779 | if (eh->dynindx != -1) | |
e5094212 | 1780 | { |
875c0872 | 1781 | eh->dynindx = -1; |
e5094212 | 1782 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, |
875c0872 | 1783 | eh->dynstr_index); |
e5094212 | 1784 | } |
31fc8a0b NC |
1785 | |
1786 | /* PR 16082: Remove version information from hidden symbol. */ | |
1787 | eh->verinfo.verdef = NULL; | |
1788 | eh->verinfo.vertree = NULL; | |
e5094212 AM |
1789 | } |
1790 | ||
4340287b DA |
1791 | /* STT_GNU_IFUNC symbol must go through PLT. */ |
1792 | if (! hppa_elf_hash_entry (eh)->plabel | |
1793 | && eh->type != STT_GNU_IFUNC) | |
74d1c347 | 1794 | { |
875c0872 | 1795 | eh->needs_plt = 0; |
4340287b | 1796 | eh->plt = elf_hash_table (info)->init_plt_offset; |
74d1c347 AM |
1797 | } |
1798 | } | |
1799 | ||
30667bf3 AM |
1800 | /* Adjust a symbol defined by a dynamic object and referenced by a |
1801 | regular object. The current definition is in some section of the | |
1802 | dynamic object, but we're not including those sections. We have to | |
1803 | change the definition to something the rest of the link can | |
1804 | understand. */ | |
252b5132 | 1805 | |
b34976b6 | 1806 | static bfd_boolean |
c39a58e6 | 1807 | elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info, |
875c0872 | 1808 | struct elf_link_hash_entry *eh) |
252b5132 | 1809 | { |
83c81bfe | 1810 | struct elf32_hppa_link_hash_table *htab; |
875c0872 | 1811 | asection *sec; |
30667bf3 AM |
1812 | |
1813 | /* If this is a function, put it in the procedure linkage table. We | |
067fa4a6 | 1814 | will fill in the contents of the procedure linkage table later. */ |
875c0872 DA |
1815 | if (eh->type == STT_FUNC |
1816 | || eh->needs_plt) | |
30667bf3 | 1817 | { |
4340287b DA |
1818 | /* If the symbol is used by a plabel, we must allocate a PLT slot. |
1819 | The refcounts are not reliable when it has been hidden since | |
1820 | hide_symbol can be called before the plabel flag is set. */ | |
1821 | if (hppa_elf_hash_entry (eh)->plabel | |
1822 | && eh->plt.refcount <= 0) | |
1823 | eh->plt.refcount = 1; | |
1824 | ||
875c0872 DA |
1825 | if (eh->plt.refcount <= 0 |
1826 | || (eh->def_regular | |
1827 | && eh->root.type != bfd_link_hash_defweak | |
1828 | && ! hppa_elf_hash_entry (eh)->plabel | |
0e1862bb | 1829 | && (!bfd_link_pic (info) || SYMBOLIC_BIND (info, eh)))) |
30667bf3 AM |
1830 | { |
1831 | /* The .plt entry is not needed when: | |
1832 | a) Garbage collection has removed all references to the | |
1833 | symbol, or | |
1834 | b) We know for certain the symbol is defined in this | |
74d1c347 AM |
1835 | object, and it's not a weak definition, nor is the symbol |
1836 | used by a plabel relocation. Either this object is the | |
1837 | application or we are doing a shared symbolic link. */ | |
1838 | ||
875c0872 DA |
1839 | eh->plt.offset = (bfd_vma) -1; |
1840 | eh->needs_plt = 0; | |
30667bf3 | 1841 | } |
4dc86686 | 1842 | |
b34976b6 | 1843 | return TRUE; |
30667bf3 | 1844 | } |
bbd7ec4a | 1845 | else |
875c0872 | 1846 | eh->plt.offset = (bfd_vma) -1; |
edd21aca | 1847 | |
30667bf3 AM |
1848 | /* If this is a weak symbol, and there is a real definition, the |
1849 | processor independent code will have arranged for us to see the | |
1850 | real definition first, and we can just use the same value. */ | |
875c0872 | 1851 | if (eh->u.weakdef != NULL) |
edd21aca | 1852 | { |
875c0872 DA |
1853 | if (eh->u.weakdef->root.type != bfd_link_hash_defined |
1854 | && eh->u.weakdef->root.type != bfd_link_hash_defweak) | |
49e9d0d3 | 1855 | abort (); |
875c0872 DA |
1856 | eh->root.u.def.section = eh->u.weakdef->root.u.def.section; |
1857 | eh->root.u.def.value = eh->u.weakdef->root.u.def.value; | |
4fc8051d | 1858 | if (ELIMINATE_COPY_RELOCS) |
875c0872 | 1859 | eh->non_got_ref = eh->u.weakdef->non_got_ref; |
b34976b6 | 1860 | return TRUE; |
30667bf3 | 1861 | } |
edd21aca | 1862 | |
30667bf3 AM |
1863 | /* This is a reference to a symbol defined by a dynamic object which |
1864 | is not a function. */ | |
1865 | ||
1866 | /* If we are creating a shared library, we must presume that the | |
1867 | only references to the symbol are via the global offset table. | |
1868 | For such cases we need not do anything here; the relocations will | |
1869 | be handled correctly by relocate_section. */ | |
0e1862bb | 1870 | if (bfd_link_pic (info)) |
b34976b6 | 1871 | return TRUE; |
30667bf3 AM |
1872 | |
1873 | /* If there are no references to this symbol that do not use the | |
1874 | GOT, we don't need to generate a copy reloc. */ | |
875c0872 | 1875 | if (!eh->non_got_ref) |
b34976b6 | 1876 | return TRUE; |
30667bf3 | 1877 | |
4fc8051d | 1878 | if (ELIMINATE_COPY_RELOCS) |
ebe50bae | 1879 | { |
875c0872 DA |
1880 | struct elf32_hppa_link_hash_entry *hh; |
1881 | struct elf32_hppa_dyn_reloc_entry *hdh_p; | |
ebe50bae | 1882 | |
875c0872 | 1883 | hh = hppa_elf_hash_entry (eh); |
a63e02c7 | 1884 | for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next) |
4fc8051d | 1885 | { |
875c0872 DA |
1886 | sec = hdh_p->sec->output_section; |
1887 | if (sec != NULL && (sec->flags & SEC_READONLY) != 0) | |
4fc8051d AM |
1888 | break; |
1889 | } | |
1890 | ||
1891 | /* If we didn't find any dynamic relocs in read-only sections, then | |
1892 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
875c0872 | 1893 | if (hdh_p == NULL) |
4fc8051d | 1894 | { |
875c0872 | 1895 | eh->non_got_ref = 0; |
4fc8051d AM |
1896 | return TRUE; |
1897 | } | |
ebe50bae AM |
1898 | } |
1899 | ||
30667bf3 AM |
1900 | /* We must allocate the symbol in our .dynbss section, which will |
1901 | become part of the .bss section of the executable. There will be | |
1902 | an entry for this symbol in the .dynsym section. The dynamic | |
1903 | object will contain position independent code, so all references | |
1904 | from the dynamic object to this symbol will go through the global | |
1905 | offset table. The dynamic linker will use the .dynsym entry to | |
1906 | determine the address it must put in the global offset table, so | |
1907 | both the dynamic object and the regular object will refer to the | |
1908 | same memory location for the variable. */ | |
1909 | ||
3ac8354b | 1910 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
1911 | if (htab == NULL) |
1912 | return FALSE; | |
30667bf3 AM |
1913 | |
1914 | /* We must generate a COPY reloc to tell the dynamic linker to | |
1915 | copy the initial value out of the dynamic object and into the | |
3ac8354b | 1916 | runtime process image. */ |
1d7e9d18 | 1917 | if ((eh->root.u.def.section->flags & SEC_ALLOC) != 0 && eh->size != 0) |
30667bf3 | 1918 | { |
eea6121a | 1919 | htab->srelbss->size += sizeof (Elf32_External_Rela); |
875c0872 | 1920 | eh->needs_copy = 1; |
edd21aca | 1921 | } |
252b5132 | 1922 | |
875c0872 | 1923 | sec = htab->sdynbss; |
edd21aca | 1924 | |
6cabe1ea | 1925 | return _bfd_elf_adjust_dynamic_copy (info, eh, sec); |
252b5132 RH |
1926 | } |
1927 | ||
e5ee5df1 | 1928 | /* Allocate space in the .plt for entries that won't have relocations. |
a252afa4 | 1929 | ie. plabel entries. */ |
a8d02d66 | 1930 | |
b34976b6 | 1931 | static bfd_boolean |
875c0872 | 1932 | allocate_plt_static (struct elf_link_hash_entry *eh, void *inf) |
a8d02d66 AM |
1933 | { |
1934 | struct bfd_link_info *info; | |
1935 | struct elf32_hppa_link_hash_table *htab; | |
875c0872 DA |
1936 | struct elf32_hppa_link_hash_entry *hh; |
1937 | asection *sec; | |
a8d02d66 | 1938 | |
875c0872 | 1939 | if (eh->root.type == bfd_link_hash_indirect) |
b34976b6 | 1940 | return TRUE; |
a8d02d66 | 1941 | |
875c0872 | 1942 | info = (struct bfd_link_info *) inf; |
9b52905e | 1943 | hh = hppa_elf_hash_entry (eh); |
a8d02d66 | 1944 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
1945 | if (htab == NULL) |
1946 | return FALSE; | |
1947 | ||
a63e02c7 | 1948 | if (htab->etab.dynamic_sections_created |
875c0872 | 1949 | && eh->plt.refcount > 0) |
e5ee5df1 AM |
1950 | { |
1951 | /* Make sure this symbol is output as a dynamic symbol. | |
1952 | Undefined weak syms won't yet be marked as dynamic. */ | |
875c0872 DA |
1953 | if (eh->dynindx == -1 |
1954 | && !eh->forced_local | |
1955 | && eh->type != STT_PARISC_MILLI) | |
a8d02d66 | 1956 | { |
875c0872 | 1957 | if (! bfd_elf_link_record_dynamic_symbol (info, eh)) |
b34976b6 | 1958 | return FALSE; |
e5ee5df1 AM |
1959 | } |
1960 | ||
0e1862bb | 1961 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), eh)) |
e5ee5df1 | 1962 | { |
067fa4a6 AM |
1963 | /* Allocate these later. From this point on, h->plabel |
1964 | means that the plt entry is only used by a plabel. | |
1965 | We'll be using a normal plt entry for this symbol, so | |
1966 | clear the plabel indicator. */ | |
68ffbac6 | 1967 | |
875c0872 | 1968 | hh->plabel = 0; |
e5ee5df1 | 1969 | } |
875c0872 | 1970 | else if (hh->plabel) |
e5ee5df1 AM |
1971 | { |
1972 | /* Make an entry in the .plt section for plabel references | |
1973 | that won't have a .plt entry for other reasons. */ | |
875c0872 DA |
1974 | sec = htab->splt; |
1975 | eh->plt.offset = sec->size; | |
1976 | sec->size += PLT_ENTRY_SIZE; | |
a8d02d66 AM |
1977 | } |
1978 | else | |
e5ee5df1 AM |
1979 | { |
1980 | /* No .plt entry needed. */ | |
875c0872 DA |
1981 | eh->plt.offset = (bfd_vma) -1; |
1982 | eh->needs_plt = 0; | |
e5ee5df1 AM |
1983 | } |
1984 | } | |
1985 | else | |
1986 | { | |
875c0872 DA |
1987 | eh->plt.offset = (bfd_vma) -1; |
1988 | eh->needs_plt = 0; | |
a8d02d66 AM |
1989 | } |
1990 | ||
b34976b6 | 1991 | return TRUE; |
a8d02d66 AM |
1992 | } |
1993 | ||
4dc86686 AM |
1994 | /* Allocate space in .plt, .got and associated reloc sections for |
1995 | global syms. */ | |
1996 | ||
b34976b6 | 1997 | static bfd_boolean |
875c0872 | 1998 | allocate_dynrelocs (struct elf_link_hash_entry *eh, void *inf) |
4dc86686 AM |
1999 | { |
2000 | struct bfd_link_info *info; | |
83c81bfe | 2001 | struct elf32_hppa_link_hash_table *htab; |
875c0872 DA |
2002 | asection *sec; |
2003 | struct elf32_hppa_link_hash_entry *hh; | |
2004 | struct elf32_hppa_dyn_reloc_entry *hdh_p; | |
4dc86686 | 2005 | |
875c0872 | 2006 | if (eh->root.type == bfd_link_hash_indirect) |
b34976b6 | 2007 | return TRUE; |
73a74a62 | 2008 | |
c39a58e6 | 2009 | info = inf; |
83c81bfe | 2010 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
2011 | if (htab == NULL) |
2012 | return FALSE; | |
2013 | ||
875c0872 | 2014 | hh = hppa_elf_hash_entry (eh); |
68ffbac6 | 2015 | |
a63e02c7 | 2016 | if (htab->etab.dynamic_sections_created |
875c0872 DA |
2017 | && eh->plt.offset != (bfd_vma) -1 |
2018 | && !hh->plabel | |
2019 | && eh->plt.refcount > 0) | |
4dc86686 | 2020 | { |
e5ee5df1 | 2021 | /* Make an entry in the .plt section. */ |
875c0872 DA |
2022 | sec = htab->splt; |
2023 | eh->plt.offset = sec->size; | |
2024 | sec->size += PLT_ENTRY_SIZE; | |
3ac8354b | 2025 | |
e5ee5df1 | 2026 | /* We also need to make an entry in the .rela.plt section. */ |
eea6121a | 2027 | htab->srelplt->size += sizeof (Elf32_External_Rela); |
e5ee5df1 | 2028 | htab->need_plt_stub = 1; |
4dc86686 | 2029 | } |
edd21aca | 2030 | |
875c0872 | 2031 | if (eh->got.refcount > 0) |
4dc86686 | 2032 | { |
446f2863 AM |
2033 | /* Make sure this symbol is output as a dynamic symbol. |
2034 | Undefined weak syms won't yet be marked as dynamic. */ | |
875c0872 DA |
2035 | if (eh->dynindx == -1 |
2036 | && !eh->forced_local | |
2037 | && eh->type != STT_PARISC_MILLI) | |
446f2863 | 2038 | { |
875c0872 | 2039 | if (! bfd_elf_link_record_dynamic_symbol (info, eh)) |
b34976b6 | 2040 | return FALSE; |
446f2863 AM |
2041 | } |
2042 | ||
875c0872 DA |
2043 | sec = htab->sgot; |
2044 | eh->got.offset = sec->size; | |
2045 | sec->size += GOT_ENTRY_SIZE; | |
9b52905e NC |
2046 | /* R_PARISC_TLS_GD* needs two GOT entries */ |
2047 | if ((hh->tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE)) | |
2048 | sec->size += GOT_ENTRY_SIZE * 2; | |
2049 | else if ((hh->tls_type & GOT_TLS_GD) == GOT_TLS_GD) | |
2050 | sec->size += GOT_ENTRY_SIZE; | |
a63e02c7 | 2051 | if (htab->etab.dynamic_sections_created |
0e1862bb | 2052 | && (bfd_link_pic (info) |
875c0872 DA |
2053 | || (eh->dynindx != -1 |
2054 | && !eh->forced_local))) | |
ce757d15 | 2055 | { |
eea6121a | 2056 | htab->srelgot->size += sizeof (Elf32_External_Rela); |
9b52905e NC |
2057 | if ((hh->tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE)) |
2058 | htab->srelgot->size += 2 * sizeof (Elf32_External_Rela); | |
2059 | else if ((hh->tls_type & GOT_TLS_GD) == GOT_TLS_GD) | |
2060 | htab->srelgot->size += sizeof (Elf32_External_Rela); | |
ce757d15 | 2061 | } |
4dc86686 AM |
2062 | } |
2063 | else | |
875c0872 | 2064 | eh->got.offset = (bfd_vma) -1; |
30667bf3 | 2065 | |
875c0872 | 2066 | if (hh->dyn_relocs == NULL) |
b34976b6 | 2067 | return TRUE; |
30667bf3 | 2068 | |
98ceb8ce AM |
2069 | /* If this is a -Bsymbolic shared link, then we need to discard all |
2070 | space allocated for dynamic pc-relative relocs against symbols | |
2071 | defined in a regular object. For the normal shared case, discard | |
2072 | space for relocs that have become local due to symbol visibility | |
2073 | changes. */ | |
0e1862bb | 2074 | if (bfd_link_pic (info)) |
446f2863 | 2075 | { |
98ceb8ce | 2076 | #if RELATIVE_DYNRELOCS |
875c0872 | 2077 | if (SYMBOL_CALLS_LOCAL (info, eh)) |
446f2863 | 2078 | { |
875c0872 | 2079 | struct elf32_hppa_dyn_reloc_entry **hdh_pp; |
30667bf3 | 2080 | |
875c0872 | 2081 | for (hdh_pp = &hh->dyn_relocs; (hdh_p = *hdh_pp) != NULL; ) |
98ceb8ce | 2082 | { |
875c0872 DA |
2083 | hdh_p->count -= hdh_p->relative_count; |
2084 | hdh_p->relative_count = 0; | |
2085 | if (hdh_p->count == 0) | |
a63e02c7 | 2086 | *hdh_pp = hdh_p->hdh_next; |
98ceb8ce | 2087 | else |
a63e02c7 | 2088 | hdh_pp = &hdh_p->hdh_next; |
98ceb8ce AM |
2089 | } |
2090 | } | |
2091 | #endif | |
4fc8051d AM |
2092 | |
2093 | /* Also discard relocs on undefined weak syms with non-default | |
2094 | visibility. */ | |
22d606e9 | 2095 | if (hh->dyn_relocs != NULL |
875c0872 | 2096 | && eh->root.type == bfd_link_hash_undefweak) |
22d606e9 AM |
2097 | { |
2098 | if (ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT) | |
2099 | hh->dyn_relocs = NULL; | |
2100 | ||
2101 | /* Make sure undefined weak symbols are output as a dynamic | |
2102 | symbol in PIEs. */ | |
2103 | else if (eh->dynindx == -1 | |
2104 | && !eh->forced_local) | |
2105 | { | |
2106 | if (! bfd_elf_link_record_dynamic_symbol (info, eh)) | |
2107 | return FALSE; | |
2108 | } | |
2109 | } | |
446f2863 | 2110 | } |
98ceb8ce | 2111 | else |
30667bf3 | 2112 | { |
98ceb8ce AM |
2113 | /* For the non-shared case, discard space for relocs against |
2114 | symbols which turn out to need copy relocs or are not | |
2115 | dynamic. */ | |
68ffbac6 | 2116 | |
875c0872 | 2117 | if (!eh->non_got_ref |
4fc8051d | 2118 | && ((ELIMINATE_COPY_RELOCS |
875c0872 DA |
2119 | && eh->def_dynamic |
2120 | && !eh->def_regular) | |
a63e02c7 | 2121 | || (htab->etab.dynamic_sections_created |
875c0872 DA |
2122 | && (eh->root.type == bfd_link_hash_undefweak |
2123 | || eh->root.type == bfd_link_hash_undefined)))) | |
98ceb8ce AM |
2124 | { |
2125 | /* Make sure this symbol is output as a dynamic symbol. | |
2126 | Undefined weak syms won't yet be marked as dynamic. */ | |
875c0872 DA |
2127 | if (eh->dynindx == -1 |
2128 | && !eh->forced_local | |
2129 | && eh->type != STT_PARISC_MILLI) | |
98ceb8ce | 2130 | { |
875c0872 | 2131 | if (! bfd_elf_link_record_dynamic_symbol (info, eh)) |
b34976b6 | 2132 | return FALSE; |
98ceb8ce AM |
2133 | } |
2134 | ||
2135 | /* If that succeeded, we know we'll be keeping all the | |
2136 | relocs. */ | |
875c0872 | 2137 | if (eh->dynindx != -1) |
98ceb8ce AM |
2138 | goto keep; |
2139 | } | |
446f2863 | 2140 | |
875c0872 | 2141 | hh->dyn_relocs = NULL; |
b34976b6 | 2142 | return TRUE; |
98ceb8ce | 2143 | |
ec338859 | 2144 | keep: ; |
30667bf3 | 2145 | } |
30667bf3 | 2146 | |
98ceb8ce | 2147 | /* Finally, allocate space. */ |
a63e02c7 | 2148 | for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next) |
30667bf3 | 2149 | { |
875c0872 DA |
2150 | asection *sreloc = elf_section_data (hdh_p->sec)->sreloc; |
2151 | sreloc->size += hdh_p->count * sizeof (Elf32_External_Rela); | |
30667bf3 | 2152 | } |
30667bf3 | 2153 | |
b34976b6 | 2154 | return TRUE; |
30667bf3 | 2155 | } |
30667bf3 | 2156 | |
d5c73c2f AM |
2157 | /* This function is called via elf_link_hash_traverse to force |
2158 | millicode symbols local so they do not end up as globals in the | |
2159 | dynamic symbol table. We ought to be able to do this in | |
2160 | adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called | |
2161 | for all dynamic symbols. Arguably, this is a bug in | |
2162 | elf_adjust_dynamic_symbol. */ | |
2163 | ||
b34976b6 | 2164 | static bfd_boolean |
875c0872 | 2165 | clobber_millicode_symbols (struct elf_link_hash_entry *eh, |
c39a58e6 | 2166 | struct bfd_link_info *info) |
d5c73c2f | 2167 | { |
875c0872 DA |
2168 | if (eh->type == STT_PARISC_MILLI |
2169 | && !eh->forced_local) | |
e0522e89 | 2170 | { |
875c0872 | 2171 | elf32_hppa_hide_symbol (info, eh, TRUE); |
e0522e89 | 2172 | } |
b34976b6 | 2173 | return TRUE; |
d5c73c2f AM |
2174 | } |
2175 | ||
98ceb8ce AM |
2176 | /* Find any dynamic relocs that apply to read-only sections. */ |
2177 | ||
b34976b6 | 2178 | static bfd_boolean |
875c0872 | 2179 | readonly_dynrelocs (struct elf_link_hash_entry *eh, void *inf) |
98ceb8ce | 2180 | { |
875c0872 DA |
2181 | struct elf32_hppa_link_hash_entry *hh; |
2182 | struct elf32_hppa_dyn_reloc_entry *hdh_p; | |
98ceb8ce | 2183 | |
875c0872 | 2184 | hh = hppa_elf_hash_entry (eh); |
a63e02c7 | 2185 | for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next) |
98ceb8ce | 2186 | { |
875c0872 | 2187 | asection *sec = hdh_p->sec->output_section; |
98ceb8ce | 2188 | |
875c0872 | 2189 | if (sec != NULL && (sec->flags & SEC_READONLY) != 0) |
98ceb8ce | 2190 | { |
c39a58e6 | 2191 | struct bfd_link_info *info = inf; |
98ceb8ce AM |
2192 | |
2193 | info->flags |= DF_TEXTREL; | |
2194 | ||
2195 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 2196 | return FALSE; |
98ceb8ce AM |
2197 | } |
2198 | } | |
b34976b6 | 2199 | return TRUE; |
98ceb8ce AM |
2200 | } |
2201 | ||
30667bf3 AM |
2202 | /* Set the sizes of the dynamic sections. */ |
2203 | ||
b34976b6 | 2204 | static bfd_boolean |
c39a58e6 AM |
2205 | elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
2206 | struct bfd_link_info *info) | |
30667bf3 | 2207 | { |
83c81bfe | 2208 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 | 2209 | bfd *dynobj; |
98ceb8ce | 2210 | bfd *ibfd; |
875c0872 | 2211 | asection *sec; |
b34976b6 | 2212 | bfd_boolean relocs; |
30667bf3 | 2213 | |
83c81bfe | 2214 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
2215 | if (htab == NULL) |
2216 | return FALSE; | |
2217 | ||
a63e02c7 | 2218 | dynobj = htab->etab.dynobj; |
49e9d0d3 AM |
2219 | if (dynobj == NULL) |
2220 | abort (); | |
30667bf3 | 2221 | |
a63e02c7 | 2222 | if (htab->etab.dynamic_sections_created) |
30667bf3 AM |
2223 | { |
2224 | /* Set the contents of the .interp section to the interpreter. */ | |
9b8b325a | 2225 | if (bfd_link_executable (info) && !info->nointerp) |
30667bf3 | 2226 | { |
3d4d4302 | 2227 | sec = bfd_get_linker_section (dynobj, ".interp"); |
875c0872 | 2228 | if (sec == NULL) |
49e9d0d3 | 2229 | abort (); |
875c0872 DA |
2230 | sec->size = sizeof ELF_DYNAMIC_INTERPRETER; |
2231 | sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
30667bf3 | 2232 | } |
74d1c347 | 2233 | |
d5c73c2f | 2234 | /* Force millicode symbols local. */ |
a63e02c7 | 2235 | elf_link_hash_traverse (&htab->etab, |
d5c73c2f AM |
2236 | clobber_millicode_symbols, |
2237 | info); | |
68fb2e56 | 2238 | } |
d5c73c2f | 2239 | |
98ceb8ce AM |
2240 | /* Set up .got and .plt offsets for local syms, and space for local |
2241 | dynamic relocs. */ | |
c72f2fb2 | 2242 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
68fb2e56 AM |
2243 | { |
2244 | bfd_signed_vma *local_got; | |
2245 | bfd_signed_vma *end_local_got; | |
2246 | bfd_signed_vma *local_plt; | |
2247 | bfd_signed_vma *end_local_plt; | |
2248 | bfd_size_type locsymcount; | |
2249 | Elf_Internal_Shdr *symtab_hdr; | |
2250 | asection *srel; | |
9b52905e | 2251 | char *local_tls_type; |
74d1c347 | 2252 | |
98ceb8ce | 2253 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
68fb2e56 | 2254 | continue; |
4dc86686 | 2255 | |
875c0872 | 2256 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
98ceb8ce | 2257 | { |
875c0872 | 2258 | struct elf32_hppa_dyn_reloc_entry *hdh_p; |
98ceb8ce | 2259 | |
875c0872 DA |
2260 | for (hdh_p = ((struct elf32_hppa_dyn_reloc_entry *) |
2261 | elf_section_data (sec)->local_dynrel); | |
2262 | hdh_p != NULL; | |
a63e02c7 | 2263 | hdh_p = hdh_p->hdh_next) |
98ceb8ce | 2264 | { |
875c0872 DA |
2265 | if (!bfd_is_abs_section (hdh_p->sec) |
2266 | && bfd_is_abs_section (hdh_p->sec->output_section)) | |
ec338859 AM |
2267 | { |
2268 | /* Input section has been discarded, either because | |
2269 | it is a copy of a linkonce section or due to | |
2270 | linker script /DISCARD/, so we'll be discarding | |
2271 | the relocs too. */ | |
2272 | } | |
875c0872 | 2273 | else if (hdh_p->count != 0) |
ec338859 | 2274 | { |
875c0872 DA |
2275 | srel = elf_section_data (hdh_p->sec)->sreloc; |
2276 | srel->size += hdh_p->count * sizeof (Elf32_External_Rela); | |
2277 | if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0) | |
248866a8 | 2278 | info->flags |= DF_TEXTREL; |
ec338859 | 2279 | } |
98ceb8ce AM |
2280 | } |
2281 | } | |
2282 | ||
2283 | local_got = elf_local_got_refcounts (ibfd); | |
68fb2e56 AM |
2284 | if (!local_got) |
2285 | continue; | |
74d1c347 | 2286 | |
98ceb8ce | 2287 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
68fb2e56 AM |
2288 | locsymcount = symtab_hdr->sh_info; |
2289 | end_local_got = local_got + locsymcount; | |
9b52905e | 2290 | local_tls_type = hppa_elf_local_got_tls_type (ibfd); |
875c0872 | 2291 | sec = htab->sgot; |
83c81bfe | 2292 | srel = htab->srelgot; |
68fb2e56 AM |
2293 | for (; local_got < end_local_got; ++local_got) |
2294 | { | |
2295 | if (*local_got > 0) | |
4dc86686 | 2296 | { |
875c0872 DA |
2297 | *local_got = sec->size; |
2298 | sec->size += GOT_ENTRY_SIZE; | |
9b52905e NC |
2299 | if ((*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE)) |
2300 | sec->size += 2 * GOT_ENTRY_SIZE; | |
2301 | else if ((*local_tls_type & GOT_TLS_GD) == GOT_TLS_GD) | |
2302 | sec->size += GOT_ENTRY_SIZE; | |
0e1862bb | 2303 | if (bfd_link_pic (info)) |
9b52905e NC |
2304 | { |
2305 | srel->size += sizeof (Elf32_External_Rela); | |
2306 | if ((*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE)) | |
2307 | srel->size += 2 * sizeof (Elf32_External_Rela); | |
2308 | else if ((*local_tls_type & GOT_TLS_GD) == GOT_TLS_GD) | |
2309 | srel->size += sizeof (Elf32_External_Rela); | |
2310 | } | |
4dc86686 | 2311 | } |
68fb2e56 AM |
2312 | else |
2313 | *local_got = (bfd_vma) -1; | |
9b52905e NC |
2314 | |
2315 | ++local_tls_type; | |
68fb2e56 | 2316 | } |
74d1c347 | 2317 | |
68fb2e56 AM |
2318 | local_plt = end_local_got; |
2319 | end_local_plt = local_plt + locsymcount; | |
a63e02c7 | 2320 | if (! htab->etab.dynamic_sections_created) |
68fb2e56 AM |
2321 | { |
2322 | /* Won't be used, but be safe. */ | |
2323 | for (; local_plt < end_local_plt; ++local_plt) | |
2324 | *local_plt = (bfd_vma) -1; | |
2325 | } | |
2326 | else | |
2327 | { | |
875c0872 | 2328 | sec = htab->splt; |
83c81bfe | 2329 | srel = htab->srelplt; |
74d1c347 AM |
2330 | for (; local_plt < end_local_plt; ++local_plt) |
2331 | { | |
2332 | if (*local_plt > 0) | |
2333 | { | |
875c0872 DA |
2334 | *local_plt = sec->size; |
2335 | sec->size += PLT_ENTRY_SIZE; | |
0e1862bb | 2336 | if (bfd_link_pic (info)) |
eea6121a | 2337 | srel->size += sizeof (Elf32_External_Rela); |
74d1c347 AM |
2338 | } |
2339 | else | |
2340 | *local_plt = (bfd_vma) -1; | |
2341 | } | |
2342 | } | |
30667bf3 | 2343 | } |
68ffbac6 | 2344 | |
9b52905e NC |
2345 | if (htab->tls_ldm_got.refcount > 0) |
2346 | { | |
68ffbac6 | 2347 | /* Allocate 2 got entries and 1 dynamic reloc for |
9b52905e NC |
2348 | R_PARISC_TLS_DTPMOD32 relocs. */ |
2349 | htab->tls_ldm_got.offset = htab->sgot->size; | |
2350 | htab->sgot->size += (GOT_ENTRY_SIZE * 2); | |
2351 | htab->srelgot->size += sizeof (Elf32_External_Rela); | |
2352 | } | |
2353 | else | |
2354 | htab->tls_ldm_got.offset = -1; | |
30667bf3 | 2355 | |
e5ee5df1 AM |
2356 | /* Do all the .plt entries without relocs first. The dynamic linker |
2357 | uses the last .plt reloc to find the end of the .plt (and hence | |
2358 | the start of the .got) for lazy linking. */ | |
a63e02c7 | 2359 | elf_link_hash_traverse (&htab->etab, allocate_plt_static, info); |
a8d02d66 | 2360 | |
98ceb8ce AM |
2361 | /* Allocate global sym .plt and .got entries, and space for global |
2362 | sym dynamic relocs. */ | |
a63e02c7 | 2363 | elf_link_hash_traverse (&htab->etab, allocate_dynrelocs, info); |
30667bf3 AM |
2364 | |
2365 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
2366 | determined the sizes of the various dynamic sections. Allocate | |
2367 | memory for them. */ | |
b34976b6 | 2368 | relocs = FALSE; |
875c0872 | 2369 | for (sec = dynobj->sections; sec != NULL; sec = sec->next) |
30667bf3 | 2370 | { |
875c0872 | 2371 | if ((sec->flags & SEC_LINKER_CREATED) == 0) |
30667bf3 AM |
2372 | continue; |
2373 | ||
875c0872 | 2374 | if (sec == htab->splt) |
68fb2e56 | 2375 | { |
83c81bfe | 2376 | if (htab->need_plt_stub) |
68fb2e56 AM |
2377 | { |
2378 | /* Make space for the plt stub at the end of the .plt | |
2379 | section. We want this stub right at the end, up | |
2380 | against the .got section. */ | |
83c81bfe | 2381 | int gotalign = bfd_section_alignment (dynobj, htab->sgot); |
875c0872 | 2382 | int pltalign = bfd_section_alignment (dynobj, sec); |
68fb2e56 | 2383 | bfd_size_type mask; |
30667bf3 | 2384 | |
68fb2e56 | 2385 | if (gotalign > pltalign) |
a253d456 | 2386 | (void) bfd_set_section_alignment (dynobj, sec, gotalign); |
68fb2e56 | 2387 | mask = ((bfd_size_type) 1 << gotalign) - 1; |
875c0872 | 2388 | sec->size = (sec->size + sizeof (plt_stub) + mask) & ~mask; |
68fb2e56 AM |
2389 | } |
2390 | } | |
c456f082 AM |
2391 | else if (sec == htab->sgot |
2392 | || sec == htab->sdynbss) | |
68fb2e56 | 2393 | ; |
0112cd26 | 2394 | else if (CONST_STRNEQ (bfd_get_section_name (dynobj, sec), ".rela")) |
30667bf3 | 2395 | { |
875c0872 | 2396 | if (sec->size != 0) |
30667bf3 | 2397 | { |
4e12ff7f AM |
2398 | /* Remember whether there are any reloc sections other |
2399 | than .rela.plt. */ | |
875c0872 | 2400 | if (sec != htab->srelplt) |
b34976b6 | 2401 | relocs = TRUE; |
47d89dba | 2402 | |
30667bf3 AM |
2403 | /* We use the reloc_count field as a counter if we need |
2404 | to copy relocs into the output file. */ | |
875c0872 | 2405 | sec->reloc_count = 0; |
30667bf3 AM |
2406 | } |
2407 | } | |
30667bf3 AM |
2408 | else |
2409 | { | |
2410 | /* It's not one of our sections, so don't allocate space. */ | |
2411 | continue; | |
2412 | } | |
2413 | ||
875c0872 | 2414 | if (sec->size == 0) |
30667bf3 AM |
2415 | { |
2416 | /* If we don't need this section, strip it from the | |
2417 | output file. This is mostly to handle .rela.bss and | |
2418 | .rela.plt. We must create both sections in | |
2419 | create_dynamic_sections, because they must be created | |
2420 | before the linker maps input sections to output | |
2421 | sections. The linker does that before | |
2422 | adjust_dynamic_symbol is called, and it is that | |
2423 | function which decides whether anything needs to go | |
2424 | into these sections. */ | |
875c0872 | 2425 | sec->flags |= SEC_EXCLUDE; |
30667bf3 AM |
2426 | continue; |
2427 | } | |
2428 | ||
c456f082 AM |
2429 | if ((sec->flags & SEC_HAS_CONTENTS) == 0) |
2430 | continue; | |
2431 | ||
30667bf3 AM |
2432 | /* Allocate memory for the section contents. Zero it, because |
2433 | we may not fill in all the reloc sections. */ | |
875c0872 | 2434 | sec->contents = bfd_zalloc (dynobj, sec->size); |
c456f082 | 2435 | if (sec->contents == NULL) |
b34976b6 | 2436 | return FALSE; |
30667bf3 AM |
2437 | } |
2438 | ||
a63e02c7 | 2439 | if (htab->etab.dynamic_sections_created) |
30667bf3 AM |
2440 | { |
2441 | /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It | |
2442 | actually has nothing to do with the PLT, it is how we | |
2443 | communicate the LTP value of a load module to the dynamic | |
2444 | linker. */ | |
dc810e39 | 2445 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 2446 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 AM |
2447 | |
2448 | if (!add_dynamic_entry (DT_PLTGOT, 0)) | |
b34976b6 | 2449 | return FALSE; |
30667bf3 AM |
2450 | |
2451 | /* Add some entries to the .dynamic section. We fill in the | |
2452 | values later, in elf32_hppa_finish_dynamic_sections, but we | |
2453 | must add the entries now so that we get the correct size for | |
2454 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
2455 | dynamic linker and used by the debugger. */ | |
0e1862bb | 2456 | if (bfd_link_executable (info)) |
30667bf3 | 2457 | { |
dc810e39 | 2458 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 2459 | return FALSE; |
30667bf3 AM |
2460 | } |
2461 | ||
eea6121a | 2462 | if (htab->srelplt->size != 0) |
30667bf3 | 2463 | { |
dc810e39 AM |
2464 | if (!add_dynamic_entry (DT_PLTRELSZ, 0) |
2465 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
2466 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 2467 | return FALSE; |
30667bf3 AM |
2468 | } |
2469 | ||
2470 | if (relocs) | |
2471 | { | |
dc810e39 AM |
2472 | if (!add_dynamic_entry (DT_RELA, 0) |
2473 | || !add_dynamic_entry (DT_RELASZ, 0) | |
2474 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
b34976b6 | 2475 | return FALSE; |
30667bf3 | 2476 | |
98ceb8ce AM |
2477 | /* If any dynamic relocs apply to a read-only section, |
2478 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 2479 | if ((info->flags & DF_TEXTREL) == 0) |
a63e02c7 | 2480 | elf_link_hash_traverse (&htab->etab, readonly_dynrelocs, info); |
98ceb8ce AM |
2481 | |
2482 | if ((info->flags & DF_TEXTREL) != 0) | |
2483 | { | |
2484 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
b34976b6 | 2485 | return FALSE; |
98ceb8ce | 2486 | } |
30667bf3 AM |
2487 | } |
2488 | } | |
dc810e39 | 2489 | #undef add_dynamic_entry |
30667bf3 | 2490 | |
b34976b6 | 2491 | return TRUE; |
30667bf3 AM |
2492 | } |
2493 | ||
30667bf3 AM |
2494 | /* External entry points for sizing and building linker stubs. */ |
2495 | ||
b4655ea9 AM |
2496 | /* Set up various things so that we can make a list of input sections |
2497 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 2498 | 0 when no stubs will be needed, and 1 on success. */ |
30667bf3 | 2499 | |
b4655ea9 | 2500 | int |
c39a58e6 | 2501 | elf32_hppa_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) |
30667bf3 AM |
2502 | { |
2503 | bfd *input_bfd; | |
b4655ea9 | 2504 | unsigned int bfd_count; |
7292b3ac | 2505 | unsigned int top_id, top_index; |
30667bf3 | 2506 | asection *section; |
25f72752 | 2507 | asection **input_list, **list; |
dc810e39 | 2508 | bfd_size_type amt; |
b4655ea9 | 2509 | struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); |
30667bf3 | 2510 | |
4dfe6ac6 NC |
2511 | if (htab == NULL) |
2512 | return -1; | |
2513 | ||
1badb539 AM |
2514 | /* Count the number of input BFDs and find the top input section id. */ |
2515 | for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; | |
30667bf3 | 2516 | input_bfd != NULL; |
c72f2fb2 | 2517 | input_bfd = input_bfd->link.next) |
30667bf3 AM |
2518 | { |
2519 | bfd_count += 1; | |
25f72752 AM |
2520 | for (section = input_bfd->sections; |
2521 | section != NULL; | |
2522 | section = section->next) | |
2523 | { | |
2524 | if (top_id < section->id) | |
2525 | top_id = section->id; | |
2526 | } | |
30667bf3 | 2527 | } |
b4655ea9 | 2528 | htab->bfd_count = bfd_count; |
30667bf3 | 2529 | |
dc810e39 | 2530 | amt = sizeof (struct map_stub) * (top_id + 1); |
c39a58e6 | 2531 | htab->stub_group = bfd_zmalloc (amt); |
83c81bfe | 2532 | if (htab->stub_group == NULL) |
b4655ea9 | 2533 | return -1; |
1badb539 | 2534 | |
b4655ea9 | 2535 | /* We can't use output_bfd->section_count here to find the top output |
1badb539 | 2536 | section index as some sections may have been removed, and |
8423293d | 2537 | strip_excluded_output_sections doesn't renumber the indices. */ |
1badb539 AM |
2538 | for (section = output_bfd->sections, top_index = 0; |
2539 | section != NULL; | |
2540 | section = section->next) | |
2541 | { | |
2542 | if (top_index < section->index) | |
2543 | top_index = section->index; | |
2544 | } | |
2545 | ||
b4655ea9 | 2546 | htab->top_index = top_index; |
dc810e39 | 2547 | amt = sizeof (asection *) * (top_index + 1); |
c39a58e6 | 2548 | input_list = bfd_malloc (amt); |
b4655ea9 | 2549 | htab->input_list = input_list; |
25f72752 | 2550 | if (input_list == NULL) |
b4655ea9 | 2551 | return -1; |
25f72752 | 2552 | |
1badb539 AM |
2553 | /* For sections we aren't interested in, mark their entries with a |
2554 | value we can check later. */ | |
2555 | list = input_list + top_index; | |
2556 | do | |
2557 | *list = bfd_abs_section_ptr; | |
2558 | while (list-- != input_list); | |
2559 | ||
2560 | for (section = output_bfd->sections; | |
2561 | section != NULL; | |
2562 | section = section->next) | |
2563 | { | |
47d89dba | 2564 | if ((section->flags & SEC_CODE) != 0) |
1badb539 AM |
2565 | input_list[section->index] = NULL; |
2566 | } | |
2567 | ||
b4655ea9 AM |
2568 | return 1; |
2569 | } | |
2570 | ||
2571 | /* The linker repeatedly calls this function for each input section, | |
2572 | in the order that input sections are linked into output sections. | |
2573 | Build lists of input sections to determine groupings between which | |
2574 | we may insert linker stubs. */ | |
2575 | ||
2576 | void | |
c39a58e6 | 2577 | elf32_hppa_next_input_section (struct bfd_link_info *info, asection *isec) |
b4655ea9 AM |
2578 | { |
2579 | struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); | |
2580 | ||
4dfe6ac6 NC |
2581 | if (htab == NULL) |
2582 | return; | |
2583 | ||
b4655ea9 | 2584 | if (isec->output_section->index <= htab->top_index) |
25f72752 | 2585 | { |
b4655ea9 AM |
2586 | asection **list = htab->input_list + isec->output_section->index; |
2587 | if (*list != bfd_abs_section_ptr) | |
25f72752 | 2588 | { |
b4655ea9 | 2589 | /* Steal the link_sec pointer for our list. */ |
83c81bfe | 2590 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
b4655ea9 AM |
2591 | /* This happens to make the list in reverse order, |
2592 | which is what we want. */ | |
2593 | PREV_SEC (isec) = *list; | |
2594 | *list = isec; | |
25f72752 AM |
2595 | } |
2596 | } | |
b4655ea9 | 2597 | } |
25f72752 | 2598 | |
b4655ea9 AM |
2599 | /* See whether we can group stub sections together. Grouping stub |
2600 | sections may result in fewer stubs. More importantly, we need to | |
2601 | put all .init* and .fini* stubs at the beginning of the .init or | |
2602 | .fini output sections respectively, because glibc splits the | |
2603 | _init and _fini functions into multiple parts. Putting a stub in | |
2604 | the middle of a function is not a good idea. */ | |
2605 | ||
2606 | static void | |
c39a58e6 AM |
2607 | group_sections (struct elf32_hppa_link_hash_table *htab, |
2608 | bfd_size_type stub_group_size, | |
2609 | bfd_boolean stubs_always_before_branch) | |
b4655ea9 AM |
2610 | { |
2611 | asection **list = htab->input_list + htab->top_index; | |
1badb539 | 2612 | do |
25f72752 AM |
2613 | { |
2614 | asection *tail = *list; | |
1badb539 AM |
2615 | if (tail == bfd_abs_section_ptr) |
2616 | continue; | |
25f72752 AM |
2617 | while (tail != NULL) |
2618 | { | |
2619 | asection *curr; | |
2620 | asection *prev; | |
2621 | bfd_size_type total; | |
00b28bb0 | 2622 | bfd_boolean big_sec; |
25f72752 AM |
2623 | |
2624 | curr = tail; | |
eea6121a | 2625 | total = tail->size; |
00b28bb0 AM |
2626 | big_sec = total >= stub_group_size; |
2627 | ||
25f72752 AM |
2628 | while ((prev = PREV_SEC (curr)) != NULL |
2629 | && ((total += curr->output_offset - prev->output_offset) | |
47d89dba | 2630 | < stub_group_size)) |
25f72752 AM |
2631 | curr = prev; |
2632 | ||
2633 | /* OK, the size from the start of CURR to the end is less | |
a248e267 | 2634 | than 240000 bytes and thus can be handled by one stub |
25f72752 | 2635 | section. (or the tail section is itself larger than |
a248e267 | 2636 | 240000 bytes, in which case we may be toast.) |
25f72752 AM |
2637 | We should really be keeping track of the total size of |
2638 | stubs added here, as stubs contribute to the final output | |
2639 | section size. That's a little tricky, and this way will | |
a248e267 AM |
2640 | only break if stubs added total more than 22144 bytes, or |
2641 | 2768 long branch stubs. It seems unlikely for more than | |
2642 | 2768 different functions to be called, especially from | |
2643 | code only 240000 bytes long. This limit used to be | |
2644 | 250000, but c++ code tends to generate lots of little | |
2645 | functions, and sometimes violated the assumption. */ | |
25f72752 AM |
2646 | do |
2647 | { | |
2648 | prev = PREV_SEC (tail); | |
2649 | /* Set up this stub group. */ | |
83c81bfe | 2650 | htab->stub_group[tail->id].link_sec = curr; |
25f72752 AM |
2651 | } |
2652 | while (tail != curr && (tail = prev) != NULL); | |
2653 | ||
a248e267 | 2654 | /* But wait, there's more! Input sections up to 240000 |
00b28bb0 AM |
2655 | bytes before the stub section can be handled by it too. |
2656 | Don't do this if we have a really large section after the | |
2657 | stubs, as adding more stubs increases the chance that | |
2658 | branches may not reach into the stub section. */ | |
2659 | if (!stubs_always_before_branch && !big_sec) | |
25f72752 | 2660 | { |
47d89dba AM |
2661 | total = 0; |
2662 | while (prev != NULL | |
2663 | && ((total += tail->output_offset - prev->output_offset) | |
2664 | < stub_group_size)) | |
2665 | { | |
2666 | tail = prev; | |
2667 | prev = PREV_SEC (tail); | |
83c81bfe | 2668 | htab->stub_group[tail->id].link_sec = curr; |
47d89dba | 2669 | } |
25f72752 AM |
2670 | } |
2671 | tail = prev; | |
2672 | } | |
2673 | } | |
b4655ea9 AM |
2674 | while (list-- != htab->input_list); |
2675 | free (htab->input_list); | |
1badb539 | 2676 | #undef PREV_SEC |
b4655ea9 AM |
2677 | } |
2678 | ||
2679 | /* Read in all local syms for all input bfds, and create hash entries | |
2680 | for export stubs if we are building a multi-subspace shared lib. | |
2681 | Returns -1 on error, 1 if export stubs created, 0 otherwise. */ | |
2682 | ||
2683 | static int | |
c39a58e6 | 2684 | get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info) |
b4655ea9 AM |
2685 | { |
2686 | unsigned int bfd_indx; | |
2687 | Elf_Internal_Sym *local_syms, **all_local_syms; | |
2688 | int stub_changed = 0; | |
2689 | struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); | |
30667bf3 | 2690 | |
4dfe6ac6 NC |
2691 | if (htab == NULL) |
2692 | return -1; | |
2693 | ||
30667bf3 AM |
2694 | /* We want to read in symbol extension records only once. To do this |
2695 | we need to read in the local symbols in parallel and save them for | |
2696 | later use; so hold pointers to the local symbols in an array. */ | |
b4655ea9 | 2697 | bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count; |
c39a58e6 | 2698 | all_local_syms = bfd_zmalloc (amt); |
b4655ea9 | 2699 | htab->all_local_syms = all_local_syms; |
30667bf3 | 2700 | if (all_local_syms == NULL) |
b4655ea9 | 2701 | return -1; |
30667bf3 AM |
2702 | |
2703 | /* Walk over all the input BFDs, swapping in local symbols. | |
2704 | If we are creating a shared library, create hash entries for the | |
2705 | export stubs. */ | |
b4655ea9 | 2706 | for (bfd_indx = 0; |
30667bf3 | 2707 | input_bfd != NULL; |
c72f2fb2 | 2708 | input_bfd = input_bfd->link.next, bfd_indx++) |
30667bf3 AM |
2709 | { |
2710 | Elf_Internal_Shdr *symtab_hdr; | |
edd21aca | 2711 | |
252b5132 RH |
2712 | /* We'll need the symbol table in a second. */ |
2713 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
2714 | if (symtab_hdr->sh_info == 0) | |
2715 | continue; | |
2716 | ||
6cdc0ccc AM |
2717 | /* We need an array of the local symbols attached to the input bfd. */ |
2718 | local_syms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
edd21aca | 2719 | if (local_syms == NULL) |
edd21aca | 2720 | { |
6cdc0ccc AM |
2721 | local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, |
2722 | symtab_hdr->sh_info, 0, | |
2723 | NULL, NULL, NULL); | |
2724 | /* Cache them for elf_link_input_bfd. */ | |
2725 | symtab_hdr->contents = (unsigned char *) local_syms; | |
edd21aca | 2726 | } |
6cdc0ccc AM |
2727 | if (local_syms == NULL) |
2728 | return -1; | |
edd21aca | 2729 | |
6cdc0ccc | 2730 | all_local_syms[bfd_indx] = local_syms; |
edd21aca | 2731 | |
0e1862bb | 2732 | if (bfd_link_pic (info) && htab->multi_subspace) |
30667bf3 | 2733 | { |
875c0872 DA |
2734 | struct elf_link_hash_entry **eh_syms; |
2735 | struct elf_link_hash_entry **eh_symend; | |
30667bf3 AM |
2736 | unsigned int symcount; |
2737 | ||
2738 | symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) | |
2739 | - symtab_hdr->sh_info); | |
875c0872 DA |
2740 | eh_syms = (struct elf_link_hash_entry **) elf_sym_hashes (input_bfd); |
2741 | eh_symend = (struct elf_link_hash_entry **) (eh_syms + symcount); | |
30667bf3 AM |
2742 | |
2743 | /* Look through the global syms for functions; We need to | |
2744 | build export stubs for all globally visible functions. */ | |
875c0872 | 2745 | for (; eh_syms < eh_symend; eh_syms++) |
30667bf3 | 2746 | { |
875c0872 | 2747 | struct elf32_hppa_link_hash_entry *hh; |
30667bf3 | 2748 | |
875c0872 | 2749 | hh = hppa_elf_hash_entry (*eh_syms); |
30667bf3 | 2750 | |
a63e02c7 DA |
2751 | while (hh->eh.root.type == bfd_link_hash_indirect |
2752 | || hh->eh.root.type == bfd_link_hash_warning) | |
2753 | hh = hppa_elf_hash_entry (hh->eh.root.u.i.link); | |
30667bf3 AM |
2754 | |
2755 | /* At this point in the link, undefined syms have been | |
2756 | resolved, so we need to check that the symbol was | |
2757 | defined in this BFD. */ | |
a63e02c7 DA |
2758 | if ((hh->eh.root.type == bfd_link_hash_defined |
2759 | || hh->eh.root.type == bfd_link_hash_defweak) | |
2760 | && hh->eh.type == STT_FUNC | |
2761 | && hh->eh.root.u.def.section->output_section != NULL | |
2762 | && (hh->eh.root.u.def.section->output_section->owner | |
25f72752 | 2763 | == output_bfd) |
a63e02c7 DA |
2764 | && hh->eh.root.u.def.section->owner == input_bfd |
2765 | && hh->eh.def_regular | |
2766 | && !hh->eh.forced_local | |
2767 | && ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT) | |
30667bf3 AM |
2768 | { |
2769 | asection *sec; | |
2770 | const char *stub_name; | |
875c0872 | 2771 | struct elf32_hppa_stub_hash_entry *hsh; |
30667bf3 | 2772 | |
a63e02c7 | 2773 | sec = hh->eh.root.u.def.section; |
9b52905e | 2774 | stub_name = hh_name (hh); |
a63e02c7 | 2775 | hsh = hppa_stub_hash_lookup (&htab->bstab, |
30667bf3 | 2776 | stub_name, |
b34976b6 | 2777 | FALSE, FALSE); |
875c0872 | 2778 | if (hsh == NULL) |
30667bf3 | 2779 | { |
875c0872 DA |
2780 | hsh = hppa_add_stub (stub_name, sec, htab); |
2781 | if (!hsh) | |
b4655ea9 | 2782 | return -1; |
30667bf3 | 2783 | |
a63e02c7 DA |
2784 | hsh->target_value = hh->eh.root.u.def.value; |
2785 | hsh->target_section = hh->eh.root.u.def.section; | |
875c0872 | 2786 | hsh->stub_type = hppa_stub_export; |
a63e02c7 | 2787 | hsh->hh = hh; |
30667bf3 AM |
2788 | stub_changed = 1; |
2789 | } | |
2790 | else | |
2791 | { | |
d003868e AM |
2792 | (*_bfd_error_handler) (_("%B: duplicate export stub %s"), |
2793 | input_bfd, | |
8f615d07 | 2794 | stub_name); |
30667bf3 AM |
2795 | } |
2796 | } | |
2797 | } | |
30667bf3 AM |
2798 | } |
2799 | } | |
edd21aca | 2800 | |
b4655ea9 AM |
2801 | return stub_changed; |
2802 | } | |
2803 | ||
2804 | /* Determine and set the size of the stub section for a final link. | |
2805 | ||
2806 | The basic idea here is to examine all the relocations looking for | |
2807 | PC-relative calls to a target that is unreachable with a "bl" | |
2808 | instruction. */ | |
2809 | ||
b34976b6 | 2810 | bfd_boolean |
c39a58e6 AM |
2811 | elf32_hppa_size_stubs |
2812 | (bfd *output_bfd, bfd *stub_bfd, struct bfd_link_info *info, | |
2813 | bfd_boolean multi_subspace, bfd_signed_vma group_size, | |
2814 | asection * (*add_stub_section) (const char *, asection *), | |
2815 | void (*layout_sections_again) (void)) | |
b4655ea9 AM |
2816 | { |
2817 | bfd_size_type stub_group_size; | |
b34976b6 AM |
2818 | bfd_boolean stubs_always_before_branch; |
2819 | bfd_boolean stub_changed; | |
b4655ea9 AM |
2820 | struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); |
2821 | ||
4dfe6ac6 NC |
2822 | if (htab == NULL) |
2823 | return FALSE; | |
2824 | ||
b4655ea9 AM |
2825 | /* Stash our params away. */ |
2826 | htab->stub_bfd = stub_bfd; | |
2827 | htab->multi_subspace = multi_subspace; | |
2828 | htab->add_stub_section = add_stub_section; | |
2829 | htab->layout_sections_again = layout_sections_again; | |
2830 | stubs_always_before_branch = group_size < 0; | |
2831 | if (group_size < 0) | |
2832 | stub_group_size = -group_size; | |
2833 | else | |
2834 | stub_group_size = group_size; | |
2835 | if (stub_group_size == 1) | |
2836 | { | |
2837 | /* Default values. */ | |
acc990f2 AM |
2838 | if (stubs_always_before_branch) |
2839 | { | |
2840 | stub_group_size = 7680000; | |
2841 | if (htab->has_17bit_branch || htab->multi_subspace) | |
2842 | stub_group_size = 240000; | |
2843 | if (htab->has_12bit_branch) | |
2844 | stub_group_size = 7500; | |
2845 | } | |
2846 | else | |
2847 | { | |
2848 | stub_group_size = 6971392; | |
2849 | if (htab->has_17bit_branch || htab->multi_subspace) | |
2850 | stub_group_size = 217856; | |
2851 | if (htab->has_12bit_branch) | |
2852 | stub_group_size = 6808; | |
2853 | } | |
b4655ea9 AM |
2854 | } |
2855 | ||
2856 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
2857 | ||
2858 | switch (get_local_syms (output_bfd, info->input_bfds, info)) | |
2859 | { | |
2860 | default: | |
2861 | if (htab->all_local_syms) | |
2862 | goto error_ret_free_local; | |
b34976b6 | 2863 | return FALSE; |
b4655ea9 AM |
2864 | |
2865 | case 0: | |
b34976b6 | 2866 | stub_changed = FALSE; |
b4655ea9 AM |
2867 | break; |
2868 | ||
2869 | case 1: | |
b34976b6 | 2870 | stub_changed = TRUE; |
b4655ea9 AM |
2871 | break; |
2872 | } | |
2873 | ||
edd21aca AM |
2874 | while (1) |
2875 | { | |
b4655ea9 AM |
2876 | bfd *input_bfd; |
2877 | unsigned int bfd_indx; | |
30667bf3 AM |
2878 | asection *stub_sec; |
2879 | ||
25f72752 | 2880 | for (input_bfd = info->input_bfds, bfd_indx = 0; |
30667bf3 | 2881 | input_bfd != NULL; |
c72f2fb2 | 2882 | input_bfd = input_bfd->link.next, bfd_indx++) |
30667bf3 AM |
2883 | { |
2884 | Elf_Internal_Shdr *symtab_hdr; | |
b4655ea9 AM |
2885 | asection *section; |
2886 | Elf_Internal_Sym *local_syms; | |
30667bf3 AM |
2887 | |
2888 | /* We'll need the symbol table in a second. */ | |
2889 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
2890 | if (symtab_hdr->sh_info == 0) | |
2891 | continue; | |
2892 | ||
b4655ea9 | 2893 | local_syms = htab->all_local_syms[bfd_indx]; |
30667bf3 AM |
2894 | |
2895 | /* Walk over each section attached to the input bfd. */ | |
2896 | for (section = input_bfd->sections; | |
2897 | section != NULL; | |
25f72752 | 2898 | section = section->next) |
30667bf3 | 2899 | { |
30667bf3 AM |
2900 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
2901 | ||
2902 | /* If there aren't any relocs, then there's nothing more | |
2903 | to do. */ | |
2904 | if ((section->flags & SEC_RELOC) == 0 | |
2905 | || section->reloc_count == 0) | |
2906 | continue; | |
2907 | ||
25f72752 AM |
2908 | /* If this section is a link-once section that will be |
2909 | discarded, then don't create any stubs. */ | |
2910 | if (section->output_section == NULL | |
2911 | || section->output_section->owner != output_bfd) | |
2912 | continue; | |
2913 | ||
1e2f5b6e AM |
2914 | /* Get the relocs. */ |
2915 | internal_relocs | |
c39a58e6 | 2916 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
45d6a902 | 2917 | info->keep_memory); |
30667bf3 | 2918 | if (internal_relocs == NULL) |
1e2f5b6e | 2919 | goto error_ret_free_local; |
30667bf3 AM |
2920 | |
2921 | /* Now examine each relocation. */ | |
2922 | irela = internal_relocs; | |
2923 | irelaend = irela + section->reloc_count; | |
2924 | for (; irela < irelaend; irela++) | |
2925 | { | |
2926 | unsigned int r_type, r_indx; | |
2927 | enum elf32_hppa_stub_type stub_type; | |
875c0872 | 2928 | struct elf32_hppa_stub_hash_entry *hsh; |
30667bf3 AM |
2929 | asection *sym_sec; |
2930 | bfd_vma sym_value; | |
2931 | bfd_vma destination; | |
875c0872 | 2932 | struct elf32_hppa_link_hash_entry *hh; |
30667bf3 | 2933 | char *stub_name; |
25f72752 | 2934 | const asection *id_sec; |
30667bf3 AM |
2935 | |
2936 | r_type = ELF32_R_TYPE (irela->r_info); | |
2937 | r_indx = ELF32_R_SYM (irela->r_info); | |
2938 | ||
2939 | if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED) | |
2940 | { | |
2941 | bfd_set_error (bfd_error_bad_value); | |
1e2f5b6e AM |
2942 | error_ret_free_internal: |
2943 | if (elf_section_data (section)->relocs == NULL) | |
2944 | free (internal_relocs); | |
2945 | goto error_ret_free_local; | |
30667bf3 AM |
2946 | } |
2947 | ||
2948 | /* Only look for stubs on call instructions. */ | |
2949 | if (r_type != (unsigned int) R_PARISC_PCREL12F | |
2950 | && r_type != (unsigned int) R_PARISC_PCREL17F | |
2951 | && r_type != (unsigned int) R_PARISC_PCREL22F) | |
2952 | continue; | |
2953 | ||
2954 | /* Now determine the call target, its name, value, | |
2955 | section. */ | |
2956 | sym_sec = NULL; | |
2957 | sym_value = 0; | |
2958 | destination = 0; | |
875c0872 | 2959 | hh = NULL; |
30667bf3 AM |
2960 | if (r_indx < symtab_hdr->sh_info) |
2961 | { | |
2962 | /* It's a local symbol. */ | |
2963 | Elf_Internal_Sym *sym; | |
2964 | Elf_Internal_Shdr *hdr; | |
4fbb74a6 | 2965 | unsigned int shndx; |
30667bf3 AM |
2966 | |
2967 | sym = local_syms + r_indx; | |
30667bf3 AM |
2968 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) |
2969 | sym_value = sym->st_value; | |
4fbb74a6 AM |
2970 | shndx = sym->st_shndx; |
2971 | if (shndx < elf_numsections (input_bfd)) | |
2972 | { | |
2973 | hdr = elf_elfsections (input_bfd)[shndx]; | |
2974 | sym_sec = hdr->bfd_section; | |
2975 | destination = (sym_value + irela->r_addend | |
2976 | + sym_sec->output_offset | |
2977 | + sym_sec->output_section->vma); | |
2978 | } | |
30667bf3 AM |
2979 | } |
2980 | else | |
2981 | { | |
2982 | /* It's an external symbol. */ | |
2983 | int e_indx; | |
2984 | ||
2985 | e_indx = r_indx - symtab_hdr->sh_info; | |
875c0872 | 2986 | hh = hppa_elf_hash_entry (elf_sym_hashes (input_bfd)[e_indx]); |
30667bf3 | 2987 | |
a63e02c7 DA |
2988 | while (hh->eh.root.type == bfd_link_hash_indirect |
2989 | || hh->eh.root.type == bfd_link_hash_warning) | |
2990 | hh = hppa_elf_hash_entry (hh->eh.root.u.i.link); | |
30667bf3 | 2991 | |
a63e02c7 DA |
2992 | if (hh->eh.root.type == bfd_link_hash_defined |
2993 | || hh->eh.root.type == bfd_link_hash_defweak) | |
30667bf3 | 2994 | { |
a63e02c7 DA |
2995 | sym_sec = hh->eh.root.u.def.section; |
2996 | sym_value = hh->eh.root.u.def.value; | |
30667bf3 AM |
2997 | if (sym_sec->output_section != NULL) |
2998 | destination = (sym_value + irela->r_addend | |
2999 | + sym_sec->output_offset | |
3000 | + sym_sec->output_section->vma); | |
3001 | } | |
a63e02c7 | 3002 | else if (hh->eh.root.type == bfd_link_hash_undefweak) |
c432ba1a | 3003 | { |
0e1862bb | 3004 | if (! bfd_link_pic (info)) |
c432ba1a AM |
3005 | continue; |
3006 | } | |
a63e02c7 | 3007 | else if (hh->eh.root.type == bfd_link_hash_undefined) |
c432ba1a | 3008 | { |
59c2e50f | 3009 | if (! (info->unresolved_syms_in_objects == RM_IGNORE |
a63e02c7 | 3010 | && (ELF_ST_VISIBILITY (hh->eh.other) |
c432ba1a | 3011 | == STV_DEFAULT) |
a63e02c7 | 3012 | && hh->eh.type != STT_PARISC_MILLI)) |
c432ba1a AM |
3013 | continue; |
3014 | } | |
30667bf3 AM |
3015 | else |
3016 | { | |
3017 | bfd_set_error (bfd_error_bad_value); | |
3018 | goto error_ret_free_internal; | |
3019 | } | |
3020 | } | |
3021 | ||
3022 | /* Determine what (if any) linker stub is needed. */ | |
875c0872 | 3023 | stub_type = hppa_type_of_stub (section, irela, hh, |
a252afa4 | 3024 | destination, info); |
30667bf3 AM |
3025 | if (stub_type == hppa_stub_none) |
3026 | continue; | |
3027 | ||
25f72752 | 3028 | /* Support for grouping stub sections. */ |
83c81bfe | 3029 | id_sec = htab->stub_group[section->id].link_sec; |
25f72752 | 3030 | |
30667bf3 | 3031 | /* Get the name of this stub. */ |
875c0872 | 3032 | stub_name = hppa_stub_name (id_sec, sym_sec, hh, irela); |
30667bf3 AM |
3033 | if (!stub_name) |
3034 | goto error_ret_free_internal; | |
3035 | ||
a63e02c7 | 3036 | hsh = hppa_stub_hash_lookup (&htab->bstab, |
30667bf3 | 3037 | stub_name, |
b34976b6 | 3038 | FALSE, FALSE); |
875c0872 | 3039 | if (hsh != NULL) |
30667bf3 AM |
3040 | { |
3041 | /* The proper stub has already been created. */ | |
3042 | free (stub_name); | |
3043 | continue; | |
3044 | } | |
3045 | ||
875c0872 DA |
3046 | hsh = hppa_add_stub (stub_name, section, htab); |
3047 | if (hsh == NULL) | |
30667bf3 AM |
3048 | { |
3049 | free (stub_name); | |
1e2f5b6e | 3050 | goto error_ret_free_internal; |
30667bf3 AM |
3051 | } |
3052 | ||
875c0872 DA |
3053 | hsh->target_value = sym_value; |
3054 | hsh->target_section = sym_sec; | |
3055 | hsh->stub_type = stub_type; | |
0e1862bb | 3056 | if (bfd_link_pic (info)) |
30667bf3 AM |
3057 | { |
3058 | if (stub_type == hppa_stub_import) | |
875c0872 | 3059 | hsh->stub_type = hppa_stub_import_shared; |
98ceb8ce | 3060 | else if (stub_type == hppa_stub_long_branch) |
875c0872 | 3061 | hsh->stub_type = hppa_stub_long_branch_shared; |
30667bf3 | 3062 | } |
a63e02c7 | 3063 | hsh->hh = hh; |
b34976b6 | 3064 | stub_changed = TRUE; |
30667bf3 AM |
3065 | } |
3066 | ||
3067 | /* We're done with the internal relocs, free them. */ | |
1e2f5b6e AM |
3068 | if (elf_section_data (section)->relocs == NULL) |
3069 | free (internal_relocs); | |
30667bf3 AM |
3070 | } |
3071 | } | |
3072 | ||
3073 | if (!stub_changed) | |
3074 | break; | |
3075 | ||
3076 | /* OK, we've added some stubs. Find out the new size of the | |
3077 | stub sections. */ | |
83c81bfe | 3078 | for (stub_sec = htab->stub_bfd->sections; |
30667bf3 AM |
3079 | stub_sec != NULL; |
3080 | stub_sec = stub_sec->next) | |
a464198b AM |
3081 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
3082 | stub_sec->size = 0; | |
74d1c347 | 3083 | |
a63e02c7 | 3084 | bfd_hash_traverse (&htab->bstab, hppa_size_one_stub, htab); |
74d1c347 | 3085 | |
30667bf3 | 3086 | /* Ask the linker to do its stuff. */ |
83c81bfe | 3087 | (*htab->layout_sections_again) (); |
b34976b6 | 3088 | stub_changed = FALSE; |
30667bf3 AM |
3089 | } |
3090 | ||
6cdc0ccc | 3091 | free (htab->all_local_syms); |
b34976b6 | 3092 | return TRUE; |
30667bf3 AM |
3093 | |
3094 | error_ret_free_local: | |
b4655ea9 | 3095 | free (htab->all_local_syms); |
b34976b6 | 3096 | return FALSE; |
30667bf3 AM |
3097 | } |
3098 | ||
30667bf3 AM |
3099 | /* For a final link, this function is called after we have sized the |
3100 | stubs to provide a value for __gp. */ | |
3101 | ||
b34976b6 | 3102 | bfd_boolean |
c39a58e6 | 3103 | elf32_hppa_set_gp (bfd *abfd, struct bfd_link_info *info) |
30667bf3 | 3104 | { |
b4655ea9 AM |
3105 | struct bfd_link_hash_entry *h; |
3106 | asection *sec = NULL; | |
3107 | bfd_vma gp_val = 0; | |
83c81bfe | 3108 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 | 3109 | |
83c81bfe | 3110 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
3111 | if (htab == NULL) |
3112 | return FALSE; | |
3113 | ||
a63e02c7 | 3114 | h = bfd_link_hash_lookup (&htab->etab.root, "$global$", FALSE, FALSE, FALSE); |
30667bf3 | 3115 | |
df8634e3 | 3116 | if (h != NULL |
b4655ea9 AM |
3117 | && (h->type == bfd_link_hash_defined |
3118 | || h->type == bfd_link_hash_defweak)) | |
30667bf3 | 3119 | { |
b4655ea9 AM |
3120 | gp_val = h->u.def.value; |
3121 | sec = h->u.def.section; | |
30667bf3 AM |
3122 | } |
3123 | else | |
3124 | { | |
0eddce27 AM |
3125 | asection *splt = bfd_get_section_by_name (abfd, ".plt"); |
3126 | asection *sgot = bfd_get_section_by_name (abfd, ".got"); | |
b4655ea9 | 3127 | |
74d1c347 AM |
3128 | /* Choose to point our LTP at, in this order, one of .plt, .got, |
3129 | or .data, if these sections exist. In the case of choosing | |
3130 | .plt try to make the LTP ideal for addressing anywhere in the | |
3131 | .plt or .got with a 14 bit signed offset. Typically, the end | |
3132 | of the .plt is the start of the .got, so choose .plt + 0x2000 | |
3133 | if either the .plt or .got is larger than 0x2000. If both | |
3134 | the .plt and .got are smaller than 0x2000, choose the end of | |
3135 | the .plt section. */ | |
225247f0 JT |
3136 | sec = strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") == 0 |
3137 | ? NULL : splt; | |
74d1c347 | 3138 | if (sec != NULL) |
30667bf3 | 3139 | { |
eea6121a AM |
3140 | gp_val = sec->size; |
3141 | if (gp_val > 0x2000 || (sgot && sgot->size > 0x2000)) | |
74d1c347 AM |
3142 | { |
3143 | gp_val = 0x2000; | |
3144 | } | |
3145 | } | |
3146 | else | |
3147 | { | |
b4655ea9 | 3148 | sec = sgot; |
74d1c347 AM |
3149 | if (sec != NULL) |
3150 | { | |
225247f0 JT |
3151 | if (strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") != 0) |
3152 | { | |
3153 | /* We know we don't have a .plt. If .got is large, | |
3154 | offset our LTP. */ | |
3155 | if (sec->size > 0x2000) | |
3156 | gp_val = 0x2000; | |
3157 | } | |
74d1c347 AM |
3158 | } |
3159 | else | |
3160 | { | |
3161 | /* No .plt or .got. Who cares what the LTP is? */ | |
3162 | sec = bfd_get_section_by_name (abfd, ".data"); | |
3163 | } | |
30667bf3 | 3164 | } |
df8634e3 AM |
3165 | |
3166 | if (h != NULL) | |
3167 | { | |
b4655ea9 AM |
3168 | h->type = bfd_link_hash_defined; |
3169 | h->u.def.value = gp_val; | |
df8634e3 | 3170 | if (sec != NULL) |
b4655ea9 | 3171 | h->u.def.section = sec; |
df8634e3 | 3172 | else |
b4655ea9 | 3173 | h->u.def.section = bfd_abs_section_ptr; |
df8634e3 | 3174 | } |
30667bf3 AM |
3175 | } |
3176 | ||
b32b5d6e | 3177 | if (sec != NULL && sec->output_section != NULL) |
74d1c347 AM |
3178 | gp_val += sec->output_section->vma + sec->output_offset; |
3179 | ||
3180 | elf_gp (abfd) = gp_val; | |
b34976b6 | 3181 | return TRUE; |
30667bf3 AM |
3182 | } |
3183 | ||
30667bf3 AM |
3184 | /* Build all the stubs associated with the current output file. The |
3185 | stubs are kept in a hash table attached to the main linker hash | |
3186 | table. We also set up the .plt entries for statically linked PIC | |
3187 | functions here. This function is called via hppaelf_finish in the | |
3188 | linker. */ | |
3189 | ||
b34976b6 | 3190 | bfd_boolean |
c39a58e6 | 3191 | elf32_hppa_build_stubs (struct bfd_link_info *info) |
30667bf3 AM |
3192 | { |
3193 | asection *stub_sec; | |
3194 | struct bfd_hash_table *table; | |
83c81bfe | 3195 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 | 3196 | |
83c81bfe | 3197 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
3198 | if (htab == NULL) |
3199 | return FALSE; | |
30667bf3 | 3200 | |
83c81bfe | 3201 | for (stub_sec = htab->stub_bfd->sections; |
30667bf3 AM |
3202 | stub_sec != NULL; |
3203 | stub_sec = stub_sec->next) | |
a464198b AM |
3204 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0 |
3205 | && stub_sec->size != 0) | |
3206 | { | |
3207 | /* Allocate memory to hold the linker stubs. */ | |
3208 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size); | |
3209 | if (stub_sec->contents == NULL) | |
3210 | return FALSE; | |
3211 | stub_sec->size = 0; | |
3212 | } | |
30667bf3 AM |
3213 | |
3214 | /* Build the stubs as directed by the stub hash table. */ | |
a63e02c7 | 3215 | table = &htab->bstab; |
30667bf3 AM |
3216 | bfd_hash_traverse (table, hppa_build_one_stub, info); |
3217 | ||
b34976b6 | 3218 | return TRUE; |
30667bf3 AM |
3219 | } |
3220 | ||
9b52905e | 3221 | /* Return the base vma address which should be subtracted from the real |
68ffbac6 | 3222 | address when resolving a dtpoff relocation. |
9b52905e NC |
3223 | This is PT_TLS segment p_vaddr. */ |
3224 | ||
3225 | static bfd_vma | |
3226 | dtpoff_base (struct bfd_link_info *info) | |
3227 | { | |
3228 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
3229 | if (elf_hash_table (info)->tls_sec == NULL) | |
3230 | return 0; | |
3231 | return elf_hash_table (info)->tls_sec->vma; | |
3232 | } | |
3233 | ||
3234 | /* Return the relocation value for R_PARISC_TLS_TPOFF*.. */ | |
3235 | ||
3236 | static bfd_vma | |
3237 | tpoff (struct bfd_link_info *info, bfd_vma address) | |
3238 | { | |
3239 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
3240 | ||
3241 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
3242 | if (htab->tls_sec == NULL) | |
3243 | return 0; | |
68ffbac6 | 3244 | /* hppa TLS ABI is variant I and static TLS block start just after |
9b52905e | 3245 | tcbhead structure which has 2 pointer fields. */ |
68ffbac6 | 3246 | return (address - htab->tls_sec->vma |
9b52905e NC |
3247 | + align_power ((bfd_vma) 8, htab->tls_sec->alignment_power)); |
3248 | } | |
3249 | ||
c46b7515 AM |
3250 | /* Perform a final link. */ |
3251 | ||
b34976b6 | 3252 | static bfd_boolean |
c39a58e6 | 3253 | elf32_hppa_final_link (bfd *abfd, struct bfd_link_info *info) |
c46b7515 | 3254 | { |
6d4b2867 JDA |
3255 | struct stat buf; |
3256 | ||
4dc86686 | 3257 | /* Invoke the regular ELF linker to do all the work. */ |
c152c796 | 3258 | if (!bfd_elf_final_link (abfd, info)) |
b34976b6 | 3259 | return FALSE; |
c46b7515 AM |
3260 | |
3261 | /* If we're producing a final executable, sort the contents of the | |
985142a4 | 3262 | unwind section. */ |
0e1862bb | 3263 | if (bfd_link_relocatable (info)) |
d9f40817 DA |
3264 | return TRUE; |
3265 | ||
6d4b2867 JDA |
3266 | /* Do not attempt to sort non-regular files. This is here |
3267 | especially for configure scripts and kernel builds which run | |
3268 | tests with "ld [...] -o /dev/null". */ | |
3269 | if (stat (abfd->filename, &buf) != 0 | |
3270 | || !S_ISREG(buf.st_mode)) | |
3271 | return TRUE; | |
3272 | ||
46fe4e66 | 3273 | return elf_hppa_sort_unwind (abfd); |
c46b7515 AM |
3274 | } |
3275 | ||
3276 | /* Record the lowest address for the data and text segments. */ | |
3277 | ||
3278 | static void | |
2ea37f1c | 3279 | hppa_record_segment_addr (bfd *abfd, asection *section, void *data) |
c46b7515 | 3280 | { |
83c81bfe | 3281 | struct elf32_hppa_link_hash_table *htab; |
c46b7515 | 3282 | |
875c0872 | 3283 | htab = (struct elf32_hppa_link_hash_table*) data; |
4dfe6ac6 NC |
3284 | if (htab == NULL) |
3285 | return; | |
c46b7515 AM |
3286 | |
3287 | if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
3288 | { | |
2ea37f1c NC |
3289 | bfd_vma value; |
3290 | Elf_Internal_Phdr *p; | |
3291 | ||
3292 | p = _bfd_elf_find_segment_containing_section (abfd, section->output_section); | |
3293 | BFD_ASSERT (p != NULL); | |
3294 | value = p->p_vaddr; | |
c46b7515 AM |
3295 | |
3296 | if ((section->flags & SEC_READONLY) != 0) | |
3297 | { | |
83c81bfe AM |
3298 | if (value < htab->text_segment_base) |
3299 | htab->text_segment_base = value; | |
c46b7515 AM |
3300 | } |
3301 | else | |
3302 | { | |
83c81bfe AM |
3303 | if (value < htab->data_segment_base) |
3304 | htab->data_segment_base = value; | |
c46b7515 AM |
3305 | } |
3306 | } | |
3307 | } | |
3308 | ||
30667bf3 AM |
3309 | /* Perform a relocation as part of a final link. */ |
3310 | ||
3311 | static bfd_reloc_status_type | |
c39a58e6 AM |
3312 | final_link_relocate (asection *input_section, |
3313 | bfd_byte *contents, | |
875c0872 | 3314 | const Elf_Internal_Rela *rela, |
c39a58e6 AM |
3315 | bfd_vma value, |
3316 | struct elf32_hppa_link_hash_table *htab, | |
3317 | asection *sym_sec, | |
875c0872 | 3318 | struct elf32_hppa_link_hash_entry *hh, |
a252afa4 | 3319 | struct bfd_link_info *info) |
30667bf3 AM |
3320 | { |
3321 | int insn; | |
875c0872 | 3322 | unsigned int r_type = ELF32_R_TYPE (rela->r_info); |
a252afa4 | 3323 | unsigned int orig_r_type = r_type; |
30667bf3 AM |
3324 | reloc_howto_type *howto = elf_hppa_howto_table + r_type; |
3325 | int r_format = howto->bitsize; | |
3326 | enum hppa_reloc_field_selector_type_alt r_field; | |
3327 | bfd *input_bfd = input_section->owner; | |
875c0872 | 3328 | bfd_vma offset = rela->r_offset; |
30667bf3 AM |
3329 | bfd_vma max_branch_offset = 0; |
3330 | bfd_byte *hit_data = contents + offset; | |
875c0872 | 3331 | bfd_signed_vma addend = rela->r_addend; |
30667bf3 | 3332 | bfd_vma location; |
875c0872 | 3333 | struct elf32_hppa_stub_hash_entry *hsh = NULL; |
68ffbac6 | 3334 | int val; |
30667bf3 AM |
3335 | |
3336 | if (r_type == R_PARISC_NONE) | |
3337 | return bfd_reloc_ok; | |
3338 | ||
3339 | insn = bfd_get_32 (input_bfd, hit_data); | |
3340 | ||
3341 | /* Find out where we are and where we're going. */ | |
3342 | location = (offset + | |
3343 | input_section->output_offset + | |
3344 | input_section->output_section->vma); | |
3345 | ||
a252afa4 DA |
3346 | /* If we are not building a shared library, convert DLTIND relocs to |
3347 | DPREL relocs. */ | |
0e1862bb | 3348 | if (!bfd_link_pic (info)) |
a252afa4 DA |
3349 | { |
3350 | switch (r_type) | |
4fc8051d AM |
3351 | { |
3352 | case R_PARISC_DLTIND21L: | |
143bb599 DA |
3353 | case R_PARISC_TLS_GD21L: |
3354 | case R_PARISC_TLS_LDM21L: | |
3355 | case R_PARISC_TLS_IE21L: | |
4fc8051d | 3356 | r_type = R_PARISC_DPREL21L; |
a252afa4 DA |
3357 | break; |
3358 | ||
4fc8051d | 3359 | case R_PARISC_DLTIND14R: |
143bb599 DA |
3360 | case R_PARISC_TLS_GD14R: |
3361 | case R_PARISC_TLS_LDM14R: | |
3362 | case R_PARISC_TLS_IE14R: | |
4fc8051d | 3363 | r_type = R_PARISC_DPREL14R; |
a252afa4 DA |
3364 | break; |
3365 | ||
4fc8051d AM |
3366 | case R_PARISC_DLTIND14F: |
3367 | r_type = R_PARISC_DPREL14F; | |
a252afa4 DA |
3368 | break; |
3369 | } | |
3370 | } | |
3371 | ||
30667bf3 AM |
3372 | switch (r_type) |
3373 | { | |
3374 | case R_PARISC_PCREL12F: | |
3375 | case R_PARISC_PCREL17F: | |
3376 | case R_PARISC_PCREL22F: | |
067fa4a6 AM |
3377 | /* If this call should go via the plt, find the import stub in |
3378 | the stub hash. */ | |
30667bf3 AM |
3379 | if (sym_sec == NULL |
3380 | || sym_sec->output_section == NULL | |
875c0872 | 3381 | || (hh != NULL |
a63e02c7 DA |
3382 | && hh->eh.plt.offset != (bfd_vma) -1 |
3383 | && hh->eh.dynindx != -1 | |
875c0872 | 3384 | && !hh->plabel |
0e1862bb | 3385 | && (bfd_link_pic (info) |
a63e02c7 DA |
3386 | || !hh->eh.def_regular |
3387 | || hh->eh.root.type == bfd_link_hash_defweak))) | |
30667bf3 | 3388 | { |
875c0872 DA |
3389 | hsh = hppa_get_stub_entry (input_section, sym_sec, |
3390 | hh, rela, htab); | |
3391 | if (hsh != NULL) | |
30667bf3 | 3392 | { |
875c0872 DA |
3393 | value = (hsh->stub_offset |
3394 | + hsh->stub_sec->output_offset | |
3395 | + hsh->stub_sec->output_section->vma); | |
30667bf3 AM |
3396 | addend = 0; |
3397 | } | |
875c0872 | 3398 | else if (sym_sec == NULL && hh != NULL |
a63e02c7 | 3399 | && hh->eh.root.type == bfd_link_hash_undefweak) |
30667bf3 | 3400 | { |
db20fd76 AM |
3401 | /* It's OK if undefined weak. Calls to undefined weak |
3402 | symbols behave as if the "called" function | |
3403 | immediately returns. We can thus call to a weak | |
3404 | function without first checking whether the function | |
3405 | is defined. */ | |
30667bf3 | 3406 | value = location; |
db20fd76 | 3407 | addend = 8; |
30667bf3 AM |
3408 | } |
3409 | else | |
f09ebc7d | 3410 | return bfd_reloc_undefined; |
30667bf3 AM |
3411 | } |
3412 | /* Fall thru. */ | |
3413 | ||
3414 | case R_PARISC_PCREL21L: | |
3415 | case R_PARISC_PCREL17C: | |
3416 | case R_PARISC_PCREL17R: | |
3417 | case R_PARISC_PCREL14R: | |
3418 | case R_PARISC_PCREL14F: | |
36751eee | 3419 | case R_PARISC_PCREL32: |
30667bf3 AM |
3420 | /* Make it a pc relative offset. */ |
3421 | value -= location; | |
3422 | addend -= 8; | |
3423 | break; | |
3424 | ||
3425 | case R_PARISC_DPREL21L: | |
3426 | case R_PARISC_DPREL14R: | |
3427 | case R_PARISC_DPREL14F: | |
a252afa4 DA |
3428 | /* Convert instructions that use the linkage table pointer (r19) to |
3429 | instructions that use the global data pointer (dp). This is the | |
3430 | most efficient way of using PIC code in an incomplete executable, | |
3431 | but the user must follow the standard runtime conventions for | |
3432 | accessing data for this to work. */ | |
143bb599 | 3433 | if (orig_r_type != r_type) |
a252afa4 | 3434 | { |
143bb599 DA |
3435 | if (r_type == R_PARISC_DPREL21L) |
3436 | { | |
3437 | /* GCC sometimes uses a register other than r19 for the | |
3438 | operation, so we must convert any addil instruction | |
3439 | that uses this relocation. */ | |
3440 | if ((insn & 0xfc000000) == ((int) OP_ADDIL << 26)) | |
3441 | insn = ADDIL_DP; | |
3442 | else | |
3443 | /* We must have a ldil instruction. It's too hard to find | |
3444 | and convert the associated add instruction, so issue an | |
3445 | error. */ | |
3446 | (*_bfd_error_handler) | |
3447 | (_("%B(%A+0x%lx): %s fixup for insn 0x%x is not supported in a non-shared link"), | |
3448 | input_bfd, | |
3449 | input_section, | |
3450 | (long) offset, | |
3451 | howto->name, | |
3452 | insn); | |
3453 | } | |
3454 | else if (r_type == R_PARISC_DPREL14F) | |
3455 | { | |
3456 | /* This must be a format 1 load/store. Change the base | |
3457 | register to dp. */ | |
3458 | insn = (insn & 0xfc1ffff) | (27 << 21); | |
3459 | } | |
a252afa4 DA |
3460 | } |
3461 | ||
143bb599 DA |
3462 | /* For all the DP relative relocations, we need to examine the symbol's |
3463 | section. If it has no section or if it's a code section, then | |
3464 | "data pointer relative" makes no sense. In that case we don't | |
3465 | adjust the "value", and for 21 bit addil instructions, we change the | |
3466 | source addend register from %dp to %r0. This situation commonly | |
3467 | arises for undefined weak symbols and when a variable's "constness" | |
3468 | is declared differently from the way the variable is defined. For | |
3469 | instance: "extern int foo" with foo defined as "const int foo". */ | |
95d0f04a | 3470 | if (sym_sec == NULL || (sym_sec->flags & SEC_CODE) != 0) |
30667bf3 AM |
3471 | { |
3472 | if ((insn & ((0x3f << 26) | (0x1f << 21))) | |
3473 | == (((int) OP_ADDIL << 26) | (27 << 21))) | |
3474 | { | |
3475 | insn &= ~ (0x1f << 21); | |
30667bf3 AM |
3476 | } |
3477 | /* Now try to make things easy for the dynamic linker. */ | |
3478 | ||
3479 | break; | |
3480 | } | |
74d1c347 | 3481 | /* Fall thru. */ |
30667bf3 AM |
3482 | |
3483 | case R_PARISC_DLTIND21L: | |
3484 | case R_PARISC_DLTIND14R: | |
3485 | case R_PARISC_DLTIND14F: | |
143bb599 DA |
3486 | case R_PARISC_TLS_GD21L: |
3487 | case R_PARISC_TLS_LDM21L: | |
3488 | case R_PARISC_TLS_IE21L: | |
9b52905e | 3489 | case R_PARISC_TLS_GD14R: |
9b52905e | 3490 | case R_PARISC_TLS_LDM14R: |
9b52905e | 3491 | case R_PARISC_TLS_IE14R: |
30667bf3 AM |
3492 | value -= elf_gp (input_section->output_section->owner); |
3493 | break; | |
3494 | ||
c46b7515 AM |
3495 | case R_PARISC_SEGREL32: |
3496 | if ((sym_sec->flags & SEC_CODE) != 0) | |
83c81bfe | 3497 | value -= htab->text_segment_base; |
c46b7515 | 3498 | else |
83c81bfe | 3499 | value -= htab->data_segment_base; |
c46b7515 AM |
3500 | break; |
3501 | ||
30667bf3 AM |
3502 | default: |
3503 | break; | |
3504 | } | |
3505 | ||
3506 | switch (r_type) | |
3507 | { | |
3508 | case R_PARISC_DIR32: | |
47d89dba | 3509 | case R_PARISC_DIR14F: |
30667bf3 AM |
3510 | case R_PARISC_DIR17F: |
3511 | case R_PARISC_PCREL17C: | |
3512 | case R_PARISC_PCREL14F: | |
36751eee | 3513 | case R_PARISC_PCREL32: |
30667bf3 AM |
3514 | case R_PARISC_DPREL14F: |
3515 | case R_PARISC_PLABEL32: | |
3516 | case R_PARISC_DLTIND14F: | |
3517 | case R_PARISC_SEGBASE: | |
3518 | case R_PARISC_SEGREL32: | |
9b52905e NC |
3519 | case R_PARISC_TLS_DTPMOD32: |
3520 | case R_PARISC_TLS_DTPOFF32: | |
3521 | case R_PARISC_TLS_TPREL32: | |
30667bf3 AM |
3522 | r_field = e_fsel; |
3523 | break; | |
3524 | ||
1bf42538 | 3525 | case R_PARISC_DLTIND21L: |
30667bf3 | 3526 | case R_PARISC_PCREL21L: |
30667bf3 | 3527 | case R_PARISC_PLABEL21L: |
1bf42538 JL |
3528 | r_field = e_lsel; |
3529 | break; | |
3530 | ||
3531 | case R_PARISC_DIR21L: | |
3532 | case R_PARISC_DPREL21L: | |
9b52905e NC |
3533 | case R_PARISC_TLS_GD21L: |
3534 | case R_PARISC_TLS_LDM21L: | |
3535 | case R_PARISC_TLS_LDO21L: | |
3536 | case R_PARISC_TLS_IE21L: | |
3537 | case R_PARISC_TLS_LE21L: | |
30667bf3 AM |
3538 | r_field = e_lrsel; |
3539 | break; | |
3540 | ||
30667bf3 | 3541 | case R_PARISC_PCREL17R: |
30667bf3 | 3542 | case R_PARISC_PCREL14R: |
30667bf3 AM |
3543 | case R_PARISC_PLABEL14R: |
3544 | case R_PARISC_DLTIND14R: | |
1bf42538 JL |
3545 | r_field = e_rsel; |
3546 | break; | |
3547 | ||
3548 | case R_PARISC_DIR17R: | |
3549 | case R_PARISC_DIR14R: | |
3550 | case R_PARISC_DPREL14R: | |
9b52905e NC |
3551 | case R_PARISC_TLS_GD14R: |
3552 | case R_PARISC_TLS_LDM14R: | |
3553 | case R_PARISC_TLS_LDO14R: | |
3554 | case R_PARISC_TLS_IE14R: | |
3555 | case R_PARISC_TLS_LE14R: | |
30667bf3 AM |
3556 | r_field = e_rrsel; |
3557 | break; | |
3558 | ||
3559 | case R_PARISC_PCREL12F: | |
3560 | case R_PARISC_PCREL17F: | |
3561 | case R_PARISC_PCREL22F: | |
3562 | r_field = e_fsel; | |
3563 | ||
3564 | if (r_type == (unsigned int) R_PARISC_PCREL17F) | |
3565 | { | |
3566 | max_branch_offset = (1 << (17-1)) << 2; | |
3567 | } | |
3568 | else if (r_type == (unsigned int) R_PARISC_PCREL12F) | |
3569 | { | |
3570 | max_branch_offset = (1 << (12-1)) << 2; | |
3571 | } | |
3572 | else | |
3573 | { | |
3574 | max_branch_offset = (1 << (22-1)) << 2; | |
3575 | } | |
3576 | ||
3577 | /* sym_sec is NULL on undefined weak syms or when shared on | |
3578 | undefined syms. We've already checked for a stub for the | |
3579 | shared undefined case. */ | |
3580 | if (sym_sec == NULL) | |
3581 | break; | |
3582 | ||
3583 | /* If the branch is out of reach, then redirect the | |
3584 | call to the local stub for this function. */ | |
3585 | if (value + addend + max_branch_offset >= 2*max_branch_offset) | |
3586 | { | |
875c0872 DA |
3587 | hsh = hppa_get_stub_entry (input_section, sym_sec, |
3588 | hh, rela, htab); | |
3589 | if (hsh == NULL) | |
f09ebc7d | 3590 | return bfd_reloc_undefined; |
30667bf3 AM |
3591 | |
3592 | /* Munge up the value and addend so that we call the stub | |
3593 | rather than the procedure directly. */ | |
875c0872 DA |
3594 | value = (hsh->stub_offset |
3595 | + hsh->stub_sec->output_offset | |
3596 | + hsh->stub_sec->output_section->vma | |
30667bf3 AM |
3597 | - location); |
3598 | addend = -8; | |
3599 | } | |
3600 | break; | |
3601 | ||
3602 | /* Something we don't know how to handle. */ | |
3603 | default: | |
3604 | return bfd_reloc_notsupported; | |
3605 | } | |
3606 | ||
3607 | /* Make sure we can reach the stub. */ | |
3608 | if (max_branch_offset != 0 | |
3609 | && value + addend + max_branch_offset >= 2*max_branch_offset) | |
3610 | { | |
3611 | (*_bfd_error_handler) | |
d003868e AM |
3612 | (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"), |
3613 | input_bfd, | |
3614 | input_section, | |
d1fa68d3 | 3615 | (long) offset, |
a63e02c7 | 3616 | hsh->bh_root.string); |
ce757d15 | 3617 | bfd_set_error (bfd_error_bad_value); |
30667bf3 AM |
3618 | return bfd_reloc_notsupported; |
3619 | } | |
3620 | ||
3621 | val = hppa_field_adjust (value, addend, r_field); | |
3622 | ||
3623 | switch (r_type) | |
3624 | { | |
3625 | case R_PARISC_PCREL12F: | |
3626 | case R_PARISC_PCREL17C: | |
3627 | case R_PARISC_PCREL17F: | |
3628 | case R_PARISC_PCREL17R: | |
3629 | case R_PARISC_PCREL22F: | |
3630 | case R_PARISC_DIR17F: | |
3631 | case R_PARISC_DIR17R: | |
3632 | /* This is a branch. Divide the offset by four. | |
3633 | Note that we need to decide whether it's a branch or | |
3634 | otherwise by inspecting the reloc. Inspecting insn won't | |
3635 | work as insn might be from a .word directive. */ | |
3636 | val >>= 2; | |
3637 | break; | |
3638 | ||
3639 | default: | |
3640 | break; | |
3641 | } | |
3642 | ||
3643 | insn = hppa_rebuild_insn (insn, val, r_format); | |
3644 | ||
3645 | /* Update the instruction word. */ | |
74d1c347 | 3646 | bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data); |
30667bf3 AM |
3647 | return bfd_reloc_ok; |
3648 | } | |
3649 | ||
30667bf3 AM |
3650 | /* Relocate an HPPA ELF section. */ |
3651 | ||
b34976b6 | 3652 | static bfd_boolean |
c39a58e6 AM |
3653 | elf32_hppa_relocate_section (bfd *output_bfd, |
3654 | struct bfd_link_info *info, | |
3655 | bfd *input_bfd, | |
3656 | asection *input_section, | |
3657 | bfd_byte *contents, | |
3658 | Elf_Internal_Rela *relocs, | |
3659 | Elf_Internal_Sym *local_syms, | |
3660 | asection **local_sections) | |
30667bf3 | 3661 | { |
30667bf3 | 3662 | bfd_vma *local_got_offsets; |
83c81bfe | 3663 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 | 3664 | Elf_Internal_Shdr *symtab_hdr; |
875c0872 | 3665 | Elf_Internal_Rela *rela; |
30667bf3 | 3666 | Elf_Internal_Rela *relend; |
30667bf3 AM |
3667 | |
3668 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
3669 | ||
83c81bfe | 3670 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
3671 | if (htab == NULL) |
3672 | return FALSE; | |
3673 | ||
74d1c347 | 3674 | local_got_offsets = elf_local_got_offsets (input_bfd); |
30667bf3 | 3675 | |
875c0872 | 3676 | rela = relocs; |
30667bf3 | 3677 | relend = relocs + input_section->reloc_count; |
875c0872 | 3678 | for (; rela < relend; rela++) |
30667bf3 AM |
3679 | { |
3680 | unsigned int r_type; | |
3681 | reloc_howto_type *howto; | |
3682 | unsigned int r_symndx; | |
875c0872 | 3683 | struct elf32_hppa_link_hash_entry *hh; |
30667bf3 AM |
3684 | Elf_Internal_Sym *sym; |
3685 | asection *sym_sec; | |
3686 | bfd_vma relocation; | |
875c0872 | 3687 | bfd_reloc_status_type rstatus; |
30667bf3 | 3688 | const char *sym_name; |
b34976b6 AM |
3689 | bfd_boolean plabel; |
3690 | bfd_boolean warned_undef; | |
30667bf3 | 3691 | |
875c0872 | 3692 | r_type = ELF32_R_TYPE (rela->r_info); |
30667bf3 AM |
3693 | if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED) |
3694 | { | |
3695 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 3696 | return FALSE; |
30667bf3 AM |
3697 | } |
3698 | if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY | |
3699 | || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT) | |
3700 | continue; | |
3701 | ||
875c0872 DA |
3702 | r_symndx = ELF32_R_SYM (rela->r_info); |
3703 | hh = NULL; | |
30667bf3 AM |
3704 | sym = NULL; |
3705 | sym_sec = NULL; | |
b34976b6 | 3706 | warned_undef = FALSE; |
30667bf3 AM |
3707 | if (r_symndx < symtab_hdr->sh_info) |
3708 | { | |
3709 | /* This is a local symbol, h defaults to NULL. */ | |
3710 | sym = local_syms + r_symndx; | |
3711 | sym_sec = local_sections[r_symndx]; | |
875c0872 | 3712 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rela); |
30667bf3 AM |
3713 | } |
3714 | else | |
3715 | { | |
875c0872 | 3716 | struct elf_link_hash_entry *eh; |
62d887d4 | 3717 | bfd_boolean unresolved_reloc, ignored; |
b2a8e766 | 3718 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); |
560e09e9 | 3719 | |
875c0872 | 3720 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rela, |
b2a8e766 | 3721 | r_symndx, symtab_hdr, sym_hashes, |
875c0872 | 3722 | eh, sym_sec, relocation, |
62d887d4 L |
3723 | unresolved_reloc, warned_undef, |
3724 | ignored); | |
560e09e9 | 3725 | |
0e1862bb | 3726 | if (!bfd_link_relocatable (info) |
ab96bf03 | 3727 | && relocation == 0 |
875c0872 DA |
3728 | && eh->root.type != bfd_link_hash_defined |
3729 | && eh->root.type != bfd_link_hash_defweak | |
3730 | && eh->root.type != bfd_link_hash_undefweak) | |
4fc8051d | 3731 | { |
59c2e50f | 3732 | if (info->unresolved_syms_in_objects == RM_IGNORE |
875c0872 DA |
3733 | && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT |
3734 | && eh->type == STT_PARISC_MILLI) | |
560e09e9 | 3735 | { |
1a72702b AM |
3736 | (*info->callbacks->undefined_symbol) |
3737 | (info, eh_name (eh), input_bfd, | |
3738 | input_section, rela->r_offset, FALSE); | |
560e09e9 NC |
3739 | warned_undef = TRUE; |
3740 | } | |
30667bf3 | 3741 | } |
875c0872 | 3742 | hh = hppa_elf_hash_entry (eh); |
30667bf3 AM |
3743 | } |
3744 | ||
dbaa2011 | 3745 | if (sym_sec != NULL && discarded_section (sym_sec)) |
e4067dbb | 3746 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
545fd46b MR |
3747 | rela, 1, relend, |
3748 | elf_hppa_howto_table + r_type, 0, | |
e4067dbb | 3749 | contents); |
ab96bf03 | 3750 | |
0e1862bb | 3751 | if (bfd_link_relocatable (info)) |
ab96bf03 AM |
3752 | continue; |
3753 | ||
30667bf3 | 3754 | /* Do any required modifications to the relocation value, and |
25f72752 AM |
3755 | determine what types of dynamic info we need to output, if |
3756 | any. */ | |
74d1c347 | 3757 | plabel = 0; |
30667bf3 AM |
3758 | switch (r_type) |
3759 | { | |
3760 | case R_PARISC_DLTIND14F: | |
3761 | case R_PARISC_DLTIND14R: | |
3762 | case R_PARISC_DLTIND21L: | |
ce757d15 AM |
3763 | { |
3764 | bfd_vma off; | |
b34976b6 | 3765 | bfd_boolean do_got = 0; |
ce757d15 AM |
3766 | |
3767 | /* Relocation is to the entry for this symbol in the | |
3768 | global offset table. */ | |
875c0872 | 3769 | if (hh != NULL) |
ce757d15 | 3770 | { |
b34976b6 | 3771 | bfd_boolean dyn; |
ce757d15 | 3772 | |
a63e02c7 DA |
3773 | off = hh->eh.got.offset; |
3774 | dyn = htab->etab.dynamic_sections_created; | |
0e1862bb L |
3775 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, |
3776 | bfd_link_pic (info), | |
a63e02c7 | 3777 | &hh->eh)) |
ce757d15 AM |
3778 | { |
3779 | /* If we aren't going to call finish_dynamic_symbol, | |
3780 | then we need to handle initialisation of the .got | |
3781 | entry and create needed relocs here. Since the | |
3782 | offset must always be a multiple of 4, we use the | |
3783 | least significant bit to record whether we have | |
3784 | initialised it already. */ | |
3785 | if ((off & 1) != 0) | |
3786 | off &= ~1; | |
3787 | else | |
3788 | { | |
a63e02c7 | 3789 | hh->eh.got.offset |= 1; |
ce757d15 AM |
3790 | do_got = 1; |
3791 | } | |
3792 | } | |
3793 | } | |
3794 | else | |
3795 | { | |
3796 | /* Local symbol case. */ | |
3797 | if (local_got_offsets == NULL) | |
3798 | abort (); | |
3799 | ||
3800 | off = local_got_offsets[r_symndx]; | |
3801 | ||
3802 | /* The offset must always be a multiple of 4. We use | |
3803 | the least significant bit to record whether we have | |
3804 | already generated the necessary reloc. */ | |
3805 | if ((off & 1) != 0) | |
3806 | off &= ~1; | |
3807 | else | |
3808 | { | |
3809 | local_got_offsets[r_symndx] |= 1; | |
3810 | do_got = 1; | |
3811 | } | |
3812 | } | |
68fb2e56 | 3813 | |
ce757d15 AM |
3814 | if (do_got) |
3815 | { | |
0e1862bb | 3816 | if (bfd_link_pic (info)) |
ce757d15 AM |
3817 | { |
3818 | /* Output a dynamic relocation for this GOT entry. | |
3819 | In this case it is relative to the base of the | |
3820 | object because the symbol index is zero. */ | |
3821 | Elf_Internal_Rela outrel; | |
947216bf | 3822 | bfd_byte *loc; |
875c0872 | 3823 | asection *sec = htab->srelgot; |
ce757d15 AM |
3824 | |
3825 | outrel.r_offset = (off | |
3826 | + htab->sgot->output_offset | |
3827 | + htab->sgot->output_section->vma); | |
3828 | outrel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32); | |
3829 | outrel.r_addend = relocation; | |
875c0872 DA |
3830 | loc = sec->contents; |
3831 | loc += sec->reloc_count++ * sizeof (Elf32_External_Rela); | |
ce757d15 AM |
3832 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
3833 | } | |
3834 | else | |
30667bf3 | 3835 | bfd_put_32 (output_bfd, relocation, |
83c81bfe | 3836 | htab->sgot->contents + off); |
ce757d15 | 3837 | } |
30667bf3 | 3838 | |
ce757d15 AM |
3839 | if (off >= (bfd_vma) -2) |
3840 | abort (); | |
30667bf3 | 3841 | |
ce757d15 AM |
3842 | /* Add the base of the GOT to the relocation value. */ |
3843 | relocation = (off | |
3844 | + htab->sgot->output_offset | |
3845 | + htab->sgot->output_section->vma); | |
3846 | } | |
30667bf3 | 3847 | break; |
252b5132 | 3848 | |
c46b7515 AM |
3849 | case R_PARISC_SEGREL32: |
3850 | /* If this is the first SEGREL relocation, then initialize | |
3851 | the segment base values. */ | |
83c81bfe AM |
3852 | if (htab->text_segment_base == (bfd_vma) -1) |
3853 | bfd_map_over_sections (output_bfd, hppa_record_segment_addr, htab); | |
c46b7515 AM |
3854 | break; |
3855 | ||
30667bf3 AM |
3856 | case R_PARISC_PLABEL14R: |
3857 | case R_PARISC_PLABEL21L: | |
3858 | case R_PARISC_PLABEL32: | |
a63e02c7 | 3859 | if (htab->etab.dynamic_sections_created) |
252b5132 | 3860 | { |
ce757d15 | 3861 | bfd_vma off; |
b34976b6 | 3862 | bfd_boolean do_plt = 0; |
74d1c347 AM |
3863 | /* If we have a global symbol with a PLT slot, then |
3864 | redirect this relocation to it. */ | |
875c0872 | 3865 | if (hh != NULL) |
74d1c347 | 3866 | { |
a63e02c7 | 3867 | off = hh->eh.plt.offset; |
0e1862bb L |
3868 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, |
3869 | bfd_link_pic (info), | |
a63e02c7 | 3870 | &hh->eh)) |
8dea1268 AM |
3871 | { |
3872 | /* In a non-shared link, adjust_dynamic_symbols | |
3873 | isn't called for symbols forced local. We | |
dc810e39 | 3874 | need to write out the plt entry here. */ |
8dea1268 AM |
3875 | if ((off & 1) != 0) |
3876 | off &= ~1; | |
3877 | else | |
3878 | { | |
a63e02c7 | 3879 | hh->eh.plt.offset |= 1; |
ce757d15 | 3880 | do_plt = 1; |
8dea1268 AM |
3881 | } |
3882 | } | |
74d1c347 AM |
3883 | } |
3884 | else | |
3885 | { | |
68fb2e56 AM |
3886 | bfd_vma *local_plt_offsets; |
3887 | ||
3888 | if (local_got_offsets == NULL) | |
3889 | abort (); | |
74d1c347 | 3890 | |
68fb2e56 AM |
3891 | local_plt_offsets = local_got_offsets + symtab_hdr->sh_info; |
3892 | off = local_plt_offsets[r_symndx]; | |
74d1c347 AM |
3893 | |
3894 | /* As for the local .got entry case, we use the last | |
3895 | bit to record whether we've already initialised | |
3896 | this local .plt entry. */ | |
3897 | if ((off & 1) != 0) | |
3898 | off &= ~1; | |
ce757d15 AM |
3899 | else |
3900 | { | |
3901 | local_plt_offsets[r_symndx] |= 1; | |
3902 | do_plt = 1; | |
3903 | } | |
3904 | } | |
3905 | ||
3906 | if (do_plt) | |
3907 | { | |
0e1862bb | 3908 | if (bfd_link_pic (info)) |
ce757d15 AM |
3909 | { |
3910 | /* Output a dynamic IPLT relocation for this | |
3911 | PLT entry. */ | |
3912 | Elf_Internal_Rela outrel; | |
947216bf AM |
3913 | bfd_byte *loc; |
3914 | asection *s = htab->srelplt; | |
ce757d15 AM |
3915 | |
3916 | outrel.r_offset = (off | |
3917 | + htab->splt->output_offset | |
3918 | + htab->splt->output_section->vma); | |
3919 | outrel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT); | |
3920 | outrel.r_addend = relocation; | |
947216bf AM |
3921 | loc = s->contents; |
3922 | loc += s->reloc_count++ * sizeof (Elf32_External_Rela); | |
ce757d15 AM |
3923 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
3924 | } | |
74d1c347 AM |
3925 | else |
3926 | { | |
3927 | bfd_put_32 (output_bfd, | |
3928 | relocation, | |
83c81bfe | 3929 | htab->splt->contents + off); |
74d1c347 | 3930 | bfd_put_32 (output_bfd, |
83c81bfe AM |
3931 | elf_gp (htab->splt->output_section->owner), |
3932 | htab->splt->contents + off + 4); | |
74d1c347 AM |
3933 | } |
3934 | } | |
3935 | ||
68fb2e56 | 3936 | if (off >= (bfd_vma) -2) |
49e9d0d3 | 3937 | abort (); |
74d1c347 AM |
3938 | |
3939 | /* PLABELs contain function pointers. Relocation is to | |
3940 | the entry for the function in the .plt. The magic +2 | |
3941 | offset signals to $$dyncall that the function pointer | |
3942 | is in the .plt and thus has a gp pointer too. | |
3943 | Exception: Undefined PLABELs should have a value of | |
3944 | zero. */ | |
875c0872 | 3945 | if (hh == NULL |
a63e02c7 DA |
3946 | || (hh->eh.root.type != bfd_link_hash_undefweak |
3947 | && hh->eh.root.type != bfd_link_hash_undefined)) | |
74d1c347 AM |
3948 | { |
3949 | relocation = (off | |
83c81bfe AM |
3950 | + htab->splt->output_offset |
3951 | + htab->splt->output_section->vma | |
74d1c347 AM |
3952 | + 2); |
3953 | } | |
3954 | plabel = 1; | |
30667bf3 AM |
3955 | } |
3956 | /* Fall through and possibly emit a dynamic relocation. */ | |
3957 | ||
3958 | case R_PARISC_DIR17F: | |
3959 | case R_PARISC_DIR17R: | |
47d89dba | 3960 | case R_PARISC_DIR14F: |
30667bf3 AM |
3961 | case R_PARISC_DIR14R: |
3962 | case R_PARISC_DIR21L: | |
3963 | case R_PARISC_DPREL14F: | |
3964 | case R_PARISC_DPREL14R: | |
3965 | case R_PARISC_DPREL21L: | |
3966 | case R_PARISC_DIR32: | |
b1e24c02 | 3967 | if ((input_section->flags & SEC_ALLOC) == 0) |
ec338859 AM |
3968 | break; |
3969 | ||
30667bf3 | 3970 | /* The reloc types handled here and this conditional |
56882138 | 3971 | expression must match the code in ..check_relocs and |
ec338859 | 3972 | allocate_dynrelocs. ie. We need exactly the same condition |
56882138 AM |
3973 | as in ..check_relocs, with some extra conditions (dynindx |
3974 | test in this case) to cater for relocs removed by | |
ec338859 | 3975 | allocate_dynrelocs. If you squint, the non-shared test |
56882138 AM |
3976 | here does indeed match the one in ..check_relocs, the |
3977 | difference being that here we test DEF_DYNAMIC as well as | |
3978 | !DEF_REGULAR. All common syms end up with !DEF_REGULAR, | |
3979 | which is why we can't use just that test here. | |
3980 | Conversely, DEF_DYNAMIC can't be used in check_relocs as | |
3981 | there all files have not been loaded. */ | |
0e1862bb | 3982 | if ((bfd_link_pic (info) |
875c0872 | 3983 | && (hh == NULL |
a63e02c7 DA |
3984 | || ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT |
3985 | || hh->eh.root.type != bfd_link_hash_undefweak) | |
446f2863 | 3986 | && (IS_ABSOLUTE_RELOC (r_type) |
a63e02c7 | 3987 | || !SYMBOL_CALLS_LOCAL (info, &hh->eh))) |
0e1862bb | 3988 | || (!bfd_link_pic (info) |
875c0872 | 3989 | && hh != NULL |
a63e02c7 DA |
3990 | && hh->eh.dynindx != -1 |
3991 | && !hh->eh.non_got_ref | |
4fc8051d | 3992 | && ((ELIMINATE_COPY_RELOCS |
a63e02c7 DA |
3993 | && hh->eh.def_dynamic |
3994 | && !hh->eh.def_regular) | |
3995 | || hh->eh.root.type == bfd_link_hash_undefweak | |
3996 | || hh->eh.root.type == bfd_link_hash_undefined))) | |
30667bf3 AM |
3997 | { |
3998 | Elf_Internal_Rela outrel; | |
b34976b6 | 3999 | bfd_boolean skip; |
98ceb8ce | 4000 | asection *sreloc; |
947216bf | 4001 | bfd_byte *loc; |
252b5132 | 4002 | |
30667bf3 AM |
4003 | /* When generating a shared object, these relocations |
4004 | are copied into the output file to be resolved at run | |
4005 | time. */ | |
252b5132 | 4006 | |
875c0872 | 4007 | outrel.r_addend = rela->r_addend; |
c629eae0 JJ |
4008 | outrel.r_offset = |
4009 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
875c0872 | 4010 | rela->r_offset); |
0bb2d96a JJ |
4011 | skip = (outrel.r_offset == (bfd_vma) -1 |
4012 | || outrel.r_offset == (bfd_vma) -2); | |
30667bf3 AM |
4013 | outrel.r_offset += (input_section->output_offset |
4014 | + input_section->output_section->vma); | |
68ffbac6 | 4015 | |
30667bf3 | 4016 | if (skip) |
252b5132 | 4017 | { |
30667bf3 | 4018 | memset (&outrel, 0, sizeof (outrel)); |
252b5132 | 4019 | } |
875c0872 | 4020 | else if (hh != NULL |
a63e02c7 | 4021 | && hh->eh.dynindx != -1 |
74d1c347 | 4022 | && (plabel |
446f2863 | 4023 | || !IS_ABSOLUTE_RELOC (r_type) |
0e1862bb | 4024 | || !bfd_link_pic (info) |
a496fbc8 | 4025 | || !SYMBOLIC_BIND (info, &hh->eh) |
a63e02c7 | 4026 | || !hh->eh.def_regular)) |
252b5132 | 4027 | { |
a63e02c7 | 4028 | outrel.r_info = ELF32_R_INFO (hh->eh.dynindx, r_type); |
30667bf3 AM |
4029 | } |
4030 | else /* It's a local symbol, or one marked to become local. */ | |
4031 | { | |
4032 | int indx = 0; | |
edd21aca | 4033 | |
30667bf3 AM |
4034 | /* Add the absolute offset of the symbol. */ |
4035 | outrel.r_addend += relocation; | |
edd21aca | 4036 | |
74d1c347 AM |
4037 | /* Global plabels need to be processed by the |
4038 | dynamic linker so that functions have at most one | |
4039 | fptr. For this reason, we need to differentiate | |
4040 | between global and local plabels, which we do by | |
4041 | providing the function symbol for a global plabel | |
4042 | reloc, and no symbol for local plabels. */ | |
4043 | if (! plabel | |
4044 | && sym_sec != NULL | |
30667bf3 AM |
4045 | && sym_sec->output_section != NULL |
4046 | && ! bfd_is_abs_section (sym_sec)) | |
252b5132 | 4047 | { |
74541ad4 AM |
4048 | asection *osec; |
4049 | ||
4050 | osec = sym_sec->output_section; | |
4051 | indx = elf_section_data (osec)->dynindx; | |
4052 | if (indx == 0) | |
4053 | { | |
4054 | osec = htab->etab.text_index_section; | |
4055 | indx = elf_section_data (osec)->dynindx; | |
4056 | } | |
4057 | BFD_ASSERT (indx != 0); | |
4b71bec0 | 4058 | |
30667bf3 AM |
4059 | /* We are turning this relocation into one |
4060 | against a section symbol, so subtract out the | |
4061 | output section's address but not the offset | |
4062 | of the input section in the output section. */ | |
74541ad4 | 4063 | outrel.r_addend -= osec->vma; |
252b5132 | 4064 | } |
252b5132 | 4065 | |
30667bf3 AM |
4066 | outrel.r_info = ELF32_R_INFO (indx, r_type); |
4067 | } | |
98ceb8ce AM |
4068 | sreloc = elf_section_data (input_section)->sreloc; |
4069 | if (sreloc == NULL) | |
4070 | abort (); | |
4071 | ||
947216bf AM |
4072 | loc = sreloc->contents; |
4073 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
98ceb8ce | 4074 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
30667bf3 AM |
4075 | } |
4076 | break; | |
68ffbac6 | 4077 | |
9b52905e NC |
4078 | case R_PARISC_TLS_LDM21L: |
4079 | case R_PARISC_TLS_LDM14R: | |
4080 | { | |
4081 | bfd_vma off; | |
68ffbac6 | 4082 | |
9b52905e NC |
4083 | off = htab->tls_ldm_got.offset; |
4084 | if (off & 1) | |
4085 | off &= ~1; | |
4086 | else | |
4087 | { | |
4088 | Elf_Internal_Rela outrel; | |
4089 | bfd_byte *loc; | |
4090 | ||
68ffbac6 | 4091 | outrel.r_offset = (off |
9b52905e NC |
4092 | + htab->sgot->output_section->vma |
4093 | + htab->sgot->output_offset); | |
4094 | outrel.r_addend = 0; | |
4095 | outrel.r_info = ELF32_R_INFO (0, R_PARISC_TLS_DTPMOD32); | |
68ffbac6 | 4096 | loc = htab->srelgot->contents; |
9b52905e NC |
4097 | loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela); |
4098 | ||
4099 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
4100 | htab->tls_ldm_got.offset |= 1; | |
4101 | } | |
4102 | ||
4103 | /* Add the base of the GOT to the relocation value. */ | |
4104 | relocation = (off | |
4105 | + htab->sgot->output_offset | |
4106 | + htab->sgot->output_section->vma); | |
4107 | ||
4108 | break; | |
4109 | } | |
4110 | ||
4111 | case R_PARISC_TLS_LDO21L: | |
4112 | case R_PARISC_TLS_LDO14R: | |
4113 | relocation -= dtpoff_base (info); | |
4114 | break; | |
4115 | ||
4116 | case R_PARISC_TLS_GD21L: | |
4117 | case R_PARISC_TLS_GD14R: | |
4118 | case R_PARISC_TLS_IE21L: | |
4119 | case R_PARISC_TLS_IE14R: | |
4120 | { | |
4121 | bfd_vma off; | |
4122 | int indx; | |
4123 | char tls_type; | |
4124 | ||
4125 | indx = 0; | |
4126 | if (hh != NULL) | |
4127 | { | |
4128 | bfd_boolean dyn; | |
4129 | dyn = htab->etab.dynamic_sections_created; | |
4130 | ||
0e1862bb L |
4131 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, |
4132 | bfd_link_pic (info), | |
4133 | &hh->eh) | |
4134 | && (!bfd_link_pic (info) | |
9b52905e NC |
4135 | || !SYMBOL_REFERENCES_LOCAL (info, &hh->eh))) |
4136 | { | |
4137 | indx = hh->eh.dynindx; | |
4138 | } | |
4139 | off = hh->eh.got.offset; | |
4140 | tls_type = hh->tls_type; | |
4141 | } | |
4142 | else | |
4143 | { | |
4144 | off = local_got_offsets[r_symndx]; | |
4145 | tls_type = hppa_elf_local_got_tls_type (input_bfd)[r_symndx]; | |
4146 | } | |
4147 | ||
4148 | if (tls_type == GOT_UNKNOWN) | |
4149 | abort (); | |
4150 | ||
4151 | if ((off & 1) != 0) | |
4152 | off &= ~1; | |
4153 | else | |
4154 | { | |
4155 | bfd_boolean need_relocs = FALSE; | |
4156 | Elf_Internal_Rela outrel; | |
4157 | bfd_byte *loc = NULL; | |
4158 | int cur_off = off; | |
4159 | ||
4160 | /* The GOT entries have not been initialized yet. Do it | |
4161 | now, and emit any relocations. If both an IE GOT and a | |
4162 | GD GOT are necessary, we emit the GD first. */ | |
4163 | ||
0e1862bb | 4164 | if ((bfd_link_pic (info) || indx != 0) |
9b52905e NC |
4165 | && (hh == NULL |
4166 | || ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT | |
4167 | || hh->eh.root.type != bfd_link_hash_undefweak)) | |
4168 | { | |
4169 | need_relocs = TRUE; | |
68ffbac6 | 4170 | loc = htab->srelgot->contents; |
9b52905e NC |
4171 | /* FIXME (CAO): Should this be reloc_count++ ? */ |
4172 | loc += htab->srelgot->reloc_count * sizeof (Elf32_External_Rela); | |
4173 | } | |
4174 | ||
4175 | if (tls_type & GOT_TLS_GD) | |
4176 | { | |
4177 | if (need_relocs) | |
4178 | { | |
4179 | outrel.r_offset = (cur_off | |
4180 | + htab->sgot->output_section->vma | |
4181 | + htab->sgot->output_offset); | |
4182 | outrel.r_info = ELF32_R_INFO (indx,R_PARISC_TLS_DTPMOD32); | |
4183 | outrel.r_addend = 0; | |
4184 | bfd_put_32 (output_bfd, 0, htab->sgot->contents + cur_off); | |
4185 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
4186 | htab->srelgot->reloc_count++; | |
4187 | loc += sizeof (Elf32_External_Rela); | |
4188 | ||
4189 | if (indx == 0) | |
4190 | bfd_put_32 (output_bfd, relocation - dtpoff_base (info), | |
4191 | htab->sgot->contents + cur_off + 4); | |
4192 | else | |
4193 | { | |
4194 | bfd_put_32 (output_bfd, 0, | |
4195 | htab->sgot->contents + cur_off + 4); | |
4196 | outrel.r_info = ELF32_R_INFO (indx, R_PARISC_TLS_DTPOFF32); | |
4197 | outrel.r_offset += 4; | |
4198 | bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc); | |
4199 | htab->srelgot->reloc_count++; | |
4200 | loc += sizeof (Elf32_External_Rela); | |
4201 | } | |
4202 | } | |
4203 | else | |
4204 | { | |
4205 | /* If we are not emitting relocations for a | |
4206 | general dynamic reference, then we must be in a | |
4207 | static link or an executable link with the | |
4208 | symbol binding locally. Mark it as belonging | |
4209 | to module 1, the executable. */ | |
4210 | bfd_put_32 (output_bfd, 1, | |
4211 | htab->sgot->contents + cur_off); | |
4212 | bfd_put_32 (output_bfd, relocation - dtpoff_base (info), | |
4213 | htab->sgot->contents + cur_off + 4); | |
4214 | } | |
4215 | ||
4216 | ||
4217 | cur_off += 8; | |
4218 | } | |
4219 | ||
4220 | if (tls_type & GOT_TLS_IE) | |
4221 | { | |
4222 | if (need_relocs) | |
4223 | { | |
4224 | outrel.r_offset = (cur_off | |
4225 | + htab->sgot->output_section->vma | |
4226 | + htab->sgot->output_offset); | |
4227 | outrel.r_info = ELF32_R_INFO (indx, R_PARISC_TLS_TPREL32); | |
4228 | ||
4229 | if (indx == 0) | |
4230 | outrel.r_addend = relocation - dtpoff_base (info); | |
4231 | else | |
4232 | outrel.r_addend = 0; | |
4233 | ||
4234 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
4235 | htab->srelgot->reloc_count++; | |
4236 | loc += sizeof (Elf32_External_Rela); | |
4237 | } | |
4238 | else | |
4239 | bfd_put_32 (output_bfd, tpoff (info, relocation), | |
4240 | htab->sgot->contents + cur_off); | |
4241 | ||
4242 | cur_off += 4; | |
4243 | } | |
4244 | ||
4245 | if (hh != NULL) | |
4246 | hh->eh.got.offset |= 1; | |
4247 | else | |
4248 | local_got_offsets[r_symndx] |= 1; | |
4249 | } | |
4250 | ||
4251 | if ((tls_type & GOT_TLS_GD) | |
4252 | && r_type != R_PARISC_TLS_GD21L | |
4253 | && r_type != R_PARISC_TLS_GD14R) | |
4254 | off += 2 * GOT_ENTRY_SIZE; | |
4255 | ||
4256 | /* Add the base of the GOT to the relocation value. */ | |
4257 | relocation = (off | |
4258 | + htab->sgot->output_offset | |
4259 | + htab->sgot->output_section->vma); | |
4260 | ||
4261 | break; | |
4262 | } | |
4263 | ||
4264 | case R_PARISC_TLS_LE21L: | |
4265 | case R_PARISC_TLS_LE14R: | |
4266 | { | |
4267 | relocation = tpoff (info, relocation); | |
4268 | break; | |
4269 | } | |
4270 | break; | |
edd21aca | 4271 | |
30667bf3 AM |
4272 | default: |
4273 | break; | |
4274 | } | |
252b5132 | 4275 | |
875c0872 DA |
4276 | rstatus = final_link_relocate (input_section, contents, rela, relocation, |
4277 | htab, sym_sec, hh, info); | |
252b5132 | 4278 | |
875c0872 | 4279 | if (rstatus == bfd_reloc_ok) |
30667bf3 | 4280 | continue; |
252b5132 | 4281 | |
875c0872 | 4282 | if (hh != NULL) |
9b52905e | 4283 | sym_name = hh_name (hh); |
30667bf3 AM |
4284 | else |
4285 | { | |
4286 | sym_name = bfd_elf_string_from_elf_section (input_bfd, | |
4287 | symtab_hdr->sh_link, | |
4288 | sym->st_name); | |
4289 | if (sym_name == NULL) | |
b34976b6 | 4290 | return FALSE; |
30667bf3 AM |
4291 | if (*sym_name == '\0') |
4292 | sym_name = bfd_section_name (input_bfd, sym_sec); | |
4293 | } | |
edd21aca | 4294 | |
30667bf3 | 4295 | howto = elf_hppa_howto_table + r_type; |
252b5132 | 4296 | |
875c0872 | 4297 | if (rstatus == bfd_reloc_undefined || rstatus == bfd_reloc_notsupported) |
30667bf3 | 4298 | { |
875c0872 | 4299 | if (rstatus == bfd_reloc_notsupported || !warned_undef) |
f09ebc7d AM |
4300 | { |
4301 | (*_bfd_error_handler) | |
d003868e AM |
4302 | (_("%B(%A+0x%lx): cannot handle %s for %s"), |
4303 | input_bfd, | |
4304 | input_section, | |
875c0872 | 4305 | (long) rela->r_offset, |
f09ebc7d AM |
4306 | howto->name, |
4307 | sym_name); | |
4308 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 4309 | return FALSE; |
f09ebc7d | 4310 | } |
30667bf3 AM |
4311 | } |
4312 | else | |
1a72702b AM |
4313 | (*info->callbacks->reloc_overflow) |
4314 | (info, (hh ? &hh->eh.root : NULL), sym_name, howto->name, | |
4315 | (bfd_vma) 0, input_bfd, input_section, rela->r_offset); | |
30667bf3 | 4316 | } |
edd21aca | 4317 | |
b34976b6 | 4318 | return TRUE; |
30667bf3 | 4319 | } |
252b5132 | 4320 | |
30667bf3 AM |
4321 | /* Finish up dynamic symbol handling. We set the contents of various |
4322 | dynamic sections here. */ | |
252b5132 | 4323 | |
b34976b6 | 4324 | static bfd_boolean |
c39a58e6 AM |
4325 | elf32_hppa_finish_dynamic_symbol (bfd *output_bfd, |
4326 | struct bfd_link_info *info, | |
875c0872 | 4327 | struct elf_link_hash_entry *eh, |
c39a58e6 | 4328 | Elf_Internal_Sym *sym) |
30667bf3 | 4329 | { |
83c81bfe | 4330 | struct elf32_hppa_link_hash_table *htab; |
875c0872 | 4331 | Elf_Internal_Rela rela; |
a252afa4 | 4332 | bfd_byte *loc; |
edd21aca | 4333 | |
83c81bfe | 4334 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
4335 | if (htab == NULL) |
4336 | return FALSE; | |
30667bf3 | 4337 | |
875c0872 | 4338 | if (eh->plt.offset != (bfd_vma) -1) |
30667bf3 AM |
4339 | { |
4340 | bfd_vma value; | |
30667bf3 | 4341 | |
875c0872 | 4342 | if (eh->plt.offset & 1) |
8dea1268 AM |
4343 | abort (); |
4344 | ||
30667bf3 AM |
4345 | /* This symbol has an entry in the procedure linkage table. Set |
4346 | it up. | |
4347 | ||
4348 | The format of a plt entry is | |
74d1c347 AM |
4349 | <funcaddr> |
4350 | <__gp> | |
47d89dba | 4351 | */ |
30667bf3 | 4352 | value = 0; |
875c0872 DA |
4353 | if (eh->root.type == bfd_link_hash_defined |
4354 | || eh->root.type == bfd_link_hash_defweak) | |
30667bf3 | 4355 | { |
875c0872 DA |
4356 | value = eh->root.u.def.value; |
4357 | if (eh->root.u.def.section->output_section != NULL) | |
4358 | value += (eh->root.u.def.section->output_offset | |
4359 | + eh->root.u.def.section->output_section->vma); | |
252b5132 | 4360 | } |
edd21aca | 4361 | |
a252afa4 | 4362 | /* Create a dynamic IPLT relocation for this entry. */ |
875c0872 | 4363 | rela.r_offset = (eh->plt.offset |
a252afa4 DA |
4364 | + htab->splt->output_offset |
4365 | + htab->splt->output_section->vma); | |
875c0872 | 4366 | if (eh->dynindx != -1) |
30667bf3 | 4367 | { |
875c0872 DA |
4368 | rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_IPLT); |
4369 | rela.r_addend = 0; | |
30667bf3 | 4370 | } |
ce757d15 | 4371 | else |
47d89dba | 4372 | { |
a252afa4 DA |
4373 | /* This symbol has been marked to become local, and is |
4374 | used by a plabel so must be kept in the .plt. */ | |
875c0872 DA |
4375 | rela.r_info = ELF32_R_INFO (0, R_PARISC_IPLT); |
4376 | rela.r_addend = value; | |
47d89dba AM |
4377 | } |
4378 | ||
a252afa4 DA |
4379 | loc = htab->srelplt->contents; |
4380 | loc += htab->srelplt->reloc_count++ * sizeof (Elf32_External_Rela); | |
875c0872 | 4381 | bfd_elf32_swap_reloca_out (htab->splt->output_section->owner, &rela, loc); |
a252afa4 | 4382 | |
875c0872 | 4383 | if (!eh->def_regular) |
30667bf3 AM |
4384 | { |
4385 | /* Mark the symbol as undefined, rather than as defined in | |
4386 | the .plt section. Leave the value alone. */ | |
4387 | sym->st_shndx = SHN_UNDEF; | |
4388 | } | |
4389 | } | |
edd21aca | 4390 | |
9b52905e NC |
4391 | if (eh->got.offset != (bfd_vma) -1 |
4392 | && (hppa_elf_hash_entry (eh)->tls_type & GOT_TLS_GD) == 0 | |
4393 | && (hppa_elf_hash_entry (eh)->tls_type & GOT_TLS_IE) == 0) | |
30667bf3 | 4394 | { |
30667bf3 AM |
4395 | /* This symbol has an entry in the global offset table. Set it |
4396 | up. */ | |
4397 | ||
875c0872 | 4398 | rela.r_offset = ((eh->got.offset &~ (bfd_vma) 1) |
83c81bfe AM |
4399 | + htab->sgot->output_offset |
4400 | + htab->sgot->output_section->vma); | |
30667bf3 | 4401 | |
4dc86686 AM |
4402 | /* If this is a -Bsymbolic link and the symbol is defined |
4403 | locally or was forced to be local because of a version file, | |
4404 | we just want to emit a RELATIVE reloc. The entry in the | |
4405 | global offset table will already have been initialized in the | |
4406 | relocate_section function. */ | |
0e1862bb | 4407 | if (bfd_link_pic (info) |
a496fbc8 | 4408 | && (SYMBOLIC_BIND (info, eh) || eh->dynindx == -1) |
875c0872 | 4409 | && eh->def_regular) |
30667bf3 | 4410 | { |
875c0872 DA |
4411 | rela.r_info = ELF32_R_INFO (0, R_PARISC_DIR32); |
4412 | rela.r_addend = (eh->root.u.def.value | |
4413 | + eh->root.u.def.section->output_offset | |
4414 | + eh->root.u.def.section->output_section->vma); | |
30667bf3 AM |
4415 | } |
4416 | else | |
4417 | { | |
875c0872 | 4418 | if ((eh->got.offset & 1) != 0) |
49e9d0d3 | 4419 | abort (); |
875c0872 DA |
4420 | |
4421 | bfd_put_32 (output_bfd, 0, htab->sgot->contents + (eh->got.offset & ~1)); | |
4422 | rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_DIR32); | |
4423 | rela.r_addend = 0; | |
30667bf3 | 4424 | } |
edd21aca | 4425 | |
947216bf AM |
4426 | loc = htab->srelgot->contents; |
4427 | loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela); | |
875c0872 | 4428 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
30667bf3 | 4429 | } |
edd21aca | 4430 | |
875c0872 | 4431 | if (eh->needs_copy) |
30667bf3 | 4432 | { |
875c0872 | 4433 | asection *sec; |
30667bf3 AM |
4434 | |
4435 | /* This symbol needs a copy reloc. Set it up. */ | |
4436 | ||
875c0872 DA |
4437 | if (! (eh->dynindx != -1 |
4438 | && (eh->root.type == bfd_link_hash_defined | |
4439 | || eh->root.type == bfd_link_hash_defweak))) | |
49e9d0d3 | 4440 | abort (); |
30667bf3 | 4441 | |
875c0872 | 4442 | sec = htab->srelbss; |
30667bf3 | 4443 | |
875c0872 DA |
4444 | rela.r_offset = (eh->root.u.def.value |
4445 | + eh->root.u.def.section->output_offset | |
4446 | + eh->root.u.def.section->output_section->vma); | |
4447 | rela.r_addend = 0; | |
4448 | rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_COPY); | |
4449 | loc = sec->contents + sec->reloc_count++ * sizeof (Elf32_External_Rela); | |
4450 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
30667bf3 AM |
4451 | } |
4452 | ||
4453 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ | |
9637f6ef | 4454 | if (eh == htab->etab.hdynamic || eh == htab->etab.hgot) |
30667bf3 AM |
4455 | { |
4456 | sym->st_shndx = SHN_ABS; | |
4457 | } | |
4458 | ||
b34976b6 | 4459 | return TRUE; |
30667bf3 AM |
4460 | } |
4461 | ||
98ceb8ce AM |
4462 | /* Used to decide how to sort relocs in an optimal manner for the |
4463 | dynamic linker, before writing them out. */ | |
4464 | ||
4465 | static enum elf_reloc_type_class | |
7e612e98 AM |
4466 | elf32_hppa_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, |
4467 | const asection *rel_sec ATTRIBUTE_UNUSED, | |
4468 | const Elf_Internal_Rela *rela) | |
98ceb8ce | 4469 | { |
9b52905e | 4470 | /* Handle TLS relocs first; we don't want them to be marked |
cf35638d | 4471 | relative by the "if (ELF32_R_SYM (rela->r_info) == STN_UNDEF)" |
9b52905e NC |
4472 | check below. */ |
4473 | switch ((int) ELF32_R_TYPE (rela->r_info)) | |
4474 | { | |
4475 | case R_PARISC_TLS_DTPMOD32: | |
4476 | case R_PARISC_TLS_DTPOFF32: | |
4477 | case R_PARISC_TLS_TPREL32: | |
4478 | return reloc_class_normal; | |
4479 | } | |
4480 | ||
cf35638d | 4481 | if (ELF32_R_SYM (rela->r_info) == STN_UNDEF) |
98ceb8ce AM |
4482 | return reloc_class_relative; |
4483 | ||
4484 | switch ((int) ELF32_R_TYPE (rela->r_info)) | |
4485 | { | |
4486 | case R_PARISC_IPLT: | |
4487 | return reloc_class_plt; | |
4488 | case R_PARISC_COPY: | |
4489 | return reloc_class_copy; | |
4490 | default: | |
4491 | return reloc_class_normal; | |
4492 | } | |
4493 | } | |
4494 | ||
30667bf3 AM |
4495 | /* Finish up the dynamic sections. */ |
4496 | ||
b34976b6 | 4497 | static bfd_boolean |
c39a58e6 AM |
4498 | elf32_hppa_finish_dynamic_sections (bfd *output_bfd, |
4499 | struct bfd_link_info *info) | |
30667bf3 AM |
4500 | { |
4501 | bfd *dynobj; | |
83c81bfe | 4502 | struct elf32_hppa_link_hash_table *htab; |
30667bf3 | 4503 | asection *sdyn; |
894891db | 4504 | asection * sgot; |
30667bf3 | 4505 | |
83c81bfe | 4506 | htab = hppa_link_hash_table (info); |
4dfe6ac6 NC |
4507 | if (htab == NULL) |
4508 | return FALSE; | |
4509 | ||
a63e02c7 | 4510 | dynobj = htab->etab.dynobj; |
30667bf3 | 4511 | |
894891db NC |
4512 | sgot = htab->sgot; |
4513 | /* A broken linker script might have discarded the dynamic sections. | |
4514 | Catch this here so that we do not seg-fault later on. */ | |
4515 | if (sgot != NULL && bfd_is_abs_section (sgot->output_section)) | |
4516 | return FALSE; | |
4517 | ||
3d4d4302 | 4518 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
30667bf3 | 4519 | |
a63e02c7 | 4520 | if (htab->etab.dynamic_sections_created) |
30667bf3 AM |
4521 | { |
4522 | Elf32_External_Dyn *dyncon, *dynconend; | |
4523 | ||
49e9d0d3 AM |
4524 | if (sdyn == NULL) |
4525 | abort (); | |
30667bf3 AM |
4526 | |
4527 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 4528 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
30667bf3 | 4529 | for (; dyncon < dynconend; dyncon++) |
edd21aca | 4530 | { |
30667bf3 AM |
4531 | Elf_Internal_Dyn dyn; |
4532 | asection *s; | |
4533 | ||
4534 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
4535 | ||
4536 | switch (dyn.d_tag) | |
4537 | { | |
4538 | default: | |
3ac8354b | 4539 | continue; |
30667bf3 AM |
4540 | |
4541 | case DT_PLTGOT: | |
4542 | /* Use PLTGOT to set the GOT register. */ | |
4543 | dyn.d_un.d_ptr = elf_gp (output_bfd); | |
30667bf3 AM |
4544 | break; |
4545 | ||
4546 | case DT_JMPREL: | |
83c81bfe | 4547 | s = htab->srelplt; |
30667bf3 | 4548 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
30667bf3 AM |
4549 | break; |
4550 | ||
4551 | case DT_PLTRELSZ: | |
83c81bfe | 4552 | s = htab->srelplt; |
eea6121a | 4553 | dyn.d_un.d_val = s->size; |
30667bf3 | 4554 | break; |
4e12ff7f AM |
4555 | |
4556 | case DT_RELASZ: | |
4557 | /* Don't count procedure linkage table relocs in the | |
4558 | overall reloc count. */ | |
6348e046 AM |
4559 | s = htab->srelplt; |
4560 | if (s == NULL) | |
4561 | continue; | |
eea6121a | 4562 | dyn.d_un.d_val -= s->size; |
6348e046 AM |
4563 | break; |
4564 | ||
4565 | case DT_RELA: | |
4566 | /* We may not be using the standard ELF linker script. | |
4567 | If .rela.plt is the first .rela section, we adjust | |
4568 | DT_RELA to not include it. */ | |
4569 | s = htab->srelplt; | |
4570 | if (s == NULL) | |
4571 | continue; | |
4572 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) | |
4573 | continue; | |
eea6121a | 4574 | dyn.d_un.d_ptr += s->size; |
4e12ff7f | 4575 | break; |
30667bf3 | 4576 | } |
3ac8354b AM |
4577 | |
4578 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
edd21aca | 4579 | } |
252b5132 | 4580 | } |
edd21aca | 4581 | |
894891db | 4582 | if (sgot != NULL && sgot->size != 0) |
30667bf3 | 4583 | { |
74d1c347 AM |
4584 | /* Fill in the first entry in the global offset table. |
4585 | We use it to point to our dynamic section, if we have one. */ | |
30667bf3 | 4586 | bfd_put_32 (output_bfd, |
c39a58e6 | 4587 | sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0, |
894891db | 4588 | sgot->contents); |
30667bf3 | 4589 | |
74d1c347 | 4590 | /* The second entry is reserved for use by the dynamic linker. */ |
894891db | 4591 | memset (sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE); |
74d1c347 | 4592 | |
30667bf3 | 4593 | /* Set .got entry size. */ |
894891db | 4594 | elf_section_data (sgot->output_section) |
74d1c347 | 4595 | ->this_hdr.sh_entsize = GOT_ENTRY_SIZE; |
30667bf3 AM |
4596 | } |
4597 | ||
eea6121a | 4598 | if (htab->splt != NULL && htab->splt->size != 0) |
47d89dba | 4599 | { |
f3c3938c JDA |
4600 | /* Set plt entry size to 0 instead of PLT_ENTRY_SIZE, since we add the |
4601 | plt stubs and as such the section does not hold a table of fixed-size | |
4602 | entries. */ | |
4603 | elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize = 0; | |
47d89dba | 4604 | |
83c81bfe | 4605 | if (htab->need_plt_stub) |
47d89dba AM |
4606 | { |
4607 | /* Set up the .plt stub. */ | |
83c81bfe | 4608 | memcpy (htab->splt->contents |
eea6121a | 4609 | + htab->splt->size - sizeof (plt_stub), |
47d89dba AM |
4610 | plt_stub, sizeof (plt_stub)); |
4611 | ||
83c81bfe AM |
4612 | if ((htab->splt->output_offset |
4613 | + htab->splt->output_section->vma | |
eea6121a | 4614 | + htab->splt->size) |
894891db NC |
4615 | != (sgot->output_offset |
4616 | + sgot->output_section->vma)) | |
47d89dba AM |
4617 | { |
4618 | (*_bfd_error_handler) | |
4619 | (_(".got section not immediately after .plt section")); | |
b34976b6 | 4620 | return FALSE; |
47d89dba AM |
4621 | } |
4622 | } | |
4623 | } | |
30667bf3 | 4624 | |
b34976b6 | 4625 | return TRUE; |
30667bf3 | 4626 | } |
252b5132 | 4627 | |
30667bf3 AM |
4628 | /* Called when writing out an object file to decide the type of a |
4629 | symbol. */ | |
4630 | static int | |
c39a58e6 | 4631 | elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type) |
30667bf3 AM |
4632 | { |
4633 | if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI) | |
4634 | return STT_PARISC_MILLI; | |
4635 | else | |
4636 | return type; | |
252b5132 RH |
4637 | } |
4638 | ||
4639 | /* Misc BFD support code. */ | |
30667bf3 AM |
4640 | #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name |
4641 | #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup | |
0c8d6e5c | 4642 | #define bfd_elf32_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup |
30667bf3 AM |
4643 | #define elf_info_to_howto elf_hppa_info_to_howto |
4644 | #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel | |
252b5132 | 4645 | |
252b5132 | 4646 | /* Stuff for the BFD linker. */ |
c46b7515 | 4647 | #define bfd_elf32_bfd_final_link elf32_hppa_final_link |
30667bf3 | 4648 | #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create |
30667bf3 | 4649 | #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol |
ebe50bae | 4650 | #define elf_backend_copy_indirect_symbol elf32_hppa_copy_indirect_symbol |
30667bf3 AM |
4651 | #define elf_backend_check_relocs elf32_hppa_check_relocs |
4652 | #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections | |
4653 | #define elf_backend_fake_sections elf_hppa_fake_sections | |
4654 | #define elf_backend_relocate_section elf32_hppa_relocate_section | |
74d1c347 | 4655 | #define elf_backend_hide_symbol elf32_hppa_hide_symbol |
30667bf3 AM |
4656 | #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol |
4657 | #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections | |
4658 | #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections | |
74541ad4 | 4659 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
30667bf3 AM |
4660 | #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook |
4661 | #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook | |
edfc032f AM |
4662 | #define elf_backend_grok_prstatus elf32_hppa_grok_prstatus |
4663 | #define elf_backend_grok_psinfo elf32_hppa_grok_psinfo | |
30667bf3 AM |
4664 | #define elf_backend_object_p elf32_hppa_object_p |
4665 | #define elf_backend_final_write_processing elf_hppa_final_write_processing | |
4666 | #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type | |
98ceb8ce | 4667 | #define elf_backend_reloc_type_class elf32_hppa_reloc_type_class |
8a696751 | 4668 | #define elf_backend_action_discarded elf_hppa_action_discarded |
30667bf3 AM |
4669 | |
4670 | #define elf_backend_can_gc_sections 1 | |
51b64d56 | 4671 | #define elf_backend_can_refcount 1 |
30667bf3 AM |
4672 | #define elf_backend_plt_alignment 2 |
4673 | #define elf_backend_want_got_plt 0 | |
4674 | #define elf_backend_plt_readonly 0 | |
4675 | #define elf_backend_want_plt_sym 0 | |
74d1c347 | 4676 | #define elf_backend_got_header_size 8 |
f0fe0e16 | 4677 | #define elf_backend_rela_normal 1 |
252b5132 | 4678 | |
6d00b590 | 4679 | #define TARGET_BIG_SYM hppa_elf32_vec |
252b5132 RH |
4680 | #define TARGET_BIG_NAME "elf32-hppa" |
4681 | #define ELF_ARCH bfd_arch_hppa | |
ae95ffa6 | 4682 | #define ELF_TARGET_ID HPPA32_ELF_DATA |
252b5132 RH |
4683 | #define ELF_MACHINE_CODE EM_PARISC |
4684 | #define ELF_MAXPAGESIZE 0x1000 | |
d1036acb | 4685 | #define ELF_OSABI ELFOSABI_HPUX |
914dfb0f | 4686 | #define elf32_bed elf32_hppa_hpux_bed |
252b5132 RH |
4687 | |
4688 | #include "elf32-target.h" | |
d952f17a AM |
4689 | |
4690 | #undef TARGET_BIG_SYM | |
6d00b590 | 4691 | #define TARGET_BIG_SYM hppa_elf32_linux_vec |
d952f17a | 4692 | #undef TARGET_BIG_NAME |
914dfb0f | 4693 | #define TARGET_BIG_NAME "elf32-hppa-linux" |
d1036acb | 4694 | #undef ELF_OSABI |
9c55345c | 4695 | #define ELF_OSABI ELFOSABI_GNU |
914dfb0f DA |
4696 | #undef elf32_bed |
4697 | #define elf32_bed elf32_hppa_linux_bed | |
d952f17a | 4698 | |
d952f17a | 4699 | #include "elf32-target.h" |
225247f0 JT |
4700 | |
4701 | #undef TARGET_BIG_SYM | |
6d00b590 | 4702 | #define TARGET_BIG_SYM hppa_elf32_nbsd_vec |
225247f0 | 4703 | #undef TARGET_BIG_NAME |
914dfb0f | 4704 | #define TARGET_BIG_NAME "elf32-hppa-netbsd" |
d1036acb L |
4705 | #undef ELF_OSABI |
4706 | #define ELF_OSABI ELFOSABI_NETBSD | |
914dfb0f DA |
4707 | #undef elf32_bed |
4708 | #define elf32_bed elf32_hppa_netbsd_bed | |
225247f0 JT |
4709 | |
4710 | #include "elf32-target.h" |