1 /* bfd back-end for HP PA-RISC SOM objects.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF)
33 #include <sys/param.h>
35 #include <machine/reg.h>
39 /* Magic not defined in standard HP-UX header files until 8.0 */
41 #ifndef CPU_PA_RISC1_0
42 #define CPU_PA_RISC1_0 0x20B
43 #endif /* CPU_PA_RISC1_0 */
45 #ifndef CPU_PA_RISC1_1
46 #define CPU_PA_RISC1_1 0x210
47 #endif /* CPU_PA_RISC1_1 */
49 #ifndef CPU_PA_RISC2_0
50 #define CPU_PA_RISC2_0 0x214
51 #endif /* CPU_PA_RISC2_0 */
53 #ifndef _PA_RISC1_0_ID
54 #define _PA_RISC1_0_ID CPU_PA_RISC1_0
55 #endif /* _PA_RISC1_0_ID */
57 #ifndef _PA_RISC1_1_ID
58 #define _PA_RISC1_1_ID CPU_PA_RISC1_1
59 #endif /* _PA_RISC1_1_ID */
61 #ifndef _PA_RISC2_0_ID
62 #define _PA_RISC2_0_ID CPU_PA_RISC2_0
63 #endif /* _PA_RISC2_0_ID */
65 #ifndef _PA_RISC_MAXID
66 #define _PA_RISC_MAXID 0x2FF
67 #endif /* _PA_RISC_MAXID */
70 #define _PA_RISC_ID(__m_num) \
71 (((__m_num) == _PA_RISC1_0_ID) || \
72 ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
73 #endif /* _PA_RISC_ID */
76 /* HIUX in it's infinite stupidity changed the names for several "well
77 known" constants. Work around such braindamage. Try the HPUX version
78 first, then the HIUX version, and finally provide a default. */
80 #define EXEC_AUX_ID HPUX_AUX_ID
83 #if !defined (EXEC_AUX_ID) && defined (HIUX_AUX_ID)
84 #define EXEC_AUX_ID HIUX_AUX_ID
91 /* Size (in chars) of the temporary buffers used during fixup and string
94 #define SOM_TMP_BUFSIZE 8192
96 /* Size of the hash table in archives. */
97 #define SOM_LST_HASH_SIZE 31
99 /* Max number of SOMs to be found in an archive. */
100 #define SOM_LST_MODULE_LIMIT 1024
102 /* Generic alignment macro. */
103 #define SOM_ALIGN(val, alignment) \
104 (((val) + (alignment) - 1) & ~((alignment) - 1))
106 /* SOM allows any one of the four previous relocations to be reused
107 with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
108 relocations are always a single byte, using a R_PREV_FIXUP instead
109 of some multi-byte relocation makes object files smaller.
111 Note one side effect of using a R_PREV_FIXUP is the relocation that
112 is being repeated moves to the front of the queue. */
115 unsigned char *reloc;
119 /* This fully describes the symbol types which may be attached to
120 an EXPORT or IMPORT directive. Only SOM uses this formation
121 (ELF has no need for it). */
125 SYMBOL_TYPE_ABSOLUTE,
129 SYMBOL_TYPE_MILLICODE,
131 SYMBOL_TYPE_PRI_PROG,
132 SYMBOL_TYPE_SEC_PROG,
135 struct section_to_type
141 /* Assorted symbol information that needs to be derived from the BFD symbol
142 and/or the BFD backend private symbol data. */
143 struct som_misc_symbol_info
145 unsigned int symbol_type;
146 unsigned int symbol_scope;
147 unsigned int arg_reloc;
148 unsigned int symbol_info;
149 unsigned int symbol_value;
152 /* Forward declarations */
154 static boolean som_mkobject PARAMS ((bfd *));
155 static const bfd_target * som_object_setup PARAMS ((bfd *,
157 struct som_exec_auxhdr *));
158 static boolean setup_sections PARAMS ((bfd *, struct header *));
159 static const bfd_target * som_object_p PARAMS ((bfd *));
160 static boolean som_write_object_contents PARAMS ((bfd *));
161 static boolean som_slurp_string_table PARAMS ((bfd *));
162 static unsigned int som_slurp_symbol_table PARAMS ((bfd *));
163 static long som_get_symtab_upper_bound PARAMS ((bfd *));
164 static long som_canonicalize_reloc PARAMS ((bfd *, sec_ptr,
165 arelent **, asymbol **));
166 static long som_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
167 static unsigned int som_set_reloc_info PARAMS ((unsigned char *, unsigned int,
168 arelent *, asection *,
169 asymbol **, boolean));
170 static boolean som_slurp_reloc_table PARAMS ((bfd *, asection *,
171 asymbol **, boolean));
172 static long som_get_symtab PARAMS ((bfd *, asymbol **));
173 static asymbol * som_make_empty_symbol PARAMS ((bfd *));
174 static void som_print_symbol PARAMS ((bfd *, PTR,
175 asymbol *, bfd_print_symbol_type));
176 static boolean som_new_section_hook PARAMS ((bfd *, asection *));
177 static boolean som_bfd_copy_private_symbol_data PARAMS ((bfd *, asymbol *,
179 static boolean som_bfd_copy_private_section_data PARAMS ((bfd *, asection *,
181 static boolean som_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
182 #define som_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
183 #define som_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
184 static boolean som_bfd_is_local_label_name PARAMS ((bfd *, const char *));
185 static boolean som_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
186 file_ptr, bfd_size_type));
187 static boolean som_get_section_contents PARAMS ((bfd *, sec_ptr, PTR,
188 file_ptr, bfd_size_type));
189 static boolean som_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
191 static boolean som_find_nearest_line PARAMS ((bfd *, asection *,
196 static void som_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
197 static asection * bfd_section_from_som_symbol PARAMS ((bfd *,
198 struct symbol_dictionary_record *));
199 static int log2 PARAMS ((unsigned int));
200 static bfd_reloc_status_type hppa_som_reloc PARAMS ((bfd *, arelent *,
204 static void som_initialize_reloc_queue PARAMS ((struct reloc_queue *));
205 static void som_reloc_queue_insert PARAMS ((unsigned char *, unsigned int,
206 struct reloc_queue *));
207 static void som_reloc_queue_fix PARAMS ((struct reloc_queue *, unsigned int));
208 static int som_reloc_queue_find PARAMS ((unsigned char *, unsigned int,
209 struct reloc_queue *));
210 static unsigned char * try_prev_fixup PARAMS ((bfd *, int *, unsigned char *,
212 struct reloc_queue *));
214 static unsigned char * som_reloc_skip PARAMS ((bfd *, unsigned int,
215 unsigned char *, unsigned int *,
216 struct reloc_queue *));
217 static unsigned char * som_reloc_addend PARAMS ((bfd *, int, unsigned char *,
219 struct reloc_queue *));
220 static unsigned char * som_reloc_call PARAMS ((bfd *, unsigned char *,
223 struct reloc_queue *));
224 static unsigned long som_count_spaces PARAMS ((bfd *));
225 static unsigned long som_count_subspaces PARAMS ((bfd *));
226 static int compare_syms PARAMS ((const void *, const void *));
227 static int compare_subspaces PARAMS ((const void *, const void *));
228 static unsigned long som_compute_checksum PARAMS ((bfd *));
229 static boolean som_prep_headers PARAMS ((bfd *));
230 static int som_sizeof_headers PARAMS ((bfd *, boolean));
231 static boolean som_finish_writing PARAMS ((bfd *));
232 static boolean som_build_and_write_symbol_table PARAMS ((bfd *));
233 static void som_prep_for_fixups PARAMS ((bfd *, asymbol **, unsigned long));
234 static boolean som_write_fixups PARAMS ((bfd *, unsigned long, unsigned int *));
235 static boolean som_write_space_strings PARAMS ((bfd *, unsigned long,
237 static boolean som_write_symbol_strings PARAMS ((bfd *, unsigned long,
238 asymbol **, unsigned int,
240 static boolean som_begin_writing PARAMS ((bfd *));
241 static reloc_howto_type * som_bfd_reloc_type_lookup
242 PARAMS ((bfd *, bfd_reloc_code_real_type));
243 static char som_section_type PARAMS ((const char *));
244 static int som_decode_symclass PARAMS ((asymbol *));
245 static boolean som_bfd_count_ar_symbols PARAMS ((bfd *, struct lst_header *,
248 static boolean som_bfd_fill_in_ar_symbols PARAMS ((bfd *, struct lst_header *,
250 static boolean som_slurp_armap PARAMS ((bfd *));
251 static boolean som_write_armap PARAMS ((bfd *, unsigned int, struct orl *,
253 static void som_bfd_derive_misc_symbol_info PARAMS ((bfd *, asymbol *,
254 struct som_misc_symbol_info *));
255 static boolean som_bfd_prep_for_ar_write PARAMS ((bfd *, unsigned int *,
257 static unsigned int som_bfd_ar_symbol_hash PARAMS ((asymbol *));
258 static boolean som_bfd_ar_write_symbol_stuff PARAMS ((bfd *, unsigned int,
262 static boolean som_is_space PARAMS ((asection *));
263 static boolean som_is_subspace PARAMS ((asection *));
264 static boolean som_is_container PARAMS ((asection *, asection *));
265 static boolean som_bfd_free_cached_info PARAMS ((bfd *));
266 static boolean som_bfd_link_split_section PARAMS ((bfd *, asection *));
268 /* Map SOM section names to POSIX/BSD single-character symbol types.
270 This table includes all the standard subspaces as defined in the
271 current "PRO ABI for PA-RISC Systems", $UNWIND$ which for
272 some reason was left out, and sections specific to embedded stabs. */
274 static const struct section_to_type stt[] = {
276 {"$SHLIB_INFO$", 't'},
277 {"$MILLICODE$", 't'},
280 {"$UNWIND_START$", 't'},
284 {"$SHLIB_DATA$", 'd'},
286 {"$SHORTDATA$", 'g'},
291 {"$GDB_STRINGS$", 'N'},
292 {"$GDB_SYMBOLS$", 'N'},
296 /* About the relocation formatting table...
298 There are 256 entries in the table, one for each possible
299 relocation opcode available in SOM. We index the table by
300 the relocation opcode. The names and operations are those
301 defined by a.out_800 (4).
303 Right now this table is only used to count and perform minimal
304 processing on relocation streams so that they can be internalized
305 into BFD and symbolically printed by utilities. To make actual use
306 of them would be much more difficult, BFD's concept of relocations
307 is far too simple to handle SOM relocations. The basic assumption
308 that a relocation can be completely processed independent of other
309 relocations before an object file is written is invalid for SOM.
311 The SOM relocations are meant to be processed as a stream, they
312 specify copying of data from the input section to the output section
313 while possibly modifying the data in some manner. They also can
314 specify that a variable number of zeros or uninitialized data be
315 inserted on in the output segment at the current offset. Some
316 relocations specify that some previous relocation be re-applied at
317 the current location in the input/output sections. And finally a number
318 of relocations have effects on other sections (R_ENTRY, R_EXIT,
319 R_UNWIND_AUX and a variety of others). There isn't even enough room
320 in the BFD relocation data structure to store enough information to
321 perform all the relocations.
323 Each entry in the table has three fields.
325 The first entry is an index into this "class" of relocations. This
326 index can then be used as a variable within the relocation itself.
328 The second field is a format string which actually controls processing
329 of the relocation. It uses a simple postfix machine to do calculations
330 based on variables/constants found in the string and the relocation
333 The third field specifys whether or not this relocation may use
334 a constant (V) from the previous R_DATA_OVERRIDE rather than a constant
335 stored in the instruction.
339 L = input space byte count
340 D = index into class of relocations
341 M = output space byte count
342 N = statement number (unused?)
344 R = parameter relocation bits
346 T = first 32 bits of stack unwind information
347 U = second 32 bits of stack unwind information
348 V = a literal constant (usually used in the next relocation)
349 P = a previous relocation
351 Lower case letters (starting with 'b') refer to following
352 bytes in the relocation stream. 'b' is the next 1 byte,
353 c is the next 2 bytes, d is the next 3 bytes, etc...
354 This is the variable part of the relocation entries that
355 makes our life a living hell.
357 numerical constants are also used in the format string. Note
358 the constants are represented in decimal.
360 '+', "*" and "=" represents the obvious postfix operators.
361 '<' represents a left shift.
365 Parameter Relocation Bits:
369 Previous Relocations: The index field represents which in the queue
370 of 4 previous fixups should be re-applied.
372 Literal Constants: These are generally used to represent addend
373 parts of relocations when these constants are not stored in the
374 fields of the instructions themselves. For example the instruction
375 addil foo-$global$-0x1234 would use an override for "0x1234" rather
376 than storing it into the addil itself. */
384 static const struct fixup_format som_fixup_formats[256] =
386 /* R_NO_RELOCATION */
387 0, "LD1+4*=", /* 0x00 */
388 1, "LD1+4*=", /* 0x01 */
389 2, "LD1+4*=", /* 0x02 */
390 3, "LD1+4*=", /* 0x03 */
391 4, "LD1+4*=", /* 0x04 */
392 5, "LD1+4*=", /* 0x05 */
393 6, "LD1+4*=", /* 0x06 */
394 7, "LD1+4*=", /* 0x07 */
395 8, "LD1+4*=", /* 0x08 */
396 9, "LD1+4*=", /* 0x09 */
397 10, "LD1+4*=", /* 0x0a */
398 11, "LD1+4*=", /* 0x0b */
399 12, "LD1+4*=", /* 0x0c */
400 13, "LD1+4*=", /* 0x0d */
401 14, "LD1+4*=", /* 0x0e */
402 15, "LD1+4*=", /* 0x0f */
403 16, "LD1+4*=", /* 0x10 */
404 17, "LD1+4*=", /* 0x11 */
405 18, "LD1+4*=", /* 0x12 */
406 19, "LD1+4*=", /* 0x13 */
407 20, "LD1+4*=", /* 0x14 */
408 21, "LD1+4*=", /* 0x15 */
409 22, "LD1+4*=", /* 0x16 */
410 23, "LD1+4*=", /* 0x17 */
411 0, "LD8<b+1+4*=", /* 0x18 */
412 1, "LD8<b+1+4*=", /* 0x19 */
413 2, "LD8<b+1+4*=", /* 0x1a */
414 3, "LD8<b+1+4*=", /* 0x1b */
415 0, "LD16<c+1+4*=", /* 0x1c */
416 1, "LD16<c+1+4*=", /* 0x1d */
417 2, "LD16<c+1+4*=", /* 0x1e */
418 0, "Ld1+=", /* 0x1f */
420 0, "Lb1+4*=", /* 0x20 */
421 1, "Ld1+=", /* 0x21 */
423 0, "Lb1+4*=", /* 0x22 */
424 1, "Ld1+=", /* 0x23 */
427 /* R_DATA_ONE_SYMBOL */
428 0, "L4=Sb=", /* 0x25 */
429 1, "L4=Sd=", /* 0x26 */
431 0, "L4=Sb=", /* 0x27 */
432 1, "L4=Sd=", /* 0x28 */
435 /* R_REPEATED_INIT */
436 0, "L4=Mb1+4*=", /* 0x2a */
437 1, "Lb4*=Mb1+L*=", /* 0x2b */
438 2, "Lb4*=Md1+4*=", /* 0x2c */
439 3, "Ld1+=Me1+=", /* 0x2d */
440 /* R_SHORT_PCREL_MODE */
442 /* R_LONG_PCREL_MODE */
445 0, "L4=RD=Sb=", /* 0x30 */
446 1, "L4=RD=Sb=", /* 0x31 */
447 2, "L4=RD=Sb=", /* 0x32 */
448 3, "L4=RD=Sb=", /* 0x33 */
449 4, "L4=RD=Sb=", /* 0x34 */
450 5, "L4=RD=Sb=", /* 0x35 */
451 6, "L4=RD=Sb=", /* 0x36 */
452 7, "L4=RD=Sb=", /* 0x37 */
453 8, "L4=RD=Sb=", /* 0x38 */
454 9, "L4=RD=Sb=", /* 0x39 */
455 0, "L4=RD8<b+=Sb=",/* 0x3a */
456 1, "L4=RD8<b+=Sb=",/* 0x3b */
457 0, "L4=RD8<b+=Sd=",/* 0x3c */
458 1, "L4=RD8<b+=Sd=",/* 0x3d */
463 0, "L4=RD=Sb=", /* 0x40 */
464 1, "L4=RD=Sb=", /* 0x41 */
465 2, "L4=RD=Sb=", /* 0x42 */
466 3, "L4=RD=Sb=", /* 0x43 */
467 4, "L4=RD=Sb=", /* 0x44 */
468 5, "L4=RD=Sb=", /* 0x45 */
469 6, "L4=RD=Sb=", /* 0x46 */
470 7, "L4=RD=Sb=", /* 0x47 */
471 8, "L4=RD=Sb=", /* 0x48 */
472 9, "L4=RD=Sb=", /* 0x49 */
473 0, "L4=RD8<b+=Sb=",/* 0x4a */
474 1, "L4=RD8<b+=Sb=",/* 0x4b */
475 0, "L4=RD8<b+=Sd=",/* 0x4c */
476 1, "L4=RD8<b+=Sd=",/* 0x4d */
481 0, "L4=SD=", /* 0x50 */
482 1, "L4=SD=", /* 0x51 */
483 2, "L4=SD=", /* 0x52 */
484 3, "L4=SD=", /* 0x53 */
485 4, "L4=SD=", /* 0x54 */
486 5, "L4=SD=", /* 0x55 */
487 6, "L4=SD=", /* 0x56 */
488 7, "L4=SD=", /* 0x57 */
489 8, "L4=SD=", /* 0x58 */
490 9, "L4=SD=", /* 0x59 */
491 10, "L4=SD=", /* 0x5a */
492 11, "L4=SD=", /* 0x5b */
493 12, "L4=SD=", /* 0x5c */
494 13, "L4=SD=", /* 0x5d */
495 14, "L4=SD=", /* 0x5e */
496 15, "L4=SD=", /* 0x5f */
497 16, "L4=SD=", /* 0x60 */
498 17, "L4=SD=", /* 0x61 */
499 18, "L4=SD=", /* 0x62 */
500 19, "L4=SD=", /* 0x63 */
501 20, "L4=SD=", /* 0x64 */
502 21, "L4=SD=", /* 0x65 */
503 22, "L4=SD=", /* 0x66 */
504 23, "L4=SD=", /* 0x67 */
505 24, "L4=SD=", /* 0x68 */
506 25, "L4=SD=", /* 0x69 */
507 26, "L4=SD=", /* 0x6a */
508 27, "L4=SD=", /* 0x6b */
509 28, "L4=SD=", /* 0x6c */
510 29, "L4=SD=", /* 0x6d */
511 30, "L4=SD=", /* 0x6e */
512 31, "L4=SD=", /* 0x6f */
513 32, "L4=Sb=", /* 0x70 */
514 33, "L4=Sd=", /* 0x71 */
523 0, "L4=Sb=", /* 0x78 */
524 1, "L4=Sd=", /* 0x79 */
532 /* R_CODE_ONE_SYMBOL */
533 0, "L4=SD=", /* 0x80 */
534 1, "L4=SD=", /* 0x81 */
535 2, "L4=SD=", /* 0x82 */
536 3, "L4=SD=", /* 0x83 */
537 4, "L4=SD=", /* 0x84 */
538 5, "L4=SD=", /* 0x85 */
539 6, "L4=SD=", /* 0x86 */
540 7, "L4=SD=", /* 0x87 */
541 8, "L4=SD=", /* 0x88 */
542 9, "L4=SD=", /* 0x89 */
543 10, "L4=SD=", /* 0x8q */
544 11, "L4=SD=", /* 0x8b */
545 12, "L4=SD=", /* 0x8c */
546 13, "L4=SD=", /* 0x8d */
547 14, "L4=SD=", /* 0x8e */
548 15, "L4=SD=", /* 0x8f */
549 16, "L4=SD=", /* 0x90 */
550 17, "L4=SD=", /* 0x91 */
551 18, "L4=SD=", /* 0x92 */
552 19, "L4=SD=", /* 0x93 */
553 20, "L4=SD=", /* 0x94 */
554 21, "L4=SD=", /* 0x95 */
555 22, "L4=SD=", /* 0x96 */
556 23, "L4=SD=", /* 0x97 */
557 24, "L4=SD=", /* 0x98 */
558 25, "L4=SD=", /* 0x99 */
559 26, "L4=SD=", /* 0x9a */
560 27, "L4=SD=", /* 0x9b */
561 28, "L4=SD=", /* 0x9c */
562 29, "L4=SD=", /* 0x9d */
563 30, "L4=SD=", /* 0x9e */
564 31, "L4=SD=", /* 0x9f */
565 32, "L4=Sb=", /* 0xa0 */
566 33, "L4=Sd=", /* 0xa1 */
581 0, "L4=Sb=", /* 0xae */
582 1, "L4=Sd=", /* 0xaf */
584 0, "L4=Sb=", /* 0xb0 */
585 1, "L4=Sd=", /* 0xb1 */
589 0, "Te=Ue=", /* 0xb3 */
599 1, "Rb4*=", /* 0xb9 */
600 2, "Rd4*=", /* 0xba */
627 /* R_DATA_OVERRIDE */
640 0, "Ob=Sd=", /* 0xd1 */
642 0, "Ob=Ve=", /* 0xd2 */
699 static const int comp1_opcodes[] =
721 static const int comp2_opcodes[] =
730 static const int comp3_opcodes[] =
737 /* These apparently are not in older versions of hpux reloc.h (hpux7). */
739 #define R_DLT_REL 0x78
743 #define R_AUX_UNWIND 0xcf
747 #define R_SEC_STMT 0xd7
750 /* And these first appeared in hpux10. */
751 #ifndef R_SHORT_PCREL_MODE
752 #define R_SHORT_PCREL_MODE 0x3e
755 #ifndef R_LONG_PCREL_MODE
756 #define R_LONG_PCREL_MODE 0x3f
768 #define R_LINETAB 0xda
771 #ifndef R_LINETAB_ESC
772 #define R_LINETAB_ESC 0xdb
775 #ifndef R_LTP_OVERRIDE
776 #define R_LTP_OVERRIDE 0xdc
780 #define R_COMMENT 0xdd
783 static reloc_howto_type som_hppa_howto_table[] =
785 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
786 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
787 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
788 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
789 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
790 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
791 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
792 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
793 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
794 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
795 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
796 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
797 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
798 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
799 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
800 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
801 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
802 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
803 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
804 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
805 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
806 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
807 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
808 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
809 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
810 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
811 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
812 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
813 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
814 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
815 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
816 {R_NO_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_NO_RELOCATION"},
817 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
818 {R_ZEROES, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ZEROES"},
819 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
820 {R_UNINIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_UNINIT"},
821 {R_RELOCATION, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RELOCATION"},
822 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
823 {R_DATA_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_ONE_SYMBOL"},
824 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
825 {R_DATA_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_PLABEL"},
826 {R_SPACE_REF, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_SPACE_REF"},
827 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
828 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
829 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
830 {R_REPEATED_INIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "REPEATED_INIT"},
831 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
832 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
833 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
834 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
835 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
836 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
837 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
838 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
839 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
840 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
841 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
842 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
843 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
844 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
845 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
846 {R_PCREL_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PCREL_CALL"},
847 {R_SHORT_PCREL_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_SHORT_PCREL_MODE"},
848 {R_LONG_PCREL_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LONG_PCREL_MODE"},
849 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
850 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
851 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
852 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
853 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
854 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
855 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
856 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
857 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
858 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
859 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
860 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
861 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
862 {R_ABS_CALL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ABS_CALL"},
863 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
864 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
865 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
866 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
867 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
868 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
869 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
870 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
871 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
872 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
873 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
874 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
875 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
876 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
877 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
878 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
879 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
880 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
881 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
882 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
883 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
884 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
885 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
886 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
887 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
888 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
889 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
890 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
891 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
892 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
893 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
894 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
895 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
896 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
897 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
898 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
899 {R_DP_RELATIVE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DP_RELATIVE"},
900 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
901 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
902 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
903 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
904 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
905 {R_DLT_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DLT_REL"},
906 {R_DLT_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DLT_REL"},
907 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
908 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
909 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
910 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
911 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
912 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
913 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
914 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
915 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
916 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
917 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
918 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
919 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
920 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
921 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
922 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
923 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
924 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
925 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
926 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
927 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
928 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
929 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
930 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
931 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
932 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
933 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
934 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
935 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
936 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
937 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
938 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
939 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
940 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
941 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
942 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
943 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
944 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
945 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
946 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
947 {R_CODE_ONE_SYMBOL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_ONE_SYMBOL"},
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_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
960 {R_MILLI_REL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_MILLI_REL"},
961 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
962 {R_CODE_PLABEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_PLABEL"},
963 {R_BREAKPOINT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BREAKPOINT"},
964 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
965 {R_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ENTRY"},
966 {R_ALT_ENTRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_ALT_ENTRY"},
967 {R_EXIT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_EXIT"},
968 {R_BEGIN_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_TRY"},
969 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
970 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
971 {R_END_TRY, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_TRY"},
972 {R_BEGIN_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_BEGIN_BRTAB"},
973 {R_END_BRTAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_END_BRTAB"},
974 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
975 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
976 {R_STATEMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_STATEMENT"},
977 {R_DATA_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_EXPR"},
978 {R_CODE_EXPR, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_CODE_EXPR"},
979 {R_FSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_FSEL"},
980 {R_LSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LSEL"},
981 {R_RSEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RSEL"},
982 {R_N_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_N_MODE"},
983 {R_S_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_S_MODE"},
984 {R_D_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_D_MODE"},
985 {R_R_MODE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_R_MODE"},
986 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
987 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
988 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
989 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
990 {R_DATA_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_DATA_OVERRIDE"},
991 {R_TRANSLATED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_TRANSLATED"},
992 {R_AUX_UNWIND, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_AUX_UNWIND"},
993 {R_COMP1, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP1"},
994 {R_COMP2, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP2"},
995 {R_COMP3, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMP3"},
996 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
997 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
998 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
999 {R_PREV_FIXUP, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_PREV_FIXUP"},
1000 {R_SEC_STMT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_SEC_STMT"},
1001 {R_N0SEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_N0SEL"},
1002 {R_N1SEL, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_N1SEL"},
1003 {R_LINETAB, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LINETAB"},
1004 {R_LINETAB_ESC, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LINETAB_ESC"},
1005 {R_LTP_OVERRIDE, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_LTP_OVERRIDE"},
1006 {R_COMMENT, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_COMMENT"},
1007 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1008 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1009 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1010 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1011 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1012 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1013 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1014 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1015 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1016 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1017 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1018 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1019 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1020 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1021 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1022 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1023 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1024 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1025 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1026 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1027 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1028 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1029 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1030 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1031 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1032 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1033 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1034 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1035 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1036 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1037 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1038 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1039 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"},
1040 {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"}};
1042 /* Initialize the SOM relocation queue. By definition the queue holds
1043 the last four multibyte fixups. */
1046 som_initialize_reloc_queue (queue)
1047 struct reloc_queue *queue;
1049 queue[0].reloc = NULL;
1051 queue[1].reloc = NULL;
1053 queue[2].reloc = NULL;
1055 queue[3].reloc = NULL;
1059 /* Insert a new relocation into the relocation queue. */
1062 som_reloc_queue_insert (p, size, queue)
1065 struct reloc_queue *queue;
1067 queue[3].reloc = queue[2].reloc;
1068 queue[3].size = queue[2].size;
1069 queue[2].reloc = queue[1].reloc;
1070 queue[2].size = queue[1].size;
1071 queue[1].reloc = queue[0].reloc;
1072 queue[1].size = queue[0].size;
1074 queue[0].size = size;
1077 /* When an entry in the relocation queue is reused, the entry moves
1078 to the front of the queue. */
1081 som_reloc_queue_fix (queue, index)
1082 struct reloc_queue *queue;
1090 unsigned char *tmp1 = queue[0].reloc;
1091 unsigned int tmp2 = queue[0].size;
1092 queue[0].reloc = queue[1].reloc;
1093 queue[0].size = queue[1].size;
1094 queue[1].reloc = tmp1;
1095 queue[1].size = tmp2;
1101 unsigned char *tmp1 = queue[0].reloc;
1102 unsigned int tmp2 = queue[0].size;
1103 queue[0].reloc = queue[2].reloc;
1104 queue[0].size = queue[2].size;
1105 queue[2].reloc = queue[1].reloc;
1106 queue[2].size = queue[1].size;
1107 queue[1].reloc = tmp1;
1108 queue[1].size = tmp2;
1114 unsigned char *tmp1 = queue[0].reloc;
1115 unsigned int tmp2 = queue[0].size;
1116 queue[0].reloc = queue[3].reloc;
1117 queue[0].size = queue[3].size;
1118 queue[3].reloc = queue[2].reloc;
1119 queue[3].size = queue[2].size;
1120 queue[2].reloc = queue[1].reloc;
1121 queue[2].size = queue[1].size;
1122 queue[1].reloc = tmp1;
1123 queue[1].size = tmp2;
1129 /* Search for a particular relocation in the relocation queue. */
1132 som_reloc_queue_find (p, size, queue)
1135 struct reloc_queue *queue;
1137 if (queue[0].reloc && !memcmp (p, queue[0].reloc, size)
1138 && size == queue[0].size)
1140 if (queue[1].reloc && !memcmp (p, queue[1].reloc, size)
1141 && size == queue[1].size)
1143 if (queue[2].reloc && !memcmp (p, queue[2].reloc, size)
1144 && size == queue[2].size)
1146 if (queue[3].reloc && !memcmp (p, queue[3].reloc, size)
1147 && size == queue[3].size)
1152 static unsigned char *
1153 try_prev_fixup (abfd, subspace_reloc_sizep, p, size, queue)
1155 int *subspace_reloc_sizep;
1158 struct reloc_queue *queue;
1160 int queue_index = som_reloc_queue_find (p, size, queue);
1162 if (queue_index != -1)
1164 /* Found this in a previous fixup. Undo the fixup we
1165 just built and use R_PREV_FIXUP instead. We saved
1166 a total of size - 1 bytes in the fixup stream. */
1167 bfd_put_8 (abfd, R_PREV_FIXUP + queue_index, p);
1169 *subspace_reloc_sizep += 1;
1170 som_reloc_queue_fix (queue, queue_index);
1174 som_reloc_queue_insert (p, size, queue);
1175 *subspace_reloc_sizep += size;
1181 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
1182 bytes without any relocation. Update the size of the subspace
1183 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
1184 current pointer into the relocation stream. */
1186 static unsigned char *
1187 som_reloc_skip (abfd, skip, p, subspace_reloc_sizep, queue)
1191 unsigned int *subspace_reloc_sizep;
1192 struct reloc_queue *queue;
1194 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
1195 then R_PREV_FIXUPs to get the difference down to a
1197 if (skip >= 0x1000000)
1200 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
1201 bfd_put_8 (abfd, 0xff, p + 1);
1202 bfd_put_16 (abfd, 0xffff, p + 2);
1203 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1204 while (skip >= 0x1000000)
1207 bfd_put_8 (abfd, R_PREV_FIXUP, p);
1209 *subspace_reloc_sizep += 1;
1210 /* No need to adjust queue here since we are repeating the
1211 most recent fixup. */
1215 /* The difference must be less than 0x1000000. Use one
1216 more R_NO_RELOCATION entry to get to the right difference. */
1217 if ((skip & 3) == 0 && skip <= 0xc0000 && skip > 0)
1219 /* Difference can be handled in a simple single-byte
1220 R_NO_RELOCATION entry. */
1223 bfd_put_8 (abfd, R_NO_RELOCATION + (skip >> 2) - 1, p);
1224 *subspace_reloc_sizep += 1;
1227 /* Handle it with a two byte R_NO_RELOCATION entry. */
1228 else if (skip <= 0x1000)
1230 bfd_put_8 (abfd, R_NO_RELOCATION + 24 + (((skip >> 2) - 1) >> 8), p);
1231 bfd_put_8 (abfd, (skip >> 2) - 1, p + 1);
1232 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1234 /* Handle it with a three byte R_NO_RELOCATION entry. */
1237 bfd_put_8 (abfd, R_NO_RELOCATION + 28 + (((skip >> 2) - 1) >> 16), p);
1238 bfd_put_16 (abfd, (skip >> 2) - 1, p + 1);
1239 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1242 /* Ugh. Punt and use a 4 byte entry. */
1245 bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
1246 bfd_put_8 (abfd, (skip - 1) >> 16, p + 1);
1247 bfd_put_16 (abfd, skip - 1, p + 2);
1248 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1253 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
1254 from a BFD relocation. Update the size of the subspace relocation
1255 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
1256 into the relocation stream. */
1258 static unsigned char *
1259 som_reloc_addend (abfd, addend, p, subspace_reloc_sizep, queue)
1263 unsigned int *subspace_reloc_sizep;
1264 struct reloc_queue *queue;
1266 if ((unsigned)(addend) + 0x80 < 0x100)
1268 bfd_put_8 (abfd, R_DATA_OVERRIDE + 1, p);
1269 bfd_put_8 (abfd, addend, p + 1);
1270 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1272 else if ((unsigned) (addend) + 0x8000 < 0x10000)
1274 bfd_put_8 (abfd, R_DATA_OVERRIDE + 2, p);
1275 bfd_put_16 (abfd, addend, p + 1);
1276 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1278 else if ((unsigned) (addend) + 0x800000 < 0x1000000)
1280 bfd_put_8 (abfd, R_DATA_OVERRIDE + 3, p);
1281 bfd_put_8 (abfd, addend >> 16, p + 1);
1282 bfd_put_16 (abfd, addend, p + 2);
1283 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
1287 bfd_put_8 (abfd, R_DATA_OVERRIDE + 4, p);
1288 bfd_put_32 (abfd, addend, p + 1);
1289 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
1294 /* Handle a single function call relocation. */
1296 static unsigned char *
1297 som_reloc_call (abfd, p, subspace_reloc_sizep, bfd_reloc, sym_num, queue)
1300 unsigned int *subspace_reloc_sizep;
1303 struct reloc_queue *queue;
1305 int arg_bits = HPPA_R_ARG_RELOC (bfd_reloc->addend);
1306 int rtn_bits = arg_bits & 0x3;
1309 /* You'll never believe all this is necessary to handle relocations
1310 for function calls. Having to compute and pack the argument
1311 relocation bits is the real nightmare.
1313 If you're interested in how this works, just forget it. You really
1314 do not want to know about this braindamage. */
1316 /* First see if this can be done with a "simple" relocation. Simple
1317 relocations have a symbol number < 0x100 and have simple encodings
1318 of argument relocations. */
1320 if (sym_num < 0x100)
1332 case 1 << 8 | 1 << 6:
1333 case 1 << 8 | 1 << 6 | 1:
1336 case 1 << 8 | 1 << 6 | 1 << 4:
1337 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
1340 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
1341 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
1345 /* Not one of the easy encodings. This will have to be
1346 handled by the more complex code below. */
1352 /* Account for the return value too. */
1356 /* Emit a 2 byte relocation. Then see if it can be handled
1357 with a relocation which is already in the relocation queue. */
1358 bfd_put_8 (abfd, bfd_reloc->howto->type + type, p);
1359 bfd_put_8 (abfd, sym_num, p + 1);
1360 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
1365 /* If this could not be handled with a simple relocation, then do a hard
1366 one. Hard relocations occur if the symbol number was too high or if
1367 the encoding of argument relocation bits is too complex. */
1370 /* Don't ask about these magic sequences. I took them straight
1371 from gas-1.36 which took them from the a.out man page. */
1373 if ((arg_bits >> 6 & 0xf) == 0xe)
1376 type += (3 * (arg_bits >> 8 & 3) + (arg_bits >> 6 & 3)) * 40;
1377 if ((arg_bits >> 2 & 0xf) == 0xe)
1380 type += (3 * (arg_bits >> 4 & 3) + (arg_bits >> 2 & 3)) * 4;
1382 /* Output the first two bytes of the relocation. These describe
1383 the length of the relocation and encoding style. */
1384 bfd_put_8 (abfd, bfd_reloc->howto->type + 10
1385 + 2 * (sym_num >= 0x100) + (type >= 0x100),
1387 bfd_put_8 (abfd, type, p + 1);
1389 /* Now output the symbol index and see if this bizarre relocation
1390 just happened to be in the relocation queue. */
1391 if (sym_num < 0x100)
1393 bfd_put_8 (abfd, sym_num, p + 2);
1394 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
1398 bfd_put_8 (abfd, sym_num >> 16, p + 2);
1399 bfd_put_16 (abfd, sym_num, p + 3);
1400 p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
1407 /* Return the logarithm of X, base 2, considering X unsigned.
1408 Abort -1 if X is not a power or two or is zero. */
1416 /* Test for 0 or a power of 2. */
1417 if (x == 0 || x != (x & -x))
1420 while ((x >>= 1) != 0)
1425 static bfd_reloc_status_type
1426 hppa_som_reloc (abfd, reloc_entry, symbol_in, data,
1427 input_section, output_bfd, error_message)
1429 arelent *reloc_entry;
1432 asection *input_section;
1434 char **error_message;
1438 reloc_entry->address += input_section->output_offset;
1439 return bfd_reloc_ok;
1441 return bfd_reloc_ok;
1444 /* Given a generic HPPA relocation type, the instruction format,
1445 and a field selector, return one or more appropriate SOM relocations. */
1448 hppa_som_gen_reloc_type (abfd, base_type, format, field, sym_diff, sym)
1452 enum hppa_reloc_field_selector_type_alt field;
1456 int *final_type, **final_types;
1458 final_types = (int **) bfd_alloc (abfd, sizeof (int *) * 6);
1459 final_type = (int *) bfd_alloc (abfd, sizeof (int));
1460 if (!final_types || !final_type)
1463 /* The field selector may require additional relocations to be
1464 generated. It's impossible to know at this moment if additional
1465 relocations will be needed, so we make them. The code to actually
1466 write the relocation/fixup stream is responsible for removing
1467 any redundant relocations. */
1474 final_types[0] = final_type;
1475 final_types[1] = NULL;
1476 final_types[2] = NULL;
1477 *final_type = base_type;
1483 final_types[0] = (int *) bfd_alloc (abfd, sizeof (int));
1484 if (!final_types[0])
1486 if (field == e_tsel)
1487 *final_types[0] = R_FSEL;
1488 else if (field == e_ltsel)
1489 *final_types[0] = R_LSEL;
1491 *final_types[0] = R_RSEL;
1492 final_types[1] = final_type;
1493 final_types[2] = NULL;
1494 *final_type = base_type;
1499 final_types[0] = (int *) bfd_alloc (abfd, sizeof (int));
1500 if (!final_types[0])
1502 *final_types[0] = R_S_MODE;
1503 final_types[1] = final_type;
1504 final_types[2] = NULL;
1505 *final_type = base_type;
1510 final_types[0] = (int *) bfd_alloc (abfd, sizeof (int));
1511 if (!final_types[0])
1513 *final_types[0] = R_N_MODE;
1514 final_types[1] = final_type;
1515 final_types[2] = NULL;
1516 *final_type = base_type;
1521 final_types[0] = (int *) bfd_alloc (abfd, sizeof (int));
1522 if (!final_types[0])
1524 *final_types[0] = R_D_MODE;
1525 final_types[1] = final_type;
1526 final_types[2] = NULL;
1527 *final_type = base_type;
1532 final_types[0] = (int *) bfd_alloc (abfd, sizeof (int));
1533 if (!final_types[0])
1535 *final_types[0] = R_R_MODE;
1536 final_types[1] = final_type;
1537 final_types[2] = NULL;
1538 *final_type = base_type;
1542 final_types[0] = (int *) bfd_alloc (abfd, sizeof (int));
1543 if (!final_types[0])
1545 *final_types[0] = R_N1SEL;
1546 final_types[1] = final_type;
1547 final_types[2] = NULL;
1548 *final_type = base_type;
1553 final_types[0] = (int *) bfd_alloc (abfd, sizeof (int));
1554 if (!final_types[0])
1556 *final_types[0] = R_N0SEL;
1557 final_types[1] = (int *) bfd_alloc (abfd, sizeof (int));
1558 if (!final_types[1])
1560 if (field == e_nlsel)
1561 *final_types[1] = R_N_MODE;
1563 *final_types[1] = R_R_MODE;
1564 final_types[2] = final_type;
1565 final_types[3] = NULL;
1566 *final_type = base_type;
1573 /* The difference of two symbols needs *very* special handling. */
1576 final_types[0] = (int *)bfd_alloc (abfd, sizeof (int));
1577 final_types[1] = (int *)bfd_alloc (abfd, sizeof (int));
1578 final_types[2] = (int *)bfd_alloc (abfd, sizeof (int));
1579 final_types[3] = (int *)bfd_alloc (abfd, sizeof (int));
1580 if (!final_types[0] || !final_types[1] || !final_types[2])
1582 if (field == e_fsel)
1583 *final_types[0] = R_FSEL;
1584 else if (field == e_rsel)
1585 *final_types[0] = R_RSEL;
1586 else if (field == e_lsel)
1587 *final_types[0] = R_LSEL;
1588 *final_types[1] = R_COMP2;
1589 *final_types[2] = R_COMP2;
1590 *final_types[3] = R_COMP1;
1591 final_types[4] = final_type;
1593 *final_types[4] = R_DATA_EXPR;
1595 *final_types[4] = R_CODE_EXPR;
1596 final_types[5] = NULL;
1599 /* PLABELs get their own relocation type. */
1600 else if (field == e_psel
1602 || field == e_rpsel)
1604 /* A PLABEL relocation that has a size of 32 bits must
1605 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
1607 *final_type = R_DATA_PLABEL;
1609 *final_type = R_CODE_PLABEL;
1612 else if (field == e_tsel
1614 || field == e_rtsel)
1615 *final_type = R_DLT_REL;
1616 /* A relocation in the data space is always a full 32bits. */
1617 else if (format == 32)
1619 *final_type = R_DATA_ONE_SYMBOL;
1621 /* If there's no SOM symbol type associated with this BFD
1622 symbol, then set the symbol type to ST_DATA.
1624 Only do this if the type is going to default later when
1625 we write the object file.
1627 This is done so that the linker never encounters an
1628 R_DATA_ONE_SYMBOL reloc involving an ST_CODE symbol.
1630 This allows the compiler to generate exception handling
1633 Note that one day we may need to also emit BEGIN_BRTAB and
1634 END_BRTAB to prevent the linker from optimizing away insns
1635 in exception handling regions. */
1636 if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN
1637 && (sym->flags & BSF_SECTION_SYM) == 0
1638 && (sym->flags & BSF_FUNCTION) == 0
1639 && ! bfd_is_com_section (sym->section))
1640 som_symbol_data (sym)->som_type = SYMBOL_TYPE_DATA;
1646 /* More PLABEL special cases. */
1649 || field == e_rpsel)
1650 *final_type = R_DATA_PLABEL;
1653 case R_HPPA_COMPLEX:
1654 /* The difference of two symbols needs *very* special handling. */
1657 final_types[0] = (int *)bfd_alloc (abfd, sizeof (int));
1658 final_types[1] = (int *)bfd_alloc (abfd, sizeof (int));
1659 final_types[2] = (int *)bfd_alloc (abfd, sizeof (int));
1660 final_types[3] = (int *)bfd_alloc (abfd, sizeof (int));
1661 if (!final_types[0] || !final_types[1] || !final_types[2])
1663 if (field == e_fsel)
1664 *final_types[0] = R_FSEL;
1665 else if (field == e_rsel)
1666 *final_types[0] = R_RSEL;
1667 else if (field == e_lsel)
1668 *final_types[0] = R_LSEL;
1669 *final_types[1] = R_COMP2;
1670 *final_types[2] = R_COMP2;
1671 *final_types[3] = R_COMP1;
1672 final_types[4] = final_type;
1674 *final_types[4] = R_DATA_EXPR;
1676 *final_types[4] = R_CODE_EXPR;
1677 final_types[5] = NULL;
1684 case R_HPPA_ABS_CALL:
1685 case R_HPPA_PCREL_CALL:
1686 /* Right now we can default all these. */
1692 /* Return the address of the correct entry in the PA SOM relocation
1696 static reloc_howto_type *
1697 som_bfd_reloc_type_lookup (abfd, code)
1699 bfd_reloc_code_real_type code;
1701 if ((int) code < (int) R_NO_RELOCATION + 255)
1703 BFD_ASSERT ((int) som_hppa_howto_table[(int) code].type == (int) code);
1704 return &som_hppa_howto_table[(int) code];
1707 return (reloc_howto_type *) 0;
1710 /* Perform some initialization for an object. Save results of this
1711 initialization in the BFD. */
1713 static const bfd_target *
1714 som_object_setup (abfd, file_hdrp, aux_hdrp)
1716 struct header *file_hdrp;
1717 struct som_exec_auxhdr *aux_hdrp;
1722 /* som_mkobject will set bfd_error if som_mkobject fails. */
1723 if (som_mkobject (abfd) != true)
1726 /* Set BFD flags based on what information is available in the SOM. */
1727 abfd->flags = BFD_NO_FLAGS;
1728 if (file_hdrp->symbol_total)
1729 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
1731 switch (file_hdrp->a_magic)
1734 abfd->flags |= (D_PAGED | WP_TEXT | EXEC_P);
1737 abfd->flags |= (WP_TEXT | EXEC_P);
1740 abfd->flags |= (EXEC_P);
1743 abfd->flags |= HAS_RELOC;
1751 abfd->flags |= DYNAMIC;
1758 /* Allocate space to hold the saved exec header information. */
1759 obj_som_exec_data (abfd) = (struct som_exec_data *)
1760 bfd_zalloc (abfd, sizeof (struct som_exec_data ));
1761 if (obj_som_exec_data (abfd) == NULL)
1764 /* The braindamaged OSF1 linker switched exec_flags and exec_entry!
1766 We used to identify OSF1 binaries based on NEW_VERSION_ID, but
1767 apparently the latest HPUX linker is using NEW_VERSION_ID now.
1769 It's about time, OSF has used the new id since at least 1992;
1770 HPUX didn't start till nearly 1995!.
1772 The new approach examines the entry field. If it's zero or not 4
1773 byte aligned then it's not a proper code address and we guess it's
1774 really the executable flags. */
1776 for (section = abfd->sections; section; section = section->next)
1778 if ((section->flags & SEC_CODE) == 0)
1780 if (aux_hdrp->exec_entry >= section->vma
1781 && aux_hdrp->exec_entry < section->vma + section->_cooked_size)
1784 if (aux_hdrp->exec_entry == 0
1785 || (aux_hdrp->exec_entry & 0x3) != 0
1788 bfd_get_start_address (abfd) = aux_hdrp->exec_flags;
1789 obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_entry;
1793 bfd_get_start_address (abfd) = aux_hdrp->exec_entry;
1794 obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_flags;
1797 bfd_default_set_arch_mach (abfd, bfd_arch_hppa, pa10);
1798 bfd_get_symcount (abfd) = file_hdrp->symbol_total;
1800 /* Initialize the saved symbol table and string table to NULL.
1801 Save important offsets and sizes from the SOM header into
1803 obj_som_stringtab (abfd) = (char *) NULL;
1804 obj_som_symtab (abfd) = (som_symbol_type *) NULL;
1805 obj_som_sorted_syms (abfd) = NULL;
1806 obj_som_stringtab_size (abfd) = file_hdrp->symbol_strings_size;
1807 obj_som_sym_filepos (abfd) = file_hdrp->symbol_location;
1808 obj_som_str_filepos (abfd) = file_hdrp->symbol_strings_location;
1809 obj_som_reloc_filepos (abfd) = file_hdrp->fixup_request_location;
1810 obj_som_exec_data (abfd)->system_id = file_hdrp->system_id;
1815 /* Convert all of the space and subspace info into BFD sections. Each space
1816 contains a number of subspaces, which in turn describe the mapping between
1817 regions of the exec file, and the address space that the program runs in.
1818 BFD sections which correspond to spaces will overlap the sections for the
1819 associated subspaces. */
1822 setup_sections (abfd, file_hdr)
1824 struct header *file_hdr;
1826 char *space_strings;
1827 unsigned int space_index, i;
1828 unsigned int total_subspaces = 0;
1829 asection **subspace_sections, *section;
1831 /* First, read in space names */
1833 space_strings = bfd_malloc (file_hdr->space_strings_size);
1834 if (!space_strings && file_hdr->space_strings_size != 0)
1837 if (bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET) < 0)
1839 if (bfd_read (space_strings, 1, file_hdr->space_strings_size, abfd)
1840 != file_hdr->space_strings_size)
1843 /* Loop over all of the space dictionaries, building up sections */
1844 for (space_index = 0; space_index < file_hdr->space_total; space_index++)
1846 struct space_dictionary_record space;
1847 struct subspace_dictionary_record subspace, save_subspace;
1849 asection *space_asect;
1852 /* Read the space dictionary element */
1853 if (bfd_seek (abfd, file_hdr->space_location
1854 + space_index * sizeof space, SEEK_SET) < 0)
1856 if (bfd_read (&space, 1, sizeof space, abfd) != sizeof space)
1859 /* Setup the space name string */
1860 space.name.n_name = space.name.n_strx + space_strings;
1862 /* Make a section out of it */
1863 newname = bfd_alloc (abfd, strlen (space.name.n_name) + 1);
1866 strcpy (newname, space.name.n_name);
1868 space_asect = bfd_make_section_anyway (abfd, newname);
1872 if (space.is_loadable == 0)
1873 space_asect->flags |= SEC_DEBUGGING;
1875 /* Set up all the attributes for the space. */
1876 if (bfd_som_set_section_attributes (space_asect, space.is_defined,
1877 space.is_private, space.sort_key,
1878 space.space_number) == false)
1881 /* If the space has no subspaces, then we're done. */
1882 if (space.subspace_quantity == 0)
1885 /* Now, read in the first subspace for this space */
1886 if (bfd_seek (abfd, file_hdr->subspace_location
1887 + space.subspace_index * sizeof subspace,
1890 if (bfd_read (&subspace, 1, sizeof subspace, abfd) != sizeof subspace)
1892 /* Seek back to the start of the subspaces for loop below */
1893 if (bfd_seek (abfd, file_hdr->subspace_location
1894 + space.subspace_index * sizeof subspace,
1898 /* Setup the start address and file loc from the first subspace record */
1899 space_asect->vma = subspace.subspace_start;
1900 space_asect->filepos = subspace.file_loc_init_value;
1901 space_asect->alignment_power = log2 (subspace.alignment);
1902 if (space_asect->alignment_power == -1)
1905 /* Initialize save_subspace so we can reliably determine if this
1906 loop placed any useful values into it. */
1907 memset (&save_subspace, 0, sizeof (struct subspace_dictionary_record));
1909 /* Loop over the rest of the subspaces, building up more sections */
1910 for (subspace_index = 0; subspace_index < space.subspace_quantity;
1913 asection *subspace_asect;
1915 /* Read in the next subspace */
1916 if (bfd_read (&subspace, 1, sizeof subspace, abfd)
1920 /* Setup the subspace name string */
1921 subspace.name.n_name = subspace.name.n_strx + space_strings;
1923 newname = bfd_alloc (abfd, strlen (subspace.name.n_name) + 1);
1926 strcpy (newname, subspace.name.n_name);
1928 /* Make a section out of this subspace */
1929 subspace_asect = bfd_make_section_anyway (abfd, newname);
1930 if (!subspace_asect)
1933 /* Store private information about the section. */
1934 if (bfd_som_set_subsection_attributes (subspace_asect, space_asect,
1935 subspace.access_control_bits,
1937 subspace.quadrant) == false)
1940 /* Keep an easy mapping between subspaces and sections.
1941 Note we do not necessarily read the subspaces in the
1942 same order in which they appear in the object file.
1944 So to make the target index come out correctly, we
1945 store the location of the subspace header in target
1946 index, then sort using the location of the subspace
1947 header as the key. Then we can assign correct
1948 subspace indices. */
1950 subspace_asect->target_index = bfd_tell (abfd) - sizeof (subspace);
1952 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
1953 by the access_control_bits in the subspace header. */
1954 switch (subspace.access_control_bits >> 4)
1956 /* Readonly data. */
1958 subspace_asect->flags |= SEC_DATA | SEC_READONLY;
1963 subspace_asect->flags |= SEC_DATA;
1966 /* Readonly code and the gateways.
1967 Gateways have other attributes which do not map
1968 into anything BFD knows about. */
1974 subspace_asect->flags |= SEC_CODE | SEC_READONLY;
1977 /* dynamic (writable) code. */
1979 subspace_asect->flags |= SEC_CODE;
1983 if (subspace.dup_common || subspace.is_common)
1984 subspace_asect->flags |= SEC_IS_COMMON;
1985 else if (subspace.subspace_length > 0)
1986 subspace_asect->flags |= SEC_HAS_CONTENTS;
1988 if (subspace.is_loadable)
1989 subspace_asect->flags |= SEC_ALLOC | SEC_LOAD;
1991 subspace_asect->flags |= SEC_DEBUGGING;
1993 if (subspace.code_only)
1994 subspace_asect->flags |= SEC_CODE;
1996 /* Both file_loc_init_value and initialization_length will
1997 be zero for a BSS like subspace. */
1998 if (subspace.file_loc_init_value == 0
1999 && subspace.initialization_length == 0)
2000 subspace_asect->flags &= ~(SEC_DATA | SEC_LOAD | SEC_HAS_CONTENTS);
2002 /* This subspace has relocations.
2003 The fixup_request_quantity is a byte count for the number of
2004 entries in the relocation stream; it is not the actual number
2005 of relocations in the subspace. */
2006 if (subspace.fixup_request_quantity != 0)
2008 subspace_asect->flags |= SEC_RELOC;
2009 subspace_asect->rel_filepos = subspace.fixup_request_index;
2010 som_section_data (subspace_asect)->reloc_size
2011 = subspace.fixup_request_quantity;
2012 /* We can not determine this yet. When we read in the
2013 relocation table the correct value will be filled in. */
2014 subspace_asect->reloc_count = -1;
2017 /* Update save_subspace if appropriate. */
2018 if (subspace.file_loc_init_value > save_subspace.file_loc_init_value)
2019 save_subspace = subspace;
2021 subspace_asect->vma = subspace.subspace_start;
2022 subspace_asect->_cooked_size = subspace.subspace_length;
2023 subspace_asect->_raw_size = subspace.subspace_length;
2024 subspace_asect->filepos = subspace.file_loc_init_value;
2025 subspace_asect->alignment_power = log2 (subspace.alignment);
2026 if (subspace_asect->alignment_power == -1)
2030 /* This can happen for a .o which defines symbols in otherwise
2032 if (!save_subspace.file_loc_init_value)
2034 space_asect->_cooked_size = 0;
2035 space_asect->_raw_size = 0;
2039 /* Setup the sizes for the space section based upon the info in the
2040 last subspace of the space. */
2041 space_asect->_cooked_size = (save_subspace.subspace_start
2043 + save_subspace.subspace_length);
2044 space_asect->_raw_size = (save_subspace.file_loc_init_value
2045 - space_asect->filepos
2046 + save_subspace.initialization_length);
2049 /* Now that we've read in all the subspace records, we need to assign
2050 a target index to each subspace. */
2051 subspace_sections = (asection **) bfd_malloc (total_subspaces
2052 * sizeof (asection *));
2053 if (subspace_sections == NULL)
2056 for (i = 0, section = abfd->sections; section; section = section->next)
2058 if (!som_is_subspace (section))
2061 subspace_sections[i] = section;
2064 qsort (subspace_sections, total_subspaces,
2065 sizeof (asection *), compare_subspaces);
2067 /* subspace_sections is now sorted in the order in which the subspaces
2068 appear in the object file. Assign an index to each one now. */
2069 for (i = 0; i < total_subspaces; i++)
2070 subspace_sections[i]->target_index = i;
2072 if (space_strings != NULL)
2073 free (space_strings);
2075 if (subspace_sections != NULL)
2076 free (subspace_sections);
2081 if (space_strings != NULL)
2082 free (space_strings);
2084 if (subspace_sections != NULL)
2085 free (subspace_sections);
2089 /* Read in a SOM object and make it into a BFD. */
2091 static const bfd_target *
2095 struct header file_hdr;
2096 struct som_exec_auxhdr aux_hdr;
2098 if (bfd_read ((PTR) & file_hdr, 1, FILE_HDR_SIZE, abfd) != FILE_HDR_SIZE)
2100 if (bfd_get_error () != bfd_error_system_call)
2101 bfd_set_error (bfd_error_wrong_format);
2105 if (!_PA_RISC_ID (file_hdr.system_id))
2107 bfd_set_error (bfd_error_wrong_format);
2111 switch (file_hdr.a_magic)
2126 #ifdef SHARED_MAGIC_CNX
2127 case SHARED_MAGIC_CNX:
2131 bfd_set_error (bfd_error_wrong_format);
2135 if (file_hdr.version_id != VERSION_ID
2136 && file_hdr.version_id != NEW_VERSION_ID)
2138 bfd_set_error (bfd_error_wrong_format);
2142 /* If the aux_header_size field in the file header is zero, then this
2143 object is an incomplete executable (a .o file). Do not try to read
2144 a non-existant auxiliary header. */
2145 memset (&aux_hdr, 0, sizeof (struct som_exec_auxhdr));
2146 if (file_hdr.aux_header_size != 0)
2148 if (bfd_read ((PTR) & aux_hdr, 1, AUX_HDR_SIZE, abfd) != AUX_HDR_SIZE)
2150 if (bfd_get_error () != bfd_error_system_call)
2151 bfd_set_error (bfd_error_wrong_format);
2156 if (!setup_sections (abfd, &file_hdr))
2158 /* setup_sections does not bubble up a bfd error code. */
2159 bfd_set_error (bfd_error_bad_value);
2163 /* This appears to be a valid SOM object. Do some initialization. */
2164 return som_object_setup (abfd, &file_hdr, &aux_hdr);
2167 /* Create a SOM object. */
2173 /* Allocate memory to hold backend information. */
2174 abfd->tdata.som_data = (struct som_data_struct *)
2175 bfd_zalloc (abfd, sizeof (struct som_data_struct));
2176 if (abfd->tdata.som_data == NULL)
2181 /* Initialize some information in the file header. This routine makes
2182 not attempt at doing the right thing for a full executable; it
2183 is only meant to handle relocatable objects. */
2186 som_prep_headers (abfd)
2189 struct header *file_hdr;
2192 /* Make and attach a file header to the BFD. */
2193 file_hdr = (struct header *) bfd_zalloc (abfd, sizeof (struct header));
2194 if (file_hdr == NULL)
2196 obj_som_file_hdr (abfd) = file_hdr;
2198 if (abfd->flags & (EXEC_P | DYNAMIC))
2201 /* Make and attach an exec header to the BFD. */
2202 obj_som_exec_hdr (abfd) = (struct som_exec_auxhdr *)
2203 bfd_zalloc (abfd, sizeof (struct som_exec_auxhdr));
2204 if (obj_som_exec_hdr (abfd) == NULL)
2207 if (abfd->flags & D_PAGED)
2208 file_hdr->a_magic = DEMAND_MAGIC;
2209 else if (abfd->flags & WP_TEXT)
2210 file_hdr->a_magic = SHARE_MAGIC;
2212 else if (abfd->flags & DYNAMIC)
2213 file_hdr->a_magic = SHL_MAGIC;
2216 file_hdr->a_magic = EXEC_MAGIC;
2219 file_hdr->a_magic = RELOC_MAGIC;
2221 /* Only new format SOM is supported. */
2222 file_hdr->version_id = NEW_VERSION_ID;
2224 /* These fields are optional, and embedding timestamps is not always
2225 a wise thing to do, it makes comparing objects during a multi-stage
2226 bootstrap difficult. */
2227 file_hdr->file_time.secs = 0;
2228 file_hdr->file_time.nanosecs = 0;
2230 file_hdr->entry_space = 0;
2231 file_hdr->entry_subspace = 0;
2232 file_hdr->entry_offset = 0;
2233 file_hdr->presumed_dp = 0;
2235 /* Now iterate over the sections translating information from
2236 BFD sections to SOM spaces/subspaces. */
2238 for (section = abfd->sections; section != NULL; section = section->next)
2240 /* Ignore anything which has not been marked as a space or
2242 if (!som_is_space (section) && !som_is_subspace (section))
2245 if (som_is_space (section))
2247 /* Allocate space for the space dictionary. */
2248 som_section_data (section)->space_dict
2249 = (struct space_dictionary_record *)
2250 bfd_zalloc (abfd, sizeof (struct space_dictionary_record));
2251 if (som_section_data (section)->space_dict == NULL)
2253 /* Set space attributes. Note most attributes of SOM spaces
2254 are set based on the subspaces it contains. */
2255 som_section_data (section)->space_dict->loader_fix_index = -1;
2256 som_section_data (section)->space_dict->init_pointer_index = -1;
2258 /* Set more attributes that were stuffed away in private data. */
2259 som_section_data (section)->space_dict->sort_key =
2260 som_section_data (section)->copy_data->sort_key;
2261 som_section_data (section)->space_dict->is_defined =
2262 som_section_data (section)->copy_data->is_defined;
2263 som_section_data (section)->space_dict->is_private =
2264 som_section_data (section)->copy_data->is_private;
2265 som_section_data (section)->space_dict->space_number =
2266 som_section_data (section)->copy_data->space_number;
2270 /* Allocate space for the subspace dictionary. */
2271 som_section_data (section)->subspace_dict
2272 = (struct subspace_dictionary_record *)
2273 bfd_zalloc (abfd, sizeof (struct subspace_dictionary_record));
2274 if (som_section_data (section)->subspace_dict == NULL)
2277 /* Set subspace attributes. Basic stuff is done here, additional
2278 attributes are filled in later as more information becomes
2280 if (section->flags & SEC_IS_COMMON)
2282 som_section_data (section)->subspace_dict->dup_common = 1;
2283 som_section_data (section)->subspace_dict->is_common = 1;
2286 if (section->flags & SEC_ALLOC)
2287 som_section_data (section)->subspace_dict->is_loadable = 1;
2289 if (section->flags & SEC_CODE)
2290 som_section_data (section)->subspace_dict->code_only = 1;
2292 som_section_data (section)->subspace_dict->subspace_start =
2294 som_section_data (section)->subspace_dict->subspace_length =
2295 bfd_section_size (abfd, section);
2296 som_section_data (section)->subspace_dict->initialization_length =
2297 bfd_section_size (abfd, section);
2298 som_section_data (section)->subspace_dict->alignment =
2299 1 << section->alignment_power;
2301 /* Set more attributes that were stuffed away in private data. */
2302 som_section_data (section)->subspace_dict->sort_key =
2303 som_section_data (section)->copy_data->sort_key;
2304 som_section_data (section)->subspace_dict->access_control_bits =
2305 som_section_data (section)->copy_data->access_control_bits;
2306 som_section_data (section)->subspace_dict->quadrant =
2307 som_section_data (section)->copy_data->quadrant;
2313 /* Return true if the given section is a SOM space, false otherwise. */
2316 som_is_space (section)
2319 /* If no copy data is available, then it's neither a space nor a
2321 if (som_section_data (section)->copy_data == NULL)
2324 /* If the containing space isn't the same as the given section,
2325 then this isn't a space. */
2326 if (som_section_data (section)->copy_data->container != section
2327 && (som_section_data (section)->copy_data->container->output_section
2331 /* OK. Must be a space. */
2335 /* Return true if the given section is a SOM subspace, false otherwise. */
2338 som_is_subspace (section)
2341 /* If no copy data is available, then it's neither a space nor a
2343 if (som_section_data (section)->copy_data == NULL)
2346 /* If the containing space is the same as the given section,
2347 then this isn't a subspace. */
2348 if (som_section_data (section)->copy_data->container == section
2349 || (som_section_data (section)->copy_data->container->output_section
2353 /* OK. Must be a subspace. */
2357 /* Return true if the given space containins the given subspace. It
2358 is safe to assume space really is a space, and subspace really
2362 som_is_container (space, subspace)
2363 asection *space, *subspace;
2365 return (som_section_data (subspace)->copy_data->container == space
2366 || (som_section_data (subspace)->copy_data->container->output_section
2370 /* Count and return the number of spaces attached to the given BFD. */
2372 static unsigned long
2373 som_count_spaces (abfd)
2379 for (section = abfd->sections; section != NULL; section = section->next)
2380 count += som_is_space (section);
2385 /* Count the number of subspaces attached to the given BFD. */
2387 static unsigned long
2388 som_count_subspaces (abfd)
2394 for (section = abfd->sections; section != NULL; section = section->next)
2395 count += som_is_subspace (section);
2400 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
2402 We desire symbols to be ordered starting with the symbol with the
2403 highest relocation count down to the symbol with the lowest relocation
2404 count. Doing so compacts the relocation stream. */
2407 compare_syms (arg1, arg2)
2412 asymbol **sym1 = (asymbol **) arg1;
2413 asymbol **sym2 = (asymbol **) arg2;
2414 unsigned int count1, count2;
2416 /* Get relocation count for each symbol. Note that the count
2417 is stored in the udata pointer for section symbols! */
2418 if ((*sym1)->flags & BSF_SECTION_SYM)
2419 count1 = (*sym1)->udata.i;
2421 count1 = som_symbol_data (*sym1)->reloc_count;
2423 if ((*sym2)->flags & BSF_SECTION_SYM)
2424 count2 = (*sym2)->udata.i;
2426 count2 = som_symbol_data (*sym2)->reloc_count;
2428 /* Return the appropriate value. */
2429 if (count1 < count2)
2431 else if (count1 > count2)
2436 /* Return -1, 0, 1 indicating the relative ordering of subspace1
2440 compare_subspaces (arg1, arg2)
2445 asection **subspace1 = (asection **) arg1;
2446 asection **subspace2 = (asection **) arg2;
2447 unsigned int count1, count2;
2449 if ((*subspace1)->target_index < (*subspace2)->target_index)
2451 else if ((*subspace2)->target_index < (*subspace1)->target_index)
2457 /* Perform various work in preparation for emitting the fixup stream. */
2460 som_prep_for_fixups (abfd, syms, num_syms)
2463 unsigned long num_syms;
2467 asymbol **sorted_syms;
2469 /* Most SOM relocations involving a symbol have a length which is
2470 dependent on the index of the symbol. So symbols which are
2471 used often in relocations should have a small index. */
2473 /* First initialize the counters for each symbol. */
2474 for (i = 0; i < num_syms; i++)
2476 /* Handle a section symbol; these have no pointers back to the
2477 SOM symbol info. So we just use the udata field to hold the
2478 relocation count. */
2479 if (som_symbol_data (syms[i]) == NULL
2480 || syms[i]->flags & BSF_SECTION_SYM)
2482 syms[i]->flags |= BSF_SECTION_SYM;
2483 syms[i]->udata.i = 0;
2486 som_symbol_data (syms[i])->reloc_count = 0;
2489 /* Now that the counters are initialized, make a weighted count
2490 of how often a given symbol is used in a relocation. */
2491 for (section = abfd->sections; section != NULL; section = section->next)
2495 /* Does this section have any relocations? */
2496 if (section->reloc_count <= 0)
2499 /* Walk through each relocation for this section. */
2500 for (i = 1; i < section->reloc_count; i++)
2502 arelent *reloc = section->orelocation[i];
2505 /* A relocation against a symbol in the *ABS* section really
2506 does not have a symbol. Likewise if the symbol isn't associated
2507 with any section. */
2508 if (reloc->sym_ptr_ptr == NULL
2509 || bfd_is_abs_section ((*reloc->sym_ptr_ptr)->section))
2512 /* Scaling to encourage symbols involved in R_DP_RELATIVE
2513 and R_CODE_ONE_SYMBOL relocations to come first. These
2514 two relocations have single byte versions if the symbol
2515 index is very small. */
2516 if (reloc->howto->type == R_DP_RELATIVE
2517 || reloc->howto->type == R_CODE_ONE_SYMBOL)
2522 /* Handle section symbols by storing the count in the udata
2523 field. It will not be used and the count is very important
2524 for these symbols. */
2525 if ((*reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
2527 (*reloc->sym_ptr_ptr)->udata.i =
2528 (*reloc->sym_ptr_ptr)->udata.i + scale;
2532 /* A normal symbol. Increment the count. */
2533 som_symbol_data (*reloc->sym_ptr_ptr)->reloc_count += scale;
2537 /* Sort a copy of the symbol table, rather than the canonical
2538 output symbol table. */
2539 sorted_syms = (asymbol **) bfd_zalloc (abfd, num_syms * sizeof (asymbol *));
2540 memcpy (sorted_syms, syms, num_syms * sizeof (asymbol *));
2541 qsort (sorted_syms, num_syms, sizeof (asymbol *), compare_syms);
2542 obj_som_sorted_syms (abfd) = sorted_syms;
2544 /* Compute the symbol indexes, they will be needed by the relocation
2546 for (i = 0; i < num_syms; i++)
2548 /* A section symbol. Again, there is no pointer to backend symbol
2549 information, so we reuse the udata field again. */
2550 if (sorted_syms[i]->flags & BSF_SECTION_SYM)
2551 sorted_syms[i]->udata.i = i;
2553 som_symbol_data (sorted_syms[i])->index = i;
2558 som_write_fixups (abfd, current_offset, total_reloc_sizep)
2560 unsigned long current_offset;
2561 unsigned int *total_reloc_sizep;
2564 /* Chunk of memory that we can use as buffer space, then throw
2566 unsigned char tmp_space[SOM_TMP_BUFSIZE];
2568 unsigned int total_reloc_size = 0;
2569 unsigned int subspace_reloc_size = 0;
2570 unsigned int num_spaces = obj_som_file_hdr (abfd)->space_total;
2571 asection *section = abfd->sections;
2573 memset (tmp_space, 0, SOM_TMP_BUFSIZE);
2576 /* All the fixups for a particular subspace are emitted in a single
2577 stream. All the subspaces for a particular space are emitted
2580 So, to get all the locations correct one must iterate through all the
2581 spaces, for each space iterate through its subspaces and output a
2583 for (i = 0; i < num_spaces; i++)
2585 asection *subsection;
2588 while (!som_is_space (section))
2589 section = section->next;
2591 /* Now iterate through each of its subspaces. */
2592 for (subsection = abfd->sections;
2594 subsection = subsection->next)
2596 int reloc_offset, current_rounding_mode;
2598 /* Find a subspace of this space. */
2599 if (!som_is_subspace (subsection)
2600 || !som_is_container (section, subsection))
2603 /* If this subspace does not have real data, then we are
2605 if ((subsection->flags & SEC_HAS_CONTENTS) == 0)
2607 som_section_data (subsection)->subspace_dict->fixup_request_index
2612 /* This subspace has some relocations. Put the relocation stream
2613 index into the subspace record. */
2614 som_section_data (subsection)->subspace_dict->fixup_request_index
2617 /* To make life easier start over with a clean slate for
2618 each subspace. Seek to the start of the relocation stream
2619 for this subspace in preparation for writing out its fixup
2621 if (bfd_seek (abfd, current_offset + total_reloc_size, SEEK_SET) < 0)
2624 /* Buffer space has already been allocated. Just perform some
2625 initialization here. */
2627 subspace_reloc_size = 0;
2629 som_initialize_reloc_queue (reloc_queue);
2630 current_rounding_mode = R_N_MODE;
2632 /* Translate each BFD relocation into one or more SOM
2634 for (j = 0; j < subsection->reloc_count; j++)
2636 arelent *bfd_reloc = subsection->orelocation[j];
2640 /* Get the symbol number. Remember it's stored in a
2641 special place for section symbols. */
2642 if ((*bfd_reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
2643 sym_num = (*bfd_reloc->sym_ptr_ptr)->udata.i;
2645 sym_num = som_symbol_data (*bfd_reloc->sym_ptr_ptr)->index;
2647 /* If there is not enough room for the next couple relocations,
2648 then dump the current buffer contents now. Also reinitialize
2649 the relocation queue.
2651 No single BFD relocation could ever translate into more
2652 than 100 bytes of SOM relocations (20bytes is probably the
2653 upper limit, but leave lots of space for growth). */
2654 if (p - tmp_space + 100 > SOM_TMP_BUFSIZE)
2656 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2661 som_initialize_reloc_queue (reloc_queue);
2664 /* Emit R_NO_RELOCATION fixups to map any bytes which were
2666 skip = bfd_reloc->address - reloc_offset;
2667 p = som_reloc_skip (abfd, skip, p,
2668 &subspace_reloc_size, reloc_queue);
2670 /* Update reloc_offset for the next iteration.
2672 Many relocations do not consume input bytes. They
2673 are markers, or set state necessary to perform some
2674 later relocation. */
2675 switch (bfd_reloc->howto->type)
2695 reloc_offset = bfd_reloc->address;
2699 reloc_offset = bfd_reloc->address + 4;
2703 /* Now the actual relocation we care about. */
2704 switch (bfd_reloc->howto->type)
2708 p = som_reloc_call (abfd, p, &subspace_reloc_size,
2709 bfd_reloc, sym_num, reloc_queue);
2712 case R_CODE_ONE_SYMBOL:
2714 /* Account for any addend. */
2715 if (bfd_reloc->addend)
2716 p = som_reloc_addend (abfd, bfd_reloc->addend, p,
2717 &subspace_reloc_size, reloc_queue);
2721 bfd_put_8 (abfd, bfd_reloc->howto->type + sym_num, p);
2722 subspace_reloc_size += 1;
2725 else if (sym_num < 0x100)
2727 bfd_put_8 (abfd, bfd_reloc->howto->type + 32, p);
2728 bfd_put_8 (abfd, sym_num, p + 1);
2729 p = try_prev_fixup (abfd, &subspace_reloc_size, p,
2732 else if (sym_num < 0x10000000)
2734 bfd_put_8 (abfd, bfd_reloc->howto->type + 33, p);
2735 bfd_put_8 (abfd, sym_num >> 16, p + 1);
2736 bfd_put_16 (abfd, sym_num, p + 2);
2737 p = try_prev_fixup (abfd, &subspace_reloc_size,
2744 case R_DATA_ONE_SYMBOL:
2748 /* Account for any addend using R_DATA_OVERRIDE. */
2749 if (bfd_reloc->howto->type != R_DATA_ONE_SYMBOL
2750 && bfd_reloc->addend)
2751 p = som_reloc_addend (abfd, bfd_reloc->addend, p,
2752 &subspace_reloc_size, reloc_queue);
2754 if (sym_num < 0x100)
2756 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2757 bfd_put_8 (abfd, sym_num, p + 1);
2758 p = try_prev_fixup (abfd, &subspace_reloc_size, p,
2761 else if (sym_num < 0x10000000)
2763 bfd_put_8 (abfd, bfd_reloc->howto->type + 1, p);
2764 bfd_put_8 (abfd, sym_num >> 16, p + 1);
2765 bfd_put_16 (abfd, sym_num, p + 2);
2766 p = try_prev_fixup (abfd, &subspace_reloc_size,
2776 arelent *tmp_reloc = NULL;
2777 bfd_put_8 (abfd, R_ENTRY, p);
2779 /* R_ENTRY relocations have 64 bits of associated
2780 data. Unfortunately the addend field of a bfd
2781 relocation is only 32 bits. So, we split up
2782 the 64bit unwind information and store part in
2783 the R_ENTRY relocation, and the rest in the R_EXIT
2785 bfd_put_32 (abfd, bfd_reloc->addend, p + 1);
2787 /* Find the next R_EXIT relocation. */
2788 for (tmp = j; tmp < subsection->reloc_count; tmp++)
2790 tmp_reloc = subsection->orelocation[tmp];
2791 if (tmp_reloc->howto->type == R_EXIT)
2795 if (tmp == subsection->reloc_count)
2798 bfd_put_32 (abfd, tmp_reloc->addend, p + 5);
2799 p = try_prev_fixup (abfd, &subspace_reloc_size,
2808 /* If this relocation requests the current rounding
2809 mode, then it is redundant. */
2810 if (bfd_reloc->howto->type != current_rounding_mode)
2812 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2813 subspace_reloc_size += 1;
2815 current_rounding_mode = bfd_reloc->howto->type;
2829 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2830 subspace_reloc_size += 1;
2835 /* The end of a exception handling region. The reloc's
2836 addend contains the offset of the exception handling
2838 if (bfd_reloc->addend == 0)
2839 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2840 else if (bfd_reloc->addend < 1024)
2842 bfd_put_8 (abfd, bfd_reloc->howto->type + 1, p);
2843 bfd_put_8 (abfd, bfd_reloc->addend / 4, p + 1);
2844 p = try_prev_fixup (abfd, &subspace_reloc_size,
2849 bfd_put_8 (abfd, bfd_reloc->howto->type + 2, p);
2850 bfd_put_8 (abfd, (bfd_reloc->addend / 4) >> 16, p + 1);
2851 bfd_put_16 (abfd, bfd_reloc->addend / 4, p + 2);
2852 p = try_prev_fixup (abfd, &subspace_reloc_size,
2858 /* The only time we generate R_COMP1, R_COMP2 and
2859 R_CODE_EXPR relocs is for the difference of two
2860 symbols. Hence we can cheat here. */
2861 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2862 bfd_put_8 (abfd, 0x44, p + 1);
2863 p = try_prev_fixup (abfd, &subspace_reloc_size,
2868 /* The only time we generate R_COMP1, R_COMP2 and
2869 R_CODE_EXPR relocs is for the difference of two
2870 symbols. Hence we can cheat here. */
2871 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2872 bfd_put_8 (abfd, 0x80, p + 1);
2873 bfd_put_8 (abfd, sym_num >> 16, p + 2);
2874 bfd_put_16 (abfd, sym_num, p + 3);
2875 p = try_prev_fixup (abfd, &subspace_reloc_size,
2881 /* The only time we generate R_COMP1, R_COMP2 and
2882 R_CODE_EXPR relocs is for the difference of two
2883 symbols. Hence we can cheat here. */
2884 bfd_put_8 (abfd, bfd_reloc->howto->type, p);
2885 subspace_reloc_size += 1;
2889 /* Put a "R_RESERVED" relocation in the stream if
2890 we hit something we do not understand. The linker
2891 will complain loudly if this ever happens. */
2893 bfd_put_8 (abfd, 0xff, p);
2894 subspace_reloc_size += 1;
2900 /* Last BFD relocation for a subspace has been processed.
2901 Map the rest of the subspace with R_NO_RELOCATION fixups. */
2902 p = som_reloc_skip (abfd, bfd_section_size (abfd, subsection)
2904 p, &subspace_reloc_size, reloc_queue);
2906 /* Scribble out the relocations. */
2907 if (bfd_write ((PTR) tmp_space, p - tmp_space, 1, abfd)
2912 total_reloc_size += subspace_reloc_size;
2913 som_section_data (subsection)->subspace_dict->fixup_request_quantity
2914 = subspace_reloc_size;
2916 section = section->next;
2918 *total_reloc_sizep = total_reloc_size;
2922 /* Write out the space/subspace string table. */
2925 som_write_space_strings (abfd, current_offset, string_sizep)
2927 unsigned long current_offset;
2928 unsigned int *string_sizep;
2930 /* Chunk of memory that we can use as buffer space, then throw
2932 unsigned char tmp_space[SOM_TMP_BUFSIZE];
2934 unsigned int strings_size = 0;
2937 memset (tmp_space, 0, SOM_TMP_BUFSIZE);
2940 /* Seek to the start of the space strings in preparation for writing
2942 if (bfd_seek (abfd, current_offset, SEEK_SET) < 0)
2945 /* Walk through all the spaces and subspaces (order is not important)
2946 building up and writing string table entries for their names. */
2947 for (section = abfd->sections; section != NULL; section = section->next)
2951 /* Only work with space/subspaces; avoid any other sections
2952 which might have been made (.text for example). */
2953 if (!som_is_space (section) && !som_is_subspace (section))
2956 /* Get the length of the space/subspace name. */
2957 length = strlen (section->name);
2959 /* If there is not enough room for the next entry, then dump the
2960 current buffer contents now. Each entry will take 4 bytes to
2961 hold the string length + the string itself + null terminator. */
2962 if (p - tmp_space + 5 + length > SOM_TMP_BUFSIZE)
2964 if (bfd_write ((PTR) &tmp_space[0], p - tmp_space, 1, abfd)
2967 /* Reset to beginning of the buffer space. */
2971 /* First element in a string table entry is the length of the
2972 string. Alignment issues are already handled. */
2973 bfd_put_32 (abfd, length, p);
2977 /* Record the index in the space/subspace records. */
2978 if (som_is_space (section))
2979 som_section_data (section)->space_dict->name.n_strx = strings_size;
2981 som_section_data (section)->subspace_dict->name.n_strx = strings_size;
2983 /* Next comes the string itself + a null terminator. */
2984 strcpy (p, section->name);
2986 strings_size += length + 1;
2988 /* Always align up to the next word boundary. */
2989 while (strings_size % 4)
2991 bfd_put_8 (abfd, 0, p);
2997 /* Done with the space/subspace strings. Write out any information
2998 contained in a partial block. */
2999 if (bfd_write ((PTR) &tmp_space[0], p - tmp_space, 1, abfd) != p - tmp_space)
3001 *string_sizep = strings_size;
3005 /* Write out the symbol string table. */
3008 som_write_symbol_strings (abfd, current_offset, syms, num_syms, string_sizep)
3010 unsigned long current_offset;
3012 unsigned int num_syms;
3013 unsigned int *string_sizep;
3017 /* Chunk of memory that we can use as buffer space, then throw
3019 unsigned char tmp_space[SOM_TMP_BUFSIZE];
3021 unsigned int strings_size = 0;
3023 memset (tmp_space, 0, SOM_TMP_BUFSIZE);
3026 /* Seek to the start of the space strings in preparation for writing
3028 if (bfd_seek (abfd, current_offset, SEEK_SET) < 0)
3031 for (i = 0; i < num_syms; i++)
3033 int length = strlen (syms[i]->name);
3035 /* If there is not enough room for the next entry, then dump the
3036 current buffer contents now. */
3037 if (p - tmp_space + 5 + length > SOM_TMP_BUFSIZE)
3039 if (bfd_write ((PTR) &tmp_space[0], p - tmp_space, 1, abfd)
3042 /* Reset to beginning of the buffer space. */
3046 /* First element in a string table entry is the length of the
3047 string. This must always be 4 byte aligned. This is also
3048 an appropriate time to fill in the string index field in the
3049 symbol table entry. */
3050 bfd_put_32 (abfd, length, p);
3054 /* Next comes the string itself + a null terminator. */
3055 strcpy (p, syms[i]->name);
3057 som_symbol_data(syms[i])->stringtab_offset = strings_size;
3059 strings_size += length + 1;
3061 /* Always align up to the next word boundary. */
3062 while (strings_size % 4)
3064 bfd_put_8 (abfd, 0, p);
3070 /* Scribble out any partial block. */
3071 if (bfd_write ((PTR) &tmp_space[0], p - tmp_space, 1, abfd) != p - tmp_space)
3074 *string_sizep = strings_size;
3078 /* Compute variable information to be placed in the SOM headers,
3079 space/subspace dictionaries, relocation streams, etc. Begin
3080 writing parts of the object file. */
3083 som_begin_writing (abfd)
3086 unsigned long current_offset = 0;
3087 int strings_size = 0;
3088 unsigned int total_reloc_size = 0;
3089 unsigned long num_spaces, num_subspaces, i;
3091 unsigned int total_subspaces = 0;
3092 struct som_exec_auxhdr *exec_header = NULL;
3094 /* The file header will always be first in an object file,
3095 everything else can be in random locations. To keep things
3096 "simple" BFD will lay out the object file in the manner suggested
3097 by the PRO ABI for PA-RISC Systems. */
3099 /* Before any output can really begin offsets for all the major
3100 portions of the object file must be computed. So, starting
3101 with the initial file header compute (and sometimes write)
3102 each portion of the object file. */
3104 /* Make room for the file header, it's contents are not complete
3105 yet, so it can not be written at this time. */
3106 current_offset += sizeof (struct header);
3108 /* Any auxiliary headers will follow the file header. Right now
3109 we support only the copyright and version headers. */
3110 obj_som_file_hdr (abfd)->aux_header_location = current_offset;
3111 obj_som_file_hdr (abfd)->aux_header_size = 0;
3112 if (abfd->flags & (EXEC_P | DYNAMIC))
3114 /* Parts of the exec header will be filled in later, so
3115 delay writing the header itself. Fill in the defaults,
3116 and write it later. */
3117 current_offset += sizeof (struct som_exec_auxhdr);
3118 obj_som_file_hdr (abfd)->aux_header_size
3119 += sizeof (struct som_exec_auxhdr);
3120 exec_header = obj_som_exec_hdr (abfd);
3121 exec_header->som_auxhdr.type = EXEC_AUX_ID;
3122 exec_header->som_auxhdr.length = 40;
3124 if (obj_som_version_hdr (abfd) != NULL)
3128 if (bfd_seek (abfd, current_offset, SEEK_SET) < 0)
3131 /* Write the aux_id structure and the string length. */
3132 len = sizeof (struct aux_id) + sizeof (unsigned int);
3133 obj_som_file_hdr (abfd)->aux_header_size += len;
3134 current_offset += len;
3135 if (bfd_write ((PTR) obj_som_version_hdr (abfd), len, 1, abfd) != len)
3138 /* Write the version string. */
3139 len = obj_som_version_hdr (abfd)->header_id.length - sizeof (int);
3140 obj_som_file_hdr (abfd)->aux_header_size += len;
3141 current_offset += len;
3142 if (bfd_write ((PTR) obj_som_version_hdr (abfd)->user_string,
3143 len, 1, abfd) != len)
3147 if (obj_som_copyright_hdr (abfd) != NULL)
3151 if (bfd_seek (abfd, current_offset, SEEK_SET) < 0)
3154 /* Write the aux_id structure and the string length. */
3155 len = sizeof (struct aux_id) + sizeof (unsigned int);
3156 obj_som_file_hdr (abfd)->aux_header_size += len;
3157 current_offset += len;
3158 if (bfd_write ((PTR) obj_som_copyright_hdr (abfd), len, 1, abfd) != len)
3161 /* Write the copyright string. */
3162 len = obj_som_copyright_hdr (abfd)->header_id.length - sizeof (int);
3163 obj_som_file_hdr (abfd)->aux_header_size += len;
3164 current_offset += len;
3165 if (bfd_write ((PTR) obj_som_copyright_hdr (abfd)->copyright,
3166 len, 1, abfd) != len)
3170 /* Next comes the initialization pointers; we have no initialization
3171 pointers, so current offset does not change. */
3172 obj_som_file_hdr (abfd)->init_array_location = current_offset;
3173 obj_som_file_hdr (abfd)->init_array_total = 0;
3175 /* Next are the space records. These are fixed length records.
3177 Count the number of spaces to determine how much room is needed
3178 in the object file for the space records.
3180 The names of the spaces are stored in a separate string table,
3181 and the index for each space into the string table is computed
3182 below. Therefore, it is not possible to write the space headers
3184 num_spaces = som_count_spaces (abfd);
3185 obj_som_file_hdr (abfd)->space_location = current_offset;
3186 obj_som_file_hdr (abfd)->space_total = num_spaces;
3187 current_offset += num_spaces * sizeof (struct space_dictionary_record);
3189 /* Next are the subspace records. These are fixed length records.
3191 Count the number of subspaes to determine how much room is needed
3192 in the object file for the subspace records.
3194 A variety if fields in the subspace record are still unknown at
3195 this time (index into string table, fixup stream location/size, etc). */
3196 num_subspaces = som_count_subspaces (abfd);
3197 obj_som_file_hdr (abfd)->subspace_location = current_offset;
3198 obj_som_file_hdr (abfd)->subspace_total = num_subspaces;
3199 current_offset += num_subspaces * sizeof (struct subspace_dictionary_record);
3201 /* Next is the string table for the space/subspace names. We will
3202 build and write the string table on the fly. At the same time
3203 we will fill in the space/subspace name index fields. */
3205 /* The string table needs to be aligned on a word boundary. */
3206 if (current_offset % 4)
3207 current_offset += (4 - (current_offset % 4));
3209 /* Mark the offset of the space/subspace string table in the
3211 obj_som_file_hdr (abfd)->space_strings_location = current_offset;
3213 /* Scribble out the space strings. */
3214 if (som_write_space_strings (abfd, current_offset, &strings_size) == false)
3217 /* Record total string table size in the header and update the
3219 obj_som_file_hdr (abfd)->space_strings_size = strings_size;
3220 current_offset += strings_size;
3222 /* Next is the compiler records. We do not use these. */
3223 obj_som_file_hdr (abfd)->compiler_location = current_offset;
3224 obj_som_file_hdr (abfd)->compiler_total = 0;
3226 /* Now compute the file positions for the loadable subspaces, taking
3227 care to make sure everything stays properly aligned. */
3229 section = abfd->sections;
3230 for (i = 0; i < num_spaces; i++)
3232 asection *subsection;
3234 unsigned int subspace_offset = 0;
3237 while (!som_is_space (section))
3238 section = section->next;
3241 /* Now look for all its subspaces. */
3242 for (subsection = abfd->sections;
3244 subsection = subsection->next)
3247 if (!som_is_subspace (subsection)
3248 || !som_is_container (section, subsection)
3249 || (subsection->flags & SEC_ALLOC) == 0)
3252 /* If this is the first subspace in the space, and we are
3253 building an executable, then take care to make sure all
3254 the alignments are correct and update the exec header. */
3256 && (abfd->flags & (EXEC_P | DYNAMIC)))
3258 /* Demand paged executables have each space aligned to a
3259 page boundary. Sharable executables (write-protected
3260 text) have just the private (aka data & bss) space aligned
3261 to a page boundary. Ugh. Not true for HPUX.
3263 The HPUX kernel requires the text to always be page aligned
3264 within the file regardless of the executable's type. */
3265 if (abfd->flags & (D_PAGED | DYNAMIC)
3266 || (subsection->flags & SEC_CODE)
3267 || ((abfd->flags & WP_TEXT)
3268 && (subsection->flags & SEC_DATA)))
3269 current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
3271 /* Update the exec header. */
3272 if (subsection->flags & SEC_CODE && exec_header->exec_tfile == 0)
3274 exec_header->exec_tmem = section->vma;
3275 exec_header->exec_tfile = current_offset;
3277 if (subsection->flags & SEC_DATA && exec_header->exec_dfile == 0)
3279 exec_header->exec_dmem = section->vma;
3280 exec_header->exec_dfile = current_offset;
3283 /* Keep track of exactly where we are within a particular
3284 space. This is necessary as the braindamaged HPUX
3285 loader will create holes between subspaces *and*
3286 subspace alignments are *NOT* preserved. What a crock. */
3287 subspace_offset = subsection->vma;
3289 /* Only do this for the first subspace within each space. */
3292 else if (abfd->flags & (EXEC_P | DYNAMIC))
3294 /* The braindamaged HPUX loader may have created a hole
3295 between two subspaces. It is *not* sufficient to use
3296 the alignment specifications within the subspaces to
3297 account for these holes -- I've run into at least one
3298 case where the loader left one code subspace unaligned
3299 in a final executable.
3301 To combat this we keep a current offset within each space,
3302 and use the subspace vma fields to detect and preserve
3303 holes. What a crock!
3305 ps. This is not necessary for unloadable space/subspaces. */
3306 current_offset += subsection->vma - subspace_offset;
3307 if (subsection->flags & SEC_CODE)
3308 exec_header->exec_tsize += subsection->vma - subspace_offset;
3310 exec_header->exec_dsize += subsection->vma - subspace_offset;
3311 subspace_offset += subsection->vma - subspace_offset;
3315 subsection->target_index = total_subspaces++;
3316 /* This is real data to be loaded from the file. */
3317 if (subsection->flags & SEC_LOAD)
3319 /* Update the size of the code & data. */
3320 if (abfd->flags & (EXEC_P | DYNAMIC)
3321 && subsection->flags & SEC_CODE)
3322 exec_header->exec_tsize += subsection->_cooked_size;
3323 else if (abfd->flags & (EXEC_P | DYNAMIC)
3324 && subsection->flags & SEC_DATA)
3325 exec_header->exec_dsize += subsection->_cooked_size;
3326 som_section_data (subsection)->subspace_dict->file_loc_init_value
3328 subsection->filepos = current_offset;
3329 current_offset += bfd_section_size (abfd, subsection);
3330 subspace_offset += bfd_section_size (abfd, subsection);
3332 /* Looks like uninitialized data. */
3335 /* Update the size of the bss section. */
3336 if (abfd->flags & (EXEC_P | DYNAMIC))
3337 exec_header->exec_bsize += subsection->_cooked_size;
3339 som_section_data (subsection)->subspace_dict->file_loc_init_value
3341 som_section_data (subsection)->subspace_dict->
3342 initialization_length = 0;
3345 /* Goto the next section. */
3346 section = section->next;
3349 /* Finally compute the file positions for unloadable subspaces.
3350 If building an executable, start the unloadable stuff on its
3353 if (abfd->flags & (EXEC_P | DYNAMIC))
3354 current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
3356 obj_som_file_hdr (abfd)->unloadable_sp_location = current_offset;
3357 section = abfd->sections;
3358 for (i = 0; i < num_spaces; i++)
3360 asection *subsection;
3363 while (!som_is_space (section))
3364 section = section->next;
3366 if (abfd->flags & (EXEC_P | DYNAMIC))
3367 current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
3369 /* Now look for all its subspaces. */
3370 for (subsection = abfd->sections;
3372 subsection = subsection->next)
3375 if (!som_is_subspace (subsection)
3376 || !som_is_container (section, subsection)
3377 || (subsection->flags & SEC_ALLOC) != 0)
3380 subsection->target_index = total_subspaces++;
3381 /* This is real data to be loaded from the file. */
3382 if ((subsection->flags & SEC_LOAD) == 0)
3384 som_section_data (subsection)->subspace_dict->file_loc_init_value
3386 subsection->filepos = current_offset;
3387 current_offset += bfd_section_size (abfd, subsection);
3389 /* Looks like uninitialized data. */
3392 som_section_data (subsection)->subspace_dict->file_loc_init_value
3394 som_section_data (subsection)->subspace_dict->
3395 initialization_length = bfd_section_size (abfd, subsection);
3398 /* Goto the next section. */
3399 section = section->next;
3402 /* If building an executable, then make sure to seek to and write
3403 one byte at the end of the file to make sure any necessary
3404 zeros are filled in. Ugh. */
3405 if (abfd->flags & (EXEC_P | DYNAMIC))
3406 current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
3407 if (bfd_seek (abfd, current_offset - 1, SEEK_SET) < 0)
3409 if (bfd_write ((PTR) "", 1, 1, abfd) != 1)
3412 obj_som_file_hdr (abfd)->unloadable_sp_size
3413 = current_offset - obj_som_file_hdr (abfd)->unloadable_sp_location;
3415 /* Loader fixups are not supported in any way shape or form. */
3416 obj_som_file_hdr (abfd)->loader_fixup_location = 0;
3417 obj_som_file_hdr (abfd)->loader_fixup_total = 0;
3419 /* Done. Store the total size of the SOM so far. */
3420 obj_som_file_hdr (abfd)->som_length = current_offset;
3425 /* Finally, scribble out the various headers to the disk. */
3428 som_finish_writing (abfd)
3431 int num_spaces = som_count_spaces (abfd);
3432 asymbol **syms = bfd_get_outsymbols (abfd);
3433 int i, num_syms, strings_size;
3434 int subspace_index = 0;
3437 unsigned long current_offset;
3438 unsigned int total_reloc_size;
3440 /* Next is the symbol table. These are fixed length records.
3442 Count the number of symbols to determine how much room is needed
3443 in the object file for the symbol table.
3445 The names of the symbols are stored in a separate string table,
3446 and the index for each symbol name into the string table is computed
3447 below. Therefore, it is not possible to write the symbol table
3450 These used to be output before the subspace contents, but they
3451 were moved here to work around a stupid bug in the hpux linker
3452 (fixed in hpux10). */
3453 current_offset = obj_som_file_hdr (abfd)->som_length;
3455 /* Make sure we're on a word boundary. */
3456 if (current_offset % 4)
3457 current_offset += (4 - (current_offset % 4));
3459 num_syms = bfd_get_symcount (abfd);
3460 obj_som_file_hdr (abfd)->symbol_location = current_offset;
3461 obj_som_file_hdr (abfd)->symbol_total = num_syms;
3462 current_offset += num_syms * sizeof (struct symbol_dictionary_record);
3464 /* Next are the symbol strings.
3465 Align them to a word boundary. */
3466 if (current_offset % 4)
3467 current_offset += (4 - (current_offset % 4));
3468 obj_som_file_hdr (abfd)->symbol_strings_location = current_offset;
3470 /* Scribble out the symbol strings. */
3471 if (som_write_symbol_strings (abfd, current_offset, syms,
3472 num_syms, &strings_size)
3476 /* Record total string table size in header and update the
3478 obj_som_file_hdr (abfd)->symbol_strings_size = strings_size;
3479 current_offset += strings_size;
3481 /* Do prep work before handling fixups. */
3482 som_prep_for_fixups (abfd,
3483 bfd_get_outsymbols (abfd),
3484 bfd_get_symcount (abfd));
3486 /* At the end of the file is the fixup stream which starts on a
3488 if (current_offset % 4)
3489 current_offset += (4 - (current_offset % 4));
3490 obj_som_file_hdr (abfd)->fixup_request_location = current_offset;
3492 /* Write the fixups and update fields in subspace headers which
3493 relate to the fixup stream. */
3494 if (som_write_fixups (abfd, current_offset, &total_reloc_size) == false)
3497 /* Record the total size of the fixup stream in the file header. */
3498 obj_som_file_hdr (abfd)->fixup_request_total = total_reloc_size;
3500 /* Done. Store the total size of the SOM. */
3501 obj_som_file_hdr (abfd)->som_length = current_offset + total_reloc_size;
3503 /* Now that the symbol table information is complete, build and
3504 write the symbol table. */
3505 if (som_build_and_write_symbol_table (abfd) == false)
3508 /* Subspaces are written first so that we can set up information
3509 about them in their containing spaces as the subspace is written. */
3511 /* Seek to the start of the subspace dictionary records. */
3512 location = obj_som_file_hdr (abfd)->subspace_location;
3513 if (bfd_seek (abfd, location, SEEK_SET) < 0)
3516 section = abfd->sections;
3517 /* Now for each loadable space write out records for its subspaces. */
3518 for (i = 0; i < num_spaces; i++)
3520 asection *subsection;
3523 while (!som_is_space (section))
3524 section = section->next;
3526 /* Now look for all its subspaces. */
3527 for (subsection = abfd->sections;
3529 subsection = subsection->next)
3532 /* Skip any section which does not correspond to a space
3533 or subspace. Or does not have SEC_ALLOC set (and therefore
3534 has no real bits on the disk). */
3535 if (!som_is_subspace (subsection)
3536 || !som_is_container (section, subsection)
3537 || (subsection->flags & SEC_ALLOC) == 0)
3540 /* If this is the first subspace for this space, then save
3541 the index of the subspace in its containing space. Also
3542 set "is_loadable" in the containing space. */
3544 if (som_section_data (section)->space_dict->subspace_quantity == 0)
3546 som_section_data (section)->space_dict->is_loadable = 1;
3547 som_section_data (section)->space_dict->subspace_index
3551 /* Increment the number of subspaces seen and the number of
3552 subspaces contained within the current space. */
3554 som_section_data (section)->space_dict->subspace_quantity++;
3556 /* Mark the index of the current space within the subspace's
3557 dictionary record. */
3558 som_section_data (subsection)->subspace_dict->space_index = i;
3560 /* Dump the current subspace header. */
3561 if (bfd_write ((PTR) som_section_data (subsection)->subspace_dict,
3562 sizeof (struct subspace_dictionary_record), 1, abfd)
3563 != sizeof (struct subspace_dictionary_record))
3566 /* Goto the next section. */
3567 section = section->next;
3570 /* Now repeat the process for unloadable subspaces. */
3571 section = abfd->sections;
3572 /* Now for each space write out records for its subspaces. */
3573 for (i = 0; i < num_spaces; i++)
3575 asection *subsection;
3578 while (!som_is_space (section))
3579 section = section->next;
3581 /* Now look for all its subspaces. */
3582 for (subsection = abfd->sections;
3584 subsection = subsection->next)
3587 /* Skip any section which does not correspond to a space or
3588 subspace, or which SEC_ALLOC set (and therefore handled
3589 in the loadable spaces/subspaces code above). */
3591 if (!som_is_subspace (subsection)
3592 || !som_is_container (section, subsection)
3593 || (subsection->flags & SEC_ALLOC) != 0)
3596 /* If this is the first subspace for this space, then save
3597 the index of the subspace in its containing space. Clear
3600 if (som_section_data (section)->space_dict->subspace_quantity == 0)
3602 som_section_data (section)->space_dict->is_loadable = 0;
3603 som_section_data (section)->space_dict->subspace_index
3607 /* Increment the number of subspaces seen and the number of
3608 subspaces contained within the current space. */
3609 som_section_data (section)->space_dict->subspace_quantity++;
3612 /* Mark the index of the current space within the subspace's
3613 dictionary record. */
3614 som_section_data (subsection)->subspace_dict->space_index = i;
3616 /* Dump this subspace header. */
3617 if (bfd_write ((PTR) som_section_data (subsection)->subspace_dict,
3618 sizeof (struct subspace_dictionary_record), 1, abfd)
3619 != sizeof (struct subspace_dictionary_record))
3622 /* Goto the next section. */
3623 section = section->next;
3626 /* All the subspace dictiondary records are written, and all the
3627 fields are set up in the space dictionary records.
3629 Seek to the right location and start writing the space
3630 dictionary records. */
3631 location = obj_som_file_hdr (abfd)->space_location;
3632 if (bfd_seek (abfd, location, SEEK_SET) < 0)
3635 section = abfd->sections;
3636 for (i = 0; i < num_spaces; i++)
3640 while (!som_is_space (section))
3641 section = section->next;
3643 /* Dump its header */
3644 if (bfd_write ((PTR) som_section_data (section)->space_dict,
3645 sizeof (struct space_dictionary_record), 1, abfd)
3646 != sizeof (struct space_dictionary_record))
3649 /* Goto the next section. */
3650 section = section->next;
3653 /* Setting of the system_id has to happen very late now that copying of
3654 BFD private data happens *after* section contents are set. */
3655 if (abfd->flags & (EXEC_P | DYNAMIC))
3656 obj_som_file_hdr(abfd)->system_id = obj_som_exec_data (abfd)->system_id;
3657 else if (bfd_get_mach (abfd) == pa20)
3658 obj_som_file_hdr(abfd)->system_id = CPU_PA_RISC2_0;
3659 else if (bfd_get_mach (abfd) == pa11)
3660 obj_som_file_hdr(abfd)->system_id = CPU_PA_RISC1_1;
3662 obj_som_file_hdr(abfd)->system_id = CPU_PA_RISC1_0;
3664 /* Compute the checksum for the file header just before writing
3665 the header to disk. */
3666 obj_som_file_hdr (abfd)->checksum = som_compute_checksum (abfd);
3668 /* Only thing left to do is write out the file header. It is always
3669 at location zero. Seek there and write it. */
3670 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0)
3672 if (bfd_write ((PTR) obj_som_file_hdr (abfd),
3673 sizeof (struct header), 1, abfd)
3674 != sizeof (struct header))
3677 /* Now write the exec header. */
3678 if (abfd->flags & (EXEC_P | DYNAMIC))
3681 struct som_exec_auxhdr *exec_header;
3683 exec_header = obj_som_exec_hdr (abfd);
3684 exec_header->exec_entry = bfd_get_start_address (abfd);
3685 exec_header->exec_flags = obj_som_exec_data (abfd)->exec_flags;
3687 /* Oh joys. Ram some of the BSS data into the DATA section
3688 to be compatable with how the hp linker makes objects
3689 (saves memory space). */
3690 tmp = exec_header->exec_dsize;
3691 tmp = SOM_ALIGN (tmp, PA_PAGESIZE);
3692 exec_header->exec_bsize -= (tmp - exec_header->exec_dsize);
3693 if (exec_header->exec_bsize < 0)
3694 exec_header->exec_bsize = 0;
3695 exec_header->exec_dsize = tmp;
3697 if (bfd_seek (abfd, obj_som_file_hdr (abfd)->aux_header_location,
3701 if (bfd_write ((PTR) exec_header, AUX_HDR_SIZE, 1, abfd)
3708 /* Compute and return the checksum for a SOM file header. */
3710 static unsigned long
3711 som_compute_checksum (abfd)
3714 unsigned long checksum, count, i;
3715 unsigned long *buffer = (unsigned long *) obj_som_file_hdr (abfd);
3718 count = sizeof (struct header) / sizeof (unsigned long);
3719 for (i = 0; i < count; i++)
3720 checksum ^= *(buffer + i);
3726 som_bfd_derive_misc_symbol_info (abfd, sym, info)
3729 struct som_misc_symbol_info *info;
3732 memset (info, 0, sizeof (struct som_misc_symbol_info));
3734 /* The HP SOM linker requires detailed type information about
3735 all symbols (including undefined symbols!). Unfortunately,
3736 the type specified in an import/export statement does not
3737 always match what the linker wants. Severe braindamage. */
3739 /* Section symbols will not have a SOM symbol type assigned to
3740 them yet. Assign all section symbols type ST_DATA. */
3741 if (sym->flags & BSF_SECTION_SYM)
3742 info->symbol_type = ST_DATA;
3745 /* Common symbols must have scope SS_UNSAT and type
3746 ST_STORAGE or the linker will choke. */
3747 if (bfd_is_com_section (sym->section))
3749 info->symbol_scope = SS_UNSAT;
3750 info->symbol_type = ST_STORAGE;
3753 /* It is possible to have a symbol without an associated
3754 type. This happens if the user imported the symbol
3755 without a type and the symbol was never defined
3756 locally. If BSF_FUNCTION is set for this symbol, then
3757 assign it type ST_CODE (the HP linker requires undefined
3758 external functions to have type ST_CODE rather than ST_ENTRY). */
3759 else if ((som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN
3760 || som_symbol_data (sym)->som_type == SYMBOL_TYPE_CODE)
3761 && bfd_is_und_section (sym->section)
3762 && sym->flags & BSF_FUNCTION)
3763 info->symbol_type = ST_CODE;
3765 /* Handle function symbols which were defined in this file.
3766 They should have type ST_ENTRY. Also retrieve the argument
3767 relocation bits from the SOM backend information. */
3768 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_ENTRY
3769 || (som_symbol_data (sym)->som_type == SYMBOL_TYPE_CODE
3770 && (sym->flags & BSF_FUNCTION))
3771 || (som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN
3772 && (sym->flags & BSF_FUNCTION)))
3774 info->symbol_type = ST_ENTRY;
3775 info->arg_reloc = som_symbol_data (sym)->tc_data.hppa_arg_reloc;
3778 /* For unknown symbols set the symbol's type based on the symbol's
3779 section (ST_DATA for DATA sections, ST_CODE for CODE sections). */
3780 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN)
3782 if (sym->section->flags & SEC_CODE)
3783 info->symbol_type = ST_CODE;
3785 info->symbol_type = ST_DATA;
3788 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN)
3789 info->symbol_type = ST_DATA;
3791 /* From now on it's a very simple mapping. */
3792 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_ABSOLUTE)
3793 info->symbol_type = ST_ABSOLUTE;
3794 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_CODE)
3795 info->symbol_type = ST_CODE;
3796 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_DATA)
3797 info->symbol_type = ST_DATA;
3798 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_MILLICODE)
3799 info->symbol_type = ST_MILLICODE;
3800 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_PLABEL)
3801 info->symbol_type = ST_PLABEL;
3802 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_PRI_PROG)
3803 info->symbol_type = ST_PRI_PROG;
3804 else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_SEC_PROG)
3805 info->symbol_type = ST_SEC_PROG;
3808 /* Now handle the symbol's scope. Exported data which is not
3809 in the common section has scope SS_UNIVERSAL. Note scope
3810 of common symbols was handled earlier! */
3811 if (bfd_is_und_section (sym->section))
3812 info->symbol_scope = SS_UNSAT;
3813 else if (sym->flags & BSF_EXPORT && ! bfd_is_com_section (sym->section))
3814 info->symbol_scope = SS_UNIVERSAL;
3815 /* Anything else which is not in the common section has scope
3817 else if (! bfd_is_com_section (sym->section))
3818 info->symbol_scope = SS_LOCAL;
3820 /* Now set the symbol_info field. It has no real meaning
3821 for undefined or common symbols, but the HP linker will
3822 choke if it's not set to some "reasonable" value. We
3823 use zero as a reasonable value. */
3824 if (bfd_is_com_section (sym->section)
3825 || bfd_is_und_section (sym->section)
3826 || bfd_is_abs_section (sym->section))
3827 info->symbol_info = 0;
3828 /* For all other symbols, the symbol_info field contains the
3829 subspace index of the space this symbol is contained in. */
3831 info->symbol_info = sym->section->target_index;
3833 /* Set the symbol's value. */
3834 info->symbol_value = sym->value + sym->section->vma;
3837 /* Build and write, in one big chunk, the entire symbol table for
3841 som_build_and_write_symbol_table (abfd)
3844 unsigned int num_syms = bfd_get_symcount (abfd);
3845 file_ptr symtab_location = obj_som_file_hdr (abfd)->symbol_location;
3846 asymbol **bfd_syms = obj_som_sorted_syms (abfd);
3847 struct symbol_dictionary_record *som_symtab = NULL;
3850 /* Compute total symbol table size and allocate a chunk of memory
3851 to hold the symbol table as we build it. */
3852 symtab_size = num_syms * sizeof (struct symbol_dictionary_record);
3853 som_symtab = (struct symbol_dictionary_record *) bfd_malloc (symtab_size);
3854 if (som_symtab == NULL && symtab_size != 0)
3856 memset (som_symtab, 0, symtab_size);
3858 /* Walk over each symbol. */
3859 for (i = 0; i < num_syms; i++)
3861 struct som_misc_symbol_info info;
3863 /* This is really an index into the symbol strings table.
3864 By the time we get here, the index has already been
3865 computed and stored into the name field in the BFD symbol. */
3866 som_symtab[i].name.n_strx = som_symbol_data(bfd_syms[i])->stringtab_offset;
3868 /* Derive SOM information from the BFD symbol. */
3869 som_bfd_derive_misc_symbol_info (abfd, bfd_syms[i], &info);
3872 som_symtab[i].symbol_type = info.symbol_type;
3873 som_symtab[i].symbol_scope = info.symbol_scope;
3874 som_symtab[i].arg_reloc = info.arg_reloc;
3875 som_symtab[i].symbol_info = info.symbol_info;
3876 som_symtab[i].symbol_value = info.symbol_value;
3879 /* Everything is ready, seek to the right location and
3880 scribble out the symbol table. */
3881 if (bfd_seek (abfd, symtab_location, SEEK_SET) != 0)
3884 if (bfd_write ((PTR) som_symtab, symtab_size, 1, abfd) != symtab_size)
3887 if (som_symtab != NULL)
3891 if (som_symtab != NULL)
3896 /* Write an object in SOM format. */
3899 som_write_object_contents (abfd)
3902 if (abfd->output_has_begun == false)
3904 /* Set up fixed parts of the file, space, and subspace headers.
3905 Notify the world that output has begun. */
3906 som_prep_headers (abfd);
3907 abfd->output_has_begun = true;
3908 /* Start writing the object file. This include all the string
3909 tables, fixup streams, and other portions of the object file. */
3910 som_begin_writing (abfd);
3913 return (som_finish_writing (abfd));
3917 /* Read and save the string table associated with the given BFD. */
3920 som_slurp_string_table (abfd)
3925 /* Use the saved version if its available. */
3926 if (obj_som_stringtab (abfd) != NULL)
3929 /* I don't think this can currently happen, and I'm not sure it should
3930 really be an error, but it's better than getting unpredictable results
3931 from the host's malloc when passed a size of zero. */
3932 if (obj_som_stringtab_size (abfd) == 0)
3934 bfd_set_error (bfd_error_no_symbols);
3938 /* Allocate and read in the string table. */
3939 stringtab = bfd_malloc (obj_som_stringtab_size (abfd));
3940 if (stringtab == NULL)
3942 memset (stringtab, 0, obj_som_stringtab_size (abfd));
3944 if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) < 0)
3947 if (bfd_read (stringtab, obj_som_stringtab_size (abfd), 1, abfd)
3948 != obj_som_stringtab_size (abfd))
3951 /* Save our results and return success. */
3952 obj_som_stringtab (abfd) = stringtab;
3956 /* Return the amount of data (in bytes) required to hold the symbol
3957 table for this object. */
3960 som_get_symtab_upper_bound (abfd)
3963 if (!som_slurp_symbol_table (abfd))
3966 return (bfd_get_symcount (abfd) + 1) * (sizeof (asymbol *));
3969 /* Convert from a SOM subspace index to a BFD section. */
3972 bfd_section_from_som_symbol (abfd, symbol)
3974 struct symbol_dictionary_record *symbol;
3978 /* The meaning of the symbol_info field changes for functions
3979 within executables. So only use the quick symbol_info mapping for
3980 incomplete objects and non-function symbols in executables. */
3981 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0
3982 || (symbol->symbol_type != ST_ENTRY
3983 && symbol->symbol_type != ST_PRI_PROG
3984 && symbol->symbol_type != ST_SEC_PROG
3985 && symbol->symbol_type != ST_MILLICODE))
3987 unsigned int index = symbol->symbol_info;
3988 for (section = abfd->sections; section != NULL; section = section->next)
3989 if (section->target_index == index && som_is_subspace (section))
3992 /* Could be a symbol from an external library (such as an OMOS
3993 shared library). Don't abort. */
3994 return bfd_abs_section_ptr;
3999 unsigned int value = symbol->symbol_value;
4001 /* For executables we will have to use the symbol's address and
4002 find out what section would contain that address. Yuk. */
4003 for (section = abfd->sections; section; section = section->next)
4005 if (value >= section->vma
4006 && value <= section->vma + section->_cooked_size
4007 && som_is_subspace (section))
4011 /* Could be a symbol from an external library (such as an OMOS
4012 shared library). Don't abort. */
4013 return bfd_abs_section_ptr;
4018 /* Read and save the symbol table associated with the given BFD. */
4021 som_slurp_symbol_table (abfd)
4024 int symbol_count = bfd_get_symcount (abfd);
4025 int symsize = sizeof (struct symbol_dictionary_record);
4027 struct symbol_dictionary_record *buf = NULL, *bufp, *endbufp;
4028 som_symbol_type *sym, *symbase;
4030 /* Return saved value if it exists. */
4031 if (obj_som_symtab (abfd) != NULL)
4032 goto successful_return;
4034 /* Special case. This is *not* an error. */
4035 if (symbol_count == 0)
4036 goto successful_return;
4038 if (!som_slurp_string_table (abfd))
4041 stringtab = obj_som_stringtab (abfd);
4043 symbase = ((som_symbol_type *)
4044 bfd_malloc (symbol_count * sizeof (som_symbol_type)));
4045 if (symbase == NULL)
4047 memset (symbase, 0, symbol_count * sizeof (som_symbol_type));
4049 /* Read in the external SOM representation. */
4050 buf = bfd_malloc (symbol_count * symsize);
4051 if (buf == NULL && symbol_count * symsize != 0)
4053 if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) < 0)
4055 if (bfd_read (buf, symbol_count * symsize, 1, abfd)
4056 != symbol_count * symsize)
4059 /* Iterate over all the symbols and internalize them. */
4060 endbufp = buf + symbol_count;
4061 for (bufp = buf, sym = symbase; bufp < endbufp; ++bufp)
4064 /* I don't think we care about these. */
4065 if (bufp->symbol_type == ST_SYM_EXT
4066 || bufp->symbol_type == ST_ARG_EXT)
4069 /* Set some private data we care about. */
4070 if (bufp->symbol_type == ST_NULL)
4071 som_symbol_data (sym)->som_type = SYMBOL_TYPE_UNKNOWN;
4072 else if (bufp->symbol_type == ST_ABSOLUTE)
4073 som_symbol_data (sym)->som_type = SYMBOL_TYPE_ABSOLUTE;
4074 else if (bufp->symbol_type == ST_DATA)
4075 som_symbol_data (sym)->som_type = SYMBOL_TYPE_DATA;
4076 else if (bufp->symbol_type == ST_CODE)
4077 som_symbol_data (sym)->som_type = SYMBOL_TYPE_CODE;
4078 else if (bufp->symbol_type == ST_PRI_PROG)
4079 som_symbol_data (sym)->som_type = SYMBOL_TYPE_PRI_PROG;
4080 else if (bufp->symbol_type == ST_SEC_PROG)
4081 som_symbol_data (sym)->som_type = SYMBOL_TYPE_SEC_PROG;
4082 else if (bufp->symbol_type == ST_ENTRY)
4083 som_symbol_data (sym)->som_type = SYMBOL_TYPE_ENTRY;
4084 else if (bufp->symbol_type == ST_MILLICODE)
4085 som_symbol_data (sym)->som_type = SYMBOL_TYPE_MILLICODE;
4086 else if (bufp->symbol_type == ST_PLABEL)
4087 som_symbol_data (sym)->som_type = SYMBOL_TYPE_PLABEL;
4089 som_symbol_data (sym)->som_type = SYMBOL_TYPE_UNKNOWN;
4090 som_symbol_data (sym)->tc_data.hppa_arg_reloc = bufp->arg_reloc;
4092 /* Some reasonable defaults. */
4093 sym->symbol.the_bfd = abfd;
4094 sym->symbol.name = bufp->name.n_strx + stringtab;
4095 sym->symbol.value = bufp->symbol_value;
4096 sym->symbol.section = 0;
4097 sym->symbol.flags = 0;
4099 switch (bufp->symbol_type)
4103 sym->symbol.flags |= BSF_FUNCTION;
4104 sym->symbol.value &= ~0x3;
4111 sym->symbol.value &= ~0x3;
4112 /* If the symbol's scope is ST_UNSAT, then these are
4113 undefined function symbols. */
4114 if (bufp->symbol_scope == SS_UNSAT)
4115 sym->symbol.flags |= BSF_FUNCTION;
4122 /* Handle scoping and section information. */
4123 switch (bufp->symbol_scope)
4125 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
4126 so the section associated with this symbol can't be known. */
4128 if (bufp->symbol_type != ST_STORAGE)
4129 sym->symbol.section = bfd_und_section_ptr;
4131 sym->symbol.section = bfd_com_section_ptr;
4132 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
4136 if (bufp->symbol_type != ST_STORAGE)
4137 sym->symbol.section = bfd_und_section_ptr;
4139 sym->symbol.section = bfd_com_section_ptr;
4143 sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
4144 sym->symbol.section = bfd_section_from_som_symbol (abfd, bufp);
4145 sym->symbol.value -= sym->symbol.section->vma;
4149 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
4150 Sound dumb? It is. */
4154 sym->symbol.flags |= BSF_LOCAL;
4155 sym->symbol.section = bfd_section_from_som_symbol (abfd, bufp);
4156 sym->symbol.value -= sym->symbol.section->vma;
4160 /* Mark section symbols and symbols used by the debugger.
4161 Note $START$ is a magic code symbol, NOT a section symbol. */
4162 if (sym->symbol.name[0] == '$'
4163 && sym->symbol.name[strlen (sym->symbol.name) - 1] == '$'
4164 && !strcmp (sym->symbol.name, sym->symbol.section->name))
4165 sym->symbol.flags |= BSF_SECTION_SYM;
4166 else if (!strncmp (sym->symbol.name, "L$0\002", 4))
4168 sym->symbol.flags |= BSF_SECTION_SYM;
4169 sym->symbol.name = sym->symbol.section->name;
4171 else if (!strncmp (sym->symbol.name, "L$0\001", 4))
4172 sym->symbol.flags |= BSF_DEBUGGING;
4174 /* Note increment at bottom of loop, since we skip some symbols
4175 we can not include it as part of the for statement. */
4179 /* We modify the symbol count to record the number of BFD symbols we
4181 bfd_get_symcount (abfd) = sym - symbase;
4183 /* Save our results and return success. */
4184 obj_som_symtab (abfd) = symbase;
4196 /* Canonicalize a SOM symbol table. Return the number of entries
4197 in the symbol table. */
4200 som_get_symtab (abfd, location)
4205 som_symbol_type *symbase;
4207 if (!som_slurp_symbol_table (abfd))
4210 i = bfd_get_symcount (abfd);
4211 symbase = obj_som_symtab (abfd);
4213 for (; i > 0; i--, location++, symbase++)
4214 *location = &symbase->symbol;
4216 /* Final null pointer. */
4218 return (bfd_get_symcount (abfd));
4221 /* Make a SOM symbol. There is nothing special to do here. */
4224 som_make_empty_symbol (abfd)
4227 som_symbol_type *new =
4228 (som_symbol_type *) bfd_zalloc (abfd, sizeof (som_symbol_type));
4231 new->symbol.the_bfd = abfd;
4233 return &new->symbol;
4236 /* Print symbol information. */
4239 som_print_symbol (ignore_abfd, afile, symbol, how)
4243 bfd_print_symbol_type how;
4245 FILE *file = (FILE *) afile;
4248 case bfd_print_symbol_name:
4249 fprintf (file, "%s", symbol->name);
4251 case bfd_print_symbol_more:
4252 fprintf (file, "som ");
4253 fprintf_vma (file, symbol->value);
4254 fprintf (file, " %lx", (long) symbol->flags);
4256 case bfd_print_symbol_all:
4258 CONST char *section_name;
4259 section_name = symbol->section ? symbol->section->name : "(*none*)";
4260 bfd_print_symbol_vandf ((PTR) file, symbol);
4261 fprintf (file, " %s\t%s", section_name, symbol->name);
4268 som_bfd_is_local_label_name (abfd, name)
4272 return (name[0] == 'L' && name[1] == '$');
4275 /* Count or process variable-length SOM fixup records.
4277 To avoid code duplication we use this code both to compute the number
4278 of relocations requested by a stream, and to internalize the stream.
4280 When computing the number of relocations requested by a stream the
4281 variables rptr, section, and symbols have no meaning.
4283 Return the number of relocations requested by the fixup stream. When
4286 This needs at least two or three more passes to get it cleaned up. */
4289 som_set_reloc_info (fixup, end, internal_relocs, section, symbols, just_count)
4290 unsigned char *fixup;
4292 arelent *internal_relocs;
4297 unsigned int op, varname, deallocate_contents = 0;
4298 unsigned char *end_fixups = &fixup[end];
4299 const struct fixup_format *fp;
4301 unsigned char *save_fixup;
4302 int variables[26], stack[20], c, v, count, prev_fixup, *sp, saved_unwind_bits;
4304 arelent *rptr= internal_relocs;
4305 unsigned int offset = 0;
4307 #define var(c) variables[(c) - 'A']
4308 #define push(v) (*sp++ = (v))
4309 #define pop() (*--sp)
4310 #define emptystack() (sp == stack)
4312 som_initialize_reloc_queue (reloc_queue);
4313 memset (variables, 0, sizeof (variables));
4314 memset (stack, 0, sizeof (stack));
4317 saved_unwind_bits = 0;
4320 while (fixup < end_fixups)
4323 /* Save pointer to the start of this fixup. We'll use
4324 it later to determine if it is necessary to put this fixup
4328 /* Get the fixup code and its associated format. */
4330 fp = &som_fixup_formats[op];
4332 /* Handle a request for a previous fixup. */
4333 if (*fp->format == 'P')
4335 /* Get pointer to the beginning of the prev fixup, move
4336 the repeated fixup to the head of the queue. */
4337 fixup = reloc_queue[fp->D].reloc;
4338 som_reloc_queue_fix (reloc_queue, fp->D);
4341 /* Get the fixup code and its associated format. */
4343 fp = &som_fixup_formats[op];
4346 /* If this fixup will be passed to BFD, set some reasonable defaults. */
4348 && som_hppa_howto_table[op].type != R_NO_RELOCATION
4349 && som_hppa_howto_table[op].type != R_DATA_OVERRIDE)
4351 rptr->address = offset;
4352 rptr->howto = &som_hppa_howto_table[op];
4354 rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
4357 /* Set default input length to 0. Get the opcode class index
4361 var ('U') = saved_unwind_bits;
4363 /* Get the opcode format. */
4366 /* Process the format string. Parsing happens in two phases,
4367 parse RHS, then assign to LHS. Repeat until no more
4368 characters in the format string. */
4371 /* The variable this pass is going to compute a value for. */
4374 /* Start processing RHS. Continue until a NULL or '=' is found. */
4379 /* If this is a variable, push it on the stack. */
4383 /* If this is a lower case letter, then it represents
4384 additional data from the fixup stream to be pushed onto
4386 else if (islower (c))
4388 int bits = (c - 'a') * 8;
4389 for (v = 0; c > 'a'; --c)
4390 v = (v << 8) | *fixup++;
4392 v = sign_extend (v, bits);
4396 /* A decimal constant. Push it on the stack. */
4397 else if (isdigit (c))
4400 while (isdigit (*cp))
4401 v = (v * 10) + (*cp++ - '0');
4406 /* An operator. Pop two two values from the stack and
4407 use them as operands to the given operation. Push
4408 the result of the operation back on the stack. */
4430 while (*cp && *cp != '=');
4432 /* Move over the equal operator. */
4435 /* Pop the RHS off the stack. */
4438 /* Perform the assignment. */
4441 /* Handle side effects. and special 'O' stack cases. */
4444 /* Consume some bytes from the input space. */
4448 /* A symbol to use in the relocation. Make a note
4449 of this if we are not just counting. */
4452 rptr->sym_ptr_ptr = &symbols[c];
4454 /* Argument relocation bits for a function call. */
4458 unsigned int tmp = var ('R');
4461 if ((som_hppa_howto_table[op].type == R_PCREL_CALL
4462 && R_PCREL_CALL + 10 > op)
4463 || (som_hppa_howto_table[op].type == R_ABS_CALL
4464 && R_ABS_CALL + 10 > op))
4466 /* Simple encoding. */
4473 rptr->addend |= 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2;
4475 rptr->addend |= 1 << 8 | 1 << 6 | 1 << 4;
4477 rptr->addend |= 1 << 8 | 1 << 6;
4479 rptr->addend |= 1 << 8;
4483 unsigned int tmp1, tmp2;
4485 /* First part is easy -- low order two bits are
4486 directly copied, then shifted away. */
4487 rptr->addend = tmp & 0x3;
4490 /* Diving the result by 10 gives us the second
4491 part. If it is 9, then the first two words
4492 are a double precision paramater, else it is
4493 3 * the first arg bits + the 2nd arg bits. */
4497 rptr->addend += (0xe << 6);
4500 /* Get the two pieces. */
4503 /* Put them in the addend. */
4504 rptr->addend += (tmp2 << 8) + (tmp1 << 6);
4507 /* What's left is the third part. It's unpacked
4508 just like the second. */
4510 rptr->addend += (0xe << 2);
4515 rptr->addend += (tmp2 << 4) + (tmp << 2);
4518 rptr->addend = HPPA_R_ADDEND (rptr->addend, 0);
4521 /* Handle the linker expression stack. */
4526 subop = comp1_opcodes;
4529 subop = comp2_opcodes;
4532 subop = comp3_opcodes;
4537 while (*subop <= (unsigned char) c)
4541 /* The lower 32unwind bits must be persistent. */
4543 saved_unwind_bits = var ('U');
4551 /* If we used a previous fixup, clean up after it. */
4554 fixup = save_fixup + 1;
4558 else if (fixup > save_fixup + 1)
4559 som_reloc_queue_insert (save_fixup, fixup - save_fixup, reloc_queue);
4561 /* We do not pass R_DATA_OVERRIDE or R_NO_RELOCATION
4563 if (som_hppa_howto_table[op].type != R_DATA_OVERRIDE
4564 && som_hppa_howto_table[op].type != R_NO_RELOCATION)
4566 /* Done with a single reloction. Loop back to the top. */
4569 if (som_hppa_howto_table[op].type == R_ENTRY)
4570 rptr->addend = var ('T');
4571 else if (som_hppa_howto_table[op].type == R_EXIT)
4572 rptr->addend = var ('U');
4573 else if (som_hppa_howto_table[op].type == R_PCREL_CALL
4574 || som_hppa_howto_table[op].type == R_ABS_CALL)
4576 else if (som_hppa_howto_table[op].type == R_DATA_ONE_SYMBOL)
4578 unsigned addend = var ('V');
4580 /* Try what was specified in R_DATA_OVERRIDE first
4581 (if anything). Then the hard way using the
4582 section contents. */
4583 rptr->addend = var ('V');
4585 if (rptr->addend == 0 && !section->contents)
4587 /* Got to read the damn contents first. We don't
4588 bother saving the contents (yet). Add it one
4589 day if the need arises. */
4590 section->contents = bfd_malloc (section->_raw_size);
4591 if (section->contents == NULL)
4594 deallocate_contents = 1;
4595 bfd_get_section_contents (section->owner,
4599 section->_raw_size);
4601 else if (rptr->addend == 0)
4602 rptr->addend = bfd_get_32 (section->owner,
4604 + offset - var ('L')));
4608 rptr->addend = var ('V');
4612 /* Now that we've handled a "full" relocation, reset
4614 memset (variables, 0, sizeof (variables));
4615 memset (stack, 0, sizeof (stack));
4618 if (deallocate_contents)
4619 free (section->contents);
4629 /* Read in the relocs (aka fixups in SOM terms) for a section.
4631 som_get_reloc_upper_bound calls this routine with JUST_COUNT
4632 set to true to indicate it only needs a count of the number
4633 of actual relocations. */
4636 som_slurp_reloc_table (abfd, section, symbols, just_count)
4642 char *external_relocs;
4643 unsigned int fixup_stream_size;
4644 arelent *internal_relocs;
4645 unsigned int num_relocs;
4647 fixup_stream_size = som_section_data (section)->reloc_size;
4648 /* If there were no relocations, then there is nothing to do. */
4649 if (section->reloc_count == 0)
4652 /* If reloc_count is -1, then the relocation stream has not been
4653 parsed. We must do so now to know how many relocations exist. */
4654 if (section->reloc_count == -1)
4656 external_relocs = (char *) bfd_malloc (fixup_stream_size);
4657 if (external_relocs == (char *) NULL)
4659 /* Read in the external forms. */
4661 obj_som_reloc_filepos (abfd) + section->rel_filepos,
4665 if (bfd_read (external_relocs, 1, fixup_stream_size, abfd)
4666 != fixup_stream_size)
4669 /* Let callers know how many relocations found.
4670 also save the relocation stream as we will
4672 section->reloc_count = som_set_reloc_info (external_relocs,
4674 NULL, NULL, NULL, true);
4676 som_section_data (section)->reloc_stream = external_relocs;
4679 /* If the caller only wanted a count, then return now. */
4683 num_relocs = section->reloc_count;
4684 external_relocs = som_section_data (section)->reloc_stream;
4685 /* Return saved information about the relocations if it is available. */
4686 if (section->relocation != (arelent *) NULL)
4689 internal_relocs = (arelent *)
4690 bfd_zalloc (abfd, (num_relocs * sizeof (arelent)));
4691 if (internal_relocs == (arelent *) NULL)
4694 /* Process and internalize the relocations. */
4695 som_set_reloc_info (external_relocs, fixup_stream_size,
4696 internal_relocs, section, symbols, false);
4698 /* We're done with the external relocations. Free them. */
4699 free (external_relocs);
4700 som_section_data (section)->reloc_stream = NULL;
4702 /* Save our results and return success. */
4703 section->relocation = internal_relocs;
4707 /* Return the number of bytes required to store the relocation
4708 information associated with the given section. */
4711 som_get_reloc_upper_bound (abfd, asect)
4715 /* If section has relocations, then read in the relocation stream
4716 and parse it to determine how many relocations exist. */
4717 if (asect->flags & SEC_RELOC)
4719 if (! som_slurp_reloc_table (abfd, asect, NULL, true))
4721 return (asect->reloc_count + 1) * sizeof (arelent *);
4723 /* There are no relocations. */
4727 /* Convert relocations from SOM (external) form into BFD internal
4728 form. Return the number of relocations. */
4731 som_canonicalize_reloc (abfd, section, relptr, symbols)
4740 if (som_slurp_reloc_table (abfd, section, symbols, false) == false)
4743 count = section->reloc_count;
4744 tblptr = section->relocation;
4747 *relptr++ = tblptr++;
4749 *relptr = (arelent *) NULL;
4750 return section->reloc_count;
4753 extern const bfd_target som_vec;
4755 /* A hook to set up object file dependent section information. */
4758 som_new_section_hook (abfd, newsect)
4762 newsect->used_by_bfd =
4763 (PTR) bfd_zalloc (abfd, sizeof (struct som_section_data_struct));
4764 if (!newsect->used_by_bfd)
4766 newsect->alignment_power = 3;
4768 /* We allow more than three sections internally */
4772 /* Copy any private info we understand from the input symbol
4773 to the output symbol. */
4776 som_bfd_copy_private_symbol_data (ibfd, isymbol, obfd, osymbol)
4782 struct som_symbol *input_symbol = (struct som_symbol *) isymbol;
4783 struct som_symbol *output_symbol = (struct som_symbol *) osymbol;
4785 /* One day we may try to grok other private data. */
4786 if (ibfd->xvec->flavour != bfd_target_som_flavour
4787 || obfd->xvec->flavour != bfd_target_som_flavour)
4790 /* The only private information we need to copy is the argument relocation
4792 output_symbol->tc_data.hppa_arg_reloc = input_symbol->tc_data.hppa_arg_reloc;
4797 /* Copy any private info we understand from the input section
4798 to the output section. */
4800 som_bfd_copy_private_section_data (ibfd, isection, obfd, osection)
4806 /* One day we may try to grok other private data. */
4807 if (ibfd->xvec->flavour != bfd_target_som_flavour
4808 || obfd->xvec->flavour != bfd_target_som_flavour
4809 || (!som_is_space (isection) && !som_is_subspace (isection)))
4812 som_section_data (osection)->copy_data
4813 = (struct som_copyable_section_data_struct *)
4814 bfd_zalloc (obfd, sizeof (struct som_copyable_section_data_struct));
4815 if (som_section_data (osection)->copy_data == NULL)
4818 memcpy (som_section_data (osection)->copy_data,
4819 som_section_data (isection)->copy_data,
4820 sizeof (struct som_copyable_section_data_struct));
4822 /* Reparent if necessary. */
4823 if (som_section_data (osection)->copy_data->container)
4824 som_section_data (osection)->copy_data->container =
4825 som_section_data (osection)->copy_data->container->output_section;
4830 /* Copy any private info we understand from the input bfd
4831 to the output bfd. */
4834 som_bfd_copy_private_bfd_data (ibfd, obfd)
4837 /* One day we may try to grok other private data. */
4838 if (ibfd->xvec->flavour != bfd_target_som_flavour
4839 || obfd->xvec->flavour != bfd_target_som_flavour)
4842 /* Allocate some memory to hold the data we need. */
4843 obj_som_exec_data (obfd) = (struct som_exec_data *)
4844 bfd_zalloc (obfd, sizeof (struct som_exec_data));
4845 if (obj_som_exec_data (obfd) == NULL)
4848 /* Now copy the data. */
4849 memcpy (obj_som_exec_data (obfd), obj_som_exec_data (ibfd),
4850 sizeof (struct som_exec_data));
4855 /* Set backend info for sections which can not be described
4856 in the BFD data structures. */
4859 bfd_som_set_section_attributes (section, defined, private, sort_key, spnum)
4863 unsigned int sort_key;
4866 /* Allocate memory to hold the magic information. */
4867 if (som_section_data (section)->copy_data == NULL)
4869 som_section_data (section)->copy_data
4870 = (struct som_copyable_section_data_struct *)
4871 bfd_zalloc (section->owner,
4872 sizeof (struct som_copyable_section_data_struct));
4873 if (som_section_data (section)->copy_data == NULL)
4876 som_section_data (section)->copy_data->sort_key = sort_key;
4877 som_section_data (section)->copy_data->is_defined = defined;
4878 som_section_data (section)->copy_data->is_private = private;
4879 som_section_data (section)->copy_data->container = section;
4880 som_section_data (section)->copy_data->space_number = spnum;
4884 /* Set backend info for subsections which can not be described
4885 in the BFD data structures. */
4888 bfd_som_set_subsection_attributes (section, container, access,
4891 asection *container;
4893 unsigned int sort_key;
4896 /* Allocate memory to hold the magic information. */
4897 if (som_section_data (section)->copy_data == NULL)
4899 som_section_data (section)->copy_data
4900 = (struct som_copyable_section_data_struct *)
4901 bfd_zalloc (section->owner,
4902 sizeof (struct som_copyable_section_data_struct));
4903 if (som_section_data (section)->copy_data == NULL)
4906 som_section_data (section)->copy_data->sort_key = sort_key;
4907 som_section_data (section)->copy_data->access_control_bits = access;
4908 som_section_data (section)->copy_data->quadrant = quadrant;
4909 som_section_data (section)->copy_data->container = container;
4913 /* Set the full SOM symbol type. SOM needs far more symbol information
4914 than any other object file format I'm aware of. It is mandatory
4915 to be able to know if a symbol is an entry point, millicode, data,
4916 code, absolute, storage request, or procedure label. If you get
4917 the symbol type wrong your program will not link. */
4920 bfd_som_set_symbol_type (symbol, type)
4924 som_symbol_data (symbol)->som_type = type;
4927 /* Attach an auxiliary header to the BFD backend so that it may be
4928 written into the object file. */
4930 bfd_som_attach_aux_hdr (abfd, type, string)
4935 if (type == VERSION_AUX_ID)
4937 int len = strlen (string);
4941 pad = (4 - (len % 4));
4942 obj_som_version_hdr (abfd) = (struct user_string_aux_hdr *)
4943 bfd_zalloc (abfd, sizeof (struct aux_id)
4944 + sizeof (unsigned int) + len + pad);
4945 if (!obj_som_version_hdr (abfd))
4947 obj_som_version_hdr (abfd)->header_id.type = VERSION_AUX_ID;
4948 obj_som_version_hdr (abfd)->header_id.length = len + pad;
4949 obj_som_version_hdr (abfd)->header_id.length += sizeof (int);
4950 obj_som_version_hdr (abfd)->string_length = len;
4951 strncpy (obj_som_version_hdr (abfd)->user_string, string, len);
4953 else if (type == COPYRIGHT_AUX_ID)
4955 int len = strlen (string);
4959 pad = (4 - (len % 4));
4960 obj_som_copyright_hdr (abfd) = (struct copyright_aux_hdr *)
4961 bfd_zalloc (abfd, sizeof (struct aux_id)
4962 + sizeof (unsigned int) + len + pad);
4963 if (!obj_som_copyright_hdr (abfd))
4965 obj_som_copyright_hdr (abfd)->header_id.type = COPYRIGHT_AUX_ID;
4966 obj_som_copyright_hdr (abfd)->header_id.length = len + pad;
4967 obj_som_copyright_hdr (abfd)->header_id.length += sizeof (int);
4968 obj_som_copyright_hdr (abfd)->string_length = len;
4969 strcpy (obj_som_copyright_hdr (abfd)->copyright, string);
4975 som_get_section_contents (abfd, section, location, offset, count)
4980 bfd_size_type count;
4982 if (count == 0 || ((section->flags & SEC_HAS_CONTENTS) == 0))
4984 if ((bfd_size_type)(offset+count) > section->_raw_size
4985 || bfd_seek (abfd, (file_ptr)(section->filepos + offset), SEEK_SET) == -1
4986 || bfd_read (location, (bfd_size_type)1, count, abfd) != count)
4987 return (false); /* on error */
4992 som_set_section_contents (abfd, section, location, offset, count)
4997 bfd_size_type count;
4999 if (abfd->output_has_begun == false)
5001 /* Set up fixed parts of the file, space, and subspace headers.
5002 Notify the world that output has begun. */
5003 som_prep_headers (abfd);
5004 abfd->output_has_begun = true;
5005 /* Start writing the object file. This include all the string
5006 tables, fixup streams, and other portions of the object file. */
5007 som_begin_writing (abfd);
5010 /* Only write subspaces which have "real" contents (eg. the contents
5011 are not generated at run time by the OS). */
5012 if (!som_is_subspace (section)
5013 || ((section->flags & SEC_HAS_CONTENTS) == 0))
5016 /* Seek to the proper offset within the object file and write the
5018 offset += som_section_data (section)->subspace_dict->file_loc_init_value;
5019 if (bfd_seek (abfd, offset, SEEK_SET) == -1)
5022 if (bfd_write ((PTR) location, 1, count, abfd) != count)
5028 som_set_arch_mach (abfd, arch, machine)
5030 enum bfd_architecture arch;
5031 unsigned long machine;
5033 /* Allow any architecture to be supported by the SOM backend */
5034 return bfd_default_set_arch_mach (abfd, arch, machine);
5038 som_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
5039 functionname_ptr, line_ptr)
5044 CONST char **filename_ptr;
5045 CONST char **functionname_ptr;
5046 unsigned int *line_ptr;
5052 som_sizeof_headers (abfd, reloc)
5056 (*_bfd_error_handler) (_("som_sizeof_headers unimplemented"));
5062 /* Return the single-character symbol type corresponding to
5063 SOM section S, or '?' for an unknown SOM section. */
5066 som_section_type (s)
5069 const struct section_to_type *t;
5071 for (t = &stt[0]; t->section; t++)
5072 if (!strcmp (s, t->section))
5078 som_decode_symclass (symbol)
5083 if (bfd_is_com_section (symbol->section))
5085 if (bfd_is_und_section (symbol->section))
5087 if (bfd_is_ind_section (symbol->section))
5089 if (!(symbol->flags & (BSF_GLOBAL|BSF_LOCAL)))
5092 if (bfd_is_abs_section (symbol->section)
5093 || (som_symbol_data (symbol) != NULL
5094 && som_symbol_data (symbol)->som_type == SYMBOL_TYPE_ABSOLUTE))
5096 else if (symbol->section)
5097 c = som_section_type (symbol->section->name);
5100 if (symbol->flags & BSF_GLOBAL)
5105 /* Return information about SOM symbol SYMBOL in RET. */
5108 som_get_symbol_info (ignore_abfd, symbol, ret)
5113 ret->type = som_decode_symclass (symbol);
5114 if (ret->type != 'U')
5115 ret->value = symbol->value+symbol->section->vma;
5118 ret->name = symbol->name;
5121 /* Count the number of symbols in the archive symbol table. Necessary
5122 so that we can allocate space for all the carsyms at once. */
5125 som_bfd_count_ar_symbols (abfd, lst_header, count)
5127 struct lst_header *lst_header;
5131 unsigned int *hash_table = NULL;
5132 file_ptr lst_filepos = bfd_tell (abfd) - sizeof (struct lst_header);
5135 (unsigned int *) bfd_malloc (lst_header->hash_size
5136 * sizeof (unsigned int));
5137 if (hash_table == NULL && lst_header->hash_size != 0)
5140 /* Don't forget to initialize the counter! */
5143 /* Read in the hash table. The has table is an array of 32bit file offsets
5144 which point to the hash chains. */
5145 if (bfd_read ((PTR) hash_table, lst_header->hash_size, 4, abfd)
5146 != lst_header->hash_size * 4)
5149 /* Walk each chain counting the number of symbols found on that particular
5151 for (i = 0; i < lst_header->hash_size; i++)
5153 struct lst_symbol_record lst_symbol;
5155 /* An empty chain has zero as it's file offset. */
5156 if (hash_table[i] == 0)
5159 /* Seek to the first symbol in this hash chain. */
5160 if (bfd_seek (abfd, lst_filepos + hash_table[i], SEEK_SET) < 0)
5163 /* Read in this symbol and update the counter. */
5164 if (bfd_read ((PTR) & lst_symbol, 1, sizeof (lst_symbol), abfd)
5165 != sizeof (lst_symbol))
5170 /* Now iterate through the rest of the symbols on this chain. */
5171 while (lst_symbol.next_entry)
5174 /* Seek to the next symbol. */
5175 if (bfd_seek (abfd, lst_filepos + lst_symbol.next_entry, SEEK_SET)
5179 /* Read the symbol in and update the counter. */
5180 if (bfd_read ((PTR) & lst_symbol, 1, sizeof (lst_symbol), abfd)
5181 != sizeof (lst_symbol))
5187 if (hash_table != NULL)
5192 if (hash_table != NULL)
5197 /* Fill in the canonical archive symbols (SYMS) from the archive described
5198 by ABFD and LST_HEADER. */
5201 som_bfd_fill_in_ar_symbols (abfd, lst_header, syms)
5203 struct lst_header *lst_header;
5206 unsigned int i, len;
5207 carsym *set = syms[0];
5208 unsigned int *hash_table = NULL;
5209 struct som_entry *som_dict = NULL;
5210 file_ptr lst_filepos = bfd_tell (abfd) - sizeof (struct lst_header);
5213 (unsigned int *) bfd_malloc (lst_header->hash_size
5214 * sizeof (unsigned int));
5215 if (hash_table == NULL && lst_header->hash_size != 0)
5219 (struct som_entry *) bfd_malloc (lst_header->module_count
5220 * sizeof (struct som_entry));
5221 if (som_dict == NULL && lst_header->module_count != 0)
5224 /* Read in the hash table. The has table is an array of 32bit file offsets
5225 which point to the hash chains. */
5226 if (bfd_read ((PTR) hash_table, lst_header->hash_size, 4, abfd)
5227 != lst_header->hash_size * 4)
5230 /* Seek to and read in the SOM dictionary. We will need this to fill
5231 in the carsym's filepos field. */
5232 if (bfd_seek (abfd, lst_filepos + lst_header->dir_loc, SEEK_SET) < 0)
5235 if (bfd_read ((PTR) som_dict, lst_header->module_count,
5236 sizeof (struct som_entry), abfd)
5237 != lst_header->module_count * sizeof (struct som_entry))
5240 /* Walk each chain filling in the carsyms as we go along. */
5241 for (i = 0; i < lst_header->hash_size; i++)
5243 struct lst_symbol_record lst_symbol;
5245 /* An empty chain has zero as it's file offset. */
5246 if (hash_table[i] == 0)
5249 /* Seek to and read the first symbol on the chain. */
5250 if (bfd_seek (abfd, lst_filepos + hash_table[i], SEEK_SET) < 0)
5253 if (bfd_read ((PTR) & lst_symbol, 1, sizeof (lst_symbol), abfd)
5254 != sizeof (lst_symbol))
5257 /* Get the name of the symbol, first get the length which is stored
5258 as a 32bit integer just before the symbol.
5260 One might ask why we don't just read in the entire string table
5261 and index into it. Well, according to the SOM ABI the string
5262 index can point *anywhere* in the archive to save space, so just
5263 using the string table would not be safe. */
5264 if (bfd_seek (abfd, lst_filepos + lst_header->string_loc
5265 + lst_symbol.name.n_strx - 4, SEEK_SET) < 0)
5268 if (bfd_read (&len, 1, 4, abfd) != 4)
5271 /* Allocate space for the name and null terminate it too. */
5272 set->name = bfd_zalloc (abfd, len + 1);
5275 if (bfd_read (set->name, 1, len, abfd) != len)
5280 /* Fill in the file offset. Note that the "location" field points
5281 to the SOM itself, not the ar_hdr in front of it. */
5282 set->file_offset = som_dict[lst_symbol.som_index].location
5283 - sizeof (struct ar_hdr);
5285 /* Go to the next symbol. */
5288 /* Iterate through the rest of the chain. */
5289 while (lst_symbol.next_entry)
5291 /* Seek to the next symbol and read it in. */
5292 if (bfd_seek (abfd, lst_filepos + lst_symbol.next_entry, SEEK_SET) <0)
5295 if (bfd_read ((PTR) & lst_symbol, 1, sizeof (lst_symbol), abfd)
5296 != sizeof (lst_symbol))
5299 /* Seek to the name length & string and read them in. */
5300 if (bfd_seek (abfd, lst_filepos + lst_header->string_loc
5301 + lst_symbol.name.n_strx - 4, SEEK_SET) < 0)
5304 if (bfd_read (&len, 1, 4, abfd) != 4)
5307 /* Allocate space for the name and null terminate it too. */
5308 set->name = bfd_zalloc (abfd, len + 1);
5312 if (bfd_read (set->name, 1, len, abfd) != len)
5316 /* Fill in the file offset. Note that the "location" field points
5317 to the SOM itself, not the ar_hdr in front of it. */
5318 set->file_offset = som_dict[lst_symbol.som_index].location
5319 - sizeof (struct ar_hdr);
5321 /* Go on to the next symbol. */
5325 /* If we haven't died by now, then we successfully read the entire
5326 archive symbol table. */
5327 if (hash_table != NULL)
5329 if (som_dict != NULL)
5334 if (hash_table != NULL)
5336 if (som_dict != NULL)
5341 /* Read in the LST from the archive. */
5343 som_slurp_armap (abfd)
5346 struct lst_header lst_header;
5347 struct ar_hdr ar_header;
5348 unsigned int parsed_size;
5349 struct artdata *ardata = bfd_ardata (abfd);
5351 int i = bfd_read ((PTR) nextname, 1, 16, abfd);
5353 /* Special cases. */
5359 if (bfd_seek (abfd, (file_ptr) - 16, SEEK_CUR) < 0)
5362 /* For archives without .o files there is no symbol table. */
5363 if (strncmp (nextname, "/ ", 16))
5365 bfd_has_map (abfd) = false;
5369 /* Read in and sanity check the archive header. */
5370 if (bfd_read ((PTR) &ar_header, 1, sizeof (struct ar_hdr), abfd)
5371 != sizeof (struct ar_hdr))
5374 if (strncmp (ar_header.ar_fmag, ARFMAG, 2))
5376 bfd_set_error (bfd_error_malformed_archive);
5380 /* How big is the archive symbol table entry? */
5382 parsed_size = strtol (ar_header.ar_size, NULL, 10);
5385 bfd_set_error (bfd_error_malformed_archive);
5389 /* Save off the file offset of the first real user data. */
5390 ardata->first_file_filepos = bfd_tell (abfd) + parsed_size;
5392 /* Read in the library symbol table. We'll make heavy use of this
5393 in just a minute. */
5394 if (bfd_read ((PTR) & lst_header, 1, sizeof (struct lst_header), abfd)
5395 != sizeof (struct lst_header))
5399 if (lst_header.a_magic != LIBMAGIC)
5401 bfd_set_error (bfd_error_malformed_archive);
5405 /* Count the number of symbols in the library symbol table. */
5406 if (som_bfd_count_ar_symbols (abfd, &lst_header, &ardata->symdef_count)
5410 /* Get back to the start of the library symbol table. */
5411 if (bfd_seek (abfd, ardata->first_file_filepos - parsed_size
5412 + sizeof (struct lst_header), SEEK_SET) < 0)
5415 /* Initializae the cache and allocate space for the library symbols. */
5417 ardata->symdefs = (carsym *) bfd_alloc (abfd,
5418 (ardata->symdef_count
5419 * sizeof (carsym)));
5420 if (!ardata->symdefs)
5423 /* Now fill in the canonical archive symbols. */
5424 if (som_bfd_fill_in_ar_symbols (abfd, &lst_header, &ardata->symdefs)
5428 /* Seek back to the "first" file in the archive. Note the "first"
5429 file may be the extended name table. */
5430 if (bfd_seek (abfd, ardata->first_file_filepos, SEEK_SET) < 0)
5433 /* Notify the generic archive code that we have a symbol map. */
5434 bfd_has_map (abfd) = true;
5438 /* Begin preparing to write a SOM library symbol table.
5440 As part of the prep work we need to determine the number of symbols
5441 and the size of the associated string section. */
5444 som_bfd_prep_for_ar_write (abfd, num_syms, stringsize)
5446 unsigned int *num_syms, *stringsize;
5448 bfd *curr_bfd = abfd->archive_head;
5450 /* Some initialization. */
5454 /* Iterate over each BFD within this archive. */
5455 while (curr_bfd != NULL)
5457 unsigned int curr_count, i;
5458 som_symbol_type *sym;
5460 /* Don't bother for non-SOM objects. */
5461 if (curr_bfd->format != bfd_object
5462 || curr_bfd->xvec->flavour != bfd_target_som_flavour)
5464 curr_bfd = curr_bfd->next;
5468 /* Make sure the symbol table has been read, then snag a pointer
5469 to it. It's a little slimey to grab the symbols via obj_som_symtab,
5470 but doing so avoids allocating lots of extra memory. */
5471 if (som_slurp_symbol_table (curr_bfd) == false)
5474 sym = obj_som_symtab (curr_bfd);
5475 curr_count = bfd_get_symcount (curr_bfd);
5477 /* Examine each symbol to determine if it belongs in the
5478 library symbol table. */
5479 for (i = 0; i < curr_count; i++, sym++)
5481 struct som_misc_symbol_info info;
5483 /* Derive SOM information from the BFD symbol. */
5484 som_bfd_derive_misc_symbol_info (curr_bfd, &sym->symbol, &info);
5486 /* Should we include this symbol? */
5487 if (info.symbol_type == ST_NULL
5488 || info.symbol_type == ST_SYM_EXT
5489 || info.symbol_type == ST_ARG_EXT)
5492 /* Only global symbols and unsatisfied commons. */
5493 if (info.symbol_scope != SS_UNIVERSAL
5494 && info.symbol_type != ST_STORAGE)
5497 /* Do no include undefined symbols. */
5498 if (bfd_is_und_section (sym->symbol.section))
5501 /* Bump the various counters, being careful to honor
5502 alignment considerations in the string table. */
5504 *stringsize = *stringsize + strlen (sym->symbol.name) + 5;
5505 while (*stringsize % 4)
5509 curr_bfd = curr_bfd->next;
5514 /* Hash a symbol name based on the hashing algorithm presented in the
5517 som_bfd_ar_symbol_hash (symbol)
5520 unsigned int len = strlen (symbol->name);
5522 /* Names with length 1 are special. */
5524 return 0x1000100 | (symbol->name[0] << 16) | symbol->name[0];
5526 return ((len & 0x7f) << 24) | (symbol->name[1] << 16)
5527 | (symbol->name[len-2] << 8) | symbol->name[len-1];
5530 /* Do the bulk of the work required to write the SOM library
5534 som_bfd_ar_write_symbol_stuff (abfd, nsyms, string_size, lst, elength)
5536 unsigned int nsyms, string_size;
5537 struct lst_header lst;
5540 file_ptr lst_filepos;
5541 char *strings = NULL, *p;
5542 struct lst_symbol_record *lst_syms = NULL, *curr_lst_sym;
5544 unsigned int *hash_table = NULL;
5545 struct som_entry *som_dict = NULL;
5546 struct lst_symbol_record **last_hash_entry = NULL;
5547 unsigned int curr_som_offset, som_index = 0;
5550 (unsigned int *) bfd_malloc (lst.hash_size * sizeof (unsigned int));
5551 if (hash_table == NULL && lst.hash_size != 0)
5554 (struct som_entry *) bfd_malloc (lst.module_count
5555 * sizeof (struct som_entry));
5556 if (som_dict == NULL && lst.module_count != 0)
5560 ((struct lst_symbol_record **)
5561 bfd_malloc (lst.hash_size * sizeof (struct lst_symbol_record *)));
5562 if (last_hash_entry == NULL && lst.hash_size != 0)
5565 /* Lots of fields are file positions relative to the start
5566 of the lst record. So save its location. */
5567 lst_filepos = bfd_tell (abfd) - sizeof (struct lst_header);
5569 /* Some initialization. */
5570 memset (hash_table, 0, 4 * lst.hash_size);
5571 memset (som_dict, 0, lst.module_count * sizeof (struct som_entry));
5572 memset (last_hash_entry, 0,
5573 lst.hash_size * sizeof (struct lst_symbol_record *));
5575 /* Symbols have som_index fields, so we have to keep track of the
5576 index of each SOM in the archive.
5578 The SOM dictionary has (among other things) the absolute file
5579 position for the SOM which a particular dictionary entry
5580 describes. We have to compute that information as we iterate
5581 through the SOMs/symbols. */
5584 /* We add in the size of the archive header twice as the location
5585 in the SOM dictionary is the actual offset of the SOM, not the
5586 archive header before the SOM. */
5587 curr_som_offset = 8 + 2 * sizeof (struct ar_hdr) + lst.file_end;
5589 /* Make room for the archive header and the contents of the
5590 extended string table. Note that elength includes the size
5591 of the archive header for the extended name table! */
5593 curr_som_offset += elength;
5595 /* Make sure we're properly aligned. */
5596 curr_som_offset = (curr_som_offset + 0x1) & ~0x1;
5598 /* FIXME should be done with buffers just like everything else... */
5599 lst_syms = bfd_malloc (nsyms * sizeof (struct lst_symbol_record));
5600 if (lst_syms == NULL && nsyms != 0)
5602 strings = bfd_malloc (string_size);
5603 if (strings == NULL && string_size != 0)
5607 curr_lst_sym = lst_syms;
5609 curr_bfd = abfd->archive_head;
5610 while (curr_bfd != NULL)
5612 unsigned int curr_count, i;
5613 som_symbol_type *sym;
5615 /* Don't bother for non-SOM objects. */
5616 if (curr_bfd->format != bfd_object
5617 || curr_bfd->xvec->flavour != bfd_target_som_flavour)
5619 curr_bfd = curr_bfd->next;
5623 /* Make sure the symbol table has been read, then snag a pointer
5624 to it. It's a little slimey to grab the symbols via obj_som_symtab,
5625 but doing so avoids allocating lots of extra memory. */
5626 if (som_slurp_symbol_table (curr_bfd) == false)
5629 sym = obj_som_symtab (curr_bfd);
5630 curr_count = bfd_get_symcount (curr_bfd);
5632 for (i = 0; i < curr_count; i++, sym++)
5634 struct som_misc_symbol_info info;
5636 /* Derive SOM information from the BFD symbol. */
5637 som_bfd_derive_misc_symbol_info (curr_bfd, &sym->symbol, &info);
5639 /* Should we include this symbol? */
5640 if (info.symbol_type == ST_NULL
5641 || info.symbol_type == ST_SYM_EXT
5642 || info.symbol_type == ST_ARG_EXT)
5645 /* Only global symbols and unsatisfied commons. */
5646 if (info.symbol_scope != SS_UNIVERSAL
5647 && info.symbol_type != ST_STORAGE)
5650 /* Do no include undefined symbols. */
5651 if (bfd_is_und_section (sym->symbol.section))
5654 /* If this is the first symbol from this SOM, then update
5655 the SOM dictionary too. */
5656 if (som_dict[som_index].location == 0)
5658 som_dict[som_index].location = curr_som_offset;
5659 som_dict[som_index].length = arelt_size (curr_bfd);
5662 /* Fill in the lst symbol record. */
5663 curr_lst_sym->hidden = 0;
5664 curr_lst_sym->secondary_def = 0;
5665 curr_lst_sym->symbol_type = info.symbol_type;
5666 curr_lst_sym->symbol_scope = info.symbol_scope;
5667 curr_lst_sym->check_level = 0;
5668 curr_lst_sym->must_qualify = 0;
5669 curr_lst_sym->initially_frozen = 0;
5670 curr_lst_sym->memory_resident = 0;
5671 curr_lst_sym->is_common = bfd_is_com_section (sym->symbol.section);
5672 curr_lst_sym->dup_common = 0;
5673 curr_lst_sym->xleast = 0;
5674 curr_lst_sym->arg_reloc = info.arg_reloc;
5675 curr_lst_sym->name.n_strx = p - strings + 4;
5676 curr_lst_sym->qualifier_name.n_strx = 0;
5677 curr_lst_sym->symbol_info = info.symbol_info;
5678 curr_lst_sym->symbol_value = info.symbol_value;
5679 curr_lst_sym->symbol_descriptor = 0;
5680 curr_lst_sym->reserved = 0;
5681 curr_lst_sym->som_index = som_index;
5682 curr_lst_sym->symbol_key = som_bfd_ar_symbol_hash (&sym->symbol);
5683 curr_lst_sym->next_entry = 0;
5685 /* Insert into the hash table. */
5686 if (hash_table[curr_lst_sym->symbol_key % lst.hash_size])
5688 struct lst_symbol_record *tmp;
5690 /* There is already something at the head of this hash chain,
5691 so tack this symbol onto the end of the chain. */
5692 tmp = last_hash_entry[curr_lst_sym->symbol_key % lst.hash_size];
5694 = (curr_lst_sym - lst_syms) * sizeof (struct lst_symbol_record)
5696 + lst.module_count * sizeof (struct som_entry)
5697 + sizeof (struct lst_header);
5701 /* First entry in this hash chain. */
5702 hash_table[curr_lst_sym->symbol_key % lst.hash_size]
5703 = (curr_lst_sym - lst_syms) * sizeof (struct lst_symbol_record)
5705 + lst.module_count * sizeof (struct som_entry)
5706 + sizeof (struct lst_header);
5709 /* Keep track of the last symbol we added to this chain so we can
5710 easily update its next_entry pointer. */
5711 last_hash_entry[curr_lst_sym->symbol_key % lst.hash_size]
5715 /* Update the string table. */
5716 bfd_put_32 (abfd, strlen (sym->symbol.name), p);
5718 strcpy (p, sym->symbol.name);
5719 p += strlen (sym->symbol.name) + 1;
5722 bfd_put_8 (abfd, 0, p);
5726 /* Head to the next symbol. */
5730 /* Keep track of where each SOM will finally reside; then look
5732 curr_som_offset += arelt_size (curr_bfd) + sizeof (struct ar_hdr);
5734 /* A particular object in the archive may have an odd length; the
5735 linker requires objects begin on an even boundary. So round
5736 up the current offset as necessary. */
5737 curr_som_offset = (curr_som_offset + 0x1) & ~0x1;
5738 curr_bfd = curr_bfd->next;
5742 /* Now scribble out the hash table. */
5743 if (bfd_write ((PTR) hash_table, lst.hash_size, 4, abfd)
5744 != lst.hash_size * 4)
5747 /* Then the SOM dictionary. */
5748 if (bfd_write ((PTR) som_dict, lst.module_count,
5749 sizeof (struct som_entry), abfd)
5750 != lst.module_count * sizeof (struct som_entry))
5753 /* The library symbols. */
5754 if (bfd_write ((PTR) lst_syms, nsyms, sizeof (struct lst_symbol_record), abfd)
5755 != nsyms * sizeof (struct lst_symbol_record))
5758 /* And finally the strings. */
5759 if (bfd_write ((PTR) strings, string_size, 1, abfd) != string_size)
5762 if (hash_table != NULL)
5764 if (som_dict != NULL)
5766 if (last_hash_entry != NULL)
5767 free (last_hash_entry);
5768 if (lst_syms != NULL)
5770 if (strings != NULL)
5775 if (hash_table != NULL)
5777 if (som_dict != NULL)
5779 if (last_hash_entry != NULL)
5780 free (last_hash_entry);
5781 if (lst_syms != NULL)
5783 if (strings != NULL)
5789 /* Write out the LST for the archive.
5791 You'll never believe this is really how armaps are handled in SOM... */
5795 som_write_armap (abfd, elength, map, orl_count, stridx)
5797 unsigned int elength;
5799 unsigned int orl_count;
5803 struct stat statbuf;
5804 unsigned int i, lst_size, nsyms, stringsize;
5806 struct lst_header lst;
5809 /* We'll use this for the archive's date and mode later. */
5810 if (stat (abfd->filename, &statbuf) != 0)
5812 bfd_set_error (bfd_error_system_call);
5816 bfd_ardata (abfd)->armap_timestamp = statbuf.st_mtime + 60;
5818 /* Account for the lst header first. */
5819 lst_size = sizeof (struct lst_header);
5821 /* Start building the LST header. */
5822 /* FIXME: Do we need to examine each element to determine the
5823 largest id number? */
5824 lst.system_id = CPU_PA_RISC1_0;
5825 lst.a_magic = LIBMAGIC;
5826 lst.version_id = VERSION_ID;
5827 lst.file_time.secs = 0;
5828 lst.file_time.nanosecs = 0;
5830 lst.hash_loc = lst_size;
5831 lst.hash_size = SOM_LST_HASH_SIZE;
5833 /* Hash table is a SOM_LST_HASH_SIZE 32bit offsets. */
5834 lst_size += 4 * SOM_LST_HASH_SIZE;
5836 /* We need to count the number of SOMs in this archive. */
5837 curr_bfd = abfd->archive_head;
5838 lst.module_count = 0;
5839 while (curr_bfd != NULL)
5841 /* Only true SOM objects count. */
5842 if (curr_bfd->format == bfd_object
5843 && curr_bfd->xvec->flavour == bfd_target_som_flavour)
5845 curr_bfd = curr_bfd->next;
5847 lst.module_limit = lst.module_count;
5848 lst.dir_loc = lst_size;
5849 lst_size += sizeof (struct som_entry) * lst.module_count;
5851 /* We don't support import/export tables, auxiliary headers,
5852 or free lists yet. Make the linker work a little harder
5853 to make our life easier. */
5856 lst.export_count = 0;
5861 /* Count how many symbols we will have on the hash chains and the
5862 size of the associated string table. */
5863 if (som_bfd_prep_for_ar_write (abfd, &nsyms, &stringsize) == false)
5866 lst_size += sizeof (struct lst_symbol_record) * nsyms;
5868 /* For the string table. One day we might actually use this info
5869 to avoid small seeks/reads when reading archives. */
5870 lst.string_loc = lst_size;
5871 lst.string_size = stringsize;
5872 lst_size += stringsize;
5874 /* SOM ABI says this must be zero. */
5876 lst.file_end = lst_size;
5878 /* Compute the checksum. Must happen after the entire lst header
5882 for (i = 0; i < sizeof (struct lst_header)/sizeof (int) - 1; i++)
5883 lst.checksum ^= *p++;
5885 sprintf (hdr.ar_name, "/ ");
5886 sprintf (hdr.ar_date, "%ld", bfd_ardata (abfd)->armap_timestamp);
5887 sprintf (hdr.ar_uid, "%ld", (long) getuid ());
5888 sprintf (hdr.ar_gid, "%ld", (long) getgid ());
5889 sprintf (hdr.ar_mode, "%-8o", (unsigned int) statbuf.st_mode);
5890 sprintf (hdr.ar_size, "%-10d", (int) lst_size);
5891 hdr.ar_fmag[0] = '`';
5892 hdr.ar_fmag[1] = '\012';
5894 /* Turn any nulls into spaces. */
5895 for (i = 0; i < sizeof (struct ar_hdr); i++)
5896 if (((char *) (&hdr))[i] == '\0')
5897 (((char *) (&hdr))[i]) = ' ';
5899 /* Scribble out the ar header. */
5900 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd)
5901 != sizeof (struct ar_hdr))
5904 /* Now scribble out the lst header. */
5905 if (bfd_write ((PTR) &lst, 1, sizeof (struct lst_header), abfd)
5906 != sizeof (struct lst_header))
5909 /* Build and write the armap. */
5910 if (som_bfd_ar_write_symbol_stuff (abfd, nsyms, stringsize, lst, elength)
5918 /* Free all information we have cached for this BFD. We can always
5919 read it again later if we need it. */
5922 som_bfd_free_cached_info (abfd)
5927 if (bfd_get_format (abfd) != bfd_object)
5930 #define FREE(x) if (x != NULL) { free (x); x = NULL; }
5931 /* Free the native string and symbol tables. */
5932 FREE (obj_som_symtab (abfd));
5933 FREE (obj_som_stringtab (abfd));
5934 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
5936 /* Free the native relocations. */
5937 o->reloc_count = -1;
5938 FREE (som_section_data (o)->reloc_stream);
5939 /* Free the generic relocations. */
5940 FREE (o->relocation);
5947 /* End of miscellaneous support functions. */
5949 /* Linker support functions. */
5951 som_bfd_link_split_section (abfd, sec)
5955 return (som_is_subspace (sec) && sec->_raw_size > 240000);
5958 #define som_close_and_cleanup som_bfd_free_cached_info
5960 #define som_read_ar_hdr _bfd_generic_read_ar_hdr
5961 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
5962 #define som_get_elt_at_index _bfd_generic_get_elt_at_index
5963 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
5964 #define som_truncate_arname bfd_bsd_truncate_arname
5965 #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
5966 #define som_construct_extended_name_table \
5967 _bfd_archive_coff_construct_extended_name_table
5968 #define som_update_armap_timestamp bfd_true
5969 #define som_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
5971 #define som_get_lineno _bfd_nosymbols_get_lineno
5972 #define som_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
5973 #define som_read_minisymbols _bfd_generic_read_minisymbols
5974 #define som_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
5975 #define som_get_section_contents_in_window \
5976 _bfd_generic_get_section_contents_in_window
5978 #define som_bfd_get_relocated_section_contents \
5979 bfd_generic_get_relocated_section_contents
5980 #define som_bfd_relax_section bfd_generic_relax_section
5981 #define som_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
5982 #define som_bfd_link_add_symbols _bfd_generic_link_add_symbols
5983 #define som_bfd_final_link _bfd_generic_final_link
5985 #define som_bfd_gc_sections bfd_generic_gc_sections
5988 const bfd_target som_vec =
5991 bfd_target_som_flavour,
5992 BFD_ENDIAN_BIG, /* target byte order */
5993 BFD_ENDIAN_BIG, /* target headers byte order */
5994 (HAS_RELOC | EXEC_P | /* object flags */
5995 HAS_LINENO | HAS_DEBUG |
5996 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | DYNAMIC),
5997 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
5998 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
6000 /* leading_symbol_char: is the first char of a user symbol
6001 predictable, and if so what is it */
6003 '/', /* ar_pad_char */
6004 14, /* ar_max_namelen */
6005 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
6006 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
6007 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
6008 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
6009 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
6010 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
6012 som_object_p, /* bfd_check_format */
6013 bfd_generic_archive_p,
6019 _bfd_generic_mkarchive,
6024 som_write_object_contents,
6025 _bfd_write_archive_contents,
6030 BFD_JUMP_TABLE_GENERIC (som),
6031 BFD_JUMP_TABLE_COPY (som),
6032 BFD_JUMP_TABLE_CORE (_bfd_nocore),
6033 BFD_JUMP_TABLE_ARCHIVE (som),
6034 BFD_JUMP_TABLE_SYMBOLS (som),
6035 BFD_JUMP_TABLE_RELOCS (som),
6036 BFD_JUMP_TABLE_WRITE (som),
6037 BFD_JUMP_TABLE_LINK (som),
6038 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
6043 #endif /* HOST_HPPAHPUX || HOST_HPPABSD || HOST_HPPAOSF */