1 /* bfd back-end for HP PA-RISC SOM objects.
2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 Contributed by the Center for Software Science at the
5 University of Utah (pa-gdb-bugs@cs.utah.edu).
7 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
26 #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF)
32 #include <sys/types.h>
33 #include <sys/param.h>
36 #include <machine/reg.h>
37 #include <sys/user.h> /* After a.out.h */
41 /* Magic not defined in standard HP-UX header files until 8.0 */
43 #ifndef CPU_PA_RISC1_0
44 #define CPU_PA_RISC1_0 0x20B
45 #endif /* CPU_PA_RISC1_0 */
47 #ifndef CPU_PA_RISC1_1
48 #define CPU_PA_RISC1_1 0x210
49 #endif /* CPU_PA_RISC1_1 */
51 #ifndef _PA_RISC1_0_ID
52 #define _PA_RISC1_0_ID CPU_PA_RISC1_0
53 #endif /* _PA_RISC1_0_ID */
55 #ifndef _PA_RISC1_1_ID
56 #define _PA_RISC1_1_ID CPU_PA_RISC1_1
57 #endif /* _PA_RISC1_1_ID */
59 #ifndef _PA_RISC_MAXID
60 #define _PA_RISC_MAXID 0x2FF
61 #endif /* _PA_RISC_MAXID */
64 #define _PA_RISC_ID(__m_num) \
65 (((__m_num) == _PA_RISC1_0_ID) || \
66 ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
67 #endif /* _PA_RISC_ID */
69 /* Size (in chars) of the temporary buffers used during fixup and string
72 #define SOM_TMP_BUFSIZE 8192
74 /* Size of the hash table in archives. */
75 #define SOM_LST_HASH_SIZE 31
77 /* Max number of SOMs to be found in an archive. */
78 #define SOM_LST_MODULE_LIMIT 1024
80 /* SOM allows any one of the four previous relocations to be reused
81 with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
82 relocations are always a single byte, using a R_PREV_FIXUP instead
83 of some multi-byte relocation makes object files smaller.
85 Note one side effect of using a R_PREV_FIXUP is the relocation that
86 is being repeated moves to the front of the queue. */
93 /* This fully describes the symbol types which may be attached to
94 an EXPORT or IMPORT directive. Only SOM uses this formation
95 (ELF has no need for it). */
103 SYMBOL_TYPE_MILLICODE
,
105 SYMBOL_TYPE_PRI_PROG
,
106 SYMBOL_TYPE_SEC_PROG
,
109 struct section_to_type
115 /* Assorted symbol information that needs to be derived from the BFD symbol
116 and/or the BFD backend private symbol data. */
117 struct som_misc_symbol_info
119 unsigned int symbol_type
;
120 unsigned int symbol_scope
;
121 unsigned int arg_reloc
;
122 unsigned int symbol_info
;
123 unsigned int symbol_value
;
126 /* Forward declarations */
128 static boolean som_mkobject
PARAMS ((bfd
*));
129 static bfd_target
* som_object_setup
PARAMS ((bfd
*,
131 struct som_exec_auxhdr
*));
132 static asection
* make_unique_section
PARAMS ((bfd
*, CONST
char *, int));
133 static boolean setup_sections
PARAMS ((bfd
*, struct header
*));
134 static bfd_target
* som_object_p
PARAMS ((bfd
*));
135 static boolean som_write_object_contents
PARAMS ((bfd
*));
136 static boolean som_slurp_string_table
PARAMS ((bfd
*));
137 static unsigned int som_slurp_symbol_table
PARAMS ((bfd
*));
138 static unsigned int som_get_symtab_upper_bound
PARAMS ((bfd
*));
139 static unsigned int som_canonicalize_reloc
PARAMS ((bfd
*, sec_ptr
,
140 arelent
**, asymbol
**));
141 static unsigned int som_get_reloc_upper_bound
PARAMS ((bfd
*, sec_ptr
));
142 static unsigned int som_set_reloc_info
PARAMS ((unsigned char *, unsigned int,
143 arelent
*, asection
*,
144 asymbol
**, boolean
));
145 static boolean som_slurp_reloc_table
PARAMS ((bfd
*, asection
*,
146 asymbol
**, boolean
));
147 static unsigned int som_get_symtab
PARAMS ((bfd
*, asymbol
**));
148 static asymbol
* som_make_empty_symbol
PARAMS ((bfd
*));
149 static void som_print_symbol
PARAMS ((bfd
*, PTR
,
150 asymbol
*, bfd_print_symbol_type
));
151 static boolean som_new_section_hook
PARAMS ((bfd
*, asection
*));
152 static boolean som_bfd_copy_private_section_data
PARAMS ((bfd
*, asection
*,
154 static boolean som_bfd_is_local_label
PARAMS ((bfd
*, asymbol
*));
155 static boolean som_set_section_contents
PARAMS ((bfd
*, sec_ptr
, PTR
,
156 file_ptr
, bfd_size_type
));
157 static boolean som_set_arch_mach
PARAMS ((bfd
*, enum bfd_architecture
,
159 static boolean som_find_nearest_line
PARAMS ((bfd
*, asection
*,
164 static void som_get_symbol_info
PARAMS ((bfd
*, asymbol
*, symbol_info
*));
165 static asection
* som_section_from_subspace_index
PARAMS ((bfd
*,
167 static int log2
PARAMS ((unsigned int));
168 static bfd_reloc_status_type hppa_som_reloc
PARAMS ((bfd
*, arelent
*,
172 static void som_initialize_reloc_queue
PARAMS ((struct reloc_queue
*));
173 static void som_reloc_queue_insert
PARAMS ((unsigned char *, unsigned int,
174 struct reloc_queue
*));
175 static void som_reloc_queue_fix
PARAMS ((struct reloc_queue
*, unsigned int));
176 static int som_reloc_queue_find
PARAMS ((unsigned char *, unsigned int,
177 struct reloc_queue
*));
178 static unsigned char * try_prev_fixup
PARAMS ((bfd
*, int *, unsigned char *,
180 struct reloc_queue
*));
182 static unsigned char * som_reloc_skip
PARAMS ((bfd
*, unsigned int,
183 unsigned char *, unsigned int *,
184 struct reloc_queue
*));
185 static unsigned char * som_reloc_addend
PARAMS ((bfd
*, int, unsigned char *,
187 struct reloc_queue
*));
188 static unsigned char * som_reloc_call
PARAMS ((bfd
*, unsigned char *,
191 struct reloc_queue
*));
192 static unsigned long som_count_spaces
PARAMS ((bfd
*));
193 static unsigned long som_count_subspaces
PARAMS ((bfd
*));
194 static int compare_syms
PARAMS ((asymbol
**, asymbol
**));
195 static unsigned long som_compute_checksum
PARAMS ((bfd
*));
196 static boolean som_prep_headers
PARAMS ((bfd
*));
197 static int som_sizeof_headers
PARAMS ((bfd
*, boolean
));
198 static boolean som_write_headers
PARAMS ((bfd
*));
199 static boolean som_build_and_write_symbol_table
PARAMS ((bfd
*));
200 static void som_prep_for_fixups
PARAMS ((bfd
*, asymbol
**, unsigned long));
201 static boolean som_write_fixups
PARAMS ((bfd
*, unsigned long, unsigned int *));
202 static boolean som_write_space_strings
PARAMS ((bfd
*, unsigned long,
204 static boolean som_write_symbol_strings
PARAMS ((bfd
*, unsigned long,
205 asymbol
**, unsigned int,
207 static boolean som_begin_writing
PARAMS ((bfd
*));
208 static const reloc_howto_type
* som_bfd_reloc_type_lookup
209 PARAMS ((bfd_arch_info_type
*, bfd_reloc_code_real_type
));
210 static char som_section_type
PARAMS ((const char *));
211 static int som_decode_symclass
PARAMS ((asymbol
*));
212 static boolean som_bfd_count_ar_symbols
PARAMS ((bfd
*, struct lst_header
*,
215 static boolean som_bfd_fill_in_ar_symbols
PARAMS ((bfd
*, struct lst_header
*,
217 static boolean som_slurp_armap
PARAMS ((bfd
*));
218 static boolean som_write_armap
PARAMS ((bfd
*));
219 static boolean som_slurp_extended_name_table
PARAMS ((bfd
*));
220 static void som_bfd_derive_misc_symbol_info
PARAMS ((bfd
*, asymbol
*,
221 struct som_misc_symbol_info
*));
222 static boolean som_bfd_prep_for_ar_write
PARAMS ((bfd
*, unsigned int *,
224 static unsigned int som_bfd_ar_symbol_hash
PARAMS ((asymbol
*));
225 static boolean som_bfd_ar_write_symbol_stuff
PARAMS ((bfd
*, unsigned int,
229 /* Map SOM section names to POSIX/BSD single-character symbol types.
231 This table includes all the standard subspaces as defined in the
232 current "PRO ABI for PA-RISC Systems", $UNWIND$ which for
233 some reason was left out, and sections specific to embedded stabs. */
235 static const struct section_to_type stt
[] = {
237 {"$SHLIB_INFO$", 't'},
238 {"$MILLICODE$", 't'},
241 {"$UNWIND_START$", 't'},
245 {"$SHLIB_DATA$", 'd'},
247 {"$SHORTDATA$", 'g'},
252 {"$GDB_STRINGS$", 'N'},
253 {"$GDB_SYMBOLS$", 'N'},
257 /* About the relocation formatting table...
259 There are 256 entries in the table, one for each possible
260 relocation opcode available in SOM. We index the table by
261 the relocation opcode. The names and operations are those
262 defined by a.out_800 (4).
264 Right now this table is only used to count and perform minimal
265 processing on relocation streams so that they can be internalized
266 into BFD and symbolically printed by utilities. To make actual use
267 of them would be much more difficult, BFD's concept of relocations
268 is far too simple to handle SOM relocations. The basic assumption
269 that a relocation can be completely processed independent of other
270 relocations before an object file is written is invalid for SOM.
272 The SOM relocations are meant to be processed as a stream, they
273 specify copying of data from the input section to the output section
274 while possibly modifying the data in some manner. They also can
275 specify that a variable number of zeros or uninitialized data be
276 inserted on in the output segment at the current offset. Some
277 relocations specify that some previous relocation be re-applied at
278 the current location in the input/output sections. And finally a number
279 of relocations have effects on other sections (R_ENTRY, R_EXIT,
280 R_UNWIND_AUX and a variety of others). There isn't even enough room
281 in the BFD relocation data structure to store enough information to
282 perform all the relocations.
284 Each entry in the table has three fields.
286 The first entry is an index into this "class" of relocations. This
287 index can then be used as a variable within the relocation itself.
289 The second field is a format string which actually controls processing
290 of the relocation. It uses a simple postfix machine to do calculations
291 based on variables/constants found in the string and the relocation
294 The third field specifys whether or not this relocation may use
295 a constant (V) from the previous R_DATA_OVERRIDE rather than a constant
296 stored in the instruction.
300 L = input space byte count
301 D = index into class of relocations
302 M = output space byte count
303 N = statement number (unused?)
305 R = parameter relocation bits
307 U = 64 bits of stack unwind and frame size info (we only keep 32 bits)
308 V = a literal constant (usually used in the next relocation)
309 P = a previous relocation
311 Lower case letters (starting with 'b') refer to following
312 bytes in the relocation stream. 'b' is the next 1 byte,
313 c is the next 2 bytes, d is the next 3 bytes, etc...
314 This is the variable part of the relocation entries that
315 makes our life a living hell.
317 numerical constants are also used in the format string. Note
318 the constants are represented in decimal.
320 '+', "*" and "=" represents the obvious postfix operators.
321 '<' represents a left shift.
325 Parameter Relocation Bits:
329 Previous Relocations: The index field represents which in the queue
330 of 4 previous fixups should be re-applied.
332 Literal Constants: These are generally used to represent addend
333 parts of relocations when these constants are not stored in the
334 fields of the instructions themselves. For example the instruction
335 addil foo-$global$-0x1234 would use an override for "0x1234" rather
336 than storing it into the addil itself. */
344 static const struct fixup_format som_fixup_formats
[256] =
346 /* R_NO_RELOCATION */
347 0, "LD1+4*=", /* 0x00 */
348 1, "LD1+4*=", /* 0x01 */
349 2, "LD1+4*=", /* 0x02 */
350 3, "LD1+4*=", /* 0x03 */
351 4, "LD1+4*=", /* 0x04 */
352 5, "LD1+4*=", /* 0x05 */
353 6, "LD1+4*=", /* 0x06 */
354 7, "LD1+4*=", /* 0x07 */
355 8, "LD1+4*=", /* 0x08 */
356 9, "LD1+4*=", /* 0x09 */
357 10, "LD1+4*=", /* 0x0a */
358 11, "LD1+4*=", /* 0x0b */
359 12, "LD1+4*=", /* 0x0c */
360 13, "LD1+4*=", /* 0x0d */
361 14, "LD1+4*=", /* 0x0e */
362 15, "LD1+4*=", /* 0x0f */
363 16, "LD1+4*=", /* 0x10 */
364 17, "LD1+4*=", /* 0x11 */
365 18, "LD1+4*=", /* 0x12 */
366 19, "LD1+4*=", /* 0x13 */
367 20, "LD1+4*=", /* 0x14 */
368 21, "LD1+4*=", /* 0x15 */
369 22, "LD1+4*=", /* 0x16 */
370 23, "LD1+4*=", /* 0x17 */
371 0, "LD8<b+1+4*=", /* 0x18 */
372 1, "LD8<b+1+4*=", /* 0x19 */
373 2, "LD8<b+1+4*=", /* 0x1a */
374 3, "LD8<b+1+4*=", /* 0x1b */
375 0, "LD16<c+1+4*=", /* 0x1c */
376 1, "LD16<c+1+4*=", /* 0x1d */
377 2, "LD16<c+1+4*=", /* 0x1e */
378 0, "Ld1+=", /* 0x1f */
380 0, "Lb1+4*=", /* 0x20 */
381 1, "Ld1+=", /* 0x21 */
383 0, "Lb1+4*=", /* 0x22 */
384 1, "Ld1+=", /* 0x23 */
387 /* R_DATA_ONE_SYMBOL */
388 0, "L4=Sb=", /* 0x25 */
389 1, "L4=Sd=", /* 0x26 */
391 0, "L4=Sb=", /* 0x27 */
392 1, "L4=Sd=", /* 0x28 */
395 /* R_REPEATED_INIT */
396 0, "L4=Mb1+4*=", /* 0x2a */
397 1, "Lb4*=Mb1+L*=", /* 0x2b */
398 2, "Lb4*=Md1+4*=", /* 0x2c */
399 3, "Ld1+=Me1+=", /* 0x2d */
404 0, "L4=RD=Sb=", /* 0x30 */
405 1, "L4=RD=Sb=", /* 0x31 */
406 2, "L4=RD=Sb=", /* 0x32 */
407 3, "L4=RD=Sb=", /* 0x33 */
408 4, "L4=RD=Sb=", /* 0x34 */
409 5, "L4=RD=Sb=", /* 0x35 */
410 6, "L4=RD=Sb=", /* 0x36 */
411 7, "L4=RD=Sb=", /* 0x37 */
412 8, "L4=RD=Sb=", /* 0x38 */
413 9, "L4=RD=Sb=", /* 0x39 */
414 0, "L4=RD8<b+=Sb=",/* 0x3a */
415 1, "L4=RD8<b+=Sb=",/* 0x3b */
416 0, "L4=RD8<b+=Sd=",/* 0x3c */
417 1, "L4=RD8<b+=Sd=",/* 0x3d */
422 0, "L4=RD=Sb=", /* 0x40 */
423 1, "L4=RD=Sb=", /* 0x41 */
424 2, "L4=RD=Sb=", /* 0x42 */
425 3, "L4=RD=Sb=", /* 0x43 */
426 4, "L4=RD=Sb=", /* 0x44 */
427 5, "L4=RD=Sb=", /* 0x45 */
428 6, "L4=RD=Sb=", /* 0x46 */
429 7, "L4=RD=Sb=", /* 0x47 */
430 8, "L4=RD=Sb=", /* 0x48 */
431 9, "L4=RD=Sb=", /* 0x49 */
432 0, "L4=RD8<b+=Sb=",/* 0x4a */
433 1, "L4=RD8<b+=Sb=",/* 0x4b */
434 0, "L4=RD8<b+=Sd=",/* 0x4c */
435 1, "L4=RD8<b+=Sd=",/* 0x4d */
440 0, "L4=SD=", /* 0x50 */
441 1, "L4=SD=", /* 0x51 */
442 2, "L4=SD=", /* 0x52 */
443 3, "L4=SD=", /* 0x53 */
444 4, "L4=SD=", /* 0x54 */
445 5, "L4=SD=", /* 0x55 */
446 6, "L4=SD=", /* 0x56 */
447 7, "L4=SD=", /* 0x57 */
448 8, "L4=SD=", /* 0x58 */
449 9, "L4=SD=", /* 0x59 */
450 10, "L4=SD=", /* 0x5a */
451 11, "L4=SD=", /* 0x5b */
452 12, "L4=SD=", /* 0x5c */
453 13, "L4=SD=", /* 0x5d */
454 14, "L4=SD=", /* 0x5e */
455 15, "L4=SD=", /* 0x5f */
456 16, "L4=SD=", /* 0x60 */
457 17, "L4=SD=", /* 0x61 */
458 18, "L4=SD=", /* 0x62 */
459 19, "L4=SD=", /* 0x63 */
460 20, "L4=SD=", /* 0x64 */
461 21, "L4=SD=", /* 0x65 */
462 22, "L4=SD=", /* 0x66 */
463 23, "L4=SD=", /* 0x67 */
464 24, "L4=SD=", /* 0x68 */
465 25, "L4=SD=", /* 0x69 */
466 26, "L4=SD=", /* 0x6a */
467 27, "L4=SD=", /* 0x6b */
468 28, "L4=SD=", /* 0x6c */
469 29, "L4=SD=", /* 0x6d */
470 30, "L4=SD=", /* 0x6e */
471 31, "L4=SD=", /* 0x6f */
472 32, "L4=Sb=", /* 0x70 */
473 33, "L4=Sd=", /* 0x71 */
482 0, "L4=Sb=", /* 0x78 */
483 1, "L4=Sd=", /* 0x79 */
491 /* R_CODE_ONE_SYMBOL */
492 0, "L4=SD=", /* 0x80 */
493 1, "L4=SD=", /* 0x81 */
494 2, "L4=SD=", /* 0x82 */
495 3, "L4=SD=", /* 0x83 */
496 4, "L4=SD=", /* 0x84 */
497 5, "L4=SD=", /* 0x85 */
498 6, "L4=SD=", /* 0x86 */
499 7, "L4=SD=", /* 0x87 */
500 8, "L4=SD=", /* 0x88 */
501 9, "L4=SD=", /* 0x89 */
502 10, "L4=SD=", /* 0x8q */
503 11, "L4=SD=", /* 0x8b */
504 12, "L4=SD=", /* 0x8c */
505 13, "L4=SD=", /* 0x8d */
506 14, "L4=SD=", /* 0x8e */
507 15, "L4=SD=", /* 0x8f */
508 16, "L4=SD=", /* 0x90 */
509 17, "L4=SD=", /* 0x91 */
510 18, "L4=SD=", /* 0x92 */
511 19, "L4=SD=", /* 0x93 */
512 20, "L4=SD=", /* 0x94 */
513 21, "L4=SD=", /* 0x95 */
514 22, "L4=SD=", /* 0x96 */
515 23, "L4=SD=", /* 0x97 */
516 24, "L4=SD=", /* 0x98 */
517 25, "L4=SD=", /* 0x99 */
518 26, "L4=SD=", /* 0x9a */
519 27, "L4=SD=", /* 0x9b */
520 28, "L4=SD=", /* 0x9c */
521 29, "L4=SD=", /* 0x9d */
522 30, "L4=SD=", /* 0x9e */
523 31, "L4=SD=", /* 0x9f */
524 32, "L4=Sb=", /* 0xa0 */
525 33, "L4=Sd=", /* 0xa1 */
540 0, "L4=Sb=", /* 0xae */
541 1, "L4=Sd=", /* 0xaf */
543 0, "L4=Sb=", /* 0xb0 */
544 1, "L4=Sd=", /* 0xb1 */
558 1, "Rb4*=", /* 0xb9 */
559 2, "Rd4*=", /* 0xba */
586 /* R_DATA_OVERRIDE */
599 0, "Ob=Sd=", /* 0xd1 */
601 0, "Ob=Ve=", /* 0xd2 */
651 static const int comp1_opcodes
[] =
673 static const int comp2_opcodes
[] =
682 static const int comp3_opcodes
[] =
689 /* These apparently are not in older versions of hpux reloc.h. */
691 #define R_DLT_REL 0x78
695 #define R_AUX_UNWIND 0xcf
699 #define R_SEC_STMT 0xd7
702 static reloc_howto_type som_hppa_howto_table
[] =
704 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
705 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
706 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
707 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
708 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
709 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
710 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
711 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
712 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
713 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
714 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
715 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
716 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
717 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
718 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
719 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
720 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
721 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
722 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
723 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
724 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
725 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
726 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
727 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
728 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
729 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
730 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
731 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
732 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
733 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
734 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
735 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
736 {R_ZEROES
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ZEROES"},
737 {R_ZEROES
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ZEROES"},
738 {R_UNINIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_UNINIT"},
739 {R_UNINIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_UNINIT"},
740 {R_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RELOCATION"},
741 {R_DATA_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_ONE_SYMBOL"},
742 {R_DATA_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_ONE_SYMBOL"},
743 {R_DATA_PLABEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_PLABEL"},
744 {R_DATA_PLABEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_PLABEL"},
745 {R_SPACE_REF
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_SPACE_REF"},
746 {R_REPEATED_INIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "REPEATED_INIT"},
747 {R_REPEATED_INIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "REPEATED_INIT"},
748 {R_REPEATED_INIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "REPEATED_INIT"},
749 {R_REPEATED_INIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "REPEATED_INIT"},
750 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
751 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
752 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
753 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
754 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
755 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
756 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
757 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
758 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
759 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
760 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
761 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
762 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
763 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
764 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
765 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
766 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
767 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
768 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
769 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
770 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
771 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
772 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
773 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
774 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
775 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
776 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
777 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
778 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
779 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
780 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
781 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
782 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
783 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
784 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
785 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
786 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
787 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
788 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
789 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
790 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
791 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
792 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
793 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
794 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
795 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
796 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
797 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
798 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
799 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
800 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
801 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
802 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
803 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
804 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
805 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
806 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
807 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
808 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
809 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
810 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
811 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
812 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
813 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
814 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
815 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
816 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
817 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
818 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
819 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
820 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
821 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
822 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
823 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
824 {R_DLT_REL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DLT_REL"},
825 {R_DLT_REL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DLT_REL"},
826 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
827 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
828 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
829 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
830 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
831 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
832 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
833 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
834 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
835 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
836 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
837 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
838 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
839 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
840 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
841 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
842 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
843 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
844 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
845 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
846 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
847 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
848 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
849 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
850 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
851 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
852 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
853 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
854 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
855 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
856 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
857 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
858 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
859 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
860 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
861 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
862 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
863 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
864 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
865 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
866 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
867 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
868 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
869 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
870 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
871 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
872 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
873 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
874 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
875 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
876 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
877 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
878 {R_MILLI_REL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_MILLI_REL"},
879 {R_MILLI_REL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_MILLI_REL"},
880 {R_CODE_PLABEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_PLABEL"},
881 {R_CODE_PLABEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_PLABEL"},
882 {R_BREAKPOINT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_BREAKPOINT"},
883 {R_ENTRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ENTRY"},
884 {R_ENTRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ENTRY"},
885 {R_ALT_ENTRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ALT_ENTRY"},
886 {R_EXIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_EXIT"},
887 {R_BEGIN_TRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_BEGIN_TRY"},
888 {R_END_TRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_END_TRY"},
889 {R_END_TRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_END_TRY"},
890 {R_END_TRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_END_TRY"},
891 {R_BEGIN_BRTAB
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_BEGIN_BRTAB"},
892 {R_END_BRTAB
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_END_BRTAB"},
893 {R_STATEMENT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_STATEMENT"},
894 {R_STATEMENT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_STATEMENT"},
895 {R_STATEMENT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_STATEMENT"},
896 {R_DATA_EXPR
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_EXPR"},
897 {R_CODE_EXPR
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_EXPR"},
898 {R_FSEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_FSEL"},
899 {R_LSEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_LSEL"},
900 {R_RSEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RSEL"},
901 {R_N_MODE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_N_MODE"},
902 {R_S_MODE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_S_MODE"},
903 {R_D_MODE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_D_MODE"},
904 {R_R_MODE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_R_MODE"},
905 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
906 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
907 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
908 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
909 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
910 {R_TRANSLATED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_TRANSLATED"},
911 {R_AUX_UNWIND
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_AUX_UNWIND"},
912 {R_COMP1
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_COMP1"},
913 {R_COMP2
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_COMP2"},
914 {R_COMP3
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_COMP3"},
915 {R_PREV_FIXUP
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PREV_FIXUP"},
916 {R_PREV_FIXUP
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PREV_FIXUP"},
917 {R_PREV_FIXUP
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PREV_FIXUP"},
918 {R_PREV_FIXUP
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PREV_FIXUP"},
919 {R_SEC_STMT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_SEC_STMT"},
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 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
927 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
928 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
929 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
930 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
931 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
932 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
933 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
934 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
935 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
936 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
937 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
938 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
939 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
940 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
941 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
942 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
943 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
944 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
945 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
946 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
947 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
948 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
949 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
950 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
951 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
952 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
953 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
954 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
955 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
956 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
957 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
958 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
959 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"}};
962 /* Initialize the SOM relocation queue. By definition the queue holds
963 the last four multibyte fixups. */
966 som_initialize_reloc_queue (queue
)
967 struct reloc_queue
*queue
;
969 queue
[0].reloc
= NULL
;
971 queue
[1].reloc
= NULL
;
973 queue
[2].reloc
= NULL
;
975 queue
[3].reloc
= NULL
;
979 /* Insert a new relocation into the relocation queue. */
982 som_reloc_queue_insert (p
, size
, queue
)
985 struct reloc_queue
*queue
;
987 queue
[3].reloc
= queue
[2].reloc
;
988 queue
[3].size
= queue
[2].size
;
989 queue
[2].reloc
= queue
[1].reloc
;
990 queue
[2].size
= queue
[1].size
;
991 queue
[1].reloc
= queue
[0].reloc
;
992 queue
[1].size
= queue
[0].size
;
994 queue
[0].size
= size
;
997 /* When an entry in the relocation queue is reused, the entry moves
998 to the front of the queue. */
1001 som_reloc_queue_fix (queue
, index
)
1002 struct reloc_queue
*queue
;
1010 unsigned char *tmp1
= queue
[0].reloc
;
1011 unsigned int tmp2
= queue
[0].size
;
1012 queue
[0].reloc
= queue
[1].reloc
;
1013 queue
[0].size
= queue
[1].size
;
1014 queue
[1].reloc
= tmp1
;
1015 queue
[1].size
= tmp2
;
1021 unsigned char *tmp1
= queue
[0].reloc
;
1022 unsigned int tmp2
= queue
[0].size
;
1023 queue
[0].reloc
= queue
[2].reloc
;
1024 queue
[0].size
= queue
[2].size
;
1025 queue
[2].reloc
= queue
[1].reloc
;
1026 queue
[2].size
= queue
[1].size
;
1027 queue
[1].reloc
= tmp1
;
1028 queue
[1].size
= tmp2
;
1034 unsigned char *tmp1
= queue
[0].reloc
;
1035 unsigned int tmp2
= queue
[0].size
;
1036 queue
[0].reloc
= queue
[3].reloc
;
1037 queue
[0].size
= queue
[3].size
;
1038 queue
[3].reloc
= queue
[2].reloc
;
1039 queue
[3].size
= queue
[2].size
;
1040 queue
[2].reloc
= queue
[1].reloc
;
1041 queue
[2].size
= queue
[1].size
;
1042 queue
[1].reloc
= tmp1
;
1043 queue
[1].size
= tmp2
;
1049 /* Search for a particular relocation in the relocation queue. */
1052 som_reloc_queue_find (p
, size
, queue
)
1055 struct reloc_queue
*queue
;
1057 if (queue
[0].reloc
&& !bcmp (p
, queue
[0].reloc
, size
)
1058 && size
== queue
[0].size
)
1060 if (queue
[1].reloc
&& !bcmp (p
, queue
[1].reloc
, size
)
1061 && size
== queue
[1].size
)
1063 if (queue
[2].reloc
&& !bcmp (p
, queue
[2].reloc
, size
)
1064 && size
== queue
[2].size
)
1066 if (queue
[3].reloc
&& !bcmp (p
, queue
[3].reloc
, size
)
1067 && size
== queue
[3].size
)
1072 static unsigned char *
1073 try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, size
, queue
)
1075 int *subspace_reloc_sizep
;
1078 struct reloc_queue
*queue
;
1080 int queue_index
= som_reloc_queue_find (p
, size
, queue
);
1082 if (queue_index
!= -1)
1084 /* Found this in a previous fixup. Undo the fixup we
1085 just built and use R_PREV_FIXUP instead. We saved
1086 a total of size - 1 bytes in the fixup stream. */
1087 bfd_put_8 (abfd
, R_PREV_FIXUP
+ queue_index
, p
);
1089 *subspace_reloc_sizep
+= 1;
1090 som_reloc_queue_fix (queue
, queue_index
);
1094 som_reloc_queue_insert (p
, size
, queue
);
1095 *subspace_reloc_sizep
+= size
;
1101 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
1102 bytes without any relocation. Update the size of the subspace
1103 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
1104 current pointer into the relocation stream. */
1106 static unsigned char *
1107 som_reloc_skip (abfd
, skip
, p
, subspace_reloc_sizep
, queue
)
1111 unsigned int *subspace_reloc_sizep
;
1112 struct reloc_queue
*queue
;
1114 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
1115 then R_PREV_FIXUPs to get the difference down to a
1117 if (skip
>= 0x1000000)
1120 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 31, p
);
1121 bfd_put_8 (abfd
, 0xff, p
+ 1);
1122 bfd_put_16 (abfd
, 0xffff, p
+ 2);
1123 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1124 while (skip
>= 0x1000000)
1127 bfd_put_8 (abfd
, R_PREV_FIXUP
, p
);
1129 *subspace_reloc_sizep
+= 1;
1130 /* No need to adjust queue here since we are repeating the
1131 most recent fixup. */
1135 /* The difference must be less than 0x1000000. Use one
1136 more R_NO_RELOCATION entry to get to the right difference. */
1137 if ((skip
& 3) == 0 && skip
<= 0xc0000 && skip
> 0)
1139 /* Difference can be handled in a simple single-byte
1140 R_NO_RELOCATION entry. */
1143 bfd_put_8 (abfd
, R_NO_RELOCATION
+ (skip
>> 2) - 1, p
);
1144 *subspace_reloc_sizep
+= 1;
1147 /* Handle it with a two byte R_NO_RELOCATION entry. */
1148 else if (skip
<= 0x1000)
1150 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 24 + (((skip
>> 2) - 1) >> 8), p
);
1151 bfd_put_8 (abfd
, (skip
>> 2) - 1, p
+ 1);
1152 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1154 /* Handle it with a three byte R_NO_RELOCATION entry. */
1157 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 28 + (((skip
>> 2) - 1) >> 16), p
);
1158 bfd_put_16 (abfd
, (skip
>> 2) - 1, p
+ 1);
1159 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1162 /* Ugh. Punt and use a 4 byte entry. */
1165 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 31, p
);
1166 bfd_put_8 (abfd
, skip
>> 16, p
+ 1);
1167 bfd_put_16 (abfd
, skip
, p
+ 2);
1168 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1173 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
1174 from a BFD relocation. Update the size of the subspace relocation
1175 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
1176 into the relocation stream. */
1178 static unsigned char *
1179 som_reloc_addend (abfd
, addend
, p
, subspace_reloc_sizep
, queue
)
1183 unsigned int *subspace_reloc_sizep
;
1184 struct reloc_queue
*queue
;
1186 if ((unsigned)(addend
) + 0x80 < 0x100)
1188 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 1, p
);
1189 bfd_put_8 (abfd
, addend
, p
+ 1);
1190 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1192 else if ((unsigned) (addend
) + 0x8000 < 0x10000)
1194 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 2, p
);
1195 bfd_put_16 (abfd
, addend
, p
+ 1);
1196 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1198 else if ((unsigned) (addend
) + 0x800000 < 0x1000000)
1200 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 3, p
);
1201 bfd_put_8 (abfd
, addend
>> 16, p
+ 1);
1202 bfd_put_16 (abfd
, addend
, p
+ 2);
1203 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1207 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 4, p
);
1208 bfd_put_32 (abfd
, addend
, p
+ 1);
1209 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 5, queue
);
1214 /* Handle a single function call relocation. */
1216 static unsigned char *
1217 som_reloc_call (abfd
, p
, subspace_reloc_sizep
, bfd_reloc
, sym_num
, queue
)
1220 unsigned int *subspace_reloc_sizep
;
1223 struct reloc_queue
*queue
;
1225 int arg_bits
= HPPA_R_ARG_RELOC (bfd_reloc
->addend
);
1226 int rtn_bits
= arg_bits
& 0x3;
1229 /* You'll never believe all this is necessary to handle relocations
1230 for function calls. Having to compute and pack the argument
1231 relocation bits is the real nightmare.
1233 If you're interested in how this works, just forget it. You really
1234 do not want to know about this braindamage. */
1236 /* First see if this can be done with a "simple" relocation. Simple
1237 relocations have a symbol number < 0x100 and have simple encodings
1238 of argument relocations. */
1240 if (sym_num
< 0x100)
1252 case 1 << 8 | 1 << 6:
1253 case 1 << 8 | 1 << 6 | 1:
1256 case 1 << 8 | 1 << 6 | 1 << 4:
1257 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
1260 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
1261 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
1265 /* Not one of the easy encodings. This will have to be
1266 handled by the more complex code below. */
1272 /* Account for the return value too. */
1276 /* Emit a 2 byte relocation. Then see if it can be handled
1277 with a relocation which is already in the relocation queue. */
1278 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ type
, p
);
1279 bfd_put_8 (abfd
, sym_num
, p
+ 1);
1280 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1285 /* If this could not be handled with a simple relocation, then do a hard
1286 one. Hard relocations occur if the symbol number was too high or if
1287 the encoding of argument relocation bits is too complex. */
1290 /* Don't ask about these magic sequences. I took them straight
1291 from gas-1.36 which took them from the a.out man page. */
1293 if ((arg_bits
>> 6 & 0xf) == 0xe)
1296 type
+= (3 * (arg_bits
>> 8 & 3) + (arg_bits
>> 6 & 3)) * 40;
1297 if ((arg_bits
>> 2 & 0xf) == 0xe)
1300 type
+= (3 * (arg_bits
>> 4 & 3) + (arg_bits
>> 2 & 3)) * 4;
1302 /* Output the first two bytes of the relocation. These describe
1303 the length of the relocation and encoding style. */
1304 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 10
1305 + 2 * (sym_num
>= 0x100) + (type
>= 0x100),
1307 bfd_put_8 (abfd
, type
, p
+ 1);
1309 /* Now output the symbol index and see if this bizarre relocation
1310 just happened to be in the relocation queue. */
1311 if (sym_num
< 0x100)
1313 bfd_put_8 (abfd
, sym_num
, p
+ 2);
1314 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1318 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 2);
1319 bfd_put_16 (abfd
, sym_num
, p
+ 3);
1320 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 5, queue
);
1327 /* Return the logarithm of X, base 2, considering X unsigned.
1328 Abort -1 if X is not a power or two or is zero. */
1336 /* Test for 0 or a power of 2. */
1337 if (x
== 0 || x
!= (x
& -x
))
1340 while ((x
>>= 1) != 0)
1345 static bfd_reloc_status_type
1346 hppa_som_reloc (abfd
, reloc_entry
, symbol_in
, data
,
1347 input_section
, output_bfd
, error_message
)
1349 arelent
*reloc_entry
;
1352 asection
*input_section
;
1354 char **error_message
;
1358 reloc_entry
->address
+= input_section
->output_offset
;
1359 return bfd_reloc_ok
;
1361 return bfd_reloc_ok
;
1364 /* Given a generic HPPA relocation type, the instruction format,
1365 and a field selector, return one or more appropriate SOM relocations. */
1368 hppa_som_gen_reloc_type (abfd
, base_type
, format
, field
)
1372 enum hppa_reloc_field_selector_type_alt field
;
1374 int *final_type
, **final_types
;
1376 final_types
= (int **) bfd_alloc_by_size_t (abfd
, sizeof (int *) * 3);
1377 final_type
= (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1378 if (!final_types
|| !final_type
)
1380 bfd_set_error (bfd_error_no_memory
);
1384 /* The field selector may require additional relocations to be
1385 generated. It's impossible to know at this moment if additional
1386 relocations will be needed, so we make them. The code to actually
1387 write the relocation/fixup stream is responsible for removing
1388 any redundant relocations. */
1395 final_types
[0] = final_type
;
1396 final_types
[1] = NULL
;
1397 final_types
[2] = NULL
;
1398 *final_type
= base_type
;
1404 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1405 if (!final_types
[0])
1407 bfd_set_error (bfd_error_no_memory
);
1410 if (field
== e_tsel
)
1411 *final_types
[0] = R_FSEL
;
1412 else if (field
== e_ltsel
)
1413 *final_types
[0] = R_LSEL
;
1415 *final_types
[0] = R_RSEL
;
1416 final_types
[1] = final_type
;
1417 final_types
[2] = NULL
;
1418 *final_type
= base_type
;
1423 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1424 if (!final_types
[0])
1426 bfd_set_error (bfd_error_no_memory
);
1429 *final_types
[0] = R_S_MODE
;
1430 final_types
[1] = final_type
;
1431 final_types
[2] = NULL
;
1432 *final_type
= base_type
;
1437 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1438 if (!final_types
[0])
1440 bfd_set_error (bfd_error_no_memory
);
1443 *final_types
[0] = R_N_MODE
;
1444 final_types
[1] = final_type
;
1445 final_types
[2] = NULL
;
1446 *final_type
= base_type
;
1451 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1452 if (!final_types
[0])
1454 bfd_set_error (bfd_error_no_memory
);
1457 *final_types
[0] = R_D_MODE
;
1458 final_types
[1] = final_type
;
1459 final_types
[2] = NULL
;
1460 *final_type
= base_type
;
1465 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1466 if (!final_types
[0])
1468 bfd_set_error (bfd_error_no_memory
);
1471 *final_types
[0] = R_R_MODE
;
1472 final_types
[1] = final_type
;
1473 final_types
[2] = NULL
;
1474 *final_type
= base_type
;
1481 /* PLABELs get their own relocation type. */
1484 || field
== e_rpsel
)
1486 /* A PLABEL relocation that has a size of 32 bits must
1487 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
1489 *final_type
= R_DATA_PLABEL
;
1491 *final_type
= R_CODE_PLABEL
;
1494 else if (field
== e_tsel
1496 || field
== e_rtsel
)
1497 *final_type
= R_DLT_REL
;
1498 /* A relocation in the data space is always a full 32bits. */
1499 else if (format
== 32)
1500 *final_type
= R_DATA_ONE_SYMBOL
;
1505 /* More PLABEL special cases. */
1508 || field
== e_rpsel
)
1509 *final_type
= R_DATA_PLABEL
;
1513 case R_HPPA_ABS_CALL
:
1514 case R_HPPA_PCREL_CALL
:
1515 case R_HPPA_COMPLEX
:
1516 case R_HPPA_COMPLEX_PCREL_CALL
:
1517 case R_HPPA_COMPLEX_ABS_CALL
:
1518 /* Right now we can default all these. */
1524 /* Return the address of the correct entry in the PA SOM relocation
1527 static const reloc_howto_type
*
1528 som_bfd_reloc_type_lookup (arch
, code
)
1529 bfd_arch_info_type
*arch
;
1530 bfd_reloc_code_real_type code
;
1532 if ((int) code
< (int) R_NO_RELOCATION
+ 255)
1534 BFD_ASSERT ((int) som_hppa_howto_table
[(int) code
].type
== (int) code
);
1535 return &som_hppa_howto_table
[(int) code
];
1538 return (reloc_howto_type
*) 0;
1541 /* Perform some initialization for an object. Save results of this
1542 initialization in the BFD. */
1545 som_object_setup (abfd
, file_hdrp
, aux_hdrp
)
1547 struct header
*file_hdrp
;
1548 struct som_exec_auxhdr
*aux_hdrp
;
1550 /* som_mkobject will set bfd_error if som_mkobject fails. */
1551 if (som_mkobject (abfd
) != true)
1554 /* Set BFD flags based on what information is available in the SOM. */
1555 abfd
->flags
= NO_FLAGS
;
1556 if (file_hdrp
->symbol_total
)
1557 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
1559 switch (file_hdrp
->a_magic
)
1562 abfd
->flags
|= (D_PAGED
| WP_TEXT
| EXEC_P
);
1565 abfd
->flags
|= (WP_TEXT
| EXEC_P
);
1568 abfd
->flags
|= (EXEC_P
);
1571 abfd
->flags
|= HAS_RELOC
;
1577 bfd_get_start_address (abfd
) = aux_hdrp
->exec_entry
;
1578 bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 0);
1579 bfd_get_symcount (abfd
) = file_hdrp
->symbol_total
;
1581 /* Initialize the saved symbol table and string table to NULL.
1582 Save important offsets and sizes from the SOM header into
1584 obj_som_stringtab (abfd
) = (char *) NULL
;
1585 obj_som_symtab (abfd
) = (som_symbol_type
*) NULL
;
1586 obj_som_stringtab_size (abfd
) = file_hdrp
->symbol_strings_size
;
1587 obj_som_sym_filepos (abfd
) = file_hdrp
->symbol_location
;
1588 obj_som_str_filepos (abfd
) = file_hdrp
->symbol_strings_location
;
1589 obj_som_reloc_filepos (abfd
) = file_hdrp
->fixup_request_location
;
1594 /* Convert all of the space and subspace info into BFD sections. Each space
1595 contains a number of subspaces, which in turn describe the mapping between
1596 regions of the exec file, and the address space that the program runs in.
1597 BFD sections which correspond to spaces will overlap the sections for the
1598 associated subspaces. */
1601 setup_sections (abfd
, file_hdr
)
1603 struct header
*file_hdr
;
1605 char *space_strings
;
1607 unsigned int total_subspaces
= 0;
1609 /* First, read in space names */
1611 space_strings
= malloc (file_hdr
->space_strings_size
);
1614 bfd_set_error (bfd_error_no_memory
);
1618 if (bfd_seek (abfd
, file_hdr
->space_strings_location
, SEEK_SET
) < 0)
1620 if (bfd_read (space_strings
, 1, file_hdr
->space_strings_size
, abfd
)
1621 != file_hdr
->space_strings_size
)
1624 /* Loop over all of the space dictionaries, building up sections */
1625 for (space_index
= 0; space_index
< file_hdr
->space_total
; space_index
++)
1627 struct space_dictionary_record space
;
1628 struct subspace_dictionary_record subspace
, save_subspace
;
1630 asection
*space_asect
;
1633 /* Read the space dictionary element */
1634 if (bfd_seek (abfd
, file_hdr
->space_location
1635 + space_index
* sizeof space
, SEEK_SET
) < 0)
1637 if (bfd_read (&space
, 1, sizeof space
, abfd
) != sizeof space
)
1640 /* Setup the space name string */
1641 space
.name
.n_name
= space
.name
.n_strx
+ space_strings
;
1643 /* Make a section out of it */
1644 newname
= bfd_alloc (abfd
, strlen (space
.name
.n_name
) + 1);
1647 strcpy (newname
, space
.name
.n_name
);
1649 space_asect
= bfd_make_section_anyway (abfd
, newname
);
1653 if (space
.is_loadable
== 0)
1654 space_asect
->flags
|= SEC_DEBUGGING
;
1656 /* Set up all the attributes for the space. */
1657 bfd_som_set_section_attributes (space_asect
, space
.is_defined
,
1658 space
.is_private
, space
.sort_key
,
1659 space
.space_number
);
1661 /* Now, read in the first subspace for this space */
1662 if (bfd_seek (abfd
, file_hdr
->subspace_location
1663 + space
.subspace_index
* sizeof subspace
,
1666 if (bfd_read (&subspace
, 1, sizeof subspace
, abfd
) != sizeof subspace
)
1668 /* Seek back to the start of the subspaces for loop below */
1669 if (bfd_seek (abfd
, file_hdr
->subspace_location
1670 + space
.subspace_index
* sizeof subspace
,
1674 /* Setup the start address and file loc from the first subspace record */
1675 space_asect
->vma
= subspace
.subspace_start
;
1676 space_asect
->filepos
= subspace
.file_loc_init_value
;
1677 space_asect
->alignment_power
= log2 (subspace
.alignment
);
1678 if (space_asect
->alignment_power
== -1)
1681 /* Initialize save_subspace so we can reliably determine if this
1682 loop placed any useful values into it. */
1683 memset (&save_subspace
, 0, sizeof (struct subspace_dictionary_record
));
1685 /* Loop over the rest of the subspaces, building up more sections */
1686 for (subspace_index
= 0; subspace_index
< space
.subspace_quantity
;
1689 asection
*subspace_asect
;
1691 /* Read in the next subspace */
1692 if (bfd_read (&subspace
, 1, sizeof subspace
, abfd
)
1696 /* Setup the subspace name string */
1697 subspace
.name
.n_name
= subspace
.name
.n_strx
+ space_strings
;
1699 newname
= bfd_alloc (abfd
, strlen (subspace
.name
.n_name
) + 1);
1702 strcpy (newname
, subspace
.name
.n_name
);
1704 /* Make a section out of this subspace */
1705 subspace_asect
= bfd_make_section_anyway (abfd
, newname
);
1706 if (!subspace_asect
)
1709 /* Store private information about the section. */
1710 bfd_som_set_subsection_attributes (subspace_asect
, space_asect
,
1711 subspace
.access_control_bits
,
1715 /* Keep an easy mapping between subspaces and sections. */
1716 som_section_data (subspace_asect
)->subspace_index
1717 = total_subspaces
++;
1719 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
1720 by the access_control_bits in the subspace header. */
1721 switch (subspace
.access_control_bits
>> 4)
1723 /* Readonly data. */
1725 subspace_asect
->flags
|= SEC_DATA
| SEC_READONLY
;
1730 subspace_asect
->flags
|= SEC_DATA
;
1733 /* Readonly code and the gateways.
1734 Gateways have other attributes which do not map
1735 into anything BFD knows about. */
1741 subspace_asect
->flags
|= SEC_CODE
| SEC_READONLY
;
1744 /* dynamic (writable) code. */
1746 subspace_asect
->flags
|= SEC_CODE
;
1750 if (subspace
.dup_common
|| subspace
.is_common
)
1751 subspace_asect
->flags
|= SEC_IS_COMMON
;
1752 else if (subspace
.subspace_length
> 0)
1753 subspace_asect
->flags
|= SEC_HAS_CONTENTS
;
1755 if (subspace
.is_loadable
)
1756 subspace_asect
->flags
|= SEC_ALLOC
| SEC_LOAD
;
1758 subspace_asect
->flags
|= SEC_DEBUGGING
;
1760 if (subspace
.code_only
)
1761 subspace_asect
->flags
|= SEC_CODE
;
1763 /* Both file_loc_init_value and initialization_length will
1764 be zero for a BSS like subspace. */
1765 if (subspace
.file_loc_init_value
== 0
1766 && subspace
.initialization_length
== 0)
1767 subspace_asect
->flags
&= ~(SEC_DATA
| SEC_LOAD
);
1769 /* This subspace has relocations.
1770 The fixup_request_quantity is a byte count for the number of
1771 entries in the relocation stream; it is not the actual number
1772 of relocations in the subspace. */
1773 if (subspace
.fixup_request_quantity
!= 0)
1775 subspace_asect
->flags
|= SEC_RELOC
;
1776 subspace_asect
->rel_filepos
= subspace
.fixup_request_index
;
1777 som_section_data (subspace_asect
)->reloc_size
1778 = subspace
.fixup_request_quantity
;
1779 /* We can not determine this yet. When we read in the
1780 relocation table the correct value will be filled in. */
1781 subspace_asect
->reloc_count
= -1;
1784 /* Update save_subspace if appropriate. */
1785 if (subspace
.file_loc_init_value
> save_subspace
.file_loc_init_value
)
1786 save_subspace
= subspace
;
1788 subspace_asect
->vma
= subspace
.subspace_start
;
1789 subspace_asect
->_cooked_size
= subspace
.subspace_length
;
1790 subspace_asect
->_raw_size
= subspace
.subspace_length
;
1791 subspace_asect
->filepos
= subspace
.file_loc_init_value
;
1792 subspace_asect
->alignment_power
= log2 (subspace
.alignment
);
1793 if (subspace_asect
->alignment_power
== -1)
1797 /* Yow! there is no subspace within the space which actually
1798 has initialized information in it; this should never happen
1799 as far as I know. */
1800 if (!save_subspace
.file_loc_init_value
)
1803 /* Setup the sizes for the space section based upon the info in the
1804 last subspace of the space. */
1805 space_asect
->_cooked_size
= save_subspace
.subspace_start
1806 - space_asect
->vma
+ save_subspace
.subspace_length
;
1807 space_asect
->_raw_size
= save_subspace
.file_loc_init_value
1808 - space_asect
->filepos
+ save_subspace
.initialization_length
;
1810 if (space_strings
!= NULL
)
1811 free (space_strings
);
1815 if (space_strings
!= NULL
)
1816 free (space_strings
);
1820 /* Read in a SOM object and make it into a BFD. */
1826 struct header file_hdr
;
1827 struct som_exec_auxhdr aux_hdr
;
1829 if (bfd_read ((PTR
) & file_hdr
, 1, FILE_HDR_SIZE
, abfd
) != FILE_HDR_SIZE
)
1831 bfd_set_error (bfd_error_system_call
);
1835 if (!_PA_RISC_ID (file_hdr
.system_id
))
1837 bfd_set_error (bfd_error_wrong_format
);
1841 switch (file_hdr
.a_magic
)
1856 #ifdef SHARED_MAGIC_CNX
1857 case SHARED_MAGIC_CNX
:
1861 bfd_set_error (bfd_error_wrong_format
);
1865 if (file_hdr
.version_id
!= VERSION_ID
1866 && file_hdr
.version_id
!= NEW_VERSION_ID
)
1868 bfd_set_error (bfd_error_wrong_format
);
1872 /* If the aux_header_size field in the file header is zero, then this
1873 object is an incomplete executable (a .o file). Do not try to read
1874 a non-existant auxiliary header. */
1875 memset (&aux_hdr
, 0, sizeof (struct som_exec_auxhdr
));
1876 if (file_hdr
.aux_header_size
!= 0)
1878 if (bfd_read ((PTR
) & aux_hdr
, 1, AUX_HDR_SIZE
, abfd
) != AUX_HDR_SIZE
)
1880 bfd_set_error (bfd_error_wrong_format
);
1885 if (!setup_sections (abfd
, &file_hdr
))
1887 /* setup_sections does not bubble up a bfd error code. */
1888 bfd_set_error (bfd_error_bad_value
);
1892 /* This appears to be a valid SOM object. Do some initialization. */
1893 return som_object_setup (abfd
, &file_hdr
, &aux_hdr
);
1896 /* Create a SOM object. */
1902 /* Allocate memory to hold backend information. */
1903 abfd
->tdata
.som_data
= (struct som_data_struct
*)
1904 bfd_zalloc (abfd
, sizeof (struct som_data_struct
));
1905 if (abfd
->tdata
.som_data
== NULL
)
1907 bfd_set_error (bfd_error_no_memory
);
1910 obj_som_file_hdr (abfd
)
1911 = (struct header
*) bfd_zalloc (abfd
, sizeof (struct header
));
1912 if (obj_som_file_hdr (abfd
) == NULL
)
1915 bfd_set_error (bfd_error_no_memory
);
1921 /* Initialize some information in the file header. This routine makes
1922 not attempt at doing the right thing for a full executable; it
1923 is only meant to handle relocatable objects. */
1926 som_prep_headers (abfd
)
1929 struct header
*file_hdr
= obj_som_file_hdr (abfd
);
1932 /* FIXME. This should really be conditional based on whether or not
1933 PA1.1 instructions/registers have been used. */
1934 file_hdr
->system_id
= CPU_PA_RISC1_0
;
1936 if (abfd
->flags
& EXEC_P
)
1938 if (abfd
->flags
& D_PAGED
)
1939 file_hdr
->a_magic
= DEMAND_MAGIC
;
1940 else if (abfd
->flags
& WP_TEXT
)
1941 file_hdr
->a_magic
= SHARE_MAGIC
;
1943 file_hdr
->a_magic
= EXEC_MAGIC
;
1946 file_hdr
->a_magic
= RELOC_MAGIC
;
1948 /* Only new format SOM is supported. */
1949 file_hdr
->version_id
= NEW_VERSION_ID
;
1951 /* These fields are optional, and embedding timestamps is not always
1952 a wise thing to do, it makes comparing objects during a multi-stage
1953 bootstrap difficult. */
1954 file_hdr
->file_time
.secs
= 0;
1955 file_hdr
->file_time
.nanosecs
= 0;
1957 if (abfd
->flags
& EXEC_P
)
1961 file_hdr
->entry_space
= 0;
1962 file_hdr
->entry_subspace
= 0;
1963 file_hdr
->entry_offset
= 0;
1966 file_hdr
->presumed_dp
= 0;
1968 /* Now iterate over the sections translating information from
1969 BFD sections to SOM spaces/subspaces. */
1971 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
1973 /* Ignore anything which has not been marked as a space or
1975 if (som_section_data (section
)->is_space
== 0
1977 && som_section_data (section
)->is_subspace
== 0)
1980 if (som_section_data (section
)->is_space
)
1982 /* Set space attributes. Note most attributes of SOM spaces
1983 are set based on the subspaces it contains. */
1984 som_section_data (section
)->space_dict
.loader_fix_index
= -1;
1985 som_section_data (section
)->space_dict
.init_pointer_index
= -1;
1989 /* Set subspace attributes. Basic stuff is done here, additional
1990 attributes are filled in later as more information becomes
1992 if (section
->flags
& SEC_IS_COMMON
)
1994 som_section_data (section
)->subspace_dict
.dup_common
= 1;
1995 som_section_data (section
)->subspace_dict
.is_common
= 1;
1998 if (section
->flags
& SEC_ALLOC
)
1999 som_section_data (section
)->subspace_dict
.is_loadable
= 1;
2001 if (section
->flags
& SEC_CODE
)
2002 som_section_data (section
)->subspace_dict
.code_only
= 1;
2004 som_section_data (section
)->subspace_dict
.subspace_start
=
2006 som_section_data (section
)->subspace_dict
.subspace_length
=
2007 bfd_section_size (abfd
, section
);
2008 som_section_data (section
)->subspace_dict
.initialization_length
=
2009 bfd_section_size (abfd
, section
);
2010 som_section_data (section
)->subspace_dict
.alignment
=
2011 1 << section
->alignment_power
;
2017 /* Count and return the number of spaces attached to the given BFD. */
2019 static unsigned long
2020 som_count_spaces (abfd
)
2026 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2027 count
+= som_section_data (section
)->is_space
;
2032 /* Count the number of subspaces attached to the given BFD. */
2034 static unsigned long
2035 som_count_subspaces (abfd
)
2041 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2042 count
+= som_section_data (section
)->is_subspace
;
2047 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
2049 We desire symbols to be ordered starting with the symbol with the
2050 highest relocation count down to the symbol with the lowest relocation
2051 count. Doing so compacts the relocation stream. */
2054 compare_syms (sym1
, sym2
)
2059 unsigned int count1
, count2
;
2061 /* Get relocation count for each symbol. Note that the count
2062 is stored in the udata pointer for section symbols! */
2063 if ((*sym1
)->flags
& BSF_SECTION_SYM
)
2064 count1
= (int)(*sym1
)->udata
;
2066 count1
= som_symbol_data (*sym1
)->reloc_count
;
2068 if ((*sym2
)->flags
& BSF_SECTION_SYM
)
2069 count2
= (int)(*sym2
)->udata
;
2071 count2
= som_symbol_data (*sym2
)->reloc_count
;
2073 /* Return the appropriate value. */
2074 if (count1
< count2
)
2076 else if (count1
> count2
)
2081 /* Perform various work in preparation for emitting the fixup stream. */
2084 som_prep_for_fixups (abfd
, syms
, num_syms
)
2087 unsigned long num_syms
;
2092 /* Most SOM relocations involving a symbol have a length which is
2093 dependent on the index of the symbol. So symbols which are
2094 used often in relocations should have a small index. */
2096 /* First initialize the counters for each symbol. */
2097 for (i
= 0; i
< num_syms
; i
++)
2099 /* Handle a section symbol; these have no pointers back to the
2100 SOM symbol info. So we just use the pointer field (udata)
2101 to hold the relocation count.
2103 FIXME. While we're here set the name of any section symbol
2104 to something which will not screw GDB. How do other formats
2105 deal with this?!? */
2106 if (som_symbol_data (syms
[i
]) == NULL
)
2108 syms
[i
]->flags
|= BSF_SECTION_SYM
;
2109 syms
[i
]->name
= "L$0\002";
2110 syms
[i
]->udata
= (PTR
) 0;
2113 som_symbol_data (syms
[i
])->reloc_count
= 0;
2116 /* Now that the counters are initialized, make a weighted count
2117 of how often a given symbol is used in a relocation. */
2118 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2122 /* Does this section have any relocations? */
2123 if (section
->reloc_count
<= 0)
2126 /* Walk through each relocation for this section. */
2127 for (i
= 1; i
< section
->reloc_count
; i
++)
2129 arelent
*reloc
= section
->orelocation
[i
];
2132 /* A relocation against a symbol in the *ABS* section really
2133 does not have a symbol. Likewise if the symbol isn't associated
2134 with any section. */
2135 if (reloc
->sym_ptr_ptr
== NULL
2136 || (*reloc
->sym_ptr_ptr
)->section
== &bfd_abs_section
)
2139 /* Scaling to encourage symbols involved in R_DP_RELATIVE
2140 and R_CODE_ONE_SYMBOL relocations to come first. These
2141 two relocations have single byte versions if the symbol
2142 index is very small. */
2143 if (reloc
->howto
->type
== R_DP_RELATIVE
2144 || reloc
->howto
->type
== R_CODE_ONE_SYMBOL
)
2149 /* Handle section symbols by ramming the count in the udata
2150 field. It will not be used and the count is very important
2151 for these symbols. */
2152 if ((*reloc
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
)
2154 (*reloc
->sym_ptr_ptr
)->udata
=
2155 (PTR
) ((int) (*reloc
->sym_ptr_ptr
)->udata
+ scale
);
2159 /* A normal symbol. Increment the count. */
2160 som_symbol_data (*reloc
->sym_ptr_ptr
)->reloc_count
+= scale
;
2164 /* Now sort the symbols. */
2165 qsort (syms
, num_syms
, sizeof (asymbol
*), compare_syms
);
2167 /* Compute the symbol indexes, they will be needed by the relocation
2169 for (i
= 0; i
< num_syms
; i
++)
2171 /* A section symbol. Again, there is no pointer to backend symbol
2172 information, so we reuse (abuse) the udata field again. */
2173 if (syms
[i
]->flags
& BSF_SECTION_SYM
)
2174 syms
[i
]->udata
= (PTR
) i
;
2176 som_symbol_data (syms
[i
])->index
= i
;
2181 som_write_fixups (abfd
, current_offset
, total_reloc_sizep
)
2183 unsigned long current_offset
;
2184 unsigned int *total_reloc_sizep
;
2187 /* Chunk of memory that we can use as buffer space, then throw
2189 unsigned char tmp_space
[SOM_TMP_BUFSIZE
];
2191 unsigned int total_reloc_size
= 0;
2192 unsigned int subspace_reloc_size
= 0;
2193 unsigned int num_spaces
= obj_som_file_hdr (abfd
)->space_total
;
2194 asection
*section
= abfd
->sections
;
2196 memset (tmp_space
, 0, SOM_TMP_BUFSIZE
);
2199 /* All the fixups for a particular subspace are emitted in a single
2200 stream. All the subspaces for a particular space are emitted
2203 So, to get all the locations correct one must iterate through all the
2204 spaces, for each space iterate through its subspaces and output a
2206 for (i
= 0; i
< num_spaces
; i
++)
2208 asection
*subsection
;
2211 while (som_section_data (section
)->is_space
== 0)
2212 section
= section
->next
;
2214 /* Now iterate through each of its subspaces. */
2215 for (subsection
= abfd
->sections
;
2217 subsection
= subsection
->next
)
2219 int reloc_offset
, current_rounding_mode
;
2221 /* Find a subspace of this space. */
2222 if (som_section_data (subsection
)->is_subspace
== 0
2223 || som_section_data (subsection
)->containing_space
!= section
)
2226 /* If this subspace had no relocations, then we're finished
2228 if (subsection
->reloc_count
<= 0)
2230 som_section_data (subsection
)->subspace_dict
.fixup_request_index
2235 /* This subspace has some relocations. Put the relocation stream
2236 index into the subspace record. */
2237 som_section_data (subsection
)->subspace_dict
.fixup_request_index
2240 /* To make life easier start over with a clean slate for
2241 each subspace. Seek to the start of the relocation stream
2242 for this subspace in preparation for writing out its fixup
2244 if (bfd_seek (abfd
, current_offset
+ total_reloc_size
, SEEK_SET
) != 0)
2246 bfd_set_error (bfd_error_system_call
);
2250 /* Buffer space has already been allocated. Just perform some
2251 initialization here. */
2253 subspace_reloc_size
= 0;
2255 som_initialize_reloc_queue (reloc_queue
);
2256 current_rounding_mode
= R_N_MODE
;
2258 /* Translate each BFD relocation into one or more SOM
2260 for (j
= 0; j
< subsection
->reloc_count
; j
++)
2262 arelent
*bfd_reloc
= subsection
->orelocation
[j
];
2266 /* Get the symbol number. Remember it's stored in a
2267 special place for section symbols. */
2268 if ((*bfd_reloc
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
)
2269 sym_num
= (int) (*bfd_reloc
->sym_ptr_ptr
)->udata
;
2271 sym_num
= som_symbol_data (*bfd_reloc
->sym_ptr_ptr
)->index
;
2273 /* If there is not enough room for the next couple relocations,
2274 then dump the current buffer contents now. Also reinitialize
2275 the relocation queue.
2277 No single BFD relocation could ever translate into more
2278 than 100 bytes of SOM relocations (20bytes is probably the
2279 upper limit, but leave lots of space for growth). */
2280 if (p
- tmp_space
+ 100 > SOM_TMP_BUFSIZE
)
2282 if (bfd_write ((PTR
) tmp_space
, p
- tmp_space
, 1, abfd
)
2285 bfd_set_error (bfd_error_system_call
);
2289 som_initialize_reloc_queue (reloc_queue
);
2292 /* Emit R_NO_RELOCATION fixups to map any bytes which were
2294 skip
= bfd_reloc
->address
- reloc_offset
;
2295 p
= som_reloc_skip (abfd
, skip
, p
,
2296 &subspace_reloc_size
, reloc_queue
);
2298 /* Update reloc_offset for the next iteration.
2300 Many relocations do not consume input bytes. They
2301 are markers, or set state necessary to perform some
2302 later relocation. */
2303 switch (bfd_reloc
->howto
->type
)
2305 /* This only needs to handle relocations that may be
2306 made by hppa_som_gen_reloc. */
2316 reloc_offset
= bfd_reloc
->address
;
2320 reloc_offset
= bfd_reloc
->address
+ 4;
2324 /* Now the actual relocation we care about. */
2325 switch (bfd_reloc
->howto
->type
)
2329 p
= som_reloc_call (abfd
, p
, &subspace_reloc_size
,
2330 bfd_reloc
, sym_num
, reloc_queue
);
2333 case R_CODE_ONE_SYMBOL
:
2335 /* Account for any addend. */
2336 if (bfd_reloc
->addend
)
2337 p
= som_reloc_addend (abfd
, bfd_reloc
->addend
, p
,
2338 &subspace_reloc_size
, reloc_queue
);
2342 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ sym_num
, p
);
2343 subspace_reloc_size
+= 1;
2346 else if (sym_num
< 0x100)
2348 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 32, p
);
2349 bfd_put_8 (abfd
, sym_num
, p
+ 1);
2350 p
= try_prev_fixup (abfd
, &subspace_reloc_size
, p
,
2353 else if (sym_num
< 0x10000000)
2355 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 33, p
);
2356 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 1);
2357 bfd_put_16 (abfd
, sym_num
, p
+ 2);
2358 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2365 case R_DATA_ONE_SYMBOL
:
2369 /* Account for any addend. */
2370 if (bfd_reloc
->addend
)
2371 p
= som_reloc_addend (abfd
, bfd_reloc
->addend
, p
,
2372 &subspace_reloc_size
, reloc_queue
);
2374 if (sym_num
< 0x100)
2376 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2377 bfd_put_8 (abfd
, sym_num
, p
+ 1);
2378 p
= try_prev_fixup (abfd
, &subspace_reloc_size
, p
,
2381 else if (sym_num
< 0x10000000)
2383 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 1, p
);
2384 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 1);
2385 bfd_put_16 (abfd
, sym_num
, p
+ 2);
2386 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2396 = (int *) som_symbol_data (*bfd_reloc
->sym_ptr_ptr
)->unwind
;
2397 bfd_put_8 (abfd
, R_ENTRY
, p
);
2398 bfd_put_32 (abfd
, descp
[0], p
+ 1);
2399 bfd_put_32 (abfd
, descp
[1], p
+ 5);
2400 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2406 bfd_put_8 (abfd
, R_EXIT
, p
);
2407 subspace_reloc_size
+= 1;
2415 /* If this relocation requests the current rounding
2416 mode, then it is redundant. */
2417 if (bfd_reloc
->howto
->type
!= current_rounding_mode
)
2419 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2420 subspace_reloc_size
+= 1;
2422 current_rounding_mode
= bfd_reloc
->howto
->type
;
2429 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2430 subspace_reloc_size
+= 1;
2434 /* Put a "R_RESERVED" relocation in the stream if
2435 we hit something we do not understand. The linker
2436 will complain loudly if this ever happens. */
2438 bfd_put_8 (abfd
, 0xff, p
);
2439 subspace_reloc_size
+= 1;
2445 /* Last BFD relocation for a subspace has been processed.
2446 Map the rest of the subspace with R_NO_RELOCATION fixups. */
2447 p
= som_reloc_skip (abfd
, bfd_section_size (abfd
, subsection
)
2449 p
, &subspace_reloc_size
, reloc_queue
);
2451 /* Scribble out the relocations. */
2452 if (bfd_write ((PTR
) tmp_space
, p
- tmp_space
, 1, abfd
)
2455 bfd_set_error (bfd_error_system_call
);
2460 total_reloc_size
+= subspace_reloc_size
;
2461 som_section_data (subsection
)->subspace_dict
.fixup_request_quantity
2462 = subspace_reloc_size
;
2464 section
= section
->next
;
2466 *total_reloc_sizep
= total_reloc_size
;
2470 /* Write out the space/subspace string table. */
2473 som_write_space_strings (abfd
, current_offset
, string_sizep
)
2475 unsigned long current_offset
;
2476 unsigned int *string_sizep
;
2478 /* Chunk of memory that we can use as buffer space, then throw
2480 unsigned char tmp_space
[SOM_TMP_BUFSIZE
];
2482 unsigned int strings_size
= 0;
2485 memset (tmp_space
, 0, SOM_TMP_BUFSIZE
);
2488 /* Seek to the start of the space strings in preparation for writing
2490 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) != 0)
2492 bfd_set_error (bfd_error_system_call
);
2496 /* Walk through all the spaces and subspaces (order is not important)
2497 building up and writing string table entries for their names. */
2498 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2502 /* Only work with space/subspaces; avoid any other sections
2503 which might have been made (.text for example). */
2504 if (som_section_data (section
)->is_space
== 0
2505 && som_section_data (section
)->is_subspace
== 0)
2508 /* Get the length of the space/subspace name. */
2509 length
= strlen (section
->name
);
2511 /* If there is not enough room for the next entry, then dump the
2512 current buffer contents now. Each entry will take 4 bytes to
2513 hold the string length + the string itself + null terminator. */
2514 if (p
- tmp_space
+ 5 + length
> SOM_TMP_BUFSIZE
)
2516 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
)
2519 bfd_set_error (bfd_error_system_call
);
2522 /* Reset to beginning of the buffer space. */
2526 /* First element in a string table entry is the length of the
2527 string. Alignment issues are already handled. */
2528 bfd_put_32 (abfd
, length
, p
);
2532 /* Record the index in the space/subspace records. */
2533 if (som_section_data (section
)->is_space
)
2534 som_section_data (section
)->space_dict
.name
.n_strx
= strings_size
;
2536 som_section_data (section
)->subspace_dict
.name
.n_strx
= strings_size
;
2538 /* Next comes the string itself + a null terminator. */
2539 strcpy (p
, section
->name
);
2541 strings_size
+= length
+ 1;
2543 /* Always align up to the next word boundary. */
2544 while (strings_size
% 4)
2546 bfd_put_8 (abfd
, 0, p
);
2552 /* Done with the space/subspace strings. Write out any information
2553 contained in a partial block. */
2554 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
) != p
- tmp_space
)
2556 bfd_set_error (bfd_error_system_call
);
2559 *string_sizep
= strings_size
;
2563 /* Write out the symbol string table. */
2566 som_write_symbol_strings (abfd
, current_offset
, syms
, num_syms
, string_sizep
)
2568 unsigned long current_offset
;
2570 unsigned int num_syms
;
2571 unsigned int *string_sizep
;
2575 /* Chunk of memory that we can use as buffer space, then throw
2577 unsigned char tmp_space
[SOM_TMP_BUFSIZE
];
2579 unsigned int strings_size
= 0;
2581 memset (tmp_space
, 0, SOM_TMP_BUFSIZE
);
2584 /* Seek to the start of the space strings in preparation for writing
2586 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) != 0)
2588 bfd_set_error (bfd_error_system_call
);
2592 for (i
= 0; i
< num_syms
; i
++)
2594 int length
= strlen (syms
[i
]->name
);
2596 /* If there is not enough room for the next entry, then dump the
2597 current buffer contents now. */
2598 if (p
- tmp_space
+ 5 + length
> SOM_TMP_BUFSIZE
)
2600 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
)
2603 bfd_set_error (bfd_error_system_call
);
2606 /* Reset to beginning of the buffer space. */
2610 /* First element in a string table entry is the length of the
2611 string. This must always be 4 byte aligned. This is also
2612 an appropriate time to fill in the string index field in the
2613 symbol table entry. */
2614 bfd_put_32 (abfd
, length
, p
);
2618 /* Next comes the string itself + a null terminator. */
2619 strcpy (p
, syms
[i
]->name
);
2622 syms
[i
]->name
= (char *)strings_size
;
2624 strings_size
+= length
+ 1;
2626 /* Always align up to the next word boundary. */
2627 while (strings_size
% 4)
2629 bfd_put_8 (abfd
, 0, p
);
2635 /* Scribble out any partial block. */
2636 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
) != p
- tmp_space
)
2638 bfd_set_error (bfd_error_system_call
);
2642 *string_sizep
= strings_size
;
2646 /* Compute variable information to be placed in the SOM headers,
2647 space/subspace dictionaries, relocation streams, etc. Begin
2648 writing parts of the object file. */
2651 som_begin_writing (abfd
)
2654 unsigned long current_offset
= 0;
2655 int strings_size
= 0;
2656 unsigned int total_reloc_size
= 0;
2657 unsigned long num_spaces
, num_subspaces
, num_syms
, i
;
2659 asymbol
**syms
= bfd_get_outsymbols (abfd
);
2660 unsigned int total_subspaces
= 0;
2662 /* The file header will always be first in an object file,
2663 everything else can be in random locations. To keep things
2664 "simple" BFD will lay out the object file in the manner suggested
2665 by the PRO ABI for PA-RISC Systems. */
2667 /* Before any output can really begin offsets for all the major
2668 portions of the object file must be computed. So, starting
2669 with the initial file header compute (and sometimes write)
2670 each portion of the object file. */
2672 /* Make room for the file header, it's contents are not complete
2673 yet, so it can not be written at this time. */
2674 current_offset
+= sizeof (struct header
);
2676 /* Any auxiliary headers will follow the file header. Right now
2677 we support only the copyright and version headers. */
2678 obj_som_file_hdr (abfd
)->aux_header_location
= current_offset
;
2679 obj_som_file_hdr (abfd
)->aux_header_size
= 0;
2680 if (obj_som_version_hdr (abfd
) != NULL
)
2684 bfd_seek (abfd
, current_offset
, SEEK_SET
);
2686 /* Write the aux_id structure and the string length. */
2687 len
= sizeof (struct aux_id
) + sizeof (unsigned int);
2688 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
2689 current_offset
+= len
;
2690 if (bfd_write ((PTR
) obj_som_version_hdr (abfd
), len
, 1, abfd
) != len
)
2692 bfd_set_error (bfd_error_system_call
);
2696 /* Write the version string. */
2697 len
= obj_som_version_hdr (abfd
)->header_id
.length
- sizeof (int);
2698 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
2699 current_offset
+= len
;
2700 if (bfd_write ((PTR
) obj_som_version_hdr (abfd
)->user_string
,
2701 len
, 1, abfd
) != len
)
2703 bfd_set_error (bfd_error_system_call
);
2708 if (obj_som_copyright_hdr (abfd
) != NULL
)
2712 bfd_seek (abfd
, current_offset
, SEEK_SET
);
2714 /* Write the aux_id structure and the string length. */
2715 len
= sizeof (struct aux_id
) + sizeof (unsigned int);
2716 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
2717 current_offset
+= len
;
2718 if (bfd_write ((PTR
) obj_som_copyright_hdr (abfd
), len
, 1, abfd
) != len
)
2720 bfd_set_error (bfd_error_system_call
);
2724 /* Write the copyright string. */
2725 len
= obj_som_copyright_hdr (abfd
)->header_id
.length
- sizeof (int);
2726 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
2727 current_offset
+= len
;
2728 if (bfd_write ((PTR
) obj_som_copyright_hdr (abfd
)->copyright
,
2729 len
, 1, abfd
) != len
)
2731 bfd_set_error (bfd_error_system_call
);
2736 /* Next comes the initialization pointers; we have no initialization
2737 pointers, so current offset does not change. */
2738 obj_som_file_hdr (abfd
)->init_array_location
= current_offset
;
2739 obj_som_file_hdr (abfd
)->init_array_total
= 0;
2741 /* Next are the space records. These are fixed length records.
2743 Count the number of spaces to determine how much room is needed
2744 in the object file for the space records.
2746 The names of the spaces are stored in a separate string table,
2747 and the index for each space into the string table is computed
2748 below. Therefore, it is not possible to write the space headers
2750 num_spaces
= som_count_spaces (abfd
);
2751 obj_som_file_hdr (abfd
)->space_location
= current_offset
;
2752 obj_som_file_hdr (abfd
)->space_total
= num_spaces
;
2753 current_offset
+= num_spaces
* sizeof (struct space_dictionary_record
);
2755 /* Next are the subspace records. These are fixed length records.
2757 Count the number of subspaes to determine how much room is needed
2758 in the object file for the subspace records.
2760 A variety if fields in the subspace record are still unknown at
2761 this time (index into string table, fixup stream location/size, etc). */
2762 num_subspaces
= som_count_subspaces (abfd
);
2763 obj_som_file_hdr (abfd
)->subspace_location
= current_offset
;
2764 obj_som_file_hdr (abfd
)->subspace_total
= num_subspaces
;
2765 current_offset
+= num_subspaces
* sizeof (struct subspace_dictionary_record
);
2767 /* Next is the string table for the space/subspace names. We will
2768 build and write the string table on the fly. At the same time
2769 we will fill in the space/subspace name index fields. */
2771 /* The string table needs to be aligned on a word boundary. */
2772 if (current_offset
% 4)
2773 current_offset
+= (4 - (current_offset
% 4));
2775 /* Mark the offset of the space/subspace string table in the
2777 obj_som_file_hdr (abfd
)->space_strings_location
= current_offset
;
2779 /* Scribble out the space strings. */
2780 if (som_write_space_strings (abfd
, current_offset
, &strings_size
) == false)
2783 /* Record total string table size in the header and update the
2785 obj_som_file_hdr (abfd
)->space_strings_size
= strings_size
;
2786 current_offset
+= strings_size
;
2788 /* Next is the symbol table. These are fixed length records.
2790 Count the number of symbols to determine how much room is needed
2791 in the object file for the symbol table.
2793 The names of the symbols are stored in a separate string table,
2794 and the index for each symbol name into the string table is computed
2795 below. Therefore, it is not possible to write the symobl table
2797 num_syms
= bfd_get_symcount (abfd
);
2798 obj_som_file_hdr (abfd
)->symbol_location
= current_offset
;
2799 obj_som_file_hdr (abfd
)->symbol_total
= num_syms
;
2800 current_offset
+= num_syms
* sizeof (struct symbol_dictionary_record
);
2802 /* Do prep work before handling fixups. */
2803 som_prep_for_fixups (abfd
, syms
, num_syms
);
2805 /* Next comes the fixup stream which starts on a word boundary. */
2806 if (current_offset
% 4)
2807 current_offset
+= (4 - (current_offset
% 4));
2808 obj_som_file_hdr (abfd
)->fixup_request_location
= current_offset
;
2810 /* Write the fixups and update fields in subspace headers which
2811 relate to the fixup stream. */
2812 if (som_write_fixups (abfd
, current_offset
, &total_reloc_size
) == false)
2815 /* Record the total size of the fixup stream in the file header. */
2816 obj_som_file_hdr (abfd
)->fixup_request_total
= total_reloc_size
;
2817 current_offset
+= total_reloc_size
;
2819 /* Next are the symbol strings.
2820 Align them to a word boundary. */
2821 if (current_offset
% 4)
2822 current_offset
+= (4 - (current_offset
% 4));
2823 obj_som_file_hdr (abfd
)->symbol_strings_location
= current_offset
;
2825 /* Scribble out the symbol strings. */
2826 if (som_write_symbol_strings (abfd
, current_offset
, syms
,
2827 num_syms
, &strings_size
)
2831 /* Record total string table size in header and update the
2833 obj_som_file_hdr (abfd
)->symbol_strings_size
= strings_size
;
2834 current_offset
+= strings_size
;
2836 /* Next is the compiler records. We do not use these. */
2837 obj_som_file_hdr (abfd
)->compiler_location
= current_offset
;
2838 obj_som_file_hdr (abfd
)->compiler_total
= 0;
2840 /* Now compute the file positions for the loadable subspaces. */
2842 section
= abfd
->sections
;
2843 for (i
= 0; i
< num_spaces
; i
++)
2845 asection
*subsection
;
2848 while (som_section_data (section
)->is_space
== 0)
2849 section
= section
->next
;
2851 /* Now look for all its subspaces. */
2852 for (subsection
= abfd
->sections
;
2854 subsection
= subsection
->next
)
2857 if (som_section_data (subsection
)->is_subspace
== 0
2858 || som_section_data (subsection
)->containing_space
!= section
2859 || (subsection
->flags
& SEC_ALLOC
) == 0)
2862 som_section_data (subsection
)->subspace_index
= total_subspaces
++;
2863 /* This is real data to be loaded from the file. */
2864 if (subsection
->flags
& SEC_LOAD
)
2866 som_section_data (subsection
)->subspace_dict
.file_loc_init_value
2868 section
->filepos
= current_offset
;
2869 current_offset
+= bfd_section_size (abfd
, subsection
);
2871 /* Looks like uninitialized data. */
2874 som_section_data (subsection
)->subspace_dict
.file_loc_init_value
2876 som_section_data (subsection
)->subspace_dict
.
2877 initialization_length
= 0;
2880 /* Goto the next section. */
2881 section
= section
->next
;
2884 /* Finally compute the file positions for unloadable subspaces. */
2886 obj_som_file_hdr (abfd
)->unloadable_sp_location
= current_offset
;
2887 section
= abfd
->sections
;
2888 for (i
= 0; i
< num_spaces
; i
++)
2890 asection
*subsection
;
2893 while (som_section_data (section
)->is_space
== 0)
2894 section
= section
->next
;
2896 /* Now look for all its subspaces. */
2897 for (subsection
= abfd
->sections
;
2899 subsection
= subsection
->next
)
2902 if (som_section_data (subsection
)->is_subspace
== 0
2903 || som_section_data (subsection
)->containing_space
!= section
2904 || (subsection
->flags
& SEC_ALLOC
) != 0)
2907 som_section_data (subsection
)->subspace_index
= total_subspaces
++;
2908 /* This is real data to be loaded from the file. */
2909 if ((subsection
->flags
& SEC_LOAD
) == 0)
2911 som_section_data (subsection
)->subspace_dict
.file_loc_init_value
2913 section
->filepos
= current_offset
;
2914 current_offset
+= bfd_section_size (abfd
, subsection
);
2916 /* Looks like uninitialized data. */
2919 som_section_data (subsection
)->subspace_dict
.file_loc_init_value
2921 som_section_data (subsection
)->subspace_dict
.
2922 initialization_length
= bfd_section_size (abfd
, subsection
);
2925 /* Goto the next section. */
2926 section
= section
->next
;
2929 obj_som_file_hdr (abfd
)->unloadable_sp_size
2930 = current_offset
- obj_som_file_hdr (abfd
)->unloadable_sp_location
;
2932 /* Loader fixups are not supported in any way shape or form. */
2933 obj_som_file_hdr (abfd
)->loader_fixup_location
= 0;
2934 obj_som_file_hdr (abfd
)->loader_fixup_total
= 0;
2936 /* Done. Store the total size of the SOM. */
2937 obj_som_file_hdr (abfd
)->som_length
= current_offset
;
2941 /* Finally, scribble out the various headers to the disk. */
2944 som_write_headers (abfd
)
2947 int num_spaces
= som_count_spaces (abfd
);
2949 int subspace_index
= 0;
2953 /* Subspaces are written first so that we can set up information
2954 about them in their containing spaces as the subspace is written. */
2956 /* Seek to the start of the subspace dictionary records. */
2957 location
= obj_som_file_hdr (abfd
)->subspace_location
;
2958 bfd_seek (abfd
, location
, SEEK_SET
);
2959 section
= abfd
->sections
;
2960 /* Now for each loadable space write out records for its subspaces. */
2961 for (i
= 0; i
< num_spaces
; i
++)
2963 asection
*subsection
;
2966 while (som_section_data (section
)->is_space
== 0)
2967 section
= section
->next
;
2969 /* Now look for all its subspaces. */
2970 for (subsection
= abfd
->sections
;
2972 subsection
= subsection
->next
)
2975 /* Skip any section which does not correspond to a space
2976 or subspace. Or does not have SEC_ALLOC set (and therefore
2977 has no real bits on the disk). */
2978 if (som_section_data (subsection
)->is_subspace
== 0
2979 || som_section_data (subsection
)->containing_space
!= section
2980 || (subsection
->flags
& SEC_ALLOC
) == 0)
2983 /* If this is the first subspace for this space, then save
2984 the index of the subspace in its containing space. Also
2985 set "is_loadable" in the containing space. */
2987 if (som_section_data (section
)->space_dict
.subspace_quantity
== 0)
2989 som_section_data (section
)->space_dict
.is_loadable
= 1;
2990 som_section_data (section
)->space_dict
.subspace_index
2994 /* Increment the number of subspaces seen and the number of
2995 subspaces contained within the current space. */
2997 som_section_data (section
)->space_dict
.subspace_quantity
++;
2999 /* Mark the index of the current space within the subspace's
3000 dictionary record. */
3001 som_section_data (subsection
)->subspace_dict
.space_index
= i
;
3003 /* Dump the current subspace header. */
3004 if (bfd_write ((PTR
) &som_section_data (subsection
)->subspace_dict
,
3005 sizeof (struct subspace_dictionary_record
), 1, abfd
)
3006 != sizeof (struct subspace_dictionary_record
))
3008 bfd_set_error (bfd_error_system_call
);
3012 /* Goto the next section. */
3013 section
= section
->next
;
3016 /* Now repeat the process for unloadable subspaces. */
3017 section
= abfd
->sections
;
3018 /* Now for each space write out records for its subspaces. */
3019 for (i
= 0; i
< num_spaces
; i
++)
3021 asection
*subsection
;
3024 while (som_section_data (section
)->is_space
== 0)
3025 section
= section
->next
;
3027 /* Now look for all its subspaces. */
3028 for (subsection
= abfd
->sections
;
3030 subsection
= subsection
->next
)
3033 /* Skip any section which does not correspond to a space or
3034 subspace, or which SEC_ALLOC set (and therefore handled
3035 in the loadable spaces/subspaces code above. */
3037 if (som_section_data (subsection
)->is_subspace
== 0
3038 || som_section_data (subsection
)->containing_space
!= section
3039 || (subsection
->flags
& SEC_ALLOC
) != 0)
3042 /* If this is the first subspace for this space, then save
3043 the index of the subspace in its containing space. Clear
3046 if (som_section_data (section
)->space_dict
.subspace_quantity
== 0)
3048 som_section_data (section
)->space_dict
.is_loadable
= 0;
3049 som_section_data (section
)->space_dict
.subspace_index
3053 /* Increment the number of subspaces seen and the number of
3054 subspaces contained within the current space. */
3055 som_section_data (section
)->space_dict
.subspace_quantity
++;
3058 /* Mark the index of the current space within the subspace's
3059 dictionary record. */
3060 som_section_data (subsection
)->subspace_dict
.space_index
= i
;
3062 /* Dump this subspace header. */
3063 if (bfd_write ((PTR
) &som_section_data (subsection
)->subspace_dict
,
3064 sizeof (struct subspace_dictionary_record
), 1, abfd
)
3065 != sizeof (struct subspace_dictionary_record
))
3067 bfd_set_error (bfd_error_system_call
);
3071 /* Goto the next section. */
3072 section
= section
->next
;
3075 /* All the subspace dictiondary records are written, and all the
3076 fields are set up in the space dictionary records.
3078 Seek to the right location and start writing the space
3079 dictionary records. */
3080 location
= obj_som_file_hdr (abfd
)->space_location
;
3081 bfd_seek (abfd
, location
, SEEK_SET
);
3083 section
= abfd
->sections
;
3084 for (i
= 0; i
< num_spaces
; i
++)
3088 while (som_section_data (section
)->is_space
== 0)
3089 section
= section
->next
;
3091 /* Dump its header */
3092 if (bfd_write ((PTR
) &som_section_data (section
)->space_dict
,
3093 sizeof (struct space_dictionary_record
), 1, abfd
)
3094 != sizeof (struct space_dictionary_record
))
3096 bfd_set_error (bfd_error_system_call
);
3100 /* Goto the next section. */
3101 section
= section
->next
;
3104 /* Only thing left to do is write out the file header. It is always
3105 at location zero. Seek there and write it. */
3106 bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
);
3107 if (bfd_write ((PTR
) obj_som_file_hdr (abfd
),
3108 sizeof (struct header
), 1, abfd
)
3109 != sizeof (struct header
))
3111 bfd_set_error (bfd_error_system_call
);
3117 /* Compute and return the checksum for a SOM file header. */
3119 static unsigned long
3120 som_compute_checksum (abfd
)
3123 unsigned long checksum
, count
, i
;
3124 unsigned long *buffer
= (unsigned long *) obj_som_file_hdr (abfd
);
3127 count
= sizeof (struct header
) / sizeof (unsigned long);
3128 for (i
= 0; i
< count
; i
++)
3129 checksum
^= *(buffer
+ i
);
3135 som_bfd_derive_misc_symbol_info (abfd
, sym
, info
)
3138 struct som_misc_symbol_info
*info
;
3141 memset (info
, 0, sizeof (struct som_misc_symbol_info
));
3143 /* The HP SOM linker requires detailed type information about
3144 all symbols (including undefined symbols!). Unfortunately,
3145 the type specified in an import/export statement does not
3146 always match what the linker wants. Severe braindamage. */
3148 /* Section symbols will not have a SOM symbol type assigned to
3149 them yet. Assign all section symbols type ST_DATA. */
3150 if (sym
->flags
& BSF_SECTION_SYM
)
3151 info
->symbol_type
= ST_DATA
;
3154 /* Common symbols must have scope SS_UNSAT and type
3155 ST_STORAGE or the linker will choke. */
3156 if (sym
->section
== &bfd_com_section
)
3158 info
->symbol_scope
= SS_UNSAT
;
3159 info
->symbol_type
= ST_STORAGE
;
3162 /* It is possible to have a symbol without an associated
3163 type. This happens if the user imported the symbol
3164 without a type and the symbol was never defined
3165 locally. If BSF_FUNCTION is set for this symbol, then
3166 assign it type ST_CODE (the HP linker requires undefined
3167 external functions to have type ST_CODE rather than ST_ENTRY). */
3168 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
3169 && sym
->section
== &bfd_und_section
3170 && sym
->flags
& BSF_FUNCTION
)
3171 info
->symbol_type
= ST_CODE
;
3173 /* Handle function symbols which were defined in this file.
3174 They should have type ST_ENTRY. Also retrieve the argument
3175 relocation bits from the SOM backend information. */
3176 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_ENTRY
3177 || (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
3178 && (sym
->flags
& BSF_FUNCTION
))
3179 || (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
3180 && (sym
->flags
& BSF_FUNCTION
)))
3182 info
->symbol_type
= ST_ENTRY
;
3183 info
->arg_reloc
= som_symbol_data (sym
)->tc_data
.hppa_arg_reloc
;
3186 /* If the type is unknown at this point, it should be
3187 ST_DATA (functions were handled as special cases above). */
3188 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
)
3189 info
->symbol_type
= ST_DATA
;
3191 /* From now on it's a very simple mapping. */
3192 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_ABSOLUTE
)
3193 info
->symbol_type
= ST_ABSOLUTE
;
3194 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
)
3195 info
->symbol_type
= ST_CODE
;
3196 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_DATA
)
3197 info
->symbol_type
= ST_DATA
;
3198 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_MILLICODE
)
3199 info
->symbol_type
= ST_MILLICODE
;
3200 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_PLABEL
)
3201 info
->symbol_type
= ST_PLABEL
;
3202 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_PRI_PROG
)
3203 info
->symbol_type
= ST_PRI_PROG
;
3204 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_SEC_PROG
)
3205 info
->symbol_type
= ST_SEC_PROG
;
3208 /* Now handle the symbol's scope. Exported data which is not
3209 in the common section has scope SS_UNIVERSAL. Note scope
3210 of common symbols was handled earlier! */
3211 if (sym
->flags
& BSF_EXPORT
&& sym
->section
!= &bfd_com_section
)
3212 info
->symbol_scope
= SS_UNIVERSAL
;
3213 /* Any undefined symbol at this point has a scope SS_UNSAT. */
3214 else if (sym
->section
== &bfd_und_section
)
3215 info
->symbol_scope
= SS_UNSAT
;
3216 /* Anything else which is not in the common section has scope
3218 else if (sym
->section
!= &bfd_com_section
)
3219 info
->symbol_scope
= SS_LOCAL
;
3221 /* Now set the symbol_info field. It has no real meaning
3222 for undefined or common symbols, but the HP linker will
3223 choke if it's not set to some "reasonable" value. We
3224 use zero as a reasonable value. */
3225 if (sym
->section
== &bfd_com_section
|| sym
->section
== &bfd_und_section
3226 || sym
->section
== &bfd_abs_section
)
3227 info
->symbol_info
= 0;
3228 /* For all other symbols, the symbol_info field contains the
3229 subspace index of the space this symbol is contained in. */
3231 info
->symbol_info
= som_section_data (sym
->section
)->subspace_index
;
3233 /* Set the symbol's value. */
3234 info
->symbol_value
= sym
->value
+ sym
->section
->vma
;
3237 /* Build and write, in one big chunk, the entire symbol table for
3241 som_build_and_write_symbol_table (abfd
)
3244 unsigned int num_syms
= bfd_get_symcount (abfd
);
3245 file_ptr symtab_location
= obj_som_file_hdr (abfd
)->symbol_location
;
3246 asymbol
**bfd_syms
= bfd_get_outsymbols (abfd
);
3247 struct symbol_dictionary_record
*som_symtab
= NULL
;
3250 /* Compute total symbol table size and allocate a chunk of memory
3251 to hold the symbol table as we build it. */
3252 symtab_size
= num_syms
* sizeof (struct symbol_dictionary_record
);
3253 som_symtab
= (struct symbol_dictionary_record
*) malloc (symtab_size
);
3254 if (som_symtab
== NULL
)
3256 bfd_set_error (bfd_error_no_memory
);
3259 memset (som_symtab
, 0, symtab_size
);
3261 /* Walk over each symbol. */
3262 for (i
= 0; i
< num_syms
; i
++)
3264 struct som_misc_symbol_info info
;
3266 /* This is really an index into the symbol strings table.
3267 By the time we get here, the index has already been
3268 computed and stored into the name field in the BFD symbol. */
3269 som_symtab
[i
].name
.n_strx
= (int) bfd_syms
[i
]->name
;
3271 /* Derive SOM information from the BFD symbol. */
3272 som_bfd_derive_misc_symbol_info (abfd
, bfd_syms
[i
], &info
);
3275 som_symtab
[i
].symbol_type
= info
.symbol_type
;
3276 som_symtab
[i
].symbol_scope
= info
.symbol_scope
;
3277 som_symtab
[i
].arg_reloc
= info
.arg_reloc
;
3278 som_symtab
[i
].symbol_info
= info
.symbol_info
;
3279 som_symtab
[i
].symbol_value
= info
.symbol_value
;
3282 /* Everything is ready, seek to the right location and
3283 scribble out the symbol table. */
3284 if (bfd_seek (abfd
, symtab_location
, SEEK_SET
) != 0)
3286 bfd_set_error (bfd_error_system_call
);
3290 if (bfd_write ((PTR
) som_symtab
, symtab_size
, 1, abfd
) != symtab_size
)
3292 bfd_set_error (bfd_error_system_call
);
3296 if (som_symtab
!= NULL
)
3300 if (som_symtab
!= NULL
)
3305 /* Write an object in SOM format. */
3308 som_write_object_contents (abfd
)
3311 if (abfd
->output_has_begun
== false)
3313 /* Set up fixed parts of the file, space, and subspace headers.
3314 Notify the world that output has begun. */
3315 som_prep_headers (abfd
);
3316 abfd
->output_has_begun
= true;
3317 /* Start writing the object file. This include all the string
3318 tables, fixup streams, and other portions of the object file. */
3319 som_begin_writing (abfd
);
3322 /* Now that the symbol table information is complete, build and
3323 write the symbol table. */
3324 if (som_build_and_write_symbol_table (abfd
) == false)
3327 /* Compute the checksum for the file header just before writing
3328 the header to disk. */
3329 obj_som_file_hdr (abfd
)->checksum
= som_compute_checksum (abfd
);
3330 return (som_write_headers (abfd
));
3334 /* Read and save the string table associated with the given BFD. */
3337 som_slurp_string_table (abfd
)
3342 /* Use the saved version if its available. */
3343 if (obj_som_stringtab (abfd
) != NULL
)
3346 /* Allocate and read in the string table. */
3347 stringtab
= bfd_zalloc (abfd
, obj_som_stringtab_size (abfd
));
3348 if (stringtab
== NULL
)
3350 bfd_set_error (bfd_error_no_memory
);
3354 if (bfd_seek (abfd
, obj_som_str_filepos (abfd
), SEEK_SET
) < 0)
3356 bfd_set_error (bfd_error_system_call
);
3360 if (bfd_read (stringtab
, obj_som_stringtab_size (abfd
), 1, abfd
)
3361 != obj_som_stringtab_size (abfd
))
3363 bfd_set_error (bfd_error_system_call
);
3367 /* Save our results and return success. */
3368 obj_som_stringtab (abfd
) = stringtab
;
3372 /* Return the amount of data (in bytes) required to hold the symbol
3373 table for this object. */
3376 som_get_symtab_upper_bound (abfd
)
3379 if (!som_slurp_symbol_table (abfd
))
3382 return (bfd_get_symcount (abfd
) + 1) * (sizeof (asymbol
*));
3385 /* Convert from a SOM subspace index to a BFD section. */
3388 som_section_from_subspace_index (abfd
, index
)
3394 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
3395 if (som_section_data (section
)->subspace_index
== index
)
3398 /* Should never happen. */
3402 /* Read and save the symbol table associated with the given BFD. */
3405 som_slurp_symbol_table (abfd
)
3408 int symbol_count
= bfd_get_symcount (abfd
);
3409 int symsize
= sizeof (struct symbol_dictionary_record
);
3411 struct symbol_dictionary_record
*buf
= NULL
, *bufp
, *endbufp
;
3412 som_symbol_type
*sym
, *symbase
;
3414 /* Return saved value if it exists. */
3415 if (obj_som_symtab (abfd
) != NULL
)
3416 goto successful_return
;
3418 /* Special case. This is *not* an error. */
3419 if (symbol_count
== 0)
3420 goto successful_return
;
3422 if (!som_slurp_string_table (abfd
))
3425 stringtab
= obj_som_stringtab (abfd
);
3427 symbase
= (som_symbol_type
*)
3428 bfd_zalloc (abfd
, symbol_count
* sizeof (som_symbol_type
));
3429 if (symbase
== NULL
)
3431 bfd_set_error (bfd_error_no_memory
);
3435 /* Read in the external SOM representation. */
3436 buf
= malloc (symbol_count
* symsize
);
3439 bfd_set_error (bfd_error_no_memory
);
3442 if (bfd_seek (abfd
, obj_som_sym_filepos (abfd
), SEEK_SET
) < 0)
3444 bfd_set_error (bfd_error_system_call
);
3447 if (bfd_read (buf
, symbol_count
* symsize
, 1, abfd
)
3448 != symbol_count
* symsize
)
3450 bfd_set_error (bfd_error_no_symbols
);
3454 /* Iterate over all the symbols and internalize them. */
3455 endbufp
= buf
+ symbol_count
;
3456 for (bufp
= buf
, sym
= symbase
; bufp
< endbufp
; ++bufp
)
3459 /* I don't think we care about these. */
3460 if (bufp
->symbol_type
== ST_SYM_EXT
3461 || bufp
->symbol_type
== ST_ARG_EXT
)
3464 /* Set some private data we care about. */
3465 if (bufp
->symbol_type
== ST_NULL
)
3466 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_UNKNOWN
;
3467 else if (bufp
->symbol_type
== ST_ABSOLUTE
)
3468 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_ABSOLUTE
;
3469 else if (bufp
->symbol_type
== ST_DATA
)
3470 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_DATA
;
3471 else if (bufp
->symbol_type
== ST_CODE
)
3472 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_CODE
;
3473 else if (bufp
->symbol_type
== ST_PRI_PROG
)
3474 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_PRI_PROG
;
3475 else if (bufp
->symbol_type
== ST_SEC_PROG
)
3476 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_SEC_PROG
;
3477 else if (bufp
->symbol_type
== ST_ENTRY
)
3478 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_ENTRY
;
3479 else if (bufp
->symbol_type
== ST_MILLICODE
)
3480 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_MILLICODE
;
3481 else if (bufp
->symbol_type
== ST_PLABEL
)
3482 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_PLABEL
;
3484 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_UNKNOWN
;
3485 som_symbol_data (sym
)->tc_data
.hppa_arg_reloc
= bufp
->arg_reloc
;
3487 /* Some reasonable defaults. */
3488 sym
->symbol
.the_bfd
= abfd
;
3489 sym
->symbol
.name
= bufp
->name
.n_strx
+ stringtab
;
3490 sym
->symbol
.value
= bufp
->symbol_value
;
3491 sym
->symbol
.section
= 0;
3492 sym
->symbol
.flags
= 0;
3494 switch (bufp
->symbol_type
)
3500 sym
->symbol
.flags
|= BSF_FUNCTION
;
3501 sym
->symbol
.value
&= ~0x3;
3506 sym
->symbol
.value
&= ~0x3;
3512 /* Handle scoping and section information. */
3513 switch (bufp
->symbol_scope
)
3515 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
3516 so the section associated with this symbol can't be known. */
3518 if (bufp
->symbol_type
!= ST_STORAGE
)
3519 sym
->symbol
.section
= &bfd_und_section
;
3521 sym
->symbol
.section
= &bfd_com_section
;
3522 sym
->symbol
.flags
|= (BSF_EXPORT
| BSF_GLOBAL
);
3526 if (bufp
->symbol_type
!= ST_STORAGE
)
3527 sym
->symbol
.section
= &bfd_und_section
;
3529 sym
->symbol
.section
= &bfd_com_section
;
3533 sym
->symbol
.flags
|= (BSF_EXPORT
| BSF_GLOBAL
);
3535 = som_section_from_subspace_index (abfd
, bufp
->symbol_info
);
3536 sym
->symbol
.value
-= sym
->symbol
.section
->vma
;
3540 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
3541 Sound dumb? It is. */
3545 sym
->symbol
.flags
|= BSF_LOCAL
;
3547 = som_section_from_subspace_index (abfd
, bufp
->symbol_info
);
3548 sym
->symbol
.value
-= sym
->symbol
.section
->vma
;
3552 /* Mark section symbols and symbols used by the debugger. */
3553 if (!strcmp (sym
->symbol
.name
, "L$0\002"))
3554 sym
->symbol
.flags
|= BSF_SECTION_SYM
;
3555 else if (!strncmp (sym
->symbol
.name
, "L$0", 3))
3556 sym
->symbol
.flags
|= BSF_DEBUGGING
;
3558 /* Note increment at bottom of loop, since we skip some symbols
3559 we can not include it as part of the for statement. */
3563 /* Save our results and return success. */
3564 obj_som_symtab (abfd
) = symbase
;
3576 /* Canonicalize a SOM symbol table. Return the number of entries
3577 in the symbol table. */
3580 som_get_symtab (abfd
, location
)
3585 som_symbol_type
*symbase
;
3587 if (!som_slurp_symbol_table (abfd
))
3590 i
= bfd_get_symcount (abfd
);
3591 symbase
= obj_som_symtab (abfd
);
3593 for (; i
> 0; i
--, location
++, symbase
++)
3594 *location
= &symbase
->symbol
;
3596 /* Final null pointer. */
3598 return (bfd_get_symcount (abfd
));
3601 /* Make a SOM symbol. There is nothing special to do here. */
3604 som_make_empty_symbol (abfd
)
3607 som_symbol_type
*new =
3608 (som_symbol_type
*) bfd_zalloc (abfd
, sizeof (som_symbol_type
));
3611 bfd_set_error (bfd_error_no_memory
);
3614 new->symbol
.the_bfd
= abfd
;
3616 return &new->symbol
;
3619 /* Print symbol information. */
3622 som_print_symbol (ignore_abfd
, afile
, symbol
, how
)
3626 bfd_print_symbol_type how
;
3628 FILE *file
= (FILE *) afile
;
3631 case bfd_print_symbol_name
:
3632 fprintf (file
, "%s", symbol
->name
);
3634 case bfd_print_symbol_more
:
3635 fprintf (file
, "som ");
3636 fprintf_vma (file
, symbol
->value
);
3637 fprintf (file
, " %lx", (long) symbol
->flags
);
3639 case bfd_print_symbol_all
:
3641 CONST
char *section_name
;
3642 section_name
= symbol
->section
? symbol
->section
->name
: "(*none*)";
3643 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
3644 fprintf (file
, " %s\t%s", section_name
, symbol
->name
);
3651 som_bfd_is_local_label (abfd
, sym
)
3655 return (sym
->name
[0] == 'L' && sym
->name
[1] == '$');
3658 /* Count or process variable-length SOM fixup records.
3660 To avoid code duplication we use this code both to compute the number
3661 of relocations requested by a stream, and to internalize the stream.
3663 When computing the number of relocations requested by a stream the
3664 variables rptr, section, and symbols have no meaning.
3666 Return the number of relocations requested by the fixup stream. When
3669 This needs at least two or three more passes to get it cleaned up. */
3672 som_set_reloc_info (fixup
, end
, internal_relocs
, section
, symbols
, just_count
)
3673 unsigned char *fixup
;
3675 arelent
*internal_relocs
;
3680 unsigned int op
, varname
;
3681 unsigned char *end_fixups
= &fixup
[end
];
3682 const struct fixup_format
*fp
;
3684 unsigned char *save_fixup
;
3685 int variables
[26], stack
[20], c
, v
, count
, prev_fixup
, *sp
;
3687 arelent
*rptr
= internal_relocs
;
3688 unsigned int offset
= just_count
? 0 : section
->vma
;
3690 #define var(c) variables[(c) - 'A']
3691 #define push(v) (*sp++ = (v))
3692 #define pop() (*--sp)
3693 #define emptystack() (sp == stack)
3695 som_initialize_reloc_queue (reloc_queue
);
3696 memset (variables
, 0, sizeof (variables
));
3697 memset (stack
, 0, sizeof (stack
));
3702 while (fixup
< end_fixups
)
3705 /* Save pointer to the start of this fixup. We'll use
3706 it later to determine if it is necessary to put this fixup
3710 /* Get the fixup code and its associated format. */
3712 fp
= &som_fixup_formats
[op
];
3714 /* Handle a request for a previous fixup. */
3715 if (*fp
->format
== 'P')
3717 /* Get pointer to the beginning of the prev fixup, move
3718 the repeated fixup to the head of the queue. */
3719 fixup
= reloc_queue
[fp
->D
].reloc
;
3720 som_reloc_queue_fix (reloc_queue
, fp
->D
);
3723 /* Get the fixup code and its associated format. */
3725 fp
= &som_fixup_formats
[op
];
3728 /* If we are not just counting, set some reasonable defaults. */
3731 rptr
->address
= offset
;
3732 rptr
->howto
= &som_hppa_howto_table
[op
];
3734 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
3737 /* Set default input length to 0. Get the opcode class index
3742 /* Get the opcode format. */
3745 /* Process the format string. Parsing happens in two phases,
3746 parse RHS, then assign to LHS. Repeat until no more
3747 characters in the format string. */
3750 /* The variable this pass is going to compute a value for. */
3753 /* Start processing RHS. Continue until a NULL or '=' is found. */
3758 /* If this is a variable, push it on the stack. */
3762 /* If this is a lower case letter, then it represents
3763 additional data from the fixup stream to be pushed onto
3765 else if (islower (c
))
3767 for (v
= 0; c
> 'a'; --c
)
3768 v
= (v
<< 8) | *fixup
++;
3772 /* A decimal constant. Push it on the stack. */
3773 else if (isdigit (c
))
3776 while (isdigit (*cp
))
3777 v
= (v
* 10) + (*cp
++ - '0');
3782 /* An operator. Pop two two values from the stack and
3783 use them as operands to the given operation. Push
3784 the result of the operation back on the stack. */
3806 while (*cp
&& *cp
!= '=');
3808 /* Move over the equal operator. */
3811 /* Pop the RHS off the stack. */
3814 /* Perform the assignment. */
3817 /* Handle side effects. and special 'O' stack cases. */
3820 /* Consume some bytes from the input space. */
3824 /* A symbol to use in the relocation. Make a note
3825 of this if we are not just counting. */
3828 rptr
->sym_ptr_ptr
= &symbols
[c
];
3830 /* Handle the linker expression stack. */
3835 subop
= comp1_opcodes
;
3838 subop
= comp2_opcodes
;
3841 subop
= comp3_opcodes
;
3846 while (*subop
<= (unsigned char) c
)
3855 /* If we used a previous fixup, clean up after it. */
3858 fixup
= save_fixup
+ 1;
3862 else if (fixup
> save_fixup
+ 1)
3863 som_reloc_queue_insert (save_fixup
, fixup
- save_fixup
, reloc_queue
);
3865 /* We do not pass R_DATA_OVERRIDE or R_NO_RELOCATION
3867 if (som_hppa_howto_table
[op
].type
!= R_DATA_OVERRIDE
3868 && som_hppa_howto_table
[op
].type
!= R_NO_RELOCATION
)
3870 /* Done with a single reloction. Loop back to the top. */
3873 rptr
->addend
= var ('V');
3877 /* Now that we've handled a "full" relocation, reset
3879 memset (variables
, 0, sizeof (variables
));
3880 memset (stack
, 0, sizeof (stack
));
3891 /* Read in the relocs (aka fixups in SOM terms) for a section.
3893 som_get_reloc_upper_bound calls this routine with JUST_COUNT
3894 set to true to indicate it only needs a count of the number
3895 of actual relocations. */
3898 som_slurp_reloc_table (abfd
, section
, symbols
, just_count
)
3904 char *external_relocs
;
3905 unsigned int fixup_stream_size
;
3906 arelent
*internal_relocs
;
3907 unsigned int num_relocs
;
3909 fixup_stream_size
= som_section_data (section
)->reloc_size
;
3910 /* If there were no relocations, then there is nothing to do. */
3911 if (section
->reloc_count
== 0)
3914 /* If reloc_count is -1, then the relocation stream has not been
3915 parsed. We must do so now to know how many relocations exist. */
3916 if (section
->reloc_count
== -1)
3918 external_relocs
= (char *) bfd_zalloc (abfd
, fixup_stream_size
);
3919 if (external_relocs
== (char *) NULL
)
3921 bfd_set_error (bfd_error_no_memory
);
3924 /* Read in the external forms. */
3926 obj_som_reloc_filepos (abfd
) + section
->rel_filepos
,
3930 bfd_set_error (bfd_error_system_call
);
3933 if (bfd_read (external_relocs
, 1, fixup_stream_size
, abfd
)
3934 != fixup_stream_size
)
3936 bfd_set_error (bfd_error_system_call
);
3939 /* Let callers know how many relocations found.
3940 also save the relocation stream as we will
3942 section
->reloc_count
= som_set_reloc_info (external_relocs
,
3944 NULL
, NULL
, NULL
, true);
3946 som_section_data (section
)->reloc_stream
= external_relocs
;
3949 /* If the caller only wanted a count, then return now. */
3953 num_relocs
= section
->reloc_count
;
3954 external_relocs
= som_section_data (section
)->reloc_stream
;
3955 /* Return saved information about the relocations if it is available. */
3956 if (section
->relocation
!= (arelent
*) NULL
)
3959 internal_relocs
= (arelent
*) bfd_zalloc (abfd
,
3960 num_relocs
* sizeof (arelent
));
3961 if (internal_relocs
== (arelent
*) NULL
)
3963 bfd_set_error (bfd_error_no_memory
);
3967 /* Process and internalize the relocations. */
3968 som_set_reloc_info (external_relocs
, fixup_stream_size
,
3969 internal_relocs
, section
, symbols
, false);
3971 /* Save our results and return success. */
3972 section
->relocation
= internal_relocs
;
3976 /* Return the number of bytes required to store the relocation
3977 information associated with the given section. */
3980 som_get_reloc_upper_bound (abfd
, asect
)
3984 /* If section has relocations, then read in the relocation stream
3985 and parse it to determine how many relocations exist. */
3986 if (asect
->flags
& SEC_RELOC
)
3988 if (som_slurp_reloc_table (abfd
, asect
, NULL
, true))
3989 return (asect
->reloc_count
+ 1) * sizeof (arelent
);
3991 /* Either there are no relocations or an error occurred while
3992 reading and parsing the relocation stream. */
3996 /* Convert relocations from SOM (external) form into BFD internal
3997 form. Return the number of relocations. */
4000 som_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
4009 if (som_slurp_reloc_table (abfd
, section
, symbols
, false) == false)
4012 count
= section
->reloc_count
;
4013 tblptr
= section
->relocation
;
4014 if (tblptr
== (arelent
*) NULL
)
4018 *relptr
++ = tblptr
++;
4020 *relptr
= (arelent
*) NULL
;
4021 return section
->reloc_count
;
4024 extern bfd_target som_vec
;
4026 /* A hook to set up object file dependent section information. */
4029 som_new_section_hook (abfd
, newsect
)
4033 newsect
->used_by_bfd
=
4034 (PTR
) bfd_zalloc (abfd
, sizeof (struct som_section_data_struct
));
4035 if (!newsect
->used_by_bfd
)
4037 bfd_set_error (bfd_error_no_memory
);
4040 newsect
->alignment_power
= 3;
4042 /* Initialize the subspace_index field to -1 so that it does
4043 not match a subspace with an index of 0. */
4044 som_section_data (newsect
)->subspace_index
= -1;
4046 /* We allow more than three sections internally */
4050 /* Copy any private info we understand from the input section
4051 to the output section. */
4053 som_bfd_copy_private_section_data (ibfd
, isection
, obfd
, osection
)
4059 /* One day we may try to grok other private data. */
4060 if (ibfd
->xvec
->flavour
!= bfd_target_som_flavour
4061 || obfd
->xvec
->flavour
!= bfd_target_som_flavour
)
4064 memcpy (som_section_data (osection
), som_section_data (isection
),
4065 sizeof (struct som_section_data_struct
));
4067 /* Reparent if necessary. */
4068 if (som_section_data (osection
)->containing_space
)
4069 som_section_data (osection
)->containing_space
=
4070 som_section_data (osection
)->containing_space
->output_section
;
4073 /* Set backend info for sections which can not be described
4074 in the BFD data structures. */
4077 bfd_som_set_section_attributes (section
, defined
, private, sort_key
, spnum
)
4081 unsigned int sort_key
;
4084 struct space_dictionary_record
*space_dict
;
4086 som_section_data (section
)->is_space
= 1;
4087 space_dict
= &som_section_data (section
)->space_dict
;
4088 space_dict
->is_defined
= defined
;
4089 space_dict
->is_private
= private;
4090 space_dict
->sort_key
= sort_key
;
4091 space_dict
->space_number
= spnum
;
4094 /* Set backend info for subsections which can not be described
4095 in the BFD data structures. */
4098 bfd_som_set_subsection_attributes (section
, container
, access
,
4101 asection
*container
;
4103 unsigned int sort_key
;
4106 struct subspace_dictionary_record
*subspace_dict
;
4107 som_section_data (section
)->is_subspace
= 1;
4108 subspace_dict
= &som_section_data (section
)->subspace_dict
;
4109 subspace_dict
->access_control_bits
= access
;
4110 subspace_dict
->sort_key
= sort_key
;
4111 subspace_dict
->quadrant
= quadrant
;
4112 som_section_data (section
)->containing_space
= container
;
4115 /* Set the full SOM symbol type. SOM needs far more symbol information
4116 than any other object file format I'm aware of. It is mandatory
4117 to be able to know if a symbol is an entry point, millicode, data,
4118 code, absolute, storage request, or procedure label. If you get
4119 the symbol type wrong your program will not link. */
4122 bfd_som_set_symbol_type (symbol
, type
)
4126 som_symbol_data (symbol
)->som_type
= type
;
4129 /* Attach 64bits of unwind information to a symbol (which hopefully
4130 is a function of some kind!). It would be better to keep this
4131 in the R_ENTRY relocation, but there is not enough space. */
4134 bfd_som_attach_unwind_info (symbol
, unwind_desc
)
4138 som_symbol_data (symbol
)->unwind
= unwind_desc
;
4141 /* Attach an auxiliary header to the BFD backend so that it may be
4142 written into the object file. */
4144 bfd_som_attach_aux_hdr (abfd
, type
, string
)
4149 if (type
== VERSION_AUX_ID
)
4151 int len
= strlen (string
);
4155 pad
= (4 - (len
% 4));
4156 obj_som_version_hdr (abfd
) = (struct user_string_aux_hdr
*)
4157 bfd_zalloc (abfd
, sizeof (struct aux_id
)
4158 + sizeof (unsigned int) + len
+ pad
);
4159 if (!obj_som_version_hdr (abfd
))
4161 bfd_set_error (bfd_error_no_memory
);
4164 obj_som_version_hdr (abfd
)->header_id
.type
= VERSION_AUX_ID
;
4165 obj_som_version_hdr (abfd
)->header_id
.length
= len
+ pad
;
4166 obj_som_version_hdr (abfd
)->header_id
.length
+= sizeof (int);
4167 obj_som_version_hdr (abfd
)->string_length
= len
;
4168 strncpy (obj_som_version_hdr (abfd
)->user_string
, string
, len
);
4170 else if (type
== COPYRIGHT_AUX_ID
)
4172 int len
= strlen (string
);
4176 pad
= (4 - (len
% 4));
4177 obj_som_copyright_hdr (abfd
) = (struct copyright_aux_hdr
*)
4178 bfd_zalloc (abfd
, sizeof (struct aux_id
)
4179 + sizeof (unsigned int) + len
+ pad
);
4180 if (!obj_som_copyright_hdr (abfd
))
4182 bfd_set_error (bfd_error_no_error
);
4185 obj_som_copyright_hdr (abfd
)->header_id
.type
= COPYRIGHT_AUX_ID
;
4186 obj_som_copyright_hdr (abfd
)->header_id
.length
= len
+ pad
;
4187 obj_som_copyright_hdr (abfd
)->header_id
.length
+= sizeof (int);
4188 obj_som_copyright_hdr (abfd
)->string_length
= len
;
4189 strcpy (obj_som_copyright_hdr (abfd
)->copyright
, string
);
4195 som_set_section_contents (abfd
, section
, location
, offset
, count
)
4200 bfd_size_type count
;
4202 if (abfd
->output_has_begun
== false)
4204 /* Set up fixed parts of the file, space, and subspace headers.
4205 Notify the world that output has begun. */
4206 som_prep_headers (abfd
);
4207 abfd
->output_has_begun
= true;
4208 /* Start writing the object file. This include all the string
4209 tables, fixup streams, and other portions of the object file. */
4210 som_begin_writing (abfd
);
4213 /* Only write subspaces which have "real" contents (eg. the contents
4214 are not generated at run time by the OS). */
4215 if (som_section_data (section
)->is_subspace
!= 1
4216 || ((section
->flags
& (SEC_LOAD
| SEC_DEBUGGING
)) == 0))
4219 /* Seek to the proper offset within the object file and write the
4221 offset
+= som_section_data (section
)->subspace_dict
.file_loc_init_value
;
4222 if (bfd_seek (abfd
, offset
, SEEK_SET
) == -1)
4224 bfd_set_error (bfd_error_system_call
);
4228 if (bfd_write ((PTR
) location
, 1, count
, abfd
) != count
)
4230 bfd_set_error (bfd_error_system_call
);
4237 som_set_arch_mach (abfd
, arch
, machine
)
4239 enum bfd_architecture arch
;
4240 unsigned long machine
;
4242 /* Allow any architecture to be supported by the SOM backend */
4243 return bfd_default_set_arch_mach (abfd
, arch
, machine
);
4247 som_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
4248 functionname_ptr
, line_ptr
)
4253 CONST
char **filename_ptr
;
4254 CONST
char **functionname_ptr
;
4255 unsigned int *line_ptr
;
4257 fprintf (stderr
, "som_find_nearest_line unimplemented\n");
4264 som_sizeof_headers (abfd
, reloc
)
4268 fprintf (stderr
, "som_sizeof_headers unimplemented\n");
4274 /* Return the single-character symbol type corresponding to
4275 SOM section S, or '?' for an unknown SOM section. */
4278 som_section_type (s
)
4281 const struct section_to_type
*t
;
4283 for (t
= &stt
[0]; t
->section
; t
++)
4284 if (!strcmp (s
, t
->section
))
4290 som_decode_symclass (symbol
)
4295 if (bfd_is_com_section (symbol
->section
))
4297 if (symbol
->section
== &bfd_und_section
)
4299 if (symbol
->section
== &bfd_ind_section
)
4301 if (!(symbol
->flags
& (BSF_GLOBAL
|BSF_LOCAL
)))
4304 if (symbol
->section
== &bfd_abs_section
)
4306 else if (symbol
->section
)
4307 c
= som_section_type (symbol
->section
->name
);
4310 if (symbol
->flags
& BSF_GLOBAL
)
4315 /* Return information about SOM symbol SYMBOL in RET. */
4318 som_get_symbol_info (ignore_abfd
, symbol
, ret
)
4323 ret
->type
= som_decode_symclass (symbol
);
4324 if (ret
->type
!= 'U')
4325 ret
->value
= symbol
->value
+symbol
->section
->vma
;
4328 ret
->name
= symbol
->name
;
4331 /* Count the number of symbols in the archive symbol table. Necessary
4332 so that we can allocate space for all the carsyms at once. */
4335 som_bfd_count_ar_symbols (abfd
, lst_header
, count
)
4337 struct lst_header
*lst_header
;
4341 unsigned int *hash_table
= NULL
;
4342 file_ptr lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
4345 (unsigned int *) malloc (lst_header
->hash_size
* sizeof (unsigned int));
4346 if (hash_table
== NULL
)
4348 bfd_set_error (bfd_error_no_memory
);
4352 /* Don't forget to initialize the counter! */
4355 /* Read in the hash table. The has table is an array of 32bit file offsets
4356 which point to the hash chains. */
4357 if (bfd_read ((PTR
) hash_table
, lst_header
->hash_size
, 4, abfd
)
4358 != lst_header
->hash_size
* 4)
4360 bfd_set_error (bfd_error_system_call
);
4364 /* Walk each chain counting the number of symbols found on that particular
4366 for (i
= 0; i
< lst_header
->hash_size
; i
++)
4368 struct lst_symbol_record lst_symbol
;
4370 /* An empty chain has zero as it's file offset. */
4371 if (hash_table
[i
] == 0)
4374 /* Seek to the first symbol in this hash chain. */
4375 if (bfd_seek (abfd
, lst_filepos
+ hash_table
[i
], SEEK_SET
) < 0)
4377 bfd_set_error (bfd_error_system_call
);
4381 /* Read in this symbol and update the counter. */
4382 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
4383 != sizeof (lst_symbol
))
4385 bfd_set_error (bfd_error_system_call
);
4390 /* Now iterate through the rest of the symbols on this chain. */
4391 while (lst_symbol
.next_entry
)
4394 /* Seek to the next symbol. */
4395 if (bfd_seek (abfd
, lst_filepos
+ lst_symbol
.next_entry
, SEEK_SET
)
4398 bfd_set_error (bfd_error_system_call
);
4402 /* Read the symbol in and update the counter. */
4403 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
4404 != sizeof (lst_symbol
))
4406 bfd_set_error (bfd_error_system_call
);
4412 if (hash_table
!= NULL
)
4417 if (hash_table
!= NULL
)
4422 /* Fill in the canonical archive symbols (SYMS) from the archive described
4423 by ABFD and LST_HEADER. */
4426 som_bfd_fill_in_ar_symbols (abfd
, lst_header
, syms
)
4428 struct lst_header
*lst_header
;
4431 unsigned int i
, len
;
4432 carsym
*set
= syms
[0];
4433 unsigned int *hash_table
= NULL
;
4434 struct som_entry
*som_dict
= NULL
;
4435 file_ptr lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
4438 (unsigned int *) malloc (lst_header
->hash_size
* sizeof (unsigned int));
4439 if (hash_table
== NULL
)
4441 bfd_set_error (bfd_error_no_memory
);
4446 (struct som_entry
*) malloc (lst_header
->module_count
4447 * sizeof (struct som_entry
));
4448 if (som_dict
== NULL
)
4450 bfd_set_error (bfd_error_no_memory
);
4454 /* Read in the hash table. The has table is an array of 32bit file offsets
4455 which point to the hash chains. */
4456 if (bfd_read ((PTR
) hash_table
, lst_header
->hash_size
, 4, abfd
)
4457 != lst_header
->hash_size
* 4)
4459 bfd_set_error (bfd_error_system_call
);
4463 /* Seek to and read in the SOM dictionary. We will need this to fill
4464 in the carsym's filepos field. */
4465 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->dir_loc
, SEEK_SET
) < 0)
4467 bfd_set_error (bfd_error_system_call
);
4471 if (bfd_read ((PTR
) som_dict
, lst_header
->module_count
,
4472 sizeof (struct som_entry
), abfd
)
4473 != lst_header
->module_count
* sizeof (struct som_entry
))
4475 bfd_set_error (bfd_error_system_call
);
4479 /* Walk each chain filling in the carsyms as we go along. */
4480 for (i
= 0; i
< lst_header
->hash_size
; i
++)
4482 struct lst_symbol_record lst_symbol
;
4484 /* An empty chain has zero as it's file offset. */
4485 if (hash_table
[i
] == 0)
4488 /* Seek to and read the first symbol on the chain. */
4489 if (bfd_seek (abfd
, lst_filepos
+ hash_table
[i
], SEEK_SET
) < 0)
4491 bfd_set_error (bfd_error_system_call
);
4495 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
4496 != sizeof (lst_symbol
))
4498 bfd_set_error (bfd_error_system_call
);
4502 /* Get the name of the symbol, first get the length which is stored
4503 as a 32bit integer just before the symbol.
4505 One might ask why we don't just read in the entire string table
4506 and index into it. Well, according to the SOM ABI the string
4507 index can point *anywhere* in the archive to save space, so just
4508 using the string table would not be safe. */
4509 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->string_loc
4510 + lst_symbol
.name
.n_strx
- 4, SEEK_SET
) < 0)
4512 bfd_set_error (bfd_error_system_call
);
4516 if (bfd_read (&len
, 1, 4, abfd
) != 4)
4518 bfd_set_error (bfd_error_system_call
);
4522 /* Allocate space for the name and null terminate it too. */
4523 set
->name
= bfd_zalloc (abfd
, len
+ 1);
4526 bfd_set_error (bfd_error_no_memory
);
4529 if (bfd_read (set
->name
, 1, len
, abfd
) != len
)
4531 bfd_set_error (bfd_error_system_call
);
4536 /* Fill in the file offset. Note that the "location" field points
4537 to the SOM itself, not the ar_hdr in front of it. */
4538 set
->file_offset
= som_dict
[lst_symbol
.som_index
].location
4539 - sizeof (struct ar_hdr
);
4541 /* Go to the next symbol. */
4544 /* Iterate through the rest of the chain. */
4545 while (lst_symbol
.next_entry
)
4547 /* Seek to the next symbol and read it in. */
4548 if (bfd_seek (abfd
, lst_filepos
+ lst_symbol
.next_entry
, SEEK_SET
)
4551 bfd_set_error (bfd_error_system_call
);
4555 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
4556 != sizeof (lst_symbol
))
4558 bfd_set_error (bfd_error_system_call
);
4562 /* Seek to the name length & string and read them in. */
4563 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->string_loc
4564 + lst_symbol
.name
.n_strx
- 4, SEEK_SET
) < 0)
4566 bfd_set_error (bfd_error_system_call
);
4570 if (bfd_read (&len
, 1, 4, abfd
) != 4)
4572 bfd_set_error (bfd_error_system_call
);
4576 /* Allocate space for the name and null terminate it too. */
4577 set
->name
= bfd_zalloc (abfd
, len
+ 1);
4580 bfd_set_error (bfd_error_no_memory
);
4583 if (bfd_read (set
->name
, 1, len
, abfd
) != len
)
4585 bfd_set_error (bfd_error_system_call
);
4590 /* Fill in the file offset. Note that the "location" field points
4591 to the SOM itself, not the ar_hdr in front of it. */
4592 set
->file_offset
= som_dict
[lst_symbol
.som_index
].location
4593 - sizeof (struct ar_hdr
);
4595 /* Go on to the next symbol. */
4599 /* If we haven't died by now, then we successfully read the entire
4600 archive symbol table. */
4601 if (hash_table
!= NULL
)
4603 if (som_dict
!= NULL
)
4608 if (hash_table
!= NULL
)
4610 if (som_dict
!= NULL
)
4615 /* Read in the LST from the archive. */
4617 som_slurp_armap (abfd
)
4620 struct lst_header lst_header
;
4621 struct ar_hdr ar_header
;
4622 unsigned int parsed_size
;
4623 struct artdata
*ardata
= bfd_ardata (abfd
);
4625 int i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
4627 /* Special cases. */
4633 if (bfd_seek (abfd
, (file_ptr
) - 16, SEEK_CUR
) < 0)
4635 bfd_set_error (bfd_error_system_call
);
4639 /* For archives without .o files there is no symbol table. */
4640 if (strncmp (nextname
, "/ ", 16))
4642 bfd_has_map (abfd
) = false;
4646 /* Read in and sanity check the archive header. */
4647 if (bfd_read ((PTR
) &ar_header
, 1, sizeof (struct ar_hdr
), abfd
)
4648 != sizeof (struct ar_hdr
))
4650 bfd_set_error (bfd_error_system_call
);
4654 if (strncmp (ar_header
.ar_fmag
, ARFMAG
, 2))
4656 bfd_set_error (bfd_error_malformed_archive
);
4660 /* How big is the archive symbol table entry? */
4662 parsed_size
= strtol (ar_header
.ar_size
, NULL
, 10);
4665 bfd_set_error (bfd_error_malformed_archive
);
4669 /* Save off the file offset of the first real user data. */
4670 ardata
->first_file_filepos
= bfd_tell (abfd
) + parsed_size
;
4672 /* Read in the library symbol table. We'll make heavy use of this
4673 in just a minute. */
4674 if (bfd_read ((PTR
) & lst_header
, 1, sizeof (struct lst_header
), abfd
)
4675 != sizeof (struct lst_header
))
4677 bfd_set_error (bfd_error_system_call
);
4682 if (lst_header
.a_magic
!= LIBMAGIC
)
4684 bfd_set_error (bfd_error_malformed_archive
);
4688 /* Count the number of symbols in the library symbol table. */
4689 if (som_bfd_count_ar_symbols (abfd
, &lst_header
, &ardata
->symdef_count
)
4693 /* Get back to the start of the library symbol table. */
4694 if (bfd_seek (abfd
, ardata
->first_file_filepos
- parsed_size
4695 + sizeof (struct lst_header
), SEEK_SET
) < 0)
4697 bfd_set_error (bfd_error_system_call
);
4701 /* Initializae the cache and allocate space for the library symbols. */
4703 ardata
->symdefs
= (carsym
*) bfd_alloc (abfd
,
4704 (ardata
->symdef_count
4705 * sizeof (carsym
)));
4706 if (!ardata
->symdefs
)
4708 bfd_set_error (bfd_error_no_memory
);
4712 /* Now fill in the canonical archive symbols. */
4713 if (som_bfd_fill_in_ar_symbols (abfd
, &lst_header
, &ardata
->symdefs
)
4717 /* Notify the generic archive code that we have a symbol map. */
4718 bfd_has_map (abfd
) = true;
4722 /* Begin preparing to write a SOM library symbol table.
4724 As part of the prep work we need to determine the number of symbols
4725 and the size of the associated string section. */
4728 som_bfd_prep_for_ar_write (abfd
, num_syms
, stringsize
)
4730 unsigned int *num_syms
, *stringsize
;
4732 bfd
*curr_bfd
= abfd
->archive_head
;
4734 /* Some initialization. */
4738 /* Iterate over each BFD within this archive. */
4739 while (curr_bfd
!= NULL
)
4741 unsigned int curr_count
, i
;
4742 som_symbol_type
*sym
;
4744 /* Make sure the symbol table has been read, then snag a pointer
4745 to it. It's a little slimey to grab the symbols via obj_som_symtab,
4746 but doing so avoids allocating lots of extra memory. */
4747 if (som_slurp_symbol_table (curr_bfd
) == false)
4750 sym
= obj_som_symtab (curr_bfd
);
4751 curr_count
= bfd_get_symcount (curr_bfd
);
4753 /* Examine each symbol to determine if it belongs in the
4754 library symbol table. */
4755 for (i
= 0; i
< curr_count
; i
++, sym
++)
4757 struct som_misc_symbol_info info
;
4759 /* Derive SOM information from the BFD symbol. */
4760 som_bfd_derive_misc_symbol_info (curr_bfd
, &sym
->symbol
, &info
);
4762 /* Should we include this symbol? */
4763 if (info
.symbol_type
== ST_NULL
4764 || info
.symbol_type
== ST_SYM_EXT
4765 || info
.symbol_type
== ST_ARG_EXT
)
4768 /* Only global symbols and unsatisfied commons. */
4769 if (info
.symbol_scope
!= SS_UNIVERSAL
4770 && info
.symbol_type
!= ST_STORAGE
)
4773 /* Do no include undefined symbols. */
4774 if (sym
->symbol
.section
== &bfd_und_section
)
4777 /* Bump the various counters, being careful to honor
4778 alignment considerations in the string table. */
4780 *stringsize
= *stringsize
+ strlen (sym
->symbol
.name
) + 5;
4781 while (*stringsize
% 4)
4785 curr_bfd
= curr_bfd
->next
;
4790 /* Hash a symbol name based on the hashing algorithm presented in the
4793 som_bfd_ar_symbol_hash (symbol
)
4796 unsigned int len
= strlen (symbol
->name
);
4798 /* Names with length 1 are special. */
4800 return 0x1000100 | (symbol
->name
[0] << 16) | symbol
->name
[0];
4802 return ((len
& 0x7f) << 24) | (symbol
->name
[1] << 16)
4803 | (symbol
->name
[len
-2] << 8) | symbol
->name
[len
-1];
4806 /* Do the bulk of the work required to write the SOM library
4810 som_bfd_ar_write_symbol_stuff (abfd
, nsyms
, string_size
, lst
)
4812 unsigned int nsyms
, string_size
;
4813 struct lst_header lst
;
4815 file_ptr lst_filepos
;
4816 char *strings
= NULL
, *p
;
4817 struct lst_symbol_record
*lst_syms
= NULL
, *curr_lst_sym
;
4818 bfd
*curr_bfd
= abfd
->archive_head
;
4819 unsigned int *hash_table
= NULL
;
4820 struct som_entry
*som_dict
= NULL
;
4821 struct lst_symbol_record
**last_hash_entry
= NULL
;
4822 unsigned int curr_som_offset
, som_index
;
4825 (unsigned int *) malloc (lst
.hash_size
* sizeof (unsigned int));
4826 if (hash_table
== NULL
)
4828 bfd_set_error (bfd_error_no_memory
);
4832 (struct som_entry
*) malloc (lst
.module_count
4833 * sizeof (struct som_entry
));
4834 if (som_dict
== NULL
)
4836 bfd_set_error (bfd_error_no_memory
);
4841 ((struct lst_symbol_record
**)
4842 malloc (lst
.hash_size
* sizeof (struct lst_symbol_record
*)));
4843 if (last_hash_entry
== NULL
)
4845 bfd_set_error (bfd_error_no_memory
);
4849 /* Lots of fields are file positions relative to the start
4850 of the lst record. So save its location. */
4851 lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
4853 /* Some initialization. */
4854 memset (hash_table
, 0, 4 * lst
.hash_size
);
4855 memset (som_dict
, 0, lst
.module_count
* sizeof (struct som_entry
));
4856 memset (last_hash_entry
, 0,
4857 lst
.hash_size
* sizeof (struct lst_symbol_record
*));
4859 /* Symbols have som_index fields, so we have to keep track of the
4860 index of each SOM in the archive.
4862 The SOM dictionary has (among other things) the absolute file
4863 position for the SOM which a particular dictionary entry
4864 describes. We have to compute that information as we iterate
4865 through the SOMs/symbols. */
4867 curr_som_offset
= 8 + 2 * sizeof (struct ar_hdr
) + lst
.file_end
;
4869 /* FIXME should be done with buffers just like everything else... */
4870 lst_syms
= malloc (nsyms
* sizeof (struct lst_symbol_record
));
4871 if (lst_syms
== NULL
)
4873 bfd_set_error (bfd_error_no_memory
);
4876 strings
= malloc (string_size
);
4877 if (strings
== NULL
)
4879 bfd_set_error (bfd_error_no_memory
);
4884 curr_lst_sym
= lst_syms
;
4887 while (curr_bfd
!= NULL
)
4889 unsigned int curr_count
, i
;
4890 som_symbol_type
*sym
;
4892 /* Make sure the symbol table has been read, then snag a pointer
4893 to it. It's a little slimey to grab the symbols via obj_som_symtab,
4894 but doing so avoids allocating lots of extra memory. */
4895 if (som_slurp_symbol_table (curr_bfd
) == false)
4898 sym
= obj_som_symtab (curr_bfd
);
4899 curr_count
= bfd_get_symcount (curr_bfd
);
4901 for (i
= 0; i
< curr_count
; i
++, sym
++)
4903 struct som_misc_symbol_info info
;
4905 /* Derive SOM information from the BFD symbol. */
4906 som_bfd_derive_misc_symbol_info (curr_bfd
, &sym
->symbol
, &info
);
4908 /* Should we include this symbol? */
4909 if (info
.symbol_type
== ST_NULL
4910 || info
.symbol_type
== ST_SYM_EXT
4911 || info
.symbol_type
== ST_ARG_EXT
)
4914 /* Only global symbols and unsatisfied commons. */
4915 if (info
.symbol_scope
!= SS_UNIVERSAL
4916 && info
.symbol_type
!= ST_STORAGE
)
4919 /* Do no include undefined symbols. */
4920 if (sym
->symbol
.section
== &bfd_und_section
)
4923 /* If this is the first symbol from this SOM, then update
4924 the SOM dictionary too. */
4925 if (som_dict
[som_index
].location
== 0)
4927 som_dict
[som_index
].location
= curr_som_offset
;
4928 som_dict
[som_index
].length
= arelt_size (curr_bfd
);
4931 /* Fill in the lst symbol record. */
4932 curr_lst_sym
->hidden
= 0;
4933 curr_lst_sym
->secondary_def
= 0;
4934 curr_lst_sym
->symbol_type
= info
.symbol_type
;
4935 curr_lst_sym
->symbol_scope
= info
.symbol_scope
;
4936 curr_lst_sym
->check_level
= 0;
4937 curr_lst_sym
->must_qualify
= 0;
4938 curr_lst_sym
->initially_frozen
= 0;
4939 curr_lst_sym
->memory_resident
= 0;
4940 curr_lst_sym
->is_common
= (sym
->symbol
.section
== &bfd_com_section
);
4941 curr_lst_sym
->dup_common
= 0;
4942 curr_lst_sym
->xleast
= 0;
4943 curr_lst_sym
->arg_reloc
= info
.arg_reloc
;
4944 curr_lst_sym
->name
.n_strx
= p
- strings
+ 4;
4945 curr_lst_sym
->qualifier_name
.n_strx
= 0;
4946 curr_lst_sym
->symbol_info
= info
.symbol_info
;
4947 curr_lst_sym
->symbol_value
= info
.symbol_value
;
4948 curr_lst_sym
->symbol_descriptor
= 0;
4949 curr_lst_sym
->reserved
= 0;
4950 curr_lst_sym
->som_index
= som_index
;
4951 curr_lst_sym
->symbol_key
= som_bfd_ar_symbol_hash (&sym
->symbol
);
4952 curr_lst_sym
->next_entry
= 0;
4954 /* Insert into the hash table. */
4955 if (hash_table
[curr_lst_sym
->symbol_key
% lst
.hash_size
])
4957 struct lst_symbol_record
*tmp
;
4959 /* There is already something at the head of this hash chain,
4960 so tack this symbol onto the end of the chain. */
4961 tmp
= last_hash_entry
[curr_lst_sym
->symbol_key
% lst
.hash_size
];
4963 = (curr_lst_sym
- lst_syms
) * sizeof (struct lst_symbol_record
)
4965 + lst
.module_count
* sizeof (struct som_entry
)
4966 + sizeof (struct lst_header
);
4970 /* First entry in this hash chain. */
4971 hash_table
[curr_lst_sym
->symbol_key
% lst
.hash_size
]
4972 = (curr_lst_sym
- lst_syms
) * sizeof (struct lst_symbol_record
)
4974 + lst
.module_count
* sizeof (struct som_entry
)
4975 + sizeof (struct lst_header
);
4978 /* Keep track of the last symbol we added to this chain so we can
4979 easily update its next_entry pointer. */
4980 last_hash_entry
[curr_lst_sym
->symbol_key
% lst
.hash_size
]
4984 /* Update the string table. */
4985 bfd_put_32 (abfd
, strlen (sym
->symbol
.name
), p
);
4987 strcpy (p
, sym
->symbol
.name
);
4988 p
+= strlen (sym
->symbol
.name
) + 1;
4991 bfd_put_8 (abfd
, 0, p
);
4995 /* Head to the next symbol. */
4999 /* Keep track of where each SOM will finally reside; then look
5001 curr_som_offset
+= arelt_size (curr_bfd
) + sizeof (struct ar_hdr
);
5002 curr_bfd
= curr_bfd
->next
;
5006 /* Now scribble out the hash table. */
5007 if (bfd_write ((PTR
) hash_table
, lst
.hash_size
, 4, abfd
)
5008 != lst
.hash_size
* 4)
5010 bfd_set_error (bfd_error_system_call
);
5014 /* Then the SOM dictionary. */
5015 if (bfd_write ((PTR
) som_dict
, lst
.module_count
,
5016 sizeof (struct som_entry
), abfd
)
5017 != lst
.module_count
* sizeof (struct som_entry
))
5019 bfd_set_error (bfd_error_system_call
);
5023 /* The library symbols. */
5024 if (bfd_write ((PTR
) lst_syms
, nsyms
, sizeof (struct lst_symbol_record
), abfd
)
5025 != nsyms
* sizeof (struct lst_symbol_record
))
5027 bfd_set_error (bfd_error_system_call
);
5031 /* And finally the strings. */
5032 if (bfd_write ((PTR
) strings
, string_size
, 1, abfd
) != string_size
)
5034 bfd_set_error (bfd_error_system_call
);
5038 if (hash_table
!= NULL
)
5040 if (som_dict
!= NULL
)
5042 if (last_hash_entry
!= NULL
)
5043 free (last_hash_entry
);
5044 if (lst_syms
!= NULL
)
5046 if (strings
!= NULL
)
5051 if (hash_table
!= NULL
)
5053 if (som_dict
!= NULL
)
5055 if (last_hash_entry
!= NULL
)
5056 free (last_hash_entry
);
5057 if (lst_syms
!= NULL
)
5059 if (strings
!= NULL
)
5065 /* Write out the LST for the archive.
5067 You'll never believe this is really how armaps are handled in SOM... */
5070 som_write_armap (abfd
)
5074 struct stat statbuf
;
5075 unsigned int i
, lst_size
, nsyms
, stringsize
;
5077 struct lst_header lst
;
5080 /* We'll use this for the archive's date and mode later. */
5081 if (stat (abfd
->filename
, &statbuf
) != 0)
5083 bfd_set_error (bfd_error_system_call
);
5087 bfd_ardata (abfd
)->armap_timestamp
= statbuf
.st_mtime
+ 60;
5089 /* Account for the lst header first. */
5090 lst_size
= sizeof (struct lst_header
);
5092 /* Start building the LST header. */
5093 lst
.system_id
= HP9000S800_ID
;
5094 lst
.a_magic
= LIBMAGIC
;
5095 lst
.version_id
= VERSION_ID
;
5096 lst
.file_time
.secs
= 0;
5097 lst
.file_time
.nanosecs
= 0;
5099 lst
.hash_loc
= lst_size
;
5100 lst
.hash_size
= SOM_LST_HASH_SIZE
;
5102 /* Hash table is a SOM_LST_HASH_SIZE 32bit offsets. */
5103 lst_size
+= 4 * SOM_LST_HASH_SIZE
;
5105 /* We need to count the number of SOMs in this archive. */
5106 curr_bfd
= abfd
->archive_head
;
5107 lst
.module_count
= 0;
5108 while (curr_bfd
!= NULL
)
5111 curr_bfd
= curr_bfd
->next
;
5113 lst
.module_limit
= lst
.module_count
;
5114 lst
.dir_loc
= lst_size
;
5115 lst_size
+= sizeof (struct som_entry
) * lst
.module_count
;
5117 /* We don't support import/export tables, auxiliary headers,
5118 or free lists yet. Make the linker work a little harder
5119 to make our life easier. */
5122 lst
.export_count
= 0;
5127 /* Count how many symbols we will have on the hash chains and the
5128 size of the associated string table. */
5129 if (som_bfd_prep_for_ar_write (abfd
, &nsyms
, &stringsize
) == false)
5132 lst_size
+= sizeof (struct lst_symbol_record
) * nsyms
;
5134 /* For the string table. One day we might actually use this info
5135 to avoid small seeks/reads when reading archives. */
5136 lst
.string_loc
= lst_size
;
5137 lst
.string_size
= stringsize
;
5138 lst_size
+= stringsize
;
5140 /* SOM ABI says this must be zero. */
5143 lst
.file_end
= lst_size
;
5145 /* Compute the checksum. Must happen after the entire lst header
5148 for (i
= 0; i
< sizeof (struct lst_header
)/sizeof (int) - 1; i
++)
5149 lst
.checksum
^= *p
++;
5151 sprintf (hdr
.ar_name
, "/ ");
5152 sprintf (hdr
.ar_date
, "%ld", bfd_ardata (abfd
)->armap_timestamp
);
5153 sprintf (hdr
.ar_uid
, "%d", getuid ());
5154 sprintf (hdr
.ar_gid
, "%d", getgid ());
5155 sprintf (hdr
.ar_mode
, "%-8o", (unsigned int) statbuf
.st_mode
);
5156 sprintf (hdr
.ar_size
, "%-10d", (int) lst_size
);
5157 hdr
.ar_fmag
[0] = '`';
5158 hdr
.ar_fmag
[1] = '\012';
5160 /* Turn any nulls into spaces. */
5161 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
5162 if (((char *) (&hdr
))[i
] == '\0')
5163 (((char *) (&hdr
))[i
]) = ' ';
5165 /* Scribble out the ar header. */
5166 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
5167 != sizeof (struct ar_hdr
))
5169 bfd_set_error (bfd_error_system_call
);
5173 /* Now scribble out the lst header. */
5174 if (bfd_write ((PTR
) &lst
, 1, sizeof (struct lst_header
), abfd
)
5175 != sizeof (struct lst_header
))
5177 bfd_set_error (bfd_error_system_call
);
5181 /* Build and write the armap. */
5182 if (som_bfd_ar_write_symbol_stuff (abfd
, nsyms
, stringsize
, lst
) == false)
5189 /* Apparently the extened names are never used, even though they appear
5190 in the SOM ABI. Hmmm. */
5192 som_slurp_extended_name_table (abfd
)
5195 bfd_ardata (abfd
)->extended_names
= NULL
;
5199 /* End of miscellaneous support functions. */
5201 #define som_bfd_debug_info_start bfd_void
5202 #define som_bfd_debug_info_end bfd_void
5203 #define som_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
5205 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
5206 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
5207 #define som_truncate_arname bfd_bsd_truncate_arname
5209 #define som_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
5210 #define som_close_and_cleanup bfd_generic_close_and_cleanup
5211 #define som_get_section_contents bfd_generic_get_section_contents
5213 #define som_bfd_get_relocated_section_contents \
5214 bfd_generic_get_relocated_section_contents
5215 #define som_bfd_relax_section bfd_generic_relax_section
5216 #define som_bfd_make_debug_symbol \
5217 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
5218 #define som_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
5219 #define som_bfd_link_add_symbols _bfd_generic_link_add_symbols
5220 #define som_bfd_final_link _bfd_generic_final_link
5222 /* Core file support is in the hpux-core backend. */
5223 #define som_core_file_failing_command _bfd_dummy_core_file_failing_command
5224 #define som_core_file_failing_signal _bfd_dummy_core_file_failing_signal
5225 #define som_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
5227 #define som_bfd_copy_private_bfd_data \
5228 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
5230 bfd_target som_vec
=
5233 bfd_target_som_flavour
,
5234 true, /* target byte order */
5235 true, /* target headers byte order */
5236 (HAS_RELOC
| EXEC_P
| /* object flags */
5237 HAS_LINENO
| HAS_DEBUG
|
5238 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
5239 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
5240 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
5242 /* leading_symbol_char: is the first char of a user symbol
5243 predictable, and if so what is it */
5245 '/', /* ar_pad_char */
5246 16, /* ar_max_namelen */
5247 3, /* minimum alignment */
5248 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
5249 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
5250 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
5251 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
5252 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
5253 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
5255 som_object_p
, /* bfd_check_format */
5256 bfd_generic_archive_p
,
5262 _bfd_generic_mkarchive
,
5267 som_write_object_contents
,
5268 _bfd_write_archive_contents
,
5276 #endif /* HOST_HPPAHPUX || HOST_HPPABSD || HOST_HPPAOSF */