(linenum→info "unix/slp.c:2238")

binutils/2.18/bfd/coff-sh.c

    1: /* BFD back-end for Renesas Super-H COFF binaries.
    2:    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
    3:    2003, 2004, 2005, 2007 Free Software Foundation, Inc.
    4:    Contributed by Cygnus Support.
    5:    Written by Steve Chamberlain, <sac@cygnus.com>.
    6:    Relaxing code written by Ian Lance Taylor, <ian@cygnus.com>.
    7: 
    8:    This file is part of BFD, the Binary File Descriptor library.
    9: 
   10:    This program is free software; you can redistribute it and/or modify
   11:    it under the terms of the GNU General Public License as published by
   12:    the Free Software Foundation; either version 3 of the License, or
   13:    (at your option) any later version.
   14: 
   15:    This program is distributed in the hope that it will be useful,
   16:    but WITHOUT ANY WARRANTY; without even the implied warranty of
   17:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18:    GNU General Public License for more details.
   19: 
   20:    You should have received a copy of the GNU General Public License
   21:    along with this program; if not, write to the Free Software
   22:    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   23:    MA 02110-1301, USA.  */
   24: 
   25: #include "sysdep.h"
   26: #include "bfd.h"
   27: #include "libiberty.h"
   28: #include "libbfd.h"
   29: #include "bfdlink.h"
   30: #include "coff/sh.h"
   31: #include "coff/internal.h"
   32: 
   33: #ifdef COFF_WITH_PE
   34: #include "coff/pe.h"
   35: 
   36: #ifndef COFF_IMAGE_WITH_PE
   37: static bfd_boolean sh_align_load_span
   38:   PARAMS ((bfd *, asection *, bfd_byte *,
   39:            bfd_boolean (*) (bfd *, asection *, PTR, bfd_byte *, bfd_vma),
   40:            PTR, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bfd_boolean *));
   41: 
   42: #define _bfd_sh_align_load_span sh_align_load_span
   43: #endif
   44: #endif
   45: 
   46: #include "libcoff.h"
   47: 
   48: /* Internal functions.  */
   49: static bfd_reloc_status_type sh_reloc
   50:   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
   51: static long get_symbol_value PARAMS ((asymbol *));
   52: static bfd_boolean sh_relax_section
   53:   PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
   54: static bfd_boolean sh_relax_delete_bytes
   55:   PARAMS ((bfd *, asection *, bfd_vma, int));
   56: #ifndef COFF_IMAGE_WITH_PE
   57: static const struct sh_opcode *sh_insn_info PARAMS ((unsigned int));
   58: #endif
   59: static bfd_boolean sh_align_loads
   60:   PARAMS ((bfd *, asection *, struct internal_reloc *, bfd_byte *,
   61:            bfd_boolean *));
   62: static bfd_boolean sh_swap_insns
   63:   PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma));
   64: static bfd_boolean sh_relocate_section
   65:   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
   66:            struct internal_reloc *, struct internal_syment *, asection **));
   67: static bfd_byte *sh_coff_get_relocated_section_contents
   68:   PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
   69:            bfd_byte *, bfd_boolean, asymbol **));
   70: static reloc_howto_type * sh_coff_reloc_type_lookup PARAMS ((bfd *, bfd_reloc_code_real_type));
   71: 
   72: #ifdef COFF_WITH_PE
   73: /* Can't build import tables with 2**4 alignment.  */
   74: #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER    2
   75: #else
   76: /* Default section alignment to 2**4.  */
   77: #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER    4
   78: #endif
   79: 
   80: #ifdef COFF_IMAGE_WITH_PE
   81: /* Align PE executables.  */
   82: #define COFF_PAGE_SIZE 0x1000
   83: #endif
   84: 
   85: /* Generate long file names.  */
   86: #define COFF_LONG_FILENAMES
   87: 
   88: #ifdef COFF_WITH_PE
   89: static bfd_boolean in_reloc_p PARAMS ((bfd *, reloc_howto_type *));
   90: /* Return TRUE if this relocation should
   91:    appear in the output .reloc section.  */
   92: static bfd_boolean in_reloc_p (abfd, howto)
   93:      bfd * abfd ATTRIBUTE_UNUSED;
   94:      reloc_howto_type * howto;
   95: {
   96:   return ! howto->pc_relative && howto->type != R_SH_IMAGEBASE;
   97: }
   98: #endif
   99: 
  100: /* The supported relocations.  There are a lot of relocations defined
  101:    in coff/internal.h which we do not expect to ever see.  */
  102: static reloc_howto_type sh_coff_howtos[] =
  103: {
  104:   EMPTY_HOWTO (0),
  105:   EMPTY_HOWTO (1),
  106: #ifdef COFF_WITH_PE
  107:   /* Windows CE */
  108:   HOWTO (R_SH_IMM32CE,          /* type */
  109:          0,                    /* rightshift */
  110:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  111:          32,                   /* bitsize */
  112:          FALSE,                        /* pc_relative */
  113:          0,                    /* bitpos */
  114:          complain_overflow_bitfield, /* complain_on_overflow */
  115:          sh_reloc,             /* special_function */
  116:          "r_imm32ce",          /* name */
  117:          TRUE,                 /* partial_inplace */
  118:          0xffffffff,           /* src_mask */
  119:          0xffffffff,           /* dst_mask */
  120:          FALSE),               /* pcrel_offset */
  121: #else
  122:   EMPTY_HOWTO (2),
  123: #endif
  124:   EMPTY_HOWTO (3), /* R_SH_PCREL8 */
  125:   EMPTY_HOWTO (4), /* R_SH_PCREL16 */
  126:   EMPTY_HOWTO (5), /* R_SH_HIGH8 */
  127:   EMPTY_HOWTO (6), /* R_SH_IMM24 */
  128:   EMPTY_HOWTO (7), /* R_SH_LOW16 */
  129:   EMPTY_HOWTO (8),
  130:   EMPTY_HOWTO (9), /* R_SH_PCDISP8BY4 */
  131: 
  132:   HOWTO (R_SH_PCDISP8BY2,       /* type */
  133:          1,                    /* rightshift */
  134:          1,                    /* size (0 = byte, 1 = short, 2 = long) */
  135:          8,                    /* bitsize */
  136:          TRUE,                 /* pc_relative */
  137:          0,                    /* bitpos */
  138:          complain_overflow_signed, /* complain_on_overflow */
  139:          sh_reloc,             /* special_function */
  140:          "r_pcdisp8by2",       /* name */
  141:          TRUE,                 /* partial_inplace */
  142:          0xff,                 /* src_mask */
  143:          0xff,                 /* dst_mask */
  144:          TRUE),                        /* pcrel_offset */
  145: 
  146:   EMPTY_HOWTO (11), /* R_SH_PCDISP8 */
  147: 
  148:   HOWTO (R_SH_PCDISP,           /* type */
  149:          1,                    /* rightshift */
  150:          1,                    /* size (0 = byte, 1 = short, 2 = long) */
  151:          12,                   /* bitsize */
  152:          TRUE,                 /* pc_relative */
  153:          0,                    /* bitpos */
  154:          complain_overflow_signed, /* complain_on_overflow */
  155:          sh_reloc,             /* special_function */
  156:          "r_pcdisp12by2",      /* name */
  157:          TRUE,                 /* partial_inplace */
  158:          0xfff,                        /* src_mask */
  159:          0xfff,                        /* dst_mask */
  160:          TRUE),                        /* pcrel_offset */
  161: 
  162:   EMPTY_HOWTO (13),
  163: 
  164:   HOWTO (R_SH_IMM32,            /* type */
  165:          0,                    /* rightshift */
  166:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  167:          32,                   /* bitsize */
  168:          FALSE,                        /* pc_relative */
  169:          0,                    /* bitpos */
  170:          complain_overflow_bitfield, /* complain_on_overflow */
  171:          sh_reloc,             /* special_function */
  172:          "r_imm32",            /* name */
  173:          TRUE,                 /* partial_inplace */
  174:          0xffffffff,           /* src_mask */
  175:          0xffffffff,           /* dst_mask */
  176:          FALSE),               /* pcrel_offset */
  177: 
  178:   EMPTY_HOWTO (15),
  179: #ifdef COFF_WITH_PE
  180:   HOWTO (R_SH_IMAGEBASE,        /* type */
  181:          0,                    /* rightshift */
  182:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  183:          32,                   /* bitsize */
  184:          FALSE,                        /* pc_relative */
  185:          0,                    /* bitpos */
  186:          complain_overflow_bitfield, /* complain_on_overflow */
  187:          sh_reloc,             /* special_function */
  188:          "rva32",              /* name */
  189:          TRUE,                 /* partial_inplace */
  190:          0xffffffff,            /* src_mask */
  191:          0xffffffff,            /* dst_mask */
  192:          FALSE),                /* pcrel_offset */
  193: #else
  194:   EMPTY_HOWTO (16), /* R_SH_IMM8 */
  195: #endif
  196:   EMPTY_HOWTO (17), /* R_SH_IMM8BY2 */
  197:   EMPTY_HOWTO (18), /* R_SH_IMM8BY4 */
  198:   EMPTY_HOWTO (19), /* R_SH_IMM4 */
  199:   EMPTY_HOWTO (20), /* R_SH_IMM4BY2 */
  200:   EMPTY_HOWTO (21), /* R_SH_IMM4BY4 */
  201: 
  202:   HOWTO (R_SH_PCRELIMM8BY2,     /* type */
  203:          1,                    /* rightshift */
  204:          1,                    /* size (0 = byte, 1 = short, 2 = long) */
  205:          8,                    /* bitsize */
  206:          TRUE,                 /* pc_relative */
  207:          0,                    /* bitpos */
  208:          complain_overflow_unsigned, /* complain_on_overflow */
  209:          sh_reloc,             /* special_function */
  210:          "r_pcrelimm8by2",     /* name */
  211:          TRUE,                 /* partial_inplace */
  212:          0xff,                 /* src_mask */
  213:          0xff,                 /* dst_mask */
  214:          TRUE),                        /* pcrel_offset */
  215: 
  216:   HOWTO (R_SH_PCRELIMM8BY4,     /* type */
  217:          2,                    /* rightshift */
  218:          1,                    /* size (0 = byte, 1 = short, 2 = long) */
  219:          8,                    /* bitsize */
  220:          TRUE,                 /* pc_relative */
  221:          0,                    /* bitpos */
  222:          complain_overflow_unsigned, /* complain_on_overflow */
  223:          sh_reloc,             /* special_function */
  224:          "r_pcrelimm8by4",     /* name */
  225:          TRUE,                 /* partial_inplace */
  226:          0xff,                 /* src_mask */
  227:          0xff,                 /* dst_mask */
  228:          TRUE),                        /* pcrel_offset */
  229: 
  230:   HOWTO (R_SH_IMM16,            /* type */
  231:          0,                    /* rightshift */
  232:          1,                    /* size (0 = byte, 1 = short, 2 = long) */
  233:          16,                   /* bitsize */
  234:          FALSE,                        /* pc_relative */
  235:          0,                    /* bitpos */
  236:          complain_overflow_bitfield, /* complain_on_overflow */
  237:          sh_reloc,             /* special_function */
  238:          "r_imm16",            /* name */
  239:          TRUE,                 /* partial_inplace */
  240:          0xffff,               /* src_mask */
  241:          0xffff,               /* dst_mask */
  242:          FALSE),               /* pcrel_offset */
  243: 
  244:   HOWTO (R_SH_SWITCH16,         /* type */
  245:          0,                    /* rightshift */
  246:          1,                    /* size (0 = byte, 1 = short, 2 = long) */
  247:          16,                   /* bitsize */
  248:          FALSE,                        /* pc_relative */
  249:          0,                    /* bitpos */
  250:          complain_overflow_bitfield, /* complain_on_overflow */
  251:          sh_reloc,             /* special_function */
  252:          "r_switch16",         /* name */
  253:          TRUE,                 /* partial_inplace */
  254:          0xffff,               /* src_mask */
  255:          0xffff,               /* dst_mask */
  256:          FALSE),               /* pcrel_offset */
  257: 
  258:   HOWTO (R_SH_SWITCH32,         /* type */
  259:          0,                    /* rightshift */
  260:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  261:          32,                   /* bitsize */
  262:          FALSE,                        /* pc_relative */
  263:          0,                    /* bitpos */
  264:          complain_overflow_bitfield, /* complain_on_overflow */
  265:          sh_reloc,             /* special_function */
  266:          "r_switch32",         /* name */
  267:          TRUE,                 /* partial_inplace */
  268:          0xffffffff,           /* src_mask */
  269:          0xffffffff,           /* dst_mask */
  270:          FALSE),               /* pcrel_offset */
  271: 
  272:   HOWTO (R_SH_USES,             /* type */
  273:          0,                    /* rightshift */
  274:          1,                    /* size (0 = byte, 1 = short, 2 = long) */
  275:          16,                   /* bitsize */
  276:          FALSE,                        /* pc_relative */
  277:          0,                    /* bitpos */
  278:          complain_overflow_bitfield, /* complain_on_overflow */
  279:          sh_reloc,             /* special_function */
  280:          "r_uses",             /* name */
  281:          TRUE,                 /* partial_inplace */
  282:          0xffff,               /* src_mask */
  283:          0xffff,               /* dst_mask */
  284:          FALSE),               /* pcrel_offset */
  285: 
  286:   HOWTO (R_SH_COUNT,            /* type */
  287:          0,                    /* rightshift */
  288:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  289:          32,                   /* bitsize */
  290:          FALSE,                        /* pc_relative */
  291:          0,                    /* bitpos */
  292:          complain_overflow_bitfield, /* complain_on_overflow */
  293:          sh_reloc,             /* special_function */
  294:          "r_count",            /* name */
  295:          TRUE,                 /* partial_inplace */
  296:          0xffffffff,           /* src_mask */
  297:          0xffffffff,           /* dst_mask */
  298:          FALSE),               /* pcrel_offset */
  299: 
  300:   HOWTO (R_SH_ALIGN,            /* type */
  301:          0,                    /* rightshift */
  302:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  303:          32,                   /* bitsize */
  304:          FALSE,                        /* pc_relative */
  305:          0,                    /* bitpos */
  306:          complain_overflow_bitfield, /* complain_on_overflow */
  307:          sh_reloc,             /* special_function */
  308:          "r_align",            /* name */
  309:          TRUE,                 /* partial_inplace */
  310:          0xffffffff,           /* src_mask */
  311:          0xffffffff,           /* dst_mask */
  312:          FALSE),               /* pcrel_offset */
  313: 
  314:   HOWTO (R_SH_CODE,             /* type */
  315:          0,                    /* rightshift */
  316:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  317:          32,                   /* bitsize */
  318:          FALSE,                        /* pc_relative */
  319:          0,                    /* bitpos */
  320:          complain_overflow_bitfield, /* complain_on_overflow */
  321:          sh_reloc,             /* special_function */
  322:          "r_code",             /* name */
  323:          TRUE,                 /* partial_inplace */
  324:          0xffffffff,           /* src_mask */
  325:          0xffffffff,           /* dst_mask */
  326:          FALSE),               /* pcrel_offset */
  327: 
  328:   HOWTO (R_SH_DATA,             /* type */
  329:          0,                    /* rightshift */
  330:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  331:          32,                   /* bitsize */
  332:          FALSE,                        /* pc_relative */
  333:          0,                    /* bitpos */
  334:          complain_overflow_bitfield, /* complain_on_overflow */
  335:          sh_reloc,             /* special_function */
  336:          "r_data",             /* name */
  337:          TRUE,                 /* partial_inplace */
  338:          0xffffffff,           /* src_mask */
  339:          0xffffffff,           /* dst_mask */
  340:          FALSE),               /* pcrel_offset */
  341: 
  342:   HOWTO (R_SH_LABEL,            /* type */
  343:          0,                    /* rightshift */
  344:          2,                    /* size (0 = byte, 1 = short, 2 = long) */
  345:          32,                   /* bitsize */
  346:          FALSE,                        /* pc_relative */
  347:          0,                    /* bitpos */
  348:          complain_overflow_bitfield, /* complain_on_overflow */
  349:          sh_reloc,             /* special_function */
  350:          "r_label",            /* name */
  351:          TRUE,                 /* partial_inplace */
  352:          0xffffffff,           /* src_mask */
  353:          0xffffffff,           /* dst_mask */
  354:          FALSE),               /* pcrel_offset */
  355: 
  356:   HOWTO (R_SH_SWITCH8,          /* type */
  357:          0,                    /* rightshift */
  358:          0,                    /* size (0 = byte, 1 = short, 2 = long) */
  359:          8,                    /* bitsize */
  360:          FALSE,                        /* pc_relative */
  361:          0,                    /* bitpos */
  362:          complain_overflow_bitfield, /* complain_on_overflow */
  363:          sh_reloc,             /* special_function */
  364:          "r_switch8",          /* name */
  365:          TRUE,                 /* partial_inplace */
  366:          0xff,                 /* src_mask */
  367:          0xff,                 /* dst_mask */
  368:          FALSE)                        /* pcrel_offset */
  369: };
  370: 
  371: #define SH_COFF_HOWTO_COUNT (sizeof sh_coff_howtos / sizeof sh_coff_howtos[0])
  372: 
  373: /* Check for a bad magic number.  */
  374: #define BADMAG(x) SHBADMAG(x)
  375: 
  376: /* Customize coffcode.h (this is not currently used).  */
  377: #define SH 1
  378: 
  379: /* FIXME: This should not be set here.  */
  380: #define __A_MAGIC_SET__
  381: 
  382: #ifndef COFF_WITH_PE
  383: /* Swap the r_offset field in and out.  */
  384: #define SWAP_IN_RELOC_OFFSET  H_GET_32
  385: #define SWAP_OUT_RELOC_OFFSET H_PUT_32
  386: 
  387: /* Swap out extra information in the reloc structure.  */
  388: #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst)    \
  389:   do                                            \
  390:     {                                           \
  391:       dst->r_stuff[0] = 'S';                    \
  392:       dst->r_stuff[1] = 'C';                    \
  393:     }                                           \
  394:   while (0)
  395: #endif
  396: 
  397: /* Get the value of a symbol, when performing a relocation.  */
  398: 
  399: static long
  400: get_symbol_value (symbol)
  401:      asymbol *symbol;
  402: {
  403:   bfd_vma relocation;
  404: 
  405:   if (bfd_is_com_section (symbol->section))
  406:     relocation = 0;
  407:   else
  408:     relocation = (symbol->value +
  409:                   symbol->section->output_section->vma +
  410:                   symbol->section->output_offset);
  411: 
  412:   return relocation;
  413: }
  414: 
  415: #ifdef COFF_WITH_PE
  416: /* Convert an rtype to howto for the COFF backend linker.
  417:    Copied from coff-i386.  */
  418: #define coff_rtype_to_howto coff_sh_rtype_to_howto
  419: static reloc_howto_type * coff_sh_rtype_to_howto PARAMS ((bfd *, asection *, struct internal_reloc *, struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *));
  420: 
  421: static reloc_howto_type *
  422: coff_sh_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
  423:      bfd * abfd ATTRIBUTE_UNUSED;
  424:      asection * sec;
  425:      struct internal_reloc * rel;
  426:      struct coff_link_hash_entry * h;
  427:      struct internal_syment * sym;
  428:      bfd_vma * addendp;
  429: {
  430:   reloc_howto_type * howto;
  431: 
  432:   howto = sh_coff_howtos + rel->r_type;
  433: 
  434:   *addendp = 0;
  435: 
  436:   if (howto->pc_relative)
  437:     *addendp += sec->vma;
  438: 
  439:   if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
  440:     {
  441:       /* This is a common symbol.  The section contents include the
  442:          size (sym->n_value) as an addend.  The relocate_section
  443:          function will be adding in the final value of the symbol.  We
  444:          need to subtract out the current size in order to get the
  445:          correct result.  */
  446:       BFD_ASSERT (h != NULL);
  447:     }
  448: 
  449:   if (howto->pc_relative)
  450:     {
  451:       *addendp -= 4;
  452: 
  453:       /* If the symbol is defined, then the generic code is going to
  454:          add back the symbol value in order to cancel out an
  455:          adjustment it made to the addend.  However, we set the addend
  456:          to 0 at the start of this function.  We need to adjust here,
  457:          to avoid the adjustment the generic code will make.  FIXME:
  458:          This is getting a bit hackish.  */
  459:       if (sym != NULL && sym->n_scnum != 0)
  460:         *addendp -= sym->n_value;
  461:     }
  462: 
  463:   if (rel->r_type == R_SH_IMAGEBASE)
  464:     *addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
  465: 
  466:   return howto;
  467: }
  468: 
  469: #endif /* COFF_WITH_PE */
  470: 
  471: /* This structure is used to map BFD reloc codes to SH PE relocs.  */
  472: struct shcoff_reloc_map
  473: {
  474:   bfd_reloc_code_real_type bfd_reloc_val;
  475:   unsigned char shcoff_reloc_val;
  476: };
  477: 
  478: #ifdef COFF_WITH_PE
  479: /* An array mapping BFD reloc codes to SH PE relocs.  */
  480: static const struct shcoff_reloc_map sh_reloc_map[] =
  481: {
  482:   { BFD_RELOC_32, R_SH_IMM32CE },
  483:   { BFD_RELOC_RVA, R_SH_IMAGEBASE },
  484:   { BFD_RELOC_CTOR, R_SH_IMM32CE },
  485: };
  486: #else
  487: /* An array mapping BFD reloc codes to SH PE relocs.  */
  488: static const struct shcoff_reloc_map sh_reloc_map[] =
  489: {
  490:   { BFD_RELOC_32, R_SH_IMM32 },
  491:   { BFD_RELOC_CTOR, R_SH_IMM32 },
  492: };
  493: #endif
  494: 
  495: /* Given a BFD reloc code, return the howto structure for the
  496:    corresponding SH PE reloc.  */
  497: #define coff_bfd_reloc_type_lookup      sh_coff_reloc_type_lookup
  498: #define coff_bfd_reloc_name_lookup sh_coff_reloc_name_lookup
  499: 
  500: static reloc_howto_type *
  501: sh_coff_reloc_type_lookup (abfd, code)
  502:      bfd * abfd ATTRIBUTE_UNUSED;
  503:      bfd_reloc_code_real_type code;
  504: {
  505:   unsigned int i;
  506: 
  507:   for (i = ARRAY_SIZE (sh_reloc_map); i--;)
  508:     if (sh_reloc_map[i].bfd_reloc_val == code)
  509:       return &sh_coff_howtos[(int) sh_reloc_map[i].shcoff_reloc_val];
  510: 
  511:   fprintf (stderr, "SH Error: unknown reloc type %d\n", code);
  512:   return NULL;
  513: }
  514: 
  515: static reloc_howto_type *
  516: sh_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  517:                            const char *r_name)
  518: {
  519:   unsigned int i;
  520: 
  521:   for (i = 0; i < sizeof (sh_coff_howtos) / sizeof (sh_coff_howtos[0]); i++)
  522:     if (sh_coff_howtos[i].name != NULL
  523:         && strcasecmp (sh_coff_howtos[i].name, r_name) == 0)
  524:       return &sh_coff_howtos[i];
  525: 
  526:   return NULL;
  527: }
  528: 
  529: /* This macro is used in coffcode.h to get the howto corresponding to
  530:    an internal reloc.  */
  531: 
  532: #define RTYPE2HOWTO(relent, internal)           \
  533:   ((relent)->howto =                            \
  534:    ((internal)->r_type < SH_COFF_HOWTO_COUNT    \
  535:     ? &sh_coff_howtos[(internal)->r_type]       \
  536:     : (reloc_howto_type *) NULL))
  537: 
  538: /* This is the same as the macro in coffcode.h, except that it copies
  539:    r_offset into reloc_entry->addend for some relocs.  */
  540: #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)                \
  541:   {                                                             \
  542:     coff_symbol_type *coffsym = (coff_symbol_type *) NULL;      \
  543:     if (ptr && bfd_asymbol_bfd (ptr) != abfd)                   \
  544:       coffsym = (obj_symbols (abfd)                             \
  545:                  + (cache_ptr->sym_ptr_ptr - symbols));         \
  546:     else if (ptr)                                               \
  547:       coffsym = coff_symbol_from (abfd, ptr);                   \
  548:     if (coffsym != (coff_symbol_type *) NULL                    \
  549:         && coffsym->native->u.syment.n_scnum == 0)              \
  550:       cache_ptr->addend = 0;                                    \
  551:     else if (ptr && bfd_asymbol_bfd (ptr) == abfd               \
  552: