1 /* evax-alpha.c -- BFD back-end for ALPHA EVAX (openVMS/AXP) files.
2 Copyright 1996 Free Software Foundation, Inc.
3 Written by Klaus Kämpf (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. */
30 static boolean evax_initialize
PARAMS ((bfd
*));
31 static boolean fill_section_ptr
PARAMS ((struct bfd_hash_entry
*, PTR
));
32 static boolean evax_fixup_sections
PARAMS ((bfd
*));
33 static boolean copy_symbols
PARAMS ((struct bfd_hash_entry
*, PTR
));
34 static bfd_reloc_status_type reloc_nil
35 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
36 static const struct bfd_target
*evax_object_p
PARAMS ((bfd
*abfd
));
37 static const struct bfd_target
*evax_archive_p
PARAMS ((bfd
*abfd
));
38 static boolean evax_mkobject
PARAMS ((bfd
*abfd
));
39 static boolean evax_write_object_contents
PARAMS ((bfd
*abfd
));
40 static boolean evax_close_and_cleanup
PARAMS ((bfd
*abfd
));
41 static boolean evax_bfd_free_cached_info
PARAMS ((bfd
*abfd
));
42 static boolean evax_new_section_hook
PARAMS ((bfd
*abfd
, asection
*section
));
43 static boolean evax_get_section_contents
44 PARAMS ((bfd
*abfd
, asection
*section
, PTR x1
, file_ptr x2
,
46 static boolean evax_get_section_contents_in_window
47 PARAMS ((bfd
*abfd
, asection
*section
, bfd_window
*w
, file_ptr offset
,
48 bfd_size_type count
));
49 static boolean evax_bfd_copy_private_bfd_data
PARAMS ((bfd
*src
, bfd
*dest
));
50 static boolean evax_bfd_copy_private_section_data
51 PARAMS ((bfd
*srcbfd
, asection
*srcsec
, bfd
*dstbfd
, asection
*dstsec
));
52 static boolean evax_bfd_copy_private_symbol_data
53 PARAMS ((bfd
*ibfd
, asymbol
*isym
, bfd
*obfd
, asymbol
*osym
));
54 static boolean evax_bfd_print_private_bfd_data
55 PARAMS ((bfd
*abfd
, void *file
));
56 static char *evax_core_file_failing_command
PARAMS ((bfd
*abfd
));
57 static int evax_core_file_failing_signal
PARAMS ((bfd
*abfd
));
58 static boolean evax_core_file_matches_executable_p
59 PARAMS ((bfd
*abfd
, bfd
*bbfd
));
60 static boolean evax_slurp_armap
PARAMS ((bfd
*abfd
));
61 static boolean evax_slurp_extended_name_table
PARAMS ((bfd
*abfd
));
62 static boolean evax_construct_extended_name_table
63 PARAMS ((bfd
*abfd
, char **tabloc
, bfd_size_type
*tablen
,
65 static void evax_truncate_arname
66 PARAMS ((bfd
*abfd
, CONST
char *pathname
, char *arhdr
));
67 static boolean evax_write_armap
68 PARAMS ((bfd
*arch
, unsigned int elength
, struct orl
*map
,
69 unsigned int orl_count
, int stridx
));
70 static PTR evax_read_ar_hdr
PARAMS ((bfd
*abfd
));
71 static bfd
*evax_get_elt_at_index
PARAMS ((bfd
*abfd
, symindex index
));
72 static bfd
*evax_openr_next_archived_file
PARAMS ((bfd
*arch
, bfd
*prev
));
73 static boolean evax_update_armap_timestamp
PARAMS ((bfd
*abfd
));
74 static int evax_generic_stat_arch_elt
PARAMS ((bfd
*abfd
, struct stat
*stat
));
75 static long evax_get_symtab_upper_bound
PARAMS ((bfd
*abfd
));
76 static long evax_get_symtab
PARAMS ((bfd
*abfd
, asymbol
**symbols
));
77 static void evax_print_symbol
78 PARAMS ((bfd
*abfd
, PTR file
, asymbol
*symbol
, bfd_print_symbol_type how
));
79 static void evax_get_symbol_info
80 PARAMS ((bfd
*abfd
, asymbol
*symbol
, symbol_info
*ret
));
81 static boolean evax_bfd_is_local_label
PARAMS ((bfd
*abfd
, asymbol
*symbol
));
82 static alent
*evax_get_lineno
PARAMS ((bfd
*abfd
, asymbol
*symbol
));
83 static boolean evax_find_nearest_line
84 PARAMS ((bfd
*abfd
, asection
*section
, asymbol
**symbols
, bfd_vma offset
,
85 const char **file
, const char **func
, unsigned int *line
));
86 static asymbol
*evax_bfd_make_debug_symbol
87 PARAMS ((bfd
*abfd
, void *ptr
, unsigned long size
));
88 static long evax_read_minisymbols
89 PARAMS ((bfd
*abfd
, boolean dynamic
, PTR
*minisymsp
, unsigned int *sizep
));
90 static asymbol
*evax_minisymbol_to_symbol
91 PARAMS ((bfd
*abfd
, boolean dynamic
, const PTR minisym
, asymbol
*sym
));
92 static long evax_get_reloc_upper_bound
PARAMS ((bfd
*abfd
, asection
*sect
));
93 static long evax_canonicalize_reloc
94 PARAMS ((bfd
*abfd
, asection
*srcsec
, arelent
**location
,
96 static const struct reloc_howto_struct
*evax_bfd_reloc_type_lookup
97 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
98 static boolean evax_set_arch_mach
99 PARAMS ((bfd
*abfd
, enum bfd_architecture arch
, unsigned long mach
));
100 static boolean evax_set_section_contents
101 PARAMS ((bfd
*abfd
, asection
*section
, PTR location
, file_ptr offset
,
102 bfd_size_type count
));
103 static int evax_sizeof_headers
PARAMS ((bfd
*abfd
, boolean reloc
));
104 static bfd_byte
*evax_bfd_get_relocated_section_contents
105 PARAMS ((bfd
*abfd
, struct bfd_link_info
*link_info
,
106 struct bfd_link_order
*link_order
, bfd_byte
*data
,
107 boolean relocateable
, asymbol
**symbols
));
108 static boolean evax_bfd_relax_section
109 PARAMS ((bfd
*abfd
, asection
*section
, struct bfd_link_info
*link_info
,
111 static struct bfd_link_hash_table
*evax_bfd_link_hash_table_create
112 PARAMS ((bfd
*abfd
));
113 static boolean evax_bfd_link_add_symbols
114 PARAMS ((bfd
*abfd
, struct bfd_link_info
*link_info
));
115 static boolean evax_bfd_final_link
116 PARAMS ((bfd
*abfd
, struct bfd_link_info
*link_info
));
117 static boolean evax_bfd_link_split_section
118 PARAMS ((bfd
*abfd
, asection
*section
));
119 static long evax_get_dynamic_symtab_upper_bound
PARAMS ((bfd
*abfd
));
120 static long evax_canonicalize_dynamic_symtab
121 PARAMS ((bfd
*abfd
, asymbol
**symbols
));
122 static long evax_get_dynamic_reloc_upper_bound
PARAMS ((bfd
*abfd
));
123 static long evax_canonicalize_dynamic_reloc
124 PARAMS ((bfd
*abfd
, arelent
**arel
, asymbol
**symbols
));
125 static boolean evax_bfd_merge_private_bfd_data
PARAMS ((bfd
*ibfd
, bfd
*obfd
));
126 static boolean evax_bfd_set_private_flags
PARAMS ((bfd
*abfd
, flagword flags
));
128 #define evax_make_empty_symbol _bfd_evax_make_empty_symbol
130 /*===========================================================================*/
132 const bfd_target evax_alpha_vec
=
135 "evax-alpha", /* name */
136 bfd_target_evax_flavour
,
137 false, /* data byte order is little */
138 false, /* header byte order is little */
140 (HAS_RELOC
| HAS_SYMS
141 | WP_TEXT
| D_PAGED
), /* object flags */
142 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
143 | SEC_READONLY
| SEC_CODE
| SEC_DATA
144 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* sect flags */
145 0, /* symbol_leading_char */
146 ' ', /* ar_pad_char */
147 15, /* ar_max_namelen */
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
,
151 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
152 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
153 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
155 {_bfd_dummy_target
, evax_object_p
, /* bfd_check_format */
156 evax_archive_p
, _bfd_dummy_target
},
157 {bfd_false
, evax_mkobject
, /* bfd_set_format */
158 _bfd_generic_mkarchive
, bfd_false
},
159 {bfd_false
, evax_write_object_contents
, /* bfd_write_contents */
160 _bfd_write_archive_contents
, bfd_false
},
162 BFD_JUMP_TABLE_GENERIC (evax
),
163 BFD_JUMP_TABLE_COPY (evax
),
164 BFD_JUMP_TABLE_CORE (evax
),
165 BFD_JUMP_TABLE_ARCHIVE (evax
),
166 BFD_JUMP_TABLE_SYMBOLS (evax
),
167 BFD_JUMP_TABLE_RELOCS (evax
),
168 BFD_JUMP_TABLE_WRITE (evax
),
169 BFD_JUMP_TABLE_LINK (evax
),
170 BFD_JUMP_TABLE_DYNAMIC (evax
),
176 /*===========================================================================*/
178 /* Initialize private data */
181 evax_initialize (abfd
)
186 if (abfd
->tdata
.any
!= 0)
189 bfd_set_start_address (abfd
, (bfd_vma
)-1);
191 abfd
->tdata
.any
= ((struct evax_private_data_struct
*)
192 bfd_malloc (sizeof (struct evax_private_data_struct
)));
193 if (abfd
->tdata
.any
== 0)
197 PRIV(rec_length
) = 0;
198 PRIV(file_format
) = FF_UNKNOWN
;
199 PRIV(filename
) = NULL
;
200 PRIV(fixup_done
) = false;
201 PRIV(sections
) = NULL
;
203 PRIV(stack
) = ((struct stack_struct
*)
204 bfd_malloc (sizeof (struct stack_struct
) * STACKSIZE
));
205 if (PRIV(stack
) == 0)
208 free (abfd
->tdata
.any
);
214 PRIV(evax_symbol_table
) = ((struct bfd_hash_table
*)
215 bfd_malloc (sizeof (struct bfd_hash_table
)));
216 if (PRIV(evax_symbol_table
) == 0)
221 goto evax_init_no_mem1
;
224 if (!bfd_hash_table_init (PRIV(evax_symbol_table
), _bfd_evax_hash_newfunc
))
227 PRIV(location_stack
) = ((struct location_struct
*)
228 bfd_malloc (sizeof (struct location_struct
)
229 * LOCATION_SAVE_SIZE
));
230 if (PRIV(location_stack
) == 0)
233 free (PRIV(evax_symbol_table
));
234 PRIV(evax_symbol_table
) = 0;
235 goto evax_init_no_mem2
;
238 for (i
= 0; i
< EVAX_SECTION_COUNT
; i
++)
239 PRIV(evax_section_table
)[i
] = NULL
;
241 PRIV(output_buf
) = (unsigned char *) malloc (MAX_OUTREC_SIZE
);
242 if (PRIV(output_buf
) == 0)
244 free (PRIV(location_stack
));
245 PRIV(location_stack
) = 0;
246 goto evax_init_no_mem3
;
248 PRIV(push_level
) = 0;
249 PRIV(pushed_size
) = 0;
250 PRIV(length_pos
) = 2;
251 PRIV(output_size
) = 0;
252 PRIV(output_alignment
) = 1;
258 /* Fill symbol->section with section ptr
259 symbol->section is filled with the section index for defined symbols
260 during reading the EGSD section. But we need the pointer to the
263 It has the correct value for referenced (undefined section) symbols
265 called from bfd_hash_traverse in evax_fixup_sections */
268 fill_section_ptr (entry
, sections
)
269 struct bfd_hash_entry
*entry
;
275 sym
= ((evax_symbol_entry
*)entry
)->symbol
;
278 if (!bfd_is_und_section (sec
))
280 sec
= ((evax_symbol_entry
*)entry
)->symbol
->section
=
281 ((asection
**)sections
)[(int)sec
];
284 if (strcmp (sym
->name
, sec
->name
) == 0)
285 sym
->flags
|= BSF_SECTION_SYM
;
292 set up all pointers and arrays, counters and sizes are fixed now
294 we build a private sections vector for easy access since sections
295 are always referenced by an index number.
297 alloc PRIV(sections) according to abfd->section_count
298 copy abfd->sections to PRIV(sections) */
301 evax_fixup_sections (abfd
)
306 if (PRIV(fixup_done
))
309 PRIV(sections
) = ((asection
**)
310 bfd_malloc (abfd
->section_count
* sizeof (asection
*)));
311 if (PRIV(sections
) == 0)
313 PRIV(egsd_sec_count
) = abfd
->section_count
;
317 PRIV(sections
)[s
->index
] = s
;
322 * traverse symbol table and fill in all section pointers
325 bfd_hash_traverse (PRIV(evax_symbol_table
), fill_section_ptr
,
326 (PTR
)(PRIV(sections
)));
328 PRIV(fixup_done
) = true;
333 /*===========================================================================*/
335 /* Check the format for a file being read.
336 Return a (bfd_target *) if it's an object file or zero if not. */
338 static const struct bfd_target
*
345 evax_debug (1, "evax_object_p(%p)\n", abfd
);
347 if (bfd_seek (abfd
, 0L, SEEK_SET
))
349 bfd_set_error (bfd_error_file_truncated
);
358 evax_debug (3, "reading at %08lx\n", bfd_tell(abfd
));
360 if (_bfd_evax_next_record (abfd
) < 0)
363 evax_debug (2, "next_record failed\n");
365 bfd_set_error (bfd_error_wrong_format
);
369 if ((prev_type
== EOBJ_S_C_EGSD
) && (PRIV(rec_type
) != EOBJ_S_C_EGSD
))
371 if (evax_fixup_sections (abfd
) == false)
374 evax_debug (2, "evax_fixup_sections failed\n");
376 bfd_set_error (bfd_error_wrong_format
);
381 prev_type
= PRIV(rec_type
);
383 switch (PRIV(rec_type
))
386 err
= _bfd_evax_slurp_emh (abfd
);
389 err
= _bfd_evax_slurp_eeom (abfd
);
392 err
= _bfd_evax_slurp_egsd (abfd
);
395 err
= _bfd_evax_slurp_etir (abfd
);
398 err
= _bfd_evax_slurp_edbg (abfd
);
401 err
= _bfd_evax_slurp_etbt (abfd
);
409 evax_debug (2, "slurp type %d failed with %d\n", PRIV(rec_type
), err
);
411 bfd_set_error (bfd_error_wrong_format
);
415 while (prev_type
!= EOBJ_S_C_EEOM
);
417 /* set arch_info to alpha */
420 const bfd_arch_info_type
*arch
= bfd_scan_arch ("alpha");
424 evax_debug (2, "arch not found\n");
426 bfd_set_error (bfd_error_wrong_format
);
429 abfd
->arch_info
= arch
;
432 return &evax_alpha_vec
;
436 /* Check the format for a file being read.
437 Return a (bfd_target *) if it's an archive file or zero. */
439 static const struct bfd_target
*
440 evax_archive_p (abfd
)
444 evax_debug (1, "evax_archive_p(%p)\n", abfd
);
447 if (!evax_initialize (abfd
))
454 /* Set the format of a file being written. */
461 evax_debug (1, "evax_mkobject(%p)\n", abfd
);
464 if (!evax_initialize (abfd
))
468 const bfd_arch_info_type
*arch
= bfd_scan_arch ("alpha");
471 bfd_set_error(bfd_error_wrong_format
);
474 abfd
->arch_info
= arch
;
481 /* Write cached information into a file being written, at bfd_close. */
484 evax_write_object_contents (abfd
)
488 evax_debug (1, "evax_write_object_contents(%p)\n", abfd
);
491 if (abfd
->section_count
> 0) /* we have sections */
493 if (_bfd_evax_write_emh (abfd
) != 0)
495 if (_bfd_evax_write_egsd (abfd
) != 0)
497 if (_bfd_evax_write_etir (abfd
) != 0)
499 if (_bfd_evax_write_etbt (abfd
) != 0)
501 if (_bfd_evax_write_eeom (abfd
) != 0)
507 /*-- 4.1, generic -----------------------------------------------------------*/
509 /* Called when the BFD is being closed to do any necessary cleanup. */
512 evax_close_and_cleanup (abfd
)
516 evax_section
*es
, *es1
;
517 evax_reloc
*er
, *er1
;
521 evax_debug (1, "evax_close_and_cleanup(%p)\n", abfd
);
526 if (PRIV(evax_buf
) != NULL
)
528 free (PRIV(evax_buf
));
529 PRIV(evax_buf
) = NULL
;
533 if (PRIV(filename
) != NULL
)
535 free (PRIV(filename
));
536 PRIV(filename
) = NULL
;
539 if (PRIV(output_buf
) != 0)
541 free (PRIV(output_buf
));
542 PRIV(output_buf
) = 0;
545 sec
= abfd
->sections
;
549 free (sec
->contents
);
553 if (PRIV(sections
) != NULL
)
555 free (PRIV(sections
));
556 PRIV(sections
) = NULL
;
559 if (PRIV(evax_symbol_table
))
561 bfd_hash_table_free (PRIV(evax_symbol_table
));
562 PRIV(evax_symbol_table
) = 0;
571 if (PRIV(location_stack
))
573 free (PRIV(location_stack
));
574 PRIV(location_stack
) = 0;
577 for (i
= 0; i
< EVAX_SECTION_COUNT
; i
++)
579 es
= PRIV(evax_section_table
)[i
];
586 PRIV(evax_section_table
)[i
] = NULL
;
589 free (abfd
->tdata
.any
);
590 abfd
->tdata
.any
= NULL
;
596 /* Ask the BFD to free all cached information. */
598 evax_bfd_free_cached_info (abfd
)
602 evax_debug (1, "evax_bfd_free_cached_info(%p)\n", abfd
);
608 /* Called when a new section is created. */
611 evax_new_section_hook (abfd
, section
)
616 evax_debug (1, "evax_new_section_hook(%p, %s)\n", abfd
, section
->name
);
618 bfd_set_section_alignment(abfd
, section
, 4);
623 /* Read the contents of a section.
624 buf points to a buffer of buf_size bytes to be filled with
625 section data (starting at offset into section) */
628 evax_get_section_contents (abfd
, section
, buf
, offset
, buf_size
)
633 bfd_size_type buf_size
;
636 evax_debug (1, "evax_get_section_contents(%p, %s, %p, off %ld, size %d)\n",
637 abfd
, section
->name
, buf
, offset
, (int)buf_size
);
640 /* shouldn't be called, since all sections are IN_MEMORY */
645 /* Read the contents of a section.
646 buf points to a buffer of buf_size bytes to be filled with
647 section data (starting at offset into section) */
650 evax_get_section_contents_in_window (abfd
, section
, w
, offset
, count
)
658 evax_debug (1, "evax_get_section_contents_in_window(%p, %s, %p, off %ld, count %d)\n",
659 abfd
, section
->name
, w
, offset
, (int)count
);
662 /* shouldn't be called, since all sections are IN_MEMORY */
667 /*-- Part 4.2, copy private data --------------------------------------------*/
669 /* Called to copy BFD general private data from one object file
673 evax_bfd_copy_private_bfd_data (src
, dest
)
678 evax_debug (1, "evax_bfd_copy_private_bfd_data(%p, %p)\n", src
, dest
);
684 /* Merge private BFD information from the BFD @var{ibfd} to the
685 the output file BFD @var{obfd} when linking. Return <<true>>
686 on success, <<false>> on error. Possible error returns are:
688 o <<bfd_error_no_memory>> -
689 Not enough memory exists to create private data for @var{obfd}. */
692 evax_bfd_merge_private_bfd_data (ibfd
, obfd
)
697 evax_debug (1,"evax_bfd_merge_private_bfd_data(%p, %p)\n", ibfd
, obfd
);
703 /* Set private BFD flag information in the BFD @var{abfd}.
704 Return <<true>> on success, <<false>> on error. Possible error
707 o <<bfd_error_no_memory>> -
708 Not enough memory exists to create private data for @var{obfd}. */
711 evax_bfd_set_private_flags (abfd
, flags
)
716 evax_debug (1,"evax_bfd_set_private_flags(%p, %lx)\n", abfd
, (long)flags
);
722 /* Called to copy BFD private section data from one object file
726 evax_bfd_copy_private_section_data (srcbfd
, srcsec
, dstbfd
, dstsec
)
733 evax_debug (1, "evax_bfd_copy_private_section_data(%p, %s, %p, %s)\n",
734 srcbfd
, srcsec
->name
, dstbfd
, dstsec
->name
);
739 /* Called to copy BFD private symbol data from one object file
743 evax_bfd_copy_private_symbol_data (ibfd
, isym
, obfd
, osym
)
750 evax_debug (1, "evax_bfd_copy_private_symbol_data(%p, %s, %p, %s)\n",
751 ibfd
, isym
->name
, obfd
, osym
->name
);
756 /*-- Part 4.3, core file ----------------------------------------------------*/
758 /* Return a read-only string explaining which program was running
759 when it failed and produced the core file abfd. */
762 evax_core_file_failing_command (abfd
)
766 evax_debug (1, "evax_core_file_failing_command(%p)\n", abfd
);
772 /* Returns the signal number which caused the core dump which
773 generated the file the BFD abfd is attached to. */
776 evax_core_file_failing_signal (abfd
)
780 evax_debug (1, "evax_core_file_failing_signal(%p)\n", abfd
);
786 /* Return true if the core file attached to core_bfd was generated
787 by a run of the executable file attached to exec_bfd, false otherwise. */
790 evax_core_file_matches_executable_p (abfd
, bbfd
)
795 evax_debug (1, "evax_core_file_matches_executable_p(%p, %p)\n", abfd
, bbfd
);
800 /*-- Part 4.4, archive ------------------------------------------------------*/
802 /* ??? do something with an archive map.
803 Return false on error, true otherwise. */
806 evax_slurp_armap (abfd
)
810 evax_debug (1, "evax_slurp_armap(%p)\n", abfd
);
816 /* ??? do something with an extended name table.
817 Return false on error, true otherwise. */
820 evax_slurp_extended_name_table (abfd
)
824 evax_debug (1, "evax_slurp_extended_name_table(%p)\n", abfd
);
830 /* ??? do something with an extended name table.
831 Return false on error, true otherwise. */
834 evax_construct_extended_name_table (abfd
, tabloc
, tablen
, name
)
837 bfd_size_type
*tablen
;
841 evax_debug (1, "evax_construct_extended_name_table(%p)\n", abfd
);
847 /* Truncate the name of an archive to match system-dependent restrictions */
850 evax_truncate_arname (abfd
, pathname
, arhdr
)
852 CONST
char *pathname
;
856 evax_debug (1, "evax_truncate_arname(%p, %s, %s)\n", abfd
, pathname
, arhdr
);
862 /* ??? write archive map */
865 evax_write_armap (arch
, elength
, map
, orl_count
, stridx
)
867 unsigned int elength
;
869 unsigned int orl_count
;
873 evax_debug (1, "evax_write_armap(%p, %d, %p, %d %d)\n",
874 arch
, elength
, map
, orl_count
, stridx
);
879 /* Read archive header ??? */
882 evax_read_ar_hdr (abfd
)
886 evax_debug (1, "evax_read_ar_hdr(%p)\n", abfd
);
892 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
893 an input BFD on the first contained element and returns that.
894 Subsequent calls should pass the archive and the previous return value
895 to return a created BFD to the next contained element.
896 NULL is returned when there are no more. */
899 evax_openr_next_archived_file (arch
, prev
)
904 evax_debug (1, "evax_openr_next_archived_file(%p, %p)\n", arch
, prev
);
910 /* Return the BFD which is referenced by the symbol in ABFD indexed by
911 INDEX. INDEX should have been returned by bfd_get_next_mapent. */
914 evax_get_elt_at_index (abfd
, index
)
919 evax_debug (1, "evax_get_elt_at_index(%p, %p)\n", abfd
, index
);
921 return _bfd_generic_get_elt_at_index(abfd
, index
);
926 -> bfd_generic_stat_arch_elt */
929 evax_generic_stat_arch_elt (abfd
, stat
)
934 evax_debug (1, "evax_generic_stat_arch_elt(%p, %p)\n", abfd
, stat
);
936 return bfd_generic_stat_arch_elt(abfd
, stat
);
940 /* This is a new function in bfd 2.5 */
943 evax_update_armap_timestamp (abfd
)
947 evax_debug (1, "evax_update_armap_timestamp(%p)\n", abfd
);
952 /*-- Part 4.5, symbols --------------------------------------------------------*/
954 /* Return the number of bytes required to store a vector of pointers
955 to asymbols for all the symbols in the BFD abfd, including a
956 terminal NULL pointer. If there are no symbols in the BFD,
957 then return 0. If an error occurs, return -1. */
960 evax_get_symtab_upper_bound (abfd
)
964 evax_debug (1, "evax_get_symtab_upper_bound(%p), %d symbols\n", abfd
, PRIV(egsd_sym_count
));
966 return (PRIV(egsd_sym_count
)+1) * sizeof(asymbol
*);
970 /* Copy symbols from hash table to symbol vector
972 called from bfd_hash_traverse in evax_get_symtab
973 init counter to 0 if entry == 0 */
976 copy_symbols (entry
, arg
)
977 struct bfd_hash_entry
*entry
;
980 bfd
*abfd
= (bfd
*) arg
;
982 if (entry
== NULL
) /* init counter */
984 else /* fill vector, inc counter */
985 PRIV(symcache
)[PRIV(symnum
)++] = ((evax_symbol_entry
*)entry
)->symbol
;
991 /* Read the symbols from the BFD abfd, and fills in the vector
992 location with pointers to the symbols and a trailing NULL.
994 return # of symbols read */
997 evax_get_symtab (abfd
, symbols
)
1002 evax_debug (1, "evax_get_symtab(%p, <ret>)\n", abfd
);
1006 (void)copy_symbols((struct bfd_hash_entry
*)0, abfd
);
1008 /* traverse table and fill symbols vector */
1010 PRIV(symcache
) = symbols
;
1011 bfd_hash_traverse(PRIV(evax_symbol_table
), copy_symbols
, (PTR
)abfd
);
1013 symbols
[bfd_get_symcount(abfd
)] = NULL
;
1015 return bfd_get_symcount(abfd
);
1019 /* Create a new asymbol structure for the BFD abfd and return a pointer
1021 This routine is necessary because each back end has private information
1022 surrounding the asymbol. Building your own asymbol and pointing to it
1023 will not create the private information, and will cause problems later on. */
1026 _bfd_evax_make_empty_symbol (abfd
)
1029 asymbol
*symbol
= (asymbol
*)bfd_zalloc(abfd
, sizeof(asymbol
));
1032 evax_debug (1, "_bfd_evax_make_empty_symbol(%p)\n", abfd
);
1037 bfd_set_error (bfd_error_no_memory
);
1040 symbol
->the_bfd
= abfd
;
1046 /* Print symbol to file according to how. how is one of
1047 bfd_print_symbol_name just print the name
1048 bfd_print_symbol_more print more (???)
1049 bfd_print_symbol_all print all we know, which is not much right now :-) */
1052 evax_print_symbol (abfd
, file
, symbol
, how
)
1056 bfd_print_symbol_type how
;
1059 evax_debug (1, "evax_print_symbol(%p, %p, %p, %d)\n", abfd
, file
, symbol
, how
);
1064 case bfd_print_symbol_name
:
1065 case bfd_print_symbol_more
:
1066 fprintf((FILE *)file
," %s", symbol
->name
);
1071 case bfd_print_symbol_all
:
1073 CONST
char *section_name
= symbol
->section
->name
;
1075 bfd_print_symbol_vandf((PTR
)file
,symbol
);
1077 fprintf((FILE *)file
," %-8s %s", section_name
, symbol
->name
);
1085 /* Return information about symbol in ret.
1087 fill type, value and name
1090 B bss segment symbol
1092 D data segment symbol
1094 t a static function symbol
1095 T text segment symbol
1100 evax_get_symbol_info (abfd
, symbol
, ret
)
1108 evax_debug (1, "evax_get_symbol_info(%p, %p, <ret>)\n", abfd
, symbol
);
1111 sec
= symbol
->section
;
1113 if (bfd_is_com_section (sec
))
1115 else if (bfd_is_abs_section (sec
))
1117 else if (bfd_is_und_section (sec
))
1119 else if (bfd_is_abs_section (sec
))
1121 else if (bfd_is_ind_section (sec
))
1123 else if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1125 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1127 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1132 if (ret
->type
!= 'U')
1133 ret
->value
= symbol
->value
+ symbol
->section
->vma
;
1136 ret
->name
= symbol
->name
;
1142 /* Return true if the given symbol sym in the BFD abfd is
1143 a compiler generated local label, else return false. */
1146 evax_bfd_is_local_label (abfd
, symbol
)
1151 evax_debug (1, "evax_bfd_is_local_label(%p, %p)\n", abfd
, symbol
);
1157 /* Get source line number for symbol */
1160 evax_get_lineno (abfd
, symbol
)
1165 evax_debug (1, "evax_get_lineno(%p, %p)\n", abfd
, symbol
);
1171 /* Provided a BFD, a section and an offset into the section, calculate and
1172 return the name of the source file and the line nearest to the wanted
1176 evax_find_nearest_line (abfd
, section
, symbols
, offset
, file
, func
, line
)
1186 evax_debug (1, "evax_find_nearest_line(%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
1187 abfd
, section
->name
, symbols
, (long int)offset
);
1193 /* Back-door to allow format-aware applications to create debug symbols
1194 while using BFD for everything else. Currently used by the assembler
1195 when creating COFF files. */
1198 evax_bfd_make_debug_symbol (abfd
, ptr
, size
)
1204 evax_debug (1, "evax_bfd_make_debug_symbol(%p, %p, %ld)\n", abfd
, ptr
, size
);
1210 /* Read minisymbols. For minisymbols, we use the unmodified a.out
1211 symbols. The minisymbol_to_symbol function translates these into
1212 BFD asymbol structures. */
1215 evax_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
)
1219 unsigned int *sizep
;
1222 evax_debug (1, "evax_read_minisymbols(%p, %d, %p, %d)\n", abfd
, dynamic
, minisymsp
, *sizep
);
1224 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
1227 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
1228 unmodified a.out symbol. The SYM argument is a structure returned
1229 by bfd_make_empty_symbol, which we fill in here. */
1232 evax_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
)
1239 evax_debug (1, "evax_minisymbol_to_symbol(%p, %d, %p, %p)\n", abfd
, dynamic
, minisym
, sym
);
1241 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
1244 /*-- Part 4.6, relocations --------------------------------------------------*/
1246 /* Return the number of bytes required to store the relocation information
1247 associated with section sect attached to bfd abfd.
1248 If an error occurs, return -1. */
1251 evax_get_reloc_upper_bound (abfd
, section
)
1256 evax_debug (1, "evax_get_reloc_upper_bound(%p, %s)\n", abfd
, section
->name
);
1262 /* Call the back end associated with the open BFD abfd and translate the
1263 external form of the relocation information attached to sec into the
1264 internal canonical form. Place the table into memory at loc, which has
1265 been preallocated, usually by a call to bfd_get_reloc_upper_bound.
1266 Returns the number of relocs, or -1 on error. */
1269 evax_canonicalize_reloc (abfd
, section
, location
, symbols
)
1276 evax_debug (1, "evax_canonicalize_reloc(%p, %s, <ret>, <ret>)\n", abfd
, section
->name
);
1281 /*---------------------------------------------------------------------------*/
1282 /* this is just copied from ecoff-alpha, needs to be fixed probably */
1284 /* How to process the various reloc types. */
1286 static bfd_reloc_status_type
1287 reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
1294 char **error_message
;
1297 evax_debug (1, "reloc_nil(abfd %p, output_bfd %p)\n", abfd
, output_bfd
);
1298 evax_debug (2, "In section %s, symbol %s\n",
1299 sec
->name
, sym
->name
);
1300 evax_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1301 reloc
->sym_ptr_ptr
[0]->name
,
1302 (unsigned long)reloc
->address
,
1303 (unsigned long)reloc
->addend
, reloc
->howto
->name
);
1304 evax_debug (2, "data at %p\n", data
);
1305 /* _bfd_hexdump (2, data, bfd_get_reloc_size(reloc->howto),0); */
1308 return bfd_reloc_ok
;
1311 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1312 from smaller values. Start with zero, widen, *then* decrement. */
1313 #define MINUS_ONE (((bfd_vma)0) - 1)
1315 static reloc_howto_type alpha_howto_table
[] =
1317 HOWTO (ALPHA_R_IGNORE
, /* type */
1319 0, /* size (0 = byte, 1 = short, 2 = long) */
1321 true, /* pc_relative */
1323 complain_overflow_dont
, /* complain_on_overflow */
1324 reloc_nil
, /* special_function */
1325 "IGNORE", /* name */
1326 true, /* partial_inplace */
1329 true), /* pcrel_offset */
1331 /* A 64 bit reference to a symbol. */
1332 HOWTO (ALPHA_R_REFQUAD
, /* type */
1334 4, /* size (0 = byte, 1 = short, 2 = long) */
1336 false, /* pc_relative */
1338 complain_overflow_bitfield
, /* complain_on_overflow */
1339 reloc_nil
, /* special_function */
1340 "REFQUAD", /* name */
1341 true, /* partial_inplace */
1342 MINUS_ONE
, /* src_mask */
1343 MINUS_ONE
, /* dst_mask */
1344 false), /* pcrel_offset */
1346 /* A 21 bit branch. The native assembler generates these for
1347 branches within the text segment, and also fills in the PC
1348 relative offset in the instruction. */
1349 HOWTO (ALPHA_R_BRADDR
, /* type */
1351 2, /* size (0 = byte, 1 = short, 2 = long) */
1353 true, /* pc_relative */
1355 complain_overflow_signed
, /* complain_on_overflow */
1356 reloc_nil
, /* special_function */
1357 "BRADDR", /* name */
1358 true, /* partial_inplace */
1359 0x1fffff, /* src_mask */
1360 0x1fffff, /* dst_mask */
1361 false), /* pcrel_offset */
1363 /* A hint for a jump to a register. */
1364 HOWTO (ALPHA_R_HINT
, /* type */
1366 1, /* size (0 = byte, 1 = short, 2 = long) */
1368 true, /* pc_relative */
1370 complain_overflow_dont
, /* complain_on_overflow */
1371 reloc_nil
, /* special_function */
1373 true, /* partial_inplace */
1374 0x3fff, /* src_mask */
1375 0x3fff, /* dst_mask */
1376 false), /* pcrel_offset */
1378 /* 16 bit PC relative offset. */
1379 HOWTO (ALPHA_R_SREL16
, /* type */
1381 1, /* size (0 = byte, 1 = short, 2 = long) */
1383 true, /* pc_relative */
1385 complain_overflow_signed
, /* complain_on_overflow */
1386 reloc_nil
, /* special_function */
1387 "SREL16", /* name */
1388 true, /* partial_inplace */
1389 0xffff, /* src_mask */
1390 0xffff, /* dst_mask */
1391 false), /* pcrel_offset */
1393 /* 32 bit PC relative offset. */
1394 HOWTO (ALPHA_R_SREL32
, /* type */
1396 2, /* size (0 = byte, 1 = short, 2 = long) */
1398 true, /* pc_relative */
1400 complain_overflow_signed
, /* complain_on_overflow */
1401 reloc_nil
, /* special_function */
1402 "SREL32", /* name */
1403 true, /* partial_inplace */
1404 0xffffffff, /* src_mask */
1405 0xffffffff, /* dst_mask */
1406 false), /* pcrel_offset */
1408 /* A 64 bit PC relative offset. */
1409 HOWTO (ALPHA_R_SREL64
, /* type */
1411 4, /* size (0 = byte, 1 = short, 2 = long) */
1413 true, /* pc_relative */
1415 complain_overflow_signed
, /* complain_on_overflow */
1416 reloc_nil
, /* special_function */
1417 "SREL64", /* name */
1418 true, /* partial_inplace */
1419 MINUS_ONE
, /* src_mask */
1420 MINUS_ONE
, /* dst_mask */
1421 false), /* pcrel_offset */
1423 /* Push a value on the reloc evaluation stack. */
1424 HOWTO (ALPHA_R_OP_PUSH
, /* type */
1426 0, /* size (0 = byte, 1 = short, 2 = long) */
1428 false, /* pc_relative */
1430 complain_overflow_dont
, /* complain_on_overflow */
1431 reloc_nil
, /* special_function */
1432 "OP_PUSH", /* name */
1433 false, /* partial_inplace */
1436 false), /* pcrel_offset */
1438 /* Store the value from the stack at the given address. Store it in
1439 a bitfield of size r_size starting at bit position r_offset. */
1440 HOWTO (ALPHA_R_OP_STORE
, /* type */
1442 4, /* size (0 = byte, 1 = short, 2 = long) */
1444 false, /* pc_relative */
1446 complain_overflow_dont
, /* complain_on_overflow */
1447 reloc_nil
, /* special_function */
1448 "OP_STORE", /* name */
1449 false, /* partial_inplace */
1451 MINUS_ONE
, /* dst_mask */
1452 false), /* pcrel_offset */
1454 /* Subtract the reloc address from the value on the top of the
1455 relocation stack. */
1456 HOWTO (ALPHA_R_OP_PSUB
, /* type */
1458 0, /* size (0 = byte, 1 = short, 2 = long) */
1460 false, /* pc_relative */
1462 complain_overflow_dont
, /* complain_on_overflow */
1463 reloc_nil
, /* special_function */
1464 "OP_PSUB", /* name */
1465 false, /* partial_inplace */
1468 false), /* pcrel_offset */
1470 /* Shift the value on the top of the relocation stack right by the
1472 HOWTO (ALPHA_R_OP_PRSHIFT
, /* type */
1474 0, /* size (0 = byte, 1 = short, 2 = long) */
1476 false, /* pc_relative */
1478 complain_overflow_dont
, /* complain_on_overflow */
1479 reloc_nil
, /* special_function */
1480 "OP_PRSHIFT", /* name */
1481 false, /* partial_inplace */
1484 false), /* pcrel_offset */
1486 /* Hack. Linkage is done by linker. */
1487 HOWTO (ALPHA_R_LINKAGE
, /* type */
1489 8, /* size (0 = byte, 1 = short, 2 = long) */
1491 false, /* pc_relative */
1493 complain_overflow_dont
, /* complain_on_overflow */
1494 reloc_nil
, /* special_function */
1495 "LINKAGE", /* name */
1496 false, /* partial_inplace */
1499 false), /* pcrel_offset */
1501 /* A 32 bit reference to a symbol. */
1502 HOWTO (ALPHA_R_REFLONG
, /* type */
1504 2, /* size (0 = byte, 1 = short, 2 = long) */
1506 false, /* pc_relative */
1508 complain_overflow_bitfield
, /* complain_on_overflow */
1509 reloc_nil
, /* special_function */
1510 "REFLONG", /* name */
1511 true, /* partial_inplace */
1512 0xffffffff, /* src_mask */
1513 0xffffffff, /* dst_mask */
1514 false), /* pcrel_offset */
1518 /* Return a pointer to a howto structure which, when invoked, will perform
1519 the relocation code on data from the architecture noted. */
1521 static const struct reloc_howto_struct
*
1522 evax_bfd_reloc_type_lookup (abfd
, code
)
1524 bfd_reloc_code_real_type code
;
1529 evax_debug (1, "evax_bfd_reloc_type_lookup(%p, %d)\t", abfd
, code
);
1534 case BFD_RELOC_16
: alpha_type
= ALPHA_R_SREL16
; break;
1535 case BFD_RELOC_32
: alpha_type
= ALPHA_R_REFLONG
; break;
1536 case BFD_RELOC_64
: alpha_type
= ALPHA_R_REFQUAD
; break;
1537 case BFD_RELOC_CTOR
: alpha_type
= ALPHA_R_REFQUAD
; break;
1538 case BFD_RELOC_23_PCREL_S2
: alpha_type
= ALPHA_R_BRADDR
; break;
1539 case BFD_RELOC_ALPHA_HINT
: alpha_type
= ALPHA_R_HINT
; break;
1540 case BFD_RELOC_16_PCREL
: alpha_type
= ALPHA_R_SREL16
; break;
1541 case BFD_RELOC_32_PCREL
: alpha_type
= ALPHA_R_SREL32
; break;
1542 case BFD_RELOC_64_PCREL
: alpha_type
= ALPHA_R_SREL64
; break;
1543 case BFD_RELOC_ALPHA_LINKAGE
: alpha_type
= ALPHA_R_LINKAGE
; break;
1545 case ???: alpha_type
= ALPHA_R_OP_PUSH
; break;
1546 case ???: alpha_type
= ALPHA_R_OP_STORE
; break;
1547 case ???: alpha_type
= ALPHA_R_OP_PSUB
; break;
1548 case ???: alpha_type
= ALPHA_R_OP_PRSHIFT
;break;
1549 case ???: alpha_type
= ALPHA_R_GPVALUE
; break;
1552 (*_bfd_error_handler
) ("reloc (%d) is *UNKNOWN*", code
);
1553 return (const struct reloc_howto_struct
*) NULL
;
1556 evax_debug (2, "reloc is %s\n", alpha_howto_table
[alpha_type
].name
);
1558 return &alpha_howto_table
[alpha_type
];
1562 /*-- Part 4.7, writing an object file ---------------------------------------*/
1564 /* Set the architecture and machine type in BFD abfd to arch and mach.
1565 Find the correct pointer to a structure and insert it into the arch_info
1569 evax_set_arch_mach (abfd
, arch
, mach
)
1571 enum bfd_architecture arch
;
1575 evax_debug (1, "evax_set_arch_mach(%p, %d, %ld)\n", abfd
, arch
, mach
);
1577 abfd
->arch_info
= bfd_scan_arch("alpha");
1583 /* Sets the contents of the section section in BFD abfd to the data starting
1584 in memory at data. The data is written to the output section starting at
1585 offset offset for count bytes.
1587 Normally true is returned, else false. Possible error returns are:
1588 o bfd_error_no_contents - The output section does not have the
1589 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1590 o and some more too */
1593 evax_set_section_contents (abfd
, section
, location
, offset
, count
)
1598 bfd_size_type count
;
1601 evax_debug (1, "evax_set_section_contents(%p, sec %s, loc %p, off %ld, count %d)\n",
1602 abfd
, section
->name
, location
, (long int)offset
, (int)count
);
1603 evax_debug (2, "secraw %d, seccooked %d\n", (int)section
->_raw_size
, (int)section
->_cooked_size
);
1605 return _bfd_save_evax_section(abfd
, section
, location
, offset
, count
);
1609 /*-- Part 4.8, linker -------------------------------------------------------*/
1611 /* Get the size of the section headers. */
1614 evax_sizeof_headers (abfd
, reloc
)
1619 evax_debug (1, "evax_sizeof_headers(%p, %s)\n", abfd
, (reloc
)?"True":"False");
1625 /* Provides default handling of relocation effort for back ends
1626 which can't be bothered to do it efficiently. */
1629 evax_bfd_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
1630 relocateable
, symbols
)
1632 struct bfd_link_info
*link_info
;
1633 struct bfd_link_order
*link_order
;
1635 boolean relocateable
;
1639 evax_debug (1, "evax_bfd_get_relocated_section_contents(%p, %p, %p, %p, %s, %p)\n",
1640 abfd
, link_info
, link_order
, data
, (relocateable
)?"True":"False", symbols
);
1649 evax_bfd_relax_section (abfd
, section
, link_info
, again
)
1652 struct bfd_link_info
*link_info
;
1656 evax_debug (1, "evax_bfd_relax_section(%p, %s, %p, <ret>)\n",
1657 abfd
, section
->name
, link_info
);
1663 /* Create a hash table for the linker. Different backends store
1664 different information in this table. */
1666 static struct bfd_link_hash_table
*
1667 evax_bfd_link_hash_table_create (abfd
)
1671 evax_debug (1, "evax_bfd_link_hash_table_create(%p)\n", abfd
);
1677 /* Add symbols from this object file into the hash table. */
1680 evax_bfd_link_add_symbols (abfd
, link_info
)
1682 struct bfd_link_info
*link_info
;
1685 evax_debug (1, "evax_bfd_link_add_symbols(%p, %p)\n", abfd
, link_info
);
1691 /* Do a link based on the link_order structures attached to each
1692 section of the BFD. */
1695 evax_bfd_final_link (abfd
, link_info
)
1697 struct bfd_link_info
*link_info
;
1700 evax_debug (1, "evax_bfd_final_link(%p, %p)\n", abfd
, link_info
);
1705 /* Should this section be split up into smaller pieces during linking. */
1708 evax_bfd_link_split_section (abfd
, section
)
1713 evax_debug (1, "evax_bfd_link_split_section(%p, %s)\n", abfd
, section
->name
);
1718 /*-- Part 4.9, dynamic symbols and relocations ------------------------------*/
1720 /* Get the amount of memory required to hold the dynamic symbols. */
1723 evax_get_dynamic_symtab_upper_bound (abfd
)
1727 evax_debug (1, "evax_get_dynamic_symtab_upper_bound(%p)\n", abfd
);
1733 evax_bfd_print_private_bfd_data (abfd
, file
)
1738 evax_debug (1, "evax_bfd_print_private_bfd_data(%p)\n", abfd
);
1744 /* Read in the dynamic symbols. */
1747 evax_canonicalize_dynamic_symtab (abfd
, symbols
)
1752 evax_debug (1, "evax_canonicalize_dynamic_symtab(%p, <ret>)\n", abfd
);
1758 /* Get the amount of memory required to hold the dynamic relocs. */
1761 evax_get_dynamic_reloc_upper_bound (abfd
)
1765 evax_debug (1, "evax_get_dynamic_reloc_upper_bound(%p)\n", abfd
);
1771 /* Read in the dynamic relocs. */
1774 evax_canonicalize_dynamic_reloc (abfd
, arel
, symbols
)
1780 evax_debug (1, "evax_canonicalize_dynamic_reloc(%p)\n", abfd
);