OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [gas/] [ehopt.c] - Diff between revs 156 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 156 Rev 816
/* ehopt.c--optimize gcc exception frame information.
/* ehopt.c--optimize gcc exception frame information.
   Copyright 1998, 2000, 2001, 2003, 2005, 2007 Free Software Foundation, Inc.
   Copyright 1998, 2000, 2001, 2003, 2005, 2007 Free Software Foundation, Inc.
   Written by Ian Lance Taylor <ian@cygnus.com>.
   Written by Ian Lance Taylor <ian@cygnus.com>.
 
 
   This file is part of GAS, the GNU Assembler.
   This file is part of GAS, the GNU Assembler.
 
 
   GAS is free software; you can redistribute it and/or modify
   GAS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   the Free Software Foundation; either version 3, or (at your option)
   any later version.
   any later version.
 
 
   GAS is distributed in the hope that it will be useful,
   GAS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with GAS; see the file COPYING.  If not, write to the Free
   along with GAS; see the file COPYING.  If not, write to the Free
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */
   02110-1301, USA.  */
 
 
#include "as.h"
#include "as.h"
#include "subsegs.h"
#include "subsegs.h"
 
 
/* We include this ELF file, even though we may not be assembling for
/* We include this ELF file, even though we may not be assembling for
   ELF, since the exception frame information is always in a format
   ELF, since the exception frame information is always in a format
   derived from DWARF.  */
   derived from DWARF.  */
 
 
