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