home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / bfd / bout.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  41KB  |  1,399 lines

  1. /* BFD back-end for Intel 960 b.out binaries.
  2.    Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. #include "bfd.h"
  23. #include "sysdep.h"
  24. #include "libbfd.h"
  25. #include "bfdlink.h"
  26. #include "bout.h"
  27.  
  28. #include "aout/stab_gnu.h"
  29. #include "libaout.h"        /* BFD a.out internal data structures */
  30.  
  31.  
  32. static boolean b_out_squirt_out_relocs PARAMS ((bfd *abfd, asection *section));
  33. static bfd_target *b_out_callback PARAMS ((bfd *));
  34. static bfd_reloc_status_type calljx_callback
  35.   PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR src, PTR dst,
  36.        asection *));
  37. static bfd_reloc_status_type callj_callback
  38.   PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR data,
  39.        unsigned int srcidx, unsigned int dstidx, asection *));
  40. static bfd_vma get_value PARAMS ((arelent *, struct bfd_link_info *,
  41.                   asection *));
  42. static int abs32code PARAMS ((asection *, asymbol **, arelent *,
  43.                   unsigned int, struct bfd_link_info *));
  44. static boolean b_out_relax_section PARAMS ((bfd *, asection *,
  45.                         struct bfd_link_info *,
  46.                         asymbol **symbols));
  47. static bfd_byte *b_out_get_relocated_section_contents
  48.   PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
  49.        bfd_byte *, boolean, asymbol **));
  50.  
  51. /* Swaps the information in an executable header taken from a raw byte
  52.    stream memory image, into the internal exec_header structure.  */
  53.  
  54. void
  55. DEFUN(bout_swap_exec_header_in,(abfd, raw_bytes, execp),
  56.       bfd *abfd AND
  57.       struct external_exec *raw_bytes AND
  58.       struct internal_exec *execp)
  59. {
  60.   struct external_exec *bytes = (struct external_exec *)raw_bytes;
  61.  
  62.   /* Now fill in fields in the execp, from the bytes in the raw data.  */
  63.   execp->a_info   = bfd_h_get_32 (abfd, bytes->e_info);
  64.   execp->a_text   = GET_WORD (abfd, bytes->e_text);
  65.   execp->a_data   = GET_WORD (abfd, bytes->e_data);
  66.   execp->a_bss    = GET_WORD (abfd, bytes->e_bss);
  67.   execp->a_syms   = GET_WORD (abfd, bytes->e_syms);
  68.   execp->a_entry  = GET_WORD (abfd, bytes->e_entry);
  69.   execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
  70.   execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
  71.   execp->a_tload  = GET_WORD (abfd, bytes->e_tload);
  72.   execp->a_dload  = GET_WORD (abfd, bytes->e_dload);
  73.   execp->a_talign = bytes->e_talign[0];
  74.   execp->a_dalign = bytes->e_dalign[0];
  75.   execp->a_balign = bytes->e_balign[0];
  76.   execp->a_relaxable = bytes->e_relaxable[0];
  77. }
  78.  
  79. /* Swaps the information in an internal exec header structure into the
  80.    supplied buffer ready for writing to disk.  */
  81.  
  82. PROTO(void, bout_swap_exec_header_out,
  83.       (bfd *abfd,
  84.        struct internal_exec *execp,
  85.        struct external_exec *raw_bytes));
  86. void
  87. DEFUN(bout_swap_exec_header_out,(abfd, execp, raw_bytes),
  88.      bfd *abfd AND
  89.      struct internal_exec *execp AND 
  90.      struct external_exec *raw_bytes)
  91. {
  92.   struct external_exec *bytes = (struct external_exec *)raw_bytes;
  93.  
  94.   /* Now fill in fields in the raw data, from the fields in the exec struct. */
  95.   bfd_h_put_32 (abfd, execp->a_info  , bytes->e_info);
  96.   PUT_WORD (abfd, execp->a_text  , bytes->e_text);
  97.   PUT_WORD (abfd, execp->a_data  , bytes->e_data);
  98.   PUT_WORD (abfd, execp->a_bss   , bytes->e_bss);
  99.   PUT_WORD (abfd, execp->a_syms  , bytes->e_syms);
  100.   PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
  101.   PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
  102.   PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
  103.   PUT_WORD (abfd, execp->a_tload , bytes->e_tload);
  104.   PUT_WORD (abfd, execp->a_dload , bytes->e_dload);
  105.   bytes->e_talign[0] = execp->a_talign;
  106.   bytes->e_dalign[0] = execp->a_dalign;
  107.   bytes->e_balign[0] = execp->a_balign;
  108.   bytes->e_relaxable[0] = execp->a_relaxable;
  109. }
  110.  
  111.  
  112. static bfd_target *
  113. b_out_object_p (abfd)
  114.      bfd *abfd;
  115. {
  116.   struct internal_exec anexec;
  117.   struct external_exec exec_bytes;
  118.  
  119.   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
  120.       != EXEC_BYTES_SIZE) {
  121.     bfd_error = wrong_format;
  122.     return 0;
  123.   }
  124.  
  125.   anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
  126.  
  127.   if (N_BADMAG (anexec)) {
  128.     bfd_error = wrong_format;
  129.     return 0;
  130.   }
  131.  
  132.   bout_swap_exec_header_in (abfd, &exec_bytes, &anexec);
  133.   return aout_32_some_aout_object_p (abfd, &anexec, b_out_callback);
  134. }
  135.  
  136.  
  137. /* Finish up the opening of a b.out file for reading.  Fill in all the
  138.    fields that are not handled by common code.  */
  139.  
  140. static bfd_target *
  141. b_out_callback (abfd)
  142.      bfd *abfd;
  143. {
  144.   struct internal_exec *execp = exec_hdr (abfd);
  145.   unsigned long bss_start;
  146.  
  147.   /* Architecture and machine type */
  148.   bfd_set_arch_mach(abfd, 
  149.             bfd_arch_i960, /* B.out only used on i960 */
  150.             bfd_mach_i960_core /* Default */
  151.             );
  152.  
  153.   /* The positions of the string table and symbol table.  */
  154.   obj_str_filepos (abfd) = N_STROFF (*execp);
  155.   obj_sym_filepos (abfd) = N_SYMOFF (*execp);
  156.  
  157.   /* The alignments of the sections */
  158.   obj_textsec (abfd)->alignment_power = execp->a_talign;
  159.   obj_datasec (abfd)->alignment_power = execp->a_dalign;
  160.   obj_bsssec  (abfd)->alignment_power = execp->a_balign;
  161.  
  162.   /* The starting addresses of the sections.  */
  163.   obj_textsec (abfd)->vma = execp->a_tload;
  164.   obj_datasec (abfd)->vma = execp->a_dload;
  165.  
  166.   /* And reload the sizes, since the aout module zaps them */
  167.   obj_textsec (abfd)->_raw_size = execp->a_text;
  168.  
  169.   bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section */
  170.   obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
  171.  
  172.   /* The file positions of the sections */
  173.   obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
  174.   obj_datasec (abfd)->filepos = N_DATOFF(*execp);
  175.  
  176.   /* The file positions of the relocation info */
  177.   obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
  178.   obj_datasec (abfd)->rel_filepos =  N_DROFF(*execp);
  179.  
  180.   adata(abfd).page_size = 1;    /* Not applicable. */
  181.   adata(abfd).segment_size = 1; /* Not applicable. */
  182.   adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
  183.  
  184.   if (execp->a_relaxable)
  185.    abfd->flags |= BFD_IS_RELAXABLE;
  186.   return abfd->xvec;
  187. }
  188.  
  189. struct bout_data_struct {
  190.     struct aoutdata a;
  191.     struct internal_exec e;
  192. };
  193.  
  194. static boolean
  195. b_out_mkobject (abfd)
  196.      bfd *abfd;
  197. {
  198.   struct bout_data_struct *rawptr;
  199.  
  200.   rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct));
  201.   if (rawptr == NULL) {
  202.       bfd_error = no_memory;
  203.       return false;
  204.     }
  205.  
  206.   abfd->tdata.bout_data = rawptr;
  207.   exec_hdr (abfd) = &rawptr->e;
  208.  
  209.   /* For simplicity's sake we just make all the sections right here. */
  210.   obj_textsec (abfd) = (asection *)NULL;
  211.   obj_datasec (abfd) = (asection *)NULL;
  212.   obj_bsssec (abfd) = (asection *)NULL;
  213.  
  214.   bfd_make_section (abfd, ".text");
  215.   bfd_make_section (abfd, ".data");
  216.   bfd_make_section (abfd, ".bss");
  217.  
  218.   return true;
  219. }
  220.  
  221. static boolean
  222. b_out_write_object_contents (abfd)
  223.      bfd *abfd;
  224. {
  225.   struct external_exec swapped_hdr;
  226.  
  227.   exec_hdr (abfd)->a_info = BMAGIC;
  228.  
  229.   exec_hdr (abfd)->a_text = obj_textsec (abfd)->_raw_size;
  230.   exec_hdr (abfd)->a_data = obj_datasec (abfd)->_raw_size;
  231.   exec_hdr (abfd)->a_bss = obj_bsssec (abfd)->_raw_size;
  232.   exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd) * sizeof (struct nlist);
  233.   exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
  234.   exec_hdr (abfd)->a_trsize = ((obj_textsec (abfd)->reloc_count) *
  235.                                sizeof (struct relocation_info));
  236.   exec_hdr (abfd)->a_drsize = ((obj_datasec (abfd)->reloc_count) *
  237.                                sizeof (struct relocation_info));
  238.  
  239.   exec_hdr (abfd)->a_talign = obj_textsec (abfd)->alignment_power;
  240.   exec_hdr (abfd)->a_dalign = obj_datasec (abfd)->alignment_power;
  241.   exec_hdr (abfd)->a_balign = obj_bsssec (abfd)->alignment_power;
  242.  
  243.   exec_hdr (abfd)->a_tload = obj_textsec (abfd)->vma;
  244.   exec_hdr (abfd)->a_dload = obj_datasec (abfd)->vma;
  245.  
  246.   bout_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
  247.  
  248.   bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
  249.   bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd);
  250.  
  251.   /* Now write out reloc info, followed by syms and strings */
  252.   if (bfd_get_symcount (abfd) != 0) 
  253.     {
  254.       bfd_seek (abfd, (file_ptr)(N_SYMOFF(*exec_hdr(abfd))), SEEK_SET);
  255.  
  256.       if (! aout_32_write_syms (abfd))
  257.     return false;
  258.  
  259.       bfd_seek (abfd, (file_ptr)(N_TROFF(*exec_hdr(abfd))), SEEK_SET);
  260.  
  261.       if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd))) return false;
  262.       bfd_seek (abfd, (file_ptr)(N_DROFF(*exec_hdr(abfd))), SEEK_SET);
  263.  
  264.       if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd))) return false;
  265.     }
  266.   return true;
  267. }
  268.  
  269. /** Some reloc hackery */
  270.  
  271. #define CALLS     0x66003800    /* Template for 'calls' instruction    */
  272. #define BAL     0x0b000000    /* Template for 'bal' instruction */
  273. #define BALX     0x85000000    /* Template for 'balx' instruction    */
  274. #define BAL_MASK 0x00ffffff
  275. #define CALL     0x09000000
  276. #define PCREL13_MASK 0x1fff
  277. /* Magic to turn callx into calljx */
  278. static bfd_reloc_status_type 
  279. calljx_callback (abfd, link_info, reloc_entry, src, dst, input_section)
  280.      bfd *abfd;
  281.      struct bfd_link_info *link_info;
  282.      arelent *reloc_entry;
  283.      PTR src;
  284.      PTR dst;
  285.      asection *input_section;
  286. {
  287.   int  word = bfd_get_32(abfd, src);
  288.   asymbol *symbol_in = *(reloc_entry->sym_ptr_ptr);
  289.   aout_symbol_type  *symbol = aout_symbol(symbol_in);
  290.  
  291.   if (symbol_in->section == &bfd_und_section)
  292.     {
  293.       if (! ((*link_info->callbacks->undefined_symbol)
  294.          (link_info, bfd_asymbol_name (symbol_in),
  295.           input_section->owner, input_section, reloc_entry->address)))
  296.     abort ();
  297.     }
  298.  
  299.   if (IS_CALLNAME(symbol->other)) 
  300.   {
  301.  
  302.     aout_symbol_type *balsym = symbol+1;
  303.     int inst = bfd_get_32(abfd, (bfd_byte *) src-4);
  304.     /* The next symbol should be an N_BALNAME */
  305.     BFD_ASSERT(IS_BALNAME(balsym->other));
  306.     inst &= BAL_MASK;
  307.     inst |= BALX;
  308.     bfd_put_32(abfd, inst, (bfd_byte *) dst-4);
  309.     symbol = balsym;
  310.   }
  311.  
  312.     word += symbol->symbol.section->output_offset +
  313.      symbol->symbol.section->output_section->vma +
  314.       symbol->symbol.value + reloc_entry->addend;
  315.  
  316.   bfd_put_32(abfd, word, dst);
  317.   return bfd_reloc_ok;
  318. }
  319.  
  320.  
  321. /* Magic to turn call into callj */
  322. static bfd_reloc_status_type 
  323. callj_callback (abfd, link_info, reloc_entry,  data, srcidx, dstidx,
  324.         input_section)
  325.      bfd *abfd;
  326.      struct bfd_link_info *link_info;
  327.      arelent *reloc_entry;
  328.      PTR data;
  329.      unsigned int srcidx;
  330.      unsigned int dstidx;
  331.      asection *input_section;
  332. {
  333.   int  word = bfd_get_32(abfd, (bfd_byte *) data + srcidx);
  334.   asymbol *symbol_in = *(reloc_entry->sym_ptr_ptr);
  335.  
  336.   aout_symbol_type  *symbol = aout_symbol(symbol_in);
  337.  
  338.   if (symbol_in->section == &bfd_und_section)
  339.     {
  340.       if (! ((*link_info->callbacks->undefined_symbol)
  341.          (link_info, bfd_asymbol_name (symbol_in),
  342.           input_section->owner, input_section, reloc_entry->address)))
  343.     abort ();
  344.     }
  345.  
  346.   if (IS_OTHER(symbol->other)) 
  347.   {
  348.     /* Call to a system procedure - replace code with system
  349.        procedure number */
  350.     word = CALLS | (symbol->other - 1);
  351.  
  352.   }
  353.  
  354.   else  if (IS_CALLNAME(symbol->other)) 
  355.   {
  356.     aout_symbol_type *balsym = symbol+1;
  357.     /* The next symbol should be an N_BALNAME */
  358.     BFD_ASSERT(IS_BALNAME(balsym->other));
  359.  
  360.     /* We are calling a leaf - so replace the call instruction
  361.        with a bal */
  362.  
  363.     word = BAL |
  364.      (((word & BAL_MASK) +
  365.        balsym->symbol.section->output_offset +
  366.        balsym->symbol.section->output_section->vma+
  367.        balsym->symbol.value + reloc_entry->addend - dstidx -
  368.        ( input_section->output_section->vma + input_section->output_offset))
  369.       & BAL_MASK);
  370.  
  371.  
  372.   }
  373.   else 
  374.   {
  375.  
  376.     word = CALL |
  377.      (((word & BAL_MASK) + 
  378.        symbol->symbol.section->output_offset +
  379.        symbol->symbol.section->output_section->vma+
  380.        symbol->symbol.value + reloc_entry->addend - dstidx -
  381.        ( input_section->output_section->vma + input_section->output_offset))
  382.       & BAL_MASK);
  383.   }
  384.   bfd_put_32(abfd, word, (bfd_byte *) data + dstidx);
  385.   return bfd_reloc_ok;
  386. }
  387.  
  388. /* type rshift size  bitsize      pcrel    bitpos  absolute overflow check*/
  389.  
  390. #define ABS32CODE 0
  391. #define ABS32CODE_SHRUNK 1 
  392. #define PCREL24 2
  393. #define CALLJ 3
  394. #define ABS32 4
  395. #define PCREL13 5
  396. #define ABS32_MAYBE_RELAXABLE 1
  397. #define ABS32_WAS_RELAXABLE 2
  398.  
  399. #define ALIGNER 10
  400. #define ALIGNDONE 11
  401. static reloc_howto_type howto_reloc_callj =
  402. HOWTO(CALLJ, 0, 2, 24, true, 0, complain_overflow_signed, 0,"callj", true, 0x00ffffff, 0x00ffffff,false);
  403. static  reloc_howto_type howto_reloc_abs32 =
  404. HOWTO(ABS32, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"abs32", true, 0xffffffff,0xffffffff,false);
  405. static reloc_howto_type howto_reloc_pcrel24 =
  406. HOWTO(PCREL24, 0, 2, 24, true, 0, complain_overflow_signed,0,"pcrel24", true, 0x00ffffff,0x00ffffff,false);
  407.  
  408. static reloc_howto_type howto_reloc_pcrel13 =
  409. HOWTO(PCREL13, 0, 2, 13, true, 0, complain_overflow_signed,0,"pcrel13", true, 0x00001fff,0x00001fff,false);
  410.  
  411.  
  412. static reloc_howto_type howto_reloc_abs32codeshrunk = 
  413. HOWTO(ABS32CODE_SHRUNK, 0, 2, 24, true, 0, complain_overflow_signed, 0,"callx->callj", true, 0x00ffffff, 0x00ffffff,false);
  414.  
  415. static  reloc_howto_type howto_reloc_abs32code =
  416. HOWTO(ABS32CODE, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"callx", true, 0xffffffff,0xffffffff,false);
  417.  
  418. static reloc_howto_type howto_align_table[] = {
  419.   HOWTO (ALIGNER, 0, 0x1, 0, false, 0, complain_overflow_dont, 0, "align16", false, 0, 0, false),
  420.   HOWTO (ALIGNER, 0, 0x3, 0, false, 0, complain_overflow_dont, 0, "align32", false, 0, 0, false),
  421.   HOWTO (ALIGNER, 0, 0x7, 0, false, 0, complain_overflow_dont, 0, "align64", false, 0, 0, false),
  422.   HOWTO (ALIGNER, 0, 0xf, 0, false, 0, complain_overflow_dont, 0, "align128", false, 0, 0, false),
  423. };
  424.  
  425. static reloc_howto_type howto_done_align_table[] = {
  426.   HOWTO (ALIGNDONE, 0x1, 0x1, 0, false, 0, complain_overflow_dont, 0, "donealign16", false, 0, 0, false),
  427.   HOWTO (ALIGNDONE, 0x3, 0x3, 0, false, 0, complain_overflow_dont, 0, "donealign32", false, 0, 0, false),
  428.   HOWTO (ALIGNDONE, 0x7, 0x7, 0, false, 0, complain_overflow_dont, 0, "donealign64", false, 0, 0, false),
  429.   HOWTO (ALIGNDONE, 0xf, 0xf, 0, false, 0, complain_overflow_dont, 0, "donealign128", false, 0, 0, false),
  430. };
  431.  
  432. static const reloc_howto_type *
  433. b_out_reloc_type_lookup (abfd, code)
  434.      bfd *abfd;
  435.      bfd_reloc_code_real_type code;
  436. {
  437.   switch (code)
  438.     {
  439.     default:
  440.       return 0;
  441.     case BFD_RELOC_I960_CALLJ:
  442.       return &howto_reloc_callj;
  443.     case BFD_RELOC_32:
  444.       return &howto_reloc_abs32;
  445.     case BFD_RELOC_24_PCREL:
  446.       return &howto_reloc_pcrel24;
  447.     }
  448. }
  449.  
  450. /* Allocate enough room for all the reloc entries, plus pointers to them all */
  451.  
  452. static boolean
  453. b_out_slurp_reloc_table (abfd, asect, symbols)
  454.      bfd *abfd;
  455.      sec_ptr asect;
  456.      asymbol **symbols;
  457. {
  458.   register struct relocation_info *rptr;
  459.   unsigned int counter ;
  460.   arelent *cache_ptr ;
  461.   int extern_mask, pcrel_mask, callj_mask, length_shift;
  462.   int incode_mask;
  463.   int size_mask;
  464.   bfd_vma prev_addr = 0;
  465.   unsigned int count;
  466.   size_t  reloc_size;
  467.   struct relocation_info *relocs;
  468.   arelent *reloc_cache;
  469.  
  470.   if (asect->relocation) return true;
  471.   if (!aout_32_slurp_symbol_table (abfd)) return false;
  472.  
  473.   if (asect == obj_datasec (abfd)) {
  474.     reloc_size = exec_hdr(abfd)->a_drsize;
  475.     goto doit;
  476.   }
  477.  
  478.   if (asect == obj_textsec (abfd)) {
  479.     reloc_size = exec_hdr(abfd)->a_trsize;
  480.     goto doit;
  481.   }
  482.  
  483.   bfd_error = invalid_operation;
  484.   return false;
  485.  
  486.  doit:
  487.   bfd_seek (abfd, (file_ptr)(asect->rel_filepos),  SEEK_SET);
  488.   count = reloc_size / sizeof (struct relocation_info);
  489.  
  490.   relocs = (struct relocation_info *) bfd_xmalloc (reloc_size);
  491.   if (!relocs) {
  492.     bfd_error = no_memory;
  493.     return false;
  494.   }
  495.   reloc_cache = (arelent *) bfd_xmalloc ((count+1) * sizeof (arelent));
  496.   if (!reloc_cache) {
  497.     free ((char*)relocs);
  498.     bfd_error = no_memory;
  499.     return false;
  500.   }
  501.  
  502.   if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) {
  503.     bfd_error = system_call_error;
  504.     free (reloc_cache);
  505.     free (relocs);
  506.     return false;
  507.   }
  508.  
  509.  
  510.   
  511.   if (abfd->xvec->header_byteorder_big_p) {
  512.     /* big-endian bit field allocation order */
  513.     pcrel_mask  = 0x80;
  514.     extern_mask = 0x10;
  515.     incode_mask = 0x08;
  516.     callj_mask  = 0x02;
  517.     size_mask =   0x20;
  518.     length_shift = 5;
  519.   } else {
  520.     /* little-endian bit field allocation order */
  521.     pcrel_mask  = 0x01;
  522.     extern_mask = 0x08;
  523.     incode_mask = 0x10;
  524.     callj_mask  = 0x40;
  525.     size_mask   = 0x02;
  526.     length_shift = 1;
  527.   }
  528.  
  529.   for (rptr = relocs, cache_ptr = reloc_cache, counter = 0;
  530.        counter < count;
  531.        counter++, rptr++, cache_ptr++) 
  532.   {
  533.     unsigned char *raw = (unsigned char *)rptr;
  534.     unsigned int symnum;
  535.     cache_ptr->address = bfd_h_get_32 (abfd, raw + 0);
  536.     cache_ptr->howto = 0;
  537.     if (abfd->xvec->header_byteorder_big_p) 
  538.     {
  539.       symnum = (raw[4] << 16) | (raw[5] << 8) | raw[6];
  540.     } 
  541.     else
  542.     {
  543.       symnum = (raw[6] << 16) | (raw[5] << 8) | raw[4];
  544.     }
  545.  
  546.     if (raw[7] & extern_mask) 
  547.     {
  548.       /* if this is set then the r_index is a index into the symbol table;
  549.        * if the bit is not set then r_index contains a section map.
  550.        * we either fill in the sym entry with a pointer to the symbol,
  551.        * or point to the correct section
  552.        */
  553.       cache_ptr->sym_ptr_ptr = symbols + symnum;
  554.       cache_ptr->addend = 0;
  555.     } else 
  556.     {
  557.       /* in a.out symbols are relative to the beginning of the
  558.        * file rather than sections ?
  559.        * (look in translate_from_native_sym_flags)
  560.        * the reloc entry addend has added to it the offset into the
  561.        * file of the data, so subtract the base to make the reloc
  562.        * section relative */
  563.       int s;
  564.       {
  565.     /* sign-extend symnum from 24 bits to whatever host uses */
  566.     s = symnum;
  567.     if (s & (1 << 23))
  568.       s |= (~0) << 24;
  569.       }
  570.       cache_ptr->sym_ptr_ptr = (asymbol **)NULL;
  571.       switch (s)
  572.       {
  573.        case N_TEXT:
  574.        case N_TEXT | N_EXT:
  575.     cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr;
  576.     cache_ptr->addend = - obj_textsec(abfd)->vma;
  577.     break;
  578.        case N_DATA:
  579.        case N_DATA | N_EXT:
  580.     cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr;
  581.     cache_ptr->addend = - obj_datasec(abfd)->vma;
  582.     break;
  583.        case N_BSS:
  584.        case N_BSS | N_EXT:
  585.     cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
  586.     cache_ptr->addend =  - obj_bsssec(abfd)->vma;
  587.     break;
  588.        case N_ABS:
  589.        case N_ABS | N_EXT:
  590.     cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
  591.     cache_ptr->addend = 0;
  592.     break;
  593.       case -2: /* .align */
  594.     if (raw[7] & pcrel_mask)
  595.       {
  596.         cache_ptr->howto = &howto_align_table[(raw[7] >> length_shift) & 3];
  597.         cache_ptr->sym_ptr_ptr = &bfd_abs_symbol;
  598.       }
  599.     else
  600.       {
  601.         /* .org? */
  602.         abort ();
  603.       }
  604.     cache_ptr->addend = 0;
  605.     break;
  606.        default:
  607.     BFD_ASSERT(0);
  608.     break;
  609.       }
  610.     
  611.     }
  612.  
  613.     /* the i960 only has a few relocation types:
  614.        abs 32-bit and pcrel 24bit.   except for callj's!  */
  615.     if (cache_ptr->howto != 0)
  616.       ;
  617.     else if (raw[7] & callj_mask)
  618.     {
  619.       cache_ptr->howto = &howto_reloc_callj;
  620.     }
  621.     else if ( raw[7] & pcrel_mask)
  622.     {
  623.       if (raw[7] & size_mask)
  624.        cache_ptr->howto = &howto_reloc_pcrel13;
  625.       else
  626.        cache_ptr->howto = &howto_reloc_pcrel24;
  627.     }
  628.     else 
  629.     {
  630.       if (raw[7] & incode_mask) 
  631.       {
  632.     cache_ptr->howto = &howto_reloc_abs32code;
  633.       }
  634.       else 
  635.       {
  636.     cache_ptr->howto = &howto_reloc_abs32;
  637.       }
  638.     }
  639.     if (cache_ptr->address < prev_addr) 
  640.     {
  641.       /* Ouch! this reloc is out of order, insert into the right place
  642.        */
  643.       arelent tmp;
  644.       arelent *cursor = cache_ptr-1;
  645.       bfd_vma stop = cache_ptr->address;
  646.       tmp  = *cache_ptr;
  647.       while (cursor->address > stop && cursor >= reloc_cache)
  648.       {
  649.     cursor[1] = cursor[0];
  650.     cursor--;
  651.       } 
  652.       cursor[1] = tmp;
  653.     }
  654.     else 
  655.     {
  656.       prev_addr = cache_ptr->address;
  657.     }
  658.   }
  659.  
  660.  
  661.   free (relocs);
  662.   asect->relocation = reloc_cache;
  663.   asect->reloc_count = count;
  664.  
  665.  
  666.   return true;
  667. }
  668.  
  669.  
  670. static boolean
  671. b_out_squirt_out_relocs (abfd, section)
  672.      bfd *abfd;
  673.      asection *section;
  674. {
  675.  
  676.   arelent **generic;
  677.   int r_extern = 0;
  678.   int r_idx;
  679.   int incode_mask;  
  680.   int len_1;
  681.   unsigned int count = section->reloc_count;
  682.   struct relocation_info *native, *natptr;
  683.   size_t natsize = count * sizeof (struct relocation_info);
  684.   int extern_mask, pcrel_mask,  len_2, callj_mask;
  685.   if (count == 0) return true;
  686.   generic   = section->orelocation;
  687.   native = ((struct relocation_info *) bfd_xmalloc (natsize));
  688.   if (!native) {
  689.     bfd_error = no_memory;
  690.     return false;
  691.   }
  692.  
  693.   if (abfd->xvec->header_byteorder_big_p) 
  694.   {
  695.     /* Big-endian bit field allocation order */
  696.     pcrel_mask  = 0x80;
  697.     extern_mask = 0x10;
  698.     len_2       = 0x40;
  699.     len_1       = 0x20;
  700.     callj_mask  = 0x02;
  701.     incode_mask = 0x08;
  702.   } 
  703.   else 
  704.   {
  705.     /* Little-endian bit field allocation order */
  706.     pcrel_mask  = 0x01;
  707.     extern_mask = 0x08;
  708.     len_2       = 0x04;
  709.     len_1       = 0x02;
  710.     callj_mask  = 0x40;
  711.     incode_mask = 0x10;
  712.   }
  713.  
  714.   for (natptr = native; count > 0; --count, ++natptr, ++generic) 
  715.   {
  716.     arelent *g = *generic;
  717.     unsigned char *raw = (unsigned char *)natptr;
  718.     asymbol *sym = *(g->sym_ptr_ptr);
  719.  
  720.     asection *output_section = sym->section->output_section;
  721.  
  722.     bfd_h_put_32(abfd, g->address, raw);  
  723.     /* Find a type in the output format which matches the input howto - 
  724.      * at the moment we assume input format == output format FIXME!!
  725.      */
  726.     r_idx = 0;
  727.     /* FIXME:  Need callj stuff here, and to check the howto entries to
  728.        be sure they are real for this architecture.  */
  729.     if (g->howto== &howto_reloc_callj) 
  730.     {
  731.       raw[7] = callj_mask + pcrel_mask + len_2;
  732.     }
  733.     else if (g->howto == &howto_reloc_pcrel24) 
  734.     {
  735.       raw[7] = pcrel_mask + len_2;
  736.     }
  737.     else if (g->howto == &howto_reloc_pcrel13) 
  738.     {
  739.       raw[7] = pcrel_mask + len_1;
  740.     }
  741.     else if (g->howto == &howto_reloc_abs32code) 
  742.     {
  743.       raw[7] = len_2 + incode_mask;
  744.     }
  745.     else if (g->howto >= howto_align_table
  746.          && g->howto <= (howto_align_table
  747.                 + sizeof (howto_align_table) / sizeof (howto_align_table[0])
  748.                 - 1))
  749.       {
  750.     /* symnum == -2; extern_mask not set, pcrel_mask set */
  751.     r_idx = -2;
  752.     r_extern = 0;
  753.     raw[7] = (pcrel_mask
  754.           | ((g->howto - howto_align_table) << 1));
  755.       }
  756.     else {
  757.       raw[7] = len_2;
  758.     }
  759.  
  760.     if (r_idx != 0)
  761.       /* already mucked with r_extern, r_idx */;
  762.     else if (bfd_is_com_section (output_section)
  763.          || output_section == &bfd_abs_section
  764.          || output_section == &bfd_und_section) 
  765.     {
  766.  
  767.       if (bfd_abs_section.symbol == sym)
  768.       {
  769.     /* Whoops, looked like an abs symbol, but is really an offset
  770.        from the abs section */
  771.     r_idx = 0;
  772.     r_extern = 0;
  773.        }
  774.       else 
  775.       {
  776.     /* Fill in symbol */
  777.  
  778.     r_extern = 1;
  779.     r_idx =  stoi((*(g->sym_ptr_ptr))->flags);
  780.       }
  781.     }
  782.     else 
  783.     {
  784.       /* Just an ordinary section */
  785.       r_extern = 0;
  786.       r_idx  = output_section->target_index;      
  787.     }
  788.  
  789.     if (abfd->xvec->header_byteorder_big_p) {
  790.       raw[4] = (unsigned char) (r_idx >> 16);
  791.       raw[5] = (unsigned char) (r_idx >>  8);
  792.       raw[6] = (unsigned char) (r_idx     );
  793.     } else {
  794.       raw[6] = (unsigned char) (r_idx >> 16);
  795.       raw[5] = (unsigned char) (r_idx>>  8);
  796.       raw[4] = (unsigned char) (r_idx     );
  797.     }  
  798.     if (r_extern)
  799.      raw[7] |= extern_mask; 
  800.   }
  801.  
  802.   if (bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
  803.     free((PTR)native);
  804.     return false;
  805.   }
  806.   free ((PTR)native);
  807.  
  808.   return true;
  809. }
  810.  
  811. /* This is stupid.  This function should be a boolean predicate */
  812. static unsigned int
  813. b_out_canonicalize_reloc (abfd, section, relptr, symbols)
  814.      bfd *abfd;
  815.      sec_ptr section;
  816.      arelent **relptr;
  817.      asymbol **symbols;
  818. {
  819.   arelent *tblptr = section->relocation;
  820.   unsigned int count = 0;
  821.  
  822.  if (!(tblptr || b_out_slurp_reloc_table (abfd, section, symbols))) return 0;
  823.   tblptr = section->relocation;
  824.  if (!tblptr) return 0;
  825.  
  826.   for (; count++ < section->reloc_count;)
  827.     *relptr++ = tblptr++;
  828.  
  829.   *relptr = 0;
  830.  
  831.   return section->reloc_count;
  832. }
  833.  
  834. static unsigned int
  835. b_out_get_reloc_upper_bound (abfd, asect)
  836.      bfd *abfd;
  837.      sec_ptr asect;
  838. {
  839.   if (bfd_get_format (abfd) != bfd_object) {
  840.     bfd_error = invalid_operation;
  841.     return 0;
  842.   }
  843.  
  844.   if (asect == obj_datasec (abfd))
  845.     return (sizeof (arelent *) *
  846.         ((exec_hdr(abfd)->a_drsize / sizeof (struct relocation_info))
  847.          +1));
  848.  
  849.   if (asect == obj_textsec (abfd))
  850.     return (sizeof (arelent *) *
  851.         ((exec_hdr(abfd)->a_trsize / sizeof (struct relocation_info))
  852.          +1));
  853.  
  854.   bfd_error = invalid_operation;
  855.   return 0;
  856. }
  857.  
  858. static boolean
  859. b_out_set_section_contents (abfd, section, location, offset, count)
  860.      bfd *abfd;
  861.      sec_ptr section;
  862.      unsigned char *location;
  863.      file_ptr offset;
  864.       int count;
  865. {
  866.  
  867.   if (abfd->output_has_begun == false) { /* set by bfd.c handler */
  868.     if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) /*||
  869.         (obj_textsec (abfd)->_cooked_size == 0) || (obj_datasec (abfd)->_cooked_size == 0)*/) {
  870.       bfd_error = invalid_operation;
  871.       return false;
  872.     }
  873.  
  874.     obj_textsec (abfd)->filepos = sizeof(struct internal_exec);
  875.     obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos 
  876.                                  +  obj_textsec (abfd)->_raw_size;
  877.  
  878.   }
  879.   /* regardless, once we know what we're doing, we might as well get going */
  880.   bfd_seek (abfd, section->filepos + offset, SEEK_SET);
  881.  
  882.   if (count != 0) {
  883.     return (bfd_write ((PTR)location, 1, count, abfd) == count) ?true:false;
  884.   }
  885.   return true;
  886. }
  887.  
  888. static boolean
  889. b_out_set_arch_mach (abfd, arch, machine)
  890.      bfd *abfd;
  891.      enum bfd_architecture arch;
  892.      unsigned long machine;
  893. {
  894.   bfd_default_set_arch_mach(abfd, arch, machine);
  895.  
  896.   if (arch == bfd_arch_unknown)    /* Unknown machine arch is OK */
  897.     return true;
  898.   if (arch == bfd_arch_i960)    /* i960 default is OK */
  899.     switch (machine) {
  900.     case bfd_mach_i960_core:
  901.     case bfd_mach_i960_kb_sb:
  902.     case bfd_mach_i960_mc:
  903.     case bfd_mach_i960_xa:
  904.     case bfd_mach_i960_ca:
  905.     case bfd_mach_i960_ka_sa:
  906.     case 0:
  907.       return true;
  908.     default:
  909.       return false;
  910.     }
  911.  
  912.   return false;
  913. }
  914.  
  915. static int 
  916. DEFUN(b_out_sizeof_headers,(ignore_abfd, ignore),
  917.       bfd *ignore_abfd AND
  918.       boolean ignore)
  919. {
  920.   return sizeof(struct internal_exec);
  921. }
  922.  
  923.  
  924.  
  925. /************************************************************************/
  926. static bfd_vma 
  927. get_value (reloc, link_info, input_section)
  928.      arelent *reloc;
  929.      struct bfd_link_info *link_info;
  930.      asection *input_section;
  931. {
  932.   bfd_vma value;
  933.   asymbol *symbol = *(reloc->sym_ptr_ptr);
  934.  
  935.   /* A symbol holds a pointer to a section, and an offset from the
  936.      base of the section.  To relocate, we find where the section will
  937.      live in the output and add that in */
  938.  
  939.   if (symbol->section == &bfd_und_section)
  940.     {
  941.       if (! ((*link_info->callbacks->undefined_symbol)
  942.          (link_info, bfd_asymbol_name (symbol),
  943.           input_section->owner, input_section, reloc->address)))
  944.     abort ();
  945.       value = symbol->value;
  946.     }
  947.   else 
  948.   {
  949.     value = symbol->value +
  950.      symbol->section->output_offset +
  951.       symbol->section->output_section->vma;
  952.   }
  953.  
  954.   /* Add the value contained in the relocation */
  955.   value += reloc->addend;
  956.   
  957.   return value;
  958. }
  959.  
  960. static void
  961. DEFUN(perform_slip,(s, slip, input_section, value),
  962.       asymbol **s AND
  963.       unsigned int slip AND
  964.       asection *input_section AND
  965.       bfd_vma value)
  966. {
  967.   
  968.   /* Find all symbols past this point, and make them know
  969.      what's happened */
  970.   while (*s) 
  971.   {
  972.     asymbol *p = *s;
  973.     if (p->section == input_section) 
  974.     {
  975.       /* This was pointing into this section, so mangle it */
  976.       if (p->value > value)
  977.       {
  978.     p->value -=slip;
  979.       }
  980.     }
  981.     s++;
  982.     
  983.   }    
  984. }
  985. #if 1
  986. /* This routine works out if the thing we want to get to can be
  987.    reached with a 24bit offset instead of a 32 bit one.
  988.    If it can, then it changes the amode */
  989.  
  990. static int 
  991. abs32code (input_section, symbols, r, shrink, link_info)
  992.      asection *input_section;
  993.      asymbol **symbols;
  994.      arelent *r;
  995.      unsigned int shrink;
  996.      struct bfd_link_info *link_info;
  997. {
  998.   bfd_vma value = get_value (r, link_info, input_section);
  999.   bfd_vma dot = input_section->output_section->vma +  input_section->output_offset + r->address;    
  1000.   bfd_vma gap;
  1001.   
  1002.   /* See if the address we're looking at within 2^23 bytes of where
  1003.      we are, if so then we can use a small branch rather than the
  1004.      jump we were going to */
  1005.  
  1006.   gap = value - (dot - shrink);
  1007.   
  1008.  
  1009.   if (-1<<23 < (long)gap && (long)gap < 1<<23 )
  1010.   { 
  1011.     /* Change the reloc type from 32bitcode possible 24, to 24bit
  1012.        possible 32 */
  1013.  
  1014.     r->howto = &howto_reloc_abs32codeshrunk;
  1015.     /* The place to relc moves back by four bytes */
  1016.     r->address -=4;
  1017.       
  1018.     /* This will be four bytes smaller in the long run */
  1019.     shrink += 4 ;
  1020.     perform_slip(symbols, 4, input_section, r->address-shrink +4);
  1021.   }      
  1022.   return shrink;      
  1023. }
  1024.  
  1025. static int 
  1026. DEFUN(aligncode,(input_section, symbols, r, shrink),
  1027.       asection *input_section AND
  1028.       asymbol **symbols AND
  1029.       arelent *r AND
  1030.       unsigned int shrink) 
  1031. {
  1032.   bfd_vma dot = input_section->output_section->vma +  input_section->output_offset + r->address;    
  1033.   bfd_vma gap;
  1034.   bfd_vma old_end;
  1035.   bfd_vma new_end;
  1036.   int shrink_delta;
  1037.   int size = r->howto->size;
  1038.  
  1039.   /* Reduce the size of the alignment so that it's still aligned but
  1040.      smaller  - the current size is already the same size as or bigger
  1041.      than the alignment required.  */
  1042.  
  1043.   /* calculate the first byte following the padding before we optimize */
  1044.   old_end = ((dot + size ) & ~size) + size+1;
  1045.   /* work out where the new end will be - remember that we're smaller
  1046.      than we used to be */
  1047.   new_end = ((dot - shrink + size) & ~size);
  1048.  
  1049.   /* This is the new end */
  1050.   gap = old_end - ((dot + size) & ~size);
  1051.  
  1052.   shrink_delta = (old_end - new_end) - shrink;
  1053.  
  1054.   if (shrink_delta)
  1055.   { 
  1056.     /* Change the reloc so that it knows how far to align to */
  1057.     r->howto = howto_done_align_table + (r->howto - howto_align_table);
  1058.  
  1059.     /* Encode the stuff into the addend - for future use we need to
  1060.        know how big the reloc used to be */
  1061.     r->addend = old_end ;
  1062.  
  1063.     /* This will be N bytes smaller in the long run, adjust all the symbols */
  1064.     perform_slip(symbols, shrink_delta, input_section, r->address - shrink );
  1065.     shrink += shrink_delta;
  1066.   }      
  1067.   return shrink;      
  1068. }
  1069.  
  1070. static boolean 
  1071. b_out_relax_section (abfd, i, link_info, symbols)
  1072.      bfd *abfd;
  1073.      asection *i;
  1074.      struct bfd_link_info *link_info;
  1075.      asymbol **symbols;
  1076. {
  1077.   
  1078.   /* Get enough memory to hold the stuff */
  1079.   bfd *input_bfd = i->owner;
  1080.   asection *input_section = i;
  1081.   int shrink = 0 ;
  1082.   boolean new = false;
  1083.   
  1084.   bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
  1085.                                input_section);
  1086.   arelent **reloc_vector = (arelent **)alloca(reloc_size);
  1087.  
  1088.   /* Get the relocs and think about them */
  1089.   if (bfd_canonicalize_reloc(input_bfd, 
  1090.                  input_section,
  1091.                  reloc_vector,
  1092.                  symbols))
  1093.   {
  1094.     arelent **parent;
  1095.     for (parent = reloc_vector; *parent; parent++) 
  1096.     {
  1097.       arelent *r = *parent;
  1098.       switch (r->howto->type) {
  1099.        case ALIGNER:
  1100.     /* An alignment reloc */
  1101.     shrink = aligncode(input_section, symbols, r,shrink);
  1102.     new=true;
  1103.     break;
  1104.        case ABS32CODE:
  1105.     /* A 32bit reloc in an addressing mode */
  1106.     shrink = abs32code (input_section, symbols, r, shrink, link_info);
  1107.     new=true;
  1108.     break;
  1109.        case ABS32CODE_SHRUNK:
  1110.     shrink+=4;
  1111.     break;
  1112.       }
  1113.     }
  1114.   }
  1115.   input_section->_cooked_size = input_section->_raw_size - shrink;  
  1116.  
  1117.   return new;
  1118. }
  1119.  
  1120. #endif
  1121. static bfd_byte *
  1122. b_out_get_relocated_section_contents (in_abfd, link_info, link_order, data,
  1123.                       relocateable, symbols)
  1124.      bfd *in_abfd;
  1125.      struct bfd_link_info *link_info;
  1126.      struct bfd_link_order *link_order;
  1127.      bfd_byte *data;
  1128.      boolean relocateable;
  1129.      asymbol **symbols;
  1130. {
  1131.   /* Get enough memory to hold the stuff */
  1132.   bfd *input_bfd = link_order->u.indirect.section->owner;
  1133.   asection *input_section = link_order->u.indirect.section;
  1134.   bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
  1135.                                input_section);
  1136.   arelent **reloc_vector = (arelent **)alloca(reloc_size);
  1137.   
  1138.   /* If producing relocateable output, don't bother to relax.  */
  1139.   if (relocateable)
  1140.     return bfd_generic_get_relocated_section_contents (in_abfd, link_info,
  1141.                                link_order,
  1142.                                data, relocateable,
  1143.                                symbols);
  1144.  
  1145.   /* read in the section */
  1146.   bfd_get_section_contents(input_bfd,
  1147.                input_section,
  1148.                data,
  1149.                0,
  1150.                input_section->_raw_size);
  1151.   
  1152.   
  1153.   if (bfd_canonicalize_reloc(input_bfd, 
  1154.                  input_section,
  1155.                  reloc_vector,
  1156.                  symbols) )
  1157.   {
  1158.     arelent **parent = reloc_vector;
  1159.     arelent *reloc ;
  1160.     
  1161.  
  1162.  
  1163.     unsigned int dst_address = 0;
  1164.     unsigned int src_address = 0;
  1165.     unsigned int run;
  1166.     unsigned int idx;
  1167.     
  1168.     /* Find how long a run we can do */
  1169.     while (dst_address < link_order->size) 
  1170.     {
  1171.       
  1172.       reloc = *parent;
  1173.       if (reloc) 
  1174.       {
  1175.     /* Note that the relaxing didn't tie up the addresses in the
  1176.        relocation, so we use the original address to work out the
  1177.        run of non-relocated data */
  1178.     run = reloc->address - src_address;
  1179.     parent++;
  1180.     
  1181.       }
  1182.       else 
  1183.       {
  1184.     run = link_order->size - dst_address;
  1185.       }
  1186.       /* Copy the bytes */
  1187.       for (idx = 0; idx < run; idx++)
  1188.       {
  1189.     data[dst_address++] = data[src_address++];
  1190.       }
  1191.     
  1192.       /* Now do the relocation */
  1193.     
  1194.       if (reloc) 
  1195.       {
  1196.     switch (reloc->howto->type) 
  1197.     {
  1198.      case ABS32CODE:
  1199.       calljx_callback (in_abfd, link_info, reloc, src_address + data,
  1200.                dst_address + data, input_section);
  1201.       src_address+=4;
  1202.       dst_address+=4;
  1203.       break;
  1204.      case ABS32:
  1205.       bfd_put_32(in_abfd,
  1206.              (bfd_get_32 (in_abfd, data+src_address)
  1207.               + get_value (reloc, link_info, input_section)),
  1208.              data+dst_address);
  1209.       src_address+=4;
  1210.       dst_address+=4;
  1211.       break;
  1212.      case CALLJ:
  1213.       callj_callback (in_abfd, link_info, reloc, data, src_address,
  1214.               dst_address, input_section);
  1215.       src_address+=4;
  1216.       dst_address+=4;
  1217.       break;
  1218.      case ALIGNDONE:
  1219.       src_address = reloc->addend;
  1220.       dst_address = (dst_address + reloc->howto->size) & ~reloc->howto->size;
  1221.       break;
  1222.      case ABS32CODE_SHRUNK: 
  1223.       /* This used to be a callx, but we've found out that a
  1224.          callj will reach, so do the right thing */
  1225.       callj_callback (in_abfd, link_info, reloc, data, src_address + 4,
  1226.               dst_address, input_section);
  1227.       dst_address+=4;
  1228.       src_address+=8;
  1229.       break;
  1230.      case PCREL24:
  1231.      {
  1232.        long int word = bfd_get_32(in_abfd, data+src_address);
  1233.        asymbol *symbol = *(reloc->sym_ptr_ptr);
  1234.        if (symbol->section == &bfd_und_section)
  1235.        {
  1236.          if (! ((*link_info->callbacks->undefined_symbol)
  1237.             (link_info, bfd_asymbol_name (symbol),
  1238.              input_section->owner, input_section, reloc->address)))
  1239.            return NULL;
  1240.        }
  1241.        word = ((word & ~BAL_MASK)
  1242.            | (((word & BAL_MASK)
  1243.                /* value of symbol */
  1244.                + symbol->value
  1245.                /* how far it's moving in this relocation */
  1246.                + (symbol->section->output_offset
  1247.               + symbol->section->output_section->vma)
  1248.                - (input_section->output_section->vma
  1249.               + input_section->output_offset)
  1250.                /* addend, of course */
  1251.                + reloc->addend)
  1252.               & BAL_MASK));
  1253.  
  1254.        bfd_put_32(in_abfd,word,  data+dst_address);
  1255.        dst_address+=4;
  1256.        src_address+=4;
  1257.  
  1258.      }
  1259.       break;
  1260.  
  1261.      case PCREL13:
  1262.      {
  1263.        long int word = bfd_get_32(in_abfd, data+src_address);
  1264.        asymbol *symbol = *(reloc->sym_ptr_ptr);
  1265.        if (symbol->section == &bfd_und_section)
  1266.          {
  1267.            if (! ((*link_info->callbacks->undefined_symbol)
  1268.               (link_info, bfd_asymbol_name (symbol),
  1269.                input_section->owner, input_section, reloc->address)))
  1270.          return NULL;
  1271.          }
  1272.        word = ((word & ~PCREL13_MASK)
  1273.            | (((word & PCREL13_MASK)
  1274.                + (symbol->section->output_offset
  1275.               + symbol->section->output_section->vma)
  1276.                + symbol->value
  1277.                + reloc->addend
  1278.                - (input_section->output_section->vma
  1279.               + input_section->output_offset))
  1280.               & PCREL13_MASK));
  1281.  
  1282.        bfd_put_32(in_abfd,word,  data+dst_address);
  1283.        dst_address+=4;
  1284.        src_address+=4;
  1285.  
  1286.      }
  1287.       break;
  1288.  
  1289.      default:
  1290.  
  1291.       abort();
  1292.     }
  1293.       }    
  1294.     }
  1295.   }
  1296.   return data;
  1297. }
  1298. /***********************************************************************/
  1299.  
  1300. /* Build the transfer vectors for Big and Little-Endian B.OUT files.  */
  1301.  
  1302. /* We don't have core files.  */
  1303. #define    aout_32_core_file_failing_command _bfd_dummy_core_file_failing_command
  1304. #define    aout_32_core_file_failing_signal _bfd_dummy_core_file_failing_signal
  1305. #define    aout_32_core_file_matches_executable_p    \
  1306.                 _bfd_dummy_core_file_matches_executable_p
  1307.  
  1308. /* We use BSD-Unix generic archive files.  */
  1309. #define    aout_32_openr_next_archived_file    bfd_generic_openr_next_archived_file
  1310. #define    aout_32_generic_stat_arch_elt    bfd_generic_stat_arch_elt
  1311. #define    aout_32_slurp_armap        bfd_slurp_bsd_armap
  1312. #define    aout_32_slurp_extended_name_table    _bfd_slurp_extended_name_table
  1313. #define    aout_32_write_armap        bsd_write_armap
  1314. #define    aout_32_truncate_arname        bfd_bsd_truncate_arname
  1315.  
  1316. /* We override these routines from the usual a.out file routines.  */
  1317. #define    aout_32_canonicalize_reloc    b_out_canonicalize_reloc
  1318. #define    aout_32_get_reloc_upper_bound    b_out_get_reloc_upper_bound
  1319. #define    aout_32_set_section_contents    b_out_set_section_contents
  1320. #define    aout_32_set_arch_mach        b_out_set_arch_mach
  1321. #define    aout_32_sizeof_headers        b_out_sizeof_headers
  1322.  
  1323. #define aout_32_bfd_debug_info_start        bfd_void
  1324. #define aout_32_bfd_debug_info_end        bfd_void
  1325. #define aout_32_bfd_debug_info_accumulate    (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
  1326.  
  1327. #define aout_32_bfd_get_relocated_section_contents  b_out_get_relocated_section_contents
  1328. #define aout_32_bfd_relax_section                   b_out_relax_section
  1329. #define aout_32_bfd_reloc_type_lookup            b_out_reloc_type_lookup
  1330. #define aout_32_bfd_make_debug_symbol \
  1331.   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
  1332. #define aout_32_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  1333. #define aout_32_bfd_link_add_symbols _bfd_generic_link_add_symbols
  1334. #define aout_32_bfd_final_link _bfd_generic_final_link
  1335.  
  1336. bfd_target b_out_vec_big_host =
  1337. {
  1338.   "b.out.big",            /* name */
  1339.   bfd_target_aout_flavour,
  1340.   false,            /* data byte order is little */
  1341.   true,                /* hdr byte order is big */
  1342.   (HAS_RELOC | EXEC_P |        /* object flags */
  1343.    HAS_LINENO | HAS_DEBUG |
  1344.    HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ),
  1345.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  1346.   '_',                /* symbol leading char */
  1347.   ' ',                /* ar_pad_char */
  1348.   16,                /* ar_max_namelen */
  1349.   2,                /* minumum alignment power */
  1350.  
  1351.   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  1352.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  1353.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  1354.   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  1355.      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  1356.      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
  1357.  {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */
  1358.    bfd_generic_archive_p, _bfd_dummy_target},
  1359.  {bfd_false, b_out_mkobject,    /* bfd_set_format */
  1360.    _bfd_generic_mkarchive, bfd_false},
  1361.  {bfd_false, b_out_write_object_contents, /* bfd_write_contents */
  1362.    _bfd_write_archive_contents, bfd_false},
  1363.  
  1364.   JUMP_TABLE(aout_32),
  1365.   (PTR) 0,
  1366. };
  1367.  
  1368.  
  1369. bfd_target b_out_vec_little_host =
  1370. {
  1371.   "b.out.little",        /* name */
  1372.   bfd_target_aout_flavour,
  1373.   false,            /* data byte order is little */
  1374.   false,            /* header byte order is little */
  1375.   (HAS_RELOC | EXEC_P |        /* object flags */
  1376.    HAS_LINENO | HAS_DEBUG |
  1377.    HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ),
  1378.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  1379.     '_',            /* symbol leading char */
  1380.   ' ',                /* ar_pad_char */
  1381.   16,                /* ar_max_namelen */
  1382.      2,                /* minum align */
  1383. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  1384.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  1385.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  1386. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  1387.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  1388.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
  1389.      
  1390.     {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */
  1391.        bfd_generic_archive_p, _bfd_dummy_target},
  1392.     {bfd_false, b_out_mkobject,    /* bfd_set_format */
  1393.        _bfd_generic_mkarchive, bfd_false},
  1394.     {bfd_false, b_out_write_object_contents,    /* bfd_write_contents */
  1395.        _bfd_write_archive_contents, bfd_false},
  1396.   JUMP_TABLE(aout_32),
  1397.   (PTR) 0
  1398. };
  1399.