* som.c (som_begin_writing): Flesh out code for handling simple
[deliverable/binutils-gdb.git] / bfd / som.c
1 /* bfd back-end for HP PA-RISC SOM objects.
2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3
4 Contributed by the Center for Software Science at the
5 University of Utah (pa-gdb-bugs@cs.utah.edu).
6
7 This file is part of BFD, the Binary File Descriptor library.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22
23 #include "bfd.h"
24 #include "sysdep.h"
25
26 #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD)
27
28 #include "libbfd.h"
29 #include "som.h"
30 #include "libhppa.h"
31
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/dir.h>
36 #include <signal.h>
37 #include <machine/reg.h>
38 #include <sys/user.h> /* After a.out.h */
39 #include <sys/file.h>
40 #include <errno.h>
41
42 /* Magic not defined in standard HP-UX header files until 8.0 */
43
44 #ifndef CPU_PA_RISC1_0
45 #define CPU_PA_RISC1_0 0x20B
46 #endif /* CPU_PA_RISC1_0 */
47
48 #ifndef CPU_PA_RISC1_1
49 #define CPU_PA_RISC1_1 0x210
50 #endif /* CPU_PA_RISC1_1 */
51
52 #ifndef _PA_RISC1_0_ID
53 #define _PA_RISC1_0_ID CPU_PA_RISC1_0
54 #endif /* _PA_RISC1_0_ID */
55
56 #ifndef _PA_RISC1_1_ID
57 #define _PA_RISC1_1_ID CPU_PA_RISC1_1
58 #endif /* _PA_RISC1_1_ID */
59
60 #ifndef _PA_RISC_MAXID
61 #define _PA_RISC_MAXID 0x2FF
62 #endif /* _PA_RISC_MAXID */
63
64 #ifndef _PA_RISC_ID
65 #define _PA_RISC_ID(__m_num) \
66 (((__m_num) == _PA_RISC1_0_ID) || \
67 ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
68 #endif /* _PA_RISC_ID */
69
70 /* Size (in chars) of the temporary buffers used during fixup and string
71 table writes. */
72
73 #define SOM_TMP_BUFSIZE 8192
74
75
76 /* SOM allows any one of the four previous relocations to be reused
77 with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
78 relocations are always a single byte, using a R_PREV_FIXUP instead
79 of some multi-byte relocation makes object files smaller.
80
81 Note one side effect of using a R_PREV_FIXUP is the relocation that
82 is being repeated moves to the front of the queue. */
83 struct reloc_queue
84 {
85 unsigned char *reloc;
86 unsigned int size;
87 } reloc_queue[4];
88
89 /* This fully describes the symbol types which may be attached to
90 an EXPORT or IMPORT directive. Only SOM uses this formation
91 (ELF has no need for it). */
92 typedef enum
93 {
94 SYMBOL_TYPE_UNKNOWN,
95 SYMBOL_TYPE_ABSOLUTE,
96 SYMBOL_TYPE_CODE,
97 SYMBOL_TYPE_DATA,
98 SYMBOL_TYPE_ENTRY,
99 SYMBOL_TYPE_MILLICODE,
100 SYMBOL_TYPE_PLABEL,
101 SYMBOL_TYPE_PRI_PROG,
102 SYMBOL_TYPE_SEC_PROG,
103 } pa_symbol_type;
104
105 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 /* These apparently are not in older versions of hpux reloc.h. */
656 #ifndef R_DLT_REL
657 #define R_DLT_REL 0x78
658 #endif
659
660 #ifndef R_AUX_UNWIND
661 #define R_AUX_UNWIND 0xcf
662 #endif
663
664 #ifndef R_SEC_STMT
665 #define R_SEC_STMT 0xd7
666 #endif
667
668 static reloc_howto_type som_hppa_howto_table[] =
669 {
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_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
690 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
691 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
692 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
693 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
694 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
695 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
696 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
697 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
698 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
699 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
700 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
701 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
702 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
703 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
704 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
705 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
706 {R_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RELOCATION"},
707 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
708 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
709 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
710 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
711 {R_SPACE_REF, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_SPACE_REF"},
712 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
713 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
714 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
715 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
716 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
717 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
718 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
719 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
720 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
721 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
722 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
723 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
724 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
725 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
726 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
727 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
728 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
729 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
730 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
731 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
732 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
733 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
734 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
735 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
736 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
737 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
738 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
739 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
740 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
741 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
742 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
743 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
744 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
745 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
746 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
747 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
748 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
749 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
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_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
773 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
774 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
775 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
776 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
777 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
778 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
779 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
780 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
781 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
782 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
783 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
784 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
785 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
786 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
787 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
788 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
789 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
790 {R_DLT_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DLT_REL"},
791 {R_DLT_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DLT_REL"},
792 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
793 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
794 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
795 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
796 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
797 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
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_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
821 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
822 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
823 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
824 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
825 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
826 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
827 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
828 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
829 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
830 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
831 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
832 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
833 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
834 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
835 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
836 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
837 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
838 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
839 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
840 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
841 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
842 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
843 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
844 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
845 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
846 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
847 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
848 {R_BREAKPOINT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BREAKPOINT"},
849 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
850 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
851 {R_ALT_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ALT_ENTRY"},
852 {R_EXIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_EXIT"},
853 {R_BEGIN_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_TRY"},
854 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
855 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
856 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
857 {R_BEGIN_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_BRTAB"},
858 {R_END_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_BRTAB"},
859 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
860 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
861 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
862 {R_DATA_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_EXPR"},
863 {R_CODE_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_EXPR"},
864 {R_FSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_FSEL"},
865 {R_LSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LSEL"},
866 {R_RSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RSEL"},
867 {R_N_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_N_MODE"},
868 {R_S_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_S_MODE"},
869 {R_D_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_D_MODE"},
870 {R_R_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_R_MODE"},
871 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
872 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
873 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
874 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
875 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
876 {R_TRANSLATED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_TRANSLATED"},
877 {R_AUX_UNWIND, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_AUX_UNWIND"},
878 {R_COMP1, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP1"},
879 {R_COMP2, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP2"},
880 {R_COMP3, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP3"},
881 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
882 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
883 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
884 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
885 {R_SEC_STMT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_SEC_STMT"},
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 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
916 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
917 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
918 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
919 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
920 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
921 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
922 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
923 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
924 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
925 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"}};
926
927
928 /* Initialize the SOM relocation queue. By definition the queue holds
929 the last four multibyte fixups. */
930
931 static void
932 som_initialize_reloc_queue (queue)
933 struct reloc_queue *queue;
934 {
935 queue[0].reloc = NULL;
936 queue[0].size = 0;
937 queue[1].reloc = NULL;
938 queue[1].size = 0;
939 queue[2].reloc = NULL;
940 queue[2].size = 0;
941 queue[3].reloc = NULL;
942 queue[3].size = 0;
943 }
944
945 /* Insert a new relocation into the relocation queue. */
946
947 static void
948 som_reloc_queue_insert (p, size, queue)
949 unsigned char *p;
950 unsigned int size;
951 struct reloc_queue *queue;
952 {
953 queue[3].reloc = queue[2].reloc;
954 queue[3].size = queue[2].size;
955 queue[2].reloc = queue[1].reloc;
956 queue[2].size = queue[1].size;
957 queue[1].reloc = queue[0].reloc;
958 queue[1].size = queue[0].size;
959 queue[0].reloc = p;
960 queue[0].size = size;
961 }
962
963 /* When an entry in the relocation queue is reused, the entry moves
964 to the front of the queue. */
965
966 static void
967 som_reloc_queue_fix (queue, index)
968 struct reloc_queue *queue;
969 unsigned int index;
970 {
971 if (index == 0)
972 return;
973
974 if (index == 1)
975 {
976 unsigned char *tmp1 = queue[0].reloc;
977 unsigned int tmp2 = queue[0].size;
978 queue[0].reloc = queue[1].reloc;
979 queue[0].size = queue[1].size;
980 queue[1].reloc = tmp1;
981 queue[1].size = tmp2;
982 return;
983 }
984
985 if (index == 2)
986 {
987 unsigned char *tmp1 = queue[0].reloc;
988 unsigned int tmp2 = queue[0].size;
989 queue[0].reloc = queue[2].reloc;
990 queue[0].size = queue[2].size;
991 queue[2].reloc = queue[1].reloc;
992 queue[2].size = queue[1].size;
993 queue[1].reloc = tmp1;
994 queue[1].size = tmp2;
995 return;
996 }
997
998 if (index == 3)
999 {
1000 unsigned char *tmp1 = queue[0].reloc;
1001 unsigned int tmp2 = queue[0].size;
1002 queue[0].reloc = queue[3].reloc;
1003 queue[0].size = queue[3].size;
1004 queue[3].reloc = queue[2].reloc;
1005 queue[3].size = queue[2].size;
1006 queue[2].reloc = queue[1].reloc;
1007 queue[2].size = queue[1].size;
1008 queue[1].reloc = tmp1;
1009 queue[1].size = tmp2;
1010 return;
1011 }
1012 abort();
1013 }
1014
1015 /* Search for a particular relocation in the relocation queue. */
1016
1017 static int
1018 som_reloc_queue_find (p, size, queue)
1019 unsigned char *p;
1020 unsigned int size;
1021 struct reloc_queue *queue;
1022 {
1023 if (!bcmp (p, queue[0].reloc, size)
1024 && size == queue[0].size)
1025 return 0;
1026 if (!bcmp (p, queue[1].reloc, size)
1027 && size == queue[1].size)
1028 return 1;
1029 if (!bcmp (p, queue[2].reloc, size)
1030 && size == queue[2].size)
1031 return 2;
1032 if (!bcmp (p, queue[3].reloc, size)
1033 && size == queue[3].size)
1034 return 3;
1035 return -1;
1036 }
1037
1038 static unsigned char *
1039 try_prev_fixup (abfd, subspace_reloc_sizep, p, size, queue)
1040 bfd *abfd;
1041 int *subspace_reloc_sizep;
1042 unsigned char *p;
1043 unsigned int size;
1044 struct reloc_queue *queue;
1045 {
1046 int queue_index = som_reloc_queue_find (p, size, queue);
1047
1048 if (queue_index != -1)
1049 {
1050 /* Found this in a previous fixup. Undo the fixup we
1051 just built and use R_PREV_FIXUP instead. We saved
1052 a total of size - 1 bytes in the fixup stream. */
1053 bfd_put_8 (abfd, R_PREV_FIXUP + queue_index, p);
1054 p += 1;
1055 *subspace_reloc_sizep += 1;
1056 som_reloc_queue_fix (queue, queue_index);
1057 }
1058 else
1059 {
1060 som_reloc_queue_insert (p, size, queue);
1061 *subspace_reloc_sizep += size;
1062 p += size;
1063 }
1064 return p;
1065 }
1066
1067 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
1068 bytes without any relocation. Update the size of the subspace
1069 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
1070 current pointer into the relocation stream. */
1071
1072 static unsigned char *
1073 som_reloc_skip (abfd, skip, p, subspace_reloc_sizep, queue)
1074 bfd *abfd;
1075 unsigned int skip;
1076 unsigned char *p;
1077 unsigned int *subspace_reloc_sizep;
1078 struct reloc_queue *queue;
1079 {
1080 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
1081 then R_PREV_FIXUPs to get the difference down to a
1082 reasonable size. */
1083 if (skip >= 0x1000000)
1084 {
1085 skip -= 0x1000000;
1086 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
1087 bfd_put_8 (abfd, 0xff, p + 1);
1088 bfd_put_16 (abfd, 0xffff, p + 2);
1089 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1090 while (skip >= 0x1000000)
1091 {
1092 skip -= 0x1000000;
1093 bfd_put_8 (abfd, R_PREV_FIXUP, p);
1094 p++;
1095 *subspace_reloc_sizep += 1;
1096 /* No need to adjust queue here since we are repeating the
1097 most recent fixup. */
1098 }
1099 }
1100
1101 /* The difference must be less than 0x1000000. Use one
1102 more R_NO_RELOCATION entry to get to the right difference. */
1103 if ((skip & 3) == 0 && skip <= 0xc0000 && skip > 0)
1104 {
1105 /* Difference can be handled in a simple single-byte
1106 R_NO_RELOCATION entry. */
1107 if (skip <= 0x60)
1108 {
1109 bfd_put_8 (abfd, R_NO_RELOCATION + (skip >> 2) - 1, p);
1110 *subspace_reloc_sizep += 1;
1111 p++;
1112 }
1113 /* Handle it with a two byte R_NO_RELOCATION entry. */
1114 else if (skip <= 0x1000)
1115 {
1116 bfd_put_8 (abfd, R_NO_RELOCATION + 24 + (((skip >> 2) - 1) >> 8), p);
1117 bfd_put_8 (abfd, (skip >> 2) - 1, p + 1);
1118 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1119 }
1120 /* Handle it with a three byte R_NO_RELOCATION entry. */
1121 else
1122 {
1123 bfd_put_8 (abfd, R_NO_RELOCATION + 28 + (((skip >> 2) - 1) >> 16), p);
1124 bfd_put_16 (abfd, (skip >> 2) - 1, p + 1);
1125 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1126 }
1127 }
1128 /* Ugh. Punt and use a 4 byte entry. */
1129 else if (skip > 0)
1130 {
1131 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
1132 bfd_put_8 (abfd, skip >> 16, p + 1);
1133 bfd_put_16 (abfd, skip, p + 2);
1134 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1135 }
1136 return p;
1137 }
1138
1139 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
1140 from a BFD relocation. Update the size of the subspace relocation
1141 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
1142 into the relocation stream. */
1143
1144 static unsigned char *
1145 som_reloc_addend (abfd, addend, p, subspace_reloc_sizep, queue)
1146 bfd *abfd;
1147 int addend;
1148 unsigned char *p;
1149 unsigned int *subspace_reloc_sizep;
1150 struct reloc_queue *queue;
1151 {
1152 if ((unsigned)(addend) + 0x80 < 0x100)
1153 {
1154 bfd_put_8 (abfd, R_DATA_OVERRIDE + 1, p);
1155 bfd_put_8 (abfd, addend, p + 1);
1156 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1157 }
1158 else if ((unsigned) (addend) + 0x8000 < 0x10000)
1159 {
1160 bfd_put_8 (abfd, R_DATA_OVERRIDE + 2, p);
1161 bfd_put_16 (abfd, addend, p + 1);
1162 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1163 }
1164 else if ((unsigned) (addend) + 0x800000 < 0x1000000)
1165 {
1166 bfd_put_8 (abfd, R_DATA_OVERRIDE + 3, p);
1167 bfd_put_8 (abfd, addend >> 16, p + 1);
1168 bfd_put_16 (abfd, addend, p + 2);
1169 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1170 }
1171 else
1172 {
1173 bfd_put_8 (abfd, R_DATA_OVERRIDE + 4, p);
1174 bfd_put_32 (abfd, addend, p + 1);
1175 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
1176 }
1177 return p;
1178 }
1179
1180 /* Handle a single function call relocation. */
1181
1182 static unsigned char *
1183 som_reloc_call (abfd, p, subspace_reloc_sizep, bfd_reloc, sym_num, queue)
1184 bfd *abfd;
1185 unsigned char *p;
1186 unsigned int *subspace_reloc_sizep;
1187 arelent *bfd_reloc;
1188 int sym_num;
1189 struct reloc_queue *queue;
1190 {
1191 int arg_bits = HPPA_R_ARG_RELOC (bfd_reloc->addend);
1192 int rtn_bits = arg_bits & 0x3;
1193 int type, done = 0;
1194
1195 /* You'll never believe all this is necessary to handle relocations
1196 for function calls. Having to compute and pack the argument
1197 relocation bits is the real nightmare.
1198
1199 If you're interested in how this works, just forget it. You really
1200 do not want to know about this braindamage. */
1201
1202 /* First see if this can be done with a "simple" relocation. Simple
1203 relocations have a symbol number < 0x100 and have simple encodings
1204 of argument relocations. */
1205
1206 if (sym_num < 0x100)
1207 {
1208 switch (arg_bits)
1209 {
1210 case 0:
1211 case 1:
1212 type = 0;
1213 break;
1214 case 1 << 8:
1215 case 1 << 8 | 1:
1216 type = 1;
1217 break;
1218 case 1 << 8 | 1 << 6:
1219 case 1 << 8 | 1 << 6 | 1:
1220 type = 2;
1221 break;
1222 case 1 << 8 | 1 << 6 | 1 << 4:
1223 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
1224 type = 3;
1225 break;
1226 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
1227 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
1228 type = 4;
1229 break;
1230 default:
1231 /* Not one of the easy encodings. This will have to be
1232 handled by the more complex code below. */
1233 type = -1;
1234 break;
1235 }
1236 if (type != -1)
1237 {
1238 /* Account for the return value too. */
1239 if (rtn_bits)
1240 type += 5;
1241
1242 /* Emit a 2 byte relocation. Then see if it can be handled
1243 with a relocation which is already in the relocation queue. */
1244 bfd_put_8 (abfd, bfd_reloc->howto->type + type, p);
1245 bfd_put_8 (abfd, sym_num, p + 1);
1246 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1247 done = 1;
1248 }
1249 }
1250
1251 /* If this could not be handled with a simple relocation, then do a hard
1252 one. Hard relocations occur if the symbol number was too high or if
1253 the encoding of argument relocation bits is too complex. */
1254 if (! done)
1255 {
1256 /* Don't ask about these magic sequences. I took them straight
1257 from gas-1.36 which took them from the a.out man page. */
1258 type = rtn_bits;
1259 if ((arg_bits >> 6 & 0xf) == 0xe)
1260 type += 9 * 40;
1261 else
1262 type += (3 * (arg_bits >> 8 & 3) + (arg_bits >> 6 & 3)) * 40;
1263 if ((arg_bits >> 2 & 0xf) == 0xe)
1264 type += 9 * 4;
1265 else
1266 type += (3 * (arg_bits >> 4 & 3) + (arg_bits >> 2 & 3)) * 4;
1267
1268 /* Output the first two bytes of the relocation. These describe
1269 the length of the relocation and encoding style. */
1270 bfd_put_8 (abfd, bfd_reloc->howto->type + 10
1271 + 2 * (sym_num >= 0x100) + (type >= 0x100),
1272 p);
1273 bfd_put_8 (abfd, type, p + 1);
1274
1275 /* Now output the symbol index and see if this bizarre relocation
1276 just happened to be in the relocation queue. */
1277 if (sym_num < 0x100)
1278 {
1279 bfd_put_8 (abfd, sym_num, p + 2);
1280 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1281 }
1282 else
1283 {
1284 bfd_put_8 (abfd, sym_num >> 16, p + 2);
1285 bfd_put_16 (abfd, sym_num, p + 3);
1286 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
1287 }
1288 }
1289 return p;
1290 }
1291
1292
1293 /* Return the logarithm of X, base 2, considering X unsigned.
1294 Abort if X is not a power of two -- this should never happen (FIXME:
1295 It will happen on corrupt executables. GDB should give an error, not
1296 a coredump, in that case). */
1297
1298 static int
1299 log2 (x)
1300 unsigned int x;
1301 {
1302 int log = 0;
1303
1304 /* Test for 0 or a power of 2. */
1305 if (x == 0 || x != (x & -x))
1306 abort();
1307
1308 while ((x >>= 1) != 0)
1309 log++;
1310 return log;
1311 }
1312
1313 static bfd_reloc_status_type
1314 hppa_som_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd)
1315 bfd *abfd;
1316 arelent *reloc_entry;
1317 asymbol *symbol_in;
1318 PTR data;
1319 asection *input_section;
1320 bfd *output_bfd;
1321 {
1322 if (output_bfd)
1323 {
1324 reloc_entry->address += input_section->output_offset;
1325 return bfd_reloc_ok;
1326 }
1327 return bfd_reloc_ok;
1328 }
1329
1330 /* Given a generic HPPA relocation type, the instruction format,
1331 and a field selector, return an appropriate SOM reloation.
1332
1333 FIXME. Need to handle %RR, %LR and the like as field selectors.
1334 These will need to generate multiple SOM relocations. */
1335
1336 int **
1337 hppa_som_gen_reloc_type (abfd, base_type, format, field)
1338 bfd *abfd;
1339 int base_type;
1340 int format;
1341 enum hppa_reloc_field_selector_type field;
1342 {
1343 int *final_type, **final_types;
1344
1345 final_types = (int **) bfd_alloc_by_size_t (abfd, sizeof (int *) * 3);
1346 final_type = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1347
1348 /* The field selector may require additional relocations to be
1349 generated. It's impossible to know at this moment if additional
1350 relocations will be needed, so we make them. The code to actually
1351 write the relocation/fixup stream is responsible for removing
1352 any redundant relocations. */
1353 switch (field)
1354 {
1355 case e_fsel:
1356 case e_psel:
1357 case e_lpsel:
1358 case e_rpsel:
1359 case e_tsel:
1360 case e_ltsel:
1361 case e_rtsel:
1362 final_types[0] = final_type;
1363 final_types[1] = NULL;
1364 final_types[2] = NULL;
1365 *final_type = base_type;
1366 break;
1367
1368 case e_lssel:
1369 case e_rssel:
1370 final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1371 *final_types[0] = R_S_MODE;
1372 final_types[1] = final_type;
1373 final_types[2] = NULL;
1374 *final_type = base_type;
1375 break;
1376
1377 case e_lsel:
1378 case e_rsel:
1379 final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1380 *final_types[0] = R_N_MODE;
1381 final_types[1] = final_type;
1382 final_types[2] = NULL;
1383 *final_type = base_type;
1384 break;
1385
1386 case e_ldsel:
1387 case e_rdsel:
1388 final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1389 *final_types[0] = R_D_MODE;
1390 final_types[1] = final_type;
1391 final_types[2] = NULL;
1392 *final_type = base_type;
1393 break;
1394
1395 case e_lrsel:
1396 case e_rrsel:
1397 final_types[0] = (int *) bfd_alloc_by_size_t (abfd, sizeof (int));
1398 *final_types[0] = R_R_MODE;
1399 final_types[1] = final_type;
1400 final_types[2] = NULL;
1401 *final_type = base_type;
1402 break;
1403 }
1404
1405 switch (base_type)
1406 {
1407 case R_HPPA:
1408 /* PLABELs get their own relocation type. */
1409 if (field == e_psel
1410 || field == e_lpsel
1411 || field == e_rpsel)
1412 {
1413 /* A PLABEL relocation that has a size of 32 bits must
1414 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
1415 if (format == 32)
1416 *final_type = R_DATA_PLABEL;
1417 else
1418 *final_type = R_CODE_PLABEL;
1419 }
1420 /* A relocatoin in the data space is always a full 32bits. */
1421 else if (format == 32)
1422 *final_type = R_DATA_ONE_SYMBOL;
1423
1424 break;
1425
1426 case R_HPPA_GOTOFF:
1427 /* More PLABEL special cases. */
1428 if (field == e_psel
1429 || field == e_lpsel
1430 || field == e_rpsel)
1431 *final_type = R_DATA_PLABEL;
1432 break;
1433
1434 case R_HPPA_NONE:
1435 case R_HPPA_ABS_CALL:
1436 case R_HPPA_PCREL_CALL:
1437 case R_HPPA_COMPLEX:
1438 case R_HPPA_COMPLEX_PCREL_CALL:
1439 case R_HPPA_COMPLEX_ABS_CALL:
1440 /* Right now we can default all these. */
1441 break;
1442 }
1443 return final_types;
1444 }
1445
1446 /* Return the address of the correct entry in the PA SOM relocation
1447 howto table. */
1448
1449 static const reloc_howto_type *
1450 som_bfd_reloc_type_lookup (arch, code)
1451 bfd_arch_info_type *arch;
1452 bfd_reloc_code_real_type code;
1453 {
1454 if ((int) code < (int) R_NO_RELOCATION + 255)
1455 {
1456 BFD_ASSERT ((int) som_hppa_howto_table[(int) code].type == (int) code);
1457 return &som_hppa_howto_table[(int) code];
1458 }
1459
1460 return (reloc_howto_type *) 0;
1461 }
1462
1463 /* Perform some initialization for an object. Save results of this
1464 initialization in the BFD. */
1465
1466 static bfd_target *
1467 som_object_setup (abfd, file_hdrp, aux_hdrp)
1468 bfd *abfd;
1469 struct header *file_hdrp;
1470 struct som_exec_auxhdr *aux_hdrp;
1471 {
1472 /* som_mkobject will set bfd_error if som_mkobject fails. */
1473 if (som_mkobject (abfd) != true)
1474 return 0;
1475
1476 /* Set BFD flags based on what information is available in the SOM. */
1477 abfd->flags = NO_FLAGS;
1478 if (! file_hdrp->entry_offset)
1479 abfd->flags |= HAS_RELOC;
1480 else
1481 abfd->flags |= EXEC_P;
1482 if (file_hdrp->symbol_total)
1483 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
1484
1485 bfd_get_start_address (abfd) = aux_hdrp->exec_entry;
1486 bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 0);
1487 bfd_get_symcount (abfd) = file_hdrp->symbol_total;
1488
1489 /* Initialize the saved symbol table and string table to NULL.
1490 Save important offsets and sizes from the SOM header into
1491 the BFD. */
1492 obj_som_stringtab (abfd) = (char *) NULL;
1493 obj_som_symtab (abfd) = (som_symbol_type *) NULL;
1494 obj_som_stringtab_size (abfd) = file_hdrp->symbol_strings_size;
1495 obj_som_sym_filepos (abfd) = file_hdrp->symbol_location;
1496 obj_som_str_filepos (abfd) = file_hdrp->symbol_strings_location;
1497 obj_som_reloc_filepos (abfd) = file_hdrp->fixup_request_location;
1498
1499 return abfd->xvec;
1500 }
1501
1502 /* Create a new BFD section for NAME. If NAME already exists, then create a
1503 new unique name, with NAME as the prefix. This exists because SOM .o files
1504 may have more than one $CODE$ subspace. */
1505
1506 static asection *
1507 make_unique_section (abfd, name, num)
1508 bfd *abfd;
1509 CONST char *name;
1510 int num;
1511 {
1512 asection *sect;
1513 char *newname;
1514 char altname[100];
1515
1516 sect = bfd_make_section (abfd, name);
1517 while (!sect)
1518 {
1519 sprintf (altname, "%s-%d", name, num++);
1520 sect = bfd_make_section (abfd, altname);
1521 }
1522
1523 newname = bfd_alloc (abfd, strlen (sect->name) + 1);
1524 strcpy (newname, sect->name);
1525
1526 sect->name = newname;
1527 return sect;
1528 }
1529
1530 /* Convert all of the space and subspace info into BFD sections. Each space
1531 contains a number of subspaces, which in turn describe the mapping between
1532 regions of the exec file, and the address space that the program runs in.
1533 BFD sections which correspond to spaces will overlap the sections for the
1534 associated subspaces. */
1535
1536 static boolean
1537 setup_sections (abfd, file_hdr)
1538 bfd *abfd;
1539 struct header *file_hdr;
1540 {
1541 char *space_strings;
1542 int space_index;
1543 unsigned int total_subspaces = 0;
1544
1545 /* First, read in space names */
1546
1547 space_strings = alloca (file_hdr->space_strings_size);
1548 if (!space_strings)
1549 return false;
1550
1551 if (bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET) < 0)
1552 return false;
1553 if (bfd_read (space_strings, 1, file_hdr->space_strings_size, abfd)
1554 != file_hdr->space_strings_size)
1555 return false;
1556
1557 /* Loop over all of the space dictionaries, building up sections */
1558 for (space_index = 0; space_index < file_hdr->space_total; space_index++)
1559 {
1560 struct space_dictionary_record space;
1561 struct subspace_dictionary_record subspace, save_subspace;
1562 int subspace_index;
1563 asection *space_asect;
1564
1565 /* Read the space dictionary element */
1566 if (bfd_seek (abfd, file_hdr->space_location
1567 + space_index * sizeof space, SEEK_SET) < 0)
1568 return false;
1569 if (bfd_read (&space, 1, sizeof space, abfd) != sizeof space)
1570 return false;
1571
1572 /* Setup the space name string */
1573 space.name.n_name = space.name.n_strx + space_strings;
1574
1575 /* Make a section out of it */
1576 space_asect = make_unique_section (abfd, space.name.n_name, space_index);
1577 if (!space_asect)
1578 return false;
1579
1580 /* Now, read in the first subspace for this space */
1581 if (bfd_seek (abfd, file_hdr->subspace_location
1582 + space.subspace_index * sizeof subspace,
1583 SEEK_SET) < 0)
1584 return false;
1585 if (bfd_read (&subspace, 1, sizeof subspace, abfd) != sizeof subspace)
1586 return false;
1587 /* Seek back to the start of the subspaces for loop below */
1588 if (bfd_seek (abfd, file_hdr->subspace_location
1589 + space.subspace_index * sizeof subspace,
1590 SEEK_SET) < 0)
1591 return false;
1592
1593 /* Setup the start address and file loc from the first subspace record */
1594 space_asect->vma = subspace.subspace_start;
1595 space_asect->filepos = subspace.file_loc_init_value;
1596 space_asect->alignment_power = log2 (subspace.alignment);
1597
1598 /* Initialize save_subspace so we can reliably determine if this
1599 loop placed any useful values into it. */
1600 bzero (&save_subspace, sizeof (struct subspace_dictionary_record));
1601
1602 /* Loop over the rest of the subspaces, building up more sections */
1603 for (subspace_index = 0; subspace_index < space.subspace_quantity;
1604 subspace_index++)
1605 {
1606 asection *subspace_asect;
1607
1608 /* Read in the next subspace */
1609 if (bfd_read (&subspace, 1, sizeof subspace, abfd)
1610 != sizeof subspace)
1611 return false;
1612
1613 /* Setup the subspace name string */
1614 subspace.name.n_name = subspace.name.n_strx + space_strings;
1615
1616 /* Make a section out of this subspace */
1617 subspace_asect = make_unique_section (abfd, subspace.name.n_name,
1618 space.subspace_index + subspace_index);
1619
1620 if (!subspace_asect)
1621 return false;
1622
1623 /* Keep an easy mapping between subspaces and sections. */
1624 som_section_data (subspace_asect)->subspace_index
1625 = total_subspaces++;
1626
1627 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
1628 by the access_control_bits in the subspace header. */
1629 switch (subspace.access_control_bits >> 4)
1630 {
1631 /* Readonly data. */
1632 case 0x0:
1633 subspace_asect->flags |= SEC_DATA | SEC_READONLY;
1634 break;
1635
1636 /* Normal data. */
1637 case 0x1:
1638 subspace_asect->flags |= SEC_DATA;
1639 break;
1640
1641 /* Readonly code and the gateways.
1642 Gateways have other attributes which do not map
1643 into anything BFD knows about. */
1644 case 0x2:
1645 case 0x4:
1646 case 0x5:
1647 case 0x6:
1648 case 0x7:
1649 subspace_asect->flags |= SEC_CODE | SEC_READONLY;
1650 break;
1651
1652 /* dynamic (writable) code. */
1653 case 0x3:
1654 subspace_asect->flags |= SEC_CODE;
1655 break;
1656 }
1657
1658 if (subspace.dup_common || subspace.is_common)
1659 subspace_asect->flags |= SEC_IS_COMMON;
1660 else if (subspace.subspace_length > 0)
1661 subspace_asect->flags |= SEC_HAS_CONTENTS;
1662 if (subspace.is_loadable)
1663 subspace_asect->flags |= SEC_ALLOC | SEC_LOAD;
1664 if (subspace.code_only)
1665 subspace_asect->flags |= SEC_CODE;
1666
1667 /* Both file_loc_init_value and initialization_length will
1668 be zero for a BSS like subspace. */
1669 if (subspace.file_loc_init_value == 0
1670 && subspace.initialization_length == 0)
1671 subspace_asect->flags &= ~(SEC_DATA | SEC_LOAD);
1672
1673 /* This subspace has relocations.
1674 The fixup_request_quantity is a byte count for the number of
1675 entries in the relocation stream; it is not the actual number
1676 of relocations in the subspace. */
1677 if (subspace.fixup_request_quantity != 0)
1678 {
1679 subspace_asect->flags |= SEC_RELOC;
1680 subspace_asect->rel_filepos = subspace.fixup_request_index;
1681 som_section_data (subspace_asect)->reloc_size
1682 = subspace.fixup_request_quantity;
1683 /* We can not determine this yet. When we read in the
1684 relocation table the correct value will be filled in. */
1685 subspace_asect->reloc_count = -1;
1686 }
1687
1688 /* Update save_subspace if appropriate. */
1689 if (subspace.file_loc_init_value > save_subspace.file_loc_init_value)
1690 save_subspace = subspace;
1691
1692 subspace_asect->vma = subspace.subspace_start;
1693 subspace_asect->_cooked_size = subspace.subspace_length;
1694 subspace_asect->_raw_size = subspace.subspace_length;
1695 subspace_asect->alignment_power = log2 (subspace.alignment);
1696 subspace_asect->filepos = subspace.file_loc_init_value;
1697 }
1698
1699 /* Yow! there is no subspace within the space which actually
1700 has initialized information in it; this should never happen
1701 as far as I know. */
1702 if (!save_subspace.file_loc_init_value)
1703 abort ();
1704
1705 /* Setup the sizes for the space section based upon the info in the
1706 last subspace of the space. */
1707 space_asect->_cooked_size = save_subspace.subspace_start
1708 - space_asect->vma + save_subspace.subspace_length;
1709 space_asect->_raw_size = save_subspace.file_loc_init_value
1710 - space_asect->filepos + save_subspace.initialization_length;
1711 }
1712 return true;
1713 }
1714
1715 /* Read in a SOM object and make it into a BFD. */
1716
1717 static bfd_target *
1718 som_object_p (abfd)
1719 bfd *abfd;
1720 {
1721 struct header file_hdr;
1722 struct som_exec_auxhdr aux_hdr;
1723
1724 if (bfd_read ((PTR) & file_hdr, 1, FILE_HDR_SIZE, abfd) != FILE_HDR_SIZE)
1725 {
1726 bfd_error = system_call_error;
1727 return 0;
1728 }
1729
1730 if (!_PA_RISC_ID (file_hdr.system_id))
1731 {
1732 bfd_error = wrong_format;
1733 return 0;
1734 }
1735
1736 switch (file_hdr.a_magic)
1737 {
1738 case RELOC_MAGIC:
1739 case EXEC_MAGIC:
1740 case SHARE_MAGIC:
1741 case DEMAND_MAGIC:
1742 #ifdef DL_MAGIC
1743 case DL_MAGIC:
1744 #endif
1745 #ifdef SHL_MAGIC
1746 case SHL_MAGIC:
1747 #endif
1748 #ifdef EXECLIBMAGIC
1749 case EXECLIBMAGIC:
1750 #endif
1751 #ifdef SHARED_MAGIC_CNX
1752 case SHARED_MAGIC_CNX:
1753 #endif
1754 break;
1755 default:
1756 bfd_error = wrong_format;
1757 return 0;
1758 }
1759
1760 if (file_hdr.version_id != VERSION_ID
1761 && file_hdr.version_id != NEW_VERSION_ID)
1762 {
1763 bfd_error = wrong_format;
1764 return 0;
1765 }
1766
1767 /* If the aux_header_size field in the file header is zero, then this
1768 object is an incomplete executable (a .o file). Do not try to read
1769 a non-existant auxiliary header. */
1770 bzero (&aux_hdr, sizeof (struct som_exec_auxhdr));
1771 if (file_hdr.aux_header_size != 0)
1772 {
1773 if (bfd_read ((PTR) & aux_hdr, 1, AUX_HDR_SIZE, abfd) != AUX_HDR_SIZE)
1774 {
1775 bfd_error = wrong_format;
1776 return 0;
1777 }
1778 }
1779
1780 if (!setup_sections (abfd, &file_hdr))
1781 {
1782 /* setup_sections does not bubble up a bfd error code. */
1783 bfd_error = bad_value;
1784 return 0;
1785 }
1786
1787 /* This appears to be a valid SOM object. Do some initialization. */
1788 return som_object_setup (abfd, &file_hdr, &aux_hdr);
1789 }
1790
1791 /* Create a SOM object. */
1792
1793 static boolean
1794 som_mkobject (abfd)
1795 bfd *abfd;
1796 {
1797 /* Allocate memory to hold backend information. */
1798 abfd->tdata.som_data = (struct som_data_struct *)
1799 bfd_zalloc (abfd, sizeof (struct som_data_struct));
1800 if (abfd->tdata.som_data == NULL)
1801 {
1802 bfd_error = no_memory;
1803 return false;
1804 }
1805 obj_som_file_hdr (abfd) = bfd_zalloc (abfd, sizeof (struct header));
1806 if (obj_som_file_hdr (abfd) == NULL)
1807
1808 {
1809 bfd_error = no_memory;
1810 return false;
1811 }
1812 return true;
1813 }
1814
1815 /* Initialize some information in the file header. This routine makes
1816 not attempt at doing the right thing for a full executable; it
1817 is only meant to handle relocatable objects. */
1818
1819 static boolean
1820 som_prep_headers (abfd)
1821 bfd *abfd;
1822 {
1823 struct header *file_hdr = obj_som_file_hdr (abfd);
1824 asection *section;
1825
1826 /* FIXME. This should really be conditional based on whether or not
1827 PA1.1 instructions/registers have been used. */
1828 file_hdr->system_id = HP9000S800_ID;
1829
1830 /* FIXME. Only correct for building relocatable objects. */
1831 if (abfd->flags & EXEC_P)
1832 abort ();
1833 else
1834 file_hdr->a_magic = RELOC_MAGIC;
1835
1836 /* Only new format SOM is supported. */
1837 file_hdr->version_id = NEW_VERSION_ID;
1838
1839 /* These fields are optional, and embedding timestamps is not always
1840 a wise thing to do, it makes comparing objects during a multi-stage
1841 bootstrap difficult. */
1842 file_hdr->file_time.secs = 0;
1843 file_hdr->file_time.nanosecs = 0;
1844
1845 if (abfd->flags & EXEC_P)
1846 abort ();
1847 else
1848 {
1849 file_hdr->entry_space = 0;
1850 file_hdr->entry_subspace = 0;
1851 file_hdr->entry_offset = 0;
1852 }
1853
1854 /* FIXME. I do not know if we ever need to put anything other
1855 than zero in this field. */
1856 file_hdr->presumed_dp = 0;
1857
1858 /* Now iterate over the sections translating information from
1859 BFD sections to SOM spaces/subspaces. */
1860
1861 for (section = abfd->sections; section != NULL; section = section->next)
1862 {
1863 /* Ignore anything which has not been marked as a space or
1864 subspace. */
1865 if (som_section_data (section)->is_space == 0
1866
1867 && som_section_data (section)->is_subspace == 0)
1868 continue;
1869
1870 if (som_section_data (section)->is_space)
1871 {
1872 /* Set space attributes. Note most attributes of SOM spaces
1873 are set based on the subspaces it contains. */
1874 som_section_data (section)->space_dict.loader_fix_index = -1;
1875 som_section_data (section)->space_dict.init_pointer_index = -1;
1876 }
1877 else
1878 {
1879 /* Set subspace attributes. Basic stuff is done here, additional
1880 attributes are filled in later as more information becomes
1881 available. */
1882 if (section->flags & SEC_IS_COMMON)
1883 {
1884 som_section_data (section)->subspace_dict.dup_common = 1;
1885 som_section_data (section)->subspace_dict.is_common = 1;
1886 }
1887
1888 if (section->flags & SEC_ALLOC)
1889 som_section_data (section)->subspace_dict.is_loadable = 1;
1890
1891 if (section->flags & SEC_CODE)
1892 som_section_data (section)->subspace_dict.code_only = 1;
1893
1894 som_section_data (section)->subspace_dict.subspace_start =
1895 section->vma;
1896 som_section_data (section)->subspace_dict.subspace_length =
1897 bfd_section_size (abfd, section);
1898 som_section_data (section)->subspace_dict.initialization_length =
1899 bfd_section_size (abfd, section);
1900 som_section_data (section)->subspace_dict.alignment =
1901 1 << section->alignment_power;
1902 }
1903 }
1904 return true;
1905 }
1906
1907 /* Count and return the number of spaces attached to the given BFD. */
1908
1909 static unsigned long
1910 som_count_spaces (abfd)
1911 bfd *abfd;
1912 {
1913 int count = 0;
1914 asection *section;
1915
1916 for (section = abfd->sections; section != NULL; section = section->next)
1917 count += som_section_data (section)->is_space;
1918
1919 return count;
1920 }
1921
1922 /* Count the number of subspaces attached to the given BFD. */
1923
1924 static unsigned long
1925 som_count_subspaces (abfd)
1926 bfd *abfd;
1927 {
1928 int count = 0;
1929 asection *section;
1930
1931 for (section = abfd->sections; section != NULL; section = section->next)
1932 count += som_section_data (section)->is_subspace;
1933
1934 return count;
1935 }
1936
1937 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
1938
1939 We desire symbols to be ordered starting with the symbol with the
1940 highest relocation count down to the symbol with the lowest relocation
1941 count. Doing so compacts the relocation stream. */
1942
1943 static int
1944 compare_syms (sym1, sym2)
1945 asymbol **sym1;
1946 asymbol **sym2;
1947
1948 {
1949 unsigned int count1, count2;
1950
1951 /* Get relocation count for each symbol. Note that the count
1952 is stored in the udata pointer for section symbols! */
1953 if ((*sym1)->flags & BSF_SECTION_SYM)
1954 count1 = (int)(*sym1)->udata;
1955 else
1956 count1 = (*som_symbol_data ((*sym1)))->reloc_count;
1957
1958 if ((*sym2)->flags & BSF_SECTION_SYM)
1959 count2 = (int)(*sym2)->udata;
1960 else
1961 count2 = (*som_symbol_data ((*sym2)))->reloc_count;
1962
1963 /* Return the appropriate value. */
1964 if (count1 < count2)
1965 return 1;
1966 else if (count1 > count2)
1967 return -1;
1968 return 0;
1969 }
1970
1971 /* Perform various work in preparation for emitting the fixup stream. */
1972
1973 static void
1974 som_prep_for_fixups (abfd, syms, num_syms)
1975 bfd *abfd;
1976 asymbol **syms;
1977 unsigned long num_syms;
1978 {
1979 int i;
1980 asection *section;
1981
1982 /* Most SOM relocations involving a symbol have a length which is
1983 dependent on the index of the symbol. So symbols which are
1984 used often in relocations should have a small index. */
1985
1986 /* First initialize the counters for each symbol. */
1987 for (i = 0; i < num_syms; i++)
1988 {
1989 /* Handle a section symbol; these have no pointers back to the
1990 SOM symbol info. So we just use the pointer field (udata)
1991 to hold the relocation count.
1992
1993 FIXME. While we're here set the name of any section symbol
1994 to something which will not screw GDB. How do other formats
1995 deal with this?!? */
1996 if (som_symbol_data (syms[i]) == NULL)
1997 {
1998 syms[i]->flags |= BSF_SECTION_SYM;
1999 syms[i]->name = "L$0\002";
2000 syms[i]->udata = (PTR) 0;
2001 }
2002 else
2003 (*som_symbol_data (syms[i]))->reloc_count = 0;
2004 }
2005
2006 /* Now that the counters are initialized, make a weighted count
2007 of how often a given symbol is used in a relocation. */
2008 for (section = abfd->sections; section != NULL; section = section->next)
2009 {
2010 int i;
2011
2012 /* Does this section have any relocations? */
2013 if (section->reloc_count <= 0)
2014 continue;
2015
2016 /* Walk through each relocation for this section. */
2017 for (i = 1; i < section->reloc_count; i++)
2018 {
2019 arelent *reloc = section->orelocation[i];
2020 int scale;
2021
2022 /* If no symbol, then there is no counter to increase. */
2023 if (reloc->sym_ptr_ptr == NULL)
2024 continue;
2025
2026 /* Scaling to encourage symbols involved in R_DP_RELATIVE
2027 and R_CODE_ONE_SYMBOL relocations to come first. These
2028 two relocations have single byte versions if the symbol
2029 index is very small. */
2030 if (reloc->howto->type == R_DP_RELATIVE
2031 || reloc->howto->type == R_CODE_ONE_SYMBOL)
2032 scale = 2;
2033 else
2034 scale = 1;
2035
2036 /* Handle section symbols by ramming the count in the udata
2037 field. It will not be used and the count is very important
2038 for these symbols. */
2039 if ((*reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
2040 {
2041 (*reloc->sym_ptr_ptr)->udata =
2042 (PTR) ((int) (*reloc->sym_ptr_ptr)->udata + scale);
2043 continue;
2044 }
2045
2046 /* A normal symbol. Increment the count. */
2047 (*som_symbol_data ((*reloc->sym_ptr_ptr)))->reloc_count += scale;
2048 }
2049 }
2050
2051 /* Now sort the symbols. */
2052 qsort (syms, num_syms, sizeof (asymbol *), compare_syms);
2053
2054 /* Compute the symbol indexes, they will be needed by the relocation
2055 code. */
2056 for (i = 0; i < num_syms; i++)
2057 {
2058 /* A section symbol. Again, there is no pointer to backend symbol
2059 information, so we reuse (abuse) the udata field again. */
2060 if (syms[i]->flags & BSF_SECTION_SYM)
2061 syms[i]->udata = (PTR) i;
2062 else
2063 (*som_symbol_data (syms[i]))->index = i;
2064 }
2065 }
2066
2067 static boolean
2068 som_write_fixups (abfd, current_offset, total_reloc_sizep)
2069 bfd *abfd;
2070 unsigned long current_offset;
2071 unsigned int *total_reloc_sizep;
2072 {
2073 unsigned int i, j;
2074 unsigned char *tmp_space, *p;
2075 unsigned int total_reloc_size = 0;
2076 unsigned int subspace_reloc_size = 0;
2077 unsigned int num_spaces = obj_som_file_hdr (abfd)->space_total;
2078 asection *section = abfd->sections;
2079
2080 /* Get a chunk of memory that we can use as buffer space, then throw
2081 away. */
2082 tmp_space = alloca (SOM_TMP_BUFSIZE);
2083 bzero (tmp_space, SOM_TMP_BUFSIZE);
2084 p = tmp_space;
2085
2086 /* All the fixups for a particular subspace are emitted in a single
2087 stream. All the subspaces for a particular space are emitted
2088 as a single stream.
2089
2090 So, to get all the locations correct one must iterate through all the
2091 spaces, for each space iterate through its subspaces and output a
2092 fixups stream. */
2093 for (i = 0; i < num_spaces; i++)
2094 {
2095 asection *subsection;
2096
2097 /* Find a space. */
2098 while (som_section_data (section)->is_space == 0)
2099 section = section->next;
2100
2101 /* Now iterate through each of its subspaces. */
2102 for (subsection = abfd->sections;
2103 subsection != NULL;
2104 subsection = subsection->next)
2105 {
2106 int reloc_offset, current_rounding_mode;
2107
2108 /* Find a subspace of this space. */
2109 if (som_section_data (subsection)->is_subspace == 0
2110 || som_section_data (subsection)->containing_space != section)
2111 continue;
2112
2113 /* If this subspace had no relocations, then we're finished
2114 with it. */
2115 if (subsection->reloc_count <= 0)
2116 {
2117 som_section_data (subsection)->subspace_dict.fixup_request_index
2118 = -1;
2119 continue;
2120 }
2121
2122 /* This subspace has some relocations. Put the relocation stream
2123 index into the subspace record. */
2124 som_section_data (subsection)->subspace_dict.fixup_request_index
2125 = total_reloc_size;
2126
2127 /* To make life easier start over with a clean slate for
2128 each subspace. Seek to the start of the relocation stream
2129 for this subspace in preparation for writing out its fixup
2130 stream. */
2131 if (bfd_seek (abfd, current_offset + total_reloc_size, SEEK_SET) != 0)
2132 {
2133 bfd_error = system_call_error;
2134 return false;
2135 }
2136
2137 /* Buffer space has already been allocated. Just perform some
2138 initialization here. */
2139 p = tmp_space;
2140 subspace_reloc_size = 0;
2141 reloc_offset = 0;
2142 som_initialize_reloc_queue (reloc_queue);
2143 current_rounding_mode = R_N_MODE;
2144
2145 /* Translate each BFD relocation into one or more SOM
2146 relocations. */
2147 for (j = 0; j < subsection->reloc_count; j++)
2148 {
2149 arelent *bfd_reloc = subsection->orelocation[j];
2150 unsigned int skip;
2151 int sym_num;
2152
2153 /* Get the symbol number. Remember it's stored in a
2154 special place for section symbols. */
2155 if ((*bfd_reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
2156 sym_num = (int) (*bfd_reloc->sym_ptr_ptr)->udata;
2157 else
2158 sym_num = (*som_symbol_data ((*bfd_reloc->sym_ptr_ptr)))->index;
2159
2160 /* If there is not enough room for the next couple relocations,
2161 then dump the current buffer contents now. Also reinitialize
2162 the relocation queue.
2163
2164 FIXME. We assume here that no BFD relocation will expand
2165 to more than 100 bytes of SOM relocations. This should (?!?)
2166 be quite safe. */
2167 if (p - tmp_space + 100 > SOM_TMP_BUFSIZE)
2168 {
2169 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2170 != p - tmp_space)
2171 {
2172 bfd_error = system_call_error;
2173 return false;
2174 }
2175 p = tmp_space;
2176 som_initialize_reloc_queue (reloc_queue);
2177 }
2178
2179 /* Emit R_NO_RELOCATION fixups to map any bytes which were
2180 skipped. */
2181 skip = bfd_reloc->address - reloc_offset;
2182 p = som_reloc_skip (abfd, skip, p,
2183 &subspace_reloc_size, reloc_queue);
2184
2185 /* Update reloc_offset for the next iteration.
2186
2187 Many relocations do not consume input bytes. They
2188 are markers, or set state necessary to perform some
2189 later relocation. */
2190 switch (bfd_reloc->howto->type)
2191 {
2192 /* This only needs to handle relocations that may be
2193 made by hppa_som_gen_reloc. */
2194 case R_ENTRY:
2195 case R_EXIT:
2196 case R_N_MODE:
2197 case R_S_MODE:
2198 case R_D_MODE:
2199 case R_R_MODE:
2200 reloc_offset = bfd_reloc->address;
2201 break;
2202
2203 default:
2204 reloc_offset = bfd_reloc->address + 4;
2205 break;
2206 }
2207
2208 /* Now the actual relocation we care about. */
2209 switch (bfd_reloc->howto->type)
2210 {
2211 case R_PCREL_CALL:
2212 case R_ABS_CALL:
2213 p = som_reloc_call (abfd, p, &subspace_reloc_size,
2214 bfd_reloc, sym_num, reloc_queue);
2215 break;
2216
2217 case R_CODE_ONE_SYMBOL:
2218 case R_DP_RELATIVE:
2219 /* Account for any addend. */
2220 if (bfd_reloc->addend)
2221 p = som_reloc_addend (abfd, bfd_reloc->addend, p,
2222 &subspace_reloc_size, reloc_queue);
2223
2224 if (sym_num < 0x20)
2225 {
2226 bfd_put_8 (abfd, bfd_reloc->howto->type + sym_num, p);
2227 subspace_reloc_size += 1;
2228 p += 1;
2229 }
2230 else if (sym_num < 0x100)
2231 {
2232 bfd_put_8 (abfd, bfd_reloc->howto->type + 32, p);
2233 bfd_put_8 (abfd, sym_num, p + 1);
2234 p = try_prev_fixup (abfd, &subspace_reloc_size, p,
2235 2, reloc_queue);
2236 }
2237 else if (sym_num < 0x10000000)
2238 {
2239 bfd_put_8 (abfd, bfd_reloc->howto->type + 33, p);
2240 bfd_put_8 (abfd, sym_num >> 16, p + 1);
2241 bfd_put_16 (abfd, sym_num, p + 2);
2242 p = try_prev_fixup (abfd, &subspace_reloc_size,
2243 p, 4, reloc_queue);
2244 }
2245 else
2246 abort ();
2247 break;
2248
2249 case R_DATA_ONE_SYMBOL:
2250 case R_DATA_PLABEL:
2251 case R_CODE_PLABEL:
2252 /* Account for any addend. */
2253 if (bfd_reloc->addend)
2254 p = som_reloc_addend (abfd, bfd_reloc->addend, p,
2255 &subspace_reloc_size, reloc_queue);
2256
2257 if (sym_num < 0x100)
2258 {
2259 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2260 bfd_put_8 (abfd, sym_num, p + 1);
2261 p = try_prev_fixup (abfd, &subspace_reloc_size, p,
2262 2, reloc_queue);
2263 }
2264 else if (sym_num < 0x10000000)
2265 {
2266 bfd_put_8 (abfd, bfd_reloc->howto->type + 1, p);
2267 bfd_put_8 (abfd, sym_num >> 16, p + 1);
2268 bfd_put_16 (abfd, sym_num, p + 2);
2269 p = try_prev_fixup (abfd, &subspace_reloc_size,
2270 p, 4, reloc_queue);
2271 }
2272 else
2273 abort ();
2274 break;
2275
2276 case R_ENTRY:
2277 {
2278 int *descp
2279 = (int *) (*som_symbol_data ((*bfd_reloc->sym_ptr_ptr)))->unwind;
2280 bfd_put_8 (abfd, R_ENTRY, p);
2281 bfd_put_32 (abfd, descp[0], p + 1);
2282 bfd_put_32 (abfd, descp[1], p + 5);
2283 p = try_prev_fixup (abfd, &subspace_reloc_size,
2284 p, 9, reloc_queue);
2285 break;
2286 }
2287
2288 case R_EXIT:
2289 bfd_put_8 (abfd, R_EXIT, p);
2290 subspace_reloc_size += 1;
2291 p += 1;
2292 break;
2293
2294 case R_N_MODE:
2295 case R_S_MODE:
2296 case R_D_MODE:
2297 case R_R_MODE:
2298 /* If this relocation requests the current rounding
2299 mode, then it is redundant. */
2300 if (bfd_reloc->howto->type != current_rounding_mode)
2301 {
2302 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2303 subspace_reloc_size += 1;
2304 p += 1;
2305 current_rounding_mode = bfd_reloc->howto->type;
2306 }
2307 break;
2308
2309 /* Put a "R_RESERVED" relocation in the stream if
2310 we hit something we do not understand. The linker
2311 will complain loudly if this ever happens. */
2312 default:
2313 bfd_put_8 (abfd, 0xff, p);
2314 subspace_reloc_size += 1;
2315 p += 1;
2316 break;
2317 }
2318 }
2319
2320 /* Last BFD relocation for a subspace has been processed.
2321 Map the rest of the subspace with R_NO_RELOCATION fixups. */
2322 p = som_reloc_skip (abfd, bfd_section_size (abfd, subsection)
2323 - reloc_offset,
2324 p, &subspace_reloc_size, reloc_queue);
2325
2326 /* Scribble out the relocations. */
2327 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2328 != p - tmp_space)
2329 {
2330 bfd_error = system_call_error;
2331 return false;
2332 }
2333 p = tmp_space;
2334
2335 total_reloc_size += subspace_reloc_size;
2336 som_section_data (subsection)->subspace_dict.fixup_request_quantity
2337 = subspace_reloc_size;
2338 }
2339 section = section->next;
2340 }
2341 *total_reloc_sizep = total_reloc_size;
2342 return true;
2343 }
2344
2345 /* Write out the space/subspace string table. */
2346
2347 static boolean
2348 som_write_space_strings (abfd, current_offset, string_sizep)
2349 bfd *abfd;
2350 unsigned long current_offset;
2351 unsigned int *string_sizep;
2352 {
2353 unsigned char *tmp_space, *p;
2354 unsigned int strings_size = 0;
2355 asection *section;
2356
2357 /* Get a chunk of memory that we can use as buffer space, then throw
2358 away. */
2359 tmp_space = alloca (SOM_TMP_BUFSIZE);
2360 bzero (tmp_space, SOM_TMP_BUFSIZE);
2361 p = tmp_space;
2362
2363 /* Seek to the start of the space strings in preparation for writing
2364 them out. */
2365 if (bfd_seek (abfd, current_offset, SEEK_SET) != 0)
2366 {
2367 bfd_error = system_call_error;
2368 return false;
2369 }
2370
2371 /* Walk through all the spaces and subspaces (order is not important)
2372 building up and writing string table entries for their names. */
2373 for (section = abfd->sections; section != NULL; section = section->next)
2374 {
2375 int length;
2376
2377 /* Only work with space/subspaces; avoid any other sections
2378 which might have been made (.text for example). */
2379 if (som_section_data (section)->is_space == 0
2380 && som_section_data (section)->is_subspace == 0)
2381 continue;
2382
2383 /* Get the length of the space/subspace name. */
2384 length = strlen (section->name);
2385
2386 /* If there is not enough room for the next entry, then dump the
2387 current buffer contents now. Each entry will take 4 bytes to
2388 hold the string length + the string itself + null terminator. */
2389 if (p - tmp_space + 5 + length > SOM_TMP_BUFSIZE)
2390 {
2391 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2392 != p - tmp_space)
2393 {
2394 bfd_error = system_call_error;
2395 return false;
2396 }
2397 /* Reset to beginning of the buffer space. */
2398 p = tmp_space;
2399 }
2400
2401 /* First element in a string table entry is the length of the
2402 string. Alignment issues are already handled. */
2403 bfd_put_32 (abfd, length, p);
2404 p += 4;
2405 strings_size += 4;
2406
2407 /* Record the index in the space/subspace records. */
2408 if (som_section_data (section)->is_space)
2409 som_section_data (section)->space_dict.name.n_strx = strings_size;
2410 else
2411 som_section_data (section)->subspace_dict.name.n_strx = strings_size;
2412
2413 /* Next comes the string itself + a null terminator. */
2414 strcpy (p, section->name);
2415 p += length + 1;
2416 strings_size += length + 1;
2417
2418 /* Always align up to the next word boundary. */
2419 while (strings_size % 4)
2420 {
2421 bfd_put_8 (abfd, 0, p);
2422 p++;
2423 strings_size++;
2424 }
2425 }
2426
2427 /* Done with the space/subspace strings. Write out any information
2428 contained in a partial block. */
2429 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd) != p - tmp_space)
2430 {
2431 bfd_error = system_call_error;
2432 return false;
2433 }
2434 *string_sizep = strings_size;
2435 return true;
2436 }
2437
2438 /* Write out the symbol string table. */
2439
2440 static boolean
2441 som_write_symbol_strings (abfd, current_offset, syms, num_syms, string_sizep)
2442 bfd *abfd;
2443 unsigned long current_offset;
2444 asymbol **syms;
2445 unsigned int num_syms;
2446 unsigned int *string_sizep;
2447 {
2448 unsigned int i;
2449 unsigned char *tmp_space, *p;
2450 unsigned int strings_size = 0;
2451
2452 /* Get a chunk of memory that we can use as buffer space, then throw
2453 away. */
2454 tmp_space = alloca (SOM_TMP_BUFSIZE);
2455 bzero (tmp_space, SOM_TMP_BUFSIZE);
2456 p = tmp_space;
2457
2458 /* Seek to the start of the space strings in preparation for writing
2459 them out. */
2460 if (bfd_seek (abfd, current_offset, SEEK_SET) != 0)
2461 {
2462 bfd_error = system_call_error;
2463 return false;
2464 }
2465
2466 for (i = 0; i < num_syms; i++)
2467 {
2468 int length = strlen (syms[i]->name);
2469
2470 /* If there is not enough room for the next entry, then dump the
2471 current buffer contents now. */
2472 if (p - tmp_space + 5 + length > SOM_TMP_BUFSIZE)
2473 {
2474 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2475 != p - tmp_space)
2476 {
2477 bfd_error = system_call_error;
2478 return false;
2479 }
2480 /* Reset to beginning of the buffer space. */
2481 p = tmp_space;
2482 }
2483
2484 /* First element in a string table entry is the length of the
2485 string. This must always be 4 byte aligned. This is also
2486 an appropriate time to fill in the string index field in the
2487 symbol table entry. */
2488 bfd_put_32 (abfd, length, p);
2489 strings_size += 4;
2490 p += 4;
2491
2492 /* Next comes the string itself + a null terminator. */
2493 strcpy (p, syms[i]->name);
2494
2495 /* ACK. FIXME. */
2496 syms[i]->name = (char *)strings_size;
2497 p += length + 1;
2498 strings_size += length + 1;
2499
2500 /* Always align up to the next word boundary. */
2501 while (strings_size % 4)
2502 {
2503 bfd_put_8 (abfd, 0, p);
2504 strings_size++;
2505 p++;
2506 }
2507 }
2508
2509 /* Scribble out any partial block. */
2510 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd) != p - tmp_space)
2511 {
2512 bfd_error = system_call_error;
2513 return false;
2514 }
2515
2516 *string_sizep = strings_size;
2517 return true;
2518 }
2519
2520 /* Compute variable information to be placed in the SOM headers,
2521 space/subspace dictionaries, relocation streams, etc. Begin
2522 writing parts of the object file. */
2523
2524 static boolean
2525 som_begin_writing (abfd)
2526 bfd *abfd;
2527 {
2528 unsigned long current_offset = 0;
2529 int strings_size = 0;
2530 unsigned int total_reloc_size = 0;
2531 unsigned long num_spaces, num_subspaces, num_syms, i;
2532 asection *section;
2533 asymbol **syms = bfd_get_outsymbols (abfd);
2534 unsigned int total_subspaces = 0;
2535
2536 /* The file header will always be first in an object file,
2537 everything else can be in random locations. To keep things
2538 "simple" BFD will lay out the object file in the manner suggested
2539 by the PRO ABI for PA-RISC Systems. */
2540
2541 /* Before any output can really begin offsets for all the major
2542 portions of the object file must be computed. So, starting
2543 with the initial file header compute (and sometimes write)
2544 each portion of the object file. */
2545
2546 /* Make room for the file header, it's contents are not complete
2547 yet, so it can not be written at this time. */
2548 current_offset += sizeof (struct header);
2549
2550 /* Any auxiliary headers will follow the file header. Right now
2551 we support only the copyright and version headers. */
2552 obj_som_file_hdr (abfd)->aux_header_location = current_offset;
2553 obj_som_file_hdr (abfd)->aux_header_size = 0;
2554 if (obj_som_version_hdr (abfd) != NULL)
2555 {
2556 unsigned int len;
2557
2558 bfd_seek (abfd, current_offset, SEEK_SET);
2559
2560 /* Write the aux_id structure and the string length. */
2561 len = sizeof (struct aux_id) + sizeof (unsigned int);
2562 obj_som_file_hdr (abfd)->aux_header_size += len;
2563 current_offset += len;
2564 if (bfd_write ((PTR) obj_som_version_hdr (abfd), len, 1, abfd) != len)
2565 {
2566 bfd_error = system_call_error;
2567 return false;
2568 }
2569
2570 /* Write the version string. */
2571 len = obj_som_version_hdr (abfd)->string_length;
2572 obj_som_file_hdr (abfd)->aux_header_size += len;
2573 current_offset += len;
2574 if (bfd_write ((PTR) obj_som_version_hdr (abfd)->user_string,
2575 len, 1, abfd) != len)
2576 {
2577 bfd_error = system_call_error;
2578 return false;
2579 }
2580 }
2581
2582 if (obj_som_copyright_hdr (abfd) != NULL)
2583 {
2584 unsigned int len;
2585
2586 bfd_seek (abfd, current_offset, SEEK_SET);
2587
2588 /* Write the aux_id structure and the string length. */
2589 len = sizeof (struct aux_id) + sizeof (unsigned int);
2590 obj_som_file_hdr (abfd)->aux_header_size += len;
2591 current_offset += len;
2592 if (bfd_write ((PTR) obj_som_copyright_hdr (abfd), len, 1, abfd) != len)
2593 {
2594 bfd_error = system_call_error;
2595 return false;
2596 }
2597
2598 /* Write the copyright string. */
2599 len = obj_som_copyright_hdr (abfd)->string_length;
2600 obj_som_file_hdr (abfd)->aux_header_size += len;
2601 current_offset += len;
2602 if (bfd_write ((PTR) obj_som_copyright_hdr (abfd)->copyright,
2603 len, 1, abfd) != len)
2604 {
2605 bfd_error = system_call_error;
2606 return false;
2607 }
2608 }
2609
2610 /* Next comes the initialization pointers; we have no initialization
2611 pointers, so current offset does not change. */
2612 obj_som_file_hdr (abfd)->init_array_location = current_offset;
2613 obj_som_file_hdr (abfd)->init_array_total = 0;
2614
2615 /* Next are the space records. These are fixed length records.
2616
2617 Count the number of spaces to determine how much room is needed
2618 in the object file for the space records.
2619
2620 The names of the spaces are stored in a separate string table,
2621 and the index for each space into the string table is computed
2622 below. Therefore, it is not possible to write the space headers
2623 at this time. */
2624 num_spaces = som_count_spaces (abfd);
2625 obj_som_file_hdr (abfd)->space_location = current_offset;
2626 obj_som_file_hdr (abfd)->space_total = num_spaces;
2627 current_offset += num_spaces * sizeof (struct space_dictionary_record);
2628
2629 /* Next are the subspace records. These are fixed length records.
2630
2631 Count the number of subspaes to determine how much room is needed
2632 in the object file for the subspace records.
2633
2634 A variety if fields in the subspace record are still unknown at
2635 this time (index into string table, fixup stream location/size, etc). */
2636 num_subspaces = som_count_subspaces (abfd);
2637 obj_som_file_hdr (abfd)->subspace_location = current_offset;
2638 obj_som_file_hdr (abfd)->subspace_total = num_subspaces;
2639 current_offset += num_subspaces * sizeof (struct subspace_dictionary_record);
2640
2641 /* Next is the string table for the space/subspace names. We will
2642 build and write the string table on the fly. At the same time
2643 we will fill in the space/subspace name index fields. */
2644
2645 /* The string table needs to be aligned on a word boundary. */
2646 if (current_offset % 4)
2647 current_offset += (4 - (current_offset % 4));
2648
2649 /* Mark the offset of the space/subspace string table in the
2650 file header. */
2651 obj_som_file_hdr (abfd)->space_strings_location = current_offset;
2652
2653 /* Scribble out the space strings. */
2654 if (som_write_space_strings (abfd, current_offset, &strings_size) == false)
2655 return false;
2656
2657 /* Record total string table size in the header and update the
2658 current offset. */
2659 obj_som_file_hdr (abfd)->space_strings_size = strings_size;
2660 current_offset += strings_size;
2661
2662 /* Next is the symbol table. These are fixed length records.
2663
2664 Count the number of symbols to determine how much room is needed
2665 in the object file for the symbol table.
2666
2667 The names of the symbols are stored in a separate string table,
2668 and the index for each symbol name into the string table is computed
2669 below. Therefore, it is not possible to write the symobl table
2670 at this time. */
2671 num_syms = bfd_get_symcount (abfd);
2672 obj_som_file_hdr (abfd)->symbol_location = current_offset;
2673 obj_som_file_hdr (abfd)->symbol_total = num_syms;
2674 current_offset += num_syms * sizeof (struct symbol_dictionary_record);
2675
2676 /* Do prep work before handling fixups. */
2677 som_prep_for_fixups (abfd, syms, num_syms);
2678
2679 /* Next comes the fixup stream which starts on a word boundary. */
2680 if (current_offset % 4)
2681 current_offset += (4 - (current_offset % 4));
2682 obj_som_file_hdr (abfd)->fixup_request_location = current_offset;
2683
2684 /* Write the fixups and update fields in subspace headers which
2685 relate to the fixup stream. */
2686 if (som_write_fixups (abfd, current_offset, &total_reloc_size) == false)
2687 return false;
2688
2689 /* Record the total size of the fixup stream in the file header. */
2690 obj_som_file_hdr (abfd)->fixup_request_total = total_reloc_size;
2691 current_offset += total_reloc_size;
2692
2693 /* Next are the symbol strings.
2694 Align them to a word boundary. */
2695 if (current_offset % 4)
2696 current_offset += (4 - (current_offset % 4));
2697 obj_som_file_hdr (abfd)->symbol_strings_location = current_offset;
2698
2699 /* Scribble out the symbol strings. */
2700 if (som_write_symbol_strings (abfd, current_offset, syms,
2701 num_syms, &strings_size)
2702 == false)
2703 return false;
2704
2705 /* Record total string table size in header and update the
2706 current offset. */
2707 obj_som_file_hdr (abfd)->symbol_strings_size = strings_size;
2708 current_offset += strings_size;
2709
2710 /* Next is the compiler records. We do not use these. */
2711 obj_som_file_hdr (abfd)->compiler_location = current_offset;
2712 obj_som_file_hdr (abfd)->compiler_total = 0;
2713
2714 /* Now compute the file positions for the loadable subspaces. */
2715
2716 section = abfd->sections;
2717 for (i = 0; i < num_spaces; i++)
2718 {
2719 asection *subsection;
2720
2721 /* Find a space. */
2722 while (som_section_data (section)->is_space == 0)
2723 section = section->next;
2724
2725 /* Now look for all its subspaces. */
2726 for (subsection = abfd->sections;
2727 subsection != NULL;
2728 subsection = subsection->next)
2729 {
2730
2731 if (som_section_data (subsection)->is_subspace == 0
2732 || som_section_data (subsection)->containing_space != section
2733 || (subsection->flags & SEC_ALLOC) == 0)
2734 continue;
2735
2736 som_section_data (subsection)->subspace_index = total_subspaces++;
2737 /* This is real data to be loaded from the file. */
2738 if (subsection->flags & SEC_LOAD)
2739 {
2740 som_section_data (subsection)->subspace_dict.file_loc_init_value
2741 = current_offset;
2742 section->filepos = current_offset;
2743 current_offset += bfd_section_size (abfd, subsection);
2744 }
2745 /* Looks like uninitialized data. */
2746 else
2747 {
2748 som_section_data (subsection)->subspace_dict.file_loc_init_value
2749 = 0;
2750 som_section_data (subsection)->subspace_dict.
2751 initialization_length = 0;
2752 }
2753 }
2754 /* Goto the next section. */
2755 section = section->next;
2756 }
2757
2758 /* Finally compute the file positions for unloadable subspaces. */
2759
2760 obj_som_file_hdr (abfd)->unloadable_sp_location = current_offset;
2761 section = abfd->sections;
2762 for (i = 0; i < num_spaces; i++)
2763 {
2764 asection *subsection;
2765
2766 /* Find a space. */
2767 while (som_section_data (section)->is_space == 0)
2768 section = section->next;
2769
2770 /* Now look for all its subspaces. */
2771 for (subsection = abfd->sections;
2772 subsection != NULL;
2773 subsection = subsection->next)
2774 {
2775
2776 if (som_section_data (subsection)->is_subspace == 0
2777 || som_section_data (subsection)->containing_space != section
2778 || (subsection->flags & SEC_ALLOC) != 0)
2779 continue;
2780
2781 som_section_data (subsection)->subspace_index = total_subspaces++;
2782 /* This is real data to be loaded from the file. */
2783 if ((subsection->flags & SEC_LOAD) == 0)
2784 {
2785 som_section_data (subsection)->subspace_dict.file_loc_init_value
2786 = current_offset;
2787 section->filepos = current_offset;
2788 current_offset += bfd_section_size (abfd, subsection);
2789 }
2790 /* Looks like uninitialized data. */
2791 else
2792 {
2793 som_section_data (subsection)->subspace_dict.file_loc_init_value
2794 = 0;
2795 som_section_data (subsection)->subspace_dict.
2796 initialization_length = bfd_section_size (abfd, subsection);
2797 }
2798 }
2799 /* Goto the next section. */
2800 section = section->next;
2801 }
2802
2803 obj_som_file_hdr (abfd)->unloadable_sp_size
2804 = current_offset - obj_som_file_hdr (abfd)->unloadable_sp_location;
2805
2806 /* Loader fixups are not supported in any way shape or form. */
2807 obj_som_file_hdr (abfd)->loader_fixup_location = 0;
2808 obj_som_file_hdr (abfd)->loader_fixup_total = 0;
2809
2810 /* Done. Store the total size of the SOM. */
2811 obj_som_file_hdr (abfd)->som_length = current_offset;
2812 return true;
2813 }
2814
2815 /* Finally, scribble out the various headers to the disk. */
2816
2817 static boolean
2818 som_write_headers (abfd)
2819 bfd *abfd;
2820 {
2821 int num_spaces = som_count_spaces (abfd);
2822 int i;
2823 int subspace_index = 0;
2824 file_ptr location;
2825 asection *section;
2826
2827 /* Subspaces are written first so that we can set up information
2828 about them in their containing spaces as the subspace is written. */
2829
2830 /* Seek to the start of the subspace dictionary records. */
2831 location = obj_som_file_hdr (abfd)->subspace_location;
2832 bfd_seek (abfd, location, SEEK_SET);
2833 section = abfd->sections;
2834 /* Now for each loadable space write out records for its subspaces. */
2835 for (i = 0; i < num_spaces; i++)
2836 {
2837 asection *subsection;
2838
2839 /* Find a space. */
2840 while (som_section_data (section)->is_space == 0)
2841 section = section->next;
2842
2843 /* Now look for all its subspaces. */
2844 for (subsection = abfd->sections;
2845 subsection != NULL;
2846 subsection = subsection->next)
2847 {
2848
2849 /* Skip any section which does not correspond to a space
2850 or subspace. Or does not have SEC_ALLOC set (and therefore
2851 has no real bits on the disk). */
2852 if (som_section_data (subsection)->is_subspace == 0
2853 || som_section_data (subsection)->containing_space != section
2854 || (subsection->flags & SEC_ALLOC) == 0)
2855 continue;
2856
2857 /* If this is the first subspace for this space, then save
2858 the index of the subspace in its containing space. Also
2859 set "is_loadable" in the containing space. */
2860
2861 if (som_section_data (section)->space_dict.subspace_quantity == 0)
2862 {
2863 som_section_data (section)->space_dict.is_loadable = 1;
2864 som_section_data (section)->space_dict.subspace_index
2865 = subspace_index;
2866 }
2867
2868 /* Increment the number of subspaces seen and the number of
2869 subspaces contained within the current space. */
2870 subspace_index++;
2871 som_section_data (section)->space_dict.subspace_quantity++;
2872
2873 /* Mark the index of the current space within the subspace's
2874 dictionary record. */
2875 som_section_data (subsection)->subspace_dict.space_index = i;
2876
2877 /* Dump the current subspace header. */
2878 if (bfd_write ((PTR) &som_section_data (subsection)->subspace_dict,
2879 sizeof (struct subspace_dictionary_record), 1, abfd)
2880 != sizeof (struct subspace_dictionary_record))
2881 {
2882 bfd_error = system_call_error;
2883 return false;
2884 }
2885 }
2886 /* Goto the next section. */
2887 section = section->next;
2888 }
2889
2890 /* Now repeat the process for unloadable subspaces. */
2891 section = abfd->sections;
2892 /* Now for each space write out records for its subspaces. */
2893 for (i = 0; i < num_spaces; i++)
2894 {
2895 asection *subsection;
2896
2897 /* Find a space. */
2898 while (som_section_data (section)->is_space == 0)
2899 section = section->next;
2900
2901 /* Now look for all its subspaces. */
2902 for (subsection = abfd->sections;
2903 subsection != NULL;
2904 subsection = subsection->next)
2905 {
2906
2907 /* Skip any section which does not correspond to a space or
2908 subspace, or which SEC_ALLOC set (and therefore handled
2909 in the loadable spaces/subspaces code above. */
2910
2911 if (som_section_data (subsection)->is_subspace == 0
2912 || som_section_data (subsection)->containing_space != section
2913 || (subsection->flags & SEC_ALLOC) != 0)
2914 continue;
2915
2916 /* If this is the first subspace for this space, then save
2917 the index of the subspace in its containing space. Clear
2918 "is_loadable". */
2919
2920 if (som_section_data (section)->space_dict.subspace_quantity == 0)
2921 {
2922 som_section_data (section)->space_dict.is_loadable = 0;
2923 som_section_data (section)->space_dict.subspace_index
2924 = subspace_index;
2925 }
2926
2927 /* Increment the number of subspaces seen and the number of
2928 subspaces contained within the current space. */
2929 som_section_data (section)->space_dict.subspace_quantity++;
2930 subspace_index++;
2931
2932 /* Mark the index of the current space within the subspace's
2933 dictionary record. */
2934 som_section_data (subsection)->subspace_dict.space_index = i;
2935
2936 /* Dump this subspace header. */
2937 if (bfd_write ((PTR) &som_section_data (subsection)->subspace_dict,
2938 sizeof (struct subspace_dictionary_record), 1, abfd)
2939 != sizeof (struct subspace_dictionary_record))
2940 {
2941 bfd_error = system_call_error;
2942 return false;
2943 }
2944 }
2945 /* Goto the next section. */
2946 section = section->next;
2947 }
2948
2949 /* All the subspace dictiondary records are written, and all the
2950 fields are set up in the space dictionary records.
2951
2952 Seek to the right location and start writing the space
2953 dictionary records. */
2954 location = obj_som_file_hdr (abfd)->space_location;
2955 bfd_seek (abfd, location, SEEK_SET);
2956
2957 section = abfd->sections;
2958 for (i = 0; i < num_spaces; i++)
2959 {
2960
2961 /* Find a space. */
2962 while (som_section_data (section)->is_space == 0)
2963 section = section->next;
2964
2965 /* Dump its header */
2966 if (bfd_write ((PTR) &som_section_data (section)->space_dict,
2967 sizeof (struct space_dictionary_record), 1, abfd)
2968 != sizeof (struct space_dictionary_record))
2969 {
2970 bfd_error = system_call_error;
2971 return false;
2972 }
2973
2974 /* Goto the next section. */
2975 section = section->next;
2976 }
2977
2978 /* Only thing left to do is write out the file header. It is always
2979 at location zero. Seek there and write it. */
2980 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
2981 if (bfd_write ((PTR) obj_som_file_hdr (abfd),
2982 sizeof (struct header), 1, abfd)
2983 != sizeof (struct header))
2984 {
2985 bfd_error = system_call_error;
2986 return false;
2987 }
2988 return true;
2989 }
2990
2991 /* Compute and return the checksum for a SOM file header. */
2992
2993 static unsigned long
2994 som_compute_checksum (abfd)
2995 bfd *abfd;
2996 {
2997 unsigned long checksum, count, i;
2998 unsigned long *buffer = (unsigned long *) obj_som_file_hdr (abfd);
2999
3000 checksum = 0;
3001 count = sizeof (struct header) / sizeof (unsigned long);
3002 for (i = 0; i < count; i++)
3003 checksum ^= *(buffer + i);
3004
3005 return checksum;
3006 }
3007
3008 /* Build and write, in one big chunk, the entire symbol table for
3009 this BFD. */
3010
3011 static boolean
3012 som_build_and_write_symbol_table (abfd)
3013 bfd *abfd;
3014 {
3015 unsigned int num_syms = bfd_get_symcount (abfd);
3016 file_ptr symtab_location = obj_som_file_hdr (abfd)->symbol_location;
3017 asymbol **bfd_syms = bfd_get_outsymbols (abfd);
3018 struct symbol_dictionary_record *som_symtab;
3019 int i, symtab_size;
3020
3021 /* Compute total symbol table size and allocate a chunk of memory
3022 to hold the symbol table as we build it. */
3023 symtab_size = num_syms * sizeof (struct symbol_dictionary_record);
3024 som_symtab = (struct symbol_dictionary_record *) alloca (symtab_size);
3025 bzero (som_symtab, symtab_size);
3026
3027 /* Walk over each symbol. */
3028 for (i = 0; i < num_syms; i++)
3029 {
3030 /* This is really an index into the symbol strings table.
3031 By the time we get here, the index has already been
3032 computed and stored into the name field in the BFD symbol. */
3033 som_symtab[i].name.n_strx = (int) bfd_syms[i]->name;
3034
3035 /* The HP SOM linker requires detailed type information about
3036 all symbols (including undefined symbols!). Unfortunately,
3037 the type specified in an import/export statement does not
3038 always match what the linker wants. Severe braindamage. */
3039
3040 /* Section symbols will not have a SOM symbol type assigned to
3041 them yet. Assign all section symbols type ST_DATA. */
3042 if (bfd_syms[i]->flags & BSF_SECTION_SYM)
3043 som_symtab[i].symbol_type = ST_DATA;
3044 else
3045 {
3046 /* Common symbols must have scope SS_UNSAT and type
3047 ST_STORAGE or the linker will choke. */
3048 if (bfd_syms[i]->section == &bfd_com_section)
3049 {
3050 som_symtab[i].symbol_scope = SS_UNSAT;
3051 som_symtab[i].symbol_type = ST_STORAGE;
3052 }
3053
3054 /* It is possible to have a symbol without an associated
3055 type. This happens if the user imported the symbol
3056 without a type and the symbol was never defined
3057 locally. If BSF_FUNCTION is set for this symbol, then
3058 assign it type ST_CODE (the HP linker requires undefined
3059 external functions to have type ST_CODE rather than ST_ENTRY. */
3060 else if (((*som_symbol_data (bfd_syms[i]))->som_type
3061 == SYMBOL_TYPE_UNKNOWN)
3062 && (bfd_syms[i]->section == &bfd_und_section)
3063 && (bfd_syms[i]->flags & BSF_FUNCTION))
3064 som_symtab[i].symbol_type = ST_CODE;
3065
3066 /* Handle function symbols which were defined in this file.
3067 They should have type ST_ENTRY. Also retrieve the argument
3068 relocation bits from the SOM backend information. */
3069 else if (((*som_symbol_data (bfd_syms[i]))->som_type
3070 == SYMBOL_TYPE_ENTRY)
3071 || (((*som_symbol_data (bfd_syms[i]))->som_type
3072 == SYMBOL_TYPE_CODE)
3073 && (bfd_syms[i]->flags & BSF_FUNCTION))
3074 || (((*som_symbol_data (bfd_syms[i]))->som_type
3075 == SYMBOL_TYPE_UNKNOWN)
3076 && (bfd_syms[i]->flags & BSF_FUNCTION)))
3077 {
3078 som_symtab[i].symbol_type = ST_ENTRY;
3079 som_symtab[i].arg_reloc
3080 = (*som_symbol_data (bfd_syms[i]))->tc_data.hppa_arg_reloc;
3081 }
3082
3083 /* If the type is unknown at this point, it should be
3084 ST_DATA (functions were handled as special cases above). */
3085 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3086 == SYMBOL_TYPE_UNKNOWN)
3087 som_symtab[i].symbol_type = ST_DATA;
3088
3089 /* From now on it's a very simple mapping. */
3090 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3091 == SYMBOL_TYPE_ABSOLUTE)
3092 som_symtab[i].symbol_type = ST_ABSOLUTE;
3093 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3094 == SYMBOL_TYPE_CODE)
3095 som_symtab[i].symbol_type = ST_CODE;
3096 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3097 == SYMBOL_TYPE_DATA)
3098 som_symtab[i].symbol_type = ST_DATA;
3099 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3100 == SYMBOL_TYPE_MILLICODE)
3101 som_symtab[i].symbol_type = ST_MILLICODE;
3102 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3103 == SYMBOL_TYPE_PLABEL)
3104 som_symtab[i].symbol_type = ST_PLABEL;
3105 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3106 == SYMBOL_TYPE_PRI_PROG)
3107 som_symtab[i].symbol_type = ST_PRI_PROG;
3108 else if ((*som_symbol_data (bfd_syms[i]))->som_type
3109 == SYMBOL_TYPE_SEC_PROG)
3110 som_symtab[i].symbol_type = ST_SEC_PROG;
3111 }
3112
3113 /* Now handle the symbol's scope. Exported data which is not
3114 in the common section has scope SS_UNIVERSAL. Note scope
3115 of common symbols was handled earlier! */
3116 if (bfd_syms[i]->flags & BSF_EXPORT
3117 && bfd_syms[i]->section != &bfd_com_section)
3118 som_symtab[i].symbol_scope = SS_UNIVERSAL;
3119 /* Any undefined symbol at this point has a scope SS_UNSAT. */
3120 else if (bfd_syms[i]->section == &bfd_und_section)
3121 som_symtab[i].symbol_scope = SS_UNSAT;
3122 /* Anything else which is not in the common section has scope
3123 SS_LOCAL. */
3124 else if (bfd_syms[i]->section != &bfd_com_section)
3125 som_symtab[i].symbol_scope = SS_LOCAL;
3126
3127 /* Now set the symbol_info field. It has no real meaning
3128 for undefined or common symbols, but the HP linker will
3129 choke if it's not set to some "reasonable" value. We
3130 use zero as a reasonable value. */
3131 if (bfd_syms[i]->section == &bfd_com_section
3132 || bfd_syms[i]->section == &bfd_und_section)
3133 som_symtab[i].symbol_info = 0;
3134 /* For all other symbols, the symbol_info field contains the
3135 subspace index of the space this symbol is contained in. */
3136 else
3137 som_symtab[i].symbol_info
3138 = som_section_data (bfd_syms[i]->section)->subspace_index;
3139
3140 /* Set the symbol's value. */
3141 som_symtab[i].symbol_value
3142 = bfd_syms[i]->value + bfd_syms[i]->section->vma;
3143 }
3144
3145 /* Egad. Everything is ready, seek to the right location and
3146 scribble out the symbol table. */
3147 if (bfd_seek (abfd, symtab_location, SEEK_SET) != 0)
3148 {
3149 bfd_error = system_call_error;
3150 return false;
3151 }
3152
3153 if (bfd_write ((PTR) som_symtab, symtab_size, 1, abfd) != symtab_size)
3154 {
3155 bfd_error = system_call_error;
3156 return false;
3157 }
3158 return true;
3159 }
3160
3161 /* Write an object in SOM format. */
3162
3163 static boolean
3164 som_write_object_contents (abfd)
3165 bfd *abfd;
3166 {
3167 if (abfd->output_has_begun == false)
3168 {
3169 /* Set up fixed parts of the file, space, and subspace headers.
3170 Notify the world that output has begun. */
3171 som_prep_headers (abfd);
3172 abfd->output_has_begun = true;
3173 /* Start writing the object file. This include all the string
3174 tables, fixup streams, and other portions of the object file. */
3175 som_begin_writing (abfd);
3176 }
3177
3178 /* Now that the symbol table information is complete, build and
3179 write the symbol table. */
3180 if (som_build_and_write_symbol_table (abfd) == false)
3181 return false;
3182
3183 /* Compute the checksum for the file header just before writing
3184 the header to disk. */
3185 obj_som_file_hdr (abfd)->checksum = som_compute_checksum (abfd);
3186 return (som_write_headers (abfd));
3187 }
3188
3189 \f
3190 /* Read and save the string table associated with the given BFD. */
3191
3192 static boolean
3193 som_slurp_string_table (abfd)
3194 bfd *abfd;
3195 {
3196 char *stringtab;
3197
3198 /* Use the saved version if its available. */
3199 if (obj_som_stringtab (abfd) != NULL)
3200 return true;
3201
3202 /* Allocate and read in the string table. */
3203 stringtab = bfd_zalloc (abfd, obj_som_stringtab_size (abfd));
3204 if (stringtab == NULL)
3205 {
3206 bfd_error = no_memory;
3207 return false;
3208 }
3209
3210 if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) < 0)
3211 {
3212 bfd_error = system_call_error;
3213 return false;
3214 }
3215
3216 if (bfd_read (stringtab, obj_som_stringtab_size (abfd), 1, abfd)
3217 != obj_som_stringtab_size (abfd))
3218 {
3219 bfd_error = system_call_error;
3220 return false;
3221 }
3222
3223 /* Save our results and return success. */
3224 obj_som_stringtab (abfd) = stringtab;
3225 return true;
3226 }
3227
3228 /* Return the amount of data (in bytes) required to hold the symbol
3229 table for this object. */
3230
3231 static unsigned int
3232 som_get_symtab_upper_bound (abfd)
3233 bfd *abfd;
3234 {
3235 if (!som_slurp_symbol_table (abfd))
3236 return 0;
3237
3238 return (bfd_get_symcount (abfd) + 1) * (sizeof (som_symbol_type *));
3239 }
3240
3241 /* Convert from a SOM subspace index to a BFD section. */
3242
3243 static asection *
3244 som_section_from_subspace_index (abfd, index)
3245 bfd *abfd;
3246 unsigned int index;
3247 {
3248 asection *section;
3249
3250 for (section = abfd->sections; section != NULL; section = section->next)
3251 if (som_section_data (section)->subspace_index == index)
3252 return section;
3253
3254 /* Should never happen. */
3255 abort();
3256 }
3257
3258 /* Read and save the symbol table associated with the given BFD. */
3259
3260 static unsigned int
3261 som_slurp_symbol_table (abfd)
3262 bfd *abfd;
3263 {
3264 int symbol_count = bfd_get_symcount (abfd);
3265 int symsize = sizeof (struct symbol_dictionary_record);
3266 char *stringtab;
3267 struct symbol_dictionary_record *buf, *bufp, *endbufp;
3268 som_symbol_type *sym, *symbase;
3269
3270 /* Return saved value if it exists. */
3271 if (obj_som_symtab (abfd) != NULL)
3272 return true;
3273
3274 /* Sanity checking. Make sure there are some symbols and that
3275 we can read the string table too. */
3276 if (symbol_count == 0)
3277 {
3278 bfd_error = no_symbols;
3279 return false;
3280 }
3281
3282 if (!som_slurp_string_table (abfd))
3283 return false;
3284
3285 stringtab = obj_som_stringtab (abfd);
3286
3287 symbase = (som_symbol_type *)
3288 bfd_zalloc (abfd, symbol_count * sizeof (som_symbol_type));
3289 if (symbase == NULL)
3290 {
3291 bfd_error = no_memory;
3292 return false;
3293 }
3294
3295 /* Read in the external SOM representation. */
3296 buf = alloca (symbol_count * symsize);
3297 if (buf == NULL)
3298 {
3299 bfd_error = no_memory;
3300 return false;
3301 }
3302 if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) < 0)
3303 {
3304 bfd_error = system_call_error;
3305 return false;
3306 }
3307 if (bfd_read (buf, symbol_count * symsize, 1, abfd)
3308 != symbol_count * symsize)
3309 {
3310 bfd_error = no_symbols;
3311 return (false);
3312 }
3313
3314 /* Iterate over all the symbols and internalize them. */
3315 endbufp = buf + symbol_count;
3316 for (bufp = buf, sym = symbase; bufp < endbufp; ++bufp)
3317 {
3318
3319 /* I don't think we care about these. */
3320 if (bufp->symbol_type == ST_SYM_EXT
3321 || bufp->symbol_type == ST_ARG_EXT)
3322 continue;
3323
3324 /* Some reasonable defaults. */
3325 sym->symbol.the_bfd = abfd;
3326 sym->symbol.name = bufp->name.n_strx + stringtab;
3327 sym->symbol.value = bufp->symbol_value;
3328 sym->symbol.section = 0;
3329 sym->symbol.flags = 0;
3330
3331 switch (bufp->symbol_type)
3332 {
3333 case ST_ENTRY:
3334 case ST_PRI_PROG:
3335 case ST_SEC_PROG:
3336 case ST_MILLICODE:
3337 sym->symbol.flags |= BSF_FUNCTION;
3338 sym->symbol.value &= ~0x3;
3339 break;
3340
3341 case ST_STUB:
3342 case ST_CODE:
3343 sym->symbol.value &= ~0x3;
3344
3345 default:
3346 break;
3347 }
3348
3349 /* Handle scoping and section information. */
3350 switch (bufp->symbol_scope)
3351 {
3352 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
3353 so the section associated with this symbol can't be known. */
3354 case SS_EXTERNAL:
3355 case SS_UNSAT:
3356 if (bufp->symbol_type != ST_STORAGE)
3357 sym->symbol.section = &bfd_und_section;
3358 else
3359 sym->symbol.section = &bfd_com_section;
3360 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
3361 break;
3362
3363 case SS_UNIVERSAL:
3364 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
3365 sym->symbol.section
3366 = som_section_from_subspace_index (abfd, bufp->symbol_info);
3367 sym->symbol.value -= sym->symbol.section->vma;
3368 break;
3369
3370 #if 0
3371 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
3372 Sound dumb? It is. */
3373 case SS_GLOBAL:
3374 #endif
3375 case SS_LOCAL:
3376 sym->symbol.flags |= BSF_LOCAL;
3377 sym->symbol.section
3378 = som_section_from_subspace_index (abfd, bufp->symbol_info);
3379 sym->symbol.value -= sym->symbol.section->vma;
3380 break;
3381 }
3382
3383 /* Mark symbols left around by the debugger. */
3384 if (strlen (sym->symbol.name) >= 2
3385 && sym->symbol.name[0] == 'L'
3386 && (sym->symbol.name[1] == '$' || sym->symbol.name[2] == '$'
3387 || sym->symbol.name[3] == '$'))
3388 sym->symbol.flags |= BSF_DEBUGGING;
3389
3390 /* Note increment at bottom of loop, since we skip some symbols
3391 we can not include it as part of the for statement. */
3392 sym++;
3393 }
3394
3395 /* Save our results and return success. */
3396 obj_som_symtab (abfd) = symbase;
3397 return (true);
3398 }
3399
3400 /* Canonicalize a SOM symbol table. Return the number of entries
3401 in the symbol table. */
3402
3403 static unsigned int
3404 som_get_symtab (abfd, location)
3405 bfd *abfd;
3406 asymbol **location;
3407 {
3408 int i;
3409 som_symbol_type *symbase;
3410
3411 if (!som_slurp_symbol_table (abfd))
3412 return 0;
3413
3414 i = bfd_get_symcount (abfd);
3415 symbase = obj_som_symtab (abfd);
3416
3417 for (; i > 0; i--, location++, symbase++)
3418 *location = &symbase->symbol;
3419
3420 /* Final null pointer. */
3421 *location = 0;
3422 return (bfd_get_symcount (abfd));
3423 }
3424
3425 /* Make a SOM symbol. There is nothing special to do here. */
3426
3427 static asymbol *
3428 som_make_empty_symbol (abfd)
3429 bfd *abfd;
3430 {
3431 som_symbol_type *new =
3432 (som_symbol_type *) bfd_zalloc (abfd, sizeof (som_symbol_type));
3433 if (new == NULL)
3434 {
3435 bfd_error = no_memory;
3436 return 0;
3437 }
3438 new->symbol.the_bfd = abfd;
3439
3440 return &new->symbol;
3441 }
3442
3443 /* Print symbol information. */
3444
3445 static void
3446 som_print_symbol (ignore_abfd, afile, symbol, how)
3447 bfd *ignore_abfd;
3448 PTR afile;
3449 asymbol *symbol;
3450 bfd_print_symbol_type how;
3451 {
3452 FILE *file = (FILE *) afile;
3453 switch (how)
3454 {
3455 case bfd_print_symbol_name:
3456 fprintf (file, "%s", symbol->name);
3457 break;
3458 case bfd_print_symbol_more:
3459 fprintf (file, "som ");
3460 fprintf_vma (file, symbol->value);
3461 fprintf (file, " %lx", (long) symbol->flags);
3462 break;
3463 case bfd_print_symbol_all:
3464 {
3465 CONST char *section_name;
3466 section_name = symbol->section ? symbol->section->name : "(*none*)";
3467 bfd_print_symbol_vandf ((PTR) file, symbol);
3468 fprintf (file, " %s\t%s", section_name, symbol->name);
3469 break;
3470 }
3471 }
3472 }
3473
3474 /* Count or process variable-length SOM fixup records.
3475
3476 To avoid code duplication we use this code both to compute the number
3477 of relocations requested by a stream, and to internalize the stream.
3478
3479 When computing the number of relocations requested by a stream the
3480 variables rptr, section, and symbols have no meaning.
3481
3482 Return the number of relocations requested by the fixup stream. When
3483 not just counting
3484
3485 This needs at least two or three more passes to get it cleaned up. */
3486
3487 static unsigned int
3488 som_set_reloc_info (fixup, end, internal_relocs, section, symbols, just_count)
3489 unsigned char *fixup;
3490 unsigned int end;
3491 arelent *internal_relocs;
3492 asection *section;
3493 asymbol **symbols;
3494 boolean just_count;
3495 {
3496 unsigned int op, varname;
3497 unsigned char *end_fixups = &fixup[end];
3498 const struct fixup_format *fp;
3499 char *cp;
3500 unsigned char *save_fixup;
3501 int variables[26], stack[20], c, v, count, prev_fixup, *sp;
3502 const int *subop;
3503 arelent *rptr= internal_relocs;
3504 unsigned int offset = just_count ? 0 : section->vma;
3505
3506 #define var(c) variables[(c) - 'A']
3507 #define push(v) (*sp++ = (v))
3508 #define pop() (*--sp)
3509 #define emptystack() (sp == stack)
3510
3511 som_initialize_reloc_queue (reloc_queue);
3512 bzero (variables, sizeof (variables));
3513 bzero (stack, sizeof (stack));
3514 count = 0;
3515 prev_fixup = 0;
3516 sp = stack;
3517
3518 while (fixup < end_fixups)
3519 {
3520
3521 /* Save pointer to the start of this fixup. We'll use
3522 it later to determine if it is necessary to put this fixup
3523 on the queue. */
3524 save_fixup = fixup;
3525
3526 /* Get the fixup code and its associated format. */
3527 op = *fixup++;
3528 fp = &som_fixup_formats[op];
3529
3530 /* Handle a request for a previous fixup. */
3531 if (*fp->format == 'P')
3532 {
3533 /* Get pointer to the beginning of the prev fixup, move
3534 the repeated fixup to the head of the queue. */
3535 fixup = reloc_queue[fp->D].reloc;
3536 som_reloc_queue_fix (reloc_queue, fp->D);
3537 prev_fixup = 1;
3538
3539 /* Get the fixup code and its associated format. */
3540 op = *fixup++;
3541 fp = &som_fixup_formats[op];
3542 }
3543
3544 /* If we are not just counting, set some reasonable defaults. */
3545 if (! just_count)
3546 {
3547 rptr->address = offset;
3548 rptr->howto = &som_hppa_howto_table[op];
3549 rptr->addend = 0;
3550 }
3551
3552 /* Set default input length to 0. Get the opcode class index
3553 into D. */
3554 var ('L') = 0;
3555 var ('D') = fp->D;
3556
3557 /* Get the opcode format. */
3558 cp = fp->format;
3559
3560 /* Process the format string. Parsing happens in two phases,
3561 parse RHS, then assign to LHS. Repeat until no more
3562 characters in the format string. */
3563 while (*cp)
3564 {
3565 /* The variable this pass is going to compute a value for. */
3566 varname = *cp++;
3567
3568 /* Start processing RHS. Continue until a NULL or '=' is found. */
3569 do
3570 {
3571 c = *cp++;
3572
3573 /* If this is a variable, push it on the stack. */
3574 if (isupper (c))
3575 push (var (c));
3576
3577 /* If this is a lower case letter, then it represents
3578 additional data from the fixup stream to be pushed onto
3579 the stack. */
3580 else if (islower (c))
3581 {
3582 for (v = 0; c > 'a'; --c)
3583 v = (v << 8) | *fixup++;
3584 push (v);
3585 }
3586
3587 /* A decimal constant. Push it on the stack. */
3588 else if (isdigit (c))
3589 {
3590 v = c - '0';
3591 while (isdigit (*cp))
3592 v = (v * 10) + (*cp++ - '0');
3593 push (v);
3594 }
3595 else
3596
3597 /* An operator. Pop two two values from the stack and
3598 use them as operands to the given operation. Push
3599 the result of the operation back on the stack. */
3600 switch (c)
3601 {
3602 case '+':
3603 v = pop ();
3604 v += pop ();
3605 push (v);
3606 break;
3607 case '*':
3608 v = pop ();
3609 v *= pop ();
3610 push (v);
3611 break;
3612 case '<':
3613 v = pop ();
3614 v = pop () << v;
3615 push (v);
3616 break;
3617 default:
3618 abort ();
3619 }
3620 }
3621 while (*cp && *cp != '=');
3622
3623 /* Move over the equal operator. */
3624 cp++;
3625
3626 /* Pop the RHS off the stack. */
3627 c = pop ();
3628
3629 /* Perform the assignment. */
3630 var (varname) = c;
3631
3632 /* Handle side effects. and special 'O' stack cases. */
3633 switch (varname)
3634 {
3635 /* Consume some bytes from the input space. */
3636 case 'L':
3637 offset += c;
3638 break;
3639 /* A symbol to use in the relocation. Make a note
3640 of this if we are not just counting. */
3641 case 'S':
3642 if (! just_count)
3643 rptr->sym_ptr_ptr = &symbols[c];
3644 break;
3645 /* Handle the linker expression stack. */
3646 case 'O':
3647 switch (op)
3648 {
3649 case R_COMP1:
3650 subop = comp1_opcodes;
3651 break;
3652 case R_COMP2:
3653 subop = comp2_opcodes;
3654 break;
3655 case R_COMP3:
3656 subop = comp3_opcodes;
3657 break;
3658 default:
3659 abort ();
3660 }
3661 while (*subop <= (unsigned char) c)
3662 ++subop;
3663 --subop;
3664 break;
3665 default:
3666 break;
3667 }
3668 }
3669
3670 /* If we used a previous fixup, clean up after it. */
3671 if (prev_fixup)
3672 {
3673 fixup = save_fixup + 1;
3674 prev_fixup = 0;
3675 }
3676 /* Queue it. */
3677 else if (fixup > save_fixup + 1)
3678 som_reloc_queue_insert (save_fixup, fixup - save_fixup, reloc_queue);
3679
3680 /* We do not pass R_DATA_OVERRIDE or R_NO_RELOCATION
3681 fixups to BFD. */
3682 if (som_hppa_howto_table[op].type != R_DATA_OVERRIDE
3683 && som_hppa_howto_table[op].type != R_NO_RELOCATION)
3684 {
3685 /* Done with a single reloction. Loop back to the top. */
3686 if (! just_count)
3687 {
3688 rptr->addend = var ('V');
3689 rptr++;
3690 }
3691 count++;
3692 /* Now that we've handled a "full" relocation, reset
3693 some state. */
3694 bzero (variables, sizeof (variables));
3695 bzero (stack, sizeof (stack));
3696 }
3697 }
3698 return count;
3699
3700 #undef var
3701 #undef push
3702 #undef pop
3703 #undef emptystack
3704 }
3705
3706 /* Read in the relocs (aka fixups in SOM terms) for a section.
3707
3708 som_get_reloc_upper_bound calls this routine with JUST_COUNT
3709 set to true to indicate it only needs a count of the number
3710 of actual relocations. */
3711
3712 static boolean
3713 som_slurp_reloc_table (abfd, section, symbols, just_count)
3714 bfd *abfd;
3715 asection *section;
3716 asymbol **symbols;
3717 boolean just_count;
3718 {
3719 char *external_relocs;
3720 unsigned int fixup_stream_size;
3721 arelent *internal_relocs;
3722 unsigned int num_relocs;
3723
3724 fixup_stream_size = som_section_data (section)->reloc_size;
3725 /* If there were no relocations, then there is nothing to do. */
3726 if (section->reloc_count == 0)
3727 return true;
3728
3729 /* If reloc_count is -1, then the relocation stream has not been
3730 parsed. We must do so now to know how many relocations exist. */
3731 if (section->reloc_count == -1)
3732 {
3733 external_relocs = (char *) bfd_zalloc (abfd, fixup_stream_size);
3734 if (external_relocs == (char *) NULL)
3735 {
3736 bfd_error = no_memory;
3737 return false;
3738 }
3739 /* Read in the external forms. */
3740 if (bfd_seek (abfd,
3741 obj_som_reloc_filepos (abfd) + section->rel_filepos,
3742 SEEK_SET)
3743 != 0)
3744 {
3745 bfd_error = system_call_error;
3746 return false;
3747 }
3748 if (bfd_read (external_relocs, 1, fixup_stream_size, abfd)
3749 != fixup_stream_size)
3750 {
3751 bfd_error = system_call_error;
3752 return false;
3753 }
3754 /* Let callers know how many relocations found.
3755 also save the relocation stream as we will
3756 need it again. */
3757 section->reloc_count = som_set_reloc_info (external_relocs,
3758 fixup_stream_size,
3759 NULL, NULL, NULL, true);
3760
3761 som_section_data (section)->reloc_stream = external_relocs;
3762 }
3763
3764 /* If the caller only wanted a count, then return now. */
3765 if (just_count)
3766 return true;
3767
3768 num_relocs = section->reloc_count;
3769 external_relocs = som_section_data (section)->reloc_stream;
3770 /* Return saved information about the relocations if it is available. */
3771 if (section->relocation != (arelent *) NULL)
3772 return true;
3773
3774 internal_relocs = (arelent *) bfd_zalloc (abfd,
3775 num_relocs * sizeof (arelent));
3776 if (internal_relocs == (arelent *) NULL)
3777 {
3778 bfd_error = no_memory;
3779 return false;
3780 }
3781
3782 /* Process and internalize the relocations. */
3783 som_set_reloc_info (external_relocs, fixup_stream_size,
3784 internal_relocs, section, symbols, false);
3785
3786 /* Save our results and return success. */
3787 section->relocation = internal_relocs;
3788 return (true);
3789 }
3790
3791 /* Return the number of bytes required to store the relocation
3792 information associated with the given section. */
3793
3794 static unsigned int
3795 som_get_reloc_upper_bound (abfd, asect)
3796 bfd *abfd;
3797 sec_ptr asect;
3798 {
3799 /* If section has relocations, then read in the relocation stream
3800 and parse it to determine how many relocations exist. */
3801 if (asect->flags & SEC_RELOC)
3802 {
3803 if (som_slurp_reloc_table (abfd, asect, NULL, true))
3804 return (asect->reloc_count + 1) * sizeof (arelent);
3805 }
3806 /* Either there are no relocations or an error occurred while
3807 reading and parsing the relocation stream. */
3808 return 0;
3809 }
3810
3811 /* Convert relocations from SOM (external) form into BFD internal
3812 form. Return the number of relocations. */
3813
3814 static unsigned int
3815 som_canonicalize_reloc (abfd, section, relptr, symbols)
3816 bfd *abfd;
3817 sec_ptr section;
3818 arelent **relptr;
3819 asymbol **symbols;
3820 {
3821 arelent *tblptr;
3822 int count;
3823
3824 if (som_slurp_reloc_table (abfd, section, symbols, false) == false)
3825 return 0;
3826
3827 count = section->reloc_count;
3828 tblptr = section->relocation;
3829 if (tblptr == (arelent *) NULL)
3830 return 0;
3831
3832 while (count--)
3833 *relptr++ = tblptr++;
3834
3835 *relptr = (arelent *) NULL;
3836 return section->reloc_count;
3837 }
3838
3839 extern bfd_target som_vec;
3840
3841 /* A hook to set up object file dependent section information. */
3842
3843 static boolean
3844 som_new_section_hook (abfd, newsect)
3845 bfd *abfd;
3846 asection *newsect;
3847 {
3848 newsect->used_by_bfd = (struct som_section_data_struct *)
3849 bfd_zalloc (abfd, sizeof (struct som_section_data_struct));
3850 newsect->alignment_power = 3;
3851
3852 /* Initialize the subspace_index field to -1 so that it does
3853 not match a subspace with an index of 0. */
3854 som_section_data (newsect)->subspace_index = -1;
3855
3856 /* We allow more than three sections internally */
3857 return true;
3858 }
3859
3860 /* Set backend info for sections which can not be described
3861 in the BFD data structures. */
3862
3863 void
3864 bfd_som_set_section_attributes (section, defined, private, sort_key, spnum)
3865 asection *section;
3866 char defined;
3867 char private;
3868 unsigned char sort_key;
3869 int spnum;
3870 {
3871 struct space_dictionary_record *space_dict;
3872
3873 som_section_data (section)->is_space = 1;
3874 space_dict = &som_section_data (section)->space_dict;
3875 space_dict->is_defined = defined;
3876 space_dict->is_private = private;
3877 space_dict->sort_key = sort_key;
3878 space_dict->space_number = spnum;
3879 }
3880
3881 /* Set backend info for subsections which can not be described
3882 in the BFD data structures. */
3883
3884 void
3885 bfd_som_set_subsection_attributes (section, container, access,
3886 sort_key, quadrant)
3887 asection *section;
3888 asection *container;
3889 int access;
3890 unsigned char sort_key;
3891 int quadrant;
3892 {
3893 struct subspace_dictionary_record *subspace_dict;
3894 som_section_data (section)->is_subspace = 1;
3895 subspace_dict = &som_section_data (section)->subspace_dict;
3896 subspace_dict->access_control_bits = access;
3897 subspace_dict->sort_key = sort_key;
3898 subspace_dict->quadrant = quadrant;
3899 som_section_data (section)->containing_space = container;
3900 }
3901
3902 /* Set the full SOM symbol type. SOM needs far more symbol information
3903 than any other object file format I'm aware of. It is mandatory
3904 to be able to know if a symbol is an entry point, millicode, data,
3905 code, absolute, storage request, or procedure label. If you get
3906 the symbol type wrong your program will not link. */
3907
3908 void
3909 bfd_som_set_symbol_type (symbol, type)
3910 asymbol *symbol;
3911 unsigned int type;
3912 {
3913 (*som_symbol_data (symbol))->som_type = type;
3914 }
3915
3916 /* Attach 64bits of unwind information to a symbol (which hopefully
3917 is a function of some kind!). It would be better to keep this
3918 in the R_ENTRY relocation, but there is not enough space. */
3919
3920 void
3921 bfd_som_attach_unwind_info (symbol, unwind_desc)
3922 asymbol *symbol;
3923 char *unwind_desc;
3924 {
3925 (*som_symbol_data (symbol))->unwind = unwind_desc;
3926 }
3927
3928 /* Attach an auxiliary header to the BFD backend so that it may be
3929 written into the object file. */
3930 void
3931 bfd_som_attach_aux_hdr (abfd, type, string)
3932 bfd *abfd;
3933 int type;
3934 char *string;
3935 {
3936 if (type == VERSION_AUX_ID)
3937 {
3938 int len = strlen (string);
3939
3940 if (len % 4)
3941 len += (4 - (len % 4));
3942 obj_som_version_hdr (abfd)
3943 = bfd_zalloc (abfd,
3944 sizeof (struct aux_id) + sizeof (unsigned int) + len);
3945 obj_som_version_hdr (abfd)->header_id.type = VERSION_AUX_ID;
3946 obj_som_version_hdr (abfd)->header_id.length
3947 = sizeof (struct aux_id) + sizeof (unsigned int) + len;
3948 obj_som_version_hdr (abfd)->string_length = len;
3949 strcpy (obj_som_version_hdr (abfd)->user_string, string);
3950 }
3951 else if (type == COPYRIGHT_AUX_ID)
3952 {
3953 int len = strlen (string);
3954
3955 if (len % 4)
3956 len += (4 - (len % 4));
3957 obj_som_copyright_hdr (abfd)
3958 = bfd_zalloc (abfd,
3959 sizeof (struct aux_id) + sizeof (unsigned int) + len);
3960 obj_som_copyright_hdr (abfd)->header_id.type = COPYRIGHT_AUX_ID;
3961 obj_som_version_hdr (abfd)->header_id.length
3962 = sizeof (struct aux_id) + sizeof (unsigned int) + len;
3963 obj_som_copyright_hdr (abfd)->string_length = len;
3964 strcpy (obj_som_copyright_hdr (abfd)->copyright, string);
3965 }
3966 else
3967 abort ();
3968 }
3969
3970 static boolean
3971 som_set_section_contents (abfd, section, location, offset, count)
3972 bfd *abfd;
3973 sec_ptr section;
3974 PTR location;
3975 file_ptr offset;
3976 bfd_size_type count;
3977 {
3978 if (abfd->output_has_begun == false)
3979 {
3980 /* Set up fixed parts of the file, space, and subspace headers.
3981 Notify the world that output has begun. */
3982 som_prep_headers (abfd);
3983 abfd->output_has_begun = true;
3984 /* Start writing the object file. This include all the string
3985 tables, fixup streams, and other portions of the object file. */
3986 som_begin_writing (abfd);
3987 }
3988
3989 /* Only write subspaces which have "real" contents (eg. the contents
3990 are not generated at run time by the OS). */
3991 if (som_section_data (section)->is_subspace != 1
3992 || ((section->flags & (SEC_LOAD | SEC_DEBUGGING)) == 0))
3993 return true;
3994
3995 /* Seek to the proper offset within the object file and write the
3996 data. */
3997 offset += som_section_data (section)->subspace_dict.file_loc_init_value;
3998 if (bfd_seek (abfd, offset, SEEK_SET) == -1)
3999 {
4000 bfd_error = system_call_error;
4001 return false;
4002 }
4003
4004 if (bfd_write ((PTR) location, 1, count, abfd) != count)
4005 {
4006 bfd_error = system_call_error;
4007 return false;
4008 }
4009 return true;
4010 }
4011
4012 static boolean
4013 som_set_arch_mach (abfd, arch, machine)
4014 bfd *abfd;
4015 enum bfd_architecture arch;
4016 unsigned long machine;
4017 {
4018 /* Allow any architecture to be supported by the SOM backend */
4019 return bfd_default_set_arch_mach (abfd, arch, machine);
4020 }
4021
4022 static boolean
4023 som_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
4024 functionname_ptr, line_ptr)
4025 bfd *abfd;
4026 asection *section;
4027 asymbol **symbols;
4028 bfd_vma offset;
4029 CONST char **filename_ptr;
4030 CONST char **functionname_ptr;
4031 unsigned int *line_ptr;
4032 {
4033 fprintf (stderr, "som_find_nearest_line unimplemented\n");
4034 fflush (stderr);
4035 abort ();
4036 return (false);
4037 }
4038
4039 static int
4040 som_sizeof_headers (abfd, reloc)
4041 bfd *abfd;
4042 boolean reloc;
4043 {
4044 fprintf (stderr, "som_sizeof_headers unimplemented\n");
4045 fflush (stderr);
4046 abort ();
4047 return (0);
4048 }
4049
4050 /* Return the single-character symbol type corresponding to
4051 SOM section S, or '?' for an unknown SOM section. */
4052
4053 static char
4054 som_section_type (s)
4055 const char *s;
4056 {
4057 const struct section_to_type *t;
4058
4059 for (t = &stt[0]; t->section; t++)
4060 if (!strcmp (s, t->section))
4061 return t->type;
4062 return '?';
4063 }
4064
4065 static int
4066 som_decode_symclass (symbol)
4067 asymbol *symbol;
4068 {
4069 char c;
4070
4071 if (bfd_is_com_section (symbol->section))
4072 return 'C';
4073 if (symbol->section == &bfd_und_section)
4074 return 'U';
4075 if (symbol->section == &bfd_ind_section)
4076 return 'I';
4077 if (!(symbol->flags & (BSF_GLOBAL|BSF_LOCAL)))
4078 return '?';
4079
4080 if (symbol->section == &bfd_abs_section)
4081 c = 'a';
4082 else if (symbol->section)
4083 c = som_section_type (symbol->section->name);
4084 else
4085 return '?';
4086 if (symbol->flags & BSF_GLOBAL)
4087 c = toupper (c);
4088 return c;
4089 }
4090
4091 /* Return information about SOM symbol SYMBOL in RET. */
4092
4093 static void
4094 som_get_symbol_info (ignore_abfd, symbol, ret)
4095 bfd *ignore_abfd;
4096 asymbol *symbol;
4097 symbol_info *ret;
4098 {
4099 ret->type = som_decode_symclass (symbol);
4100 if (ret->type != 'U')
4101 ret->value = symbol->value+symbol->section->vma;
4102 else
4103 ret->value = 0;
4104 ret->name = symbol->name;
4105 }
4106
4107 /* End of miscellaneous support functions. */
4108
4109 #define som_bfd_debug_info_start bfd_void
4110 #define som_bfd_debug_info_end bfd_void
4111 #define som_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
4112
4113 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
4114 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
4115 #define som_slurp_armap bfd_false
4116 #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
4117 #define som_truncate_arname (void (*)())bfd_nullvoidptr
4118 #define som_write_armap 0
4119
4120 #define som_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
4121 #define som_close_and_cleanup bfd_generic_close_and_cleanup
4122 #define som_get_section_contents bfd_generic_get_section_contents
4123
4124 #define som_bfd_get_relocated_section_contents \
4125 bfd_generic_get_relocated_section_contents
4126 #define som_bfd_relax_section bfd_generic_relax_section
4127 #define som_bfd_seclet_link bfd_generic_seclet_link
4128 #define som_bfd_make_debug_symbol \
4129 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
4130
4131 /* Core file support is in the hpux-core backend. */
4132 #define som_core_file_failing_command _bfd_dummy_core_file_failing_command
4133 #define som_core_file_failing_signal _bfd_dummy_core_file_failing_signal
4134 #define som_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
4135
4136 bfd_target som_vec =
4137 {
4138 "som", /* name */
4139 bfd_target_som_flavour,
4140 true, /* target byte order */
4141 true, /* target headers byte order */
4142 (HAS_RELOC | EXEC_P | /* object flags */
4143 HAS_LINENO | HAS_DEBUG |
4144 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
4145 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
4146 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
4147
4148 /* leading_symbol_char: is the first char of a user symbol
4149 predictable, and if so what is it */
4150 0,
4151 ' ', /* ar_pad_char */
4152 16, /* ar_max_namelen */
4153 3, /* minimum alignment */
4154 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
4155 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
4156 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
4157 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
4158 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
4159 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
4160 {_bfd_dummy_target,
4161 som_object_p, /* bfd_check_format */
4162 bfd_generic_archive_p,
4163 _bfd_dummy_target
4164 },
4165 {
4166 bfd_false,
4167 som_mkobject,
4168 _bfd_generic_mkarchive,
4169 bfd_false
4170 },
4171 {
4172 bfd_false,
4173 som_write_object_contents,
4174 _bfd_write_archive_contents,
4175 bfd_false,
4176 },
4177 #undef som
4178 JUMP_TABLE (som),
4179 (PTR) 0
4180 };
4181
4182 #endif /* HOST_HPPAHPUX || HOST_HPPABSD */
This page took 0.178923 seconds and 5 git commands to generate.