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