* som.c (som_hppa_howto_table): Add missing R_END_TRY. Delete
[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 struct section_to_type
106 {
107 char *section;
108 char type;
109 };
110
111 /* Forward declarations */
112
113 static boolean som_mkobject PARAMS ((bfd *));
114 static bfd_target * som_object_setup PARAMS ((bfd *,
115 struct header *,
116 struct som_exec_auxhdr *));
117 static asection * make_unique_section PARAMS ((bfd *, CONST char *, int));
118 static boolean setup_sections PARAMS ((bfd *, struct header *));
119 static bfd_target * som_object_p PARAMS ((bfd *));
120 static boolean som_write_object_contents PARAMS ((bfd *));
121 static boolean som_slurp_string_table PARAMS ((bfd *));
122 static unsigned int som_slurp_symbol_table PARAMS ((bfd *));
123 static unsigned int som_get_symtab_upper_bound PARAMS ((bfd *));
124 static unsigned int som_canonicalize_reloc PARAMS ((bfd *, sec_ptr,
125 arelent **, asymbol **));
126 static unsigned int som_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
127 static unsigned int som_set_reloc_info PARAMS ((unsigned char *, unsigned int,
128 arelent *, asection *,
129 asymbol **, boolean));
130 static boolean som_slurp_reloc_table PARAMS ((bfd *, asection *,
131 asymbol **, boolean));
132 static unsigned int som_get_symtab PARAMS ((bfd *, asymbol **));
133 static asymbol * som_make_empty_symbol PARAMS ((bfd *));
134 static void som_print_symbol PARAMS ((bfd *, PTR,
135 asymbol *, bfd_print_symbol_type));
136 static boolean som_new_section_hook PARAMS ((bfd *, asection *));
137 static boolean som_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
138 file_ptr, bfd_size_type));
139 static boolean som_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
140 unsigned long));
141 static boolean som_find_nearest_line PARAMS ((bfd *, asection *,
142 asymbol **, bfd_vma,
143 CONST char **,
144 CONST char **,
145 unsigned int *));
146 static void som_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
147 static asection * som_section_from_subspace_index PARAMS ((bfd *,
148 unsigned int));
149 static int log2 PARAMS ((unsigned int));
150 static bfd_reloc_status_type hppa_som_reloc PARAMS ((bfd *, arelent *,
151 asymbol *, PTR,
152 asection *, bfd *));
153 static void som_initialize_reloc_queue PARAMS ((struct reloc_queue *));
154 static void som_reloc_queue_insert PARAMS ((unsigned char *, unsigned int,
155 struct reloc_queue *));
156 static void som_reloc_queue_fix PARAMS ((struct reloc_queue *, unsigned int));
157 static int som_reloc_queue_find PARAMS ((unsigned char *, unsigned int,
158 struct reloc_queue *));
159 static unsigned char * try_prev_fixup PARAMS ((bfd *, int *, unsigned char *,
160 unsigned int,
161 struct reloc_queue *));
162
163 static unsigned char * som_reloc_skip PARAMS ((bfd *, unsigned int,
164 unsigned char *, unsigned int *,
165 struct reloc_queue *));
166 static unsigned char * som_reloc_addend PARAMS ((bfd *, int, unsigned char *,
167 unsigned int *,
168 struct reloc_queue *));
169 static unsigned char * som_reloc_call PARAMS ((bfd *, unsigned char *,
170 unsigned int *,
171 arelent *, int,
172 struct reloc_queue *));
173 static unsigned long som_count_spaces PARAMS ((bfd *));
174 static unsigned long som_count_subspaces PARAMS ((bfd *));
175 static int compare_syms PARAMS ((asymbol **, asymbol **));
176 static unsigned long som_compute_checksum PARAMS ((bfd *));
177 static boolean som_prep_headers PARAMS ((bfd *));
178 static int som_sizeof_headers PARAMS ((bfd *, boolean));
179 static boolean som_write_headers PARAMS ((bfd *));
180 static boolean som_build_and_write_symbol_table PARAMS ((bfd *));
181 static void som_prep_for_fixups PARAMS ((bfd *, asymbol **, unsigned long));
182 static boolean som_write_fixups PARAMS ((bfd *, unsigned long, unsigned int *));
183 static boolean som_write_space_strings PARAMS ((bfd *, unsigned long,
184 unsigned int *));
185 static boolean som_write_symbol_strings PARAMS ((bfd *, unsigned long,
186 asymbol **, unsigned int,
187 unsigned *));
188 static boolean som_begin_writing PARAMS ((bfd *));
189 static const reloc_howto_type * som_bfd_reloc_type_lookup
190 PARAMS ((bfd_arch_info_type *, bfd_reloc_code_real_type));
191 static char som_section_type PARAMS ((const char *));
192 static int som_decode_symclass PARAMS ((asymbol *));
193
194
195 /* Map SOM section names to POSIX/BSD single-character symbol types.
196
197 This table includes all the standard subspaces as defined in the
198 current "PRO ABI for PA-RISC Systems", $UNWIND$ which for
199 some reason was left out, and sections specific to embedded stabs. */
200
201 static const struct section_to_type stt[] = {
202 {"$TEXT$", 't'},
203 {"$SHLIB_INFO$", 't'},
204 {"$MILLICODE$", 't'},
205 {"$LIT$", 't'},
206 {"$CODE$", 't'},
207 {"$UNWIND_START$", 't'},
208 {"$UNWIND$", 't'},
209 {"$PRIVATE$", 'd'},
210 {"$PLT$", 'd'},
211 {"$SHLIB_DATA$", 'd'},
212 {"$DATA$", 'd'},
213 {"$SHORTDATA$", 'g'},
214 {"$DLT$", 'd'},
215 {"$GLOBAL$", 'g'},
216 {"$SHORTBSS$", 's'},
217 {"$BSS$", 'b'},
218 {"$GDB_STRINGS$", 'N'},
219 {"$GDB_SYMBOLS$", 'N'},
220 {0, 0}
221 };
222
223 /* About the relocation formatting table...
224
225 There are 256 entries in the table, one for each possible
226 relocation opcode available in SOM. We index the table by
227 the relocation opcode. The names and operations are those
228 defined by a.out_800 (4).
229
230 Right now this table is only used to count and perform minimal
231 processing on relocation streams so that they can be internalized
232 into BFD and symbolically printed by utilities. To make actual use
233 of them would be much more difficult, BFD's concept of relocations
234 is far too simple to handle SOM relocations. The basic assumption
235 that a relocation can be completely processed independent of other
236 relocations before an object file is written is invalid for SOM.
237
238 The SOM relocations are meant to be processed as a stream, they
239 specify copying of data from the input section to the output section
240 while possibly modifying the data in some manner. They also can
241 specify that a variable number of zeros or uninitialized data be
242 inserted on in the output segment at the current offset. Some
243 relocations specify that some previous relocation be re-applied at
244 the current location in the input/output sections. And finally a number
245 of relocations have effects on other sections (R_ENTRY, R_EXIT,
246 R_UNWIND_AUX and a variety of others). There isn't even enough room
247 in the BFD relocation data structure to store enough information to
248 perform all the relocations.
249
250 Each entry in the table has three fields.
251
252 The first entry is an index into this "class" of relocations. This
253 index can then be used as a variable within the relocation itself.
254
255 The second field is a format string which actually controls processing
256 of the relocation. It uses a simple postfix machine to do calculations
257 based on variables/constants found in the string and the relocation
258 stream.
259
260 The third field specifys whether or not this relocation may use
261 a constant (V) from the previous R_DATA_OVERRIDE rather than a constant
262 stored in the instruction.
263
264 Variables:
265
266 L = input space byte count
267 D = index into class of relocations
268 M = output space byte count
269 N = statement number (unused?)
270 O = stack operation
271 R = parameter relocation bits
272 S = symbol index
273 U = 64 bits of stack unwind and frame size info (we only keep 32 bits)
274 V = a literal constant (usually used in the next relocation)
275 P = a previous relocation
276
277 Lower case letters (starting with 'b') refer to following
278 bytes in the relocation stream. 'b' is the next 1 byte,
279 c is the next 2 bytes, d is the next 3 bytes, etc...
280 This is the variable part of the relocation entries that
281 makes our life a living hell.
282
283 numerical constants are also used in the format string. Note
284 the constants are represented in decimal.
285
286 '+', "*" and "=" represents the obvious postfix operators.
287 '<' represents a left shift.
288
289 Stack Operations:
290
291 Parameter Relocation Bits:
292
293 Unwind Entries:
294
295 Previous Relocations: The index field represents which in the queue
296 of 4 previous fixups should be re-applied.
297
298 Literal Constants: These are generally used to represent addend
299 parts of relocations when these constants are not stored in the
300 fields of the instructions themselves. For example the instruction
301 addil foo-$global$-0x1234 would use an override for "0x1234" rather
302 than storing it into the addil itself. */
303
304 struct fixup_format
305 {
306 int D;
307 char *format;
308 };
309
310 static const struct fixup_format som_fixup_formats[256] =
311 {
312 /* R_NO_RELOCATION */
313 0, "LD1+4*=", /* 0x00 */
314 1, "LD1+4*=", /* 0x01 */
315 2, "LD1+4*=", /* 0x02 */
316 3, "LD1+4*=", /* 0x03 */
317 4, "LD1+4*=", /* 0x04 */
318 5, "LD1+4*=", /* 0x05 */
319 6, "LD1+4*=", /* 0x06 */
320 7, "LD1+4*=", /* 0x07 */
321 8, "LD1+4*=", /* 0x08 */
322 9, "LD1+4*=", /* 0x09 */
323 10, "LD1+4*=", /* 0x0a */
324 11, "LD1+4*=", /* 0x0b */
325 12, "LD1+4*=", /* 0x0c */
326 13, "LD1+4*=", /* 0x0d */
327 14, "LD1+4*=", /* 0x0e */
328 15, "LD1+4*=", /* 0x0f */
329 16, "LD1+4*=", /* 0x10 */
330 17, "LD1+4*=", /* 0x11 */
331 18, "LD1+4*=", /* 0x12 */
332 19, "LD1+4*=", /* 0x13 */
333 20, "LD1+4*=", /* 0x14 */
334 21, "LD1+4*=", /* 0x15 */
335 22, "LD1+4*=", /* 0x16 */
336 23, "LD1+4*=", /* 0x17 */
337 0, "LD8<b+1+4*=", /* 0x18 */
338 1, "LD8<b+1+4*=", /* 0x19 */
339 2, "LD8<b+1+4*=", /* 0x1a */
340 3, "LD8<b+1+4*=", /* 0x1b */
341 0, "LD16<c+1+4*=", /* 0x1c */
342 1, "LD16<c+1+4*=", /* 0x1d */
343 2, "LD16<c+1+4*=", /* 0x1e */
344 0, "Ld1+=", /* 0x1f */
345 /* R_ZEROES */
346 0, "Lb1+4*=", /* 0x20 */
347 1, "Ld1+=", /* 0x21 */
348 /* R_UNINIT */
349 0, "Lb1+4*=", /* 0x22 */
350 1, "Ld1+=", /* 0x23 */
351 /* R_RELOCATION */
352 0, "L4=", /* 0x24 */
353 /* R_DATA_ONE_SYMBOL */
354 0, "L4=Sb=", /* 0x25 */
355 1, "L4=Sd=", /* 0x26 */
356 /* R_DATA_PLEBEL */
357 0, "L4=Sb=", /* 0x27 */
358 1, "L4=Sd=", /* 0x28 */
359 /* R_SPACE_REF */
360 0, "L4=", /* 0x29 */
361 /* R_REPEATED_INIT */
362 0, "L4=Mb1+4*=", /* 0x2a */
363 1, "Lb4*=Mb1+L*=", /* 0x2b */
364 2, "Lb4*=Md1+4*=", /* 0x2c */
365 3, "Ld1+=Me1+=", /* 0x2d */
366 /* R_RESERVED */
367 0, "", /* 0x2e */
368 0, "", /* 0x2f */
369 /* R_PCREL_CALL */
370 0, "L4=RD=Sb=", /* 0x30 */
371 1, "L4=RD=Sb=", /* 0x31 */
372 2, "L4=RD=Sb=", /* 0x32 */
373 3, "L4=RD=Sb=", /* 0x33 */
374 4, "L4=RD=Sb=", /* 0x34 */
375 5, "L4=RD=Sb=", /* 0x35 */
376 6, "L4=RD=Sb=", /* 0x36 */
377 7, "L4=RD=Sb=", /* 0x37 */
378 8, "L4=RD=Sb=", /* 0x38 */
379 9, "L4=RD=Sb=", /* 0x39 */
380 0, "L4=RD8<b+=Sb=",/* 0x3a */
381 1, "L4=RD8<b+=Sb=",/* 0x3b */
382 0, "L4=RD8<b+=Sd=",/* 0x3c */
383 1, "L4=RD8<b+=Sd=",/* 0x3d */
384 /* R_RESERVED */
385 0, "", /* 0x3e */
386 0, "", /* 0x3f */
387 /* R_ABS_CALL */
388 0, "L4=RD=Sb=", /* 0x40 */
389 1, "L4=RD=Sb=", /* 0x41 */
390 2, "L4=RD=Sb=", /* 0x42 */
391 3, "L4=RD=Sb=", /* 0x43 */
392 4, "L4=RD=Sb=", /* 0x44 */
393 5, "L4=RD=Sb=", /* 0x45 */
394 6, "L4=RD=Sb=", /* 0x46 */
395 7, "L4=RD=Sb=", /* 0x47 */
396 8, "L4=RD=Sb=", /* 0x48 */
397 9, "L4=RD=Sb=", /* 0x49 */
398 0, "L4=RD8<b+=Sb=",/* 0x4a */
399 1, "L4=RD8<b+=Sb=",/* 0x4b */
400 0, "L4=RD8<b+=Sd=",/* 0x4c */
401 1, "L4=RD8<b+=Sd=",/* 0x4d */
402 /* R_RESERVED */
403 0, "", /* 0x4e */
404 0, "", /* 0x4f */
405 /* R_DP_RELATIVE */
406 0, "L4=SD=", /* 0x50 */
407 1, "L4=SD=", /* 0x51 */
408 2, "L4=SD=", /* 0x52 */
409 3, "L4=SD=", /* 0x53 */
410 4, "L4=SD=", /* 0x54 */
411 5, "L4=SD=", /* 0x55 */
412 6, "L4=SD=", /* 0x56 */
413 7, "L4=SD=", /* 0x57 */
414 8, "L4=SD=", /* 0x58 */
415 9, "L4=SD=", /* 0x59 */
416 10, "L4=SD=", /* 0x5a */
417 11, "L4=SD=", /* 0x5b */
418 12, "L4=SD=", /* 0x5c */
419 13, "L4=SD=", /* 0x5d */
420 14, "L4=SD=", /* 0x5e */
421 15, "L4=SD=", /* 0x5f */
422 16, "L4=SD=", /* 0x60 */
423 17, "L4=SD=", /* 0x61 */
424 18, "L4=SD=", /* 0x62 */
425 19, "L4=SD=", /* 0x63 */
426 20, "L4=SD=", /* 0x64 */
427 21, "L4=SD=", /* 0x65 */
428 22, "L4=SD=", /* 0x66 */
429 23, "L4=SD=", /* 0x67 */
430 24, "L4=SD=", /* 0x68 */
431 25, "L4=SD=", /* 0x69 */
432 26, "L4=SD=", /* 0x6a */
433 27, "L4=SD=", /* 0x6b */
434 28, "L4=SD=", /* 0x6c */
435 29, "L4=SD=", /* 0x6d */
436 30, "L4=SD=", /* 0x6e */
437 31, "L4=SD=", /* 0x6f */
438 32, "L4=Sb=", /* 0x70 */
439 33, "L4=Sd=", /* 0x71 */
440 /* R_RESERVED */
441 0, "", /* 0x72 */
442 0, "", /* 0x73 */
443 0, "", /* 0x74 */
444 0, "", /* 0x75 */
445 0, "", /* 0x76 */
446 0, "", /* 0x77 */
447 /* R_DLT_REL */
448 0, "L4=Sb=", /* 0x78 */
449 1, "L4=Sd=", /* 0x79 */
450 /* R_RESERVED */
451 0, "", /* 0x7a */
452 0, "", /* 0x7b */
453 0, "", /* 0x7c */
454 0, "", /* 0x7d */
455 0, "", /* 0x7e */
456 0, "", /* 0x7f */
457 /* R_CODE_ONE_SYMBOL */
458 0, "L4=SD=", /* 0x80 */
459 1, "L4=SD=", /* 0x81 */
460 2, "L4=SD=", /* 0x82 */
461 3, "L4=SD=", /* 0x83 */
462 4, "L4=SD=", /* 0x84 */
463 5, "L4=SD=", /* 0x85 */
464 6, "L4=SD=", /* 0x86 */
465 7, "L4=SD=", /* 0x87 */
466 8, "L4=SD=", /* 0x88 */
467 9, "L4=SD=", /* 0x89 */
468 10, "L4=SD=", /* 0x8q */
469 11, "L4=SD=", /* 0x8b */
470 12, "L4=SD=", /* 0x8c */
471 13, "L4=SD=", /* 0x8d */
472 14, "L4=SD=", /* 0x8e */
473 15, "L4=SD=", /* 0x8f */
474 16, "L4=SD=", /* 0x90 */
475 17, "L4=SD=", /* 0x91 */
476 18, "L4=SD=", /* 0x92 */
477 19, "L4=SD=", /* 0x93 */
478 20, "L4=SD=", /* 0x94 */
479 21, "L4=SD=", /* 0x95 */
480 22, "L4=SD=", /* 0x96 */
481 23, "L4=SD=", /* 0x97 */
482 24, "L4=SD=", /* 0x98 */
483 25, "L4=SD=", /* 0x99 */
484 26, "L4=SD=", /* 0x9a */
485 27, "L4=SD=", /* 0x9b */
486 28, "L4=SD=", /* 0x9c */
487 29, "L4=SD=", /* 0x9d */
488 30, "L4=SD=", /* 0x9e */
489 31, "L4=SD=", /* 0x9f */
490 32, "L4=Sb=", /* 0xa0 */
491 33, "L4=Sd=", /* 0xa1 */
492 /* R_RESERVED */
493 0, "", /* 0xa2 */
494 0, "", /* 0xa3 */
495 0, "", /* 0xa4 */
496 0, "", /* 0xa5 */
497 0, "", /* 0xa6 */
498 0, "", /* 0xa7 */
499 0, "", /* 0xa8 */
500 0, "", /* 0xa9 */
501 0, "", /* 0xaa */
502 0, "", /* 0xab */
503 0, "", /* 0xac */
504 0, "", /* 0xad */
505 /* R_MILLI_REL */
506 0, "L4=Sb=", /* 0xae */
507 1, "L4=Sd=", /* 0xaf */
508 /* R_CODE_PLABEL */
509 0, "L4=Sb=", /* 0xb0 */
510 1, "L4=Sd=", /* 0xb1 */
511 /* R_BREAKPOINT */
512 0, "L4=", /* 0xb2 */
513 /* R_ENTRY */
514 0, "Ui=", /* 0xb3 */
515 1, "Uf=", /* 0xb4 */
516 /* R_ALT_ENTRY */
517 0, "", /* 0xb5 */
518 /* R_EXIT */
519 0, "", /* 0xb6 */
520 /* R_BEGIN_TRY */
521 0, "", /* 0xb7 */
522 /* R_END_TRY */
523 0, "R0=", /* 0xb8 */
524 1, "Rb4*=", /* 0xb9 */
525 2, "Rd4*=", /* 0xba */
526 /* R_BEGIN_BRTAB */
527 0, "", /* 0xbb */
528 /* R_END_BRTAB */
529 0, "", /* 0xbc */
530 /* R_STATEMENT */
531 0, "Nb=", /* 0xbd */
532 1, "Nc=", /* 0xbe */
533 2, "Nd=", /* 0xbf */
534 /* R_DATA_EXPR */
535 0, "L4=", /* 0xc0 */
536 /* R_CODE_EXPR */
537 0, "L4=", /* 0xc1 */
538 /* R_FSEL */
539 0, "", /* 0xc2 */
540 /* R_LSEL */
541 0, "", /* 0xc3 */
542 /* R_RSEL */
543 0, "", /* 0xc4 */
544 /* R_N_MODE */
545 0, "", /* 0xc5 */
546 /* R_S_MODE */
547 0, "", /* 0xc6 */
548 /* R_D_MODE */
549 0, "", /* 0xc7 */
550 /* R_R_MODE */
551 0, "", /* 0xc8 */
552 /* R_DATA_OVERRIDE */
553 0, "V0=", /* 0xc9 */
554 1, "Vb=", /* 0xca */
555 2, "Vc=", /* 0xcb */
556 3, "Vd=", /* 0xcc */
557 4, "Ve=", /* 0xcd */
558 /* R_TRANSLATED */
559 0, "", /* 0xce */
560 /* R_RESERVED */
561 0, "", /* 0xcf */
562 /* R_COMP1 */
563 0, "Ob=", /* 0xd0 */
564 /* R_COMP2 */
565 0, "Ob=Sd=", /* 0xd1 */
566 /* R_COMP3 */
567 0, "Ob=Ve=", /* 0xd2 */
568 /* R_PREV_FIXUP */
569 0, "P", /* 0xd3 */
570 1, "P", /* 0xd4 */
571 2, "P", /* 0xd5 */
572 3, "P", /* 0xd6 */
573 /* R_RESERVED */
574 0, "", /* 0xd7 */
575 0, "", /* 0xd8 */
576 0, "", /* 0xd9 */
577 0, "", /* 0xda */
578 0, "", /* 0xdb */
579 0, "", /* 0xdc */
580 0, "", /* 0xdd */
581 0, "", /* 0xde */
582 0, "", /* 0xdf */
583 0, "", /* 0xe0 */
584 0, "", /* 0xe1 */
585 0, "", /* 0xe2 */
586 0, "", /* 0xe3 */
587 0, "", /* 0xe4 */
588 0, "", /* 0xe5 */
589 0, "", /* 0xe6 */
590 0, "", /* 0xe7 */
591 0, "", /* 0xe8 */
592 0, "", /* 0xe9 */
593 0, "", /* 0xea */
594 0, "", /* 0xeb */
595 0, "", /* 0xec */
596 0, "", /* 0xed */
597 0, "", /* 0xee */
598 0, "", /* 0xef */
599 0, "", /* 0xf0 */
600 0, "", /* 0xf1 */
601 0, "", /* 0xf2 */
602 0, "", /* 0xf3 */
603 0, "", /* 0xf4 */
604 0, "", /* 0xf5 */
605 0, "", /* 0xf6 */
606 0, "", /* 0xf7 */
607 0, "", /* 0xf8 */
608 0, "", /* 0xf9 */
609 0, "", /* 0xfa */
610 0, "", /* 0xfb */
611 0, "", /* 0xfc */
612 0, "", /* 0xfd */
613 0, "", /* 0xfe */
614 0, "", /* 0xff */
615 };
616
617 static const int comp1_opcodes[] =
618 {
619 0x00,
620 0x40,
621 0x41,
622 0x42,
623 0x43,
624 0x44,
625 0x45,
626 0x46,
627 0x47,
628 0x48,
629 0x49,
630 0x4a,
631 0x4b,
632 0x60,
633 0x80,
634 0xa0,
635 0xc0,
636 -1
637 };
638
639 static const int comp2_opcodes[] =
640 {
641 0x00,
642 0x80,
643 0x82,
644 0xc0,
645 -1
646 };
647
648 static const int comp3_opcodes[] =
649 {
650 0x00,
651 0x02,
652 -1
653 };
654
655 static reloc_howto_type som_hppa_howto_table[] =
656 {
657 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
658 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
659 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
660 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
661 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
662 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
663 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
664 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
665 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
666 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
667 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
668 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
669 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
670 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
671 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
672 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
673 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
674 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
675 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
676 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
677 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
678 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
679 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
680 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
681 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
682 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
683 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
684 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
685 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
686 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
687 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
688 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
689 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
690 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
691 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
692 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
693 {R_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RELOCATION"},
694 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
695 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
696 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
697 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
698 {R_SPACE_REF, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_SPACE_REF"},
699 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
700 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
701 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
702 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
703 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
704 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
705 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
706 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
707 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
708 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
709 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
710 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
711 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
712 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
713 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
714 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
715 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
716 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
717 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
718 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
719 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
720 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
721 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
722 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
723 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
724 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
725 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
726 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
727 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
728 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
729 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
730 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
731 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
732 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
733 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
734 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
735 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
736 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
737 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
738 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
739 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
740 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
741 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
742 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
743 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
744 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
745 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
746 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
747 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
748 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
749 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
750 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
751 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
752 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
753 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
754 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
755 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
756 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
757 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
758 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
759 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
760 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
761 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
762 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
763 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
764 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
765 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
766 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
767 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
768 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
769 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
770 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
771 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
772 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
773 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
774 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
775 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
776 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
777 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
778 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
779 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
780 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
781 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
782 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
783 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
784 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
785 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
786 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
787 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
788 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
789 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
790 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
791 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
792 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
793 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
794 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
795 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
796 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
797 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
798 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
799 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
800 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
801 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
802 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
803 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
804 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
805 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
806 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
807 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
808 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
809 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
810 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
811 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
812 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
813 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
814 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
815 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
816 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
817 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
818 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
819 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
820 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
821 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
822 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
823 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
824 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
825 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
826 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
827 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
828 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
829 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
830 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
831 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
832 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
833 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
834 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
835 {R_BREAKPOINT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BREAKPOINT"},
836 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
837 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
838 {R_ALT_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ALT_ENTRY"},
839 {R_EXIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_EXIT"},
840 {R_BEGIN_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_TRY"},
841 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
842 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
843 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
844 {R_BEGIN_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_BRTAB"},
845 {R_END_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_BRTAB"},
846 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
847 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
848 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
849 {R_DATA_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_EXPR"},
850 {R_CODE_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_EXPR"},
851 {R_FSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_FSEL"},
852 {R_LSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LSEL"},
853 {R_RSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RSEL"},
854 {R_N_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_N_MODE"},
855 {R_S_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_S_MODE"},
856 {R_D_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_D_MODE"},
857 {R_R_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_R_MODE"},
858 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
859 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
860 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
861 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
862 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
863 {R_TRANSLATED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_TRANSLATED"},
864 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
865 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
866 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
867 {R_COMP1, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP1"},
868 {R_COMP2, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP2"},
869 {R_COMP3, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP3"},
870 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
871 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
872 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
873 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
874 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
875 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
876 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
877 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
878 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
879 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
880 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
881 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
882 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
883 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
884 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
885 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
886 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
887 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
888 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
889 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
890 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
891 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
892 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
893 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
894 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
895 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
896 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
897 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
898 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
899 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
900 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
901 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
902 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
903 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
904 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
905 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
906 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
907 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
908 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
909 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
910 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
911 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
912 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
913 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
914 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"}};
915
916
917 /* Initialize the SOM relocation queue. By definition the queue holds
918 the last four multibyte fixups. */
919
920 static void
921 som_initialize_reloc_queue (queue)
922 struct reloc_queue *queue;
923 {
924 queue[0].reloc = NULL;
925 queue[0].size = 0;
926 queue[1].reloc = NULL;
927 queue[1].size = 0;
928 queue[2].reloc = NULL;
929 queue[2].size = 0;
930 queue[3].reloc = NULL;
931 queue[3].size = 0;
932 }
933
934 /* Insert a new relocation into the relocation queue. */
935
936 static void
937 som_reloc_queue_insert (p, size, queue)
938 unsigned char *p;
939 unsigned int size;
940 struct reloc_queue *queue;
941 {
942 queue[3].reloc = queue[2].reloc;
943 queue[3].size = queue[2].size;
944 queue[2].reloc = queue[1].reloc;
945 queue[2].size = queue[1].size;
946 queue[1].reloc = queue[0].reloc;
947 queue[1].size = queue[0].size;
948 queue[0].reloc = p;
949 queue[0].size = size;
950 }
951
952 /* When an entry in the relocation queue is reused, the entry moves
953 to the front of the queue. */
954
955 static void
956 som_reloc_queue_fix (queue, index)
957 struct reloc_queue *queue;
958 unsigned int index;
959 {
960 if (index == 0)
961 return;
962
963 if (index == 1)
964 {
965 unsigned char *tmp1 = queue[0].reloc;
966 unsigned int tmp2 = queue[0].size;
967 queue[0].reloc = queue[1].reloc;
968 queue[0].size = queue[1].size;
969 queue[1].reloc = tmp1;
970 queue[1].size = tmp2;
971 return;
972 }
973
974 if (index == 2)
975 {
976 unsigned char *tmp1 = queue[0].reloc;
977 unsigned int tmp2 = queue[0].size;
978 queue[0].reloc = queue[2].reloc;
979 queue[0].size = queue[2].size;
980 queue[2].reloc = queue[1].reloc;
981 queue[2].size = queue[1].size;
982 queue[1].reloc = tmp1;
983 queue[1].size = tmp2;
984 return;
985 }
986
987 if (index == 3)
988 {
989 unsigned char *tmp1 = queue[0].reloc;
990 unsigned int tmp2 = queue[0].size;
991 queue[0].reloc = queue[3].reloc;
992 queue[0].size = queue[3].size;
993 queue[3].reloc = queue[2].reloc;
994 queue[3].size = queue[2].size;
995 queue[2].reloc = queue[1].reloc;
996 queue[2].size = queue[1].size;
997 queue[1].reloc = tmp1;
998 queue[1].size = tmp2;
999 return;
1000 }
1001 abort();
1002 }
1003
1004 /* Search for a particular relocation in the relocation queue. */
1005
1006 static int
1007 som_reloc_queue_find (p, size, queue)
1008 unsigned char *p;
1009 unsigned int size;
1010 struct reloc_queue *queue;
1011 {
1012 if (!bcmp (p, queue[0].reloc, size)
1013 && size == queue[0].size)
1014 return 0;
1015 if (!bcmp (p, queue[1].reloc, size)
1016 && size == queue[1].size)
1017 return 1;
1018 if (!bcmp (p, queue[2].reloc, size)
1019 && size == queue[2].size)
1020 return 2;
1021 if (!bcmp (p, queue[3].reloc, size)
1022 && size == queue[3].size)
1023 return 3;
1024 return -1;
1025 }
1026
1027 static unsigned char *
1028 try_prev_fixup (abfd, subspace_reloc_sizep, p, size, queue)
1029 bfd *abfd;
1030 int *subspace_reloc_sizep;
1031 unsigned char *p;
1032 unsigned int size;
1033 struct reloc_queue *queue;
1034 {
1035 int queue_index = som_reloc_queue_find (p, size, queue);
1036
1037 if (queue_index != -1)
1038 {
1039 /* Found this in a previous fixup. Undo the fixup we
1040 just built and use R_PREV_FIXUP instead. We saved
1041 a total of size - 1 bytes in the fixup stream. */
1042 bfd_put_8 (abfd, R_PREV_FIXUP + queue_index, p);
1043 p += 1;
1044 *subspace_reloc_sizep += 1;
1045 som_reloc_queue_fix (queue, queue_index);
1046 }
1047 else
1048 {
1049 som_reloc_queue_insert (p, size, queue);
1050 *subspace_reloc_sizep += size;
1051 p += size;
1052 }
1053 return p;
1054 }
1055
1056 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
1057 bytes without any relocation. Update the size of the subspace
1058 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
1059 current pointer into the relocation stream. */
1060
1061 static unsigned char *
1062 som_reloc_skip (abfd, skip, p, subspace_reloc_sizep, queue)
1063 bfd *abfd;
1064 unsigned int skip;
1065 unsigned char *p;
1066 unsigned int *subspace_reloc_sizep;
1067 struct reloc_queue *queue;
1068 {
1069 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
1070 then R_PREV_FIXUPs to get the difference down to a
1071 reasonable size. */
1072 if (skip >= 0x1000000)
1073 {
1074 skip -= 0x1000000;
1075 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
1076 bfd_put_8 (abfd, 0xff, p + 1);
1077 bfd_put_16 (abfd, 0xffff, p + 2);
1078 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1079 while (skip >= 0x1000000)
1080 {
1081 skip -= 0x1000000;
1082 bfd_put_8 (abfd, R_PREV_FIXUP, p);
1083 p++;
1084 *subspace_reloc_sizep += 1;
1085 /* No need to adjust queue here since we are repeating the
1086 most recent fixup. */
1087 }
1088 }
1089
1090 /* The difference must be less than 0x1000000. Use one
1091 more R_NO_RELOCATION entry to get to the right difference. */
1092 if ((skip & 3) == 0 && skip <= 0xc0000 && skip > 0)
1093 {
1094 /* Difference can be handled in a simple single-byte
1095 R_NO_RELOCATION entry. */
1096 if (skip <= 0x60)
1097 {
1098 bfd_put_8 (abfd, R_NO_RELOCATION + (skip >> 2) - 1, p);
1099 *subspace_reloc_sizep += 1;
1100 p++;
1101 }
1102 /* Handle it with a two byte R_NO_RELOCATION entry. */
1103 else if (skip <= 0x1000)
1104 {
1105 bfd_put_8 (abfd, R_NO_RELOCATION + 24 + (((skip >> 2) - 1) >> 8), p);
1106 bfd_put_8 (abfd, (skip >> 2) - 1, p + 1);
1107 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1108 }
1109 /* Handle it with a three byte R_NO_RELOCATION entry. */
1110 else
1111 {
1112 bfd_put_8 (abfd, R_NO_RELOCATION + 28 + (((skip >> 2) - 1) >> 16), p);
1113 bfd_put_16 (abfd, (skip >> 2) - 1, p + 1);
1114 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1115 }
1116 }
1117 /* Ugh. Punt and use a 4 byte entry. */
1118 else if (skip > 0)
1119 {
1120 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
1121 bfd_put_8 (abfd, skip >> 16, p + 1);
1122 bfd_put_16 (abfd, skip, p + 2);
1123 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1124 }
1125 return p;
1126 }
1127
1128 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
1129 from a BFD relocation. Update the size of the subspace relocation
1130 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
1131 into the relocation stream. */
1132
1133 static unsigned char *
1134 som_reloc_addend (abfd, addend, p, subspace_reloc_sizep, queue)
1135 bfd *abfd;
1136 int addend;
1137 unsigned char *p;
1138 unsigned int *subspace_reloc_sizep;
1139 struct reloc_queue *queue;
1140 {
1141 if ((unsigned)(addend) + 0x80 < 0x100)
1142 {
1143 bfd_put_8 (abfd, R_DATA_OVERRIDE + 1, p);
1144 bfd_put_8 (abfd, addend, p + 1);
1145 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1146 }
1147 else if ((unsigned) (addend) + 0x8000 < 0x10000)
1148 {
1149 bfd_put_8 (abfd, R_DATA_OVERRIDE + 2, p);
1150 bfd_put_16 (abfd, addend, p + 1);
1151 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1152 }
1153 else if ((unsigned) (addend) + 0x800000 < 0x1000000)
1154 {
1155 bfd_put_8 (abfd, R_DATA_OVERRIDE + 3, p);
1156 bfd_put_8 (abfd, addend >> 16, p + 1);
1157 bfd_put_16 (abfd, addend, p + 2);
1158 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1159 }
1160 else
1161 {
1162 bfd_put_8 (abfd, R_DATA_OVERRIDE + 4, p);
1163 bfd_put_32 (abfd, addend, p + 1);
1164 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
1165 }
1166 return p;
1167 }
1168
1169 /* Handle a single function call relocation. */
1170
1171 static unsigned char *
1172 som_reloc_call (abfd, p, subspace_reloc_sizep, bfd_reloc, sym_num, queue)
1173 bfd *abfd;
1174 unsigned char *p;
1175 unsigned int *subspace_reloc_sizep;
1176 arelent *bfd_reloc;
1177 int sym_num;
1178 struct reloc_queue *queue;
1179 {
1180 int arg_bits = HPPA_R_ARG_RELOC (bfd_reloc->addend);
1181 int rtn_bits = arg_bits & 0x3;
1182 int type, done = 0;
1183
1184 /* You'll never believe all this is necessary to handle relocations
1185 for function calls. Having to compute and pack the argument
1186 relocation bits is the real nightmare.
1187
1188 If you're interested in how this works, just forget it. You really
1189 do not want to know about this braindamage. */
1190
1191 /* First see if this can be done with a "simple" relocation. Simple
1192 relocations have a symbol number < 0x100 and have simple encodings
1193 of argument relocations. */
1194
1195 if (sym_num < 0x100)
1196 {
1197 switch (arg_bits)
1198 {
1199 case 0:
1200 case 1:
1201 type = 0;
1202 break;
1203 case 1 << 8:
1204 case 1 << 8 | 1:
1205 type = 1;
1206 break;
1207 case 1 << 8 | 1 << 6:
1208 case 1 << 8 | 1 << 6 | 1:
1209 type = 2;
1210 break;
1211 case 1 << 8 | 1 << 6 | 1 << 4:
1212 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
1213 type = 3;
1214 break;
1215 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
1216 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
1217 type = 4;
1218 break;
1219 default:
1220 /* Not one of the easy encodings. This will have to be
1221 handled by the more complex code below. */
1222 type = -1;
1223 break;
1224 }
1225 if (type != -1)
1226 {
1227 /* Account for the return value too. */
1228 if (rtn_bits)
1229 type += 5;
1230
1231 /* Emit a 2 byte relocation. Then see if it can be handled
1232 with a relocation which is already in the relocation queue. */
1233 bfd_put_8 (abfd, bfd_reloc->howto->type + type, p);
1234 bfd_put_8 (abfd, sym_num, p + 1);
1235 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1236 done = 1;
1237 }
1238 }
1239
1240 /* If this could not be handled with a simple relocation, then do a hard
1241 one. Hard relocations occur if the symbol number was too high or if
1242 the encoding of argument relocation bits is too complex. */
1243 if (! done)
1244 {
1245 /* Don't ask about these magic sequences. I took them straight
1246 from gas-1.36 which took them from the a.out man page. */
1247 type = rtn_bits;
1248 if ((arg_bits >> 6 & 0xf) == 0xe)
1249 type += 9 * 40;
1250 else
1251 type += (3 * (arg_bits >> 8 & 3) + (arg_bits >> 6 & 3)) * 40;
1252 if ((arg_bits >> 2 & 0xf) == 0xe)
1253 type += 9 * 4;
1254 else
1255 type += (3 * (arg_bits >> 4 & 3) + (arg_bits >> 2 & 3)) * 4;
1256
1257 /* Output the first two bytes of the relocation. These describe
1258 the length of the relocation and encoding style. */
1259 bfd_put_8 (abfd, bfd_reloc->howto->type + 10
1260 + 2 * (sym_num >= 0x100) + (type >= 0x100),
1261 p);
1262 bfd_put_8 (abfd, type, p + 1);
1263
1264 /* Now output the symbol index and see if this bizarre relocation
1265 just happened to be in the relocation queue. */
1266 if (sym_num < 0x100)
1267 {
1268 bfd_put_8 (abfd, sym_num, p + 2);
1269 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1270 }
1271 else
1272 {
1273 bfd_put_8 (abfd, sym_num >> 16, p + 2);
1274 bfd_put_16 (abfd, sym_num, p + 3);
1275 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
1276 }
1277 }
1278 return p;
1279 }
1280
1281
1282 /* Return the logarithm of X, base 2, considering X unsigned.
1283 Abort if X is not a power of two -- this should never happen (FIXME:
1284 It will happen on corrupt executables. GDB should give an error, not
1285 a coredump, in that case). */
1286
1287 static int
1288 log2 (x)
1289 unsigned int x;
1290 {
1291 int log = 0;
1292
1293 /* Test for 0 or a power of 2. */
1294 if (x == 0 || x != (x & -x))
1295 abort();
1296
1297 while ((x >>= 1) != 0)
1298 log++;
1299 return log;
1300 }
1301
1302 static bfd_reloc_status_type
1303 hppa_som_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd)
1304 bfd *abfd;
1305 arelent *reloc_entry;
1306 asymbol *symbol_in;
1307 PTR data;
1308 asection *input_section;
1309 bfd *output_bfd;
1310 {
1311 if (output_bfd)
1312 {
1313 reloc_entry->address += input_section->output_offset;
1314 return bfd_reloc_ok;
1315 }
1316 return bfd_reloc_ok;
1317 }
1318
1319 /* Given a generic HPPA relocation type, the instruction format,
1320 and a field selector, return an appropriate SOM reloation.
1321
1322 FIXME. Need to handle %RR, %LR and the like as field selectors.
1323 These will need to generate multiple SOM relocations. */
1324
1325 int **
1326 hppa_som_gen_reloc_type (abfd, base_type, format, field)
1327 bfd *abfd;
1328 int base_type;
1329 int format;
1330 enum hppa_reloc_field_selector_type field;
1331 {
1332 int *final_type, **final_types;
1333
1334 final_types = (int **) bfd_alloc_by_size_t (abfd, sizeof (int *) * 3);
1335 final_type = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1336
1337 /* The field selector may require additional relocations to be
1338 generated. It's impossible to know at this moment if additional
1339 relocations will be needed, so we make them. The code to actually
1340 write the relocation/fixup stream is responsible for removing
1341 any redundant relocations. */
1342 switch (field)
1343 {
1344 case e_fsel:
1345 case e_psel:
1346 case e_lpsel:
1347 case e_rpsel:
1348 case e_tsel:
1349 case e_ltsel:
1350 case e_rtsel:
1351 final_types[0] = final_type;
1352 final_types[1] = NULL;
1353 final_types[2] = NULL;
1354 *final_type = base_type;
1355 break;
1356
1357 case e_lssel:
1358 case e_rssel:
1359 final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1360 *final_types[0] = R_S_MODE;
1361 final_types[1] = final_type;
1362 final_types[2] = NULL;
1363 *final_type = base_type;
1364 break;
1365
1366 case e_lsel:
1367 case e_rsel:
1368 final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1369 *final_types[0] = R_N_MODE;
1370 final_types[1] = final_type;
1371 final_types[2] = NULL;
1372 *final_type = base_type;
1373 break;
1374
1375 case e_ldsel:
1376 case e_rdsel:
1377 final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1378 *final_types[0] = R_D_MODE;
1379 final_types[1] = final_type;
1380 final_types[2] = NULL;
1381 *final_type = base_type;
1382 break;
1383
1384 case e_lrsel:
1385 case e_rrsel:
1386 final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1387 *final_types[0] = R_R_MODE;
1388 final_types[1] = final_type;
1389 final_types[2] = NULL;
1390 *final_type = base_type;
1391 break;
1392 }
1393
1394 switch (base_type)
1395 {
1396 case R_HPPA:
1397 /* PLABELs get their own relocation type. */
1398 if (field == e_psel
1399 || field == e_lpsel
1400 || field == e_rpsel)
1401 {
1402 /* A PLABEL relocation that has a size of 32 bits must
1403 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
1404 if (format == 32)
1405 *final_type = R_DATA_PLABEL;
1406 else
1407 *final_type = R_CODE_PLABEL;
1408 }
1409 /* A relocatoin in the data space is always a full 32bits. */
1410 else if (format == 32)
1411 *final_type = R_DATA_ONE_SYMBOL;
1412
1413 break;
1414
1415 case R_HPPA_GOTOFF:
1416 /* More PLABEL special cases. */
1417 if (field == e_psel
1418 || field == e_lpsel
1419 || field == e_rpsel)
1420 *final_type = R_DATA_PLABEL;
1421 break;
1422
1423 case R_HPPA_NONE:
1424 case R_HPPA_ABS_CALL:
1425 case R_HPPA_PCREL_CALL:
1426 case R_HPPA_COMPLEX:
1427 case R_HPPA_COMPLEX_PCREL_CALL:
1428 case R_HPPA_COMPLEX_ABS_CALL:
1429 /* Right now we can default all these. */
1430 break;
1431 }
1432 return final_types;
1433 }
1434
1435 /* Return the address of the correct entry in the PA SOM relocation
1436 howto table. */
1437
1438 static const reloc_howto_type *
1439 som_bfd_reloc_type_lookup (arch, code)
1440 bfd_arch_info_type *arch;
1441 bfd_reloc_code_real_type code;
1442 {
1443 if ((int) code < (int) R_NO_RELOCATION + 255)
1444 {
1445 BFD_ASSERT ((int) som_hppa_howto_table[(int) code].type == (int) code);
1446 return &som_hppa_howto_table[(int) code];
1447 }
1448
1449 return (reloc_howto_type *) 0;
1450 }
1451
1452 /* Perform some initialization for an object. Save results of this
1453 initialization in the BFD. */
1454
1455 static bfd_target *
1456 som_object_setup (abfd, file_hdrp, aux_hdrp)
1457 bfd *abfd;
1458 struct header *file_hdrp;
1459 struct som_exec_auxhdr *aux_hdrp;
1460 {
1461 /* som_mkobject will set bfd_error if som_mkobject fails. */
1462 if (som_mkobject (abfd) != true)
1463 return 0;
1464
1465 /* Set BFD flags based on what information is available in the SOM. */
1466 abfd->flags = NO_FLAGS;
1467 if (! file_hdrp->entry_offset)
1468 abfd->flags |= HAS_RELOC;
1469 else
1470 abfd->flags |= EXEC_P;
1471 if (file_hdrp->symbol_total)
1472 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
1473
1474 bfd_get_start_address (abfd) = aux_hdrp->exec_entry;
1475 bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 0);
1476 bfd_get_symcount (abfd) = file_hdrp->symbol_total;
1477
1478 /* Initialize the saved symbol table and string table to NULL.
1479 Save important offsets and sizes from the SOM header into
1480 the BFD. */
1481 obj_som_stringtab (abfd) = (char *) NULL;
1482 obj_som_symtab (abfd) = (som_symbol_type *) NULL;
1483 obj_som_stringtab_size (abfd) = file_hdrp->symbol_strings_size;
1484 obj_som_sym_filepos (abfd) = file_hdrp->symbol_location;
1485 obj_som_str_filepos (abfd) = file_hdrp->symbol_strings_location;
1486 obj_som_reloc_filepos (abfd) = file_hdrp->fixup_request_location;
1487
1488 return abfd->xvec;
1489 }
1490
1491 /* Create a new BFD section for NAME. If NAME already exists, then create a
1492 new unique name, with NAME as the prefix. This exists because SOM .o files
1493 may have more than one $CODE$ subspace. */
1494
1495 static asection *
1496 make_unique_section (abfd, name, num)
1497 bfd *abfd;
1498 CONST char *name;
1499 int num;
1500 {
1501 asection *sect;
1502 char *newname;
1503 char altname[100];
1504
1505 sect = bfd_make_section (abfd, name);
1506 while (!sect)
1507 {
1508 sprintf (altname, "%s-%d", name, num++);
1509 sect = bfd_make_section (abfd, altname);
1510 }
1511
1512 newname = bfd_alloc (abfd, strlen (sect->name) + 1);
1513 strcpy (newname, sect->name);
1514
1515 sect->name = newname;
1516 return sect;
1517 }
1518
1519 /* Convert all of the space and subspace info into BFD sections. Each space
1520 contains a number of subspaces, which in turn describe the mapping between
1521 regions of the exec file, and the address space that the program runs in.
1522 BFD sections which correspond to spaces will overlap the sections for the
1523 associated subspaces. */
1524
1525 static boolean
1526 setup_sections (abfd, file_hdr)
1527 bfd *abfd;
1528 struct header *file_hdr;
1529 {
1530 char *space_strings;
1531 int space_index;
1532 unsigned int total_subspaces = 0;
1533
1534 /* First, read in space names */
1535
1536 space_strings = alloca (file_hdr->space_strings_size);
1537 if (!space_strings)
1538 return false;
1539
1540 if (bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET) < 0)
1541 return false;
1542 if (bfd_read (space_strings, 1, file_hdr->space_strings_size, abfd)
1543 != file_hdr->space_strings_size)
1544 return false;
1545
1546 /* Loop over all of the space dictionaries, building up sections */
1547 for (space_index = 0; space_index < file_hdr->space_total; space_index++)
1548 {
1549 struct space_dictionary_record space;
1550 struct subspace_dictionary_record subspace, save_subspace;
1551 int subspace_index;
1552 asection *space_asect;
1553
1554 /* Read the space dictionary element */
1555 if (bfd_seek (abfd, file_hdr->space_location
1556 + space_index * sizeof space, SEEK_SET) < 0)
1557 return false;
1558 if (bfd_read (&space, 1, sizeof space, abfd) != sizeof space)
1559 return false;
1560
1561 /* Setup the space name string */
1562 space.name.n_name = space.name.n_strx + space_strings;
1563
1564 /* Make a section out of it */
1565 space_asect = make_unique_section (abfd, space.name.n_name, space_index);
1566 if (!space_asect)
1567 return false;
1568
1569 /* Now, read in the first subspace for this space */
1570 if (bfd_seek (abfd, file_hdr->subspace_location
1571 + space.subspace_index * sizeof subspace,
1572 SEEK_SET) < 0)
1573 return false;
1574 if (bfd_read (&subspace, 1, sizeof subspace, abfd) != sizeof subspace)
1575 return false;
1576 /* Seek back to the start of the subspaces for loop below */
1577 if (bfd_seek (abfd, file_hdr->subspace_location
1578 + space.subspace_index * sizeof subspace,
1579 SEEK_SET) < 0)
1580 return false;
1581
1582 /* Setup the start address and file loc from the first subspace record */
1583 space_asect->vma = subspace.subspace_start;
1584 space_asect->filepos = subspace.file_loc_init_value;
1585 space_asect->alignment_power = log2 (subspace.alignment);
1586
1587 /* Initialize save_subspace so we can reliably determine if this
1588 loop placed any useful values into it. */
1589 bzero (&save_subspace, sizeof (struct subspace_dictionary_record));
1590
1591 /* Loop over the rest of the subspaces, building up more sections */
1592 for (subspace_index = 0; subspace_index < space.subspace_quantity;
1593 subspace_index++)
1594 {
1595 asection *subspace_asect;
1596
1597 /* Read in the next subspace */
1598 if (bfd_read (&subspace, 1, sizeof subspace, abfd)
1599 != sizeof subspace)
1600 return false;
1601
1602 /* Setup the subspace name string */
1603 subspace.name.n_name = subspace.name.n_strx + space_strings;
1604
1605 /* Make a section out of this subspace */
1606 subspace_asect = make_unique_section (abfd, subspace.name.n_name,
1607 space.subspace_index + subspace_index);
1608
1609 if (!subspace_asect)
1610 return false;
1611
1612 /* Keep an easy mapping between subspaces and sections. */
1613 som_section_data (subspace_asect)->subspace_index
1614 = total_subspaces++;
1615
1616 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
1617 by the access_control_bits in the subspace header. */
1618 switch (subspace.access_control_bits >> 4)
1619 {
1620 /* Readonly data. */
1621 case 0x0:
1622 subspace_asect->flags |= SEC_DATA | SEC_READONLY;
1623 break;
1624
1625 /* Normal data. */
1626 case 0x1:
1627 subspace_asect->flags |= SEC_DATA;
1628 break;
1629
1630 /* Readonly code and the gateways.
1631 Gateways have other attributes which do not map
1632 into anything BFD knows about. */
1633 case 0x2:
1634 case 0x4:
1635 case 0x5:
1636 case 0x6:
1637 case 0x7:
1638 subspace_asect->flags |= SEC_CODE | SEC_READONLY;
1639 break;
1640
1641 /* dynamic (writable) code. */
1642 case 0x3:
1643 subspace_asect->flags |= SEC_CODE;
1644 break;
1645 }
1646
1647 if (subspace.dup_common || subspace.is_common)
1648 subspace_asect->flags |= SEC_IS_COMMON;
1649 else if (subspace.subspace_length > 0)
1650 subspace_asect->flags |= SEC_HAS_CONTENTS;
1651 if (subspace.is_loadable)
1652 subspace_asect->flags |= SEC_ALLOC | SEC_LOAD;
1653 if (subspace.code_only)
1654 subspace_asect->flags |= SEC_CODE;
1655
1656 /* Both file_loc_init_value and initialization_length will
1657 be zero for a BSS like subspace. */
1658 if (subspace.file_loc_init_value == 0
1659 && subspace.initialization_length == 0)
1660 subspace_asect->flags &= ~(SEC_DATA | SEC_LOAD);
1661
1662 /* This subspace has relocations.
1663 The fixup_request_quantity is a byte count for the number of
1664 entries in the relocation stream; it is not the actual number
1665 of relocations in the subspace. */
1666 if (subspace.fixup_request_quantity != 0)
1667 {
1668 subspace_asect->flags |= SEC_RELOC;
1669 subspace_asect->rel_filepos = subspace.fixup_request_index;
1670 som_section_data (subspace_asect)->reloc_size
1671 = subspace.fixup_request_quantity;
1672 /* We can not determine this yet. When we read in the
1673 relocation table the correct value will be filled in. */
1674 subspace_asect->reloc_count = -1;
1675 }
1676
1677 /* Update save_subspace if appropriate. */
1678 if (subspace.file_loc_init_value > save_subspace.file_loc_init_value)
1679 save_subspace = subspace;
1680
1681 subspace_asect->vma = subspace.subspace_start;
1682 subspace_asect->_cooked_size = subspace.subspace_length;
1683 subspace_asect->_raw_size = subspace.subspace_length;
1684 subspace_asect->alignment_power = log2 (subspace.alignment);
1685 subspace_asect->filepos = subspace.file_loc_init_value;
1686 }
1687
1688 /* Yow! there is no subspace within the space which actually
1689 has initialized information in it; this should never happen
1690 as far as I know. */
1691 if (!save_subspace.file_loc_init_value)
1692 abort ();
1693
1694 /* Setup the sizes for the space section based upon the info in the
1695 last subspace of the space. */
1696 space_asect->_cooked_size = save_subspace.subspace_start
1697 - space_asect->vma + save_subspace.subspace_length;
1698 space_asect->_raw_size = save_subspace.file_loc_init_value
1699 - space_asect->filepos + save_subspace.initialization_length;
1700 }
1701 return true;
1702 }
1703
1704 /* Read in a SOM object and make it into a BFD. */
1705
1706 static bfd_target *
1707 som_object_p (abfd)
1708 bfd *abfd;
1709 {
1710 struct header file_hdr;
1711 struct som_exec_auxhdr aux_hdr;
1712
1713 if (bfd_read ((PTR) & file_hdr, 1, FILE_HDR_SIZE, abfd) != FILE_HDR_SIZE)
1714 {
1715 bfd_error = system_call_error;
1716 return 0;
1717 }
1718
1719 if (!_PA_RISC_ID (file_hdr.system_id))
1720 {
1721 bfd_error = wrong_format;
1722 return 0;
1723 }
1724
1725 switch (file_hdr.a_magic)
1726 {
1727 case RELOC_MAGIC:
1728 case EXEC_MAGIC:
1729 case SHARE_MAGIC:
1730 case DEMAND_MAGIC:
1731 #ifdef DL_MAGIC
1732 case DL_MAGIC:
1733 #endif
1734 #ifdef SHL_MAGIC
1735 case SHL_MAGIC:
1736 #endif
1737 #ifdef EXECLIBMAGIC
1738 case EXECLIBMAGIC:
1739 #endif
1740 #ifdef SHARED_MAGIC_CNX
1741 case SHARED_MAGIC_CNX:
1742 #endif
1743 break;
1744 default:
1745 bfd_error = wrong_format;
1746 return 0;
1747 }
1748
1749 if (file_hdr.version_id != VERSION_ID
1750 && file_hdr.version_id != NEW_VERSION_ID)
1751 {
1752 bfd_error = wrong_format;
1753 return 0;
1754 }
1755
1756 /* If the aux_header_size field in the file header is zero, then this
1757 object is an incomplete executable (a .o file). Do not try to read
1758 a non-existant auxiliary header. */
1759 bzero (&aux_hdr, sizeof (struct som_exec_auxhdr));
1760 if (file_hdr.aux_header_size != 0)
1761 {
1762 if (bfd_read ((PTR) & aux_hdr, 1, AUX_HDR_SIZE, abfd) != AUX_HDR_SIZE)
1763 {
1764 bfd_error = wrong_format;
1765 return 0;
1766 }
1767 }
1768
1769 if (!setup_sections (abfd, &file_hdr))
1770 {
1771 /* setup_sections does not bubble up a bfd error code. */
1772 bfd_error = bad_value;
1773 return 0;
1774 }
1775
1776 /* This appears to be a valid SOM object. Do some initialization. */
1777 return som_object_setup (abfd, &file_hdr, &aux_hdr);
1778 }
1779
1780 /* Create a SOM object. */
1781
1782 static boolean
1783 som_mkobject (abfd)
1784 bfd *abfd;
1785 {
1786 /* Allocate memory to hold backend information. */
1787 abfd->tdata.som_data = (struct som_data_struct *)
1788 bfd_zalloc (abfd, sizeof (struct som_data_struct));
1789 if (abfd->tdata.som_data == NULL)
1790 {
1791 bfd_error = no_memory;
1792 return false;
1793 }
1794 obj_som_file_hdr (abfd) = bfd_zalloc (abfd, sizeof (struct header));
1795 if (obj_som_file_hdr (abfd) == NULL)
1796
1797 {
1798 bfd_error = no_memory;
1799 return false;
1800 }
1801 return true;
1802 }
1803
1804 /* Initialize some information in the file header. This routine makes
1805 not attempt at doing the right thing for a full executable; it
1806 is only meant to handle relocatable objects. */
1807
1808 static boolean
1809 som_prep_headers (abfd)
1810 bfd *abfd;
1811 {
1812 struct header *file_hdr = obj_som_file_hdr (abfd);
1813 asection *section;
1814
1815 /* FIXME. This should really be conditional based on whether or not
1816 PA1.1 instructions/registers have been used. */
1817 file_hdr->system_id = HP9000S800_ID;
1818
1819 /* FIXME. Only correct for building relocatable objects. */
1820 if (abfd->flags & EXEC_P)
1821 abort ();
1822 else
1823 file_hdr->a_magic = RELOC_MAGIC;
1824
1825 /* Only new format SOM is supported. */
1826 file_hdr->version_id = NEW_VERSION_ID;
1827
1828 /* These fields are optional, and embedding timestamps is not always
1829 a wise thing to do, it makes comparing objects during a multi-stage
1830 bootstrap difficult. */
1831 file_hdr->file_time.secs = 0;
1832 file_hdr->file_time.nanosecs = 0;
1833
1834 if (abfd->flags & EXEC_P)
1835 abort ();
1836 else
1837 {
1838 file_hdr->entry_space = 0;
1839 file_hdr->entry_subspace = 0;
1840 file_hdr->entry_offset = 0;
1841 }
1842
1843 /* FIXME. I do not know if we ever need to put anything other
1844 than zero in this field. */
1845 file_hdr->presumed_dp = 0;
1846
1847 /* Now iterate over the sections translating information from
1848 BFD sections to SOM spaces/subspaces. */
1849
1850 for (section = abfd->sections; section != NULL; section = section->next)
1851 {
1852 /* Ignore anything which has not been marked as a space or
1853 subspace. */
1854 if (som_section_data (section)->is_space == 0
1855
1856 && som_section_data (section)->is_subspace == 0)
1857 continue;
1858
1859 if (som_section_data (section)->is_space)
1860 {
1861 /* Set space attributes. Note most attributes of SOM spaces
1862 are set based on the subspaces it contains. */
1863 som_section_data (section)->space_dict.loader_fix_index = -1;
1864 som_section_data (section)->space_dict.init_pointer_index = -1;
1865 }
1866 else
1867 {
1868 /* Set subspace attributes. Basic stuff is done here, additional
1869 attributes are filled in later as more information becomes
1870 available. */
1871 if (section->flags & SEC_IS_COMMON)
1872 {
1873 som_section_data (section)->subspace_dict.dup_common = 1;
1874 som_section_data (section)->subspace_dict.is_common = 1;
1875 }
1876
1877 if (section->flags & SEC_ALLOC)
1878 som_section_data (section)->subspace_dict.is_loadable = 1;
1879
1880 if (section->flags & SEC_CODE)
1881 som_section_data (section)->subspace_dict.code_only = 1;
1882
1883 som_section_data (section)->subspace_dict.subspace_start =
1884 section->vma;
1885 som_section_data (section)->subspace_dict.subspace_length =
1886 bfd_section_size (abfd, section);
1887 som_section_data (section)->subspace_dict.initialization_length =
1888 bfd_section_size (abfd, section);
1889 som_section_data (section)->subspace_dict.alignment =
1890 1 << section->alignment_power;
1891 }
1892 }
1893 return true;
1894 }
1895
1896 /* Count and return the number of spaces attached to the given BFD. */
1897
1898 static unsigned long
1899 som_count_spaces (abfd)
1900 bfd *abfd;
1901 {
1902 int count = 0;
1903 asection *section;
1904
1905 for (section = abfd->sections; section != NULL; section = section->next)
1906 count += som_section_data (section)->is_space;
1907
1908 return count;
1909 }
1910
1911 /* Count the number of subspaces attached to the given BFD. */
1912
1913 static unsigned long
1914 som_count_subspaces (abfd)
1915 bfd *abfd;
1916 {
1917 int count = 0;
1918 asection *section;
1919
1920 for (section = abfd->sections; section != NULL; section = section->next)
1921 count += som_section_data (section)->is_subspace;
1922
1923 return count;
1924 }
1925
1926 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
1927
1928 We desire symbols to be ordered starting with the symbol with the
1929 highest relocation count down to the symbol with the lowest relocation
1930 count. Doing so compacts the relocation stream. */
1931
1932 static int
1933 compare_syms (sym1, sym2)
1934 asymbol **sym1;
1935 asymbol **sym2;
1936
1937 {
1938 unsigned int count1, count2;
1939
1940 /* Get relocation count for each symbol. Note that the count
1941 is stored in the udata pointer for section symbols! */
1942 if ((*sym1)->flags & BSF_SECTION_SYM)
1943 count1 = (int)(*sym1)->udata;
1944 else
1945 count1 = (*som_symbol_data ((*sym1)))->reloc_count;
1946
1947 if ((*sym2)->flags & BSF_SECTION_SYM)
1948 count2 = (int)(*sym2)->udata;
1949 else
1950 count2 = (*som_symbol_data ((*sym2)))->reloc_count;
1951
1952 /* Return the appropriate value. */
1953 if (count1 < count2)
1954 return 1;
1955 else if (count1 > count2)
1956 return -1;
1957 return 0;
1958 }
1959
1960 /* Perform various work in preparation for emitting the fixup stream. */
1961
1962 static void
1963 som_prep_for_fixups (abfd, syms, num_syms)
1964 bfd *abfd;
1965 asymbol **syms;
1966 unsigned long num_syms;
1967 {
1968 int i;
1969 asection *section;
1970
1971 /* Most SOM relocations involving a symbol have a length which is
1972 dependent on the index of the symbol. So symbols which are
1973 used often in relocations should have a small index. */
1974
1975 /* First initialize the counters for each symbol. */
1976 for (i = 0; i < num_syms; i++)
1977 {
1978 /* Handle a section symbol; these have no pointers back to the
1979 SOM symbol info. So we just use the pointer field (udata)
1980 to hold the relocation count.
1981
1982 FIXME. While we're here set the name of any section symbol
1983 to something which will not screw GDB. How do other formats
1984 deal with this?!? */
1985 if (som_symbol_data (syms[i]) == NULL)
1986 {
1987 syms[i]->flags |= BSF_SECTION_SYM;
1988 syms[i]->name = "L$0\002";
1989 syms[i]->udata = (PTR) 0;
1990 }
1991 else
1992 (*som_symbol_data (syms[i]))->reloc_count = 0;
1993 }
1994
1995 /* Now that the counters are initialized, make a weighted count
1996 of how often a given symbol is used in a relocation. */
1997 for (section = abfd->sections; section != NULL; section = section->next)
1998 {
1999 int i;
2000
2001 /* Does this section have any relocations? */
2002 if (section->reloc_count <= 0)
2003 continue;
2004
2005 /* Walk through each relocation for this section. */
2006 for (i = 1; i < section->reloc_count; i++)
2007 {
2008 arelent *reloc = section->orelocation[i];
2009 int scale;
2010
2011 /* If no symbol, then there is no counter to increase. */
2012 if (reloc->sym_ptr_ptr == NULL)
2013 continue;
2014
2015 /* Scaling to encourage symbols involved in R_DP_RELATIVE
2016 and R_CODE_ONE_SYMBOL relocations to come first. These
2017 two relocations have single byte versions if the symbol
2018 index is very small. */
2019 if (reloc->howto->type == R_DP_RELATIVE
2020 || reloc->howto->type == R_CODE_ONE_SYMBOL)
2021 scale = 2;
2022 else
2023 scale = 1;
2024
2025 /* Handle section symbols by ramming the count in the udata
2026 field. It will not be used and the count is very important
2027 for these symbols. */
2028 if ((*reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
2029 {
2030 (*reloc->sym_ptr_ptr)->udata =
2031 (PTR) ((int) (*reloc->sym_ptr_ptr)->udata + scale);
2032 continue;
2033 }
2034
2035 /* A normal symbol. Increment the count. */
2036 (*som_symbol_data ((*reloc->sym_ptr_ptr)))->reloc_count += scale;
2037 }
2038 }
2039
2040 /* Now sort the symbols. */
2041 qsort (syms, num_syms, sizeof (asymbol *), compare_syms);
2042
2043 /* Compute the symbol indexes, they will be needed by the relocation
2044 code. */
2045 for (i = 0; i < num_syms; i++)
2046 {
2047 /* A section symbol. Again, there is no pointer to backend symbol
2048 information, so we reuse (abuse) the udata field again. */
2049 if (syms[i]->flags & BSF_SECTION_SYM)
2050 syms[i]->udata = (PTR) i;
2051 else
2052 (*som_symbol_data (syms[i]))->index = i;
2053 }
2054 }
2055
2056 static boolean
2057 som_write_fixups (abfd, current_offset, total_reloc_sizep)
2058 bfd *abfd;
2059 unsigned long current_offset;
2060 unsigned int *total_reloc_sizep;
2061 {
2062 unsigned int i, j;
2063 unsigned char *tmp_space, *p;
2064 unsigned int total_reloc_size = 0;
2065 unsigned int subspace_reloc_size = 0;
2066 unsigned int num_spaces = obj_som_file_hdr (abfd)->space_total;
2067 asection *section = abfd->sections;
2068
2069 /* Get a chunk of memory that we can use as buffer space, then throw
2070 away. */
2071 tmp_space = alloca (SOM_TMP_BUFSIZE);
2072 bzero (tmp_space, SOM_TMP_BUFSIZE);
2073 p = tmp_space;
2074
2075 /* All the fixups for a particular subspace are emitted in a single
2076 stream. All the subspaces for a particular space are emitted
2077 as a single stream.
2078
2079 So, to get all the locations correct one must iterate through all the
2080 spaces, for each space iterate through its subspaces and output a
2081 fixups stream. */
2082 for (i = 0; i < num_spaces; i++)
2083 {
2084 asection *subsection;
2085
2086 /* Find a space. */
2087 while (som_section_data (section)->is_space == 0)
2088 section = section->next;
2089
2090 /* Now iterate through each of its subspaces. */
2091 for (subsection = abfd->sections;
2092 subsection != NULL;
2093 subsection = subsection->next)
2094 {
2095 int reloc_offset, current_rounding_mode;
2096
2097 /* Find a subspace of this space. */
2098 if (som_section_data (subsection)->is_subspace == 0
2099 || som_section_data (subsection)->containing_space != section)
2100 continue;
2101
2102 /* If this subspace had no relocations, then we're finished
2103 with it. */
2104 if (subsection->reloc_count <= 0)
2105 {
2106 som_section_data (subsection)->subspace_dict.fixup_request_index
2107 = -1;
2108 continue;
2109 }
2110
2111 /* This subspace has some relocations. Put the relocation stream
2112 index into the subspace record. */
2113 som_section_data (subsection)->subspace_dict.fixup_request_index
2114 = total_reloc_size;
2115
2116 /* To make life easier start over with a clean slate for
2117 each subspace. Seek to the start of the relocation stream
2118 for this subspace in preparation for writing out its fixup
2119 stream. */
2120 if (bfd_seek (abfd, current_offset + total_reloc_size, SEEK_SET) != 0)
2121 {
2122 bfd_error = system_call_error;
2123 return false;
2124 }
2125
2126 /* Buffer space has already been allocated. Just perform some
2127 initialization here. */
2128 p = tmp_space;
2129 subspace_reloc_size = 0;
2130 reloc_offset = 0;
2131 som_initialize_reloc_queue (reloc_queue);
2132 current_rounding_mode = R_N_MODE;
2133
2134 /* Translate each BFD relocation into one or more SOM
2135 relocations. */
2136 for (j = 0; j < subsection->reloc_count; j++)
2137 {
2138 arelent *bfd_reloc = subsection->orelocation[j];
2139 unsigned int skip;
2140 int sym_num;
2141
2142 /* Get the symbol number. Remember it's stored in a
2143 special place for section symbols. */
2144 if ((*bfd_reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
2145 sym_num = (int) (*bfd_reloc->sym_ptr_ptr)->udata;
2146 else
2147 sym_num = (*som_symbol_data ((*bfd_reloc->sym_ptr_ptr)))->index;
2148
2149 /* If there is not enough room for the next couple relocations,
2150 then dump the current buffer contents now. Also reinitialize
2151 the relocation queue.
2152
2153 FIXME. We assume here that no BFD relocation will expand
2154 to more than 100 bytes of SOM relocations. This should (?!?)
2155 be quite safe. */
2156 if (p - tmp_space + 100 > SOM_TMP_BUFSIZE)
2157 {
2158 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2159 != p - tmp_space)
2160 {
2161 bfd_error = system_call_error;
2162 return false;
2163 }
2164 p = tmp_space;
2165 som_initialize_reloc_queue (reloc_queue);
2166 }
2167
2168 /* Emit R_NO_RELOCATION fixups to map any bytes which were
2169 skipped. */
2170 skip = bfd_reloc->address - reloc_offset;
2171 p = som_reloc_skip (abfd, skip, p,
2172 &subspace_reloc_size, reloc_queue);
2173
2174 /* Update reloc_offset for the next iteration.
2175
2176 Many relocations do not consume input bytes. They
2177 are markers, or set state necessary to perform some
2178 later relocation. */
2179 switch (bfd_reloc->howto->type)
2180 {
2181 /* This only needs to handle relocations that may be
2182 made by hppa_som_gen_reloc. */
2183 case R_ENTRY:
2184 case R_EXIT:
2185 case R_N_MODE:
2186 case R_S_MODE:
2187 case R_D_MODE:
2188 case R_R_MODE:
2189 reloc_offset = bfd_reloc->address;
2190 break;
2191
2192 default:
2193 reloc_offset = bfd_reloc->address + 4;
2194 break;
2195 }
2196
2197 /* Now the actual relocation we care about. */
2198 switch (bfd_reloc->howto->type)
2199 {
2200 case R_PCREL_CALL:
2201 case R_ABS_CALL:
2202 p = som_reloc_call (abfd, p, &subspace_reloc_size,
2203 bfd_reloc, sym_num, reloc_queue);
2204 break;
2205
2206 case R_CODE_ONE_SYMBOL:
2207 case R_DP_RELATIVE:
2208 /* Account for any addend. */
2209 if (bfd_reloc->addend)
2210 p = som_reloc_addend (abfd, bfd_reloc->addend, p,
2211 &subspace_reloc_size, reloc_queue);
2212
2213 if (sym_num < 0x20)
2214 {
2215 bfd_put_8 (abfd, bfd_reloc->howto->type + sym_num, p);
2216 subspace_reloc_size += 1;
2217 p += 1;
2218 }
2219 else if (sym_num < 0x100)
2220 {
2221 bfd_put_8 (abfd, bfd_reloc->howto->type + 32, p);
2222 bfd_put_8 (abfd, sym_num, p + 1);
2223 p = try_prev_fixup (abfd, &subspace_reloc_size, p,
2224 2, reloc_queue);
2225 }
2226 else if (sym_num < 0x10000000)
2227 {
2228 bfd_put_8 (abfd, bfd_reloc->howto->type + 33, p);
2229 bfd_put_8 (abfd, sym_num >> 16, p + 1);
2230 bfd_put_16 (abfd, sym_num, p + 2);
2231 p = try_prev_fixup (abfd, &subspace_reloc_size,
2232 p, 4, reloc_queue);
2233 }
2234 else
2235 abort ();
2236 break;
2237
2238 case R_DATA_ONE_SYMBOL:
2239 case R_DATA_PLABEL:
2240 case R_CODE_PLABEL:
2241 /* Account for any addend. */
2242 if (bfd_reloc->addend)
2243 p = som_reloc_addend (abfd, bfd_reloc->addend, p,
2244 &subspace_reloc_size, reloc_queue);
2245
2246 if (sym_num < 0x100)
2247 {
2248 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2249 bfd_put_8 (abfd, sym_num, p + 1);
2250 p = try_prev_fixup (abfd, &subspace_reloc_size, p,
2251 2, reloc_queue);
2252 }
2253 else if (sym_num < 0x10000000)
2254 {
2255 bfd_put_8 (abfd, bfd_reloc->howto->type + 1, p);
2256 bfd_put_8 (abfd, sym_num >> 16, p + 1);
2257 bfd_put_16 (abfd, sym_num, p + 2);
2258 p = try_prev_fixup (abfd, &subspace_reloc_size,
2259 p, 4, reloc_queue);
2260 }
2261 else
2262 abort ();
2263 break;
2264
2265 case R_ENTRY:
2266 {
2267 int *descp
2268 = (int *) (*som_symbol_data ((*bfd_reloc->sym_ptr_ptr)))->unwind;
2269 bfd_put_8 (abfd, R_ENTRY, p);
2270 bfd_put_32 (abfd, descp[0], p + 1);
2271 bfd_put_32 (abfd, descp[1], p + 5);
2272 p = try_prev_fixup (abfd, &subspace_reloc_size,
2273 p, 9, reloc_queue);
2274 break;
2275 }
2276
2277 case R_EXIT:
2278 bfd_put_8 (abfd, R_EXIT, p);
2279 subspace_reloc_size += 1;
2280 p += 1;
2281 break;
2282
2283 case R_N_MODE:
2284 case R_S_MODE:
2285 case R_D_MODE:
2286 case R_R_MODE:
2287 /* If this relocation requests the current rounding
2288 mode, then it is redundant. */
2289 if (bfd_reloc->howto->type != current_rounding_mode)
2290 {
2291 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2292 subspace_reloc_size += 1;
2293 p += 1;
2294 current_rounding_mode = bfd_reloc->howto->type;
2295 }
2296 break;
2297
2298 /* Put a "R_RESERVED" relocation in the stream if
2299 we hit something we do not understand. The linker
2300 will complain loudly if this ever happens. */
2301 default:
2302 bfd_put_8 (abfd, 0xff, p);
2303 subspace_reloc_size += 1;
2304 p += 1;
2305 break;
2306 }
2307 }
2308
2309 /* Last BFD relocation for a subspace has been processed.
2310 Map the rest of the subspace with R_NO_RELOCATION fixups. */
2311 p = som_reloc_skip (abfd, bfd_section_size (abfd, subsection)
2312 - reloc_offset,
2313 p, &subspace_reloc_size, reloc_queue);
2314
2315 /* Scribble out the relocations. */
2316 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2317 != p - tmp_space)
2318 {
2319 bfd_error = system_call_error;
2320 return false;
2321 }
2322 p = tmp_space;
2323
2324 total_reloc_size += subspace_reloc_size;
2325 som_section_data (subsection)->subspace_dict.fixup_request_quantity
2326 = subspace_reloc_size;
2327 }
2328 section = section->next;
2329 }
2330 *total_reloc_sizep = total_reloc_size;
2331 return true;
2332 }
2333
2334 /* Write out the space/subspace string table. */
2335
2336 static boolean
2337 som_write_space_strings (abfd, current_offset, string_sizep)
2338 bfd *abfd;
2339 unsigned long current_offset;
2340 unsigned int *string_sizep;
2341 {
2342 unsigned char *tmp_space, *p;
2343 unsigned int strings_size = 0;
2344 asection *section;
2345
2346 /* Get a chunk of memory that we can use as buffer space, then throw
2347 away. */
2348 tmp_space = alloca (SOM_TMP_BUFSIZE);
2349 bzero (tmp_space, SOM_TMP_BUFSIZE);
2350 p = tmp_space;
2351
2352 /* Seek to the start of the space strings in preparation for writing
2353 them out. */
2354 if (bfd_seek (abfd, current_offset, SEEK_SET) != 0)
2355 {
2356 bfd_error = system_call_error;
2357 return false;
2358 }
2359
2360 /* Walk through all the spaces and subspaces (order is not important)
2361 building up and writing string table entries for their names. */
2362 for (section = abfd->sections; section != NULL; section = section->next)
2363 {
2364 int length;
2365
2366 /* Only work with space/subspaces; avoid any other sections
2367 which might have been made (.text for example). */
2368 if (som_section_data (section)->is_space == 0
2369 && som_section_data (section)->is_subspace == 0)
2370 continue;
2371
2372 /* Get the length of the space/subspace name. */
2373 length = strlen (section->name);
2374
2375 /* If there is not enough room for the next entry, then dump the
2376 current buffer contents now. Each entry will take 4 bytes to
2377 hold the string length + the string itself + null terminator. */
2378 if (p - tmp_space + 5 + length > SOM_TMP_BUFSIZE)
2379 {
2380 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2381 != p - tmp_space)
2382 {
2383 bfd_error = system_call_error;
2384 return false;
2385 }
2386 /* Reset to beginning of the buffer space. */
2387 p = tmp_space;
2388 }
2389
2390 /* First element in a string table entry is the length of the
2391 string. Alignment issues are already handled. */
2392 bfd_put_32 (abfd, length, p);
2393 p += 4;
2394 strings_size += 4;
2395
2396 /* Record the index in the space/subspace records. */
2397 if (som_section_data (section)->is_space)
2398 som_section_data (section)->space_dict.name.n_strx = strings_size;
2399 else
2400 som_section_data (section)->subspace_dict.name.n_strx = strings_size;
2401
2402 /* Next comes the string itself + a null terminator. */
2403 strcpy (p, section->name);
2404 p += length + 1;
2405 strings_size += length + 1;
2406
2407 /* Always align up to the next word boundary. */
2408 while (strings_size % 4)
2409 {
2410 bfd_put_8 (abfd, 0, p);
2411 p++;
2412 strings_size++;
2413 }
2414 }
2415
2416 /* Done with the space/subspace strings. Write out any information
2417 contained in a partial block. */
2418 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd) != p - tmp_space)
2419 {
2420 bfd_error = system_call_error;
2421 return false;
2422 }
2423 *string_sizep = strings_size;
2424 return true;
2425 }
2426
2427 /* Write out the symbol string table. */
2428
2429 static boolean
2430 som_write_symbol_strings (abfd, current_offset, syms, num_syms, string_sizep)
2431 bfd *abfd;
2432 unsigned long current_offset;
2433 asymbol **syms;
2434 unsigned int num_syms;
2435 unsigned int *string_sizep;
2436 {
2437 unsigned int i;
2438 unsigned char *tmp_space, *p;
2439 unsigned int strings_size = 0;
2440
2441 /* Get a chunk of memory that we can use as buffer space, then throw
2442 away. */
2443 tmp_space = alloca (SOM_TMP_BUFSIZE);
2444 bzero (tmp_space, SOM_TMP_BUFSIZE);
2445 p = tmp_space;
2446
2447 /* Seek to the start of the space strings in preparation for writing
2448 them out. */
2449 if (bfd_seek (abfd, current_offset, SEEK_SET) != 0)
2450 {
2451 bfd_error = system_call_error;
2452 return false;
2453 }
2454
2455 for (i = 0; i < num_syms; i++)
2456 {
2457 int length = strlen (syms[i]->name);
2458
2459 /* If there is not enough room for the next entry, then dump the
2460 current buffer contents now. */
2461 if (p - tmp_space + 5 + length > SOM_TMP_BUFSIZE)
2462 {
2463 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2464 != p - tmp_space)
2465 {
2466 bfd_error = system_call_error;
2467 return false;
2468 }
2469 /* Reset to beginning of the buffer space. */
2470 p = tmp_space;
2471 }
2472
2473 /* First element in a string table entry is the length of the
2474 string. This must always be 4 byte aligned. This is also
2475 an appropriate time to fill in the string index field in the
2476 symbol table entry. */
2477 bfd_put_32 (abfd, length, p);
2478 strings_size += 4;
2479 p += 4;
2480
2481 /* Next comes the string itself + a null terminator. */
2482 strcpy (p, syms[i]->name);
2483
2484 /* ACK. FIXME. */
2485 syms[i]->name = (char *)strings_size;
2486 p += length + 1;
2487 strings_size += length + 1;
2488
2489 /* Always align up to the next word boundary. */
2490 while (strings_size % 4)
2491 {
2492 bfd_put_8 (abfd, 0, p);
2493 strings_size++;
2494 p++;
2495 }
2496 }
2497
2498 /* Scribble out any partial block. */
2499 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd) != p - tmp_space)
2500 {
2501 bfd_error = system_call_error;
2502 return false;
2503 }
2504
2505 *string_sizep = strings_size;
2506 return true;
2507 }
2508
2509 /* Compute variable information to be placed in the SOM headers,
2510 space/subspace dictionaries, relocation streams, etc. Begin
2511 writing parts of the object file. */
2512
2513 static boolean
2514 som_begin_writing (abfd)
2515 bfd *abfd;
2516 {
2517 unsigned long current_offset = 0;
2518 int strings_size = 0;
2519 unsigned int total_reloc_size = 0;
2520 unsigned long num_spaces, num_subspaces, num_syms, i;
2521 asection *section;
2522 asymbol **syms = bfd_get_outsymbols (abfd);
2523 unsigned int total_subspaces = 0;
2524
2525 /* The file header will always be first in an object file,
2526 everything else can be in random locations. To keep things
2527 "simple" BFD will lay out the object file in the manner suggested
2528 by the PRO ABI for PA-RISC Systems. */
2529
2530 /* Before any output can really begin offsets for all the major
2531 portions of the object file must be computed. So, starting
2532 with the initial file header compute (and sometimes write)
2533 each portion of the object file. */
2534
2535 /* Make room for the file header, it's contents are not complete
2536 yet, so it can not be written at this time. */
2537 current_offset += sizeof (struct header);
2538
2539 /* Any auxiliary headers will follow the file header. Right now
2540 we have no auxiliary headers, so current_offset does not change. */
2541 obj_som_file_hdr (abfd)->aux_header_location = current_offset;
2542 obj_som_file_hdr (abfd)->aux_header_size = 0;
2543
2544 /* Next comes the initialization pointers; again we have no
2545 initialization pointers, so current offset does not change. */
2546 obj_som_file_hdr (abfd)->init_array_location = current_offset;
2547 obj_som_file_hdr (abfd)->init_array_total = 0;
2548
2549 /* Next are the space records. These are fixed length records.
2550
2551 Count the number of spaces to determine how much room is needed
2552 in the object file for the space records.
2553
2554 The names of the spaces are stored in a separate string table,
2555 and the index for each space into the string table is computed
2556 below. Therefore, it is not possible to write the space headers
2557 at this time. */
2558 num_spaces = som_count_spaces (abfd);
2559 obj_som_file_hdr (abfd)->space_location = current_offset;
2560 obj_som_file_hdr (abfd)->space_total = num_spaces;
2561 current_offset += num_spaces * sizeof (struct space_dictionary_record);
2562
2563 /* Next are the subspace records. These are fixed length records.
2564
2565 Count the number of subspaes to determine how much room is needed
2566 in the object file for the subspace records.
2567
2568 A variety if fields in the subspace record are still unknown at
2569 this time (index into string table, fixup stream location/size, etc). */
2570 num_subspaces = som_count_subspaces (abfd);
2571 obj_som_file_hdr (abfd)->subspace_location = current_offset;
2572 obj_som_file_hdr (abfd)->subspace_total = num_subspaces;
2573 current_offset += num_subspaces * sizeof (struct subspace_dictionary_record);
2574
2575 /* Next is the string table for the space/subspace names. We will
2576 build and write the string table on the fly. At the same time
2577 we will fill in the space/subspace name index fields. */
2578
2579 /* The string table needs to be aligned on a word boundary. */
2580 if (current_offset % 4)
2581 current_offset += (4 - (current_offset % 4));
2582
2583 /* Mark the offset of the space/subspace string table in the
2584 file header. */
2585 obj_som_file_hdr (abfd)->space_strings_location = current_offset;
2586
2587 /* Scribble out the space strings. */
2588 if (som_write_space_strings (abfd, current_offset, &strings_size) == false)
2589 return false;
2590
2591 /* Record total string table size in the header and update the
2592 current offset. */
2593 obj_som_file_hdr (abfd)->space_strings_size = strings_size;
2594 current_offset += strings_size;
2595
2596 /* Next is the symbol table. These are fixed length records.
2597
2598 Count the number of symbols to determine how much room is needed
2599 in the object file for the symbol table.
2600
2601 The names of the symbols are stored in a separate string table,
2602 and the index for each symbol name into the string table is computed
2603 below. Therefore, it is not possible to write the symobl table
2604 at this time. */
2605 num_syms = bfd_get_symcount (abfd);
2606 obj_som_file_hdr (abfd)->symbol_location = current_offset;
2607 obj_som_file_hdr (abfd)->symbol_total = num_syms;
2608 current_offset += num_syms * sizeof (struct symbol_dictionary_record);
2609
2610 /* Do prep work before handling fixups. */
2611 som_prep_for_fixups (abfd, syms, num_syms);
2612
2613 /* Next comes the fixup stream which starts on a word boundary. */
2614 if (current_offset % 4)
2615 current_offset += (4 - (current_offset % 4));
2616 obj_som_file_hdr (abfd)->fixup_request_location = current_offset;
2617
2618 /* Write the fixups and update fields in subspace headers which
2619 relate to the fixup stream. */
2620 if (som_write_fixups (abfd, current_offset, &total_reloc_size) == false)
2621 return false;
2622
2623 /* Record the total size of the fixup stream in the file header. */
2624 obj_som_file_hdr (abfd)->fixup_request_total = total_reloc_size;
2625 current_offset += total_reloc_size;
2626
2627 /* Next are the symbol strings.
2628 Align them to a word boundary. */
2629 if (current_offset % 4)
2630 current_offset += (4 - (current_offset % 4));
2631 obj_som_file_hdr (abfd)->symbol_strings_location = current_offset;
2632
2633 /* Scribble out the symbol strings. */
2634 if (som_write_symbol_strings (abfd, current_offset, syms,
2635 num_syms, &strings_size)
2636 == false)
2637 return false;
2638
2639 /* Record total string table size in header and update the
2640 current offset. */
2641 obj_som_file_hdr (abfd)->symbol_strings_size = strings_size;
2642 current_offset += strings_size;
2643
2644 /* Next is the compiler records. We do not use these. */
2645 obj_som_file_hdr (abfd)->compiler_location = current_offset;
2646 obj_som_file_hdr (abfd)->compiler_total = 0;
2647
2648 /* Now compute the file positions for the loadable subspaces. */
2649
2650 section = abfd->sections;
2651 for (i = 0; i < num_spaces; i++)
2652 {
2653 asection *subsection;
2654
2655 /* Find a space. */
2656 while (som_section_data (section)->is_space == 0)
2657 section = section->next;
2658
2659 /* Now look for all its subspaces. */
2660 for (subsection = abfd->sections;
2661 subsection != NULL;
2662 subsection = subsection->next)
2663 {
2664
2665 if (som_section_data (subsection)->is_subspace == 0
2666 || som_section_data (subsection)->containing_space != section
2667 || (subsection->flags & SEC_ALLOC) == 0)
2668 continue;
2669
2670 som_section_data (subsection)->subspace_index = total_subspaces++;
2671 /* This is real data to be loaded from the file. */
2672 if (subsection->flags & SEC_LOAD)
2673 {
2674 som_section_data (subsection)->subspace_dict.file_loc_init_value
2675 = current_offset;
2676 section->filepos = current_offset;
2677 current_offset += bfd_section_size (abfd, subsection);
2678 }
2679 /* Looks like uninitialized data. */
2680 else
2681 {
2682 som_section_data (subsection)->subspace_dict.file_loc_init_value
2683 = 0;
2684 som_section_data (subsection)->subspace_dict.
2685 initialization_length = 0;
2686 }
2687 }
2688 /* Goto the next section. */
2689 section = section->next;
2690 }
2691
2692 /* Finally compute the file positions for unloadable subspaces. */
2693
2694 obj_som_file_hdr (abfd)->unloadable_sp_location = current_offset;
2695 section = abfd->sections;
2696 for (i = 0; i < num_spaces; i++)
2697 {
2698 asection *subsection;
2699
2700 /* Find a space. */
2701 while (som_section_data (section)->is_space == 0)
2702 section = section->next;
2703
2704 /* Now look for all its subspaces. */
2705 for (subsection = abfd->sections;
2706 subsection != NULL;
2707 subsection = subsection->next)
2708 {
2709
2710 if (som_section_data (subsection)->is_subspace == 0
2711 || som_section_data (subsection)->containing_space != section
2712 || (subsection->flags & SEC_ALLOC) != 0)
2713 continue;
2714
2715 som_section_data (subsection)->subspace_index = total_subspaces++;
2716 /* This is real data to be loaded from the file. */
2717 if ((subsection->flags & SEC_LOAD) == 0)
2718 {
2719 som_section_data (subsection)->subspace_dict.file_loc_init_value
2720 = current_offset;
2721 section->filepos = current_offset;
2722 current_offset += bfd_section_size (abfd, subsection);
2723 }
2724 /* Looks like uninitialized data. */
2725 else
2726 {
2727 som_section_data (subsection)->subspace_dict.file_loc_init_value
2728 = 0;
2729 som_section_data (subsection)->subspace_dict.
2730 initialization_length = bfd_section_size (abfd, subsection);
2731 }
2732 }
2733 /* Goto the next section. */
2734 section = section->next;
2735 }
2736
2737 obj_som_file_hdr (abfd)->unloadable_sp_size
2738 = current_offset - obj_som_file_hdr (abfd)->unloadable_sp_location;
2739
2740 /* Loader fixups are not supported in any way shape or form. */
2741 obj_som_file_hdr (abfd)->loader_fixup_location = 0;
2742 obj_som_file_hdr (abfd)->loader_fixup_total = 0;
2743
2744 /* Done. Store the total size of the SOM. */
2745 obj_som_file_hdr (abfd)->som_length = current_offset;
2746 return true;
2747 }
2748
2749 /* Finally, scribble out the various headers to the disk. */
2750
2751 static boolean
2752 som_write_headers (abfd)
2753 bfd *abfd;
2754 {
2755 int num_spaces = som_count_spaces (abfd);
2756 int i;
2757 int subspace_index = 0;
2758 file_ptr location;
2759 asection *section;
2760
2761 /* Subspaces are written first so that we can set up information
2762 about them in their containing spaces as the subspace is written. */
2763
2764 /* Seek to the start of the subspace dictionary records. */
2765 location = obj_som_file_hdr (abfd)->subspace_location;
2766 bfd_seek (abfd, location, SEEK_SET);
2767 section = abfd->sections;
2768 /* Now for each loadable space write out records for its subspaces. */
2769 for (i = 0; i < num_spaces; i++)
2770 {
2771 asection *subsection;
2772
2773 /* Find a space. */
2774 while (som_section_data (section)->is_space == 0)
2775 section = section->next;
2776
2777 /* Now look for all its subspaces. */
2778 for (subsection = abfd->sections;
2779 subsection != NULL;
2780 subsection = subsection->next)
2781 {
2782
2783 /* Skip any section which does not correspond to a space
2784 or subspace. Or does not have SEC_ALLOC set (and therefore
2785 has no real bits on the disk). */
2786 if (som_section_data (subsection)->is_subspace == 0
2787 || som_section_data (subsection)->containing_space != section
2788 || (subsection->flags & SEC_ALLOC) == 0)
2789 continue;
2790
2791 /* If this is the first subspace for this space, then save
2792 the index of the subspace in its containing space. Also
2793 set "is_loadable" in the containing space. */
2794
2795 if (som_section_data (section)->space_dict.subspace_quantity == 0)
2796 {
2797 som_section_data (section)->space_dict.is_loadable = 1;
2798 som_section_data (section)->space_dict.subspace_index
2799 = subspace_index;
2800 }
2801
2802 /* Increment the number of subspaces seen and the number of
2803 subspaces contained within the current space. */
2804 subspace_index++;
2805 som_section_data (section)->space_dict.subspace_quantity++;
2806
2807 /* Mark the index of the current space within the subspace's
2808 dictionary record. */
2809 som_section_data (subsection)->subspace_dict.space_index = i;
2810
2811 /* Dump the current subspace header. */
2812 if (bfd_write ((PTR) &som_section_data (subsection)->subspace_dict,
2813 sizeof (struct subspace_dictionary_record), 1, abfd)
2814 != sizeof (struct subspace_dictionary_record))
2815 {
2816 bfd_error = system_call_error;
2817 return false;
2818 }
2819 }
2820 /* Goto the next section. */
2821 section = section->next;
2822 }
2823
2824 /* Now repeat the process for unloadable subspaces. */
2825 section = abfd->sections;
2826 /* Now for each space write out records for its subspaces. */
2827 for (i = 0; i < num_spaces; i++)
2828 {
2829 asection *subsection;
2830
2831 /* Find a space. */
2832 while (som_section_data (section)->is_space == 0)
2833 section = section->next;
2834
2835 /* Now look for all its subspaces. */
2836 for (subsection = abfd->sections;
2837 subsection != NULL;
2838 subsection = subsection->next)
2839 {
2840
2841 /* Skip any section which does not correspond to a space or
2842 subspace, or which SEC_ALLOC set (and therefore handled
2843 in the loadable spaces/subspaces code above. */
2844
2845 if (som_section_data (subsection)->is_subspace == 0
2846 || som_section_data (subsection)->containing_space != section
2847 || (subsection->flags & SEC_ALLOC) != 0)
2848 continue;
2849
2850 /* If this is the first subspace for this space, then save
2851 the index of the subspace in its containing space. Clear
2852 "is_loadable". */
2853
2854 if (som_section_data (section)->space_dict.subspace_quantity == 0)
2855 {
2856 som_section_data (section)->space_dict.is_loadable = 0;
2857 som_section_data (section)->space_dict.subspace_index
2858 = subspace_index;
2859 }
2860
2861 /* Increment the number of subspaces seen and the number of
2862 subspaces contained within the current space. */
2863 som_section_data (section)->space_dict.subspace_quantity++;
2864 subspace_index++;
2865
2866 /* Mark the index of the current space within the subspace's
2867 dictionary record. */
2868 som_section_data (subsection)->subspace_dict.space_index = i;
2869
2870 /* Dump this subspace header. */
2871 if (bfd_write ((PTR) &som_section_data (subsection)->subspace_dict,
2872 sizeof (struct subspace_dictionary_record), 1, abfd)
2873 != sizeof (struct subspace_dictionary_record))
2874 {
2875 bfd_error = system_call_error;
2876 return false;
2877 }
2878 }
2879 /* Goto the next section. */
2880 section = section->next;
2881 }
2882
2883 /* All the subspace dictiondary records are written, and all the
2884 fields are set up in the space dictionary records.
2885
2886 Seek to the right location and start writing the space
2887 dictionary records. */
2888 location = obj_som_file_hdr (abfd)->space_location;
2889 bfd_seek (abfd, location, SEEK_SET);
2890
2891 section = abfd->sections;
2892 for (i = 0; i < num_spaces; i++)
2893 {
2894
2895 /* Find a space. */
2896 while (som_section_data (section)->is_space == 0)
2897 section = section->next;
2898
2899 /* Dump its header */
2900 if (bfd_write ((PTR) &som_section_data (section)->space_dict,
2901 sizeof (struct space_dictionary_record), 1, abfd)
2902 != sizeof (struct space_dictionary_record))
2903 {
2904 bfd_error = system_call_error;
2905 return false;
2906 }
2907
2908 /* Goto the next section. */
2909 section = section->next;
2910 }
2911
2912 /* Only thing left to do is write out the file header. It is always
2913 at location zero. Seek there and write it. */
2914 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
2915 if (bfd_write ((PTR) obj_som_file_hdr (abfd),
2916 sizeof (struct header), 1, abfd)
2917 != sizeof (struct header))
2918 {
2919 bfd_error = system_call_error;
2920 return false;
2921 }
2922 return true;
2923 }
2924
2925 /* Compute and return the checksum for a SOM file header. */
2926
2927 static unsigned long
2928 som_compute_checksum (abfd)
2929 bfd *abfd;
2930 {
2931 unsigned long checksum, count, i;
2932 unsigned long *buffer = (unsigned long *) obj_som_file_hdr (abfd);
2933
2934 checksum = 0;
2935 count = sizeof (struct header) / sizeof (unsigned long);
2936 for (i = 0; i < count; i++)
2937 checksum ^= *(buffer + i);
2938
2939 return checksum;
2940 }
2941
2942 /* Build and write, in one big chunk, the entire symbol table for
2943 this BFD. */
2944
2945 static boolean
2946 som_build_and_write_symbol_table (abfd)
2947 bfd *abfd;
2948 {
2949 unsigned int num_syms = bfd_get_symcount (abfd);
2950 file_ptr symtab_location = obj_som_file_hdr (abfd)->symbol_location;
2951 asymbol **bfd_syms = bfd_get_outsymbols (abfd);
2952 struct symbol_dictionary_record *som_symtab;
2953 int i, symtab_size;
2954
2955 /* Compute total symbol table size and allocate a chunk of memory
2956 to hold the symbol table as we build it. */
2957 symtab_size = num_syms * sizeof (struct symbol_dictionary_record);
2958 som_symtab = (struct symbol_dictionary_record *) alloca (symtab_size);
2959 bzero (som_symtab, symtab_size);
2960
2961 /* Walk over each symbol. */
2962 for (i = 0; i < num_syms; i++)
2963 {
2964 /* This is really an index into the symbol strings table.
2965 By the time we get here, the index has already been
2966 computed and stored into the name field in the BFD symbol. */
2967 som_symtab[i].name.n_strx = (int) bfd_syms[i]->name;
2968
2969 /* The HP SOM linker requires detailed type information about
2970 all symbols (including undefined symbols!). Unfortunately,
2971 the type specified in an import/export statement does not
2972 always match what the linker wants. Severe braindamage. */
2973
2974 /* Section symbols will not have a SOM symbol type assigned to
2975 them yet. Assign all section symbols type ST_DATA. */
2976 if (bfd_syms[i]->flags & BSF_SECTION_SYM)
2977 som_symtab[i].symbol_type = ST_DATA;
2978 else
2979 {
2980 /* Common symbols must have scope SS_UNSAT and type
2981 ST_STORAGE or the linker will choke. */
2982 if (bfd_syms[i]->section == &bfd_com_section)
2983 {
2984 som_symtab[i].symbol_scope = SS_UNSAT;
2985 som_symtab[i].symbol_type = ST_STORAGE;
2986 }
2987
2988 /* It is possible to have a symbol without an associated
2989 type. This happens if the user imported the symbol
2990 without a type and the symbol was never defined
2991 locally. If BSF_FUNCTION is set for this symbol, then
2992 assign it type ST_CODE (the HP linker requires undefined
2993 external functions to have type ST_CODE rather than ST_ENTRY. */
2994 else if (((*som_symbol_data (bfd_syms[i]))->som_type
2995 == SYMBOL_TYPE_UNKNOWN)
2996 && (bfd_syms[i]->section == &bfd_und_section)
2997 && (bfd_syms[i]->flags & BSF_FUNCTION))
2998 som_symtab[i].symbol_type = ST_CODE;
2999
3000 /* Handle function symbols which were defined in this file.
3001 They should have type ST_ENTRY. Also retrieve the argument
3002 relocation bits from the SOM backend information. */
3003 else if (((*som_symbol_data (bfd_syms[i]))->som_type
3004 == SYMBOL_TYPE_ENTRY)
3005 || (((*som_symbol_data (bfd_syms[i]))->som_type
3006 == SYMBOL_TYPE_CODE)
3007 && (bfd_syms[i]->flags & BSF_FUNCTION))
3008 || (((*som_symbol_data (bfd_syms[i]))->som_type
3009 == SYMBOL_TYPE_UNKNOWN)
3010 && (bfd_syms[i]->flags & BSF_FUNCTION)))
3011 {
3012 som_symtab[i].symbol_type = ST_ENTRY;
3013 som_symtab[i].arg_reloc
3014 = (*som_symbol_data (bfd_syms[i]))->tc_data.hppa_arg_reloc;
3015 }
3016
3017 /* If the type is unknown at this point, it should be
3018 ST_DATA (functions were handled as special cases above). */
3019 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3020 == SYMBOL_TYPE_UNKNOWN)
3021 som_symtab[i].symbol_type = ST_DATA;
3022
3023 /* From now on it's a very simple mapping. */
3024 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3025 == SYMBOL_TYPE_ABSOLUTE)
3026 som_symtab[i].symbol_type = ST_ABSOLUTE;
3027 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3028 == SYMBOL_TYPE_CODE)
3029 som_symtab[i].symbol_type = ST_CODE;
3030 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3031 == SYMBOL_TYPE_DATA)
3032 som_symtab[i].symbol_type = ST_DATA;
3033 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3034 == SYMBOL_TYPE_MILLICODE)
3035 som_symtab[i].symbol_type = ST_MILLICODE;
3036 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3037 == SYMBOL_TYPE_PLABEL)
3038 som_symtab[i].symbol_type = ST_PLABEL;
3039 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3040 == SYMBOL_TYPE_PRI_PROG)
3041 som_symtab[i].symbol_type = ST_PRI_PROG;
3042 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3043 == SYMBOL_TYPE_SEC_PROG)
3044 som_symtab[i].symbol_type = ST_SEC_PROG;
3045 }
3046
3047 /* Now handle the symbol's scope. Exported data which is not
3048 in the common section has scope SS_UNIVERSAL. Note scope
3049 of common symbols was handled earlier! */
3050 if (bfd_syms[i]->flags & BSF_EXPORT
3051 && bfd_syms[i]->section != &bfd_com_section)
3052 som_symtab[i].symbol_scope = SS_UNIVERSAL;
3053 /* Any undefined symbol at this point has a scope SS_UNSAT. */
3054 else if (bfd_syms[i]->section == &bfd_und_section)
3055 som_symtab[i].symbol_scope = SS_UNSAT;
3056 /* Anything else which is not in the common section has scope
3057 SS_LOCAL. */
3058 else if (bfd_syms[i]->section != &bfd_com_section)
3059 som_symtab[i].symbol_scope = SS_LOCAL;
3060
3061 /* Now set the symbol_info field. It has no real meaning
3062 for undefined or common symbols, but the HP linker will
3063 choke if it's not set to some "reasonable" value. We
3064 use zero as a reasonable value. */
3065 if (bfd_syms[i]->section == &bfd_com_section
3066 || bfd_syms[i]->section == &bfd_und_section)
3067 som_symtab[i].symbol_info = 0;
3068 /* For all other symbols, the symbol_info field contains the
3069 subspace index of the space this symbol is contained in. */
3070 else
3071 som_symtab[i].symbol_info
3072 = som_section_data (bfd_syms[i]->section)->subspace_index;
3073
3074 /* Set the symbol's value. */
3075 som_symtab[i].symbol_value
3076 = bfd_syms[i]->value + bfd_syms[i]->section->vma;
3077 }
3078
3079 /* Egad. Everything is ready, seek to the right location and
3080 scribble out the symbol table. */
3081 if (bfd_seek (abfd, symtab_location, SEEK_SET) != 0)
3082 {
3083 bfd_error = system_call_error;
3084 return false;
3085 }
3086
3087 if (bfd_write ((PTR) som_symtab, symtab_size, 1, abfd) != symtab_size)
3088 {
3089 bfd_error = system_call_error;
3090 return false;
3091 }
3092 return true;
3093 }
3094
3095 /* Write an object in SOM format. */
3096
3097 static boolean
3098 som_write_object_contents (abfd)
3099 bfd *abfd;
3100 {
3101 if (abfd->output_has_begun == false)
3102 {
3103 /* Set up fixed parts of the file, space, and subspace headers.
3104 Notify the world that output has begun. */
3105 som_prep_headers (abfd);
3106 abfd->output_has_begun = true;
3107 /* Start writing the object file. This include all the string
3108 tables, fixup streams, and other portions of the object file. */
3109 som_begin_writing (abfd);
3110 }
3111
3112 /* Now that the symbol table information is complete, build and
3113 write the symbol table. */
3114 if (som_build_and_write_symbol_table (abfd) == false)
3115 return false;
3116
3117 /* Compute the checksum for the file header just before writing
3118 the header to disk. */
3119 obj_som_file_hdr (abfd)->checksum = som_compute_checksum (abfd);
3120 return (som_write_headers (abfd));
3121 }
3122
3123 \f
3124 /* Read and save the string table associated with the given BFD. */
3125
3126 static boolean
3127 som_slurp_string_table (abfd)
3128 bfd *abfd;
3129 {
3130 char *stringtab;
3131
3132 /* Use the saved version if its available. */
3133 if (obj_som_stringtab (abfd) != NULL)
3134 return true;
3135
3136 /* Allocate and read in the string table. */
3137 stringtab = bfd_zalloc (abfd, obj_som_stringtab_size (abfd));
3138 if (stringtab == NULL)
3139 {
3140 bfd_error = no_memory;
3141 return false;
3142 }
3143
3144 if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) < 0)
3145 {
3146 bfd_error = system_call_error;
3147 return false;
3148 }
3149
3150 if (bfd_read (stringtab, obj_som_stringtab_size (abfd), 1, abfd)
3151 != obj_som_stringtab_size (abfd))
3152 {
3153 bfd_error = system_call_error;
3154 return false;
3155 }
3156
3157 /* Save our results and return success. */
3158 obj_som_stringtab (abfd) = stringtab;
3159 return true;
3160 }
3161
3162 /* Return the amount of data (in bytes) required to hold the symbol
3163 table for this object. */
3164
3165 static unsigned int
3166 som_get_symtab_upper_bound (abfd)
3167 bfd *abfd;
3168 {
3169 if (!som_slurp_symbol_table (abfd))
3170 return 0;
3171
3172 return (bfd_get_symcount (abfd) + 1) * (sizeof (som_symbol_type *));
3173 }
3174
3175 /* Convert from a SOM subspace index to a BFD section. */
3176
3177 static asection *
3178 som_section_from_subspace_index (abfd, index)
3179 bfd *abfd;
3180 unsigned int index;
3181 {
3182 asection *section;
3183
3184 for (section = abfd->sections; section != NULL; section = section->next)
3185 if (som_section_data (section)->subspace_index == index)
3186 return section;
3187
3188 /* Should never happen. */
3189 abort();
3190 }
3191
3192 /* Read and save the symbol table associated with the given BFD. */
3193
3194 static unsigned int
3195 som_slurp_symbol_table (abfd)
3196 bfd *abfd;
3197 {
3198 int symbol_count = bfd_get_symcount (abfd);
3199 int symsize = sizeof (struct symbol_dictionary_record);
3200 char *stringtab;
3201 struct symbol_dictionary_record *buf, *bufp, *endbufp;
3202 som_symbol_type *sym, *symbase;
3203
3204 /* Return saved value if it exists. */
3205 if (obj_som_symtab (abfd) != NULL)
3206 return true;
3207
3208 /* Sanity checking. Make sure there are some symbols and that
3209 we can read the string table too. */
3210 if (symbol_count == 0)
3211 {
3212 bfd_error = no_symbols;
3213 return false;
3214 }
3215
3216 if (!som_slurp_string_table (abfd))
3217 return false;
3218
3219 stringtab = obj_som_stringtab (abfd);
3220
3221 symbase = (som_symbol_type *)
3222 bfd_zalloc (abfd, symbol_count * sizeof (som_symbol_type));
3223 if (symbase == NULL)
3224 {
3225 bfd_error = no_memory;
3226 return false;
3227 }
3228
3229 /* Read in the external SOM representation. */
3230 buf = alloca (symbol_count * symsize);
3231 if (buf == NULL)
3232 {
3233 bfd_error = no_memory;
3234 return false;
3235 }
3236 if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) < 0)
3237 {
3238 bfd_error = system_call_error;
3239 return false;
3240 }
3241 if (bfd_read (buf, symbol_count * symsize, 1, abfd)
3242 != symbol_count * symsize)
3243 {
3244 bfd_error = no_symbols;
3245 return (false);
3246 }
3247
3248 /* Iterate over all the symbols and internalize them. */
3249 endbufp = buf + symbol_count;
3250 for (bufp = buf, sym = symbase; bufp < endbufp; ++bufp)
3251 {
3252
3253 /* I don't think we care about these. */
3254 if (bufp->symbol_type == ST_SYM_EXT
3255 || bufp->symbol_type == ST_ARG_EXT)
3256 continue;
3257
3258 /* Some reasonable defaults. */
3259 sym->symbol.the_bfd = abfd;
3260 sym->symbol.name = bufp->name.n_strx + stringtab;
3261 sym->symbol.value = bufp->symbol_value;
3262 sym->symbol.section = 0;
3263 sym->symbol.flags = 0;
3264
3265 switch (bufp->symbol_type)
3266 {
3267 case ST_ENTRY:
3268 case ST_PRI_PROG:
3269 case ST_SEC_PROG:
3270 case ST_MILLICODE:
3271 sym->symbol.flags |= BSF_FUNCTION;
3272 sym->symbol.value &= ~0x3;
3273 break;
3274
3275 case ST_STUB:
3276 case ST_CODE:
3277 sym->symbol.value &= ~0x3;
3278
3279 default:
3280 break;
3281 }
3282
3283 /* Handle scoping and section information. */
3284 switch (bufp->symbol_scope)
3285 {
3286 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
3287 so the section associated with this symbol can't be known. */
3288 case SS_EXTERNAL:
3289 case SS_UNSAT:
3290 if (bufp->symbol_type != ST_STORAGE)
3291 sym->symbol.section = &bfd_und_section;
3292 else
3293 sym->symbol.section = &bfd_com_section;
3294 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
3295 break;
3296
3297 case SS_UNIVERSAL:
3298 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
3299 sym->symbol.section
3300 = som_section_from_subspace_index (abfd, bufp->symbol_info);
3301 sym->symbol.value -= sym->symbol.section->vma;
3302 break;
3303
3304 #if 0
3305 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
3306 Sound dumb? It is. */
3307 case SS_GLOBAL:
3308 #endif
3309 case SS_LOCAL:
3310 sym->symbol.flags |= BSF_LOCAL;
3311 sym->symbol.section
3312 = som_section_from_subspace_index (abfd, bufp->symbol_info);
3313 sym->symbol.value -= sym->symbol.section->vma;
3314 break;
3315 }
3316
3317 /* Mark symbols left around by the debugger. */
3318 if (strlen (sym->symbol.name) >= 2
3319 && sym->symbol.name[0] == 'L'
3320 && (sym->symbol.name[1] == '$' || sym->symbol.name[2] == '$'
3321 || sym->symbol.name[3] == '$'))
3322 sym->symbol.flags |= BSF_DEBUGGING;
3323
3324 /* Note increment at bottom of loop, since we skip some symbols
3325 we can not include it as part of the for statement. */
3326 sym++;
3327 }
3328
3329 /* Save our results and return success. */
3330 obj_som_symtab (abfd) = symbase;
3331 return (true);
3332 }
3333
3334 /* Canonicalize a SOM symbol table. Return the number of entries
3335 in the symbol table. */
3336
3337 static unsigned int
3338 som_get_symtab (abfd, location)
3339 bfd *abfd;
3340 asymbol **location;
3341 {
3342 int i;
3343 som_symbol_type *symbase;
3344
3345 if (!som_slurp_symbol_table (abfd))
3346 return 0;
3347
3348 i = bfd_get_symcount (abfd);
3349 symbase = obj_som_symtab (abfd);
3350
3351 for (; i > 0; i--, location++, symbase++)
3352 *location = &symbase->symbol;
3353
3354 /* Final null pointer. */
3355 *location = 0;
3356 return (bfd_get_symcount (abfd));
3357 }
3358
3359 /* Make a SOM symbol. There is nothing special to do here. */
3360
3361 static asymbol *
3362 som_make_empty_symbol (abfd)
3363 bfd *abfd;
3364 {
3365 som_symbol_type *new =
3366 (som_symbol_type *) bfd_zalloc (abfd, sizeof (som_symbol_type));
3367 if (new == NULL)
3368 {
3369 bfd_error = no_memory;
3370 return 0;
3371 }
3372 new->symbol.the_bfd = abfd;
3373
3374 return &new->symbol;
3375 }
3376
3377 /* Print symbol information. */
3378
3379 static void
3380 som_print_symbol (ignore_abfd, afile, symbol, how)
3381 bfd *ignore_abfd;
3382 PTR afile;
3383 asymbol *symbol;
3384 bfd_print_symbol_type how;
3385 {
3386 FILE *file = (FILE *) afile;
3387 switch (how)
3388 {
3389 case bfd_print_symbol_name:
3390 fprintf (file, "%s", symbol->name);
3391 break;
3392 case bfd_print_symbol_more:
3393 fprintf (file, "som ");
3394 fprintf_vma (file, symbol->value);
3395 fprintf (file, " %lx", (long) symbol->flags);
3396 break;
3397 case bfd_print_symbol_all:
3398 {
3399 CONST char *section_name;
3400 section_name = symbol->section ? symbol->section->name : "(*none*)";
3401 bfd_print_symbol_vandf ((PTR) file, symbol);
3402 fprintf (file, " %s\t%s", section_name, symbol->name);
3403 break;
3404 }
3405 }
3406 }
3407
3408 /* Count or process variable-length SOM fixup records.
3409
3410 To avoid code duplication we use this code both to compute the number
3411 of relocations requested by a stream, and to internalize the stream.
3412
3413 When computing the number of relocations requested by a stream the
3414 variables rptr, section, and symbols have no meaning.
3415
3416 Return the number of relocations requested by the fixup stream. When
3417 not just counting
3418
3419 This needs at least two or three more passes to get it cleaned up. */
3420
3421 static unsigned int
3422 som_set_reloc_info (fixup, end, internal_relocs, section, symbols, just_count)
3423 unsigned char *fixup;
3424 unsigned int end;
3425 arelent *internal_relocs;
3426 asection *section;
3427 asymbol **symbols;
3428 boolean just_count;
3429 {
3430 unsigned int op, varname;
3431 unsigned char *end_fixups = &fixup[end];
3432 const struct fixup_format *fp;
3433 char *cp;
3434 unsigned char *save_fixup;
3435 int variables[26], stack[20], c, v, count, prev_fixup, *sp;
3436 const int *subop;
3437 arelent *rptr= internal_relocs;
3438 unsigned int offset = just_count ? 0 : section->vma;
3439
3440 #define var(c) variables[(c) - 'A']
3441 #define push(v) (*sp++ = (v))
3442 #define pop() (*--sp)
3443 #define emptystack() (sp == stack)
3444
3445 som_initialize_reloc_queue (reloc_queue);
3446 bzero (variables, sizeof (variables));
3447 bzero (stack, sizeof (stack));
3448 count = 0;
3449 prev_fixup = 0;
3450 sp = stack;
3451
3452 while (fixup < end_fixups)
3453 {
3454
3455 /* Save pointer to the start of this fixup. We'll use
3456 it later to determine if it is necessary to put this fixup
3457 on the queue. */
3458 save_fixup = fixup;
3459
3460 /* Get the fixup code and its associated format. */
3461 op = *fixup++;
3462 fp = &som_fixup_formats[op];
3463
3464 /* Handle a request for a previous fixup. */
3465 if (*fp->format == 'P')
3466 {
3467 /* Get pointer to the beginning of the prev fixup, move
3468 the repeated fixup to the head of the queue. */
3469 fixup = reloc_queue[fp->D].reloc;
3470 som_reloc_queue_fix (reloc_queue, fp->D);
3471 prev_fixup = 1;
3472
3473 /* Get the fixup code and its associated format. */
3474 op = *fixup++;
3475 fp = &som_fixup_formats[op];
3476 }
3477
3478 /* If we are not just counting, set some reasonable defaults. */
3479 if (! just_count)
3480 {
3481 rptr->address = offset;
3482 rptr->howto = &som_hppa_howto_table[op];
3483 rptr->addend = 0;
3484 }
3485
3486 /* Set default input length to 0. Get the opcode class index
3487 into D. */
3488 var ('L') = 0;
3489 var ('D') = fp->D;
3490
3491 /* Get the opcode format. */
3492 cp = fp->format;
3493
3494 /* Process the format string. Parsing happens in two phases,
3495 parse RHS, then assign to LHS. Repeat until no more
3496 characters in the format string. */
3497 while (*cp)
3498 {
3499 /* The variable this pass is going to compute a value for. */
3500 varname = *cp++;
3501
3502 /* Start processing RHS. Continue until a NULL or '=' is found. */
3503 do
3504 {
3505 c = *cp++;
3506
3507 /* If this is a variable, push it on the stack. */
3508 if (isupper (c))
3509 push (var (c));
3510
3511 /* If this is a lower case letter, then it represents
3512 additional data from the fixup stream to be pushed onto
3513 the stack. */
3514 else if (islower (c))
3515 {
3516 for (v = 0; c > 'a'; --c)
3517 v = (v << 8) | *fixup++;
3518 push (v);
3519 }
3520
3521 /* A decimal constant. Push it on the stack. */
3522 else if (isdigit (c))
3523 {
3524 v = c - '0';
3525 while (isdigit (*cp))
3526 v = (v * 10) + (*cp++ - '0');
3527 push (v);
3528 }
3529 else
3530
3531 /* An operator. Pop two two values from the stack and
3532 use them as operands to the given operation. Push
3533 the result of the operation back on the stack. */
3534 switch (c)
3535 {
3536 case '+':
3537 v = pop ();
3538 v += pop ();
3539 push (v);
3540 break;
3541 case '*':
3542 v = pop ();
3543 v *= pop ();
3544 push (v);
3545 break;
3546 case '<':
3547 v = pop ();
3548 v = pop () << v;
3549 push (v);
3550 break;
3551 default:
3552 abort ();
3553 }
3554 }
3555 while (*cp && *cp != '=');
3556
3557 /* Move over the equal operator. */
3558 cp++;
3559
3560 /* Pop the RHS off the stack. */
3561 c = pop ();
3562
3563 /* Perform the assignment. */
3564 var (varname) = c;
3565
3566 /* Handle side effects. and special 'O' stack cases. */
3567 switch (varname)
3568 {
3569 /* Consume some bytes from the input space. */
3570 case 'L':
3571 offset += c;
3572 break;
3573 /* A symbol to use in the relocation. Make a note
3574 of this if we are not just counting. */
3575 case 'S':
3576 if (! just_count)
3577 rptr->sym_ptr_ptr = &symbols[c];
3578 break;
3579 /* Handle the linker expression stack. */
3580 case 'O':
3581 switch (op)
3582 {
3583 case R_COMP1:
3584 subop = comp1_opcodes;
3585 break;
3586 case R_COMP2:
3587 subop = comp2_opcodes;
3588 break;
3589 case R_COMP3:
3590 subop = comp3_opcodes;
3591 break;
3592 default:
3593 abort ();
3594 }
3595 while (*subop <= (unsigned char) c)
3596 ++subop;
3597 --subop;
3598 break;
3599 default:
3600 break;
3601 }
3602 }
3603
3604 /* If we used a previous fixup, clean up after it. */
3605 if (prev_fixup)
3606 {
3607 fixup = save_fixup + 1;
3608 prev_fixup = 0;
3609 }
3610 /* Queue it. */
3611 else if (fixup > save_fixup + 1)
3612 som_reloc_queue_insert (save_fixup, fixup - save_fixup, reloc_queue);
3613
3614 /* We do not pass R_DATA_OVERRIDE or R_NO_RELOCATION
3615 fixups to BFD. */
3616 if (som_hppa_howto_table[op].type != R_DATA_OVERRIDE
3617 && som_hppa_howto_table[op].type != R_NO_RELOCATION)
3618 {
3619 /* Done with a single reloction. Loop back to the top. */
3620 if (! just_count)
3621 {
3622 rptr->addend = var ('V');
3623 rptr++;
3624 }
3625 count++;
3626 /* Now that we've handled a "full" relocation, reset
3627 some state. */
3628 bzero (variables, sizeof (variables));
3629 bzero (stack, sizeof (stack));
3630 }
3631 }
3632 return count;
3633
3634 #undef var
3635 #undef push
3636 #undef pop
3637 #undef emptystack
3638 }
3639
3640 /* Read in the relocs (aka fixups in SOM terms) for a section.
3641
3642 som_get_reloc_upper_bound calls this routine with JUST_COUNT
3643 set to true to indicate it only needs a count of the number
3644 of actual relocations. */
3645
3646 static boolean
3647 som_slurp_reloc_table (abfd, section, symbols, just_count)
3648 bfd *abfd;
3649 asection *section;
3650 asymbol **symbols;
3651 boolean just_count;
3652 {
3653 char *external_relocs;
3654 unsigned int fixup_stream_size;
3655 arelent *internal_relocs;
3656 unsigned int num_relocs;
3657
3658 fixup_stream_size = som_section_data (section)->reloc_size;
3659 /* If there were no relocations, then there is nothing to do. */
3660 if (section->reloc_count == 0)
3661 return true;
3662
3663 /* If reloc_count is -1, then the relocation stream has not been
3664 parsed. We must do so now to know how many relocations exist. */
3665 if (section->reloc_count == -1)
3666 {
3667 external_relocs = (char *) bfd_zalloc (abfd, fixup_stream_size);
3668 if (external_relocs == (char *) NULL)
3669 {
3670 bfd_error = no_memory;
3671 return false;
3672 }
3673 /* Read in the external forms. */
3674 if (bfd_seek (abfd,
3675 obj_som_reloc_filepos (abfd) + section->rel_filepos,
3676 SEEK_SET)
3677 != 0)
3678 {
3679 bfd_error = system_call_error;
3680 return false;
3681 }
3682 if (bfd_read (external_relocs, 1, fixup_stream_size, abfd)
3683 != fixup_stream_size)
3684 {
3685 bfd_error = system_call_error;
3686 return false;
3687 }
3688 /* Let callers know how many relocations found.
3689 also save the relocation stream as we will
3690 need it again. */
3691 section->reloc_count = som_set_reloc_info (external_relocs,
3692 fixup_stream_size,
3693 NULL, NULL, NULL, true);
3694
3695 som_section_data (section)->reloc_stream = external_relocs;
3696 }
3697
3698 /* If the caller only wanted a count, then return now. */
3699 if (just_count)
3700 return true;
3701
3702 num_relocs = section->reloc_count;
3703 external_relocs = som_section_data (section)->reloc_stream;
3704 /* Return saved information about the relocations if it is available. */
3705 if (section->relocation != (arelent *) NULL)
3706 return true;
3707
3708 internal_relocs = (arelent *) bfd_zalloc (abfd,
3709 num_relocs * sizeof (arelent));
3710 if (internal_relocs == (arelent *) NULL)
3711 {
3712 bfd_error = no_memory;
3713 return false;
3714 }
3715
3716 /* Process and internalize the relocations. */
3717 som_set_reloc_info (external_relocs, fixup_stream_size,
3718 internal_relocs, section, symbols, false);
3719
3720 /* Save our results and return success. */
3721 section->relocation = internal_relocs;
3722 return (true);
3723 }
3724
3725 /* Return the number of bytes required to store the relocation
3726 information associated with the given section. */
3727
3728 static unsigned int
3729 som_get_reloc_upper_bound (abfd, asect)
3730 bfd *abfd;
3731 sec_ptr asect;
3732 {
3733 /* If section has relocations, then read in the relocation stream
3734 and parse it to determine how many relocations exist. */
3735 if (asect->flags & SEC_RELOC)
3736 {
3737 if (som_slurp_reloc_table (abfd, asect, NULL, true))
3738 return (asect->reloc_count + 1) * sizeof (arelent);
3739 }
3740 /* Either there are no relocations or an error occurred while
3741 reading and parsing the relocation stream. */
3742 return 0;
3743 }
3744
3745 /* Convert relocations from SOM (external) form into BFD internal
3746 form. Return the number of relocations. */
3747
3748 static unsigned int
3749 som_canonicalize_reloc (abfd, section, relptr, symbols)
3750 bfd *abfd;
3751 sec_ptr section;
3752 arelent **relptr;
3753 asymbol **symbols;
3754 {
3755 arelent *tblptr;
3756 int count;
3757
3758 if (som_slurp_reloc_table (abfd, section, symbols, false) == false)
3759 return 0;
3760
3761 count = section->reloc_count;
3762 tblptr = section->relocation;
3763 if (tblptr == (arelent *) NULL)
3764 return 0;
3765
3766 while (count--)
3767 *relptr++ = tblptr++;
3768
3769 *relptr = (arelent *) NULL;
3770 return section->reloc_count;
3771 }
3772
3773 extern bfd_target som_vec;
3774
3775 /* A hook to set up object file dependent section information. */
3776
3777 static boolean
3778 som_new_section_hook (abfd, newsect)
3779 bfd *abfd;
3780 asection *newsect;
3781 {
3782 newsect->used_by_bfd = (struct som_section_data_struct *)
3783 bfd_zalloc (abfd, sizeof (struct som_section_data_struct));
3784 newsect->alignment_power = 3;
3785
3786 /* Initialize the subspace_index field to -1 so that it does
3787 not match a subspace with an index of 0. */
3788 som_section_data (newsect)->subspace_index = -1;
3789
3790 /* We allow more than three sections internally */
3791 return true;
3792 }
3793
3794 /* Set backend info for sections which can not be described
3795 in the BFD data structures. */
3796
3797 void
3798 bfd_som_set_section_attributes (section, defined, private, sort_key, spnum)
3799 asection *section;
3800 char defined;
3801 char private;
3802 unsigned char sort_key;
3803 int spnum;
3804 {
3805 struct space_dictionary_record *space_dict;
3806
3807 som_section_data (section)->is_space = 1;
3808 space_dict = &som_section_data (section)->space_dict;
3809 space_dict->is_defined = defined;
3810 space_dict->is_private = private;
3811 space_dict->sort_key = sort_key;
3812 space_dict->space_number = spnum;
3813 }
3814
3815 /* Set backend info for subsections which can not be described
3816 in the BFD data structures. */
3817
3818 void
3819 bfd_som_set_subsection_attributes (section, container, access,
3820 sort_key, quadrant)
3821 asection *section;
3822 asection *container;
3823 int access;
3824 unsigned char sort_key;
3825 int quadrant;
3826 {
3827 struct subspace_dictionary_record *subspace_dict;
3828 som_section_data (section)->is_subspace = 1;
3829 subspace_dict = &som_section_data (section)->subspace_dict;
3830 subspace_dict->access_control_bits = access;
3831 subspace_dict->sort_key = sort_key;
3832 subspace_dict->quadrant = quadrant;
3833 som_section_data (section)->containing_space = container;
3834 }
3835
3836 /* Set the full SOM symbol type. SOM needs far more symbol information
3837 than any other object file format I'm aware of. It is mandatory
3838 to be able to know if a symbol is an entry point, millicode, data,
3839 code, absolute, storage request, or procedure label. If you get
3840 the symbol type wrong your program will not link. */
3841
3842 void
3843 bfd_som_set_symbol_type (symbol, type)
3844 asymbol *symbol;
3845 unsigned int type;
3846 {
3847 (*som_symbol_data (symbol))->som_type = type;
3848 }
3849
3850 /* Attach 64bits of unwind information to a symbol (which hopefully
3851 is a function of some kind!). It would be better to keep this
3852 in the R_ENTRY relocation, but there is not enough space. */
3853
3854 void
3855 bfd_som_attach_unwind_info (symbol, unwind_desc)
3856 asymbol *symbol;
3857 char *unwind_desc;
3858 {
3859 (*som_symbol_data (symbol))->unwind = unwind_desc;
3860 }
3861
3862 static boolean
3863 som_set_section_contents (abfd, section, location, offset, count)
3864 bfd *abfd;
3865 sec_ptr section;
3866 PTR location;
3867 file_ptr offset;
3868 bfd_size_type count;
3869 {
3870 if (abfd->output_has_begun == false)
3871 {
3872 /* Set up fixed parts of the file, space, and subspace headers.
3873 Notify the world that output has begun. */
3874 som_prep_headers (abfd);
3875 abfd->output_has_begun = true;
3876 /* Start writing the object file. This include all the string
3877 tables, fixup streams, and other portions of the object file. */
3878 som_begin_writing (abfd);
3879 }
3880
3881 /* Only write subspaces which have "real" contents (eg. the contents
3882 are not generated at run time by the OS). */
3883 if (som_section_data (section)->is_subspace != 1
3884 || ((section->flags & (SEC_LOAD | SEC_DEBUGGING)) == 0))
3885 return true;
3886
3887 /* Seek to the proper offset within the object file and write the
3888 data. */
3889 offset += som_section_data (section)->subspace_dict.file_loc_init_value;
3890 if (bfd_seek (abfd, offset, SEEK_SET) == -1)
3891 {
3892 bfd_error = system_call_error;
3893 return false;
3894 }
3895
3896 if (bfd_write ((PTR) location, 1, count, abfd) != count)
3897 {
3898 bfd_error = system_call_error;
3899 return false;
3900 }
3901 return true;
3902 }
3903
3904 static boolean
3905 som_set_arch_mach (abfd, arch, machine)
3906 bfd *abfd;
3907 enum bfd_architecture arch;
3908 unsigned long machine;
3909 {
3910 /* Allow any architecture to be supported by the SOM backend */
3911 return bfd_default_set_arch_mach (abfd, arch, machine);
3912 }
3913
3914 static boolean
3915 som_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
3916 functionname_ptr, line_ptr)
3917 bfd *abfd;
3918 asection *section;
3919 asymbol **symbols;
3920 bfd_vma offset;
3921 CONST char **filename_ptr;
3922 CONST char **functionname_ptr;
3923 unsigned int *line_ptr;
3924 {
3925 fprintf (stderr, "som_find_nearest_line unimplemented\n");
3926 fflush (stderr);
3927 abort ();
3928 return (false);
3929 }
3930
3931 static int
3932 som_sizeof_headers (abfd, reloc)
3933 bfd *abfd;
3934 boolean reloc;
3935 {
3936 fprintf (stderr, "som_sizeof_headers unimplemented\n");
3937 fflush (stderr);
3938 abort ();
3939 return (0);
3940 }
3941
3942 /* Return the single-character symbol type corresponding to
3943 SOM section S, or '?' for an unknown SOM section. */
3944
3945 static char
3946 som_section_type (s)
3947 const char *s;
3948 {
3949 const struct section_to_type *t;
3950
3951 for (t = &stt[0]; t->section; t++)
3952 if (!strcmp (s, t->section))
3953 return t->type;
3954 return '?';
3955 }
3956
3957 static int
3958 som_decode_symclass (symbol)
3959 asymbol *symbol;
3960 {
3961 char c;
3962
3963 if (bfd_is_com_section (symbol->section))
3964 return 'C';
3965 if (symbol->section == &bfd_und_section)
3966 return 'U';
3967 if (symbol->section == &bfd_ind_section)
3968 return 'I';
3969 if (!(symbol->flags & (BSF_GLOBAL|BSF_LOCAL)))
3970 return '?';
3971
3972 if (symbol->section == &bfd_abs_section)
3973 c = 'a';
3974 else if (symbol->section)
3975 c = som_section_type (symbol->section->name);
3976 else
3977 return '?';
3978 if (symbol->flags & BSF_GLOBAL)
3979 c = toupper (c);
3980 return c;
3981 }
3982
3983 /* Return information about SOM symbol SYMBOL in RET. */
3984
3985 static void
3986 som_get_symbol_info (ignore_abfd, symbol, ret)
3987 bfd *ignore_abfd;
3988 asymbol *symbol;
3989 symbol_info *ret;
3990 {
3991 ret->type = som_decode_symclass (symbol);
3992 if (ret->type != 'U')
3993 ret->value = symbol->value+symbol->section->vma;
3994 else
3995 ret->value = 0;
3996 ret->name = symbol->name;
3997 }
3998
3999 /* End of miscellaneous support functions. */
4000
4001 #define som_bfd_debug_info_start bfd_void
4002 #define som_bfd_debug_info_end bfd_void
4003 #define som_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
4004
4005 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
4006 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
4007 #define som_slurp_armap bfd_false
4008 #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
4009 #define som_truncate_arname (void (*)())bfd_nullvoidptr
4010 #define som_write_armap 0
4011
4012 #define som_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
4013 #define som_close_and_cleanup bfd_generic_close_and_cleanup
4014 #define som_get_section_contents bfd_generic_get_section_contents
4015
4016 #define som_bfd_get_relocated_section_contents \
4017 bfd_generic_get_relocated_section_contents
4018 #define som_bfd_relax_section bfd_generic_relax_section
4019 #define som_bfd_seclet_link bfd_generic_seclet_link
4020 #define som_bfd_make_debug_symbol \
4021 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
4022
4023 /* Core file support is in the hpux-core backend. */
4024 #define som_core_file_failing_command _bfd_dummy_core_file_failing_command
4025 #define som_core_file_failing_signal _bfd_dummy_core_file_failing_signal
4026 #define som_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
4027
4028 bfd_target som_vec =
4029 {
4030 "som", /* name */
4031 bfd_target_som_flavour,
4032 true, /* target byte order */
4033 true, /* target headers byte order */
4034 (HAS_RELOC | EXEC_P | /* object flags */
4035 HAS_LINENO | HAS_DEBUG |
4036 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
4037 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
4038 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
4039
4040 /* leading_symbol_char: is the first char of a user symbol
4041 predictable, and if so what is it */
4042 0,
4043 ' ', /* ar_pad_char */
4044 16, /* ar_max_namelen */
4045 3, /* minimum alignment */
4046 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
4047 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
4048 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
4049 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
4050 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
4051 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
4052 {_bfd_dummy_target,
4053 som_object_p, /* bfd_check_format */
4054 bfd_generic_archive_p,
4055 _bfd_dummy_target
4056 },
4057 {
4058 bfd_false,
4059 som_mkobject,
4060 _bfd_generic_mkarchive,
4061 bfd_false
4062 },
4063 {
4064 bfd_false,
4065 som_write_object_contents,
4066 _bfd_write_archive_contents,
4067 bfd_false,
4068 },
4069 #undef som
4070 JUMP_TABLE (som),
4071 (PTR) 0
4072 };
4073
4074 #endif /* HOST_HPPAHPUX || HOST_HPPABSD */