Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/riscix.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for RISC iX (Acorn, arm) binaries.
    2    Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001
     2   Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002
    33   Free Software Foundation, Inc.
    44   Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
     
    5656
    5757/* Only a pure OMAGIC file has the minimal header */
    58 #define N_TXTOFF(x)                     \
    59  ((x).a_info == OMAGIC ? 32             \
    60   : (N_MAGIC(x) == ZMAGIC) ? TARGET_PAGE_SIZE  \
    61   : 999)
    62 
    63 #define N_TXTADDR(x)                                                         \
    64   (N_MAGIC(x) != ZMAGIC ? 0 /* object file or NMAGIC */                      \
     58#define N_TXTOFF(x)             \
     59 ((x).a_info == OMAGIC          \
     60  ? 32                          \
     61  : (N_MAGIC(x) == ZMAGIC       \
     62     ? TARGET_PAGE_SIZE         \
     63     : 999))
     64
     65#define N_TXTADDR(x)                                                         \
     66  (N_MAGIC(x) != ZMAGIC                                                      \
     67   ? (bfd_vma) 0 /* object file or NMAGIC */                                 \
    6568   /* Programs with shared libs are loaded at the first page after all the   \
    6669      text segments of the shared library programs.  Without looking this    \
    6770      up we can't know exactly what the address will be.  A reasonable guess \
    68       is that a_entry will be in the first page of the executable.  */       \
    69    : N_SHARED_LIB(x) ? ((x).a_entry & ~(TARGET_PAGE_SIZE - 1))                      \
    70    : TEXT_START_ADDR)
     71      is that a_entry will be in the first page of the executable.  */       \
     72   : (N_SHARED_LIB(x)                                                        \
     73      ? ((x).a_entry & ~(bfd_vma) (TARGET_PAGE_SIZE - 1))                    \
     74      : (bfd_vma) TEXT_START_ADDR))
    7175
    7276#define N_SYMOFF(x) \
     
    8084#define DEFAULT_ARCH bfd_arch_arm
    8185
    82 #define MY(OP) CAT(riscix_,OP)
     86/* Do not "beautify" the CONCAT* macro args.  Traditional C will not
     87   remove whitespace added here, and thus will fail to concatenate
     88   the tokens.  */
     89#define MY(OP) CONCAT2 (riscix_,OP)
    8390#define TARGETNAME "a.out-riscix"
    8491#define N_BADMAG(x) ((((x).a_info & ~007200) != ZMAGIC) && \
     
    9198#include "libbfd.h"
    9299
    93 #define WRITE_HEADERS(abfd, execp)                                         \
    94   {                                                                        \
    95     bfd_size_type text_size; /* dummy vars */                              \
    96     file_ptr text_end;                                                     \
    97     if (adata(abfd).magic == undecided_magic)                              \
    98       NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end);      \
    99                                                                            \
    100     execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE;         \
    101     execp->a_entry = bfd_get_start_address (abfd);                         \
    102                                                                            \
    103     execp->a_trsize = ((obj_textsec (abfd)->reloc_count) *                 \
    104                        obj_reloc_entry_size (abfd));                       \
    105     execp->a_drsize = ((obj_datasec (abfd)->reloc_count) *                 \
    106                        obj_reloc_entry_size (abfd));                       \
    107     NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes);            \
    108                                                                            \
    109     if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) return false;        \
    110     if (bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)            \
    111         != EXEC_BYTES_SIZE)                                                \
    112       return false;                                                        \
    113     /* Now write out reloc info, followed by syms and strings */           \
    114                                                                            \
    115     if (bfd_get_outsymbols (abfd) != (asymbol **) NULL                     \
    116         && bfd_get_symcount (abfd) != 0)                                   \
    117       {                                                                    \
     100#define WRITE_HEADERS(abfd, execp)                                          \
     101  {                                                                         \
     102    bfd_size_type text_size; /* dummy vars */                               \
     103    file_ptr text_end;                                                      \
     104    if (adata(abfd).magic == undecided_magic)                               \
     105      NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end);       \
     106                                                                            \
     107    execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE;          \
     108    execp->a_entry = bfd_get_start_address (abfd);                          \
     109                                                                            \
     110    execp->a_trsize = ((obj_textsec (abfd)->reloc_count) *                  \
     111                       obj_reloc_entry_size (abfd));                        \
     112    execp->a_drsize = ((obj_datasec (abfd)->reloc_count) *                  \
     113                       obj_reloc_entry_size (abfd));                        \
     114    NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes);             \
     115                                                                            \
     116    if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0                        \
     117        || bfd_bwrite ((PTR) &exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE,   \
     118                      abfd) != EXEC_BYTES_SIZE)                             \
     119      return FALSE;                                                         \
     120    /* Now write out reloc info, followed by syms and strings */            \
     121                                                                            \
     122    if (bfd_get_outsymbols (abfd) != (asymbol **) NULL                      \
     123        && bfd_get_symcount (abfd) != 0)                                    \
     124      {                                                                     \
    118125        if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*execp)), SEEK_SET) != 0)  \
    119           return false;                                                    \
    120                                                                            \
    121         if (! NAME(aout,write_syms) (abfd)) return false;                  \
    122                                                                            \
     126          return FALSE;                                                     \
     127                                                                            \
     128        if (! NAME(aout,write_syms) (abfd)) return FALSE;                   \
     129                                                                            \
    123130        if (bfd_seek (abfd, (file_ptr) (N_TRELOFF(*execp)), SEEK_SET) != 0) \
    124           return false;                                                    \
    125                                                                            \
    126         if (! riscix_squirt_out_relocs (abfd, obj_textsec (abfd)))         \
    127           return false;                                                    \
     131          return FALSE;                                                     \
     132                                                                            \
     133        if (! riscix_squirt_out_relocs (abfd, obj_textsec (abfd)))          \
     134          return FALSE;                                                     \
    128135        if (bfd_seek (abfd, (file_ptr) (N_DRELOFF(*execp)), SEEK_SET) != 0) \
    129           return false;                                                    \
    130                                                                            \
    131         if (!NAME(aout,squirt_out_relocs) (abfd, obj_datasec (abfd)))      \
    132           return false;                                                    \
    133       }                                                                    \
     136          return FALSE;                                                     \
     137                                                                            \
     138        if (!NAME(aout,squirt_out_relocs) (abfd, obj_datasec (abfd)))       \
     139          return FALSE;                                                     \
     140      }                                                                     \
    134141  }
    135142
     
    144151riscix_fix_pcrel_26 PARAMS ((bfd *, arelent *, asymbol *, PTR,
    145152                             asection *, bfd *, char **));
     153static const bfd_target *
     154MY (object_p) PARAMS ((bfd *));
     155
     156reloc_howto_type *
     157riscix_reloc_type_lookup PARAMS ((bfd *, bfd_reloc_code_real_type));
     158
     159void
     160riscix_swap_std_reloc_out PARAMS ((bfd *, arelent *, struct reloc_std_external *));
     161
     162bfd_boolean
     163riscix_squirt_out_relocs PARAMS ((bfd *, asection *));
     164
     165long
     166MY (canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
     167
     168const bfd_target *
     169riscix_some_aout_object_p PARAMS ((bfd *, struct internal_exec *, const bfd_target *(*) (bfd *)));
     170
    146171
    147172static reloc_howto_type riscix_std_reloc_howto[] = {
    148173  /* type              rs size bsz  pcrel bitpos ovrf                     sf name     part_inpl readmask  setmask    pcdone */
    149   HOWTO( 0,              0,  0,   8,  false, 0, complain_overflow_bitfield,0,"8",        true, 0x000000ff,0x000000ff, false),
    150   HOWTO( 1,              0,  1,   16, false, 0, complain_overflow_bitfield,0,"16",        true, 0x0000ffff,0x0000ffff, false),
    151   HOWTO( 2,              0,  2,   32, false, 0, complain_overflow_bitfield,0,"32",        true, 0xffffffff,0xffffffff, false),
    152   HOWTO( 3,              2,  3,   26, true, 0, complain_overflow_signed,  riscix_fix_pcrel_26 , "ARM26",      true, 0x00ffffff,0x00ffffff, false),
    153   HOWTO( 4,              0,  0,   8,  true,  0, complain_overflow_signed,  0,"DISP8",     true, 0x000000ff,0x000000ff, true),
    154   HOWTO( 5,              0,  1,   16, true,  0, complain_overflow_signed,  0,"DISP16",    true, 0x0000ffff,0x0000ffff, true),
    155   HOWTO( 6,              0,  2,   32, true,  0, complain_overflow_signed,  0,"DISP32",    true, 0xffffffff,0xffffffff, true),
    156   HOWTO( 7,              2,  3,   26, false, 0, complain_overflow_signed,  riscix_fix_pcrel_26_done, "ARM26D",true,0x00ffffff,0x00ffffff, false),
     174  HOWTO( 0,              0,  0,   8,  FALSE, 0, complain_overflow_bitfield,0,"8",        TRUE, 0x000000ff,0x000000ff, FALSE),
     175  HOWTO( 1,              0,  1,   16, FALSE, 0, complain_overflow_bitfield,0,"16",        TRUE, 0x0000ffff,0x0000ffff, FALSE),
     176  HOWTO( 2,              0,  2,   32, FALSE, 0, complain_overflow_bitfield,0,"32",        TRUE, 0xffffffff,0xffffffff, FALSE),
     177  HOWTO( 3,              2,  3,   26, TRUE, 0, complain_overflow_signed,  riscix_fix_pcrel_26 , "ARM26",      TRUE, 0x00ffffff,0x00ffffff, FALSE),
     178  HOWTO( 4,              0,  0,   8,  TRUE,  0, complain_overflow_signed,  0,"DISP8",     TRUE, 0x000000ff,0x000000ff, TRUE),
     179  HOWTO( 5,              0,  1,   16, TRUE,  0, complain_overflow_signed,  0,"DISP16",    TRUE, 0x0000ffff,0x0000ffff, TRUE),
     180  HOWTO( 6,              0,  2,   32, TRUE,  0, complain_overflow_signed,  0,"DISP32",    TRUE, 0xffffffff,0xffffffff, TRUE),
     181  HOWTO( 7,              2,  3,   26, FALSE, 0, complain_overflow_signed,  riscix_fix_pcrel_26_done, "ARM26D",TRUE,0x00ffffff,0x00ffffff, FALSE),
    157182  EMPTY_HOWTO (-1),
    158   HOWTO( 9,              0, -1,   16, false, 0, complain_overflow_bitfield,0,"NEG16",        true, 0x0000ffff,0x0000ffff, false),
    159   HOWTO( 10,              0, -2,   32, false, 0, complain_overflow_bitfield,0,"NEG32",        true, 0xffffffff,0xffffffff, false)
     183  HOWTO( 9,              0, -1,   16, FALSE, 0, complain_overflow_bitfield,0,"NEG16",        TRUE, 0x0000ffff,0x0000ffff, FALSE),
     184  HOWTO( 10,              0, -2,   32, FALSE, 0, complain_overflow_bitfield,0,"NEG32",        TRUE, 0xffffffff,0xffffffff, FALSE)
    160185};
    161186
     
    223248        flag = bfd_reloc_overflow;
    224249    }
    225   else if (relocation & ~0x03ffffff)
     250  else if (relocation & ~ (bfd_vma) 0x03ffffff)
    226251    flag = bfd_reloc_overflow;
    227252
    228253  target &= ~0x00ffffff;
    229254  target |= (relocation >> 2) & 0x00ffffff;
    230   bfd_put_32 (abfd, target, (bfd_byte *) data + addr);
     255  bfd_put_32 (abfd, (bfd_vma) target, (bfd_byte *) data + addr);
    231256
    232257  /* Now the ARM magic... Change the reloc type so that it is marked as done.
     
    372397}
    373398
    374 boolean
     399bfd_boolean
    375400riscix_squirt_out_relocs (abfd, section)
    376401     bfd *abfd;
     
    382407
    383408  unsigned int count = section->reloc_count;
    384   size_t natsize;
    385 
    386   if (count == 0) return true;
     409  bfd_size_type natsize;
     410
     411  if (count == 0)
     412    return TRUE;
    387413
    388414  each_size = obj_reloc_entry_size (abfd);
    389   natsize = each_size * count;
     415  natsize = each_size;
     416  natsize *= count;
    390417  native = (unsigned char *) bfd_zalloc (abfd, natsize);
    391418  if (!native)
    392     return false;
     419    return FALSE;
    393420
    394421  generic = section->orelocation;
     
    400427                               (struct reloc_std_external *) natptr);
    401428
    402   if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize)
    403     {
    404       bfd_release(abfd, native);
    405       return false;
     429  if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize)
     430    {
     431      bfd_release (abfd, native);
     432      return FALSE;
    406433    }
    407434
    408435  bfd_release (abfd, native);
    409   return true;
     436  return TRUE;
    410437}
    411438
     
    471498  struct aout_data_struct *rawptr, *oldrawptr;
    472499  const bfd_target *result;
    473 
    474   rawptr = ((struct aout_data_struct  *)
    475             bfd_zalloc (abfd, sizeof (struct aout_data_struct )));
     500  bfd_size_type amt = sizeof (struct aout_data_struct);
     501
     502  rawptr = (struct aout_data_struct  *) bfd_zalloc (abfd, amt);
    476503
    477504  if (rawptr == NULL)
     
    615642  const bfd_target *target;
    616643
    617   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
    618       != EXEC_BYTES_SIZE) {
    619     if (bfd_get_error () != bfd_error_system_call)
    620       bfd_set_error (bfd_error_wrong_format);
    621     return 0;
    622   }
    623 
    624   exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
     644  if (bfd_bread ((PTR) &exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, abfd)
     645      != EXEC_BYTES_SIZE)
     646    {
     647      if (bfd_get_error () != bfd_error_system_call)
     648        bfd_set_error (bfd_error_wrong_format);
     649      return 0;
     650    }
     651
     652  exec.a_info = H_GET_32 (abfd, exec_bytes.e_info);
    625653
    626654  if (N_BADMAG (exec)) return 0;
Note: See TracChangeset for help on using the changeset viewer.