1 /* bfd back-end for HP PA-RISC SOM objects.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
6 Contributed by the Center for Software Science at the
9 This file is part of BFD, the Binary File Descriptor library.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "alloca-conf.h"
30 #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF) || defined(HOST_HPPAMPEIX)
34 #include "safe-ctype.h"
36 #include <sys/param.h>
38 #include <machine/reg.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 CPU_PA_RISC2_0
52 #define CPU_PA_RISC2_0 0x214
53 #endif /* CPU_PA_RISC2_0 */
55 #ifndef _PA_RISC1_0_ID
56 #define _PA_RISC1_0_ID CPU_PA_RISC1_0
57 #endif /* _PA_RISC1_0_ID */
59 #ifndef _PA_RISC1_1_ID
60 #define _PA_RISC1_1_ID CPU_PA_RISC1_1
61 #endif /* _PA_RISC1_1_ID */
63 #ifndef _PA_RISC2_0_ID
64 #define _PA_RISC2_0_ID CPU_PA_RISC2_0
65 #endif /* _PA_RISC2_0_ID */
67 #ifndef _PA_RISC_MAXID
68 #define _PA_RISC_MAXID 0x2FF
69 #endif /* _PA_RISC_MAXID */
72 #define _PA_RISC_ID(__m_num) \
73 (((__m_num) == _PA_RISC1_0_ID) || \
74 ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
75 #endif /* _PA_RISC_ID */
77 /* HIUX in it's infinite stupidity changed the names for several "well
78 known" constants. Work around such braindamage. Try the HPUX version
79 first, then the HIUX version, and finally provide a default. */
81 #define EXEC_AUX_ID HPUX_AUX_ID
84 #if !defined (EXEC_AUX_ID) && defined (HIUX_AUX_ID)
85 #define EXEC_AUX_ID HIUX_AUX_ID
92 /* Size (in chars) of the temporary buffers used during fixup and string
95 #define SOM_TMP_BUFSIZE 8192
97 /* Size of the hash table in archives. */
98 #define SOM_LST_HASH_SIZE 31
100 /* Max number of SOMs to be found in an archive. */
101 #define SOM_LST_MODULE_LIMIT 1024
103 /* Generic alignment macro. */
104 #define SOM_ALIGN(val, alignment) \
105 (((val) + (alignment) - 1) &~ ((unsigned long) (alignment) - 1))
107 /* SOM allows any one of the four previous relocations to be reused
108 with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
109 relocations are always a single byte, using a R_PREV_FIXUP instead
110 of some multi-byte relocation makes object files smaller.
112 Note one side effect of using a R_PREV_FIXUP is the relocation that
113 is being repeated moves to the front of the queue. */
115 unsigned char *reloc
;
119 /* This fully describes the symbol types which may be attached to
120 an EXPORT or IMPORT directive. Only SOM uses this formation
121 (ELF has no need for it). */
124 SYMBOL_TYPE_ABSOLUTE
,
128 SYMBOL_TYPE_MILLICODE
,
130 SYMBOL_TYPE_PRI_PROG
,
131 SYMBOL_TYPE_SEC_PROG
,
134 struct section_to_type
{
139 /* Assorted symbol information that needs to be derived from the BFD symbol
140 and/or the BFD backend private symbol data. */
141 struct som_misc_symbol_info
{
142 unsigned int symbol_type
;
143 unsigned int symbol_scope
;
144 unsigned int arg_reloc
;
145 unsigned int symbol_info
;
146 unsigned int symbol_value
;
147 unsigned int priv_level
;
148 unsigned int secondary_def
;
151 /* Forward declarations. */
153 static bfd_boolean som_mkobject
155 static const bfd_target
* som_object_setup
156 PARAMS ((bfd
*, struct header
*, struct som_exec_auxhdr
*, unsigned long));
157 static bfd_boolean setup_sections
158 PARAMS ((bfd
*, struct header
*, unsigned long));
159 static const bfd_target
* som_object_p
161 static bfd_boolean som_write_object_contents
163 static bfd_boolean som_slurp_string_table
165 static unsigned int som_slurp_symbol_table
167 static long som_get_symtab_upper_bound
169 static long som_canonicalize_reloc
170 PARAMS ((bfd
*, sec_ptr
, arelent
**, asymbol
**));
171 static long som_get_reloc_upper_bound
172 PARAMS ((bfd
*, sec_ptr
));
173 static unsigned int som_set_reloc_info
174 PARAMS ((unsigned char *, unsigned int, arelent
*, asection
*,
175 asymbol
**, bfd_boolean
));
176 static bfd_boolean som_slurp_reloc_table
177 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_boolean
));
178 static long som_canonicalize_symtab
179 PARAMS ((bfd
*, asymbol
**));
180 static asymbol
* som_make_empty_symbol
182 static void som_print_symbol
183 PARAMS ((bfd
*, PTR
, asymbol
*, bfd_print_symbol_type
));
184 static bfd_boolean som_new_section_hook
185 PARAMS ((bfd
*, asection
*));
186 static bfd_boolean som_bfd_copy_private_symbol_data
187 PARAMS ((bfd
*, asymbol
*, bfd
*, asymbol
*));
188 static bfd_boolean som_bfd_copy_private_section_data
189 PARAMS ((bfd
*, asection
*, bfd
*, asection
*));
190 static bfd_boolean som_bfd_copy_private_bfd_data
191 PARAMS ((bfd
*, bfd
*));
192 #define som_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
193 #define som_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
194 static bfd_boolean som_bfd_is_local_label_name
195 PARAMS ((bfd
*, const char *));
196 static bfd_boolean som_set_section_contents
197 PARAMS ((bfd
*, sec_ptr
, const PTR
, file_ptr
, bfd_size_type
));
198 static bfd_boolean som_get_section_contents
199 PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
200 static bfd_boolean som_set_arch_mach
201 PARAMS ((bfd
*, enum bfd_architecture
, unsigned long));
202 static bfd_boolean som_find_nearest_line
203 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
204 const char **, unsigned int *));
205 static void som_get_symbol_info
206 PARAMS ((bfd
*, asymbol
*, symbol_info
*));
207 static asection
* bfd_section_from_som_symbol
208 PARAMS ((bfd
*, struct symbol_dictionary_record
*));
210 PARAMS ((unsigned int));
211 static bfd_reloc_status_type hppa_som_reloc
212 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
213 static void som_initialize_reloc_queue
214 PARAMS ((struct reloc_queue
*));
215 static void som_reloc_queue_insert
216 PARAMS ((unsigned char *, unsigned int, struct reloc_queue
*));
217 static void som_reloc_queue_fix
218 PARAMS ((struct reloc_queue
*, unsigned int));
219 static int som_reloc_queue_find
220 PARAMS ((unsigned char *, unsigned int, struct reloc_queue
*));
221 static unsigned char * try_prev_fixup
222 PARAMS ((bfd
*, int *, unsigned char *, unsigned int, struct reloc_queue
*));
223 static unsigned char * som_reloc_skip
224 PARAMS ((bfd
*, unsigned int, unsigned char *, unsigned int *,
225 struct reloc_queue
*));
226 static unsigned char * som_reloc_addend
227 PARAMS ((bfd
*, bfd_vma
, unsigned char *, unsigned int *,
228 struct reloc_queue
*));
229 static unsigned char * som_reloc_call
230 PARAMS ((bfd
*, unsigned char *, unsigned int *, arelent
*, int,
231 struct reloc_queue
*));
232 static unsigned long som_count_spaces
234 static unsigned long som_count_subspaces
236 static int compare_syms
237 PARAMS ((const void *, const void *));
238 static int compare_subspaces
239 PARAMS ((const void *, const void *));
240 static unsigned long som_compute_checksum
242 static bfd_boolean som_prep_headers
244 static int som_sizeof_headers
245 PARAMS ((bfd
*, bfd_boolean
));
246 static bfd_boolean som_finish_writing
248 static bfd_boolean som_build_and_write_symbol_table
250 static void som_prep_for_fixups
251 PARAMS ((bfd
*, asymbol
**, unsigned long));
252 static bfd_boolean som_write_fixups
253 PARAMS ((bfd
*, unsigned long, unsigned int *));
254 static bfd_boolean som_write_space_strings
255 PARAMS ((bfd
*, unsigned long, unsigned int *));
256 static bfd_boolean som_write_symbol_strings
257 PARAMS ((bfd
*, unsigned long, asymbol
**, unsigned int, unsigned *,
259 static bfd_boolean som_begin_writing
261 static reloc_howto_type
* som_bfd_reloc_type_lookup
262 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
263 static char som_section_type
264 PARAMS ((const char *));
265 static int som_decode_symclass
266 PARAMS ((asymbol
*));
267 static bfd_boolean som_bfd_count_ar_symbols
268 PARAMS ((bfd
*, struct lst_header
*, symindex
*));
269 static bfd_boolean som_bfd_fill_in_ar_symbols
270 PARAMS ((bfd
*, struct lst_header
*, carsym
**));
271 static bfd_boolean som_slurp_armap
273 static bfd_boolean som_write_armap
274 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
275 static void som_bfd_derive_misc_symbol_info
276 PARAMS ((bfd
*, asymbol
*, struct som_misc_symbol_info
*));
277 static bfd_boolean som_bfd_prep_for_ar_write
278 PARAMS ((bfd
*, unsigned int *, unsigned int *));
279 static unsigned int som_bfd_ar_symbol_hash
280 PARAMS ((asymbol
*));
281 static bfd_boolean som_bfd_ar_write_symbol_stuff
282 PARAMS ((bfd
*, unsigned int, unsigned int, struct lst_header
,
284 static bfd_boolean som_is_space
285 PARAMS ((asection
*));
286 static bfd_boolean som_is_subspace
287 PARAMS ((asection
*));
288 static bfd_boolean som_is_container
289 PARAMS ((asection
*, asection
*));
290 static bfd_boolean som_bfd_free_cached_info
292 static bfd_boolean som_bfd_link_split_section
293 PARAMS ((bfd
*, asection
*));
295 /* Map SOM section names to POSIX/BSD single-character symbol types.
297 This table includes all the standard subspaces as defined in the
298 current "PRO ABI for PA-RISC Systems", $UNWIND$ which for
299 some reason was left out, and sections specific to embedded stabs. */
301 static const struct section_to_type stt
[] = {
303 {"$SHLIB_INFO$", 't'},
304 {"$MILLICODE$", 't'},
307 {"$UNWIND_START$", 't'},
311 {"$SHLIB_DATA$", 'd'},
313 {"$SHORTDATA$", 'g'},
318 {"$GDB_STRINGS$", 'N'},
319 {"$GDB_SYMBOLS$", 'N'},
323 /* About the relocation formatting table...
325 There are 256 entries in the table, one for each possible
326 relocation opcode available in SOM. We index the table by
327 the relocation opcode. The names and operations are those
328 defined by a.out_800 (4).
330 Right now this table is only used to count and perform minimal
331 processing on relocation streams so that they can be internalized
332 into BFD and symbolically printed by utilities. To make actual use
333 of them would be much more difficult, BFD's concept of relocations
334 is far too simple to handle SOM relocations. The basic assumption
335 that a relocation can be completely processed independent of other
336 relocations before an object file is written is invalid for SOM.
338 The SOM relocations are meant to be processed as a stream, they
339 specify copying of data from the input section to the output section
340 while possibly modifying the data in some manner. They also can
341 specify that a variable number of zeros or uninitialized data be
342 inserted on in the output segment at the current offset. Some
343 relocations specify that some previous relocation be re-applied at
344 the current location in the input/output sections. And finally a number
345 of relocations have effects on other sections (R_ENTRY, R_EXIT,
346 R_UNWIND_AUX and a variety of others). There isn't even enough room
347 in the BFD relocation data structure to store enough information to
348 perform all the relocations.
350 Each entry in the table has three fields.
352 The first entry is an index into this "class" of relocations. This
353 index can then be used as a variable within the relocation itself.
355 The second field is a format string which actually controls processing
356 of the relocation. It uses a simple postfix machine to do calculations
357 based on variables/constants found in the string and the relocation
360 The third field specifys whether or not this relocation may use
361 a constant (V) from the previous R_DATA_OVERRIDE rather than a constant
362 stored in the instruction.
366 L = input space byte count
367 D = index into class of relocations
368 M = output space byte count
369 N = statement number (unused?)
371 R = parameter relocation bits
373 T = first 32 bits of stack unwind information
374 U = second 32 bits of stack unwind information
375 V = a literal constant (usually used in the next relocation)
376 P = a previous relocation
378 Lower case letters (starting with 'b') refer to following
379 bytes in the relocation stream. 'b' is the next 1 byte,
380 c is the next 2 bytes, d is the next 3 bytes, etc...
381 This is the variable part of the relocation entries that
382 makes our life a living hell.
384 numerical constants are also used in the format string. Note
385 the constants are represented in decimal.
387 '+', "*" and "=" represents the obvious postfix operators.
388 '<' represents a left shift.
392 Parameter Relocation Bits:
396 Previous Relocations: The index field represents which in the queue
397 of 4 previous fixups should be re-applied.
399 Literal Constants: These are generally used to represent addend
400 parts of relocations when these constants are not stored in the
401 fields of the instructions themselves. For example the instruction
402 addil foo-$global$-0x1234 would use an override for "0x1234" rather
403 than storing it into the addil itself. */
405 struct fixup_format
{
410 static const struct fixup_format som_fixup_formats
[256] = {
411 /* R_NO_RELOCATION */
412 { 0, "LD1+4*=" }, /* 0x00 */
413 { 1, "LD1+4*=" }, /* 0x01 */
414 { 2, "LD1+4*=" }, /* 0x02 */
415 { 3, "LD1+4*=" }, /* 0x03 */
416 { 4, "LD1+4*=" }, /* 0x04 */
417 { 5, "LD1+4*=" }, /* 0x05 */
418 { 6, "LD1+4*=" }, /* 0x06 */
419 { 7, "LD1+4*=" }, /* 0x07 */
420 { 8, "LD1+4*=" }, /* 0x08 */
421 { 9, "LD1+4*=" }, /* 0x09 */
422 { 10, "LD1+4*=" }, /* 0x0a */
423 { 11, "LD1+4*=" }, /* 0x0b */
424 { 12, "LD1+4*=" }, /* 0x0c */
425 { 13, "LD1+4*=" }, /* 0x0d */
426 { 14, "LD1+4*=" }, /* 0x0e */
427 { 15, "LD1+4*=" }, /* 0x0f */
428 { 16, "LD1+4*=" }, /* 0x10 */
429 { 17, "LD1+4*=" }, /* 0x11 */
430 { 18, "LD1+4*=" }, /* 0x12 */
431 { 19, "LD1+4*=" }, /* 0x13 */
432 { 20, "LD1+4*=" }, /* 0x14 */
433 { 21, "LD1+4*=" }, /* 0x15 */
434 { 22, "LD1+4*=" }, /* 0x16 */
435 { 23, "LD1+4*=" }, /* 0x17 */
436 { 0, "LD8<b+1+4*=" }, /* 0x18 */
437 { 1, "LD8<b+1+4*=" }, /* 0x19 */
438 { 2, "LD8<b+1+4*=" }, /* 0x1a */
439 { 3, "LD8<b+1+4*=" }, /* 0x1b */
440 { 0, "LD16<c+1+4*=" }, /* 0x1c */
441 { 1, "LD16<c+1+4*=" }, /* 0x1d */
442 { 2, "LD16<c+1+4*=" }, /* 0x1e */
443 { 0, "Ld1+=" }, /* 0x1f */
445 { 0, "Lb1+4*=" }, /* 0x20 */
446 { 1, "Ld1+=" }, /* 0x21 */
448 { 0, "Lb1+4*=" }, /* 0x22 */
449 { 1, "Ld1+=" }, /* 0x23 */
451 { 0, "L4=" }, /* 0x24 */
452 /* R_DATA_ONE_SYMBOL */
453 { 0, "L4=Sb=" }, /* 0x25 */
454 { 1, "L4=Sd=" }, /* 0x26 */
456 { 0, "L4=Sb=" }, /* 0x27 */
457 { 1, "L4=Sd=" }, /* 0x28 */
459 { 0, "L4=" }, /* 0x29 */
460 /* R_REPEATED_INIT */
461 { 0, "L4=Mb1+4*=" }, /* 0x2a */
462 { 1, "Lb4*=Mb1+L*=" }, /* 0x2b */
463 { 2, "Lb4*=Md1+4*=" }, /* 0x2c */
464 { 3, "Ld1+=Me1+=" }, /* 0x2d */
465 { 0, "" }, /* 0x2e */
466 { 0, "" }, /* 0x2f */
468 { 0, "L4=RD=Sb=" }, /* 0x30 */
469 { 1, "L4=RD=Sb=" }, /* 0x31 */
470 { 2, "L4=RD=Sb=" }, /* 0x32 */
471 { 3, "L4=RD=Sb=" }, /* 0x33 */
472 { 4, "L4=RD=Sb=" }, /* 0x34 */
473 { 5, "L4=RD=Sb=" }, /* 0x35 */
474 { 6, "L4=RD=Sb=" }, /* 0x36 */
475 { 7, "L4=RD=Sb=" }, /* 0x37 */
476 { 8, "L4=RD=Sb=" }, /* 0x38 */
477 { 9, "L4=RD=Sb=" }, /* 0x39 */
478 { 0, "L4=RD8<b+=Sb=" }, /* 0x3a */
479 { 1, "L4=RD8<b+=Sb=" }, /* 0x3b */
480 { 0, "L4=RD8<b+=Sd=" }, /* 0x3c */
481 { 1, "L4=RD8<b+=Sd=" }, /* 0x3d */
482 /* R_SHORT_PCREL_MODE */
483 { 0, "" }, /* 0x3e */
484 /* R_LONG_PCREL_MODE */
485 { 0, "" }, /* 0x3f */
487 { 0, "L4=RD=Sb=" }, /* 0x40 */
488 { 1, "L4=RD=Sb=" }, /* 0x41 */
489 { 2, "L4=RD=Sb=" }, /* 0x42 */
490 { 3, "L4=RD=Sb=" }, /* 0x43 */
491 { 4, "L4=RD=Sb=" }, /* 0x44 */
492 { 5, "L4=RD=Sb=" }, /* 0x45 */
493 { 6, "L4=RD=Sb=" }, /* 0x46 */
494 { 7, "L4=RD=Sb=" }, /* 0x47 */
495 { 8, "L4=RD=Sb=" }, /* 0x48 */
496 { 9, "L4=RD=Sb=" }, /* 0x49 */
497 { 0, "L4=RD8<b+=Sb=" }, /* 0x4a */
498 { 1, "L4=RD8<b+=Sb=" }, /* 0x4b */
499 { 0, "L4=RD8<b+=Sd=" }, /* 0x4c */
500 { 1, "L4=RD8<b+=Sd=" }, /* 0x4d */
502 { 0, "" }, /* 0x4e */
503 { 0, "" }, /* 0x4f */
505 { 0, "L4=SD=" }, /* 0x50 */
506 { 1, "L4=SD=" }, /* 0x51 */
507 { 2, "L4=SD=" }, /* 0x52 */
508 { 3, "L4=SD=" }, /* 0x53 */
509 { 4, "L4=SD=" }, /* 0x54 */
510 { 5, "L4=SD=" }, /* 0x55 */
511 { 6, "L4=SD=" }, /* 0x56 */
512 { 7, "L4=SD=" }, /* 0x57 */
513 { 8, "L4=SD=" }, /* 0x58 */
514 { 9, "L4=SD=" }, /* 0x59 */
515 { 10, "L4=SD=" }, /* 0x5a */
516 { 11, "L4=SD=" }, /* 0x5b */
517 { 12, "L4=SD=" }, /* 0x5c */
518 { 13, "L4=SD=" }, /* 0x5d */
519 { 14, "L4=SD=" }, /* 0x5e */
520 { 15, "L4=SD=" }, /* 0x5f */
521 { 16, "L4=SD=" }, /* 0x60 */
522 { 17, "L4=SD=" }, /* 0x61 */
523 { 18, "L4=SD=" }, /* 0x62 */
524 { 19, "L4=SD=" }, /* 0x63 */
525 { 20, "L4=SD=" }, /* 0x64 */
526 { 21, "L4=SD=" }, /* 0x65 */
527 { 22, "L4=SD=" }, /* 0x66 */
528 { 23, "L4=SD=" }, /* 0x67 */
529 { 24, "L4=SD=" }, /* 0x68 */
530 { 25, "L4=SD=" }, /* 0x69 */
531 { 26, "L4=SD=" }, /* 0x6a */
532 { 27, "L4=SD=" }, /* 0x6b */
533 { 28, "L4=SD=" }, /* 0x6c */
534 { 29, "L4=SD=" }, /* 0x6d */
535 { 30, "L4=SD=" }, /* 0x6e */
536 { 31, "L4=SD=" }, /* 0x6f */
537 { 32, "L4=Sb=" }, /* 0x70 */
538 { 33, "L4=Sd=" }, /* 0x71 */
540 { 0, "" }, /* 0x72 */
541 { 0, "" }, /* 0x73 */
542 { 0, "" }, /* 0x74 */
543 { 0, "" }, /* 0x75 */
544 { 0, "" }, /* 0x76 */
545 { 0, "" }, /* 0x77 */
547 { 0, "L4=Sb=" }, /* 0x78 */
548 { 1, "L4=Sd=" }, /* 0x79 */
550 { 0, "" }, /* 0x7a */
551 { 0, "" }, /* 0x7b */
552 { 0, "" }, /* 0x7c */
553 { 0, "" }, /* 0x7d */
554 { 0, "" }, /* 0x7e */
555 { 0, "" }, /* 0x7f */
556 /* R_CODE_ONE_SYMBOL */
557 { 0, "L4=SD=" }, /* 0x80 */
558 { 1, "L4=SD=" }, /* 0x81 */
559 { 2, "L4=SD=" }, /* 0x82 */
560 { 3, "L4=SD=" }, /* 0x83 */
561 { 4, "L4=SD=" }, /* 0x84 */
562 { 5, "L4=SD=" }, /* 0x85 */
563 { 6, "L4=SD=" }, /* 0x86 */
564 { 7, "L4=SD=" }, /* 0x87 */
565 { 8, "L4=SD=" }, /* 0x88 */
566 { 9, "L4=SD=" }, /* 0x89 */
567 { 10, "L4=SD=" }, /* 0x8q */
568 { 11, "L4=SD=" }, /* 0x8b */
569 { 12, "L4=SD=" }, /* 0x8c */
570 { 13, "L4=SD=" }, /* 0x8d */
571 { 14, "L4=SD=" }, /* 0x8e */
572 { 15, "L4=SD=" }, /* 0x8f */
573 { 16, "L4=SD=" }, /* 0x90 */
574 { 17, "L4=SD=" }, /* 0x91 */
575 { 18, "L4=SD=" }, /* 0x92 */
576 { 19, "L4=SD=" }, /* 0x93 */
577 { 20, "L4=SD=" }, /* 0x94 */
578 { 21, "L4=SD=" }, /* 0x95 */
579 { 22, "L4=SD=" }, /* 0x96 */
580 { 23, "L4=SD=" }, /* 0x97 */
581 { 24, "L4=SD=" }, /* 0x98 */
582 { 25, "L4=SD=" }, /* 0x99 */
583 { 26, "L4=SD=" }, /* 0x9a */
584 { 27, "L4=SD=" }, /* 0x9b */
585 { 28, "L4=SD=" }, /* 0x9c */
586 { 29, "L4=SD=" }, /* 0x9d */
587 { 30, "L4=SD=" }, /* 0x9e */
588 { 31, "L4=SD=" }, /* 0x9f */
589 { 32, "L4=Sb=" }, /* 0xa0 */
590 { 33, "L4=Sd=" }, /* 0xa1 */
592 { 0, "" }, /* 0xa2 */
593 { 0, "" }, /* 0xa3 */
594 { 0, "" }, /* 0xa4 */
595 { 0, "" }, /* 0xa5 */
596 { 0, "" }, /* 0xa6 */
597 { 0, "" }, /* 0xa7 */
598 { 0, "" }, /* 0xa8 */
599 { 0, "" }, /* 0xa9 */
600 { 0, "" }, /* 0xaa */
601 { 0, "" }, /* 0xab */
602 { 0, "" }, /* 0xac */
603 { 0, "" }, /* 0xad */
605 { 0, "L4=Sb=" }, /* 0xae */
606 { 1, "L4=Sd=" }, /* 0xaf */
608 { 0, "L4=Sb=" }, /* 0xb0 */
609 { 1, "L4=Sd=" }, /* 0xb1 */
611 { 0, "L4=" }, /* 0xb2 */
613 { 0, "Te=Ue=" }, /* 0xb3 */
614 { 1, "Uf=" }, /* 0xb4 */
616 { 0, "" }, /* 0xb5 */
618 { 0, "" }, /* 0xb6 */
620 { 0, "" }, /* 0xb7 */
622 { 0, "R0=" }, /* 0xb8 */
623 { 1, "Rb4*=" }, /* 0xb9 */
624 { 2, "Rd4*=" }, /* 0xba */
626 { 0, "" }, /* 0xbb */
628 { 0, "" }, /* 0xbc */
630 { 0, "Nb=" }, /* 0xbd */
631 { 1, "Nc=" }, /* 0xbe */
632 { 2, "Nd=" }, /* 0xbf */
634 { 0, "L4=" }, /* 0xc0 */
636 { 0, "L4=" }, /* 0xc1 */
638 { 0, "" }, /* 0xc2 */
640 { 0, "" }, /* 0xc3 */
642 { 0, "" }, /* 0xc4 */
644 { 0, "" }, /* 0xc5 */
646 { 0, "" }, /* 0xc6 */
648 { 0, "" }, /* 0xc7 */
650 { 0, "" }, /* 0xc8 */
651 /* R_DATA_OVERRIDE */
652 { 0, "V0=" }, /* 0xc9 */
653 { 1, "Vb=" }, /* 0xca */
654 { 2, "Vc=" }, /* 0xcb */
655 { 3, "Vd=" }, /* 0xcc */
656 { 4, "Ve=" }, /* 0xcd */
658 { 0, "" }, /* 0xce */
660 { 0,"Sd=Ve=Ee=" }, /* 0xcf */
662 { 0, "Ob=" }, /* 0xd0 */
664 { 0, "Ob=Sd=" }, /* 0xd1 */
666 { 0, "Ob=Ve=" }, /* 0xd2 */
668 { 0, "P" }, /* 0xd3 */
669 { 1, "P" }, /* 0xd4 */
670 { 2, "P" }, /* 0xd5 */
671 { 3, "P" }, /* 0xd6 */
673 { 0, "" }, /* 0xd7 */
675 { 0, "" }, /* 0xd8 */
677 { 0, "" }, /* 0xd9 */
679 { 0, "Eb=Sd=Ve=" }, /* 0xda */
681 { 0, "Eb=Mb=" }, /* 0xdb */
683 { 0, "" }, /* 0xdc */
685 { 0, "Ob=Vf=" }, /* 0xdd */
687 { 0, "" }, /* 0xde */
688 { 0, "" }, /* 0xdf */
689 { 0, "" }, /* 0xe0 */
690 { 0, "" }, /* 0xe1 */
691 { 0, "" }, /* 0xe2 */
692 { 0, "" }, /* 0xe3 */
693 { 0, "" }, /* 0xe4 */
694 { 0, "" }, /* 0xe5 */
695 { 0, "" }, /* 0xe6 */
696 { 0, "" }, /* 0xe7 */
697 { 0, "" }, /* 0xe8 */
698 { 0, "" }, /* 0xe9 */
699 { 0, "" }, /* 0xea */
700 { 0, "" }, /* 0xeb */
701 { 0, "" }, /* 0xec */
702 { 0, "" }, /* 0xed */
703 { 0, "" }, /* 0xee */
704 { 0, "" }, /* 0xef */
705 { 0, "" }, /* 0xf0 */
706 { 0, "" }, /* 0xf1 */
707 { 0, "" }, /* 0xf2 */
708 { 0, "" }, /* 0xf3 */
709 { 0, "" }, /* 0xf4 */
710 { 0, "" }, /* 0xf5 */
711 { 0, "" }, /* 0xf6 */
712 { 0, "" }, /* 0xf7 */
713 { 0, "" }, /* 0xf8 */
714 { 0, "" }, /* 0xf9 */
715 { 0, "" }, /* 0xfa */
716 { 0, "" }, /* 0xfb */
717 { 0, "" }, /* 0xfc */
718 { 0, "" }, /* 0xfd */
719 { 0, "" }, /* 0xfe */
720 { 0, "" }, /* 0xff */
723 static const int comp1_opcodes
[] = {
744 static const int comp2_opcodes
[] = {
752 static const int comp3_opcodes
[] = {
758 /* These apparently are not in older versions of hpux reloc.h (hpux7). */
760 #define R_DLT_REL 0x78
764 #define R_AUX_UNWIND 0xcf
768 #define R_SEC_STMT 0xd7
771 /* And these first appeared in hpux10. */
772 #ifndef R_SHORT_PCREL_MODE
773 #define NO_PCREL_MODES
774 #define R_SHORT_PCREL_MODE 0x3e
777 #ifndef R_LONG_PCREL_MODE
778 #define R_LONG_PCREL_MODE 0x3f
790 #define R_LINETAB 0xda
793 #ifndef R_LINETAB_ESC
794 #define R_LINETAB_ESC 0xdb
797 #ifndef R_LTP_OVERRIDE
798 #define R_LTP_OVERRIDE 0xdc
802 #define R_COMMENT 0xdd
805 #define SOM_HOWTO(TYPE, NAME) \
806 HOWTO(TYPE, 0, 0, 32, FALSE, 0, 0, hppa_som_reloc, NAME, FALSE, 0, 0, FALSE)
808 static reloc_howto_type som_hppa_howto_table
[] = {
809 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
810 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
811 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
812 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
813 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
814 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
815 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
816 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
817 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
818 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
819 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
820 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
821 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
822 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
823 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
824 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
825 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
826 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
827 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
828 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
829 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
830 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
831 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
832 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
833 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
834 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
835 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
836 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
837 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
838 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
839 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
840 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
841 SOM_HOWTO (R_ZEROES
, "R_ZEROES"),
842 SOM_HOWTO (R_ZEROES
, "R_ZEROES"),
843 SOM_HOWTO (R_UNINIT
, "R_UNINIT"),
844 SOM_HOWTO (R_UNINIT
, "R_UNINIT"),
845 SOM_HOWTO (R_RELOCATION
, "R_RELOCATION"),
846 SOM_HOWTO (R_DATA_ONE_SYMBOL
, "R_DATA_ONE_SYMBOL"),
847 SOM_HOWTO (R_DATA_ONE_SYMBOL
, "R_DATA_ONE_SYMBOL"),
848 SOM_HOWTO (R_DATA_PLABEL
, "R_DATA_PLABEL"),
849 SOM_HOWTO (R_DATA_PLABEL
, "R_DATA_PLABEL"),
850 SOM_HOWTO (R_SPACE_REF
, "R_SPACE_REF"),
851 SOM_HOWTO (R_REPEATED_INIT
, "REPEATED_INIT"),
852 SOM_HOWTO (R_REPEATED_INIT
, "REPEATED_INIT"),
853 SOM_HOWTO (R_REPEATED_INIT
, "REPEATED_INIT"),
854 SOM_HOWTO (R_REPEATED_INIT
, "REPEATED_INIT"),
855 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
856 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
857 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
858 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
859 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
860 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
861 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
862 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
863 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
864 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
865 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
866 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
867 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
868 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
869 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
870 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
871 SOM_HOWTO (R_SHORT_PCREL_MODE
, "R_SHORT_PCREL_MODE"),
872 SOM_HOWTO (R_LONG_PCREL_MODE
, "R_LONG_PCREL_MODE"),
873 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
874 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
875 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
876 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
877 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
878 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
879 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
880 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
881 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
882 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
883 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
884 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
885 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
886 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
887 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
888 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
889 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
890 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
891 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
892 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
893 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
894 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
895 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
896 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
897 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
898 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
899 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
900 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
901 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
902 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
903 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
904 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
905 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
906 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
907 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
908 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
909 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
910 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
911 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
912 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
913 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
914 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
915 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
916 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
917 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
918 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
919 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
920 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
921 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
922 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
923 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
924 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
925 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
926 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
927 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
928 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
929 SOM_HOWTO (R_DLT_REL
, "R_DLT_REL"),
930 SOM_HOWTO (R_DLT_REL
, "R_DLT_REL"),
931 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
932 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
933 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
934 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
935 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
936 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
937 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
938 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
939 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
940 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
941 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
942 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
943 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
944 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
945 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
946 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
947 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
948 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
949 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
950 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
951 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
952 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
953 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
954 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
955 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
956 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
957 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
958 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
959 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
960 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
961 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
962 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
963 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
964 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
965 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
966 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
967 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
968 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
969 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
970 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
971 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
972 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
973 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
974 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
975 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
976 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
977 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
978 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
979 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
980 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
981 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
982 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
983 SOM_HOWTO (R_MILLI_REL
, "R_MILLI_REL"),
984 SOM_HOWTO (R_MILLI_REL
, "R_MILLI_REL"),
985 SOM_HOWTO (R_CODE_PLABEL
, "R_CODE_PLABEL"),
986 SOM_HOWTO (R_CODE_PLABEL
, "R_CODE_PLABEL"),
987 SOM_HOWTO (R_BREAKPOINT
, "R_BREAKPOINT"),
988 SOM_HOWTO (R_ENTRY
, "R_ENTRY"),
989 SOM_HOWTO (R_ENTRY
, "R_ENTRY"),
990 SOM_HOWTO (R_ALT_ENTRY
, "R_ALT_ENTRY"),
991 SOM_HOWTO (R_EXIT
, "R_EXIT"),
992 SOM_HOWTO (R_BEGIN_TRY
, "R_BEGIN_TRY"),
993 SOM_HOWTO (R_END_TRY
, "R_END_TRY"),
994 SOM_HOWTO (R_END_TRY
, "R_END_TRY"),
995 SOM_HOWTO (R_END_TRY
, "R_END_TRY"),
996 SOM_HOWTO (R_BEGIN_BRTAB
, "R_BEGIN_BRTAB"),
997 SOM_HOWTO (R_END_BRTAB
, "R_END_BRTAB"),
998 SOM_HOWTO (R_STATEMENT
, "R_STATEMENT"),
999 SOM_HOWTO (R_STATEMENT
, "R_STATEMENT"),
1000 SOM_HOWTO (R_STATEMENT
, "R_STATEMENT"),
1001 SOM_HOWTO (R_DATA_EXPR
, "R_DATA_EXPR"),
1002 SOM_HOWTO (R_CODE_EXPR
, "R_CODE_EXPR"),
1003 SOM_HOWTO (R_FSEL
, "R_FSEL"),
1004 SOM_HOWTO (R_LSEL
, "R_LSEL"),
1005 SOM_HOWTO (R_RSEL
, "R_RSEL"),
1006 SOM_HOWTO (R_N_MODE
, "R_N_MODE"),
1007 SOM_HOWTO (R_S_MODE
, "R_S_MODE"),
1008 SOM_HOWTO (R_D_MODE
, "R_D_MODE"),
1009 SOM_HOWTO (R_R_MODE
, "R_R_MODE"),
1010 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
1011 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
1012 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
1013 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
1014 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
1015 SOM_HOWTO (R_TRANSLATED
, "R_TRANSLATED"),
1016 SOM_HOWTO (R_AUX_UNWIND
, "R_AUX_UNWIND"),
1017 SOM_HOWTO (R_COMP1
, "R_COMP1"),
1018 SOM_HOWTO (R_COMP2
, "R_COMP2"),
1019 SOM_HOWTO (R_COMP3
, "R_COMP3"),
1020 SOM_HOWTO (R_PREV_FIXUP
, "R_PREV_FIXUP"),
1021 SOM_HOWTO (R_PREV_FIXUP
, "R_PREV_FIXUP"),
1022 SOM_HOWTO (R_PREV_FIXUP
, "R_PREV_FIXUP"),
1023 SOM_HOWTO (R_PREV_FIXUP
, "R_PREV_FIXUP"),
1024 SOM_HOWTO (R_SEC_STMT
, "R_SEC_STMT"),
1025 SOM_HOWTO (R_N0SEL
, "R_N0SEL"),
1026 SOM_HOWTO (R_N1SEL
, "R_N1SEL"),
1027 SOM_HOWTO (R_LINETAB
, "R_LINETAB"),
1028 SOM_HOWTO (R_LINETAB_ESC
, "R_LINETAB_ESC"),
1029 SOM_HOWTO (R_LTP_OVERRIDE
, "R_LTP_OVERRIDE"),
1030 SOM_HOWTO (R_COMMENT
, "R_COMMENT"),
1031 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1032 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1033 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1034 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1035 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1036 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1037 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1038 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1039 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1040 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1041 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1042 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1043 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1044 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1045 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1046 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1047 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1048 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1049 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1050 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1051 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1052 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1053 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1054 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1055 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1056 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1057 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1058 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1059 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1060 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1061 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1062 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1063 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1064 SOM_HOWTO (R_RESERVED
, "R_RESERVED")
1067 /* Initialize the SOM relocation queue. By definition the queue holds
1068 the last four multibyte fixups. */
1071 som_initialize_reloc_queue (queue
)
1072 struct reloc_queue
*queue
;
1074 queue
[0].reloc
= NULL
;
1076 queue
[1].reloc
= NULL
;
1078 queue
[2].reloc
= NULL
;
1080 queue
[3].reloc
= NULL
;
1084 /* Insert a new relocation into the relocation queue. */
1087 som_reloc_queue_insert (p
, size
, queue
)
1090 struct reloc_queue
*queue
;
1092 queue
[3].reloc
= queue
[2].reloc
;
1093 queue
[3].size
= queue
[2].size
;
1094 queue
[2].reloc
= queue
[1].reloc
;
1095 queue
[2].size
= queue
[1].size
;
1096 queue
[1].reloc
= queue
[0].reloc
;
1097 queue
[1].size
= queue
[0].size
;
1099 queue
[0].size
= size
;
1102 /* When an entry in the relocation queue is reused, the entry moves
1103 to the front of the queue. */
1106 som_reloc_queue_fix (queue
, index
)
1107 struct reloc_queue
*queue
;
1115 unsigned char *tmp1
= queue
[0].reloc
;
1116 unsigned int tmp2
= queue
[0].size
;
1117 queue
[0].reloc
= queue
[1].reloc
;
1118 queue
[0].size
= queue
[1].size
;
1119 queue
[1].reloc
= tmp1
;
1120 queue
[1].size
= tmp2
;
1126 unsigned char *tmp1
= queue
[0].reloc
;
1127 unsigned int tmp2
= queue
[0].size
;
1128 queue
[0].reloc
= queue
[2].reloc
;
1129 queue
[0].size
= queue
[2].size
;
1130 queue
[2].reloc
= queue
[1].reloc
;
1131 queue
[2].size
= queue
[1].size
;
1132 queue
[1].reloc
= tmp1
;
1133 queue
[1].size
= tmp2
;
1139 unsigned char *tmp1
= queue
[0].reloc
;
1140 unsigned int tmp2
= queue
[0].size
;
1141 queue
[0].reloc
= queue
[3].reloc
;
1142 queue
[0].size
= queue
[3].size
;
1143 queue
[3].reloc
= queue
[2].reloc
;
1144 queue
[3].size
= queue
[2].size
;
1145 queue
[2].reloc
= queue
[1].reloc
;
1146 queue
[2].size
= queue
[1].size
;
1147 queue
[1].reloc
= tmp1
;
1148 queue
[1].size
= tmp2
;
1154 /* Search for a particular relocation in the relocation queue. */
1157 som_reloc_queue_find (p
, size
, queue
)
1160 struct reloc_queue
*queue
;
1162 if (queue
[0].reloc
&& !memcmp (p
, queue
[0].reloc
, size
)
1163 && size
== queue
[0].size
)
1165 if (queue
[1].reloc
&& !memcmp (p
, queue
[1].reloc
, size
)
1166 && size
== queue
[1].size
)
1168 if (queue
[2].reloc
&& !memcmp (p
, queue
[2].reloc
, size
)
1169 && size
== queue
[2].size
)
1171 if (queue
[3].reloc
&& !memcmp (p
, queue
[3].reloc
, size
)
1172 && size
== queue
[3].size
)
1177 static unsigned char *
1178 try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, size
, queue
)
1179 bfd
*abfd ATTRIBUTE_UNUSED
;
1180 int *subspace_reloc_sizep
;
1183 struct reloc_queue
*queue
;
1185 int queue_index
= som_reloc_queue_find (p
, size
, queue
);
1187 if (queue_index
!= -1)
1189 /* Found this in a previous fixup. Undo the fixup we
1190 just built and use R_PREV_FIXUP instead. We saved
1191 a total of size - 1 bytes in the fixup stream. */
1192 bfd_put_8 (abfd
, R_PREV_FIXUP
+ queue_index
, p
);
1194 *subspace_reloc_sizep
+= 1;
1195 som_reloc_queue_fix (queue
, queue_index
);
1199 som_reloc_queue_insert (p
, size
, queue
);
1200 *subspace_reloc_sizep
+= size
;
1206 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
1207 bytes without any relocation. Update the size of the subspace
1208 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
1209 current pointer into the relocation stream. */
1211 static unsigned char *
1212 som_reloc_skip (abfd
, skip
, p
, subspace_reloc_sizep
, queue
)
1216 unsigned int *subspace_reloc_sizep
;
1217 struct reloc_queue
*queue
;
1219 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
1220 then R_PREV_FIXUPs to get the difference down to a
1222 if (skip
>= 0x1000000)
1225 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 31, p
);
1226 bfd_put_8 (abfd
, 0xff, p
+ 1);
1227 bfd_put_16 (abfd
, (bfd_vma
) 0xffff, p
+ 2);
1228 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1229 while (skip
>= 0x1000000)
1232 bfd_put_8 (abfd
, R_PREV_FIXUP
, p
);
1234 *subspace_reloc_sizep
+= 1;
1235 /* No need to adjust queue here since we are repeating the
1236 most recent fixup. */
1240 /* The difference must be less than 0x1000000. Use one
1241 more R_NO_RELOCATION entry to get to the right difference. */
1242 if ((skip
& 3) == 0 && skip
<= 0xc0000 && skip
> 0)
1244 /* Difference can be handled in a simple single-byte
1245 R_NO_RELOCATION entry. */
1248 bfd_put_8 (abfd
, R_NO_RELOCATION
+ (skip
>> 2) - 1, p
);
1249 *subspace_reloc_sizep
+= 1;
1252 /* Handle it with a two byte R_NO_RELOCATION entry. */
1253 else if (skip
<= 0x1000)
1255 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 24 + (((skip
>> 2) - 1) >> 8), p
);
1256 bfd_put_8 (abfd
, (skip
>> 2) - 1, p
+ 1);
1257 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1259 /* Handle it with a three byte R_NO_RELOCATION entry. */
1262 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 28 + (((skip
>> 2) - 1) >> 16), p
);
1263 bfd_put_16 (abfd
, (bfd_vma
) (skip
>> 2) - 1, p
+ 1);
1264 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1267 /* Ugh. Punt and use a 4 byte entry. */
1270 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 31, p
);
1271 bfd_put_8 (abfd
, (skip
- 1) >> 16, p
+ 1);
1272 bfd_put_16 (abfd
, (bfd_vma
) skip
- 1, p
+ 2);
1273 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1278 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
1279 from a BFD relocation. Update the size of the subspace relocation
1280 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
1281 into the relocation stream. */
1283 static unsigned char *
1284 som_reloc_addend (abfd
, addend
, p
, subspace_reloc_sizep
, queue
)
1288 unsigned int *subspace_reloc_sizep
;
1289 struct reloc_queue
*queue
;
1291 if (addend
+ 0x80 < 0x100)
1293 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 1, p
);
1294 bfd_put_8 (abfd
, addend
, p
+ 1);
1295 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1297 else if (addend
+ 0x8000 < 0x10000)
1299 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 2, p
);
1300 bfd_put_16 (abfd
, addend
, p
+ 1);
1301 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1303 else if (addend
+ 0x800000 < 0x1000000)
1305 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 3, p
);
1306 bfd_put_8 (abfd
, addend
>> 16, p
+ 1);
1307 bfd_put_16 (abfd
, addend
, p
+ 2);
1308 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1312 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 4, p
);
1313 bfd_put_32 (abfd
, addend
, p
+ 1);
1314 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 5, queue
);
1319 /* Handle a single function call relocation. */
1321 static unsigned char *
1322 som_reloc_call (abfd
, p
, subspace_reloc_sizep
, bfd_reloc
, sym_num
, queue
)
1325 unsigned int *subspace_reloc_sizep
;
1328 struct reloc_queue
*queue
;
1330 int arg_bits
= HPPA_R_ARG_RELOC (bfd_reloc
->addend
);
1331 int rtn_bits
= arg_bits
& 0x3;
1334 /* You'll never believe all this is necessary to handle relocations
1335 for function calls. Having to compute and pack the argument
1336 relocation bits is the real nightmare.
1338 If you're interested in how this works, just forget it. You really
1339 do not want to know about this braindamage. */
1341 /* First see if this can be done with a "simple" relocation. Simple
1342 relocations have a symbol number < 0x100 and have simple encodings
1343 of argument relocations. */
1345 if (sym_num
< 0x100)
1357 case 1 << 8 | 1 << 6:
1358 case 1 << 8 | 1 << 6 | 1:
1361 case 1 << 8 | 1 << 6 | 1 << 4:
1362 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
1365 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
1366 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
1370 /* Not one of the easy encodings. This will have to be
1371 handled by the more complex code below. */
1377 /* Account for the return value too. */
1381 /* Emit a 2 byte relocation. Then see if it can be handled
1382 with a relocation which is already in the relocation queue. */
1383 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ type
, p
);
1384 bfd_put_8 (abfd
, sym_num
, p
+ 1);
1385 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1390 /* If this could not be handled with a simple relocation, then do a hard
1391 one. Hard relocations occur if the symbol number was too high or if
1392 the encoding of argument relocation bits is too complex. */
1395 /* Don't ask about these magic sequences. I took them straight
1396 from gas-1.36 which took them from the a.out man page. */
1398 if ((arg_bits
>> 6 & 0xf) == 0xe)
1401 type
+= (3 * (arg_bits
>> 8 & 3) + (arg_bits
>> 6 & 3)) * 40;
1402 if ((arg_bits
>> 2 & 0xf) == 0xe)
1405 type
+= (3 * (arg_bits
>> 4 & 3) + (arg_bits
>> 2 & 3)) * 4;
1407 /* Output the first two bytes of the relocation. These describe
1408 the length of the relocation and encoding style. */
1409 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 10
1410 + 2 * (sym_num
>= 0x100) + (type
>= 0x100),
1412 bfd_put_8 (abfd
, type
, p
+ 1);
1414 /* Now output the symbol index and see if this bizarre relocation
1415 just happened to be in the relocation queue. */
1416 if (sym_num
< 0x100)
1418 bfd_put_8 (abfd
, sym_num
, p
+ 2);
1419 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1423 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 2);
1424 bfd_put_16 (abfd
, (bfd_vma
) sym_num
, p
+ 3);
1425 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 5, queue
);
1431 /* Return the logarithm of X, base 2, considering X unsigned.
1432 Abort -1 if X is not a power or two or is zero. */
1440 /* Test for 0 or a power of 2. */
1441 if (x
== 0 || x
!= (x
& -x
))
1444 while ((x
>>= 1) != 0)
1449 static bfd_reloc_status_type
1450 hppa_som_reloc (abfd
, reloc_entry
, symbol_in
, data
,
1451 input_section
, output_bfd
, error_message
)
1452 bfd
*abfd ATTRIBUTE_UNUSED
;
1453 arelent
*reloc_entry
;
1454 asymbol
*symbol_in ATTRIBUTE_UNUSED
;
1455 PTR data ATTRIBUTE_UNUSED
;
1456 asection
*input_section
;
1458 char **error_message ATTRIBUTE_UNUSED
;
1462 reloc_entry
->address
+= input_section
->output_offset
;
1463 return bfd_reloc_ok
;
1465 return bfd_reloc_ok
;
1468 /* Given a generic HPPA relocation type, the instruction format,
1469 and a field selector, return one or more appropriate SOM relocations. */
1472 hppa_som_gen_reloc_type (abfd
, base_type
, format
, field
, sym_diff
, sym
)
1476 enum hppa_reloc_field_selector_type_alt field
;
1480 int *final_type
, **final_types
;
1482 final_types
= (int **) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int *) * 6);
1483 final_type
= (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1484 if (!final_types
|| !final_type
)
1487 /* The field selector may require additional relocations to be
1488 generated. It's impossible to know at this moment if additional
1489 relocations will be needed, so we make them. The code to actually
1490 write the relocation/fixup stream is responsible for removing
1491 any redundant relocations. */
1498 final_types
[0] = final_type
;
1499 final_types
[1] = NULL
;
1500 final_types
[2] = NULL
;
1501 *final_type
= base_type
;
1507 final_types
[0] = (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1508 if (!final_types
[0])
1510 if (field
== e_tsel
)
1511 *final_types
[0] = R_FSEL
;
1512 else if (field
== e_ltsel
)
1513 *final_types
[0] = R_LSEL
;
1515 *final_types
[0] = R_RSEL
;
1516 final_types
[1] = final_type
;
1517 final_types
[2] = NULL
;
1518 *final_type
= base_type
;
1523 final_types
[0] = (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1524 if (!final_types
[0])
1526 *final_types
[0] = R_S_MODE
;
1527 final_types
[1] = final_type
;
1528 final_types
[2] = NULL
;
1529 *final_type
= base_type
;
1534 final_types
[0] = (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1535 if (!final_types
[0])
1537 *final_types
[0] = R_N_MODE
;
1538 final_types
[1] = final_type
;
1539 final_types
[2] = NULL
;
1540 *final_type
= base_type
;
1545 final_types
[0] = (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1546 if (!final_types
[0])
1548 *final_types
[0] = R_D_MODE
;
1549 final_types
[1] = final_type
;
1550 final_types
[2] = NULL
;
1551 *final_type
= base_type
;
1556 final_types
[0] = (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1557 if (!final_types
[0])
1559 *final_types
[0] = R_R_MODE
;
1560 final_types
[1] = final_type
;
1561 final_types
[2] = NULL
;
1562 *final_type
= base_type
;
1566 final_types
[0] = (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1567 if (!final_types
[0])
1569 *final_types
[0] = R_N1SEL
;
1570 final_types
[1] = final_type
;
1571 final_types
[2] = NULL
;
1572 *final_type
= base_type
;
1577 final_types
[0] = (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1578 if (!final_types
[0])
1580 *final_types
[0] = R_N0SEL
;
1581 final_types
[1] = (int *) bfd_alloc (abfd
, (bfd_size_type
) sizeof (int));
1582 if (!final_types
[1])
1584 if (field
== e_nlsel
)
1585 *final_types
[1] = R_N_MODE
;
1587 *final_types
[1] = R_R_MODE
;
1588 final_types
[2] = final_type
;
1589 final_types
[3] = NULL
;
1590 *final_type
= base_type
;
1593 /* FIXME: These two field selectors are not currently supported. */
1602 /* The difference of two symbols needs *very* special handling. */
1605 bfd_size_type amt
= sizeof (int);
1606 final_types
[0] = (int *) bfd_alloc (abfd
, amt
);
1607 final_types
[1] = (int *) bfd_alloc (abfd
, amt
);
1608 final_types
[2] = (int *) bfd_alloc (abfd
, amt
);
1609 final_types
[3] = (int *) bfd_alloc (abfd
, amt
);
1610 if (!final_types
[0] || !final_types
[1] || !final_types
[2])
1612 if (field
== e_fsel
)
1613 *final_types
[0] = R_FSEL
;
1614 else if (field
== e_rsel
)
1615 *final_types
[0] = R_RSEL
;
1616 else if (field
== e_lsel
)
1617 *final_types
[0] = R_LSEL
;
1618 *final_types
[1] = R_COMP2
;
1619 *final_types
[2] = R_COMP2
;
1620 *final_types
[3] = R_COMP1
;
1621 final_types
[4] = final_type
;
1623 *final_types
[4] = R_DATA_EXPR
;
1625 *final_types
[4] = R_CODE_EXPR
;
1626 final_types
[5] = NULL
;
1629 /* PLABELs get their own relocation type. */
1630 else if (field
== e_psel
1632 || field
== e_rpsel
)
1634 /* A PLABEL relocation that has a size of 32 bits must
1635 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
1637 *final_type
= R_DATA_PLABEL
;
1639 *final_type
= R_CODE_PLABEL
;
1642 else if (field
== e_tsel
1644 || field
== e_rtsel
)
1645 *final_type
= R_DLT_REL
;
1646 /* A relocation in the data space is always a full 32bits. */
1647 else if (format
== 32)
1649 *final_type
= R_DATA_ONE_SYMBOL
;
1651 /* If there's no SOM symbol type associated with this BFD
1652 symbol, then set the symbol type to ST_DATA.
1654 Only do this if the type is going to default later when
1655 we write the object file.
1657 This is done so that the linker never encounters an
1658 R_DATA_ONE_SYMBOL reloc involving an ST_CODE symbol.
1660 This allows the compiler to generate exception handling
1663 Note that one day we may need to also emit BEGIN_BRTAB and
1664 END_BRTAB to prevent the linker from optimizing away insns
1665 in exception handling regions. */
1666 if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
1667 && (sym
->flags
& BSF_SECTION_SYM
) == 0
1668 && (sym
->flags
& BSF_FUNCTION
) == 0
1669 && ! bfd_is_com_section (sym
->section
))
1670 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_DATA
;
1675 /* More PLABEL special cases. */
1678 || field
== e_rpsel
)
1679 *final_type
= R_DATA_PLABEL
;
1682 case R_HPPA_COMPLEX
:
1683 /* The difference of two symbols needs *very* special handling. */
1686 bfd_size_type amt
= sizeof (int);
1687 final_types
[0] = (int *) bfd_alloc (abfd
, amt
);
1688 final_types
[1] = (int *) bfd_alloc (abfd
, amt
);
1689 final_types
[2] = (int *) bfd_alloc (abfd
, amt
);
1690 final_types
[3] = (int *) bfd_alloc (abfd
, amt
);
1691 if (!final_types
[0] || !final_types
[1] || !final_types
[2])
1693 if (field
== e_fsel
)
1694 *final_types
[0] = R_FSEL
;
1695 else if (field
== e_rsel
)
1696 *final_types
[0] = R_RSEL
;
1697 else if (field
== e_lsel
)
1698 *final_types
[0] = R_LSEL
;
1699 *final_types
[1] = R_COMP2
;
1700 *final_types
[2] = R_COMP2
;
1701 *final_types
[3] = R_COMP1
;
1702 final_types
[4] = final_type
;
1704 *final_types
[4] = R_DATA_EXPR
;
1706 *final_types
[4] = R_CODE_EXPR
;
1707 final_types
[5] = NULL
;
1714 case R_HPPA_ABS_CALL
:
1715 /* Right now we can default all these. */
1718 case R_HPPA_PCREL_CALL
:
1720 #ifndef NO_PCREL_MODES
1721 /* If we have short and long pcrel modes, then generate the proper
1722 mode selector, then the pcrel relocation. Redundant selectors
1723 will be eliminated as the relocs are sized and emitted. */
1724 bfd_size_type amt
= sizeof (int);
1725 final_types
[0] = (int *) bfd_alloc (abfd
, amt
);
1726 if (!final_types
[0])
1729 *final_types
[0] = R_SHORT_PCREL_MODE
;
1731 *final_types
[0] = R_LONG_PCREL_MODE
;
1732 final_types
[1] = final_type
;
1733 final_types
[2] = NULL
;
1734 *final_type
= base_type
;
1742 /* Return the address of the correct entry in the PA SOM relocation
1745 static reloc_howto_type
*
1746 som_bfd_reloc_type_lookup (abfd
, code
)
1747 bfd
*abfd ATTRIBUTE_UNUSED
;
1748 bfd_reloc_code_real_type code
;
1750 if ((int) code
< (int) R_NO_RELOCATION
+ 255)
1752 BFD_ASSERT ((int) som_hppa_howto_table
[(int) code
].type
== (int) code
);
1753 return &som_hppa_howto_table
[(int) code
];
1756 return (reloc_howto_type
*) 0;
1759 /* Perform some initialization for an object. Save results of this
1760 initialization in the BFD. */
1762 static const bfd_target
*
1763 som_object_setup (abfd
, file_hdrp
, aux_hdrp
, current_offset
)
1765 struct header
*file_hdrp
;
1766 struct som_exec_auxhdr
*aux_hdrp
;
1767 unsigned long current_offset
;
1772 /* som_mkobject will set bfd_error if som_mkobject fails. */
1773 if (! som_mkobject (abfd
))
1776 /* Set BFD flags based on what information is available in the SOM. */
1777 abfd
->flags
= BFD_NO_FLAGS
;
1778 if (file_hdrp
->symbol_total
)
1779 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
1781 switch (file_hdrp
->a_magic
)
1784 abfd
->flags
|= (D_PAGED
| WP_TEXT
| EXEC_P
);
1787 abfd
->flags
|= (WP_TEXT
| EXEC_P
);
1790 abfd
->flags
|= (EXEC_P
);
1793 abfd
->flags
|= HAS_RELOC
;
1801 abfd
->flags
|= DYNAMIC
;
1808 /* Allocate space to hold the saved exec header information. */
1809 obj_som_exec_data (abfd
) = (struct som_exec_data
*)
1810 bfd_zalloc (abfd
, (bfd_size_type
) sizeof (struct som_exec_data
));
1811 if (obj_som_exec_data (abfd
) == NULL
)
1814 /* The braindamaged OSF1 linker switched exec_flags and exec_entry!
1816 We used to identify OSF1 binaries based on NEW_VERSION_ID, but
1817 apparently the latest HPUX linker is using NEW_VERSION_ID now.
1819 It's about time, OSF has used the new id since at least 1992;
1820 HPUX didn't start till nearly 1995!.
1822 The new approach examines the entry field. If it's zero or not 4
1823 byte aligned then it's not a proper code address and we guess it's
1824 really the executable flags. */
1826 for (section
= abfd
->sections
; section
; section
= section
->next
)
1830 if ((section
->flags
& SEC_CODE
) == 0)
1832 entry
= aux_hdrp
->exec_entry
;
1833 if (entry
>= section
->vma
1834 && entry
< section
->vma
+ section
->_cooked_size
)
1837 if (aux_hdrp
->exec_entry
== 0
1838 || (aux_hdrp
->exec_entry
& 0x3) != 0
1841 bfd_get_start_address (abfd
) = aux_hdrp
->exec_flags
;
1842 obj_som_exec_data (abfd
)->exec_flags
= aux_hdrp
->exec_entry
;
1846 bfd_get_start_address (abfd
) = aux_hdrp
->exec_entry
+ current_offset
;
1847 obj_som_exec_data (abfd
)->exec_flags
= aux_hdrp
->exec_flags
;
1850 obj_som_exec_data (abfd
)->version_id
= file_hdrp
->version_id
;
1852 bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, pa10
);
1853 bfd_get_symcount (abfd
) = file_hdrp
->symbol_total
;
1855 /* Initialize the saved symbol table and string table to NULL.
1856 Save important offsets and sizes from the SOM header into
1858 obj_som_stringtab (abfd
) = (char *) NULL
;
1859 obj_som_symtab (abfd
) = (som_symbol_type
*) NULL
;
1860 obj_som_sorted_syms (abfd
) = NULL
;
1861 obj_som_stringtab_size (abfd
) = file_hdrp
->symbol_strings_size
;
1862 obj_som_sym_filepos (abfd
) = file_hdrp
->symbol_location
+ current_offset
;
1863 obj_som_str_filepos (abfd
) = (file_hdrp
->symbol_strings_location
1865 obj_som_reloc_filepos (abfd
) = (file_hdrp
->fixup_request_location
1867 obj_som_exec_data (abfd
)->system_id
= file_hdrp
->system_id
;
1872 /* Convert all of the space and subspace info into BFD sections. Each space
1873 contains a number of subspaces, which in turn describe the mapping between
1874 regions of the exec file, and the address space that the program runs in.
1875 BFD sections which correspond to spaces will overlap the sections for the
1876 associated subspaces. */
1879 setup_sections (abfd
, file_hdr
, current_offset
)
1881 struct header
*file_hdr
;
1882 unsigned long current_offset
;
1884 char *space_strings
;
1885 unsigned int space_index
, i
;
1886 unsigned int total_subspaces
= 0;
1887 asection
**subspace_sections
= NULL
;
1891 /* First, read in space names. */
1893 amt
= file_hdr
->space_strings_size
;
1894 space_strings
= bfd_malloc (amt
);
1895 if (!space_strings
&& amt
!= 0)
1898 if (bfd_seek (abfd
, current_offset
+ file_hdr
->space_strings_location
,
1901 if (bfd_bread (space_strings
, amt
, abfd
) != amt
)
1904 /* Loop over all of the space dictionaries, building up sections. */
1905 for (space_index
= 0; space_index
< file_hdr
->space_total
; space_index
++)
1907 struct space_dictionary_record space
;
1908 struct subspace_dictionary_record subspace
, save_subspace
;
1909 unsigned int subspace_index
;
1910 asection
*space_asect
;
1913 /* Read the space dictionary element. */
1915 (current_offset
+ file_hdr
->space_location
1916 + space_index
* sizeof space
),
1920 if (bfd_bread (&space
, amt
, abfd
) != amt
)
1923 /* Setup the space name string. */
1924 space
.name
.n_name
= space
.name
.n_strx
+ space_strings
;
1926 /* Make a section out of it. */
1927 amt
= strlen (space
.name
.n_name
) + 1;
1928 newname
= bfd_alloc (abfd
, amt
);
1931 strcpy (newname
, space
.name
.n_name
);
1933 space_asect
= bfd_make_section_anyway (abfd
, newname
);
1937 if (space
.is_loadable
== 0)
1938 space_asect
->flags
|= SEC_DEBUGGING
;
1940 /* Set up all the attributes for the space. */
1941 if (! bfd_som_set_section_attributes (space_asect
, space
.is_defined
,
1942 space
.is_private
, space
.sort_key
,
1943 space
.space_number
))
1946 /* If the space has no subspaces, then we're done. */
1947 if (space
.subspace_quantity
== 0)
1950 /* Now, read in the first subspace for this space. */
1952 (current_offset
+ file_hdr
->subspace_location
1953 + space
.subspace_index
* sizeof subspace
),
1956 amt
= sizeof subspace
;
1957 if (bfd_bread (&subspace
, amt
, abfd
) != amt
)
1959 /* Seek back to the start of the subspaces for loop below. */
1961 (current_offset
+ file_hdr
->subspace_location
1962 + space
.subspace_index
* sizeof subspace
),
1966 /* Setup the start address and file loc from the first subspace
1968 space_asect
->vma
= subspace
.subspace_start
;
1969 space_asect
->filepos
= subspace
.file_loc_init_value
+ current_offset
;
1970 space_asect
->alignment_power
= log2 (subspace
.alignment
);
1971 if (space_asect
->alignment_power
== (unsigned) -1)
1974 /* Initialize save_subspace so we can reliably determine if this
1975 loop placed any useful values into it. */
1976 memset (&save_subspace
, 0, sizeof (struct subspace_dictionary_record
));
1978 /* Loop over the rest of the subspaces, building up more sections. */
1979 for (subspace_index
= 0; subspace_index
< space
.subspace_quantity
;
1982 asection
*subspace_asect
;
1984 /* Read in the next subspace. */
1985 amt
= sizeof subspace
;
1986 if (bfd_bread (&subspace
, amt
, abfd
) != amt
)
1989 /* Setup the subspace name string. */
1990 subspace
.name
.n_name
= subspace
.name
.n_strx
+ space_strings
;
1992 amt
= strlen (subspace
.name
.n_name
) + 1;
1993 newname
= bfd_alloc (abfd
, amt
);
1996 strcpy (newname
, subspace
.name
.n_name
);
1998 /* Make a section out of this subspace. */
1999 subspace_asect
= bfd_make_section_anyway (abfd
, newname
);
2000 if (!subspace_asect
)
2003 /* Store private information about the section. */
2004 if (! bfd_som_set_subsection_attributes (subspace_asect
, space_asect
,
2005 subspace
.access_control_bits
,
2010 /* Keep an easy mapping between subspaces and sections.
2011 Note we do not necessarily read the subspaces in the
2012 same order in which they appear in the object file.
2014 So to make the target index come out correctly, we
2015 store the location of the subspace header in target
2016 index, then sort using the location of the subspace
2017 header as the key. Then we can assign correct
2018 subspace indices. */
2020 subspace_asect
->target_index
= bfd_tell (abfd
) - sizeof (subspace
);
2022 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
2023 by the access_control_bits in the subspace header. */
2024 switch (subspace
.access_control_bits
>> 4)
2026 /* Readonly data. */
2028 subspace_asect
->flags
|= SEC_DATA
| SEC_READONLY
;
2033 subspace_asect
->flags
|= SEC_DATA
;
2036 /* Readonly code and the gateways.
2037 Gateways have other attributes which do not map
2038 into anything BFD knows about. */
2044 subspace_asect
->flags
|= SEC_CODE
| SEC_READONLY
;
2047 /* dynamic (writable) code. */
2049 subspace_asect
->flags
|= SEC_CODE
;
2053 if (subspace
.dup_common
|| subspace
.is_common
)
2054 subspace_asect
->flags
|= SEC_IS_COMMON
;
2055 else if (subspace
.subspace_length
> 0)
2056 subspace_asect
->flags
|= SEC_HAS_CONTENTS
;
2058 if (subspace
.is_loadable
)
2059 subspace_asect
->flags
|= SEC_ALLOC
| SEC_LOAD
;
2061 subspace_asect
->flags
|= SEC_DEBUGGING
;
2063 if (subspace
.code_only
)
2064 subspace_asect
->flags
|= SEC_CODE
;
2066 /* Both file_loc_init_value and initialization_length will
2067 be zero for a BSS like subspace. */
2068 if (subspace
.file_loc_init_value
== 0
2069 && subspace
.initialization_length
== 0)
2070 subspace_asect
->flags
&= ~(SEC_DATA
| SEC_LOAD
| SEC_HAS_CONTENTS
);
2072 /* This subspace has relocations.
2073 The fixup_request_quantity is a byte count for the number of
2074 entries in the relocation stream; it is not the actual number
2075 of relocations in the subspace. */
2076 if (subspace
.fixup_request_quantity
!= 0)
2078 subspace_asect
->flags
|= SEC_RELOC
;
2079 subspace_asect
->rel_filepos
= subspace
.fixup_request_index
;
2080 som_section_data (subspace_asect
)->reloc_size
2081 = subspace
.fixup_request_quantity
;
2082 /* We can not determine this yet. When we read in the
2083 relocation table the correct value will be filled in. */
2084 subspace_asect
->reloc_count
= (unsigned) -1;
2087 /* Update save_subspace if appropriate. */
2088 if (subspace
.file_loc_init_value
> save_subspace
.file_loc_init_value
)
2089 save_subspace
= subspace
;
2091 subspace_asect
->vma
= subspace
.subspace_start
;
2092 subspace_asect
->_cooked_size
= subspace
.subspace_length
;
2093 subspace_asect
->_raw_size
= subspace
.subspace_length
;
2094 subspace_asect
->filepos
= (subspace
.file_loc_init_value
2096 subspace_asect
->alignment_power
= log2 (subspace
.alignment
);
2097 if (subspace_asect
->alignment_power
== (unsigned) -1)
2101 /* This can happen for a .o which defines symbols in otherwise
2103 if (!save_subspace
.file_loc_init_value
)
2105 space_asect
->_cooked_size
= 0;
2106 space_asect
->_raw_size
= 0;
2110 /* Setup the sizes for the space section based upon the info in the
2111 last subspace of the space. */
2112 space_asect
->_cooked_size
= (save_subspace
.subspace_start
2114 + save_subspace
.subspace_length
);
2115 space_asect
->_raw_size
= (save_subspace
.file_loc_init_value
2116 - space_asect
->filepos
2117 + save_subspace
.initialization_length
);
2120 /* Now that we've read in all the subspace records, we need to assign
2121 a target index to each subspace. */
2122 amt
= total_subspaces
;
2123 amt
*= sizeof (asection
*);
2124 subspace_sections
= (asection
**) bfd_malloc (amt
);
2125 if (subspace_sections
== NULL
)
2128 for (i
= 0, section
= abfd
->sections
; section
; section
= section
->next
)
2130 if (!som_is_subspace (section
))
2133 subspace_sections
[i
] = section
;
2136 qsort (subspace_sections
, total_subspaces
,
2137 sizeof (asection
*), compare_subspaces
);
2139 /* subspace_sections is now sorted in the order in which the subspaces
2140 appear in the object file. Assign an index to each one now. */
2141 for (i
= 0; i
< total_subspaces
; i
++)
2142 subspace_sections
[i
]->target_index
= i
;
2144 if (space_strings
!= NULL
)
2145 free (space_strings
);
2147 if (subspace_sections
!= NULL
)
2148 free (subspace_sections
);
2153 if (space_strings
!= NULL
)
2154 free (space_strings
);
2156 if (subspace_sections
!= NULL
)
2157 free (subspace_sections
);
2161 /* Read in a SOM object and make it into a BFD. */
2163 static const bfd_target
*
2167 struct header file_hdr
;
2168 struct som_exec_auxhdr aux_hdr
;
2169 unsigned long current_offset
= 0;
2170 struct lst_header lst_header
;
2171 struct som_entry som_entry
;
2173 #define ENTRY_SIZE sizeof (struct som_entry)
2175 amt
= FILE_HDR_SIZE
;
2176 if (bfd_bread ((PTR
) &file_hdr
, amt
, abfd
) != amt
)
2178 if (bfd_get_error () != bfd_error_system_call
)
2179 bfd_set_error (bfd_error_wrong_format
);
2183 if (!_PA_RISC_ID (file_hdr
.system_id
))
2185 bfd_set_error (bfd_error_wrong_format
);
2189 switch (file_hdr
.a_magic
)
2201 #ifdef SHARED_MAGIC_CNX
2202 case SHARED_MAGIC_CNX
:
2208 /* Read the lst header and determine where the SOM directory begins. */
2210 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2212 if (bfd_get_error () != bfd_error_system_call
)
2213 bfd_set_error (bfd_error_wrong_format
);
2218 if (bfd_bread ((PTR
) &lst_header
, amt
, abfd
) != amt
)
2220 if (bfd_get_error () != bfd_error_system_call
)
2221 bfd_set_error (bfd_error_wrong_format
);
2225 /* Position to and read the first directory entry. */
2227 if (bfd_seek (abfd
, lst_header
.dir_loc
, SEEK_SET
) != 0)
2229 if (bfd_get_error () != bfd_error_system_call
)
2230 bfd_set_error (bfd_error_wrong_format
);
2235 if (bfd_bread ((PTR
) &som_entry
, amt
, abfd
) != amt
)
2237 if (bfd_get_error () != bfd_error_system_call
)
2238 bfd_set_error (bfd_error_wrong_format
);
2242 /* Now position to the first SOM. */
2244 if (bfd_seek (abfd
, som_entry
.location
, SEEK_SET
) != 0)
2246 if (bfd_get_error () != bfd_error_system_call
)
2247 bfd_set_error (bfd_error_wrong_format
);
2251 current_offset
= som_entry
.location
;
2253 /* And finally, re-read the som header. */
2254 amt
= FILE_HDR_SIZE
;
2255 if (bfd_bread ((PTR
) &file_hdr
, amt
, abfd
) != amt
)
2257 if (bfd_get_error () != bfd_error_system_call
)
2258 bfd_set_error (bfd_error_wrong_format
);
2266 bfd_set_error (bfd_error_wrong_format
);
2270 if (file_hdr
.version_id
!= VERSION_ID
2271 && file_hdr
.version_id
!= NEW_VERSION_ID
)
2273 bfd_set_error (bfd_error_wrong_format
);
2277 /* If the aux_header_size field in the file header is zero, then this
2278 object is an incomplete executable (a .o file). Do not try to read
2279 a non-existant auxiliary header. */
2280 memset (&aux_hdr
, 0, sizeof (struct som_exec_auxhdr
));
2281 if (file_hdr
.aux_header_size
!= 0)
2284 if (bfd_bread ((PTR
) &aux_hdr
, amt
, abfd
) != amt
)
2286 if (bfd_get_error () != bfd_error_system_call
)
2287 bfd_set_error (bfd_error_wrong_format
);
2292 if (!setup_sections (abfd
, &file_hdr
, current_offset
))
2294 /* setup_sections does not bubble up a bfd error code. */
2295 bfd_set_error (bfd_error_bad_value
);
2299 /* This appears to be a valid SOM object. Do some initialization. */
2300 return som_object_setup (abfd
, &file_hdr
, &aux_hdr
, current_offset
);
2303 /* Create a SOM object. */
2309 /* Allocate memory to hold backend information. */
2310 abfd
->tdata
.som_data
= (struct som_data_struct
*)
2311 bfd_zalloc (abfd
, (bfd_size_type
) sizeof (struct som_data_struct
));
2312 if (abfd
->tdata
.som_data
== NULL
)
2317 /* Initialize some information in the file header. This routine makes
2318 not attempt at doing the right thing for a full executable; it
2319 is only meant to handle relocatable objects. */
2322 som_prep_headers (abfd
)
2325 struct header
*file_hdr
;
2327 bfd_size_type amt
= sizeof (struct header
);
2329 /* Make and attach a file header to the BFD. */
2330 file_hdr
= (struct header
*) bfd_zalloc (abfd
, amt
);
2331 if (file_hdr
== NULL
)
2333 obj_som_file_hdr (abfd
) = file_hdr
;
2335 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
2337 /* Make and attach an exec header to the BFD. */
2338 amt
= sizeof (struct som_exec_auxhdr
);
2339 obj_som_exec_hdr (abfd
) =
2340 (struct som_exec_auxhdr
*) bfd_zalloc (abfd
, amt
);
2341 if (obj_som_exec_hdr (abfd
) == NULL
)
2344 if (abfd
->flags
& D_PAGED
)
2345 file_hdr
->a_magic
= DEMAND_MAGIC
;
2346 else if (abfd
->flags
& WP_TEXT
)
2347 file_hdr
->a_magic
= SHARE_MAGIC
;
2349 else if (abfd
->flags
& DYNAMIC
)
2350 file_hdr
->a_magic
= SHL_MAGIC
;
2353 file_hdr
->a_magic
= EXEC_MAGIC
;
2356 file_hdr
->a_magic
= RELOC_MAGIC
;
2358 /* These fields are optional, and embedding timestamps is not always
2359 a wise thing to do, it makes comparing objects during a multi-stage
2360 bootstrap difficult. */
2361 file_hdr
->file_time
.secs
= 0;
2362 file_hdr
->file_time
.nanosecs
= 0;
2364 file_hdr
->entry_space
= 0;
2365 file_hdr
->entry_subspace
= 0;
2366 file_hdr
->entry_offset
= 0;
2367 file_hdr
->presumed_dp
= 0;
2369 /* Now iterate over the sections translating information from
2370 BFD sections to SOM spaces/subspaces. */
2372 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2374 /* Ignore anything which has not been marked as a space or
2376 if (!som_is_space (section
) && !som_is_subspace (section
))
2379 if (som_is_space (section
))
2381 /* Allocate space for the space dictionary. */
2382 amt
= sizeof (struct space_dictionary_record
);
2383 som_section_data (section
)->space_dict
=
2384 (struct space_dictionary_record
*) bfd_zalloc (abfd
, amt
);
2385 if (som_section_data (section
)->space_dict
== NULL
)
2387 /* Set space attributes. Note most attributes of SOM spaces
2388 are set based on the subspaces it contains. */
2389 som_section_data (section
)->space_dict
->loader_fix_index
= -1;
2390 som_section_data (section
)->space_dict
->init_pointer_index
= -1;
2392 /* Set more attributes that were stuffed away in private data. */
2393 som_section_data (section
)->space_dict
->sort_key
=
2394 som_section_data (section
)->copy_data
->sort_key
;
2395 som_section_data (section
)->space_dict
->is_defined
=
2396 som_section_data (section
)->copy_data
->is_defined
;
2397 som_section_data (section
)->space_dict
->is_private
=
2398 som_section_data (section
)->copy_data
->is_private
;
2399 som_section_data (section
)->space_dict
->space_number
=
2400 som_section_data (section
)->copy_data
->space_number
;
2404 /* Allocate space for the subspace dictionary. */
2405 amt
= sizeof (struct subspace_dictionary_record
);
2406 som_section_data (section
)->subspace_dict
=
2407 (struct subspace_dictionary_record
*) bfd_zalloc (abfd
, amt
);
2408 if (som_section_data (section
)->subspace_dict
== NULL
)
2411 /* Set subspace attributes. Basic stuff is done here, additional
2412 attributes are filled in later as more information becomes
2414 if (section
->flags
& SEC_IS_COMMON
)
2416 som_section_data (section
)->subspace_dict
->dup_common
= 1;
2417 som_section_data (section
)->subspace_dict
->is_common
= 1;
2420 if (section
->flags
& SEC_ALLOC
)
2421 som_section_data (section
)->subspace_dict
->is_loadable
= 1;
2423 if (section
->flags
& SEC_CODE
)
2424 som_section_data (section
)->subspace_dict
->code_only
= 1;
2426 som_section_data (section
)->subspace_dict
->subspace_start
=
2428 som_section_data (section
)->subspace_dict
->subspace_length
=
2429 bfd_section_size (abfd
, section
);
2430 som_section_data (section
)->subspace_dict
->initialization_length
=
2431 bfd_section_size (abfd
, section
);
2432 som_section_data (section
)->subspace_dict
->alignment
=
2433 1 << section
->alignment_power
;
2435 /* Set more attributes that were stuffed away in private data. */
2436 som_section_data (section
)->subspace_dict
->sort_key
=
2437 som_section_data (section
)->copy_data
->sort_key
;
2438 som_section_data (section
)->subspace_dict
->access_control_bits
=
2439 som_section_data (section
)->copy_data
->access_control_bits
;
2440 som_section_data (section
)->subspace_dict
->quadrant
=
2441 som_section_data (section
)->copy_data
->quadrant
;
2447 /* Return TRUE if the given section is a SOM space, FALSE otherwise. */
2450 som_is_space (section
)
2453 /* If no copy data is available, then it's neither a space nor a
2455 if (som_section_data (section
)->copy_data
== NULL
)
2458 /* If the containing space isn't the same as the given section,
2459 then this isn't a space. */
2460 if (som_section_data (section
)->copy_data
->container
!= section
2461 && (som_section_data (section
)->copy_data
->container
->output_section
2465 /* OK. Must be a space. */
2469 /* Return TRUE if the given section is a SOM subspace, FALSE otherwise. */
2472 som_is_subspace (section
)
2475 /* If no copy data is available, then it's neither a space nor a
2477 if (som_section_data (section
)->copy_data
== NULL
)
2480 /* If the containing space is the same as the given section,
2481 then this isn't a subspace. */
2482 if (som_section_data (section
)->copy_data
->container
== section
2483 || (som_section_data (section
)->copy_data
->container
->output_section
2487 /* OK. Must be a subspace. */
2491 /* Return TRUE if the given space contains the given subspace. It
2492 is safe to assume space really is a space, and subspace really
2496 som_is_container (space
, subspace
)
2497 asection
*space
, *subspace
;
2499 return (som_section_data (subspace
)->copy_data
->container
== space
2500 || (som_section_data (subspace
)->copy_data
->container
->output_section
2504 /* Count and return the number of spaces attached to the given BFD. */
2506 static unsigned long
2507 som_count_spaces (abfd
)
2513 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2514 count
+= som_is_space (section
);
2519 /* Count the number of subspaces attached to the given BFD. */
2521 static unsigned long
2522 som_count_subspaces (abfd
)
2528 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2529 count
+= som_is_subspace (section
);
2534 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
2536 We desire symbols to be ordered starting with the symbol with the
2537 highest relocation count down to the symbol with the lowest relocation
2538 count. Doing so compacts the relocation stream. */
2541 compare_syms (arg1
, arg2
)
2546 asymbol
**sym1
= (asymbol
**) arg1
;
2547 asymbol
**sym2
= (asymbol
**) arg2
;
2548 unsigned int count1
, count2
;
2550 /* Get relocation count for each symbol. Note that the count
2551 is stored in the udata pointer for section symbols! */
2552 if ((*sym1
)->flags
& BSF_SECTION_SYM
)
2553 count1
= (*sym1
)->udata
.i
;
2555 count1
= som_symbol_data (*sym1
)->reloc_count
;
2557 if ((*sym2
)->flags
& BSF_SECTION_SYM
)
2558 count2
= (*sym2
)->udata
.i
;
2560 count2
= som_symbol_data (*sym2
)->reloc_count
;
2562 /* Return the appropriate value. */
2563 if (count1
< count2
)
2565 else if (count1
> count2
)
2570 /* Return -1, 0, 1 indicating the relative ordering of subspace1
2574 compare_subspaces (arg1
, arg2
)
2579 asection
**subspace1
= (asection
**) arg1
;
2580 asection
**subspace2
= (asection
**) arg2
;
2582 if ((*subspace1
)->target_index
< (*subspace2
)->target_index
)
2584 else if ((*subspace2
)->target_index
< (*subspace1
)->target_index
)
2590 /* Perform various work in preparation for emitting the fixup stream. */
2593 som_prep_for_fixups (abfd
, syms
, num_syms
)
2596 unsigned long num_syms
;
2600 asymbol
**sorted_syms
;
2603 /* Most SOM relocations involving a symbol have a length which is
2604 dependent on the index of the symbol. So symbols which are
2605 used often in relocations should have a small index. */
2607 /* First initialize the counters for each symbol. */
2608 for (i
= 0; i
< num_syms
; i
++)
2610 /* Handle a section symbol; these have no pointers back to the
2611 SOM symbol info. So we just use the udata field to hold the
2612 relocation count. */
2613 if (som_symbol_data (syms
[i
]) == NULL
2614 || syms
[i
]->flags
& BSF_SECTION_SYM
)
2616 syms
[i
]->flags
|= BSF_SECTION_SYM
;
2617 syms
[i
]->udata
.i
= 0;
2620 som_symbol_data (syms
[i
])->reloc_count
= 0;
2623 /* Now that the counters are initialized, make a weighted count
2624 of how often a given symbol is used in a relocation. */
2625 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2629 /* Does this section have any relocations? */
2630 if ((int) section
->reloc_count
<= 0)
2633 /* Walk through each relocation for this section. */
2634 for (j
= 1; j
< (int) section
->reloc_count
; j
++)
2636 arelent
*reloc
= section
->orelocation
[j
];
2639 /* A relocation against a symbol in the *ABS* section really
2640 does not have a symbol. Likewise if the symbol isn't associated
2641 with any section. */
2642 if (reloc
->sym_ptr_ptr
== NULL
2643 || bfd_is_abs_section ((*reloc
->sym_ptr_ptr
)->section
))
2646 /* Scaling to encourage symbols involved in R_DP_RELATIVE
2647 and R_CODE_ONE_SYMBOL relocations to come first. These
2648 two relocations have single byte versions if the symbol
2649 index is very small. */
2650 if (reloc
->howto
->type
== R_DP_RELATIVE
2651 || reloc
->howto
->type
== R_CODE_ONE_SYMBOL
)
2656 /* Handle section symbols by storing the count in the udata
2657 field. It will not be used and the count is very important
2658 for these symbols. */
2659 if ((*reloc
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
)
2661 (*reloc
->sym_ptr_ptr
)->udata
.i
=
2662 (*reloc
->sym_ptr_ptr
)->udata
.i
+ scale
;
2666 /* A normal symbol. Increment the count. */
2667 som_symbol_data (*reloc
->sym_ptr_ptr
)->reloc_count
+= scale
;
2671 /* Sort a copy of the symbol table, rather than the canonical
2672 output symbol table. */
2674 amt
*= sizeof (asymbol
*);
2675 sorted_syms
= (asymbol
**) bfd_zalloc (abfd
, amt
);
2676 memcpy (sorted_syms
, syms
, num_syms
* sizeof (asymbol
*));
2677 qsort (sorted_syms
, num_syms
, sizeof (asymbol
*), compare_syms
);
2678 obj_som_sorted_syms (abfd
) = sorted_syms
;
2680 /* Compute the symbol indexes, they will be needed by the relocation
2682 for (i
= 0; i
< num_syms
; i
++)
2684 /* A section symbol. Again, there is no pointer to backend symbol
2685 information, so we reuse the udata field again. */
2686 if (sorted_syms
[i
]->flags
& BSF_SECTION_SYM
)
2687 sorted_syms
[i
]->udata
.i
= i
;
2689 som_symbol_data (sorted_syms
[i
])->index
= i
;
2694 som_write_fixups (abfd
, current_offset
, total_reloc_sizep
)
2696 unsigned long current_offset
;
2697 unsigned int *total_reloc_sizep
;
2700 /* Chunk of memory that we can use as buffer space, then throw
2702 unsigned char tmp_space
[SOM_TMP_BUFSIZE
];
2704 unsigned int total_reloc_size
= 0;
2705 unsigned int subspace_reloc_size
= 0;
2706 unsigned int num_spaces
= obj_som_file_hdr (abfd
)->space_total
;
2707 asection
*section
= abfd
->sections
;
2710 memset (tmp_space
, 0, SOM_TMP_BUFSIZE
);
2713 /* All the fixups for a particular subspace are emitted in a single
2714 stream. All the subspaces for a particular space are emitted
2717 So, to get all the locations correct one must iterate through all the
2718 spaces, for each space iterate through its subspaces and output a
2720 for (i
= 0; i
< num_spaces
; i
++)
2722 asection
*subsection
;
2725 while (!som_is_space (section
))
2726 section
= section
->next
;
2728 /* Now iterate through each of its subspaces. */
2729 for (subsection
= abfd
->sections
;
2731 subsection
= subsection
->next
)
2734 unsigned int current_rounding_mode
;
2735 #ifndef NO_PCREL_MODES
2736 unsigned int current_call_mode
;
2739 /* Find a subspace of this space. */
2740 if (!som_is_subspace (subsection
)
2741 || !som_is_container (section
, subsection
))
2744 /* If this subspace does not have real data, then we are
2745 finished with it. */
2746 if ((subsection
->flags
& SEC_HAS_CONTENTS
) == 0)
2748 som_section_data (subsection
)->subspace_dict
->fixup_request_index
2753 /* This subspace has some relocations. Put the relocation stream
2754 index into the subspace record. */
2755 som_section_data (subsection
)->subspace_dict
->fixup_request_index
2758 /* To make life easier start over with a clean slate for
2759 each subspace. Seek to the start of the relocation stream
2760 for this subspace in preparation for writing out its fixup
2762 if (bfd_seek (abfd
, current_offset
+ total_reloc_size
, SEEK_SET
) != 0)
2765 /* Buffer space has already been allocated. Just perform some
2766 initialization here. */
2768 subspace_reloc_size
= 0;
2770 som_initialize_reloc_queue (reloc_queue
);
2771 current_rounding_mode
= R_N_MODE
;
2772 #ifndef NO_PCREL_MODES
2773 current_call_mode
= R_SHORT_PCREL_MODE
;
2776 /* Translate each BFD relocation into one or more SOM
2778 for (j
= 0; j
< subsection
->reloc_count
; j
++)
2780 arelent
*bfd_reloc
= subsection
->orelocation
[j
];
2784 /* Get the symbol number. Remember it's stored in a
2785 special place for section symbols. */
2786 if ((*bfd_reloc
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
)
2787 sym_num
= (*bfd_reloc
->sym_ptr_ptr
)->udata
.i
;
2789 sym_num
= som_symbol_data (*bfd_reloc
->sym_ptr_ptr
)->index
;
2791 /* If there is not enough room for the next couple relocations,
2792 then dump the current buffer contents now. Also reinitialize
2793 the relocation queue.
2795 No single BFD relocation could ever translate into more
2796 than 100 bytes of SOM relocations (20bytes is probably the
2797 upper limit, but leave lots of space for growth). */
2798 if (p
- tmp_space
+ 100 > SOM_TMP_BUFSIZE
)
2800 amt
= p
- tmp_space
;
2801 if (bfd_bwrite ((PTR
) tmp_space
, amt
, abfd
) != amt
)
2805 som_initialize_reloc_queue (reloc_queue
);
2808 /* Emit R_NO_RELOCATION fixups to map any bytes which were
2810 skip
= bfd_reloc
->address
- reloc_offset
;
2811 p
= som_reloc_skip (abfd
, skip
, p
,
2812 &subspace_reloc_size
, reloc_queue
);
2814 /* Update reloc_offset for the next iteration.
2816 Many relocations do not consume input bytes. They
2817 are markers, or set state necessary to perform some
2818 later relocation. */
2819 switch (bfd_reloc
->howto
->type
)
2839 #ifndef NO_PCREL_MODES
2840 case R_SHORT_PCREL_MODE
:
2841 case R_LONG_PCREL_MODE
:
2843 reloc_offset
= bfd_reloc
->address
;
2847 reloc_offset
= bfd_reloc
->address
+ 4;
2851 /* Now the actual relocation we care about. */
2852 switch (bfd_reloc
->howto
->type
)
2856 p
= som_reloc_call (abfd
, p
, &subspace_reloc_size
,
2857 bfd_reloc
, sym_num
, reloc_queue
);
2860 case R_CODE_ONE_SYMBOL
:
2862 /* Account for any addend. */
2863 if (bfd_reloc
->addend
)
2864 p
= som_reloc_addend (abfd
, bfd_reloc
->addend
, p
,
2865 &subspace_reloc_size
, reloc_queue
);
2869 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ sym_num
, p
);
2870 subspace_reloc_size
+= 1;
2873 else if (sym_num
< 0x100)
2875 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 32, p
);
2876 bfd_put_8 (abfd
, sym_num
, p
+ 1);
2877 p
= try_prev_fixup (abfd
, &subspace_reloc_size
, p
,
2880 else if (sym_num
< 0x10000000)
2882 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 33, p
);
2883 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 1);
2884 bfd_put_16 (abfd
, (bfd_vma
) sym_num
, p
+ 2);
2885 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2892 case R_DATA_ONE_SYMBOL
:
2896 /* Account for any addend using R_DATA_OVERRIDE. */
2897 if (bfd_reloc
->howto
->type
!= R_DATA_ONE_SYMBOL
2898 && bfd_reloc
->addend
)
2899 p
= som_reloc_addend (abfd
, bfd_reloc
->addend
, p
,
2900 &subspace_reloc_size
, reloc_queue
);
2902 if (sym_num
< 0x100)
2904 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2905 bfd_put_8 (abfd
, sym_num
, p
+ 1);
2906 p
= try_prev_fixup (abfd
, &subspace_reloc_size
, p
,
2909 else if (sym_num
< 0x10000000)
2911 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 1, p
);
2912 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 1);
2913 bfd_put_16 (abfd
, (bfd_vma
) sym_num
, p
+ 2);
2914 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2924 arelent
*tmp_reloc
= NULL
;
2925 bfd_put_8 (abfd
, R_ENTRY
, p
);
2927 /* R_ENTRY relocations have 64 bits of associated
2928 data. Unfortunately the addend field of a bfd
2929 relocation is only 32 bits. So, we split up
2930 the 64bit unwind information and store part in
2931 the R_ENTRY relocation, and the rest in the R_EXIT
2933 bfd_put_32 (abfd
, bfd_reloc
->addend
, p
+ 1);
2935 /* Find the next R_EXIT relocation. */
2936 for (tmp
= j
; tmp
< subsection
->reloc_count
; tmp
++)
2938 tmp_reloc
= subsection
->orelocation
[tmp
];
2939 if (tmp_reloc
->howto
->type
== R_EXIT
)
2943 if (tmp
== subsection
->reloc_count
)
2946 bfd_put_32 (abfd
, tmp_reloc
->addend
, p
+ 5);
2947 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2956 /* If this relocation requests the current rounding
2957 mode, then it is redundant. */
2958 if (bfd_reloc
->howto
->type
!= current_rounding_mode
)
2960 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2961 subspace_reloc_size
+= 1;
2963 current_rounding_mode
= bfd_reloc
->howto
->type
;
2967 #ifndef NO_PCREL_MODES
2968 case R_LONG_PCREL_MODE
:
2969 case R_SHORT_PCREL_MODE
:
2970 if (bfd_reloc
->howto
->type
!= current_call_mode
)
2972 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2973 subspace_reloc_size
+= 1;
2975 current_call_mode
= bfd_reloc
->howto
->type
;
2990 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2991 subspace_reloc_size
+= 1;
2996 /* The end of an exception handling region. The reloc's
2997 addend contains the offset of the exception handling
2999 if (bfd_reloc
->addend
== 0)
3000 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
3001 else if (bfd_reloc
->addend
< 1024)
3003 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 1, p
);
3004 bfd_put_8 (abfd
, bfd_reloc
->addend
/ 4, p
+ 1);
3005 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
3010 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 2, p
);
3011 bfd_put_8 (abfd
, (bfd_reloc
->addend
/ 4) >> 16, p
+ 1);
3012 bfd_put_16 (abfd
, bfd_reloc
->addend
/ 4, p
+ 2);
3013 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
3019 /* The only time we generate R_COMP1, R_COMP2 and
3020 R_CODE_EXPR relocs is for the difference of two
3021 symbols. Hence we can cheat here. */
3022 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
3023 bfd_put_8 (abfd
, 0x44, p
+ 1);
3024 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
3029 /* The only time we generate R_COMP1, R_COMP2 and
3030 R_CODE_EXPR relocs is for the difference of two
3031 symbols. Hence we can cheat here. */
3032 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
3033 bfd_put_8 (abfd
, 0x80, p
+ 1);
3034 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 2);
3035 bfd_put_16 (abfd
, (bfd_vma
) sym_num
, p
+ 3);
3036 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
3042 /* The only time we generate R_COMP1, R_COMP2 and
3043 R_CODE_EXPR relocs is for the difference of two
3044 symbols. Hence we can cheat here. */
3045 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
3046 subspace_reloc_size
+= 1;
3050 /* Put a "R_RESERVED" relocation in the stream if
3051 we hit something we do not understand. The linker
3052 will complain loudly if this ever happens. */
3054 bfd_put_8 (abfd
, 0xff, p
);
3055 subspace_reloc_size
+= 1;
3061 /* Last BFD relocation for a subspace has been processed.
3062 Map the rest of the subspace with R_NO_RELOCATION fixups. */
3063 p
= som_reloc_skip (abfd
, (bfd_section_size (abfd
, subsection
)
3065 p
, &subspace_reloc_size
, reloc_queue
);
3067 /* Scribble out the relocations. */
3068 amt
= p
- tmp_space
;
3069 if (bfd_bwrite ((PTR
) tmp_space
, amt
, abfd
) != amt
)
3073 total_reloc_size
+= subspace_reloc_size
;
3074 som_section_data (subsection
)->subspace_dict
->fixup_request_quantity
3075 = subspace_reloc_size
;
3077 section
= section
->next
;
3079 *total_reloc_sizep
= total_reloc_size
;
3083 /* Write out the space/subspace string table. */
3086 som_write_space_strings (abfd
, current_offset
, string_sizep
)
3088 unsigned long current_offset
;
3089 unsigned int *string_sizep
;
3091 /* Chunk of memory that we can use as buffer space, then throw
3093 size_t tmp_space_size
= SOM_TMP_BUFSIZE
;
3094 unsigned char *tmp_space
= alloca (tmp_space_size
);
3095 unsigned char *p
= tmp_space
;
3096 unsigned int strings_size
= 0;
3100 /* Seek to the start of the space strings in preparation for writing
3102 if (bfd_seek (abfd
, (file_ptr
) current_offset
, SEEK_SET
) != 0)
3105 /* Walk through all the spaces and subspaces (order is not important)
3106 building up and writing string table entries for their names. */
3107 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
3111 /* Only work with space/subspaces; avoid any other sections
3112 which might have been made (.text for example). */
3113 if (!som_is_space (section
) && !som_is_subspace (section
))
3116 /* Get the length of the space/subspace name. */
3117 length
= strlen (section
->name
);
3119 /* If there is not enough room for the next entry, then dump the
3120 current buffer contents now and maybe allocate a larger
3121 buffer. Each entry will take 4 bytes to hold the string
3122 length + the string itself + null terminator. */
3123 if (p
- tmp_space
+ 5 + length
> tmp_space_size
)
3125 /* Flush buffer before refilling or reallocating. */
3126 amt
= p
- tmp_space
;
3127 if (bfd_bwrite ((PTR
) &tmp_space
[0], amt
, abfd
) != amt
)
3130 /* Reallocate if now empty buffer still too small. */
3131 if (5 + length
> tmp_space_size
)
3133 /* Ensure a minimum growth factor to avoid O(n**2) space
3134 consumption for n strings. The optimal minimum
3135 factor seems to be 2, as no other value can guarantee
3136 wasting less than 50% space. (Note that we cannot
3137 deallocate space allocated by `alloca' without
3138 returning from this function.) The same technique is
3139 used a few more times below when a buffer is
3141 tmp_space_size
= MAX (2 * tmp_space_size
, 5 + length
);
3142 tmp_space
= alloca (tmp_space_size
);
3145 /* Reset to beginning of the (possibly new) buffer space. */
3149 /* First element in a string table entry is the length of the
3150 string. Alignment issues are already handled. */
3151 bfd_put_32 (abfd
, (bfd_vma
) length
, p
);
3155 /* Record the index in the space/subspace records. */
3156 if (som_is_space (section
))
3157 som_section_data (section
)->space_dict
->name
.n_strx
= strings_size
;
3159 som_section_data (section
)->subspace_dict
->name
.n_strx
= strings_size
;
3161 /* Next comes the string itself + a null terminator. */
3162 strcpy (p
, section
->name
);
3164 strings_size
+= length
+ 1;
3166 /* Always align up to the next word boundary. */
3167 while (strings_size
% 4)
3169 bfd_put_8 (abfd
, 0, p
);
3175 /* Done with the space/subspace strings. Write out any information
3176 contained in a partial block. */
3177 amt
= p
- tmp_space
;
3178 if (bfd_bwrite ((PTR
) &tmp_space
[0], amt
, abfd
) != amt
)
3180 *string_sizep
= strings_size
;
3184 /* Write out the symbol string table. */
3187 som_write_symbol_strings (abfd
, current_offset
, syms
, num_syms
, string_sizep
,
3190 unsigned long current_offset
;
3192 unsigned int num_syms
;
3193 unsigned int *string_sizep
;
3194 COMPUNIT
*compilation_unit
;
3198 /* Chunk of memory that we can use as buffer space, then throw
3200 size_t tmp_space_size
= SOM_TMP_BUFSIZE
;
3201 unsigned char *tmp_space
= alloca (tmp_space_size
);
3202 unsigned char *p
= tmp_space
;
3204 unsigned int strings_size
= 0;
3205 unsigned char *comp
[4];
3208 /* This gets a bit gruesome because of the compilation unit. The
3209 strings within the compilation unit are part of the symbol
3210 strings, but don't have symbol_dictionary entries. So, manually
3211 write them and update the compilation unit header. On input, the
3212 compilation unit header contains local copies of the strings.
3214 if (compilation_unit
)
3216 comp
[0] = compilation_unit
->name
.n_name
;
3217 comp
[1] = compilation_unit
->language_name
.n_name
;
3218 comp
[2] = compilation_unit
->product_id
.n_name
;
3219 comp
[3] = compilation_unit
->version_id
.n_name
;
3222 /* Seek to the start of the space strings in preparation for writing
3224 if (bfd_seek (abfd
, (file_ptr
) current_offset
, SEEK_SET
) != 0)
3227 if (compilation_unit
)
3229 for (i
= 0; i
< 4; i
++)
3231 size_t length
= strlen (comp
[i
]);
3233 /* If there is not enough room for the next entry, then dump
3234 the current buffer contents now and maybe allocate a
3236 if (p
- tmp_space
+ 5 + length
> tmp_space_size
)
3238 /* Flush buffer before refilling or reallocating. */
3239 amt
= p
- tmp_space
;
3240 if (bfd_bwrite ((PTR
) &tmp_space
[0], amt
, abfd
) != amt
)
3243 /* Reallocate if now empty buffer still too small. */
3244 if (5 + length
> tmp_space_size
)
3246 /* See alloca above for discussion of new size. */
3247 tmp_space_size
= MAX (2 * tmp_space_size
, 5 + length
);
3248 tmp_space
= alloca (tmp_space_size
);
3251 /* Reset to beginning of the (possibly new) buffer
3256 /* First element in a string table entry is the length of
3257 the string. This must always be 4 byte aligned. This is
3258 also an appropriate time to fill in the string index
3259 field in the symbol table entry. */
3260 bfd_put_32 (abfd
, (bfd_vma
) length
, p
);
3264 /* Next comes the string itself + a null terminator. */
3265 strcpy (p
, comp
[i
]);
3270 obj_som_compilation_unit (abfd
)->name
.n_strx
= strings_size
;
3273 obj_som_compilation_unit (abfd
)->language_name
.n_strx
=
3277 obj_som_compilation_unit (abfd
)->product_id
.n_strx
=
3281 obj_som_compilation_unit (abfd
)->version_id
.n_strx
=
3287 strings_size
+= length
+ 1;
3289 /* Always align up to the next word boundary. */
3290 while (strings_size
% 4)
3292 bfd_put_8 (abfd
, 0, p
);
3299 for (i
= 0; i
< num_syms
; i
++)
3301 size_t length
= strlen (syms
[i
]->name
);
3303 /* If there is not enough room for the next entry, then dump the
3304 current buffer contents now and maybe allocate a larger buffer. */
3305 if (p
- tmp_space
+ 5 + length
> tmp_space_size
)
3307 /* Flush buffer before refilling or reallocating. */
3308 amt
= p
- tmp_space
;
3309 if (bfd_bwrite ((PTR
) &tmp_space
[0], amt
, abfd
) != amt
)
3312 /* Reallocate if now empty buffer still too small. */
3313 if (5 + length
> tmp_space_size
)
3315 /* See alloca above for discussion of new size. */
3316 tmp_space_size
= MAX (2 * tmp_space_size
, 5 + length
);
3317 tmp_space
= alloca (tmp_space_size
);
3320 /* Reset to beginning of the (possibly new) buffer space. */
3324 /* First element in a string table entry is the length of the
3325 string. This must always be 4 byte aligned. This is also
3326 an appropriate time to fill in the string index field in the
3327 symbol table entry. */
3328 bfd_put_32 (abfd
, (bfd_vma
) length
, p
);
3332 /* Next comes the string itself + a null terminator. */
3333 strcpy (p
, syms
[i
]->name
);
3335 som_symbol_data (syms
[i
])->stringtab_offset
= strings_size
;
3337 strings_size
+= length
+ 1;
3339 /* Always align up to the next word boundary. */
3340 while (strings_size
% 4)
3342 bfd_put_8 (abfd
, 0, p
);
3348 /* Scribble out any partial block. */
3349 amt
= p
- tmp_space
;
3350 if (bfd_bwrite ((PTR
) &tmp_space
[0], amt
, abfd
) != amt
)
3353 *string_sizep
= strings_size
;
3357 /* Compute variable information to be placed in the SOM headers,
3358 space/subspace dictionaries, relocation streams, etc. Begin
3359 writing parts of the object file. */
3362 som_begin_writing (abfd
)
3365 unsigned long current_offset
= 0;
3366 int strings_size
= 0;
3367 unsigned long num_spaces
, num_subspaces
, i
;
3369 unsigned int total_subspaces
= 0;
3370 struct som_exec_auxhdr
*exec_header
= NULL
;
3372 /* The file header will always be first in an object file,
3373 everything else can be in random locations. To keep things
3374 "simple" BFD will lay out the object file in the manner suggested
3375 by the PRO ABI for PA-RISC Systems. */
3377 /* Before any output can really begin offsets for all the major
3378 portions of the object file must be computed. So, starting
3379 with the initial file header compute (and sometimes write)
3380 each portion of the object file. */
3382 /* Make room for the file header, it's contents are not complete
3383 yet, so it can not be written at this time. */
3384 current_offset
+= sizeof (struct header
);
3386 /* Any auxiliary headers will follow the file header. Right now
3387 we support only the copyright and version headers. */
3388 obj_som_file_hdr (abfd
)->aux_header_location
= current_offset
;
3389 obj_som_file_hdr (abfd
)->aux_header_size
= 0;
3390 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3392 /* Parts of the exec header will be filled in later, so
3393 delay writing the header itself. Fill in the defaults,
3394 and write it later. */
3395 current_offset
+= sizeof (struct som_exec_auxhdr
);
3396 obj_som_file_hdr (abfd
)->aux_header_size
3397 += sizeof (struct som_exec_auxhdr
);
3398 exec_header
= obj_som_exec_hdr (abfd
);
3399 exec_header
->som_auxhdr
.type
= EXEC_AUX_ID
;
3400 exec_header
->som_auxhdr
.length
= 40;
3402 if (obj_som_version_hdr (abfd
) != NULL
)
3406 if (bfd_seek (abfd
, (file_ptr
) current_offset
, SEEK_SET
) != 0)
3409 /* Write the aux_id structure and the string length. */
3410 len
= sizeof (struct aux_id
) + sizeof (unsigned int);
3411 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
3412 current_offset
+= len
;
3413 if (bfd_bwrite ((PTR
) obj_som_version_hdr (abfd
), len
, abfd
) != len
)
3416 /* Write the version string. */
3417 len
= obj_som_version_hdr (abfd
)->header_id
.length
- sizeof (int);
3418 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
3419 current_offset
+= len
;
3420 if (bfd_bwrite ((PTR
) obj_som_version_hdr (abfd
)->user_string
, len
, abfd
)
3425 if (obj_som_copyright_hdr (abfd
) != NULL
)
3429 if (bfd_seek (abfd
, (file_ptr
) current_offset
, SEEK_SET
) != 0)
3432 /* Write the aux_id structure and the string length. */
3433 len
= sizeof (struct aux_id
) + sizeof (unsigned int);
3434 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
3435 current_offset
+= len
;
3436 if (bfd_bwrite ((PTR
) obj_som_copyright_hdr (abfd
), len
, abfd
) != len
)
3439 /* Write the copyright string. */
3440 len
= obj_som_copyright_hdr (abfd
)->header_id
.length
- sizeof (int);
3441 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
3442 current_offset
+= len
;
3443 if (bfd_bwrite ((PTR
) obj_som_copyright_hdr (abfd
)->copyright
, len
, abfd
)
3448 /* Next comes the initialization pointers; we have no initialization
3449 pointers, so current offset does not change. */
3450 obj_som_file_hdr (abfd
)->init_array_location
= current_offset
;
3451 obj_som_file_hdr (abfd
)->init_array_total
= 0;
3453 /* Next are the space records. These are fixed length records.
3455 Count the number of spaces to determine how much room is needed
3456 in the object file for the space records.
3458 The names of the spaces are stored in a separate string table,
3459 and the index for each space into the string table is computed
3460 below. Therefore, it is not possible to write the space headers
3462 num_spaces
= som_count_spaces (abfd
);
3463 obj_som_file_hdr (abfd
)->space_location
= current_offset
;
3464 obj_som_file_hdr (abfd
)->space_total
= num_spaces
;
3465 current_offset
+= num_spaces
* sizeof (struct space_dictionary_record
);
3467 /* Next are the subspace records. These are fixed length records.
3469 Count the number of subspaes to determine how much room is needed
3470 in the object file for the subspace records.
3472 A variety if fields in the subspace record are still unknown at
3473 this time (index into string table, fixup stream location/size, etc). */
3474 num_subspaces
= som_count_subspaces (abfd
);
3475 obj_som_file_hdr (abfd
)->subspace_location
= current_offset
;
3476 obj_som_file_hdr (abfd
)->subspace_total
= num_subspaces
;
3477 current_offset
+= num_subspaces
* sizeof (struct subspace_dictionary_record
);
3479 /* Next is the string table for the space/subspace names. We will
3480 build and write the string table on the fly. At the same time
3481 we will fill in the space/subspace name index fields. */
3483 /* The string table needs to be aligned on a word boundary. */
3484 if (current_offset
% 4)
3485 current_offset
+= (4 - (current_offset
% 4));
3487 /* Mark the offset of the space/subspace string table in the
3489 obj_som_file_hdr (abfd
)->space_strings_location
= current_offset
;
3491 /* Scribble out the space strings. */
3492 if (! som_write_space_strings (abfd
, current_offset
, &strings_size
))
3495 /* Record total string table size in the header and update the
3497 obj_som_file_hdr (abfd
)->space_strings_size
= strings_size
;
3498 current_offset
+= strings_size
;
3500 /* Next is the compilation unit. */
3501 obj_som_file_hdr (abfd
)->compiler_location
= current_offset
;
3502 obj_som_file_hdr (abfd
)->compiler_total
= 0;
3503 if (obj_som_compilation_unit (abfd
))
3505 obj_som_file_hdr (abfd
)->compiler_total
= 1;
3506 current_offset
+= COMPUNITSZ
;
3509 /* Now compute the file positions for the loadable subspaces, taking
3510 care to make sure everything stays properly aligned. */
3512 section
= abfd
->sections
;
3513 for (i
= 0; i
< num_spaces
; i
++)
3515 asection
*subsection
;
3517 unsigned int subspace_offset
= 0;
3520 while (!som_is_space (section
))
3521 section
= section
->next
;
3524 /* Now look for all its subspaces. */
3525 for (subsection
= abfd
->sections
;
3527 subsection
= subsection
->next
)
3530 if (!som_is_subspace (subsection
)
3531 || !som_is_container (section
, subsection
)
3532 || (subsection
->flags
& SEC_ALLOC
) == 0)
3535 /* If this is the first subspace in the space, and we are
3536 building an executable, then take care to make sure all
3537 the alignments are correct and update the exec header. */
3539 && (abfd
->flags
& (EXEC_P
| DYNAMIC
)))
3541 /* Demand paged executables have each space aligned to a
3542 page boundary. Sharable executables (write-protected
3543 text) have just the private (aka data & bss) space aligned
3544 to a page boundary. Ugh. Not true for HPUX.
3546 The HPUX kernel requires the text to always be page aligned
3547 within the file regardless of the executable's type. */
3548 if (abfd
->flags
& (D_PAGED
| DYNAMIC
)
3549 || (subsection
->flags
& SEC_CODE
)
3550 || ((abfd
->flags
& WP_TEXT
)
3551 && (subsection
->flags
& SEC_DATA
)))
3552 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
3554 /* Update the exec header. */
3555 if (subsection
->flags
& SEC_CODE
&& exec_header
->exec_tfile
== 0)
3557 exec_header
->exec_tmem
= section
->vma
;
3558 exec_header
->exec_tfile
= current_offset
;
3560 if (subsection
->flags
& SEC_DATA
&& exec_header
->exec_dfile
== 0)
3562 exec_header
->exec_dmem
= section
->vma
;
3563 exec_header
->exec_dfile
= current_offset
;
3566 /* Keep track of exactly where we are within a particular
3567 space. This is necessary as the braindamaged HPUX
3568 loader will create holes between subspaces *and*
3569 subspace alignments are *NOT* preserved. What a crock. */
3570 subspace_offset
= subsection
->vma
;
3572 /* Only do this for the first subspace within each space. */
3575 else if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3577 /* The braindamaged HPUX loader may have created a hole
3578 between two subspaces. It is *not* sufficient to use
3579 the alignment specifications within the subspaces to
3580 account for these holes -- I've run into at least one
3581 case where the loader left one code subspace unaligned
3582 in a final executable.
3584 To combat this we keep a current offset within each space,
3585 and use the subspace vma fields to detect and preserve
3586 holes. What a crock!
3588 ps. This is not necessary for unloadable space/subspaces. */
3589 current_offset
+= subsection
->vma
- subspace_offset
;
3590 if (subsection
->flags
& SEC_CODE
)
3591 exec_header
->exec_tsize
+= subsection
->vma
- subspace_offset
;
3593 exec_header
->exec_dsize
+= subsection
->vma
- subspace_offset
;
3594 subspace_offset
+= subsection
->vma
- subspace_offset
;
3597 subsection
->target_index
= total_subspaces
++;
3598 /* This is real data to be loaded from the file. */
3599 if (subsection
->flags
& SEC_LOAD
)
3601 /* Update the size of the code & data. */
3602 if (abfd
->flags
& (EXEC_P
| DYNAMIC
)
3603 && subsection
->flags
& SEC_CODE
)
3604 exec_header
->exec_tsize
+= subsection
->_cooked_size
;
3605 else if (abfd
->flags
& (EXEC_P
| DYNAMIC
)
3606 && subsection
->flags
& SEC_DATA
)
3607 exec_header
->exec_dsize
+= subsection
->_cooked_size
;
3608 som_section_data (subsection
)->subspace_dict
->file_loc_init_value
3610 subsection
->filepos
= current_offset
;
3611 current_offset
+= bfd_section_size (abfd
, subsection
);
3612 subspace_offset
+= bfd_section_size (abfd
, subsection
);
3614 /* Looks like uninitialized data. */
3617 /* Update the size of the bss section. */
3618 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3619 exec_header
->exec_bsize
+= subsection
->_cooked_size
;
3621 som_section_data (subsection
)->subspace_dict
->file_loc_init_value
3623 som_section_data (subsection
)->subspace_dict
->
3624 initialization_length
= 0;
3627 /* Goto the next section. */
3628 section
= section
->next
;
3631 /* Finally compute the file positions for unloadable subspaces.
3632 If building an executable, start the unloadable stuff on its
3635 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3636 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
3638 obj_som_file_hdr (abfd
)->unloadable_sp_location
= current_offset
;
3639 section
= abfd
->sections
;
3640 for (i
= 0; i
< num_spaces
; i
++)
3642 asection
*subsection
;
3645 while (!som_is_space (section
))
3646 section
= section
->next
;
3648 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3649 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
3651 /* Now look for all its subspaces. */
3652 for (subsection
= abfd
->sections
;
3654 subsection
= subsection
->next
)
3657 if (!som_is_subspace (subsection
)
3658 || !som_is_container (section
, subsection
)
3659 || (subsection
->flags
& SEC_ALLOC
) != 0)
3662 subsection
->target_index
= total_subspaces
++;
3663 /* This is real data to be loaded from the file. */
3664 if ((subsection
->flags
& SEC_LOAD
) == 0)
3666 som_section_data (subsection
)->subspace_dict
->file_loc_init_value
3668 subsection
->filepos
= current_offset
;
3669 current_offset
+= bfd_section_size (abfd
, subsection
);
3671 /* Looks like uninitialized data. */
3674 som_section_data (subsection
)->subspace_dict
->file_loc_init_value
3676 som_section_data (subsection
)->subspace_dict
->
3677 initialization_length
= bfd_section_size (abfd
, subsection
);
3680 /* Goto the next section. */
3681 section
= section
->next
;
3684 /* If building an executable, then make sure to seek to and write
3685 one byte at the end of the file to make sure any necessary
3686 zeros are filled in. Ugh. */
3687 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3688 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
3689 if (bfd_seek (abfd
, (file_ptr
) current_offset
- 1, SEEK_SET
) != 0)
3691 if (bfd_bwrite ((PTR
) "", (bfd_size_type
) 1, abfd
) != 1)
3694 obj_som_file_hdr (abfd
)->unloadable_sp_size
3695 = current_offset
- obj_som_file_hdr (abfd
)->unloadable_sp_location
;
3697 /* Loader fixups are not supported in any way shape or form. */
3698 obj_som_file_hdr (abfd
)->loader_fixup_location
= 0;
3699 obj_som_file_hdr (abfd
)->loader_fixup_total
= 0;
3701 /* Done. Store the total size of the SOM so far. */
3702 obj_som_file_hdr (abfd
)->som_length
= current_offset
;
3707 /* Finally, scribble out the various headers to the disk. */
3710 som_finish_writing (abfd
)
3713 int num_spaces
= som_count_spaces (abfd
);
3714 asymbol
**syms
= bfd_get_outsymbols (abfd
);
3715 int i
, num_syms
, strings_size
;
3716 int subspace_index
= 0;
3719 unsigned long current_offset
;
3720 unsigned int total_reloc_size
;
3723 /* We must set up the version identifier here as objcopy/strip copy
3724 private BFD data too late for us to handle this in som_begin_writing. */
3725 if (obj_som_exec_data (abfd
)
3726 && obj_som_exec_data (abfd
)->version_id
)
3727 obj_som_file_hdr (abfd
)->version_id
= obj_som_exec_data (abfd
)->version_id
;
3729 obj_som_file_hdr (abfd
)->version_id
= NEW_VERSION_ID
;
3731 /* Next is the symbol table. These are fixed length records.
3733 Count the number of symbols to determine how much room is needed
3734 in the object file for the symbol table.
3736 The names of the symbols are stored in a separate string table,
3737 and the index for each symbol name into the string table is computed
3738 below. Therefore, it is not possible to write the symbol table
3741 These used to be output before the subspace contents, but they
3742 were moved here to work around a stupid bug in the hpux linker
3743 (fixed in hpux10). */
3744 current_offset
= obj_som_file_hdr (abfd
)->som_length
;
3746 /* Make sure we're on a word boundary. */
3747 if (current_offset
% 4)
3748 current_offset
+= (4 - (current_offset
% 4));
3750 num_syms
= bfd_get_symcount (abfd
);
3751 obj_som_file_hdr (abfd
)->symbol_location
= current_offset
;
3752 obj_som_file_hdr (abfd
)->symbol_total
= num_syms
;
3753 current_offset
+= num_syms
* sizeof (struct symbol_dictionary_record
);
3755 /* Next are the symbol strings.
3756 Align them to a word boundary. */
3757 if (current_offset
% 4)
3758 current_offset
+= (4 - (current_offset
% 4));
3759 obj_som_file_hdr (abfd
)->symbol_strings_location
= current_offset
;
3761 /* Scribble out the symbol strings. */
3762 if (! som_write_symbol_strings (abfd
, current_offset
, syms
,
3763 num_syms
, &strings_size
,
3764 obj_som_compilation_unit (abfd
)))
3767 /* Record total string table size in header and update the
3769 obj_som_file_hdr (abfd
)->symbol_strings_size
= strings_size
;
3770 current_offset
+= strings_size
;
3772 /* Do prep work before handling fixups. */
3773 som_prep_for_fixups (abfd
,
3774 bfd_get_outsymbols (abfd
),
3775 bfd_get_symcount (abfd
));
3777 /* At the end of the file is the fixup stream which starts on a
3779 if (current_offset
% 4)
3780 current_offset
+= (4 - (current_offset
% 4));
3781 obj_som_file_hdr (abfd
)->fixup_request_location
= current_offset
;
3783 /* Write the fixups and update fields in subspace headers which
3784 relate to the fixup stream. */
3785 if (! som_write_fixups (abfd
, current_offset
, &total_reloc_size
))
3788 /* Record the total size of the fixup stream in the file header. */
3789 obj_som_file_hdr (abfd
)->fixup_request_total
= total_reloc_size
;
3791 /* Done. Store the total size of the SOM. */
3792 obj_som_file_hdr (abfd
)->som_length
= current_offset
+ total_reloc_size
;
3794 /* Now that the symbol table information is complete, build and
3795 write the symbol table. */
3796 if (! som_build_and_write_symbol_table (abfd
))
3799 /* Subspaces are written first so that we can set up information
3800 about them in their containing spaces as the subspace is written. */
3802 /* Seek to the start of the subspace dictionary records. */
3803 location
= obj_som_file_hdr (abfd
)->subspace_location
;
3804 if (bfd_seek (abfd
, location
, SEEK_SET
) != 0)
3807 section
= abfd
->sections
;
3808 /* Now for each loadable space write out records for its subspaces. */
3809 for (i
= 0; i
< num_spaces
; i
++)
3811 asection
*subsection
;
3814 while (!som_is_space (section
))
3815 section
= section
->next
;
3817 /* Now look for all its subspaces. */
3818 for (subsection
= abfd
->sections
;
3820 subsection
= subsection
->next
)
3823 /* Skip any section which does not correspond to a space
3824 or subspace. Or does not have SEC_ALLOC set (and therefore
3825 has no real bits on the disk). */
3826 if (!som_is_subspace (subsection
)
3827 || !som_is_container (section
, subsection
)
3828 || (subsection
->flags
& SEC_ALLOC
) == 0)
3831 /* If this is the first subspace for this space, then save
3832 the index of the subspace in its containing space. Also
3833 set "is_loadable" in the containing space. */
3835 if (som_section_data (section
)->space_dict
->subspace_quantity
== 0)
3837 som_section_data (section
)->space_dict
->is_loadable
= 1;
3838 som_section_data (section
)->space_dict
->subspace_index
3842 /* Increment the number of subspaces seen and the number of
3843 subspaces contained within the current space. */
3845 som_section_data (section
)->space_dict
->subspace_quantity
++;
3847 /* Mark the index of the current space within the subspace's
3848 dictionary record. */
3849 som_section_data (subsection
)->subspace_dict
->space_index
= i
;
3851 /* Dump the current subspace header. */
3852 amt
= sizeof (struct subspace_dictionary_record
);
3853 if (bfd_bwrite ((PTR
) som_section_data (subsection
)->subspace_dict
,
3857 /* Goto the next section. */
3858 section
= section
->next
;
3861 /* Now repeat the process for unloadable subspaces. */
3862 section
= abfd
->sections
;
3863 /* Now for each space write out records for its subspaces. */
3864 for (i
= 0; i
< num_spaces
; i
++)
3866 asection
*subsection
;
3869 while (!som_is_space (section
))
3870 section
= section
->next
;
3872 /* Now look for all its subspaces. */
3873 for (subsection
= abfd
->sections
;
3875 subsection
= subsection
->next
)
3878 /* Skip any section which does not correspond to a space or
3879 subspace, or which SEC_ALLOC set (and therefore handled
3880 in the loadable spaces/subspaces code above). */
3882 if (!som_is_subspace (subsection
)
3883 || !som_is_container (section
, subsection
)
3884 || (subsection
->flags
& SEC_ALLOC
) != 0)
3887 /* If this is the first subspace for this space, then save
3888 the index of the subspace in its containing space. Clear
3891 if (som_section_data (section
)->space_dict
->subspace_quantity
== 0)
3893 som_section_data (section
)->space_dict
->is_loadable
= 0;
3894 som_section_data (section
)->space_dict
->subspace_index
3898 /* Increment the number of subspaces seen and the number of
3899 subspaces contained within the current space. */
3900 som_section_data (section
)->space_dict
->subspace_quantity
++;
3903 /* Mark the index of the current space within the subspace's
3904 dictionary record. */
3905 som_section_data (subsection
)->subspace_dict
->space_index
= i
;
3907 /* Dump this subspace header. */
3908 amt
= sizeof (struct subspace_dictionary_record
);
3909 if (bfd_bwrite ((PTR
) som_section_data (subsection
)->subspace_dict
,
3913 /* Goto the next section. */
3914 section
= section
->next
;
3917 /* All the subspace dictionary records are written, and all the
3918 fields are set up in the space dictionary records.
3920 Seek to the right location and start writing the space
3921 dictionary records. */
3922 location
= obj_som_file_hdr (abfd
)->space_location
;
3923 if (bfd_seek (abfd
, location
, SEEK_SET
) != 0)
3926 section
= abfd
->sections
;
3927 for (i
= 0; i
< num_spaces
; i
++)
3930 while (!som_is_space (section
))
3931 section
= section
->next
;
3933 /* Dump its header. */
3934 amt
= sizeof (struct space_dictionary_record
);
3935 if (bfd_bwrite ((PTR
) som_section_data (section
)->space_dict
,
3939 /* Goto the next section. */
3940 section
= section
->next
;
3943 /* Write the compilation unit record if there is one. */
3944 if (obj_som_compilation_unit (abfd
))
3946 location
= obj_som_file_hdr (abfd
)->compiler_location
;
3947 if (bfd_seek (abfd
, location
, SEEK_SET
) != 0)
3951 if (bfd_bwrite ((PTR
) obj_som_compilation_unit (abfd
), amt
, abfd
) != amt
)
3955 /* Setting of the system_id has to happen very late now that copying of
3956 BFD private data happens *after* section contents are set. */
3957 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3958 obj_som_file_hdr (abfd
)->system_id
= obj_som_exec_data (abfd
)->system_id
;
3959 else if (bfd_get_mach (abfd
) == pa20
)
3960 obj_som_file_hdr (abfd
)->system_id
= CPU_PA_RISC2_0
;
3961 else if (bfd_get_mach (abfd
) == pa11
)
3962 obj_som_file_hdr (abfd
)->system_id
= CPU_PA_RISC1_1
;
3964 obj_som_file_hdr (abfd
)->system_id
= CPU_PA_RISC1_0
;
3966 /* Compute the checksum for the file header just before writing
3967 the header to disk. */
3968 obj_som_file_hdr (abfd
)->checksum
= som_compute_checksum (abfd
);
3970 /* Only thing left to do is write out the file header. It is always
3971 at location zero. Seek there and write it. */
3972 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3974 amt
= sizeof (struct header
);
3975 if (bfd_bwrite ((PTR
) obj_som_file_hdr (abfd
), amt
, abfd
) != amt
)
3978 /* Now write the exec header. */
3979 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3981 long tmp
, som_length
;
3982 struct som_exec_auxhdr
*exec_header
;
3984 exec_header
= obj_som_exec_hdr (abfd
);
3985 exec_header
->exec_entry
= bfd_get_start_address (abfd
);
3986 exec_header
->exec_flags
= obj_som_exec_data (abfd
)->exec_flags
;
3988 /* Oh joys. Ram some of the BSS data into the DATA section
3989 to be compatible with how the hp linker makes objects
3990 (saves memory space). */
3991 tmp
= exec_header
->exec_dsize
;
3992 tmp
= SOM_ALIGN (tmp
, PA_PAGESIZE
);
3993 exec_header
->exec_bsize
-= (tmp
- exec_header
->exec_dsize
);
3994 if (exec_header
->exec_bsize
< 0)
3995 exec_header
->exec_bsize
= 0;
3996 exec_header
->exec_dsize
= tmp
;
3998 /* Now perform some sanity checks. The idea is to catch bogons now and
3999 inform the user, instead of silently generating a bogus file. */
4000 som_length
= obj_som_file_hdr (abfd
)->som_length
;
4001 if (exec_header
->exec_tfile
+ exec_header
->exec_tsize
> som_length
4002 || exec_header
->exec_dfile
+ exec_header
->exec_dsize
> som_length
)
4004 bfd_set_error (bfd_error_bad_value
);
4008 if (bfd_seek (abfd
, obj_som_file_hdr (abfd
)->aux_header_location
,
4013 if (bfd_bwrite ((PTR
) exec_header
, amt
, abfd
) != amt
)
4019 /* Compute and return the checksum for a SOM file header. */
4021 static unsigned long
4022 som_compute_checksum (abfd
)
4025 unsigned long checksum
, count
, i
;
4026 unsigned long *buffer
= (unsigned long *) obj_som_file_hdr (abfd
);
4029 count
= sizeof (struct header
) / sizeof (unsigned long);
4030 for (i
= 0; i
< count
; i
++)
4031 checksum
^= *(buffer
+ i
);
4037 som_bfd_derive_misc_symbol_info (abfd
, sym
, info
)
4038 bfd
*abfd ATTRIBUTE_UNUSED
;
4040 struct som_misc_symbol_info
*info
;
4043 memset (info
, 0, sizeof (struct som_misc_symbol_info
));
4045 /* The HP SOM linker requires detailed type information about
4046 all symbols (including undefined symbols!). Unfortunately,
4047 the type specified in an import/export statement does not
4048 always match what the linker wants. Severe braindamage. */
4050 /* Section symbols will not have a SOM symbol type assigned to
4051 them yet. Assign all section symbols type ST_DATA. */
4052 if (sym
->flags
& BSF_SECTION_SYM
)
4053 info
->symbol_type
= ST_DATA
;
4056 /* Common symbols must have scope SS_UNSAT and type
4057 ST_STORAGE or the linker will choke. */
4058 if (bfd_is_com_section (sym
->section
))
4060 info
->symbol_scope
= SS_UNSAT
;
4061 info
->symbol_type
= ST_STORAGE
;
4064 /* It is possible to have a symbol without an associated
4065 type. This happens if the user imported the symbol
4066 without a type and the symbol was never defined
4067 locally. If BSF_FUNCTION is set for this symbol, then
4068 assign it type ST_CODE (the HP linker requires undefined
4069 external functions to have type ST_CODE rather than ST_ENTRY). */
4070 else if ((som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
4071 || som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
)
4072 && bfd_is_und_section (sym
->section
)
4073 && sym
->flags
& BSF_FUNCTION
)
4074 info
->symbol_type
= ST_CODE
;
4076 /* Handle function symbols which were defined in this file.
4077 They should have type ST_ENTRY. Also retrieve the argument
4078 relocation bits from the SOM backend information. */
4079 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_ENTRY
4080 || (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
4081 && (sym
->flags
& BSF_FUNCTION
))
4082 || (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
4083 && (sym
->flags
& BSF_FUNCTION
)))
4085 info
->symbol_type
= ST_ENTRY
;
4086 info
->arg_reloc
= som_symbol_data (sym
)->tc_data
.ap
.hppa_arg_reloc
;
4087 info
->priv_level
= som_symbol_data (sym
)->tc_data
.ap
.hppa_priv_level
;
4090 /* For unknown symbols set the symbol's type based on the symbol's
4091 section (ST_DATA for DATA sections, ST_CODE for CODE sections). */
4092 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
)
4094 if (sym
->section
->flags
& SEC_CODE
)
4095 info
->symbol_type
= ST_CODE
;
4097 info
->symbol_type
= ST_DATA
;
4100 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
)
4101 info
->symbol_type
= ST_DATA
;
4103 /* From now on it's a very simple mapping. */
4104 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_ABSOLUTE
)
4105 info
->symbol_type
= ST_ABSOLUTE
;
4106 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
)
4107 info
->symbol_type
= ST_CODE
;
4108 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_DATA
)
4109 info
->symbol_type
= ST_DATA
;
4110 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_MILLICODE
)
4111 info
->symbol_type
= ST_MILLICODE
;
4112 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_PLABEL
)
4113 info
->symbol_type
= ST_PLABEL
;
4114 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_PRI_PROG
)
4115 info
->symbol_type
= ST_PRI_PROG
;
4116 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_SEC_PROG
)
4117 info
->symbol_type
= ST_SEC_PROG
;
4120 /* Now handle the symbol's scope. Exported data which is not
4121 in the common section has scope SS_UNIVERSAL. Note scope
4122 of common symbols was handled earlier! */
4123 if (bfd_is_und_section (sym
->section
))
4124 info
->symbol_scope
= SS_UNSAT
;
4125 else if (sym
->flags
& (BSF_EXPORT
| BSF_WEAK
)
4126 && ! bfd_is_com_section (sym
->section
))
4127 info
->symbol_scope
= SS_UNIVERSAL
;
4128 /* Anything else which is not in the common section has scope
4130 else if (! bfd_is_com_section (sym
->section
))
4131 info
->symbol_scope
= SS_LOCAL
;
4133 /* Now set the symbol_info field. It has no real meaning
4134 for undefined or common symbols, but the HP linker will
4135 choke if it's not set to some "reasonable" value. We
4136 use zero as a reasonable value. */
4137 if (bfd_is_com_section (sym
->section
)
4138 || bfd_is_und_section (sym
->section
)
4139 || bfd_is_abs_section (sym
->section
))
4140 info
->symbol_info
= 0;
4141 /* For all other symbols, the symbol_info field contains the
4142 subspace index of the space this symbol is contained in. */
4144 info
->symbol_info
= sym
->section
->target_index
;
4146 /* Set the symbol's value. */
4147 info
->symbol_value
= sym
->value
+ sym
->section
->vma
;
4149 /* The secondary_def field is for weak symbols. */
4150 if (sym
->flags
& BSF_WEAK
)
4151 info
->secondary_def
= TRUE
;
4153 info
->secondary_def
= FALSE
;
4157 /* Build and write, in one big chunk, the entire symbol table for
4161 som_build_and_write_symbol_table (abfd
)
4164 unsigned int num_syms
= bfd_get_symcount (abfd
);
4165 file_ptr symtab_location
= obj_som_file_hdr (abfd
)->symbol_location
;
4166 asymbol
**bfd_syms
= obj_som_sorted_syms (abfd
);
4167 struct symbol_dictionary_record
*som_symtab
= NULL
;
4169 bfd_size_type symtab_size
;
4171 /* Compute total symbol table size and allocate a chunk of memory
4172 to hold the symbol table as we build it. */
4173 symtab_size
= num_syms
;
4174 symtab_size
*= sizeof (struct symbol_dictionary_record
);
4175 som_symtab
= (struct symbol_dictionary_record
*) bfd_zmalloc (symtab_size
);
4176 if (som_symtab
== NULL
&& symtab_size
!= 0)
4179 /* Walk over each symbol. */
4180 for (i
= 0; i
< num_syms
; i
++)
4182 struct som_misc_symbol_info info
;
4184 /* This is really an index into the symbol strings table.
4185 By the time we get here, the index has already been
4186 computed and stored into the name field in the BFD symbol. */
4187 som_symtab
[i
].name
.n_strx
= som_symbol_data(bfd_syms
[i
])->stringtab_offset
;
4189 /* Derive SOM information from the BFD symbol. */
4190 som_bfd_derive_misc_symbol_info (abfd
, bfd_syms
[i
], &info
);
4193 som_symtab
[i
].symbol_type
= info
.symbol_type
;
4194 som_symtab
[i
].symbol_scope
= info
.symbol_scope
;
4195 som_symtab
[i
].arg_reloc
= info
.arg_reloc
;
4196 som_symtab
[i
].symbol_info
= info
.symbol_info
;
4197 som_symtab
[i
].xleast
= 3;
4198 som_symtab
[i
].symbol_value
= info
.symbol_value
| info
.priv_level
;
4199 som_symtab
[i
].secondary_def
= info
.secondary_def
;
4202 /* Everything is ready, seek to the right location and
4203 scribble out the symbol table. */
4204 if (bfd_seek (abfd
, symtab_location
, SEEK_SET
) != 0)
4207 if (bfd_bwrite ((PTR
) som_symtab
, symtab_size
, abfd
) != symtab_size
)
4210 if (som_symtab
!= NULL
)
4214 if (som_symtab
!= NULL
)
4219 /* Write an object in SOM format. */
4222 som_write_object_contents (abfd
)
4225 if (! abfd
->output_has_begun
)
4227 /* Set up fixed parts of the file, space, and subspace headers.
4228 Notify the world that output has begun. */
4229 som_prep_headers (abfd
);
4230 abfd
->output_has_begun
= TRUE
;
4231 /* Start writing the object file. This include all the string
4232 tables, fixup streams, and other portions of the object file. */
4233 som_begin_writing (abfd
);
4236 return (som_finish_writing (abfd
));
4239 /* Read and save the string table associated with the given BFD. */
4242 som_slurp_string_table (abfd
)
4248 /* Use the saved version if its available. */
4249 if (obj_som_stringtab (abfd
) != NULL
)
4252 /* I don't think this can currently happen, and I'm not sure it should
4253 really be an error, but it's better than getting unpredictable results
4254 from the host's malloc when passed a size of zero. */
4255 if (obj_som_stringtab_size (abfd
) == 0)
4257 bfd_set_error (bfd_error_no_symbols
);
4261 /* Allocate and read in the string table. */
4262 amt
= obj_som_stringtab_size (abfd
);
4263 stringtab
= bfd_zmalloc (amt
);
4264 if (stringtab
== NULL
)
4267 if (bfd_seek (abfd
, obj_som_str_filepos (abfd
), SEEK_SET
) != 0)
4270 if (bfd_bread (stringtab
, amt
, abfd
) != amt
)
4273 /* Save our results and return success. */
4274 obj_som_stringtab (abfd
) = stringtab
;
4278 /* Return the amount of data (in bytes) required to hold the symbol
4279 table for this object. */
4282 som_get_symtab_upper_bound (abfd
)
4285 if (!som_slurp_symbol_table (abfd
))
4288 return (bfd_get_symcount (abfd
) + 1) * (sizeof (asymbol
*));
4291 /* Convert from a SOM subspace index to a BFD section. */
4294 bfd_section_from_som_symbol (abfd
, symbol
)
4296 struct symbol_dictionary_record
*symbol
;
4300 /* The meaning of the symbol_info field changes for functions
4301 within executables. So only use the quick symbol_info mapping for
4302 incomplete objects and non-function symbols in executables. */
4303 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
4304 || (symbol
->symbol_type
!= ST_ENTRY
4305 && symbol
->symbol_type
!= ST_PRI_PROG
4306 && symbol
->symbol_type
!= ST_SEC_PROG
4307 && symbol
->symbol_type
!= ST_MILLICODE
))
4309 int index
= symbol
->symbol_info
;
4310 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
4311 if (section
->target_index
== index
&& som_is_subspace (section
))
4314 /* Could be a symbol from an external library (such as an OMOS
4315 shared library). Don't abort. */
4316 return bfd_abs_section_ptr
;
4321 unsigned int value
= symbol
->symbol_value
;
4323 /* For executables we will have to use the symbol's address and
4324 find out what section would contain that address. Yuk. */
4325 for (section
= abfd
->sections
; section
; section
= section
->next
)
4327 if (value
>= section
->vma
4328 && value
<= section
->vma
+ section
->_cooked_size
4329 && som_is_subspace (section
))
4333 /* Could be a symbol from an external library (such as an OMOS
4334 shared library). Don't abort. */
4335 return bfd_abs_section_ptr
;
4340 /* Read and save the symbol table associated with the given BFD. */
4343 som_slurp_symbol_table (abfd
)
4346 int symbol_count
= bfd_get_symcount (abfd
);
4347 int symsize
= sizeof (struct symbol_dictionary_record
);
4349 struct symbol_dictionary_record
*buf
= NULL
, *bufp
, *endbufp
;
4350 som_symbol_type
*sym
, *symbase
;
4353 /* Return saved value if it exists. */
4354 if (obj_som_symtab (abfd
) != NULL
)
4355 goto successful_return
;
4357 /* Special case. This is *not* an error. */
4358 if (symbol_count
== 0)
4359 goto successful_return
;
4361 if (!som_slurp_string_table (abfd
))
4364 stringtab
= obj_som_stringtab (abfd
);
4367 amt
*= sizeof (som_symbol_type
);
4368 symbase
= (som_symbol_type
*) bfd_zmalloc (amt
);
4369 if (symbase
== NULL
)
4372 /* Read in the external SOM representation. */
4375 buf
= bfd_malloc (amt
);
4376 if (buf
== NULL
&& amt
!= 0)
4378 if (bfd_seek (abfd
, obj_som_sym_filepos (abfd
), SEEK_SET
) != 0)
4380 if (bfd_bread (buf
, amt
, abfd
) != amt
)
4383 /* Iterate over all the symbols and internalize them. */
4384 endbufp
= buf
+ symbol_count
;
4385 for (bufp
= buf
, sym
= symbase
; bufp
< endbufp
; ++bufp
)
4388 /* I don't think we care about these. */
4389 if (bufp
->symbol_type
== ST_SYM_EXT
4390 || bufp
->symbol_type
== ST_ARG_EXT
)
4393 /* Set some private data we care about. */
4394 if (bufp
->symbol_type
== ST_NULL
)
4395 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_UNKNOWN
;
4396 else if (bufp
->symbol_type
== ST_ABSOLUTE
)
4397 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_ABSOLUTE
;
4398 else if (bufp
->symbol_type
== ST_DATA
)
4399 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_DATA
;
4400 else if (bufp
->symbol_type
== ST_CODE
)
4401 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_CODE
;
4402 else if (bufp
->symbol_type
== ST_PRI_PROG
)
4403 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_PRI_PROG
;
4404 else if (bufp
->symbol_type
== ST_SEC_PROG
)
4405 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_SEC_PROG
;
4406 else if (bufp
->symbol_type
== ST_ENTRY
)
4407 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_ENTRY
;
4408 else if (bufp
->symbol_type
== ST_MILLICODE
)
4409 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_MILLICODE
;
4410 else if (bufp
->symbol_type
== ST_PLABEL
)
4411 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_PLABEL
;
4413 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_UNKNOWN
;
4414 som_symbol_data (sym
)->tc_data
.ap
.hppa_arg_reloc
= bufp
->arg_reloc
;
4416 /* Some reasonable defaults. */
4417 sym
->symbol
.the_bfd
= abfd
;
4418 sym
->symbol
.name
= bufp
->name
.n_strx
+ stringtab
;
4419 sym
->symbol
.value
= bufp
->symbol_value
;
4420 sym
->symbol
.section
= 0;
4421 sym
->symbol
.flags
= 0;
4423 switch (bufp
->symbol_type
)
4427 sym
->symbol
.flags
|= BSF_FUNCTION
;
4428 som_symbol_data (sym
)->tc_data
.ap
.hppa_priv_level
=
4429 sym
->symbol
.value
& 0x3;
4430 sym
->symbol
.value
&= ~0x3;
4437 som_symbol_data (sym
)->tc_data
.ap
.hppa_priv_level
=
4438 sym
->symbol
.value
& 0x3;
4439 sym
->symbol
.value
&= ~0x3;
4440 /* If the symbol's scope is SS_UNSAT, then these are
4441 undefined function symbols. */
4442 if (bufp
->symbol_scope
== SS_UNSAT
)
4443 sym
->symbol
.flags
|= BSF_FUNCTION
;
4449 /* Handle scoping and section information. */
4450 switch (bufp
->symbol_scope
)
4452 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
4453 so the section associated with this symbol can't be known. */
4455 if (bufp
->symbol_type
!= ST_STORAGE
)
4456 sym
->symbol
.section
= bfd_und_section_ptr
;
4458 sym
->symbol
.section
= bfd_com_section_ptr
;
4459 sym
->symbol
.flags
|= (BSF_EXPORT
| BSF_GLOBAL
);
4463 if (bufp
->symbol_type
!= ST_STORAGE
)
4464 sym
->symbol
.section
= bfd_und_section_ptr
;
4466 sym
->symbol
.section
= bfd_com_section_ptr
;
4470 sym
->symbol
.flags
|= (BSF_EXPORT
| BSF_GLOBAL
);
4471 sym
->symbol
.section
= bfd_section_from_som_symbol (abfd
, bufp
);
4472 sym
->symbol
.value
-= sym
->symbol
.section
->vma
;
4476 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
4477 Sound dumb? It is. */
4481 sym
->symbol
.flags
|= BSF_LOCAL
;
4482 sym
->symbol
.section
= bfd_section_from_som_symbol (abfd
, bufp
);
4483 sym
->symbol
.value
-= sym
->symbol
.section
->vma
;
4487 /* Check for a weak symbol. */
4488 if (bufp
->secondary_def
)
4489 sym
->symbol
.flags
|= BSF_WEAK
;
4491 /* Mark section symbols and symbols used by the debugger.
4492 Note $START$ is a magic code symbol, NOT a section symbol. */
4493 if (sym
->symbol
.name
[0] == '$'
4494 && sym
->symbol
.name
[strlen (sym
->symbol
.name
) - 1] == '$'
4495 && !strcmp (sym
->symbol
.name
, sym
->symbol
.section
->name
))
4496 sym
->symbol
.flags
|= BSF_SECTION_SYM
;
4497 else if (!strncmp (sym
->symbol
.name
, "L$0\002", 4))
4499 sym
->symbol
.flags
|= BSF_SECTION_SYM
;
4500 sym
->symbol
.name
= sym
->symbol
.section
->name
;
4502 else if (!strncmp (sym
->symbol
.name
, "L$0\001", 4))
4503 sym
->symbol
.flags
|= BSF_DEBUGGING
;
4505 /* Note increment at bottom of loop, since we skip some symbols
4506 we can not include it as part of the for statement. */
4510 /* We modify the symbol count to record the number of BFD symbols we
4512 bfd_get_symcount (abfd
) = sym
- symbase
;
4514 /* Save our results and return success. */
4515 obj_som_symtab (abfd
) = symbase
;
4527 /* Canonicalize a SOM symbol table. Return the number of entries
4528 in the symbol table. */
4531 som_canonicalize_symtab (abfd
, location
)
4536 som_symbol_type
*symbase
;
4538 if (!som_slurp_symbol_table (abfd
))
4541 i
= bfd_get_symcount (abfd
);
4542 symbase
= obj_som_symtab (abfd
);
4544 for (; i
> 0; i
--, location
++, symbase
++)
4545 *location
= &symbase
->symbol
;
4547 /* Final null pointer. */
4549 return (bfd_get_symcount (abfd
));
4552 /* Make a SOM symbol. There is nothing special to do here. */
4555 som_make_empty_symbol (abfd
)
4558 bfd_size_type amt
= sizeof (som_symbol_type
);
4559 som_symbol_type
*new = (som_symbol_type
*) bfd_zalloc (abfd
, amt
);
4562 new->symbol
.the_bfd
= abfd
;
4564 return &new->symbol
;
4567 /* Print symbol information. */
4570 som_print_symbol (abfd
, afile
, symbol
, how
)
4574 bfd_print_symbol_type how
;
4576 FILE *file
= (FILE *) afile
;
4579 case bfd_print_symbol_name
:
4580 fprintf (file
, "%s", symbol
->name
);
4582 case bfd_print_symbol_more
:
4583 fprintf (file
, "som ");
4584 fprintf_vma (file
, symbol
->value
);
4585 fprintf (file
, " %lx", (long) symbol
->flags
);
4587 case bfd_print_symbol_all
:
4589 const char *section_name
;
4590 section_name
= symbol
->section
? symbol
->section
->name
: "(*none*)";
4591 bfd_print_symbol_vandf (abfd
, (PTR
) file
, symbol
);
4592 fprintf (file
, " %s\t%s", section_name
, symbol
->name
);
4599 som_bfd_is_local_label_name (abfd
, name
)
4600 bfd
*abfd ATTRIBUTE_UNUSED
;
4603 return (name
[0] == 'L' && name
[1] == '$');
4606 /* Count or process variable-length SOM fixup records.
4608 To avoid code duplication we use this code both to compute the number
4609 of relocations requested by a stream, and to internalize the stream.
4611 When computing the number of relocations requested by a stream the
4612 variables rptr, section, and symbols have no meaning.
4614 Return the number of relocations requested by the fixup stream. When
4617 This needs at least two or three more passes to get it cleaned up. */
4620 som_set_reloc_info (fixup
, end
, internal_relocs
, section
, symbols
, just_count
)
4621 unsigned char *fixup
;
4623 arelent
*internal_relocs
;
4626 bfd_boolean just_count
;
4628 unsigned int op
, varname
, deallocate_contents
= 0;
4629 unsigned char *end_fixups
= &fixup
[end
];
4630 const struct fixup_format
*fp
;
4632 unsigned char *save_fixup
;
4633 int variables
[26], stack
[20], c
, v
, count
, prev_fixup
, *sp
, saved_unwind_bits
;
4635 arelent
*rptr
= internal_relocs
;
4636 unsigned int offset
= 0;
4638 #define var(c) variables[(c) - 'A']
4639 #define push(v) (*sp++ = (v))
4640 #define pop() (*--sp)
4641 #define emptystack() (sp == stack)
4643 som_initialize_reloc_queue (reloc_queue
);
4644 memset (variables
, 0, sizeof (variables
));
4645 memset (stack
, 0, sizeof (stack
));
4648 saved_unwind_bits
= 0;
4651 while (fixup
< end_fixups
)
4654 /* Save pointer to the start of this fixup. We'll use
4655 it later to determine if it is necessary to put this fixup
4659 /* Get the fixup code and its associated format. */
4661 fp
= &som_fixup_formats
[op
];
4663 /* Handle a request for a previous fixup. */
4664 if (*fp
->format
== 'P')
4666 /* Get pointer to the beginning of the prev fixup, move
4667 the repeated fixup to the head of the queue. */
4668 fixup
= reloc_queue
[fp
->D
].reloc
;
4669 som_reloc_queue_fix (reloc_queue
, fp
->D
);
4672 /* Get the fixup code and its associated format. */
4674 fp
= &som_fixup_formats
[op
];
4677 /* If this fixup will be passed to BFD, set some reasonable defaults. */
4679 && som_hppa_howto_table
[op
].type
!= R_NO_RELOCATION
4680 && som_hppa_howto_table
[op
].type
!= R_DATA_OVERRIDE
)
4682 rptr
->address
= offset
;
4683 rptr
->howto
= &som_hppa_howto_table
[op
];
4685 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
4688 /* Set default input length to 0. Get the opcode class index
4692 var ('U') = saved_unwind_bits
;
4694 /* Get the opcode format. */
4697 /* Process the format string. Parsing happens in two phases,
4698 parse RHS, then assign to LHS. Repeat until no more
4699 characters in the format string. */
4702 /* The variable this pass is going to compute a value for. */
4705 /* Start processing RHS. Continue until a NULL or '=' is found. */
4710 /* If this is a variable, push it on the stack. */
4714 /* If this is a lower case letter, then it represents
4715 additional data from the fixup stream to be pushed onto
4717 else if (ISLOWER (c
))
4719 int bits
= (c
- 'a') * 8;
4720 for (v
= 0; c
> 'a'; --c
)
4721 v
= (v
<< 8) | *fixup
++;
4723 v
= sign_extend (v
, bits
);
4727 /* A decimal constant. Push it on the stack. */
4728 else if (ISDIGIT (c
))
4731 while (ISDIGIT (*cp
))
4732 v
= (v
* 10) + (*cp
++ - '0');
4736 /* An operator. Pop two two values from the stack and
4737 use them as operands to the given operation. Push
4738 the result of the operation back on the stack. */
4760 while (*cp
&& *cp
!= '=');
4762 /* Move over the equal operator. */
4765 /* Pop the RHS off the stack. */
4768 /* Perform the assignment. */
4771 /* Handle side effects. and special 'O' stack cases. */
4774 /* Consume some bytes from the input space. */
4778 /* A symbol to use in the relocation. Make a note
4779 of this if we are not just counting. */
4782 rptr
->sym_ptr_ptr
= &symbols
[c
];
4784 /* Argument relocation bits for a function call. */
4788 unsigned int tmp
= var ('R');
4791 if ((som_hppa_howto_table
[op
].type
== R_PCREL_CALL
4792 && R_PCREL_CALL
+ 10 > op
)
4793 || (som_hppa_howto_table
[op
].type
== R_ABS_CALL
4794 && R_ABS_CALL
+ 10 > op
))
4796 /* Simple encoding. */
4803 rptr
->addend
|= 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2;
4805 rptr
->addend
|= 1 << 8 | 1 << 6 | 1 << 4;
4807 rptr
->addend
|= 1 << 8 | 1 << 6;
4809 rptr
->addend
|= 1 << 8;
4813 unsigned int tmp1
, tmp2
;
4815 /* First part is easy -- low order two bits are
4816 directly copied, then shifted away. */
4817 rptr
->addend
= tmp
& 0x3;
4820 /* Diving the result by 10 gives us the second
4821 part. If it is 9, then the first two words
4822 are a double precision paramater, else it is
4823 3 * the first arg bits + the 2nd arg bits. */
4827 rptr
->addend
+= (0xe << 6);
4830 /* Get the two pieces. */
4833 /* Put them in the addend. */
4834 rptr
->addend
+= (tmp2
<< 8) + (tmp1
<< 6);
4837 /* What's left is the third part. It's unpacked
4838 just like the second. */
4840 rptr
->addend
+= (0xe << 2);
4845 rptr
->addend
+= (tmp2
<< 4) + (tmp
<< 2);
4848 rptr
->addend
= HPPA_R_ADDEND (rptr
->addend
, 0);
4851 /* Handle the linker expression stack. */
4856 subop
= comp1_opcodes
;
4859 subop
= comp2_opcodes
;
4862 subop
= comp3_opcodes
;
4867 while (*subop
<= (unsigned char) c
)
4871 /* The lower 32unwind bits must be persistent. */
4873 saved_unwind_bits
= var ('U');
4881 /* If we used a previous fixup, clean up after it. */
4884 fixup
= save_fixup
+ 1;
4888 else if (fixup
> save_fixup
+ 1)
4889 som_reloc_queue_insert (save_fixup
, fixup
- save_fixup
, reloc_queue
);
4891 /* We do not pass R_DATA_OVERRIDE or R_NO_RELOCATION
4893 if (som_hppa_howto_table
[op
].type
!= R_DATA_OVERRIDE
4894 && som_hppa_howto_table
[op
].type
!= R_NO_RELOCATION
)
4896 /* Done with a single reloction. Loop back to the top. */
4899 if (som_hppa_howto_table
[op
].type
== R_ENTRY
)
4900 rptr
->addend
= var ('T');
4901 else if (som_hppa_howto_table
[op
].type
== R_EXIT
)
4902 rptr
->addend
= var ('U');
4903 else if (som_hppa_howto_table
[op
].type
== R_PCREL_CALL
4904 || som_hppa_howto_table
[op
].type
== R_ABS_CALL
)
4906 else if (som_hppa_howto_table
[op
].type
== R_DATA_ONE_SYMBOL
)
4908 /* Try what was specified in R_DATA_OVERRIDE first
4909 (if anything). Then the hard way using the
4910 section contents. */
4911 rptr
->addend
= var ('V');
4913 if (rptr
->addend
== 0 && !section
->contents
)
4915 /* Got to read the damn contents first. We don't
4916 bother saving the contents (yet). Add it one
4917 day if the need arises. */
4918 section
->contents
= bfd_malloc (section
->_raw_size
);
4919 if (section
->contents
== NULL
)
4920 return (unsigned) -1;
4922 deallocate_contents
= 1;
4923 bfd_get_section_contents (section
->owner
,
4927 section
->_raw_size
);
4929 else if (rptr
->addend
== 0)
4930 rptr
->addend
= bfd_get_32 (section
->owner
,
4932 + offset
- var ('L')));
4936 rptr
->addend
= var ('V');
4940 /* Now that we've handled a "full" relocation, reset
4942 memset (variables
, 0, sizeof (variables
));
4943 memset (stack
, 0, sizeof (stack
));
4946 if (deallocate_contents
)
4947 free (section
->contents
);
4957 /* Read in the relocs (aka fixups in SOM terms) for a section.
4959 som_get_reloc_upper_bound calls this routine with JUST_COUNT
4960 set to TRUE to indicate it only needs a count of the number
4961 of actual relocations. */
4964 som_slurp_reloc_table (abfd
, section
, symbols
, just_count
)
4968 bfd_boolean just_count
;
4970 char *external_relocs
;
4971 unsigned int fixup_stream_size
;
4972 arelent
*internal_relocs
;
4973 unsigned int num_relocs
;
4976 fixup_stream_size
= som_section_data (section
)->reloc_size
;
4977 /* If there were no relocations, then there is nothing to do. */
4978 if (section
->reloc_count
== 0)
4981 /* If reloc_count is -1, then the relocation stream has not been
4982 parsed. We must do so now to know how many relocations exist. */
4983 if (section
->reloc_count
== (unsigned) -1)
4985 amt
= fixup_stream_size
;
4986 external_relocs
= (char *) bfd_malloc (amt
);
4987 if (external_relocs
== (char *) NULL
)
4989 /* Read in the external forms. */
4991 obj_som_reloc_filepos (abfd
) + section
->rel_filepos
,
4995 if (bfd_bread (external_relocs
, amt
, abfd
) != amt
)
4998 /* Let callers know how many relocations found.
4999 also save the relocation stream as we will
5001 section
->reloc_count
= som_set_reloc_info (external_relocs
,
5003 NULL
, NULL
, NULL
, TRUE
);
5005 som_section_data (section
)->reloc_stream
= external_relocs
;
5008 /* If the caller only wanted a count, then return now. */
5012 num_relocs
= section
->reloc_count
;
5013 external_relocs
= som_section_data (section
)->reloc_stream
;
5014 /* Return saved information about the relocations if it is available. */
5015 if (section
->relocation
!= (arelent
*) NULL
)
5019 amt
*= sizeof (arelent
);
5020 internal_relocs
= (arelent
*) bfd_zalloc (abfd
, (amt
));
5021 if (internal_relocs
== (arelent
*) NULL
)
5024 /* Process and internalize the relocations. */
5025 som_set_reloc_info (external_relocs
, fixup_stream_size
,
5026 internal_relocs
, section
, symbols
, FALSE
);
5028 /* We're done with the external relocations. Free them. */
5029 free (external_relocs
);
5030 som_section_data (section
)->reloc_stream
= NULL
;
5032 /* Save our results and return success. */
5033 section
->relocation
= internal_relocs
;
5037 /* Return the number of bytes required to store the relocation
5038 information associated with the given section. */
5041 som_get_reloc_upper_bound (abfd
, asect
)
5045 /* If section has relocations, then read in the relocation stream
5046 and parse it to determine how many relocations exist. */
5047 if (asect
->flags
& SEC_RELOC
)
5049 if (! som_slurp_reloc_table (abfd
, asect
, NULL
, TRUE
))
5051 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
5053 /* There are no relocations. */
5057 /* Convert relocations from SOM (external) form into BFD internal
5058 form. Return the number of relocations. */
5061 som_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
5070 if (! som_slurp_reloc_table (abfd
, section
, symbols
, FALSE
))
5073 count
= section
->reloc_count
;
5074 tblptr
= section
->relocation
;
5077 *relptr
++ = tblptr
++;
5079 *relptr
= (arelent
*) NULL
;
5080 return section
->reloc_count
;
5083 extern const bfd_target som_vec
;
5085 /* A hook to set up object file dependent section information. */
5088 som_new_section_hook (abfd
, newsect
)
5092 bfd_size_type amt
= sizeof (struct som_section_data_struct
);
5093 newsect
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
5094 if (!newsect
->used_by_bfd
)
5096 newsect
->alignment_power
= 3;
5098 /* We allow more than three sections internally. */
5102 /* Copy any private info we understand from the input symbol
5103 to the output symbol. */
5106 som_bfd_copy_private_symbol_data (ibfd
, isymbol
, obfd
, osymbol
)
5112 struct som_symbol
*input_symbol
= (struct som_symbol
*) isymbol
;
5113 struct som_symbol
*output_symbol
= (struct som_symbol
*) osymbol
;
5115 /* One day we may try to grok other private data. */
5116 if (ibfd
->xvec
->flavour
!= bfd_target_som_flavour
5117 || obfd
->xvec
->flavour
!= bfd_target_som_flavour
)
5120 /* The only private information we need to copy is the argument relocation
5122 output_symbol
->tc_data
.ap
.hppa_arg_reloc
=
5123 input_symbol
->tc_data
.ap
.hppa_arg_reloc
;
5128 /* Copy any private info we understand from the input section
5129 to the output section. */
5132 som_bfd_copy_private_section_data (ibfd
, isection
, obfd
, osection
)
5140 /* One day we may try to grok other private data. */
5141 if (ibfd
->xvec
->flavour
!= bfd_target_som_flavour
5142 || obfd
->xvec
->flavour
!= bfd_target_som_flavour
5143 || (!som_is_space (isection
) && !som_is_subspace (isection
)))
5146 amt
= sizeof (struct som_copyable_section_data_struct
);
5147 som_section_data (osection
)->copy_data
=
5148 (struct som_copyable_section_data_struct
*) bfd_zalloc (obfd
, amt
);
5149 if (som_section_data (osection
)->copy_data
== NULL
)
5152 memcpy (som_section_data (osection
)->copy_data
,
5153 som_section_data (isection
)->copy_data
,
5154 sizeof (struct som_copyable_section_data_struct
));
5156 /* Reparent if necessary. */
5157 if (som_section_data (osection
)->copy_data
->container
)
5158 som_section_data (osection
)->copy_data
->container
=
5159 som_section_data (osection
)->copy_data
->container
->output_section
;
5164 /* Copy any private info we understand from the input bfd
5165 to the output bfd. */
5168 som_bfd_copy_private_bfd_data (ibfd
, obfd
)
5171 /* One day we may try to grok other private data. */
5172 if (ibfd
->xvec
->flavour
!= bfd_target_som_flavour
5173 || obfd
->xvec
->flavour
!= bfd_target_som_flavour
)
5176 /* Allocate some memory to hold the data we need. */
5177 obj_som_exec_data (obfd
) = (struct som_exec_data
*)
5178 bfd_zalloc (obfd
, (bfd_size_type
) sizeof (struct som_exec_data
));
5179 if (obj_som_exec_data (obfd
) == NULL
)
5182 /* Now copy the data. */
5183 memcpy (obj_som_exec_data (obfd
), obj_som_exec_data (ibfd
),
5184 sizeof (struct som_exec_data
));
5189 /* Set backend info for sections which can not be described
5190 in the BFD data structures. */
5193 bfd_som_set_section_attributes (section
, defined
, private, sort_key
, spnum
)
5197 unsigned int sort_key
;
5200 /* Allocate memory to hold the magic information. */
5201 if (som_section_data (section
)->copy_data
== NULL
)
5203 bfd_size_type amt
= sizeof (struct som_copyable_section_data_struct
);
5204 som_section_data (section
)->copy_data
=
5205 (struct som_copyable_section_data_struct
*) bfd_zalloc (section
->owner
,
5207 if (som_section_data (section
)->copy_data
== NULL
)
5210 som_section_data (section
)->copy_data
->sort_key
= sort_key
;
5211 som_section_data (section
)->copy_data
->is_defined
= defined
;
5212 som_section_data (section
)->copy_data
->is_private
= private;
5213 som_section_data (section
)->copy_data
->container
= section
;
5214 som_section_data (section
)->copy_data
->space_number
= spnum
;
5218 /* Set backend info for subsections which can not be described
5219 in the BFD data structures. */
5222 bfd_som_set_subsection_attributes (section
, container
, access
,
5225 asection
*container
;
5227 unsigned int sort_key
;
5230 /* Allocate memory to hold the magic information. */
5231 if (som_section_data (section
)->copy_data
== NULL
)
5233 bfd_size_type amt
= sizeof (struct som_copyable_section_data_struct
);
5234 som_section_data (section
)->copy_data
=
5235 (struct som_copyable_section_data_struct
*) bfd_zalloc (section
->owner
,
5237 if (som_section_data (section
)->copy_data
== NULL
)
5240 som_section_data (section
)->copy_data
->sort_key
= sort_key
;
5241 som_section_data (section
)->copy_data
->access_control_bits
= access
;
5242 som_section_data (section
)->copy_data
->quadrant
= quadrant
;
5243 som_section_data (section
)->copy_data
->container
= container
;
5247 /* Set the full SOM symbol type. SOM needs far more symbol information
5248 than any other object file format I'm aware of. It is mandatory
5249 to be able to know if a symbol is an entry point, millicode, data,
5250 code, absolute, storage request, or procedure label. If you get
5251 the symbol type wrong your program will not link. */
5254 bfd_som_set_symbol_type (symbol
, type
)
5258 som_symbol_data (symbol
)->som_type
= type
;
5261 /* Attach an auxiliary header to the BFD backend so that it may be
5262 written into the object file. */
5265 bfd_som_attach_aux_hdr (abfd
, type
, string
)
5272 if (type
== VERSION_AUX_ID
)
5274 size_t len
= strlen (string
);
5278 pad
= (4 - (len
% 4));
5279 amt
= sizeof (struct aux_id
) + sizeof (unsigned int) + len
+ pad
;
5280 obj_som_version_hdr (abfd
) =
5281 (struct user_string_aux_hdr
*) bfd_zalloc (abfd
, amt
);
5282 if (!obj_som_version_hdr (abfd
))
5284 obj_som_version_hdr (abfd
)->header_id
.type
= VERSION_AUX_ID
;
5285 obj_som_version_hdr (abfd
)->header_id
.length
= len
+ pad
;
5286 obj_som_version_hdr (abfd
)->header_id
.length
+= sizeof (int);
5287 obj_som_version_hdr (abfd
)->string_length
= len
;
5288 strncpy (obj_som_version_hdr (abfd
)->user_string
, string
, len
);
5290 else if (type
== COPYRIGHT_AUX_ID
)
5292 int len
= strlen (string
);
5296 pad
= (4 - (len
% 4));
5297 amt
= sizeof (struct aux_id
) + sizeof (unsigned int) + len
+ pad
;
5298 obj_som_copyright_hdr (abfd
) =
5299 (struct copyright_aux_hdr
*) bfd_zalloc (abfd
, amt
);
5300 if (!obj_som_copyright_hdr (abfd
))
5302 obj_som_copyright_hdr (abfd
)->header_id
.type
= COPYRIGHT_AUX_ID
;
5303 obj_som_copyright_hdr (abfd
)->header_id
.length
= len
+ pad
;
5304 obj_som_copyright_hdr (abfd
)->header_id
.length
+= sizeof (int);
5305 obj_som_copyright_hdr (abfd
)->string_length
= len
;
5306 strcpy (obj_som_copyright_hdr (abfd
)->copyright
, string
);
5311 /* Attach a compilation unit header to the BFD backend so that it may be
5312 written into the object file. */
5315 bfd_som_attach_compilation_unit (abfd
, name
, language_name
, product_id
,
5319 const char *language_name
;
5320 const char *product_id
;
5321 const char *version_id
;
5323 COMPUNIT
*n
= (COMPUNIT
*) bfd_zalloc (abfd
, (bfd_size_type
) COMPUNITSZ
);
5330 n->f.n_name = bfd_alloc (abfd, (bfd_size_type) strlen (f) + 1); \
5331 if (n->f.n_name == NULL) \
5333 strcpy (n->f.n_name, f); \
5337 STRDUP (language_name
);
5338 STRDUP (product_id
);
5339 STRDUP (version_id
);
5343 obj_som_compilation_unit (abfd
) = n
;
5349 som_get_section_contents (abfd
, section
, location
, offset
, count
)
5354 bfd_size_type count
;
5356 if (count
== 0 || ((section
->flags
& SEC_HAS_CONTENTS
) == 0))
5358 if ((bfd_size_type
) (offset
+count
) > section
->_raw_size
5359 || bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
5360 || bfd_bread (location
, count
, abfd
) != count
)
5361 return FALSE
; /* On error. */
5366 som_set_section_contents (abfd
, section
, location
, offset
, count
)
5371 bfd_size_type count
;
5373 if (! abfd
->output_has_begun
)
5375 /* Set up fixed parts of the file, space, and subspace headers.
5376 Notify the world that output has begun. */
5377 som_prep_headers (abfd
);
5378 abfd
->output_has_begun
= TRUE
;
5379 /* Start writing the object file. This include all the string
5380 tables, fixup streams, and other portions of the object file. */
5381 som_begin_writing (abfd
);
5384 /* Only write subspaces which have "real" contents (eg. the contents
5385 are not generated at run time by the OS). */
5386 if (!som_is_subspace (section
)
5387 || ((section
->flags
& SEC_HAS_CONTENTS
) == 0))
5390 /* Seek to the proper offset within the object file and write the
5392 offset
+= som_section_data (section
)->subspace_dict
->file_loc_init_value
;
5393 if (bfd_seek (abfd
, offset
, SEEK_SET
) != 0)
5396 if (bfd_bwrite (location
, count
, abfd
) != count
)
5402 som_set_arch_mach (abfd
, arch
, machine
)
5404 enum bfd_architecture arch
;
5405 unsigned long machine
;
5407 /* Allow any architecture to be supported by the SOM backend. */
5408 return bfd_default_set_arch_mach (abfd
, arch
, machine
);
5412 som_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
5413 functionname_ptr
, line_ptr
)
5414 bfd
*abfd ATTRIBUTE_UNUSED
;
5415 asection
*section ATTRIBUTE_UNUSED
;
5416 asymbol
**symbols ATTRIBUTE_UNUSED
;
5417 bfd_vma offset ATTRIBUTE_UNUSED
;
5418 const char **filename_ptr ATTRIBUTE_UNUSED
;
5419 const char **functionname_ptr ATTRIBUTE_UNUSED
;
5420 unsigned int *line_ptr ATTRIBUTE_UNUSED
;
5426 som_sizeof_headers (abfd
, reloc
)
5427 bfd
*abfd ATTRIBUTE_UNUSED
;
5428 bfd_boolean reloc ATTRIBUTE_UNUSED
;
5430 (*_bfd_error_handler
) (_("som_sizeof_headers unimplemented"));
5436 /* Return the single-character symbol type corresponding to
5437 SOM section S, or '?' for an unknown SOM section. */
5440 som_section_type (s
)
5443 const struct section_to_type
*t
;
5445 for (t
= &stt
[0]; t
->section
; t
++)
5446 if (!strcmp (s
, t
->section
))
5452 som_decode_symclass (symbol
)
5457 if (bfd_is_com_section (symbol
->section
))
5459 if (bfd_is_und_section (symbol
->section
))
5461 if (bfd_is_ind_section (symbol
->section
))
5463 if (symbol
->flags
& BSF_WEAK
)
5465 if (!(symbol
->flags
& (BSF_GLOBAL
| BSF_LOCAL
)))
5468 if (bfd_is_abs_section (symbol
->section
)
5469 || (som_symbol_data (symbol
) != NULL
5470 && som_symbol_data (symbol
)->som_type
== SYMBOL_TYPE_ABSOLUTE
))
5472 else if (symbol
->section
)
5473 c
= som_section_type (symbol
->section
->name
);
5476 if (symbol
->flags
& BSF_GLOBAL
)
5481 /* Return information about SOM symbol SYMBOL in RET. */
5484 som_get_symbol_info (ignore_abfd
, symbol
, ret
)
5485 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
5489 ret
->type
= som_decode_symclass (symbol
);
5490 if (ret
->type
!= 'U')
5491 ret
->value
= symbol
->value
+ symbol
->section
->vma
;
5494 ret
->name
= symbol
->name
;
5497 /* Count the number of symbols in the archive symbol table. Necessary
5498 so that we can allocate space for all the carsyms at once. */
5501 som_bfd_count_ar_symbols (abfd
, lst_header
, count
)
5503 struct lst_header
*lst_header
;
5507 unsigned int *hash_table
= NULL
;
5509 file_ptr lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
5511 amt
= lst_header
->hash_size
;
5512 amt
*= sizeof (unsigned int);
5513 hash_table
= (unsigned int *) bfd_malloc (amt
);
5514 if (hash_table
== NULL
&& lst_header
->hash_size
!= 0)
5517 /* Don't forget to initialize the counter! */
5520 /* Read in the hash table. The has table is an array of 32bit file offsets
5521 which point to the hash chains. */
5522 if (bfd_bread ((PTR
) hash_table
, amt
, abfd
) != amt
)
5525 /* Walk each chain counting the number of symbols found on that particular
5527 for (i
= 0; i
< lst_header
->hash_size
; i
++)
5529 struct lst_symbol_record lst_symbol
;
5531 /* An empty chain has zero as it's file offset. */
5532 if (hash_table
[i
] == 0)
5535 /* Seek to the first symbol in this hash chain. */
5536 if (bfd_seek (abfd
, lst_filepos
+ hash_table
[i
], SEEK_SET
) != 0)
5539 /* Read in this symbol and update the counter. */
5540 amt
= sizeof (lst_symbol
);
5541 if (bfd_bread ((PTR
) &lst_symbol
, amt
, abfd
) != amt
)
5546 /* Now iterate through the rest of the symbols on this chain. */
5547 while (lst_symbol
.next_entry
)
5550 /* Seek to the next symbol. */
5551 if (bfd_seek (abfd
, lst_filepos
+ lst_symbol
.next_entry
, SEEK_SET
)
5555 /* Read the symbol in and update the counter. */
5556 amt
= sizeof (lst_symbol
);
5557 if (bfd_bread ((PTR
) &lst_symbol
, amt
, abfd
) != amt
)
5563 if (hash_table
!= NULL
)
5568 if (hash_table
!= NULL
)
5573 /* Fill in the canonical archive symbols (SYMS) from the archive described
5574 by ABFD and LST_HEADER. */
5577 som_bfd_fill_in_ar_symbols (abfd
, lst_header
, syms
)
5579 struct lst_header
*lst_header
;
5582 unsigned int i
, len
;
5583 carsym
*set
= syms
[0];
5584 unsigned int *hash_table
= NULL
;
5585 struct som_entry
*som_dict
= NULL
;
5587 file_ptr lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
5589 amt
= lst_header
->hash_size
;
5590 amt
*= sizeof (unsigned int);
5591 hash_table
= (unsigned int *) bfd_malloc (amt
);
5592 if (hash_table
== NULL
&& lst_header
->hash_size
!= 0)
5595 /* Read in the hash table. The has table is an array of 32bit file offsets
5596 which point to the hash chains. */
5597 if (bfd_bread ((PTR
) hash_table
, amt
, abfd
) != amt
)
5600 /* Seek to and read in the SOM dictionary. We will need this to fill
5601 in the carsym's filepos field. */
5602 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->dir_loc
, SEEK_SET
) != 0)
5605 amt
= lst_header
->module_count
;
5606 amt
*= sizeof (struct som_entry
);
5607 som_dict
= (struct som_entry
*) bfd_malloc (amt
);
5608 if (som_dict
== NULL
&& lst_header
->module_count
!= 0)
5611 if (bfd_bread ((PTR
) som_dict
, amt
, abfd
) != amt
)
5614 /* Walk each chain filling in the carsyms as we go along. */
5615 for (i
= 0; i
< lst_header
->hash_size
; i
++)
5617 struct lst_symbol_record lst_symbol
;
5619 /* An empty chain has zero as it's file offset. */
5620 if (hash_table
[i
] == 0)
5623 /* Seek to and read the first symbol on the chain. */
5624 if (bfd_seek (abfd
, lst_filepos
+ hash_table
[i
], SEEK_SET
) != 0)
5627 amt
= sizeof (lst_symbol
);
5628 if (bfd_bread ((PTR
) &lst_symbol
, amt
, abfd
) != amt
)
5631 /* Get the name of the symbol, first get the length which is stored
5632 as a 32bit integer just before the symbol.
5634 One might ask why we don't just read in the entire string table
5635 and index into it. Well, according to the SOM ABI the string
5636 index can point *anywhere* in the archive to save space, so just
5637 using the string table would not be safe. */
5638 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->string_loc
5639 + lst_symbol
.name
.n_strx
- 4, SEEK_SET
) != 0)
5642 if (bfd_bread (&len
, (bfd_size_type
) 4, abfd
) != 4)
5645 /* Allocate space for the name and null terminate it too. */
5646 set
->name
= bfd_zalloc (abfd
, (bfd_size_type
) len
+ 1);
5649 if (bfd_bread (set
->name
, (bfd_size_type
) len
, abfd
) != len
)
5654 /* Fill in the file offset. Note that the "location" field points
5655 to the SOM itself, not the ar_hdr in front of it. */
5656 set
->file_offset
= som_dict
[lst_symbol
.som_index
].location
5657 - sizeof (struct ar_hdr
);
5659 /* Go to the next symbol. */
5662 /* Iterate through the rest of the chain. */
5663 while (lst_symbol
.next_entry
)
5665 /* Seek to the next symbol and read it in. */
5666 if (bfd_seek (abfd
, lst_filepos
+ lst_symbol
.next_entry
, SEEK_SET
)
5670 amt
= sizeof (lst_symbol
);
5671 if (bfd_bread ((PTR
) &lst_symbol
, amt
, abfd
) != amt
)
5674 /* Seek to the name length & string and read them in. */
5675 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->string_loc
5676 + lst_symbol
.name
.n_strx
- 4, SEEK_SET
) != 0)
5679 if (bfd_bread (&len
, (bfd_size_type
) 4, abfd
) != 4)
5682 /* Allocate space for the name and null terminate it too. */
5683 set
->name
= bfd_zalloc (abfd
, (bfd_size_type
) len
+ 1);
5687 if (bfd_bread (set
->name
, (bfd_size_type
) len
, abfd
) != len
)
5691 /* Fill in the file offset. Note that the "location" field points
5692 to the SOM itself, not the ar_hdr in front of it. */
5693 set
->file_offset
= som_dict
[lst_symbol
.som_index
].location
5694 - sizeof (struct ar_hdr
);
5696 /* Go on to the next symbol. */
5700 /* If we haven't died by now, then we successfully read the entire
5701 archive symbol table. */
5702 if (hash_table
!= NULL
)
5704 if (som_dict
!= NULL
)
5709 if (hash_table
!= NULL
)
5711 if (som_dict
!= NULL
)
5716 /* Read in the LST from the archive. */
5719 som_slurp_armap (abfd
)
5722 struct lst_header lst_header
;
5723 struct ar_hdr ar_header
;
5724 unsigned int parsed_size
;
5725 struct artdata
*ardata
= bfd_ardata (abfd
);
5727 bfd_size_type amt
= 16;
5728 int i
= bfd_bread ((PTR
) nextname
, amt
, abfd
);
5730 /* Special cases. */
5736 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
5739 /* For archives without .o files there is no symbol table. */
5740 if (strncmp (nextname
, "/ ", 16))
5742 bfd_has_map (abfd
) = FALSE
;
5746 /* Read in and sanity check the archive header. */
5747 amt
= sizeof (struct ar_hdr
);
5748 if (bfd_bread ((PTR
) &ar_header
, amt
, abfd
) != amt
)
5751 if (strncmp (ar_header
.ar_fmag
, ARFMAG
, 2))
5753 bfd_set_error (bfd_error_malformed_archive
);
5757 /* How big is the archive symbol table entry? */
5759 parsed_size
= strtol (ar_header
.ar_size
, NULL
, 10);
5762 bfd_set_error (bfd_error_malformed_archive
);
5766 /* Save off the file offset of the first real user data. */
5767 ardata
->first_file_filepos
= bfd_tell (abfd
) + parsed_size
;
5769 /* Read in the library symbol table. We'll make heavy use of this
5770 in just a minute. */
5771 amt
= sizeof (struct lst_header
);
5772 if (bfd_bread ((PTR
) &lst_header
, amt
, abfd
) != amt
)
5776 if (lst_header
.a_magic
!= LIBMAGIC
)
5778 bfd_set_error (bfd_error_malformed_archive
);
5782 /* Count the number of symbols in the library symbol table. */
5783 if (! som_bfd_count_ar_symbols (abfd
, &lst_header
, &ardata
->symdef_count
))
5786 /* Get back to the start of the library symbol table. */
5787 if (bfd_seek (abfd
, (ardata
->first_file_filepos
- parsed_size
5788 + sizeof (struct lst_header
)), SEEK_SET
) != 0)
5791 /* Initialize the cache and allocate space for the library symbols. */
5793 amt
= ardata
->symdef_count
;
5794 amt
*= sizeof (carsym
);
5795 ardata
->symdefs
= (carsym
*) bfd_alloc (abfd
, amt
);
5796 if (!ardata
->symdefs
)
5799 /* Now fill in the canonical archive symbols. */
5800 if (! som_bfd_fill_in_ar_symbols (abfd
, &lst_header
, &ardata
->symdefs
))
5803 /* Seek back to the "first" file in the archive. Note the "first"
5804 file may be the extended name table. */
5805 if (bfd_seek (abfd
, ardata
->first_file_filepos
, SEEK_SET
) != 0)
5808 /* Notify the generic archive code that we have a symbol map. */
5809 bfd_has_map (abfd
) = TRUE
;
5813 /* Begin preparing to write a SOM library symbol table.
5815 As part of the prep work we need to determine the number of symbols
5816 and the size of the associated string section. */
5819 som_bfd_prep_for_ar_write (abfd
, num_syms
, stringsize
)
5821 unsigned int *num_syms
, *stringsize
;
5823 bfd
*curr_bfd
= abfd
->archive_head
;
5825 /* Some initialization. */
5829 /* Iterate over each BFD within this archive. */
5830 while (curr_bfd
!= NULL
)
5832 unsigned int curr_count
, i
;
5833 som_symbol_type
*sym
;
5835 /* Don't bother for non-SOM objects. */
5836 if (curr_bfd
->format
!= bfd_object
5837 || curr_bfd
->xvec
->flavour
!= bfd_target_som_flavour
)
5839 curr_bfd
= curr_bfd
->next
;
5843 /* Make sure the symbol table has been read, then snag a pointer
5844 to it. It's a little slimey to grab the symbols via obj_som_symtab,
5845 but doing so avoids allocating lots of extra memory. */
5846 if (! som_slurp_symbol_table (curr_bfd
))
5849 sym
= obj_som_symtab (curr_bfd
);
5850 curr_count
= bfd_get_symcount (curr_bfd
);
5852 /* Examine each symbol to determine if it belongs in the
5853 library symbol table. */
5854 for (i
= 0; i
< curr_count
; i
++, sym
++)
5856 struct som_misc_symbol_info info
;
5858 /* Derive SOM information from the BFD symbol. */
5859 som_bfd_derive_misc_symbol_info (curr_bfd
, &sym
->symbol
, &info
);
5861 /* Should we include this symbol? */
5862 if (info
.symbol_type
== ST_NULL
5863 || info
.symbol_type
== ST_SYM_EXT
5864 || info
.symbol_type
== ST_ARG_EXT
)
5867 /* Only global symbols and unsatisfied commons. */
5868 if (info
.symbol_scope
!= SS_UNIVERSAL
5869 && info
.symbol_type
!= ST_STORAGE
)
5872 /* Do no include undefined symbols. */
5873 if (bfd_is_und_section (sym
->symbol
.section
))
5876 /* Bump the various counters, being careful to honor
5877 alignment considerations in the string table. */
5879 *stringsize
= *stringsize
+ strlen (sym
->symbol
.name
) + 5;
5880 while (*stringsize
% 4)
5884 curr_bfd
= curr_bfd
->next
;
5889 /* Hash a symbol name based on the hashing algorithm presented in the
5893 som_bfd_ar_symbol_hash (symbol
)
5896 unsigned int len
= strlen (symbol
->name
);
5898 /* Names with length 1 are special. */
5900 return 0x1000100 | (symbol
->name
[0] << 16) | symbol
->name
[0];
5902 return ((len
& 0x7f) << 24) | (symbol
->name
[1] << 16)
5903 | (symbol
->name
[len
- 2] << 8) | symbol
->name
[len
- 1];
5906 /* Do the bulk of the work required to write the SOM library
5910 som_bfd_ar_write_symbol_stuff (abfd
, nsyms
, string_size
, lst
, elength
)
5912 unsigned int nsyms
, string_size
;
5913 struct lst_header lst
;
5916 file_ptr lst_filepos
;
5917 char *strings
= NULL
, *p
;
5918 struct lst_symbol_record
*lst_syms
= NULL
, *curr_lst_sym
;
5920 unsigned int *hash_table
= NULL
;
5921 struct som_entry
*som_dict
= NULL
;
5922 struct lst_symbol_record
**last_hash_entry
= NULL
;
5923 unsigned int curr_som_offset
, som_index
= 0;
5926 amt
= lst
.hash_size
;
5927 amt
*= sizeof (unsigned int);
5928 hash_table
= (unsigned int *) bfd_zmalloc (amt
);
5929 if (hash_table
== NULL
&& lst
.hash_size
!= 0)
5932 amt
= lst
.module_count
;
5933 amt
*= sizeof (struct som_entry
);
5934 som_dict
= (struct som_entry
*) bfd_zmalloc (amt
);
5935 if (som_dict
== NULL
&& lst
.module_count
!= 0)
5938 amt
= lst
.hash_size
;
5939 amt
*= sizeof (struct lst_symbol_record
*);
5940 last_hash_entry
= ((struct lst_symbol_record
**) bfd_zmalloc (amt
));
5941 if (last_hash_entry
== NULL
&& lst
.hash_size
!= 0)
5944 /* Lots of fields are file positions relative to the start
5945 of the lst record. So save its location. */
5946 lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
5948 /* Symbols have som_index fields, so we have to keep track of the
5949 index of each SOM in the archive.
5951 The SOM dictionary has (among other things) the absolute file
5952 position for the SOM which a particular dictionary entry
5953 describes. We have to compute that information as we iterate
5954 through the SOMs/symbols. */
5957 /* We add in the size of the archive header twice as the location
5958 in the SOM dictionary is the actual offset of the SOM, not the
5959 archive header before the SOM. */
5960 curr_som_offset
= 8 + 2 * sizeof (struct ar_hdr
) + lst
.file_end
;
5962 /* Make room for the archive header and the contents of the
5963 extended string table. Note that elength includes the size
5964 of the archive header for the extended name table! */
5966 curr_som_offset
+= elength
;
5968 /* Make sure we're properly aligned. */
5969 curr_som_offset
= (curr_som_offset
+ 0x1) & ~0x1;
5971 /* FIXME should be done with buffers just like everything else... */
5973 amt
*= sizeof (struct lst_symbol_record
);
5974 lst_syms
= bfd_malloc (amt
);
5975 if (lst_syms
== NULL
&& nsyms
!= 0)
5977 strings
= bfd_malloc ((bfd_size_type
) string_size
);
5978 if (strings
== NULL
&& string_size
!= 0)
5982 curr_lst_sym
= lst_syms
;
5984 curr_bfd
= abfd
->archive_head
;
5985 while (curr_bfd
!= NULL
)
5987 unsigned int curr_count
, i
;
5988 som_symbol_type
*sym
;
5990 /* Don't bother for non-SOM objects. */
5991 if (curr_bfd
->format
!= bfd_object
5992 || curr_bfd
->xvec
->flavour
!= bfd_target_som_flavour
)
5994 curr_bfd
= curr_bfd
->next
;
5998 /* Make sure the symbol table has been read, then snag a pointer
5999 to it. It's a little slimey to grab the symbols via obj_som_symtab,
6000 but doing so avoids allocating lots of extra memory. */
6001 if (! som_slurp_symbol_table (curr_bfd
))
6004 sym
= obj_som_symtab (curr_bfd
);
6005 curr_count
= bfd_get_symcount (curr_bfd
);
6007 for (i
= 0; i
< curr_count
; i
++, sym
++)
6009 struct som_misc_symbol_info info
;
6011 /* Derive SOM information from the BFD symbol. */
6012 som_bfd_derive_misc_symbol_info (curr_bfd
, &sym
->symbol
, &info
);
6014 /* Should we include this symbol? */
6015 if (info
.symbol_type
== ST_NULL
6016 || info
.symbol_type
== ST_SYM_EXT
6017 || info
.symbol_type
== ST_ARG_EXT
)
6020 /* Only global symbols and unsatisfied commons. */
6021 if (info
.symbol_scope
!= SS_UNIVERSAL
6022 && info
.symbol_type
!= ST_STORAGE
)
6025 /* Do no include undefined symbols. */
6026 if (bfd_is_und_section (sym
->symbol
.section
))
6029 /* If this is the first symbol from this SOM, then update
6030 the SOM dictionary too. */
6031 if (som_dict
[som_index
].location
== 0)
6033 som_dict
[som_index
].location
= curr_som_offset
;
6034 som_dict
[som_index
].length
= arelt_size (curr_bfd
);
6037 /* Fill in the lst symbol record. */
6038 curr_lst_sym
->hidden
= 0;
6039 curr_lst_sym
->secondary_def
= info
.secondary_def
;
6040 curr_lst_sym
->symbol_type
= info
.symbol_type
;
6041 curr_lst_sym
->symbol_scope
= info
.symbol_scope
;
6042 curr_lst_sym
->check_level
= 0;
6043 curr_lst_sym
->must_qualify
= 0;
6044 curr_lst_sym
->initially_frozen
= 0;
6045 curr_lst_sym
->memory_resident
= 0;
6046 curr_lst_sym
->is_common
= bfd_is_com_section (sym
->symbol
.section
);
6047 curr_lst_sym
->dup_common
= 0;
6048 curr_lst_sym
->xleast
= 3;
6049 curr_lst_sym
->arg_reloc
= info
.arg_reloc
;
6050 curr_lst_sym
->name
.n_strx
= p
- strings
+ 4;
6051 curr_lst_sym
->qualifier_name
.n_strx
= 0;
6052 curr_lst_sym
->symbol_info
= info
.symbol_info
;
6053 curr_lst_sym
->symbol_value
= info
.symbol_value
| info
.priv_level
;
6054 curr_lst_sym
->symbol_descriptor
= 0;
6055 curr_lst_sym
->reserved
= 0;
6056 curr_lst_sym
->som_index
= som_index
;
6057 curr_lst_sym
->symbol_key
= som_bfd_ar_symbol_hash (&sym
->symbol
);
6058 curr_lst_sym
->next_entry
= 0;
6060 /* Insert into the hash table. */
6061 if (hash_table
[curr_lst_sym
->symbol_key
% lst
.hash_size
])
6063 struct lst_symbol_record
*tmp
;
6065 /* There is already something at the head of this hash chain,
6066 so tack this symbol onto the end of the chain. */
6067 tmp
= last_hash_entry
[curr_lst_sym
->symbol_key
% lst
.hash_size
];
6069 = (curr_lst_sym
- lst_syms
) * sizeof (struct lst_symbol_record
)
6071 + lst
.module_count
* sizeof (struct som_entry
)
6072 + sizeof (struct lst_header
);
6076 /* First entry in this hash chain. */
6077 hash_table
[curr_lst_sym
->symbol_key
% lst
.hash_size
]
6078 = (curr_lst_sym
- lst_syms
) * sizeof (struct lst_symbol_record
)
6080 + lst
.module_count
* sizeof (struct som_entry
)
6081 + sizeof (struct lst_header
);
6084 /* Keep track of the last symbol we added to this chain so we can
6085 easily update its next_entry pointer. */
6086 last_hash_entry
[curr_lst_sym
->symbol_key
% lst
.hash_size
]
6089 /* Update the string table. */
6090 bfd_put_32 (abfd
, strlen (sym
->symbol
.name
), p
);
6092 strcpy (p
, sym
->symbol
.name
);
6093 p
+= strlen (sym
->symbol
.name
) + 1;
6096 bfd_put_8 (abfd
, 0, p
);
6100 /* Head to the next symbol. */
6104 /* Keep track of where each SOM will finally reside; then look
6106 curr_som_offset
+= arelt_size (curr_bfd
) + sizeof (struct ar_hdr
);
6108 /* A particular object in the archive may have an odd length; the
6109 linker requires objects begin on an even boundary. So round
6110 up the current offset as necessary. */
6111 curr_som_offset
= (curr_som_offset
+ 0x1) &~ (unsigned) 1;
6112 curr_bfd
= curr_bfd
->next
;
6116 /* Now scribble out the hash table. */
6117 amt
= lst
.hash_size
* 4;
6118 if (bfd_bwrite ((PTR
) hash_table
, amt
, abfd
) != amt
)
6121 /* Then the SOM dictionary. */
6122 amt
= lst
.module_count
* sizeof (struct som_entry
);
6123 if (bfd_bwrite ((PTR
) som_dict
, amt
, abfd
) != amt
)
6126 /* The library symbols. */
6127 amt
= nsyms
* sizeof (struct lst_symbol_record
);
6128 if (bfd_bwrite ((PTR
) lst_syms
, amt
, abfd
) != amt
)
6131 /* And finally the strings. */
6133 if (bfd_bwrite ((PTR
) strings
, amt
, abfd
) != amt
)
6136 if (hash_table
!= NULL
)
6138 if (som_dict
!= NULL
)
6140 if (last_hash_entry
!= NULL
)
6141 free (last_hash_entry
);
6142 if (lst_syms
!= NULL
)
6144 if (strings
!= NULL
)
6149 if (hash_table
!= NULL
)
6151 if (som_dict
!= NULL
)
6153 if (last_hash_entry
!= NULL
)
6154 free (last_hash_entry
);
6155 if (lst_syms
!= NULL
)
6157 if (strings
!= NULL
)
6163 /* Write out the LST for the archive.
6165 You'll never believe this is really how armaps are handled in SOM... */
6168 som_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
6170 unsigned int elength
;
6171 struct orl
*map ATTRIBUTE_UNUSED
;
6172 unsigned int orl_count ATTRIBUTE_UNUSED
;
6173 int stridx ATTRIBUTE_UNUSED
;
6176 struct stat statbuf
;
6177 unsigned int i
, lst_size
, nsyms
, stringsize
;
6179 struct lst_header lst
;
6183 /* We'll use this for the archive's date and mode later. */
6184 if (stat (abfd
->filename
, &statbuf
) != 0)
6186 bfd_set_error (bfd_error_system_call
);
6190 bfd_ardata (abfd
)->armap_timestamp
= statbuf
.st_mtime
+ 60;
6192 /* Account for the lst header first. */
6193 lst_size
= sizeof (struct lst_header
);
6195 /* Start building the LST header. */
6196 /* FIXME: Do we need to examine each element to determine the
6197 largest id number? */
6198 lst
.system_id
= CPU_PA_RISC1_0
;
6199 lst
.a_magic
= LIBMAGIC
;
6200 lst
.version_id
= VERSION_ID
;
6201 lst
.file_time
.secs
= 0;
6202 lst
.file_time
.nanosecs
= 0;
6204 lst
.hash_loc
= lst_size
;
6205 lst
.hash_size
= SOM_LST_HASH_SIZE
;
6207 /* Hash table is a SOM_LST_HASH_SIZE 32bit offsets. */
6208 lst_size
+= 4 * SOM_LST_HASH_SIZE
;
6210 /* We need to count the number of SOMs in this archive. */
6211 curr_bfd
= abfd
->archive_head
;
6212 lst
.module_count
= 0;
6213 while (curr_bfd
!= NULL
)
6215 /* Only true SOM objects count. */
6216 if (curr_bfd
->format
== bfd_object
6217 && curr_bfd
->xvec
->flavour
== bfd_target_som_flavour
)
6219 curr_bfd
= curr_bfd
->next
;
6221 lst
.module_limit
= lst
.module_count
;
6222 lst
.dir_loc
= lst_size
;
6223 lst_size
+= sizeof (struct som_entry
) * lst
.module_count
;
6225 /* We don't support import/export tables, auxiliary headers,
6226 or free lists yet. Make the linker work a little harder
6227 to make our life easier. */
6230 lst
.export_count
= 0;
6235 /* Count how many symbols we will have on the hash chains and the
6236 size of the associated string table. */
6237 if (! som_bfd_prep_for_ar_write (abfd
, &nsyms
, &stringsize
))
6240 lst_size
+= sizeof (struct lst_symbol_record
) * nsyms
;
6242 /* For the string table. One day we might actually use this info
6243 to avoid small seeks/reads when reading archives. */
6244 lst
.string_loc
= lst_size
;
6245 lst
.string_size
= stringsize
;
6246 lst_size
+= stringsize
;
6248 /* SOM ABI says this must be zero. */
6250 lst
.file_end
= lst_size
;
6252 /* Compute the checksum. Must happen after the entire lst header
6256 for (i
= 0; i
< sizeof (struct lst_header
) / sizeof (int) - 1; i
++)
6257 lst
.checksum
^= *p
++;
6259 sprintf (hdr
.ar_name
, "/ ");
6260 sprintf (hdr
.ar_date
, "%ld", bfd_ardata (abfd
)->armap_timestamp
);
6261 sprintf (hdr
.ar_uid
, "%ld", (long) getuid ());
6262 sprintf (hdr
.ar_gid
, "%ld", (long) getgid ());
6263 sprintf (hdr
.ar_mode
, "%-8o", (unsigned int) statbuf
.st_mode
);
6264 sprintf (hdr
.ar_size
, "%-10d", (int) lst_size
);
6265 hdr
.ar_fmag
[0] = '`';
6266 hdr
.ar_fmag
[1] = '\012';
6268 /* Turn any nulls into spaces. */
6269 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
6270 if (((char *) (&hdr
))[i
] == '\0')
6271 (((char *) (&hdr
))[i
]) = ' ';
6273 /* Scribble out the ar header. */
6274 amt
= sizeof (struct ar_hdr
);
6275 if (bfd_bwrite ((PTR
) &hdr
, amt
, abfd
) != amt
)
6278 /* Now scribble out the lst header. */
6279 amt
= sizeof (struct lst_header
);
6280 if (bfd_bwrite ((PTR
) &lst
, amt
, abfd
) != amt
)
6283 /* Build and write the armap. */
6284 if (!som_bfd_ar_write_symbol_stuff (abfd
, nsyms
, stringsize
, lst
, elength
))
6291 /* Free all information we have cached for this BFD. We can always
6292 read it again later if we need it. */
6295 som_bfd_free_cached_info (abfd
)
6300 if (bfd_get_format (abfd
) != bfd_object
)
6303 #define FREE(x) if (x != NULL) { free (x); x = NULL; }
6304 /* Free the native string and symbol tables. */
6305 FREE (obj_som_symtab (abfd
));
6306 FREE (obj_som_stringtab (abfd
));
6307 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
6309 /* Free the native relocations. */
6310 o
->reloc_count
= (unsigned) -1;
6311 FREE (som_section_data (o
)->reloc_stream
);
6312 /* Free the generic relocations. */
6313 FREE (o
->relocation
);
6320 /* End of miscellaneous support functions. */
6322 /* Linker support functions. */
6325 som_bfd_link_split_section (abfd
, sec
)
6326 bfd
*abfd ATTRIBUTE_UNUSED
;
6329 return (som_is_subspace (sec
) && sec
->_raw_size
> 240000);
6332 #define som_close_and_cleanup som_bfd_free_cached_info
6334 #define som_read_ar_hdr _bfd_generic_read_ar_hdr
6335 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
6336 #define som_get_elt_at_index _bfd_generic_get_elt_at_index
6337 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
6338 #define som_truncate_arname bfd_bsd_truncate_arname
6339 #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
6340 #define som_construct_extended_name_table \
6341 _bfd_archive_coff_construct_extended_name_table
6342 #define som_update_armap_timestamp bfd_true
6343 #define som_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
6345 #define som_get_lineno _bfd_nosymbols_get_lineno
6346 #define som_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
6347 #define som_read_minisymbols _bfd_generic_read_minisymbols
6348 #define som_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
6349 #define som_get_section_contents_in_window \
6350 _bfd_generic_get_section_contents_in_window
6352 #define som_bfd_get_relocated_section_contents \
6353 bfd_generic_get_relocated_section_contents
6354 #define som_bfd_relax_section bfd_generic_relax_section
6355 #define som_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
6356 #define som_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
6357 #define som_bfd_link_add_symbols _bfd_generic_link_add_symbols
6358 #define som_bfd_link_just_syms _bfd_generic_link_just_syms
6359 #define som_bfd_final_link _bfd_generic_final_link
6361 #define som_bfd_gc_sections bfd_generic_gc_sections
6362 #define som_bfd_merge_sections bfd_generic_merge_sections
6363 #define som_bfd_discard_group bfd_generic_discard_group
6365 const bfd_target som_vec
= {
6367 bfd_target_som_flavour
,
6368 BFD_ENDIAN_BIG
, /* target byte order */
6369 BFD_ENDIAN_BIG
, /* target headers byte order */
6370 (HAS_RELOC
| EXEC_P
| /* object flags */
6371 HAS_LINENO
| HAS_DEBUG
|
6372 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
| DYNAMIC
),
6373 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
6374 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
6376 /* leading_symbol_char: is the first char of a user symbol
6377 predictable, and if so what is it. */
6379 '/', /* ar_pad_char */
6380 14, /* ar_max_namelen */
6381 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
6382 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
6383 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
6384 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
6385 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
6386 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
6388 som_object_p
, /* bfd_check_format */
6389 bfd_generic_archive_p
,
6395 _bfd_generic_mkarchive
,
6400 som_write_object_contents
,
6401 _bfd_write_archive_contents
,
6406 BFD_JUMP_TABLE_GENERIC (som
),
6407 BFD_JUMP_TABLE_COPY (som
),
6408 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
6409 BFD_JUMP_TABLE_ARCHIVE (som
),
6410 BFD_JUMP_TABLE_SYMBOLS (som
),
6411 BFD_JUMP_TABLE_RELOCS (som
),
6412 BFD_JUMP_TABLE_WRITE (som
),
6413 BFD_JUMP_TABLE_LINK (som
),
6414 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
6421 #endif /* HOST_HPPAHPUX || HOST_HPPABSD || HOST_HPPAOSF */