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