* gas/hppa/reloc/reloc.exp (roundmode test): Tweak expected output
[deliverable/binutils-gdb.git] / bfd / elf32-hppa.c
CommitLineData
4c85cbfa 1/* BFD back-end for HP PA-RISC ELF files.
f4bd7a8f 2 Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
4c85cbfa
KR
3
4 Written by
e8f2240a 5
4c85cbfa
KR
6 Center for Software Science
7 Department of Computer Science
8 University of Utah
9
10This file is part of BFD, the Binary File Descriptor library.
11
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation; either version 2 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25
26#include "bfd.h"
27#include "sysdep.h"
28#include "libbfd.h"
29#include "obstack.h"
4991ebb9 30#include "bfdlink.h"
4c85cbfa
KR
31#include "libelf.h"
32
f5bfdacd
JL
33/* Note there isn't much error handling code in here yet. Unexpected
34 conditions are handled by just calling abort. FIXME damnit! */
35
4c85cbfa
KR
36/* ELF32/HPPA relocation support
37
38 This file contains ELF32/HPPA relocation support as specified
39 in the Stratus FTX/Golf Object File Format (SED-1762) dated
f5bfdacd 40 November 19, 1992. */
4c85cbfa 41
4c85cbfa 42#include "elf32-hppa.h"
e8f2240a 43#include "aout/aout64.h"
d9ad93bc 44#include "hppa_stubs.h"
4c85cbfa 45
e08b9ad7
JL
46/* The basic stub types supported. If/when shared libraries are
47 implemented some form of IMPORT and EXPORT stubs will be needed. */
48typedef enum
49{
50 HPPA_STUB_ILLEGAL,
51 HPPA_STUB_ARG_RELOC,
52 HPPA_STUB_LONG_CALL,
53} hppa_stub_type;
54
55/* This is a list of all the stubs for a particular BFD. */
56
57typedef struct elf32_hppa_stub_name_list_struct
58{
59 /* The symbol associated with this stub. */
60 asymbol *sym;
61 /* Pointer to chain of all stub chains. */
62 struct elf32_hppa_stub_description_struct *stub_desc;
63 /* Pointer to the stub contents (eg instructions). */
64 int *stub_secp;
65 /* Size of this stub? (in what units? FIXME). */
66 unsigned size;
67 /* Pointer to the next stub entry in the chain. */
68 struct elf32_hppa_stub_name_list_struct *next;
69} elf32_hppa_stub_name_list;
70
71/* This is a linked list in which each entry describes all the
72 linker stubs for a particular bfd. */
73
74typedef struct elf32_hppa_stub_description_struct
75{
76 /* The next group of stubs. */
77 struct elf32_hppa_stub_description_struct *next;
78 /* Used to identify this group of stubs as belonging
79 to a particular bfd. */
80 bfd *this_bfd;
81 /* FIXME: The stub section for this group of stubs? Is
82 this redundant with stub_listP->sym->section? */
83 asection *stub_sec;
84 /* FIXME: what the hell is this? */
85 unsigned relocs_allocated_cnt;
86 /* The current real size of the stubs (in bytes?). */
87 unsigned real_size;
88 /* How much space we have allocated for stubs (in bytes?). */
89 unsigned allocated_size;
90 /* Pointer to the first available space for new stubs. */
91 int *stub_secp;
92 /* Pointer to the beginning of the stubs. FIXME: Why an int *
93 above and a char * here? */
94 char *stub_contents;
95 /* The list of stubs for this bfd. */
96 elf32_hppa_stub_name_list *stub_listP;
97 /* I guess we just carry this around for fun. */
98 struct bfd_link_info *link_info;
99} elf32_hppa_stub_description;
100
101/* FIXME. */
102#define ARGUMENTS 0
103#define RETURN_VALUE 1
104
105/* The various argument relocations that may be performed.
106 Note GRX,GRY really means ARGX,ARGY. */
107typedef enum
108{
109 /* No relocation. */
110 NO_ARG_RELOC,
111 /* Relocate 32 bits from general to FP register. */
112 R_TO_FR,
113 /* Relocate 64 bits from arg0,arg1 to FParg1. */
114 R01_TO_FR,
115 /* Relocate 64 bits from arg2,arg3 to FParg3. */
116 R23_TO_FR,
117 /* Relocate 32 bits from FP to general register. */
118 FR_TO_R,
119 /* Relocate 64 bits from FParg1 to arg0,arg1. */
120 FR_TO_R01,
121 /* Relocate 64 bits from FParg3 to arg2,arg3. */
122 FR_TO_R23,
123 /* Death. */
124 ARG_RELOC_ERR,
125} arg_reloc_type;
126
127/* Where (what register type) is an argument comming from? */
128typedef enum
129{
130 /* Not in a register. */
131 AR_NO,
132 /* In a general argument register. */
133 AR_GR,
134 /* In right half of a FP argument register. */
135 AR_FR,
136 /* In upper (left) half of a FP argument register. */
137 AR_FU,
138 /* In general argument register pair 0 (arg0, arg1). */
139 AR_DBL01,
140 /* In general argument register pair 1 (arg2, arg3). */
141 AR_DBL23,
142} arg_location;
143
144/* What is being relocated (eg which argument or the return value). */
145typedef enum
146{
147 ARG0, ARG1, ARG2, ARG3, RETVAL,
148} arg_reloc_location;
149
150/* Horizontal represents callee's argument location information, vertical
151 represents caller's argument location information. Value at a particular
152 X, Y location represents what (if any) argument relocation needs to
153 be performed to make caller and callee agree. */
154static CONST arg_reloc_type mismatches[6][6] =
155{
f3b477be 156 {NO_ARG_RELOC, NO_ARG_RELOC, NO_ARG_RELOC, NO_ARG_RELOC,
e08b9ad7
JL
157 NO_ARG_RELOC, NO_ARG_RELOC},
158 {NO_ARG_RELOC, NO_ARG_RELOC, R_TO_FR, ARG_RELOC_ERR,
159 R01_TO_FR, ARG_RELOC_ERR},
160 {NO_ARG_RELOC, FR_TO_R, NO_ARG_RELOC, ARG_RELOC_ERR,
161 ARG_RELOC_ERR, ARG_RELOC_ERR},
162 {ARG_RELOC_ERR, ARG_RELOC_ERR, ARG_RELOC_ERR, ARG_RELOC_ERR,
163 ARG_RELOC_ERR, ARG_RELOC_ERR},
164 {NO_ARG_RELOC, FR_TO_R01, NO_ARG_RELOC, ARG_RELOC_ERR,
165 NO_ARG_RELOC, ARG_RELOC_ERR},
166 {NO_ARG_RELOC, FR_TO_R23, NO_ARG_RELOC, ARG_RELOC_ERR,
167 ARG_RELOC_ERR, NO_ARG_RELOC},
168};
169
170/* Likewise for the return value. */
171static CONST arg_reloc_type retval_mismatches[6][6] =
172{
f3b477be 173 {NO_ARG_RELOC, NO_ARG_RELOC, NO_ARG_RELOC, NO_ARG_RELOC,
e08b9ad7
JL
174 NO_ARG_RELOC, NO_ARG_RELOC},
175 {NO_ARG_RELOC, NO_ARG_RELOC, FR_TO_R, ARG_RELOC_ERR,
176 FR_TO_R01, ARG_RELOC_ERR},
177 {NO_ARG_RELOC, R_TO_FR, NO_ARG_RELOC, ARG_RELOC_ERR,
178 ARG_RELOC_ERR, ARG_RELOC_ERR},
179 {ARG_RELOC_ERR, ARG_RELOC_ERR, ARG_RELOC_ERR, ARG_RELOC_ERR,
180 ARG_RELOC_ERR, ARG_RELOC_ERR},
181 {NO_ARG_RELOC, R01_TO_FR, NO_ARG_RELOC, ARG_RELOC_ERR,
182 NO_ARG_RELOC, ARG_RELOC_ERR},
183 {NO_ARG_RELOC, R23_TO_FR, NO_ARG_RELOC, ARG_RELOC_ERR,
184 ARG_RELOC_ERR, NO_ARG_RELOC},
185};
186
187/* Used for index mapping in symbol-extension sections. */
188struct elf32_hppa_symextn_map_struct
189{
190 int old_index;
191 bfd *bfd;
192 asymbol *sym;
193 int new_index;
194};
4c85cbfa 195
4991ebb9
ILT
196static bfd_reloc_status_type hppa_elf_reloc
197 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
4c85cbfa 198
f5bfdacd
JL
199static unsigned long hppa_elf_relocate_insn
200 PARAMS ((bfd *, asection *, unsigned long, unsigned long, long,
201 long, unsigned long, unsigned long, unsigned long));
202
f5bfdacd 203static long get_symbol_value PARAMS ((asymbol *));
e08b9ad7 204
f5bfdacd
JL
205static bfd_reloc_status_type hppa_elf_reloc
206 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd*, char **));
207
208static CONST reloc_howto_type * elf_hppa_reloc_type_lookup
7ed5e970 209 PARAMS ((bfd *, bfd_reloc_code_real_type));
f5bfdacd 210
e08b9ad7
JL
211static symext_entryS elf32_hppa_get_sym_extn PARAMS ((bfd *, asymbol *, int));
212
213static elf32_hppa_stub_description * find_stubs PARAMS ((bfd *, asection *));
214
215static elf32_hppa_stub_description * new_stub
216 PARAMS ((bfd *, asection *, struct bfd_link_info *));
217
218static arg_reloc_type type_of_mismatch PARAMS ((int, int, int));
219
220static elf32_hppa_stub_name_list * find_stub_by_name
221 PARAMS ((bfd *, asection *, char *));
222
223static elf32_hppa_stub_name_list * add_stub_by_name
224 PARAMS ((bfd *, asection *, asymbol *, struct bfd_link_info *));
225
226static void hppa_elf_stub_finish PARAMS ((bfd *));
227
228static void hppa_elf_stub_reloc
6e58a4e5 229 PARAMS ((elf32_hppa_stub_description *, bfd *, asymbol **, int,
e08b9ad7
JL
230 elf32_hppa_reloc_type));
231
232static int hppa_elf_arg_reloc_needed_p
233 PARAMS ((bfd *, arelent *, arg_reloc_type [5], symext_entryS));
234
235static asymbol * hppa_elf_build_linker_stub
236 PARAMS ((bfd *, bfd *, struct bfd_link_info *, arelent *,
237 arg_reloc_type [5], int, unsigned *, hppa_stub_type));
238
239static void hppa_elf_create_stub_sec
240 PARAMS ((bfd *, bfd *, asection **, struct bfd_link_info *));
241
242static int hppa_elf_long_branch_needed_p
243 PARAMS ((bfd *, asection *, arelent *, asymbol *, unsigned));
244
245static boolean hppa_elf_set_section_contents
246 PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
247
248static void elf_info_to_howto
249 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
250
251static void elf32_hppa_backend_symbol_processing PARAMS ((bfd *, asymbol *));
252
253static boolean elf32_hppa_backend_section_processing
254 PARAMS ((bfd *, Elf32_Internal_Shdr *));
255
256static boolean elf32_hppa_backend_symbol_table_processing
257 PARAMS ((bfd *, elf_symbol_type *, int));
258
259static boolean elf32_hppa_backend_section_from_shdr
260 PARAMS ((bfd *, Elf32_Internal_Shdr *, char *));
261
262static boolean elf32_hppa_backend_fake_sections
263 PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
264
265static boolean elf32_hppa_backend_section_from_bfd_section
266 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *));
267
459ae909
JL
268static void elf32_hppa_backend_begin_write_processing PARAMS ((bfd *));
269
270static void elf32_hppa_backend_final_write_processing PARAMS ((bfd *));
271
272static void add_entry_to_symext_chain
273 PARAMS ((bfd *, elf_symbol_type *, int, symext_chainS **, symext_chainS **));
274
275static void
276elf_hppa_tc_make_sections PARAMS ((bfd *, symext_chainS *));
277
7ed5e970 278static boolean hppa_elf_is_local_label PARAMS ((bfd *, asymbol *));
25057836 279
e08b9ad7
JL
280/* ELF/PA relocation howto entries. */
281
d9ad93bc 282static reloc_howto_type elf_hppa_howto_table[ELF_HOWTO_TABLE_SIZE] =
4c85cbfa 283{
459ae909
JL
284 {R_PARISC_NONE, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_NONE"},
285 {R_PARISC_DIR32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR32"},
286 {R_PARISC_DIR21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR21L"},
287 {R_PARISC_DIR17R, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR17R"},
288 {R_PARISC_DIR17F, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR17F"},
289 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
290 {R_PARISC_DIR14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DIR14R"},
291 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
292
293 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
294 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
295 {R_PARISC_PCREL21L, 0, 0, 21, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL21L"},
296 {R_PARISC_PCREL17R, 0, 0, 17, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL17R"},
297 {R_PARISC_PCREL17F, 0, 0, 17, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL17F"},
298 {R_PARISC_PCREL17C, 0, 0, 17, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL17C"},
299 {R_PARISC_PCREL14R, 0, 0, 14, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL14R"},
300 {R_PARISC_PCREL14F, 0, 0, 14, true, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PCREL14F"},
301
302 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
303 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
304 {R_PARISC_DPREL21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DPREL21L"},
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_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
308 {R_PARISC_DPREL14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DPREL14R"},
309 {R_PARISC_DPREL14F, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DPREL14F"},
310
311 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
312 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
313 {R_PARISC_DLTREL21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTREL21L"},
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_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
317 {R_PARISC_DLTREL14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTREL14R"},
318 {R_PARISC_DLTREL14F, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTREL14F"},
319
320 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
321 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
322 {R_PARISC_DLTIND21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTIND21L"},
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_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
326 {R_PARISC_DLTIND14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTIND14R"},
327 {R_PARISC_DLTIND14F, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_DLTIND14F"},
328
329 {R_PARISC_SETBASE, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_SETBASE"},
330 {R_PARISC_BASEREL32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL32"},
331 {R_PARISC_BASEREL21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL21L"},
332 {R_PARISC_BASEREL17R, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL17R"},
333 {R_PARISC_BASEREL17F, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL17F"},
334 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
335 {R_PARISC_BASEREL14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL14R"},
336 {R_PARISC_BASEREL14F, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_BASEREL14F"},
337
338 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
339 {R_PARISC_TEXTREL32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_TEXTREL32"},
340 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
341 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
342 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
343 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
344 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
345 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
346
347 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
348 {R_PARISC_DATAREL32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
349 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
350 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
351 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
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
356
357 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
358 {R_PARISC_PLABEL32, 0, 0, 32, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLABEL32"},
359 {R_PARISC_PLABEL21L, 0, 0, 21, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLABEL21L"},
360 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, 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_PLABEL14R, 0, 0, 14, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLABEL14R"},
364 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
365
366 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
367 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
368 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
369 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
370 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
371 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
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
375 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
376 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
377 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
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 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
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
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 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
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
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 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_UNIMPLEMENTED"},
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
426
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_PLTIND21L, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLTIND21L"},
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_PLTIND14R, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLTIND14R"},
434 {R_PARISC_PLTIND14F, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_PLTIND14F"},
435
436
437 {R_PARISC_COPY, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_COPY"},
438 {R_PARISC_GLOB_DAT, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_GLOB_DAT"},
439 {R_PARISC_JMP_SLOT, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_JMP_SLOT"},
440 {R_PARISC_RELATIVE, 0, 0, 0, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_RELATIVE"},
441 {R_PARISC_STUB_CALL_17, 0, 0, 17, false, 0, complain_overflow_bitfield, hppa_elf_reloc, "R_PARISC_STUB_CALL_17"},
442
443 {R_PARISC_UNIMPLEMENTED, 0, 0, 0, false, 0, complain_overflow_dont, NULL, "R_PARISC_UNIMPLEMENTED"},
e8f2240a 444};
4c85cbfa 445
d9ad93bc
KR
446static symext_chainS *symext_rootP;
447static symext_chainS *symext_lastP;
459ae909 448static int symext_chain_size;
f5bfdacd
JL
449static long global_value;
450static long GOT_value;
451static asymbol *global_symbol;
452static int global_sym_defined;
f5bfdacd 453static symext_entryS *symextn_contents;
e08b9ad7
JL
454static elf32_hppa_stub_description *elf_hppa_stub_rootP;
455static boolean stubs_finished = false;
456static struct elf32_hppa_symextn_map_struct *elf32_hppa_symextn_map;
457static int elf32_hppa_symextn_map_size;
458
459static char *linker_stubs = NULL;
460static int linker_stubs_size = 0;
461static int linker_stubs_max_size = 0;
462#define STUB_ALLOC_INCR 100
463#define STUB_SYM_BUFFER_INC 5
e8f2240a 464
f5bfdacd 465/* Relocate the given INSN given the various input parameters.
e8f2240a 466
f5bfdacd 467 FIXME: endianness and sizeof (long) issues abound here. */
4c85cbfa
KR
468
469static unsigned long
f5bfdacd
JL
470hppa_elf_relocate_insn (abfd, input_sect, insn, address, sym_value,
471 r_addend, r_format, r_field, pcrel)
f4bd7a8f
DM
472 bfd *abfd;
473 asection *input_sect;
474 unsigned long insn;
475 unsigned long address;
f4bd7a8f
DM
476 long sym_value;
477 long r_addend;
f5bfdacd
JL
478 unsigned long r_format;
479 unsigned long r_field;
480 unsigned long pcrel;
4c85cbfa 481{
e8f2240a
KR
482 unsigned char opcode = get_opcode (insn);
483 long constant_value;
484 unsigned arg_reloc;
485
486 switch (opcode)
487 {
488 case LDO:
489 case LDB:
490 case LDH:
491 case LDW:
492 case LDWM:
493 case STB:
494 case STH:
495 case STW:
496 case STWM:
f5bfdacd
JL
497 case COMICLR:
498 case SUBI:
499 case ADDIT:
500 case ADDI:
501 case LDIL:
502 case ADDIL:
7218bb04 503 constant_value = HPPA_R_CONSTANT (r_addend);
e8f2240a
KR
504
505 if (pcrel)
506 sym_value -= address;
e8f2240a 507
e8f2240a 508 sym_value = hppa_field_adjust (sym_value, constant_value, r_field);
f5bfdacd 509 return hppa_rebuild_insn (abfd, insn, sym_value, r_format);
e8f2240a
KR
510
511 case BL:
512 case BE:
513 case BLE:
7218bb04 514 arg_reloc = HPPA_R_ARG_RELOC (r_addend);
e8f2240a 515
e8f2240a
KR
516 /* XXX computing constant_value is not needed??? */
517 constant_value = assemble_17 ((insn & 0x001f0000) >> 16,
518 (insn & 0x00001ffc) >> 2,
519 insn & 1);
f5bfdacd 520
e8f2240a
KR
521 constant_value = (constant_value << 15) >> 15;
522 if (pcrel)
523 {
524 sym_value -=
525 address + input_sect->output_offset
526 + input_sect->output_section->vma;
527 sym_value = hppa_field_adjust (sym_value, -8, r_field);
528 }
529 else
530 sym_value = hppa_field_adjust (sym_value, constant_value, r_field);
4c85cbfa 531
f5bfdacd 532 return hppa_rebuild_insn (abfd, insn, sym_value >> 2, r_format);
4c85cbfa 533
e8f2240a
KR
534 default:
535 if (opcode == 0)
536 {
7218bb04 537 constant_value = HPPA_R_CONSTANT (r_addend);
e8f2240a 538
f5bfdacd
JL
539 if (pcrel)
540 sym_value -= address;
541
e8f2240a
KR
542 return hppa_field_adjust (sym_value, constant_value, r_field);
543 }
544 else
f5bfdacd 545 abort ();
e8f2240a 546 }
4c85cbfa
KR
547}
548
f5bfdacd
JL
549/* Return the relocated value of the given symbol. */
550
e8f2240a
KR
551static long
552get_symbol_value (symbol)
553 asymbol *symbol;
554{
f5bfdacd
JL
555 if (symbol == NULL
556 || symbol->section == &bfd_com_section)
557 return 0;
e8f2240a 558 else
f5bfdacd
JL
559 return symbol->value + symbol->section->output_section->vma
560 + symbol->section->output_offset;
4c85cbfa
KR
561}
562
f5bfdacd 563/* Return one (or more) BFD relocations which implement the base
e08b9ad7 564 relocation with modifications based on format and field. */
4c85cbfa 565
e8f2240a
KR
566elf32_hppa_reloc_type **
567hppa_elf_gen_reloc_type (abfd, base_type, format, field)
568 bfd *abfd;
569 elf32_hppa_reloc_type base_type;
570 int format;
571 int field;
4c85cbfa 572{
e8f2240a
KR
573 elf32_hppa_reloc_type *finaltype;
574 elf32_hppa_reloc_type **final_types;
e8f2240a 575
f5bfdacd
JL
576 /* Allocate slots for the BFD relocation. */
577 final_types = (elf32_hppa_reloc_type **)
578 bfd_alloc_by_size_t (abfd, sizeof (elf32_hppa_reloc_type *) * 2);
9783e04a 579 BFD_ASSERT (final_types != 0); /* FIXME */
e8f2240a 580
f5bfdacd
JL
581 /* Allocate space for the relocation itself. */
582 finaltype = (elf32_hppa_reloc_type *)
583 bfd_alloc_by_size_t (abfd, sizeof (elf32_hppa_reloc_type));
9783e04a 584 BFD_ASSERT (finaltype != 0); /* FIXME */
e8f2240a 585
f5bfdacd 586 /* Some reasonable defaults. */
e8f2240a
KR
587 final_types[0] = finaltype;
588 final_types[1] = NULL;
589
590#define final_type finaltype[0]
591
592 final_type = base_type;
593
f5bfdacd
JL
594 /* Just a tangle of nested switch statements to deal with the braindamage
595 that a different field selector means a completely different relocation
596 for PA ELF. */
e8f2240a
KR
597 switch (base_type)
598 {
599 case R_HPPA:
600 switch (format)
601 {
e8f2240a
KR
602 case 14:
603 switch (field)
604 {
605 case e_rsel:
e8f2240a 606 case e_rrsel:
459ae909 607 final_type = R_PARISC_DIR14R;
e8f2240a 608 break;
459ae909
JL
609 case e_rtsel:
610 final_type = R_PARISC_DLTREL14R;
e8f2240a 611 break;
e8f2240a 612 case e_tsel:
459ae909 613 final_type = R_PARISC_DLTREL14F;
a36b6f1d 614 break;
459ae909
JL
615 case e_rpsel:
616 final_type = R_PARISC_PLABEL14R;
a36b6f1d 617 break;
e8f2240a 618 default:
f5bfdacd 619 abort ();
e8f2240a
KR
620 break;
621 }
622 break;
f5bfdacd 623
e8f2240a
KR
624 case 17:
625 switch (field)
626 {
627 case e_fsel:
459ae909 628 final_type = R_PARISC_DIR17F;
e8f2240a
KR
629 break;
630 case e_rsel:
e8f2240a 631 case e_rrsel:
459ae909 632 final_type = R_PARISC_DIR17R;
e8f2240a 633 break;
e8f2240a 634 default:
f5bfdacd 635 abort ();
e8f2240a
KR
636 break;
637 }
638 break;
f5bfdacd 639
e8f2240a
KR
640 case 21:
641 switch (field)
642 {
643 case e_lsel:
e8f2240a 644 case e_lrsel:
459ae909 645 final_type = R_PARISC_DIR21L;
e8f2240a 646 break;
a36b6f1d 647 case e_ltsel:
459ae909
JL
648 final_type = R_PARISC_DLTREL21L;
649 break;
650 case e_lpsel:
651 final_type = R_PARISC_PLABEL21L;
a36b6f1d 652 break;
e8f2240a 653 default:
f5bfdacd 654 abort ();
e8f2240a
KR
655 break;
656 }
657 break;
f5bfdacd 658
e8f2240a
KR
659 case 32:
660 switch (field)
661 {
662 case e_fsel:
459ae909 663 final_type = R_PARISC_DIR32;
e8f2240a
KR
664 break;
665 case e_psel:
459ae909 666 final_type = R_PARISC_PLABEL32;
a36b6f1d 667 break;
e8f2240a 668 default:
f5bfdacd 669 abort ();
e8f2240a
KR
670 break;
671 }
672 break;
f5bfdacd 673
e8f2240a 674 default:
f5bfdacd 675 abort ();
e8f2240a
KR
676 break;
677 }
678 break;
f5bfdacd
JL
679
680
e8f2240a
KR
681 case R_HPPA_GOTOFF:
682 switch (format)
683 {
e8f2240a
KR
684 case 14:
685 switch (field)
686 {
687 case e_rsel:
e8f2240a 688 case e_rrsel:
459ae909 689 final_type = R_PARISC_DPREL14R;
e8f2240a
KR
690 break;
691 case e_fsel:
459ae909 692 final_type = R_PARISC_DPREL14F;
e8f2240a 693 break;
e8f2240a 694 default:
f5bfdacd 695 abort ();
e8f2240a
KR
696 break;
697 }
698 break;
f5bfdacd 699
e8f2240a
KR
700 case 21:
701 switch (field)
702 {
e8f2240a 703 case e_lrsel:
e8f2240a 704 case e_lsel:
459ae909 705 final_type = R_PARISC_DPREL21L;
e8f2240a 706 break;
e8f2240a 707 default:
f5bfdacd 708 abort ();
e8f2240a
KR
709 break;
710 }
711 break;
f5bfdacd 712
e8f2240a 713 default:
f5bfdacd 714 abort ();
e8f2240a
KR
715 break;
716 }
717 break;
f5bfdacd
JL
718
719
459ae909 720 case R_HPPA_PCREL_CALL:
e8f2240a
KR
721 switch (format)
722 {
e8f2240a
KR
723 case 14:
724 switch (field)
725 {
726 case e_rsel:
e8f2240a 727 case e_rrsel:
459ae909 728 final_type = R_PARISC_PCREL14R;
e8f2240a
KR
729 break;
730 case e_fsel:
459ae909 731 final_type = R_PARISC_PCREL14F;
e8f2240a 732 break;
e8f2240a 733 default:
f5bfdacd 734 abort ();
e8f2240a
KR
735 break;
736 }
737 break;
f5bfdacd 738
e8f2240a
KR
739 case 17:
740 switch (field)
741 {
742 case e_rsel:
e8f2240a 743 case e_rrsel:
459ae909 744 final_type = R_PARISC_PCREL17R;
e8f2240a
KR
745 break;
746 case e_fsel:
459ae909 747 final_type = R_PARISC_PCREL17F;
e8f2240a 748 break;
e8f2240a 749 default:
f5bfdacd 750 abort ();
e8f2240a
KR
751 break;
752 }
753 break;
f5bfdacd 754
e8f2240a
KR
755 case 21:
756 switch (field)
757 {
758 case e_lsel:
e8f2240a 759 case e_lrsel:
459ae909 760 final_type = R_PARISC_PCREL21L;
e8f2240a 761 break;
e8f2240a 762 default:
f5bfdacd 763 abort ();
e8f2240a
KR
764 break;
765 }
766 break;
f5bfdacd 767
e8f2240a 768 default:
f5bfdacd 769 abort ();
e8f2240a
KR
770 break;
771 }
772 break;
f5bfdacd 773
e8f2240a 774 default:
459ae909 775 abort ();
e8f2240a
KR
776 break;
777 }
778
779 return final_types;
4c85cbfa
KR
780}
781
e8f2240a
KR
782#undef final_type
783
4c85cbfa 784
f5bfdacd 785/* Actually perform a relocation. */
4c85cbfa
KR
786
787static bfd_reloc_status_type
4991ebb9
ILT
788hppa_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
789 error_message)
4861ac76
JL
790 bfd *abfd;
791 arelent *reloc_entry;
792 asymbol *symbol_in;
793 PTR data;
794 asection *input_section;
795 bfd *output_bfd;
4991ebb9 796 char **error_message;
e8f2240a
KR
797{
798 unsigned long insn;
799 long sym_value = 0;
4861ac76 800 unsigned long addr = reloc_entry->address;
f5bfdacd
JL
801 bfd_byte *hit_data = addr + (bfd_byte *) data;
802 unsigned long r_type = reloc_entry->howto->type;
803 unsigned long r_field = e_fsel;
e8f2240a 804 boolean r_pcrel = reloc_entry->howto->pc_relative;
e8f2240a
KR
805 unsigned r_format = reloc_entry->howto->bitsize;
806 long r_addend = reloc_entry->addend;
807
f5bfdacd 808 /* If only performing a partial link, get out early. */
e8f2240a
KR
809 if (output_bfd)
810 {
e8f2240a 811 reloc_entry->address += input_section->output_offset;
459ae909
JL
812
813 /* Work around lossage in generic elf code to write relocations.
814 (maps different section symbols into the same symbol index). */
815 if ((symbol_in->flags & BSF_SECTION_SYM)
816 && symbol_in->section)
817 reloc_entry->addend += symbol_in->section->output_offset;
e8f2240a
KR
818 return bfd_reloc_ok;
819 }
820
4861ac76
JL
821 /* If performing final link and the symbol we're relocating against
822 is undefined, then return an error. */
e8f2240a
KR
823 if (symbol_in && symbol_in->section == &bfd_und_section)
824 return bfd_reloc_undefined;
825
f5bfdacd 826 /* Get the final relocated value. */
e8f2240a
KR
827 sym_value = get_symbol_value (symbol_in);
828
f5bfdacd
JL
829 /* Compute the value of $global$.
830 FIXME: None of this should be necessary. $global$ is just a
831 marker and shouldn't really figure into these computations.
832
833 Once that's fixed we'll need to teach this backend to change
834 DP-relative relocations involving symbols in the text section
835 to be simple absolute relocations. */
d9ad93bc 836 if (!global_sym_defined)
e8f2240a 837 {
d9ad93bc 838 if (global_symbol)
e8f2240a 839 {
d9ad93bc
KR
840 global_value = (global_symbol->value
841 + global_symbol->section->output_section->vma
842 + global_symbol->section->output_offset);
4861ac76 843 GOT_value = global_value;
d9ad93bc 844 global_sym_defined++;
e8f2240a
KR
845 }
846 }
847
4861ac76 848 /* Get the instruction word. */
e8f2240a
KR
849 insn = bfd_get_32 (abfd, hit_data);
850
e8f2240a
KR
851 switch (r_type)
852 {
459ae909 853 case R_PARISC_NONE:
e8f2240a 854 break;
4861ac76 855
459ae909
JL
856 case R_PARISC_DIR32:
857 case R_PARISC_DIR17F:
858 case R_PARISC_PCREL17F:
859 case R_PARISC_PCREL17C:
860 case R_PARISC_PLABEL32:
861 case R_PARISC_PCREL14F:
e8f2240a
KR
862 r_field = e_fsel;
863 goto do_basic_type_1;
459ae909
JL
864 case R_PARISC_DIR21L:
865 case R_PARISC_PCREL21L:
866 case R_PARISC_PLABEL21L:
e8f2240a
KR
867 r_field = e_lrsel;
868 goto do_basic_type_1;
459ae909
JL
869 case R_PARISC_DIR17R:
870 case R_PARISC_PCREL17R:
871 case R_PARISC_DIR14R:
872 case R_PARISC_PCREL14R:
873 case R_PARISC_PLABEL14R:
e8f2240a 874 r_field = e_rrsel;
459ae909 875 goto do_basic_type_1;
e8f2240a 876
459ae909 877 case R_PARISC_DPREL21L:
e8f2240a 878 r_field = e_lrsel;
e8f2240a 879 sym_value -= GOT_value;
459ae909
JL
880 goto do_basic_type_1;
881 case R_PARISC_DPREL14R:
e8f2240a 882 r_field = e_rrsel;
459ae909
JL
883 sym_value -= GOT_value;
884 goto do_basic_type_1;
885 case R_PARISC_DPREL14F:
e8f2240a 886 r_field = e_fsel;
459ae909
JL
887 sym_value -= GOT_value;
888 goto do_basic_type_1;
4861ac76 889
e8f2240a 890
459ae909 891do_basic_type_1:
e8f2240a 892 insn = hppa_elf_relocate_insn (abfd, input_section, insn, addr,
f5bfdacd
JL
893 sym_value, r_addend, r_format,
894 r_field, r_pcrel);
e8f2240a
KR
895 break;
896
4861ac76 897
4861ac76 898 /* This is a linker internal relocation. */
459ae909 899 case R_PARISC_STUB_CALL_17:
4861ac76
JL
900 /* This relocation is for a branch to a long branch stub.
901 Change instruction to a BLE,N. It may also be necessary
f5bfdacd 902 to interchange the branch and its delay slot.
4861ac76
JL
903 The original instruction stream is
904
905 bl <foo>,r ; call foo using register r as
906 ; the return pointer
907 XXX ; delay slot instruction
908
909 The new instruction stream will be:
910
911 XXX ; delay slot instruction
912 ble <foo_stub> ; call the long call stub for foo
913 ; using r31 as the return pointer
914
915 This braindamage is necessary because the compiler may put
916 an instruction which uses %r31 in the delay slot of the original
917 call. By changing the call instruction from a "bl" to a "ble"
f5bfdacd
JL
918 %r31 gets clobbered before the delay slot executes. This
919 also means the stub has to play funny games to make sure
920 we return to the instruction just after the BLE rather than
921 two instructions after the BLE.
4861ac76
JL
922
923 We do not interchange the branch and delay slot if the delay
924 slot was already nullified, or if the instruction in the delay
925 slot modifies the return pointer to avoid an unconditional
f5bfdacd
JL
926 jump after the call returns (GCC optimization).
927
928 None of this horseshit would be necessary if we put the
929 stubs between functions and just redirected the "bl" to
930 the stub. Live and learn. */
4861ac76 931
f5bfdacd 932 /* Is this instruction nullified? (does this ever happen?) */
4861ac76 933 if (insn & 2)
a36b6f1d
JL
934 {
935 insn = BLE_N_XXX_0_0;
936 bfd_put_32 (abfd, insn, hit_data);
459ae909 937 r_type = R_PARISC_DIR17F;
a36b6f1d
JL
938 r_pcrel = 0;
939 insn = hppa_elf_relocate_insn (abfd, input_section, insn,
f5bfdacd
JL
940 addr, sym_value, r_addend,
941 r_format, r_field, r_pcrel);
a36b6f1d 942 }
d9ad93bc 943 else
7218bb04 944 {
f5bfdacd 945 /* So much for the trivial case... */
7218bb04
KR
946 unsigned long old_delay_slot_insn = bfd_get_32 (abfd, hit_data + 4);
947 unsigned rtn_reg = (insn & 0x03e00000) >> 21;
948
4861ac76 949 if (get_opcode (old_delay_slot_insn) == LDO)
7218bb04
KR
950 {
951 unsigned ldo_src_reg = (old_delay_slot_insn & 0x03e00000) >> 21;
952 unsigned ldo_target_reg = (old_delay_slot_insn & 0x001f0000) >> 16;
953
4861ac76
JL
954 /* If the target of the LDO is the same as the return
955 register then there is no reordering. We can leave the
f5bfdacd
JL
956 instuction as a non-nullified BLE in this case.
957
958 FIXME: This test looks wrong. If we had a ble using
959 ldo_target_reg as the *source* we'd fuck this up. */
7218bb04
KR
960 if (ldo_target_reg == rtn_reg)
961 {
962 unsigned long new_delay_slot_insn = old_delay_slot_insn;
963
f5bfdacd 964 BFD_ASSERT (ldo_src_reg == ldo_target_reg);
7218bb04
KR
965 new_delay_slot_insn &= 0xfc00ffff;
966 new_delay_slot_insn |= ((31 << 21) | (31 << 16));
4861ac76
JL
967 bfd_put_32 (abfd, new_delay_slot_insn, hit_data + 4);
968 insn = BLE_XXX_0_0;
459ae909 969 r_type = R_PARISC_DIR17F;
4861ac76
JL
970 r_pcrel = 0;
971 insn = hppa_elf_relocate_insn (abfd, input_section, insn,
f5bfdacd
JL
972 addr, sym_value, r_addend,
973 r_format, r_field, r_pcrel);
a36b6f1d 974 bfd_put_32 (abfd, insn, hit_data);
4861ac76 975 return bfd_reloc_ok;
7218bb04 976 }
a36b6f1d
JL
977 else if (rtn_reg == 31)
978 {
979 /* The return register is r31, so this is a millicode
980 call. Do not perform any instruction reordering. */
981 insn = BLE_XXX_0_0;
459ae909 982 r_type = R_PARISC_DIR17F;
a36b6f1d
JL
983 r_pcrel = 0;
984 insn = hppa_elf_relocate_insn (abfd, input_section, insn,
f5bfdacd
JL
985 addr, sym_value,
986 r_addend, r_format,
a36b6f1d
JL
987 r_field, r_pcrel);
988 bfd_put_32 (abfd, insn, hit_data);
989 return bfd_reloc_ok;
990 }
4861ac76
JL
991 else
992 {
993 /* Check to see if the delay slot instruction has a
994 relocation. If so, we need to change the address
f5bfdacd
JL
995 field of it because the instruction it relocates
996 is going to be moved. Oh what a mess. */
4861ac76
JL
997 arelent * next_reloc_entry = reloc_entry+1;
998
999 if (next_reloc_entry->address == reloc_entry->address + 4)
1000 next_reloc_entry->address -= 4;
1001
1002 insn = old_delay_slot_insn;
1003 bfd_put_32 (abfd, insn, hit_data);
1004 insn = BLE_N_XXX_0_0;
1005 bfd_put_32 (abfd, insn, hit_data + 4);
459ae909 1006 r_type = R_PARISC_DIR17F;
4861ac76
JL
1007 r_pcrel = 0;
1008 insn = hppa_elf_relocate_insn (abfd, input_section, insn,
f5bfdacd
JL
1009 addr + 4,
1010 sym_value, r_addend,
4861ac76
JL
1011 r_format, r_field, r_pcrel);
1012 bfd_put_32 (abfd, insn, hit_data + 4);
1013 return bfd_reloc_ok;
1014 }
1015 }
f5bfdacd 1016 /* Same comments as above regarding incorrect test. */
a36b6f1d
JL
1017 else if (rtn_reg == 31)
1018 {
1019 /* The return register is r31, so this is a millicode call.
1020 Perform no instruction reordering in this case. */
1021 insn = BLE_XXX_0_0;
459ae909 1022 r_type = R_PARISC_DIR17F;
a36b6f1d
JL
1023 r_pcrel = 0;
1024 insn = hppa_elf_relocate_insn (abfd, input_section, insn,
f5bfdacd
JL
1025 addr, sym_value,
1026 r_addend, r_format,
a36b6f1d
JL
1027 r_field, r_pcrel);
1028 bfd_put_32 (abfd, insn, hit_data);
1029 return bfd_reloc_ok;
1030 }
4861ac76
JL
1031 else
1032 {
1033 /* Check to see if the delay slot instruction has a
1034 relocation. If so, we need to change its address
1035 field because the instruction it relocates is going
1036 to be moved. */
1037 arelent * next_reloc_entry = reloc_entry+1;
1038
1039 if (next_reloc_entry->address == reloc_entry->address + 4)
1040 next_reloc_entry->address -= 4;
1041
1042 insn = old_delay_slot_insn;
1043 bfd_put_32 (abfd, insn, hit_data);
1044 insn = BLE_N_XXX_0_0;
1045 bfd_put_32 (abfd, insn, hit_data + 4);
459ae909 1046 r_type = R_PARISC_DIR17F;
4861ac76
JL
1047 r_pcrel = 0;
1048 insn = hppa_elf_relocate_insn (abfd, input_section, insn,
f5bfdacd
JL
1049 addr + 4, sym_value,
1050 r_addend, r_format,
4861ac76
JL
1051 r_field, r_pcrel);
1052 bfd_put_32 (abfd, insn, hit_data + 4);
1053 return bfd_reloc_ok;
7218bb04 1054 }
7218bb04 1055 }
d9ad93bc
KR
1056 break;
1057
f5bfdacd 1058 /* Something we don't know how to handle. */
e8f2240a 1059 default:
4991ebb9 1060 *error_message = (char *) "Unrecognized reloc";
f5bfdacd 1061 return bfd_reloc_notsupported;
e8f2240a
KR
1062 }
1063
4861ac76 1064 /* Update the instruction word. */
e8f2240a 1065 bfd_put_32 (abfd, insn, hit_data);
e8f2240a 1066 return (bfd_reloc_ok);
e8f2240a
KR
1067}
1068
f5bfdacd
JL
1069/* Return the address of the howto table entry to perform the CODE
1070 relocation for an ARCH machine. */
1071
1072static CONST reloc_howto_type *
7ed5e970
ILT
1073elf_hppa_reloc_type_lookup (abfd, code)
1074 bfd *abfd;
e8f2240a
KR
1075 bfd_reloc_code_real_type code;
1076{
459ae909 1077 if ((int) code < (int) R_PARISC_UNIMPLEMENTED)
e8f2240a
KR
1078 {
1079 BFD_ASSERT ((int) elf_hppa_howto_table[(int) code].type == (int) code);
1080 return &elf_hppa_howto_table[(int) code];
1081 }
f5bfdacd 1082 return NULL;
e8f2240a
KR
1083}
1084
25057836
JL
1085/* Return true if SYM represents a local label symbol. */
1086
1087static boolean
1088hppa_elf_is_local_label (abfd, sym)
1089 bfd *abfd;
1090 asymbol *sym;
1091{
1092 return (sym->name[0] == 'L' && sym->name[1] == '$');
1093}
e8f2240a 1094
459ae909
JL
1095/* Do any backend specific processing when beginning to write an object
1096 file. For PA ELF we need to determine the size of the symbol extension
1097 section *before* any other output processing happens. */
1098
1099static void
1100elf32_hppa_backend_begin_write_processing (abfd)
1101 bfd *abfd;
1102{
1103 int i;
1104 asection *symextn_sec;
1105
1106 /* Size up the symbol extension section. We can't built it just
1107 yet as the elf_symbol_map hasn't been built. */
1108 if (abfd->outsymbols == NULL || symext_chain_size != 0)
1109 return;
1110
1111 /* Look at each symbol, and determine if it will need an entry in
1112 the symbol extension section. */
1113 for (i = 0; i < abfd->symcount; i++)
1114 {
1115 elf_symbol_type *symbol = (elf_symbol_type *)abfd->outsymbols[i];
1116
1117 /* Only functions ever need an entry in the symbol extension
1118 section. */
1119 if (!(symbol->symbol.flags & BSF_FUNCTION))
1120 continue;
1121
1122 /* And only if they specify the locations of their arguments. */
1123 if (symbol->tc_data.hppa_arg_reloc == 0)
1124 continue;
1125
1126 /* Yup. This function symbol needs an entry. */
1127 symext_chain_size += 2 * sizeof (symext_entryS);
1128 }
1129
1130 /* Now create the section and set its size. We'll fill in the
1131 contents later. */
1132 symextn_sec = bfd_get_section_by_name (abfd, SYMEXTN_SECTION_NAME);
1133 if (symextn_sec == NULL)
1134 {
1135 symextn_sec = bfd_make_section (abfd, SYMEXTN_SECTION_NAME);
1136 bfd_set_section_flags (abfd, symextn_sec,
1137 SEC_LOAD | SEC_HAS_CONTENTS | SEC_DATA);
1138 symextn_sec->output_section = symextn_sec;
1139 symextn_sec->output_offset = 0;
1140 bfd_set_section_alignment (abfd, symextn_sec, 2);
1141 bfd_set_section_size (abfd, symextn_sec, symext_chain_size);
1142 }
1143
1144}
1145
1146/* Perform any processing needed late in the object file writing process.
1147 For PA ELF we build and set the contents of the symbol extension
1148 section. */
1149
1150static void
1151elf32_hppa_backend_final_write_processing (abfd)
1152 bfd *abfd;
1153{
1154 asection *symextn_sec;
1155 int i, *symtab_map = (int *) elf_sym_extra (abfd);
1156
1157 /* Now build the symbol extension section. */
1158 if (symext_chain_size == 0)
1159 return;
1160
1161 /* Look at each symbol, adding the appropriate information to the
1162 symbol extension section list as necessary. */
1163 for (i = 0; i < abfd->symcount; i++)
1164 {
1165 elf_symbol_type *symbol = (elf_symbol_type *) abfd->outsymbols[i];
1166
1167 /* Only functions ever need an entry in the symbol extension
1168 section. */
1169 if (!(symbol->symbol.flags & BSF_FUNCTION))
1170 continue;
1171
1172 /* And only if they specify the locations of their arguments. */
1173 if (symbol->tc_data.hppa_arg_reloc == 0)
1174 continue;
1175
1176 /* Add this symbol's information to the chain. */
1177 add_entry_to_symext_chain (abfd, symbol, symtab_map[i],
1178 &symext_rootP, &symext_lastP);
1179 }
1180
1181 /* Now fill in the contents of the symbol extension chain. */
1182 elf_hppa_tc_make_sections (abfd, symext_rootP);
1183
1184 /* And attach that as the section's contents. */
1185 symextn_sec = bfd_get_section_by_name (abfd, SYMEXTN_SECTION_NAME);
1186 if (symextn_sec == (asection *) 0)
1187 abort();
1188
1189 symextn_sec->contents = (void *)symextn_contents;
1190
1191 bfd_set_section_contents (abfd, symextn_sec, symextn_sec->contents,
1192 symextn_sec->output_offset, symextn_sec->_raw_size);
1193}
1194
f5bfdacd
JL
1195/* Update the symbol extention chain to include the symbol pointed to
1196 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
e8f2240a 1197
459ae909
JL
1198static void
1199add_entry_to_symext_chain (abfd, symbol, sym_idx, symext_root, symext_last)
f4bd7a8f 1200 bfd *abfd;
459ae909 1201 elf_symbol_type *symbol;
f4bd7a8f 1202 int sym_idx;
f5bfdacd
JL
1203 symext_chainS **symext_root;
1204 symext_chainS **symext_last;
e8f2240a
KR
1205{
1206 symext_chainS *symextP;
459ae909 1207 unsigned int arg_reloc = symbol->tc_data.hppa_arg_reloc;
3a70b01d 1208
f5bfdacd 1209 /* Allocate memory and initialize this entry. */
e8f2240a 1210 symextP = (symext_chainS *) bfd_alloc (abfd, sizeof (symext_chainS) * 2);
9783e04a
DM
1211 if (!symextP)
1212 {
f5bfdacd 1213 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
1214 abort(); /* FIXME */
1215 }
e8f2240a 1216
459ae909 1217 symextP[0].entry = ELF32_PARISC_SX_WORD (PARISC_SXT_SYMNDX, sym_idx);
e8f2240a
KR
1218 symextP[0].next = &symextP[1];
1219
459ae909 1220 symextP[1].entry = ELF32_PARISC_SX_WORD (PARISC_SXT_ARG_RELOC, arg_reloc);
e8f2240a
KR
1221 symextP[1].next = NULL;
1222
f5bfdacd
JL
1223 /* Now update the chain itself so it can be walked later to build
1224 the symbol extension section. */
1225 if (*symext_root == NULL)
e8f2240a 1226 {
f5bfdacd
JL
1227 *symext_root = &symextP[0];
1228 *symext_last = &symextP[1];
e8f2240a
KR
1229 }
1230 else
1231 {
f5bfdacd
JL
1232 (*symext_last)->next = &symextP[0];
1233 *symext_last = &symextP[1];
e8f2240a
KR
1234 }
1235}
1236
f5bfdacd 1237/* Build the symbol extension section. Used internally and by GAS. */
e8f2240a 1238
459ae909 1239static void
f5bfdacd 1240elf_hppa_tc_make_sections (abfd, symext_root)
f4bd7a8f 1241 bfd *abfd;
f5bfdacd 1242 symext_chainS *symext_root;
e8f2240a
KR
1243{
1244 symext_chainS *symextP;
459ae909 1245 int i;
e8f2240a
KR
1246 asection *symextn_sec;
1247
f5bfdacd 1248 /* FIXME: Huh? I don't see what this is supposed to do for us. */
e8f2240a
KR
1249 hppa_elf_stub_finish (abfd);
1250
e8f2240a 1251 symextn_sec = bfd_get_section_by_name (abfd, SYMEXTN_SECTION_NAME);
f5bfdacd
JL
1252
1253 /* Grab some memory for the contents of the symbol extension section
1254 itself. */
459ae909
JL
1255 symextn_contents = (symext_entryS *) bfd_zalloc (abfd,
1256 symextn_sec->_raw_size);
9783e04a
DM
1257 if (!symextn_contents)
1258 {
f5bfdacd 1259 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
1260 abort(); /* FIXME */
1261 }
e8f2240a 1262
459ae909 1263 /* Fill in the contents of the symbol extension chain. */
f5bfdacd 1264 for (i = 0, symextP = symext_root; symextP; symextP = symextP->next, ++i)
e8f2240a 1265 symextn_contents[i] = symextP->entry;
e8f2240a
KR
1266
1267 return;
1268}
1269
e08b9ad7 1270/* Return the symbol extension record of type TYPE for the symbol SYM. */
e8f2240a 1271
e08b9ad7 1272static symext_entryS
e8f2240a
KR
1273elf32_hppa_get_sym_extn (abfd, sym, type)
1274 bfd *abfd;
1275 asymbol *sym;
1276 int type;
1277{
e8f2240a
KR
1278 switch (type)
1279 {
459ae909
JL
1280 case PARISC_SXT_SYMNDX:
1281 case PARISC_SXT_NULL:
e08b9ad7 1282 return (symext_entryS) 0;
459ae909 1283 case PARISC_SXT_ARG_RELOC:
e8f2240a 1284 {
3a70b01d 1285 elf_symbol_type *esymP = (elf_symbol_type *) sym;
e8f2240a 1286
e08b9ad7 1287 return (symext_entryS) esymP->tc_data.hppa_arg_reloc;
e8f2240a 1288 }
d9ad93bc
KR
1289 /* This should never happen. */
1290 default:
1291 abort();
e8f2240a 1292 }
e8f2240a
KR
1293}
1294
e08b9ad7
JL
1295/* Search the chain of stub descriptions and locate the stub
1296 description for this the given section within the given bfd.
e8f2240a 1297
e08b9ad7
JL
1298 FIXME: I see yet another wonderful linear linked list search
1299 here. This is probably bad. */
e8f2240a 1300
3a70b01d 1301static elf32_hppa_stub_description *
e8f2240a
KR
1302find_stubs (abfd, stub_sec)
1303 bfd *abfd;
1304 asection *stub_sec;
1305{
3a70b01d 1306 elf32_hppa_stub_description *stubP;
e8f2240a
KR
1307
1308 for (stubP = elf_hppa_stub_rootP; stubP; stubP = stubP->next)
1309 {
e08b9ad7
JL
1310 /* Is this the right one? */
1311 if (stubP->this_bfd == abfd && stubP->stub_sec == stub_sec)
3a70b01d 1312 return stubP;
e8f2240a 1313 }
e08b9ad7 1314 return NULL;
e8f2240a
KR
1315}
1316
3a70b01d 1317static elf32_hppa_stub_description *
4991ebb9 1318new_stub (abfd, stub_sec, link_info)
e8f2240a
KR
1319 bfd *abfd;
1320 asection *stub_sec;
4991ebb9 1321 struct bfd_link_info *link_info;
e8f2240a 1322{
3a70b01d 1323 elf32_hppa_stub_description *stub = find_stubs (abfd, stub_sec);
e8f2240a 1324
e08b9ad7 1325 /* If we found a list for this bfd, then use it. */
e8f2240a
KR
1326 if (stub)
1327 return stub;
1328
e08b9ad7
JL
1329 /* Nope, allocate and initialize a new entry in the stub list chain. */
1330 stub = (elf32_hppa_stub_description *)
1331 bfd_zalloc (abfd, sizeof (elf32_hppa_stub_description));
3a70b01d
KR
1332 if (stub)
1333 {
1334 stub->this_bfd = abfd;
1335 stub->stub_sec = stub_sec;
1336 stub->real_size = 0;
1337 stub->allocated_size = 0;
1338 stub->stub_contents = NULL;
1339 stub->stub_secp = NULL;
4991ebb9 1340 stub->link_info = link_info;
3a70b01d
KR
1341
1342 stub->next = elf_hppa_stub_rootP;
1343 elf_hppa_stub_rootP = stub;
1344 }
1345 else
1346 {
f5bfdacd 1347 bfd_set_error (bfd_error_no_memory);
9783e04a 1348 abort(); /* FIXME */
3a70b01d 1349 }
e8f2240a
KR
1350
1351 return stub;
1352}
1353
e08b9ad7
JL
1354/* Try and locate a stub with the name NAME within the stubs
1355 associated with ABFD. More linked list searches. */
1356
3a70b01d
KR
1357static elf32_hppa_stub_name_list *
1358find_stub_by_name (abfd, stub_sec, name)
1359 bfd *abfd;
1360 asection *stub_sec;
1361 char *name;
1362{
e08b9ad7 1363 /* Find the stubs associated with this bfd. */
3a70b01d
KR
1364 elf32_hppa_stub_description *stub = find_stubs (abfd, stub_sec);
1365
e08b9ad7 1366 /* If found, then we have to walk down them looking for a match. */
3a70b01d
KR
1367 if (stub)
1368 {
1369 elf32_hppa_stub_name_list *name_listP;
1370
e08b9ad7
JL
1371 for (name_listP = stub->stub_listP;
1372 name_listP;
1373 name_listP = name_listP->next)
3a70b01d
KR
1374 {
1375 if (!strcmp (name_listP->sym->name, name))
1376 return name_listP;
1377 }
1378 }
1379
e08b9ad7 1380 /* Not found. */
3a70b01d
KR
1381 return 0;
1382}
1383
e08b9ad7 1384/* Add a new stub (SYM) to the list of stubs associated with the given BFD. */
3a70b01d 1385static elf32_hppa_stub_name_list *
4991ebb9 1386add_stub_by_name(abfd, stub_sec, sym, link_info)
3a70b01d
KR
1387 bfd *abfd;
1388 asection *stub_sec;
1389 asymbol *sym;
4991ebb9 1390 struct bfd_link_info *link_info;
e8f2240a 1391{
3a70b01d
KR
1392 elf32_hppa_stub_description *stub = find_stubs (abfd, stub_sec);
1393 elf32_hppa_stub_name_list *stub_entry;
e8f2240a 1394
e08b9ad7
JL
1395 /* If no stubs are associated with this bfd, then we have to make
1396 a chain-of-stubs associated with this bfd. */
3a70b01d 1397 if (!stub)
e08b9ad7 1398 stub = new_stub (abfd, stub_sec, link_info);
e8f2240a 1399
3a70b01d 1400 if (stub)
e8f2240a 1401 {
e08b9ad7 1402 /* Allocate and initialize an entry in the stub chain. */
3a70b01d
KR
1403 stub_entry = (elf32_hppa_stub_name_list *)
1404 bfd_zalloc (abfd, sizeof (elf32_hppa_stub_name_list));
e8f2240a 1405
3a70b01d 1406 if (stub_entry)
e8f2240a 1407 {
3a70b01d
KR
1408 stub_entry->size = 0;
1409 stub_entry->sym = sym;
1410 stub_entry->stub_desc = stub;
1411 /* First byte of this stub is the pointer to
1412 the next available location in the stub buffer. */
1413 stub_entry->stub_secp = stub->stub_secp;
e08b9ad7 1414 /* Add it to the chain. */
3a70b01d
KR
1415 if (stub->stub_listP)
1416 stub_entry->next = stub->stub_listP;
1417 else
1418 stub_entry->next = NULL;
1419 stub->stub_listP = stub_entry;
1420 return stub_entry;
4c85cbfa 1421 }
e8f2240a
KR
1422 else
1423 {
f5bfdacd 1424 bfd_set_error (bfd_error_no_memory);
9783e04a 1425 abort(); /* FIXME */
e8f2240a
KR
1426 }
1427 }
e08b9ad7
JL
1428 /* Death by mis-adventure. */
1429 abort ();
3a70b01d 1430 return (elf32_hppa_stub_name_list *)NULL;
e8f2240a
KR
1431}
1432
e08b9ad7
JL
1433/* For the given caller/callee argument location information and the
1434 type of relocation (arguments or return value), return the type
1435 of argument relocation needed to make caller and callee happy. */
e8f2240a 1436
e08b9ad7 1437static arg_reloc_type
e8f2240a
KR
1438type_of_mismatch (caller_bits, callee_bits, type)
1439 int caller_bits;
1440 int callee_bits;
1441 int type;
1442{
1443 switch (type)
1444 {
1445 case ARGUMENTS:
1446 return mismatches[caller_bits][callee_bits];
1447 case RETURN_VALUE:
1448 return retval_mismatches[caller_bits][callee_bits];
1449 }
e08b9ad7 1450 return ARG_RELOC_ERR;
e8f2240a
KR
1451}
1452
e08b9ad7
JL
1453/* Extract specific argument location bits for WHICH from the
1454 the full argument location information in AR. */
1455#define EXTRACT_ARBITS(ar, which) ((ar) >> (8 - ((which) * 2))) & 3
e8f2240a 1456
e08b9ad7
JL
1457/* Add the new instruction INSN into the stub area denoted by ENTRY.
1458 FIXME: Looks like more cases where we assume sizeof (int) ==
1459 sizeof (insn) which may not be true if building cross tools. */
1460#define NEW_INSTRUCTION(entry, insn) \
4861ac76 1461{ \
3a70b01d 1462 *((entry)->stub_desc->stub_secp)++ = (insn); \
e08b9ad7 1463 (entry)->stub_desc->real_size += sizeof (int); \
3a70b01d
KR
1464 (entry)->size += sizeof(int); \
1465 bfd_set_section_size((entry)->stub_desc->this_bfd, \
1466 (entry)->stub_desc->stub_sec, \
4861ac76
JL
1467 (entry)->stub_desc->real_size); \
1468}
e8f2240a 1469
e08b9ad7
JL
1470/* Find the offset of the current stub? Looks more like it
1471 finds the offset of the last instruction to me. */
3a70b01d 1472#define CURRENT_STUB_OFFSET(entry) \
9783e04a
DM
1473 ((char *)(entry)->stub_desc->stub_secp \
1474 - (char *)(entry)->stub_desc->stub_contents - 4)
d9ad93bc 1475
e08b9ad7
JL
1476/* All the stubs have already been built, finish up stub stuff
1477 by applying relocations to the stubs. */
d9ad93bc 1478
e08b9ad7 1479static void
e8f2240a
KR
1480hppa_elf_stub_finish (output_bfd)
1481 bfd *output_bfd;
1482{
3a70b01d 1483 elf32_hppa_stub_description *stub_list = elf_hppa_stub_rootP;
e8f2240a 1484
e08b9ad7 1485 /* If the stubs have been finished, then we're already done. */
f5bfdacd 1486 if (stubs_finished)
d9ad93bc
KR
1487 return;
1488
e08b9ad7 1489 /* Walk down the list of stub lists. */
e8f2240a
KR
1490 for (; stub_list; stub_list = stub_list->next)
1491 {
e08b9ad7 1492 /* If this list has stubs, then do something. */
3a70b01d 1493 if (stub_list->real_size)
e8f2240a 1494 {
3a70b01d 1495 bfd *stub_bfd = stub_list->this_bfd;
e08b9ad7 1496 asection *stub_sec = bfd_get_section_by_name (stub_bfd,
459ae909 1497 ".PARISC.stubs");
326e32d7 1498 long reloc_size;
e8f2240a 1499 arelent **reloc_vector;
326e32d7 1500 long reloc_count;
e8f2240a 1501
e08b9ad7 1502 /* Some sanity checking. */
3a70b01d 1503 BFD_ASSERT (stub_sec == stub_list->stub_sec);
e8f2240a
KR
1504 BFD_ASSERT (stub_sec);
1505
e08b9ad7
JL
1506 /* For stub sections raw_size == cooked_size. Also update
1507 reloc_done as we're handling the relocs now. */
e8f2240a
KR
1508 stub_sec->_cooked_size = stub_sec->_raw_size;
1509 stub_sec->reloc_done = true;
1510
e08b9ad7
JL
1511 /* Make space to hold the relocations for the stub section. */
1512 reloc_size = bfd_get_reloc_upper_bound (stub_bfd, stub_sec);
326e32d7
ILT
1513 if (reloc_size < 0)
1514 {
1515 /* FIXME: Should return an error. */
1516 abort ();
1517 }
80425e6c 1518 reloc_vector = (arelent **) malloc (reloc_size);
25057836 1519 if (reloc_vector == NULL && reloc_size != 0)
80425e6c
JK
1520 {
1521 /* FIXME: should be returning an error so the caller can
1522 clean up */
1523 abort ();
1524 }
e8f2240a 1525
e08b9ad7 1526 /* If we have relocations, do them. */
326e32d7
ILT
1527 reloc_count = bfd_canonicalize_reloc (stub_bfd, stub_sec,
1528 reloc_vector,
1529 output_bfd->outsymbols);
1530 if (reloc_count < 0)
1531 {
1532 /* FIXME: Should return an error. */
1533 abort ();
1534 }
1535 if (reloc_count > 0)
e8f2240a
KR
1536 {
1537 arelent **parent;
e08b9ad7 1538 for (parent = reloc_vector; *parent != NULL; parent++)
e8f2240a 1539 {
e08b9ad7 1540 char *err = NULL;
e8f2240a 1541 bfd_reloc_status_type r =
e08b9ad7 1542 bfd_perform_relocation (stub_bfd, *parent,
4991ebb9
ILT
1543 stub_list->stub_contents,
1544 stub_sec, (bfd *) NULL, &err);
e8f2240a 1545
e08b9ad7 1546 /* If there was an error, tell someone about it. */
e8f2240a
KR
1547 if (r != bfd_reloc_ok)
1548 {
4991ebb9
ILT
1549 struct bfd_link_info *link_info = stub_list->link_info;
1550
e8f2240a
KR
1551 switch (r)
1552 {
1553 case bfd_reloc_undefined:
4991ebb9
ILT
1554 if (! ((*link_info->callbacks->undefined_symbol)
1555 (link_info,
1556 bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
1557 stub_bfd, stub_sec, (*parent)->address)))
1558 abort ();
e8f2240a
KR
1559 break;
1560 case bfd_reloc_dangerous:
4991ebb9
ILT
1561 if (! ((*link_info->callbacks->reloc_dangerous)
1562 (link_info, err, stub_bfd, stub_sec,
1563 (*parent)->address)))
1564 abort ();
e8f2240a 1565 break;
e8f2240a 1566 case bfd_reloc_overflow:
4991ebb9
ILT
1567 {
1568 if (! ((*link_info->callbacks->reloc_overflow)
1569 (link_info,
1570 bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
1571 (*parent)->howto->name,
1572 (*parent)->addend,
1573 stub_bfd, stub_sec,
1574 (*parent)->address)))
1575 abort ();
1576 }
e8f2240a 1577 break;
4991ebb9 1578 case bfd_reloc_outofrange:
e8f2240a
KR
1579 default:
1580 abort ();
1581 break;
1582 }
1583 }
1584 }
1585 }
80425e6c 1586 free (reloc_vector);
e8f2240a 1587
e08b9ad7
JL
1588 /* All done with the relocations. Set the final contents
1589 of the stub section. FIXME: no check of return value! */
1590 bfd_set_section_contents (output_bfd, stub_sec,
3a70b01d 1591 stub_list->stub_contents,
e08b9ad7 1592 0, stub_list->real_size);
e8f2240a
KR
1593 }
1594 }
e08b9ad7 1595 /* All done. */
d9ad93bc 1596 stubs_finished = true;
e8f2240a
KR
1597}
1598
e08b9ad7 1599/* Allocate a new relocation entry to be used in a linker stub. */
d9ad93bc 1600
e08b9ad7
JL
1601static void
1602hppa_elf_stub_reloc (stub_desc, output_bfd, target_sym, offset, type)
f4bd7a8f
DM
1603 elf32_hppa_stub_description *stub_desc;
1604 bfd *output_bfd;
6e58a4e5 1605 asymbol **target_sym;
f4bd7a8f
DM
1606 int offset;
1607 elf32_hppa_reloc_type type;
d9ad93bc 1608{
d9ad93bc
KR
1609 arelent relent;
1610 int size;
1611 Elf_Internal_Shdr *rela_hdr;
1612
e08b9ad7 1613 /* I really don't like the realloc nonsense in here. FIXME. */
d9ad93bc
KR
1614 if (stub_desc->relocs_allocated_cnt == stub_desc->stub_sec->reloc_count)
1615 {
e08b9ad7 1616 /* Allocate the first few relocation entries. */
d9ad93bc
KR
1617 if (stub_desc->stub_sec->relocation == NULL)
1618 {
1619 stub_desc->relocs_allocated_cnt = STUB_RELOC_INCR;
1620 size = sizeof (arelent) * stub_desc->relocs_allocated_cnt;
f4bd7a8f 1621 stub_desc->stub_sec->relocation = (arelent *) bfd_zmalloc (size);
d9ad93bc
KR
1622 }
1623 else
1624 {
e08b9ad7
JL
1625 /* We've used all the entries we've already allocated. So get
1626 some more. */
d9ad93bc
KR
1627 stub_desc->relocs_allocated_cnt += STUB_RELOC_INCR;
1628 size = sizeof (arelent) * stub_desc->relocs_allocated_cnt;
e08b9ad7
JL
1629 stub_desc->stub_sec->relocation = (arelent *)
1630 realloc (stub_desc->stub_sec->relocation, size);
d9ad93bc 1631 }
9783e04a
DM
1632 if (!stub_desc->stub_sec->relocation)
1633 {
f5bfdacd 1634 bfd_set_error (bfd_error_no_memory);
e08b9ad7 1635 abort (); /* FIXME */
9783e04a 1636 }
d9ad93bc
KR
1637 }
1638
1639 rela_hdr = &elf_section_data(stub_desc->stub_sec)->rel_hdr;
1640 rela_hdr->sh_size += sizeof(Elf32_External_Rela);
1641
1642 /* Fill in the details. */
1643 relent.address = offset;
1644 relent.addend = 0;
6e58a4e5 1645 relent.sym_ptr_ptr = target_sym;
d9ad93bc 1646 relent.howto = bfd_reloc_type_lookup (stub_desc->this_bfd, type);
e8f2240a 1647
e08b9ad7 1648 /* Save it in the array of relocations for the stub section. */
e8f2240a 1649 memcpy (&stub_desc->stub_sec->relocation[stub_desc->stub_sec->reloc_count++],
e08b9ad7 1650 &relent, sizeof (arelent));
e8f2240a
KR
1651}
1652
e08b9ad7
JL
1653/* Build an argument relocation stub. RTN_ADJUST is a hint that an
1654 adjust to the return pointer from within the stub itself may be
1655 needed. */
1656
1657static asymbol *
1658hppa_elf_build_linker_stub (abfd, output_bfd, link_info, reloc_entry,
1659 stub_types, rtn_adjust, data, linker_stub_type)
e8f2240a
KR
1660 bfd *abfd;
1661 bfd *output_bfd;
4991ebb9 1662 struct bfd_link_info *link_info;
e8f2240a 1663 arelent *reloc_entry;
e08b9ad7 1664 arg_reloc_type stub_types[5];
4861ac76
JL
1665 int rtn_adjust;
1666 unsigned *data;
e08b9ad7 1667 hppa_stub_type linker_stub_type;
e8f2240a 1668{
e8f2240a 1669 int i;
e08b9ad7 1670 boolean milli, dyncall;
e8f2240a 1671 char stub_sym_name[128];
3a70b01d 1672 elf32_hppa_stub_name_list *stub_entry;
e08b9ad7 1673 /* Some initialization. */
4861ac76 1674 unsigned insn = data[0];
e08b9ad7 1675 asymbol *stub_sym = NULL;
f3b477be 1676 asymbol **orig_sym = reloc_entry->sym_ptr_ptr;
459ae909 1677 asection *stub_sec = bfd_get_section_by_name (abfd, ".PARISC.stubs");
e08b9ad7 1678 elf32_hppa_stub_description *stub_desc = find_stubs (abfd, stub_sec);
4861ac76
JL
1679
1680 /* Perform some additional checks on whether we should really do the
1681 return adjustment. For example, if the instruction is nullified
1682 or if the delay slot contains an instruction that modifies the return
1683 pointer, then the branch instructions should not be rearranged
1684 (rtn_adjust is false). */
1685 if (insn & 2 || insn == 0)
1686 rtn_adjust = false;
1687 else
1688 {
1689 unsigned delay_insn = data[1];
e8f2240a 1690
4861ac76
JL
1691 if (get_opcode (delay_insn) == LDO
1692 && (((insn & 0x03e00000) >> 21) == ((delay_insn & 0x001f0000) >> 16)))
1693 rtn_adjust = false;
1694 }
1695
e08b9ad7
JL
1696 /* Some special code for long-call stubs. */
1697 if (linker_stub_type == HPPA_STUB_LONG_CALL)
1698 {
1699
1700 /* Is this a millicode call? If so, the return address
1701 comes in on r31 rather than r2 (rp) so a slightly
1702 different code sequence is needed. */
1703 unsigned rtn_reg = (insn & 0x03e00000) >> 21;
1704 if (rtn_reg == 31)
1705 milli = true;
1706
1707 /* Dyncall is special because the user code has already
1708 put the return pointer in %r2 (aka RP). Other millicode
1709 calls have the return pointer in %r31. */
f3b477be 1710 if (strcmp ((*orig_sym)->name, "$$dyncall") == 0)
e08b9ad7
JL
1711 dyncall = true;
1712
1713 /* If we are creating a call from a stub to another stub, then
1714 never do the instruction reordering. We can tell if we are
1715 going to be calling one stub from another by the fact that
1716 the symbol name has '_stub_' (arg. reloc. stub) or '_lb_stub_'
1717 prepended to the name. Alternatively, the section of the
459ae909 1718 symbol will be '.PARISC.stubs'. This is only an issue
e08b9ad7
JL
1719 for long-calls; they are the only stubs allowed to call another
1720 stub. */
f3b477be
JL
1721 if ((strncmp ((*orig_sym)->name, "_stub_", 6) == 0)
1722 || (strncmp ((*orig_sym)->name, "_lb_stub_", 9) == 0))
e08b9ad7 1723 {
459ae909 1724 BFD_ASSERT (strcmp ((*orig_sym)->section->name, ".PARISC.stubs")
e08b9ad7
JL
1725 == 0);
1726 rtn_adjust = false;
1727 }
1728 }
1729
1730 /* Create the stub section if necessary. */
e8f2240a
KR
1731 if (!stub_sec)
1732 {
1733 BFD_ASSERT (stub_desc == NULL);
e08b9ad7 1734 hppa_elf_create_stub_sec (abfd, output_bfd, &stub_sec, link_info);
4991ebb9 1735 stub_desc = new_stub (abfd, stub_sec, link_info);
e8f2240a
KR
1736 }
1737
4861ac76 1738 /* Make the stub if we did not find one already. */
e8f2240a 1739 if (!stub_desc)
4991ebb9 1740 stub_desc = new_stub (abfd, stub_sec, link_info);
e8f2240a 1741
4861ac76 1742 /* Allocate space to write the stub.
e08b9ad7 1743 FIXME: Why using realloc?!? */
e8f2240a
KR
1744 if (!stub_desc->stub_contents)
1745 {
1746 stub_desc->allocated_size = STUB_BUFFER_INCR;
9783e04a 1747 stub_desc->stub_contents = (char *) malloc (STUB_BUFFER_INCR);
e8f2240a
KR
1748 }
1749 else if ((stub_desc->allocated_size - stub_desc->real_size) < STUB_MAX_SIZE)
1750 {
1751 stub_desc->allocated_size = stub_desc->allocated_size + STUB_BUFFER_INCR;
a5ccdad1
ILT
1752 stub_desc->stub_contents = (char *) realloc (stub_desc->stub_contents,
1753 stub_desc->allocated_size);
e8f2240a
KR
1754 }
1755
e08b9ad7
JL
1756 /* If no memory die. (I seriously doubt the other routines
1757 are prepared to get a NULL return value). */
1758 if (!stub_desc->stub_contents)
1759 {
1760 bfd_set_error (bfd_error_no_memory);
1761 abort ();
1762 }
1763
1764 /* Generate an appropriate name for this stub. */
1765 if (linker_stub_type == HPPA_STUB_ARG_RELOC)
1766 sprintf (stub_sym_name,
1767 "_stub_%s_%02d_%02d_%02d_%02d_%02d_%s",
1768 reloc_entry->sym_ptr_ptr[0]->name,
1769 stub_types[0], stub_types[1], stub_types[2],
1770 stub_types[3], stub_types[4],
1771 rtn_adjust ? "RA" : "");
1772 else
1773 sprintf (stub_sym_name,
1774 "_lb_stub_%s_%s", reloc_entry->sym_ptr_ptr[0]->name,
1775 rtn_adjust ? "RA" : "");
1776
1777
4861ac76
JL
1778 stub_desc->stub_secp
1779 = (int *) (stub_desc->stub_contents + stub_desc->real_size);
4861ac76 1780 stub_entry = find_stub_by_name (abfd, stub_sec, stub_sym_name);
e8f2240a 1781
e08b9ad7 1782 /* See if we already have one by this name. */
3a70b01d
KR
1783 if (stub_entry)
1784 {
e08b9ad7
JL
1785 /* Yes, re-use it. Redirect the original relocation from the
1786 old symbol (a function symbol) to the stub (the stub will call
1787 the original function). */
3a70b01d 1788 stub_sym = stub_entry->sym;
44fd6622
JL
1789 reloc_entry->sym_ptr_ptr = (asymbol **) bfd_zalloc (abfd,
1790 sizeof (asymbol **));
6e58a4e5
JL
1791 if (reloc_entry->sym_ptr_ptr == NULL)
1792 {
1793 bfd_set_error (bfd_error_no_memory);
1794 abort ();
1795 }
1796 reloc_entry->sym_ptr_ptr[0] = stub_sym;
e08b9ad7 1797 if (linker_stub_type == HPPA_STUB_LONG_CALL
459ae909 1798 || (reloc_entry->howto->type != R_PARISC_PLABEL32
e08b9ad7
JL
1799 && (get_opcode(insn) == BLE
1800 || get_opcode (insn) == BE
1801 || get_opcode (insn) == BL)))
459ae909 1802 reloc_entry->howto = bfd_reloc_type_lookup (abfd, R_PARISC_STUB_CALL_17);
3a70b01d
KR
1803 }
1804 else
1805 {
4861ac76 1806 /* Create a new symbol to point to this stub. */
3a70b01d 1807 stub_sym = bfd_make_empty_symbol (abfd);
9783e04a
DM
1808 if (!stub_sym)
1809 {
f5bfdacd 1810 bfd_set_error (bfd_error_no_memory);
e08b9ad7 1811 abort ();
9783e04a 1812 }
3a70b01d 1813 stub_sym->name = bfd_zalloc (abfd, strlen (stub_sym_name) + 1);
9783e04a
DM
1814 if (!stub_sym->name)
1815 {
f5bfdacd 1816 bfd_set_error (bfd_error_no_memory);
e08b9ad7 1817 abort ();
9783e04a 1818 }
3a70b01d 1819 strcpy ((char *) stub_sym->name, stub_sym_name);
4861ac76 1820 stub_sym->value
9783e04a 1821 = (char *) stub_desc->stub_secp - (char *) stub_desc->stub_contents;
3a70b01d
KR
1822 stub_sym->section = stub_sec;
1823 stub_sym->flags = BSF_LOCAL | BSF_FUNCTION;
4991ebb9 1824 stub_entry = add_stub_by_name (abfd, stub_sec, stub_sym, link_info);
3a70b01d 1825
4861ac76 1826 /* Redirect the original relocation from the old symbol (a function)
e08b9ad7 1827 to the stub (the stub calls the function). */
44fd6622
JL
1828 reloc_entry->sym_ptr_ptr = (asymbol **) bfd_zalloc (abfd,
1829 sizeof (asymbol **));
6e58a4e5
JL
1830 if (reloc_entry->sym_ptr_ptr == NULL)
1831 {
1832 bfd_set_error (bfd_error_no_memory);
1833 abort ();
1834 }
1835 reloc_entry->sym_ptr_ptr[0] = stub_sym;
e08b9ad7 1836 if (linker_stub_type == HPPA_STUB_LONG_CALL
459ae909 1837 || (reloc_entry->howto->type != R_PARISC_PLABEL32
e08b9ad7
JL
1838 && (get_opcode (insn) == BLE
1839 || get_opcode (insn) == BE
1840 || get_opcode (insn) == BL)))
459ae909 1841 reloc_entry->howto = bfd_reloc_type_lookup (abfd, R_PARISC_STUB_CALL_17);
3a70b01d 1842
e08b9ad7
JL
1843 /* Now generate the code for the stub. Starting with two
1844 common instructions.
3a70b01d 1845
e08b9ad7
JL
1846 FIXME: Do we still need the SP adjustment?
1847 Do we still need to muck with space registers? */
1848 NEW_INSTRUCTION (stub_entry, LDSID_31_1)
1849 NEW_INSTRUCTION (stub_entry, MTSP_1_SR0)
3a70b01d 1850
e08b9ad7 1851 if (linker_stub_type == HPPA_STUB_ARG_RELOC)
3a70b01d 1852 {
e08b9ad7 1853 NEW_INSTRUCTION (stub_entry, ADDI_8_SP)
e8f2240a 1854
e08b9ad7
JL
1855 /* Examine each argument, generating code to relocate it
1856 into a different register if necessary. */
1857 for (i = ARG0; i < ARG3; i++)
1858 {
1859 switch (stub_types[i])
1860 {
4861ac76 1861
e08b9ad7
JL
1862 case NO_ARG_RELOC:
1863 continue;
1864
1865 case R_TO_FR:
1866 switch (i)
1867 {
1868 case ARG0:
1869 NEW_INSTRUCTION (stub_entry, STWS_ARG0_M8SP)
1870 NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FARG0)
1871 break;
1872 case ARG1:
1873 NEW_INSTRUCTION (stub_entry, STWS_ARG1_M8SP)
1874 NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FARG1)
1875 break;
1876 case ARG2:
1877 NEW_INSTRUCTION (stub_entry, STWS_ARG2_M8SP)
1878 NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FARG2)
1879 break;
1880 case ARG3:
1881 NEW_INSTRUCTION (stub_entry, STWS_ARG3_M8SP)
1882 NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FARG3)
1883 break;
1884 }
1885 continue;
1886
1887 case R01_TO_FR:
1888 switch (i)
1889 {
1890 case ARG0:
1891 NEW_INSTRUCTION (stub_entry, STWS_ARG0_M4SP)
1892 NEW_INSTRUCTION (stub_entry, STWS_ARG1_M8SP)
1893 NEW_INSTRUCTION (stub_entry, FLDDS_M8SP_FARG1)
1894 break;
1895 default:
1896 abort ();
1897 break;
1898 }
1899 continue;
1900
1901 case R23_TO_FR:
1902 switch (i)
1903 {
1904 case ARG2:
1905 NEW_INSTRUCTION (stub_entry, STWS_ARG2_M4SP)
1906 NEW_INSTRUCTION (stub_entry, STWS_ARG3_M8SP)
1907 NEW_INSTRUCTION (stub_entry, FLDDS_M8SP_FARG3)
1908 break;
1909 default:
1910 abort ();
1911 break;
1912 }
1913 continue;
1914
1915 case FR_TO_R:
1916 switch (i)
1917 {
1918 case ARG0:
1919 NEW_INSTRUCTION (stub_entry, FSTWS_FARG0_M8SP)
1920 NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG0)
1921 break;
1922 case ARG1:
1923 NEW_INSTRUCTION (stub_entry, FSTWS_FARG1_M8SP)
1924 NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG1)
1925 break;
1926 case ARG2:
1927 NEW_INSTRUCTION (stub_entry, FSTWS_FARG2_M8SP)
1928 NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG2)
1929 break;
1930 case ARG3:
1931 NEW_INSTRUCTION (stub_entry, FSTWS_FARG3_M8SP)
1932 NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG3)
1933 break;
1934 }
1935 continue;
1936
1937 case FR_TO_R01:
1938 switch (i)
1939 {
1940 case ARG0:
1941 NEW_INSTRUCTION (stub_entry, FSTDS_FARG1_M8SP)
1942 NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG0)
1943 NEW_INSTRUCTION (stub_entry, LDWS_M8SP_ARG1)
1944 break;
1945 default:
1946 abort ();
1947 break;
1948 }
1949 continue;
1950
1951 case FR_TO_R23:
1952 switch (i)
1953 {
1954 case ARG2:
1955 NEW_INSTRUCTION (stub_entry, FSTDS_FARG3_M8SP)
1956 NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG2)
1957 NEW_INSTRUCTION (stub_entry, LDWS_M8SP_ARG3)
1958 break;
1959 default:
1960 abort ();
1961 break;
1962 }
1963 continue;
1964
1965 default:
1966 abort ();
1967 break;
1968 }
1969 }
1970
1971 /* Put the stack pointer back. FIXME: Is this still necessary? */
1972 NEW_INSTRUCTION (stub_entry, ADDI_M8_SP_SP)
1973 }
1974
1975 /* Common code again. Return pointer adjustment and the like. */
1976 if (!dyncall)
4861ac76 1977 {
e08b9ad7
JL
1978 /* This isn't dyncall. */
1979 if (!milli)
1980 {
1981 /* It's not a millicode call, so get the correct return
1982 value into %r2 (aka RP). */
1983 if (rtn_adjust)
1984 NEW_INSTRUCTION (stub_entry, ADDI_M4_31_RP)
1985 else
1986 NEW_INSTRUCTION (stub_entry, COPY_31_2)
1987 }
1988 else
1989 {
1990 /* It is a millicode call, so get the correct return
1991 value into %r1?!?. FIXME: Shouldn't this be
1992 %r31? Yes, and a little re-arrangement of the
1993 code below would make that possible. */
1994 if (rtn_adjust)
1995 NEW_INSTRUCTION (stub_entry, ADDI_M4_31_1)
1996 else
1997 NEW_INSTRUCTION (stub_entry, COPY_31_1)
1998 }
4861ac76 1999 }
4991ebb9 2000 else
e08b9ad7
JL
2001 {
2002 /* This is dyncall, so the code is a little different as the
2003 return pointer is already in %r2 (aka RP). */
2004 if (rtn_adjust)
2005 NEW_INSTRUCTION (stub_entry, ADDI_M4_31_RP)
2006 }
e8f2240a 2007
4861ac76 2008 /* Save the return address. */
e08b9ad7
JL
2009 if (linker_stub_type == HPPA_STUB_ARG_RELOC)
2010 NEW_INSTRUCTION (stub_entry, STW_RP_M8SP)
e8f2240a 2011
4861ac76 2012 /* Long branch to the target function. */
e08b9ad7 2013 NEW_INSTRUCTION (stub_entry, LDIL_XXX_31)
3a70b01d 2014 hppa_elf_stub_reloc (stub_entry->stub_desc,
f3b477be 2015 abfd, orig_sym,
4861ac76 2016 CURRENT_STUB_OFFSET (stub_entry),
459ae909 2017 R_PARISC_DIR21L);
e08b9ad7 2018 NEW_INSTRUCTION (stub_entry, BLE_XXX_0_31)
3a70b01d 2019 hppa_elf_stub_reloc (stub_entry->stub_desc,
f3b477be 2020 abfd, orig_sym,
4861ac76 2021 CURRENT_STUB_OFFSET (stub_entry),
459ae909 2022 R_PARISC_DIR17R);
4861ac76 2023
e08b9ad7
JL
2024 if (linker_stub_type == HPPA_STUB_ARG_RELOC)
2025 {
2026 /* In delay slot of long-call, copy %r31 into %r2 so that
2027 the callee can return in the normal fashion. */
2028 NEW_INSTRUCTION (stub_entry, COPY_31_2)
2029
2030 /* Restore the return address. */
2031 NEW_INSTRUCTION (stub_entry, LDW_M8SP_RP)
3a70b01d 2032
e08b9ad7
JL
2033 /* Generate the code to move the return value around. */
2034 switch (stub_types[RETVAL])
2035 {
2036 case NO_ARG_RELOC:
2037 break;
2038
2039 case R_TO_FR:
2040 NEW_INSTRUCTION (stub_entry, STWS_RET0_M8SP)
2041 NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FRET0)
2042 break;
2043
2044 case FR_TO_R:
2045 NEW_INSTRUCTION (stub_entry, FSTWS_FRET0_M8SP)
2046 NEW_INSTRUCTION (stub_entry, LDWS_M4SP_RET0)
2047 break;
2048
2049 default:
2050 abort ();
2051 break;
2052 }
2053
2054 /* Return back to the main code stream. */
2055 NEW_INSTRUCTION (stub_entry, BV_N_0_RP)
2056 }
2057 else
e8f2240a 2058 {
e08b9ad7 2059 if (!dyncall)
e8f2240a 2060 {
e08b9ad7
JL
2061 /* Get return address into %r31. Both variants may be necessary
2062 (I think) as we could be cascading into another stub. */
2063 if (!milli)
2064 NEW_INSTRUCTION (stub_entry, COPY_2_31)
2065 else
2066 NEW_INSTRUCTION (stub_entry, COPY_1_31)
2067 }
2068 else
2069 {
2070 /* Get the return address into %r31 too. Might be necessary
2071 (I think) as we could be cascading into another stub. */
2072 NEW_INSTRUCTION (stub_entry, COPY_2_31)
e8f2240a 2073 }
e08b9ad7
JL
2074
2075 /* No need for a return to the main stream. */
e8f2240a
KR
2076 }
2077 }
e8f2240a
KR
2078 return stub_sym;
2079}
2080
e08b9ad7
JL
2081/* Return nonzero if an argument relocation will be needed to call
2082 the function (symbol in RELOC_ENTRY) assuming the caller has
2083 argument relocation bugs CALLER_AR. */
2084
2085static int
3a70b01d 2086hppa_elf_arg_reloc_needed_p (abfd, reloc_entry, stub_types, caller_ar)
e8f2240a
KR
2087 bfd *abfd;
2088 arelent *reloc_entry;
e08b9ad7 2089 arg_reloc_type stub_types[5];
3a70b01d 2090 symext_entryS caller_ar;
e8f2240a 2091{
e08b9ad7
JL
2092 /* If the symbol is still undefined, then it's impossible to know
2093 if an argument relocation is needed. */
2094 if (reloc_entry->sym_ptr_ptr[0]
2095 && reloc_entry->sym_ptr_ptr[0]->section != &bfd_und_section)
e8f2240a 2096 {
e8f2240a
KR
2097 symext_entryS callee_ar = elf32_hppa_get_sym_extn (abfd,
2098 reloc_entry->sym_ptr_ptr[0],
459ae909 2099 PARISC_SXT_ARG_RELOC);
e8f2240a 2100
e08b9ad7
JL
2101 /* Now examine all the argument and return value location
2102 information to determine if a relocation stub will be needed. */
e8f2240a
KR
2103 if (caller_ar && callee_ar)
2104 {
e08b9ad7
JL
2105 arg_location caller_loc[5];
2106 arg_location callee_loc[5];
e8f2240a 2107
e08b9ad7
JL
2108 /* Extract the location information for the return value
2109 and argument registers separately. */
e8f2240a
KR
2110 callee_loc[RETVAL] = EXTRACT_ARBITS (callee_ar, RETVAL);
2111 caller_loc[RETVAL] = EXTRACT_ARBITS (caller_ar, RETVAL);
2112 callee_loc[ARG0] = EXTRACT_ARBITS (callee_ar, ARG0);
2113 caller_loc[ARG0] = EXTRACT_ARBITS (caller_ar, ARG0);
2114 callee_loc[ARG1] = EXTRACT_ARBITS (callee_ar, ARG1);
2115 caller_loc[ARG1] = EXTRACT_ARBITS (caller_ar, ARG1);
2116 callee_loc[ARG2] = EXTRACT_ARBITS (callee_ar, ARG2);
2117 caller_loc[ARG2] = EXTRACT_ARBITS (caller_ar, ARG2);
2118 callee_loc[ARG3] = EXTRACT_ARBITS (callee_ar, ARG3);
2119 caller_loc[ARG3] = EXTRACT_ARBITS (caller_ar, ARG3);
2120
e08b9ad7
JL
2121 /* Check some special combinations. For example, if FU
2122 appears in ARG1 or ARG3, we can move it to ARG0 or ARG2,
2123 respectively. (I guess this braindamage is correct? It'd
2124 take an hour or two of reading PA calling conventions to
2125 really know). */
e8f2240a
KR
2126
2127 if (caller_loc[ARG0] == AR_FU || caller_loc[ARG1] == AR_FU)
2128 {
d9ad93bc 2129 caller_loc[ARG0] = AR_DBL01;
e8f2240a
KR
2130 caller_loc[ARG1] = AR_NO;
2131 }
2132 if (caller_loc[ARG2] == AR_FU || caller_loc[ARG3] == AR_FU)
2133 {
d9ad93bc 2134 caller_loc[ARG2] = AR_DBL23;
e8f2240a
KR
2135 caller_loc[ARG3] = AR_NO;
2136 }
2137 if (callee_loc[ARG0] == AR_FU || callee_loc[ARG1] == AR_FU)
2138 {
d9ad93bc 2139 callee_loc[ARG0] = AR_DBL01;
e8f2240a
KR
2140 callee_loc[ARG1] = AR_NO;
2141 }
2142 if (callee_loc[ARG2] == AR_FU || callee_loc[ARG3] == AR_FU)
2143 {
d9ad93bc 2144 callee_loc[ARG2] = AR_DBL23;
e8f2240a
KR
2145 callee_loc[ARG3] = AR_NO;
2146 }
2147
e08b9ad7
JL
2148 /* Now look up potential mismatches. */
2149 stub_types[ARG0] = type_of_mismatch (caller_loc[ARG0],
2150 callee_loc[ARG0],
2151 ARGUMENTS);
2152 stub_types[ARG1] = type_of_mismatch (caller_loc[ARG1],
2153 callee_loc[ARG1],
2154 ARGUMENTS);
2155 stub_types[ARG2] = type_of_mismatch (caller_loc[ARG2],
2156 callee_loc[ARG2],
2157 ARGUMENTS);
2158 stub_types[ARG3] = type_of_mismatch (caller_loc[ARG3],
2159 callee_loc[ARG3],
2160 ARGUMENTS);
2161 stub_types[RETVAL] = type_of_mismatch (caller_loc[RETVAL],
2162 callee_loc[RETVAL],
2163 RETURN_VALUE);
2164
2165 /* If any of the arguments or return value need an argument
2166 relocation, then we will need an argument relocation stub. */
2167 if (stub_types[ARG0] != NO_ARG_RELOC
2168 || stub_types[ARG1] != NO_ARG_RELOC
2169 || stub_types[ARG2] != NO_ARG_RELOC
2170 || stub_types[ARG3] != NO_ARG_RELOC
2171 || stub_types[RETVAL] != NO_ARG_RELOC)
2172 return 1;
e8f2240a
KR
2173 }
2174 }
2175 return 0;
2176}
2177
e08b9ad7
JL
2178/* Create the linker stub section. */
2179
2180static void
2181hppa_elf_create_stub_sec (abfd, output_bfd, secptr, link_info)
d9ad93bc
KR
2182 bfd *abfd;
2183 bfd *output_bfd;
e08b9ad7 2184 asection **secptr;
4991ebb9 2185 struct bfd_link_info *link_info;
d9ad93bc 2186{
e08b9ad7
JL
2187 asection *output_text_section;
2188
2189 output_text_section = bfd_get_section_by_name (output_bfd, ".text");
459ae909 2190 *secptr = bfd_make_section (abfd, ".PARISC.stubs");
e08b9ad7
JL
2191 bfd_set_section_flags (abfd, *secptr,
2192 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD
2193 | SEC_RELOC | SEC_CODE | SEC_READONLY);
2194 (*secptr)->output_section = output_text_section->output_section;
2195 (*secptr)->output_offset = 0;
2196
2197 /* Set up the ELF section header for this new section. This
2198 is basically the same processing as elf_make_sections().
2199 elf_make_sections is static and therefore not accessable
2200 here. */
2201 {
2202 Elf_Internal_Shdr *this_hdr;
2203 this_hdr = &elf_section_data ((*secptr))->this_hdr;
2204
2205 /* Set the sizes of this section. The contents have already
2206 been set up ?!? */
2207 this_hdr->sh_addr = (*secptr)->vma;
2208 this_hdr->sh_size = (*secptr)->_raw_size;
2209
2210 /* Set appropriate flags for sections with relocations. */
2211 if ((*secptr)->flags & SEC_RELOC)
d9ad93bc 2212 {
e08b9ad7
JL
2213 Elf_Internal_Shdr *rela_hdr;
2214 int use_rela_p = get_elf_backend_data (abfd)->use_rela_p;
4861ac76 2215
e08b9ad7 2216 rela_hdr = &elf_section_data ((*secptr))->rel_hdr;
4861ac76 2217
e08b9ad7 2218 if (use_rela_p)
d9ad93bc 2219 {
e08b9ad7
JL
2220 rela_hdr->sh_type = SHT_RELA;
2221 rela_hdr->sh_entsize = sizeof (Elf32_External_Rela);
d9ad93bc 2222 }
e08b9ad7 2223 else
d9ad93bc 2224 {
e08b9ad7
JL
2225 rela_hdr->sh_type = SHT_REL;
2226 rela_hdr->sh_entsize = sizeof (Elf32_External_Rel);
d9ad93bc 2227 }
e08b9ad7
JL
2228 rela_hdr->sh_flags = 0;
2229 rela_hdr->sh_addr = 0;
2230 rela_hdr->sh_offset = 0;
2231 rela_hdr->sh_addralign = 0;
2232 rela_hdr->size = 0;
d9ad93bc 2233 }
4861ac76 2234
e08b9ad7
JL
2235 if ((*secptr)->flags & SEC_ALLOC)
2236 this_hdr->sh_flags |= SHF_ALLOC;
2237
2238 if (!((*secptr)->flags & SEC_READONLY))
2239 this_hdr->sh_flags |= SHF_WRITE;
2240
2241 if ((*secptr)->flags & SEC_CODE)
2242 this_hdr->sh_flags |= SHF_EXECINSTR;
4861ac76
JL
2243 }
2244
e08b9ad7 2245 bfd_set_section_alignment (abfd, *secptr, 2);
d9ad93bc
KR
2246}
2247
e08b9ad7
JL
2248/* Return nonzero if a long-call stub will be needed to call the
2249 function (symbol in RELOC_ENTRY). */
2250
2251static int
d9ad93bc
KR
2252hppa_elf_long_branch_needed_p (abfd, asec, reloc_entry, symbol, insn)
2253 bfd *abfd;
2254 asection *asec;
2255 arelent *reloc_entry;
2256 asymbol *symbol;
2257 unsigned insn;
2258{
e08b9ad7 2259 long sym_value = get_symbol_value (symbol);
d9ad93bc 2260 int fmt = reloc_entry->howto->bitsize;
e08b9ad7 2261 unsigned char op = get_opcode (insn);
d9ad93bc
KR
2262 unsigned raddr;
2263
e08b9ad7
JL
2264#define too_far(val,num_bits) \
2265 ((int)(val) > (1 << (num_bits)) - 1) || ((int)(val) < (-1 << (num_bits)))
d9ad93bc 2266
d9ad93bc
KR
2267 switch (op)
2268 {
2269 case BL:
2270 raddr =
2271 reloc_entry->address + asec->output_offset + asec->output_section->vma;
e08b9ad7
JL
2272 /* If the symbol and raddr (relocated addr?) are too far away from
2273 each other, then a long-call stub will be needed. */
2274 if (too_far (sym_value - raddr, fmt + 1))
d9ad93bc 2275 return 1;
d9ad93bc
KR
2276 break;
2277 }
2278 return 0;
2279}
2280
e08b9ad7
JL
2281/* Search the given section and determine if linker stubs will be
2282 needed for any calls within that section.
2283
2284 Return any new stub symbols created.
e8f2240a 2285
e08b9ad7
JL
2286 Used out of hppaelf.em in the linker. */
2287
e8f2240a 2288asymbol *
4861ac76 2289hppa_look_for_stubs_in_section (stub_bfd, abfd, output_bfd, asec,
6e58a4e5 2290 new_sym_cnt, link_info)
d9ad93bc 2291 bfd *stub_bfd;
e8f2240a
KR
2292 bfd *abfd;
2293 bfd *output_bfd;
2294 asection *asec;
e8f2240a 2295 int *new_sym_cnt;
4991ebb9 2296 struct bfd_link_info *link_info;
e8f2240a
KR
2297{
2298 int i;
e08b9ad7
JL
2299 arg_reloc_type stub_types[5];
2300 asymbol *new_syms = NULL;
e8f2240a
KR
2301 int new_cnt = 0;
2302 int new_max = 0;
80425e6c 2303 arelent **reloc_vector = NULL;
e8f2240a 2304
3a70b01d
KR
2305 /* Relocations are in different places depending on whether this is
2306 an output section or an input section. Also, the relocations are
e08b9ad7
JL
2307 in different forms. Sigh. Luckily, we have bfd_canonicalize_reloc()
2308 to straighten this out for us . */
e8f2240a
KR
2309 if (asec->reloc_count > 0)
2310 {
80425e6c
JK
2311 reloc_vector
2312 = (arelent **) malloc (asec->reloc_count * (sizeof (arelent *) + 1));
2313 if (reloc_vector == NULL)
2314 {
2315 bfd_set_error (bfd_error_no_memory);
2316 goto error_return;
2317 }
e8f2240a 2318
6e58a4e5
JL
2319 /* Make sure the canonical symbols are hanging around in a convient
2320 location. */
2321 if (bfd_get_outsymbols (abfd) == NULL)
2322 {
326e32d7
ILT
2323 long symsize;
2324 long symcount;
6e58a4e5 2325
326e32d7
ILT
2326 symsize = bfd_get_symtab_upper_bound (abfd);
2327 if (symsize < 0)
2328 goto error_return;
6e58a4e5 2329 abfd->outsymbols = (asymbol **) bfd_alloc (abfd, symsize);
326e32d7 2330 if (!abfd->outsymbols && symsize != 0)
6e58a4e5
JL
2331 {
2332 bfd_set_error (bfd_error_no_memory);
80425e6c 2333 goto error_return;
6e58a4e5 2334 }
326e32d7
ILT
2335 symcount = bfd_canonicalize_symtab (abfd, abfd->outsymbols);
2336 if (symcount < 0)
2337 goto error_return;
2338 abfd->symcount = symcount;
6e58a4e5
JL
2339 }
2340
2341 /* Now get the relocations. */
326e32d7
ILT
2342 if (bfd_canonicalize_reloc (abfd, asec, reloc_vector,
2343 bfd_get_outsymbols (abfd)) < 0)
2344 goto error_return;
e08b9ad7
JL
2345
2346 /* Examine each relocation entry in this section. */
e8f2240a
KR
2347 for (i = 0; i < asec->reloc_count; i++)
2348 {
e8f2240a
KR
2349 arelent *rle = reloc_vector[i];
2350
2351 switch (rle->howto->type)
2352 {
e08b9ad7
JL
2353 /* Any call could need argument relocation stubs, and
2354 some may need long-call stubs. */
459ae909
JL
2355 case R_PARISC_PCREL21L:
2356 case R_PARISC_PCREL17R:
2357 case R_PARISC_PCREL17F:
2358 case R_PARISC_PCREL17C:
2359 case R_PARISC_PCREL14R:
2360 case R_PARISC_PCREL14F:
3a70b01d 2361 {
4861ac76
JL
2362 symext_entryS caller_ar
2363 = (symext_entryS) HPPA_R_ARG_RELOC (rle->addend);
2364 unsigned insn[2];
2365
e08b9ad7 2366 /* We'll need this for the long-call checks. */
4861ac76
JL
2367 bfd_get_section_contents (abfd, asec, insn, rle->address,
2368 sizeof(insn));
e08b9ad7
JL
2369
2370 /* See if this call needs an argument relocation stub. */
3a70b01d
KR
2371 if (hppa_elf_arg_reloc_needed_p (abfd, rle, stub_types,
2372 caller_ar))
2373 {
4861ac76 2374 /* Generate a stub and keep track of the new symbol. */
3a70b01d 2375 asymbol *r;
d9ad93bc 2376
3a70b01d
KR
2377 if (new_cnt == new_max)
2378 {
2379 new_max += STUB_SYM_BUFFER_INC;
4861ac76
JL
2380 new_syms = (asymbol *)
2381 realloc (new_syms, new_max * sizeof (asymbol));
e08b9ad7 2382 if (new_syms == NULL)
80425e6c
JK
2383 {
2384 bfd_set_error (bfd_error_no_memory);
2385 goto error_return;
2386 }
3a70b01d 2387 }
4861ac76 2388
e08b9ad7
JL
2389 /* Build the argument relocation stub. */
2390 r = hppa_elf_build_linker_stub (stub_bfd, output_bfd,
2391 link_info, rle,
2392 stub_types, true, insn,
2393 HPPA_STUB_ARG_RELOC);
3a70b01d
KR
2394 new_syms[new_cnt++] = *r;
2395 }
d9ad93bc 2396
e08b9ad7 2397 /* See if this call needs a long-call stub. */
4861ac76
JL
2398 if (hppa_elf_long_branch_needed_p (abfd, asec, rle,
2399 rle->sym_ptr_ptr[0],
2400 insn[0]))
2401 {
2402 /* Generate a stub and keep track of the new symbol. */
2403 asymbol *r;
3a70b01d 2404
4861ac76
JL
2405 if (new_cnt == new_max)
2406 {
2407 new_max += STUB_SYM_BUFFER_INC;
2408 new_syms = (asymbol *)
2409 realloc (new_syms, (new_max * sizeof (asymbol)));
e08b9ad7 2410 if (! new_syms)
80425e6c
JK
2411 {
2412 bfd_set_error (bfd_error_no_memory);
2413 goto error_return;
2414 }
4861ac76 2415 }
e08b9ad7
JL
2416
2417 /* Build the long-call stub. */
2418 r = hppa_elf_build_linker_stub (stub_bfd, output_bfd,
2419 link_info, rle,
2420 NULL, true, insn,
2421 HPPA_STUB_LONG_CALL);
4861ac76
JL
2422 new_syms[new_cnt++] = *r;
2423 }
3a70b01d
KR
2424 }
2425 break;
2426
e08b9ad7 2427 /* PLABELs may need argument relocation stubs. */
459ae909
JL
2428 case R_PARISC_PLABEL32:
2429 case R_PARISC_PLABEL21L:
2430 case R_PARISC_PLABEL14R:
d9ad93bc 2431 {
3a70b01d 2432 /* On a plabel relocation, assume the arguments of the
e08b9ad7
JL
2433 caller are set up in general registers (indirect
2434 calls only use general registers.
2435 NOTE: 0x155 = ARGW0=GR,ARGW1=GR,ARGW2=GR,RETVAL=GR. */
3a70b01d 2436 symext_entryS caller_ar = (symext_entryS) 0x155;
4861ac76
JL
2437 unsigned insn[2];
2438
e08b9ad7 2439 /* Do we really need this? */
4861ac76
JL
2440 bfd_get_section_contents (abfd, asec, insn, rle->address,
2441 sizeof(insn));
d9ad93bc 2442
e08b9ad7 2443 /* See if this call needs an argument relocation stub. */
3a70b01d
KR
2444 if (hppa_elf_arg_reloc_needed_p (abfd, rle, stub_types,
2445 caller_ar))
d9ad93bc 2446 {
4861ac76
JL
2447 /* Generate a plabel stub and keep track of the
2448 new symbol. */
d9ad93bc 2449 asymbol *r;
4861ac76 2450 int rtn_adjust;
d9ad93bc
KR
2451
2452 if (new_cnt == new_max)
2453 {
2454 new_max += STUB_SYM_BUFFER_INC;
4861ac76
JL
2455 new_syms = (asymbol *) realloc (new_syms, new_max
2456 * sizeof (asymbol));
d9ad93bc 2457 }
4861ac76
JL
2458
2459 /* Determine whether a return adjustment
2460 (see the relocation code for relocation type
459ae909 2461 R_PARISC_STUB_CALL_17) is possible. Basically,
4861ac76 2462 determine whether we are looking at a branch or not. */
459ae909 2463 if (rle->howto->type == R_PARISC_PLABEL32)
4861ac76
JL
2464 rtn_adjust = false;
2465 else
2466 {
2467 switch (get_opcode(insn[0]))
2468 {
2469 case BLE:
2470 case BE:
2471 rtn_adjust = true;
2472 break;
2473 default:
2474 rtn_adjust = false;
2475 }
2476 }
e08b9ad7
JL
2477
2478 /* Build the argument relocation stub. */
2479 r = hppa_elf_build_linker_stub (stub_bfd, output_bfd,
2480 link_info, rle, stub_types,
2481 rtn_adjust, insn,
2482 HPPA_STUB_ARG_RELOC);
d9ad93bc
KR
2483 new_syms[new_cnt++] = *r;
2484 }
2485 }
e8f2240a 2486 break;
4c85cbfa 2487
e8f2240a
KR
2488 default:
2489 break;
e8f2240a
KR
2490 }
2491 }
2492 }
e08b9ad7 2493
80425e6c
JK
2494 if (reloc_vector != NULL)
2495 free (reloc_vector);
e08b9ad7 2496 /* Return the new symbols and update the counters. */
e8f2240a
KR
2497 *new_sym_cnt = new_cnt;
2498 return new_syms;
80425e6c
JK
2499
2500 error_return:
2501 if (reloc_vector != NULL)
2502 free (reloc_vector);
2503 /* FIXME: This is bogus. We should be returning NULL. But do the callers
2504 check for that? */
2505 abort ();
4c85cbfa
KR
2506}
2507
e08b9ad7 2508/* Set the contents of a particular section at a particular location. */
d9ad93bc 2509
e08b9ad7 2510static boolean
f4bd7a8f
DM
2511hppa_elf_set_section_contents (abfd, section, location, offset, count)
2512 bfd *abfd;
2513 sec_ptr section;
2514 PTR location;
2515 file_ptr offset;
2516 bfd_size_type count;
4c85cbfa 2517{
e08b9ad7 2518 /* Linker stubs are handled a little differently. */
459ae909 2519 if (! strcmp (section->name, ".PARISC.stubs"))
d9ad93bc 2520 {
f5bfdacd 2521 if (linker_stubs_max_size < offset + count)
d9ad93bc
KR
2522 {
2523 linker_stubs_max_size = offset + count + STUB_ALLOC_INCR;
e08b9ad7
JL
2524 linker_stubs = (char *)realloc (linker_stubs, linker_stubs_max_size);
2525 if (! linker_stubs)
2526 abort ();
d9ad93bc
KR
2527 }
2528
f5bfdacd 2529 if (offset + count > linker_stubs_size)
d9ad93bc
KR
2530 linker_stubs_size = offset + count;
2531
e08b9ad7
JL
2532 /* Set the contents. */
2533 memcpy(linker_stubs + offset, location, count);
d9ad93bc
KR
2534 return (true);
2535 }
459ae909
JL
2536 /* Ignore write requests for the symbol extension section until we've
2537 had the chance to rebuild it ourselves. */
2538 else if (! strcmp (section->name, ".PARISC.symextn") && !symext_chain_size)
2539 return true;
d9ad93bc
KR
2540 else
2541 return bfd_elf32_set_section_contents (abfd, section, location,
2542 offset, count);
e8f2240a 2543}
4c85cbfa 2544
7218bb04
KR
2545/* Get the contents of the given section.
2546
2547 This is special for PA ELF because some sections (such as linker stubs)
2548 may reside in memory rather than on disk, or in the case of the symbol
2549 extension section, the contents may need to be generated from other
2550 information contained in the BFD. */
2551
e8f2240a 2552boolean
7218bb04
KR
2553hppa_elf_get_section_contents (abfd, section, location, offset, count)
2554 bfd *abfd;
2555 sec_ptr section;
2556 PTR location;
2557 file_ptr offset;
2558 bfd_size_type count;
e8f2240a 2559{
7218bb04
KR
2560 /* If this is the linker stub section, then its contents are contained
2561 in memory rather than on disk. FIXME. Is that always right? What
2562 about the case where a final executable is read in and a user tries
2563 to get the contents of this section? In that case the contents would
2564 be on disk like everything else. */
459ae909 2565 if (strcmp (section->name, ".PARISC.stubs") == 0)
e8f2240a 2566 {
3a70b01d 2567 elf32_hppa_stub_description *stub_desc = find_stubs (abfd, section);
7218bb04 2568
e8f2240a
KR
2569 if (count == 0)
2570 return true;
7218bb04
KR
2571
2572 /* Sanity check our arguments. */
2573 if ((bfd_size_type) (offset + count) > section->_raw_size
2574 || (bfd_size_type) (offset + count) > stub_desc->real_size)
2575 return (false);
2576
e8f2240a
KR
2577 memcpy (location, stub_desc->stub_contents + offset, count);
2578 return (true);
2579 }
e8f2240a 2580 else
459ae909 2581 /* It's not the linker stub section, use the generic routines. */
6812b607
ILT
2582 return _bfd_generic_get_section_contents (abfd, section, location,
2583 offset, count);
4c85cbfa
KR
2584}
2585
e08b9ad7
JL
2586/* Translate from an elf into field into a howto relocation pointer. */
2587
8ddd7ab3 2588static void
f4bd7a8f
DM
2589elf_info_to_howto (abfd, cache_ptr, dst)
2590 bfd *abfd;
2591 arelent *cache_ptr;
2592 Elf32_Internal_Rela *dst;
4c85cbfa 2593{
459ae909 2594 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_PARISC_UNIMPLEMENTED);
e08b9ad7 2595 cache_ptr->howto = &elf_hppa_howto_table[ELF32_R_TYPE (dst->r_info)];
d9ad93bc
KR
2596}
2597
e08b9ad7
JL
2598/* Do PA ELF specific processing for symbols. Needed to find the
2599 value of $global$. */
2600
d9ad93bc 2601static void
f4bd7a8f
DM
2602elf32_hppa_backend_symbol_processing (abfd, sym)
2603 bfd *abfd;
2604 asymbol *sym;
d9ad93bc
KR
2605{
2606 /* Is this a definition of $global$? If so, keep it because it will be
2607 needed if any relocations are performed. */
d9ad93bc
KR
2608 if (!strcmp (sym->name, "$global$")
2609 && sym->section != &bfd_und_section)
2610 {
2611 global_symbol = sym;
2612 }
2613}
2614
e08b9ad7
JL
2615/* Do some PA ELF specific work after reading in the symbol table.
2616 In particular attach the argument relocation from the
2617 symbol extension section to the appropriate symbols. */
d9ad93bc 2618static boolean
f4bd7a8f
DM
2619elf32_hppa_backend_symbol_table_processing (abfd, esyms,symcnt)
2620 bfd *abfd;
2621 elf_symbol_type *esyms;
2622 int symcnt;
d9ad93bc 2623{
e08b9ad7
JL
2624 Elf32_Internal_Shdr *symextn_hdr =
2625 bfd_elf_find_section (abfd, SYMEXTN_SECTION_NAME);
2626 int i, current_sym_idx = 0;
d9ad93bc 2627
e08b9ad7
JL
2628 /* If no symbol extension existed, then all symbol extension information
2629 is assumed to be zero. */
f5bfdacd 2630 if (symextn_hdr == NULL)
d9ad93bc 2631 {
f5bfdacd 2632 for (i = 0; i < symcnt; i++)
e08b9ad7 2633 esyms[i].tc_data.hppa_arg_reloc = 0;
d9ad93bc
KR
2634 return (true);
2635 }
2636
e08b9ad7 2637 /* Allocate a buffer of the appropriate size for the symextn section. */
d9ad93bc 2638 symextn_hdr->contents = bfd_zalloc(abfd,symextn_hdr->sh_size);
9783e04a
DM
2639 if (!symextn_hdr->contents)
2640 {
f5bfdacd 2641 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
2642 return false;
2643 }
d9ad93bc
KR
2644 symextn_hdr->size = symextn_hdr->sh_size;
2645
e08b9ad7 2646 /* Read in the symextn section. */
d9ad93bc 2647 if (bfd_seek (abfd, symextn_hdr->sh_offset, SEEK_SET) == -1)
25057836 2648 return false;
d9ad93bc
KR
2649 if (bfd_read ((PTR) symextn_hdr->contents, 1, symextn_hdr->size, abfd)
2650 != symextn_hdr->size)
25057836 2651 return false;
d9ad93bc 2652
e08b9ad7
JL
2653 /* Parse entries in the symbol extension section, updating the symtab
2654 entries as we go */
f5bfdacd 2655 for (i = 0; i < symextn_hdr->size / sizeof(symext_entryS); i++)
d9ad93bc
KR
2656 {
2657 symext_entryS *seP = ((symext_entryS *)symextn_hdr->contents) + i;
459ae909
JL
2658 int se_value = ELF32_PARISC_SX_VAL (*seP);
2659 int se_type = ELF32_PARISC_SX_TYPE (*seP);
d9ad93bc 2660
f5bfdacd 2661 switch (se_type)
d9ad93bc 2662 {
459ae909 2663 case PARISC_SXT_NULL:
d9ad93bc
KR
2664 break;
2665
459ae909 2666 case PARISC_SXT_SYMNDX:
f5bfdacd 2667 if (se_value >= symcnt)
d9ad93bc 2668 {
f5bfdacd 2669 bfd_set_error (bfd_error_bad_value);
d9ad93bc
KR
2670 return (false);
2671 }
2672 current_sym_idx = se_value - 1;
2673 break;
2674
459ae909 2675 case PARISC_SXT_ARG_RELOC:
d9ad93bc
KR
2676 esyms[current_sym_idx].tc_data.hppa_arg_reloc = se_value;
2677 break;
2678
2679 default:
f5bfdacd 2680 bfd_set_error (bfd_error_bad_value);
d9ad93bc
KR
2681 return (false);
2682 }
2683 }
2684 return (true);
2685}
2686
e08b9ad7
JL
2687/* Perform on PA ELF specific processing once a section has been
2688 read in. In particular keep the symbol indexes correct for
2689 the symbol extension information. */
d9ad93bc
KR
2690
2691static boolean
f4bd7a8f
DM
2692elf32_hppa_backend_section_processing (abfd, secthdr)
2693 bfd *abfd;
2694 Elf32_Internal_Shdr *secthdr;
d9ad93bc 2695{
e08b9ad7 2696 int i, j, k;
d9ad93bc 2697
459ae909 2698 if (secthdr->sh_type == SHT_PARISC_SYMEXTN)
d9ad93bc 2699 {
e08b9ad7 2700 for (i = 0; i < secthdr->size / sizeof (symext_entryS); i++)
d9ad93bc
KR
2701 {
2702 symext_entryS *seP = ((symext_entryS *)secthdr->contents) + i;
459ae909
JL
2703 int se_value = ELF32_PARISC_SX_VAL (*seP);
2704 int se_type = ELF32_PARISC_SX_TYPE (*seP);
d9ad93bc 2705
f5bfdacd 2706 switch (se_type)
d9ad93bc 2707 {
459ae909 2708 case PARISC_SXT_NULL:
d9ad93bc
KR
2709 break;
2710
459ae909 2711 case PARISC_SXT_SYMNDX:
f5bfdacd 2712 for (j = 0; j < abfd->symcount; j++)
d9ad93bc 2713 {
e08b9ad7
JL
2714 /* Locate the map entry for this symbol and modify the
2715 symbol extension section symbol index entry to reflect
2716 the new symbol table index. */
f5bfdacd 2717 for (k = 0; k < elf32_hppa_symextn_map_size; k++)
d9ad93bc 2718 {
f5bfdacd 2719 if (elf32_hppa_symextn_map[k].old_index == se_value
e08b9ad7
JL
2720 && elf32_hppa_symextn_map[k].bfd
2721 == abfd->outsymbols[j]->the_bfd
2722 && elf32_hppa_symextn_map[k].sym
2723 == abfd->outsymbols[j])
d9ad93bc
KR
2724 {
2725 bfd_put_32(abfd,
459ae909 2726 ELF32_PARISC_SX_WORD (PARISC_SXT_SYMNDX, j),
d9ad93bc
KR
2727 (char *)seP);
2728 }
2729 }
2730 }
2731 break;
2732
459ae909 2733 case PARISC_SXT_ARG_RELOC:
d9ad93bc
KR
2734 break;
2735
2736 default:
f5bfdacd 2737 bfd_set_error (bfd_error_bad_value);
d9ad93bc
KR
2738 return (false);
2739 }
2740 }
2741 }
2742 return true;
2743}
2744
e08b9ad7
JL
2745/* What does this really do? Just determine if there is an appropriate
2746 mapping from ELF section headers to backend sections? More symbol
2747 extension braindamage. */
d9ad93bc
KR
2748
2749static boolean
f4bd7a8f
DM
2750elf32_hppa_backend_section_from_shdr (abfd, hdr, name)
2751 bfd *abfd;
2752 Elf32_Internal_Shdr *hdr;
2753 char *name;
d9ad93bc
KR
2754{
2755 asection *newsect;
2756
459ae909 2757 if (hdr->sh_type == SHT_PARISC_SYMEXTN)
d9ad93bc 2758 {
459ae909 2759 BFD_ASSERT (strcmp (name, ".PARISC.symextn") == 0);
d9ad93bc 2760
e08b9ad7 2761 /* Bits that get saved. This one is real. */
d9ad93bc
KR
2762 if (!hdr->rawdata)
2763 {
2764 newsect = bfd_make_section (abfd, name);
2765 if (newsect != NULL)
2766 {
2767 newsect->vma = hdr->sh_addr;
2768 newsect->_raw_size = hdr->sh_size;
e08b9ad7 2769 newsect->filepos = hdr->sh_offset;
d9ad93bc
KR
2770 newsect->flags |= SEC_HAS_CONTENTS;
2771 newsect->alignment_power = hdr->sh_addralign;
2772
2773 if (hdr->sh_flags & SHF_ALLOC)
2774 {
2775 newsect->flags |= SEC_ALLOC;
2776 newsect->flags |= SEC_LOAD;
2777 }
2778
2779 if (!(hdr->sh_flags & SHF_WRITE))
2780 newsect->flags |= SEC_READONLY;
2781
2782 if (hdr->sh_flags & SHF_EXECINSTR)
e08b9ad7 2783 newsect->flags |= SEC_CODE;
d9ad93bc
KR
2784 else
2785 newsect->flags |= SEC_DATA;
2786
2787 hdr->rawdata = (void *) newsect;
2788 }
2789 }
2790 return true;
2791 }
2792 return false;
2793}
2794
e08b9ad7 2795/* Return true if the given section is a fake section. */
d9ad93bc
KR
2796
2797static boolean
f4bd7a8f
DM
2798elf32_hppa_backend_fake_sections (abfd, secthdr, asect)
2799 bfd *abfd;
2800 Elf_Internal_Shdr *secthdr;
2801 asection *asect;
d9ad93bc
KR
2802{
2803
459ae909 2804 if (strcmp(asect->name, ".PARISC.symextn") == 0)
d9ad93bc 2805 {
459ae909 2806 secthdr->sh_type = SHT_PARISC_SYMEXTN;
d9ad93bc
KR
2807 secthdr->sh_flags = 0;
2808 secthdr->sh_info = elf_section_data(asect)->rel_hdr.sh_link;
2809 secthdr->sh_link = elf_onesymtab(abfd);
2810 return true;
2811 }
2812
459ae909 2813 if (!strcmp (asect->name, ".PARISC.unwind"))
d9ad93bc
KR
2814 {
2815 secthdr->sh_type = SHT_PROGBITS;
2816 /* Unwind descriptors are not part of the program memory image. */
2817 secthdr->sh_flags = 0;
2818 secthdr->sh_info = 0;
2819 secthdr->sh_link = 0;
2820 secthdr->sh_entsize = 16;
2821 return true;
2822 }
2823
7218bb04
KR
2824 /* @@ Should this be CPU specific?? KR */
2825 if (!strcmp (asect->name, ".stabstr"))
2826 {
2827 secthdr->sh_type = SHT_STRTAB;
2828 secthdr->sh_flags = 0;
2829 secthdr->sh_info = 0;
2830 secthdr->sh_link = 0;
2831 secthdr->sh_entsize = 0;
2832 return true;
2833 }
2834
d9ad93bc
KR
2835 return false;
2836}
2837
e08b9ad7
JL
2838/* Return true if there is a mapping from bfd section into a
2839 backend section. */
d9ad93bc
KR
2840
2841static boolean
e08b9ad7 2842elf32_hppa_backend_section_from_bfd_section (abfd, hdr, asect, ignored)
f4bd7a8f
DM
2843 bfd *abfd;
2844 Elf32_Internal_Shdr *hdr;
2845 asection *asect;
e08b9ad7 2846 int *ignored;
d9ad93bc 2847{
459ae909 2848 if (hdr->sh_type == SHT_PARISC_SYMEXTN)
d9ad93bc
KR
2849 {
2850 if (hdr->rawdata)
2851 {
2852 if (((struct sec *) (hdr->rawdata)) == asect)
2853 {
459ae909 2854 BFD_ASSERT (strcmp (asect->name, ".PARISC.symextn") == 0);
d9ad93bc
KR
2855 return true;
2856 }
2857 }
2858 }
f5bfdacd 2859 else if (hdr->sh_type == SHT_STRTAB)
7218bb04
KR
2860 {
2861 if (hdr->rawdata)
2862 {
2863 if (((struct sec *) (hdr->rawdata)) == asect)
2864 {
f5bfdacd 2865 BFD_ASSERT (strcmp (asect->name, ".stabstr") == 0);
7218bb04
KR
2866 return true;
2867 }
2868 }
2869 }
d9ad93bc
KR
2870
2871 return false;
8ddd7ab3 2872}
4c85cbfa 2873
f5bfdacd 2874#define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
d9ad93bc
KR
2875#define elf_backend_section_from_bfd_section elf32_hppa_backend_section_from_bfd_section
2876
e08b9ad7
JL
2877#define elf_backend_symbol_processing elf32_hppa_backend_symbol_processing
2878#define elf_backend_symbol_table_processing elf32_hppa_backend_symbol_table_processing
2879
6812b607 2880#define bfd_elf32_get_section_contents hppa_elf_get_section_contents
d9ad93bc 2881#define bfd_elf32_set_section_contents hppa_elf_set_section_contents
25057836 2882#define bfd_elf32_bfd_is_local_label hppa_elf_is_local_label
d9ad93bc 2883
e08b9ad7
JL
2884#define elf_backend_section_processing elf32_hppa_backend_section_processing
2885
2886#define elf_backend_section_from_shdr elf32_hppa_backend_section_from_shdr
2887#define elf_backend_fake_sections elf32_hppa_backend_fake_sections
459ae909
JL
2888#define elf_backend_begin_write_processing \
2889 elf32_hppa_backend_begin_write_processing
2890#define elf_backend_final_write_processing \
2891 elf32_hppa_backend_final_write_processing
e08b9ad7 2892
e8f2240a 2893#define TARGET_BIG_SYM bfd_elf32_hppa_vec
8ddd7ab3
KR
2894#define TARGET_BIG_NAME "elf32-hppa"
2895#define ELF_ARCH bfd_arch_hppa
459ae909 2896#define ELF_MACHINE_CODE EM_PARISC
3a70b01d 2897#define ELF_MAXPAGESIZE 0x1000
8ddd7ab3
KR
2898
2899#include "elf32-target.h"
This page took 0.223186 seconds and 4 git commands to generate.