1 /* bfd back-end for HP PA-RISC SOM objects.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 1998, 2000
3 Free Software Foundation, Inc.
5 Contributed by the Center for Software Science at the
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF) || defined(HOST_HPPAMPEIX)
33 #include <sys/param.h>
35 #include <machine/reg.h>
39 /* Magic not defined in standard HP-UX header files until 8.0 */
41 #ifndef CPU_PA_RISC1_0
42 #define CPU_PA_RISC1_0 0x20B
43 #endif /* CPU_PA_RISC1_0 */
45 #ifndef CPU_PA_RISC1_1
46 #define CPU_PA_RISC1_1 0x210
47 #endif /* CPU_PA_RISC1_1 */
49 #ifndef CPU_PA_RISC2_0
50 #define CPU_PA_RISC2_0 0x214
51 #endif /* CPU_PA_RISC2_0 */
53 #ifndef _PA_RISC1_0_ID
54 #define _PA_RISC1_0_ID CPU_PA_RISC1_0
55 #endif /* _PA_RISC1_0_ID */
57 #ifndef _PA_RISC1_1_ID
58 #define _PA_RISC1_1_ID CPU_PA_RISC1_1
59 #endif /* _PA_RISC1_1_ID */
61 #ifndef _PA_RISC2_0_ID
62 #define _PA_RISC2_0_ID CPU_PA_RISC2_0
63 #endif /* _PA_RISC2_0_ID */
65 #ifndef _PA_RISC_MAXID
66 #define _PA_RISC_MAXID 0x2FF
67 #endif /* _PA_RISC_MAXID */
70 #define _PA_RISC_ID(__m_num) \
71 (((__m_num) == _PA_RISC1_0_ID) || \
72 ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
73 #endif /* _PA_RISC_ID */
76 /* HIUX in it's infinite stupidity changed the names for several "well
77 known" constants. Work around such braindamage. Try the HPUX version
78 first, then the HIUX version, and finally provide a default. */
80 #define EXEC_AUX_ID HPUX_AUX_ID
83 #if !defined (EXEC_AUX_ID) && defined (HIUX_AUX_ID)
84 #define EXEC_AUX_ID HIUX_AUX_ID
91 /* Size (in chars) of the temporary buffers used during fixup and string
94 #define SOM_TMP_BUFSIZE 8192
96 /* Size of the hash table in archives. */
97 #define SOM_LST_HASH_SIZE 31
99 /* Max number of SOMs to be found in an archive. */
100 #define SOM_LST_MODULE_LIMIT 1024
102 /* Generic alignment macro. */
103 #define SOM_ALIGN(val, alignment) \
104 (((val) + (alignment) - 1) & ~((alignment) - 1))
106 /* SOM allows any one of the four previous relocations to be reused
107 with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
108 relocations are always a single byte, using a R_PREV_FIXUP instead
109 of some multi-byte relocation makes object files smaller.
111 Note one side effect of using a R_PREV_FIXUP is the relocation that
112 is being repeated moves to the front of the queue. */
115 unsigned char *reloc
;
119 /* This fully describes the symbol types which may be attached to
120 an EXPORT or IMPORT directive. Only SOM uses this formation
121 (ELF has no need for it). */
125 SYMBOL_TYPE_ABSOLUTE
,
129 SYMBOL_TYPE_MILLICODE
,
131 SYMBOL_TYPE_PRI_PROG
,
132 SYMBOL_TYPE_SEC_PROG
,
135 struct section_to_type
141 /* Assorted symbol information that needs to be derived from the BFD symbol
142 and/or the BFD backend private symbol data. */
143 struct som_misc_symbol_info
145 unsigned int symbol_type
;
146 unsigned int symbol_scope
;
147 unsigned int arg_reloc
;
148 unsigned int symbol_info
;
149 unsigned int symbol_value
;
150 unsigned int priv_level
;
151 unsigned int secondary_def
;
154 /* Forward declarations */
156 static boolean som_mkobject
PARAMS ((bfd
*));
157 static const bfd_target
* som_object_setup
PARAMS ((bfd
*,
159 struct som_exec_auxhdr
*,
161 static boolean setup_sections
PARAMS ((bfd
*, struct header
*, unsigned long));
162 static const bfd_target
* som_object_p
PARAMS ((bfd
*));
163 static boolean som_write_object_contents
PARAMS ((bfd
*));
164 static boolean som_slurp_string_table
PARAMS ((bfd
*));
165 static unsigned int som_slurp_symbol_table
PARAMS ((bfd
*));
166 static long som_get_symtab_upper_bound
PARAMS ((bfd
*));
167 static long som_canonicalize_reloc
PARAMS ((bfd
*, sec_ptr
,
168 arelent
**, asymbol
**));
169 static long som_get_reloc_upper_bound
PARAMS ((bfd
*, sec_ptr
));
170 static unsigned int som_set_reloc_info
PARAMS ((unsigned char *, unsigned int,
171 arelent
*, asection
*,
172 asymbol
**, boolean
));
173 static boolean som_slurp_reloc_table
PARAMS ((bfd
*, asection
*,
174 asymbol
**, boolean
));
175 static long som_get_symtab
PARAMS ((bfd
*, asymbol
**));
176 static asymbol
* som_make_empty_symbol
PARAMS ((bfd
*));
177 static void som_print_symbol
PARAMS ((bfd
*, PTR
,
178 asymbol
*, bfd_print_symbol_type
));
179 static boolean som_new_section_hook
PARAMS ((bfd
*, asection
*));
180 static boolean som_bfd_copy_private_symbol_data
PARAMS ((bfd
*, asymbol
*,
182 static boolean som_bfd_copy_private_section_data
PARAMS ((bfd
*, asection
*,
184 static boolean som_bfd_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
185 #define som_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
186 #define som_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
187 static boolean som_bfd_is_local_label_name
PARAMS ((bfd
*, const char *));
188 static boolean som_set_section_contents
PARAMS ((bfd
*, sec_ptr
, PTR
,
189 file_ptr
, bfd_size_type
));
190 static boolean som_get_section_contents
PARAMS ((bfd
*, sec_ptr
, PTR
,
191 file_ptr
, bfd_size_type
));
192 static boolean som_set_arch_mach
PARAMS ((bfd
*, enum bfd_architecture
,
194 static boolean som_find_nearest_line
PARAMS ((bfd
*, asection
*,
199 static void som_get_symbol_info
PARAMS ((bfd
*, asymbol
*, symbol_info
*));
200 static asection
* bfd_section_from_som_symbol
PARAMS ((bfd
*,
201 struct symbol_dictionary_record
*));
202 static int log2
PARAMS ((unsigned int));
203 static bfd_reloc_status_type hppa_som_reloc
PARAMS ((bfd
*, arelent
*,
207 static void som_initialize_reloc_queue
PARAMS ((struct reloc_queue
*));
208 static void som_reloc_queue_insert
PARAMS ((unsigned char *, unsigned int,
209 struct reloc_queue
*));
210 static void som_reloc_queue_fix
PARAMS ((struct reloc_queue
*, unsigned int));
211 static int som_reloc_queue_find
PARAMS ((unsigned char *, unsigned int,
212 struct reloc_queue
*));
213 static unsigned char * try_prev_fixup
PARAMS ((bfd
*, int *, unsigned char *,
215 struct reloc_queue
*));
217 static unsigned char * som_reloc_skip
PARAMS ((bfd
*, unsigned int,
218 unsigned char *, unsigned int *,
219 struct reloc_queue
*));
220 static unsigned char * som_reloc_addend
PARAMS ((bfd
*, int, unsigned char *,
222 struct reloc_queue
*));
223 static unsigned char * som_reloc_call
PARAMS ((bfd
*, unsigned char *,
226 struct reloc_queue
*));
227 static unsigned long som_count_spaces
PARAMS ((bfd
*));
228 static unsigned long som_count_subspaces
PARAMS ((bfd
*));
229 static int compare_syms
PARAMS ((const void *, const void *));
230 static int compare_subspaces
PARAMS ((const void *, const void *));
231 static unsigned long som_compute_checksum
PARAMS ((bfd
*));
232 static boolean som_prep_headers
PARAMS ((bfd
*));
233 static int som_sizeof_headers
PARAMS ((bfd
*, boolean
));
234 static boolean som_finish_writing
PARAMS ((bfd
*));
235 static boolean som_build_and_write_symbol_table
PARAMS ((bfd
*));
236 static void som_prep_for_fixups
PARAMS ((bfd
*, asymbol
**, unsigned long));
237 static boolean som_write_fixups
PARAMS ((bfd
*, unsigned long, unsigned int *));
238 static boolean som_write_space_strings
PARAMS ((bfd
*, unsigned long,
240 static boolean som_write_symbol_strings
PARAMS ((bfd
*, unsigned long,
241 asymbol
**, unsigned int,
244 static boolean som_begin_writing
PARAMS ((bfd
*));
245 static reloc_howto_type
* som_bfd_reloc_type_lookup
246 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
247 static char som_section_type
PARAMS ((const char *));
248 static int som_decode_symclass
PARAMS ((asymbol
*));
249 static boolean som_bfd_count_ar_symbols
PARAMS ((bfd
*, struct lst_header
*,
252 static boolean som_bfd_fill_in_ar_symbols
PARAMS ((bfd
*, struct lst_header
*,
254 static boolean som_slurp_armap
PARAMS ((bfd
*));
255 static boolean som_write_armap
PARAMS ((bfd
*, unsigned int, struct orl
*,
257 static void som_bfd_derive_misc_symbol_info
PARAMS ((bfd
*, asymbol
*,
258 struct som_misc_symbol_info
*));
259 static boolean som_bfd_prep_for_ar_write
PARAMS ((bfd
*, unsigned int *,
261 static unsigned int som_bfd_ar_symbol_hash
PARAMS ((asymbol
*));
262 static boolean som_bfd_ar_write_symbol_stuff
PARAMS ((bfd
*, unsigned int,
266 static boolean som_is_space
PARAMS ((asection
*));
267 static boolean som_is_subspace
PARAMS ((asection
*));
268 static boolean som_is_container
PARAMS ((asection
*, asection
*));
269 static boolean som_bfd_free_cached_info
PARAMS ((bfd
*));
270 static boolean som_bfd_link_split_section
PARAMS ((bfd
*, asection
*));
272 /* Map SOM section names to POSIX/BSD single-character symbol types.
274 This table includes all the standard subspaces as defined in the
275 current "PRO ABI for PA-RISC Systems", $UNWIND$ which for
276 some reason was left out, and sections specific to embedded stabs. */
278 static const struct section_to_type stt
[] = {
280 {"$SHLIB_INFO$", 't'},
281 {"$MILLICODE$", 't'},
284 {"$UNWIND_START$", 't'},
288 {"$SHLIB_DATA$", 'd'},
290 {"$SHORTDATA$", 'g'},
295 {"$GDB_STRINGS$", 'N'},
296 {"$GDB_SYMBOLS$", 'N'},
300 /* About the relocation formatting table...
302 There are 256 entries in the table, one for each possible
303 relocation opcode available in SOM. We index the table by
304 the relocation opcode. The names and operations are those
305 defined by a.out_800 (4).
307 Right now this table is only used to count and perform minimal
308 processing on relocation streams so that they can be internalized
309 into BFD and symbolically printed by utilities. To make actual use
310 of them would be much more difficult, BFD's concept of relocations
311 is far too simple to handle SOM relocations. The basic assumption
312 that a relocation can be completely processed independent of other
313 relocations before an object file is written is invalid for SOM.
315 The SOM relocations are meant to be processed as a stream, they
316 specify copying of data from the input section to the output section
317 while possibly modifying the data in some manner. They also can
318 specify that a variable number of zeros or uninitialized data be
319 inserted on in the output segment at the current offset. Some
320 relocations specify that some previous relocation be re-applied at
321 the current location in the input/output sections. And finally a number
322 of relocations have effects on other sections (R_ENTRY, R_EXIT,
323 R_UNWIND_AUX and a variety of others). There isn't even enough room
324 in the BFD relocation data structure to store enough information to
325 perform all the relocations.
327 Each entry in the table has three fields.
329 The first entry is an index into this "class" of relocations. This
330 index can then be used as a variable within the relocation itself.
332 The second field is a format string which actually controls processing
333 of the relocation. It uses a simple postfix machine to do calculations
334 based on variables/constants found in the string and the relocation
337 The third field specifys whether or not this relocation may use
338 a constant (V) from the previous R_DATA_OVERRIDE rather than a constant
339 stored in the instruction.
343 L = input space byte count
344 D = index into class of relocations
345 M = output space byte count
346 N = statement number (unused?)
348 R = parameter relocation bits
350 T = first 32 bits of stack unwind information
351 U = second 32 bits of stack unwind information
352 V = a literal constant (usually used in the next relocation)
353 P = a previous relocation
355 Lower case letters (starting with 'b') refer to following
356 bytes in the relocation stream. 'b' is the next 1 byte,
357 c is the next 2 bytes, d is the next 3 bytes, etc...
358 This is the variable part of the relocation entries that
359 makes our life a living hell.
361 numerical constants are also used in the format string. Note
362 the constants are represented in decimal.
364 '+', "*" and "=" represents the obvious postfix operators.
365 '<' represents a left shift.
369 Parameter Relocation Bits:
373 Previous Relocations: The index field represents which in the queue
374 of 4 previous fixups should be re-applied.
376 Literal Constants: These are generally used to represent addend
377 parts of relocations when these constants are not stored in the
378 fields of the instructions themselves. For example the instruction
379 addil foo-$global$-0x1234 would use an override for "0x1234" rather
380 than storing it into the addil itself. */
388 static const struct fixup_format som_fixup_formats
[256] =
390 /* R_NO_RELOCATION */
391 0, "LD1+4*=", /* 0x00 */
392 1, "LD1+4*=", /* 0x01 */
393 2, "LD1+4*=", /* 0x02 */
394 3, "LD1+4*=", /* 0x03 */
395 4, "LD1+4*=", /* 0x04 */
396 5, "LD1+4*=", /* 0x05 */
397 6, "LD1+4*=", /* 0x06 */
398 7, "LD1+4*=", /* 0x07 */
399 8, "LD1+4*=", /* 0x08 */
400 9, "LD1+4*=", /* 0x09 */
401 10, "LD1+4*=", /* 0x0a */
402 11, "LD1+4*=", /* 0x0b */
403 12, "LD1+4*=", /* 0x0c */
404 13, "LD1+4*=", /* 0x0d */
405 14, "LD1+4*=", /* 0x0e */
406 15, "LD1+4*=", /* 0x0f */
407 16, "LD1+4*=", /* 0x10 */
408 17, "LD1+4*=", /* 0x11 */
409 18, "LD1+4*=", /* 0x12 */
410 19, "LD1+4*=", /* 0x13 */
411 20, "LD1+4*=", /* 0x14 */
412 21, "LD1+4*=", /* 0x15 */
413 22, "LD1+4*=", /* 0x16 */
414 23, "LD1+4*=", /* 0x17 */
415 0, "LD8<b+1+4*=", /* 0x18 */
416 1, "LD8<b+1+4*=", /* 0x19 */
417 2, "LD8<b+1+4*=", /* 0x1a */
418 3, "LD8<b+1+4*=", /* 0x1b */
419 0, "LD16<c+1+4*=", /* 0x1c */
420 1, "LD16<c+1+4*=", /* 0x1d */
421 2, "LD16<c+1+4*=", /* 0x1e */
422 0, "Ld1+=", /* 0x1f */
424 0, "Lb1+4*=", /* 0x20 */
425 1, "Ld1+=", /* 0x21 */
427 0, "Lb1+4*=", /* 0x22 */
428 1, "Ld1+=", /* 0x23 */
431 /* R_DATA_ONE_SYMBOL */
432 0, "L4=Sb=", /* 0x25 */
433 1, "L4=Sd=", /* 0x26 */
435 0, "L4=Sb=", /* 0x27 */
436 1, "L4=Sd=", /* 0x28 */
439 /* R_REPEATED_INIT */
440 0, "L4=Mb1+4*=", /* 0x2a */
441 1, "Lb4*=Mb1+L*=", /* 0x2b */
442 2, "Lb4*=Md1+4*=", /* 0x2c */
443 3, "Ld1+=Me1+=", /* 0x2d */
447 0, "L4=RD=Sb=", /* 0x30 */
448 1, "L4=RD=Sb=", /* 0x31 */
449 2, "L4=RD=Sb=", /* 0x32 */
450 3, "L4=RD=Sb=", /* 0x33 */
451 4, "L4=RD=Sb=", /* 0x34 */
452 5, "L4=RD=Sb=", /* 0x35 */
453 6, "L4=RD=Sb=", /* 0x36 */
454 7, "L4=RD=Sb=", /* 0x37 */
455 8, "L4=RD=Sb=", /* 0x38 */
456 9, "L4=RD=Sb=", /* 0x39 */
457 0, "L4=RD8<b+=Sb=",/* 0x3a */
458 1, "L4=RD8<b+=Sb=",/* 0x3b */
459 0, "L4=RD8<b+=Sd=",/* 0x3c */
460 1, "L4=RD8<b+=Sd=",/* 0x3d */
461 /* R_SHORT_PCREL_MODE */
463 /* R_LONG_PCREL_MODE */
466 0, "L4=RD=Sb=", /* 0x40 */
467 1, "L4=RD=Sb=", /* 0x41 */
468 2, "L4=RD=Sb=", /* 0x42 */
469 3, "L4=RD=Sb=", /* 0x43 */
470 4, "L4=RD=Sb=", /* 0x44 */
471 5, "L4=RD=Sb=", /* 0x45 */
472 6, "L4=RD=Sb=", /* 0x46 */
473 7, "L4=RD=Sb=", /* 0x47 */
474 8, "L4=RD=Sb=", /* 0x48 */
475 9, "L4=RD=Sb=", /* 0x49 */
476 0, "L4=RD8<b+=Sb=",/* 0x4a */
477 1, "L4=RD8<b+=Sb=",/* 0x4b */
478 0, "L4=RD8<b+=Sd=",/* 0x4c */
479 1, "L4=RD8<b+=Sd=",/* 0x4d */
484 0, "L4=SD=", /* 0x50 */
485 1, "L4=SD=", /* 0x51 */
486 2, "L4=SD=", /* 0x52 */
487 3, "L4=SD=", /* 0x53 */
488 4, "L4=SD=", /* 0x54 */
489 5, "L4=SD=", /* 0x55 */
490 6, "L4=SD=", /* 0x56 */
491 7, "L4=SD=", /* 0x57 */
492 8, "L4=SD=", /* 0x58 */
493 9, "L4=SD=", /* 0x59 */
494 10, "L4=SD=", /* 0x5a */
495 11, "L4=SD=", /* 0x5b */
496 12, "L4=SD=", /* 0x5c */
497 13, "L4=SD=", /* 0x5d */
498 14, "L4=SD=", /* 0x5e */
499 15, "L4=SD=", /* 0x5f */
500 16, "L4=SD=", /* 0x60 */
501 17, "L4=SD=", /* 0x61 */
502 18, "L4=SD=", /* 0x62 */
503 19, "L4=SD=", /* 0x63 */
504 20, "L4=SD=", /* 0x64 */
505 21, "L4=SD=", /* 0x65 */
506 22, "L4=SD=", /* 0x66 */
507 23, "L4=SD=", /* 0x67 */
508 24, "L4=SD=", /* 0x68 */
509 25, "L4=SD=", /* 0x69 */
510 26, "L4=SD=", /* 0x6a */
511 27, "L4=SD=", /* 0x6b */
512 28, "L4=SD=", /* 0x6c */
513 29, "L4=SD=", /* 0x6d */
514 30, "L4=SD=", /* 0x6e */
515 31, "L4=SD=", /* 0x6f */
516 32, "L4=Sb=", /* 0x70 */
517 33, "L4=Sd=", /* 0x71 */
526 0, "L4=Sb=", /* 0x78 */
527 1, "L4=Sd=", /* 0x79 */
535 /* R_CODE_ONE_SYMBOL */
536 0, "L4=SD=", /* 0x80 */
537 1, "L4=SD=", /* 0x81 */
538 2, "L4=SD=", /* 0x82 */
539 3, "L4=SD=", /* 0x83 */
540 4, "L4=SD=", /* 0x84 */
541 5, "L4=SD=", /* 0x85 */
542 6, "L4=SD=", /* 0x86 */
543 7, "L4=SD=", /* 0x87 */
544 8, "L4=SD=", /* 0x88 */
545 9, "L4=SD=", /* 0x89 */
546 10, "L4=SD=", /* 0x8q */
547 11, "L4=SD=", /* 0x8b */
548 12, "L4=SD=", /* 0x8c */
549 13, "L4=SD=", /* 0x8d */
550 14, "L4=SD=", /* 0x8e */
551 15, "L4=SD=", /* 0x8f */
552 16, "L4=SD=", /* 0x90 */
553 17, "L4=SD=", /* 0x91 */
554 18, "L4=SD=", /* 0x92 */
555 19, "L4=SD=", /* 0x93 */
556 20, "L4=SD=", /* 0x94 */
557 21, "L4=SD=", /* 0x95 */
558 22, "L4=SD=", /* 0x96 */
559 23, "L4=SD=", /* 0x97 */
560 24, "L4=SD=", /* 0x98 */
561 25, "L4=SD=", /* 0x99 */
562 26, "L4=SD=", /* 0x9a */
563 27, "L4=SD=", /* 0x9b */
564 28, "L4=SD=", /* 0x9c */
565 29, "L4=SD=", /* 0x9d */
566 30, "L4=SD=", /* 0x9e */
567 31, "L4=SD=", /* 0x9f */
568 32, "L4=Sb=", /* 0xa0 */
569 33, "L4=Sd=", /* 0xa1 */
584 0, "L4=Sb=", /* 0xae */
585 1, "L4=Sd=", /* 0xaf */
587 0, "L4=Sb=", /* 0xb0 */
588 1, "L4=Sd=", /* 0xb1 */
592 0, "Te=Ue=", /* 0xb3 */
602 1, "Rb4*=", /* 0xb9 */
603 2, "Rd4*=", /* 0xba */
630 /* R_DATA_OVERRIDE */
639 0, "Sd=Vf=Ef=", /* 0xcf */
643 0, "Ob=Sd=", /* 0xd1 */
645 0, "Ob=Ve=", /* 0xd2 */
658 0, "Eb=Sd=Ve=", /* 0xda */
660 0, "Eb=Mb=", /* 0xdb */
664 0, "Ob=Ve=", /* 0xdd */
702 static const int comp1_opcodes
[] =
724 static const int comp2_opcodes
[] =
733 static const int comp3_opcodes
[] =
740 /* These apparently are not in older versions of hpux reloc.h (hpux7). */
742 #define R_DLT_REL 0x78
746 #define R_AUX_UNWIND 0xcf
750 #define R_SEC_STMT 0xd7
753 /* And these first appeared in hpux10. */
754 #ifndef R_SHORT_PCREL_MODE
755 #define NO_PCREL_MODES
756 #define R_SHORT_PCREL_MODE 0x3e
759 #ifndef R_LONG_PCREL_MODE
760 #define R_LONG_PCREL_MODE 0x3f
772 #define R_LINETAB 0xda
775 #ifndef R_LINETAB_ESC
776 #define R_LINETAB_ESC 0xdb
779 #ifndef R_LTP_OVERRIDE
780 #define R_LTP_OVERRIDE 0xdc
784 #define R_COMMENT 0xdd
787 #define SOM_HOWTO(TYPE, NAME) \
788 HOWTO(TYPE, 0, 0, 32, false, 0, 0, hppa_som_reloc, NAME, false, 0, 0, false)
790 static reloc_howto_type som_hppa_howto_table
[] =
792 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
793 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
794 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
795 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
796 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
797 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
798 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
799 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
800 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
801 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
802 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
803 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
804 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
805 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
806 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
807 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
808 SOM_HOWTO (R_NO_RELOCATION
, "R_NO_RELOCATION"),
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_ZEROES
, "R_ZEROES"),
825 SOM_HOWTO (R_ZEROES
, "R_ZEROES"),
826 SOM_HOWTO (R_UNINIT
, "R_UNINIT"),
827 SOM_HOWTO (R_UNINIT
, "R_UNINIT"),
828 SOM_HOWTO (R_RELOCATION
, "R_RELOCATION"),
829 SOM_HOWTO (R_DATA_ONE_SYMBOL
, "R_DATA_ONE_SYMBOL"),
830 SOM_HOWTO (R_DATA_ONE_SYMBOL
, "R_DATA_ONE_SYMBOL"),
831 SOM_HOWTO (R_DATA_PLABEL
, "R_DATA_PLABEL"),
832 SOM_HOWTO (R_DATA_PLABEL
, "R_DATA_PLABEL"),
833 SOM_HOWTO (R_SPACE_REF
, "R_SPACE_REF"),
834 SOM_HOWTO (R_REPEATED_INIT
, "REPEATED_INIT"),
835 SOM_HOWTO (R_REPEATED_INIT
, "REPEATED_INIT"),
836 SOM_HOWTO (R_REPEATED_INIT
, "REPEATED_INIT"),
837 SOM_HOWTO (R_REPEATED_INIT
, "REPEATED_INIT"),
838 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
839 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
840 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
841 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
842 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
843 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
844 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
845 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
846 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
847 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
848 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
849 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
850 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
851 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
852 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
853 SOM_HOWTO (R_PCREL_CALL
, "R_PCREL_CALL"),
854 SOM_HOWTO (R_SHORT_PCREL_MODE
, "R_SHORT_PCREL_MODE"),
855 SOM_HOWTO (R_LONG_PCREL_MODE
, "R_LONG_PCREL_MODE"),
856 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
857 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
858 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
859 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
860 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
861 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
862 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
863 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
864 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
865 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
866 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
867 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
868 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
869 SOM_HOWTO (R_ABS_CALL
, "R_ABS_CALL"),
870 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
871 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
872 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
873 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
874 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
875 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
876 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
877 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
878 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
879 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
880 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
881 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
882 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
883 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
884 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
885 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
886 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
887 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
888 SOM_HOWTO (R_DP_RELATIVE
, "R_DP_RELATIVE"),
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_RESERVED
, "R_RESERVED"),
908 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
909 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
910 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
911 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
912 SOM_HOWTO (R_DLT_REL
, "R_DLT_REL"),
913 SOM_HOWTO (R_DLT_REL
, "R_DLT_REL"),
914 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
915 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
916 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
917 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
918 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
919 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
920 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
921 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
922 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
923 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
924 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
925 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
926 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
927 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
928 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
929 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
930 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
931 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
932 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
933 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
934 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
935 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
936 SOM_HOWTO (R_CODE_ONE_SYMBOL
, "R_CODE_ONE_SYMBOL"),
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_RESERVED
, "R_RESERVED"),
956 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
957 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
958 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
959 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
960 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
961 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
962 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
963 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
964 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
965 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
966 SOM_HOWTO (R_MILLI_REL
, "R_MILLI_REL"),
967 SOM_HOWTO (R_MILLI_REL
, "R_MILLI_REL"),
968 SOM_HOWTO (R_CODE_PLABEL
, "R_CODE_PLABEL"),
969 SOM_HOWTO (R_CODE_PLABEL
, "R_CODE_PLABEL"),
970 SOM_HOWTO (R_BREAKPOINT
, "R_BREAKPOINT"),
971 SOM_HOWTO (R_ENTRY
, "R_ENTRY"),
972 SOM_HOWTO (R_ENTRY
, "R_ENTRY"),
973 SOM_HOWTO (R_ALT_ENTRY
, "R_ALT_ENTRY"),
974 SOM_HOWTO (R_EXIT
, "R_EXIT"),
975 SOM_HOWTO (R_BEGIN_TRY
, "R_BEGIN_TRY"),
976 SOM_HOWTO (R_END_TRY
, "R_END_TRY"),
977 SOM_HOWTO (R_END_TRY
, "R_END_TRY"),
978 SOM_HOWTO (R_END_TRY
, "R_END_TRY"),
979 SOM_HOWTO (R_BEGIN_BRTAB
, "R_BEGIN_BRTAB"),
980 SOM_HOWTO (R_END_BRTAB
, "R_END_BRTAB"),
981 SOM_HOWTO (R_STATEMENT
, "R_STATEMENT"),
982 SOM_HOWTO (R_STATEMENT
, "R_STATEMENT"),
983 SOM_HOWTO (R_STATEMENT
, "R_STATEMENT"),
984 SOM_HOWTO (R_DATA_EXPR
, "R_DATA_EXPR"),
985 SOM_HOWTO (R_CODE_EXPR
, "R_CODE_EXPR"),
986 SOM_HOWTO (R_FSEL
, "R_FSEL"),
987 SOM_HOWTO (R_LSEL
, "R_LSEL"),
988 SOM_HOWTO (R_RSEL
, "R_RSEL"),
989 SOM_HOWTO (R_N_MODE
, "R_N_MODE"),
990 SOM_HOWTO (R_S_MODE
, "R_S_MODE"),
991 SOM_HOWTO (R_D_MODE
, "R_D_MODE"),
992 SOM_HOWTO (R_R_MODE
, "R_R_MODE"),
993 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
994 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
995 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
996 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
997 SOM_HOWTO (R_DATA_OVERRIDE
, "R_DATA_OVERRIDE"),
998 SOM_HOWTO (R_TRANSLATED
, "R_TRANSLATED"),
999 SOM_HOWTO (R_AUX_UNWIND
, "R_AUX_UNWIND"),
1000 SOM_HOWTO (R_COMP1
, "R_COMP1"),
1001 SOM_HOWTO (R_COMP2
, "R_COMP2"),
1002 SOM_HOWTO (R_COMP3
, "R_COMP3"),
1003 SOM_HOWTO (R_PREV_FIXUP
, "R_PREV_FIXUP"),
1004 SOM_HOWTO (R_PREV_FIXUP
, "R_PREV_FIXUP"),
1005 SOM_HOWTO (R_PREV_FIXUP
, "R_PREV_FIXUP"),
1006 SOM_HOWTO (R_PREV_FIXUP
, "R_PREV_FIXUP"),
1007 SOM_HOWTO (R_SEC_STMT
, "R_SEC_STMT"),
1008 SOM_HOWTO (R_N0SEL
, "R_N0SEL"),
1009 SOM_HOWTO (R_N1SEL
, "R_N1SEL"),
1010 SOM_HOWTO (R_LINETAB
, "R_LINETAB"),
1011 SOM_HOWTO (R_LINETAB_ESC
, "R_LINETAB_ESC"),
1012 SOM_HOWTO (R_LTP_OVERRIDE
, "R_LTP_OVERRIDE"),
1013 SOM_HOWTO (R_COMMENT
, "R_COMMENT"),
1014 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1015 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1016 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1017 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1018 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1019 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1020 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1021 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1022 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1023 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1024 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1025 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1026 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1027 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1028 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1029 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
1030 SOM_HOWTO (R_RESERVED
, "R_RESERVED"),
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")};
1049 /* Initialize the SOM relocation queue. By definition the queue holds
1050 the last four multibyte fixups. */
1053 som_initialize_reloc_queue (queue
)
1054 struct reloc_queue
*queue
;
1056 queue
[0].reloc
= NULL
;
1058 queue
[1].reloc
= NULL
;
1060 queue
[2].reloc
= NULL
;
1062 queue
[3].reloc
= NULL
;
1066 /* Insert a new relocation into the relocation queue. */
1069 som_reloc_queue_insert (p
, size
, queue
)
1072 struct reloc_queue
*queue
;
1074 queue
[3].reloc
= queue
[2].reloc
;
1075 queue
[3].size
= queue
[2].size
;
1076 queue
[2].reloc
= queue
[1].reloc
;
1077 queue
[2].size
= queue
[1].size
;
1078 queue
[1].reloc
= queue
[0].reloc
;
1079 queue
[1].size
= queue
[0].size
;
1081 queue
[0].size
= size
;
1084 /* When an entry in the relocation queue is reused, the entry moves
1085 to the front of the queue. */
1088 som_reloc_queue_fix (queue
, index
)
1089 struct reloc_queue
*queue
;
1097 unsigned char *tmp1
= queue
[0].reloc
;
1098 unsigned int tmp2
= queue
[0].size
;
1099 queue
[0].reloc
= queue
[1].reloc
;
1100 queue
[0].size
= queue
[1].size
;
1101 queue
[1].reloc
= tmp1
;
1102 queue
[1].size
= tmp2
;
1108 unsigned char *tmp1
= queue
[0].reloc
;
1109 unsigned int tmp2
= queue
[0].size
;
1110 queue
[0].reloc
= queue
[2].reloc
;
1111 queue
[0].size
= queue
[2].size
;
1112 queue
[2].reloc
= queue
[1].reloc
;
1113 queue
[2].size
= queue
[1].size
;
1114 queue
[1].reloc
= tmp1
;
1115 queue
[1].size
= tmp2
;
1121 unsigned char *tmp1
= queue
[0].reloc
;
1122 unsigned int tmp2
= queue
[0].size
;
1123 queue
[0].reloc
= queue
[3].reloc
;
1124 queue
[0].size
= queue
[3].size
;
1125 queue
[3].reloc
= queue
[2].reloc
;
1126 queue
[3].size
= queue
[2].size
;
1127 queue
[2].reloc
= queue
[1].reloc
;
1128 queue
[2].size
= queue
[1].size
;
1129 queue
[1].reloc
= tmp1
;
1130 queue
[1].size
= tmp2
;
1136 /* Search for a particular relocation in the relocation queue. */
1139 som_reloc_queue_find (p
, size
, queue
)
1142 struct reloc_queue
*queue
;
1144 if (queue
[0].reloc
&& !memcmp (p
, queue
[0].reloc
, size
)
1145 && size
== queue
[0].size
)
1147 if (queue
[1].reloc
&& !memcmp (p
, queue
[1].reloc
, size
)
1148 && size
== queue
[1].size
)
1150 if (queue
[2].reloc
&& !memcmp (p
, queue
[2].reloc
, size
)
1151 && size
== queue
[2].size
)
1153 if (queue
[3].reloc
&& !memcmp (p
, queue
[3].reloc
, size
)
1154 && size
== queue
[3].size
)
1159 static unsigned char *
1160 try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, size
, queue
)
1161 bfd
*abfd ATTRIBUTE_UNUSED
;
1162 int *subspace_reloc_sizep
;
1165 struct reloc_queue
*queue
;
1167 int queue_index
= som_reloc_queue_find (p
, size
, queue
);
1169 if (queue_index
!= -1)
1171 /* Found this in a previous fixup. Undo the fixup we
1172 just built and use R_PREV_FIXUP instead. We saved
1173 a total of size - 1 bytes in the fixup stream. */
1174 bfd_put_8 (abfd
, R_PREV_FIXUP
+ queue_index
, p
);
1176 *subspace_reloc_sizep
+= 1;
1177 som_reloc_queue_fix (queue
, queue_index
);
1181 som_reloc_queue_insert (p
, size
, queue
);
1182 *subspace_reloc_sizep
+= size
;
1188 /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
1189 bytes without any relocation. Update the size of the subspace
1190 relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
1191 current pointer into the relocation stream. */
1193 static unsigned char *
1194 som_reloc_skip (abfd
, skip
, p
, subspace_reloc_sizep
, queue
)
1198 unsigned int *subspace_reloc_sizep
;
1199 struct reloc_queue
*queue
;
1201 /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
1202 then R_PREV_FIXUPs to get the difference down to a
1204 if (skip
>= 0x1000000)
1207 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 31, p
);
1208 bfd_put_8 (abfd
, 0xff, p
+ 1);
1209 bfd_put_16 (abfd
, 0xffff, p
+ 2);
1210 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1211 while (skip
>= 0x1000000)
1214 bfd_put_8 (abfd
, R_PREV_FIXUP
, p
);
1216 *subspace_reloc_sizep
+= 1;
1217 /* No need to adjust queue here since we are repeating the
1218 most recent fixup. */
1222 /* The difference must be less than 0x1000000. Use one
1223 more R_NO_RELOCATION entry to get to the right difference. */
1224 if ((skip
& 3) == 0 && skip
<= 0xc0000 && skip
> 0)
1226 /* Difference can be handled in a simple single-byte
1227 R_NO_RELOCATION entry. */
1230 bfd_put_8 (abfd
, R_NO_RELOCATION
+ (skip
>> 2) - 1, p
);
1231 *subspace_reloc_sizep
+= 1;
1234 /* Handle it with a two byte R_NO_RELOCATION entry. */
1235 else if (skip
<= 0x1000)
1237 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 24 + (((skip
>> 2) - 1) >> 8), p
);
1238 bfd_put_8 (abfd
, (skip
>> 2) - 1, p
+ 1);
1239 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1241 /* Handle it with a three byte R_NO_RELOCATION entry. */
1244 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 28 + (((skip
>> 2) - 1) >> 16), p
);
1245 bfd_put_16 (abfd
, (skip
>> 2) - 1, p
+ 1);
1246 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1249 /* Ugh. Punt and use a 4 byte entry. */
1252 bfd_put_8 (abfd
, R_NO_RELOCATION
+ 31, p
);
1253 bfd_put_8 (abfd
, (skip
- 1) >> 16, p
+ 1);
1254 bfd_put_16 (abfd
, skip
- 1, p
+ 2);
1255 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1260 /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
1261 from a BFD relocation. Update the size of the subspace relocation
1262 stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
1263 into the relocation stream. */
1265 static unsigned char *
1266 som_reloc_addend (abfd
, addend
, p
, subspace_reloc_sizep
, queue
)
1270 unsigned int *subspace_reloc_sizep
;
1271 struct reloc_queue
*queue
;
1273 if ((unsigned)(addend
) + 0x80 < 0x100)
1275 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 1, p
);
1276 bfd_put_8 (abfd
, addend
, p
+ 1);
1277 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1279 else if ((unsigned) (addend
) + 0x8000 < 0x10000)
1281 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 2, p
);
1282 bfd_put_16 (abfd
, addend
, p
+ 1);
1283 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1285 else if ((unsigned) (addend
) + 0x800000 < 0x1000000)
1287 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 3, p
);
1288 bfd_put_8 (abfd
, addend
>> 16, p
+ 1);
1289 bfd_put_16 (abfd
, addend
, p
+ 2);
1290 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 4, queue
);
1294 bfd_put_8 (abfd
, R_DATA_OVERRIDE
+ 4, p
);
1295 bfd_put_32 (abfd
, addend
, p
+ 1);
1296 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 5, queue
);
1301 /* Handle a single function call relocation. */
1303 static unsigned char *
1304 som_reloc_call (abfd
, p
, subspace_reloc_sizep
, bfd_reloc
, sym_num
, queue
)
1307 unsigned int *subspace_reloc_sizep
;
1310 struct reloc_queue
*queue
;
1312 int arg_bits
= HPPA_R_ARG_RELOC (bfd_reloc
->addend
);
1313 int rtn_bits
= arg_bits
& 0x3;
1316 /* You'll never believe all this is necessary to handle relocations
1317 for function calls. Having to compute and pack the argument
1318 relocation bits is the real nightmare.
1320 If you're interested in how this works, just forget it. You really
1321 do not want to know about this braindamage. */
1323 /* First see if this can be done with a "simple" relocation. Simple
1324 relocations have a symbol number < 0x100 and have simple encodings
1325 of argument relocations. */
1327 if (sym_num
< 0x100)
1339 case 1 << 8 | 1 << 6:
1340 case 1 << 8 | 1 << 6 | 1:
1343 case 1 << 8 | 1 << 6 | 1 << 4:
1344 case 1 << 8 | 1 << 6 | 1 << 4 | 1:
1347 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
1348 case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
1352 /* Not one of the easy encodings. This will have to be
1353 handled by the more complex code below. */
1359 /* Account for the return value too. */
1363 /* Emit a 2 byte relocation. Then see if it can be handled
1364 with a relocation which is already in the relocation queue. */
1365 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ type
, p
);
1366 bfd_put_8 (abfd
, sym_num
, p
+ 1);
1367 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 2, queue
);
1372 /* If this could not be handled with a simple relocation, then do a hard
1373 one. Hard relocations occur if the symbol number was too high or if
1374 the encoding of argument relocation bits is too complex. */
1377 /* Don't ask about these magic sequences. I took them straight
1378 from gas-1.36 which took them from the a.out man page. */
1380 if ((arg_bits
>> 6 & 0xf) == 0xe)
1383 type
+= (3 * (arg_bits
>> 8 & 3) + (arg_bits
>> 6 & 3)) * 40;
1384 if ((arg_bits
>> 2 & 0xf) == 0xe)
1387 type
+= (3 * (arg_bits
>> 4 & 3) + (arg_bits
>> 2 & 3)) * 4;
1389 /* Output the first two bytes of the relocation. These describe
1390 the length of the relocation and encoding style. */
1391 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 10
1392 + 2 * (sym_num
>= 0x100) + (type
>= 0x100),
1394 bfd_put_8 (abfd
, type
, p
+ 1);
1396 /* Now output the symbol index and see if this bizarre relocation
1397 just happened to be in the relocation queue. */
1398 if (sym_num
< 0x100)
1400 bfd_put_8 (abfd
, sym_num
, p
+ 2);
1401 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 3, queue
);
1405 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 2);
1406 bfd_put_16 (abfd
, sym_num
, p
+ 3);
1407 p
= try_prev_fixup (abfd
, subspace_reloc_sizep
, p
, 5, queue
);
1414 /* Return the logarithm of X, base 2, considering X unsigned.
1415 Abort -1 if X is not a power or two or is zero. */
1423 /* Test for 0 or a power of 2. */
1424 if (x
== 0 || x
!= (x
& -x
))
1427 while ((x
>>= 1) != 0)
1432 static bfd_reloc_status_type
1433 hppa_som_reloc (abfd
, reloc_entry
, symbol_in
, data
,
1434 input_section
, output_bfd
, error_message
)
1435 bfd
*abfd ATTRIBUTE_UNUSED
;
1436 arelent
*reloc_entry
;
1437 asymbol
*symbol_in ATTRIBUTE_UNUSED
;
1438 PTR data ATTRIBUTE_UNUSED
;
1439 asection
*input_section
;
1441 char **error_message ATTRIBUTE_UNUSED
;
1445 reloc_entry
->address
+= input_section
->output_offset
;
1446 return bfd_reloc_ok
;
1448 return bfd_reloc_ok
;
1451 /* Given a generic HPPA relocation type, the instruction format,
1452 and a field selector, return one or more appropriate SOM relocations. */
1455 hppa_som_gen_reloc_type (abfd
, base_type
, format
, field
, sym_diff
, sym
)
1459 enum hppa_reloc_field_selector_type_alt field
;
1463 int *final_type
, **final_types
;
1465 final_types
= (int **) bfd_alloc (abfd
, sizeof (int *) * 6);
1466 final_type
= (int *) bfd_alloc (abfd
, sizeof (int));
1467 if (!final_types
|| !final_type
)
1470 /* The field selector may require additional relocations to be
1471 generated. It's impossible to know at this moment if additional
1472 relocations will be needed, so we make them. The code to actually
1473 write the relocation/fixup stream is responsible for removing
1474 any redundant relocations. */
1481 final_types
[0] = final_type
;
1482 final_types
[1] = NULL
;
1483 final_types
[2] = NULL
;
1484 *final_type
= base_type
;
1490 final_types
[0] = (int *) bfd_alloc (abfd
, sizeof (int));
1491 if (!final_types
[0])
1493 if (field
== e_tsel
)
1494 *final_types
[0] = R_FSEL
;
1495 else if (field
== e_ltsel
)
1496 *final_types
[0] = R_LSEL
;
1498 *final_types
[0] = R_RSEL
;
1499 final_types
[1] = final_type
;
1500 final_types
[2] = NULL
;
1501 *final_type
= base_type
;
1506 final_types
[0] = (int *) bfd_alloc (abfd
, sizeof (int));
1507 if (!final_types
[0])
1509 *final_types
[0] = R_S_MODE
;
1510 final_types
[1] = final_type
;
1511 final_types
[2] = NULL
;
1512 *final_type
= base_type
;
1517 final_types
[0] = (int *) bfd_alloc (abfd
, sizeof (int));
1518 if (!final_types
[0])
1520 *final_types
[0] = R_N_MODE
;
1521 final_types
[1] = final_type
;
1522 final_types
[2] = NULL
;
1523 *final_type
= base_type
;
1528 final_types
[0] = (int *) bfd_alloc (abfd
, sizeof (int));
1529 if (!final_types
[0])
1531 *final_types
[0] = R_D_MODE
;
1532 final_types
[1] = final_type
;
1533 final_types
[2] = NULL
;
1534 *final_type
= base_type
;
1539 final_types
[0] = (int *) bfd_alloc (abfd
, sizeof (int));
1540 if (!final_types
[0])
1542 *final_types
[0] = R_R_MODE
;
1543 final_types
[1] = final_type
;
1544 final_types
[2] = NULL
;
1545 *final_type
= base_type
;
1549 final_types
[0] = (int *) bfd_alloc (abfd
, sizeof (int));
1550 if (!final_types
[0])
1552 *final_types
[0] = R_N1SEL
;
1553 final_types
[1] = final_type
;
1554 final_types
[2] = NULL
;
1555 *final_type
= base_type
;
1560 final_types
[0] = (int *) bfd_alloc (abfd
, sizeof (int));
1561 if (!final_types
[0])
1563 *final_types
[0] = R_N0SEL
;
1564 final_types
[1] = (int *) bfd_alloc (abfd
, sizeof (int));
1565 if (!final_types
[1])
1567 if (field
== e_nlsel
)
1568 *final_types
[1] = R_N_MODE
;
1570 *final_types
[1] = R_R_MODE
;
1571 final_types
[2] = final_type
;
1572 final_types
[3] = NULL
;
1573 *final_type
= base_type
;
1580 /* The difference of two symbols needs *very* special handling. */
1583 final_types
[0] = (int *)bfd_alloc (abfd
, sizeof (int));
1584 final_types
[1] = (int *)bfd_alloc (abfd
, sizeof (int));
1585 final_types
[2] = (int *)bfd_alloc (abfd
, sizeof (int));
1586 final_types
[3] = (int *)bfd_alloc (abfd
, sizeof (int));
1587 if (!final_types
[0] || !final_types
[1] || !final_types
[2])
1589 if (field
== e_fsel
)
1590 *final_types
[0] = R_FSEL
;
1591 else if (field
== e_rsel
)
1592 *final_types
[0] = R_RSEL
;
1593 else if (field
== e_lsel
)
1594 *final_types
[0] = R_LSEL
;
1595 *final_types
[1] = R_COMP2
;
1596 *final_types
[2] = R_COMP2
;
1597 *final_types
[3] = R_COMP1
;
1598 final_types
[4] = final_type
;
1600 *final_types
[4] = R_DATA_EXPR
;
1602 *final_types
[4] = R_CODE_EXPR
;
1603 final_types
[5] = NULL
;
1606 /* PLABELs get their own relocation type. */
1607 else if (field
== e_psel
1609 || field
== e_rpsel
)
1611 /* A PLABEL relocation that has a size of 32 bits must
1612 be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
1614 *final_type
= R_DATA_PLABEL
;
1616 *final_type
= R_CODE_PLABEL
;
1619 else if (field
== e_tsel
1621 || field
== e_rtsel
)
1622 *final_type
= R_DLT_REL
;
1623 /* A relocation in the data space is always a full 32bits. */
1624 else if (format
== 32)
1626 *final_type
= R_DATA_ONE_SYMBOL
;
1628 /* If there's no SOM symbol type associated with this BFD
1629 symbol, then set the symbol type to ST_DATA.
1631 Only do this if the type is going to default later when
1632 we write the object file.
1634 This is done so that the linker never encounters an
1635 R_DATA_ONE_SYMBOL reloc involving an ST_CODE symbol.
1637 This allows the compiler to generate exception handling
1640 Note that one day we may need to also emit BEGIN_BRTAB and
1641 END_BRTAB to prevent the linker from optimizing away insns
1642 in exception handling regions. */
1643 if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
1644 && (sym
->flags
& BSF_SECTION_SYM
) == 0
1645 && (sym
->flags
& BSF_FUNCTION
) == 0
1646 && ! bfd_is_com_section (sym
->section
))
1647 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_DATA
;
1653 /* More PLABEL special cases. */
1656 || field
== e_rpsel
)
1657 *final_type
= R_DATA_PLABEL
;
1660 case R_HPPA_COMPLEX
:
1661 /* The difference of two symbols needs *very* special handling. */
1664 final_types
[0] = (int *)bfd_alloc (abfd
, sizeof (int));
1665 final_types
[1] = (int *)bfd_alloc (abfd
, sizeof (int));
1666 final_types
[2] = (int *)bfd_alloc (abfd
, sizeof (int));
1667 final_types
[3] = (int *)bfd_alloc (abfd
, sizeof (int));
1668 if (!final_types
[0] || !final_types
[1] || !final_types
[2])
1670 if (field
== e_fsel
)
1671 *final_types
[0] = R_FSEL
;
1672 else if (field
== e_rsel
)
1673 *final_types
[0] = R_RSEL
;
1674 else if (field
== e_lsel
)
1675 *final_types
[0] = R_LSEL
;
1676 *final_types
[1] = R_COMP2
;
1677 *final_types
[2] = R_COMP2
;
1678 *final_types
[3] = R_COMP1
;
1679 final_types
[4] = final_type
;
1681 *final_types
[4] = R_DATA_EXPR
;
1683 *final_types
[4] = R_CODE_EXPR
;
1684 final_types
[5] = NULL
;
1691 case R_HPPA_ABS_CALL
:
1692 /* Right now we can default all these. */
1695 case R_HPPA_PCREL_CALL
:
1697 #ifndef NO_PCREL_MODES
1698 /* If we have short and long pcrel modes, then generate the proper
1699 mode selector, then the pcrel relocation. Redundant selectors
1700 will be eliminted as the relocs are sized and emitted. */
1701 final_types
[0] = (int *) bfd_alloc (abfd
, sizeof (int));
1702 if (!final_types
[0])
1705 *final_types
[0] = R_SHORT_PCREL_MODE
;
1707 *final_types
[0] = R_LONG_PCREL_MODE
;
1708 final_types
[1] = final_type
;
1709 final_types
[2] = NULL
;
1710 *final_type
= base_type
;
1718 /* Return the address of the correct entry in the PA SOM relocation
1722 static reloc_howto_type
*
1723 som_bfd_reloc_type_lookup (abfd
, code
)
1724 bfd
*abfd ATTRIBUTE_UNUSED
;
1725 bfd_reloc_code_real_type code
;
1727 if ((int) code
< (int) R_NO_RELOCATION
+ 255)
1729 BFD_ASSERT ((int) som_hppa_howto_table
[(int) code
].type
== (int) code
);
1730 return &som_hppa_howto_table
[(int) code
];
1733 return (reloc_howto_type
*) 0;
1736 /* Perform some initialization for an object. Save results of this
1737 initialization in the BFD. */
1739 static const bfd_target
*
1740 som_object_setup (abfd
, file_hdrp
, aux_hdrp
, current_offset
)
1742 struct header
*file_hdrp
;
1743 struct som_exec_auxhdr
*aux_hdrp
;
1744 unsigned long current_offset
;
1749 /* som_mkobject will set bfd_error if som_mkobject fails. */
1750 if (som_mkobject (abfd
) != true)
1753 /* Set BFD flags based on what information is available in the SOM. */
1754 abfd
->flags
= BFD_NO_FLAGS
;
1755 if (file_hdrp
->symbol_total
)
1756 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
1758 switch (file_hdrp
->a_magic
)
1761 abfd
->flags
|= (D_PAGED
| WP_TEXT
| EXEC_P
);
1764 abfd
->flags
|= (WP_TEXT
| EXEC_P
);
1767 abfd
->flags
|= (EXEC_P
);
1770 abfd
->flags
|= HAS_RELOC
;
1778 abfd
->flags
|= DYNAMIC
;
1785 /* Allocate space to hold the saved exec header information. */
1786 obj_som_exec_data (abfd
) = (struct som_exec_data
*)
1787 bfd_zalloc (abfd
, sizeof (struct som_exec_data
));
1788 if (obj_som_exec_data (abfd
) == NULL
)
1791 /* The braindamaged OSF1 linker switched exec_flags and exec_entry!
1793 We used to identify OSF1 binaries based on NEW_VERSION_ID, but
1794 apparently the latest HPUX linker is using NEW_VERSION_ID now.
1796 It's about time, OSF has used the new id since at least 1992;
1797 HPUX didn't start till nearly 1995!.
1799 The new approach examines the entry field. If it's zero or not 4
1800 byte aligned then it's not a proper code address and we guess it's
1801 really the executable flags. */
1803 for (section
= abfd
->sections
; section
; section
= section
->next
)
1805 if ((section
->flags
& SEC_CODE
) == 0)
1807 if (aux_hdrp
->exec_entry
>= section
->vma
1808 && aux_hdrp
->exec_entry
< section
->vma
+ section
->_cooked_size
)
1811 if (aux_hdrp
->exec_entry
== 0
1812 || (aux_hdrp
->exec_entry
& 0x3) != 0
1815 bfd_get_start_address (abfd
) = aux_hdrp
->exec_flags
;
1816 obj_som_exec_data (abfd
)->exec_flags
= aux_hdrp
->exec_entry
;
1820 bfd_get_start_address (abfd
) = aux_hdrp
->exec_entry
+ current_offset
;
1821 obj_som_exec_data (abfd
)->exec_flags
= aux_hdrp
->exec_flags
;
1824 bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, pa10
);
1825 bfd_get_symcount (abfd
) = file_hdrp
->symbol_total
;
1827 /* Initialize the saved symbol table and string table to NULL.
1828 Save important offsets and sizes from the SOM header into
1830 obj_som_stringtab (abfd
) = (char *) NULL
;
1831 obj_som_symtab (abfd
) = (som_symbol_type
*) NULL
;
1832 obj_som_sorted_syms (abfd
) = NULL
;
1833 obj_som_stringtab_size (abfd
) = file_hdrp
->symbol_strings_size
;
1834 obj_som_sym_filepos (abfd
) = file_hdrp
->symbol_location
+ current_offset
;
1835 obj_som_str_filepos (abfd
) = (file_hdrp
->symbol_strings_location
1837 obj_som_reloc_filepos (abfd
) = (file_hdrp
->fixup_request_location
1839 obj_som_exec_data (abfd
)->system_id
= file_hdrp
->system_id
;
1844 /* Convert all of the space and subspace info into BFD sections. Each space
1845 contains a number of subspaces, which in turn describe the mapping between
1846 regions of the exec file, and the address space that the program runs in.
1847 BFD sections which correspond to spaces will overlap the sections for the
1848 associated subspaces. */
1851 setup_sections (abfd
, file_hdr
, current_offset
)
1853 struct header
*file_hdr
;
1854 unsigned long current_offset
;
1856 char *space_strings
;
1857 unsigned int space_index
, i
;
1858 unsigned int total_subspaces
= 0;
1859 asection
**subspace_sections
, *section
;
1861 /* First, read in space names */
1863 space_strings
= bfd_malloc (file_hdr
->space_strings_size
);
1864 if (!space_strings
&& file_hdr
->space_strings_size
!= 0)
1867 if (bfd_seek (abfd
, current_offset
+ file_hdr
->space_strings_location
,
1870 if (bfd_read (space_strings
, 1, file_hdr
->space_strings_size
, abfd
)
1871 != file_hdr
->space_strings_size
)
1874 /* Loop over all of the space dictionaries, building up sections */
1875 for (space_index
= 0; space_index
< file_hdr
->space_total
; space_index
++)
1877 struct space_dictionary_record space
;
1878 struct subspace_dictionary_record subspace
, save_subspace
;
1880 asection
*space_asect
;
1883 /* Read the space dictionary element */
1885 (current_offset
+ file_hdr
->space_location
1886 + space_index
* sizeof space
),
1889 if (bfd_read (&space
, 1, sizeof space
, abfd
) != sizeof space
)
1892 /* Setup the space name string */
1893 space
.name
.n_name
= space
.name
.n_strx
+ space_strings
;
1895 /* Make a section out of it */
1896 newname
= bfd_alloc (abfd
, strlen (space
.name
.n_name
) + 1);
1899 strcpy (newname
, space
.name
.n_name
);
1901 space_asect
= bfd_make_section_anyway (abfd
, newname
);
1905 if (space
.is_loadable
== 0)
1906 space_asect
->flags
|= SEC_DEBUGGING
;
1908 /* Set up all the attributes for the space. */
1909 if (bfd_som_set_section_attributes (space_asect
, space
.is_defined
,
1910 space
.is_private
, space
.sort_key
,
1911 space
.space_number
) == false)
1914 /* If the space has no subspaces, then we're done. */
1915 if (space
.subspace_quantity
== 0)
1918 /* Now, read in the first subspace for this space */
1920 (current_offset
+ file_hdr
->subspace_location
1921 + space
.subspace_index
* sizeof subspace
),
1924 if (bfd_read (&subspace
, 1, sizeof subspace
, abfd
) != sizeof subspace
)
1926 /* Seek back to the start of the subspaces for loop below */
1928 (current_offset
+ file_hdr
->subspace_location
1929 + space
.subspace_index
* sizeof subspace
),
1933 /* Setup the start address and file loc from the first subspace record */
1934 space_asect
->vma
= subspace
.subspace_start
;
1935 space_asect
->filepos
= subspace
.file_loc_init_value
+ current_offset
;
1936 space_asect
->alignment_power
= log2 (subspace
.alignment
);
1937 if (space_asect
->alignment_power
== -1)
1940 /* Initialize save_subspace so we can reliably determine if this
1941 loop placed any useful values into it. */
1942 memset (&save_subspace
, 0, sizeof (struct subspace_dictionary_record
));
1944 /* Loop over the rest of the subspaces, building up more sections */
1945 for (subspace_index
= 0; subspace_index
< space
.subspace_quantity
;
1948 asection
*subspace_asect
;
1950 /* Read in the next subspace */
1951 if (bfd_read (&subspace
, 1, sizeof subspace
, abfd
)
1955 /* Setup the subspace name string */
1956 subspace
.name
.n_name
= subspace
.name
.n_strx
+ space_strings
;
1958 newname
= bfd_alloc (abfd
, strlen (subspace
.name
.n_name
) + 1);
1961 strcpy (newname
, subspace
.name
.n_name
);
1963 /* Make a section out of this subspace */
1964 subspace_asect
= bfd_make_section_anyway (abfd
, newname
);
1965 if (!subspace_asect
)
1968 /* Store private information about the section. */
1969 if (bfd_som_set_subsection_attributes (subspace_asect
, space_asect
,
1970 subspace
.access_control_bits
,
1972 subspace
.quadrant
) == false)
1975 /* Keep an easy mapping between subspaces and sections.
1976 Note we do not necessarily read the subspaces in the
1977 same order in which they appear in the object file.
1979 So to make the target index come out correctly, we
1980 store the location of the subspace header in target
1981 index, then sort using the location of the subspace
1982 header as the key. Then we can assign correct
1983 subspace indices. */
1985 subspace_asect
->target_index
= bfd_tell (abfd
) - sizeof (subspace
);
1987 /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
1988 by the access_control_bits in the subspace header. */
1989 switch (subspace
.access_control_bits
>> 4)
1991 /* Readonly data. */
1993 subspace_asect
->flags
|= SEC_DATA
| SEC_READONLY
;
1998 subspace_asect
->flags
|= SEC_DATA
;
2001 /* Readonly code and the gateways.
2002 Gateways have other attributes which do not map
2003 into anything BFD knows about. */
2009 subspace_asect
->flags
|= SEC_CODE
| SEC_READONLY
;
2012 /* dynamic (writable) code. */
2014 subspace_asect
->flags
|= SEC_CODE
;
2018 if (subspace
.dup_common
|| subspace
.is_common
)
2019 subspace_asect
->flags
|= SEC_IS_COMMON
;
2020 else if (subspace
.subspace_length
> 0)
2021 subspace_asect
->flags
|= SEC_HAS_CONTENTS
;
2023 if (subspace
.is_loadable
)
2024 subspace_asect
->flags
|= SEC_ALLOC
| SEC_LOAD
;
2026 subspace_asect
->flags
|= SEC_DEBUGGING
;
2028 if (subspace
.code_only
)
2029 subspace_asect
->flags
|= SEC_CODE
;
2031 /* Both file_loc_init_value and initialization_length will
2032 be zero for a BSS like subspace. */
2033 if (subspace
.file_loc_init_value
== 0
2034 && subspace
.initialization_length
== 0)
2035 subspace_asect
->flags
&= ~(SEC_DATA
| SEC_LOAD
| SEC_HAS_CONTENTS
);
2037 /* This subspace has relocations.
2038 The fixup_request_quantity is a byte count for the number of
2039 entries in the relocation stream; it is not the actual number
2040 of relocations in the subspace. */
2041 if (subspace
.fixup_request_quantity
!= 0)
2043 subspace_asect
->flags
|= SEC_RELOC
;
2044 subspace_asect
->rel_filepos
= subspace
.fixup_request_index
;
2045 som_section_data (subspace_asect
)->reloc_size
2046 = subspace
.fixup_request_quantity
;
2047 /* We can not determine this yet. When we read in the
2048 relocation table the correct value will be filled in. */
2049 subspace_asect
->reloc_count
= -1;
2052 /* Update save_subspace if appropriate. */
2053 if (subspace
.file_loc_init_value
> save_subspace
.file_loc_init_value
)
2054 save_subspace
= subspace
;
2056 subspace_asect
->vma
= subspace
.subspace_start
;
2057 subspace_asect
->_cooked_size
= subspace
.subspace_length
;
2058 subspace_asect
->_raw_size
= subspace
.subspace_length
;
2059 subspace_asect
->filepos
= (subspace
.file_loc_init_value
2061 subspace_asect
->alignment_power
= log2 (subspace
.alignment
);
2062 if (subspace_asect
->alignment_power
== -1)
2066 /* This can happen for a .o which defines symbols in otherwise
2068 if (!save_subspace
.file_loc_init_value
)
2070 space_asect
->_cooked_size
= 0;
2071 space_asect
->_raw_size
= 0;
2075 /* Setup the sizes for the space section based upon the info in the
2076 last subspace of the space. */
2077 space_asect
->_cooked_size
= (save_subspace
.subspace_start
2079 + save_subspace
.subspace_length
);
2080 space_asect
->_raw_size
= (save_subspace
.file_loc_init_value
2081 - space_asect
->filepos
2082 + save_subspace
.initialization_length
);
2085 /* Now that we've read in all the subspace records, we need to assign
2086 a target index to each subspace. */
2087 subspace_sections
= (asection
**) bfd_malloc (total_subspaces
2088 * sizeof (asection
*));
2089 if (subspace_sections
== NULL
)
2092 for (i
= 0, section
= abfd
->sections
; section
; section
= section
->next
)
2094 if (!som_is_subspace (section
))
2097 subspace_sections
[i
] = section
;
2100 qsort (subspace_sections
, total_subspaces
,
2101 sizeof (asection
*), compare_subspaces
);
2103 /* subspace_sections is now sorted in the order in which the subspaces
2104 appear in the object file. Assign an index to each one now. */
2105 for (i
= 0; i
< total_subspaces
; i
++)
2106 subspace_sections
[i
]->target_index
= i
;
2108 if (space_strings
!= NULL
)
2109 free (space_strings
);
2111 if (subspace_sections
!= NULL
)
2112 free (subspace_sections
);
2117 if (space_strings
!= NULL
)
2118 free (space_strings
);
2120 if (subspace_sections
!= NULL
)
2121 free (subspace_sections
);
2125 /* Read in a SOM object and make it into a BFD. */
2127 static const bfd_target
*
2131 struct header file_hdr
;
2132 struct som_exec_auxhdr aux_hdr
;
2133 unsigned long current_offset
= 0;
2134 struct lst_header lst_header
;
2135 struct som_entry som_entry
;
2136 #define ENTRY_SIZE sizeof(struct som_entry)
2138 if (bfd_read ((PTR
) & file_hdr
, 1, FILE_HDR_SIZE
, abfd
) != FILE_HDR_SIZE
)
2140 if (bfd_get_error () != bfd_error_system_call
)
2141 bfd_set_error (bfd_error_wrong_format
);
2145 if (!_PA_RISC_ID (file_hdr
.system_id
))
2147 bfd_set_error (bfd_error_wrong_format
);
2151 switch (file_hdr
.a_magic
)
2163 #ifdef SHARED_MAGIC_CNX
2164 case SHARED_MAGIC_CNX
:
2170 /* Read the lst header and determine where the SOM directory begins */
2172 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) < 0)
2174 if (bfd_get_error () != bfd_error_system_call
)
2175 bfd_set_error (bfd_error_wrong_format
);
2179 if (bfd_read ((PTR
) & lst_header
, 1, SLSTHDR
, abfd
) != SLSTHDR
)
2181 if (bfd_get_error () != bfd_error_system_call
)
2182 bfd_set_error (bfd_error_wrong_format
);
2186 /* Position to and read the first directory entry */
2188 if (bfd_seek (abfd
, lst_header
.dir_loc
, SEEK_SET
) < 0)
2190 if (bfd_get_error () != bfd_error_system_call
)
2191 bfd_set_error (bfd_error_wrong_format
);
2195 if (bfd_read ((PTR
) & som_entry
, 1, ENTRY_SIZE
, abfd
) != ENTRY_SIZE
)
2197 if (bfd_get_error () != bfd_error_system_call
)
2198 bfd_set_error (bfd_error_wrong_format
);
2202 /* Now position to the first SOM */
2204 if (bfd_seek (abfd
, som_entry
.location
, SEEK_SET
) < 0)
2206 if (bfd_get_error () != bfd_error_system_call
)
2207 bfd_set_error (bfd_error_wrong_format
);
2211 current_offset
= som_entry
.location
;
2213 /* And finally, re-read the som header */
2215 if (bfd_read ((PTR
) & file_hdr
, 1, FILE_HDR_SIZE
, abfd
) != FILE_HDR_SIZE
)
2217 if (bfd_get_error () != bfd_error_system_call
)
2218 bfd_set_error (bfd_error_wrong_format
);
2226 bfd_set_error (bfd_error_wrong_format
);
2230 if (file_hdr
.version_id
!= VERSION_ID
2231 && file_hdr
.version_id
!= NEW_VERSION_ID
)
2233 bfd_set_error (bfd_error_wrong_format
);
2237 /* If the aux_header_size field in the file header is zero, then this
2238 object is an incomplete executable (a .o file). Do not try to read
2239 a non-existant auxiliary header. */
2240 memset (&aux_hdr
, 0, sizeof (struct som_exec_auxhdr
));
2241 if (file_hdr
.aux_header_size
!= 0)
2243 if (bfd_read ((PTR
) & aux_hdr
, 1, AUX_HDR_SIZE
, abfd
) != AUX_HDR_SIZE
)
2245 if (bfd_get_error () != bfd_error_system_call
)
2246 bfd_set_error (bfd_error_wrong_format
);
2251 if (!setup_sections (abfd
, &file_hdr
, current_offset
))
2253 /* setup_sections does not bubble up a bfd error code. */
2254 bfd_set_error (bfd_error_bad_value
);
2258 /* This appears to be a valid SOM object. Do some initialization. */
2259 return som_object_setup (abfd
, &file_hdr
, &aux_hdr
, current_offset
);
2262 /* Create a SOM object. */
2268 /* Allocate memory to hold backend information. */
2269 abfd
->tdata
.som_data
= (struct som_data_struct
*)
2270 bfd_zalloc (abfd
, sizeof (struct som_data_struct
));
2271 if (abfd
->tdata
.som_data
== NULL
)
2276 /* Initialize some information in the file header. This routine makes
2277 not attempt at doing the right thing for a full executable; it
2278 is only meant to handle relocatable objects. */
2281 som_prep_headers (abfd
)
2284 struct header
*file_hdr
;
2287 /* Make and attach a file header to the BFD. */
2288 file_hdr
= (struct header
*) bfd_zalloc (abfd
, sizeof (struct header
));
2289 if (file_hdr
== NULL
)
2291 obj_som_file_hdr (abfd
) = file_hdr
;
2293 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
2296 /* Make and attach an exec header to the BFD. */
2297 obj_som_exec_hdr (abfd
) = (struct som_exec_auxhdr
*)
2298 bfd_zalloc (abfd
, sizeof (struct som_exec_auxhdr
));
2299 if (obj_som_exec_hdr (abfd
) == NULL
)
2302 if (abfd
->flags
& D_PAGED
)
2303 file_hdr
->a_magic
= DEMAND_MAGIC
;
2304 else if (abfd
->flags
& WP_TEXT
)
2305 file_hdr
->a_magic
= SHARE_MAGIC
;
2307 else if (abfd
->flags
& DYNAMIC
)
2308 file_hdr
->a_magic
= SHL_MAGIC
;
2311 file_hdr
->a_magic
= EXEC_MAGIC
;
2314 file_hdr
->a_magic
= RELOC_MAGIC
;
2316 /* Only new format SOM is supported. */
2317 file_hdr
->version_id
= NEW_VERSION_ID
;
2319 /* These fields are optional, and embedding timestamps is not always
2320 a wise thing to do, it makes comparing objects during a multi-stage
2321 bootstrap difficult. */
2322 file_hdr
->file_time
.secs
= 0;
2323 file_hdr
->file_time
.nanosecs
= 0;
2325 file_hdr
->entry_space
= 0;
2326 file_hdr
->entry_subspace
= 0;
2327 file_hdr
->entry_offset
= 0;
2328 file_hdr
->presumed_dp
= 0;
2330 /* Now iterate over the sections translating information from
2331 BFD sections to SOM spaces/subspaces. */
2333 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2335 /* Ignore anything which has not been marked as a space or
2337 if (!som_is_space (section
) && !som_is_subspace (section
))
2340 if (som_is_space (section
))
2342 /* Allocate space for the space dictionary. */
2343 som_section_data (section
)->space_dict
2344 = (struct space_dictionary_record
*)
2345 bfd_zalloc (abfd
, sizeof (struct space_dictionary_record
));
2346 if (som_section_data (section
)->space_dict
== NULL
)
2348 /* Set space attributes. Note most attributes of SOM spaces
2349 are set based on the subspaces it contains. */
2350 som_section_data (section
)->space_dict
->loader_fix_index
= -1;
2351 som_section_data (section
)->space_dict
->init_pointer_index
= -1;
2353 /* Set more attributes that were stuffed away in private data. */
2354 som_section_data (section
)->space_dict
->sort_key
=
2355 som_section_data (section
)->copy_data
->sort_key
;
2356 som_section_data (section
)->space_dict
->is_defined
=
2357 som_section_data (section
)->copy_data
->is_defined
;
2358 som_section_data (section
)->space_dict
->is_private
=
2359 som_section_data (section
)->copy_data
->is_private
;
2360 som_section_data (section
)->space_dict
->space_number
=
2361 som_section_data (section
)->copy_data
->space_number
;
2365 /* Allocate space for the subspace dictionary. */
2366 som_section_data (section
)->subspace_dict
2367 = (struct subspace_dictionary_record
*)
2368 bfd_zalloc (abfd
, sizeof (struct subspace_dictionary_record
));
2369 if (som_section_data (section
)->subspace_dict
== NULL
)
2372 /* Set subspace attributes. Basic stuff is done here, additional
2373 attributes are filled in later as more information becomes
2375 if (section
->flags
& SEC_IS_COMMON
)
2377 som_section_data (section
)->subspace_dict
->dup_common
= 1;
2378 som_section_data (section
)->subspace_dict
->is_common
= 1;
2381 if (section
->flags
& SEC_ALLOC
)
2382 som_section_data (section
)->subspace_dict
->is_loadable
= 1;
2384 if (section
->flags
& SEC_CODE
)
2385 som_section_data (section
)->subspace_dict
->code_only
= 1;
2387 som_section_data (section
)->subspace_dict
->subspace_start
=
2389 som_section_data (section
)->subspace_dict
->subspace_length
=
2390 bfd_section_size (abfd
, section
);
2391 som_section_data (section
)->subspace_dict
->initialization_length
=
2392 bfd_section_size (abfd
, section
);
2393 som_section_data (section
)->subspace_dict
->alignment
=
2394 1 << section
->alignment_power
;
2396 /* Set more attributes that were stuffed away in private data. */
2397 som_section_data (section
)->subspace_dict
->sort_key
=
2398 som_section_data (section
)->copy_data
->sort_key
;
2399 som_section_data (section
)->subspace_dict
->access_control_bits
=
2400 som_section_data (section
)->copy_data
->access_control_bits
;
2401 som_section_data (section
)->subspace_dict
->quadrant
=
2402 som_section_data (section
)->copy_data
->quadrant
;
2408 /* Return true if the given section is a SOM space, false otherwise. */
2411 som_is_space (section
)
2414 /* If no copy data is available, then it's neither a space nor a
2416 if (som_section_data (section
)->copy_data
== NULL
)
2419 /* If the containing space isn't the same as the given section,
2420 then this isn't a space. */
2421 if (som_section_data (section
)->copy_data
->container
!= section
2422 && (som_section_data (section
)->copy_data
->container
->output_section
2426 /* OK. Must be a space. */
2430 /* Return true if the given section is a SOM subspace, false otherwise. */
2433 som_is_subspace (section
)
2436 /* If no copy data is available, then it's neither a space nor a
2438 if (som_section_data (section
)->copy_data
== NULL
)
2441 /* If the containing space is the same as the given section,
2442 then this isn't a subspace. */
2443 if (som_section_data (section
)->copy_data
->container
== section
2444 || (som_section_data (section
)->copy_data
->container
->output_section
2448 /* OK. Must be a subspace. */
2452 /* Return true if the given space containins the given subspace. It
2453 is safe to assume space really is a space, and subspace really
2457 som_is_container (space
, subspace
)
2458 asection
*space
, *subspace
;
2460 return (som_section_data (subspace
)->copy_data
->container
== space
2461 || (som_section_data (subspace
)->copy_data
->container
->output_section
2465 /* Count and return the number of spaces attached to the given BFD. */
2467 static unsigned long
2468 som_count_spaces (abfd
)
2474 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2475 count
+= som_is_space (section
);
2480 /* Count the number of subspaces attached to the given BFD. */
2482 static unsigned long
2483 som_count_subspaces (abfd
)
2489 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2490 count
+= som_is_subspace (section
);
2495 /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
2497 We desire symbols to be ordered starting with the symbol with the
2498 highest relocation count down to the symbol with the lowest relocation
2499 count. Doing so compacts the relocation stream. */
2502 compare_syms (arg1
, arg2
)
2507 asymbol
**sym1
= (asymbol
**) arg1
;
2508 asymbol
**sym2
= (asymbol
**) arg2
;
2509 unsigned int count1
, count2
;
2511 /* Get relocation count for each symbol. Note that the count
2512 is stored in the udata pointer for section symbols! */
2513 if ((*sym1
)->flags
& BSF_SECTION_SYM
)
2514 count1
= (*sym1
)->udata
.i
;
2516 count1
= som_symbol_data (*sym1
)->reloc_count
;
2518 if ((*sym2
)->flags
& BSF_SECTION_SYM
)
2519 count2
= (*sym2
)->udata
.i
;
2521 count2
= som_symbol_data (*sym2
)->reloc_count
;
2523 /* Return the appropriate value. */
2524 if (count1
< count2
)
2526 else if (count1
> count2
)
2531 /* Return -1, 0, 1 indicating the relative ordering of subspace1
2535 compare_subspaces (arg1
, arg2
)
2540 asection
**subspace1
= (asection
**) arg1
;
2541 asection
**subspace2
= (asection
**) arg2
;
2543 if ((*subspace1
)->target_index
< (*subspace2
)->target_index
)
2545 else if ((*subspace2
)->target_index
< (*subspace1
)->target_index
)
2551 /* Perform various work in preparation for emitting the fixup stream. */
2554 som_prep_for_fixups (abfd
, syms
, num_syms
)
2557 unsigned long num_syms
;
2561 asymbol
**sorted_syms
;
2563 /* Most SOM relocations involving a symbol have a length which is
2564 dependent on the index of the symbol. So symbols which are
2565 used often in relocations should have a small index. */
2567 /* First initialize the counters for each symbol. */
2568 for (i
= 0; i
< num_syms
; i
++)
2570 /* Handle a section symbol; these have no pointers back to the
2571 SOM symbol info. So we just use the udata field to hold the
2572 relocation count. */
2573 if (som_symbol_data (syms
[i
]) == NULL
2574 || syms
[i
]->flags
& BSF_SECTION_SYM
)
2576 syms
[i
]->flags
|= BSF_SECTION_SYM
;
2577 syms
[i
]->udata
.i
= 0;
2580 som_symbol_data (syms
[i
])->reloc_count
= 0;
2583 /* Now that the counters are initialized, make a weighted count
2584 of how often a given symbol is used in a relocation. */
2585 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
2589 /* Does this section have any relocations? */
2590 if (section
->reloc_count
<= 0)
2593 /* Walk through each relocation for this section. */
2594 for (i
= 1; i
< section
->reloc_count
; i
++)
2596 arelent
*reloc
= section
->orelocation
[i
];
2599 /* A relocation against a symbol in the *ABS* section really
2600 does not have a symbol. Likewise if the symbol isn't associated
2601 with any section. */
2602 if (reloc
->sym_ptr_ptr
== NULL
2603 || bfd_is_abs_section ((*reloc
->sym_ptr_ptr
)->section
))
2606 /* Scaling to encourage symbols involved in R_DP_RELATIVE
2607 and R_CODE_ONE_SYMBOL relocations to come first. These
2608 two relocations have single byte versions if the symbol
2609 index is very small. */
2610 if (reloc
->howto
->type
== R_DP_RELATIVE
2611 || reloc
->howto
->type
== R_CODE_ONE_SYMBOL
)
2616 /* Handle section symbols by storing the count in the udata
2617 field. It will not be used and the count is very important
2618 for these symbols. */
2619 if ((*reloc
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
)
2621 (*reloc
->sym_ptr_ptr
)->udata
.i
=
2622 (*reloc
->sym_ptr_ptr
)->udata
.i
+ scale
;
2626 /* A normal symbol. Increment the count. */
2627 som_symbol_data (*reloc
->sym_ptr_ptr
)->reloc_count
+= scale
;
2631 /* Sort a copy of the symbol table, rather than the canonical
2632 output symbol table. */
2633 sorted_syms
= (asymbol
**) bfd_zalloc (abfd
, num_syms
* sizeof (asymbol
*));
2634 memcpy (sorted_syms
, syms
, num_syms
* sizeof (asymbol
*));
2635 qsort (sorted_syms
, num_syms
, sizeof (asymbol
*), compare_syms
);
2636 obj_som_sorted_syms (abfd
) = sorted_syms
;
2638 /* Compute the symbol indexes, they will be needed by the relocation
2640 for (i
= 0; i
< num_syms
; i
++)
2642 /* A section symbol. Again, there is no pointer to backend symbol
2643 information, so we reuse the udata field again. */
2644 if (sorted_syms
[i
]->flags
& BSF_SECTION_SYM
)
2645 sorted_syms
[i
]->udata
.i
= i
;
2647 som_symbol_data (sorted_syms
[i
])->index
= i
;
2652 som_write_fixups (abfd
, current_offset
, total_reloc_sizep
)
2654 unsigned long current_offset
;
2655 unsigned int *total_reloc_sizep
;
2658 /* Chunk of memory that we can use as buffer space, then throw
2660 unsigned char tmp_space
[SOM_TMP_BUFSIZE
];
2662 unsigned int total_reloc_size
= 0;
2663 unsigned int subspace_reloc_size
= 0;
2664 unsigned int num_spaces
= obj_som_file_hdr (abfd
)->space_total
;
2665 asection
*section
= abfd
->sections
;
2667 memset (tmp_space
, 0, SOM_TMP_BUFSIZE
);
2670 /* All the fixups for a particular subspace are emitted in a single
2671 stream. All the subspaces for a particular space are emitted
2674 So, to get all the locations correct one must iterate through all the
2675 spaces, for each space iterate through its subspaces and output a
2677 for (i
= 0; i
< num_spaces
; i
++)
2679 asection
*subsection
;
2682 while (!som_is_space (section
))
2683 section
= section
->next
;
2685 /* Now iterate through each of its subspaces. */
2686 for (subsection
= abfd
->sections
;
2688 subsection
= subsection
->next
)
2690 int reloc_offset
, current_rounding_mode
;
2691 #ifndef NO_PCREL_MODES
2692 int current_call_mode
;
2695 /* Find a subspace of this space. */
2696 if (!som_is_subspace (subsection
)
2697 || !som_is_container (section
, subsection
))
2700 /* If this subspace does not have real data, then we are
2702 if ((subsection
->flags
& SEC_HAS_CONTENTS
) == 0)
2704 som_section_data (subsection
)->subspace_dict
->fixup_request_index
2709 /* This subspace has some relocations. Put the relocation stream
2710 index into the subspace record. */
2711 som_section_data (subsection
)->subspace_dict
->fixup_request_index
2714 /* To make life easier start over with a clean slate for
2715 each subspace. Seek to the start of the relocation stream
2716 for this subspace in preparation for writing out its fixup
2718 if (bfd_seek (abfd
, current_offset
+ total_reloc_size
, SEEK_SET
) < 0)
2721 /* Buffer space has already been allocated. Just perform some
2722 initialization here. */
2724 subspace_reloc_size
= 0;
2726 som_initialize_reloc_queue (reloc_queue
);
2727 current_rounding_mode
= R_N_MODE
;
2728 #ifndef NO_PCREL_MODES
2729 current_call_mode
= R_SHORT_PCREL_MODE
;
2732 /* Translate each BFD relocation into one or more SOM
2734 for (j
= 0; j
< subsection
->reloc_count
; j
++)
2736 arelent
*bfd_reloc
= subsection
->orelocation
[j
];
2740 /* Get the symbol number. Remember it's stored in a
2741 special place for section symbols. */
2742 if ((*bfd_reloc
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
)
2743 sym_num
= (*bfd_reloc
->sym_ptr_ptr
)->udata
.i
;
2745 sym_num
= som_symbol_data (*bfd_reloc
->sym_ptr_ptr
)->index
;
2747 /* If there is not enough room for the next couple relocations,
2748 then dump the current buffer contents now. Also reinitialize
2749 the relocation queue.
2751 No single BFD relocation could ever translate into more
2752 than 100 bytes of SOM relocations (20bytes is probably the
2753 upper limit, but leave lots of space for growth). */
2754 if (p
- tmp_space
+ 100 > SOM_TMP_BUFSIZE
)
2756 if (bfd_write ((PTR
) tmp_space
, p
- tmp_space
, 1, abfd
)
2761 som_initialize_reloc_queue (reloc_queue
);
2764 /* Emit R_NO_RELOCATION fixups to map any bytes which were
2766 skip
= bfd_reloc
->address
- reloc_offset
;
2767 p
= som_reloc_skip (abfd
, skip
, p
,
2768 &subspace_reloc_size
, reloc_queue
);
2770 /* Update reloc_offset for the next iteration.
2772 Many relocations do not consume input bytes. They
2773 are markers, or set state necessary to perform some
2774 later relocation. */
2775 switch (bfd_reloc
->howto
->type
)
2795 #ifndef NO_PCREL_MODES
2796 case R_SHORT_PCREL_MODE
:
2797 case R_LONG_PCREL_MODE
:
2799 reloc_offset
= bfd_reloc
->address
;
2803 reloc_offset
= bfd_reloc
->address
+ 4;
2807 /* Now the actual relocation we care about. */
2808 switch (bfd_reloc
->howto
->type
)
2812 p
= som_reloc_call (abfd
, p
, &subspace_reloc_size
,
2813 bfd_reloc
, sym_num
, reloc_queue
);
2816 case R_CODE_ONE_SYMBOL
:
2818 /* Account for any addend. */
2819 if (bfd_reloc
->addend
)
2820 p
= som_reloc_addend (abfd
, bfd_reloc
->addend
, p
,
2821 &subspace_reloc_size
, reloc_queue
);
2825 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ sym_num
, p
);
2826 subspace_reloc_size
+= 1;
2829 else if (sym_num
< 0x100)
2831 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 32, p
);
2832 bfd_put_8 (abfd
, sym_num
, p
+ 1);
2833 p
= try_prev_fixup (abfd
, &subspace_reloc_size
, p
,
2836 else if (sym_num
< 0x10000000)
2838 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 33, p
);
2839 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 1);
2840 bfd_put_16 (abfd
, sym_num
, p
+ 2);
2841 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2848 case R_DATA_ONE_SYMBOL
:
2852 /* Account for any addend using R_DATA_OVERRIDE. */
2853 if (bfd_reloc
->howto
->type
!= R_DATA_ONE_SYMBOL
2854 && bfd_reloc
->addend
)
2855 p
= som_reloc_addend (abfd
, bfd_reloc
->addend
, p
,
2856 &subspace_reloc_size
, reloc_queue
);
2858 if (sym_num
< 0x100)
2860 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2861 bfd_put_8 (abfd
, sym_num
, p
+ 1);
2862 p
= try_prev_fixup (abfd
, &subspace_reloc_size
, p
,
2865 else if (sym_num
< 0x10000000)
2867 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 1, p
);
2868 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 1);
2869 bfd_put_16 (abfd
, sym_num
, p
+ 2);
2870 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2880 arelent
*tmp_reloc
= NULL
;
2881 bfd_put_8 (abfd
, R_ENTRY
, p
);
2883 /* R_ENTRY relocations have 64 bits of associated
2884 data. Unfortunately the addend field of a bfd
2885 relocation is only 32 bits. So, we split up
2886 the 64bit unwind information and store part in
2887 the R_ENTRY relocation, and the rest in the R_EXIT
2889 bfd_put_32 (abfd
, bfd_reloc
->addend
, p
+ 1);
2891 /* Find the next R_EXIT relocation. */
2892 for (tmp
= j
; tmp
< subsection
->reloc_count
; tmp
++)
2894 tmp_reloc
= subsection
->orelocation
[tmp
];
2895 if (tmp_reloc
->howto
->type
== R_EXIT
)
2899 if (tmp
== subsection
->reloc_count
)
2902 bfd_put_32 (abfd
, tmp_reloc
->addend
, p
+ 5);
2903 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2912 /* If this relocation requests the current rounding
2913 mode, then it is redundant. */
2914 if (bfd_reloc
->howto
->type
!= current_rounding_mode
)
2916 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2917 subspace_reloc_size
+= 1;
2919 current_rounding_mode
= bfd_reloc
->howto
->type
;
2923 #ifndef NO_PCREL_MODES
2924 case R_LONG_PCREL_MODE
:
2925 case R_SHORT_PCREL_MODE
:
2926 if (bfd_reloc
->howto
->type
!= current_call_mode
)
2928 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2929 subspace_reloc_size
+= 1;
2931 current_call_mode
= bfd_reloc
->howto
->type
;
2946 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2947 subspace_reloc_size
+= 1;
2952 /* The end of a exception handling region. The reloc's
2953 addend contains the offset of the exception handling
2955 if (bfd_reloc
->addend
== 0)
2956 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2957 else if (bfd_reloc
->addend
< 1024)
2959 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 1, p
);
2960 bfd_put_8 (abfd
, bfd_reloc
->addend
/ 4, p
+ 1);
2961 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2966 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
+ 2, p
);
2967 bfd_put_8 (abfd
, (bfd_reloc
->addend
/ 4) >> 16, p
+ 1);
2968 bfd_put_16 (abfd
, bfd_reloc
->addend
/ 4, p
+ 2);
2969 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2975 /* The only time we generate R_COMP1, R_COMP2 and
2976 R_CODE_EXPR relocs is for the difference of two
2977 symbols. Hence we can cheat here. */
2978 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2979 bfd_put_8 (abfd
, 0x44, p
+ 1);
2980 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2985 /* The only time we generate R_COMP1, R_COMP2 and
2986 R_CODE_EXPR relocs is for the difference of two
2987 symbols. Hence we can cheat here. */
2988 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
2989 bfd_put_8 (abfd
, 0x80, p
+ 1);
2990 bfd_put_8 (abfd
, sym_num
>> 16, p
+ 2);
2991 bfd_put_16 (abfd
, sym_num
, p
+ 3);
2992 p
= try_prev_fixup (abfd
, &subspace_reloc_size
,
2998 /* The only time we generate R_COMP1, R_COMP2 and
2999 R_CODE_EXPR relocs is for the difference of two
3000 symbols. Hence we can cheat here. */
3001 bfd_put_8 (abfd
, bfd_reloc
->howto
->type
, p
);
3002 subspace_reloc_size
+= 1;
3006 /* Put a "R_RESERVED" relocation in the stream if
3007 we hit something we do not understand. The linker
3008 will complain loudly if this ever happens. */
3010 bfd_put_8 (abfd
, 0xff, p
);
3011 subspace_reloc_size
+= 1;
3017 /* Last BFD relocation for a subspace has been processed.
3018 Map the rest of the subspace with R_NO_RELOCATION fixups. */
3019 p
= som_reloc_skip (abfd
, bfd_section_size (abfd
, subsection
)
3021 p
, &subspace_reloc_size
, reloc_queue
);
3023 /* Scribble out the relocations. */
3024 if (bfd_write ((PTR
) tmp_space
, p
- tmp_space
, 1, abfd
)
3029 total_reloc_size
+= subspace_reloc_size
;
3030 som_section_data (subsection
)->subspace_dict
->fixup_request_quantity
3031 = subspace_reloc_size
;
3033 section
= section
->next
;
3035 *total_reloc_sizep
= total_reloc_size
;
3039 /* Write out the space/subspace string table. */
3042 som_write_space_strings (abfd
, current_offset
, string_sizep
)
3044 unsigned long current_offset
;
3045 unsigned int *string_sizep
;
3047 /* Chunk of memory that we can use as buffer space, then throw
3049 size_t tmp_space_size
= SOM_TMP_BUFSIZE
;
3050 unsigned char *tmp_space
= alloca (tmp_space_size
);
3051 unsigned char *p
= tmp_space
;
3052 unsigned int strings_size
= 0;
3055 /* Seek to the start of the space strings in preparation for writing
3057 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) < 0)
3060 /* Walk through all the spaces and subspaces (order is not important)
3061 building up and writing string table entries for their names. */
3062 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
3066 /* Only work with space/subspaces; avoid any other sections
3067 which might have been made (.text for example). */
3068 if (!som_is_space (section
) && !som_is_subspace (section
))
3071 /* Get the length of the space/subspace name. */
3072 length
= strlen (section
->name
);
3074 /* If there is not enough room for the next entry, then dump the
3075 current buffer contents now and maybe allocate a larger
3076 buffer. Each entry will take 4 bytes to hold the string
3077 length + the string itself + null terminator. */
3078 if (p
- tmp_space
+ 5 + length
> tmp_space_size
)
3080 /* Flush buffer before refilling or reallocating. */
3081 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
)
3085 /* Reallocate if now empty buffer still too small. */
3086 if (5 + length
> tmp_space_size
)
3088 /* Ensure a minimum growth factor to avoid O(n**2) space
3089 consumption for n strings. The optimal minimum
3090 factor seems to be 2, as no other value can guarantee
3091 wasting less then 50% space. (Note that we cannot
3092 deallocate space allocated by `alloca' without
3093 returning from this function.) The same technique is
3094 used a few more times below when a buffer is
3096 tmp_space_size
= MAX (2 * tmp_space_size
, 5 + length
);
3097 tmp_space
= alloca (tmp_space_size
);
3100 /* Reset to beginning of the (possibly new) buffer space. */
3104 /* First element in a string table entry is the length of the
3105 string. Alignment issues are already handled. */
3106 bfd_put_32 (abfd
, length
, p
);
3110 /* Record the index in the space/subspace records. */
3111 if (som_is_space (section
))
3112 som_section_data (section
)->space_dict
->name
.n_strx
= strings_size
;
3114 som_section_data (section
)->subspace_dict
->name
.n_strx
= strings_size
;
3116 /* Next comes the string itself + a null terminator. */
3117 strcpy (p
, section
->name
);
3119 strings_size
+= length
+ 1;
3121 /* Always align up to the next word boundary. */
3122 while (strings_size
% 4)
3124 bfd_put_8 (abfd
, 0, p
);
3130 /* Done with the space/subspace strings. Write out any information
3131 contained in a partial block. */
3132 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
) != p
- tmp_space
)
3134 *string_sizep
= strings_size
;
3138 /* Write out the symbol string table. */
3141 som_write_symbol_strings (abfd
, current_offset
, syms
, num_syms
, string_sizep
,
3144 unsigned long current_offset
;
3146 unsigned int num_syms
;
3147 unsigned int *string_sizep
;
3148 COMPUNIT
*compilation_unit
;
3152 /* Chunk of memory that we can use as buffer space, then throw
3154 size_t tmp_space_size
= SOM_TMP_BUFSIZE
;
3155 unsigned char *tmp_space
= alloca (tmp_space_size
);
3156 unsigned char *p
= tmp_space
;
3158 unsigned int strings_size
= 0;
3159 unsigned char *comp
[4];
3161 /* This gets a bit gruesome because of the compilation unit. The
3162 strings within the compilation unit are part of the symbol
3163 strings, but don't have symbol_dictionary entries. So, manually
3164 write them and update the compliation unit header. On input, the
3165 compilation unit header contains local copies of the strings.
3167 if (compilation_unit
)
3169 comp
[0] = compilation_unit
->name
.n_name
;
3170 comp
[1] = compilation_unit
->language_name
.n_name
;
3171 comp
[2] = compilation_unit
->product_id
.n_name
;
3172 comp
[3] = compilation_unit
->version_id
.n_name
;
3175 /* Seek to the start of the space strings in preparation for writing
3177 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) < 0)
3180 if (compilation_unit
)
3182 for (i
= 0; i
< 4; i
++)
3184 size_t length
= strlen (comp
[i
]);
3186 /* If there is not enough room for the next entry, then dump
3187 the current buffer contents now and maybe allocate a
3189 if (p
- tmp_space
+ 5 + length
> tmp_space_size
)
3191 /* Flush buffer before refilling or reallocating. */
3192 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
)
3196 /* Reallocate if now empty buffer still too small. */
3197 if (5 + length
> tmp_space_size
)
3199 /* See alloca above for discussion of new size. */
3200 tmp_space_size
= MAX (2 * tmp_space_size
, 5 + length
);
3201 tmp_space
= alloca (tmp_space_size
);
3204 /* Reset to beginning of the (possibly new) buffer
3209 /* First element in a string table entry is the length of
3210 the string. This must always be 4 byte aligned. This is
3211 also an appropriate time to fill in the string index
3212 field in the symbol table entry. */
3213 bfd_put_32 (abfd
, length
, p
);
3217 /* Next comes the string itself + a null terminator. */
3218 strcpy (p
, comp
[i
]);
3223 obj_som_compilation_unit (abfd
)->name
.n_strx
= strings_size
;
3226 obj_som_compilation_unit (abfd
)->language_name
.n_strx
=
3230 obj_som_compilation_unit (abfd
)->product_id
.n_strx
=
3234 obj_som_compilation_unit (abfd
)->version_id
.n_strx
=
3240 strings_size
+= length
+ 1;
3242 /* Always align up to the next word boundary. */
3243 while (strings_size
% 4)
3245 bfd_put_8 (abfd
, 0, p
);
3252 for (i
= 0; i
< num_syms
; i
++)
3254 size_t length
= strlen (syms
[i
]->name
);
3256 /* If there is not enough room for the next entry, then dump the
3257 current buffer contents now and maybe allocate a larger buffer. */
3258 if (p
- tmp_space
+ 5 + length
> tmp_space_size
)
3260 /* Flush buffer before refilling or reallocating. */
3261 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
)
3265 /* Reallocate if now empty buffer still too small. */
3266 if (5 + length
> tmp_space_size
)
3268 /* See alloca above for discussion of new size. */
3269 tmp_space_size
= MAX (2 * tmp_space_size
, 5 + length
);
3270 tmp_space
= alloca (tmp_space_size
);
3273 /* Reset to beginning of the (possibly new) buffer space. */
3277 /* First element in a string table entry is the length of the
3278 string. This must always be 4 byte aligned. This is also
3279 an appropriate time to fill in the string index field in the
3280 symbol table entry. */
3281 bfd_put_32 (abfd
, length
, p
);
3285 /* Next comes the string itself + a null terminator. */
3286 strcpy (p
, syms
[i
]->name
);
3288 som_symbol_data(syms
[i
])->stringtab_offset
= strings_size
;
3290 strings_size
+= length
+ 1;
3292 /* Always align up to the next word boundary. */
3293 while (strings_size
% 4)
3295 bfd_put_8 (abfd
, 0, p
);
3301 /* Scribble out any partial block. */
3302 if (bfd_write ((PTR
) &tmp_space
[0], p
- tmp_space
, 1, abfd
) != p
- tmp_space
)
3305 *string_sizep
= strings_size
;
3309 /* Compute variable information to be placed in the SOM headers,
3310 space/subspace dictionaries, relocation streams, etc. Begin
3311 writing parts of the object file. */
3314 som_begin_writing (abfd
)
3317 unsigned long current_offset
= 0;
3318 int strings_size
= 0;
3319 unsigned long num_spaces
, num_subspaces
, i
;
3321 unsigned int total_subspaces
= 0;
3322 struct som_exec_auxhdr
*exec_header
= NULL
;
3324 /* The file header will always be first in an object file,
3325 everything else can be in random locations. To keep things
3326 "simple" BFD will lay out the object file in the manner suggested
3327 by the PRO ABI for PA-RISC Systems. */
3329 /* Before any output can really begin offsets for all the major
3330 portions of the object file must be computed. So, starting
3331 with the initial file header compute (and sometimes write)
3332 each portion of the object file. */
3334 /* Make room for the file header, it's contents are not complete
3335 yet, so it can not be written at this time. */
3336 current_offset
+= sizeof (struct header
);
3338 /* Any auxiliary headers will follow the file header. Right now
3339 we support only the copyright and version headers. */
3340 obj_som_file_hdr (abfd
)->aux_header_location
= current_offset
;
3341 obj_som_file_hdr (abfd
)->aux_header_size
= 0;
3342 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3344 /* Parts of the exec header will be filled in later, so
3345 delay writing the header itself. Fill in the defaults,
3346 and write it later. */
3347 current_offset
+= sizeof (struct som_exec_auxhdr
);
3348 obj_som_file_hdr (abfd
)->aux_header_size
3349 += sizeof (struct som_exec_auxhdr
);
3350 exec_header
= obj_som_exec_hdr (abfd
);
3351 exec_header
->som_auxhdr
.type
= EXEC_AUX_ID
;
3352 exec_header
->som_auxhdr
.length
= 40;
3354 if (obj_som_version_hdr (abfd
) != NULL
)
3358 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) < 0)
3361 /* Write the aux_id structure and the string length. */
3362 len
= sizeof (struct aux_id
) + sizeof (unsigned int);
3363 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
3364 current_offset
+= len
;
3365 if (bfd_write ((PTR
) obj_som_version_hdr (abfd
), len
, 1, abfd
) != len
)
3368 /* Write the version string. */
3369 len
= obj_som_version_hdr (abfd
)->header_id
.length
- sizeof (int);
3370 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
3371 current_offset
+= len
;
3372 if (bfd_write ((PTR
) obj_som_version_hdr (abfd
)->user_string
,
3373 len
, 1, abfd
) != len
)
3377 if (obj_som_copyright_hdr (abfd
) != NULL
)
3381 if (bfd_seek (abfd
, current_offset
, SEEK_SET
) < 0)
3384 /* Write the aux_id structure and the string length. */
3385 len
= sizeof (struct aux_id
) + sizeof (unsigned int);
3386 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
3387 current_offset
+= len
;
3388 if (bfd_write ((PTR
) obj_som_copyright_hdr (abfd
), len
, 1, abfd
) != len
)
3391 /* Write the copyright string. */
3392 len
= obj_som_copyright_hdr (abfd
)->header_id
.length
- sizeof (int);
3393 obj_som_file_hdr (abfd
)->aux_header_size
+= len
;
3394 current_offset
+= len
;
3395 if (bfd_write ((PTR
) obj_som_copyright_hdr (abfd
)->copyright
,
3396 len
, 1, abfd
) != len
)
3400 /* Next comes the initialization pointers; we have no initialization
3401 pointers, so current offset does not change. */
3402 obj_som_file_hdr (abfd
)->init_array_location
= current_offset
;
3403 obj_som_file_hdr (abfd
)->init_array_total
= 0;
3405 /* Next are the space records. These are fixed length records.
3407 Count the number of spaces to determine how much room is needed
3408 in the object file for the space records.
3410 The names of the spaces are stored in a separate string table,
3411 and the index for each space into the string table is computed
3412 below. Therefore, it is not possible to write the space headers
3414 num_spaces
= som_count_spaces (abfd
);
3415 obj_som_file_hdr (abfd
)->space_location
= current_offset
;
3416 obj_som_file_hdr (abfd
)->space_total
= num_spaces
;
3417 current_offset
+= num_spaces
* sizeof (struct space_dictionary_record
);
3419 /* Next are the subspace records. These are fixed length records.
3421 Count the number of subspaes to determine how much room is needed
3422 in the object file for the subspace records.
3424 A variety if fields in the subspace record are still unknown at
3425 this time (index into string table, fixup stream location/size, etc). */
3426 num_subspaces
= som_count_subspaces (abfd
);
3427 obj_som_file_hdr (abfd
)->subspace_location
= current_offset
;
3428 obj_som_file_hdr (abfd
)->subspace_total
= num_subspaces
;
3429 current_offset
+= num_subspaces
* sizeof (struct subspace_dictionary_record
);
3431 /* Next is the string table for the space/subspace names. We will
3432 build and write the string table on the fly. At the same time
3433 we will fill in the space/subspace name index fields. */
3435 /* The string table needs to be aligned on a word boundary. */
3436 if (current_offset
% 4)
3437 current_offset
+= (4 - (current_offset
% 4));
3439 /* Mark the offset of the space/subspace string table in the
3441 obj_som_file_hdr (abfd
)->space_strings_location
= current_offset
;
3443 /* Scribble out the space strings. */
3444 if (som_write_space_strings (abfd
, current_offset
, &strings_size
) == false)
3447 /* Record total string table size in the header and update the
3449 obj_som_file_hdr (abfd
)->space_strings_size
= strings_size
;
3450 current_offset
+= strings_size
;
3452 /* Next is the compilation unit. */
3453 obj_som_file_hdr (abfd
)->compiler_location
= current_offset
;
3454 obj_som_file_hdr (abfd
)->compiler_total
= 0;
3455 if (obj_som_compilation_unit (abfd
))
3457 obj_som_file_hdr (abfd
)->compiler_total
= 1;
3458 current_offset
+= COMPUNITSZ
;
3461 /* Now compute the file positions for the loadable subspaces, taking
3462 care to make sure everything stays properly aligned. */
3464 section
= abfd
->sections
;
3465 for (i
= 0; i
< num_spaces
; i
++)
3467 asection
*subsection
;
3469 unsigned int subspace_offset
= 0;
3472 while (!som_is_space (section
))
3473 section
= section
->next
;
3476 /* Now look for all its subspaces. */
3477 for (subsection
= abfd
->sections
;
3479 subsection
= subsection
->next
)
3482 if (!som_is_subspace (subsection
)
3483 || !som_is_container (section
, subsection
)
3484 || (subsection
->flags
& SEC_ALLOC
) == 0)
3487 /* If this is the first subspace in the space, and we are
3488 building an executable, then take care to make sure all
3489 the alignments are correct and update the exec header. */
3491 && (abfd
->flags
& (EXEC_P
| DYNAMIC
)))
3493 /* Demand paged executables have each space aligned to a
3494 page boundary. Sharable executables (write-protected
3495 text) have just the private (aka data & bss) space aligned
3496 to a page boundary. Ugh. Not true for HPUX.
3498 The HPUX kernel requires the text to always be page aligned
3499 within the file regardless of the executable's type. */
3500 if (abfd
->flags
& (D_PAGED
| DYNAMIC
)
3501 || (subsection
->flags
& SEC_CODE
)
3502 || ((abfd
->flags
& WP_TEXT
)
3503 && (subsection
->flags
& SEC_DATA
)))
3504 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
3506 /* Update the exec header. */
3507 if (subsection
->flags
& SEC_CODE
&& exec_header
->exec_tfile
== 0)
3509 exec_header
->exec_tmem
= section
->vma
;
3510 exec_header
->exec_tfile
= current_offset
;
3512 if (subsection
->flags
& SEC_DATA
&& exec_header
->exec_dfile
== 0)
3514 exec_header
->exec_dmem
= section
->vma
;
3515 exec_header
->exec_dfile
= current_offset
;
3518 /* Keep track of exactly where we are within a particular
3519 space. This is necessary as the braindamaged HPUX
3520 loader will create holes between subspaces *and*
3521 subspace alignments are *NOT* preserved. What a crock. */
3522 subspace_offset
= subsection
->vma
;
3524 /* Only do this for the first subspace within each space. */
3527 else if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3529 /* The braindamaged HPUX loader may have created a hole
3530 between two subspaces. It is *not* sufficient to use
3531 the alignment specifications within the subspaces to
3532 account for these holes -- I've run into at least one
3533 case where the loader left one code subspace unaligned
3534 in a final executable.
3536 To combat this we keep a current offset within each space,
3537 and use the subspace vma fields to detect and preserve
3538 holes. What a crock!
3540 ps. This is not necessary for unloadable space/subspaces. */
3541 current_offset
+= subsection
->vma
- subspace_offset
;
3542 if (subsection
->flags
& SEC_CODE
)
3543 exec_header
->exec_tsize
+= subsection
->vma
- subspace_offset
;
3545 exec_header
->exec_dsize
+= subsection
->vma
- subspace_offset
;
3546 subspace_offset
+= subsection
->vma
- subspace_offset
;
3550 subsection
->target_index
= total_subspaces
++;
3551 /* This is real data to be loaded from the file. */
3552 if (subsection
->flags
& SEC_LOAD
)
3554 /* Update the size of the code & data. */
3555 if (abfd
->flags
& (EXEC_P
| DYNAMIC
)
3556 && subsection
->flags
& SEC_CODE
)
3557 exec_header
->exec_tsize
+= subsection
->_cooked_size
;
3558 else if (abfd
->flags
& (EXEC_P
| DYNAMIC
)
3559 && subsection
->flags
& SEC_DATA
)
3560 exec_header
->exec_dsize
+= subsection
->_cooked_size
;
3561 som_section_data (subsection
)->subspace_dict
->file_loc_init_value
3563 subsection
->filepos
= current_offset
;
3564 current_offset
+= bfd_section_size (abfd
, subsection
);
3565 subspace_offset
+= bfd_section_size (abfd
, subsection
);
3567 /* Looks like uninitialized data. */
3570 /* Update the size of the bss section. */
3571 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3572 exec_header
->exec_bsize
+= subsection
->_cooked_size
;
3574 som_section_data (subsection
)->subspace_dict
->file_loc_init_value
3576 som_section_data (subsection
)->subspace_dict
->
3577 initialization_length
= 0;
3580 /* Goto the next section. */
3581 section
= section
->next
;
3584 /* Finally compute the file positions for unloadable subspaces.
3585 If building an executable, start the unloadable stuff on its
3588 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3589 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
3591 obj_som_file_hdr (abfd
)->unloadable_sp_location
= current_offset
;
3592 section
= abfd
->sections
;
3593 for (i
= 0; i
< num_spaces
; i
++)
3595 asection
*subsection
;
3598 while (!som_is_space (section
))
3599 section
= section
->next
;
3601 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3602 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
3604 /* Now look for all its subspaces. */
3605 for (subsection
= abfd
->sections
;
3607 subsection
= subsection
->next
)
3610 if (!som_is_subspace (subsection
)
3611 || !som_is_container (section
, subsection
)
3612 || (subsection
->flags
& SEC_ALLOC
) != 0)
3615 subsection
->target_index
= total_subspaces
++;
3616 /* This is real data to be loaded from the file. */
3617 if ((subsection
->flags
& SEC_LOAD
) == 0)
3619 som_section_data (subsection
)->subspace_dict
->file_loc_init_value
3621 subsection
->filepos
= current_offset
;
3622 current_offset
+= bfd_section_size (abfd
, subsection
);
3624 /* Looks like uninitialized data. */
3627 som_section_data (subsection
)->subspace_dict
->file_loc_init_value
3629 som_section_data (subsection
)->subspace_dict
->
3630 initialization_length
= bfd_section_size (abfd
, subsection
);
3633 /* Goto the next section. */
3634 section
= section
->next
;
3637 /* If building an executable, then make sure to seek to and write
3638 one byte at the end of the file to make sure any necessary
3639 zeros are filled in. Ugh. */
3640 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3641 current_offset
= SOM_ALIGN (current_offset
, PA_PAGESIZE
);
3642 if (bfd_seek (abfd
, current_offset
- 1, SEEK_SET
) < 0)
3644 if (bfd_write ((PTR
) "", 1, 1, abfd
) != 1)
3647 obj_som_file_hdr (abfd
)->unloadable_sp_size
3648 = current_offset
- obj_som_file_hdr (abfd
)->unloadable_sp_location
;
3650 /* Loader fixups are not supported in any way shape or form. */
3651 obj_som_file_hdr (abfd
)->loader_fixup_location
= 0;
3652 obj_som_file_hdr (abfd
)->loader_fixup_total
= 0;
3654 /* Done. Store the total size of the SOM so far. */
3655 obj_som_file_hdr (abfd
)->som_length
= current_offset
;
3660 /* Finally, scribble out the various headers to the disk. */
3663 som_finish_writing (abfd
)
3666 int num_spaces
= som_count_spaces (abfd
);
3667 asymbol
**syms
= bfd_get_outsymbols (abfd
);
3668 int i
, num_syms
, strings_size
;
3669 int subspace_index
= 0;
3672 unsigned long current_offset
;
3673 unsigned int total_reloc_size
;
3675 /* Next is the symbol table. These are fixed length records.
3677 Count the number of symbols to determine how much room is needed
3678 in the object file for the symbol table.
3680 The names of the symbols are stored in a separate string table,
3681 and the index for each symbol name into the string table is computed
3682 below. Therefore, it is not possible to write the symbol table
3685 These used to be output before the subspace contents, but they
3686 were moved here to work around a stupid bug in the hpux linker
3687 (fixed in hpux10). */
3688 current_offset
= obj_som_file_hdr (abfd
)->som_length
;
3690 /* Make sure we're on a word boundary. */
3691 if (current_offset
% 4)
3692 current_offset
+= (4 - (current_offset
% 4));
3694 num_syms
= bfd_get_symcount (abfd
);
3695 obj_som_file_hdr (abfd
)->symbol_location
= current_offset
;
3696 obj_som_file_hdr (abfd
)->symbol_total
= num_syms
;
3697 current_offset
+= num_syms
* sizeof (struct symbol_dictionary_record
);
3699 /* Next are the symbol strings.
3700 Align them to a word boundary. */
3701 if (current_offset
% 4)
3702 current_offset
+= (4 - (current_offset
% 4));
3703 obj_som_file_hdr (abfd
)->symbol_strings_location
= current_offset
;
3705 /* Scribble out the symbol strings. */
3706 if (som_write_symbol_strings (abfd
, current_offset
, syms
,
3707 num_syms
, &strings_size
,
3708 obj_som_compilation_unit (abfd
))
3712 /* Record total string table size in header and update the
3714 obj_som_file_hdr (abfd
)->symbol_strings_size
= strings_size
;
3715 current_offset
+= strings_size
;
3717 /* Do prep work before handling fixups. */
3718 som_prep_for_fixups (abfd
,
3719 bfd_get_outsymbols (abfd
),
3720 bfd_get_symcount (abfd
));
3722 /* At the end of the file is the fixup stream which starts on a
3724 if (current_offset
% 4)
3725 current_offset
+= (4 - (current_offset
% 4));
3726 obj_som_file_hdr (abfd
)->fixup_request_location
= current_offset
;
3728 /* Write the fixups and update fields in subspace headers which
3729 relate to the fixup stream. */
3730 if (som_write_fixups (abfd
, current_offset
, &total_reloc_size
) == false)
3733 /* Record the total size of the fixup stream in the file header. */
3734 obj_som_file_hdr (abfd
)->fixup_request_total
= total_reloc_size
;
3736 /* Done. Store the total size of the SOM. */
3737 obj_som_file_hdr (abfd
)->som_length
= current_offset
+ total_reloc_size
;
3739 /* Now that the symbol table information is complete, build and
3740 write the symbol table. */
3741 if (som_build_and_write_symbol_table (abfd
) == false)
3744 /* Subspaces are written first so that we can set up information
3745 about them in their containing spaces as the subspace is written. */
3747 /* Seek to the start of the subspace dictionary records. */
3748 location
= obj_som_file_hdr (abfd
)->subspace_location
;
3749 if (bfd_seek (abfd
, location
, SEEK_SET
) < 0)
3752 section
= abfd
->sections
;
3753 /* Now for each loadable space write out records for its subspaces. */
3754 for (i
= 0; i
< num_spaces
; i
++)
3756 asection
*subsection
;
3759 while (!som_is_space (section
))
3760 section
= section
->next
;
3762 /* Now look for all its subspaces. */
3763 for (subsection
= abfd
->sections
;
3765 subsection
= subsection
->next
)
3768 /* Skip any section which does not correspond to a space
3769 or subspace. Or does not have SEC_ALLOC set (and therefore
3770 has no real bits on the disk). */
3771 if (!som_is_subspace (subsection
)
3772 || !som_is_container (section
, subsection
)
3773 || (subsection
->flags
& SEC_ALLOC
) == 0)
3776 /* If this is the first subspace for this space, then save
3777 the index of the subspace in its containing space. Also
3778 set "is_loadable" in the containing space. */
3780 if (som_section_data (section
)->space_dict
->subspace_quantity
== 0)
3782 som_section_data (section
)->space_dict
->is_loadable
= 1;
3783 som_section_data (section
)->space_dict
->subspace_index
3787 /* Increment the number of subspaces seen and the number of
3788 subspaces contained within the current space. */
3790 som_section_data (section
)->space_dict
->subspace_quantity
++;
3792 /* Mark the index of the current space within the subspace's
3793 dictionary record. */
3794 som_section_data (subsection
)->subspace_dict
->space_index
= i
;
3796 /* Dump the current subspace header. */
3797 if (bfd_write ((PTR
) som_section_data (subsection
)->subspace_dict
,
3798 sizeof (struct subspace_dictionary_record
), 1, abfd
)
3799 != sizeof (struct subspace_dictionary_record
))
3802 /* Goto the next section. */
3803 section
= section
->next
;
3806 /* Now repeat the process for unloadable subspaces. */
3807 section
= abfd
->sections
;
3808 /* Now for each 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 or
3824 subspace, or which SEC_ALLOC set (and therefore handled
3825 in the loadable spaces/subspaces code above). */
3827 if (!som_is_subspace (subsection
)
3828 || !som_is_container (section
, subsection
)
3829 || (subsection
->flags
& SEC_ALLOC
) != 0)
3832 /* If this is the first subspace for this space, then save
3833 the index of the subspace in its containing space. Clear
3836 if (som_section_data (section
)->space_dict
->subspace_quantity
== 0)
3838 som_section_data (section
)->space_dict
->is_loadable
= 0;
3839 som_section_data (section
)->space_dict
->subspace_index
3843 /* Increment the number of subspaces seen and the number of
3844 subspaces contained within the current space. */
3845 som_section_data (section
)->space_dict
->subspace_quantity
++;
3848 /* Mark the index of the current space within the subspace's
3849 dictionary record. */
3850 som_section_data (subsection
)->subspace_dict
->space_index
= i
;
3852 /* Dump this subspace header. */
3853 if (bfd_write ((PTR
) som_section_data (subsection
)->subspace_dict
,
3854 sizeof (struct subspace_dictionary_record
), 1, abfd
)
3855 != sizeof (struct subspace_dictionary_record
))
3858 /* Goto the next section. */
3859 section
= section
->next
;
3862 /* All the subspace dictiondary records are written, and all the
3863 fields are set up in the space dictionary records.
3865 Seek to the right location and start writing the space
3866 dictionary records. */
3867 location
= obj_som_file_hdr (abfd
)->space_location
;
3868 if (bfd_seek (abfd
, location
, SEEK_SET
) < 0)
3871 section
= abfd
->sections
;
3872 for (i
= 0; i
< num_spaces
; i
++)
3876 while (!som_is_space (section
))
3877 section
= section
->next
;
3879 /* Dump its header */
3880 if (bfd_write ((PTR
) som_section_data (section
)->space_dict
,
3881 sizeof (struct space_dictionary_record
), 1, abfd
)
3882 != sizeof (struct space_dictionary_record
))
3885 /* Goto the next section. */
3886 section
= section
->next
;
3889 /* Write the compilation unit record if there is one. */
3890 if (obj_som_compilation_unit (abfd
))
3892 location
= obj_som_file_hdr (abfd
)->compiler_location
;
3893 if (bfd_seek (abfd
, location
, SEEK_SET
) < 0)
3896 if (bfd_write ((PTR
) obj_som_compilation_unit (abfd
),
3897 COMPUNITSZ
, 1, abfd
) != COMPUNITSZ
)
3901 /* Setting of the system_id has to happen very late now that copying of
3902 BFD private data happens *after* section contents are set. */
3903 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3904 obj_som_file_hdr(abfd
)->system_id
= obj_som_exec_data (abfd
)->system_id
;
3905 else if (bfd_get_mach (abfd
) == pa20
)
3906 obj_som_file_hdr(abfd
)->system_id
= CPU_PA_RISC2_0
;
3907 else if (bfd_get_mach (abfd
) == pa11
)
3908 obj_som_file_hdr(abfd
)->system_id
= CPU_PA_RISC1_1
;
3910 obj_som_file_hdr(abfd
)->system_id
= CPU_PA_RISC1_0
;
3912 /* Compute the checksum for the file header just before writing
3913 the header to disk. */
3914 obj_som_file_hdr (abfd
)->checksum
= som_compute_checksum (abfd
);
3916 /* Only thing left to do is write out the file header. It is always
3917 at location zero. Seek there and write it. */
3918 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) < 0)
3920 if (bfd_write ((PTR
) obj_som_file_hdr (abfd
),
3921 sizeof (struct header
), 1, abfd
)
3922 != sizeof (struct header
))
3925 /* Now write the exec header. */
3926 if (abfd
->flags
& (EXEC_P
| DYNAMIC
))
3928 long tmp
, som_length
;
3929 struct som_exec_auxhdr
*exec_header
;
3931 exec_header
= obj_som_exec_hdr (abfd
);
3932 exec_header
->exec_entry
= bfd_get_start_address (abfd
);
3933 exec_header
->exec_flags
= obj_som_exec_data (abfd
)->exec_flags
;
3935 /* Oh joys. Ram some of the BSS data into the DATA section
3936 to be compatable with how the hp linker makes objects
3937 (saves memory space). */
3938 tmp
= exec_header
->exec_dsize
;
3939 tmp
= SOM_ALIGN (tmp
, PA_PAGESIZE
);
3940 exec_header
->exec_bsize
-= (tmp
- exec_header
->exec_dsize
);
3941 if (exec_header
->exec_bsize
< 0)
3942 exec_header
->exec_bsize
= 0;
3943 exec_header
->exec_dsize
= tmp
;
3945 /* Now perform some sanity checks. The idea is to catch bogons now and
3946 inform the user, instead of silently generating a bogus file. */
3947 som_length
= obj_som_file_hdr (abfd
)->som_length
;
3948 if (exec_header
->exec_tfile
+ exec_header
->exec_tsize
> som_length
3949 || exec_header
->exec_dfile
+ exec_header
->exec_dsize
> som_length
)
3951 bfd_set_error (bfd_error_bad_value
);
3955 if (bfd_seek (abfd
, obj_som_file_hdr (abfd
)->aux_header_location
,
3959 if (bfd_write ((PTR
) exec_header
, AUX_HDR_SIZE
, 1, abfd
)
3966 /* Compute and return the checksum for a SOM file header. */
3968 static unsigned long
3969 som_compute_checksum (abfd
)
3972 unsigned long checksum
, count
, i
;
3973 unsigned long *buffer
= (unsigned long *) obj_som_file_hdr (abfd
);
3976 count
= sizeof (struct header
) / sizeof (unsigned long);
3977 for (i
= 0; i
< count
; i
++)
3978 checksum
^= *(buffer
+ i
);
3984 som_bfd_derive_misc_symbol_info (abfd
, sym
, info
)
3985 bfd
*abfd ATTRIBUTE_UNUSED
;
3987 struct som_misc_symbol_info
*info
;
3990 memset (info
, 0, sizeof (struct som_misc_symbol_info
));
3992 /* The HP SOM linker requires detailed type information about
3993 all symbols (including undefined symbols!). Unfortunately,
3994 the type specified in an import/export statement does not
3995 always match what the linker wants. Severe braindamage. */
3997 /* Section symbols will not have a SOM symbol type assigned to
3998 them yet. Assign all section symbols type ST_DATA. */
3999 if (sym
->flags
& BSF_SECTION_SYM
)
4000 info
->symbol_type
= ST_DATA
;
4003 /* Common symbols must have scope SS_UNSAT and type
4004 ST_STORAGE or the linker will choke. */
4005 if (bfd_is_com_section (sym
->section
))
4007 info
->symbol_scope
= SS_UNSAT
;
4008 info
->symbol_type
= ST_STORAGE
;
4011 /* It is possible to have a symbol without an associated
4012 type. This happens if the user imported the symbol
4013 without a type and the symbol was never defined
4014 locally. If BSF_FUNCTION is set for this symbol, then
4015 assign it type ST_CODE (the HP linker requires undefined
4016 external functions to have type ST_CODE rather than ST_ENTRY). */
4017 else if ((som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
4018 || som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
)
4019 && bfd_is_und_section (sym
->section
)
4020 && sym
->flags
& BSF_FUNCTION
)
4021 info
->symbol_type
= ST_CODE
;
4023 /* Handle function symbols which were defined in this file.
4024 They should have type ST_ENTRY. Also retrieve the argument
4025 relocation bits from the SOM backend information. */
4026 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_ENTRY
4027 || (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
4028 && (sym
->flags
& BSF_FUNCTION
))
4029 || (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
4030 && (sym
->flags
& BSF_FUNCTION
)))
4032 info
->symbol_type
= ST_ENTRY
;
4033 info
->arg_reloc
= som_symbol_data (sym
)->tc_data
.ap
.hppa_arg_reloc
;
4034 info
->priv_level
= som_symbol_data (sym
)->tc_data
.ap
.hppa_priv_level
;
4037 /* For unknown symbols set the symbol's type based on the symbol's
4038 section (ST_DATA for DATA sections, ST_CODE for CODE sections). */
4039 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
)
4041 if (sym
->section
->flags
& SEC_CODE
)
4042 info
->symbol_type
= ST_CODE
;
4044 info
->symbol_type
= ST_DATA
;
4047 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_UNKNOWN
)
4048 info
->symbol_type
= ST_DATA
;
4050 /* From now on it's a very simple mapping. */
4051 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_ABSOLUTE
)
4052 info
->symbol_type
= ST_ABSOLUTE
;
4053 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_CODE
)
4054 info
->symbol_type
= ST_CODE
;
4055 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_DATA
)
4056 info
->symbol_type
= ST_DATA
;
4057 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_MILLICODE
)
4058 info
->symbol_type
= ST_MILLICODE
;
4059 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_PLABEL
)
4060 info
->symbol_type
= ST_PLABEL
;
4061 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_PRI_PROG
)
4062 info
->symbol_type
= ST_PRI_PROG
;
4063 else if (som_symbol_data (sym
)->som_type
== SYMBOL_TYPE_SEC_PROG
)
4064 info
->symbol_type
= ST_SEC_PROG
;
4067 /* Now handle the symbol's scope. Exported data which is not
4068 in the common section has scope SS_UNIVERSAL. Note scope
4069 of common symbols was handled earlier! */
4070 if (bfd_is_und_section (sym
->section
))
4071 info
->symbol_scope
= SS_UNSAT
;
4072 else if (sym
->flags
& (BSF_EXPORT
| BSF_WEAK
)
4073 && ! bfd_is_com_section (sym
->section
))
4074 info
->symbol_scope
= SS_UNIVERSAL
;
4075 /* Anything else which is not in the common section has scope
4077 else if (! bfd_is_com_section (sym
->section
))
4078 info
->symbol_scope
= SS_LOCAL
;
4080 /* Now set the symbol_info field. It has no real meaning
4081 for undefined or common symbols, but the HP linker will
4082 choke if it's not set to some "reasonable" value. We
4083 use zero as a reasonable value. */
4084 if (bfd_is_com_section (sym
->section
)
4085 || bfd_is_und_section (sym
->section
)
4086 || bfd_is_abs_section (sym
->section
))
4087 info
->symbol_info
= 0;
4088 /* For all other symbols, the symbol_info field contains the
4089 subspace index of the space this symbol is contained in. */
4091 info
->symbol_info
= sym
->section
->target_index
;
4093 /* Set the symbol's value. */
4094 info
->symbol_value
= sym
->value
+ sym
->section
->vma
;
4096 /* The secondary_def field is for weak symbols. */
4097 if (sym
->flags
& BSF_WEAK
)
4098 info
->secondary_def
= true;
4100 info
->secondary_def
= false;
4104 /* Build and write, in one big chunk, the entire symbol table for
4108 som_build_and_write_symbol_table (abfd
)
4111 unsigned int num_syms
= bfd_get_symcount (abfd
);
4112 file_ptr symtab_location
= obj_som_file_hdr (abfd
)->symbol_location
;
4113 asymbol
**bfd_syms
= obj_som_sorted_syms (abfd
);
4114 struct symbol_dictionary_record
*som_symtab
= NULL
;
4117 /* Compute total symbol table size and allocate a chunk of memory
4118 to hold the symbol table as we build it. */
4119 symtab_size
= num_syms
* sizeof (struct symbol_dictionary_record
);
4120 som_symtab
= (struct symbol_dictionary_record
*) bfd_malloc (symtab_size
);
4121 if (som_symtab
== NULL
&& symtab_size
!= 0)
4123 memset (som_symtab
, 0, symtab_size
);
4125 /* Walk over each symbol. */
4126 for (i
= 0; i
< num_syms
; i
++)
4128 struct som_misc_symbol_info info
;
4130 /* This is really an index into the symbol strings table.
4131 By the time we get here, the index has already been
4132 computed and stored into the name field in the BFD symbol. */
4133 som_symtab
[i
].name
.n_strx
= som_symbol_data(bfd_syms
[i
])->stringtab_offset
;
4135 /* Derive SOM information from the BFD symbol. */
4136 som_bfd_derive_misc_symbol_info (abfd
, bfd_syms
[i
], &info
);
4139 som_symtab
[i
].symbol_type
= info
.symbol_type
;
4140 som_symtab
[i
].symbol_scope
= info
.symbol_scope
;
4141 som_symtab
[i
].arg_reloc
= info
.arg_reloc
;
4142 som_symtab
[i
].symbol_info
= info
.symbol_info
;
4143 som_symtab
[i
].xleast
= 3;
4144 som_symtab
[i
].symbol_value
= info
.symbol_value
| info
.priv_level
;
4145 som_symtab
[i
].secondary_def
= info
.secondary_def
;
4148 /* Everything is ready, seek to the right location and
4149 scribble out the symbol table. */
4150 if (bfd_seek (abfd
, symtab_location
, SEEK_SET
) != 0)
4153 if (bfd_write ((PTR
) som_symtab
, symtab_size
, 1, abfd
) != symtab_size
)
4156 if (som_symtab
!= NULL
)
4160 if (som_symtab
!= NULL
)
4165 /* Write an object in SOM format. */
4168 som_write_object_contents (abfd
)
4171 if (abfd
->output_has_begun
== false)
4173 /* Set up fixed parts of the file, space, and subspace headers.
4174 Notify the world that output has begun. */
4175 som_prep_headers (abfd
);
4176 abfd
->output_has_begun
= true;
4177 /* Start writing the object file. This include all the string
4178 tables, fixup streams, and other portions of the object file. */
4179 som_begin_writing (abfd
);
4182 return (som_finish_writing (abfd
));
4186 /* Read and save the string table associated with the given BFD. */
4189 som_slurp_string_table (abfd
)
4194 /* Use the saved version if its available. */
4195 if (obj_som_stringtab (abfd
) != NULL
)
4198 /* I don't think this can currently happen, and I'm not sure it should
4199 really be an error, but it's better than getting unpredictable results
4200 from the host's malloc when passed a size of zero. */
4201 if (obj_som_stringtab_size (abfd
) == 0)
4203 bfd_set_error (bfd_error_no_symbols
);
4207 /* Allocate and read in the string table. */
4208 stringtab
= bfd_malloc (obj_som_stringtab_size (abfd
));
4209 if (stringtab
== NULL
)
4211 memset (stringtab
, 0, obj_som_stringtab_size (abfd
));
4213 if (bfd_seek (abfd
, obj_som_str_filepos (abfd
), SEEK_SET
) < 0)
4216 if (bfd_read (stringtab
, obj_som_stringtab_size (abfd
), 1, abfd
)
4217 != obj_som_stringtab_size (abfd
))
4220 /* Save our results and return success. */
4221 obj_som_stringtab (abfd
) = stringtab
;
4225 /* Return the amount of data (in bytes) required to hold the symbol
4226 table for this object. */
4229 som_get_symtab_upper_bound (abfd
)
4232 if (!som_slurp_symbol_table (abfd
))
4235 return (bfd_get_symcount (abfd
) + 1) * (sizeof (asymbol
*));
4238 /* Convert from a SOM subspace index to a BFD section. */
4241 bfd_section_from_som_symbol (abfd
, symbol
)
4243 struct symbol_dictionary_record
*symbol
;
4247 /* The meaning of the symbol_info field changes for functions
4248 within executables. So only use the quick symbol_info mapping for
4249 incomplete objects and non-function symbols in executables. */
4250 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
4251 || (symbol
->symbol_type
!= ST_ENTRY
4252 && symbol
->symbol_type
!= ST_PRI_PROG
4253 && symbol
->symbol_type
!= ST_SEC_PROG
4254 && symbol
->symbol_type
!= ST_MILLICODE
))
4256 unsigned int index
= symbol
->symbol_info
;
4257 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
4258 if (section
->target_index
== index
&& som_is_subspace (section
))
4261 /* Could be a symbol from an external library (such as an OMOS
4262 shared library). Don't abort. */
4263 return bfd_abs_section_ptr
;
4268 unsigned int value
= symbol
->symbol_value
;
4270 /* For executables we will have to use the symbol's address and
4271 find out what section would contain that address. Yuk. */
4272 for (section
= abfd
->sections
; section
; section
= section
->next
)
4274 if (value
>= section
->vma
4275 && value
<= section
->vma
+ section
->_cooked_size
4276 && som_is_subspace (section
))
4280 /* Could be a symbol from an external library (such as an OMOS
4281 shared library). Don't abort. */
4282 return bfd_abs_section_ptr
;
4287 /* Read and save the symbol table associated with the given BFD. */
4290 som_slurp_symbol_table (abfd
)
4293 int symbol_count
= bfd_get_symcount (abfd
);
4294 int symsize
= sizeof (struct symbol_dictionary_record
);
4296 struct symbol_dictionary_record
*buf
= NULL
, *bufp
, *endbufp
;
4297 som_symbol_type
*sym
, *symbase
;
4299 /* Return saved value if it exists. */
4300 if (obj_som_symtab (abfd
) != NULL
)
4301 goto successful_return
;
4303 /* Special case. This is *not* an error. */
4304 if (symbol_count
== 0)
4305 goto successful_return
;
4307 if (!som_slurp_string_table (abfd
))
4310 stringtab
= obj_som_stringtab (abfd
);
4312 symbase
= ((som_symbol_type
*)
4313 bfd_malloc (symbol_count
* sizeof (som_symbol_type
)));
4314 if (symbase
== NULL
)
4316 memset (symbase
, 0, symbol_count
* sizeof (som_symbol_type
));
4318 /* Read in the external SOM representation. */
4319 buf
= bfd_malloc (symbol_count
* symsize
);
4320 if (buf
== NULL
&& symbol_count
* symsize
!= 0)
4322 if (bfd_seek (abfd
, obj_som_sym_filepos (abfd
), SEEK_SET
) < 0)
4324 if (bfd_read (buf
, symbol_count
* symsize
, 1, abfd
)
4325 != symbol_count
* symsize
)
4328 /* Iterate over all the symbols and internalize them. */
4329 endbufp
= buf
+ symbol_count
;
4330 for (bufp
= buf
, sym
= symbase
; bufp
< endbufp
; ++bufp
)
4333 /* I don't think we care about these. */
4334 if (bufp
->symbol_type
== ST_SYM_EXT
4335 || bufp
->symbol_type
== ST_ARG_EXT
)
4338 /* Set some private data we care about. */
4339 if (bufp
->symbol_type
== ST_NULL
)
4340 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_UNKNOWN
;
4341 else if (bufp
->symbol_type
== ST_ABSOLUTE
)
4342 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_ABSOLUTE
;
4343 else if (bufp
->symbol_type
== ST_DATA
)
4344 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_DATA
;
4345 else if (bufp
->symbol_type
== ST_CODE
)
4346 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_CODE
;
4347 else if (bufp
->symbol_type
== ST_PRI_PROG
)
4348 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_PRI_PROG
;
4349 else if (bufp
->symbol_type
== ST_SEC_PROG
)
4350 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_SEC_PROG
;
4351 else if (bufp
->symbol_type
== ST_ENTRY
)
4352 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_ENTRY
;
4353 else if (bufp
->symbol_type
== ST_MILLICODE
)
4354 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_MILLICODE
;
4355 else if (bufp
->symbol_type
== ST_PLABEL
)
4356 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_PLABEL
;
4358 som_symbol_data (sym
)->som_type
= SYMBOL_TYPE_UNKNOWN
;
4359 som_symbol_data (sym
)->tc_data
.ap
.hppa_arg_reloc
= bufp
->arg_reloc
;
4361 /* Some reasonable defaults. */
4362 sym
->symbol
.the_bfd
= abfd
;
4363 sym
->symbol
.name
= bufp
->name
.n_strx
+ stringtab
;
4364 sym
->symbol
.value
= bufp
->symbol_value
;
4365 sym
->symbol
.section
= 0;
4366 sym
->symbol
.flags
= 0;
4368 switch (bufp
->symbol_type
)
4372 sym
->symbol
.flags
|= BSF_FUNCTION
;
4373 som_symbol_data (sym
)->tc_data
.ap
.hppa_priv_level
=
4374 sym
->symbol
.value
& 0x3;
4375 sym
->symbol
.value
&= ~0x3;
4382 som_symbol_data (sym
)->tc_data
.ap
.hppa_priv_level
=
4383 sym
->symbol
.value
& 0x3;
4384 sym
->symbol
.value
&= ~0x3;
4385 /* If the symbol's scope is SS_UNSAT, then these are
4386 undefined function symbols. */
4387 if (bufp
->symbol_scope
== SS_UNSAT
)
4388 sym
->symbol
.flags
|= BSF_FUNCTION
;
4395 /* Handle scoping and section information. */
4396 switch (bufp
->symbol_scope
)
4398 /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
4399 so the section associated with this symbol can't be known. */
4401 if (bufp
->symbol_type
!= ST_STORAGE
)
4402 sym
->symbol
.section
= bfd_und_section_ptr
;
4404 sym
->symbol
.section
= bfd_com_section_ptr
;
4405 sym
->symbol
.flags
|= (BSF_EXPORT
| BSF_GLOBAL
);
4409 if (bufp
->symbol_type
!= ST_STORAGE
)
4410 sym
->symbol
.section
= bfd_und_section_ptr
;
4412 sym
->symbol
.section
= bfd_com_section_ptr
;
4416 sym
->symbol
.flags
|= (BSF_EXPORT
| BSF_GLOBAL
);
4417 sym
->symbol
.section
= bfd_section_from_som_symbol (abfd
, bufp
);
4418 sym
->symbol
.value
-= sym
->symbol
.section
->vma
;
4422 /* SS_GLOBAL and SS_LOCAL are two names for the same thing.
4423 Sound dumb? It is. */
4427 sym
->symbol
.flags
|= BSF_LOCAL
;
4428 sym
->symbol
.section
= bfd_section_from_som_symbol (abfd
, bufp
);
4429 sym
->symbol
.value
-= sym
->symbol
.section
->vma
;
4433 /* Check for a weak symbol. */
4434 if (bufp
->secondary_def
)
4435 sym
->symbol
.flags
|= BSF_WEAK
;
4437 /* Mark section symbols and symbols used by the debugger.
4438 Note $START$ is a magic code symbol, NOT a section symbol. */
4439 if (sym
->symbol
.name
[0] == '$'
4440 && sym
->symbol
.name
[strlen (sym
->symbol
.name
) - 1] == '$'
4441 && !strcmp (sym
->symbol
.name
, sym
->symbol
.section
->name
))
4442 sym
->symbol
.flags
|= BSF_SECTION_SYM
;
4443 else if (!strncmp (sym
->symbol
.name
, "L$0\002", 4))
4445 sym
->symbol
.flags
|= BSF_SECTION_SYM
;
4446 sym
->symbol
.name
= sym
->symbol
.section
->name
;
4448 else if (!strncmp (sym
->symbol
.name
, "L$0\001", 4))
4449 sym
->symbol
.flags
|= BSF_DEBUGGING
;
4451 /* Note increment at bottom of loop, since we skip some symbols
4452 we can not include it as part of the for statement. */
4456 /* We modify the symbol count to record the number of BFD symbols we
4458 bfd_get_symcount (abfd
) = sym
- symbase
;
4460 /* Save our results and return success. */
4461 obj_som_symtab (abfd
) = symbase
;
4473 /* Canonicalize a SOM symbol table. Return the number of entries
4474 in the symbol table. */
4477 som_get_symtab (abfd
, location
)
4482 som_symbol_type
*symbase
;
4484 if (!som_slurp_symbol_table (abfd
))
4487 i
= bfd_get_symcount (abfd
);
4488 symbase
= obj_som_symtab (abfd
);
4490 for (; i
> 0; i
--, location
++, symbase
++)
4491 *location
= &symbase
->symbol
;
4493 /* Final null pointer. */
4495 return (bfd_get_symcount (abfd
));
4498 /* Make a SOM symbol. There is nothing special to do here. */
4501 som_make_empty_symbol (abfd
)
4504 som_symbol_type
*new =
4505 (som_symbol_type
*) bfd_zalloc (abfd
, sizeof (som_symbol_type
));
4508 new->symbol
.the_bfd
= abfd
;
4510 return &new->symbol
;
4513 /* Print symbol information. */
4516 som_print_symbol (ignore_abfd
, afile
, symbol
, how
)
4517 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
4520 bfd_print_symbol_type how
;
4522 FILE *file
= (FILE *) afile
;
4525 case bfd_print_symbol_name
:
4526 fprintf (file
, "%s", symbol
->name
);
4528 case bfd_print_symbol_more
:
4529 fprintf (file
, "som ");
4530 fprintf_vma (file
, symbol
->value
);
4531 fprintf (file
, " %lx", (long) symbol
->flags
);
4533 case bfd_print_symbol_all
:
4535 CONST
char *section_name
;
4536 section_name
= symbol
->section
? symbol
->section
->name
: "(*none*)";
4537 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
4538 fprintf (file
, " %s\t%s", section_name
, symbol
->name
);
4545 som_bfd_is_local_label_name (abfd
, name
)
4546 bfd
*abfd ATTRIBUTE_UNUSED
;
4549 return (name
[0] == 'L' && name
[1] == '$');
4552 /* Count or process variable-length SOM fixup records.
4554 To avoid code duplication we use this code both to compute the number
4555 of relocations requested by a stream, and to internalize the stream.
4557 When computing the number of relocations requested by a stream the
4558 variables rptr, section, and symbols have no meaning.
4560 Return the number of relocations requested by the fixup stream. When
4563 This needs at least two or three more passes to get it cleaned up. */
4566 som_set_reloc_info (fixup
, end
, internal_relocs
, section
, symbols
, just_count
)
4567 unsigned char *fixup
;
4569 arelent
*internal_relocs
;
4574 unsigned int op
, varname
, deallocate_contents
= 0;
4575 unsigned char *end_fixups
= &fixup
[end
];
4576 const struct fixup_format
*fp
;
4578 unsigned char *save_fixup
;
4579 int variables
[26], stack
[20], c
, v
, count
, prev_fixup
, *sp
, saved_unwind_bits
;
4581 arelent
*rptr
= internal_relocs
;
4582 unsigned int offset
= 0;
4584 #define var(c) variables[(c) - 'A']
4585 #define push(v) (*sp++ = (v))
4586 #define pop() (*--sp)
4587 #define emptystack() (sp == stack)
4589 som_initialize_reloc_queue (reloc_queue
);
4590 memset (variables
, 0, sizeof (variables
));
4591 memset (stack
, 0, sizeof (stack
));
4594 saved_unwind_bits
= 0;
4597 while (fixup
< end_fixups
)
4600 /* Save pointer to the start of this fixup. We'll use
4601 it later to determine if it is necessary to put this fixup
4605 /* Get the fixup code and its associated format. */
4607 fp
= &som_fixup_formats
[op
];
4609 /* Handle a request for a previous fixup. */
4610 if (*fp
->format
== 'P')
4612 /* Get pointer to the beginning of the prev fixup, move
4613 the repeated fixup to the head of the queue. */
4614 fixup
= reloc_queue
[fp
->D
].reloc
;
4615 som_reloc_queue_fix (reloc_queue
, fp
->D
);
4618 /* Get the fixup code and its associated format. */
4620 fp
= &som_fixup_formats
[op
];
4623 /* If this fixup will be passed to BFD, set some reasonable defaults. */
4625 && som_hppa_howto_table
[op
].type
!= R_NO_RELOCATION
4626 && som_hppa_howto_table
[op
].type
!= R_DATA_OVERRIDE
)
4628 rptr
->address
= offset
;
4629 rptr
->howto
= &som_hppa_howto_table
[op
];
4631 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
4634 /* Set default input length to 0. Get the opcode class index
4638 var ('U') = saved_unwind_bits
;
4640 /* Get the opcode format. */
4643 /* Process the format string. Parsing happens in two phases,
4644 parse RHS, then assign to LHS. Repeat until no more
4645 characters in the format string. */
4648 /* The variable this pass is going to compute a value for. */
4651 /* Start processing RHS. Continue until a NULL or '=' is found. */
4656 /* If this is a variable, push it on the stack. */
4660 /* If this is a lower case letter, then it represents
4661 additional data from the fixup stream to be pushed onto
4663 else if (islower (c
))
4665 int bits
= (c
- 'a') * 8;
4666 for (v
= 0; c
> 'a'; --c
)
4667 v
= (v
<< 8) | *fixup
++;
4669 v
= sign_extend (v
, bits
);
4673 /* A decimal constant. Push it on the stack. */
4674 else if (isdigit (c
))
4677 while (isdigit (*cp
))
4678 v
= (v
* 10) + (*cp
++ - '0');
4683 /* An operator. Pop two two values from the stack and
4684 use them as operands to the given operation. Push
4685 the result of the operation back on the stack. */
4707 while (*cp
&& *cp
!= '=');
4709 /* Move over the equal operator. */
4712 /* Pop the RHS off the stack. */
4715 /* Perform the assignment. */
4718 /* Handle side effects. and special 'O' stack cases. */
4721 /* Consume some bytes from the input space. */
4725 /* A symbol to use in the relocation. Make a note
4726 of this if we are not just counting. */
4729 rptr
->sym_ptr_ptr
= &symbols
[c
];
4731 /* Argument relocation bits for a function call. */
4735 unsigned int tmp
= var ('R');
4738 if ((som_hppa_howto_table
[op
].type
== R_PCREL_CALL
4739 && R_PCREL_CALL
+ 10 > op
)
4740 || (som_hppa_howto_table
[op
].type
== R_ABS_CALL
4741 && R_ABS_CALL
+ 10 > op
))
4743 /* Simple encoding. */
4750 rptr
->addend
|= 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2;
4752 rptr
->addend
|= 1 << 8 | 1 << 6 | 1 << 4;
4754 rptr
->addend
|= 1 << 8 | 1 << 6;
4756 rptr
->addend
|= 1 << 8;
4760 unsigned int tmp1
, tmp2
;
4762 /* First part is easy -- low order two bits are
4763 directly copied, then shifted away. */
4764 rptr
->addend
= tmp
& 0x3;
4767 /* Diving the result by 10 gives us the second
4768 part. If it is 9, then the first two words
4769 are a double precision paramater, else it is
4770 3 * the first arg bits + the 2nd arg bits. */
4774 rptr
->addend
+= (0xe << 6);
4777 /* Get the two pieces. */
4780 /* Put them in the addend. */
4781 rptr
->addend
+= (tmp2
<< 8) + (tmp1
<< 6);
4784 /* What's left is the third part. It's unpacked
4785 just like the second. */
4787 rptr
->addend
+= (0xe << 2);
4792 rptr
->addend
+= (tmp2
<< 4) + (tmp
<< 2);
4795 rptr
->addend
= HPPA_R_ADDEND (rptr
->addend
, 0);
4798 /* Handle the linker expression stack. */
4803 subop
= comp1_opcodes
;
4806 subop
= comp2_opcodes
;
4809 subop
= comp3_opcodes
;
4814 while (*subop
<= (unsigned char) c
)
4818 /* The lower 32unwind bits must be persistent. */
4820 saved_unwind_bits
= var ('U');
4828 /* If we used a previous fixup, clean up after it. */
4831 fixup
= save_fixup
+ 1;
4835 else if (fixup
> save_fixup
+ 1)
4836 som_reloc_queue_insert (save_fixup
, fixup
- save_fixup
, reloc_queue
);
4838 /* We do not pass R_DATA_OVERRIDE or R_NO_RELOCATION
4840 if (som_hppa_howto_table
[op
].type
!= R_DATA_OVERRIDE
4841 && som_hppa_howto_table
[op
].type
!= R_NO_RELOCATION
)
4843 /* Done with a single reloction. Loop back to the top. */
4846 if (som_hppa_howto_table
[op
].type
== R_ENTRY
)
4847 rptr
->addend
= var ('T');
4848 else if (som_hppa_howto_table
[op
].type
== R_EXIT
)
4849 rptr
->addend
= var ('U');
4850 else if (som_hppa_howto_table
[op
].type
== R_PCREL_CALL
4851 || som_hppa_howto_table
[op
].type
== R_ABS_CALL
)
4853 else if (som_hppa_howto_table
[op
].type
== R_DATA_ONE_SYMBOL
)
4855 /* Try what was specified in R_DATA_OVERRIDE first
4856 (if anything). Then the hard way using the
4857 section contents. */
4858 rptr
->addend
= var ('V');
4860 if (rptr
->addend
== 0 && !section
->contents
)
4862 /* Got to read the damn contents first. We don't
4863 bother saving the contents (yet). Add it one
4864 day if the need arises. */
4865 section
->contents
= bfd_malloc (section
->_raw_size
);
4866 if (section
->contents
== NULL
)
4869 deallocate_contents
= 1;
4870 bfd_get_section_contents (section
->owner
,
4874 section
->_raw_size
);
4876 else if (rptr
->addend
== 0)
4877 rptr
->addend
= bfd_get_32 (section
->owner
,
4879 + offset
- var ('L')));
4883 rptr
->addend
= var ('V');
4887 /* Now that we've handled a "full" relocation, reset
4889 memset (variables
, 0, sizeof (variables
));
4890 memset (stack
, 0, sizeof (stack
));
4893 if (deallocate_contents
)
4894 free (section
->contents
);
4904 /* Read in the relocs (aka fixups in SOM terms) for a section.
4906 som_get_reloc_upper_bound calls this routine with JUST_COUNT
4907 set to true to indicate it only needs a count of the number
4908 of actual relocations. */
4911 som_slurp_reloc_table (abfd
, section
, symbols
, just_count
)
4917 char *external_relocs
;
4918 unsigned int fixup_stream_size
;
4919 arelent
*internal_relocs
;
4920 unsigned int num_relocs
;
4922 fixup_stream_size
= som_section_data (section
)->reloc_size
;
4923 /* If there were no relocations, then there is nothing to do. */
4924 if (section
->reloc_count
== 0)
4927 /* If reloc_count is -1, then the relocation stream has not been
4928 parsed. We must do so now to know how many relocations exist. */
4929 if (section
->reloc_count
== -1)
4931 external_relocs
= (char *) bfd_malloc (fixup_stream_size
);
4932 if (external_relocs
== (char *) NULL
)
4934 /* Read in the external forms. */
4936 obj_som_reloc_filepos (abfd
) + section
->rel_filepos
,
4940 if (bfd_read (external_relocs
, 1, fixup_stream_size
, abfd
)
4941 != fixup_stream_size
)
4944 /* Let callers know how many relocations found.
4945 also save the relocation stream as we will
4947 section
->reloc_count
= som_set_reloc_info (external_relocs
,
4949 NULL
, NULL
, NULL
, true);
4951 som_section_data (section
)->reloc_stream
= external_relocs
;
4954 /* If the caller only wanted a count, then return now. */
4958 num_relocs
= section
->reloc_count
;
4959 external_relocs
= som_section_data (section
)->reloc_stream
;
4960 /* Return saved information about the relocations if it is available. */
4961 if (section
->relocation
!= (arelent
*) NULL
)
4964 internal_relocs
= (arelent
*)
4965 bfd_zalloc (abfd
, (num_relocs
* sizeof (arelent
)));
4966 if (internal_relocs
== (arelent
*) NULL
)
4969 /* Process and internalize the relocations. */
4970 som_set_reloc_info (external_relocs
, fixup_stream_size
,
4971 internal_relocs
, section
, symbols
, false);
4973 /* We're done with the external relocations. Free them. */
4974 free (external_relocs
);
4975 som_section_data (section
)->reloc_stream
= NULL
;
4977 /* Save our results and return success. */
4978 section
->relocation
= internal_relocs
;
4982 /* Return the number of bytes required to store the relocation
4983 information associated with the given section. */
4986 som_get_reloc_upper_bound (abfd
, asect
)
4990 /* If section has relocations, then read in the relocation stream
4991 and parse it to determine how many relocations exist. */
4992 if (asect
->flags
& SEC_RELOC
)
4994 if (! som_slurp_reloc_table (abfd
, asect
, NULL
, true))
4996 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
4998 /* There are no relocations. */
5002 /* Convert relocations from SOM (external) form into BFD internal
5003 form. Return the number of relocations. */
5006 som_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
5015 if (som_slurp_reloc_table (abfd
, section
, symbols
, false) == false)
5018 count
= section
->reloc_count
;
5019 tblptr
= section
->relocation
;
5022 *relptr
++ = tblptr
++;
5024 *relptr
= (arelent
*) NULL
;
5025 return section
->reloc_count
;
5028 extern const bfd_target som_vec
;
5030 /* A hook to set up object file dependent section information. */
5033 som_new_section_hook (abfd
, newsect
)
5037 newsect
->used_by_bfd
=
5038 (PTR
) bfd_zalloc (abfd
, sizeof (struct som_section_data_struct
));
5039 if (!newsect
->used_by_bfd
)
5041 newsect
->alignment_power
= 3;
5043 /* We allow more than three sections internally */
5047 /* Copy any private info we understand from the input symbol
5048 to the output symbol. */
5051 som_bfd_copy_private_symbol_data (ibfd
, isymbol
, obfd
, osymbol
)
5057 struct som_symbol
*input_symbol
= (struct som_symbol
*) isymbol
;
5058 struct som_symbol
*output_symbol
= (struct som_symbol
*) osymbol
;
5060 /* One day we may try to grok other private data. */
5061 if (ibfd
->xvec
->flavour
!= bfd_target_som_flavour
5062 || obfd
->xvec
->flavour
!= bfd_target_som_flavour
)
5065 /* The only private information we need to copy is the argument relocation
5067 output_symbol
->tc_data
.ap
.hppa_arg_reloc
=
5068 input_symbol
->tc_data
.ap
.hppa_arg_reloc
;
5073 /* Copy any private info we understand from the input section
5074 to the output section. */
5076 som_bfd_copy_private_section_data (ibfd
, isection
, obfd
, osection
)
5082 /* One day we may try to grok other private data. */
5083 if (ibfd
->xvec
->flavour
!= bfd_target_som_flavour
5084 || obfd
->xvec
->flavour
!= bfd_target_som_flavour
5085 || (!som_is_space (isection
) && !som_is_subspace (isection
)))
5088 som_section_data (osection
)->copy_data
5089 = (struct som_copyable_section_data_struct
*)
5090 bfd_zalloc (obfd
, sizeof (struct som_copyable_section_data_struct
));
5091 if (som_section_data (osection
)->copy_data
== NULL
)
5094 memcpy (som_section_data (osection
)->copy_data
,
5095 som_section_data (isection
)->copy_data
,
5096 sizeof (struct som_copyable_section_data_struct
));
5098 /* Reparent if necessary. */
5099 if (som_section_data (osection
)->copy_data
->container
)
5100 som_section_data (osection
)->copy_data
->container
=
5101 som_section_data (osection
)->copy_data
->container
->output_section
;
5106 /* Copy any private info we understand from the input bfd
5107 to the output bfd. */
5110 som_bfd_copy_private_bfd_data (ibfd
, obfd
)
5113 /* One day we may try to grok other private data. */
5114 if (ibfd
->xvec
->flavour
!= bfd_target_som_flavour
5115 || obfd
->xvec
->flavour
!= bfd_target_som_flavour
)
5118 /* Allocate some memory to hold the data we need. */
5119 obj_som_exec_data (obfd
) = (struct som_exec_data
*)
5120 bfd_zalloc (obfd
, sizeof (struct som_exec_data
));
5121 if (obj_som_exec_data (obfd
) == NULL
)
5124 /* Now copy the data. */
5125 memcpy (obj_som_exec_data (obfd
), obj_som_exec_data (ibfd
),
5126 sizeof (struct som_exec_data
));
5131 /* Set backend info for sections which can not be described
5132 in the BFD data structures. */
5135 bfd_som_set_section_attributes (section
, defined
, private, sort_key
, spnum
)
5139 unsigned int sort_key
;
5142 /* Allocate memory to hold the magic information. */
5143 if (som_section_data (section
)->copy_data
== NULL
)
5145 som_section_data (section
)->copy_data
5146 = (struct som_copyable_section_data_struct
*)
5147 bfd_zalloc (section
->owner
,
5148 sizeof (struct som_copyable_section_data_struct
));
5149 if (som_section_data (section
)->copy_data
== NULL
)
5152 som_section_data (section
)->copy_data
->sort_key
= sort_key
;
5153 som_section_data (section
)->copy_data
->is_defined
= defined
;
5154 som_section_data (section
)->copy_data
->is_private
= private;
5155 som_section_data (section
)->copy_data
->container
= section
;
5156 som_section_data (section
)->copy_data
->space_number
= spnum
;
5160 /* Set backend info for subsections which can not be described
5161 in the BFD data structures. */
5164 bfd_som_set_subsection_attributes (section
, container
, access
,
5167 asection
*container
;
5169 unsigned int sort_key
;
5172 /* Allocate memory to hold the magic information. */
5173 if (som_section_data (section
)->copy_data
== NULL
)
5175 som_section_data (section
)->copy_data
5176 = (struct som_copyable_section_data_struct
*)
5177 bfd_zalloc (section
->owner
,
5178 sizeof (struct som_copyable_section_data_struct
));
5179 if (som_section_data (section
)->copy_data
== NULL
)
5182 som_section_data (section
)->copy_data
->sort_key
= sort_key
;
5183 som_section_data (section
)->copy_data
->access_control_bits
= access
;
5184 som_section_data (section
)->copy_data
->quadrant
= quadrant
;
5185 som_section_data (section
)->copy_data
->container
= container
;
5189 /* Set the full SOM symbol type. SOM needs far more symbol information
5190 than any other object file format I'm aware of. It is mandatory
5191 to be able to know if a symbol is an entry point, millicode, data,
5192 code, absolute, storage request, or procedure label. If you get
5193 the symbol type wrong your program will not link. */
5196 bfd_som_set_symbol_type (symbol
, type
)
5200 som_symbol_data (symbol
)->som_type
= type
;
5203 /* Attach an auxiliary header to the BFD backend so that it may be
5204 written into the object file. */
5206 bfd_som_attach_aux_hdr (abfd
, type
, string
)
5211 if (type
== VERSION_AUX_ID
)
5213 int len
= strlen (string
);
5217 pad
= (4 - (len
% 4));
5218 obj_som_version_hdr (abfd
) = (struct user_string_aux_hdr
*)
5219 bfd_zalloc (abfd
, sizeof (struct aux_id
)
5220 + sizeof (unsigned int) + len
+ pad
);
5221 if (!obj_som_version_hdr (abfd
))
5223 obj_som_version_hdr (abfd
)->header_id
.type
= VERSION_AUX_ID
;
5224 obj_som_version_hdr (abfd
)->header_id
.length
= len
+ pad
;
5225 obj_som_version_hdr (abfd
)->header_id
.length
+= sizeof (int);
5226 obj_som_version_hdr (abfd
)->string_length
= len
;
5227 strncpy (obj_som_version_hdr (abfd
)->user_string
, string
, len
);
5229 else if (type
== COPYRIGHT_AUX_ID
)
5231 int len
= strlen (string
);
5235 pad
= (4 - (len
% 4));
5236 obj_som_copyright_hdr (abfd
) = (struct copyright_aux_hdr
*)
5237 bfd_zalloc (abfd
, sizeof (struct aux_id
)
5238 + sizeof (unsigned int) + len
+ pad
);
5239 if (!obj_som_copyright_hdr (abfd
))
5241 obj_som_copyright_hdr (abfd
)->header_id
.type
= COPYRIGHT_AUX_ID
;
5242 obj_som_copyright_hdr (abfd
)->header_id
.length
= len
+ pad
;
5243 obj_som_copyright_hdr (abfd
)->header_id
.length
+= sizeof (int);
5244 obj_som_copyright_hdr (abfd
)->string_length
= len
;
5245 strcpy (obj_som_copyright_hdr (abfd
)->copyright
, string
);
5250 /* Attach an compilation unit header to the BFD backend so that it may be
5251 written into the object file. */
5254 bfd_som_attach_compilation_unit (abfd
, name
, language_name
, product_id
,
5258 const char *language_name
;
5259 const char *product_id
;
5260 const char *version_id
;
5262 COMPUNIT
*n
= (COMPUNIT
*) bfd_zalloc (abfd
, COMPUNITSZ
);
5269 n->f.n_name = bfd_alloc (abfd, strlen (f) + 1); \
5270 if (n->f.n_name == NULL) \
5272 strcpy (n->f.n_name, f); \
5276 STRDUP (language_name
);
5277 STRDUP (product_id
);
5278 STRDUP (version_id
);
5282 obj_som_compilation_unit (abfd
) = n
;
5288 som_get_section_contents (abfd
, section
, location
, offset
, count
)
5293 bfd_size_type count
;
5295 if (count
== 0 || ((section
->flags
& SEC_HAS_CONTENTS
) == 0))
5297 if ((bfd_size_type
)(offset
+count
) > section
->_raw_size
5298 || bfd_seek (abfd
, (file_ptr
)(section
->filepos
+ offset
), SEEK_SET
) == -1
5299 || bfd_read (location
, (bfd_size_type
)1, count
, abfd
) != count
)
5300 return (false); /* on error */
5305 som_set_section_contents (abfd
, section
, location
, offset
, count
)
5310 bfd_size_type count
;
5312 if (abfd
->output_has_begun
== false)
5314 /* Set up fixed parts of the file, space, and subspace headers.
5315 Notify the world that output has begun. */
5316 som_prep_headers (abfd
);
5317 abfd
->output_has_begun
= true;
5318 /* Start writing the object file. This include all the string
5319 tables, fixup streams, and other portions of the object file. */
5320 som_begin_writing (abfd
);
5323 /* Only write subspaces which have "real" contents (eg. the contents
5324 are not generated at run time by the OS). */
5325 if (!som_is_subspace (section
)
5326 || ((section
->flags
& SEC_HAS_CONTENTS
) == 0))
5329 /* Seek to the proper offset within the object file and write the
5331 offset
+= som_section_data (section
)->subspace_dict
->file_loc_init_value
;
5332 if (bfd_seek (abfd
, offset
, SEEK_SET
) == -1)
5335 if (bfd_write ((PTR
) location
, 1, count
, abfd
) != count
)
5341 som_set_arch_mach (abfd
, arch
, machine
)
5343 enum bfd_architecture arch
;
5344 unsigned long machine
;
5346 /* Allow any architecture to be supported by the SOM backend */
5347 return bfd_default_set_arch_mach (abfd
, arch
, machine
);
5351 som_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
5352 functionname_ptr
, line_ptr
)
5353 bfd
*abfd ATTRIBUTE_UNUSED
;
5354 asection
*section ATTRIBUTE_UNUSED
;
5355 asymbol
**symbols ATTRIBUTE_UNUSED
;
5356 bfd_vma offset ATTRIBUTE_UNUSED
;
5357 CONST
char **filename_ptr ATTRIBUTE_UNUSED
;
5358 CONST
char **functionname_ptr ATTRIBUTE_UNUSED
;
5359 unsigned int *line_ptr ATTRIBUTE_UNUSED
;
5365 som_sizeof_headers (abfd
, reloc
)
5366 bfd
*abfd ATTRIBUTE_UNUSED
;
5367 boolean reloc ATTRIBUTE_UNUSED
;
5369 (*_bfd_error_handler
) (_("som_sizeof_headers unimplemented"));
5375 /* Return the single-character symbol type corresponding to
5376 SOM section S, or '?' for an unknown SOM section. */
5379 som_section_type (s
)
5382 const struct section_to_type
*t
;
5384 for (t
= &stt
[0]; t
->section
; t
++)
5385 if (!strcmp (s
, t
->section
))
5391 som_decode_symclass (symbol
)
5396 if (bfd_is_com_section (symbol
->section
))
5398 if (bfd_is_und_section (symbol
->section
))
5400 if (bfd_is_ind_section (symbol
->section
))
5402 if (symbol
->flags
& BSF_WEAK
)
5404 if (!(symbol
->flags
& (BSF_GLOBAL
|BSF_LOCAL
)))
5407 if (bfd_is_abs_section (symbol
->section
)
5408 || (som_symbol_data (symbol
) != NULL
5409 && som_symbol_data (symbol
)->som_type
== SYMBOL_TYPE_ABSOLUTE
))
5411 else if (symbol
->section
)
5412 c
= som_section_type (symbol
->section
->name
);
5415 if (symbol
->flags
& BSF_GLOBAL
)
5420 /* Return information about SOM symbol SYMBOL in RET. */
5423 som_get_symbol_info (ignore_abfd
, symbol
, ret
)
5424 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
5428 ret
->type
= som_decode_symclass (symbol
);
5429 if (ret
->type
!= 'U')
5430 ret
->value
= symbol
->value
+symbol
->section
->vma
;
5433 ret
->name
= symbol
->name
;
5436 /* Count the number of symbols in the archive symbol table. Necessary
5437 so that we can allocate space for all the carsyms at once. */
5440 som_bfd_count_ar_symbols (abfd
, lst_header
, count
)
5442 struct lst_header
*lst_header
;
5446 unsigned int *hash_table
= NULL
;
5447 file_ptr lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
5450 (unsigned int *) bfd_malloc (lst_header
->hash_size
5451 * sizeof (unsigned int));
5452 if (hash_table
== NULL
&& lst_header
->hash_size
!= 0)
5455 /* Don't forget to initialize the counter! */
5458 /* Read in the hash table. The has table is an array of 32bit file offsets
5459 which point to the hash chains. */
5460 if (bfd_read ((PTR
) hash_table
, lst_header
->hash_size
, 4, abfd
)
5461 != lst_header
->hash_size
* 4)
5464 /* Walk each chain counting the number of symbols found on that particular
5466 for (i
= 0; i
< lst_header
->hash_size
; i
++)
5468 struct lst_symbol_record lst_symbol
;
5470 /* An empty chain has zero as it's file offset. */
5471 if (hash_table
[i
] == 0)
5474 /* Seek to the first symbol in this hash chain. */
5475 if (bfd_seek (abfd
, lst_filepos
+ hash_table
[i
], SEEK_SET
) < 0)
5478 /* Read in this symbol and update the counter. */
5479 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
5480 != sizeof (lst_symbol
))
5485 /* Now iterate through the rest of the symbols on this chain. */
5486 while (lst_symbol
.next_entry
)
5489 /* Seek to the next symbol. */
5490 if (bfd_seek (abfd
, lst_filepos
+ lst_symbol
.next_entry
, SEEK_SET
)
5494 /* Read the symbol in and update the counter. */
5495 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
5496 != sizeof (lst_symbol
))
5502 if (hash_table
!= NULL
)
5507 if (hash_table
!= NULL
)
5512 /* Fill in the canonical archive symbols (SYMS) from the archive described
5513 by ABFD and LST_HEADER. */
5516 som_bfd_fill_in_ar_symbols (abfd
, lst_header
, syms
)
5518 struct lst_header
*lst_header
;
5521 unsigned int i
, len
;
5522 carsym
*set
= syms
[0];
5523 unsigned int *hash_table
= NULL
;
5524 struct som_entry
*som_dict
= NULL
;
5525 file_ptr lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
5528 (unsigned int *) bfd_malloc (lst_header
->hash_size
5529 * sizeof (unsigned int));
5530 if (hash_table
== NULL
&& lst_header
->hash_size
!= 0)
5534 (struct som_entry
*) bfd_malloc (lst_header
->module_count
5535 * sizeof (struct som_entry
));
5536 if (som_dict
== NULL
&& lst_header
->module_count
!= 0)
5539 /* Read in the hash table. The has table is an array of 32bit file offsets
5540 which point to the hash chains. */
5541 if (bfd_read ((PTR
) hash_table
, lst_header
->hash_size
, 4, abfd
)
5542 != lst_header
->hash_size
* 4)
5545 /* Seek to and read in the SOM dictionary. We will need this to fill
5546 in the carsym's filepos field. */
5547 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->dir_loc
, SEEK_SET
) < 0)
5550 if (bfd_read ((PTR
) som_dict
, lst_header
->module_count
,
5551 sizeof (struct som_entry
), abfd
)
5552 != lst_header
->module_count
* sizeof (struct som_entry
))
5555 /* Walk each chain filling in the carsyms as we go along. */
5556 for (i
= 0; i
< lst_header
->hash_size
; i
++)
5558 struct lst_symbol_record lst_symbol
;
5560 /* An empty chain has zero as it's file offset. */
5561 if (hash_table
[i
] == 0)
5564 /* Seek to and read the first symbol on the chain. */
5565 if (bfd_seek (abfd
, lst_filepos
+ hash_table
[i
], SEEK_SET
) < 0)
5568 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
5569 != sizeof (lst_symbol
))
5572 /* Get the name of the symbol, first get the length which is stored
5573 as a 32bit integer just before the symbol.
5575 One might ask why we don't just read in the entire string table
5576 and index into it. Well, according to the SOM ABI the string
5577 index can point *anywhere* in the archive to save space, so just
5578 using the string table would not be safe. */
5579 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->string_loc
5580 + lst_symbol
.name
.n_strx
- 4, SEEK_SET
) < 0)
5583 if (bfd_read (&len
, 1, 4, abfd
) != 4)
5586 /* Allocate space for the name and null terminate it too. */
5587 set
->name
= bfd_zalloc (abfd
, len
+ 1);
5590 if (bfd_read (set
->name
, 1, len
, abfd
) != len
)
5595 /* Fill in the file offset. Note that the "location" field points
5596 to the SOM itself, not the ar_hdr in front of it. */
5597 set
->file_offset
= som_dict
[lst_symbol
.som_index
].location
5598 - sizeof (struct ar_hdr
);
5600 /* Go to the next symbol. */
5603 /* Iterate through the rest of the chain. */
5604 while (lst_symbol
.next_entry
)
5606 /* Seek to the next symbol and read it in. */
5607 if (bfd_seek (abfd
, lst_filepos
+ lst_symbol
.next_entry
, SEEK_SET
) <0)
5610 if (bfd_read ((PTR
) & lst_symbol
, 1, sizeof (lst_symbol
), abfd
)
5611 != sizeof (lst_symbol
))
5614 /* Seek to the name length & string and read them in. */
5615 if (bfd_seek (abfd
, lst_filepos
+ lst_header
->string_loc
5616 + lst_symbol
.name
.n_strx
- 4, SEEK_SET
) < 0)
5619 if (bfd_read (&len
, 1, 4, abfd
) != 4)
5622 /* Allocate space for the name and null terminate it too. */
5623 set
->name
= bfd_zalloc (abfd
, len
+ 1);
5627 if (bfd_read (set
->name
, 1, len
, abfd
) != len
)
5631 /* Fill in the file offset. Note that the "location" field points
5632 to the SOM itself, not the ar_hdr in front of it. */
5633 set
->file_offset
= som_dict
[lst_symbol
.som_index
].location
5634 - sizeof (struct ar_hdr
);
5636 /* Go on to the next symbol. */
5640 /* If we haven't died by now, then we successfully read the entire
5641 archive symbol table. */
5642 if (hash_table
!= NULL
)
5644 if (som_dict
!= NULL
)
5649 if (hash_table
!= NULL
)
5651 if (som_dict
!= NULL
)
5656 /* Read in the LST from the archive. */
5658 som_slurp_armap (abfd
)
5661 struct lst_header lst_header
;
5662 struct ar_hdr ar_header
;
5663 unsigned int parsed_size
;
5664 struct artdata
*ardata
= bfd_ardata (abfd
);
5666 int i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
5668 /* Special cases. */
5674 if (bfd_seek (abfd
, (file_ptr
) - 16, SEEK_CUR
) < 0)
5677 /* For archives without .o files there is no symbol table. */
5678 if (strncmp (nextname
, "/ ", 16))
5680 bfd_has_map (abfd
) = false;
5684 /* Read in and sanity check the archive header. */
5685 if (bfd_read ((PTR
) &ar_header
, 1, sizeof (struct ar_hdr
), abfd
)
5686 != sizeof (struct ar_hdr
))
5689 if (strncmp (ar_header
.ar_fmag
, ARFMAG
, 2))
5691 bfd_set_error (bfd_error_malformed_archive
);
5695 /* How big is the archive symbol table entry? */
5697 parsed_size
= strtol (ar_header
.ar_size
, NULL
, 10);
5700 bfd_set_error (bfd_error_malformed_archive
);
5704 /* Save off the file offset of the first real user data. */
5705 ardata
->first_file_filepos
= bfd_tell (abfd
) + parsed_size
;
5707 /* Read in the library symbol table. We'll make heavy use of this
5708 in just a minute. */
5709 if (bfd_read ((PTR
) & lst_header
, 1, sizeof (struct lst_header
), abfd
)
5710 != sizeof (struct lst_header
))
5714 if (lst_header
.a_magic
!= LIBMAGIC
)
5716 bfd_set_error (bfd_error_malformed_archive
);
5720 /* Count the number of symbols in the library symbol table. */
5721 if (som_bfd_count_ar_symbols (abfd
, &lst_header
, &ardata
->symdef_count
)
5725 /* Get back to the start of the library symbol table. */
5726 if (bfd_seek (abfd
, ardata
->first_file_filepos
- parsed_size
5727 + sizeof (struct lst_header
), SEEK_SET
) < 0)
5730 /* Initializae the cache and allocate space for the library symbols. */
5732 ardata
->symdefs
= (carsym
*) bfd_alloc (abfd
,
5733 (ardata
->symdef_count
5734 * sizeof (carsym
)));
5735 if (!ardata
->symdefs
)
5738 /* Now fill in the canonical archive symbols. */
5739 if (som_bfd_fill_in_ar_symbols (abfd
, &lst_header
, &ardata
->symdefs
)
5743 /* Seek back to the "first" file in the archive. Note the "first"
5744 file may be the extended name table. */
5745 if (bfd_seek (abfd
, ardata
->first_file_filepos
, SEEK_SET
) < 0)
5748 /* Notify the generic archive code that we have a symbol map. */
5749 bfd_has_map (abfd
) = true;
5753 /* Begin preparing to write a SOM library symbol table.
5755 As part of the prep work we need to determine the number of symbols
5756 and the size of the associated string section. */
5759 som_bfd_prep_for_ar_write (abfd
, num_syms
, stringsize
)
5761 unsigned int *num_syms
, *stringsize
;
5763 bfd
*curr_bfd
= abfd
->archive_head
;
5765 /* Some initialization. */
5769 /* Iterate over each BFD within this archive. */
5770 while (curr_bfd
!= NULL
)
5772 unsigned int curr_count
, i
;
5773 som_symbol_type
*sym
;
5775 /* Don't bother for non-SOM objects. */
5776 if (curr_bfd
->format
!= bfd_object
5777 || curr_bfd
->xvec
->flavour
!= bfd_target_som_flavour
)
5779 curr_bfd
= curr_bfd
->next
;
5783 /* Make sure the symbol table has been read, then snag a pointer
5784 to it. It's a little slimey to grab the symbols via obj_som_symtab,
5785 but doing so avoids allocating lots of extra memory. */
5786 if (som_slurp_symbol_table (curr_bfd
) == false)
5789 sym
= obj_som_symtab (curr_bfd
);
5790 curr_count
= bfd_get_symcount (curr_bfd
);
5792 /* Examine each symbol to determine if it belongs in the
5793 library symbol table. */
5794 for (i
= 0; i
< curr_count
; i
++, sym
++)
5796 struct som_misc_symbol_info info
;
5798 /* Derive SOM information from the BFD symbol. */
5799 som_bfd_derive_misc_symbol_info (curr_bfd
, &sym
->symbol
, &info
);
5801 /* Should we include this symbol? */
5802 if (info
.symbol_type
== ST_NULL
5803 || info
.symbol_type
== ST_SYM_EXT
5804 || info
.symbol_type
== ST_ARG_EXT
)
5807 /* Only global symbols and unsatisfied commons. */
5808 if (info
.symbol_scope
!= SS_UNIVERSAL
5809 && info
.symbol_type
!= ST_STORAGE
)
5812 /* Do no include undefined symbols. */
5813 if (bfd_is_und_section (sym
->symbol
.section
))
5816 /* Bump the various counters, being careful to honor
5817 alignment considerations in the string table. */
5819 *stringsize
= *stringsize
+ strlen (sym
->symbol
.name
) + 5;
5820 while (*stringsize
% 4)
5824 curr_bfd
= curr_bfd
->next
;
5829 /* Hash a symbol name based on the hashing algorithm presented in the
5832 som_bfd_ar_symbol_hash (symbol
)
5835 unsigned int len
= strlen (symbol
->name
);
5837 /* Names with length 1 are special. */
5839 return 0x1000100 | (symbol
->name
[0] << 16) | symbol
->name
[0];
5841 return ((len
& 0x7f) << 24) | (symbol
->name
[1] << 16)
5842 | (symbol
->name
[len
-2] << 8) | symbol
->name
[len
-1];
5845 /* Do the bulk of the work required to write the SOM library
5849 som_bfd_ar_write_symbol_stuff (abfd
, nsyms
, string_size
, lst
, elength
)
5851 unsigned int nsyms
, string_size
;
5852 struct lst_header lst
;
5855 file_ptr lst_filepos
;
5856 char *strings
= NULL
, *p
;
5857 struct lst_symbol_record
*lst_syms
= NULL
, *curr_lst_sym
;
5859 unsigned int *hash_table
= NULL
;
5860 struct som_entry
*som_dict
= NULL
;
5861 struct lst_symbol_record
**last_hash_entry
= NULL
;
5862 unsigned int curr_som_offset
, som_index
= 0;
5865 (unsigned int *) bfd_malloc (lst
.hash_size
* sizeof (unsigned int));
5866 if (hash_table
== NULL
&& lst
.hash_size
!= 0)
5869 (struct som_entry
*) bfd_malloc (lst
.module_count
5870 * sizeof (struct som_entry
));
5871 if (som_dict
== NULL
&& lst
.module_count
!= 0)
5875 ((struct lst_symbol_record
**)
5876 bfd_malloc (lst
.hash_size
* sizeof (struct lst_symbol_record
*)));
5877 if (last_hash_entry
== NULL
&& lst
.hash_size
!= 0)
5880 /* Lots of fields are file positions relative to the start
5881 of the lst record. So save its location. */
5882 lst_filepos
= bfd_tell (abfd
) - sizeof (struct lst_header
);
5884 /* Some initialization. */
5885 memset (hash_table
, 0, 4 * lst
.hash_size
);
5886 memset (som_dict
, 0, lst
.module_count
* sizeof (struct som_entry
));
5887 memset (last_hash_entry
, 0,
5888 lst
.hash_size
* sizeof (struct lst_symbol_record
*));
5890 /* Symbols have som_index fields, so we have to keep track of the
5891 index of each SOM in the archive.
5893 The SOM dictionary has (among other things) the absolute file
5894 position for the SOM which a particular dictionary entry
5895 describes. We have to compute that information as we iterate
5896 through the SOMs/symbols. */
5899 /* We add in the size of the archive header twice as the location
5900 in the SOM dictionary is the actual offset of the SOM, not the
5901 archive header before the SOM. */
5902 curr_som_offset
= 8 + 2 * sizeof (struct ar_hdr
) + lst
.file_end
;
5904 /* Make room for the archive header and the contents of the
5905 extended string table. Note that elength includes the size
5906 of the archive header for the extended name table! */
5908 curr_som_offset
+= elength
;
5910 /* Make sure we're properly aligned. */
5911 curr_som_offset
= (curr_som_offset
+ 0x1) & ~0x1;
5913 /* FIXME should be done with buffers just like everything else... */
5914 lst_syms
= bfd_malloc (nsyms
* sizeof (struct lst_symbol_record
));
5915 if (lst_syms
== NULL
&& nsyms
!= 0)
5917 strings
= bfd_malloc (string_size
);
5918 if (strings
== NULL
&& string_size
!= 0)
5922 curr_lst_sym
= lst_syms
;
5924 curr_bfd
= abfd
->archive_head
;
5925 while (curr_bfd
!= NULL
)
5927 unsigned int curr_count
, i
;
5928 som_symbol_type
*sym
;
5930 /* Don't bother for non-SOM objects. */
5931 if (curr_bfd
->format
!= bfd_object
5932 || curr_bfd
->xvec
->flavour
!= bfd_target_som_flavour
)
5934 curr_bfd
= curr_bfd
->next
;
5938 /* Make sure the symbol table has been read, then snag a pointer
5939 to it. It's a little slimey to grab the symbols via obj_som_symtab,
5940 but doing so avoids allocating lots of extra memory. */
5941 if (som_slurp_symbol_table (curr_bfd
) == false)
5944 sym
= obj_som_symtab (curr_bfd
);
5945 curr_count
= bfd_get_symcount (curr_bfd
);
5947 for (i
= 0; i
< curr_count
; i
++, sym
++)
5949 struct som_misc_symbol_info info
;
5951 /* Derive SOM information from the BFD symbol. */
5952 som_bfd_derive_misc_symbol_info (curr_bfd
, &sym
->symbol
, &info
);
5954 /* Should we include this symbol? */
5955 if (info
.symbol_type
== ST_NULL
5956 || info
.symbol_type
== ST_SYM_EXT
5957 || info
.symbol_type
== ST_ARG_EXT
)
5960 /* Only global symbols and unsatisfied commons. */
5961 if (info
.symbol_scope
!= SS_UNIVERSAL
5962 && info
.symbol_type
!= ST_STORAGE
)
5965 /* Do no include undefined symbols. */
5966 if (bfd_is_und_section (sym
->symbol
.section
))
5969 /* If this is the first symbol from this SOM, then update
5970 the SOM dictionary too. */
5971 if (som_dict
[som_index
].location
== 0)
5973 som_dict
[som_index
].location
= curr_som_offset
;
5974 som_dict
[som_index
].length
= arelt_size (curr_bfd
);
5977 /* Fill in the lst symbol record. */
5978 curr_lst_sym
->hidden
= 0;
5979 curr_lst_sym
->secondary_def
= info
.secondary_def
;
5980 curr_lst_sym
->symbol_type
= info
.symbol_type
;
5981 curr_lst_sym
->symbol_scope
= info
.symbol_scope
;
5982 curr_lst_sym
->check_level
= 0;
5983 curr_lst_sym
->must_qualify
= 0;
5984 curr_lst_sym
->initially_frozen
= 0;
5985 curr_lst_sym
->memory_resident
= 0;
5986 curr_lst_sym
->is_common
= bfd_is_com_section (sym
->symbol
.section
);
5987 curr_lst_sym
->dup_common
= 0;
5988 curr_lst_sym
->xleast
= 3;
5989 curr_lst_sym
->arg_reloc
= info
.arg_reloc
;
5990 curr_lst_sym
->name
.n_strx
= p
- strings
+ 4;
5991 curr_lst_sym
->qualifier_name
.n_strx
= 0;
5992 curr_lst_sym
->symbol_info
= info
.symbol_info
;
5993 curr_lst_sym
->symbol_value
= info
.symbol_value
| info
.priv_level
;
5994 curr_lst_sym
->symbol_descriptor
= 0;
5995 curr_lst_sym
->reserved
= 0;
5996 curr_lst_sym
->som_index
= som_index
;
5997 curr_lst_sym
->symbol_key
= som_bfd_ar_symbol_hash (&sym
->symbol
);
5998 curr_lst_sym
->next_entry
= 0;
6000 /* Insert into the hash table. */
6001 if (hash_table
[curr_lst_sym
->symbol_key
% lst
.hash_size
])
6003 struct lst_symbol_record
*tmp
;
6005 /* There is already something at the head of this hash chain,
6006 so tack this symbol onto the end of the chain. */
6007 tmp
= last_hash_entry
[curr_lst_sym
->symbol_key
% lst
.hash_size
];
6009 = (curr_lst_sym
- lst_syms
) * sizeof (struct lst_symbol_record
)
6011 + lst
.module_count
* sizeof (struct som_entry
)
6012 + sizeof (struct lst_header
);
6016 /* First entry in this hash chain. */
6017 hash_table
[curr_lst_sym
->symbol_key
% lst
.hash_size
]
6018 = (curr_lst_sym
- lst_syms
) * sizeof (struct lst_symbol_record
)
6020 + lst
.module_count
* sizeof (struct som_entry
)
6021 + sizeof (struct lst_header
);
6024 /* Keep track of the last symbol we added to this chain so we can
6025 easily update its next_entry pointer. */
6026 last_hash_entry
[curr_lst_sym
->symbol_key
% lst
.hash_size
]
6030 /* Update the string table. */
6031 bfd_put_32 (abfd
, strlen (sym
->symbol
.name
), p
);
6033 strcpy (p
, sym
->symbol
.name
);
6034 p
+= strlen (sym
->symbol
.name
) + 1;
6037 bfd_put_8 (abfd
, 0, p
);
6041 /* Head to the next symbol. */
6045 /* Keep track of where each SOM will finally reside; then look
6047 curr_som_offset
+= arelt_size (curr_bfd
) + sizeof (struct ar_hdr
);
6049 /* A particular object in the archive may have an odd length; the
6050 linker requires objects begin on an even boundary. So round
6051 up the current offset as necessary. */
6052 curr_som_offset
= (curr_som_offset
+ 0x1) & ~0x1;
6053 curr_bfd
= curr_bfd
->next
;
6057 /* Now scribble out the hash table. */
6058 if (bfd_write ((PTR
) hash_table
, lst
.hash_size
, 4, abfd
)
6059 != lst
.hash_size
* 4)
6062 /* Then the SOM dictionary. */
6063 if (bfd_write ((PTR
) som_dict
, lst
.module_count
,
6064 sizeof (struct som_entry
), abfd
)
6065 != lst
.module_count
* sizeof (struct som_entry
))
6068 /* The library symbols. */
6069 if (bfd_write ((PTR
) lst_syms
, nsyms
, sizeof (struct lst_symbol_record
), abfd
)
6070 != nsyms
* sizeof (struct lst_symbol_record
))
6073 /* And finally the strings. */
6074 if (bfd_write ((PTR
) strings
, string_size
, 1, abfd
) != string_size
)
6077 if (hash_table
!= NULL
)
6079 if (som_dict
!= NULL
)
6081 if (last_hash_entry
!= NULL
)
6082 free (last_hash_entry
);
6083 if (lst_syms
!= NULL
)
6085 if (strings
!= NULL
)
6090 if (hash_table
!= NULL
)
6092 if (som_dict
!= NULL
)
6094 if (last_hash_entry
!= NULL
)
6095 free (last_hash_entry
);
6096 if (lst_syms
!= NULL
)
6098 if (strings
!= NULL
)
6104 /* Write out the LST for the archive.
6106 You'll never believe this is really how armaps are handled in SOM... */
6110 som_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
6112 unsigned int elength
;
6113 struct orl
*map ATTRIBUTE_UNUSED
;
6114 unsigned int orl_count ATTRIBUTE_UNUSED
;
6115 int stridx ATTRIBUTE_UNUSED
;
6118 struct stat statbuf
;
6119 unsigned int i
, lst_size
, nsyms
, stringsize
;
6121 struct lst_header lst
;
6124 /* We'll use this for the archive's date and mode later. */
6125 if (stat (abfd
->filename
, &statbuf
) != 0)
6127 bfd_set_error (bfd_error_system_call
);
6131 bfd_ardata (abfd
)->armap_timestamp
= statbuf
.st_mtime
+ 60;
6133 /* Account for the lst header first. */
6134 lst_size
= sizeof (struct lst_header
);
6136 /* Start building the LST header. */
6137 /* FIXME: Do we need to examine each element to determine the
6138 largest id number? */
6139 lst
.system_id
= CPU_PA_RISC1_0
;
6140 lst
.a_magic
= LIBMAGIC
;
6141 lst
.version_id
= VERSION_ID
;
6142 lst
.file_time
.secs
= 0;
6143 lst
.file_time
.nanosecs
= 0;
6145 lst
.hash_loc
= lst_size
;
6146 lst
.hash_size
= SOM_LST_HASH_SIZE
;
6148 /* Hash table is a SOM_LST_HASH_SIZE 32bit offsets. */
6149 lst_size
+= 4 * SOM_LST_HASH_SIZE
;
6151 /* We need to count the number of SOMs in this archive. */
6152 curr_bfd
= abfd
->archive_head
;
6153 lst
.module_count
= 0;
6154 while (curr_bfd
!= NULL
)
6156 /* Only true SOM objects count. */
6157 if (curr_bfd
->format
== bfd_object
6158 && curr_bfd
->xvec
->flavour
== bfd_target_som_flavour
)
6160 curr_bfd
= curr_bfd
->next
;
6162 lst
.module_limit
= lst
.module_count
;
6163 lst
.dir_loc
= lst_size
;
6164 lst_size
+= sizeof (struct som_entry
) * lst
.module_count
;
6166 /* We don't support import/export tables, auxiliary headers,
6167 or free lists yet. Make the linker work a little harder
6168 to make our life easier. */
6171 lst
.export_count
= 0;
6176 /* Count how many symbols we will have on the hash chains and the
6177 size of the associated string table. */
6178 if (som_bfd_prep_for_ar_write (abfd
, &nsyms
, &stringsize
) == false)
6181 lst_size
+= sizeof (struct lst_symbol_record
) * nsyms
;
6183 /* For the string table. One day we might actually use this info
6184 to avoid small seeks/reads when reading archives. */
6185 lst
.string_loc
= lst_size
;
6186 lst
.string_size
= stringsize
;
6187 lst_size
+= stringsize
;
6189 /* SOM ABI says this must be zero. */
6191 lst
.file_end
= lst_size
;
6193 /* Compute the checksum. Must happen after the entire lst header
6197 for (i
= 0; i
< sizeof (struct lst_header
)/sizeof (int) - 1; i
++)
6198 lst
.checksum
^= *p
++;
6200 sprintf (hdr
.ar_name
, "/ ");
6201 sprintf (hdr
.ar_date
, "%ld", bfd_ardata (abfd
)->armap_timestamp
);
6202 sprintf (hdr
.ar_uid
, "%ld", (long) getuid ());
6203 sprintf (hdr
.ar_gid
, "%ld", (long) getgid ());
6204 sprintf (hdr
.ar_mode
, "%-8o", (unsigned int) statbuf
.st_mode
);
6205 sprintf (hdr
.ar_size
, "%-10d", (int) lst_size
);
6206 hdr
.ar_fmag
[0] = '`';
6207 hdr
.ar_fmag
[1] = '\012';
6209 /* Turn any nulls into spaces. */
6210 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
6211 if (((char *) (&hdr
))[i
] == '\0')
6212 (((char *) (&hdr
))[i
]) = ' ';
6214 /* Scribble out the ar header. */
6215 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
6216 != sizeof (struct ar_hdr
))
6219 /* Now scribble out the lst header. */
6220 if (bfd_write ((PTR
) &lst
, 1, sizeof (struct lst_header
), abfd
)
6221 != sizeof (struct lst_header
))
6224 /* Build and write the armap. */
6225 if (som_bfd_ar_write_symbol_stuff (abfd
, nsyms
, stringsize
, lst
, elength
)
6233 /* Free all information we have cached for this BFD. We can always
6234 read it again later if we need it. */
6237 som_bfd_free_cached_info (abfd
)
6242 if (bfd_get_format (abfd
) != bfd_object
)
6245 #define FREE(x) if (x != NULL) { free (x); x = NULL; }
6246 /* Free the native string and symbol tables. */
6247 FREE (obj_som_symtab (abfd
));
6248 FREE (obj_som_stringtab (abfd
));
6249 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
6251 /* Free the native relocations. */
6252 o
->reloc_count
= -1;
6253 FREE (som_section_data (o
)->reloc_stream
);
6254 /* Free the generic relocations. */
6255 FREE (o
->relocation
);
6262 /* End of miscellaneous support functions. */
6264 /* Linker support functions. */
6266 som_bfd_link_split_section (abfd
, sec
)
6267 bfd
*abfd ATTRIBUTE_UNUSED
;
6270 return (som_is_subspace (sec
) && sec
->_raw_size
> 240000);
6273 #define som_close_and_cleanup som_bfd_free_cached_info
6275 #define som_read_ar_hdr _bfd_generic_read_ar_hdr
6276 #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
6277 #define som_get_elt_at_index _bfd_generic_get_elt_at_index
6278 #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
6279 #define som_truncate_arname bfd_bsd_truncate_arname
6280 #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
6281 #define som_construct_extended_name_table \
6282 _bfd_archive_coff_construct_extended_name_table
6283 #define som_update_armap_timestamp bfd_true
6284 #define som_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
6286 #define som_get_lineno _bfd_nosymbols_get_lineno
6287 #define som_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
6288 #define som_read_minisymbols _bfd_generic_read_minisymbols
6289 #define som_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
6290 #define som_get_section_contents_in_window \
6291 _bfd_generic_get_section_contents_in_window
6293 #define som_bfd_get_relocated_section_contents \
6294 bfd_generic_get_relocated_section_contents
6295 #define som_bfd_relax_section bfd_generic_relax_section
6296 #define som_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
6297 #define som_bfd_link_add_symbols _bfd_generic_link_add_symbols
6298 #define som_bfd_final_link _bfd_generic_final_link
6300 #define som_bfd_gc_sections bfd_generic_gc_sections
6303 const bfd_target som_vec
=
6306 bfd_target_som_flavour
,
6307 BFD_ENDIAN_BIG
, /* target byte order */
6308 BFD_ENDIAN_BIG
, /* target headers byte order */
6309 (HAS_RELOC
| EXEC_P
| /* object flags */
6310 HAS_LINENO
| HAS_DEBUG
|
6311 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
| DYNAMIC
),
6312 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
6313 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
6315 /* leading_symbol_char: is the first char of a user symbol
6316 predictable, and if so what is it */
6318 '/', /* ar_pad_char */
6319 14, /* ar_max_namelen */
6320 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
6321 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
6322 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
6323 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
6324 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
6325 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
6327 som_object_p
, /* bfd_check_format */
6328 bfd_generic_archive_p
,
6334 _bfd_generic_mkarchive
,
6339 som_write_object_contents
,
6340 _bfd_write_archive_contents
,
6345 BFD_JUMP_TABLE_GENERIC (som
),
6346 BFD_JUMP_TABLE_COPY (som
),
6347 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
6348 BFD_JUMP_TABLE_ARCHIVE (som
),
6349 BFD_JUMP_TABLE_SYMBOLS (som
),
6350 BFD_JUMP_TABLE_RELOCS (som
),
6351 BFD_JUMP_TABLE_WRITE (som
),
6352 BFD_JUMP_TABLE_LINK (som
),
6353 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
6360 #endif /* HOST_HPPAHPUX || HOST_HPPABSD || HOST_HPPAOSF */