#include "elf/dwarf2.h"
#include "elf/dwarf2.h"
 
 
/* Try to optimize gcc 2.8 exception frame information.
/* Try to optimize gcc 2.8 exception frame information.
 
 
   Exception frame information is emitted for every function in the
   Exception frame information is emitted for every function in the
   .eh_frame or .debug_frame sections.  Simple information for a function
   .eh_frame or .debug_frame sections.  Simple information for a function
   with no exceptions looks like this:
   with no exceptions looks like this:
 
 
__FRAME_BEGIN__:
__FRAME_BEGIN__:
        .4byte  .LLCIE1 / Length of Common Information Entry
        .4byte  .LLCIE1 / Length of Common Information Entry
.LSCIE1:
.LSCIE1:
#if .eh_frame
#if .eh_frame
        .4byte  0x0     / CIE Identifier Tag
        .4byte  0x0     / CIE Identifier Tag
#elif .debug_frame
#elif .debug_frame
        .4byte  0xffffffff / CIE Identifier Tag
        .4byte  0xffffffff / CIE Identifier Tag
#endif
#endif
        .byte   0x1     / CIE Version
        .byte   0x1     / CIE Version
        .byte   0x0     / CIE Augmentation (none)
        .byte   0x0     / CIE Augmentation (none)
        .byte   0x1     / ULEB128 0x1 (CIE Code Alignment Factor)
        .byte   0x1     / ULEB128 0x1 (CIE Code Alignment Factor)
        .byte   0x7c    / SLEB128 -4 (CIE Data Alignment Factor)
        .byte   0x7c    / SLEB128 -4 (CIE Data Alignment Factor)
        .byte   0x8     / CIE RA Column
        .byte   0x8     / CIE RA Column
        .byte   0xc     / DW_CFA_def_cfa
        .byte   0xc     / DW_CFA_def_cfa
        .byte   0x4     / ULEB128 0x4
        .byte   0x4     / ULEB128 0x4
        .byte   0x4     / ULEB128 0x4
        .byte   0x4     / ULEB128 0x4
        .byte   0x88    / DW_CFA_offset, column 0x8
        .byte   0x88    / DW_CFA_offset, column 0x8
        .byte   0x1     / ULEB128 0x1
        .byte   0x1     / ULEB128 0x1
        .align 4
        .align 4
.LECIE1:
.LECIE1:
        .set    .LLCIE1,.LECIE1-.LSCIE1 / CIE Length Symbol
        .set    .LLCIE1,.LECIE1-.LSCIE1 / CIE Length Symbol
        .4byte  .LLFDE1 / FDE Length
        .4byte  .LLFDE1 / FDE Length
.LSFDE1:
.LSFDE1:
        .4byte  .LSFDE1-__FRAME_BEGIN__ / FDE CIE offset
        .4byte  .LSFDE1-__FRAME_BEGIN__ / FDE CIE offset
        .4byte  .LFB1   / FDE initial location
        .4byte  .LFB1   / FDE initial location
        .4byte  .LFE1-.LFB1     / FDE address range
        .4byte  .LFE1-.LFB1     / FDE address range
        .byte   0x4     / DW_CFA_advance_loc4
        .byte   0x4     / DW_CFA_advance_loc4
        .4byte  .LCFI0-.LFB1
        .4byte  .LCFI0-.LFB1
        .byte   0xe     / DW_CFA_def_cfa_offset
        .byte   0xe     / DW_CFA_def_cfa_offset
        .byte   0x8     / ULEB128 0x8
        .byte   0x8     / ULEB128 0x8
        .byte   0x85    / DW_CFA_offset, column 0x5
        .byte   0x85    / DW_CFA_offset, column 0x5
        .byte   0x2     / ULEB128 0x2
        .byte   0x2     / ULEB128 0x2
        .byte   0x4     / DW_CFA_advance_loc4
        .byte   0x4     / DW_CFA_advance_loc4
        .4byte  .LCFI1-.LCFI0
        .4byte  .LCFI1-.LCFI0
        .byte   0xd     / DW_CFA_def_cfa_register
        .byte   0xd     / DW_CFA_def_cfa_register
        .byte   0x5     / ULEB128 0x5
        .byte   0x5     / ULEB128 0x5
        .byte   0x4     / DW_CFA_advance_loc4
        .byte   0x4     / DW_CFA_advance_loc4
        .4byte  .LCFI2-.LCFI1
        .4byte  .LCFI2-.LCFI1
        .byte   0x2e    / DW_CFA_GNU_args_size
        .byte   0x2e    / DW_CFA_GNU_args_size
        .byte   0x4     / ULEB128 0x4
        .byte   0x4     / ULEB128 0x4
        .byte   0x4     / DW_CFA_advance_loc4
        .byte   0x4     / DW_CFA_advance_loc4
        .4byte  .LCFI3-.LCFI2
        .4byte  .LCFI3-.LCFI2
        .byte   0x2e    / DW_CFA_GNU_args_size
        .byte   0x2e    / DW_CFA_GNU_args_size
        .byte   0x0     / ULEB128 0x0
        .byte   0x0     / ULEB128 0x0
        .align 4
        .align 4
.LEFDE1:
.LEFDE1:
        .set    .LLFDE1,.LEFDE1-.LSFDE1 / FDE Length Symbol
        .set    .LLFDE1,.LEFDE1-.LSFDE1 / FDE Length Symbol
 
 
   The immediate issue we can address in the assembler is the
   The immediate issue we can address in the assembler is the
   DW_CFA_advance_loc4 followed by a four byte value.  The value is
   DW_CFA_advance_loc4 followed by a four byte value.  The value is
   the difference of two addresses in the function.  Since gcc does
   the difference of two addresses in the function.  Since gcc does
   not know this value, it always uses four bytes.  We will know the
   not know this value, it always uses four bytes.  We will know the
   value at the end of assembly, so we can do better.  */
   value at the end of assembly, so we can do better.  */
 
 
