* som.c (som_write_fixups): 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 /* Size (in chars) of the temporary buffers used during fixup and string
71 table writes. */
72
73 #define SOM_TMP_BUFSIZE 8192
74
75
76 /* SOM allows any one of the four previous relocations to be reused
77 with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
78 relocations are always a single byte, using a R_PREV_FIXUP instead
79 of some multi-byte relocation makes object files smaller.
80
81 Note one side effect of using a R_PREV_FIXUP is the relocation that
82 is being repeated moves to the front of the queue. */
83 struct reloc_queue
84 {
85 unsigned char *reloc;
86 unsigned int size;
87 } reloc_queue[4];
88
89 /* This fully describes the symbol types which may be attached to
90 an EXPORT or IMPORT directive. Only SOM uses this formation
91 (ELF has no need for it). */
92 typedef enum
93 {
94 SYMBOL_TYPE_UNKNOWN,
95 SYMBOL_TYPE_ABSOLUTE,
96 SYMBOL_TYPE_CODE,
97 SYMBOL_TYPE_DATA,
98 SYMBOL_TYPE_ENTRY,
99 SYMBOL_TYPE_MILLICODE,
100 SYMBOL_TYPE_PLABEL,
101 SYMBOL_TYPE_PRI_PROG,
102 SYMBOL_TYPE_SEC_PROG,
103 } pa_symbol_type;
104
105 /* Forward declarations */
106
107 static boolean som_mkobject PARAMS ((bfd *));
108 static bfd_target * som_object_setup PARAMS ((bfd *,
109 struct header *,
110 struct som_exec_auxhdr *));
111 static asection * make_unique_section PARAMS ((bfd *, CONST char *, int));
112 static boolean setup_sections PARAMS ((bfd *, struct header *));
113 static bfd_target * som_object_p PARAMS ((bfd *));
114 static boolean som_write_object_contents PARAMS ((bfd *));
115 static boolean som_slurp_string_table PARAMS ((bfd *));
116 static unsigned int som_slurp_symbol_table PARAMS ((bfd *));
117 static unsigned int som_get_symtab_upper_bound PARAMS ((bfd *));
118 static unsigned int som_canonicalize_reloc PARAMS ((bfd *, sec_ptr,
119 arelent **, asymbol **));
120 static unsigned int som_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
121 static unsigned int som_get_symtab PARAMS ((bfd *, asymbol **));
122 static asymbol * som_make_empty_symbol PARAMS ((bfd *));
123 static void som_print_symbol PARAMS ((bfd *, PTR,
124 asymbol *, bfd_print_symbol_type));
125 static boolean som_new_section_hook PARAMS ((bfd *, asection *));
126 static boolean som_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
127 file_ptr, bfd_size_type));
128 static boolean som_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
129 unsigned long));
130 static boolean som_find_nearest_line PARAMS ((bfd *, asection *,
131 asymbol **, bfd_vma,
132 CONST char **,
133 CONST char **,
134 unsigned int *));
135 static void som_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
136 static asection * som_section_from_subspace_index PARAMS ((bfd *,
137 unsigned int));
138 static int log2 PARAMS ((unsigned int));
139 static bfd_reloc_status_type hppa_som_reloc PARAMS ((bfd *, arelent *,
140 asymbol *, PTR,
141 asection *, bfd *));
142 static void som_initialize_reloc_queue PARAMS ((struct reloc_queue *));
143 static void som_reloc_queue_insert PARAMS ((unsigned char *, unsigned int,
144 struct reloc_queue *));
145 static void som_reloc_queue_fix PARAMS ((struct reloc_queue *, unsigned int));
146 static int som_reloc_queue_find PARAMS ((unsigned char *, unsigned int,
147 struct reloc_queue *));
148 static unsigned char * try_prev_fixup PARAMS ((bfd *, int *, unsigned char *,
149 unsigned int,
150 struct reloc_queue *));
151
152 static unsigned char * som_reloc_skip PARAMS ((bfd *, unsigned int,
153 unsigned char *, unsigned int *,
154 struct reloc_queue *));
155 static unsigned char * som_reloc_addend PARAMS ((bfd *, int, unsigned char *,
156 unsigned int *,
157 struct reloc_queue *));
158 static unsigned char * som_reloc_call PARAMS ((bfd *, unsigned char *,
159 unsigned int *,
160 arelent *, int,
161 struct reloc_queue *));
162 static unsigned long som_count_spaces PARAMS ((bfd *));
163 static unsigned long som_count_subspaces PARAMS ((bfd *));
164 static int compare_syms PARAMS ((asymbol **, asymbol **));
165 static unsigned long som_compute_checksum PARAMS ((bfd *));
166 static boolean som_prep_headers PARAMS ((bfd *));
167 static int som_sizeof_headers PARAMS ((bfd *, boolean));
168 static boolean som_write_headers PARAMS ((bfd *));
169 static boolean som_build_and_write_symbol_table PARAMS ((bfd *));
170 static void som_prep_for_fixups PARAMS ((bfd *, asymbol **, unsigned long));
171 static boolean som_write_fixups PARAMS ((bfd *, unsigned long, unsigned int *));
172
173 static reloc_howto_type som_hppa_howto_table[] =
174 {
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_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
198 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
199 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
200 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
201 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
202 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
203 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
204 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
205 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
206 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
207 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
208 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
209 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
210 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
211 {R_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RELOCATION"},
212 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
213 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
214 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
215 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
216 {R_SPACE_REF, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_SPACE_REF"},
217 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
218 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
219 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
220 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
221 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
222 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
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_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
228 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
229 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
230 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
231 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
232 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
233 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
234 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
235 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
236 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
237 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
238 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
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_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
244 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
245 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
246 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
247 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
248 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
249 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
250 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
251 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
252 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
253 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
254 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
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_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
281 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
282 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
283 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
284 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
285 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
286 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
287 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
288 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
289 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
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_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
294 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
295 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
296 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
297 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
298 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
299 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
300 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
301 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
302 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
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_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
329 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
330 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
331 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
332 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
333 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
334 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
335 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
336 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
337 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
338 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
339 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
340 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
341 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
342 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
343 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
344 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
345 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
346 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
347 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
348 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
349 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
350 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
351 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
352 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
353 {R_BREAKPOINT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BREAKPOINT"},
354 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
355 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
356 {R_ALT_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ALT_ENTRY"},
357 {R_EXIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_EXIT"},
358 {R_BEGIN_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_TRY"},
359 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
360 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
361 {R_BEGIN_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_BRTAB"},
362 {R_END_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_BRTAB"},
363 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
364 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
365 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
366 {R_DATA_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_EXPR"},
367 {R_CODE_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_EXPR"},
368 {R_FSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_FSEL"},
369 {R_LSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LSEL"},
370 {R_RSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RSEL"},
371 {R_N_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_N_MODE"},
372 {R_S_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_S_MODE"},
373 {R_D_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_D_MODE"},
374 {R_R_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_R_MODE"},
375 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
376 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
377 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
378 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
379 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
380 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
381 {R_TRANSLATED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_TRANSLATED"},
382 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
383 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
384 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
385 {R_COMP1, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP1"},
386 {R_COMP2, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP2"},
387 {R_COMP3, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP3"},
388 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
389 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
390 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
391 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
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 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
424 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
425 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
426 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
427 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
428 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
429 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
430 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
431 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
432 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"}};
433
434
435 /* Initialize the SOM relocation queue. By definition the queue holds
436 the last four multibyte fixups. */
437
438 static void
439 som_initialize_reloc_queue (queue)
440 struct reloc_queue *queue;
441 {
442 queue[0].reloc = NULL;
443 queue[0].size = 0;
444 queue[1].reloc = NULL;
445 queue[1].size = 0;
446 queue[2].reloc = NULL;
447 queue[2].size = 0;
448 queue[3].reloc = NULL;
449 queue[3].size = 0;
450 }
451
452 /* Insert a new relocation into the relocation queue. */
453
454 static void
455 som_reloc_queue_insert (p, size, queue)
456 unsigned char *p;
457 unsigned int size;
458 struct reloc_queue *queue;
459 {
460 queue[3].reloc = queue[2].reloc;
461 queue[3].size = queue[2].size;
462 queue[2].reloc = queue[1].reloc;
463 queue[2].size = queue[1].size;
464 queue[1].reloc = queue[0].reloc;
465 queue[1].size = queue[0].size;
466 queue[0].reloc = p;
467 queue[0].size = size;
468 }
469
470 /* When an entry in the relocation queue is reused, the entry moves
471 to the front of the queue. */
472
473 static void
474 som_reloc_queue_fix (queue, index)
475 struct reloc_queue *queue;
476 unsigned int index;
477 {
478 if (index == 0)
479 return;
480
481 if (index == 1)
482 {
483 unsigned char *tmp1 = queue[0].reloc;
484 unsigned int tmp2 = queue[0].size;
485 queue[0].reloc = queue[1].reloc;
486 queue[0].size = queue[1].size;
487 queue[1].reloc = tmp1;
488 queue[1].size = tmp2;
489 return;
490 }
491
492 if (index == 2)
493 {
494 unsigned char *tmp1 = queue[0].reloc;
495 unsigned int tmp2 = queue[0].size;
496 queue[0].reloc = queue[2].reloc;
497 queue[0].size = queue[2].size;
498 queue[2].reloc = queue[1].reloc;
499 queue[2].size = queue[1].size;
500 queue[1].reloc = tmp1;
501 queue[1].size = tmp2;
502 return;
503 }
504
505 if (index == 3)
506 {
507 unsigned char *tmp1 = queue[0].reloc;
508 unsigned int tmp2 = queue[0].size;
509 queue[0].reloc = queue[3].reloc;
510 queue[0].size = queue[3].size;
511 queue[3].reloc = queue[2].reloc;
512 queue[3].size = queue[2].size;
513 queue[2].reloc = queue[1].reloc;
514 queue[2].size = queue[1].size;
515 queue[1].reloc = tmp1;
516 queue[1].size = tmp2;
517 return;
518 }
519 abort();
520 }
521
522 /* Search for a particular relocation in the relocation queue. */
523
524 static int
525 som_reloc_queue_find (p, size, queue)
526 unsigned char *p;
527 unsigned int size;
528 struct reloc_queue *queue;
529 {
530 if (!bcmp (p, queue[0].reloc, size)
531 && size == queue[0].size)
532 return 0;
533 if (!bcmp (p, queue[1].reloc, size)
534 && size == queue[1].size)
535 return 1;
536 if (!bcmp (p, queue[2].reloc, size)
537 && size == queue[2].size)
538 return 2;
539 if (!bcmp (p, queue[3].reloc, size)
540 && size == queue[3].size)
541 return 3;
542 return -1;
543 }
544
545 static unsigned char *
546 try_prev_fixup (abfd, subspace_reloc_sizep, p, size, queue)
547 bfd *abfd;
548 int *subspace_reloc_sizep;
549 unsigned char *p;
550 unsigned int size;
551 struct reloc_queue *queue;
552 {
553 int queue_index = som_reloc_queue_find (p, size, queue);
554
555 if (queue_index != -1)
556 {
557 /* Found this in a previous fixup. Undo the fixup we
558 just built and use R_PREV_FIXUP instead. We saved
559 a total of size - 1 bytes in the fixup stream. */
560 bfd_put_8 (abfd, R_PREV_FIXUP + queue_index, p);
561 p += 1;
562 *subspace_reloc_sizep += 1;
563 som_reloc_queue_fix (queue, queue_index);
564 }
565 else
566 {
567 som_reloc_queue_insert (p, size, queue);
568 *subspace_reloc_sizep += size;
569 p += size;
570 }
571 return p;
572 }
573
574 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
575 bytes without any relocation. Update the size of the subspace
576 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
577 current pointer into the relocation stream. */
578
579 static unsigned char *
580 som_reloc_skip (abfd, skip, p, subspace_reloc_sizep, queue)
581 bfd *abfd;
582 unsigned int skip;
583 unsigned char *p;
584 unsigned int *subspace_reloc_sizep;
585 struct reloc_queue *queue;
586 {
587 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
588 then R_PREV_FIXUPs to get the difference down to a
589 reasonable size. */
590 if (skip >= 0x1000000)
591 {
592 skip -= 0x1000000;
593 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
594 bfd_put_8 (abfd, 0xff, p + 1);
595 bfd_put_16 (abfd, 0xffff, p + 2);
596 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
597 while (skip >= 0x1000000)
598 {
599 skip -= 0x1000000;
600 bfd_put_8 (abfd, R_PREV_FIXUP, p);
601 p++;
602 *subspace_reloc_sizep += 1;
603 /* No need to adjust queue here since we are repeating the
604 most recent fixup. */
605 }
606 }
607
608 /* The difference must be less than 0x1000000. Use one
609 more R_NO_RELOCATION entry to get to the right difference. */
610 if ((skip & 3) == 0 && skip <= 0xc0000 && skip > 0)
611 {
612 /* Difference can be handled in a simple single-byte
613 R_NO_RELOCATION entry. */
614 if (skip <= 0x60)
615 {
616 bfd_put_8 (abfd, R_NO_RELOCATION + (skip >> 2) - 1, p);
617 *subspace_reloc_sizep += 1;
618 p++;
619 }
620 /* Handle it with a two byte R_NO_RELOCATION entry. */
621 else if (skip <= 0x1000)
622 {
623 bfd_put_8 (abfd, R_NO_RELOCATION + 24 + (((skip >> 2) - 1) >> 8), p);
624 bfd_put_8 (abfd, (skip >> 2) - 1, p + 1);
625 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
626 }
627 /* Handle it with a three byte R_NO_RELOCATION entry. */
628 else
629 {
630 bfd_put_8 (abfd, R_NO_RELOCATION + 28 + (((skip >> 2) - 1) >> 16), p);
631 bfd_put_16 (abfd, (skip >> 2) - 1, p + 1);
632 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
633 }
634 }
635 /* Ugh. Punt and use a 4 byte entry. */
636 else if (skip > 0)
637 {
638 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
639 bfd_put_8 (abfd, skip >> 16, p + 1);
640 bfd_put_16 (abfd, skip, p + 2);
641 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
642 }
643 return p;
644 }
645
646 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
647 from a BFD relocation. Update the size of the subspace relocation
648 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
649 into the relocation stream. */
650
651 static unsigned char *
652 som_reloc_addend (abfd, addend, p, subspace_reloc_sizep, queue)
653 bfd *abfd;
654 int addend;
655 unsigned char *p;
656 unsigned int *subspace_reloc_sizep;
657 struct reloc_queue *queue;
658 {
659 if ((unsigned)(addend) + 0x80 < 0x100)
660 {
661 bfd_put_8 (abfd, R_DATA_OVERRIDE + 1, p);
662 bfd_put_8 (abfd, addend, p + 1);
663 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
664 }
665 else if ((unsigned) (addend) + 0x8000 < 0x10000)
666 {
667 bfd_put_8 (abfd, R_DATA_OVERRIDE + 2, p);
668 bfd_put_16 (abfd, addend, p + 1);
669 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
670 }
671 else if ((unsigned) (addend) + 0x800000 < 0x1000000)
672 {
673 bfd_put_8 (abfd, R_DATA_OVERRIDE + 3, p);
674 bfd_put_8 (abfd, addend >> 16, p + 1);
675 bfd_put_16 (abfd, addend, p + 2);
676 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
677 }
678 else
679 {
680 bfd_put_8 (abfd, R_DATA_OVERRIDE + 4, p);
681 bfd_put_32 (abfd, addend, p + 1);
682 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
683 }
684 return p;
685 }
686
687 /* Handle a single function call relocation. */
688
689 static unsigned char *
690 som_reloc_call (abfd, p, subspace_reloc_sizep, bfd_reloc, sym_num, queue)
691 bfd *abfd;
692 unsigned char *p;
693 unsigned int *subspace_reloc_sizep;
694 arelent *bfd_reloc;
695 int sym_num;
696 struct reloc_queue *queue;
697 {
698 int arg_bits = HPPA_R_ARG_RELOC (bfd_reloc->addend);
699 int rtn_bits = arg_bits & 0x3;
700 int type, done = 0;
701
702 /* You'll never believe all this is necessary to handle relocations
703 for function calls. Having to compute and pack the argument
704 relocation bits is the real nightmare.
705
706 If you're interested in how this works, just forget it. You really
707 do not want to know about this braindamage. */
708
709 /* First see if this can be done with a "simple" relocation. Simple
710 relocations have a symbol number < 0x100 and have simple encodings
711 of argument relocations. */
712
713 if (sym_num < 0x100)
714 {
715 switch (arg_bits)
716 {
717 case 0:
718 case 1:
719 type = 0;
720 break;
721 case 1 << 8:
722 case 1 << 8 | 1:
723 type = 1;
724 break;
725 case 1 << 8 | 1 << 6:
726 case 1 << 8 | 1 << 6 | 1:
727 type = 2;
728 break;
729 case 1 << 8 | 1 << 6 | 1 << 4:
730 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
731 type = 3;
732 break;
733 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
734 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
735 type = 4;
736 break;
737 default:
738 /* Not one of the easy encodings. This will have to be
739 handled by the more complex code below. */
740 type = -1;
741 break;
742 }
743 if (type != -1)
744 {
745 /* Account for the return value too. */
746 if (rtn_bits)
747 type += 5;
748
749 /* Emit a 2 byte relocation. Then see if it can be handled
750 with a relocation which is already in the relocation queue. */
751 bfd_put_8 (abfd, bfd_reloc->howto->type + type, p);
752 bfd_put_8 (abfd, sym_num, p + 1);
753 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
754 done = 1;
755 }
756 }
757
758 /* If this could not be handled with a simple relocation, then do a hard
759 one. Hard relocations occur if the symbol number was too high or if
760 the encoding of argument relocation bits is too complex. */
761 if (! done)
762 {
763 /* Don't ask about these magic sequences. I took them straight
764 from gas-1.36 which took them from the a.out man page. */
765 type = rtn_bits;
766 if ((arg_bits >> 6 & 0xf) == 0xe)
767 type += 9 * 40;
768 else
769 type += (3 * (arg_bits >> 8 & 3) + (arg_bits >> 6 & 3)) * 40;
770 if ((arg_bits >> 2 & 0xf) == 0xe)
771 type += 9 * 4;
772 else
773 type += (3 * (arg_bits >> 4 & 3) + (arg_bits >> 2 & 3)) * 4;
774
775 /* Output the first two bytes of the relocation. These describe
776 the length of the relocation and encoding style. */
777 bfd_put_8 (abfd, bfd_reloc->howto->type + 10
778 + 2 * (sym_num >= 0x100) + (type >= 0x100),
779 p);
780 bfd_put_8 (abfd, type, p + 1);
781
782 /* Now output the symbol index and see if this bizarre relocation
783 just happened to be in the relocation queue. */
784 if (sym_num < 0x100)
785 {
786 bfd_put_8 (abfd, sym_num, p + 2);
787 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
788 }
789 else
790 {
791 bfd_put_8 (abfd, sym_num >> 16, p + 2);
792 bfd_put_16 (abfd, sym_num, p + 3);
793 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
794 }
795 }
796 return p;
797 }
798
799
800 /* Return the logarithm of X, base 2, considering X unsigned.
801 Abort if X is not a power of two -- this should never happen (FIXME:
802 It will happen on corrupt executables. GDB should give an error, not
803 a coredump, in that case). */
804
805 static int
806 log2 (x)
807 unsigned int x;
808 {
809 int log = 0;
810
811 /* Test for 0 or a power of 2. */
812 if (x == 0 || x != (x & -x))
813 abort();
814
815 while ((x >>= 1) != 0)
816 log++;
817 return log;
818 }
819
820 static bfd_reloc_status_type
821 hppa_som_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd)
822 bfd *abfd;
823 arelent *reloc_entry;
824 asymbol *symbol_in;
825 PTR data;
826 asection *input_section;
827 bfd *output_bfd;
828 {
829 if (output_bfd)
830 {
831 reloc_entry->address += input_section->output_offset;
832 return bfd_reloc_ok;
833 }
834 return bfd_reloc_ok;
835 }
836
837 /* Given a generic HPPA relocation type, the instruction format,
838 and a field selector, return an appropriate SOM reloation.
839
840 FIXME. Need to handle %RR, %LR and the like as field selectors.
841 These will need to generate multiple SOM relocations. */
842
843 int **
844 hppa_som_gen_reloc_type (abfd, base_type, format, field)
845 bfd *abfd;
846 int base_type;
847 int format;
848 int field;
849 {
850 int *final_type, **final_types;
851
852 final_types = (int **) bfd_alloc_by_size_t (abfd, sizeof (int *) * 2);
853 final_type = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
854
855
856 final_types[0] = final_type;
857 final_types[1] = NULL;
858
859 /* Default to the basic relocation passed in. */
860 *final_type = base_type;
861
862 switch (base_type)
863 {
864 case R_HPPA:
865 /* PLABELs get their own relocation type. */
866 if (field == e_psel
867 || field == e_lpsel
868 || field == e_rpsel)
869 {
870 /* A PLABEL relocation that has a size of 32 bits must
871 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
872 if (format == 32)
873 *final_type = R_DATA_PLABEL;
874 else
875 *final_type = R_CODE_PLABEL;
876 }
877 /* A relocatoin in the data space is always a full 32bits. */
878 else if (format == 32)
879 *final_type = R_DATA_ONE_SYMBOL;
880
881 break;
882
883 case R_HPPA_GOTOFF:
884 /* More PLABEL special cases. */
885 if (field == e_psel
886 || field == e_lpsel
887 || field == e_rpsel)
888 *final_type = R_DATA_PLABEL;
889 break;
890
891 case R_HPPA_NONE:
892 case R_HPPA_ABS_CALL:
893 case R_HPPA_PCREL_CALL:
894 case R_HPPA_COMPLEX:
895 case R_HPPA_COMPLEX_PCREL_CALL:
896 case R_HPPA_COMPLEX_ABS_CALL:
897 /* Right now we can default all these. */
898 break;
899 }
900 return final_types;
901 }
902
903 /* Return the address of the correct entry in the PA SOM relocation
904 howto table. */
905
906 static reloc_howto_type *
907 som_bfd_reloc_type_lookup (arch, code)
908 bfd_arch_info_type *arch;
909 bfd_reloc_code_real_type code;
910 {
911 if ((int) code < (int) R_NO_RELOCATION + 255)
912 {
913 BFD_ASSERT ((int) som_hppa_howto_table[(int) code].type == (int) code);
914 return &som_hppa_howto_table[(int) code];
915 }
916
917 return (reloc_howto_type *) 0;
918 }
919
920 /* Perform some initialization for an object. Save results of this
921 initialization in the BFD. */
922
923 static bfd_target *
924 som_object_setup (abfd, file_hdrp, aux_hdrp)
925 bfd *abfd;
926 struct header *file_hdrp;
927 struct som_exec_auxhdr *aux_hdrp;
928 {
929 asection *text, *data, *bss;
930
931 /* som_mkobject will set bfd_error if som_mkobject fails. */
932 if (som_mkobject (abfd) != true)
933 return 0;
934
935 /* Make the standard .text, .data, and .bss sections so that tools
936 which assume those names work (size for example). They will have
937 no contents, but the sizes and such will reflect those of the
938 $CODE$, $DATA$, and $BSS$ subspaces respectively.
939
940 FIXME: Should check return status from bfd_make_section calls below. */
941
942 text = bfd_make_section (abfd, ".text");
943 data = bfd_make_section (abfd, ".data");
944 bss = bfd_make_section (abfd, ".bss");
945
946 text->_raw_size = aux_hdrp->exec_tsize;
947 data->_raw_size = aux_hdrp->exec_dsize;
948 bss->_raw_size = aux_hdrp->exec_bsize;
949
950 text->flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_CODE);
951 data->flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS);
952 bss->flags = (SEC_ALLOC | SEC_IS_COMMON);
953
954 /* The virtual memory addresses of the sections */
955 text->vma = aux_hdrp->exec_tmem;
956 data->vma = aux_hdrp->exec_dmem;
957 bss->vma = aux_hdrp->exec_bfill;
958
959 /* The file offsets of the sections */
960 text->filepos = aux_hdrp->exec_tfile;
961 data->filepos = aux_hdrp->exec_dfile;
962
963 /* The file offsets of the relocation info */
964 text->rel_filepos = 0;
965 data->rel_filepos = 0;
966
967 /* Set BFD flags based on what information is available in the SOM. */
968 abfd->flags = NO_FLAGS;
969 if (! file_hdrp->entry_offset)
970 abfd->flags |= HAS_RELOC;
971 else
972 abfd->flags |= EXEC_P;
973 if (file_hdrp->symbol_total)
974 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
975
976 bfd_get_start_address (abfd) = aux_hdrp->exec_entry;
977 bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 0);
978 bfd_get_symcount (abfd) = file_hdrp->symbol_total;
979
980 /* Initialize the saved symbol table and string table to NULL.
981 Save important offsets and sizes from the SOM header into
982 the BFD. */
983 obj_som_stringtab (abfd) = (char *) NULL;
984 obj_som_symtab (abfd) = (som_symbol_type *) NULL;
985 obj_som_stringtab_size (abfd) = file_hdrp->symbol_strings_size;
986 obj_som_sym_filepos (abfd) = file_hdrp->symbol_location;
987 obj_som_str_filepos (abfd) = file_hdrp->symbol_strings_location;
988 obj_som_reloc_filepos (abfd) = file_hdrp->fixup_request_location;
989
990 return abfd->xvec;
991 }
992
993 /* Create a new BFD section for NAME. If NAME already exists, then create a
994 new unique name, with NAME as the prefix. This exists because SOM .o files
995 may have more than one $CODE$ subspace. */
996
997 static asection *
998 make_unique_section (abfd, name, num)
999 bfd *abfd;
1000 CONST char *name;
1001 int num;
1002 {
1003 asection *sect;
1004 char *newname;
1005 char altname[100];
1006
1007 sect = bfd_make_section (abfd, name);
1008 while (!sect)
1009 {
1010 sprintf (altname, "%s-%d", name, num++);
1011 sect = bfd_make_section (abfd, altname);
1012 }
1013
1014 newname = bfd_alloc (abfd, strlen (sect->name) + 1);
1015 strcpy (newname, sect->name);
1016
1017 sect->name = newname;
1018 return sect;
1019 }
1020
1021 /* Convert all of the space and subspace info into BFD sections. Each space
1022 contains a number of subspaces, which in turn describe the mapping between
1023 regions of the exec file, and the address space that the program runs in.
1024 BFD sections which correspond to spaces will overlap the sections for the
1025 associated subspaces. */
1026
1027 static boolean
1028 setup_sections (abfd, file_hdr)
1029 bfd *abfd;
1030 struct header *file_hdr;
1031 {
1032 char *space_strings;
1033 int space_index;
1034 unsigned int total_subspaces = 0;
1035
1036 /* First, read in space names */
1037
1038 space_strings = alloca (file_hdr->space_strings_size);
1039 if (!space_strings)
1040 return false;
1041
1042 if (bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET) < 0)
1043 return false;
1044 if (bfd_read (space_strings, 1, file_hdr->space_strings_size, abfd)
1045 != file_hdr->space_strings_size)
1046 return false;
1047
1048 /* Loop over all of the space dictionaries, building up sections */
1049 for (space_index = 0; space_index < file_hdr->space_total; space_index++)
1050 {
1051 struct space_dictionary_record space;
1052 struct subspace_dictionary_record subspace, save_subspace;
1053 int subspace_index;
1054 asection *space_asect;
1055
1056 /* Read the space dictionary element */
1057 if (bfd_seek (abfd, file_hdr->space_location
1058 + space_index * sizeof space, SEEK_SET) < 0)
1059 return false;
1060 if (bfd_read (&space, 1, sizeof space, abfd) != sizeof space)
1061 return false;
1062
1063 /* Setup the space name string */
1064 space.name.n_name = space.name.n_strx + space_strings;
1065
1066 /* Make a section out of it */
1067 space_asect = make_unique_section (abfd, space.name.n_name, space_index);
1068 if (!space_asect)
1069 return false;
1070
1071 /* Now, read in the first subspace for this space */
1072 if (bfd_seek (abfd, file_hdr->subspace_location
1073 + space.subspace_index * sizeof subspace,
1074 SEEK_SET) < 0)
1075 return false;
1076 if (bfd_read (&subspace, 1, sizeof subspace, abfd) != sizeof subspace)
1077 return false;
1078 /* Seek back to the start of the subspaces for loop below */
1079 if (bfd_seek (abfd, file_hdr->subspace_location
1080 + space.subspace_index * sizeof subspace,
1081 SEEK_SET) < 0)
1082 return false;
1083
1084 /* Setup the start address and file loc from the first subspace record */
1085 space_asect->vma = subspace.subspace_start;
1086 space_asect->filepos = subspace.file_loc_init_value;
1087 space_asect->alignment_power = log2 (subspace.alignment);
1088
1089 /* Initialize save_subspace so we can reliably determine if this
1090 loop placed any useful values into it. */
1091 bzero (&save_subspace, sizeof (struct subspace_dictionary_record));
1092
1093 /* Loop over the rest of the subspaces, building up more sections */
1094 for (subspace_index = 0; subspace_index < space.subspace_quantity;
1095 subspace_index++)
1096 {
1097 asection *subspace_asect;
1098
1099 /* Read in the next subspace */
1100 if (bfd_read (&subspace, 1, sizeof subspace, abfd)
1101 != sizeof subspace)
1102 return false;
1103
1104 /* Setup the subspace name string */
1105 subspace.name.n_name = subspace.name.n_strx + space_strings;
1106
1107 /* Make a section out of this subspace */
1108 subspace_asect = make_unique_section (abfd, subspace.name.n_name,
1109 space.subspace_index + subspace_index);
1110
1111 if (!subspace_asect)
1112 return false;
1113
1114 /* Keep an easy mapping between subspaces and sections. */
1115 som_section_data (subspace_asect)->subspace_index
1116 = total_subspaces++;
1117
1118 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
1119 by the access_control_bits in the subspace header. */
1120 switch (subspace.access_control_bits >> 4)
1121 {
1122 /* Readonly data. */
1123 case 0x0:
1124 subspace_asect->flags |= SEC_DATA | SEC_READONLY;
1125 break;
1126
1127 /* Normal data. */
1128 case 0x1:
1129 subspace_asect->flags |= SEC_DATA;
1130 break;
1131
1132 /* Readonly code and the gateways.
1133 Gateways have other attributes which do not map
1134 into anything BFD knows about. */
1135 case 0x2:
1136 case 0x4:
1137 case 0x5:
1138 case 0x6:
1139 case 0x7:
1140 subspace_asect->flags |= SEC_CODE | SEC_READONLY;
1141 break;
1142
1143 /* dynamic (writable) code. */
1144 case 0x3:
1145 subspace_asect->flags |= SEC_CODE;
1146 break;
1147 }
1148
1149 if (subspace.dup_common || subspace.is_common)
1150 subspace_asect->flags |= SEC_IS_COMMON;
1151 else
1152 subspace_asect->flags |= SEC_HAS_CONTENTS;
1153 if (subspace.is_loadable)
1154 subspace_asect->flags |= SEC_ALLOC | SEC_LOAD;
1155 if (subspace.code_only)
1156 subspace_asect->flags |= SEC_CODE;
1157
1158 /* This subspace has relocations.
1159 The fixup_request_quantity is a byte count for the number of
1160 entries in the relocation stream; it is not the actual number
1161 of relocations in the subspace. */
1162 if (subspace.fixup_request_quantity != 0)
1163 {
1164 subspace_asect->flags |= SEC_RELOC;
1165 subspace_asect->rel_filepos = subspace.fixup_request_index;
1166 som_section_data (subspace_asect)->reloc_size
1167 = subspace.fixup_request_quantity;
1168 /* We can not determine this yet. When we read in the
1169 relocation table the correct value will be filled in. */
1170 subspace_asect->reloc_count = -1;
1171 }
1172
1173 /* Update save_subspace if appropriate. */
1174 if (subspace.file_loc_init_value > save_subspace.file_loc_init_value)
1175 save_subspace = subspace;
1176
1177 subspace_asect->vma = subspace.subspace_start;
1178 subspace_asect->_cooked_size = subspace.subspace_length;
1179 subspace_asect->_raw_size = subspace.initialization_length;
1180 subspace_asect->alignment_power = log2 (subspace.alignment);
1181 subspace_asect->filepos = subspace.file_loc_init_value;
1182 }
1183
1184 /* Yow! there is no subspace within the space which actually
1185 has initialized information in it; this should never happen
1186 as far as I know. */
1187 if (!save_subspace.file_loc_init_value)
1188 abort ();
1189
1190 /* Setup the sizes for the space section based upon the info in the
1191 last subspace of the space. */
1192 space_asect->_cooked_size = save_subspace.subspace_start
1193 - space_asect->vma + save_subspace.subspace_length;
1194 space_asect->_raw_size = save_subspace.file_loc_init_value
1195 - space_asect->filepos + save_subspace.initialization_length;
1196 }
1197 return true;
1198 }
1199
1200 /* Read in a SOM object and make it into a BFD. */
1201
1202 static bfd_target *
1203 som_object_p (abfd)
1204 bfd *abfd;
1205 {
1206 struct header file_hdr;
1207 struct som_exec_auxhdr aux_hdr;
1208
1209 if (bfd_read ((PTR) & file_hdr, 1, FILE_HDR_SIZE, abfd) != FILE_HDR_SIZE)
1210 {
1211 bfd_error = system_call_error;
1212 return 0;
1213 }
1214
1215 if (!_PA_RISC_ID (file_hdr.system_id))
1216 {
1217 bfd_error = wrong_format;
1218 return 0;
1219 }
1220
1221 switch (file_hdr.a_magic)
1222 {
1223 case RELOC_MAGIC:
1224 case EXEC_MAGIC:
1225 case SHARE_MAGIC:
1226 case DEMAND_MAGIC:
1227 #ifdef DL_MAGIC
1228 case DL_MAGIC:
1229 #endif
1230 #ifdef SHL_MAGIC
1231 case SHL_MAGIC:
1232 #endif
1233 #ifdef EXECLIBMAGIC
1234 case EXECLIBMAGIC:
1235 #endif
1236 break;
1237 default:
1238 bfd_error = wrong_format;
1239 return 0;
1240 }
1241
1242 if (file_hdr.version_id != VERSION_ID
1243 && file_hdr.version_id != NEW_VERSION_ID)
1244 {
1245 bfd_error = wrong_format;
1246 return 0;
1247 }
1248
1249 /* If the aux_header_size field in the file header is zero, then this
1250 object is an incomplete executable (a .o file). Do not try to read
1251 a non-existant auxiliary header. */
1252 bzero (&aux_hdr, sizeof (struct som_exec_auxhdr));
1253 if (file_hdr.aux_header_size != 0)
1254 {
1255 if (bfd_read ((PTR) & aux_hdr, 1, AUX_HDR_SIZE, abfd) != AUX_HDR_SIZE)
1256 {
1257 bfd_error = wrong_format;
1258 return 0;
1259 }
1260 }
1261
1262 if (!setup_sections (abfd, &file_hdr))
1263 {
1264 /* setup_sections does not bubble up a bfd error code. */
1265 bfd_error = bad_value;
1266 return 0;
1267 }
1268
1269 /* This appears to be a valid SOM object. Do some initialization. */
1270 return som_object_setup (abfd, &file_hdr, &aux_hdr);
1271 }
1272
1273 /* Create a SOM object. */
1274
1275 static boolean
1276 som_mkobject (abfd)
1277 bfd *abfd;
1278 {
1279 /* Allocate memory to hold backend information. */
1280 abfd->tdata.som_data = (struct som_data_struct *)
1281 bfd_zalloc (abfd, sizeof (struct som_data_struct));
1282 if (abfd->tdata.som_data == NULL)
1283 {
1284 bfd_error = no_memory;
1285 return false;
1286 }
1287 obj_som_file_hdr (abfd) = bfd_zalloc (abfd, sizeof (struct header));
1288 if (obj_som_file_hdr (abfd) == NULL)
1289
1290 {
1291 bfd_error = no_memory;
1292 return false;
1293 }
1294 return true;
1295 }
1296
1297 /* Initialize some information in the file header. This routine makes
1298 not attempt at doing the right thing for a full executable; it
1299 is only meant to handle relocatable objects. */
1300
1301 static boolean
1302 som_prep_headers (abfd)
1303 bfd *abfd;
1304 {
1305 struct header *file_hdr = obj_som_file_hdr (abfd);
1306 asection *section;
1307
1308 /* FIXME. This should really be conditional based on whether or not
1309 PA1.1 instructions/registers have been used. */
1310 file_hdr->system_id = HP9000S800_ID;
1311
1312 /* FIXME. Only correct for building relocatable objects. */
1313 if (abfd->flags & EXEC_P)
1314 abort ();
1315 else
1316 file_hdr->a_magic = RELOC_MAGIC;
1317
1318 /* Only new format SOM is supported. */
1319 file_hdr->version_id = NEW_VERSION_ID;
1320
1321 /* These fields are optional, and embedding timestamps is not always
1322 a wise thing to do, it makes comparing objects during a multi-stage
1323 bootstrap difficult. */
1324 file_hdr->file_time.secs = 0;
1325 file_hdr->file_time.nanosecs = 0;
1326
1327 if (abfd->flags & EXEC_P)
1328 abort ();
1329 else
1330 {
1331 file_hdr->entry_space = 0;
1332 file_hdr->entry_subspace = 0;
1333 file_hdr->entry_offset = 0;
1334 }
1335
1336 /* FIXME. I do not know if we ever need to put anything other
1337 than zero in this field. */
1338 file_hdr->presumed_dp = 0;
1339
1340 /* Now iterate over the sections translating information from
1341 BFD sections to SOM spaces/subspaces. */
1342
1343 for (section = abfd->sections; section != NULL; section = section->next)
1344 {
1345 /* Ignore anything which has not been marked as a space or
1346 subspace. */
1347 if (som_section_data (section)->is_space == 0
1348
1349 && som_section_data (section)->is_subspace == 0)
1350 continue;
1351
1352 if (som_section_data (section)->is_space)
1353 {
1354 /* Set space attributes. Note most attributes of SOM spaces
1355 are set based on the subspaces it contains. */
1356 som_section_data (section)->space_dict.loader_fix_index = -1;
1357 som_section_data (section)->space_dict.init_pointer_index = -1;
1358 }
1359 else
1360 {
1361 /* Set subspace attributes. Basic stuff is done here, additional
1362 attributes are filled in later as more information becomes
1363 available. */
1364 if (section->flags & SEC_IS_COMMON)
1365 {
1366 som_section_data (section)->subspace_dict.dup_common = 1;
1367 som_section_data (section)->subspace_dict.is_common = 1;
1368 }
1369
1370 if (section->flags & SEC_ALLOC)
1371 som_section_data (section)->subspace_dict.is_loadable = 1;
1372
1373 if (section->flags & SEC_CODE)
1374 som_section_data (section)->subspace_dict.code_only = 1;
1375
1376 som_section_data (section)->subspace_dict.subspace_start =
1377 section->vma;
1378 som_section_data (section)->subspace_dict.subspace_length =
1379 bfd_section_size (abfd, section);
1380 som_section_data (section)->subspace_dict.initialization_length =
1381 bfd_section_size (abfd, section);
1382 som_section_data (section)->subspace_dict.alignment =
1383 1 << section->alignment_power;
1384 }
1385 }
1386 return true;
1387 }
1388
1389 /* Count and return the number of spaces attached to the given BFD. */
1390
1391 static unsigned long
1392 som_count_spaces (abfd)
1393 bfd *abfd;
1394 {
1395 int count = 0;
1396 asection *section;
1397
1398 for (section = abfd->sections; section != NULL; section = section->next)
1399 count += som_section_data (section)->is_space;
1400
1401 return count;
1402 }
1403
1404 /* Count the number of subspaces attached to the given BFD. */
1405
1406 static unsigned long
1407 som_count_subspaces (abfd)
1408 bfd *abfd;
1409 {
1410 int count = 0;
1411 asection *section;
1412
1413 for (section = abfd->sections; section != NULL; section = section->next)
1414 count += som_section_data (section)->is_subspace;
1415
1416 return count;
1417 }
1418
1419 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
1420
1421 We desire symbols to be ordered starting with the symbol with the
1422 highest relocation count down to the symbol with the lowest relocation
1423 count. Doing so compacts the relocation stream. */
1424
1425 static int
1426 compare_syms (sym1, sym2)
1427 asymbol **sym1;
1428 asymbol **sym2;
1429
1430 {
1431 unsigned int count1, count2;
1432
1433 /* Get relocation count for each symbol. Note that the count
1434 is stored in the udata pointer for section symbols! */
1435 if ((*sym1)->flags & BSF_SECTION_SYM)
1436 count1 = (int)(*sym1)->udata;
1437 else
1438 count1 = (*som_symbol_data ((*sym1)))->reloc_count;
1439
1440 if ((*sym2)->flags & BSF_SECTION_SYM)
1441 count2 = (int)(*sym2)->udata;
1442 else
1443 count2 = (*som_symbol_data ((*sym2)))->reloc_count;
1444
1445 /* Return the appropriate value. */
1446 if (count1 < count2)
1447 return 1;
1448 else if (count1 > count2)
1449 return -1;
1450 return 0;
1451 }
1452
1453 /* Perform various work in preparation for emitting the fixup stream. */
1454
1455 static void
1456 som_prep_for_fixups (abfd, syms, num_syms)
1457 bfd *abfd;
1458 asymbol **syms;
1459 unsigned long num_syms;
1460 {
1461 int i;
1462 asection *section;
1463
1464 /* Most SOM relocations involving a symbol have a length which is
1465 dependent on the index of the symbol. So symbols which are
1466 used often in relocations should have a small index. */
1467
1468 /* First initialize the counters for each symbol. */
1469 for (i = 0; i < num_syms; i++)
1470 {
1471 /* Handle a section symbol; these have no pointers back to the
1472 SOM symbol info. So we just use the pointer field (udata)
1473 to hold the relocation count.
1474
1475 FIXME. While we're here set the name of any section symbol
1476 to something which will not screw GDB. How do other formats
1477 deal with this?!? */
1478 if (som_symbol_data (syms[i]) == NULL)
1479 {
1480 syms[i]->flags |= BSF_SECTION_SYM;
1481 syms[i]->name = "L$0\002";
1482 syms[i]->udata = (PTR) 0;
1483 }
1484 else
1485 (*som_symbol_data (syms[i]))->reloc_count = 0;
1486 }
1487
1488 /* Now that the counters are initialized, make a weighted count
1489 of how often a given symbol is used in a relocation. */
1490 for (section = abfd->sections; section != NULL; section = section->next)
1491 {
1492 int i;
1493
1494 /* Does this section have any relocations? */
1495 if (section->reloc_count <= 0)
1496 continue;
1497
1498 /* Walk through each relocation for this section. */
1499 for (i = 1; i < section->reloc_count; i++)
1500 {
1501 arelent *reloc = section->orelocation[i];
1502 int scale;
1503
1504 /* If no symbol, then there is no counter to increase. */
1505 if (reloc->sym_ptr_ptr == NULL)
1506 continue;
1507
1508 /* Scaling to encourage symbols involved in R_DP_RELATIVE
1509 and R_CODE_ONE_SYMBOL relocations to come first. These
1510 two relocations have single byte versions if the symbol
1511 index is very small. */
1512 if (reloc->howto->type == R_DP_RELATIVE
1513 || reloc->howto->type == R_CODE_ONE_SYMBOL)
1514 scale = 2;
1515 else
1516 scale = 1;
1517
1518 /* Handle section symbols by ramming the count in the udata
1519 field. It will not be used and the count is very important
1520 for these symbols. */
1521 if ((*reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
1522 {
1523 (*reloc->sym_ptr_ptr)->udata =
1524 (PTR) ((int) (*reloc->sym_ptr_ptr)->udata + scale);
1525 continue;
1526 }
1527
1528 /* A normal symbol. Increment the count. */
1529 (*som_symbol_data ((*reloc->sym_ptr_ptr)))->reloc_count += scale;
1530 }
1531 }
1532
1533 /* Now sort the symbols. */
1534 qsort (syms, num_syms, sizeof (asymbol *), compare_syms);
1535
1536 /* Compute the symbol indexes, they will be needed by the relocation
1537 code. */
1538 for (i = 0; i < num_syms; i++)
1539 {
1540 /* A section symbol. Again, there is no pointer to backend symbol
1541 information, so we reuse (abuse) the udata field again. */
1542 if (syms[i]->flags & BSF_SECTION_SYM)
1543 syms[i]->udata = (PTR) i;
1544 else
1545 (*som_symbol_data (syms[i]))->index = i;
1546 }
1547 }
1548
1549 static boolean
1550 som_write_fixups (abfd, current_offset, total_reloc_sizep)
1551 bfd *abfd;
1552 unsigned long current_offset;
1553 unsigned int *total_reloc_sizep;
1554 {
1555 unsigned int i, j;
1556 unsigned char *tmp_space, *p;
1557 unsigned int total_reloc_size = 0;
1558 unsigned int subspace_reloc_size = 0;
1559 unsigned int num_spaces = obj_som_file_hdr (abfd)->space_total;
1560 asection *section = abfd->sections;
1561
1562 /* Get a chunk of memory that we can use as buffer space, then throw
1563 away. */
1564 tmp_space = alloca (SOM_TMP_BUFSIZE);
1565 bzero (tmp_space, SOM_TMP_BUFSIZE);
1566 p = tmp_space;
1567
1568 /* All the fixups for a particular subspace are emitted in a single
1569 stream. All the subspaces for a particular space are emitted
1570 as a single stream.
1571
1572 So, to get all the locations correct one must iterate through all the
1573 spaces, for each space iterate through its subspaces and output a
1574 fixups stream. */
1575 for (i = 0; i < num_spaces; i++)
1576 {
1577 asection *subsection;
1578
1579 /* Find a space. */
1580 while (som_section_data (section)->is_space == 0)
1581 section = section->next;
1582
1583 /* Now iterate through each of its subspaces. */
1584 for (subsection = abfd->sections;
1585 subsection != NULL;
1586 subsection = subsection->next)
1587 {
1588 int reloc_offset;
1589
1590 /* Find a subspace of this space. */
1591 if (som_section_data (subsection)->is_subspace == 0
1592 || som_section_data (subsection)->containing_space != section)
1593 continue;
1594
1595 /* If this subspace had no relocations, then we're finished
1596 with it. */
1597 if (subsection->reloc_count <= 0)
1598 {
1599 som_section_data (subsection)->subspace_dict.fixup_request_index
1600 = -1;
1601 continue;
1602 }
1603
1604 /* This subspace has some relocations. Put the relocation stream
1605 index into the subspace record. */
1606 som_section_data (subsection)->subspace_dict.fixup_request_index
1607 = total_reloc_size;
1608
1609 /* To make life easier start over with a clean slate for
1610 each subspace. Seek to the start of the relocation stream
1611 for this subspace in preparation for writing out its fixup
1612 stream. */
1613 if (bfd_seek (abfd, current_offset + total_reloc_size, SEEK_SET) != 0)
1614 {
1615 bfd_error = system_call_error;
1616 return false;
1617 }
1618
1619 /* Buffer space has already been allocated. Just perform some
1620 initialization here. */
1621 p = tmp_space;
1622 subspace_reloc_size = 0;
1623 reloc_offset = 0;
1624 som_initialize_reloc_queue (reloc_queue);
1625
1626 /* Translate each BFD relocation into one or more SOM
1627 relocations. */
1628 for (j = 0; j < subsection->reloc_count; j++)
1629 {
1630 arelent *bfd_reloc = subsection->orelocation[j];
1631 unsigned int skip;
1632 int sym_num;
1633
1634 /* Get the symbol number. Remember it's stored in a
1635 special place for section symbols. */
1636 if ((*bfd_reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
1637 sym_num = (int) (*bfd_reloc->sym_ptr_ptr)->udata;
1638 else
1639 sym_num = (*som_symbol_data ((*bfd_reloc->sym_ptr_ptr)))->index;
1640
1641 /* If there is not enough room for the next couple relocations,
1642 then dump the current buffer contents now. Also reinitialize
1643 the relocation queue.
1644
1645 FIXME. We assume here that no BFD relocation will expand
1646 to more than 100 bytes of SOM relocations. This should (?!?)
1647 be quite safe. */
1648 if (p - tmp_space + 100 > SOM_TMP_BUFSIZE)
1649 {
1650 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
1651 != p - tmp_space)
1652 {
1653 bfd_error = system_call_error;
1654 return false;
1655 }
1656 p = tmp_space;
1657 som_initialize_reloc_queue (reloc_queue);
1658 }
1659
1660 /* Emit R_NO_RELOCATION fixups to map any bytes which were
1661 skipped. */
1662 skip = bfd_reloc->address - reloc_offset;
1663 p = som_reloc_skip (abfd, skip, p,
1664 &subspace_reloc_size, reloc_queue);
1665
1666 /* Update reloc_offset for the next iteration.
1667
1668 Note R_ENTRY and R_EXIT relocations are just markers,
1669 they do not consume input bytes. */
1670 if (bfd_reloc->howto->type != R_ENTRY
1671 && bfd_reloc->howto->type != R_EXIT)
1672 reloc_offset = bfd_reloc->address + 4;
1673 else
1674 reloc_offset = bfd_reloc->address;
1675
1676
1677 /* Now the actual relocation we care about. */
1678 switch (bfd_reloc->howto->type)
1679 {
1680 case R_PCREL_CALL:
1681 case R_ABS_CALL:
1682 p = som_reloc_call (abfd, p, &subspace_reloc_size,
1683 bfd_reloc, sym_num, reloc_queue);
1684 break;
1685
1686 case R_CODE_ONE_SYMBOL:
1687 case R_DP_RELATIVE:
1688 /* Account for any addend. */
1689 if (bfd_reloc->addend)
1690 p = som_reloc_addend (abfd, bfd_reloc->addend, p,
1691 &subspace_reloc_size, reloc_queue);
1692
1693 if (sym_num < 0x20)
1694 {
1695 bfd_put_8 (abfd, bfd_reloc->howto->type + sym_num, p);
1696 subspace_reloc_size += 1;
1697 p += 1;
1698 }
1699 else if (sym_num < 0x100)
1700 {
1701 bfd_put_8 (abfd, bfd_reloc->howto->type + 32, p);
1702 bfd_put_8 (abfd, sym_num, p + 1);
1703 p = try_prev_fixup (abfd, &subspace_reloc_size, p,
1704 2, reloc_queue);
1705 }
1706 else if (sym_num < 0x10000000)
1707 {
1708 bfd_put_8 (abfd, bfd_reloc->howto->type + 33, p);
1709 bfd_put_8 (abfd, sym_num >> 16, p + 1);
1710 bfd_put_16 (abfd, sym_num, p + 2);
1711 p = try_prev_fixup (abfd, &subspace_reloc_size,
1712 p, 4, reloc_queue);
1713 }
1714 else
1715 abort ();
1716 break;
1717
1718 case R_DATA_ONE_SYMBOL:
1719 case R_DATA_PLABEL:
1720 case R_CODE_PLABEL:
1721 /* Account for any addend. */
1722 if (bfd_reloc->addend)
1723 p = som_reloc_addend (abfd, bfd_reloc->addend, p,
1724 &subspace_reloc_size, reloc_queue);
1725
1726 if (sym_num < 0x100)
1727 {
1728 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
1729 bfd_put_8 (abfd, sym_num, p + 1);
1730 p = try_prev_fixup (abfd, &subspace_reloc_size, p,
1731 2, reloc_queue);
1732 }
1733 else if (sym_num < 0x10000000)
1734 {
1735 bfd_put_8 (abfd, bfd_reloc->howto->type + 1, p);
1736 bfd_put_8 (abfd, sym_num >> 16, p + 1);
1737 bfd_put_16 (abfd, sym_num, p + 2);
1738 p = try_prev_fixup (abfd, &subspace_reloc_size,
1739 p, 4, reloc_queue);
1740 }
1741 else
1742 abort ();
1743 break;
1744
1745 case R_ENTRY:
1746 {
1747 int *descp
1748 = (int *) (*som_symbol_data ((*bfd_reloc->sym_ptr_ptr)))->unwind;
1749 bfd_put_8 (abfd, R_ENTRY, p);
1750 bfd_put_32 (abfd, descp[0], p + 1);
1751 bfd_put_32 (abfd, descp[1], p + 5);
1752 p = try_prev_fixup (abfd, &subspace_reloc_size,
1753 p, 9, reloc_queue);
1754 break;
1755 }
1756
1757 case R_EXIT:
1758 bfd_put_8 (abfd, R_EXIT, p);
1759 subspace_reloc_size += 1;
1760 p += 1;
1761 break;
1762
1763 /* Put a "R_RESERVED" relocation in the stream if
1764 we hit something we do not understand. The linker
1765 will complain loudly if this ever happens. */
1766 default:
1767 bfd_put_8 (abfd, 0xff, p);
1768 subspace_reloc_size += 1;
1769 p += 1;
1770 }
1771 }
1772
1773 /* Last BFD relocation for a subspace has been processed.
1774 Map the rest of the subspace with R_NO_RELOCATION fixups. */
1775 p = som_reloc_skip (abfd, bfd_section_size (abfd, subsection)
1776 - reloc_offset,
1777 p, &subspace_reloc_size, reloc_queue);
1778
1779 /* Scribble out the relocations. */
1780 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
1781 != p - tmp_space)
1782 {
1783 bfd_error = system_call_error;
1784 return false;
1785 }
1786 p = tmp_space;
1787
1788 total_reloc_size += subspace_reloc_size;
1789 som_section_data (subsection)->subspace_dict.fixup_request_quantity
1790 = subspace_reloc_size;
1791 }
1792 section = section->next;
1793 }
1794 *total_reloc_sizep = total_reloc_size;
1795 return true;
1796 }
1797
1798 /* Finally, scribble out the various headers to the disk. */
1799
1800 static boolean
1801 som_write_headers (abfd)
1802 bfd *abfd;
1803 {
1804 int num_spaces = som_count_spaces (abfd);
1805 int i;
1806 int subspace_index = 0;
1807 file_ptr location;
1808 asection *section;
1809
1810 /* Subspaces are written first so that we can set up information
1811 about them in their containing spaces as the subspace is written. */
1812
1813 /* Seek to the start of the subspace dictionary records. */
1814 location = obj_som_file_hdr (abfd)->subspace_location;
1815 bfd_seek (abfd, location, SEEK_SET);
1816 section = abfd->sections;
1817 /* Now for each loadable space write out records for its subspaces. */
1818 for (i = 0; i < num_spaces; i++)
1819 {
1820 asection *subsection;
1821
1822 /* Find a space. */
1823 while (som_section_data (section)->is_space == 0)
1824 section = section->next;
1825
1826 /* Now look for all its subspaces. */
1827 for (subsection = abfd->sections;
1828 subsection != NULL;
1829 subsection = subsection->next)
1830 {
1831
1832 /* Skip any section which does not correspond to a space
1833 or subspace. Or does not have SEC_ALLOC set (and therefore
1834 has no real bits on the disk). */
1835 if (som_section_data (subsection)->is_subspace == 0
1836 || som_section_data (subsection)->containing_space != section
1837 || (subsection->flags & SEC_ALLOC) == 0)
1838 continue;
1839
1840 /* If this is the first subspace for this space, then save
1841 the index of the subspace in its containing space. Also
1842 set "is_loadable" in the containing space. */
1843
1844 if (som_section_data (section)->space_dict.subspace_quantity == 0)
1845 {
1846 som_section_data (section)->space_dict.is_loadable = 1;
1847 som_section_data (section)->space_dict.subspace_index
1848 = subspace_index;
1849 }
1850
1851 /* Increment the number of subspaces seen and the number of
1852 subspaces contained within the current space. */
1853 subspace_index++;
1854 som_section_data (section)->space_dict.subspace_quantity++;
1855
1856 /* Mark the index of the current space within the subspace's
1857 dictionary record. */
1858 som_section_data (subsection)->subspace_dict.space_index = i;
1859
1860 /* Dump the current subspace header. */
1861 if (bfd_write ((PTR) &som_section_data (subsection)->subspace_dict,
1862 sizeof (struct subspace_dictionary_record), 1, abfd)
1863 != sizeof (struct subspace_dictionary_record))
1864 {
1865 bfd_error = system_call_error;
1866 return false;
1867 }
1868 }
1869 /* Goto the next section. */
1870 section = section->next;
1871 }
1872
1873 /* Now repeat the process for unloadable subspaces. */
1874 section = abfd->sections;
1875 /* Now for each space write out records for its subspaces. */
1876 for (i = 0; i < num_spaces; i++)
1877 {
1878 asection *subsection;
1879
1880 /* Find a space. */
1881 while (som_section_data (section)->is_space == 0)
1882 section = section->next;
1883
1884 /* Now look for all its subspaces. */
1885 for (subsection = abfd->sections;
1886 subsection != NULL;
1887 subsection = subsection->next)
1888 {
1889
1890 /* Skip any section which does not correspond to a space or
1891 subspace, or which SEC_ALLOC set (and therefore handled
1892 in the loadable spaces/subspaces code above. */
1893
1894 if (som_section_data (subsection)->is_subspace == 0
1895 || som_section_data (subsection)->containing_space != section
1896 || (subsection->flags & SEC_ALLOC) != 0)
1897 continue;
1898
1899 /* If this is the first subspace for this space, then save
1900 the index of the subspace in its containing space. Clear
1901 "is_loadable". */
1902
1903 if (som_section_data (section)->space_dict.subspace_quantity == 0)
1904 {
1905 som_section_data (section)->space_dict.is_loadable = 0;
1906 som_section_data (section)->space_dict.subspace_index
1907 = subspace_index;
1908 }
1909
1910 /* Increment the number of subspaces seen and the number of
1911 subspaces contained within the current space. */
1912 som_section_data (section)->space_dict.subspace_quantity++;
1913 subspace_index++;
1914
1915 /* Mark the index of the current space within the subspace's
1916 dictionary record. */
1917 som_section_data (subsection)->subspace_dict.space_index = i;
1918
1919 /* Dump this subspace header. */
1920 if (bfd_write ((PTR) &som_section_data (subsection)->subspace_dict,
1921 sizeof (struct subspace_dictionary_record), 1, abfd)
1922 != sizeof (struct subspace_dictionary_record))
1923 {
1924 bfd_error = system_call_error;
1925 return false;
1926 }
1927 }
1928 /* Goto the next section. */
1929 section = section->next;
1930 }
1931
1932 /* All the subspace dictiondary records are written, and all the
1933 fields are set up in the space dictionary records.
1934
1935 Seek to the right location and start writing the space
1936 dictionary records. */
1937 location = obj_som_file_hdr (abfd)->space_location;
1938 bfd_seek (abfd, location, SEEK_SET);
1939
1940 section = abfd->sections;
1941 for (i = 0; i < num_spaces; i++)
1942 {
1943
1944 /* Find a space. */
1945 while (som_section_data (section)->is_space == 0)
1946 section = section->next;
1947
1948 /* Dump its header */
1949 if (bfd_write ((PTR) &som_section_data (section)->space_dict,
1950 sizeof (struct space_dictionary_record), 1, abfd)
1951 != sizeof (struct space_dictionary_record))
1952 {
1953 bfd_error = system_call_error;
1954 return false;
1955 }
1956
1957 /* Goto the next section. */
1958 section = section->next;
1959 }
1960
1961 /* Only thing left to do is write out the file header. It is always
1962 at location zero. Seek there and write it. */
1963 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
1964 if (bfd_write ((PTR) obj_som_file_hdr (abfd),
1965 sizeof (struct header), 1, abfd)
1966 != sizeof (struct header))
1967 {
1968 bfd_error = system_call_error;
1969 return false;
1970 }
1971 return true;
1972 }
1973
1974 /* Compute and return the checksum for a SOM file header. */
1975
1976 static unsigned long
1977 som_compute_checksum (abfd)
1978 bfd *abfd;
1979 {
1980 unsigned long checksum, count, i;
1981 unsigned long *buffer = (unsigned long *) obj_som_file_hdr (abfd);
1982
1983 checksum = 0;
1984 count = sizeof (struct header) / sizeof (unsigned long);
1985 for (i = 0; i < count; i++)
1986 checksum ^= *(buffer + i);
1987
1988 return checksum;
1989 }
1990
1991 /* Build and write, in one big chunk, the entire symbol table for
1992 this BFD. */
1993
1994 static boolean
1995 som_build_and_write_symbol_table (abfd)
1996 bfd *abfd;
1997 {
1998 unsigned int num_syms = bfd_get_symcount (abfd);
1999 file_ptr symtab_location = obj_som_file_hdr (abfd)->symbol_location;
2000 asymbol **bfd_syms = bfd_get_outsymbols (abfd);
2001 struct symbol_dictionary_record *som_symtab;
2002 int i, symtab_size;
2003
2004 /* Compute total symbol table size and allocate a chunk of memory
2005 to hold the symbol table as we build it. */
2006 symtab_size = num_syms * sizeof (struct symbol_dictionary_record);
2007 som_symtab = (struct symbol_dictionary_record *) alloca (symtab_size);
2008 bzero (som_symtab, symtab_size);
2009
2010 /* Walk over each symbol. */
2011 for (i = 0; i < num_syms; i++)
2012 {
2013 /* This is really an index into the symbol strings table.
2014 By the time we get here, the index has already been
2015 computed and stored into the name field in the BFD symbol. */
2016 som_symtab[i].name.n_strx = (int) bfd_syms[i]->name;
2017
2018 /* The HP SOM linker requires detailed type information about
2019 all symbols (including undefined symbols!). Unfortunately,
2020 the type specified in an import/export statement does not
2021 always match what the linker wants. Severe braindamage. */
2022
2023 /* Section symbols will not have a SOM symbol type assigned to
2024 them yet. Assign all section symbols type ST_DATA. */
2025 if (bfd_syms[i]->flags & BSF_SECTION_SYM)
2026 som_symtab[i].symbol_type = ST_DATA;
2027 else
2028 {
2029 /* Common symbols must have scope SS_UNSAT and type
2030 ST_STORAGE or the linker will choke. */
2031 if (bfd_syms[i]->section == &bfd_com_section)
2032 {
2033 som_symtab[i].symbol_scope = SS_UNSAT;
2034 som_symtab[i].symbol_type = ST_STORAGE;
2035 }
2036
2037 /* It is possible to have a symbol without an associated
2038 type. This happens if the user imported the symbol
2039 without a type and the symbol was never defined
2040 locally. If BSF_FUNCTION is set for this symbol, then
2041 assign it type ST_CODE (the HP linker requires undefined
2042 external functions to have type ST_CODE rather than ST_ENTRY. */
2043 else if (((*som_symbol_data (bfd_syms[i]))->som_type
2044 == SYMBOL_TYPE_UNKNOWN)
2045 && (bfd_syms[i]->section == &bfd_und_section)
2046 && (bfd_syms[i]->flags & BSF_FUNCTION))
2047 som_symtab[i].symbol_type = ST_CODE;
2048
2049 /* Handle function symbols which were defined in this file.
2050 They should have type ST_ENTRY. Also retrieve the argument
2051 relocation bits from the SOM backend information. */
2052 else if (((*som_symbol_data (bfd_syms[i]))->som_type
2053 == SYMBOL_TYPE_ENTRY)
2054 || (((*som_symbol_data (bfd_syms[i]))->som_type
2055 == SYMBOL_TYPE_CODE)
2056 && (bfd_syms[i]->flags & BSF_FUNCTION))
2057 || (((*som_symbol_data (bfd_syms[i]))->som_type
2058 == SYMBOL_TYPE_UNKNOWN)
2059 && (bfd_syms[i]->flags & BSF_FUNCTION)))
2060 {
2061 som_symtab[i].symbol_type = ST_ENTRY;
2062 som_symtab[i].arg_reloc
2063 = (*som_symbol_data (bfd_syms[i]))->tc_data.hppa_arg_reloc;
2064 }
2065
2066 /* If the type is unknown at this point, it should be
2067 ST_DATA (functions were handled as special cases above). */
2068 else if ((*som_symbol_data (bfd_syms[i]))->som_type
2069 == SYMBOL_TYPE_UNKNOWN)
2070 som_symtab[i].symbol_type = ST_DATA;
2071
2072 /* From now on it's a very simple mapping. */
2073 else if ((*som_symbol_data (bfd_syms[i]))->som_type
2074 == SYMBOL_TYPE_ABSOLUTE)
2075 som_symtab[i].symbol_type = ST_ABSOLUTE;
2076 else if ((*som_symbol_data (bfd_syms[i]))->som_type
2077 == SYMBOL_TYPE_CODE)
2078 som_symtab[i].symbol_type = ST_CODE;
2079 else if ((*som_symbol_data (bfd_syms[i]))->som_type
2080 == SYMBOL_TYPE_DATA)
2081 som_symtab[i].symbol_type = ST_DATA;
2082 else if ((*som_symbol_data (bfd_syms[i]))->som_type
2083 == SYMBOL_TYPE_MILLICODE)
2084 som_symtab[i].symbol_type = ST_MILLICODE;
2085 else if ((*som_symbol_data (bfd_syms[i]))->som_type
2086 == SYMBOL_TYPE_PLABEL)
2087 som_symtab[i].symbol_type = ST_PLABEL;
2088 else if ((*som_symbol_data (bfd_syms[i]))->som_type
2089 == SYMBOL_TYPE_PRI_PROG)
2090 som_symtab[i].symbol_type = ST_PRI_PROG;
2091 else if ((*som_symbol_data (bfd_syms[i]))->som_type
2092 == SYMBOL_TYPE_SEC_PROG)
2093 som_symtab[i].symbol_type = ST_SEC_PROG;
2094 }
2095
2096 /* Now handle the symbol's scope. Exported data which is not
2097 in the common section has scope SS_UNIVERSAL. Note scope
2098 of common symbols was handled earlier! */
2099 if (bfd_syms[i]->flags & BSF_EXPORT
2100 && bfd_syms[i]->section != &bfd_com_section)
2101 som_symtab[i].symbol_scope = SS_UNIVERSAL;
2102 /* Any undefined symbol at this point has a scope SS_UNSAT. */
2103 else if (bfd_syms[i]->section == &bfd_und_section)
2104 som_symtab[i].symbol_scope = SS_UNSAT;
2105 /* Anything else which is not in the common section has scope
2106 SS_LOCAL. */
2107 else if (bfd_syms[i]->section != &bfd_com_section)
2108 som_symtab[i].symbol_scope = SS_LOCAL;
2109
2110 /* Now set the symbol_info field. It has no real meaning
2111 for undefined or common symbols, but the HP linker will
2112 choke if it's not set to some "reasonable" value. We
2113 use zero as a reasonable value. */
2114 if (bfd_syms[i]->section == &bfd_com_section
2115 || bfd_syms[i]->section == &bfd_und_section)
2116 som_symtab[i].symbol_info = 0;
2117 /* For all other symbols, the symbol_info field contains the
2118 subspace index of the space this symbol is contained in. */
2119 else
2120 som_symtab[i].symbol_info
2121 = som_section_data (bfd_syms[i]->section)->subspace_index;
2122
2123 /* Set the symbol's value. */
2124 som_symtab[i].symbol_value
2125 = bfd_syms[i]->value + bfd_syms[i]->section->vma;
2126 }
2127
2128 /* Egad. Everything is ready, seek to the right location and
2129 scribble out the symbol table. */
2130 if (bfd_seek (abfd, symtab_location, SEEK_SET) != 0)
2131 {
2132 bfd_error = system_call_error;
2133 return false;
2134 }
2135
2136 if (bfd_write ((PTR) som_symtab, symtab_size, 1, abfd) != symtab_size)
2137 {
2138 bfd_error = system_call_error;
2139 return false;
2140 }
2141 return true;
2142 }
2143
2144 /* Write an object in SOM format. */
2145
2146 static boolean
2147 som_write_object_contents (abfd)
2148 bfd *abfd;
2149 {
2150 if (abfd->output_has_begun == false)
2151 {
2152 /* Set up fixed parts of the file, space, and subspace headers.
2153 Notify the world that output has begun. */
2154 som_prep_headers (abfd);
2155 abfd->output_has_begun = true;
2156 #if 0
2157 /* Not in Cygnus sources yet. */
2158 /* Start writing the object file. This include all the string
2159 tables, fixup streams, and other portions of the object file. */
2160 som_begin_writing (abfd);
2161 #endif
2162 }
2163
2164 /* Now that the symbol table information is complete, build and
2165 write the symbol table. */
2166 if (som_build_and_write_symbol_table (abfd) == false)
2167 return false;
2168
2169 /* Compute the checksum for the file header just before writing
2170 the header to disk. */
2171 obj_som_file_hdr (abfd)->checksum = som_compute_checksum (abfd);
2172 return (som_write_headers (abfd));
2173 }
2174
2175 \f
2176 /* Read and save the string table associated with the given BFD. */
2177
2178 static boolean
2179 som_slurp_string_table (abfd)
2180 bfd *abfd;
2181 {
2182 char *stringtab;
2183
2184 /* Use the saved version if its available. */
2185 if (obj_som_stringtab (abfd) != NULL)
2186 return true;
2187
2188 /* Allocate and read in the string table. */
2189 stringtab = bfd_zalloc (abfd, obj_som_stringtab_size (abfd));
2190 if (stringtab == NULL)
2191 {
2192 bfd_error = no_memory;
2193 return false;
2194 }
2195
2196 if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) < 0)
2197 {
2198 bfd_error = system_call_error;
2199 return false;
2200 }
2201
2202 if (bfd_read (stringtab, obj_som_stringtab_size (abfd), 1, abfd)
2203 != obj_som_stringtab_size (abfd))
2204 {
2205 bfd_error = system_call_error;
2206 return false;
2207 }
2208
2209 /* Save our results and return success. */
2210 obj_som_stringtab (abfd) = stringtab;
2211 return true;
2212 }
2213
2214 /* Return the amount of data (in bytes) required to hold the symbol
2215 table for this object. */
2216
2217 static unsigned int
2218 som_get_symtab_upper_bound (abfd)
2219 bfd *abfd;
2220 {
2221 if (!som_slurp_symbol_table (abfd))
2222 return 0;
2223
2224 return (bfd_get_symcount (abfd) + 1) * (sizeof (som_symbol_type *));
2225 }
2226
2227 /* Convert from a SOM subspace index to a BFD section. */
2228
2229 static asection *
2230 som_section_from_subspace_index (abfd, index)
2231 bfd *abfd;
2232 unsigned int index;
2233 {
2234 asection *section;
2235
2236 for (section = abfd->sections; section != NULL; section = section->next)
2237 if (som_section_data (section)->subspace_index == index)
2238 return section;
2239
2240 /* Should never happen. */
2241 abort();
2242 }
2243
2244 /* Read and save the symbol table associated with the given BFD. */
2245
2246 static unsigned int
2247 som_slurp_symbol_table (abfd)
2248 bfd *abfd;
2249 {
2250 int symbol_count = bfd_get_symcount (abfd);
2251 int symsize = sizeof (struct symbol_dictionary_record);
2252 char *stringtab;
2253 struct symbol_dictionary_record *buf, *bufp, *endbufp;
2254 som_symbol_type *sym, *symbase;
2255
2256 /* Return saved value if it exists. */
2257 if (obj_som_symtab (abfd) != NULL)
2258 return true;
2259
2260 /* Sanity checking. Make sure there are some symbols and that
2261 we can read the string table too. */
2262 if (symbol_count == 0)
2263 {
2264 bfd_error = no_symbols;
2265 return false;
2266 }
2267
2268 if (!som_slurp_string_table (abfd))
2269 return false;
2270
2271 stringtab = obj_som_stringtab (abfd);
2272
2273 symbase = (som_symbol_type *)
2274 bfd_zalloc (abfd, symbol_count * sizeof (som_symbol_type));
2275 if (symbase == NULL)
2276 {
2277 bfd_error = no_memory;
2278 return false;
2279 }
2280
2281 /* Read in the external SOM representation. */
2282 buf = alloca (symbol_count * symsize);
2283 if (buf == NULL)
2284 {
2285 bfd_error = no_memory;
2286 return false;
2287 }
2288 if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) < 0)
2289 {
2290 bfd_error = system_call_error;
2291 return false;
2292 }
2293 if (bfd_read (buf, symbol_count * symsize, 1, abfd)
2294 != symbol_count * symsize)
2295 {
2296 bfd_error = no_symbols;
2297 return (false);
2298 }
2299
2300 /* Iterate over all the symbols and internalize them. */
2301 endbufp = buf + symbol_count;
2302 for (bufp = buf, sym = symbase; bufp < endbufp; ++bufp)
2303 {
2304
2305 /* I don't think we care about these. */
2306 if (bufp->symbol_type == ST_SYM_EXT
2307 || bufp->symbol_type == ST_ARG_EXT)
2308 continue;
2309
2310 /* Some reasonable defaults. */
2311 sym->symbol.the_bfd = abfd;
2312 sym->symbol.name = bufp->name.n_strx + stringtab;
2313 sym->symbol.value = bufp->symbol_value;
2314 sym->symbol.section = 0;
2315 sym->symbol.flags = 0;
2316
2317 switch (bufp->symbol_type)
2318 {
2319 case ST_ENTRY:
2320 sym->symbol.flags |= BSF_FUNCTION;
2321 sym->symbol.value &= ~0x3;
2322 break;
2323
2324 case ST_PRI_PROG:
2325 case ST_SEC_PROG:
2326 case ST_STUB:
2327 case ST_MILLICODE:
2328 case ST_CODE:
2329 sym->symbol.value &= ~0x3;
2330
2331 default:
2332 break;
2333 }
2334
2335 /* Handle scoping and section information. */
2336 switch (bufp->symbol_scope)
2337 {
2338 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
2339 so the section associated with this symbol can't be known. */
2340 case SS_EXTERNAL:
2341 case SS_UNSAT:
2342 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
2343 break;
2344
2345 case SS_UNIVERSAL:
2346 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
2347 sym->symbol.section
2348 = som_section_from_subspace_index (abfd, bufp->symbol_info);
2349 sym->symbol.value -= sym->symbol.section->vma;
2350 break;
2351
2352 #if 0
2353 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
2354 Sound dumb? It is. */
2355 case SS_GLOBAL:
2356 #endif
2357 case SS_LOCAL:
2358 sym->symbol.flags |= BSF_LOCAL;
2359 sym->symbol.section
2360 = som_section_from_subspace_index (abfd, bufp->symbol_info);
2361 sym->symbol.value -= sym->symbol.section->vma;
2362 break;
2363 }
2364
2365 /* Mark symbols left around by the debugger. */
2366 if (strlen (sym->symbol.name) >= 3
2367 && sym->symbol.name[0] == 'L'
2368 && (sym->symbol.name[2] == '$' || sym->symbol.name[3] == '$'))
2369 sym->symbol.flags |= BSF_DEBUGGING;
2370
2371 /* Note increment at bottom of loop, since we skip some symbols
2372 we can not include it as part of the for statement. */
2373 sym++;
2374 }
2375
2376 /* Save our results and return success. */
2377 obj_som_symtab (abfd) = symbase;
2378 return (true);
2379 }
2380
2381 /* Canonicalize a SOM symbol table. Return the number of entries
2382 in the symbol table. */
2383
2384 static unsigned int
2385 som_get_symtab (abfd, location)
2386 bfd *abfd;
2387 asymbol **location;
2388 {
2389 int i;
2390 som_symbol_type *symbase;
2391
2392 if (!som_slurp_symbol_table (abfd))
2393 return 0;
2394
2395 i = bfd_get_symcount (abfd);
2396 symbase = obj_som_symtab (abfd);
2397
2398 for (; i > 0; i--, location++, symbase++)
2399 *location = &symbase->symbol;
2400
2401 /* Final null pointer. */
2402 *location = 0;
2403 return (bfd_get_symcount (abfd));
2404 }
2405
2406 /* Make a SOM symbol. There is nothing special to do here. */
2407
2408 static asymbol *
2409 som_make_empty_symbol (abfd)
2410 bfd *abfd;
2411 {
2412 som_symbol_type *new =
2413 (som_symbol_type *) bfd_zalloc (abfd, sizeof (som_symbol_type));
2414 if (new == NULL)
2415 {
2416 bfd_error = no_memory;
2417 return 0;
2418 }
2419 new->symbol.the_bfd = abfd;
2420
2421 return &new->symbol;
2422 }
2423
2424 /* Print symbol information. */
2425
2426 static void
2427 som_print_symbol (ignore_abfd, afile, symbol, how)
2428 bfd *ignore_abfd;
2429 PTR afile;
2430 asymbol *symbol;
2431 bfd_print_symbol_type how;
2432 {
2433 FILE *file = (FILE *) afile;
2434 switch (how)
2435 {
2436 case bfd_print_symbol_name:
2437 fprintf (file, "%s", symbol->name);
2438 break;
2439 case bfd_print_symbol_more:
2440 fprintf (file, "som ");
2441 fprintf_vma (file, symbol->value);
2442 fprintf (file, " %lx", (long) symbol->flags);
2443 break;
2444 case bfd_print_symbol_all:
2445 {
2446 CONST char *section_name;
2447 section_name = symbol->section ? symbol->section->name : "(*none*)";
2448 bfd_print_symbol_vandf ((PTR) file, symbol);
2449 fprintf (file, " %s\t%s", section_name, symbol->name);
2450 break;
2451 }
2452 }
2453 }
2454
2455 static unsigned int
2456 som_get_reloc_upper_bound (abfd, asect)
2457 bfd *abfd;
2458 sec_ptr asect;
2459 {
2460 fprintf (stderr, "som_get_reloc_upper_bound unimplemented\n");
2461 fflush (stderr);
2462 abort ();
2463 return (0);
2464 }
2465
2466 static unsigned int
2467 som_canonicalize_reloc (abfd, section, relptr, symbols)
2468 bfd *abfd;
2469 sec_ptr section;
2470 arelent **relptr;
2471 asymbol **symbols;
2472 {
2473 fprintf (stderr, "som_canonicalize_reloc unimplemented\n");
2474 fflush (stderr);
2475 abort ();
2476 }
2477
2478 extern bfd_target som_vec;
2479
2480 /* A hook to set up object file dependent section information. */
2481
2482 static boolean
2483 som_new_section_hook (abfd, newsect)
2484 bfd *abfd;
2485 asection *newsect;
2486 {
2487 newsect->used_by_bfd = (struct som_section_data_struct *)
2488 bfd_zalloc (abfd, sizeof (struct som_section_data_struct));
2489 newsect->alignment_power = 3;
2490
2491 /* Initialize the subspace_index field to -1 so that it does
2492 not match a subspace with an index of 0. */
2493 som_section_data (newsect)->subspace_index = -1;
2494
2495 /* We allow more than three sections internally */
2496 return true;
2497 }
2498
2499 /* Set backend info for sections which can not be described
2500 in the BFD data structures. */
2501
2502 void
2503 bfd_som_set_section_attributes (section, defined, private, sort_key, spnum)
2504 asection *section;
2505 char defined;
2506 char private;
2507 unsigned char sort_key;
2508 int spnum;
2509 {
2510 struct space_dictionary_record *space_dict;
2511
2512 som_section_data (section)->is_space = 1;
2513 space_dict = &som_section_data (section)->space_dict;
2514 space_dict->is_defined = defined;
2515 space_dict->is_private = private;
2516 space_dict->sort_key = sort_key;
2517 space_dict->space_number = spnum;
2518 }
2519
2520 /* Set backend info for subsections which can not be described
2521 in the BFD data structures. */
2522
2523 void
2524 bfd_som_set_subsection_attributes (section, container, access,
2525 sort_key, quadrant)
2526 asection *section;
2527 asection *container;
2528 int access;
2529 unsigned char sort_key;
2530 int quadrant;
2531 {
2532 struct subspace_dictionary_record *subspace_dict;
2533 som_section_data (section)->is_subspace = 1;
2534 subspace_dict = &som_section_data (section)->subspace_dict;
2535 subspace_dict->access_control_bits = access;
2536 subspace_dict->sort_key = sort_key;
2537 subspace_dict->quadrant = quadrant;
2538 som_section_data (section)->containing_space = container;
2539 }
2540
2541 /* Set the full SOM symbol type. SOM needs far more symbol information
2542 than any other object file format I'm aware of. It is mandatory
2543 to be able to know if a symbol is an entry point, millicode, data,
2544 code, absolute, storage request, or procedure label. If you get
2545 the symbol type wrong your program will not link. */
2546
2547 void
2548 bfd_som_set_symbol_type (symbol, type)
2549 asymbol *symbol;
2550 unsigned int type;
2551 {
2552 (*som_symbol_data (symbol))->som_type = type;
2553 }
2554
2555 /* Attach 64bits of unwind information to a symbol (which hopefully
2556 is a function of some kind!). It would be better to keep this
2557 in the R_ENTRY relocation, but there is not enough space. */
2558
2559 void
2560 bfd_som_attach_unwind_info (symbol, unwind_desc)
2561 asymbol *symbol;
2562 char *unwind_desc;
2563 {
2564 (*som_symbol_data (symbol))->unwind = unwind_desc;
2565 }
2566
2567 static boolean
2568 som_set_section_contents (abfd, section, location, offset, count)
2569 bfd *abfd;
2570 sec_ptr section;
2571 PTR location;
2572 file_ptr offset;
2573 bfd_size_type count;
2574 {
2575 if (abfd->output_has_begun == false)
2576 {
2577 /* Set up fixed parts of the file, space, and subspace headers.
2578 Notify the world that output has begun. */
2579 som_prep_headers (abfd);
2580 abfd->output_has_begun = true;
2581 #if 0
2582 /* Not in Cygnus sources yet. */
2583 /* Start writing the object file. This include all the string
2584 tables, fixup streams, and other portions of the object file. */
2585 som_begin_writing (abfd);
2586 #endif
2587 }
2588
2589 /* Only write subspaces which have "real" contents (eg. the contents
2590 are not generated at run time by the OS). */
2591 if (som_section_data (section)->is_subspace != 1
2592 || ((section->flags & (SEC_LOAD | SEC_DEBUGGING)) == 0))
2593 return true;
2594
2595 /* Seek to the proper offset within the object file and write the
2596 data. */
2597 offset += som_section_data (section)->subspace_dict.file_loc_init_value;
2598 if (bfd_seek (abfd, offset, SEEK_SET) == -1)
2599 {
2600 bfd_error = system_call_error;
2601 return false;
2602 }
2603
2604 if (bfd_write ((PTR) location, 1, count, abfd) != count)
2605 {
2606 bfd_error = system_call_error;
2607 return false;
2608 }
2609 return true;
2610 }
2611
2612 static boolean
2613 som_set_arch_mach (abfd, arch, machine)
2614 bfd *abfd;
2615 enum bfd_architecture arch;
2616 unsigned long machine;
2617 {
2618 /* Allow any architecture to be supported by the SOM backend */
2619 return bfd_default_set_arch_mach (abfd, arch, machine);
2620 }
2621
2622 static boolean
2623 som_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
2624 functionname_ptr, line_ptr)
2625 bfd *abfd;
2626 asection *section;
2627 asymbol **symbols;
2628 bfd_vma offset;
2629 CONST char **filename_ptr;
2630 CONST char **functionname_ptr;
2631 unsigned int *line_ptr;
2632 {
2633 fprintf (stderr, "som_find_nearest_line unimplemented\n");
2634 fflush (stderr);
2635 abort ();
2636 return (false);
2637 }
2638
2639 static int
2640 som_sizeof_headers (abfd, reloc)
2641 bfd *abfd;
2642 boolean reloc;
2643 {
2644 fprintf (stderr, "som_sizeof_headers unimplemented\n");
2645 fflush (stderr);
2646 abort ();
2647 return (0);
2648 }
2649
2650 /* Return information about SOM symbol SYMBOL in RET. */
2651
2652 static void
2653 som_get_symbol_info (ignore_abfd, symbol, ret)
2654 bfd *ignore_abfd; /* Ignored. */
2655 asymbol *symbol;
2656 symbol_info *ret;
2657 {
2658 bfd_symbol_info (symbol, ret);
2659 }
2660
2661 /* End of miscellaneous support functions. */
2662
2663 #define som_bfd_debug_info_start bfd_void
2664 #define som_bfd_debug_info_end bfd_void
2665 #define som_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
2666
2667 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
2668 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
2669 #define som_slurp_armap bfd_false
2670 #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
2671 #define som_truncate_arname (void (*)())bfd_nullvoidptr
2672 #define som_write_armap 0
2673
2674 #define som_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
2675 #define som_close_and_cleanup bfd_generic_close_and_cleanup
2676 #define som_get_section_contents bfd_generic_get_section_contents
2677
2678 #define som_bfd_get_relocated_section_contents \
2679 bfd_generic_get_relocated_section_contents
2680 #define som_bfd_relax_section bfd_generic_relax_section
2681 #define som_bfd_seclet_link bfd_generic_seclet_link
2682 #define som_bfd_reloc_type_lookup \
2683 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
2684 #define som_bfd_make_debug_symbol \
2685 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
2686
2687 /* Core file support is in the hpux-core backend. */
2688 #define som_core_file_failing_command _bfd_dummy_core_file_failing_command
2689 #define som_core_file_failing_signal _bfd_dummy_core_file_failing_signal
2690 #define som_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
2691
2692 bfd_target som_vec =
2693 {
2694 "som", /* name */
2695 bfd_target_som_flavour,
2696 true, /* target byte order */
2697 true, /* target headers byte order */
2698 (HAS_RELOC | EXEC_P | /* object flags */
2699 HAS_LINENO | HAS_DEBUG |
2700 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
2701 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
2702 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2703
2704 /* leading_symbol_char: is the first char of a user symbol
2705 predictable, and if so what is it */
2706 0,
2707 ' ', /* ar_pad_char */
2708 16, /* ar_max_namelen */
2709 3, /* minimum alignment */
2710 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2711 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2712 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
2713 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2714 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2715 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
2716 {_bfd_dummy_target,
2717 som_object_p, /* bfd_check_format */
2718 bfd_generic_archive_p,
2719 _bfd_dummy_target
2720 },
2721 {
2722 bfd_false,
2723 som_mkobject,
2724 _bfd_generic_mkarchive,
2725 bfd_false
2726 },
2727 {
2728 bfd_false,
2729 som_write_object_contents,
2730 _bfd_write_archive_contents,
2731 bfd_false,
2732 },
2733 #undef som
2734 JUMP_TABLE (som),
2735 (PTR) 0
2736 };
2737
2738 #endif /* HOST_HPPAHPUX || HOST_HPPABSD */
This page took 0.092032 seconds and 5 git commands to generate.