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/coff-a29k.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for AMD 29000 COFF binaries.
    2    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1999, 2000, 2001
     2   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002
    33   Free Software Foundation, Inc.
    44   Contributed by David Wood at New York University 7/8/91.
     
    3232static bfd_reloc_status_type a29k_reloc
    3333  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
    34 static boolean coff_a29k_relocate_section
     34static bfd_boolean coff_a29k_relocate_section
    3535  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
    3636           struct internal_reloc *, struct internal_syment *, asection **));
    37 static boolean coff_a29k_adjust_symndx
     37static bfd_boolean coff_a29k_adjust_symndx
    3838  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
    39            struct internal_reloc *, boolean *));
     39           struct internal_reloc *, bfd_boolean *));
     40static void reloc_processing
     41  PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
    4042
    4143#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
     
    4850    (((HWORD) ^ 0x8000) - 0x8000)
    4951
    50 /* Provided the symbol, returns the value reffed */
     52/* Provided the symbol, returns the value reffed.  */
     53
    5154static long
    5255get_symbol_value (symbol)
     
    5659
    5760  if (bfd_is_com_section (symbol->section))
    58     {
    59       relocation = 0;
    60     }
     61    relocation = 0;
    6162  else
    62     {
    63       relocation = symbol->value +
    64         symbol->section->output_section->vma +
    65         symbol->section->output_offset;
    66     }
    67 
    68   return(relocation);
     63    relocation = symbol->value +
     64      symbol->section->output_section->vma +
     65      symbol->section->output_offset;
     66
     67  return relocation;
    6968}
    7069
    71 /* this function is in charge of performing all the 29k relocations */
     70/* This function is in charge of performing all the 29k relocations. */
    7271
    7372static bfd_reloc_status_type
     
    8281     char **error_message;
    8382{
    84   /* the consth relocation comes in two parts, we have to remember
    85      the state between calls, in these variables */
    86   static boolean part1_consth_active = false;
     83  /* The consth relocation comes in two parts, we have to remember
     84     the state between calls, in these variables. */
     85  static bfd_boolean part1_consth_active = FALSE;
    8786  static unsigned long part1_consth_value;
    88 
    8987  unsigned long insn;
    9088  unsigned long sym_value;
     
    9290  unsigned short r_type;
    9391  long signed_value;
    94 
    9592  unsigned long addr = reloc_entry->address ; /*+ input_section->vma*/
    9693  bfd_byte  *hit_data =addr + (bfd_byte *) (data);
     
    10097  if (output_bfd)
    10198    {
    102       /* Partial linking - do nothing */
     99      /* Partial linking - do nothing. */
    103100      reloc_entry->address += input_section->output_offset;
    104101      return bfd_reloc_ok;
    105 
    106102    }
    107103
     
    109105      && bfd_is_und_section (symbol_in->section))
    110106    {
    111       /* Keep the state machine happy in case we're called again */
     107      /* Keep the state machine happy in case we're called again. */
    112108      if (r_type == R_IHIHALF)
    113109        {
    114           part1_consth_active = true;
     110          part1_consth_active = TRUE;
    115111          part1_consth_value  = 0;
    116112        }
    117       return(bfd_reloc_undefined);
     113      return bfd_reloc_undefined;
    118114    }
    119115
    120116  if ((part1_consth_active) && (r_type != R_IHCONST))
    121117    {
    122       part1_consth_active = false;
     118      part1_consth_active = FALSE;
    123119      *error_message = (char *) _("Missing IHCONST");
    124       return(bfd_reloc_dangerous);
     120
     121      return bfd_reloc_dangerous;
    125122    }
    126123
     
    131128    case R_IREL:
    132129      insn = bfd_get_32 (abfd, hit_data);
    133       /* Take the value in the field and sign extend it */
     130      /* Take the value in the field and sign extend it. */
    134131      signed_value = EXTRACT_HWORD(insn);
    135132      signed_value = SIGN_EXTEND_HWORD(signed_value);
     
    143140      if ((signed_value & ~0x3ffff) == 0)
    144141        {                               /* Absolute jmp/call */
    145           insn |= (1<<24);              /* Make it absolute */
    146           /* FIXME: Should we change r_type to R_IABS */
     142          insn |= (1 << 24);            /* Make it absolute */
     143          /* FIXME: Should we change r_type to R_IABS. */
    147144        }
    148145      else
    149146        {
    150147          /* Relative jmp/call, so subtract from the value the
    151              address of the place we're coming from */
     148             address of the place we're coming from. */
    152149          signed_value -= (reloc_entry->address
    153150                           + input_section->output_section->vma
    154151                           + input_section->output_offset);
    155           if (signed_value>0x1ffff || signed_value<-0x20000)
    156             return(bfd_reloc_overflow);
     152          if (signed_value > 0x1ffff || signed_value < -0x20000)
     153            return bfd_reloc_overflow;
    157154        }
    158155      signed_value >>= 2;
    159       insn = INSERT_HWORD(insn, signed_value);
    160       bfd_put_32 (abfd, insn ,hit_data);
     156      insn = INSERT_HWORD (insn, signed_value);
     157      bfd_put_32 (abfd, (bfd_vma) insn ,hit_data);
    161158      break;
    162159    case R_ILOHALF:
     
    165162      unsigned_value +=  sym_value + reloc_entry->addend;
    166163      insn = INSERT_HWORD(insn, unsigned_value);
    167       bfd_put_32 (abfd, insn, hit_data);
     164      bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
    168165      break;
    169166    case R_IHIHALF:
    170167      insn = bfd_get_32 (abfd, hit_data);
    171168      /* consth, part 1
    172          Just get the symbol value that is referenced */
    173       part1_consth_active = true;
     169         Just get the symbol value that is referenced. */
     170      part1_consth_active = TRUE;
    174171      part1_consth_value = sym_value + reloc_entry->addend;
    175       /* Don't modify insn until R_IHCONST */
     172      /* Don't modify insn until R_IHCONST. */
    176173      break;
    177174    case R_IHCONST:
    178175      insn = bfd_get_32 (abfd, hit_data);
    179176      /* consth, part 2
    180          Now relocate the reference */
    181       if (part1_consth_active == false)
     177         Now relocate the reference. */
     178      if (! part1_consth_active)
    182179        {
    183180          *error_message = (char *) _("Missing IHIHALF");
    184           return(bfd_reloc_dangerous);
     181          return bfd_reloc_dangerous;
    185182        }
    186183      /* sym_ptr_ptr = r_symndx, in coff_slurp_reloc_table() */
     
    190187      unsigned_value = unsigned_value >> 16;
    191188      insn = INSERT_HWORD(insn, unsigned_value);
    192       part1_consth_active = false;
    193       bfd_put_32 (abfd, insn, hit_data);
     189      part1_consth_active = FALSE;
     190      bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
    194191      break;
    195192    case R_BYTE:
     
    197194      unsigned_value = insn + sym_value + reloc_entry->addend;
    198195      if (unsigned_value & 0xffffff00)
    199         return(bfd_reloc_overflow);
     196        return bfd_reloc_overflow;
    200197      bfd_put_8 (abfd, unsigned_value, hit_data);
    201198      break;
     
    204201      unsigned_value = insn + sym_value + reloc_entry->addend;
    205202      if (unsigned_value & 0xffff0000)
    206         return(bfd_reloc_overflow);
    207       bfd_put_16 (abfd, insn, hit_data);
     203        return bfd_reloc_overflow;
     204      bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
    208205      break;
    209206    case R_WORD:
    210207      insn = bfd_get_32 (abfd, hit_data);
    211208      insn += sym_value + reloc_entry->addend;
    212       bfd_put_32 (abfd, insn, hit_data);
     209      bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
    213210      break;
    214211    default:
    215212      *error_message = _("Unrecognized reloc");
    216       return (bfd_reloc_dangerous);
     213      return bfd_reloc_dangerous;
    217214    }
    218215
     
    220217}
    221218
    222 /*      type       rightshift
    223                        size
    224                           bitsize
    225                                pc-relative
    226                                      bitpos
    227                                          absolute
    228                                              complain_on_overflow
    229                                                   special_function
    230                                                     relocation name
    231                                                                partial_inplace
    232                                                                       src_mask
    233 */
    234 
    235 /*FIXME: I'm not real sure about this table */
     219/*FIXME: I'm not real sure about this table.  */
    236220static reloc_howto_type howto_table[] =
    237 {
    238   {R_ABS,     0, 3, 32, false, 0, complain_overflow_bitfield,a29k_reloc,"ABS",     true, 0xffffffff,0xffffffff, false},
    239   EMPTY_HOWTO (1),
    240   EMPTY_HOWTO (2),
    241   EMPTY_HOWTO (3),
    242   EMPTY_HOWTO (4),
    243   EMPTY_HOWTO (5),
    244   EMPTY_HOWTO (6),
    245   EMPTY_HOWTO (7),
    246   EMPTY_HOWTO (8),
    247   EMPTY_HOWTO (9),
    248   EMPTY_HOWTO (10),
    249   EMPTY_HOWTO (11),
    250   EMPTY_HOWTO (12),
    251   EMPTY_HOWTO (13),
    252   EMPTY_HOWTO (14),
    253   EMPTY_HOWTO (15),
    254   EMPTY_HOWTO (16),
    255   EMPTY_HOWTO (17),
    256   EMPTY_HOWTO (18),
    257   EMPTY_HOWTO (19),
    258   EMPTY_HOWTO (20),
    259   EMPTY_HOWTO (21),
    260   EMPTY_HOWTO (22),
    261   EMPTY_HOWTO (23),
    262   {R_IREL,    0, 3, 32, true,  0, complain_overflow_signed,a29k_reloc,"IREL",    true, 0xffffffff,0xffffffff, false},
    263   {R_IABS,    0, 3, 32, false, 0, complain_overflow_bitfield, a29k_reloc,"IABS",    true, 0xffffffff,0xffffffff, false},
    264   {R_ILOHALF, 0, 3, 16, true,  0, complain_overflow_signed, a29k_reloc,"ILOHALF", true, 0x0000ffff,0x0000ffff, false},
    265   {R_IHIHALF, 0, 3, 16, true,  16, complain_overflow_signed, a29k_reloc,"IHIHALF", true, 0xffff0000,0xffff0000, false},
    266   {R_IHCONST, 0, 3, 16, true,  0, complain_overflow_signed, a29k_reloc,"IHCONST", true, 0xffff0000,0xffff0000, false},
    267   {R_BYTE,    0, 0, 8, false, 0, complain_overflow_bitfield, a29k_reloc,"BYTE",    true, 0x000000ff,0x000000ff, false},
    268   {R_HWORD,   0, 1, 16, false, 0, complain_overflow_bitfield, a29k_reloc,"HWORD",   true, 0x0000ffff,0x0000ffff, false},
    269   {R_WORD,    0, 2, 32, false, 0, complain_overflow_bitfield, a29k_reloc,"WORD",    true, 0xffffffff,0xffffffff, false},
    270 };
     221  {
     222    {R_ABS,     0, 3, 32, FALSE, 0, complain_overflow_bitfield,a29k_reloc,"ABS",     TRUE, 0xffffffff,0xffffffff, FALSE},
     223    EMPTY_HOWTO (1),
     224    EMPTY_HOWTO (2),
     225    EMPTY_HOWTO (3),
     226    EMPTY_HOWTO (4),
     227    EMPTY_HOWTO (5),
     228    EMPTY_HOWTO (6),
     229    EMPTY_HOWTO (7),
     230    EMPTY_HOWTO (8),
     231    EMPTY_HOWTO (9),
     232    EMPTY_HOWTO (10),
     233    EMPTY_HOWTO (11),
     234    EMPTY_HOWTO (12),
     235    EMPTY_HOWTO (13),
     236    EMPTY_HOWTO (14),
     237    EMPTY_HOWTO (15),
     238    EMPTY_HOWTO (16),
     239    EMPTY_HOWTO (17),
     240    EMPTY_HOWTO (18),
     241    EMPTY_HOWTO (19),
     242    EMPTY_HOWTO (20),
     243    EMPTY_HOWTO (21),
     244    EMPTY_HOWTO (22),
     245    EMPTY_HOWTO (23),
     246    {R_IREL,    0, 3, 32, TRUE,  0, complain_overflow_signed,a29k_reloc,"IREL",    TRUE, 0xffffffff,0xffffffff, FALSE},
     247    {R_IABS,    0, 3, 32, FALSE, 0, complain_overflow_bitfield, a29k_reloc,"IABS",    TRUE, 0xffffffff,0xffffffff, FALSE},
     248    {R_ILOHALF, 0, 3, 16, TRUE,  0, complain_overflow_signed, a29k_reloc,"ILOHALF", TRUE, 0x0000ffff,0x0000ffff, FALSE},
     249    {R_IHIHALF, 0, 3, 16, TRUE,  16, complain_overflow_signed, a29k_reloc,"IHIHALF", TRUE, 0xffff0000,0xffff0000, FALSE},
     250    {R_IHCONST, 0, 3, 16, TRUE,  0, complain_overflow_signed, a29k_reloc,"IHCONST", TRUE, 0xffff0000,0xffff0000, FALSE},
     251    {R_BYTE,    0, 0, 8, FALSE, 0, complain_overflow_bitfield, a29k_reloc,"BYTE",    TRUE, 0x000000ff,0x000000ff, FALSE},
     252    {R_HWORD,   0, 1, 16, FALSE, 0, complain_overflow_bitfield, a29k_reloc,"HWORD",   TRUE, 0x0000ffff,0x0000ffff, FALSE},
     253    {R_WORD,    0, 2, 32, FALSE, 0, complain_overflow_bitfield, a29k_reloc,"WORD",    TRUE, 0xffffffff,0xffffffff, FALSE},
     254  };
    271255
    272256#define BADMAG(x) A29KBADMAG(x)
     
    305289    {
    306290      asymbol *ptr;
    307       relent->sym_ptr_ptr = symbols + obj_convert(abfd)[reloc->r_symndx];
     291
     292      relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
    308293
    309294      ptr = *(relent->sym_ptr_ptr);
     
    311296      if (ptr
    312297          && bfd_asymbol_bfd(ptr) == abfd
    313 
    314           && ((ptr->flags & BSF_OLD_COMMON)== 0))
    315         {
    316           relent->addend = 0;
    317         }
     298          && ((ptr->flags & BSF_OLD_COMMON) == 0))
     299        relent->addend = 0;
    318300      else
    319         {
    320           relent->addend = 0;
    321         }
     301        relent->addend = 0;
     302
    322303      relent->address-= section->vma;
    323304      if (reloc->r_type == R_IHIHALF)
     
    330311/* The reloc processing routine for the optimized COFF linker.  */
    331312
    332 static boolean
     313static bfd_boolean
    333314coff_a29k_relocate_section (output_bfd, info, input_bfd, input_section,
    334315                            contents, relocs, syms, sections)
     
    344325  struct internal_reloc *rel;
    345326  struct internal_reloc *relend;
    346   boolean hihalf;
     327  bfd_boolean hihalf;
    347328  bfd_vma hihalf_val;
    348329
     
    351332     addresses and symbol indices.  */
    352333  if (info->relocateable)
    353     return true;
    354 
    355   hihalf = false;
     334    return TRUE;
     335
     336  hihalf = FALSE;
    356337  hihalf_val = 0;
    357338
     
    366347      asection *sec;
    367348      bfd_vma val;
    368       boolean overflow;
     349      bfd_boolean overflow;
    369350      unsigned long insn;
    370351      long signed_value;
     
    405386          else
    406387            {
    407               if (h->root.type == bfd_link_hash_defined
     388              if (   h->root.type == bfd_link_hash_defined
    408389                  || h->root.type == bfd_link_hash_defweak)
    409390                {
     
    417398                  if (! ((*info->callbacks->undefined_symbol)
    418399                         (info, h->root.root.string, input_bfd, input_section,
    419                           rel->r_vaddr - input_section->vma, true)))
    420                     return false;
     400                          rel->r_vaddr - input_section->vma, TRUE)))
     401                    return FALSE;
    421402                }
    422403            }
     
    427408                     (info, _("missing IHCONST reloc"), input_bfd,
    428409                      input_section, rel->r_vaddr - input_section->vma)))
    429                 return false;
    430               hihalf = false;
    431             }
    432         }
    433 
    434       overflow = false;
     410                return FALSE;
     411              hihalf = FALSE;
     412            }
     413        }
     414
     415      overflow = FALSE;
    435416
    436417      switch (rel->r_type)
     
    438419        default:
    439420          bfd_set_error (bfd_error_bad_value);
    440           return false;
     421          return FALSE;
    441422
    442423        case R_IREL:
     
    485466              if (signed_value > 0x1ffff || signed_value < - 0x20000)
    486467                {
    487                   overflow = true;
     468                  overflow = TRUE;
    488469                  signed_value = 0;
    489470                }
     
    495476
    496477          bfd_put_32 (input_bfd, (bfd_vma) insn, loc);
    497 
    498478          break;
    499479
     
    503483          unsigned_value += val;
    504484          insn = INSERT_HWORD (insn, unsigned_value);
    505           bfd_put_32 (input_bfd, insn, loc);
     485          bfd_put_32 (input_bfd, (bfd_vma) insn, loc);
    506486          break;
    507487
    508488        case R_IHIHALF:
    509489          /* Save the value for the R_IHCONST reloc.  */
    510           hihalf = true;
     490          hihalf = TRUE;
    511491          hihalf_val = val;
    512492          break;
     
    518498                     (info, _("missing IHIHALF reloc"), input_bfd,
    519499                      input_section, rel->r_vaddr - input_section->vma)))
    520                 return false;
     500                return FALSE;
    521501              hihalf_val = 0;
    522502            }
     
    528508          bfd_put_32 (input_bfd, (bfd_vma) insn, loc);
    529509
    530           hihalf = false;
     510          hihalf = FALSE;
    531511
    532512          break;
     
    538518                                          input_bfd, val, loc);
    539519          if (rstat == bfd_reloc_overflow)
    540             overflow = true;
     520            overflow = TRUE;
    541521          else if (rstat != bfd_reloc_ok)
    542522            abort ();
     
    569549                  input_bfd, input_section,
    570550                  rel->r_vaddr - input_section->vma)))
    571             return false;
    572         }
    573     }
    574 
    575   return true;
     551            return FALSE;
     552        }
     553    }
     554
     555  return TRUE;
    576556}
    577557
     
    581561   is actually an addend, not a symbol index at all.  */
    582562
    583 static boolean
     563static bfd_boolean
    584564coff_a29k_adjust_symndx (obfd, info, ibfd, sec, irel, adjustedp)
    585565     bfd *obfd ATTRIBUTE_UNUSED;
     
    588568     asection *sec ATTRIBUTE_UNUSED;
    589569     struct internal_reloc *irel;
    590      boolean *adjustedp;
     570     bfd_boolean *adjustedp;
    591571{
    592572  if (irel->r_type == R_IHCONST)
    593     *adjustedp = true;
     573    *adjustedp = TRUE;
    594574  else
    595     *adjustedp = false;
    596   return true;
     575    *adjustedp = FALSE;
     576  return TRUE;
    597577}
    598578
Note: See TracChangeset for help on using the changeset viewer.