if (((val > 0) && (val & ~0x3ff)) || ((val < 0) && (~(val - 1) & ~0x3ff))) { as_bad ("relocation overflow."); }
if (! in_signed_range (val, 0x3ff)) as_bad ("relocation overflow.");
md_apply_fix (fixP, value)     fixS *fixP;     valueT *value;{  char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;  offsetT val;  val = *value;  assert (fixP->fx_r_type < BFD_RELOC_UNUSED);  fixP->fx_addnumber = val;	/* Remember value for emit_reloc */#ifdef OBJ_ELF  /* FIXME: SPARC ELF relocations don't use an addend in the data     field itself.  This whole approach should be somehow combined     with the calls to bfd_perform_relocation.  Also, the value passed     in by fixup_segment includes the value of a defined symbol.  We     don't want to include the value of an externally visible symbol.  */  if (fixP->fx_addsy != NULL)    {      if ((S_IS_EXTERN (fixP->fx_addsy)	   || (sparc_pic_code && ! fixP->fx_pcrel))	  && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section	  && S_GET_SEGMENT (fixP->fx_addsy) != undefined_section	  && ! bfd_is_com_section (S_GET_SEGMENT (fixP->fx_addsy)))	fixP->fx_addnumber -= S_GET_VALUE (fixP->fx_addsy);      return 1;    }#endif  /* This is a hack.  There should be a better way to     handle this.  Probably in terms of howto fields, once     we can look at these fixups in terms of howtos.  */  if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)    val += fixP->fx_where + fixP->fx_frag->fr_address;#ifdef OBJ_AOUT  /* FIXME: More ridiculous gas reloc hacking.  If we are going to     generate a reloc, then we just want to let the reloc addend set     the value.  We do not want to also stuff the addend into the     object file.  Including the addend in the object file works when     doing a static link, because the linker will ignore the object     file contents.  However, the dynamic linker does not ignore the     object file contents.  */  if (fixP->fx_addsy != NULL      && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2)    val = 0;  /* When generating PIC code, we do not want an addend for a reloc     against a local symbol.  We adjust fx_addnumber to cancel out the     value already included in val, and to also cancel out the     adjustment which bfd_install_relocation will create.  */  if (sparc_pic_code      && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2      && fixP->fx_addsy != NULL      && ! S_IS_COMMON (fixP->fx_addsy)      && (fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) == 0)    fixP->fx_addnumber -= 2 * S_GET_VALUE (fixP->fx_addsy);#endif  switch (fixP->fx_r_type)    {    case BFD_RELOC_16:      buf[0] = val >> 8;      buf[1] = val;      break;    case BFD_RELOC_32:      buf[0] = val >> 24;      buf[1] = val >> 16;      buf[2] = val >> 8;      buf[3] = val;      break;    case BFD_RELOC_32_PCREL_S2:      val = (val >>= 2);      if (! sparc_pic_code	  || fixP->fx_addsy == NULL	  || (fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)	++val;      buf[0] |= (val >> 24) & 0x3f;      buf[1] = (val >> 16);      buf[2] = val >> 8;      buf[3] = val;      break;#ifndef NO_V9    case BFD_RELOC_64:      {	bfd_vma valh = BSR (val, 32);	buf[0] = valh >> 24;	buf[1] = valh >> 16;	buf[2] = valh >> 8;	buf[3] = valh;	buf[4] = val >> 24;	buf[5] = val >> 16;	buf[6] = val >> 8;	buf[7] = val;      }      break;    case BFD_RELOC_SPARC_11:      if (((val > 0) && (val & ~0x7ff))	  || ((val < 0) && (~(val - 1) & ~0x7ff)))	{	  as_bad ("relocation overflow.");	}			/* on overflow */      buf[2] |= (val >> 8) & 0x7;      buf[3] = val & 0xff;      break;    case BFD_RELOC_SPARC_10:      if (((val > 0) && (val & ~0x3ff))	  || ((val < 0) && (~(val - 1) & ~0x3ff)))	{	  as_bad ("relocation overflow.");	}			/* on overflow */      buf[2] |= (val >> 8) & 0x3;      buf[3] = val & 0xff;      break;    case BFD_RELOC_SPARC_WDISP16:      if (((val > 0) && (val & ~0x3fffc))	  || ((val < 0) && (~(val - 1) & ~0x3fffc)))	{	  as_bad ("relocation overflow.");	}			/* on overflow */      val = (val >>= 2) + 1;      buf[1] |= ((val >> 14) & 0x3) << 4;      buf[2] |= (val >> 8) & 0x3f;      buf[3] = val & 0xff;      break;    case BFD_RELOC_SPARC_WDISP19:      if (((val > 0) && (val & ~0x1ffffc))	  || ((val < 0) && (~(val - 1) & ~0x1ffffc)))	{	  as_bad ("relocation overflow.");	}			/* on overflow */      val = (val >>= 2) + 1;      buf[1] |= (val >> 16) & 0x7;      buf[2] = (val >> 8) & 0xff;      buf[3] = val & 0xff;      break;    case BFD_RELOC_SPARC_HH22:      val = BSR (val, 32);      /* intentional fallthrough */#endif /* NO_V9 */#ifndef NO_V9    case BFD_RELOC_SPARC_LM22:#endif    case BFD_RELOC_HI22:      if (!fixP->fx_addsy)	{	  buf[1] |= (val >> 26) & 0x3f;	  buf[2] = val >> 18;	  buf[3] = val >> 10;	}      else	{	  buf[2] = 0;	  buf[3] = 0;	}      break;    case BFD_RELOC_SPARC22:      if (val & ~0x003fffff)	{	  as_bad ("relocation overflow");	}			/* on overflow */      buf[1] |= (val >> 16) & 0x3f;      buf[2] = val >> 8;      buf[3] = val & 0xff;      break;#ifndef NO_V9    case BFD_RELOC_SPARC_HM10:      val = BSR (val, 32);      /* intentional fallthrough */#endif /* NO_V9 */    case BFD_RELOC_LO10:      if (!fixP->fx_addsy)	{	  buf[2] |= (val >> 8) & 0x03;	  buf[3] = val;	}      else	buf[3] = 0;      break;    case BFD_RELOC_SPARC13:      if (! in_signed_range (val, 0x1fff))	as_bad ("relocation overflow");      buf[2] |= (val >> 8) & 0x1f;      buf[3] = val;      break;    case BFD_RELOC_SPARC_WDISP22:      val = (val >> 2) + 1;      /* FALLTHROUGH */    case BFD_RELOC_SPARC_BASE22:      buf[1] |= (val >> 16) & 0x3f;      buf[2] = val >> 8;      buf[3] = val;      break;    case BFD_RELOC_NONE:    default:      as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);      break;    }  /* Are we finished with this relocation now?  */  if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)    fixP->fx_done = 1;  return 1;}