1 /* evax-alpha.c -- BFD back-end for ALPHA EVAX (openVMS/Alpha) files.
2 Copyright 1996, 1997, 1998 Free Software Foundation, Inc.
3 Written by Klaus K"ampf (kkaempf@progis.de)
4 of proGIS Softwareentwicklung, Aachen, Germany
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 static boolean evax_initialize
PARAMS ((bfd
*));
28 static boolean fill_section_ptr
PARAMS ((struct bfd_hash_entry
*, PTR
));
29 static boolean evax_fixup_sections
PARAMS ((bfd
*));
30 static boolean copy_symbols
PARAMS ((struct bfd_hash_entry
*, PTR
));
31 static bfd_reloc_status_type reloc_nil
32 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
33 static const struct bfd_target
*evax_object_p
PARAMS ((bfd
*abfd
));
34 static const struct bfd_target
*evax_archive_p
PARAMS ((bfd
*abfd
));
35 static boolean evax_mkobject
PARAMS ((bfd
*abfd
));
36 static boolean evax_write_object_contents
PARAMS ((bfd
*abfd
));
37 static boolean evax_close_and_cleanup
PARAMS ((bfd
*abfd
));
38 static boolean evax_bfd_free_cached_info
PARAMS ((bfd
*abfd
));
39 static boolean evax_new_section_hook
PARAMS ((bfd
*abfd
, asection
*section
));
40 static boolean evax_get_section_contents
41 PARAMS ((bfd
*abfd
, asection
*section
, PTR x1
, file_ptr x2
,
43 static boolean evax_get_section_contents_in_window
44 PARAMS ((bfd
*abfd
, asection
*section
, bfd_window
*w
, file_ptr offset
,
45 bfd_size_type count
));
46 static boolean evax_bfd_copy_private_bfd_data
PARAMS ((bfd
*src
, bfd
*dest
));
47 static boolean evax_bfd_copy_private_section_data
48 PARAMS ((bfd
*srcbfd
, asection
*srcsec
, bfd
*dstbfd
, asection
*dstsec
));
49 static boolean evax_bfd_copy_private_symbol_data
50 PARAMS ((bfd
*ibfd
, asymbol
*isym
, bfd
*obfd
, asymbol
*osym
));
51 static boolean evax_bfd_print_private_bfd_data
52 PARAMS ((bfd
*abfd
, void *file
));
53 static char *evax_core_file_failing_command
PARAMS ((bfd
*abfd
));
54 static int evax_core_file_failing_signal
PARAMS ((bfd
*abfd
));
55 static boolean evax_core_file_matches_executable_p
56 PARAMS ((bfd
*abfd
, bfd
*bbfd
));
57 static boolean evax_slurp_armap
PARAMS ((bfd
*abfd
));
58 static boolean evax_slurp_extended_name_table
PARAMS ((bfd
*abfd
));
59 static boolean evax_construct_extended_name_table
60 PARAMS ((bfd
*abfd
, char **tabloc
, bfd_size_type
*tablen
,
62 static void evax_truncate_arname
63 PARAMS ((bfd
*abfd
, CONST
char *pathname
, char *arhdr
));
64 static boolean evax_write_armap
65 PARAMS ((bfd
*arch
, unsigned int elength
, struct orl
*map
,
66 unsigned int orl_count
, int stridx
));
67 static PTR evax_read_ar_hdr
PARAMS ((bfd
*abfd
));
68 static bfd
*evax_get_elt_at_index
PARAMS ((bfd
*abfd
, symindex index
));
69 static bfd
*evax_openr_next_archived_file
PARAMS ((bfd
*arch
, bfd
*prev
));
70 static boolean evax_update_armap_timestamp
PARAMS ((bfd
*abfd
));
71 static int evax_generic_stat_arch_elt
PARAMS ((bfd
*abfd
, struct stat
*stat
));
72 static long evax_get_symtab_upper_bound
PARAMS ((bfd
*abfd
));
73 static long evax_get_symtab
PARAMS ((bfd
*abfd
, asymbol
**symbols
));
74 static void evax_print_symbol
75 PARAMS ((bfd
*abfd
, PTR file
, asymbol
*symbol
, bfd_print_symbol_type how
));
76 static void evax_get_symbol_info
77 PARAMS ((bfd
*abfd
, asymbol
*symbol
, symbol_info
*ret
));
78 static boolean evax_bfd_is_local_label_name
PARAMS ((bfd
*abfd
, const char *));
79 static alent
*evax_get_lineno
PARAMS ((bfd
*abfd
, asymbol
*symbol
));
80 static boolean evax_find_nearest_line
81 PARAMS ((bfd
*abfd
, asection
*section
, asymbol
**symbols
, bfd_vma offset
,
82 const char **file
, const char **func
, unsigned int *line
));
83 static asymbol
*evax_bfd_make_debug_symbol
84 PARAMS ((bfd
*abfd
, void *ptr
, unsigned long size
));
85 static long evax_read_minisymbols
86 PARAMS ((bfd
*abfd
, boolean dynamic
, PTR
*minisymsp
, unsigned int *sizep
));
87 static asymbol
*evax_minisymbol_to_symbol
88 PARAMS ((bfd
*abfd
, boolean dynamic
, const PTR minisym
, asymbol
*sym
));
89 static long evax_get_reloc_upper_bound
PARAMS ((bfd
*abfd
, asection
*sect
));
90 static long evax_canonicalize_reloc
91 PARAMS ((bfd
*abfd
, asection
*srcsec
, arelent
**location
,
93 static const struct reloc_howto_struct
*evax_bfd_reloc_type_lookup
94 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
95 static boolean evax_set_arch_mach
96 PARAMS ((bfd
*abfd
, enum bfd_architecture arch
, unsigned long mach
));
97 static boolean evax_set_section_contents
98 PARAMS ((bfd
*abfd
, asection
*section
, PTR location
, file_ptr offset
,
99 bfd_size_type count
));
100 static int evax_sizeof_headers
PARAMS ((bfd
*abfd
, boolean reloc
));
101 static bfd_byte
*evax_bfd_get_relocated_section_contents
102 PARAMS ((bfd
*abfd
, struct bfd_link_info
*link_info
,
103 struct bfd_link_order
*link_order
, bfd_byte
*data
,
104 boolean relocateable
, asymbol
**symbols
));
105 static boolean evax_bfd_relax_section
106 PARAMS ((bfd
*abfd
, asection
*section
, struct bfd_link_info
*link_info
,
108 static struct bfd_link_hash_table
*evax_bfd_link_hash_table_create
109 PARAMS ((bfd
*abfd
));
110 static boolean evax_bfd_link_add_symbols
111 PARAMS ((bfd
*abfd
, struct bfd_link_info
*link_info
));
112 static boolean evax_bfd_final_link
113 PARAMS ((bfd
*abfd
, struct bfd_link_info
*link_info
));
114 static boolean evax_bfd_link_split_section
115 PARAMS ((bfd
*abfd
, asection
*section
));
116 static long evax_get_dynamic_symtab_upper_bound
PARAMS ((bfd
*abfd
));
117 static long evax_canonicalize_dynamic_symtab
118 PARAMS ((bfd
*abfd
, asymbol
**symbols
));
119 static long evax_get_dynamic_reloc_upper_bound
PARAMS ((bfd
*abfd
));
120 static long evax_canonicalize_dynamic_reloc
121 PARAMS ((bfd
*abfd
, arelent
**arel
, asymbol
**symbols
));
122 static boolean evax_bfd_merge_private_bfd_data
PARAMS ((bfd
*ibfd
, bfd
*obfd
));
123 static boolean evax_bfd_set_private_flags
PARAMS ((bfd
*abfd
, flagword flags
));
125 #define evax_make_empty_symbol _bfd_evax_make_empty_symbol
127 /*===========================================================================*/
129 const bfd_target evax_alpha_vec
=
132 "evax-alpha", /* name */
133 bfd_target_evax_flavour
,
134 false, /* data byte order is little */
135 false, /* header byte order is little */
137 (HAS_RELOC
| HAS_SYMS
138 | WP_TEXT
| D_PAGED
), /* object flags */
139 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
140 | SEC_READONLY
| SEC_CODE
| SEC_DATA
141 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* sect flags */
142 0, /* symbol_leading_char */
143 ' ', /* ar_pad_char */
144 15, /* ar_max_namelen */
145 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
146 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
147 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
148 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
149 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
150 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
152 {_bfd_dummy_target
, evax_object_p
, /* bfd_check_format */
153 evax_archive_p
, _bfd_dummy_target
},
154 {bfd_false
, evax_mkobject
, /* bfd_set_format */
155 _bfd_generic_mkarchive
, bfd_false
},
156 {bfd_false
, evax_write_object_contents
, /* bfd_write_contents */
157 _bfd_write_archive_contents
, bfd_false
},
159 BFD_JUMP_TABLE_GENERIC (evax
),
160 BFD_JUMP_TABLE_COPY (evax
),
161 BFD_JUMP_TABLE_CORE (evax
),
162 BFD_JUMP_TABLE_ARCHIVE (evax
),
163 BFD_JUMP_TABLE_SYMBOLS (evax
),
164 BFD_JUMP_TABLE_RELOCS (evax
),
165 BFD_JUMP_TABLE_WRITE (evax
),
166 BFD_JUMP_TABLE_LINK (evax
),
167 BFD_JUMP_TABLE_DYNAMIC (evax
),
173 /*===========================================================================*/
175 /* Initialize private data */
178 evax_initialize (abfd
)
183 if (abfd
->tdata
.any
!= 0)
186 bfd_set_start_address (abfd
, (bfd_vma
)-1);
188 abfd
->tdata
.any
= ((struct evax_private_data_struct
*)
189 bfd_malloc (sizeof (struct evax_private_data_struct
)));
190 if (abfd
->tdata
.any
== 0)
194 PRIV(rec_length
) = 0;
195 PRIV(file_format
) = FF_UNKNOWN
;
196 PRIV(fixup_done
) = false;
197 PRIV(sections
) = NULL
;
199 PRIV(stack
) = ((struct stack_struct
*)
200 bfd_malloc (sizeof (struct stack_struct
) * STACKSIZE
));
201 if (PRIV(stack
) == 0)
204 free (abfd
->tdata
.any
);
210 PRIV(evax_symbol_table
) = ((struct bfd_hash_table
*)
211 bfd_malloc (sizeof (struct bfd_hash_table
)));
212 if (PRIV(evax_symbol_table
) == 0)
217 goto evax_init_no_mem1
;
220 if (!bfd_hash_table_init (PRIV(evax_symbol_table
), _bfd_evax_hash_newfunc
))
223 PRIV(location_stack
) = ((struct location_struct
*)
224 bfd_malloc (sizeof (struct location_struct
)
225 * LOCATION_SAVE_SIZE
));
226 if (PRIV(location_stack
) == 0)
229 free (PRIV(evax_symbol_table
));
230 PRIV(evax_symbol_table
) = 0;
231 goto evax_init_no_mem2
;
234 for (i
= 0; i
< EVAX_SECTION_COUNT
; i
++)
235 PRIV(evax_section_table
)[i
] = NULL
;
237 PRIV(output_buf
) = (unsigned char *) malloc (MAX_OUTREC_SIZE
);
238 if (PRIV(output_buf
) == 0)
240 free (PRIV(location_stack
));
241 PRIV(location_stack
) = 0;
242 goto evax_init_no_mem3
;
244 PRIV(push_level
) = 0;
245 PRIV(pushed_size
) = 0;
246 PRIV(length_pos
) = 2;
247 PRIV(output_size
) = 0;
248 PRIV(output_alignment
) = 1;
254 /* Fill symbol->section with section ptr
255 symbol->section is filled with the section index for defined symbols
256 during reading the EGSD section. But we need the pointer to the
259 It has the correct value for referenced (undefined section) symbols
261 called from bfd_hash_traverse in evax_fixup_sections */
264 fill_section_ptr (entry
, sections
)
265 struct bfd_hash_entry
*entry
;
271 sym
= ((evax_symbol_entry
*)entry
)->symbol
;
274 if (!bfd_is_und_section (sec
))
276 sec
= ((evax_symbol_entry
*)entry
)->symbol
->section
=
277 ((asection
**)sections
)[(int)sec
];
280 if (strcmp (sym
->name
, sec
->name
) == 0)
281 sym
->flags
|= BSF_SECTION_SYM
;
288 set up all pointers and arrays, counters and sizes are fixed now
290 we build a private sections vector for easy access since sections
291 are always referenced by an index number.
293 alloc PRIV(sections) according to abfd->section_count
294 copy abfd->sections to PRIV(sections) */
297 evax_fixup_sections (abfd
)
302 if (PRIV(fixup_done
))
305 PRIV(sections
) = ((asection
**)
306 bfd_malloc (abfd
->section_count
* sizeof (asection
*)));
307 if (PRIV(sections
) == 0)
309 PRIV(egsd_sec_count
) = abfd
->section_count
;
313 PRIV(sections
)[s
->index
] = s
;
318 * traverse symbol table and fill in all section pointers
321 bfd_hash_traverse (PRIV(evax_symbol_table
), fill_section_ptr
,
322 (PTR
)(PRIV(sections
)));
324 PRIV(fixup_done
) = true;
329 /*===========================================================================*/
331 /* Check the format for a file being read.
332 Return a (bfd_target *) if it's an object file or zero if not. */
334 static const struct bfd_target
*
341 evax_debug (1, "evax_object_p(%p)\n", abfd
);
343 if (bfd_seek (abfd
, 0L, SEEK_SET
))
345 bfd_set_error (bfd_error_file_truncated
);
354 evax_debug (3, "reading at %08lx\n", bfd_tell(abfd
));
356 if (_bfd_evax_next_record (abfd
) < 0)
359 evax_debug (2, "next_record failed\n");
361 bfd_set_error (bfd_error_wrong_format
);
365 if ((prev_type
== EOBJ_S_C_EGSD
) && (PRIV(rec_type
) != EOBJ_S_C_EGSD
))
367 if (evax_fixup_sections (abfd
) == false)
370 evax_debug (2, "evax_fixup_sections failed\n");
372 bfd_set_error (bfd_error_wrong_format
);
377 prev_type
= PRIV(rec_type
);
379 switch (PRIV(rec_type
))
382 err
= _bfd_evax_slurp_emh (abfd
);
385 err
= _bfd_evax_slurp_eeom (abfd
);
388 err
= _bfd_evax_slurp_egsd (abfd
);
391 err
= _bfd_evax_slurp_etir (abfd
);
394 err
= _bfd_evax_slurp_edbg (abfd
);
397 err
= _bfd_evax_slurp_etbt (abfd
);
405 evax_debug (2, "slurp type %d failed with %d\n", PRIV(rec_type
), err
);
407 bfd_set_error (bfd_error_wrong_format
);
411 while (prev_type
!= EOBJ_S_C_EEOM
);
413 /* set arch_info to alpha */
416 const bfd_arch_info_type
*arch
= bfd_scan_arch ("alpha");
420 evax_debug (2, "arch not found\n");
422 bfd_set_error (bfd_error_wrong_format
);
425 abfd
->arch_info
= arch
;
428 return &evax_alpha_vec
;
432 /* Check the format for a file being read.
433 Return a (bfd_target *) if it's an archive file or zero. */
435 static const struct bfd_target
*
436 evax_archive_p (abfd
)
440 evax_debug (1, "evax_archive_p(%p)\n", abfd
);
443 if (!evax_initialize (abfd
))
450 /* Set the format of a file being written. */
457 evax_debug (1, "evax_mkobject(%p)\n", abfd
);
460 if (!evax_initialize (abfd
))
464 const bfd_arch_info_type
*arch
= bfd_scan_arch ("alpha");
467 bfd_set_error(bfd_error_wrong_format
);
470 abfd
->arch_info
= arch
;
477 /* Write cached information into a file being written, at bfd_close. */
480 evax_write_object_contents (abfd
)
484 evax_debug (1, "evax_write_object_contents(%p)\n", abfd
);
487 if (abfd
->section_count
> 0) /* we have sections */
489 if (_bfd_evax_write_emh (abfd
) != 0)
491 if (_bfd_evax_write_egsd (abfd
) != 0)
493 if (_bfd_evax_write_etir (abfd
) != 0)
495 if (_bfd_evax_write_etbt (abfd
) != 0)
497 if (_bfd_evax_write_eeom (abfd
) != 0)
503 /*-- 4.1, generic -----------------------------------------------------------*/
505 /* Called when the BFD is being closed to do any necessary cleanup. */
508 evax_close_and_cleanup (abfd
)
512 evax_section
*es
, *es1
;
516 evax_debug (1, "evax_close_and_cleanup(%p)\n", abfd
);
521 if (PRIV(evax_buf
) != NULL
)
523 free (PRIV(evax_buf
));
524 PRIV(evax_buf
) = NULL
;
528 if (PRIV(output_buf
) != 0)
530 free (PRIV(output_buf
));
531 PRIV(output_buf
) = 0;
534 sec
= abfd
->sections
;
538 free (sec
->contents
);
542 if (PRIV(sections
) != NULL
)
544 free (PRIV(sections
));
545 PRIV(sections
) = NULL
;
548 if (PRIV(evax_symbol_table
))
550 bfd_hash_table_free (PRIV(evax_symbol_table
));
551 PRIV(evax_symbol_table
) = 0;
560 if (PRIV(location_stack
))
562 free (PRIV(location_stack
));
563 PRIV(location_stack
) = 0;
566 for (i
= 0; i
< EVAX_SECTION_COUNT
; i
++)
568 es
= PRIV(evax_section_table
)[i
];
575 PRIV(evax_section_table
)[i
] = NULL
;
578 free (abfd
->tdata
.any
);
579 abfd
->tdata
.any
= NULL
;
585 /* Ask the BFD to free all cached information. */
587 evax_bfd_free_cached_info (abfd
)
591 evax_debug (1, "evax_bfd_free_cached_info(%p)\n", abfd
);
597 /* Called when a new section is created. */
600 evax_new_section_hook (abfd
, section
)
605 evax_debug (1, "evax_new_section_hook(%p, %s)\n", abfd
, section
->name
);
607 bfd_set_section_alignment(abfd
, section
, 4);
612 /* Read the contents of a section.
613 buf points to a buffer of buf_size bytes to be filled with
614 section data (starting at offset into section) */
617 evax_get_section_contents (abfd
, section
, buf
, offset
, buf_size
)
622 bfd_size_type buf_size
;
625 evax_debug (1, "evax_get_section_contents(%p, %s, %p, off %ld, size %d)\n",
626 abfd
, section
->name
, buf
, offset
, (int)buf_size
);
629 /* shouldn't be called, since all sections are IN_MEMORY */
634 /* Read the contents of a section.
635 buf points to a buffer of buf_size bytes to be filled with
636 section data (starting at offset into section) */
639 evax_get_section_contents_in_window (abfd
, section
, w
, offset
, count
)
647 evax_debug (1, "evax_get_section_contents_in_window(%p, %s, %p, off %ld, count %d)\n",
648 abfd
, section
->name
, w
, offset
, (int)count
);
651 /* shouldn't be called, since all sections are IN_MEMORY */
656 /*-- Part 4.2, copy private data --------------------------------------------*/
658 /* Called to copy BFD general private data from one object file
662 evax_bfd_copy_private_bfd_data (src
, dest
)
667 evax_debug (1, "evax_bfd_copy_private_bfd_data(%p, %p)\n", src
, dest
);
673 /* Merge private BFD information from the BFD @var{ibfd} to the
674 the output file BFD @var{obfd} when linking. Return <<true>>
675 on success, <<false>> on error. Possible error returns are:
677 o <<bfd_error_no_memory>> -
678 Not enough memory exists to create private data for @var{obfd}. */
681 evax_bfd_merge_private_bfd_data (ibfd
, obfd
)
686 evax_debug (1,"evax_bfd_merge_private_bfd_data(%p, %p)\n", ibfd
, obfd
);
692 /* Set private BFD flag information in the BFD @var{abfd}.
693 Return <<true>> on success, <<false>> on error. Possible error
696 o <<bfd_error_no_memory>> -
697 Not enough memory exists to create private data for @var{obfd}. */
700 evax_bfd_set_private_flags (abfd
, flags
)
705 evax_debug (1,"evax_bfd_set_private_flags(%p, %lx)\n", abfd
, (long)flags
);
711 /* Called to copy BFD private section data from one object file
715 evax_bfd_copy_private_section_data (srcbfd
, srcsec
, dstbfd
, dstsec
)
722 evax_debug (1, "evax_bfd_copy_private_section_data(%p, %s, %p, %s)\n",
723 srcbfd
, srcsec
->name
, dstbfd
, dstsec
->name
);
728 /* Called to copy BFD private symbol data from one object file
732 evax_bfd_copy_private_symbol_data (ibfd
, isym
, obfd
, osym
)
739 evax_debug (1, "evax_bfd_copy_private_symbol_data(%p, %s, %p, %s)\n",
740 ibfd
, isym
->name
, obfd
, osym
->name
);
745 /*-- Part 4.3, core file ----------------------------------------------------*/
747 /* Return a read-only string explaining which program was running
748 when it failed and produced the core file abfd. */
751 evax_core_file_failing_command (abfd
)
755 evax_debug (1, "evax_core_file_failing_command(%p)\n", abfd
);
761 /* Returns the signal number which caused the core dump which
762 generated the file the BFD abfd is attached to. */
765 evax_core_file_failing_signal (abfd
)
769 evax_debug (1, "evax_core_file_failing_signal(%p)\n", abfd
);
775 /* Return true if the core file attached to core_bfd was generated
776 by a run of the executable file attached to exec_bfd, false otherwise. */
779 evax_core_file_matches_executable_p (abfd
, bbfd
)
784 evax_debug (1, "evax_core_file_matches_executable_p(%p, %p)\n", abfd
, bbfd
);
789 /*-- Part 4.4, archive ------------------------------------------------------*/
791 /* ??? do something with an archive map.
792 Return false on error, true otherwise. */
795 evax_slurp_armap (abfd
)
799 evax_debug (1, "evax_slurp_armap(%p)\n", abfd
);
805 /* ??? do something with an extended name table.
806 Return false on error, true otherwise. */
809 evax_slurp_extended_name_table (abfd
)
813 evax_debug (1, "evax_slurp_extended_name_table(%p)\n", abfd
);
819 /* ??? do something with an extended name table.
820 Return false on error, true otherwise. */
823 evax_construct_extended_name_table (abfd
, tabloc
, tablen
, name
)
826 bfd_size_type
*tablen
;
830 evax_debug (1, "evax_construct_extended_name_table(%p)\n", abfd
);
836 /* Truncate the name of an archive to match system-dependent restrictions */
839 evax_truncate_arname (abfd
, pathname
, arhdr
)
841 CONST
char *pathname
;
845 evax_debug (1, "evax_truncate_arname(%p, %s, %s)\n", abfd
, pathname
, arhdr
);
851 /* ??? write archive map */
854 evax_write_armap (arch
, elength
, map
, orl_count
, stridx
)
856 unsigned int elength
;
858 unsigned int orl_count
;
862 evax_debug (1, "evax_write_armap(%p, %d, %p, %d %d)\n",
863 arch
, elength
, map
, orl_count
, stridx
);
868 /* Read archive header ??? */
871 evax_read_ar_hdr (abfd
)
875 evax_debug (1, "evax_read_ar_hdr(%p)\n", abfd
);
881 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
882 an input BFD on the first contained element and returns that.
883 Subsequent calls should pass the archive and the previous return value
884 to return a created BFD to the next contained element.
885 NULL is returned when there are no more. */
888 evax_openr_next_archived_file (arch
, prev
)
893 evax_debug (1, "evax_openr_next_archived_file(%p, %p)\n", arch
, prev
);
899 /* Return the BFD which is referenced by the symbol in ABFD indexed by
900 INDEX. INDEX should have been returned by bfd_get_next_mapent. */
903 evax_get_elt_at_index (abfd
, index
)
908 evax_debug (1, "evax_get_elt_at_index(%p, %p)\n", abfd
, index
);
910 return _bfd_generic_get_elt_at_index(abfd
, index
);
915 -> bfd_generic_stat_arch_elt */
918 evax_generic_stat_arch_elt (abfd
, stat
)
923 evax_debug (1, "evax_generic_stat_arch_elt(%p, %p)\n", abfd
, stat
);
925 return bfd_generic_stat_arch_elt(abfd
, stat
);
929 /* This is a new function in bfd 2.5 */
932 evax_update_armap_timestamp (abfd
)
936 evax_debug (1, "evax_update_armap_timestamp(%p)\n", abfd
);
941 /*-- Part 4.5, symbols --------------------------------------------------------*/
943 /* Return the number of bytes required to store a vector of pointers
944 to asymbols for all the symbols in the BFD abfd, including a
945 terminal NULL pointer. If there are no symbols in the BFD,
946 then return 0. If an error occurs, return -1. */
949 evax_get_symtab_upper_bound (abfd
)
953 evax_debug (1, "evax_get_symtab_upper_bound(%p), %d symbols\n", abfd
, PRIV(egsd_sym_count
));
955 return (PRIV(egsd_sym_count
)+1) * sizeof(asymbol
*);
959 /* Copy symbols from hash table to symbol vector
961 called from bfd_hash_traverse in evax_get_symtab
962 init counter to 0 if entry == 0 */
965 copy_symbols (entry
, arg
)
966 struct bfd_hash_entry
*entry
;
969 bfd
*abfd
= (bfd
*) arg
;
971 if (entry
== NULL
) /* init counter */
973 else /* fill vector, inc counter */
974 PRIV(symcache
)[PRIV(symnum
)++] = ((evax_symbol_entry
*)entry
)->symbol
;
980 /* Read the symbols from the BFD abfd, and fills in the vector
981 location with pointers to the symbols and a trailing NULL.
983 return # of symbols read */
986 evax_get_symtab (abfd
, symbols
)
991 evax_debug (1, "evax_get_symtab(%p, <ret>)\n", abfd
);
995 (void)copy_symbols((struct bfd_hash_entry
*)0, abfd
);
997 /* traverse table and fill symbols vector */
999 PRIV(symcache
) = symbols
;
1000 bfd_hash_traverse(PRIV(evax_symbol_table
), copy_symbols
, (PTR
)abfd
);
1002 symbols
[PRIV(egsd_sym_count
)] = NULL
;
1004 return PRIV(egsd_sym_count
);
1008 /* Create a new asymbol structure for the BFD abfd and return a pointer
1010 This routine is necessary because each back end has private information
1011 surrounding the asymbol. Building your own asymbol and pointing to it
1012 will not create the private information, and will cause problems later on. */
1015 _bfd_evax_make_empty_symbol (abfd
)
1018 asymbol
*symbol
= (asymbol
*)bfd_zalloc(abfd
, sizeof(asymbol
));
1021 evax_debug (1, "_bfd_evax_make_empty_symbol(%p)\n", abfd
);
1026 bfd_set_error (bfd_error_no_memory
);
1029 symbol
->the_bfd
= abfd
;
1035 /* Print symbol to file according to how. how is one of
1036 bfd_print_symbol_name just print the name
1037 bfd_print_symbol_more print more (???)
1038 bfd_print_symbol_all print all we know, which is not much right now :-) */
1041 evax_print_symbol (abfd
, file
, symbol
, how
)
1045 bfd_print_symbol_type how
;
1048 evax_debug (1, "evax_print_symbol(%p, %p, %p, %d)\n", abfd
, file
, symbol
, how
);
1053 case bfd_print_symbol_name
:
1054 case bfd_print_symbol_more
:
1055 fprintf((FILE *)file
," %s", symbol
->name
);
1060 case bfd_print_symbol_all
:
1062 CONST
char *section_name
= symbol
->section
->name
;
1064 bfd_print_symbol_vandf((PTR
)file
,symbol
);
1066 fprintf((FILE *)file
," %-8s %s", section_name
, symbol
->name
);
1074 /* Return information about symbol in ret.
1076 fill type, value and name
1079 B bss segment symbol
1081 D data segment symbol
1083 t a static function symbol
1084 T text segment symbol
1089 evax_get_symbol_info (abfd
, symbol
, ret
)
1097 evax_debug (1, "evax_get_symbol_info(%p, %p, <ret>)\n", abfd
, symbol
);
1100 sec
= symbol
->section
;
1102 if (bfd_is_com_section (sec
))
1104 else if (bfd_is_abs_section (sec
))
1106 else if (bfd_is_und_section (sec
))
1108 else if (bfd_is_ind_section (sec
))
1110 else if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1112 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1114 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1119 if (ret
->type
!= 'U')
1120 ret
->value
= symbol
->value
+ symbol
->section
->vma
;
1123 ret
->name
= symbol
->name
;
1129 /* Return true if the given symbol sym in the BFD abfd is
1130 a compiler generated local label, else return false. */
1133 evax_bfd_is_local_label_name (abfd
, name
)
1138 evax_debug (1, "evax_bfd_is_local_label_name(%p, %s)\n", abfd
, name
);
1140 return name
[0] == '$';
1144 /* Get source line number for symbol */
1147 evax_get_lineno (abfd
, symbol
)
1152 evax_debug (1, "evax_get_lineno(%p, %p)\n", abfd
, symbol
);
1158 /* Provided a BFD, a section and an offset into the section, calculate and
1159 return the name of the source file and the line nearest to the wanted
1163 evax_find_nearest_line (abfd
, section
, symbols
, offset
, file
, func
, line
)
1173 evax_debug (1, "evax_find_nearest_line(%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
1174 abfd
, section
->name
, symbols
, (long int)offset
);
1180 /* Back-door to allow format-aware applications to create debug symbols
1181 while using BFD for everything else. Currently used by the assembler
1182 when creating COFF files. */
1185 evax_bfd_make_debug_symbol (abfd
, ptr
, size
)
1191 evax_debug (1, "evax_bfd_make_debug_symbol(%p, %p, %ld)\n", abfd
, ptr
, size
);
1197 /* Read minisymbols. For minisymbols, we use the unmodified a.out
1198 symbols. The minisymbol_to_symbol function translates these into
1199 BFD asymbol structures. */
1202 evax_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
)
1206 unsigned int *sizep
;
1209 evax_debug (1, "evax_read_minisymbols(%p, %d, %p, %d)\n", abfd
, dynamic
, minisymsp
, *sizep
);
1211 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
1214 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
1215 unmodified a.out symbol. The SYM argument is a structure returned
1216 by bfd_make_empty_symbol, which we fill in here. */
1219 evax_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
)
1226 evax_debug (1, "evax_minisymbol_to_symbol(%p, %d, %p, %p)\n", abfd
, dynamic
, minisym
, sym
);
1228 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
1231 /*-- Part 4.6, relocations --------------------------------------------------*/
1233 /* Return the number of bytes required to store the relocation information
1234 associated with section sect attached to bfd abfd.
1235 If an error occurs, return -1. */
1238 evax_get_reloc_upper_bound (abfd
, section
)
1243 evax_debug (1, "evax_get_reloc_upper_bound(%p, %s)\n", abfd
, section
->name
);
1249 /* Call the back end associated with the open BFD abfd and translate the
1250 external form of the relocation information attached to sec into the
1251 internal canonical form. Place the table into memory at loc, which has
1252 been preallocated, usually by a call to bfd_get_reloc_upper_bound.
1253 Returns the number of relocs, or -1 on error. */
1256 evax_canonicalize_reloc (abfd
, section
, location
, symbols
)
1263 evax_debug (1, "evax_canonicalize_reloc(%p, %s, <ret>, <ret>)\n", abfd
, section
->name
);
1268 /*---------------------------------------------------------------------------*/
1269 /* this is just copied from ecoff-alpha, needs to be fixed probably */
1271 /* How to process the various reloc types. */
1273 static bfd_reloc_status_type
1274 reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
1281 char **error_message
;
1284 evax_debug (1, "reloc_nil(abfd %p, output_bfd %p)\n", abfd
, output_bfd
);
1285 evax_debug (2, "In section %s, symbol %s\n",
1286 sec
->name
, sym
->name
);
1287 evax_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1288 reloc
->sym_ptr_ptr
[0]->name
,
1289 (unsigned long)reloc
->address
,
1290 (unsigned long)reloc
->addend
, reloc
->howto
->name
);
1291 evax_debug (2, "data at %p\n", data
);
1292 /* _bfd_hexdump (2, data, bfd_get_reloc_size(reloc->howto),0); */
1295 return bfd_reloc_ok
;
1298 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1299 from smaller values. Start with zero, widen, *then* decrement. */
1300 #define MINUS_ONE (((bfd_vma)0) - 1)
1302 static reloc_howto_type alpha_howto_table
[] =
1304 HOWTO (ALPHA_R_IGNORE
, /* type */
1306 0, /* size (0 = byte, 1 = short, 2 = long) */
1308 true, /* pc_relative */
1310 complain_overflow_dont
, /* complain_on_overflow */
1311 reloc_nil
, /* special_function */
1312 "IGNORE", /* name */
1313 true, /* partial_inplace */
1316 true), /* pcrel_offset */
1318 /* A 64 bit reference to a symbol. */
1319 HOWTO (ALPHA_R_REFQUAD
, /* type */
1321 4, /* size (0 = byte, 1 = short, 2 = long) */
1323 false, /* pc_relative */
1325 complain_overflow_bitfield
, /* complain_on_overflow */
1326 reloc_nil
, /* special_function */
1327 "REFQUAD", /* name */
1328 true, /* partial_inplace */
1329 MINUS_ONE
, /* src_mask */
1330 MINUS_ONE
, /* dst_mask */
1331 false), /* pcrel_offset */
1333 /* A 21 bit branch. The native assembler generates these for
1334 branches within the text segment, and also fills in the PC
1335 relative offset in the instruction. */
1336 HOWTO (ALPHA_R_BRADDR
, /* type */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1340 true, /* pc_relative */
1342 complain_overflow_signed
, /* complain_on_overflow */
1343 reloc_nil
, /* special_function */
1344 "BRADDR", /* name */
1345 true, /* partial_inplace */
1346 0x1fffff, /* src_mask */
1347 0x1fffff, /* dst_mask */
1348 false), /* pcrel_offset */
1350 /* A hint for a jump to a register. */
1351 HOWTO (ALPHA_R_HINT
, /* type */
1353 1, /* size (0 = byte, 1 = short, 2 = long) */
1355 true, /* pc_relative */
1357 complain_overflow_dont
, /* complain_on_overflow */
1358 reloc_nil
, /* special_function */
1360 true, /* partial_inplace */
1361 0x3fff, /* src_mask */
1362 0x3fff, /* dst_mask */
1363 false), /* pcrel_offset */
1365 /* 16 bit PC relative offset. */
1366 HOWTO (ALPHA_R_SREL16
, /* type */
1368 1, /* size (0 = byte, 1 = short, 2 = long) */
1370 true, /* pc_relative */
1372 complain_overflow_signed
, /* complain_on_overflow */
1373 reloc_nil
, /* special_function */
1374 "SREL16", /* name */
1375 true, /* partial_inplace */
1376 0xffff, /* src_mask */
1377 0xffff, /* dst_mask */
1378 false), /* pcrel_offset */
1380 /* 32 bit PC relative offset. */
1381 HOWTO (ALPHA_R_SREL32
, /* type */
1383 2, /* size (0 = byte, 1 = short, 2 = long) */
1385 true, /* pc_relative */
1387 complain_overflow_signed
, /* complain_on_overflow */
1388 reloc_nil
, /* special_function */
1389 "SREL32", /* name */
1390 true, /* partial_inplace */
1391 0xffffffff, /* src_mask */
1392 0xffffffff, /* dst_mask */
1393 false), /* pcrel_offset */
1395 /* A 64 bit PC relative offset. */
1396 HOWTO (ALPHA_R_SREL64
, /* type */
1398 4, /* size (0 = byte, 1 = short, 2 = long) */
1400 true, /* pc_relative */
1402 complain_overflow_signed
, /* complain_on_overflow */
1403 reloc_nil
, /* special_function */
1404 "SREL64", /* name */
1405 true, /* partial_inplace */
1406 MINUS_ONE
, /* src_mask */
1407 MINUS_ONE
, /* dst_mask */
1408 false), /* pcrel_offset */
1410 /* Push a value on the reloc evaluation stack. */
1411 HOWTO (ALPHA_R_OP_PUSH
, /* type */
1413 0, /* size (0 = byte, 1 = short, 2 = long) */
1415 false, /* pc_relative */
1417 complain_overflow_dont
, /* complain_on_overflow */
1418 reloc_nil
, /* special_function */
1419 "OP_PUSH", /* name */
1420 false, /* partial_inplace */
1423 false), /* pcrel_offset */
1425 /* Store the value from the stack at the given address. Store it in
1426 a bitfield of size r_size starting at bit position r_offset. */
1427 HOWTO (ALPHA_R_OP_STORE
, /* type */
1429 4, /* size (0 = byte, 1 = short, 2 = long) */
1431 false, /* pc_relative */
1433 complain_overflow_dont
, /* complain_on_overflow */
1434 reloc_nil
, /* special_function */
1435 "OP_STORE", /* name */
1436 false, /* partial_inplace */
1438 MINUS_ONE
, /* dst_mask */
1439 false), /* pcrel_offset */
1441 /* Subtract the reloc address from the value on the top of the
1442 relocation stack. */
1443 HOWTO (ALPHA_R_OP_PSUB
, /* type */
1445 0, /* size (0 = byte, 1 = short, 2 = long) */
1447 false, /* pc_relative */
1449 complain_overflow_dont
, /* complain_on_overflow */
1450 reloc_nil
, /* special_function */
1451 "OP_PSUB", /* name */
1452 false, /* partial_inplace */
1455 false), /* pcrel_offset */
1457 /* Shift the value on the top of the relocation stack right by the
1459 HOWTO (ALPHA_R_OP_PRSHIFT
, /* type */
1461 0, /* size (0 = byte, 1 = short, 2 = long) */
1463 false, /* pc_relative */
1465 complain_overflow_dont
, /* complain_on_overflow */
1466 reloc_nil
, /* special_function */
1467 "OP_PRSHIFT", /* name */
1468 false, /* partial_inplace */
1471 false), /* pcrel_offset */
1473 /* Hack. Linkage is done by linker. */
1474 HOWTO (ALPHA_R_LINKAGE
, /* type */
1476 8, /* size (0 = byte, 1 = short, 2 = long) */
1478 false, /* pc_relative */
1480 complain_overflow_dont
, /* complain_on_overflow */
1481 reloc_nil
, /* special_function */
1482 "LINKAGE", /* name */
1483 false, /* partial_inplace */
1486 false), /* pcrel_offset */
1488 /* A 32 bit reference to a symbol. */
1489 HOWTO (ALPHA_R_REFLONG
, /* type */
1491 2, /* size (0 = byte, 1 = short, 2 = long) */
1493 false, /* pc_relative */
1495 complain_overflow_bitfield
, /* complain_on_overflow */
1496 reloc_nil
, /* special_function */
1497 "REFLONG", /* name */
1498 true, /* partial_inplace */
1499 0xffffffff, /* src_mask */
1500 0xffffffff, /* dst_mask */
1501 false), /* pcrel_offset */
1503 /* A 64 bit reference to a procedure, written as 32 bit value. */
1504 HOWTO (ALPHA_R_CODEADDR
, /* type */
1506 4, /* size (0 = byte, 1 = short, 2 = long) */
1508 false, /* pc_relative */
1510 complain_overflow_signed
,/* complain_on_overflow */
1511 reloc_nil
, /* special_function */
1512 "CODEADDR", /* name */
1513 false, /* partial_inplace */
1514 0xffffffff, /* src_mask */
1515 0xffffffff, /* dst_mask */
1516 false), /* pcrel_offset */
1520 /* Return a pointer to a howto structure which, when invoked, will perform
1521 the relocation code on data from the architecture noted. */
1523 static const struct reloc_howto_struct
*
1524 evax_bfd_reloc_type_lookup (abfd
, code
)
1526 bfd_reloc_code_real_type code
;
1531 evax_debug (1, "evax_bfd_reloc_type_lookup(%p, %d)\t", abfd
, code
);
1536 case BFD_RELOC_16
: alpha_type
= ALPHA_R_SREL16
; break;
1537 case BFD_RELOC_32
: alpha_type
= ALPHA_R_REFLONG
; break;
1538 case BFD_RELOC_64
: alpha_type
= ALPHA_R_REFQUAD
; break;
1539 case BFD_RELOC_CTOR
: alpha_type
= ALPHA_R_REFQUAD
; break;
1540 case BFD_RELOC_23_PCREL_S2
: alpha_type
= ALPHA_R_BRADDR
; break;
1541 case BFD_RELOC_ALPHA_HINT
: alpha_type
= ALPHA_R_HINT
; break;
1542 case BFD_RELOC_16_PCREL
: alpha_type
= ALPHA_R_SREL16
; break;
1543 case BFD_RELOC_32_PCREL
: alpha_type
= ALPHA_R_SREL32
; break;
1544 case BFD_RELOC_64_PCREL
: alpha_type
= ALPHA_R_SREL64
; break;
1545 case BFD_RELOC_ALPHA_LINKAGE
: alpha_type
= ALPHA_R_LINKAGE
; break;
1546 case BFD_RELOC_ALPHA_CODEADDR
: alpha_type
= ALPHA_R_CODEADDR
; break;
1548 (*_bfd_error_handler
) ("reloc (%d) is *UNKNOWN*", code
);
1549 return (const struct reloc_howto_struct
*) NULL
;
1552 evax_debug (2, "reloc is %s\n", alpha_howto_table
[alpha_type
].name
);
1554 return &alpha_howto_table
[alpha_type
];
1558 /*-- Part 4.7, writing an object file ---------------------------------------*/
1560 /* Set the architecture and machine type in BFD abfd to arch and mach.
1561 Find the correct pointer to a structure and insert it into the arch_info
1565 evax_set_arch_mach (abfd
, arch
, mach
)
1567 enum bfd_architecture arch
;
1571 evax_debug (1, "evax_set_arch_mach(%p, %d, %ld)\n", abfd
, arch
, mach
);
1573 if (arch
!= bfd_arch_alpha
1574 && arch
!= bfd_arch_unknown
)
1577 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
1581 /* Sets the contents of the section section in BFD abfd to the data starting
1582 in memory at data. The data is written to the output section starting at
1583 offset offset for count bytes.
1585 Normally true is returned, else false. Possible error returns are:
1586 o bfd_error_no_contents - The output section does not have the
1587 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1588 o and some more too */
1591 evax_set_section_contents (abfd
, section
, location
, offset
, count
)
1596 bfd_size_type count
;
1599 evax_debug (1, "evax_set_section_contents(%p, sec %s, loc %p, off %ld, count %d)\n",
1600 abfd
, section
->name
, location
, (long int)offset
, (int)count
);
1601 evax_debug (2, "secraw %d, seccooked %d\n", (int)section
->_raw_size
, (int)section
->_cooked_size
);
1603 return _bfd_save_evax_section(abfd
, section
, location
, offset
, count
);
1607 /*-- Part 4.8, linker -------------------------------------------------------*/
1609 /* Get the size of the section headers. */
1612 evax_sizeof_headers (abfd
, reloc
)
1617 evax_debug (1, "evax_sizeof_headers(%p, %s)\n", abfd
, (reloc
)?"True":"False");
1623 /* Provides default handling of relocation effort for back ends
1624 which can't be bothered to do it efficiently. */
1627 evax_bfd_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
1628 relocateable
, symbols
)
1630 struct bfd_link_info
*link_info
;
1631 struct bfd_link_order
*link_order
;
1633 boolean relocateable
;
1637 evax_debug (1, "evax_bfd_get_relocated_section_contents(%p, %p, %p, %p, %s, %p)\n",
1638 abfd
, link_info
, link_order
, data
, (relocateable
)?"True":"False", symbols
);
1647 evax_bfd_relax_section (abfd
, section
, link_info
, again
)
1650 struct bfd_link_info
*link_info
;
1654 evax_debug (1, "evax_bfd_relax_section(%p, %s, %p, <ret>)\n",
1655 abfd
, section
->name
, link_info
);
1661 /* Create a hash table for the linker. Different backends store
1662 different information in this table. */
1664 static struct bfd_link_hash_table
*
1665 evax_bfd_link_hash_table_create (abfd
)
1669 evax_debug (1, "evax_bfd_link_hash_table_create(%p)\n", abfd
);
1675 /* Add symbols from this object file into the hash table. */
1678 evax_bfd_link_add_symbols (abfd
, link_info
)
1680 struct bfd_link_info
*link_info
;
1683 evax_debug (1, "evax_bfd_link_add_symbols(%p, %p)\n", abfd
, link_info
);
1689 /* Do a link based on the link_order structures attached to each
1690 section of the BFD. */
1693 evax_bfd_final_link (abfd
, link_info
)
1695 struct bfd_link_info
*link_info
;
1698 evax_debug (1, "evax_bfd_final_link(%p, %p)\n", abfd
, link_info
);
1703 /* Should this section be split up into smaller pieces during linking. */
1706 evax_bfd_link_split_section (abfd
, section
)
1711 evax_debug (1, "evax_bfd_link_split_section(%p, %s)\n", abfd
, section
->name
);
1716 /*-- Part 4.9, dynamic symbols and relocations ------------------------------*/
1718 /* Get the amount of memory required to hold the dynamic symbols. */
1721 evax_get_dynamic_symtab_upper_bound (abfd
)
1725 evax_debug (1, "evax_get_dynamic_symtab_upper_bound(%p)\n", abfd
);
1731 evax_bfd_print_private_bfd_data (abfd
, file
)
1736 evax_debug (1, "evax_bfd_print_private_bfd_data(%p)\n", abfd
);
1742 /* Read in the dynamic symbols. */
1745 evax_canonicalize_dynamic_symtab (abfd
, symbols
)
1750 evax_debug (1, "evax_canonicalize_dynamic_symtab(%p, <ret>)\n", abfd
);
1756 /* Get the amount of memory required to hold the dynamic relocs. */
1759 evax_get_dynamic_reloc_upper_bound (abfd
)
1763 evax_debug (1, "evax_get_dynamic_reloc_upper_bound(%p)\n", abfd
);
1769 /* Read in the dynamic relocs. */
1772 evax_canonicalize_dynamic_reloc (abfd
, arel
, symbols
)
1778 evax_debug (1, "evax_canonicalize_dynamic_reloc(%p)\n", abfd
);