1 /* bfd back-end for HP PA-RISC SOM objects.
2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 Contributed by the Center for Software Science at the
5 University of Utah (pa-gdb-bugs@cs.utah.edu).
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF)
32 #include <sys/types.h>
33 #include <sys/param.h>
36 #include <machine/reg.h>
37 #include <sys/user.h> /* After a.out.h */
41 /* Magic not defined in standard HP-UX header files until 8.0 */
43 #ifndef CPU_PA_RISC1_0
44 #define CPU_PA_RISC1_0 0x20B
45 #endif /* CPU_PA_RISC1_0 */
47 #ifndef CPU_PA_RISC1_1
48 #define CPU_PA_RISC1_1 0x210
49 #endif /* CPU_PA_RISC1_1 */
51 #ifndef _PA_RISC1_0_ID
52 #define _PA_RISC1_0_ID CPU_PA_RISC1_0
53 #endif /* _PA_RISC1_0_ID */
55 #ifndef _PA_RISC1_1_ID
56 #define _PA_RISC1_1_ID CPU_PA_RISC1_1
57 #endif /* _PA_RISC1_1_ID */
59 #ifndef _PA_RISC_MAXID
60 #define _PA_RISC_MAXID 0x2FF
61 #endif /* _PA_RISC_MAXID */
64 #define _PA_RISC_ID(__m_num) \
65 (((__m_num) == _PA_RISC1_0_ID) || \
66 ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
67 #endif /* _PA_RISC_ID */
69 /* Size (in chars) of the temporary buffers used during fixup and string
72 #define SOM_TMP_BUFSIZE 8192
74 /* Size of the hash table in archives. */
75 #define SOM_LST_HASH_SIZE 31
77 /* Max number of SOMs to be found in an archive. */
78 #define SOM_LST_MODULE_LIMIT 1024
80 /* Generic alignment macro. */
81 #define SOM_ALIGN(val, alignment) \
82 (((val) + (alignment) - 1) & ~((alignment) - 1))
84 /* SOM allows any one of the four previous relocations to be reused
85 with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
86 relocations are always a single byte, using a R_PREV_FIXUP instead
87 of some multi-byte relocation makes object files smaller.
89 Note one side effect of using a R_PREV_FIXUP is the relocation that
90 is being repeated moves to the front of the queue. */
97 /* This fully describes the symbol types which may be attached to
98 an EXPORT or IMPORT directive. Only SOM uses this formation
99 (ELF has no need for it). */
103 SYMBOL_TYPE_ABSOLUTE
,
107 SYMBOL_TYPE_MILLICODE
,
109 SYMBOL_TYPE_PRI_PROG
,
110 SYMBOL_TYPE_SEC_PROG
,
113 struct section_to_type
119 /* Assorted symbol information that needs to be derived from the BFD symbol
120 and/or the BFD backend private symbol data. */
121 struct som_misc_symbol_info
123 unsigned int symbol_type
;
124 unsigned int symbol_scope
;
125 unsigned int arg_reloc
;
126 unsigned int symbol_info
;
127 unsigned int symbol_value
;
130 /* Forward declarations */
132 static boolean som_mkobject
PARAMS ((bfd
*));
133 static bfd_target
* som_object_setup
PARAMS ((bfd
*,
135 struct som_exec_auxhdr
*));
136 static asection
* make_unique_section
PARAMS ((bfd
*, CONST
char *, int));
137 static boolean setup_sections
PARAMS ((bfd
*, struct header
*));
138 static bfd_target
* som_object_p
PARAMS ((bfd
*));
139 static boolean som_write_object_contents
PARAMS ((bfd
*));
140 static boolean som_slurp_string_table
PARAMS ((bfd
*));
141 static unsigned int som_slurp_symbol_table
PARAMS ((bfd
*));
142 static unsigned int som_get_symtab_upper_bound
PARAMS ((bfd
*));
143 static unsigned int som_canonicalize_reloc
PARAMS ((bfd
*, sec_ptr
,
144 arelent
**, asymbol
**));
145 static unsigned int som_get_reloc_upper_bound
PARAMS ((bfd
*, sec_ptr
));
146 static unsigned int som_set_reloc_info
PARAMS ((unsigned char *, unsigned int,
147 arelent
*, asection
*,
148 asymbol
**, boolean
));
149 static boolean som_slurp_reloc_table
PARAMS ((bfd
*, asection
*,
150 asymbol
**, boolean
));
151 static unsigned int som_get_symtab
PARAMS ((bfd
*, asymbol
**));
152 static asymbol
* som_make_empty_symbol
PARAMS ((bfd
*));
153 static void som_print_symbol
PARAMS ((bfd
*, PTR
,
154 asymbol
*, bfd_print_symbol_type
));
155 static boolean som_new_section_hook
PARAMS ((bfd
*, asection
*));
156 static boolean som_bfd_copy_private_section_data
PARAMS ((bfd
*, asection
*,
158 static boolean som_bfd_is_local_label
PARAMS ((bfd
*, asymbol
*));
159 static boolean som_set_section_contents
PARAMS ((bfd
*, sec_ptr
, PTR
,
160 file_ptr
, bfd_size_type
));
161 static boolean som_set_arch_mach
PARAMS ((bfd
*, enum bfd_architecture
,
163 static boolean som_find_nearest_line
PARAMS ((bfd
*, asection
*,
168 static void som_get_symbol_info
PARAMS ((bfd
*, asymbol
*, symbol_info
*));
169 static asection
* som_section_from_subspace_index
PARAMS ((bfd
*,
171 static int log2
PARAMS ((unsigned int));
172 static bfd_reloc_status_type hppa_som_reloc
PARAMS ((bfd
*, arelent
*,
176 static void som_initialize_reloc_queue
PARAMS ((struct reloc_queue
*));
177 static void som_reloc_queue_insert
PARAMS ((unsigned char *, unsigned int,
178 struct reloc_queue
*));
179 static void som_reloc_queue_fix
PARAMS ((struct reloc_queue
*, unsigned int));
180 static int som_reloc_queue_find
PARAMS ((unsigned char *, unsigned int,
181 struct reloc_queue
*));
182 static unsigned char * try_prev_fixup
PARAMS ((bfd
*, int *, unsigned char *,
184 struct reloc_queue
*));
186 static unsigned char * som_reloc_skip
PARAMS ((bfd
*, unsigned int,
187 unsigned char *, unsigned int *,
188 struct reloc_queue
*));
189 static unsigned char * som_reloc_addend
PARAMS ((bfd
*, int, unsigned char *,
191 struct reloc_queue
*));
192 static unsigned char * som_reloc_call
PARAMS ((bfd
*, unsigned char *,
195 struct reloc_queue
*));
196 static unsigned long som_count_spaces
PARAMS ((bfd
*));
197 static unsigned long som_count_subspaces
PARAMS ((bfd
*));
198 static int compare_syms
PARAMS ((asymbol
**, asymbol
**));
199 static unsigned long som_compute_checksum
PARAMS ((bfd
*));
200 static boolean som_prep_headers
PARAMS ((bfd
*));
201 static int som_sizeof_headers
PARAMS ((bfd
*, boolean
));
202 static boolean som_write_headers
PARAMS ((bfd
*));
203 static boolean som_build_and_write_symbol_table
PARAMS ((bfd
*));
204 static void som_prep_for_fixups
PARAMS ((bfd
*, asymbol
**, unsigned long));
205 static boolean som_write_fixups
PARAMS ((bfd
*, unsigned long, unsigned int *));
206 static boolean som_write_space_strings
PARAMS ((bfd
*, unsigned long,
208 static boolean som_write_symbol_strings
PARAMS ((bfd
*, unsigned long,
209 asymbol
**, unsigned int,
211 static boolean som_begin_writing
PARAMS ((bfd
*));
212 static const reloc_howto_type
* som_bfd_reloc_type_lookup
213 PARAMS ((bfd_arch_info_type
*, bfd_reloc_code_real_type
));
214 static char som_section_type
PARAMS ((const char *));
215 static int som_decode_symclass
PARAMS ((asymbol
*));
216 static boolean som_bfd_count_ar_symbols
PARAMS ((bfd
*, struct lst_header
*,
219 static boolean som_bfd_fill_in_ar_symbols
PARAMS ((bfd
*, struct lst_header
*,
221 static boolean som_slurp_armap
PARAMS ((bfd
*));
222 static boolean som_write_armap
PARAMS ((bfd
*));
223 static void som_bfd_derive_misc_symbol_info
PARAMS ((bfd
*, asymbol
*,
224 struct som_misc_symbol_info
*));
225 static boolean som_bfd_prep_for_ar_write
PARAMS ((bfd
*, unsigned int *,
227 static unsigned int som_bfd_ar_symbol_hash
PARAMS ((asymbol
*));
228 static boolean som_bfd_ar_write_symbol_stuff
PARAMS ((bfd
*, unsigned int,
231 static CONST
char *normalize
PARAMS ((CONST
char *file
));
233 /* Map SOM section names to POSIX/BSD single-character symbol types.
235 This table includes all the standard subspaces as defined in the
236 current "PRO ABI for PA-RISC Systems", $UNWIND$ which for
237 some reason was left out, and sections specific to embedded stabs. */
239 static const struct section_to_type stt
[] = {
241 {"$SHLIB_INFO$", 't'},
242 {"$MILLICODE$", 't'},
245 {"$UNWIND_START$", 't'},
249 {"$SHLIB_DATA$", 'd'},
251 {"$SHORTDATA$", 'g'},
256 {"$GDB_STRINGS$", 'N'},
257 {"$GDB_SYMBOLS$", 'N'},
261 /* About the relocation formatting table...
263 There are 256 entries in the table, one for each possible
264 relocation opcode available in SOM. We index the table by
265 the relocation opcode. The names and operations are those
266 defined by a.out_800 (4).
268 Right now this table is only used to count and perform minimal
269 processing on relocation streams so that they can be internalized
270 into BFD and symbolically printed by utilities. To make actual use
271 of them would be much more difficult, BFD's concept of relocations
272 is far too simple to handle SOM relocations. The basic assumption
273 that a relocation can be completely processed independent of other
274 relocations before an object file is written is invalid for SOM.
276 The SOM relocations are meant to be processed as a stream, they
277 specify copying of data from the input section to the output section
278 while possibly modifying the data in some manner. They also can
279 specify that a variable number of zeros or uninitialized data be
280 inserted on in the output segment at the current offset. Some
281 relocations specify that some previous relocation be re-applied at
282 the current location in the input/output sections. And finally a number
283 of relocations have effects on other sections (R_ENTRY, R_EXIT,
284 R_UNWIND_AUX and a variety of others). There isn't even enough room
285 in the BFD relocation data structure to store enough information to
286 perform all the relocations.
288 Each entry in the table has three fields.
290 The first entry is an index into this "class" of relocations. This
291 index can then be used as a variable within the relocation itself.
293 The second field is a format string which actually controls processing
294 of the relocation. It uses a simple postfix machine to do calculations
295 based on variables/constants found in the string and the relocation
298 The third field specifys whether or not this relocation may use
299 a constant (V) from the previous R_DATA_OVERRIDE rather than a constant
300 stored in the instruction.
304 L = input space byte count
305 D = index into class of relocations
306 M = output space byte count
307 N = statement number (unused?)
309 R = parameter relocation bits
311 U = 64 bits of stack unwind and frame size info (we only keep 32 bits)
312 V = a literal constant (usually used in the next relocation)
313 P = a previous relocation
315 Lower case letters (starting with 'b') refer to following
316 bytes in the relocation stream. 'b' is the next 1 byte,
317 c is the next 2 bytes, d is the next 3 bytes, etc...
318 This is the variable part of the relocation entries that
319 makes our life a living hell.
321 numerical constants are also used in the format string. Note
322 the constants are represented in decimal.
324 '+', "*" and "=" represents the obvious postfix operators.
325 '<' represents a left shift.
329 Parameter Relocation Bits:
333 Previous Relocations: The index field represents which in the queue
334 of 4 previous fixups should be re-applied.
336 Literal Constants: These are generally used to represent addend
337 parts of relocations when these constants are not stored in the
338 fields of the instructions themselves. For example the instruction
339 addil foo-$global$-0x1234 would use an override for "0x1234" rather
340 than storing it into the addil itself. */
348 static const struct fixup_format som_fixup_formats
[256] =
350 /* R_NO_RELOCATION */
351 0, "LD1+4*=", /* 0x00 */
352 1, "LD1+4*=", /* 0x01 */
353 2, "LD1+4*=", /* 0x02 */
354 3, "LD1+4*=", /* 0x03 */
355 4, "LD1+4*=", /* 0x04 */
356 5, "LD1+4*=", /* 0x05 */
357 6, "LD1+4*=", /* 0x06 */
358 7, "LD1+4*=", /* 0x07 */
359 8, "LD1+4*=", /* 0x08 */
360 9, "LD1+4*=", /* 0x09 */
361 10, "LD1+4*=", /* 0x0a */
362 11, "LD1+4*=", /* 0x0b */
363 12, "LD1+4*=", /* 0x0c */
364 13, "LD1+4*=", /* 0x0d */
365 14, "LD1+4*=", /* 0x0e */
366 15, "LD1+4*=", /* 0x0f */
367 16, "LD1+4*=", /* 0x10 */
368 17, "LD1+4*=", /* 0x11 */
369 18, "LD1+4*=", /* 0x12 */
370 19, "LD1+4*=", /* 0x13 */
371 20, "LD1+4*=", /* 0x14 */
372 21, "LD1+4*=", /* 0x15 */
373 22, "LD1+4*=", /* 0x16 */
374 23, "LD1+4*=", /* 0x17 */
375 0, "LD8<b+1+4*=", /* 0x18 */
376 1, "LD8<b+1+4*=", /* 0x19 */
377 2, "LD8<b+1+4*=", /* 0x1a */
378 3, "LD8<b+1+4*=", /* 0x1b */
379 0, "LD16<c+1+4*=", /* 0x1c */
380 1, "LD16<c+1+4*=", /* 0x1d */
381 2, "LD16<c+1+4*=", /* 0x1e */
382 0, "Ld1+=", /* 0x1f */
384 0, "Lb1+4*=", /* 0x20 */
385 1, "Ld1+=", /* 0x21 */
387 0, "Lb1+4*=", /* 0x22 */
388 1, "Ld1+=", /* 0x23 */
391 /* R_DATA_ONE_SYMBOL */
392 0, "L4=Sb=", /* 0x25 */
393 1, "L4=Sd=", /* 0x26 */
395 0, "L4=Sb=", /* 0x27 */
396 1, "L4=Sd=", /* 0x28 */
399 /* R_REPEATED_INIT */
400 0, "L4=Mb1+4*=", /* 0x2a */
401 1, "Lb4*=Mb1+L*=", /* 0x2b */
402 2, "Lb4*=Md1+4*=", /* 0x2c */
403 3, "Ld1+=Me1+=", /* 0x2d */
408 0, "L4=RD=Sb=", /* 0x30 */
409 1, "L4=RD=Sb=", /* 0x31 */
410 2, "L4=RD=Sb=", /* 0x32 */
411 3, "L4=RD=Sb=", /* 0x33 */
412 4, "L4=RD=Sb=", /* 0x34 */
413 5, "L4=RD=Sb=", /* 0x35 */
414 6, "L4=RD=Sb=", /* 0x36 */
415 7, "L4=RD=Sb=", /* 0x37 */
416 8, "L4=RD=Sb=", /* 0x38 */
417 9, "L4=RD=Sb=", /* 0x39 */
418 0, "L4=RD8<b+=Sb=",/* 0x3a */
419 1, "L4=RD8<b+=Sb=",/* 0x3b */
420 0, "L4=RD8<b+=Sd=",/* 0x3c */
421 1, "L4=RD8<b+=Sd=",/* 0x3d */
426 0, "L4=RD=Sb=", /* 0x40 */
427 1, "L4=RD=Sb=", /* 0x41 */
428 2, "L4=RD=Sb=", /* 0x42 */
429 3, "L4=RD=Sb=", /* 0x43 */
430 4, "L4=RD=Sb=", /* 0x44 */
431 5, "L4=RD=Sb=", /* 0x45 */
432 6, "L4=RD=Sb=", /* 0x46 */
433 7, "L4=RD=Sb=", /* 0x47 */
434 8, "L4=RD=Sb=", /* 0x48 */
435 9, "L4=RD=Sb=", /* 0x49 */
436 0, "L4=RD8<b+=Sb=",/* 0x4a */
437 1, "L4=RD8<b+=Sb=",/* 0x4b */
438 0, "L4=RD8<b+=Sd=",/* 0x4c */
439 1, "L4=RD8<b+=Sd=",/* 0x4d */
444 0, "L4=SD=", /* 0x50 */
445 1, "L4=SD=", /* 0x51 */
446 2, "L4=SD=", /* 0x52 */
447 3, "L4=SD=", /* 0x53 */
448 4, "L4=SD=", /* 0x54 */
449 5, "L4=SD=", /* 0x55 */
450 6, "L4=SD=", /* 0x56 */
451 7, "L4=SD=", /* 0x57 */
452 8, "L4=SD=", /* 0x58 */
453 9, "L4=SD=", /* 0x59 */
454 10, "L4=SD=", /* 0x5a */
455 11, "L4=SD=", /* 0x5b */
456 12, "L4=SD=", /* 0x5c */
457 13, "L4=SD=", /* 0x5d */
458 14, "L4=SD=", /* 0x5e */
459 15, "L4=SD=", /* 0x5f */
460 16, "L4=SD=", /* 0x60 */
461 17, "L4=SD=", /* 0x61 */
462 18, "L4=SD=", /* 0x62 */
463 19, "L4=SD=", /* 0x63 */
464 20, "L4=SD=", /* 0x64 */
465 21, "L4=SD=", /* 0x65 */
466 22, "L4=SD=", /* 0x66 */
467 23, "L4=SD=", /* 0x67 */
468 24, "L4=SD=", /* 0x68 */
469 25, "L4=SD=", /* 0x69 */
470 26, "L4=SD=", /* 0x6a */
471 27, "L4=SD=", /* 0x6b */
472 28, "L4=SD=", /* 0x6c */
473 29, "L4=SD=", /* 0x6d */
474 30, "L4=SD=", /* 0x6e */
475 31, "L4=SD=", /* 0x6f */
476 32, "L4=Sb=", /* 0x70 */
477 33, "L4=Sd=", /* 0x71 */
486 0, "L4=Sb=", /* 0x78 */
487 1, "L4=Sd=", /* 0x79 */
495 /* R_CODE_ONE_SYMBOL */
496 0, "L4=SD=", /* 0x80 */
497 1, "L4=SD=", /* 0x81 */
498 2, "L4=SD=", /* 0x82 */
499 3, "L4=SD=", /* 0x83 */
500 4, "L4=SD=", /* 0x84 */
501 5, "L4=SD=", /* 0x85 */
502 6, "L4=SD=", /* 0x86 */
503 7, "L4=SD=", /* 0x87 */
504 8, "L4=SD=", /* 0x88 */
505 9, "L4=SD=", /* 0x89 */
506 10, "L4=SD=", /* 0x8q */
507 11, "L4=SD=", /* 0x8b */
508 12, "L4=SD=", /* 0x8c */
509 13, "L4=SD=", /* 0x8d */
510 14, "L4=SD=", /* 0x8e */
511 15, "L4=SD=", /* 0x8f */
512 16, "L4=SD=", /* 0x90 */
513 17, "L4=SD=", /* 0x91 */
514 18, "L4=SD=", /* 0x92 */
515 19, "L4=SD=", /* 0x93 */
516 20, "L4=SD=", /* 0x94 */
517 21, "L4=SD=", /* 0x95 */
518 22, "L4=SD=", /* 0x96 */
519 23, "L4=SD=", /* 0x97 */
520 24, "L4=SD=", /* 0x98 */
521 25, "L4=SD=", /* 0x99 */
522 26, "L4=SD=", /* 0x9a */
523 27, "L4=SD=", /* 0x9b */
524 28, "L4=SD=", /* 0x9c */
525 29, "L4=SD=", /* 0x9d */
526 30, "L4=SD=", /* 0x9e */
527 31, "L4=SD=", /* 0x9f */
528 32, "L4=Sb=", /* 0xa0 */
529 33, "L4=Sd=", /* 0xa1 */
544 0, "L4=Sb=", /* 0xae */
545 1, "L4=Sd=", /* 0xaf */
547 0, "L4=Sb=", /* 0xb0 */
548 1, "L4=Sd=", /* 0xb1 */
562 1, "Rb4*=", /* 0xb9 */
563 2, "Rd4*=", /* 0xba */
590 /* R_DATA_OVERRIDE */
603 0, "Ob=Sd=", /* 0xd1 */
605 0, "Ob=Ve=", /* 0xd2 */
655 static const int comp1_opcodes
[] =
677 static const int comp2_opcodes
[] =
686 static const int comp3_opcodes
[] =
693 /* These apparently are not in older versions of hpux reloc.h. */
695 #define R_DLT_REL 0x78
699 #define R_AUX_UNWIND 0xcf
703 #define R_SEC_STMT 0xd7
706 static reloc_howto_type som_hppa_howto_table
[] =
708 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
709 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
710 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
711 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
712 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
713 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
714 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
715 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
716 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
717 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
718 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
719 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
720 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
721 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
722 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
723 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
724 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
725 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
726 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
727 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
728 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
729 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
730 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
731 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
732 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
733 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
734 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
735 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
736 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
737 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
738 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
739 {R_NO_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_NO_RELOCATION"},
740 {R_ZEROES
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ZEROES"},
741 {R_ZEROES
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ZEROES"},
742 {R_UNINIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_UNINIT"},
743 {R_UNINIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_UNINIT"},
744 {R_RELOCATION
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RELOCATION"},
745 {R_DATA_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_ONE_SYMBOL"},
746 {R_DATA_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_ONE_SYMBOL"},
747 {R_DATA_PLABEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_PLABEL"},
748 {R_DATA_PLABEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_PLABEL"},
749 {R_SPACE_REF
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_SPACE_REF"},
750 {R_REPEATED_INIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "REPEATED_INIT"},
751 {R_REPEATED_INIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "REPEATED_INIT"},
752 {R_REPEATED_INIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "REPEATED_INIT"},
753 {R_REPEATED_INIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "REPEATED_INIT"},
754 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
755 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
756 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
757 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
758 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
759 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
760 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
761 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
762 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
763 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
764 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
765 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
766 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
767 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
768 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
769 {R_PCREL_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PCREL_CALL"},
770 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
771 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
772 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
773 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
774 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
775 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
776 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
777 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
778 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
779 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
780 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
781 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
782 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
783 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
784 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
785 {R_ABS_CALL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ABS_CALL"},
786 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
787 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
788 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
789 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
790 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
791 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
792 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
793 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
794 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
795 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
796 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
797 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
798 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
799 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
800 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
801 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
802 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
803 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
804 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
805 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
806 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
807 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
808 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
809 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
810 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
811 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
812 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
813 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
814 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
815 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
816 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
817 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
818 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
819 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
820 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
821 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
822 {R_DP_RELATIVE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DP_RELATIVE"},
823 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
824 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
825 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
826 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
827 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
828 {R_DLT_REL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DLT_REL"},
829 {R_DLT_REL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DLT_REL"},
830 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
831 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
832 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
833 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
834 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
835 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
836 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
837 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
838 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
839 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
840 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
841 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
842 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
843 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
844 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
845 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
846 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
847 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
848 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
849 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
850 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
851 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
852 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
853 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
854 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
855 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
856 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
857 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
858 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
859 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
860 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
861 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
862 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
863 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
864 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
865 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
866 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
867 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
868 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
869 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
870 {R_CODE_ONE_SYMBOL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_ONE_SYMBOL"},
871 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
872 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
873 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
874 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
875 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
876 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
877 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
878 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
879 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
880 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
881 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
882 {R_MILLI_REL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_MILLI_REL"},
883 {R_MILLI_REL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_MILLI_REL"},
884 {R_CODE_PLABEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_PLABEL"},
885 {R_CODE_PLABEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_PLABEL"},
886 {R_BREAKPOINT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_BREAKPOINT"},
887 {R_ENTRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ENTRY"},
888 {R_ENTRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ENTRY"},
889 {R_ALT_ENTRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_ALT_ENTRY"},
890 {R_EXIT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_EXIT"},
891 {R_BEGIN_TRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_BEGIN_TRY"},
892 {R_END_TRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_END_TRY"},
893 {R_END_TRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_END_TRY"},
894 {R_END_TRY
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_END_TRY"},
895 {R_BEGIN_BRTAB
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_BEGIN_BRTAB"},
896 {R_END_BRTAB
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_END_BRTAB"},
897 {R_STATEMENT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_STATEMENT"},
898 {R_STATEMENT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_STATEMENT"},
899 {R_STATEMENT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_STATEMENT"},
900 {R_DATA_EXPR
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_EXPR"},
901 {R_CODE_EXPR
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_CODE_EXPR"},
902 {R_FSEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_FSEL"},
903 {R_LSEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_LSEL"},
904 {R_RSEL
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RSEL"},
905 {R_N_MODE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_N_MODE"},
906 {R_S_MODE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_S_MODE"},
907 {R_D_MODE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_D_MODE"},
908 {R_R_MODE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_R_MODE"},
909 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
910 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
911 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
912 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
913 {R_DATA_OVERRIDE
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_DATA_OVERRIDE"},
914 {R_TRANSLATED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_TRANSLATED"},
915 {R_AUX_UNWIND
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_AUX_UNWIND"},
916 {R_COMP1
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_COMP1"},
917 {R_COMP2
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_COMP2"},
918 {R_COMP3
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_COMP3"},
919 {R_PREV_FIXUP
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PREV_FIXUP"},
920 {R_PREV_FIXUP
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PREV_FIXUP"},
921 {R_PREV_FIXUP
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PREV_FIXUP"},
922 {R_PREV_FIXUP
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_PREV_FIXUP"},
923 {R_SEC_STMT
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_SEC_STMT"},
924 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
925 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
926 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
927 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
928 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
929 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
930 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
931 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
932 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
933 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
934 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
935 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
936 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
937 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
938 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
939 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
940 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
941 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
942 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
943 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
944 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
945 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
946 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
947 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
948 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
949 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
950 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
951 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
952 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
953 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
954 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
955 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
956 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
957 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
958 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
959 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
960 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
961 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
962 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"},
963 {R_RESERVED
, 0, 0, 32, false, 0, 0, hppa_som_reloc
, "R_RESERVED"}};
966 /* Initialize the SOM relocation queue. By definition the queue holds
967 the last four multibyte fixups. */
970 som_initialize_reloc_queue (queue
)
971 struct reloc_queue
*queue
;
973 queue
[0].reloc
= NULL
;
975 queue
[1].reloc
= NULL
;
977 queue
[2].reloc
= NULL
;
979 queue
[3].reloc
= NULL
;
983 /* Insert a new relocation into the relocation queue. */
986 som_reloc_queue_insert (p
, size
, queue
)
989 struct reloc_queue
*queue
;
991 queue
[3].reloc
= queue
[2].reloc
;
992 queue
[3].size
= queue
[2].size
;
993 queue
[2].reloc
= queue
[1].reloc
;
994 queue
[2].size
= queue
[1].size
;
995 queue
[1].reloc
= queue
[0].reloc
;
996 queue
[1].size
= queue
[0].size
;
998 queue
[0].size
= size
;
1001 /* When an entry in the relocation queue is reused, the entry moves
1002 to the front of the queue. */
1005 som_reloc_queue_fix (queue
, index
)
1006 struct reloc_queue
*queue
;
1014 unsigned char *tmp1
= queue
[0].reloc
;
1015 unsigned int tmp2
= queue
[0].size
;
1016 queue
[0].reloc
= queue
[1].reloc
;
1017 queue
[0].size
= queue
[1].size
;
1018 queue
[1].reloc
= tmp1
;
1019 queue
[1].size
= tmp2
;
1025 unsigned char *tmp1
= queue
[0].reloc
;
1026 unsigned int tmp2
= queue
[0].size
;
1027 queue
[0].reloc
= queue
[2].reloc
;
1028 queue
[0].size
= queue
[2].size
;
1029 queue
[2].reloc
= queue
[1].reloc
;
1030 queue
[2].size
= queue
[1].size
;
1031 queue
[1].reloc
= tmp1
;
1032 queue
[1].size
= tmp2
;
1038 unsigned char *tmp1
= queue
[0].reloc
;
1039 unsigned int tmp2
= queue
[0].size
;
1040 queue
[0].reloc
= queue
[3].reloc
;
1041 queue
[0].size
= queue
[3].size
;
1042 queue
[3].reloc
= queue
[2].reloc
;
1043 queue
[3].size
= queue
[2].size
;
1044 queue
[2].reloc
= queue
[1].reloc
;
1045 queue
[2].size
= queue
[1].size
;
1046 queue
[1].reloc
= tmp1
;
1047 queue
[1].size
= tmp2
;
1053 /* Search for a particular relocation in the relocation queue. */
1056 som_reloc_queue_find (p
, size
, queue
)
1059 struct reloc_queue
*queue
;
1061 if (queue
[0].reloc
&& !bcmp (p
, queue
[0].reloc
, size
)
1062 && size
== queue
[0].size
)
1064 if (queue
[1].reloc
&& !bcmp (p
, queue
[1].reloc
, size
)
1065 && size
== queue
[1].size
)
1067 if (queue
[2].reloc
&& !bcmp (p
, queue
[2].reloc
, size
)
1068 && size
== queue
[2].size
)
1070 if (queue
[3].reloc
&& !bcmp (p
, queue
[3].reloc
, size
)
1071 && size
== queue
[3].size
)
1076 static unsigned char *
1077 try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, size
, queue
)
1079 int *subspace_reloc_sizep
;
1082 struct reloc_queue
*queue
;
1084 int queue_index
= som_reloc_queue_find (p
, size
, queue
);
1086 if (queue_index
!= -1)
1088 /* Found this in a previous fixup. Undo the fixup we
1089 just built and use R_PREV_FIXUP instead. We saved
1090 a total of size - 1 bytes in the fixup stream. */
1091 bfd_put_8 (abfd
, R_PREV_FIXUP
+ queue_index
, p
);
1093 *subspace_reloc_sizep
+= 1;
1094 som_reloc_queue_fix (queue
, queue_index
);
1098 som_reloc_queue_insert (p
, size
, queue
);
1099 *subspace_reloc_sizep
+= size
;
1105 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
1106 bytes without any relocation. Update the size of the subspace
1107 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
1108 current pointer into the relocation stream. */
1110 static unsigned char *
1111 som_reloc_skip (abfd
, skip
, p
, subspace_reloc_sizep
, queue
)
1115 unsigned int *subspace_reloc_sizep
;
1116 struct reloc_queue
*queue
;
1118 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
1119 then R_PREV_FIXUPs to get the difference down to a
1121 if (skip
>= 0x1000000)
1124 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 31, p
);
1125 bfd_put_8 (abfd
, 0xff, p
+ 1);
1126 bfd_put_16 (abfd
, 0xffff, p
+ 2);
1127 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1128 while (skip
>= 0x1000000)
1131 bfd_put_8 (abfd
, R_PREV_FIXUP
, p
);
1133 *subspace_reloc_sizep
+= 1;
1134 /* No need to adjust queue here since we are repeating the
1135 most recent fixup. */
1139 /* The difference must be less than 0x1000000. Use one
1140 more R_NO_RELOCATION entry to get to the right difference. */
1141 if ((skip
& 3) == 0 && skip
<= 0xc0000 && skip
> 0)
1143 /* Difference can be handled in a simple single-byte
1144 R_NO_RELOCATION entry. */
1147 bfd_put_8 (abfd
, R_NO_RELOCATION
+ (skip
>> 2) - 1, p
);
1148 *subspace_reloc_sizep
+= 1;
1151 /* Handle it with a two byte R_NO_RELOCATION entry. */
1152 else if (skip
<= 0x1000)
1154 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 24 + (((skip
>> 2) - 1) >> 8), p
);
1155 bfd_put_8 (abfd
, (skip
>> 2) - 1, p
+ 1);
1156 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1158 /* Handle it with a three byte R_NO_RELOCATION entry. */
1161 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 28 + (((skip
>> 2) - 1) >> 16), p
);
1162 bfd_put_16 (abfd
, (skip
>> 2) - 1, p
+ 1);
1163 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1166 /* Ugh. Punt and use a 4 byte entry. */
1169 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 31, p
);
1170 bfd_put_8 (abfd
, skip
>> 16, p
+ 1);
1171 bfd_put_16 (abfd
, skip
, p
+ 2);
1172 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1177 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
1178 from a BFD relocation. Update the size of the subspace relocation
1179 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
1180 into the relocation stream. */
1182 static unsigned char *
1183 som_reloc_addend (abfd
, addend
, p
, subspace_reloc_sizep
, queue
)
1187 unsigned int *subspace_reloc_sizep
;
1188 struct reloc_queue
*queue
;
1190 if ((unsigned)(addend
) + 0x80 < 0x100)
1192 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 1, p
);
1193 bfd_put_8 (abfd
, addend
, p
+ 1);
1194 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1196 else if ((unsigned) (addend
) + 0x8000 < 0x10000)
1198 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 2, p
);
1199 bfd_put_16 (abfd
, addend
, p
+ 1);
1200 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1202 else if ((unsigned) (addend
) + 0x800000 < 0x1000000)
1204 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 3, p
);
1205 bfd_put_8 (abfd
, addend
>> 16, p
+ 1);
1206 bfd_put_16 (abfd
, addend
, p
+ 2);
1207 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1211 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 4, p
);
1212 bfd_put_32 (abfd
, addend
, p
+ 1);
1213 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 5, queue
);
1218 /* Handle a single function call relocation. */
1220 static unsigned char *
1221 som_reloc_call (abfd
, p
, subspace_reloc_sizep
, bfd_reloc
, sym_num
, queue
)
1224 unsigned int *subspace_reloc_sizep
;
1227 struct reloc_queue
*queue
;
1229 int arg_bits
= HPPA_R_ARG_RELOC (bfd_reloc
->addend
);
1230 int rtn_bits
= arg_bits
& 0x3;
1233 /* You'll never believe all this is necessary to handle relocations
1234 for function calls. Having to compute and pack the argument
1235 relocation bits is the real nightmare.
1237 If you're interested in how this works, just forget it. You really
1238 do not want to know about this braindamage. */
1240 /* First see if this can be done with a "simple" relocation. Simple
1241 relocations have a symbol number < 0x100 and have simple encodings
1242 of argument relocations. */
1244 if (sym_num
< 0x100)
1256 case 1 << 8 | 1 << 6:
1257 case 1 << 8 | 1 << 6 | 1:
1260 case 1 << 8 | 1 << 6 | 1 << 4:
1261 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
1264 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
1265 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
1269 /* Not one of the easy encodings. This will have to be
1270 handled by the more complex code below. */
1276 /* Account for the return value too. */
1280 /* Emit a 2 byte relocation. Then see if it can be handled
1281 with a relocation which is already in the relocation queue. */
1282 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ type
, p
);
1283 bfd_put_8 (abfd
, sym_num
, p
+ 1);
1284 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1289 /* If this could not be handled with a simple relocation, then do a hard
1290 one. Hard relocations occur if the symbol number was too high or if
1291 the encoding of argument relocation bits is too complex. */
1294 /* Don't ask about these magic sequences. I took them straight
1295 from gas-1.36 which took them from the a.out man page. */
1297 if ((arg_bits
>> 6 & 0xf) == 0xe)
1300 type
+= (3 * (arg_bits
>> 8 & 3) + (arg_bits
>> 6 & 3)) * 40;
1301 if ((arg_bits
>> 2 & 0xf) == 0xe)
1304 type
+= (3 * (arg_bits
>> 4 & 3) + (arg_bits
>> 2 & 3)) * 4;
1306 /* Output the first two bytes of the relocation. These describe
1307 the length of the relocation and encoding style. */
1308 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 10
1309 + 2 * (sym_num
>= 0x100) + (type
>= 0x100),
1311 bfd_put_8 (abfd
, type
, p
+ 1);
1313 /* Now output the symbol index and see if this bizarre relocation
1314 just happened to be in the relocation queue. */
1315 if (sym_num
< 0x100)
1317 bfd_put_8 (abfd
, sym_num
, p
+ 2);
1318 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1322 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 2);
1323 bfd_put_16 (abfd
, sym_num
, p
+ 3);
1324 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 5, queue
);
1331 /* Return the logarithm of X, base 2, considering X unsigned.
1332 Abort -1 if X is not a power or two or is zero. */
1340 /* Test for 0 or a power of 2. */
1341 if (x
== 0 || x
!= (x
& -x
))
1344 while ((x
>>= 1) != 0)
1349 static bfd_reloc_status_type
1350 hppa_som_reloc (abfd
, reloc_entry
, symbol_in
, data
,
1351 input_section
, output_bfd
, error_message
)
1353 arelent
*reloc_entry
;
1356 asection
*input_section
;
1358 char **error_message
;
1362 reloc_entry
->address
+= input_section
->output_offset
;
1363 return bfd_reloc_ok
;
1365 return bfd_reloc_ok
;
1368 /* Given a generic HPPA relocation type, the instruction format,
1369 and a field selector, return one or more appropriate SOM relocations. */
1372 hppa_som_gen_reloc_type (abfd
, base_type
, format
, field
)
1376 enum hppa_reloc_field_selector_type_alt field
;
1378 int *final_type
, **final_types
;
1380 final_types
= (int **) bfd_alloc_by_size_t (abfd
, sizeof (int *) * 3);
1381 final_type
= (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1382 if (!final_types
|| !final_type
)
1384 bfd_set_error (bfd_error_no_memory
);
1388 /* The field selector may require additional relocations to be
1389 generated. It's impossible to know at this moment if additional
1390 relocations will be needed, so we make them. The code to actually
1391 write the relocation/fixup stream is responsible for removing
1392 any redundant relocations. */
1399 final_types
[0] = final_type
;
1400 final_types
[1] = NULL
;
1401 final_types
[2] = NULL
;
1402 *final_type
= base_type
;
1408 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1409 if (!final_types
[0])
1411 bfd_set_error (bfd_error_no_memory
);
1414 if (field
== e_tsel
)
1415 *final_types
[0] = R_FSEL
;
1416 else if (field
== e_ltsel
)
1417 *final_types
[0] = R_LSEL
;
1419 *final_types
[0] = R_RSEL
;
1420 final_types
[1] = final_type
;
1421 final_types
[2] = NULL
;
1422 *final_type
= base_type
;
1427 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1428 if (!final_types
[0])
1430 bfd_set_error (bfd_error_no_memory
);
1433 *final_types
[0] = R_S_MODE
;
1434 final_types
[1] = final_type
;
1435 final_types
[2] = NULL
;
1436 *final_type
= base_type
;
1441 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1442 if (!final_types
[0])
1444 bfd_set_error (bfd_error_no_memory
);
1447 *final_types
[0] = R_N_MODE
;
1448 final_types
[1] = final_type
;
1449 final_types
[2] = NULL
;
1450 *final_type
= base_type
;
1455 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1456 if (!final_types
[0])
1458 bfd_set_error (bfd_error_no_memory
);
1461 *final_types
[0] = R_D_MODE
;
1462 final_types
[1] = final_type
;
1463 final_types
[2] = NULL
;
1464 *final_type
= base_type
;
1469 final_types
[0] = (int *) bfd_alloc_by_size_t (abfd
, sizeof (int));
1470 if (!final_types
[0])
1472 bfd_set_error (bfd_error_no_memory
);
1475 *final_types
[0] = R_R_MODE
;
1476 final_types
[1] = final_type
;
1477 final_types
[2] = NULL
;
1478 *final_type
= base_type
;
1485 /* PLABELs get their own relocation type. */
1488 || field
== e_rpsel
)
1490 /* A PLABEL relocation that has a size of 32 bits must
1491 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
1493 *final_type
= R_DATA_PLABEL
;
1495 *final_type
= R_CODE_PLABEL
;
1498 else if (field
== e_tsel
1500 || field
== e_rtsel
)
1501 *final_type
= R_DLT_REL
;
1502 /* A relocation in the data space is always a full 32bits. */
1503 else if (format
== 32)
1504 *final_type
= R_DATA_ONE_SYMBOL
;
1509 /* More PLABEL special cases. */
1512 || field
== e_rpsel
)
1513 *final_type
= R_DATA_PLABEL
;
1517 case R_HPPA_ABS_CALL
:
1518 case R_HPPA_PCREL_CALL
:
1519 case R_HPPA_COMPLEX
:
1520 case R_HPPA_COMPLEX_PCREL_CALL
:
1521 case R_HPPA_COMPLEX_ABS_CALL
:
1522 /* Right now we can default all these. */
1528 /* Return the address of the correct entry in the PA SOM relocation
1531 static const reloc_howto_type
*
1532 som_bfd_reloc_type_lookup (arch
, code
)
1533 bfd_arch_info_type
*arch
;
1534 bfd_reloc_code_real_type code
;
1536 if ((int) code
< (int) R_NO_RELOCATION
+ 255)
1538 BFD_ASSERT ((int) som_hppa_howto_table
[(int) code
].type
== (int) code
);
1539 return &som_hppa_howto_table
[(int) code
];
1542 return (reloc_howto_type
*) 0;
1545 /* Perform some initialization for an object. Save results of this
1546 initialization in the BFD. */
1549 som_object_setup (abfd
, file_hdrp
, aux_hdrp
)
1551 struct header
*file_hdrp
;
1552 struct som_exec_auxhdr
*aux_hdrp
;
1554 /* som_mkobject will set bfd_error if som_mkobject fails. */
1555 if (som_mkobject (abfd
) != true)
1558 /* Set BFD flags based on what information is available in the SOM. */
1559 abfd
->flags
= NO_FLAGS
;
1560 if (file_hdrp
->symbol_total
)
1561 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
1563 switch (file_hdrp
->a_magic
)
1566 abfd
->flags
|= (D_PAGED
| WP_TEXT
| EXEC_P
);
1569 abfd
->flags
|= (WP_TEXT
| EXEC_P
);
1572 abfd
->flags
|= (EXEC_P
);
1575 abfd
->flags
|= HAS_RELOC
;
1581 bfd_get_start_address (abfd
) = aux_hdrp
->exec_entry
;
1582 bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 0);
1583 bfd_get_symcount (abfd
) = file_hdrp
->symbol_total
;
1585 /* Initialize the saved symbol table and string table to NULL.
1586 Save important offsets and sizes from the SOM header into
1588 obj_som_stringtab (abfd
) = (char *) NULL
;
1589 obj_som_symtab (abfd
) = (som_symbol_type
*) NULL
;
1590 obj_som_stringtab_size (abfd
) = file_hdrp
->symbol_strings_size
;
1591 obj_som_sym_filepos (abfd
) = file_hdrp
->symbol_location
;
1592 obj_som_str_filepos (abfd
) = file_hdrp
->symbol_strings_location
;
1593 obj_som_reloc_filepos (abfd
) = file_hdrp
->fixup_request_location
;
1598 /* Convert all of the space and subspace info into BFD sections. Each space
1599 contains a number of subspaces, which in turn describe the mapping between
1600 regions of the exec file, and the address space that the program runs in.
1601 BFD sections which correspond to spaces will overlap the sections for the
1602 associated subspaces. */
1605 setup_sections (abfd
, file_hdr
)
1607 struct header
*file_hdr
;
1609 char *space_strings
;
1611 unsigned int total_subspaces
= 0;
1613 /* First, read in space names */
1615 space_strings
= malloc (file_hdr
->space_strings_size
);
1616 if (!space_strings
&& file_hdr
->space_strings_size
!= 0)
1618 bfd_set_error (bfd_error_no_memory
);
1622 if (bfd_seek (abfd
, file_hdr
->space_strings_location
, SEEK_SET
) < 0)
1624 if (bfd_read (space_strings
, 1, file_hdr
->space_strings_size
, abfd
)
1625 != file_hdr
->space_strings_size
)
1628 /* Loop over all of the space dictionaries, building up sections */
1629 for (space_index
= 0; space_index
< file_hdr
->space_total
; space_index
++)
1631 struct space_dictionary_record space
;
1632 struct subspace_dictionary_record subspace
, save_subspace
;
1634 asection
*space_asect
;
1637 /* Read the space dictionary element */
1638 if (bfd_seek (abfd
, file_hdr
->space_location
1639 + space_index
* sizeof space
, SEEK_SET
) < 0)
1641 if (bfd_read (&space
, 1, sizeof space
, abfd
) != sizeof space
)
1644 /* Setup the space name string */
1645 space
.name
.n_name
= space
.name
.n_strx
+ space_strings
;
1647 /* Make a section out of it */
1648 newname
= bfd_alloc (abfd
, strlen (space
.name
.n_name
) + 1);
1651 strcpy (newname
, space
.name
.n_name
);
1653 space_asect
= bfd_make_section_anyway (abfd
, newname
);
1657 if (space
.is_loadable
== 0)
1658 space_asect
->flags
|= SEC_DEBUGGING
;
1660 /* Set up all the attributes for the space. */
1661 bfd_som_set_section_attributes (space_asect
, space
.is_defined
,
1662 space
.is_private
, space
.sort_key
,
1663 space
.space_number
);
1665 /* Now, read in the first subspace for this space */
1666 if (bfd_seek (abfd
, file_hdr
->subspace_location
1667 + space
.subspace_index
* sizeof subspace
,
1670 if (bfd_read (&subspace
, 1, sizeof subspace
, abfd
) != sizeof subspace
)
1672 /* Seek back to the start of the subspaces for loop below */
1673 if (bfd_seek (abfd
, file_hdr
->subspace_location
1674 + space
.subspace_index
* sizeof subspace
,
1678 /* Setup the start address and file loc from the first subspace record */
1679 space_asect
->vma
= subspace
.subspace_start
;
1680 space_asect
->filepos
= subspace
.file_loc_init_value
;
1681 space_asect
->alignment_power
= log2 (subspace
.alignment
);
1682 if (space_asect
->alignment_power
== -1)
1685 /* Initialize save_subspace so we can reliably determine if this
1686 loop placed any useful values into it. */
1687 memset (&save_subspace
, 0, sizeof (struct subspace_dictionary_record
));
1689 /* Loop over the rest of the subspaces, building up more sections */
1690 for (subspace_index
= 0; subspace_index
< space
.subspace_quantity
;
1693 asection
*subspace_asect
;
1695 /* Read in the next subspace */
1696 if (bfd_read (&subspace
, 1, sizeof subspace
, abfd
)
1700 /* Setup the subspace name string */
1701 subspace
.name
.n_name
= subspace
.name
.n_strx
+ space_strings
;
1703 newname
= bfd_alloc (abfd
, strlen (subspace
.name
.n_name
) + 1);
1706 strcpy (newname
, subspace
.name
.n_name
);
1708 /* Make a section out of this subspace */
1709 subspace_asect
= bfd_make_section_anyway (abfd
, newname
);
1710 if (!subspace_asect
)
1713 /* Store private information about the section. */
1714 bfd_som_set_subsection_attributes (subspace_asect
, space_asect
,
1715 subspace
.access_control_bits
,
1719 /* Keep an easy mapping between subspaces and sections. */
1720 som_section_data (subspace_asect
)->subspace_index
1721 = total_subspaces
++;
1723 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
1724 by the access_control_bits in the subspace header. */
1725 switch (subspace
.access_control_bits
>> 4)
1727 /* Readonly data. */
1729 subspace_asect
->flags
|= SEC_DATA
| SEC_READONLY
;
1734 subspace_asect
->flags
|= SEC_DATA
;
1737 /* Readonly code and the gateways.
1738 Gateways have other attributes which do not map
1739 into anything BFD knows about. */
1745 subspace_asect
->flags
|= SEC_CODE
| SEC_READONLY
;
1748 /* dynamic (writable) code. */
1750 subspace_asect
->flags
|= SEC_CODE
;
1754 if (subspace
.dup_common
|| subspace
.is_common
)
1755 subspace_asect
->flags
|= SEC_IS_COMMON
;
1756 else if (subspace
.subspace_length
> 0)
1757 subspace_asect
->flags
|= SEC_HAS_CONTENTS
;
1759 if (subspace
.is_loadable
)
1760 subspace_asect
->flags
|= SEC_ALLOC
| SEC_LOAD
;
1762 subspace_asect
->flags
|= SEC_DEBUGGING
;
1764 if (subspace
.code_only
)
1765 subspace_asect
->flags
|= SEC_CODE
;
1767 /* Both file_loc_init_value and initialization_length will
1768 be zero for a BSS like subspace. */
1769 if (subspace
.file_loc_init_value
== 0
1770 && subspace
.initialization_length
== 0)
1771 subspace_asect
->flags
&= ~(SEC_DATA
| SEC_LOAD
);
1773 /* This subspace has relocations.
1774 The fixup_request_quantity is a byte count for the number of
1775 entries in the relocation stream; it is not the actual number
1776 of relocations in the subspace. */
1777 if (subspace
.fixup_request_quantity
!= 0)
1779 subspace_asect
->flags
|= SEC_RELOC
;
1780 subspace_asect
->rel_filepos
= subspace
.fixup_request_index
;
1781 som_section_data (subspace_asect
)->reloc_size
1782 = subspace
.fixup_request_quantity
;
1783 /* We can not determine this yet. When we read in the
1784 relocation table the correct value will be filled in. */
1785 subspace_asect
->reloc_count
= -1;
1788 /* Update save_subspace if appropriate. */
1789 if (subspace
.file_loc_init_value
> save_subspace
.file_loc_init_value
)
1790 save_subspace
= subspace
;
1792 subspace_asect
->vma
= subspace
.subspace_start
;
1793 subspace_asect
->_cooked_size
= subspace
.subspace_length
;
1794 subspace_asect
->_raw_size
= subspace
.subspace_length
;
1795 subspace_asect
->filepos
= subspace
.file_loc_init_value
;
1796 subspace_asect
->alignment_power
= log2 (subspace
.alignment
);
1797 if (subspace_asect
->alignment_power
== -1)
1801 /* Yow! there is no subspace within the space which actually
1802 has initialized information in it; this should never happen
1803 as far as I know. */
1804 if (!save_subspace
.file_loc_init_value
)
1807 /* Setup the sizes for the space section based upon the info in the
1808 last subspace of the space. */
1809 space_asect
->_cooked_size
= save_subspace
.subspace_start
1810 - space_asect
->vma
+ save_subspace
.subspace_length
;
1811 space_asect
->_raw_size
= save_subspace
.file_loc_init_value
1812 - space_asect
->filepos
+ save_subspace
.initialization_length
;
1814 if (space_strings
!= NULL
)
1815 free (space_strings
);
1819 if (space_strings
!= NULL
)
1820 free (space_strings
);
1824 /* Read in a SOM object and make it into a BFD. */
1830 struct header file_hdr
;
1831 struct som_exec_auxhdr aux_hdr
;
1833 if (bfd_read ((PTR
) & file_hdr
, 1, FILE_HDR_SIZE
, abfd
) != FILE_HDR_SIZE
)
1835 bfd_set_error (bfd_error_system_call
);
1839 if (!_PA_RISC_ID (file_hdr
.system_id
))
1841 bfd_set_error (bfd_error_wrong_format
);
1845 switch (file_hdr
.a_magic
)
1860 #ifdef SHARED_MAGIC_CNX
1861 case SHARED_MAGIC_CNX
:
1865 bfd_set_error (bfd_error_wrong_format
);
1869 if (file_hdr
.version_id
!= VERSION_ID
1870 && file_hdr
.version_id
!= NEW_VERSION_ID
)
1872 bfd_set_error (bfd_error_wrong_format
);
1876 /* If the aux_header_size field in the file header is zero, then this
1877 object is an incomplete executable (a .o file). Do not try to read
1878 a non-existant auxiliary header. */
1879 memset (&aux_hdr
, 0, sizeof (struct som_exec_auxhdr
));
1880 if (file_hdr
.aux_header_size
!= 0)
1882 if (bfd_read ((PTR
) & aux_hdr
, 1, AUX_HDR_SIZE
, abfd
) != AUX_HDR_SIZE
)
1884 bfd_set_error (bfd_error_wrong_format
);
1889 if (!setup_sections (abfd
, &file_hdr
))
1891 /* setup_sections does not bubble up a bfd error code. */
1892 bfd_set_error (bfd_error_bad_value
);
1896 /* This appears to be a valid SOM object. Do some initialization. */
1897 return som_object_setup (abfd
, &file_hdr
, &aux_hdr
);
1900 /* Create a SOM object. */
1906 /* Allocate memory to hold backend information. */
1907 abfd
->tdata
.som_data
= (struct som_data_struct
*)
1908 bfd_zalloc (abfd
, sizeof (struct som_data_struct
));
1909 if (abfd
->tdata
.som_data
== NULL
)
1911 bfd_set_error (bfd_error_no_memory
);
1914 obj_som_file_hdr (abfd
)
1915 = (struct header
*) bfd_zalloc (abfd
, sizeof (struct header
));
1916 if (obj_som_file_hdr (abfd
) == NULL
)
1919 bfd_set_error (bfd_error_no_memory
);
1925 /* Initialize some information in the file header. This routine makes
1926 not attempt at doing the right thing for a full executable; it
1927 is only meant to handle relocatable objects. */
1930 som_prep_headers (abfd
)
1933 struct header
*file_hdr
= obj_som_file_hdr (abfd
);
1936 /* FIXME. This should really be conditional based on whether or not
1937 PA1.1 instructions/registers have been used. */
1938 file_hdr
->system_id
= CPU_PA_RISC1_0
;
1940 if (abfd
->flags
& EXEC_P
)
1942 if (abfd
->flags
& D_PAGED
)
1943 file_hdr
->a_magic
= DEMAND_MAGIC
;
1944 else if (abfd
->flags
& WP_TEXT
)
1945 file_hdr
->a_magic
= SHARE_MAGIC
;
1947 file_hdr
->a_magic
= EXEC_MAGIC
;
1950 file_hdr
->a_magic
= RELOC_MAGIC
;
1952 /* Only new format SOM is supported. */
1953 file_hdr
->version_id
= NEW_VERSION_ID
;
1955 /* These fields are optional, and embedding timestamps is not always
1956 a wise thing to do, it makes comparing objects during a multi-stage
1957 bootstrap difficult. */
1958 file_hdr
->file_time
.secs
= 0;
1959 file_hdr
->file_time
.nanosecs
= 0;
1961 if (abfd
->flags
& EXEC_P
)
1965 file_hdr
->entry_space
= 0;
1966 file_hdr
->entry_subspace
= 0;
1967 file_hdr
->entry_offset
= 0;
1970 file_hdr
->presumed_dp
= 0;
1972 /* Now iterate over the sections translating information from
1973 BFD sections to SOM spaces/subspaces. */
1975 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
1977 /* Ignore anything which has not been marked as a space or
1979 if (som_section_data (section
)->is_space
== 0
1981 && som_section_data (section
)->is_subspace
== 0)
1984 if (som_section_data (section
)->is_space
)
1986 /* Set space attributes. Note most attributes of SOM spaces
1987 are set based on the subspaces it contains. */
1988 som_section_data (section
)->space_dict
.loader_fix_index
= -1;
1989 som_section_data (section
)->space_dict
.init_pointer_index
= -1;
1993 /* Set subspace attributes. Basic stuff is done here, additional
1994 attributes are filled in later as more information becomes
1996 if (section
->flags
& SEC_IS_COMMON
)
1998 som_section_data (section
)->subspace_dict
.dup_common
= 1;
1999 som_section_data (section
)->subspace_dict
.is_common
= 1;
2002 if (section
->flags
& SEC_ALLOC
)
2003 som_section_data (section
)->subspace_dict
.is_loadable
= 1;
2005 if (section
->flags
& SEC_CODE
)
2006 som_section_data (section
)->subspace_dict
.code_only
= 1;
2008 som_section_data (section
)->subspace_dict
.subspace_start
=
2010 som_section_data (section
)->subspace_dict
.subspace_length
=
2011 bfd_section_size (abfd
, section
);
2012 som_section_data (section
)->subspace_dict
.initialization_length
=
2013 bfd_section_size (abfd
, section
);
2014 som_section_data (section
)->subspace_dict
.alignment
=
2015 1 << section
->alignment_power
;
2021 /* Count and return the number of spaces attached to the given BFD. */
2023 static unsigned long
2024 som_count_spaces (abfd
)
2030 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2031 count
+= som_section_data (section
)->is_space
;
2036 /* Count the number of subspaces attached to the given BFD. */
2038 static unsigned long
2039 som_count_subspaces (abfd
)
2045 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2046 count
+= som_section_data (section
)->is_subspace
;
2051 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
2053 We desire symbols to be ordered starting with the symbol with the
2054 highest relocation count down to the symbol with the lowest relocation
2055 count. Doing so compacts the relocation stream. */
2058 compare_syms (sym1
, sym2
)
2063 unsigned int count1
, count2
;
2065 /* Get relocation count for each symbol. Note that the count
2066 is stored in the udata pointer for section symbols! */
2067 if ((*sym1
)->flags
& BSF_SECTION_SYM
)
2068 count1
= (int)(*sym1
)->udata
;
2070 count1
= som_symbol_data (*sym1
)->reloc_count
;
2072 if ((*sym2
)->flags
& BSF_SECTION_SYM
)
2073 count2
= (int)(*sym2
)->udata
;
2075 count2
= som_symbol_data (*sym2
)->reloc_count
;
2077 /* Return the appropriate value. */
2078 if (count1
< count2
)
2080 else if (count1
> count2
)
2085 /* Perform various work in preparation for emitting the fixup stream. */
2088 som_prep_for_fixups (abfd
, syms
, num_syms
)
2091 unsigned long num_syms
;
2096 /* Most SOM relocations involving a symbol have a length which is
2097 dependent on the index of the symbol. So symbols which are
2098 used often in relocations should have a small index. */
2100 /* First initialize the counters for each symbol. */
2101 for (i
= 0; i
< num_syms
; i
++)
2103 /* Handle a section symbol; these have no pointers back to the
2104 SOM symbol info. So we just use the pointer field (udata)
2105 to hold the relocation count. */
2106 if (som_symbol_data (syms
[i
]) == NULL
2107 || syms
[i
]->flags
& BSF_SECTION_SYM
)
2109 syms
[i
]->flags
|= BSF_SECTION_SYM
;
2110 syms
[i
]->udata
= (PTR
) 0;
2113 som_symbol_data (syms
[i
])->reloc_count
= 0;
2116 /* Now that the counters are initialized, make a weighted count
2117 of how often a given symbol is used in a relocation. */
2118 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2122 /* Does this section have any relocations? */
2123 if (section
->reloc_count
<= 0)
2126 /* Walk through each relocation for this section. */
2127 for (i
= 1; i
< section
->reloc_count
; i
++)
2129 arelent
*reloc
= section
->orelocation
[i
];
2132 /* A relocation against a symbol in the *ABS* section really
2133 does not have a symbol. Likewise if the symbol isn't associated
2134 with any section. */
2135 if (reloc
->sym_ptr_ptr
== NULL
2136 || (*reloc
->sym_ptr_ptr
)->section
== &bfd_abs_section
)
2139 /* Scaling to encourage symbols involved in R_DP_RELATIVE
2140 and R_CODE_ONE_SYMBOL relocations to come first. These
2141 two relocations have single byte versions if the symbol
2142 index is very small. */
2143 if (reloc
->howto
->type
== R_DP_RELATIVE
2144 || reloc
->howto
->type
== R_CODE_ONE_SYMBOL
)
2149 /* Handle section symbols by ramming the count in the udata
2150 field. It will not be used and the count is very important
2151 for these symbols. */
2152 if ((*reloc
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
)
2154 (*reloc
->sym_ptr_ptr
)->udata
=
2155 (PTR
) ((int) (*reloc
->sym_ptr_ptr
)->udata
+ scale
);
2159 /* A normal symbol. Increment the count. */
2160 som_symbol_data (*reloc
->sym_ptr_ptr
)->reloc_count
+= scale
;
2164 /* Now sort the symbols. */
2165 qsort (syms
, num_syms
, sizeof (asymbol
*), compare_syms
);
2167 /* Compute the symbol indexes, they will be needed by the relocation
2169 for (i
= 0; i
< num_syms
; i
++)
2171 /* A section symbol. Again, there is no pointer to backend symbol
2172 information, so we reuse (abuse) the udata field again. */
2173 if (syms
[i
]->flags
& BSF_SECTION_SYM
)
2174 syms
[i
]->udata
= (PTR
) i
;
2176 som_symbol_data (syms
[i
])->index
= i
;
2181 som_write_fixups (abfd
, current_offset
, total_reloc_sizep
)
2183 unsigned long current_offset
;
2184 unsigned int *total_reloc_sizep
;
2187 /* Chunk of memory that we can use as buffer space, then throw
2189 unsigned char tmp_space
[SOM_TMP_BUFSIZE
];
2191 unsigned int total_reloc_size
= 0;
2192 unsigned int subspace_reloc_size
= 0;
2193 unsigned int num_spaces
= obj_som_file_hdr (abfd
)->space_total
;
2194 asection
*section
= abfd
->sections
;
2196 memset (tmp_space
, 0, SOM_TMP_BUFSIZE
);
2199 /* All the fixups for a particular subspace are emitted in a single
2200 stream. All the subspaces for a particular space are emitted
2203 So, to get all the locations correct one must iterate through all the
2204 spaces, for each space iterate through its subspaces and output a
2206 for (i
= 0; i
< num_spaces
; i
++)
2208 asection
*subsection
;
2211 while (som_section_data (section
)->is_space
== 0)
2212 section
= section
->next
;
2214 /* Now iterate through each of its subspaces. */
2215 for (subsection
= abfd
->sections
;
2217 subsection
= subsection
->next
)
2219 int reloc_offset
, current_rounding_mode
;
2221 /* Find a subspace of this space. */
2222 if (som_section_data (subsection
)->is_subspace
== 0
2223 || som_section_data (subsection
)->containing_space
!= section
)
2226 /* If this subspace had no relocations, then we're finished
2228 if (subsection
->reloc_count
<= 0)
2230 som_section_data (subsection
)->subspace_dict
.fixup_request_index
2235 /* This subspace has some relocations. Put the relocation stream
2236 index into the subspace record. */
2237 som_section_data (subsection
)->subspace_dict
.fixup_request_index
2240 /* To make life easier start over with a clean slate for
2241 each subspace. Seek to the start of the relocation stream
2242 for this subspace in preparation for writing out its fixup
2244 if (bfd_seek (abfd
, current_offset
+ total_reloc_size
, SEEK_SET
) != 0)
2246 bfd_set_error (bfd_error_system_call
);
2250 /* Buffer space has already been allocated. Just perform some
2251 initialization here. */
2253 subspace_reloc_size
= 0;
2255 som_initialize_reloc_queue (reloc_queue
);
2256 current_rounding_mode
= R_N_MODE
;
2258 /* Translate each BFD relocation into one or more SOM
2260 for (j
= 0; j
< subsection
->reloc_count
; j
++)
2262 arelent
*bfd_reloc
= subsection
->orelocation
[j
];
2266 /* Get the symbol number. Remember it's stored in a
2267 special place for section symbols. */
2268 if ((*bfd_reloc
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
)
2269 sym_num
= (int) (*bfd_reloc
->sym_ptr_ptr
)->udata
;
2271 sym_num
= som_symbol_data (*bfd_reloc
->sym_ptr_ptr
)->index
;
2273 /* If there is not enough room for the next couple relocations,
2274 then dump the current buffer contents now. Also reinitialize
2275 the relocation queue.
2277 No single BFD relocation could ever translate into more
2278 than 100 bytes of SOM relocations (20bytes is probably the
2279 upper limit, but leave lots of space for growth). */
2280 if (p
- tmp_space
+ 100 > SOM_TMP_BUFSIZE
)
2282 if (bfd_write ((PTR
) tmp_space
, p
- tmp_space
, 1, abfd
)
2285 bfd_set_error (bfd_error_system_call
);
2289 som_initialize_reloc_queue (reloc_queue
);
2292 /* Emit R_NO_RELOCATION fixups to map any bytes which were
2294 skip
= bfd_reloc
->address
- reloc_offset
;
2295 p
= som_reloc_skip (abfd
, skip
, p
,
2296 &subspace_reloc_size
, reloc_queue
);
2298 /* Update reloc_offset for the next iteration.
2300 Many relocations do not consume input bytes. They
2301 are markers, or set state necessary to perform some
2302 later relocation. */
2303 switch (bfd_reloc
->howto
->type
)
2305 /* This only needs to handle relocations that may be
2306 made by hppa_som_gen_reloc. */
2316 reloc_offset
= bfd_reloc
->address
;
2320 reloc_offset
= bfd_reloc
->address
+ 4;
2324 /* Now the actual relocation we care about. */
2325 switch (bfd_reloc
->howto
->type
)
2329 p
= som_reloc_call (abfd
, p
, &subspace_reloc_size
,
2330 bfd_reloc
, sym_num
, reloc_queue
);
2333 case R_CODE_ONE_SYMBOL
:
2335 /* Account for any addend. */
2336 if (bfd_reloc
->addend
)
2337 p
= som_reloc_addend (abfd
, bfd_reloc
->addend
, p
,
2338 &subspace_reloc_size
, reloc_queue
);
2342 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ sym_num
, p
);
2343 subspace_reloc_size
+= 1;
2346 else if (sym_num
< 0x100)
2348 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 32, p
);
2349 bfd_put_8 (abfd
, sym_num
, p
+ 1);
2350 p
= try_prev_fixup (abfd
, &subspace_reloc_size
, p
,
2353 else if (sym_num
< 0x10000000)
2355 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 33, p
);
2356 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 1);
2357 bfd_put_16 (abfd
, sym_num
, p
+ 2);
2358 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2365 case R_DATA_ONE_SYMBOL
:
2369 /* Account for any addend. */
2370 if (bfd_reloc
->addend
)
2371 p
= som_reloc_addend (abfd
, bfd_reloc
->addend
, p
,
2372 &subspace_reloc_size
, reloc_queue
);
2374 if (sym_num
< 0x100)
2376 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2377 bfd_put_8 (abfd
, sym_num
, p
+ 1);
2378 p
= try_prev_fixup (abfd
, &subspace_reloc_size
, p
,
2381 else if (sym_num
< 0x10000000)
2383 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 1, p
);
2384 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 1);
2385 bfd_put_16 (abfd
, sym_num
, p
+ 2);
2386 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2396 = (int *) som_symbol_data (*bfd_reloc
->sym_ptr_ptr
)->unwind
;
2397 bfd_put_8 (abfd
, R_ENTRY
, p
);
2398 bfd_put_32 (abfd
, descp
[0], p
+ 1);
2399 bfd_put_32 (abfd
, descp
[1], p
+ 5);
2400 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2406 bfd_put_8 (abfd
, R_EXIT
, p
);
2407 subspace_reloc_size
+= 1;
2415 /* If this relocation requests the current rounding
2416 mode, then it is redundant. */
2417 if (bfd_reloc
->howto
->type
!= current_rounding_mode
)
2419 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2420 subspace_reloc_size
+= 1;
2422 current_rounding_mode
= bfd_reloc
->howto
->type
;
2429 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2430 subspace_reloc_size
+= 1;
2434 /* Put a "R_RESERVED" relocation in the stream if
2435 we hit something we do not understand. The linker
2436 will complain loudly if this ever happens. */
2438 bfd_put_8 (abfd
, 0xff, p
);
2439 subspace_reloc_size
+= 1;
2445 /* Last BFD relocation for a subspace has been processed.
2446 Map the rest of the subspace with R_NO_RELOCATION fixups. */
2447 p
= som_reloc_skip (abfd
, bfd_section_size (abfd
, subsection
)
2449 p
, &subspace_reloc_size
, reloc_queue
);
2451 /* Scribble out the relocations. */
2452 if (bfd_write ((PTR
) tmp_space
, p
- tmp_space
, 1, abfd
)
2455 bfd_set_error (bfd_error_system_call
);
2460 total_reloc_size
+= subspace_reloc_size
;
2461 som_section_data (subsection
)->subspace_dict
.fixup_request_quantity
2462 = subspace_reloc_size
;
2464 section
= section
->next
;
2466 *total_reloc_sizep
= total_reloc_size
;
2470 /* Write out the space/subspace string table. */
2473 som_write_space_strings (abfd
, current_offset
, string_sizep
)
2475 unsigned long current_offset
;
2476 unsigned int *string_sizep
;
2478 /* Chunk of memory that we can use as buffer space, then throw
2480 unsigned char tmp_space
[SOM_TMP_BUFSIZE
];
2482 unsigned int strings_size
= 0;
2485 memset (tmp_space
, 0, SOM_TMP_BUFSIZE
);
2488 /* Seek to the start of the space strings in preparation for writing
2490 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) != 0)
2492 bfd_set_error (bfd_error_system_call
);
2496 /* Walk through all the spaces and subspaces (order is not important)
2497 building up and writing string table entries for their names. */
2498 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2502 /* Only work with space/subspaces; avoid any other sections
2503 which might have been made (.text for example). */
2504 if (som_section_data (section
)->is_space
== 0
2505 && som_section_data (section
)->is_subspace
== 0)
2508 /* Get the length of the space/subspace name. */
2509 length
= strlen (section
->name
);
2511 /* If there is not enough room for the next entry, then dump the
2512 current buffer contents now. Each entry will take 4 bytes to
2513 hold the string length + the string itself + null terminator. */
2514 if (p
- tmp_space
+ 5 + length
> SOM_TMP_BUFSIZE
)
2516 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
)
2519 bfd_set_error (bfd_error_system_call
);
2522 /* Reset to beginning of the buffer space. */
2526 /* First element in a string table entry is the length of the
2527 string. Alignment issues are already handled. */
2528 bfd_put_32 (abfd
, length
, p
);
2532 /* Record the index in the space/subspace records. */
2533 if (som_section_data (section
)->is_space
)
2534 som_section_data (section
)->space_dict
.name
.n_strx
= strings_size
;
2536 som_section_data (section
)->subspace_dict
.name
.n_strx
= strings_size
;
2538 /* Next comes the string itself + a null terminator. */
2539 strcpy (p
, section
->name
);
2541 strings_size
+= length
+ 1;
2543 /* Always align up to the next word boundary. */
2544 while (strings_size
% 4)
2546 bfd_put_8 (abfd
, 0, p
);
2552 /* Done with the space/subspace strings. Write out any information
2553 contained in a partial block. */
2554 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
) != p
- tmp_space
)
2556 bfd_set_error (bfd_error_system_call
);
2559 *string_sizep
= strings_size
;
2563 /* Write out the symbol string table. */
2566 som_write_symbol_strings (abfd
, current_offset
, syms
, num_syms
, string_sizep
)
2568 unsigned long current_offset
;
2570 unsigned int num_syms
;
2571 unsigned int *string_sizep
;
2575 /* Chunk of memory that we can use as buffer space, then throw
2577 unsigned char tmp_space
[SOM_TMP_BUFSIZE
];
2579 unsigned int strings_size
= 0;
2581 memset (tmp_space
, 0, SOM_TMP_BUFSIZE
);
2584 /* Seek to the start of the space strings in preparation for writing
2586 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) != 0)
2588 bfd_set_error (bfd_error_system_call
);
2592 for (i
= 0; i
< num_syms
; i
++)
2594 int length
= strlen (syms
[i
]->name
);
2596 /* If there is not enough room for the next entry, then dump the
2597 current buffer contents now. */
2598 if (p
- tmp_space
+ 5 + length
> SOM_TMP_BUFSIZE
)
2600 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
)
2603 bfd_set_error (bfd_error_system_call
);
2606 /* Reset to beginning of the buffer space. */
2610 /* First element in a string table entry is the length of the
2611 string. This must always be 4 byte aligned. This is also
2612 an appropriate time to fill in the string index field in the
2613 symbol table entry. */
2614 bfd_put_32 (abfd
, length
, p
);
2618 /* Next comes the string itself + a null terminator. */
2619 strcpy (p
, syms
[i
]->name
);
2622 syms
[i
]->name
= (char *)strings_size
;
2624 strings_size
+= length
+ 1;
2626 /* Always align up to the next word boundary. */
2627 while (strings_size
% 4)
2629 bfd_put_8 (abfd
, 0, p
);
2635 /* Scribble out any partial block. */
2636 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
) != p
- tmp_space
)
2638 bfd_set_error (bfd_error_system_call
);
2642 *string_sizep
= strings_size
;
2646 /* Compute variable information to be placed in the SOM headers,
2647 space/subspace dictionaries, relocation streams, etc. Begin
2648 writing parts of the object file. */
2651 som_begin_writing (abfd
)
2654 unsigned long current_offset
= 0;
2655 int strings_size
= 0;
2656 unsigned int total_reloc_size
= 0;
2657 unsigned long num_spaces
, num_subspaces
, num_syms
, i
;
2659 asymbol
**syms
= bfd_get_outsymbols (abfd
);
2660 unsigned int total_subspaces
= 0;
2661 struct som_exec_auxhdr exec_header
;
2663 /* The file header will always be first in an object file,
2664 everything else can be in random locations. To keep things
2665 "simple" BFD will lay out the object file in the manner suggested
2666 by the PRO ABI for PA-RISC Systems. */
2668 /* Before any output can really begin offsets for all the major
2669 portions of the object file must be computed. So, starting
2670 with the initial file header compute (and sometimes write)
2671 each portion of the object file. */
2673 /* Make room for the file header, it's contents are not complete
2674 yet, so it can not be written at this time. */
2675 current_offset
+= sizeof (struct header
);
2677 /* Any auxiliary headers will follow the file header. Right now
2678 we support only the copyright and version headers. */
2679 obj_som_file_hdr (abfd
)->aux_header_location
= current_offset
;
2680 obj_som_file_hdr (abfd
)->aux_header_size
= 0;
2681 if (abfd
->flags
& EXEC_P
)
2683 /* Parts of the exec header will be filled in later, so
2684 delay writing the header itself. Fill in the defaults,
2685 and write it later. */
2686 current_offset
+= sizeof (exec_header
);
2687 obj_som_file_hdr (abfd
)->aux_header_size
+= sizeof (exec_header
);
2688 memset (&exec_header
, 0, sizeof (exec_header
));
2689 exec_header
.som_auxhdr
.type
= HPUX_AUX_ID
;
2690 exec_header
.som_auxhdr
.length
= 40;
2692 if (obj_som_version_hdr (abfd
) != NULL
)
2696 bfd_seek (abfd
, current_offset
, SEEK_SET
);
2698 /* Write the aux_id structure and the string length. */
2699 len
= sizeof (struct aux_id
) + sizeof (unsigned int);
2700 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
2701 current_offset
+= len
;
2702 if (bfd_write ((PTR
) obj_som_version_hdr (abfd
), len
, 1, abfd
) != len
)
2704 bfd_set_error (bfd_error_system_call
);
2708 /* Write the version string. */
2709 len
= obj_som_version_hdr (abfd
)->header_id
.length
- sizeof (int);
2710 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
2711 current_offset
+= len
;
2712 if (bfd_write ((PTR
) obj_som_version_hdr (abfd
)->user_string
,
2713 len
, 1, abfd
) != len
)
2715 bfd_set_error (bfd_error_system_call
);
2720 if (obj_som_copyright_hdr (abfd
) != NULL
)
2724 bfd_seek (abfd
, current_offset
, SEEK_SET
);
2726 /* Write the aux_id structure and the string length. */
2727 len
= sizeof (struct aux_id
) + sizeof (unsigned int);
2728 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
2729 current_offset
+= len
;
2730 if (bfd_write ((PTR
) obj_som_copyright_hdr (abfd
), len
, 1, abfd
) != len
)
2732 bfd_set_error (bfd_error_system_call
);
2736 /* Write the copyright string. */
2737 len
= obj_som_copyright_hdr (abfd
)->header_id
.length
- sizeof (int);
2738 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
2739 current_offset
+= len
;
2740 if (bfd_write ((PTR
) obj_som_copyright_hdr (abfd
)->copyright
,
2741 len
, 1, abfd
) != len
)
2743 bfd_set_error (bfd_error_system_call
);
2748 /* Next comes the initialization pointers; we have no initialization
2749 pointers, so current offset does not change. */
2750 obj_som_file_hdr (abfd
)->init_array_location
= current_offset
;
2751 obj_som_file_hdr (abfd
)->init_array_total
= 0;
2753 /* Next are the space records. These are fixed length records.
2755 Count the number of spaces to determine how much room is needed
2756 in the object file for the space records.
2758 The names of the spaces are stored in a separate string table,
2759 and the index for each space into the string table is computed
2760 below. Therefore, it is not possible to write the space headers
2762 num_spaces
= som_count_spaces (abfd
);
2763 obj_som_file_hdr (abfd
)->space_location
= current_offset
;
2764 obj_som_file_hdr (abfd
)->space_total
= num_spaces
;
2765 current_offset
+= num_spaces
* sizeof (struct space_dictionary_record
);
2767 /* Next are the subspace records. These are fixed length records.
2769 Count the number of subspaes to determine how much room is needed
2770 in the object file for the subspace records.
2772 A variety if fields in the subspace record are still unknown at
2773 this time (index into string table, fixup stream location/size, etc). */
2774 num_subspaces
= som_count_subspaces (abfd
);
2775 obj_som_file_hdr (abfd
)->subspace_location
= current_offset
;
2776 obj_som_file_hdr (abfd
)->subspace_total
= num_subspaces
;
2777 current_offset
+= num_subspaces
* sizeof (struct subspace_dictionary_record
);
2779 /* Next is the string table for the space/subspace names. We will
2780 build and write the string table on the fly. At the same time
2781 we will fill in the space/subspace name index fields. */
2783 /* The string table needs to be aligned on a word boundary. */
2784 if (current_offset
% 4)
2785 current_offset
+= (4 - (current_offset
% 4));
2787 /* Mark the offset of the space/subspace string table in the
2789 obj_som_file_hdr (abfd
)->space_strings_location
= current_offset
;
2791 /* Scribble out the space strings. */
2792 if (som_write_space_strings (abfd
, current_offset
, &strings_size
) == false)
2795 /* Record total string table size in the header and update the
2797 obj_som_file_hdr (abfd
)->space_strings_size
= strings_size
;
2798 current_offset
+= strings_size
;
2800 /* Next is the symbol table. These are fixed length records.
2802 Count the number of symbols to determine how much room is needed
2803 in the object file for the symbol table.
2805 The names of the symbols are stored in a separate string table,
2806 and the index for each symbol name into the string table is computed
2807 below. Therefore, it is not possible to write the symobl table
2809 num_syms
= bfd_get_symcount (abfd
);
2810 obj_som_file_hdr (abfd
)->symbol_location
= current_offset
;
2811 obj_som_file_hdr (abfd
)->symbol_total
= num_syms
;
2812 current_offset
+= num_syms
* sizeof (struct symbol_dictionary_record
);
2814 /* Do prep work before handling fixups. */
2815 som_prep_for_fixups (abfd
, syms
, num_syms
);
2817 /* Next comes the fixup stream which starts on a word boundary. */
2818 if (current_offset
% 4)
2819 current_offset
+= (4 - (current_offset
% 4));
2820 obj_som_file_hdr (abfd
)->fixup_request_location
= current_offset
;
2822 /* Write the fixups and update fields in subspace headers which
2823 relate to the fixup stream. */
2824 if (som_write_fixups (abfd
, current_offset
, &total_reloc_size
) == false)
2827 /* Record the total size of the fixup stream in the file header. */
2828 obj_som_file_hdr (abfd
)->fixup_request_total
= total_reloc_size
;
2829 current_offset
+= total_reloc_size
;
2831 /* Next are the symbol strings.
2832 Align them to a word boundary. */
2833 if (current_offset
% 4)
2834 current_offset
+= (4 - (current_offset
% 4));
2835 obj_som_file_hdr (abfd
)->symbol_strings_location
= current_offset
;
2837 /* Scribble out the symbol strings. */
2838 if (som_write_symbol_strings (abfd
, current_offset
, syms
,
2839 num_syms
, &strings_size
)
2843 /* Record total string table size in header and update the
2845 obj_som_file_hdr (abfd
)->symbol_strings_size
= strings_size
;
2846 current_offset
+= strings_size
;
2848 /* Next is the compiler records. We do not use these. */
2849 obj_som_file_hdr (abfd
)->compiler_location
= current_offset
;
2850 obj_som_file_hdr (abfd
)->compiler_total
= 0;
2852 /* Now compute the file positions for the loadable subspaces, taking
2853 care to make sure everything stays properly aligned. */
2855 section
= abfd
->sections
;
2856 for (i
= 0; i
< num_spaces
; i
++)
2858 asection
*subsection
;
2862 while (som_section_data (section
)->is_space
== 0)
2863 section
= section
->next
;
2866 /* Now look for all its subspaces. */
2867 for (subsection
= abfd
->sections
;
2869 subsection
= subsection
->next
)
2872 if (som_section_data (subsection
)->is_subspace
== 0
2873 || som_section_data (subsection
)->containing_space
!= section
2874 || (subsection
->flags
& SEC_ALLOC
) == 0)
2877 /* If this is the first subspace in the space, and we are
2878 building an executable, then take care to make sure all
2879 the alignments are correct and update the exec header. */
2881 && (abfd
->flags
& EXEC_P
))
2883 /* Demand paged executables have each space aligned to a
2884 page boundary. Sharable executables (write-protected
2885 text) have just the private (aka data & bss) space aligned
2886 to a page boundary. */
2887 if (abfd
->flags
& D_PAGED
2888 || ((abfd
->flags
& WP_TEXT
)
2889 && (subsection
->flags
& SEC_DATA
)))
2890 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
2892 /* Update the exec header. */
2893 if (subsection
->flags
& SEC_CODE
&& exec_header
.exec_tfile
== 0)
2895 exec_header
.exec_tmem
= section
->vma
;
2896 exec_header
.exec_tfile
= current_offset
;
2898 if (subsection
->flags
& SEC_DATA
&& exec_header
.exec_dfile
== 0)
2900 exec_header
.exec_dmem
= section
->vma
;
2901 exec_header
.exec_dfile
= current_offset
;
2904 /* Only do this for the first subspace within each space. */
2908 som_section_data (subsection
)->subspace_index
= total_subspaces
++;
2909 /* This is real data to be loaded from the file. */
2910 if (subsection
->flags
& SEC_LOAD
)
2912 /* Update the size of the code & data. */
2913 if (abfd
->flags
& EXEC_P
2914 && subsection
->flags
& SEC_CODE
)
2915 exec_header
.exec_tsize
+= subsection
->_cooked_size
;
2916 else if (abfd
->flags
& EXEC_P
2917 && subsection
->flags
& SEC_DATA
)
2918 exec_header
.exec_dsize
+= subsection
->_cooked_size
;
2919 som_section_data (subsection
)->subspace_dict
.file_loc_init_value
2921 section
->filepos
= current_offset
;
2922 current_offset
+= bfd_section_size (abfd
, subsection
);
2924 /* Looks like uninitialized data. */
2927 /* Update the size of the bss section. */
2928 if (abfd
->flags
& EXEC_P
)
2929 exec_header
.exec_bsize
+= subsection
->_cooked_size
;
2931 som_section_data (subsection
)->subspace_dict
.file_loc_init_value
2933 som_section_data (subsection
)->subspace_dict
.
2934 initialization_length
= 0;
2937 /* Goto the next section. */
2938 section
= section
->next
;
2941 /* Finally compute the file positions for unloadable subspaces.
2942 If building an executable, start the unloadable stuff on its
2945 if (abfd
->flags
& EXEC_P
)
2946 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
2948 obj_som_file_hdr (abfd
)->unloadable_sp_location
= current_offset
;
2949 section
= abfd
->sections
;
2950 for (i
= 0; i
< num_spaces
; i
++)
2952 asection
*subsection
;
2955 while (som_section_data (section
)->is_space
== 0)
2956 section
= section
->next
;
2958 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
2960 /* Now look for all its subspaces. */
2961 for (subsection
= abfd
->sections
;
2963 subsection
= subsection
->next
)
2966 if (som_section_data (subsection
)->is_subspace
== 0
2967 || som_section_data (subsection
)->containing_space
!= section
2968 || (subsection
->flags
& SEC_ALLOC
) != 0)
2971 som_section_data (subsection
)->subspace_index
= total_subspaces
++;
2972 /* This is real data to be loaded from the file. */
2973 if ((subsection
->flags
& SEC_LOAD
) == 0)
2975 som_section_data (subsection
)->subspace_dict
.file_loc_init_value
2977 section
->filepos
= current_offset
;
2978 current_offset
+= bfd_section_size (abfd
, subsection
);
2980 /* Looks like uninitialized data. */
2983 som_section_data (subsection
)->subspace_dict
.file_loc_init_value
2985 som_section_data (subsection
)->subspace_dict
.
2986 initialization_length
= bfd_section_size (abfd
, subsection
);
2989 /* Goto the next section. */
2990 section
= section
->next
;
2993 /* If building an executable, then make sure to seek to and write
2994 one byte at the end of the file to make sure any necessary
2995 zeros are filled in. Ugh. */
2996 if (abfd
->flags
& EXEC_P
)
2997 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
2998 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) < 0)
3000 bfd_set_error (bfd_error_system_call
);
3003 if (bfd_write ((PTR
) "", 1, 1, abfd
) != 1)
3005 bfd_set_error (bfd_error_system_call
);
3009 obj_som_file_hdr (abfd
)->unloadable_sp_size
3010 = current_offset
- obj_som_file_hdr (abfd
)->unloadable_sp_location
;
3012 /* Loader fixups are not supported in any way shape or form. */
3013 obj_som_file_hdr (abfd
)->loader_fixup_location
= 0;
3014 obj_som_file_hdr (abfd
)->loader_fixup_total
= 0;
3016 /* Done. Store the total size of the SOM. */
3017 obj_som_file_hdr (abfd
)->som_length
= current_offset
;
3019 /* Now write the exec header. */
3020 if (abfd
->flags
& EXEC_P
)
3024 /* Oh joys. Ram some of the BSS data into the DATA section
3025 to be compatable with how the hp linker makes objects
3026 (saves memory space). */
3027 tmp
= exec_header
.exec_dsize
;
3028 tmp
= SOM_ALIGN (tmp
, PA_PAGESIZE
);
3029 exec_header
.exec_bsize
-= (tmp
- exec_header
.exec_dsize
);
3030 exec_header
.exec_dsize
= tmp
;
3032 bfd_seek (abfd
, obj_som_file_hdr (abfd
)->aux_header_location
, SEEK_SET
);
3034 if (bfd_write ((PTR
) &exec_header
, AUX_HDR_SIZE
, 1, abfd
)
3037 bfd_set_error (bfd_error_system_call
);
3044 /* Finally, scribble out the various headers to the disk. */
3047 som_write_headers (abfd
)
3050 int num_spaces
= som_count_spaces (abfd
);
3052 int subspace_index
= 0;
3056 /* Subspaces are written first so that we can set up information
3057 about them in their containing spaces as the subspace is written. */
3059 /* Seek to the start of the subspace dictionary records. */
3060 location
= obj_som_file_hdr (abfd
)->subspace_location
;
3061 bfd_seek (abfd
, location
, SEEK_SET
);
3062 section
= abfd
->sections
;
3063 /* Now for each loadable space write out records for its subspaces. */
3064 for (i
= 0; i
< num_spaces
; i
++)
3066 asection
*subsection
;
3069 while (som_section_data (section
)->is_space
== 0)
3070 section
= section
->next
;
3072 /* Now look for all its subspaces. */
3073 for (subsection
= abfd
->sections
;
3075 subsection
= subsection
->next
)
3078 /* Skip any section which does not correspond to a space
3079 or subspace. Or does not have SEC_ALLOC set (and therefore
3080 has no real bits on the disk). */
3081 if (som_section_data (subsection
)->is_subspace
== 0
3082 || som_section_data (subsection
)->containing_space
!= section
3083 || (subsection
->flags
& SEC_ALLOC
) == 0)
3086 /* If this is the first subspace for this space, then save
3087 the index of the subspace in its containing space. Also
3088 set "is_loadable" in the containing space. */
3090 if (som_section_data (section
)->space_dict
.subspace_quantity
== 0)
3092 som_section_data (section
)->space_dict
.is_loadable
= 1;
3093 som_section_data (section
)->space_dict
.subspace_index
3097 /* Increment the number of subspaces seen and the number of
3098 subspaces contained within the current space. */
3100 som_section_data (section
)->space_dict
.subspace_quantity
++;
3102 /* Mark the index of the current space within the subspace's
3103 dictionary record. */
3104 som_section_data (subsection
)->subspace_dict
.space_index
= i
;
3106 /* Dump the current subspace header. */
3107 if (bfd_write ((PTR
) &som_section_data (subsection
)->subspace_dict
,
3108 sizeof (struct subspace_dictionary_record
), 1, abfd
)
3109 != sizeof (struct subspace_dictionary_record
))
3111 bfd_set_error (bfd_error_system_call
);
3115 /* Goto the next section. */
3116 section
= section
->next
;
3119 /* Now repeat the process for unloadable subspaces. */
3120 section
= abfd
->sections
;
3121 /* Now for each space write out records for its subspaces. */
3122 for (i
= 0; i
< num_spaces
; i
++)
3124 asection
*subsection
;
3127 while (som_section_data (section
)->is_space
== 0)
3128 section
= section
->next
;
3130 /* Now look for all its subspaces. */
3131 for (subsection
= abfd
->sections
;
3133 subsection
= subsection
->next
)
3136 /* Skip any section which does not correspond to a space or
3137 subspace, or which SEC_ALLOC set (and therefore handled
3138 in the loadable spaces/subspaces code above. */
3140 if (som_section_data (subsection
)->is_subspace
== 0
3141 || som_section_data (subsection
)->containing_space
!= section
3142 || (subsection
->flags
& SEC_ALLOC
) != 0)
3145 /* If this is the first subspace for this space, then save
3146 the index of the subspace in its containing space. Clear
3149 if (som_section_data (section
)->space_dict
.subspace_quantity
== 0)
3151 som_section_data (section
)->space_dict
.is_loadable
= 0;
3152 som_section_data (section
)->space_dict
.subspace_index
3156 /* Increment the number of subspaces seen and the number of
3157 subspaces contained within the current space. */
3158 som_section_data (section
)->space_dict
.subspace_quantity
++;
3161 /* Mark the index of the current space within the subspace's
3162 dictionary record. */
3163 som_section_data (subsection
)->subspace_dict
.space_index
= i
;
3165 /* Dump this subspace header. */
3166 if (bfd_write ((PTR
) &som_section_data (subsection
)->subspace_dict
,
3167 sizeof (struct subspace_dictionary_record
), 1, abfd
)
3168 != sizeof (struct subspace_dictionary_record
))
3170 bfd_set_error (bfd_error_system_call
);
3174 /* Goto the next section. */
3175 section
= section
->next
;
3178 /* All the subspace dictiondary records are written, and all the
3179 fields are set up in the space dictionary records.
3181 Seek to the right location and start writing the space
3182 dictionary records. */
3183 location
= obj_som_file_hdr (abfd
)->space_location
;
3184 bfd_seek (abfd
, location
, SEEK_SET
);
3186 section
= abfd
->sections
;
3187 for (i
= 0; i
< num_spaces
; i
++)
3191 while (som_section_data (section
)->is_space
== 0)
3192 section
= section
->next
;
3194 /* Dump its header */
3195 if (bfd_write ((PTR
) &som_section_data (section
)->space_dict
,
3196 sizeof (struct space_dictionary_record
), 1, abfd
)
3197 != sizeof (struct space_dictionary_record
))
3199 bfd_set_error (bfd_error_system_call
);
3203 /* Goto the next section. */
3204 section
= section
->next
;
3207 /* Only thing left to do is write out the file header. It is always
3208 at location zero. Seek there and write it. */
3209 bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
);
3210 if (bfd_write ((PTR
) obj_som_file_hdr (abfd
),
3211 sizeof (struct header
), 1, abfd
)
3212 != sizeof (struct header
))
3214 bfd_set_error (bfd_error_system_call
);
3220 /* Compute and return the checksum for a SOM file header. */
3222 static unsigned long
3223 som_compute_checksum (abfd
)
3226 unsigned long checksum
, count
, i
;
3227 unsigned long *buffer
= (unsigned long *) obj_som_file_hdr (abfd
);
3230 count
= sizeof (struct header
) / sizeof (unsigned long);
3231 for (i
= 0; i
< count
; i
++)
3232 checksum
^= *(buffer
+ i
);
3238 som_bfd_derive_misc_symbol_info (abfd
, sym
, info
)
3241 struct som_misc_symbol_info
*info
;
3244 memset (info
, 0, sizeof (struct som_misc_symbol_info
));
3246 /* The HP SOM linker requires detailed type information about
3247 all symbols (including undefined symbols!). Unfortunately,
3248 the type specified in an import/export statement does not
3249 always match what the linker wants. Severe braindamage. */
3251 /* Section symbols will not have a SOM symbol type assigned to
3252 them yet. Assign all section symbols type ST_DATA. */
3253 if (sym
->flags
& BSF_SECTION_SYM
)
3254 info
->symbol_type
= ST_DATA
;
3257 /* Common symbols must have scope SS_UNSAT and type
3258 ST_STORAGE or the linker will choke. */
3259 if (sym
->section
== &bfd_com_section
)
3261 info
->symbol_scope
= SS_UNSAT
;
3262 info
->symbol_type
= ST_STORAGE
;
3265 /* It is possible to have a symbol without an associated
3266 type. This happens if the user imported the symbol
3267 without a type and the symbol was never defined
3268 locally. If BSF_FUNCTION is set for this symbol, then
3269 assign it type ST_CODE (the HP linker requires undefined
3270 external functions to have type ST_CODE rather than ST_ENTRY). */
3271 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
3272 && sym
->section
== &bfd_und_section
3273 && sym
->flags
& BSF_FUNCTION
)
3274 info
->symbol_type
= ST_CODE
;
3276 /* Handle function symbols which were defined in this file.
3277 They should have type ST_ENTRY. Also retrieve the argument
3278 relocation bits from the SOM backend information. */
3279 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_ENTRY
3280 || (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
3281 && (sym
->flags
& BSF_FUNCTION
))
3282 || (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
3283 && (sym
->flags
& BSF_FUNCTION
)))
3285 info
->symbol_type
= ST_ENTRY
;
3286 info
->arg_reloc
= som_symbol_data (sym
)->tc_data
.hppa_arg_reloc
;
3289 /* If the type is unknown at this point, it should be
3290 ST_DATA (functions were handled as special cases above). */
3291 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
)
3292 info
->symbol_type
= ST_DATA
;
3294 /* From now on it's a very simple mapping. */
3295 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_ABSOLUTE
)
3296 info
->symbol_type
= ST_ABSOLUTE
;
3297 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
)
3298 info
->symbol_type
= ST_CODE
;
3299 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_DATA
)
3300 info
->symbol_type
= ST_DATA
;
3301 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_MILLICODE
)
3302 info
->symbol_type
= ST_MILLICODE
;
3303 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_PLABEL
)
3304 info
->symbol_type
= ST_PLABEL
;
3305 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_PRI_PROG
)
3306 info
->symbol_type
= ST_PRI_PROG
;
3307 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_SEC_PROG
)
3308 info
->symbol_type
= ST_SEC_PROG
;
3311 /* Now handle the symbol's scope. Exported data which is not
3312 in the common section has scope SS_UNIVERSAL. Note scope
3313 of common symbols was handled earlier! */
3314 if (sym
->flags
& BSF_EXPORT
&& sym
->section
!= &bfd_com_section
)
3315 info
->symbol_scope
= SS_UNIVERSAL
;
3316 /* Any undefined symbol at this point has a scope SS_UNSAT. */
3317 else if (sym
->section
== &bfd_und_section
)
3318 info
->symbol_scope
= SS_UNSAT
;
3319 /* Anything else which is not in the common section has scope
3321 else if (sym
->section
!= &bfd_com_section
)
3322 info
->symbol_scope
= SS_LOCAL
;
3324 /* Now set the symbol_info field. It has no real meaning
3325 for undefined or common symbols, but the HP linker will
3326 choke if it's not set to some "reasonable" value. We
3327 use zero as a reasonable value. */
3328 if (sym
->section
== &bfd_com_section
|| sym
->section
== &bfd_und_section
3329 || sym
->section
== &bfd_abs_section
)
3330 info
->symbol_info
= 0;
3331 /* For all other symbols, the symbol_info field contains the
3332 subspace index of the space this symbol is contained in. */
3334 info
->symbol_info
= som_section_data (sym
->section
)->subspace_index
;
3336 /* Set the symbol's value. */
3337 info
->symbol_value
= sym
->value
+ sym
->section
->vma
;
3340 /* Build and write, in one big chunk, the entire symbol table for
3344 som_build_and_write_symbol_table (abfd
)
3347 unsigned int num_syms
= bfd_get_symcount (abfd
);
3348 file_ptr symtab_location
= obj_som_file_hdr (abfd
)->symbol_location
;
3349 asymbol
**bfd_syms
= bfd_get_outsymbols (abfd
);
3350 struct symbol_dictionary_record
*som_symtab
= NULL
;
3353 /* Compute total symbol table size and allocate a chunk of memory
3354 to hold the symbol table as we build it. */
3355 symtab_size
= num_syms
* sizeof (struct symbol_dictionary_record
);
3356 som_symtab
= (struct symbol_dictionary_record
*) malloc (symtab_size
);
3357 if (som_symtab
== NULL
&& symtab_size
!= 0)
3359 bfd_set_error (bfd_error_no_memory
);
3362 memset (som_symtab
, 0, symtab_size
);
3364 /* Walk over each symbol. */
3365 for (i
= 0; i
< num_syms
; i
++)
3367 struct som_misc_symbol_info info
;
3369 /* This is really an index into the symbol strings table.
3370 By the time we get here, the index has already been
3371 computed and stored into the name field in the BFD symbol. */
3372 som_symtab
[i
].name
.n_strx
= (int) bfd_syms
[i
]->name
;
3374 /* Derive SOM information from the BFD symbol. */
3375 som_bfd_derive_misc_symbol_info (abfd
, bfd_syms
[i
], &info
);
3378 som_symtab
[i
].symbol_type
= info
.symbol_type
;
3379 som_symtab
[i
].symbol_scope
= info
.symbol_scope
;
3380 som_symtab
[i
].arg_reloc
= info
.arg_reloc
;
3381 som_symtab
[i
].symbol_info
= info
.symbol_info
;
3382 som_symtab
[i
].symbol_value
= info
.symbol_value
;
3385 /* Everything is ready, seek to the right location and
3386 scribble out the symbol table. */
3387 if (bfd_seek (abfd
, symtab_location
, SEEK_SET
) != 0)
3389 bfd_set_error (bfd_error_system_call
);
3393 if (bfd_write ((PTR
) som_symtab
, symtab_size
, 1, abfd
) != symtab_size
)
3395 bfd_set_error (bfd_error_system_call
);
3399 if (som_symtab
!= NULL
)
3403 if (som_symtab
!= NULL
)
3408 /* Write an object in SOM format. */
3411 som_write_object_contents (abfd
)
3414 if (abfd
->output_has_begun
== false)
3416 /* Set up fixed parts of the file, space, and subspace headers.
3417 Notify the world that output has begun. */
3418 som_prep_headers (abfd
);
3419 abfd
->output_has_begun
= true;
3420 /* Start writing the object file. This include all the string
3421 tables, fixup streams, and other portions of the object file. */
3422 som_begin_writing (abfd
);
3425 /* Now that the symbol table information is complete, build and
3426 write the symbol table. */
3427 if (som_build_and_write_symbol_table (abfd
) == false)
3430 /* Compute the checksum for the file header just before writing
3431 the header to disk. */
3432 obj_som_file_hdr (abfd
)->checksum
= som_compute_checksum (abfd
);
3433 return (som_write_headers (abfd
));
3437 /* Read and save the string table associated with the given BFD. */
3440 som_slurp_string_table (abfd
)
3445 /* Use the saved version if its available. */
3446 if (obj_som_stringtab (abfd
) != NULL
)
3449 /* Allocate and read in the string table. */
3450 stringtab
= bfd_zalloc (abfd
, obj_som_stringtab_size (abfd
));
3451 if (stringtab
== NULL
)
3453 bfd_set_error (bfd_error_no_memory
);
3457 if (bfd_seek (abfd
, obj_som_str_filepos (abfd
), SEEK_SET
) < 0)
3459 bfd_set_error (bfd_error_system_call
);
3463 if (bfd_read (stringtab
, obj_som_stringtab_size (abfd
), 1, abfd
)
3464 != obj_som_stringtab_size (abfd
))
3466 bfd_set_error (bfd_error_system_call
);
3470 /* Save our results and return success. */
3471 obj_som_stringtab (abfd
) = stringtab
;
3475 /* Return the amount of data (in bytes) required to hold the symbol
3476 table for this object. */
3479 som_get_symtab_upper_bound (abfd
)
3482 if (!som_slurp_symbol_table (abfd
))
3485 return (bfd_get_symcount (abfd
) + 1) * (sizeof (asymbol
*));
3488 /* Convert from a SOM subspace index to a BFD section. */
3491 som_section_from_subspace_index (abfd
, index
)
3497 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
3498 if (som_section_data (section
)->subspace_index
== index
)
3501 /* Should never happen. */
3505 /* Read and save the symbol table associated with the given BFD. */
3508 som_slurp_symbol_table (abfd
)
3511 int symbol_count
= bfd_get_symcount (abfd
);
3512 int symsize
= sizeof (struct symbol_dictionary_record
);
3514 struct symbol_dictionary_record
*buf
= NULL
, *bufp
, *endbufp
;
3515 som_symbol_type
*sym
, *symbase
;
3517 /* Return saved value if it exists. */
3518 if (obj_som_symtab (abfd
) != NULL
)
3519 goto successful_return
;
3521 /* Special case. This is *not* an error. */
3522 if (symbol_count
== 0)
3523 goto successful_return
;
3525 if (!som_slurp_string_table (abfd
))
3528 stringtab
= obj_som_stringtab (abfd
);
3530 symbase
= (som_symbol_type
*)
3531 bfd_zalloc (abfd
, symbol_count
* sizeof (som_symbol_type
));
3532 if (symbase
== NULL
)
3534 bfd_set_error (bfd_error_no_memory
);
3538 /* Read in the external SOM representation. */
3539 buf
= malloc (symbol_count
* symsize
);
3540 if (buf
== NULL
&& symbol_count
* symsize
!= 0)
3542 bfd_set_error (bfd_error_no_memory
);
3545 if (bfd_seek (abfd
, obj_som_sym_filepos (abfd
), SEEK_SET
) < 0)
3547 bfd_set_error (bfd_error_system_call
);
3550 if (bfd_read (buf
, symbol_count
* symsize
, 1, abfd
)
3551 != symbol_count
* symsize
)
3553 bfd_set_error (bfd_error_no_symbols
);
3557 /* Iterate over all the symbols and internalize them. */
3558 endbufp
= buf
+ symbol_count
;
3559 for (bufp
= buf
, sym
= symbase
; bufp
< endbufp
; ++bufp
)
3562 /* I don't think we care about these. */
3563 if (bufp
->symbol_type
== ST_SYM_EXT
3564 || bufp
->symbol_type
== ST_ARG_EXT
)
3567 /* Set some private data we care about. */
3568 if (bufp
->symbol_type
== ST_NULL
)
3569 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_UNKNOWN
;
3570 else if (bufp
->symbol_type
== ST_ABSOLUTE
)
3571 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_ABSOLUTE
;
3572 else if (bufp
->symbol_type
== ST_DATA
)
3573 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_DATA
;
3574 else if (bufp
->symbol_type
== ST_CODE
)
3575 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_CODE
;
3576 else if (bufp
->symbol_type
== ST_PRI_PROG
)
3577 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_PRI_PROG
;
3578 else if (bufp
->symbol_type
== ST_SEC_PROG
)
3579 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_SEC_PROG
;
3580 else if (bufp
->symbol_type
== ST_ENTRY
)
3581 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_ENTRY
;
3582 else if (bufp
->symbol_type
== ST_MILLICODE
)
3583 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_MILLICODE
;
3584 else if (bufp
->symbol_type
== ST_PLABEL
)
3585 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_PLABEL
;
3587 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_UNKNOWN
;
3588 som_symbol_data (sym
)->tc_data
.hppa_arg_reloc
= bufp
->arg_reloc
;
3590 /* Some reasonable defaults. */
3591 sym
->symbol
.the_bfd
= abfd
;
3592 sym
->symbol
.name
= bufp
->name
.n_strx
+ stringtab
;
3593 sym
->symbol
.value
= bufp
->symbol_value
;
3594 sym
->symbol
.section
= 0;
3595 sym
->symbol
.flags
= 0;
3597 switch (bufp
->symbol_type
)
3603 sym
->symbol
.flags
|= BSF_FUNCTION
;
3604 sym
->symbol
.value
&= ~0x3;
3609 sym
->symbol
.value
&= ~0x3;
3615 /* Handle scoping and section information. */
3616 switch (bufp
->symbol_scope
)
3618 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
3619 so the section associated with this symbol can't be known. */
3621 if (bufp
->symbol_type
!= ST_STORAGE
)
3622 sym
->symbol
.section
= &bfd_und_section
;
3624 sym
->symbol
.section
= &bfd_com_section
;
3625 sym
->symbol
.flags
|= (BSF_EXPORT
| BSF_GLOBAL
);
3629 if (bufp
->symbol_type
!= ST_STORAGE
)
3630 sym
->symbol
.section
= &bfd_und_section
;
3632 sym
->symbol
.section
= &bfd_com_section
;
3636 sym
->symbol
.flags
|= (BSF_EXPORT
| BSF_GLOBAL
);
3638 = som_section_from_subspace_index (abfd
, bufp
->symbol_info
);
3639 sym
->symbol
.value
-= sym
->symbol
.section
->vma
;
3643 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
3644 Sound dumb? It is. */
3648 sym
->symbol
.flags
|= BSF_LOCAL
;
3650 = som_section_from_subspace_index (abfd
, bufp
->symbol_info
);
3651 sym
->symbol
.value
-= sym
->symbol
.section
->vma
;
3655 /* Mark section symbols and symbols used by the debugger. */
3656 if (sym
->symbol
.name
[0] == '$'
3657 && sym
->symbol
.name
[strlen (sym
->symbol
.name
) - 1] == '$')
3658 sym
->symbol
.flags
|= BSF_SECTION_SYM
;
3659 else if (!strncmp (sym
->symbol
.name
, "L$0\002", 4))
3661 sym
->symbol
.flags
|= BSF_SECTION_SYM
;
3662 sym
->symbol
.name
= sym
->symbol
.section
->name
;
3664 else if (!strncmp (sym
->symbol
.name
, "L$0\001", 4))
3665 sym
->symbol
.flags
|= BSF_DEBUGGING
;
3667 /* Note increment at bottom of loop, since we skip some symbols
3668 we can not include it as part of the for statement. */
3672 /* Save our results and return success. */
3673 obj_som_symtab (abfd
) = symbase
;
3685 /* Canonicalize a SOM symbol table. Return the number of entries
3686 in the symbol table. */
3689 som_get_symtab (abfd
, location
)
3694 som_symbol_type
*symbase
;
3696 if (!som_slurp_symbol_table (abfd
))
3699 i
= bfd_get_symcount (abfd
);
3700 symbase
= obj_som_symtab (abfd
);
3702 for (; i
> 0; i
--, location
++, symbase
++)
3703 *location
= &symbase
->symbol
;
3705 /* Final null pointer. */
3707 return (bfd_get_symcount (abfd
));
3710 /* Make a SOM symbol. There is nothing special to do here. */
3713 som_make_empty_symbol (abfd
)
3716 som_symbol_type
*new =
3717 (som_symbol_type
*) bfd_zalloc (abfd
, sizeof (som_symbol_type
));
3720 bfd_set_error (bfd_error_no_memory
);
3723 new->symbol
.the_bfd
= abfd
;
3725 return &new->symbol
;
3728 /* Print symbol information. */
3731 som_print_symbol (ignore_abfd
, afile
, symbol
, how
)
3735 bfd_print_symbol_type how
;
3737 FILE *file
= (FILE *) afile
;
3740 case bfd_print_symbol_name
:
3741 fprintf (file
, "%s", symbol
->name
);
3743 case bfd_print_symbol_more
:
3744 fprintf (file
, "som ");
3745 fprintf_vma (file
, symbol
->value
);
3746 fprintf (file
, " %lx", (long) symbol
->flags
);
3748 case bfd_print_symbol_all
:
3750 CONST
char *section_name
;
3751 section_name
= symbol
->section
? symbol
->section
->name
: "(*none*)";
3752 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
3753 fprintf (file
, " %s\t%s", section_name
, symbol
->name
);
3760 som_bfd_is_local_label (abfd
, sym
)
3764 return (sym
->name
[0] == 'L' && sym
->name
[1] == '$');
3767 /* Count or process variable-length SOM fixup records.
3769 To avoid code duplication we use this code both to compute the number
3770 of relocations requested by a stream, and to internalize the stream.
3772 When computing the number of relocations requested by a stream the
3773 variables rptr, section, and symbols have no meaning.
3775 Return the number of relocations requested by the fixup stream. When
3778 This needs at least two or three more passes to get it cleaned up. */
3781 som_set_reloc_info (fixup
, end
, internal_relocs
, section
, symbols
, just_count
)
3782 unsigned char *fixup
;
3784 arelent
*internal_relocs
;
3789 unsigned int op
, varname
;
3790 unsigned char *end_fixups
= &fixup
[end
];
3791 const struct fixup_format
*fp
;
3793 unsigned char *save_fixup
;
3794 int variables
[26], stack
[20], c
, v
, count
, prev_fixup
, *sp
;
3796 arelent
*rptr
= internal_relocs
;
3797 unsigned int offset
= just_count
? 0 : section
->vma
;
3799 #define var(c) variables[(c) - 'A']
3800 #define push(v) (*sp++ = (v))
3801 #define pop() (*--sp)
3802 #define emptystack() (sp == stack)
3804 som_initialize_reloc_queue (reloc_queue
);
3805 memset (variables
, 0, sizeof (variables
));
3806 memset (stack
, 0, sizeof (stack
));
3811 while (fixup
< end_fixups
)
3814 /* Save pointer to the start of this fixup. We'll use
3815 it later to determine if it is necessary to put this fixup
3819 /* Get the fixup code and its associated format. */
3821 fp
= &som_fixup_formats
[op
];
3823 /* Handle a request for a previous fixup. */
3824 if (*fp
->format
== 'P')
3826 /* Get pointer to the beginning of the prev fixup, move
3827 the repeated fixup to the head of the queue. */
3828 fixup
= reloc_queue
[fp
->D
].reloc
;
3829 som_reloc_queue_fix (reloc_queue
, fp
->D
);
3832 /* Get the fixup code and its associated format. */
3834 fp
= &som_fixup_formats
[op
];
3837 /* If we are not just counting, set some reasonable defaults. */
3840 rptr
->address
= offset
;
3841 rptr
->howto
= &som_hppa_howto_table
[op
];
3843 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
3846 /* Set default input length to 0. Get the opcode class index
3851 /* Get the opcode format. */
3854 /* Process the format string. Parsing happens in two phases,
3855 parse RHS, then assign to LHS. Repeat until no more
3856 characters in the format string. */
3859 /* The variable this pass is going to compute a value for. */
3862 /* Start processing RHS. Continue until a NULL or '=' is found. */
3867 /* If this is a variable, push it on the stack. */
3871 /* If this is a lower case letter, then it represents
3872 additional data from the fixup stream to be pushed onto
3874 else if (islower (c
))
3876 for (v
= 0; c
> 'a'; --c
)
3877 v
= (v
<< 8) | *fixup
++;
3881 /* A decimal constant. Push it on the stack. */
3882 else if (isdigit (c
))
3885 while (isdigit (*cp
))
3886 v
= (v
* 10) + (*cp
++ - '0');
3891 /* An operator. Pop two two values from the stack and
3892 use them as operands to the given operation. Push
3893 the result of the operation back on the stack. */
3915 while (*cp
&& *cp
!= '=');
3917 /* Move over the equal operator. */
3920 /* Pop the RHS off the stack. */
3923 /* Perform the assignment. */
3926 /* Handle side effects. and special 'O' stack cases. */
3929 /* Consume some bytes from the input space. */
3933 /* A symbol to use in the relocation. Make a note
3934 of this if we are not just counting. */
3937 rptr
->sym_ptr_ptr
= &symbols
[c
];
3939 /* Handle the linker expression stack. */
3944 subop
= comp1_opcodes
;
3947 subop
= comp2_opcodes
;
3950 subop
= comp3_opcodes
;
3955 while (*subop
<= (unsigned char) c
)
3964 /* If we used a previous fixup, clean up after it. */
3967 fixup
= save_fixup
+ 1;
3971 else if (fixup
> save_fixup
+ 1)
3972 som_reloc_queue_insert (save_fixup
, fixup
- save_fixup
, reloc_queue
);
3974 /* We do not pass R_DATA_OVERRIDE or R_NO_RELOCATION
3976 if (som_hppa_howto_table
[op
].type
!= R_DATA_OVERRIDE
3977 && som_hppa_howto_table
[op
].type
!= R_NO_RELOCATION
)
3979 /* Done with a single reloction. Loop back to the top. */
3982 rptr
->addend
= var ('V');
3986 /* Now that we've handled a "full" relocation, reset
3988 memset (variables
, 0, sizeof (variables
));
3989 memset (stack
, 0, sizeof (stack
));
4000 /* Read in the relocs (aka fixups in SOM terms) for a section.
4002 som_get_reloc_upper_bound calls this routine with JUST_COUNT
4003 set to true to indicate it only needs a count of the number
4004 of actual relocations. */
4007 som_slurp_reloc_table (abfd
, section
, symbols
, just_count
)
4013 char *external_relocs
;
4014 unsigned int fixup_stream_size
;
4015 arelent
*internal_relocs
;
4016 unsigned int num_relocs
;
4018 fixup_stream_size
= som_section_data (section
)->reloc_size
;
4019 /* If there were no relocations, then there is nothing to do. */
4020 if (section
->reloc_count
== 0)
4023 /* If reloc_count is -1, then the relocation stream has not been
4024 parsed. We must do so now to know how many relocations exist. */
4025 if (section
->reloc_count
== -1)
4027 external_relocs
= (char *) bfd_zalloc (abfd
, fixup_stream_size
);
4028 if (external_relocs
== (char *) NULL
)
4030 bfd_set_error (bfd_error_no_memory
);
4033 /* Read in the external forms. */
4035 obj_som_reloc_filepos (abfd
) + section
->rel_filepos
,
4039 bfd_set_error (bfd_error_system_call
);
4042 if (bfd_read (external_relocs
, 1, fixup_stream_size
, abfd
)
4043 != fixup_stream_size
)
4045 bfd_set_error (bfd_error_system_call
);
4048 /* Let callers know how many relocations found.
4049 also save the relocation stream as we will
4051 section
->reloc_count
= som_set_reloc_info (external_relocs
,
4053 NULL
, NULL
, NULL
, true);
4055 som_section_data (section
)->reloc_stream
= external_relocs
;
4058 /* If the caller only wanted a count, then return now. */
4062 num_relocs
= section
->reloc_count
;
4063 external_relocs
= som_section_data (section
)->reloc_stream
;
4064 /* Return saved information about the relocations if it is available. */
4065 if (section
->relocation
!= (arelent
*) NULL
)
4068 internal_relocs
= (arelent
*) bfd_zalloc (abfd
,
4069 num_relocs
* sizeof (arelent
));
4070 if (internal_relocs
== (arelent
*) NULL
)
4072 bfd_set_error (bfd_error_no_memory
);
4076 /* Process and internalize the relocations. */
4077 som_set_reloc_info (external_relocs
, fixup_stream_size
,
4078 internal_relocs
, section
, symbols
, false);
4080 /* Save our results and return success. */
4081 section
->relocation
= internal_relocs
;
4085 /* Return the number of bytes required to store the relocation
4086 information associated with the given section. */
4089 som_get_reloc_upper_bound (abfd
, asect
)
4093 /* If section has relocations, then read in the relocation stream
4094 and parse it to determine how many relocations exist. */
4095 if (asect
->flags
& SEC_RELOC
)
4097 if (som_slurp_reloc_table (abfd
, asect
, NULL
, true))
4098 return (asect
->reloc_count
+ 1) * sizeof (arelent
);
4100 /* Either there are no relocations or an error occurred while
4101 reading and parsing the relocation stream. */
4105 /* Convert relocations from SOM (external) form into BFD internal
4106 form. Return the number of relocations. */
4109 som_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
4118 if (som_slurp_reloc_table (abfd
, section
, symbols
, false) == false)
4121 count
= section
->reloc_count
;
4122 tblptr
= section
->relocation
;
4123 if (tblptr
== (arelent
*) NULL
)
4127 *relptr
++ = tblptr
++;
4129 *relptr
= (arelent
*) NULL
;
4130 return section
->reloc_count
;
4133 extern bfd_target som_vec
;
4135 /* A hook to set up object file dependent section information. */
4138 som_new_section_hook (abfd
, newsect
)
4142 newsect
->used_by_bfd
=
4143 (PTR
) bfd_zalloc (abfd
, sizeof (struct som_section_data_struct
));
4144 if (!newsect
->used_by_bfd
)
4146 bfd_set_error (bfd_error_no_memory
);
4149 newsect
->alignment_power
= 3;
4151 /* Initialize the subspace_index field to -1 so that it does
4152 not match a subspace with an index of 0. */
4153 som_section_data (newsect
)->subspace_index
= -1;
4155 /* We allow more than three sections internally */
4159 /* Copy any private info we understand from the input section
4160 to the output section. */
4162 som_bfd_copy_private_section_data (ibfd
, isection
, obfd
, osection
)
4168 /* One day we may try to grok other private data. */
4169 if (ibfd
->xvec
->flavour
!= bfd_target_som_flavour
4170 || obfd
->xvec
->flavour
!= bfd_target_som_flavour
)
4173 memcpy (som_section_data (osection
), som_section_data (isection
),
4174 sizeof (struct som_section_data_struct
));
4176 /* Reparent if necessary. */
4177 if (som_section_data (osection
)->containing_space
)
4178 som_section_data (osection
)->containing_space
=
4179 som_section_data (osection
)->containing_space
->output_section
;
4182 /* Set backend info for sections which can not be described
4183 in the BFD data structures. */
4186 bfd_som_set_section_attributes (section
, defined
, private, sort_key
, spnum
)
4190 unsigned int sort_key
;
4193 struct space_dictionary_record
*space_dict
;
4195 som_section_data (section
)->is_space
= 1;
4196 space_dict
= &som_section_data (section
)->space_dict
;
4197 space_dict
->is_defined
= defined
;
4198 space_dict
->is_private
= private;
4199 space_dict
->sort_key
= sort_key
;
4200 space_dict
->space_number
= spnum
;
4203 /* Set backend info for subsections which can not be described
4204 in the BFD data structures. */
4207 bfd_som_set_subsection_attributes (section
, container
, access
,
4210 asection
*container
;
4212 unsigned int sort_key
;
4215 struct subspace_dictionary_record
*subspace_dict
;
4216 som_section_data (section
)->is_subspace
= 1;
4217 subspace_dict
= &som_section_data (section
)->subspace_dict
;
4218 subspace_dict
->access_control_bits
= access
;
4219 subspace_dict
->sort_key
= sort_key
;
4220 subspace_dict
->quadrant
= quadrant
;
4221 som_section_data (section
)->containing_space
= container
;
4224 /* Set the full SOM symbol type. SOM needs far more symbol information
4225 than any other object file format I'm aware of. It is mandatory
4226 to be able to know if a symbol is an entry point, millicode, data,
4227 code, absolute, storage request, or procedure label. If you get
4228 the symbol type wrong your program will not link. */
4231 bfd_som_set_symbol_type (symbol
, type
)
4235 som_symbol_data (symbol
)->som_type
= type
;
4238 /* Attach 64bits of unwind information to a symbol (which hopefully
4239 is a function of some kind!). It would be better to keep this
4240 in the R_ENTRY relocation, but there is not enough space. */
4243 bfd_som_attach_unwind_info (symbol
, unwind_desc
)
4247 som_symbol_data (symbol
)->unwind
= unwind_desc
;
4250 /* Attach an auxiliary header to the BFD backend so that it may be
4251 written into the object file. */
4253 bfd_som_attach_aux_hdr (abfd
, type
, string
)
4258 if (type
== VERSION_AUX_ID
)
4260 int len
= strlen (string
);
4264 pad
= (4 - (len
% 4));
4265 obj_som_version_hdr (abfd
) = (struct user_string_aux_hdr
*)
4266 bfd_zalloc (abfd
, sizeof (struct aux_id
)
4267 + sizeof (unsigned int) + len
+ pad
);
4268 if (!obj_som_version_hdr (abfd
))
4270 bfd_set_error (bfd_error_no_memory
);
4273 obj_som_version_hdr (abfd
)->header_id
.type
= VERSION_AUX_ID
;
4274 obj_som_version_hdr (abfd
)->header_id
.length
= len
+ pad
;
4275 obj_som_version_hdr (abfd
)->header_id
.length
+= sizeof (int);
4276 obj_som_version_hdr (abfd
)->string_length
= len
;
4277 strncpy (obj_som_version_hdr (abfd
)->user_string
, string
, len
);
4279 else if (type
== COPYRIGHT_AUX_ID
)
4281 int len
= strlen (string
);
4285 pad
= (4 - (len
% 4));
4286 obj_som_copyright_hdr (abfd
) = (struct copyright_aux_hdr
*)
4287 bfd_zalloc (abfd
, sizeof (struct aux_id
)
4288 + sizeof (unsigned int) + len
+ pad
);
4289 if (!obj_som_copyright_hdr (abfd
))
4291 bfd_set_error (bfd_error_no_error
);
4294 obj_som_copyright_hdr (abfd
)->header_id
.type
= COPYRIGHT_AUX_ID
;
4295 obj_som_copyright_hdr (abfd
)->header_id
.length
= len
+ pad
;
4296 obj_som_copyright_hdr (abfd
)->header_id
.length
+= sizeof (int);
4297 obj_som_copyright_hdr (abfd
)->string_length
= len
;
4298 strcpy (obj_som_copyright_hdr (abfd
)->copyright
, string
);
4304 som_set_section_contents (abfd
, section
, location
, offset
, count
)
4309 bfd_size_type count
;
4311 if (abfd
->output_has_begun
== false)
4313 /* Set up fixed parts of the file, space, and subspace headers.
4314 Notify the world that output has begun. */
4315 som_prep_headers (abfd
);
4316 abfd
->output_has_begun
= true;
4317 /* Start writing the object file. This include all the string
4318 tables, fixup streams, and other portions of the object file. */
4319 som_begin_writing (abfd
);
4322 /* Only write subspaces which have "real" contents (eg. the contents
4323 are not generated at run time by the OS). */
4324 if (som_section_data (section
)->is_subspace
!= 1
4325 || ((section
->flags
& (SEC_LOAD
| SEC_DEBUGGING
)) == 0))
4328 /* Seek to the proper offset within the object file and write the
4330 offset
+= som_section_data (section
)->subspace_dict
.file_loc_init_value
;
4331 if (bfd_seek (abfd
, offset
, SEEK_SET
) == -1)
4333 bfd_set_error (bfd_error_system_call
);
4337 if (bfd_write ((PTR
) location
, 1, count
, abfd
) != count
)
4339 bfd_set_error (bfd_error_system_call
);
4346 som_set_arch_mach (abfd
, arch
, machine
)
4348 enum bfd_architecture arch
;
4349 unsigned long machine
;
4351 /* Allow any architecture to be supported by the SOM backend */
4352 return bfd_default_set_arch_mach (abfd
, arch
, machine
);
4356 som_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
4357 functionname_ptr
, line_ptr
)
4362 CONST
char **filename_ptr
;
4363 CONST
char **functionname_ptr
;
4364 unsigned int *line_ptr
;
4366 fprintf (stderr
, "som_find_nearest_line unimplemented\n");
4373 som_sizeof_headers (abfd
, reloc
)
4377 fprintf (stderr
, "som_sizeof_headers unimplemented\n");
4383 /* Return the single-character symbol type corresponding to
4384 SOM section S, or '?' for an unknown SOM section. */
4387 som_section_type (s
)
4390 const struct section_to_type
*t
;
4392 for (t
= &stt
[0]; t
->section
; t
++)
4393 if (!strcmp (s
, t
->section
))
4399 som_decode_symclass (symbol
)
4404 if (bfd_is_com_section (symbol
->section
))
4406 if (symbol
->section
== &bfd_und_section
)
4408 if (symbol
->section
== &bfd_ind_section
)
4410 if (!(symbol
->flags
& (BSF_GLOBAL
|BSF_LOCAL
)))
4413 if (symbol
->section
== &bfd_abs_section
)
4415 else if (symbol
->section
)
4416 c
= som_section_type (symbol
->section
->name
);
4419 if (symbol
->flags
& BSF_GLOBAL
)
4424 /* Return information about SOM symbol SYMBOL in RET. */
4427 som_get_symbol_info (ignore_abfd
, symbol
, ret
)
4432 ret
->type
= som_decode_symclass (symbol
);
4433 if (ret
->type
!= 'U')
4434 ret
->value
= symbol
->value
+symbol
->section
->vma
;
4437 ret
->name
= symbol
->name
;
4440 /* Count the number of symbols in the archive symbol table. Necessary
4441 so that we can allocate space for all the carsyms at once. */
4444 som_bfd_count_ar_symbols (abfd
, lst_header
, count
)
4446 struct lst_header
*lst_header
;
4450 unsigned int *hash_table
= NULL
;
4451 file_ptr lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
4454 (unsigned int *) malloc (lst_header
->hash_size
* sizeof (unsigned int));
4455 if (hash_table
== NULL
&& lst_header
->hash_size
!= 0)
4457 bfd_set_error (bfd_error_no_memory
);
4461 /* Don't forget to initialize the counter! */
4464 /* Read in the hash table. The has table is an array of 32bit file offsets
4465 which point to the hash chains. */
4466 if (bfd_read ((PTR
) hash_table
, lst_header
->hash_size
, 4, abfd
)
4467 != lst_header
->hash_size
* 4)
4469 bfd_set_error (bfd_error_system_call
);
4473 /* Walk each chain counting the number of symbols found on that particular
4475 for (i
= 0; i
< lst_header
->hash_size
; i
++)
4477 struct lst_symbol_record lst_symbol
;
4479 /* An empty chain has zero as it's file offset. */
4480 if (hash_table
[i
] == 0)
4483 /* Seek to the first symbol in this hash chain. */
4484 if (bfd_seek (abfd
, lst_filepos
+ hash_table
[i
], SEEK_SET
) < 0)
4486 bfd_set_error (bfd_error_system_call
);
4490 /* Read in this symbol and update the counter. */
4491 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
4492 != sizeof (lst_symbol
))
4494 bfd_set_error (bfd_error_system_call
);
4499 /* Now iterate through the rest of the symbols on this chain. */
4500 while (lst_symbol
.next_entry
)
4503 /* Seek to the next symbol. */
4504 if (bfd_seek (abfd
, lst_filepos
+ lst_symbol
.next_entry
, SEEK_SET
)
4507 bfd_set_error (bfd_error_system_call
);
4511 /* Read the symbol in and update the counter. */
4512 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
4513 != sizeof (lst_symbol
))
4515 bfd_set_error (bfd_error_system_call
);
4521 if (hash_table
!= NULL
)
4526 if (hash_table
!= NULL
)
4531 /* Fill in the canonical archive symbols (SYMS) from the archive described
4532 by ABFD and LST_HEADER. */
4535 som_bfd_fill_in_ar_symbols (abfd
, lst_header
, syms
)
4537 struct lst_header
*lst_header
;
4540 unsigned int i
, len
;
4541 carsym
*set
= syms
[0];
4542 unsigned int *hash_table
= NULL
;
4543 struct som_entry
*som_dict
= NULL
;
4544 file_ptr lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
4547 (unsigned int *) malloc (lst_header
->hash_size
* sizeof (unsigned int));
4548 if (hash_table
== NULL
&& lst_header
->hash_size
!= 0)
4550 bfd_set_error (bfd_error_no_memory
);
4555 (struct som_entry
*) malloc (lst_header
->module_count
4556 * sizeof (struct som_entry
));
4557 if (som_dict
== NULL
&& lst_header
->module_count
!= 0)
4559 bfd_set_error (bfd_error_no_memory
);
4563 /* Read in the hash table. The has table is an array of 32bit file offsets
4564 which point to the hash chains. */
4565 if (bfd_read ((PTR
) hash_table
, lst_header
->hash_size
, 4, abfd
)
4566 != lst_header
->hash_size
* 4)
4568 bfd_set_error (bfd_error_system_call
);
4572 /* Seek to and read in the SOM dictionary. We will need this to fill
4573 in the carsym's filepos field. */
4574 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->dir_loc
, SEEK_SET
) < 0)
4576 bfd_set_error (bfd_error_system_call
);
4580 if (bfd_read ((PTR
) som_dict
, lst_header
->module_count
,
4581 sizeof (struct som_entry
), abfd
)
4582 != lst_header
->module_count
* sizeof (struct som_entry
))
4584 bfd_set_error (bfd_error_system_call
);
4588 /* Walk each chain filling in the carsyms as we go along. */
4589 for (i
= 0; i
< lst_header
->hash_size
; i
++)
4591 struct lst_symbol_record lst_symbol
;
4593 /* An empty chain has zero as it's file offset. */
4594 if (hash_table
[i
] == 0)
4597 /* Seek to and read the first symbol on the chain. */
4598 if (bfd_seek (abfd
, lst_filepos
+ hash_table
[i
], SEEK_SET
) < 0)
4600 bfd_set_error (bfd_error_system_call
);
4604 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
4605 != sizeof (lst_symbol
))
4607 bfd_set_error (bfd_error_system_call
);
4611 /* Get the name of the symbol, first get the length which is stored
4612 as a 32bit integer just before the symbol.
4614 One might ask why we don't just read in the entire string table
4615 and index into it. Well, according to the SOM ABI the string
4616 index can point *anywhere* in the archive to save space, so just
4617 using the string table would not be safe. */
4618 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->string_loc
4619 + lst_symbol
.name
.n_strx
- 4, SEEK_SET
) < 0)
4621 bfd_set_error (bfd_error_system_call
);
4625 if (bfd_read (&len
, 1, 4, abfd
) != 4)
4627 bfd_set_error (bfd_error_system_call
);
4631 /* Allocate space for the name and null terminate it too. */
4632 set
->name
= bfd_zalloc (abfd
, len
+ 1);
4635 bfd_set_error (bfd_error_no_memory
);
4638 if (bfd_read (set
->name
, 1, len
, abfd
) != len
)
4640 bfd_set_error (bfd_error_system_call
);
4645 /* Fill in the file offset. Note that the "location" field points
4646 to the SOM itself, not the ar_hdr in front of it. */
4647 set
->file_offset
= som_dict
[lst_symbol
.som_index
].location
4648 - sizeof (struct ar_hdr
);
4650 /* Go to the next symbol. */
4653 /* Iterate through the rest of the chain. */
4654 while (lst_symbol
.next_entry
)
4656 /* Seek to the next symbol and read it in. */
4657 if (bfd_seek (abfd
, lst_filepos
+ lst_symbol
.next_entry
, SEEK_SET
)
4660 bfd_set_error (bfd_error_system_call
);
4664 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
4665 != sizeof (lst_symbol
))
4667 bfd_set_error (bfd_error_system_call
);
4671 /* Seek to the name length & string and read them in. */
4672 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->string_loc
4673 + lst_symbol
.name
.n_strx
- 4, SEEK_SET
) < 0)
4675 bfd_set_error (bfd_error_system_call
);
4679 if (bfd_read (&len
, 1, 4, abfd
) != 4)
4681 bfd_set_error (bfd_error_system_call
);
4685 /* Allocate space for the name and null terminate it too. */
4686 set
->name
= bfd_zalloc (abfd
, len
+ 1);
4689 bfd_set_error (bfd_error_no_memory
);
4692 if (bfd_read (set
->name
, 1, len
, abfd
) != len
)
4694 bfd_set_error (bfd_error_system_call
);
4699 /* Fill in the file offset. Note that the "location" field points
4700 to the SOM itself, not the ar_hdr in front of it. */
4701 set
->file_offset
= som_dict
[lst_symbol
.som_index
].location
4702 - sizeof (struct ar_hdr
);
4704 /* Go on to the next symbol. */
4708 /* If we haven't died by now, then we successfully read the entire
4709 archive symbol table. */
4710 if (hash_table
!= NULL
)
4712 if (som_dict
!= NULL
)
4717 if (hash_table
!= NULL
)
4719 if (som_dict
!= NULL
)
4724 /* Read in the LST from the archive. */
4726 som_slurp_armap (abfd
)
4729 struct lst_header lst_header
;
4730 struct ar_hdr ar_header
;
4731 unsigned int parsed_size
;
4732 struct artdata
*ardata
= bfd_ardata (abfd
);
4734 int i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
4736 /* Special cases. */
4742 if (bfd_seek (abfd
, (file_ptr
) - 16, SEEK_CUR
) < 0)
4744 bfd_set_error (bfd_error_system_call
);
4748 /* For archives without .o files there is no symbol table. */
4749 if (strncmp (nextname
, "/ ", 16))
4751 bfd_has_map (abfd
) = false;
4755 /* Read in and sanity check the archive header. */
4756 if (bfd_read ((PTR
) &ar_header
, 1, sizeof (struct ar_hdr
), abfd
)
4757 != sizeof (struct ar_hdr
))
4759 bfd_set_error (bfd_error_system_call
);
4763 if (strncmp (ar_header
.ar_fmag
, ARFMAG
, 2))
4765 bfd_set_error (bfd_error_malformed_archive
);
4769 /* How big is the archive symbol table entry? */
4771 parsed_size
= strtol (ar_header
.ar_size
, NULL
, 10);
4774 bfd_set_error (bfd_error_malformed_archive
);
4778 /* Save off the file offset of the first real user data. */
4779 ardata
->first_file_filepos
= bfd_tell (abfd
) + parsed_size
;
4781 /* Read in the library symbol table. We'll make heavy use of this
4782 in just a minute. */
4783 if (bfd_read ((PTR
) & lst_header
, 1, sizeof (struct lst_header
), abfd
)
4784 != sizeof (struct lst_header
))
4786 bfd_set_error (bfd_error_system_call
);
4791 if (lst_header
.a_magic
!= LIBMAGIC
)
4793 bfd_set_error (bfd_error_malformed_archive
);
4797 /* Count the number of symbols in the library symbol table. */
4798 if (som_bfd_count_ar_symbols (abfd
, &lst_header
, &ardata
->symdef_count
)
4802 /* Get back to the start of the library symbol table. */
4803 if (bfd_seek (abfd
, ardata
->first_file_filepos
- parsed_size
4804 + sizeof (struct lst_header
), SEEK_SET
) < 0)
4806 bfd_set_error (bfd_error_system_call
);
4810 /* Initializae the cache and allocate space for the library symbols. */
4812 ardata
->symdefs
= (carsym
*) bfd_alloc (abfd
,
4813 (ardata
->symdef_count
4814 * sizeof (carsym
)));
4815 if (!ardata
->symdefs
)
4817 bfd_set_error (bfd_error_no_memory
);
4821 /* Now fill in the canonical archive symbols. */
4822 if (som_bfd_fill_in_ar_symbols (abfd
, &lst_header
, &ardata
->symdefs
)
4826 /* Seek back to the "first" file in the archive. Note the "first"
4827 file may be the extended name table. */
4828 if (bfd_seek (abfd
, ardata
->first_file_filepos
, SEEK_SET
) < 0)
4830 bfd_set_error (bfd_error_system_call
);
4834 /* Notify the generic archive code that we have a symbol map. */
4835 bfd_has_map (abfd
) = true;
4839 /* Begin preparing to write a SOM library symbol table.
4841 As part of the prep work we need to determine the number of symbols
4842 and the size of the associated string section. */
4845 som_bfd_prep_for_ar_write (abfd
, num_syms
, stringsize
)
4847 unsigned int *num_syms
, *stringsize
;
4849 bfd
*curr_bfd
= abfd
->archive_head
;
4851 /* Some initialization. */
4855 /* Iterate over each BFD within this archive. */
4856 while (curr_bfd
!= NULL
)
4858 unsigned int curr_count
, i
;
4859 som_symbol_type
*sym
;
4861 /* Make sure the symbol table has been read, then snag a pointer
4862 to it. It's a little slimey to grab the symbols via obj_som_symtab,
4863 but doing so avoids allocating lots of extra memory. */
4864 if (som_slurp_symbol_table (curr_bfd
) == false)
4867 sym
= obj_som_symtab (curr_bfd
);
4868 curr_count
= bfd_get_symcount (curr_bfd
);
4870 /* Examine each symbol to determine if it belongs in the
4871 library symbol table. */
4872 for (i
= 0; i
< curr_count
; i
++, sym
++)
4874 struct som_misc_symbol_info info
;
4876 /* Derive SOM information from the BFD symbol. */
4877 som_bfd_derive_misc_symbol_info (curr_bfd
, &sym
->symbol
, &info
);
4879 /* Should we include this symbol? */
4880 if (info
.symbol_type
== ST_NULL
4881 || info
.symbol_type
== ST_SYM_EXT
4882 || info
.symbol_type
== ST_ARG_EXT
)
4885 /* Only global symbols and unsatisfied commons. */
4886 if (info
.symbol_scope
!= SS_UNIVERSAL
4887 && info
.symbol_type
!= ST_STORAGE
)
4890 /* Do no include undefined symbols. */
4891 if (sym
->symbol
.section
== &bfd_und_section
)
4894 /* Bump the various counters, being careful to honor
4895 alignment considerations in the string table. */
4897 *stringsize
= *stringsize
+ strlen (sym
->symbol
.name
) + 5;
4898 while (*stringsize
% 4)
4902 curr_bfd
= curr_bfd
->next
;
4907 /* Hash a symbol name based on the hashing algorithm presented in the
4910 som_bfd_ar_symbol_hash (symbol
)
4913 unsigned int len
= strlen (symbol
->name
);
4915 /* Names with length 1 are special. */
4917 return 0x1000100 | (symbol
->name
[0] << 16) | symbol
->name
[0];
4919 return ((len
& 0x7f) << 24) | (symbol
->name
[1] << 16)
4920 | (symbol
->name
[len
-2] << 8) | symbol
->name
[len
-1];
4927 CONST
char *filename
= strrchr (file
, '/');
4929 if (filename
!= NULL
)
4936 /* Do the bulk of the work required to write the SOM library
4940 som_bfd_ar_write_symbol_stuff (abfd
, nsyms
, string_size
, lst
)
4942 unsigned int nsyms
, string_size
;
4943 struct lst_header lst
;
4945 file_ptr lst_filepos
;
4946 char *strings
= NULL
, *p
;
4947 struct lst_symbol_record
*lst_syms
= NULL
, *curr_lst_sym
;
4949 unsigned int *hash_table
= NULL
;
4950 struct som_entry
*som_dict
= NULL
;
4951 struct lst_symbol_record
**last_hash_entry
= NULL
;
4952 unsigned int curr_som_offset
, som_index
, extended_name_length
= 0;
4953 unsigned int maxname
= abfd
->xvec
->ar_max_namelen
;
4956 (unsigned int *) malloc (lst
.hash_size
* sizeof (unsigned int));
4957 if (hash_table
== NULL
&& lst
.hash_size
!= 0)
4959 bfd_set_error (bfd_error_no_memory
);
4963 (struct som_entry
*) malloc (lst
.module_count
4964 * sizeof (struct som_entry
));
4965 if (som_dict
== NULL
&& lst
.module_count
!= 0)
4967 bfd_set_error (bfd_error_no_memory
);
4972 ((struct lst_symbol_record
**)
4973 malloc (lst
.hash_size
* sizeof (struct lst_symbol_record
*)));
4974 if (last_hash_entry
== NULL
&& lst
.hash_size
!= 0)
4976 bfd_set_error (bfd_error_no_memory
);
4980 /* Lots of fields are file positions relative to the start
4981 of the lst record. So save its location. */
4982 lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
4984 /* Some initialization. */
4985 memset (hash_table
, 0, 4 * lst
.hash_size
);
4986 memset (som_dict
, 0, lst
.module_count
* sizeof (struct som_entry
));
4987 memset (last_hash_entry
, 0,
4988 lst
.hash_size
* sizeof (struct lst_symbol_record
*));
4990 /* Symbols have som_index fields, so we have to keep track of the
4991 index of each SOM in the archive.
4993 The SOM dictionary has (among other things) the absolute file
4994 position for the SOM which a particular dictionary entry
4995 describes. We have to compute that information as we iterate
4996 through the SOMs/symbols. */
4998 curr_som_offset
= 8 + 2 * sizeof (struct ar_hdr
) + lst
.file_end
;
5000 /* Yow! We have to know the size of the extended name table
5002 for (curr_bfd
= abfd
->archive_head
;
5004 curr_bfd
= curr_bfd
->next
)
5006 CONST
char *normal
= normalize (curr_bfd
->filename
);
5007 unsigned int thislen
;
5011 bfd_set_error (bfd_error_no_memory
);
5014 thislen
= strlen (normal
);
5015 if (thislen
> maxname
)
5016 extended_name_length
+= thislen
+ 1;
5019 /* Make room for the archive header and the contents of the
5020 extended string table. */
5021 if (extended_name_length
)
5022 curr_som_offset
+= extended_name_length
+ sizeof (struct ar_hdr
);
5024 /* Make sure we're properly aligned. */
5025 curr_som_offset
= (curr_som_offset
+ 0x1) & ~0x1;
5027 /* FIXME should be done with buffers just like everything else... */
5028 lst_syms
= malloc (nsyms
* sizeof (struct lst_symbol_record
));
5029 if (lst_syms
== NULL
&& nsyms
!= 0)
5031 bfd_set_error (bfd_error_no_memory
);
5034 strings
= malloc (string_size
);
5035 if (strings
== NULL
&& string_size
!= 0)
5037 bfd_set_error (bfd_error_no_memory
);
5042 curr_lst_sym
= lst_syms
;
5044 curr_bfd
= abfd
->archive_head
;
5045 while (curr_bfd
!= NULL
)
5047 unsigned int curr_count
, i
;
5048 som_symbol_type
*sym
;
5050 /* Make sure the symbol table has been read, then snag a pointer
5051 to it. It's a little slimey to grab the symbols via obj_som_symtab,
5052 but doing so avoids allocating lots of extra memory. */
5053 if (som_slurp_symbol_table (curr_bfd
) == false)
5056 sym
= obj_som_symtab (curr_bfd
);
5057 curr_count
= bfd_get_symcount (curr_bfd
);
5059 for (i
= 0; i
< curr_count
; i
++, sym
++)
5061 struct som_misc_symbol_info info
;
5063 /* Derive SOM information from the BFD symbol. */
5064 som_bfd_derive_misc_symbol_info (curr_bfd
, &sym
->symbol
, &info
);
5066 /* Should we include this symbol? */
5067 if (info
.symbol_type
== ST_NULL
5068 || info
.symbol_type
== ST_SYM_EXT
5069 || info
.symbol_type
== ST_ARG_EXT
)
5072 /* Only global symbols and unsatisfied commons. */
5073 if (info
.symbol_scope
!= SS_UNIVERSAL
5074 && info
.symbol_type
!= ST_STORAGE
)
5077 /* Do no include undefined symbols. */
5078 if (sym
->symbol
.section
== &bfd_und_section
)
5081 /* If this is the first symbol from this SOM, then update
5082 the SOM dictionary too. */
5083 if (som_dict
[som_index
].location
== 0)
5085 som_dict
[som_index
].location
= curr_som_offset
;
5086 som_dict
[som_index
].length
= arelt_size (curr_bfd
);
5089 /* Fill in the lst symbol record. */
5090 curr_lst_sym
->hidden
= 0;
5091 curr_lst_sym
->secondary_def
= 0;
5092 curr_lst_sym
->symbol_type
= info
.symbol_type
;
5093 curr_lst_sym
->symbol_scope
= info
.symbol_scope
;
5094 curr_lst_sym
->check_level
= 0;
5095 curr_lst_sym
->must_qualify
= 0;
5096 curr_lst_sym
->initially_frozen
= 0;
5097 curr_lst_sym
->memory_resident
= 0;
5098 curr_lst_sym
->is_common
= (sym
->symbol
.section
== &bfd_com_section
);
5099 curr_lst_sym
->dup_common
= 0;
5100 curr_lst_sym
->xleast
= 0;
5101 curr_lst_sym
->arg_reloc
= info
.arg_reloc
;
5102 curr_lst_sym
->name
.n_strx
= p
- strings
+ 4;
5103 curr_lst_sym
->qualifier_name
.n_strx
= 0;
5104 curr_lst_sym
->symbol_info
= info
.symbol_info
;
5105 curr_lst_sym
->symbol_value
= info
.symbol_value
;
5106 curr_lst_sym
->symbol_descriptor
= 0;
5107 curr_lst_sym
->reserved
= 0;
5108 curr_lst_sym
->som_index
= som_index
;
5109 curr_lst_sym
->symbol_key
= som_bfd_ar_symbol_hash (&sym
->symbol
);
5110 curr_lst_sym
->next_entry
= 0;
5112 /* Insert into the hash table. */
5113 if (hash_table
[curr_lst_sym
->symbol_key
% lst
.hash_size
])
5115 struct lst_symbol_record
*tmp
;
5117 /* There is already something at the head of this hash chain,
5118 so tack this symbol onto the end of the chain. */
5119 tmp
= last_hash_entry
[curr_lst_sym
->symbol_key
% lst
.hash_size
];
5121 = (curr_lst_sym
- lst_syms
) * sizeof (struct lst_symbol_record
)
5123 + lst
.module_count
* sizeof (struct som_entry
)
5124 + sizeof (struct lst_header
);
5128 /* First entry in this hash chain. */
5129 hash_table
[curr_lst_sym
->symbol_key
% lst
.hash_size
]
5130 = (curr_lst_sym
- lst_syms
) * sizeof (struct lst_symbol_record
)
5132 + lst
.module_count
* sizeof (struct som_entry
)
5133 + sizeof (struct lst_header
);
5136 /* Keep track of the last symbol we added to this chain so we can
5137 easily update its next_entry pointer. */
5138 last_hash_entry
[curr_lst_sym
->symbol_key
% lst
.hash_size
]
5142 /* Update the string table. */
5143 bfd_put_32 (abfd
, strlen (sym
->symbol
.name
), p
);
5145 strcpy (p
, sym
->symbol
.name
);
5146 p
+= strlen (sym
->symbol
.name
) + 1;
5149 bfd_put_8 (abfd
, 0, p
);
5153 /* Head to the next symbol. */
5157 /* Keep track of where each SOM will finally reside; then look
5159 curr_som_offset
+= arelt_size (curr_bfd
) + sizeof (struct ar_hdr
);
5160 curr_bfd
= curr_bfd
->next
;
5164 /* Now scribble out the hash table. */
5165 if (bfd_write ((PTR
) hash_table
, lst
.hash_size
, 4, abfd
)
5166 != lst
.hash_size
* 4)
5168 bfd_set_error (bfd_error_system_call
);
5172 /* Then the SOM dictionary. */
5173 if (bfd_write ((PTR
) som_dict
, lst
.module_count
,
5174 sizeof (struct som_entry
), abfd
)
5175 != lst
.module_count
* sizeof (struct som_entry
))
5177 bfd_set_error (bfd_error_system_call
);
5181 /* The library symbols. */
5182 if (bfd_write ((PTR
) lst_syms
, nsyms
, sizeof (struct lst_symbol_record
), abfd
)
5183 != nsyms
* sizeof (struct lst_symbol_record
))
5185 bfd_set_error (bfd_error_system_call
);
5189 /* And finally the strings. */
5190 if (bfd_write ((PTR
) strings
, string_size
, 1, abfd
) != string_size
)
5192 bfd_set_error (bfd_error_system_call
);
5196 if (hash_table
!= NULL
)
5198 if (som_dict
!= NULL
)
5200 if (last_hash_entry
!= NULL
)
5201 free (last_hash_entry
);
5202 if (lst_syms
!= NULL
)
5204 if (strings
!= NULL
)
5209 if (hash_table
!= NULL
)
5211 if (som_dict
!= NULL
)
5213 if (last_hash_entry
!= NULL
)
5214 free (last_hash_entry
);
5215 if (lst_syms
!= NULL
)
5217 if (strings
!= NULL
)
5223 /* Write out the LST for the archive.
5225 You'll never believe this is really how armaps are handled in SOM... */
5228 som_write_armap (abfd
)
5232 struct stat statbuf
;
5233 unsigned int i
, lst_size
, nsyms
, stringsize
;
5235 struct lst_header lst
;
5238 /* We'll use this for the archive's date and mode later. */
5239 if (stat (abfd
->filename
, &statbuf
) != 0)
5241 bfd_set_error (bfd_error_system_call
);
5245 bfd_ardata (abfd
)->armap_timestamp
= statbuf
.st_mtime
+ 60;
5247 /* Account for the lst header first. */
5248 lst_size
= sizeof (struct lst_header
);
5250 /* Start building the LST header. */
5251 lst
.system_id
= HP9000S800_ID
;
5252 lst
.a_magic
= LIBMAGIC
;
5253 lst
.version_id
= VERSION_ID
;
5254 lst
.file_time
.secs
= 0;
5255 lst
.file_time
.nanosecs
= 0;
5257 lst
.hash_loc
= lst_size
;
5258 lst
.hash_size
= SOM_LST_HASH_SIZE
;
5260 /* Hash table is a SOM_LST_HASH_SIZE 32bit offsets. */
5261 lst_size
+= 4 * SOM_LST_HASH_SIZE
;
5263 /* We need to count the number of SOMs in this archive. */
5264 curr_bfd
= abfd
->archive_head
;
5265 lst
.module_count
= 0;
5266 while (curr_bfd
!= NULL
)
5269 curr_bfd
= curr_bfd
->next
;
5271 lst
.module_limit
= lst
.module_count
;
5272 lst
.dir_loc
= lst_size
;
5273 lst_size
+= sizeof (struct som_entry
) * lst
.module_count
;
5275 /* We don't support import/export tables, auxiliary headers,
5276 or free lists yet. Make the linker work a little harder
5277 to make our life easier. */
5280 lst
.export_count
= 0;
5285 /* Count how many symbols we will have on the hash chains and the
5286 size of the associated string table. */
5287 if (som_bfd_prep_for_ar_write (abfd
, &nsyms
, &stringsize
) == false)
5290 lst_size
+= sizeof (struct lst_symbol_record
) * nsyms
;
5292 /* For the string table. One day we might actually use this info
5293 to avoid small seeks/reads when reading archives. */
5294 lst
.string_loc
= lst_size
;
5295 lst
.string_size
= stringsize
;
5296 lst_size
+= stringsize
;
5298 /* SOM ABI says this must be zero. */
5300 lst
.file_end
= lst_size
;
5302 /* Compute the checksum. Must happen after the entire lst header
5306 for (i
= 0; i
< sizeof (struct lst_header
)/sizeof (int) - 1; i
++)
5307 lst
.checksum
^= *p
++;
5309 sprintf (hdr
.ar_name
, "/ ");
5310 sprintf (hdr
.ar_date
, "%ld", bfd_ardata (abfd
)->armap_timestamp
);
5311 sprintf (hdr
.ar_uid
, "%d", getuid ());
5312 sprintf (hdr
.ar_gid
, "%d", getgid ());
5313 sprintf (hdr
.ar_mode
, "%-8o", (unsigned int) statbuf
.st_mode
);
5314 sprintf (hdr
.ar_size
, "%-10d", (int) lst_size
);
5315 hdr
.ar_fmag
[0] = '`';
5316 hdr
.ar_fmag
[1] = '\012';
5318 /* Turn any nulls into spaces. */
5319 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
5320 if (((char *) (&hdr
))[i
] == '\0')
5321 (((char *) (&hdr
))[i
]) = ' ';
5323 /* Scribble out the ar header. */
5324 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
5325 != sizeof (struct ar_hdr
))
5327 bfd_set_error (bfd_error_system_call
);
5331 /* Now scribble out the lst header. */
5332 if (bfd_write ((PTR
) &lst
, 1, sizeof (struct lst_header
), abfd
)
5333 != sizeof (struct lst_header
))
5335 bfd_set_error (bfd_error_system_call
);
5339 /* Build and write the armap. */
5340 if (som_bfd_ar_write_symbol_stuff (abfd
, nsyms
, stringsize
, lst
) == false)
5347 /* End of miscellaneous support functions. */
5349 #define som_bfd_debug_info_start bfd_void
5350 #define som_bfd_debug_info_end bfd_void
5351 #define som_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
5353 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
5354 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
5355 #define som_truncate_arname bfd_bsd_truncate_arname
5356 #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
5358 #define som_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
5359 #define som_close_and_cleanup bfd_generic_close_and_cleanup
5360 #define som_get_section_contents bfd_generic_get_section_contents
5362 #define som_bfd_get_relocated_section_contents \
5363 bfd_generic_get_relocated_section_contents
5364 #define som_bfd_relax_section bfd_generic_relax_section
5365 #define som_bfd_make_debug_symbol \
5366 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
5367 #define som_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
5368 #define som_bfd_link_add_symbols _bfd_generic_link_add_symbols
5369 #define som_bfd_final_link _bfd_generic_final_link
5371 /* Core file support is in the hpux-core backend. */
5372 #define som_core_file_failing_command _bfd_dummy_core_file_failing_command
5373 #define som_core_file_failing_signal _bfd_dummy_core_file_failing_signal
5374 #define som_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
5376 #define som_bfd_copy_private_bfd_data \
5377 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
5379 bfd_target som_vec
=
5382 bfd_target_som_flavour
,
5383 true, /* target byte order */
5384 true, /* target headers byte order */
5385 (HAS_RELOC
| EXEC_P
| /* object flags */
5386 HAS_LINENO
| HAS_DEBUG
|
5387 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
5388 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
5389 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
5391 /* leading_symbol_char: is the first char of a user symbol
5392 predictable, and if so what is it */
5394 '/', /* ar_pad_char */
5395 14, /* ar_max_namelen */
5396 3, /* minimum alignment */
5397 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
5398 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
5399 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
5400 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
5401 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
5402 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
5404 som_object_p
, /* bfd_check_format */
5405 bfd_generic_archive_p
,
5411 _bfd_generic_mkarchive
,
5416 som_write_object_contents
,
5417 _bfd_write_archive_contents
,
5425 #endif /* HOST_HPPAHPUX || HOST_HPPABSD || HOST_HPPAOSF */