struct cie_info
struct cie_info
{
{
  unsigned code_alignment;
  unsigned code_alignment;
  int z_augmentation;
  int z_augmentation;
};
};
 
 
static int get_cie_info (struct cie_info *);
static int get_cie_info (struct cie_info *);
 
 
/* Extract information from the CIE.  */
/* Extract information from the CIE.  */
 
 
static int
static int
get_cie_info (struct cie_info *info)
get_cie_info (struct cie_info *info)
{
{
  fragS *f;
  fragS *f;
  fixS *fix;
  fixS *fix;
  int offset;
  int offset;
  char CIE_id;
  char CIE_id;
  char augmentation[10];
  char augmentation[10];
  int iaug;
  int iaug;
  int code_alignment = 0;
  int code_alignment = 0;
 
 
  /* We should find the CIE at the start of the section.  */
  /* We should find the CIE at the start of the section.  */
 
 
  f = seg_info (now_seg)->frchainP->frch_root;
  f = seg_info (now_seg)->frchainP->frch_root;
  fix = seg_info (now_seg)->frchainP->fix_root;
  fix = seg_info (now_seg)->frchainP->fix_root;
 
 
  /* Look through the frags of the section to find the code alignment.  */
  /* Look through the frags of the section to find the code alignment.  */
 
 
  /* First make sure that the CIE Identifier Tag is 0/-1.  */
  /* First make sure that the CIE Identifier Tag is 0/-1.  */
 
 
  if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
  if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
    CIE_id = (char)0xff;
    CIE_id = (char)0xff;
  else
  else
    CIE_id = 0;
    CIE_id = 0;
 
 
  offset = 4;
  offset = 4;
  while (f != NULL && offset >= f->fr_fix)
  while (f != NULL && offset >= f->fr_fix)
    {
    {
      offset -= f->fr_fix;
      offset -= f->fr_fix;
      f = f->fr_next;
      f = f->fr_next;
    }
    }
  if (f == NULL
  if (f == NULL
      || f->fr_fix - offset < 4
      || f->fr_fix - offset < 4
      || f->fr_literal[offset] != CIE_id
      || f->fr_literal[offset] != CIE_id
      || f->fr_literal[offset + 1] != CIE_id
      || f->fr_literal[offset + 1] != CIE_id
      || f->fr_literal[offset + 2] != CIE_id
      || f->fr_literal[offset + 2] != CIE_id
      || f->fr_literal[offset + 3] != CIE_id)
      || f->fr_literal[offset + 3] != CIE_id)
    return 0;
    return 0;
 
 
  /* Next make sure the CIE version number is 1.  */
  /* Next make sure the CIE version number is 1.  */
 
 
  offset += 4;
  offset += 4;
  while (f != NULL && offset >= f->fr_fix)
  while (f != NULL && offset >= f->fr_fix)
    {
    {
      offset -= f->fr_fix;
      offset -= f->fr_fix;
      f = f->fr_next;
      f = f->fr_next;
    }
    }
  if (f == NULL
  if (f == NULL
      || f->fr_fix - offset < 1
      || f->fr_fix - offset < 1
      || f->fr_literal[offset] != 1)
      || f->fr_literal[offset] != 1)
    return 0;
    return 0;
 
 
  /* Skip the augmentation (a null terminated string).  */
  /* Skip the augmentation (a null terminated string).  */
 
 
  iaug = 0;
  iaug = 0;
  ++offset;
  ++offset;
  while (1)
  while (1)
    {
    {
      while (f != NULL && offset >= f->fr_fix)
      while (f != NULL && offset >= f->fr_fix)
        {
        {
          offset -= f->fr_fix;
          offset -= f->fr_fix;
          f = f->fr_next;
          f = f->fr_next;
        }
        }
      if (f == NULL)
      if (f == NULL)
        return 0;
        return 0;
 
 
      while (offset < f->fr_fix && f->fr_literal[offset] != '\0')
      while (offset < f->fr_fix && f->fr_literal[offset] != '\0')
        {
        {
          if ((size_t) iaug < (sizeof augmentation) - 1)
          if ((size_t) iaug < (sizeof augmentation) - 1)
            {
            {
              augmentation[iaug] = f->fr_literal[offset];
              augmentation[iaug] = f->fr_literal[offset];
              ++iaug;
              ++iaug;
            }
            }
          ++offset;
          ++offset;
        }
        }
      if (offset < f->fr_fix)
      if (offset < f->fr_fix)
        break;
        break;
    }
    }
  ++offset;
  ++offset;
  while (f != NULL && offset >= f->fr_fix)
  while (f != NULL && offset >= f->fr_fix)
    {
    {
      offset -= f->fr_fix;
      offset -= f->fr_fix;
      f = f->fr_next;
      f = f->fr_next;
    }
    }
  if (f == NULL)
  if (f == NULL)
    return 0;
    return 0;
 
 
  augmentation[iaug] = '\0';
  augmentation[iaug] = '\0';
  if (augmentation[0] == '\0')
  if (augmentation[0] == '\0')
    {
    {
      /* No augmentation.  */
      /* No augmentation.  */
    }
    }
  else if (strcmp (augmentation, "eh") == 0)
  else if (strcmp (augmentation, "eh") == 0)
    {
    {
      /* We have to skip a pointer.  Unfortunately, we don't know how
      /* We have to skip a pointer.  Unfortunately, we don't know how
         large it is.  We find out by looking for a matching fixup.  */
         large it is.  We find out by looking for a matching fixup.  */
      while (fix != NULL
      while (fix != NULL
             && (fix->fx_frag != f || fix->fx_where != offset))
             && (fix->fx_frag != f || fix->fx_where != offset))
        fix = fix->fx_next;
        fix = fix->fx_next;
      if (fix == NULL)
      if (fix == NULL)
        offset += 4;
        offset += 4;
      else
      else
        offset += fix->fx_size;
        offset += fix->fx_size;
      while (f != NULL && offset >= f->fr_fix)
      while (f != NULL && offset >= f->fr_fix)
        {
        {
          offset -= f->fr_fix;
          offset -= f->fr_fix;
          f = f->fr_next;
          f = f->fr_next;
        }
        }
      if (f == NULL)
      if (f == NULL)
        return 0;
        return 0;
    }
    }
  else if (augmentation[0] != 'z')
  else if (augmentation[0] != 'z')
    return 0;
    return 0;
 
 
  /* We're now at the code alignment factor, which is a ULEB128.  If
  /* We're now at the code alignment factor, which is a ULEB128.  If
     it isn't a single byte, forget it.  */
     it isn't a single byte, forget it.  */
 
 
  code_alignment = f->fr_literal[offset] & 0xff;
  code_alignment = f->fr_literal[offset] & 0xff;
  if ((code_alignment & 0x80) != 0)
  if ((code_alignment & 0x80) != 0)
    code_alignment = 0;
    code_alignment = 0;
 
 
  info->code_alignment = code_alignment;
  info->code_alignment = code_alignment;
  info->z_augmentation = (augmentation[0] == 'z');
  info->z_augmentation = (augmentation[0] == 'z');
 
 
  return 1;
  return 1;
}
}
 
 
/* This function is called from emit_expr.  It looks for cases which
/* This function is called from emit_expr.  It looks for cases which
   we can optimize.
   we can optimize.
 
 
   Rather than try to parse all this information as we read it, we
   Rather than try to parse all this information as we read it, we
   look for a single byte DW_CFA_advance_loc4 followed by a 4 byte
   look for a single byte DW_CFA_advance_loc4 followed by a 4 byte
   difference.  We turn that into a rs_cfa_advance frag, and handle
   difference.  We turn that into a rs_cfa_advance frag, and handle
   those frags at the end of the assembly.  If the gcc output changes
   those frags at the end of the assembly.  If the gcc output changes
   somewhat, this optimization may stop working.
   somewhat, this optimization may stop working.
 
 
   This function returns non-zero if it handled the expression and
   This function returns non-zero if it handled the expression and
   emit_expr should not do anything, or zero otherwise.  It can also
   emit_expr should not do anything, or zero otherwise.  It can also
   change *EXP and *PNBYTES.  */
   change *EXP and *PNBYTES.  */
 
 
