00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef LIBAOUT_H
00028 #define LIBAOUT_H
00029
00030
00031
00032
00033
00034 #include "bfdlink.h"
00035
00036
00037
00038 #define H_PUT_64 bfd_h_put_64
00039 #define H_PUT_32 bfd_h_put_32
00040 #define H_PUT_16 bfd_h_put_16
00041 #define H_PUT_8 bfd_h_put_8
00042 #define H_PUT_S64 bfd_h_put_signed_64
00043 #define H_PUT_S32 bfd_h_put_signed_32
00044 #define H_PUT_S16 bfd_h_put_signed_16
00045 #define H_PUT_S8 bfd_h_put_signed_8
00046 #define H_GET_64 bfd_h_get_64
00047 #define H_GET_32 bfd_h_get_32
00048 #define H_GET_16 bfd_h_get_16
00049 #define H_GET_8 bfd_h_get_8
00050 #define H_GET_S64 bfd_h_get_signed_64
00051 #define H_GET_S32 bfd_h_get_signed_32
00052 #define H_GET_S16 bfd_h_get_signed_16
00053 #define H_GET_S8 bfd_h_get_signed_8
00054
00055
00056
00057
00058
00059
00060 #if ARCH_SIZE==64
00061 #define GET_WORD H_GET_64
00062 #define GET_SWORD H_GET_S64
00063 #define GET_MAGIC H_GET_32
00064 #define PUT_WORD H_PUT_64
00065 #define PUT_MAGIC H_PUT_32
00066 #ifndef NAME
00067 #define NAME(x,y) CONCAT3 (x,_64_,y)
00068 #endif
00069 #define JNAME(x) CONCAT2 (x,_64)
00070 #define BYTES_IN_WORD 8
00071 #else
00072 #if ARCH_SIZE==16
00073 #define GET_WORD H_GET_16
00074 #define GET_SWORD H_GET_S16
00075 #define GET_MAGIC H_GET_16
00076 #define PUT_WORD H_PUT_16
00077 #define PUT_MAGIC H_PUT_16
00078 #ifndef NAME
00079 #define NAME(x,y) CONCAT3 (x,_16_,y)
00080 #endif
00081 #define JNAME(x) CONCAT2 (x,_16)
00082 #define BYTES_IN_WORD 2
00083 #else
00084 #define GET_WORD H_GET_32
00085 #define GET_SWORD H_GET_S32
00086 #define GET_MAGIC H_GET_32
00087 #define PUT_WORD H_PUT_32
00088 #define PUT_MAGIC H_PUT_32
00089 #ifndef NAME
00090 #define NAME(x,y) CONCAT3 (x,_32_,y)
00091 #endif
00092 #define JNAME(x) CONCAT2 (x,_32)
00093 #define BYTES_IN_WORD 4
00094 #endif
00095 #endif
00096
00097
00098
00099 struct external_exec;
00100 struct external_nlist;
00101 struct reloc_ext_external;
00102 struct reloc_std_external;
00103
00104
00105
00106 struct aout_link_hash_entry
00107 {
00108 struct bfd_link_hash_entry root;
00109
00110 bfd_boolean written;
00111
00112 int indx;
00113 };
00114
00115
00116
00117 struct aout_link_hash_table
00118 {
00119 struct bfd_link_hash_table root;
00120 };
00121
00122
00123
00124 #define aout_link_hash_lookup(table, string, create, copy, follow) \
00125 ((struct aout_link_hash_entry *) \
00126 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
00127
00128
00129
00130 #define aout_link_hash_traverse(table, func, info) \
00131 (bfd_link_hash_traverse \
00132 (&(table)->root, \
00133 (bfd_boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
00134 (info)))
00135
00136
00137
00138
00139 #define aout_hash_table(p) ((struct aout_link_hash_table *) ((p)->hash))
00140
00141
00142 struct aout_backend_data
00143 {
00144
00145
00146
00147 unsigned char zmagic_mapped_contiguous;
00148
00149
00150
00151 unsigned char text_includes_header;
00152
00153
00154
00155
00156
00157 unsigned char entry_is_text_address;
00158
00159
00160 unsigned char exec_hdr_flags;
00161
00162
00163
00164
00165
00166
00167
00168 bfd_vma default_text_vma;
00169
00170
00171
00172 bfd_boolean (*set_sizes)
00173 PARAMS ((bfd *));
00174
00175
00176
00177
00178 unsigned char exec_header_not_counted;
00179
00180
00181
00182 bfd_boolean (*add_dynamic_symbols)
00183 PARAMS ((bfd *, struct bfd_link_info *, struct external_nlist **,
00184 bfd_size_type *, char **));
00185
00186
00187
00188 bfd_boolean (*add_one_symbol)
00189 PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword,
00190 asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
00191 struct bfd_link_hash_entry **));
00192
00193
00194 bfd_boolean (*link_dynamic_object)
00195 PARAMS ((struct bfd_link_info *, bfd *));
00196
00197
00198
00199 bfd_boolean (*write_dynamic_symbol)
00200 PARAMS ((bfd *, struct bfd_link_info *, struct aout_link_hash_entry *));
00201
00202
00203
00204
00205
00206 bfd_boolean (*check_dynamic_reloc)
00207 PARAMS ((struct bfd_link_info *info, bfd *input_bfd,
00208 asection *input_section, struct aout_link_hash_entry *h,
00209 PTR reloc, bfd_byte *contents, bfd_boolean *skip,
00210 bfd_vma *relocation));
00211
00212
00213
00214 bfd_boolean (*finish_dynamic_link)
00215 PARAMS ((bfd *, struct bfd_link_info *));
00216 };
00217 #define aout_backend_info(abfd) \
00218 ((const struct aout_backend_data *)((abfd)->xvec->backend_data))
00219
00220
00221
00222
00223
00224
00225
00226 struct internal_exec
00227 {
00228 long a_info;
00229 bfd_vma a_text;
00230 bfd_vma a_data;
00231 bfd_vma a_bss;
00232 bfd_vma a_syms;
00233 bfd_vma a_entry;
00234 bfd_vma a_trsize;
00235 bfd_vma a_drsize;
00236
00237 bfd_vma a_tload;
00238 bfd_vma a_dload;
00239 unsigned char a_talign;
00240 unsigned char a_dalign;
00241 unsigned char a_balign;
00242 char a_relaxable;
00243 };
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 enum machine_type
00256 {
00257 M_UNKNOWN = 0,
00258 M_68010 = 1,
00259 M_68020 = 2,
00260 M_SPARC = 3,
00261
00262
00263 M_NS32032 = (64),
00264 M_NS32532 = (64 + 5),
00265 M_386 = 100,
00266 M_29K = 101,
00267 M_386_DYNIX = 102,
00268 M_ARM = 103,
00269 M_SPARCLET = 131,
00270 M_386_NETBSD = 134,
00271 M_68K_NETBSD = 135,
00272 M_68K4K_NETBSD = 136,
00273 M_532_NETBSD = 137,
00274 M_SPARC_NETBSD = 138,
00275 M_PMAX_NETBSD = 139,
00276 M_VAX_NETBSD = 140,
00277 M_ALPHA_NETBSD = 141,
00278 M_ARM6_NETBSD = 143,
00279 M_SPARCLET_1 = 147,
00280 M_POWERPC_NETBSD = 149,
00281 M_VAX4K_NETBSD = 150,
00282 M_MIPS1 = 151,
00283 M_MIPS2 = 152,
00284 M_88K_OPENBSD = 153,
00285 M_HPPA_OPENBSD = 154,
00286 M_SPARC64_NETBSD = 156,
00287 M_X86_64_NETBSD = 157,
00288 M_SPARCLET_2 = 163,
00289 M_SPARCLET_3 = 179,
00290 M_SPARCLET_4 = 195,
00291 M_HP200 = 200,
00292 M_HP300 = (300 % 256),
00293 M_HPUX = (0x20c % 256),
00294 M_SPARCLET_5 = 211,
00295 M_SPARCLET_6 = 227,
00296
00297 M_SPARCLITE_LE = 243,
00298 M_CRIS = 255
00299 };
00300
00301 #define N_DYNAMIC(exec) ((exec).a_info & 0x80000000)
00302
00303 #ifndef N_MAGIC
00304 # define N_MAGIC(exec) ((exec).a_info & 0xffff)
00305 #endif
00306
00307 #ifndef N_MACHTYPE
00308 # define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
00309 #endif
00310
00311 #ifndef N_FLAGS
00312 # define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
00313 #endif
00314
00315 #ifndef N_SET_INFO
00316 # define N_SET_INFO(exec, magic, type, flags) \
00317 ((exec).a_info = ((magic) & 0xffff) \
00318 | (((int)(type) & 0xff) << 16) \
00319 | (((flags) & 0xff) << 24))
00320 #endif
00321
00322 #ifndef N_SET_DYNAMIC
00323 # define N_SET_DYNAMIC(exec, dynamic) \
00324 ((exec).a_info = (dynamic) ? (long) ((exec).a_info | 0x80000000) : \
00325 ((exec).a_info & 0x7fffffff))
00326 #endif
00327
00328 #ifndef N_SET_MAGIC
00329 # define N_SET_MAGIC(exec, magic) \
00330 ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
00331 #endif
00332
00333 #ifndef N_SET_MACHTYPE
00334 # define N_SET_MACHTYPE(exec, machtype) \
00335 ((exec).a_info = \
00336 ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
00337 #endif
00338
00339 #ifndef N_SET_FLAGS
00340 # define N_SET_FLAGS(exec, flags) \
00341 ((exec).a_info = \
00342 ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
00343 #endif
00344
00345 typedef struct aout_symbol
00346 {
00347 asymbol symbol;
00348 short desc;
00349 char other;
00350 unsigned char type;
00351 } aout_symbol_type;
00352
00353
00354
00355
00356
00357 struct aoutdata
00358 {
00359 struct internal_exec *hdr;
00360 aout_symbol_type *symbols;
00361
00362
00363 asection *textsec;
00364 asection *datasec;
00365 asection *bsssec;
00366
00367
00368
00369 file_ptr sym_filepos;
00370 file_ptr str_filepos;
00371
00372
00373 unsigned reloc_entry_size;
00374
00375
00376 unsigned symbol_entry_size;
00377
00378
00379 unsigned long page_size;
00380
00381
00382 unsigned long segment_size;
00383
00384
00385
00386 unsigned long zmagic_disk_block_size;
00387
00388 unsigned exec_bytes_size;
00389 unsigned vma_adjusted : 1;
00390
00391
00392 enum
00393 {
00394 default_format = 0,
00395
00396 gnu_encap_format,
00397
00398 q_magic_format
00399 } subformat;
00400
00401 enum
00402 {
00403 undecided_magic = 0,
00404 z_magic,
00405 o_magic,
00406 n_magic
00407 } magic;
00408
00409
00410 char *line_buf;
00411
00412
00413 struct external_nlist *external_syms;
00414 bfd_size_type external_sym_count;
00415 bfd_window sym_window;
00416 char *external_strings;
00417 bfd_size_type external_string_size;
00418 bfd_window string_window;
00419 struct aout_link_hash_entry **sym_hashes;
00420
00421
00422 PTR dynamic_info;
00423
00424
00425
00426
00427 bfd_vma *local_got_offsets;
00428 };
00429
00430 struct aout_data_struct
00431 {
00432 struct aoutdata a;
00433 struct internal_exec e;
00434 };
00435
00436 #define adata(bfd) ((bfd)->tdata.aout_data->a)
00437 #define exec_hdr(bfd) (adata (bfd).hdr)
00438 #define obj_aout_symbols(bfd) (adata (bfd).symbols)
00439 #define obj_textsec(bfd) (adata (bfd).textsec)
00440 #define obj_datasec(bfd) (adata (bfd).datasec)
00441 #define obj_bsssec(bfd) (adata (bfd).bsssec)
00442 #define obj_sym_filepos(bfd) (adata (bfd).sym_filepos)
00443 #define obj_str_filepos(bfd) (adata (bfd).str_filepos)
00444 #define obj_reloc_entry_size(bfd) (adata (bfd).reloc_entry_size)
00445 #define obj_symbol_entry_size(bfd) (adata (bfd).symbol_entry_size)
00446 #define obj_aout_subformat(bfd) (adata (bfd).subformat)
00447 #define obj_aout_external_syms(bfd) (adata (bfd).external_syms)
00448 #define obj_aout_external_sym_count(bfd) (adata (bfd).external_sym_count)
00449 #define obj_aout_sym_window(bfd) (adata (bfd).sym_window)
00450 #define obj_aout_external_strings(bfd) (adata (bfd).external_strings)
00451 #define obj_aout_external_string_size(bfd) (adata (bfd).external_string_size)
00452 #define obj_aout_string_window(bfd) (adata (bfd).string_window)
00453 #define obj_aout_sym_hashes(bfd) (adata (bfd).sym_hashes)
00454 #define obj_aout_dynamic_info(bfd) (adata (bfd).dynamic_info)
00455
00456
00457
00458 #define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd))
00459
00460
00461
00462
00463 struct aout_section_data_struct
00464 {
00465
00466 PTR relocs;
00467 };
00468
00469 #define aout_section_data(s) \
00470 ((struct aout_section_data_struct *) (s)->used_by_bfd)
00471
00472 #define set_aout_section_data(s,v) \
00473 ((s)->used_by_bfd = (PTR)&(v)->relocs)
00474
00475
00476
00477 extern bfd_boolean NAME(aout,squirt_out_relocs)
00478 PARAMS ((bfd *, asection *));
00479
00480 extern bfd_boolean NAME(aout,make_sections)
00481 PARAMS ((bfd *));
00482
00483 extern const bfd_target * NAME(aout,some_aout_object_p)
00484 PARAMS ((bfd *, struct internal_exec *, const bfd_target *(*) (bfd *)));
00485
00486 extern bfd_boolean NAME(aout,mkobject)
00487 PARAMS ((bfd *));
00488
00489 extern enum machine_type NAME(aout,machine_type)
00490 PARAMS ((enum bfd_architecture, unsigned long, bfd_boolean *));
00491
00492 extern bfd_boolean NAME(aout,set_arch_mach)
00493 PARAMS ((bfd *, enum bfd_architecture, unsigned long));
00494
00495 extern bfd_boolean NAME(aout,new_section_hook)
00496 PARAMS ((bfd *, asection *));
00497
00498 extern bfd_boolean NAME(aout,set_section_contents)
00499 PARAMS ((bfd *, sec_ptr, const PTR, file_ptr, bfd_size_type));
00500
00501 extern asymbol * NAME(aout,make_empty_symbol)
00502 PARAMS ((bfd *));
00503
00504 extern bfd_boolean NAME(aout,translate_symbol_table)
00505 PARAMS ((bfd *, aout_symbol_type *, struct external_nlist *, bfd_size_type,
00506 char *, bfd_size_type, bfd_boolean));
00507
00508 extern bfd_boolean NAME(aout,slurp_symbol_table)
00509 PARAMS ((bfd *));
00510
00511 extern bfd_boolean NAME(aout,write_syms)
00512 PARAMS ((bfd *));
00513
00514 extern void NAME(aout,reclaim_symbol_table)
00515 PARAMS ((bfd *));
00516
00517 extern long NAME(aout,get_symtab_upper_bound)
00518 PARAMS ((bfd *));
00519
00520 extern long NAME(aout,canonicalize_symtab)
00521 PARAMS ((bfd *, asymbol **));
00522
00523 extern void NAME(aout,swap_ext_reloc_in)
00524 PARAMS ((bfd *, struct reloc_ext_external *, arelent *, asymbol **,
00525 bfd_size_type));
00526 extern void NAME(aout,swap_std_reloc_in)
00527 PARAMS ((bfd *, struct reloc_std_external *, arelent *, asymbol **,
00528 bfd_size_type));
00529
00530 extern reloc_howto_type * NAME(aout,reloc_type_lookup)
00531 PARAMS ((bfd *, bfd_reloc_code_real_type));
00532
00533 extern bfd_boolean NAME(aout,slurp_reloc_table)
00534 PARAMS ((bfd *, sec_ptr, asymbol **));
00535
00536 extern long NAME(aout,canonicalize_reloc)
00537 PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
00538
00539 extern long NAME(aout,get_reloc_upper_bound)
00540 PARAMS ((bfd *, sec_ptr));
00541
00542 extern void NAME(aout,reclaim_reloc)
00543 PARAMS ((bfd *, sec_ptr));
00544
00545 extern alent * NAME(aout,get_lineno)
00546 PARAMS ((bfd *, asymbol *));
00547
00548 extern void NAME(aout,print_symbol)
00549 PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
00550
00551 extern void NAME(aout,get_symbol_info)
00552 PARAMS ((bfd *, asymbol *, symbol_info *));
00553
00554 extern bfd_boolean NAME(aout,find_nearest_line)
00555 PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
00556 const char **, unsigned int *));
00557
00558 extern long NAME(aout,read_minisymbols)
00559 PARAMS ((bfd *, bfd_boolean, PTR *, unsigned int *));
00560
00561 extern asymbol * NAME(aout,minisymbol_to_symbol)
00562 PARAMS ((bfd *, bfd_boolean, const PTR, asymbol *));
00563
00564 extern int NAME(aout,sizeof_headers)
00565 PARAMS ((bfd *, bfd_boolean));
00566
00567 extern bfd_boolean NAME(aout,adjust_sizes_and_vmas)
00568 PARAMS ((bfd *, bfd_size_type *, file_ptr *));
00569
00570 extern void NAME(aout,swap_exec_header_in)
00571 PARAMS ((bfd *, struct external_exec *, struct internal_exec *));
00572
00573 extern void NAME(aout,swap_exec_header_out)
00574 PARAMS ((bfd *, struct internal_exec *, struct external_exec *));
00575
00576 extern struct bfd_hash_entry * NAME(aout,link_hash_newfunc)
00577 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
00578
00579 extern bfd_boolean NAME(aout,link_hash_table_init)
00580 PARAMS ((struct aout_link_hash_table *, bfd *,
00581 struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
00582 struct bfd_hash_table *,
00583 const char *)));
00584
00585 extern struct bfd_link_hash_table * NAME(aout,link_hash_table_create)
00586 PARAMS ((bfd *));
00587
00588 extern bfd_boolean NAME(aout,link_add_symbols)
00589 PARAMS ((bfd *, struct bfd_link_info *));
00590
00591 extern bfd_boolean NAME(aout,final_link)
00592 PARAMS ((bfd *, struct bfd_link_info *,
00593 void (*) (bfd *, file_ptr *, file_ptr *, file_ptr *)));
00594
00595 extern bfd_boolean NAME(aout,bfd_free_cached_info)
00596 PARAMS ((bfd *));
00597
00598
00599
00600 #define aout_16_get_section_contents _bfd_generic_get_section_contents
00601
00602 #define aout_32_get_section_contents _bfd_generic_get_section_contents
00603
00604 #define aout_64_get_section_contents _bfd_generic_get_section_contents
00605 #ifndef NO_WRITE_HEADER_KLUDGE
00606 #define NO_WRITE_HEADER_KLUDGE 0
00607 #endif
00608
00609 #ifndef aout_32_bfd_is_local_label_name
00610 #define aout_32_bfd_is_local_label_name bfd_generic_is_local_label_name
00611 #endif
00612
00613 #ifndef aout_32_bfd_is_target_special_symbol
00614 #define aout_32_bfd_is_target_special_symbol \
00615 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
00616 #endif
00617
00618 #ifndef WRITE_HEADERS
00619 #define WRITE_HEADERS(abfd, execp) \
00620 { \
00621 bfd_size_type text_size; \
00622 file_ptr text_end; \
00623 if (adata(abfd).magic == undecided_magic) \
00624 NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end); \
00625 \
00626 execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE; \
00627 execp->a_entry = bfd_get_start_address (abfd); \
00628 \
00629 execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * \
00630 obj_reloc_entry_size (abfd)); \
00631 execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * \
00632 obj_reloc_entry_size (abfd)); \
00633 NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes); \
00634 \
00635 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 \
00636 || bfd_bwrite ((PTR) &exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE,\
00637 abfd) != EXEC_BYTES_SIZE) \
00638 return FALSE; \
00639 \
00640 \
00641 if (bfd_get_outsymbols (abfd) != (asymbol **) NULL \
00642 && bfd_get_symcount (abfd) != 0) \
00643 { \
00644 if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*execp)), SEEK_SET) != 0)\
00645 return FALSE; \
00646 \
00647 if (! NAME(aout,write_syms) (abfd)) \
00648 return FALSE; \
00649 } \
00650 \
00651 if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*execp)), SEEK_SET) != 0) \
00652 return FALSE; \
00653 if (!NAME(aout,squirt_out_relocs) (abfd, obj_textsec (abfd))) \
00654 return FALSE; \
00655 \
00656 if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*execp)), SEEK_SET) != 0) \
00657 return FALSE; \
00658 if (!NAME(aout,squirt_out_relocs) (abfd, obj_datasec (abfd))) \
00659 return FALSE; \
00660 }
00661 #endif
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672 #define aout_section_merge_with_text_p(abfd, sec) \
00673 (((sec)->flags & (SEC_HAS_CONTENTS | SEC_READONLY)) == \
00674 (SEC_HAS_CONTENTS | SEC_READONLY) \
00675 && obj_textsec (abfd) != NULL \
00676 && obj_datasec (abfd) != NULL \
00677 && (sec)->vma >= (obj_textsec (abfd)->vma + \
00678 obj_textsec (abfd)->size) \
00679 && ((sec)->vma + (sec)->size) <= obj_datasec (abfd)->vma \
00680 && ((abfd)->flags & D_PAGED) != 0)
00681
00682 #endif