* som.c (som_reloc_call): New function.
[deliverable/binutils-gdb.git] / bfd / som.c
1 /* bfd back-end for HP PA-RISC SOM objects.
2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3
4 Contributed by the Center for Software Science at the
5 University of Utah (pa-gdb-bugs@cs.utah.edu).
6
7 This file is part of BFD, the Binary File Descriptor library.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22
23 #include "bfd.h"
24 #include "sysdep.h"
25
26 #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD)
27
28 #include "libbfd.h"
29 #include "som.h"
30 #include "libhppa.h"
31
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/dir.h>
36 #include <signal.h>
37 #include <machine/reg.h>
38 #include <sys/user.h> /* After a.out.h */
39 #include <sys/file.h>
40 #include <errno.h>
41
42 /* Magic not defined in standard HP-UX header files until 8.0 */
43
44 #ifndef CPU_PA_RISC1_0
45 #define CPU_PA_RISC1_0 0x20B
46 #endif /* CPU_PA_RISC1_0 */
47
48 #ifndef CPU_PA_RISC1_1
49 #define CPU_PA_RISC1_1 0x210
50 #endif /* CPU_PA_RISC1_1 */
51
52 #ifndef _PA_RISC1_0_ID
53 #define _PA_RISC1_0_ID CPU_PA_RISC1_0
54 #endif /* _PA_RISC1_0_ID */
55
56 #ifndef _PA_RISC1_1_ID
57 #define _PA_RISC1_1_ID CPU_PA_RISC1_1
58 #endif /* _PA_RISC1_1_ID */
59
60 #ifndef _PA_RISC_MAXID
61 #define _PA_RISC_MAXID 0x2FF
62 #endif /* _PA_RISC_MAXID */
63
64 #ifndef _PA_RISC_ID
65 #define _PA_RISC_ID(__m_num) \
66 (((__m_num) == _PA_RISC1_0_ID) || \
67 ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
68 #endif /* _PA_RISC_ID */
69
70 /* SOM allows any one of the four previous relocations to be reused
71 with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
72 relocations are always a single byte, using a R_PREV_FIXUP instead
73 of some multi-byte relocation makes object files smaller.
74
75 Note one side effect of using a R_PREV_FIXUP is the relocation that
76 is being repeated moves to the front of the queue. */
77 struct reloc_queue
78 {
79 unsigned char *reloc;
80 unsigned int size;
81 } reloc_queue[4];
82
83 /* This fully describes the symbol types which may be attached to
84 an EXPORT or IMPORT directive. Only SOM uses this formation
85 (ELF has no need for it). */
86 typedef enum
87 {
88 SYMBOL_TYPE_UNKNOWN,
89 SYMBOL_TYPE_ABSOLUTE,
90 SYMBOL_TYPE_CODE,
91 SYMBOL_TYPE_DATA,
92 SYMBOL_TYPE_ENTRY,
93 SYMBOL_TYPE_MILLICODE,
94 SYMBOL_TYPE_PLABEL,
95 SYMBOL_TYPE_PRI_PROG,
96 SYMBOL_TYPE_SEC_PROG,
97 } pa_symbol_type;
98
99 /* Forward declarations */
100
101 static boolean som_mkobject PARAMS ((bfd *));
102 static bfd_target * som_object_setup PARAMS ((bfd *,
103 struct header *,
104 struct som_exec_auxhdr *));
105 static asection * make_unique_section PARAMS ((bfd *, CONST char *, int));
106 static boolean setup_sections PARAMS ((bfd *, struct header *));
107 static bfd_target * som_object_p PARAMS ((bfd *));
108 static boolean som_write_object_contents PARAMS ((bfd *));
109 static boolean som_slurp_string_table PARAMS ((bfd *));
110 static unsigned int som_slurp_symbol_table PARAMS ((bfd *));
111 static unsigned int som_get_symtab_upper_bound PARAMS ((bfd *));
112 static unsigned int som_canonicalize_reloc PARAMS ((bfd *, sec_ptr,
113 arelent **, asymbol **));
114 static unsigned int som_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
115 static unsigned int som_get_symtab PARAMS ((bfd *, asymbol **));
116 static asymbol * som_make_empty_symbol PARAMS ((bfd *));
117 static void som_print_symbol PARAMS ((bfd *, PTR,
118 asymbol *, bfd_print_symbol_type));
119 static boolean som_new_section_hook PARAMS ((bfd *, asection *));
120 static boolean som_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
121 file_ptr, bfd_size_type));
122 static boolean som_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
123 unsigned long));
124 static boolean som_find_nearest_line PARAMS ((bfd *, asection *,
125 asymbol **, bfd_vma,
126 CONST char **,
127 CONST char **,
128 unsigned int *));
129 static void som_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
130 static asection * som_section_from_subspace_index PARAMS ((bfd *,
131 unsigned int));
132 static int log2 PARAMS ((unsigned int));
133 static bfd_reloc_status_type hppa_som_reloc PARAMS ((bfd *, arelent *,
134 asymbol *, PTR,
135 asection *, bfd *));
136 static void som_initialize_reloc_queue PARAMS ((struct reloc_queue *));
137 static void som_reloc_queue_insert PARAMS ((unsigned char *, unsigned int,
138 struct reloc_queue *));
139 static void som_reloc_queue_fix PARAMS ((struct reloc_queue *, unsigned int));
140 static int som_reloc_queue_find PARAMS ((unsigned char *, unsigned int,
141 struct reloc_queue *));
142 static unsigned char * try_prev_fixup PARAMS ((bfd *, int *, unsigned char *,
143 unsigned int,
144 struct reloc_queue *));
145
146 static unsigned char * som_reloc_skip PARAMS ((bfd *, unsigned int,
147 unsigned char *, unsigned int *,
148 struct reloc_queue *));
149 static unsigned char * som_reloc_addend PARAMS ((bfd *, int, unsigned char *,
150 unsigned int *,
151 struct reloc_queue *));
152 static unsigned char * som_reloc_call PARAMS ((bfd *, unsigned char *,
153 unsigned int *,
154 arelent *, int,
155 struct reloc_queue *));
156 static unsigned long som_count_spaces PARAMS ((bfd *));
157 static unsigned long som_count_subspaces PARAMS ((bfd *));
158 static int compare_syms PARAMS ((asymbol **, asymbol **));
159 static unsigned long som_compute_checksum PARAMS ((bfd *));
160 static boolean som_prep_headers PARAMS ((bfd *));
161 static int som_sizeof_headers PARAMS ((bfd *, boolean));
162
163 static reloc_howto_type som_hppa_howto_table[] =
164 {
165 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
166 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
167 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
168 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
169 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
170 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
171 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
172 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
173 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
174 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
175 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
176 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
177 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
178 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
179 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
180 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
181 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
182 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
183 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
184 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
185 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
186 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
187 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
188 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
189 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
190 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
191 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
192 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
193 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
194 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
195 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
196 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
197 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
198 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
199 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
200 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
201 {R_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RELOCATION"},
202 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
203 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
204 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
205 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
206 {R_SPACE_REF, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_SPACE_REF"},
207 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
208 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
209 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
210 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
211 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
212 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
213 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
214 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
215 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
216 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
217 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
218 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
219 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
220 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
221 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
222 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
223 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
224 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
225 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
226 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
227 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
228 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
229 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
230 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
231 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
232 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
233 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
234 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
235 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
236 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
237 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
238 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
239 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
240 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
241 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
242 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
243 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
244 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
245 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
246 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
247 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
248 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
249 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
250 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
251 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
252 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
253 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
254 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
255 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
256 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
257 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
258 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
259 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
260 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
261 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
262 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
263 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
264 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
265 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
266 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
267 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
268 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
269 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
270 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
271 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
272 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
273 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
274 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
275 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
276 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
277 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
278 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
279 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
280 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
281 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
282 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
283 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
284 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
285 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
286 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
287 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
288 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
289 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
290 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
291 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
292 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
293 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
294 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
295 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
296 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
297 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
298 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
299 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
300 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
301 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
302 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
303 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
304 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
305 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
306 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
307 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
308 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
309 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
310 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
311 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
312 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
313 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
314 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
315 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
316 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
317 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
318 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
319 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
320 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
321 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
322 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
323 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
324 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
325 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
326 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
327 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
328 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
329 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
330 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
331 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
332 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
333 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
334 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
335 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
336 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
337 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
338 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
339 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
340 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
341 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
342 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
343 {R_BREAKPOINT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BREAKPOINT"},
344 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
345 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
346 {R_ALT_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ALT_ENTRY"},
347 {R_EXIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_EXIT"},
348 {R_BEGIN_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_TRY"},
349 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
350 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
351 {R_BEGIN_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_BRTAB"},
352 {R_END_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_BRTAB"},
353 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
354 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
355 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
356 {R_DATA_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_EXPR"},
357 {R_CODE_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_EXPR"},
358 {R_FSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_FSEL"},
359 {R_LSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LSEL"},
360 {R_RSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RSEL"},
361 {R_N_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_N_MODE"},
362 {R_S_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_S_MODE"},
363 {R_D_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_D_MODE"},
364 {R_R_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_R_MODE"},
365 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
366 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
367 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
368 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
369 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
370 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
371 {R_TRANSLATED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_TRANSLATED"},
372 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
373 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
374 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
375 {R_COMP1, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP1"},
376 {R_COMP2, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP2"},
377 {R_COMP3, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP3"},
378 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
379 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
380 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
381 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
382 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
383 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
384 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
385 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
386 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
387 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
388 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
389 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
390 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
391 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
392 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
393 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
394 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
395 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
396 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
397 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
398 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
399 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
400 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
401 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
402 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
403 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
404 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
405 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
406 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
407 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
408 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
409 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
410 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
411 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
412 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
413 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
414 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
415 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
416 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
417 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
418 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
419 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
420 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
421 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
422 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"}};
423
424
425 /* Initialize the SOM relocation queue. By definition the queue holds
426 the last four multibyte fixups. */
427
428 static void
429 som_initialize_reloc_queue (queue)
430 struct reloc_queue *queue;
431 {
432 queue[0].reloc = NULL;
433 queue[0].size = 0;
434 queue[1].reloc = NULL;
435 queue[1].size = 0;
436 queue[2].reloc = NULL;
437 queue[2].size = 0;
438 queue[3].reloc = NULL;
439 queue[3].size = 0;
440 }
441
442 /* Insert a new relocation into the relocation queue. */
443
444 static void
445 som_reloc_queue_insert (p, size, queue)
446 unsigned char *p;
447 unsigned int size;
448 struct reloc_queue *queue;
449 {
450 queue[3].reloc = queue[2].reloc;
451 queue[3].size = queue[2].size;
452 queue[2].reloc = queue[1].reloc;
453 queue[2].size = queue[1].size;
454 queue[1].reloc = queue[0].reloc;
455 queue[1].size = queue[0].size;
456 queue[0].reloc = p;
457 queue[0].size = size;
458 }
459
460 /* When an entry in the relocation queue is reused, the entry moves
461 to the front of the queue. */
462
463 static void
464 som_reloc_queue_fix (queue, index)
465 struct reloc_queue *queue;
466 unsigned int index;
467 {
468 if (index == 0)
469 return;
470
471 if (index == 1)
472 {
473 unsigned char *tmp1 = queue[0].reloc;
474 unsigned int tmp2 = queue[0].size;
475 queue[0].reloc = queue[1].reloc;
476 queue[0].size = queue[1].size;
477 queue[1].reloc = tmp1;
478 queue[1].size = tmp2;
479 return;
480 }
481
482 if (index == 2)
483 {
484 unsigned char *tmp1 = queue[0].reloc;
485 unsigned int tmp2 = queue[0].size;
486 queue[0].reloc = queue[2].reloc;
487 queue[0].size = queue[2].size;
488 queue[2].reloc = queue[1].reloc;
489 queue[2].size = queue[1].size;
490 queue[1].reloc = tmp1;
491 queue[1].size = tmp2;
492 return;
493 }
494
495 if (index == 3)
496 {
497 unsigned char *tmp1 = queue[0].reloc;
498 unsigned int tmp2 = queue[0].size;
499 queue[0].reloc = queue[3].reloc;
500 queue[0].size = queue[3].size;
501 queue[3].reloc = queue[2].reloc;
502 queue[3].size = queue[2].size;
503 queue[2].reloc = queue[1].reloc;
504 queue[2].size = queue[1].size;
505 queue[1].reloc = tmp1;
506 queue[1].size = tmp2;
507 return;
508 }
509 abort();
510 }
511
512 /* Search for a particular relocation in the relocation queue. */
513
514 static int
515 som_reloc_queue_find (p, size, queue)
516 unsigned char *p;
517 unsigned int size;
518 struct reloc_queue *queue;
519 {
520 if (!bcmp (p, queue[0].reloc, size)
521 && size == queue[0].size)
522 return 0;
523 if (!bcmp (p, queue[1].reloc, size)
524 && size == queue[1].size)
525 return 1;
526 if (!bcmp (p, queue[2].reloc, size)
527 && size == queue[2].size)
528 return 2;
529 if (!bcmp (p, queue[3].reloc, size)
530 && size == queue[3].size)
531 return 3;
532 return -1;
533 }
534
535 static unsigned char *
536 try_prev_fixup (abfd, subspace_reloc_sizep, p, size, queue)
537 bfd *abfd;
538 int *subspace_reloc_sizep;
539 unsigned char *p;
540 unsigned int size;
541 struct reloc_queue *queue;
542 {
543 int queue_index = som_reloc_queue_find (p, size, queue);
544
545 if (queue_index != -1)
546 {
547 /* Found this in a previous fixup. Undo the fixup we
548 just built and use R_PREV_FIXUP instead. We saved
549 a total of size - 1 bytes in the fixup stream. */
550 bfd_put_8 (abfd, R_PREV_FIXUP + queue_index, p);
551 p += 1;
552 *subspace_reloc_sizep += 1;
553 som_reloc_queue_fix (queue, queue_index);
554 }
555 else
556 {
557 som_reloc_queue_insert (p, size, queue);
558 *subspace_reloc_sizep += size;
559 p += size;
560 }
561 return p;
562 }
563
564 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
565 bytes without any relocation. Update the size of the subspace
566 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
567 current pointer into the relocation stream. */
568
569 static unsigned char *
570 som_reloc_skip (abfd, skip, p, subspace_reloc_sizep, queue)
571 bfd *abfd;
572 unsigned int skip;
573 unsigned char *p;
574 unsigned int *subspace_reloc_sizep;
575 struct reloc_queue *queue;
576 {
577 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
578 then R_PREV_FIXUPs to get the difference down to a
579 reasonable size. */
580 if (skip >= 0x1000000)
581 {
582 skip -= 0x1000000;
583 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
584 bfd_put_8 (abfd, 0xff, p + 1);
585 bfd_put_16 (abfd, 0xffff, p + 2);
586 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
587 while (skip >= 0x1000000)
588 {
589 skip -= 0x1000000;
590 bfd_put_8 (abfd, R_PREV_FIXUP, p);
591 p++;
592 *subspace_reloc_sizep += 1;
593 /* No need to adjust queue here since we are repeating the
594 most recent fixup. */
595 }
596 }
597
598 /* The difference must be less than 0x1000000. Use one
599 more R_NO_RELOCATION entry to get to the right difference. */
600 if ((skip & 3) == 0 && skip <= 0xc0000 && skip > 0)
601 {
602 /* Difference can be handled in a simple single-byte
603 R_NO_RELOCATION entry. */
604 if (skip <= 0x60)
605 {
606 bfd_put_8 (abfd, R_NO_RELOCATION + (skip >> 2) - 1, p);
607 *subspace_reloc_sizep += 1;
608 p++;
609 }
610 /* Handle it with a two byte R_NO_RELOCATION entry. */
611 else if (skip <= 0x1000)
612 {
613 bfd_put_8 (abfd, R_NO_RELOCATION + 24 + (((skip >> 2) - 1) >> 8), p);
614 bfd_put_8 (abfd, (skip >> 2) - 1, p + 1);
615 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
616 }
617 /* Handle it with a three byte R_NO_RELOCATION entry. */
618 else
619 {
620 bfd_put_8 (abfd, R_NO_RELOCATION + 28 + (((skip >> 2) - 1) >> 16), p);
621 bfd_put_16 (abfd, (skip >> 2) - 1, p + 1);
622 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
623 }
624 }
625 /* Ugh. Punt and use a 4 byte entry. */
626 else if (skip > 0)
627 {
628 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
629 bfd_put_8 (abfd, skip >> 16, p + 1);
630 bfd_put_16 (abfd, skip, p + 2);
631 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
632 }
633 return p;
634 }
635
636 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
637 from a BFD relocation. Update the size of the subspace relocation
638 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
639 into the relocation stream. */
640
641 static unsigned char *
642 som_reloc_addend (abfd, addend, p, subspace_reloc_sizep, queue)
643 bfd *abfd;
644 int addend;
645 unsigned char *p;
646 unsigned int *subspace_reloc_sizep;
647 struct reloc_queue *queue;
648 {
649 if ((unsigned)(addend) + 0x80 < 0x100)
650 {
651 bfd_put_8 (abfd, R_DATA_OVERRIDE + 1, p);
652 bfd_put_8 (abfd, addend, p + 1);
653 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
654 }
655 else if ((unsigned) (addend) + 0x8000 < 0x10000)
656 {
657 bfd_put_8 (abfd, R_DATA_OVERRIDE + 2, p);
658 bfd_put_16 (abfd, addend, p + 1);
659 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
660 }
661 else if ((unsigned) (addend) + 0x800000 < 0x1000000)
662 {
663 bfd_put_8 (abfd, R_DATA_OVERRIDE + 3, p);
664 bfd_put_8 (abfd, addend >> 16, p + 1);
665 bfd_put_16 (abfd, addend, p + 2);
666 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
667 }
668 else
669 {
670 bfd_put_8 (abfd, R_DATA_OVERRIDE + 4, p);
671 bfd_put_32 (abfd, addend, p + 1);
672 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
673 }
674 return p;
675 }
676
677 /* Handle a single function call relocation. */
678
679 static unsigned char *
680 som_reloc_call (abfd, p, subspace_reloc_sizep, bfd_reloc, sym_num, queue)
681 bfd *abfd;
682 unsigned char *p;
683 unsigned int *subspace_reloc_sizep;
684 arelent *bfd_reloc;
685 int sym_num;
686 struct reloc_queue *queue;
687 {
688 int arg_bits = HPPA_R_ARG_RELOC (bfd_reloc->addend);
689 int rtn_bits = arg_bits & 0x3;
690 int type, done = 0;
691
692 /* You'll never believe all this is necessary to handle relocations
693 for function calls. Having to compute and pack the argument
694 relocation bits is the real nightmare.
695
696 If you're interested in how this works, just forget it. You really
697 do not want to know about this braindamage. */
698
699 /* First see if this can be done with a "simple" relocation. Simple
700 relocations have a symbol number < 0x100 and have simple encodings
701 of argument relocations. */
702
703 if (sym_num < 0x100)
704 {
705 switch (arg_bits)
706 {
707 case 0:
708 case 1:
709 type = 0;
710 break;
711 case 1 << 8:
712 case 1 << 8 | 1:
713 type = 1;
714 break;
715 case 1 << 8 | 1 << 6:
716 case 1 << 8 | 1 << 6 | 1:
717 type = 2;
718 break;
719 case 1 << 8 | 1 << 6 | 1 << 4:
720 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
721 type = 3;
722 break;
723 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
724 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
725 type = 4;
726 break;
727 default:
728 /* Not one of the easy encodings. This will have to be
729 handled by the more complex code below. */
730 type = -1;
731 break;
732 }
733 if (type != -1)
734 {
735 /* Account for the return value too. */
736 if (rtn_bits)
737 type += 5;
738
739 /* Emit a 2 byte relocation. Then see if it can be handled
740 with a relocation which is already in the relocation queue. */
741 bfd_put_8 (abfd, bfd_reloc->howto->type + type, p);
742 bfd_put_8 (abfd, sym_num, p + 1);
743 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
744 done = 1;
745 }
746 }
747
748 /* If this could not be handled with a simple relocation, then do a hard
749 one. Hard relocations occur if the symbol number was too high or if
750 the encoding of argument relocation bits is too complex. */
751 if (! done)
752 {
753 /* Don't ask about these magic sequences. I took them straight
754 from gas-1.36 which took them from the a.out man page. */
755 type = rtn_bits;
756 if ((arg_bits >> 6 & 0xf) == 0xe)
757 type += 9 * 40;
758 else
759 type += (3 * (arg_bits >> 8 & 3) + (arg_bits >> 6 & 3)) * 40;
760 if ((arg_bits >> 2 & 0xf) == 0xe)
761 type += 9 * 4;
762 else
763 type += (3 * (arg_bits >> 4 & 3) + (arg_bits >> 2 & 3)) * 4;
764
765 /* Output the first two bytes of the relocation. These describe
766 the length of the relocation and encoding style. */
767 bfd_put_8 (abfd, bfd_reloc->howto->type + 10
768 + 2 * (sym_num >= 0x100) + (type >= 0x100),
769 p);
770 bfd_put_8 (abfd, type, p + 1);
771
772 /* Now output the symbol index and see if this bizarre relocation
773 just happened to be in the relocation queue. */
774 if (sym_num < 0x100)
775 {
776 bfd_put_8 (abfd, sym_num, p + 2);
777 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
778 }
779 else
780 {
781 bfd_put_8 (abfd, sym_num >> 16, p + 2);
782 bfd_put_16 (abfd, sym_num, p + 3);
783 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
784 }
785 }
786 return p;
787 }
788
789
790 /* Return the logarithm of X, base 2, considering X unsigned.
791 Abort if X is not a power of two -- this should never happen (FIXME:
792 It will happen on corrupt executables. GDB should give an error, not
793 a coredump, in that case). */
794
795 static int
796 log2 (x)
797 unsigned int x;
798 {
799 int log = 0;
800
801 /* Test for 0 or a power of 2. */
802 if (x == 0 || x != (x & -x))
803 abort();
804
805 while ((x >>= 1) != 0)
806 log++;
807 return log;
808 }
809
810 static bfd_reloc_status_type
811 hppa_som_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd)
812 bfd *abfd;
813 arelent *reloc_entry;
814 asymbol *symbol_in;
815 PTR data;
816 asection *input_section;
817 bfd *output_bfd;
818 {
819 if (output_bfd)
820 {
821 reloc_entry->address += input_section->output_offset;
822 return bfd_reloc_ok;
823 }
824 return bfd_reloc_ok;
825 }
826
827 /* Given a generic HPPA relocation type, the instruction format,
828 and a field selector, return an appropriate SOM reloation.
829
830 FIXME. Need to handle %RR, %LR and the like as field selectors.
831 These will need to generate multiple SOM relocations. */
832
833 int **
834 hppa_som_gen_reloc_type (abfd, base_type, format, field)
835 bfd *abfd;
836 int base_type;
837 int format;
838 int field;
839 {
840 int *final_type, **final_types;
841
842 final_types = (int **) bfd_alloc_by_size_t (abfd, sizeof (int *) * 2);
843 final_type = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
844
845
846 final_types[0] = final_type;
847 final_types[1] = NULL;
848
849 /* Default to the basic relocation passed in. */
850 *final_type = base_type;
851
852 switch (base_type)
853 {
854 case R_HPPA:
855 /* PLABELs get their own relocation type. */
856 if (field == e_psel
857 || field == e_lpsel
858 || field == e_rpsel)
859 {
860 /* A PLABEL relocation that has a size of 32 bits must
861 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
862 if (format == 32)
863 *final_type = R_DATA_PLABEL;
864 else
865 *final_type = R_CODE_PLABEL;
866 }
867 /* A relocatoin in the data space is always a full 32bits. */
868 else if (format == 32)
869 *final_type = R_DATA_ONE_SYMBOL;
870
871 break;
872
873 case R_HPPA_GOTOFF:
874 /* More PLABEL special cases. */
875 if (field == e_psel
876 || field == e_lpsel
877 || field == e_rpsel)
878 *final_type = R_DATA_PLABEL;
879 break;
880
881 case R_HPPA_NONE:
882 case R_HPPA_ABS_CALL:
883 case R_HPPA_PCREL_CALL:
884 case R_HPPA_COMPLEX:
885 case R_HPPA_COMPLEX_PCREL_CALL:
886 case R_HPPA_COMPLEX_ABS_CALL:
887 /* Right now we can default all these. */
888 break;
889 }
890 return final_types;
891 }
892
893 /* Return the address of the correct entry in the PA SOM relocation
894 howto table. */
895
896 static reloc_howto_type *
897 som_bfd_reloc_type_lookup (arch, code)
898 bfd_arch_info_type *arch;
899 bfd_reloc_code_real_type code;
900 {
901 if ((int) code < (int) R_NO_RELOCATION + 255)
902 {
903 BFD_ASSERT ((int) som_hppa_howto_table[(int) code].type == (int) code);
904 return &som_hppa_howto_table[(int) code];
905 }
906
907 return (reloc_howto_type *) 0;
908 }
909
910 /* Perform some initialization for an object. Save results of this
911 initialization in the BFD. */
912
913 static bfd_target *
914 som_object_setup (abfd, file_hdrp, aux_hdrp)
915 bfd *abfd;
916 struct header *file_hdrp;
917 struct som_exec_auxhdr *aux_hdrp;
918 {
919 asection *text, *data, *bss;
920
921 /* som_mkobject will set bfd_error if som_mkobject fails. */
922 if (som_mkobject (abfd) != true)
923 return 0;
924
925 /* Make the standard .text, .data, and .bss sections so that tools
926 which assume those names work (size for example). They will have
927 no contents, but the sizes and such will reflect those of the
928 $CODE$, $DATA$, and $BSS$ subspaces respectively.
929
930 FIXME: Should check return status from bfd_make_section calls below. */
931
932 text = bfd_make_section (abfd, ".text");
933 data = bfd_make_section (abfd, ".data");
934 bss = bfd_make_section (abfd, ".bss");
935
936 text->_raw_size = aux_hdrp->exec_tsize;
937 data->_raw_size = aux_hdrp->exec_dsize;
938 bss->_raw_size = aux_hdrp->exec_bsize;
939
940 text->flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_CODE);
941 data->flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS);
942 bss->flags = (SEC_ALLOC | SEC_IS_COMMON);
943
944 /* The virtual memory addresses of the sections */
945 text->vma = aux_hdrp->exec_tmem;
946 data->vma = aux_hdrp->exec_dmem;
947 bss->vma = aux_hdrp->exec_bfill;
948
949 /* The file offsets of the sections */
950 text->filepos = aux_hdrp->exec_tfile;
951 data->filepos = aux_hdrp->exec_dfile;
952
953 /* The file offsets of the relocation info */
954 text->rel_filepos = 0;
955 data->rel_filepos = 0;
956
957 /* Set BFD flags based on what information is available in the SOM. */
958 abfd->flags = NO_FLAGS;
959 if (! file_hdrp->entry_offset)
960 abfd->flags |= HAS_RELOC;
961 else
962 abfd->flags |= EXEC_P;
963 if (file_hdrp->symbol_total)
964 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
965
966 bfd_get_start_address (abfd) = aux_hdrp->exec_entry;
967 bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 0);
968 bfd_get_symcount (abfd) = file_hdrp->symbol_total;
969
970 /* Initialize the saved symbol table and string table to NULL.
971 Save important offsets and sizes from the SOM header into
972 the BFD. */
973 obj_som_stringtab (abfd) = (char *) NULL;
974 obj_som_symtab (abfd) = (som_symbol_type *) NULL;
975 obj_som_stringtab_size (abfd) = file_hdrp->symbol_strings_size;
976 obj_som_sym_filepos (abfd) = file_hdrp->symbol_location;
977 obj_som_str_filepos (abfd) = file_hdrp->symbol_strings_location;
978 obj_som_reloc_filepos (abfd) = file_hdrp->fixup_request_location;
979
980 return abfd->xvec;
981 }
982
983 /* Create a new BFD section for NAME. If NAME already exists, then create a
984 new unique name, with NAME as the prefix. This exists because SOM .o files
985 may have more than one $CODE$ subspace. */
986
987 static asection *
988 make_unique_section (abfd, name, num)
989 bfd *abfd;
990 CONST char *name;
991 int num;
992 {
993 asection *sect;
994 char *newname;
995 char altname[100];
996
997 sect = bfd_make_section (abfd, name);
998 while (!sect)
999 {
1000 sprintf (altname, "%s-%d", name, num++);
1001 sect = bfd_make_section (abfd, altname);
1002 }
1003
1004 newname = bfd_alloc (abfd, strlen (sect->name) + 1);
1005 strcpy (newname, sect->name);
1006
1007 sect->name = newname;
1008 return sect;
1009 }
1010
1011 /* Convert all of the space and subspace info into BFD sections. Each space
1012 contains a number of subspaces, which in turn describe the mapping between
1013 regions of the exec file, and the address space that the program runs in.
1014 BFD sections which correspond to spaces will overlap the sections for the
1015 associated subspaces. */
1016
1017 static boolean
1018 setup_sections (abfd, file_hdr)
1019 bfd *abfd;
1020 struct header *file_hdr;
1021 {
1022 char *space_strings;
1023 int space_index;
1024 unsigned int total_subspaces = 0;
1025
1026 /* First, read in space names */
1027
1028 space_strings = alloca (file_hdr->space_strings_size);
1029 if (!space_strings)
1030 return false;
1031
1032 if (bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET) < 0)
1033 return false;
1034 if (bfd_read (space_strings, 1, file_hdr->space_strings_size, abfd)
1035 != file_hdr->space_strings_size)
1036 return false;
1037
1038 /* Loop over all of the space dictionaries, building up sections */
1039 for (space_index = 0; space_index < file_hdr->space_total; space_index++)
1040 {
1041 struct space_dictionary_record space;
1042 struct subspace_dictionary_record subspace, save_subspace;
1043 int subspace_index;
1044 asection *space_asect;
1045
1046 /* Read the space dictionary element */
1047 if (bfd_seek (abfd, file_hdr->space_location
1048 + space_index * sizeof space, SEEK_SET) < 0)
1049 return false;
1050 if (bfd_read (&space, 1, sizeof space, abfd) != sizeof space)
1051 return false;
1052
1053 /* Setup the space name string */
1054 space.name.n_name = space.name.n_strx + space_strings;
1055
1056 /* Make a section out of it */
1057 space_asect = make_unique_section (abfd, space.name.n_name, space_index);
1058 if (!space_asect)
1059 return false;
1060
1061 /* Now, read in the first subspace for this space */
1062 if (bfd_seek (abfd, file_hdr->subspace_location
1063 + space.subspace_index * sizeof subspace,
1064 SEEK_SET) < 0)
1065 return false;
1066 if (bfd_read (&subspace, 1, sizeof subspace, abfd) != sizeof subspace)
1067 return false;
1068 /* Seek back to the start of the subspaces for loop below */
1069 if (bfd_seek (abfd, file_hdr->subspace_location
1070 + space.subspace_index * sizeof subspace,
1071 SEEK_SET) < 0)
1072 return false;
1073
1074 /* Setup the start address and file loc from the first subspace record */
1075 space_asect->vma = subspace.subspace_start;
1076 space_asect->filepos = subspace.file_loc_init_value;
1077 space_asect->alignment_power = log2 (subspace.alignment);
1078
1079 /* Initialize save_subspace so we can reliably determine if this
1080 loop placed any useful values into it. */
1081 bzero (&save_subspace, sizeof (struct subspace_dictionary_record));
1082
1083 /* Loop over the rest of the subspaces, building up more sections */
1084 for (subspace_index = 0; subspace_index < space.subspace_quantity;
1085 subspace_index++)
1086 {
1087 asection *subspace_asect;
1088
1089 /* Read in the next subspace */
1090 if (bfd_read (&subspace, 1, sizeof subspace, abfd)
1091 != sizeof subspace)
1092 return false;
1093
1094 /* Setup the subspace name string */
1095 subspace.name.n_name = subspace.name.n_strx + space_strings;
1096
1097 /* Make a section out of this subspace */
1098 subspace_asect = make_unique_section (abfd, subspace.name.n_name,
1099 space.subspace_index + subspace_index);
1100
1101 if (!subspace_asect)
1102 return false;
1103
1104 /* Keep an easy mapping between subspaces and sections. */
1105 som_section_data (subspace_asect)->subspace_index
1106 = total_subspaces++;
1107
1108 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
1109 by the access_control_bits in the subspace header. */
1110 switch (subspace.access_control_bits >> 4)
1111 {
1112 /* Readonly data. */
1113 case 0x0:
1114 subspace_asect->flags |= SEC_DATA | SEC_READONLY;
1115 break;
1116
1117 /* Normal data. */
1118 case 0x1:
1119 subspace_asect->flags |= SEC_DATA;
1120 break;
1121
1122 /* Readonly code and the gateways.
1123 Gateways have other attributes which do not map
1124 into anything BFD knows about. */
1125 case 0x2:
1126 case 0x4:
1127 case 0x5:
1128 case 0x6:
1129 case 0x7:
1130 subspace_asect->flags |= SEC_CODE | SEC_READONLY;
1131 break;
1132
1133 /* dynamic (writable) code. */
1134 case 0x3:
1135 subspace_asect->flags |= SEC_CODE;
1136 break;
1137 }
1138
1139 if (subspace.dup_common || subspace.is_common)
1140 subspace_asect->flags |= SEC_IS_COMMON;
1141 else
1142 subspace_asect->flags |= SEC_HAS_CONTENTS;
1143 if (subspace.is_loadable)
1144 subspace_asect->flags |= SEC_ALLOC | SEC_LOAD;
1145 if (subspace.code_only)
1146 subspace_asect->flags |= SEC_CODE;
1147
1148 /* This subspace has relocations.
1149 The fixup_request_quantity is a byte count for the number of
1150 entries in the relocation stream; it is not the actual number
1151 of relocations in the subspace. */
1152 if (subspace.fixup_request_quantity != 0)
1153 {
1154 subspace_asect->flags |= SEC_RELOC;
1155 subspace_asect->rel_filepos = subspace.fixup_request_index;
1156 som_section_data (subspace_asect)->reloc_size
1157 = subspace.fixup_request_quantity;
1158 /* We can not determine this yet. When we read in the
1159 relocation table the correct value will be filled in. */
1160 subspace_asect->reloc_count = -1;
1161 }
1162
1163 /* Update save_subspace if appropriate. */
1164 if (subspace.file_loc_init_value > save_subspace.file_loc_init_value)
1165 save_subspace = subspace;
1166
1167 subspace_asect->vma = subspace.subspace_start;
1168 subspace_asect->_cooked_size = subspace.subspace_length;
1169 subspace_asect->_raw_size = subspace.initialization_length;
1170 subspace_asect->alignment_power = log2 (subspace.alignment);
1171 subspace_asect->filepos = subspace.file_loc_init_value;
1172 }
1173
1174 /* Yow! there is no subspace within the space which actually
1175 has initialized information in it; this should never happen
1176 as far as I know. */
1177 if (!save_subspace.file_loc_init_value)
1178 abort ();
1179
1180 /* Setup the sizes for the space section based upon the info in the
1181 last subspace of the space. */
1182 space_asect->_cooked_size = save_subspace.subspace_start
1183 - space_asect->vma + save_subspace.subspace_length;
1184 space_asect->_raw_size = save_subspace.file_loc_init_value
1185 - space_asect->filepos + save_subspace.initialization_length;
1186 }
1187 return true;
1188 }
1189
1190 /* Read in a SOM object and make it into a BFD. */
1191
1192 static bfd_target *
1193 som_object_p (abfd)
1194 bfd *abfd;
1195 {
1196 struct header file_hdr;
1197 struct som_exec_auxhdr aux_hdr;
1198
1199 if (bfd_read ((PTR) & file_hdr, 1, FILE_HDR_SIZE, abfd) != FILE_HDR_SIZE)
1200 {
1201 bfd_error = system_call_error;
1202 return 0;
1203 }
1204
1205 if (!_PA_RISC_ID (file_hdr.system_id))
1206 {
1207 bfd_error = wrong_format;
1208 return 0;
1209 }
1210
1211 switch (file_hdr.a_magic)
1212 {
1213 case RELOC_MAGIC:
1214 case EXEC_MAGIC:
1215 case SHARE_MAGIC:
1216 case DEMAND_MAGIC:
1217 #ifdef DL_MAGIC
1218 case DL_MAGIC:
1219 #endif
1220 #ifdef SHL_MAGIC
1221 case SHL_MAGIC:
1222 #endif
1223 #ifdef EXECLIBMAGIC
1224 case EXECLIBMAGIC:
1225 #endif
1226 break;
1227 default:
1228 bfd_error = wrong_format;
1229 return 0;
1230 }
1231
1232 if (file_hdr.version_id != VERSION_ID
1233 && file_hdr.version_id != NEW_VERSION_ID)
1234 {
1235 bfd_error = wrong_format;
1236 return 0;
1237 }
1238
1239 /* If the aux_header_size field in the file header is zero, then this
1240 object is an incomplete executable (a .o file). Do not try to read
1241 a non-existant auxiliary header. */
1242 bzero (&aux_hdr, sizeof (struct som_exec_auxhdr));
1243 if (file_hdr.aux_header_size != 0)
1244 {
1245 if (bfd_read ((PTR) & aux_hdr, 1, AUX_HDR_SIZE, abfd) != AUX_HDR_SIZE)
1246 {
1247 bfd_error = wrong_format;
1248 return 0;
1249 }
1250 }
1251
1252 if (!setup_sections (abfd, &file_hdr))
1253 {
1254 /* setup_sections does not bubble up a bfd error code. */
1255 bfd_error = bad_value;
1256 return 0;
1257 }
1258
1259 /* This appears to be a valid SOM object. Do some initialization. */
1260 return som_object_setup (abfd, &file_hdr, &aux_hdr);
1261 }
1262
1263 /* Create a SOM object. */
1264
1265 static boolean
1266 som_mkobject (abfd)
1267 bfd *abfd;
1268 {
1269 /* Allocate memory to hold backend information. */
1270 abfd->tdata.som_data = (struct som_data_struct *)
1271 bfd_zalloc (abfd, sizeof (struct som_data_struct));
1272 if (abfd->tdata.som_data == NULL)
1273 {
1274 bfd_error = no_memory;
1275 return false;
1276 }
1277 obj_som_file_hdr (abfd) = bfd_zalloc (abfd, sizeof (struct header));
1278 if (obj_som_file_hdr (abfd) == NULL)
1279
1280 {
1281 bfd_error = no_memory;
1282 return false;
1283 }
1284 return true;
1285 }
1286
1287 /* Initialize some information in the file header. This routine makes
1288 not attempt at doing the right thing for a full executable; it
1289 is only meant to handle relocatable objects. */
1290
1291 static boolean
1292 som_prep_headers (abfd)
1293 bfd *abfd;
1294 {
1295 struct header *file_hdr = obj_som_file_hdr (abfd);
1296 asection *section;
1297
1298 /* FIXME. This should really be conditional based on whether or not
1299 PA1.1 instructions/registers have been used. */
1300 file_hdr->system_id = HP9000S800_ID;
1301
1302 /* FIXME. Only correct for building relocatable objects. */
1303 if (abfd->flags & EXEC_P)
1304 abort ();
1305 else
1306 file_hdr->a_magic = RELOC_MAGIC;
1307
1308 /* Only new format SOM is supported. */
1309 file_hdr->version_id = NEW_VERSION_ID;
1310
1311 /* These fields are optional, and embedding timestamps is not always
1312 a wise thing to do, it makes comparing objects during a multi-stage
1313 bootstrap difficult. */
1314 file_hdr->file_time.secs = 0;
1315 file_hdr->file_time.nanosecs = 0;
1316
1317 if (abfd->flags & EXEC_P)
1318 abort ();
1319 else
1320 {
1321 file_hdr->entry_space = 0;
1322 file_hdr->entry_subspace = 0;
1323 file_hdr->entry_offset = 0;
1324 }
1325
1326 /* FIXME. I do not know if we ever need to put anything other
1327 than zero in this field. */
1328 file_hdr->presumed_dp = 0;
1329
1330 /* Now iterate over the sections translating information from
1331 BFD sections to SOM spaces/subspaces. */
1332
1333 for (section = abfd->sections; section != NULL; section = section->next)
1334 {
1335 /* Ignore anything which has not been marked as a space or
1336 subspace. */
1337 if (som_section_data (section)->is_space == 0
1338
1339 && som_section_data (section)->is_subspace == 0)
1340 continue;
1341
1342 if (som_section_data (section)->is_space)
1343 {
1344 /* Set space attributes. Note most attributes of SOM spaces
1345 are set based on the subspaces it contains. */
1346 som_section_data (section)->space_dict.loader_fix_index = -1;
1347 som_section_data (section)->space_dict.init_pointer_index = -1;
1348 }
1349 else
1350 {
1351 /* Set subspace attributes. Basic stuff is done here, additional
1352 attributes are filled in later as more information becomes
1353 available. */
1354 if (section->flags & SEC_IS_COMMON)
1355 {
1356 som_section_data (section)->subspace_dict.dup_common = 1;
1357 som_section_data (section)->subspace_dict.is_common = 1;
1358 }
1359
1360 if (section->flags & SEC_ALLOC)
1361 som_section_data (section)->subspace_dict.is_loadable = 1;
1362
1363 if (section->flags & SEC_CODE)
1364 som_section_data (section)->subspace_dict.code_only = 1;
1365
1366 som_section_data (section)->subspace_dict.subspace_start =
1367 section->vma;
1368 som_section_data (section)->subspace_dict.subspace_length =
1369 bfd_section_size (abfd, section);
1370 som_section_data (section)->subspace_dict.initialization_length =
1371 bfd_section_size (abfd, section);
1372 som_section_data (section)->subspace_dict.alignment =
1373 1 << section->alignment_power;
1374 }
1375 }
1376 return true;
1377 }
1378
1379 /* Count and return the number of spaces attached to the given BFD. */
1380
1381 static unsigned long
1382 som_count_spaces (abfd)
1383 bfd *abfd;
1384 {
1385 int count = 0;
1386 asection *section;
1387
1388 for (section = abfd->sections; section != NULL; section = section->next)
1389 count += som_section_data (section)->is_space;
1390
1391 return count;
1392 }
1393
1394 /* Count the number of subspaces attached to the given BFD. */
1395
1396 static unsigned long
1397 som_count_subspaces (abfd)
1398 bfd *abfd;
1399 {
1400 int count = 0;
1401 asection *section;
1402
1403 for (section = abfd->sections; section != NULL; section = section->next)
1404 count += som_section_data (section)->is_subspace;
1405
1406 return count;
1407 }
1408
1409 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
1410
1411 We desire symbols to be ordered starting with the symbol with the
1412 highest relocation count down to the symbol with the lowest relocation
1413 count. Doing so compacts the relocation stream. */
1414
1415 static int
1416 compare_syms (sym1, sym2)
1417 asymbol **sym1;
1418 asymbol **sym2;
1419
1420 {
1421 unsigned int count1, count2;
1422
1423 /* Get relocation count for each symbol. Note that the count
1424 is stored in the udata pointer for section symbols! */
1425 if ((*sym1)->flags & BSF_SECTION_SYM)
1426 count1 = (int)(*sym1)->udata;
1427 else
1428 count1 = (*som_symbol_data ((*sym1)))->reloc_count;
1429
1430 if ((*sym2)->flags & BSF_SECTION_SYM)
1431 count2 = (int)(*sym2)->udata;
1432 else
1433 count2 = (*som_symbol_data ((*sym2)))->reloc_count;
1434
1435 /* Return the appropriate value. */
1436 if (count1 < count2)
1437 return 1;
1438 else if (count1 > count2)
1439 return -1;
1440 return 0;
1441 }
1442
1443 static unsigned long
1444 som_compute_checksum (abfd)
1445 bfd *abfd;
1446 {
1447 unsigned long checksum, count, i;
1448 unsigned long *buffer = (unsigned long *) obj_som_file_hdr (abfd);
1449
1450 checksum = 0;
1451 count = sizeof (struct header) / sizeof (unsigned long);
1452 for (i = 0; i < count; i++)
1453 checksum ^= *(buffer + i);
1454
1455 return checksum;
1456 }
1457
1458 boolean
1459 som_write_object_contents (abfd)
1460 bfd *abfd;
1461 {
1462 fprintf (stderr, "som_write_object_contents unimplemented\n");
1463 fflush (stderr);
1464 abort ();
1465 return (false);
1466 }
1467 /* Read and save the string table associated with the given BFD. */
1468
1469 static boolean
1470 som_slurp_string_table (abfd)
1471 bfd *abfd;
1472 {
1473 char *stringtab;
1474
1475 /* Use the saved version if its available. */
1476 if (obj_som_stringtab (abfd) != NULL)
1477 return true;
1478
1479 /* Allocate and read in the string table. */
1480 stringtab = bfd_zalloc (abfd, obj_som_stringtab_size (abfd));
1481 if (stringtab == NULL)
1482 {
1483 bfd_error = no_memory;
1484 return false;
1485 }
1486
1487 if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) < 0)
1488 {
1489 bfd_error = system_call_error;
1490 return false;
1491 }
1492
1493 if (bfd_read (stringtab, obj_som_stringtab_size (abfd), 1, abfd)
1494 != obj_som_stringtab_size (abfd))
1495 {
1496 bfd_error = system_call_error;
1497 return false;
1498 }
1499
1500 /* Save our results and return success. */
1501 obj_som_stringtab (abfd) = stringtab;
1502 return true;
1503 }
1504
1505 /* Return the amount of data (in bytes) required to hold the symbol
1506 table for this object. */
1507
1508 static unsigned int
1509 som_get_symtab_upper_bound (abfd)
1510 bfd *abfd;
1511 {
1512 if (!som_slurp_symbol_table (abfd))
1513 return 0;
1514
1515 return (bfd_get_symcount (abfd) + 1) * (sizeof (som_symbol_type *));
1516 }
1517
1518 /* Convert from a SOM subspace index to a BFD section. */
1519
1520 static asection *
1521 som_section_from_subspace_index (abfd, index)
1522 bfd *abfd;
1523 unsigned int index;
1524 {
1525 asection *section;
1526
1527 for (section = abfd->sections; section != NULL; section = section->next)
1528 if (som_section_data (section)->subspace_index == index)
1529 return section;
1530
1531 /* Should never happen. */
1532 abort();
1533 }
1534
1535 /* Read and save the symbol table associated with the given BFD. */
1536
1537 static unsigned int
1538 som_slurp_symbol_table (abfd)
1539 bfd *abfd;
1540 {
1541 int symbol_count = bfd_get_symcount (abfd);
1542 int symsize = sizeof (struct symbol_dictionary_record);
1543 char *stringtab;
1544 struct symbol_dictionary_record *buf, *bufp, *endbufp;
1545 som_symbol_type *sym, *symbase;
1546
1547 /* Return saved value if it exists. */
1548 if (obj_som_symtab (abfd) != NULL)
1549 return true;
1550
1551 /* Sanity checking. Make sure there are some symbols and that
1552 we can read the string table too. */
1553 if (symbol_count == 0)
1554 {
1555 bfd_error = no_symbols;
1556 return false;
1557 }
1558
1559 if (!som_slurp_string_table (abfd))
1560 return false;
1561
1562 stringtab = obj_som_stringtab (abfd);
1563
1564 symbase = (som_symbol_type *)
1565 bfd_zalloc (abfd, symbol_count * sizeof (som_symbol_type));
1566 if (symbase == NULL)
1567 {
1568 bfd_error = no_memory;
1569 return false;
1570 }
1571
1572 /* Read in the external SOM representation. */
1573 buf = alloca (symbol_count * symsize);
1574 if (buf == NULL)
1575 {
1576 bfd_error = no_memory;
1577 return false;
1578 }
1579 if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) < 0)
1580 {
1581 bfd_error = system_call_error;
1582 return false;
1583 }
1584 if (bfd_read (buf, symbol_count * symsize, 1, abfd)
1585 != symbol_count * symsize)
1586 {
1587 bfd_error = no_symbols;
1588 return (false);
1589 }
1590
1591 /* Iterate over all the symbols and internalize them. */
1592 endbufp = buf + symbol_count;
1593 for (bufp = buf, sym = symbase; bufp < endbufp; ++bufp)
1594 {
1595
1596 /* I don't think we care about these. */
1597 if (bufp->symbol_type == ST_SYM_EXT
1598 || bufp->symbol_type == ST_ARG_EXT)
1599 continue;
1600
1601 /* Some reasonable defaults. */
1602 sym->symbol.the_bfd = abfd;
1603 sym->symbol.name = bufp->name.n_strx + stringtab;
1604 sym->symbol.value = bufp->symbol_value;
1605 sym->symbol.section = 0;
1606 sym->symbol.flags = 0;
1607
1608 switch (bufp->symbol_type)
1609 {
1610 case ST_ENTRY:
1611 sym->symbol.flags |= BSF_FUNCTION;
1612 sym->symbol.value &= ~0x3;
1613 break;
1614
1615 case ST_PRI_PROG:
1616 case ST_SEC_PROG:
1617 case ST_STUB:
1618 case ST_MILLICODE:
1619 case ST_CODE:
1620 sym->symbol.value &= ~0x3;
1621
1622 default:
1623 break;
1624 }
1625
1626 /* Handle scoping and section information. */
1627 switch (bufp->symbol_scope)
1628 {
1629 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
1630 so the section associated with this symbol can't be known. */
1631 case SS_EXTERNAL:
1632 case SS_UNSAT:
1633 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
1634 break;
1635
1636 case SS_UNIVERSAL:
1637 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
1638 sym->symbol.section
1639 = som_section_from_subspace_index (abfd, bufp->symbol_info);
1640 sym->symbol.value -= sym->symbol.section->vma;
1641 break;
1642
1643 #if 0
1644 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
1645 Sound dumb? It is. */
1646 case SS_GLOBAL:
1647 #endif
1648 case SS_LOCAL:
1649 sym->symbol.flags |= BSF_LOCAL;
1650 sym->symbol.section
1651 = som_section_from_subspace_index (abfd, bufp->symbol_info);
1652 sym->symbol.value -= sym->symbol.section->vma;
1653 break;
1654 }
1655
1656 /* Mark symbols left around by the debugger. */
1657 if (strlen (sym->symbol.name) >= 3
1658 && sym->symbol.name[0] == 'L'
1659 && (sym->symbol.name[2] == '$' || sym->symbol.name[3] == '$'))
1660 sym->symbol.flags |= BSF_DEBUGGING;
1661
1662 /* Note increment at bottom of loop, since we skip some symbols
1663 we can not include it as part of the for statement. */
1664 sym++;
1665 }
1666
1667 /* Save our results and return success. */
1668 obj_som_symtab (abfd) = symbase;
1669 return (true);
1670 }
1671
1672 /* Canonicalize a SOM symbol table. Return the number of entries
1673 in the symbol table. */
1674
1675 static unsigned int
1676 som_get_symtab (abfd, location)
1677 bfd *abfd;
1678 asymbol **location;
1679 {
1680 int i;
1681 som_symbol_type *symbase;
1682
1683 if (!som_slurp_symbol_table (abfd))
1684 return 0;
1685
1686 i = bfd_get_symcount (abfd);
1687 symbase = obj_som_symtab (abfd);
1688
1689 for (; i > 0; i--, location++, symbase++)
1690 *location = &symbase->symbol;
1691
1692 /* Final null pointer. */
1693 *location = 0;
1694 return (bfd_get_symcount (abfd));
1695 }
1696
1697 /* Make a SOM symbol. There is nothing special to do here. */
1698
1699 static asymbol *
1700 som_make_empty_symbol (abfd)
1701 bfd *abfd;
1702 {
1703 som_symbol_type *new =
1704 (som_symbol_type *) bfd_zalloc (abfd, sizeof (som_symbol_type));
1705 if (new == NULL)
1706 {
1707 bfd_error = no_memory;
1708 return 0;
1709 }
1710 new->symbol.the_bfd = abfd;
1711
1712 return &new->symbol;
1713 }
1714
1715 /* Print symbol information. */
1716
1717 static void
1718 som_print_symbol (ignore_abfd, afile, symbol, how)
1719 bfd *ignore_abfd;
1720 PTR afile;
1721 asymbol *symbol;
1722 bfd_print_symbol_type how;
1723 {
1724 FILE *file = (FILE *) afile;
1725 switch (how)
1726 {
1727 case bfd_print_symbol_name:
1728 fprintf (file, "%s", symbol->name);
1729 break;
1730 case bfd_print_symbol_more:
1731 fprintf (file, "som ");
1732 fprintf_vma (file, symbol->value);
1733 fprintf (file, " %lx", (long) symbol->flags);
1734 break;
1735 case bfd_print_symbol_all:
1736 {
1737 CONST char *section_name;
1738 section_name = symbol->section ? symbol->section->name : "(*none*)";
1739 bfd_print_symbol_vandf ((PTR) file, symbol);
1740 fprintf (file, " %s\t%s", section_name, symbol->name);
1741 break;
1742 }
1743 }
1744 }
1745
1746 static unsigned int
1747 som_get_reloc_upper_bound (abfd, asect)
1748 bfd *abfd;
1749 sec_ptr asect;
1750 {
1751 fprintf (stderr, "som_get_reloc_upper_bound unimplemented\n");
1752 fflush (stderr);
1753 abort ();
1754 return (0);
1755 }
1756
1757 static unsigned int
1758 som_canonicalize_reloc (abfd, section, relptr, symbols)
1759 bfd *abfd;
1760 sec_ptr section;
1761 arelent **relptr;
1762 asymbol **symbols;
1763 {
1764 fprintf (stderr, "som_canonicalize_reloc unimplemented\n");
1765 fflush (stderr);
1766 abort ();
1767 }
1768
1769 extern bfd_target som_vec;
1770
1771 /* A hook to set up object file dependent section information. */
1772
1773 static boolean
1774 som_new_section_hook (abfd, newsect)
1775 bfd *abfd;
1776 asection *newsect;
1777 {
1778 newsect->used_by_bfd = (struct som_section_data_struct *)
1779 bfd_zalloc (abfd, sizeof (struct som_section_data_struct));
1780 newsect->alignment_power = 3;
1781
1782 /* Initialize the subspace_index field to -1 so that it does
1783 not match a subspace with an index of 0. */
1784 som_section_data (newsect)->subspace_index = -1;
1785
1786 /* We allow more than three sections internally */
1787 return true;
1788 }
1789
1790 /* Set backend info for sections which can not be described
1791 in the BFD data structures. */
1792
1793 void
1794 bfd_som_set_section_attributes (section, defined, private, sort_key, spnum)
1795 asection *section;
1796 char defined;
1797 char private;
1798 unsigned char sort_key;
1799 int spnum;
1800 {
1801 struct space_dictionary_record *space_dict;
1802
1803 som_section_data (section)->is_space = 1;
1804 space_dict = &som_section_data (section)->space_dict;
1805 space_dict->is_defined = defined;
1806 space_dict->is_private = private;
1807 space_dict->sort_key = sort_key;
1808 space_dict->space_number = spnum;
1809 }
1810
1811 /* Set backend info for subsections which can not be described
1812 in the BFD data structures. */
1813
1814 void
1815 bfd_som_set_subsection_attributes (section, container, access,
1816 sort_key, quadrant)
1817 asection *section;
1818 asection *container;
1819 int access;
1820 unsigned char sort_key;
1821 int quadrant;
1822 {
1823 struct subspace_dictionary_record *subspace_dict;
1824 som_section_data (section)->is_subspace = 1;
1825 subspace_dict = &som_section_data (section)->subspace_dict;
1826 subspace_dict->access_control_bits = access;
1827 subspace_dict->sort_key = sort_key;
1828 subspace_dict->quadrant = quadrant;
1829 som_section_data (section)->containing_space = container;
1830 }
1831
1832 /* Set the full SOM symbol type. SOM needs far more symbol information
1833 than any other object file format I'm aware of. It is mandatory
1834 to be able to know if a symbol is an entry point, millicode, data,
1835 code, absolute, storage request, or procedure label. If you get
1836 the symbol type wrong your program will not link. */
1837
1838 void
1839 bfd_som_set_symbol_type (symbol, type)
1840 asymbol *symbol;
1841 unsigned int type;
1842 {
1843 (*som_symbol_data (symbol))->som_type = type;
1844 }
1845
1846 /* Attach 64bits of unwind information to a symbol (which hopefully
1847 is a function of some kind!). It would be better to keep this
1848 in the R_ENTRY relocation, but there is not enough space. */
1849
1850 void
1851 bfd_som_attach_unwind_info (symbol, unwind_desc)
1852 asymbol *symbol;
1853 char *unwind_desc;
1854 {
1855 (*som_symbol_data (symbol))->unwind = unwind_desc;
1856 }
1857
1858 static boolean
1859 som_set_section_contents (abfd, section, location, offset, count)
1860 bfd *abfd;
1861 sec_ptr section;
1862 PTR location;
1863 file_ptr offset;
1864 bfd_size_type count;
1865 {
1866 fprintf (stderr, "som_set_section_contents unimplimented\n");
1867 fflush (stderr);
1868 abort ();
1869 return false;
1870 }
1871
1872 static boolean
1873 som_set_arch_mach (abfd, arch, machine)
1874 bfd *abfd;
1875 enum bfd_architecture arch;
1876 unsigned long machine;
1877 {
1878 /* Allow any architecture to be supported by the SOM backend */
1879 return bfd_default_set_arch_mach (abfd, arch, machine);
1880 }
1881
1882 static boolean
1883 som_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
1884 functionname_ptr, line_ptr)
1885 bfd *abfd;
1886 asection *section;
1887 asymbol **symbols;
1888 bfd_vma offset;
1889 CONST char **filename_ptr;
1890 CONST char **functionname_ptr;
1891 unsigned int *line_ptr;
1892 {
1893 fprintf (stderr, "som_find_nearest_line unimplemented\n");
1894 fflush (stderr);
1895 abort ();
1896 return (false);
1897 }
1898
1899 static int
1900 som_sizeof_headers (abfd, reloc)
1901 bfd *abfd;
1902 boolean reloc;
1903 {
1904 fprintf (stderr, "som_sizeof_headers unimplemented\n");
1905 fflush (stderr);
1906 abort ();
1907 return (0);
1908 }
1909
1910 /* Return information about SOM symbol SYMBOL in RET. */
1911
1912 static void
1913 som_get_symbol_info (ignore_abfd, symbol, ret)
1914 bfd *ignore_abfd; /* Ignored. */
1915 asymbol *symbol;
1916 symbol_info *ret;
1917 {
1918 bfd_symbol_info (symbol, ret);
1919 }
1920
1921 /* End of miscellaneous support functions. */
1922
1923 #define som_bfd_debug_info_start bfd_void
1924 #define som_bfd_debug_info_end bfd_void
1925 #define som_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
1926
1927 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
1928 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
1929 #define som_slurp_armap bfd_false
1930 #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
1931 #define som_truncate_arname (void (*)())bfd_nullvoidptr
1932 #define som_write_armap 0
1933
1934 #define som_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
1935 #define som_close_and_cleanup bfd_generic_close_and_cleanup
1936 #define som_get_section_contents bfd_generic_get_section_contents
1937
1938 #define som_bfd_get_relocated_section_contents \
1939 bfd_generic_get_relocated_section_contents
1940 #define som_bfd_relax_section bfd_generic_relax_section
1941 #define som_bfd_seclet_link bfd_generic_seclet_link
1942 #define som_bfd_reloc_type_lookup \
1943 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
1944 #define som_bfd_make_debug_symbol \
1945 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
1946
1947 /* Core file support is in the hpux-core backend. */
1948 #define som_core_file_failing_command _bfd_dummy_core_file_failing_command
1949 #define som_core_file_failing_signal _bfd_dummy_core_file_failing_signal
1950 #define som_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
1951
1952 bfd_target som_vec =
1953 {
1954 "som", /* name */
1955 bfd_target_som_flavour,
1956 true, /* target byte order */
1957 true, /* target headers byte order */
1958 (HAS_RELOC | EXEC_P | /* object flags */
1959 HAS_LINENO | HAS_DEBUG |
1960 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1961 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
1962 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1963
1964 /* leading_symbol_char: is the first char of a user symbol
1965 predictable, and if so what is it */
1966 0,
1967 ' ', /* ar_pad_char */
1968 16, /* ar_max_namelen */
1969 3, /* minimum alignment */
1970 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1971 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1972 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
1973 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1974 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1975 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
1976 {_bfd_dummy_target,
1977 som_object_p, /* bfd_check_format */
1978 bfd_generic_archive_p,
1979 _bfd_dummy_target
1980 },
1981 {
1982 bfd_false,
1983 som_mkobject,
1984 _bfd_generic_mkarchive,
1985 bfd_false
1986 },
1987 {
1988 bfd_false,
1989 som_write_object_contents,
1990 _bfd_write_archive_contents,
1991 bfd_false,
1992 },
1993 #undef som
1994 JUMP_TABLE (som),
1995 (PTR) 0
1996 };
1997
1998 #endif /* HOST_HPPAHPUX || HOST_HPPABSD */
This page took 0.083007 seconds and 5 git commands to generate.