int
int
check_eh_frame (expressionS *exp, unsigned int *pnbytes)
check_eh_frame (expressionS *exp, unsigned int *pnbytes)
{
{
  struct frame_data
  struct frame_data
  {
  {
    enum frame_state
    enum frame_state
    {
    {
      state_idle,
      state_idle,
      state_saw_size,
      state_saw_size,
      state_saw_cie_offset,
      state_saw_cie_offset,
      state_saw_pc_begin,
      state_saw_pc_begin,
      state_seeing_aug_size,
      state_seeing_aug_size,
      state_skipping_aug,
      state_skipping_aug,
      state_wait_loc4,
      state_wait_loc4,
      state_saw_loc4,
      state_saw_loc4,
      state_error,
      state_error,
    } state;
    } state;
 
 
    int cie_info_ok;
    int cie_info_ok;
    struct cie_info cie_info;
    struct cie_info cie_info;
 
 
    symbolS *size_end_sym;
    symbolS *size_end_sym;
    fragS *loc4_frag;
    fragS *loc4_frag;
    int loc4_fix;
    int loc4_fix;
 
 
    int aug_size;
    int aug_size;
    int aug_shift;
    int aug_shift;
  };
  };
 
 
  static struct frame_data eh_frame_data;
  static struct frame_data eh_frame_data;
  static struct frame_data debug_frame_data;
  static struct frame_data debug_frame_data;
  struct frame_data *d;
  struct frame_data *d;
 
 
  /* Don't optimize.  */
  /* Don't optimize.  */
  if (flag_traditional_format)
  if (flag_traditional_format)
    return 0;
    return 0;
 
 
#ifdef md_allow_eh_opt
#ifdef md_allow_eh_opt
  if (! md_allow_eh_opt)
  if (! md_allow_eh_opt)
    return 0;
    return 0;
#endif
#endif
 
 
  /* Select the proper section data.  */
  /* Select the proper section data.  */
  if (strcmp (segment_name (now_seg), ".eh_frame") == 0)
  if (strcmp (segment_name (now_seg), ".eh_frame") == 0)
    d = &eh_frame_data;
    d = &eh_frame_data;
  else if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
  else if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
    d = &debug_frame_data;
    d = &debug_frame_data;
  else
  else
    return 0;
    return 0;
 
 
  if (d->state >= state_saw_size && S_IS_DEFINED (d->size_end_sym))
  if (d->state >= state_saw_size && S_IS_DEFINED (d->size_end_sym))
    {
    {
      /* We have come to the end of the CIE or FDE.  See below where
      /* We have come to the end of the CIE or FDE.  See below where
         we set saw_size.  We must check this first because we may now
         we set saw_size.  We must check this first because we may now
         be looking at the next size.  */
         be looking at the next size.  */
      d->state = state_idle;
      d->state = state_idle;
    }
    }
 
 
  switch (d->state)
  switch (d->state)
    {
    {
    case state_idle:
    case state_idle:
      if (*pnbytes == 4)
      if (*pnbytes == 4)
        {
        {
          /* This might be the size of the CIE or FDE.  We want to know
          /* This might be the size of the CIE or FDE.  We want to know
             the size so that we don't accidentally optimize across an FDE
             the size so that we don't accidentally optimize across an FDE
             boundary.  We recognize the size in one of two forms: a
             boundary.  We recognize the size in one of two forms: a
             symbol which will later be defined as a difference, or a
             symbol which will later be defined as a difference, or a
             subtraction of two symbols.  Either way, we can tell when we
             subtraction of two symbols.  Either way, we can tell when we
             are at the end of the FDE because the symbol becomes defined
             are at the end of the FDE because the symbol becomes defined
             (in the case of a subtraction, the end symbol, from which the
             (in the case of a subtraction, the end symbol, from which the
             start symbol is being subtracted).  Other ways of describing
             start symbol is being subtracted).  Other ways of describing
             the size will not be optimized.  */
             the size will not be optimized.  */
          if ((exp->X_op == O_symbol || exp->X_op == O_subtract)
          if ((exp->X_op == O_symbol || exp->X_op == O_subtract)
              && ! S_IS_DEFINED (exp->X_add_symbol))
              && ! S_IS_DEFINED (exp->X_add_symbol))
            {
            {
              d->state = state_saw_size;
              d->state = state_saw_size;
              d->size_end_sym = exp->X_add_symbol;
              d->size_end_sym = exp->X_add_symbol;
            }
            }
        }
        }
      break;
      break;
 
 
    case state_saw_size:
    case state_saw_size:
    case state_saw_cie_offset:
    case state_saw_cie_offset:
      /* Assume whatever form it appears in, it appears atomically.  */
      /* Assume whatever form it appears in, it appears atomically.  */
      d->state += 1;
      d->state += 1;
      break;
      break;
 
 
    case state_saw_pc_begin:
    case state_saw_pc_begin:
      /* Decide whether we should see an augmentation.  */
      /* Decide whether we should see an augmentation.  */
      if (! d->cie_info_ok
      if (! d->cie_info_ok
          && ! (d->cie_info_ok = get_cie_info (&d->cie_info)))
          && ! (d->cie_info_ok = get_cie_info (&d->cie_info)))
        d->state = state_error;
        d->state = state_error;
      else if (d->cie_info.z_augmentation)
      else if (d->cie_info.z_augmentation)
        {
        {
          d->state = state_seeing_aug_size;
          d->state = state_seeing_aug_size;
          d->aug_size = 0;
          d->aug_size = 0;
          d->aug_shift = 0;
          d->aug_shift = 0;
        }
        }
      else
      else
        d->state = state_wait_loc4;
        d->state = state_wait_loc4;
      break;
      break;
 
 
    case state_seeing_aug_size:
    case state_seeing_aug_size:
      /* Bytes == -1 means this comes from an leb128 directive.  */
      /* Bytes == -1 means this comes from an leb128 directive.  */
      if ((int)*pnbytes == -1 && exp->X_op == O_constant)
      if ((int)*pnbytes == -1 && exp->X_op == O_constant)
        {
        {
          d->aug_size = exp->X_add_number;
          d->aug_size = exp->X_add_number;
          d->state = state_skipping_aug;
          d->state = state_skipping_aug;
        }
        }
      else if (*pnbytes == 1 && exp->X_op == O_constant)
      else if (*pnbytes == 1 && exp->X_op == O_constant)
        {
        {
          unsigned char byte = exp->X_add_number;
          unsigned char byte = exp->X_add_number;
          d->aug_size |= (byte & 0x7f) << d->aug_shift;
          d->aug_size |= (byte & 0x7f) << d->aug_shift;
          d->aug_shift += 7;
          d->aug_shift += 7;
          if ((byte & 0x80) == 0)
          if ((byte & 0x80) == 0)
            d->state = state_skipping_aug;
            d->state = state_skipping_aug;
        }
        }
      else
      else
        d->state = state_error;
        d->state = state_error;
      if (d->state == state_skipping_aug && d->aug_size == 0)
      if (d->state == state_skipping_aug && d->aug_size == 0)
        d->state = state_wait_loc4;
        d->state = state_wait_loc4;
      break;
      break;
 
 
    case state_skipping_aug:
    case state_skipping_aug:
      if ((int)*pnbytes < 0)
      if ((int)*pnbytes < 0)
        d->state = state_error;
        d->state = state_error;
      else
      else
        {
        {
          int left = (d->aug_size -= *pnbytes);
          int left = (d->aug_size -= *pnbytes);
          if (left == 0)
          if (left == 0)
            d->state = state_wait_loc4;
            d->state = state_wait_loc4;
          else if (left < 0)
          else if (left < 0)
            d->state = state_error;
            d->state = state_error;
        }
        }
      break;
      break;
 
 
    case state_wait_loc4:
    case state_wait_loc4:
      if (*pnbytes == 1
      if (*pnbytes == 1
          && exp->X_op == O_constant
          && exp->X_op == O_constant
          && exp->X_add_number == DW_CFA_advance_loc4)
          && exp->X_add_number == DW_CFA_advance_loc4)
        {
        {
          /* This might be a DW_CFA_advance_loc4.  Record the frag and the
          /* This might be a DW_CFA_advance_loc4.  Record the frag and the
             position within the frag, so that we can change it later.  */
             position within the frag, so that we can change it later.  */
          frag_grow (1);
          frag_grow (1);
          d->state = state_saw_loc4;
          d->state = state_saw_loc4;
          d->loc4_frag = frag_now;
          d->loc4_frag = frag_now;
          d->loc4_fix = frag_now_fix ();
          d->loc4_fix = frag_now_fix ();
        }
        }
      break;
      break;
 
 
    case state_saw_loc4:
    case state_saw_loc4:
      d->state = state_wait_loc4;
      d->state = state_wait_loc4;
      if (*pnbytes != 4)
      if (*pnbytes != 4)
        break;
        break;
      if (exp->X_op == O_constant)
      if (exp->X_op == O_constant)
        {
        {
          /* This is a case which we can optimize.  The two symbols being
          /* This is a case which we can optimize.  The two symbols being
             subtracted were in the same frag and the expression was
             subtracted were in the same frag and the expression was
             reduced to a constant.  We can do the optimization entirely
             reduced to a constant.  We can do the optimization entirely
             in this function.  */
             in this function.  */
          if (d->cie_info.code_alignment > 0
          if (d->cie_info.code_alignment > 0
              && exp->X_add_number % d->cie_info.code_alignment == 0
              && exp->X_add_number % d->cie_info.code_alignment == 0
              && exp->X_add_number / d->cie_info.code_alignment < 0x40)
              && exp->X_add_number / d->cie_info.code_alignment < 0x40)
            {
            {
              d->loc4_frag->fr_literal[d->loc4_fix]
              d->loc4_frag->fr_literal[d->loc4_fix]
                = DW_CFA_advance_loc
                = DW_CFA_advance_loc
                  | (exp->X_add_number / d->cie_info.code_alignment);
                  | (exp->X_add_number / d->cie_info.code_alignment);
              /* No more bytes needed.  */
              /* No more bytes needed.  */
              return 1;
              return 1;
            }
            }
          else if (exp->X_add_number < 0x100)
          else if (exp->X_add_number < 0x100)
            {
            {
              d->loc4_frag->fr_literal[d->loc4_fix] = DW_CFA_advance_loc1;
              d->loc4_frag->fr_literal[d->loc4_fix] = DW_CFA_advance_loc1;
              *pnbytes = 1;
              *pnbytes = 1;
            }
            }
          else if (exp->X_add_number < 0x10000)
          else if (exp->X_add_number < 0x10000)
            {
            {
              d->loc4_frag->fr_literal[d->loc4_fix] = DW_CFA_advance_loc2;
              d->loc4_frag->fr_literal[d->loc4_fix] = DW_CFA_advance_loc2;
              *pnbytes = 2;
              *pnbytes = 2;
            }
            }
        }
        }
      else if (exp->X_op == O_subtract)
      else if (exp->X_op == O_subtract)
        {
        {
          /* This is a case we can optimize.  The expression was not
          /* This is a case we can optimize.  The expression was not
             reduced, so we can not finish the optimization until the end
             reduced, so we can not finish the optimization until the end
             of the assembly.  We set up a variant frag which we handle
             of the assembly.  We set up a variant frag which we handle
             later.  */
             later.  */
          int fr_subtype;
          int fr_subtype;
 
 
          if (d->cie_info.code_alignment > 0)
          if (d->cie_info.code_alignment > 0)
            fr_subtype = d->cie_info.code_alignment << 3;
            fr_subtype = d->cie_info.code_alignment << 3;
          else
          else
            fr_subtype = 0;
            fr_subtype = 0;
 
 
          frag_var (rs_cfa, 4, 0, fr_subtype, make_expr_symbol (exp),
          frag_var (rs_cfa, 4, 0, fr_subtype, make_expr_symbol (exp),
                    d->loc4_fix, (char *) d->loc4_frag);
                    d->loc4_fix, (char *) d->loc4_frag);
          return 1;
          return 1;
        }
        }
      break;
      break;
 
 
    case state_error:
    case state_error:
      /* Just skipping everything.  */
      /* Just skipping everything.  */
      break;
      break;
    }
    }
 
 
  return 0;
  return 0;
}
}
 
 
/* The function estimates the size of a rs_cfa variant frag based on
/* The function estimates the size of a rs_cfa variant frag based on
   the current values of the symbols.  It is called before the
   the current values of the symbols.  It is called before the
   relaxation loop.  We set fr_subtype{0:2} to the expected length.  */
   relaxation loop.  We set fr_subtype{0:2} to the expected length.  */
 
 
