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