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 #define N_SHARED_LIB(x) 0
00026
00027 #define TEXT_START_ADDR 0
00028 #define TARGET_PAGE_SIZE 4096
00029 #define SEGMENT_SIZE TARGET_PAGE_SIZE
00030 #define DEFAULT_ARCH bfd_arch_i386
00031
00032
00033
00034
00035 #define MY(OP) CONCAT2 (i386lynx_aout_,OP)
00036 #define TARGETNAME "a.out-i386-lynx"
00037
00038 #include "bfd.h"
00039 #include "sysdep.h"
00040 #include "libbfd.h"
00041
00042 #ifndef WRITE_HEADERS
00043 #define WRITE_HEADERS(abfd, execp) \
00044 { \
00045 bfd_size_type text_size; \
00046 file_ptr text_end; \
00047 if (adata(abfd).magic == undecided_magic) \
00048 NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end); \
00049 \
00050 execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE; \
00051 execp->a_entry = bfd_get_start_address (abfd); \
00052 \
00053 execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * \
00054 obj_reloc_entry_size (abfd)); \
00055 execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * \
00056 obj_reloc_entry_size (abfd)); \
00057 NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes); \
00058 \
00059 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 \
00060 || bfd_bwrite ((PTR) &exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, \
00061 abfd) != EXEC_BYTES_SIZE) \
00062 return FALSE; \
00063 \
00064 \
00065 if (bfd_get_symcount (abfd) != 0) \
00066 { \
00067 if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*execp)), SEEK_SET) \
00068 != 0) \
00069 return FALSE; \
00070 \
00071 if (! NAME(aout,write_syms) (abfd)) return FALSE; \
00072 \
00073 if (bfd_seek (abfd, (file_ptr) (N_TRELOFF(*execp)), SEEK_SET) \
00074 != 0) \
00075 return FALSE; \
00076 \
00077 if (!NAME(lynx,squirt_out_relocs) (abfd, obj_textsec (abfd))) \
00078 return FALSE; \
00079 if (bfd_seek (abfd, (file_ptr) (N_DRELOFF(*execp)), SEEK_SET) \
00080 != 0) \
00081 return 0; \
00082 \
00083 if (!NAME(lynx,squirt_out_relocs) (abfd, obj_datasec (abfd))) \
00084 return FALSE; \
00085 } \
00086 }
00087 #endif
00088
00089 #include "libaout.h"
00090 #include "aout/aout64.h"
00091
00092 void NAME (lynx,swap_std_reloc_out)
00093 PARAMS ((bfd *, arelent *, struct reloc_std_external *));
00094 void NAME (lynx,swap_ext_reloc_out)
00095 PARAMS ((bfd *, arelent *, struct reloc_ext_external *));
00096 void NAME (lynx,swap_ext_reloc_in)
00097 PARAMS ((bfd *, struct reloc_ext_external *, arelent *, asymbol **,
00098 bfd_size_type));
00099 void NAME (lynx,swap_std_reloc_in)
00100 PARAMS ((bfd *, struct reloc_std_external *, arelent *, asymbol **,
00101 bfd_size_type));
00102 bfd_boolean NAME (lynx,slurp_reloc_table)
00103 PARAMS ((bfd *, sec_ptr, asymbol **));
00104 bfd_boolean NAME (lynx,squirt_out_relocs)
00105 PARAMS ((bfd *, asection *));
00106 long NAME (lynx,canonicalize_reloc)
00107 PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
00108
00109 #ifdef LYNX_CORE
00110
00111 char *lynx_core_file_failing_command ();
00112 int lynx_core_file_failing_signal ();
00113 bfd_boolean lynx_core_file_matches_executable_p ();
00114 const bfd_target *lynx_core_file_p ();
00115
00116 #define MY_core_file_failing_command lynx_core_file_failing_command
00117 #define MY_core_file_failing_signal lynx_core_file_failing_signal
00118 #define MY_core_file_matches_executable_p lynx_core_file_matches_executable_p
00119 #define MY_core_file_p lynx_core_file_p
00120
00121 #endif
00122
00123
00124 #define KEEPIT udata.i
00125
00126 extern reloc_howto_type aout_32_ext_howto_table[];
00127 extern reloc_howto_type aout_32_std_howto_table[];
00128
00129
00130
00131
00132 void
00133 NAME(lynx,swap_std_reloc_out) (abfd, g, natptr)
00134 bfd *abfd;
00135 arelent *g;
00136 struct reloc_std_external *natptr;
00137 {
00138 int r_index;
00139 asymbol *sym = *(g->sym_ptr_ptr);
00140 int r_extern;
00141 unsigned int r_length;
00142 int r_pcrel;
00143 int r_baserel, r_jmptable, r_relative;
00144 unsigned int r_addend;
00145 asection *output_section = sym->section->output_section;
00146
00147 PUT_WORD (abfd, g->address, natptr->r_address);
00148
00149 r_length = g->howto->size;
00150 r_pcrel = (int) g->howto->pc_relative;
00151
00152 r_baserel = 0;
00153 r_jmptable = 0;
00154 r_relative = 0;
00155
00156 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 if (bfd_is_com_section (output_section)
00170 || bfd_is_abs_section (output_section)
00171 || bfd_is_und_section (output_section))
00172 {
00173 if (bfd_abs_section_ptr->symbol == sym)
00174 {
00175
00176
00177 r_index = 0;
00178 r_extern = 0;
00179 }
00180 else
00181 {
00182
00183 r_extern = 1;
00184 r_index = (*g->sym_ptr_ptr)->KEEPIT;
00185 }
00186 }
00187 else
00188 {
00189
00190 r_extern = 0;
00191 r_index = output_section->target_index;
00192 }
00193
00194
00195 if (bfd_header_big_endian (abfd))
00196 {
00197 natptr->r_index[0] = r_index >> 16;
00198 natptr->r_index[1] = r_index >> 8;
00199 natptr->r_index[2] = r_index;
00200 natptr->r_type[0] =
00201 (r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
00202 | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
00203 | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
00204 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
00205 | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
00206 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG);
00207 }
00208 else
00209 {
00210 natptr->r_index[2] = r_index >> 16;
00211 natptr->r_index[1] = r_index >> 8;
00212 natptr->r_index[0] = r_index;
00213 natptr->r_type[0] =
00214 (r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
00215 | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
00216 | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
00217 | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
00218 | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
00219 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE);
00220 }
00221 }
00222
00223
00224
00225
00226
00227 void
00228 NAME(lynx,swap_ext_reloc_out) (abfd, g, natptr)
00229 bfd *abfd;
00230 arelent *g;
00231 register struct reloc_ext_external *natptr;
00232 {
00233 int r_index;
00234 int r_extern;
00235 unsigned int r_type;
00236 unsigned int r_addend;
00237 asymbol *sym = *(g->sym_ptr_ptr);
00238 asection *output_section = sym->section->output_section;
00239
00240 PUT_WORD (abfd, g->address, natptr->r_address);
00241
00242 r_type = (unsigned int) g->howto->type;
00243
00244 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 if (bfd_is_com_section (output_section)
00256 || bfd_is_abs_section (output_section)
00257 || bfd_is_und_section (output_section))
00258 {
00259 if (bfd_abs_section_ptr->symbol == sym)
00260 {
00261
00262
00263 r_index = 0;
00264 r_extern = 0;
00265 }
00266 else
00267 {
00268 r_extern = 1;
00269 r_index = (*g->sym_ptr_ptr)->KEEPIT;
00270 }
00271 }
00272 else
00273 {
00274
00275 r_extern = 0;
00276 r_index = output_section->target_index;
00277 }
00278
00279
00280
00281 if (bfd_header_big_endian (abfd))
00282 {
00283 natptr->r_index[0] = r_index >> 16;
00284 natptr->r_index[1] = r_index >> 8;
00285 natptr->r_index[2] = r_index;
00286 natptr->r_type[0] =
00287 (r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
00288 | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG);
00289 }
00290 else
00291 {
00292 natptr->r_index[2] = r_index >> 16;
00293 natptr->r_index[1] = r_index >> 8;
00294 natptr->r_index[0] = r_index;
00295 natptr->r_type[0] =
00296 (r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
00297 | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
00298 }
00299
00300 PUT_WORD (abfd, r_addend, natptr->r_addend);
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 #define MOVE_ADDRESS(ad) \
00313 if (r_extern) { \
00314 \
00315 cache_ptr->sym_ptr_ptr = symbols + r_index; \
00316 cache_ptr->addend = ad; \
00317 } else { \
00318
00319 \
00320 switch (r_index) { \
00321 case N_TEXT: \
00322 case N_TEXT | N_EXT: \
00323 cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr; \
00324 cache_ptr->addend = ad - su->textsec->vma; \
00325 break; \
00326 case N_DATA: \
00327 case N_DATA | N_EXT: \
00328 cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr; \
00329 cache_ptr->addend = ad - su->datasec->vma; \
00330 break; \
00331 case N_BSS: \
00332 case N_BSS | N_EXT: \
00333 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr; \
00334 cache_ptr->addend = ad - su->bsssec->vma; \
00335 break; \
00336 default: \
00337 case N_ABS: \
00338 case N_ABS | N_EXT: \
00339 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
00340 cache_ptr->addend = ad; \
00341 break; \
00342 } \
00343 } \
00344
00345 void
00346 NAME(lynx,swap_ext_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
00347 bfd *abfd;
00348 struct reloc_ext_external *bytes;
00349 arelent *cache_ptr;
00350 asymbol **symbols;
00351 bfd_size_type symcount ATTRIBUTE_UNUSED;
00352 {
00353 int r_index;
00354 int r_extern;
00355 unsigned int r_type;
00356 struct aoutdata *su = &(abfd->tdata.aout_data->a);
00357
00358 cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
00359
00360 r_index = bytes->r_index[1];
00361 r_extern = (0 != (bytes->r_index[0] & RELOC_EXT_BITS_EXTERN_BIG));
00362 r_type = (bytes->r_index[0] & RELOC_EXT_BITS_TYPE_BIG)
00363 >> RELOC_EXT_BITS_TYPE_SH_BIG;
00364
00365 cache_ptr->howto = aout_32_ext_howto_table + r_type;
00366 MOVE_ADDRESS (GET_SWORD (abfd, bytes->r_addend));
00367 }
00368
00369 void
00370 NAME(lynx,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
00371 bfd *abfd;
00372 struct reloc_std_external *bytes;
00373 arelent *cache_ptr;
00374 asymbol **symbols;
00375 bfd_size_type symcount ATTRIBUTE_UNUSED;
00376 {
00377 int r_index;
00378 int r_extern;
00379 unsigned int r_length;
00380 int r_pcrel;
00381 int r_baserel, r_jmptable, r_relative;
00382 struct aoutdata *su = &(abfd->tdata.aout_data->a);
00383
00384 cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
00385
00386 r_index = bytes->r_index[1];
00387 r_extern = (0 != (bytes->r_index[0] & RELOC_STD_BITS_EXTERN_BIG));
00388 r_pcrel = (0 != (bytes->r_index[0] & RELOC_STD_BITS_PCREL_BIG));
00389 r_baserel = (0 != (bytes->r_index[0] & RELOC_STD_BITS_BASEREL_BIG));
00390 r_jmptable = (0 != (bytes->r_index[0] & RELOC_STD_BITS_JMPTABLE_BIG));
00391 r_relative = (0 != (bytes->r_index[0] & RELOC_STD_BITS_RELATIVE_BIG));
00392 r_length = (bytes->r_index[0] & RELOC_STD_BITS_LENGTH_BIG)
00393 >> RELOC_STD_BITS_LENGTH_SH_BIG;
00394
00395 cache_ptr->howto = aout_32_std_howto_table + r_length + 4 * r_pcrel;
00396
00397
00398 MOVE_ADDRESS (0);
00399 }
00400
00401
00402
00403 bfd_boolean
00404 NAME(lynx,slurp_reloc_table) (abfd, asect, symbols)
00405 bfd *abfd;
00406 sec_ptr asect;
00407 asymbol **symbols;
00408 {
00409 bfd_size_type count;
00410 bfd_size_type reloc_size;
00411 PTR relocs;
00412 arelent *reloc_cache;
00413 size_t each_size;
00414
00415 if (asect->relocation)
00416 return TRUE;
00417
00418 if (asect->flags & SEC_CONSTRUCTOR)
00419 return TRUE;
00420
00421 if (asect == obj_datasec (abfd))
00422 {
00423 reloc_size = exec_hdr (abfd)->a_drsize;
00424 goto doit;
00425 }
00426
00427 if (asect == obj_textsec (abfd))
00428 {
00429 reloc_size = exec_hdr (abfd)->a_trsize;
00430 goto doit;
00431 }
00432
00433 bfd_set_error (bfd_error_invalid_operation);
00434 return FALSE;
00435
00436 doit:
00437 if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
00438 return FALSE;
00439 each_size = obj_reloc_entry_size (abfd);
00440
00441 count = reloc_size / each_size;
00442
00443
00444 reloc_cache = (arelent *) bfd_zmalloc (count * sizeof (arelent));
00445 if (!reloc_cache && count != 0)
00446 return FALSE;
00447
00448 relocs = (PTR) bfd_alloc (abfd, reloc_size);
00449 if (!relocs && reloc_size != 0)
00450 {
00451 free (reloc_cache);
00452 return FALSE;
00453 }
00454
00455 if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
00456 {
00457 bfd_release (abfd, relocs);
00458 free (reloc_cache);
00459 return FALSE;
00460 }
00461
00462 if (each_size == RELOC_EXT_SIZE)
00463 {
00464 register struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;
00465 unsigned int counter = 0;
00466 arelent *cache_ptr = reloc_cache;
00467
00468 for (; counter < count; counter++, rptr++, cache_ptr++)
00469 {
00470 NAME(lynx,swap_ext_reloc_in) (abfd, rptr, cache_ptr, symbols,
00471 (bfd_size_type) bfd_get_symcount (abfd));
00472 }
00473 }
00474 else
00475 {
00476 register struct reloc_std_external *rptr = (struct reloc_std_external *) relocs;
00477 unsigned int counter = 0;
00478 arelent *cache_ptr = reloc_cache;
00479
00480 for (; counter < count; counter++, rptr++, cache_ptr++)
00481 {
00482 NAME(lynx,swap_std_reloc_in) (abfd, rptr, cache_ptr, symbols,
00483 (bfd_size_type) bfd_get_symcount (abfd));
00484 }
00485
00486 }
00487
00488 bfd_release (abfd, relocs);
00489 asect->relocation = reloc_cache;
00490 asect->reloc_count = count;
00491 return TRUE;
00492 }
00493
00494
00495
00496
00497
00498 bfd_boolean
00499 NAME(lynx,squirt_out_relocs) (abfd, section)
00500 bfd *abfd;
00501 asection *section;
00502 {
00503 arelent **generic;
00504 unsigned char *native, *natptr;
00505 size_t each_size;
00506
00507 unsigned int count = section->reloc_count;
00508 bfd_size_type natsize;
00509
00510 if (count == 0)
00511 return TRUE;
00512
00513 each_size = obj_reloc_entry_size (abfd);
00514 natsize = count;
00515 natsize *= each_size;
00516 native = (unsigned char *) bfd_zalloc (abfd, natsize);
00517 if (!native)
00518 return FALSE;
00519
00520 generic = section->orelocation;
00521
00522 if (each_size == RELOC_EXT_SIZE)
00523 {
00524 for (natptr = native;
00525 count != 0;
00526 --count, natptr += each_size, ++generic)
00527 NAME(lynx,swap_ext_reloc_out) (abfd, *generic, (struct reloc_ext_external *) natptr);
00528 }
00529 else
00530 {
00531 for (natptr = native;
00532 count != 0;
00533 --count, natptr += each_size, ++generic)
00534 NAME(lynx,swap_std_reloc_out) (abfd, *generic, (struct reloc_std_external *) natptr);
00535 }
00536
00537 if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize)
00538 {
00539 bfd_release (abfd, native);
00540 return FALSE;
00541 }
00542 bfd_release (abfd, native);
00543
00544 return TRUE;
00545 }
00546
00547
00548 long
00549 NAME(lynx,canonicalize_reloc) (abfd, section, relptr, symbols)
00550 bfd *abfd;
00551 sec_ptr section;
00552 arelent **relptr;
00553 asymbol **symbols;
00554 {
00555 arelent *tblptr = section->relocation;
00556 unsigned int count;
00557
00558 if (!(tblptr || NAME(lynx,slurp_reloc_table) (abfd, section, symbols)))
00559 return -1;
00560
00561 if (section->flags & SEC_CONSTRUCTOR)
00562 {
00563 arelent_chain *chain = section->constructor_chain;
00564 for (count = 0; count < section->reloc_count; count++)
00565 {
00566 *relptr++ = &chain->relent;
00567 chain = chain->next;
00568 }
00569 }
00570 else
00571 {
00572 tblptr = section->relocation;
00573
00574 for (count = 0; count++ < section->reloc_count;)
00575 {
00576 *relptr++ = tblptr++;
00577 }
00578 }
00579 *relptr = 0;
00580
00581 return section->reloc_count;
00582 }
00583
00584 #define MY_canonicalize_reloc NAME(lynx,canonicalize_reloc)
00585
00586 #include "aout-target.h"