int
int
eh_frame_estimate_size_before_relax (fragS *frag)
eh_frame_estimate_size_before_relax (fragS *frag)
{
{
  offsetT diff;
  offsetT diff;
  int ca = frag->fr_subtype >> 3;
  int ca = frag->fr_subtype >> 3;
  int ret;
  int ret;
 
 
  diff = resolve_symbol_value (frag->fr_symbol);
  diff = resolve_symbol_value (frag->fr_symbol);
 
 
  if (ca > 0 && diff % ca == 0 && diff / ca < 0x40)
  if (ca > 0 && diff % ca == 0 && diff / ca < 0x40)
    ret = 0;
    ret = 0;
  else if (diff < 0x100)
  else if (diff < 0x100)
    ret = 1;
    ret = 1;
  else if (diff < 0x10000)
  else if (diff < 0x10000)
    ret = 2;
    ret = 2;
  else
  else
    ret = 4;
    ret = 4;
 
 
  frag->fr_subtype = (frag->fr_subtype & ~7) | ret;
  frag->fr_subtype = (frag->fr_subtype & ~7) | ret;
 
 
  return ret;
  return ret;
}
}
 
 
/* This function relaxes a rs_cfa variant frag based on the current
/* This function relaxes a rs_cfa variant frag based on the current
   values of the symbols.  fr_subtype{0:2} is the current length of
   values of the symbols.  fr_subtype{0:2} is the current length of
   the frag.  This returns the change in frag length.  */
   the frag.  This returns the change in frag length.  */
 
 
