| 1 | /* Define a target vector and some small routines for a variant of a.out. |
| 2 | Copyright (C) 1990-1991 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of BFD, the Binary File Descriptor library. |
| 5 | |
| 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. |
| 10 | |
| 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. |
| 15 | |
| 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 19 | |
| 20 | #include "aout/aout64.h" |
| 21 | #include "aout/stab_gnu.h" |
| 22 | #include "aout/ar.h" |
| 23 | /*#include "libaout.h"*/ |
| 24 | |
| 25 | /* Set parameters about this a.out file that are machine-dependent. |
| 26 | This routine is called from some_aout_object_p just before it returns. */ |
| 27 | static bfd_target * |
| 28 | DEFUN(MY(callback),(abfd), |
| 29 | bfd *abfd) |
| 30 | { |
| 31 | struct internal_exec *execp = exec_hdr (abfd); |
| 32 | |
| 33 | /* Calculate the file positions of the parts of a newly read aout header */ |
| 34 | obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp); |
| 35 | |
| 36 | /* The virtual memory addresses of the sections */ |
| 37 | obj_textsec (abfd)->vma = N_TXTADDR(*execp); |
| 38 | obj_datasec (abfd)->vma = N_DATADDR(*execp); |
| 39 | obj_bsssec (abfd)->vma = N_BSSADDR(*execp); |
| 40 | |
| 41 | /* The file offsets of the sections */ |
| 42 | obj_textsec (abfd)->filepos = N_TXTOFF (*execp); |
| 43 | obj_datasec (abfd)->filepos = N_DATOFF (*execp); |
| 44 | |
| 45 | /* The file offsets of the relocation info */ |
| 46 | obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp); |
| 47 | obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp); |
| 48 | |
| 49 | /* The file offsets of the string table and symbol table. */ |
| 50 | obj_sym_filepos (abfd) = N_SYMOFF (*execp); |
| 51 | obj_str_filepos (abfd) = N_STROFF (*execp); |
| 52 | |
| 53 | /* Determine the architecture and machine type of the object file. */ |
| 54 | #ifdef SET_ARCH_MACH |
| 55 | SET_ARCH_MACH(abfd, *execp); |
| 56 | #else |
| 57 | bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0); |
| 58 | #endif |
| 59 | |
| 60 | adata(abfd).page_size = PAGE_SIZE; |
| 61 | #ifdef SEGMENT_SIZE |
| 62 | adata(abfd).segment_size = SEGMENT_SIZE; |
| 63 | #else |
| 64 | adata(abfd).segment_size = PAGE_SIZE; |
| 65 | #endif |
| 66 | adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE; |
| 67 | |
| 68 | return abfd->xvec; |
| 69 | } |
| 70 | |
| 71 | #ifndef MY_object_p |
| 72 | /* Finish up the reading of an a.out file header */ |
| 73 | |
| 74 | static bfd_target * |
| 75 | DEFUN(MY(object_p),(abfd), |
| 76 | bfd *abfd) |
| 77 | { |
| 78 | struct external_exec exec_bytes; /* Raw exec header from file */ |
| 79 | struct internal_exec exec; /* Cleaned-up exec header */ |
| 80 | bfd_target *target; |
| 81 | |
| 82 | if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd) |
| 83 | != EXEC_BYTES_SIZE) { |
| 84 | bfd_error = wrong_format; |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info); |
| 89 | |
| 90 | if (N_BADMAG (exec)) return 0; |
| 91 | |
| 92 | NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec); |
| 93 | target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback)); |
| 94 | |
| 95 | #ifdef ENTRY_CAN_BE_ZERO |
| 96 | /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage) |
| 97 | * means that it isn't obvious if EXEC_P should be set. |
| 98 | * All of the following must be true for an executable: |
| 99 | * There must be no relocations, the bfd can be neither an |
| 100 | * archive nor an archive element, and the file must be executable. */ |
| 101 | |
| 102 | if (exec.a_trsize + exec.a_drsize == 0 |
| 103 | && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL) |
| 104 | { |
| 105 | struct stat buf; |
| 106 | #ifndef S_IXUSR |
| 107 | #define S_IXUSR 0100 /* Execute by owner. */ |
| 108 | #endif |
| 109 | if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR)) |
| 110 | abfd->flags |= EXEC_P; |
| 111 | } |
| 112 | #endif /* ENTRY_CAN_BE_ZERO */ |
| 113 | |
| 114 | return target; |
| 115 | } |
| 116 | #define MY_object_p MY(object_p) |
| 117 | #endif |
| 118 | |
| 119 | |
| 120 | #ifndef MY_mkobject |
| 121 | static boolean |
| 122 | DEFUN(MY(mkobject),(abfd), |
| 123 | bfd *abfd) |
| 124 | { |
| 125 | if (NAME(aout,mkobject)(abfd) == false) |
| 126 | return false; |
| 127 | adata(abfd).page_size = PAGE_SIZE; |
| 128 | #ifdef SEGMENT_SIZE |
| 129 | adata(abfd).segment_size = SEGMENT_SIZE; |
| 130 | #else |
| 131 | adata(abfd).segment_size = PAGE_SIZE; |
| 132 | #endif |
| 133 | adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE; |
| 134 | return true; |
| 135 | } |
| 136 | #define MY_mkobject MY(mkobject) |
| 137 | #endif |
| 138 | |
| 139 | /* Write an object file. |
| 140 | Section contents have already been written. We write the |
| 141 | file header, symbols, and relocation. */ |
| 142 | |
| 143 | #ifndef MY_write_object_contents |
| 144 | static boolean |
| 145 | DEFUN(MY(write_object_contents),(abfd), |
| 146 | bfd *abfd) |
| 147 | { |
| 148 | bfd_size_type data_pad = 0; |
| 149 | struct external_exec exec_bytes; |
| 150 | struct internal_exec *execp = exec_hdr (abfd); |
| 151 | |
| 152 | #if CHOOSE_RELOC_SIZE |
| 153 | CHOOSE_RELOC_SIZE(abfd); |
| 154 | #else |
| 155 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; |
| 156 | #endif |
| 157 | |
| 158 | WRITE_HEADERS(abfd, execp); |
| 159 | |
| 160 | return true; |
| 161 | } |
| 162 | #define MY_write_object_contents MY(write_object_contents) |
| 163 | #endif |
| 164 | |
| 165 | /* We assume BFD generic archive files. */ |
| 166 | #ifndef MY_openr_next_archived_file |
| 167 | #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file |
| 168 | #endif |
| 169 | #ifndef MY_generic_stat_arch_elt |
| 170 | #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt |
| 171 | #endif |
| 172 | #ifndef MY_slurp_armap |
| 173 | #define MY_slurp_armap bfd_slurp_bsd_armap |
| 174 | #endif |
| 175 | #ifndef MY_slurp_extended_name_table |
| 176 | #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table |
| 177 | #endif |
| 178 | #ifndef MY_write_armap |
| 179 | #define MY_write_armap bsd_write_armap |
| 180 | #endif |
| 181 | #ifndef MY_truncate_arname |
| 182 | #define MY_truncate_arname bfd_bsd_truncate_arname |
| 183 | #endif |
| 184 | |
| 185 | /* No core file defined here -- configure in trad-core.c separately. */ |
| 186 | #ifndef MY_core_file_failing_command |
| 187 | #define MY_core_file_failing_command _bfd_dummy_core_file_failing_command |
| 188 | #endif |
| 189 | #ifndef MY_core_file_failing_signal |
| 190 | #define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal |
| 191 | #endif |
| 192 | #ifndef MY_core_file_matches_executable_p |
| 193 | #define MY_core_file_matches_executable_p \ |
| 194 | _bfd_dummy_core_file_matches_executable_p |
| 195 | #endif |
| 196 | #ifndef MY_core_file_p |
| 197 | #define MY_core_file_p _bfd_dummy_target |
| 198 | #endif |
| 199 | |
| 200 | #ifndef MY_bfd_debug_info_start |
| 201 | #define MY_bfd_debug_info_start bfd_void |
| 202 | #endif |
| 203 | #ifndef MY_bfd_debug_info_end |
| 204 | #define MY_bfd_debug_info_end bfd_void |
| 205 | #endif |
| 206 | #ifndef MY_bfd_debug_info_accumulate |
| 207 | #define MY_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void |
| 208 | #endif |
| 209 | |
| 210 | #ifndef MY_core_file_failing_command |
| 211 | #define MY_core_file_failing_command NAME(aout,core_file_failing_command) |
| 212 | #endif |
| 213 | #ifndef MY_core_file_failing_signal |
| 214 | #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal) |
| 215 | #endif |
| 216 | #ifndef MY_core_file_matches_executable_p |
| 217 | #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p) |
| 218 | #endif |
| 219 | #ifndef MY_slurp_armap |
| 220 | #define MY_slurp_armap NAME(aout,slurp_armap) |
| 221 | #endif |
| 222 | #ifndef MY_slurp_extended_name_table |
| 223 | #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table) |
| 224 | #endif |
| 225 | #ifndef MY_truncate_arname |
| 226 | #define MY_truncate_arname NAME(aout,truncate_arname) |
| 227 | #endif |
| 228 | #ifndef MY_write_armap |
| 229 | #define MY_write_armap NAME(aout,write_armap) |
| 230 | #endif |
| 231 | #ifndef MY_close_and_cleanup |
| 232 | #define MY_close_and_cleanup NAME(aout,close_and_cleanup) |
| 233 | #endif |
| 234 | #ifndef MY_set_section_contents |
| 235 | #define MY_set_section_contents NAME(aout,set_section_contents) |
| 236 | #endif |
| 237 | #ifndef MY_get_section_contents |
| 238 | #define MY_get_section_contents NAME(aout,get_section_contents) |
| 239 | #endif |
| 240 | #ifndef MY_new_section_hook |
| 241 | #define MY_new_section_hook NAME(aout,new_section_hook) |
| 242 | #endif |
| 243 | #ifndef MY_get_symtab_upper_bound |
| 244 | #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound) |
| 245 | #endif |
| 246 | #ifndef MY_get_symtab |
| 247 | #define MY_get_symtab NAME(aout,get_symtab) |
| 248 | #endif |
| 249 | #ifndef MY_get_reloc_upper_bound |
| 250 | #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound) |
| 251 | #endif |
| 252 | #ifndef MY_canonicalize_reloc |
| 253 | #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc) |
| 254 | #endif |
| 255 | #ifndef MY_make_empty_symbol |
| 256 | #define MY_make_empty_symbol NAME(aout,make_empty_symbol) |
| 257 | #endif |
| 258 | #ifndef MY_print_symbol |
| 259 | #define MY_print_symbol NAME(aout,print_symbol) |
| 260 | #endif |
| 261 | #ifndef MY_get_lineno |
| 262 | #define MY_get_lineno NAME(aout,get_lineno) |
| 263 | #endif |
| 264 | #ifndef MY_set_arch_mach |
| 265 | #define MY_set_arch_mach NAME(aout,set_arch_mach) |
| 266 | #endif |
| 267 | #ifndef MY_openr_next_archived_file |
| 268 | #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file) |
| 269 | #endif |
| 270 | #ifndef MY_find_nearest_line |
| 271 | #define MY_find_nearest_line NAME(aout,find_nearest_line) |
| 272 | #endif |
| 273 | #ifndef MY_generic_stat_arch_elt |
| 274 | #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt) |
| 275 | #endif |
| 276 | #ifndef MY_sizeof_headers |
| 277 | #define MY_sizeof_headers NAME(aout,sizeof_headers) |
| 278 | #endif |
| 279 | #ifndef MY_bfd_debug_info_start |
| 280 | #define MY_bfd_debug_info_start NAME(aout,bfd_debug_info_start) |
| 281 | #endif |
| 282 | #ifndef MY_bfd_debug_info_end |
| 283 | #define MY_bfd_debug_info_end NAME(aout,bfd_debug_info_end) |
| 284 | #endif |
| 285 | #ifndef MY_bfd_debug_info_accumulat |
| 286 | #define MY_bfd_debug_info_accumulat NAME(aout,bfd_debug_info_accumulat) |
| 287 | #endif |
| 288 | #ifndef MY_reloc_howto_type_lookup |
| 289 | #define MY_reloc_howto_type_lookup 0 |
| 290 | #endif |
| 291 | #ifndef MY_make_debug_symbol |
| 292 | #define MY_make_debug_symbol 0 |
| 293 | #endif |
| 294 | #ifndef MY_backend_data |
| 295 | #define MY_backend_data (PTR) 0 |
| 296 | #endif |
| 297 | |
| 298 | bfd_target MY(vec) = |
| 299 | { |
| 300 | TARGETNAME, /* name */ |
| 301 | bfd_target_aout_flavour, |
| 302 | #ifdef TARGET_IS_BIG_ENDIAN_P |
| 303 | true, /* target byte order (big) */ |
| 304 | true, /* target headers byte order (big) */ |
| 305 | #else |
| 306 | false, /* target byte order (little) */ |
| 307 | false, /* target headers byte order (little) */ |
| 308 | #endif |
| 309 | (HAS_RELOC | EXEC_P | /* object flags */ |
| 310 | HAS_LINENO | HAS_DEBUG | |
| 311 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), |
| 312 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
| 313 | ' ', /* ar_pad_char */ |
| 314 | 15, /* ar_max_namelen */ |
| 315 | 1, /* minimum alignment */ |
| 316 | #ifdef TARGET_IS_BIG_ENDIAN_P |
| 317 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */ |
| 318 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */ |
| 319 | #else |
| 320 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */ |
| 321 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */ |
| 322 | #endif |
| 323 | {_bfd_dummy_target, MY_object_p, /* bfd_check_format */ |
| 324 | bfd_generic_archive_p, MY_core_file_p}, |
| 325 | {bfd_false, MY_mkobject, /* bfd_set_format */ |
| 326 | _bfd_generic_mkarchive, bfd_false}, |
| 327 | {bfd_false, MY_write_object_contents, /* bfd_write_contents */ |
| 328 | _bfd_write_archive_contents, bfd_false}, |
| 329 | |
| 330 | MY_core_file_failing_command, |
| 331 | MY_core_file_failing_signal, |
| 332 | MY_core_file_matches_executable_p, |
| 333 | MY_slurp_armap, |
| 334 | MY_slurp_extended_name_table, |
| 335 | MY_truncate_arname, |
| 336 | MY_write_armap, |
| 337 | MY_close_and_cleanup, |
| 338 | MY_set_section_contents, |
| 339 | MY_get_section_contents, |
| 340 | MY_new_section_hook, |
| 341 | MY_get_symtab_upper_bound, |
| 342 | MY_get_symtab, |
| 343 | MY_get_reloc_upper_bound, |
| 344 | MY_canonicalize_reloc, |
| 345 | MY_make_empty_symbol, |
| 346 | MY_print_symbol, |
| 347 | MY_get_lineno, |
| 348 | MY_set_arch_mach, |
| 349 | MY_openr_next_archived_file, |
| 350 | MY_find_nearest_line, |
| 351 | MY_generic_stat_arch_elt, |
| 352 | MY_sizeof_headers, |
| 353 | MY_bfd_debug_info_start, |
| 354 | MY_bfd_debug_info_end, |
| 355 | MY_bfd_debug_info_accumulate, |
| 356 | bfd_generic_get_relocated_section_contents, |
| 357 | bfd_generic_relax_section, |
| 358 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* COFF stuff?! */ |
| 359 | MY_reloc_howto_type_lookup, |
| 360 | MY_make_debug_symbol, |
| 361 | (PTR) MY_backend_data, |
| 362 | }; |