Use a hash table when writing out ELF symbol names.
[binutils-gdb.git] / bfd / elf32-hppa.c
1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
3
4 Written by
5
6 Center for Software Science
7 Department of Computer Science
8 University of Utah
9
10 This file is part of BFD, the Binary File Descriptor library.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25
26 #include "bfd.h"
27 #include "sysdep.h"
28 #include "bfdlink.h"
29 #include "libbfd.h"
30 #include "obstack.h"
31 #include "libelf.h"
32
33
34 /* HPPA symbol table extension entry types */
35 enum elf32_hppa_symextn_types
36 {
37 PARISC_SXT_NULL,
38 PARISC_SXT_SYMNDX,
39 PARISC_SXT_ARG_RELOC,
40 };
41
42 /* These macros compose and decompose the value of a symextn entry:
43
44 entry_type = ELF32_PARISC_SX_TYPE(word);
45 entry_value = ELF32_PARISC_SX_VAL(word);
46 word = ELF32_PARISC_SX_WORD(type,val); */
47
48 #define ELF32_PARISC_SX_TYPE(p) ((p) >> 24)
49 #define ELF32_PARISC_SX_VAL(p) ((p) & 0xFFFFFF)
50 #define ELF32_PARISC_SX_WORD(type,val) (((type) << 24) + (val & 0xFFFFFF))
51
52 /* The following was added facilitate implementation of the .hppa_symextn
53 section. This section is built after the symbol table is built in the
54 elf_write_object_contents routine (called from bfd_close). It is built
55 so late because it requires information that is not known until
56 the symbol and string table sections have been allocated, and
57 the symbol table has been built. */
58
59 #define SYMEXTN_SECTION_NAME ".PARISC.symext"
60
61 /* FIXME. Are these external? (For example used by GAS?). If so the
62 names need to change to avoid namespace pollution, if not they should
63 be moved into elf32-hppa.c. */
64 typedef unsigned long symext_entryS;
65 struct symext_chain
66 {
67 symext_entryS entry;
68 struct symext_chain *next;
69 };
70
71 typedef struct symext_chain symext_chainS;
72
73 /* We use three different hash tables to hold information for
74 linking PA ELF objects.
75
76 The first is the elf32_hppa_link_hash_table which is derived
77 from the standard ELF linker hash table. We use this as a place to
78 attach other hash tables and static information.
79
80 The second is the stub hash table which is derived from the
81 base BFD hash table. The stub hash table holds the information
82 necessary to build the linker stubs during a link.
83
84 The last hash table keeps track of argument location information needed
85 to build hash tables. Each function with nonzero argument location
86 bits will have an entry in this table. */
87
88 /* Hash table for linker stubs. */
89
90 struct elf32_hppa_stub_hash_entry
91 {
92 /* Base hash table entry structure, we can get the name of the stub
93 (and thus know exactly what actions it performs) from the base
94 hash table entry. */
95 struct bfd_hash_entry root;
96
97 /* Offset of the beginning of this stub. */
98 bfd_vma offset;
99
100 /* Given the symbol's value and its section we can determine its final
101 value when building the stubs (so the stub knows where to jump. */
102 symvalue target_value;
103 asection *target_section;
104 };
105
106 struct elf32_hppa_stub_hash_table
107 {
108 /* The hash table itself. */
109 struct bfd_hash_table root;
110
111 /* The stub BFD. */
112 bfd *stub_bfd;
113
114 /* Where to place the next stub. */
115 bfd_byte *location;
116
117 /* Current offset in the stub section. */
118 unsigned int offset;
119
120 };
121
122 /* Hash table for argument location information. */
123
124 struct elf32_hppa_args_hash_entry
125 {
126 /* Base hash table entry structure. */
127 struct bfd_hash_entry root;
128
129 /* The argument location bits for this entry. */
130 int arg_bits;
131 };
132
133 struct elf32_hppa_args_hash_table
134 {
135 /* The hash table itself. */
136 struct bfd_hash_table root;
137 };
138
139 struct elf32_hppa_link_hash_entry
140 {
141 struct elf_link_hash_entry root;
142 };
143
144 struct elf32_hppa_link_hash_table
145 {
146 /* The main hash table. */
147 struct elf_link_hash_table root;
148
149 /* The stub hash table. */
150 struct elf32_hppa_stub_hash_table *stub_hash_table;
151
152 /* The argument relocation bits hash table. */
153 struct elf32_hppa_args_hash_table *args_hash_table;
154
155 /* A count of the number of output symbols. */
156 unsigned int output_symbol_count;
157
158 /* Stuff so we can handle DP relative relocations. */
159 long global_value;
160 int global_sym_defined;
161 };
162
163 typedef unsigned int symextn_entry;
164
165 /* FIXME. */
166 #define ARGUMENTS 0
167 #define RETURN_VALUE 1
168
169 /* The various argument relocations that may be performed. */
170 typedef enum
171 {
172 /* No relocation. */
173 NO,
174 /* Relocate 32 bits from GR to FP register. */
175 GF,
176 /* Relocate 64 bits from a GR pair to FP pair. */
177 GD,
178 /* Relocate 32 bits from FP to GR. */
179 FG,
180 /* Relocate 64 bits from FP pair to GR pair. */
181 DG,
182 } arg_reloc_type;
183
184 /* What is being relocated (eg which argument or the return value). */
185 typedef enum
186 {
187 ARG0, ARG1, ARG2, ARG3, RET,
188 } arg_reloc_location;
189
190
191 /* ELF32/HPPA relocation support
192
193 This file contains ELF32/HPPA relocation support as specified
194 in the Stratus FTX/Golf Object File Format (SED-1762) dated
195 February 1994. */
196
197 #include "elf32-hppa.h"
198 #include "hppa_stubs.h"
199
200 static bfd_reloc_status_type hppa_elf_reloc
201 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
202
203 static unsigned long hppa_elf_relocate_insn
204 PARAMS ((bfd *, asection *, unsigned long, unsigned long, long,
205 long, unsigned long, unsigned long, unsigned long));
206
207 static bfd_reloc_status_type hppa_elf_reloc
208 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd*, char **));
209
210 static CONST reloc_howto_type * elf_hppa_reloc_type_lookup
211 PARAMS ((bfd *, bfd_reloc_code_real_type));
212
213 static boolean elf32_hppa_set_section_contents
214 PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
215
216 static void elf_info_to_howto
217 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
218
219 static boolean elf32_hppa_backend_symbol_table_processing
220 PARAMS ((bfd *, elf_symbol_type *, int));
221
222 static void elf32_hppa_backend_begin_write_processing
223 PARAMS ((bfd *, struct bfd_link_info *));
224
225 static void elf32_hppa_backend_final_write_processing
226 PARAMS ((bfd *, boolean));
227
228 static void add_entry_to_symext_chain
229 PARAMS ((bfd *, unsigned int, unsigned int, symext_chainS **,
230 symext_chainS **));
231
232 static void
233 elf_hppa_tc_make_sections PARAMS ((bfd *, symext_chainS *));
234
235 static boolean hppa_elf_is_local_label PARAMS ((bfd *, asymbol *));
236
237 static boolean elf32_hppa_add_symbol_hook
238 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
239 const char **, flagword *, asection **, bfd_vma *));
240
241 static bfd_reloc_status_type elf32_hppa_bfd_final_link_relocate
242 PARAMS ((const reloc_howto_type *, bfd *, bfd *, asection *,
243 bfd_byte *, bfd_vma, bfd_vma, bfd_vma, struct bfd_link_info *,
244 asection *, const char *, int));
245
246 static struct bfd_link_hash_table *elf32_hppa_link_hash_table_create
247 PARAMS ((bfd *));
248
249 static struct bfd_hash_entry *
250 elf32_hppa_stub_hash_newfunc
251 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
252
253 static struct bfd_hash_entry *
254 elf32_hppa_args_hash_newfunc
255 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
256
257 static boolean
258 elf32_hppa_relocate_section
259 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
260 bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
261
262 static boolean
263 elf32_hppa_stub_hash_table_init
264 PARAMS ((struct elf32_hppa_stub_hash_table *, bfd *,
265 struct bfd_hash_entry *(*) PARAMS ((struct bfd_hash_entry *,
266 struct bfd_hash_table *,
267 const char *))));
268
269 static boolean
270 elf32_hppa_build_one_stub PARAMS ((struct bfd_hash_entry *, PTR));
271
272 static boolean
273 elf32_hppa_read_symext_info
274 PARAMS ((bfd *, Elf_Internal_Shdr *, struct elf32_hppa_args_hash_table *,
275 Elf_Internal_Sym *, boolean, boolean));
276
277 static unsigned int elf32_hppa_size_of_stub
278 PARAMS ((unsigned int, unsigned int, bfd_vma, bfd_vma, const char *));
279
280 static boolean elf32_hppa_arg_reloc_needed
281 PARAMS ((unsigned int, unsigned int, arg_reloc_type []));
282
283 static void elf32_hppa_name_of_stub
284 PARAMS ((unsigned int, unsigned int, bfd_vma, bfd_vma, char *));
285
286 static boolean elf32_hppa_size_symext PARAMS ((struct bfd_hash_entry *, PTR));
287
288 static boolean elf32_hppa_link_output_symbol_hook
289 PARAMS ((bfd *, struct bfd_link_info *, const char *,
290 Elf_Internal_Sym *, asection *));
291
292 /* ELF/PA relocation howto entries. */
293
294 static reloc_howto_type elf_hppa_howto_table[ELF_HOWTO_TABLE_SIZE] =
295 {
296 {R_PARISC_NONE, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_NONE"},
297 {R_PARISC_DIR32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR32"},
298 {R_PARISC_DIR21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR21L"},
299 {R_PARISC_DIR17R, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR17R"},
300 {R_PARISC_DIR17F, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR17F"},
301 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
302 {R_PARISC_DIR14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR14R"},
303 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
304
305 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
306 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
307 {R_PARISC_PCREL21L, 0, 0, 21, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL21L"},
308 {R_PARISC_PCREL17R, 0, 0, 17, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL17R"},
309 {R_PARISC_PCREL17F, 0, 0, 17, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL17F"},
310 {R_PARISC_PCREL17C, 0, 0, 17, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL17C"},
311 {R_PARISC_PCREL14R, 0, 0, 14, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL14R"},
312 {R_PARISC_PCREL14F, 0, 0, 14, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL14F"},
313
314 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
315 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
316 {R_PARISC_DPREL21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DPREL21L"},
317 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
318 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
319 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
320 {R_PARISC_DPREL14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DPREL14R"},
321 {R_PARISC_DPREL14F, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DPREL14F"},
322
323 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
324 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
325 {R_PARISC_DLTREL21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTREL21L"},
326 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
327 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
328 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
329 {R_PARISC_DLTREL14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTREL14R"},
330 {R_PARISC_DLTREL14F, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTREL14F"},
331
332 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
333 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
334 {R_PARISC_DLTIND21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTIND21L"},
335 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
336 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
337 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
338 {R_PARISC_DLTIND14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTIND14R"},
339 {R_PARISC_DLTIND14F, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTIND14F"},
340
341 {R_PARISC_SETBASE, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_SETBASE"},
342 {R_PARISC_BASEREL32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL32"},
343 {R_PARISC_BASEREL21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL21L"},
344 {R_PARISC_BASEREL17R, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL17R"},
345 {R_PARISC_BASEREL17F, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL17F"},
346 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
347 {R_PARISC_BASEREL14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL14R"},
348 {R_PARISC_BASEREL14F, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL14F"},
349
350 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
351 {R_PARISC_TEXTREL32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_TEXTREL32"},
352 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
353 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
354 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
355 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
356 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
357 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
358
359 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
360 {R_PARISC_DATAREL32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
361 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
362 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
363 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
364 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
365 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
366 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
367
368
369 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
370 {R_PARISC_PLABEL32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLABEL32"},
371 {R_PARISC_PLABEL21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLABEL21L"},
372 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
373 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
374 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
375 {R_PARISC_PLABEL14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLABEL14R"},
376 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
377
378 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
379 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
380 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
381 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
382 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
383 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
384 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
385 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
386
387 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
388 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
389 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
390 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
391 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
392 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
393 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
394 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
395 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
396 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
397 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
398 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
399 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
400 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
401 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
402 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
403
404 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
405 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
406 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
407 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
408 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
409 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
410 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
411 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
412 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
413 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
414 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
415 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
416 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
417 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
418 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
419 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
420
421 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
422 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
423 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
424 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
425 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
426 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
427 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
428 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
429 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
430 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
431 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
432 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
433 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
434 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
435 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
436 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
437
438
439 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
440 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
441 {R_PARISC_PLTIND21L, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLTIND21L"},
442 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
443 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
444 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
445 {R_PARISC_PLTIND14R, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLTIND14R"},
446 {R_PARISC_PLTIND14F, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLTIND14F"},
447
448
449 {R_PARISC_COPY, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_COPY"},
450 {R_PARISC_GLOB_DAT, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_GLOB_DAT"},
451 {R_PARISC_JMP_SLOT, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_JMP_SLOT"},
452 {R_PARISC_RELATIVE, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_RELATIVE"},
453
454 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_dont, NULL, "R_PARISC_UNIMPLEMENTED"},
455 };
456
457 /* Where (what register type) is an argument comming from? */
458 typedef enum
459 {
460 AR_NO,
461 AR_GR,
462 AR_FR,
463 AR_FU,
464 AR_FPDBL1,
465 AR_FPDBL2,
466 } arg_location;
467
468 /* Horizontal represents the callee's argument location information,
469 vertical represents caller's argument location information. Value at a
470 particular X,Y location represents what (if any) argument relocation
471 needs to be performed to make caller and callee agree. */
472
473 static CONST arg_reloc_type arg_mismatches[6][6] =
474 {
475 {NO, NO, NO, NO, NO, NO},
476 {NO, NO, GF, NO, GD, NO},
477 {NO, FG, NO, NO, NO, NO},
478 {NO, NO, NO, NO, NO, NO},
479 {NO, DG, NO, NO, NO, NO},
480 {NO, DG, NO, NO, NO, NO},
481 };
482
483 /* Likewise, but reversed for the return value. */
484 static CONST arg_reloc_type ret_mismatches[6][6] =
485 {
486 {NO, NO, NO, NO, NO, NO},
487 {NO, NO, FG, NO, DG, NO},
488 {NO, GF, NO, NO, NO, NO},
489 {NO, NO, NO, NO, NO, NO},
490 {NO, GD, NO, NO, NO, NO},
491 {NO, GD, NO, NO, NO, NO},
492 };
493
494 /* Misc static crud for symbol extension records. */
495 static symext_chainS *symext_rootP;
496 static symext_chainS *symext_lastP;
497 static int symext_chain_size;
498
499 /* FIXME: We should be able to try this static variable! */
500 static symext_entryS *symextn_contents;
501
502
503 /* For linker stub hash tables. */
504 #define elf32_hppa_stub_hash_lookup(table, string, create, copy) \
505 ((struct elf32_hppa_stub_hash_entry *) \
506 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
507
508 #define elf32_hppa_stub_hash_traverse(table, func, info) \
509 (bfd_hash_traverse \
510 (&(table)->root, \
511 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
512 (info)))
513
514 /* For linker args hash tables. */
515 #define elf32_hppa_args_hash_lookup(table, string, create, copy) \
516 ((struct elf32_hppa_args_hash_entry *) \
517 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
518
519 #define elf32_hppa_args_hash_traverse(table, func, info) \
520 (bfd_hash_traverse \
521 (&(table)->root, \
522 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
523 (info)))
524
525 #define elf32_hppa_args_hash_table_init(table, newfunc) \
526 (bfd_hash_table_init \
527 (&(table)->root, \
528 (struct bfd_hash_entry *(*) PARAMS ((struct bfd_hash_entry *, \
529 struct bfd_hash_table *, \
530 const char *))) (newfunc)))
531
532 /* For HPPA linker hash table. */
533
534 #define elf32_hppa_link_hash_lookup(table, string, create, copy, follow)\
535 ((struct elf32_hppa_link_hash_entry *) \
536 elf_link_hash_lookup (&(table)->root, (string), (create), \
537 (copy), (follow)))
538
539 #define elf32_hppa_link_hash_traverse(table, func, info) \
540 (elf_link_hash_traverse \
541 (&(table)->root, \
542 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
543 (info)))
544
545 /* Get the PA ELF linker hash table from a link_info structure. */
546
547 #define elf32_hppa_hash_table(p) \
548 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
549
550
551 /* Extract specific argument location bits for WHICH from
552 the full argument location in AR. */
553 #define EXTRACT_ARBITS(ar, which) ((ar) >> (8 - ((which) * 2))) & 3
554
555 /* Assorted hash table functions. */
556
557 /* Initialize an entry in the stub hash table. */
558
559 static struct bfd_hash_entry *
560 elf32_hppa_stub_hash_newfunc (entry, table, string)
561 struct bfd_hash_entry *entry;
562 struct bfd_hash_table *table;
563 const char *string;
564 {
565 struct elf32_hppa_stub_hash_entry *ret;
566
567 ret = (struct elf32_hppa_stub_hash_entry *) entry;
568
569 /* Allocate the structure if it has not already been allocated by a
570 subclass. */
571 if (ret == NULL)
572 ret = ((struct elf32_hppa_stub_hash_entry *)
573 bfd_hash_allocate (table,
574 sizeof (struct elf32_hppa_stub_hash_entry)));
575 if (ret == NULL)
576 {
577 bfd_set_error (bfd_error_no_memory);
578 return NULL;
579 }
580
581 /* Call the allocation method of the superclass. */
582 ret = ((struct elf32_hppa_stub_hash_entry *)
583 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
584
585 if (ret)
586 {
587 /* Initialize the local fields. */
588 ret->offset = 0;
589 ret->target_value = 0;
590 ret->target_section = NULL;
591 }
592
593 return (struct bfd_hash_entry *) ret;
594 }
595
596 /* Initialize a stub hash table. */
597
598 static boolean
599 elf32_hppa_stub_hash_table_init (table, stub_bfd, newfunc)
600 struct elf32_hppa_stub_hash_table *table;
601 bfd *stub_bfd;
602 struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
603 struct bfd_hash_table *,
604 const char *));
605 {
606 table->offset = 0;
607 table->location = 0;
608 table->stub_bfd = stub_bfd;
609 return (bfd_hash_table_init (&table->root, newfunc));
610 }
611
612 /* Initialize an entry in the argument location hash table. */
613
614 static struct bfd_hash_entry *
615 elf32_hppa_args_hash_newfunc (entry, table, string)
616 struct bfd_hash_entry *entry;
617 struct bfd_hash_table *table;
618 const char *string;
619 {
620 struct elf32_hppa_args_hash_entry *ret;
621
622 ret = (struct elf32_hppa_args_hash_entry *) entry;
623
624 /* Allocate the structure if it has not already been allocated by a
625 subclass. */
626 if (ret == NULL)
627 ret = ((struct elf32_hppa_args_hash_entry *)
628 bfd_hash_allocate (table,
629 sizeof (struct elf32_hppa_args_hash_entry)));
630 if (ret == NULL)
631 {
632 bfd_set_error (bfd_error_no_memory);
633 return NULL;
634 }
635
636 /* Call the allocation method of the superclass. */
637 ret = ((struct elf32_hppa_args_hash_entry *)
638 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
639
640 /* Initialize the local fields. */
641 if (ret)
642 ret->arg_bits = 0;
643
644 return (struct bfd_hash_entry *) ret;
645 }
646
647 /* Create the derived linker hash table. The PA ELF port uses the derived
648 hash table to keep information specific to the PA ELF linker (without
649 using static variables). */
650
651 static struct bfd_link_hash_table *
652 elf32_hppa_link_hash_table_create (abfd)
653 bfd *abfd;
654 {
655 struct elf32_hppa_link_hash_table *ret;
656
657 ret = ((struct elf32_hppa_link_hash_table *)
658 bfd_alloc (abfd, sizeof (struct elf32_hppa_link_hash_table)));
659 if (ret == NULL)
660 {
661 bfd_set_error (bfd_error_no_memory);
662 return NULL;
663 }
664 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
665 _bfd_elf_link_hash_newfunc))
666 {
667 bfd_release (abfd, ret);
668 return NULL;
669 }
670 ret->stub_hash_table = NULL;
671 ret->args_hash_table = NULL;
672 ret->output_symbol_count = 0;
673 ret->global_value = 0;
674 ret->global_sym_defined = 0;
675
676 return &ret->root.root;
677 }
678
679 /* Relocate the given INSN given the various input parameters.
680
681 FIXME: endianness and sizeof (long) issues abound here. */
682
683 static unsigned long
684 hppa_elf_relocate_insn (abfd, input_sect, insn, address, sym_value,
685 r_addend, r_format, r_field, pcrel)
686 bfd *abfd;
687 asection *input_sect;
688 unsigned long insn;
689 unsigned long address;
690 long sym_value;
691 long r_addend;
692 unsigned long r_format;
693 unsigned long r_field;
694 unsigned long pcrel;
695 {
696 unsigned char opcode = get_opcode (insn);
697 long constant_value;
698
699 switch (opcode)
700 {
701 case LDO:
702 case LDB:
703 case LDH:
704 case LDW:
705 case LDWM:
706 case STB:
707 case STH:
708 case STW:
709 case STWM:
710 case COMICLR:
711 case SUBI:
712 case ADDIT:
713 case ADDI:
714 case LDIL:
715 case ADDIL:
716 constant_value = HPPA_R_CONSTANT (r_addend);
717
718 if (pcrel)
719 sym_value -= address;
720
721 sym_value = hppa_field_adjust (sym_value, constant_value, r_field);
722 return hppa_rebuild_insn (abfd, insn, sym_value, r_format);
723
724 case BL:
725 case BE:
726 case BLE:
727 /* XXX computing constant_value is not needed??? */
728 constant_value = assemble_17 ((insn & 0x001f0000) >> 16,
729 (insn & 0x00001ffc) >> 2,
730 insn & 1);
731
732 constant_value = (constant_value << 15) >> 15;
733 if (pcrel)
734 {
735 sym_value -=
736 address + input_sect->output_offset
737 + input_sect->output_section->vma;
738 sym_value = hppa_field_adjust (sym_value, -8, r_field);
739 }
740 else
741 sym_value = hppa_field_adjust (sym_value, constant_value, r_field);
742
743 return hppa_rebuild_insn (abfd, insn, sym_value >> 2, r_format);
744
745 default:
746 if (opcode == 0)
747 {
748 constant_value = HPPA_R_CONSTANT (r_addend);
749
750 if (pcrel)
751 sym_value -= address;
752
753 return hppa_field_adjust (sym_value, constant_value, r_field);
754 }
755 else
756 abort ();
757 }
758 }
759
760 /* Relocate an HPPA ELF section. */
761
762 static boolean
763 elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
764 contents, relocs, local_syms, local_sections)
765 bfd *output_bfd;
766 struct bfd_link_info *info;
767 bfd *input_bfd;
768 asection *input_section;
769 bfd_byte *contents;
770 Elf_Internal_Rela *relocs;
771 Elf_Internal_Sym *local_syms;
772 asection **local_sections;
773 {
774 Elf_Internal_Shdr *symtab_hdr;
775 Elf_Internal_Rela *rel;
776 Elf_Internal_Rela *relend;
777
778 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
779
780 rel = relocs;
781 relend = relocs + input_section->reloc_count;
782 for (; rel < relend; rel++)
783 {
784 int r_type;
785 const reloc_howto_type *howto;
786 long r_symndx;
787 struct elf_link_hash_entry *h;
788 Elf_Internal_Sym *sym;
789 asection *sym_sec;
790 bfd_vma relocation;
791 bfd_reloc_status_type r;
792 const char *sym_name;
793
794 r_type = ELF32_R_TYPE (rel->r_info);
795 if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED)
796 {
797 bfd_set_error (bfd_error_bad_value);
798 return false;
799 }
800 howto = elf_hppa_howto_table + r_type;
801
802 r_symndx = ELF32_R_SYM (rel->r_info);
803
804 if (info->relocateable)
805 {
806 /* This is a relocateable link. We don't have to change
807 anything, unless the reloc is against a section symbol,
808 in which case we have to adjust according to where the
809 section symbol winds up in the output section. */
810 if (r_symndx < symtab_hdr->sh_info)
811 {
812 sym = local_syms + r_symndx;
813 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
814 {
815 sym_sec = local_sections[r_symndx];
816 rel->r_addend += sym_sec->output_offset;
817 }
818 }
819
820 continue;
821 }
822
823 /* This is a final link. */
824 h = NULL;
825 sym = NULL;
826 sym_sec = NULL;
827 if (r_symndx < symtab_hdr->sh_info)
828 {
829 sym = local_syms + r_symndx;
830 sym_sec = local_sections[r_symndx];
831 relocation = ((ELF_ST_TYPE (sym->st_info) == STT_SECTION
832 ? 0 : sym->st_value)
833 + sym_sec->output_offset
834 + sym_sec->output_section->vma);
835 }
836 else
837 {
838 long indx;
839
840 indx = r_symndx - symtab_hdr->sh_info;
841 h = elf_sym_hashes (input_bfd)[indx];
842 if (h->root.type == bfd_link_hash_defined)
843 {
844 sym_sec = h->root.u.def.section;
845 relocation = (h->root.u.def.value
846 + sym_sec->output_offset
847 + sym_sec->output_section->vma);
848 }
849 else if (h->root.type == bfd_link_hash_weak)
850 relocation = 0;
851 else
852 {
853 if (!((*info->callbacks->undefined_symbol)
854 (info, h->root.root.string, input_bfd,
855 input_section, rel->r_offset)))
856 return false;
857 relocation = 0;
858 }
859 }
860
861 if (h != NULL)
862 sym_name = h->root.root.string;
863 else
864 {
865 sym_name = elf_string_from_elf_section (input_bfd,
866 symtab_hdr->sh_link,
867 sym->st_name);
868 if (sym_name == NULL)
869 return false;
870 if (*sym_name == '\0')
871 sym_name = bfd_section_name (input_bfd, sym_sec);
872 }
873
874 /* If args_hash_table is NULL, then we have encountered some
875 kind of link error (ex. undefined symbols). Do not try to
876 apply any relocations, continue the loop so we can notify
877 the user of several errors in a single attempted link. */
878 if (elf32_hppa_hash_table (info)->args_hash_table == NULL)
879 continue;
880
881 r = elf32_hppa_bfd_final_link_relocate (howto, input_bfd, output_bfd,
882 input_section, contents,
883 rel->r_offset, relocation,
884 rel->r_addend, info, sym_sec,
885 sym_name, h == NULL);
886
887 if (r != bfd_reloc_ok)
888 {
889 switch (r)
890 {
891 case bfd_reloc_dangerous:
892 {
893 /* We use this return value to indicate that we performed
894 a "dangerous" relocation. This doesn't mean we did
895 the wrong thing, it just means there may be some cleanup
896 that needs to be done here.
897
898 In particular we had to swap the last call insn and its
899 delay slot. If the delay slot insn needed a relocation,
900 then we'll need to adjust the next relocation entry's
901 offset to account for the fact that the insn moved.
902
903 This hair wouldn't be necessary if we inserted stubs
904 between procedures and used a "bl" to get to the stub. */
905 if (rel != relend)
906 {
907 Elf_Internal_Rela *next_rel = rel + 1;
908
909 if (rel->r_offset + 4 == next_rel->r_offset)
910 next_rel->r_offset -= 4;
911 }
912 break;
913 }
914 default:
915 case bfd_reloc_outofrange:
916 case bfd_reloc_overflow:
917 {
918 if (!((*info->callbacks->reloc_overflow)
919 (info, sym_name, howto->name, (bfd_vma) 0,
920 input_bfd, input_section, rel->r_offset)))
921 return false;
922 }
923 break;
924 }
925 }
926 }
927
928 return true;
929 }
930
931 /* Return one (or more) BFD relocations which implement the base
932 relocation with modifications based on format and field. */
933
934 elf32_hppa_reloc_type **
935 hppa_elf_gen_reloc_type (abfd, base_type, format, field)
936 bfd *abfd;
937 elf32_hppa_reloc_type base_type;
938 int format;
939 int field;
940 {
941 elf32_hppa_reloc_type *finaltype;
942 elf32_hppa_reloc_type **final_types;
943
944 /* Allocate slots for the BFD relocation. */
945 final_types = (elf32_hppa_reloc_type **)
946 bfd_alloc_by_size_t (abfd, sizeof (elf32_hppa_reloc_type *) * 2);
947 if (final_types == NULL)
948 return NULL;
949
950 /* Allocate space for the relocation itself. */
951 finaltype = (elf32_hppa_reloc_type *)
952 bfd_alloc_by_size_t (abfd, sizeof (elf32_hppa_reloc_type));
953 if (finaltype == NULL)
954 return NULL;
955
956 /* Some reasonable defaults. */
957 final_types[0] = finaltype;
958 final_types[1] = NULL;
959
960 #define final_type finaltype[0]
961
962 final_type = base_type;
963
964 /* Just a tangle of nested switch statements to deal with the braindamage
965 that a different field selector means a completely different relocation
966 for PA ELF. */
967 switch (base_type)
968 {
969 case R_HPPA:
970 case R_HPPA_ABS_CALL:
971 switch (format)
972 {
973 case 14:
974 switch (field)
975 {
976 case e_rsel:
977 case e_rrsel:
978 final_type = R_PARISC_DIR14R;
979 break;
980 case e_rtsel:
981 final_type = R_PARISC_DLTREL14R;
982 break;
983 case e_tsel:
984 final_type = R_PARISC_DLTREL14F;
985 break;
986 case e_rpsel:
987 final_type = R_PARISC_PLABEL14R;
988 break;
989 default:
990 return NULL;
991 }
992 break;
993
994 case 17:
995 switch (field)
996 {
997 case e_fsel:
998 final_type = R_PARISC_DIR17F;
999 break;
1000 case e_rsel:
1001 case e_rrsel:
1002 final_type = R_PARISC_DIR17R;
1003 break;
1004 default:
1005 return NULL;
1006 }
1007 break;
1008
1009 case 21:
1010 switch (field)
1011 {
1012 case e_lsel:
1013 case e_lrsel:
1014 final_type = R_PARISC_DIR21L;
1015 break;
1016 case e_ltsel:
1017 final_type = R_PARISC_DLTREL21L;
1018 break;
1019 case e_lpsel:
1020 final_type = R_PARISC_PLABEL21L;
1021 break;
1022 default:
1023 return NULL;
1024 }
1025 break;
1026
1027 case 32:
1028 switch (field)
1029 {
1030 case e_fsel:
1031 final_type = R_PARISC_DIR32;
1032 break;
1033 case e_psel:
1034 final_type = R_PARISC_PLABEL32;
1035 break;
1036 default:
1037 return NULL;
1038 }
1039 break;
1040
1041 default:
1042 return NULL;
1043 }
1044 break;
1045
1046
1047 case R_HPPA_GOTOFF:
1048 switch (format)
1049 {
1050 case 14:
1051 switch (field)
1052 {
1053 case e_rsel:
1054 case e_rrsel:
1055 final_type = R_PARISC_DPREL14R;
1056 break;
1057 case e_fsel:
1058 final_type = R_PARISC_DPREL14F;
1059 break;
1060 default:
1061 return NULL;
1062 }
1063 break;
1064
1065 case 21:
1066 switch (field)
1067 {
1068 case e_lrsel:
1069 case e_lsel:
1070 final_type = R_PARISC_DPREL21L;
1071 break;
1072 default:
1073 return NULL;
1074 }
1075 break;
1076
1077 default:
1078 return NULL;
1079 }
1080 break;
1081
1082
1083 case R_HPPA_PCREL_CALL:
1084 switch (format)
1085 {
1086 case 14:
1087 switch (field)
1088 {
1089 case e_rsel:
1090 case e_rrsel:
1091 final_type = R_PARISC_PCREL14R;
1092 break;
1093 case e_fsel:
1094 final_type = R_PARISC_PCREL14F;
1095 break;
1096 default:
1097 return NULL;
1098 }
1099 break;
1100
1101 case 17:
1102 switch (field)
1103 {
1104 case e_rsel:
1105 case e_rrsel:
1106 final_type = R_PARISC_PCREL17R;
1107 break;
1108 case e_fsel:
1109 final_type = R_PARISC_PCREL17F;
1110 break;
1111 default:
1112 return NULL;
1113 }
1114 break;
1115
1116 case 21:
1117 switch (field)
1118 {
1119 case e_lsel:
1120 case e_lrsel:
1121 final_type = R_PARISC_PCREL21L;
1122 break;
1123 default:
1124 return NULL;
1125 }
1126 break;
1127
1128 default:
1129 return NULL;
1130 }
1131 break;
1132
1133 default:
1134 return NULL;
1135 }
1136
1137 return final_types;
1138 }
1139
1140 #undef final_type
1141
1142 /* Set the contents of a particular section at a particular location. */
1143
1144 static boolean
1145 elf32_hppa_set_section_contents (abfd, section, location, offset, count)
1146 bfd *abfd;
1147 sec_ptr section;
1148 PTR location;
1149 file_ptr offset;
1150 bfd_size_type count;
1151 {
1152 /* Ignore write requests for the symbol extension section until we've
1153 had the chance to rebuild it ourselves. */
1154 if (!strcmp (section->name, ".PARISC.symextn") && !symext_chain_size)
1155 return true;
1156 else
1157 return bfd_elf32_set_section_contents (abfd, section, location,
1158 offset, count);
1159 }
1160
1161 /* Translate from an elf into field into a howto relocation pointer. */
1162
1163 static void
1164 elf_info_to_howto (abfd, cache_ptr, dst)
1165 bfd *abfd;
1166 arelent *cache_ptr;
1167 Elf32_Internal_Rela *dst;
1168 {
1169 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_PARISC_UNIMPLEMENTED);
1170 cache_ptr->howto = &elf_hppa_howto_table[ELF32_R_TYPE (dst->r_info)];
1171 }
1172
1173
1174 /* Actually perform a relocation. NOTE this is (mostly) superceeded
1175 by elf32_hppa_bfd_final_link_relocate which is called by the new
1176 fast linker. */
1177
1178 static bfd_reloc_status_type
1179 hppa_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
1180 error_message)
1181 bfd *abfd;
1182 arelent *reloc_entry;
1183 asymbol *symbol_in;
1184 PTR data;
1185 asection *input_section;
1186 bfd *output_bfd;
1187 char **error_message;
1188 {
1189 /* It is no longer valid to call hppa_elf_reloc when creating
1190 a final executable. */
1191 if (output_bfd)
1192 {
1193 reloc_entry->address += input_section->output_offset;
1194
1195 /* Work around lossage in generic elf code to write relocations.
1196 (maps different section symbols into the same symbol index). */
1197 if ((symbol_in->flags & BSF_SECTION_SYM)
1198 && symbol_in->section)
1199 reloc_entry->addend += symbol_in->section->output_offset;
1200 return bfd_reloc_ok;
1201 }
1202 else
1203 {
1204 *error_message = (char *) "Unsupported call to hppa_elf_reloc";
1205 return bfd_reloc_notsupported;
1206 }
1207 }
1208
1209 /* Actually perform a relocation as part of a final link. This can get
1210 rather hairy when linker stubs are needed. */
1211
1212 static bfd_reloc_status_type
1213 elf32_hppa_bfd_final_link_relocate (howto, input_bfd, output_bfd,
1214 input_section, contents, offset, value,
1215 addend, info, sym_sec, sym_name, is_local)
1216 const reloc_howto_type *howto;
1217 bfd *input_bfd;
1218 bfd *output_bfd;
1219 asection *input_section;
1220 bfd_byte *contents;
1221 bfd_vma offset;
1222 bfd_vma value;
1223 bfd_vma addend;
1224 struct bfd_link_info *info;
1225 asection *sym_sec;
1226 const char *sym_name;
1227 int is_local;
1228 {
1229 unsigned long insn;
1230 unsigned long r_type = howto->type;
1231 unsigned long r_format = howto->bitsize;
1232 unsigned long r_field = e_fsel;
1233 bfd_byte *hit_data = contents + offset + input_section->vma;
1234 boolean r_pcrel = howto->pc_relative;
1235
1236 insn = bfd_get_32 (input_bfd, hit_data);
1237
1238 /* Make sure we have a value for $global$. FIXME isn't this effectively
1239 just like the gp pointer on MIPS? Can we use those routines for this
1240 purpose? */
1241 if (!elf32_hppa_hash_table (info)->global_sym_defined)
1242 {
1243 struct elf_link_hash_entry *h;
1244 asection *sec;
1245
1246 h = elf_link_hash_lookup (elf_hash_table (info), "$global$", false,
1247 false, false);
1248
1249 /* If there isn't a $global$, then we're in deep trouble. */
1250 if (h == NULL)
1251 return bfd_reloc_notsupported;
1252
1253 sec = h->root.u.def.section;
1254 elf32_hppa_hash_table (info)->global_value = (h->root.u.def.value
1255 + sec->vma
1256 + sec->output_offset);
1257 elf32_hppa_hash_table (info)->global_sym_defined = 1;
1258 }
1259
1260 switch (r_type)
1261 {
1262 case R_PARISC_NONE:
1263 break;
1264
1265 case R_PARISC_DIR32:
1266 case R_PARISC_DIR17F:
1267 case R_PARISC_PCREL17C:
1268 r_field = e_fsel;
1269 goto do_basic_type_1;
1270 case R_PARISC_DIR21L:
1271 case R_PARISC_PCREL21L:
1272 r_field = e_lrsel;
1273 goto do_basic_type_1;
1274 case R_PARISC_DIR17R:
1275 case R_PARISC_PCREL17R:
1276 case R_PARISC_DIR14R:
1277 case R_PARISC_PCREL14R:
1278 r_field = e_rrsel;
1279 goto do_basic_type_1;
1280
1281 /* For all the DP relative relocations, we need to examine the symbol's
1282 section. If it's a code section, then "data pointer relative" makes
1283 no sense. In that case we don't adjust the "value", and for 21 bit
1284 addil instructions, we change the source addend register from %dp to
1285 %r0. */
1286 case R_PARISC_DPREL21L:
1287 r_field = e_lrsel;
1288 if (sym_sec->flags & SEC_CODE)
1289 insn &= ~0x03e00000;
1290 else
1291 value -= elf32_hppa_hash_table (info)->global_value;
1292 goto do_basic_type_1;
1293 case R_PARISC_DPREL14R:
1294 r_field = e_rrsel;
1295 if ((sym_sec->flags & SEC_CODE) == 0)
1296 value -= elf32_hppa_hash_table (info)->global_value;
1297 goto do_basic_type_1;
1298 case R_PARISC_DPREL14F:
1299 r_field = e_fsel;
1300 if ((sym_sec->flags & SEC_CODE) == 0)
1301 value -= elf32_hppa_hash_table (info)->global_value;
1302 goto do_basic_type_1;
1303
1304 /* These cases are separate as they may involve a lot more work
1305 to deal with linker stubs. */
1306 case R_PARISC_PLABEL32:
1307 case R_PARISC_PLABEL21L:
1308 case R_PARISC_PLABEL14R:
1309 case R_PARISC_PCREL17F:
1310 {
1311 bfd_vma location;
1312 unsigned int len, caller_args, callee_args;
1313 arg_reloc_type arg_reloc_types[5];
1314 struct elf32_hppa_args_hash_table *args_hash_table;
1315 struct elf32_hppa_args_hash_entry *args_hash;
1316 char *new_name, *stub_name;
1317
1318 /* Get the field selector right. We'll need it in a minute. */
1319 if (r_type == R_PARISC_PCREL17F
1320 || r_type == R_PARISC_PLABEL32)
1321 r_field = e_fsel;
1322 else if (r_type == R_PARISC_PLABEL21L)
1323 r_field = e_lrsel;
1324 else if (r_type == R_PARISC_PLABEL14R)
1325 r_field = e_rrsel;
1326
1327 /* Find out where we are and where we're going. */
1328 location = (offset +
1329 input_section->output_offset +
1330 input_section->output_section->vma);
1331
1332 /* Now look for the argument relocation bits associated with the
1333 target. */
1334 len = strlen (sym_name) + 1;
1335 if (is_local)
1336 len += 9;
1337 new_name = malloc (len);
1338 if (!new_name)
1339 {
1340 bfd_set_error (bfd_error_no_memory);
1341 return bfd_reloc_notsupported;
1342 }
1343 strcpy (new_name, sym_name);
1344
1345 /* Local symbols have unique IDs. */
1346 if (is_local)
1347 sprintf (new_name + len - 10, "_%08x", (int)sym_sec);
1348
1349 args_hash_table = elf32_hppa_hash_table (info)->args_hash_table;
1350
1351 args_hash = elf32_hppa_args_hash_lookup (args_hash_table,
1352 new_name, false, false);
1353 if (args_hash == NULL)
1354 callee_args = 0;
1355 else
1356 callee_args = args_hash->arg_bits;
1357
1358 /* If this is a CALL relocation, then get the caller's bits
1359 from the addend. Else use the magic 0x155 value for PLABELS.
1360
1361 Also we don't care about the destination (value) for PLABELS. */
1362 if (r_type == R_PARISC_PCREL17F)
1363 caller_args = HPPA_R_ARG_RELOC (addend);
1364 else
1365 {
1366 caller_args = 0x155;
1367 location = value;
1368 }
1369
1370 /* Any kind of linker stub needed? */
1371 if (((int)(value - location) > 0x3ffff)
1372 || ((int)(value - location) < (int)0xfffc0000)
1373 || elf32_hppa_arg_reloc_needed (caller_args, callee_args,
1374 arg_reloc_types))
1375 {
1376 struct elf32_hppa_stub_hash_table *stub_hash_table;
1377 struct elf32_hppa_stub_hash_entry *stub_hash;
1378 asection *stub_section;
1379
1380 /* Build a name for the stub. */
1381
1382 len = strlen (new_name);
1383 len += 23;
1384 stub_name = malloc (len);
1385 if (!stub_name)
1386 {
1387 bfd_set_error (bfd_error_no_memory);
1388 return bfd_reloc_notsupported;
1389 }
1390 elf32_hppa_name_of_stub (caller_args, callee_args,
1391 location, value, stub_name);
1392 strcat (stub_name, new_name);
1393 free (new_name);
1394
1395 stub_hash_table = elf32_hppa_hash_table (info)->stub_hash_table;
1396
1397 stub_hash
1398 = elf32_hppa_stub_hash_lookup (stub_hash_table, stub_name,
1399 false, false);
1400
1401 /* We're done with that name. */
1402 free (stub_name);
1403
1404 /* The stub BFD only has one section. */
1405 stub_section = stub_hash_table->stub_bfd->sections;
1406
1407 if (stub_hash != NULL)
1408 {
1409
1410 if (r_type == R_PARISC_PCREL17F)
1411 {
1412 unsigned long delay_insn;
1413 unsigned int opcode, rtn_reg, ldo_target_reg, ldo_src_reg;
1414
1415 /* We'll need to peek at the next insn. */
1416 delay_insn = bfd_get_32 (input_bfd, hit_data + 4);
1417 opcode = get_opcode (delay_insn);
1418
1419 /* We also need to know the return register for this
1420 call. */
1421 rtn_reg = (insn & 0x03e00000) >> 21;
1422
1423 ldo_src_reg = (delay_insn & 0x03e00000) >> 21;
1424 ldo_target_reg = (delay_insn & 0x001f0000) >> 16;
1425
1426 /* Munge up the value and other parameters for
1427 hppa_elf_relocate_insn. */
1428
1429 value = (stub_hash->offset
1430 + stub_section->output_offset
1431 + stub_section->output_section->vma);
1432
1433 r_format = 17;
1434 r_field = e_fsel;
1435 r_pcrel = 0;
1436 addend = 0;
1437
1438 /* We need to peek at the delay insn and determine if
1439 we'll need to swap the branch and its delay insn. */
1440 if ((insn & 2)
1441 || (opcode == LDO
1442 && ldo_target_reg == rtn_reg)
1443 || (delay_insn == 0x08000240))
1444 {
1445 /* No need to swap the branch and its delay slot, but
1446 we do need to make sure to jump past the return
1447 pointer update in the stub. */
1448 value += 4;
1449
1450 /* If the delay insn does a return pointer adjustment,
1451 then we have to make sure it stays valid. */
1452 if (opcode == LDO
1453 && ldo_target_reg == rtn_reg)
1454 {
1455 delay_insn &= 0xfc00ffff;
1456 delay_insn |= ((31 << 21) | (31 << 16));
1457 bfd_put_32 (input_bfd, delay_insn, hit_data + 4);
1458 }
1459 /* Use a BLE to reach the stub. */
1460 insn = BLE_SR4_R0;
1461 }
1462 else
1463 {
1464 /* Wonderful, we have to swap the call insn and its
1465 delay slot. */
1466 bfd_put_32 (input_bfd, delay_insn, hit_data);
1467 /* Use a BLE,n to reach the stub. */
1468 insn = (BLE_SR4_R0 | 0x2);
1469 bfd_put_32 (input_bfd, insn, hit_data + 4);
1470 insn = hppa_elf_relocate_insn (input_bfd,
1471 input_section,
1472 insn, offset + 4,
1473 value, addend,
1474 r_format, r_field,
1475 r_pcrel);
1476 /* Update the instruction word. */
1477 bfd_put_32 (input_bfd, insn, hit_data + 4);
1478 return bfd_reloc_dangerous;
1479 }
1480 }
1481 else
1482 {
1483 /* PLABEL stuff is easy. */
1484
1485 value = (stub_hash->offset
1486 + stub_section->output_offset
1487 + stub_section->output_section->vma);
1488 /* We don't need the RP adjustment for PLABELs. */
1489 value += 4;
1490 if (r_type == R_PARISC_PLABEL32)
1491 r_format = 32;
1492 else if (r_type == R_PARISC_PLABEL21L)
1493 r_format = 21;
1494 else if (r_type == R_PARISC_PLABEL14R)
1495 r_format = 14;
1496
1497 r_pcrel = 0;
1498 addend = 0;
1499 }
1500 }
1501 else
1502 return bfd_reloc_notsupported;
1503 }
1504 goto do_basic_type_1;
1505 }
1506
1507 do_basic_type_1:
1508 insn = hppa_elf_relocate_insn (input_bfd, input_section, insn,
1509 offset, value, addend, r_format,
1510 r_field, r_pcrel);
1511 break;
1512
1513 /* Something we don't know how to handle. */
1514 default:
1515 return bfd_reloc_notsupported;
1516 }
1517
1518 /* Update the instruction word. */
1519 bfd_put_32 (input_bfd, insn, hit_data);
1520 return (bfd_reloc_ok);
1521 }
1522
1523 /* Return the address of the howto table entry to perform the CODE
1524 relocation for an ARCH machine. */
1525
1526 static CONST reloc_howto_type *
1527 elf_hppa_reloc_type_lookup (abfd, code)
1528 bfd *abfd;
1529 bfd_reloc_code_real_type code;
1530 {
1531 if ((int) code < (int) R_PARISC_UNIMPLEMENTED)
1532 {
1533 BFD_ASSERT ((int) elf_hppa_howto_table[(int) code].type == (int) code);
1534 return &elf_hppa_howto_table[(int) code];
1535 }
1536 return NULL;
1537 }
1538
1539 /* Return true if SYM represents a local label symbol. */
1540
1541 static boolean
1542 hppa_elf_is_local_label (abfd, sym)
1543 bfd *abfd;
1544 asymbol *sym;
1545 {
1546 return (sym->name[0] == 'L' && sym->name[1] == '$');
1547 }
1548
1549 /* Do any backend specific processing when beginning to write an object
1550 file. For PA ELF we need to determine the size of the symbol extension
1551 section *before* any other output processing happens. */
1552
1553 static void
1554 elf32_hppa_backend_begin_write_processing (abfd, info)
1555 bfd *abfd;
1556 struct bfd_link_info *info;
1557 {
1558 unsigned int i;
1559 asection *symextn_sec;
1560
1561 /* Size up the symbol extension section. */
1562 if ((abfd->outsymbols == NULL
1563 && info == NULL)
1564 || symext_chain_size != 0)
1565 return;
1566
1567 if (info == NULL)
1568 {
1569 /* We were not called from the BFD ELF linker code, so we need
1570 to examine the output BFD's outsymbols.
1571
1572 Note we can not build the symbol extensions now as the symbol
1573 map hasn't been set up. */
1574 for (i = 0; i < abfd->symcount; i++)
1575 {
1576 elf_symbol_type *symbol = (elf_symbol_type *)abfd->outsymbols[i];
1577
1578 /* Only functions ever need an entry in the symbol extension
1579 section. */
1580 if (!(symbol->symbol.flags & BSF_FUNCTION))
1581 continue;
1582
1583 /* And only if they specify the locations of their arguments. */
1584 if (symbol->tc_data.hppa_arg_reloc == 0)
1585 continue;
1586
1587 /* Yup. This function symbol needs an entry. */
1588 symext_chain_size += 2 * sizeof (symext_entryS);
1589 }
1590 }
1591 else if (info->relocateable == true)
1592 {
1593 struct elf32_hppa_args_hash_table *table;
1594 table = elf32_hppa_hash_table (info)->args_hash_table;
1595
1596 /* Determine the size of the symbol extension section. */
1597 elf32_hppa_args_hash_traverse (table,
1598 elf32_hppa_size_symext,
1599 &symext_chain_size);
1600 }
1601
1602 /* Now create the section and set its size. We'll fill in the
1603 contents later. */
1604 symextn_sec = bfd_get_section_by_name (abfd, SYMEXTN_SECTION_NAME);
1605 if (symextn_sec == NULL)
1606 symextn_sec = bfd_make_section (abfd, SYMEXTN_SECTION_NAME);
1607
1608 bfd_set_section_flags (abfd, symextn_sec,
1609 SEC_LOAD | SEC_HAS_CONTENTS | SEC_DATA);
1610 symextn_sec->output_section = symextn_sec;
1611 symextn_sec->output_offset = 0;
1612 bfd_set_section_alignment (abfd, symextn_sec, 2);
1613 bfd_set_section_size (abfd, symextn_sec, symext_chain_size);
1614 }
1615
1616 /* Called for each entry in the args location hash table. For each
1617 entry we bump the size pointer by 2 records (16 bytes). */
1618
1619 static boolean
1620 elf32_hppa_size_symext (gen_entry, in_args)
1621 struct bfd_hash_entry *gen_entry;
1622 PTR in_args;
1623 {
1624 unsigned int *sizep = (unsigned int *)in_args;
1625
1626 *sizep += 2 * sizeof (symext_entryS);
1627 return true;
1628 }
1629
1630 /* Backend routine called by the linker for each output symbol.
1631
1632 For PA ELF we use this opportunity to add an appropriate entry
1633 to the symbol extension chain for function symbols. */
1634
1635 static boolean
1636 elf32_hppa_link_output_symbol_hook (abfd, info, name, sym, section)
1637 bfd *abfd;
1638 struct bfd_link_info *info;
1639 const char *name;
1640 Elf_Internal_Sym *sym;
1641 asection *section;
1642 {
1643 char *new_name;
1644 unsigned int len, index;
1645 struct elf32_hppa_args_hash_table *args_hash_table;
1646 struct elf32_hppa_args_hash_entry *args_hash;
1647
1648 /* If the args hash table is NULL, then we've encountered an error
1649 of some sorts (for example, an undefined symbol). In that case
1650 we've got nothing else to do.
1651
1652 NOTE: elf_link_output_symbol will abort if we return false here! */
1653 if (elf32_hppa_hash_table (info)->args_hash_table == NULL)
1654 return true;
1655
1656 index = elf32_hppa_hash_table (info)->output_symbol_count++;
1657
1658 /* We need to look up this symbol in the args hash table to see if
1659 it has argument relocation bits. */
1660 if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
1661 return true;
1662
1663 /* We know it's a function symbol of some kind. */
1664 len = strlen (name) + 1;
1665 if (ELF_ST_BIND (sym->st_info) == STB_LOCAL)
1666 len += 9;
1667
1668 new_name = malloc (len);
1669 if (new_name == NULL)
1670 {
1671 bfd_set_error (bfd_error_no_memory);
1672 return false;
1673 }
1674
1675 strcpy (new_name, name);
1676 if (ELF_ST_BIND (sym->st_info) == STB_LOCAL)
1677 sprintf (new_name + len - 10, "_%08x", (int)section);
1678
1679 /* Now that we have the unique name, we can look it up in the
1680 args hash table. */
1681 args_hash_table = elf32_hppa_hash_table (info)->args_hash_table;
1682 args_hash = elf32_hppa_args_hash_lookup (args_hash_table, new_name,
1683 false, false);
1684 free (new_name);
1685 if (args_hash == NULL)
1686 return true;
1687
1688 /* We know this symbol has arg reloc bits. */
1689 add_entry_to_symext_chain (abfd, args_hash->arg_bits,
1690 index, &symext_rootP, &symext_lastP);
1691 return true;
1692 }
1693
1694 /* Perform any processing needed late in the object file writing process.
1695 For PA ELF we build and set the contents of the symbol extension
1696 section. */
1697
1698 static void
1699 elf32_hppa_backend_final_write_processing (abfd, linker)
1700 bfd *abfd;
1701 boolean linker;
1702 {
1703 asection *symextn_sec;
1704 unsigned int i, *symtab_map = (unsigned int *) elf_sym_extra (abfd);
1705
1706 /* Now build the symbol extension section. */
1707 if (symext_chain_size == 0)
1708 return;
1709
1710 if (! linker)
1711 {
1712 /* We were not called from the backend linker, so we still need
1713 to build the symbol extension chain.
1714
1715 Look at each symbol, adding the appropriate information to the
1716 symbol extension section list as necessary. */
1717 for (i = 0; i < abfd->symcount; i++)
1718 {
1719 elf_symbol_type *symbol = (elf_symbol_type *) abfd->outsymbols[i];
1720
1721 /* Only functions ever need an entry in the symbol extension
1722 section. */
1723 if (!(symbol->symbol.flags & BSF_FUNCTION))
1724 continue;
1725
1726 /* And only if they specify the locations of their arguments. */
1727 if (symbol->tc_data.hppa_arg_reloc == 0)
1728 continue;
1729
1730 /* Add this symbol's information to the chain. */
1731 add_entry_to_symext_chain (abfd, symbol->tc_data.hppa_arg_reloc,
1732 symtab_map[i], &symext_rootP,
1733 &symext_lastP);
1734 }
1735 }
1736
1737 /* Now fill in the contents of the symbol extension section. */
1738 elf_hppa_tc_make_sections (abfd, symext_rootP);
1739
1740 /* And attach that as the section's contents. */
1741 symextn_sec = bfd_get_section_by_name (abfd, SYMEXTN_SECTION_NAME);
1742 if (symextn_sec == (asection *) 0)
1743 abort();
1744
1745 symextn_sec->contents = (void *)symextn_contents;
1746
1747 bfd_set_section_contents (abfd, symextn_sec, symextn_sec->contents,
1748 symextn_sec->output_offset, symextn_sec->_raw_size);
1749 }
1750
1751 /* Update the symbol extention chain to include the symbol pointed to
1752 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
1753
1754 static void
1755 add_entry_to_symext_chain (abfd, arg_reloc, sym_idx, symext_root, symext_last)
1756 bfd *abfd;
1757 unsigned int arg_reloc;
1758 unsigned int sym_idx;
1759 symext_chainS **symext_root;
1760 symext_chainS **symext_last;
1761 {
1762 symext_chainS *symextP;
1763
1764 /* Allocate memory and initialize this entry. */
1765 symextP = (symext_chainS *) bfd_alloc (abfd, sizeof (symext_chainS) * 2);
1766 if (!symextP)
1767 {
1768 bfd_set_error (bfd_error_no_memory);
1769 abort(); /* FIXME */
1770 }
1771
1772 symextP[0].entry = ELF32_PARISC_SX_WORD (PARISC_SXT_SYMNDX, sym_idx);
1773 symextP[0].next = &symextP[1];
1774
1775 symextP[1].entry = ELF32_PARISC_SX_WORD (PARISC_SXT_ARG_RELOC, arg_reloc);
1776 symextP[1].next = NULL;
1777
1778 /* Now update the chain itself so it can be walked later to build
1779 the symbol extension section. */
1780 if (*symext_root == NULL)
1781 {
1782 *symext_root = &symextP[0];
1783 *symext_last = &symextP[1];
1784 }
1785 else
1786 {
1787 (*symext_last)->next = &symextP[0];
1788 *symext_last = &symextP[1];
1789 }
1790 }
1791
1792 /* Build the symbol extension section. */
1793
1794 static void
1795 elf_hppa_tc_make_sections (abfd, symext_root)
1796 bfd *abfd;
1797 symext_chainS *symext_root;
1798 {
1799 symext_chainS *symextP;
1800 unsigned int i;
1801 asection *symextn_sec;
1802
1803 symextn_sec = bfd_get_section_by_name (abfd, SYMEXTN_SECTION_NAME);
1804
1805 /* Grab some memory for the contents of the symbol extension section
1806 itself. */
1807 symextn_contents = (symext_entryS *) bfd_zalloc (abfd,
1808 symextn_sec->_raw_size);
1809 if (!symextn_contents)
1810 {
1811 bfd_set_error (bfd_error_no_memory);
1812 abort(); /* FIXME */
1813 }
1814
1815 /* Fill in the contents of the symbol extension chain. */
1816 for (i = 0, symextP = symext_root; symextP; symextP = symextP->next, ++i)
1817 symextn_contents[i] = symextP->entry;
1818
1819 return;
1820 }
1821
1822 /* Do some PA ELF specific work after reading in the symbol table.
1823 In particular attach the argument relocation from the
1824 symbol extension section to the appropriate symbols. */
1825
1826 static boolean
1827 elf32_hppa_backend_symbol_table_processing (abfd, esyms,symcnt)
1828 bfd *abfd;
1829 elf_symbol_type *esyms;
1830 int symcnt;
1831 {
1832 Elf32_Internal_Shdr *symextn_hdr =
1833 bfd_elf_find_section (abfd, SYMEXTN_SECTION_NAME);
1834 unsigned int i, current_sym_idx = 0;
1835
1836 /* If no symbol extension existed, then all symbol extension information
1837 is assumed to be zero. */
1838 if (symextn_hdr == NULL)
1839 {
1840 for (i = 0; i < symcnt; i++)
1841 esyms[i].tc_data.hppa_arg_reloc = 0;
1842 return (true);
1843 }
1844
1845 /* FIXME: Why not use bfd_get_section_contents here? Also should give
1846 memory back when we're done. */
1847 /* Allocate a buffer of the appropriate size for the symextn section. */
1848 symextn_hdr->contents = bfd_zalloc(abfd,symextn_hdr->sh_size);
1849 if (!symextn_hdr->contents)
1850 {
1851 bfd_set_error (bfd_error_no_memory);
1852 return false;
1853 }
1854 symextn_hdr->size = symextn_hdr->sh_size;
1855
1856 /* Read in the symextn section. */
1857 if (bfd_seek (abfd, symextn_hdr->sh_offset, SEEK_SET) == -1)
1858 return false;
1859 if (bfd_read ((PTR) symextn_hdr->contents, 1, symextn_hdr->size, abfd)
1860 != symextn_hdr->size)
1861 return false;
1862
1863 /* Parse entries in the symbol extension section, updating the symtab
1864 entries as we go */
1865 for (i = 0; i < symextn_hdr->size / sizeof(symext_entryS); i++)
1866 {
1867 symext_entryS *seP = ((symext_entryS *)symextn_hdr->contents) + i;
1868 unsigned int se_value = ELF32_PARISC_SX_VAL (*seP);
1869 unsigned int se_type = ELF32_PARISC_SX_TYPE (*seP);
1870
1871 switch (se_type)
1872 {
1873 case PARISC_SXT_NULL:
1874 break;
1875
1876 case PARISC_SXT_SYMNDX:
1877 if (se_value >= symcnt)
1878 {
1879 bfd_set_error (bfd_error_bad_value);
1880 return (false);
1881 }
1882 current_sym_idx = se_value - 1;
1883 break;
1884
1885 case PARISC_SXT_ARG_RELOC:
1886 esyms[current_sym_idx].tc_data.hppa_arg_reloc = se_value;
1887 break;
1888
1889 default:
1890 bfd_set_error (bfd_error_bad_value);
1891 return (false);
1892 }
1893 }
1894 return (true);
1895 }
1896
1897 /* Read and attach the symbol extension information for the symbols
1898 in INPUT_BFD to the argument location hash table. Handle locals
1899 if DO_LOCALS is true; likewise for globals when DO_GLOBALS is true. */
1900
1901 static boolean
1902 elf32_hppa_read_symext_info (input_bfd, symtab_hdr, args_hash_table,
1903 local_syms, do_locals, do_globals)
1904 bfd *input_bfd;
1905 Elf_Internal_Shdr *symtab_hdr;
1906 struct elf32_hppa_args_hash_table *args_hash_table;
1907 Elf_Internal_Sym *local_syms;
1908 boolean do_locals;
1909 boolean do_globals;
1910 {
1911 asection *symextn_sec;
1912 symextn_entry *contents;
1913 unsigned int i, n_entries, current_index = 0;
1914
1915 /* Get the symbol extension section for this BFD. If no section exists
1916 then there's nothing to do. Likewise if the section exists, but
1917 has no contents. */
1918 symextn_sec = bfd_get_section_by_name (input_bfd, SYMEXTN_SECTION_NAME);
1919 if (symextn_sec == NULL)
1920 return true;
1921
1922 /* Done separately so we can turn off SEC_HAS_CONTENTS (see below). */
1923 if (symextn_sec->_raw_size == 0)
1924 {
1925 symextn_sec->flags &= ~SEC_HAS_CONTENTS;
1926 return true;
1927 }
1928
1929 contents = (symextn_entry *) malloc (symextn_sec->_raw_size);
1930 if (contents == NULL)
1931 {
1932 bfd_set_error (bfd_error_no_memory);
1933 return false;
1934 }
1935
1936 /* How gross. We turn off SEC_HAS_CONTENTS for the input symbol extension
1937 sections to keep the generic ELF/BFD code from trying to do anything
1938 with them. We have to undo that hack temporarily so that we can read
1939 in the contents with the generic code. */
1940 symextn_sec->flags |= SEC_HAS_CONTENTS;
1941 if (bfd_get_section_contents (input_bfd, symextn_sec, contents,
1942 0, symextn_sec->_raw_size) == false)
1943 {
1944 symextn_sec->flags &= ~SEC_HAS_CONTENTS;
1945 free (contents);
1946 return false;
1947 }
1948
1949 /* Gross. Turn off SEC_HAS_CONTENTS for the input symbol extension
1950 sections (see above). */
1951 symextn_sec->flags &= ~SEC_HAS_CONTENTS;
1952
1953 n_entries = symextn_sec->_raw_size / sizeof (symextn_entry);
1954 for (i = 0; i < n_entries; i++)
1955 {
1956 symextn_entry entry = contents[i];
1957 unsigned int value = ELF32_PARISC_SX_VAL (entry);
1958 unsigned int type = ELF32_PARISC_SX_TYPE (entry);
1959 struct elf32_hppa_args_hash_entry *args_hash;
1960
1961 switch (type)
1962 {
1963 case PARISC_SXT_NULL:
1964 break;
1965
1966 case PARISC_SXT_SYMNDX:
1967 if (value >= symtab_hdr->sh_size / sizeof (Elf32_External_Sym))
1968 {
1969 bfd_set_error (bfd_error_bad_value);
1970 free (contents);
1971 return false;
1972 }
1973 current_index = value;
1974 break;
1975
1976 case PARISC_SXT_ARG_RELOC:
1977 if (current_index < symtab_hdr->sh_info
1978 && do_locals)
1979 {
1980 Elf_Internal_Shdr *hdr;
1981 char *new_name;
1982 const char *sym_name;
1983 asection *sym_sec;
1984 unsigned int len;
1985
1986 hdr = elf_elfsections (input_bfd)[local_syms[current_index].st_shndx];
1987 sym_sec = hdr->bfd_section;
1988 sym_name = elf_string_from_elf_section (input_bfd,
1989 symtab_hdr->sh_link,
1990 local_syms[current_index].st_name);
1991 len = strlen (sym_name) + 10;
1992 new_name = malloc (len);
1993 if (new_name == NULL)
1994 {
1995 bfd_set_error (bfd_error_no_memory);
1996 free (contents);
1997 return false;
1998 }
1999 strcpy (new_name, sym_name);
2000 sprintf (new_name + len - 10, "_%08x", (int)sym_sec);
2001
2002 /* This is a global symbol with argument location info.
2003 We need to enter it into the hash table. */
2004 args_hash = elf32_hppa_args_hash_lookup (args_hash_table,
2005 new_name, true,
2006 true);
2007 free (new_name);
2008 if (args_hash == NULL)
2009 {
2010 free (contents);
2011 return false;
2012 }
2013 args_hash->arg_bits = value;
2014 break;
2015 }
2016 else if (current_index >= symtab_hdr->sh_info
2017 && do_globals)
2018 {
2019 struct elf_link_hash_entry *h;
2020
2021 current_index -= symtab_hdr->sh_info;
2022 h = elf_sym_hashes(input_bfd)[current_index];
2023 /* This is a global symbol with argument location
2024 information. We need to enter it into the hash table. */
2025 args_hash = elf32_hppa_args_hash_lookup (args_hash_table,
2026 h->root.root.string,
2027 true, true);
2028 if (args_hash == NULL)
2029 {
2030 bfd_set_error (bfd_error_bad_value);
2031 free (contents);
2032 return false;
2033 }
2034 args_hash->arg_bits = value;
2035 break;
2036 }
2037 else
2038 break;
2039
2040 default:
2041 bfd_set_error (bfd_error_bad_value);
2042 free (contents);
2043 return false;
2044 }
2045 }
2046 free (contents);
2047 return true;
2048 }
2049
2050 /* Undo the generic ELF code's subtraction of section->vma from the
2051 value of each external symbol. */
2052
2053 static boolean
2054 elf32_hppa_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2055 bfd *abfd;
2056 struct bfd_link_info *info;
2057 const Elf_Internal_Sym *sym;
2058 const char **namep;
2059 flagword *flagsp;
2060 asection **secp;
2061 bfd_vma *valp;
2062 {
2063 *valp += (*secp)->vma;
2064 return true;
2065 }
2066
2067 /* Determine the name of the stub needed to perform a call assuming the
2068 argument relocation bits for caller and callee are in CALLER and CALLEE
2069 for a call from LOCATION to DESTINATION. Copy the name into STUB_NAME. */
2070
2071 static void
2072 elf32_hppa_name_of_stub (caller, callee, location, destination, stub_name)
2073 unsigned int caller, callee;
2074 bfd_vma location, destination;
2075 char *stub_name;
2076 {
2077 arg_reloc_type arg_reloc_types[5];
2078
2079 if (elf32_hppa_arg_reloc_needed (caller, callee, arg_reloc_types))
2080 {
2081 arg_reloc_location i;
2082 /* Fill in the basic template. */
2083 strcpy (stub_name, "__XX_XX_XX_XX_XX_stub_");
2084
2085 /* Now fix the specifics. */
2086 for (i = ARG0; i <= RET; i++)
2087 switch (arg_reloc_types[i])
2088 {
2089 case NO:
2090 stub_name[3 * i + 2] = 'N';
2091 stub_name[3 * i + 3] = 'O';
2092 break;
2093 case GF:
2094 stub_name[3 * i + 2] = 'G';
2095 stub_name[3 * i + 3] = 'F';
2096 break;
2097 case FG:
2098 stub_name[3 * i + 2] = 'F';
2099 stub_name[3 * i + 3] = 'G';
2100 break;
2101 case GD:
2102 stub_name[3 * i + 2] = 'G';
2103 stub_name[3 * i + 3] = 'D';
2104 break;
2105 case DG:
2106 stub_name[3 * i + 2] = 'D';
2107 stub_name[3 * i + 3] = 'G';
2108 break;
2109 }
2110 }
2111 else
2112 strcpy (stub_name, "_____long_branch_stub_");
2113 }
2114
2115 /* Determine if an argument relocation stub is needed to perform a
2116 call assuming the argument relocation bits for caller and callee
2117 are in CALLER and CALLEE. Place the type of relocations (if any)
2118 into stub_types_p. */
2119
2120 static boolean
2121 elf32_hppa_arg_reloc_needed (caller, callee, stub_types)
2122 unsigned int caller, callee;
2123 arg_reloc_type stub_types[5];
2124 {
2125 /* Special case for no relocations. */
2126 if (caller == 0 || callee == 0)
2127 return 0;
2128 else
2129 {
2130 arg_location caller_loc[5];
2131 arg_location callee_loc[5];
2132
2133 /* Extract the location information for the argument and return
2134 value on both the caller and callee sides. */
2135 caller_loc[ARG0] = EXTRACT_ARBITS (caller, ARG0);
2136 callee_loc[ARG0] = EXTRACT_ARBITS (callee, ARG0);
2137 caller_loc[ARG1] = EXTRACT_ARBITS (caller, ARG1);
2138 callee_loc[ARG1] = EXTRACT_ARBITS (callee, ARG1);
2139 caller_loc[ARG2] = EXTRACT_ARBITS (caller, ARG2);
2140 callee_loc[ARG2] = EXTRACT_ARBITS (callee, ARG2);
2141 caller_loc[ARG3] = EXTRACT_ARBITS (caller, ARG3);
2142 callee_loc[ARG3] = EXTRACT_ARBITS (callee, ARG3);
2143 caller_loc[RET] = EXTRACT_ARBITS (caller, RET);
2144 callee_loc[RET] = EXTRACT_ARBITS (callee, RET);
2145
2146 /* Check some special combinations. This is necessary to
2147 deal with double precision FP arguments. */
2148 if (caller_loc[ARG0] == AR_FU || caller_loc[ARG1] == AR_FU)
2149 {
2150 caller_loc[ARG0] = AR_FPDBL1;
2151 caller_loc[ARG1] = AR_NO;
2152 }
2153 if (caller_loc[ARG2] == AR_FU || caller_loc[ARG3] == AR_FU)
2154 {
2155 caller_loc[ARG2] = AR_FPDBL2;
2156 caller_loc[ARG3] = AR_NO;
2157 }
2158 if (callee_loc[ARG0] == AR_FU || callee_loc[ARG1] == AR_FU)
2159 {
2160 callee_loc[ARG0] = AR_FPDBL1;
2161 callee_loc[ARG1] = AR_NO;
2162 }
2163 if (callee_loc[ARG2] == AR_FU || callee_loc[ARG3] == AR_FU)
2164 {
2165 callee_loc[ARG2] = AR_FPDBL2;
2166 callee_loc[ARG3] = AR_NO;
2167 }
2168
2169 /* Now look up any relocation needed for each argument and the
2170 return value. */
2171 stub_types[ARG0] = arg_mismatches[caller_loc[ARG0]][callee_loc[ARG0]];
2172 stub_types[ARG1] = arg_mismatches[caller_loc[ARG1]][callee_loc[ARG1]];
2173 stub_types[ARG2] = arg_mismatches[caller_loc[ARG2]][callee_loc[ARG2]];
2174 stub_types[ARG3] = arg_mismatches[caller_loc[ARG3]][callee_loc[ARG3]];
2175 stub_types[RET] = ret_mismatches[caller_loc[RET]][callee_loc[RET]];
2176
2177 return (stub_types[ARG0] != NO
2178 || stub_types[ARG1] != NO
2179 || stub_types[ARG2] != NO
2180 || stub_types[ARG3] != NO
2181 || stub_types[RET] != NO);
2182 }
2183 }
2184
2185 /* Compute the size of the stub needed to call from LOCATION to DESTINATION
2186 (a function named SYM_NAME), with argument relocation bits CALLER and
2187 CALLEE. Return zero if no stub is needed to perform such a call. */
2188
2189 static unsigned int
2190 elf32_hppa_size_of_stub (callee, caller, location, destination, sym_name)
2191 unsigned int callee, caller;
2192 bfd_vma location, destination;
2193 const char *sym_name;
2194 {
2195 arg_reloc_type arg_reloc_types[5];
2196
2197 /* Determine if a long branch or argument relocation stub is needed.
2198 If an argument relocation stub is needed, the relocation will be
2199 stored into arg_reloc_types. */
2200 if (!(((int)(location - destination) > 0x3ffff)
2201 || ((int)(location - destination) < (int)0xfffc0000)
2202 || elf32_hppa_arg_reloc_needed (caller, callee, arg_reloc_types)))
2203 return 0;
2204
2205 /* Some kind of stub is needed. Determine how big it needs to be.
2206 First check for argument relocation stubs as they also handle
2207 long calls. Then check for long calls to millicode and finally
2208 the normal long calls. */
2209 if (arg_reloc_types[ARG0] != NO
2210 || arg_reloc_types[ARG1] != NO
2211 || arg_reloc_types[ARG2] != NO
2212 || arg_reloc_types[ARG3] != NO
2213 || arg_reloc_types[RET] != NO)
2214 {
2215 /* Some kind of argument relocation stub is needed. */
2216 unsigned int len = 16;
2217 arg_reloc_location i;
2218
2219 /* Each GR or FG relocation takes 2 insns, each GD or DG
2220 relocation takes 3 insns. Plus 4 more insns for the
2221 RP adjustment, ldil & (be | ble) and copy. */
2222 for (i = ARG0; i <= RET; i++)
2223 switch (arg_reloc_types[i])
2224 {
2225 case GF:
2226 case FG:
2227 len += 8;
2228 break;
2229
2230 case GD:
2231 case DG:
2232 len += 12;
2233 break;
2234
2235 default:
2236 break;
2237 }
2238
2239 /* Extra instructions are needed if we're relocating a return value. */
2240 if (arg_reloc_types[RET] != NO)
2241 len += 12;
2242
2243 return len;
2244 }
2245 else if (!strncmp ("$$", sym_name, 2)
2246 && strcmp ("$$dyncall", sym_name))
2247 return 12;
2248 else
2249 return 16;
2250 }
2251
2252 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
2253 IN_ARGS contains the stub BFD and link info pointers. */
2254
2255 static boolean
2256 elf32_hppa_build_one_stub (gen_entry, in_args)
2257 struct bfd_hash_entry *gen_entry;
2258 PTR in_args;
2259 {
2260 void **args = (void **)in_args;
2261 bfd *stub_bfd = (bfd *)args[0];
2262 struct bfd_link_info *info = (struct bfd_link_info *)args[1];
2263 struct elf32_hppa_stub_hash_entry *entry;
2264 struct elf32_hppa_stub_hash_table *stub_hash_table;
2265 bfd_byte *loc;
2266 symvalue sym_value;
2267 const char *sym_name;
2268
2269 /* Initialize pointers to the stub hash table, the particular entry we
2270 are building a stub for, and where (in memory) we should place the stub
2271 instructions. */
2272 entry = (struct elf32_hppa_stub_hash_entry *)gen_entry;
2273 stub_hash_table = elf32_hppa_hash_table(info)->stub_hash_table;
2274 loc = stub_hash_table->location;
2275
2276 /* Make a note of the offset within the stubs for this entry. */
2277 entry->offset = stub_hash_table->offset;
2278
2279 /* The symbol's name starts at offset 22. */
2280 sym_name = entry->root.string + 22;
2281
2282 sym_value = (entry->target_value
2283 + entry->target_section->output_offset
2284 + entry->target_section->output_section->vma);
2285
2286 if (strncmp ("_____long_branch_stub_", entry->root.string, 22))
2287 {
2288 /* This must be an argument or return value relocation stub. */
2289 unsigned long insn;
2290 arg_reloc_location i;
2291 bfd_byte *begin_loc = loc;
2292
2293 /* First the return pointer adjustment. Depending on exact calling
2294 sequence this instruction may be skipped. */
2295 bfd_put_32 (stub_bfd, LDO_M4_R31_R31, loc);
2296 loc += 4;
2297
2298 /* If we are relocating a return value, then we're going to have
2299 to return into the stub. So we have to save off the user's
2300 return pointer into the stack at RP'. */
2301 if (strncmp (entry->root.string + 14, "NO", 2))
2302 {
2303 bfd_put_32 (stub_bfd, STW_R31_M8R30, loc);
2304 loc += 4;
2305 }
2306
2307 /* Iterate over the argument relocations, emitting instructions
2308 to move them around as necessary. */
2309 for (i = ARG0; i <= ARG3; i++)
2310 {
2311 if (!strncmp (entry->root.string + 3 * i + 2, "GF", 2))
2312 {
2313 bfd_put_32 (stub_bfd, STW_ARG_M16R30 | ((26 - i) << 16), loc);
2314 bfd_put_32 (stub_bfd, FLDW_M16R30_FARG | (4 + i), loc + 4);
2315 loc += 8;
2316 }
2317 else if (!strncmp (entry->root.string + 3 * i + 2, "FG", 2))
2318 {
2319 bfd_put_32 (stub_bfd, FSTW_FARG_M16R30 | (4 + i), loc);
2320 bfd_put_32 (stub_bfd, LDW_M16R30_ARG | ((26 - i) << 16), loc + 4);
2321 loc += 8;
2322 }
2323 else if (!strncmp (entry->root.string + 3 * i + 2, "GD", 2))
2324 {
2325 bfd_put_32 (stub_bfd, STW_ARG_M12R30 | ((26 - i) << 16), loc);
2326 bfd_put_32 (stub_bfd, STW_ARG_M16R30 | ((25 - i) << 16), loc + 4);
2327 bfd_put_32 (stub_bfd, FLDD_M16R30_FARG | (5 + i), loc + 8);
2328 loc += 12;
2329 }
2330 else if (!strncmp (entry->root.string + 3 * i + 2, "DG", 2))
2331 {
2332 bfd_put_32 (stub_bfd, FSTD_FARG_M16R30 | (5 + i), loc);
2333 bfd_put_32 (stub_bfd, LDW_M12R30_ARG | ((26 - i) << 16), loc + 4);
2334 bfd_put_32 (stub_bfd, LDW_M16R30_ARG | ((25 - i) << 16), loc + 8);
2335 loc += 12;
2336 }
2337 }
2338
2339 /* Load the high bits of the target address into %r1. */
2340 insn = hppa_rebuild_insn (stub_bfd, LDIL_R1,
2341 hppa_field_adjust (sym_value, 0, e_lrsel), 21);
2342 bfd_put_32 (stub_bfd, insn, loc);
2343 loc += 4;
2344
2345 /* If we are relocating a return value, then we're going to have
2346 to return into the stub, then perform the return value relocation. */
2347 if (strncmp (entry->root.string + 14, "NO", 2))
2348 {
2349 /* To return to the stub we "ble" to the target and copy the return
2350 pointer from %r31 into %r2. */
2351 insn = hppa_rebuild_insn (stub_bfd,
2352 BLE_SR4_R1,
2353 hppa_field_adjust (sym_value, 0,
2354 e_rrsel) >> 2,
2355 17);
2356 bfd_put_32 (stub_bfd, insn, loc);
2357 bfd_put_32 (stub_bfd, COPY_R31_R2, loc + 4);
2358
2359 /* Reload the return pointer for our caller from the stack. */
2360 bfd_put_32 (stub_bfd, LDW_M8R30_R31, loc + 8);
2361 loc += 12;
2362
2363 /* Perform the return value relocation. */
2364 if (!strncmp (entry->root.string + 14, "GF", 2))
2365 {
2366 bfd_put_32 (stub_bfd, STW_ARG_M16R30 | (28 << 16), loc);
2367 bfd_put_32 (stub_bfd, FLDW_M16R30_FARG | 4, loc + 4);
2368 loc += 8;
2369 }
2370 else if (!strncmp (entry->root.string + 14, "FG", 2))
2371 {
2372 bfd_put_32 (stub_bfd, FSTW_FARG_M16R30 | 4, loc);
2373 bfd_put_32 (stub_bfd, LDW_M16R30_ARG | (28 << 16), loc + 4);
2374 loc += 8;
2375 }
2376 else if (!strncmp (entry->root.string + 2, "GD", 2))
2377 {
2378 bfd_put_32 (stub_bfd, STW_ARG_M12R30 | (28 << 16), loc);
2379 bfd_put_32 (stub_bfd, STW_ARG_M16R30 | (29 << 16), loc + 4);
2380 bfd_put_32 (stub_bfd, FLDD_M16R30_FARG | 4, loc + 8);
2381 loc += 12;
2382 }
2383 else if (!strncmp (entry->root.string + 2, "DG", 2))
2384 {
2385 bfd_put_32 (stub_bfd, FSTD_FARG_M16R30 | 4, loc);
2386 bfd_put_32 (stub_bfd, LDW_M12R30_ARG | (28 << 16), loc + 4);
2387 bfd_put_32 (stub_bfd, LDW_M16R30_ARG | (29 << 16), loc + 8);
2388 loc += 12;
2389 }
2390 /* Branch back to the user's code now. */
2391 bfd_put_32 (stub_bfd, BV_N_0_R31, loc);
2392 loc += 4;
2393 }
2394 else
2395 {
2396 /* No return value relocation, so we can simply "be" to the
2397 target and copy out return pointer into %r2. */
2398 insn = hppa_rebuild_insn (stub_bfd, BE_SR4_R1,
2399 hppa_field_adjust (sym_value, 0,
2400 e_rrsel) >> 2, 17);
2401 bfd_put_32 (stub_bfd, insn, loc);
2402 bfd_put_32 (stub_bfd, COPY_R31_R2, loc + 4);
2403 loc += 8;
2404 }
2405
2406 /* Update the location and offsets. */
2407 stub_hash_table->location += (loc - begin_loc);
2408 stub_hash_table->offset += (loc - begin_loc);
2409 }
2410 else
2411 {
2412 /* Create one of two variant long branch stubs. One for $$dyncall and
2413 normal calls, the other for calls to millicode. */
2414 unsigned long insn;
2415 int millicode_call = 0;
2416
2417 if (!strncmp ("$$", sym_name, 2) && strcmp ("$$dyncall", sym_name))
2418 millicode_call = 1;
2419
2420 /* First the return pointer adjustment. Depending on exact calling
2421 sequence this instruction may be skipped. */
2422 bfd_put_32 (stub_bfd, LDO_M4_R31_R31, loc);
2423
2424 /* The next two instructions are the long branch itself. A long branch
2425 is formed with "ldil" loading the upper bits of the target address
2426 into a register, then branching with "be" which adds in the lower bits.
2427 Long branches to millicode nullify the delay slot of the "be". */
2428 insn = hppa_rebuild_insn (stub_bfd, LDIL_R1,
2429 hppa_field_adjust (sym_value, 0, e_lrsel), 21);
2430 bfd_put_32 (stub_bfd, insn, loc + 4);
2431 insn = hppa_rebuild_insn (stub_bfd, BE_SR4_R1 | (millicode_call ? 2 : 0),
2432 hppa_field_adjust (sym_value, 0, e_rrsel) >> 2,
2433 17);
2434 bfd_put_32 (stub_bfd, insn, loc + 8);
2435
2436 if (!millicode_call)
2437 {
2438 /* The sequence to call this stub places the return pointer into %r31,
2439 the final target expects the return pointer in %r2, so copy the
2440 return pointer into the proper register. */
2441 bfd_put_32 (stub_bfd, COPY_R31_R2, loc + 12);
2442
2443 /* Update the location and offsets. */
2444 stub_hash_table->location += 16;
2445 stub_hash_table->offset += 16;
2446 }
2447 else
2448 {
2449 /* Update the location and offsets. */
2450 stub_hash_table->location += 12;
2451 stub_hash_table->offset += 12;
2452 }
2453
2454 }
2455 return true;
2456 }
2457
2458 /* External entry points for sizing and building linker stubs. */
2459
2460 /* Build all the stubs associated with the current output file. The
2461 stubs are kept in a hash table attached to the main linker hash
2462 table. This is called via hppaelf_finish in the linker. */
2463
2464 boolean
2465 elf32_hppa_build_stubs (stub_bfd, info)
2466 bfd *stub_bfd;
2467 struct bfd_link_info *info;
2468 {
2469 /* The stub BFD only has one section. */
2470 asection *stub_sec = stub_bfd->sections;
2471 struct elf32_hppa_stub_hash_table *table;
2472 unsigned int size;
2473 void *args[2];
2474
2475 /* So we can pass both the BFD for the stubs and the link info
2476 structure to the routine which actually builds stubs. */
2477 args[0] = stub_bfd;
2478 args[1] = info;
2479
2480 /* Allocate memory to hold the linker stubs. */
2481 size = bfd_section_size (stub_bfd, stub_sec);
2482 stub_sec->contents = (unsigned char *) bfd_zalloc (stub_bfd, size);
2483 if (stub_sec->contents == NULL)
2484 {
2485 bfd_set_error (bfd_error_no_memory);
2486 return false;
2487 }
2488 table = elf32_hppa_hash_table(info)->stub_hash_table;
2489 table->location = stub_sec->contents;
2490
2491 /* Build the stubs as directed by the stub hash table. */
2492 elf32_hppa_stub_hash_traverse (table, elf32_hppa_build_one_stub, args);
2493
2494 return true;
2495 }
2496
2497 /* Determine and set the size of the stub section for a final link.
2498
2499 The basic idea here is to examine all the relocations looking for
2500 PC-relative calls to a target that is unreachable with a "bl"
2501 instruction or calls where the caller and callee disagree on the
2502 location of their arguments or return value. */
2503
2504 boolean
2505 elf32_hppa_size_stubs (stub_bfd, output_bfd, link_info)
2506 bfd *stub_bfd;
2507 bfd *output_bfd;
2508 struct bfd_link_info *link_info;
2509 {
2510 bfd *input_bfd;
2511 asection *section, *stub_sec;
2512 Elf_Internal_Shdr *symtab_hdr;
2513 Elf_Internal_Sym *local_syms, *isym;
2514 Elf32_External_Sym *ext_syms, *esym;
2515 struct elf32_hppa_stub_hash_table *stub_hash_table = 0;
2516 struct elf32_hppa_args_hash_table *args_hash_table = 0;
2517
2518 /* Create and initialize the stub hash table. */
2519 stub_hash_table = ((struct elf32_hppa_stub_hash_table *)
2520 malloc (sizeof (struct elf32_hppa_stub_hash_table)));
2521 if (!stub_hash_table)
2522 {
2523 bfd_set_error (bfd_error_no_memory);
2524 goto error_return;
2525 }
2526
2527 if (!elf32_hppa_stub_hash_table_init (stub_hash_table, stub_bfd,
2528 elf32_hppa_stub_hash_newfunc))
2529 goto error_return;
2530
2531 /* Likewise for the argument location hash table. */
2532 args_hash_table = ((struct elf32_hppa_args_hash_table *)
2533 malloc (sizeof (struct elf32_hppa_args_hash_table)));
2534 if (!args_hash_table)
2535 {
2536 bfd_set_error (bfd_error_no_memory);
2537 goto error_return;
2538 }
2539
2540 if (!elf32_hppa_args_hash_table_init (args_hash_table,
2541 elf32_hppa_args_hash_newfunc))
2542 goto error_return;
2543
2544 /* Attach the hash tables to the main hash table. */
2545 elf32_hppa_hash_table(link_info)->stub_hash_table = stub_hash_table;
2546 elf32_hppa_hash_table(link_info)->args_hash_table = args_hash_table;
2547
2548 /* Walk over all the input BFDs adding entries to the args hash table
2549 for all the external functions. */
2550 for (input_bfd = link_info->input_bfds;
2551 input_bfd != NULL;
2552 input_bfd = input_bfd->link_next)
2553 {
2554 /* We'll need the symbol table in a second. */
2555 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2556 if (symtab_hdr->sh_info == 0)
2557 continue;
2558
2559 if (elf32_hppa_read_symext_info (input_bfd, symtab_hdr, args_hash_table,
2560 NULL, false, true) == false)
2561 goto error_return;
2562 }
2563
2564 /* Magic as we know the stub bfd only has one section. */
2565 stub_sec = stub_bfd->sections;
2566
2567 /* Now that we have argument location information for all the global
2568 functions we can start looking for stubs. */
2569 for (input_bfd = link_info->input_bfds;
2570 input_bfd != NULL;
2571 input_bfd = input_bfd->link_next)
2572 {
2573 unsigned int i;
2574
2575 /* We'll need the symbol table in a second. */
2576 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2577 if (symtab_hdr->sh_info == 0)
2578 continue;
2579
2580 /* We need an array of the local symbols attached to the input bfd.
2581 Unfortunately, we're going to have to read & swap them in. */
2582 local_syms
2583 = (Elf_Internal_Sym *)malloc (symtab_hdr->sh_info
2584 * sizeof (Elf_Internal_Sym));
2585 if (local_syms == NULL)
2586 {
2587 bfd_set_error (bfd_error_no_memory);
2588 goto error_return;
2589 }
2590
2591 ext_syms
2592 = (Elf32_External_Sym *)malloc (symtab_hdr->sh_info
2593 * sizeof (Elf32_External_Sym));
2594 if (ext_syms == NULL)
2595 {
2596 bfd_set_error (bfd_error_no_memory);
2597 free (local_syms);
2598 goto error_return;
2599 }
2600
2601 if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
2602 || bfd_read (ext_syms, 1,
2603 (symtab_hdr->sh_info
2604 * sizeof (Elf32_External_Sym)), input_bfd)
2605 != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)))
2606 {
2607 free (local_syms);
2608 free (ext_syms);
2609 goto error_return;
2610 }
2611
2612 /* Swap the local symbols in. */
2613 isym = local_syms;
2614 esym = ext_syms;
2615 for (i = 0; i < symtab_hdr->sh_info; i++, esym++, isym++)
2616 bfd_elf32_swap_symbol_in (input_bfd, esym, isym);
2617
2618 /* Now we can free the external symbols. */
2619 free (ext_syms);
2620
2621 if (elf32_hppa_read_symext_info (input_bfd, symtab_hdr, args_hash_table,
2622 local_syms, true, false) == false)
2623 {
2624 free (local_syms);
2625 goto error_return;
2626 }
2627
2628 /* If generating a relocateable output file, then we don't
2629 have to examine the relocs. */
2630 if (link_info->relocateable)
2631 {
2632 free (local_syms);
2633 return true;
2634 }
2635
2636 /* Walk over each section attached to the input bfd. */
2637 for (section = input_bfd->sections;
2638 section != NULL;
2639 section = section->next)
2640 {
2641 Elf_Internal_Shdr *input_rel_hdr;
2642 Elf32_External_Rela *external_relocs, *erelaend, *erela;
2643 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
2644
2645 /* If there aren't any relocs, then there's nothing to do. */
2646 if ((section->flags & SEC_RELOC) == 0
2647 || section->reloc_count == 0)
2648 continue;
2649
2650 /* Allocate space for the external relocations. */
2651 external_relocs
2652 = (Elf32_External_Rela *) malloc (section->reloc_count * sizeof (Elf32_External_Rela));
2653 if (external_relocs == NULL)
2654 {
2655 bfd_set_error (bfd_error_no_memory);
2656 free (local_syms);
2657 goto error_return;
2658 }
2659
2660 /* Likewise for the internal relocations. */
2661 internal_relocs
2662 = (Elf_Internal_Rela *) malloc (section->reloc_count * sizeof (Elf_Internal_Rela));
2663 if (internal_relocs == NULL)
2664 {
2665 bfd_set_error (bfd_error_no_memory);
2666 free (external_relocs);
2667 free (local_syms);
2668 goto error_return;
2669 }
2670
2671 /* Read in the external relocs. */
2672 input_rel_hdr = &elf_section_data (section)->rel_hdr;
2673 if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0
2674 || bfd_read (external_relocs, 1, input_rel_hdr->sh_size,
2675 input_bfd) != input_rel_hdr->sh_size)
2676 {
2677 free (external_relocs);
2678 free (internal_relocs);
2679 free (local_syms);
2680 goto error_return;
2681 }
2682
2683 /* Swap in the relocs. */
2684 erela = external_relocs;
2685 erelaend = erela + section->reloc_count;
2686 irela = internal_relocs;
2687 for (; erela < erelaend; erela++, irela++)
2688 bfd_elf32_swap_reloca_in (input_bfd, erela, irela);
2689
2690 /* We're done with the external relocs, free them. */
2691 free (external_relocs);
2692
2693 /* Now examine each relocation. */
2694 irela = internal_relocs;
2695 irelaend = irela + section->reloc_count;
2696 for (; irela < irelaend; irela++)
2697 {
2698 long r_type, callee_args, caller_args, r_index, size_of_stub;
2699 struct elf_link_hash_entry *hash;
2700 struct elf32_hppa_stub_hash_entry *stub_hash;
2701 struct elf32_hppa_args_hash_entry *args_hash;
2702 Elf_Internal_Sym *sym;
2703 asection *sym_sec;
2704 const char *sym_name;
2705 symvalue sym_value;
2706 bfd_vma location, destination;
2707 char *new_name = NULL;
2708
2709 r_type = ELF32_R_TYPE (irela->r_info);
2710 r_index = ELF32_R_SYM (irela->r_info);
2711
2712 if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED)
2713 {
2714 bfd_set_error (bfd_error_bad_value);
2715 free (internal_relocs);
2716 free (local_syms);
2717 goto error_return;
2718 }
2719
2720 /* Only look for stubs on call instructions or plabel
2721 references. */
2722 if (r_type != R_PARISC_PCREL17F
2723 && r_type != R_PARISC_PLABEL32
2724 && r_type != R_PARISC_PLABEL21L
2725 && r_type != R_PARISC_PLABEL14R)
2726 continue;
2727
2728 /* Now determine the call target, its name, value, section
2729 and argument relocation bits. */
2730 hash = NULL;
2731 sym = NULL;
2732 sym_sec = NULL;
2733 if (r_index < symtab_hdr->sh_info)
2734 {
2735 /* It's a local symbol. */
2736 Elf_Internal_Shdr *hdr;
2737
2738 sym = local_syms + r_index;
2739 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
2740 sym_sec = hdr->bfd_section;
2741 sym_name = elf_string_from_elf_section (input_bfd,
2742 symtab_hdr->sh_link,
2743 sym->st_name);
2744 sym_value = (ELF_ST_TYPE (sym->st_info) == STT_SECTION
2745 ? 0 : sym->st_value);
2746 destination = (sym_value
2747 + sym_sec->output_offset
2748 + sym_sec->output_section->vma);
2749
2750 /* Tack on an ID so we can uniquely identify this local
2751 symbol in the stub or arg info hash tables. */
2752 new_name = malloc (strlen (sym_name) + 10);
2753 if (new_name == 0)
2754 {
2755 bfd_set_error (bfd_error_bad_value);
2756 free (internal_relocs);
2757 free (local_syms);
2758 goto error_return;
2759 }
2760 sprintf (new_name, "%s_%08x", sym_name, (int)sym_sec);
2761 sym_name = new_name;
2762 }
2763 else
2764 {
2765 /* It's an external symbol. */
2766 long index;
2767
2768 index = r_index - symtab_hdr->sh_info;
2769 hash = elf_sym_hashes (input_bfd)[index];
2770 if (hash->root.type == bfd_link_hash_defined)
2771 {
2772 sym_sec = hash->root.u.def.section;
2773 sym_name = hash->root.root.string;
2774 sym_value = hash->root.u.def.value;
2775 destination = (sym_value
2776 + sym_sec->output_offset
2777 + sym_sec->output_section->vma);
2778 }
2779 else
2780 {
2781 bfd_set_error (bfd_error_bad_value);
2782 free (internal_relocs);
2783 free (local_syms);
2784 goto error_return;
2785 }
2786 }
2787
2788 args_hash = elf32_hppa_args_hash_lookup (args_hash_table,
2789 sym_name, false, false);
2790
2791 /* Get both caller and callee argument information. */
2792 if (args_hash == NULL)
2793 callee_args = 0;
2794 else
2795 callee_args = args_hash->arg_bits;
2796
2797 /* For calls get the caller's bits from the addend of
2798 the call relocation. For PLABELS the caller's bits
2799 are assumed to have all args & return values in general
2800 registers (0x155). */
2801 if (r_type == R_PARISC_PCREL17F)
2802 caller_args = HPPA_R_ARG_RELOC (irela->r_addend);
2803 else
2804 caller_args = 0x155;
2805
2806 /* Now determine where the call point is. */
2807 location = (section->output_offset
2808 + section->output_section->vma
2809 + irela->r_offset);
2810
2811 /* We only care about the destination for PCREL function
2812 calls (eg. we don't care for PLABELS). */
2813 if (r_type != R_PARISC_PCREL17F)
2814 location = destination;
2815
2816 /* Determine what (if any) linker stub is needed and its
2817 size (in bytes). */
2818 size_of_stub = elf32_hppa_size_of_stub (callee_args,
2819 caller_args,
2820 location,
2821 destination,
2822 sym_name);
2823 if (size_of_stub != 0)
2824 {
2825 char *stub_name;
2826 unsigned int len;
2827
2828 /* Get the name of this stub. */
2829 len = strlen (sym_name);
2830 len += 23;
2831
2832 stub_name = malloc (len);
2833 if (!stub_name)
2834 {
2835 bfd_set_error (bfd_error_no_memory);
2836
2837 /* Because sym_name was mallocd above for local
2838 symbols. */
2839 if (r_index < symtab_hdr->sh_info)
2840 free (new_name);
2841
2842 free (internal_relocs);
2843 free (local_syms);
2844 goto error_return;
2845 }
2846 elf32_hppa_name_of_stub (caller_args, callee_args,
2847 location, destination, stub_name);
2848 strcat (stub_name + 22, sym_name);
2849
2850 /* Because sym_name was malloced above for local symbols. */
2851 if (r_index < symtab_hdr->sh_info)
2852 free (new_name);
2853
2854 stub_hash
2855 = elf32_hppa_stub_hash_lookup (stub_hash_table, stub_name,
2856 false, false);
2857 if (stub_hash != NULL)
2858 {
2859 /* The proper stub has already been created, nothing
2860 else to do. */
2861 free (stub_name);
2862 }
2863 else
2864 {
2865 bfd_set_section_size (stub_bfd, stub_sec,
2866 (bfd_section_size (stub_bfd,
2867 stub_sec)
2868 + size_of_stub));
2869
2870 /* Enter this entry into the linker stub hash table. */
2871 stub_hash
2872 = elf32_hppa_stub_hash_lookup (stub_hash_table,
2873 stub_name, true, true);
2874 if (stub_hash == NULL)
2875 {
2876 bfd_set_error (bfd_error_no_memory);
2877 free (stub_name);
2878 free (internal_relocs);
2879 free (local_syms);
2880 goto error_return;
2881 }
2882
2883 /* We'll need these to determine the address that the
2884 stub will branch to. */
2885 stub_hash->target_value = sym_value;
2886 stub_hash->target_section = sym_sec;
2887 }
2888 free (stub_name);
2889 }
2890 }
2891 /* We're done with the internal relocs, free them. */
2892 free (internal_relocs);
2893 }
2894 /* We're done with the local symbols, free them. */
2895 free (local_syms);
2896 }
2897 return true;
2898
2899 error_return:
2900 /* Return gracefully, avoiding dangling references to the hash tables. */
2901 if (stub_hash_table)
2902 {
2903 elf32_hppa_hash_table(link_info)->stub_hash_table = NULL;
2904 free (stub_hash_table);
2905 }
2906 if (args_hash_table)
2907 {
2908 elf32_hppa_hash_table(link_info)->args_hash_table = NULL;
2909 free (args_hash_table);
2910 }
2911 return false;
2912 }
2913
2914 /* Misc BFD support code. */
2915 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2916 #define bfd_elf32_bfd_is_local_label hppa_elf_is_local_label
2917
2918 /* Symbol extension stuff. */
2919 #define bfd_elf32_set_section_contents elf32_hppa_set_section_contents
2920 #define elf_backend_symbol_table_processing \
2921 elf32_hppa_backend_symbol_table_processing
2922 #define elf_backend_begin_write_processing \
2923 elf32_hppa_backend_begin_write_processing
2924 #define elf_backend_final_write_processing \
2925 elf32_hppa_backend_final_write_processing
2926
2927 /* Stuff for the BFD linker. */
2928 #define elf_backend_relocate_section elf32_hppa_relocate_section
2929 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
2930 #define elf_backend_link_output_symbol_hook \
2931 elf32_hppa_link_output_symbol_hook
2932 #define bfd_elf32_bfd_link_hash_table_create \
2933 elf32_hppa_link_hash_table_create
2934
2935 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
2936 #define TARGET_BIG_NAME "elf32-hppa"
2937 #define ELF_ARCH bfd_arch_hppa
2938 #define ELF_MACHINE_CODE EM_PARISC
2939 #define ELF_MAXPAGESIZE 0x1000
2940
2941 #include "elf32-target.h"