int
int
eh_frame_relax_frag (fragS *frag)
eh_frame_relax_frag (fragS *frag)
{
{
  int oldsize, newsize;
  int oldsize, newsize;
 
 
  oldsize = frag->fr_subtype & 7;
  oldsize = frag->fr_subtype & 7;
  newsize = eh_frame_estimate_size_before_relax (frag);
  newsize = eh_frame_estimate_size_before_relax (frag);
  return newsize - oldsize;
  return newsize - oldsize;
}
}
 
 
/* This function converts a rs_cfa variant frag into a normal fill
/* This function converts a rs_cfa variant frag into a normal fill
   frag.  This is called after all relaxation has been done.
   frag.  This is called after all relaxation has been done.
   fr_subtype{0:2} will be the desired length of the frag.  */
   fr_subtype{0:2} will be the desired length of the frag.  */
 
 
void
void
eh_frame_convert_frag (fragS *frag)
eh_frame_convert_frag (fragS *frag)
{
{
  offsetT diff;
  offsetT diff;
  fragS *loc4_frag;
  fragS *loc4_frag;
  int loc4_fix;
  int loc4_fix;
 
 
  loc4_frag = (fragS *) frag->fr_opcode;
  loc4_frag = (fragS *) frag->fr_opcode;
  loc4_fix = (int) frag->fr_offset;
  loc4_fix = (int) frag->fr_offset;
 
 
  diff = resolve_symbol_value (frag->fr_symbol);
  diff = resolve_symbol_value (frag->fr_symbol);
 
 
  switch (frag->fr_subtype & 7)
  switch (frag->fr_subtype & 7)
    {
    {
    case 0:
    case 0:
      {
      {
        int ca = frag->fr_subtype >> 3;
        int ca = frag->fr_subtype >> 3;
        assert (ca > 0 && diff % ca == 0 && diff / ca < 0x40);
        assert (ca > 0 && diff % ca == 0 && diff / ca < 0x40);
        loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc | (diff / ca);
        loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc | (diff / ca);
      }
      }
      break;
      break;
 
 
    case 1:
    case 1:
      assert (diff < 0x100);
      assert (diff < 0x100);
      loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc1;
      loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc1;
      frag->fr_literal[frag->fr_fix] = diff;
      frag->fr_literal[frag->fr_fix] = diff;
      break;
      break;
 
 
    case 2:
    case 2:
      assert (diff < 0x10000);
      assert (diff < 0x10000);
      loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc2;
      loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc2;
      md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 2);
      md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 2);
      break;
      break;
 
 
    default:
    default:
      md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 4);
      md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 4);
      break;
      break;
    }
    }
 
 
  frag->fr_fix += frag->fr_subtype & 7;
  frag->fr_fix += frag->fr_subtype & 7;
  frag->fr_type = rs_fill;
  frag->fr_type = rs_fill;
  frag->fr_subtype = 0;
  frag->fr_subtype = 0;
  frag->fr_offset = 0;
  frag->fr_offset = 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.