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